Help coding a custom indicator - page 2

 
WHRoeder:
  1. I asked you simple question,
    What is the type of the second argument of SetIndexBuffer?
    what does the manual say. Let me post it and highlight the question and answer in red
    bool SetIndexBuffer( int index, double array[])
    But you couldn't bother to look at the links posted.

  2. No they are not set to zero, they are indicator buffers. Why didn't you look at what the manual says. Again, let me post it and highlight the question and answer in red
    void SetIndexEmptyValue( int index, double value)
    Sets drawing line empty value. Empty values are not drawn or shown in the DataWindow. By default, empty value is EMPTY_VALUE. 
    But you couldn't bother to look at the links posted.
  3. RTFM and the links

WHRoeder: Thanks for your extreme patience with me . I completely missed the links you sent and thought it was just the MQL html highlighting the word . It was nothing to do with not being bothered. I've been trying to absorb MQL for a few days without much sleep and reading and experimenting with code to write what I am trying to achieve. Please bare with my ignorance as I have only been in this forum for 2 days and trying to shift from programming in AFL ( amibroker ) to MT4. MQL seems at first appearance to be much fussier when setting up these plots. 

1.) Ok so after reading it seems that the allowable type must be Double correct ?

If this is the case then why would MQL allow the use of INT arrays if they cannot be plotted ?

2.) So you are saying by not setting  the empty value my array will not be able to be written into ? Again ,please be patient as I have never seen SetIndexEmptyValue in other code samples such as moving average andit seemd to be working fine. So the question is when do we use SetIndexEmptyValue other than filling in the array with default values. In my code every element of array is written to so no need for a default value  ( as I understand) .

Thanks again for you patience.

dasser

 

@dasser: I added some De-bugging to your codes.

 //////////////////// UNCOMMENT THIS SECTION TO ENABLE THE SUMMATION  Array
 //////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////
    for(k=1; k<20; k++){
        for(j=1; j<20; j++){
            Print("k+j="+(k+j));
            Print("up[k+j]="+up[k+j]);
            upma[k]  += up[k+j];
            Print("upma[k]="+upma[k]);
            Print("k="+k,"____","j="+j);
    }   }
 /*  
   int limitupdn = limit  - 20 ;           
             for( k=0; k < limitupdn ; k++)
             {
                        for( j=0; j < 20 ; j++)
                        {
                        upma[k]  += up[k+j];} 
                         }
  
 */

==========General Help============

1>Use print statements to see what you're adding.

2>Use print statement to see what your results are.

3>Use print statements before Conditions.

4>Use print statements inside Conditions.

5>Learn location of the Log file and How to use it.

6>Read the Book, Documents and some Articles.

==========Your Code============

1>You have two Loops the k_loop and j_loop

2>You gonna process k=1, 20_times in the j_loop

3>upma[k]  += up[k+j]; ... why?

4>You could easily count the # of 1s with upma += up[ i ]

5>when k=11 and j=11, k+j=22, the up[] buffer

only goes from 0--->20,

6>when you ask it for a value of empty buffer, it'll return

the large value you're seeing. I believe that value is the 

bar-date time in seconds. 

7>If you want empty value to be zero then use:

SetIndexEmptyValue(3, 0.0);
==========My Suggestions============

You might be a programmer already, i dunno, however your de-bugging of this problem was non-existent. If you don't have experience coding in languages like c for example then i strongly recommend reading the book. I prefer reading something comprehensive but everyone learns differently. From what I noticed, people tryng to write mql4 by trial and error ends up spending weeks on a simple problem like yours. Most people here would rather you spend the weeks finding your own errors and learning from it than being given the answer. I only provided this much support because u showed some good effort. later.

 
ubzen:

@dasser: I added some De-bugging to your codes.

==========General Help============

1>Use print statements to see what you're adding.

2>Use print statement to see what your results are.

3>Use print statements before Conditions.

4>Use print statements inside Conditions.

5>Learn location of the Log file and How to use it.

6>Read the Book, Documents and some Articles.

==========Your Code============

1>You have two Loops the k_loop and j_loop

2>You gonna process k=1, 20_times in the j_loop

3>upma[k]  += up[k+j]; ... why?

4>You could easily count the # of 1s with upma += up[ i ]

5>when k=11 and j=11, k+j=22, the up[] buffer

only goes from 0--->20,

6>when you ask it for a value of empty buffer, it'll return

the large value you're seeing. I believe that value is the 

bar-date time in seconds. 

7>If you want empty value to be zero then use:

==========My Suggestions============

You might be a programmer already, i dunno, however your de-bugging of this problem was non-existent. If you don't have experience coding in languages like c for example then i strongly recommend reading the book. I prefer reading something comprehensive but everyone learns differently. From what I noticed, people tryng to write mql4 by trial and error ends up spending weeks on a simple problem like yours. Most people here would rather you spend the weeks finding your own errors and learning from it than being given the answer. I only provided this much support because u showed some good effort. later.

+++++++++++++++++++++

Thanks ubzen,

Thanks for feedback. I am not looking for answers just information that helps me understand to solve the problem. I managed to get it working by use of Alert() and a thread I found on debugging and looking at a moving_average indicator and it appears that using a seperate function to calculate is helping but I need to go back and see why exactly that solves the issue. I will write more alerts in old code to understand the flow better.

Now I am working on averaging out this buffer array I had trouble with over a period " int Perd" .  I think a great deal of the problem for me  is understanding exactly how MT4 language executes and flows and so use of the Alert/Print has been a good find for me .I thought MT4 would have a more debug sophisticated setup as with other development software , debug windows showing variables , steps , breaks etc .. 

Is there any difference for debugging between ALERT and PRINT  ?

I realise people may think some of these as very basic problems.  I really appreciate your time in helping moving me forward . I normally learn by trying to code something I am interested in and do it in basic parts via reading ,looking for similar examples and understanding through the problems I come across.  I have read parts of the books and manual but to some degree I find some people have a way to explain things that make more sense hence use of the the forum. Sometimes the manual seems very " program speak " and short in it's explanation, using examples which sometimes do not clarify any better . I have tried looking at exisiting code too and each time understand a little more, however, it feels slow progress. 

I have been reading this URL and it has helped :

http://www.forexmt4.com/_MT4_Tutorials/ which seems more digestible at present.

also I found this debug tool which started me off understanding better what goes on .

http://www.forexfactory.com/showthread.php?t=245303


Thanks again for your time . :-)

Ubzen-->

OK I had time to digest your post: 

"3>upma[k]  += up[k+j]; ... why?" --->

Assume a chart with 100 bars .

up[]  // represents the occurance of "up" ( Close > Open) bars. The size of up[] should be as large as Bars ( the total number of bars in chart) .

upma[] // represents a 20 period summation backwards of up[]. It counts how many up bars have occured in the past 20 periods.The upma[] will also be as large as Bars ( the total number of bars in chart) .

So the k loop is used to reference all the bars from 0 to the oldest bar less the 20 periods needed for the summation because we cannot reference 20 bars in the past with less than 20 bars at the oldest time end of the array . We would be referencing an array past its size. So if there were 100 bars in total in chart we must only calculate 80 bars and make the last 20 NULL or 0.0 as they are used for calculating the first 20 summation for bar no up(80-1) = up[79].

The loop uses limitupdn = limit -20 as the highest bar for k . Therefore upma[80] to upma[100] would be initialised to 0.0 as there are less than 20 bars left.

The j loop is used to add the previous 20 bars /periods of up[] and load into the upma[] for storage.

eg)

To calculate upma[3] we need to sum up[3] through to up[22]

To calculate upma[4] we need to sum up[4] through to up[23] .. and so on

so for upma[k] = sum up[k + j]  where j loops 0 to 19

Calculating upma[] =

upma[1] = up[1 + 0] +up[1 + 1] +up[1 + 2] +up[1 + 3] +up[1 + 4] + ... up[k +j] // k= 0 , j loops 0 -19

upma[1] = up[1] + up[2] + up[3] + up[4] + .... up[20]    // k= 1, j loops 0 -19

upma[2] = up[2] + up[3] + up[4] + up[5] + up[6] + .... up[21]       // k= 2, j loops 0 -19 etc etc


   int limitupdn = limit  - 20 ;           
             for( k=0; k < limitupdn ; k++)
             {
                        for( j=0; j < 20 ; j++)
                        {
                        upma[k]  += up[k+j];} 
                         }
              }
   

Does that answer your question ?







 
@dasser:  Is there any difference for debugging between ALERT and PRINT? Alert is a pop-up box. Print outputs to the log-file. When using the strategy tester, alert acts like print.
Reason: