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

Strategy conditions on/off

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

    Strategy conditions on/off

    I have a strategy with seven rules/conditions that I would like to turn on/off depending on the optimization. The only way I can think of that this could be done is by setting a variable for each rule 0=off 1=on. See very simplified explanation below my problem is how do I isolate the rules when not needed so they are isolated from the trade order condition? (example if I do not want Rule 1 to be taken into account I would set it to 0 before starting the strategy)

    There is most likely a simple coding technique for this, it is driving me mad I can't find any solutions any advice would be appreciated.

    //Variables
    private int trend = 1;
    private int rsi = 1;

    // Rule 1
    if (trend == 1)
    {
    Strategy Logic... blah blah
    condition1 = true;
    }
    else {condition1 = false}

    //Rule 2
    if (rsi == 1)
    {
    Strategy Logic... blah blah
    condition2 = true;
    }
    else {condition2 = false}

    //and so on for seven rules

    // order placement
    if (condition1 == true && condition2 == true)
    {
    EnterLimit....
    }

    #2
    Hello matt_, and thank you for your question.

    If I understand you correctly, I believe your strategy could benefit from a synchronous dispatcher pattern. Here is something I had in mind

    Code:
    [FONT=Courier New]//Variables
    private int trend = 1;
    private int rsi = 1;[/FONT][FONT=Courier New][FONT=Courier New]
    public bool useRule1 = false; // this is a setable property[/FONT][/FONT][FONT=Courier New][FONT=Courier New][FONT=Courier New]
    public bool useRule2 = false; // this is a setable property[/FONT][/FONT][/FONT][FONT=Courier New][FONT=Courier New][FONT=Courier New][FONT=Courier New]
    public bool useRule3 = false; // this is a setable property[/FONT][/FONT][/FONT]
    
    /// <summary> copy this method once for each rule 1 ... N </summary>
    /// <return>true if we should place a trade, false otherwise</return>
    private bool Rule1()
    {
      if (! useRule1)
      {
        return false;
      }
    
      // rule 1 logic here
    
      return true; // if we make it here, we place a trade
    }
    
    /// <summary> your onBarUpdate description </summary>
    protected override void OnBarUpdate()
    {
      bool doTheTrade = false;
      doTheTrade |= Rule1(); // repeat this line for all your rules 1 ... N
    
      if (doTheTrade)
      {
        EnterLong(/* args */);
      }
    }
    
    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public bool UseRule1
    {
      get { return useRule1; }
      set { useRule1 = value; }
    }
    
    // repeat to useRuleN
    #endregion
    [/FONT]
    If I didn't understand quite correctly, or if there is any other way we can help, please feel free to let us know, and we will follow up as soon as possible.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Hi Jessica
      You've answered my problem thank you!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by GussJ, 03-04-2020, 03:11 PM
      11 responses
      3,229 views
      0 likes
      Last Post xiinteractive  
      Started by andrewtrades, Today, 04:57 PM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by chbruno, Today, 04:10 PM
      0 responses
      7 views
      0 likes
      Last Post chbruno
      by chbruno
       
      Started by josh18955, 03-25-2023, 11:16 AM
      6 responses
      441 views
      0 likes
      Last Post Delerium  
      Started by FAQtrader, Today, 03:35 PM
      0 responses
      12 views
      0 likes
      Last Post FAQtrader  
      Working...
      X