0
votes

I have been working on an algorithm for pinescript and I am stuck with some logic relating to hypothetically entering the position.

First of all bullPlot and bearPlot are either true or false which is where the long and short signals are painted on the chart. Relating to my strategy, once a long/short signal is plotted you then wait for price to go beyond the close for long/short depending on red/green candle

How can I create a statement which checks if there is a signal on the previous candle, if true, plot a circle based on last close. This is merely to help with the manual trading side of the algorithm.

example of the chart/algo

example of entry dot

1

1 Answers

0
votes

You can create a series that holds your trigger result on each bar.
Then you can just reference the trigger value on the previous bar by using the [1] construct, and plot close[1] on the current bar.

When you don't want a value in a series plotted, you can make it plot the na value, like this:

signal_on_previous_candle ? previousClose : na

The ?: is a ternary operator, which is a shortend if-then-else statement.
The above code can also be written as

if signal_on_previous_candle
    previousClose
else
    na

I think this what you're looking for

//@version=4
study("bullPlot", overlay=true)

var bool signal_on_candle = false
signal_trigger_time = timestamp(year(timenow), month(timenow), dayofmonth(timenow), 11, 30, 0)

signal_triggered = time == signal_trigger_time

if signal_triggered
    signal_on_candle := true
else
    signal_on_candle := false

signal_on_previous_candle = signal_on_candle[1]

previousClose = close[1]

plot(signal_on_previous_candle ? previousClose : na, title="Dot",style=plot.style_circles, color=color.yellow, linewidth=5)

This code could be shorter, but it's for illustration purposes.