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].
victor: my problem is that the first candle is that the position is opened remains the highest bar, and the highest bar price,
Why does that surprise you?
William Roeder #:
ok, but this is the problem, if position was opened 5 bars ago from index[0] to index[5](index 5 being the open position bar), if index [3] had the lowest price low, ilowest still return index [5] as the lowest bar
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?
thanks I was able to solve it by removing the ibarshift function completely and using (0)
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?
victor #: , if position was opened 5 bars ago from index[0] to index[5](index 5 being the open position bar), if index [3] had the lowest price low, ilowest still return index [5] as the lowest bar
Your lowest function is not looking at bar 3; only the open bar to the past.
victor #: though I don't really know why this worked, any idea?
Now you are looking from the open bar to current.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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