Pine Script(TradingView)条件语句转C#的正确性验证
关于Pine Script条件语句转C#代码的正确性验证
我无法理解这段TradingView的Pine Script条件语句:
if isHighLast ? price > pLast : price < pLast // Command else // Command
我写了对应的C#等效代码,想请教这段代码是否正确:
if(isHighLast == true) { if(price > pLast) // Command } else { if(price < pLast) // Command }
你的C#代码逻辑是正确的。
原Pine Script的核心逻辑是:将三元表达式的结果作为if的判断条件——
- 当
isHighLast为真时,判断price > pLast是否成立:成立则执行if块命令,否则执行else块命令 - 当
isHighLast为假时,判断price < pLast是否成立:成立则执行if块命令,否则执行else块命令
你的C#代码通过外层if-else拆分isHighLast的两种情况,再分别判断对应的价格条件,完全还原了原逻辑,结构和执行结果与Pine Script代码一致。
内容的提问来源于stack exchange,提问作者Masoud
相关产品推荐
相关产品推荐

