CALobo

string2float v1.0

CALobo Mis à jour   
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.... :-)
Notes de version:
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...
Script open-source

Dans le véritable esprit de TradingView, l'auteur de ce script l'a publié en open-source, afin que les traders puissent le comprendre et le vérifier. Bravo à l'auteur! Vous pouvez l'utiliser gratuitement, mais la réutilisation de ce code dans une publication est régie par le règlement. Vous pouvez le mettre en favori pour l'utiliser sur un graphique.

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.

Vous voulez utiliser ce script sur un graphique ?