[pshaiCmd] Indicator Memory

0 815 Views No Comments 2 years ago
  • A memory for custom indicator calculations and other things that might cause “repaint of history”.

    A good example of this “repaint” issue would be when you calculate EMA(c, 20) on “this” update, and EMA(c, 10) on the next (i.e. variable period length). So to overcome this issue with changing history, this command lets you do this:

    -- Load prices
    local o = OpenPrices()
    local h = HighPrices()
    -- Calculate EMA using Adaptive Period length
    local ema = CC_OptimalIndicator(
        -- memory is not used in this calculation, as we do not use previous values for our calculations
        function(i, memory)
            local c = c[i]
            local o = o[i]
            local period = CC_AdaptivePeriod(o, c, 3, 20, 5, 20)
            return ArrayGet(EMA(c, period), 1)

    So the command takes in a callback function, and it is called with an input for an index (which is used for the offset step in warmup period).

    You can also do calculations that require the previously calculated values to be known by accessing the second input parameter in your callback function (named “memory” in the example above).

    Adaptive period command: https://www.haasscripts.com/t/pshaicmd-adaptive-period-length/

    HaasScript Code
    Sign in or Register to download for free
  • Phemex x HaasOnline Promotion Type: contest Expires: May 31, 2024 Exclusive
    Receive up to 1,200 USDT! The more you trade, the more you earn.
Login or Register to Comment

Unlock your crypto trading potential

Create a free account and enjoy everything we have to offer.

Join for Free