নিষ্ক্রিয় পরিসীমা বিপরীত কৌশল

লেখক:চাওঝাং, তারিখ: ২০২৩-১০-৩০ ১০ঃ৫৪
ট্যাগঃ

img

সারসংক্ষেপ

নিষ্ক্রিয় পরিসীমা বিপরীত কৌশলটি প্রবেশ সংকেত হিসাবে হ্রাসযোগ্যতা সময়কাল ব্যবহার করে এবং যখন অস্থিরতা আবার শুরু হয় তখন মুনাফা অর্জনের লক্ষ্য রাখে। এটি এমন পরিস্থিতি সনাক্ত করে যেখানে দামটি একটি সংকীর্ণ নিষ্ক্রিয় পরিসরের মধ্যে রয়েছে এবং আসন্ন মূল্য প্রবণতা ক্যাপচার করে। এই কৌশলটি ভাল কাজ করে যখন বর্তমান অস্থিরতা কম তবে একটি ব্রেকআউট প্রত্যাশিত।

কৌশলগত যুক্তি

কৌশলটি প্রথমে একটি নিষ্ক্রিয় পরিসীমা চিহ্নিত করে, যা যখন মূল্য পূর্ববর্তী ট্রেডিং দিনের মূল্য পরিসরের মধ্যে থাকে। এটি নির্দেশ করে যে কয়েক দিন আগে তুলনায় অস্থিরতা হ্রাস পেয়েছে। আমরা বর্তমান দিনের উচ্চ < n দিন আগে উচ্চ (সাধারণত 4 দিন আগে) এবং বর্তমান দিনের নিম্ন > n দিন আগে কম যোগ্যতা অর্জনের জন্য পরীক্ষা করি।

একটি নিষ্ক্রিয় পরিসীমা সনাক্ত করার পরে, কৌশলটি দুটি অপেক্ষমান অর্ডার রাখে - একটি ক্রয় স্টপ পরিসীমার শীর্ষে এবং একটি বিক্রয় স্টপ পরিসীমার নীচে। এটি তারপরে দামের উপরে বা নীচে ব্যাপ্তিটি ভেঙে যাওয়ার জন্য অপেক্ষা করে। যদি দামটি উপরে ভাঙ্গতে থাকে তবে ক্রয় অর্ডারটি দীর্ঘ যেতে ট্রিগার করা হয়। যদি দাম নীচে ভাঙ্গতে থাকে তবে বিক্রয় অর্ডারটি শর্ট যেতে ট্রিগার করা হয়।

প্রবেশের পরে, স্টপ লস এবং লাভ অর্ডার স্থাপন করা হয়। স্টপ লস ডাউনসাইড ঝুঁকি নিয়ন্ত্রণ করে এবং লাভ লাভের জন্য বাণিজ্য বন্ধ করে দেয়। ঝুঁকি পরামিতিতে সংজ্ঞায়িত হিসাবে প্রবেশের দাম থেকে % দূরত্বে স্টপ লস স্থাপন করা হয়। লাভ গ্রহণটি সক্রিয় পরিসরের আকারের সমান দূরত্বে স্থাপন করা হয় কারণ আমরা আশা করি যে দাম পূর্ববর্তী অস্থিরতার অনুরূপ চলবে।

অবশেষে, একটি স্থির ভগ্নাংশ পজিশন সাইজিং মডেল বাণিজ্যের আকার পরিচালনা করে। এটি ঝুঁকি-সমন্বিত রিটার্ন উন্নত করার জন্য লাভের আকার বৃদ্ধি করে এবং ক্ষতির আকার হ্রাস করে।

সুবিধা

এই কৌশলটির সুবিধাগুলো হল:

  1. সূচক হিসেবে হ্রাসপ্রাপ্ত অস্থিরতা ব্যবহার করে আসন্ন প্রবণতা ধরা হয়।

  2. ডুয়াল-ডাইরেকশন অর্ডারগুলি আপট্রেন্ড বা ডাউনট্রেন্ডকে ধরতে পারে।

  3. স্টপ লস এবং লাভ নিয়ন্ত্রণ করে একক বাণিজ্য ঝুঁকি।

  4. স্থির ভগ্নাংশের আকার মূলধন দক্ষতা উন্নত করে।

  5. সহজ যুক্তি বাস্তবায়ন করা সহজ।

ঝুঁকি

যেসব ঝুঁকি বিবেচনা করা উচিতঃ

  1. যদি ব্যাপ্তি অস্পষ্ট হয় তাহলে ভুল দিকনির্দেশ।

  2. ব্রেকআউট হতে পারে কেবল একটি স্বল্প সময়ের বিপরীতমুখী, স্থায়ী প্রবণতা নয়।

  3. স্টপ লস হুমকির মধ্যে রয়েছে।

  4. ফিক্সড ফ্রেকশন সাইজিং হারাতে হারাতে হারাতে হারাতে হারাতে হারাতে হারাতে পারে।

  5. প্যারামিটার সঠিকভাবে সেট না হলে খারাপ পারফরম্যান্স।

উন্নতির সুযোগ

কৌশল উন্নত করার কিছু উপায়:

  1. ভুয়া ব্রেকআউট এড়ানোর জন্য ডিভার্জেন্সের মতো ফিল্টার যুক্ত করুন।

  2. স্টপ লস বা অর্ডার স্টপ লসের সাথে স্টপ লস উন্নত করুন।

  3. বিপরীত প্রবণতা এন্ট্রি এড়াতে প্রবণতা ফিল্টার যোগ করুন।

  4. সুষম ঝুঁকি/উপার্জনের জন্য স্থির ভগ্নাংশের অনুপাত অনুকূল করা।

  5. এজ উন্নত করার জন্য একাধিক সময়সীমার দিকে তাকান।

  6. স্বয়ংক্রিয় প্যারামিটার অপ্টিমাইজেশনের জন্য মেশিন লার্নিং ব্যবহার করুন।

সিদ্ধান্ত

নিষ্ক্রিয় ব্যাপ্তি বিপরীত কৌশল একটি স্পষ্ট যুক্তি এবং মুনাফা সম্ভাবনা আছে। অপ্টিমাইজেশান, ঝুঁকি ব্যবস্থাপনা এবং সংকেত ফিল্টারিং মাধ্যমে সূক্ষ্ম সুরক্ষা আরও ধারাবাহিকতা উন্নত করতে পারেন। কিন্তু সব গড় বিপরীত কৌশল অন্তর্নিহিত ঝুঁকি বহন এবং অবস্থান আকার নিয়ন্ত্রণ করা প্রয়োজন। এটি বিপরীত কৌশল সঙ্গে পরিচিত এবং একটি শব্দ ঝুঁকি সচেতনতা মালিক ট্রেডারদের উপযুক্ত।


/*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)

আরো