Download MetaTrader 5

Programming contest : find some bugs in less time. Start Monday at 15:00 GMT. Sign up here.

To add comments, please log in or register
Alain Verleyen
Moderator
32829
Alain Verleyen  

This is the announcement for the 1er programming contest for mql5 community. This little contest consist to find some bugs in less time possible.


See also this topic Programmers Contest : Who can find more bugs in less time. Are you interested to participate ?

There is no price, the goal is to learn and entertain us a little. Monday at 15:00 GMT, I will post a mql5 code, with some bugs. Each participant can then begin his work to found the bug and then send me the results. When all results will be received, I will post them here, with a classification and of course some explanation. Of course some people who are interested to participate won't be free at this time, so don't worry, it's only the first contest, and the followers will be planned at different day/time, you can post your preference in this thread to help us organize the next contest.

The rules are the following :

  1. To participate you have simply to add a new post in this thread.
  2. Monday 2014.01.2014 at 15:00 GMT, I will post the buggy code on this thread, with some explanation if necessary.
  3. When the job will be done, you have to post the corrected code to me by pm.
  4. When all participants will have posted their code, I will post the results of each one here.
  5. The first to post a good answer will be the winner.
  6. A complete classification will be posted here too.

We are also trying to organize such contest for mql4 and on other language sections. Feel free to ask any question.

P.S: If some is interested but want to be anonymous for whatever reason, there is no problem. Simply send me your code with correction, I won't publish your name publicly.

Alain Verleyen
Moderator
32829
Alain Verleyen  
If your are interested to prepare the buggy code and have some ideas about that, please contact me by pm. Of course, that means you can't participate to the contest.
Xiangdong Guo
3983
Xiangdong Guo  
interesting...
Alain Verleyen
Moderator
32829
Alain Verleyen  
tradelife:
interesting...
Can I consider you as a participant ?
Biantoro Kunarto
17055
Biantoro Kunarto  
I participated in this contest
enbo lu
Moderator
1941
enbo lu  
I'm in... if I have the time.
Xiangdong Guo
3983
Xiangdong Guo  
angevoyageur:
Can I consider you as a participant ?
Yes, of course.
Alain Verleyen
Moderator
32829
Alain Verleyen  
So we have 3 participants for now.
Alain Verleyen
Moderator
32829
Alain Verleyen  
Soon the contest will begin, I hope participants are present.
Alain Verleyen
Moderator
32829
Alain Verleyen  

So you can find the buggy code attached. This is an indicator where I introduced some bugs myself, below you can find the result you have to obtain when attached to a chart.

Please respect the rules and don't try to find the original code on Internet.

When you think you have the expected result, please post me the code by pm.

Files:
Contest1.mq5 6 kb
Alain Verleyen
Moderator
32829
Alain Verleyen  

We get 1 winner, which is not even listed as participant.

The winner is Tjipke de Vries (deVries)

Congratulations !

He found the 3 bugs I introduced, and even a little more, good work !

Here his code, with the bugs and correction highlighted in yellow and the original code can be found here.

#property indicator_chart_window 
#property indicator_buffers 2
#property indicator_plots   2
#property indicator_type1   DRAW_ARROW
#property indicator_color1  Red
#property indicator_width1  4
#property indicator_label1  "Sell"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  Lime
#property indicator_width2  4
#property indicator_label2 "Buy"

//+----------------------------------------------+
//|  Indicator input parameters                  |
//+----------------------------------------------+
input int RISK=3;
input int NumberofAlerts=2;

double SellBuffer[];
double BuyBuffer[];

int K,SSP=9;
int counter=0;
bool old,uptrend_;
int StartBars;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//---- initialization of variables of the start of data calculation
   StartBars=SSP+1;
//---- set dynamic array as an indicator buffer
   SetIndexBuffer(0,SellBuffer,INDICATOR_DATA);
//---- shifting the start of drawing of the indicator 1
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,StartBars);
//---- create a label to display in DataWindow
   PlotIndexSetString(0,PLOT_LABEL,"Sell");
//---- indicator symbol
   PlotIndexSetInteger(0,PLOT_ARROW,108);
//---- indexing elements in the buffer as time series   
   ArraySetAsSeries(SellBuffer,true);   
//---- setting the indicator values that won't be visible on a chart
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);    
   
   
   

//---- set dynamic array as an indicator buffer
   SetIndexBuffer(1,BuyBuffer,INDICATOR_DATA);
//---- shifting the start of drawing of the indicator 2
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,StartBars);
//---- create a label to display in DataWindow
   PlotIndexSetString(1,PLOT_LABEL,"Buy");
//---- indicator symbol
   PlotIndexSetInteger(1,PLOT_ARROW,108);
//---- indexing elements in the buffer as time series
   ArraySetAsSeries(BuyBuffer,true);   
//---- setting the indicator values that won't be visible on a chart
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0);   
   
   

//---- Setting the format of accuracy of displaying the indicator
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//---- name for the data window and for the label of sub-windows 
   string short_name="Trend_Signal";
   IndicatorSetString(INDICATOR_SHORTNAME,short_name);
//----   
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---- checking the number of bars to be enough for the calculation
   if(rates_total<StartBars) return(0);

//---- declarations of local variables 
   int limit;
   double Range,AvgRange,smin,smax,SsMax,SsMin,price;
   bool uptrend;

//---- calculations of the necessary amount of data to be copied
//---- and the 'limit' starting index for the bars recalculation loop
   if(prev_calculated>rates_total || prev_calculated<=0)// checking for the first start of the indicator calculation
     {
      K=33-RISK;
      limit=rates_total-StartBars;       // starting index for calculation of all bars
     }
   else
     {
      limit=rates_total-prev_calculated; // starting index for calculation of new bars
     }
  
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(close,true);

//---- restore values of the variables
   uptrend=uptrend_;

//---- main indicator calculation loop
   for(int bar=limit; bar>=0; bar--)
     {
      //---- save values of the variables before running at the current bar
      if(rates_total!=prev_calculated && bar==0)
        {
         uptrend_=uptrend;
        }

      Range=0;
      AvgRange=0;
      for(int iii=bar; iii<=bar+SSP; iii++) AvgRange=AvgRange+MathAbs(high[iii]-low[iii]);  //AvgRange+=AvgRange+MathAbs(high[iii]-low[iii]);
      Range=AvgRange/(SSP+1);
      //----
      SsMax=low[bar];
      SsMin=close[bar];

      for(int kkk=bar; kkk<=bar+SSP-1; kkk++)
        {
         price=high[kkk];
         if(SsMax<price) SsMax=price;
         price=low[kkk];
         if(SsMin>=price) SsMin=price;
        }

      smin=SsMin+(SsMax-SsMin)*K/100;
      smax=SsMax-(SsMax-SsMin)*K/100;

      SellBuffer[bar]=0;
      BuyBuffer[bar]=0;

      if(close[bar]<smin) uptrend=false;
      if(close[bar]>smax) uptrend=true;

      if(uptrend!=old && uptrend==true)
        {
         BuyBuffer[bar]=low[bar]-Range*0.5;
         if(bar==0)  //possible signals at bar 0 gonna be repainted or removed again
           {
            if(counter<NumberofAlerts)//if(counter<=NumberofAlerts)
              {
               //Alert("Trend ",EnumToString(Period())," ",Symbol()," BUY");
               Alert("Trend ",EnumToString(Period())," ",Symbol()," BUY","\n","Current time is ",TimeToString(TimeCurrent(),TIME_SECONDS));
               counter++;
              }
           }
         else counter=0;
        }
      if(uptrend!=old && uptrend==false)
        {
         SellBuffer[bar]=high[bar]+Range*0.5;

         if(bar==0)  //possible signals at bar 0 gonna be repainted
           {
            if(counter<NumberofAlerts)//if(counter<=NumberofAlerts)
              {
               //Alert("Trend ",EnumToString(Period())," ",Symbol()," SELL");
               Alert("Trend ",EnumToString(Period())," ",Symbol()," SELL","\n","Current time is ",TimeToString(TimeCurrent(),TIME_SECONDS));
               counter++;
              }
           }
         else counter=0;
        }

      if(bar>0) old=uptrend;
     }
//---- 
   
   return(rates_total);//return(prev_calculated);
  }
//+------------------------------------------------------------------+
12
To add comments, please log in or register