दोहरी चलती औसत क्रॉसओवर एल्गोरिथम ट्रेडिंग रणनीति

लेखक:चाओझांग, दिनांकः 2023-10-30 15:27:34
टैगः

img

अवलोकन

यह रणनीति मुख्य रूप से चलती औसत क्रॉसओवर सिद्धांत का उपयोग करती है, जो कि आरएसआई संकेतक रिवर्सल सिग्नल और ट्रेंड ट्रेडिंग को लागू करने के लिए कस्टम डबल मूविंग एवरेज क्रॉसओवर एल्गोरिथ्म के साथ संयुक्त है। यह रणनीति अलग-अलग अवधि के दो चलती औसत को ट्रैक करती है, जिसमें एक तेज एमए अल्पकालिक रुझानों को ट्रैक करता है और एक धीमी एमए दीर्घकालिक रुझानों को ट्रैक करता है। जब तेज एमए धीमी एमए को ऊपर की ओर पार करता है, तो यह एक ऊपर की प्रवृत्ति और खरीदने का मौका संकेत देता है। जब तेज एमए धीमी एमए से नीचे पार करता है, तो यह अल्पकालिक प्रवृत्ति के अंत और पदों को बंद करने का मौका संकेत देता है।

रणनीति तर्क

  1. विभिन्न मापदंडों के साथ VWAP चलती औसत के दो समूहों की गणना करें, जो क्रमशः दीर्घकालिक और अल्पकालिक रुझानों का प्रतिनिधित्व करते हैं।

    • धीमी Tenkansen और Kijunsen लंबी अवधि के रुझान की गणना
    • फास्ट टेनकैंसेन और किजुनसेन ने अल्पकालिक प्रवृत्ति की गणना की
  2. Tenkansen और Kijunsen के औसत धीमी और तेजी से चलती औसत के रूप में ले लो.

  3. समेकन और ब्रेकआउट की पहचान करने के लिए बोलिंगर बैंड की गणना करें।

    • मध्य रेखा तेज और धीमी एमए का औसत है
    • ऊपरी और निचले बैंड का उपयोग ब्रेकआउट का पता लगाने के लिए किया जाता है
  4. वॉल्यूम ऊर्जा निर्धारित करने के लिए TSV की गणना

    • 0 से अधिक TSV तेजी की मात्रा दर्शाता है
    • इसके ईएमए से अधिक टीएसवी मजबूत गति का संकेत देता है
  5. ओवरबॉट और ओवरसोल्ड स्थितियों की पहचान करने के लिए आरएसआई की गणना करें

    • आरएसआई 30 से नीचे खरीद के लिए ओवरसोल्ड क्षेत्र है
    • 70 से ऊपर का आरएसआई बिक्री के लिए ओवरबॉट क्षेत्र है।
  6. प्रवेश की शर्तें:

    • तेज एमए धीमे एमए से पार होता है
    • ऊपरी बोलिंगर बैंड के ऊपर बंद क्रॉस
    • टीएसवी 0 से अधिक और ईएमए
    • आरएसआई 30 से नीचे
  7. बाहर निकलने की शर्तेंः

    • तेज एमए धीमी एमए से नीचे जाता है
    • आरएसआई 70 से अधिक

लाभ विश्लेषण

  1. दोहरी चलती औसत प्रणाली दीर्घकालिक और अल्पकालिक दोनों रुझानों को पकड़ती है

  2. आरएसआई ओवरबॉट जोन खरीदने और ओवरसोल्ड जोन बेचने से बचता है

  3. टीएसवी प्रवृत्ति का समर्थन करने के लिए पर्याप्त मात्रा सुनिश्चित करता है

  4. बोलिंगर बैंड्स प्रमुख ब्रेकआउट बिंदुओं की पहचान करते हैं

  5. संकेतकों का संयोजन झूठे ब्रेकआउट को फ़िल्टर करने में मदद करता है

जोखिम विश्लेषण

  1. एमए सिस्टम झूठे संकेतों के लिए प्रवण हैं, अन्य संकेतकों के साथ फ़िल्टर करने की आवश्यकता है

  2. आरएसआई मापदंडों को अनुकूलित करने की आवश्यकता है, अन्यथा खरीद / बिक्री बिंदुओं को याद कर सकते हैं

  3. टीएसवी भी मापदंडों के लिए बहुत संवेदनशील है, सावधानीपूर्वक परीक्षण की आवश्यकता है

  4. बीबी ऊपरी बैंड तोड़ने झूठी ब्रेकआउट हो सकता है, सत्यापन की जरूरत है

  5. कई संकेतकों को अनुकूलित करना कठिन है, अति अनुकूलन का खतरा है

  6. ट्रेन/परीक्षण डेटा का अपर्याप्त होना वक्र को फिट करने का कारण बन सकता है

अनुकूलन दिशाएँ

  1. सर्वोत्तम पैरामीटर संयोजन खोजने के लिए अधिक अवधि का परीक्षण करें

  2. आरएसआई के साथ बदलने या संयोजन करने के लिए एमएसीडी, केडी जैसे अन्य संकेतकों का प्रयास करें

  3. पैरामीटर अनुकूलन के लिए आगे बढ़ विश्लेषण का उपयोग करें

  4. एकल व्यापार हानि को नियंत्रित करने के लिए स्टॉप लॉस जोड़ें

  5. संकेत भविष्यवाणी में सहायता के लिए मशीन सीखने के मॉडल पर विचार करें

  6. विभिन्न बाजारों के लिए मापदंडों को समायोजित करें, एकल मापदंड सेट के लिए overfit नहीं

निष्कर्ष

यह रणनीति दोहरी चलती औसत का उपयोग करके दीर्घकालिक और अल्पकालिक रुझानों को पकड़ती है, और आरएसआई, टीएसवी, बोलिंगर बैंड और अधिक के साथ संकेतों को फ़िल्टर करती है। लाभ लंबी अवधि के ऊपरी गति के अनुरूप व्यापार कर रहा है। लेकिन इसमें झूठे संकेत जोखिम भी हैं, जिससे जोखिमों को कम करने के लिए आगे पैरामीटर ट्यूनिंग और स्टॉप लॉस की आवश्यकता होती है। कुल मिलाकर, प्रवृत्ति के बाद और औसत प्रतिगमन को जोड़ने से दीर्घकालिक अपट्रेंड में अच्छे परिणाम प्राप्त होते हैं, लेकिन मापदंडों को विभिन्न बाजारों के लिए समायोजन की आवश्यकता होती है।


