binary “buy/sell” indicator results display: convenience or further processing
Forums › ProRealTime English forum › ProBuilder support › binary “buy/sell” indicator results display: convenience or further processing
- This topic has 2 replies, 2 voices, and was last updated 9 months ago by tomse.
-
-
02/25/2024 at 1:54 PM #228711
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.
binary12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849// ------------------------------// 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, bullishEMAslopeSwitch = 1ELSEIF (EMAslope < -EMAslopetreshold) THEN // lower range, bearishEMAslopeSwitch = -1ELSEEMAslopeSwitch = 0 // medium range, neutralENDIFENDIF//// --- Colour management -----//IF EMAslopeSwitch > 0 THENg = 255r = 0ELSEIF EMAslopeSwitch = 0 THENg = 50r = 50ELSEIF EMAslopeSwitch < 0 THENg = 0r = 255ENDIFENDIFENDIF//RETURN EMAslopeSwitch coloured(r, g, 10) AS "EMA Slope Switch 240225", 0//Hope that helps you with your programming – have fun!
tomse
1 user thanked author for this post.
02/25/2024 at 3:55 PM #228724Hi 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])
1 user thanked author for this post.
02/29/2024 at 8:42 AM #228962Hi 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
1 user thanked author for this post.
-
AuthorPosts