Help Combining two indicator

 

Hello Everyone!

I am hoping someone can help me. I have two indicators that I am trying to combine into one stand alone indicator. Im not much of a coder. I have traded for years and am just now taking beginner coding courses. I have attempted to code this myself however my attempt only draws one of the two indicator lines and have been thus far unable to figure out what I did wrong. Any and all help is Greatly appreciated!!

Here is the first indi. Below will be the second as well as my attempt. Thanks Again 


#property description "The algorithm was taken from the book "

#property description "\"Cybernetics Analysis for Stock and Futures\" "

#property description "by John F. Ehlers"

#property strict



#property indicator_separate_window;

#property indicator_buffers 1;

#property indicator_type1 DRAW_LINE,STYLE_SOLID,1;

#property indicator_color1 clrCyan;

//#property indicator_color2 clrBlue



#property indicator_level1 0



double Cycle[];

double Trigger[];

double Smooth[];



input double mult=1.00;

input double Alpha = 0.07;



int buffers = 0;

int drawBegin = 64;



int init() {

    IndicatorBuffers(3);

    initBuffer(Cycle, "Adapt Stoch", DRAW_LINE);

    initBuffer(Trigger, "Trigger", DRAW_LINE);

    initBuffer(Smooth);

    IndicatorShortName("Adaptive Stochastic");

    return (0);

}

  

int start() {

    if (Bars <= drawBegin) return (0);

    int countedBars = IndicatorCounted();

    if (countedBars < 0) return (-1);

    if (countedBars > 0) countedBars--;

    int s, limit = MathMin(Bars - countedBars - 1, Bars - drawBegin);

    for (s = limit; s >= 0; s--) {

        Smooth[s] = (P(s) + 2.0 * P(s + 1) + 2.0 * P(s + 2) + P(s + 3)) / 6.0;

        double period = mult*iCustom(NULL, 0, "CyclePeriod", Alpha, 0, s);

        double alpha1 = 2.0 / (period + 1.0);

        Cycle[s] =  iStochastic(NULL,0,period,3,3,0,0,0,s) * -1;          

        if (s > Bars - 8) {

            Cycle[s] = (P(s) - 2.0 * P(s + 1) + P(s + 2)) / 4.0;

        }

        Trigger[s] = Cycle[s + 1];

    }

    return (0);

}



double P(int index) {

    if (index >= Bars) {

        return ((High[Bars - 1] + Low[Bars - 1]) / 2.0);

    }

    return ((High[index] + Low[index]) / 2.0);

}



void initBuffer(double& array[], string label = "", int type = DRAW_NONE, int arrow = 0, int style = EMPTY, int width = EMPTY, color clr = CLR_NONE) {

    SetIndexBuffer(buffers, array);

    SetIndexLabel(buffers, label);

    SetIndexEmptyValue(buffers, EMPTY_VALUE);

    SetIndexDrawBegin(buffers, drawBegin);

    SetIndexShift(buffers, 0);

    SetIndexStyle(buffers, type, style, width);

    SetIndexArrow(buffers, arrow);

    buffers++;

}

HERE IS THE 2ND INDI


//+------------------------------------------------------------------+

//|                                                     Momentum.mq4 |

//|                   Copyright 2005-2014, MetaQuotes Software Corp. |

//|                                              http://www.mql4.com |

//+------------------------------------------------------------------+

#property copyright   "2005-2014, MetaQuotes Software Corp."

#property link        "http://www.mql4.com"

#property description "Momentum"

#property strict



#property indicator_separate_window

#property indicator_buffers 1

#property indicator_color1 DodgerBlue

//--- input parameter

input int InpMomPeriod=14;  // Momentum Period

//--- buffers

double ExtMomBuffer[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit(void)

  {

   string short_name;

//--- indicator line

   SetIndexStyle(0,DRAW_LINE);

   SetIndexBuffer(0,ExtMomBuffer);

//--- name for DataWindow and indicator subwindow label

   short_name="Mom("+IntegerToString(InpMomPeriod)+")";

   IndicatorShortName(short_name);

   SetIndexLabel(0,short_name);

//--- check for input parameter

   if(InpMomPeriod<=0)

     {

      Print("Wrong input parameter Momentum Period=",InpMomPeriod);

      return(INIT_FAILED);

     }

//---

   SetIndexDrawBegin(0,InpMomPeriod);

//--- initialization done

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Momentum                                                         |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

   int i,limit;

//--- check for bars count and input parameter

   if(rates_total<=InpMomPeriod || InpMomPeriod<=0)

      return(0);

//--- counting from 0 to rates_total

   ArraySetAsSeries(ExtMomBuffer,false);

   ArraySetAsSeries(close,false);

//--- initial zero

   if(prev_calculated<=0)

     {

      for(i=0; i<InpMomPeriod; i++)

         ExtMomBuffer[i]=0.0;

      limit=InpMomPeriod;

     }

   else

      limit=prev_calculated-1;

//--- the main loop of calculations

   for(i=limit; i<rates_total; i++)

      ExtMomBuffer[i]=close[i]*100/close[i-InpMomPeriod];

//--- done

   return(rates_total);

  }

//+------------------------------------------------------------------+

HERE IS MY ATTEMPT AT COMPINING THE TWO

//+------------------------------------------------------------------+

//|                                              Mom is the Best.mq4 |

//|                        Copyright 2020, MetaQuotes Software Corp. |

//|                                             https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "Copyright 2020, MetaQuotes Software Corp."

#property link      "https://www.mql5.com"

#property version   "1.00"

#property strict

#property indicator_separate_window;

#property indicator_buffers 2;

#property indicator_type1 DRAW_LINE,STYLE_SOLID,1;

#property indicator_color1 clrRed;

#property indicator_type2 DRAW_LINE,STYLE_SOLID,1;

#property indicator_color2 clrBlue;

#property indicator_level1 0



double Cycle[];

double Trigger[];

double Smooth[];

double ExtMomBuffer[];



input int InpMomPeriod=14;

input double mult=1.00;

input double Alpha=0.07;



int buffers = 0;

int drawBegin = 64;



//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit(void)

  {

   string short_name;

//--- indicator line

   SetIndexStyle(0,DRAW_LINE);

   SetIndexBuffer(0,ExtMomBuffer);

//--- name for DataWindow and indicator subwindow label

   short_name="Mom("+IntegerToString(InpMomPeriod)+")";

   IndicatorShortName(short_name);

   SetIndexLabel(0,short_name);

//--- check for input parameter

   if(InpMomPeriod<=0)

     {

      Print("Wrong input parameter Momentum Period=",InpMomPeriod);

      return(INIT_FAILED);

     }

//---

   SetIndexDrawBegin(0,InpMomPeriod);

//--- initialization done

   return(INIT_SUCCEEDED);

  IndicatorBuffers(3);

    initBuffer(Cycle, "Adapt Stoch", DRAW_LINE);

    initBuffer(Trigger, "Trigger", DRAW_LINE);

    initBuffer(Smooth);

       return (0);

}

  int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

   int i,limit;

//--- check for bars count and input parameter

   if(rates_total<=InpMomPeriod || InpMomPeriod<=0)

      return(0);

//--- counting from 0 to rates_total

   ArraySetAsSeries(ExtMomBuffer,false);

   ArraySetAsSeries(close,false);

//--- initial zero

   if(prev_calculated<=0)

     {

      for(i=0; i<InpMomPeriod; i++)

         ExtMomBuffer[i]=0.0;

      limit=InpMomPeriod;

     }

   else

      limit=prev_calculated-1;

//--- the main loop of calculations

   for(i=limit; i<rates_total; i++)

      ExtMomBuffer[i]=close[i]*100/close[i-InpMomPeriod];

//--- done

   return(rates_total);

   if (Bars <= drawBegin) return (0);

    int countedBars = IndicatorCounted();

    if (countedBars < 0) return (-1);

    if (countedBars > 0) countedBars--;

    int s, limit1 = MathMin(Bars - countedBars - 1, Bars - drawBegin);

    for (s = limit1; s >= 0; s--) {

        Smooth[s] = (P(s) + 2.0 * P(s + 1) + 2.0 * P(s + 2) + P(s + 3)) / 6.0;

        double period = mult*iCustom(NULL, 0, "CyclePeriod", Alpha, 0, s);

        double alpha1 = 2.0 / (period + 1.0);

        Cycle[s] =  iStochastic(NULL,0,period,3,3,0,0,0,s) * -1;          

        if (s > Bars - 8) {

            Cycle[s] = (P(s) - 2.0 * P(s + 1) + P(s + 2)) / 4.0;

        }

        Trigger[s] = Cycle[s + 1];

    }

    return (0);

}



double P(int index) {

    if (index >= Bars) {

        return ((High[Bars - 1] + Low[Bars - 1]) / 2.0);

    }

    return ((High[index] + Low[index]) / 2.0);

}



void initBuffer(double& array[], string label = "", int type = DRAW_NONE, int arrow = 0, int style = EMPTY, int width = EMPTY, color clr = CLR_NONE) {

    SetIndexBuffer(buffers, array);

    SetIndexLabel(buffers, label);

    SetIndexEmptyValue(buffers, EMPTY_VALUE);

    SetIndexDrawBegin(buffers, drawBegin);

    SetIndexShift(buffers, 0);

    SetIndexStyle(buffers, type, style, width);

    SetIndexArrow(buffers, arrow);

    buffers++;

}


MQL4: automated forex trading, strategy tester and custom indicators with MetaTrader
MQL4: automated forex trading, strategy tester and custom indicators with MetaTrader
  • www.mql4.com
MQL4: automated forex trading, strategy tester and custom indicators with MetaTrader
 
mwilson4754: my attempt only draws one of the two indicator lines and have been thus far unable to figure out what I did wrong.

int OnInit(void){
   string short_name;
//--- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMomBuffer);

How can it possibly draw two lines when you only declare one buffer?

Reason: