_tp BrianIndex (SinglePair) V2.02

Download script
_tp BrianIndex (SinglePair) V2.02

This indicator is designed to provide traders with a visual representation of price movement relative to historical weekly data. It focuses on calculating specific "levels" based on how much the market has historically fluctuated during previous weeks, allowing users to see potential areas of high interest or resistance.

Core Logic and Functionality

Historical Data Analysis The script begins by scanning a significant amount of historical weekly data (based on a user-defined timeframe). It calculates the average distance between the highest highs and the lowest lows compared to the previous week's closing price. By doing this, it establishes a "standard" for how much the market typically swings in a given period.

Price Level Calculations Once the historical averages are established, the script identifies several key levels:

  • High and Low Indicators: It uses two different multipliers (factors) to project potential upper and lower boundaries.
  • Multipliers: These factors allow the indicator to show both "primary" and "secondary" levels, helping traders distinguish between different zones of significance.

Real-Time Tracking The script dynamically tracks the current price movement relative to the previous week's closing price. It converts this difference into "pips," providing a clear numerical value of how far the market has traveled since the start of the trading period.

Visual Presentation

To ensure clarity for the user, the indicator produces several visual components:

  • Dynamic Lines: The script draws five distinct lines on a separate window (not directly on the price chart). These represent the calculated high/low levels and the current price progress.
  • Live Dashboard: A set of labels is generated on the screen to provide an immediate snapshot of data. This includes:
    • Current High Levels (HH1 and HH2)
    • Current Low Levels (LL1 and LL2)
    • The "Current" value showing the live price displacement.
    • A counter showing how many weeks of history were analyzed to generate the data.

User Customization

The logic is designed to be flexible, allowing users to adjust:

  • Timeframes: The user can choose which specific timeframe (e.g., M15, H1, D1) the indicator should prioritize for its calculations.
  • Smoothing: It includes options for different Moving Average types (SMA, EMA, LWMA) to influence how data is smoothed.
  • Sensitivity Factors: Users can modify the "Level Factors" to expand or contract the projected high and low zones based on their specific trading style.
Price Data Components
Series 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 barSeries array that contains open time of each barSeries array that contains close prices for each bar
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
_tp BrianIndex (SinglePair) V2.02
//+------------------------------------------------------------------+
//|                            _tp BrianIndex (SinglePair) V2.02.mq4 |
//|                                                                  |
//|  V2.00                                                           |
//|     1) Add 90% & 30% lines                                       |
//|                                                                  |
//|  V2.01                                                           |
//|     1) Show multiple history week value                          |
//|                                                                  |
//|  V2.02                                                           |
//|     1) Fix ObjectCreate error                                    |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers      5
#property indicator_color1       Blue        
#property indicator_color2       Orange       
#property indicator_color3       Orange        
#property indicator_color4       Lime        
#property indicator_color5       Lime        

#property indicator_style1 STYLE_SOLID
#property indicator_style2 STYLE_DOT
#property indicator_style3 STYLE_DOT
#property indicator_style4 STYLE_DOT
#property indicator_style5 STYLE_DOT


#property indicator_level1       0
#property indicator_levelcolor   DarkGray

extern double Level1Factor = 2.3;
extern double Level2Factor = 0.85;
extern int HistoryWeek      = 104;
extern int FontSize         = 16;

string TimeFrame_value = "TimeFrame(0,M5,M15,M30,H1,D1)";
string TimeFrame = "0";
string MA_Type_value = "SMA, EMA, LWMA";
string MA_Type = "SMA";

int timeFrame = 0;
double pair1Close;
int totalWeek = 0;
int lastDay = 0;
int maType;

double BufBI[];
double BufBIHHLevel1[];
double BufBIHHLevel2[];
double BufBILLLevel2[];
double BufBILLLevel1[];

int MaxWeek = 0;
double WeekCloseArray[];
double WeekHHpipsArray[];
double WeekLLpipsArray[];
int History2, History3, History4, History5;

datetime LastWeekDateTime = 0;

string sShortName = "_tp BI (SP) V2.02";

int objectcnt=1;

int init() {

   IndicatorBuffers(5);

   IndicatorShortName(sShortName);


   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexStyle(4,DRAW_LINE);
   
   SetIndexLabel(0,"BI");
   SetIndexLabel(1,"HH1");
   SetIndexLabel(2,"HH22");
   SetIndexLabel(3,"LL2");
   SetIndexLabel(4,"LL1");

   SetIndexBuffer(0,BufBI);
   SetIndexBuffer(1,BufBIHHLevel1);
   SetIndexBuffer(2,BufBIHHLevel2);
   SetIndexBuffer(3,BufBILLLevel2);
   SetIndexBuffer(4,BufBILLLevel1);
   
   
   if (MA_Type == "SMA") {

      maType = MODE_SMA;

   } else if (MA_Type == "EMA") {

      maType = MODE_EMA;

   } else if (MA_Type == "LWMA") {

      maType = MODE_LWMA;

   } else {

      maType = MODE_SMA;

   }


   if (TimeFrame == "M5") {

      timeFrame = PERIOD_M5;

   } else if (TimeFrame == "M15") {

      timeFrame = PERIOD_M15;

   } else if (TimeFrame == "M30") {

      timeFrame = PERIOD_M30;

   } else if (TimeFrame == "H1") {

      timeFrame = PERIOD_H1;

   } else if (TimeFrame == "D1") {

      timeFrame = PERIOD_D1;

   } else {

      timeFrame = 0;

   }

//   HistoryWeek = MathMin(HistoryWeek+1, iBars(NULL,PERIOD_W1)) - 1;
   ArrayResize(WeekCloseArray, HistoryWeek);
   ArrayResize(WeekHHpipsArray, HistoryWeek);
   ArrayResize(WeekLLpipsArray, HistoryWeek);

   return(0);

}

