
इस रणनीति का मुख्य विचार बड़े समय के फ्रेम पर प्रवृत्ति की दिशा की पहचान करना है और छोटे समय के फ्रेम पर प्रवेश के लिए ब्रेकआउट को ढूंढना है, जबकि स्टॉप-लॉस एक्जिट बड़े समय के फ्रेम पर चलती औसत को ट्रैक करता है।
इस रणनीति का मूल्यांकन मुख्य रूप से तीन मापदंडों पर आधारित है:
सबसे पहले, एक लंबी अवधि (जैसे कि दिन की रेखा) के लिए एक एक्स-दिवसीय सरल चलती औसत की गणना करें, और कीमत पर चलने के बाद ही खरीदारी की अनुमति दें। इसका उपयोग समग्र प्रवृत्ति की दिशा का पता लगाने के लिए किया जा सकता है, जिससे व्यापारिक उतार-चढ़ाव की अवधि से बचा जा सकता है।
दूसरा, एक छोटी अवधि (जैसे 5 दिन) के भीतर उच्चतम मूल्य स्विंग हाई की गणना करें, जब कीमत इस उच्चतम मूल्य को तोड़ती है तो एक खरीद संकेत ट्रिगर करती है।
तीसरा, एक स्टॉप लाइन स्थापित करना। स्थिति में प्रवेश करने के बाद, स्टॉप लाइन एक निश्चित अवधि के lbStop के न्यूनतम मूल्य पर ताला लगा देती है जो निकटतम निचले बिंदु से दूर है। साथ ही एक चलती औसत (जैसे कि 10-दिन ईएमए) को एक निकास तंत्र के रूप में सेट करना, जब कीमत उस चलती औसत से कम हो जाती है तो स्थिति से बाहर निकलना।
इस रणनीति के साथ ही एटीआर मूल्य निर्धारित किया गया है ताकि ओवरएक्स्ड बिट्स की खरीद से बचा जा सके। इसके अलावा, अन्य सहायक शर्तें जैसे कि समय सीमा को फिर से मापना।
उपरोक्त तीनों सूचकांकों का परस्पर संबंध इस रणनीति का मूल तर्क है।
यह एक ऐसी रणनीति है, जिसके कुछ फायदे हैं:
दो समय-सीमाओं का उपयोग करें ताकि आप अस्थिर बाजारों में फंसने से बच सकें। लंबी समय-सीमाएं सामान्य रुझानों का आकलन करती हैं और छोटी समय-सीमाएं विशिष्ट प्रवेश बिंदुओं की तलाश करती हैं।
स्विंग हाई के माध्यम से बनने वाले ब्रेकआउट के लिए, इस तरह के ब्रेकआउट में कुछ गतिशीलता होती है और इसे आसानी से ट्रैक किया जा सकता है।
स्टॉप लॉस का तरीका अधिक सख्त है, हाल के निचले बिंदुओं को ट्रैक करता है और एक निश्चित बफर दूरी छोड़ता है, ताकि स्टॉप को बंद न किया जा सके।
एक बाहर निकलने की विधि के रूप में एक चलती औसत का उपयोग करें।
एटीआर सूचकांक अत्यधिक उत्सर्जन से होने वाले जोखिमों से बचता है।
परीक्षण के लिए विभिन्न पैरामीटर संयोजनों को सेट किया जा सकता है, अनुकूलन के लिए अधिक जगह।
इस रणनीति में कुछ जोखिम भी हैं:
जब कीमतें चलती औसत के आसपास उतार-चढ़ाव करती हैं, तो उन्हें बार-बार स्थानांतरित किया जा सकता है। इस स्थिति में उच्च शुल्क का जोखिम होता है।
जब एक क्रॉसओवर एक चलती औसत के करीब होता है, तो एक बड़े रिट्रीट का जोखिम होता है। यह रणनीति की अपनी विशेषता है।
जब बाजार में कोई स्पष्ट प्रवृत्ति नहीं होती है, तो स्थिति को लंबे समय तक रखने से समय का जोखिम हो सकता है।
एटीआर पैरामीटर को उचित रूप से सेट करने की आवश्यकता है। एटीआर कम होने पर फ़िल्टरिंग प्रभाव कम होता है, और अधिक होने पर प्रवेश की संभावना कम हो जाती है।
परिणामों पर विभिन्न lb मापदंडों के प्रभाव का परीक्षण करना आवश्यक है। बहुत बड़े पैरामीटर कुछ अवसरों को याद कर सकते हैं, और बहुत छोटे पैरामीटर झूठी सफलताओं की पहचान कर सकते हैं।
जोखिम समाधान:
इस रणनीति को निम्नलिखित आयामों से भी अनुकूलित किया जा सकता हैः
विभिन्न चलती औसत मापदंडों के संयोजनों का परीक्षण करें और इष्टतम मापदंड खोजें।
विभिन्न एटीआर पैरामीटर सेटिंग्स का प्रयास करें और प्रवेश के अवसरों और जोखिम नियंत्रण को संतुलित करें।
अधिक कुशल ब्रेकआउट की पहचान करने के लिए lb पैरामीटर को अनुकूलित करें।
गतिशील स्टॉप बनाने की कोशिश करें, अस्थिरता और वापसी के आधार पर जोखिम को नियंत्रित करें।
ट्रेड वॉल्यूम इंडिकेटर जैसे अन्य कारकों के साथ, सफलता की प्रभावशीलता का आकलन करें।
उदाहरण के लिए, यदि आप </>, </,>< आदि को संदर्भ के रूप में उपयोग करते हैं, तो आप इस विधि का उपयोग कर सकते हैं।
मशीन सीखने के लिए पैरामीटर को प्रशिक्षित करने का प्रयास करें
समग्र रूप से, यह रणनीति एक विशिष्ट ब्रेकआउट ट्रैकिंग रणनीति है। दोहरे समय-सीमा निर्णय, स्विंग हाई ने प्रवेश समय, स्टॉप-लॉस लाइन और चलती औसत डबल बीमा से बाहर निकलने के तंत्र की पहचान की, जिससे एक पूर्ण तार्किक प्रणाली बनाई गई। इस रणनीति के जोखिम और लाभ की विशेषताएं स्पष्ट हैं, जो मध्यम और लंबी लाइन ट्रैकिंग प्रकार के निवेशकों के लिए उपयुक्त हैं। हालांकि कुछ जोखिम मौजूद हैं, जोखिम के स्तर को कम करने के लिए पैरामीटर अनुकूलन और नियम अनुकूलन के माध्यम से किया जा सकता है। इस रणनीति में सुधार के लिए बहुत जगह है, और अधिक सूचक निर्णय के साथ मिलकर रणनीति की प्रभावशीलता को और बढ़ाया जा सकता है।
/*backtest
start: 2023-01-24 00:00:00
end: 2024-01-30 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/
// © millerrh
// The intent of this strategy is to buy breakouts with a tight stop on smaller timeframes in the direction of the longer term trend.
// Then use a trailing stop of a close below either the 10 MA or 20 MA (user choice) on that larger timeframe as the position
// moves in your favor (i.e. whenever position price rises above the MA).
// Option of using daily ATR as a measure of finding contracting ranges and ensuring a decent risk/reward.
// (If the difference between the breakout point and your stop level is below a certain % of ATR, it could possibly find those consolidating periods.)
//@version=4
strategy("Qullamaggie Breakout", overlay=true, initial_capital=10000, currency='USD',
default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1)
// === BACKTEST RANGE ===
Start = input(defval = timestamp("01 Jan 2019 06:00 +0000"), title = "Backtest Start Date", type = input.time)
Finish = input(defval = timestamp("01 Jan 2100 00:00 +0000"), title = "Backtest End Date", type = input.time)
// Inputs
lb = input(defval = 3, title = "Lookback Period for Swing High", minval = 1,
tooltip = "Lookback period for defining the breakout level.")
lbStop = input(defval = 3, title = "Lookback Bars for Stop Level", minval = 1,
tooltip = "Initial stop placement is the lowest low this many bars back. Allows for tighter stop placement than referencing swing lows.")
htf = input(defval="D", title="Timeframe of Moving Averages", type=input.resolution,
tooltip = "Allows you to set a different time frame for the moving averages. The default behavior is to identify good tightening setups on a larger timeframe
(like daily) and enter the trade on a breakout occuring on a smaller timeframe, using the moving averages of the larger timeframe to trail your stop.")
maType = input(defval="SMA", options=["EMA", "SMA"], title = "Moving Average Type")
ma1Length = input(defval = 10, title = "1st Moving Average Length", minval = 1)
ma2Length = input(defval = 20, title = "2nd Moving Average Length", minval = 1)
ma3Length = input(defval = 50, title = "3rd Moving Average Length", minval = 1)
useMaFilter = input(title = "Use 3rd Moving Average for Filtering?", type = input.bool, defval = true,
tooltip = "Signals will be ignored when price is under this slowest moving average. The intent is to keep you out of bear periods and only
buying when price is showing strength or trading with the longer term trend.")
trailMaInput = input(defval="2nd Moving Average", options=["1st Moving Average", "2nd Moving Average"], title = "Trailing Stop")
// MA Calculations
ma(maType, src, length) =>
maType == "EMA" ? ema(src, length) : sma(src, length) //Ternary Operator (if maType equals EMA, then do ema calc, else do sma calc)
ma1 = security(syminfo.tickerid, htf, ma(maType, close, ma1Length))
ma2 = security(syminfo.tickerid, htf, ma(maType, close, ma2Length))
ma3 = security(syminfo.tickerid, htf, ma(maType, close, ma3Length))
plot(ma1, color=color.purple, style=plot.style_line, title="MA1", linewidth=2, transp = 60)
plot(ma2, color=color.yellow, style=plot.style_line, title="MA2", linewidth=2, transp = 60)
plot(ma3, color=color.white, style=plot.style_line, title="MA3", linewidth=2, transp = 60)
// === USE ATR FOR FILTERING ===
// The idea here is that you want to buy in a consolodating range for best risk/reward. So here you can compare the current distance between
// support/resistance vs.the ATR and make sure you aren't buying at a point that is too extended from normal.
useAtrFilter = input(title = "Use ATR for Filtering?", type = input.bool, defval = false,
tooltip = "Signals will be ignored if the distance between support and resistance is larger than a user-defined percentage of Daily ATR.
This allows the user to ensure they are not buying something that is too extended and instead focus on names that are consolidating more.")
atrPerc = input(defval = 100, title = "% of Daily ATR Value", minval = 1)
atrValue = security(syminfo.tickerid, "D", atr(14))*atrPerc*.01
// === PLOT SWING HIGH/LOW AND MOST RECENT LOW TO USE AS STOP LOSS EXIT POINT ===
// Change these values to adjust the look back and look forward periods for your swing high/low calculations
pvtLenL = lb
pvtLenR = lb
// Get High and Low Pivot Points
pvthi_ = pivothigh(high, pvtLenL, pvtLenR)
pvtlo_ = pivotlow(low, pvtLenL, pvtLenR)
// Force Pivot completion before plotting.
Shunt = 1 //Wait for close before printing pivot? 1 for true 0 for flase
maxLvlLen = 0 //Maximum Extension Length
pvthi = pvthi_[Shunt]
pvtlo = pvtlo_[Shunt]
// Count How many candles for current Pivot Level, If new reset.
counthi = barssince(not na(pvthi))
countlo = barssince(not na(pvtlo))
pvthis = fixnan(pvthi)
pvtlos = fixnan(pvtlo)
hipc = change(pvthis) != 0 ? na : color.maroon
lopc = change(pvtlos) != 0 ? na : color.green
// Display Pivot lines
plot((maxLvlLen == 0 or counthi < maxLvlLen) ? pvthis : na, color=hipc, transp=0, linewidth=1, offset=-pvtLenR-Shunt, title="Top Levels")
// plot((maxLvlLen == 0 or countlo < maxLvlLen) ? pvtlos : na, color=lopc, transp=0, linewidth=1, offset=-pvtLenR-Shunt, title="Bottom Levels")
plot((maxLvlLen == 0 or counthi < maxLvlLen) ? pvthis : na, color=hipc, transp=0, linewidth=1, offset=0, title="Top Levels 2")
// plot((maxLvlLen == 0 or countlo < maxLvlLen) ? pvtlos : na, color=lopc, transp=0, linewidth=1, offset=0, title="Bottom Levels 2")
// BUY CONDITIONS
stopLevelCalc = valuewhen(pvtlo_, low[pvtLenR], 0) //Stop Level at Swing Low
buyLevel = valuewhen(pvthi_, high[pvtLenR], 0) //Buy level at Swing High
plot(buyLevel, style=plot.style_line, color=color.blue, title = "Current Breakout Level", show_last=1, linewidth=1, transp=50, trackprice=true)
// Conditions for entry and exit
stopLevel = float(na) // Define stop level here as "na" so that I can reference it in the inPosition
// variable and the ATR calculation before the stopLevel is actually defined.
buyConditions = (useMaFilter ? buyLevel > ma3 : true) and
(useAtrFilter ? (buyLevel - stopLevel[1]) < atrValue : true)
// buySignal = high > buyLevel and buyConditions
buySignal = crossover(high, buyLevel) and buyConditions
trailMa = trailMaInput == "1st Moving Average" ? ma1 : ma2
sellSignal = crossunder(close, trailMa)
// sellSignal = security(syminfo.tickerid, htf, close < trailMa) and security(syminfo.tickerid, htf, close[1] < trailMa)
// STOP AND PRICE LEVELS
inPosition = bool(na)
inPosition := buySignal[1] ? true : sellSignal[1] ? false : low <= stopLevel[1] ? false : inPosition[1]
lowDefine = lowest(low, lbStop)
stopLevel := inPosition ? stopLevel[1] : lowDefine
// plot(stopLevel)
buyPrice = buyLevel
buyPrice := inPosition ? buyPrice[1] : buyLevel
plot(stopLevel, style=plot.style_line, color=color.orange, title = "Current Stop Level", show_last=1, linewidth=1, transp=50, trackprice=true)
plot(inPosition ? stopLevel : na, style=plot.style_circles, color=color.orange, title = "Historical Stop Levels", transp=50, trackprice=false)
// plot(buyPrice, style=plot.style_line, color=color.blue, linewidth=1, transp=50, trackprice=true)
// (STRATEGY ONLY) Comment out for Study
strategy.entry("Long", strategy.long, stop = buyLevel, when = buyConditions)
strategy.exit("Exit Long", from_entry = "Long", stop=stopLevel[1])
if (low[1] > trailMa)
strategy.close("Long", when = sellSignal)
// if (low[1] > trailMa)
// strategy.exit("Exit Long", from_entry = "Long", stop=trailMa) //to get this to work right, I need to reference highest highs instead of swing highs
//because it can have me buy right back in after selling if the stop level is above the last registered swing high point.