Files
xPineScript/xIndicators/x-saherelm.price.action.candle.recognition.pine
T
2024-01-25 04:07:49 +03:30

146 lines
4.4 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center XTrade XCRT_IND Indicator
// ---------------------------------------------
// Candle Recognition Types
//
// it is an indicator which going to find candle types
// and provides some usefull info based on them.
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
//@version=5
indicator(title="SaherElm X-Price Action Candle Recognition Indicator", shorttitle = "XS_PA_CR_IND", overlay = true)
//
// START Inputs ....
//
//
showCandleTypeLabel = input.bool(defval = false, title = "Show Recognized Candle Types Labels")
showCandleTypeTitlesAsTooltip = input.bool(defval = false, title = "Show Titles as Tooltip")
//
// Candle Type Recognition Rules ...
var candleItselfRule = "Candle itself"
var candleByItsNeighborhoodRule = "Candle and it's prev Neighborhood"
candleRecognitionRule = input.string(defval = candleItselfRule, title = "Candle Recognition Rule", options = [candleItselfRule, candleByItsNeighborhoodRule])
//
// END Inputs ....
//
//
// START Functions ....
//
//
// Retrieve Specific Candle Height (based on low and high) ...
getCandleRange() =>
high - low
//
// Retrieve Candle Ranges Thirs Section ...
getCandleThird() =>
getCandleRange() / 3
//
// Determines a Candle is Bullish or not ...
isBullishCandle() =>
close > low + (getCandleThird() * 2)
//
// Determines a Candle is Bearish or not ...
isNeutralCandle() =>
close < low + (getCandleThird() * 2) and close > low + getCandleThird()
//
// Determines a Candle is Neutral or not ...
isBearishCandle() =>
close < low + getCandleThird()
//
// END Functions ....
//
//
// START Calculations ....
//
//
var bullishColor = color.lime
var bullishShape = shape.arrowup
var bullishTitle = "Bullish"
var bullishType = 1
//
var bearishColor = color.red
var bearishShape = shape.arrowdown
var bearishTitle = "Bearish"
var bearishType = -1
//
var neutralColor = color.gray
var neutralShape = shape.circle
var neutralTitle = "Neutral"
var neutralType = 0
//
candleType = isBullishCandle() ? bullishType : isNeutralCandle() ? neutralType : isBearishCandle() ? bearishType : neutralType
//
prevCandleType = not na(candleType[1]) ? candleType[1] : neutralType
//
candleNeighborhoodBaseType = prevCandleType + candleType
candleNeighborhoodBaseTypeTitle = str.tostring(prevCandleType) + "," + str.tostring(candleType)
//
// END Calculations ....
//
//
// START Plots ....
//
//
// Plot Range inside of indicator title ...
// plot(getCandleRange(), color = color.orange, title = "Bar Ranges")
//
// Plot Range inside of indicator title ...
// plot(getCandleThird(), color = color.aqua, title = "Bar Thirds")
//
// Plot Candle State ...
//
// Candle Type ...
if showCandleTypeLabel and candleRecognitionRule == candleItselfRule
candleTypeLabelStyle = candleType > 0 ? label.style_label_up : candleType == 0 ? label.style_label_center : candleType < 0 ? label.style_label_down : na
candleTypeLabelColor = candleType > 0 ? bullishColor : candleType == 0 ? neutralColor : candleType < 0 ? bearishColor : na
candleTypeLabel = label.new(x = bar_index, y = low, yloc = yloc.belowbar, style = candleTypeLabelStyle, text = showCandleTypeTitlesAsTooltip ? na : str.tostring(candleType), color = candleTypeLabelColor, textcolor = color.white, tooltip = showCandleTypeTitlesAsTooltip ? str.tostring(candleType) : na)
//
// Candle Neighborhood Base Type ...
if showCandleTypeLabel and candleRecognitionRule == candleByItsNeighborhoodRule
candleTypeLabelStyle = candleNeighborhoodBaseType > 0 ? label.style_label_up : candleNeighborhoodBaseType == 0 ? label.style_label_center : candleNeighborhoodBaseType < 0 ? label.style_label_down : na
candleTypeLabelColor = candleNeighborhoodBaseType > 0 ? bullishColor : candleNeighborhoodBaseType == 0 ? neutralColor : candleNeighborhoodBaseType < 0 ? bearishColor : na
candleTypeLabel = label.new(x = bar_index, y = low, yloc = yloc.belowbar, style = candleTypeLabelStyle, text = showCandleTypeTitlesAsTooltip ? na : candleNeighborhoodBaseTypeTitle, color = candleTypeLabelColor, textcolor = color.white, tooltip = showCandleTypeTitlesAsTooltip ? candleNeighborhoodBaseTypeTitle : na)
//
// END Plots ....
//
//
// START Alerts ...
//
//
// END Alerts ...
//
//////////////////////////////////////////////////////
// TODOS:
// -------
// - []
//////////////////////////////////////////////////////