PIVOTS cja
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 close prices for each bar
0 Views
0 Downloads
0 Favorites
PIVOTS cja
//+------------------------------------------------------------------+
//|                                                       PIVOTS.mq4 |
//|                             Copyright © 2006, cjatradingtools.com|
//+------------------------------------------------------------------+
#property copyright " By cja -  http://cjatradingtools.com/"

#property indicator_chart_window
extern bool Show_PivotLines = true;
extern bool Show_M_PivotLines = true;
extern int Shift_Lines_START  = -20;
extern int Shift_Lines_END  = -100;
extern int SHIFT_PivotPointText = -30;
extern int SHIFT_M_PivotText = -30;
extern color PivotLabel_Col = DimGray;
extern color CentralPivot_Color = DarkSlateGray;
extern int CentralPivot_width = 2;
extern int Pivots_width = 1;
extern int Pivots_style= 0;
extern color MainLabel_Col= DimGray;
extern color R3_Color = DarkSlateGray;
extern color R2_Color = DarkSlateGray;
extern color R1_Color = DarkSlateGray;
extern color S1_Color = DarkSlateGray;
extern color S2_Color = DarkSlateGray;
extern color S3_Color = DarkSlateGray;
extern int MPivots_width = 1; 
extern int MPivots_style= 2;
extern color MLabel_Col = DimGray;
extern color M5_Color = DarkSlateGray;
extern color M4_Color = DarkSlateGray;
extern color M3_Color = DarkSlateGray;
extern color M2_Color = DarkSlateGray;
extern color M1_Color = DarkSlateGray;
extern color M0_Color = DarkSlateGray;
extern string txt = "----edit text here---";
extern string S1txt = "S1 ";
extern string S2txt = "S2 ";
extern string S3txt = "S3 ";
extern string Ptxt = "Pivot ";
extern string R1txt = "R1 ";
extern string R2txt = "R1 ";
extern string R3txt = "R1 ";


extern bool  Show_Daily_HILOW = false;


#define PP1 "PP1"
#define RR3 "RR3"
#define RR2 "RR2"
#define RR1 "RR1"
#define SS1 "SS1"
#define SS2 "SS2"
#define SS3 "SS3"

#define MM1 "MM1"   
#define MM2 "MM2"
#define MM3 "MM3"
#define MM4 "MM4"
#define MM5 "MM5"
#define MM0 "MM0"


#define HI "DailyHI"
#define LO "DailyLO"

double x;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
IndicatorShortName("PIVOTS");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
        
   ObjectDelete(PP1);ObjectDelete(RR3); ObjectDelete(RR3);ObjectDelete(RR2); ObjectDelete(RR1);ObjectDelete(SS1);
   ObjectDelete(SS2);ObjectDelete(SS3);ObjectDelete(MM1);ObjectDelete(MM2);ObjectDelete(MM3);ObjectDelete(MM4);
   ObjectDelete(MM5); ObjectDelete(MM0);
   ObjectDelete(HI);ObjectDelete(LO);  
   
   ObjectDelete("P");ObjectDelete("R3"); ObjectDelete("R2"); ObjectDelete("R1");ObjectDelete("S1");
   ObjectDelete("S2");ObjectDelete("S3");ObjectDelete("M1");ObjectDelete("M2");ObjectDelete("M3");ObjectDelete("M4");
   ObjectDelete("M5"); ObjectDelete("M0");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars= IndicatorCounted();
    x = Period();
       if(x > 240) return(-1); 
   
//----
   CreatePVT();
}

void CreatePivot(string Pivot, double start, double end,double w, double s,color clr)
  {
   ObjectCreate(Pivot, OBJ_TREND, 0, CustomTime(Shift_Lines_END), start, CustomTime(Shift_Lines_START), end);
   ObjectSet(Pivot, OBJPROP_COLOR, clr);
   ObjectSet(Pivot,OBJPROP_RAY,false);
   ObjectSet(Pivot,OBJPROP_WIDTH,w);
   ObjectSet(Pivot,OBJPROP_STYLE,s);
     }
        void DeletePivot()
   { 
   ObjectDelete(PP1); ObjectDelete(RR3); ObjectDelete(RR2); ObjectDelete(RR1); ObjectDelete(SS1); ObjectDelete(SS2);
   ObjectDelete(SS3);
    
   ObjectDelete(MM1); ObjectDelete(MM2); ObjectDelete(MM3); ObjectDelete(MM4); ObjectDelete(MM5); ObjectDelete(MM0);
   ObjectDelete(HI);ObjectDelete(LO);
   }
   void CreatePVT()
   {
   
     DeletePivot();
     
     

  
   
    double P = (iHigh(NULL,1440,1) + iLow(NULL,1440,1) + iClose(NULL,1440,1)) / 3;
         double rr3 = ( 2 * P ) + ( iHigh(NULL,1440,1) - ( 2 * iLow(NULL,1440,1) ));
         double rr2 = P + ( iHigh(NULL,1440,1) - iLow(NULL,1440,1) );
         double rr1 = ( 2 * P ) - iLow(NULL,1440,1);
         double ss1 = ( 2 * P ) - iHigh(NULL,1440,1);
         double ss2 = P - ( iHigh(NULL,1440,1)- iLow(NULL,1440,1));
         double ss3 = ( 2 * P ) - ( ( 2 * iHigh(NULL,1440,1) ) - iLow(NULL,1440,1) );
         
         double mm0 = (ss2 + ss3)/2;
         double mm1 = (ss1 + ss2)/2;
         double mm2 = (P + ss1)/2;
         double mm3 = (P + rr1)/2; 
         double mm4 = (rr1 + rr2)/2;
         double mm5 = (rr2 + rr3)/2; 
         
        double D_HI=iHigh(NULL,1440,1);
        double D_LO=iLow(NULL,1440,1);
       {  
          if (Show_PivotLines==true)
    {  
    ObjectDelete("P");  
      if(ObjectFind("P") != 0){
ObjectCreate("P", OBJ_TEXT, 0, CustomTime(SHIFT_PivotPointText), P);
ObjectSetText("P", Ptxt+DoubleToStr(P,Digits)+"", 8, "Arial", PivotLabel_Col);
}else{ObjectMove("P", 0, CustomTime(SHIFT_PivotPointText), P);}
     ObjectDelete("S3");
     if(ObjectFind("S3") != 0){
ObjectCreate("S3", OBJ_TEXT, 0, CustomTime(SHIFT_PivotPointText), ss3);
ObjectSetText("S3", S3txt+DoubleToStr(ss3,Digits)+"", 8, "Arial", MainLabel_Col);
}else{ObjectMove("S3", 0, CustomTime(SHIFT_PivotPointText), ss3);}
     ObjectDelete("S2");
     if(ObjectFind("S2") != 0){
ObjectCreate("S2", OBJ_TEXT, 0, CustomTime(SHIFT_PivotPointText), ss2);
ObjectSetText("S2", S2txt+DoubleToStr(ss2,Digits)+"", 8, "Arial", MainLabel_Col);
}else{ObjectMove("S2", 0, CustomTime(SHIFT_PivotPointText), ss2);}
     ObjectDelete("S1");
     if(ObjectFind("S1") != 0){
ObjectCreate("S1", OBJ_TEXT, 0, CustomTime(SHIFT_PivotPointText), ss1);
ObjectSetText("S1", S1txt+DoubleToStr(ss1,Digits)+"", 8, "Arial", MainLabel_Col);
}else{ObjectMove("S1", 0, CustomTime(SHIFT_PivotPointText), ss1);}
     ObjectDelete("R1");
     if(ObjectFind("R1") != 0){
ObjectCreate("R1", OBJ_TEXT, 0, CustomTime(SHIFT_PivotPointText), rr1);
ObjectSetText("R1", R1txt+DoubleToStr(rr1,Digits)+"", 8, "Arial", MainLabel_Col);
}else{ObjectMove("R1", 0, CustomTime(SHIFT_PivotPointText), rr1);}
     ObjectDelete("R2");
     if(ObjectFind("R2") != 0){
ObjectCreate("R2", OBJ_TEXT, 0, CustomTime(SHIFT_PivotPointText), rr2);
ObjectSetText("R2", R2txt+DoubleToStr(rr2,Digits)+"", 8, "Arial", MainLabel_Col);
}else{ObjectMove("R2", 0, CustomTime(SHIFT_PivotPointText), rr2);}
     ObjectDelete("R3");
     if(ObjectFind("R3") != 0){
ObjectCreate("R3", OBJ_TEXT, 0, CustomTime(SHIFT_PivotPointText), rr3);
ObjectSetText("R3", R3txt+DoubleToStr(rr3,Digits)+"", 8, "Arial", MainLabel_Col);
}else{ObjectMove("R3", 0, CustomTime(SHIFT_PivotPointText), rr3);}
}
 if (Show_M_PivotLines==true) 
         {
     ObjectDelete("M5");    
     if(ObjectFind("M5") != 0){
ObjectCreate("M5", OBJ_TEXT, 0, CustomTime(SHIFT_M_PivotText), mm5);
ObjectSetText("M5", "M5 "+DoubleToStr(mm5,Digits)+"", 8, "Arial", MLabel_Col);
}else{ObjectMove("M5", 0, CustomTime(SHIFT_M_PivotText), mm5);}
     ObjectDelete("M4"); 
     if(ObjectFind("M4") != 0){
ObjectCreate("M4", OBJ_TEXT, 0, CustomTime(SHIFT_M_PivotText), mm4);
ObjectSetText("M4", "M4 "+DoubleToStr(mm4,Digits)+"", 8, "Arial", MLabel_Col);
}else{ObjectMove("M4", 0, CustomTime(SHIFT_M_PivotText), mm4);}
     ObjectDelete("M3"); 
     if(ObjectFind("M3") != 0){
ObjectCreate("M3", OBJ_TEXT, 0, CustomTime(SHIFT_M_PivotText), mm3);
ObjectSetText("M3", "M3 "+DoubleToStr(mm3,Digits)+"", 8, "Arial", MLabel_Col);
}else{ObjectMove("M3", 0, CustomTime(SHIFT_M_PivotText), mm3);}
     ObjectDelete("M2"); 
     if(ObjectFind("M2") != 0){
ObjectCreate("M2", OBJ_TEXT, 0, CustomTime(SHIFT_M_PivotText), mm2);
ObjectSetText("M2", "M2 "+DoubleToStr(mm2,Digits)+"", 8, "Arial", MLabel_Col);
}else{ObjectMove("M2", 0, CustomTime(SHIFT_M_PivotText), mm2);}
     ObjectDelete("M1");  
     if(ObjectFind("M1") != 0){
ObjectCreate("M1", OBJ_TEXT, 0, CustomTime(SHIFT_M_PivotText), mm1);
ObjectSetText("M1", "M1 "+DoubleToStr(mm1,Digits)+"", 8, "Arial", MLabel_Col);
}else{ObjectMove("M1", 0, CustomTime(SHIFT_M_PivotText), mm1);}
     ObjectDelete("M0"); 
     if(ObjectFind("M0") != 0){
ObjectCreate("M0", OBJ_TEXT, 0, CustomTime(SHIFT_M_PivotText), mm0);
ObjectSetText("M0", "M0 "+DoubleToStr(mm0,Digits)+"", 8, "Arial", MLabel_Col);
}else{ObjectMove("M0", 0, CustomTime(SHIFT_M_PivotText), mm0);}
}
         if(Show_Daily_HILOW==true){
         CreatePivot(HI,D_HI,D_HI,1,2, Lime);
         CreatePivot(LO,D_LO,D_LO,1,2, Red);}       
    
         CreatePivot(PP1,P,P,CentralPivot_width,0,CentralPivot_Color);
         CreatePivot(RR3,rr3,rr3,Pivots_width,Pivots_style, R3_Color );
         CreatePivot(RR2,rr2,rr2,Pivots_width,Pivots_style, R2_Color );
         CreatePivot(RR1,rr1,rr1,Pivots_width,Pivots_style, R1_Color );
         CreatePivot(SS1,ss1,ss1,Pivots_width,Pivots_style, S1_Color);
         CreatePivot(SS2,ss2,ss2,Pivots_width,Pivots_style, S2_Color);
         CreatePivot(SS3,ss3,ss3,Pivots_width,Pivots_style, S3_Color);   
         }
        
     if (Show_M_PivotLines==true) 
         {
          CreatePivot(MM1,mm1,mm1,MPivots_width,MPivots_style, M1_Color);
          CreatePivot(MM2,mm2,mm2,MPivots_width,MPivots_style, M2_Color);
          CreatePivot(MM3,mm3,mm3,MPivots_width,MPivots_style, M3_Color);
          CreatePivot(MM4,mm4,mm4,MPivots_width,MPivots_style, M4_Color);
          CreatePivot(MM5,mm5,mm5,MPivots_width,MPivots_style, M5_Color);
          CreatePivot(MM0,mm0,mm0,MPivots_width,MPivots_style, M0_Color);
                  
        	}          
    
//----
   return(0);
  }
  
    
  int CustomTime(int a)
{
if(a<0)
return(Time[0]+Period()*60*MathAbs(a));
else return(Time[a]); 
}
//+------------------------------------------------------------------+

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