سپر ٹرینڈ اسٹاپ ٹریلنگ ٹریڈنگ حکمت عملی


تخلیق کی تاریخ: 2023-09-18 16:05:31 آخر میں ترمیم کریں: 2023-09-18 16:05:31
کاپی: 0 کلکس کی تعداد: 880
1
پر توجہ دیں
1617
پیروکار

جائزہ

یہ حکمت عملی سپر ٹرینڈ اشارے کا استعمال کرتی ہے تاکہ قیمتوں کے رجحانات کا اندازہ لگایا جاسکے ، اور اسٹاپ نقصان کے طریقہ کار کے ساتھ ٹرینڈ ٹریکنگ کی تجارت کی جاسکتی ہے۔ یہ ایک سپر ٹرینڈ اشارے کی تعمیر کے لئے دو چلتی اوسط کی مختلف اقدار کو جوڑتا ہے ، جس میں اشارے پر زیادہ اور نچلے حصے پر خالی ہوتا ہے۔ اس کے ساتھ ہی اسٹاپ نقصان کی لائن بھی ترتیب دی جاتی ہے تاکہ زیادہ نقصان سے بچا جاسکے۔

حکمت عملی کا اصول

تیز لائن اور سست لائن کا ڈی ای ایم اے حساب لگائیں ، اور دونوں لائنوں کے فرق کی بنیاد پر سپر ٹرینڈ کی سمت کا تعین کریں۔ بڑھتے ہوئے رجحان میں ، تیز لائن پر سست لائن کو زیادہ سے زیادہ عبور کریں؛ گرنے والے رجحان میں ، تیز لائن کے نیچے سست لائن کو خالی کریں۔ داخلے کے بعد ، اسٹاپ نقصان کی لائن ترتیب دیں ، اور جب نقصانات اسٹاپ نقصان کی حد تک پہنچ جاتے ہیں تو اس کا خاتمہ ہوجاتا ہے۔

طاقت کا تجزیہ

  • سپر رجحانات کا تعین کرنے کے لئے قیمتوں کے رجحانات آسان اور موثر ہیں
  • اسٹاپ نقصان کا طریقہ کار ایک ہی تجارت کے خطرے کو مؤثر طریقے سے کنٹرول کرتا ہے
  • مختلف مرحلے کے مطابق مختلف پیرامیٹرز کا مجموعہ استعمال کیا جا سکتا ہے
  • مضبوط واپسی کنٹرول

خطرے کا تجزیہ

  • حرکت پذیر اوسط کے فیصلے میں تاخیر
  • اسٹاپ نقصان کی حد کو بہت زیادہ نرمی سے ترتیب دینا نقصان کو بڑھا سکتا ہے
  • اعلی ٹرانزیکشن فریکوئینسی ، بھاری فیس
  • ٹرینڈ کی تبدیلی کا درست اندازہ نہیں لگایا جا سکا

خطرے کو کنٹرول کرنے کے لئے ، اوسط سائیکل کو مناسب طریقے سے کم کیا جاسکتا ہے ، اسٹاپ نقصان کی حد کو بہتر بنایا جاسکتا ہے ، اور تجارت کی تعداد کو کم کیا جاسکتا ہے۔

اصلاح کی سمت

  • تیز اور سست لائن پیرامیٹرز کے مختلف مجموعوں کی جانچ
  • اسٹاپ نقصان کی حد کو بہتر بنائیں
  • دوسرے اشارے کے ساتھ ٹرینڈ ریورس پر غور کریں
  • مختلف نسلوں میں ٹیسٹ پیرامیٹرز کی مضبوطی

خلاصہ کریں۔

اس حکمت عملی میں رجحان کی سمت کا تعین کرنے کے لئے آسان اشارے کا استعمال کیا جاتا ہے ، نقصان کو روکنے کے لئے خطرہ کنٹرول کیا جاتا ہے ، اور دن کے اندر تجارت کے لئے موزوں ہے۔ اس کی تاثیر کو مزید بڑھایا جاسکتا ہے ، جیسے پیرامیٹرز کو ایڈجسٹ کرنا۔

حکمت عملی کا ماخذ کوڈ
/*backtest
start: 2023-09-10 00:00:00
end: 2023-09-13 00:00:00
period: 2m
basePeriod: 1m
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/

//@version=3
strategy(title = "[Prod] SuperTrend with Stoploss+TrendZones - 1H", default_qty_type=strategy.percent_of_equity, default_qty_value=100, shorttitle = "[Prod] SuperTrend with Stoploss+TrendZones - 1H", overlay = true, commission_type=strategy.commission.percent, commission_value=0.3)
//--cyberfunk 2018 
 
////////////////////////////////////////////////////////////
// This section of code was borrowed from "Trend Trader Strategy" to 
// help us det. if we are in an uptrend or downtrend.
////////////////////////////////////////////////////////////
Length = input(12, minval=1),   // 19 / 5 also works for lenth /multiplier... but 11 /4 seems slightly more optimal somehow
Multiplier = input(4, minval=1)
avgTR      = wma(atr(1), Length)
highestC   = highest(Length)
lowestC    = lowest(Length)
hiLimit = highestC[1]-(avgTR[1] * Multiplier)
loLimit = lowestC[1]+(avgTR[1] * Multiplier)
ret = na
pos =na
ret := iff(close > hiLimit and close > loLimit, hiLimit,iff(close < loLimit and close < hiLimit, loLimit, nz(ret[1], 0)))
pos :=	iff(close > ret, 1,iff(close < ret, -1, nz(pos[1], 0))) 
//barcolor(pos == -1 ? red: pos == 1 ? green : blue )
plot(ret, color= blue , title="Trend Trader Strategy")
uptrend = if close > ret  // this will be used later to determine which domain we are in (uptrend or downtrend)
    true
else
    false
/////////////////////////////////////////////////////////////////////
// This script has been optimized for the 1 hr candle window view.  
// An older Pine2 ancestor of this script suffered from repainting issues when 
// viewing in lower resolutions than the res/2 parameter.
// running this in Pine3 mode seems to fix those problems, see https://www.tradingview.com/wiki/Pine_Script:_Release_Notes#Pine_Version_3  and https://backtest-rookies.com/2017/11/29/tradingview-indicator-repainting/ for references on the problem. 
//
//  There does seem to be ocassional repainting that affects backtrading here though, somehow.. and i'm not sure how to fix it.  V3 SHOULD have made it impossible.  Any help appreciated.
//
// Also note that the length of the DEMA sampling shouldn't be longer than a 
// candle, which could happen if you made resolution > chartres^2.  For example,
// a chartres=5min and a res=30 setting would cause sampling = 6, which is longer
// than the length of a candle (5 min, b/c chartres=5 min)
/////////////////////////////////////////////////////////////////////


fastPeriod    = input(title="fastPeriod",defval=4, minval=1)
slowPeriod = input(title="slowPeriod",defval=31, minval=1) 
resInteger = input(title="resolution",defval=98)
// The parameters above that work well highly oscillating sideways markets,
// struggle with longer-term trends, particularly strong ones, where there's the
// potential for a lot of loss or strong gain. To make sure we don't get burned 
// by long term losses, a stoploss mechanism is implemented to compensate.
// *stoplossPercent* is the point at which it becomes useful to "panic sell".
// *letitRidePercent* is the point beyond which it's more profitable NOT to panic sell.
// Like the periods, these values will have to be tuned to a particuliar market behavior.
stoplossPercent    = input(title="stopLossPercentage",type=float,defval=2, minval=1, maxval=100)
letitRidePercent = input(title="letItRidePercentage",type=float,defval=3, minval=1, maxval=100)

//To try to recapture the value of the long term strong-uptrends, first we 
// detected when we are in strong uptrend mode, by using an indicator (uptrend?)
// Then, if we are in strong uptrend mode, we use a different
// set of variables for fast/slow periods that's better suited to that situation.

uptrendFastPeriod = input(title="Uptrend FastPeriod",defval=4, minval=1) 
uptrendSlowPeriod = input(title="Uptrend SlowPeriod",defval=16, minval=1) 
//uptrendResInteger = input(title="Uptrend resolution",defval=98)

// Now that we have everything setup, for each bar we calculate the difference of emas for the downtrend/uptrend situations
res = tostring(resInteger) 
sampling =  (resInteger / timeframe.period )
demaFastNormal = security(syminfo.tickerid, res, 2 * ema(close, fastPeriod) - ema(ema(close, fastPeriod), fastPeriod))
demaSlowNormal = security(syminfo.tickerid,res, 2 * ema(close, slowPeriod) - ema(ema(close, slowPeriod), slowPeriod)  )
demaFastUT = security(syminfo.tickerid, res, 2 * ema(close, uptrendFastPeriod) - ema(ema(close, uptrendFastPeriod), uptrendFastPeriod))
demaSlowUT = security(syminfo.tickerid,res, 2 * ema(close, uptrendSlowPeriod) - ema(ema(close, uptrendSlowPeriod), uptrendSlowPeriod)  )

// now, based on our uptrend indicator, we decide which of the two line pairs to
// use to determine the crossover signals that tell us to buy/sell.
demaFast = uptrend? demaFastUT:demaFastNormal
demaSlow =  uptrend? demaSlowUT:demaSlowNormal


//  Now, we calculate the crossover signals.
// **IMPORTANT TRADING NOTE** :  You should buy/sell on the CLOSE of the
// highlighted bar with the  signal, to adhere to back-tested results!
// (Technically, the open of the NEXT bar, but these are usually effectively the same.)  
// Note that if you check "calculate on every tick", you might be decieved until 
// you reload the page, this is NOT, however, a repaint issue, as after the bar 
// after the signal closes there is a consistent buy/sell indicator at the open 
// price of the bar after the the signal, which is basically as close to same as
// the close price of the signal (red/green highlighted) bar.

buy = crossover(demaSlow[sampling], demaFast[sampling])
stoploss = ( strategy.openprofit <-1*stoplossPercent/100*strategy.equity) and not ( strategy.openprofit < -1*letitRidePercent/100*strategy.equity )
sell = strategy.opentrades!=0 and (crossunder(demaSlow[sampling], demaFast[sampling]) or crossover(ret,close) ) and not stoploss // "and not stoploss" here helps us not over-color when both conditions are true.  The stoploss is more interesting than a regular sell condition


///////////////////////////////////////
// PLOTTING SECTION 
// This is a collected place for Plotting and coloring all the things 
// for easy toggling on/off.
///////////////////////////////////////

//plot(buyPrice, title="BuyPriceLine", color = purple )   // For a study, this replaces the strategy.openprofit way to guard against stoploss
plot(demaFast)   // These are the crossover lines that trigger the buy/sell
plot(demaSlow)




bgcolor( buy ? lime : na, transp=50)
bgcolor( stoploss ? orange : na, transp=10)
bgcolor( sell ? red : na, transp=50)
bgcolor( strategy.openprofit < -1*letitRidePercent/100*strategy.equity ? purple : na, transp= 50)

bgcolor( demaSlow[sampling]> demaFast[sampling]  ? lime : na, transp=96)
bgcolor( demaSlow [sampling]< demaFast[sampling]  ? red : na, transp=99)

// the below is for backtesting from different timeframes.  By default it is set to 1/1/2017 at 1:00 AM
startdate=timestamp(2017, 01, 01, 01, 00)   // year , month, day, hour, minute

strategy.entry("BUY", strategy.long, when = buy and (time>=startdate) )
strategy.close("BUY", when = sell or stoploss)