Hello,
This is my first time using graphical objects in an indicator. I would need to draw a vertical line everyday at the same time "22:00", could you please guide me to a solution?
Thanks
Use Cycles instead of VLine.
Regards, Luke
for (int shift22=0; shift22<Bars && TimeHour(Time[shift22])!=22; shift22++){} VLine("2200", Time[shift22] %3600, Red); // %3600 needed for M30 and lower =================================== void vLine(string name, datetime T0, color clr){ #define WINDOW_MAIN 0 if (!Show.Objects) return; /**/ if (ObjectMove( name, 0, T0, 0 )){} else if(!ObjectCreate( name, OBJ_VLINE, WINDOW_MAIN, T0, 0 )) Alert("ObjectCreate(",name,",VLINE) failed: ", GetLastError() ); if (!ObjectSet(name, OBJPROP_COLOR, clr )) // Allow color change Alert("ObjectSet(", name, ",Color) [1] failed: ", GetLastError() ); if (!ObjectSetText(name, TimeToStr(T0, TIME_MINUTES), 10)) Alert("ObjectSetText(",name,") [1] failed: ", GetLastError()); }
Hello guys,
I could solve the issue with other code (really I could not apply the solutions given above), but not at all.
Now I get vertical lines for all the previous 22:00 candles, but I need the line in the coming 22:00 candle at the right side of the price (future), how could I get that?
This is the code:
...
for (shift=NumBars;shift>=0;shift--)
}
Help!
Thanks :)
Please use this to post code . . . it makes it easier to read.
Now I get vertical lines for all the previous 22:00 candles, but I need the line in the coming 22:00 candle at the right side of the price (future), how could I get that?
- Next time be more precise with your original question.
datetime now = Time[0], bod = now - now % 86400, // Beginning of the day Hr22= bod + 22 * 3600; // 2200 VLine("2200", Hr22, Red);
- Next time be more precise with your original question.
Is it possible to draw vertical lines in the right side of the chart away from the current price by knowing only the date
For example assume current time is 2019.05.17 00:00 , and I want to draw a vertical line in the future at 2019.06.04 16:00 using the date information only ?
Yes.
Use ObjectCreate( and OBJ_VLINE
Or use this function for example:
//+------------------------------------------------------------------+ //| Create the vertical line | //+------------------------------------------------------------------+ bool VLineCreate(const long chart_ID=0, // chart's ID const string name="VLine", // line name const int sub_window=0, // subwindow index datetime time=0, // line time const color clr=clrRed, // line color const ENUM_LINE_STYLE style=STYLE_SOLID, // line style const int width=1, // line width const bool back=false, // in the background const bool selection=true, // highlight to move const bool ray=true, // line's continuation down const bool hidden=true, // hidden in the object list const long z_order=0) // priority for mouse click { //--- if the line time is not set, draw it via the last bar if(!time) time=TimeCurrent(); //--- reset the error value ResetLastError(); //--- create a vertical line if(!ObjectCreate(chart_ID,name,OBJ_VLINE,sub_window,time,0)) { Print(__FUNCTION__, ": failed to create a vertical line! Error code = ",GetLastError()); return(false); } //--- set line color ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); //--- set line display style ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); //--- set line width ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width); //--- display in the foreground (false) or background (true) ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); //--- enable (true) or disable (false) the mode of moving the line by mouse //--- when creating a graphical object using ObjectCreate function, the object cannot be //--- highlighted and moved by default. Inside this method, selection parameter //--- is true by default making it possible to highlight and move the object ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); //--- enable (true) or disable (false) the mode of displaying the line in the chart subwindows ObjectSetInteger(chart_ID,name,OBJPROP_RAY,ray); //--- hide (true) or display (false) graphical object name in the object list ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); //--- set the priority for receiving the event of a mouse click in the chart ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); //--- successful execution return(true); } //+------------------------------------------------------------------+
Thanks Marco , it did not work , I'll post the entire code , you will see in the alert that I have the right date but I am unable to create the line on that date
What I am trying to achieve is save the information I have on the chart in case its lost as sometimes when the market is closed and MT4 opens on the VPS with no connection to the broker the information is lost
So before the weekend I want to keep my lines which are in the future section of the chart ( on the far right ) to do so I created a symbol on the chart , saved the date for that Symbol then use that date to recreate the lines .. all is good except the part to re-create the lines and I wonder if someone could help with that
//+------------------------------------------------------------------+ //| TestLines.mq4 | //| Copyright 2019, Alfa | //+------------------------------------------------------------------+ #property copyright "Copyright 2019, Alpha" #property version "1.00" #property strict datetime PreTradeDOT, Symb_Chart_Dates, Exit_SymDOT; string Exit_SymSymbol = "Exit_Sym", ExitLine = "Exit"; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- OnTick(); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //---Object creation ObjectCreate(0, Exit_SymSymbol, OBJ_ARROW_DOWN, 0, Time[0] + Period() * 60 * 40, High[0]); ObjectSet(Exit_SymSymbol, OBJPROP_COLOR, Red); ObjectSet(Exit_SymSymbol, OBJPROP_STYLE, STYLE_SOLID); ObjectSet(Exit_SymSymbol, OBJPROP_WIDTH, 3); ObjectSet(Exit_SymSymbol, OBJPROP_RAY, false); ObjectSet(Exit_SymSymbol, OBJPROP_BACK, True); ObjectSet(Exit_SymSymbol, OBJPROP_NAME, True); ObjectSet(Exit_SymSymbol, OBJPROP_TEXT, True); ObjectSetText(Exit_SymSymbol, "Exit_SymSymbol", 1); datetime TimeExit_SymSymbol = (datetime) ObjectGetInteger(0, Exit_SymSymbol, OBJPROP_TIME1); string TxtExit_SymSymbol = TimeToStr(TimeExit_SymSymbol, TIME_DATE | TIME_SECONDS); //--- if (ObjectFind(0, Exit_SymSymbol) == 0) // Object is found on main screen when its ==0 { Exit_SymDOT = (datetime) ObjectGetInteger(0, Exit_SymSymbol, 0, 0); //Alert(Exit_SymDOT ); SaveDates(); } if (ObjectFind(0, ExitLine) != 0) { ReadDates(); datetime Symb_Dates = StringToTime(StringSubstr(Symb_Chart_Dates, 0, 16)); // OK Alert(Symb_Dates); VLineCreate(0, "VLine", 0, Symb_Dates, clrRed, STYLE_SOLID, 1, false, true, true, true, 0); /* // ObjectCreate(0,ExitLine, OBJ_VLINE, 0, StringToTime(Symb_Dates), Low[0]); ObjectCreate(ExitLine, OBJ_VLINE, 0, StringToTime( Symb_Dates), Low[0]); // ObjectCreate(vLine, OBJ_VLINE, 0, Time[0] + (Symb_Dates-TimeCurrent()) , Low[0]); //ObjectCreate( ExitLine, OBJ_VLINE, 0, Symb_Dates, 0 ); ObjectSet(ExitLine, OBJPROP_COLOR, Orange); ObjectSet(ExitLine, OBJPROP_STYLE, STYLE_SOLID); ObjectSet(ExitLine, OBJPROP_WIDTH, 3); ObjectSet(ExitLine, OBJPROP_RAY, false); ObjectSet(ExitLine, OBJPROP_BACK, True); */ } } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //-- Function: ReadSpread //+------------------------------------------------------------------+ void ReadDates() { string fileName = getFileName(1); int file = FileOpen(fileName, FILE_CSV | FILE_READ); //--- This is a protection to avoid low spread and also for the expert //--- if the file has not been created then create a new file Symb_Chart_Dates = (datetime) ObjectGetInteger(0, Exit_SymSymbol, OBJPROP_TIME1, 0); int ShiftEntryBar = 10, TradeExit_SymBar = 30; if (file <= -1) { Exit_SymDOT = Time[0] + Period() * 60 * TradeExit_SymBar; SaveDates(); } //--- If there is a file then save the spreads if (file > 0) { Symb_Chart_Dates = FileReadNumber(file); FileClose(file); } } // //+------------------------------------------------------------------+ //-- Function: saveSpread //+------------------------------------------------------------------+ void SaveDates() { string fileName = getFileName(1); int file = FileOpen(fileName, FILE_CSV | FILE_WRITE); if (file > 0) { FileWrite(file, PreTradeDOT, Symb_Chart_Dates, Exit_SymDOT); FileClose(file); } } //+--------------------------------------------------------------------------------------------------+ //-- Function: getFileName //+--------------------------------------------------------------------------------------------------+ string getFileName(int FileNo) { string filename; //--- The spread file will be used for all time frames if (FileNo == 1) filename = " # " + "Lines" + ".txt"; // spread file return(filename); } //+------------------------------------------------------------------+ //| Create the vertical line | //+------------------------------------------------------------------+ bool VLineCreate(const long chart_ID = 0, // chart's ID const string name = "VLine", // line name const int sub_window = 0, // subwindow index datetime time = 0, // line time const color clr = clrRed, // line color const ENUM_LINE_STYLE style = STYLE_SOLID, // line style const int width = 1, // line width const bool back = false, // in the background const bool selection = true, // highlight to move const bool ray = true, // line's continuation down const bool hidden = true, // hidden in the object list const long z_order = 0) // priority for mouse click { //--- if the line time is not set, draw it via the last bar if (!time) time = TimeCurrent(); //--- reset the error value ResetLastError(); //--- create a vertical line if (!ObjectCreate(chart_ID, name, OBJ_VLINE, sub_window, time, 0)) { Print(__FUNCTION__, ": failed to create a vertical line! Error code = ", GetLastError()); return(false); } //--- set line color ObjectSetInteger(chart_ID, name, OBJPROP_COLOR, clr); //--- set line display style ObjectSetInteger(chart_ID, name, OBJPROP_STYLE, style); //--- set line width ObjectSetInteger(chart_ID, name, OBJPROP_WIDTH, width); //--- display in the foreground (false) or background (true) ObjectSetInteger(chart_ID, name, OBJPROP_BACK, back); //--- enable (true) or disable (false) the mode of moving the line by mouse //--- when creating a graphical object using ObjectCreate function, the object cannot be //--- highlighted and moved by default. Inside this method, selection parameter //--- is true by default making it possible to highlight and move the object ObjectSetInteger(chart_ID, name, OBJPROP_SELECTABLE, selection); ObjectSetInteger(chart_ID, name, OBJPROP_SELECTED, selection); //--- enable (true) or disable (false) the mode of displaying the line in the chart subwindows ObjectSetInteger(chart_ID, name, OBJPROP_RAY, ray); //--- hide (true) or display (false) graphical object name in the object list ObjectSetInteger(chart_ID, name, OBJPROP_HIDDEN, hidden); //--- set the priority for receiving the event of a mouse click in the chart ObjectSetInteger(chart_ID, name, OBJPROP_ZORDER, z_order); //--- successful execution return(true); } //+------------------------------------------------------------------+
Is it possible to draw vertical lines in the right side of the chart away from the current price by knowing only the date
For example assume current time is 2019.05.17 00:00 , and I want to draw a vertical line in the future at 2019.06.04 16:00 using the date information only ?
Use D' format to set the wanted time in ObjectCreate()
ObjectCreate(0,"v_line",OBJ_VLINE,0,D'2019.06.04 16:00',0);
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
This is my first time using graphical objects in an indicator. I would need to draw a vertical line everyday at the same time "22:00", could you please guide me to a solution?
Thanks