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 NullPointStrategies, Today, 05:17 AM
    0 responses
    50 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    126 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    69 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X