Errors, bugs, questions - page 1863

 
fxsaber:

ACCOUNT_PROFIT in the tester shows nonsense.


I will add:

1. for exchange instruments

Как следствие, неправильно оцениваются эквити, просадка и т.д.

2. Also, the Expert Advisor's logic does not work correctly when focusing on the total profit/loss of positions.

We focus on ACCOUNT_PROFIT values at closing.

2017.04.20 11:30:26.318 Core 1  2017.04.17 18:02:46   Профит = 333.01

On closing, the terminal recalculates the profit, so you end up with

close on loss

2017.04.20 11:30:26.318 Core 1  2017.04.17 22:02:08   Профит = -338.66

as a result we have

#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
//--- global variable
CPositionInfo  m_position;                   // trade position object
CTrade         m_trade;                      // trading object
input     string symb="GOLD-6.17";
input     string symb1="GOLD-9.17";
input     double  ТП  =333;
datetime date1;
double i1,ask1,ask2,bid1,bid2,last1,last2,profit;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
  double price1=SymbolInfoDouble(symb,SYMBOL_BID);
  double price2=SymbolInfoDouble(symb1,SYMBOL_BID);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
Comment("");
   }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+

void OnTick()
  {
//---
      profit=AccountInfoDouble(ACCOUNT_PROFIT);
      Comment("ПРофит = ",profit);
     if(PositionsTotal()==0 )
     {
      m_trade.Buy(1.00,symb);
      m_trade.Buy(1.00,symb1);    
     }

   if( MathAbs(profit)>=ТП )
     {
      Print("Профит = ",profit);
     CloseAll();
     }

  }  
//+------------------------------------------------------------------+
void CloseAll()
  {
   for(int i=PositionsTotal()-1;i>=0;i--) // returns the number of open positions
      if(m_position.SelectByIndex(i))
         m_trade.PositionClose(m_position.Ticket());
  }
//+------------------------------------------------------------------+

 
kaus_bonus:

I'll add:

In the SD, we're dealing with...
 
Slawa:
Apparently I do not understand something about HFT. As far as I know, when you trade "very fast", you don't care about previous trades.

HFT gave an example of a TS that just makes a lot of trades.

You can run a run over a long period of some scalper. The main thing is to have a lot of trades (tens of thousands). Then the disadvantages of the current implementation of working with history will appear.


The current situation is as follows. If there are a lot of deals, do not use history.

 
fxsaber:
In the SD...


that's great.

it is enough to remove the use of LAST price to get adequate results

 

Please help me to find minimum indentation in points from position open price to stop-loss and take-profit levels, in order not to put them too close to open price and not to run into error 10016 (TRADE_RETCODE_INVALID_STOPS). I tried to use SymbolInfoInteger (see code below), but this calculation returns 0. If anyone can give me an idea how to calculate it correctly.

void OnStart()
  {
   long stopLevel;
   if(SymbolInfoInteger("EURUSD",SYMBOL_TRADE_STOPS_LEVEL,stopLevel))
      Print("stopLevel = ",stopLevel);
  }
 
Maxim Khrolenko:

Please help me to find minimum indentation in points from position open price to stop-loss and take-profit levels, in order not to put them too close to open price and not to run into error 10016 (TRADE_RETCODE_INVALID_STOPS). I tried to use SymbolInfoInteger (see code below), but this calculation returns 0. If anyone can give me an idea how to calculate it correctly.


0 - no limit. But there are also SYMBOL_SESSION_PRICE_LIMIT_MIN and SYMBOL_SESSION_PRICE_LIMIT_MAX.
 
fxsaber:

0 - there is no limit. But there are also SYMBOL_SESSION_PRICE_LIMIT_MIN and SYMBOL_SESSION_PRICE_LIMIT_MAX.
Hmm, in that case I wish SYMBOL_TRADE_STOPS_LEVEL would somehow work differently. If 0 is unlimited, then theoretically, when sending .PositionOpen(...) to the server, we could set stops at 1 point (by 5 digits) from the open price but the TRADE_RETCODE_INVALID_STOPS error would pop up 100%. I'm stumped so far.
 
Maxim Khrolenko:
Hmm, in that case I would like SYMBOL_TRADE_STOPS_LEVEL to work differently somehow. If 0 is unlimited, then theoretically, when sending .PositionOpen(...) to the server, one could place stops at 1 pip (by 5 digits) from the open price, but the TRADE_RETCODE_INVALID_STOPS error would pop up 100% here. I'm stumped so far.

How about this?

 if(stoplevel==0) stoplevel=SymbolInfoInteger(symb,SYMBOL_SPREAD);
 
Something has happened to the tester again - 1586. Expert Advisor for playback
#include <MT4Orders.mqh>

// Metaquotes-Demo, RTS-6.17, 2017.04.07 - 2017.04.08, на основе реальных тиков, начальный баланс 100000
void OnTick()
{  
  static int Type = OP_BUY;

  MqlTick Tick;    
  
  if (OrderSelect(0, SELECT_BY_POS) && (OrderType() <= OP_SELL))
    OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0);    
  else if ((OrdersTotal() == 0) && SymbolInfoTick(_Symbol, Tick) && (Tick.bid != 0) && (Tick.ask != 0))
  {
    OrderSend(_Symbol, Type + OP_BUYLIMIT, 1, (Type == OP_BUY) ? Tick.ask : Tick.bid, 0, 0, 0);
    
    Type = OP_SELL - Type;
  }    
}

At every tick either puts a limit at the current price (to execute immediately) or closes the position. That is, there should be a lot of positions. But this is not the case, as the limiters have stopped executing. Here is the end of the log showing

2017.04.20 12:47:41.885 2017.04.07 10:00:00   sell limit 1.00 RTS-6.17 at 114060 (114060 / 114180 / 113770)
2017.04.20 12:47:41.885 2017.04.07 23:44:59   order canceled due end of test [#140  sell limit 1.00 RTS-6.17 at 114060]
2017.04.20 12:47:41.885 final balance 91195.12 RUR
2017.04.20 12:47:41.885 RTS-6.17,M1: 327182 ticks, 788 bars generated. Test passed in 0:00:00.218.

SellLimit was set at Bid, but it was never executed.

In 1585 everything was ok with it.

 
fxsaber:
Something has been done to the tester again - 1586.

And I understand that I'm wrong, but still I get the impression of some wrong approach to builds release. There used to be no such a large number of bug reports after builds release.