Last active
September 19, 2018 02:49
-
-
Save sophie-eihpos/ba07fabd514037e2f9ffea15a0e2b4fc to your computer and use it in GitHub Desktop.
1HSetups
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=2 | |
strategy(title='Beat the Odds 1H setups', shorttitle='1H setups', overlay=true, pyramiding=0, initial_capital=1000, currency=currency.USD) | |
// best input value is 540 (default) for BTCUSD | |
//----------------- EMA 1 ---------------------------------------------------------------------------// | |
src0 = close, len0 = input(10, minval=1, title="Fast EMA Cross") | |
emaFast = ema(src0, len0) | |
direction = rising(emaFast, 2) ? +1 : falling(emaFast, 2) ? -1 : 0 | |
plot_color = direction > 0 ? lime: direction < 0 ? red : na | |
plot(emaFast, title="EMA", style=line, linewidth=1, color = plot_color) | |
//----------------- EMA 2 --------------------------------------------------------------------------// | |
src02 = close, len02 = input(20, minval=1, title="Slow EMA Cross") | |
emaSlow = ema(src02, len02) | |
direction2 = rising(emaSlow, 2) ? +1 : falling(emaSlow, 2) ? -1 : 0 | |
plot_color2 = direction2 > 0 ? lime: direction2 < 0 ? red : na | |
plot(emaSlow, title="EMA Signal 2", style=line, linewidth=1, color = plot_color2) | |
//---------------- EMA Cross ----------------------------------------------------------------------// | |
plot(cross(emaFast, emaSlow) ? emaFast: na, style = cross, color = yellow, linewidth = 4) | |
//-------------------- sling shot with EMA --------------------------------------------------------// | |
//sae = input(true, title="Show Aggressive Entry?, Or Use as Alert To Potential Conservative Entry?") | |
sce = input(true, title="Show Conservative Entry?") | |
st = input(true, title="Show Trend Arrows at Top and Bottom of Screen?") | |
//def = input(false, title="Only Choose 1 - Either Conservative Entry Arrows or 'B'-'S' Letters") | |
pa = input(true, title="Show Conservative Entry Arrows?") | |
sl = input(false, title="Show 'B'-'S' Letters?") | |
//Conservative Entry True/False Condition | |
entryUpTrend = emaFast > emaSlow and close[1] < emaFast and close > emaFast ? 1 : 0 | |
entryDnTrend = emaFast < emaSlow and close[1] > emaFast and close < emaFast ? 1 : 0 | |
//Define Up and Down Trend for Trend Arrows at Top and Bottom of Screen | |
upTrend = emaFast >= emaSlow | |
downTrend = emaFast < emaSlow | |
//Definition for Conseervative Entry Up and Down PlotArrows | |
codiff = entryUpTrend == 1 ? entryUpTrend : 0 | |
codiff2 = entryDnTrend == 1 ? entryDnTrend : 0 | |
//Trend Triangles at Top and Bottom of Screen | |
plotshape(st and upTrend ? upTrend : na, title="Conservative Buy Entry Triangle",style=shape.triangleup, location=location.bottom, color=lime, transp=0, offset=0) | |
plotshape(st and downTrend ? downTrend : na, title="Conservative Short Entry Triangle",style=shape.triangledown, location=location.top, color=red, transp=0, offset=0) | |
//Plot Arrows OR Letters B and S for Buy Sell Signals | |
plotarrow(pa and codiff ? codiff : na, title="Up Entry Arrow", colorup=lime, maxheight=10, minheight=10, transp=0) | |
plotarrow(pa and codiff2*-1 ? codiff2*-1 : na, title="Down Entry Arrow", colordown=fuchsia, maxheight=10, minheight=10, transp=0) | |
plotchar(sl and codiff ? low - tr : na, title="Buy Entry", offset=0, char='B', location=location.absolute, color=lime, transp=0) | |
plotchar(sl and codiff2 ? high + tr : na, title="Short Entry", offset=0, char='S', location=location.absolute, color=fuchsia, transp=0) | |
//---------------- TD Sequencial -----------------------------------------------------------------// | |
SR=input(true) | |
Barcolor=input(true) | |
//------------// | |
// Sell Setup // | |
//------------// | |
priceflip = barssince(close<close[4]) | |
sellsetup = close>close[4] and priceflip | |
sell = sellsetup and barssince(priceflip!=9) | |
sellovershoot = sellsetup and barssince(priceflip!=13) | |
sellovershoot1 = sellsetup and barssince(priceflip!=14) | |
sellovershoot2 = sellsetup and barssince(priceflip!=15) | |
sellovershoot3 = sellsetup and barssince(priceflip!=16) | |
//----------// | |
// Buy setup// | |
//----------// | |
priceflip1 = barssince(close>close[4]) | |
buysetup = close<close[4] and priceflip1 | |
buy = buysetup and barssince(priceflip1!=9) | |
buyovershoot = barssince(priceflip1!=13) and buysetup | |
buyovershoot1 = barssince(priceflip1!=14) and buysetup | |
buyovershoot2 = barssince(priceflip1!=15) and buysetup | |
buyovershoot3 = barssince(priceflip1!=16) and buysetup | |
//----------// | |
// TD lines // | |
//----------// | |
TDbuyh = valuewhen(buy,high,0) | |
TDbuyl = valuewhen(buy,low,0) | |
TDsellh = valuewhen(sell,high,0) | |
TDselll = valuewhen(sell,low,0) | |
//----------// | |
// Plots // | |
//----------// | |
plot(SR?(TDbuyh ? TDbuyl: na) : na, style=circles, linewidth=1, color=red) | |
plot(SR?(TDselll ? TDsellh : na) : na, style=circles, linewidth=1, color=lime) | |
barcolor(Barcolor?(sell? #FF0000 : buy? #00FF00 : sellovershoot? #FF66A3 : sellovershoot1? #FF3385 : sellovershoot2? #FF0066 : sellovershoot3? #CC0052 : buyovershoot? #D6FF5C : buyovershoot1? #D1FF47 : buyovershoot2? #B8E62E : buyovershoot3? #8FB224 : na):na) | |
//----------------- Plot RSI and MACD histogram Buy and Sell Signals with X ------------------------------------------// | |
// RSI | |
rsiPeriod=input(14) | |
rsival=rsi(close, rsiPeriod) | |
overBought=input(60, "RSI overbought") | |
pullup=rsival>overBought | |
overSold=input(40, "RSI oversold") | |
pulldown=rsival<overSold | |
//MACD | |
slow = input(12, "MACD Short period") | |
fast = input(26, "MACD Long period") | |
signal = input(9, "Smoothing period") | |
maFast = ema( volume * close, fast ) / ema( volume, fast ) | |
maSlow = ema( volume * close, slow ) / ema( volume, slow ) | |
d = maSlow - maFast | |
maSignal = ema( d, signal ) | |
dm=d-maSignal | |
crossdown() => crossunder(rsival,overBought) and dm<dm[1] and dm[1]<dm[2] | |
plotshape(crossdown(),style=shape.xcross,location=location.abovebar,size=size.tiny,color=fuchsia, transp=0) | |
crossup() => crossover(rsival,overSold) and dm>dm[1] and dm[1]>dm[2] | |
plotshape(crossup(),style=shape.xcross,location=location.belowbar,size=size.tiny,color=lime, transp=0) | |
//============ signal Generator ======================================================================================// | |
duration=input('540') | |
ch1 = security(tickerid, duration, open) | |
ch2 = security(tickerid, duration, close) | |
longCondition = crossover(ch2, ch1) | |
if (longCondition) | |
strategy.entry("L", strategy.long) | |
shortCondition = crossunder(ch2, ch1) | |
if (shortCondition) | |
strategy.entry("S", strategy.short) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment