Skip to content

Commit

Permalink
feat: Add SWMA
Browse files Browse the repository at this point in the history
  • Loading branch information
sibvic committed Oct 4, 2024
1 parent 08efc05 commit df79552
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
36 changes: 36 additions & 0 deletions snippets/Streams/Averages/SwmaOnStream.mqh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <Streams/AOnStream.mqh>

#ifndef SwmaOnStream_IMPL
#define SwmaOnStream_IMPL

// EMA on stream v1.0

class SwmaOnStream : public AOnStream
{
public:
SwmaOnStream(IStream *source)
:AOnStream(source)
{
}

bool GetValue(const int period, double &val)
{
int totalBars = _source.Size();
if (period > totalBars - 4)
{
return false;
}

double x0;
double x1;
double x2;
double x3;
if (!_source.GetValue(period, x0) || !_source.GetValue(period + 1, x1) || !_source.GetValue(period + 2, x2) || !_source.GetValue(period + 3, x3))
{
return false;
}
val = x3 * 1 / 6 + x2 * 2 / 6 + x1 * 2 / 6 + x0 * 1 / 6;
return true;
}
};
#endif
6 changes: 5 additions & 1 deletion snippets/Streams/Averages/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ Hull moving average on stream

## VwapOnStream

VWAP average on stream
VWAP average on stream

## SwmaOnStream

SWMA average.

0 comments on commit df79552

Please sign in to comment.