স্টোকাস্টিক এবং এমএসিডি সূচকগুলির উপর ভিত্তি করে বিপরীত ট্রেডিং কৌশল

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

সারসংক্ষেপ

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

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

  1. স্টোকাস্টিক সূচকটি ব্যবহার করে অতিরিক্ত ক্রয় এবং অতিরিক্ত বিক্রয় শর্তগুলি সনাক্ত করুন। 20 এর নিচে পাঠ্যগুলি অতিরিক্ত বিক্রয় স্তরগুলি নির্দেশ করে যখন 80 এর উপরে অতিরিক্ত ক্রয়ের অঞ্চলগুলি নির্দেশ করে, বিপরীতমুখী সংকেত গঠন করে।

  2. এমএসিডি গোল্ডেন ক্রসগুলিতে লম্বা যান এবং এমএসিডি ডেথ ক্রসগুলিতে শর্ট যান। সিগন্যাল লাইনের উপরে এমএসিডি ক্রসিং চলমান গড় বিপরীতমুখী নির্দেশ করে এবং প্রবণতা বিপরীতমুখী বোঝায়।

  3. যখন স্টোকাস্টিক বিপরীতমুখী সিগন্যাল MACD বিপরীতমুখী সিগন্যালের সাথে সঙ্গতিপূর্ণ হয় তখন লং বা শর্ট পজিশন নিন।

  4. ট্রেলিং স্টপ লস বাস্তবায়ন করুন। একটি প্রবণতা প্রবেশ করার পরে, যখন মূল্য একটি নির্দিষ্ট মুনাফা শতাংশে পৌঁছে যায়, ট্রেলিং স্টপ ট্রিগার করা হয়। স্টপ স্তরটি তারপর আপগ্রেড মূল্য চ্যানেলের পিছনে থাকে।

  5. বিদ্যমান পজিশন বন্ধ করা হয় এবং নতুন বিপরীত সংকেত প্রদর্শিত হলে স্টপ লস রিসেট করা হয়।

সুবিধা

  • একাধিক সূচক নিশ্চিতকরণ সংকেত নির্ভুলতা উন্নত

  • স্টোক্যাস্টিক কার্যকরভাবে ওভারকুপেড/ওভারসোল্ড জোন চিহ্নিত করে

  • এমএসিডি গতিশীল গড়ের বিপরীতমুখীতাকে প্রাথমিকভাবে ধরা দেয়

  • ট্রেলিং স্টপ লাভের মধ্যে ভাল লক

  • স্পষ্ট কৌশল সংকেত সহ পর্যাপ্ত ব্যাকটেস্টিং ডেটা

  • সহজ সমন্বয় জন্য অপ্টিমাইজযোগ্য পরামিতি

ঝুঁকি

  • একাধিক সূচক অপ্টিমাইজ করার অসুবিধা

  • বিপরীত সংকেত ভুলভাবে বিচার করা যেতে পারে এবং বৈধতা প্রয়োজন

  • ট্রেলিং স্টপ পরীক্ষা এবং অপ্টিমাইজ করার জন্য আরও তথ্য প্রয়োজন

  • স্টোকাস্টিক এবং এমএসিডির বিলম্বিত প্রকৃতি

  • ঘন ঘন লেনদেনের ফলে ব্যয় বাড়তে পারে

উন্নতি

  • একটি শক্তিশালী ট্রেডিং সিস্টেম গড়ে তুলতে আরও সূচক যুক্ত করুন

  • সর্বোত্তম সমন্বয় খুঁজে পেতে বিভিন্ন প্যারামিটার সময়কাল পরীক্ষা করুন

  • রিয়েল-টাইমে আপডেট হওয়া অভিযোজিত পরামিতিগুলি বিকাশ করুন

  • সর্বাধিক ড্রডাউন সীমাবদ্ধ করার জন্য ড্রডাউন স্টপ লস সেট করুন

  • বিভ্রান্তি থেকে মিথ্যা সংকেত এড়ানোর জন্য ভলিউম অন্তর্ভুক্ত করুন

  • ট্রেডিং খরচ প্রভাব বিবেচনা করুন এবং সর্বনিম্ন মুনাফা লক্ষ্য নির্ধারণ করুন

সিদ্ধান্ত

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


/*backtest
start: 2022-09-14 00:00:00
end: 2023-06-24 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
////////////////////////////////////////////////////////////
// @CoinDigger
//
// Credits for the base strategy go to HPotter
//
// I've just added a trail stop, basic leverage simulation and stop loss
//
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 28/01/2021
// This is combo strategies for get a cumulative signal. 
//
// First strategy
// This System was created from the Book "How I Tripled My Money In The 
// Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
// The strategy buys at market, if close price is higher than the previous close 
// during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50. 
// The strategy sells at market, if close price is lower than the previous close price 
// during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
//
// Second strategy
// MACD – Moving Average Convergence Divergence. The MACD is calculated 
// by subtracting a 26-day moving average of a security's price from a 
// 12-day moving average of its price. The result is an indicator that 
// oscillates above and below zero. When the MACD is above zero, it means 
// the 12-day moving average is higher than the 26-day moving average. 
// This is bullish as it shows that current expectations (i.e., the 12-day 
// moving average) are more bullish than previous expectations (i.e., the 
// 26-day average). This implies a bullish, or upward, shift in the supply/demand 
// lines. When the MACD falls below zero, it means that the 12-day moving average 
// is less than the 26-day moving average, implying a bearish shift in the 
// supply/demand lines.
// A 9-day moving average of the MACD (not of the security's price) is usually 
// plotted on top of the MACD indicator. This line is referred to as the "signal" 
// line. The signal line anticipates the convergence of the two moving averages 
// (i.e., the movement of the MACD toward the zero line).
// Let's consider the rational behind this technique. The MACD is the difference 
// between two moving averages of price. When the shorter-term moving average rises 
// above the longer-term moving average (i.e., the MACD rises above zero), it means 
// that investor expectations are becoming more bullish (i.e., there has been an 
// upward shift in the supply/demand lines). By plotting a 9-day moving average of 
// the MACD, we can see the changing of expectations (i.e., the shifting of the 
// supply/demand lines) as they occur.
//
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
Reversal123(Length, KSmoothing, DLength, Level) =>
    vFast = sma(stoch(close, high, low, Length), KSmoothing) 
    vSlow = sma(vFast, DLength)
    pos = 0.0
    pos := iff(close[2] < close[1] and close > close[1] and vFast < vSlow and vFast > Level, 1,
	         iff(close[2] > close[1] and close < close[1] and vFast > vSlow and vFast < Level, -1, nz(pos[1], 0))) 
	pos

MACD(fastLength,slowLength,signalLength) =>
    pos = 0.0
    fastMA = ema(close, fastLength)
    slowMA = ema(close, slowLength)
    macd = fastMA - slowMA
    signal = sma(macd, signalLength)
    pos:= iff(signal < macd , 1,
	       iff(signal > macd, -1, nz(pos[1], 0))) 
    pos
strategy(title="Combo Backtest 123 Reversal & MACD Crossover with Trail and Stop", shorttitle="ComboReversal123MACDWithStop", overlay = false, precision=8,default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=100, currency="USD", commission_type=strategy.commission.percent, commission_value=0.075)

leverage=input(2,"leverage",step=1)
percentOfEquity=input(100,"percentOfEquity",step=1)

sl_trigger = input(10, title='Stop Trail Trigger %', type=input.float)/100
sl_trail = input(5, title='Stop Trail %', type=input.float)/100
sl_inp = input(10, title='Stop Loss %', type=input.float)/100

Length = input(100, minval=1)
KSmoothing = input(1, minval=1)
DLength = input(2, minval=1)
Level = input(1, minval=1)
//-------------------------
fastLength = input(10, minval=1)
slowLength = input(19,minval=1)
signalLength=input(24,minval=1)
xSeria = input(title="Source", type=input.source, defval=close)
reverse = input(false, title="Trade reverse")


////////////////////////////////////////////////////////////////////////////////
// BACKTESTING RANGE
 
// From Date Inputs
fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
fromYear = input(defval = 2015, title = "From Year", minval = 1970)
 
// To Date Inputs
toDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
toMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
toYear = input(defval = 2999, title = "To Year", minval = 1970)
 
// Calculate start/end date and time condition
startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)
finishDate = timestamp(toYear, toMonth, toDay, 00, 00)
time_cond = time >= startDate and time <= finishDate
 
////////////////////////////////////////////////////////////////////////////////



////////////////////// STOP LOSS CALCULATIONS //////////////////////////////
///////////////////////////////////////////////////


cond() => barssince(strategy.position_size[1] == 0 and (strategy.position_size > 0 or strategy.position_size < 0)) > 0

lastStopLong = 0.0
lastStopLong := lastStopLong[1] != strategy.position_avg_price - (strategy.position_avg_price * (sl_inp)) and lastStopLong[1]  != 0.0 ? lastStopLong[1]  : strategy.position_size > 0 ? (cond() and close > strategy.position_avg_price + (strategy.position_avg_price * (sl_trigger)) ? strategy.position_avg_price + (strategy.position_avg_price * (sl_trail)) : strategy.position_avg_price - (strategy.position_avg_price * (sl_inp))) : 0
lastStopShort = 0.0
lastStopShort := lastStopShort[1] != strategy.position_avg_price + (strategy.position_avg_price * (sl_inp)) and lastStopShort[1]  != 9999999999.0 ? lastStopShort[1]  : strategy.position_size < 0 ? (cond() and close < strategy.position_avg_price - (strategy.position_avg_price * (sl_trigger)) ? strategy.position_avg_price - (strategy.position_avg_price * (sl_trail)) : strategy.position_avg_price + (strategy.position_avg_price * (sl_inp))) : 9999999999.0

longStopPrice = 0.0
longStopPrice2 = 0.0
longStopPrice3 = 0.0
shortStopPrice = 0.0
longStopPrice := if strategy.position_size > 0
    originalStop = strategy.position_avg_price - (strategy.position_avg_price * (sl_inp))
    trigger = strategy.position_avg_price + (strategy.position_avg_price * (sl_trigger))
    trail = strategy.position_avg_price + (strategy.position_avg_price * (sl_trail))
    stopValue = high > trigger ? trail : 0
    max(stopValue, originalStop, longStopPrice[1])
else
    0

longStopPrice2 := if strategy.position_size > 0
    originalStop = strategy.position_avg_price - (strategy.position_avg_price * (sl_inp))
    trigger = strategy.position_avg_price + (strategy.position_avg_price * (sl_trigger*2))
    trail = strategy.position_avg_price + (strategy.position_avg_price * (sl_trail*2))
    stopValue = high > trigger ? trail : 0
    max(stopValue, originalStop, longStopPrice2[1])
else
    0


longStopPrice3 := if strategy.position_size > 0
    originalStop = strategy.position_avg_price - (strategy.position_avg_price * (sl_inp))
    trigger = strategy.position_avg_price + (strategy.position_avg_price * (sl_trigger*4))
    trail = strategy.position_avg_price + (strategy.position_avg_price * (sl_trail*3))
    stopValue = high > trigger ? trail : 0
    max(stopValue, originalStop, longStopPrice3[1])
else
    0
    
shortStopPrice := if strategy.position_size < 0
    originalStop = strategy.position_avg_price + (strategy.position_avg_price * (sl_inp))
    trigger = strategy.position_avg_price - (strategy.position_avg_price * (sl_trigger))
    trail = strategy.position_avg_price - (strategy.position_avg_price * (sl_trail))
    stopValue = low < trigger ? trail : 999999
    min(stopValue, originalStop, shortStopPrice[1])
else
    999999
    
///////////////////////////////////////////////////
///////////////////////////////////////////////////


posReversal123 = Reversal123(Length, KSmoothing, DLength, Level)
posMACD = MACD(fastLength,slowLength, signalLength)
pos = iff(posReversal123 == 1 and posMACD == 1 , 1,
	   iff(posReversal123 == -1 and posMACD == -1, -1, 0)) 
	   
possig = pos

quantity = max(0.000001,min(((strategy.equity*(percentOfEquity/100))*leverage/open),100000000))

if (possig == 1 and time_cond)
    strategy.entry("Long", strategy.long, qty=quantity)
if (possig == -1 and time_cond)
    strategy.entry("Short", strategy.short, qty=quantity) 
if (strategy.position_size > 0 and possig == -1 and time_cond)   
    strategy.close_all()
if (strategy.position_size < 0 and possig == 1 and time_cond)   
    strategy.close_all()
if ((strategy.position_size < 0 or strategy.position_size > 0) and possig == 0)   
    strategy.close_all()

//EXIT TRADE @ TSL
if strategy.position_size > 0
    strategy.exit(id="Long", stop=longStopPrice)
if strategy.position_size < 0
    strategy.exit(id="Short", stop=shortStopPrice)



আরো