Last active
October 22, 2020 00:26
-
-
Save tomasbarrios/bae970d23e7d76761b08f369fae0018e 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
// from https://www.tradingview.com/script/XZcsLIEW-Ichimoku-Kinko-Hyo-Basic-Strategy/ | |
strategy("Ichimoku Kinko Hyo: Basic Strategy", overlay=true) | |
//Inputs | |
ts_bars = input(9, minval=1, title="Tenkan-Sen Bars") | |
ks_bars = input(26, minval=1, title="Kijun-Sen Bars") | |
ssb_bars = input(52, minval=1, title="Senkou-Span B Bars") | |
cs_offset = input(26, minval=1, title="Chikou-Span Offset") | |
ss_offset = input(26, minval=1, title="Senkou-Span Offset") | |
long_entry = input(true, title="Long Entry") | |
short_entry = input(true, title="Short Entry") | |
middle(len) => avg(lowest(len), highest(len)) | |
// Ichimoku Components | |
tenkan = middle(ts_bars) | |
kijun = middle(ks_bars) | |
senkouA = avg(tenkan, kijun) | |
senkouB = middle(ssb_bars) | |
// Plot Ichimoku Kinko Hyo | |
plot(tenkan, color=#0496ff, title="Tenkan-Sen") | |
plot(kijun, color=#991515, title="Kijun-Sen") | |
plot(close, offset=-cs_offset+1, color=#459915, title="Chikou-Span") | |
sa=plot(senkouA, offset=ss_offset-1, color=green, title="Senkou-Span A") | |
sb=plot(senkouB, offset=ss_offset-1, color=red, title="Senkou-Span B") | |
fill(sa, sb, color = senkouA > senkouB ? green : red, title="Cloud color") | |
ss_high = max(senkouA[ss_offset-1], senkouB[ss_offset-1]) | |
ss_low = min(senkouA[ss_offset-1], senkouB[ss_offset-1]) | |
// Entry/Exit Signals | |
tk_cross_bull = tenkan > kijun | |
tk_cross_bear = tenkan < kijun | |
cs_cross_bull = mom(close, cs_offset-1) > 0 | |
cs_cross_bear = mom(close, cs_offset-1) < 0 | |
price_above_kumo = close > ss_high | |
price_below_kumo = close < ss_low | |
bullish = tk_cross_bull and cs_cross_bull and price_above_kumo | |
bearish = tk_cross_bear and cs_cross_bear and price_below_kumo | |
strategy.entry("Long", strategy.long, when=bullish and long_entry) | |
strategy.entry("Short", strategy.short, when=bearish and short_entry) | |
strategy.close("Long", when=bearish and not short_entry) | |
strategy.close("Short", when=bullish and not long_entry) |
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
//@version=4 | |
strategy("My Strategy", overlay=true) | |
longCondition = crossover(sma(close, 14), sma(close, 28)) | |
if (longCondition) | |
strategy.entry("My Long Entry Id", strategy.long) | |
shortCondition = crossunder(sma(close, 14), sma(close, 28)) | |
if (shortCondition) | |
strategy.entry("My Short Entry Id", strategy.short) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment