首页 > 解决方案 > EMA 200 的买卖条件

问题描述

我在策略中针对以下条件写的内容:1)如果价格高于 200 EMA,请不要做空 2)如果价格低于 200 EMA,请不要做多 ----- 策略的哪个点这些条件应该写吗?

标签: pine-script

解决方案


strategy("200ema", overlay=true)  

ema1=ema(close,1)
ema2=ema(close,200)

buy= crossover(ema1,ema2)
sell=crossunder(ema1,ema2)

if (buy)
    strategy.entry("Buy", strategy.long)
    
if (sell)
    strategy.entry("Sell", strategy.short) 
     

这是一个简单的脚本,当 ema1 与 ema2 交叉时将显示买入/卖出。

如果您想做类似“价格必须高于 200 才能触发买入,低于 200 才能触发卖出”之类的操作

只需添加这个

strategy("200ema", overlay=true)  

ema1=ema(close,1)
ema2=ema(close,200)

bf=ema1>ema2
sf=ema1<ema2
buy= (your strategy) and bf
sell=(your strategy) and sf

if (buy)
    strategy.entry("Buy", strategy.long)

if (sell)
    strategy.entry("Sell", strategy.short) 

推荐阅读