Reinitialising Indicator in EA or changing it'Parameters

 

Hi!

For an EA I use a custom indicator with iCustom.

It works fine so far.

But for the strategy I need to change the indicators parameters at some point of time.

I can get a new indicatorhandel with iCustom(...) with the new indicator settings. this works fine too.

But then I will have two indicators running. I need to get rid of the old one.
I tried to use indicatorrelease() but this is not working.

It just says 

ERR_FUNCTION_NOT_ALLOWED

4014

Function is not allowed for call

 

How can I get rid of the  old indicator or change it's parameters?

Thanks for your help!

 Best regards 

Documentation on MQL5: Timeseries and Indicators Access / IndicatorRelease
Documentation on MQL5: Timeseries and Indicators Access / IndicatorRelease
  • www.mql5.com
Timeseries and Indicators Access / IndicatorRelease - Reference on algorithmic/automated trading language for MetaTrader 5
 

You can't change the parameter.

IndicatorRelease() is working only on a live chart. With the Strategy Tester you can't call it, so don't worry about it.

 
Alain Verleyen:

You can't change the parameter.

IndicatorRelease() is working only on a live chart. With the Strategy Tester you can't call it, so don't worry about it.

Hello

I understand. So is there any workaround to change an indicator parameter while using the Strategy Tester?

I mean: I use a MA indicator with period 100 bars in my EA  -->  Something happens in the EA  -->  The MA period should be turned to 80 bars.

It sounds to me like a quote common need...isn't it?


Thanks

 
David986:

Hello

I understand. So is there any workaround to change an indicator parameter while using the Strategy Tester?

I mean: I use a MA indicator with period 100 bars in my EA  -->  Something happens in the EA  -->  The MA period should be turned to 80 bars.

It sounds to me like a quote common need...isn't it?


Thanks

So just do it. Initialize a new indicator handle. What is the problem ?
 
Alain Verleyen:
So just do it. Initialize a new indicator handle. What is the problem ?

What is want to have a MA with a 80 bars period  in place ofthe old 100 bars MA on the Strategy Tester.

I tried this: to add a 80 bars MA using ChartIndicatorAdd() and delete the old 100 bars MA with ChartIndicatorDelete(), but ChartIndicatorDelete() seems to be ineffective So the result are two MAs running in my Strategy Tester...

It would be necessary to find a way to change the MA period during the backtest.

Documentation on MQL5: Chart Operations / ChartIndicatorAdd
Documentation on MQL5: Chart Operations / ChartIndicatorAdd
  • www.mql5.com
"the Expert Advisor's properties and specify correct  and  parameters." //| Expert initialization function                                   |                                                                                       ); "Attention! %s: Trying to add MACD(%s/%s) indicator on %s/%s chart. Receiving error 4114" //
 
David986:

What is want to have a MA with a 80 bars period  in place ofthe old 100 bars MA on the Strategy Tester.

I tried this: to add a 80 bars MA using ChartIndicatorAdd() and delete the old 100 bars MA with ChartIndicatorDelete(), but ChartIndicatorDelete() seems to be ineffective So the result are two MAs running in my Strategy Tester...

It would be necessary to find a way to change the MA period during the backtest.

If you cannot live with having two lines at all times, how about creating your own custom indicator - delegate the MA period switching decision to the custom indicator, so that it's single buffer will take values from either of 80/100 bars MA at different time, according to your predefined conditions. This way, your EA will just call one single custom indicator at all times.

 
Seng Joo Thio:

If you cannot live with having two lines at all times, how about creating your own custom indicator - delegate the MA period switching decision to the custom indicator, so that it's single buffer will take values from either of 80/100 bars MA at different time, according to your predefined conditions. This way, your EA will just call one single custom indicator at all times.

The condition that should change the MA period cannot be predefined, but it is determined time by time based on events happening in the EA.

I am familiar with custom indicators, so if there is any way to change custom indicator variables starting from EA events, that could be a solution. Is there?

 
David986:

What is want to have a MA with a 80 bars period  in place ofthe old 100 bars MA on the Strategy Tester.

I tried this: to add a 80 bars MA using ChartIndicatorAdd() and delete the old 100 bars MA with ChartIndicatorDelete(), but ChartIndicatorDelete() seems to be ineffective So the result are two MAs running in my Strategy Tester...

It would be necessary to find a way to change the MA period during the backtest.

I already answered in this topic : you CAN NOT remove or change an indicator from the Strategy Tester, forget it and live with it.

Why "in place" ? that seems a useless complication. Anyway, if you really want to do it just send a command from the EA to the indicator and recalculate it. Use a custom event or a GVT for example.

 
David986:

The condition that should change the MA period cannot be predefined, but it is determined time by time based on events happening in the EA.

I am familiar with custom indicators, so if there is any way to change custom indicator variables starting from EA events, that could be a solution. Is there?

Technically possible, but it's not efficient and not natural (i.e. indicators aren't designed to behave this way).

In fact what you're looking at can be fulfilled either with separate indicators, or with a function within your EA instead.

 
Alain Verleyen:

I already answered in this topic : you CAN NOT remove or change an indicator from the Strategy Tester, forget it and live with it.

Why "in place" ? that seems a useless complication. Anyway, if you really want to do it just send a command from the EA to the indicator and recalculate it. Use a custom event or a GVT for example.

Ok.

I said "in place" because I need to change the indicator period frequently, so I cannot add lines on lines to the chart. I need to replace the old-set-MA with the new-set-MA everytime the EA changes its period.

As you suggested, I read this useful article on custom events and TGV: https://www.mql5.com/en/articles/39 

There is some work to do but it seems feasable. Before spending time on it, I just have a couple of questions:

- do custom events work in Strategy Tester mode?

- after implementing this code, will I need to launch backtests ONLY from MetaEditor debug mode, or can I still launch them from the Strategy Tester window?

Event handling in MQL5: Changing MA period on-the-fly
Event handling in MQL5: Changing MA period on-the-fly
  • www.mql5.com
This short article is devoted to one of the new MQL5 features of MetaTrader 5 platform, developed by MetaQuotes Software Corp. Perhaps this article is slightly late (it should have been issued in September-October 2009 - then it would be timely), but there were no similar articles on this topic. Moreover, in that time there were no such...
 
Alain Verleyen #:

I already answered in this topic : you CAN NOT remove or change an indicator from the Strategy Tester, forget it and live with it.

Why "in place" ? that seems a useless complication. Anyway, if you really want to do it just send a command from the EA to the indicator and recalculate it. Use a custom event or a GVT for example.

I have a neural network. It chooses between 8 different indicators. And 4 different timeframes. and 8 different time periods.

000 00 00 ( X 6 )

And this is done 6 times.
The idea is to choose 6 indicators and configure them, according to the inputs.
And this process is repeated every new bar.


If I start to create a new handle in each bar, I would need 1440 X 6 handles per year..... There must be a more elegant solution...

So nice and simple in MQL4

Reason: