[pshaiCmd] Indicator Memory

0 451 Views No Comments 1 year 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)
        end
    )
    

    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/

    • This topic was modified 1 year, 5 months ago by pshai.
    • This topic was modified 1 year, 5 months ago by pshai.
    • This topic was modified 5 months, 2 weeks ago by pshai. Reason: added variable warmup length, improved
    HaasScript Code
    Sign in or Register to download for free
  • Earn Up to 2,000 $BMEX Tokens Promotion Type: contest Expires: July 31, 2023 Exclusive
    Fire up your trade bots and earn up to 2,000 $BMEX, $BTC, free subscriptions, and more.
Login or Register to Comment

Unlock your crypto trading potential

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

Join for Free