Questions from Beginners MQL5 MT5 MetaTrader 5 - page 507

 
Mike:
Thanks, I downloaded and installed it, good stuff... Do you know anything similar with stock quotes? I want to try stock CFD, my broker has lots of stocks, good and different ones... :)
no
 
Please tell me how to make it buy once and after take profit did not do anything - and waited for a new breach (the code is written as - if (cena>ma && cena> ma2 && cena> Ma && cena>Ma1) ???
Files:
safasf.png  41 kb
 
Tema97:
Please tell me how to make it buy once and after take profit it does not do anything - it waits for new breakthrough (the code is written as - if (cena>ma && cena> ma2 && cena> Ma && cena>Ma1) ???

Check the type of the last closed position, if it was a buy then do not reopen the buy position, but wait for the sell signal and vice versa.

The GetTypeLastClosePos() function.

This function returns the type of the last closed position, or -1. A more accurate selection of positions to be considered is defined by external parameters:

  • sy- Name of market instrument. If this parameter is set, the function will consider only positions of the specified instrument. The default value -"" means any market instrument.NULL means the current instrument.
  • mn- position identifier, MagicNumber. Default value-1 means any identifier.
  • //+----------------------------------------------------------------------------+
    //|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
    //+----------------------------------------------------------------------------+
    //|  Версия   : 19.02.2008                                                     |
    //|  Описание : Возвращает тип последней закрытой позиции или -1               |
    //+----------------------------------------------------------------------------+
    //|  Параметры:                                                                |
    //|    sy - наименование инструмента   (""   - любой символ,                   |
    //|                                     NULL - текущий символ)                 |
    //|    mn - MagicNumber                (-1   - любой магик)                    |
    //+----------------------------------------------------------------------------+
    int GetTypeLastClosePos(string sy="", int mn=-1) {
      datetime t=0;
      int      i, k=OrdersHistoryTotal(), r=-1;
    
      if (sy=="0") sy=Symbol();
      for (i=0; i<k; i++) {
        if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
          if ((OrderSymbol()==sy || sy=="") && (mn<0 || OrderMagicNumber()==mn)) {
            if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
              if (t<OrderCloseTime()) {
                t=OrderCloseTime();
                r=OrderType();
              }
            }
          }
        }
      }
      return(r);
    }
    https://www.mql5.com/ru/forum/131859/page4#434227
Только "Полезные функции от KimIV". - MQL4 форум
  • www.mql5.com
Только "Полезные функции от KimIV". - MQL4 форум
 
Leanid Aladzyeu:

if(Ask ==("line "+100*Point))

buy

iMA - data of the MA indicator

why exactly Ask and not Bid or it doesn't matter?
 
Tema97:
Why is it an asc and not a bid or is it not important?
Apparently he wants to overplay the spread as buy opens on asc, but on bid would be a more correct condition.
 
Vladimir Zubov:
Apparently wants to overplay the spread as buy opens on asc, but on bid would be a more correct condition.
Thanks for the ifna)))
 
Tema97:
Why is it an asc and not a bid, or does it not matter?
If you want to buy, put a bid on an indicator and sell, or vice versa. For buying oriented to the Bid indicator , for selling vice versa . it is so that the advisor would work with the spread
 
Leanid Aladzyeu:
...to buy oriented to the Bid indicator, to sell on the contrary . it is so that the advisor would work on the indicator, taking into account the spread

I guess it's the other way around.)

И... which "indicators" are you talking about? ))))

 

I have a follow-up question --- how to make for example a buy within 100-200 points of a line, I only have a code for exactly 100 if(Ask ==("line "+100*Point)) ) for example between 100 and 300 pips) or it may be that when I reach 100 pips it does not buy because the market moved fast etc. -( with a strong move (eg (Non Farm) - ) personally I had a big delay before I closed the position or a stop loss when I dragged the line)

 
Tema97:

I have a follow-up question --- how to make for example a buy within 100-200 points of a line, I only have a code for exactly 100 if(Ask ==("line "+100*Point)) ) for example between 100 and 300 pips) or it may be that when I reach 100 pips it does not buy because the market moved fast etc. -( with a strong move (eg (Non Farm) - ) personally I had a big delay before I closed the position or a stop loss when I dragged the line)

my god. >100 и <300
Reason: