Yes, the current implementation is functionally correct.
At runtime, base_type is only used when found == true , and the function exits early otherwise. Therefore, under the current logic, the variable will always be assigned before use, and the EA will behave correctly.
However, the compiler warning is also valid from a formal and safety perspective. The compiler cannot mathematically guarantee that base_type is initialized on all possible code paths. For this reason, the section can be cleanly replaced with an explicitly initialized and safer version, which removes the warning and makes the code fully deterministic and market-ready.
Replacing the entire section improves:
-
code clarity
-
formal correctness
-
future maintainability
//+------------------------------------------------------------------+ bool PlaceGrid() { double base_price = 0.0; ENUM_POSITION_TYPE base_type = POSITION_TYPE_BUY; bool found = false; for(int i = 0; i < PositionsTotal(); i++) { ulong ticket = PositionGetTicket(i); if(!PositionSelectByTicket(ticket)) continue; if(PositionGetInteger(POSITION_MAGIC) != Magic_Number) continue; base_price = PositionGetDouble(POSITION_PRICE_OPEN); base_type = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE); found = true; break; } if(!found) return false; double lot = CalcLot(); if(lot <= 0) return false; double point = _Point; for(int i = 1; i <= Numb_Orders; i++) { double offset = (Distance + Grid_Step * i) * point; double buy = base_price; double sell = base_price; if(base_type == POSITION_TYPE_BUY) { buy += offset; sell -= offset; } else { buy -= offset; sell += offset; } buy = NormalizeDouble(buy, _Digits); sell = NormalizeDouble(sell, _Digits); double buy_tp = NormalizeDouble(buy + Take_Profit * point, _Digits); double sell_tp = NormalizeDouble(sell - Take_Profit * point, _Digits); if(!Type_Limit) { if(CheckMoneyForTrade(_Symbol, lot, ORDER_TYPE_BUY_STOP)) trade.BuyStop(lot, buy, _Symbol, 0, buy_tp); if(CheckMoneyForTrade(_Symbol, lot, ORDER_TYPE_SELL_STOP)) trade.SellStop(lot, sell, _Symbol, 0, sell_tp); } else { if(CheckMoneyForTrade(_Symbol, lot, ORDER_TYPE_BUY_LIMIT)) trade.BuyLimit(lot, buy, _Symbol, 0, buy_tp); if(CheckMoneyForTrade(_Symbol, lot, ORDER_TYPE_SELL_LIMIT)) trade.SellLimit(lot, sell, _Symbol, 0, sell_tp); } } return true; }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use

Grid Master:
Overview Grid Master EA is an automated trading system that implements a bidirectional grid strategy. It places multiple pending orders above and below the current market price, capturing profits from market oscillations in both directions.
Author: Zbynek Liska