سی وی ڈی ڈائیورجنسی کوانٹیٹیٹیو ٹریڈنگ حکمت عملی

مصنف:چاؤ ژانگ، تاریخ: 2024-03-15 16:47:47
ٹیگز:

img

حکمت عملی کا جائزہ: سی وی ڈی تغیرات کی مقداری تجارتی حکمت عملی سی وی ڈی اشارے اور قیمت کے مابین تغیرات کو ممکنہ رجحان الٹ سگنلز پر قبضہ کرنے کے لئے استعمال کرتی ہے۔ حکمت عملی سی وی ڈی اشارے کا حساب لگاتی ہے اور اس کی قیمت کے ساتھ موازنہ کرتی ہے تاکہ یہ معلوم کیا جاسکے کہ کیا تیزی یا bearish تغیرات تشکیل پائے ہیں۔ جب تغیراتی سگنل کا پتہ چلتا ہے تو ، حکمت عملی ایک لمبی یا مختصر پوزیشن کھولتی ہے۔ یہ خطرہ کو کنٹرول کرنے اور منافع میں تالا لگانے کے لئے ٹریلنگ اسٹاپ نقصان اور مقررہ فیصد منافع بھی استعمال کرتی ہے۔ حکمت عملی متعدد پوزیشنوں کے ساتھ اہرام سازی کی حمایت کرتی ہے۔

حکمت عملی کے اصول:

  1. سی وی ڈی اشارے کا حساب لگائیں: سی وی ڈی اشارے اور اس کے چلتے ہوئے اوسط کا حساب بڑھتی ہوئی اور bearish حجم کی بنیاد پر لگائیں۔
  2. اختلافات کی نشاندہی کریں: اس بات کا تعین کرنے کے لئے کہ آیا اختلافات تشکیل پائے ہیں ، سی وی ڈی اشارے کی اونچائیوں اور اونچائیوں کا قیمت کی اونچائیوں اور اونچائیوں کے ساتھ موازنہ کریں۔
    • باقاعدگی سے تیزی کا فرق: قیمت کم کم ہوتی ہے ، لیکن سی وی ڈی اعلی کم بناتا ہے۔
    • پوشیدہ تیزی کا فرق: قیمت ایک اعلی کم بناتا ہے، لیکن سی وی ڈی ایک کم کم بناتا ہے.
    • باقاعدہ bearish divergence: قیمت ایک اعلی اعلی بناتا ہے، لیکن CVD ایک کم اعلی بناتا ہے.
    • خفیہ bearish divergence: قیمت ایک کم اعلی بناتا ہے، لیکن CVD ایک اعلی اعلی بناتا ہے.
  3. کھلی پوزیشنیں: جب کوئی انحراف کا اشارہ ملتا ہے تو، انحراف کی قسم کی بنیاد پر ایک لمبی یا مختصر پوزیشن کھولیں۔
  4. اسٹاپ نقصان اور منافع حاصل کریں: ٹریلنگ اسٹاپ نقصان اور مقررہ فیصد منافع حاصل کریں۔ اسٹاپ نقصان کی قیمت کا حساب اسٹاپ نقصان فیصد سے ضرب کرکے کیا جاتا ہے ، اور منافع کی قیمت کا حساب منافع کی فیصد سے ضرب کرکے کیا جاتا ہے۔
  5. پرامائڈنگ: حکمت عملی پرامائڈنگ کے لئے زیادہ سے زیادہ 3 پوزیشنوں کی اجازت دیتی ہے۔

حکمت عملی کے فوائد:

  1. رجحان کی تبدیلی کے اشارے: سی وی ڈی کی تبدیلی ایک مؤثر رجحان کی تبدیلی کا اشارہ ہے جو رجحان کی تبدیلی کے مواقع کو پکڑنے میں مدد کرسکتا ہے۔
  2. رجحان کی تسلسل کے سگنل: پوشیدہ اختلافات رجحان کی تسلسل کے سگنل کے طور پر کام کرسکتے ہیں ، جس سے رجحانات کے دوران حکمت عملی کو صحیح سمت برقرار رکھنے میں مدد ملتی ہے۔
  3. خطرے کا کنٹرول: ٹریلنگ سٹاپ نقصان اور مقررہ فیصد منافع لینے کا استعمال کرتے ہوئے، خطرے کو مؤثر طریقے سے منظم کیا جاتا ہے.
  4. پرامڈائڈنگ: پرامڈائڈنگ کے لئے متعدد پوزیشنوں کی اجازت دینے سے رجحانات کی منڈیوں پر بہتر سرمایہ کاری ممکن ہوتی ہے۔

