Created
December 1, 2013 07:17
-
-
Save currencysecrets/7729483 to your computer and use it in GitHub Desktop.
"Trade with the trend!" Here's my method on determining the ***weekly*** trend. The numbers returned correspond to the following detail:
++ A positive number is how many bars the instrument has been in an UP trend
++ A negative number is how many bars the instrument has been in a DOWN trend
++ A zero denotes that the instrument is currently NOT …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int getWeeklyTrend( string sym ) { | |
int per = PERIOD_W1, | |
b = iBars( sym, per ) - 3, | |
isLong, pk0, pk1, pk2, tr0, tr1, tr2, i; | |
for ( i = b; i > 0; i -= 1 ) { | |
if ( isLong <= 0 ) { | |
if ( tr1 > 0 && iHigh( sym, per, i ) > iHigh( sym, per, pk0 ) && iLow( sym, per, tr0 ) > iLow( sym, per, tr1 ) ) { | |
isLong = i; | |
} else if ( iHigh( sym, per, i ) > iHigh( sym, per, pk0 ) ) { | |
isLong = 0; | |
} | |
} | |
if ( isLong >= 0 ) { | |
if ( pk1 > 0 && iLow( sym, per, i ) < iLow( sym, per, tr0 ) && iHigh( sym, per, pk0 ) < iHigh( sym, per, pk1 ) ) { | |
isLong = -i; | |
} else if ( iLow( sym, per, i ) < iLow( sym, per, tr0 ) ) { | |
isLong = 0; | |
} | |
} | |
if ( iHigh( sym, per, i+2 ) <= iHigh( sym, per, i+1 ) && iHigh( sym, per, i+1 ) > iHigh( sym, per, i ) ) { | |
pk1 = pk0; | |
pk0 = i+1; | |
} | |
if ( iLow( sym, per, i+2 ) >= iLow( sym, per, i+1 ) && iLow( sym, per, i+1 ) < iLow( sym, per, i ) ) { | |
tr1 = tr0; | |
tr0 = i+1; | |
} | |
} | |
return( isLong ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment