Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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
Can you help answer these questions from other members on 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.
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
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.
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:
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.
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.