static array ?

 

Hi all,

First thanks to everyone for all the answers this has been great learning MQL4

I'm moving on to understand how to build array's

Subject:

How to store signals into a static array for example: Highs, and Lows of a series of candles etc, I will likely put a small line on top of each high and low.

So I'm thinking static array[1,2,3,4,5,6,7]

array[1] = (Low[3] < Low[4] && Low[3] < Low[3]) //or something like this ?

Low_1 = array[1]

Low_2 = array[2] and so on.

Would this be a standard way to do this or am I way off ?

Please advise thanks

 

Read first . . . then read it again till you grasp it.

https://book.mql4.com/variables/arrays

For example, first element of an array is element 0, bit like Bars, fumy that, eh ? ;-)

 
  1. You're way off.
  2. array[1,2,3,4,5,6,7] giberish
  3. array[1] = (Low[3] < Low[4] && Low[3]... is array a bool
  4. Low_1 = array[1] implies that array is not a bool
  5. "store signals into a static array" why does it need to be static when you can compute them whenever needed.
 

oops I meant int array[1][7];

Thanks for the response

Well after some more reading, your direction and questions, I guess an array may not be what I'm trying to do.

Basically I want to learn to create my own defined version of highs and lows; and be able to reference them for a signal even after new bars form. But only a number of them that I choose not the whole complete history of highs/lows.
I may be on the wrong track here.

I'll rethink this some more.

Thank you

 
Agent86:


Basically I want to learn to create my own defined version of highs and lows; and be able to reference them for a signal even after new bars form. But only a number of them that I choose not the whole complete history of highs/lows.

Why ? Can you explain what you are trying to achieve ?
 

I think I'll do something more like this:

I guess that makes this post is no longer about arrays at this point so I'll retract this questioning until I can learn more about arrays


Thanks.

static double Low_A;
   
   if(Low[2] < Low[2]
      && Low [2] < Low[1])
      {
      Low_A = Low[3];
      Print (Low_A + " Low_A has formed");
      }
 
RaptorUK:
Why ? Can you explain what you are trying to achieve ?

Well sure, it's not actually highs and lows of a particular candle but perhaps a series of candles.

Lets say one example could be to call a Low_A depending on how many candles I wish to use but it could be to say that a low is considered 4 higher candles to the left and 4 higher candles to the right, and this low candle would be considered to be a Low_A

Or it could me more candles, or less to make up a Low or High, and then create others like this for Highs, and Lows.
Then to create some functions to compare the previous Lows to the next Lows, and the previous Highs to the next Highs.

Then to perhaps draw a trendline from a series of either 2) highs/lows or 3/highs/lows or mabe even more

Or I could just use as in this example 1 candle that has 1 lower candle to the left and 1 lower candle to the right and call this a low.

Initially I was considering putting the result into an array, but I don't think this will do what I was wanting, or at least I don't understand arrays well enough to determine that at this point. Some more reading no doubt will straighten me out. HA !

I really wasn't sure if arrays would be useful for this to store a series of highs and lows which I define.
 

If I Print Low[2] it gives me 8 digits instead of 5 digits, and some are all 0.0000000

Probably because the data type I used was static double Low_A;

I'm not sure if I need to make it print correctly, however for the purpose of storing the correct static, I'm not sure what data to use.

 
OK, I'm ditching the static array, and the static double idea

I need a new design it's obvious that what I was trying to do will not work properly and I now understand why.

Sooooo, back to the drawing board again. OUCH
 

Back to this,

After some more learning I was wondering is there even such a thing as a static array, or is an array static mainly by default, and after reading the links you provided I say all are static by default. Great.


Anyhow, I'm thinking iFractals instead of trying to mark Highs and Lows as I define them. I can use Fractals for now until I get better knowledge and more reading.

So what about iFractals, how can I mark them and refer to them ?
Would I just create additional iFractals and change the shift and refer to it that way, or will the shift with iFractals still be talking about Bars and not the previous Fractal ?

//+------------------------------------------------------------------+
//|                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

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

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

   SetIndexArrow(1, 119);
   SetIndexStyle(1,DRAW_ARROW,STYLE_DOT,1,Blue);
   SetIndexBuffer(1, v2);
   SetIndexLabel(1,"Support");
//----
   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--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+


Someone wrote this code and I understand how it works, but I'm not sure I understand how I would select from the array a particular High and/or Low aka Support/Resistance.

I mean I can surely make a function that would Open a trade if(val1 > imacd) or something, but what about the previous iFractals, or lets say 2 back,

Would this simply be a matter of shift ?

Or do I need to put this into another array of some sort ?

Please advise

Thanks

 
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 )
Reason: