Help me debug please!

lbranjord

Well-known member
Messages
453
Likes
15
Below is most of the code from an EA I'm working on. I keep getting the OrderSend 130 even though I know my stop loss and entry should be ok! Anyone know what the problem is? I'm thinking some kind of error with the doubles. It's only opening half the time and other half it doesn't get past the 130 error. This operates on daily time frame so should look at open prices only of the '0' candle.

Thanks guys! let me borrow your brain.

int Symbol.magic=90022;
extern double Lots=0.05;
int Slippage=3;
int start()
{
if(Volume[0]>1) return;
CloseAll();
SetNew();
return(0);
}
//+------------------------------------------------------------------+
void SetNew(){
double high=iHigh(NULL,PERIOD_D1, 1);
double low=iLow(NULL,PERIOD_D1,1);

OrderSend
(Symbol(),OP_BUYLIMIT,Lots,high,Slippage,low,0,"Big Ben Making dollars.",Symbol.magic,0,Blue);

OrderSend
(Symbol(),OP_SELLLIMIT,Lots,low,Slippage,high,0,"Big Ben Making dollars.",Symbol.magic,0,Blue);
 
Below is most of the code from an EA I'm working on. I keep getting the OrderSend 130 even though I know my stop loss and entry should be ok! Anyone know what the problem is? I'm thinking some kind of error with the doubles. It's only opening half the time and other half it doesn't get past the 130 error. This operates on daily time frame so should look at open prices only of the '0' candle.

Thanks guys! let me borrow your brain.

int Symbol.magic=90022;
extern double Lots=0.05;
int Slippage=3;
int start()
{
if(Volume[0]>1) return;
CloseAll();
SetNew();
return(0);
}
//+------------------------------------------------------------------+
void SetNew(){
double high=iHigh(NULL,PERIOD_D1, 1);
double low=iLow(NULL,PERIOD_D1,1);

OrderSend
(Symbol(),OP_BUYLIMIT,Lots,high,Slippage,low,0,"Big Ben Making dollars.",Symbol.magic,0,Blue);

OrderSend
(Symbol(),OP_SELLLIMIT,Lots,low,Slippage,high,0,"Big Ben Making dollars.",Symbol.magic,0,Blue);

This will only open both sides if the current price is between the high and low, if the current price is outside then only one leg will be opened and you would get the 130 message for the other.
 
Thanks s&p, I hadn't thought of that yet.

I'm trying to go off the open price only with this line in the start() > if(Volume[0]>1) return;

So it should only look at each bar once when it opens. But in some cases I suppose the bar can gap up and then it would be over the buylimit/selllimit. Or if the Ask/Bid puts it over/under the limit by a couple pips.

Maybe I'll do something like this:
if (Ask<high){ put the BUYLIMIT in this case }
if (Ask>high){ put a OP_BUY in this case to open at whatever current price }
 
Thanks s&p, I hadn't thought of that yet.

I'm trying to go off the open price only with this line in the start() > if(Volume[0]>1) return;

So it should only look at each bar once when it opens. But in some cases I suppose the bar can gap up and then it would be over the buylimit/selllimit. Or if the Ask/Bid puts it over/under the limit by a couple pips.

Maybe I'll do something like this:
if (Ask<high){ put the BUYLIMIT in this case }
if (Ask>high){ put a OP_BUY in this case to open at whatever current price }


You may also need to take into account the minimum distance that your broker allows stops/limits to be placed away from current price
 
You may also need to take into account the minimum distance that your broker allows stops/limits to be placed away from current price

Ok, I found some code online to help me with that part too. On another forum they also told me to get rid of the Volume equation and to use a new-bar function instead. I'm adding all these pieces in one at a time and hopefully can get things smooth.
 
SP, if you're still there. Do you have any idea why my orderclose function is throwing errors? It seems to be closing all the orders at the right time.

//+------------------------------------------------------------------+
// Close All FUNCTION
//+------------------------------------------------------------------+
void CloseAll(){
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol() && OrderMagicNumber()==Symbol.magic) {
if (OrderType()==OP_BUYSTOP) {
OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, Blue);
}
if (OrderType()==OP_SELLSTOP) {
OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, Red);
}
if (OrderType()==OP_BUY) {
OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, Blue);
}
if (OrderType()==OP_SELL) {
OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, Red);
}
}
}
Print("Closed all orders. Current open:" + OrdersTotal());
}
 
Top