یوٹیوب ماسٹر سے "جادوئی ڈبل EMA موونگ ایوریج اسٹریٹجی"
اس شمارے میں، ہم یوٹیوب سے ایک "جادوئی ڈبل EMA موونگ ایوریج حکمت عملی" پر بات کریں گے، جسے "اسٹاک اور کریپٹو کرنسی مارکیٹ قاتل" کہا جاتا ہے۔ ویڈیو دیکھنے کے بعد، میں نے سیکھا کہ یہ حکمت عملی ایک ٹریڈنگ ویو پائن لینگویج اسٹریٹجی ہے، جو 2 ٹریڈنگ ویو انڈیکیٹرز استعمال کرتی ہے۔ ویڈیو میں بیک ٹیسٹنگ کے نتائج دیکھ کر بہت اچھے تھے، اور FMZ ٹریڈنگ ویو کی پائن لینگویج کو بھی سپورٹ کرتا ہے، میں مدد نہیں کر سکا لیکن میں خود بیک ٹیسٹ کرنا چاہتا ہوں اور تجزیہ کرنا چاہتا ہوں۔ پھر پوری زندگی شروع! آئیے ویڈیو میں حکمت عملی کو نقل کرتے ہیں۔
حکمت عملی کے ذریعہ استعمال کردہ اشارے
- EMA اشارے
ڈیزائن میں سادگی کی خاطر، ہم ویڈیو میں درج موونگ ایوریج ایکسپونیشل استعمال نہیں کریں گے۔ ہم اس کی بجائے ٹریڈنگ ویو میں بلٹ ان ta.ema استعمال کرتے ہیں (دراصل وہ ایک جیسے ہیں)۔
- VuManChu سوئنگ فری انڈیکیٹر
یہ ٹریڈنگ ویو پر ایک انڈیکیٹر ہے ہمیں ٹریڈنگ ویو پر جانا اور سورس کوڈ ڈاؤن لوڈ کرنا ہے۔
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")
حکمت عملی کی منطق
EMA اشارے: حکمت عملی دو EMA حرکت پذیر اوسط، ایک تیز لائن (چھوٹا سائیکل پیرامیٹر) اور ایک سست لائن (بڑے سائیکل پیرامیٹر) کا استعمال کرتی ہے۔ ڈبل EMA موونگ ایوریج کا بنیادی کام مارکیٹ کے رجحانات کی سمت کا تعین کرنے میں ہماری مدد کرنا ہے۔
-
طویل انتظام
تیز لائن سست لائن کے اوپر ہے۔ -
مختصر انتظام
تیز لائن سست لائن سے نیچے ہے۔
VuManChu Swing Free Indicator: VuManChu Swing Free Indicator کو سگنل بھیجنے کے لیے استعمال کیا جاتا ہے، اور پھر دوسری شرائط کے ساتھ یہ طے کرنے کے لیے کہ آیا ٹریڈنگ کے لیے آرڈر دینا ہے۔ VuManChu سوئنگ فری انڈیکیٹر سورس کوڈ سے، ہم دیکھ سکتے ہیں کہ longCondition متغیر خرید سگنل کی نمائندگی کرتا ہے، اور shortCondition متغیر فروخت سگنل کی نمائندگی کرتا ہے۔ بعد میں آرڈر کی شرائط لکھتے وقت یہ دو متغیر استعمال کیے جائیں گے۔
اب آئیے حکمت عملی کے مخصوص تجارتی سگنل کو متحرک کرنے والے حالات کے بارے میں بات کرتے ہیں:
-
لمبی پوزیشنوں میں داخل ہونے کے اصول:
مثبت K-لائن کی اختتامی قیمت EMA فاسٹ لائن سے اوپر ہونی چاہیے، دو EMA موونگ ایوریجز تیزی سے ترتیب میں ہونی چاہئیں (تیز لائن سست لائن سے اوپر ہے)، اور VuManChu Swing Free اشارے کو خرید کا سگنل دکھانا چاہیے۔ (طویل حالت درست ہے)۔ اگر تین شرائط پوری ہوجاتی ہیں، تو یہ K-لائن لمبی پوزیشن میں داخل ہونے کے لیے کلیدی K-لائن ہے، اور اس K-لائن کی اختتامی قیمت اندراج کی پوزیشن ہے۔ -
مختصر پوزیشن میں داخل ہونے کے قواعد (لمبی پوزیشن کے برعکس):
منفی کینڈل سٹک کی اختتامی قیمت تیز EMA لائن سے نیچے ہونی چاہیے، دو EMA حرکت پذیر اوسط مختصر پوزیشن میں ہونی چاہیے (تیز لائن سست لائن سے نیچے ہے)، اور VuManChu سوئنگ فری انڈیکیٹر کو فروخت کا سگنل دکھانا چاہیے (شارٹ کنڈیشن سچ ہے)۔ اگر تین شرائط پوری ہوتی ہیں، تو اس K-لائن کی اختتامی قیمت مختصر فروخت کے لیے انٹری پوائنٹ ہے۔
کیا تجارتی منطق بہت آسان نہیں ہے چونکہ ماخذ ویڈیو میں ٹیک-پرافٹ اور سٹاپ لاس کی وضاحت نہیں کی گئی ہے، اس لیے ایڈیٹر ایک فکسڈ پوائنٹ سٹاپ نقصان اور ٹریکنگ کا استعمال کرتے ہوئے زیادہ معتدل ٹیک-پرافٹ اور سٹاپ لاس کا طریقہ استعمال کرے گا؟ فائدہ اٹھانا
کوڈ ڈیزائن
ہم VuManChu Swing Free اشارے کے کوڈ کو براہ راست اپنے حکمت عملی کوڈ میں برقرار رکھتے ہیں۔
پھر ہم ٹرانزیکشن فنکشن کو نافذ کرنے کے لیے پائن لینگویج کوڈ کا ایک ٹکڑا لکھتے ہیں:
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 Swing Free indicator طویل جانے کے لیے سگنل بھیجتا ہے)۔
- emaFast > emaSlow (EMA تیزی کا انتظام)۔
- بند کریں > کھلا (اس بات کی نشاندہی کرتا ہے کہ موجودہ بار ایک مثبت لائن ہے)، بند کریں > emaFast (یہ بتاتا ہے کہ اختتامی قیمت EMA فاسٹ لائن سے اوپر ہے)۔
لمبا سفر کرنے کی تین شرائط پوری ہوتی ہیں۔
B. فروخت کی حالت درست ہونے پر، مختصر فروخت کے لیے تین شرائط پوری ہوتی ہیں (یہاں بیان نہیں کیا گیا)۔
پھر، جب if حالت یہ طے کرتی ہے کہ سگنل ٹرگر ہو گیا ہے، تو مارکیٹ میں داخل ہونے اور پوزیشن کھولنے کے لیے strategy.entry فنکشن کا استعمال کریں، اور نقصان اور پچھلے منافع کو روکنے کے لیے strategy.exit فنکشن سیٹ کریں۔
مکمل کوڈ
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 تک منتخب کی گئی ہے، K-line کی مدت 15 منٹ ہے، اور اختتامی قیمت کا ماڈل بیک ٹیسٹنگ کے لیے استعمال کیا جاتا ہے۔ مارکیٹ Binance کے ETH_USDT دائمی معاہدے کا انتخاب کرتی ہے۔ پیرامیٹر سیٹنگز جیسا کہ سورس ویڈیو میں بتایا گیا ہے: فاسٹ لائن کے لیے 50 پیریڈز اور سلو لائن کے لیے 200 پیریڈز، اور دیگر پیرامیٹرز بذریعہ ڈیفالٹ غیر تبدیل شدہ رہتے ہیں۔ میں سٹاپ نقصان اور پچھلے منافع کے پوائنٹس کو سیٹ کرنے میں تھوڑا سا ساپیکش ہوں اور انہیں صرف 30 پوائنٹس پر سیٹ کرتا ہوں۔
بیک ٹیسٹ کے نتائج بہت زیادہ بیک ٹیسٹ کے بعد، ایسا لگتا ہے کہ ٹیک-پرافٹ اور سٹاپ-لاس جیسے پیرامیٹر کا بیک ٹیسٹ کے نتائج پر کچھ اثر پڑتا ہے۔ میں محسوس کرتا ہوں کہ اس پہلو کو مزید بہتر بنانے کی ضرورت ہے۔ تاہم، حکمت عملی کے سگنل کے ٹرانزیکشن کو متحرک کرنے کے بعد جیتنے کی شرح اب بھی اچھی ہے۔
آئیے ایک BTC_USDT دائمی معاہدہ آزمائیں:
بی ٹی سی پر بیک ٹیسٹ کے نتائج بھی دھماکہ خیز ہیں:
حکمت عملی کا پتہ: https://www.fmz.com/strategy/385745
ایسا لگتا ہے کہ یہ تجارتی طریقہ رجحان کو سمجھنے کے لیے نسبتاً قابل اعتماد ہے، اور اس خیال کی بنیاد پر ڈیزائن کو مزید بہتر بنایا جا سکتا ہے۔ اس آرٹیکل میں، ہم نے نہ صرف ڈبل موونگ ایوریج اسٹریٹجی کا آئیڈیا سیکھا بلکہ یوٹیوب پر ماسٹرز کی حکمت عملیوں کو پروسیس کرنے اور سیکھنے کا طریقہ بھی سیکھا۔ ٹھیک ہے، اوپر دیئے گئے حکمت عملی کے کوڈز صرف میری تجاویز ہیں۔ آپ کے تعاون کا شکریہ، اگلی بار ملیں گے!
您好,这个是因为图表上显示的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
















