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 asd32, Today, 11:45 AM
    0 responses
    0 views
    0 likes
    Last Post asd32
    by asd32
     
    Started by tkaboris, Today, 11:09 AM
    1 response
    3 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by marco231, 03-20-2024, 03:56 PM
    5 responses
    155 views
    0 likes
    Last Post bnoisette  
    Started by tonynt, Today, 08:05 AM
    2 responses
    17 views
    0 likes
    Last Post tonynt
    by tonynt
     
    Started by victor68133, Today, 07:50 AM
    4 responses
    26 views
    0 likes
    Last Post backtester831  
    Working...
    X