Custom Indicator Variables from an EA

 

I've got a custom indicator with an external variable that I would like to be able to change and backtest through an EA.


How can I define that variable in an EA so that I can change the value in the EA so that it is reflected in the indicator?

 
mixtermind:

I've got a custom indicator with an external variable that I would like to be able to change and backtest through an EA.


How can I define that variable in an EA so that I can change the value in the EA so that it is reflected in the indicator?

The variable name is Lookback. When I use GlobalVariableGet it outputs 0 as it's value. The value in the indicator is NOT 0, it's 10. I've verifed through a comment that the Global Variable does exist. Why is the GlobalVariableGet giving the wrong value?


// check variable before use
if(!GlobalVariableCheck("Lookback"))
{
string exists="Yes";
double value=GlobalVariableGet("Lookback");
}
Comment("Gann: ",ind1[0]," ",ind1[1]," ",ind1[2],"\n","Bars: ",Open[0]," ",Close[1]," ",Close[2],"\n",exists," ",value);

 

See here 'SVOS Multi-Indicator EA'

for an example of calling a custom indicator with iCustom() from an EA

Good Luck

-BB-

 
BarrowBoy:

See here 'SVOS Multi-Indicator EA'

for an example of calling a custom indicator with iCustom() from an EA

Good Luck

-BB-

The problem is that the variable in question is not a function of the Custom Indicator but of an iMA call made within the indicator. The variable can't be called as a parameter of iCustom, hence the difficulty.

 
mixtermind:

The problem is that the variable in question is not a function of the Custom Indicator but of an iMA call made within the indicator. The variable can't be called as a parameter of iCustom, hence the difficulty.

I've tried to integrate the indicator code into my EA thereby bypassing the need to port the variable. Unfornately it doesn't seem to be working. Here's the code:


int start()

{

int Lookback = 10;
double ssl[],Hld,Hlv;

for(int i=Bars-Lookback;i>=0;i--)
{
if(Close[i]>iMA(Symbol(),0,Lookback,0,MODE_SMA,PRICE_HIGH,i+1))
Hld=1;
else
{
if(Close[i]<iMA(Symbol(),0,Lookback,0,MODE_SMA,PRICE_LOW,i+1))
Hld=-1;
else
Hld=0;
}
if(Hld!=0)
Hlv=Hld;
if(Hlv==-1)
ssl[i]=iMA(Symbol(),0,Lookback,0,MODE_SMA,PRICE_HIGH,i+1);
else
ssl[i]=iMA(Symbol(),0,Lookback,0,MODE_SMA,PRICE_LOW,i+1);
}

}

 

If you have an indicator that is working OK, just use iCustom and keep the EA simpler and with better performance than putting the indi code in the EA!

-BB-

 
BarrowBoy:

If you have an indicator that is working OK, just use iCustom and keep the EA simpler and with better performance than putting the indi code in the EA!

-BB-

Back to my original problem:


How do I affect variables in my custom indicator that can't be accessed via iCustom?

 
mixtermind:

Back to my original problem:


How do I affect variables in my custom indicator that can't be accessed via iCustom?

... - Parameters set (if necessary). The passed parameters and their order must correspond with the desclaration order and the type of extern variables of the custom indicator.



I see this in the documentation. How do I choose the parameters to be passed to the indicator?

 

If its an extern, as in "I've got a custom indicator with an external variable" it can be accessed by iCustom - unless its got more than 64 externs!

You could have a version of the indi with the defaults changed to what the EA will normally use, then the values dont have to be passed by iCustom - defaults are then assumed

FWIW

-BB-

 
BarrowBoy:

If its an extern, as in "I've got a custom indicator with an external variable" it can be accessed by iCustom - unless its got more than 64 externs!

You could have a version of the indi with the defaults changed to what the EA will normally use, then the values dont have to be passed by iCustom - defaults are then assumed

FWIW

-BB-

Thanks for the help. I figured out the whole extern variable to paramater deal a few minutes ago. It works like a charm. Now I've got a way to backtest the indicator via the EA.


Thanks again.


Ken

Reason: