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

divergence logic

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

    divergence logic

    hi I want to find a bullish divergence with fisher Transform indicator, where there are two swing lows in the past 20 bars. I first check for this pattern in the last 7 bars, and do another check starting 7bars back. I am not sure if I am doing it right, but for some reason this condition doesnt get evaluated
    if (isFisherPattern2 && isFisherPattern1 && swingLow1 < swingLow2)

    Code:
    for (int i = 0; i < 7; i++)
                {
                    // Fisher Transform pattern condition
                    bool isFisherPattern2 = fisherInd[i] > fisherInd[i + 1] && fisherInd[i + 1] > fisherInd[i + 2]
                                           && fisherInd[i + 2] < fisherInd[i + 3] && fisherInd[i + 3] < fisherInd[i + 4] && fisherInd[i] < 0;
    
                    // Check if the pattern is found
                    if (isFisherPattern2)
                    {
                        swingLow2 = fisherInd[i+2];
                    }
                }
                
                for (int i = 7; i < 25; i++)
                {
                    // Fisher Transform pattern condition
                    bool isFisherPattern1 = fisherInd[i] > fisherInd[i + 1] && fisherInd[i + 1] > fisherInd[i + 2]
                                           && fisherInd[i + 2] < fisherInd[i + 3] && fisherInd[i + 3] < fisherInd[i + 4] && fisherInd[i] < 0;
    
                    // Check if the pattern is found
                    if (isFisherPattern1)
                    {
                        
                        swingLow1 = fisherInd[i+2];
                    }
                }
                
                if (isFisherPattern2 && isFisherPattern1 && swingLow1 < swingLow2)
                {
                    Print("Time"+ Time[0]);
                    Print("Bullish divergence");
                }
                ​

    #2
    Hello tkaboris,

    Thank you for your post.

    In order to better understand how the code is working, it will be necessary to use Print to see how the conditions are evaluating and enable TraceOrders to see if orders are being submitted, ignored, rejected, or cancelled.

    The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very helpful to include labels and operators in the print to understand what is being compared in the condition sets.

    Below I am providing a link to a video that demonstrates adding prints to a script to get further information about the behavior of the script.
    NT8 —
    https://youtu.be/H7aDpWoWUQs?t=2577&...We0Nf&index=14

    Enable TraceOrders, print the time of the bar and all values used in the conditions that submit entry orders. Include labels for all values and comparison operators.

    Let me know if you need any assistance creating a print or enabling TraceOrders.

    Save the output from the output window to a text file and provide this with your reply.

    I'll be happy to assist with analyzing the output.​
    Gaby V.NinjaTrader Customer Service

    Comment


      #3

      hi I wanted to locate that divergence but condition if( isFisherPattern2 && isFisherPattern1) never evaluated to true
      my updated code
      Code:
      for (int i = 0; i < 7; i++)
                  {
                      // Fisher Transform pattern condition
                      bool isFisherPattern2 = fisherInd[i] > fisherInd[i + 1] && fisherInd[i + 1] > fisherInd[i + 2]
                                             && fisherInd[i + 2] < fisherInd[i + 3] && fisherInd[i + 3] < fisherInd[i + 4] && fisherInd[i] < -0;
      
                      // Check if the pattern is found
                      if (isFisherPattern2)
                      {
                          swingLow2 = fisherInd[i+2];
                          Print("swingLow2" + swingLow2);
                          Print("isFisherPattern2" + isFisherPattern2);
                      }
                  }
                  
                  for (int i = 7; i < 25; i++)
                  {
                      // Fisher Transform pattern condition
                      bool isFisherPattern1 = fisherInd[i] > fisherInd[i + 1] && fisherInd[i + 1] > fisherInd[i + 2]
                                             && fisherInd[i + 2] < fisherInd[i + 3] && fisherInd[i + 3] < fisherInd[i + 4] && fisherInd[i] < -0;
      
                      // Check if the pattern is found
                      if (isFisherPattern1)
                      {
                          
                          swingLow1 = fisherInd[i+2];
                          Print("swingLow1" + swingLow1);
                          Print("isFisherPattern1" + isFisherPattern1);
                      }
                  }
                                            
                      if( isFisherPattern2 && isFisherPattern1)
      
                      
                      {                                        
                          Print("Divergence Found" );
                      }​
      Attached Files

      Comment


        #4
        Hello tkaboris,

        From this output, I'm not seeing the values of the bools printed out. Are you adding the print 1 line above the condition to print out the value isFisherPattern2and isFisherPattern1?

        If these aren't evaluating as true, you'll need to add prints to the parts of the code related to calculating if isFisherPattern2and isFisherPattern1 are going to be true or not.

        Please let us know if you have any further questions.
        Gaby V.NinjaTrader Customer Service

        Comment


          #5
          I am adding more prints
          Click image for larger version

