Announcement

Collapse
No announcement yet.

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 timko, Yesterday, 11:39 PM
1 response
6 views
0 likes
Last Post NinjaTrader_Marco  
Started by levikNT, Yesterday, 11:38 PM
0 responses
5 views
0 likes
Last Post levikNT
by levikNT
 
Started by Al Recites, Yesterday, 09:19 PM
1 response
8 views
0 likes
Last Post NinjaTrader_Marco  
Started by Crassius, Yesterday, 10:19 PM
0 responses
12 views
0 likes
Last Post Crassius  
Started by MisterGee, Yesterday, 10:09 PM
0 responses
8 views
0 likes
Last Post MisterGee  
Working...
X