Rj_HSlice 1.1

Download script
Author: Copyright � 2011, RJ Rjabkov Aleksandr
Rj_HSlice 1.1

This script is designed to provide traders with a visual representation of market volume and pressure by analyzing historical price data. It identifies areas where buying and selling forces are concentrated, allowing for a clearer understanding of market sentiment.

Core Logic Overview

The script operates by scanning a specific timeframe (user-defined) over a set period of days. It calculates the price range across this history to create a vertical "map" of the market. Every price point within this range is then evaluated to determine the intensity of buying versus selling activity.

Key Functionalities

  • Volume Distribution Mapping The script categorizes volume into "Buy" and "Sell" categories. It creates a visual histogram where different colors represent dominant forces:

    • Greenish tones indicate areas where buying pressure is stronger.
    • Reddish tones indicate areas where selling pressure is stronger.
    • Aqua/Blue tones highlight neutral zones where buying and selling pressures are equal.
  • Dynamic Visual Customization Users can choose how this data is displayed on their charts:

    • Background Levels: Shows the entire history of volume distribution across the visible chart area.
    • Limited View: Focuses the visual data on a specific number of bars for a cleaner, more localized look at current market dynamics.
  • Volume Concentration Analysis The script identifies "clusters" of activity. It calculates the total accumulated volume for specific price levels where significant trading occurred. These totals are displayed as text labels on the chart, providing a quantitative look at how many contracts or units were traded at those specific points.

  • Turning Point Detection One of the most sophisticated parts of the logic is its ability to identify "Turning Points." The script compares the proximity of buying and selling clusters:

    • It looks for instances where significant buy and sell volumes are happening very close to each other (within a small percentage of difference).
    • When these two opposing forces meet in a tight price range, the script identifies this as a potential "turning point."
    • It then automatically draws a horizontal line at that specific price level to alert the trader to a zone where the market trend might shift or consolidate.

Summary for the Trader

Instead of just looking at raw price movements, this tool helps you see the "footprints" left by other participants. By highlighting where heavy buying and selling are concentrated and identifying exactly where those forces collide, it provides a map of significant support, resistance, and potential trend reversals.

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
3 Views
0 Downloads
0 Favorites
Rj_HSlice 1.1
//+------------------------------------------------------------------+
//|                                                Rj_HSlice 1.1.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      = 30;
extern double UpdateTime        = 1;
extern int    CalcPeriod        = 1;
extern double PercentDiscrep    = 0.2;
extern bool   ShowLevelsOn      = true;
extern bool   ShowTurningOn     = true;
extern bool   ShowContractOn    = true;
extern bool   BackgroundLevelOn = true;
extern color  ColorLine         = Aqua;

double lBuy[];
double lSell[];
double ValueCall[][2], ValuePut[][2];
static datetime LastTime=0;
static datetime StartTime=1;

int init() {
  return(0);
}

