I've been playing around with a day trading indicator. It consists of the ratio of advancing stocks to declining stocks (on the NYSE), Up volume vs. Down volume (NYSE) and the cumulative tick (also NYSE). Basically, if advancing stocks are above declining and the UpVolume for the day is higher than the down volume, this indicator will show you that the market is bullish. To filter these signals, I use the cumulative tick. If the tick lines up with the other two then the bars are painted green (when bullish) or red (when bearish). If the tick conflicts with the other indicators, the bar will be painted blue. Check out a five minute SPY chart:
This indicator is useful for day trading, as it can help you determine where the market internals are pushing the market and get you on board with the trend as it's developing intra-day. This indicator should not be used all by itself for entries and/or exits. It is not perfect, as there are plenty of times when the bars are green and prices just drop. I have been playing with it more as a filter. For example, if I'm trading using bollinger bands, I will look for long intra-day setups when the bars are green. Or if I'm looking to fade rallies using a stochastic oscillator, I'll look to sell an over bought signal if the bars are red. There are lots of possibilities to incorporate this and tweak it to your liking.
Here is the think script code for think or swim if anyone out there uses TOS.
//
def VolUp = close("$UVOL");
def VolDn = close("$DVOL");
def advancers = close("$ADVN");
def decliners = close("$DECN");
def BullVol = if volup>voldn then 1 else 0;
def BullAdv = if advancers>decliners then 1 else 0;
def BearVol = if volup<voldn then 1 else 0;
def BearAdv = if advancers<decliners then 1 else 0;
def BullMode = if BullVol and BullAdv then 1 else 0;
def BearMode = if BearVol and BearAdv then 1 else 0;
def upper = no;
input hidecumtick = yes;
input symbol = "$TICK";
input period = 20;
input smooth = 5;
input lookback = 4;
input filter = 300;
def p = period;
def i = barNumber();
def na = double.nan;
#input usetrend = {"No", default "Yes"};
def usetrend = yes;
rec htick = if IsNaN(high(symbol)) then htick[1] else high("$TICK") ;
rec ltick = if IsNaN(low(symbol)) then ltick[1] else low("$TICK");
rec avgh = if i == 1 then htick else Max(filter, avgh[1] + 2 / (p + 1) * (htick - avgh[1]));
rec avgl = if i == 1 then ltick else Min(-filter, avgl[1] + 2 / (p + 1) * (ltick - avgl[1]));
def hi = high("$TICK");
def lo = low("$TICK");
def Last = if IsNaN(close(symbol)[-1]) then close(symbol) else double.nan;
def amean = if IsNaN(close) then na else (avgh + avgl) / 2;
def trendmean = if usetrend AND (htick > avgh OR ltick < avgl) then amean else 0;
def bull = if htick > avgh then htick - avgh else 0;
def bear = if ltick < avgl then ltick - avgl else 0;
rec ctick = if i == 1 then 0 else if IsNaN(htick) OR IsNaN(ltick) then ctick[1] else ctick[1] + bull + bear + trendmean;
def ctickavg = ExpAverage(ctick, smooth);
def cumtick = if IsNaN(close) then na else ctickavg;
def nettick = if IsNaN(close) then na else ctick;
def zero = 0;
AssignPriceColor(if !upper then color.current else if cumtick > cumtick[lookback] AND ltick < avgl then color.green else if cumtick > cumtick[lookback] then color.gray else if cumtick < cumtick[lookback] AND htick > avgh then color.red else color.gray);
def hcumtick=if !hidecumtick then cumtick else na;
def hzero=if !hidecumtick then zero else na;
AddCloud(hcumtick, hzero );
def buy = if cumtick > cumtick[lookback] AND ltick < avgl then low - tickSize() else if cumtick > cumtick[lookback] then na else if cumtick < cumtick[lookback] AND htick > avgh then na else na;
def sell = if cumtick > cumtick[lookback] AND ltick < avgl then na else if cumtick > cumtick[lookback] then na else if cumtick < cumtick[lookback] AND htick > avgh then high + tickSize() else na;
def ahi = if IsNaN(close) then na else avgh;
def alo = if IsNaN(close) then na else avgl;
def hib = if hi < 0 then hi else na;
def lob = if lo > 0 then lo else na;
def phi = hi;
def plo = lo;
#plot zero=0;
#
# Formatting:
Def TickBull = (if cumtick > cumtick[lookback] then 1 else 0);
assignPriceColor(if BullMode and TickBull then color.Green else if BearMode then color.red else color.blue);
//
That's all folks. I have been working on quite a few indicators and strategies lately and would be happy to share more code if there is enough interest/demand. We'll see. Hope everyone's trading is going well.
TLT
*****Update*****
The above code has been fixed. A reader alerted me to a problem with the coding from the original post..not sure what happen but it appears to be a copy/paste error. The new code should work much better
This indicator is useful for day trading, as it can help you determine where the market internals are pushing the market and get you on board with the trend as it's developing intra-day. This indicator should not be used all by itself for entries and/or exits. It is not perfect, as there are plenty of times when the bars are green and prices just drop. I have been playing with it more as a filter. For example, if I'm trading using bollinger bands, I will look for long intra-day setups when the bars are green. Or if I'm looking to fade rallies using a stochastic oscillator, I'll look to sell an over bought signal if the bars are red. There are lots of possibilities to incorporate this and tweak it to your liking.
Here is the think script code for think or swim if anyone out there uses TOS.
//
def VolUp = close("$UVOL");
def VolDn = close("$DVOL");
def advancers = close("$ADVN");
def decliners = close("$DECN");
def BullVol = if volup>voldn then 1 else 0;
def BullAdv = if advancers>decliners then 1 else 0;
def BearVol = if volup<voldn then 1 else 0;
def BearAdv = if advancers<decliners then 1 else 0;
def BullMode = if BullVol and BullAdv then 1 else 0;
def BearMode = if BearVol and BearAdv then 1 else 0;
def upper = no;
input hidecumtick = yes;
input symbol = "$TICK";
input period = 20;
input smooth = 5;
input lookback = 4;
input filter = 300;
def p = period;
def i = barNumber();
def na = double.nan;
#input usetrend = {"No", default "Yes"};
def usetrend = yes;
rec htick = if IsNaN(high(symbol)) then htick[1] else high("$TICK") ;
rec ltick = if IsNaN(low(symbol)) then ltick[1] else low("$TICK");
rec avgh = if i == 1 then htick else Max(filter, avgh[1] + 2 / (p + 1) * (htick - avgh[1]));
rec avgl = if i == 1 then ltick else Min(-filter, avgl[1] + 2 / (p + 1) * (ltick - avgl[1]));
def hi = high("$TICK");
def lo = low("$TICK");
def Last = if IsNaN(close(symbol)[-1]) then close(symbol) else double.nan;
def amean = if IsNaN(close) then na else (avgh + avgl) / 2;
def trendmean = if usetrend AND (htick > avgh OR ltick < avgl) then amean else 0;
def bull = if htick > avgh then htick - avgh else 0;
def bear = if ltick < avgl then ltick - avgl else 0;
rec ctick = if i == 1 then 0 else if IsNaN(htick) OR IsNaN(ltick) then ctick[1] else ctick[1] + bull + bear + trendmean;
def ctickavg = ExpAverage(ctick, smooth);
def cumtick = if IsNaN(close) then na else ctickavg;
def nettick = if IsNaN(close) then na else ctick;
def zero = 0;
AssignPriceColor(if !upper then color.current else if cumtick > cumtick[lookback] AND ltick < avgl then color.green else if cumtick > cumtick[lookback] then color.gray else if cumtick < cumtick[lookback] AND htick > avgh then color.red else color.gray);
def hcumtick=if !hidecumtick then cumtick else na;
def hzero=if !hidecumtick then zero else na;
AddCloud(hcumtick, hzero );
def buy = if cumtick > cumtick[lookback] AND ltick < avgl then low - tickSize() else if cumtick > cumtick[lookback] then na else if cumtick < cumtick[lookback] AND htick > avgh then na else na;
def sell = if cumtick > cumtick[lookback] AND ltick < avgl then na else if cumtick > cumtick[lookback] then na else if cumtick < cumtick[lookback] AND htick > avgh then high + tickSize() else na;
def ahi = if IsNaN(close) then na else avgh;
def alo = if IsNaN(close) then na else avgl;
def hib = if hi < 0 then hi else na;
def lob = if lo > 0 then lo else na;
def phi = hi;
def plo = lo;
#plot zero=0;
#
# Formatting:
Def TickBull = (if cumtick > cumtick[lookback] then 1 else 0);
assignPriceColor(if BullMode and TickBull then color.Green else if BearMode then color.red else color.blue);
//
That's all folks. I have been working on quite a few indicators and strategies lately and would be happy to share more code if there is enough interest/demand. We'll see. Hope everyone's trading is going well.
TLT
*****Update*****
The above code has been fixed. A reader alerted me to a problem with the coding from the original post..not sure what happen but it appears to be a copy/paste error. The new code should work much better
6 comments:
I just happened upon this and find the idea rather interesting. Have you experimented at all with aggregating some of the def variables via rec variables then displaying as an oscillator on the bottom? I see a lot of promise here and if the answer is no, mind if I manipulate your code a bit and see what I can come up with?
Optntdr13,
Sorry for the delayed response..just noticed this comment today. Manipulate the code all you want..let me know if you come up with anything interesting.
TLT
Thanx for sharing your code, i know it must have been a lot of work
When I copy and paste the code, I am only getting green and red candles. I can see the blue briefly when I hit "apply" after adding the code for the new study, but it doesn't seem to work correctly.
Yeah, something change with ThinkorSwim and its thrown the code off. I'll see if I can update it and get it working.
Hi,
Do you have the ninjatrader script for the Index Trader Indicator?
Post a Comment