MQL5 Vline creation

MQL5 Vline creation

Manage alerts

Loading saved threads...

lancegoh · External communityPost link
External question — Stack Overflow Stack Exchange Author: lancegoh Original post: https://stackoverflow.com/questions/77509376 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I am trying to draw a vertical line on MQL5 Ontick event. But its not printing the line. Anyone knows what the issue in my code? void OnTick() { MqlDateTime mqlDateTime; TimeToStruct(TimeCurrent(), mqlDateTime); // Check if it's 10:00 AM and the line hasn't been drawn yet if(mqlDateTime.hour == 10 && mqlDateTime.min == 0 && !ObjectFind(0, "Line_10AM")) { // Create a vertical line at the current time datetime targetTime = TimeCurrent(); if(!ObjectCreate(0, "Line_10AM", OBJ_VLINE, 0, targetTime, 0)) { Print("Failed to create line: ", GetLastError()); return; } // Set the color and style of the line ObjectSetInteger(0, "Line_10AM", OBJPROP_COLOR, clrBlue); ObjectSetInteger(0, "Line_10AM", OBJPROP_STYLE, STYLE_SOLID); ObjectSetInteger(0, "Line_10AM", OBJPROP_WIDTH, 2);
Quote
Report
PaulB · External communityPost link
External answer — Stack Overflow Stack Exchange Author: PaulB Original post: https://stackoverflow.com/a/77516894 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Your problem with the code as shown is the ObjectFind Function. The return value for ObjectFind is the number of the subwindow (0 means the main window of the chart), in which the object is found. If the object is not found, the function returns a negative number. To correct your code, it should read MqlDateTime mqlDateTime; TimeToStruct(TimeCurrent(), mqlDateTime); Comment(mqlDateTime.hour,"\r\n",mqlDateTime.min); // Check if it's 10:00 AM and the line hasn't been drawn yet if(mqlDateTime.hour == 10 && mqlDateTime.min == 00 && ObjectFind(0, "Line_10AM")<0) { // Create a vertical line at the current time datetime targetTime = TimeCurrent(); if(!ObjectCreate(0, "Line_10AM", OBJ_VLINE, 0, targetTime, 0)) { Print("Failed to create line: ", GetLastError()); return; } // Set the color and style of the line ObjectSetInteger(0, "Line_10AM", OBJPROP_COLOR, clrBlue); ObjectSetInteger(0, "Line_10AM", OBJPROP_STYLE, STYLE_SOLID); ObjectSetInteger(0, "Line_10AM", OBJPROP_WIDTH, 2); }
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: lancegoh Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/questions/77509376 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I am trying to draw a vertical line on MQL5 Ontick event. But its not printing the line. Anyone knows what the issue in my code? void OnTick() { MqlDateTime mqlDateTime; TimeToStruct(TimeCurrent(), mqlDateTime); // Check if it's 10:00 AM and the line hasn't been drawn yet if(mqlDateTime.hour == 10 && mqlDateTime.min == 0 && !ObjectFind(0, "Line_10AM")) { // Create a vertical line at the current time datetime targetTime = TimeCurrent(); if(!ObjectCreate(0, "Line_10AM", OBJ_VLINE, 0, targetTime, 0)) { Print("Failed to create line: ", GetLastError()); return; } // Set the color and style of the line ObjectSetInteger(0, "Line_10AM", OBJPROP_COLOR, clrBlue); ObjectSetInteger(0, "Line_10AM", OBJPROP_STYLE, STYLE_SOLID); ObjectSetInteger(0, "Line_10AM", OBJPROP_WIDTH, 2);

Cancel quote

Checking account access…