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

Apply or not apply an indicator inside a strat

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

    Apply or not apply an indicator inside a strat

    I want to create a strategy with a couple of indicators. While backtesting, I would love a way to check a box and the strategy would run with or without my chosen indicators. So, I could run with an SMA and MACD or a MACD and RSI. Both combinations would be on the same strategy, but it will only apply the indicators I check off.

    I love to have checkboxes for all my indicators and the strat would only apply the indicators I specify.

    Is this possible? How would I write that code?

    #2
    Hello goelon,

    Thanks for your post.

    Yes, this is possible, and will you will need to create code sections that are enabled based on your check box selections.

    You can create bool type inputs to enable or disable the use of the indicators. As a user input, the check box (for the bool) will appear in the user interface.

    In your code, you can then use the state of that bool to enable the "display" of the indicator, for example:

    if (UseMACD) // UseMACD would be the name of the bool user input
    {
    AddChartIndicator(MACD(12, 26, 9));
    }
    etc. etc.


    In the OnBarUpdate() you would use the bool(s) to section your code, for example:

    if (UseMACD && !UseRSI && !UseSMA) // UseRSI would be the name of the bool user input to use the RSI. Note that this is using ! which means UseRSI and UseSMA must be false.
    {
    // all your code for processing based on MACD only
    }

    if (UseMACD && UseRSI && !UseSMA)
    {
    // all your code for processing with MACD and RSI
    }

    etc. etc.

    You would effectively be writing multiple strategies in one script.


    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Irukandji, Yesterday, 02:53 AM
    2 responses
    17 views
    0 likes
    Last Post Irukandji  
    Started by adeelshahzad, Today, 03:54 AM
    0 responses
    3 views
    0 likes
    Last Post adeelshahzad  
    Started by CortexZenUSA, Today, 12:53 AM
    0 responses
    3 views
    0 likes
    Last Post CortexZenUSA  
    Started by CortexZenUSA, Today, 12:46 AM
    0 responses
    1 view
    0 likes
    Last Post CortexZenUSA  
    Started by usazencortex, Today, 12:43 AM
    0 responses
    5 views
    0 likes
    Last Post usazencortex  
    Working...
    X