Implementing Multi-Timeframe Analysis and Anchored Text Display in ProBuilder

26 Sep 2022
0 comment
0 attachment

This ProBuilder script demonstrates how to perform multi-timeframe analysis and display various indicators and price differences using anchored text on a trading chart. The code snippet below includes calculations for exponential moving averages (EMAs), simple moving averages (SMAs), and volume-weighted average price (VWAP) across different timeframes (1 minute, 5 minutes, and 15 minutes). It also shows how to anchor text elements to specific positions on the chart, which remain fixed regardless of chart resizing.

DefParam DrawOnLastBarOnly = True
TimeFrame(15 minutes)
My15MnEMA200 = Average[50,1](close)
My15MnSMA50 = Average[50,0](close)
TimeFrame(5 minutes)
My5MnEMA200 = Average[200,1](close)
My5MnSMA50 = Average[50,0](close)
TimeFrame(1 minute, Default)
d = max(1, intradaybarindex)
MyVwap = SUMMATION[d](volume*typicalprice)/SUMMATION[d](volume)
MyVwapRounded = Round(MyVwap, 2)
My1MnEMA200 = Average[200,1](close)
My1MnSMA50 = Average[50,0](close)
MyPrice = Close
MyPriceRounded = Round(MyPrice, 2)
MyDiffPriceVwap = MyPriceRounded - MyVwapRounded
My15MnAboveEMA200 = Close > My15MnEMA200
My15MnAboveSMA50 = Close > My15MnSMA50
My5MnAboveEMA200 = Close > My5MnEMA200
My5MnAboveSMA50 = Close > My5MnSMA50
My1MnAboveEMA200 = Close > My1MnEMA200
My1MnAboveSMA50 = Close > My1MnSMA50
DrawText ("Vwap: #MyVwapRounded#", -240, 125, SansSerif, Bold, 12) anchor(BottomRight) coloured (0,0,0)
DrawText ("Prix: #MyPrice#", -140, 125, SansSerif, Standard, 12) anchor(BottomRight) coloured (0,0,0)
DrawText ("Diff: #MyDiffPriceVwap#", -50, 125, SansSerif, standard, 12) anchor(BottomRight)
DrawText("EMA200 SMA50 ", -110, 100, dialog, standard,12) anchor(BottomRight)
DrawText("15 Minutes ", -250, 75, dialog, standard,12)anchor(BottomRight)
DrawText("5 Minutes ", -250, 50, dialog, standard,12)anchor(BottomRight)
DrawText("1 Minute ", -250, 25, dialog, standard,12)anchor(BottomRight)
If My15MnAboveEMA200 then
    DrawText("#My15MnEMA200#", -150, 75, dialog, standard,12) anchor(BottomRight) coloured(102,255,0)
Else
    DrawText("#My15MnEMA200#", -150, 75, dialog, standard,12) anchor(BottomRight) coloured(255,0,0)
Endif
If My15MnAboveSMA50 then
    DrawText("#My15MnSMA50#", -50, 75, dialog, standard,12) anchor(BottomRight) coloured(102,255,0)
Else
    DrawText("#My15MnSMA50#", -50, 75, dialog, standard,12) anchor(BottomRight) coloured(255,0,0)
Endif
If My5MnAboveEMA200 then
    DrawText("#My5MnEMA200#", -150, 50, dialog, standard,12) anchor(BottomRight) coloured(102,255,0)
Else
    DrawText("#My5MnEMA200#", -150, 50, dialog, standard,12) anchor(BottomRight) coloured(255,0,0)
Endif
If My5MnAboveSMA50 then
    DrawText("#My5MnSMA50#", -50, 50, dialog, standard,12) anchor(BottomRight) coloured(102,255,0)
Else
    DrawText("#My5MnSMA50#", -50, 50, dialog, standard,12) anchor(BottomRight) coloured(255,0,0)
Endif
If My1MnAboveEMA200 then
    DrawText("#My1MnEMA200#", -150, 25, dialog, standard,12) anchor(BottomRight) coloured(102,255,0)
Else
    DrawText("#My1MnEMA200#", -150, 25, dialog, standard,12) anchor(BottomRight) coloured(255,0,0)
Endif
If My1MnAboveSMA50 then
    DrawText("#My1MnSMA50#", -50, 25, dialog, standard,12) anchor(BottomRight) coloured(102,255,0)
Else
    DrawText("#My1MnSMA50#", -50, 25, dialog, standard,12) anchor(BottomRight) coloured(255,0,0)
Endif
DrawRectangle(-290,140,-10,10) anchor(BottomRight) coloured(220,220,220,100) borderColor(0,0,0,0)
DrawRectangle(-195,110,-100,10) anchor(BottomRight) coloured(211,211,211,100) borderColor(0,0,0,0)
Return

Explanation of the Code:

  • The script starts by setting parameters to draw only on the last bar and defines multiple timeframes for analysis.
  • It calculates EMAs and SMAs for 15-minute, 5-minute, and 1-minute timeframes.
  • The VWAP is calculated for the current day using intraday volume and price data.
  • Price differences between the current price and VWAP are calculated and rounded for display.
  • Conditional statements check if the current price is above the calculated EMAs and SMAs, changing the color of the displayed text based on these conditions.
  • Text elements are anchored to the bottom right of the chart, ensuring they stay in place even when the chart is resized.
  • Rectangles are drawn to create a background for the text, enhancing readability.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/affichage-ema-200-sur-ut-15-et-15-mn/#post-197461

Visit Link
What is a Snippet? A snippet is a small, reusable chunk of code designed to solve specific tasks quickly. Think of it as a shortcut that helps you achieve your coding goals without reinventing the wheel. How to Use: Simply copy the snippet and paste it into your project where needed. Don't forget to tweak it to fit your context. Snippets are not just time-savers; they're also learning tools to help you become a more efficient coder.
druby Junior
Developer by day, aspiring writer by night. Still compiling my bio... Error 404: presentation not found.
Author’s Profile

Comments

Search Snippets

Showing some results...
Sorry, no result found!

Snippets Categories

global
35
indicator
135
strategy
171

Recent Snippets

A multi indicator Dashboard for ProRealTime
indicator
This snippet creates a compact on-chart dashboard that aggregates multiple indicator states into a single, readable [...]
How to Track Up/Down Cumulative Volume Inside Each Candle (Tick Volume Delta)
indicator
This snippet separates the real-time, intra-candle volume into up-volume and down-volume based on whether the last [...]
How to Create a Simple MTF Trend Dashboard with EMA and SMA
indicator
This indicator builds a compact multi-timeframe (MTF) dashboard that shows whether price is trading above or below a [...]
How to Display Per-Bar Volume Accumulation in Real Time (Intrabar Updates)
global
This snippet tracks and displays the current bar’s accumulated volume while the bar is still forming, instead of only [...]
Ticks Counter: Count Tick Updates Per Bar on Tick or Time Charts
global
This snippet counts how many tick updates have occurred for the current bar by incrementing a per-bar counter on each [...]
ProRealCode ProRealCode
Loading...