
इस रणनीति में माइक्रोस्कोप मैकड और मल्टी-टाइम फ्रेम औसत रेखा का उपयोग करके एक लंबी और छोटी द्वि-दिशात्मक ट्रेडिंग रणनीति का निर्माण किया गया है, जो प्रवृत्ति और प्रवृत्ति रिवर्स सिग्नल का व्यापक उपयोग करता है। यह रणनीति प्रवृत्ति की स्थिति में अतिरिक्त मुनाफा कमा सकती है, जबकि रिवर्स के अवसरों को भी पकड़ सकती है।
दो अलग-अलग चक्रों के ईएमए के दो समूहों का उपयोग करके बहु-समय फ़्रेम फ़िल्टर के लिए सहकार्य करते हुए, लंबी दूरी की दिशा का आकलन करेंः 15 मिनट तेज ईएमए 1 घंटे धीमी ईएमए से अधिक के लिए पूर्वाग्रह फ़िल्टर, 15 मिनट तेज ईएमए 1 घंटे धीमी ईएमए से कम के लिए पूर्वाग्रह फ़िल्टर।
जब माइक्रोफ़ोन शेल्फ के विचलन को देखा जाता है, तो निर्णय उलट सकता है।
यदि कोई बैल बाजार के साथ शुरू होता है (कीमतें नई हैं और MACD उच्च नहीं हैं), तो MACD के शून्य-अक्ष पर पहनने की प्रतीक्षा करें, और अधिक करें। यदि कोई भालू बाजार के साथ शुरू होता है (कीमतें नई हैं और MACD कम नहीं हैं), तो MACD के शून्य-अक्ष के नीचे पहनने की प्रतीक्षा करें, और खाली करें।
स्टॉप लॉस स्टॉप लॉस है जो लगातार ट्रैक किया जाता है और इसकी गणना उच्चतम मूल्य और निम्नतम मूल्य में उतार-चढ़ाव की सीमा के आधार पर की जाती है। स्टॉप लॉस स्टॉप लॉस का एक निश्चित गुणांक है।
जब MACD स्तंभ रेखा शून्य-अक्षीय दिशा में पार करती है तो समतल स्थिति।
मल्टीटाइम फ्रेम ईएमए पोर्टफोलियो महाचक्र के रुझानों का आकलन करता है और प्रतिकूल ट्रेडिंग से बचा जाता है।
एमएसीडी एक पलटाव रणनीति के लिए उपयुक्त है, क्योंकि यह एक पलटाव के अवसर को पकड़ने से दूर है।
डायनामिक ट्रैकिंग स्टॉप लॉस लाभ को लॉक करने और घाटे के विस्तार से बचने में मदद करता है।
स्टॉप लॉस की गणना के आधार पर स्टॉप दूरी से अपेक्षित रिटर्न प्राप्त किया जा सकता है।
ईएमए समानांतर समूह एक फ़िल्टर के रूप में कार्य करता है, जो गणना अवधि के दौरान दिशा में गलत निर्णय ले सकता है।
मैकड के पीछे एक छोटा सा रिबाउंड है, जो लाभदायक नहीं हो सकता है।
स्टॉपर गलत तरीके से सेट किया गया है, यह बहुत ढीला या बहुत संकुचित हो सकता है।
इस तरह की घटनाओं से लोगों को लाभ नहीं मिल रहा है।
यह समय के साथ बदल जाता है, और बहुत जल्दी या देर से नुकसान हो सकता है।
प्रवृत्ति के अधिक सटीक निर्णय के लिए विभिन्न मापदंडों के संयोजनों के ईएमए का परीक्षण किया जा सकता है
MACD पैरामीटर को अधिक संवेदनशील पैरामीटर संयोजन में समायोजित करने का प्रयास करें।
विभिन्न स्टॉप लॉस और स्टॉप ब्रेक अनुपात सेटिंग्स का परीक्षण किया जा सकता है।
अतिरिक्त फ़िल्टरिंग शर्तों को शामिल किया जा सकता है ताकि झूठे रिबाउंड में फंसने से बचा जा सके। उदाहरण के लिए, ईएमए द्वारा वैश्विक रुझानों के लिए एक उच्च समय सीमा को शामिल करना।
रिवर्स ट्रेंड को सुनिश्चित करने के लिए रिवर्स कट-इन कन्फर्मेशन को अनुकूलित किया जा सकता है।
इस रणनीति में ट्रेंड फिल्टर, ट्रेंड रिवर्स सिग्नल, डायनामिक स्टॉप लॉस स्टॉप मैनेजमेंट आदि का उपयोग किया गया है, जो अनुक्रमिक रूप से काम कर सकता है और रिवर्स को पकड़ सकता है। पैरामीटर को समायोजित करने और फ़िल्टरिंग की स्थिति को अनुकूलित करने के माध्यम से, यह व्यापक बाजार की स्थिति के अनुकूल हो सकता है, जोखिम को नियंत्रित करने के लिए स्थिर रिटर्न प्राप्त कर सकता है। इस रणनीति में कुछ सार्वभौमिकता और व्यावहारिक मूल्य है, जो बहु-समय फ्रेमवर्क और संकेतक एकीकरण के उपयोग का एक विशिष्ट प्रतिनिधि है।
/*backtest
start: 2023-01-01 00:00:00
end: 2023-06-16 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/
// © maxits
//@version=4
// MACD Divergence + Multi Time Frame EMA
// This Strategy uses 3 indicators: the Macd and two emas in different time frames
// The configuration of the strategy is:
// Macd standar configuration (12, 26, 9) in 1H resolution
// 10 periods ema, in 1H resolution
// 5 periods ema, in 15 minutes resolution
// We use the two emas to filter for long and short positions.
// If 15 minutes ema is above 1H ema, we look for long positions
// If 15 minutes ema is below 1H ema, we look for short positions
// We can use an aditional filter using a 100 days ema, so when the 15' and 1H emas are above the daily ema we take long positions
// Using this filter improves the strategy
// We wait for Macd indicator to form a divergence between histogram and price
// If we have a bullish divergence, and 15 minutes ema is above 1H ema, we wait for macd line to cross above signal line and we open a long position
// If we have a bearish divergence, and 15 minutes ema is below 1H ema, we wait for macd line to cross below signal line and we open a short position
// We close both position after a cross in the oposite direction of macd line and signal line
// Also we can configure a Take profit parameter and a trailing stop loss
// strategy("Macd + MTF EMA",
// overlay=true,
// initial_capital=1000,
// default_qty_value=20,
// default_qty_type=strategy.percent_of_equity,
// commission_value=0.1,
// pyramiding=0)
// User Inputs
i_time = input(defval = timestamp("01 Apr 2018 13:30 +0000"), title = "Start Time", type = input.time) // Starting time for backtest
f_time = input(defval = timestamp("30 Sep 2021 13:30 +0000"), title = "Finish Time", type = input.time) // Finishing time for backtest
long_pos = input(title="Show Long Positions", defval=true, type=input.bool) // Enable Long Positions
short_pos = input(title="Show Short Positions", defval=true, type=input.bool) // Enable Short Positions
src = input(close, title="Source") // Price value to calculate indicators
emas_properties = input(title="============ EMAS Properties ============", defval=false, type=input.bool) // Properties
mtf_15 = input(title="Fast EMA", type=input.resolution, defval="15") // Resolucion para MTF EMA 15 minutes
ma_15_length = input(5, title = "Fast EMA Period") // MTF EMA 15 minutes Length
mtf_60 = input(title="Slow EMA", type=input.resolution, defval="60") // Resolucion para MTF EMA 60 minutes
ma_60_length = input(10, title = "Slow EMA Period") // MTF EMA 60 minutes Length
e_new_filter = input(title="Enable a Third Ema filter?", defval=true, type=input.bool)
slowest_ema_len = input(100, title = "Fast EMA Period")
slowest_ema_res = input(title="Slowest EMA", type=input.resolution, defval="D")
macd_res = input(title="MACD TimeFrame", type=input.resolution, defval="") // MACD Time Frame
macd_properties = input(title="============ MACD Properties ============", defval="") // Properties
fast_len = input(title="Fast Length", type=input.integer, defval=12) // Fast MA Length
slow_len = input(title="Sign Length", type=input.integer, defval=26) // Sign MA Length
sign_len = input(title="Sign Length", type=input.integer, defval=9)
syst_properties = input(title="============ System Properties ============", defval="") // Properties
lookback = input(title="Lookback period", type=input.integer, defval=14, minval=1) // Candles to lookback for swing high or low
multiplier = input(title="Profit Multiplier based on Stop Loss", type=input.float, defval=6.0, minval=0.1) // Profit multiplier based on stop loss
shortStopPer = input(title="Short Stop Loss Percentage", type=input.float, defval=1.0, minval=0.0)/100
longStopPer = input(title="Long Stop Loss Percentage", type=input.float, defval=2.0, minval=0.0)/100
// Indicators
[macd, signal, hist] = security(syminfo.tickerid, macd_res, macd(src, fast_len, slow_len, sign_len))
ma_15 = security(syminfo.tickerid, mtf_15, ema(src, ma_15_length))
ma_60 = security(syminfo.tickerid, mtf_60, ema(src, ma_60_length))
ma_slo = security(syminfo.tickerid, slowest_ema_res, ema(src, slowest_ema_len))
// Macd Plot
col_grow_above = #26A69A
col_grow_below = #FFCDD2
col_fall_above = #B2DFDB
col_fall_below = #EF5350
plot(macd, color=color.new(color.blue, 0)) // Solo para visualizar que se plotea correctamente
plot(signal, color=color.new(color.orange, 0))
plot(hist, style=plot.style_columns,
color=(hist >= 0 ? (hist[1] < hist ? col_grow_above : col_fall_above) :
(hist[1] < hist ? col_grow_below : col_fall_below)))
// MTF EMA Plot
bullish_filter = e_new_filter ? ma_15 > ma_60 and ma_60 > ma_slo : ma_15 > ma_60
bearish_filter = e_new_filter ? ma_15 < ma_60 and ma_60 < ma_slo : ma_15 < ma_60
plot(ma_15, color=color.new(color.blue, 0))
plot(ma_60, color=color.new(color.yellow, 0))
plot(e_new_filter ? ma_slo : na, color = ma_60 > ma_slo ? color.new(color.green, 0) : color.new(color.red, 0))
////////////////////////////////////////////// Logic For Divergence
zero_cross = false
zero_cross := crossover(hist,0) or crossunder(hist,0) //Cruce del Histograma a la linea 0
// plot(zero_cross ? 1 : na)
// MACD DIVERGENCE TOPS (Bearish Divergence)
highest_top = 0.0
highest_top := (zero_cross == true ? 0.0 : (hist > 0 and hist > highest_top[1] ? hist : highest_top[1]))
prior_top = 0.0
prior_top := (crossunder(hist,0) ? highest_top[1] : prior_top[1]) // Búsqueda del Maximo en MACD
// plot(highest_top)
// plot(prior_top)
highest_top_close = 0.0
highest_top_close := (zero_cross == true ? 0.0 : (hist > 0 and hist > highest_top[1] ? close : highest_top_close[1]))
prior_top_close = 0.0
prior_top_close := (crossunder(hist,0) ? highest_top_close[1] : prior_top_close[1]) // Búsqueda del Maximo en pRECIO
// plot(highest_top_close)
// plot(prior_top_close)
top = false
top := highest_top[1] < prior_top[1]
and highest_top_close[1] > prior_top_close[1]
and hist < hist[1]
and crossunder(hist,0) // Bearish Divergence: top == true
// MACD DIVERGENCE BOTTOMS (Bullish Divergence)
lowest_bottom = 0.0
lowest_bottom := (zero_cross == true ? 0.0 : (hist < 0 and hist < lowest_bottom[1] ? hist : lowest_bottom[1]))
prior_bottom = 0.0
prior_bottom := (crossover(hist,0) ? lowest_bottom[1] : prior_bottom[1])
lowest_bottom_close = 0.0
lowest_bottom_close := (zero_cross == true ? 0.0 : (hist < 0 and hist < lowest_bottom[1] ? close : lowest_bottom_close[1]))
prior_bottom_close = 0.0
prior_bottom_close := (crossover(hist,0) ? lowest_bottom_close[1] : prior_bottom_close[1])
bottom = false
bottom := lowest_bottom[1] > prior_bottom[1]
and lowest_bottom_close[1] < prior_bottom_close[1]
and hist > hist[1]
and crossover(hist,0) // Bullish Divergence: bottom == true
////////////////////////////////////////////// System Conditions //////////////////////////////////////////////
inTrade = strategy.position_size != 0 // In Trade
longTrade = strategy.position_size > 0 // Long position
shortTrade = strategy.position_size < 0 // Short position
notInTrade = strategy.position_size == 0 // No trade
entryPrice = strategy.position_avg_price // Position Entry Price
////////////////////////////////////////////// Long Conditions //////////////////////////////////////////////
sl = lowest(low, lookback) // Swing Low for Long Entry
longStopLoss = 0.0 // Trailing Stop Loss calculation
longStopLoss := if (longTrade)
astopValue = sl * (1 - longStopPer)
max(longStopLoss[1], astopValue)
else
0
longTakeProf = 0.0 // Profit calculation based on stop loss
longTakeProf := if (longTrade)
profitValue = entryPrice + (entryPrice - longStopLoss) * multiplier
max(longTakeProf[1], profitValue)
else
0
// Long Entry Conditions
if bottom and notInTrade and bullish_filter and long_pos
strategy.entry(id="Go Long", long=strategy.long, comment="Long Position")
// strategy.close(id="Go Long", when=zero_cross)
if longTrade
strategy.exit("Exit Long", "Go Long", limit = longTakeProf, stop = longStopLoss)
plot(longTrade and longStopLoss ? longStopLoss : na, title="Long Stop Loss", color=color.new(color.red, 0), style=plot.style_linebr)
plot(longTrade and longTakeProf ? longTakeProf : na, title="Long Take Prof", color=color.new(color.green, 0), style=plot.style_linebr)
////////////////////////////////////////////// Short Conditions //////////////////////////////////////////////
sh = highest(high, lookback) // Swing High for Short Entry
shortStopLoss = 0.0
shortStopLoss := if (shortTrade)
bstopValue = sh * (1 + shortStopPer)
min(shortStopLoss[1], bstopValue)
else
999999
shortTakeProf = 0.0
shortTakeProf := if (shortTrade)
SprofitValue = entryPrice - (shortStopLoss - entryPrice) * multiplier
min(SprofitValue, shortTakeProf[1])
else
999999
// Short Entry
if top and notInTrade and bearish_filter and short_pos
strategy.entry(id="Go Short", long=strategy.short, comment="Short Position")
// strategy.close(id="Go Short", when=zero_cross)
if shortTrade
strategy.exit("Exit Short", "Go Short", limit = shortTakeProf, stop = shortStopLoss)
plot(shortTrade and shortStopLoss ? shortStopLoss : na, title="Short Stop Loss", color=color.new(color.red, 0), style=plot.style_linebr)
plot(shortTrade and shortTakeProf ? shortTakeProf : na, title="Short Take Prof", color=color.new(color.green, 0), style=plot.style_linebr)