Droptext.cc – Free Anonymous Text Hosting

Share your text data anonymously and free



indicators Sutupid bot

//@version=4
strategy("Stupid bot Supertrend + CDC ActionZone", overlay = true,initial_capital=100,default_qty_value=100,default_qty_type=strategy.percent_of_equity,commission_type=strategy.commission.percent,commission_value=0.01)

//Input symbol and amount for future order by stupid bot
Symbol = input(title="Symbol", type=input.string, defval="$", group="Sizing Order",tooltip="Example: Input % or $ or @")
Amount = input(title="Amount", type=input.float, minval=0.0, step=0.1, defval=1, group="Sizing Order", tooltip="Example: Input value")

//Calculate TP&SL//
TP1Perc = input(title="Take Profit (%) @ TP1", type=input.float, minval=0.0, step=0.1, defval=8, group="TP & SL")
TP2Perc = input(title="Take Profit (%) @ TP2", type=input.float, minval=0.0, step=0.1, defval=16, group="TP & SL")
TP3Perc = input(title="Take Profit (%) @ TP3", type=input.float, minval=0.0, step=0.1, defval=24, group="TP & SL")
TP4Perc = input(title="Take Profit (%) @ TP4", type=input.float, minval=0.0, step=0.1, defval=32, group="TP & SL")
TP5Perc = input(title="Take Profit (%) @ TP5", type=input.float, minval=0.0, step=0.1, defval=40, group="TP & SL")
SLPerc = input(title="Stop Loss (%)", type=input.float, minval=0.0, step=0.1, defval=8, group="TP & SL")

TP1_Ratio = input(title="Sell Postion Size % @ TP1", type=input.float, defval=10, step=1, group="TP & SL", tooltip="Example: 8 closing 8% of the position once TP1 is reached")/100
TP2_Ratio = input(title="Sell Postion Size % @ TP2", type=input.float, defval=10, step=1, group="TP & SL", tooltip="Example: 16 closing 16% of the position once TP1 is reached")/100
TP3_Ratio = input(title="Sell Postion Size % @ TP3", type=input.float, defval=10, step=1, group="TP & SL", tooltip="Example: 24 closing 24% of the position once TP1 is reached")/100
TP4_Ratio = input(title="Sell Postion Size % @ TP4", type=input.float, defval=10, step=1, group="TP & SL", tooltip="Example: 32 closing 32% of the position once TP1 is reached")/100
TP5_Ratio = input(title="Sell Postion Size % @ TP5", type=input.float, defval=10, step=1, group="TP & SL", tooltip="Example: 40 closing 40% of the position once TP1 is reached")/100
SL_Ratio = input(title="Sell Postion Size % @ SL", type=input.float, defval=100, step=1, group="TP & SL", tooltip="Example: 100 closing 100% of the position once SL is reached")

Periods = input(title="ATR Period", type=input.integer, defval=12)
src = input(ohlc4, title="Source")
Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=4)
changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)
showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true)
highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=false)
atr2 = sma(tr, Periods)
atr= changeATR ? atr(Periods) : atr2
up=src-(Multiplier*atr)
up1 = nz(up[1],up)
up := close[1] > up1 ? max(up,up1) : up
dn=src+(Multiplier*atr)
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? 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
upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)
buySignal = trend == 1 and trend[1] == -1
plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)
plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)
dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)
sellSignal = trend == -1 and trend[1] == 1
plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)
plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)
mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)
longFillColor = highlighting ? (trend == 1 ? color.green : color.white) : color.white
shortFillColor = highlighting ? (trend == -1 ? color.red : color.white) : color.white
//fill(mPlot, upPlot, title="UpTrend Highligter", color=longFillColor)
//fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)
alertcondition(buySignal, title="SuperTrend Buy", message="SuperTrend Buy!")
alertcondition(sellSignal, title="SuperTrend Sell", message="SuperTrend Sell!")
changeCond = trend != trend[1]
alertcondition(changeCond, title="SuperTrend Direction Change", message="SuperTrend has changed direction!")

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// ยฉ piriya33
// Added Labels and alert conditions and other quality of life feature
// Updated compatability with pine script v4
// Based on improvements from "Kitti-Playbook Action Zone V.4.2.0.3 for Stock Market"

//****************************************************************************//
// CDC Action Zone is based on a simple EMA crossover
// between [default] EMA12 and EMA26
// The zones are defined by the relative position of
// price in relation to the two EMA lines
// Different zones can be use to activate / deactivate
// other trading strategies
// The strategy can also be used on its own with
// acceptable result, buy on the first green candle
// and sell on the first red candle
//****************************************************************************//
//****************************************************************************//
// Define User Input Variables

xsrc = input(title="Source Data",type=input.source, defval=close)
xprd1 = input(title="Fast EMA period", type=input.integer, defval=25)
xprd2 = input(title="Slow EMA period", type=input.integer, defval=50)
xsmooth = input(title="Smoothing period (1 = no smoothing)", type=input.integer, defval=1)
fillSW = input(title="Paint Bar Colors", type=input.bool, defval=true)
fastSW = input(title="Show fast moving average line", type=input.bool, defval=true)
slowSW = input(title="Show slow moving average line", type=input.bool, defval=true)
labelSwitch = input(title="Turn on assistive text", type=input.bool, defval=true)
plotSigsw = input(title="Plot Buy/Sell Signals? ", type=input.bool, defval=true)
plotRibsw = input(title="Plot Buy/Sell Ribbon", type=input.bool, defval=false)
plotRibbonPos = input(title="Ribbon Position", options=["Top", "Bottom"], defval="Top")

xfixtf = input(title="** Use Fixed time frame Mode (advanced) **", type=input.bool, defval=false)
xtf = input(title="** Fix chart to which time frame ? **)", type=input.resolution, defval="D")

plotSig2sw = input(title="Plot momentum based Buy/Sell Signals? ", type=input.bool, defval=false)
plotSig2lv = input(title="Set signal threshold (higher = stricter)", type=input.integer, defval=1, minval=0, maxval=1)

//****************************************************************************//
//Calculate Indicators

xPrice = ema(xsrc,xsmooth)
FastMA = xfixtf ?
ema(security(syminfo.tickerid, xtf, ema(xsrc,xprd1),
gaps = barmerge.gaps_off, lookahead = barmerge.lookahead_on), xsmooth)
:
ema(xPrice,xprd1)
SlowMA = xfixtf ?
ema(security(syminfo.tickerid, xtf, ema(xsrc,xprd2),
gaps = barmerge.gaps_off, lookahead = barmerge.lookahead_on), xsmooth)
:
ema(xPrice,xprd2)

Bull = FastMA > SlowMA
Bear = FastMA < SlowMA

//****************************************************************************//
// Define Color Zones

Green = Bull and xPrice>FastMA // Buy
Blue = Bear and xPrice>FastMA and xPrice>SlowMA //Pre Buy 2
LBlue = Bear and xPrice>FastMA and xPrice<SlowMA //Pre Buy 1

Red = Bear and xPrice < FastMA // Sell
Orange = Bull and xPrice < FastMA and xPrice < SlowMA // Pre Sell 2
Yellow = Bull and xPrice < FastMA and xPrice > SlowMA // Pre Sell 1

//****************************************************************************//
// Display color on chart


bColor = Green ? color.green :
Blue ? color.blue :
LBlue ? color.aqua :
Red ? color.red :
Orange ? color.orange :
Yellow ? color.yellow :
color.black
barcolor(color=fillSW? bColor : na)

//****************************************************************************//
// Display MA lines

FastL = plot(fastSW ? FastMA : na,"Fast EMA",color=color.red)
SlowL = plot(slowSW ? SlowMA : na,"Slow EMA",color=color.blue)
fillcolor = Bull ? color.green : Bear ? color.red : color.black
fill(FastL,SlowL,fillcolor)

//****************************************************************************//
// Define Buy and Sell condition
// This is only for thebasic usage of CDC Actionzone (EMA Crossover)
// ie. Buy on first green bar and sell on first red bar

buycond = Green and Green[1]==0
sellcond = Red and Red[1]==0

bullish = barssince(buycond) < barssince(sellcond)
bearish = barssince(sellcond) < barssince(buycond)

buy= bearish[1]and buycond
sell= bullish[1] and sellcond

bColor_BullBear = bullish ? color.green : bearish ? color.red : color.black

//****************************************************************************//
// Plot Buy and Sell point on chart

plotshape(plotSigsw ? buy : na,
style=shape.circle,
title = "Buy Signal",
location = location.belowbar,
color = color.green)
plotshape(plotSigsw ? sell : na,
style=shape.circle,
title = "Sell Signal",
location=location.abovebar,
color = color.red)

// Display Buy/Sell Ribbon


plotshape(plotRibsw ? plotRibbonPos == "Top" ? close : na : na,
style=shape.square,
title = "Buy/Sell Ribbon",
location = location.top,
color = bColor_BullBear)

plotshape(plotRibsw ? plotRibbonPos == "Bottom" ? close : na : na,
style=shape.square,
title = "Buy/Sell Ribbon",
location = location.bottom,
color = bColor_BullBear)


//****************************************************************************//
// Label

labelstyle = close>SlowMA ? label.style_labeldown : label.style_labelup
labelyloc = close>SlowMA ? yloc.abovebar : yloc.belowbar
labeltcolor = buy? color.black :
sell ? color.white :
close > close[1] ? color.green :
color.red
labelbgcolor = buy ? color.green : sell ? color.red : color.silver
labeltext = buy ? "BUY next bar\n" : sell ? "SELL next bar\n" : " "
trendText = bullish ? "bullish" : bearish ? "bearish" : "sideways"


l1 = label.new(bar_index,na,
text=labeltext+syminfo.ticker + " "+tostring(close) + " " + syminfo.currency + "\n currently in a " + trendText + " trend \n" ,
color = labelbgcolor,
textcolor=labeltcolor,
yloc=labelyloc,
style=labelstyle)

label.delete(labelSwitch ? l1[1] : l1)

// Momentum Signal using StochRSI

// Adds a momentum based signal following trends to the script
// Default is hidden, only use with caution
// Parameters for STOCH RSI is hard-coded to avoid cluttering the input screen further
// If you need to change anything, make a copy of the code and change it.
// Inputs are commented out, to enable them comment out the hard coded variables first!

// fixed inputs //

smoothK = 3
smoothD = 3
RSIlen = 14
STOlen = 14
SRsrc = close
OSlevel = 30
OBlevel = 70

// User inputs // // COMMENT ABOVE VARIABLES FIRST!!

// smoothK = input(3,"StochRSI smooth K",type=input.integer,minval=1)
// smoothD = input(3,"StochRSI smooth D",type=input.integer,minval=1)
// RSIlen = input(14,"RSI length",type=input.integer,minval=1)
// STOlen = input(14,"Stochastic length",type=input.integer,minval=1)
// SRsrc = input(close,"Source for StochasticRSI",type=input.source)
// OSlevel = input(30,"Oversold Threshold",type=input.float,minval=0.00)
// OBlevel = input(70,"Oversold Threshold",type=input.float,minval=0.00)

// calculations //
rsi1 = rsi(SRsrc,RSIlen)
k = sma(stoch(rsi1,rsi1,rsi1,STOlen),smoothK)
d = sma(k,smoothD)

// storsiBuySig = if bullish
// if (d < OSlevel and crossover(k,d))
// 3
// else if crossover(k,OSlevel)
// 2
// else if d > OSlevel and crossover(k,d)
// 1
// else
// 0
// else
// 0

storsiBuySig = iff(bullish,
iff(d < OSlevel and crossover(k,d),
2,
iff(d > OSlevel and crossover(k,d),
1,
0)),
0)

storsiSellSig = iff(bearish,
iff(d > OBlevel and crossunder(k,d),
2,
iff(d < OBlevel and crossunder(k,d),
1,
0)),
0)

plotshape(plotSig2sw ? storsiBuySig > plotSig2lv ? storsiBuySig : na : na,
"Buy more signals", style=shape.triangleup,
location=location.belowbar, color = color.teal)
plotshape(plotSig2sw ? storsiSellSig > plotSig2lv ? storsiSellSig : na : na,
"Sell more signals", style=shape.triangledown,
location=location.abovebar, color = color.orange)


//****************************************************************************//
// Alert conditions

alertcondition(buy,
title="*Buy Alert",
message= "Buy {{exchange}}:{{ticker}}")

alertcondition(sell,
title="*Sell Alert",
message= "Sell {{exchange}}:{{ticker}}")

alertcondition(bullish,
title="is Bullish")

alertcondition(bearish,
title="is Bearish")

alertcondition(Green,
title="is Green")

alertcondition(Blue,
title="is Blue (Strong Rally)")

alertcondition(LBlue,
title="is Light Blue (Rally)")

alertcondition(Red,
title="is Red")

alertcondition(Orange,
title="is Orange (Strong Dip)")

alertcondition(Yellow,
title="is Yellow (Dip)")


//****************************************************************************//

// STEP 2:
// Figure out take profit price
percentAsPoints(pcnt) =>
strategy.position_size != 0 ? round(pcnt / 100.0 * strategy.position_avg_price / syminfo.mintick) : float(na)

percentAsPrice(pcnt) =>
strategy.position_size != 0 ? ((pcnt / 100.0) + 1.0) * strategy.position_avg_price : float(na)

current_position_size = abs(strategy.position_size)
initial_position_size = abs(valuewhen(strategy.position_size[1] == 0.0, strategy.position_size, 0))

TP1 = strategy.position_avg_price + percentAsPoints(TP1Perc) * syminfo.mintick * strategy.position_size / abs(strategy.position_size)
TP2 = strategy.position_avg_price + percentAsPoints(TP2Perc) * syminfo.mintick * strategy.position_size / abs(strategy.position_size)
TP3 = strategy.position_avg_price + percentAsPoints(TP3Perc) * syminfo.mintick * strategy.position_size / abs(strategy.position_size)
TP4 = strategy.position_avg_price + percentAsPoints(TP4Perc) * syminfo.mintick * strategy.position_size / abs(strategy.position_size)
TP5 = strategy.position_avg_price + percentAsPoints(TP5Perc) * syminfo.mintick * strategy.position_size / abs(strategy.position_size)
SL = strategy.position_avg_price - percentAsPoints(SLPerc) * syminfo.mintick * strategy.position_size / abs(strategy.position_size)

pairCurrency=syminfo.basecurrency+syminfo.currency+'PERP'

buytext='{"side": "OpenLong", "amount": "'+ Symbol + tostring(Amount) + '", "symbol": "'+ pairCurrency +'", "passphrase": "1234"}'
selltext='{"side": "OpenShort", "amount": "'+ Symbol + tostring(Amount) + '", "symbol": "'+ pairCurrency +'", "passphrase": "1234"}'
closeLongTP1='{"side": "CloseLong", "amount": "'+ Symbol + tostring(TP1_Ratio) + '", "symbol": "'+ pairCurrency +'", "passphrase": "1234"}'
closeLongTP2='{"side": "CloseLong", "amount": "'+ Symbol + tostring(TP2_Ratio) + '", "symbol": "'+ pairCurrency +'", "passphrase": "1234"}'
closeLongTP3='{"side": "CloseLong", "amount": "'+ Symbol + tostring(TP3_Ratio) + '", "symbol": "'+ pairCurrency +'", "passphrase": "1234"}'
closeLongTP4='{"side": "CloseLong", "amount": "'+ Symbol + tostring(TP4_Ratio) + '", "symbol": "'+ pairCurrency +'", "passphrase": "1234"}'
closeLongTP5='{"side": "CloseLong", "amount": "'+ Symbol + tostring(TP5_Ratio) + '", "symbol": "'+ pairCurrency +'", "passphrase": "1234"}'
closeLongSL ='{"side": "CloseLong", "amount": "%' + tostring(SL_Ratio) + '", "symbol": "'+ pairCurrency +'", "passphrase": "1234"}'
closeShortTP1='{"side": "CloseShort", "amount": "'+ Symbol + tostring(TP1_Ratio) + '", "symbol": "'+ pairCurrency +'", "passphrase": "1234"}'
closeShortTP2='{"side": "CloseShort", "amount": "'+ Symbol + tostring(TP2_Ratio) + '", "symbol": "'+ pairCurrency +'", "passphrase": "1234"}'
closeShortTP3='{"side": "CloseShort", "amount": "'+ Symbol + tostring(TP3_Ratio) + '", "symbol": "'+ pairCurrency +'", "passphrase": "1234"}'
closeShortTP4='{"side": "CloseShort", "amount": "'+ Symbol + tostring(TP4_Ratio) + '", "symbol": "'+ pairCurrency +'", "passphrase": "1234"}'
closeShortTP5='{"side": "CloseShort", "amount": "'+ Symbol + tostring(TP5_Ratio) + '", "symbol": "'+ pairCurrency +'", "passphrase": "1234"}'
closeShortSL ='{"side": "CloseShort", "amount": "%'+ tostring(SL_Ratio) + '", "symbol": "'+ pairCurrency +'", "passphrase": "1234"}'

enterLong=buySignal and FastMA>SlowMA or buy and trend == 1
enterShort=sellSignal or sell and trend == -1

strategy.entry("Long",true,when=enterLong,comment=buytext,alert_message=buytext)
strategy.close("Long",when=sellSignal,comment='Close buy',alert_message=closeLongSL)
strategy.entry("Short",false,when=enterShort,comment=selltext,alert_message=selltext)
strategy.close("Short",when=buySignal,comment='Close Sell',alert_message=closeShortSL)

if (strategy.position_size > 0)
strategy.exit("TP1", from_entry="Long", qty = initial_position_size * TP1_Ratio, limit = TP1,comment='TP 8%',alert_message=closeLongTP1)
strategy.exit("TP2", from_entry="Long", qty = initial_position_size * TP2_Ratio, limit = TP2,comment='TP 16%',alert_message=closeLongTP2)
strategy.exit("TP3", from_entry="Long", qty = initial_position_size * TP3_Ratio, limit = TP3,comment='TP 24%',alert_message=closeLongTP3)
strategy.exit("TP4", from_entry="Long", qty = initial_position_size * TP4_Ratio, limit = TP4,comment='TP 32%',alert_message=closeLongTP4)
strategy.exit("TP5", from_entry="Long", qty = initial_position_size * TP5_Ratio, limit = TP5,comment='TP 40%',alert_message=closeLongTP5)
strategy.exit("Stop loss Long", from_entry="Long",qty_percent=100, stop = SL,comment='Stop loss Buy',alert_message=closeLongSL)

if (strategy.position_size < 0)
strategy.exit("TP1", from_entry="Short", qty = initial_position_size * TP1_Ratio, limit = TP1,comment='TP 8%',alert_message=closeShortTP1)
strategy.exit("TP2", from_entry="Short", qty = initial_position_size * TP2_Ratio, limit = TP2,comment='TP 16%',alert_message=closeShortTP2)
strategy.exit("TP3", from_entry="Short", qty = initial_position_size * TP3_Ratio, limit = TP3,comment='TP 24%',alert_message=closeShortTP3)
strategy.exit("TP4", from_entry="Short", qty = initial_position_size * TP4_Ratio, limit = TP4,comment='TP 32%',alert_message=closeShortTP4)
strategy.exit("TP5", from_entry="Short", qty = initial_position_size * TP5_Ratio, limit = TP5,comment='TP 40%',alert_message=closeShortTP5)
strategy.exit("Stop loss Short", from_entry="Short", qty_percent=100, stop = SL,comment='Stop loss Sell',alert_message=closeShortSL)



Views: 97, posted on: 2022-02-27