简体   繁体   中英

Combining two indicator to one

I'm trying to combine 2 indicator to one.

The first one is a really simple one I made my self. It's 2 different ema built into one indicator. The second I would like to integrate is the "multi time frame EMA".

At the end, I want my indicator to display 2 ema normally and I want a 3rd one that will be a 50 period ema displaying the h1 time frame. For exemple: on the 15 minutes charts, I will have ema1 = ema 20, ema2 = ema 50, ema 3 = ema 50 from the 1h time frame.

I am in my first baby step as a "pine script coder" and I didn't find how to do it by my self.

My multiple indicator script:

indicator('EMA', overlay=true)
ema1 = ta.ema(close, length=input(title='ema1', defval=50))
plot(ema1, title='ema1', color=#f80000)
ema2 = ta.ema(close, length=input(title='ema2', defval=200))
plot(ema2, title='ema3', color=#000000)

The one I would like to add:

study("Multi Time Frame Exponential Moving Average", "MTF EMA", overlay=true)
ma_len = input(title="Length", type=integer, defval=100)
src = input(title="Source", type=source, defval=close)
ma_offset = input(title="Offset", type=integer, defval=0)
res = input(title="Resolution", type=resolution, defval="240")
htf_ma = ema(src, ma_len)
out = security(tickerid, res, htf_ma)
plot(out, color=red, offset=ma_offset) 

If you want to merge two script, make sure that they have the same pinescript version.

Your first script is written in v5 and your second script seems to be written in v1 or v2 or v3 .

If you don't have a version identifier, just add //@version=3 to top of your script and either convert it to v5 manually or use the auto converter tool.

Use the Migration Guideline when you need support.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM