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

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.​
      Gaby V.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by AaronKoRn, Today, 09:49 PM
      0 responses
      7 views
      0 likes
      Last Post AaronKoRn  
      Started by carnitron, Today, 08:42 PM
      0 responses
      9 views
      0 likes
      Last Post carnitron  
      Started by strategist007, Today, 07:51 PM
      0 responses
      10 views
      0 likes
      Last Post strategist007  
      Started by StockTrader88, 03-06-2021, 08:58 AM
      44 responses
      3,980 views
      3 likes
      Last Post jhudas88  
      Started by rbeckmann05, Today, 06:48 PM
      0 responses
      9 views
      0 likes
      Last Post rbeckmann05  
      Working...
      X