Drawing TrendLine Forward in time

 

is it possible to draw a trend line forward in time ?
for example: from low of candle -5 to high of candle -8 ?

 I tried this but its not working since it expects a positive number 

            ObjectCreate(0,i,OBJ_TREND,0,Time[-5],High[-5],Time[-8],Low[-8]);
            ObjectSetInteger(0,i,OBJPROP_COLOR,clrLime);
            ObjectSetInteger(0,i,OBJPROP_STYLE,STYLE_SOLID);
            ObjectSetInteger(0,i,OBJPROP_WIDTH,3);
            ObjectSetInteger(0,i,OBJPROP_BACK,false);
            ObjectSetInteger(0,i,OBJPROP_SELECTABLE,false);
            ObjectSetInteger(0,i,OBJPROP_SELECTED,false);
            ObjectSetInteger(0,i,OBJPROP_RAY_RIGHT,false);
            ObjectSetInteger(0,i,OBJPROP_HIDDEN,true);

Is there any way to draw it forward in time ?


Thanks 

 

yes there is but it's not done purely tru the array, since arrays do not have access to future values


you must calculate ''by hand'' the future ending time so instead of using Time[ending position in the future], you must know the time when your line will end, which is possible if you have some regularity in what you are doing. Let's say you know the index '' beginning_index'' for the beginning of the trend line and you know that the ending Time of the trend line is N indexes later on, so you add ""N periods" to the beginning of the trend line.


for instance, if you count the index from left to right, ie your array is NOT a series, ie the leftmost bar is at index 0 and the rightmost bar is at Bars-1,

datetime future_ending_point=Time[beginning_index]+(N-1)*_Period //N-1 because you count the bar at index '' beginning_index '' inside the N bars...


or I think this works too: you use  Time[N-1]-Time[0] which should give  the total time it took for the first N bars to appear and since your graph is regularl, it takes always the same amount of time to form N bars:

datetime future_ending_point=Time[beginning_index]+Time[N-1]-Time[0]


if your ''' beginning_index '' changes all the time, ie it is like some index ''i'' from some loop ''for'' and so son, you need to update all the time your  ending time of your trend line, so you must add

 ObjectSet(NAME OF TRENDLINE,OBJPROP_TIME2, future_ending_point );


you probably should update the beginning time and also beginning price and ending price too

 
  1. Enau:
    datetime future_ending_point=Time[beginning_index]+(N-1)*_Period
    Don't do that, as it will make converting to MT5 harder, where period values are not multiple of minutes.
    datetime future_ending_point=Time[beginning_index]+(N-1)*PeriodSeconds()

  2. Enau: or I think this works too: you use  Time[N-1]-Time[0] which should give  the total time it took for the first N bars to appear and since your graph is regularl, it takes always the same amount of time to form N bars:
    datetime future_ending_point=Time[beginning_index]+Time[N-1]-Time[0]

    Wrong. This assumes that all bars exist — they don't. 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 20 June 2006
              No candle if open = close ? - MQL4 programming forum

Reason: