Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Wrong referenced bar

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

    Wrong referenced bar

    Hello.
    I have the code below which produces the following prints:

    DMI Swing High
    16/12/2019 07:45:00 | Current Bar = 932 | HSwDMI[0] = 0.6842 | HSwDMIbar = 930 | HSwDMIprice[0] = 59.92
    -
    Last High Swing DMI Found
    16/12/2019 07:55:00 | Current Bar = 934 | LastHSwDMI[0] = 0.0000 | lastHSwDMIbar = 930| lastHSwDMIpriceBar = 930 | HSwDMIprice[0] = 59.05

    The problem is that, even though in the first print line the values are correct, in the second print, lastHSwDMIbar = 930 and lastHSwDMIpriceBar = 930 are found correctly, but the values LastHSwDMI[0] = 0.0000 and HSwDMIprice[0] = 59.05 are wrong, as the should be as in the first line, 0.6842 and 59.92

    Thank you

    Code:
    // Finding DMI swing High
                        if ((/*FlatIndBar && */DMI1[2] - DMI1[1] > 0.001 && DMI1[2] - DMI1[3] > 0.001)
                            || (FlatIndBar && FlatDMI[0] - DMI1[1] > 0.001 && FlatDMI[0] - DMI(Closes[2], Convert.ToInt32(DmiPeriod)).Values[0].GetValueAt(flatDMIbar - 1) > 0.001))
                        {
                            HSwDMI[0] = DMI1[2];
                            HSwDMIbar = CurrentBar - 2;
                            HSwDMIprice[0] = Highs[2].GetValueAt(HSwDMIbar);                        
                            if (PrintDmiSwing)
                                Print("DMI Swing High \r\n" + Time[0] + " | Current Bar = " + CurrentBar + string.Format(" | HSwDMI[0] = {0:F4}", HSwDMI[0]) + 
                                    " | HSwDMIbar = " + HSwDMIbar + " | HSwDMIprice[0] = " + HSwDMIprice[0] + "\r\n-");
                        }            
    ..................
    if (!LastHSwDMIfound)
                        {        
                            LastHSwDMI[0] = MAX(HSwDMI, 5)[1];
                            LastHSwDMIfound = true;                        
                        }
                        if (LastHSwDMIfound)
                        {
                            lastHSwDMIbar = CurrentBar - HighestBar(DMI(Closes[2], Convert.ToInt32(DmiPeriod)), 5);
                            lastHSwDMIpriceBar = CurrentBar - HighestBar(Lows[2], 5);
                            HSwDMIprice[0] = Highs[2][lastHSwDMIpriceBar];
                            if (PrintDmiSwing)
                                Print("Last High Swing DMI Found\r\n" + Time[0] + " | Current Bar = " + CurrentBar + string.Format(@" | LastHSwDMI[0] = {0:F4}", LastHSwDMI[0]) + 
                                    " | lastHSwDMIbar = " + lastHSwDMIbar + "| lastHSwDMIpriceBar = " + lastHSwDMIpriceBar + " | HSwDMIprice[0] = " + HSwDMIprice[0] + "\r\n-");

    #2
    Hello itrader46,

    From this amount of information I couldn't really say what may be causing that. It looks like you are using multiple series here so that may relate.

    In this situation you would very likely need to add more specific debugging or reduce your code to find what the difference is between those two blocks of logic. The CurrentBar changed between your prints so potentially this is a secondary series calling the logic, I cannot tell from this sample.

    I don't see where you are setting LastHSwDMI inside the condition where it resides, only in the condition before it. Are both conditions coming true on the same bar? the [0] BarsAgo would not relate to the value set in the first condition if the bar had changed between the two conditions being true.

    You may try printing the BarsInProgress here to see if that relates to the problem.

    Alternatively I would suggest reducing what you are doing here to try and find where the problem starts. You could try removing the conditions and printing for every bar to see if a constant value is being seen across all bars as one test.

    I look forward to being of further assistance.

    Comment

    Latest Posts

    Collapse

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