Clearing in the tester - page 4

 
Roman Shiredchenko #:

Write-offs during clearing can be disregarded.

Example. You open a buy trade at 50, at the start of clearing the price is say 70. During clearing your trade will be deleted and you will get 20 tugrik, after clearing your trade will be opened at 70.

If you close it at 100, the terminal will show one trade with a profit of 50 tugriks.

The problem usually occurs when writing a trawl or CU. Suppose we want to put a CUE of +5 when the trade is 15+.

Then if we take numbers from the example, it turns out that before clearing our stop loss will be +5 points and after clearing it will be -5 points. But if a trade will be closed on stop, we will still get profit of 5 rounds.

Therefore, clearing can be disregarded in the tester.

 
Aleksandr Slavskii #:

Really simple, and most importantly reliable.


I'll forgive the author for the off-topic, but do you have a recipe for determining when clearing is over?

The problem is this: the opener broker, during clearing deletes pending orders, and the clearing field does not set them again.

I don't know about futures, but on stocks clearing ends at different times.

So, I have not been able to determine the moment when clearing ends for a specific security.

I just send a timer order to place an order until it opens.

I don't like this approach, and I don't have another one.

That's OK - discuss and debate together - the topic is open to all!!!!!
 
Aleksandr Slavskii #:

Write-offs during clearing can be disregarded.

Example. You open a buy trade at 50, at the time of clearing the price is say 70. During clearing your trade will be deleted and you will get 20 tugrik, after clearing your trade will be opened at 70.

If you close it at 100, the terminal will show one trade with a profit of 50 tugriks.

The problem usually occurs when writing a trawl or CU. Suppose we want to put a CUE of +5 when the trade is 15+.

Then if we take numbers from the example, it turns out that before clearing our stop loss will be +5 points and after clearing it will be -5 points. But if a trade will be closed on stop, we will still get profit of 5 rounds.

That's why we may disregard clearing in the tester.

Oh! How interesting... will have to go deeper and try it out! :-)

wrote (took from article) f-i-tion exactly out count from trades on history, on fact (it's who has position in plus) - count consecutive minus and display it on screen - sort of ACCOUNT clearing, can certainly not quite it will all be correct when trading - just looking at it now ...

So to close position accurately, for example, taking into account previous clearing, if it was minus - then we should compare values of closed profit and previous loss on clearing.

//+------------------------------------------------------------------+
//|                 УЧЕТ КЛИРИНГА
//+------------------------------------------------------------------+
double Calc_Clearing() // вычисление лота
  {
   bool ord;
   double TotalLot=0;
    for(int i=HistoryDealsTotal()-1; i>=0; i--)
     {
      ulong ticket=HistoryDealGetTicket(i);
      ord=HistoryDealSelect(ticket);
      if(ord && HistoryDealGetString(ticket,DEAL_SYMBOL) == _Symbol
       //  && HistoryDealGetInteger(ticket,DEAL_MAGIC) == MagicC
         && HistoryDealGetInteger(ticket,DEAL_ENTRY) == DEAL_ENTRY_OUT)
        {
         if(HistoryDealGetDouble(ticket,DEAL_PROFIT) <= 0)
           {
            TotalLot+=HistoryDealGetDouble(ticket,DEAL_VOLUME);
           }
         else
           {
            break;
           }
        }
     }
   return TotalLot == 0 ? TotalLot: TotalLot;
  }

found an error - fix it:

TotalLot+=HistoryDealGetDouble(ticket,DEAL_PROFIT);

as a result this is the picture on the screen above before this insertion:

   Comment(" SPREAD текущий по символу ", _Symbol, " составляет: ", SymbolInfoInteger(_Symbol,SYMBOL_SPREAD),
    "      СВЕРКА по клирингу:  ", NormalizeDouble(Calc_Clearing(),0));

clearing reconciliation

because there was no clearing loss yet:

09.11.2021: all "out" is in the plus:


 
Roman Shiredchenko #:

Terrible! There's too much wrong to comment on.

Let's put it another way.

Why do you need transaction history if you are interested in position?

Imho, it is sufficient to write the price of the last position into a variable for each new trade, and when clearing comes, adjust the CU by the difference between the price written in the variable and the price of the last tick before clearing.

Example:

lot = 1;

double end_position=0;

first trade at price 30, end_position = 30;

second trade at the price of 60, end_position = 45;

third trade at price 90, end_position = 60;


That is, you have a position at 60 with a volume of 3.

Suppose the clearing came at the price of 70, the profit is equal to 30 tugriks.

double clearing_price = 70;

After clearing, the position opened at price 70, but we have to remember that the actual price of this position isend_position == 60; therefore, this is the price to calculate the trawl or CUE from.

Accordingly, during clearing, fill in the variable

double corrector = 0;

corrector =clearing_price-end_position;

Suppose you have a CU start when the trade is +20 pips, respectively, add to the CU function that the CU start is: 20 -corrector;

And also the CU is put some points in plus, they must also be corrected by the corrector value.

After closing any position corrector = 0;


But this will only work if there are no partial closes or fills after clearing. If there are, we have to do it differently.

 
Aleksandr Slavskii #:

Really simple, and most importantly reliable.


I'll forgive the author for the off-topic, but do you have a recipe for determining when clearing is over?

The problem is this: the opener broker, during clearing deletes pending orders, and the clearing field does not set them again.

I don't know about futures, but on stocks clearing ends at different times.

So, I have not been able to determine the moment when clearing ends for a specific security.

I simply use timer to send order placement until it opens.

I don't like this approach, and I don't have any other.

I also have an opener, but on futures. I have the same problem with end of clearing, I do not know how to determine it, I just take 19:05.

I mean, you can put the deferrals up to the date, not just for today. At least on futures.

 
Aleksandr Slavskii #:

1. The horror! There's too much wrong to comment on.

Let's put it another way.

Why do you need transaction history if you are interested in position?

Imho, it is sufficient to write the price of the last position into a variable for each new trade, and when clearing comes, adjust the CU by the difference between the price written in the variable and the price of the last tick before clearing.

Example:

lot = 1;

double end_position=0;

first trade at price 30, end_position = 30;

second trade at the price of 60, end_position = 45;

third trade at price 90, end_position = 60;


That is, you have a position at 60 with a volume of 3.

Suppose the clearing came at the price of 70, the profit is equal to 30 tugriks.

double clearing_price = 70;

After clearing, the position opened at price 70, but we have to remember that the actual price of this position isend_position == 60; therefore, this is the price to calculate the trawl or CUE from.

Accordingly, during clearing, fill in the variable

double corrector = 0;

corrector =clearing_price-end_position;

Suppose you have a CU start when the trade is +20 pips, respectively, add to the CU function that the CU start is: 20 -corrector;

And also the CU is put some points in plus, they must also be corrected by the corrector value.

After closing any position corrector = 0;


2. But this will only work if there are no partial closes or fills after clearing. If there are, we should do it differently.

1. Thanks for the schedule. I want to look without corrector for now, as I have additions and trawl with boo + e.g. 30 pips, also after trawl setting there may be partial closes according to robot's operating logic. I.e. after opening a start position, I memorise the open price, after adding an add-on - averaging - I memorise the NEW open price again. And in essence, clearing and setting a new opening price by the broker will not matter.

I understand correctly, that this approach can also take place according to the trading logic above written here in this post of mine...

Further, if current price of the asset allows, transfer SL to BU + 30 pips from previously memorized cumulative position price.

And who cares about the current open position price for the futures, set by your broker?


2.

"But this will only work if there are no partial closes or fills after clearing. If there are, it needs to be done differently. "

I have fills... before and after - until it transfers to BU + 30 pips - is it really necessary to read the current average price of all market orders via arrays, because we will need

...we would need the opening price of a market order and the number and volume of contracts for each order... to display the average price for them in total - where does the transfer to a CU mean - to calculate...


An average price = ((OPEN_1 * VOLUME_1) + (OPEN_2 * VOLUME_2) + (OPEN_3 * VOLUME_3)+n) / (VOL_1 + VOL_2 + VOL_3 + n), here it turns out that I have not translated SL in BU + 30 pips on all aggregate position - it is necessary to write all these values in arrays or what? If we open the N-th market order slice, should we raise this entire chain to calculate the average for all of them?

Or we could play with it somehow:

HistoryOrderSelect ()
HistoryOrderGetTicket ()

But there the question arises as to how to take the beginning and the end of the loop of ACTUAL market orders which take part in the formation of the ACTUAL aggregate position?

 
Roman Shiredchenko #:

VOLUME_Price = ((OPEN_1 * VOLUME_1) + (OPEN_2 * VOLUME_2) + (OPEN_3 * VOLUME_3)+n) / (VOL_1+VOL_2 + VOL_3 + n), so it turns out that I have not yet translated SL into BU + 30 pips on all aggregate position - should I write all these values in arrays? If we open the N-th market order, we have to bring up the whole chain in order to calculate the average for all of them?

Alas, this is exactly the case.

 

Roman Shiredchenko #:

Average_Price = ((OPEN_1 * VOLUME_1) + (OPEN_2 * VOLUME_2) + (OPEN_3 * VOLUME_3)+n) / (VOL_1 + VOL_2 + VOL_3 + n), so it turns out that I have not translated SL into BU + 30 pips on all aggregate position - should all these values write in arrays or what? If we open the N-th market order slice, should we raise this entire chain to calculate the average for all of them?

Or we could play with it somehow:

But there the question arises, how to take the beginning and the end of the cycle of ACTUAL market orders which take part in the ACTUAL total position formation?

It is sufficient to store the last average price.

 
JRandomTrader #:

It is sufficient to keep the latest average price.

OK, but if I refill, for example, with any volume - how do I count it ACTUALLY?
 
Roman Shiredchenko #:
OK, but if I am adding, for example, any volume - how to calculate its ACTUAL?

I showed you. Take this last average price and volume of the position, the price of the new trade and its volume. Everything will be calculated correctly.

Reason: