[Solved] Can i compare candles using PRICE_OPEN and PRICE_CLOSE?

 

I'm preparing a strategy, that's based on candle comparisons. I need that a if and else structure, returns me the graph movement.

I tried this:

if(Open[Bars] > Close[Bars-1]){
Print("Topo");
return(subindo);
}else{
if(Close[Bars-2] > Open[Bars-1]){
Print("Base");
return(descendo);
}
}

But a friend who's working with me, told me that the correct way to do this, is using PRICE_OPEN and PRICE_CLOSE instead of Open and Close.

it's possible?

'cause PRICE_OPEN and PRICE_CLOSE are constants... i'm tottaly lost(i've started programing in mql4 this week). Can someone help me?

 

Bars is a reserved constant so advise not to use it with Open[ n ]

iHighest(...) ; could be what you are looking for - returns the bar/candle with the value you are looking for.

int iHighest( string symbol, int timeframe, int type, int count=WHOLE_ARRAY, int start=0)
Returns the shift of the maximum value over a specific number of periods depending on type.
Parameters:
symbol - Symbol the data of which should be used to calculate indicator. NULL means the current symbol.
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.
type - Series array identifier. It can be any of the Series array identifier enumeration values.
count - Number of periods (in direction from the start bar to the back one) on which the calculation is carried out.
start - Shift showing the bar, relative to the current bar, that the data should be taken from.

 

if(Open[Bars] > Close[Bars-1]){

This is wrong. The price arrays are ordered in such a way that the current (still unfinished) candle is 0, the previous candle is 1 and so on.


Close[0] would be the current price, the price where the current candle would close should no ticks for this candle arrive anymore.

Open[0] is where the current candle has opened


High[0] is the maximum so far for the current candle

Low[0] is the minimum so far for the current candle


Close[1] is the close of the previous candle

etc...


You probably want to do something like:

if (Open[0] > Close[1])

or something like that.

Or maybe I misunderstood you and you are trying to loop through all history and use Bars as the Bar number or loop variable. This is not allowed. Bars is one of the few reserved words that you cannot use as variable name, Bars exists already and always contains the maximum number of bars in the chart. Open[Bars] would then be the open of the very first bar (oldest bar) in the chart, while Open[0] is always the open of the currently running bar.

 
The constants you mentioned in the first post are for a completely different thing, your friend either confused something or did not understand your problem correctly or he meant something completely different. These constants are meant to be used to tell an indicator (for example a moving average) whether it should be calculated on the highs or on the lows or on the closes or on the typicals etc.
 

Ickyrus

I tried to ise iHighest, iHigh... etc...but this functions didn't fit my purpose, as 7bit said, Open[0] and Close[1] was the solution for my problem, thanks!

7Bit:

Thanks! it was the solution!

Thank you a lot, guys!