引用先前退出价格的松本脚本录入策略

时间:2018-10-22 13:14:54

标签: trading algorithmic-trading tradingview-api pine-script

我正在尝试在电视中建立一种策略(仅限多头头寸),其中 strategy.entry 将考虑先前的退出价格。例如:

strategy.entry("long", strategy.long, when = longcondition==true)
strategy.close("long", strategy.close, when = longcondition==false)

除了longcondition == true外,我还要为strategy.entry插入另一个条件,该条件表示以下意图:

strategy.entry("long", strategy.long, when = longcondition==true and close[1] < previousExitPrice)

如何正确执行?预先感谢您的回答。

2 个答案:

答案 0 :(得分:0)

我不能说出您的多头头寸是什么,但是如果是市场卖出,您可以尝试使用if而不是when并设置退出价格和退出订单:

previousExitPrice = 0.0
previousExitPrice := nz(previousExitPrice[1]) //this will put the variable in memory

strategy.entry("long", strategy.long, when = longcondition==true and close[1] < previousExitPrice)

if longcondition==false
    strategy.close("long", strategy.close)
    previousExitPrice := close //in case of market sell

答案 1 :(得分:-1)

enterlong = 0;
if (longcondition == true and close[1] < previousExitPrice)
    enterlong := 1;

strategy.entry("long", strategy.long, when = enterlong)