
この戦略は,開値と高値の交差による取引信号判断を行う.開値の上で高値の穿越をすると多し,開値の下に高値の穿越をすると空きをする.移動平均を使用することで価格データを平らにし,取引のノイズを減らす.移動平均のタイプとパラメータを構成することができる.また,トラッキングストップを有効に設定して利益をロックするかどうかを構成することができる.
代替周期解析度 ((useRes) を使用するかどうかを入力パラメータに基づいて決定する.使用する場合はstratResに基づいて周期を設定する.
入力パラメータに基づいて移動平均を使用するかどうかを決定する ((useMA) 。使用する場合は,basisTypeに基づいて移動平均のタイプを選択し,basisLenは周期長さを設定する。
オープン価格 ((open) とクローズ価格 ((close)) の一連のデータを取得します.移動平均を使用する場合,選択した移動平均のタイプとパラメータのスムーズ処理を適用します.
現在の開値xと開値シリーズopenSeriesを比較する。xがopenSeriesより大きい場合はトレンドステートは多頭,そうでない場合は空頭である。
値上がり時に多信号 longCond,値下がり時に空調信号 shortCondを生成する.
多頭または空頭ポジションに多頭または空頭ポジションに移動する. 追跡ストップが有効である場合は,ストップポイント位置と偏移距離を設定する.
オープン価格と高価格の2つの異なるシリーズを使用して取引信号判断を行い,単一のデータシリーズの制限を回避する.
移動平均の技術は,短期市場のノイズをフィルタリングし,主要トレンドをロックします.
移動平均の種類を柔軟に設定し,パラメータを最適に調整できます.
トラッキング・ストップを使用してリスクをコントロールし,利益をロックするかどうかを選択できます.
戦略の最適化スペースは広く,異なる品種と市場環境に対応してパラメータの調整が可能である.
単一の取引信号源,信号が稀で,シールが漏れやすい.
移動平均は後退し,短期的な機会を逃す可能性があります.
追跡停止の設定が不適切で,早すぎたり,大きすぎたりする可能性があります.
パラメータを正しく設定しない場合,仮想取引が頻繁になり,実際の取引の効果が損なわれる可能性があります.
異なる品種と市場環境によってパラメータを調整する必要があり,最適化が困難である.
他の指標判断を追加したり,機械学習モデルを導入したりして信号源を豊かにすることができる.移動平均のタイプとパラメータを最適の平滑効果に調整する.慎重にストップポイントを設定し,より多くの利益を得るために適切に放宽する.十分なフィットバックを施して,パラメータを信頼できるように最適化する.
ブリン・バンド,KDなどの技術指標の判断を加え,取引信号を豊かにする.
信号判断を処理する機械学習モデルを適用する.
移動平均のパラメータを最適化して,最適なパラメータの組み合わせを見つけます.
ストップ・ロスのパラメータを最適化して,ストップ・ロスの幅と利益の獲得をバランスさせる.
パラメータ最適化機能が追加され,最適なパラメータを自動的に検索する.
各種種に特有のパラメータテンプレートを開発する.
定量化フィードバックフレームワークの開発,急速な代入戦略.
この戦略は,開値と高値の交差を基に取引信号判断を行い,移動平均技術のフィルターノイズを使用する.パラメータを柔軟に配置し,複数の効果を実現する.一定の利点があるが,信号の少量,滞りなどいくつかの問題もある.より多くの指標の組み合わせ判断,機械学習方法などの導入によって最適化され,より強力な取引戦略を形成することができる.異なる品種と市場環境に応じてパラメータ調整を最適化して,最適な効果を達成する必要がある.
/*backtest
start: 2022-10-17 00:00:00
end: 2023-10-17 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
//strategy(title = "Open Close Cross Strategy", shorttitle = "OCC Strategy", overlay = true, pyramiding = 0, default_qty_type = strategy.percent_of_equity, default_qty_value = 10)
// Revision: 1
// Author: @JayRogers
//
// Description:
// - Strategy based around Open-Close Crossovers.
// Setup:
// - I have generally found that setting the strategy resolution to 3-4x that of the chart you are viewing
// tends to yield the best results, regardless of which MA option you may choose (if any)
// - Don't aim for perfection. Just aim to get a reasonably snug fit with the O-C band, with good runs of
// green and red.
// - Option to either use basic open and close series data, or pick your poison with a wide array of MA types.
// - Optional trailing stop for damage mitigation if desired (can be toggled on/off)
// - Positions get taken automagically following a crossover - which is why it's better to set the resolution
// of the script greater than that of your chart, so that the trades get taken sooner rather than later.
// - If you make use of the trailing stops, be sure to take your time tweaking the values. Cutting it too fine
// will cost you profits but keep you safer, while letting them loose could lead to more drawdown than you
// can handle.
// === INPUTS ===
useRes = input(defval = true, title = "Use Alternate Resolution? ( recommended )")
stratRes = input(defval = "120", title = "Set Resolution ( should not be lower than chart )")
useMA = input(defval = true, title = "Use MA? ( otherwise use simple Open/Close data )")
basisType = input(defval = "DEMA", title = "MA Type: SMA, EMA, DEMA, TEMA, WMA, VWMA, SMMA, HullMA, LSMA, ALMA ( case sensitive )")
basisLen = input(defval = 14, title = "MA Period", minval = 1)
offsetSigma = input(defval = 6, title = "Offset for LSMA / Sigma for ALMA", minval = 0)
offsetALMA = input(defval = 0.85, title = "Offset for ALMA", minval = 0, step = 0.01)
useStop = input(defval = true, title = "Use Trailing Stop?")
slPoints = input(defval = 200, title = "Stop Loss Trail Points", minval = 1)
slOffset = input(defval = 400, title = "Stop Loss Trail Offset", minval = 1)
// === /INPUTS ===
// === BASE FUNCTIONS ===
// Returns MA input selection variant, default to SMA if blank or typo.
variant(type, src, len, offSig, offALMA) =>
v1 = sma(src, len) // Simple
v2 = ema(src, len) // Exponential
v3 = 2 * v2 - ema(v2, len) // Double Exponential
v4 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len) // Triple Exponential
v5 = wma(src, len) // Weighted
v6 = vwma(src, len) // Volume Weighted
v7 = na(v5[1]) ? sma(src, len) : (v5[1] * (len - 1) + src) / len // Smoothed
v8 = wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len))) // Hull
v9 = linreg(src, len, offSig) // Least Squares
v10 = alma(src, len, offALMA, offSig) // Arnaud Legoux
type=="EMA"?v2 : type=="DEMA"?v3 : type=="TEMA"?v4 : type=="WMA"?v5 : type=="VWMA"?v6 : type=="SMMA"?v7 : type=="HullMA"?v8 : type=="LSMA"?v9 : type=="ALMA"?v10 : v1
// security wrapper for repeat calls
reso(exp, use, res) => use ? request.security(syminfo.tickerid, res, exp) : exp
// === /BASE FUNCTIONS ===
// === SERIES SETUP ===
// open/close
//closeSeries = useMA ? reso(variant(basisType, close, basisLen, offsetSigma, offsetALMA), useRes, stratRes) : reso(close, useRes, stratRes)
openSeries = useMA ? reso(variant(basisType, open, basisLen, offsetSigma, offsetALMA), useRes, stratRes) : reso(open, useRes, stratRes)
x = openSeries[1]
trendState = x > openSeries ? true : x < openSeries ? false : trendState[1]
// === /SERIES ===
// === PLOTTING ===
barcolor(color = x > openSeries ? #006600 : #990000, title = "Bar Colours")
// channel outline
closePlot = plot(x, title = "Close Line", color = #009900, linewidth = 2, style = line, transp = 90)
openPlot = plot(openSeries, title = "Open Line", color = #CC0000, linewidth = 2, style = line, transp = 90)
// channel fill
closePlotU = plot(trendState ? x : na, transp = 100, editable = false)
openPlotU = plot(trendState ? openSeries : na, transp = 100, editable = false)
closePlotD = plot(trendState ? na : x, transp = 100, editable = false)
openPlotD = plot(trendState ? na : openSeries, transp = 100, editable = false)
fill(openPlotU, closePlotU, title = "Up Trend Fill", color = #009900, transp = 40)
fill(openPlotD, closePlotD, title = "Down Trend Fill", color = #CC0000, transp = 40)
// === /PLOTTING ===
// === STRATEGY ===
// conditions
longCond = crossover(openSeries, x)
shortCond = crossunder(openSeries, x)
// entries and base exit
strategy.entry("long", true, when = longCond)
strategy.entry("short", false, when = shortCond)
// if we're using the trailing stop
//if (useStop)
// strategy.exit("XL", from_entry = "long", trail_points = slPoints, trail_offset = slOffset)
// strategy.exit("XS", from_entry = "short", trail_points = slPoints, trail_offset = slOffset)
// not sure needed, but just incase..
//strategy.exit("XL", from_entry = "long", when = shortCond)
//strategy.exit("XS", from_entry = "short", when = longCond)
// === /STRATEGY ===