Discussion of article "Developing stock indicators featuring volume control through the example of the delta indicator" - page 9

 
Aleksey Vyazmikin:

If we take open interest, is this the kind of code you had in mind?

Traded delta, I am referring to the indicator, in the thread where our dialogue is going on

So you summarise these deltas in a floating window (for example, the last 100) or in ascending order (n+1 from a certain date, for example, from the start date of the current day), for what period? Why for this period?

Well, yes, this code is approximately. If in %, then * 100. This is more suitable for robots, visually it is better to look at absolute values. IMHO.

I have a number of windows for different tactics. Something like this:


 

Assuming that the futures starts to be actively traded (and for some markets globally determine asset prices, such as 6B,6E,RB,CL,GC) as soon as it becomes the closest, the delta should be summarised from the beginning of this date.

If you work with delta on stocks, it is much more difficult to determine the starting point. In reality, most systems (like ClusterDelta) take a fixed moving window, e.g. 90 bars. However, if you think carefully, it is probably more correct to take some price extremum in the past, e.g. 30 days, as a point of reference

 

mr. kozitsyn, 

congratulations for great job ! this is best Delta indicator until now, very fast.

I try modify it to plot only positive values with diferent color to buy/sell delta (best to compare size of histogram bars),without success, You can give some tipe how to do it or post where should modify the original code ?

Another question, is it possible to plot a vertical instead horizontal histogram ? I try to plot vertical histogram using https://www.mql5.com/en/articles/2714 but it didn´t plot any value, in fact I try plot volume values in vertical histogram and it didn´t plot any king of volume (I use NormalizeDouble to convert from long to double).

Thanks very much !

Statistical distributions in the form of histograms without indicator buffers and arrays
Statistical distributions in the form of histograms without indicator buffers and arrays
  • www.mql5.com
Histograms allow researchers to visually evaluate the distribution of statistical data grouped by the frequency of their penetration into a certain (predetermined) interval. Histograms and their use in the statistical data analysis are a well-studied topic with multiple articles devoted to it [1, 2, 3, 4, 5, 6, 7] and a large number of CodeBase...
 
frcardim:

mr. kozitsyn, 

congratulations for great job ! this is best Delta indicator until now, very fast.

Thanks!

I try modify it to plot only positive values with diferent color to buy/sell delta (best to compare size of histogram bars),without success, You can give some tipe how to do it or post where should modify the original code ?

Replace DisplayValues() function with this one:

//+------------------------------------------------------------------+
//| Отображение значений индикатора                                                                                             |
//+------------------------------------------------------------------+
void DisplayValues(const int index,// Номер свечи
                   const long sumVolBuy,// Суммарный объем покупок
                   const long sumVolSell,          // Суммарный объем продаж
                   const int line                  // Номер строки вызова функции
                   )
  {
//--- Проверяем корректность номера свечи
   if(index<0) // Если некорректный номер
     {
      Print(__FUNCTION__,": ОШИБКА! Некорректный номер свечи '",index,"'");
      return;                                       // Выходим
     }
//--- Рассчитаем дельту
   const double delta=double(sumVolBuy-sumVolSell);
//--- Заносим значения в буферы
   //bufDelta[ index ]= delta;                       // Записываем значение дельты
   bufDelta[ index ]= (delta>0) ? delta : -delta;  // Записываем значение дельты
   bufDeltaColor[ index ] =(delta>0) ?  0 : 1;     // Записываем цвет значения
   bufBuyVol[ index ] = (double)sumVolBuy;         // Записываем сумму покупок
   bufSellVol[ index ]=(double)sumVolSell;         // Записываем сумму продаж
  }

Another question, is it possible to plot a vertical instead horizontal histogram ? 

It's not possible in this indicator.
 

Mr. Kozitsyn,


First of alll, congratulations!!! Great, great, great job!!! That's what i'm looking for.

However, this indicator is half of my desire. I'd like to draw a bolinger band over delta indicator to show me where the money flow is greater than a normal behavior. I had tried this, but i  wasn't able to see the bbands lines at the same window. Could you help me?

Thanks a lot!!!


Rodrigo Pimenta

 
rpimentaf:

Could you help me?

Thanks a lot!!!


Rodrigo Pimenta

Sorry, but I don't work with BB.

You can use Freelance for your task.

 
Alexey Kozitsyn:

In general, on our market using ticks and glass you can do very cool things.

I agree with you. I have been watching Delta for a long time, I don't use it often

You have a great indicator, it even works for me on weekends!

I watch the delta on timeframes less than a minute, when the price breaks the local high and instead of stops (blue delta) there are market sales. Usually after such a set-up, the price makes a correction.

picture

Well, it's just like that, just on the topic.

My question is different. I have recently started to learn how to write indicators. I am slowly mastering them, using the scientific method and copypaste.

I wanted to write a delta divergence indicator. This is the code of delta selling delta of AP bars (red), and blue delta of down bars.

With the help of your indicator, through iCustom my indicator works normally.

But since I am learning, I am interested in writing my own. And my own indicator does not work (. It is the third day I am beating over it, and it does not give in. If it is not difficult, please tell me what is the error.

The logic of determining the delta is as follows: since I don't need the delta on the current bar, I decided that I can calculate the delta using the tick volume of the previous bar OnCalculate, tick_volume[] , as the number of ticks when copying CopyTicks. The meta-editor compiles, but gives a warning that I use different data types in tick volume long, and in CopyTicks it is necessary to specify the number of ticks in uint. The time of copying start is taken in the same time[],

When testing in the tester it gives the error "Array out of range", and I can't understand what limits it goes beyond and how to determine what to change to make the indicator not work, but at least remove this error.

Here's the code of the adder, please don't laugh too much.

#property indicator_chart_window 
#property indicator_buffers 5 
#property indicator_plots   1
  
#property indicator_label1  "Diver_handl" 
#property indicator_type1   DRAW_COLOR_CANDLES 
//--- set 2 colours to paint candles (they are stored in the colour buffer) 
#property indicator_color1  clrRed,clrBlue
#property indicator_style1  STYLE_SOLID 
#property indicator_width1  1 // line drawing thickness, not really needed here.

//--- input parameters 
//--- indicator buffers
double         ColorCandlesBuffer1[];//candle buffers
double         ColorCandlesBuffer2[];
double         ColorCandlesBuffer3[];
double         ColorCandlesBuffer4[];
double         ColorCandlesColors[]; // Colour buffer

string symbol;  //--- character name 
double _Delta;
//+------------------------------------------------------------------+ 
//| Custom indicator initialisation function | 
//+------------------------------------------------------------------+ 
int OnInit()
  {
//--- indicator buffers mapping 
   SetIndexBuffer(0,ColorCandlesBuffer1,INDICATOR_DATA);
   SetIndexBuffer(1,ColorCandlesBuffer2,INDICATOR_DATA);
   SetIndexBuffer(2,ColorCandlesBuffer3,INDICATOR_DATA);
   SetIndexBuffer(3,ColorCandlesBuffer4,INDICATOR_DATA);
   SetIndexBuffer(4,ColorCandlesColors,INDICATOR_COLOR_INDEX);
   
//--- empty value (value that will not be drawn) 
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   
//--- name of the symbol by which bars are drawn 
   symbol=_Symbol;
   
//--- set the symbol display 
   PlotIndexSetString(0,PLOT_LABEL,symbol+" Open;"+symbol+" High;"+symbol+" Low;"+symbol+" Close");
   IndicatorSetString(INDICATOR_SHORTNAME,"Diver("+symbol+")");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+ 
//| Custom indicator iteration function | 
//+------------------------------------------------------------------+ 
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 i,limit;
   int buf_size=rates_total-prev_calculated;
   if(rates_total<2)
      return(0);

   if(prev_calculated<3)
     {
      limit=1;
      // initialise arrays with empty values
      ArrayInitialize(ColorCandlesBuffer1,EMPTY_VALUE);
      ArrayInitialize(ColorCandlesBuffer2,EMPTY_VALUE);
      ArrayInitialize(ColorCandlesBuffer3,EMPTY_VALUE);
      ArrayInitialize(ColorCandlesBuffer4,EMPTY_VALUE);
      ArrayInitialize(ColorCandlesColors,EMPTY_VALUE);
     }
   else limit=rates_total-1;

   MqlTick Ticks[];   //declare an array to be filled with tick data
   
   for(i=limit; i<rates_total-1; i++)
     {
      CopyTicks(Symbol(),Ticks,COPY_TICKS_TRADE,0,tick_volume[i]);  // copy to the Ticks array the tick data in the amount equal to the tick volume in the candle tick_volume[i]
      SetBarData(time[i],Ticks,i,_Delta,tick_volume[i]);// function in the basement ↓

      if(open[i-1]<close[i-1] && _Delta<0)
        {
         ColorCandlesBuffer1[i-1]=open[i-1];
         ColorCandlesBuffer2[i-1]=high[i-1];
         ColorCandlesBuffer3[i-1]=low[i];
         ColorCandlesBuffer4[i-1]=close[i];
         ColorCandlesColors[i-1]=1;
        }
      else if(open[i]>close[i] && _Delta>0)
        {
         ColorCandlesBuffer1[i-1]=open[i-1];
         ColorCandlesBuffer2[i-1]=high[i-1];
         ColorCandlesBuffer3[i-1]=low[i];
         ColorCandlesBuffer4[i-1]=close[i];
         ColorCandlesColors[i-1]=0;
        }
      else
        {
         ColorCandlesBuffer1[i]=0.0;
         ColorCandlesBuffer2[i]=0.0;
         ColorCandlesBuffer3[i]=0.0;
         ColorCandlesBuffer4[i]=0.0;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
// Fills the bar with appropriate ticks
void SetBarData(const datetime TimeBar,const MqlTick &Ticks[],int &Pos,double &Delta,const long vol)
  {
  int i=0;
   while(i<vol)
     {
      MqlTick Tick=Ticks[Pos];  // copy tick data buffer readings into the variable
      if(i>=vol)
         break;   // when i sanset is equal to tick volume , vail †
      if((bool)(Tick.flags  &TICK_FLAG_BUY))  // if the flag is buy add to the delta
         Delta+=(double)Tick.volume;
      else if((bool)(Tick.flags  &TICK_FLAG_SELL)) // if the flag is Sell, subtract from the delta
         Delta-=(double)Tick.volume;
      i++;
     }
   return;
  }
//+------------------------------------------------------------------+
I experimented a lot, so there may be artefacts from previous experiments, in the form of declared but not used variables.
 
s22aa:

If it is not difficult, please tell me what the error is.

I can't see the exact place with the error at first glance, but, for starters, look at how CopyTicks() is handled in my indicator. In particular, return of the value and handling of possible errors.

Yes, if an array overrun occurs... see how many values are in the array and which element you are accessing. You can also unpaint the first and last value after receiving data to see if all data was received.

 
Alexey Kozitsyn:

see how CopyTicks() is handled in my indicator.

Wow, it's complicated. Ticks are copied both by time interval and by number. In general, the system is duplicated no worse than in cosmonauts))))

I found where I did it.

MqlTick Tick = Ticks[Pos];

I'm trying to copy an array into a variable. It is strange why the compiler does not react to it, and when you run it in the tester, the tester hangs.

I'll try to think of something else.
 
s22aa:

I'm trying to copy an array into a variable.


No, you're not. That's right. I'm totally confused. I'm gonna have a better morning. Tomorrow, it'll all work out.