Having trouble with code for Schaff indicator in EA

 

Hi guys,

I'm writing an EA that looks for a Stochastic cross as 1st trigger, then looks for a gap between a 10 and 30 EMA as a 2nd trigger.

I have this code working ok.

finally it qualifies the Schaff indicator and this is where I'm having a few issues.

Note: this is for a long trade only

The buy range of the Schaff is: > 20.0 (that's easy as per below) and can go > 99.0 but only for a maximum of 10 bars (H1 chart)

code so far.

double Schaff = iCustom(NULL, NULL, "STC",26,78,780,0,1)

if((Schaff >= 20.0) && (Schaff <= Schaff99) //Schaff99 code below.

T4 = 1; // is the true trading condition

*********************

int schaff99;
{
schaff99 = 0;
for ( int bar = 1; bar <= 10; bar++ ) {
if (iCustom(NULL, NULL, "STC",26,78,780,0,1)>=99.0)
{
if(schaff99 > 10);
{
T4 = 0;
}
}

}
return(schaff99);

}

Tried while loop and setting Schaff <=99 with shift set to 10, so it would look back 10 bars - only problem was it would only buy >99.

Any ideas very welcome. This has been frustrating me all Christmas break.

pjonz2008

 
I cannot follow your code that well as you did not use the "SRC" button when posting. Anyway, you appear to be using scaff99 and Scaff99 as variables. MQL is case sensitive. Also you set schaff99 to 0. I cannot see you ever changing its value from zero.
 
in addition to rocketman99

Y testing 10 times the same thing

for ( int bar = 1; bar <= 10; bar++ ) {
if (iCustom(NULL, NULL, "STC",26,78,780,0,1)>=99.0) 

maybe u meant

for ( int bar = 1; bar <= 10; bar++ ) {
if (iCustom(NULL, NULL, "STC",26,78,780,0,bar)>=99.0) 
 
I would also like to add that although the Schaff indicator looks impressive onscreen my own test results where quite poor. I think it suffers the same lookback and repainting issues as with the ZigZig indicator.
Reason: