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 usazencort, Today, 01:16 AM
      0 responses
      1 view
      0 likes
      Last Post usazencort  
      Started by kaywai, 09-01-2023, 08:44 PM
      5 responses
      603 views
      0 likes
      Last Post NinjaTrader_Jason  
      Started by xiinteractive, 04-09-2024, 08:08 AM
      6 responses
      23 views
      0 likes
      Last Post xiinteractive  
      Started by Pattontje, Yesterday, 02:10 PM
      2 responses
      22 views
      0 likes
      Last Post Pattontje  
      Started by flybuzz, 04-21-2024, 04:07 PM
      17 responses
      230 views
      0 likes
      Last Post TradingLoss  
      Working...
      X