NexusFi: Find Your Edge


Home Menu

 





Drawing trendline in "future"


Discussion in EasyLanguage Programming

Updated
    1. trending_up 2,390 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 6 posts
    2. attach_file 1 attachments




 
Search this Thread
  #1 (permalink)
berni147
Bratislava, Slovakia
 
Posts: 4 since Nov 2022
Thanks Given: 1
Thanks Received: 0

Hello,

is it possible to drawn trendlines in "future"? So far I was always drawing in "history". e.g. from current candle to candle[5] before,but now I would like to draw line (constant) for next N (e.g. 5) candles. Is that possible?

From TrendLine.Create (Create(DTPoint, DTPoint)) it looks like I need date in future, so Ideally if I can get BarDateTime from next Nth candle (BarDateTime[-5] or something like that) Is that possible?

Other option would probably be to draw long line and then cut it off once Nth candle reached.

Thanks


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Iran Update May 8: Still Reviewing MOU, Demands Reparati …
Traders Hideout
ATFX Suspends Prop Trading Unit ATFunded -- Full Review …
Funded Trading Evaluation Firms
Election Sunday Resolves: Peru Heads to Runoff at 42pct, …
Prediction Markets & Event Contracts
Powell in 48 Hours: Word Markets Give 78% on Inflation, …
Prediction Markets & Event Contracts
UMA Votes Tonight: Polymarkets $80M Strategy Bitcoin Bat …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Big Mike in Ecuador
196 thanks
Sober Journey With S&P
27 thanks
30 Sessions
20 thanks
BERN ALGOS algo trading journal
8 thanks
Volume Indicators
8 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,642

berni147,

welcome to NexusFi.

Depending on the bar type you are working with, you could calculate the end DateTime of your trendline by adding a TimeSpan which corresponds to five times the duration of your bar span to your start DateTime to calculate the end point.
Another idea could be using Barnumbers and BNPoints instead. What you mentioned in your last sentence would work as well i.e. moving the end point with every new bar for five bars.

Regards,

ABCTG


berni147 View Post
Hello,

is it possible to drawn trendlines in "future"? So far I was always drawing in "history". e.g. from current candle to candle[5] before,but now I would like to draw line (constant) for next N (e.g. 5) candles. Is that possible?

From TrendLine.Create (Create(DTPoint, DTPoint)) it looks like I need date in future, so Ideally if I can get BarDateTime from next Nth candle (BarDateTime[-5] or something like that) Is that possible?

Other option would probably be to draw long line and then cut it off once Nth candle reached.

Thanks


Follow me on X Reply With Quote
  #3 (permalink)
berni147
Bratislava, Slovakia
 
Posts: 4 since Nov 2022
Thanks Given: 1
Thanks Received: 0



ABCTG View Post
berni147,

welcome to NexusFi.

Depending on the bar type you are working with, you could calculate the end DateTime of your trendline by adding a TimeSpan which corresponds to five times the duration of your bar span to your start DateTime to calculate the end point.
Another idea could be using Barnumbers and BNPoints instead. What you mentioned in your last sentence would work as well i.e. moving the end point with every new bar for five bars.

Regards,

ABCTG


Thanks, BNPoints looks exactly like a way to go. However, there is something weird with it. I had a look at the definition of Trendline, there is a nice example how to use BNPoints - so I take that and apply to my case - something like this (simplified):

If LastBarOnChart then
Begin
myBNPoint1 = BNPoint.Create(barnumber,4000);
myBNPoint2 = BNPoint.Create(barnumber+10,4000);
MyTL = TrendLine.Create( myBNPoint1, myBNPoint2 ) ;
MyTL.ExtRight = False ;
DrawingObjects.Add( MyTL ) ;
End;


TrendLine is plotted but it is shifted to the left. If I add debug prints of myBNPoint1, it refers to the correct barnumber&price, even if I change barnumbers so that line is plotted in history - BNPoints seem to be correct but the line is shifted.

Funny thing is that TrendLine is shifted always by 23 candles, so if I add some magic_constant=23 there:
mag_const=23;
myBNPoint1 = BNPoint.Create(barnumber+mag_const,4000);
myBNPoint2 = BNPoint.Create(barnumber+mag_const+10,4000);

It works as expected. However, I would like to avoid Bulgarian constants in my code

Thanks!


Reply With Quote
  #4 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,642

berni147,

when you refer to the BNPoint class description in the help file it will become clear that the maxbarsback value for a study must be included since a BNPoint refers to the absolute bar index (zero-based) of the collection of bars in a chart.

Regards,

ABCTG


berni147 View Post
Thanks, BNPoints looks exactly like a way to go. However, there is something weird with it. I had a look at the definition of Trendline, there is a nice example how to use BNPoints - so I take that and apply to my case - something like this (simplified):

If LastBarOnChart then
Begin
myBNPoint1 = BNPoint.Create(barnumber,4000);
myBNPoint2 = BNPoint.Create(barnumber+10,4000);
MyTL = TrendLine.Create( myBNPoint1, myBNPoint2 ) ;
MyTL.ExtRight = False ;
DrawingObjects.Add( MyTL ) ;
End;


TrendLine is plotted but it is shifted to the left. If I add debug prints of myBNPoint1, it refers to the correct barnumber&price, even if I change barnumbers so that line is plotted in history - BNPoints seem to be correct but the line is shifted.

Funny thing is that TrendLine is shifted always by 23 candles, so if I add some magic_constant=23 there:
mag_const=23;
myBNPoint1 = BNPoint.Create(barnumber+mag_const,4000);
myBNPoint2 = BNPoint.Create(barnumber+mag_const+10,4000);

It works as expected. However, I would like to avoid Bulgarian constants in my code

Thanks!


Follow me on X Reply With Quote
Thanked by:
  #5 (permalink)
berni147
Bratislava, Slovakia
 
Posts: 4 since Nov 2022
Thanks Given: 1
Thanks Received: 0

You are right, adding maxbarsback minus one works ; barnumber+MaxBarsBack-1 points to the current candle. Thanks a lot for your help.



ABCTG View Post
berni147,

when you refer to the BNPoint class description in the help file it will become clear that the maxbarsback value for a study must be included since a BNPoint refers to the absolute bar index (zero-based) of the collection of bars in a chart.

Regards,

ABCTG


Reply With Quote
  #6 (permalink)
berni147
Bratislava, Slovakia
 
Posts: 4 since Nov 2022
Thanks Given: 1
Thanks Received: 0


ABCTG View Post
berni147,

when you refer to the BNPoint class description in the help file it will become clear that the maxbarsback value for a study must be included since a BNPoint refers to the absolute bar index (zero-based) of the collection of bars in a chart.

Regards,

ABCTG

I have one more question if I may, I have tried this approach live and it drawing seem to be a bit weird.
The code is very simple; Im creating two BNPoints and displaying them:


 
Code
	
                myBNPoint1 = BNPoint.Create(barnumber+Maxbarsback,value);
		myBNPoint2 = BNPoint.Create(barnumber+Maxbarsback+history_candles-1,value);
		
		MyTL = TrendLine.Create( myBNPoint1, myBNPoint2 ) ;
When running on historical data, lines are perfect. Once this goes live, lines are for some reason shorter. Basically on history data there is line above each N bars whereas running live the line is only on top of first few bars, e.g. when history_candles is set to 10, I would have line on top of each 10 bars in history but when running live, line would be drawn only on first 5 bars, then 5 bars without line, and again new line but again only on first few bars.. When I would re-run indicator, lines would be correct (again until I go live).

My first though was that barnumber is different or maxbarsback is different when running live, but funny thing is that Im always printing out both BNPoints and the numbers are still the same regardless running live or not - it is always BNPoint1 -> X and BNPoint2 -> X + history_candles. So, although BNPoints are still calculated correctly, lines are not drawn correctly.

Is there anything else Im missing?

Thanks!


Attached Thumbnails
Click image for larger version

Name:	image_450.png
Views:	172
Size:	12.6 KB
ID:	329764  
Reply With Quote
  #7 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,642

berni147,

you could test increasing the "Space to the right" for the chart to a setting >= history_candles in case this setting is currently smaller.
Another approach could be to start the trendline with a span of one bar and update the end point i.e. extend the line by one bar for history_candles number of bars with every new bar.

Regards,

ABCTG


berni147 View Post
I have one more question if I may, I have tried this approach live and it drawing seem to be a bit weird.
The code is very simple; Im creating two BNPoints and displaying them:


 
Code
	
                myBNPoint1 = BNPoint.Create(barnumber+Maxbarsback,value);
		myBNPoint2 = BNPoint.Create(barnumber+Maxbarsback+history_candles-1,value);
		
		MyTL = TrendLine.Create( myBNPoint1, myBNPoint2 ) ;
When running on historical data, lines are perfect. Once this goes live, lines are for some reason shorter. Basically on history data there is line above each N bars whereas running live the line is only on top of first few bars, e.g. when history_candles is set to 10, I would have line on top of each 10 bars in history but when running live, line would be drawn only on first 5 bars, then 5 bars without line, and again new line but again only on first few bars.. When I would re-run indicator, lines would be correct (again until I go live).

My first though was that barnumber is different or maxbarsback is different when running live, but funny thing is that Im always printing out both BNPoints and the numbers are still the same regardless running live or not - it is always BNPoint1 -> X and BNPoint2 -> X + history_candles. So, although BNPoints are still calculated correctly, lines are not drawn correctly.

Is there anything else Im missing?

Thanks!


Follow me on X Reply With Quote




Last Updated on February 14, 2023


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts