Last OpenPrice of Buy and Sell Orders

Post Reply
deejoy
Posts: 6
Joined: Sun Mar 09, 2014 12:09 pm

Last OpenPrice of Buy and Sell Orders

Post by deejoy »

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 ?
User avatar
milanese
TechAdmin
Posts: 3293
Joined: Wed Jan 09, 2013 9:02 am
Location: btr rdx, r8 +

Last OpenPrice of Buy and Sell Orders

Post by milanese »

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
Global Prime is the official SHF broker :yahoo:
Searching for Servers and Workstations with individual configuration?
Just PM
:smile: Click here to go to the BoardKnowledgeBase
NOTE: Cookies and JavaScript are required for the using the board, with full functionality
deejoy
Posts: 6
Joined: Sun Mar 09, 2014 12:09 pm

Last OpenPrice of Buy and Sell Orders

Post by deejoy »

thx
works perfect :yahoo:
Post Reply

Return to “Coders Hangout”