Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Help with chart trader and button

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

    #31
    Hi i have the following code and need to make sure correct fib gets drawn. It shows correct fib for long but it doesnt show for fib short. Only drawing fiblong. What am i doing wrong?

    fibLong
    remove fib
    fibLong
    remove fib


    Code:
    protected void Button13Click(object sender, RoutedEventArgs e) // Fib show
            {
                fibpressed = !fibpressed;
                if (fibpressed){
                    if(llPriceLevel < hhPriceLevel)
                        {
                            Print("fibLong");
                            TriggerCustomEvent(o =>
                            {
                             Draw.FibonacciRetracements(this, "fibLong", true, CurrentBar-llDrawnbar, llPriceLevel , CurrentBar-hhDrawnbar, hhPriceLevel);
                           }, null);
                        }
    
    
    //                    else
    //                    {
    //                    Print("remove fib");
    //                    RemoveDrawObject("fibLong");
    
    //                    }
                }
    
                if (fibpressed){
                    if(llPriceLevel > hhPriceLevel)
                        {
                            Print("fibShort");
                            TriggerCustomEvent(o =>
                            {
                             Draw.FibonacciRetracements(this, "fibShort", true, CurrentBar-hhDrawnbar, hhPriceLevel , CurrentBar-llDrawnbar, llPriceLevel);
                           }, null);
                        }
    
    
    
                }
                else
                        {
                        Print("remove fib");
                        RemoveDrawObject("fibShort");
                            RemoveDrawObject("fibLong");
    
                        }
    
            }​​
    Last edited by tkaboris; 11-09-2023, 07:35 AM.

    Comment


      #32
      Hello tkaboris,

      We will need output from printing the values in the conditions to understand if this is evaluating as true or false.

      One line above the conditions print the values in the conditions with labels for each value and comparison operator.


      Save the output to a text file and include this with your next post.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #33

        fibLofibpressedTrue
        llPriceLevel15402
        hhPriceLevel15409.5
        fibLong
        fibpressed
        fibLofibpressedFalse
        llPriceLevel15402
        hhPriceLevel15409.5
        remove fib
        fibLofibpressedTrue
        llPriceLevel15402
        hhPriceLevel15409.5
        fibLong
        fibpressed
        fibLofibpressedFalse
        llPriceLevel15402
        hhPriceLevel15409.5
        remove fib
        fibLofibpressedTrue
        llPriceLevel15402
        hhPriceLevel15409.5
        fibLong
        fibpressed

        my code for fib short is here
        else if (fibpressed && hhPriceLevel > llPriceLevel){

        TriggerCustomEvent(o =>
        {
        Draw.FibonacciRetracements(this, "fibShort", true, CurrentBar-hhDrawnbar, hhPriceLevel , CurrentBar-llDrawnbar, llPriceLevel);
        }, null);

        }

        and before conditions
        fibpressed = !fibpressed;
        Print("fibLofibpressed" + fibpressed);
        Print("llPriceLevel" + llPriceLevel);
        Print("hhPriceLevel" + hhPriceLevel);​​

        Click image for larger version

