Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
5 views1 page

Maths Square

This document is a Pine Script code for TradingView that creates pivot-based trading levels using a square root formula. It calculates buy and sell levels based on the previous day's close and plots them as circles on the chart, with options to show or hide these levels. Additionally, it adds labels for each level and highlights the background on a new trading day.

Uploaded by

dorab2176
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)
5 views1 page

Maths Square

This document is a Pine Script code for TradingView that creates pivot-based trading levels using a square root formula. It calculates buy and sell levels based on the previous day's close and plots them as circles on the chart, with options to show or hide these levels. Additionally, it adds labels for each level and highlights the background on a new trading day.

Uploaded by

dorab2176
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/ 1

//@version=5

indicator("Pivot-Based Levels with Sqrt Formula (Dots)", overlay=true)

// === Toggle to show/hide plots ===


show = input.bool(true, "Show Levels", inline="showhide")

// === Fetch previous day's close ===


prev_close = request.security(syminfo.tickerid, "D", close[1],
lookahead=barmerge.lookahead_on)

// === Calculate Range (R) using the provided formula ===


r = ((math.sqrt(prev_close) + 1) * (math.sqrt(prev_close) + 1) - prev_close) / 2.5

// === Calculate levels ===


buy_above = prev_close + r
sell_below = prev_close - r
buy_target1 = buy_above + r
buy_target2 = buy_target1 + r
sell_target1 = sell_below - r
sell_target2 = sell_target1 - r
stop_loss = prev_close

// === Plot using requested dot styles and colors ===


plot(show ? buy_above : na, color=color.green, style=plot.style_circles, title="Buy
Above")
plot(show ? sell_below : na, color=color.red, style=plot.style_circles, title="Sell
Below")
plot(show ? buy_target1 : na, color=color.green, style=plot.style_circles,
title="Buy Target 1")
plot(show ? buy_target2 : na, color=color.green, style=plot.style_circles,
title="Buy Target 2")
plot(show ? sell_target1 : na, color=color.red, style=plot.style_circles,
title="Sell Target 1")
plot(show ? sell_target2 : na, color=color.red, style=plot.style_circles,
title="Sell Target 2")
plot(show ? stop_loss : na, color=color.blue, style=plot.style_circles,
title="Stop-Loss (Close)")

// === Add labels on a new day ===


if ta.change(time("D"))
label.new(bar_index, buy_above, "Buy: " + str.tostring(buy_above, "#.##"),
color=color.green, style=label.style_label_down, textcolor=color.white)
label.new(bar_index, sell_below, "Sell: " + str.tostring(sell_below, "#.##"),
color=color.red, style=label.style_label_up, textcolor=color.white)
label.new(bar_index, buy_target1, "T1 Buy: " + str.tostring(buy_target1,
"#.##"), color=color.green, style=label.style_label_down, textcolor=color.white)
label.new(bar_index, buy_target2, "T2 Buy: " + str.tostring(buy_target2,
"#.##"), color=color.green, style=label.style_label_down, textcolor=color.white)
label.new(bar_index, sell_target1, "T1 Sell: " + str.tostring(sell_target1,
"#.##"), color=color.red, style=label.style_label_up, textcolor=color.white)
label.new(bar_index, sell_target2, "T2 Sell: " + str.tostring(sell_target2,
"#.##"), color=color.red, style=label.style_label_up, textcolor=color.white)
label.new(bar_index, stop_loss, "SL: " + str.tostring(stop_loss, "#.##"),
color=color.blue, style=label.style_label_left, textcolor=color.white)

// === Background highlight on a new day ===


bgcolor(ta.change(time("D")) ? color.new(color.gray, 90) : na)

You might also like