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 New
This author is like an anonymous function, present but not directly identifiable. More details on this code architect as soon as they exit 'incognito' mode.
Author’s Profile

Comments

Search Snippets

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

Snippets Categories

global
33
indicator
132
strategy
171

Recent Snippets

How to Build a Step-Based Trailing Stop That Moves to Break-Even First
strategy
This snippet implements a step trailing stop that advances in fixed increments once price reaches predefined profit [...]
Utilizing Arrays to Track and Compare Indicator Values Within the Same Bar in ProBuilder
indicator
This ProBuilder code snippet demonstrates how to use arrays to compare the values of an indicator (RSI in this case) [...]
Calculating Break-Even Points in ProBuilder
strategy
This ProBuilder code snippet demonstrates how to calculate the break-even point for a trading position. The break-even [...]
Implementing Time and Day Restrictions in Trading Algorithms
strategy
This code snippet demonstrates how to set restrictions on trading activities based on specific days of the week and [...]
Implementing Partial Position Closure Based on Price Retracement in ProBuilder
strategy
This code snippet demonstrates how to partially close a trading position when the price retraces to a certain level in [...]
Logo Logo
Loading...