I am no EL expert here, but I think you should try the CountIf function:
example based on builit in MACD LE strategy of TS with added CountIf; you may need to play with Value1 and Condition1 test length to get the logic right.
Also search for this function in TS help and TS forum.
 |
|
 |
 |
|
 |
|
inputs: FastLength( 12 ), SlowLength( 26 ), MACDLength( 9 ) ;
variables: MyMACD( 0 ), MACDAvg( 0 ), MACDDiff( 0 ) ;
MyMACD = MACD( Close, FastLength, SlowLength ) ;
MACDAvg = XAverage( MyMACD, MACDLength ) ;
MACDDiff = MyMACD - MACDAvg ;
Condition1 = MACDDiff crosses below 0;
Value1 = CountIF(Condition1, 10); // CountIF returns A numeric value containing the number of true test condition occurrences for the current bar.
if Value1>0 and CurrentBar > 2 and MACDDiff crosses over 0 then { CB > 2 check used to
avoid spurious cross confirmation at CB = 2 (at CB = 1, MyMACD and MACDAvg will be
the same) }
Buy ( "MacdLE" ) next bar at market ;
{ ** Copyright (c) 2005 TradeStation Technologies, Inc. All rights reserved. **
** TradeStation reserves the right to modify or overwrite this strategy component
with each release. ** } |
|
 |
|
 |
|