static array ? - page 2

 
Ok, at least I was almost on the right track but since I didn't know about EMPTY_VALUE and how to use it I was thinking of trying to loop back to detect the change in value since the resistance and the support value stays the same until the previous indicators.

Anyhow, thanks I'll have to read up some more on this, I am getting closer but it's still a little foggy. :)

Seems like it's taking me too long to learn things. I think I need to read more of other peoples codes and try to understand them to get better design ideas.

Thanks for the response.
 
RaptorUK:
There are 2 buffers (arrays) that hold the price values of the Fractals . . . val1 & val2. If you want to find previous fractal values you simply loop, incrementing a shift value, and check the buffer values till you find ones that aren't EMPTY_VALUE ( https://docs.mql4.com/customind/SetIndexEmptyValue )
Ok, just thinking out loud here:

So I can loop back v1[i] and v2[i] with something 1++ code,

I don't understand val1>0 isn't it always greater then 0 except for High[0] ?

And why does val1 only mark the high fractal and not all the High[i] 's AHHH I think I see because the if statement tells it to only do the High[i]'s

So ok let me think some more.

val1 is the fractals, however v1[i] are only the fractal high's ok I think I got this part worked out.

So then I could loop v1[i] 1++ somehow(i'll have to work that part out) to the previous point before the EMPTY_VALUE and this would be the previous High[i] fractal.

Am I getting closer ?
 
Agent86:
Ok, just thinking out loud here:

val1 is the fractals, however v1[i] are only the fractal high's ok I think I got this part worked out.

So then I could loop v1[i] 1++ somehow(i'll have to work that part out) to the previous point before the EMPTY_VALUE and this would be the previous High[i] fractal.

Am I getting closer ?
Correct . . . :-)
 
RaptorUK:
Correct . . . :-)
Whew ! I was worried

Thanks
 
I got something wrong, I can put 0 in for EMPTY_VALUE and it prints 0 continuously so that's not right well maybe that is right but not my desired effect.

Anyhow:

//+------------------------------------------------------------------+
//|                                                  Agent86_5min.mq4 |
//|                                                    Unfinished POS |
//|                                    
//+------------------------------------------------------------------+
#property copyright "Unfinished POS by Agent86"


//---- input parameters
extern double    TakeProfit=20.0;
extern double    Lots=0.1;
extern double    StopLoss=15.0;
extern int MagicNumber=123486;

double v1[];
double v2[];
double val1;
double val2;

//++++ These are adjusted for 5 digit brokers.

int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)

    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   if (Digits == 5 || Digits == 3)
   {    // Adjust for five (5) digit brokers.
      pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
   } 
   else 
    {    
      pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; 
    }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
     
   
    
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
   
    
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  
  
   double   faster = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1), //MODE_MAIN
            slower = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1); //MODE_SIGNAL
            
   int i=Bars;         
   
   while(i>=0)
     {
      val1=iFractals(NULL, 0, MODE_UPPER,i);
      if (val1 > 0) v1[i]=High[i];
      else          v1[i]=v1[i+1];

      val2=iFractals(NULL, 0, MODE_LOWER,i);
      if (val2 > 0) v2[i]=Low[i];
      else          v2[i]=v2[i+1];
      
      i--;
     }
   
    for(val1=High[i]; v1[i] == EMPTY_VALUE ;i++)
      {
      Print (v1[i]);
      } 
  
//----
            
                       
            

           

//---- 

 
                    
        

                
   return(0);
  }    

//+------------------------------------------------------------------+
I thought the for loop would have taken me back just one signal and printed the signal level for me. but I get nothing or 0

After a few days thinking this through and trying many things, and yet I tried to make these changes to the indicator version also by adding a 3rd buffer and attempt to signal with price on charts but that's been a no go too.


Well, wait I take this back the short version EA I do not have the EMPTY_VALUE buffer so that likely is not going to work anyhow, and so the idea was to test the EA so I could see the print functions to see the results, but the indicator version I would have to wait for so I have to post back on that as it turns out.

Anyhow here is the indicator version, but I do not feel confident about this because I'm not exactly sure if I should attempt to loop inside the while statement or create a new loop and recreating val1 = .... again also.

//+------------------------------------------------------------------+
//|                Support and Resistance                            |
//|                Copyright © 2004/5     Barry Stander              |
//|                http://www.4Africa.net/4meta/                     |
//+------------------------------------------------------------------+

#property copyright "Support and Resistance             Barry_Stander_4@yahoo.com"
#property link      "http://www.4Africa.net/4meta/"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 White

//---- buffers
double v1[];
double v2[];
double v3[];
double val1;
double val2;
double val3;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
//----
   IndicatorBuffers(2);

   SetIndexArrow(0, 159);
   SetIndexStyle(0,DRAW_ARROW,STYLE_DOT,1,Red);
   SetIndexBuffer(0, v1);
   SetIndexLabel(0,"Resistance");
   SetIndexEmptyValue(0,0.0);

   SetIndexArrow(1, 159);
   SetIndexStyle(1,DRAW_ARROW,STYLE_DOT,1,Blue);
   SetIndexBuffer(1, v2);
   SetIndexLabel(1,"Support");
   SetIndexEmptyValue(1,0.0);
   
   SetIndexArrow(2, 225);
   SetIndexStyle(2,DRAW_ARROW,STYLE_DOT,1,White);
   SetIndexBuffer(2, v3);
   SetIndexLabel(2,"High A");
   SetIndexEmptyValue(2,0.0); 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   
   
   int i=Bars;
//----
   while(i>=0)
     {
      val1=iFractals(NULL, 0, MODE_UPPER,i);
      if (val1 > 0) v1[i]=High[i];
      else          v1[i]=v1[i+1];

      val2=iFractals(NULL, 0, MODE_LOWER,i);
      if (val2 > 0) v2[i]=Low[i];
      else          v2[i]=v2[i+1];
      
      i--;      
       
      }
      
     
     for(val1=High[i]; v1[i] == 0 ;i++)  // or v1[i] == EMPTY_VALUE
      {
      Print (v1[i]);
      }
       
     
     
     
//----
   return(0);
  }
//+------------------------------------------------------------------+
well I ditched trying to get the 3rd buffer / signal to be created for now and just want to see if I can print the result of the previous signal

EMPTY_VALUE the way I put in the code initializes the indicator, but thats all nothing printing
 

Can you explain how this for loop works ?

for(val1=High[i]; v1[i] == 0 ;i++)

 
RaptorUK:

Can you explain how this for loop works ?

for(val1=High[i]; v1[i] == 0 ;i++)

I guess I was thinking that since the while statement and v1[i] stores the highs and i -- counts down from Bars highest then I would simply count back up again while v1[i] == EMPTY_VALUE

I though this would increment i++ up 1 level to the previous high, well actually I guess it would go past that to the next EMPTY_VALUE

So I need to do this in the opposite way v1[i] = High[i]; i++

Then shouldn't this take me to the previous High, but I'm not sure how to initialise it properly.

I'll keep working on it.
 
I'm changing it to an if( I just want to see anything print at this point so I can at least see what the indicator is doing.

All I get is 0's so there is actually NO values when = Print (v1[i]);
Which is strange because how do I have the indicator even working at this point then ?

Oh well, I'll keep on it.
 
Agent86:
I'm changing it to an if( I just want to see anything print at this point so I can at least see what the indicator is doing.

All I get is 0's so there is actually NO values when = Print (v1[i]);
Which is strange because how do I have the indicator even working at this point then ?

Oh well, I'll keep on it.


Maybe you are just seeing values for v1[0] ? print i at the same time . .

Print ("v1[", i, "]= ", v1[i]);
 
2011.09.17 11:56:15     2011.01.03 09:24  Agent86_5min EURUSD,M5: v1[-1]= 0
hmm interesting
I didn't post all of it but all the lines read the same = 0

I thought I should still see an actual value for v1[0] ?

how can it always be 0 when the indicator must be if(>0) ?

I may be getting into yet another area that I am ignorant about.

I thought I might be able to print so I might try and understand what and why all my attempts are failing; and so that I might increment i++ in some way to get to the next fractal and then somehow figure out how to use this information for something.


I can print High[i] or v1[i] and it's always 0

Printing High[0] or High[1] also 0

Although I understand what you posted and printing of i value which seems to be stuck because of the i-- loop which always takes it to 0, but even so it should still print a value for i, as least I thought.

And I understand why it's printing [-1] because i=Bars. I get this, but =0 ?




Reason: