Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

The Difference Between CrossAbove/Below and High(0)/Low(0) Greater/Less Than?

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

    The Difference Between CrossAbove/Below and High(0)/Low(0) Greater/Less Than?

    Dear Ninja Team,

    I am trying to build a strategy where:
    - if price crossabove(high, indicator[0],1) && open[0] < indicator[0]; then enter long.
    - if price crossbelow(low[0], indicator[0],1) && open[0] > indicator[0]; then enter short.

    After back testing it and going through the chart i realized that some of the trades where these conditions were valid were not taken.

    So alternatively, I translated cross above/below by changing the rules to:
    - if price high[0] > indicator[0] && open[0] < indicator[0]; then enter long.
    - if price low[0] < indicator[0] && open[0] > indicator[0]; then enter short.

    This combination gave me significantly different results when comparing it to cross above/below.

    Can you please explain the difference between the two set ups and why it gives different results when running backtests on each?

    Please find attached test strategies and runs i did to show you the results.

    The results of the below strategies will be uploaded in my next reply.
    Attached Files

    #2
    Result attachments are below.
    Attached Files

    Comment


      #3
      Hello ahpeak951,

      Thank you for your post.

      Please note that:

      if price crossabove(high, indicator[0],1) && open[0] < indicator[0]; then enter long.

      if price high[0] > indicator[0] && open[0] < indicator[0]; then enter long.

      Are not equivalent statements.

      A CrossAbove as you have it currently would be checking if High[1] < Indicator[0] and High[0] > Indicator[0]. If these two statements are true, then a CrossAbove occurred.

      High[0] > Indicator[0] is only checking if the current high is greater than the value of Indicator[0], not if the High crossed above this value at any point.

      This is also true for CrossBelow.

      crossbelow(low[0], indicator[0],1

      Note that this should actually be​:

      CrossBelow(Low, Indicator[0], 1)

      To match the correct syntax which is: CrossBelow(ISeries<double> series1, double value, int lookBackPeriod)



      CrossBelow(Low, Indicator[0], 1) would be checking if Low[1] > Indicator[0] and Low[0] < Indicator[0].


      I recommend using prints and enabling TraceOrders to debug the script.

      To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, 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 strategy add prints (outside of any conditions) that print the date time of the bar and all values compared in every condition that places an order.

      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 important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.

      Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

      Further, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

      I am happy to assist you with analyzing the output from the output window.

      Run or backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.

      Below is a link to a forum post that demonstrates using informative prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.


      Please let me know if I may further assist with analyzing the output or if you need any assistance creating a print or enabling TraceOrders.​

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Today, 05:17 AM
      0 responses
      52 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      70 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X