Only opens order in one direction

To add comments, please log in or register
Mark
249
Mark  

Okay here's the order execution code from my EA, the problem I'm having is that it only seems to open orders in the direction I put first in the code... So for this code it only opens short positions, however if I swap the Buy and Sell orders around it opens long and not short positions. I just get invalid stop errors opening BUY/SELL order depending on which one is last in the code. If i change the stop loss and take profit to 0 in the last one it places trades but i need to put stops in obviously... Anyone see what I'm doing wrong?


bool ticket;
int cnt;
int TotalBuyOrders=0;
int TotalSellOrders=0;

for(cnt=0;cnt<OrdersTotal();cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_SELL)
{
TotalSellOrders=TotalSellOrders+1;
}
}
if(TotalSellOrders<(MaxOrders/2))
{
if(SellSignal>=5)
{
double ATR=iATR(NULL,0,14,0);
double SL=1*ATR*ATRM;
double TP=5*ATR*ATRM;
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slip,Bid+SL,Bid-TP,NULL,16180,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
for(cnt=0;cnt<OrdersTotal();cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_BUY)
{
TotalBuyOrders=TotalBuyOrders+1;
}
}
if(TotalBuyOrders<(MaxOrders/2))
{
if(BuySignal>=5)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slip,Ask-SL,Ask+TP,NULL,16180,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
}
return(0);
} 
Keith
371
Keith  
mrwobbles wrote >>

Okay here's the order execution code from my EA, the problem I'm having is that it only seems to open orders in the direction I put first in the code... So for this code it only opens short positions, however if I swap the Buy and Sell orders around it opens long and not short positions. I just get invalid stop errors opening BUY/SELL order depending on which one is last in the code. If i change the stop loss and take profit to 0 in the last one it places trades but i need to put stops in obviously... Anyone see what I'm doing wrong?

Try deleting this return(0); I suspect that you never reach the second trade loop:}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
for(cnt=0;cnt<OrdersTotal();cnt++)

HTH

Keith

Alexander
2441
Alexander  
What volume of your SL and TP?
Mark
249
Mark  
kminler:

Try deleting this return(0); I suspect that you never reach the second trade loop:}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
for(cnt=0;cnt<OrdersTotal();cnt++)

HTH

Keith

No I get error opening BUY order :130 from the second loop. It must be something to do with the stops because if I set them to be fixed values say 100*point then it works. However I want my stops to be based on the ATR and that doesnt seem possible at the moment. Having said that it happily puts variable stops on the sell orders, so im not sure whats going on... The SL is calculated as twice the ATR times by my ATR multiplier which ive set at 1 for now. The TP is calculated very similarly just it's 5 times the ATR. Thanks for the suggestion thou Keith

Mark
249
Mark  
Found out why, I'd defined ATR in the sell loop, when I defined another called ATR1 in the buy loop it works fine... by the by could I put both orders in one for loop?
To add comments, please log in or register