Type/to search
8
Follow
1361
Followers
"Strategi Purata Pergerakan EMA Berganda Ajaib" daripada YouTube Master
Discussions
Created 2022-10-09 15:56:22  Updated 2024-11-29 18:59:45
 28
 7906

img

"Strategi Purata Pergerakan EMA Berganda Ajaib" daripada YouTube Master

Dalam isu ini, kita akan membincangkan "strategi purata bergerak EMA berganda ajaib" daripada YouTube, yang dipanggil "pembunuh pasaran saham dan mata wang kripto." Selepas menonton video, saya mengetahui bahawa strategi ini ialah strategi bahasa pain paparan perdagangan, yang menggunakan 2 penunjuk paparan dagangan. Melihat keputusan ujian belakang dalam video adalah sangat baik, dan FMZ juga menyokong bahasa Pine Trading View, saya tidak dapat membantu tetapi ingin menguji semula dan menguji analisis sendiri. Kemudian mulakan seluruh hidup! Mari kita ulangi strategi dalam video.

Penunjuk yang digunakan oleh strategi

  1. Penunjuk EMA

Demi kesederhanaan dalam reka bentuk, kami tidak akan menggunakan Purata Pergerakan Eksponen yang disenaraikan dalam video. Kami menggunakan ta.ema terbina dalam dalam paparan dagangan sebaliknya (sebenarnya ia adalah sama).

  1. Penunjuk VuManChu Swing Free

Ini adalah penunjuk pada Paparan Dagangan Kita perlu pergi ke Paparan Dagangan dan muat turun kod sumber.

img

Kod Percuma VuManChu Swing:

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")

Logik Strategi

Penunjuk EMA: Strategi menggunakan dua purata bergerak EMA, satu garis pantas (parameter kitaran kecil) dan satu garis perlahan (parameter kitaran besar). Fungsi utama purata bergerak EMA berganda adalah untuk membantu kami menentukan arah aliran pasaran.

  • Susunan panjang
    Garisan pantas berada di atas garisan perlahan.

  • Susunan pendek
    Garisan pantas berada di bawah garisan perlahan.

Penunjuk VuManChu Swing Free: Penunjuk VuManChu Swing Free digunakan untuk menghantar isyarat, dan kemudian digabungkan dengan syarat lain untuk menentukan sama ada untuk membuat pesanan untuk perdagangan. Daripada kod sumber penunjuk VuManChu Swing Free, kita dapat melihat bahawa pembolehubah longCondition mewakili isyarat beli, dan pembolehubah shortCondition mewakili isyarat jual. Kedua-dua pembolehubah ini akan digunakan semasa menulis syarat pesanan nanti.

Sekarang mari kita bercakap tentang isyarat perdagangan tertentu yang mencetuskan syarat strategi:

  1. Peraturan untuk memasuki kedudukan panjang:
    Harga penutupan garis K yang positif hendaklah berada di atas garisan pantas EMA, kedua-dua purata bergerak EMA hendaklah dalam susunan menaik (garisan pantas berada di atas garisan perlahan), dan penunjuk VuManChu Swing Free harus menunjukkan isyarat beli (longCondition adalah benar). Jika ketiga-tiga syarat dipenuhi, K-line ini adalah kunci K-line untuk memasuki kedudukan panjang, dan harga penutupan K-line ini adalah kedudukan kemasukan.

  2. Peraturan untuk memasukkan kedudukan pendek (bertentangan dengan kedudukan panjang):
    Harga penutup batang lilin negatif hendaklah berada di bawah garisan EMA pantas, dua purata bergerak EMA hendaklah berada dalam kedudukan pendek (garisan pantas berada di bawah garisan perlahan), dan penunjuk VuManChu Swing Free harus menunjukkan isyarat jual (shortCondition). adalah benar). Sekiranya ketiga-tiga syarat itu dipenuhi, harga penutupan K-line ini adalah titik masuk untuk jualan pendek.

Bukankah logik dagangan sangat mudah Memandangkan video sumber tidak menyatakan ambil untung dan henti rugi, editor akan menggunakan kaedah ambil untung dan henti rugi yang lebih sederhana, menggunakan henti rugi dan penjejakan mata tetap ambil untung.

Reka bentuk kod

Kami meletakkan kod penunjuk VuManChu Swing Free terus ke dalam kod strategi kami secara utuh.

img

Kemudian kami menulis sekeping kod bahasa Pine untuk melaksanakan fungsi transaksi:

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. Seperti yang anda boleh lihat, apabila buyCondition adalah benar:

  1. Pembolehubah longCondition adalah benar (penunjuk VuManChu Swing Free menghantar isyarat untuk pergi long).
  2. emaFast > emaSlow (aturan kenaikkan EMA).
  3. tutup > buka (menunjukkan bahawa BAR semasa ialah garisan positif), tutup > emaFast (menunjukkan bahawa harga penutupan berada di atas garisan pantas EMA).

Tiga syarat untuk pergi lama dipenuhi.

B. Apabila sellCondition adalah benar, tiga syarat untuk jualan pendek dipenuhi (tidak dijelaskan di sini).

Kemudian, apabila keadaan if menentukan bahawa isyarat dicetuskan, gunakan fungsi strategi.entry untuk memasuki pasaran dan membuka kedudukan, dan tetapkan fungsi strategi.exit untuk menghentikan kerugian dan mengekori keuntungan.

Kod lengkap

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)

Ujian belakang

Julat masa ujian belakang dipilih dari Januari 2022 hingga Oktober 2022, tempoh K-line ialah 15 minit dan model harga penutup digunakan untuk ujian balik. Pasaran memilih kontrak kekal ETH_USDT Binance. Tetapan parameter adalah seperti yang dinyatakan dalam video sumber: 50 titik untuk garis cepat dan 200 titik untuk garis perlahan, dan parameter lain kekal tidak berubah secara lalai. Saya agak subjektif dalam menetapkan stop loss dan mengekori mata keuntungan dan hanya menetapkannya pada 30 mata.

img

img

Keputusan backtest adalah begitu-begitu Selepas beberapa ujian belakang, nampaknya parameter seperti take-profit dan stop-loss mempunyai beberapa kesan pada keputusan backtest. Saya merasakan bahawa aspek ini memerlukan pengoptimuman selanjutnya. Walau bagaimanapun, kadar kemenangan masih baik selepas isyarat strategi mencetuskan transaksi.

Mari cuba kontrak kekal BTC_USDT:

img

Keputusan ujian belakang pada BTC juga meletup:

img

img

Alamat strategi: https://www.fmz.com/strategy/385745

Nampaknya kaedah dagangan ini agak boleh dipercayai untuk memahami arah aliran, dan reka bentuk boleh dioptimumkan lagi berdasarkan idea ini. Dalam artikel ini, kami bukan sahaja mempelajari idea strategi purata bergerak berganda, tetapi juga mempelajari cara memproses dan mempelajari strategi pakar di YouTube. OK, kod strategi di atas hanyalah cadangan saya Hasil ujian belakang tidak mewakili keputusan sebenar yang khusus Kod dan reka bentuk strategi adalah untuk rujukan sahaja. Terima kasih atas sokongan anda, jumpa lagi di lain kali!

Related Recommendations
Comment
All comments (27)

    梦总,现在回测,2022年1月3日之后就不交易了是怎么回事,也不报错..

    2 years ago

    在的,您说的是这个策略吗?

    2 years ago

    是的 img

    2 years ago

    好的, 这边测试看看。

    2 years ago

    这个策略会不会也是赌参数呢?

    4 years ago

    哈哈,本身做趋势策略就是赌,赌未来行情有趋势,否则就做震荡策略了。

    4 years ago

    梦大,为什么图标上显示信号但是实盘没有开单呢
    img
    img
    img

    4 years ago

    您好,这个是因为图表上显示的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)
    4 years ago

    感谢梦大

    4 years ago

    不客气。

    4 years ago

    梦大,建议从油管找两三个具有代表性的,改写难度较大,函数、参数、运算方式较多的策略做几个文字版的教程,比如带有类似【line.delete】这样的。(不需要策略盈利,就算是亏损的策略也无所谓,主要是用来学习写策略)。
    我现在用这个双均线的策略,已经学会改一些不是非常复杂的组合策略了,改了十几个组合策略,其中有一两个确实是21年22年数据回测结果非常不错的,也已经在跑实盘测试了,但是遇到复杂函数参数运算这种【比如提示:line: 62 Could not find function or function reference 'line.delete',】而在FMZ PINE Script 文档并没有找到line.delete相关解释,用法说明,就懵圈了,所以希望梦大能弄点儿复杂策略改写一下,当然注释也多一些最好。就更方便学习了。[抱拳]
    谢谢梦大。

    4 years ago

    line 这个对象在FMZ上暂时还没支持,所以有些带line这种的可能改不了。有些策略使用了这个对象参与计算了。

    4 years ago

    怪不得,明白了,谢谢

    4 years ago

    时间选21年4月-10月,BTC比较惨

    4 years ago

    看文档看不懂这个止盈止损是什么意思 方便解释一下吗?比如默认的30 意思就是btc跌了30刀?就止损?

    4 years ago

    Pine语言教程里有章节有描述,您可以看下:https://www.fmz.com/bbs-topic/9390#带跟踪止损止盈的超级趋势策略

    4 years ago

    梦大,请教下,PINE可以写复杂点儿的止盈方式吗?比如分层级止盈这样的???谢谢。
    如果PINE可以和JS混编就好了,比如用PINE写指标,JS写交易部分就方便多了。。。。。

    4 years ago

    Pine应该可以设计更加复杂的止盈,嵌入JS代码这个暂时还没有。

    4 years ago

    好的,谢谢梦大,另外请教下,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

    但是如果不改时间段就正常回测了。。。。 img

    4 years ago

    没有限制,这个报错应该是回测时间范围过大。

    4 years ago

    嗯嗯,我设置1年内或者10个月,基本上能完成,过了1年就会有这个提示或者一堆别的了。。。。。

    4 years ago

    应该是回测时间太长,数据多导致的。

    4 years ago

    实盘会有-2022的报错

    4 years ago

    可以发下截图,看下具体报错。

    4 years ago

    保存策略提示这玩意
    REST: sql: no rows in result set

    4 years ago

    哦,不好意思,策略地址贴错了,已经修改啦~

    4 years ago

    梦总牛逼

    4 years ago
  • 1
iPhone Download
Forums
PINE Language
© 2015 - ∞ INVENTOR PTE LTD (SG)