Abu Dhabi + United Arab Emirates
Posts: 2 since Oct 2013
Thanks Given: 0
Thanks Received: 0
|
I'm using the Sylvain Vervoort Crossover Alert and wanted help in creating a column on my watchlist which shows the output for the number of bars since the condition was true. This is the code I'm using for my current column (it outputs the % difference between the current close and the the 8 EMA when the condition is true, I'm using this output to see if I'm too late to enter a position based on the move but it's kind of useless info. I'd prefer to see bars since last true). Appreciate any help on this!!!
input period = 55;
def price = (high+low+close)/3;
#-----Typical Price ZeroLag Triple Exponential Moving Average
def TMA1 = 3*expAverage(price,period)
-3*expAverage(expAverage(price,period),period)
+expAverage(expAverage(expAverage(price,period)
,period),period);
def TMA2 = 3*expAverage(TMA1,period)
-3*expAverage(expAverage(TMA1,period),period)
+expAverage(expAverage(expAverage(TMA1,period)
,period),period);
def difference = TMA1-TMA2;
def TypicalPriceZeroLagTEMA = TMA1+difference;
#------Heikin-Ashi Close ZeroLag Triple Exponential Moving Average
rec haopen = CompoundValue(1,((open[1]+high[1]
+low[1]+close[1])/4 + haopen[1])/2, hl2);
def haclose = ((open+high+low+close)/4+haopen
+max(high,haopen)+min(low,haopen))/4;
def HATMA1 = 3*expAverage(haclose,period)
-3*expAverage(expAverage(haclose,period),period)
+expAverage(expAverage(expAverage(haclose,period)
,period),period);
def HATMA2 = 3 * ExpAverage(HATMA1, period)
- 3 * ExpAverage(ExpAverage(HATMA1, period), period)
+ ExpAverage(ExpAverage(ExpAverage(HATMA1, period)
, period), period);
def HAdifference = HATMA1 - HATMA2;
def HeikinAshiZeroLagTEMA = HATMA1 + HAdifference;
def buySignal = if TypicalPriceZeroLagTEMA > HeikinAshiZeroLagTEMA and TypicalPriceZeroLagTEMA[1] <= HeikinAshiZeroLagTEMA[1] then 1 else 0;
def sellSignal = if TypicalPriceZeroLagTEMA < HeikinAshiZeroLagTEMA and TypicalPriceZeroLagTEMA[1] >= HeikinAshiZeroLagTEMA[1] then 1 else 0;
plot signalBuy = if buySignal then (Close - expAverage(Price,8))/ expAverage(Price,8) else double.nan;
|