binary “buy/sell” indicator results display: convenience or further processing

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #228711 quote
    tomse
    Participant
    New

    Dear all,

    as I find this forum really helpful when starting with programming indicators, I´d like to contribute something in return.

    When diving into the logics of an indicator, I quickly found it would be helpful to have a simplified, binary “buy/sell” or “on/off” display of my indicator results, either for convenience in the (visual) cart display or if I wanted to combine the results of different indicators to receive a consolidated result – which may even be used to feed a stock screener based on my defined criteria.

    The result is displayed as a line marked either green (= +1) or white (= 0) or red (= -1). This is visually simple and also may be used as input for a sum of n indicators to receive a final rating, combining different indicators 🙂

    This example is a simple indicator if the EMA slope is steep (positive or negative) or if it is within the noise (to shallow).  The 2 variables need to be defined in the variables menu. The colouring of the plot needs to be adjusted in the settings menu for the indicator colour to paint the areas between zero and indicator line either green or red.

    // ------------------------------
    // EMA Slope Switch Demo
    // Author: tomse
    // Task1: Is EMA slope significant or to shallow (noise)
    // Task2: Is EMA slope bullish / neutral / bearish ?
    // Output: 1 / 0 / -1
    // -----------------------------------------
    //
    defparam calculateonlastbars = 500 // static number of lookback candles (to save calculation time/computing power)
    //
    // -----EMA part-------------------------------
    //
    // Variable: EMAperiod = 20
    // Variable: EMAslopetreshold , type = integer , default = 0.5
    //
    EMAxx = Exponentialaverage[EMAperiod](close)
    EMAslope = (EMAxx - EMAxx[1]) / EMAxx[1] * 100 // --> (ma-value (current) - ma-value (previous period)) / ma-value(previous period) * 100
    //
    // ---- Switch -----
    //
    If (EMAslope > EMAslopetreshold) THEN // upper range, bullish
    EMAslopeSwitch = 1
    ELSE
    IF (EMAslope < -EMAslopetreshold) THEN // lower range, bearish
    EMAslopeSwitch = -1
    ELSE
    EMAslopeSwitch = 0 // medium range, neutral
    ENDIF
    ENDIF
    //
    // --- Colour management -----
    //
    IF EMAslopeSwitch > 0 THEN
    g = 255
    r = 0
    ELSE
    IF EMAslopeSwitch = 0 THEN
    g = 50
    r = 50
    ELSE
    IF EMAslopeSwitch < 0 THEN
    g = 0
    r = 255
    ENDIF
    ENDIF
    ENDIF
    //
    RETURN EMAslopeSwitch coloured(r, g, 10) AS "EMA Slope Switch 240225", 0
    //

     

    Hope that helps you with your programming – have fun!

    tomse

    robertogozzi thanked this post
    #228724 quote
    JS
    Participant
    Senior

    Hi tomse,

    Thanks for sharing.

    Note: in your indicator you do not calculate the slope of the EMA but the percentage difference between the current and the previous value of the EMA.

    (Slope=EMA-EMA[1])

    tomse thanked this post
    #228962 quote
    tomse
    Participant
    New
    Hi JS, great comment, true ! I am referring to the slope as a “measure for steepness” in terms of delta(Y) / delta(X) . As the delta of the time period (delta(X)) is 1, it will look like what you wrote above. This value is absolute and will change with the price of the stock. But I prefer to have relative values, to make different stocks kind of comparable. So the additional division with EMA[1]. I multiplied it with 100 to receive the % value, which in more common language often referred as “slope”, so I will need to deal with less decimal places 🙂 Best regards
    JS thanked this post
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

binary “buy/sell” indicator results display: convenience or further processing


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
tomse @tomse Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by tomse
1 year, 11 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 02/25/2024
Status: Active
Attachments: 2 files
Logo Logo
Loading...