The differences among OnCalculate(), start() and OnStart()

 

Does any one can tell:

What are differences among OnCalculate(), start()  and OnStart()?

How to get prev_calculated value in start() function?

Cheers

 
dolemi: What are differences among OnCalculate(), start()  and OnStart()? How to get prev_calculated value in start() function?
Read the documentation
  1. start(): old way, script, EA, or indicator. Indicator uses IndicatorCounted()
  2. New way OnCalculate - indicator only. OnStart - script only. OnTick - EA only.
 
WHRoeder:
dolemi: What are differences among OnCalculate(), start()  and OnStart()? How to get prev_calculated value in start() function?
Read the documentation
  1. start(): old way, script, EA, or indicator. Indicator uses IndicatorCounted()
  2. New way OnCalculate - indicator only. OnStart - script only. OnTick - EA only.
Thanks
 
dolemi:
Thanks
It may also help clear things up to review this information...  https://docs.mql4.com/runtime/event_fire#calculate
 
in my indicator generator, it looks like this.

int start()
  {
   OnEveryTick1();

   return(0);
  }

//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnEveryTick1()
  {

   int i;
   int counted_bars = IndicatorCounted();
   if(counted_bars < 0)
      return(-1);
   if(counted_bars > 0)
      counted_bars--;
   i = Bars - counted_bars;
// main calculation loop
   while(i >= 0)
     {
      current = i;
      ChartText2();

      i--;
     }
  }

Is it wise to do this instead of using OnCalculate() ?

 
Muhammad Naim Bin Nordin #:
in my indicator generator, it looks like this.

Is it wise to do this instead of using OnCalculate() ?

No!

 

You should stop using the old event handlers and IndicatorCounted() and start using new event handlers.
          Event Handling Functions - MQL4 Reference
          How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 (2016)

 
William Roeder #:

You should stop using the old event handlers and IndicatorCounted() and start using new event handlers.
          Event Handling Functions - MQL4 Reference
          How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 (2016)

Thank you for the response.

with all brilliant post from you, and some youtubers i managed to built this:

{

   int total = 0;

   switch(prev_calculated == 0)
     {
      case true:
         total = rates_total-1;
         if(total>500)
            total = 11;
         break;

      case false:
         total=rates_total-prev_calculated+1;
         if(total>500)
            total = 11;
         break;
     }

   for(int i = 1; i < total ; i++)
     {
      Print("This candle is ",i," high is ", High [i+1]," broker time is ", TimeToString(Time[i],TIME_MINUTES));
     }


   return(rates_total);
  }

Tested that and it does exactly what i've intended to.

 
Keith Watford #:

No!

 {

//int j = (i == 10) ? 1 : 0; // If i is equal to 10 j is assigned the value 1, otherwise it is assigned 0.

   int look = 0, forCount = (rates_total-1>500 && prev_calculated == 0) ? AroonPeriod : rates_total-prev_calculated+look;

   for(int i=forCount; i>=0+look; i--)

      //for(int i=0+look; i < forCount; i++)

     {
      prh[i] = getPrice(PriceHigh,Open,Close,High,Low,i,0);
      prl[i] = getPrice(PriceLow,Open,Close,High,Low,i,1);
      Print("candle sekarang ialah ",i," high ialah ", High [i]," masa open candle ialah ", TimeToString(Time[i],TIME_MINUTES));
      double max=0;
      double maxv=prh[i];
      double min=0;
      double minv=prl[i];
      for(int k=1; k<=AroonPeriod && (i+k)<Bars; k++)
        {
         if(prh[i+k]>maxv)
           {
            max=k;
            maxv = prh[i+k];
           }
         if(prl[i+k]<minv)
           {
            min=k;
            minv = prl[i+k];
           }
        }
      valueup[i]  = 100*(AroonPeriod-max)/AroonPeriod;
      valuedn[i]  = 100*(AroonPeriod-min)/AroonPeriod;

      //lebih ni

     }
   return(rates_total);
  }


I have one question. This doesn't work when i changed to

for(int i=0+look; i < forCount; i++)

So, how to solve this? I'm intended for this running only once per bar