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

question about Crossover's

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

    question about Crossover's

    Hello everyone, question about Crossover

    I use the code to output the signal to the strategy

    the code

    Code:
    if (Close[0] > Values[1][0] && Open[0] > Values[1][0] && High[0] > Values[1][0] && Low[0] > Values[1][0])
    
    {
    // Paint the current price bar lime to draw our attention to it
    BarBrushes[0] = Brushes.Lime;
    
    /* This crossover condition is considered bullish so we set the "bullIndication" Series<bool> object to true.
    We also set the "bearIndication" object to false so it does not take on a null value. */
    bullIndication[0] = (true);
    bearIndication[0] = (false);
    }
    
    else if (Close[0] < Values[1][0] && Open[0] < Values[1][0] && High[0] < Values[1][0] && Low[0] < Values[1][0])
    
    {
    // Paint the current price bar magenta to draw our attention to it
    BarBrushes[0] = Brushes.Magenta;
    
    /* This crossover condition is considered bearish so we set the "bearIndication" Series<bool> object to true.
    We also set the "bullIndication" object to false so it does not take on a null value. */
    bullIndication[0] = (false);
    bearIndication[0] = (true);
    }
    
    // Crossover: No cross
    else
    {
    /* Since no crosses occured we are not receiving any bullish or bearish signals so we
    set our Series<bool> objects both to false. */
    bullIndication[0] = (false);
    bearIndication[0] = (false);
    }
    
    // We set our variable to the close value.
    exposedVariable = Close[0];
    conditions

    Code:
    if (Close[0] > Values[1][0] && Open[0] > Values[1][0] && High[0] > Values[1][0] && Low[0] > Values[1][0])
    else if (Close[0] < Values[1][0] && Open[0] < Values[1][0] && High[0] < Values[1][0] && Low[0] < Values[1][0])
    work correctly and paint over the bars if the price crosses the Plot0 line
    everything is as i need

    The problem is that under these conditions a signal is sent to the strategy at each bar.

    I tried to replace condition with Crossover so that the signal comes only once and only when crossing the line

    Code:
    if (CrossAbove(Values[1], 900, 1))
    else if (CrossBelow(Values[1], 900, 1))
    but unfortunately then the indication does not work - the code does not work, what am I doing wrong? the problem is in syntax? how to do it right?

    #2
    Hello memonolog,

    Thank you for your post.

    The CrossAbove/CrossBelow conditions you have shared would check if a second added plot (Values[1]) in your script crosses above or below a value of 900 on the previous bar.

    What specifically is not working with the code?
    Are you not seeing the candle painted when the CrossAbove/CrossBelow condition returns true?
    Does the added plot not show on the chart?
    What value is being assigned to the plot?

    Please see the modified version of SampleBoolSeries attached that demonstrates adding two plots to the indicator script and using CrossAbove/CrossBelow conditions to determine if a candle is painted.

    Also, see the help guide documentation below for more information about using AddPlot().


    Let us know if we may assist further.
    Attached Files
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_BrandonH View Post
      Hello memonolog,

      Thank you for your post.

      The CrossAbove/CrossBelow conditions you have shared would check if a second added plot (Values[1]) in your script crosses above or below a value of 900 on the previous bar.

      What specifically is not working with the code?
      Are you not seeing the candle painted when the CrossAbove/CrossBelow condition returns true?
      Does the added plot not show on the chart?
      What value is being assigned to the plot?

      Please see the modified version of SampleBoolSeries attached that demonstrates adding two plots to the indicator script and using CrossAbove/CrossBelow conditions to determine if a candle is painted.

      Also, see the help guide documentation below for more information about using AddPlot().
      https://ninjatrader.com/support/help...t8/addplot.htm

      Let us know if we may assist further.
      Code:
      if (CurrentBar < 1) return; // do not process below this line until 20 bars processed.
      
      
      if (ToTime(Time[0]) == 110000)
      {
      if (IsFirstTickOfBar)
      {
      Open = Close[0];
      
      }
      }
      
      OPEN[0] = open;
      
      
      if (CrossAbove(Values[1], Close[0], 1))
      //if (Close[0] > Values[1][0] && Open[0] > Values[1][0] && High[0] > Values[1][0] && Low[0] > Values[1][0])
      
      {
      // Paint the current price bar lime to draw our attention to it
      BarBrushes[0] = Brushes.Lime;
      
      /* This crossover condition is considered bullish so we set the "bullIndication" Series<bool> object to true.
      We also set the "bearIndication" object to false so it does not take on a null value. */
      bullIndication[0] = (true);
      bearIndication[0] = (false);
      }
      
      
      else if (CrossBelow(Values[1], Close[0], 1))
      //else if (Close[0] < Values[1][0] && Open[0] < Values[1][0] && High[0] < Values[1][0] && Low[0] < Values[1][0])
      
      {
      // Paint the current price bar magenta to draw our attention to it
      BarBrushes[0] = Brushes.Magenta;
      
      /* This crossover condition is considered bearish so we set the "bearIndication" Series<bool> object to true.
      We also set the "bullIndication" object to false so it does not take on a null value. */
      bullIndication[0] = (false);
      bearIndication[0] = (true);
      }
      
      // Crossover: No cross
      else
      {
      /* Since no crosses occured we are not receiving any bullish or bearish signals so we
      set our Series<bool> objects both to false. */
      bullIndication[0] = (false);
      bearIndication[0] = (false);
      }
      
      // We set our variable to the close value.
      exposedVariable = Close[0];
      
      }
      Are you not seeing the candle painted when the CrossAbove/CrossBelow condition returns true? = yes
      Does the added plot not show on the chart? = plot show on the char
      What value is being assigned to the plot? = OPEN[0] = open;

      with

      Code:
      if (Close[0] > Values[1][0] && Open[0] > Values[1][0] && High[0] > Values[1][0] && Low[0] > Values[1][0]) else if (Close[0] < Values[1][0] && Open[0] < Values[1][0] && High[0] < Values[1][0] && Low[0] < Values[1][0])
      everything is as i need

      Comment


        #4
        i just don't know the right one
        syntax
        for an analog these condition

        if (Close[0] > Values[1][0]

        but with the

        CrossAbove

        The CrossAbove/CrossBelow conditions you have shared would check if a second added plot (Values[1]) in your script crosses above or below a value of 900 on the previous bar.
        i need to
        CrossAbove/CrossBelow conditions check if a current price crosses above or below plot (Values[1]) on the previous bar
        Last edited by memonolog; 02-26-2021, 11:25 AM.

        Comment


          #5
          Hello memonolog,

          Thank you for your note.

          If you would like to create a condition in your script that checks if the plot crosses above or below a certain value, such as the Close[0], you would need to call the following.

          if (CrossAbove(Values[1], Close[0], 1))
          {
          ...
          {
          else if (CrossBelow(Values[1], Close[0], 1))
          {
          ...
          }

          This would check if the second plot added in your script (Values[1]) crosses above or below the current Close price.

          Ultimately, debugging steps should be taken to determine how your script is behaving.

          To understand why the script is behaving as it is, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

          In the script add prints (outside of any conditions) that print the values of every variable used along with the time of that bar. Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

          Below is a link to a forum post that demonstrates using prints to understand behavior and including a link to a video recorded using the Strategy Builder.
          https://ninjatrader.com/support/foru...121#post791121

          Please let me know if I may further assist
          Brandon H.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_BrandonH View Post
            Hello memonolog,

            Thank you for your note.

            If you would like to create a condition in your script that checks if the plot crosses above or below a certain value, such as the Close[0], you would need to call the following.

            if (CrossAbove(Values[1], Close[0], 1))
            {
            ...
            {
            else if (CrossBelow(Values[1], Close[0], 1))
            {
            ...
            }

            This would check if the second plot added in your script (Values[1]) crosses above or below the current Close price.

            Ultimately, debugging steps should be taken to determine how your script is behaving.

            To understand why the script is behaving as it is, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

            In the script add prints (outside of any conditions) that print the values of every variable used along with the time of that bar. Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

            Below is a link to a forum post that demonstrates using prints to understand behavior and including a link to a video recorded using the Strategy Builder.
            https://ninjatrader.com/support/foru...121#post791121

            Please let me know if I may further assist
            Code:
            if (CrossAbove(Values[1], Close[0], 1))
            
            
            {
            // Paint the current price bar lime to draw our attention to it
            BarBrushes[0] = Brushes.Lime;
            
            /* This crossover condition is considered bullish so we set the "bullIndication" Series<bool> object to true.
            We also set the "bearIndication" object to false so it does not take on a null value. */
            bullIndication[0] = (true);
            bearIndication[0] = (false);
            }
            
            
            else if (CrossBelow(Values[1], Close[0], 1))
            
            
            {
            // Paint the current price bar magenta to draw our attention to it
            BarBrushes[0] = Brushes.Magenta;
            
            /* This crossover condition is considered bearish so we set the "bearIndication" Series<bool> object to true.
            We also set the "bullIndication" object to false so it does not take on a null value. */
            bullIndication[0] = (false);
            bearIndication[0] = (true);
            }
            unfortunately this code doesn’t work and I don’t understand why

            I know about the print, but I don't quite understand how it will help me if I don't know what's the matter

            Comment


              #7
              Hello memonolog,

              Thank you for your note.

              Unfortunately, in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services in our support. This is so that we can maintain a high level of service for all of our clients as well as our partners.

              Taking debugging steps will allow you to understand what values are being used for the conditions in your script while the conditions are being processed. By adding prints before the conditions in your script that print out the values being used in your conditions you are able to determine how the values in your script are being calculated. If the script is processing data and we print all the values used in the conditions then we can see on which bars the conditions are true or false, and we get to know why they are true are false because we can look at the same values used in the condition. For example, you would be able to see what value is being assigned to Values[1] as well as the value used by Close[0] to determine if your condition is returning true or not. Or, you would be able to determine if a value in your script returns null.

              Please see the forum post in my previous reply regarding how to go about debugging your script.

              Let us know if we may assist further.
              Brandon H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by rdtdale, Today, 01:02 PM
              0 responses
              1 view
              0 likes
              Last Post rdtdale
              by rdtdale
               
              Started by alifarahani, Today, 09:40 AM
              3 responses
              15 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by RookieTrader, Today, 09:37 AM
              4 responses
              18 views
              0 likes
              Last Post RookieTrader  
              Started by PaulMohn, Today, 12:36 PM
              0 responses
              6 views
              0 likes
              Last Post PaulMohn  
              Started by love2code2trade, 04-17-2024, 01:45 PM
              4 responses
              40 views
              0 likes
              Last Post love2code2trade  
              Working...
              X