stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Last OpenPrice of Buy and Sell Orders
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=3634
Page 1 of 1
Author:  deejoy [ Mon May 19, 2014 8:20 pm ]
Post subject:  Last OpenPrice of Buy and Sell Orders

Hi,

i need the last OpenPrice of a Sell Order and of a Buy Order. I try it with this function but i get only the Price of the last open Order.

Code: Select all

double fk_getLastOpenOrderPrice(double d_OrderOpenPrice)
{

double dOpenBuyPrice  ;
double dOpenSellPrice ;
int iAnzOrders = OrdersTotal();

if(OrderSelect(iAnzOrders,SELECT_BY_TICKET)==true){
       
if ((OrderType() == OP_BUY) && (OrderSymbol() == sSymbol))
       {
       
       dOpenBuyPrice = OrderOpenPrice();
       }
       
if ((OrderType() == OP_SELL) && (OrderSymbol() == sSymbol))
       {
       
       dOpenSellPrice = OrderOpenPrice();
       }
  }    
       
if (d_OrderOpenPrice ==1) return(dOpenBuyPrice);
if (d_OrderOpenPrice ==2) return(dOpenSellPrice);
 return(0);

How get i both Openprice ?
Author:  milanese [ Mon May 19, 2014 8:40 pm ]
Post subject:  Last OpenPrice of Buy and Sell Orders

this two functions should do what you want..

Code: Select all

double LastOpenBuyTradePrice(string strSymbol, int nMagic)
{
	double priceLastOpenOrder=0;
	datetime opendate=0;
	for (int i=OrdersTotal()-1 ; i>=0 ; i--)
	{
		if (!OrderSelect(i,SELECT_BY_POS)) continue;
		if (OrderType() != OP_BUY) continue;
		if (OrderMagicNumber() == nMagic)
		if (OrderSymbol() == strSymbol)
		if (OrderOpenTime()>=opendate)
		{
			priceLastOpenOrder=OrderOpenPrice();
			opendate=OrderOpenTime();
		}
	}
	return(priceLastOpenOrder);
}
double LastOpenSellTradePrice(string strSymbol, int nMagic)
{
	double priceLastOpenOrder=0;
	datetime opendate=0;
	for (int i=OrdersTotal()-1 ; i>=0 ; i--)
	{
		if (!OrderSelect(i,SELECT_BY_POS)) continue;
		if (OrderType() != OP_SELL) continue;
		if (OrderMagicNumber() == nMagic)
		if (OrderSymbol() == strSymbol)
		if (OrderOpenTime()>=opendate)
		{
			priceLastOpenOrder=OrderOpenPrice();
			opendate=OrderOpenTime();
		}
	}
	return(priceLastOpenOrder);
}
Cheers :)

Tommaso
Author:  deejoy [ Mon May 19, 2014 8:53 pm ]
Post subject:  Last OpenPrice of Buy and Sell Orders

thx
works perfect :yahoo:
All times are UTC Page 1 of 1