Useful features from KimIV - page 84

 
vopros писал(а) >>

Igor, hello!

Could you please advise how to implement sound notification in an existing indicator?

For example, in ZigZag. How can I add it, that there will be a sound at the moment of drawing the new line:

//| ZIG-ZAG_RPoint_v2_m.mq4 |https://www.mql5.com/ru/code/8739
//| Copyright © 2004-2008, Poul_Trade_Forum |Reproduced the code of RPoint indicator . RPoint'.
//| Aborigen & Kharko |
//| http://forex.kbpauk.ru/ | QUALITY ZIGZAG
//+------------------------------------------------------------------+

 

Gentlemen programmers, please make an EA (for reasonable money) from Kim's indicator.

Details by mail

Vladimir

vladmo@mail.ru

//+------------------------------------------------------------------+
//| i-MorningRange.mq4 |
//| Kim Igor V. aka KimIV |
//| http://www.kimiv.ru |
//| |
//| 08.02.2006 The morning range indicator. |
//+------------------------------------------------------------------+
#property copyright "Kim Igor V. aka KimIV"
#property link "http://www.kimiv.ru"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 blue
#property indicator_color2 Orange

//------- External indicator parameters -------------------------------
extern string CheckTime = "08:00"; // Check range time
extern bool ShowHistory = True; // Show history levels
extern inttern NumberOfDays = 5; // Number of days of history
extern bool ShowComment = True; // Show comments

//------- Indicator Buffers ------------------------------------------
double dBuf0[], dBuf1[];

//+------------------------------------------------------------------+
//| Custom indicator initialisation function |
//+------------------------------------------------------------------+
void init() {
SetIndexArrow(0, 217);
SetIndexBuffer(0, dBuf0);
SetIndexStyle (0, DRAW_ARROW, 1, 2);
SetIndexArrow(1, 218);
SetIndexBuffer(1, dBuf1);
SetIndexStyle (1, DRAW_ARROW, 1, 2);

DeleteLines();
for (int i=0; i<2; i++) {
ObjectCreate("HLine "+i, OBJ_HLINE, 0, 0,0);
}

for (i=0; i<NumberOfDays; i++) {
CreateLines("upLine "+i, indicator_color1);
CreateLines("dnLine "+i, indicator_color2);
}
}

//+------------------------------------------------------------------+
//| CreateLine objects |
//| Parameters: |
//| no - line name ||
//| cl - line colour |
//+------------------------------------------------------------------+
void CreateLines(string no, colour cl) {
ObjectCreate(no, OBJ_TREND, 0, 0,0, 0,0);
ObjectSet(no, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet(no, OBJPROP_WIDTH, 1);
ObjectSet(no, OBJPROP_COLOR, cl);
ObjectSet(no, OBJPROP_RAY, False);
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void deinit() {
DeleteLines();
Comment(");
}

//+------------------------------------------------------------------+
//| Delete horizontal lines. |
//+------------------------------------------------------------------+
void DeleteLines() {
for (int i=0; i<2; i++) {
ObjectDelete("HLine "+i);
}

for (i=0; i<NumberOfDays; i++) {
ObjectDelete("upLine "+i);
ObjectDelete("dnLine "+i);
}
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
void start() {
datetime t1, t2, dt;
double p1, p2;
int b1, b2; sd=0;

t1=StrToTime(TimeToStr(CurTime(), TIME_DATE)+" 00:00");
t2=StrToTime(TimeToStr(CurTime(), TIME_DATE)+""+CheckTime);
b1=iBarShift(NULL, 0, t1);
b2=iBarShift(NULL, 0, t2);
p1=High[Highest(NULL, 0, MODE_HIGH, b1-b2+1, b2)];
p2=Low[Lowest(NULL, 0, MODE_LOW, b1-b2+1, b2)];

SetHLine(0, p1);
SetHLine(1, p2);

if (ShowHistory) {
dt=decDateTradeDay(CurTime());
for (int i=0; i<NumberOfDays; i++) {
DrawLines(dt, i);
dt=decDateTradeDay(dt);
while (TimeDayOfWeek(dt)<1 || TimeDayOfWeek(dt)>5) dt=decDateTradeDay(dt);
}
}

if (ShowComment) Comment("CheckTime="+CheckTime);
}

//+------------------------------------------------------------------+
//| Set the current day's horizontal line details. |
//+------------------------------------------------------------------+
void SetHLine(int nl, double pp) {
color cl;

if (pp!=EMPTY_VALUE) {
switch (nl) {
case 0: cl=indicator_color1; break;
case 1: cl=indicator_color2; break;
}
ObjectSet("HLine "+nl, OBJPROP_COLOR, cl);
ObjectSet("HLine "+nl, OBJPROP_PRICE1, pp);
ObjectSet("HLine "+nl, OBJPROP_STYLE, STYLE_DOT);
}
}

//+------------------------------------------------------------------+
//| Draw lines on the chart |
//| Parameters: |
//| dt - date of the trading day |
//| nd - number of the day (for numbering of objects) |
//+------------------------------------------------------------------+
void DrawLines(datetime dt, int nd) {
datetime t1, t2;
double p1, p2;
int b1, b2;

t1=StrToTime(TimeToStr(dt, TIME_DATE)+" 00:00");
t2=StrToTime(TimeToStr(dt, TIME_DATE)+""+CheckTime);
b1=iBarShift(NULL, 0, t1);
b2=iBarShift(NULL, 0, t2);
p1=High[Highest(NULL, 0, MODE_HIGH, b1-b2+1, b2)];
p2=Low[Lowest(NULL, 0, MODE_LOW, b1-b2+1, b2)];

ObjectSet("upLine "+nd, OBJPROP_TIME1, t1);
ObjectSet("upLine "+nd, OBJPROP_PRICE1, p1);
ObjectSet("upLine "+nd, OBJPROP_TIME2, t2);
ObjectSet("upLine "+nd, OBJPROP_PRICE2, p1);

ObjectSet("dnLine "+nd, OBJPROP_TIME1, t1);
ObjectSet("dnLine "+nd, OBJPROP_PRICE1, p2);
ObjectSet("dnLine "+nd, OBJPROP_TIME2, t2);
ObjectSet("dnLine "+nd, OBJPROP_PRICE2, p2);
}

//+------------------------------------------------------------------+
//| Decrease date by one trading day |
//| Parameters: |
//| dt - date of the trading day |
//+------------------------------------------------------------------+
datetime decDateTradeDay(datetime dt) {
int ty=TimeYear(dt);
int tm=TimeMonth(dt);
int td=TimeDay(dt);
int th=TimeHour(dt);
int ti=TimeMinute(dt);

td--;
if (td==0) {
tm--;
if (tm==0) {
ty--;
tm=12;
}
if (tm==1 || tm==3 || tm==5 || tm==7 || tm==8 || tm==10 || tm==12) td=31;
if (tm==2) if (MathMod(ty, 4)==0) td=29; else td=28;
if (tm==4 || tm==6 || tm==9 || tm==11) td=30;
}
return(StrToTime(ty+"."+tm+"."+td+" "+th+":"+ti));
}
//+------------------------------------------------------------------+

 
Igor, hello! There are two experts (expert1 and expert2).Expert1 has a file in which it writes data from each new row. Expert2 has a value to compare with the maximum value in the file. Please help me to pull out this maximal number.
 
Milka писал(а) >>
Hello Igor, there are two Expert Advisors (Expert1 and Expert2). Expert1 has a file in which it writes data from each new row. Expert2 has a value to compare with maximal value in file. Please help me to pull this maximal number.

In Expert 2, load all the numbers into an array and then use ArrayMaximum().

 
KimIV >> :

In Expert 2, load all the numbers into an array and then use ArrayMaximum().

I just can't load the data into an array

 
Milka писал(а) >>

I'm having trouble loading data into an array.

Check out my array functions in this thread. The examples should fill arrays with data.

 

Igor, hello!

When I create a line on a chart ( for example - ObjectCreate(tLine,OBJ_TREND,0,Time[3],Low[3],Time[1],Low[1]) the platform draws a DRIVE of infinite length, while the tutorial says - a TREAD! I can't find how to turn OBJ_TREND into a segment of the right length. Manually convert all the rays or trick (draw a triangle as it were) seems to be out of the question. Can you give me a hint...

 
alexpert007 писал(а) >>

Igor, hello!

When I create a line on a chart ( for example - ObjectCreate(tLine,OBJ_TREND,0,Time[3],Low[3],Time[1],Low[1]) the platform draws a DRIVE of infinite length, while the tutorial says - a TREAD! I can't find how to turn OBJ_TREND into a segment of the right length. Manually convert all the rays or trick (draw a triangle as it were) seems to be out of the question. Hint...

Use ObjectSet(tLine, OBJPROP_RAY, False).

 

Hello Igor,

I already raised the question about the partial closing of positions, and in particular, the error 131 (p. 49-50 auth.6232). It is not a problem to partially close positions, but the 131 error in the log does not allow me to continue writing the EA. I found a link to your function "Close one third of a position" in the branch "Is there a ready function for partial closing of a position", but I have not found the given function here, in this branch, nor your reply to 6232's question. The answer (p.50) helped to partially solve the problem. The log did not generate an error, but a side effect appeared - the first open position was not closed as required.

For comparison, the first chart closed "as it should be", but with 131 error constantly:

and a chart with no error, but with incorrect closing of the first (and for some reason only the first) open position:

 

The closing code looked like this:

Files:
codv1.mq4  8 kb
Reason: