Skip to content

Instantly share code, notes, and snippets.

@itsnotyoutoday
Last active November 28, 2019 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsnotyoutoday/f922e31b68b651069159bfb8a8246c51 to your computer and use it in GitHub Desktop.
Save itsnotyoutoday/f922e31b68b651069159bfb8a8246c51 to your computer and use it in GitHub Desktop.
CTrader Calgo Weiss Wave Indicator
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
// Calgo Weiss Wave Indicator By RLB
namespace cAlgo
{
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class WeissWave : Indicator
{
[Parameter("Source")]
// Need to see if there is a way to restrictt his to open or close... sadly calgo's API sucks
public DataSeries Source { get; set; }
[Parameter("Trend Length", DefaultValue = 2)]
public int trend_length { get; set; }
[Output("Down Trend", LineColor = "Red", PlotType = PlotType.Histogram, Thickness = 3)]
public IndicatorDataSeries DownTrend { get; set; }
[Output("Up Trend", LineColor = "Green", PlotType = PlotType.Histogram, Thickness = 3)]
public IndicatorDataSeries UpTrend { get; set; }
// Helpers
private IndicatorDataSeries Wave;
private IndicatorDataSeries MVol;
private IndicatorDataSeries Mov;
private IndicatorDataSeries Trend;
protected override void Initialize()
{
// The Helpers from: https://www.tradingview.com/script/XttzkWc0-Weis-Wave-Volume-Pinescript-4/
Mov = CreateDataSeries();
Wave = CreateDataSeries();
MVol = CreateDataSeries();
Trend = CreateDataSeries();
}
public override void Calculate(int index)
{
bool isTrending = isRising(index, Source, trend_length) || isFalling(index, Source, trend_length);
if (isRising(index, MarketSeries.Close, 1))
Mov[index] = 1;
else if (isFalling(index, MarketSeries.Close, 1))
Mov[index] = -1;
else
Mov[index] = 0;
if (Mov[index] != 0 && Mov[index] != Mov[index - 1])
Trend[index] = Mov[index];
else
Trend[index] = Trend[index - 1];
if (Trend[index] != Wave[index - 1] && isTrending)
// Set Wave Index to Trend Index if Trend is not the last Wave, and we are trending
Wave[index] = Trend[index];
else
Wave[index] = Wave[index - 1];
if (Wave[index] == Wave[index - 1])
// If Wave Is Past Wave... Increase our Volume Index
MVol[index] = MVol[index - 1] + MarketSeries.TickVolume[index];
else
// New Wave? Well Lets start Over
MVol[index] = MarketSeries.TickVolume[index];
if (Wave[index] == 1)
UpTrend[index] = MVol[index];
if (Wave[index] == -1)
DownTrend[index] = MVol[index];
}
private bool isFalling(int index, DataSeries series, int length)
{
return series[index] < series[index - length];
}
private bool isRising(int index, DataSeries series, int length)
{
return series[index] > series[index - length];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment