EveryDayBetter
Pine Script Master
Pine Script Master
Posts: 27
Joined: February 16th, 2022

How it is possible to define the All Time High as another Buy Condition?

How it is possible to define it as another Buy Condition, when I wanna say, that the stock should be not more than 10 percent under the All Time High?

processingclouds
Pine Script Master
Pine Script Master
Posts: 115
Joined: January 30th, 2022

Re: How it is possible to define the All Time High as another Buy Condition?

It would be something like this :

Code: Select all

 
var float ATH= 0.0
var float under10 = na
ATH := math.max(high, ATH)
under10 := ATH * 0.90

isLong = yourCondition and close > under10

EveryDayBetter
Pine Script Master
Pine Script Master
Posts: 27
Joined: February 16th, 2022

Re: How it is possible to define the All Time High as another Buy Condition?

It works very well, thank you so much.

Return to “Pine Script Q&A”