Trendline

 

Hi!


I try to make a trendline that starts at the current bar and is draw 20 bars in the future, I tried to use this code below but it do not work, Code is Mql5.
Any suggestions?

ObjectDelete(0,"H5"); ObjectCreate(0,"H5",OBJ_TREND,0,TimeCurrent(),H5,time[-20],H5);
ObjectSetInteger(0,"H5",OBJPROP_COLOR,clrGreen); ObjectSetInteger(0,"H5",OBJPROP_STYLE,STYLE_SOLID);
ObjectSetInteger(0,"H5",OBJPROP_WIDTH,2); ObjectSetInteger(0,"H5",OBJPROP_BACK,false);
ObjectSetString(0,"H5",OBJPROP_TEXT,"H5 LB Target");     ObjectSetDouble(0,"H5",OBJPROP_PRICE,H5);


Thanks,


Kim

 
Blackbay:

Hi!


I try to make a trendline that starts at the current bar and is draw 20 bars in the future, I tried to use this code below but it do not work, Code is Mql5.
Any suggestions?

ObjectDelete(0,"H5"); ObjectCreate(0,"H5",OBJ_TREND,0,TimeCurrent(),H5,time[-20],H5);
ObjectSetInteger(0,"H5",OBJPROP_COLOR,clrGreen); ObjectSetInteger(0,"H5",OBJPROP_STYLE,STYLE_SOLID);
ObjectSetInteger(0,"H5",OBJPROP_WIDTH,2); ObjectSetInteger(0,"H5",OBJPROP_BACK,false);
ObjectSetString(0,"H5",OBJPROP_TEXT,"H5 LB Target");     ObjectSetDouble(0,"H5",OBJPROP_PRICE,H5);


Thanks,


Kim

The sample code belongs to me.

You have to review the manual from the beginning: https://www.mql5.com/en/docs/constants/objectconstants/enum_object_property#enum_object_property_integer

Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Properties
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Properties
  • www.mql5.com
All objects used in technical analysis are bound to the time and price coordinates: trendline, channels, Fibonacci tools, etc. But there is a number of auxiliary objects intended to improve the user interface that are bound to the always visible part of a chart (main chart windows or indicator subwindows): – defines the chart corner relative...
 

Ok, but I think most of the "SetInteger" code is working, the problem is how to obtain the time/date for the 20th bar.

So this part of the code:

ObjectCreate(0,"H5",OBJ_TREND,0,TimeCurrent(),H5,time[-20],H5);

 
Blackbay:

Ok, but I think most of the "SetInteger" code is working, the problem is how to obtain the time/date for the 20th bar.

So this part of the code:

ObjectCreate(0,"H5",OBJ_TREND,0,TimeCurrent(),H5,time[-20],H5);

How about:

ObjectCreate(0,"H5",OBJ_TREND,0,TimeCurrent(),H5,TimeCurrent()+20*Period()*60,H5);
And as an alternative (although not equal to TimeCurrent()), Time[0] will give you the exact start time of the latest bar...
 
Blackbay: draw 20 bars in the future,

Can't be done.

  1. Time[0]+20*Period()*60 will not work. @Seng Joo Thio It assumes that the value of the enumeration (ENUM_TIMEFRAMES) equals the period in minutes. On MT 5 ENUM_TIMEFRAMES values are not the period in minutes.
    Use EnumToString(TF[i]) to see the string representation of the time frame.
    Use PeriodSeconds(TF[i]) to see the duration of the time frame.
              Why calculations of period()_value are different? (over 30 minutes) What's Burg? - Indices - Technical Indicators - MQL5 programming forum

  2. Time[0]+20*PeriodSeconds() will not work. It assumes that all bars exist in the future. What if there are no ticks during a specific candle period? There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific.) requires knowledge of when your broker stops and starts (not necessary the same as the market.)
              "Free-of-Holes" Charts - MQL4 Articles
              No candle if open = close ? - MQL4 programming forum

  3. № 2 is only an approximation, and you can update the time each new bar.
 
William Roeder:

Can't be done.

  1. Time[0]+20*Period()*60 will not work. @Seng Joo Thio 
Oops! Thanks for pointing that out. 

I must make it a point to refrain from posting any messages at 5 plus in the morning - error rate is waaaaaaaaayy too high 😂😂😂
 
Seng Joo Thio: I must make it a point to refrain from posting any messages at 5 plus in the morning - error rate is waaaaaaaaayy too high 😂😂😂

Been there, done that. Need c o f f e e.

Reason: