IU Opening range Breakout Strategy

Shivam_Mandrai · strategy · 69 行 · 点赞 460 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Shivam_Mandrai
 
//@version=6
strategy('IU Opening range Breakout Strategy', overlay = true)
 
//________________________________ User input ___________________________________________________\\
RTR = input.float(2.00, 'RTR =  ', tooltip = 'Set the Risk To Reward')
max_trades = input.int(2, 'Max trades in a day = ') * 2
days_end_time = input.session("1500-1515", "End of day Time = ", tooltip = "At this time all of the open potions will close")
//----------- setting the max trade allow ---------- \\
strategy.risk.max_intraday_filled_orders(max_trades, 'Max trade allow limit is filled')
 
//________________________________ Getting the Opening range ____________________________________\\
opening_range_high = ta.valuewhen(session.isfirstbar, high, 0)
opening_range_low = ta.valuewhen(session.isfirstbar, low, 0)
//-----plotting high and low ---- \\
plot(opening_range_high, 'Opening range high', color.lime, 2, style = plot.style_circles)
plot(opening_range_low, 'Opening range high', color.red, 2, style = plot.style_circles)
 
 
//_______________________________ goning long and short __________________________________________\\
//----- going long -----\\
if ta.crossover(close, opening_range_high) and strategy.position_size == 0 and barstate.isconfirmed
    strategy.entry('long', strategy.long, comment = 'Long Entry')
    //----- going short ----\\
if ta.crossunder(close, opening_range_low) and strategy.position_size == 0 and barstate.isconfirmed
    strategy.entry('short', strategy.short, comment = 'short Entry')
 
 
//______________________________ long SL and TP ___________________________________________________\\
//------ previous candle low as an SL --------\\
long_SL = ta.valuewhen(strategy.position_size > 0 and strategy.position_size[1] == 0, low[1], 0)
long_TP = strategy.position_avg_price + (strategy.position_avg_price - long_SL) * RTR
if strategy.position_size > 0
    strategy.exit('long', 'long', stop = long_SL, limit = long_TP, comment = 'long Exit')
 
 
//______________________________ short SL and TP ___________________________________________________\\
//------ previous candle high as an SL --------\\
short_SL = ta.valuewhen(strategy.position_size < 0 and strategy.position_size[1] == 0, high[1], 0)
short_TP = strategy.position_avg_price - (short_SL - strategy.position_avg_price) * RTR
if strategy.position_size < 0
    strategy.exit('short', 'short', stop = short_SL, limit = short_TP, comment = 'short Exit')
 
 
//______________________________ Plotting long and short SL , TP ___________________________________\\
// ---- for long positions ------ \\
long_SL_plot = plot(strategy.position_size[1] > 0 ? long_SL : na, 'Long SL', color.red, style = plot.style_linebr)
long_TP_plot = plot(strategy.position_size[1] > 0 ? long_TP[1] : na, 'Long TP', color.green, style = plot.style_linebr)
// ---- for short positions ----- \\
short_SL_plot = plot(strategy.position_size[1] < 0 ? short_SL : na, 'Short SL', color.red, style = plot.style_linebr)
short_TP_plot = plot(strategy.position_size[1] < 0 ? short_TP[1] : na, 'Short SL', color.green, style = plot.style_linebr)
 
 
//______________________________ Exit at the end of the day _____________________________________\\
end_of_day = time("", days_end_time)
if not na(end_of_day)
    strategy.close_all("End of the day exit")
 
 
//______________________________ Filling stop loss and take profits ______________//
entry_plot = plot(strategy.position_size[1] != 0 ? strategy.position_avg_price[1] : na, color = color.new(color.silver, 20), style = plot.style_linebr)
// ------------- for long ----------- \\
fill(entry_plot, long_SL_plot, color.new(color.red, 85), 'Long SL plot')
fill(entry_plot, long_TP_plot, color.new(color.green, 85), 'Long TP plot')
// ------------- for short ---------- \\ 
fill(entry_plot, short_SL_plot, color.new(color.red, 85), 'Short SL plot')
fill(entry_plot, short_TP_plot, color.new(color.green, 85), 'Short TP plot')

← 返回列表