1 Star 0 Fork 4

Joysing/mql4

forked from 航耍耍/mql4 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
叠箱体5.0破解源码版.mq4 62.39 KB
一键复制 编辑 原始数据 按行查看 历史
航耍耍 提交于 2021-11-09 08:24 . 123123123123
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
//+------------------------------------------------------------------+
//| 20171008_19895_EA.mq4 |
//| Copyright 2017, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
//2箱体联动
enum XZ
{
X=0,//单箱体止盈
Y=1,//两箱体止盈
};
extern double Lots=0.01;//下单手数
extern double Grid=100;//网格点数
extern int N=5;//箱体层数
extern double addN1=1.5;//首单突破单倍数
extern double addN2=2;//以后突破单倍数
extern XZ TPMethod=0;//止盈选择
extern double Earn=4;//止盈金额
extern bool UseMoveSL=true;//开启移动止盈
extern double Earn_N=25;//止盈点数
extern double BackDot=10;//回调点数
extern bool UseTwo=true;//启动第二箱体
extern double MaxLot=8;//变更突破倍率最大手数
extern double addN3=1;//最终固定突破倍率
extern double Percent=50;//清仓亏损百分比
string comA="箱体A";
string comB="箱体B";
int magA=17653,magB=86524;;
double MoveEarn_total=0,MoveEarn_a=0,MoveEarn_b=0;
//购买源码+授权加密
int OnInit()
{
//---
button("Close",clrWhite,clrMediumVioletRed,50,50,26,10,"一键平仓");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
ObjectDelete("Close");
ObjectDelete("a");
ObjectDelete("a1");
ObjectDelete("a2");
ObjectDelete("a3");
ObjectDelete("a4");
ObjectDelete("a5");
ObjectDelete("b");
ObjectDelete("b1");
ObjectDelete("b2");
ObjectDelete("b3");
ObjectDelete("b4");
ObjectDelete("b5");
ObjectDelete("c");
ObjectDelete("c1");
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
//---
if(id==CHARTEVENT_OBJECT_CLICK)
{
if(sparam=="Close")
{
close(comA,magA,2,1);
close(comB,magB,2,1);
}
}
}
void OnTick()
{
//---
//显示计算
int buyopenA=0,sellopenA=0,buyopenB=0,sellopenB=0;
double buyLotsA=0,sellLotsA=0,proA=0,buyLotsB=0,sellLotsB=0,proB=0,pro_total=0;
Show(buyopenA,sellopenA,buyLotsA,sellLotsA,proA,buyopenB,sellopenB,buyLotsB,sellLotsB,proB,pro_total);
Txt("a",50,50,"=======A箱体=======",10,clrGold);
Txt("a1",50,70,"多单数量:"+IntegerToString(buyopenA,0),10,clrGold);
Txt("a2",50,90,"多单手数:"+DoubleToStr(buyLotsA,2),10,clrGold);
Txt("a3",50,110,"空单数量:"+IntegerToString(sellopenA,0),10,clrGold);
Txt("a4",50,130,"空单手数:"+DoubleToStr(sellLotsA,2),10,clrGold);
Txt("a5",50,150,"盈亏金额:"+DoubleToStr(proA,2),10,clrGold);
Txt("b",50,170,"=======B箱体=======",10,clrGold);
Txt("b1",50,190,"多单数量:"+IntegerToString(buyopenB,0),10,clrGold);
Txt("b2",50,210,"多单手数:"+DoubleToStr(buyLotsB,2),10,clrGold);
Txt("b3",50,230,"空单数量:"+IntegerToString(sellopenB,0),10,clrGold);
Txt("b4",50,250,"空单手数:"+DoubleToStr(sellLotsB,2),10,clrGold);
Txt("b5",50,270,"盈亏金额:"+DoubleToStr(proB,2),10,clrGold);
Txt("c",50,290,"===================",10,clrGold);
Txt("c1",50,310,"总盈亏金额:"+DoubleToStr(pro_total,2),10,clrGold);
//计算清仓百分比
if((AccountBalance()-AccountEquity())/AccountBalance()>=Percent/100)
{
close(comA,magA,2,1);
close(comB,magB,2,1);
MoveEarn_total=0;
MoveEarn_a=0;
MoveEarn_b=0;
}
int ConfirmNum=0;//箱体确认数量
Check_Confirm_Num(ConfirmNum);//先查询箱体确立了多少个
//printf("ConfirmNum:"+ConfirmNum+" MoveEarn_total "+MoveEarn_total);
if(ConfirmNum>0 && TPMethod==1)//总盈利平仓
{
if(pro_total>=Earn)
{
close(comA,magA,2,1);
close(comB,magB,2,1);
MoveEarn_total=0;
}
if(UseMoveSL==false && pro_total>=Earn_N*MathAbs(buyLotsA+buyLotsB-sellLotsA-sellLotsB))
{
close(comA,magA,2,1);
close(comB,magB,2,1);
MoveEarn_total=0;
}
if(UseMoveSL)//移动止盈
{
if(pro_total>=Earn_N*MathAbs(buyLotsA+buyLotsB-sellLotsA-sellLotsB) && pro_total>MoveEarn_total)
{
MoveEarn_total=pro_total;
printf("(两箱体)最高金额:"+ DoubleToStr(MoveEarn_total,2)+" 平仓金额:"+DoubleToStr(MoveEarn_total-BackDot*MathAbs(buyLotsA+buyLotsB-sellLotsA-sellLotsB),2));
}
if(MoveEarn_total>0 && pro_total<=MoveEarn_total-BackDot*MathAbs(buyLotsA+buyLotsB-sellLotsA-sellLotsB))//盈利少于之前最高时回调的点数,平仓
{
close(comA,magA,2,1);
close(comB,magB,2,1);
MoveEarn_total=0;
printf("(两箱体)完成移动止盈:"+DoubleToStr(pro_total,2));
ExpertRemove();
}
}
}
if(ConfirmNum==0)//没有箱体确立,有可能一个箱体止盈了,另一个箱体有单但没确立箱体,也有可能是新开启
{
int Aopen=0,Bopen=0;
CheckAB(Aopen,Bopen);//查询两个箱体谁有单
int mag=0,mag_op=0;
string com="",com_op="";
if(Aopen==0 && Bopen>0)//B箱体有单但没确立,A箱体之前止盈了
{
mag=magB;
mag_op=magA;
com=comB;
com_op=comA;
}
if(Aopen>0 && Bopen==0)//A箱体有单但没确立,B箱体之前止盈了
{
mag=magA;
mag_op=magB;
com=comA;
com_op=comB;
}
int open=0,buyopen=0,sellopen=0;
double buylp=10000,sellhp=0,buyalllot=0,sellalllot=0;
Count1(mag,open,buyopen,sellopen,buylp,sellhp,buyalllot,sellalllot);//查询有单的箱体的订单情况
if(Aopen==0 && Bopen==0 && open==0)//AB箱体都没单,就是刚启动EA时,先下A箱体的单
{
buy(Symbol(),Lots,0,0,comA,magA,1);
sell(Symbol(),Lots,0,0,comA,magA,1);
}
if(open>0)
{
//空单加仓
if(sellopen>0 && Bid>sellhp+Grid*Point)
{
if(sellopen<N)//空单小于箱体层数 --加仓
{
close(com,mag,0,0);//平掉多单盈利的单
sell(Symbol(),Lots,0,0,com,mag,N);
buyopen=0;
sellopen=0;
Count2(mag,buyopen,sellopen);//查询多单是否被清空
if(buyopen==0) buy(Symbol(),Lots,0,0,com,mag,N);//多单没有了,要加多单
}
else //空单等于箱体层数,用多单第一次锁仓
{
close(com,mag,0,1);//平掉基础多单
buy(Symbol(),NormalizeDouble(sellalllot*addN1,2),0,0,com,mag,10);
//ConfirmNum++;
if(UseTwo)
{
buy(Symbol(),Lots,0,0,com_op,mag_op,1);//第二个箱体首单建立
sell(Symbol(),Lots,0,0,com_op,mag_op,1);//第二个箱体首单建立
}
}
}
//多单加仓
if(buyopen>0 && Ask<buylp-Grid*Point)
{
if(buyopen<N)//多单小于箱体层数 --加仓
{
close(com,mag,1,0);//平掉空单盈利的单
buy(Symbol(),Lots,0,0,com,mag,N);
buyopen=0;
sellopen=0;
Count2(mag,buyopen,sellopen);//查询空单是否被清空
if(sellopen==0) sell(Symbol(),Lots,0,0,com,mag,N);//空单没有了,要加空单
}
else //多单等于箱体层数,用空单第一次锁仓
{
close(com,mag,1,1);//平掉空单基础单
sell(Symbol(),NormalizeDouble(buyalllot*addN1,2),0,0,com,mag,10);
//ConfirmNum++;
if(UseTwo)
{
buy(Symbol(),Lots,0,0,com_op,mag_op,1);//第二个箱体首单建立
sell(Symbol(),Lots,0,0,com_op,mag_op,1);//第二个箱体首单建立
}
}
}
}
}
//只有一个箱体,寻找另一箱体的建单点位
if(ConfirmNum==1 && UseTwo)
{
//查询哪个箱体是确立的,找出确立的订单的最高价和最低价就是箱体边缘
//如果另外箱体没有单,并且在有单箱体的外侧,则开首单
//如果另外箱体有单,则按照没确立前的双向开单方法进行开仓,参考上面,直到两个箱体都确立了,此功能不再执行
//只处理没确立的箱体,已确立的箱体在下面处理
//printf("箱体2");
int mag_con=0,un_open=0;
double lowp=10000,highp=0;
Check_UnConfirm(mag_con,lowp,highp,un_open);//返回确定箱体的mag,箱体两端价格,没确立箱体的开单数
int mag_un=0;
string com_un="";
if(mag_con==magA)//确定没确立的箱体的mag
{
mag_un=magB;
com_un=comB;
}
if(mag_con==magB)//确定没确立的箱体的mag
{
mag_un=magA;
com_un=comA;
}
if(un_open==0)//只有一个确立的箱体,另外箱体没有单,刚止盈时,寻找确立箱体的高低点建首仓
{
if(Close[0]>highp || Close[0]<lowp)
{
buy(Symbol(),Lots,0,0,com_un,mag_un,1);//第二个箱体首单建立
sell(Symbol(),Lots,0,0,com_un,mag_un,1);//第二个箱体首单建立
}
}
if(un_open>0)//有一箱体确立了,另外箱体已经有单,但还没确立,要双向加仓,直到确立为止
{
int open=0,buyopen=0,sellopen=0;
double buylp=10000,sellhp=0,buyalllot=0,sellalllot=0;
Count1(mag_un,open,buyopen,sellopen,buylp,sellhp,buyalllot,sellalllot);//查询有单的箱体的订单情况
//空单加仓
if(sellopen>0 && Bid>sellhp+Grid*Point)
{
if(sellopen<N)//空单小于箱体层数 --加仓
{
close(com_un,mag_un,0,0);//平掉多单盈利的单
sell(Symbol(),Lots,0,0,com_un,mag_un,N);
buyopen=0;
sellopen=0;
Count2(mag_un,buyopen,sellopen);//查询多单是否被清空
if(buyopen==0) buy(Symbol(),Lots,0,0,com_un,mag_un,N);//多单没有了,要加多单
}
else //空单等于箱体层数,用多单第一次锁仓
{
close(com_un,mag_un,0,1);//平掉多单基础单
buy(Symbol(),NormalizeDouble(sellalllot*addN1,2),0,0,com_un,mag_un,10);
//ConfirmNum++;
}
}
//多单加仓
if(buyopen>0 && Ask<buylp-Grid*Point)
{
if(buyopen<N)//多单小于箱体层数 --加仓
{
close(com_un,mag_un,1,0);//平掉空单盈利的单
buy(Symbol(),Lots,0,0,com_un,mag_un,N);
buyopen=0;
sellopen=0;
Count2(mag_un,buyopen,sellopen);//查询空单是否被清空
if(sellopen==0) sell(Symbol(),Lots,0,0,com_un,mag_un,N);//空单没有了,要加空单
}
else //多单等于箱体层数,用空单第一次锁仓
{
close(com_un,mag_un,1,1);//平掉空单基础单
sell(Symbol(),NormalizeDouble(buyalllot*addN1,2),0,0,com_un,mag_un,10);
//ConfirmNum++;
}
}
}
}
//有箱体,计算箱体止盈,箱体内部的各自加仓处理
if(ConfirmNum>0)
{
//箱体总体平仓操作
if(TPMethod==0)
{
double pro=0;
double buylot=0,selllot=0;
bool Confirm=false;
CheckTP(magA,pro,buylot,selllot,Confirm);
if(pro>=Earn)
{
close(comA,magA,2,1);
MoveEarn_a=0;
}
if(Confirm && UseMoveSL==false && pro>=Earn_N*MathAbs(buylot-selllot))//A箱体已经确立了,才能执行整体止盈操作
{
close(comA,magA,2,1);
MoveEarn_a=0;
}
//移动止盈
if(Confirm && UseMoveSL && pro>=Earn_N*MathAbs(buylot-selllot) && pro>MoveEarn_a)//A箱体已经确立了,才能执行移动止盈操作
{
MoveEarn_a=pro;
printf("(A箱体)最高金额:"+ DoubleToStr(MoveEarn_a,2)+" 平仓金额:"+DoubleToStr(MoveEarn_a-BackDot*MathAbs(buylot-selllot),2));
}
if(Confirm && UseMoveSL && MoveEarn_a>0 && pro<=MoveEarn_a-BackDot*MathAbs(buylot-selllot))//盈利少于之前最高时回调的点数,平仓
{
close(comA,magA,2,1);
MoveEarn_a=0;
printf("(A箱体)完成移动止盈:"+DoubleToStr(pro,2));
}
pro=0;
buylot=0;
selllot=0;
Confirm=false;
CheckTP(magB,pro,buylot,selllot,Confirm);
if(pro>=Earn)
{
close(comB,magB,2,1);
MoveEarn_b=0;
}
if(Confirm && UseMoveSL==false && pro>=Earn_N*MathAbs(buylot-selllot))
{
close(comB,magB,2,1);
MoveEarn_b=0;
}
//移动止盈
if(Confirm && UseMoveSL && pro>=Earn_N*MathAbs(buylot-selllot) && pro>MoveEarn_b)
{
MoveEarn_b=pro;
printf("(B箱体)最高金额:"+ DoubleToStr(MoveEarn_b,2)+" 平仓金额:"+DoubleToStr(MoveEarn_b-BackDot*MathAbs(buylot-selllot),2));
}
if(Confirm && UseMoveSL && MoveEarn_b>0 && pro<=MoveEarn_b-BackDot*MathAbs(buylot-selllot))//盈利少于之前最高时回调的点数,平仓
{
close(comB,magB,2,1);
MoveEarn_b=0;
printf("(B箱体)完成移动止盈:"+DoubleToStr(pro,2));
}
}
//
Function(magA,comA);//箱体内加仓、箱体两端加翻倍仓
if(UseTwo) Function(magB,comB);
}
}
//+------------------------------------------------------------------+
void Show(int &buyopenA,int &sellopenA,double &buyLotsA,double &sellLotsA,double &proA,int &buyopenB,int &sellopenB,double &buyLotsB,double &sellLotsB,double &proB,double &pro_total)
{
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
if(Symbol()==OrderSymbol() && OrderType()<=1)
{
pro_total+=OrderProfit()+OrderCommission()+OrderSwap();
if(OrderMagicNumber()==magA)
{
proA+=OrderProfit()+OrderCommission()+OrderSwap();
if(OrderType()==OP_BUY)
{
buyopenA++;
buyLotsA+=OrderLots();
}
if(OrderType()==OP_SELL)
{
sellopenA++;
sellLotsA+=OrderLots();
}
}
if(OrderMagicNumber()==magB)
{
proB+=OrderProfit()+OrderCommission()+OrderSwap();
if(OrderType()==OP_BUY)
{
buyopenB++;
buyLotsB+=OrderLots();
}
if(OrderType()==OP_SELL)
{
sellopenB++;
sellLotsB+=OrderLots();
}
}
}
}
}
}
void Check_Confirm_Num(int &num)//查询确立箱体的有多少个
{
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
if(Symbol()==OrderSymbol() && OrderType()<=1)
{
if(OrderLots()==NormalizeDouble(Lots*N*addN1,2))//有锁单的,就是已经确立的
{
num++;
}
}
}
}
}
void Check_UnConfirm(int &mag,double &lowp,double &highp,int &un_open)
{
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
if(Symbol()==OrderSymbol() && OrderType()<=1)
{
if(OrderLots()==NormalizeDouble(Lots*N*addN1,2))//有锁单的,就是已经确立的
{
mag=OrderMagicNumber();//已经确立的箱体mag
}
}
}
}
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
if(OrderMagicNumber()==mag && Symbol()==OrderSymbol() && OrderType()<=1)
{
if(OrderOpenPrice()<lowp) lowp=OrderOpenPrice();
if(OrderOpenPrice()>highp) highp=OrderOpenPrice();
}
if(OrderMagicNumber()!=mag && Symbol()==OrderSymbol() && OrderType()<=1)
{
un_open++;//没确立的箱体的订单数
}
}
}
}
void Function(int mag,string com)
{
int addDirect=10,buyopen=0,sellopen=0,maxdire=10;
double buylp=10000,sellhp=0,maxlot=0,maxopenprice=0;
Count_Function(mag,buyopen,sellopen,addDirect,buylp,sellhp,maxlot,maxdire,maxopenprice);//查询有单的箱体的订单情况
if(addDirect==1)//只能加空单,箱体成立时已定
{
if(sellopen>0 && Bid>sellhp+Grid*Point)
{
if(sellopen<N)//空单小于箱体层数 --加仓
{
sell(Symbol(),Lots,0,0,com,mag,N);
}
else //空单等于箱体层数,
{
if(maxdire==1)//最大单是空单时,就是下方已经有了最大的多单
{
if(maxlot<MaxLot)
{
buy(Symbol(),NormalizeDouble(maxlot*addN2,2),0,0,com,mag,10);
}
else
{
buy(Symbol(),NormalizeDouble(maxlot*addN3,2),0,0,com,mag,10);
}
}
}
}
if(sellopen>0 && Bid<sellhp-Grid*Point)
{
close(com,mag,1,0);//平掉空单盈利的单
}
if(sellopen==0 && maxlot>0 && maxdire==0)//空单没有了,只有最大手数单,并且最大手数单是多单
{
if(maxlot<MaxLot)
{
sell(Symbol(),NormalizeDouble(maxlot*addN2,2),0,0,com,mag,10);//最大单翻倍
}
else
{
sell(Symbol(),NormalizeDouble(maxlot*addN3,2),0,0,com,mag,10);//最大单翻倍
}
}
if(maxdire==1 && sellopen==0)//最大单同向,没有基础单
{
if(Bid>maxopenprice+Grid*Point)
{
sell(Symbol(),Lots,0,0,com,mag,N);//补第一单基础单
}
}
}
if(addDirect==0)//只能加多单,箱体成立时已定
{
if(buyopen>0 && Ask<buylp-Grid*Point)
{
if(buyopen<N)//多单小于箱体层数 --加仓
{
buy(Symbol(),Lots,0,0,com,mag,N);
}
else //多单等于箱体层数,
{
if(maxdire==0)//最大单是多单时,就是上方已经有了空单
{
if(maxlot<MaxLot)
{
sell(Symbol(),NormalizeDouble(maxlot*addN2,2),0,0,com,mag,10);
}
else
{
sell(Symbol(),NormalizeDouble(maxlot*addN3,2),0,0,com,mag,10);
}
}
}
}
if(buyopen>0 && Ask>buylp+Grid*Point)
{
close(com,mag,0,0);//平掉多单盈利的单
}
if(buyopen==0 && maxlot>0 && maxdire==1) //多单没有了,只有最大手数单,并且最大手数单是空单
{
if(maxlot<MaxLot)
{
buy(Symbol(),NormalizeDouble(maxlot*addN2,2),0,0,com,mag,10);//最大单翻倍
}
else
{
buy(Symbol(),NormalizeDouble(maxlot*addN3,2),0,0,com,mag,10);//最大单翻倍
}
}
if(maxdire==0 && buyopen==0)//最大单同向,没有基础单,回抽
{
if(Ask<maxopenprice-Grid*Point)
{
buy(Symbol(),Lots,0,0,com,mag,N);//补第一单基础单
}
}
}
}
void Count_Function(int mag,int &buyopen,int &sellopen,int &addDirect,double &buylp,double &sellhp,double &maxlot,int &maxdire,double &maxopenprice)
{
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
if(OrderMagicNumber()==mag && Symbol()==OrderSymbol() && OrderType()<=1)
{
if(OrderType()==OP_BUY && OrderLots()==NormalizeDouble(Lots*N*addN1,2))//第一次锁仓是多单,即是只能加仓空单
{
addDirect=1;
}
if(OrderType()==OP_SELL && OrderLots()==NormalizeDouble(Lots*N*addN1,2))
{
addDirect=0;
}
if(OrderType()==OP_BUY && OrderLots()==Lots)
{
buyopen++;
}
if(OrderType()==OP_SELL && OrderLots()==Lots)
{
sellopen++;
}
if(OrderType()==OP_BUY && OrderOpenPrice()<buylp && OrderLots()==Lots) buylp=OrderOpenPrice();
if(OrderType()==OP_SELL && OrderOpenPrice()>sellhp && OrderLots()==Lots) sellhp=OrderOpenPrice();
if(OrderLots()>maxlot)
{
maxlot=OrderLots();
maxdire=OrderType();
maxopenprice=OrderOpenPrice();
}
}
}
}
}
void CheckTP(int mag,double &pro,double &buylot,double &selllot,bool &Confirm)//查询箱体盈利情况
{
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
if(OrderMagicNumber()==mag && Symbol()==OrderSymbol() && OrderType()<=1)
{
if(Confirm==false && OrderLots()==NormalizeDouble(Lots*N*addN1,2)) Confirm=true;
pro+=OrderProfit()+OrderCommission()+OrderSwap();
if(OrderType()==OP_BUY)
{
buylot+=OrderLots();
}
if(OrderType()==OP_SELL)
{
selllot+=OrderLots();
}
}
}
}
}
void CheckAB(int &Aopen,int &Bopen)//查询两箱体的各自开单数量
{
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
if(OrderMagicNumber()==magA && Symbol()==OrderSymbol() && OrderType()<=1)
{
Aopen++;
}
if(OrderMagicNumber()==magB && Symbol()==OrderSymbol() && OrderType()<=1)
{
Bopen++;
}
}
}
}
void Count1(int mag,int &open,int &buyopen,int &sellopen,double &buylp,double &sellhp,double &buyalllot,double &sellalllot)
{
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
if(OrderMagicNumber()==mag && Symbol()==OrderSymbol() && OrderType()<=1)
{
open++;
if(OrderType()==OP_BUY)
{
buyopen++;
buyalllot+=OrderLots();
}
if(OrderType()==OP_SELL)
{
sellopen++;
sellalllot+=OrderLots();
}
if(OrderType()==OP_BUY && OrderOpenPrice()<buylp) buylp=OrderOpenPrice();
if(OrderType()==OP_SELL && OrderOpenPrice()>sellhp) sellhp=OrderOpenPrice();
}
}
}
}
void Count2(int mag,int &buyopen,int &sellopen)
{
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
if(OrderMagicNumber()==mag && Symbol()==OrderSymbol() && OrderType()<=1)
{
if(OrderType()==OP_BUY)
{
buyopen++;
}
if(OrderType()==OP_SELL)
{
sellopen++;
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int buy(string sb,double lot,double sl,double tp,string comment,int magic,int limitbuy=1)
{
int ticket=0;
int opened=0;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
int ordermagic=OrderMagicNumber();
string ordercom=OrderComment();
if(OrderSymbol()==sb && OrderType()==OP_BUY && magic==ordermagic && comment==ordercom && OrderLots()==Lots)
{
opened++;
}
}
}
if(opened<limitbuy)
{
RefreshRates();
double stoploss=0,takeprofit=0;
if(sl>0) stoploss=MarketInfo(sb,MODE_ASK)-sl*Point;
if(tp>0) takeprofit=MarketInfo(sb,MODE_ASK)+tp*Point;
ticket=OrderSend(sb,OP_BUY,lot,MarketInfo(sb,MODE_ASK),5,stoploss,takeprofit,comment,magic,0,clrRed);
}
return(ticket);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int sell(string sb,double lot,double sl,double tp,string comment,int magic,int limitsell=1)
{
int ticket=0;
int opened=0;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
int ordermagic=OrderMagicNumber();
string ordercom=OrderComment();
if(OrderSymbol()==sb && OrderType()==OP_SELL && magic==ordermagic && comment==ordercom && OrderLots()==Lots)
{
opened++;
}
}
}
if(opened<limitsell)
{
RefreshRates();
double stoploss=0,takeprofit=0;
if(sl>0) stoploss=MarketInfo(sb,MODE_BID)+sl*Point;
if(tp>0) takeprofit=MarketInfo(sb,MODE_BID)-tp*Point;
ticket=OrderSend(sb,OP_SELL,lot,MarketInfo(sb,MODE_BID),5,stoploss,takeprofit,comment,magic,0,clrGreen);
}
return(ticket);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void close(string comment,int magic,int type,int type2) //type2=0时,要看盈利,type2=1时,不看盈利
{
for(int i=OrdersTotal();i>=0;i--)
{
if(OrderSelect(i-1,SELECT_BY_POS))
{
if(OrderSymbol()==Symbol() && OrderComment()==comment && OrderMagicNumber()==magic)
{
if(type<2 && OrderType()==type && OrderLots()==Lots)
{
if(OrderProfit()+OrderCommission()+OrderSwap()>0 && type2==0 && MathAbs(Close[0]-OrderOpenPrice())/Point>Grid/2) bool a=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),5,clrGold);
if(type2==1) bool a=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),5,clrGold);
}
if(type==2)
{
bool a=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),5,clrGold);
}
}
}
}
}
void Txt(string name,int x,int y,string content,int size,color clr)
{
ObjectCreate(name,OBJ_LABEL,0,10,10);
ObjectSet(name,OBJPROP_XDISTANCE,x);
ObjectSet(name,OBJPROP_YDISTANCE,y);
ObjectSet(name,OBJPROP_CORNER,CORNER_LEFT_UPPER);
ObjectSetText(name,content,size,"Arial",clr);
}
void button(string name,color fontyanse,color bgcolor,int x,int y,int ysize,int fontsize,string text,int changdu=0)
{
ObjectCreate(0,name,OBJ_BUTTON,0,0,0);
ObjectSetInteger(0,name,OBJPROP_COLOR,fontyanse);
ObjectSetInteger(0,name,OBJPROP_BGCOLOR,bgcolor);
ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
if(changdu==0)
{
int as=StringLen(text);
ObjectSetInteger(0,name,OBJPROP_XSIZE,as*25);
}
else
{
ObjectSetInteger(0,name,OBJPROP_XSIZE,changdu);
}
ObjectSetInteger(0,name,OBJPROP_YSIZE,ysize);
ObjectSetString(0,name,OBJPROP_FONT,"Arial");
ObjectSetString(0,name,OBJPROP_TEXT,text);
ObjectSetInteger(0,name,OBJPROP_FONTSIZE,fontsize);
ObjectSetInteger(0,name,OBJPROP_CORNER,CORNER_LEFT_LOWER);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/joysing/mql4.git
git@gitee.com:joysing/mql4.git
joysing
mql4
mql4
master

搜索帮助