Jump to content

Recommended Posts

Posted (edited)

Hello friends this is checkmail and have coded an ema cross bar histogram with reference from other available indicators, but am having an problem.

 

Unbalanced paranthesis , / end of the program.etc stuff, just one error.

 

After checking the code am suspecting some mistake in mine calculations, would anybody here try to correct it, also want to display signal on charts (up/down).

 

 

Here is the code :

 

 

#property copyright "EMACROSSHISTOGRAM"

#property link "emacrosshist"

 

//---- indicator settings

#property indicator_separate_window

#property indicator_minimum -0.5

#property indicator_maximum 1.05

#property indicator_buffers 2

 

 

#property indicator_color1 Blue

#property indicator_color2 Red

 

 

 

//---- indicator parameters

 

 

//---- indicator buffers

double UpBuffer1[];

double UpBuffer2[];

 

double ind_buffer1[];

 

extern int ema1 = 10;

extern int ema2 = 25;

 

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

IndicatorBuffers(3);

//---- drawing settings

SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);

SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2);

 

 

SetIndexBuffer(0,UpBuffer1);

SetIndexBuffer(1,UpBuffer2);

IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);

 

SetIndexBuffer(2,ind_buffer1);

 

 

//---- name for DataWindow and indicator subwindow label

IndicatorShortName("EMACROSSHIST");

//---- initialization done

return(0);

}

//+------------------------------------------------------------------+

//| Moving Average of Oscillator |

//+------------------------------------------------------------------+

int start()

{

int limit;

int trend;

double current,prev;

int counted_bars=IndicatorCounted();

//---- check for possible errors

if(counted_bars<0) return(-1);

//---- last counted bar will be recounted

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

 

//---- Bar counted in the 1-st add buffer

 

for(int i=0; i<limit; i++)

ind_buffer1=iMA(NULL,0,ema1,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,ema2,0,MODE_EMA,PRICE_CLOSE,i);

 

 

for(i=limit-1; i>=0; i--)

{

UpBuffer1=0;

UpBuffer2=0;

 

current=ind_buffer1;

prev=ind_buffer1[i+1];

 

 

if((current>prev)&&(current>0)) trend = 2;

if((current>prev)&&((current<0))trend = 1;

if((current<prev)) trend = 1;

 

if(trend==2)

{

UpBuffer1=1;

UpBuffer2=0;

 

}

if(trend==1)

{

UpBuffer1=0;

UpBuffer2=1;

 

}

 

}

//---- done

return(0);

}

//+------------------------------------------------------------------+

 

 

:)

Edited by checkmail

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×
×
  • Create New...