Untitled

 avatar
unknown
plain_text
a year ago
2.9 kB
18
Indexable
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ScryptoMB

//@version=5
strategy(title='My Strategy', 
 overlay=true, 
 initial_capital=10000, 
 pyramiding=16, 
 calc_on_order_fills=false, 
 process_orders_on_close=false, 
 calc_on_every_tick=true,
 backtest_fill_limits_assumption=1,
 slippage=2,
 commission_type=strategy.commission.percent, 
 commission_value=0.03,
 use_bar_magnifier=false,
 close_entries_rule="ANY")

rsiLength = input.int(14, title='RSI Length')
longValue = input.float(25, title='RSI Long Value')
tp1Long = input.float(1, title='TP Long %')
stopLong = input.float(20, title='SL Long %')

rsi = ta.rsi(close, rsiLength)
rsiLong = ta.crossunder(rsi, longValue)
rsiSO1 = ta.crossunder(rsi, longValue) and strategy.opentrades == 1
rsiSO2 = ta.crossunder(rsi, longValue) and strategy.opentrades == 2
rsiSO3 = ta.crossunder(rsi, longValue) and strategy.opentrades == 3
rsiSO4 = ta.crossunder(rsi, longValue) and strategy.opentrades == 4
rsiSO5 = ta.crossunder(rsi, longValue) and strategy.opentrades == 5

TP1Lperc = strategy.position_avg_price * (1 + (tp1Long * 0.01))
SLLperc = strategy.opentrades.entry_price(0) * (1 - (stopLong * 0.01))

// Entry logic
if rsiLong
    if strategy.position_size == 0
        strategy.entry("Base Order Long", strategy.long, qty=0.2, comment="Base Order L")

if rsiSO1
    strategy.entry("Safety Order 1", strategy.long, qty=0.4, comment="SO 1")

if rsiSO2
    strategy.entry("Safety Order 2", strategy.long, qty=0.8, comment="SO 2")

if rsiSO3
    strategy.entry("Safety Order 3", strategy.long, qty=0.16, comment="SO 3")

if rsiSO4
    strategy.entry("Safety Order 4", strategy.long, qty=0.32, comment="SO 4")

if rsiSO5
    strategy.entry("Safety Order 5", strategy.long, qty=0.64, comment="SO 5")



// Exit logic
if strategy.position_size > 0
    strategy.exit('Exit Long Base', 'Base Order Long', qty_percent=100, limit=TP1Lperc, stop=SLLperc)
    strategy.exit('Exit Safety 1', 'Safety Order 1', qty_percent=100, limit=TP1Lperc, stop=SLLperc)
    strategy.exit('Exit Safety 2', 'Safety Order 2', qty_percent=100, limit=TP1Lperc, stop=SLLperc)
    strategy.exit('Exit Safety 3', 'Safety Order 3', qty_percent=100, limit=TP1Lperc, stop=SLLperc)
    strategy.exit('Exit Safety 4', 'Safety Order 4', qty_percent=100, limit=TP1Lperc, stop=SLLperc)
    strategy.exit('Exit Safety 5', 'Safety Order 5', qty_percent=100, limit=TP1Lperc, stop=SLLperc)

plotshape(rsiLong, location=location.belowbar, style=shape.labelup, text='Long', textcolor=color.white, color=color.teal)

entryLevel = plot(strategy.position_avg_price, title="Entry level", color=color.white, linewidth=1, style=plot.style_linebr) 
takeProfit = plot(TP1Lperc, title="TP", color=color.teal, linewidth=1, style=plot.style_linebr) 
stopLoss = plot(SLLperc, title="SL", color=color.red, linewidth=1, style=plot.style_linebr) 
Editor is loading...
Leave a Comment