Category Other  Published on 07/05/2024

Block Order Candle

Description

Block Order Candle

Large candles indicate that a key market participant showed strong interest during the previous candle. Consequently, the blocks are calculated based on the candle(s) preceding this large candle.

Functionality:

This trading indicator aims to identify important price areas on a chart by using blocks. It draws rectangles based on criteria like fractals or the True Range, helping traders visualize support and resistance zones.

Main Parameters:

  • LookBack Show Block Start: Controls how many blocks should be ignored from the end.
  • Nbrs Bloc Show: Number of blocks to display.
  • True Range Type: Determines the calculation type to use for the blocks (Fractal, True Range).
  • Period Fractal: Period to calculate fractals.
  • Nbrs Pips True Range: Number of pips to define the True Range zone.
  • Lookback Max Size: Maximum number of candles for And_Max type blocks.
  • ColorBlock: The color used to draw the blocks.

Types of True Range:

  • The different types are defined in the EnumTrType enumeration.
  • Fractal: Calculation based on the fractal levels of the price.
  • True Range: Based on the price movement between opening and closing.

Features:

  • Initialize: Initializes the necessary data structures, such as series for block levels and fractals.
  • Calculate:
    • Calculates the levels of the candles based on the chosen type.
    • Identifies blocks based on fractals or True Range and adds these blocks to a list.
    • Displays the blocks on the chart using AfficherBlocs.

Block Calculation Methods:

  • AjouterBloc: Calculates the maximum and minimum levels of a block according to the defined criteria and adds them to the list.
  • AfficherBlocs: Draws rectangles on the chart to show significant areas.

Large Candles:

  • Large candles indicate strong interest from the participant responsible for the movement. Therefore, blocks are calculated on the preceding candles to identify the support or resistance level where the participant showed interest.

Objective:

This indicator aims to highlight support and resistance zones by using calculation methods based on fractals or the True Range. Traders can thus visualize areas where the market may change direction or identify significant price levels.

Displaying the blocks graphically provides a clear idea of the zones to monitor for making more informed trading decisions.


On telegram : https://t.me/nimi012


 


using System;
using System.Collections.Generic;
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class BlockOrder30 : Indicator
    {
        [Parameter("LookBack Show Block Start", DefaultValue = 5, MinValue = 0, Group = "Blocks")]
        public int LookBackShowBlockStart { get; set; }

        [Parameter("Nbrs Bloc Show", DefaultValue = 10, MinValue = 0, Group = "Blocks")]
        public int NbrsBloc { get; set; }

        [Parameter("True Range Type", DefaultValue = EnumTrType.Fractal_On_Body, Group = "Methode Type")]
        public EnumTrType TrType { get; set; }

        [Parameter("Period Fractal", DefaultValue = 34, MinValue = 1, Group = "Factal")]
        public int Period { get; set; }

        [Parameter("Nbrs Pips True Range", DefaultValue = 34, MinValue = 1, Group = "True Range")]
        public int PipsMaxFunction { get; set; }

        [Parameter("Lookback block Max Size", DefaultValue = 3, MinValue = 0, Group = "Lookback Setting")]
        public int LookbackMaxFunction { get; set; }

        [Parameter("Lookback block Max Size", DefaultValue = "#39FFFF01", MinValue = 0, Group = "Lookback Setting")]
        public Color ColorBlock { get; set; }

        [Output("Result True range", PlotType = PlotType.Line, LineColor = "white")]
        public IndicatorDataSeries ResultTr { get; set; }

        [Output("Result Fractal", PlotType = PlotType.Line, LineColor = "Red")]
        public IndicatorDataSeries ResultFractal { get; set; }

        private IndicatorDataSeries Top, Bottom, Middle, candle, BlockTop, BlockBottom, ResultDcnUp;
        private List<List<double>> block;
        private int barsTot;
        private int prevIndex;

        public enum EnumTrType
        {
            Fractal_On_Body,
            Fractal_On_Body_And_Max,
            Pips_True_Range_Body,
            Pips_True_Range_Body_And_Max,
            Fractal_On_Candle,
            Fractal_On_Candle_And_Max,
            Pips_True_Range_Candle,
            Pips_True_Range_Candle_And_Max,
        }

        protected override void Initialize()
        {
            block = new List<List<double>>();
            candle = CreateDataSeries();
            Top = CreateDataSeries();
            Bottom = CreateDataSeries();
            Middle = CreateDataSeries();
            barsTot = Bars.Count;
            BlockTop = CreateDataSeries();
            BlockBottom = CreateDataSeries();
            ResultDcnUp = CreateDataSeries();
            prevIndex = 0;
        }

        public override void Calculate(int index)
        {
            // Calculate candle values

            if (prevIndex != index)
            {
                if (TrType == EnumTrType.Fractal_On_Body || TrType == EnumTrType.Fractal_On_Body_And_Max || TrType == EnumTrType.Pips_True_Range_Body || TrType == EnumTrType.Pips_True_Range_Body_And_Max)
                    candle[index] = Math.Abs(Bars.ClosePrices.Last(1) - Bars.OpenPrices.Last(1)) / Symbol.PipSize;
                else if (TrType == EnumTrType.Fractal_On_Candle || TrType == EnumTrType.Fractal_On_Candle_And_Max || TrType == EnumTrType.Pips_True_Range_Candle || TrType == EnumTrType.Pips_True_Range_Candle_And_Max)
                    candle[index] = (Bars.HighPrices.Last(1) - Bars.LowPrices.Last(1)) / Symbol.PipSize;

                // Calculate upper and lower levels
                Top[index] = candle.Maximum(Period);
                Bottom[index] = candle.Minimum(Period);
                Middle[index] = (Top[index] - Bottom[index]) / 2 + Bottom[index];

                ResultTr[index - 1] = candle[index];
                ResultDcnUp[index - 1] = Top[index - 1];

                // Determine fractal values
                if (TrType == EnumTrType.Fractal_On_Body || TrType == EnumTrType.Fractal_On_Body_And_Max || TrType == EnumTrType.Fractal_On_Candle || TrType == EnumTrType.Fractal_On_Candle_And_Max)
                {
                    ResultFractal[index - 1] = Top[index - 1];
                    if (candle.Last(1) > ResultDcnUp.Last(1) && candle.Last(2) < ResultDcnUp.Last(2))
                    {
                        AddBlock(index, TrType);
                    }
                }
                else if (TrType == EnumTrType.Pips_True_Range_Body || TrType == EnumTrType.Pips_True_Range_Body_And_Max || TrType == EnumTrType.Pips_True_Range_Candle || TrType == EnumTrType.Pips_True_Range_Candle_And_Max)
                {
                    ResultFractal[index - 1] = PipsMaxFunction;
                    if (candle.Last(1) > PipsMaxFunction && candle.Last(2) < PipsMaxFunction)
                    {
                        AddBlock(index, TrType);
                    }
                }

                // Display blocks based on parameters
                DisplayBlocks(index);

                prevIndex = index;
            }
        }

        private void AddBlock(int index, EnumTrType trType)
        {
            var max = Bars.HighPrices.Last(3);
            var min = Bars.LowPrices.Last(3);

            // Adjust levels if the type includes "And_Max"
            if (trType == EnumTrType.Fractal_On_Body_And_Max || trType == EnumTrType.Pips_True_Range_Body_And_Max ||
                trType == EnumTrType.Fractal_On_Candle_And_Max || trType == EnumTrType.Pips_True_Range_Candle_And_Max)
            {
                for (int i = 0; i < LookbackMaxFunction; i++)
                {
                    max = Math.Max(max, Bars.HighPrices.Last(3 + i));
                    min = Math.Min(min, Bars.LowPrices.Last(3 + i));
                }
            }

            BlockTop[index - 3] = max;
            BlockBottom[index - 3] = min;
            block.Add(new List<double> { max, min, index - 3 });
        }

        private void DisplayBlocks(int index)
        {
            if (block.Count > LookBackShowBlockStart)
            {
                int start = block.Count - LookBackShowBlockStart - NbrsBloc;
                start = Math.Max(0, start);

                int end = block.Count - LookBackShowBlockStart;

                for (int i = start; i < end; i++)
                {
                    var blocStartIndex = (int)block[i][2];
                    var highPrice = block[i][0];
                    var lowPrice = block[i][1];
                    Chart.DrawRectangle("Bloc " + i, blocStartIndex, highPrice, index, lowPrice, ColorBlock).IsFilled = true;
                }

                for (int j = 0; j < start; j++)
                {
                    Chart.RemoveObject("Bloc " + j);
                }

            }
        }
    }
}


YE
YesOrNot

Joined on 10.10.2022 Blocked

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Block Order 3.0.algo
  • Rating: 0
  • Installs: 265
  • Modified: 07/05/2024 04:48
Comments
Log in to add a comment.
No comments found.