High Low Day/Year

 
Hi Friends,
I am new to MT4 and trying to write a code for drawing horizontal lines for:

1. High and Low of Previous day.
2. High and Low of Previous and Current Week.
3. High and Low of Previous and Current Month.
4. High and Low of Previous and Current Year.


If someone can please show me where to start or if someone have something similar already written, I would really appreciate if you can share your knowledge.


Look forward to hear back.

Thanks in Advance
The_One
 
use iHight(...) and iLow(...)functions, see metaediter' help file for MQL.
 
DxdCn:
use iHight(...) and iLow(...)functions, see metaediter' help file for MQL.
Hi DxdCn,
Thanks for the quick reply. I looked into the functions and not sure of they can do what I am after. These function takes "shift" (i) as the parameter, which says "Shift relative to the current bar (number of periods back), where the data should be taken from".

double iHigh(string symbol, int timeframe, int shift)

Now for example if I want previous year high, I can't put i = 365, because it will get the highest high in last 365 days from today. I need a function which can look into the calender end of year and month.

Any suggestions??? :)

Regards
The_One
 
the_one:
Hi Friends,
I am new to MT4 and trying to write a code for drawing horizontal lines for:

1. High and Low of Previous day.
2. High and Low of Previous and Current Week.
3. High and Low of Previous and Current Month.
4. High and Low of Previous and Current Year.


double yesterdayHigh = iHigh(NULL, PERIOD_D1, 1);
double yesterdayLow = iLow(NULL, PERIOD_D1, 1);
 
double lastWeekHigh = iHigh(NULL, PERIOD_W1, 1);
double lastWeekLow = iLow(NULL, PERIOD_W1, 1);
 
double thisWeekHigh = iHigh(NULL, PERIOD_W1, 0);
double thisWeekLow = iLow(NULL, PERIOD_W1, 0);
 
double lastMonthHigh = iHigh(NULL, PERIOD_MN1, 1);
double lastMonthLow = iLow(NULL, PERIOD_MN1, 1);
 
double thisMonthHigh = iHigh(NULL, PERIOD_MN1, 0);
double thisMonthLow = iLow(NULL, PERIOD_MN1, 0);
 
double lastYearHigh = iHigh(NULL, PERIOD_MN1, iHighest(NULL, PERIOD_MN1, MODE_HIGH, 12, 12));
double lastYearLow = iLow(NULL, PERIOD_MN1, iLowest(NULL, PERIOD_MN1, MODE_LOW, 12, 12));
 
double thisYearHigh = iHigh(NULL, PERIOD_MN1, iHighest(NULL, PERIOD_MN1, MODE_HIGH, Month(), 0));
double thisYearLow = iLow(NULL, PERIOD_MN1, iLowest(NULL, PERIOD_MN1, MODE_LOW, Month(), 0));
 
Irtron:

Hi Irtron,
Thanks a lot for you time in writing those lines of code for me. :)

I tried putting this in the code and I don't see anything on the charts when I apply this indicator.


#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Red
//---- input parameters
extern int yesterdayHigh;
extern int yesterdayLow;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];

int init()
{

SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
return(0);
}

int deinit()
{
return(0);
}

int start()
{
int counted_bars=IndicatorCounted();


ExtMapBuffer1[yesterdayHigh] = iHigh(NULL, PERIOD_D1, 1);
ExtMapBuffer2[yesterdayLow] = iLow(NULL, PERIOD_D1, 1);

return(0);
}



Can someone please suggest what I am doing wrong here?

Regards
The_One
 
The indicator merely puts two points - iHigh and iLow - at the current bar on the chart. Perhaps you just didn't notice them.
It's rather difficult to suggest anything without knowing what are you trying to achieve.

PS.
Please use MQL4 Code tag for source code. Either MQL button in the toolbar or Ctrl + Alt + M shortcut.
 
Irtron:
The indicator merely puts two points - iHigh and iLow - at the current bar on the chart. Perhaps you just didn't notice them.
It's rather difficult to suggest anything without knowing what are you trying to achieve.

PS.
Please use MQL4 Code tag for source code. Either MQL button in the toolbar or Ctrl + Alt + M shortcut.

Hi Irtron,
Thanks again for replying. I am trying to simply draw horizontal lines for the Highs and Lows. They will act as profit taking / Stop loss points for me. I know I can do them manually, but it would be nice to have an indicator. Also this way I can start to learn coding and also get to know people in this forum.


Regards
The_One
 
the_one:
I am trying to simply draw horizontal lines for the Highs and Lows.
Lines are formed by sets of points, not just one point. So you need to put a point at every bar on the chart.

Please refer to the indicators in the MT package. Look at the loops involving that counted_bars variable.
 
Irtron:
the_one:
I am trying to simply draw horizontal lines for the Highs and Lows.
Lines are formed by sets of points, not just one point. So you need to put a point at every bar on the chart.

Please refer to the indicators in the MT package. Look at the loops involving that counted_bars variable.
Hi Irtron,
I understand what you saying, however there is no other point to join them together. I simply need to identity previous day high and draw a horizontal line across which spans in all time frames.


Thanks
The_One
 
Hi,
Can anyone please help me out writing this code to draw horizontal lines for:

1. High and Low of Previous day.
2. High and Low of Previous and Current Week.
3. High and Low of Previous and Current Month.
4. High and Low of Previous and Current Year.


Please help

The_One
 
ObjectCreate( string name, int type, int window, datetime time1, double price1, datetime time2=0, double price2=0, datetime time3=0, double price3=0)

use:

double yesterdayHigh = iHigh(NULL, PERIOD_D1, 1);
double yesterdayLow = iLow(NULL, PERIOD_D1, 1);

ObjectCreate
("yesDay", OBJ_HLINE, 0, Time[0],yesterdayHigh );

ObjectCreate
("Daylow", OBJ_HLINE, 0, Time[0],yesterdayLow );

..............

not

ExtMapBuffer1[yesterdayHigh] = iHigh(NULL, PERIOD_D1, 1);
ExtMapBuffer2[yesterdayLow] = iLow(NULL, PERIOD_D1, 1);

Reason: