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:
    //Variables
    private int trend = 1;
    private int rsi = 1;
    public bool useRule1 = false; // this is a setable property
    public bool useRule2 = false; // this is a setable property
    public bool useRule3 = false; // this is a setable property
    
    /// <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
    
    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 stafe, Today, 12:34 PM
      2 responses
      7 views
      0 likes
      Last Post stafe
      by stafe
       
      Started by asmmbillah, Today, 11:18 AM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_ChrisL  
      Started by nickse2003, Today, 09:56 AM
      1 response
      23 views
      0 likes
      Last Post NinjaTrader_ChristopherJ  
      Started by ATMtrader0001, Today, 10:08 AM
      5 responses
      32 views
      0 likes
      Last Post ATMtrader0001  
      Started by WHICKED, Today, 09:47 AM
      1 response
      21 views
      0 likes
      Last Post NinjaTrader_Spencer  
      Working...
      X