• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Statement executed on false condition

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

    Statement executed on false condition

    Hello

    My indicator draws an arrow when the condition for drawing is false and I can't figure it out why, as it produces the following prints:

    Swing Low = False | CB = 2617
    Swing Low = False | CB = 2618
    Swing Low = False | CB = 2619

    More confusing, if I put the Print in the statement body after the Draw.Arrow, it doesn't get executed, so again, how does the arrow get drawn?


    Code:
    private void PriceSwingLow()
            {                        
                Print("Swing Low  = " + ((Math.Round(Lows[0][0] - MIN(Lows[0], MinSpan)[1], 2) >= TickSize && Math.Round(MIN(Lows[0], MinSpan - 1)[2] - MIN(Lows[0], MinSpan)[1], 2) >= TickSize
                    && CurrentBar - (CurrentBar - LowestBar(Lows[0], MinSpan + 1)) == 1)
                    || (CurrentBar - flatLowPriceBar == 1 && Math.Round(Lows[0][0] - FlatLowPrice[w-1], 2) >= TickSize && Math.Round(Lows[0].GetValueAt(flatLowPriceBar - 1) - FlatLowPrice[w-1], 2) >= TickSize)) + "    |    CB = " + CurrentBar + "\r\n-");
    
                if ((Math.Round(Lows[0][0] - MIN(Lows[0], MinSpan)[1], 2) >= TickSize && Math.Round(MIN(Lows[0], MinSpan - 1)[2] - MIN(Lows[0], MinSpan)[1], 2) >= TickSize
                    && CurrentBar - (CurrentBar - LowestBar(Lows[0], MinSpan + 1)) == 1)
                    || (CurrentBar - flatLowPriceBar == 1 && Math.Round(Lows[0][0] - FlatLowPrice[w-1], 2) >= TickSize && Math.Round(Lows[0].GetValueAt(flatLowPriceBar - 1) - FlatLowPrice[w-1], 2) >= TickSize))
                {
                    Lprice.Add(MIN(Lows[0], MinSpan)[1]);    // u
                    LpriceBar.Add(CurrentBar - LowestBar(Lows[0], MinSpan + 1));    // u
                    if (DrawArrows)                
                        Draw.ArrowUp(this, "Swing Up" + "  |    L P = " + LpriceBar[u], true, CurrentBar - LpriceBar[u], Lprice[u] - 3 * TickSize, Brushes.White, true);
                    u++;                
                }
            }
    Also, one line (that I noticed) is drawn with identical Start and End - basically just a dot invisible on the chart, but recorded in the drawing objects window, as per the second attachment.
    The code below produces the following prints:

    Hprice.Count = 10 | HpriceBar[t-1] = 2619 | HpriceBar[t-2] = 2592 | Bar = 2620
    Hprice.Count = 11 | HpriceBar[t-1] = 2625 | HpriceBar[t-2] = 2619 | Bar = 2626

    As you can see, the script sees different values for HpriceBar[t-1] and HpriceBar[t-2] on Bar 2626, but when it draws the line, it takes equal values


    Code:
    private void NegativeDivergence()        
    {
        if (Hprice.Count != listCountH)
       {
           if (b > 0 && HpriceBar[t-1] - HSwDMIbar[b-1] <= BarDiff /*&& HpriceBar[t-1] - HSwDMIbar[b-1] >= 0*/)
                        HSwDMIbarHP.Add(HSwDMIbar[b-1]);    // f
                    else
                        HSwDMIbarHP.Add(HpriceBar[t-1]);                
    
                    if (t > 1 && f > 0)        
                    {                    
                        //    Lower DMI Swing High and Higher Price
                        ND1 = Math.Round(Hprice[t-1] - Hprice[t-2], 2) >= 0 && Math.Round(DMI1.Values[0].GetValueAt(HSwDMIbarHP[f-1]) - DMI1.Values[0].GetValueAt(HSwDMIbarHP[f]), 2) > 0;    
    
                        Print ("Hprice.Count = " + Hprice.Count + "    |    HpriceBar[t-1] = " + HpriceBar[t-1] + "    |    HpriceBar[t-2] = " + HpriceBar[t-2]  + "    |    Bar = " + CurrentBar + "\r\n-");
    
                        if (!negDiv && ND1)
                        {
                            //PrintNegDiv();                            
                            negDiv = true;  // NEG DIV = Reversal Down
                            if (ND1)    
                            {
    
                                if (DrawPriceLine)        // ###***    Line Start = Line End on 14.02.2020 / 10:50am  ***###
                                    Draw.Line(this, "Neg Div " + " / P S " + HpriceBar[t-2] + " / P E " + HpriceBar[t-1],                                
                                    true, CurrentBar - HpriceBar[t-2], Hprice[t-2], CurrentBar - HpriceBar[t-1], Hprice[t-1], negDivColour, divDashStyle, 1, true);
    
    
                                if (DrawPriceLine)
                                    Draw.Line(this, "DMI Neg Div " + " / Dmi S " + HSwDMIbarHP[f-1] + " / Dmi E " + HSwDMIbarHP[f],
                                    true, CurrentBar - HSwDMIbarHP[f-1], DMI1.Values[0].GetValueAt(HSwDMIbarHP[f-1]), CurrentBar - HSwDMIbarHP[f], DMI1.Values[0].GetValueAt(HSwDMIbarHP[f]), negDivColour, divDashStyle, 1, false);
    Attached Files
    Last edited by itrader46; 02-18-2020, 06:36 AM.

    #2
    Hello itrader46,

    Thanks for your post.

    Please note that as a small team we can not provide debugging services for code you have created.

    Regarding, "More confusing, if I put the Print in the statement body after the Draw.Arrow, it doesn't get executed, so again, how does the arrow get drawn?" I would put a print statement just before and after the actual draw statement. If neither are being hit then something else is drawing the arrow.

    I would suggest trying to reduce/isolate your code to further refine what is happening.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul

      That answer is so typical and predictable!

      I am not asking you to debug my code, I just need assistance with the fact that a statement executes when the condition for it is False, as well as the fact that, despite seeing two different values for the start and end of a bar, the bar it is drawn with the same start and end.

      Unless, of course, you guys are OK with that, in which case you might as well do something else than claim you provide script support...

      Comment


        #4
        Hello itrader46,

        Thanks for your reply.

        Please provide a standalone reduced/simplified script that demonstrates the issues you are reporting.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by itrader46 View Post
          Hi Paul

          That answer is so typical and predictable!

          I am not asking you to debug my code, I just need assistance with the fact that a statement executes when the condition for it is False, as well as the fact that, despite seeing two different values for the start and end of a bar, the bar it is drawn with the same start and end.

          Unless, of course, you guys are OK with that, in which case you might as well do something else than claim you provide script support...
          Not sure why you being so rude. Ninja support is fantastic, unparalleled to many. You most likely have a bug in your code. I suggest you install Visual Studio and check all in debugging. Very simple, and Ninja has step by step guide on it. From my experience using ninja for over 10 years and writing code since Ninja 5, I have never seen False condition executing.

          Comment


            #6
            Hi Paul

            I attached the script with only the two methods that are drawing the arrows on False condition

            Comment


              #7
              Hello itrader46,

              Thanks for your reply.

              As you have mentioned from your comment in your initial post, that the print next to the draw method is not seen when the print for the condition is false, this proves that the draw method is not being reached when the condition is false. The draw method must then be called when the condition is true at another time with parameters to draw it at X location.". We suggest adding a print statement when you draw the arrow to show the current bar number along with the parameters used in the Draw.ArrowUp() as this will help you see why your logic is placing the draw object at "X" location where it may not be expected. Generally I have found that printing all variables on a per bar basis is the best way to step through code that is not executing as expected, however given all of the variables even in your reduced sample this may an overwhelming amount of data.

              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Hi Paul

                The advice of printing the Current bar with the arrows helped me finding the error.

                Thank you

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by MavMoney, Today, 07:17 AM
                1 response
                5 views
                0 likes
                Last Post MavMoney  
                Started by jameslee001, Today, 08:09 AM
                0 responses
                5 views
                0 likes
                Last Post jameslee001  
                Started by bertochi, Today, 07:25 AM
                1 response
                2 views
                0 likes
                Last Post bertochi  
                Started by Kentoes, Today, 07:06 AM
                0 responses
                4 views
                0 likes
                Last Post Kentoes
                by Kentoes
                 
                Started by third monkey, Today, 06:33 AM
                0 responses
                1 view
                0 likes
                Last Post third monkey  
                Working...
                X