Buy stop Sell stop Grid advisor as a class - page 3

 
Vladimir Karputov:

Version 1.003:

  • now closes ALL opposing positions when a position is opened.
  • current price acquisition has been moved inside the PlacesBuy and PlacesSell functions to protect against gaps and slippages.
  • InOnTradeTransaction pending orders are placed in a while loop - so to say, we are beating the server to the punch :) - It is not the best solution but it will stay for now.

Actually, now we can think:

  1. What is the best way to increase positions (lot volume calculation)?
  2. What to do with the opposing positions


  1. How best to increase position (lot volume calculation) - no way, adding lots, this is a pyramid, this is different, the lot should remain constant.
  2. What to do with the opposite positions - Close as is.
 

I recommend adding this indicator to the "tester.tpl" template:LifeHack Balance Equity, then the tester will immediately show changes in balance and funds. Approximately like this:

LifeHack Balance Equity in the tester


 
Vladimir Karputov:

Feito. Conecte o Vault, atualize os arquivos do projeto do Vault.



Hi Vladimir, can you add me please? thank you so much.

 
Cid Ougaske:


Hi Vladimir, can you add me please? Thank you so much.


Done, added it.

The plan is to make statistics like this: how many positions of one direction are open in a row before the flip.

For example: #1 Buy, #2 Buy, #3Buy and #1Sell -> close all Buy positions. So the statistics will be: three positions.

 
Vladimir Karputov:

... connect the template and pass the input parameters to the EA class



Done, connected.

Sometimes there are too many parameters. Recently, I've become lazy. I do it this way because I do not need to bother with passing parameters to the EA. What are the disadvantages?

input double LotSize = 0.1;
input int    SL      = 500;
input int    TP      = 300;
//другие входные переменные

#include <AvLib\ClassEA.mqh> // тут лежит класс советника

CClassEA MyEA;
 

Vladimir, can you hook me up, please?

 

While the Expert Advisor is working, data is written to the array in OnTradeTransaction. The recording format is as follows: if a Buy position is opened, we record "+1"; if a Sell position is opened, we record "-1".

For instance:

  • Buy - we record "+1".
  • Buy - we record "+1".
  • Buy - we record "+1".
  • Sell - we record "-1".

When testing is completed, the array data is processed in OnTester and written to the csv file. The file is created ina shared folder of all client terminals \Terminal\Common\Files. The name of the file is formed as follows:

   string file_name="Direction_of_trades"+"_"+m_symbol.Name()+"_"+IntegerToString(StepGrid());

then the extension "csv" is added to the file name:

   int filehandle=FileOpen(file_name+".csv",FILE_WRITE|FILE_CSV|FILE_COMMON);

Algorithm of array processing: if current record is the same direction as previous one (it corresponds to opening several positions of one direction in a row) - then we increase counter by one, if current record is opposite to previous one (it corresponds to reversal of position direction) - then we assign counter value "1" to it.

The resulting csv file is easy to process in Excel:

step one: left click on the column with the data

left-click

step two: insert recommended chart

insert recommended chart


These are the statistics (for step "35" and step "65"):

direction_of_trades_EURUSD_35_65

 
Alexey Volchanskiy:

Vladimir, can you hook me up, please?


Done. Added (didn't see the post right away, missed it).

 

The current list of connected users to the project:

Users connected to the project

 

For step 35, extended totals:

Direction_of_trades_EURUSD_35

Here we can see that

  • practically 50% of all cases are when the length of uninterrupted trades equals "1". In other words, we have situations such as: we opened Buy and then reversed the position (i.e. closed Buy with a loss and opened Sell) or this situation: we opened Sell and then reversed the position (i.e. closed Sell with a loss and opened Buy). Thus situations with uninterrupted trades of length "1" are a guaranteed loss.
  • Approximately 25% of all cases with the length of uninterrupted trades equaling "2", by the following example: we opened Buy, then opened another Buy and reversed the position (i.e. closed two Buy and opened Sell - resulting in a loss equal to zero).

I think these most numerous categories (length of uninterrupted trades equal to "1" and "2") must be thought over in more detail in order to correct the strategy of placing Stop pending orders.

Reason: