OPEN-SOURCE SCRIPT

BENSIG

//version=5
indicator("Swing High/Low Entry Strategy with SL/TP", overlay=true)

// Input for the time range (10:30am to 16:45pm UTC-5)
startTime = timestamp("GMT-5", year, month, dayofmonth, 10, 30)
endTime = timestamp("GMT-5", year, month, dayofmonth, 16, 45)

// Variables to store the highest and lowest swing points within a specific time range
var float swingHigh = na
var float swingLow = na

// Lookback period for calculating swing high and low
lookbackPeriod = 10

// Calculate swing high and low between the specified time period
if (time >= startTime and time <= endTime)
swingHigh := na
swingLow := na
else
swingHigh := ta.highest(high, lookbackPeriod) // Highest high in the last 10 bars
swingLow := ta.lowest(low, lookbackPeriod) // Lowest low in the last 10 bars

// Detect when swing high is broken (swept)
sweepHigh = not na(swingHigh) and high > swingHigh

// Bearish Order Block Detection (simple method using previous bearish candle)
bearishOrderBlock = close[1] > open[1] and close < open

// Buy and Sell logic based on swing high being swept and a bearish order block detected
buyCondition = sweepHigh and bearishOrderBlock
sellCondition = sweepHigh and bearishOrderBlock

// Stop loss and take profit logic
SL_buy = swingHigh
SL_sell = swingLow
TP_buy = swingLow
TP_sell = swingHigh

// Plot Buy and Sell Signals with labels and lines for SL and TP
if (buyCondition)
label.new(bar_index, low, text="BUY", style=label.style_label_up, color=color.green, textcolor=color.white, size=size.small)
line.new(x1=bar_index, y1=SL_buy, x2=bar_index + 10, y2=SL_buy, color=color.red, width=2, extend=extend.right)
line.new(x1=bar_index, y1=TP_buy, x2=bar_index + 10, y2=TP_buy, color=color.green, width=2, extend=extend.right)

if (sellCondition)
label.new(bar_index, high, text="SELL", style=label.style_label_down, color=color.red, textcolor=color.white, size=size.small)
line.new(x1=bar_index, y1=SL_sell, x2=bar_index + 10, y2=SL_sell, color=color.green, width=2, extend=extend.right)
line.new(x1=bar_index, y1=TP_sell, x2=bar_index + 10, y2=TP_sell, color=color.red, width=2, extend=extend.right)

// Alerts
alertcondition(buyCondition, title="Buy Signal", message="Buy signal triggered")
alertcondition(sellCondition, title="Sell Signal", message="Sell signal triggered")
Candlestick analysisChart patternsCycles

オープンソーススクリプト

TradingViewの精神に則り、このスクリプトの作者は、トレーダーが理解し検証できるようにオープンソースで公開しています。作者に敬意を表します!無料で使用することができますが、このコードを投稿で再利用するには、ハウスルールに準拠する必要があります。 お気に入りに登録してチャート上でご利用頂けます。

チャートでこのスクリプトを利用したいですか?

免責事項