Jump to content

[HELP] With small coding problem!


EAcollector

Recommended Posts

Hi guys. I have this indicator of La Selle Street in .els need it in mql4 now for my ea. Its real basic but cant get it to work right.

 

For the first 3 bars the regEMA buffer should equal the close price from there it should go over and do the calculation as u need regEMA[2] for the calculation thus first 3 bars must equal close. Here is my code, help would be gladly appreciated!!!

 

extern int EMA_Length = 22;

double PctBelow = 0.5;

double PctAbove = 0.5;

 

double Alpha=0.0, PctBelowFactor=0.0, PctAboveFactor=0.0;

int start()

{

int counted_bars=IndicatorCounted();

int limit;

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

if (counted_bars > 0) counted_bars--;

limit = Bars-counted_bars;

 

Alpha = 2/(EMA_Length + 1);

PctBelowFactor = (1 - (0.5*0.01));

PctAboveFactor = (1 + (0.5*0.01));

 

for (int i = Bars; i >= 0; i++)

{

if (i > 3)

{

regEMABuffer = (regEMABuffer[i+1]*(1+2*0.5) + Alpha*(Close-regEMABuffer[i+1]) - 0.5*regEMABuffer[i+2]) /1.5;

}

else

{

regEMABuffer = Close;

}

 

lowerRemaBuffer = regEMABuffer * PctBelowFactor;

upperRemaBuffer = regEMABuffer * PctAboveFactor;

}

return(0);

}

 

It should be flowing bands mine is all zigzag and it never touches the highs of the bar and that's kind of the idea to define oversold and overbought conditions, and it works quite nicely.

Link to comment
Share on other sites

  • 1 month later...

Here you go, no money required :)

 

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

//| AlphaEMAband.mq4 |

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

#property copyright ""

#property link ""

#property version "1.00"

#property indicator_chart_window

#property indicator_buffers 3

#property indicator_color1 Green

#property indicator_color2 Red

#property indicator_color3 Blue

 

extern int EMA_Length = 22;

double PctBelow = 0.5;

double PctAbove = 0.5;

double PctBelowFactor = 0.0;

double PctAboveFactor = 0.0;

double regEMAbuffer[];

double lowerEMAbuffer[];

double upperEMAbuffer[];

 

 

int init()

{

SetIndexBuffer(0, regEMAbuffer);

SetIndexStyle(0, DRAW_NONE);

SetIndexBuffer(1, lowerEMAbuffer);

SetIndexStyle(1, DRAW_LINE);

SetIndexBuffer(2, upperEMAbuffer);

SetIndexStyle(2, DRAW_LINE);

return(0);

}

 

int start()

{

double Alpha = 2/(EMA_Length + 1);

PctBelowFactor = (1 - (0.5*0.01));

PctAboveFactor = (1 + (0.5*0.01));

 

for(int i=Bars-EMA_Length; i>=0; i--)

{

if (i < 3)

{

regEMAbuffer = (regEMAbuffer[i+1]*(1+2*0.5) + Alpha*(Close-regEMAbuffer[i+1]) - 0.5 * regEMAbuffer[i+2]) /1.5;

}

else { regEMAbuffer = Close; }

 

lowerEMAbuffer = regEMAbuffer * PctBelowFactor;

upperEMAbuffer = regEMAbuffer * PctAboveFactor;

}

return(0);

}

Edited by maximillian
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...