Name:	image.png
Views:	31
Size:	23.0 KB
ID:	1304383​​

          Comment


            #6
            I see it evaluates to true in the loop, but outside of the loop it evalutes to false


            Timme4/29/2024 3:08:24 PM
            isFisherPattern2False
            isFisherPattern1False
            isFisherPattern2 && isFisherPattern1False
            swingLow2-1.93175039238242
            isFisherPattern2True
            swingLow1-4.06977232800588
            isFisherPattern1True​

            Comment


              #7
              Hello tkaboris,

              Thank you for your response.

              Can you print the times of the bar with your isFisherPattern2False and isFisherPattern1 prints?

              Where are these prints placed? Outside of which loop is it evaluating as true and false?

              We are interested in the values at the time if( isFisherPattern2 && isFisherPattern1) is being evaluated. The print should be 1 line above the condition so we can see what the values are.

              For example:

              Code:
              Print(Times[0][0] + " isFisherPattern2: " + isFisherPattern2 + " isFisherPattern1: " + isFisherPattern1);
              if( isFisherPattern2 && isFisherPattern1)
              If the values are evaluating as false when you don't expect them to, add additional prints to the parts of the code related to calculating the value of isFisherPattern2and isFisherPattern1.​
              Gaby V.NinjaTrader Customer Service

              Comment


                #8
                HI i added times print.
                My updated code
                Code:
                Print(Times[0][0] + " isFisherPattern2: " + isFisherPattern2 + " isFisherPattern1: " + isFisherPattern1);
                
                            for (int i = 0; i < 7; i++)
                            {
                                // Fisher Transform pattern condition
                                isFisherPattern2 = fisherInd[i] > fisherInd[i + 1] && fisherInd[i + 1] > fisherInd[i + 2]
                                                       && fisherInd[i + 2] < fisherInd[i + 3] && fisherInd[i + 3] < fisherInd[i + 4] && fisherInd[i] < -0;
                
                                // Check if the pattern is found
                                if (isFisherPattern2)
                                {
                                    swingLow2 = fisherInd[i+2];
                                    Print("swingLow2" + swingLow2);
                                    Print("isFisherPattern2" + isFisherPattern2);
                                }
                            }
                            
                            for (int i = 7; i < 25; i++)
                            {
                                // Fisher Transform pattern condition
                                isFisherPattern1 = fisherInd[i] > fisherInd[i + 1] && fisherInd[i + 1] > fisherInd[i + 2]
                                                       && fisherInd[i + 2] < fisherInd[i + 3] && fisherInd[i + 3] < fisherInd[i + 4] && fisherInd[i] < -0;
                
                                // Check if the pattern is found
                                if (isFisherPattern1)
                                {
                                    
                                    swingLow1 = fisherInd[i+2];
                                    Print("swingLow1" + swingLow1);
                                    Print("isFisherPattern1" + isFisherPattern1);
                                }
                            }
                                                  
                                if( isFisherPattern2 && isFisherPattern1)
                
                                
                                {                                        
                                    Print("Divergence Found" );
                                }​
                Attached Files

                Comment


                  #9
                  Hello tkaboris,

                  Thank you for the output.

                  Your print is not in the right spot. It is happening outside the loop and before isFisherPattern2 and isFisherPattern1 are assigned within the loop, so once you get to the line
                  if( isFisherPattern2 && isFisherPattern1) in the code, the values shown in the output may not be up to date.

                  The print should be one line above the condition as shown below.

                  Code:
                  Print(Times[0][0] + " isFisherPattern2: " + isFisherPattern2 + " isFisherPattern1: " + isFisherPattern1);
                  if( isFisherPattern2 && isFisherPattern1)
                  Then we can see the updated values of your two variables at the time this condition is being evaluated. ​
                  Gaby V.NinjaTrader Customer Service

                  Comment


                    #10
                    HI i made it work when I removed bool and initialezed bool in privates

                    However I have problem with this part of code. Basically I need to specify if this pattern occured in the last 2 bars. When isFisherPattern2Short condition occurs it keeps on evalutting to true even after 2 more bars it passed. Is this a right loop for that?

                    for (int i = 0; i < 2; i++)
                    {
                    // Fisher Transform pattern condition
                    if(fisherInd[i] < fisherInd[i + 1] && fisherInd[i + 1] < fisherInd[i + 2]
                    && fisherInd[i + 2] > fisherInd[i + 3] && fisherInd[i + 3] > fisherInd[i + 4]
                    // && fisherInd[i + 4] > fisherInd[i + 5]
                    && fisherInd[i] > 0)
                    {
                    swingHigh2 = fisherInd[i+2];
                    swingHigh2Price = High[i+2];
                    isFisherPattern2Short = true;
                    Print("swingHigh2" + swingHigh2);
                    Print("isFisherPattern2Short" + isFisherPattern2Short);

                    }
                    }
                    Print("++++++++++++++");
                    Print("time event"+Time[0]);
                    Print("Event isFisherPattern2Short" + isFisherPattern2Short);
                    Print("++++++++++++++");​


                    Last edited by tkaboris; 05-23-2024, 09:05 AM.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by oneybuchi2, Today, 03:48 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post oneybuchi2  
                    Started by Graci117, 06-19-2024, 01:39 PM
                    6 responses
                    53 views
                    0 likes
                    Last Post Graci117  
                    Started by farawayz, Today, 01:20 PM
                    0 responses
                    11 views
                    0 likes
                    Last Post farawayz  
                    Started by rjm1903, Today, 01:10 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post rjm1903
                    by rjm1903
                     
                    Started by AH369, 06-21-2024, 11:09 AM
                    3 responses
                    29 views
                    0 likes
                    Last Post AH369
                    by AH369
                     
                    Working...
                    X