Description
This indicator represents the Angle of the VWAP (Volume Weighted Average Price) using a histogram.
→ Feel free to comment to suggest things.
Have fun, and for any collaboration, contact me !!!
On telegram : https://t.me/nimi012 (direct messaging)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo
{
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class VWAPAngleHistorgram : Indicator
{
[Parameter("VWAP TF", DefaultValue = "Daily")]
public TimeFrame TF { get; set; }
[Parameter("Open Period Wait Bars", DefaultValue = 5)]
public int WaitBars { get; set; }
[Parameter("Signal Period", DefaultValue = 55)]
public int SignalPeriod { get; set; }
[Parameter("Signal Type", DefaultValue = MovingAverageType.Weighted)]
public MovingAverageType MaType { get; set; }
[Output("White", PlotType = PlotType.Histogram, LineColor = "White", Thickness = 4)]
public IndicatorDataSeries White { get; set; }
[Output("Up Bullish", PlotType = PlotType.Histogram, LineColor = "Lime", Thickness = 4)]
public IndicatorDataSeries StrongBullish { get; set; }
[Output("Down Bullish", PlotType = PlotType.Histogram, LineColor = "Green", Thickness = 4)]
public IndicatorDataSeries WeakBullish { get; set; }
[Output("Down Bearish", PlotType = PlotType.Histogram, LineColor = "Red", Thickness = 4)]
public IndicatorDataSeries StrongBearish { get; set; }
[Output("Up Bearish", PlotType = PlotType.Histogram, LineColor = "DarkSalmon", Thickness = 4)]
public IndicatorDataSeries WeakBearish { get; set; }
[Output("Signal", PlotType = PlotType.Line, LineColor = "DeepSkyBlue", Thickness = 1)]
public IndicatorDataSeries Signal { get; set; }
private MovingAverage ma, signal;
private AverageTrueRange atr;
private IndicatorDataSeries BarsVolume, ResVwap, ResAngle;
private Bars bars;
protected override void Initialize()
{
bars = MarketData.GetBars(TF);
BarsVolume = CreateDataSeries();
ResVwap = CreateDataSeries();
ResAngle = CreateDataSeries();
ma = Indicators.MovingAverage(ResVwap, 1, MovingAverageType.Simple);
atr = Indicators.AverageTrueRange(500, MovingAverageType.Simple);
signal = Indicators.MovingAverage(ResAngle, SignalPeriod, MaType);
}
public override void Calculate(int index)
{
BarsVolume[index] = Bars.ClosePrices[index] * Bars.TickVolumes[index];
int startIndex = Bars.OpenTimes.GetIndexByTime(bars.OpenTimes[bars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index])]);
double cptv = 0, cv = 0;
for (int i = index; i >= startIndex; --i)
{
cptv += BarsVolume[i];
cv += Bars.TickVolumes[i];
}
ResVwap[index] = cptv / cv;
var indexbars = bars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
var atrRange = atr.Result[index];
var CoteOpposePlus = ((ma.Result[index]) - (ma.Result[index - (1)]));
var CoteOpposeMinus = (ma.Result[index - (1)]) - (ma.Result[index]);
var CoteOppose = (ma.Result[index]) > (ma.Result[index - (1)]) ? CoteOpposePlus / atrRange : CoteOpposeMinus / atrRange;
var Hypothenuse = Math.Sqrt((CoteOppose * CoteOppose) + (1 * 1));
var cos = (1 / Hypothenuse);
if (Bars.OpenTimes[index] <= bars.OpenTimes[indexbars] + (Bars.OpenTimes[index] - Bars.OpenTimes[index - WaitBars]))
{
ResAngle[index] = 0;
//if (Bars.OpenTimes[index] == bars.OpenTimes[indexbars])
IndicatorArea.DrawRectangle("OpenZone" + index, index - WaitBars, 500, index + WaitBars, -500, Color.FromArgb(255 / 2 / WaitBars, Color.DeepSkyBlue)).IsFilled = true;
}
else
ResAngle[index] = (ma.Result[index]) > (ma.Result[index - (1)]) ? (0 + (Math.Acos(cos) * 100)) : (0 - (Math.Acos(cos) * 100));
Signal[index] = signal.Result.Last(0);
//Histogram
double HistogramValue = ResAngle[index];
double prevHistogramValue = ResAngle[index - 1];
if (HistogramValue > 0)
{
if (prevHistogramValue >= HistogramValue)
{
WeakBullish[index] = HistogramValue;
StrongBullish[index] = 0;
WeakBearish[index] = 0;
StrongBearish[index] = 0;
White[index] = 0;
}
else
{
StrongBullish[index] = HistogramValue;
WeakBullish[index] = 0;
WeakBearish[index] = 0;
StrongBearish[index] = 0;
White[index] = 0;
}
}
else if (HistogramValue < -0)
{
if (HistogramValue <= prevHistogramValue)
{
StrongBearish[index] = HistogramValue;
WeakBearish[index] = 0;
StrongBullish[index] = 0;
WeakBullish[index] = 0;
White[index] = 0;
}
else
{
WeakBearish[index] = HistogramValue;
StrongBearish[index] = 0;
StrongBullish[index] = 0;
WeakBullish[index] = 0;
White[index] = 0;
}
}
else
{
if (HistogramValue <= prevHistogramValue)
{
White[index] = HistogramValue;
WeakBearish[index] = 0;
WeakBearish[index] = 0;
StrongBullish[index] = 0;
WeakBullish[index] = 0;
}
else
{
WeakBearish[index] = 0;
White[index] = HistogramValue;
StrongBearish[index] = 0;
StrongBullish[index] = 0;
WeakBullish[index] = 0;
}
}
}
}
}
YE
YesOrNot
Joined on 10.10.2022 Blocked
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: VWAP Angle Historgram.algo
- Rating: 5
- Installs: 605
- Modified: 10/12/2023 20:12
Note that publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section, please use the Copyright Infringement Notification form to submit a claim.
Comments
Log in to add a comment.
Great.