任务编号:137648
悬赏任务5H币
悬赏任务 : 按雇主需求进行任务后提交稿件,被采纳后即获得佣金。
距截止:
任务已圆满完成
雇主已托管赏金:25 H币
雇主发布需求25.02.02
雇主托管佣金25.02.02
投稿者投稿25.02.05
雇主开始选稿25.02.05
任务完成25.02.22
任务大厅共需5个合格投稿 | 每稿将获得5 H币 | 每人交稿次数不限 可多次任务
投诉举报
联系Ta
我来承接
已有1 个投稿 | 已采纳0 稿 | 拒绝1 稿 | 还需要5 稿
任务需求:
请帮我在下面MT4 EA源代码中增加对冲功能如下逻辑:
多单信号首单浮亏加仓:当多单信号出现且首单浮亏时,按照设定的手数倍数进行加仓。
空单信号首单浮亏加仓:当空单信号出现且首单浮亏时,按照设定的手数倍数进行加仓。
反向信号对冲:
当多单持仓浮亏且出现空单信号时,加倍对冲多单持仓。
当空单持仓浮亏且出现多单信号时,加倍对冲空单持仓。
多空持仓单持平盈亏均价止盈:当多单和空单的均价差小于设定值时,平仓所有多单和空单
逆势加仓,间隔加仓,出现反向信号停止加仓,然后用反向信号的单子加倍开单对冲浮亏持仓单,比如下单手数0.02,加仓0.03,加仓0.04,那么反向信号出现就是0.09-然后顺势间隔加仓上去 ,设置对冲均价止盈几美金离场,
单边逆势加仓,还是采取单边加仓的均价止盈离场,
还有就是一个单子,没出现浮亏加仓的情况下,是单独盈利400点出场的
#property copyright ""
#property link ""
#property version "1.00"
#property strict
string 使用期限=""; //不填写则不限制,格式:2018.04.08 00:00
string 账号限制=""; //不填写则不限制,填写授权数字账号,|间隔,如:8888|9999|666
enum MYPERIOD{当前=PERIOD_CURRENT,M1=PERIOD_M1,M5=PERIOD_M5,M15=PERIOD_M15,M30=PERIOD_M30,H1=PERIOD_H1,H4=PERIOD_H4,D1=PERIOD_D1,W1=PERIOD_W1,MN1=PERIOD_MN1};
input MYPERIOD 时间周期=当前;
enum MY_OP2{BUY=OP_BUY,SELL=OP_SELL};
input string __A_指标名称="";
input int __做空箭头颜色序号=0;
input double __手数=0.1;
input int __止盈点数=200;
input int __做多箭头颜色序号=1;
input int __亏损加仓间隔点数=100;
input double __手数倍数=2;
input int __最大加仓几单=5;
input int __均价止盈点数=100;
input int 最大允许滑点=900;
#define _tn_int int
#define _m_int int
#define _p_int int
input _m_int _订单识别码=0;
_m_int _内码=0;
input string 订单注释="";
_m_int 子识别码=0;
_m_int 订单识别码=0;
_m_int 备份_分组码=0;
_m_int 备份_指定码=0;
int 强制判断识别码=0;
int 分组循环中=0;
int 指令执行了操盘=0;
_m_int 订单_R_识别码=0;
_m_int 备份_R_分组码=0;
_m_int 备份_R_指定码=0;
int _点系数=1;
double _132间隔分钟=10;
double _其它间隔分钟=0.5;
_tn_int _mPubTsIns[1000]={};
int _mPubTsInc=0;
_tn_int _mPubTsExs[1000]={};
int _mPubTsExc=0;
_tn_int _mPubTs2Ins[1000]={};
_tn_int _mPubTs2Exs[1000]={};
_tn_int _mPubTn0=0;
#define MYARC 20
#define MYPC 300
_p_int _mPubi[MYPC];
double _mPubv[MYPC];
datetime _mPubTime[MYPC];
double _mPubFs[MYARC][MYPC]={};
_p_int _mPubIs[MYARC][MYPC]={};
int _mPubIsc[MYARC]={};
int _mPubFsc[MYARC]={};
#define MYARR_DC 1
#define MYARR_IC 1
int mArrDc[MYARR_DC];
_p_int mArrIs[MYARR_IC][300];
int mArrIc[MYARR_IC];
int §=0;
_m_int gGa=0;
_m_int gGb=0;
_m_int gGa_bak=0;
_m_int gGb_bak=0;
string sym="";
int period=0;
string mPreCap="";
string mPreCapP=""; //此类变量会在修改参数后也删除重置
string mPreCapNoDel="";//此类变量如果是挂ea,则永不清除;若是回测,则清除
string _mInitCap_LoadTime="";
string _mCap_TimePos1=""; //时间标注点
int OnInit() {
string hd=MQLInfoString(MQL_PROGRAM_NAME);
mPreCap=hd+"_"+string(_订单识别码)+"_"+Symbol()+"_"; if (IsTesting()) mPreCap+="test_";
if (StringLen(mPreCap)>26) mPreCap=StringSubstr(mPreCap,StringLen(mPreCap)-26);
mPreCapNoDel=hd+"_"+string(_订单识别码)+"*_"+Symbol()+"_"; if (IsTesting()) mPreCapNoDel+="test_";
if (StringLen(mPreCapNoDel)>26) mPreCapNoDel=StringSubstr(mPreCapNoDel,StringLen(mPreCapNoDel)-26);
if (IsTesting()) {
myObjectDeleteByPreCap(mPreCap);
myDeleteGlobalVariableByPre(mPreCap);
myObjectDeleteByPreCap(mPreCapNoDel);
myDeleteGlobalVariableByPre(mPreCapNoDel);
}
mPreCapP=mPreCap+"#_";
_mInitCap_LoadTime=mPreCap+"_pub_loadtime";
if (myGlobalVDateTimeCheck(_mInitCap_LoadTime)==false) myGlobalVDateTimeSet(_mInitCap_LoadTime,TimeCurrent());
_mCap_TimePos1=mPreCap+"_pub_tmpos1";
if (myGlobalVDateTimeCheck(_mCap_TimePos1)==false) myGlobalVDateTimeSet(_mCap_TimePos1,TimeCurrent());
//显性复位
for (int i=0;i<MYPC;++i) {
_mPubi[i]=0;
_mPubv[i]=0;
_mPubTime[i]=0;
}
for (int i=0;i<MYARC;++i) {
for (int j=0;j<MYPC;++j) {
_mPubFs[i][j]=0;
_mPubIs[i][j]=0;
}
_mPubIsc[i]=0;
_mPubFsc[i]=0;
}
ArrayInitialize(mArrDc,-1);
ArrayInitialize(mArrIc,-1);
if (__A_指标名称=="") { Alert("未输入自定义指标名称,ea中止执行。"); ExpertRemove(); }
_内码=_订单识别码; if (_内码==0) _内码=444;
订单识别码=_内码;
订单_R_识别码=_内码;
if (_内码<-9999 || _内码>9999) { static datetime tm0=0; if (TimeCurrent()-tm0>10) { tm0=TimeCurrent(); Alert("~~~此ea订单识别码不能超过4位数字"); } return 0; }
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason) {
//if (IsTesting()==false) myObjectDeleteByPreCap(mPreCap); //切换周期不能删除,否则按钮状态会改变
if (reason==REASON_REMOVE || reason==REASON_CHARTCLOSE) {
if (IsTesting()==false) {
myObjectDeleteByPreCap(mPreCap);
bool ok=true;
if (ok) myDeleteGlobalVariableByPre(mPreCap);
}
}
else if (reason==REASON_PARAMETERS) {
myObjectDeleteByPreCap(mPreCapP);
myDeleteGlobalVariableByPre(mPreCapP);
}
}
void OnTick() {
if (myTimeLimit(使用期限)==false) return;
if (myAccountNumCheck()==false) return;
if (_订单识别码==444 || _订单识别码==-444) { Alert("~~~~~~自定识别码不能设置为444和-444这两个数字"); ExpertRemove(); return; }
int _tmp_w_break=0;
if (_内码<-9999 || _内码>9999) { static datetime tm0=0; if (TimeCurrent()-tm0>10) { tm0=TimeCurrent(); Alert("~~~此ea订单识别码不能超过4位数字"); } return; }
int _or=0;
§=0; gGa=0; _mPubTsInc=_mPubTsExc=-1;
period=时间周期; if (period==0) period=Period();
sym=Symbol();
if (时间周期!=Period() && iOpen(sym,时间周期,0)==0.00004751) Print("~~~a");
int _ok0=-1;
if (_ok0==-1) {
int _ok1=-1;
if (_ok1==-1) {
int _ok2=myFun8_1();
_ok1=_ok2;
}
//r/ _ok0=_ok1;
}
if (_ok0==-1) {
int _ok3=myFun8_2();
//r/ _ok0=_ok3;
if (_ok3==1) {
}
}
if (_ok0==-1) {
int _ok4=myFun18_1();
//r/ _ok0=_ok4;
if (_ok4==1) { myFun139_1(); }
}
if (_ok0==-1) {
int _ok5=myFun18_2();
//r/ _ok0=_ok5;
if (_ok5==1) { myFun139_2(); }
}
if (_ok0==-1) {
int _ok6=myFun8_3();
//r/ _ok0=_ok6;
if (_ok6==1) { myFun98_1(); }
}
if (_ok0==-1) {
int _ok7=myFun8_4();
_ok0=_ok7;
if (_ok7==1) { myFun24_1(); }
}
}
int mMaxX=0;
int mMaxY=0;
datetime myGlobalVDateTimeGet(string vcap) {
string hcap=vcap+"__h";
string lcap=vcap+"__l";
double h=GlobalVariableGet(hcap);
double l=GlobalVariableGet(lcap);
double r=h*1000000+l;
return (datetime)r;
}
void myGlobalVDateTimeSet(string vcap,datetime t) {
string hcap=vcap+"__h";
string lcap=vcap+"__l";
double f=(double)t;
double h=int(f/1000000);
double l=int(f)%1000000;
GlobalVariableSet(hcap,h);
GlobalVariableSet(lcap,l);
}
bool myGlobalVDateTimeCheck(string vcap) {
return GlobalVariableCheck(vcap+"__h");
}
bool myIsOpenByThisEA(_m_int om) {
if (订单识别码==0 && 强制判断识别码==0) return true;
if (_订单识别码==0 && 强制判断识别码==0) return true; //用户接口参数直接设置为0表示忽略识别码(判断的是“_订单识别码”,而非“订单识别码”,因此不影响区分手工单)
if (分组循环中==1) return om==订单识别码;
return om==订单识别码;
}
bool myIsOpenByThisEA2(_m_int om,int incSub) {
if (订单识别码==0 && 强制判断识别码==0) return true;
if (_订单识别码==0 && 强制判断识别码==0) return true; //用户接口参数直接设置为0表示忽略识别码(判断的是“_订单识别码”,而非“订单识别码”,因此不影响区分手工单)
if (分组循环中==1) return om==订单识别码;
if (订单识别码==0) return om==订单识别码 || (incSub && int(om/100000)==444); //避免将其它ea的小于100000的识别码误认为是手工单
return om==订单识别码 || (incSub && int(om/100000)==订单识别码);
}
void myCreateLabel(string str="mylabel",string ID="def_la1",long chartid=0,int xdis=20,int ydis=20,int fontsize=12,color clr=clrRed,int corner=CORNER_LEFT_UPPER) {
ObjectCreate(chartid,ID,OBJ_LABEL,0,0,0);
ObjectSetInteger(chartid,ID,OBJPROP_XDISTANCE,xdis);
ObjectSetInteger(chartid,ID,OBJPROP_YDISTANCE,ydis);
ObjectSetString(chartid,ID,OBJPROP_FONT,"Trebuchet MS");
ObjectSetInteger(chartid,ID,OBJPROP_FONTSIZE,fontsize);
ObjectSetInteger(chartid,ID,OBJPROP_CORNER,corner);
ObjectSetInteger(chartid,ID,OBJPROP_SELECTABLE,true);
ObjectSetString(chartid,ID,OBJPROP_TOOLTIP,"\n");
ObjectSetString(chartid,ID,OBJPROP_TEXT,str);
ObjectSetInteger(chartid,ID,OBJPROP_COLOR,clr);
}
double myLotsValid(string sym0,double lots,bool returnMin=false) {
double step=MarketInfo(sym0,MODE_LOTSTEP);
if (step<0.000001) { Alert("品种【",sym0,"】数据读取失败,请检查此品种是否存在。若有后缀,请包含后缀。"); return lots; }
int v=(int)MathRound(lots/step); lots=v*step;
double min=MarketInfo(sym0,MODE_MINLOT);
double max=MarketInfo(sym0,MODE_MAXLOT);
if (lots<min) {
if (returnMin) return min;
Alert("手数太小,不符合平台要求"); lots=-1;
}
if (lots>max) lots=max;
return lots;
}
double myLotsBs(string sym0,double lots0,double bs) {
double lots=lots0*bs; double l0=lots; lots=myLotsValid(sym0,lots,true);
if (MathAbs(lots0-l0)<0.00001) {
if (bs>1.000001) { lots+=MarketInfo(sym0,MODE_LOTSTEP); lots=myLotsValid(sym0,lots,true); }
else if (bs<1-0.000001) { lots-=MarketInfo(sym0,MODE_LOTSTEP); lots=myLotsValid(sym0,lots,true); }
}
return lots;
}
string 时间限制_时间前缀="使用期限:";
string 时间限制_时间后缀="";
string 时间过期_时间前缀="~~~~~~~已过使用期限:";
string 时间过期_时间后缀="";
bool myTimeLimit(string timestr) {
if (timestr=="") return true;
datetime t=StringToTime(timestr);
if (TimeCurrent()<t) {
myCreateLabel(时间限制_时间前缀+timestr+时间限制_时间后缀,mPreCap+"myTimeLimit",0,20,20,10,255,CORNER_LEFT_LOWER);
return true;
}
else {
myCreateLabel(时间过期_时间前缀+timestr+时间过期_时间后缀,mPreCap+"myTimeLimit",0,20,20,10,255,CORNER_LEFT_LOWER);
return false;
}
}
bool myAccountNumCheck() {
if (账号限制=="") return true;
ushort u_sep=StringGetCharacter("|",0);
string ss[1000]; int c=StringSplit(账号限制,u_sep,ss);
if (c>=1000) Alert("授权列表数量太大");
string s=string(AccountNumber());
for (int i=0;i<c;++i) if (s==ss[i]) return true;
myCreateLabel("非授权账户账号:"+s,mPreCap+"onlyuser2");
return false;
}
void myDeleteGlobalVariableByPre(string pre) {
int len=StringLen(pre);
for (int i=GlobalVariablesTotal()-1;i>=0;--i) {
string cap=GlobalVariableName(i);
if (StringSubstr(cap,0,len)==pre)
GlobalVariableDel(cap);
}
}
void myObjectDeleteByPreCap(string PreCap) {
//删除指定名称前缀的对象
int len=StringLen(PreCap);
for (int i=ObjectsTotal()-1;i>=0;--i) {
string cap=ObjectName(i);
if (StringSubstr(cap,0,len)==PreCap)
ObjectDelete(cap);
}
}
string myPeriodStr(int p0) {
int pid=0; if (p0==0) p0=Period();
string pstr;
switch (p0) {
case 1: pid=0; pstr="M1"; break;
case 5: pid=1; pstr="M5"; break;
case 15: pid=2; pstr="M15"; break;
case 30: pid=3; pstr="M30"; break;
case 60: pid=4; pstr="H1"; break;
case 240: pid=5; pstr="H4"; break;
case 1440: pid=6; pstr="D1"; break;
case 10080: pid=7; pstr="W1"; break;
case 43200: pid=8; pstr="MN"; break;
default: pstr=string(p0);
}
return pstr;
}
bool myOrderOks(_tn_int tn) {
if (_mPubTsExc>0) { for (int i=0;i<_mPubTsExc;++i) { if (_mPubTsExs[i]==tn) return false; } }
if (_mPubTsInc>=0){
int i=0; for (;i<_mPubTsInc;++i) { if (_mPubTsIns[i]==tn) break; }
if (i>=_mPubTsInc) return false;
}
return true;
}
bool myFun8_1() {
return true;
}
bool myFun8_2() {
return true;
}
bool myFun18_1() {
double a=double(iCustom(sym,period,__A_指标名称,__做空箭头颜色序号,1+§));
int c=0;
double b=double(0.1);
c+=a>b;
b=99999999;
c+=a<b;
if (c==2) return true;
return false;
}
_p_int myFun139_1() {
指令执行了操盘=0;
_m_int magic=订单识别码;
int slip=最大允许滑点;
string comm=订单注释;
double pnt=MarketInfo(sym,MODE_POINT);
int type=1;
double lots=myLotsValid(sym,double(__手数),true);
double sl=double(0*_点系数);
double tp=double(int(__止盈点数)*_点系数);
datetime tm0=iTime(sym,period,0);
for(int pos=OrdersTotal()-1;pos>=0;pos--) {
if (OrderSelect(pos,SELECT_BY_POS)==false) continue;
if (magic!=444 && myIsOpenByThisEA2(OrderMagicNumber(),1)==false) continue;
if (sym!="" && OrderSymbol()!=sym) continue;
if (OrderOpenTime()>=tm0) return 0; //一根K线只建仓一单
if (OrderType()==type) return 0; //一个方向只持仓一单
}
for(int pos=OrdersHistoryTotal()-1;pos>=0;pos--) {
if (OrderSelect(pos,SELECT_BY_POS,MODE_HISTORY)==false) continue;
if (magic!=444 && myIsOpenByThisEA2(OrderMagicNumber(),1)==false) continue;
if (sym!="" && OrderSymbol()!=sym) continue;
if (OrderOpenTime()>=tm0) return 0; //一根K线只建仓一单
if (OrderCloseTime()<tm0) break;
}
_tn_int t2=0;
for (int w=0;w<4;++w) { if (w>0) { Sleep(3000); Alert("~~~m=",magic,"~~~slip=",slip,"~~~~~建仓重试",w); RefreshRates(); }
double op2=0;
if (type==OP_BUY) op2=MarketInfo(sym,MODE_ASK);
else if (type==OP_SELL) op2=MarketInfo(sym,MODE_BID);
else return 0;
t2=OrderSend(sym,type,lots,op2,slip,0,0,comm,magic);
if (t2>0 && w>0) Alert("~~~~重试建仓成功");
if (t2<=0) {
int err=GetLastError();
if (err==134) { Alert("~~~~~~~~~~保证金不足,建仓手数无效:",lots); Sleep(3000); return 0; }
else if (err>=135 && err<=138) { Alert("~~m=",magic,"~~~网速慢或平台服务器卡~~~~~建仓失败:",err); continue; }
else Alert("~~m=",magic,"~~~~~~~~建仓失败:",err);
Sleep(3000); break;
}
else {
if ((sl>pnt || tp>pnt) && OrderSelect(t2,SELECT_BY_TICKET)) {
if (type==OP_BUY) {
if (sl>0.001) sl=OrderOpenPrice()-sl*MarketInfo(sym,MODE_POINT);
if (tp>0.001) tp=OrderOpenPrice()+tp*MarketInfo(sym,MODE_POINT);
}
else if (type==OP_SELL) {
if (sl>0.001) sl=OrderOpenPrice()+sl*MarketInfo(sym,MODE_POINT);
if (tp>0.001) tp=OrderOpenPrice()-tp*MarketInfo(sym,MODE_POINT);
}
if (OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0)==false)
Print("~~~~~~~~~设置止盈止损失败:",GetLastError());
}
}
if (t2>0) { 指令执行了操盘=1; break; }
}
return t2;
}
bool myFun18_2() {
double a=double(iCustom(sym,period,__A_指标名称,__做多箭头颜色序号,1+§));
int c=0;
double b=double(0.1);
c+=a>b;
b=99999999;
c+=a<b;
if (c==2) return true;
return false;
}
_p_int myFun139_2() {
指令执行了操盘=0;
_m_int magic=订单识别码;
int slip=最大允许滑点;
string comm=订单注释;
double pnt=MarketInfo(sym,MODE_POINT);
int type=0;
double lots=myLotsValid(sym,double(__手数),true);
double sl=double(0*_点系数);
double tp=double(int(__止盈点数)*_点系数);
datetime tm0=iTime(sym,period,0);
for(int pos=OrdersTotal()-1;pos>=0;pos--) {
if (OrderSelect(pos,SELECT_BY_POS)==false) continue;
if (magic!=444 && myIsOpenByThisEA2(OrderMagicNumber(),1)==false) continue;
if (sym!="" && OrderSymbol()!=sym) continue;
if (OrderOpenTime()>=tm0) return 0; //一根K线只建仓一单
if (OrderType()==type) return 0; //一个方向只持仓一单
}
for(int pos=OrdersHistoryTotal()-1;pos>=0;pos--) {
if (OrderSelect(pos,SELECT_BY_POS,MODE_HISTORY)==false) continue;
if (magic!=444 && myIsOpenByThisEA2(OrderMagicNumber(),1)==false) continue;
if (sym!="" && OrderSymbol()!=sym) continue;
if (OrderOpenTime()>=tm0) return 0; //一根K线只建仓一单
if (OrderCloseTime()<tm0) break;
}
_tn_int t2=0;
for (int w=0;w<4;++w) { if (w>0) { Sleep(3000); Alert("~~~m=",magic,"~~~slip=",slip,"~~~~~建仓重试",w); RefreshRates(); }
double op2=0;
if (type==OP_BUY) op2=MarketInfo(sym,MODE_ASK);
else if (type==OP_SELL) op2=MarketInfo(sym,MODE_BID);
else return 0;
t2=OrderSend(sym,type,lots,op2,slip,0,0,comm,magic);
if (t2>0 && w>0) Alert("~~~~重试建仓成功");
if (t2<=0) {
int err=GetLastError();
if (err==134) { Alert("~~~~~~~~~~保证金不足,建仓手数无效:",lots); Sleep(3000); return 0; }
else if (err>=135 && err<=138) { Alert("~~m=",magic,"~~~网速慢或平台服务器卡~~~~~建仓失败:",err); continue; }
else Alert("~~m=",magic,"~~~~~~~~建仓失败:",err);
Sleep(3000); break;
}
else {
if ((sl>pnt || tp>pnt) && OrderSelect(t2,SELECT_BY_TICKET)) {
if (type==OP_BUY) {
if (sl>0.001) sl=OrderOpenPrice()-sl*MarketInfo(sym,MODE_POINT);
if (tp>0.001) tp=OrderOpenPrice()+tp*MarketInfo(sym,MODE_POINT);
}
else if (type==OP_SELL) {
if (sl>0.001) sl=OrderOpenPrice()+sl*MarketInfo(sym,MODE_POINT);
if (tp>0.001) tp=OrderOpenPrice()-tp*MarketInfo(sym,MODE_POINT);
}
if (OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0)==false)
Print("~~~~~~~~~设置止盈止损失败:",GetLastError());
}
}
if (t2>0) { 指令执行了操盘=1; break; }
}
return t2;
}
bool myFun8_3() {
return true;
}
_p_int myFun98_1() {
指令执行了操盘=0;
_m_int magic=订单识别码;
int slip=最大允许滑点;
string comm=订单注释;
double pnt=MarketInfo(sym,MODE_POINT);
int typ=0; string st="亏损加仓"; if (typ==1) st="盈利加仓";
double jg=double(int(__亏损加仓间隔点数));
double bs=double(double(__手数倍数));
int maxc=int(int(__最大加仓几单));
bool oneKone=0;
int slt=0; double sl=double(0);
int tpt=0; double tp=double(0);
{ //读取首单
double op00[2]={0,0}; _tn_int tn00[2]={0,0};
for(int pos=OrdersTotal()-1;pos>=0;pos--) {
if (OrderSelect(pos,SELECT_BY_POS)==false) continue;
if (magic!=444 && myIsOpenByThisEA2(OrderMagicNumber(),1)==false) continue;
if (sym!="" && OrderSymbol()!=sym) continue;
int t=OrderType();
if (t!=OP_BUY && t!=OP_SELL) continue;
if (tn00[t]==0 || OrderTicket()<tn00[t]) { op00[t]=OrderOpenPrice(); tn00[t]=OrderTicket(); }
}
//读取持仓数据
double op[2]={0,0},ls[2]={0,0}; int kc[2]={0,0},addc[2]={0,0};
datetime tm0=iTime(sym,period,0);
for(int pos=OrdersTotal()-1;pos>=0;pos--) {
if (OrderSelect(pos,SELECT_BY_POS)==false) continue;
if (magic!=444 && myIsOpenByThisEA2(OrderMagicNumber(),1)==false) continue;
if (sym!="" && OrderSymbol()!=sym) continue;
int t=OrderType();
if (t!=OP_BUY && t!=OP_SELL) continue;
if (t==OP_BUY) {
if (typ==0 && (op[t]<pnt || OrderOpenPrice()<op[t])) { op[t]=OrderOpenPrice(); ls[t]=OrderLots(); } //亏损加仓,搜索价格最低的buy单
else if (typ==1 && (op[t]<pnt || OrderOpenPrice()>op[t])) { op[t]=OrderOpenPrice(); ls[t]=OrderLots(); } //盈利加仓
if (typ==0 && op00[t]-OrderOpenPrice()>=pnt) addc[t]+=1;
else if (typ==1 && OrderOpenPrice()-op00[t]>=pnt) addc[t]+=1;
}
else {
if (typ==0 && (op[t]<pnt || OrderOpenPrice()>op[t])) { op[t]=OrderOpenPrice(); ls[t]=OrderLots(); }
else if (typ==1 && (op[t]<pnt || OrderOpenPrice()<op[t])) { op[t]=OrderOpenPrice(); ls[t]=OrderLots(); }
if (typ==0 && OrderOpenPrice()-op00[t]>=pnt) addc[t]+=1;
else if (typ==1 && op00[t]-OrderOpenPrice()>=pnt) addc[t]+=1;
}
if (OrderOpenTime()>=tm0) kc[t]+=1;
}
//加仓
int z=0;
if (op[z]>pnt && (oneKone==false || kc[z]==0) && addc[z]<maxc) { int type=OP_BUY; double op0=op[z]; double ls0=ls[z];
double op2=MarketInfo(sym,MODE_ASK);
if ((typ==0 && op0-op2>=jg*pnt) || (typ==1 && op2-op0>=jg*pnt)) {
double lots=myLotsBs(sym,ls0,bs);
if (slt==0 && sl>0.001) sl=op2-sl*pnt;
if (tpt==0 && tp>0.001) tp=op2+tp*pnt;
static datetime errtm1=0,errtm2=0; datetime cur=TimeCurrent();
if (cur-errtm1>60*_132间隔分钟 && cur-errtm2>60*_其它间隔分钟) {
Print("~~~~~~~~~~~",st);
_tn_int tn=OrderSend(sym,type,lots,op2,slip,sl,tp,st+"_"+comm,magic);
if (tn<=0) { int err=GetLastError();
if (err==132) { errtm1=TimeCurrent(); Print("~~~~~~~本品种市场未开市"); }
else { errtm2=TimeCurrent(); Print("~~~~~~~~~~buy加仓错误:",err,",lots=",lots); }
}
else 指令执行了操盘=1;
}
}
}
z=1;
if (op[z]>pnt && (oneKone==false || kc[z]==0) && addc[z]<maxc) { int type=OP_SELL; double op0=op[z]; double ls0=ls[z];
double op2=MarketInfo(sym,MODE_BID);
if ((typ==0 && op2-op0>=jg*pnt) || (typ==1 && op0-op2>=jg*pnt)) {
double lots=myLotsBs(sym,ls0,bs);
if (slt==0 && sl>0.001) sl=op2+sl*pnt;
if (tpt==0 && tp>0.001) tp=op2-tp*pnt;
static datetime errtm1=0,errtm2=0; datetime cur=TimeCurrent();
if (cur-errtm1>60*_132间隔分钟 && cur-errtm2>60*_其它间隔分钟) {
Print("~~~~~~~~~~~",st);
_tn_int tn=OrderSend(sym,type,lots,op2,slip,sl,tp,st+"_"+comm,magic);
if (tn<=0) { int err=GetLastError();
if (err==132) { errtm1=TimeCurrent(); Print("~~~~~~~本品种市场未开市"); }
else { errtm2=TimeCurrent(); Print("~~~~~~~~~~sell加仓错误:",err,",lots=",lots); }
}
else 指令执行了操盘=1;
}
}
}
}
return 0;
}
bool myFun8_4() {
return true;
}
_p_int myFun24_1() {
指令执行了操盘=0;
int slip=最大允许滑点;
string comm=订单注释;
double pnt=MarketInfo(sym,MODE_POINT);
int digit=(int)MarketInfo(sym,MODE_DIGITS);
double tpp=double(int(__均价止盈点数));
int minc=2;
int canBig=0;
//if (tpp<pnt) return 0;
{ double op[2]={0,0},ls[2]={0,0}; int oc[2]={0,0};
for(int pos=OrdersTotal()-1;pos>=0;pos--) {
if (OrderSelect(pos,SELECT_BY_POS)==false) continue;
if (myIsOpenByThisEA2(OrderMagicNumber(),1)==false) continue;
if (sym!="" && OrderSymbol()!=sym) continue;
int t=OrderType();
if (t!=OP_BUY && t!=OP_SELL) continue;
if (myOrderOks(OrderTicket())==false) continue;
op[t]+=OrderOpenPrice()*OrderLots(); ls[t]+=OrderLots(); oc[t]+=1;
}
for (int i=0;i<2;++i) {
if (oc[i]==0) continue;
op[i]/=ls[i]; op[i]=NormalizeDouble(op[i],digit);
}
//修改止盈价
int z=0;
if (oc[z]>0 && oc[z]>=minc) { int type=OP_BUY; double tpaver=op[z]+tpp*pnt;
for(int pos=OrdersTotal()-1;pos>=0;pos--) {
if (OrderSelect(pos,SELECT_BY_POS)==false) continue;
if (myIsOpenByThisEA2(OrderMagicNumber(),1)==false) continue;
if (sym!="" && OrderSymbol()!=sym) continue;
if (OrderType()!=type) continue;
if (myOrderOks(OrderTicket())==false) continue;
if (MathAbs(OrderTakeProfit()-tpaver)<pnt) continue;
if (canBig==false && OrderTakeProfit()>pnt && tpaver>OrderTakeProfit()) continue;
if (OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),tpaver,OrderExpiration())==false)
Print("buy止盈修改失败#",OrderTicket(),",",OrderSymbol(),",",GetLastError());
else 指令执行了操盘=1;
}
}
z=1;
if (oc[z]>0 && oc[z]>=minc) { int type=OP_SELL; double tpaver=op[z]-tpp*pnt;
for(int pos=OrdersTotal()-1;pos>=0;pos--) {
if (OrderSelect(pos,SELECT_BY_POS)==false) continue;
if (myIsOpenByThisEA2(OrderMagicNumber(),1)==false) continue;
if (sym!="" && OrderSymbol()!=sym) continue;
if (OrderType()!=type) continue;
if (myOrderOks(OrderTicket())==false) continue;
if (MathAbs(OrderTakeProfit()-tpaver)<pnt) continue;
if (canBig==false && OrderTakeProfit()>pnt && tpaver<OrderTakeProfit()) continue;
if (OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),tpaver,OrderExpiration())==false)
Print("sell止盈修改失败#",OrderTicket(),",",OrderSymbol(),",",GetLastError());
else 指令执行了操盘=1;
}
}
}
return 0;
1.出现多单信号开仓做多,首单0.02,出现浮亏,则利用逆势间隔加仓,逆势倍数加仓,(首单0.02,间隔200点加仓,倍数1.3 开单0.03,行情延续下跌,继续加仓0.04,然后多单没有盈利,均持仓0.09单,这个时候出现反向信号空头,则利用空单信号来对冲多单持仓单量总数2倍加仓,然后综合多空持仓单一起均价止盈离场,疑问,如果这个时候又出现反向信号多单,我如何来详细做对冲前面的多空持仓单,而且减少风险的情况下,应该怎么操作,或者怎么开单对冲来达到综合均价止盈几美金离场,注意,有对冲肯定不能用止损功能,只能多空均价止盈几美金,小盈利离场
1.多单信号首单浮亏加仓:当多单信号出现且首单浮亏时,按照设定的手数倍数进行加仓。
示例:开仓做多,首单0.02,出现浮亏,则利用逆势间隔加仓,逆势倍数加仓,比如:(首单0.02,间隔200点加仓,倍数1.3 开单0.03,行情延续下跌,继续加仓0.04,正常止盈是根据参数设定的单逆势加仓均价止盈点数止盈,
2.如果首单没有出现逆势加仓的情况下,则根据参数设定的单独止盈点数400小点止盈离场,
3.示例:开仓做多,首单0.02,出现浮亏,则利用逆势间隔加仓,逆势倍数加仓,比如:(首单0.02,间隔200点加仓,倍数1.3 开单0.03,行情延续下跌,继续加仓0.04,然后多单没有盈利,此时多单持仓为0.09单,此时出现反向信号空头,则利用空单信号来对冲多单持仓单量总数2倍加仓,然后综合多空持仓单一起均价止盈几美金小盈利离场,疑问,如果这个时候又出现反向信号多单,我如何来详细做对冲前面的多空持仓单,而且减少风险的情况下,应该怎么操作,或者怎么开单对冲来达到综合均价止盈几美金离场,注意,有对冲肯定不能用止损功能,只能多空均价止盈几美金,小盈利离场
空单反之。。。
|