Grid help

 

Hello I've this grid system code from my EA. When the conditions for buy order have been fulfilled the Grid will be activated. Anytime the price moves down by the grip gap points the EA will open sell grid orders and when the sell order conditions have been activated and the price moves up by the grid gap the EA will open buy grid orders. Kindly help me in address this logic in my code. Your help will be appreciated. Thank you

void Grid()
   {
     
     //Buy grid
     if(data.buys > 0)
       {
          if(Ask <= data.buy_open_price - grid_gap * Point())
            {
               double lots = data.buy_lots;
               if(use_marti && multiplier > 0)lots = lots * multiplier;
               BUY(lots);
            }
       }
     //Sell grid
     if(data.sells > 0)
       {
          if(Bid >= data.sell_open_price + grid_gap * Point())
            {
               double lots = data.sell_lots;
               if(use_marti && multiplier > 0)lots = lots * multiplier;
               SELL(lots);
            }
       }  
     
   }
   
 

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)

 
William Roeder #:

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

Thank you for the concern though I'm just new to programming and this code is for my learning purposes. It's a grid system that uses martingale. The help I want is make the EA anytime we have  a buy order and price moves down it'll activate grid sell orders and when sell order was initially taken and price moves up it'll activate grid buy orders. 

 
Ernest Akoyi #:

Thank you for the concern though I'm just new to programming and this code is for my learning purposes. It's a grid system that uses martingale. The help I want is make the EA anytime we have  a buy order and price moves down it'll activate grid sell orders and when sell order was initially taken and price moves up it'll activate grid buy orders. 

Honestly, I don't think anyone will help you with a grid and/or martingale...

If you are learning, I strongly suggest, you learn MQL5, it's much more advanced, has continuous development and a larger, more active community...

MQL4+ and especially MQL4 is considered EOL.

If you want to start, start with something serious. Try one of the examples provided in your Experts folder.
 
Ernest Akoyi #: Thank you for the concern though I'm just new to programming and this code is for my learning purposes. It's a grid system that uses martingale. The help I want is make the EA anytime we have  a buy order and price moves down it'll activate grid sell orders and when sell order was initially taken and price moves up it'll activate grid buy orders. 
Dominik Christian Egert #: Honestly, I don't think anyone will help you with a grid and/or martingale... If you are learning, I strongly suggest, you learn MQL5, it's much more advanced, has continuous development and a larger, more active community... MQL4+ and especially MQL4 is considered EOL. If you want to start, start with something serious. Try one of the examples provided in your Experts folder.

I agree with @Dominik Christian Egert.

Start learning with something that will be useful and based on practical experience when trading manually. For example, creating trading assistants that will help develop your trading skills.

Practical knowledge when trading manually is vital when designing and coding an EA.

 
Fernando Carreiro #:

I agree with @Dominik Christian Egert.

Start learning with something that will be useful and based on practical experience when trading manually. For example, creating trading assistants that will help develop your trading skills.

Practical knowledge when trading manually is vital when designing and coding an EA.

Thank you all for your guidance.