0

Hello everybody and thanks in advance.

I wrote this "script" (it is 5 lines long...) just to test the function "ta.highest" and it does not open any trade... and I can't figure out why.

//@version=5
strategy("La mia strategia", overlay=true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100  )

longCondition = close > ta.highest(high, 7)
closeCondition= close < ta.lowest(low, 7)
if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long)

if closeCondition
    strategy.close("My Long Entry Id")

Anybody can help? Thank you.

The condition is reached multiple times (a close which is higher than the previous 7-days highest high) but pinescript seems to not recognize it... or I misunderstand the logic of the function "ta.highest"?

G.Lebret
  • 2,826
  • 2
  • 16
  • 27
Alex
  • 1

1 Answers1

0

The condition can never be true because if the stock closes above the highest high of the last 7 days then it becomes the highest. You need to use the historical operator.

//@version=5 
strategy("La mia strategia", overlay=true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100 )

longCondition = close > ta.highest(high, 7)[1] 
closeCondition= close < ta.lowest(low, 7)[1]

if (longCondition) 
    strategy.entry("My Long Entry Id", strategy.long)

if closeCondition 
    strategy.close("My Long Entry Id")
smashapalooza
  • 932
  • 2
  • 2
  • 12