//@version=5 strategy(title='Marks Strategy [Markorifelj]', overlay=true, max_lines_count = 500) // Paste This Msg In Alert Msg Boz - {{strategy.order.alert_message}} //RSI MACD fastLength = input.int(8, minval=1) slowLength = input.int(16, minval=1) signalLength = input.int(11, minval=1) hline(0, color=color.purple, linestyle=hline.style_dashed) fastMA = ta.ema(close, fastLength) slowMA = ta.ema(close, slowLength) macd = fastMA - slowMA signal = ta.sma(macd, signalLength) Length = input.int(10, minval=1) Oversold = input.int(49, minval=1) Overbought = input.int(51, minval=1) xRSI = ta.rsi(close, Length) pos = int(na) iff_1 = xRSI < Oversold and signal > macd ? -1 : nz(pos[1], 0) pos := xRSI > Overbought and signal < macd ? 1 : iff_1 barcolor(pos == -1 ? color.red : pos == 1 ? color.green : color.blue) plot(pos, title='pos', style=plot.style_line, linewidth=1, color=color.new(color.red, 0)) qtyRound = 2 qty = math.round(((strategy.equity/100) * 1000 ) /close, qtyRound) StrRemoveSuffix(string source, string suffix, ignoreCase=false) => sourceStr = ignoreCase ? str.lower(source) : source suffixStr = ignoreCase ? str.lower(suffix) : suffix if str.endswith(sourceStr, suffixStr) str.substring(source, 0, str.length(source) - str.length(suffix)) else source rawSymbolA = StrRemoveSuffix(syminfo.ticker, '.P', true) rawSymbolB = StrRemoveSuffix(rawSymbolA, 'PERP', true) rawSymbolC = StrRemoveSuffix(rawSymbolB, 'BUSD', true) rawSymbolD = StrRemoveSuffix(rawSymbolC, 'USD', true) tknSymbol = StrRemoveSuffix(rawSymbolD, 'USDT', true) buyEnSyntax = "Buy "+str.tostring(tknSymbol)+"USDT Q="+str.tostring(qty)+"" selEnSyntax = "Sell "+str.tostring(tknSymbol)+"USDT Q="+str.tostring(qty)+"" buyExSyntax = "Close "+str.tostring(tknSymbol)+"USDT T=buy Q="+str.tostring(100)+"%" selExSyntax = "Close "+str.tostring(tknSymbol)+"USDT T=sell Q="+str.tostring(100)+"%" ts = syminfo.ticker exchange = syminfo.prefix ////////////////// Strategy Code ///////////////// basePeriods = input.int(26, minval=1, title='Period') donchian(len) => math.avg(ta.lowest(len), ta.highest(len)) baseLine = donchian(basePeriods) plot(baseLine, color=color.new(#991515, 0), title='Kijun-Sen') //Heiken Ashi Candles data = ticker.heikinashi(syminfo.tickerid) resLT = input.timeframe(title='Res LT', defval='D') resMT = input.timeframe(title='Res MT', defval='240') LTo = request.security(data, resLT, open, lookahead=barmerge.lookahead_on) LTc = request.security(data, resLT, close, lookahead=barmerge.lookahead_on) MTo = request.security(data, resMT, open, lookahead=barmerge.lookahead_on) MTc = request.security(data, resMT, close, lookahead=barmerge.lookahead_on) LTlong = LTc > LTo LTshort = LTc < LTo MTema20 = ta.ema(MTc, 20) MTema20delta = ta.change(MTema20) MTlong = MTc > MTo and MTc > MTema20 and MTema20delta > 0 MTshort = MTc < MTo and MTc < MTema20 and MTema20delta < 0 traderange = input.session('0000-2300', 'Trading Time Range Duration (NYC Standard Time)') imeIsAllowed = not na(time(timeframe.period, traderange)) Long = MTlong and LTlong Short = MTshort and LTshort z=Long ? 1 : Short ? -1 : 0 plot(Long ? 1 : Short ? -1 : 0, title='TrendAlert', color=Long ? color.lime : Short ? color.red : color.gray, style=plot.style_columns) bool trendalertcon=na bool trendalertcon2=na low1=low high1=high lookback=input.int(10,'Look back bars') for x = 0 to lookback if Long[x]==true trendalertcon:=true for x = 0 to lookback if Short[x]==true trendalertcon2:=true Sencon=0 //DAILY takeprofit daypnl=strategy.closedtrades.profit(strategy.closedtrades - 1) var float daysprofit=0.0 var float daysloss=0.0 var float acc_bal =0.0 if daypnl!=daypnl[1] and daypnl>=0 daysprofit+=daypnl else if daypnl!=daypnl[1] and daypnl<0 daysloss+=daypnl if dayofmonth!=dayofmonth[1] line.new(x1=bar_index,y1=close + 1,y2= close - 1,x2=bar_index,extend=extend.both,color=color.white) daysprofit:=0.0 daysloss:=0.0 acc_bal:=strategy.equity candle_sizevar=input.float(0,'candle size variable in 1% pecentage') Longen=input.bool(true,'Long On/Off') shorten=input.bool(true,'ShortOn/Off') daystoplim=input.float(2,'Days loss limit') dayprofitlim=input.float(2,'Days profit limit') conday=(acc_bal*-0.01*daystoplim)<=daysloss and (acc_bal*0.01*dayprofitlim)>=daysprofit tp=input.float(1,'Takeprofit Multiplier') sl=input.float(1,'Stoploss Multiplier') exitcon=input.string('Stoploss/TakeProfit','Exit Type',options = [ 'Stoploss/TakeProfit','RSI MACD']) // Tradingview PaperTrading NLB Syntax tvBuySynt = '[{"E":"' + str.tostring(exchange) + '","TS":"' + str.tostring(ts) + '","PRICE":"' + str.tostring(close) + '","Q":"' + str.tostring(strategy.equity*0.01/(close-low1)) + '","TT":"BUY","AT":"TRADINGVIEW"}]' tvSelSynt = '[{"E":"' + str.tostring(exchange) + '","TS":"' + str.tostring(ts) + '","PRICE":"' + str.tostring(close) + '","Q":"' + str.tostring(strategy.equity*0.01/(high1-close)) + '","TT":"SELL","AT":"TRADINGVIEW"}]' tvExtSynt = '[{"E":"' + str.tostring(exchange) + '","TS":"' + str.tostring(ts) + '","PRICE":"' + str.tostring(close) + '","CLOSE":"CLOSE","AT":"TRADINGVIEW"}]' //Table Plotting var T_label = table.new(position = position.top_right, columns = 5, rows = 26, bgcolor = color.new(color.white, 0), border_color=color.new(color.black, 0), frame_width = 1, border_width = 1) if close > 0 //and tableEn table.cell(table_id = T_label, column = 0, row = 0, text = str.tostring(tvBuySynt), text_color = color.white, bgcolor = color.gray, text_size = size.small) table.cell(table_id = T_label, column = 0, row = 1, text = str.tostring(tvSelSynt), text_color = color.white, bgcolor = color.gray, text_size = size.small) if baseLine>high and not(Short) and trendalertcon Sencon:=1 if Sencon[1]>0 and trendalertcon and not(Short) Sencon:=Sencon[1] if Sencon==1 and close>baseLine and low[1]baseLine and imeIsAllowed and conday and Longen and open0 and trendalertcon2 and not(Long) Sencon1:=Sencon1[1] if Sencon1==1 and closebaseLine and imeIsAllowed and shorten and conday and closebaseLine Sencon1:=3 if Sencon1==3 and close 0 // line.delete(buySlLine[1]) // line.delete(buyTpLine[1]) buyTpLine := line.new(bar_index, (((close[1]-low1[1])*tp)+close[1]) , bar_index + 10, (((close[1]-low1[1])*tp)+close[1]), color = color.lime) buySlLine := line.new(x1=bar_index,y1=close-((close-low1)*sl) ,x2=bar_index + 10,y2=close-((close-low1)*sl), color = color.red) if strategy.position_size[1] == 0 and strategy.position_size < 0 // line.delete(selSlLine[1]) // line.delete(selTpLine[1]) selTpLine := line.new(bar_index, close[1]-((high1[1]-close[1])*tp) , bar_index + 10, close[1]-((high1[1]-close[1])*tp), color = color.lime) selSlLine := line.new(bar_index, close+((high1-close)*sl) , bar_index + 10, close+((high1-close)*sl), color = color.red) if strategy.position_size < 0 line.set_x2(selSlLine, bar_index+1) line.set_x2(selTpLine, bar_index+1) if strategy.position_size > 0 line.set_x2(buySlLine, bar_index+1) line.set_x2(buyTpLine, bar_index+1)