Using a custom indicator in an EA

 

Hello Experts,

I am relatively new in using expert advisors, and I need your help in learning it better. I am trying to learn how to use custom indicators in EA.

I downloaded a custom indicator "parabolic_sub.mq4" from this site. I copied it to my experts/indicator folder and I compiled it. When I drag this custom indicator from my navigator to the chart, it correctly shows psar values.

When I call it from my EA, it always gives me zero. This is how I call it in a for loop

double psar[6];

For (i = 0; i <= 5; i++)

{

psar[i] = iCustom(NULL,0,"parabolic_sub",0.02,0.2,i);

print(psar[i]); <== It always seems to print "0".

}

I don't know why it doesn't print actual psar values. I appreciate your help. I am also attaching the custom indicator I am using.

Regards,

Jay

Files:
 

you did:

psar[i] = iCustom(NULL,0,"parabolic_sub",0.02,0.2,i);

.............................................................................^

you need:

iCustom(NULL,0,"parabolic_sub",0.02,0.2,<MODE>,<SarBuffer[index]>);

.................................................................^^^^^^

must be "Line index. Can be from 0 to 7 and must correspond with the index used by one of SetIndexBuffer functions." the indicator uses: "SetIndexBuffer(0, SarBuffer);"

.

iCustom(NULL,0,"parabolic_sub",0.02,0.2,<MODE>,<SarBuffer[index]>);

and------------------------------------------------------------^^^^^^^^^^^^

must be actual "Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago)." iow, if you use ,2 that is going to return to you SarBuffer[2]

.

eg:

psar[i] = iCustom(NULL,0,"parabolic_sub",0.02,0.2,0,shift);

shift is the index into the index buffer "SarBuffer[]"

.

your code loops 6 times - to load your psar[0..5] array.

.

your code MUST decide what values it wants from the indicators SarBuffer[] each time iCustom() called

IF it is SarBuffer[0..5] then ok... just do above replacing shift for i

.

ending up with:

psar[i] = iCustom(NULL,0,"parabolic_sub",0.02,0.2,0,i);

.

have-a-go... maybe it will work for you ;)

 
fbj wrote >>

you did:

psar[i] = iCustom(NULL,0,"parabolic_sub",0.02,0.2,i);

.............................................................................^

you need:

iCustom(NULL,0,"parabolic_sub",0.02,0.2,<MODE>,<SarBuffer[index]>);

.................................................................^^^^^^

must be "Line index. Can be from 0 to 7 and must correspond with the index used by one of SetIndexBuffer functions." the indicator uses: "SetIndexBuffer(0, SarBuffer);"

.

iCustom(NULL,0,"parabolic_sub",0.02,0.2,<MODE>,<SarBuffer[index]>);

and------------------------------------------------------------^^^^^^^^^^^^

must be actual "Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago)." iow, if you use ,2 that is going to return to you SarBuffer[2]

.

eg:

psar[i] = iCustom(NULL,0,"parabolic_sub",0.02,0.2,0,shift);

shift is the index into the index buffer "SarBuffer[]"

.

your code loops 6 times - to load your psar[0..5] array.

.

your code MUST decide what values it wants from the indicators SarBuffer[] each time iCustom() called

IF it is SarBuffer[0..5] then ok... just do above replacing shift for i

.

ending up with:

psar[i] = iCustom(NULL,0,"parabolic_sub",0.02,0.2,0,i);

.

have-a-go... maybe it will work for you ;)

Thank You so much! It does work like a champ

Reason: