How to reinitialize Custom Indicator variables?

 

Hi,

I've created an adaptive custom indicator based on RSI and Stochastic that analyzes the immediate previous history and then chooses parameter settings based on that analysis. I then created an EA that uses that custom indicator to make trades. Its working great except for one thing: Once the indicator chooses the settings, it uses them for EVERY trade.

I want the indicator to reanalyze the settings again once a trade closes in the EA. I have created some globalvariables so that the EA can tell the indicator when a trade opens and closes...and that works....but I can't seem to get the indicator to refresh and start over when it receives the message that a trade has closed. How can I get the indicator to restart the analyze function with initialized variables (Basically startover), when the EA closes the trade?

I hope that's clear.

Any Ideas?

 
ThemBonez:
Hi,

I've created an adaptive custom indicator based on RSI and Stochastic that analyzes the immediate previous history and then chooses parameter settings based on that analysis. I then created an EA that uses that custom indicator to make trades. Its working great except for one thing: Once the indicator chooses the settings, it uses them for EVERY trade.

I want the indicator to reanalyze the settings again once a trade closes in the EA. I have created some globalvariables so that the EA can tell the indicator when a trade opens and closes...and that works....but I can't seem to get the indicator to refresh and start over when it receives the message that a trade has closed. How can I get the indicator to restart the analyze function with initialized variables (Basically startover), when the EA closes the trade?

I hope that's clear.

Any Ideas?

As soon as you change any of the parameters in the call to the custom indicator, new instance to the indicator will be created (that will be the same as if you reset it - you can add one dummy parameter to it, and when you decide to change parameters just change the value of that dummy parameter to some value not used before).

The problems are that you can not reset the existing instance and that that instance is going to stay loaded in memory until you unload the calling EA from the chart

 

The indicator is very good at monitoring price volatility, trend and range and selecting parameter settings accordingly. So as the EA is running and the market dynamics are changing, the intention is that the indicator changes its parameters to match the current market.

Therefore, everytime the EA closes a trade, I want the indicator to reassess and change, if necessary.

Are you telling me with :

The problems are that you can not reset the existing instance and that that instance is going to stay loaded in memory until you unload the calling EA from the chart

That this is not possible while the EA is running? If it is possible....any ideas?

Thanx

ThemBonez

 
ThemBonez:
The indicator is very good at monitoring price volatility, trend and range and selecting parameter settings accordingly. So as the EA is running and the market dynamics are changing, the intention is that the indicator changes its parameters to match the current market.

Therefore, everytime the EA closes a trade, I want the indicator to reassess and change, if necessary.

Are you telling me with :

That this is not possible while the EA is running? If it is possible....any ideas?

Thanx

ThemBonez

ThemBonez

Read this part :

As soon as you change any of the parameters in the call to the custom indicator, new instance to the indicator will be created

That is the same as if you have reset the indicator. Except that you did not reset it but a new instance of indicator in memory is created, and from then on you access that new instance.

 

If I sent you the code for the Adaptive Indicator would you take a look for me. I don't think the issue is in the EA....I think its in the indicator and I can't figure it out.

 
ThemBonez:
If I sent you the code for the Adaptive Indicator would you take a look for me. I don't think the issue is in the EA....I think its in the indicator and I can't figure it out.

I did not say that there is some problem with the indicator

Please read that again : if you add one dummy parameter and you change its value using the iCustom() call, the effect will be the same as you have reset it

Like this

static int dummy = 0; if (someCondition) dummy++;

indicatorValue = iCustom(NULL,0,"custom indicator",....,dummy,0,0);

And whenever the dummy value is changed there will be a new instance of the indicator - the same as if you have reset it

______________________

But read the drawbacks of the way how metatrader treats indicators in those cases too

 

And another benefit of MLaden's suggestion is that you do not need to use Global Variables to communicate between the EA and the indicator. Just use:

if(TradeClosed == True) dummy++;

Reason: