0% found this document useful (0 votes)
2 views2 pages

How To Reference Lower Timeframes

This document contains a Pine Script code for a trading indicator named 'PSMC - Lower Timeframe Dayta'. It retrieves and processes Average True Range (ATR) values and closing prices from a specified lower timeframe, allowing users to analyze historical data over a defined lookback period. The script includes functions for safely accessing array values and visualizing the ATR data on a chart.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

How To Reference Lower Timeframes

This document contains a Pine Script code for a trading indicator named 'PSMC - Lower Timeframe Dayta'. It retrieves and processes Average True Range (ATR) values and closing prices from a specified lower timeframe, allowing users to analyze historical data over a defined lookback period. The script includes functions for safely accessing array values and visualizing the ATR data on a chart.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

// This source code is subject to the terms of the Mozilla Public License 2.

0 at
[Link]
// © ZenAndTheArtOfTrading
// @version=5
indicator("PSMC - Lower Timeframe Dayta")

// Get user input


int i_Lookback = [Link](title="Lookback", defval=10)
string i_Period = [Link](title="Lower Timeframe", defval="D")

// Define custom function for safely retrieving array values without index OOB errors
getArrayValue(float[] array, int idx) =>
if [Link](array) > idx
[Link](array, idx)
else
na

// Get ATR value expression (for passing to security() function)


float atrValue = [Link](14)
plot(atrValue, color=[Link]([Link], 100))

// Get lower timeframe dayta


float[] LtfATR_Array = request.security_lower_tf([Link], i_Period, atrValue)
float[] LtfClosingPrice_Array = request.security_lower_tf([Link], i_Period,
close)

// Define our merged ATR values array


var float[] ATR_Array = array.new_float(i_Lookback, 0)
var float[] ClosingPrice_Array = array.new_float(i_Lookback, 0)

// If current timeframe is the reference timeframe, we don't need to reference LTF


data
if [Link] == i_Period
for i = 0 to [Link](ATR_Array) - 1
[Link](ATR_Array, i, atrValue[i]) // Set each array index with the
corresponding historical value
[Link](ClosingPrice_Array, i, close[i])
[Link](ATR_Array) // Reverse array to be consistent with HTF array
population handled below
[Link](ClosingPrice_Array)
else // Populate our ATR array
if [Link](LtfATR_Array) > 0
for i = 0 to [Link](LtfATR_Array) - 1
[Link](ATR_Array) // Remove the array's first element
[Link](ATR_Array, [Link](LtfATR_Array, i)) // Insert a new array
element (FIFO)
[Link](ClosingPrice_Array)
[Link](ClosingPrice_Array, [Link](LtfClosingPrice_Array, i))

// Draw the past 10 days ATR values


plot(getArrayValue(ATR_Array, 0))
plot(getArrayValue(ATR_Array, 1))
plot(getArrayValue(ATR_Array, 2))
plot(getArrayValue(ATR_Array, 3))
plot(getArrayValue(ATR_Array, 4))
plot(getArrayValue(ATR_Array, 5))
plot(getArrayValue(ATR_Array, 6))
plot(getArrayValue(ATR_Array, 7))
plot(getArrayValue(ATR_Array, 8))
plot(getArrayValue(ATR_Array, 9))

// For debug purposes


string debugStr = ""
for i = 0 to [Link](ClosingPrice_Array) - 1
debugStr := debugStr + [Link](getArrayValue(ClosingPrice_Array, i), "#.##")
+ ", "
var table debugDisplay = [Link](position.top_right, 1, 1)
if [Link]
atrPercent = (getArrayValue(ATR_Array, [Link](ATR_Array) - 1) /
getArrayValue(ClosingPrice_Array, [Link](ClosingPrice_Array) - 1)) * 100
[Link](debugDisplay, 0, 0, [Link](atrPercent), text_color=[Link])
//[Link](debugDisplay, 0, 0, debugStr, text_color=[Link])

You might also like