CALobo

string2float v1.0

CALobo Aktualisiert   
In the v5 version of PineScript, casting a string to a float - float(x) - does not appear to work, in spite of the reference manual seemingly indicating that it should. The simplest test case that I could generate "float('4750.0')" would result in a "Cannot call 'float' with argument 'x'='4750.0'. An argument of 'literal string' type was used but a 'const float' is expected." Since I was pulling the floats from a string array, I could not find a way to make them into "const floats". So I gave up and wrote a quick and dirty string to float converter function that handles both positive and negative integers and floats and returns the a float. Hopefully it might save someone else an afternoon of insanity.... :-)
Versionshinweise:
It's been pointed out that I missed the str.tonumber() function in my quest to convert a string to a float.... The update version 2.0 of the script tests out this function - see line 62 where it changes the str2float() function call to the built in function str.tonumber(). I'm happy to say that the revision passes all the tests and that this script/function/library can now be retired. I've left the code here in case some else has a similar problem, or wants to see how the str.tonumber() function call might be implemented...
Open-source Skript

Ganz im Spirit von TradingView hat der Autor dieses Skripts es als Open-Source veröffentlicht, damit Trader es besser verstehen und überprüfen können. Herzlichen Glückwunsch an den Autor! Sie können es kostenlos verwenden, aber die Wiederverwendung dieses Codes in einer Veröffentlichung unterliegt den Hausregeln. Sie können es als Favoriten auswählen, um es in einem Chart zu verwenden.

Haftungsausschluss

Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.

Möchten Sie dieses Skript auf einem Chart verwenden?