# Example code to get the highest high in the last 14 bars

**URL:** <https://community.tradovate.com/t/example-code-to-get-the-highest-high-in-the-last-14-bars/3503>\
**Category:** Custom Indicators\
**Tags:** complete\
**Created:** [December 12, 2021, 12:16am UTC](https://community.tradovate.com/t/example-code-to-get-the-highest-high-in-the-last-14-bars/3503 "2021-12-12T00:16:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![diazlaz](https://avatars.discourse-cdn.com/v4/letter/d/f08c70/32.png) [@diazlaz](https://community.tradovate.com/u/diazlaz)\
**Post date:** [December 12, 2021, 12:16am UTC](https://community.tradovate.com/t/example-code-to-get-the-highest-high-in-the-last-14-bars/3503/1 "2021-12-12T00:16:45Z")

</div>

Hi Devs,

can you please help with an example on how i can save in a const/var the current highest high in the last 14 bars of the chart?

i tried to code using the MovingHigh function and was not successful.

thanks in advance,  
LD.

---

<div class="post-metadata">

**Author:** ![Alexander](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/alexander/32/988_2.png) [@Alexander](https://community.tradovate.com/u/Alexander)\
**Post date:** [December 13, 2021, 1:22pm UTC](https://community.tradovate.com/t/example-code-to-get-the-highest-high-in-the-last-14-bars/3503/2 "2021-12-13T13:22:01Z")

</div>

Hi @diazlaz,

Probably the easiest way to do this would be to create a little tool like this:

```auto
function Highs(period) {
    function highs(input) {
        return highs.push(input)
    }
    highs.push = function(input) {
        highs.state.values.push(input)
        //if we have more that period values...
        if(highs.state.values.length > period) {
           highs.state.values.shift() //...drop the last value in the set
        }
        //find highest value from set via reduce and Math.max
        return highs.state.values.reduce((a, b) => Math.max(a, b), 0)
    }

    highs.reset = () => highs.state = { values: [] }

    highs.reset()

    return highs
}

```

Then in your indicator code:

```auto
class HighsIndicator {
    init() { this.highs = Highs(this.props.period) }
   
    map(d) {
        return highs(d.value())
    }
}

//remember to add the period as user defined input
module.exports = {
    //...rest of indicator module omitted
    params: {
        period: predef.paramSpecs.period(14) //default to 14 bar period
    }
}

```

For more info on the specifics of Custom Indicators, see the [official docs](https://tradovate.github.io/custom-indicators/index.html).

---

<div class="post-metadata">

**Author:** ![diazlaz](https://avatars.discourse-cdn.com/v4/letter/d/f08c70/32.png) [@diazlaz](https://community.tradovate.com/u/diazlaz)\
**Post date:** [December 16, 2021, 7:55pm UTC](https://community.tradovate.com/t/example-code-to-get-the-highest-high-in-the-last-14-bars/3503/3 "2021-12-16T19:55:20Z")

</div>

thank you, Alexander, I appreciate the response.
