Questions from Beginners MQL4 MT4 MetaTrader 4 - page 180

 
Igor Makanu:

Yes, I am of the same opinion, but not only history and number of indicator buffers - i.e. again on memory allocation, if MT4 has gobbled up all the memory, then it is slowing down - apparently it starts freeing up memory areas

Definitely, the developers can answer, but we are talking about MetaTrader 4, and here ...

 
Alexander Fedosov:

Why make any calculations in the code?

Don't do calculations - the topic was not smart, and I was interested to check what the optimizer does, so I drafted the code

You may add it to your code in such a way:

int handle=INVALID_HANDLE;
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   handle=FileOpen("tst.txt",FILE_READ|FILE_WRITE|FILE_TXT);
   FileSeek(handle,0,SEEK_END);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   if(handle!=INVALID_HANDLE)
     {
      FileWriteString(handle,DoubleToString(Value1),DoubleToString(Value2)+"\n");
      FileClose(handle);
     }
  }
//+------------------------------------------------------------------+
void OnTick()
  {
  }

i.e. just write optimization parameters into the file, if it hangs, in the file you can read the last pass what parameters were and time of file will be time of "last breath" of the tester

 
Artyom Trishkin:

The developers will be able to answer unambiguously, but we are talking about MetaTrader 4, and there ...

And here... nothing's going to change. We use what we have.

 

Hello, Can you advise me, the trading system only opens a position when a new hour bar opens under certain conditions. I need to make sure that if I close the position using a stop loss on the current bar, the trade will not open again. I implemented it this way :

if (OrdersTotal()==0 && ticket!=-1) // no open lots but ticket exists

{

if (OrderSelect(ticket,SELECT_BY_TICKET)==true)

{

datetime tct=OrderCloseTime(); // order close time

datetime tob=iTime(NULL,PERIOD_H1,0); // Open time of the current bar

if (tob>tct) // does not allow to open a new order if the trade has closed on the same bar as it opened

{

FUNCTION TO OPEN A POSITION

}


In the strategy tester, reopened positions are no longer opened, but when trading live, a position is opened. Can you tell me what's wrong?)

 
kmerlin:

Hello, Can you tell me if the trading system opens a position only at the opening of a new hourly bar under certain conditions? I need to make sure that if I close the position using a stop loss on the current bar, the trade will not open again. I implemented it this way :

if (OrdersTotal()==0 && ticket!=-1) // no open lots but ticket exists

{

if (OrderSelect(ticket,SELECT_BY_TICKET)==true)

{

datetime tct=OrderCloseTime(); // order close time

datetime tob=iTime(NULL,PERIOD_H1,0); // Open time of the current bar

if (tob>tct) // does not allow to open a new order if the trade has closed on the same bar as it opened

{

FUNCTION TO OPEN A POSITION

}


In the strategy tester, reopened positions are no longer opened, but when trading live, a position is opened. Can you tell me what's wrong?)

Is it?

 
Alexander Fedosov:

Is it?


not really. What's wrong with my variant ? the main condition is not being able to re-enter on the current hourly candle ! It's a pretty simple condition, what's wrong with it and why doesn't it work ?

 
kmerlin:

not really. What's wrong with my variant? the main condition is that it is not possible to re-enter on the current candle! It's a pretty simple condition, what's wrong with it and why doesn't it work?

if (OrdersTotal()==0 && ticket!=-1) // Открытых лотов нет но тикет существует

{

if (OrderSelect(ticket,SELECT_BY_TICKET)==true)

{

datetime tct=OrderCloseTime(); // Время закрытия ордера

datetime tob=iTime(NULL,PERIOD_H1,0); // Время открытия бара текущего

if (tob>tct) // Не дает открыть повторный ордер если сделка закрылась на той же свече что и открылась

{

ФУНКЦИЯ ОТКРЫТИЯ ПОЗИЦИИ

}

And what ticket did you choose in OrderSelect?

 
Alexander Fedosov:

Which ticket did you select in OrderSelect?

The ticket is sent last... When an order is open, no new orders can be opened in the system and no pending orders can be placed. So the last ticket is the last stop or profit order.
 
kmerlin:
The ticket is passed to the last order. When an order is open, the opening of new orders is impossible within the system, and the pending orders cannot take place either. So, the last ticket is the last order at stop or profit.

How do you pass the ticket of the last order?

And OrdersTotal() passes the total number of open and pending orders.

Here is the new bar of the current timeframe.

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool IsNewBar()
  {
   static datetime prevtime=0;
   if(prevtime==Time[0])
      return(false);
   else
     {
      prevtime=Time[0];
      return(true);
     }
  }
 
Alexander Fedosov:

How do you pass the ticket of the last order?

And OrdersTotal() passes the total number of open and pending orders.

Here is the new bar of the current timeframe.

The ticket is declared as a global variable. A ticket is passed to buy or sell. In my system, several orders cannot be opened, only one order can be opened, and there cannot be any pending ones either. Therefore, the last ticket, as I understand it, is an order closed at profit or stop.

ok, my head is buzzing... i will rethink your advice tomorrow

Reason: