Grid entry

 

Hello everyone below is my grid code though it's not functioning as per my logic. The grid orders should only be triggered once the original buy and sell conditions have been met within the specified grid distance. What my code does it only triggers grid orders at the specified grid distance without waiting for the entry conditions to be made. Kindly help.

void Grid()
  {
     //buy grid
     if(use_marti == true)
       {
           
            if(data.buys > 0)
               {
                  if(Ask <= data.buy_open_price - marti_Distance * Point())
                     {
                        double lots = data.buy_lots;
                        if(use_marti && multiplier > 0)lots = lots * multiplier;
                        
                        BUY(lots);
                        
                        data = GetData(data);
                        ModifyTP();
                     }
               }
               
            if(data.sells > 0)
               {
                 
                  if(Bid >= data.sell_open_price + marti_Distance * Point())
                     {
                        double lots = data.sell_lots;
                        if(use_marti && multiplier > 0)lots = lots * multiplier;
                        
                        SELL(lots);
                        
                        data = GetData(data);
                        ModifyTP();
                     }
               }
               
       }         
  }   
 
Ernest Akoyi:

Hello everyone below is my grid code though it's not functioning as per my logic. The grid orders should only be triggered once the original buy and sell conditions have been met within the specified grid distance. What my code does it only triggers grid orders at the specified grid distance without waiting for the entry conditions to be made. Kindly help.

what is data.buys? Is that your condition for Buy ?  This grid is more is more like a recovery for a losing trade I suppose… I mean your are buying in a down market 
 

Martingale is not a strategy. It's a betting system.

Hedging, grid trading, same as Martingale.
          Martingale, Hedging and Grid : MHG - General - MQL5 programming forum (2016)

Martingale, guaranteed to blow your account eventually. If your strategy is not profitable without, it is definitely not profitable with.
          Martingale vs. Non Martingale (Simplified RoR vs Profit and the Illusions) - MQL5 programming forum (2015)

Why it won't work:
          Calculate Loss from Lot Pips - MQL5 programming forum (2017)
          THIS Trading Strategy is a LIE... I took 100,000 TRADES with the Martingale Strategy - YouTube (2020)