1
votes

I want to indicate historical trades in tradingview charts via a script based on information on time and price for entry and close.

My best idea is to search through "time" to find matches for entry and close, and then change the background color according to short or long position or draw a horizontal line. However, this seems not optimal. Any suggestions?

1

1 Answers

1
votes

I'd implement that in the next way:

//@version=3
strategy("Background changing", overlay=true)

NONE = 0
LONG = 1000
SHORT = -1000

position = NONE
position := nz(position[1], NONE)

longCondition = crossover(sma(close, 14), sma(close, 28))
if (longCondition)
    strategy.entry("LongEntryId", strategy.long)
    position := LONG


if (close < high[1])
    strategy.close("LongEntryId")
    position := NONE


getColor(state) =>
    state == LONG ? green :
  state == SHORT ? red :
  white


bgcolor(color=getColor(position))

Or you can put arrows to the chart:

//@version=3
study("My Script", overlay=true)

order = 0
if time >= timestamp(2018, 1, 10, 0, 0)
    order := 1
if time == timestamp(2018, 1, 17, 0, 0)
    order := -1
plotarrow(order)