Skip to content

Instantly share code, notes, and snippets.

@tayyebi
Last active August 20, 2021 11:39
Show Gist options
  • Save tayyebi/a543ac022e638544efe2cc366335fddd to your computer and use it in GitHub Desktop.
Save tayyebi/a543ac022e638544efe2cc366335fddd to your computer and use it in GitHub Desktop.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tayyebi
//@version=4
study(shorttitle="TYYI", title="Tayyip Strategy", overlay=true, resolution="")
// strategy("Tayyebi's Strategy", overlay=true, margin_long=1, margin_short=1)
// BB
length = input(20, minval=1)
src = input(close, title="Source")
mult = input(2.0, minval=0.001, maxval=50, title="StdDev")
basis = sma(src, length)
dev = mult * stdev(src, length)
upper = basis + dev
lower = basis - dev
offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)
// plot(basis, "Basis", color=#FF6D00, offset = offset)
// plot(upper, "Upper", color=#2962FF, offset = offset)
// plot(lower, "Lower", color=#2962FF, offset = offset)
// EMA
len = input(9, minval=1, title="Length")
ave = ema(src, len)
plot(ave, title="EMA", color=color.purple, offset=offset)
// Signals
buyCondition = high > lower and close[1] < lower and ave < basis // and close > open
plotshape(buyCondition, location=location.belowbar, color=color.orange, size=size.tiny, style=shape.triangleup)
sellCondition = low < upper and close[1] > upper and ave > basis // and close < open
plotshape(sellCondition, location=location.abovebar, color=color.red, size=size.tiny, style=shape.triangledown)
// Strategy
// // strategy.close("sell", when=high<highest(high, 20)[1])
// // strategy.entry("buy", strategy.long, stop = close[1], limit=ave, when=buyCondition)
// strategy.entry("buy", strategy.long, when=buyCondition, qty=10)
// strategy.close("buy", when=high>=ave)
// strategy.entry("sell", strategy.short, when=sellCondition, qty=10)
// strategy.close("sell", when=low<=ave)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment