1 Mins Strategy
1 Mins Strategy
0 at
https://mozilla.org/MPL/2.0/
// © Samuel Ralte
//@version=5
strategy("1 mins strategy ", overlay=true)
// Inputs
group0 = "Sell Sensitivity"
a = input(2, title="Sensitivity", group = group0)
c = input(1, title='ATR Period',group = group0)
h = true
xATR = ta.atr(c)
nLoss = a * xATR
xATRTrailingStop = 0.0
iff_1 = src > nz(xATRTrailingStop[1], 0) ? src - nLoss : src + nLoss
iff_2 = src < nz(xATRTrailingStop[1], 0) and src[1] < nz(xATRTrailingStop[1], 0) ?
math.min(nz(xATRTrailingStop[1]), src + nLoss) : iff_1
xATRTrailingStop := src > nz(xATRTrailingStop[1], 0) and src[1] >
nz(xATRTrailingStop[1], 0) ? math.max(nz(xATRTrailingStop[1]), src - nLoss) : iff_2
pos = 0
iff_3 = src[1] > nz(xATRTrailingStop[1], 0) and src < nz(xATRTrailingStop[1], 0) ?
-1 : nz(pos[1], 0)
pos := src[1] < nz(xATRTrailingStop[1], 0) and src > nz(xATRTrailingStop[1], 0) ? 1
: iff_3
emaa = ta.ema(src, 1)
///////////////////////////////////
xATRTrailingStop1 = 0.0
iff_11 = src1 > nz(xATRTrailingStop1[1], 0) ? src1 - nLoss1 : src1 + nLoss1
iff_21 = src1 < nz(xATRTrailingStop1[1], 0) and src1[1] < nz(xATRTrailingStop1[1],
0) ? math.min(nz(xATRTrailingStop1[1]), src1 + nLoss1) : iff_11
xATRTrailingStop1 := src1 > nz(xATRTrailingStop1[1], 0) and src1[1] >
nz(xATRTrailingStop1[1], 0) ? math.max(nz(xATRTrailingStop1[1]), src1 - nLoss1) :
iff_21
pos1 = 0
iff_31 = src1[1] > nz(xATRTrailingStop1[1], 0) and src1 < nz(xATRTrailingStop1[1],
0) ? -1 : nz(pos1[1], 0)
pos1 := src1[1] < nz(xATRTrailingStop1[1], 0) and src1 > nz(xATRTrailingStop1[1],
0) ? 1 : iff_31
ema1aa = ta.ema(src1, 1)
// //////////////////////////////
EEEEEE = 80
BBBB = 27
BBBBB = 50
if mAAAAA[3] <= mAAAAA[2] and mAAAAA[2] > mAAAAA[1] and mAAAAA > 75
alert('Red', alert.freq_once_per_bar)
if mAAAAA[3] >= mAAAAA[2] and mAAAAA[2] < mAAAAA[1] and mAAAAA < 25
alert('Green', alert.freq_once_per_bar)
// EMA Filter
// i_emaFilterEnabled = input.bool(defval = true , title = "Enable EMA Filter")
i_emaSource = input.source(close,"EMA Source" ,group = "Moving Average")
ema_type = input.string("EMA", title="Choose MA type", options=["EMA", "SMA",
"WMA","Zero_Lag_Tema","Zero_Lag_EMA"])
ema_length = input(30, "Length")
enable_plot = input(false,title = "Plot MA")
// colorbars = input.bool(true, "Color bars?", group="UI Options")
ema_color = color.lime
ema = 0.0
zlagtema(float src, simple int len) =>
float ema1 = ta.ema(src, len)
float ema2 = ta.ema(ema1, len)
float ema3 = ta.ema(ema2, len)
float out = 3 * (ema1 - ema2) + ema3
float ema1a = ta.ema(out, len)
float ema2a = ta.ema(ema1a, len)
float ema3a = ta.ema(ema2a, len)
float outf = 3 * (ema1a - ema2a) + ema3a
outf
lag = math.floor((ema_length - 1) / 2)
if ema_type == "SMA"
ema := ta.sma(i_emaSource, ema_length)
else if ema_type == "WMA"
ema := ta.wma(i_emaSource, ema_length)
else if ema_type == "EMA"
ema := ta.ema(i_emaSource, ema_length)
else if ema_type == "Zero_Lag_Tema"
ema := zlagtema(i_emaSource, ema_length)
else if ema_type == "Zero_Lag_EMA"
ema := ta.ema(close + close - close[lag], ema_length)
long = b1 and mAAAAA > mAAAAA[1] and mAAAAA < 25 and abovema
short = s1 and mAAAAA < mAAAAA[1] and mAAAAA > 75 and belowma
plotshape(long,title = "Buy",style = shape.labelup,location =
location.belowbar,text = "Long",textcolor = color.white,color = color.teal,size =
size.small)
plotshape(short,title = "Sell",style = shape.labeldown,location =
location.abovebar,text = "Short",textcolor = color.white,color = color.maroon,size
= size.small)
// Leverage
leverage = input.float(2.0, "Leverage", minval=1.0, maxval=20.0,group="Leverage")
// Input options
riskPercentage = input.float(100, "Risk Percentage", minval=1, maxval=100)
if isStartEndPeriodsAndTimeInRange
if long
strategy.entry('LONG', strategy.long, qty=(strategy.equity * riskPercentage
/ 100 / close) * leverage)
if short
strategy.entry('SHORT', strategy.short, qty=(strategy.equity *
riskPercentage / 100 / close) * leverage)
// Input options
atrValue = ta.atr(14)
stopLossType = input.string("ATR", "Stop Loss Type", options=["ATR",
"Percent"],group = "STOP LOSS/TAKE PROFIT TYPE")
takeProfitType = input.string("R/R","Take Profit Type",options = ["R/R","Percent"])
// TP/SL PERCENT
// TP/SL ATR
atrMultiplier = input(2.5, "Atr Stoploss", group="Stoploss/Take Profit")
stopPer = input(1.0, title="Stop Loss %") / 100
// TP/SL
takeProfitMultiple = input(1.0, title='Risk/Rward',group = "TAKE PROFIT")
takePer1 = input(2.5, title='Take Profit 1 %') / 100
useTwoTakeProfit = input.bool(true, "Use Take Profits 2")
takePer2 = input(3.0, title='Take Profit 2 %') / 100
takeProfitpercent1 = input.float(30, "Take Profit 1 Percent",tooltip = "Will only
effect if take profit 2 is enable")
if stopLossType == "ATR"
stopLossLong := strategy.position_avg_price - (atrValue * atrMultiplier)
stopLossShort := strategy.position_avg_price + (atrValue * atrMultiplier)
else
stopLossLong := strategy.position_avg_price * (1 - stopPer)
stopLossShort := strategy.position_avg_price * (1 + stopPer)
if takeProfitType == "R/R"
shortTake1 := strategy.position_avg_price - takeProfit
longTake1 := strategy.position_avg_price + takeProfit
else
shortTake12 := strategy.position_avg_price * (1 - takePer1)
longTake12 := strategy.position_avg_price * (1 + takePer1)
shortTake4 := strategy.position_avg_price * (1 - takePer2)
longTake4 := strategy.position_avg_price * (1 + takePer2)
// Exit conditions
if strategy.position_size > 0
if takeProfitType == "R/R"
strategy.exit("tp/sl_1", stop=stopLossLong, limit=longTake1)
if useTwoTakeProfit
strategy.exit("tp/sl_2", stop=stopLossLong, limit=longTake4)
else
strategy.exit("tp/sl_1", stop=stopLossLong, limit=longTake12,
qty=takeProfitpercent)
if useTwoTakeProfit
strategy.exit("tp/sl_2", stop=stopLossLong, limit=longTake4)
if strategy.position_size < 0
if takeProfitType == "R/R"
strategy.exit("tp/sl_1", stop=stopLossShort, limit=shortTake1)
if useTwoTakeProfit
strategy.exit("tp/sl_2", stop=stopLossShort, limit=shortTake4)
else
strategy.exit("tp/sl_1", stop=stopLossShort, limit=shortTake12,
qty=takeProfitpercent)
if useTwoTakeProfit
strategy.exit("tp/sl_2", stop=stopLossShort, limit=shortTake4)
// Dashboard
if newWin
lossRow := 0
winRow := winRow + 1
if winRow > maxWinRow
maxWinRow := winRow
if newLoss
winRow := 0
lossRow := lossRow + 1
if lossRow > maxLossRow
maxLossRow := lossRow
if barstate.islastconfirmedhistory
// Update table
lastTime = strategy.position_size == 0 ?
strategy.closedtrades.exit_time(strategy.closedtrades-1) : time
dollarReturn = strategy.netprofit
f_fillCell(dashTable, 0, 2, "Start Trade:", str.format("{0,date,long}",
strategy.closedtrades.entry_time(0)) , bgcolor, color.new(color.white,0))
// f_fillCell(dashTable, 1, 2, "End:", str.format("{0,date,long}",
lastTime) , bgcolor, color.white)
_profit = (strategy.netprofit / strategy.initial_capital) * 100
f_fillCell(dashTable, 2, 2, "Net Profit:", str.tostring(_profit, '##.##') +
"%", color.new(color.black,100), _profit > 0 ? color.green : color.red)
_numOfDaysInStrategy = (lastTime - strategy.closedtrades.entry_time(0)) /
(1000 * 3600 * 24)
f_fillCell(dashTable, 3, 2, "Percent Per Day", str.tostring(_profit /
_numOfDaysInStrategy, '#########################.#####')+"%",
color.new(color.black,100), _profit > 0 ? color.green : color.red)
_winRate = ( strategy.wintrades / strategy.closedtrades ) * 100
f_fillCell(dashTable, 4, 2, "Percent Profitable:", str.tostring(_winRate,
'##.##') + "%", color.new(color.black,100), _winRate < 50 ? color.red : _winRate <
75 ? #999900 : color.green)
f_fillCell(dashTable, 5, 2, "Profit Factor:",
str.tostring(strategy.grossprofit / strategy.grossloss, '##.###'),
color.new(color.black,100),strategy.grossprofit > strategy.grossloss ?
color.green : color.red)
f_fillCell(dashTable, 6, 2, "Total Trades:",
str.tostring(strategy.closedtrades), bgcolor, color.white)
f_fillCell(dashTable, 7, 2, "Winning Trades:",
str.tostring(strategy.wintrades),color.new(color.black,100), strategy.wintrades >
strategy.losstrades ? color.green : color.red)
f_fillCell(dashTable, 8, 2, "Losing Trades:",
str.tostring(strategy.losstrades),color.new(color.black,100),strategy.wintrades <
strategy.losstrades ? color.green : color.red)
f_fillCell(dashTable, 9, 2, "Max Wins In A Row:", str.tostring(maxWinRow,
'######') , bgcolor,maxWinRow > maxLossRow ? color.rgb(13, 196, 242) : color.red)
f_fillCell(dashTable, 10, 2, "Max Losses In A Row:",
str.tostring(maxLossRow, '######') , bgcolor, color.rgb(142, 147, 166))