There seems to be no interest in helping me with my code, so I thought I would print the code I'm trying to alter.
Before everybody starts to copy the code I need to tell you that its just a shell for plotting the custom Delta indicator as ohlc candles in a separate window, thus making it a Cumulative Delta Volume indicator. And no I cant give out the Custom Delta indicator that's in the code.
I'm trying to make 2 things with this code, first make it start over from 0 every day and second calculate and plot a moving average of the candles in the code.
But I'm having problems with both. Its easy to just drop a moving average over the indicator on chart, but I need the buffer for it.
Any ideas would be welcome, and yes I have made efforts in making it work but I have failed every time.
Here is the original code:
Code: Select all
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_plots 1
#property indicator_type1 DRAW_COLOR_CANDLES
#property indicator_color1 clrGreen, clrCrimson
#property indicator_label1 "Delta Open;Delta High;Delta Low;Delta Close"
// Indicator buffers
double ExtOBuffer[];
double ExtHBuffer[];
double ExtLBuffer[];
double ExtCBuffer[];
double ExtColorBuffer[];
// Delta buffers
double DeltaBuf[];
double BuyBuf[];
double SellBuf[];
input datetime inpHistoryDate=D'2022.01.01';
void OnInit()
{
SetIndexBuffer(0, ExtOBuffer, INDICATOR_DATA);
SetIndexBuffer(1, ExtHBuffer, INDICATOR_DATA);
SetIndexBuffer(2, ExtLBuffer, INDICATOR_DATA);
SetIndexBuffer(3, ExtCBuffer, INDICATOR_DATA);
SetIndexBuffer(4, ExtColorBuffer, INDICATOR_COLOR_INDEX);
}
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
int Delta;
Delta = iCustom(NULL, PERIOD_CURRENT,"Delta_Indicator",inpHistoryDate); //Delta_Close
if (CopyBuffer(Delta, 0, 0, rates_total, DeltaBuf) != rates_total) return 0;
Delta = iCustom(NULL, PERIOD_CURRENT,"Delta_Indicator",inpHistoryDate); //Delta_Buy
if (CopyBuffer(Delta, 2, 0, rates_total, BuyBuf) != rates_total) return 0;
Delta = iCustom(NULL, PERIOD_CURRENT,"Delta_Indicator",inpHistoryDate); //Delta_Sell
if (CopyBuffer(Delta, 3, 0, rates_total, SellBuf) != rates_total) return 0;
// Preliminary calculations.
int limit;
if (prev_calculated <= 1)
{
// Set the first candle.
ExtLBuffer[0] = 0;
ExtHBuffer[0] = 0;
ExtOBuffer[0] = 0;
ExtCBuffer[0] = 0;
limit = 1;
}
else limit = prev_calculated - 1;
// The main loop of calculations.
for (int i = limit; i < rates_total; i++)
{
ExtOBuffer[i] = ExtCBuffer[i-1];
ExtLBuffer[i] = ExtCBuffer[i-1];
ExtHBuffer[i] = ExtCBuffer[i-1];
ExtCBuffer[i] = ExtCBuffer[i-1];
if (BuyBuf[i] - SellBuf[i] < 0)
{
ExtOBuffer[i] = ExtCBuffer[i-1];
ExtLBuffer[i] = ExtCBuffer[i-1]-DeltaBuf[i];
ExtHBuffer[i] = ExtCBuffer[i-1];
ExtCBuffer[i] = ExtCBuffer[i-1]-DeltaBuf[i];
ExtColorBuffer[i] = 1.0;
}
else if (BuyBuf[i] - SellBuf[i] > 0)
{
ExtOBuffer[i] = ExtCBuffer[i-1];
ExtLBuffer[i] = ExtCBuffer[i-1];
ExtHBuffer[i] = ExtCBuffer[i-1]+DeltaBuf[i];
ExtCBuffer[i] = ExtCBuffer[i-1]+DeltaBuf[i];
ExtColorBuffer[i] = 0.0;
}
}
return rates_total;
}
//+------------------------------------------------------------------+
here is how it looks, the problem is it just adds the delta from previous candle and so on.