Jump to content

coderlen

Members
  • Posts

    1
  • Joined

  • Last visited

Posts posted by coderlen

  1. 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

×
×
  • Create New...
us