Hi
I am trying to code an indicator which returns 1 when EMA(period) is higher than the high of current bar and returns -1 when is less than tha current low
I did some coding but its returning only ema value , not 1/-1
Can some body help please.
Thanks
neuron_sun
Hi
I am trying to code an indicator which returns 1 when EMA(period) is higher than the high of current bar and returns -1 when is less than tha current low
I did some coding but its returning only ema value , not 1/-1
Can some body help please.
Thanks
neuron_sun
Hi
Please post the code so we can help you.
Regards
Hi
Please post the code so we can help you.
Regards
Hi
This is my first code , so i don't know which value is taken by indicator_data
Custom indicator name is ema_left
basically I want an arrow when ema is greater than high and another arrow when its less than low
input int ema=3;
//code to get ema value -- this I think is correct
ema_left=iMA(NULL,0,3,0,meth,PRICE_CLOSE);
// I need help with
// code to return buybuffer arrow -- HELP needed
// code to return sell buffer arrow HELP needed
// Don't know which value to return
Thanks
neuron_sun
Hi
This is my first code , so i don't know which value is taken by indicator_data
Custom indicator name is ema_left
basically I want an arrow when ema is greater than high and another arrow when its less than low
input int ema=3;
//code to get ema value -- this I think is correct
ema_left=iMA(NULL,0,3,0,meth,PRICE_CLOSE);
// I need help with
// code to return buybuffer arrow -- HELP needed
// code to return sell buffer arrow HELP needed
// Don't know which value to return
Thanks
neuron_sun
Hi there!
To code this properly I give you some sugestions:
- declare an indicator handle below the buffers declaration, like this:
int handle_ema_left;
- Initiate the handle in the OnInit() fuction, like this:
handle_ema_left = iMA(NULL,0,ema,0,meth,PRICE_CLOSE);
- Because your using a discrete arrow output it's recommended to set an empty value
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);
- In the OnCalculate() fuction try this code and modify to your needs:
//--- check for rates total
if(rates_total<ema+1)
return(0); // not enough bars for calculation
//--- not all data may be calculated
int calculated=BarsCalculated(handle_ema_left);
if(calculated<rates_total)
{
Print("Not all data of ema_left is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
//--- we may not need all data
int to_copy;
double ema_left[];
if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
else
{
to_copy=rates_total-prev_calculated;
if(prev_calculated>0) to_copy++;
}
//--- get ema_left buffer
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(handle_ema_left,0,0,to_copy,ema_left)<=0)
{
Print("Getting EMA has failed! Error",GetLastError());
return(0);
}
//--- calculations
int i,limit;
//--- first calculation or number of bars was changed
if(prev_calculated<=ema+1)
{
for(i=0;i<ema+1;i++)
{
buyBuffer[i]=0.0;
sellBuffer[i]=0.0;
}
limit=ema+1;
}
else limit=prev_calculated-1;
//--- main loop of calculations
for(i=limit+1; i<rates_total && !IsStopped(); i++)
{
if(ema_left[i]>High[i] ) sellBuffer[i]=-1.0; //or any value you want beside 0.0
else sellBuffer[i]=0.0;
if(ema_left[i]<Low[i] ) buyBuffer[i]=1.0; //or any value you want beside 0.0
else buyBuffer[i]=0.0;
}
//--- return value of prev_calculated for next call
return(rates_total);
Hope it helps!
Bye
Hi there!
To code this properly I give you some sugestions:
- declare an indicator handle below the buffers declaration, like this:
int handle_ema_left;
- Initiate the handle in the OnInit() fuction, like this:
handle_ema_left = iMA(NULL,0,ema,0,meth,PRICE_CLOSE);
- Because your using a discrete arrow output it's recommended to set an empty value
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);
- In the OnCalculate() fuction try this code and modify to your needs:
//--- check for rates total
if(rates_total<ema+1)
return(0); // not enough bars for calculation
//--- not all data may be calculated
int calculated=BarsCalculated(handle_ema_left);
if(calculated<rates_total)
{
Print("Not all data of ema_left is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
//--- we may not need all data
int to_copy;
double ema_left[];
if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
else
{
to_copy=rates_total-prev_calculated;
if(prev_calculated>0) to_copy++;
}
//--- get ema_left buffer
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(handle_ema_left,0,0,to_copy,ema_left)<=0)
{
Print("Getting EMA has failed! Error",GetLastError());
return(0);
}
//--- calculations
int i,limit;
//--- first calculation or number of bars was changed
if(prev_calculated<=ema+1)
{
for(i=0;i<ema+1;i++)
{
buyBuffer[i]=0.0;
sellBuffer[i]=0.0;
}
limit=ema+1;
}
else limit=prev_calculated-1;
//--- main loop of calculations
for(i=limit+1; i<rates_total && !IsStopped(); i++)
{
if(ema_left[i]>High[i] ) sellBuffer[i]=-1.0; //or any value you want beside 0.0
else sellBuffer[i]=0.0;
if(ema_left[i]<Low[i] ) buyBuffer[i]=1.0; //or any value you want beside 0.0
else buyBuffer[i]=0.0;
}
//--- return value of prev_calculated for next call
return(rates_total);
Hope it helps!
Bye
Hi
It worked , thanks a ton!!!
neuron_sun
Please use SRC button to post your code. It will make your codes much easier to read for other forumer.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi
I am trying to code an indicator which returns 1 when EMA(period) is higher than the high of current bar and returns -1 when is less than tha current low
I did some coding but its returning only ema value , not 1/-1
Can some body help please.
Thanks
neuron_sun