[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 130

 
borilunad:


How simple it is! M5 is open and its top a bit sauced and M1 below it shows the right comments.

As they say, it's always better in the morning! Good morning!

And what prevents you from putting the EA on the exact window where you need to draw?
 
borilunad:


How simple it is! M5 is open and its top a bit sauced and M1 below it shows the comments you want.

As they say, it's always better in the morning! Good morning!


This is where questions are asked and answers are given about the software implementation.

And you can read the comments on a sheet of paper ;)

 
Can you tell me where the error is - I can't find it.
I already rewrote the order modification code and the error remains.
I emphasize that the error is not from the log - there is not a single error in the log.
I found the error in the Results while running a test.
Example:
I opened buy position (order number 1) with price 1.4654
then in Results it says modify (order number 1) price 1.4654 and TakeProfit 1.4752
then in Results it says close (order number 1) price 1.4704 and TakeProfit 1.4752
Profit = 50.00

Example loss-making position though I should close only at TakeProfit because I have not set Stop Loss.
I opened a buy position (order number 271) at 1.4820
and in the Results it says modify (order number 271) price 1.4820 and TakeProfit 1.4918
and in the Results it says close (order number 1) price 1.4737 and TakeProfit 1.4918
Profit = - 83.46

I put a TakeProfit of 100 everywhere.

I didn't set StopLoss.

I don't know how to fix it.

When compiling this EA code = 0 errors and 0 warnings.

I used this code to Modify Orders:

//|  Описание : Модификация ордера. Версия функции для тестов на истории.      |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    pp - цена открытия позиции, установки ордера                            |
//|    sl - ценовой уровень стопа                                              |
//|    tp - ценовой уровень тейка                                              |
//|    ex - дата истечения                                                     |
//+----------------------------------------------------------------------------+
void ModifyOrder(double pp=-1, double sl=0, double tp=0, datetime ex=0){
  int    dg=MarketInfo(OrderSymbol(), MODE_DIGITS), er;
  double op=NormalizeDouble(OrderOpenPrice() , dg);
  double os=NormalizeDouble(OrderStopLoss()  , dg);
  double ot=NormalizeDouble(OrderTakeProfit(), dg);
  color  cl;

  if (pp<=0) pp=OrderOpenPrice();
  if (sl<0 ) sl=OrderStopLoss();
  if (tp<0 ) tp=OrderTakeProfit();
  
  pp=NormalizeDouble(pp, dg);
  sl=NormalizeDouble(sl, dg);
  tp=NormalizeDouble(tp, dg);

  if (pp!=op || sl!=os || tp!=ot) {
    if (MathMod(OrderType(), 2)==0) cl=clModifyBuy;
    if (!OrderModify(OrderTicket(), pp, sl, tp, ex, cl)) {
      er=GetLastError();
      Print("Error(",er,") modifying order: ",Error(error_code));
      Print("Ask=",Ask," Bid=",Bid," sy=",OrderSymbol(),
            " op="+GetNameOP(OrderType())," pp=",pp," sl=",sl," tp=",tp);
    }
  }
}
 
I forgot to mention that this EA works via an Excel spreadsheet - the Orders.csv file saved in the \experts\file
 
alex12:
Can you tell me where the error is - I can't find it.
I have already rewritten the order modification code and the error remains.
I emphasise that the error is not from the log - there is not a single error in the log.
I found the error in the Results during the test.
Example:
I opened a buy position (order number 1) at 1.4654
Next, in the Results it says buy (order number 1) price 1.4654 and TakeProfit 1.4752.
Next, in the Results it says close (order number 1) price 1.4704 and TakeProfit 1.4752
Profit = 50.00

An example of a losing position though I should close only at Take Profit because I have not set Stop Loss.
I have opened a buy position (order number 271) at 1.4820
Next, in the Results it says modify (order number 271) price 1.4820 and TakeProfit 1.4918
next it says close (order number 1) price 1.4737 and TakeProfit 1.4918 in the Results
Profit = - 83.46

I set the TakeProfit to 100 everywhere.

I didn't set StopLoss.

I don't know how to fix it.

When compiling this EA code = 0 errors and 0 warnings.

I used this code to Modify Orders:

When closing trades in the tester is written as shown here, it is most likely the result of the orderclose function (TP and SL have nothing to do with it)
 

Please help me to find the values of

1 Maximum daily volatility (daily high minus low) over the last X=5 days .

2 Average daily volatility overlast X=130 days

3 And how can these values be written in the condition if the Maximum Daily Volatilitylies in the range A=75 to B=150- Average Daily Volatility

double Dmax= 0.0; 
double DAvg= 0.0;
int a = 0; 
int d =d+1;  
while(a < 5) 
  { 
    Dmax = iHigh(Symbol(),PERIOD_D1,d)-iLow(Symbol(),PERIOD_D1,d); 
    a++; 
  } 
//Comment( "T ("+Dmax+")");

while(a < 130) 
   {  
 
DAvg += (iHigh(Symbol(),PERIOD_D1,d-1)-iLow(Symbol(),PERIOD_D1,d-1))/130; 
    a++; 
}
Comment( "T ("+DAvg+")");
 
sergeev:

1. First you find out how many bars you need in the window https://docs.mql4.com/ru/windows/WindowBarsPerChart.

2. Then you will get the date of the first bar https://docs.mql4.com/ru/windows/WindowFirstVisibleBar.

3. Knowing this initial bar and the number of bars - go through these bars and determine the high and low among them

4. profit


Variant 2

https://docs.mql4.com/ru/windows/WindowPriceMaxтво

https://docs.mql4.com/ru/windows/WindowPriceMinВторой variant

I was inclined to the first option, but I didn't know how to calculate the number of bars in the window. The second option is more laconic.

But how to "catch" the last max and min on the previous bar? Thank you in advance!

 
MK07:


But how to "catch" the last max and min on the previous bar?

You just need to memorize the maximum and minimum reached on the current bar, and when a new bar appears and becomes the previous bar, you will take the maximum and minimum from the memorized variables.

 
sergeev:

You just need to remember the maximum and minimum reached on the current bar, and when a new bar appears and becomes the previous bar, you will take the maximum and minimum from the remembered variables.


But how? Suppose we assign a max value to the variable Z and a new bar appears (that may be checked) and Z is immediately assigned a new value, while the value (Z-1) is "lost". Probably, there should be some check when assigning a new value to Z (may be a new bar appears), I rely on your professionalism and patience! Thank you for your efforts.
 

declare the zet variable as static, or declare it in the global zone.

Before assigning a new value to it, check for a new bar, and check the difference between its value and the current value, and then assign a new value to it.

Reason: