0% found this document useful (0 votes)
3 views

Colored Pivot With Colored Ema Mobile

This Pine Script™ code implements a trading indicator called 'COLORED PIVOT WITH EMA' that overlays colored pivot points and an Exponential Moving Average (EMA) on price charts. Users can customize the EMA length, pivot types, and display options for pivot levels and labels. The script includes logic for calculating and drawing pivot points based on various timeframes and user inputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Colored Pivot With Colored Ema Mobile

This Pine Script™ code implements a trading indicator called 'COLORED PIVOT WITH EMA' that overlays colored pivot points and an Exponential Moving Average (EMA) on price charts. Users can customize the EMA length, pivot types, and display options for pivot levels and labels. The script includes logic for calculating and drawing pivot points based on various timeframes and user inputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.

0
at https://mozilla.org/MPL/2.0/
// © KULDEEP157

//@version=6
indicator("COLORED PIVOT WITH EMA", "COLORED PIVOT WITH EMA", overlay=true,
max_lines_count=500, max_labels_count=500)

// Input for EMA length


ema_length = input.int(13, title="EMA Length", minval=1, maxval=500)

// Calculate EMA
ema_value = ta.ema(close, ema_length)

// EMA color
ema_color = ema_value > ema_value[1] ? color.new(#00FF08, 0) : color.new(#FF0000,
0)

// Plot EMA
plot(ema_value, color=ema_color, title="EMA", linewidth=2)

// Pivot Points Inputs


pivotTypeInput = input.string(title="Type", defval="Traditional",
options=["Traditional", "Fibonacci", "Woodie", "Classic", "DM", "Camarilla"])
pivotAnchorInput = input.string(title="Pivots Timeframe", defval="Auto",
options=["Auto", "Daily", "Weekly", "Monthly", "Quarterly", "Yearly", "Biyearly",
"Triyearly", "Quinquennially", "Decennially"])
maxHistoricalPivotsInput = input.int(title="Number of Pivots Back", defval=1,
minval=1, maxval=200)
isDailyBasedInput = input.bool(title="Use Daily-based Values", defval=true,
tooltip="When unchecked, uses intraday data for intraday charts.")
showLabelsInput = input.bool(title="Show Labels", defval=true, group="labels")
showPricesInput = input.bool(title="Show Prices", defval=true, group="labels")
positionLabelsInput = input.string("Left", "Labels Position", options=["Left",
"Right"], group="labels")
linewidthInput = input.int(title="Line Width", defval=1, minval=1, maxval=100,
group="levels")

// Colors and Visibility for Pivot


pColor = color.new(#000000, 0)
rColor = color.new(#FF0000, 0)
sColor = color.new(#00FF08, 0)

pShowInput = input.bool(true, "Show P", inline="P", group="levels")


r1ShowInput = input.bool(true, "Show R1", inline="R1", group="levels")
s1ShowInput = input.bool(true, "Show S1", inline="S1", group="levels")
r2ShowInput = input.bool(true, "Show R2", inline="R2", group="levels")
s2ShowInput = input.bool(true, "Show S2", inline="S2", group="levels")
r3ShowInput = input.bool(true, "Show R3", inline="R3", group="levels")
s3ShowInput = input.bool(true, "Show S3", inline="S3", group="levels")

// Define Graphic Settings


type graphicSettings
string levelName
color levelColor
bool showLevel

var graphicSettingsArray = array.from(


graphicSettings.new(" P", pColor, pShowInput),
graphicSettings.new("R1", rColor, r1ShowInput),
graphicSettings.new("S1", sColor, s1ShowInput),
graphicSettings.new("R2", rColor, r2ShowInput),
graphicSettings.new("S2", sColor, s2ShowInput),
graphicSettings.new("R3", rColor, r3ShowInput),
graphicSettings.new("S3", sColor, s3ShowInput))

// Auto Anchor Logic


autoAnchor = switch
timeframe.isintraday => timeframe.multiplier <= 15 ? "1D" : "1W"
timeframe.isdaily => "1M"
=> "12M"

pivotTimeframe = switch pivotAnchorInput


"Auto" => autoAnchor
"Daily" => "1D"
"Weekly" => "1W"
"Monthly" => "1M"
"Quarterly" => "3M"
=> "12M"

pivotYearMultiplier = switch pivotAnchorInput


"Biyearly" => 2
"Triyearly" => 3
"Quinquennially" => 5
"Decennially" => 10
=> 1

// Number of Pivot Levels Adjusted


numOfPivotLevels = switch pivotTypeInput
"Traditional" => 7
"Camarilla" => 7
"Woodie" => 7
"Classic" => 7
"Fibonacci" => 7
"DM" => 3

type pivotGraphic
line pivotLine
label pivotLabel

method delete(pivotGraphic graphic) =>


graphic.pivotLine.delete()
graphic.pivotLabel.delete()

var drawnGraphics = matrix.new<pivotGraphic>()

localPivotTimeframeChange = timeframe.change(pivotTimeframe) and year %


pivotYearMultiplier == 0
securityPivotTimeframeChange = timeframe.change(timeframe.period) and year %
pivotYearMultiplier == 0

pivotTimeframeChangeCounter(condition) =>
var count = 0
if condition and bar_index > 0
count += 1
count

localPivots = ta.pivot_point_levels(pivotTypeInput, localPivotTimeframeChange)


securityPivotPointsArray = ta.pivot_point_levels(pivotTypeInput,
securityPivotTimeframeChange)

securityTimeframe = timeframe.isintraday ? "1D" : timeframe.period


[securityPivots, securityPivotCounter] = request.security(syminfo.tickerid,
pivotTimeframe, [securityPivotPointsArray,
pivotTimeframeChangeCounter(securityPivotTimeframeChange)], lookahead =
barmerge.lookahead_on)
pivotPointsArray = isDailyBasedInput ? securityPivots : localPivots

affixOldPivots(endTime) =>
if drawnGraphics.rows() > 0
lastGraphics = drawnGraphics.row(drawnGraphics.rows() - 1)
for graphic in lastGraphics
graphic.pivotLine.set_x2(endTime)
if positionLabelsInput == "Right"
graphic.pivotLabel.set_x(endTime)

drawNewPivots(startTime) =>
newGraphics = array.new<pivotGraphic>()
for [index, coord] in pivotPointsArray
if index < array.size(graphicSettingsArray)
levelSettings = graphicSettingsArray.get(index)
if not na(coord) and levelSettings.showLevel
lineEndTime = startTime + timeframe.in_seconds(pivotTimeframe) *
1000 * pivotYearMultiplier
pivotLine = line.new(startTime, coord, lineEndTime, coord, xloc =
xloc.bar_time, color=levelSettings.levelColor, width=linewidthInput)
pivotLabel = label.new(x = positionLabelsInput == "Left" ?
startTime : lineEndTime,
y = coord,
text = (showLabelsInput ?
levelSettings.levelName + " " : "") + (showPricesInput ? "(" + str.tostring(coord,
format.mintick) + ")" : ""),
style = positionLabelsInput == "Left" ?
label.style_label_right : label.style_label_left,
textcolor = levelSettings.levelColor,
color = color.new(#000000, 100),
xloc=xloc.bar_time)
newGraphics.push(pivotGraphic.new(pivotLine, pivotLabel))

drawnGraphics.add_row(array_id = newGraphics)
if drawnGraphics.rows() > maxHistoricalPivotsInput
oldGraphics = drawnGraphics.remove_row(0)
for graphic in oldGraphics
graphic.delete()

localPivotDrawConditionStatic = not isDailyBasedInput and localPivotTimeframeChange


securityPivotDrawConditionStatic = isDailyBasedInput and securityPivotCounter !=
securityPivotCounter[1]

var isMultiYearly = array.from("Biyearly", "Triyearly", "Quinquennially",


"Decennially").includes(pivotAnchorInput)
localPivotDrawConditionDeveloping = not isDailyBasedInput and time_close ==
time_close(pivotTimeframe) and not isMultiYearly
securityPivotDrawConditionDeveloping = false

if (securityPivotDrawConditionStatic or localPivotDrawConditionStatic)
affixOldPivots(time)
drawNewPivots(time)

var FIRST_BAR_TIME = time


if (barstate.islastconfirmedhistory and drawnGraphics.columns() == 0)
if not na(securityPivots) and securityPivotCounter > 0
if isDailyBasedInput
drawNewPivots(FIRST_BAR_TIME)
else
runtime.error("Not enough intraday data to calculate Pivot Points.")
else
runtime.error("Not enough data to calculate Pivot Points.")

You might also like