Trying to develop an indicator that will produce a horizontal line on trade entry and trade exits. where the trade history arrows show basically want horizontal lines instead or and horizontal lines. my codes compiles but does not draw the lines. any idea where to go from here. i can show the code
It compiles ok but i get no history data found. even if i open trades and close them . still no lines drawn
MQL5:
// Input parameters input int HistoryDepth = 50; // Number of past trades to display lines for //+------------------------------------------------------------------+ //| Custom Indicator Initialization function | //+------------------------------------------------------------------+ int OnInit() { // Initialization code if necessary return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom Indicator Deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { // Clean up any drawn objects when the indicator is removed for(int i = 0; i < HistoryDepth; i++) { string obj_name = "TradeLine_" + IntegerToString(i); if(ObjectFind(0, obj_name) >= 0) { ObjectDelete(0, obj_name); // Correct ObjectDelete usage for MT5 } } } //+------------------------------------------------------------------+ //| Custom Indicator Calculation function | //+------------------------------------------------------------------+ void OnTick() { // Check if there are any historical orders int totalTrades = HistoryOrdersTotal(); Print("Total trades in history: ", totalTrades); // Debugging line if (totalTrades == 0) { Print("No trade history found."); return; } // Loop through recent closed trades int startTrade = totalTrades - HistoryDepth; if (startTrade < 0) startTrade = 0; for(int i = startTrade; i < totalTrades; i++) { ulong ticket = HistoryOrderGetTicket(i); // Select the order by ticket if(HistoryOrderSelect(ticket)) { // Get trade entry price (ORDER_PRICE_OPEN for open price) double entryPrice = HistoryOrderGetDouble(ticket, ORDER_PRICE_OPEN); // Get the time of the most recent bar (you can adjust the bar index if needed) datetime barTime = iTime(Symbol(), PERIOD_D1, 0); // Get the time of the latest daily bar // Draw a horizontal line at the entry price string lineName = "TradeLine_" + IntegerToString(i); if(ObjectFind(0, lineName) < 0) { // Draw the horizontal line at the entry price ObjectCreate(0, lineName, OBJ_HLINE, 0, barTime, entryPrice); ObjectSetInteger(0, lineName, OBJPROP_COLOR, clrBlue); // Line color (can be customized) ObjectSetInteger(0, lineName, OBJPROP_RAY_RIGHT, 0); // Don't extend the line to the right } } else { Print("Error selecting history order ", i, " - ", GetLastError()); // Debugging line } } }
Post automatically merged:
It compiles ok but i get no history data found. even if i open trades and close them . still no lines drawn
Last edited by a moderator: