Need Help in Plotting 6 legs of Indicators - Beginner - page 2

 
I have made the changes now it's plotting the 3 lines on chart is it correct. I have one doubt that there are 6 legs but why on chart lines are only 3
//defining properties

#property  indicator_chart_window
#property indicator_buffers 6
#property indicator_plots   6
#property indicator_color1 clrRed
#property indicator_color2 clrOrange
#property indicator_color3 clrYellow
#property indicator_color4 clrGold
#property indicator_color5 clrYellow
#property indicator_color6 clrRed



// Define input parameters
input ENUM_APPLIED_PRICE price = PRICE_HIGH;
input int MA_Period = 14;
// ...
input int  bars_CI_H3 = 14;
input ENUM_APPLIED_PRICE price_CI_H3 = PRICE_HIGH;
/*input int  bars_CI_H2 = 14;
input ENUM_APPLIED_PRICE price_CI_H2 = PRICE_HIGH;
input int  bars_CI_H1 = 14;
input ENUM_APPLIED_PRICE price_CI_H1 = PRICE_HIGH;*/

//input Custom Low indicators
input int  bars_CI_L1 = 14;
input ENUM_APPLIED_PRICE price_CI_L1 = PRICE_LOW;

//needs to look once

/*input int  bars_CI_L2 = 14;
input ENUM_APPLIED_PRICE price_CI_L2 = PRICE_LOW;

input int  bars_CI_L3 = 14;
input ENUM_APPLIED_PRICE price_CI_L3 = PRICE_LOW;*/

//Buffers of the 6 legs of custom Indicators
double  CI_H3Buffer[];
double  CI_H2Buffer[];
double CI_H1Buffer[];
double CI_L1Buffer[];
double CI_L2Buffer[];
double CI_L3Buffer[];

//Buffers for BandRange, BandHigh, BandLow

double SMA14RangeBuffer[]; //SMA14RangeBuffer - BandRange
double valueSMAH[]; //valueSMAH - BandHigh
double valueSMAL[]; //valueSMAL - BandLow

//integer handle for iMA(low, high) function
int handleSMA14H;
int handleSMA14L;

//integer handle for extra iMA(low, high) function part that we are calculating on each legs of indicators
int extraSMA;
int extraSMAL;

int OnInit()
{
      //--- indicator buffers mapping
      
      SetIndexBuffer(0, CI_H3Buffer, INDICATOR_DATA);
      SetIndexBuffer(1, CI_H2Buffer, INDICATOR_DATA);
      SetIndexBuffer(2, CI_H1Buffer, INDICATOR_DATA);
      SetIndexBuffer(3, CI_L1Buffer, INDICATOR_DATA);
      SetIndexBuffer(4, CI_L2Buffer, INDICATOR_DATA);
      SetIndexBuffer(5, CI_L3Buffer, INDICATOR_DATA);
      
      //--- name for DataWindow and indicator subwindow label
      IndicatorSetString(INDICATOR_SHORTNAME, "TNJK ExtensionBands");
      
      // Set arrays as series
      ArraySetAsSeries(CI_H3Buffer, true);
      ArraySetAsSeries(CI_H2Buffer, true);
      ArraySetAsSeries(CI_H1Buffer, true);
      ArraySetAsSeries(CI_L1Buffer, true);
      ArraySetAsSeries(CI_L2Buffer, true);
      ArraySetAsSeries(CI_L3Buffer, true);
      
      // Calculate handles for moving averages
      
      handleSMA14H = iMA(_Symbol, PERIOD_CURRENT, MA_Period, 0, MODE_SMA, PRICE_HIGH);
      handleSMA14L = iMA(_Symbol, PERIOD_CURRENT, MA_Period, 0, MODE_SMA, PRICE_LOW);
      
      // Calculate handles for extra moving averages that we need to add in 6 legs of indicators
      extraSMA = iMA(_Symbol, PERIOD_CURRENT, bars_CI_H3, 0, MODE_SMA, price_CI_H3);
      extraSMAL = iMA(_Symbol, PERIOD_CURRENT, bars_CI_L1, 0, MODE_SMA, price_CI_L1);
      
      // Set arrays as series
      ArraySetAsSeries(valueSMAH, true);
      ArraySetAsSeries(valueSMAL, true);
      
      // Set plotting properties
      //PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, 0.0);
      for(int count=0; count<6; count++) PlotIndexSetInteger(count,PLOT_DRAW_TYPE,DRAW_LINE);
      for(int count=0; count<6; count++) PlotIndexSetString(count,PLOT_LABEL,"Line "+string(count+1));
      
      
      return (INIT_SUCCEEDED);
}

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 limit = rates_total - prev_calculated; // // Calculate the limit for the current calculation cycle
    
    // If there were previous calculations, increment the limit to include the missing bar
    if (prev_calculated > 0) limit++;
    
    // Copy values from moving averages into arrays through handles
    CopyBuffer(handleSMA14H, 0, 0, limit, valueSMAH);
    CopyBuffer(handleSMA14L, 0, 0, limit, valueSMAL);
    
    // Set range buffer's arrays as series
    ArraySetAsSeries(SMA14RangeBuffer, true);
    
    //Setting length of RangeBuffer to length limit
    ArrayResize(SMA14RangeBuffer,limit);
    
    // Calculate BandRange values
    for(int i = limit - 1; i >= 0; i--) {
         SMA14RangeBuffer[i] = valueSMAH[i] - valueSMAL[i];
         
    }
    // Create temporary arrays for extra moving averages
    double extraSMAHigh[];
    ArraySetAsSeries(extraSMAHigh, true);
    CopyBuffer(extraSMA, 0, 0, limit, extraSMAHigh);
    
    double extraSMALow[];
    ArraySetAsSeries(extraSMALow, true);
    CopyBuffer(extraSMAL, 0, 0, limit, extraSMALow);
    
    
    
    // Calculate the custom indicator lines
    
    for(int i = limit - 1; i >= 0; i--) {
      CI_H3Buffer[i] = (SMA14RangeBuffer[i] * 3) + extraSMAHigh[i];
      CI_H2Buffer[i] = (SMA14RangeBuffer[i] * 2) + extraSMAHigh[i];
      
      CI_H1Buffer[i] = SMA14RangeBuffer[i] + extraSMAHigh[i];
      CI_L1Buffer[i] = SMA14RangeBuffer[i] - extraSMALow[i];
      CI_L2Buffer[i] = (SMA14RangeBuffer[i]*2) - extraSMALow[i];
      CI_L3Buffer[i] = (SMA14RangeBuffer[i]*3) - extraSMALow[i];
   }
   
    
   
   return rates_total;
}
 
William Roeder #:
  1. I already did. What part of “You get that in OnInit” was unclear? Did you move the creation of your handles there?

  2. That is not a value. What part of "you use the handle, shift and count" was unclear?

  3. Mixture of MT4 and MT5 code. Stop using ChatGPT.
              Help needed to debug and fix an AI EA - Trading Systems - MQL5 programming forum #2 (2023)

    If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into your code.

  1. Yeah correct so I have changed my code according to that but now it's only plotting 3 lines of CI_H's instead of 6. One more thing for CI_L's when I printing it show's negative value contained and if I multilply those CI_L's formula with -1 it successfully plotting 6 lines does that mean formula for buffers are wrong or my code has some bugs. Please let me know once. Thanks!