यूट्यूब मास्टर से "जादुई डबल ईएमए मूविंग एवरेज रणनीति"
इस अंक में, हम यूट्यूब से एक "जादुई डबल ईएमए मूविंग एवरेज रणनीति" पर चर्चा करेंगे, जिसे "स्टॉक और क्रिप्टोकरेंसी मार्केट किलर" कहा जाता है। वीडियो देखने के बाद, मुझे पता चला कि यह रणनीति एक ट्रेडिंग व्यू पाइन लैंग्वेज रणनीति है, जो 2 ट्रेडिंग व्यू संकेतक का उपयोग करती है। वीडियो में बैकटेस्टिंग के परिणाम बहुत अच्छे थे, तथा FMZ भी ट्रेडिंग व्यू की पाइन भाषा का समर्थन करता है, यह देखकर मैं स्वयं भी बैकटेस्ट और विश्लेषण का परीक्षण करने के लिए प्रेरित हुआ। फिर शुरू हो जाइये पूरी जिंदगी! आइये वीडियो में बताई गई रणनीति को दोहराएं।
रणनीति द्वारा प्रयुक्त संकेतक
- ईएमए सूचक
डिजाइन में सरलता के लिए, हम वीडियो में सूचीबद्ध मूविंग एवरेज एक्सपोनेंशियल का उपयोग नहीं करेंगे। इसके स्थान पर हम ट्रेडिंग दृश्य में अंतर्निहित ta.ema का उपयोग करते हैं (वास्तव में वे एक ही हैं)।
- वुमानचू स्विंग फ्री इंडिकेटर
यह ट्रेडिंग व्यू पर एक संकेतक है। हमें ट्रेडिंग व्यू पर जाकर सोर्स कोड डाउनलोड करना होगा।
VuManChu स्विंग निःशुल्क कोड:
pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Credits to the original Script - Range Filter DonovanWall https://www.tradingview.com/script/lut7sBgG-Range-Filter-DW/
// This version is the old version of the Range Filter with less settings to tinker with
//@version=4
study(title="Range Filter - B&S Signals", shorttitle="RF - B&S Signals", overlay=true)
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Functions
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Range Size Function
rng_size(x, qty, n)=>
// AC = Cond_EMA(abs(x - x[1]), 1, n)
wper = (n*2) - 1
avrng = ema(abs(x - x[1]), n)
AC = ema(avrng, wper)*qty
rng_size = AC
//Range Filter Function
rng_filt(x, rng_, n)=>
r = rng_
var rfilt = array.new_float(2, x)
array.set(rfilt, 1, array.get(rfilt, 0))
if x - r > array.get(rfilt, 1)
array.set(rfilt, 0, x - r)
if x + r < array.get(rfilt, 1)
array.set(rfilt, 0, x + r)
rng_filt1 = array.get(rfilt, 0)
hi_band = rng_filt1 + r
lo_band = rng_filt1 - r
rng_filt = rng_filt1
[hi_band, lo_band, rng_filt]
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Inputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Range Source
rng_src = input(defval=close, type=input.source, title="Swing Source")
//Range Period
rng_per = input(defval=20, minval=1, title="Swing Period")
//Range Size Inputs
rng_qty = input(defval=3.5, minval=0.0000001, title="Swing Multiplier")
//Bar Colors
use_barcolor = input(defval=false, type=input.bool, title="Bar Colors On/Off")
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Definitions
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Range Filter Values
[h_band, l_band, filt] = rng_filt(rng_src, rng_size(rng_src, rng_qty, rng_per), rng_per)
//Direction Conditions
var fdir = 0.0
fdir := filt > filt[1] ? 1 : filt < filt[1] ? -1 : fdir
upward = fdir==1 ? 1 : 0
downward = fdir==-1 ? 1 : 0
//Trading Condition
longCond = rng_src > filt and rng_src > rng_src[1] and upward > 0 or rng_src > filt and rng_src < rng_src[1] and upward > 0
shortCond = rng_src < filt and rng_src < rng_src[1] and downward > 0 or rng_src < filt and rng_src > rng_src[1] and downward > 0
CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]
longCondition = longCond and CondIni[1] == -1
shortCondition = shortCond and CondIni[1] == 1
//Colors
filt_color = upward ? #05ff9b : downward ? #ff0583 : #cccccc
bar_color = upward and (rng_src > filt) ? (rng_src > rng_src[1] ? #05ff9b : #00b36b) :
downward and (rng_src < filt) ? (rng_src < rng_src[1] ? #ff0583 : #b8005d) : #cccccc
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Outputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Filter Plot
filt_plot = plot(filt, color=filt_color, transp=67, linewidth=3, title="Filter")
//Band Plots
h_band_plot = plot(h_band, color=color.new(#05ff9b, 100), title="High Band")
l_band_plot = plot(l_band, color=color.new(#ff0583, 100), title="Low Band")
//Band Fills
fill(h_band_plot, filt_plot, color=color.new(#00b36b, 92), title="High Band Fill")
fill(l_band_plot, filt_plot, color=color.new(#b8005d, 92), title="Low Band Fill")
//Bar Color
barcolor(use_barcolor ? bar_color : na)
//Plot Buy and Sell Labels
plotshape(longCondition, title = "Buy Signal", text ="BUY", textcolor = color.white, style=shape.labelup, size = size.normal, location=location.belowbar, color = color.new(color.green, 0))
plotshape(shortCondition, title = "Sell Signal", text ="SELL", textcolor = color.white, style=shape.labeldown, size = size.normal, location=location.abovebar, color = color.new(color.red, 0))
//Alerts
alertcondition(longCondition, title="Buy Alert", message = "BUY")
alertcondition(shortCondition, title="Sell Alert", message = "SELL")
रणनीति तर्क
ईएमए संकेतक: यह रणनीति दो ईएमए चलती औसत का उपयोग करती है, एक तेज़ रेखा (छोटा चक्र पैरामीटर) और एक धीमी रेखा (बड़ा चक्र पैरामीटर)। डबल ईएमए मूविंग एवरेज का मुख्य कार्य हमें बाजार के रुझान की दिशा निर्धारित करने में मदद करना है।
-
लंबी व्यवस्था
तेज़ रेखा धीमी रेखा से ऊपर है। -
संक्षिप्त व्यवस्था
तेज़ रेखा धीमी रेखा के नीचे है।
वुमानचू स्विंग फ्री इंडिकेटर: वुमानचू स्विंग फ्री इंडिकेटर का उपयोग सिग्नल भेजने के लिए किया जाता है, और फिर अन्य शर्तों के साथ संयुक्त करके यह निर्धारित किया जाता है कि ट्रेडिंग के लिए ऑर्डर दिया जाए या नहीं। VuManChu स्विंग फ्री इंडिकेटर स्रोत कोड से, हम देख सकते हैं कि longCondition चर खरीद संकेत का प्रतिनिधित्व करता है, और shortCondition चर बिक्री संकेत का प्रतिनिधित्व करता है। इन दो चरों का उपयोग बाद में ऑर्डर की शर्तें लिखते समय किया जाएगा।
अब आइए रणनीति की विशिष्ट ट्रेडिंग सिग्नल ट्रिगरिंग स्थितियों के बारे में बात करते हैं:
-
लॉन्ग पोजीशन में प्रवेश करने के नियम:
सकारात्मक K-लाइन का समापन मूल्य EMA फास्ट लाइन से ऊपर होना चाहिए, दो EMA मूविंग एवरेज एक तेजी वाली व्यवस्था में होने चाहिए (फास्ट लाइन धीमी रेखा से ऊपर है), और VuManChu स्विंग फ्री संकेतक को एक खरीद संकेत दिखाना चाहिए (longCondition सत्य है). यदि तीनों शर्तें पूरी होती हैं, तो यह K-लाइन, दीर्घ स्थिति में प्रवेश करने के लिए प्रमुख K-लाइन है, तथा इस K-लाइन का समापन मूल्य, प्रवेश स्थिति है। -
शॉर्ट पोजीशन में प्रवेश करने के नियम (लॉन्ग पोजीशन के विपरीत):
नकारात्मक कैंडलस्टिक का समापन मूल्य तेज ईएमए लाइन से नीचे होना चाहिए, दो ईएमए मूविंग एवरेज एक छोटी स्थिति में होना चाहिए (तेज रेखा धीमी रेखा से नीचे है), और वुमानचू स्विंग फ्री संकेतक को एक विक्रय संकेत दिखाना चाहिए (शॉर्टकंडीशन क्या सच है)। यदि तीनों शर्तें पूरी होती हैं, तो इस K-लाइन का समापन मूल्य शॉर्ट सेलिंग के लिए प्रवेश बिंदु है।
क्या ट्रेडिंग का तर्क बहुत सरल नहीं है? चूँकि स्रोत वीडियो में लाभ-हानि और स्टॉप-लॉस का उल्लेख नहीं किया गया है, इसलिए संपादक एक अधिक उदार लाभ-हानि और स्टॉप-लॉस विधि का उपयोग करेगा, जिसमें एक निश्चित-बिंदु स्टॉप लॉस और ट्रैकिंग का उपयोग किया जाएगा। लाभ लेने के।
कोड डिजाइन
हमने वुमानचू स्विंग फ्री इंडिकेटर का कोड सीधे ही अपने रणनीति कोड में डाल दिया।
फिर हम लेनदेन फ़ंक्शन को कार्यान्वित करने के लिए पाइन भाषा कोड का एक अंश लिखते हैं:
pine
// extend
fastEmaPeriod = input(50, "fastEmaPeriod") // 快线周期
slowEmaPeriod = input(200, "slowEmaPeriod") // 慢线周期
loss = input(30, "loss") // 止损点数
trailPoints = input(30, "trailPoints") // 移动止盈触发点数
trailOffset = input(30, "trailOffset") // 移动止盈偏移量(点数)
amount = input(1, "amount") // 下单量
emaFast = ta.ema(close, fastEmaPeriod) // 计算快线EMA
emaSlow = ta.ema(close, slowEmaPeriod) // 计算慢线EMA
buyCondition = longCondition and emaFast > emaSlow and close > open and close > emaFast // 做多入场条件
sellCondition = shortCondition and emaFast < emaSlow and close < open and close < emaFast // 做空入场条件
if buyCondition and strategy.position_size == 0
strategy.entry("long", strategy.long, amount)
strategy.exit("exit_long", "long", amount, loss=loss, trail_points=trailPoints, trail_offset=trailOffset)
if sellCondition and strategy.position_size == 0
strategy.entry("short", strategy.short, amount)
strategy.exit("exit_short", "short", amount, loss=loss, trail_points=trailPoints, trail_offset=trailOffset)
A. जैसा कि आप देख सकते हैं, जब buyCondition सत्य है:
- longCondition चर सत्य है (VuManChu स्विंग फ्री संकेतक लंबे समय तक जाने के लिए संकेत भेजता है)।
- emaFast > emaSlow (EMA तेजी व्यवस्था)।
- बंद > खुला (यह दर्शाता है कि वर्तमान BAR एक सकारात्मक रेखा है), बंद > emaFast (यह दर्शाता है कि समापन मूल्य EMA फास्ट रेखा से ऊपर है)।
लंबे समय तक चलने के लिए तीन शर्तें पूरी होती हैं।
B. जब sellCondition सत्य होता है, तो शॉर्ट सेलिंग के लिए तीन शर्तें पूरी होती हैं (यहां समझाया नहीं गया है)।
फिर, जब if स्थिति यह निर्धारित करती है कि संकेत ट्रिगर हो गया है, तो बाजार में प्रवेश करने और एक स्थिति खोलने के लिए रणनीति.प्रविष्टि फ़ंक्शन का उपयोग करें, और नुकसान और ट्रेलिंग लाभ को रोकने के लिए रणनीति.निकास फ़ंक्शन को सेट करें।
पूरा कोड
pine
/*backtest
start: 2022-01-01 00:00:00
end: 2022-10-08 00:00:00
period: 15m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
args: [["ZPrecision",0,358374]]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Credits to the original Script - Range Filter DonovanWall https://www.tradingview.com/script/lut7sBgG-Range-Filter-DW/
// This version is the old version of the Range Filter with less settings to tinker with
//@version=4
study(title="Range Filter - B&S Signals", shorttitle="RF - B&S Signals", overlay=true)
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Functions
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Range Size Function
rng_size(x, qty, n)=>
// AC = Cond_EMA(abs(x - x[1]), 1, n)
wper = (n*2) - 1
avrng = ema(abs(x - x[1]), n)
AC = ema(avrng, wper)*qty
rng_size = AC
//Range Filter Function
rng_filt(x, rng_, n)=>
r = rng_
var rfilt = array.new_float(2, x)
array.set(rfilt, 1, array.get(rfilt, 0))
if x - r > array.get(rfilt, 1)
array.set(rfilt, 0, x - r)
if x + r < array.get(rfilt, 1)
array.set(rfilt, 0, x + r)
rng_filt1 = array.get(rfilt, 0)
hi_band = rng_filt1 + r
lo_band = rng_filt1 - r
rng_filt = rng_filt1
[hi_band, lo_band, rng_filt]
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Inputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Range Source
rng_src = input(defval=close, type=input.source, title="Swing Source")
//Range Period
rng_per = input(defval=20, minval=1, title="Swing Period")
//Range Size Inputs
rng_qty = input(defval=3.5, minval=0.0000001, title="Swing Multiplier")
//Bar Colors
use_barcolor = input(defval=false, type=input.bool, title="Bar Colors On/Off")
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Definitions
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Range Filter Values
[h_band, l_band, filt] = rng_filt(rng_src, rng_size(rng_src, rng_qty, rng_per), rng_per)
//Direction Conditions
var fdir = 0.0
fdir := filt > filt[1] ? 1 : filt < filt[1] ? -1 : fdir
upward = fdir==1 ? 1 : 0
downward = fdir==-1 ? 1 : 0
//Trading Condition
longCond = rng_src > filt and rng_src > rng_src[1] and upward > 0 or rng_src > filt and rng_src < rng_src[1] and upward > 0
shortCond = rng_src < filt and rng_src < rng_src[1] and downward > 0 or rng_src < filt and rng_src > rng_src[1] and downward > 0
CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]
longCondition = longCond and CondIni[1] == -1
shortCondition = shortCond and CondIni[1] == 1
//Colors
filt_color = upward ? #05ff9b : downward ? #ff0583 : #cccccc
bar_color = upward and (rng_src > filt) ? (rng_src > rng_src[1] ? #05ff9b : #00b36b) :
downward and (rng_src < filt) ? (rng_src < rng_src[1] ? #ff0583 : #b8005d) : #cccccc
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Outputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Filter Plot
filt_plot = plot(filt, color=filt_color, transp=67, linewidth=3, title="Filter")
//Band Plots
h_band_plot = plot(h_band, color=color.new(#05ff9b, 100), title="High Band")
l_band_plot = plot(l_band, color=color.new(#ff0583, 100), title="Low Band")
//Band Fills
fill(h_band_plot, filt_plot, color=color.new(#00b36b, 92), title="High Band Fill")
fill(l_band_plot, filt_plot, color=color.new(#b8005d, 92), title="Low Band Fill")
//Bar Color
barcolor(use_barcolor ? bar_color : na)
//Plot Buy and Sell Labels
plotshape(longCondition, title = "Buy Signal", text ="BUY", textcolor = color.white, style=shape.labelup, size = size.normal, location=location.belowbar, color = color.new(color.green, 0))
plotshape(shortCondition, title = "Sell Signal", text ="SELL", textcolor = color.white, style=shape.labeldown, size = size.normal, location=location.abovebar, color = color.new(color.red, 0))
//Alerts
alertcondition(longCondition, title="Buy Alert", message = "BUY")
alertcondition(shortCondition, title="Sell Alert", message = "SELL")
// extend
fastEmaPeriod = input(50, "fastEmaPeriod")
slowEmaPeriod = input(200, "slowEmaPeriod")
loss = input(30, "loss")
trailPoints = input(30, "trailPoints")
trailOffset = input(30, "trailOffset")
amount = input(1, "amount")
emaFast = ta.ema(close, fastEmaPeriod)
emaSlow = ta.ema(close, slowEmaPeriod)
buyCondition = longCondition and emaFast > emaSlow and close > open and close > emaFast
sellCondition = shortCondition and emaFast < emaSlow and close < open and close < emaFast
if buyCondition and strategy.position_size == 0
strategy.entry("long", strategy.long, amount)
strategy.exit("exit_long", "long", amount, loss=loss, trail_points=trailPoints, trail_offset=trailOffset)
if sellCondition and strategy.position_size == 0
strategy.entry("short", strategy.short, amount)
strategy.exit("exit_short", "short", amount, loss=loss, trail_points=trailPoints, trail_offset=trailOffset)
बैकटेस्टिंग
बैकटेस्टिंग समय सीमा जनवरी 2022 से अक्टूबर 2022 तक चुनी जाती है, के-लाइन अवधि 15 मिनट है, और बैकटेस्टिंग के लिए समापन मूल्य मॉडल का उपयोग किया जाता है। बाजार Binance के ETH_USDT सतत अनुबंध को चुनता है। पैरामीटर सेटिंग स्रोत वीडियो में बताए अनुसार हैं: तेज़ लाइन के लिए 50 अवधि और धीमी लाइन के लिए 200 अवधि, तथा अन्य पैरामीटर डिफ़ॉल्ट रूप से अपरिवर्तित रहते हैं। मैं स्टॉप लॉस और ट्रेलिंग प्रॉफिट पॉइंट निर्धारित करने में थोड़ा व्यक्तिपरक हूं और मैंने उन्हें 30 पॉइंट पर ही सेट कर दिया है।
बैकटेस्ट के नतीजे औसत दर्जे के हैं। कई बैकटेस्ट के बाद, ऐसा लगता है कि टेक-प्रॉफिट और स्टॉप-लॉस जैसे पैरामीटर बैकटेस्ट के नतीजों पर कुछ असर डालते हैं। मुझे लगता है कि इस पहलू को और अधिक अनुकूलित करने की आवश्यकता है। हालाँकि, रणनीति संकेत द्वारा लेनदेन शुरू होने के बाद भी जीत की दर अच्छी रहती है।
आइए BTC_USDT सतत अनुबंध का प्रयास करें:
बीटीसी पर बैकटेस्ट के परिणाम भी विस्फोटक हैं:
रणनीति पता: https://www.fmz.com/strategy/385745
ऐसा लगता है कि यह ट्रेडिंग पद्धति प्रवृत्ति को समझने के लिए अपेक्षाकृत विश्वसनीय है, और इस विचार के आधार पर डिजाइन को और अधिक अनुकूलित किया जा सकता है। इस लेख में, हमने न केवल एक डबल मूविंग औसत रणनीति का विचार सीखा, बल्कि यह भी सीखा कि YouTube पर मास्टर्स की रणनीतियों को कैसे संसाधित और सीखना है। ठीक है, ऊपर दिए गए रणनीति कोड सिर्फ़ मेरे सुझाव हैं। बैकटेस्ट के नतीजे विशिष्ट वास्तविक नतीजों का प्रतिनिधित्व नहीं करते। रणनीति कोड और डिज़ाइन सिर्फ़ संदर्भ के लिए हैं। आपके समर्थन के लिए धन्यवाद, अगली बार मिलते हैं!
您好,这个是因为图表上显示的BUY标记只是文章中指标的信号显示,后面还结合了均线。
pine
//Plot Buy and Sell Labels
plotshape(longCondition, title = "Buy Signal", text ="BUY", textcolor = color.white, style=shape.labelup, size = size.normal, location=location.belowbar, color = color.new(color.green, 0))
plotshape(shortCondition, title = "Sell Signal", text ="SELL", textcolor = color.white, style=shape.labeldown, size = size.normal, location=location.abovebar, color = color.new(color.red, 0))
plotshape(longCondition, title = "Buy Signal", text ="BUY 画图显示时,只是longCondition条件符合了。
下单条件在这一块:
pine
if buyCondition and strategy.position_size == 0
strategy.entry("long", strategy.long, amount)
strategy.exit("exit_long", "long", amount, loss=loss, trail_points=trailPoints, trail_offset=trailOffset)
if sellCondition and strategy.position_size == 0
strategy.entry("short", strategy.short, amount)
strategy.exit("exit_short", "short", amount, loss=loss, trail_points=trailPoints, trail_offset=trailOffset)
梦大,建议从油管找两三个具有代表性的,改写难度较大,函数、参数、运算方式较多的策略做几个文字版的教程,比如带有类似【line.delete】这样的。(不需要策略盈利,就算是亏损的策略也无所谓,主要是用来学习写策略)。
我现在用这个双均线的策略,已经学会改一些不是非常复杂的组合策略了,改了十几个组合策略,其中有一两个确实是21年22年数据回测结果非常不错的,也已经在跑实盘测试了,但是遇到复杂函数参数运算这种【比如提示:line: 62 Could not find function or function reference 'line.delete',】而在FMZ PINE Script 文档并没有找到line.delete相关解释,用法说明,就懵圈了,所以希望梦大能弄点儿复杂策略改写一下,当然注释也多一些最好。就更方便学习了。[抱拳]
谢谢梦大。
梦大,请教下,PINE可以写复杂点儿的止盈方式吗?比如分层级止盈这样的???谢谢。
如果PINE可以和JS混编就好了,比如用PINE写指标,JS写交易部分就方便多了。。。。。
好的,谢谢梦大,另外请教下,PINE回测时间区间有限制吗?我选择2021年1月1日,到2022年10月11日,提示错误:
RuntimeError: abort(undefined) at Error at jsStackTrace (eval at self.onmessage (https://www.fmz.com/scripts/worker_detours.393054f7.js:1:147), <anonymous>:1:2096171) at stackTrace (eval at self.onmessage (https://www.fmz.com/scripts/worker_detours.393054f7.js:1:147), <anonymous>:1:2096345) at abort (eval at self.onmessage (https://www.fmz.com/scripts/worker_detours.393054f7.js:1:147), <anonymous>:1:2092408) at _abort (eval at self.onmessage (https://www.fmz.com/scripts/worker_detours.393054f7.js:1:147), <anonymous>:1:2137287) at <anonymous>:wasm-function[1297]:0x76bdc at <anonymous>:wasm-function[466]:0x3d789 at <anonymous>:wasm-function[477]:0x42e6b at <anonymous>:wasm-function[471]:0x4149e at <anonymous>:wasm-function[453]:0x3bf18 at <anonymous>:wasm-function[173]:0x13122
- 1
