int deinit() {

   ObjectsDeleteAll(0, OBJ_VLINE);

   return(0);
}

int start() {

   int i, j, counted_bars = IndicatorCounted();
   int AvailableWeek = 0;
   
   i = Bars - counted_bars - 1;
   
   
   double TotalHHtoLastFriClose = 0.0; 
   double TotalLLtoLastFriClose = 0.0;

   if (LastWeekDateTime != iTime(NULL,PERIOD_W1,1) )
   {
      for (j = HistoryWeek; j>0; j--)
      {
         if (iClose(NULL,PERIOD_W1,j+1) > 0)
         {
            TotalHHtoLastFriClose = TotalHHtoLastFriClose  + ( iHigh(NULL,PERIOD_W1,j) - iClose(NULL,PERIOD_W1,j+1) );
            TotalLLtoLastFriClose = TotalLLtoLastFriClose  + ( iLow(NULL,PERIOD_W1,j) - iClose(NULL,PERIOD_W1,j+1) );
            AvailableWeek++;
         }
      }
      TotalHHtoLastFriClose = TotalHHtoLastFriClose / AvailableWeek / MarketInfo(Symbol(),MODE_POINT);
      TotalLLtoLastFriClose = TotalLLtoLastFriClose / AvailableWeek / MarketInfo(Symbol(),MODE_POINT);

      LastWeekDateTime = iTime(NULL,PERIOD_D1,1);
    }

   while (i >= 0) 
   {

      int timeFrameIndex = iBarShift(0, timeFrame, Time[i], true);

      if ((TimeDayOfWeek(iTime(NULL, timeFrame, timeFrameIndex)) == 1 && TimeDayOfWeek(iTime(NULL, timeFrame, timeFrameIndex+1)) == 5) ||
         (TimeDayOfWeek(iTime(NULL, timeFrame, timeFrameIndex)) == 0 && TimeDayOfWeek(iTime(NULL, timeFrame, timeFrameIndex+1)) == 5)){

         pair1Close = iClose(NULL, timeFrame, timeFrameIndex+1);  // closes of last week
      }
      

      if (pair1Close > 0 && TimeDayOfWeek(iTime(NULL, timeFrame, i)) >= 1) 
      {
          
          if (lastDay != TimeDayOfWeek(iTime(NULL, timeFrame, i))) 
          {
            lastDay = TimeDayOfWeek(iTime(NULL, timeFrame, i));
            totalWeek = 0;

          }

          BufBI[i] = (iClose(Symbol(), timeFrame, i) - pair1Close)/MarketInfo(Symbol(),MODE_POINT);
          BufBIHHLevel1[i] = TotalHHtoLastFriClose * Level1Factor;
          BufBIHHLevel2[i] = TotalHHtoLastFriClose * Level2Factor;
          BufBILLLevel2[i] = TotalLLtoLastFriClose * Level2Factor;
          BufBILLLevel1[i] = TotalLLtoLastFriClose * Level1Factor;
      } 

      i--;

   }
   
   objectcnt=1;
   
   CreateLabelObject("HH1 = ",FontSize,3,Orange);
   CreateLabelObject(DoubleToStr(BufBIHHLevel1[0],0),FontSize,2,Orange);
   objectcnt++;
   CreateLabelObject("HH2 = ",FontSize,3,Orange);
   CreateLabelObject(DoubleToStr(BufBIHHLevel2[0],0),FontSize,2,Orange);
   objectcnt++;
   CreateLabelObject("Cur = ",FontSize,3,White);
   CreateLabelObject(DoubleToStr(BufBI[0],0),FontSize,2,White);
   objectcnt++;
   CreateLabelObject("LL2 = ",FontSize,3,Lime);
   CreateLabelObject(DoubleToStr(BufBILLLevel2[0],0),FontSize,2,Lime);
   CreateLabelObject(DoubleToStr(AvailableWeek,0),8,1,Gray);
   objectcnt++;
   CreateLabelObject("LL1 = ",FontSize,3,Lime);
   CreateLabelObject(DoubleToStr(BufBILLLevel1[0],0),FontSize,2,Lime);
   objectcnt++;


   return(0);
}

string formatInteger(int value) {

   if (value < 10) {
   
      return("0" + value);
   
   } else {
   
      return("" + value);
   
   }

}




void CreateLabelObject(string sString, int iFontSize, int iColumn, color cColor)
{
   string objectname = sShortName+objectcnt+"_"+iColumn;
   int xx;
   
   if (iColumn == 1)
      xx = 10;
   else if (iColumn == 2)
      xx = 10 + 20;
   else if (iColumn == 3)
      xx = 10 + 60;

   ObjectDelete(objectname);  
   ObjectCreate(objectname, OBJ_LABEL, WindowFind(sShortName), 0, 0);
   ObjectSet(objectname, OBJPROP_CORNER, 1);
   ObjectSet(objectname, OBJPROP_XDISTANCE, xx);
   ObjectSet(objectname, OBJPROP_YDISTANCE, 3+(objectcnt-1)*(iFontSize + 6));  
   ObjectSetText(objectname,sString, iFontSize,"Arial" ,cColor);

}

//+------------------------------------------------------------------+

Comments