TradingView
RicardoSantos
Mar 3, 2020 7:23 PM

[RS]Example: function instantiation 

U.S. Dollar / Russian RubleFOREX.com

Description

EXPERIMENTAL:
Practical example of how to create a shared function instance.
Comments
neillswap
Hello sir, i am working on one indicator...Where i would like to add if statement for every Ticker(Symbol)...
Without function i am not able to add more than 500 if statements because,
it gives error

:add to chart operation failed, reason: script has too many local scopes:521. the limit is 500

//@version=4
study("PineTest", "", true)
srcHi = 0.00
srcLo = 0.00
if syminfo.ticker == "AMZN"
srcHi:=2000.00
srcLo:=1670.00
if syminfo.ticker == "SPY"
srcHi:=300.00
srcLo:=210.00
if syminfo.ticker == "AAPL"
srcHi:=300.00
srcLo:=170.00
if syminfo.ticker == "MSFT"
srcHi:=210.00
srcLo:=50.00 `

diff = srcHi - srcLo
p1=plot(diff)

Will you please help me how to solve this problem with the help of function??Thanks in advance
syrinxflunki
Very useful, thanks !
idrisbengali
Masterful.... Thanks
Tom1trader
Thanks! Another nugget of good info - I jump in once in a while and find it easier every time due a lot to your sharing. Keep smiling!
CUBYC
You are a master of Pine and I believe if there is a solution you can see it from the start. I will leave an example in case I was not clear, an example of what i try to do:

//@version=4
TradeSymbol = input("BTC-x2", title = "🙏==Tip Simbol==🙏", options = ["BTC-x2", "FORMULA","OIL-x10","SIRVER-x10","GOLD-x20","UBER-x5","GERMANY30-x20"])
TradeComission= TradeSymbol == "BTC-x2" ? 0.05 : TradeSymbol == "FORMULA" ? 0.01 : TradeSymbol == "OIL-x10" ? 0.03 : TradeSymbol == "SIRVER-x10" ? 0.02 :
TradeSymbol == "GOLD-x20" ? 0.005 : TradeSymbol == "UBER-x5" ? 0.001 : TradeSymbol == "GERMANY30-x20" ? 0.003 : 0

strategy(
title="Cubyc",
overlay=false,
initial_capital=1000,
commission_type=strategy.commission.percent,
commission_value = TradeComission)

And tried many other ways still getting error and nothing is working.
Thanks
CUBYC
Hello mate, if you are kind to teach me something me something:
As you know different symbols have different commision on different exchanges and I was looking to make so presets/options values to be chosen from settings of my indicator
I`m struggling for days now and can not find the correct set-up. So in a strategy we have:
(commission_type=strategy.commission.percent, commission_value=0.075) from and tried so many different ways to change the commission_value... i believe that is not possible, commission_value is a (const float) .not an expert but is const means constant, meaning that can not be changed? So can you please enlighten me if is possible to make an" input" or some variable options to chose for that value?
Thank you
RicardoSantos
@CUBYC, thats correct, comission value cannot be changed
CUBYC
@RicardoSantos, We posted same time I believe, understood, thank you for your answer and great work, trying to learn tricks in Pine but is so difficult, you make things clear sometimes. Thanks again
More