Hey guys,
Ive come up empty handed after searching the correct way to write my code so that it places pending orders a certain pip distance above the previous bars H n L.
Ive seen similar questions but they weren't resolved and i can't find any documentation in the book about this specifically.
I have my the code working fine in regards to placing them at the H n L of the previous bar but i get errors when i try to alter the code with something like * point to get the order ex 10 pips above previous high.
so I've posted the code and a picture of an example. I tried change the lines around the iHigh symbols and iLow symbols but it generates lots of errors. The examples i found
were written different to mine so they don't work. Could anyone shed any light or is there more documentation on this topic anywhere?
Thank you.
Hi Clint,
I created a function for you, hope it useful :)
//+---------------------+ //| Function BUY STOP | //+---------------------+ bool Buy_Stop(double xhigh, //-- your previous high int xrange, //-- pips range above the high double xlot, //--lot size should be checked for minimum and maximum lot that allowed in trade int xsl, //-- stoploss in pips int xtp, //-- target in pips int xmagic, //-- magic number string xlog, //-- log comment in trade int xslippage, //-- slippage string xdesc) //-- description : more detail in "Print()" { ResetLastError(); Print("* Opening Buy_Stop: ",xdesc," at ",xrange," pips above last high ",NormalizeDouble(xhigh, Digits)); int Dgt; if (Digits==4) Dgt=1; else if (Digits==5||Digits==2||Digits==3) Dgt=10; double position=xhigh+(xrange*Dgt*Point);//--price at xrange pips above xhigh double target=position+(xtp*Dgt*Point);//--target at xtp pips above position double stop=position-(xsl*Dgt*Point);//--stoploss at xsl pips below position int ticket=OrderSend(Symbol(),OP_BUYSTOP, xlot, NormalizeDouble(position,Digits), xslippage, NormalizeDouble(stop,Digits), NormalizeDouble(target,Digits), xlog,xmagic,0,clrBlue); if(ticket<=0) { Print("! Buy_Stop failed with error #",GetLastError()); return(false); } else { Print("* Position Buy_Stop ",xdesc," .. ticket #",ticket," placed successfully."); return(true); } }
By that way, you can copy and make minor update for Sell Stop.
Kind regards,
Yohana
Hi Clint,
I created a function for you, hope it useful :)
By that way, you can copy and make minor update for Sell Stop.
Kind regards,
Yohana
Wow thank you for the reply.
Fantastic work by the way. May i ask did you just come up with this from scratch or is this kind information referenced somewhere.
Im so keen to learn how to program from scratch but it seems sooo difficult.
Thanks again.
Wow thank you for the reply.
Fantastic work by the way. May i ask did you just come up with this from scratch or is this kind information referenced somewhere.
Im so keen to learn how to program from scratch but it seems sooo difficult.
Thanks again.
Hi Clint,
Please tell me if you can't use that function, then I will explain it more detail with example how to call it :)
Btw, all about MQL4 is at https://docs.mql4.com
Hi Clint,
Please tell me if you can't use that function, then I will explain it more detail with example how to call it :)
Btw, all about MQL4 is at https://docs.mql4.com
Yohana,
I tried to implement the code you gave but no success. To be honesty i don't think i have any idea what i was doing ha,
I created the code to start using fx quant so that takes care of most of the layout for me as i don't know how to build from scratch yet.
thanks
Yohana,
I tried to implement the code you gave but no success. To be honesty i don't think i have any idea what i was doing ha,
I created the code to start using fx quant so that takes care of most of the layout for me as i don't know how to build from scratch yet.
thanks
Okay, please you can wait for a while, I am now writing code as example for more detail.
Kind regards
Yohana,
I tried to implement the code you gave but no success. To be honesty i don't think i have any idea what i was doing ha,
I created the code to start using fx quant so that takes care of most of the layout for me as i don't know how to build from scratch yet.
thanks
Hi Clint,
Here is more complete example for you,
Good luck :)
//+------------------------------------------------------------------+ //| For_Clint.mq4 | //| Copyright 2017, Yohana | //+------------------------------------------------------------------+ #property copyright "Copyright 2017, Yohana" #property link "https://www.mql5.com/en/users/yohana/seller#products" #property version "1.00" #property strict //--- input parameters input int MagicNo=0;//Magic Number input double Lot=0.01;//Lot size input int Slip=3;//Slippage input int StopRange=10;//Pips to place stop order input int TP=20;//Pips target input int SL=20;//Pips stoploss input string TradeLog="ClintTaylor91";//Trade Comment input bool alert_hp=false;//Send trade notification to smartphone input bool alert_email=false;//Send trade notification to email int ticket, Dgt; double position, target, stop; double newlot; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- CheckVolumeValue(Lot); if (Digits==4) Dgt=1; else if (Digits==5||Digits==2||Digits==3) Dgt=10; //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--clear your screen when EA exit, etc. } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- your criteria to place pending order if(............) //<--write here for your criteria before placing buy_stop { if(Buy_Stop(High[1],StopRange,newlot,SL,TP,MagicNo,TradeLog,Slip,"Your description")) { //--succeed //--send alert notification } else { //--failed //--send alert notification } } //--- }//--end of OnTick//+---------------------+ //| Function BUY STOP | //+---------------------+ bool Buy_Stop(double xhigh, //-- your previous high int xrange, //-- pips above the high double xlot, //--lot size should be checked for minimum and maximum lot that allowed in trade int xsl, //-- stoploss in pips int xtp, //-- target in pips int xmagic, //-- magic number string xlog, //-- log comment in trade int xslippage, //-- slippage string xdesc) //-- description more detail in "Print()" { ResetLastError(); Print("* Opening Buy_Stop: ",xdesc," at ",xrange," pips above last high ",NormalizeDouble(xhigh, Digits)); position=xhigh+(xrange*Dgt*Point);//--price at xrange pips above xhigh target=position+(xtp*Dgt*Point);//--target at xtp pips above position stop=position-(xsl*Dgt*Point);//--stoploss at xsl pips below position ticket=OrderSend(Symbol(),OP_BUYSTOP, xlot, NormalizeDouble(position,Digits), xslippage, NormalizeDouble(stop,Digits), NormalizeDouble(target,Digits), xlog,xmagic,0,clrBlue); if(ticket<=0) { Print("! Buy_Stop failed with error #",GetLastError()); return(false); } else { Print("* Position Buy_Stop ",xdesc," .. ticket #",ticket," placed successfully."); return(true); } }//--end of Buy_Stop
//+------------------------------------------------------------------+ //| Check the correctness of the order volume | //+------------------------------------------------------------------+ void CheckVolumeValue(double volume) { //--- minimal allowed volume for trade operations double min_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN); if(volume<min_volume) { if(alert_email==true) SendMail("Lot volume changed.","Lot volume has changed to "+DoubleToString(min_volume,2)+" as minimum volume that allowed by broker."); if(alert_hp==true) SendNotification("Lot volume has changed to "+DoubleToString(min_volume,2)+" as minimum volume that allowed by broker."); Print("Lot volume has changed to "+DoubleToString(min_volume,2)+" as minimum volume that allowed by broker."); newlot=min_volume; } else newlot=Lot; }//--end of CheckVolumeValue
Yohana Parmi: I created a function for you, hope it useful :)
if (Digits==4) Dgt=1; else if (Digits==5||Digits==2||Digits==3) Dgt=10; double position=xhigh+(xrange*Dgt*Point);//--price at xrange pips above xhigh | Digits are 1,2,3,4,5. Has nothing to do with the definition of a PIP. Define PIP properly and your done. See adjusting SL, TP, and slippage; for 4/5 digit brokers and for JPY pairs. |
Digits are 1,2,3,4,5. Has nothing to do with the definition of a PIP. Define PIP properly and your done. See adjusting SL, TP, and slippage; for 4/5 digit brokers and for JPY pairs. |
Thank you,
I just wanted to give a simpler way to make it easier for a beginner to understand, and it works :)
Your technique is good, expert and useful.
I managed to get it working guys, works a charm
Thank you for all your help Yohana, i appreciate your work and thank you whroeder1!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey guys,
Ive come up empty handed after searching the correct way to write my code so that it places pending orders a certain pip distance above the previous bars H n L.
Ive seen similar questions but they weren't resolved and i can't find any documentation in the book about this specifically.
I have my the code working fine in regards to placing them at the H n L of the previous bar but i get errors when i try to alter the code with something like * point to get the order ex 10 pips above previous high.
so I've posted the code and a picture of an example. I tried change the lines around the iHigh symbols and iLow symbols but it generates lots of errors. The examples i found
were written different to mine so they don't work. Could anyone shed any light or is there more documentation on this topic anywhere?
Thank you.