/*backtest
start: 2022-10-23 00:00:00
end: 2023-10-29 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// @version=4

// Credits

// "Vwap with period" code which used in this strategy to calculate the leadLine was written by "neolao" active on https://tr.tradingview.com/u/neolao/
// "TSV" code which used in this strategy was written by "liw0" active on https://www.tradingview.com/u/liw0. The code is corrected by "vitelot" December 2018.
// "Vidya" code which used in this strategy was written by "everget" active on https://tr.tradingview.com/u/everget/

strategy("HYE Combo Market [Strategy] (Vwap Mean Reversion + Trend Hunter)", overlay = true, initial_capital = 1000, default_qty_value = 100, default_qty_type = strategy.percent_of_equity, commission_value = 0.025)
  
//Strategy inputs

source = input(title = "Source", defval = close, group = "Mean Reversion Strategy Inputs")
smallcumulativePeriod = input(title = "Small VWAP", defval = 8, group = "Mean Reversion Strategy Inputs")
bigcumulativePeriod = input(title = "Big VWAP", defval = 10, group = "Mean Reversion Strategy Inputs")
meancumulativePeriod = input(title = "Mean VWAP", defval = 50, group = "Mean Reversion Strategy Inputs")
percentBelowToBuy = input(title = "Percent below to buy %", defval = 2, group = "Mean Reversion Strategy Inputs")
rsiPeriod = input(title = "Rsi Period", defval = 2, group = "Mean Reversion Strategy Inputs")
rsiEmaPeriod = input(title = "Rsi Ema Period", defval = 5, group = "Mean Reversion Strategy Inputs") 
rsiLevelforBuy = input(title = "Maximum Rsi Level for Buy", defval = 30, group = "Mean Reversion Strategy Inputs")
slowtenkansenPeriod = input(9, minval=1, title="Slow Tenkan Sen VWAP Line Length", group = "Trend Hunter Strategy Inputs")
slowkijunsenPeriod = input(13, minval=1, title="Slow Kijun Sen VWAP Line Length", group = "Trend Hunter Strategy Inputs")
fasttenkansenPeriod = input(3, minval=1, title="Fast Tenkan Sen VWAP Line Length", group = "Trend Hunter Strategy Inputs")
fastkijunsenPeriod = input(7, minval=1, title="Fast Kijun Sen VWAP Line Length", group = "Trend Hunter Strategy Inputs")
BBlength = input(20, minval=1, title= "Bollinger Band Length", group = "Trend Hunter Strategy Inputs")
BBmult = input(2.0, minval=0.001, maxval=50, title="Bollinger Band StdDev", group = "Trend Hunter Strategy Inputs")
tsvlength  = input(20, minval=1, title="TSV Length", group = "Trend Hunter Strategy Inputs")
tsvemaperiod = input(7, minval=1, title="TSV Ema Length", group = "Trend Hunter Strategy Inputs")
length = input(title="Vidya Length", type=input.integer, defval=20, group = "Trend Hunter Strategy Inputs") 
src = input(title="Vidya Source", type=input.source, defval= hl2 , group = "Trend Hunter Strategy Inputs")

// Vidya Calculation 

getCMO(src, length) =>
    mom = change(src)
    upSum = sum(max(mom, 0), length)
    downSum = sum(-min(mom, 0), length)
    out = (upSum - downSum) / (upSum + downSum)
    out

cmo = abs(getCMO(src, length))

alpha = 2 / (length + 1)

vidya = 0.0
vidya := src * alpha * cmo + nz(vidya[1]) * (1 - alpha * cmo)

// Make input options that configure backtest date range 

startDate = input(title="Start Date", type=input.integer,
     defval=1, minval=1, maxval=31, group = "Strategy Date Range")
startMonth = input(title="Start Month", type=input.integer,
     defval=1, minval=1, maxval=12, group = "Strategy Date Range")
startYear = input(title="Start Year", type=input.integer,
     defval=2000, minval=1800, maxval=2100, group = "Strategy Date Range")

endDate = input(title="End Date", type=input.integer, 
     defval=31, minval=1, maxval=31, group = "Strategy Date Range")
endMonth = input(title="End Month", type=input.integer,
     defval=12, minval=1, maxval=12, group = "Strategy Date Range") 
endYear = input(title="End Year", type=input.integer,
     defval=2021, minval=1800, maxval=2100, group = "Strategy Date Range")
     
inDateRange = true
// Mean Reversion Strategy Calculation 

typicalPriceS = (high + low + close) / 3
typicalPriceVolumeS = typicalPriceS * volume
cumulativeTypicalPriceVolumeS = sum(typicalPriceVolumeS, smallcumulativePeriod)
cumulativeVolumeS = sum(volume, smallcumulativePeriod)
smallvwapValue = cumulativeTypicalPriceVolumeS / cumulativeVolumeS

typicalPriceB = (high + low + close) / 3
typicalPriceVolumeB = typicalPriceB * volume
cumulativeTypicalPriceVolumeB = sum(typicalPriceVolumeB, bigcumulativePeriod)
cumulativeVolumeB = sum(volume, bigcumulativePeriod)
bigvwapValue = cumulativeTypicalPriceVolumeB / cumulativeVolumeB 

typicalPriceM = (high + low + close) / 3
typicalPriceVolumeM = typicalPriceM * volume
cumulativeTypicalPriceVolumeM = sum(typicalPriceVolumeM, meancumulativePeriod)
cumulativeVolumeM = sum(volume, meancumulativePeriod)
meanvwapValue = cumulativeTypicalPriceVolumeM / cumulativeVolumeM

rsiValue = rsi(source, rsiPeriod)
rsiEMA   = ema(rsiValue, rsiEmaPeriod)
buyMA = ((100 - percentBelowToBuy) / 100) * bigvwapValue[0]

inTrade = strategy.position_size > 0
notInTrade = strategy.position_size <= 0

if(crossunder(smallvwapValue, buyMA) and rsiEMA < rsiLevelforBuy and close < meanvwapValue and inDateRange and notInTrade)
    strategy.entry("BUY-M", strategy.long)

if(close > meanvwapValue or not inDateRange)
    strategy.close("BUY-M")
    
// Trend Hunter Strategy Calculation

// Slow Tenkan Sen Calculation

typicalPriceTS = (high + low + close) / 3
typicalPriceVolumeTS = typicalPriceTS * volume
cumulativeTypicalPriceVolumeTS = sum(typicalPriceVolumeTS, slowtenkansenPeriod)
cumulativeVolumeTS = sum(volume, slowtenkansenPeriod)
slowtenkansenvwapValue = cumulativeTypicalPriceVolumeTS / cumulativeVolumeTS

// Slow Kijun Sen Calculation

typicalPriceKS = (high + low + close) / 3
typicalPriceVolumeKS = typicalPriceKS * volume
cumulativeTypicalPriceVolumeKS = sum(typicalPriceVolumeKS, slowkijunsenPeriod)
cumulativeVolumeKS = sum(volume, slowkijunsenPeriod)
slowkijunsenvwapValue = cumulativeTypicalPriceVolumeKS / cumulativeVolumeKS

// Fast Tenkan Sen Calculation

typicalPriceTF = (high + low + close) / 3
typicalPriceVolumeTF = typicalPriceTF * volume
cumulativeTypicalPriceVolumeTF = sum(typicalPriceVolumeTF, fasttenkansenPeriod)
cumulativeVolumeTF = sum(volume, fasttenkansenPeriod)
fasttenkansenvwapValue = cumulativeTypicalPriceVolumeTF / cumulativeVolumeTF

// Fast Kijun Sen Calculation

typicalPriceKF = (high + low + close) / 3
typicalPriceVolumeKF = typicalPriceKS * volume
cumulativeTypicalPriceVolumeKF = sum(typicalPriceVolumeKF, fastkijunsenPeriod)
cumulativeVolumeKF = sum(volume, fastkijunsenPeriod)
fastkijunsenvwapValue = cumulativeTypicalPriceVolumeKF / cumulativeVolumeKF

// Slow LeadLine Calculation
 
lowesttenkansen_s = lowest(slowtenkansenvwapValue, slowtenkansenPeriod)
highesttenkansen_s = highest(slowtenkansenvwapValue, slowtenkansenPeriod)

lowestkijunsen_s = lowest(slowkijunsenvwapValue, slowkijunsenPeriod)
highestkijunsen_s = highest(slowkijunsenvwapValue, slowkijunsenPeriod)

slowtenkansen = avg(lowesttenkansen_s, highesttenkansen_s)
slowkijunsen = avg(lowestkijunsen_s, highestkijunsen_s)
slowleadLine = avg(slowtenkansen, slowkijunsen)

// Fast LeadLine Calculation 
 
lowesttenkansen_f = lowest(fasttenkansenvwapValue, fasttenkansenPeriod)
highesttenkansen_f = highest(fasttenkansenvwapValue, fasttenkansenPeriod)

lowestkijunsen_f = lowest(fastkijunsenvwapValue, fastkijunsenPeriod)
highestkijunsen_f = highest(fastkijunsenvwapValue, fastkijunsenPeriod) 

fasttenkansen = avg(lowesttenkansen_f, highesttenkansen_f)
fastkijunsen = avg(lowestkijunsen_f, highestkijunsen_f)
fastleadLine = avg(fasttenkansen, fastkijunsen)

// BBleadLine Calculation
 
BBleadLine = avg(fastleadLine, slowleadLine)

// Bollinger Band Calculation
 
basis = sma(BBleadLine, BBlength)
dev = BBmult * stdev(BBleadLine, BBlength)
upper = basis + dev  
lower = basis - dev 

// TSV Calculation

tsv = sum(close>close[1]?volume*(close-close[1]):close<close[1]?volume*(close-close[1]):0,tsvlength)
tsvema = ema(tsv, tsvemaperiod)

// Rules for Entry & Exit  

if(fastleadLine > fastleadLine[1] and slowleadLine > slowleadLine[1] and tsv > 0 and tsv > tsvema and close > upper and close > vidya and inDateRange and notInTrade)
    strategy.entry("BUY-T", strategy.long)
 
if((fastleadLine < fastleadLine[1] and slowleadLine < slowleadLine[1]) or not inDateRange)
    strategy.close("BUY-T")

// Plots 

plot(meanvwapValue, title="MEAN VWAP", linewidth=2, color=color.yellow)

//plot(vidya, title="VIDYA", linewidth=2, color=color.green)

//colorsettingS = input(title="Solid Color Slow Leadline", defval=false, type=input.bool)
//plot(slowleadLine, title = "Slow LeadLine", color = colorsettingS ? color.aqua : slowleadLine > slowleadLine[1] ? color.green : color.red, linewidth=3)

//colorsettingF = input(title="Solid Color Fast Leadline", defval=false, type=input.bool)
//plot(fastleadLine, title = "Fast LeadLine", color = colorsettingF ? color.orange : fastleadLine > fastleadLine[1] ? color.green : color.red, linewidth=3)

//p1 = plot(upper, "Upper BB", color=#2962FF)
//p2 = plot(lower, "Lower BB", color=#2962FF)
//fill(p1, p2, title = "Background", color=color.blue)

//plot(smallvwapValue, color=#13C425, linewidth=2)
//plot(bigvwapValue, color=#CA1435, linewidth=2)


अधिक