NightShark: How to convert text to Numbers using toNumber()

NightShark: How to convert text to Numbers using toNumber()

Introduction

In the realm of algo-trading, data is king. But what good is data if it can't be understood or acted upon by your trading algorithms? Enter NightShark's toNumber() function, a simple yet powerful tool that converts screen-captured metrics into actionable numerical data. This blog post aims to shed light on this essential function and how it can elevate your automated trading strategies.

What is toNumber()?

The toNumber() function in NightShark serves as a data converter. It takes the metrics captured from the areas you've defined on your trading platform and converts them into numerical values. This conversion is crucial for making logical comparisons and decisions within your trading algorithms.

Why toNumber() Matters

In algo-trading, decisions are often made based on numerical thresholds or conditions. For instance, you might want to buy a stock when its price rises above a certain level or sell it when it falls below another. The toNumber() function allows you to convert real-time metrics into numerical data, which can then be used to trigger these conditional actions.

How to Use toNumber()

Using toNumber() is straightforward. Typically, it's used in conjunction with the read_areas() function to continuously monitor specific metrics. Here's a simplified example:

loop {
  read_areas()
  if (toNumber(area[1]) > 20) {
    Click(point.a)  // Executes a Buy order
  } else if (toNumber(area[1]) < -10) {
    Click(point.b)  // Executes a Sell order
  }
  Sleep 1000  // Pauses for 1 second before the next iteration
}

In this example, read_areas() captures the metrics from a predefined area (let's say, the stock price). The toNumber() function then converts this metric into a numerical value, which is used to make trading decisions. If the stock price goes above 20, a Buy order is executed by clicking a predefined point (point.a). If it falls below -10, a Sell order is executed by clicking another point (point.b).

The Synergy with Other Functions

The toNumber() function is most effective when used in tandem with other NightShark functions like read_areas() for capturing metrics and Click() for executing actions. This trio of functions creates a powerful automated trading system that can monitor, decide, and act in real-time, giving you an edge in the fast-paced trading environment.

Conclusion

The toNumber() function in NightShark is a small but vital cog in the machine of automated trading. By converting screen-captured metrics into actionable numerical data, it enables your algorithms to make informed, timely decisions. With toNumber(), you're not just capturing data; you're empowering your trading strategies.

Happy Trading!