首页 > 解决方案 > 将策略转换为研究,停止金字塔式增长

问题描述

我是 Pine 的新手,我正在尝试将以下策略转换为研究:

//@version=4
strategy(title="test", default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=.0020, pyramiding=0, slippage=3, overlay=true)

ema8 = ema(close, 8)
ema13 = ema(close, 13)
ema55 = ema(close, 55)
longEmaCondition = ema8 > ema13
exitLongEmaCondition = ema13 < ema55

// STRATEGY //

longCondition = longEmaCondition and strategy.position_size == 0
exitLongCondition = exitLongEmaCondition and strategy.position_size > 0

if longCondition
    strategy.entry("LONG", strategy.long)
if exitLongCondition
    strategy.close("LONG")

这是我目前的尝试:

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

ema8 = ema(close, 8)
ema13 = ema(close, 13)
ema55 = ema(close, 55)
longEmaCondition = ema8 > ema13
exitLongEmaCondition = ema13 < ema55

// STRATEGY //

longCondition = longEmaCondition
exitLongCondition = exitLongEmaCondition

alertcondition(longCondition, title = "Entry Long")
alertcondition(exitLongCondition, title = "Exit Long")

plotshape(longCondition,text='LONG' ,color=color.green, location=location.abovebar,style=shape.arrowup)
plotshape(exitLongCondition, color=color.green,text='Close \n LONG', location=location.belowbar)

然而,当绘制上面的图时,有很多金字塔交易(见下面的图片链接)。我该如何阻止这个?我删除了strategy.position_size变量,因为我在研究脚本中找不到等效函数。这是导致金字塔的原因吗?

学习脚本中的金字塔

任何帮助将不胜感激。

标签: pine-script

解决方案


推荐阅读