getting the highest bar
int bar_index = iBarShift(_Symbol,PERIOD_CURRENT,open_price_time,false); int bar_count = Bars(_Symbol,PERIOD_CURRENT,open_price_time,TimeCurrent()); int lowestbar = iLowest(_Symbol,PERIOD_CURRENT,MODE_LOW,bar_count,bar_index);
Suppose the position was opened ten (10) bars ago.
bar_index equals 10 as does bar_count. iLowest is looking at bars [10 … 19].
Why does that surprise you?
Suppose the position was opened ten (10) bars ago.
bar_index equals 10 as does bar_count. iLowest is looking at bars [10 … 19].
Why does that surprise you?
int open_price_time = (int)PositionGetInteger(POSITION_TIME); int bar_count = Bars(_Symbol,PERIOD_CURRENT,open_price_time,TimeCurrent()); int lowestbar = iLowest(_Symbol,PERIOD_CURRENT,MODE_LOW,bar_count,0); int highestbar = iHighest(_Symbol,PERIOD_CURRENT,MODE_HIGH,bar_count,0); // to get price of the lowest and highest bars double lowestbar_price = iLow(_Symbol,PERIOD_CURRENT,lowestbar); double highestbar_price = iHigh(_Symbol,PERIOD_CURRENT,highestbar);
used zero for the index number of the open position index, and removing ibarshift function completely
though I don't really know why this worked, any idea?
Your lowest function is not looking at bar 3; only the open bar to the past.
Now you are looking from the open bar to current.
Am new to mql5 but so far i have been enjoy the ride, while try to get the highest price bar from the bar index of an open position,
my problem is that the first candle is that the position is opened remains the highest bar, and the highest bar price, even if new bars move higher than its value, same is applied for the lowest bar. how do i solve this, that is, for it to scan through that current bar with index[0] to where the position was opened and return the index or the highest bar price.
thanks