How to trigger multiple buy and sell signals when conditions to open and close trades are met

Would love someones help with the below code. I’m trying to open multiple buy and sell orders when the following conditions are met:

For a long trade to be opened, RSI has to be above 50, Tenkan crosses over the Kijun, price is above kumo
and if an open long trade has been closed the entry has to be above the previous closed long’s price with all long conditions still valid.

A long trade can be closed either with a stop loss or take profit.

For a short trade to be opened, RSI has to be below 50, Tenkan crosses under the Kijun, price is below kumo and if an short long trade has been closed, the entry has to be below the previous closed short’s price with all short conditions still valid.

Currently on the daily time-frame it only triggers 2 trades.

Any help for a novice would be much appreciated. Thanks in advance.

//@version=4

//Ichimoku Inputs

ts_bars = input(9, minval=1, title="Tenkan-Sen Bars", group="Ichimoku Cloud")
ks_bars = input(26, minval=1, title="Kijun-Sen Bars", group="Ichimoku Cloud")
ssb_bars = input(52, minval=1, title="Senkou-Span B Bars", group="Ichimoku Cloud")
cs_offset = input(26, minval=1, title="Chikou-Span Offset", group="Ichimoku Cloud")
ss_offset = input(26, minval=1, title="Senkou-Span Offset", group="Ichimoku Cloud")
trade_long = input(true, title="Long Entry", group="Ichimoku Cloud")
trade_short = input(true, title="Short Entry", group="Ichimoku Cloud")

//Stop Loss Inputs

use_short_stop_loss = input(true, title="Short Stop Loss", group="Stop Loss and Take Profit", inline="Short_SL")
short_stop_loss = input(title="(%)", type=input.float, minval=0.0, step=0.1, defval=5, group="Stop Loss and Take Profit", inline="Short_SL") * 0.01
use_long_stop_loss = input(true, title="Long Stop Loss", group="Stop Loss and Take Profit", inline="Long_SL")
long_stop_loss = input(title="(%)", type=input.float, minval=0.0, step=0.1, defval=5, group="Stop Loss and Take Profit", inline="Long_SL") * 0.01

//Take Profit Inputs

use_short_take_profit = input(true, title="Short Take Profit", group="Stop Loss and Take Profit", inline="Short_TP")
short_take_profit = input(title="(%)", type=input.float, minval=0.0, step=0.1, defval = 20, group="Stop Loss and Take Profit", inline="Short_TP")* .01
use_long_take_profit = input(true, title="Long Take Profit", group="Stop Loss and Take Profit", inline="Long_TP")
long_take_profit = input(title="(%)", type=input.float, minval=0.0, step=0.1, defval = 20, group="Stop Loss and Take Profit", inline="Long_TP") * .01

//RSI Inputs

rsi_length = input(defval=14, title="RSI Period", type=input.integer, group="RSI")
mid_rsi = input(defval=50, title="Oversold Level", type=input.float, group="RSI")

//SuperTrend Inputs

atrPeriod = input(10,"ATR Length", minval = 1)
factor =    input(3.0, "Factor",minval = 0.01, step = 0.01)
[supertrend, direction] = supertrend(factor, atrPeriod)

//Plot Supertrend

supertrend := barstate.isfirst ? na : supertrend
upTrend =    plot(direction < 0 ? supertrend : na, "Up Trend",   color = color.blue, style = lot.style_linebr)
downTrend =  plot(direction > 0 ? na : supertrend, "Down Trend", color = color.orange,   style =     plot.style_linebr)
bodyMiddle = plot(barstate.isfirst ? na : (open + close) / 2, "Body Middle",display = display.none)

middle(len) => avg(lowest(len), highest(len))

//Ichimoku Components

tenkan = middle(ts_bars)
kijun = middle(ks_bars)
senkouA = avg(tenkan, kijun)
senkouB = middle(ssb_bars)
chikou = close[cs_offset]

// Plot Ichimoku Kinko Hyo

plot(tenkan, color=#0496ff, title="Tenkan-Sen")
plot(kijun, color=#991515, title="Kijun-Sen")
plot(chikou, color=#caeb36, title="Chikou-Span")
sa=plot(senkouA, offset=ss_offset, color=color.green, title="Senkou-Span A")
sb=plot(senkouB, offset=ss_offset, color=color.red, title="Senkou-Span B")
fill(sa, sb, color = senkouA > senkouB ? color.green : color.red, title="Cloud color")

ss_high = max(senkouA[ss_offset], senkouB[ss_offset])
ss_low = min(senkouA[ss_offset], senkouB[ss_offset])`

// Long and Short Signals

tk_cross_bull = crossover(tenkan, kijun)
tk_cross_bear = crossunder(tenkan, kijun)
rsi = rsi(close, rsi_length)
Long_supertrend = change(direction) < 0
Short_supertrend = change(direction) > 0

// Entry/Exit Confirmation

cs_cross_bull = mom(close, cs_offset) > 0
cs_cross_bear = mom(close, cs_offset) < 0
price_above_kumo = close > ss_high
price_below_kumo = close < ss_low
senkou_green = senkouA > senkouB ? true : false

// Get previous close price of the strategy

prev_close = strategy.position_size[1] > 0 ? strategy.position_avg_price[1] : close[1]

// Entry condition: price above previous close

Closed_long = close > prev_close
Closed_short = close < prev_close

//Entry Conditions

long_entry = tk_cross_bull and rsi > 50 and Long_supertrend and Closed_long and not in_long
short_entry = tk_cross_bear and rsi < 50 and Short_supertrend and Closed_short and not in_short

longStopPrice  = strategy.position_avg_price * (1 - long_stop_loss)
shortStopPrice = strategy.position_avg_price * (1 + short_stop_loss)
longLimitPrice = strategy.position_avg_price * (1 + long_take_profit)
shortLimitPrice = strategy.position_avg_price * (1 - short_take_profit)

strategy.order("Long", strategy.long, when=long_entry)
strategy.order("Short", strategy.short, when=short_entry)
strategy.exit("Long", stop = longStopPrice, limit = longLimitPrice)
strategy.exit("Short", stop = shortStopPrice, limit = shortLimitPrice)

New contributor

Mathew Axhorn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật