Automatic changing of indicator line lengths to match dominant market cycle.

 

Recently I have been studying about cycles within markets. I came across a set of indicators developed by John Ehlers (rather, the original algorithms were Ehlers, the MT4 indicator was developed elsewhere) called coronas. These indicators work by first determining what is the dominant cyle period for their particular timeframe and then performing calculations. I want to use this dominant cycle as an input variable in one/several of my indicators. I can read the value fine through iCustom but was wondering if I need to 'reload' the indicator by calling init() again each time the periods change? The init() function checks for invalid inputs for the JMA series functions I use among other things. Assuming that I can ensure the value from the custom indicator is a valid length for the JMA series, would it be ok to just immediately use it, and then recall the AssignShortName() function again after the new input values have been chosen. I've added in my init() function below.


int init() {
   //open log file (specific to the indicator, chart and date)
   log_open(sIndicatorName+IndicatorInstanceNo);
   //the number of levels that can be set above as #property indicator_level 
   //is limited to eight so add in any further needed levels here. 
   SetLevelValue(9,0);
   sSymbol = Symbol();
   PipFactor = CheckBrokerDigits(sSymbol);
   if(Digits<=3) LabelPositionFactor = 100;
   //delete objects created by previous instances
   DeleteObjectsByPrefix("("+BBLength_1+","+MainLineMALength_1+","+SignalLineMALength_1+")");
   DeleteObjectsByPrefix("("+BBLength_2+","+MainLineMALength_2+","+SignalLineMALength_2+")");
   DeleteObjectsByPrefix("("+BBLength_3+","+MainLineMALength_3+","+SignalLineMALength_3+")");
   DeleteObjectsByPrefix("("+BBLength_4+","+MainLineMALength_4+","+SignalLineMALength_4+")");
   DeleteObjectsByPrefix("("+BBLength_5+","+MainLineMALength_5+","+SignalLineMALength_5+")");
   //---- Setting the accuracy format (number of digits after the decimal point)
   //---- for the visualization of the indicator values 
   IndicatorDigits(Digits + 1);
   
   //---- defining buffers for calculation 
   SetIndexBuffer(0,SignalBuffer_1);
   SetIndexBuffer(1,SignalBuffer_2);
   SetIndexBuffer(2,SignalBuffer_3);
   SetIndexBuffer(3,SignalBuffer_4);
   SetIndexBuffer(4,SignalBuffer_5);
   
   SetIndexStyle(0,IndexStyle0);
   SetIndexStyle(1,IndexStyle1);
   SetIndexStyle(2,IndexStyle2);
   SetIndexStyle(3,IndexStyle3);
   SetIndexStyle(4,IndexStyle4);
   
   //---- labels for subwindows
   SetIndexLabel(0,StringConcatenate("%B ","(",BBLength_1,",",MainLineMALength_1,",",SignalLineMALength_1,") "," Signal"));
   SetIndexLabel(1,StringConcatenate("%B ","(",BBLength_2,",",MainLineMALength_2,",",SignalLineMALength_2,") "," Signal"));  
   SetIndexLabel(2,StringConcatenate("%B ","(",BBLength_3,",",MainLineMALength_3,",",SignalLineMALength_3,") "," Signal")); 
   SetIndexLabel(3,StringConcatenate("%B ","(",BBLength_4,",",MainLineMALength_4,",",SignalLineMALength_4,") "," Signal")); 
   SetIndexLabel(4,StringConcatenate("%B ","(",BBLength_5,",",MainLineMALength_5,",",SignalLineMALength_5,") "," Signal"));  
   //---- setting alerts for not allowed values of external variables
   JJMASeriesAlert (0, "BBLength_1", BBLength_1);
   JJMASeriesAlert (0, "MainLineMALength_1", MainLineMALength_1);
   JJMASeriesAlert (0, "SignalLineMALength_1", SignalLineMALength_1);
   //---- check for invalid phase values
   JJMASeriesAlert (1, "BBPhase_1", BBPhase_1);  
   JJMASeriesAlert (1, "MainLinePhase_1", MainLinePhase_1);  
   JJMASeriesAlert (1, "SignalLinePhase_1", SignalLinePhase_1); 
   //---- setting alerts for not allowed values of external variables
   JJMASeriesAlert (0, "BBLength_2", BBLength_2);
   JJMASeriesAlert (0, "MainLineMALength_2", MainLineMALength_2);
   JJMASeriesAlert (0, "SignalLineMALength_2", SignalLineMALength_2);
   //---- check for invalid phase values
   JJMASeriesAlert (1, "BBPhase_2", BBPhase_2);  
   JJMASeriesAlert (1, "MainLinePhase_2", MainLinePhase_2);  
   JJMASeriesAlert (1, "SignalLinePhase_2", SignalLinePhase_2); 
   //---- setting alerts for not allowed values of external variables
   JJMASeriesAlert (0, "BBLength_3", BBLength_3);
   JJMASeriesAlert (0, "MainLineMALength_3", MainLineMALength_3);
   JJMASeriesAlert (0, "SignalLineMALength_3", SignalLineMALength_3);
   //---- check for invalid phase values
   JJMASeriesAlert (1, "BBPhase_3", BBPhase_3);  
   JJMASeriesAlert (1, "MainLinePhase_3", MainLinePhase_3);  
   JJMASeriesAlert (1, "SignalLinePhase_3", SignalLinePhase_3);
      //---- setting alerts for not allowed values of external variables
   JJMASeriesAlert (0, "BBLength_4", BBLength_4);
   JJMASeriesAlert (0, "MainLineMALength_4", MainLineMALength_4);
   JJMASeriesAlert (0, "SignalLineMALength_4", SignalLineMALength_4);
   //---- check for invalid phase values
   JJMASeriesAlert (1, "BBPhase_4", BBPhase_4);  
   JJMASeriesAlert (1, "MainLinePhase_4", MainLinePhase_4);  
   JJMASeriesAlert (1, "SignalLinePhase_4", SignalLinePhase_4);
   //---- setting alerts for not allowed values of external variables
   JJMASeriesAlert (0, "BBLength_5", BBLength_5);
   JJMASeriesAlert (0, "MainLineMALength_5", MainLineMALength_5);
   JJMASeriesAlert (0, "SignalLineMALength_5", SignalLineMALength_5);
   //---- check for invalid phase values
   JJMASeriesAlert (1, "BBPhase_5", BBPhase_5);  
   JJMASeriesAlert (1, "MainLinePhase_5", MainLinePhase_5);  
   JJMASeriesAlert (1, "SignalLinePhase_5", SignalLinePhase_5);    
   
   PriceSeriesAlert(AppliedPrice_1);
   PriceSeriesAlert(AppliedPrice_2); 
   PriceSeriesAlert(AppliedPrice_3);
   PriceSeriesAlert(AppliedPrice_4);
   PriceSeriesAlert(AppliedPrice_5);      
   //---- Changing sizes of buffer variables of the function
   //---- SmoothXSeries, number = X(X calls of the SmoothXSeries function)   
   if (SmoothXSeriesResize(15) != 15) {
      INIT = false;
      return(0);
    }

   SetIndexDrawBegin(1,BBLength_1+MainLineMALength_1+SignalLineMALength_1);
   SetIndexDrawBegin(2,BBLength_2+MainLineMALength_2+SignalLineMALength_2);
   SetIndexDrawBegin(3,BBLength_3+MainLineMALength_3+SignalLineMALength_3);
   SetIndexDrawBegin(4,BBLength_4+MainLineMALength_4+SignalLineMALength_4);
   SetIndexDrawBegin(5,BBLength_4+MainLineMALength_5+SignalLineMALength_5);
   //Assign indicator short name depending on input variables
   short_name = AssignShortName(sIndicatorName,ShowBand1,ShowBand2,ShowBand3,ShowBand4,ShowBand5);
   //Alert(short_name);
   IndicatorShortName(short_name); 
   //---- end of initialization
   INIT = true;
 
   return(0);
}