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

 
gyfto:

How can I simplify this expression?

is from the ADX algorithm by MetaQuotes. MetaQuotes themselves use this expression:

- how to simplify it?


Why doesn't the simplest option suit you?

z=0;
if(y>x && y>0) z=y;
 
Roger:


Why is the simplest option not good enough for you?


I guess sometimes you have to look at a problem from a different angle. Right, thank you.
 
gyfto:

hoz, at I was wondering how to shorten the if even further.See: if we put a variable

we have cnt=cnt+step, where

But 1=cnt/cnt, a -cnt=cnt/(-1), the only difference is the denominator. Now recall that x^0=1, x^1=x, i.e. we can put our Boolean variable _if in the exponent, i.e.step=cnt/a*(cnt^_if); where

But ±a is supposedly 2*_if-1, i.e.

Or we simplify


Wow, you have simplified things. I don't understand your logic.
 
I figured we'd go down to if... :-)))
 
zoritch:
I figured we'd go down to if... :-)))

I also understood that I didn't understand anything. Not even those icons of incomprehensible... :)
 
hoz:

Bars of one sign are going up, i.e. bullish.

int LastCandlesType(int trend)
{
   int cnt,                            // Счётчик идущих друг за другом свечей с требуемыми признаками

   for (int i=i_AnyBarsToHistory; i>=1; i--)
   {
      if ((Close[i] - Open[i]) >= i_sizeOfSequentialCorrectionBar * pt)     // Если бар соответствует требуемым признакам..
          cnt++;                                                                     // .. прибавим 1 к счётчику

      if (Close[i] < Open[i])                                                        // Если бар, не соответствует основному признаку..
          cnt = 0;                                                                   // .. счётчик обнуляем
      
/*      if (i == 1)
      Print("i = ", i,"; cnt = ", cnt);*/
   }

   if (cnt == 3)                                                                     // Если 5 баров вподряд бычьи..
    return (REQUIRED_SEQUENTIAL_CANDLE_GOT);                                         //..Выходим из функции
}

How to make it so that when a trend parameter is passed to this function, which will be responsible for the transfer of the assumed main trend at the moment, the calculation is based on this parameter.

I.e., if trend == downward, the function in the loop was like now, and iftrend == upward, the Open[i] and Close[i] were swapped in the loop, so that the conditions were observed. In that case, the bar close price will be lower than the open price and the difference will be minus.

int LastCandlesType(bool trend)//trend равен 1 (бычий) или 0 (медвежий)
   int cnt,                            // Счётчик идущих друг за другом свечей с требуемыми признаками

   for (int i=i_AnyBarsToHistory; i>=1; i--)
   {
      if ((2*trend-1)*(Close[i] - Open[i]) >= i_sizeOfSequentialCorrectionBar * pt)     // Если бар соответствует требуемым признакам..
          cnt++;                                                                     // .. прибавим 1 к счётчику

      if ((2*trend-1)*(Close[i] - Open[i]) < i_sizeOfSequentialCorrectionBar * pt)    // Если бар, не соответствует основному признаку..
          cnt = 0;                                                                   // .. счётчик обнуляем
      
/*      if (i == 1)
      Print("i = ", i,"; cnt = ", cnt);*/
   }

   if (cnt == 3)                                                                     // Если 5 баров вподряд бычьи..
    return (REQUIRED_SEQUENTIAL_CANDLE_GOT);                                         //..Выходим из функции
}

Or to simplify it further

int LastCandlesType(bool trend)//trend равен 1 (бычий) или 0 (медвежий)
   int cnt,                            // Счётчик идущих друг за другом свечей с требуемыми признаками

   for (int i=i_AnyBarsToHistory; i>=1; i--)
   {
      bool _if=((2*trend-1)*(Close[i] - Open[i])>=i_sizeOfSequentialCorrectionBar * pt); cnt=cnt+cnt/((2*_if-1)*MathPow(cnt, _if));
      
/*      if (i == 1)
      Print("i = ", i,"; cnt = ", cnt);*/
   }

   if (cnt == 3)                                                                     // Если 5 баров вподряд бычьи..
    return (REQUIRED_SEQUENTIAL_CANDLE_GOT);                                         //..Выходим из функции
}

Δ is the difference, i.e.Close[i] - Open[i], ^ is the power sign. const - constant in this expression, i.e.i_sizeOfSequentialCorrectionBar * pt, standard mathematical notation, I haven't invented anything. 2*bVar-1 is similar to±1, bVar here is any bool-variable. And expression 2*bVar-1 takes values not 0 and 1, but -1 and +1.≥ is MQL4 >=, also a standard mathematical notation.step is a step, i.e. in cnt++ step is 1, and in cnt=0 step is -cnt. What else was unclear from the notations?

 
I don't know how to create logs, how can I get MT4 to delete free logs automatically (or not create them at all)? A few brokerage companies with 5 digits, these logs for the day grow to terrifying size (1.6 gb), and space on the vps is limited. Thanks in advance.
 
M2012K:
How can I suggest - how to make MT4 delete free logs automatically (or not to create them at all)? I have to use some brokerage companies with 5 digits, these logs start growing in one day (by 1.6 gb), and place on vps is limited. Thanks in advance.

You can do it yourself:

Library1, library2.

==============

Although, the last (current) file is opened by the terminal. It is not easy to delete it. But you can delete the contents, which is written in the beginning.

Creation of logs is not disabled.

==============

1. Create a symlink (library1) to the logs folder in the files folder.

2. Delete all unnecessary files using MQL4 tools.

Open current file using MQL4. Edit it as you need.

4. Close the file.

5. You can delete the link. You do not have to. It will come in handy later.

==============

You can also create a script file (BAT) and run it in the Expert Advisor. The script is the same as above. Only without creating a link. Working with files, of course, using Windows tools.

 
M2012K:

How can I advise how to delete free logs automatically (or not to create them at all)?

Because on some DCs with 5 digits, these logs for a day grow to appalling size (by 1.6 gb), and space on the vps is limited. Thanks in advance.

logs what?

What is the difference between this and the EA errors?

 

Hi! I need help with refining my primitive robot. To start with, I'll explain my simple strategy to make it clearer where help is needed and for what purpose.

The essence of TS:

1. If the open price is lower than the MA and the close price is higher, we buy.

2. If the opening price is higher than the MA and the closing price is lower, we should sell.

If the price has moved by X% from the most favourable price, then we close the order. This is similar to a trailing stop but instead of pips X% of the opening distance of the order and the best price. As it is shown on the picture:

AB - distance from order opening to the most favourable price; BC=X% of AB; C - order closing.

Items 1 and 2 I have written in the program:

extern int period=50;
extern int ma_shift=0;
extern int Magic=666;
extern double lot=0.1;
extern int SL=150;


//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  int kolpos=0;
  double ma=iMA (NULL,0,period,ma_shift,MODE_SMMA,PRICE_MEDIAN,0);
//----
   for (int pos=0; pos<OrdersTotal(); pos++)
   {
   OrderSelect (pos, SELECT_BY_POS, MODE_TRADES);
   if (OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic)
   kolpos++;
   }
   if (kolpos==0)
   {
 
   if(Open[1]>ma && Close[1]<ma)  
   OrderSend(Symbol(),OP_SELL,lot,Bid,10,Bid+SL*Point,0,NULL,Magic,0,Red);
   if(Open[1]<ma && Close[1]>ma)  
   OrderSend(Symbol(),OP_BUY,lot,Ask,10,Ask-SL*Point,0,NULL,Magic,0,Green);
   
   }
   
   
  
//----
   return(0);
  }

Generally, I need help with writing a function to close orders for my TS (point 3) and adapting existing code to the function.

P.S. And I know the TS is not good.