Attachments forums

List of attachments posted on this forum.


All files on forums: 136014

Re: Coding Help

aphong, Tue Aug 20, 2019 1:34 pm

mladen wrote: Tue Feb 14, 2017 12:03 am Decided to keep this subject as a section, not as a single thread.

I think that this way we can have cleaner overview and state of coding issues and help (which will, eventually, help more than one single thread will all the issues - harder to find, at the lest then seeing issue short description in the thread name ...)
___________________________

So I would like to suggest it as a kind of a standard :
the thread name should have a short, but descriptive name that describes well enough the codding issue
Hello master mladen & all others,
First, Thank you so much master mladen for sharing lots of cool indis :)
...im quite new to FX & Coding mql4.
I find the "averages - mtf - alerts 9.1.ex4" so cool & want to get signals from this indi by iCustom call.
in fact ... Im testing this by writting an indi to visualize the signals again & check with the signals generated by the "averages - mtf - alerts 9.1.ex4" ... But things are not good, my signals ( yellow & blue arrows) doesnt match the original signals (red & green dots) ? :oops:
is that im calling wrong buffer or sending wrong parameters? please help :(
attached is my code & an image to better describe my problem.


Code: Select all

// Test_iCustom_Signal
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Gold
//
#define NAME "averages - mtf - alerts 9.1"
//
extern int TimeFrame = 1440;
extern int barstotest = 100;
//
double CrossUp[];
double CrossDown[];
//-----------------
int OnInit()
  {
//---- indicators
   SetIndexStyle  (0, DRAW_ARROW, EMPTY, 1);
   SetIndexArrow  (0, 233);
   SetIndexBuffer (0, CrossUp);
   SetIndexStyle  (1, DRAW_ARROW, EMPTY, 1);
   SetIndexArrow  (1, 234);
   SetIndexBuffer (1, CrossDown);
//----
   return(INIT_SUCCEEDED);
  }
//-----------------
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime& time[],
                const double& open[],
                const double& high[],
                const double& low[],
                const double& close[],
                const long& tick_volume[],
                const long& volume[],
                const int& spread[])
  {
   int limit, i, counter, counted_bars=prev_calculated;
   double Range, AvgRange, I, II, III; 
//---- check for possible errors
   if(rates_total<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=rates_total-counted_bars;
   if (barstotest>0) limit = MathMin(limit,barstotest);
   //
   for(i = limit; i >=0; i--) {
      //
      counter=i;
      Range=0;
      AvgRange=0;
      for   (counter=i ;counter<=i+9;counter++) {
            AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
         }
      Range=AvgRange/10;
      /////////////////////////////////////////////////////////
      //sending parameters: (...,0,0,14,0,13,...) == (...,current timeframe, not use custom timeframe, average period=14, mode price_close=10, SMA = 13,...)
      
      I     = iCustom(NULL,TimeFrame,NAME,0,0,14,0,13,   2,  i);
      II    = iCustom(NULL,TimeFrame,NAME,0,0,14,0,13,   2,i+1);
      III   = iCustom(NULL,TimeFrame,NAME,0,0,14,0,13,   2,i+2);
      //////////////////////////////////////////////////////////
      // Buy Arrows
      CrossUp[i] = EMPTY_VALUE;
      if ((I > II) && (II < III))   CrossUp[i]     = Low[i] - Range*1; 
      else CrossUp[i] = EMPTY_VALUE;
      // Sell Arrows
      CrossDown[i] = EMPTY_VALUE;
      if ((I < II) && (II > III))   CrossDown[i]   = High[i] + Range*1; 
      else CrossDown[i] = EMPTY_VALUE;
   }
   //
      return(rates_total);
  }
thanks in advance! ;)
aphong,
All files in topic