Eine Durchschnittsbrechstrategie ist eine Short-Line-Trading-Strategie, bei der der Moving Average zum Urteilen genutzt wird. Die Strategie wird durch die Einstellung der Länge der Durchschnittslinie und die Durchführung von Kauf- und Verkaufsaktionen bei Durchschnittsbrechen ausgeführt. Sie ist einfach und leicht zu beherrschen.
Die Strategie beurteilt die Preisentwicklung hauptsächlich durch die Einstellung von zwei Moving Averages, einer Schnelllinie und einer Langlinie. Die Schnelllinie ist kurz und reaktionssensibel; die Langlinie ist lang und reagiert stabil.
Der Code definiert die Schnelllinie-Periode (shortPeriod) und die Langlinie-Periode (longPeriod) durch die Einstellung der Inputparameter. Dann werden die Werte der beiden Mittellinien (shortSMA und longSMA) berechnet.
Wenn die kurzperiodische Durchschnittslinie von unten nach oben die langperiodische Durchschnittslinie überschreitet, zeigt dies, dass die Preisentwicklung von unten nach unten umgekehrt ist, und macht einen Überschuss. Wenn die kurzperiodische Durchschnittslinie von oben nach unten die langperiodische Durchschnittslinie überschreitet, zeigt dies, dass die Preisentwicklung von unten nach unten umgekehrt ist und macht einen Ausfall.
Die Bedingungen für den Eintritt in eine Multi-Position sind:
快线由下向上突破慢线
快线>慢线
Eintritt in eine Leerlaufposition:
快线由上向下跌破慢线
快线<慢线
Darüber hinaus werden in der Strategie Parameter wie Stop-Loss, Stop-Loss und Betrag festgelegt, um das Risiko zu kontrollieren.
Risiken:
Das Konzept der Durchschnittsbrechstrategie ist einfach, durch schnelle und langsame Durchschnittsbeurteilung ist es leicht zu handhaben. Es gibt jedoch einige Probleme wie falsche Durchbrüche, Verzögerungen usw. Es kann durch Optimierung von Parametern und Kombination anderer Indikatoren verbessert werden.
/*backtest
start: 2023-08-26 00:00:00
end: 2023-09-25 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © YohanNaftali
//@version=5
///////////////////////////////////////////////////////////////////////////////
// Heikin Ashi Candle Startegy
// ver 2021.12.29
// © YohanNaftali
// This script composed by Yohan Naftali for educational purpose only
// Reader who will use this signal must do own research
///////////////////////////////////////////////////////////////////////////////
strategy(
title = 'Heikin Ashi Candle Startegy Long',
shorttitle = 'HA Strategy Long',
format = format.price,
precision = 0,
overlay = true)
// Input
validationPeriod = input.int(
defval = 3,
title = 'Validation Period',
group = 'Candle')
qtyOrder = input.float(
defval = 1.0,
title = 'Qty',
group = 'Order')
maxActive = input.float(
defval = 1.0,
title = 'Maximum Active Open Position',
group = 'Order')
// Long Strategy
tpLong = input.float(
defval = 1,
title = "Take Profit (%)",
minval = 0.0,
step = 0.1,
group = "Long") * 0.01
slLong = input.float(
defval = 25,
title = "Stop Loss (%)",
minval=0.0,
step=0.1,
group="Long") * 0.01
trailingStopLong = input.float(
defval = 0.2,
title = "Trailing Stop (%)",
minval = 0.0,
step = 0.1,
group = 'Long') * 0.01
// Calculation
haTicker = ticker.heikinashi(syminfo.tickerid)
haClose = request.security(haTicker, timeframe.period, close)
haOpen = request.security(haTicker, timeframe.period, open)
// Long
limitLong = tpLong > 0.0 ? strategy.position_avg_price * (1 + tpLong) : na
stopLong = slLong > 0.0 ? strategy.position_avg_price * (1 - slLong) : na
float trailLong = 0.0
trailLong := if strategy.position_size > 0
trailClose = close * (1 - trailLong)
math.max(trailClose, trailLong[1])
else
0
isGreen = true
for i = 0 to validationPeriod-1
isGreen := isGreen and haClose[i] > haOpen[i]
isLong = isGreen and haClose[validationPeriod] < haOpen[validationPeriod]
plot(
limitLong,
title = 'Limit',
color = color.rgb(0, 0, 255, 0),
style = plot.style_stepline,
linewidth = 1)
plot(
trailLong,
title = 'Trailing',
color = color.rgb(255, 255, 0, 0),
style = plot.style_stepline,
linewidth = 1)
plot(
stopLong,
title = 'Stop',
style = plot.style_stepline,
color = color.rgb(255, 0, 0, 0),
linewidth = 1)
// plotshape(
// isLong,
// title = 'Entry',
// style = shape.arrowup,
// location = location.belowbar,
// offset = 1,
// color = color.new(color.green, 0),
// text = 'Long Entry',
// size = size.small)
// Strategy
strategy.risk.max_position_size(maxActive)
strategy.risk.allow_entry_in(strategy.direction.long)
strategy.entry(
id = "Long",
direction = strategy.long,
qty = qtyOrder,
when = isLong,
alert_message = "LN")
if (strategy.position_size > 0)
strategy.exit(
id = "Long Exit",
from_entry = "Long",
limit = limitLong,
stop = stopLong,
trail_price = trailLong,
alert_message = "LX")