Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1384

 
Mikhail Mishanin:

If we replace the "time value" with the difference between the new time and the last calculated time?

I.e. we will know that there is a new time:

-from the new day

-from a new week

-or with a difference of more than the specified time.

I have no idea how to apply this!


On the screenshot rollover and spread widening at 22-00, in most other dealing at 00-00, it is 1 hour after - spread widening.

How do I find out programmatically when rollover is, without limiting the program to the time in the input parameters?

---

P.S. This code behaves well, but on condition that it is run 500 ticks before rollover

bool CheckSpr(int _sp)
{
   static int ts=0, res=0;
   static long tc=0;
  // Comment( res,"=",tc );
   if(tc>500 && res*3<_sp) return(false); // если уже собрали 500 тиков и есть средний спред - смотрим на расширенный spr*3
   tc++;
   ts += _sp;
   res =ts/tc;
   if(tc>LONG_MAX-1) {
      tc=0;
      ts=0;
   }
   // Comment( res,"=",tc );
   if(tc<500) return(false);
   return(res>_sp?true:false);
}
 
Vitaly Muzichenko:

I have no idea how to apply this!


In the screenshot rollover and spread widening at 22-00, in most other dealings at 00-00, it is 1 hour after - spread widening.

How do I find out programmatically when rollover is, without limiting the program to the time in the input parameters?

---

P.S. This code behaves well, but under the condition that it is run 500 ticks before the rollover

The reason of spread widening by dealing is the opening of the trading session, i.e. the "dumping" of a large number of orders for processing, and the uncertainty of how (at what price) everything will "settle". Dealing will insure and widen the spread. You just need to delay the time from the end/beginning of the trading session.

 
Mikhail Mishanin:

The reason for the spread widening by dealing is the opening of the trading session, i.e. a large number of orders being placed for processing, and therefore the uncertainty of how (at what price) everything will "settle". Dealing will insure and widen the spread. You just need to set aside the time from the end/beginning of the trading session.

Yes, but it's not in the instrument specification.

That's where the rollover is at 10:00 p.m.

And this is the rollover at 00-00.


 
Vitaly Muzichenko:

Yes, but it is not in the tool specification

TimeCurrent()-TimeGMT()
 

Hopefully, the final version will take everything into account

MqlDateTime dt;
bool CheckSpr(int _sp)
{
  TimeGMT(dt);
  static int ts=0, res=0;
  static long tc=0;
   if(dt.hour==22) return(false);
   tc++;
   ts += _sp;
   res =ts/tc;
   if(tc>LONG_MAX-1) {
      tc=0;
      ts=0;
   }
   // Comment( res,"=",tc );
   if(tc<500) return(false);
   return(res>_sp?true:false);
}
 
Vitaly Muzichenko:

Hopefully, the final version will take into account all

two variables

datetime daLAST=0;

datetime daOLD=0;


In each function that can "trade", i.e. it can get the time of the tick

daOLD = daLAST;

daLAST= "tick time"

If ( daLAST - daOLD > "time gap") - a new session started, there was a time gap

{

//save, use and cancel this as you please

}

 
Mikhail Mishanin:

two variables

datetime daLAST=0;

datetime daOLD=0;


In each function that can "trade", i.e. can get the time of the tick

daOLD = daLAST;

daLAST="tick time"

If ( daLAST - daOLD > "time gap") - a new session started, there was a time gap

{

//save, use and cancel this as you please

}

There are some pairs and dilemmas where the Asian session may not have a tick for up to several minutes, with a rollover time of 21-59 to 22-01, that is faster than the arrival of the tick in Asia.

 
Vitaly Muzichenko:

There are some pairs and dillings on which in the Asian session there may be no tick for up to several minutes, with rollover time from 21-59 to 22-01, i.e. faster than the arrival of the tick in Asia.

back to square one then.

what is the objective? to skip trades with an exorbitantly widened spread - right?

Then we can probably ignore the time and analyze the spread itself.

if Ask - Bid > "threshold" - enable tracking/accumulation.

ifAsk - Bid < "threshold" - switch it off or also accumulate.

Such a "cow" seems to come in handy for me too, I'll collect something like this, it will collect statistics...


And if there is no fresh tick for some minutes, it will be more reasonable to skip the first one(s) in trade.

The statistics should be collected on specific pairs and dillings, because any "curvature" may work both in "-" and in "+".

 
Mikhail Mishanin:

let's go back to square one then.

what is the objective? to skip trades with an exorbitantly widened spread - right?

Then we can probably ignore the time and analyse the spread itself.

if Ask - Bid > "threshold" - enable tracking/accumulation.

ifAsk - Bid < "threshold" - switch it off or also accumulate.

Such a "cow" seems to be useful for me too, I will collect something like this, it will collect statistics...


And if there is no fresh tick for some minutes, it will be more reasonable to skip the first one(s) in trade.

The statistics should be collected for particular pairs and dillings, because any "curvature" may work as in "-" as in "+".

All that you described makes the code above, except for yellow - I think it is redundant and not quite correct. Somehow never met, that rollover was someone at other time, always all in one and the same - at 22-00 GMT, although I can be mistaken.

But often seen different duration rollover, some 5 minutes, and others a little over a minute.

---

Check code, maybe change something:

//+------------------------------------------------------------------+
void OnTick(void)
{
   int sp = SymbolInfoInteger(Symbol(),SYMBOL_SPREAD);
   static int ts=0;

   if(CheckSpr(sp)) {
      // Здесь код отправки
      Comment( sp,"=",ts++,"=",res );
   } else Comment( "false: ",sp,"=",ts++,"=",res );
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
MqlDateTime dt;
int res=0;
bool CheckSpr(int _sp)
{
  TimeGMT(dt);
  static int ts=0;
  static long tc=0;
   if(dt.hour==22) return(false);
   tc++;
   ts += _sp;
   res =ts/tc;
   if(tc>LONG_MAX-1) {
      tc=0;
      ts=0;
   }
   // Comment( res,"=",tc );
   if(tc<500) return(false);
   return(res>_sp?true:false);
}
 
Vitaly Muzichenko:

Everyone's at the same time - 10pm GMT, although I could be wrong.

You're not wrong.