int deinit() {
  for (int i=0; i<4000; i++) {
    ObjectDelete("vhb "+i); 
    ObjectDelete("V "+i);
    ObjectDelete("H "+i);
  }
  Comment("");
  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);
    string DataComment="";
    switch(CalcPeriod) {
      case 1: DataComment="ìèíóòíûé"; break;
      case 5: DataComment="ïÿòü ìèíóò"; break;
      case 15: DataComment="ïÿòíàäöàòü ìèíóò"; break;
      case 30: DataComment="òðèäöàòü ìèíóò"; break;
      case 60: DataComment="÷àñîâîé"; break;
      case 240: DataComment="÷åòûðå ÷àñà"; break;
      case 1440: DataComment="äíåâíîé"; break;
      case 10080: DataComment="íåäåëüíûé"; break;
      case 43200: DataComment="ìåñÿ÷íûé"; break;
      default : DataComment="òåêóùèé"; break;
    }
    Comment("\n Ïåðèîä ðàñ÷¸òà äàííûõ: "+DataComment);
    
    if(CalcPeriod>1 && CalcPeriod<5) {CalcPeriod=5; DataComment="ïÿòü ìèíóò";}
    if(CalcPeriod>5 && CalcPeriod<15) {CalcPeriod=15; DataComment="ïÿòíàäöàòü ìèíóò";}
    if(CalcPeriod>15 && CalcPeriod<30) {CalcPeriod=30; DataComment="òðèäöàòü ìèíóò";}
    if(CalcPeriod>30 && CalcPeriod<60) {CalcPeriod=60; DataComment="÷àñîâîé";}
    if(CalcPeriod>60 && CalcPeriod<240) {CalcPeriod=240; DataComment="÷åòûðå ÷àñà";}
    if(CalcPeriod>240 && CalcPeriod<1440) {CalcPeriod=1440; DataComment="äíåâíîé";}
    if(CalcPeriod>1440 && CalcPeriod<10080) {CalcPeriod=10080; DataComment="íåäåëüíûé";}
    if(CalcPeriod>10080 && CalcPeriod<43200) {CalcPeriod=43200; DataComment="ìåñÿ÷íûé";}
    if(CalcPeriod>43200) {CalcPeriod=43200; DataComment="ìåñÿ÷íûé";}
    
    
    for(i=0; i<=Range; i++) {
      lBuy[i]  = iCustom(NULL, CalcPeriod, "Rj_Volume", DepthCalcDay, 0, i);
      lSell[i] = iCustom(NULL, CalcPeriod, "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<=4000; i++) {
      ObjectDelete("vhb "+i); 
      ObjectDelete("V "+i);
      ObjectDelete("H "+i);
    }
    
    if(ShowLevelsOn) {
      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);
        }
      }
    }
    InstallVolume(lBuy, lSell, MinPrice, TimeVisiblBar, ValueCall, ValuePut);
    CalcTurning(ValueCall, ValuePut);
    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, double& ArrCall[][], double& ArrPut[][]) {
  int shift, j, indexCall=0, indexPut=0, inc;
  double DifBuy[], DifSell[], exit;
  
  ArrayResize(DifBuy, ArraySize(ArrBuy)+1);
  ArrayInitialize(DifBuy, 0.0);
  ArrayResize(DifSell, ArraySize(ArrBuy)+1);
  ArrayInitialize(DifSell, 0.0);
  ArrayResize(ArrCall, ArraySize(ArrBuy)+1);
  ArrayInitialize(ArrCall, 0.0);
  ArrayResize(ArrPut, ArraySize(ArrBuy)+1);
  ArrayInitialize(ArrPut, 0.0);
  if(Digits==5) inc=10; else inc=100;
  for(shift=0; shift<=ArraySize(ArrBuy); shift++) {
    if(ArrBuy[shift]>ArrSell[shift]) DifBuy[shift]=MathRound((ArrBuy[shift]-ArrSell[shift])*inc);
    if(ArrBuy[shift]<ArrSell[shift]) DifSell[shift]=MathRound((ArrSell[shift]-ArrBuy[shift])*inc);
  }

  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--;
      }
      if(ShowTurningOn) {
        ArrCall[indexCall][0]=Value;
        ArrCall[indexCall][1]=pos+(shift+j)*Point/2;
      }
      if(ShowContractOn) {
        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);
      }
      indexCall++;
    }
    if(DifSell[shift-1]!=0.0 && DifSell[shift]==0.0) {
      j = shift-1;
      while(DifSell[j]!=0.0) {
        Value += DifSell[j];
        j--;
      }
      if(ShowTurningOn) {
        ArrPut[indexPut][0]=Value;
        ArrPut[indexPut][1]=pos+(shift+j)*Point/2;
      }
      if(ShowContractOn) {
        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);
      }
      indexPut++;
    }
  }
}

void  CalcTurning(double& ArrCall[][], double& ArrPut[][]) {
  int index;
  int count=ArraySize(ArrPut);
  double ratio, max, min, coordinat;
  for(index=1; index<count; index++) {
    if(ArrCall[index+1][0]==0.0 && ArrPut[index+1][0]==0.0) {
      return;
    } else {
      if(ArrCall[index][1]<ArrPut[index][1]) {
        max=MathMax(ArrCall[index][0], ArrPut[index][0]);
        min=MathMin(ArrCall[index][0], ArrPut[index][0]);
        ratio=max*PercentDiscrep;
        if(max-min<ratio) {
          coordinat=MathRound((ArrCall[index][1]+ArrPut[index][1])/Point/2)*Point;
          InstallTurning(coordinat, index);
        }
        max=MathMax(ArrCall[index][0], ArrPut[index-1][0]);
        min=MathMin(ArrCall[index][0], ArrPut[index-1][0]);
        ratio=max*PercentDiscrep;
        if(max-min<ratio) {
          coordinat=MathRound((ArrCall[index][1]+ArrPut[index-1][1])/Point/2)*Point;
          InstallTurning(coordinat, index);
        }
      }
      if(ArrCall[index][1]>ArrPut[index][1]) {
        max=MathMax(ArrCall[index][0], ArrPut[index][0]);
        min=MathMin(ArrCall[index][0], ArrPut[index][0]);
        ratio=max*PercentDiscrep;
        if(max-min<ratio) {
          coordinat=MathRound((ArrCall[index][1]+ArrPut[index][1])/Point/2)*Point;
          InstallTurning(coordinat, index);
        }
        max=MathMax(ArrCall[index][0], ArrPut[index+1][0]);
        min=MathMin(ArrCall[index][0], ArrPut[index+1][0]);
        ratio=max*PercentDiscrep;
        if(max-min<ratio) {
          coordinat=MathRound((ArrCall[index][1]+ArrPut[index+1][1])/Point/2)*Point;
          InstallTurning(coordinat, index);
        }
      }
    }      
  }
}

void InstallTurning(double coord, int index) {
  if(ShowTurningOn) {
    ObjectCreate("H "+index, OBJ_HLINE, 0,0,0,0,0);
    ObjectSet("H "+index, OBJPROP_PRICE1, coord);
    ObjectSet("H "+index, OBJPROP_COLOR, ColorLine);
    ObjectSet("H "+index, OBJPROP_WIDTH, 2);
    ObjectSet("H "+index, OBJPROP_BACK, false);
  }
}

Comments