the code is not excuting any order can you fix it…
- User
the code is not excuting any order can you fix it //+------------------------------------------------------------------+ //| ThreePipTrader.mq5 | //| Created by OpenAI Assistant | //+------------------------------------------------------------------+ #property copyright "OpenAI" #property link "https://openai.com/" #property version "1.00" #property strict
// Inputs input double Lots = 0.1; // Lot size input int PipDistance = 3; // Distance in pips to trigger orders input int ReversePips = 6; // Pips reversal to open opposite trade input int TakeProfitPips = 3; // Take Profit in pips
// Global variables double BuyTriggerPrice; double SellTriggerPrice; bool BuyOrderOpen = false; bool SellOrderOpen = false;
//+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { // Initialize trigger prices to current Bid price double price = SymbolInfoDouble(_Symbol, SYMBOL_BID); BuyTriggerPrice = price + (PipDistance * _Point); SellTriggerPrice = price - (PipDistance * _Point); return(INIT_SUCCEEDED); }
//+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID); double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
// Check if there are open orders BuyOrderOpen = IsOrderOpen(ORDER_TYPE_BUY); SellOrderOpen = IsOrderOpen(ORDER_TYPE_SELL);
// If no orders are open, check for new trade conditions if(!BuyOrderOpen && !SellOrderOpen) { // Check for buy condition if(bid >= BuyTriggerPrice) { OpenOrder(ORDER_TYPE_BUY); // Set new trigger prices BuyTriggerPrice = bid + (ReversePips * _Point); SellTriggerPrice = bid - (ReversePips * _Point); } // Check for sell condition else if(bid <= SellTriggerPrice) { OpenOrder(ORDER_TYPE_SELL); // Set new trigger prices BuyTriggerPrice = bid + (ReversePips * _Point); SellTriggerPrice = bid - (ReversePips * _Point); } } else { // If a buy order is open and price reverses by ReversePips, open a sell trade with TP if(BuyOrderOpen && bid <= (BuyTriggerPrice - (ReversePips * _Point))) { OpenOrder(ORDER_TYPE_SELL, TakeProfitPips); BuyOrderOpen = false; // Close the buy order status } // If a sell order is open and price reverses by ReversePips, open a buy trade with TP else if(SellOrderOpen && bid >= (SellTriggerPrice + (ReversePips * _Point))) { OpenOrder(ORDER_TYPE_BUY, TakeProfitPips); SellOrderOpen = false; // Close the sell order status } } }
//+------------------------------------------------------------------+ //| Function to check if there is an open order of a specific type | //+------------------------------------------------------------------+ bool IsOrderOpen(ENUM_ORDER_TYPE type) { ulong ticket = PositionGetTicket(0); if(ticket != 0) { if(PositionGetInteger(POSITION_TYPE) == type) return true; } return false; }
- Assistant