//@version=4 strategy("newlineenrgy", overlay=true,process_orders_on_close = true) //plot(close) enableLong = input(true,"Long Trades",group = "Strategy options", inline = "LongShort") enableShort = input(true,"Short Trades",group = "Strategy options", inline = "LongShort") fastLength = input(title="MACD Fast Length", defval=23, group = "STC") slowLength = input(title="MACD Slow Length", defval=50, group = "STC") cycleLength = input(title="Cycle Length", defval=10, group = "STC") d1Length = input(title="1st %D Length", defval=3, group = "STC") d2Length = input(title="2nd %D Length" ,defval=3, group = "STC") src = input(title="Source", defval=close, group = "STC") highlightBreakouts = input(title="Highlight Breakouts ?", defval=true, group = "STC") macd = ema(src, fastLength) - ema(src, slowLength) k = nz(fixnan(stoch(macd, macd, macd, cycleLength))) d = ema(k, d1Length) kd = nz(fixnan(stoch(d, d, d, cycleLength))) stc = ema(kd, d2Length) stc := stc > 100 ? 100 : stc < 0 ? 0 : stc stcColor = not highlightBreakouts ? (stc > stc[1] ? color.green : color.red) : #ff3013 //stcPlot = plot(stc, title="STC", color=stcColor, transp=0) upper = 75 lower = 25 transparent = color.new(color.white, 100) //upperLevel = plot(upper, title="Upper", color=color.gray) //hline(50, title="Middle", linestyle=hline.style_dotted) //lowerLevel = plot(lower, title="Lower", color=color.gray) //fill(upperLevel, lowerLevel, color=#f9cb9c, transp=90) upperFillColor = stc > upper and highlightBreakouts ? color.green : transparent lowerFillColor = stc < lower and highlightBreakouts ? color.red : transparent // fill(upperLevel, stcPlot, color=upperFillColor, transp=80) // fill(lowerLevel, stcPlot, color=lowerFillColor, transp=80) // plotshape(crossover(stc, lower) ? lower : na, title="Crossover", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0) // plotshape(crossunder(stc, upper) ? upper : na, title="Crossunder", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0) sellAlert = stc > upper and barstate.isconfirmed buyAlert = stc < lower and barstate.isconfirmed alertcondition(sellAlert, "Sell","Sell Alert") alertcondition(buyAlert, "Buy","Buy Alert") // BEEP BOOP fast_length = input(title="Fast Length", type=input.integer, defval=12, group = "Beep Boop") slow_length = input(title="Slow Length", type=input.integer, defval=26, group = "Beep Boop") EMATrend = input(title="EMA Trend", type=input.integer, defval=50, group = "Beep Boop") src1 = input(title="Source", type=input.source, defval=close, group = "Beep Boop") signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9, group = "Beep Boop") sma_source = input(title="Simple MA(Oscillator)", type=input.bool, defval=false, group = "Beep Boop") sma_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=false, group = "Beep Boop") ema_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=false, group = "Beep Boop") col_grow_above = #26A69A col_grow_below = #FF0000 col_fall_above = #FFFFFF col_fall_below = #FFFFFF col_macd = #0094ff col_signal = #ff6a00 variant_doubleema(src,len) => v2 = ema(src, len) v6 = 2 * v2 - ema(v2, len) v6 variant_zerolagema(src, len) => price = src l = (len - 1) / 2 d = (price + (price - price[l])) z = ema(d, len) z //fast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length) //slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length) //macd = fast_ma - slow_ma //signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length) fast_ma = sma_source ? sma(src1, fast_length) : ema_signal ? ema(src1, fast_length) : variant_doubleema(src1, fast_length) slow_ma = sma_source ? sma(src1, slow_length) : ema_signal ? ema(src1, slow_length) : variant_doubleema(src1, slow_length) macd1 = fast_ma - slow_ma signal = sma_signal ? sma(macd1, signal_length) : ema_signal ? ema(macd1, signal_length) : variant_doubleema(macd1, signal_length) hist = macd1 - signal histplot = hist maxhist = highest(histplot,30) if (hist > 0) hist := maxhist // hist := 0.1 if (hist < 0) hist := 0.9*maxhist // hist := 0.09 //fastMA = ema(close, EMATrend) fastMA = ema_signal ? ema(close, EMATrend) : variant_doubleema(close, EMATrend) //fastMA = 0 //plot(hist, title="Histogram", style=plot.style_columns, color=(hist == maxhist ? ((hist == maxhist) and (close > fastMA) and (open > fastMA) and (low > fastMA) ? col_grow_above : col_fall_above) : ((hist == 0.9*maxhist) and (close < fastMA) and (open < fastMA) and (high < fastMA)? col_grow_below : col_fall_below) ), transp=0 ) //plot(histplot) greenBar = ((hist == maxhist) and (close > fastMA) and (open > fastMA) and (low > fastMA)) redBar = ((hist == 0.9*maxhist) and (close < fastMA) and (open < fastMA) and (high < fastMA)) whiteBar = not greenBar and not redBar longCondition = stc > stc[1] and stc[1] < 25 longExit = stc > 75 and redBar//and (hist != maxhist) and (hist == 0.9*maxhist) and (close < fastMA) and (open < fastMA) and (high < fastMA) longExit1 = stc[1] > 75 and stc < stc[1] longExit2 = whiteBar and whiteBar[1] and whiteBar[2] and greenBar[3] and stc > 75 strategy.exit("Exit Long","Long",when = longExit or longExit1 or longExit2 ,limit=close) shortCondition = stc < stc[1] and stc[1] > 75 shortExit = stc < 25 and greenBar//and (hist == maxhist) and (close > fastMA) and (open > fastMA) and (low > fastMA) shortExit1 = whiteBar and whiteBar[1] and whiteBar[2] and redBar[3] and stc < 25 //longExit2 = not ((hist == 0.9*maxhist) and (close < fastMA) and (open < fastMA) and (high < fastMA)) and barssince(longCondition) >1 strategy.exit("Exit Short","Short",when = shortExit or shortExit1,limit=close) if (longCondition and enableLong) strategy.entry("Long", strategy.long) if (shortCondition and enableShort) strategy.entry("Short", strategy.short) streakLen = 0 lossstreakLen = 0 winlen = 0 losslen = 0 newWin = (strategy.wintrades > strategy.wintrades[1]) and (strategy.losstrades == strategy.losstrades[1]) and (strategy.eventrades == strategy.eventrades[1]) newLoss = (strategy.losstrades > strategy.losstrades[1]) and (strategy.wintrades == strategy.wintrades[1]) and (strategy.eventrades == strategy.eventrades[1]) streakLen := if (newWin) nz(streakLen[1]) + 1 else if (strategy.losstrades > strategy.losstrades[1]) or (strategy.eventrades > strategy.eventrades[1]) 0 else nz(streakLen[1]) lossstreakLen := if (newLoss) nz(lossstreakLen[1]) + 1 else if (strategy.wintrades > strategy.wintrades[1]) or (strategy.eventrades > strategy.eventrades[1]) 0 else nz(lossstreakLen[1]) // Draw table with all the variables var string GP2 = "Display Table" showDisplay = input(true,"Show Display Pane", group = GP2) string i_tableYpos = input("top", "Display position", inline = "11", options = ["top", "middle", "bottom"], group = GP2) string i_tableXpos = input("right", "", inline = "11", options = ["left", "center", "right"], group = GP2) //color i_c_bull = input(color.new(color.green, 30), "Bull", inline = "12", group = GP2) //color i_c_bear = input(color.new(color.red, 30), "Bear", inline = "12", group = GP2) color i_c_neutral = input(color.new(#434651, 00), "Display Background", inline = "12", group = GP2) c = input(title="Display Text Color", type=input.color, defval=color.white, group = GP2) var table panel = table.new(i_tableYpos + "_" + i_tableXpos, 2, 30, border_width = 1) winlen := valuewhen(newWin == false and newWin[1] == true, streakLen, 0) losslen := valuewhen(newLoss == false and newLoss[1] == true, lossstreakLen, 0) mostWin = highest(winlen,5000) mostLoss = highest(losslen,5000) perProfitable = (strategy.wintrades/strategy.closedtrades)*100 if showDisplay table.cell(panel, 0, 0, "Variable \""+syminfo.ticker+"\"", bgcolor = i_c_neutral, text_color = c) table.cell(panel, 1, 0, "Value", bgcolor = i_c_neutral, text_color = c) table.cell(panel, 0, 1, "Winners", bgcolor = i_c_neutral, text_color = c) table.cell(panel, 1, 1, tostring(strategy.wintrades), bgcolor = i_c_neutral, text_color = c) table.cell(panel, 0, 2, "Losers", bgcolor = i_c_neutral, text_color = c) table.cell(panel, 1, 2, tostring(strategy.losstrades), bgcolor = i_c_neutral, text_color = c) table.cell(panel, 0, 3, "Percent Profitable", bgcolor = i_c_neutral, text_color = c) table.cell(panel, 1, 3, tostring(round(perProfitable))+"%", bgcolor = i_c_neutral, text_color = c) table.cell(panel, 0, 4, "Initial Capital", bgcolor = i_c_neutral, text_color = c) table.cell(panel, 1, 4, tostring(strategy.initial_capital)+" USD", bgcolor = i_c_neutral, text_color = c) table.cell(panel, 0, 5, "Ending Capital", bgcolor = i_c_neutral, text_color = c) table.cell(panel, 1, 5,tostring(round(strategy.initial_capital+strategy.netprofit))+" USD", bgcolor = i_c_neutral, text_color = c) table.cell(panel, 0, 6, "Net Profit", bgcolor = i_c_neutral, text_color = c) table.cell(panel, 1, 6, tostring(round(strategy.netprofit))+" USD", bgcolor = i_c_neutral, text_color = c) table.cell(panel, 0, 7, "% Return", bgcolor = i_c_neutral, text_color = c) table.cell(panel, 1, 7, tostring(round((strategy.netprofit/strategy.initial_capital)*100))+" %", bgcolor = i_c_neutral, text_color = c) table.cell(panel, 0, 8, "Gross Profit", bgcolor = i_c_neutral, text_color = c) table.cell(panel, 1, 8, tostring(round(strategy.grossprofit))+" USD", bgcolor = i_c_neutral, text_color = c) table.cell(panel, 0, 9, "Gross Loss", bgcolor = i_c_neutral, text_color = c) table.cell(panel, 1, 9, tostring(round(strategy.grossloss))+" USD", bgcolor = i_c_neutral, text_color = c) table.cell(panel, 0, 10, "Max Drawdown", bgcolor = i_c_neutral, text_color = c) table.cell(panel, 1, 10, tostring(round(strategy.max_drawdown))+" USD", bgcolor = i_c_neutral, text_color = c) table.cell(panel, 0, 11, "Number of Trades", bgcolor = i_c_neutral, text_color = c) table.cell(panel, 1, 11, tostring(round(strategy.closedtrades)), bgcolor = i_c_neutral, text_color = c) table.cell(panel, 0, 12, "Most Wins in a row", bgcolor = i_c_neutral, text_color = c) table.cell(panel, 1, 12, tostring(mostWin), bgcolor = i_c_neutral, text_color = c) table.cell(panel, 0, 13, "Most Losses in a row", bgcolor = i_c_neutral, text_color = c) table.cell(panel, 1, 13, tostring(mostLoss), bgcolor = i_c_neutral, text_color = c)