[pshaiCmd] Indicator Memory

0 335 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, 1 month ago by pshai.
    • This topic was modified 1 year, 1 month ago by pshai.
    • This topic was modified 1 month, 1 week ago by pshai. Reason: added variable warmup length, improved
    HaasScript Code
    Sign in or Register to download for free
  • Mandala Trading Competition Promotion Type: contest Expires: June 9, 2023 Exclusive
    Trading volume competition, win up to $10,000 USDT and bounties.
  • Earn Up to 200 BMEX Tokens Promotion Type: contest Expires: March 31, 2023
    15 BMEX @ $20,000, 25 BMEX @ $50,000, 50 [email protected] $200,000, 100 BMEX @ $400,000, 200 BMEX @ $600,000 in monthly derivatives volume
Login or Register to Comment

Unlock your crypto trading potential

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

Join for Free