
이 전략은 광역 이동 평균을 기반으로, 빠른 느린 이동 평균의 황금 포크 사각형을 통해 거래 신호를 형성한다. 광역 이동 평균은 간단한 이동 평균에서 흔들리는 이동 평균 등 다양한 유형을 커버하고, 파라미터를 통해 자유 조합을 조정할 수 있으며, 강한 적응력을 가지고 있다.
이 전략은 변수 이동 평균 함수를 사용하여 12가지의 다른 유형의 이동 평균을 생성할 수 있다. 기본 원칙은 빠른 라인 (Close MA) 과 느린 라인 (Open MA) 의 두 가지 이동 평균을 계산하는 것으로, 빠른 라인 상에서 느린 라인을 통과할 때 구매 신호를 생성하고, 빠른 라인 아래에서 느린 라인을 통과할 때 판매 신호를 생성한다. 동시에 스톱 스톱 파라미터를 설정하여 자동 스톱 스톱을 구현할 수 있다.
핵심 논리는 변수 함수를 통해 두 개의 이동 평균을 생성하는 것이다:closeSeries = variant(basisType, close, basisLen, offsetSigma, offsetALMA)그리고openSeries = variant(basisType, open, basisLen, offsetSigma, offsetALMA)。variant 함수는 12가지의 다른 유형의 평균 계산 방법을 포괄하고, basisType 변수를 통해 자유롭게 선택할 수 있다。 이렇게 해서 광광 이동 평균의 조합이 실현된다。
기본 거래 신호 생성 논리는 다음과 같습니다.longCond = xlong 그리고 shortCond = xshort엑스포는 엑스포를 지나가면 엑스포를 지나가면 엑스포를 지나가면 엑스포를 지나가면 엑스포를 지나가면 엑스포를 지나가면 엑스포를 지나가면 엑스포를 지나가면 엑스포를 지나가면 엑스포를 지나가면 엑스포를 지나가면 엑스포를 지나가면 엑스포를 지나가면 엑스포를 지나가면 엑스포를 지나가다.
전략 입문 규칙은 longCond 또는 shortCond 조건이 충족될 때 각각 더 많은 공백을 한다. 정지 규칙은 가격 이동이 기본 설정된 정지 지점을 달성할 때 정지한다.
이 전략의 가장 큰 장점은 여러 가지 다른 유형의 이동 평균을 자유롭게 조합할 수 있다는 것입니다. 다른 시장의 다른 주기, 어떤 이동 평균이 가장 적합한지는 확실하지 않습니다. 이 전략은 강력한 사용자 정의 능력을 제공합니다. 사용자는 반복 테스트를 통해 최적의 파라미터 조합을 결정하여 특정 시장에 대한 최적의 계획을 수립 할 수 있습니다.
또 다른 장점은 전략 논리가 간단하고 명확하지만 강력한 기능을 제공한다는 것입니다. 사용자는 전략을 쉽게 이해하고 사용할 수 있습니다. 또한 풍부한 입력 매개 변수는 고급 사용자에게 충분한 최적화 공간을 제공합니다.
이 전략의 가장 큰 위험은 광역 이동 평균 자체에 어느 정도의 지연이 존재한다는 것입니다. 비정상적인 가격 돌파구가 발생하면 큰 손실이 발생할 수 있습니다. 또한, 매개 변수가 잘못 선택되면 거래 빈도가 너무 높거나 여분의 신호가 발생할 수 있습니다.
위험을 줄이기 위해, 다른 지표와 결합하여 신호의 효과를 판단하여 가짜 돌파구를 피하는 것이 좋습니다. 또한, 매개 변수 최적화 및 재검토가 매우 필요하며, 최적의 매개 변수 조합을 찾기 위해 반복 테스트가 필요합니다. 실장에 위치 규모를 적절히 축소하여 단위 손실을 제어해야합니다.
이 전략에는 다음과 같은 몇 가지 주요 최적화 방향이 있습니다.
이러한 몇 가지 방향의 최적화를 통해 전략의 실무 실적을 지속적으로 향상시킬 수 있습니다.
이 거래 전략은 광 스펙트럼 이동 평균에 기반하여 높은 유연성을 구현한다. 그것은 강력한 사용자 정의 기능을 제공하며 사용자는 다양한 유형의 평균을 자유롭게 선택하고 조합할 수 있다. 전략 논리는 간단하고 명확하며 사용하기 편리하며 또한 풍부한 최적화 공간을 제공합니다. 매개 변수 최적화 및 위험 통제를 통해 전략은 다양한 시장 환경에 적응할 수 있으며 안정적인 수익을 얻을 수 있다.
/*backtest
start: 2023-01-18 00:00:00
end: 2024-01-24 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
//
strategy(title="Long/Short", shorttitle="Banana Maker", overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=100, calc_on_every_tick=false)
// === INPUTS ===
useRes = input(defval=true, title="Use Alternate Resolution?")
intRes = input(defval=7, title="Multiplier for Alernate Resolution")
stratRes = timeframe.ismonthly ? tostring(timeframe.multiplier * intRes, "###M") :
timeframe.isweekly ? tostring(timeframe.multiplier * intRes, "###W") :
timeframe.isdaily ? tostring(timeframe.multiplier * intRes, "###D") :
timeframe.isintraday ? tostring(timeframe.multiplier * intRes, "####") : '60'
basisType = input(defval="DEMA", title="MA Type: ", options=["SMA", "EMA", "DEMA", "TEMA", "WMA", "VWMA", "SMMA", "HullMA", "LSMA", "ALMA", "SSMA", "TMA"])
basisLen = input(defval=8, 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)
scolor = input(false, title="Show coloured Bars to indicate Trend?")
delayOffset = input(defval=0, title="Delay Open/Close MA (Forces Non-Repainting)", minval=0, step=1)
tradeType = input("BOTH", title="What trades should be taken : ", options=["LONG", "SHORT", "BOTH", "NONE"])
// === /INPUTS ===
// Constants colours that include fully non-transparent option.
green100 = #008000FF
lime100 = #6ad279
red100 = #FF0000FF
blue100 = #0000FFFF
aqua100 = #00FFFFFF
darkred100 = #8B0000FF
gray100 = #808080FF
// === BASE FUNCTIONS ===
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 = 0.0
sma_1 = sma(src, len) // Smoothed
v7 := na(v7[1]) ? sma_1 : (v7[1] * (len - 1) + src) / len
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
v11 = sma(v1, len) // Triangular (extreme smooth)
// SuperSmoother filter
// © 2013 John F. Ehlers
a1 = exp(-1.414 * 3.14159 / len)
b1 = 2 * a1 * cos(1.414 * 3.14159 / len)
c2 = b1
c3 = -a1 * a1
c1 = 1 - c2 - c3
v12 = 0.0
v12 := c1 * (src + nz(src[1])) / 2 + c2 * nz(v12[1]) + c3 * nz(v12[2])
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 : type == "TMA" ? v11 : type == "SSMA" ? v12 : v1
// security wrapper for repeat calls* NEEDS REFINEMENT- backtesting this shows repaint. need new wrapper
reso(exp, use, res) =>
security_1 = security(syminfo.tickerid, res, exp, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
use ? security_1 : exp
// === /BASE FUNCTIONS ===
// === SERIES SETUP ===
closeSeries = variant(basisType, close[delayOffset], basisLen, offsetSigma, offsetALMA)
openSeries = variant(basisType, open[delayOffset], basisLen, offsetSigma, offsetALMA)
// === /SERIES ===
// === PLOTTING ===
// alt resulution
closeSeriesAlt = reso(closeSeries, useRes, stratRes)
openSeriesAlt = reso(openSeries, useRes, stratRes)
//
trendColour = closeSeriesAlt > openSeriesAlt ? color.green : color.red
bcolour = closeSeries > openSeriesAlt ? lime100 : red100
barcolor(scolor ? bcolour : na, title="Bar Colours")
closeP = plot(closeSeriesAlt, title="Close Series", color=trendColour, linewidth=0, style=plot.style_line, transp=1)
openP = plot(openSeriesAlt, title="Open Series", color=trendColour, linewidth=0, style=plot.style_line, transp=1)
fill(closeP, openP, color=trendColour, transp=80)
// === /PLOTTING ===
//
//
// === ALERT conditions
xlong = crossover(closeSeriesAlt, openSeriesAlt)
xshort = crossunder(closeSeriesAlt, openSeriesAlt)
longCond = xlong // alternative: longCond[1]? false : (xlong or xlong[1]) and close>closeSeriesAlt and close>=open
shortCond = xshort // alternative: shortCond[1]? false : (xshort or xshort[1]) and close<closeSeriesAlt and close<=open
// === /ALERT conditions. needs work in study mode. the banana maker is the study script.
// Create alert for cross, shunt back 1 if source is not 'open', this should prevent repaint issue.
//shunt = RSIsrc == open ? 0 : 1
//shunt = 0
//c_alert = (buy[shunt]==1 or sell[shunt]==1)
//alertcondition(c_alert, title="QQECROSS Alert", message="QQECROSS Alert")
// show only when alert condition is met and bar closed.
//plotshape(c_alert,title= "Alert Indicator Closed", location=location.bottom, color=sell[shunt]==1?red:green, transp=0, style=shape.circle)
//Repaint city, study mode will help but wont trigger the alerts
// === STRATEGY ===
// stop loss
slPoints = input(defval=0, title="Initial Stop Loss Points (zero to disable)", minval=0)
tpPoints = input(defval=0, title="Initial Target Profit Points (zero for disable)", minval=0)
// Include bar limiting algorithm
ebar = input(defval=1000, title="Number of Bars for Back Testing", minval=0)
dummy = input(false, title="- SET to ZERO for Daily or Longer Timeframes")
//
// Calculate how many mars since last bar
tdays = (timenow - time) / 60000.0 // number of minutes since last bar
tdays := timeframe.ismonthly ? tdays / 1440.0 / 5.0 / 4.3 / timeframe.multiplier :
timeframe.isweekly ? tdays / 1440.0 / 5.0 / timeframe.multiplier :
timeframe.isdaily ? tdays / 1440.0 / timeframe.multiplier :
tdays / timeframe.multiplier // number of bars since last bar
//
//set up exit parameters
TP = tpPoints > 0 ? tpPoints : na
SL = slPoints > 0 ? slPoints : na
// Make sure we are within the bar range, Set up entries and exit conditions
if (ebar == 0 or tdays <= ebar) and tradeType != "NONE"
strategy.entry("long", strategy.long, when=longCond == true and tradeType != "SHORT")
strategy.entry("short", strategy.short, when=shortCond == true and tradeType != "LONG")
strategy.close("long", when=shortCond == true and tradeType == "LONG")
strategy.close("short", when=longCond == true and tradeType == "SHORT")
strategy.exit("XL", from_entry="long", profit=TP, loss=SL)
strategy.exit("XS", from_entry="short", profit=TP, loss=SL)
// === /STRATEGY ===
// eof