100% found this document useful (1 vote)
158 views4 pages

Trading Bot

Uploaded by

kosawi1011
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
158 views4 pages

Trading Bot

Uploaded by

kosawi1011
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

//@version=5

indicator("Bit Bite ht",shorttitle = "Bit Bite hindi technical", overlay = true)


src = input(hl2, title="Source",group = "Trend Continuation Signals with TP & SL")
Multiplier = input.float(2,title="Sensitivity (0.5 - 5)", step=0.1, defval=2,
minval=0.5, maxval=5,group = "Trend Continuation Signals with TP & SL")
atrPeriods = input.int(14,title="ATR Length", defval=10,group = "Trend Continuation
Signals with TP & SL")
atrCalcMethod= input.string("Method 1",title = "ATR Calculation Methods",options =
["Method 1","Method 2"],group = "Trend Continuation Signals with TP & SL")
cloud_val = input.int(10,title = "Cloud Moving Average Length", defval = 10, minval
= 5, maxval = 500,group = "Trend Continuation Signals with TP & SL")
stopLossVal = input.float(2.0, title="Stop Loss Percent (0 for Disabling)",
minval=0,group = "Trend Continuation Signals with TP & SL")
showBuySellSignals = input.bool(true,title="Show Buy/Sell Signals",
defval=true,group = "Trend Continuation Signals with TP & SL")
showMovingAverageCloud = input.bool(true, title="Show Cloud MA",group = "Trend
Continuation Signals with TP & SL")

percent(nom, div) =>


100 * nom / div

src1 = ta.hma(open, 5)[1]


src2 = ta.hma(close, 12)
momm1 = ta.change(src1)
momm2 = ta.change(src2)
f1(m, n) => m >= n ? m : 0.0
f2(m, n) => m >= n ? 0.0 : -m
m1 = f1(momm1, momm2)
m2 = f2(momm1, momm2)
sm1 = math.sum(m1, 1)
sm2 = math.sum(m2, 1)

cmoCalc = percent(sm1-sm2, sm1+sm2)

hh = ta.highest(2)
h1 = ta.dev(hh, 2) ? na : hh
hpivot = fixnan(h1)
ll = ta.lowest(2)
l1 = ta.dev(ll, 2) ? na : ll
lpivot = fixnan(l1)

rsiCalc = ta.rsi(close,9)
lowPivot = lpivot
highPivot = hpivot

sup = rsiCalc < 25 and cmoCalc > 50 and lowPivot


res = rsiCalc > 75 and cmoCalc < -50 and highPivot

atr2 = ta.sma(ta.tr, atrPeriods)


atr= atrCalcMethod == "Method 1" ? ta.atr(atrPeriods) : atr2
up=src-(Multiplier*atr)
up1 = nz(up[1],up)
up := close[1] > up1 ? math.max(up,up1) : up
dn=src+(Multiplier*atr)
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? math.min(dn, dn1) : dn

trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
buySignal = trend == 1 and trend[1] == -1
sellSignal = trend == -1 and trend[1] == 1

pos = 0.0
pos:= buySignal? 1 : sellSignal ? -1 : pos[1]

longCond = buySignal and pos[1]!= 1


shortCond = sellSignal and pos[1]!=-1

entryOfLongPosition = ta.valuewhen(longCond , close, 0)


entryOfShortPosition = ta.valuewhen(shortCond, close, 0)

sl = stopLossVal > 0 ? stopLossVal / 262 : 99999

stopLossForLong = entryOfLongPosition * (1 - sl)


stopLossForShort = entryOfShortPosition * (1 + sl)

takeProfitForLong1R = entryOfLongPosition * (1 + sl)


takeProfitForShort1R = entryOfShortPosition * (1 - sl)

takeProfitForLong2R = entryOfLongPosition * (1 + sl*2)


takeProfitForShort2R = entryOfShortPosition * (1 - sl*2)

takeProfitForLong3R = entryOfLongPosition * (1 + sl*3)


takeProfitForShort3R = entryOfShortPosition * (1 - sl*3)

long_sl = low < stopLossForLong and pos[1]==1


short_sl = high> stopLossForShort and pos[1]==-1

takeProfitForLongFinal = high>takeProfitForLong3R and pos[1]==1


takeProfitForShortFinal = low <takeProfitForShort3R and pos[1]==-1

if long_sl or short_sl or takeProfitForLongFinal or takeProfitForShortFinal


pos:=0

lindex = ta.valuewhen(longCond, bar_index, 0)


sindex= ta.valuewhen(shortCond, bar_index, 0)

entryColor = pos==1? color.blue : color.purple

if barstate.islast and pos!=0


lineEntry = line.new(bar_index, pos>0?
entryOfLongPosition :entryOfShortPosition , pos>0?lindex:sindex, pos>0?
entryOfLongPosition :entryOfShortPosition , color=entryColor )
line.delete(lineEntry[1])
stopLine = line.new(bar_index, pos>0?stopLossForLong :stopLossForShort ,
pos>0?lindex:sindex, pos>0?stopLossForLong :stopLossForShort , color=color.red )
tpLine1 = line.new(bar_index, pos>0?takeProfitForLong1R:takeProfitForShort1R,
pos>0?lindex:sindex, pos>0?takeProfitForLong1R:takeProfitForShort1R,
color=color.green)
tpLine2 = line.new(bar_index, pos>0?takeProfitForLong2R:takeProfitForShort2R,
pos>0?lindex:sindex, pos>0?takeProfitForLong2R:takeProfitForShort2R,
color=color.green)
tpLine3 = line.new(bar_index, pos>0?takeProfitForLong3R:takeProfitForShort3R,
pos>0?lindex:sindex, pos>0?takeProfitForLong3R:takeProfitForShort3R,
color=color.green)
line.delete(stopLine [1])
line.delete(tpLine1[1])
line.delete(tpLine2[1])
line.delete(tpLine3[1])

labelEntry = label.new(bar_index, pos>0?


entryOfLongPosition :entryOfShortPosition , color=entryColor , textcolor=#000000,
style=label.style_label_left, text="Entry Price: " + str.tostring(pos>0?
entryOfLongPosition :entryOfShortPosition ))
label.delete(labelEntry[1])

labelStop = label.new(bar_index, pos>0?stopLossForLong :stopLossForShort ,


color=color.red , textcolor=#000000, style=label.style_label_left, text="Stop Loss
Price: " + str.tostring(math.round((pos>0?stopLossForLong :stopLossForShort)
*100)/100))
labelTp1 = label.new(bar_index, pos>0?takeProfitForLong1R:takeProfitForShort1R,
color=color.green, textcolor=#000000, style=label.style_label_left, text="(1-1)
Take Profit: " +str.tostring(math.round((pos>0?
takeProfitForLong1R:takeProfitForShort1R) * 100)/100))
labelTp2 = label.new(bar_index, pos>0?takeProfitForLong2R:takeProfitForShort2R,
color=color.green, textcolor=#000000, style=label.style_label_left, text="(2-1)
Take Profit: " + str.tostring(math.round((pos>0?
takeProfitForLong2R:takeProfitForShort2R) * 100)/100))
labelTp3 = label.new(bar_index, pos>0?takeProfitForLong3R:takeProfitForShort3R,
color=color.green, textcolor=#000000, style=label.style_label_left, text="(3-1)
Take Profit: " + str.tostring(math.round((pos>0?
takeProfitForLong3R:takeProfitForShort3R) * 100)/100))
label.delete(labelStop [1])
label.delete(labelTp1[1])
label.delete(labelTp2[1])
label.delete(labelTp3[1])

changeCond = trend != trend[1]


smaSrcHigh = ta.ema(high,cloud_val)
smaSrcLow = ta.ema(low, cloud_val)
[macdLine, signalLine, histLine] = ta.macd(close, 12, 26, 9)
plot_high = plot(showMovingAverageCloud? smaSrcHigh : na, color = na, transp = 1,
editable = false)
plot_low = plot(showMovingAverageCloud? smaSrcLow : na, color = na, transp = 1,
editable = false)

plotshape(longCond ? up : na, title="UpTrend Begins", location=location.belowbar,


style=shape.circle, size=size.tiny, color=color.new(color.teal,transp = 50) )
plotshape(longCond and showBuySellSignals ? up : na, title="Buy kar lo", text="Buy
kar lo", location=location.belowbar, style=shape.labelup, size=size.tiny,
color=color.new(color.teal,transp = 50), textcolor=color.white )
plotshape(shortCond ? dn : na, title="DownTrend Begins",
location=location.abovebar, style=shape.circle, size=size.tiny,
color=color.new(color.red,transp = 50) )
plotshape(shortCond and showBuySellSignals ? dn : na, title="Sell kar do",
text="Sell kar do", location=location.abovebar, style=shape.labeldown,
size=size.tiny, color=color.new(color.red,transp = 50), textcolor=color.white)

fill(plot_high, plot_low, color = (macdLine > 0) and (macdLine[0] > macdLine[1]) ?


color.new(color.aqua,transp = 85) : na, title = "Positive Cloud Uptrend")
fill(plot_high, plot_low, color = macdLine > 0 and macdLine[0] < macdLine[1] ?
color.new(color.aqua,transp = 85) : na, title = "Positive Cloud Downtrend")
fill(plot_high, plot_low, color = macdLine < 0 and macdLine[0] < macdLine[1] ?
color.new(color.red,transp = 85) : na, title = "Negative Cloud Uptrend")
fill(plot_high, plot_low, color = macdLine < 0 and macdLine[0] > macdLine[1] ?
color.new(color.red,transp = 85) : na, title = "Negative Cloud Downtrend")
mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)
alertcondition(changeCond, title="Trend Direction Change ", message="Trend
direction has changed ! ")

alertLongText = str.tostring(syminfo.ticker) + " BUY ALERT! " +


"Entry Price: " + str.tostring(entryOfLongPosition) +
", Take Profit 1: " + str.tostring(takeProfitForLong1R) +
", Take Profit 2: " + str.tostring(takeProfitForLong2R) +
", Take Profit 3: " + str.tostring(takeProfitForLong3R) +
", Stop Loss Price: " + str.tostring(stopLossForLong)

alertShortText = str.tostring(syminfo.ticker) + " SELL ALERT!" +


", Entry Price: " + str.tostring(entryOfShortPosition) +
", Take Profit 1: " + str.tostring(takeProfitForShort1R) +
", Take Profit 2: " + str.tostring(takeProfitForShort2R) +
", Take Profit 3: " + str.tostring(takeProfitForShort3R) +
", Stop Loss Price: " + str.tostring(stopLossForShort)

longJson = '{"content": "' + alertLongText + '"}'


shortJson = '{"content": "' + alertShortText + '"}'

if longCond
alert(longJson, alert.freq_once_per_bar_close)

if shortCond
alert(shortJson, alert.freq_once_per_bar_close)

You might also like