Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Detecting Previous Red Bars - Not Working

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

    Detecting Previous Red Bars - Not Working

    I appreciate any help on this matter. I wanted to add text to the top of the candles if the previous bar is red. Currently this is the only thing the strategy does. But it randomly skips bars and I don't know why. The code is very simple. This is in BackTesting by the way.

    Questions:
    1) Why is it randomly skipping bars?
    2) Why does it always skip the first few bars of the day?


    Code:
            protected override void OnBarUpdate()
            {
                if (CurrentBar < BarsRequiredToTrade)
                    return;
            
                if (Close[1] < Open[1])  // RED BAR
                        Draw.Text(this, "R"+Bars.GetAsk(CurrentBar), "R", 0, High[0]+.01);​
    Click image for larger version

Name:	2025-02-06 18_00_04-Strategy Analyzer - Analyzer.png
Views:	114
Size:	56.4 KB
ID:	1333865

    #2
    Hello jerrod.davenport,

    Use unique tag names to create new drawing objects instead of moving existing drawing objects.

    With your code a drawing object at the same ask price will have a duplicate tag and will modify to move the existing object instead of generating a new object.


    Add CurrentBar to the tag name so this is unique for each new bar.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    43 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    21 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    30 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    50 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    40 views
    0 likes
    Last Post CarlTrading  
    Working...
    X