2 Star 5 Fork 4

航耍耍/mql4

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
均线趋势马丁H4.mq4 94.71 KB
一键复制 编辑 原始数据 按行查看 历史
航耍耍 提交于 2021-11-09 08:24 . 123123123123
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
//--
#property copyright ""
#property link "https://yanchengea.taobao.com"
#property description " "
#property description "永久忠告:建议先暂停实盘,直到有经得起长期测试,且稳定的好EA,再实盘,赚钱永远都不会晚的。" //无限
#property description " "
#property description "言成EA代写:诚心做人,踏实做事!价格公道,童叟无欺不讲价,可以保证质量与服务。" //无限
#property description " "
#property description ""
#property version "1.0"
#property strict
//参数 ccs-参数
input string 灬a1="---------";
input int 均线周期a=10;
input int 均线周期b=10;
input int 均线周期c=20;
input int 均线周期d=30;
input int 均线周期e=60;
input int 均线周期f=60;
input ENUM_MA_METHOD 移动平均=MODE_SMA;
input ENUM_APPLIED_PRICE 价格应用=PRICE_CLOSE;
input string 灬a2="---------";
input bool 是否开启均线排列过滤条件=false;
input int 排列均线a=60;
input int 排列均线b=60;
input int 排列均线c=60;
input int 排列均线d=60;
input int 排列均线e=60;
input int 排列均线f=60;
input ENUM_MA_METHOD 排列平均=MODE_SMA;
input ENUM_APPLIED_PRICE 排列价格=PRICE_CLOSE;
input string 灬a3="---------";
enum TradeType{即时交易=0,收盘交易=1};
input TradeType 交易模式=收盘交易;
input int 间隔N微点顺势加仓_0为关闭=50;
input int 间隔N微点逆势加仓_0为关闭=400;
input string 灬b1="---------";
input double A_建仓手数=0.01;
input bool A_是否开启自动单量=true;
input int A_每N美元余额做001手=3000;//A_每N美元余额做0.01手
input double 顺势加仓倍率_1为关闭=1.0;
input double 逆势加仓倍率_1为关闭=3.0;
input int 单向顺势最大加仓次数=2;
input int 单向逆势最大加仓次数=5;
input string 灬c1="---------";
input int 单向均价止盈N微点_0为关闭=100;
input int A_单向均价止损N微点_0为关闭=0;
input int A_直接止损后N秒内禁止建仓=0;
input int B_单向均价盈利N微点后_0为关闭=0;
input int B_追踪止损于盈利回撤N微点平仓_0为关闭=0;
input int B_移动止损后N秒内禁止建仓=0;
input string 灬c2="---------";
input double 总盈利大于N美元全平_0为关闭=0;
input double 总亏损大于N美元全平_0为关闭=0;
input int 总盈利大于总手数乘N全平_0为关闭=100;
input int 总亏损大于总手数乘N全平_0为关闭=0;
input double 总亏损大于余额百分之N全平_0为关闭=0;
input bool C_是否开启均线AB交叉全平=false;
input int C_均线周期A=20;
input int C_均线周期B=20;
input ENUM_MA_METHOD C_移动平均AB=MODE_SMA;
input ENUM_APPLIED_PRICE C_价格应用AB=PRICE_CLOSE;
input string 灬d1="---------";
input bool A_是否显示免费统计信息=true;
input color A_信息颜色=clrDeepSkyBlue;
input int A_信息离左边距离N=300;
input int Magic_1=6266616;//Magic_设置0会兼容手动单
string 注释_1="言成EA代写:6266616 ";
int InitAryVol=50,ResetVol=0,InitTickVol=0;double customvalue=0,InitBid=Bid; //InitBid备用于价格触碰
datetime StartTime=TimeCurrent(),InitTime=TimeCurrent(); //必须开盘才下单可用到这个 InitTime<Time[0],且最后InitTime=TimeCurrent();
int OnInit() //初始化函数中,修改参数也重置,否则类似static,重启MT4、重载EA才重置。
{
InitTickVol=0;Print("正在初始化……最近转化ex4时间:",__DATETIME__);
Print("EA客户端重启成功!重启因素:周期切换、修改参数、重启mt4、重新加载!");
Print("每1微点数造成的盈亏额度:",MarketInfo(Symbol(),MODE_TICKVALUE)); //可能0
Print("平台限制:允许的最小交易手数",MarketInfo(Symbol(),MODE_MINLOT));
Print("平台限制:允许的最小止损止盈和当前价格距离微点数",MarketInfo(Symbol(),MODE_STOPLEVEL));
Print("温馨提示:“止损/止盈/挂单”请务必设置大于“平台限制距离+点差*2”!");
if(EventSetMillisecondTimer(300)==false) {ErrorAlert(Symbol(),"SetTime。不影响使用,请忽略即可。");} //EventSetTimer秒,太小会失败。
ObjectCreate(0,"Event_YCEA",OBJ_EVENT,0,TimeCurrent(),0);
return(INIT_SUCCEEDED);
}
void OnTimer() {OnTick();} //OnInit·EventSetTimer(1);OnDeinit·EventKillTimer();
void OnTick() //qqq2
{
//正式进入
static double InitAProfitHest_1[],InitAProfitLest_1[]; static int InitAVol_1[],InitBVol_1[],InitSVol_1[],InitBModifyVol_1[],InitSModifyVol_1[]; ArrayResize(InitAProfitHest_1,InitAryVol);ArrayResize(InitAProfitLest_1,InitAryVol);ArrayResize(InitAVol_1,InitAryVol);ArrayResize(InitBVol_1,InitAryVol);ArrayResize(InitSVol_1,InitAryVol);ArrayResize(InitBModifyVol_1,InitAryVol);ArrayResize(InitSModifyVol_1,InitAryVol);//ArrayInitialize(InitBModifyVol_1,0); //可用于多货币对多Magic
int CycleVol=1; //if(!是否只针对当前货币对) {CycleVol=ArraySize(ArySymbol_String);}
for(int s=0;s<=CycleVol-1;s++)
{
if(IsStopped()){break;} static datetime AlertTime_1=TimeCurrent();if(!IsTradeAllowed()&&TimeCurrent()-AlertTime_1>=3600) {MessageBox(IntegerToString(AccountNumber())+" - "+Symbol()+" - "+(string)Period()+" - EA停止中,请检查:\n\n1.MT4上方的【自动交易】,请保持[按下]状态。\n\n2.右击图表->EA交易系统->属性->常用->允许实时自动交易,请保持[勾选]状态。","温馨提示",MB_OKCANCEL);AlertTime_1=TimeCurrent();} //确定1,取消2
RefreshRates();string symbol=Symbol(); //if(!是否只针对当前货币对) {symbol=ArySymbol_String[s];}
double ask=MarketInfo(symbol,MODE_ASK),bid=MarketInfo(symbol,MODE_BID),ticksize=MarketInfo(Symbol(),MODE_TICKSIZE),point=MarketInfo(symbol,MODE_POINT),minlot=MarketInfo(symbol,MODE_MINLOT),maxlot=MarketInfo(symbol,MODE_MAXLOT),tickvalue=MarketInfo(symbol,MODE_TICKVALUE),marginrequired=MarketInfo(symbol,MODE_MARGINREQUIRED);//minlot部分平台总是为0,marginrequired每手保证金
double accountbalance=AccountBalance()+AccountCredit(),accountequity=AccountEquity(),accountprofit=AccountProfit(),accountmargin=AccountMargin();
int digits=int(MarketInfo(symbol,MODE_DIGITS)),orderstotals=OrdersTotal(),spead=(int)MarketInfo(symbol,MODE_SPREAD),stoplevel=(int)MarketInfo(Symbol(),MODE_STOPLEVEL)+spead;
if(minlot==0){minlot=0.01;}if(maxlot==0){maxlot=20;}if(tickvalue==0){tickvalue=1;}if(AccountNumber()==0||accountbalance==0||accountequity==0||ask==0||bid==0) {Print(s," 可能资金为0或无此货币 ",symbol," AccountNumber() ",AccountNumber()," accountbalance ",accountbalance," accountequity ",accountequity," ask ",ask," bid ",bid);continue;} //ask==0,部分平台掉线后为0
int period_T1=Period(); //if(图表周期_T1!=0) {period_T1=图表周期_T1;} //int period_T2=Period(); if(图表周期_T2!=0) {period_T2=图表周期_T2;}
datetime time0=iTime(symbol,period_T1,0); int bars=Bars(symbol,period_T1)-10;if(bars>1000){bars=1000;} if(bars<=0) {return;}
//统计订单 ttj-统计 NormalizeDouble规范小数点 注意:除法的分母必须为小数,%余数必须整数。 大类市价单+挂单,小类a-z排列
datetime AllAryOpenTime_1[];ArrayResize(AllAryOpenTime_1,orderstotals);datetime BuyAryOpenTime_1[];ArrayResize(BuyAryOpenTime_1,orderstotals);datetime SelAryOpenTime_1[];ArrayResize(SelAryOpenTime_1,orderstotals);
double AllAryProfit_1[];ArrayResize(AllAryProfit_1,orderstotals); int AllAryTicket_1[];ArrayResize(AllAryTicket_1,orderstotals); //ArrayInitialize(AllAryTicket_1,0); //初始化数组
double BuyAryLots_1[],BuyAryOpenPrice_1[],BuyAryProfit_1[];ArrayResize(BuyAryLots_1,orderstotals);ArrayResize(BuyAryOpenPrice_1,orderstotals);ArrayResize(BuyAryProfit_1,orderstotals); int BuyAryTicket_1[];ArrayResize(BuyAryTicket_1,orderstotals); //ArrayInitialize(AllAryTicket_1,0); //初始化数组
double SelAryLots_1[],SelAryOpenPrice_1[],SelAryProfit_1[];ArrayResize(SelAryLots_1,orderstotals);ArrayResize(SelAryOpenPrice_1,orderstotals);ArrayResize(SelAryProfit_1,orderstotals); int SelAryTicket_1[];ArrayResize(SelAryTicket_1,orderstotals); //ArrayInitialize(AllAryTicket_1,0); //初始化数组
datetime AllFirstOpenTime_1=0,AllLastOpenTime_1=0,BuyFirstOpenTime_1=0,BuyLastOpenTime_1=0,SelFirstOpenTime_1=0,SelLastOpenTime_1=0;
double AllFirstLots_1=0,AllFirstOpenPrice_1=0,AllFirstProfit_1=0,AllFirstType_1=8,AllHighest_1=0,AllLastLots_1=0,AllLastLots_Num2_1=0,AllLastOpenPrice_1=0,AllLastOpenPrice_Num2_1=0,AllLastProfit_1=0,AllLastStopLoss_1=0,AllProfit_1=0,AllLowest_1=0,AllLots_1=0,AllProfit_Day_1=0,AllSwap_1=0,AllTPHighest_1=0,AllTPHighestPoint_1=0,AllTPLowest_1=0,AllTPLowestPoint_1=0;
double BuyAllOpenPrice_1=0,BuyFirstLots_1=0,BuyFirstOpenPrice_1=0,BuyHighest_1=0,BuyHighestLots_1=0,BuyHighestProfit_1=0,BuyHighestTicket_1=0,BuyHLots_1=0,BuyLastLots_1=0,BuyLastLots_Num2_1=0,BuyLastOpenPrice_1=0,BuyLastOpenPrice_Num2_1=0,BuyLastProfit_1=0,BuyLastStopLoss_1=0,BuyLLots_1=0,BuyLots_1=0,BuyLowest_1=0,BuyLowestLots_1=0,BuyProfit_1=0,BuySwap_1=0;
double SelAllOpenPrice_1=0,SelFirstLots_1=0,SelFirstOpenPrice_1=0,SelHighest_1=0,SelHighestLots_1=0,SelHLots_1=0,SelLastLots_1=0,SelLastLots_Num2_1=0,SelLastOpenPrice_1=0,SelLastOpenPrice_Num2_1=0,SelLastProfit_1=0,SelLastStopLoss_1=0,SelLLots_1=0,SelLots_1=0,SelLowest_1=0,SelLowestLots_1=0,SelLowestProfit_1=0,SelLowestTicket_1=0,SelProfit_1=0,SelSwap_1=0;
int AllLastType_1=8,AllNewKVol_1=0,AllSLVol_1=0,AllTPVol_1=0,AllVol_1=0,AllVol_Day_1=0,BuyNewKVol_1=0,BuyVol_1=0,BuyVol_JianGe_1=0,BuySLVol_1=0,BuyTPVol_1=0,SelNewKVol_1=0,SelVol_1=0,SelVol_JianGe_1=0,SelSLVol_1=0,SelTPVol_1=0;
if(OrdersTotal()>=0)
{
for(int i=OrdersTotal()-1;i>=0;i--) //建仓晚至早_非平仓时间 //i>=0&&TimeOrder,会直接中断,相当于break。 //和历史统计一样,从0表示First首单。 for(int i=0;i<orderstotals;i++) //从First首单开始扫描。
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
RefreshRates(); if(ask==0||bid==0){return;}
string ordersymbol=OrderSymbol(),ordercomment=OrderComment(); int orderticket=OrderTicket(),orderdigs=int(MarketInfo(OrderSymbol(),MODE_DIGITS));datetime orderopentime=OrderOpenTime(),orderclosetime=OrderCloseTime();
int OrderK0=iBarShift(ordersymbol,0,OrderOpenTime()),OrderK1=iBarShift(ordersymbol,0,OrderOpenTime())+1;
double orderlots=OrderLots(),orderopenprice=OrderOpenPrice(),orderpoint=MarketInfo(OrderSymbol(),MODE_POINT),orderprofit=OrderProfit()+OrderCommission()+OrderSwap();
if(OrderSymbol()==symbol&&OrderMagicNumber()==Magic_1) //&&OrderOpenTime()>=InitTime
{
if(OrderType()==0||OrderType()==1) //if(StringFind(ordersymbol,StringSubstr(symbol,0,3))>=0) {PendAllVol_Left_1++;} if(StringFind(ordersymbol,StringSubstr(symbol,3,3))>=0) {PendAllVol_Right_1++;}
{
AllAryOpenTime_1[AllVol_1]=OrderOpenTime(); AllAryProfit_1[AllVol_1]=orderprofit; AllAryTicket_1[AllVol_1]=OrderTicket();
AllVol_1++; if(AllVol_1==2) {AllLastLots_Num2_1=OrderLots();AllLastOpenPrice_Num2_1=OrderOpenPrice();}
if(OrderOpenTime()>=time0) {AllNewKVol_1++;}//当前K线中已建仓数量
if(OrderOpenTime()>=iTime(Symbol(),1440,0)) {AllVol_Day_1++;AllProfit_Day_1+=orderprofit;}
if(orderprofit>0) {AllTPVol_1++;} if(orderprofit<=0) {AllSLVol_1++;}
AllLots_1=AllLots_1+OrderLots(); //MarketInfo(symbol, MODE_MARGINREQUIRED) 1标准手所需保证金(每1手获利10美元所需微点)NPoint=10/tickvalue;
AllProfit_1=AllProfit_1+OrderProfit()+OrderCommission()+OrderSwap();AllSwap_1=AllSwap_1+OrderCommission()+OrderSwap();
if((AllTPHighest_1<OrderProfit())||AllTPHighest_1==0) {AllTPHighest_1=OrderProfit();AllTPHighestPoint_1=MathAbs(OrderOpenPrice()-bid)/point;}
if((AllTPLowest_1>OrderProfit())||AllTPLowest_1==0) {AllTPLowest_1=OrderProfit();AllTPLowestPoint_1=MathAbs(OrderOpenPrice()-bid)/point;}
if(AllFirstOpenTime_1>OrderOpenTime()||AllFirstOpenTime_1==0) {AllFirstOpenTime_1=OrderOpenTime();AllFirstLots_1=OrderLots();AllFirstOpenPrice_1=OrderOpenPrice();AllFirstType_1=OrderType();AllFirstProfit_1=OrderProfit();} //最后单的入场时间。
if(AllLastOpenTime_1<OrderOpenTime()) {AllLastOpenTime_1=OrderOpenTime();AllLastLots_1=OrderLots();AllLastStopLoss_1=OrderStopLoss();AllLastOpenPrice_1=OrderOpenPrice();AllLastType_1=OrderType();AllLastProfit_1=OrderProfit();} //最后单的入场时间。
if(AllLowest_1>OrderOpenPrice()||AllLowest_1==0) {AllLowest_1=OrderOpenPrice();} //建仓最低价格。
if(AllHighest_1<OrderOpenPrice()) {AllHighest_1=OrderOpenPrice();} //建仓最高价格。
}
if(OrderType()==0)
{
BuyAryLots_1[BuyVol_1]=OrderLots();BuyAryOpenPrice_1[BuyVol_1]=OrderOpenPrice();BuyAryOpenTime_1[BuyVol_1]=OrderOpenTime(); BuyAryProfit_1[BuyVol_1]=orderprofit; BuyAryTicket_1[BuyVol_1]=OrderTicket();
BuyVol_1++; if(BuyVol_1==2) {BuyLastLots_Num2_1=OrderLots();BuyLastOpenPrice_Num2_1=OrderOpenPrice();} //if(BuyVol==2) {Last2BuyOpenPrice=OrderOpenPrice();}
if(OrderOpenTime()>=time0) {BuyNewKVol_1++;}
if(orderprofit>0) {BuyTPVol_1++;} if(orderprofit<=0) {BuySLVol_1++;} if(MathAbs(OrderOpenPrice()-ask)<100*1.0*point) {BuyVol_JianGe_1++;} //平仓后补仓
BuyLots_1=BuyLots_1+OrderLots();
if(BuyHLots_1<OrderLots()) {BuyHLots_1=OrderLots();}
if(BuyLLots_1>OrderLots()||BuyLLots_1==0) {BuyLLots_1=OrderLots();}
BuyAllOpenPrice_1=BuyAllOpenPrice_1+OrderOpenPrice()*OrderLots();
BuyProfit_1=BuyProfit_1+OrderProfit()+OrderCommission()+OrderSwap();BuySwap_1+=OrderCommission()+OrderSwap();
if(BuyFirstOpenTime_1>OrderOpenTime()||BuyFirstOpenTime_1==0) {BuyFirstOpenTime_1=OrderOpenTime();BuyFirstLots_1=OrderLots();BuyFirstOpenPrice_1=OrderOpenPrice();} //最先交易的多单入场时间与价格。
if(BuyLastOpenTime_1<OrderOpenTime()||BuyLastOpenTime_1==0) {BuyLastOpenTime_1=OrderOpenTime();BuyLastStopLoss_1=OrderStopLoss();BuyLastLots_1=OrderLots();BuyLastProfit_1=orderprofit;BuyLastOpenPrice_1=OrderOpenPrice();} //最后交易的多单入场时间。if(BuyVol==1)也可以。
if(BuyLowest_1>OrderOpenPrice()||BuyLowest_1==0) {BuyLowest_1=OrderOpenPrice();BuyLowestLots_1=OrderLots();} //买单中建仓最低价格。
if(BuyHighest_1<OrderOpenPrice()) {BuyHighest_1=OrderOpenPrice();BuyHighestLots_1=OrderLots();BuyHighestProfit_1=orderprofit;BuyHighestTicket_1=orderticket;} //买单中建仓最高价格。
}
if(OrderType()==1)
{
SelAryLots_1[SelVol_1]=OrderLots();SelAryOpenPrice_1[SelVol_1]=OrderOpenPrice();SelAryOpenTime_1[SelVol_1]=OrderOpenTime(); SelAryProfit_1[SelVol_1]=orderprofit; SelAryTicket_1[SelVol_1]=OrderTicket();
SelVol_1++; if(SelVol_1==2) {SelLastLots_Num2_1=OrderLots();SelLastOpenPrice_Num2_1=OrderOpenPrice();}
if(OrderOpenTime()>=time0) {SelNewKVol_1++;}
if(orderprofit>0) {SelTPVol_1++;} if(orderprofit<=0) {SelSLVol_1++;} if(MathAbs(OrderOpenPrice()-bid)<100*1.0*point) {SelVol_JianGe_1++;} //平仓后补仓
SelLots_1=SelLots_1+OrderLots();
if(SelHLots_1<OrderLots()) {SelHLots_1=OrderLots();}
if(SelLLots_1>OrderLots()||SelLLots_1==0) {SelLLots_1=OrderLots();}
SelAllOpenPrice_1=SelAllOpenPrice_1+OrderOpenPrice()*OrderLots();
SelProfit_1=SelProfit_1+OrderProfit()+OrderCommission()+OrderSwap();SelSwap_1+=OrderCommission()+OrderSwap();
if(SelFirstOpenTime_1>OrderOpenTime()||SelFirstOpenTime_1==0) {SelFirstOpenTime_1=OrderOpenTime();SelFirstLots_1=OrderLots();SelFirstOpenPrice_1=OrderOpenPrice();} //最先交易的卖单入场时间与价格。
if(SelLastOpenTime_1<OrderOpenTime()||SelLastOpenTime_1==0) {SelLastOpenTime_1=OrderOpenTime();SelLastStopLoss_1=OrderStopLoss();SelLastLots_1=OrderLots();SelLastProfit_1=orderprofit;SelLastOpenPrice_1=OrderOpenPrice();} //最后交易的卖单入场时间。if(SelVol==1)也可以。
if(SelLowest_1>OrderOpenPrice()||SelLowest_1==0) {SelLowest_1=OrderOpenPrice();SelLowestLots_1=OrderLots();SelLowestProfit_1=orderprofit;SelLowestTicket_1=orderticket;} //卖单中建仓最低价格。
if(SelHighest_1<OrderOpenPrice()) {SelHighest_1=OrderOpenPrice();SelHighestLots_1=OrderLots();} //卖单中建仓最高价格。
}
}
}
}
}
double BuyMAPrice_1=0; //请应用时确保 BuyMAPrice>0 //均价于尾单 (AllBuyOpenPrice_1+ask*BWaitOpenLots)/(BuyLots_1+BWaitOpenLots)=BuyLastOpenPrice_1 //(AllBuyOpenPrice_1-BuyLastOpenPrice_1*BuyLots_1)/(BuyLastOpenPrice_1-ask)=BWaitOpenLots
if(BuyLots_1>0) {BuyMAPrice_1=NormalizeDouble(BuyAllOpenPrice_1/BuyLots_1,digits);}
double SelMAPrice_1=0; //请应用时确保 SelMAPrice>0 //均价于尾单 (AllSelOpenPrice_1+bid*SWaitOpenLots)/(SelLots_1+SWaitOpenLots)=LastSelOpenPrice_1 //(AllSelOpenPrice_1-LastSelOpenPrice_1*SelLots_1)/(LastSelOpenPrice_1-bid)=SWaitOpenLots
if(SelLots_1>0) {SelMAPrice_1=NormalizeDouble(SelAllOpenPrice_1/SelLots_1,digits);}
if(AllVol_1>0) {ArrayResize(AllAryProfit_1,AllVol_1);ArrayResize(AllAryTicket_1,AllVol_1);ArrayResize(AllAryOpenTime_1,AllVol_1);ArraySort(AllAryProfit_1,WHOLE_ARRAY,0,MODE_ASCEND);ArraySort(AllAryTicket_1,WHOLE_ARRAY,0,MODE_ASCEND);}
if(BuyVol_1>0) {ArrayResize(BuyAryOpenPrice_1,BuyVol_1);ArrayResize(BuyAryProfit_1,BuyVol_1);ArrayResize(BuyAryTicket_1,BuyVol_1);ArrayResize(BuyAryOpenTime_1,BuyVol_1);ArraySort(BuyAryOpenPrice_1,WHOLE_ARRAY,0,MODE_ASCEND);ArraySort(BuyAryOpenTime_1,WHOLE_ARRAY,0,MODE_ASCEND);}
if(SelVol_1>0) {ArrayResize(SelAryOpenPrice_1,SelVol_1);ArrayResize(SelAryProfit_1,SelVol_1);ArrayResize(SelAryTicket_1,SelVol_1);ArrayResize(SelAryOpenTime_1,SelVol_1);ArraySort(SelAryOpenPrice_1,WHOLE_ARRAY,0,MODE_ASCEND);ArraySort(SelAryOpenTime_1,WHOLE_ARRAY,0,MODE_ASCEND);}
if(AllVol_1>0&&(InitAProfitHest_1[s]==0||InitAProfitHest_1[s]<AllProfit_1)) {InitAProfitHest_1[s]=AllProfit_1;} if(AllVol_1==0) {InitAProfitHest_1[s]=0;}
if(AllVol_1>0&&(InitAProfitLest_1[s]==0||InitAProfitLest_1[s]>AllProfit_1)) {InitAProfitLest_1[s]=AllProfit_1;} if(AllVol_1==0) {InitAProfitLest_1[s]=0;}
if(AllVol_1==0) {InitAVol_1[s]=0;} if(AllVol_1>0&&InitAVol_1[s]<AllVol_1) {InitAVol_1[s]=AllVol_1;} if(BuyVol_1==0) {InitBModifyVol_1[s]=0;InitBVol_1[s]=0;} if(SelVol_1==0) {InitSModifyVol_1[s]=0;InitSVol_1[s]=0;}
//免费赠送的统计显示xxs //,"\n净保证金:"+DoubleToStr(AccountMargin(),1)+" 当前总保证金:"+DoubleToStr(AllLots_1*marginrequired,1)+" 当前净保证金:"+DoubleToStr((AllLots_1-MathMin(BuyLots_1,SelLots_1))*marginrequired,1)
//string CommentSpace; int WindowWidth=int((ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0)-110)/3);for(int i=0;i<WindowWidth;i++) {CommentSpace+=" ";}
static string 内容[];ArrayResize(内容,InitAryVol);int Aryi=0;
内容[Aryi]="【免费赠送的统计】";Aryi++;
内容[Aryi]="最小手数:"+DoubleToStr(MarketInfo(Symbol(), MODE_MINLOT),2)+" 最小止损:"+DoubleToStr(MarketInfo(Symbol(),MODE_STOPLEVEL),2)+" 点差: "+DoubleToStr((Ask-Bid)/Point,0);Aryi++;
内容[Aryi]="平台:"+TimeToStr(TimeCurrent())+" 北京:"+TimeToStr(TimeLocal(),TIME_SECONDS);Aryi++; //杠杆:AccountLeverage()。500.00
内容[Aryi]="---------";Aryi++;
内容[Aryi]="多单单数:"+IntegerToString(BuyVol_1)+" 多单手数:"+DoubleToString(BuyLots_1,2)+" 多单盈亏:"+DoubleToString(BuyProfit_1,2);Aryi++;
内容[Aryi]="空单单数:"+IntegerToString(SelVol_1)+" 空单手数:"+DoubleToString(SelLots_1,2)+" 空单盈亏:"+DoubleToString(SelProfit_1,2);Aryi++;
内容[Aryi]="---------";Aryi++;
内容[Aryi]="账户余额:"+DoubleToString(AccountBalance(),2)+" 账户净值:"+DoubleToString(AccountEquity(),2);Aryi++;
内容[Aryi]="合计盈亏:"+DoubleToString(AllProfit_1,2)+" Magic:"+(string)Magic_1;Aryi++; //8
for(int j=0;j<=8&&A_是否显示免费统计信息;j++)
{
if(内容[j]=="") {break;}
int 信息距离上边N=20;int 信息间隔N=18;int 信息大小=10;
CreateLabel("Name_YCEA"+IntegerToString(j),A_信息离左边距离N,信息距离上边N+j*信息间隔N,""+内容[j],信息大小,0,ANCHOR_LEFT_UPPER,A_信息颜色);
//CreateLabel(IntegerToString(j)+"Name_YCEA",A_信息离左边距离N,信息距离上边N+j*信息间隔N,""+内容[j],信息大小,1,ANCHOR_RIGHT_UPPER,A_信息颜色);
}
//二次统计 ttj-统计 或者通过“注释”来区分。 通过Magic来区分,一劳永逸!
int BuyDwVol_1=0,BuyUpVol_1=0,PendBuyDwVol_1=0,PendBuyUpVol_1=0,PendSelDwVol_1=0,PendSelUpVol_1=0,SelDwVol_1=0,SelUpVol_1=0;
if(orderstotals>=0)
{
for(int i=orderstotals-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
if(OrderSymbol()==symbol&&OrderMagicNumber()==Magic_1)
{
if(OrderType()==0)
{
if(OrderOpenPrice()>BuyFirstOpenPrice_1) {BuyUpVol_1++;}
if(OrderOpenPrice()<BuyFirstOpenPrice_1) {BuyDwVol_1++;}
}
if(OrderType()==1)
{
if(OrderOpenPrice()>SelFirstOpenPrice_1) {SelUpVol_1++;}
if(OrderOpenPrice()<SelFirstOpenPrice_1) {SelDwVol_1++;}
}
if(OrderType()==0||OrderType()==2||OrderType()==4)
{
if(OrderOpenPrice()>BuyFirstOpenPrice_1) {PendBuyUpVol_1++;}
if(OrderOpenPrice()<BuyFirstOpenPrice_1) {PendBuyDwVol_1++;}
}
if(OrderType()==1||OrderType()==3||OrderType()==5)
{
if(OrderOpenPrice()>SelFirstOpenPrice_1) {PendSelUpVol_1++;}
if(OrderOpenPrice()<SelFirstOpenPrice_1) {PendSelDwVol_1++;}
}
}
}
}
}
//历史统计 ttj-统计 OrderProfit()+OrderCommission()+OrderSwap() a-z排列
double HAllLastLots_Close_1=0,HAllLastClosePrice_Close_1=0,HAllLastClosePrice_One_1=0,HAllLastType_Close_1=8,HAllLastLots_1=0,HAllLastLots_One_1=0,HAllLastOpenPrice_Close_1=0,HAllLastOpenPrice_One_1=0,HAllLastPoint_Close_1=0,HAllLastProfit_Close_1=0,HAllLastProfit_1=0,HAllLastProfit_One_1=0,HAllLastSLLots_Close_1=0,HAllLastTPLots_Close_1=0;
double HAllLots_1=0,HAllLots_Day_1=0,HAllLots_Week_1=0,HAllProfit_1=0,HAllProfit_Day_1=0,HAllProfit_Week_1=0,HAllSLProfit_Continue_1=0,HAllTPProfit_Continue_1=0;
double HBuyLastClosePrice_1=0,HBuyLastClosePrice_One_1=0,HBuyLastCloseVol_One_1=0,HBuyLastLots_1=0,HBuyLastLots_One_1=0,HBuyLastOpenPrice_One_1=0,HBuyLastProfit_1=0,HBuyLastProfit_One_1=0,HBuyLastSLLots_1=0,HBuyLastTPLots_1=0,HSelLastClosePrice_1=0,HSelLastClosePrice_One_1=0,HSelLastCloseVol_One_1=0,HSelLastLots_1=0,HSelLastLots_One_1=0,HSelLastOpenPrice_One_1=0,HSelLastProfit_1=0,HSelLastProfit_One_1=0,HSelLastSLLots_1=0,HSelLastTPLots_1=0;
datetime HAllLastCloseTime_1=0,HAllLastOpenTime_1=0,HAllLastCloseTime_One_1=0,HBuyLastCloseTime_1=0,HBuyLastCloseTime_One_1=0,HBuyLastOpenTime_1=0,HSelLastCloseTime_1=0,HSelLastCloseTime_One_1=0,HSelLastOpenTime_1=0;
datetime HN_AllLastOpenTime_1=AllLastOpenTime_1; double HN_AllLastType_1=AllLastType_1,HN_AllLastProfit_1=AllLastProfit_1,HN_AllLastLots_1=AllLastLots_1; datetime HN_BuyLastOpenTime_1=BuyLastOpenTime_1; double HN_BuyLastProfit_1=BuyLastProfit_1,HN_BuyLastLots_1=BuyLastLots_1; datetime HN_SelLastOpenTime_1=SelLastOpenTime_1; double HN_SelLastProfit_1=SelLastProfit_1,HN_SelLastLots_1=SelLastLots_1;
int HAllLastCloseVol_One_1=0,HAllLastType_1=8,HAllLastType_One_1=8,HAllNewKCloseVol_1=0,HAllNewKVol_1=0,HAllSLVol_1=0,HAllSLVol_Continue_1=0,HAllSLVol_TempCon_1=0,HAllTPVol_1=0,HAllTPVol_Continue_1=0,HAllTPVol_TempCon_1=0,HAllVol_1=0,HAllVol_AllSymbol_1=0,HAllVol_Day_1=0,HAllVol_Week_1=0,HBuyNewKVol_1=0,HBuyNewKCloseVol_1=0,HBuyVol_1=0,HPendAllVol_1=0,HSelNewKVol_1=0,HSelNewKCloseVol_1=0,HSelVol_1=0;
//-- double HAllOpenPrice_不计分批_1=0; if(OrderOpenPrice()==HAllOpenPrice_不计分批_1) {continue;} if(OrderOpenPrice()!=HAllOpenPrice_不计分批_1||HAllOpenPrice_不计分批_1==0) {HAllOpenPrice_不计分批_1=OrderOpenPrice();} //可令加条件
double CycleProfit_1=0; static int InitAllCycleVol_1=0; static datetime InitCycleLastTime_1=TimeCurrent(); //static int 剩余轮数=0,TickLastCloseVol_Temp=0;if(剩余轮数==0&&TickLastCloseVol_Temp>=3) {剩余轮数=StrToInteger(ObjectGetString(0,"LunShu_Edit_YCEA",OBJPROP_TEXT));} //if(MathAbs(剩余轮数-StrToInteger(ObjectGetString(0,"LunShu_Edit_YCEA",OBJPROP_TEXT)))>=3) {剩余轮数=StrToInteger(ObjectGetString(0,"LunShu_Edit_YCEA",OBJPROP_TEXT));} if(){剩余轮数--;} //TickLastCloseVol_Temp=TickLastCloseVol_1;
double HAllProfit_temp_1=0; int HAllVol_temp_1=0; static datetime HAllTime_temp_1=TimeCurrent(); //HAllProfit_temp_1加仓EA起盈亏,盈利创新高后重置
if(OrdersHistoryTotal()>0)
{
for(int i=OrdersHistoryTotal()-1;i>=0;i--) //建仓晚至早_非平仓时间
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
{
HAllVol_AllSymbol_1++; if(OrderCloseTime()<=InitTime||HAllVol_AllSymbol_1>=1000) {break;}
int orderticket=OrderTicket();datetime orderopentime=OrderOpenTime();double orderlots=OrderLots(),orderopenprice=OrderOpenPrice(),orderpoint=MarketInfo(OrderSymbol(), MODE_POINT),orderprofit=OrderProfit()+OrderCommission()+OrderSwap();
if(OrderSymbol()==symbol&&OrderMagicNumber()==Magic_1) //&&OrderType()<=1,6入金,7出金
{
HPendAllVol_1++;
if(OrderCloseTime()>=InitCycleLastTime_1) {CycleProfit_1+=orderprofit;}
if(OrderType()==0||OrderType()==1)
{
HAllVol_1++;
if(OrderOpenTime()>=time0) {HAllNewKVol_1++;} //用 iTime(symbol,1,0) 回测时无法调取数据的bug 碰到获取Ask和建仓价格不一致时也可用(或间隔60秒开仓一次)
if(OrderCloseTime()>=time0) {HAllNewKCloseVol_1++;}
HAllLots_1+=OrderLots(); HAllProfit_1+=orderprofit;
if(OrderCloseTime()>HAllTime_temp_1) {HAllProfit_temp_1+=orderprofit;HAllVol_temp_1++;}
if(OrderCloseTime()>=iTime(symbol,1440,0)) {HAllVol_Day_1++;HAllProfit_Day_1+=orderprofit;HAllLots_Day_1+=OrderLots();}
if(OrderCloseTime()>=iTime(symbol,10080,0)) {HAllVol_Week_1++;HAllProfit_Week_1+=orderprofit;HAllLots_Week_1+=OrderLots();}
if(OrderProfit()>0) {HAllTPVol_TempCon_1++;} if(HAllSLVol_TempCon_1==0&&OrderProfit()>0) {HAllTPVol_Continue_1++;HAllTPProfit_Continue_1+=OrderProfit()+OrderCommission()+OrderSwap();}
if(OrderProfit()<=0) {HAllSLVol_TempCon_1++;} if(HAllTPVol_TempCon_1==0&&OrderProfit()<=0) {HAllSLVol_Continue_1++;HAllSLProfit_Continue_1+=OrderProfit()+OrderCommission()+OrderSwap();}
if(HAllLastCloseTime_1==0||HAllLastCloseTime_1<OrderCloseTime())
{
HAllLastCloseTime_1=OrderCloseTime();HAllLastType_Close_1=OrderType();HAllLastLots_Close_1=OrderLots();HAllLastClosePrice_Close_1=OrderClosePrice();HAllLastOpenPrice_Close_1=OrderOpenPrice();
HAllLastProfit_Close_1=OrderProfit()+OrderCommission()+OrderSwap(); if(OrderType()==0) {HAllLastPoint_Close_1=OrderClosePrice()-OrderOpenPrice();} if(OrderType()==1) {HAllLastPoint_Close_1=OrderOpenPrice()-OrderClosePrice();}
//if(OrderProfit()<=0) {HAllLastSLLots_Close_1=OrderLots();HAllSLVol_1++;}
//if(OrderProfit()>0) {HAllLastTPLots_Close_1=OrderLots();HAllTPVol_1++;}
if((OrderType()==0&&OrderStopLoss()>0&&OrderClosePrice()<=OrderStopLoss())||(OrderType()==1&&OrderStopLoss()>0&&OrderClosePrice()>=OrderStopLoss())) {HAllLastSLLots_Close_1=OrderLots();HAllSLVol_1++;}
if((OrderType()==0&&OrderTakeProfit()>0&&OrderClosePrice()>=OrderTakeProfit())||(OrderType()==1&&OrderTakeProfit()>0&&OrderClosePrice()<=OrderTakeProfit())) {HAllLastTPLots_Close_1=OrderLots();HAllTPVol_1++;}
}
if(HAllLastOpenTime_1==0||HAllLastOpenTime_1<OrderOpenTime())
{
HAllLastOpenTime_1=OrderOpenTime();HAllLastType_1=OrderType();HAllLastLots_1=OrderLots();HAllLastProfit_1=orderprofit;
if(AllLastOpenTime_1<HAllLastOpenTime_1) {HN_AllLastType_1=HAllLastType_1;HN_AllLastProfit_1=HAllLastProfit_1;HN_AllLastLots_1=HAllLastLots_1;HN_AllLastOpenTime_1=HAllLastOpenTime_1;}
}
//最后一批平仓单
if(OrderCloseTime()>=InitTime&&(HAllLastCloseTime_One_1==0||OrderCloseTime()>HAllLastCloseTime_One_1-10)) //&&OrderOpenPrice()==HLastOneOpenPrice
{
HAllLastProfit_One_1+=OrderProfit()+OrderCommission()+OrderSwap();HAllLastLots_One_1+=OrderLots();
HAllLastCloseTime_One_1=OrderCloseTime();HAllLastCloseVol_One_1++;
HAllLastOpenPrice_One_1=OrderOpenPrice();HAllLastClosePrice_One_1=OrderClosePrice(); HAllLastType_One_1=OrderType();
}
}
if(OrderType()==0)
{
HBuyVol_1++;
if(OrderOpenTime()>=time0) {HBuyNewKVol_1++;}
if(OrderCloseTime()>=time0) {HBuyNewKCloseVol_1++;}
if(HBuyLastCloseTime_1==0||HBuyLastCloseTime_1<OrderCloseTime())
{
HBuyLastCloseTime_1=OrderCloseTime();
HBuyLastClosePrice_1=OrderClosePrice();
if(OrderProfit()<=0) {HBuyLastSLLots_1=OrderLots();}
if(OrderProfit()>0) {HBuyLastTPLots_1=OrderLots();}
}
if(HBuyLastOpenTime_1==0||HBuyLastOpenTime_1<OrderOpenTime())
{
HBuyLastOpenTime_1=OrderOpenTime();;HBuyLastLots_1=OrderLots();HBuyLastProfit_1=orderprofit;
if(BuyLastOpenTime_1<HBuyLastOpenTime_1) {HN_BuyLastProfit_1=HBuyLastProfit_1;HN_BuyLastLots_1=HBuyLastLots_1;HN_BuyLastOpenTime_1=HBuyLastOpenTime_1;}
}
//最后一批平仓单
if(OrderCloseTime()>=InitTime&&(HBuyLastCloseTime_One_1==0||OrderCloseTime()>HBuyLastCloseTime_One_1-10)) //&&OrderOpenPrice()==HLastOneOpenPrice
{
HBuyLastProfit_One_1+=OrderProfit()+OrderCommission()+OrderSwap();HBuyLastLots_One_1+=OrderLots();
HBuyLastCloseTime_One_1=OrderCloseTime();HBuyLastCloseVol_One_1++;
HBuyLastOpenPrice_One_1=OrderOpenPrice();HBuyLastClosePrice_One_1=OrderClosePrice();
}
}
if(OrderType()==1)
{
HSelVol_1++;
if(OrderOpenTime()>=time0) {HSelNewKVol_1++;}
if(OrderCloseTime()>=time0) {HSelNewKCloseVol_1++;}
if(HSelLastCloseTime_1==0||HSelLastCloseTime_1<OrderCloseTime())
{
HSelLastCloseTime_1=OrderCloseTime();
HSelLastClosePrice_1=OrderClosePrice();
if(OrderProfit()<=0) {HSelLastSLLots_1=OrderLots();}
if(OrderProfit()>0) {HSelLastTPLots_1=OrderLots();}
}
if(HSelLastOpenTime_1==0||HSelLastOpenTime_1<OrderOpenTime())
{
HSelLastOpenTime_1=OrderOpenTime();;HSelLastLots_1=OrderLots();HSelLastProfit_1=orderprofit;
if(SelLastOpenTime_1<HSelLastOpenTime_1) {HN_SelLastProfit_1=HSelLastProfit_1;HN_SelLastLots_1=HSelLastLots_1;HN_SelLastOpenTime_1=HSelLastOpenTime_1;}
}
//最后一批平仓单
if(OrderCloseTime()>=InitTime&&(HSelLastCloseTime_One_1==0||OrderCloseTime()>HSelLastCloseTime_One_1-10)) //&&OrderOpenPrice()==HLastOneOpenPrice
{
HSelLastProfit_One_1+=OrderProfit()+OrderCommission()+OrderSwap();HSelLastLots_One_1+=OrderLots();
HSelLastCloseTime_One_1=OrderCloseTime();HSelLastCloseVol_One_1++;
HSelLastOpenPrice_One_1=OrderOpenPrice();HSelLastClosePrice_One_1=OrderClosePrice();
}
}
if(HPendAllVol_1>100/*/&&!IsTesting()/*/) {break;}
}
}
}
}
if(HAllProfit_temp_1>0) {HAllTime_temp_1=HAllLastCloseTime_1;}
int MoveEAVolEd=0,MoveEAVol=5;
if(OrdersHistoryTotal()>0)
{
for(int i=OrdersHistoryTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
{
if(OrderCloseTime()<=InitTime) {break;}
if(OrderSymbol()==symbol&&OrderType()<=1&&OrderMagicNumber()==Magic_1) //&&OrderType()<=1
{
if(OrderCloseTime()-OrderOpenTime()<=3) {MoveEAVolEd++;}
if(OrderCloseTime()-OrderOpenTime()>3) {break;}
}
}
}
}
if(MoveEAVolEd>=MoveEAVol)
{
Alert("★风险提醒:快进快出次数已大于"+IntegerToString(MoveEAVol)+"次,为防范爆仓风险,EA已自动退出。请检查建平条件是否冲突!——"+TimeToStr(TimeCurrent()));
Alert("★风险提醒:快进快出次数已大于"+IntegerToString(MoveEAVol)+"次,为防范爆仓风险,EA已自动退出。请检查建平条件是否冲突!——"+TimeToStr(TimeCurrent()));
Alert("★风险提醒:快进快出次数已大于"+IntegerToString(MoveEAVol)+"次,为防范爆仓风险,EA已自动退出。请检查建平条件是否冲突!——"+TimeToStr(TimeCurrent()));
ExpertRemove();
}
//指标···建仓条件 zzb-指标
static bool InitStopEA_1[];ArrayResize(InitStopEA_1,InitAryVol); static datetime InitStopTime_1[];ArrayResize(InitStopTime_1,InitAryVol); //全平后禁止建仓:static int InitVol_1=0; if(InitVol_1==0&&AllVol>0) {InitVol_1=AllVol;} if(是否开启全平后禁止建仓等待重新加载&&AllVol==0&&InitVol_1>0) {StopEA_1[s]=true;}
static int TickLastCloseVol_1=0; static datetime TickLastCloseTime_1=0; if(TickLastCloseTime_1<HAllLastCloseTime_1) {TickLastCloseVol_1=0;TickLastCloseTime_1=HAllLastCloseTime_1;}
static int TickNewKVol_1=0; static datetime TickNewKTime_1=0; if(TickNewKTime_1<time0) {TickNewKVol_1=0;TickNewKTime_1=TimeCurrent();} TickNewKVol_1++;
double 预付款比例=100000000; if(AccountMargin()>0){预付款比例=AccountEquity()/AccountMargin()*100;} //预付款比率,200,表示200%。对比时不用百分比。平仓
double MAA1_C=iMA(symbol,0,C_均线周期A,0,C_移动平均AB,C_价格应用AB,1);
double MAA2_C=iMA(symbol,0,C_均线周期A,0,C_移动平均AB,C_价格应用AB,1+1);
double MAB1_C=iMA(symbol,0,C_均线周期B,0,C_移动平均AB,C_价格应用AB,1);
double MAB2_C=iMA(symbol,0,C_均线周期B,0,C_移动平均AB,C_价格应用AB,1+1);
double MAa1=iMA(symbol,0,均线周期a,0,移动平均,价格应用,交易模式);
double MAa2=iMA(symbol,0,均线周期a,0,移动平均,价格应用,交易模式+1);
double MAb1=iMA(symbol,0,均线周期b,0,移动平均,价格应用,交易模式);
double MAb2=iMA(symbol,0,均线周期b,0,移动平均,价格应用,交易模式+1);
double MAc1=iMA(symbol,0,均线周期c,0,移动平均,价格应用,交易模式);
double MAc2=iMA(symbol,0,均线周期c,0,移动平均,价格应用,交易模式+1);
double MAd1=iMA(symbol,0,均线周期d,0,移动平均,价格应用,交易模式);
double MAd2=iMA(symbol,0,均线周期d,0,移动平均,价格应用,交易模式+1);
double MAe1=iMA(symbol,0,均线周期e,0,移动平均,价格应用,交易模式);
double MAe2=iMA(symbol,0,均线周期e,0,移动平均,价格应用,交易模式+1);
double MAf1=iMA(symbol,0,均线周期f,0,移动平均,价格应用,交易模式);
double MAf2=iMA(symbol,0,均线周期f,0,移动平均,价格应用,交易模式+1);
double MAa1_排列=iMA(symbol,0,排列均线a,0,排列平均,排列价格,交易模式);
double MAa2_排列=iMA(symbol,0,排列均线a,0,排列平均,排列价格,交易模式+1);
double MAb1_排列=iMA(symbol,0,排列均线b,0,排列平均,排列价格,交易模式);
double MAb2_排列=iMA(symbol,0,排列均线b,0,排列平均,排列价格,交易模式+1);
double MAc1_排列=iMA(symbol,0,排列均线c,0,排列平均,排列价格,交易模式);
double MAc2_排列=iMA(symbol,0,排列均线c,0,排列平均,排列价格,交易模式+1);
double MAd1_排列=iMA(symbol,0,排列均线d,0,排列平均,排列价格,交易模式);
double MAd2_排列=iMA(symbol,0,排列均线d,0,排列平均,排列价格,交易模式+1);
double MAe1_排列=iMA(symbol,0,排列均线e,0,排列平均,排列价格,交易模式);
double MAe2_排列=iMA(symbol,0,排列均线e,0,排列平均,排列价格,交易模式+1);
double MAf1_排列=iMA(symbol,0,排列均线f,0,排列平均,排列价格,交易模式);
double MAf2_排列=iMA(symbol,0,排列均线f,0,排列平均,排列价格,交易模式+1);
//平仓指标 ppc-平仓
int ModifyBVol_1[],ModifySVol_1[];ArrayResize(ModifyBVol_1,InitAryVol);ArrayResize(ModifySVol_1,InitAryVol);static datetime InitBTime_1[],InitSTime_1[];ArrayResize(InitBTime_1,InitAryVol);ArrayResize(InitSTime_1,InitAryVol); //平仓类,不可用于移动止损等
bool BuyOrder_Close=false,SelOrder_Close=false,AllOrder_Close=false;
if(总盈利大于N美元全平_0为关闭!=0&&AllProfit_1>总盈利大于N美元全平_0为关闭){AllOrder_Close=true;}
if(总亏损大于N美元全平_0为关闭!=0&&AllProfit_1<-总亏损大于N美元全平_0为关闭){AllOrder_Close=true;}
if(总盈利大于总手数乘N全平_0为关闭!=0&&AllProfit_1>总盈利大于总手数乘N全平_0为关闭*MathAbs(AllLots_1)*tickvalue){AllOrder_Close=true;}
if(总亏损大于总手数乘N全平_0为关闭!=0&&AllProfit_1<-总亏损大于总手数乘N全平_0为关闭*MathAbs(AllLots_1)*tickvalue){AllOrder_Close=true;}
if(总亏损大于余额百分之N全平_0为关闭!=0&&AllProfit_1<-总亏损大于余额百分之N全平_0为关闭/100.0*accountbalance){AllOrder_Close=true;}
//平仓·必要时放到建仓上方·制作EA关系放到此处
if(OrdersTotal()>0)//&&IsTradeAllowed()
{
for(int i=OrdersTotal()-1;i>=0;i--) //150错误。--写成++会卡且100%漏平(,除非int orderstotal=orderstotals;for(int i=0;i<orderstotal;i++) if(OrderSelect(AllAryTicket_1[i],SELECT_BY_TICKET)==true)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
RefreshRates();//ask=MarketInfo(OrderSymbol(),MODE_ASK);bid=MarketInfo(OrderSymbol(),MODE_BID);
if(ask==0||bid==0){continue;}int OrderK0=iBarShift(OrderSymbol(),period_T1,OrderOpenTime()),OrderK1=OrderK0+1;
string ordersymbol=OrderSymbol(),ordercomment=OrderComment(); int orderticket=OrderTicket(),orderdigs=int(MarketInfo(OrderSymbol(),MODE_DIGITS));datetime orderopentime=OrderOpenTime(),orderclosetime=OrderCloseTime();
double orderlots=OrderLots(),orderopenprice=OrderOpenPrice(),orderticksize=MarketInfo(OrderSymbol(),MODE_TICKSIZE),orderpoint=MarketInfo(OrderSymbol(),MODE_POINT),orderprofit=OrderProfit()+OrderCommission()+OrderSwap();
if(OrderSymbol()==symbol&&OrderMagicNumber()==Magic_1)
{
//初始止损 zzs-止损
if(OrderSelect(orderticket,SELECT_BY_TICKET)==false) {continue;} RefreshRates();
double BuyStopLoss=OrderStopLoss(),SelStopLoss=OrderStopLoss(),BuyTakeProfit=OrderTakeProfit(),SelTakeProfit=OrderTakeProfit(); //double BuyStopLoss=0,SelStopLoss=0,BuyTakeProfit=0,SelTakeProfit=0;
if(A_单向均价止损N微点_0为关闭!=0&&InitBModifyVol_1[s]==0) {BuyStopLoss=BuyMAPrice_1-A_单向均价止损N微点_0为关闭*orderpoint;}
if(A_单向均价止损N微点_0为关闭!=0&&InitSModifyVol_1[s]==0) {SelStopLoss=SelMAPrice_1+A_单向均价止损N微点_0为关闭*orderpoint;}
//---
if(单向均价止盈N微点_0为关闭!=0) {BuyTakeProfit=BuyMAPrice_1+单向均价止盈N微点_0为关闭*orderpoint;}
if(单向均价止盈N微点_0为关闭!=0) {SelTakeProfit=SelMAPrice_1-单向均价止盈N微点_0为关闭*orderpoint;}
BuyStopLoss=MathRound(BuyStopLoss/orderticksize)*orderticksize;SelStopLoss=MathRound(SelStopLoss/orderticksize)*orderticksize; BuyTakeProfit=MathRound(BuyTakeProfit/orderticksize)*orderticksize;SelTakeProfit=MathRound(SelTakeProfit/orderticksize)*orderticksize;
if((OrderType()==0||OrderType()==2||OrderType()==4)&&(MathAbs(OrderStopLoss()-BuyStopLoss)>3*orderpoint||MathAbs(OrderTakeProfit()-BuyTakeProfit)>3*orderpoint)) //如果是可上下移动性止损,可采用:OrderStopLoss()!=BuyStopLoss 、MathAbs(OrderStopLoss()-BuyStopLoss)>3*Point简单暴力!
{
if(!OrderModify(OrderTicket(),OrderOpenPrice(),BuyStopLoss,BuyTakeProfit,0,clrBlue)){ErrorAlert(OrderSymbol(),"多:初损失败。如还有疑问,请联系QQ6266616。");}
}
if((OrderType()==1||OrderType()==3||OrderType()==5)&&(MathAbs(OrderStopLoss()-SelStopLoss)>3*orderpoint||MathAbs(OrderTakeProfit()-SelTakeProfit)>3*orderpoint)) //&&OrderStopLoss()==0&&OrderTakeProfit()==0
{
if(!OrderModify(OrderTicket(),OrderOpenPrice(),SelStopLoss,SelTakeProfit,0,clrRed)){ErrorAlert(OrderSymbol(),"空:初损失败。如还有疑问,请联系QQ6266616。");}
}
//标准移动止损yyd
if(OrderSelect(orderticket,SELECT_BY_TICKET)==false) {continue;} RefreshRates();
if(OrderType()==0&&B_单向均价盈利N微点后_0为关闭!=0&&B_追踪止损于盈利回撤N微点平仓_0为关闭!=0&&(bid-BuyMAPrice_1>=B_单向均价盈利N微点后_0为关闭*orderpoint||InitBModifyVol_1[s]>0)&&(OrderStopLoss()<bid-B_追踪止损于盈利回撤N微点平仓_0为关闭*orderpoint-0*orderpoint||OrderStopLoss()==0)) //OrderStopLoss()<bid-移动止损于回撤多少微点平仓*orderpoint-每盈利N微点移动一次*orderpoint
{
ModifyBVol_1[s]++;InitBModifyVol_1[s]++; //每N微点移动一次
if(!OrderModify(OrderTicket(),OrderOpenPrice(),bid-B_追踪止损于盈利回撤N微点平仓_0为关闭*orderpoint,OrderTakeProfit(),0,clrBlue)) {ErrorAlert(OrderSymbol(),"多:移损失败。如还有疑问,请联系QQ6266616。");} //&&TimeCurrent()-InitBTime_1[s]>B_每N分钟调整一次*60
}
if(OrderType()==1&&B_单向均价盈利N微点后_0为关闭!=0&&B_追踪止损于盈利回撤N微点平仓_0为关闭!=0&&(SelMAPrice_1-ask>=B_单向均价盈利N微点后_0为关闭*orderpoint||InitSModifyVol_1[s]>0)&&(OrderStopLoss()>ask+B_追踪止损于盈利回撤N微点平仓_0为关闭*orderpoint+0*orderpoint||OrderStopLoss()==0))
{
ModifySVol_1[s]++;InitSModifyVol_1[s]++; //int 追踪止损=B_追踪止损于盈利回撤N微点平仓+int((bid-OrderOpenPrice())/orderpoint)/B_盈利每增加N微点*B_移动止损增加N微点;
if(!OrderModify(OrderTicket(),OrderOpenPrice(),ask+B_追踪止损于盈利回撤N微点平仓_0为关闭*orderpoint,OrderTakeProfit(),0,clrRed)){ErrorAlert(OrderSymbol(),"空:移损失败。如还有疑问,请联系QQ6266616。");} //&&TimeCurrent()-InitSTime_1[s]>B_每N分钟调整一次*60
}
//平仓4108故后面 ppc-平仓
if(OrderSelect(orderticket,SELECT_BY_TICKET)==false) {continue;} RefreshRates();
if(OrderType()==0&&BuyVol_1>0&&(AllOrder_Close||BuyOrder_Close
||(bid!=0&&BuyStopLoss!=0&&bid<BuyStopLoss)||(bid!=0&&BuyTakeProfit!=0&&bid>BuyTakeProfit)
||(C_是否开启均线AB交叉全平&&MAA1_C>MAB1_C&&MAA2_C<=MAB2_C&&orderopentime<time0)
||(C_是否开启均线AB交叉全平&&MAA1_C<MAB1_C&&MAA2_C>=MAB2_C&&orderopentime<time0)
))
{
if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),500,clrBlue)) {ErrorAlert(OrderSymbol(),"多:平仓失败。如还有疑问,请联系QQ6266616。");} else{continue;} //i=orderstotals; //i--会抵消1
}
if(OrderType()==1&&SelVol_1>0&&(AllOrder_Close||SelOrder_Close
||(ask!=0&&SelStopLoss!=0&&ask>SelStopLoss)||(ask!=0&&SelTakeProfit!=0&&ask<SelTakeProfit)
||(C_是否开启均线AB交叉全平&&MAA1_C>MAB1_C&&MAA2_C<=MAB2_C&&orderopentime<time0)
||(C_是否开启均线AB交叉全平&&MAA1_C<MAB1_C&&MAA2_C>=MAB2_C&&orderopentime<time0)
))
{
if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),500,clrRed)) {ErrorAlert(OrderSymbol(),"空:平仓失败。如还有疑问,请联系QQ6266616。");} else{continue;} //i=orderstotals; //i--会抵消1
}
}
}
if(i==0&&ModifyBVol_1[s]>0) {InitBTime_1[s]=TimeCurrent();}
if(i==0&&ModifySVol_1[s]>0) {InitSTime_1[s]=TimeCurrent();}
}
}
//单量定义 ddl-单量
double OpenLots=A_建仓手数;
if(A_是否开启自动单量) {OpenLots=accountbalance/A_每N美元余额做001手*0.01;} // int 取整数,MathFloor 取更小整数,MathCeil 取更大整数 MathRound 取四舍五入整数。
//单量定义 ddl-单量 //static int Rand_1=MathRand()%5; static datetime RandTime_1=0; if(TimeCurrent()-RandTime_1>=C_每N秒随机一次) {Rand_1=MathRand()%5;RandTime_1=TimeCurrent();} //随机数字01234
double BWaitOpenLots=OpenLots; //可以用WaitOpenLots作为跳板来制作更复杂单量。
if(BuyVol_1>0&&ask>BuyHighest_1) {BWaitOpenLots=BuyHighestLots_1*顺势加仓倍率_1为关闭;}
if(BuyVol_1>0&&ask<BuyLowest_1) {BWaitOpenLots=BuyLowestLots_1*逆势加仓倍率_1为关闭;}
BWaitOpenLots=MathMin(MathMax(minlot,MathCeil((BWaitOpenLots-0.001)/minlot)*minlot),maxlot);
double SWaitOpenLots=OpenLots;
if(SelVol_1>0&&bid<SelLowest_1) {SWaitOpenLots=SelLowestLots_1*顺势加仓倍率_1为关闭;}
if(SelVol_1>0&&bid>SelHighest_1) {SWaitOpenLots=SelHighestLots_1*逆势加仓倍率_1为关闭;}
SWaitOpenLots=MathMin(MathMax(minlot,MathCeil((SWaitOpenLots-0.001)/minlot)*minlot),maxlot);
bool AOrder1=true;
if(AllVol_1==0&&HAllSLVol_1>0&&HAllLastProfit_One_1<0&&TimeCurrent()-HAllLastCloseTime_1<=A_直接止损后N秒内禁止建仓){AOrder1=false;}
if(AllVol_1==0&&HAllSLVol_1>0&&HAllLastProfit_One_1>=0&&TimeCurrent()-HAllLastCloseTime_1<=B_移动止损后N秒内禁止建仓){AOrder1=false;}
//共同条件
bool AllOrder=false;
if(TickLastCloseVol_1!=0/*/&&AllNewKVol_1+HAllNewKVol_1==0/*/&&!InitStopEA_1[s]&&TimeCurrent()-HN_AllLastOpenTime_1>=0&&AOrder1) {AllOrder=true;} //&&HN_AllLastOpenTime_1<Time[AryZZKi[1]] //(spread<=点差大于N微点禁止建仓_0为关闭||点差大于N微点禁止建仓_0为关闭==0)
bool BOrder1=false,SOrder1=false;
if(MAa1>MAa2&&MAb1>MAb2&&MAc1>MAc2&&MAd1>MAd2&&MAe1>MAe2&&MAf1>MAf2
&&(!是否开启均线排列过滤条件||(MAa1_排列>=MAb1_排列&&MAb1_排列>=MAc1_排列&&MAc1_排列>=MAd1_排列&&MAd1_排列>=MAe1_排列&&MAe1_排列>=MAf1_排列))) {BOrder1=true;}
if(MAa1<MAa2&&MAb1<MAb2&&MAc1<MAc2&&MAd1<MAd2&&MAe1<MAe2&&MAf1<MAf2
&&(!是否开启均线排列过滤条件||(MAa1_排列<=MAb1_排列&&MAb1_排列<=MAc1_排列&&MAc1_排列<=MAd1_排列&&MAd1_排列<=MAe1_排列&&MAe1_排列<=MAf1_排列))) {SOrder1=true;}
//建仓条件 jjc-建仓 //涉及多个Magic的条件,一定要记得【int Magic=0;且后续加上Magic==0的条件】,否则紊乱。
bool BuyOrder=false,SelOrder=false; RefreshRates();//(AllVol_1==0||TimeCurrent()-AllFirstOpenTime_1<5) //string B备注="No",S备注="No";int Magic=Magic_1;string 注释=注释_1;
if(AllVol_1==0&&BOrder1) {BuyOrder=true;} //&&((MAa2<=MAb2&&AllNewKVol_1+HAllNewKVol_1==0)||(HAllLastType_1==1&&交易模式==0))
if(AllVol_1==0&&SOrder1) {SelOrder=true;}
if(间隔N微点顺势加仓_0为关闭!=0&&BuyVol_1>0&&ask-BuyHighest_1>=间隔N微点顺势加仓_0为关闭*point&&BuyUpVol_1<单向顺势最大加仓次数/*/&&BOrder1/*/) {BuyOrder=true;} //TimeCurrent()-AllLastOpenTime_1>=至少间隔N分钟加仓_0为关闭*60
if(间隔N微点顺势加仓_0为关闭!=0&&SelVol_1>0&&SelLowest_1-bid>=间隔N微点顺势加仓_0为关闭*point&&SelDwVol_1<单向顺势最大加仓次数/*/&&SOrder1/*/) {SelOrder=true;}
if(间隔N微点逆势加仓_0为关闭!=0&&BuyVol_1>0&&BuyLowest_1-ask>=间隔N微点逆势加仓_0为关闭*point&&BuyDwVol_1<单向逆势最大加仓次数/*/&&BOrder1/*/) {BuyOrder=true;} //间隔加上点差,可让间隔性追踪止损提前触发
if(间隔N微点逆势加仓_0为关闭!=0&&SelVol_1>0&&bid-SelHighest_1>=间隔N微点逆势加仓_0为关闭*point&&SelUpVol_1<单向逆势最大加仓次数/*/&&SOrder1/*/) {SelOrder=true;}
//开多单 jjc-建仓
if(OrdersTotal()!=orderstotals||ask==0||bid==0){continue;} RefreshRates();
if(BuyOrder&&AllOrder) //&&TickNewKVol_1<=3&&HN_AllLastType_1!=0&&(AllVol_1>0||HAllVol_1==0)
{
int ticket=OrderSend(symbol,OP_BUY,BWaitOpenLots,MarketInfo(symbol,MODE_ASK),500,0,0,注释_1,Magic_1,0,clrBlue);//挂单成交时变号不变.
if(ticket>0)
{
Print("多:建仓成功。");InitAVol_1[s]++;InitBVol_1[s]++; //if(AllVol_1==0) {剩余轮数--;AllVol_1++;InitAllCycleVol_1++;}
}
else {ErrorAlert(symbol,"多:建仓失败。如还有疑问,请联系QQ6266616。");}
}
//开空单
RefreshRates(); //if(TimeCurrent()>=D'2017.06.28 01:57'||AllVol_1>0) {Print(HighKi," ",LowKi," ",ToUpCrossKi," ",ToDwCrossKi," "," "," "," ");ExpertRemove();}
if(SelOrder&&AllOrder) //&&TickNewKVol_1<=3&&HN_AllLastType_1!=1&&(AllVol_1>0||HAllVol_1==0)
{
int ticket=OrderSend(symbol,OP_SELL,SWaitOpenLots,MarketInfo(symbol,MODE_BID),500,0,0,注释_1,Magic_1,0,clrRed);
if(ticket>0)
{
Print("空:建仓成功。");InitAVol_1[s]++;InitSVol_1[s]++; //if(AllVol_1==0) {剩余轮数--;AllVol_1++;InitAllCycleVol_1++;}
}
else {ErrorAlert(symbol,"空:建仓失败。如还有疑问,请联系QQ6266616。");}
}
if(OrdersTotal()!=orderstotals||ask==0||bid==0) {continue;} TickLastCloseVol_1++;
}
//--
InitTickVol++;InitBid=Bid;
}
void CreateLabel(string Name,int XDistance,int YDistance,string StringText,int FontSize,int Corner,int Anchor,color TextColor)
{
if(ObjectFind(0,Name)==-1) //判断是否存在
{
ObjectCreate(0,Name,OBJ_LABEL,0,0,0); //第4个:WindowOnDropped()自适应窗口、ChartWindowFind()自适应第几个窗口、WindowFind("YCADX"+IntegerToString(ADX周期))查找在哪个窗口
ObjectSetString(0,Name,OBJPROP_FONT,"宋体"); //字体 宋体比微软雅黑更清晰,但大字体时更模糊。 "微软雅黑"
ObjectSetInteger(0,Name,OBJPROP_FONTSIZE,FontSize);//文字大小
ObjectSetInteger(0,Name,OBJPROP_CORNER,Corner);//放哪个角落 0123为左右上下
ObjectSetInteger(0,Name,OBJPROP_SELECTABLE,0); //0不可选取,1可被选取
}
ObjectSetInteger(0,Name,OBJPROP_COLOR,TextColor); //文字颜色
ObjectSetInteger(0,Name,OBJPROP_XDISTANCE,XDistance);//X轴位置
ObjectSetInteger(0,Name,OBJPROP_YDISTANCE,YDistance);//Y轴位置
ObjectSetString(0,Name,OBJPROP_TEXT,StringText); //插入string文字 //在大括号内部为不变更,外部为设置变更
ObjectSetInteger(0,Name,OBJPROP_ANCHOR,Anchor); //向左对齐、向右对齐 //ANCHOR_LEFT_UPPER (向左上角对齐) ANCHOR_RIGHT_LOWER(向右下角对齐)
}
void OnDeinit(const int reason) //ooo
{
if(reason==1) {Print("=========EA从图表中删除=========");}
if(reason==2) {Print("=========重新编译交易导致EA重新加载=========");}
if(reason==3) {Print("=========在图表上改变货币对或时间周期导致EA重新加载=========");}
if(reason==4) {Print("=========关闭图表导致EA退出=========");}
if(reason==5) {Print("=========改变了输入参量导致EA重新加载=========");}
if(reason==6) {Print("=========666666其他账户已激活1888=========");}
if(reason<1||reason>6) {Print("=========其他缘故=========");}
EventKillTimer();Comment(""); //注意:程序放到结束语函数中,会导致退出缓慢
if(reason==1||reason==2||reason==4||reason==5||Ask>=0)
{
//ObjectsDeleteAll();
for(int j=ObjectsTotal()-1;j>=0;j--)
{
if(StringFind(ObjectName(j),"_YCEA")>=0) {ObjectDelete(ObjectName(j));}
}
}
}
void ErrorAlert(string symbol,string Contact) //hhm //注意:部分程序,自定义函数中的for循环中的i,不能和主程序中的循环i一致,否则会卡死
{
if(IsOptimization()) {return;} //优化模式
int ErrorNumber=GetLastError();string AlertText="Nothing";
if(ErrorNumber!=0)
{
switch(ErrorNumber)
{
case 1:AlertText="当前值和移动值过近!";break;
case 3:AlertText="无效交易参量,平台系统因素导致,请更换平台测试!";break;
case 6:AlertText="没有连接服务器,可能平台已掉线,重连后,继续执行…";
case 129:AlertText="无效价格,ticksize";break;
case 130:AlertText="止损/止盈/挂单空间过小:请让空间大于“平台限制距离“"+IntegerToString((int)MarketInfo(symbol,MODE_STOPLEVEL))+"+“点差*2”!"+"即:"+IntegerToString((int)MarketInfo(symbol,MODE_STOPLEVEL)+int(MarketInfo(Symbol(),MODE_SPREAD)));break;
case 131:AlertText="无效交易量,可能当前品种禁止EA交易";break;
case 132:AlertText="市场关闭";break;
case 133:AlertText="交易被禁止,大概率是观摩账号、同一种货币多个品种。请联系平台客服。";break;
case 134:AlertText="资金不足";break;
case 136:AlertText="开价:报价过期";break;
case 138:AlertText="重新开价:当前报价无效,重新向服务器请求新报价";break;
case 148:AlertText="开单和挂单总数已被经纪限定";break;
case 149:AlertText="平台禁止当前品种多空同时持仓,即禁止对冲功能";break;
case 4017:AlertText="禁止调用DLL ";break;
case 4051:AlertText="无效参量值函数,大概率是手数止损止盈小于等于0导致";break;
case 4106:AlertText="不明货币对";break;
case 4108:AlertText="无效定单编码";break;
case 4109:AlertText="不允许交易:请确保右上角是笑脸!";break;
case 4110:AlertText="不允许长期,请开启关于中'Long&Short'";break;
case 4111:AlertText="不允许短期,请开启关于中'Long&Short',";break;
case 4112:AlertText="交易商不允许此品种EA交易,请联系平台客服开通EA权限,或更换平台测试。";break;
case 5006:AlertText="无法删除文件";break;//http://bbs.fanyong.la/thread-11-1-1.html
}
}
if(ErrorNumber!=0) {Print(symbol," - ",Contact,"代号",ErrorNumber," : ",AlertText); Sleep(500);}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/hangyejiadao_581/mql4.git
git@gitee.com:hangyejiadao_581/mql4.git
hangyejiadao_581
mql4
mql4
master

搜索帮助