Having trouble with a positionModify method

 

Hi.

I have made an EA which I want to improve by moving SL and TP while a position is running.

What I do not understand is how this method changes my backtesting result??!?

<Deleted> when i'm not calling this method - but when I'm calling the method my EA breaks down pretty fast...


As you can see I have out-commented the lines where it actually makes changes - so  now it should not make any changes - but still the EA breaks.

When I debug and step though the code it seems like it doesen't make changes. 

Does the execution-time matter that much? Or what can be my problem?



Code; 

***

Testing trading strategies on real ticks
Testing trading strategies on real ticks
  • www.mql5.com
The article provides the results of testing a simple trading strategy in three modes: "1 minute OHLC", "Every tick" and "Every tick based on real ticks" using actual historical data.
 
Ulrikhjul :


To insert the code, use the Codebutton

 
void moveStopLoss()
{
   double sl = normalizePrice(m_position.StopLoss());
   double currentPrice = normalizePrice(m_position.PriceCurrent());

   for(int i=PositionsTotal()-1; i>=0; i--)
   {
     if(m_position.SelectByIndex(i))
     {
         if(m_position.Symbol()==m_symbol.Name());// && m_position.Magic()==InpMagic)
         {
            //if buy pos
            if(m_position.PositionType()==POSITION_TYPE_BUY)
            {
               double slMoveLevel = sl+(NormalizeDouble(1000 * _Point, _Digits));                        // DowJones : 1 point = 0,1  
            
               if(slMoveLevel <= currentPrice)
               {
                  double slNew = sl;//+(NormalizeDouble(100 * _Point, _Digits ));                        //Move sl +10
                  double tpNew = m_position.TakeProfit();//+(NormalizeDouble(25*_Point, _Digits));
                  trade.PositionModify(m_position.Ticket(), slNew, tpNew);
               }               
            }
            //If sell pos
            if(m_position.PositionType()==POSITION_TYPE_SELL)
            {
               double slMoveLevel = sl-(NormalizeDouble(1000 * _Point, _Digits));                        // Ved DowJones er 1 point = 0,1  
               
               if(slMoveLevel >= currentPrice)
               {
                  double slNew = sl;//-(NormalizeDouble(100 * _Point, _Digits ));                        //Move sl -10
                  double tpNew = m_position.TakeProfit();//-(NormalizeDouble(25*_Point, _Digits));
                  trade.PositionModify(m_position.Ticket(), slNew, tpNew);  
               }
            }

         }
         
     }
   
   }
}
 

Like that :)

Thanks

Reason: