[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 565

 
TarasBY:

If you want to learn how to program, either parse other people's code (CodaBase is for that) or proceed from the algorithm for the task at hand. Asking to write code for you is the most hopeless way to learn. Most often you will get not the best code for your task, something like (allegorically) when your neighbour every minute rings your doorbell and asks "what's your name" - this is about unnecessary (superfluous) calculations.

I completely agree with you. You are 100% right. This is the right way and I've tried to follow it. However, studying MQL4 without the textbooks and reading for no reason led to nothing. I had to analyze somebody else's code anyway, since I couldn't put my own crazy ideas into the program for the most part. I have started to build the strategy in ....excel (it is closer to me and more understandable). As for the basics of the strategy, it has been very successful and clear (on the history, of course). But further I should take into account peculiarities of trading: floating spread, swap, brokerage house peculiarities, it is hard to fit all this into exel formulas. So I decided to analyze the difference between profit in excel and MQL. Frankly speaking the difference is too much, not in my favour. I do not know yet, I will analyze each position, maybe the Expert Advisor made a mistake, but that is up to me.

Anyway, good people on this forum have helped me in solving one specific problem, what a great human thank you for.

 
Ekburg:

no, the problem with changing the order number of a position when one of them is closed has been solved, I have checked more than once thinking there may be an error there, but everything is fine there, the required order is selected and the stoploss is calculated correctly for it, but the order does not want to be modified...

Error 1 is generated only if all of the parameters passed to theOrderModify( ) function are equal to all of the parameters of the order being modified, which you( by ticket number) or theOrderSelect() function selected for modification. Example usage of the check:

Only "Useful functions from KimIV".

ModifyOrder() functionhttps://www.mql5.com/ru/forum/131859

 
rigonich:

Error 1 is generated only if all parameters passed to theOrderModify( ) function are equal to all parameters of the modifiable order you selected( by ticket number) or theOrderSelect() function for modification.

1 (ERR_NO_RESULT) - if none of the parameters has been changed or there is no error, but the result is unknown, most likely, the order is not modified for some reason...
 
abeiks:

Yes, I agree, programming is not my thing, that's why I am learning and asking questions here. I tried to add position closing to your algorithm but it did not work (all buy positions were closing) so I decided to approach the problem from the other side and see the solution of closing the last two buy positions on a ready-made closing block that was provided and offered to me.

I would be very grateful if you could show me how to close the last two buy positions. I will understand where I have made an error.

 int Slippage = 3;
int Close_buy_2pos()
{
    int ordercount = 0, OpenOrders = OrdersTotal();
    for (int cnt = OpenOrders - 1; cnt >= 0; cnt--)   // scan all orders and positions. ..
    {
        if (!OrderSelect (cnt, SELECT_BY_POS)) return (ordercount);
        if (OrderSymbol() != Symbol()) continue;
        if (OrderMagicNumber() != magic) continue;
        if (OrderType() != OP_BUY) continue;
        if (OrderClose (OrderTicket(), OrderLots(), Bid, Slippage)) ordercount++;
        else return (ordercount);
        if (ordercount == 2) break;
    } 
    Print ("::::::::::::::::::::::::: ordercount = ", ordercount);    
    return (ordercount);   
}

In a general case it is like this. If we use the "moronic" variant (it is what I use), then we have to start a loop: first, find the last open BUY position, then delete it from the ticket, and repeat the loop as many times as needed.

P.S. Writing functions for BUY and SELL separately - it is a wrong idea from the very beginning (IMHO).

And the function in that case will not look much more complicated:

int Slippage = 3;
int Close_LastPos (string fs_Symbol,
                   int fi_Magic,
                   int fi_Type = -1,   // тип закрываемых позиций
                   int fi_cnt = 1)     // количсетво закрываемых позиций
{
    int ordercount = 0, OpenOrders = OrdersTotal();
    double ld_PriceClose;
    for (int cnt = OpenOrders - 1; cnt >= 0; cnt--)   // scan all orders and positions. ..
    {
        if (!OrderSelect (cnt, SELECT_BY_POS)) return (ordercount);
        if (OrderSymbol() != fs_Symbol) continue;
        if (OrderMagicNumber() != fi_Magic) continue;
        if (OrderType() != fi_Type) if (fi_Type != -1) continue;
        if (OrderType() > 1) continue;
        if (OrderType() == OP_BUY) ld_PriceClose = NormalizeDouble (Bid, Digits);
        else ld_PriceClose = NormalizeDouble (Ask, Digits);
        if (OrderClose (OrderTicket(), OrderLots(), ld_PriceClose, Slippage)) ordercount++;
        else return (ordercount);
        if (ordercount == fi_cnt) break;
    } 
    Print ("::::::::::::::::::::::::: ordercount = ", ordercount);    
    return (ordercount);   
}
 
Ekburg:

1 (ERR_NO_RESULT) - if none of the parameters has been changed or There is no error but the result is unknown, most likely just that the order is not modified for some reason ...
ERR_NO_RESULT is not an either or, but there is no error but the result is unknown . In what cases this error returns is described above. If function GetLastError() is called after functionOrderModify(), it will definitely return the error code(i.e. the reason why the order hasn't been modified) or 0 (in case of successful modification).

 
TarasBY:

In the general case so. If we use the "moronic" variant (it is the one I use), then we have to start a loop: first, find the last open BUY position, then delete it from the ticket and repeat the loop as many times as necessary.

P.S. Writing functions for BUY and SELL separately - it is a wrong idea from the very beginning (IMHO).

And function in this case would not look much more complicated:


Thanks, I will look into it.

 

Good evening everyone, could you please tell me why MetaTrader4 (latest) doesn't update at all? I installed it yesterday, but the last update date shows 30th of November, and there is no dynamics on any currency pair, and when I buy any currency the market is closed. (I have a Demo account). Can you please tell me how to enable the update or what I have to do to keep track of price changes?

 
Lucifer982:

Good evening everyone, could you please tell the green and inexperienced why MetaTrader4 (latest) does not update at all? I installed it yesterday, but the last update date shows 30th of November, and there is no dynamics on any currency pair, and when I buy any currency the market is closed. (I have a Demo account). Can you please tell me how to enable the update or what I have to do to keep track of price changes?


The system will start updating itself within a few hours (depending on your time zone). DoC has a day off on Saturday, Sunday. So they have nothing to worry about)))).

Or the second option: write a complaint to the Service Desk of the Ministry of Finance.

 
T1000:


It will switch itself on within a few hours (depending on your time zone). The service desk has a day off on Saturday, Sunday. so they do not have any jerks))))

Or the second option: write a complaint to the Service Desk of the Ministry of Finance.


I see, thank you, I will wait)
 

how do i get the total number of open orders for a given pair?

I have one open chart, EA is working on 10 symbols.

I decided to let the comments on the chart show the total number of open orders for each symbol.

How do I do that? If OrdersTotal shows the total amount of

Reason: