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 NullPointStrategies, Today, 05:17 AM
    0 responses
    50 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    126 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    69 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X