Name:	image.png
Views:	72
Size:	209.3 KB
ID:	1277198

        Comment


          #34
          Hello tkaboris,

          The output appears to be showing IIPriceLevel with a value of 15402 is not greater than hhPriceLevel at 15409.5, so the condition is not evaluated as true and no action is triggered.


          Note with the print, this should be informative to match the condition and include operators (so we can look at the output and see how the values are being compared).

          For the conditions:
          if (fibpressed){
          if(llPriceLevel &gt; hhPriceLevel)​

          The print should appear as:

          Print(string.Format("fibpressed: {0} == true && llPriceLevel: {1} > hhPriceLevel: {2}", fibpressed, llPriceLevel, hhPriceLevel));


          To save output to a text file, right-click the the NinjaScript Output window then select Save As. Then you attach the text file with your post.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #35
            hi

            Its still not showing right retracement for shorts. Yellow line and blue line is 50 and 61%, so it should be on upper side of retracement

            Code:
            protected void Button13Click(object sender, RoutedEventArgs e) // Fib show
                    {
                        fibpressed = !fibpressed;
                        Print(string.Format("fibpressed: {0} == true && llPriceLevel: {1} > hhPriceLevel: {2}", fibpressed, llPriceLevel, hhPriceLevel));
                        if (fibpressed && llPriceLevel < hhPriceLevel){
            //                if(llPriceLevel < hhPriceLevel)
            //                    {
                                    Print("fibLong");
                            Print("fibpressed");
            //                        Print("llPriceLevel" + llPriceLevel);
            //                        Print("hhPriceLevel" + hhPriceLevel);
                                    TriggerCustomEvent(o =>
                                    {
                                     Draw.FibonacciRetracements(this, "fibLong", true, CurrentBar-llDrawnbar, llPriceLevel , CurrentBar-hhDrawnbar, hhPriceLevel);
                                   }, null);
            //                    }
            
            
            //                    else
            //                    {
            //                    Print("remove fib");
            //                    RemoveDrawObject("fibLong");
            
            //                    }
                        }
            
                        else if (fibpressed && hhPriceLevel > llPriceLevel){
            //                if(llPriceLevel > hhPriceLevel)
            //                    {
                                    Print("fibShort");
                                    Print("fibpressed" + fibpressed);
            //                        Print("llPriceLevel" + llPriceLevel);
            //                        Print("hhPriceLevel" + hhPriceLevel);
                                    TriggerCustomEvent(o =>
                                    {
                                     Draw.FibonacciRetracements(this, "fibShort", true, CurrentBar-hhDrawnbar, hhPriceLevel , CurrentBar-llDrawnbar, llPriceLevel);
                                   }, null);
            //                    }
            
            
            
                        }
                        else
                                {
                                Print("remove fib");
                                RemoveDrawObject("fibShort");
                                    RemoveDrawObject("fibLong");
            
                                }
            
                    }
            
                    #endregion
                    ​
            Click image for larger version  Name:	image.png Views:	0 Size:	308.2 KB ID:	1277254
            Last edited by tkaboris; 11-09-2023, 02:30 PM.

            Comment


              #36
              Hello tkaboris,

              llPriceLevel with a value of 15189.5 is less than hhPriceLevel at 15202.75.

              if (fibpressed && llPriceLevel < hhPriceLevel){
              This 'if' evaluated as true, so the 'else if' below will not be evaluated.

              else if (fibpressed && hhPriceLevel > llPriceLevel){
              This 'else if' was not evaluated as the 'if' above evaluated as true.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #37
                I don’t understand then. First condition always evaluates to true and skips second condition for short… what other condition do I need to specify?

                Comment


                  #38
                  Hello tkaboris,

                  You might not be familiar with how an 'else-if' works in C# (or pretty much all programming languages).

                  Below is a link to an educational site.
                  The `if` and `switch` statements provide branching logic in C#. You use `if, `else` and `switch` to choose the path your program follows.


                  If the 'if' part evaluates as true, the 'else' or 'else-if' are not evaluated.

                  Are you expecting the 'if' above to evaluate as false even though llPriceLevel is less than hhPriceLevel?

                  Are you expecting both conditions to be evaluated?
                  If so, why are you using an 'else-if' here?
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #39
                    i removed else if and only have if but now it draws both of fibs for long and short
                    I want to evaluate only one condition to true, if its long retracement or short retracement.

                    fibpressed: True == true && llPriceLevel: 15244.25 > hhPriceLevel: 15268
                    fibLong
                    fibpressed
                    fibShort
                    fibpressedTrue
                    fibpressed: False == true && llPriceLevel: 15244.25 > hhPriceLevel: 15268
                    remove fib

                    Comment


                      #40
                      Never mind fixed it.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Taddypole, 04-26-2024, 02:47 PM
                      1 response
                      12 views
                      0 likes
                      Last Post NinjaTrader_Eduardo  
                      Started by futtrader, 04-21-2024, 01:50 AM
                      6 responses
                      58 views
                      0 likes
                      Last Post futtrader  
                      Started by sgordet, Today, 11:48 AM
                      0 responses
                      4 views
                      0 likes
                      Last Post sgordet
                      by sgordet
                       
                      Started by Trader146, Today, 11:41 AM
                      0 responses
                      5 views
                      0 likes
                      Last Post Trader146  
                      Started by jpapa, 04-23-2024, 07:22 AM
                      2 responses
                      22 views
                      0 likes
                      Last Post rene69851  
                      Working...
                      X