Skip to content

Instantly share code, notes, and snippets.

@pequet
Last active July 4, 2018 19:30
Show Gist options
  • Save pequet/3bcec972976f5a215241e4d30ef07c40 to your computer and use it in GitHub Desktop.
Save pequet/3bcec972976f5a215241e4d30ef07c40 to your computer and use it in GitHub Desktop.
// 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.1", shorttitle="Doji Gaps", precision=8, overlay=true, scale=scale.right)
rrInput = input(2.0, title="Risk/Reward")
// doji
IsDoji(n) =>
(high[n] - low[n]) / abs(open[n] - close[n]) > 50
// 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
confirmedCond = dojiGapCond[1] == 1 and close > close[1] ? 1 : dojiGapCond[1] == -1 and close < close[1] ? -1 : 0
// if confirmed enter there and 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
bgcolor(dojiGapCond==1 ? green : dojiGapCond==-1 ? red : na, transp=50)
plotchar(entry, color=green, location=location.absolute, char="⟵", transp=0, style=circles, offset=0)
plotchar(stop, color=red, location=location.absolute, char="⟵", transp=0, style=circles, offset=0)
plotchar(target, color=green, location=location.absolute, char="⟵", transp=0, style=circles, offset=0)
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