Here is the correct code:
//+------------------------------------------------------------------+ //| iCustom AMA smoothed RSI (fl) value on chart.mq5 | //| Copyright © 2022, Vladimir Karputov | //+------------------------------------------------------------------+ #property copyright "Copyright © 2022, Vladimir Karputov" #property version "1.000" #property tester_indicator "AMA smoothed RSI (fl)" //--- input parameters input int inpRsiPeriod = 14; // RSI period input int inpPeriod = 14; // AMA Period input int inpFastPeriod = 2; // AMA Fast end period input int inpSlowPeriod = 30; // AMA Slow end period input ENUM_APPLIED_PRICE inpPrice = PRICE_CLOSE; // Price enum enColorChangeOn { cchange_onSlope, // Change color on slope change cchange_onLevels, // Change color on outer levels cross cchange_onZero // Change color on middle level cross }; input int inpFlPeriod = 25; // Floating levels period input double inpFlLevelUp = 90; // Floating levels up % input double inpFlLevelDn = 10; // Floating levels down % input enColorChangeOn inpColorChange = cchange_onLevels; // Color changing mode //--- int handle_iCustom; // variable for storing the handle of the iCustom indicator //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- create handle of the indicator iMACD ([data folder]\MQL5\Indicators\AMA smoothed RSI (fl).mq5) handle_iCustom=iCustom(Symbol(),Period(),"AMA smoothed RSI (fl)", inpRsiPeriod, inpPeriod, inpFastPeriod, inpSlowPeriod, inpPrice, inpFlPeriod, inpFlLevelUp, inpFlLevelDn, inpColorChange); //--- if the handle is not created if(handle_iCustom==INVALID_HANDLE) { //--- tell about the failure and output the error code PrintFormat("Failed to create handle of the 'AMA smoothed RSI (fl)' indicator for the symbol %s/%s, error code %d", Symbol(), EnumToString(Period()), GetLastError()); //--- the indicator is stopped early return(INIT_FAILED); } //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- if(handle_iCustom!=INVALID_HANDLE) IndicatorRelease(handle_iCustom); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- double levu[],levm[],levd[],val[]; ArraySetAsSeries(levu,true); ArraySetAsSeries(levm,true); ArraySetAsSeries(levd,true); ArraySetAsSeries(val,true); int start_pos=0,count=3; if(!iGetArray(handle_iCustom,0,start_pos,count,levu) || !iGetArray(handle_iCustom,1,start_pos,count,levm) || !iGetArray(handle_iCustom,2,start_pos,count,levd) || !iGetArray(handle_iCustom,3,start_pos,count,val)) { return; } //--- string text=" Upper level | Middle level | Lower level | AMA smoothed RSI"+"\n"; for(int i=count-1; i>=0; i--) { text=text+"#"+IntegerToString(i)+ " | "+DoubleToString(levu[i],Digits()+1)+ " | "+DoubleToString(levm[i],Digits()+1)+ " | "+DoubleToString(levd[i],Digits()+1)+ " | "+DoubleToString(val[i],Digits()+1)+"\n"; } Comment(text); } //+------------------------------------------------------------------+ //| Get value of buffers | //+------------------------------------------------------------------+ bool iGetArray(const int handle,const int buffer,const int start_pos, const int count,double &arr_buffer[]) { bool result=true; if(!ArrayIsDynamic(arr_buffer)) { PrintFormat("ERROR! EA: %s, FUNCTION: %s, this a no dynamic array!",__FILE__,__FUNCTION__); return(false); } ArrayFree(arr_buffer); //--- reset error code ResetLastError(); //--- fill a part of the iBands array with values from the indicator buffer int copied=CopyBuffer(handle,buffer,start_pos,count,arr_buffer); if(copied!=count) { //--- if the copying fails, tell the error code PrintFormat("ERROR! EA: %s, FUNCTION: %s, amount to copy: %d, copied: %d, error code %d", __FILE__,__FUNCTION__,count,copied,GetLastError()); //--- quit with zero result - it means that the indicator is considered as not calculated return(false); } return(result); } //+------------------------------------------------------------------+
Result:
Files:

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Thanks.