Download MetaTrader 5
To add comments, please log in or register
No time for trading? Subscribe to signals!
MGsid
5
MGsid 2016.06.18 13:48 

Could someone tell me where i make mistake. Function calculates Stop Loss incorrectly for Buy signals (Bid>MA). For Sell orders (Bid<MA) everything is fine.

double CalcStopLoss(double MA)
    {
      double SL,Fractal,stoplevel;
      int i,j;
     
      stoplevel=MarketInfo(Symbol(),MODE_STOPLEVEL);
     
         if(Bid>MA)
         {
            for(i=1; i<100; i++)
            {
               Fractal=iFractals(NULL,0,MODE_LOWER,i);
               if(Fractal!=0)
                  if(Fractal<Ask-stoplevel*Point)
                  {
                     SL=(Ask-Fractal)+SLFracPips*Point;
                     break;
                  }
            }
         }
         if(Bid<MA)
         {
            for(j=1; j<100; j++)
            {
               Fractal=iFractals(NULL,0,MODE_UPPER,j);
               if(Fractal!=0)
                  if(Fractal>Bid+stoplevel*Point)
                  {
                     SL=(Fractal-Bid)+SLFracPips*Point;
                     break;
                  }
            }
         }   
    return(SL);
    }
/
To add comments, please log in or register