Rj_HSlice_1_0

Author: Copyright � 2011, RJ Rjabkov Aleksandr
Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains open time of each bar
0 Views
0 Downloads
0 Favorites
Rj_HSlice_1_0
//+------------------------------------------------------------------+
//|                                                Rj_HSlice 1.0.mq4 |
//|                           Copyright © 2011, RJ Rjabkov Aleksandr |
//|                                                     rj-a@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, RJ Rjabkov Aleksandr"
#property link      "rj-a@mail.ru"

#property indicator_chart_window

extern int DepthCalcDay       = 5;
extern double UpdateTime      = 1;
extern bool BackgroundLevelOn = true;
extern bool ValueContractOn   = true;

double lBuy[];
double lSell[];
static datetime LastTime=0;
static datetime StartTime=1;
int init() {
  return(0);
}

int deinit() {
  for (int i=0; i<3000; i++) {ObjectDelete("vhb "+i); ObjectDelete("V "+i);}
  return(0);
}
 
int start() {
  if(LastTime < StartTime) {
    int i, j, MaxVolume, EndTime, VolSlice;
    color ColLine;
    int TimeVisiblBar = WindowBarsPerChart()-WindowFirstVisibleBar();
    double MaxPrice = iHigh(NULL, PERIOD_D1, 0);
    double MinPrice = iLow(NULL, PERIOD_D1, 0);
    for(j=DepthCalcDay; j>=0; j--) {
      MaxPrice = MathMax(MaxPrice, iHigh(NULL, PERIOD_D1, j));
      MinPrice = MathMin(MinPrice, iLow(NULL, PERIOD_D1, j));
    }
    int Range = MathRound((MaxPrice-MinPrice)/Point);
    
    ArrayResize(lBuy, Range+1);
    ArrayInitialize(lBuy, 0.0);
    ArrayResize(lSell, Range+1);
    ArrayInitialize(lSell, 0.0);
    
    for(i=0; i<=Range; i++) {
      lBuy[i]  = iCustom(NULL, PERIOD_M1, "Rj_Volume", DepthCalcDay, 0, i);
      lSell[i] = iCustom(NULL, PERIOD_M1, "Rj_Volume", DepthCalcDay, 1, i);
    }
    
    if(MathRound(lBuy[ArrayMaximum(lBuy)])>=MathRound(lSell[ArrayMaximum(lSell)])) MaxVolume=MathRound(lBuy[ArrayMaximum(lBuy)]); 
    else MaxVolume=MathRound(lSell[ArrayMaximum(lSell)]);
    
    if(TimeVisiblBar<=2) TimeVisiblBar=50;
    
    for (i=0; i<=Range; i++) {ObjectDelete("vhb "+i); ObjectDelete("V "+i);}
    
    for(i=0; i<=Range; i++) {
      if(BackgroundLevelOn) {
        if(lBuy[i]>lSell[i]) {
          ColLine=C'64,136,50';
        }
        if(lBuy[i]<lSell[i]) {
          ColLine=C'218,118,125';
        }
        if(lBuy[i]==lSell[i]) {
          ColLine=Aqua;
        }
        ObjectCreate("vhb "+i, OBJ_RECTANGLE, 0, TimeStart(), MinPrice+i*Point, iTime(NULL, PERIOD_D1, DepthCalcDay), MinPrice+(i+1)*Point);
        ObjectSet("vhb "+i, OBJPROP_STYLE, DRAW_HISTOGRAM);
        ObjectSet("vhb "+i, OBJPROP_COLOR, ColLine);
        ObjectSet("vhb "+i, OBJPROP_BACK, true);
      }
      if(!BackgroundLevelOn) {
        if(lBuy[i]>lSell[i]) {
          EndTime = TimeStart()-(TimeVisiblBar-1)*Period()*60;
          ColLine=C'64,136,50';
        }
        if(lBuy[i]<lSell[i]) {
          EndTime = TimeStart()-(TimeVisiblBar-1)*Period()*60;
          ColLine=C'218,118,125';
        }
        if(lBuy[i]==lSell[i]) {
          EndTime = TimeStart()-(TimeVisiblBar-1)*Period()*60;
          ColLine=Aqua;
        }
        ObjectCreate("vhb "+i, OBJ_RECTANGLE, 0, TimeStart(), MinPrice+i*Point, EndTime, MinPrice+(i+1)*Point);
        ObjectSet("vhb "+i, OBJPROP_STYLE, DRAW_HISTOGRAM);
        ObjectSet("vhb "+i, OBJPROP_COLOR, ColLine);
        ObjectSet("vhb "+i, OBJPROP_BACK, true);
      }
    }
  if(ValueContractOn) InstallVolume(lBuy, lSell, MinPrice, TimeVisiblBar);
  StartTime=MathRound(TimeCurrent()+UpdateTime*60);
  }
  LastTime = TimeCurrent();
  return(0);
}
//+------------------------------------------------------------------+
datetime TimeStart() {
  int Indention = Time[0]+(WindowBarsPerChart()-WindowFirstVisibleBar())*Period()*60;
  return(Indention);
}

void InstallVolume(double ArrBuy[], double ArrSell[], double pos, int TimePos) {
  int shift, j;
  double DifBuy[], DifSell[], exit;
  
  ArrayResize(DifBuy, ArraySize(ArrBuy)+1);
  ArrayInitialize(DifBuy, 0.0);
  ArrayResize(DifSell, ArraySize(ArrBuy)+1);
  ArrayInitialize(DifSell, 0.0);
  
  for(shift=0; shift<=ArraySize(ArrBuy); shift++) {
    if(ArrBuy[shift]>ArrSell[shift]) DifBuy[shift]=MathRound((ArrBuy[shift]-ArrSell[shift])*100);
    if(ArrBuy[shift]<ArrSell[shift]) DifSell[shift]=MathRound((ArrSell[shift]-ArrBuy[shift])*100);
  }

  for(shift=1; shift<=ArraySize(ArrBuy); shift++) {
    double Value=0.0;
    if(DifBuy[shift-1]!=0.0 && DifBuy[shift]==0.0) {
      j = shift-1;
      while(DifBuy[j]!=0.0) {
        Value += DifBuy[j];
        j--;
      }
      exit = pos+(shift+j+4)*Point/2;
      ObjectCreate("V "+shift, OBJ_TEXT, 0, TimeStart()-((TimePos-6)*Period()*60), exit);
      ObjectSetText("V "+shift, DoubleToStr(Value, 0),8,"Tahoma",GreenYellow);
    }
    if(DifSell[shift-1]!=0.0 && DifSell[shift]==0.0) {
      j = shift-1;
      while(DifSell[j]!=0.0) {
        Value += DifSell[j];
        j--;
      }
      exit = pos+(shift+j+4)*Point/2;
      ObjectCreate("V "+shift, OBJ_TEXT, 0, TimeStart()-((TimePos-15)*Period()*60), exit);
      ObjectSetText("V "+shift, DoubleToStr(Value, 0),8,"Tahoma",Maroon);
    }
  }
}

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---