
この戦略は,価格のパーセント変化を利用して買入ラインと止損ラインを設定し,価格が買入ラインを破った時にポジションを建設し,止損ラインの下での止損を行う.その主な特徴は,単位のリスクのみを担うことであり,つまり,前回のポジションが既定の収益目標に達したときにのみポジションを上げる.
この戦略は,まず,基準価格を設定し,この価格の10%を価格区間として,上辺は買取ライン,下辺は止損ラインとする.価格が買取ラインを破るとき,固定数で購入する.価格が止損ラインを破るとき,平仓止損する.利益を得た後に,買取ラインと止損ラインは,利益区間を拡大するために,パーセントで調整される.
この戦略のもう一つの重要なポイントは,単位のリスクのみを担うことである.つまり,現在のポジションが収益目標に達した後にのみ,新しいポジションを倉庫に入れることである.新しいポジションは,新しい買入線と止損線で設定されることもである.このことは,リスクを制限することができる.
この戦略は,ストップトラッキングと倉庫管理の優位性を組み合わせて,リスクを効果的に管理し,同時に利益を得ることができます.
この戦略にはいくつかのリスクがあります.
これらのリスクは,パーセンテージ区画のサイズを調整し,加仓条件を調整するなど,パラメータの調整によって回避できます.
この戦略をさらに改善する余地があります.
これは,パーセンテージ区間を利用して取引する戦略である.これは,シンプルで実用的で,リスクを効果的に制御している.パラメータ調整とモデルの最適化により,この戦略は,投資家に安定した余剰利益を生み出す,信頼できるトレンド追跡システムになることができる.
/*backtest
start: 2022-11-16 00:00:00
end: 2023-11-22 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HermanBrummer 4 April 2021
strategy ("The Box Percent Strat", shorttitle="The Box", overlay = true)
/// Designed for LONG only on Daily, 2D or 3D Charts
/// Uses fixed investment risk amount, meaning you're willing to lose that amount per trade
/// Limit buy to not overpay
RiskPerTrade = input(10000, "Risk losing this much per trade", tooltip="This calculates how much you will lose based on difference between the entry price and stop loss price")
TradeAboveMAFilterPer = input(50, "The System won't trade if price is below this MA")
UpBoxSize = (input(10, "Box size in %") * 0.01)+1 // 1.1 == 10% up
DnBoxSize = 1-(input(10, "Box size in %") * 0.01) // 0.9 == 10% dn
var FirstBar = close > 0 ? close : na
var FirstTop = FirstBar * UpBoxSize
var FirstBot = FirstBar * DnBoxSize
var top = sma(FirstTop, 1)
var bot = sma(FirstBot, 1)
/// The Box Calcs
if high[2] > top
top := top * UpBoxSize
bot := bot * UpBoxSize
if low[1] < bot
top := top * DnBoxSize
bot := bot * DnBoxSize
plot(bot, "Bot", #ff0000) // Green
plot(top, "Top", #00ff00) // Red
mid = ((top-bot)/2)+bot
plot(mid, "Mid", color.gray)
TradeAboveMAFilter = sma(close, TradeAboveMAFilterPer)
plot(TradeAboveMAFilter, "Trade AboveMAF Filter", color.yellow, 3, style=plot.style_circles)
// col = high[1] < top and high >= top ? color.white : na
// bgcolor(col)
/// Shares
RiskRange = close * abs(DnBoxSize - 1) // 0.9 - 1 == 1.10 // 10% abs so you don't get a neg number NB NB
Shares = RiskPerTrade / RiskRange
//plot(close-RiskRange, "RiskRange", color.fuchsia)
Enter = high >= top
and close[1] > TradeAboveMAFilter
and strategy.opentrades[0] == strategy.opentrades[1]
and strategy.opentrades[1] == strategy.opentrades[2]
and strategy.opentrades[2] == strategy.opentrades[3]
and strategy.opentrades[3] == strategy.opentrades[4]
and strategy.opentrades[4] == strategy.opentrades[5]
and strategy.opentrades[5] == strategy.opentrades[6]
// won't enter if new positon was taken in the last 6 bars
// need better code for this.
/// Buy & Sell
// (new highs) and (Close above moving average filter) and (No new trades were taken receently)
if Enter //(high >= top) and (close[1] > TradeAboveMAFilter) and strategy.opentrades[0] == strategy.opentrades[1]
strategy.order("En", strategy.long, qty=Shares, limit=top)//, stop=top)
//barcolor(strategy.position_size != 0 ? #00ff00 : color.gray)
// /// If ONE Position THEN this Stop Because:
// if strategy.position_size == 1
// strategy.exit("Ex", "En", stop=bot)
/// If it has more than one trad OPEN
if strategy.position_size > 0
strategy.exit("Ex", "En", stop=bot[2] ) // puts stop on old bot
//plot(strategy.position_avg_price, "Avg Price", color.yellow)