have some issue to set StopLoss

Back to topics list To post a new topic, please log in or register
avatar
19
GoodPointMas 2015.04.28 08:28
 

i need simple logic

 

extern double StopLoss    = 100;

extern double TakeProfit  = 50;

if(Digits==3 || Digits ==5)

   {

      TakeProfit*=10;

      StopLoss*=10;

   }

 

point=MarketInfo(pairs[MaxIndex],MODE_POINT);

dig=MarketInfo(pairs[MaxIndex],MODE_DIGITS);

CurrentPriceBid=MarketInfo(pairs[MaxIndex],MODE_BID);
CurrentPriceAsk=MarketInfo(pairs[MaxIndex],MODE_ASK);

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? 


avatar
13009
WHRoeder 2015.04.28 15:04 #
 
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. 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 pips2dbl
  3. point=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.
  4. 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
  5. Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong

Back to topics list  

To add comments, please log in or register