حکمت عملی کے خطرات:

  1. سگنل کی صداقت: انحراف سگنل مکمل طور پر قابل اعتماد نہیں ہیں اور بعض اوقات غلط سگنل بھی ہوسکتے ہیں۔
  2. پیرامیٹر کی تشکیل: حکمت عملی کے نتائج پیرامیٹر کی ترتیبات کے لئے حساس ہیں ، اور مختلف پیرامیٹرز مختلف نتائج کا باعث بن سکتے ہیں۔
  3. اسٹاپ نقصان کی کمی: غیر مستحکم مارکیٹوں میں ، اسٹاپ نقصان کے احکامات کو پہلے سے طے شدہ قیمت پر پورا نہیں کیا جاسکتا ہے ، جس سے اضافی خطرہ پیدا ہوتا ہے۔
  4. لین دین کے اخراجات: پوزیشنوں کے اکثر کھولنے اور بند ہونے سے لین دین کے اخراجات زیادہ ہو سکتے ہیں، جس سے حکمت عملی کی منافع بخش پر اثر پڑتا ہے۔

اصلاح کی ہدایات:

  1. متحرک پیرامیٹر کی اصلاح: سگنل کی موزونیت کو بہتر بنانے کے لئے مختلف مارکیٹ کے حالات کے لئے موافقت پذیر پیرامیٹرز کا استعمال کریں۔
  2. دوسرے اشارے کے ساتھ امتزاج: سگنل کی وشوسنییتا کو بڑھانے کے لئے دیگر تکنیکی اشارے جیسے آر ایس آئی ، ایم اے سی ڈی وغیرہ کے ساتھ ضم کریں۔
  3. بہتر سٹاپ نقصان اور منافع لے لو: زیادہ اعلی درجے کی سٹاپ نقصان کو اپنانا اور منافع لینے کی حکمت عملی، جیسے ٹرائلنگ سٹاپ نقصان یا اتار چڑھاؤ پر مبنی سٹاپ نقصان.
  4. پوزیشن سائزنگ: مارکیٹ کی اتار چڑھاؤ، اکاؤنٹ کیپٹل وغیرہ کی بنیاد پر پوزیشن سائز کو متحرک طور پر ایڈجسٹ کریں۔

نتیجہ: سی وی ڈی ڈائیورجنسی مقداری تجارتی حکمت عملی کا مقصد سی وی ڈی اشارے اور قیمت کے مابین اختلافات کو پکڑ کر ممکنہ رجحان کی تبدیلی کے مواقع کی نشاندہی کرنا ہے۔ یہ خطرے کو سنبھالنے کے لئے ٹریلنگ اسٹاپ نقصان اور مقررہ فیصد منافع حاصل کرنے کا استعمال کرتا ہے۔ حکمت عملی کے اہم فوائد اس کی صلاحیت میں ہیں کہ وہ رجحان کی تبدیلی اور تسلسل کے اشاروں کو مؤثر طریقے سے پکڑ سکے ، اور پرامڈائڈنگ کے ذریعہ رجحان کی مارکیٹوں پر بہتر فائدہ اٹھاسکے۔ تاہم ، اس حکمت عملی کو سگنل کی موزونیت ، پیرامیٹر کی تشکیل ، اسٹاپ نقصان کی کھوج ، اور لین دین کے اخراجات جیسے خطرات کا بھی سامنا کرنا پڑتا ہے۔ مستقبل میں بہتری متحرک پیرامیٹر کی اصلاح ، دوسرے اشارے کے ساتھ امتزاج ، بہتر اسٹاپ نقصان اور منافع لینے کے طریقہ کار ، اور پوزیشن سائزنگ مینجمنٹ کے ذریعے کی جاسکتی ہے۔ مجموعی طور پر ، سی وی ڈی ڈائیورجنسی مقداری تجارتی حکمت عملی ان تاجروں کے لئے ایک موثر اور اصلاح پذیر رجحان کی پیروی کرنے والی حکمت عملی ہے جو رجحان کے مواقع کو سنبھالنے


/*backtest
start: 2023-03-09 00:00:00
end: 2024-03-14 00:00:00
period: 1d
basePeriod: 1h
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/

//@version=5
//@ mmattman

//Thank you to @ contrerae and Tradingview each for parts of the code to make 
//this indicator and matching strategy and also theCrypster for the clean concise TP/SL code.

// indicator(title="CVD Divergence Indicator 1", shorttitle='CVD Div1', format=format.price, timeframe="", timeframe_gaps=true)

strategy("CVD Divergence Strategy.1.mm", shorttitle = 'CVD Div Str 1', overlay=false)


//..................................................................................................................
// Inputs
periodMa = input.int(title='MA Length', minval=1, defval=20)
plotMa = input(title='Plot MA?', defval=false)

// Calculations (Bull & Bear Balance Indicator by Vadim Gimelfarb)
iff_1 = close[1] < open ? math.max(high - close[1], close - low) : math.max(high - open, close - low)
iff_2 = close[1] > open ? high - low : math.max(open - close[1], high - low)
iff_3 = close[1] < open ? math.max(high - close[1], close - low) : high - open
iff_4 = close[1] > open ? high - low : math.max(open - close[1], high - low)
iff_5 = close[1] < open ? math.max(open - close[1], high - low) : high - low
iff_6 = close[1] > open ? math.max(high - open, close - low) : iff_5
iff_7 = high - close < close - low ? iff_4 : iff_6
iff_8 = high - close > close - low ? iff_3 : iff_7
iff_9 = close > open ? iff_2 : iff_8
bullPower = close < open ? iff_1 : iff_9
iff_10 = close[1] > open ? math.max(close[1] - open, high - low) : high - low
iff_11 = close[1] > open ? math.max(close[1] - low, high - close) : math.max(open - low, high - close)
iff_12 = close[1] > open ? math.max(close[1] - open, high - low) : high - low
iff_13 = close[1] > open ? math.max(close[1] - low, high - close) : open - low
iff_14 = close[1] < open ? math.max(open - low, high - close) : high - low
iff_15 = close[1] > open ? math.max(close[1] - open, high - low) : iff_14
iff_16 = high - close < close - low ? iff_13 : iff_15
iff_17 = high - close > close - low ? iff_12 : iff_16
iff_18 = close > open ? iff_11 : iff_17
bearPower = close < open ? iff_10 : iff_18

// Calculations (Bull & Bear Pressure Volume)
bullVolume = bullPower / (bullPower + bearPower) * volume
bearVolume = bearPower / (bullPower + bearPower) * volume

// Calculations Delta
delta = bullVolume - bearVolume
cvd = ta.cum(delta)
cvdMa = ta.sma(cvd, periodMa)

// Plotting
customColor = cvd > cvdMa ? color.new(color.teal, 50) : color.new(color.red, 50)
plotRef1 = plot(cvd, style=plot.style_line, linewidth=1, color=color.new(color.yellow, 0), title='CVD')
plotRef2 = plot(plotMa ? cvdMa : na, style=plot.style_line, linewidth=1, color=color.new(color.white, 0), title='CVD MA')
fill(plotRef1, plotRef2, color=customColor)
//..................................................................................................................


// len = input.int(title="RSI Period", minval=1, defval=14)
// src = input(title="RSI Source", defval=close)
lbR = input(title="Pivot Lookback Right", defval=3)
lbL = input(title="Pivot Lookback Left", defval=7)
rangeUpper = input(title="Max of Lookback Range", defval=60)
rangeLower = input(title="Min of Lookback Range", defval=5)
plotBull = input(title="Plot Bullish", defval=true)
plotHiddenBull = input(title="Plot Hidden Bullish", defval=true)
plotBear = input(title="Plot Bearish", defval=true)
plotHiddenBear = input(title="Plot Hidden Bearish", defval=true)
bearColor = color.red
bullColor = color.green
hiddenBullColor = color.new(color.green, 80)
hiddenBearColor = color.new(color.red, 80)
textColor = color.white
noneColor = color.new(color.white, 100)
osc = cvd

// plot(osc, title="CVD", linewidth=2, color=#2962FF)
// hline(50, title="Middle Line", color=#787B86, linestyle=hline.style_dotted)
// obLevel = hline(70, title="Overbought", color=#787B86, linestyle=hline.style_dotted)
// osLevel = hline(30, title="Oversold", color=#787B86, linestyle=hline.style_dotted)
// fill(obLevel, osLevel, title="Background", color=color.rgb(33, 150, 243, 90))

plFound = na(ta.pivotlow(osc, lbL, lbR)) ? false : true
phFound = na(ta.pivothigh(osc, lbL, lbR)) ? false : true
_inRange(cond) =>
	bars = ta.barssince(cond == true)
	rangeLower <= bars and bars <= rangeUpper

//------------------------------------------------------------------------------
// Regular Bullish
// Osc: Higher Low

oscHL = osc[lbR] > ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])

// Price: Lower Low

priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1)
bullCondAlert = priceLL and oscHL and plFound
bullCond = plotBull and bullCondAlert

plot(
     plFound ? osc[lbR] : na,
     offset=-lbR,
     title="Regular Bullish",
     linewidth=2,
     color=(bullCond ? bullColor : noneColor)
     )

plotshape(
	 bullCond ? osc[lbR] : na,
	 offset=-lbR,
	 title="Regular Bullish Label",
	 text=" Bull ",
	 style=shape.labelup,
	 location=location.absolute,
	 color=bullColor,
	 textcolor=textColor
	 )

//------------------------------------------------------------------------------
// Hidden Bullish
// Osc: Lower Low

oscLL = osc[lbR] < ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])

// Price: Higher Low

priceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1)
hiddenBullCondAlert = priceHL and oscLL and plFound
hiddenBullCond = plotHiddenBull and hiddenBullCondAlert

plot(
	 plFound ? osc[lbR] : na,
	 offset=-lbR,
	 title="Hidden Bullish",
	 linewidth=2,
	 color=(hiddenBullCond ? hiddenBullColor : noneColor)
	 )

plotshape(
	 hiddenBullCond ? osc[lbR] : na,
	 offset=-lbR,
	 title="Hidden Bullish Label",
	 text=" H Bull ",
	 style=shape.labelup,
	 location=location.absolute,
	 color=bullColor,
	 textcolor=textColor
	 )

//------------------------------------------------------------------------------
// Regular Bearish
// Osc: Lower High

oscLH = osc[lbR] < ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])

// Price: Higher High

priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1)

bearCondAlert = priceHH and oscLH and phFound
bearCond = plotBear and bearCondAlert

plot(
	 phFound ? osc[lbR] : na,
	 offset=-lbR,
	 title="Regular Bearish",
	 linewidth=2,
	 color=(bearCond ? bearColor : noneColor)
	 )

plotshape(
	 bearCond ? osc[lbR] : na,
	 offset=-lbR,
	 title="Regular Bearish Label",
	 text=" Bear ",
	 style=shape.labeldown,
	 location=location.absolute,
	 color=bearColor,
	 textcolor=textColor
	 )

//------------------------------------------------------------------------------
// Hidden Bearish
// Osc: Higher High

oscHH = osc[lbR] > ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])

// Price: Lower High

priceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1)

hiddenBearCondAlert = priceLH and oscHH and phFound
hiddenBearCond = plotHiddenBear and hiddenBearCondAlert

plot(
	 phFound ? osc[lbR] : na,
	 offset=-lbR,
	 title="Hidden Bearish",
	 linewidth=2,
	 color=(hiddenBearCond ? hiddenBearColor : noneColor)
	 )

plotshape(
	 hiddenBearCond ? osc[lbR] : na,
	 offset=-lbR,
	 title="Hidden Bearish Label",
	 text=" H Bear ",
	 style=shape.labeldown,
	 location=location.absolute,
	 color=bearColor,
	 textcolor=textColor
	 )

// alertcondition(bullCondAlert, title='Regular Bullish CVD Divergence', message="Found a new Regular Bullish Divergence, `Pivot Lookback Right` number of bars to the left of the current bar")
// alertcondition(hiddenBullCondAlert, title='Hidden Bullish CVD Divergence', message='Found a new Hidden Bullish Divergence, `Pivot Lookback Right` number of bars to the left of the current bar')
// alertcondition(bearCondAlert, title='Regular Bearish CVD Divergence', message='Found a new Regular Bearish Divergence, `Pivot Lookback Right` number of bars to the left of the current bar')
// alertcondition(hiddenBearCondAlert, title='Hidden Bearisn CVD Divergence', message='Found a new Hidden Bearisn Divergence, `Pivot Lookback Right` number of bars to the left of the current bar')

le = bullCondAlert or hiddenBullCondAlert

se = bearCondAlert or hiddenBearCondAlert

ltp = se

stp = le

// Check if the entry conditions for a long position are met
if (le) //and (close > ema200)
    strategy.entry("Long", strategy.long, comment="EL")

 // Check if the entry conditions for a short position are met
if (se) //and (close < ema200)
    strategy.entry("Short", strategy.short, comment="ES")

// Close long position if exit condition is met
if (ltp) // or (close < ema200)
    strategy.close("Long", comment="XL")

    // Close short position if exit condition is met
if (stp) //or (close > ema200)
    strategy.close("Short", comment="XS")


// The Fixed Percent Stop Loss Code
// User Options to Change Inputs (%)
stopPer = input.float(5.0, title='Stop Loss %') / 100
takePer = input.float(10.0, title='Take Profit %') / 100

// Determine where you've entered and in what direction
longStop = strategy.position_avg_price * (1 - stopPer)
shortStop = strategy.position_avg_price * (1 + stopPer)
shortTake = strategy.position_avg_price * (1 - takePer)
longTake = strategy.position_avg_price * (1 + takePer)

if strategy.position_size > 0 
    strategy.exit("Close Long", "Long", stop=longStop, limit=longTake)
if strategy.position_size < 0 
    strategy.exit("Close Short", "Short", stop=shortStop, limit=shortTake)









مزید