Библиотеки: Virtual - страница 56

 
В библиотеке есть такая метка виртуальных тиков.
this.CurrentTick.flags |= this.Handle << 8; // Метка виртуального тика.

Позволяющая идентифицировать окружение, из которого был получен тик через SymbolInfoTick.


Кто использует, учитывайте это изменение от MQ.

 

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Библиотеки: Virtual

hini, 2024.08.05 03:44

void OnTickMulti( const string &Symb, const int &Index ) {
    _VSP(virtualEnvAry[Index]); // Choose a virtual trading environment
    MqlTick ticks[1];
    if (SymbolInfoTick(Symb, ticks[0])) break;
    VIRTUAL::NewTickMulti(ticks, hedge.MyOnTick);
}

// void Hedge::MyOnTick(const string &Symb_, const int &Index_)

May I ask the author why it cannot be compiled here?

error: pointer to this function type is not supported yet

void OnTickMulti( const string &Symb, const int &Index ) {
    _VSP(virtualEnvAry[Index]); // Choose a virtual trading environment
    MqlTick ticks[1];
    if (!SymbolInfoTick(Symb, ticks[0])) break;
    VIRTUAL::NewTickMulti(ticks, MyStrategy);
}

void MyStrategy( const string &Symb, const int &Index )
{
  hedge.MyOnTick(Symb, Index);
}


Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Библиотеки: Virtual

hini, 2024.08.05 04:00

void OnTickMulti( const string &Symb, const int &Index ) {
    _VSP(virtualEnvAry[Index]); // Choose a virtual trading environment
    MqlTick ticks[1];
    if (SymbolInfoTick(Symb, ticks[0])) break;
    VIRTUAL::NewTickMulti(ticks);
    hedge.MyOnTick(Symb, index);
}

Should it be used this way?

Можно и так.

 

Thank you very much!

fxsaber #:
Можно и так.
Thank you very much!
 
fxsaber #:
В библиотеке есть такая метка виртуальных тиков.

Позволяющая идентифицировать окружение, из которого был получен тик через SymbolInfoTick.


Кто использует, учитывайте это изменение от MQ.

Could you please tell me if there are specific application scenarios for this? Is it used within the trading system TS to identify whether the current environment is virtual or real, and then take targeted actions accordingly?
 
  ORDER order1;
  order1.MagicNumber = 111;
  order1.Type = OP_BUY;
  order1.Ticket = 1;
  order1.TakeProfit = 0;
  order1.StopLoss = 0;
  order1.Commission = 0;
  order1.Swap = 0;
  order1.CloseTimeMsc = 0;
  order1.Lots = 0.01;
  order1.OpenPrice = 1.23345;
  order1.OpenTimeMsc = D'2024-06-07 18:33:34';
  VIRTUAL::AddOrder(order1);

Why can't I retrieve the profit after adding a virtual order? The order is still open, but  OrderProfit()  returns a very small negative value.

 
hini #:
Could you please tell me if there are specific application scenarios for this? Is it used within the trading system TS to identify whether the current environment is virtual or real, and then take targeted actions accordingly?

Такое иногда может пригодиться для самоконтроля в сложных советниках.

 
hini #:

Why can't I retrieve the profit after adding a virtual order? The order is still open, but  OrderProfit()  returns a very small negative value.

Не понимаю.

 
fxsaber #:

Не понимаю.

I tested in a virtual environment without using  OrderSend()  to open positions. Instead, I manually added a series of  ORDER_BASE  orders using  VIRTUAL::AddOrder(orders);  to the virtual environment. Then, I used  OrdersTotal()  to iterate through the manually added orders and could retrieve the lot size, but I am unable to get the profit using  OrderProfit() .
 
fxsaber #:

Не понимаю.

In summary, I want to manually add positions at any time, with any lot size, and whether they are closed or still open. This would allow me to immediately test how the EA performs under certain market conditions without needing to use the tester to find such conditions for testing.

#define PIPS_TO_PRICE_TEST(x)  ((x) * SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE))
ORDER_BASE orders[];
ENUM_ORDER_TYPE firstType = OP_BUY;
int size = 7;
string strLots = "0.01,0.03,0.06,0.07";
string lots[];
int lotsSize = ::StringSplit(strLots, ',', lots);
ArrayResize(lots, size);
for (int i = 0; i < size; i++) {
  if (lots[i] == NULL) lots[i] = lots[lotsSize - 1];
}
double startOP = 1.23125;
datetime startOTime = D'2024-06-07 18:33:34';
ArrayResize(orders, size);
for(int i = 0; i < size; ++i) {
  ORDER order1;
  order1.MagicNumber = virtualHedgeAry[curSymbolIndex].EAMagicNumber;
  order1.Type = firstType;
  order1.Ticket = i + 1;
  order1.TakeProfit = 0;
  order1.StopLoss = 0;
  order1.Commission = 0;
  order1.Swap = 0;
  order1.Profit = -121;
  order1.CloseTimeMsc = 0;
  order1.ClosePrice = 0;
  order1.OpenReason = DEAL_REASON_EXPERT;
  order1.CloseReason = DEAL_REASON_CLIENT;
  order1.Lots = StringToDouble(lots[i]);
  order1.OpenPrice = startOP + PIPS_TO_PRICE_TEST(100);
  order1.OpenPriceRequest = order1.OpenPrice;
  order1.ClosePriceRequest = 0;
  order1.OpenTimeMsc = startOTime + 60 * 60;
  orders[i] = order1;
}

VIRTUAL::AddOrder(orders);

double totalProfit = 0;
for(int i = OrdersTotal() - 1; i >= 0; --i) {
  totalProfit += OrderProfit();	
}


 
hini #:
I tested in a virtual environment without using  OrderSend()  to open positions. Instead, I manually added a series of  ORDER_BASE  orders using  VIRTUAL::AddOrder(orders);  to the virtual environment. Then, I used  OrdersTotal()  to iterate through the manually added orders and could retrieve the lot size, but I am unable to get the profit using  OrderProfit() .
#include <fxsaber\Virtual\Virtual.mqh>

#define Ask SymbolInfoDouble(_Symbol, SYMBOL_ASK)

void OnStart()
{
  if (VIRTUAL::SelectByHandle(VIRTUAL::Create()))
  {
    VIRTUAL::NewTick();
    
    if ((OrderSend(_Symbol, OP_BUY, 1, Ask, 0, 0, 0) > 0) && OrderSelect(0, SELECT_BY_POS))
    {
      ORDER_BASE Order = VIRTUAL::GetOrder();
      
      Order.Ticket = 123;
      
      if (VIRTUAL::AddOrder(Order))
        for (uint i = OrdersTotal(); (bool)i--;)
          if (OrderSelect(i, SELECT_BY_POS))
            OrderPrint();      
    }
  }
}


Result.

#123 2024.08.05 10:28:06.022 buy 1.00 AUDCAD 0.89312 0.00000 0.00000 0.89305 0.00 0.00 -7.00 0: -7 (-7) - 00:00:00
#2 2024.08.05 10:28:06.022 buy 1.00 AUDCAD 0.89312 0.00000 0.00000 0.89305 0.00 0.00 -7.00 0: -7 (-7) - 00:00:00