
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Need little help
Collapse
X
-
Hello,
thank you for the question.
This first message is letting you know that in your call to DrawText, the amount of bars ago you are requesting is not yet loaded on the chart.Error on calling 'OnBarUpdate' method for indicator 'M5b' on bar 0: Mother50back.DrawText: startBarsAgo out of valid range 0 through 0, was 1.
For example you call this DrawText on bar 0, and it is trying to start 5 bars ago. 5 bars have not yet been loaded so this would be looking for an index location of -5 which will never exist and causes the error.
You will need to check for bars before executing this code, for example:
Because in this example I am requesting the drawtext 10 bars ago, I prevent the script from processing until I have 10 bars.Code:[B]if(CurrentBar < 10) return;[/B] DrawText("MyText", "Sample text", [B]10[/B], High[0], Color.Blue);
For your next question:
This indicates that something is not set when you are checking it, this more than likely would be related to the line of code that contains "AnotherChart". If you would like to post the section of code or whole code I could take a look and see if I can see the error on this.Failed to get property 'AnotherChart' for indicator '': Object reference not set to an instance of an object.
Otherwise you need to ensure the object you are checking has a value before you are checking it.
Please let me know if I may be of additional assistance.
-
Hello,
Thank you for the script.
I copied what you have and placed this in the OnBarUpdate of a blank indicator and did get the error you were.
This is related to what I had previously posted about.
In your code you are referencing prior bars in your conditions, these prior bars will not exist when you start the script up initially. You need to check for this otherwise you get the error you are listing.
All I have done is added the following to the top of OnBarUpdate after the brace you have in your example. I have included the // Condition set 1 so you can see exactly where in the script I am speaking of.
This tells the script, if the CurrentBar is less than the BarsRequired (defaults to 20) then do not do anything.Code:{ if (CurrentBar < BarsRequired) return; // Condition set 1
This will prevent the error because now on bar 20, bar 19 will exist, you are looking back 1 bar in your conditions so at least 1 bar needs to be loaded before doing your check.
Please let me know if I may be of additional assistance.
Comment
-
Yes, It works . Thank you very much. There is one more question
I would like write my self code for %. I mean if current candle close 50% below previous candle. Where can I study or find how to write this code ? I mean is there any written lines already or I have to ask programmers for complete this request ? anything 
Thank you very much
jake
Comment
-
Very quickly because I'm in a rrrrrrrush but is this what you're looking for?Originally posted by Jakub View PostYes, It works . Thank you very much. There is one more question
I would like write my self code for %. I mean if current candle close 50% below previous candle. Where can I study or find how to write this code ? I mean is there any written lines already or I have to ask programmers for complete this request ? anything 
Thank you very much
jake
This should give you a positive or negative %, with the previous Low[1] = 0% and the previous High[1] = 100%.Code:double p = (Close[0] - Low[1]) / (High[1] - Low[1]) * 100;
(Substitute Close and Open or High and Low if this is what you want.)
Hope this helps.Last edited by arbuthnot; 02-01-2015, 12:08 PM.
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