Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
//
// Details and background information on "PFCC - Pivot Fractal Chaos Channel" and
how to use this indicator can be found in the description of this indicator.
//
// The code is briefly commented. Please feel free to use or further customize
it ... And, of course, I would be happy to be named and/or linked.
// If you're satisfied, maybe buy me a coffee ;-)
//
// I'm curious to see how this indicator will develop with more ideas - Please keep
me updated by commenting below or by sending me a message.
//
// consilus @ https://www.tradingview.com/u/consilus/
//
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

//@version=4
study(title="PFCC - Pivot Fractal Chaos Channel (dv63o)", overlay=true,
max_bars_back=2000, max_labels_count=500)

// --------------------------------------------------
// Pivot Fractal Chaos Channel
// --------------------------------------------------
// Data to use / Returns:
// - PFCC_UpperBand_Value
// - PFCC_LowerBand_Value
// - PFCC_Signal_OrderDirection (-1, 0, 1) [<> 0 when price crosses the Pivot
Fractal Chaos Channel]
// - PFCC_Signal_Price2Channel (-1, 0, 1) [based on position of price to Pivot
Fractal Chaos Channel]
// --------------------------------------------------

// --------------------------------------------------
// Inputs
// --------------------------------------------------
PFCC_Set_LengthLeft = input(title="Pivot Length left side", defval=15, minval=1,
maxval=999, group="PFCC - Pivot Fractal Chaos Channel [by consilus]")
PFCC_Set_LengthRight = input(title="Pivot Length right side", defval=15, minval=1,
maxval=999, group="PFCC - Pivot Fractal Chaos Channel [by consilus]")

// --------------------------------------------------
// Calculation
// --------------------------------------------------
PFCC_High_Value = pivothigh(high, PFCC_Set_LengthLeft, PFCC_Set_LengthRight)
PFCC_Low_Value = pivotlow(low, PFCC_Set_LengthLeft, PFCC_Set_LengthRight)

PFCC_UpperBand_Value = 0.0
PFCC_UpperBand_Value := na(PFCC_High_Value) ? PFCC_UpperBand_Value[1] :
high[PFCC_Set_LengthRight]

PFCC_LowerBand_Value = 0.0
PFCC_LowerBand_Value := na(PFCC_Low_Value) ? PFCC_LowerBand_Value[1] :
low[PFCC_Set_LengthRight]

// --------------------------------------------------
// Signals
// --------------------------------------------------
PFCC_Signal_OrderDirection = (close <= PFCC_LowerBand_Value and open >=
PFCC_LowerBand_Value) ? -1 : (close >= PFCC_UpperBand_Value and open <=
PFCC_UpperBand_Value) ? 1 : 0

PFCC_Signal_Price2Channel = close <= PFCC_LowerBand_Value ? -1 : close >=


PFCC_UpperBand_Value ? 1 : 0

// --------------------------------------------------
// Plotting
// --------------------------------------------------
color_Bullish = color.new(#2196F3, 0)
color_Bearish = color.new(#FFEB3B, 0)
color_Neutral = color.new(#CCCCCC, 0)

color_Bullish_Light = color.new(#2196F3, 80)


color_Bearish_Light = color.new(#FFEB3B, 80)
color_Neutral_Light = color.new(#CCCCCC, 80)

color_PFCC_UpperBand = PFCC_Signal_Price2Channel > 0 ? color_Bullish :


PFCC_Signal_Price2Channel < 0 ? color_Bearish : color_Neutral
color_PFCC_LowerBand = PFCC_Signal_Price2Channel > 0 ? color_Bullish :
PFCC_Signal_Price2Channel < 0 ? color_Bearish : color_Neutral
color_PFCC_Background = PFCC_Signal_Price2Channel > 0 ? color_Bullish_Light :
PFCC_Signal_Price2Channel < 0 ? color_Bearish_Light : color_Neutral_Light
color_PFCC_BarColor = PFCC_Signal_OrderDirection > 0 ? color_Bullish :
PFCC_Signal_OrderDirection < 0 ? color_Bearish : na

// Channel as Steplines with Background


plot_PFCC_UpperBand = plot(PFCC_UpperBand_Value, color=color_PFCC_UpperBand,
linewidth=2, style=plot.style_stepline, offset=0, title="PFCC Upper Band (color
based on position of price to Pivot Fractal Chaos Channel)")

plot_PFCC_LowerBand = plot(PFCC_LowerBand_Value, color=color_PFCC_LowerBand,


linewidth=2, style=plot.style_stepline, offset=0, title="PFCC Lower Band (color
based on position of price to Pivot Fractal Chaos Channel)")

fill(plot_PFCC_UpperBand, plot_PFCC_LowerBand, title="PFCC Background (color based


on position of price to Pivot Fractal Chaos Channel)", color=color_PFCC_Background)

// Barcolor
barcolor(title="PFCC Barcolor (when price crosses the Pivot Fractal Chaos
Channel)", color=color_PFCC_BarColor)

// Triangles
plotshape(PFCC_Signal_OrderDirection > 0, title="PFCC CROSS UP",
style=shape.triangleup, location=location.abovebar, color=color_Bullish,
size=size.tiny)
plotshape(PFCC_Signal_OrderDirection < 0, title="PFCC CROSS DOWN",
style=shape.triangledown, location=location.abovebar, color=color_Bearish,
size=size.tiny)

// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
// ALERTS
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
setting_rule_alert = input("once per bar close", "The triggering frequency for
alerts", options=["once per bar close", "once per bar"], tooltip="To use alerts,
select 'Any alert() function call' in the 'Create Alert' dialog. If you change the
triggering frequency, create the alert from scratch to be on the safe side.",
group="Alerts")

var string alert_details = ""


if PFCC_Signal_OrderDirection > 0 or PFCC_Signal_OrderDirection < 0
alert_details := ""
alert_details := alert_details + "PFCC CROSS " + (PFCC_Signal_OrderDirection >
0 ? "UP" : PFCC_Signal_OrderDirection < 0 ? "DOWN" : "-") + "\n"
alert_details := alert_details + "\n" + "[Indicator: PFCC - Pivot Fractal Chaos
Channel [Open Source] (by consilus)]"

alert(tostring(alert_details), setting_rule_alert == "once per bar close" ?


alert.freq_once_per_bar_close : alert.freq_once_per_bar) //
alert.freq_once_per_bar_close

// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
// EOF
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

You might also like