[pshaiCmd] Indicator Breakdown

0 219 Views No Comments 6 months ago
  • Indicator Breakdown command with multiple outputs for detailed control.

    Inputs:
    – values: Main data series
    – middle: Middle level.
    – upper: Upper level.
    – lower: Lower level.
    – upperCrossLb: Defines how far back upper level cross-overs and -unders are still valid. Setting this to 1 means it’s only valid “now”.
    – lowerCrossLb: Defines how far back lower level cross-overs and -unders are still valid. Setting this to 1 means it’s only valid “now”.
    – middleCrossLb: Defines how far back middle level cross-overs and -unders are still valid. Setting this to 1 means it’s only valid “now”.
    – upwardsLb: Lookback value for upward movement definition. If set to 1: current value is compared to previous.
    – downwardsLb: Lookback value for downward movement definition. If set to 1: current value is compared to previous.

    Outputs:
    – results: The results object itself
    – IsAboveMid: True if current value is above middle level
    – IsInTheZone: True if current value is above lower and below upper level
    – IsAboveUpper: True if current value is above upper level
    – IsBelowLower: True if current value is below lower level
    – IsMovingUpwards: True if values moving upwards
    – IsMovingDownwards: True if values moving downwards
    – CrossOverUpper: True if current value crossed over upper level
    – CrossUnderUpper: True if current value crossed under upper level
    – CrossOverLower: True if current value crossed over lower level
    – CrossUnderLower: True if current value crossed under lower level
    – CrossOverMiddle: True if current value crossed over middle level
    – CrossUnderMiddle: True if current value crossed under middle level

    • This topic was modified 5 months, 4 weeks ago by pshai.
    • This topic was modified 5 months, 4 weeks ago by pshai.
    • This topic was modified 5 months, 4 weeks ago by pshai.
    HaasScript Code
    DefineCommand('IndicatorBreakdown', 'Indicator Breakdown command with multiple outputs for detailed control. Created by pshai.')
    
    -- Command inputs
        local values  = DefineParameter(ListNumberType, 'values', 'Main data series', true, ClosePrices(), 'Technical Analysis, Price Data, SessionGet')
        local middle   = DefineParameter(NumberType, 'middle', 'Middle level', true, 0, 'Input, Number, SessionGet')
        local upper   = DefineParameter(NumberType, 'upper', 'Upper level', true, 1, 'Input, Number, SessionGet')
        local lower   = DefineParameter(NumberType, 'lower', 'Lower level', true, -1, 'Input, Number, SessionGet')
        local upperCrossLb   = DefineParameter(NumberType, 'upperCrossLb', 'Defines how far back upper level cross-overs and -unders are still valid. Setting this to 1 means it's only valid "now".', false, 1, 'Input, Number, SessionGet')
        local lowerCrossLb   = DefineParameter(NumberType, 'lowerCrossLb', 'Defines how far back lower level cross-overs and -unders are still valid. Setting this to 1 means it's only valid "now".', false, 1, 'Input, Number, SessionGet')
        local middleCrossLb   = DefineParameter(NumberType, 'middleCrossLb', 'Defines how far back middle level cross-overs and -unders are still valid. Setting this to 1 means it's only valid "now".', false, 1, 'Input, Number, SessionGet')
        local upwardsLb   = DefineParameter(NumberType, 'upwardsLb', 'Lookback value for upward movement definition. If set to 1, current value is compared to previous.', false, 1, 'Input, Number, SessionGet')
        local downwardsLb   = DefineParameter(NumberType, 'downwardsLb', 'Lookback value for downward movement definition. If set to 1, current value is compared to previous.', false, 1, 'Input, Number, SessionGet')
    
    -- Data
        local results = {
            IsAboveMid = false,
            IsInTheZone = false,
            IsAboveUpper = false,
            IsBelowLower = false,
            IsMovingUpwards = false,
            IsMovingDownwards = false,
            CrossOverUpper = false,
            CrossUnderUpper = false,
            CrossOverLower = false,
            CrossUnderLower = false,
            CrossOverMiddle = false,
            CrossUnderMiddle = false,
        }
    
        if values > middle then results.IsAboveMid = true end
        if values <= upper and values >= lower then results.IsInTheZone = true end
        if values > upper then results.IsAboveUpper = true end
        if values < lower then results.IsBelowLower = true end
        if values[1] > values[upwardsLb+1] then results.IsMovingUpwards = true end
        if values[1] < values[downwardsLb+1] then results.IsMovingDownwards = true end
        if CrossOverSince(values, upper) <= upperCrossLb then results.CrossOverUpper = true end
        if CrossUnderSince(values, upper) <= upperCrossLb then results.CrossUnderUpper = true end
        if CrossOverSince(values, lower) <= lowerCrossLb then results.CrossOverLower = true end
        if CrossUnderSince(values, lower) <= lowerCrossLb then results.CrossUnderLower = true end
        if CrossOverSince(values, middle) <= middleCrossLb then results.CrossOverMiddle = true end
        if CrossUnderSince(values, middle) <= middleCrossLb then results.CrossUnderMiddle = true end
    
    DefineOutput(ListDynamicType, results, 'True/False values object.')
        DefineOutputIndex(1, BooleanType, 'IsAboveMid', 'True if current value is above middle level', 'IsTrue, IsFalse, Not, SessionSet')
        DefineOutputIndex(2, BooleanType, 'IsInTheZone', 'True if current value is above lower and below upper level', 'IsTrue, IsFalse, Not, SessionSet')
        DefineOutputIndex(3, BooleanType, 'IsAboveUpper', 'True if current value is above upper level', 'IsTrue, IsFalse, Not, SessionSet')
        DefineOutputIndex(4, BooleanType, 'IsBelowLower', 'True if current value is below lower level', 'IsTrue, IsFalse, Not, SessionSet')
        DefineOutputIndex(5, BooleanType, 'IsMovingUpwards', 'True if values moving upwards', 'IsTrue, IsFalse, Not, SessionSet')
        DefineOutputIndex(6, BooleanType, 'IsMovingDownwards', 'True if values moving downwards', 'IsTrue, IsFalse, Not, SessionSet')
        DefineOutputIndex(7, BooleanType, 'CrossOverUpper', 'True if current value crossed over upper level', 'IsTrue, IsFalse, Not, SessionSet')
        DefineOutputIndex(8, BooleanType, 'CrossUnderUpper', 'True if current value crossed under upper level', 'IsTrue, IsFalse, Not, SessionSet')
        DefineOutputIndex(9, BooleanType, 'CrossOverLower', 'True if current value crossed over lower level', 'IsTrue, IsFalse, Not, SessionSet')
        DefineOutputIndex(10, BooleanType, 'CrossUnderLower', 'True if current value crossed under lower level', 'IsTrue, IsFalse, Not, SessionSet')
        DefineOutputIndex(11, BooleanType, 'CrossOverMiddle', 'True if current value crossed over middle level', 'IsTrue, IsFalse, Not, SessionSet')
        DefineOutputIndex(12, BooleanType, 'CrossUnderMiddle', 'True if current value crossed under middle level', 'IsTrue, IsFalse, Not, SessionSet')
    
    
Login or Register to Comment

Unlock your crypto trading potential

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

Join for Free