Created
July 7, 2018 23:32
-
-
Save pequet/9eae36471829790f3dbae59a3ad69385 to your computer and use it in GitHub Desktop.
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
// Created by @pequet (https://www.tradingview.com/u/pequet) July 4 2018 | |
// https://github.com/pequet/ | |
// @version=3 | |
// Reference: https://www.tradingview.com/x/j7TADzBK/ | |
study("Doji Gaps v0.0.2", shorttitle="Doji Gaps", precision=8, overlay=false, scale=scale.right) | |
dojiInput = input(20, title="Doji is defined by (High-Low) / Body greater than") | |
rrInput = input(2.0, step=0.5, title="Risk/Reward Ratio") | |
// doji | |
IsDoji(n) => | |
(high[n] - low[n]) / abs(open[n] - close[n]) > dojiInput | |
// gap | |
IsGap(n) => | |
max(open[n+1], close[n+1]) < min(open[n], close[n]) ? 1 : min(open[n+1], close[n+1]) > max(open[n], close[n]) ? -1 : 0 | |
dojiGapCond = IsDoji(1) ? IsGap(0) : 0 | |
// alert: doji, gap, and this candle breaking over the doji high/low | |
activatedCond = dojiGapCond == 1 and close > high[1] ? 1 : dojiGapCond == -1 and close < low[1] ? -1 : 0 | |
// confirmed: look for break of the candle after gap high/low | |
confirmedCond = activatedCond[1] == 1 and high > high[1] ? 1 : activatedCond[1] == -1 and low < low[1] ? -1 : 0 | |
// risk to bottom of doji | |
entry = confirmedCond==1 ? high[1] : confirmedCond==-1 ? low[1] : na | |
stop = confirmedCond==1 ? low[2] : confirmedCond==-1 ? high[2] : na | |
target = confirmedCond!= 0 ? entry + rrInput * (entry - stop) : na | |
_candleColor = open > close ? silver : gray | |
_wickColor = gray | |
plotcandle(open, high, low, close, color=_candleColor, wickcolor=_wickColor, title="") | |
// confirmed | |
stopPlotObj = plot(not na(stop) ? stop : not na(stop[1]) ? stop[1] : na, color=color(red, 100), style=linebr, linewidth=2, title="Stop", offset=0) | |
targetPlotObj = plot(not na(target) ? target : not na(target[1]) ? target[1] : na, color=color(green, 100), style=linebr, linewidth=2, title="Target", offset=0) | |
plotshape(activatedCond!=0 ? avg(open, close[1]) : na, location=location.absolute, style=shape.circle, color=activatedCond==1 ? green : activatedCond==-1 ? red : na, textcolor=activatedCond==1 ? green : activatedCond==-1 ? red : na, size=size.small, title="Doji Gap", text="Doji Gap", offset=0) | |
// watch entry level | |
entryPlotObj = plot(activatedCond==1 ? high : activatedCond==-1 ? low : activatedCond[1]==1 ? high[1] : activatedCond[1]==-1 ? low[1] : activatedCond[2]==1 ? high[2] : activatedCond[2]==-1 ? low[2] : na, color=green, transp=0, style=linebr, linewidth=2, title="Entry") | |
fill(stopPlotObj, entryPlotObj, color=red, transp=50) | |
fill(targetPlotObj, entryPlotObj, color=green, transp=50) | |
alertcondition(activatedCond!= 0, title='Doji gap (potential)', message='Doji gap! (potential)') | |
alertcondition(confirmedCond!= 0, title='Doji gap', message='Doji gap!') | |
// - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment