Probuilder - 4h Pivot Code Help

Hi. I wonder if anyone can help me. I have found some code and successfully modified it to work with Monthly, Weekly,Daily, and 1h Pivots, however its beyond me how I can get this to work with 4h Pivots. I know we have some really great programmers on the boards and I hope someone could help me. I have included the code below for the Daily and Weekly Pivots.

Its for the ProRealTime software I use.

If anyone can tell me how to get the code below working for 4h pivots, or show me where im going wrong I would be extremely grateful! :slight_smile:


Weekly Pivots

IF DAYOFWEEK < DAYOFWEEK[1] THEN
weekhigh = prevweekhigh
weeklow = prevweeklow
weekclose = prevweekclose
prevweekhigh = HIGH
prevweeklow = LOW
ENDIF

prevweekhigh = MAX(prevweekhigh, HIGH)
prevweeklow = MIN(prevweeklow, LOW)
prevweekclose = CLOSE

PP = (weekhigh + weeklow + weekclose)/3
// RANGE = PREVIOUS DAY’S HIGH - PREVOIUS DAY’S LOW
PRANGE = weekhigh - weeklow

// Resistance 2 : PP+RANGE
PR2 = PP + PRANGE
// Résistance 1 : (2PP)-LOW
PR1 = 2 * PP - weeklow
//R3 := 2
PP + (high - 2low);
PR3 = 2
PP + (weekhigh - (2weeklow))
// Support 1 : (2
PP)-H
PS1 = 2 * PP - weekhigh
// Support 2 : PP-RANGE
PS2 = PP - PRANGE
// S3 := 2PP - (2high - low);
PS3 = 2PP - (2weekhigh-weeklow)
// MID POINT BETWEEN S2 AND RS3
M0 = (PS2 + PS3) / 2
// MID POINT BETWEEN S2 AND R1
M1 = (PS2 + PS1) / 2
// MID POINT BETWEEN PP AND S1
M2 = (PP + PS1) / 2
// MID POINT BETWEEN PP AND R1
M3 = (PP + PR1) / 2
// MID POINT BETWEEN R2 AND R1
M4 = (PR2 + PR1) / 2
//MID POINT BETWEEN R2 AND R3;
M5 = (PR2 + PR3)/2

RETURN PR3 as “Res3” ,PR2 AS “Res2” , M4 AS “M4” , PR1 AS “Res1” , PS3 AS “Sup 3” ,M3 AS “M3” , PP AS “Pivot” , M2 AS “M2” , PS1 AS “Sup1” , M1 AS “M1” , PS2 AS “Sup2” ,M5 as “M5” , M0 AS “MO”


Daily Pivots

REM Daily Pivot Points indicator - Use on intraday charts only.

pivotmethod = 0

IF BARINDEX = 0 THEN

initialization = 2 // we are in the middle of a day
resistance3 = UNDEFINED
resistance2 = UNDEFINED
resistance1 = UNDEFINED
p = UNDEFINED
support1 = UNDEFINED
support2 = UNDEFINED
support3 = UNDEFINED

M0 = UNDEFINED
M1 = UNDEFINED
M2 = UNDEFINED
M3 = UNDEFINED
M4 = UNDEFINED
M5 = UNDEFINED

ELSE

IF DAYOFWEEK[1] <> DAYOFWEEK THEN

prevmax = newmax
prevmin = newmin
prevclose = newclose

newmax = HIGH
newmin = LOW
newopen = OPEN
newclose = CLOSE

initialization = MAX(0, initialization - 1)
// initialization = 1 means that we are in the first entire day
// initialization = 0 means that we are in at least the second day

ELSE

newmax = MAX(newmax, HIGH)
newmin = MIN(newmin, LOW)
newclose = close

// uniquement apres les initialisations
IF initialization = 0 THEN
IF pivotmethod = 0 THEN
p = (prevmax + prevmin + prevclose) / 3
ELSIF pivotmethod = 1 THEN
p = (prevmax + prevmin + prevclose + newopen) / 4
ELSE
p = (prevmax + prevmin + newopen) / 3
ENDIF

resistance2 = p + (resistance1-support1)
resistance1 = (2 * p) - prevmin
P = p
support1 = (2 * p) - prevmax
support2 = p - (resistance1 - support1)

REM Formula for midpoints, S3 and R3 lines, remove comments to activate them and replace the "return line in the code with the commented return line below it.

resistance3 = prevmax + 2*(p-prevmin)
support3 = prevmin - 2*(prevmax-p)

M0 = (support3 + support2)/2
M1 = (support2 + support1)/2
M2 = (support1+p)/2
M3 = (resistance1+ p)/2
M4 = (resistance1+resistance2)/2
M5 = (resistance2+resistance3)/2
ENDIF

ENDIF

ENDIF

//RETURN resistance2 as “R2” , resistance1 as “R1” , P as “pivot” , support1 as “S1” , support2 as “S2”

Return M0 as “M0 Daily”, M1 as “M1 Daily”, M2 as “M2 Daily”, M3 as “M3 Daily”, M4 as “M4 Daily”, M5 as “M5 Daily”, resistance2 as “R2 Daily” , resistance1 as “R1 Daily” , P as “pivot Daily” , support1 as “S1 Daily” , support2 as “S2 Daily”, resistance3 as “R3 Daily”, support3 as “S3 Daily”


I have something similar coded in MQL4. I’ve made the indicator myself, if you want I can upload it for you.

Please! If nothing else it may give me something to go on. Im really not a coder though so im stabbing in the dark a bit with all this!

All right there you go:

//±-----------------------------------------------------------------+
//| PP_Gica.mq4 |
//| Copyright © 2011, MetaQuotes Software Corp. |
//| MetaTrader 5 Trading Platform / MetaQuotes Software Corp. |
//±-----------------------------------------------------------------+
#property copyright “Copyright © 2011, MetaQuotes Software Corp.”
#property link “http://www.metaquotes.net

extern int period = 1;

extern bool Daily = true;
extern bool Weekly = false;
extern bool Monthly = false;
extern bool Hourly = false;

extern color clr_Pivot = Black;
extern color clr_R = SteelBlue;
extern color clr_S = Red;
extern color clr_M = Orange;

#property indicator_chart_window
//±-----------------------------------------------------------------+
//| Custom indicator initialization function |
//±-----------------------------------------------------------------+
int init()
{
//---- indicators
//----
return(0);
}
//±-----------------------------------------------------------------+
//| Custom indicator deinitialization function |
//±-----------------------------------------------------------------+
int deinit()
{
ObjectsDeleteAll (0,OBJ_HLINE);
return(0);
}
//±-----------------------------------------------------------------+
//| Custom indicator iteration function |
//±-----------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();

//Base pivot parameters for daily
int normalizer = 5;
/*
double high;
double low;
double close;
*/

//Pivot point parameter data
double d_h = iHigh (Symbol (),PERIOD_D1,period);
double d_l = iLow (Symbol (),PERIOD_D1,period);
double d_c = iClose(Symbol (),PERIOD_D1,period);

double w_h = iHigh (Symbol (),PERIOD_W1,period);
double w_l = iLow (Symbol (),PERIOD_W1,period);
double w_c = iClose(Symbol (),PERIOD_W1,period);

double m_h = iHigh (Symbol (),PERIOD_MN1,period);
double m_l = iLow (Symbol (),PERIOD_MN1,period);
double m_c = iClose(Symbol (),PERIOD_MN1,period);

double h_h = iHigh (Symbol (),PERIOD_H1,period);
double h_l = iLow (Symbol (),PERIOD_H1,period);
double h_c = iClose(Symbol (),PERIOD_H1,period);

if (Daily == true)
{
double pivot = NormalizeDouble((d_h + d_l + d_c)/3,normalizer);

double r1 = NormalizeDouble((2pivot)- d_l,normalizer);
double r2 = NormalizeDouble(pivot + (d_h - d_l),normalizer);
double r3 = NormalizeDouble (d_h + 2
(pivot - d_l),normalizer);

double s1 = NormalizeDouble((2pivot)- d_h,normalizer);
double s2 = NormalizeDouble(pivot - (d_h - d_l),normalizer);
double s3 = NormalizeDouble (d_l - 2
(d_h - pivot),normalizer);

double m5 = NormalizeDouble (r1 + (r2 - r1)/2,normalizer);
double m4 = NormalizeDouble (pivot + (r1 - pivot)/2,normalizer);
double m3 = NormalizeDouble (s1 + (pivot - s1)/2,normalizer);
double m2 = NormalizeDouble (s2 + (s1-s2)/2,normalizer);

ObjectCreate (“d_pivot”,OBJ_HLINE, 0,0,pivot);
ObjectSet (“d_pivot”, OBJPROP_COLOR,clr_Pivot);
ObjectSet (“d_pivot”, OBJPROP_WIDTH,2);

ObjectCreate (“d_r1”,OBJ_HLINE, 0,0,r1);
ObjectSet (“d_r1”, OBJPROP_COLOR,clr_R);
ObjectCreate (“d_r2”,OBJ_HLINE, 0,0,r2);
ObjectSet (“d_r2”, OBJPROP_COLOR,clr_R);
ObjectCreate (“d_r3”,OBJ_HLINE, 0,0,r3);
ObjectSet (“d_r3”, OBJPROP_COLOR,clr_R);

ObjectCreate (“d_s1”,OBJ_HLINE, 0,0,s1);
ObjectSet (“d_s1”, OBJPROP_COLOR,clr_S);
ObjectCreate (“d_s2”,OBJ_HLINE, 0,0,s2);
ObjectSet (“d_s2”, OBJPROP_COLOR,clr_S);
ObjectCreate (“d_s3”,OBJ_HLINE, 0,0,s3);
ObjectSet (“d_s3”, OBJPROP_COLOR,clr_S);

ObjectCreate (“d_m2”,OBJ_HLINE, 0,0,m2);
ObjectSet (“d_m2”, OBJPROP_COLOR,clr_M);
ObjectCreate (“d_m3”,OBJ_HLINE, 0,0,m3);
ObjectSet (“d_m3”, OBJPROP_COLOR,clr_M);
ObjectCreate (“d_m4”,OBJ_HLINE, 0,0,m4);
ObjectSet (“d_m4”, OBJPROP_COLOR,clr_M);
ObjectCreate (“d_m5”,OBJ_HLINE, 0,0,m5);
ObjectSet (“d_m5”, OBJPROP_COLOR,clr_M);
}

if (Weekly == true)
{
double w_pivot = NormalizeDouble((w_h + w_l + w_c)/3,normalizer);

double w_r1 = NormalizeDouble((2w_pivot)- w_l,normalizer);
double w_r2 = NormalizeDouble(w_pivot + (w_h - w_l),normalizer);
double w_r3 = NormalizeDouble (w_h + 2
(w_pivot - w_l),normalizer);

double w_s1 = NormalizeDouble((2w_pivot)- w_h,normalizer);
double w_s2 = NormalizeDouble(w_pivot - (w_h - w_l),normalizer);
double w_s3 = NormalizeDouble (w_l - 2
(w_h - w_pivot),normalizer);

double w_m5 = NormalizeDouble (w_r1 + (w_r2 - w_r1)/2,normalizer);
double w_m4 = NormalizeDouble (w_pivot + (w_r1 - w_pivot)/2,normalizer);
double w_m3 = NormalizeDouble (w_s1 + (w_pivot - w_s1)/2,normalizer);
double w_m2 = NormalizeDouble (w_s2 + (w_s1-w_s2)/2,normalizer);

ObjectCreate (“w_pivot”,OBJ_HLINE, 0,0,w_pivot);
ObjectSet (“w_pivot”, OBJPROP_COLOR,clr_Pivot);
ObjectSet (“w_pivot”, OBJPROP_WIDTH,2);

ObjectCreate (“w_r1”,OBJ_HLINE, 0,0,w_r1);
ObjectSet (“w_r1”, OBJPROP_COLOR,clr_R);
ObjectCreate (“w_r2”,OBJ_HLINE, 0,0,w_r2);
ObjectSet (“w_r2”, OBJPROP_COLOR,clr_R);
ObjectCreate (“w_r3”,OBJ_HLINE, 0,0,w_r3);
ObjectSet (“w_r3”, OBJPROP_COLOR,clr_R);

ObjectCreate (“w_s1”,OBJ_HLINE, 0,0,w_s1);
ObjectSet (“w_s1”, OBJPROP_COLOR,clr_S);
ObjectCreate (“w_s2”,OBJ_HLINE, 0,0,w_s2);
ObjectSet (“w_s2”, OBJPROP_COLOR,clr_S);
ObjectCreate (“w_s3”,OBJ_HLINE, 0,0,w_s3);
ObjectSet (“w_s3”, OBJPROP_COLOR,clr_S);

ObjectCreate (“w_m2”,OBJ_HLINE, 0,0,w_m2);
ObjectSet (“w_m2”, OBJPROP_COLOR,clr_M);
ObjectCreate (“w_m3”,OBJ_HLINE, 0,0,w_m3);
ObjectSet (“w_m3”, OBJPROP_COLOR,clr_M);
ObjectCreate (“w_m4”,OBJ_HLINE, 0,0,w_m4);
ObjectSet (“w_m4”, OBJPROP_COLOR,clr_M);
ObjectCreate (“w_m5”,OBJ_HLINE, 0,0,w_m5);
ObjectSet (“w_m5”, OBJPROP_COLOR,clr_M);
}

if (Monthly == true)
{
double m_pivot = NormalizeDouble((m_h + m_l + m_c)/3,normalizer);

double m_r1 = NormalizeDouble((2m_pivot)- m_l,normalizer);
double m_r2 = NormalizeDouble(m_pivot + (m_h - m_l),normalizer);
double m_r3 = NormalizeDouble (m_h + 2
(m_pivot - m_l),normalizer);

double m_s1 = NormalizeDouble((2m_pivot)- m_h,normalizer);
double m_s2 = NormalizeDouble(m_pivot - (m_h - m_l),normalizer);
double m_s3 = NormalizeDouble (m_l - 2
(m_h - m_pivot),normalizer);

double m_m5 = NormalizeDouble (m_r1 + (m_r2 - m_r1)/2,normalizer);
double m_m4 = NormalizeDouble (m_pivot + (m_r1 - m_pivot)/2,normalizer);
double m_m3 = NormalizeDouble (m_s1 + (m_pivot - m_s1)/2,normalizer);
double m_m2 = NormalizeDouble (m_s2 + (m_s1-m_s2)/2,normalizer);

ObjectCreate (“m_pivot”,OBJ_HLINE, 0,0,m_pivot);
ObjectSet (“m_pivot”, OBJPROP_COLOR,clr_Pivot);
ObjectSet (“m_pivot”, OBJPROP_WIDTH,2);

ObjectCreate (“m_r1”,OBJ_HLINE, 0,0,m_r1);
ObjectSet (“m_r1”, OBJPROP_COLOR,clr_R);
ObjectCreate (“m_r2”,OBJ_HLINE, 0,0,m_r2);
ObjectSet (“m_r2”, OBJPROP_COLOR,clr_R);
ObjectCreate (“m_r3”,OBJ_HLINE, 0,0,m_r3);
ObjectSet (“m_r3”, OBJPROP_COLOR,clr_R);

ObjectCreate (“m_s1”,OBJ_HLINE, 0,0,m_s1);
ObjectSet (“m_s1”, OBJPROP_COLOR,clr_S);
ObjectCreate (“m_s2”,OBJ_HLINE, 0,0,m_s2);
ObjectSet (“m_s2”, OBJPROP_COLOR,clr_S);
ObjectCreate (“m_s3”,OBJ_HLINE, 0,0,m_s3);
ObjectSet (“m_s3”, OBJPROP_COLOR,clr_S);

ObjectCreate (“m_m2”,OBJ_HLINE, 0,0,m_m2);
ObjectSet (“m_m2”, OBJPROP_COLOR,clr_M);
ObjectCreate (“m_m3”,OBJ_HLINE, 0,0,m_m3);
ObjectSet (“m_m3”, OBJPROP_COLOR,clr_M);
ObjectCreate (“m_m4”,OBJ_HLINE, 0,0,m_m4);
ObjectSet (“m_m4”, OBJPROP_COLOR,clr_M);
ObjectCreate (“m_m5”,OBJ_HLINE, 0,0,m_m5);
ObjectSet (“m_m5”, OBJPROP_COLOR,clr_M);
}

if (Hourly == true)
{
double h_pivot = NormalizeDouble((h_h + h_l + h_c)/3,normalizer);

double h_r1 = NormalizeDouble((2h_pivot)- h_l,normalizer);
double h_r2 = NormalizeDouble(h_pivot + (h_h - h_l),normalizer);
double h_r3 = NormalizeDouble (h_h + 2
(h_pivot - h_l),normalizer);

double h_s1 = NormalizeDouble((2h_pivot)- h_h,normalizer);
double h_s2 = NormalizeDouble(h_pivot - (h_h - h_l),normalizer);
double h_s3 = NormalizeDouble (h_l - 2
(h_h - h_pivot),normalizer);

double h_m5 = NormalizeDouble (h_r1 + (h_r2 - h_r1)/2,normalizer);
double h_m4 = NormalizeDouble (h_pivot + (h_r1 - h_pivot)/2,normalizer);
double h_m3 = NormalizeDouble (h_s1 + (h_pivot - h_s1)/2,normalizer);
double h_m2 = NormalizeDouble (h_s2 + (h_s1-h_s2)/2,normalizer);

ObjectCreate (“h_pivot”,OBJ_HLINE, 0,0,h_pivot);
ObjectSet (“h_pivot”, OBJPROP_COLOR,clr_Pivot);
ObjectSet (“h_pivot”, OBJPROP_WIDTH,2);

ObjectCreate (“h_r1”,OBJ_HLINE, 0,0,h_r1);
ObjectSet (“h_r1”, OBJPROP_COLOR,clr_R);
ObjectCreate (“h_r2”,OBJ_HLINE, 0,0,h_r2);
ObjectSet (“h_r2”, OBJPROP_COLOR,clr_R);
ObjectCreate (“h_r3”,OBJ_HLINE, 0,0,h_r3);
ObjectSet (“h_r3”, OBJPROP_COLOR,clr_R);

ObjectCreate (“h_s1”,OBJ_HLINE, 0,0,h_s1);
ObjectSet (“h_s1”, OBJPROP_COLOR,clr_S);
ObjectCreate (“h_s2”,OBJ_HLINE, 0,0,h_s2);
ObjectSet (“h_s2”, OBJPROP_COLOR,clr_S);
ObjectCreate (“h_s3”,OBJ_HLINE, 0,0,h_s3);
ObjectSet (“h_s3”, OBJPROP_COLOR,clr_S);

ObjectCreate (“h_m2”,OBJ_HLINE, 0,0,h_m2);
ObjectSet (“h_m2”, OBJPROP_COLOR,clr_M);
ObjectCreate (“h_m3”,OBJ_HLINE, 0,0,h_m3);
ObjectSet (“h_m3”, OBJPROP_COLOR,clr_M);
ObjectCreate (“h_m4”,OBJ_HLINE, 0,0,h_m4);
ObjectSet (“h_m4”, OBJPROP_COLOR,clr_M);
ObjectCreate (“h_m5”,OBJ_HLINE, 0,0,h_m5);
ObjectSet (“h_m5”, OBJPROP_COLOR,clr_M);
}

//Difference from open to pivot
/*
double m_range = MathAbs(m_pivot - m_o)*10000;
Comment ("T/P: " + m_range);
*/
return(0);
}
//±-----------------------------------------------------------------+

There you go:

double h_h = iHigh (Symbol (),PERIOD_H1,period);
double h_l = iLow (Symbol (),PERIOD_H1,period);
double h_c = iClose(Symbol (),PERIOD_H1,period);

At this point, you just change PERIOD_H1 to PERIOD_H4 >> save and compile and it’s all done.

I’m uploading the indicator itself just in case you might wanna use it. Just a note though, I haven’t used it for a while, I’m not sure if it perfectly bug free for I’m not much of a programmer.

Pivot Point Gica.zip (12.4 KB)

Good luck.