-
Play videoPlease edit your post.
For large amounts of code, attach it.
extern double StopLoss = 100; extern double TakeProfit = 50; if(Digits==3 || Digits ==5){ TakeProfit*=10; StopLoss*=10; }
Every time you change pair/TF and other things, the EA goes through a Deinit/Init cycle. It is not reloaded. Therefor your StopLoss becomes 1,000, 10,000, 100,000. See my pips2dblpoint=MarketInfo(pairs[MaxIndex],MODE_POINT); dig=MarketInfo(pairs[MaxIndex],MODE_DIGITS); CurrentPriceBid=MarketInfo(pairs[MaxIndex],MODE_BID); CurrentPriceAsk=MarketInfo(pairs[MaxIndex],MODE_ASK);
Why are you doing this. Digits is only for the chart pair. But now you are looking at other pairs. You are overly complicating everything. Trading other pairs mean you can not use any predefined variables and must pole all symbols for new ticks (onTick is called only for the current chart.) Make your EA trade the current chart pair only. Then put it on multiple charts. Done.StopLoss=NormalizeDouble(CurrentPriceAsk+StopLoss*point,dig);
StopLoss was 100 or 1000, i.e. points. Now you've change it to a price. 1.2345. What happens on the next OrderSend when SL = current price + price*point = current price +0.000012345- Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it.
It's use is always wrong
- SL/TP are market orders when triggered, they don't need to be normalized, only abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 forum
- Only the open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum
- Lot size must also be adjusted to a multiple of LotStep. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
i need simple logic
extern double StopLoss = 100;
extern double TakeProfit = 50;
if(Digits==3 || Digits ==5)
{
TakeProfit*=10;
StopLoss*=10;
}
dig=MarketInfo(pairs[MaxIndex],MODE_DIGITS);
to SELL
StopLoss=NormalizeDouble(CurrentPriceAsk+StopLoss*point,dig);
TakeProfit=NormalizeDouble(CurrentPriceBid-TakeProfit*point,dig);
OrderSend(pairs[MaxIndex], OP_SELL, Lots,CurrentPriceBid, Slippage, StopLoss,TakeProfit,"Sell",Magic,0,Blue)
to BUY
StopLoss=NormalizeDouble(CurrentPriceBid-StopLoss*point,dig);
TakeProfit=NormalizeDouble(CurrentPriceAsk+TakeProfit*point,dig);
OrderSend(pairs[MaxIndex],OP_BUY, Lots, CurrentPriceAsk,Slippage, StopLoss,TakeProfit,"Buy",Magic,0,Green)
I got expected TakeProfit +/- Slippage (47, 49 or 50) but StopLoss about 107, 109, any ideas why?