anyone can help with this code.... until now I can't get this EA to run STOP LOSS function... could anyone point the error on the code?
Hi sysop
The code is fine.
1. The reason your trailing stop doesn't work is because the take profit you have set (10) is closer than the trailing stop (15). If you set LTakeprofit and STakeProfit much larger it works fine.
2. You do need to multiply all your point values by 10 for it to work properly with a 5-digit broker.
3. It won't place SELL orders because your initial stop loss (ldStop = 0.5;) is below the entry price. If you set it to 2.5, for example, you get short positions as well.
Cheers
Jellybean
Hi sysop
The code is fine.
1. The reason your trailing stop doesn't work is because the take profit you have set (10) is closer than the trailing stop (15). If you set LTakeprofit and STakeProfit much larger it works fine.
2. You do need to multiply all your point values by 10 for it to work properly with a 5-digit broker.
3. It won't place SELL orders because your initial stop loss (ldStop = 0.5;) is below the entry price. If you set it to 2.5, for example, you get short positions as well.
Cheers
Jellybean
I've follow your guidelines but still the stop loss can't get to the exact point (i.e if buy GBP/JPY at 153.22) ... then if I set up ldStop at 2.5 and TP at 25 pips, the value I get on the MT Platform is like this..
Buy: 153.22
SL: 2.50
TP: 153.47
What's wrong with the ldStop?
extern double lStopLoss = 50; extern double sStopLoss = 50;
void OpenBuy() { double ldLot, ldStop, ldTake; string lsComm; ldLot = GetSizeLot(); ldStop = 0.5; ldTake = GetTakeProfitBuy(); lsComm = GetCommentForOrder(); OrderSend(Symbol (),OP_BUY,ldLot,Ask,Slippage,ldStop,ldTake,lsComm,0,0,clOpenBuy); if (UseSound) PlaySound(NameFileSound); } void OpenSell() { double ldLot, ldStop, ldTake; string lsComm; ldLot = GetSizeLot(); ldStop = 0.5; ldTake = GetTakeProfitSell(); lsComm = GetCommentForOrder(); OrderSend(Symbol (),OP_SELL,ldLot,Bid,Slippage,ldStop,ldTake,lsComm,0,0,clOpenSell); if (UseSound) PlaySound(NameFileSound); }to
void OpenBuy() { double ldLot, ldStop, ldTake; string lsComm; ldLot = GetSizeLot(); ldStop = Ask-lStopLoss*Point; ldTake = GetTakeProfitBuy(); lsComm = GetCommentForOrder(); OrderSend(Symbol (),OP_BUY,ldLot,Ask,Slippage,ldStop,ldTake,lsComm,0,0,clOpenBuy); if (UseSound) PlaySound(NameFileSound); } void OpenSell() { double ldLot, ldStop, ldTake; string lsComm; ldLot = GetSizeLot(); ldStop = Bid+sStopLoss*Point; ldTake = GetTakeProfitSell(); lsComm = GetCommentForOrder(); OrderSend(Symbol (),OP_SELL,ldLot,Bid,Slippage,ldStop,ldTake,lsComm,0,0,clOpenSell); if (UseSound) PlaySound(NameFileSound); }
Done... it work like what it should be.. thanks..
I've follow your guidelines but still the stop loss can't get to the exact point (i.e if buy GBP/JPY at 153.22) ... then if I set up ldStop at 2.5 and TP at 25 pips, the value I get on the MT Platform is like this..
Buy: 153.22
SL: 2.50
TP: 153.47
What's wrong with the ldStop?
Hi sysop
Further to Roger's reply above, you must also make sure that lTrailingStop is less than lTakeProfit and sTrailingStop is less than sTakeProfit. The reason is that this code does not trail a stop-loss until the price has moved beyond the entry price by the amount of the trailing stop. If the take profit is closer, the order will close before it gets a chance to trail the stop.
Cheers
Jellybean
Hi sysop
Further to Roger's reply above, you must also make sure that lTrailingStop is less than lTakeProfit and sTrailingStop is less than sTakeProfit. The reason is that this code does not trail a stop-loss until the price has moved beyond the entry price by the amount of the trailing stop. If the take profit is closer, the order will close before it gets a chance to trail the stop.
Cheers
Jellybean
Yup... done that also... thanks for the reminder...
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear All,
Here is my personal usage EA code, it run's okay but can't get the stop loss and trailing stop loss to be functioning. Do you mind helping me. If possible please point out where should the instruction for 50 pip stop loss should be placed.