以风险比率定义策略的问题
我试图根据RR的所需值(风险indIndex
)来定义我的策略,并通过货币和时间范围的变化风险RO奖励比率变化。我使用sma50
和stragity.position_avg_price
之间的距离来设置RR值。问题在于策略在RR = stight> RiskRewardIndex
之前退出位置(例如:rr = 2
时,它在1.43
等中退出),出口点与RR比不完全匹配。我更喜欢使用tick而不是价格更改。
//@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
shortCondition = crossunder(sma(close, 14), sma(close, 28)) and close<smastoploss
//Risk to Rewars Ration
RiskRewardIndex=input(2, "Risk Reward Index", type=input.float)
//Stoploss will be in the low (Long position) /high(Sort position) of ENTRY CANDLE
float distancelong=0.00
float stoplosslong=0.00
float takeprofitlong=0.00
float distanceshort=0.00
float stoplossshort=0.00
float takeprofitshort=0.00
//var float smastoploss=na
if (longCondition)
strategy.entry("Long", strategy.long)
distancelong := strategy.position_avg_price-smastoploss
stoplosslong:=distancelong/syminfo.mintick
takeprofitlong:=RiskRewardIndex*distancelong/syminfo.mintick
tpl=(takeprofitlong*syminfo.mintick)/2.0+ strategy.position_avg_price
plot(tpl,color=color.black)
strategy.exit("exit", "Long", loss =stoplosslong ,profit=takeprofitlong,comment='ExitLongRR')
if (shortCondition)
strategy.entry("Short", strategy.short)
distanceshort :=smastoploss-strategy.position_avg_price
stoplossshort:=distanceshort/syminfo.mintick
takeprofitshort:=RiskRewardIndex*distanceshort/syminfo.mintick
strategy.exit("exit", "Short", loss = stoplossshort,profit=takeprofitshort,comment='ExitShortRR')
I am trying to define my strategy based on desired values of RR (RiskRewardIndex
), and risk ro reward ratio changes by currency and timeframe. I use the distance between sma50
and strategy.position_avg_price
to set RR values. The problem is that strategy exits the positions before RR= RiskRewardIndex
(for example: when RR=2
, it exits at 1.43
and etc) , the exit point does not matches exactly with RR ratio. I prefer to use ticks instead of price changes.
//@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
shortCondition = crossunder(sma(close, 14), sma(close, 28)) and close<smastoploss
//Risk to Rewars Ration
RiskRewardIndex=input(2, "Risk Reward Index", type=input.float)
//Stoploss will be in the low (Long position) /high(Sort position) of ENTRY CANDLE
float distancelong=0.00
float stoplosslong=0.00
float takeprofitlong=0.00
float distanceshort=0.00
float stoplossshort=0.00
float takeprofitshort=0.00
//var float smastoploss=na
if (longCondition)
strategy.entry("Long", strategy.long)
distancelong := strategy.position_avg_price-smastoploss
stoplosslong:=distancelong/syminfo.mintick
takeprofitlong:=RiskRewardIndex*distancelong/syminfo.mintick
tpl=(takeprofitlong*syminfo.mintick)/2.0+ strategy.position_avg_price
plot(tpl,color=color.black)
strategy.exit("exit", "Long", loss =stoplosslong ,profit=takeprofitlong,comment='ExitLongRR')
if (shortCondition)
strategy.entry("Short", strategy.short)
distanceshort :=smastoploss-strategy.position_avg_price
stoplossshort:=distanceshort/syminfo.mintick
takeprofitshort:=RiskRewardIndex*distanceshort/syminfo.mintick
strategy.exit("exit", "Short", loss = stoplossshort,profit=takeprofitshort,comment='ExitShortRR')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过使用
value时解决了这个问题(条件,源,出现)→系列[float]
pine-script中的函数,此函数返回source
时的nth值。 >条件是正确的。另外,我忽略了前200支蜡烛来计算移动平均值。I solved this question by using the
valuewhen(condition, source, occurrence) → series[float]
function in pine-script, this function returns nth value ofsource
whencondition
is true. Also, I ignored first 200 candles to calculate moving averages.