How to set different RSI levels created during EA OnInit() method ?

 

Hi, 

Could anyone help me to set the levels for a RSI indicator that I'm creating/adding during EA OnInit() event ?

Just to be clear, I want to do this during the EXPERT execution, not during Indicator initialization, as I'm getting those limits as parameters from my EA.

I can add the RSI indicator using code below, but it always starts with the default values 70/30 - didn't find a way to change this from the EA. I found many articles explaining how to do this on an indicator code, but not on how to change the values from the Expert Advisor...


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {

   hRsi = new CiRSI;
   hRsi.Create(Symbol(), Period(), 14, PRICE_CLOSE);
   ChartIndicatorAdd(0,1,hRsi.Handle());
   
   hRsi.Redrawer(true); 
   
    
   ChartRedraw();
   
   return(INIT_SUCCEEDED);
  }
 

In OnInit:

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- indicator buffers mapping
***
//--- set levels
   IndicatorSetInteger(INDICATOR_LEVELS,2);
   IndicatorSetDouble(INDICATOR_LEVELVALUE,0,InpLevelDown);
   IndicatorSetDouble(INDICATOR_LEVELVALUE,1,InpLevelUp);
 
Example:  CCI Color Levels:


Indicator Input

  • Averaging period - indicator averaging period;
  • Level UP - the UP level value;
  • Level DOWN - the DOWN level value.

The UP and DOWN levels will be immediately shown in the indicator sub-window:

CCI Color Levels Inputs

CCI Color Levels
CCI Color Levels
  • www.mql5.com
The indicator looks like this: Three types of graphical constructions were used for this visual effect: Indicator Input The UP and DOWN levels will be immediately shown in the indicator sub-window: How to Access Indicator Data in an Expert Advisor The DRAW_HISTOGRAM2 style is based on two indicator buffers, that is why we see two Level UP...
 
Vladimir Karputov:

In OnInit:


Hi Vladimir, 


First of all, thank you for taking time to help!

The methods "IndicatorSet"... cannot be used from Experts, only at Indicators - they are in this list of "Prohibited" functions as stated in this article :  https://www.mql5.com/en/docs/runtime/running


All functions designed for indicators are prohibited in Expert Advisors and scripts:


Any other way to do this ?

Documentation on MQL5: Custom Indicators / SetIndexBuffer
Documentation on MQL5: Custom Indicators / SetIndexBuffer
  • www.mql5.com
//|                                              TestCopyBuffer1.mq5 | //|                        Copyright 2009, MetaQuotes Software Corp. | //|                                              https://www.mql5.com | //| Custom indicator initialization function                         |...
 
int OnInit()
  {

   hRsi = new CiRSI;
   hRsi.Create(Symbol(), Period(), 14, PRICE_CLOSE);
   ChartIndicatorAdd(0,1,hRsi.Handle());
   ObjectCreate(0, "LimiteSup", OBJ_HLINE, 1, 0, gatilhoSuperior);
   ObjectCreate(0, "LimiteInf", OBJ_HLINE, 1, 0, gatilhoInferior);
   hRsi.Redrawer(true); 
   
    
   ChartRedraw();
   
   
   
//---
   return(INIT_SUCCEEDED);
  }


Just adding some information, I managed to add "lines" to the indicator window, but they are separated objects and they don't show up on backtesting, only running the expert on an actual chart.

This is not what I wanted...

 
WalcirW :


Just adding some information, I managed to add "lines" to the indicator window, but they are separated objects and they don't show up on backtesting , only running the expert on an actual chart.

This is not what I wanted...

You did not understand. The algorithm is as follows: You write your custom indicator (the indicator in which you add levels - an example in the code CCI Color Levels). And then, in the Expert Advisor, you create the indicator handle (the handle must be created in OnInit) and using the 'ChartIndicatorAdd' add the indicator to the chart.

CCI Color Levels
CCI Color Levels
  • www.mql5.com
The indicator looks like this: Three types of graphical constructions were used for this visual effect: Indicator Input The UP and DOWN levels will be immediately shown in the indicator sub-window: How to Access Indicator Data in an Expert Advisor The DRAW_HISTOGRAM2 style is based on two indicator buffers, that is why we see two Level UP...
 

An example of a custom indicator with custom levels and an example of an Expert Advisor that works with this indicator

Custom indicator based on iRSI (Relative Strength Index, RSI) - added two custom levels

RSI Levels :

Custom indicator based on iRSI (Relative Strength Index, RSI) - added two custom levels 

RSI Levels

 
Vladimir Karputov:

You did not understand. The algorithm is as follows: You write your custom indicator (the indicator in which you add levels - an example in the code CCI Color Levels). And then, in the Expert Advisor, you create the indicator handle (the handle must be created in OnInit) and using the 'ChartIndicatorAdd' add the indicator to the chart.

I really appreciate your help Vladimir !

Never crossed my mind that we actually have to create ANOTHER indicator just to change two levels that already exist in the "base" one... That sounds kind of silly to someone that works with software development. It would make sense if I was trying to add more levels or change the behavior of the indicator, but this is not the case :-) So I guess that this limitation is based on the fact that the included RSI indicator is bases on the "de facto" standard and so they assume we woudn't change levels...

Anyways, I'm very happy that you helped me with this, and as I saw, you had this same problem in the past - thank's for sharing !

Best regards from Brasil !

 
Vladimir Karputov:

You did not understand. The algorithm is as follows: You write your custom indicator (the indicator in which you add levels - an example in the code CCI Color Levels). And then, in the Expert Advisor, you create the indicator handle (the handle must be created in OnInit) and using the 'ChartIndicatorAdd' add the indicator to the chart.

Humm, let me say: first I need to create a custom indicator that contein all level that i need (RSI indicator with 4 or more levels); finaly, Create an EA where i will use my custom indicator. That is all???

 
WalcirW #:

I really appreciate your help Vladimir !

Never crossed my mind that we actually have to create ANOTHER indicator just to change two levels that already exist in the "base" one... That sounds kind of silly to someone that works with software development. It would make sense if I was trying to add more levels or change the behavior of the indicator, but this is not the case :-) So I guess that this limitation is based on the fact that the included RSI indicator is bases on the "de facto" standard and so they assume we woudn't change levels...

Anyways, I'm very happy that you helped me with this, and as I saw, you had this same problem in the past - thank's for sharing !

Best regards from Brasil !

I have the same situation, can you help me with the code

Reason: