问题描述
我试图用pine脚本编写自定义的日常风险管理功能,但没有成功。 有两个主要目标:
- 每日利润追踪止损点
- 如果每日余额为正或负,则在x交易后的第二天停止交易。
带有这些选项的输入。
当前代码如下(在其他地方定义了输入)
//strategy.risk.max_intraday_filled_orders(iXTrades) -> commented out as doesn't do what I need
netProfit = 0.0
netProfit := nz(netProfit[1])
yesterday = 0.0
yesterday := nz(yesterday[1])
if yesterday != dayofmonth
yesterday := dayofmonth
netProfit := strategy.netprofit
netProfit
filledOrders = 0
filledOrders := (dayofweek != dayofweek[1]) ? 0 :
(strategy.position_size != strategy.position_size[1]) ?
filledOrders[1] + 1 :
filledOrders[1]
//Tallies daily balance
dayProfit = strategy.netprofit - netProfit + strategy.openprofit
//Daily Break-even
maxProfit = -iDailyLosslimit
if iBEDistance > 0
if dayProfit >= iBEven and dayProfit >= maxProfit
maxProfit := dayProfit
stopBE = dayProfit <= (maxProfit - iBEDistance)
// Stop after x trades with positive or negative or whatever daily balance
stopX = (iSSTrades == "Positive or Negative" and filledOrders >= iSDXTrades) or (iSSTrades == "Positive" and filledOrders >= iSDXTrades and dayProfit > 0) or (iSSTrades == "Negative" and filledOrders >= iSDXTrades and dayProfit < 0)
dayStop = dayProfit >= iSDailyGain or dayProfit <= -iDailyLosslimit or stopBE or stopX
//Later in the code dayStop is used to block trading for the day
全球每日收益和每日损失都停止工作,但是如果x交易为负数或正数,则追踪止损和止损将不起作用。它会在x交易后停止,但不会考虑余额。
关于我做错什么的任何线索吗?我是派恩(Pine)的新手。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)