highest price since order entry?

 

Hi, i'm new to writing expert advisors.

I was wondering how i can get (or keep track of) the highest price since a buy order has been entered (if I have multiple orders that is, so keeping track with a single global variable doesn't work)


Thanks!

 
drunktrader wrote >>

Hi, i'm new to writing expert advisors.

I was wondering how i can get (or keep track of) the highest price since a buy order has been entered (if I have multiple orders that is, so keeping track with a single global variable doesn't work)

Thanks!

Hi,

You can use the following :

int HIGHEST= iHigh(OrderSymbol(),PERIOD,iHighest(OrderSymbol(),PERIOD,MODE_HIGH,iBarShift(OrderSymbol(),PERIOD,OrderOpenTime(),false),0));

to get the highest price riched from the opening of an order.

Then make a loop to calculate that figure for each order you have and keep in memory only the highest :

if (memHighest < HIGHEST) memHighest=HIGHEST

for example

 
Jacques366:

You can use the following :

int HIGHEST= iHigh(OrderSymbol(),PERIOD,iHighest(OrderSymbol(),PERIOD,MODE_HIGH,iBarShift(OrderSymbol(),PERIOD,OrderOpenTime(),false),0));

I think there may be some problems with this. The main one is that if iBarShift returns 0, because the order-open was during the most recent bar, then iHighest effectively gets called with count = WHOLE_ARRAY, and returns the all-time high for the symbol. Under all other circumstances, it's not going to count the high of the bar during which the trade was opened.


Personally, I'd use something like the following - exactly the same principle, but explicitly using M1 bars rather than the current chart timeframe. If the order was opened e.g. 20 seconds into a bar, then the code will potentially return a high which formed in those 20 seconds before entering the trade:


   OrderSelect(etc);

   

   // Get the number of M1 bars since open. Zero means that the order was opened

   // during the current bar

   int M1BarShiftOfTradeOpen = iBarShift(OrderSymbol(), PERIOD_M1, OrderOpenTime(), false);

   // Get the index of the highest high during the last n bars

   int IndexOfHigh = iHighest(OrderSymbol(), PERIOD_M1, MODE_HIGH, M1BarShiftOfTradeOpen + 1, 0);

   // Get the high price from the bar with the given M1 index

   double HighestVal = iHigh(OrderSymbol(), PERIOD_M1, IndexOfHigh);


The only other thing to bear in mind is that this sort of method always gives you the highest bid price. If you need the ask, then you can semi-reconstruct it by adding the current spread. If you need the true highest ask then there's no obvious alternative to constant monitoring of Ask in each call to start()

Reason: