Announcement

Collapse
No announcement yet.

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.


    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    58 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    34 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    195 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Started by CaptainJack, 04-24-2026, 11:07 PM
    0 responses
    359 views
    0 likes
    Last Post CaptainJack  
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    281 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X