Simples questions about mql5

 

Hello,

I'm pretty new with this programming language , I've searched answers to my questions on the internet but couldn't find very clear answers;

1) Is the ontick function launching at every tick ? Basically , if i want to count number of ticks that appears as a example, i would simple have to do something like ,

void ontick ()

{

int counter;

counter=counter+1;

}

And it will count the number of ticks that appears;

2)So I guess , putting a conditions at a specific time , like I want my expert to buy at 9 o clock precisely ,It would be a problem because let's imagine there would be no tick between 9 and 9:01 (no chance it happens but let suppose it) , then my code won't work because it would only launch the ontick function when a tick is generated;

How to deal with the problem ? Something with using the ontimer function maybe ?

(More precisely , how to do a specific action at a specific time , that would work even if there were no ticks on the chart)

Sorry for my bad English,

Eol.

 
eoltrading :

Hello,

I'm pretty new with this programming language , I've searched answers to my questions on the internet but couldn't find very clear answers;

1) Is the ontick function launching at every tick ? Basically , if i want to count number of ticks that appears as a example, i would simple have to do something like ,

void ontick ()

{

int counter;

counter=counter+1;

}

And it will count the number of ticks that appears;

2)So I guess , putting a conditions at a specific time , like I want my expert to buy at 9 o clock precisely ,It would be a problem because let's imagine there would be no tick between 9 and 9:01 (no chance it happens but let suppose it) , then my code won't work because it would only launch the ontick function when a tick is generated;

How to deal with the problem ? Something with using the ontimer function maybe ?

(More precisely , how to do a specific action at a specific time , that would work even if there were no ticks on the chart)

Sorry for my bad English,

Eol.

1. There is no 'ontick' in MQL5 - there is 'OnTick' in MQL5.

2. If there are no ticks in the specified period of time, you can hedge against the timer (OnTimer)

3. How to open a position at 9-00: Check the time (it is better to check the time interval). If you find our time - open a position


   MqlDateTime STimeCurrent;
   TimeToStruct(TimeCurrent(),STimeCurrent);

   if(STimeCurrent.hour==9 && STimeCurrent.min==0)
      if(PositionsTotal()==0)
        {
         m_trade.Buy(1.0);
        }


*** m_trade;                      // object of CTrade class

Documentation on MQL5: Standard Library / Trade Classes / CTrade
Documentation on MQL5: Standard Library / Trade Classes / CTrade
  • www.mql5.com
Standard Library / Trade Classes / CTrade - Reference on algorithmic/automated trading language for MetaTrader 5
 

eoltrading:

1) Is the ontick function launching at every tick ? ;

2)So I guess , putting a conditions at a specific time , like I want my expert to buy at 9 o clock precisely ,It would be a problem because let's imagine there would be no tick between 9 and 9:01 (no chance it happens but let suppose it) , then my code won't work because it would only launch the ontick function when a tick is generated;

How to deal with the problem ? Something with using the ontimer function maybe ?

  1. Perhaps you should read the manual.

  2. Don't assume that every bar every exists — they don't. What if there are no ticks during a specific candle period? There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific.) requires knowledge of when your broker stops and starts (not necessary the same as the market.)
              "Free-of-Holes" Charts - MQL4 Articles
              No candle if open = close ? - MQL4 programming forum

  3. If there are no ticks, nothing has changed. You didn't want to do something before 9AM. Why does it have to be a precise time? Nothing has changed but one tick. If you insist, use the timer. (№ 1)
 
static int counter=0;

May this helps

 
eoltrading:

Hello,

I'm pretty new with this programming language , I've searched answers to my questions on the internet but couldn't find very clear answers;

1) Is the ontick function launching at every tick ? Basically , if i want to count number of ticks that appears as a example, i would simple have to do something like ,

void ontick ()

{

int counter;

counter=counter+1;

}

And it will count the number of ticks that appears;

2)So I guess , putting a conditions at a specific time , like I want my expert to buy at 9 o clock precisely ,It would be a problem because let's imagine there would be no tick between 9 and 9:01 (no chance it happens but let suppose it) , then my code won't work because it would only launch the ontick function when a tick is generated;

How to deal with the problem ? Something with using the ontimer function maybe ?

(More precisely , how to do a specific action at a specific time , that would work even if there were no ticks on the chart)

Sorry for my bad English,

Eol.

int tick_counter =0;
//--- there is another event called on timer. It deals with time-driven functions
int OnInit()
{
        EventSetTimer(60);
return 0;
}
//---
void OnTick()
{
        tick_counter+=1;
        //or 
        tick_counter = tick_counter+1;
        //or
        tick_counter++;
}
//---
void OnTimer()
{
        //find out how to check time, then use it here.
        if(check_time ==trading_time)
        // open trades here
}
Reason: