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

Including Choppiness Index as an entry criteria produces error

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

    Including Choppiness Index as an entry criteria produces error

    Hey,

    I want to include Choppiness Index indicator as a part of entry criteria. The error happens in Strategy Analyzer window, when I choose Optimize: ChoppinessEBool. It gives correct results, when it is set to TRUE, and gives 0's (0 trades, 0 profit/loss) when it is set to FALSE.

    I will paste my formulas here, so you could maybe help me with an error.

    _____________________________________________
    public class AI_ADX_200807_O : Strategy

    private bool ChoppinessEBool = false,

    _____________________________________________

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {

    ChpE = false; // Choppiness Index: Entry- Boolean.
    ChoppinessPeriodE = 2; // Choppiness Index: Entry- Period.
    ChoppinessTE = 80; // Choppiness Index: Entry- To (Highest Value).
    _______________________________________________

    protected override void OnBarUpdate()
    {

    ChoppinessEBool = (((ChpE && ChoppinessIndex(ChoppinessPeriodE)[0] < ChoppinessTE)) ? true : false);

    if (CrossAbove(ADX(Period), Trend, 1)
    && ADX(Period)[0] < ADXMax
    && Close[0] > SMA(Close, MAB)[0] && ChoppinessEBool)
    {
    EnterLong();
    }
    _________________________________________________


    As I said, it works fine, when Optimization is set to TRUE, but when it's set to FALSE, it returns 0 trades. And I want it to work as 'it supposed to' - Ignore Choppiness indicator, so I could compare which method - with or without indicator - performs better.

    #2
    Hello UltraNIX,

    Thanks for your post.

    Your ChoppinessEBool bool is part of your criteria to enter. In your logic, this value must be set to true in addition to your other entry criteria in order for EnterLong to be reached.

    If you do not optimize the property, setting the bool to true in the Strategy Analyzer will allow EnterLong to be reached when other criteria is met.

    If you do not optimize the property, setting the bool to false in the Strategy Analyzer NOT will allow EnterLong to be reached, even when other criteria is met.

    If you optimize the property, the strategy will be backtested with this set to true and again with it set to false.

    You would take debugging steps in this case to check your logic and confirm the values used to evaluate your conditions to see why the action has not taken place.

    Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm

    To attain your goal, I may suggest making separate entry conditions that are nested within a check for ChoppinessEBool.

    For example:

    Code:
    if (ChoppinessEBool == true)
    {
        // Your Entry Logic WITH Choppiness
    }
    else
    {
        // Your Entry Logic WITHOUT Choppiness
    }
    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      NInjaTrader_Jim, thank you for your initial efforts. Can we spend more time on this and fix the ChoppinessEBool calculation part.

      Because I want to also test other indicator settings as entry criteria, so If I had to "Nest" inside, like

      If (ChoppinessEBool == true)
      {
      If (MAEBool == true)
      {
      if (ADXEBool == true)

      that would mess the whole calculation scheme, as then I would have to determine as many scenarios of those true/false combinations as possible.

      There have to be a better way, like If bool is set to TRUE, then it includes that part into calculation, and if it is set to FALSe, then it is omitted and other conditions are evaluated. Without nesting inside multiple if statements.

      Comment


        #4
        Hello UltraNIX,

        My main point is that this is a logical issue. You could consider using OR operators (||) and grouping conditions together with parenthesis, and you could also consider using a Ternary operator (conditional operator) to create inline boolean expressions to control your logic.

        How you want to design your logic will be up to you, and how complex the logic is can make writing the code trickier.

        A publicly available resource on Ternary operators can be found here - https://docs.microsoft.com/en-us/dot...ional-operator

        Another option to consider is to create bools and use those to represent your conditions so they are easier to follow.

        We look forward to assisting.
        JimNinjaTrader Customer Service

        Comment


          #5
          Yes, Jim, thanks, I think that with OR operators (||) I would do the trick. Thank you.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by inanazsocial, Today, 01:15 AM
          0 responses
          2 views
          0 likes
          Last Post inanazsocial  
          Started by trilliantrader, 04-18-2024, 08:16 AM
          5 responses
          22 views
          0 likes
          Last Post trilliantrader  
          Started by Davidtowleii, Today, 12:15 AM
          0 responses
          3 views
          0 likes
          Last Post Davidtowleii  
          Started by guillembm, Yesterday, 11:25 AM
          2 responses
          10 views
          0 likes
          Last Post guillembm  
          Started by junkone, 04-21-2024, 07:17 AM
          9 responses
          71 views
          0 likes
          Last Post jeronymite  
          Working...
          X