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

 
lottamer:

but how do you use this in practice if you need to code a condition "if the last two trades were losers....."? ??


In practice this is used in all ops that work with orders. You must first select the order and then do something with it (view order information, send a trade order to the server to modify or close it) There are two ways to select orders in the terminal, by ticket, which is the number assigned to the order on the server that does not change for a particular order, or by the order number (index) under which the order is stored in the terminal. This number may change on every tick, depending on what and how many orders are opened, set, closed or deleted.

There are order cycles to work with orders.

 
rigonich:


It's not the time itself that matters, but whether something has been done within a certain period of time, that's what you should check.

P.S. And you don't need to define N, just do your checkif(TimeCurrent() >= iTime(Symbol(),1440,0) ) until the action you want is done (setting an order).


But if you set it this way:

if(TimeCurrent() >= iTime(Symbol(),1440,0)

This way the signal will be valid all the time after the bar opens and . To infinity. Why do I need it? The main thing is to open one order at the opening of a bar, not a pack.

 
hoz:

But if you put it like this:

This way the signal will be valid permanently after the bar opens and ... Until infinity. What do I need it for? The main thing is to open one order at the bar opening instead of the pack.


И ... To infinity - this is a special case, if your necessary condition - order setting - will not be fulfilled today or tomorrow...

And to avoid the opening of a pack, we should simply check before each opening whether the order is opened or has been opened during the period you need.

 
rigonich:


In practice this is used in all ops that work with orders. You must first select the order and then do something with it (view order information, send a trade order to the server to modify or close it) There are two ways to select orders in the terminal, by ticket, which is the number assigned to the order on the server that does not change for a particular order, or by the order number (index) under which the order is stored in the terminal. This number may change on every tick, depending on what and how many orders are opened, set, closed or deleted.

To work with orders, cycles of order evaluation are implemented.


I know how to start such a loop.

for(int i=0; i<total; i++)

{

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

How can I get a variable to give TRUE-when the last two trades are losing, and FALSE when they are profitable?

OR this way.

when trades are closed by stop - somewhere the checkbox counter.... should be turned on but how do i catch the moment of closing ?

 
rigonich:


This is the index that determines the position of the order in the array where the data on the orders present in the terminal is stored.

That is,what is underlined (under SELECT_BY_POS) bool OrderSelect(int index, int select, int pool=MODE_TRADES)



I correctly understand that the last order I closed will have index 1. And after closing the next one, index 2...and so on with each new closed position? What about daily totals? do yesterday's trades count? or does it start all over again every day?
 
lottamer:


I know how to start such a loop...

for(int i=0; i<total; i++)

{

if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

How can I get a variable to give TRUE-when the last two trades are losing, and FALSE when they are profitable?

OR this way.

when trades are closed by stop - somewhere the checkbox counter.... should be turned on but how do i catch the moment of closing ?


There are a few solutions to these problems. The easiest way is to go through all the orders in the loop, looking for the one that was closed last, see if your order closed on a stop or profit, pick its ticket, start the loop over again, if the order with the ticket you saved saved, skip it, find the one that closed last but one...

P.S. And notMODE_TRADES, but MODE_HISTORY.

 
but another question ...SecondsAfterOpenLastPos() function. if the EA was disabled, will this function return the value of the last CLOSED trade yesterday? (can't check it - market is stagnant)
 
rigonich:


There are a few solutions to these problems. The easiest one is probably the following: go through all orders in the loop, look for the one that was closed last, use stop or profit to find the order, save its ticket, restart the loop, if the order with the ticket you saved was selected, skip it,find the one that closed last but one...

P.S. And notMODE_TRADES, but MODE_HISTORY.


the logic is clear.... but for me it's impossible to write it in my code... it's too complicated... i've never worked with brute force loops before... i just didn't need it... so it's a dark forest :))) and the loops I've seen aren't very clear to me... it's clear that they try something... and that's it.

Could you give me the simplest example...but with explanations, so I understand what's going on in the loop and where?

 
lottamer:

maybe you can redo two options from here https://forum.mql4.com/ru/38949/page5#434244

Function TimeOpenLastPos().

This function returns the time of the last position opened.

We need an open time of the last CLOSED position.

or

Function SecondsAfterOpenLastPos().

This function returns the number of seconds since the last position opened.

And it MUST be in hours.... instead of seconds.

this one is closer.

The first option can be used with minimal changes (look for the history and what you need). Do you want it to open no more than one trade a day?
 
lottamer:
But another question ... theSecondsAfterOpenLastPos() function. if the EA was disabled, will this function return the value of the last CLOSED trade yesterday? (can't check it - market is stagnant)


It will.

More precisely, it will be, but not closed, but open.

Reason: