Array question about High[],Low[],Close[],Open[] etc.

 

Hi coders,

I am now learning about building arrays and using some of the built in functions for some of these

So here is what I would like to find out. (Is High[] closed candle or current open candle)?

I guess I'm asking this in anticipation of creating codes that might trade based on a series of candle formations such as if(Close[0] >Open[0]){//Or something like this}

or maybe bool bull = (Close[0]>Open[0]) or maybe if (Close[0]>Open[0]) bull = 1 well not exactly but something to this nature.

But all this would depend on whether or not High[0] is really High[0] of the previous closed candle or the new currently opened candle ?


Basically want to practice writing code for EA's and indicators that mark or trade some basic candle formations such as Engulfing candles, tweezer tops, morning stars and/or just labelling the candle bull or bear like in the charts green up, red down etc.

Just for the learning experience and to use in future code projects


So anyhow, is the High[0] the last closed or the current opened candle too ?


Please advise
Thanks a lot

 
Agent86:

So anyhow, is the High[0] the last closed or the current opened candle too ?


That's an easy one, bar 0 is the currently forming bar . . . so High[0] is the high ( so far ) of the currently forming candle.

Some additional info . . the currently forming bar has never fully closed until it's become bar 1, so Close[0] gives the current Bid price . . .

 
Ahhh, nice info thanks
 
RaptorUK:

That's an easy one, bar 0 is the currently forming bar . . . so High[0] is the high ( so far ) of the currently forming candle.

Some additional info . . the currently forming bar has never fully closed until it's become bar 1, so Close[0] gives the current Bid price . . .

I'm trying to understand arrays better

How would I trading if(High[0] > High[1]), with only 1 trade when this condition is met for Bar[0]

Basically once the trade is open let it run till sl or tp and never trading the signal again during this particular Bar
 
Agent86:
I'm trying to understand arrays better

How would I trading if(High[0] > High[1]), with only 1 trade when this condition is met for Bar[0]

Basically once the trade is open let it run till sl or tp and never trading the signal again during this particular Bar

OK, you need to start thinking about stuff like this . . . a question to get you thinking in the right direction . . .

Q. What changes when a new bar starts ? it's not the bar number because the bar forming is always bar number 0 . . so what does change that you can use to tell you when a new bar has started ?

 
WOW, huh ? a lot of things, Time, Open,Close,Price and *number of bars etc.

I'll have to consider this some more. It's not particularly useful on it's own but I know I will need to know things like this to use in much larger arrays and functions.


I was considering something in the lines of MODE_HISTORY and using the OrderCloseTime and Time[] but I haven't got it worked out cause that won't get the initial trade to occur if I just block everything from trading LOL


I'll think about this some more thanks

 
RaptorUK:

OK, you need to start thinking about stuff like this . . . a question to get you thinking in the right direction . . .

Q. What changes when a new bar starts ? it's not the bar number because the bar forming is always bar number 0 . . so what does change that you can use to tell you when a new bar has started ?


That´s a question I spent a lot of time about, too. One of my ideas was to pass the current number of bars when the trade is executed to a variable and to skip the trade function till the numbers of bars is bigger than that one stored in the variable. But you told that there is a maximum of bars and when that it is reached, this way would not work longer.

So I pass the opentime via Time[0] to the variable and skip the trade function till it changed (when a new bar has started to form). What about this way?

Another attempt is to use OrdersTotal() and skip the trade function like if(OrdersTotal() != 0)...

I am curious about to learn the most efficient way to solve this situation because it appears frequently.

 
APeng:

That´s a question I spent a lot of time about, too. One of my ideas was to pass the current number of bars when the trade is executed to a variable and to skip the trade function till the numbers of bars is bigger than that one stored in the variable. But you told that there is a maximum of bars and when that it is reached, this way would not work longer.

So I pass the opentime via Time[0] to the variable and skip the trade function till it changed (when a new bar has started to form). What about this way?


:-) Time is your friend . . .
 
Agent86:
  1. How would I trading if(High[0] > High[1]), with only 1 trade when this condition is met for Bar[0]
  2. Basically once the trade is open let it run till sl or tp and never trading the signal again during this particular Bar

You have three criteria:

  1. If you opened this bar - don't open.
  2. If there's a trade already open - don't open this bar. If the previous trade closed this bar - don't open
  3. If it's time to trade - open.

So you need

  1. int start(){
       static datetime Time0Last;
       if (Time0Last == Time[0]) return;
  2.     for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
            OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
        &&  OrderMagicNumber()  == magic.number             // my magic number
        &&  OrderSymbol()       == Symbol()                 // and my pair.
        ){
           Time0Last = Time[0]; return; // Prevent another this bar.
        }
  3.     if (High[0] > High[1]){
            int ticket = OrderSend(...)
            if (ticket < 0) Alert("OrderSend Failed: ", GetLastError());
            else            Time0Last = Time[0]; // Prevent another this bar.
        }
Another attempt is to use OrdersTotal() and skip the trade function like if(OrdersTotal() != 0)...
You do NOT want to use that in isolation. Other EA's (or your EA) on other charts and their order should be ignored. See #2
 
I almost understand.
But still confused. It looks like Time0Last == Time[0] all the time ?

I need to think this through a bit, but it seems that if Time0Last == Time[0] then I get to the if(trade statements)
And the loop resets the Time0Last = Time[0] again which will also allow the if(trade statements) again while on the same bar ?

I'm not sure I see how this prevents it from trading during Bar[0] after the initial trade ?
Let me consider (thinking out loud and in text) that Time[0] is the Current Opening Time of the Current Bar
If this were a 4 hour chart then Time0Last = Time[0] for about 4 hours. And while High[0] > High[1] might occur several times during Time0Last == Time[0]

Perhaps I don't understand this, but I'm trying to think it through and this is what it looks like to me.

Please clarify.

Thanks



 
Oh wait a min.

The return keeps it from getting to the if(trading statements)

I think I see now, it keeps returning while Trade0Last == Time[0] keeping it from getting to the if(trading statements)

At least I think so ? LOL my head hurts, I'll pick this up again tomorrow.

Thanks all for the help.

Reason: