Questions from Beginners MQL5 MT5 MetaTrader 5 - page 135

 
zfs:
The average profitable trade will not cover the slippage and profitability is small, and it could also be a fit).

I wrote the Expert Advisor myself. There is no stop loss in it.

 
PetrovichV:

I wrote the expert myself. It doesn't have a stoploss.

That's even worse).
 
zfs:
It's even worse).
Thank you.
 

I'll probably answer my own question, now that the solution has been found - you never know who will be googling...

The question was about how to get the opening price of the last order from the history. It turned out (at least, not for me) that it was correct - I had to get the price of a deal rather than that of an order. In the tester, the initial variant worked too (not written by me) - I suspect the difference was in the fact that in the demo version it just says "market price" instead of price and when trying to request it as double, zeros are returned for some reason. To hell with it, now the function looks like this:

PositionID = PositionGetInteger(POSITION_IDENTIFIER);

double FindLastPrice(long PositionID) {
   int  i = 0, DealsTotal;
   ENUM_DEAL_TYPE CheckType;
   long Ticket, OldTicket = 0, PosID, Magic, Type;
   double OrderPrice = 0;
   
   DealsTotal = HistoryDealsTotal();
   
   for (i = 0; i < DealsTotal; i++) {
      Ticket = (int)HistoryDealGetTicket(i);
      PosID  = HistoryDealGetInteger(Ticket, DEAL_POSITION_ID);
      Magic  = HistoryDealGetInteger(Ticket, DEAL_MAGIC);
      Type   = HistoryDealGetInteger(Ticket, DEAL_TYPE);
      
      if (Sell) CheckType = DEAL_TYPE_SELL; 
      else CheckType = DEAL_TYPE_BUY;
      
      if ((PosID == PositionID) && (Magic == MagicNumber) && (Type == CheckType)) {
         if (Ticket > OldTicket) {
            OrderPrice = HistoryDealGetDouble(Ticket, DEAL_PRICE);
            OldTicket = Ticket;
         }
      }
   }
   if(!OrderPrice) Print("Ошибка получения цены открытия предыдущей сделки! Error ",GetLastError());
   return(OrderPrice);
}

I had to kill a few hours for this nonsense, but at least it all has its advantages: because of this non-working function I had to invent a workaround, at the same time mastering basic work with files to stupidly write each new order price to a file and read it when necessary...

 
Lone_Irbis:

I'll probably answer my own question, since the solution has been found - just in case anyone is googling...

The question was about how to get the opening price of the last order from the history. ....

And if you could just use the search on the website or look through the articles that already have something.

>>> MQL5 Recipes - Trade History and Library of Functions for Getting Position Properties

 
tol64:

And you could just use the site search or look through the articles where there is nothing else.

>>> MQL5 Recipes - Trade History and Library of Functions for Getting Position Properties

I googled this site for a week (namely, through Google, because the built-in search is somewhat strange: it either gives totally inexact things in random order, not by relevance, or even says "not found anything" even for copied requests from the same documentation)... But to find something useful you should know exactly what it is called and how it differs from already existing non-working version :) It's easy to talk about search from the position of someone who knows the language at a decent level, but it's harder to do, if you know the name mql5 only for a week and are already trying to make something in it...

And plus I don't really like ready-made solutions and detailed manuals, as a concept, they just discourage me from making it myself. :) Maybe my way of self-study is not very effective, but it's more important that it is interesting - otherwise the enthusiasm to invest personal time into this topic will not be enough for a long time.

Nevertheless, thanks for the link, I will read it.

 

Good afternoon.

Is there any way to download historical data for currencies for 20-30 years?

In Alfa-Forex it's only for the last 12 years, but before that it's in bits and pieces.

 
PetrovichV:

Good afternoon.

Is there any way to download historical data for currencies for 20-30 years?

In Alfa-Forex it's only for the last 12 years, but before that it's in bits and pieces.

Your broker gives you the history, the quality decreases when you increase the period.
 

Here is the code where the buy order is placed and then its SL and TP are changed.

I get error: 2013.09.06 00:03:39 Trades '10022332': failed modify order #0 buy 0.00 GBPUSD at market sl: 0.00000 tp: 0.00000 -> 1.56255, sl: 1.55787 tp: 1.56787 [Invalid request]
What is wrong with the request to change levels?

int Positions;
double delta=0.00500;

MqlTradeRequest  Request;
MqlTradeResult   Result;
MqlTick         InfoTick;


void OnTick()

{
//---

 if(PositionsTotal()==0) // если открытых позиций нет, покупаем
   { 
      
    SymbolInfoTick(_Symbol, InfoTick);
                              
    Request.action=TRADE_ACTION_DEAL;
    Request.symbol=_Symbol;
    Request.volume=1;
    Request.price=InfoTick.bid;
    Request.sl=InfoTick.bid - delta;
    Request.tp=InfoTick.bid + delta;
    Request.deviation=50;
    Request.type=ORDER_TYPE_BUY;
    Request.type_filling=ORDER_FILLING_FOK;
               
    OrderSend(Request, Result);
   
  }else{                                     // меняем уровни
        SymbolInfoTick(_Symbol, InfoTick); 
        
        Request.action=TRADE_ACTION_MODIFY;
        Request.symbol=_Symbol;
        Request.sl=InfoTick.last - delta;
        Request.tp=InfoTick.last + delta;
                          
        OrderSend(Request, Result);
       }
}
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров
  • www.mql5.com
Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров - Документация по MQL5
 
agvozdezkiy:

Here is the code where the buy order is placed and then its SL and TP are changed.

I get error: 2013.09.06 00:03:39 Trades '10022332': failed modify order #0 buy 0.00 GBPUSD at market sl: 0.00000 tp: 0.00000 -> 1.56255, sl: 1.55787 tp: 1.56787 [Invalid request]
What is wrong with the request to change levels?

Get the error code for starters.
Reason: