من در تلاش هستم که استراتژی خود را بر اساس مقادیر مورد نظر RR (RiskRewardIndex) تعریف کنم و نسبت پاداش Risk Ro را از طریق ارز و بازه زمانی تغییر می دهد. من از فاصله بین SMA50 و استراتژی استفاده می کنم. برای تنظیم مقادیر RR. مشکل این است که استراتژی از موقعیت ها قبل از RR = RiskRewardIndex خارج می شود (به عنوان مثال: وقتی RR = 2 ، در 1. 43 و غیره خارج می شود) ، نقطه خروج دقیقاً با نسبت RR مطابقت ندارد. من ترجیح می دهم به جای تغییر قیمت از کنه استفاده کنم.
//@version=4 strategy("Strategy Profit Loss RiskReaward", overlay=true) smastoploss=sma(close,50) plot(smastoploss,color=color.blue) longCondition = crossover(sma(close, 14), sma(close, 28)) and close>کوتاه مدت Smastoploss = Crossunder (SMA (نزدیک ، 14) ، SMA (نزدیک ، 28)) و نزدیک

کوارتو بازرگانی الگوریتمی کاج-اسکریپت-V4
دنبال کردن 23 آوریل 2022 در 15:54 پرسید مهدی shokati mehdi shokati 29 7 7 نشان های برنز
1 پاسخ 1
مرتب شده توسط: تنظیم مجدد به طور پیش فرض
من این سؤال را با استفاده از Value WHEN (شرط ، منبع ، وقوع) حل کردم. همچنین ، من 200 شمع اول را برای محاسبه میانگین های متحرک نادیده گرفتم.
//@version=4 strategy("Strategy Profit Loss RiskReaward",overlay=true,calc_on_every_tick=true, pyramiding = 0, default_qty_type=strategy.percent_of_equity, default_qty_value=20, initial_capital=5000, calc_on_order_fills=false,commission_type=strategy.commission.percent, commission_value=0.1) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Risk to Rewars Ration RiskRewardIndex=input(4, "Risk Reward Index", type=input.float) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //We should ignore someof first candles to check our strategy lastBarsFilterInput = input(100, "Bars Count:",type=input.integer) // Here, we store the 'last_bar_index' value that is known from the beginning of the script's calculation. // The 'last_bar_index' will change when new real-time bars appear, so we declare 'lastbar' with the 'var' keyword. //var int lastbar=0 lastbar = 4900 // Check if the current bar_index is 'lastBarsFilterInput' removed from the last bar on the chart, or the chart is traded in real-time. int allowedToTrade=0 //Which candles we cand trade if (lastbar-bar_index>=lastbar-lastBarsFilterInput) or barstate.isrealtime allowedToTrade:=0 else allowedToTrade:=bar_index ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //CalculateLong/Short Entry Conditions periodShort = input(13, minval=1, title="Enter Period for Short Moving Average") periodLong = input(48, minval=1, title="Enter Period for Long Moving Average") fastema=ema(close,periodShort) slowema=ema(close,periodLong) //Calculate PSAR psarStart = input(title="PSAR Start", type=input.float, step=0.001, defval=0.02, group="PSAR") psarIncrement = input(title="PSAR Increment", type=input.float, step=0.001, defval=0.02, group="PSAR") psarMaximum = input(title="PSAR Maximum", type=input.float, step=0.01, defval=0.2, group="PSAR") psar = sar(psarStart, psarIncrement, psarMaximum) longema=crossover(ema(close, periodShort), ema(close, periodLong)) shortema=crossunder(ema(close, periodShort), ema(close, periodLong)) longCondition = (longema and slowema>psar and close>fastema) or (fastema>slowema and crossunder(psar,close) and close>fastema) shortCondition = ( shortema and slowemafastema) or ( crossunder(psar,slowema) and close>fastema) // or ( close>fastema and close>close[1] and close[1]>close[2] and close[2]>close[3] and close[3]>close[4]) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Stoploss will be in the size of difference between strategy average price and desired SMA length =input(title="SMAlength",type=input.integer,minval=9,defval=60) source1=sma(close,length) smastoplosslong=valuewhen(longCondition,source1,0) smastoplossshort=valuewhen(shortCondition,source1,0) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// float distancelong=0.00 float stoplosslong=0.00 float takeprofitlong=0.00 float distanceshort=0.00 float stoplossshort=0.00 float takeprofitshort=0.00 ///////////////////////////////////////////LONG/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if longCondition and strategy.opentrades==0 and allowedToTrade>0 strategy.entry("Long", strategy.long) distancelong := abs(strategy.position_avg_price-smastoplosslong) // Stop size calculation stoplosslong:=distancelong/syminfo.mintick //Profit size calculation takeprofitlong:=RiskRewardIndex*distancelong/syminfo.mintick strategy.exit("exit", "Long", loss =stoplosslong ,profit=takeprofitlong,comment='ExitLongRR') //Close Strategy if longConditionexit strategy.close( "Long",when=longConditionexit,comment='ExLoEMACross') ///////////////////////////////////////////SHORT/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if shortCondition and strategy.opentrades== 0 and allowedToTrade>0 strategy.entry("Short", strategy.short) distanceshort :=abs(strategy.position_avg_price-smastoplossshort) // Stop size calculation stoplossshort:=distanceshort/syminfo.mintick //Profit size calculation takeprofitshort:=RiskRewardIndex*distanceshort/syminfo.mintick strategy.exit("exit", "Short", loss = stoplossshort,profit=takeprofitshort,comment='ExitShortRR') //Close Strategy if shortConditionexit strategy.close( "Short",when=shortConditionexit,comment='ExShEMACross') /////////////////// Colors ///////////////////// collongsl = color.blue collongtp = color.green colshortsl = color.orange colshorttp = color.red ///////////////////////////////////////////PLOT/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //LONG Position TP/SL Plot p1=plot(strategy.position_size> 0 ? strategy.position_avg_price-stoplosslong*syminfo.mintick : na, color= longCondition ? collongsl : na, style=plot.style_linebr, title="SL_Long") p2=plot(strategy.position_size> 0 ? strategy.position_avg_price+takeprofitlong*syminfo.mintick : na, color= longCondition ? collongtp : na , style=plot.style_linebr, title="TP_Long") p3=plot(strategy.position_size>0؟Strategy. Position_AVG_PRICE: NA ، COLOR = COLOR. SILVER ، STYLE = PLOT. STYLE_LINEBR ، TITLE = "ENTER_LONG") FILL (P1 ، P3 ، COLOR = COLOR. NEW (COLOR. RED ، TRANSP = 90)) پر کنید (P2 ، P3 ، P3 ، P3، color = color. new (color. aqua ، transp = 90)) // موقعیت کوتاه tp/sl plot p4 = plot (استراتژی. position_size<0 ? strategy.position_avg_price+stoplossshort*syminfo.mintick : na, color= shortCondition ? colshortsl : na, style=plot.style_linebr, title="SL_Short") p5=plot(strategy.position_size <0 ? strategy.position_avg_price-takeprofitshort*syminfo.mintick: na, color= shortCondition ? colshorttp : na, style=plot.style_linebr, title="TP_Short") p6=plot(strategy.position_size <0 ? strategy.position_avg_price : na, color=color.silver, style=plot.style_linebr, title="Entry_Short") fill(p4, p6, color=color.new(color.red, transp = 90)) fill(p5, p6, color=color.new(color.aqua, transp = 90))
استراتژی برای تجارت گزینه های...
ما را در سایت استراتژی برای تجارت گزینه های دنبال می کنید
برچسب :
نویسنده : فریبا کامران
بازدید : 35
تاريخ : پنجشنبه
26 مرداد
1402 ساعت: 14:13