Help Using an indicator on custom indicator

 
Hi friends, I have a question. I have designed a personal indicator that I use the RSI indicator inside.When I first drop the indicator on the chart and set its initial parameters, it works fine . It shows the signals on the chart, but when I reset the input parameters, the indicator erases the signals that were on the past candles. What is the reason? Thank you for your help.
[Deleted]  
If you need help with your code, then show it please.
[Deleted]  

Please use the CODE button (Alt-S) when inserting code.

Code button in editor


 
//+------------------------------------------------------------------+
//|                                                New_Indicator.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

#include <CandlestickType.mqh>

#property indicator_chart_window
//--- plot 1
/*#property indicator_label1  ""
#property indicator_type1   DRAW_LINE
#property indicator_color1  Green,Red
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
#property indicator_buffers 5
#property indicator_plots   1*/

//---- indicator buffers
/*double ExtOpen[];
double ExtHigh[];
double ExtLow[];
double ExtClose[];
double ExtColor[];*/

//--- indicator handles



//-------- input parameters
input int RSI_ma_period                           = 14;
input ENUM_APPLIED_PRICE   RSI_applied_price      = PRICE_CLOSE ;
input double RSI_low_level                        = 30;
input double RSI_high_level                       = 70;

input int CCI_ma_period                           = 14;
input ENUM_APPLIED_PRICE   CCI_applied_price      = PRICE_CLOSE ;
input double CCI_low_level                        = -100;
input double CCI_high_level                       = +100;

input bool  InpAlert       = true;      // Enable. signal
input int   InpCountBars   = 100;      // Amount of bars for calculation
input color InpColorBull   = DodgerBlue;// Color of bullish models
input color InpColorBear   = Tomato;    // Color of bearish models
input bool  InpCommentOn   = true;      // Enable comment
input int   InpTextFontSize = 10;       // Font size

//--- list global variable
string prefix = "Signal Type ";
datetime CurTime = 0;
int number = 0;

double    RSIBuffer[]; 
int RSI_handle = 0 ;
int CCI_handle =0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---

     
   number = rates_total;
//--- We wait for a new bar
   if(rates_total == prev_calculated)
     {
      return(rates_total);
     }
Print("rates_total = ", rates_total);
Print("prev_calculated = ", prev_calculated);
//--- delete object
   string objname, comment;

   int objcount = 0;
//---
   int limit = 0;
   if(prev_calculated == 0)
     {
      if(InpCountBars <= 0 || InpCountBars >= rates_total)
         limit = 1;
      else
         limit = rates_total - InpCountBars;
     }
   else
      limit = prev_calculated - 1;
      
   if(!SeriesInfoInteger(Symbol(), 0, SERIES_SYNCHRONIZED))
      return(0);
// Variable of time when the signal should be given
   CurTime = time[rates_total - 2];
//--- calculate Candlestick Patterns

   for(int i = limit; i < rates_total; i++)
     {
      CANDLE_STRUCTURE cand1;
      if(!RecognizeCandle(_Symbol, _Period, time[i - 1], 1, cand1))
         continue;
      double x = RSI_Func(_Symbol, _Period,RSI_applied_price, RSI_ma_period, number - i);
      if(x > RSI_low_level - 3 && x < RSI_low_level + 3)
        {
         DrawSignal(prefix + "RSI buy " + string(objcount++), cand1, InpColorBull, "RSI BUY");
        }
      if(x > RSI_high_level - 3 && x < RSI_high_level + 3)
        {
         DrawSignal(prefix + "RSI sell " + string(objcount++), cand1, InpColorBear, "RSI SELL");
        }
      
     } // end of cycle of checks
     
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double RSI_Func(string symbol_name, ENUM_TIMEFRAMES time_frame, ENUM_APPLIED_PRICE applied_price, int ma_period, int Candles_Num)
  {
//--- indicator buffers
   
   //double    RSIBuffer[];         //Main buffer
   ArrayFree(RSIBuffer);
   
   ArraySetAsSeries(RSIBuffer, true);
   RSI_handle = iRSI(symbol_name, time_frame, ma_period, applied_price);
   CopyBuffer(RSI_handle, 0, 0, number, RSIBuffer);
  
   return NormalizeDouble(RSIBuffer[Candles_Num], 2);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DrawSignal(string objname, CANDLE_STRUCTURE &cand, color Col, string comment)
  {
   string objtext = objname + "text";
   if(ObjectFind(0, objtext) >= 0)
      ObjectDelete(0, objtext);
   if(ObjectFind(0, objname) >= 0)
      ObjectDelete(0, objname);
   if(InpAlert && cand.time >= CurTime)
     {
      Alert(Symbol(), " ", _Period, " ", comment);
     }
   if(Col == InpColorBull)
     {
      ObjectCreate(0, objname, OBJ_ARROW_BUY, 0, cand.time, cand.low);
      ObjectSetInteger(0, objname, OBJPROP_ANCHOR, ANCHOR_TOP);
      if(InpCommentOn)
        {
         ObjectCreate(0, objtext, OBJ_TEXT, 0, cand.time, cand.low);
         ObjectSetInteger(0, objtext, OBJPROP_ANCHOR, ANCHOR_LEFT);
         ObjectSetDouble(0, objtext, OBJPROP_ANGLE, -90);
        }
     }
   else
     {
      ObjectCreate(0, objname, OBJ_ARROW_SELL, 0, cand.time, cand.high);
      ObjectSetInteger(0, objname, OBJPROP_ANCHOR, ANCHOR_BOTTOM);
      if(InpCommentOn)
        {
         ObjectCreate(0, objtext, OBJ_TEXT, 0, cand.time, cand.high);
         ObjectSetInteger(0, objtext, OBJPROP_ANCHOR, ANCHOR_LEFT);
         ObjectSetDouble(0, objtext, OBJPROP_ANGLE, 90);
        }
     }
   ObjectSetInteger(0, objname, OBJPROP_COLOR, Col);
   ObjectSetInteger(0, objname, OBJPROP_BACK, false);
   ObjectSetString(0, objname, OBJPROP_TEXT, comment);
   if(InpCommentOn)
     {
      ObjectSetInteger(0, objtext, OBJPROP_COLOR, Col);
      ObjectSetString(0, objtext, OBJPROP_FONT, "Tahoma");
      ObjectSetInteger(0, objtext, OBJPROP_FONTSIZE, InpTextFontSize);
      ObjectSetString(0, objtext, OBJPROP_TEXT, "    " + comment);
     }
  }
 
Fernando Carreiro #:Please use the CODE button (Alt-S) when inserting code.
Thanks very
[Deleted]  

Your code is MQL5, but you posted in the MQL4 section. So your topic has been moved to the section: Technical Indicators
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893

 
Fernando Carreiro #:

Your code is MQL5, but you posted in the MQL4 section. So your topic has been moved to the section: Technical Indicators
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893

Thanks
 
   ArraySetAsSeries(RSIBuffer, true);
   RSI_handle = iRSI(symbol_name, time_frame, ma_period, applied_price);
   CopyBuffer(RSI_handle, 0, 0, number, RSIBuffer);

Perhaps you should read the manual, especially the examples.
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
          Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
          Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
          How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
          How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
          MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
          How to call indicators in MQL5 - MQL5 Articles (2010)