[英]Stochastic pine script stratygy
Hi all hope ur doing well,大家好,希望你们做得好,
I'm trying to code a strategy that go long when k is in the overbought area and crossed d and the opposite for shorting我正在尝试编写一个策略,当 k 处于超买区域并越过 d 时做多,而做空则相反
But I'm new to this and I don't now how to write the long entry if the cross happen in the overbought area.但我是新手,如果交叉发生在超买区域,我现在不知道如何写多头入场。
Thanks all,谢谢大家,
I have coded the following to get strategy results that go long when k is in the overbought area and crossed d and the opposite for shorting.我编写了以下代码,以获得当 k 处于超买区域并越过 d 时做多的策略结果,反之则做空。 More details added within the code comment.
在代码注释中添加了更多详细信息。
//@version=5
strategy("Stochastic Strategy", overlay=true)
//Stochastic Inputs
length = input.int(14, minval=1)
OverBought = input(80)
OverSold = input(20)
smoothK = 3
smoothD = 3
k = ta.sma(ta.stoch(close, high, low, length), smoothK)
d = ta.sma(k, smoothD)
//Rule to define crossover /crossunder
co = ta.crossover(k,d)
cu = ta.crossunder(k,d)
if (not na(k) and not na(d))
//code to define if k is in overbought zone and k crossover d and enter a long trade
if (co and k < OverSold)
strategy.entry("StochLE", strategy.long, comment="StochLE")
//code to define if k is in oversold zone and k crossunder d and enters a short trade
if (cu and k > OverBought)
strategy.entry("StochSE", strategy.short, comment="StochSE")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.