Skip to content

Commit

Permalink
feat: Stream of candles
Browse files Browse the repository at this point in the history
  • Loading branch information
sibvic committed Sep 5, 2024
1 parent d7228fc commit 205a236
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
86 changes: 86 additions & 0 deletions snippets/Streams/CandleStreams.mqh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Candles stream v.1.0
class CandleStreams
{
double OpenStream[];
double CloseStream[];
double HighStream[];
double LowStream[];
double ColorIndex[];
color colors[];
int streamIndex;
public:
CandleStreams(int streamIndex)
{
this.streamIndex = streamIndex;
}
void Init()
{
ArrayInitialize(OpenStream, EMPTY_VALUE);
ArrayInitialize(CloseStream, EMPTY_VALUE);
ArrayInitialize(HighStream, EMPTY_VALUE);
ArrayInitialize(LowStream, EMPTY_VALUE);
ArrayInitialize(ColorIndex, 0);
}

void Clear(const int index)
{
OpenStream[index] = EMPTY_VALUE;
CloseStream[index] = EMPTY_VALUE;
HighStream[index] = EMPTY_VALUE;
LowStream[index] = EMPTY_VALUE;
ColorIndex[index] = 0;
}

void AddColor(color clr)
{
int size = ArraySize(colors);
ArrayResize(colors, size + 1);
colors[size] = clr;
}

int RegisterStreams(const int id)
{
SetIndexBuffer(id, OpenStream, INDICATOR_DATA);
SetIndexBuffer(id + 1, HighStream, INDICATOR_DATA);
SetIndexBuffer(id + 2, LowStream, INDICATOR_DATA);
SetIndexBuffer(id + 3, CloseStream, INDICATOR_DATA);
SetIndexBuffer(id + 4, ColorIndex, INDICATOR_COLOR_INDEX);
int size = ArraySize(colors);
PlotIndexSetInteger(streamIndex, PLOT_COLOR_INDEXES, size);
for (int i = 0; i < size; ++i)
{
PlotIndexSetInteger(streamIndex, PLOT_LINE_COLOR, i, colors[i]);
}
return id + 5;
}

void Set(const int index, const double open, const double high, const double low, const double close, color clr)
{
if (clr == (color)EMPTY_VALUE)
{
return;
}
OpenStream[index] = open;
HighStream[index] = high;
LowStream[index] = low;
CloseStream[index] = close;
ColorIndex[index] = FindColor(clr);
}

void SetOffset(int offset)
{
}
private:
int FindColor(color clr)
{
int size = ArraySize(colors);
for (int i = 0; i < size; ++i)
{
if (colors[i] == clr)
{
return i;
}
}
return 0;
}
};
6 changes: 5 additions & 1 deletion snippets/Streams/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,8 @@ Equivalent to lowestbars from TradingView.

## ColoredFill

Multi-colored PS-like Fill()
Multi-colored PS-like Fill()

## CandleStreams

Stream of candles

0 comments on commit 205a236

Please sign in to comment.