风险管理:如果已经做多,则不要下新订单 [英] Risk Management: If already long then do not place new order

查看:41
本文介绍了风险管理:如果已经做多,则不要下新订单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果标志已经指示 long,则不应有新标志指示 long.如果标志不表示长计算表达式

If the flag is already indicating long, there should not be a new flag indicating long. If flag does not indicate long evaluate the expression

longCondition = if (strategy.long) ? false: (rsi<30) and (close>moving_avg)

shortCondition = if (strategy.short) ? false: (rsi>70) and (close<moving_avg)

处理脚本...

第 30 行:不匹配的输入shortCondition"期待行尾"没有续行'

line 30: mismatched input 'shortCondition' expecting 'end of line without line continuation'

推荐答案

我认为这是一个指标而不是策略.因为您可以使用 pyramiding 参数在策略中配置要在同一方向上拥有多少条目.默认为 0,所以如果这是一个策略并且您没有更改金字塔参数,那应该没有问题.

I assume this is an indicator and not a strategy. Because you can configure how many entries you want to have in the same direction in a strategy with the pyramiding parameter. Default is 0, so if this is a strategy and you haven't changed the pyramiding parameter, it shouldn't be a problem.

对于指标,您可以使用这样的变量:

For indicators, you can use a variable like this:

//@version=4
study("My Script", overlay=true)

var isLong = false
var isShort = false

rsi = rsi(close, 14)
moving_avg = ema(close, 9)

buySignal = not isLong and (rsi<50) and (close>moving_avg)    // Buy only if we are not already long
sellSignal = not isShort and (rsi>50) and (close<moving_avg)  // Sell only if we are not already short

if buySignal
    isLong := true
    isShort := false

if sellSignal
    isLong := false
    isShort := true

plotshape(series=buySignal, title="BUY", text="BUY", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(series=sellSignal, title="SELL", text="SELL", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)

这篇关于风险管理:如果已经做多,则不要下新订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