[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 674

 

Thank you.
 

Such a problem.

I started to modify Expert Advisor from tutorial - strings.mq4 (link to experthttp://c.mql4.com/book/mq4/experts/strings.mq4)

I have added a couple of lines, but it does not work. It is clear that I have made a mistake, but I cannot find the error.

So. All changes are concentrated in block 10.

Here's the original:

//-------------------------------------------------------------- 10 --
int Create(int Ind_Bar, int Line) // Custom function...
{ // ...create object
Color Color; // object colour
datetime T_Bar=Time [Ind_Bar]; // open time of the bar
double O_Bar=Open [Ind_Bar]; // Bar open price
double C_Bar=Close[Ind_Bar]; // Closing price of a bar
double H_Bar=High [Ind_Bar]; // Bar maximum price
double L_Bar=Low [Ind_Bar]; // Minimum bar price

string Nom_Lin =Line + "_"; // String - line number
// string Nom_Lin = DoubleToStr(Line,0)+"_"; // This is also possible
string Str_Time=TimeToStr(T_Bar); // String - open time.
string His_Name=Prefix+Nom_Lin+Str_Time;// Name of the created object
if (O_Bar < C_Bar) Color=Blue; // colour selection depending...
if (O_Bar > C_Bar) Color=Red; // ... depending on the characteristics of the bar
if (O_Bar ==C_Bar) Color=Green;

switch(Line) // Thin or thick line
{
case 1: // Thin line
ObjectCreate(His_Name,OBJ_TREND,0,T_Bar,H_Bar,T_Bar,L_Bar);
break; // Exit switch
case 2: // thick line
ObjectCreate(His_Name,OBJ_TREND,0,T_Bar,O_Bar,T_Bar,C_Bar);
ObjectSet( His_Name, OBJPROP_WIDTH, 3); // Style
}
ObjectSet( His_Name,OBJPROP_COLOR,Color); // Color
ObjectSet( His_Name, OBJPROP_RAY, false); // Beam
ObjectSetText(His_Name, "Object was created by the Expert Advisor",10); // Description
return; // Exit from the function

}

And here's what I've done (compiles without errors): (see also attached file)

//-------------------------------------------------------------- 10 --
int Create(int Ind_Bar, int Line) // Custom function...
{ // ...object creation
Color Color; // Object colour
datetime T_Bar=Time [Ind_Bar]; // open time of the bar
double O_Bar=Open [Ind_Bar]; // Bar open price
double C_Bar=Close[Ind_Bar]; // Closing price of a bar
double H_Bar=High [Ind_Bar]; // Bar maximum price
double L_Bar=Low [Ind_Bar]; // Minimum bar price
//-------------------изменения---------------------------------------
double Macd_M_D1=iMACD(NULL,1440,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
// top - access to the MAACD calculation on the days of the main line
double Macd_S_D1=iMACD(NULL,1440,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
// This is the reference to the MACD and calculation of the Signal Line on the days
double Macd_M_H4=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
// This is the reference to the MACD and calculation of the main line on the current timeframe
double Macd_S_H4=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
// This is the reference to the MACD and calculation of the signal line at the current timeframe

string Nom_Lin =Line + "_"; // String - number of the line
// string Nom_Lin = DoubleToStr(Line,0)+"_"; // You can do it this way
string Str_Time=TimeToStr(T_Bar); // String - open time.
string His_Name=Prefix+Nom_Lin+Str_Time;// Name of the created object
if ((Macd_M_D1 < Macd_S_D1)&&(Macd_M_H4 < Macd_S_H4))Color=Blue;
if ((Macd_M_D1 > Macd_S_D1)&&(Macd_M_H4 > Macd_S_H4))Color=Red;
//
//if (O_Bar < C_Bar) Color=Blue; //Colour selection depending on...
//if (O_Bar > C_Bar) Color=Red; // ... depending on the characteristics of the bar
//if (O_Bar ==C_Bar) Color=Green;

//-------------------изменения---------------------------------------

The aim - if MACD readings on the daily and current timeframe are similar - is to colour the candle either red or blue depending on the direction.

Files:
 

You cannot declare arrays like this

datetime T_Bar=Time [Ind_Bar]; // Время открытия бара
double O_Bar=Open [Ind_Bar]; // Цена открытия бара
double C_Bar=Close[Ind_Bar]; // Цена закрытия бара
double H_Bar=High [Ind_Bar]; // Максимальная цена бара
double L_Bar=Low [Ind_Bar]; // Минимальная цена бара

The compiler will see that there is a variable instead of an array's size. It simply won't know how much memory should be allocated for the future array. That's why your code does not work

 
drknn:

You cannot declare arrays like this

The compiler will see that there is a variable instead of the array's size. It simply won't know how much memory should be allocated for the future array. And that's why your code does not work

The thing is, I didn't touch that part of the Expert Advisor - and it worked fine - and the specified part of the code was taken from the MQL4 tutorial - here https://c.mql4.com/book/mq4/experts/strings.mq4

 
victor417:

The thing is, I didn't touch this part of the Expert Advisor - and it all worked - and the mentioned part of the code is taken from the MQL4 tutorial - here https://c.mql4.com/book/mq4/experts/strings.mq4


If that's how arrays are declared in the tutorial, it's quite strange. Would you have highlighted with a comment the part of the code that YOU contributed.

I haven't read that textbook either. And what is the author's reasoning behind the legitimacy of array declaration?

 

I've noticed a strange feature - the bigger the volume of quotes, the harder the tester slows down... If I start the test from 1999, it runs fast, but the closer to the present time, the harder the brakes... 2008 and closer to "today" - impossible to test in visualisation mode at all.

How do you combat the tester's brakes at all???

 

drknn:

You cannot declare arrays like this

datetime T_Bar=Time [Ind_Bar]; // Время открытия бара
double O_Bar=Open [Ind_Bar]; // Цена открытия бара
double C_Bar=Close[Ind_Bar]; // Цена закрытия бара
double H_Bar=High [Ind_Bar]; // Максимальная цена бара
double L_Bar=Low [Ind_Bar]; // Минимальная цена бара

The compiler will see that there is a variable instead of the array's size. It simply won't know how much memory should be allocated for the future array. And that's why your code does not work.

If this is how arrays are defined in the tutorial, it's really strange. Would you have put a comment on the part of code you've written?

I haven't read that textbook either. And what is the author's reasoning behind the legitimacy of array declaration?

I see variable initialization. Where are the arrays?

Timeseries? ;)

 
Hello, can someone make a zigzag indicator to bend the current at a minimum deviation from the high lowe but in pips... For example, if you set a deviation of 50 pips, anything less than that, it is considered noise... I really do not know how to search for such a large kollichestvo stuff on the forum... Thanks in advance.
 

Can you tell me please, I have a problem with the tester.

The report shows that Total loss = 863 and max drawdown = 1427. how can this be?

If you look at the balance curve - you can see that the max. drawdown - 863.

What kind of glitch is this, can you tell me please, or maybe this is the way it should be?

Thanks in advance)

 
Hi! Can someone add a trailing stop here; and the stoploss is set differently every time...Fix it please.
Files:
a_sidus_1.mq4  5 kb
Reason: