Price Data Components
Miscellaneous
2
Views
0
Downloads
0
Favorites
_TRO_TEMPLATE
//+------------------------------------------------------------------+
//| _TRO_TEMPLATE |
//| |
//| Copyright © 2007, Avery T. Horton, Jr. aka TheRumpledOne |
//| |
//| PO BOX 43575, TUCSON, AZ 85733 |
//| |
//| GIFT AND DONATIONS ACCEPTED |
//| |
//| http://docs.mql4.com/constants/wingdings | |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Avery T. Horton, Jr. aka TheRumpledOne"
#property link "therumpledone@gmail.com"
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 White
#property indicator_color2 Lime
#property indicator_color3 MediumTurquoise
#property indicator_color4 Red
#property indicator_color5 Yellow
#property indicator_color6 Orange
#property indicator_color7 OrangeRed
//---- For the small screens
//extern string Display_infos = "=== If true, displayed on the chart ===";
//extern bool display_on_chart = true ; // If true, the open trade analysis, daily pivots and daily range will be displayed on the chart window
// indicators parameters
extern bool iPlotChart = true ;
extern bool iPlotGauge = true ;
extern int LocalTimeZone= 0;
extern int DestTimeZone= 0;
extern int myPeriod = 1440 ;
extern int myOffset = 1 ;
extern int myChartY = 1 ;
extern int myStyle1 = 2 ;
extern int myStyle2 = 2 ;
extern int myStyle3 = 2 ;
extern int myStyle4 = 2 ;
extern int myStyle5 = 2 ;
extern int myStyle6 = 2 ;
extern int myStyle7 = 2 ;
extern int myWingDing1 = 115 ;
extern int myWingDing2 = 115 ;
extern int myWingDing3 = 115 ;
extern int myWingDing4 = 115 ;
extern int myWingDing5 = 115 ;
extern int myWingDing6 = 115 ;
extern int myWingDing7 = 115 ;
extern color myColor1 =White ;
extern color myColor2 =Lime;
extern color myColor3 =MediumTurquoise ;
extern color myColor4 =Red;
extern color myColor5 =Yellow;
extern color myColor6 =Orange;
extern color myColor7 =OrangeRed;
//---- buffers
double P1Buffer[];
double P2Buffer[];
double P3Buffer[];
double P4Buffer[];
double P5Buffer[];
double P6Buffer[];
double P7Buffer[];
double yesterday_high=0;
double yesterday_open=0;
double yesterday_low=0;
double yesterday_close=0;
double today_open=0;
double today_high=0;
double today_low=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- name for indicator window
string short_name=" ";
IndicatorShortName(short_name);
SetIndexBuffer(0, P1Buffer);
SetIndexBuffer(1, P2Buffer);
SetIndexBuffer(2, P3Buffer);
SetIndexBuffer(3, P4Buffer);
SetIndexBuffer(4, P5Buffer);
SetIndexBuffer(5, P6Buffer);
SetIndexBuffer(6, P7Buffer);
//----
SetIndexArrow(0, myWingDing1);
SetIndexArrow(1, myWingDing2);
SetIndexArrow(2, myWingDing3);
SetIndexArrow(3, myWingDing4);
SetIndexArrow(4, myWingDing5);
SetIndexArrow(5, myWingDing6);
SetIndexArrow(6, myWingDing7);
SetIndexStyle(0, DRAW_ARROW, myStyle1, 1);
SetIndexStyle(1, DRAW_ARROW, myStyle2, 1);
SetIndexStyle(2, DRAW_ARROW, myStyle3, 1);
SetIndexStyle(3, DRAW_ARROW, myStyle4, 1);
SetIndexStyle(4, DRAW_ARROW, myStyle5, 1);
SetIndexStyle(5, DRAW_ARROW, myStyle6, 1);
SetIndexStyle(6, DRAW_ARROW, myStyle7, 1);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
ObjectDelete("XXX");
ObjectDelete("line5XXX");
ObjectDelete("X01_LabelXXX");
ObjectDelete("X01_ValueXXX");
ObjectDelete("X02_LabelXXX");
ObjectDelete("X02_ValueXXX");
ObjectDelete("X03_LabelXXX");
ObjectDelete("X03_ValueXXX");
ObjectDelete("X04_LabelXXX");
ObjectDelete("X04_ValueXXX");
ObjectDelete("X05_LabelXXX");
ObjectDelete("X05_ValueXXX");
ObjectDelete("X06_LabelXXX");
ObjectDelete("X06_ValueXXX");
ObjectDelete("X07_LabelXXX");
ObjectDelete("X07_ValueXXX");
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i, dayi, counted_bars = IndicatorCounted();
//---- check for possible errors
if(counted_bars < 0)
return(-1);
//---- last counted bar will be recounted
if(counted_bars > 0)
counted_bars--;
int limit = Bars - counted_bars;
//----
for(i = limit - 1; i >= 0; i--)
{
dayi = iBarShift(Symbol(), myPeriod, Time[i], false);
double day_high = iHigh(Symbol(), myPeriod,dayi + myOffset );
double day_low = iLow(Symbol(), myPeriod,dayi + myOffset );
double day_close = iClose(Symbol(), myPeriod,dayi + myOffset );
double day_open = iOpen(Symbol(), myPeriod,dayi + myOffset );
double xRange = (day_high - day_low) ;
double xMid = (day_high + day_low)*0.50 ;
double X01 = day_open ; // Open
double X02 = day_high ; // High
double X03 = xMid ; // Middle
double X04 = day_low ; // Low
double X05 = day_close ; // Close
double X06 = yesterday_low - (xRange * 0.382 ) ; // fib 382
double X07 = yesterday_low - (xRange * 0.618 ) ; // fib 618
if ( iPlotChart ) {
P1Buffer[i] = X01 ;
P2Buffer[i] = X02 ;
P3Buffer[i] = X03 ;
P4Buffer[i] = X04 ;
P5Buffer[i] = X05 ;
P6Buffer[i] = X06 ;
P7Buffer[i] = X07 ;
int idxfirstbaroftoday= 0,
idxfirstbarofyesterday= 0,
idxlastbarofyesterday= 0;
// let's find out which hour bars make today and yesterday
ComputeDayIndices(LocalTimeZone, DestTimeZone, idxfirstbaroftoday, idxfirstbarofyesterday, idxlastbarofyesterday);
// draw the vertical bars that marks the time span
double level= (yesterday_high + yesterday_low + yesterday_close) / 3;
SetTimeLine("YesterdayStart", "Yesterday", idxfirstbarofyesterday, White, level+10*Point);
SetTimeLine("YesterdayEnd", "Today", idxfirstbaroftoday, White, level+10*Point);
} // iPlotChart
} // FOR
if ( iPlotGauge ) {
string StrX01 = "-XO1" ;
string StrX02 = "-XO2" ;
string StrX03 = "-XO3" ;
string StrX04 = "-XO4" ;
string StrX05 = "-XO5" ;
string StrX06 = "-XO6" ;
string StrX07 = "-XO7" ;
color color_XXX_1=Orchid;
color color_X01=Red;
color color_X02=Red;
color color_X03=Red;
color color_X04=Red;
color color_X05=Red;
color color_X06=Red;
color color_X07=Red;
if( Close[0] < X01) { color_X01=Lime; }
if( Close[0] < X02) { color_X02=Lime; }
if( Close[0] < X03) { color_X03=Lime; }
if( Close[0] < X04) { color_X04=Lime; }
if( Close[0] < X05) { color_X05=Lime; }
if( Close[0] < X06) { color_X06=Lime; }
// if( Close[0] < X07) { color_X07=Lime; }
int Precision, dig;
if( StringFind( Symbol(), "JPY", 0) != -1 ) { Precision = 100; dig = 2;}
else { Precision = 10000; dig = 4; }
int sPeriod= Period();
if (myPeriod != NULL){ sPeriod= myPeriod ;}
//---- Set labels
int WindowToUse;
int Corner_line, Xdist_line;
int Corner_text, Corner_ValueXXX, Xdist_text, Xdist_ValueXXX;
int Ydist_line5;
int Corner_pivots, Xdist_pivots, Ydist_pivots;
int Ydist_X01, Ydist_X02, Ydist_X03, Ydist_X04, Ydist_X05, Ydist_X06, Ydist_X07;
int YdistInc ;
WindowToUse = 0;
Corner_line = 1;
Corner_text = 1;
Corner_ValueXXX = 1;
Xdist_line = 21;
Xdist_text = 93;
Xdist_ValueXXX = 23;
Corner_pivots = 1;
Xdist_pivots = 21;
Ydist_pivots = myChartY;
Ydist_line5 =
Ydist_pivots + 11;
YdistInc = 15 ;
Ydist_X01 = Ydist_pivots + 25;
Ydist_X02 = Ydist_X01 + YdistInc;
Ydist_X03 = Ydist_X01 + YdistInc*2;
Ydist_X04 = Ydist_X01 + YdistInc*3;
Ydist_X05 = Ydist_X01 + YdistInc*4;
Ydist_X06 = Ydist_X01 + YdistInc*5;
Ydist_X07 = Ydist_X01 + YdistInc*6;
ObjectCreate("XXX", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("XXX",sPeriod + " XXX ",9, "Verdana", color_XXX_1);
ObjectSet("XXX", OBJPROP_CORNER, Corner_pivots);
ObjectSet("XXX", OBJPROP_XDISTANCE, Xdist_pivots);
ObjectSet("XXX", OBJPROP_YDISTANCE, Ydist_pivots);
ObjectCreate("line5XXX", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("line5XXX","---------------------",7, "Verdana", color_XXX_1);
ObjectSet("line5XXX", OBJPROP_CORNER, Corner_line);
ObjectSet("line5XXX", OBJPROP_XDISTANCE, Xdist_line);
ObjectSet("line5XXX", OBJPROP_YDISTANCE, Ydist_line5);
ObjectCreate("X01_LabelXXX", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("X01_LabelXXX",StrX01,9, "Verdana", myColor1);
ObjectSet("X01_LabelXXX", OBJPROP_CORNER, Corner_text);
ObjectSet("X01_LabelXXX", OBJPROP_XDISTANCE, Xdist_text);
ObjectSet("X01_LabelXXX", OBJPROP_YDISTANCE, Ydist_X01);
ObjectCreate("X01_ValueXXX", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("X01_ValueXXX"," "+DoubleToStr(X01,dig),9, "Verdana", color_X01);
ObjectSet("X01_ValueXXX", OBJPROP_CORNER, Corner_ValueXXX);
ObjectSet("X01_ValueXXX", OBJPROP_XDISTANCE, Xdist_ValueXXX);
ObjectSet("X01_ValueXXX", OBJPROP_YDISTANCE, Ydist_X01);
ObjectCreate("X02_LabelXXX", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("X02_LabelXXX",StrX02,9, "Verdana", myColor2);
ObjectSet("X02_LabelXXX", OBJPROP_CORNER, Corner_text);
ObjectSet("X02_LabelXXX", OBJPROP_XDISTANCE, Xdist_text);
ObjectSet("X02_LabelXXX", OBJPROP_YDISTANCE, Ydist_X02);
ObjectCreate("X02_ValueXXX", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("X02_ValueXXX"," "+DoubleToStr(X02,dig),9, "Verdana", color_X02);
ObjectSet("X02_ValueXXX", OBJPROP_CORNER, Corner_ValueXXX);
ObjectSet("X02_ValueXXX", OBJPROP_XDISTANCE, Xdist_ValueXXX);
ObjectSet("X02_ValueXXX", OBJPROP_YDISTANCE, Ydist_X02);
ObjectCreate("X03_LabelXXX", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("X03_LabelXXX",StrX03,9, "Verdana", myColor3 );
ObjectSet("X03_LabelXXX", OBJPROP_CORNER, Corner_text);
ObjectSet("X03_LabelXXX", OBJPROP_XDISTANCE, Xdist_text);
ObjectSet("X03_LabelXXX", OBJPROP_YDISTANCE, Ydist_X03);
ObjectCreate("X03_ValueXXX", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("X03_ValueXXX"," "+DoubleToStr(X03,dig),9, "Verdana", color_X03);
ObjectSet("X03_ValueXXX", OBJPROP_CORNER, Corner_ValueXXX);
ObjectSet("X03_ValueXXX", OBJPROP_XDISTANCE, Xdist_ValueXXX);
ObjectSet("X03_ValueXXX", OBJPROP_YDISTANCE, Ydist_X03);
ObjectCreate("X04_LabelXXX", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("X04_LabelXXX",StrX04,9, "Verdana", myColor4 );
ObjectSet("X04_LabelXXX", OBJPROP_CORNER, Corner_text);
ObjectSet("X04_LabelXXX", OBJPROP_XDISTANCE, Xdist_text);
ObjectSet("X04_LabelXXX", OBJPROP_YDISTANCE, Ydist_X04);
ObjectCreate("X04_ValueXXX", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("X04_ValueXXX"," "+DoubleToStr(X04,dig),9, "Verdana", color_X04);
ObjectSet("X04_ValueXXX", OBJPROP_CORNER, Corner_ValueXXX);
ObjectSet("X04_ValueXXX", OBJPROP_XDISTANCE, Xdist_ValueXXX);
ObjectSet("X04_ValueXXX", OBJPROP_YDISTANCE, Ydist_X04);
ObjectCreate("X05_LabelXXX", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("X05_LabelXXX",StrX05,9, "Verdana", myColor5 );
ObjectSet("X05_LabelXXX", OBJPROP_CORNER, Corner_text);
ObjectSet("X05_LabelXXX", OBJPROP_XDISTANCE, Xdist_text);
ObjectSet("X05_LabelXXX", OBJPROP_YDISTANCE, Ydist_X05);
ObjectCreate("X05_ValueXXX", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("X05_ValueXXX"," "+DoubleToStr(X05,dig),9, "Verdana", color_X05);
ObjectSet("X05_ValueXXX", OBJPROP_CORNER, Corner_ValueXXX);
ObjectSet("X05_ValueXXX", OBJPROP_XDISTANCE, Xdist_ValueXXX);
ObjectSet("X05_ValueXXX", OBJPROP_YDISTANCE, Ydist_X05);
ObjectCreate("X06_LabelXXX", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("X06_LabelXXX",StrX06,9, "Verdana", myColor6 );
ObjectSet("X06_LabelXXX", OBJPROP_CORNER, Corner_text);
ObjectSet("X06_LabelXXX", OBJPROP_XDISTANCE, Xdist_text);
ObjectSet("X06_LabelXXX", OBJPROP_YDISTANCE, Ydist_X06);
ObjectCreate("X06_ValueXXX", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("X06_ValueXXX"," "+DoubleToStr(X06,dig),9, "Verdana", color_X06);
ObjectSet("X06_ValueXXX", OBJPROP_CORNER, Corner_ValueXXX);
ObjectSet("X06_ValueXXX", OBJPROP_XDISTANCE, Xdist_ValueXXX);
ObjectSet("X06_ValueXXX", OBJPROP_YDISTANCE, Ydist_X06);
ObjectCreate("X07_LabelXXX", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("X07_LabelXXX",StrX07,9, "Verdana", myColor7 );
ObjectSet("X07_LabelXXX", OBJPROP_CORNER, Corner_text);
ObjectSet("X07_LabelXXX", OBJPROP_XDISTANCE, Xdist_text);
ObjectSet("X07_LabelXXX", OBJPROP_YDISTANCE, Ydist_X07);
ObjectCreate("X07_ValueXXX", OBJ_LABEL, WindowToUse, 0, 0);
ObjectSetText("X07_ValueXXX"," "+DoubleToStr(X07,dig),9, "Verdana", color_X07);
ObjectSet("X07_ValueXXX", OBJPROP_CORNER, Corner_ValueXXX);
ObjectSet("X07_ValueXXX", OBJPROP_XDISTANCE, Xdist_ValueXXX);
ObjectSet("X07_ValueXXX", OBJPROP_YDISTANCE, Ydist_X07);
} // iPlotGauge
return(0);
}
//+------------------------------------------------------------------+
//| Compute index of first/last bar of yesterday and today |
//+------------------------------------------------------------------+
void ComputeDayIndices(int tzlocal, int tzdest, int &idxfirstbaroftoday, int &idxfirstbarofyesterday, int &idxlastbarofyesterday)
{
int tzdiff= tzlocal - tzdest,
tzdiffsec= tzdiff*3600,
dayminutes= 24 * 60,
barsperday= dayminutes/Period();
int dayofweektoday= TimeDayOfWeek(Time[0] - tzdiffsec), // what day is today in the dest timezone?
dayofweektofind= -1;
//
// due to gaps in the data, and shift of time around weekends (due
// to time zone) it is not as easy as to just look back for a bar
// with 00:00 time
//
idxfirstbaroftoday= 0;
idxfirstbarofyesterday= 0;
idxlastbarofyesterday= 0;
switch (dayofweektoday) {
case 6: // sat
case 0: // sun
case 1: // mon
dayofweektofind= 5; // yesterday in terms of trading was previous friday
break;
default:
dayofweektofind= dayofweektoday -1;
break;
}
// search backwards for the last occrrence (backwards) of the day today (today's first bar)
for (int i=1; i<=barsperday+1; i++) {
datetime timet= Time[i] - tzdiffsec;
if (TimeDayOfWeek(timet)!=dayofweektoday) {
idxfirstbaroftoday= i-1;
break;
}
}
// search backwards for the first occrrence (backwards) of the weekday we are looking for (yesterday's last bar)
for (int j= 0; j<=2*barsperday+1; j++) {
datetime timey= Time[i+j] - tzdiffsec;
if (TimeDayOfWeek(timey)==dayofweektofind) { // ignore saturdays (a Sa may happen due to TZ conversion)
idxlastbarofyesterday= i+j;
break;
}
}
// search backwards for the first occurrence of weekday before yesterday (to determine yesterday's first bar)
for (j= 1; j<=barsperday; j++) {
datetime timey2= Time[idxlastbarofyesterday+j] - tzdiffsec;
if (TimeDayOfWeek(timey2)!=dayofweektofind) { // ignore saturdays (a Sa may happen due to TZ conversion)
idxfirstbarofyesterday= idxlastbarofyesterday+j-1;
break;
}
}
}
//+------------------------------------------------------------------+
//| Helper |
//+------------------------------------------------------------------+
void SetTimeLine(string objname, string text, int idx, color col1, double vleveltext)
{
string name= "[PIVOT] " + objname;
int x= Time[idx];
if (ObjectFind(name) != 0)
ObjectCreate(name, OBJ_TREND, 0, x, 0, x, 100);
else {
ObjectMove(name, 0, x, 0);
ObjectMove(name, 1, x, 100);
}
ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);
ObjectSet(name, OBJPROP_COLOR, DarkGray);
if (ObjectFind(name + " Label") != 0)
ObjectCreate(name + " Label", OBJ_TEXT, 0, x, vleveltext);
else
ObjectMove(name + " Label", 0, x, vleveltext);
ObjectSetText(name + " Label", text, 8, "Arial", col1);
}
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---