
নিদ্রা পরিসীমা বিপরীত কৌশলটি পজিশন তৈরির সংকেত হিসাবে দামের ওঠানামা হ্রাসের সময়কে ব্যবহার করে এবং যখন দামের ওঠানামা আবার বেড়ে যায় তখন লাভজনক পজিশন গ্রহণ করে। দামগুলি সংকীর্ণ ওঠানামার নিদ্রা পরিসরের মধ্যে সীমাবদ্ধ থাকলে তা সনাক্ত করে এটি আসন্ন বিস্ফোরণে মূল্যের প্রবণতাকে ক্যাপচার করে। এই কৌশলটি সাধারণত বর্তমানের ওঠানামা কম স্তরে থাকে তবে ভবিষ্যতে বিস্ফোরণ ঘটতে পারে।
এই কৌশলটি প্রথমে একটি নিদ্রা পরিসীমা চিহ্নিত করে, যেখানে দামগুলি পূর্বের ট্রেডিং দিনের দামের পরিসরের মধ্যে সীমাবদ্ধ থাকে। এটি নির্দেশ করে যে বর্তমান অস্থিরতা আগের দিনগুলির তুলনায় কিছুটা কমে গেছে। আমরা বর্তমান ট্রেডিং দিনের সর্বোচ্চ মূল্যের সাথে n দিন আগে (সাধারণত 4 দিন) সর্বোচ্চ মূল্যের তুলনা করে এবং বর্তমান ট্রেডিং দিনের সর্বনিম্ন মূল্যের সাথে n দিন আগে সর্বনিম্ন মূল্যের তুলনা করে নিদ্রা পরিসরের সাথে সামঞ্জস্যপূর্ণ কিনা তা বিচার করি।
একবার নিস্তব্ধ পরিসীমা নিশ্চিত হয়ে গেলে, কৌশলটি একই সাথে দুটি হ্যান্ডলগুলি খুলবেঃ একটি ক্রয় হ্যান্ডলটি পরিসীমা উচ্চতার কাছাকাছি এবং একটি বিক্রয় হ্যান্ডলটি পরিসীমা নিম্নের কাছাকাছি। তারপরে দামটি নিস্তব্ধ পরিসীমাটি ভেঙে যাওয়ার জন্য অপেক্ষা করুন। যদি দামটি উপরে উঠে যায় তবে ক্রয়টি একাধিক শীর্ষ অবস্থান তৈরি করতে ট্রিগার করা হবে; যদি এটি নীচে ভেঙে যায় তবে বিক্রয়টি শূন্য অবস্থান তৈরি করতে ট্রিগার করা হবে।
পজিশন স্থাপনের পরে, কৌশলটি স্টপ লস ওয়ারেন্ট এবং স্টপ কার্ড সেট করে। স্টপ লস ওয়ারেন্টটি নেমে যাওয়ার ঝুঁকিকে সীমাবদ্ধ করে, স্টপ কার্ডটি লাভের পরে পজিশনটি প্লেইন করার জন্য ব্যবহৃত হয়। স্টপ লস ওয়ারেন্টটি প্রবেশের দাম থেকে এক অনুপাতের দূরত্ব, এই অনুপাতটি ঝুঁকি পরিচালনার প্যারামিটার দ্বারা সেট করা হয়েছে; স্টপ কার্ডটি প্রবেশের দাম থেকে একটি নিদ্রা অঞ্চল হিসাবে বড়, কারণ আমরা প্রত্যাশা করি যে দামের চলাচলের পরিমাণ পূর্বের ওঠানামা হবে।
অবশেষে, এই কৌশলটিতে একটি তহবিল পরিচালনার মডিউলও রয়েছে। ফিক্সড মাল্টিপ্লেক্স পদ্ধতির মাধ্যমে অর্ডার ট্রেডিং তহবিলের পরিমাণ সামঞ্জস্য করুন, লাভজনক হলে তহবিলের ব্যবহার বাড়ান এবং ক্ষতিগ্রস্থ হলে ঝুঁকি হ্রাস করুন।
এই কৌশলটির কিছু সুবিধা রয়েছেঃ
দামের প্রবণতা শুরু হওয়ার আগেই পজিশন তৈরির সংকেত হিসেবে কম ওঠানামা সময়কে কাজে লাগান।
একই সময়ে, একটি মাল্টি-ফ্রি ডাবল-ডাইরেক্ট ট্রেডিং অর্ডার সেট করুন, যা একটি উত্থান বা পতনের প্রবণতা ক্যাপচার করতে পারে।
স্টপ লস স্টপ কৌশল ব্যবহার করে, একক লেনদেনের ঝুঁকি কার্যকরভাবে নিয়ন্ত্রণ করা যায়।
ফিক্সড মাল্টিপ্লাইড ফান্ড ম্যানেজমেন্ট পদ্ধতি ব্যবহার করে তহবিলের ব্যবহারের দক্ষতা বাড়ানো যায়।
কৌশলগত ধারণাগুলি সহজ, পরিষ্কার এবং বাস্তবায়নের জন্য সহজ।
এই কৌশলটির কিছু ঝুঁকি রয়েছে যা সম্পর্কে সতর্ক থাকা দরকারঃ
ঘুমন্ত পরিসরের ভাঙ্গার দিকটি ভুলভাবে বিচার করার ঝুঁকি। দামের উপরে বা নীচে কোনও বিচ্ছিন্নতা দেখা যায় না, যার ফলে প্রবেশের দিকটি ভুল হয়।
বিপর্যয়ের পরে, এটি কেবলমাত্র একটি স্বল্পমেয়াদী বিপর্যয়।
স্টপ লোন অতিক্রম করার ঝুঁকি। বিশেষ পরিস্থিতিতে স্টপ লোন অতিক্রম করা যেতে পারে।
স্থির গুণিতক পদ্ধতিতে হারের ঝুঁকি বাড়ানোর ঝুঁকি। ঝুঁকি কমাতে স্থির গুণিতকের মান হ্রাস করা যেতে পারে।
ভুল প্যারামিটার সেট করার ফলে কৌশলটি কার্যকর হতে পারে না।
এই কৌশলটি নিম্নলিখিত দিকগুলি থেকেও উন্নত করা যেতে পারেঃ
ত্রুটিপূর্ণ ব্রেকিং এড়ানোর জন্য ব্রেকিং বিপর্যয়ের জন্য একটি ফিল্টারিং সংকেত যোগ করুন।
ক্ষতি বন্ধ করার কৌশল উন্নত করুন, যেমন- মুভিং স্টপ, ওয়ান স্টপ ইত্যাদি।
ট্রেন্ডের মূল্যায়ন করার জন্য একটি সূচক তৈরি করুন, যাতে আপনি ট্রেন্ডের বিপরীত দিকে যেতে না পারেন।
ফিক্সড গুণিতক মান অপ্টিমাইজ করুন, লাভ-ক্ষতি অনুপাতের ভারসাম্য বজায় রাখুন
একাধিক সময়কাল বিশ্লেষণের সাথে মিলিত হয়ে, লাভের সম্ভাবনা বাড়িয়ে তোলা।
মেশিন লার্নিং পদ্ধতি ব্যবহার করে প্যারামিটারগুলি স্বয়ংক্রিয়ভাবে অপ্টিমাইজ করুন।
নিস্তব্ধ পরিসীমা বিপরীতকরণ কৌশলটির সামগ্রিক চিন্তাভাবনা পরিষ্কার এবং এর কিছু লাভের সম্ভাবনা রয়েছে। প্যারামিটার অপ্টিমাইজেশন, ঝুঁকি ব্যবস্থাপনা, সংকেত ফিল্টারিং ইত্যাদির মাধ্যমে কৌশলটির স্থায়িত্ব আরও বাড়ানো যেতে পারে। তবে যে কোনও প্রবণতা বিপরীতকরণ কৌশলটির কিছু ঝুঁকি রয়েছে, এটি সাবধানতার সাথে ব্যবহার করা উচিত এবং যথাযথভাবে পজিশন স্কেলটি সামঞ্জস্য করা উচিত। এই কৌশলটি বিপরীতকরণের সাথে পরিচিত এবং ঝুঁকি সচেতন ব্যবসায়ীদের জন্য উপযুক্ত।
/*backtest
start: 2023-09-29 00:00:00
end: 2023-10-29 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/
// © gsanson66
//This code is based on the Narrow Range strategy
//Interactive Broker fees are applied on this strategy
//@version=5
strategy("NARROW RANGE BACKTESTING", shorttitle="NR BACKTESTING", overlay=true, initial_capital=1000, default_qty_type=strategy.fixed, commission_type=strategy.commission.percent, commission_value=0.18)
//--------------------------------FUNCTIONS------------------------------------//
//@function to print label
debugLabel(txt, color) =>
label.new(bar_index, high, text = txt, color=color, style = label.style_label_lower_right, textcolor = color.black, size = size.small)
//@function which looks if the close date of the current bar falls inside the date range
inBacktestPeriod(start, end) => (time >= start) and (time <= end)
//--------------------------------USER INPUTS------------------------------------//
//Narrow Range Length
nrLength = input.int(4, minval=2, title="Narrow Range Length", group="Strategy parameters")
//Risk Management
stopLossInput = input.float(0.5, title="Stop Loss (in percentage of reference range)", group="Strategy parameters")
//Money Management
fixedRatio = input.int(defval=400, minval=1, title="Fixed Ratio Value ($)", group="Money Management")
increasingOrderAmount = input.int(defval=200, minval=1, title="Increasing Order Amount ($)", group="Money Management")
//Backtesting period
startDate = input(title="Start Date", defval=timestamp("1 Janv 2020 00:00:00"), group="Backtesting Period")
endDate = input(title="End Date", defval=timestamp("1 July 2024 00:00:00"), group="Backtesting Period")
//--------------------------------VARIABLES INITIALISATION--------------------------//
strategy.initial_capital = 50000
bool nr = na
var bool long = na
var bool short = na
var float stopPriceLong = na
var float stopLossLong = na
var float takeProfitLong = na
var float stopPriceShort = na
var float stopLossShort = na
var float takeProfitShort = na
var float takeProfit = na
var float stopLoss = na
bool inRange = na
int closedtrades = strategy.closedtrades
equity = math.abs(strategy.equity - strategy.openprofit)
var float capital_ref = strategy.initial_capital
var float cashOrder = strategy.initial_capital * 0.95
//------------------------------CHECKING SOME CONDITIONS ON EACH SCRIPT EXECUTION-------------------------------//
//Checking if the date belong to the range
inRange := true
//Checking performances of the strategy
if equity > capital_ref + fixedRatio
spread = (equity - capital_ref)/fixedRatio
nb_level = int(spread)
increasingOrder = nb_level * increasingOrderAmount
cashOrder := cashOrder + increasingOrder
capital_ref := capital_ref + nb_level*fixedRatio
if equity < capital_ref - fixedRatio
spread = (capital_ref - equity)/fixedRatio
nb_level = int(spread)
decreasingOrder = nb_level * increasingOrderAmount
cashOrder := cashOrder - decreasingOrder
capital_ref := capital_ref - nb_level*fixedRatio
//We check if a trade has been closed to cancel all previous orders
if closedtrades > closedtrades[1]
strategy.cancel("Long")
strategy.cancel("Short")
stopPriceLong := na
stopPriceShort := na
//Checking if we close all trades in case where we exit the backtesting period
if strategy.position_size!=0 and not inRange
debugLabel("END OF BACKTESTING PERIOD : we close the trade", color=color.rgb(116, 116, 116))
strategy.close_all()
long := na
short := na
stopPriceLong := na
stopLossLong := na
takeProfitLong := na
stopPriceShort := na
stopLossShort := na
takeProfitShort := na
takeProfit := na
stopLoss := na
//----------------------------------FINDING NARROW RANGE DAY------------------------------------------//
// We find the Narrow Range Day
if low > low[nrLength] and high < high[nrLength]
nr := true
//------------------------------------STOP ORDERS--------------------------------------------//
// We handle plotting of stop orders and cancellation of other side order if one order is triggered
if strategy.position_size > 0 and not na(stopPriceLong) and not na(stopPriceShort)
long := true
strategy.cancel("Short")
stopPriceLong := na
stopPriceShort := na
takeProfit := takeProfitLong
stopLoss := stopLossLong
if strategy.position_size < 0 and not na(stopPriceLong) and not na(stopPriceShort)
short := true
strategy.cancel("Long")
stopPriceLong := na
stopPriceShort := na
takeProfit := takeProfitShort
stopLoss := stopLossShort
//------------------------------------STOP LOSS & TAKE PROFIT--------------------------------//
// If an order is triggered we plot TP and SL
if not na(takeProfit) and not na(stopLoss) and long
if high >= takeProfit and closedtrades == closedtrades[1] + 1
takeProfit := na
stopLoss := na
long := na
if low <= stopLoss and closedtrades == closedtrades[1] + 1
takeProfit := na
stopLoss := na
long := na
if not na(takeProfit) and not na(stopLoss) and short
if high >= stopLoss and closedtrades == closedtrades[1] + 1
takeProfit := na
stopLoss := na
short := na
if low <= takeProfit and closedtrades == closedtrades[1] + 1
takeProfit := na
stopLoss := na
short := na
//-----------------------------LONG/SHORT CONDITION-------------------------//
// Conditions to create two stop orders (one for Long and one for Short) and SL & TP calculation
if nr and inRange and strategy.position_size == 0
stopPriceLong := high[4]
takeProfitLong := high[4] + (high[4] - low[4])
stopLossLong := high[4] - (high[4] - low[4])*stopLossInput
qtyLong = cashOrder/stopPriceLong
strategy.entry("Long", strategy.long, qtyLong, stop=stopPriceLong)
strategy.exit("Exit Long", "Long", limit=takeProfitLong ,stop=stopLossLong)
stopPriceShort := low[4]
takeProfitShort := low[4] - (high[4] - low[4])
stopLossShort := low[4] + (high[4] - low[4])*stopLossInput
qtyShort = cashOrder/stopPriceShort
strategy.entry("Short", strategy.short, qtyShort, stop=stopPriceShort)
strategy.exit("Exit Short", "Short", limit=takeProfitShort ,stop=stopLossShort)
//--------------------------PLOTTING ELEMENT----------------------------//
plotshape(nr, "NR", shape.arrowdown, location.abovebar, color.rgb(255, 132, 0), text= "NR4", size=size.huge)
plot(stopPriceLong, "Stop Order", color.blue, 3, plot.style_linebr)
plot(stopPriceShort, "Stop Order", color.blue, 3, plot.style_linebr)
plot(takeProfit, "Take Profit", color.green, 3, plot.style_linebr)
plot(stopLoss, "Stop Loss", color.red, 3, plot.style_linebr)