Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Background Coloring Indicator Not Working

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • redart1021
    replied
    Thanks Paul. This worked great

    Leave a comment:


  • NinjaTrader_PaulH
    replied
    Hello redart1021,

    Thanks for your post and welcome to the NinjaTrader forums!

    When an indicator is not working as expected, please check the "log" tab of the NinjaTrader control center.

    Based on the code you have shared I suspect that you would see an error messages about bar indexing.

    What happens when you load a script is that it will start processing the very first bar in the data series that is applied to the chart. If on the first bar of data processed the script tries to access a prior bar (I see [1] and [2] in your code) then it will fail because those bars are not available at that time.

    The reason it is inconsistent ( works on some charts but fails to load on others) is related to the conditions you have. If part of the condition is not true the rest is not evaluated so in that case you can get lucky and see the indicator. I would expect that the indicator could fail on any given chart on any given day when it is loaded.

    What you need to do is to prevent your code from processing until, from what I see, at least 2 bars have been loaded. In OnBarUpdate() before your code accesses any previous bars, add this line of code:

    if (CurrentBar < 2) return; // do not process below this line until at least 2 bars

    You could also use 20 bars as a number because no indicator will print before 20 bars have been loaded.

    Reference: https://ninjatrader.com/support/help...currentbar.htm

    Leave a comment:


  • redart1021
    started a topic Background Coloring Indicator Not Working

    Background Coloring Indicator Not Working

    Hi would anyone know why this indicator works on some charts but fails to load on others?
    Thanks

    Code:
    protected override void OnBarUpdate()
    {
    BackBrush = Brushes.PaleGreen;
    BackBrush = null;
    
    if (EMA(30)[0] >= Close[0] && EMA(30)[0] >= Close[1] && EMA(30)[0] >= Close[2])
    {
    BackBrush = Brushes.LightPink;
    }
    else if (EMA(30)[0] <= Close[0] && EMA(30)[0] <= Close[1] && EMA(30)[0] <= Close[2])
    {
    BackBrush = Brushes.DarkSeaGreen;
    }
    else
    {
    BackBrush = Brushes.PapayaWhip;
    }
    }

Latest Posts

Collapse

Topics Statistics Last Post
Started by bortz, 11-06-2023, 08:04 AM
47 responses
1,610 views
0 likes
Last Post aligator  
Started by jaybedreamin, Today, 05:56 PM
0 responses
9 views
0 likes
Last Post jaybedreamin  
Started by DJ888, 04-16-2024, 06:09 PM
6 responses
19 views
0 likes
Last Post DJ888
by DJ888
 
Started by Jon17, Today, 04:33 PM
0 responses
6 views
0 likes
Last Post Jon17
by Jon17
 
Started by Javierw.ok, Today, 04:12 PM
0 responses
21 views
0 likes
Last Post Javierw.ok  
Working...
X