MQL4 - automated forex trading   /  

Forum

Login | Register | Language: ru cn en
Buy Latest Technical Indicators in MetaTrader Market

Using a custom indicator in an EA

Back to topics list To post a new topic, please log in or register
avatar
3
jaypnarayan 2009.02.03 08:50
 

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

Attached files:
  parabolicosub.mq4  (7.44 KB)
 
UK political risk: The next market storm?
UK political risk: The next market storm?
Ronnie Mansolillo | 30 October 2014, 16:15 | Views: 93
The U.K. is facing its most uncertain political future for decades – some argue centuries. With just over six months until the general election on May 7, predicting who will hold the balance of power is becoming increasingly difficult – and worrying – for investors. The election will affect more than just U.
avatar
857
fbj 2009.02.03 22:19 #
 

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 ;)

 
avatar
3
jaypnarayan 2009.02.05 02:08 #
 
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

Back to topics list  

To add comments, please log in or register