Hi,
As my thread title implies I would like to know if TP/SL can be hard-coded into an existing EA.
Currently, a trade is opened and then it is modified.
Thanks.
David.
Not that it is desirable to hard code anything, but yes. The Sky is the limit.
Not that it is desirable to hard code anything, but yes. The Sky is the limit.
These parameters need hardcoding:
extern int ActionPips = 1;
extern int TargetPips = 1;
extern int StopPips = 150;
extern int ActionPips = 1; extern int TargetPips = 1; extern int StopPips = 150;
- When you post code please use the SRC button! Please edit your post.
General rules and best pratices of the Forum. - General - MQL5 programming forum - So do it; remove the extern keyword. What's your problem?
Sometimes it will close out the trade very quickly without modify TP and SL. Other time it does modify with two options ~ MathMin/MathMax (TP or STOPLEVEL). '
Copy and paste from the original code.
if((CurrentPips>=TargetPips || CurrentPips<=-StopPips) && IsTradeContextBusy()==false) { if(OrderType()==OP_BUY) OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(dBid,Digits), Slippage*MyPoint/Point, Blue); else OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(dAsk,Digits), Slippage*MyPoint/Point, Red); } else if(VirtualStops==false && OrderStopLoss()<Point && IsTradeContextBusy()==false) { double MinDistance=MarketInfo(Symbol(),MODE_STOPLEVEL)*Point+MyPoint; if(OrderType()==OP_BUY) OrderModify(OrderTicket(),OrderOpenPrice() ,MathMin(OrderOpenPrice()-StopPips*MyPoint,dBid-MinDistance) ,MathMax(OrderOpenPrice()+TargetPips*MyPoint,dAsk+MinDistance),0); else OrderModify(OrderTicket(),OrderOpenPrice() ,MathMax(OrderOpenPrice()+StopPips*MyPoint,dAsk+MinDistance) ,MathMin(OrderOpenPrice()-TargetPips*MyPoint,dBid-MinDistance),0); }
- Use the debugger or print out your variables, including _LastError and find out why.
OrderClose(OrderTicket(), OrderLots(), ...); else OrderClose(OrderTicket(), OrderLots(), ...); } else if(...){ double MinDistance=MarketInfo(Symbol(),MODE_STOPLEVEL)*Point+MyPoint; if(OrderType()==OP_BUY) OrderModify(OrderTicket(),OrderOpenPrice() ...); else OrderModify(OrderTicket(),OrderOpenPrice() ...);
Check your return codes for errors and report them.
What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articlesif(OrderType()==OP_BUY) OrderModify(OrderTicket(),OrderOpenPrice() ,MathMin(OrderOpenPrice()-StopPips*MyPoint,dBid-MinDistance) ,MathMax(OrderOpenPrice()+TargetPips*MyPoint,dAsk+MinDistance),0); else OrderModify(OrderTicket(),OrderOpenPrice() ,MathMax(OrderOpenPrice()+StopPips*MyPoint,dAsk+MinDistance) ,MathMin(OrderOpenPrice()-TargetPips*MyPoint,dBid-MinDistance),0);
You buy at the Ask and sell at the Bid.- Your buy order's TP/SL are triggered when the Bid reaches it. Not the Ask.
-
Your sell order's TP/SL will be triggered when the Ask reaches it. To trigger at
a specific Bid price, add the average spread.
MODE_SPREAD (Paul) - MQL4 and MetaTrader 4 - MQL4 programming forum - Page 3 - The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools -> Options {control-O} -> charts -> Show ask line.)
Sometimes it will close out the trade very quickly without modify TP and SL. Other time it does modify with two options ~ MathMin/MathMax (TP or STOPLEVEL).
This is the exact problem I am having. Trades are opened and closed too damn quickly without modifying TP and SL.
Question: Can it just open a trade at market price with hardcoded SL("StopPips = 5"), TP("TargetPips = 1") and our trigger: ("ActonPips = 1") ???
This is the exact problem I am having. Trades are opened and closed too damn quickly without modifying TP and SL.
Question: Can it just open a trade at market price with hardcoded SL("StopPips = 5"), TP("TargetPips = 1") and our trigger: ("ActonPips = 1") ???
You need to ask one of freelances to help you. It can be fixed.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
As my thread title implies I would like to know if TP/SL can be hard-coded into an existing EA.
Currently, a trade is opened and then it is modified.
Thanks.
David.