ট্রেন্ড ফিল্টার ভিত্তিক দ্রুত QQE ক্রসওভার ট্রেডিং কৌশল

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

img

সারসংক্ষেপ

প্রবণতা ফিল্টার উপর ভিত্তি করে দ্রুত QQE ক্রসওভার ট্রেডিং কৌশল একটি প্রবণতা অনুসরণকারী ট্রেডিং কৌশল যা প্রবণতা দিক ফিল্টারিংয়ের জন্য চলমান গড়ের সাথে দ্রুত QQE ক্রস ব্যবহার করে। QQE বা গুণগত পরিমাণগত অনুমান আপেক্ষিক শক্তি সূচকের উপর ভিত্তি করে, তবে অতিরিক্ত রূপান্তর হিসাবে একটি মসৃণকরণ কৌশল ব্যবহার করে। তিনটি ক্রস নির্বাচন করা যেতে পারে (সমস্ত ডিফল্টরূপে নির্বাচন করা হয়):

  • RSI সিগন্যাল ক্রসিং শূন্য (XZERO)
  • RSI সংকেত দ্রুত RSIatr লাইন (XQQE) অতিক্রম করে
  • RSI থ্রেশহোল্ড চ্যানেল থেকে বেরিয়ে আসা RSI সংকেত (BUY/SELL)

(BUY/SELL) সতর্কতাসমূহকে চলমান গড়ের মাধ্যমে ফিল্টার করা যেতে পারেঃ

  • ক্রয় সতর্কতার জন্য, বন্ধটি দ্রুত ম্যাক এবং দ্রুত ম্যাক (EMA8) > মাঝারি ম্যাক (EMA20) > ধীর ম্যাক (SMA50) এর উপরে থাকতে হবে।
  • বিক্রয় সতর্কতার জন্য, বন্ধটি দ্রুত এমএ এবং দ্রুত এমএ (ইএমএ 8) < মাঝারি এমএ (ইএমএ 20) < ধীর এমএ (এসএমএ 50) এর নীচে থাকতে হবে।

এবং/অথবা দিকনির্দেশক ফিল্টারঃ

  • ক্রয় সতর্কতার জন্য, বন্ধটি ধীর MA (SMA50) এর উপরে এবং দিকনির্দেশক MA (EMA20) সবুজ হতে হবে।
  • বিক্রয় সতর্কতার জন্য, বন্ধটি ধীর MA (SMA50) এর নীচে এবং দিকনির্দেশক MA (EMA20) লাল হতে হবে।

XZERO এবং XQQE ফিল্টারিংয়ে অন্তর্ভুক্ত নয়, তারা অপেক্ষমান BUY/SELL সতর্কতা, বিশেষ করে XZERO নির্দেশ করতে ব্যবহৃত হয়।

এই কৌশলটি যেকোনো মুদ্রা জোড়া এবং বেশিরভাগ চার্ট টাইমফ্রেমে কাজ করবে।

কৌশল নীতি

এই কৌশলটির মূল ধারণা হল দ্রুত QQE সূচকের দিকনির্দেশক ক্রসওভারকে ট্রেডিং সিগন্যাল হিসাবে ব্যবহার করা এবং প্রবণতা দিক ধরার জন্য চলমান গড়ের সংমিশ্রণের মাধ্যমে গোলমালযুক্ত ট্রেডিং সিগন্যালগুলি ফিল্টার করা।

বিশেষ করে, কৌশলটি নিম্নলিখিত সূচক এবং সংকেত ব্যবহার করেঃ

দ্রুত QQE সূচক: এটি আরও সংবেদনশীল এবং দ্রুত করার জন্য অতিরিক্ত মসৃণীকরণের সাথে একটি আরএসআই ভিত্তিক সূচক। সূচকটিতে তিনটি লাইন রয়েছেঃ মাঝারি লাইনটি আরএসআইয়ের এক্সপোনেনশিয়াল চলমান গড়, উপরের লাইনটি মাঝারি লাইন + দ্রুত এটিআর * একটি ফ্যাক্টর এবং নিম্ন লাইনটি মধ্য লাইন - দ্রুত এটিআর * একটি ফ্যাক্টর। যখন আরএসআই উপরের লাইনের উপরে যায়, এটি একটি বিক্রয় সংকেত। যখন আরএসআই নিম্ন লাইনের নীচে যায়, এটি একটি ক্রয় সংকেত।

শূন্য রেখা ক্রসওভার: এটি যখন আরএসআই এর মাঝারি রেখা শূন্য রেখা অতিক্রম করে তখন সংকেত উৎপন্ন করে। উপরে ক্রসওভার ক্রয় সংকেত এবং নীচে ক্রসওভার বিক্রয় সংকেত। এই সংকেতগুলি প্রবণতা পরিবর্তনের প্রারম্ভকে নির্দেশ করে।

চ্যানেল ব্রেকআউট: এটি সিগন্যাল উৎপন্ন করে যখন আরএসআই এর মাঝারি রেখা সেট থ্রেশহোল্ড চ্যানেলে প্রবেশ করে। উপরের চ্যানেলটি ভাঙ্গার অর্থ বিক্রয় সংকেত এবং নিম্ন চ্যানেলটি ভাঙ্গার অর্থ ক্রয় সংকেত। এগুলি শক্তিশালী প্রবণতা সংকেত।

চলমান গড়ের সমন্বয়: দ্রুত (8 পিরিয়ড), মাঝারি (20 পিরিয়ড) এবং ধীর (50 পিরিয়ড) চলমান গড়ের সংমিশ্রণ ব্যবহার করুন। যখন তিনটি লাইন যেমন সাজানো হয়ঃ দ্রুত > মাঝারি > ধীর, এটি একটি আপগ্রেড প্রবণতা। যখন দ্রুত < মাঝারি < ধীর হিসাবে সাজানো হয়, এটি একটি ডাউনগ্রেড প্রবণতা। কম্পোটি সামগ্রিক প্রবণতা দিক নির্ধারণ করতে ব্যবহৃত হয়।

প্রবণতা দিকনির্দেশ ফিল্টার: একটি ক্রয় সংকেত কেবল তখনই উত্পন্ন হয় যখন বন্ধের দাম ধীর চলমান গড়ের উপরে থাকে এবং মাঝারি চলমান গড় (20 পিরিয়ড) ঊর্ধ্বমুখী হয় (অবধি সর্বোচ্চ মূল্য > সর্বনিম্ন মূল্য) । একটি বিক্রয় সংকেত কেবল তখনই উত্পন্ন হয় যখন বন্ধের দাম ধীর চলমান গড়ের নীচে থাকে এবং মাঝারি চলমান গড় (20 পিরিয়ড) নেমে যায়। এটি কিছু বিপরীত মিথ্যা সংকেত ফিল্টার করতে পারে।

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

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

কৌশলটির সুবিধা

  • দ্রুত এবং সংবেদনশীল QQE সূচক ব্যবহার করে দ্রুত বিপরীত সংকেত ধরা
  • বড় চক্রের দিকনির্দেশনা নির্ধারণ এবং প্রবণতা বিরুদ্ধে ট্রেডিং এড়ানোর জন্য একাধিক চলমান গড় প্রয়োগ করে
  • একাধিক ক্রস সিগন্যাল অন্তর্ভুক্ত করে যা লাভের সুযোগ বাড়ানোর জন্য একত্রে ব্যবহার করা যেতে পারে
  • সামঞ্জস্যযোগ্য পরামিতি যা বিভিন্ন পণ্য এবং সময়সীমার জন্য অপ্টিমাইজ করা যেতে পারে
  • প্যারামিটার নির্ভরতা এড়াতে পৃথক চ্যানেল অঙ্কন করার পরিবর্তে সূচক এর নিজস্ব চ্যানেল ব্রেকআউট সংকেত ব্যবহার করে
  • বড় প্রবণতা চক্রের অধীনে খুব ভালভাবে স্বল্পমেয়াদী বিপরীতমুখী আন্দোলন ক্যাপচার করতে পারে
  • সহজ এবং পরিষ্কার ধারণা, সহজেই বোঝা এবং বাস্তবায়ন

কৌশলটির ঝুঁকি

এই কৌশলটির সাথে কিছু সম্ভাব্য ঝুঁকিও রয়েছেঃ

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

প্রতিরোধ ব্যবস্থা এবং সমাধানগুলির মধ্যে রয়েছেঃ

  • চলমান গড় পরামিতিগুলি সামঞ্জস্য করুন, প্রবণতা নির্ধারণের জন্য আরও চক্রের দৈর্ঘ্য ব্যবহার করুন
  • কম্বো ফিল্টারিংয়ের জন্য MACD, bias ইত্যাদির মতো অন্যান্য সূচক যুক্ত করুন
  • একক ট্রেড ক্ষতির আকার নিয়ন্ত্রণের জন্য স্টপ লস কৌশল যোগ করুন
  • বাস্তব অর্থ পরীক্ষা, প্যারামিটার অপ্টিমাইজ

অপ্টিমাইজেশান নির্দেশাবলী

এই কৌশল আরও উন্নত করার সুযোগ রয়েছেঃ

  1. সর্বোত্তম প্যারামিটার সমন্বয় খুঁজে পেতে QQE সূচকের দ্রুত এবং ধীর লাইন পরামিতি অপ্টিমাইজ করুন
  2. সর্বোত্তম ফিল্টারিং কর্মক্ষমতা খুঁজে পেতে আরো চলমান গড় combo পরীক্ষা করুন
  3. সহায়ক সংকেত ফিল্টারিংয়ের জন্য MACD এর মতো অন্যান্য সূচক যোগ করুন
  4. পজিশনের আকারকে অনুকূল করার জন্য অর্থ পরিচালনার কৌশল প্রয়োগ করুন
  5. ট্রেড প্রতি ডাউনসাইড ঝুঁকি নিয়ন্ত্রণের জন্য স্টপ লস কৌশল সেট করুন
  6. বিভিন্ন পণ্যের উপর ভিত্তি করে পরামিতি অপ্টিমাইজ করুন
  7. স্বল্পমেয়াদী বিপর্যয়ের দ্বারা বিভ্রান্ত না হওয়ার জন্য আরও বেশি সময়সীমার প্রবণতা নির্ধারণ করুন

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

সিদ্ধান্ত

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

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


/*backtest
start: 2024-01-17 00:00:00
end: 2024-01-24 00:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
//
// Title:   [STRATEGY][UL]QQE Cross v1.1
// Author:  JustUncleL
// Date:    22-Oct-2016
// Version: v1.1
//
// Description:
//  A trend following trading Strategy that uses fast QQE crosses with Moving Averages
//  for trend direction filtering. QQE or Qualitative Quantitative Estimation is based 
//  on the relative strength index, but uses a smoothing technique as an additional 
//  transformation. Three crosses can be selected (all selected by default): 
//    - RSI signal crossing ZERO (XZERO)
//    - RSI signal crossing Fast RSIatr line (XQQE)
//    - RSI signal exiting the RSI Threshhold Channel (BUY/SELL)
//  The (BUY/SELL) alerts can be optionally filtered by the Moving averages:
//    - For BUY alert the Close must be above the fast MA and 
//        fast MA (EMA8) > medium MA (EMA20) > slow MA (SMA50).
//    - For SELL alert the Close must be below the fast MA and
//        fast MA (EMA8) < medium MA (EMA20) < slow MA (SMA50).
//  and/or directional filter:
//    - For BUY alert the Close must be above the slow MA (SMA50) and the
//      directional MA (EMA20) must be green.
//    - For SELL alert the Close must be below the slow MA (SMA50) and the
//      directional MA (EMA20) must be red.
//. The XZERO and XQQE are not included in the filtering, they are used to indicate
//  pending BUY/SELL alerts, particularly the XZERO. 
//
//  This Strategy should work on any currency pair and most chart timeframes.
//  *** USE AT YOUR OWN RISK ***
//  
// 
//
// Mofidifications:
//  1.1 - Added Target Profit option, cleaned up the risk management code.
//        Changed Trade Close to EMA20 direction change instead of opposite BUY/SELL
//        signal, which will be earlier, this means stop loss setting should not be
//        required when an AutoTrader is available.
//        Modified code to prevent potential repaint issues.
//  1.0 - original
//
// References:
//  Some Code borrowed from:
//  - "Scalp Jockey - MTF MA Cross Visual Strategizer by JayRogers"
//  - "QQE MT4 by glaz"
//  - "Strategy Code Example by JayRogers"  
//  Inspiration from:
//  - http://www.forexstrategiesresources.com/binary-options-strategies-ii/189-aurora-binary-trading/
//  - http://www.forexstrategiesresources.com/metatrader-4-trading-systems-v/652-qqe-smoothed-trading/
//  - http://dewinforex.com/forex-indicators/qqe-indicator-not-quite-grail-but-accurately-defines-trend-and-flat.html
//

strategy(title='[STRATEGY][UL]QQE Cross v1.1', pyramiding=0, overlay=true )


// - INPUTS START
// Fast MA - type, source, length
type1   = input(defval="EMA", title="Fast MA Type: SMA, EMA, WMA, VWMA, SMMA, DEMA, TEMA, HullMA, ZEMA ( case sensitive )")
len1    = input(defval=8, title="Fast - Length", minval=1)
// Medium Fast MA - type, source, length
type2   = input(defval="EMA", title="Medium Fast MA Type: SMA, EMA, WMA, VWMA, SMMA, DEMA, TEMA, HullMA, ZEMA ( case sensitive )")
len2    = input(defval=20, title="Medium Fast - Length", minval=1)
// Slow MA - type, source, length
type3   = input(defval="SMA", title="Slow MA Type: SMA, EMA, WMA, VWMA, SMMA, DEMA, TEMA, HullMA, LSMA, ZEMA ( case sensitive )")
len3    = input(defval=50, title="Slow Length", minval=1)
//
// QQE rsi Length, Smoothing, fast ATR factor, source
RSILen  = input(6,title='RSI Length')
SF      = input(3,title='RSI Smoothing Factor')
QQE     = input(2.618,title='Fast QQE Factor')
threshhold = input(10, title="RSI Threshhold")
//
sQQEx   = input(false,title="Show QQE Signal crosses")
sQQEz   = input(false,title="Show QQE Zero crosses")
//
filter  = input(false,title="Use Moving Average Filter")
dfilter = input(true, title="Use Trend Directional Filter" )
RSIsrc  = input(close,title="Source")
srcclose= RSIsrc

// - INPUTS END

// - FUNCTIONS

// Returns MA input selection variant, default to SMA if blank or typo.
variant(type, src, len) =>
    v1 = sma(src, len)                                                  // Simple
    v2 = ema(src, len)                                                  // Exponential
    v3 = wma(src, len)                                                  // Weighted
    v4 = vwma(src, len)                                                 // Volume Weighted
    v5 = na(v5[1]) ? sma(src, len) : (v5[1] * (len - 1) + src) / len    // Smoothed
    v6 = 2 * v2 - ema(v2, len)                                          // Double Exponential
    v7 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len)               // Triple Exponential
    v8 = wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len)))   // Hull
    ema1 = ema(src, len)
    ema2 = ema(ema1, len)
    v10 = ema1+(ema1-ema2)                                              // Zero Lag Exponential
    // return variant, defaults to SMA if input invalid.
    type=="EMA"?v2 : type=="WMA"?v3 : type=="VWMA"?v4 : type=="SMMA"?v5 : type=="DEMA"?v6 : type=="TEMA"?v7 : type=="HullMA"?v8 : type=="ZEMA"?v10 : v1

// - FUNCTIONS END

// - Fast ATR QQE
//
Wilders_Period = RSILen * 2 - 1
//
Rsi = rsi(RSIsrc,RSILen)
RSIndex = ema(Rsi, SF)
AtrRsi = abs(RSIndex[1] - RSIndex)
MaAtrRsi = ema(AtrRsi, Wilders_Period)
DeltaFastAtrRsi = ema(MaAtrRsi,Wilders_Period) * QQE
//
newshortband=  RSIndex + DeltaFastAtrRsi
newlongband= RSIndex - DeltaFastAtrRsi
longband=RSIndex[1] > longband[1] and RSIndex > longband[1] ? max(longband[1],newlongband) : newlongband
shortband=RSIndex[1] < shortband[1] and  RSIndex < shortband[1] ? min(shortband[1],newshortband) : newshortband
trend=cross(RSIndex, shortband[1])? 1 : cross(longband[1], RSIndex) ? -1 : nz(trend[1],1)
FastAtrRsiTL = trend==1 ? longband : shortband


// - SERIES VARIABLES
// MA's
ma_fast    = variant(type1, srcclose, len1)
ma_medium  = variant(type2, srcclose, len2)
ma_slow    = variant(type3, srcclose, len3)
// Get Direction From Medium Moving Average
direction = rising(ma_medium,3) ? 1 : falling(ma_medium,3) ? -1 : 0
//
// Find all the QQE Crosses
QQExshort = sQQEx and crossover(FastAtrRsiTL, RSIndex)
QQExlong  = sQQEx and crossunder(FastAtrRsiTL, RSIndex)
// Zero cross
QQEzlong = sQQEz and crossover(RSIndex,50)
QQEzshort  = sQQEz and crossunder(RSIndex,50)
//  
// Thresh Hold channel Crosses give the BUY/SELL alerts.
QQEclong = RSIndex>(50+threshhold) ? na(QQEclong[1]) ? 1 : QQEclong[1]+1 : 0
QQEcshort = RSIndex<(50-threshhold) ? na(QQEcshort[1]) ? 1 : QQEcshort[1]+1 : 0

//
// Check Filtering.
QQEflong = (not filter or (srcclose>ma_fast and ma_medium>ma_slow and ma_fast>ma_medium)) and 
  (not dfilter or (direction>0 and srcclose>ma_slow))
QQEfshort = (not filter or (srcclose<ma_fast and ma_medium<ma_slow and ma_fast<ma_medium)) and
  (not dfilter or (direction<0 and srcclose<ma_slow))
//
// Get final BUY / SELL alert determination
buy = QQEclong>0 and QQEflong ? na(buy[1]) ? 1 : buy[1]+1 : 0
sell= QQEcshort>0 and QQEfshort ? na(sell[1]) ? 1 : sell[1]+1 : 0

// - SERIES VARIABLES END

// - PLOTTING
// Ma's
plot(ma_fast, title="MA Fast", color=olive, linewidth=2, transp=20)
plot(ma_medium, title="MA Medium Fast", color=direction<0?red:green, linewidth=3, transp=0)
plot(ma_slow, title="MA Slow", color=blue, linewidth=2, transp=20)
// QQE crosses
plotshape(QQExlong and buy!=1, title="QQE Cross Over", style=shape.triangleup, location=location.belowbar, text="XQQE", color=blue, transp=20, size=size.tiny)
plotshape(QQExshort and sell!=1, title="QQE Cross Under", style=shape.triangledown, location=location.abovebar, text="XQQE", color=black, transp=20, size=size.tiny)
// Signal crosses zero line
plotshape(QQEzlong and buy!=1 and not QQExlong, title="QQE Zero Cross Over", style=shape.triangleup, location=location.belowbar, text="XZERO", color=aqua, transp=20, size=size.tiny)
plotshape(QQEzshort and sell!=1 and not QQExshort, title="QQE Zero Cross Under", style=shape.triangledown, location=location.abovebar, text="XZERO", color=fuchsia, transp=20, size=size.tiny)

// - PLOTTING END

// Create alert for cross, shunt back 1 if source is not 'open', this should prevent repaint issue.
//shunt = RSIsrc == open ? 0 : 1
shunt = 0
c_alert = (buy[shunt]==1 or sell[shunt]==1)
//alertcondition(c_alert, title="QQECROSS Alert", message="QQECROSS Alert")
// show only when alert condition is met and bar closed.
plotshape(c_alert,title= "Alert Indicator Closed", location=location.bottom, color=sell[shunt]==1?red:green, transp=0, style=shape.circle)


//  Strategy: (Thanks to JayRogers)
// === STRATEGY RELATED INPUTS ===
//tradeInvert     = input(defval = false, title = "Invert Trade Direction?")
// the risk management inputs
inpTakeProfit   = input(defval = 0, title = "Take Profit Points", minval = 0)
inpStopLoss     = input(defval = 0, title = "Stop Loss Points", minval = 0)
inpTrailStop    = input(defval = 100, title = "Trailing Stop Loss Points", minval = 0)
inpTrailOffset  = input(defval = 0, title = "Trailing Stop Loss Offset Points", minval = 0)

// === RISK MANAGEMENT VALUE PREP ===
// if an input is less than 1, assuming not wanted so we assign 'na' value to disable it.
useTakeProfit   = inpTakeProfit  >= 1 ? inpTakeProfit  : na
useStopLoss     = inpStopLoss    >= 1 ? inpStopLoss    : na
useTrailStop    = inpTrailStop   >= 1 ? inpTrailStop   : na
useTrailOffset  = inpTrailOffset >= 1 ? inpTrailOffset : na

// === STRATEGY - LONG POSITION EXECUTION ===
strategy.entry(id = "Buy", long = true, when = buy[shunt]==1 )// use function or simple condition to decide when to get in
strategy.close(id = "Buy", when = direction[shunt]!=direction[shunt+1])// ...and when to get out

// === STRATEGY - SHORT POSITION EXECUTION ===
strategy.entry(id = "Sell", long = false, when = sell[shunt]==1)
strategy.close(id = "Sell", when = direction[shunt]!=direction[shunt+1])

// === STRATEGY RISK MANAGEMENT EXECUTION ===
// finally, make use of all the earlier values we got prepped
strategy.exit("Exit Buy", from_entry = "Buy", profit = useTakeProfit, loss = useStopLoss, trail_points = useTrailStop, trail_offset = useTrailOffset)
strategy.exit("Exit Sell", from_entry = "Sell", profit = useTakeProfit, loss = useStopLoss, trail_points = useTrailStop, trail_offset = useTrailOffset)

//eof

আরো