Error 130

 
This is my own version of the My_First_EA which is described in forex-tsd lessons (I think 13 and 14). I put it into live test on E/U 5-min chart and got this error.

Error opening BUY order : 130

There are 3 things here:

1. why the error?

2. the short MA was crossing below the long MA, so why buy? I should be sell.

3. I've got this error 3 times within the duration of the same candle. Does it mean that the EA does not wait till the close of a candle? If yes, how to prevent that?

Your support is highly appreciated.

tapo
Files:
 
You need to print more debugging info . . . add more variables into your error print statement . . . for example, had you adjusted your TakeProfit extern variable ?
 
RaptorUK:
You need to print more debugging info . . . add more variables into your error print statement . . . for example, had you adjusted your TakeProfit extern variable ?

I'm not sure I've got you. Do you mean you want me to print all the input variables along with the error? I've not adjusted TP. In fact I only want to see how the entries are made.
 
tapo:

I'm not sure I've got you. Do you mean you want me to print all the input variables along with the error? I've not adjusted TP. In fact I only want to see how the entries are made.

To find what is causing your issue you need as much information as possible, for example what was the Spread when this error occurred ? if you print Bid & Ask at the time when the error occurs you would have been able to answer the question . . .

Is your Broker an ECN Broker ?

 
tapo:
Error opening BUY order : 130

2. the short MA was crossing below the long MA, so why buy? I should be sell.

3. I've got this error 3 times within the duration of the same candle. Does it mean that the EA does not wait till the close of a candle? If yes, how to prevent that?
  1. Not adjusting for 4/5 digit broker, not adjusted for ECN brokers.
    //++++ These are adjusted for 5 digit brokers.
    int     pips2points;    // slippage  3 pips    3=points    30=points
    double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){
         if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    //---- These are adjusted for 5 digit brokers.
        /* On ECN brokers you must open first and THEN set stops
        int ticket = OrderSend(...)
        if (ticket < 0)
           Alert("OrderSend failed: ", GetLastError());
        else if (!OrderSelect(ticket, SELECT_BY_TICKET))
           Alert("OrderSelect failed: ", GetLastError());
        else if (!OrderModify(OrderTicket()...)
           Alert("OrderModify failed: ", GetLastError());
         */
    

  2. Add print statement to your code to find out why.
  3. Add code to prevent that
    int start(){
       static datetime Time0; if (Time0 == Time[0]); return; Time0 = Time[0];

  4.    total = OrdersTotal();
       if (total < 1)
    This make the EA incompatable with every other including itself on other charts.
       total = 0;
        for(iPos = OrdersTotal()-1; iPos >= 0 ; iPos--) if (
            OrderSelect(iPos, SELECT_BY_POS)                // Only my orders w/
        &&  OrderMagicNumber()  == magic.number             // my magic number
        &&  OrderSymbol()       == Symbol()                 // and my pair.
        ){ total++; }
       if (total < 1)

  5. You must count down when closing.
 
tapo:
This is my own version of the My_First_EA which is described in forex-tsd lessons (I think 13 and 14). I put it into live test on E/U 5-min chart and got this error.

Error opening BUY order : 130

There are 3 things here:

1. why the error?

2. the short MA was crossing below the long MA, so why buy? I should be sell.

3. I've got this error 3 times within the duration of the same candle. Does it mean that the EA does not wait till the close of a candle? If yes, how to prevent that?

Your support is highly appreciated.

tapo
Before going live, you should at least backtest on visual mode, to see if its operational to execute trades by itself and that MA signals are indeed correct. imho.
 

Hi all,

My broker is ECN, even though I don't know what ECN stands for. But anyway, I only have demo accounts for MT4, no real yet. At the moment, I am just learning how to right my own program.

WHRoeder, Thank you very much for the detailed code, and I am not able to understand all of it now, and have to get back to it later on. For the time being, I open a 4-digit demo account. And my question is, is your code necessary for trading or it's just for printing? If for trading, then is it necessary for entries or only for SL and TP?

And thank you all for the useful comments.

tapo

 
tapo:

Hi all,

My broker is ECN, even though I don't know what ECN stands for.

With an ECN Broker you MUST send the order with TP & SL set to 0 then do an OrderModify to add the SL & TP . . .

Plenty of info here: http://crum.be/ecn

 
RaptorUK:

With an ECN Broker you MUST send the order with TP & SL set to 0 then do an OrderModify to add the SL & TP . . .

Plenty of info here: http://crum.be/ecn


Thank you Raptor,

http://i39.tinypic.com/24b5ifa.png

Now the issue with the EA is that is opens only long positions and it does not wait for a candle to close. After I set TP and SL to 0, it opened a trade with no crossover. Just for the short MA was above the long MA. I want it to 1) open short position 2) open position only upon crossovers only. 3) wait for a candle to close (in my case at the end/beginning of a 5-min candle, and not any time else within it)

Could you help in this.

Thanks,

tapo

 

I have done some research and written this code to make the EA wait for the close of a bar.

bool isNewBar()
{
   static datetime NewTime = 0;
   bool NewBar = false;
   if (NewTime != Time[0])
   {
      NewTime = Time[0];
      NewBar = true;
   }
   return (NewBar);
}

Can you assist me in figuring out why it does not trigger sell orders?

 
If you start off with a Buy order because Crossed returns a 1 then a Sell can't be placed because you only allow 1 order to be open at a time . . . when Crossed does change to 2 an order is open, this order will be trailed or closed, the next output from Crossed will be 0 . . when the short and long EMAs change next the output from Crossed will be 1 and a Buy can be placed . . . you can never get a situation when there is no order open and Crossed returns a 2 . . . as far as I can see.
Reason: