int barsAgoLONG = MRO(() => ShortPercent >= 0.90 , 1, 20);
if (barsAgoLONG > -1)
{
Print(" " + Time[barsAgoLONG] + " " + barsAgoLONG);
Draw.Dot(this, @"InitateCustomCode " + CurrentBars[0].ToString(), true, 0, GetCurrentAsk(0), Brushes.Pink);
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
MRO barsago value printing 0
Collapse
X
-
MRO barsago value printing 0
Simple condition and I want to print the time and bars ago from current. However, I'm not sure what I am missing here as the time prints correctly at the bar when the condition meets but the barsAgoLong always prints 0. Probably an array error but any ideas?
Code:Tags: None
-
Hello Boonfly8,
Thank you for your note.
Could it be that (ShortPercent >= 0.90) is always true? Thus the most recent occurrence is always going to be bar index zero, or the current bar?
If you add,
And check the output window, is ShortPercent Always >=.9?Code:Print("ShortPercent_"+ShortPercent.ToString()); int barsAgoLONG = MRO(() => ShortPercent >= 0.90 , 1, 20);
I look forward to your reply.Alan P.NinjaTrader Customer Service
-
Hi Alan P,
it is definitely not always true as the output does print out the time when it happens, and it doesn't happen all the time. However, the barsago value is 0. Here's an example of the output
7/20/2018 7:51:00 AM 0
7/20/2018 7:52:00 AM 0
7/20/2018 7:53:00 AM 0
7/20/2018 7:55:00 AM 0
7/20/2018 7:56:00 AM 0
7/20/2018 9:20:00 AM 0
7/20/2018 9:52:00 AM 0
7/20/2018 9:53:00 AM 0
7/20/2018 9:55:00 AM 0
7/20/2018 10:08:00 AM 0
7/20/2018 10:49:00 AM 0
7/20/2018 10:54:00 AM 0
7/20/2018 10:56:00 AM 0
7/20/2018 10:57:00 AM 0
7/20/2018 10:59:00 AM 0
7/20/2018 11:01:00 AM 0
7/20/2018 11:07:00 AM 0
7/20/2018 11:08:00 AM 0
7/20/2018 11:12:00 AM 0
7/20/2018 11:13:00 AM 0
7/20/2018 11:14:00 AM 0
Comment
-
Hello,
Without the script I would be unable to know. I suggest the following links on debugging.
I’ve provided a link to a youtube video which covers an example of using prints to understand behavior:
I’ve provided a link covering debugging which you may find helpful.
Debugging: http://ninjatrader.com/support/forum...ead.php?t=3418
If you try the above and still unable to figure out the issue, please leave the print statements in the script and you can upload a copy and I'll take a look and see if anything jumps out.
To export a NinjaScript from NinjaTrader 8 do the following:
From the Control Center window select Tools -> Export -> NinjaScript...
Click Add>Select the indicator>OK>Export.
Then attach that file you saved; under My Docs>NT8>Bin>Custom>Select the downloaded .zip file.
Please let us know if you need further assistance.Alan P.NinjaTrader Customer Service
Comment
-
Hey Alan, the code is simple so I'll leave it here. I tried to see the outputs but there's something that's going on that I'm not seeing. Instead of using ShortPercent, I made the condition simpler, but still the same result...seeing 0.
Code:else if (State == State.DataLoaded) { BollInitiate = Bollinger(Close, 2, 20); BollInitiate.Plots[0].Brush = Brushes.DeepSkyBlue; BollInitiate.Plots[1].Brush = Brushes.Goldenrod; BollInitiate.Plots[2].Brush = Brushes.DeepSkyBlue; AddChartIndicator(BollInitiate); }Code:protected override void OnBarUpdate() { Print("ShortPercent_"+ShortPercent.ToString()); //Alan's Print Statement int barsAgoLONG = MRO(() => GetCurrentBid() <= BollInitiate.Lower[0] , 1, 5); if (barsAgoLONG > -1) { Print(" " + Time[barsAgoLONG] + " " + barsAgoLONG); Draw.Dot(this, @"InitateCustomCode " + CurrentBars[0].ToString(), true, 0, GetCurrentAsk(0), Brushes.Pink); } }
Comment
-
Hello Boonfly8,
When I apply the code I am unable to replicate and it works as expected. See screen shot.
If you test the attached script do you see the correct prints?
If not, who is your data provider? What instrument and time frame are you applying this to?
I look forward to your reply.Alan P.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
44 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
126 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
65 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
42 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment