DayCandleAsStock

Author: AlexALL
Price Data Components
Series array that contains open prices of each barSeries array that contains close prices for each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
0 Views
0 Downloads
0 Favorites
DayCandleAsStock
//+------------------------------------------------------------------+
//|                                              DayCandleAsStock.mq5|
//|                                                          AlexALL |
//|                                                 alex-all@mail.ru |
//+------------------------------------------------------------------+
#property copyright "AlexALL"
#property link      "alex-all@mail.ru"
#property version   "1.00"
//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots   1
#property indicator_type1   DRAW_COLOR_CANDLES
#property indicator_color1  Green, Red
#property indicator_label1  "Day Candles As Stock"
//---
input int  HourBegin=9;
input int  HourEnd=23;
//--- indicator buffers
double ExtOBuffer[];
double ExtHBuffer[];
double ExtLBuffer[];
double ExtCBuffer[];
double ExtColorBuffer[];
datetime shift,arr[],arr2[];
int ishift;
string symbol;
 //ChartSetSymbolPeriod(0,Symbol(),PERIOD_D1);

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- indicator buffers mapping
   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);
//---
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- sets first bar from what index will be drawn
   IndicatorSetString(INDICATOR_SHORTNAME,"AsStock");
//--- sets drawing line empty value
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
//--- initialization done
 if (ChartPeriod()!=PERIOD_D1)
 {
     ChartSetSymbolPeriod(0,Symbol(),PERIOD_D1);
 CopyTime(Symbol(),PERIOD_D1,0,iBars(Symbol(),PERIOD_D1),arr);
     
     ChartRedraw();
     Sleep(100);
  }   
 ChartSetInteger(0,CHART_MODE,CHART_LINE);   
 long color1=ChartGetInteger(0,CHART_COLOR_BACKGROUND);
 ChartSetInteger(0,CHART_COLOR_CHART_LINE,color1);
 ChartSetInteger(0,CHART_FOREGROUND,false);
 shift=(HourEnd)*3600;
 if(HourEnd<HourBegin)shift+=86400;
 ishift=(HourEnd-HourBegin);
 if(ishift<0)ishift+=24;
 CopyTime(Symbol(),PERIOD_H1,0,iBars(Symbol(),PERIOD_H1),arr2);
 symbol=Symbol();
 
  }
//+------------------------------------------------------------------+
//| Heiken Ashi                                                      |
//+------------------------------------------------------------------+
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 &TickVolume[],
                const long &Volume[],
                const int &Spread[])
  {
   int i,limit,barBegin,barEnd,ih,il;
   datetime end;
//--- preliminary calculations
   if(prev_calculated==0)
     {
      //--- set first candle
      ExtLBuffer[0]=Low[0];
      ExtHBuffer[0]=High[0];
      ExtOBuffer[0]=Open[0];
      ExtCBuffer[0]=Close[0];
      limit=1;
     }
   else limit=prev_calculated-1;

//--- the main loop of calculations
   for(i=limit;i<rates_total;i++)
     {
      end=Time[i]+shift;
      barEnd=iBarShift(symbol,PERIOD_H1,end,false);
      barBegin=barEnd+ishift;
      double haOpen=iOpen(symbol,PERIOD_H1,barBegin);
      double haClose=iClose(symbol,PERIOD_H1,barEnd);
      ih=iHighest(symbol,PERIOD_H1,MODE_HIGH,ishift,barEnd);
      il=iLowest(symbol,PERIOD_H1,MODE_LOW,ishift,barEnd);
      double haHigh=iHigh(symbol,PERIOD_H1,ih);
      double haLow=iLow(symbol,PERIOD_H1,il);

      ExtLBuffer[i]=haLow;
      ExtHBuffer[i]=haHigh;
      ExtOBuffer[i]=haOpen;
      ExtCBuffer[i]=haClose;

      //--- set candle color
      if(haOpen<haClose) ExtColorBuffer[i]=0.0; // set color DodgerBlue
      else               ExtColorBuffer[i]=1.0; // set color Red
     }
//--- done
   return(rates_total);
  }
//+------------------------------------------------------------------+

Comments