Home > database >  Pine Script V5 - displaying results of a formula as text
Pine Script V5 - displaying results of a formula as text

Time:02-17

I am extremely new to Pinescript and writing my first indicator. As I scalp on a low timeframe I figured it would be a good idea to display profit targets, stop loss, and order volume in text when given a signal to make inputting the orders easier. This is proving to be a challenge however as I can't find any good info for V5 (the tostring() gives an "Could not find function or function reference 'tostring'" error when used).

Here is an example of what I am trying to do, have already displayed them as lines. Profit targets (1x, 1.5x, 2x, and 3x) with a 0.5 pip stop shown as lines. Last line is an arbitrary volume calculation based on my own risk if going long (risk/SL).

line.new(x1=bar_index[1], y1=lowestlevel - 0.00005, x2=bar_index   1, y2=lowestlevel - 0.00005)
line.new(x1=bar_index[1], y1=close   (close - (lowestlevel - 0.00005)) * 3, x2=bar_index   1, y2=close   (close - (lowestlevel - 0.00005)) * 3, color=color.lime)
line.new(x1=bar_index[1], y1=close   (close - (lowestlevel - 0.00005)) * 2, x2=bar_index   1, y2=close   (close - (lowestlevel - 0.00005)) * 2, color=color.green)
line.new(x1=bar_index[1], y1=close   (close - (lowestlevel - 0.00005)) * 1.5, x2=bar_index   1, y2=close   (close - (lowestlevel - 0.00005)) * 1.5, color=color.aqua)
line.new(x1=bar_index[1], y1=close   (close - (lowestlevel - 0.00005)) * 1, x2=bar_index   1, y2=close   (close - (lowestlevel - 0.00005)) * 1, color=color.white)
ordervolume = math.floor(500/(close-(lowestlevel - 0.00005)))

If someone can please assist with adding the results of the above as text below the entry candle I would greatly appreciate it. Alternatively adding the results below the relative lines would be nice, but not necessarily required.

Error I am getting as an example (although not sure how to format anyway:

enter image description here

enter image description here

CodePudding user response:

Well, that is because the function is called str.tostring() and not tostring().

//@version=5
indicator("My script", overlay=true)

var label label1 = na

if (barstate.islast)
    label1 := label.new(bar_index, high, text=str.tostring(math.floor(500 / close)))

enter image description here

  • Related