Floor_Pivots_Daily_Mid

Floor_Pivots_Daily_Mid
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
Floor_Pivots_Daily_Mid
//+------------------------------------------------------------------+
//|                                       Floor_Pivots_Daily_Mid.mq4 |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property link      "http://www.metaquotes.net"
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 C'200,200,200'
#property indicator_color2 C'100,100,100'
#property indicator_color3 C'100,100,100'
#property indicator_color4 C'000,100,000'
#property indicator_color5 C'000,100,000'
#property indicator_color6 C'100,000,000'
#property indicator_color7 C'100,000,000'

//Input Params
extern string PivotStart = "22:00";
extern string PivotEnd   = "22:00";

double Buffer1[]; // Pivot Point
double Buffer2[]; // PivotRangeHigh
double Buffer3[]; // PivotRangeLow
double Buffer4[]; // Mid R1-R2
double Buffer5[]; // Mid PP-R1
double Buffer6[]; // Mid PP-S1
double Buffer7[]; // Mid S1-S2

double LastHigh,LastLow,LastClose;
double PivP, PivD, PivH, PivL;
double PivotRangeHigh, PivotRangeLow;
double PivR1, PivR2, PivR3;
double PivS1, PivS2, PivS3;
double PPR1, R1R2, PPS1, S1S2;

int OpenBar;
    
int init()
{  SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,167);
   SetIndexBuffer(0,Buffer1);
   
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,160);
   SetIndexBuffer(1,Buffer2);
   
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,160);
   SetIndexBuffer(2,Buffer3);
   
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,160);
   SetIndexBuffer(3,Buffer4);
   
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexArrow(4,160);
   SetIndexBuffer(4,Buffer5);
   
   SetIndexStyle(5,DRAW_ARROW);
   SetIndexArrow(5,160);
   SetIndexBuffer(5,Buffer6);
   
   SetIndexStyle(6,DRAW_ARROW);
   SetIndexArrow(6,160);
   SetIndexBuffer(6,Buffer7);
   
   return(0); }

int deinit()
   {
	ObjectDelete("PRP");
	ObjectDelete("PRH");
	ObjectDelete("PRL");
	ObjectDelete("R2R1");
	ObjectDelete("R1PP");
	ObjectDelete("S1PP");
	ObjectDelete("S2S1");
	Comment("");
	return(0);
   }

int start()
{  if (Period() > 240) return(0);		//Chart cannot be higher than H4
   string BarTime="", LastBarTime="";         
   string BarDay="",  LastBarDay="";
   int CloseBar;
          
   for(int i=Bars; i>=0; i--)
   {  BarTime = TimeToStr(Time[i], TIME_MINUTES);
      LastBarTime = TimeToStr(Time[i+1], TIME_MINUTES);
      BarDay = TimeToStr(Time[i],TIME_DATE);
      LastBarDay = TimeToStr(Time[i+1],TIME_DATE); 
      
      //need to handle if pivotrangestart/end is 00:00
      if ((PivotEnd == "00:00" && BarTime>=PivotEnd && BarDay>LastBarDay) || (BarTime>=PivotEnd && LastBarTime<PivotEnd))
      {  CloseBar = i + 1;
         
         if (OpenBar>0)
         {  calculatePivotRangeValues(OpenBar, CloseBar);  }  }
      
      if ((PivotStart == "00:00" && BarTime>=PivotStart && BarDay>LastBarDay) || (BarTime>=PivotStart && LastBarTime<PivotStart))
      { OpenBar = i; }
      
      if (OpenBar>0)
      { drawIndicators(i);  } }
   return(0);}
void calculatePivotRangeValues(int openBar, int closeBar)
   {
   LastHigh = High[Highest(NULL, 0, MODE_HIGH, (openBar - closeBar + 1), closeBar)];
   LastLow = Low[Lowest(NULL, 0, MODE_LOW, (openBar - closeBar + 1), closeBar)];
   LastClose = Close[closeBar];
   
   PivP = (LastHigh + LastLow + LastClose) / 3;
   PivD = MathAbs(((LastHigh + LastLow)/2) - PivP);      

   PivotRangeHigh = PivP + PivD;
   PivotRangeLow  = PivP - PivD;

   PivR3 = (2*PivP)+(LastHigh-(2*LastLow));
   PivR2 = PivP+(LastHigh - LastLow);
   PivR1 = (2*PivP)-LastLow;
   PivS1 = (2*PivP)-LastHigh;
   PivS2 = PivP-(LastHigh - LastLow);
   PivS3 = (2*PivP)-((2* LastHigh)-LastLow);
   
   R1R2  = (PivR1 + PivR2) / 2;
   PPR1  = (PivP  + PivR1) / 2;
   PPS1  = (PivP  + PivS1) / 2;
   S1S2  = (PivS1 + PivS2) / 2;
   
   }

void drawIndicators(int curBar)
   {
//   Buffer1[curBar] = PivP;
   Buffer2[curBar] = PivotRangeHigh;
   Buffer3[curBar] = PivotRangeLow;
   Buffer4[curBar] = R1R2;
   Buffer5[curBar] = PPR1;
   Buffer6[curBar] = PPS1;
   Buffer7[curBar] = S1S2;
   
   DoLabel("PRP", Buffer1[0], indicator_color1);
 //DoLabel("PRH", Buffer2[0], indicator_color2);
 //DoLabel("PRL", Buffer3[0], indicator_color3);
   DoLabel("R2R1", Buffer4[0], indicator_color4);
   DoLabel("R1PP", Buffer5[0], indicator_color5);
   DoLabel("S1PP", Buffer6[0], indicator_color6);
   DoLabel("S2S1", Buffer7[0], indicator_color7);
   return(0); }
	
void DoLabel( string dName, double dValue, color dColor )
   {
   if (ObjectFind(dName) != 0)
      {
      ObjectCreate(dName,OBJ_ARROW,0,Time[0],dValue);
      ObjectSet(dName,OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
      ObjectSet(dName,OBJPROP_COLOR,dColor);  
      } 
   else
      {
      ObjectMove(dName,0,Time[0],dValue);
      }
   }
//+-----------------------------------------------------------------------------------------+
//|                                         THE END                                         |
//+-----------------------------------------------------------------------------------------+

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 ---