Is it possible for a script to determine what input values are currently being used by an indicator on the same chart?

 

UPDATE:  Solved.  See solution below.


Hello,

I'm wondering if it is possible for a script to discover what input parameter values are currently being used by an indicator on a chart.

Here is the most concise example I can provide, with the examples and questions in the comments of the code:

//+------------------------------------------------------------------+
//|                                           expressionTester10.mq5 |
//|                                   Copyright 2022, CTB Group, LLC |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, CTB Group, LLC"
#property link      "https://www.mql5.com"
#property version   "1.00"

#define indicatorToUse "csb_MACD Status In Timeframes_v4.05.ex5"

int macdStatusHandle;

input ENUM_TIMEFRAMES TF1=PERIOD_MN1;
input ENUM_TIMEFRAMES TF2=PERIOD_W1;
input ENUM_TIMEFRAMES TF3=PERIOD_D1;
input ENUM_TIMEFRAMES TF4=PERIOD_H4;
input ENUM_TIMEFRAMES TF5=PERIOD_H1;
input ENUM_TIMEFRAMES TF6=PERIOD_M15;
input ENUM_TIMEFRAMES TF7=PERIOD_M5;
input ENUM_TIMEFRAMES TF8=PERIOD_M1;

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
int OnStart()
  {
//---
   
   // ALTERNATIVE 1
   // of course I can use the default values of the indicator, and if the indicator was always known to be using default values 
   // then instead of using input parameters in this script, they could be #define statements instead of inputs.
   macdStatusHandle=iCustom(_Symbol,_Period,indicatorToUse);
   
   // ALTERNATIVE 2
   // but if the indicator instance on the chart is not using default values, then I have to prompt for matching input
   // values from the user of this script (which burdens the user to be sure are the same as being used on the indicator) 
   // and pass them to the iCustom call like this:
   macdStatusHandle=iCustom(_Symbol,_Period,indicatorToUse,TF1,TF2,TF3,TF4,TF5,TF6,TF7,TF8);
   
   // what I would like to do is be able to answer the question:
   // "What input parameters are currently being used by the indicator on this chart?"
   // and not force the user of the script to input them and make sure they are correct.
   
   // IS THIS POSSIBLE SOMEHOW?
   
   <do some stuff...>   
  
  return(0);
  }

Really appreciate any insight or alternative work-arounds.  Thank you in advance for your time!

 
Christian Berrigan:

Hello,

I'm wondering if it is possible for a script to discover what input parameter values are currently being used by an indicator on a chart.

Here is the most concise example I can provide, with the examples and questions in the comments of the code:

Really appreciate any insight or alternative work-arounds.  Thank you in advance for your time!

I figured it out!  Finally found the ChartIndicatorGet() and IndicatorParameters()

This seems to work:

int OnStart()
  {
//---
   

   macdStatusHandle=iCustom(_Symbol,_Period,indicatorToUse);
   
   MqlParam indParms[];
   int indHandle=ChartIndicatorGet(0,0,"MACD Timeframes");
   Print("handle: ",indHandle);
   ENUM_INDICATOR indicatorType;
   int paramCount=IndicatorParameters(indHandle,indicatorType,indParms);
   Print("errors: ",GetLastError());
   IndicatorRelease(indHandle);
   
   //indParms contains the parameters and their current values :)
  return(0);
  }

I wish I had better intuition about how to find these functions.

Hope this helps someone else someday.