Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 852

 

It is best to use the new CopyHigh features of mql4 and the MathMax math function

Or iHighest

 

Good morning, tell me where the mistake is.

/////////////////////////////////////////////////////////////////////////////////////////////////////

  //////////////////////////////////Зона консолидации/////////////////////////////////////////////////

  ///////////////////////////////////////////////////////////////////////////////////////////////////

  if(Hour()>=10)

  {

   for(x9=2; x9<=5; x9++)

   {

    x10=Hour()-x9;//x10 -номер свечи от которой считаем восемь свечей назад

    if(x10>=0)

    {

     int Minn=iLowest(NULL, PERIOD_H1, MODE_LOW , x10+8, x10);

     int Maxx=iHighest(NULL, PERIOD_H1, MODE_HIGH, x10+8, x10);

     z11 =iHigh(NULL,PERIOD_H1,Maxx);

     z12 =iLow(NULL, PERIOD_H1,Minn);

     ZPB     =iTime(NULL,PERIOD_H1,x10+8);

     ZPB1     =iTime(NULL,PERIOD_H1,x10);

     if(z11-z12<=z10)

     {

      y4=ObjectCreate("Зона консолидации",OBJ_RECTANGLE,0,0,0,0,0);

      y4=ObjectSet("Зона консолидации",OBJPROP_WIDTH,2);

      y4=ObjectSet("Зона консолидации",OBJPROP_COLOR,Blue);

      y4=ObjectSet("Зона консолидации",OBJPROP_BACK,true);

      y4=ObjectMove("Зона консолидации",0,ZPB,z11);

      y4=ObjectMove("Зона консолидации",1,ZPB1,z12);

     }

    }

   }

  }

  ////////////////////////////////////////////////////////////////////////////////////////////////////

The idea is that at each iteration the code should check the channel width and if it is less than or equal to the current value(z11-z12<=z10), a rectangle should be drawn, but the output is that all iterations are passed first, and then there is a check for consistency.
 
AlexeyVik:

It is best to use the new CopyHigh features of mql4 and the MathMax math function

Or iHighest

If CopyHigh, then ArrayMaximum, IMHO...
 

Please advise how to deal with error number 1 (ERR_NO_RESULT No error, but result unknown) ?

When an order is losing more than $1 (100 pips at 0.01 lot) on EURUSD, my Expert Advisor tries to modify the order (place TakeProfit of the order at its open price).

I get this error, what should I do?

 
evillive:
If CopyHigh, then ArrayMaximum, IMHO...
Yeah, that's what I was thinking... There may be some slip-ups and misunderstandings. About a month and a half ago there was the same question on the fifth forum. So there I spoke about ArrayMaximum, and here a little bit got mixed up...
 

Hello, I am working with 2000 moving averages(MAs).

The task is to calculate the number of repetitions of MA price on Close[1].

- How can I implement this task with minimal resources.

 
Top2n:

Hello, I am working with 2000 moving averages (MAs).

The task is to calculate the number of repetitions of MA price on Close[1].

- How can I implement this task with minimal resources.

If we don't use period 1 on Close prices, the number of repetitions will be zero. But if we consider getting into a certain range, the task can be solvable and more interesting. Alternatively, we find the maximum and minimum values. We divide the difference by the range. Then we define a range falling into each muving (we will consider an array that corresponds to ranges or intervals). The array index with the maximum number of hits is the winner. Maybe I wasn't quite clear. The task had better be solved in a separate topic. There may be several variants of solution. And in the future someone may need them. And here they won't find the end of it afterwards.
 

Hello, reading the tutorial, got to the GV variables. I can't understand how they work. For example, the tutorial says that GV variables can only be of type double. Okay, double so double). But then when listingGlobalVariableSet(),GlobalVariableGet(),GlobalVariableDel()functionsthey write that one of them returns time, another one returns bool, etc. I got confused in my head, I don't understand how they are organized. I also started to study MQL4 recently, I got a lot of new information in my head. If possible, please explain me an example of one of the problems in a textbook (or any of your own):

Task 24. Several Expert Advisors work in the terminal simultaneously. The deposit amount is $10 000. Total value of all open orders should not exceed 30% of the deposit amount. Each Expert Advisor should be allocated the same amount of money. Create an Expert Advisor program containing calculation of the amount of money allocated for trading.

intExperts;//Number of Expert Advisors. of experts

double Depo=10000.0, // Specified deposit

Persent=30,// given percentage

Money;// Funds sought

string Quantity="GV_Quantity"; // Name of GV-variable

//--------------------------------------------------------------------

int init()//Special. function init

{

Experts=GlobalVariableGet(Quantity); // Get text value.

Experts=Experts+1; // Number of Experts.

GlobalVariableSet(Quantity, Experts); // New value

Money=Depo*Persent/100/Experts; // Exp.

Alert("For the expert in the window ", Symbol()," allocated ",Money);

return;// Exit from init()

}

//--------------------------------------------------------------------

int start()// Special. function start

{

int New_Experts= GlobalVariableGet(Quantity);// New number of exp.

if (Experts!=New_Experts) // If changed

{

Experts=New_Experts; // Now the current number is

Money=Depo*Persent/100/Experts; // New value of exper.

Alert("New value for expert ",Symbol(),": ",Money);

}

/*

...

The main code of the Expert Advisor must be specified here,

which uses the value of the variable Money

...

*/

return;//exit from start()

}

//--------------------------------------------------------------------

int deinit()//Proper. deinit() function

{

if (Experts ==1)// If only one expert..

GlobalVariableDel(Quantity); //...delete GV-variables

else// Otherwise..

GlobalVariableSet(Quantity, Experts-1); //...decrease by 1

Alert("EA is unloaded from the window ",Symbol()); // Notify about unloading

return;// Exit from deinit()

}

 
Vinin:
If you don't use period 1 on closing prices, the number of repetitions will be zero. But if you count hitting some range, then the problem might be solvable and more interesting. Alternatively, we can find the maximum and minimum values. We divide the difference by the range. Then we define a range falling into each muving (we will consider an array that corresponds to ranges or intervals). The array index with the maximum number of hits is the winner. Maybe I wasn't quite clear. The task had better be solved in a separate topic. There may be several variants of solution. And in the future someone may need them. And here they won't find the end of it afterwards.

I'll have to think about it, thanks.

separate topic - https://forum.mql4.com/ru/66882

 

Hello, I'm switching from mql5 to mql4.

I am trying to use indicators from different timeframes in my code.

Suppose I am running the EA on M1.
This code works fine: iSAR(NULL,0,0.02,0.2,1);
This one too: iSAR(NULL,PERIOD_M1,0.02,0.2,1);

But if I access another timeframe, it always returns 0, for example: iSAR(NULL,PERIOD_M30,0.02,0.2,1);

Thank you.

Reason: