Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // buggy code
- declare upper;
- def dn=double.nan;
- input dojiOn = yes; #Doji
- input ema105On = yes; #EMA
- input rsiDailyOn = yes; #RSI Daily
- input rsiIntradayOn = yes; #RSI Intraday
- input nr7On = no; #NR7
- input lh3On = no; #LH3
- input hl3On = no; #HL3
- def hasVolume = volume > 1;
- def range = absvalue(high-low);
- def range3rd = (range * .299);
- def dir = if close>open then 1 else -1;
- def body = absvalue(close[0]-open[0]) <= (range * .17);
- def idd_upperWick = if dir==1 then (high-close<range3rd) else (high-open<range3rd);
- def idd_lowerWick = if dir==1 then (open-low>=range3rd*2) else (close-low>=range3rd*2);
- def idd_doji = idd_upperWick and idd_lowerWick and body and range < .75 and range > .05 and hasVolume;
- def isDragonflyDoji= idd_doji;
- def igd_upperWick = if dir==1 then (high-close>=range3rd*2) else (high-open>=range3rd*2);
- def igd_lowerWick = if dir==1 then (open-low<range3rd) else (close-low<range3rd);
- def igd_doji = igd_upperWick and igd_lowerWick and body and range < .75 and range > .05 and hasVolume;
- def isGravestoneDoji =igd_doji;
- def id_upperWick = if dir==1 then (high-close>=range3rd) else (high-open>=range3rd);
- def id_lowerWick = if dir==1 then (open-low>=range3rd) else (close-low>=range3rd);
- def id_doji = id_upperWick and id_lowerWick and body and range < .75 and range > .05 and hasVolume;
- def isDoji = id_doji;
- def diff=absvalue(high - low);
- def in7_a= diff[0];
- def in7_b= diff[1];
- def in7_c= diff[2];
- def in7_d= diff[3];
- def in7_e= diff[4];
- def in7_f= diff[5];
- def in7_g= diff[6];
- def in7_retval= in7_a <= in7_b and in7_a <= in7_c and in7_a <= in7_d and in7_a <= in7_e and in7_a <= in7_f and in7_a <= in7_g;
- def isNr7= if !isNan(in7_retval) and in7_retval then in7_a else 0;
- def threeHigherLows= low[0] >= low[1] and low[1] >= low[2];
- def threeLowerHighs= high[2] >= high[1] and high[1] >= high[0];
- def ema1 = MovingAverage(averagetype.exponential, close, 20); def sma1 = MovingAverage(averagetype.simple, close, 20);
- def ema2 = MovingAverage(averagetype.exponential, close, 50); def sma2 = MovingAverage(averagetype.simple, close, 50);
- def ema3 = MovingAverage(averagetype.exponential, close, 100); def sma3 = MovingAverage(averagetype.simple, close, 100);
- def ema4 = MovingAverage(averagetype.exponential, close, 200); def sma4 = MovingAverage(averagetype.simple, close, 200);
- def aboveMovingAvg = high > ema1 and high > ema2 and high > ema3 and high > ema4 and high > sma1 and high > sma2 and high > sma3; #and high > sma(close, 200)
- def belowMovingAvg = low < ema1 and low < ema2 and low < ema3 and low < ema4 and low < sma1 and low < sma2 and low < sma3; #and low < sma(close, 200)
- #Definitions
- def agr= getaggregationperiod();
- def isintraday = agr<86400000;
- def dojiCandle = isDoji[0] or isGravestoneDoji[0] or isDragonflyDoji[0];
- def ndx = if isDoji[2] or isGravestoneDoji[2] or isDragonflyDoji[2] then 2 else 1;
- def ndx1 = if isDoji[3] or isGravestoneDoji[3] or isDragonflyDoji[3] then 3 else ndx;
- def dojiDouble = (dojiCandle[0] and getvalue(dojiCandle,ndx1) ) and isintraday;
- def closeHigher = close[0] > getvalue(open,ndx1) and isintraday and hasVolume[0];
- def closeLower = close[0] < getvalue(open,ndx1) and isintraday and hasVolume[0];
- def lh3 = threeLowerHighs and isintraday and hasVolume[0];
- def hl3 = threeHigherLows and isintraday and hasVolume[0];
- def nr7Candle = isNr7[0] and isintraday and hasVolume[0];
- def rsi_fix = if close-close==0 then rsi(price=close, length= 14) else rsi_fix[1];
- def dojiOverbought = rsi_fix >= 60 and isintraday and hasVolume[0];
- def rsi_below = rsi_fix <= 50;
- def dojiOversold_ =rsi_below and isintraday and hasVolume[0];
- def dojiOversold = if (isnan( dojiOversold_)) then dn else dojiOversold_ ;
- def belowMAs = belowMovingAvg;
- input aggregation_displacer=1;
- #Guides
- def agr1 = if isintraday and agr<=aggregationperiod.THIRTY_MIN then aggregationperiod.THIRTY_MIN else agr;
- def ema105 = if !isintraday or agr>aggregationperiod.THIRTY_MIN then dn else movingaverage(averagetype.exponential, close(period=agr1), 105)[aggregation_displacer];
- plot ema105_= if !ema105On then dn else ema105; ema105_.SetDefaultColor(color.pink); ema105_.SetLineWeight(4);
- #def above105 = close >= ema105;
- #def below105 = close < ema105;
- def rsiDaily_ = rsi(price=close(period=aggregationperiod.DAY), length= 5)[aggregation_displacer];
- def rsiDaily = if !isnan(rsiDaily_) then rsiDaily_ else rsiDaily[1];
- plot xxDN= rsiDaily; xxDN.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE); xxDN.SetDefaultColor(color.red); xxDN.SetLineWeight(1);
- plot x= if rsi_below then 1 else 2; x.setpaintingstrategy(paintingstrategy.values_below);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement