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:	120
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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    93 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    138 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    123 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    73 views
    0 likes
    Last Post PaulMohn  
    Working...
    X