Cette stratégie est appelée stratégie de réversion de la moyenne basée sur la moyenne mobile. L’idée principale est d’acheter après avoir dépassé la moyenne critique et de s’arrêter après avoir atteint le profit cible prévu.
Le principe principal de cette stratégie est d’utiliser la reprise de la courte période moyenne, pour capturer la possibilité de rebond dans la tendance de l’ensemble du marché. Plus précisément, lorsque les prix ont montré de fortes signes de dépassement après la chute de la moyenne de la plus longue période (comme la ligne de 20 jours, la ligne de 50 jours, etc.), les prix ont tendance à produire un certain rebond.
La logique d’achat spécifique de cette stratégie est la suivante: acheter une main après la chute du prix à la ligne des 20 jours, placer une main après la chute de la ligne des 50 jours, continuer à placer une main après la chute de la ligne des 100 jours, placer une main au maximum après la chute de la ligne des 200 jours, faire 4 mains supplémentaires. Placer la position après avoir atteint l’objectif de stop-loss prédéfini.
Cette stratégie est globalement une stratégie de négociation de courbe plus classique et plus généralisée. Elle utilise correctement les caractéristiques de l’équilibrage de la courbe, tout en combinant plusieurs courbes pour identifier les opportunités d’achat à court terme.
/*backtest
start: 2023-12-13 00:00:00
end: 2023-12-20 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA_zorba1", shorttitle="zorba_ema", overlay=true)
// Input parameters
qt1 = input.int(5, title="Quantity 1", minval=1)
qt2 = input.int(10, title="Quantity 2", minval=1)
qt3 = input.int(15, title="Quantity 3", minval=1)
qt4 = input.int(20, title="Quantity 4", minval=1)
ema10 = ta.ema(close, 10)
ema20 = ta.ema(close, 20)
ema50 = ta.ema(close, 50)
ema100 = ta.ema(close, 100)
ema200 = ta.ema(close, 200)
// Date range filter
start_date = timestamp(year=2021, month=1, day=1)
end_date = timestamp(year=2024, month=10, day=27)
in_date_range = true
// Profit condition
profit_percentage = input(1, title="Profit Percentage") // Adjust this value as needed
// Pyramiding setting
pyramiding = input.int(2, title="Pyramiding", minval=1, maxval=10)
// Buy conditions
buy_condition_1 = in_date_range and close < ema20 and close > ema50 and close < open and close < low[1]
buy_condition_2 = in_date_range and close < ema50 and close > ema100 and close < open and close < low[1]
buy_condition_3 = in_date_range and close < ema100 and close > ema200 and close < open and close < low[1]
buy_condition_4 = in_date_range and close < ema200 and close < open and close < low[1]
// Exit conditions
profit_condition = strategy.position_avg_price * (1 + profit_percentage / 100) <= close
exit_condition_1 = in_date_range and (close > ema10 and ema10 > ema20 and ema10 > ema50 and ema10 > ema100 and ema10 > ema200 and close < open) and profit_condition and close < low[1] and close < low[2]
exit_condition_2 = in_date_range and (close < ema10 and close[1] > ema10 and close < close[1] and ema10 > ema20 and ema10 > ema50 and ema10 > ema100 and ema10 > ema200 and close < open) and profit_condition and close < low[1] and close < low[2]
// Exit condition for when today's close is less than the previous day's low
//exit_condition_3 = close < low[1]
// Strategy logic
strategy.entry("Buy1", strategy.long, qty=qt1 * pyramiding, when=buy_condition_1)
strategy.entry("Buy2", strategy.long, qty=qt2 * pyramiding, when=buy_condition_2)
strategy.entry("Buy3", strategy.long, qty=qt3 * pyramiding, when=buy_condition_3)
strategy.entry("Buy4", strategy.long, qty=qt4 * pyramiding, when=buy_condition_4)
strategy.close("Buy1", when=exit_condition_1 or exit_condition_2)
strategy.close("Buy2", when=exit_condition_1 or exit_condition_2)
strategy.close("Buy3", when=exit_condition_1 or exit_condition_2)
strategy.close("Buy4", when=exit_condition_1 or exit_condition_2)