Jump to content

Cannot place orders in any Expert Advisor; Error Code 130 and 131


Recommended Posts

I have been attempting to place a trade, any trade, in my Demo Account, using an Expert Advisor. When the EA issues a Buy or Sell order, I get error code 130 or 131.

Yes, I have the AutoTrading button enabled on the chart, and "Live Trading" is checked. 

Yes, I am trading EURUSD.FX. And yes, I can place a manual trade, either Buy or Sell.

For your information, I am using Linux, with Wine that emulates Windows. I have not experienced any other issues, and as I said, I can issue manual Buy and Sell orders. So I don't think Wine is getting in the way. I think it's something with my Buy and Sell order within the EA. Maybe the wrong lot size, or some other parameter. I have tried changing the lot size, but it makes no difference.

I am posting here the code from my EA, and the code for the function, which gets called from the EA. I am also posting a screen print, showing the actual error code.

I realize that if I get this code to work, I will be submitting Buy or Sell orders extremely rapidly, until I run out of margin. I am on a Demo Account, so I'm not worried about that right now. I'll address that issue when I can actually get some orders submitted.

So, what gives? What am I doing wrong? Thanks.

bool CheckOpenOrders(){ 
        // We need to scan all the open and pending orders to see if there are any.
        // OrdersTotal returns the total number of market and pending orders.
        // What we do is scan all orders and check if they are of the same symbol as the one where the EA is running.
        for( int i = 0 ; i < OrdersTotal() ; i++ ) { 
                // We select the order of index i selecting by position and from the pool of market/pending trades.
                OrderSelect( i, SELECT_BY_POS, MODE_TRADES ); 
                // If the pair of the order is equal to the pair where the EA is running.
                if (OrderSymbol() == Symbol()) return(true); 
        } 
        // If the loop finishes it mean there were no open orders for that pair.
        return(false); 

//+------------------------------------------------------------------+
//|                                                 Alternator01.mq4 |
//|                                                     Len Cheatham |
//|                                             https://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "Len Cheatham"
#property link      "https://www.mql4.com"
#property version   "1.00"
#property strict
#include <C:/Program Files (x86)/IG MetaTrader 4 Terminal/MQL4/Include/Strings/CustomFunctions01.mqh>
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   Alert("Are there open orders for this currency? ",CheckOpenOrders()); 
   Alert("");
   Alert("Symbol = ", Symbol());  
   if (Close[0] > Open[0])
   {
     int orderID = OrderSend(_Symbol,OP_BUY,0.0001,Ask,10,1.001,1.001);
     if(orderID < 0) Alert("Buy Order rejected, Order error: " + GetLastError());
//     if(CheckOpenOrders())
//     {
//       if // Sell the current 
//     }
   }
   else
     {
       if (Close[0] < Open[0])
       {
         int orderID = OrderSend(_Symbol,OP_SELL,0.0001,Bid,10,1.001,1.001);
         if(orderID < 0) Alert("Sell Order rejected, Order error: " + GetLastError());
       }
     }
  }
//+------------------------------------------------------------------+
 

Screenshot from 2022-03-24 09-22-41.png

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • image.png

  • Posts

    • HODL offers a unique approach for crypto investors on BNBChain. Instead of focusing on active trading, you earn rewards simply for holding HODL tokens. Every transaction feeds a pool that gets distributed as BNB tokens to HODLers, essentially rewarding patience. The project goes beyond just transactions, exploring NFTs, Play-to-Earn games, and other ways to generate income for holders. Their innovative contract even automates the reward system, functioning like a built-in sell bot working for you around the clock. If you're a crypto believer who values long-term holding and want to be rewarded for your loyalty, HODL could be a great fit. HODL rose by 80% after its bitget listing.Just remember to do your own research before investing
    • I remember this tournament from last year. Seems they've upped the rewards this time. $5m and multiple modules to compete on. I'll tell my traders friends. This should get their juices up!.
    • The low mcap and daily trading volume makes it attractive to ape in early. The listing on bitget will give it more exposure.
×
×
  • Create New...
us