首页 > 解决方案 > 在 pine 脚本版本 2 中使用标志概念

问题描述

我必须使用 pine 脚本的版本 2,因为使用版本 4 的结果与版本 2 不同。我希望在脚本中使用标志的概念,即我希望一个变量在满足条件后立即取值 1在未满足退出条件时进行交易并保持 1。我正在尝试使用下面的代码

var putflag := 0 //declaring the flag for taking a short position

trend = cola == red ? 0 : 1

put = putflag ==0 and trend ==0 and (open > out1 or high >= floor(out1 - 5)) //conditions for taking the short position 
 
if put ==1
    putflag :=1 // the flag takes value at the first instance trade conditions are met and stays 1 till exit conditions are not met.***

但是这在版本 2 中没有执行,而在版本 4 中这很容易完成

标签: pine-scripttradingview-api

解决方案


推荐阅读