Thank you
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
transfer indicator drawn lines/values from one chart to another of same symbol
Collapse
X
-
transfer indicator drawn lines/values from one chart to another of same symbol
Hi, I made an indicator that draws lines on a 1 Tick chart, however this indicator isn't working well when dragged onto any other time frame (i.e. the results are different). Is there a way to store those values so i can draw them onto another chart with a higher timeframe for better overview? Or perhaps just create alerts on the 1 tick chart which then are also created on any other charts with the same symbol? As in any way i can visualise the values of that indicator on a higher timeframe. Any ideas? From searching the forum i couldn't really find anything except for this findmechangemechangesharpdxcolor indicator but not sure about it (or rather i don't understand it
Thank you
Tags: None
-
Hello kalli44100,
Welcome to the forum!
To clarify, you want the lines to stay the same as if they were calculating on the 1-tick series when you apply the indicator to a chart with a higher time frame?
You can add a 1-tick series to your indicator and have the indicator do the calculations for drawing the lines based on the 1-tick series. Then, when you apply the indicator to a higher time frame it will still calculate the lines on the 1-tick series on top of the primary series bars.
Please let us know if you have any further questions.
-
Hi Gaby,
Thank you for your swift response! Yes that's the plan, draw on tick chart, see it on minute chart etc.
So you're suggesting that i add
AddDataSeries(BarsPeriodType.Tick, 1);
To my indicator script and then do my calculations with Close[1][0] instead of Close[0]? That way once I'd load it onto a chart with whatever timeframe it would still calculate on the same as the 1 tick chart? Is that correct?
That would also mean calculating the same values twice, i take it there is no better way to just calc it once and then copy it to the other charts? Probably more complex that way i take it
Thx
Comment
-
Hello kalli44100,
Yes you have understood correctly, a secondary series can be used to execute logic always on a specific series no matter what primary bars are selected.
There is not a way to transfer calculations to other charts, if you apply a script to a chart it will only apply to that single chart.
Comment
-
Hi Jesse and or Gaby,
I put my onbarupdate code inside the if(barsinprogress==1){} and it works, the lines are now drawn at the correct values on charts with a higher timeframe than 1 Tick but using 1 Tick as dataseries. Issue now is that the lines are drawn backwards. so in my code i save the Currentbar and price when the event occurs and then cycle through my list to adjust the lines to update drawing from that original currentbar and price to now.. on the higher timeframe, the lines are now drawn backwards.
I presume it's because the lines are being redrawn on the bars of the higher timeframe?
The code is basically "check bars 0-5 then check bars 6-10. if bar 6==x, then save to list i.e. curreentBar=currentbar-6 and price=Close[6]. something like that. so instead of drawing the line adding a tick to length every time a new tick comes, it adds a bar of the current timeframe every time a new tick comes
Any suggestions?
Thank you
Karl
Comment
-
Hello Karl,
Since you have an added data series, make sure you are using the CurrentBars value for the correct Bars object you want to save the value for.
CurrentBars[0] is the primary series, and CurrentBars[1] is your added series (the 1-tick series).
In order to better understand how the code is working, such not placing or note placing drawing objects where expected, it will be necessary to use Print to see how the conditions are evaluating.
In the script add prints (outside of any conditions) that print the values of every variable used in every condition along with the time of that bar.
Below is a link to a forum post that demonstrates using prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.
Save the output from the output window to a text file and provide this with your reply.
I'll be happy to assist with analyzing the output.
Comment
-
Thank you Gaby,
I gotta go do school run now but just noticed that my code has CurrentBar and that I cannot add a [] at the end. I changed it to CurrentBars (with an S) and that worked. alas now there is another error and i gotta rush:P I didn't realise there was a difference betweeen Currentbar and bars... Will check the other stuff and get back to you. Thank you
Comment
-
I'm now getting "Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."
this is how i put it at the beginning of onbarupdate, i'm not using series 0, just my added 1 tick series. I thought that this would be the right way to avoid that error:
protected override void OnBarUpdate()
{
if (CurrentBar < 10)return;
if (BarsInProgress == 1){
if (CurrentBars[1] < 1000)return;
I'm adding CurrentBars[1]-10 to my list to save the bars ago from which to draw my lines
then i'm drawing my line at CurrentBars[1] - the saved currentbars[1] in the list.
I put prints everywhere and the error comes when the Draw.Line gets executed. (theBar is the saved bar from the list)
Draw.Line(this, myIdent+"abcd", false, CurrentBars[1]-theBar, thePrice, 0, thePrice, Brushes.Lime, DashStyleHelper.Solid, 1);
Comment
-
Hello,
This message is indicating the specific index requested from a collection does not exist. Indexes must be a non-negative number and less than the size of the collection. The error may be indicating the index requested is larger than the number of elements in the collection.
The help guide discusses ‘Make sure you have enough bars in the data series you are accessing’ .
NinjaScript > Educational Resources > Tips > Make sure you have enough bars in the data series you are accessing
For example,
I recommend printing out CurrentBars[1] and the index of the bars you are trying to access in Draw.Line, this will help you see why you are getting the index error.Code:(CurrentBar < 1) return; Draw.Dot(this, “myDot”, 5, Brushes.Blue); // this line of code will cause an invalid index error as the start barsAgo parameter is 5 when the CurrentBar processed is bar 1
Comment
-
ok will print currentbars[1] in a minute. but is the above mentioned syntax not correct for multiple dataseries?
protected override void OnBarUpdate()
{
if (CurrentBar < 10)return;
if (BarsInProgress == 1){
if (CurrentBars[1] < 1000)return;
Comment
-
Ok I changed that but the error remains.
Does the fact that I am using Draw.Line inside if(BarsInProgress==1){} mean that Draw.Line uses the second dataseries or does it use the chart's inherent bar value i.e. CurrentBars[0]? because now i can see that it prints 3 values for CurrentBars[1]-savedBar and then stops. I think it may be drawing backwards to before the first bar again using the tickseries bar from my calculation but applying it to the currentbars[0]... is the right? does Draw.Line take the integer you give it for bars and draw on the native dataseries (i.e. currentbars[0])?
Comment
-
If your Draw.Line call is within BIP1 this means that is using the added data series' barsAgo values.
If you have the output from the script, can you share it?
Print the time of the bar, CurrentBars[0], CurrentBars[1], as well as the startBarsAgo and endBarsAgo values you are using in your Draw.Line call.
Comment
-
I printed all these jjust before the Draw.Line. "theBar" is the saved bar index from the list. CurrentBars[1]-theBar is used to draw the line from. this is all i get then the script stops and that is also presumably when the error kicks in
U -- theBar = 1222
U -- CurrentBars[0] = 11
U -- CurrentBars[1] = 1232
U -- CurrentBars[1]-theBar = 10
U -- theBar = 1222
U -- CurrentBars[0] = 11
U -- CurrentBars[1] = 1233
U -- CurrentBars[1]-theBar = 11
U -- theBar = 1222
U -- CurrentBars[0] = 11
U -- CurrentBars[1] = 1234
U -- CurrentBars[1]-theBar = 12
Comment
-
It really looks like Draw..line is trying to draw 12 bars back where there isn't a bar yet because we only started drawing 10 bars in. But you said Draw.Line within BiP should use dataseries 1. Is there a setting within Draw.Line I need to change to make sure it uses series 1 instead of 0? or something like htat?
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
579 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
334 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
554 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
551 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment