
トレンドブロック戦略は,価格変化のパーセントまたは跳躍点数に基づいて対角線配列を行う取引戦略である.これは,グラフにローカルなトレンドとターニングポイントを明確に示すことができる.これは価格の方向を追跡するための非常に有用なツールである.
この戦略の計算は,価格変動のパーセントまたは跳躍点偏差 (偏差パラメータで表される) に基づいて,対角線形の形でグラフに表示される.
各行は,基準の中線,上限線,下限線から構成される.
基準中央線は,前行または次の行の上限線または下限線に等しい. (もし価格が時間間隔で急速に変化するならば,現在の行の中央線は,前行の上限線より大きく,または次の行の下限線より小さい.これは,価格変化の方向に応じて,等しい数の偏差である).計算を開始する際には,基準中央線は,最初の行の最初の値に等しい.
数パラメータは,価格変化方向の上限線または下限線による偏差量を決定し,回転パラメータは,価格変化方向を変える偏差量を決定する.
新しい行を作るルール:
閉盘価格が上限線以上で閉盘価格が開盘価格以上である場合,上限線は徐々に上向きに移動し,下限線も上向きに移動するが,幅は小さい.
最低値≤下限値と閉盘値<開盤値の場合は,下限線は徐々に下移し,上限線も下移するが幅は小さい.
偏差値の調整によって,グラフ上でローカルなトレンドとターニングポイントをはっきりと見ることができます. これは価格の動きを追跡するための非常に有用なツールです.
価格の変化の傾向を視覚的に表示し,サポート・レジスタンスを明確に識別する.
角線は突破の強度と回調の範囲を明確に示す.
角線の傾きを調整する必要があるので,異なる強さのトレンドを識別できます.
反対側にある大きな抵抗を見つけ,それを突破する.
価格のペースの変化を容易に見ることができ,ポジションを調整できます.
角線は,後続の価格動きを完全に正確に予測することはできません.
価格の偏差に注意してください. 角線と実際の価格との間には違いが生じることがあります.
単一の策略として使用できないので,他の指標と組み合わせて大きなトレンドを判断する必要があります.
パラメータを正しく調整しない場合,取引が頻発する可能性があることに注意してください.
機械的に盲目追跡できないため,呼び出し時に警報の反転が必要である可能性.
ポジションの規模を適切に縮小し,他の指標を補助判断として参照し,大トレンドの下で操作することができる.
ポジション管理モジュールが追加され,トレンドの異なる段階でポジションを動的に調整できます.
波動率の指標と組み合わせて,波動が大きくなるとポジションを下げる.
単一損失を制御するために,撤回比率に基づいてストップ・ロスを設定できます.
フィルターを追加して,価格の偏差が発生したときに取引を一時停止します.
複数のレベルの対角斜率を区分して,異なる強さの傾向変化を識別することができる.
ポジションを動的に調整し,ストップとフィルター条件を設定することで,価格の傾向をより安定的に追跡することができます.
トレンドブロック戦略は,対角線の直視的な価格傾向の変化を利用して,サポートレジスタンスと突破口を明確に識別できます. しかし,対角線の独立した判断に依存することはできません.リスクを管理しながら,他の指標と併せて総合的な分析を行う必要があります. これは,トレーダーが市場リズムをよりよく把握するのを助ける非常に価値のある補助ツールです. 最適化により,戦略をより安定して効率的にすることができます.
/*backtest
start: 2023-10-06 00:00:00
end: 2023-11-05 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
// **********************************************************************************
// This code is invented and written by @StCogitans.
// The idea presented in this code and the rights to this code belong to @StCogitans.
// © https://www.tradingview.com/u/StCogitans
//
// Description.
// Sizeblock - a price change strategy in the form of diagonal rows.
// **********************************************************************************
// STRATEGY
string NAME = 'Sizeblock'
string ACRONYM = 'SB'
bool OVERLAY = true
int PYRAMIDING = 0
string QTY_TYPE = strategy.percent_of_equity
float QTY_VALUE = 100
float CAPITAL = 100
string COM_TYPE = strategy.commission.percent
float COM_VALUE = 0.1
bool ON_CLOSE = false
bool BAR_MAGNIFIER = false
bool OHLC = true
strategy(NAME, ACRONYM, OVERLAY, pyramiding=PYRAMIDING, default_qty_type=QTY_TYPE, default_qty_value=QTY_VALUE, initial_capital=CAPITAL, commission_type=COM_TYPE, commission_value=COM_VALUE, process_orders_on_close=ON_CLOSE, use_bar_magnifier=BAR_MAGNIFIER, fill_orders_on_standard_ohlc=OHLC)
// ARGUMENTS
// Datetime
DTstart = input(timestamp("01 Jan 2000 00:00 +0000"), 'Start time', group='Datetime')
DTfinish = input(timestamp("01 Jan 2080 23:59 +0000"), 'Finish time', group='Datetime')
DTperiod = true
// Main
dev_source = input.string('Close', title='Source', options=["Close", "HighLow"], tooltip='Price data for settlement.', group='Main')
dev_type = input.string('Percentage', title='Deviation', options=['Percentage', 'Ticks'], tooltip='The type of deviation to calculate.', group='Main')
dev_value = input.float(1, title='Quantity', minval=0.001, step=0.01, tooltip='Quantity to be calculated.', group='Main')
dev_back = input.float(2, title='U-turn', minval=0.001, step=0.01, tooltip='Quantity for reversal.', group='Main')
mode = input.string('Limit', title='Positions', options=['Limit', 'Market'], tooltip='Limit or market orders.', group='Main')
direct = input.string('All', title='Direction', options=['All', 'Buy', 'Sell'], tooltip='The type of positions to be opened.', group='Main')
swapping = input.bool(false, title='Swapping', tooltip='Swap points to open a new position.', group='Main')
// CALCULATION SYSTEM
Assembling(s, t, v, vb) =>
float a = open
float b = close
float c = s == "HighLow" ? math.round_to_mintick(high) : math.round_to_mintick(b)
float d = s == "HighLow" ? math.round_to_mintick(low) : math.round_to_mintick(b)
float x = math.round_to_mintick(a)
x := nz(x[1], x)
float _v = t == "Ticks" ? syminfo.mintick * v : v
float _vb = t == "Ticks" ? syminfo.mintick * vb : vb
float h = t == "Ticks" ? math.round_to_mintick(x + _v) : math.round_to_mintick(x * (1 + _v / 100))
float l = t == "Ticks" ? math.round_to_mintick(x - _v) : math.round_to_mintick(x * (1 - _v / 100))
h := nz(h[1], h)
l := nz(l[1], l)
if t == "Ticks"
if c >= h and b > a
while c >= h
x := h
h := math.round_to_mintick(h + _v)
l := math.round_to_mintick(x - _vb)
if d <= l and b < a
while d <= l
x := l
l := math.round_to_mintick(l - _v)
h := math.round_to_mintick(x + _vb)
else if t == "Percentage"
if c >= h and b > a
while c >= h
x := h
h := math.round_to_mintick(h * (1 + _v / 100))
l := math.round_to_mintick(x * (1 - _vb / 100))
if d <= l and b < a
while d <= l
x := l
l := math.round_to_mintick(l * (1 - _v / 100))
h := math.round_to_mintick(x * (1 + _vb / 100))
[x, h, l]
[lx, lh, ll] = Assembling(dev_source, dev_type, dev_value, dev_back)
// PLOT
// Lines
plot_up = plot(lh, color=color.new(color.green, 50), style=plot.style_line, linewidth=1)
plot_main = plot(lx, color=color.new(color.silver, 50), style=plot.style_line, linewidth=1)
plot_down = plot(ll, color=color.new(color.red, 50), style=plot.style_line, linewidth=1)
// Areas
fill(plot_up, plot_main, lh, lx, color.new(color.teal, 80), color.new(color.teal, 80))
fill(plot_main, plot_down, lx, ll, color.new(color.maroon, 80), color.new(color.maroon, 80))
// TRADING
// Alert variables
int Action = -1
int PosType = -1
int OrderType = -1
float Price = -1.0
// Direction variables
bool ifBuy = direct == "All" or direct == "Buy" ? true : false
bool ifSell = direct == "All" or direct == "Sell" ? true : false
// Market entries
if (strategy.closedtrades + strategy.opentrades == 0 or mode == "Market") and DTperiod
if ((swapping and lx < nz(lx[1], lx)) or (not swapping and lx > nz(lx[1], lx))) and ifBuy
Action := 1
PosType := 1
OrderType := 1
Price := math.round_to_mintick(close)
strategy.entry('Long', strategy.long)
if ((swapping and lx > nz(lx[1], lx)) or (not swapping and lx < nz(lx[1], lx))) and ifSell
Action := 2
PosType := 2
OrderType := 1
Price := math.round_to_mintick(close)
strategy.entry('Short', strategy.short)
// Closing positions by market
if DTperiod and mode == "Market"
if direct == "Buy" and strategy.position_size > 0
if swapping and lx > nz(lx[1], lx)
Action := 2
PosType := 3
OrderType := 1
Price := math.round_to_mintick(close)
strategy.close('Long', comment='Close')
if not swapping and lx < nz(lx[1], lx)
Action := 2
PosType := 3
OrderType := 1
Price := math.round_to_mintick(close)
strategy.close('Long', comment='Close')
if direct == "Sell" and strategy.position_size < 0
if swapping and lx < nz(lx[1], lx)
Action := 1
PosType := 3
OrderType := 1
Price := math.round_to_mintick(close)
strategy.close('Short', comment='Close')
if not swapping and lx > nz(lx[1], lx)
Action := 1
PosType := 3
OrderType := 1
Price := math.round_to_mintick(close)
strategy.close('Short', comment='Close')
// Limit entries and exits
if swapping and DTperiod and mode == "Limit"
if strategy.position_size < 0
Action := 1
PosType := 1
OrderType := 2
Price := ll
if ifBuy
strategy.entry('Long', strategy.long, limit=ll)
else
PosType := 3
strategy.exit('Exit', limit=ll)
if strategy.position_size > 0
Action := 2
PosType := 2
OrderType := 2
Price := lh
if ifSell
strategy.entry('Short', strategy.short, limit=lh)
else
PosType := 3
strategy.exit('Exit', limit=lh)
if strategy.closedtrades + strategy.opentrades > 0 and strategy.position_size == 0
if ifBuy
Action := 1
PosType := 1
OrderType := 2
Price := ll
strategy.entry('Long', strategy.long, limit=ll)
if ifSell
Action := 2
PosType := 2
OrderType := 2
Price := lh
strategy.entry('Short', strategy.short, limit=lh)
if not swapping and DTperiod and mode == "Limit"
if strategy.position_size < 0
Action := 1
PosType := 1
OrderType := 2
Price := lh
if ifBuy
strategy.entry('Long', strategy.long, stop=lh)
else
PosType := 3
strategy.exit('Exit', stop=lh)
if strategy.position_size > 0
Action := 2
PosType := 2
OrderType := 2
Price := ll
if ifSell
strategy.entry('Short', strategy.short, stop=ll)
else
PosType := 3
strategy.exit('Exit', stop=ll)
if strategy.closedtrades + strategy.opentrades > 0 and strategy.position_size == 0
if ifBuy
Action := 1
PosType := 1
OrderType := 2
Price := lh
strategy.entry('Long', strategy.long, stop=lh)
if ifSell
Action := 2
PosType := 2
OrderType := 2
Price := ll
strategy.entry('Short', strategy.short, stop=ll)
// Everything is closed and canceled
if not DTperiod
strategy.cancel_all()
strategy.close_all(comment='Close')
// Alerts
// Convert to string variables
string Action_Txt = Action == 1 ? "Buy" : Action == 2 ? "Sell" : na
string PosType_Txt = PosType == 1 ? "Long" : PosType == 2 ? "Short" : PosType == 3 ? "Flat" : na
string OrderType_Txt = OrderType == 1 ? "Market" : OrderType == 2 ? "Limit" : na
string Price_Txt = Price > 0 ? str.tostring(Price) : na
// Output
if not (Action == nz(Action[1], Action) and Price == nz(Price[1], Price) and OrderType == nz(OrderType[1], OrderType)) and DTperiod
alert('{"pair": "' + syminfo.ticker + '", "direction": "' + Action_Txt + '", "entertype": "' + OrderType_Txt + '", "position": "' + PosType_Txt + '", "price": "' + Price_Txt + '"}')
// *********************
// Good job, Soldier! ;>
// *********************