Start function every tick?

 

hi,


I'm new to MetaTrader and have a question to the start function when writing an expert advisor.

As far the documentation says, the start function will be executed every new tick.

Assume that a tick wil be emitted every second, then I have 60 ticks per minute, 3600 tick per hour.

Assume I have a chart with hour timeframe.

So if I write a start function like iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0); will this be calcuted 3600 times for the same hour bar?


Thanks,

Ilhan

 
ilhany:

hi,


I'm new to MetaTrader and have a question to the start function when writing an expert advisor.

As far the documentation says, the start function will be executed every new tick.

Assume that a tick wil be emitted every second, then I have 60 ticks per minute, 3600 tick per hour.

Assume I have a chart with hour timeframe.

So if I write a start function like iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0); will this be calcuted 3600 times for the same hour bar?

Potentially a whole lot more than 3600 times for a H1 bar.
 
ilhany:

So if I write a start function like iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0); will this be calcuted 3600 times for the same hour bar?


yes, for shift 0.

in other words: start() will be executed this many times, indicator calculation may depend on which bar's value you want to get and the use of IndicatorCalculated() in the indi. code.

 
ilhany:
will this be calcuted 3600 times for the same hour bar?
just to be clear: the bar number is the same but the HLC,V values of the bar will/may change on every tick, so the results of indicators will be, may be different after every tick.
 
Ok, but how can I write a system that is based on completed bars? I haven't found a function for it.
 
ilhany:
Ok, but how can I write a system that is based on completed bars? I haven't found a function for it.

use bar numbers >0. bar. nr (or shift) is usually parameter. you can also check if a new bar was completed on the chart you use.
 
szgy74:

use bar numbers >0. bar. nr (or shift) is usually parameter.


I understand, but I have still a question.

The bar=1 would be a complete bar, thats good.

If I have a signal to buy for bar=1, I would get 3600 signals.

To avoid this, I have to remember that I buyed, correct?

 
szgy74:

you can also check if a new bar was completed on the chart you use.

Is ther a function for this, I haven't found anything
 
ilhany:

Is ther a function for this, I haven't found anything
You code it yourself . . . search for once per bar
 
ilhany:

If I have a signal to buy for bar=1, I would get 3600 signals.

To avoid this, I have to remember that I buyed, correct?


it is enough to calculate the things you want once per bar. that is why I mentioned new bar checking. there are several ways to check, below is an example.

this returns true when a new bar is formed (it happens after when the the next (#1) bar is completed).


//+------------------------------------------------------------------+
//| isNewBar()                                                       |
//+------------------------------------------------------------------+
bool isNewBar() 
{
   bool blnReturn = false;
   static datetime dtLastTime = 0;
   
   if ( Time[0] != dtLastTime ) 
   {
      dtLastTime = Time[0];     
      blnReturn = true;
   }
   
   return( blnReturn );
}

 
Thanks, that will help a lot.
Reason: