Description
Here is a very basic VWAP indicator that uses the start of the session. Its free so enjoy!
Only for timeframes under a day i.e. it calculates from the start of a daily session. someone could extend this code to work with higher timeframes . e.g if daily then start at the week, if weekly then start and the month, etc
* fyi.. i like it in the 5 min chart as it can provide an extra layer of confluence
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class JLoVWAP : Indicator
{
[Output("Main", LineColor = "#FF00843B", Thickness = 2)]
public IndicatorDataSeries Result { get; set; }
private Bars dailyResults;
public override void Calculate(int index)
{
double CumulativePrice = 0;
double CumulativeVol = 0;
//Get session start time from daily bars
dailyResults = MarketData.GetBars(TimeFrame.Daily);
var indexDaily = dailyResults.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
DateTimeOffset tradingStartTime = dailyResults[indexDaily].OpenTime;
//calculate the cumalative price and the cumulative volume
//get the index of this chart when the day opened
var indexStart = Bars.OpenTimes.GetIndexByExactTime(tradingStartTime.DateTime);
int i = index; //work backwards from the current index to the start of the day
while(i > indexStart)
{
CumulativePrice += Bars.TypicalPrices[i] * Bars.TickVolumes[i];
CumulativeVol += Bars.TickVolumes[i];
i--;
}
//return the result
Result[index] = CumulativePrice / CumulativeVol;
}
}
}
J.
J.Lo
Joined on 23.10.2021
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: VWAP.JLo.algo
- Rating: 0
- Installs: 2473
- Modified: 23/10/2021 00:56
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.
No comments found.