Expert/Indicator - page 3

 
double iCustom( string symbol, int timeframe, string name, ... , int mode, int shift)

The first three are symbol, timeframe, name ... the last two are mode and shift. Whatever extra values are there are passed as input.


Obviously I am not making myself clear.

Can I detect "int shift" in my indicator?......so I can add it to my internal indicator values.
-Stan
 
Sub

No, the Expert just "looks" at the indicator and picks the shift'th value (from the ExtMap buffers).

Usually an indicator when added to a chart computes it's values for all the bars. When the ticks come in, MT calls the indicator to compute the most recent bar (or most recent two bars or such). On a new bar, it just moves all values down the buffers (so that the old values remain aligned to the bars for which they were computed) and then you are called again to compute bar 0.

The main part of an indicator to do this is usually something like this:

int start()
{
   int counted_bars= IndicatorCounted(),
         lastbar;
     
   if (counted_bars>0)
      counted_bars--;
      
   lastbar= Bars - counted_bars;

   // dont compute more than 10 bars when called from Expert
   if (FromExpert && lastbar>10)
      lastbar= 10;   

   Print("lastbar= ", lastbar);

   // compute values for indicator buffers from lastbar down to zero
   for (int i= lastbar; i>=0; i--) {
      ...
   }

   return (0);
}   



On the first call (when attaching the indicator to a chart), IndicatorCounted() will be zero, so this way your indicator always fills the Buffers for the whole chart with their values. When new Ticks come in, IndicatorCounted() will be 999 (on a chart of 1000 bars), this means that you don't need to recalc the first 999, just do the current values for bar 0.

On an indicator with a Print as above, you will see this on the output (Experts or Journal tab).

This is done internally by MT. The first iCustom() call adds your indicator to a virtual chart with the given ("...") parameters and then lets it compute it's stuff as on live trading, feeding ticks and telling it what to recompute through the IndicatorCounted() call.

When you call iCustom() with a shift value, it just picks the shift'th value from the mode'th buffer and returns it to your expert. In other words, your indicator is not called for every iCustom call. It is called on a new tick, fills it's buffers and iCustom() just picks the value form the buffers as a human would look at the indicator lines for different bars.

The code snippet above also has a check that the indicator would never compute more than 10 bars when called from an expert. However, this means that your expert should never use an iCustom() call with a shift higher than 10, or it will get an unset value.

If you want a real function call (with control over when and how the indicator is called), you'll need to put it into a function, probably in an .mqh file and #include the function in your indicator and also in the expert.

Hope this will make sense.


Markus

 

Hope this will make sense.

It does make sense Markus, with exception for "FromExpert" variable.
How is it set and cleared?

If from External Input than it would be set only once and remain set even if I would disable expert on the Top Menu Bar.
 
The FromExpert would be an Input. It will be set according to your "..." parameters. If you use iCustom with that set to 1 and set to 0, you will have the indicator on the virtual chart two times, one time with 1, one time with 0 (similar to adding an MA indicator to a chart with different periods).


Markus