dusktrader
Pine Script Scholar
Pine Script Scholar
Posts: 32
Joined: February 24th, 2021
Contact: TradingView Profile

Access value from custom indicator in pinescript

Hello, I'm having a terrible time trying to solve this (seemingly simple?) issue. I want to access another indicator's value and make use of it in my pinescript.

The other indicator is a slightly modified version of Chop Zone. For example, I renamed it Chop30 and I forced the resolution to 30. I also updated the plot on the Chop30 so that it provides me the emaAngle value I need like this:

Code: Select all

plot(emaAngle, color=chopZoneColor, style=plot.style_columns)
From what I can tell, the Chop30 indicator is working correctly and I can see the value I want displayed on the screen when I hover over bars.

In my pinescript strategy, this is where I'm having difficulty accessing that value. For example I have done this:

Code: Select all

chop30 = input(title="Chop30", type=input.source, defval=close)
and it was my understanding that this would return the indicator's plot value.

However, the value I get when I try to plot that value is the "close" value of the bar, not the emaAngle value that I need. On my pinescript inputs, I see the Chop30 selector, but it only contains the hardcoded pinescript defaults (open, high, low, close, etc...)

I am still researching how to get this value, but any tips would be appreciated. Thanks!

kmarryat
Pine Script Rookie
Pine Script Rookie
Posts: 20
Joined: December 21st, 2020
Contact: TradingView Profile

Re: Access value from custom indicator in pinescript

In order for the External Indicator feature to work you can only have 1 input of the type input.source in your strategy/study that is trying to access the external value.

Are there any other inputs in your Pinescript strategy that are set as input.source?

An I'm pretty sure the plot statement needs a title.
plot(emaAngle, title="emaAngle", color=chopZoneColor, style=plot.style_columns)

dusktrader
Pine Script Scholar
Pine Script Scholar
Posts: 32
Joined: February 24th, 2021
Contact: TradingView Profile

Re: Access value from custom indicator in pinescript

Aha! this works. You are right, I was trying to use more than 1 input.source in my strategy pinescript.

So this is a new dilemma then. What I'm trying to do is use 3 variations of Chop Zone:
- Chop30 --> get the emaAngle when run on 30min timeframe
- Chop15 --> get the emaAngle when run on 15min timeframe
- Chop5 --> get the emaAngle when run on 5min timeframe

What I probably should do is incorporate the calculations directly into my pinescript strategy, so that I don't have to rely on an external indicator. But I don't know how to do this for multi-timeframe yet. So that's why I just add the indicator and set the resolution so they each calculate the timeframe I want.

Is there another way to access the values of these 3 different Chop indicators, or do I need to merge that code directly into my pinescript?

Thanks

kmarryat
Pine Script Rookie
Pine Script Rookie
Posts: 20
Joined: December 21st, 2020
Contact: TradingView Profile

Re: Access value from custom indicator in pinescript

You can only access 1 external plot value.

I have developed a process for accessing multiple signal values from an external indicator by doing the calculations in the external script. Then convert the individual signals into a single decimal value that I plot. Then convert the decimal value back to multiple binary values in the receiving script.

You can check out a sample here: viewtopic.php?f=21&t=142

Hope it helps. Good Luck!

dusktrader
Pine Script Scholar
Pine Script Scholar
Posts: 32
Joined: February 24th, 2021
Contact: TradingView Profile

Re: Access value from custom indicator in pinescript

This is awesome -- thanks!! I can definitely follow this pattern I think. So the limitation is on TV itself, it can only access values from a single external indicator (please correct me if that's wrong).

I like your idea a lot... so basically put all the calculations into an indicator, then pass them into the strategy in this "serialized" way, then unpack inside the strategy.

I think this can work. Basically on the multi-timeframe, I just want the indicators to all agree. If they don't all agree, then it violates an entry rule. So really I just need to figure out how to compute the 3 timeframes inside of a single indicator, then link to that to get the boolean values (or in my case could just be a single value -- yes they all agree - or no they don't)

kmarryat
Pine Script Rookie
Pine Script Rookie
Posts: 20
Joined: December 21st, 2020
Contact: TradingView Profile

Re: Access value from custom indicator in pinescript

TV can only access 1 external plot from 1 external indicator at a time. You can use your 1 source input to switch from one external indicator/plot to another, but only one at a time. Since you can only have 1 source input, you can only look at 1 indicator/plot at a time.

That's why I went with the serialized approach. I wanted my strategy to be able to respond to multiple conditions without having to manually change the indicator input settings for each one.

dusktrader
Pine Script Scholar
Pine Script Scholar
Posts: 32
Joined: February 24th, 2021
Contact: TradingView Profile

Re: Access value from custom indicator in pinescript

Hey I have one more newb question on this. I was able to adjust the ChopZone to calculate properly with multi-timeframe now. This means I can look at all 3 timeframes inside this indicator and generate a single signal plot. I am currently plotting a 1 for long signal and -1 for short signal.

All of this is connecting and working great on my study, but it requires me to first click on the chart and link to that ChopZone plot output. How can I make this work with Strategy Tester? By default the input is using "close". Is there a way to make Strategy Tester look at this custom indicator's signal plot?

Thanks

dusktrader
Pine Script Scholar
Pine Script Scholar
Posts: 32
Joined: February 24th, 2021
Contact: TradingView Profile

Re: Access value from custom indicator in pinescript

So I found a workaround for this. Since I'm still a newb, my scripts are very simple. In this case, I was able to easily move the ChopZone function I wrote directly into my strategy script. So now I no longer need to connect to an external indicator.

But I'd still like to know if it's possible to use Strategy Tester when an external indicator plot is required (or if its not possible yet).

Thank you again for all your help! I have spent so many hours manually wading through signals to see if this strategy works. It will go sooooo much faster if I can just do it in code!!

Return to “Pine Script Q&A”