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.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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?