wrong stop loss and take profit

 

Hello, I have the following problem. I wrote my expert advisor and it works well on live trading. But when I put it in the strategy tester, my stop loss and take profit are wrong. Can someone tell me what's going on?

 
The problem is that, we see no code. 
 
datetime londonOpenDate = StringToTime(londonOpen);

   if(londonOpenDate == iTime(_Symbol,PERIOD_CURRENT,0) && NewBar() == true)
     {
      int shift = iBarShift(_Symbol,PERIOD_CURRENT,__DATE__,false);

      int highPriceIndex = iHighest(_Symbol,PERIOD_CURRENT,MODE_HIGH,shift,1);
      double highPrice = iHigh(_Symbol,PERIOD_CURRENT,highPriceIndex);

      int lowPriceIndex = iLowest(_Symbol,PERIOD_CURRENT,MODE_LOW,shift,1);
      double lowPrice = iLow(_Symbol,PERIOD_CURRENT,lowPriceIndex);

      double asiaHighPips = NormalizeDouble((highPrice - Close(1)) / 0.0001, 1);
      double asiaLowPips = NormalizeDouble((Close(1) - lowPrice) / 0.0001, 1);
      if(asiaHighPips < asiaLowPips)
        {
         double lots = 0.01;
         double stopLoss = highPrice;
         if(asiaHighPips < minSL)
            stopLoss = Close(1) + (minSL * 0.0001);
         double takeProfit = lowPrice;

         trade.Sell(lots,_Symbol,0,stopLoss,takeProfit,"Sell");
        }
      if(asiaHighPips > asiaLowPips)
        {
         double lots = 0.01;
         double stopLoss = lowPrice;
         if(asiaLowPips < minSL)
            stopLoss = Close(1) - (minSL * 0.0001);
         double takeProfit = highPrice;
         trade.Buy(lots,_Symbol,0,stopLoss,takeProfit,"Buy");
        }
     }
Ioannis Christopoulos #:
The problem is that, we see no code. 
 
   double SymPoint = 0.0001;
   if(SymbolInfoInteger(_Symbol,SYMBOL_DIGITS) == 3)
      SymPoint = 0.01;

    double bid=SymbolInfoDouble(_Symbol,SYMBOL_BID); 
    double ask=SymbolInfoDouble(_Symbol,SYMBOL_ASK);  

datetime londonOpenDate = StringToTime(londonOpen);

   if(londonOpenDate == iTime(_Symbol,PERIOD_CURRENT,0) && NewBar() == true)
     {
      int shift = iBarShift(_Symbol,PERIOD_CURRENT,__DATE__,false);

      int highPriceIndex = iHighest(_Symbol,PERIOD_CURRENT,MODE_HIGH,shift,1);
      double highPrice = iHigh(_Symbol,PERIOD_CURRENT,highPriceIndex);

      int lowPriceIndex = iLowest(_Symbol,PERIOD_CURRENT,MODE_LOW,shift,1);
      double lowPrice = iLow(_Symbol,PERIOD_CURRENT,lowPriceIndex);

      double asiaHighPips = NormalizeDouble((highPrice - Close(1)) / 0.0001, 1);
      double asiaLowPips = NormalizeDouble((Close(1) - lowPrice) / 0.0001, 1);
      if(asiaHighPips < asiaLowPips)
        {
         double lots = 0.01;
         double stopLoss = highPrice;
         if(asiaHighPips < minSL)
            stopLoss = bid + (minSL * SymPoint);
         double takeProfit = lowPrice;

         trade.Sell(lots,_Symbol,bid,stopLoss,takeProfit,"Sell");
        }
      if(asiaHighPips > asiaLowPips)
        {
         double lots = 0.01;
         double stopLoss = lowPrice;
         if(asiaLowPips < minSL)
            stopLoss = ask - (minSL * SymPoint);
         double takeProfit = highPrice;
         trade.Buy(lots,_Symbol,ask,stopLoss,takeProfit,"Buy");
        }
     }
Well.. many mistakes i see. i try to fix and replece some of them. good luck with learning mql5 . search more, read more, ask less.
 
Thanks, but I don't think this will help me. You changed some things. For starters, I'm using my own functions in some places and it's confusing everything. I can't understand why when I trade live everything is fine, but when I put it in the strategy tester, my stop loss and take profit are wrong.
 
Yordan Tzonev #:
Thanks, but I don't think this will help me. You changed some things. For starters, I'm using my own functions in some places and it's confusing everything. I can't understand why when I trade live everything is fine, but when I put it in the strategy tester, my stop loss and take profit are wrong.
  stopLoss = Close(1) - (minSL * 0.0001);

if on tester you try to trade on JPY pairs then you will have problem. i solved this problem with my part of code

 
I know that. I will not trade JPY pairs. If I decide to do it I will change the code. And I wrote this CLose (1) function for the closing price. Because iClose() is very long.