hi,i would like if some one help me to modify rhis code to be ok on ECN;many thanks
int start()
{
double llots;
double lSL;
if (TakeProfit==0) TakeProfit=StopLoss/2;
if (StopDistance!=TakeProfit)
if (StopDistance!=(TakeProfit/2))
return (-1);
if (TimeFrame!=0)
if ((TimeFrame!=PERIOD_M1) && (TimeFrame!=PERIOD_M5) && (TimeFrame!=PERIOD_M15) && (TimeFrame!=PERIOD_M30) && (TimeFrame!=PERIOD_H1) && (TimeFrame!=PERIOD_H4) && (TimeFrame!=PERIOD_D1) && (TimeFrame!=PERIOD_W1) && (TimeFrame!=PERIOD_MN1))
return (-1);
if(MaxLots==0) llots=LotSize(); else
if(MaxLots==LotSize()) llots=3*LotSize(); else
llots=MaxLots*2;
lSL=StopLoss;
CheckSignal();
if(cur_signal & _BUY !=0)
OpenOrder(OP_BUY, llots, Ask, Slippage, lSL, TakeProfit, WindowExpertName(), MagicNumber, 0, Blue);
if(cur_signal & _SELL !=0)
OpenOrder(OP_SELL, llots, Bid, Slippage, lSL, TakeProfit, WindowExpertName(), MagicNumber, 0, Red);
if(cur_signal & _CLOSEBUY !=0)
{
CloseLongs(MagicNumber);
}
if(cur_signal & _CLOSESELL !=0)
{
CloseShorts(MagicNumber);
}
if(cur_signal & _DELETEBUYSTOP !=0)
DeleteOpenOrder(OP_BUYSTOP);
if(cur_signal & _DELETESELLSTOP !=0)
DeleteOpenOrder(OP_SELLSTOP);
if(cur_signal & _OPENBUYSTOP !=0)
{
DeleteOpenOrder(OP_BUYSTOP);
if(FirstOrderIsLong) BuyStopPrice=EntryPrice; else BuyStopPrice=EntryPrice+StopDistance*point;
Print ("First Order Is Long = " + FirstOrderIsLong);
OpenOrder(OP_BUYSTOP, llots, BuyStopPrice, Slippage, lSL, TakeProfit, WindowExpertName(), MagicNumber, 0, Blue);
}
if(cur_signal & _OPENSELLSTOP !=0)
{
DeleteOpenOrder(OP_SELLSTOP);
Print ("Entry Price = " + NormalizeDouble(EntryPrice,Digits));
if(FirstOrderIsLong) SellStopPrice=EntryPrice-StopDistance*point; else SellStopPrice=EntryPrice;
Print ("First Order Is Long = " + FirstOrderIsLong);
OpenOrder(OP_SELLSTOP, llots, SellStopPrice, Slippage, lSL, TakeProfit, WindowExpertName(), MagicNumber, 0, Red);
}
CheckOpenPositions();
HandleOpenPositions();
return(0);
}
//+------------------------------------------------------------------+
void CheckSignal()
{
cur_signal=_NONE;
if(OpenBuy==0 && OpenSell==0)
{
if(OpenBuyStop>0) cur_signal |= _DELETEBUYSTOP;
if(OpenSellStop>0) cur_signal |= _DELETESELLSTOP;
if(cur_signal==_NONE)
{
// to see if it's possible to made a trade
if(BlockTradingFilter1())
return(0);
MA=iMA(NULL,TimeFrame,Period_MA,0,MODE_SMA,PRICE_CLOSE,0);
if (Bid > MA && Fact_Up == true) // Checking if price above
{
Fact_Dn = true; // Report about price above MA
Fact_Up = false; // Don't report about price below MA
//Alert("Price is above MA(",Period_MA,")."); // Alert
FirstOrderIsLong = true;
}
//--------------------------------------------------------------------
if (Bid < MA && Fact_Dn == true) // Checking if price below
{
Fact_Up = true; // Report about price below MA
Fact_Dn = false; // Don't report about price above MA
//Alert("Price is below MA(",Period_MA,").");// Alert
FirstOrderIsLong = false;
}
if(FirstOrderIsLong) cur_signal |= _BUY; else cur_signal |= _SELL;
EntryPrice=0;
}
}
if(OpenBuy!=0 || OpenSell!=0)
{
if(OpenBuy>OpenSell && OpenSellStop==0)
{
cur_signal |= _OPENSELLSTOP;
}
if(OpenBuy<OpenSell && OpenBuyStop==0)
{
cur_signal |= _OPENBUYSTOP;
}
}
}
//+------------------------------------------------------------------+
//| FILTER BLOCK MODULES
//+------------------------------------------------------------------+
bool BlockTradingFilter1()
{ //Original code Contributed by Wackena
bool BlockTrade=false; //trade by default
if (UseHourTrade)
{
if( !(Hour() >= StartHourTrade && Hour() <= EndHourTrade && Minute()<= 3) )
{
// Comment("Non-Trading Hours!");
BlockTrade=true;
}
}
return (BlockTrade);
}
//+------------------------------------------------------------------+
//| Handle Open Positions |
//| Check if any open positions need to be closed or modified |
//+------------------------------------------------------------------+
int HandleOpenPositions()
{
int cnt;
bool YesClose;
double pt;
for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
{
OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES);
if ( OrderSymbol() != Symbol()) continue;
if ( OrderMagicNumber() != MagicNumber) continue;
if(OrderType() == OP_BUY)
{
}
if(OrderType() == OP_SELL)
{
}
}
return(0);
}
int OpenOrder(int aCmd, double aLots, double aPrice, int aSlipPage, int aStopLoss, int aTakeProfit, string aComment, int aMagic, datetime aExpiration, color aColor)
{
int order_ticket = 0;
int err = 0;
int l_Try = 0;
int l_MaxTry = 10;
double aPrice2=aPrice;// +Ask-Bid;
double maxLots = MarketInfo(Symbol(),MODE_MAXLOT);
double StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL);
switch (aCmd) {
case OP_BUY:
case OP_BUYLIMIT:
case OP_BUYSTOP:
for (l_Try = 0; l_Try < l_MaxTry; l_Try++)
{
aPrice2=aPrice;
if(aCmd==OP_BUY) { RefreshRates(); aPrice=Ask; /*aPrice2=Bid;*/ }
if (aLots<=maxLots)
order_ticket = OrderSend(Symbol(), aCmd, aLots, aPrice, aSlipPage, StopLong(aPrice, aStopLoss), TakeLong(aPrice, aTakeProfit), aComment, aMagic, aExpiration, aColor);
else{
while (aLots>0){
double bLots = 0;
string bLotComment = DoubleToStr( aLots,2);
if (aLots>maxLots)
{
aLots = aLots - maxLots;
bLots = maxLots;
}
else{
bLots = aLots;
aLots = 0;
}
order_ticket = OrderSend(Symbol(), aCmd, bLots, aPrice, aSlipPage, StopLong(aPrice, aStopLoss), TakeLong(aPrice, aTakeProfit), bLotComment, aMagic, aExpiration, aColor);
}
}
if (order_ticket > 0) break;
err = GetLastError();
if (err == 0) break;
if (err == 4 || err == 137 || err == 146 || err == 136) Sleep(5000);
else {
if (aCmd == OP_BUY)
Print ("Buy");
else if (aCmd == OP_BUYSTOP)
Print ("Buy Stop");
else
Print ("Buy Limit");
Print("Buy Error Code= ", err, "Lots = " + DoubleToStr(MathMax(bLots,aLots),2), "SL = " + DoubleToStr(StopLong(aPrice,aStopLoss),Digits), "TP = " + DoubleToStr(TakeLong(aPrice,TakeProfit),Digits), " When Price = " + DoubleToStr(aPrice,Digits), " StopLevel = " + DoubleToStr(StopLevel,2), " Bid = " + DoubleToStr(Bid,Digits), " Ask = " + DoubleToStr(Ask,Digits), " AB = " + DoubleToStr(AccountBalance(),2), " AE = " + DoubleToStr(AccountEquity(),2), " EP = " + DoubleToStr(EntryPrice,Digits));
break;
}
}
break;
case OP_SELL:
case OP_SELLLIMIT:
case OP_SELLSTOP:
for (l_Try = 0; l_Try < l_MaxTry; l_Try++) {
aPrice2=aPrice;
if(aCmd==OP_SELL) { RefreshRates(); aPrice=Bid; aPrice2=Ask; }
if (aLots<=maxLots)
order_ticket = OrderSend(Symbol(), aCmd, aLots, aPrice, aSlipPage, StopShort(aPrice, aStopLoss), TakeShort(aPrice, aTakeProfit), aComment, aMagic, aExpiration, aColor);
else{
double sLots = 0;
string slotComment = DoubleToStr( aLots,2);
if (aLots>maxLots)
{
aLots = aLots - maxLots;
sLots = maxLots;
}
else{
sLots = aLots;
aLots = 0;
}
order_ticket = OrderSend(Symbol(), aCmd, sLots, aPrice, aSlipPage, StopShort(aPrice, aStopLoss), TakeShort(aPrice, aTakeProfit), slotComment, aMagic, aExpiration, aColor);
}
if (order_ticket > 0) break;
err = GetLastError();
if (err == 0) break;
if (err == 4 || err == 137 || err == 146 || err == 136) Sleep(5000);
else {
if (aCmd == OP_SELL)
Print ("Sell");
else if (aCmd == OP_SELLSTOP)
Print ("Sell Stop");
else
Print ("Sell Limit");
Print("Sell Error Code= ", err, "Lots = " + DoubleToStr(MathMax(sLots,aLots),2), "SL = " + DoubleToStr(StopShort(aPrice,aStopLoss),Digits), "TP = " + DoubleToStr(TakeShort(aPrice,TakeProfit),Digits), " When Price = " + DoubleToStr(aPrice,Digits), " StopLevel = " + DoubleToStr(StopLevel,2), " Bid = " + DoubleToStr(Bid,Digits), " Ask = " + DoubleToStr(Ask,Digits), " AB = " + DoubleToStr(AccountBalance(),2), " AE = " + DoubleToStr(AccountEquity(),2), " EP = " + DoubleToStr(EntryPrice,Digits));
break;
}
}
}
CheckStops(order_ticket);
return (order_ticket);
}
double StopLong(double aPrice, int aPips) {
if (aPips == 0) return (0);
else return (NormalizeDouble(aPrice - aPips * point,Digits));
}
double StopShort(double aPrice, int aPips) {
if (aPips == 0) return (0);
else return (NormalizeDouble(aPrice + aPips * point,Digits));
}
double TakeLong(double aPrice, int aPips) {
if (aPips == 0) return (0);
else return (NormalizeDouble(aPrice + aPips * point,Digits));
}
double TakeShort(double aPrice, int aPips) {
if (aPips == 0) return (0);
else return (NormalizeDouble(aPrice - aPips * point,Digits));
}
double CheckOpenPositions(bool InclOpenOrder=true)
{
int cnt, total;
double NumPositions;
NumPositions = 0;
total=OrdersTotal();
OpenBuy=0;
OpenSell=0;
OpenBuyLimit=0;
OpenSellLimit=0;
OpenBuyStop=0;
OpenSellStop=0;
MaxLots=0;
for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
{
OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES);
if ( OrderSymbol() != Symbol()) continue;
if ( OrderMagicNumber() != MagicNumber) continue;
if (OrderComment()==WindowExpertName())
{
if(MaxLots<OrderLots()) MaxLots=OrderLots();
}
else
{
if(MaxLots<StrToDouble(OrderComment())) MaxLots=StrToDouble(OrderComment());
}
//Print ("MaxLots = " + MaxLots + " Comment = " + OrderComment() + " Expert Name = " + WindowExpertName());
if(OrderType() == OP_BUY )
{
OpenBuy=OpenBuy+OrderLots();
if(EntryPrice==0) EntryPrice=OrderOpenPrice();
}
if(OrderType() == OP_SELL )
{
OpenSell=OpenSell+OrderLots();
if(EntryPrice==0) EntryPrice=OrderOpenPrice();
}
if(OrderType() == OP_BUYLIMIT ) OpenBuyLimit=OpenBuyLimit+OrderLots();
if(OrderType() == OP_SELLLIMIT ) OpenSellLimit=OpenSellLimit+OrderLots();
if(OrderType() == OP_BUYSTOP ) {OpenBuyStop=OpenBuyStop+OrderLots(); LastBuyStopPrice=OrderOpenPrice();}
if(OrderType() == OP_SELLSTOP ) {OpenSellStop=OpenSellStop+OrderLots(); LastSellStopPrice=OrderOpenPrice();}
}
NumPositions = OpenBuy-OpenSell;
if(InclOpenOrder) NumPositions += OpenBuyLimit+OpenBuyStop-OpenSellLimit-OpenSellStop;
return (NumPositions);
}
int start()
{
double llots;
double lSL;
if (TakeProfit==0) TakeProfit=StopLoss/2;
if (StopDistance!=TakeProfit)
if (StopDistance!=(TakeProfit/2))
return (-1);
if (TimeFrame!=0)
if ((TimeFrame!=PERIOD_M1) && (TimeFrame!=PERIOD_M5) && (TimeFrame!=PERIOD_M15) && (TimeFrame!=PERIOD_M30) && (TimeFrame!=PERIOD_H1) && (TimeFrame!=PERIOD_H4) && (TimeFrame!=PERIOD_D1) && (TimeFrame!=PERIOD_W1) && (TimeFrame!=PERIOD_MN1))
return (-1);
if(MaxLots==0) llots=LotSize(); else
if(MaxLots==LotSize()) llots=3*LotSize(); else
llots=MaxLots*2;
lSL=StopLoss;
CheckSignal();
if(cur_signal & _BUY !=0)
OpenOrder(OP_BUY, llots, Ask, Slippage, lSL, TakeProfit, WindowExpertName(), MagicNumber, 0, Blue);
if(cur_signal & _SELL !=0)
OpenOrder(OP_SELL, llots, Bid, Slippage, lSL, TakeProfit, WindowExpertName(), MagicNumber, 0, Red);
if(cur_signal & _CLOSEBUY !=0)
{
CloseLongs(MagicNumber);
}
if(cur_signal & _CLOSESELL !=0)
{
CloseShorts(MagicNumber);
}
if(cur_signal & _DELETEBUYSTOP !=0)
DeleteOpenOrder(OP_BUYSTOP);
if(cur_signal & _DELETESELLSTOP !=0)
DeleteOpenOrder(OP_SELLSTOP);
if(cur_signal & _OPENBUYSTOP !=0)
{
DeleteOpenOrder(OP_BUYSTOP);
if(FirstOrderIsLong) BuyStopPrice=EntryPrice; else BuyStopPrice=EntryPrice+StopDistance*point;
Print ("First Order Is Long = " + FirstOrderIsLong);
OpenOrder(OP_BUYSTOP, llots, BuyStopPrice, Slippage, lSL, TakeProfit, WindowExpertName(), MagicNumber, 0, Blue);
}
if(cur_signal & _OPENSELLSTOP !=0)
{
DeleteOpenOrder(OP_SELLSTOP);
Print ("Entry Price = " + NormalizeDouble(EntryPrice,Digits));
if(FirstOrderIsLong) SellStopPrice=EntryPrice-StopDistance*point; else SellStopPrice=EntryPrice;
Print ("First Order Is Long = " + FirstOrderIsLong);
OpenOrder(OP_SELLSTOP, llots, SellStopPrice, Slippage, lSL, TakeProfit, WindowExpertName(), MagicNumber, 0, Red);
}
CheckOpenPositions();
HandleOpenPositions();
return(0);
}
//+------------------------------------------------------------------+
void CheckSignal()
{
cur_signal=_NONE;
if(OpenBuy==0 && OpenSell==0)
{
if(OpenBuyStop>0) cur_signal |= _DELETEBUYSTOP;
if(OpenSellStop>0) cur_signal |= _DELETESELLSTOP;
if(cur_signal==_NONE)
{
// to see if it's possible to made a trade
if(BlockTradingFilter1())
return(0);
MA=iMA(NULL,TimeFrame,Period_MA,0,MODE_SMA,PRICE_CLOSE,0);
if (Bid > MA && Fact_Up == true) // Checking if price above
{
Fact_Dn = true; // Report about price above MA
Fact_Up = false; // Don't report about price below MA
//Alert("Price is above MA(",Period_MA,")."); // Alert
FirstOrderIsLong = true;
}
//--------------------------------------------------------------------
if (Bid < MA && Fact_Dn == true) // Checking if price below
{
Fact_Up = true; // Report about price below MA
Fact_Dn = false; // Don't report about price above MA
//Alert("Price is below MA(",Period_MA,").");// Alert
FirstOrderIsLong = false;
}
if(FirstOrderIsLong) cur_signal |= _BUY; else cur_signal |= _SELL;
EntryPrice=0;
}
}
if(OpenBuy!=0 || OpenSell!=0)
{
if(OpenBuy>OpenSell && OpenSellStop==0)
{
cur_signal |= _OPENSELLSTOP;
}
if(OpenBuy<OpenSell && OpenBuyStop==0)
{
cur_signal |= _OPENBUYSTOP;
}
}
}
//+------------------------------------------------------------------+
//| FILTER BLOCK MODULES
//+------------------------------------------------------------------+
bool BlockTradingFilter1()
{ //Original code Contributed by Wackena
bool BlockTrade=false; //trade by default
if (UseHourTrade)
{
if( !(Hour() >= StartHourTrade && Hour() <= EndHourTrade && Minute()<= 3) )
{
// Comment("Non-Trading Hours!");
BlockTrade=true;
}
}
return (BlockTrade);
}
//+------------------------------------------------------------------+
//| Handle Open Positions |
//| Check if any open positions need to be closed or modified |
//+------------------------------------------------------------------+
int HandleOpenPositions()
{
int cnt;
bool YesClose;
double pt;
for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
{
OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES);
if ( OrderSymbol() != Symbol()) continue;
if ( OrderMagicNumber() != MagicNumber) continue;
if(OrderType() == OP_BUY)
{
}
if(OrderType() == OP_SELL)
{
}
}
return(0);
}
int OpenOrder(int aCmd, double aLots, double aPrice, int aSlipPage, int aStopLoss, int aTakeProfit, string aComment, int aMagic, datetime aExpiration, color aColor)
{
int order_ticket = 0;
int err = 0;
int l_Try = 0;
int l_MaxTry = 10;
double aPrice2=aPrice;// +Ask-Bid;
double maxLots = MarketInfo(Symbol(),MODE_MAXLOT);
double StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL);
switch (aCmd) {
case OP_BUY:
case OP_BUYLIMIT:
case OP_BUYSTOP:
for (l_Try = 0; l_Try < l_MaxTry; l_Try++)
{
aPrice2=aPrice;
if(aCmd==OP_BUY) { RefreshRates(); aPrice=Ask; /*aPrice2=Bid;*/ }
if (aLots<=maxLots)
order_ticket = OrderSend(Symbol(), aCmd, aLots, aPrice, aSlipPage, StopLong(aPrice, aStopLoss), TakeLong(aPrice, aTakeProfit), aComment, aMagic, aExpiration, aColor);
else{
while (aLots>0){
double bLots = 0;
string bLotComment = DoubleToStr( aLots,2);
if (aLots>maxLots)
{
aLots = aLots - maxLots;
bLots = maxLots;
}
else{
bLots = aLots;
aLots = 0;
}
order_ticket = OrderSend(Symbol(), aCmd, bLots, aPrice, aSlipPage, StopLong(aPrice, aStopLoss), TakeLong(aPrice, aTakeProfit), bLotComment, aMagic, aExpiration, aColor);
}
}
if (order_ticket > 0) break;
err = GetLastError();
if (err == 0) break;
if (err == 4 || err == 137 || err == 146 || err == 136) Sleep(5000);
else {
if (aCmd == OP_BUY)
Print ("Buy");
else if (aCmd == OP_BUYSTOP)
Print ("Buy Stop");
else
Print ("Buy Limit");
Print("Buy Error Code= ", err, "Lots = " + DoubleToStr(MathMax(bLots,aLots),2), "SL = " + DoubleToStr(StopLong(aPrice,aStopLoss),Digits), "TP = " + DoubleToStr(TakeLong(aPrice,TakeProfit),Digits), " When Price = " + DoubleToStr(aPrice,Digits), " StopLevel = " + DoubleToStr(StopLevel,2), " Bid = " + DoubleToStr(Bid,Digits), " Ask = " + DoubleToStr(Ask,Digits), " AB = " + DoubleToStr(AccountBalance(),2), " AE = " + DoubleToStr(AccountEquity(),2), " EP = " + DoubleToStr(EntryPrice,Digits));
break;
}
}
break;
case OP_SELL:
case OP_SELLLIMIT:
case OP_SELLSTOP:
for (l_Try = 0; l_Try < l_MaxTry; l_Try++) {
aPrice2=aPrice;
if(aCmd==OP_SELL) { RefreshRates(); aPrice=Bid; aPrice2=Ask; }
if (aLots<=maxLots)
order_ticket = OrderSend(Symbol(), aCmd, aLots, aPrice, aSlipPage, StopShort(aPrice, aStopLoss), TakeShort(aPrice, aTakeProfit), aComment, aMagic, aExpiration, aColor);
else{
double sLots = 0;
string slotComment = DoubleToStr( aLots,2);
if (aLots>maxLots)
{
aLots = aLots - maxLots;
sLots = maxLots;
}
else{
sLots = aLots;
aLots = 0;
}
order_ticket = OrderSend(Symbol(), aCmd, sLots, aPrice, aSlipPage, StopShort(aPrice, aStopLoss), TakeShort(aPrice, aTakeProfit), slotComment, aMagic, aExpiration, aColor);
}
if (order_ticket > 0) break;
err = GetLastError();
if (err == 0) break;
if (err == 4 || err == 137 || err == 146 || err == 136) Sleep(5000);
else {
if (aCmd == OP_SELL)
Print ("Sell");
else if (aCmd == OP_SELLSTOP)
Print ("Sell Stop");
else
Print ("Sell Limit");
Print("Sell Error Code= ", err, "Lots = " + DoubleToStr(MathMax(sLots,aLots),2), "SL = " + DoubleToStr(StopShort(aPrice,aStopLoss),Digits), "TP = " + DoubleToStr(TakeShort(aPrice,TakeProfit),Digits), " When Price = " + DoubleToStr(aPrice,Digits), " StopLevel = " + DoubleToStr(StopLevel,2), " Bid = " + DoubleToStr(Bid,Digits), " Ask = " + DoubleToStr(Ask,Digits), " AB = " + DoubleToStr(AccountBalance(),2), " AE = " + DoubleToStr(AccountEquity(),2), " EP = " + DoubleToStr(EntryPrice,Digits));
break;
}
}
}
CheckStops(order_ticket);
return (order_ticket);
}
double StopLong(double aPrice, int aPips) {
if (aPips == 0) return (0);
else return (NormalizeDouble(aPrice - aPips * point,Digits));
}
double StopShort(double aPrice, int aPips) {
if (aPips == 0) return (0);
else return (NormalizeDouble(aPrice + aPips * point,Digits));
}
double TakeLong(double aPrice, int aPips) {
if (aPips == 0) return (0);
else return (NormalizeDouble(aPrice + aPips * point,Digits));
}
double TakeShort(double aPrice, int aPips) {
if (aPips == 0) return (0);
else return (NormalizeDouble(aPrice - aPips * point,Digits));
}
double CheckOpenPositions(bool InclOpenOrder=true)
{
int cnt, total;
double NumPositions;
NumPositions = 0;
total=OrdersTotal();
OpenBuy=0;
OpenSell=0;
OpenBuyLimit=0;
OpenSellLimit=0;
OpenBuyStop=0;
OpenSellStop=0;
MaxLots=0;
for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
{
OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES);
if ( OrderSymbol() != Symbol()) continue;
if ( OrderMagicNumber() != MagicNumber) continue;
if (OrderComment()==WindowExpertName())
{
if(MaxLots<OrderLots()) MaxLots=OrderLots();
}
else
{
if(MaxLots<StrToDouble(OrderComment())) MaxLots=StrToDouble(OrderComment());
}
//Print ("MaxLots = " + MaxLots + " Comment = " + OrderComment() + " Expert Name = " + WindowExpertName());
if(OrderType() == OP_BUY )
{
OpenBuy=OpenBuy+OrderLots();
if(EntryPrice==0) EntryPrice=OrderOpenPrice();
}
if(OrderType() == OP_SELL )
{
OpenSell=OpenSell+OrderLots();
if(EntryPrice==0) EntryPrice=OrderOpenPrice();
}
if(OrderType() == OP_BUYLIMIT ) OpenBuyLimit=OpenBuyLimit+OrderLots();
if(OrderType() == OP_SELLLIMIT ) OpenSellLimit=OpenSellLimit+OrderLots();
if(OrderType() == OP_BUYSTOP ) {OpenBuyStop=OpenBuyStop+OrderLots(); LastBuyStopPrice=OrderOpenPrice();}
if(OrderType() == OP_SELLSTOP ) {OpenSellStop=OpenSellStop+OrderLots(); LastSellStopPrice=OrderOpenPrice();}
}
NumPositions = OpenBuy-OpenSell;
if(InclOpenOrder) NumPositions += OpenBuyLimit+OpenBuyStop-OpenSellLimit-OpenSellStop;
return (NumPositions);
}