Tracking Bullish and Bearish Candlesticks Over a Specific Time Period

17 Dec 2021
0 comment
0 attachment

This ProBuilder code snippet is designed to count and measure the strength of bullish and bearish candlesticks within a specified time frame during a trading day. It is useful for analyzing market trends during peak trading hours.


ONCE StartTime = 080000
ONCE EndTime = 100000
ONCE BullCount = 0
ONCE BearCount = 0
Bullish = close > open
Bearish = close < open
IF Time = StartTime THEN
    BullCount = 0
    BearCount = 0
ENDIF
IF time >= StartTime AND time <= EndTime THEN
    IF Bullish THEN
        BullCount = BullCount + (close - open)
    ENDIF
    IF Bearish THEN
        BearCount = BearCount + (open - close)
    ENDIF
ENDIF

Explanation of the Code:

  • Initialization: The code starts by setting up the start and end times for the period during which the candlesticks will be analyzed. It also initializes counters for bullish and bearish candlesticks.
  • Determining Candlestick Type: Two boolean variables, Bullish and Bearish, are defined to identify the type of each candlestick based on whether the closing price is higher or lower than the opening price.
  • Resetting Counters: At the exact start time specified, the counters for both bullish and bearish candlesticks are reset to zero. This ensures that the counting starts fresh each day at the specified start time.
  • Counting During Specified Period: The code checks if the current time is within the defined time window. If a candlestick is bullish, the difference between the close and open prices is added to BullCount. If a candlestick is bearish, the difference between the open and close prices is added to BearCount. This not only counts the number of bullish or bearish candlesticks but also measures their cumulative strength.

This snippet is particularly useful for traders or analysts who want to measure market sentiment during specific hours of the trading day.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/sum-open-to-close-of-candles-in-a-defined-time-range/#post-102543

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...