Capturing and Displaying Price and Bar Index at a Specific Time in ProBuilder

06 Jun 2017
0 comment
0 attachment

This ProBuilder script is designed to capture and display the price and bar index of a financial instrument at exactly 11:00 AM. It is useful for traders who need to analyze price action at specific times of the day.


DEFPARAM DrawOnLastBarOnly = true

IF (Time = 110000) OR (Time > 110000 AND Time[1] < 110000) THEN
    PriceAT11 = close[1]
    BarAT11 = barindex
ENDIF

IF PriceAT11 > 0 THEN
    DRAWTEXT("Price at 11:00:00 #PriceAT11#", BarAT11, PriceAT11)
ENDIF

RETURN

This script performs the following steps:

  • Initialization: DEFPARAM DrawOnLastBarOnly = true ensures that drawing commands (like DRAWTEXT) only execute on the last available bar to avoid cluttering the chart.
  • Condition Check: The IF statement checks if the current time is exactly 11:00 AM or if it has just passed 11:00 AM since the last checked bar. This is done using the Time and Time[1] variables, where Time[1] represents the time of the previous bar.
  • Storing Values: If the condition is true, the closing price of the previous bar (close[1]) is stored in PriceAT11, and the current bar index (barindex) is stored in BarAT11. These variables capture the price and the position of the bar at 11:00 AM.
  • Displaying Information: Another IF statement checks if PriceAT11 has been set (i.e., is greater than 0). If true, it uses DRAWTEXT to display the price at 11:00 AM on the chart at the corresponding bar index.

This script is particularly useful for back-testing strategies that require analysis of price action at specific times or for visually marking important times on trading charts.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/multiple-timeframes-2/page/2/#post-109913

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.
robertogozzi Master
Roberto https://www.ots-onlinetradingsoftware.com
Author’s Profile

Comments

Search Snippets

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

Snippets Categories

global
35
indicator
133
strategy
171

Recent Snippets

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 [...]
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) [...]
Logo Logo
Loading...