jacob frothschild
jacob frothschild

Reputation: 1

Convert Think script (within x bars) to pine script

Im trying to convert Think script to pine script.

Here is the Think Script i am wanting to convert...

      High crosses above Highest("data" = HIGH, "length" = 240)[1] within 60 bars

I want to know how to convert the "within 60 bars" part for pine script.

What i want to achieve in pine script is...

      x condition has happened within last x bars

      or

      Condition "within 60 bars"

Upvotes: 0

Views: 136

Answers (1)

mr_statler
mr_statler

Reputation: 2161

You can count the number of bars since the last time a condition was true using the ta.barssince() function and then compare it to 60:

counter = ta.barssince(yourCondition)
if counter < 60
    // do something

Upvotes: 0

Related Questions