error 10013

 

Hi

I wrote a EA But buy order don't execute and i get this error. pl help !

Error:
2014.05.12 11 36.000 2014.04.04 05:01:06 Function: BuyOrder3 Error: 10013 Invalid request

2014.05.12 11 36.000 2014.04.04 05:01:07 failed exchange buy 0.20 EURUSD at 1.37150 sl: 1.36950 tp: 1.37450 [Invalid request]

Thank You

//+------------------------------------------------------------------+
//|              Forex EA and Script Generator version 4.1        EA |
//|                                     Copyright 2011, Etasoft Inc. |
//|                                    http://www.forexgenerator.com |
//+------------------------------------------------------------------+
// Keywords: developer, Forex EA builder, create EA, expert advisor, MT5, MT4

#property copyright "Copyright © 2011, Etasoft Inc. Forex EA Generator v4.1"
#property link      "http://www.forexgenerator.com"

#include <Trade\Trade.mqh>

// exported variables
input double Lots3 = 0.2;
input int Stoploss3 = 200;
input int Takeprofit3 = 300;


// local variables
double PipValue=1;    // this variable is here to support 5-digit brokers
bool Terminated = false;
string LF = "\n";  // use this in custom or utility blocks where you need line feeds
int NDigits = 4;   // used mostly for NormalizeDouble in Flex type blocks
int ObjCount = 0;  // count of all objects created on the chart, allows creation of objects with unique names
int current = 0;

int Count8 = 0;


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
    //---
    NDigits = Digits();
    if (NDigits == 3 || NDigits == 5) PipValue = 10;
   
    if (AccountInfoInteger(ACCOUNT_TRADE_EXPERT) == false)
    {
        Print("Check terminal options because EA trade option is set to not allowed.");
        Comment("Check terminal options because EA trade option is set to not allowed.");
    }
   
    if (false) ObjectsDeleteAll(0);      // clear the chart
   
   
    Comment("");    // clear the chart
    //---
    return(0);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
    //---
    if (false) ObjectsDeleteAll(0);
   
   
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
    //---
    if (Terminated == true)
    {
        Comment("EA Terminated.");
    }
   
    OnEveryTick5();
}

//+------------------------------------------------------------------+
//| Get Low for specified bar index                                  |
//+------------------------------------------------------------------+
double Low(int index)
{
    double arr[];
    double low = 0;
    ArraySetAsSeries(arr, true);
    int copied = CopyLow(Symbol(), PERIOD_CURRENT, 0, Bars(Symbol(), PERIOD_CURRENT), arr);
    if (copied>0 && index<copied) low = arr[index];
    return (low);
}
//+------------------------------------------------------------------+
//| Get the High for specified bar index                             |
//+------------------------------------------------------------------+
double High(int index)
{
    double arr[];
    double high = 0;
    ArraySetAsSeries(arr, true);
    int copied = CopyHigh(Symbol(), PERIOD_CURRENT, 0, Bars(Symbol(), PERIOD_CURRENT), arr);
    if (copied>0 && index<copied) high=arr[index];
    return(high);
}
//+------------------------------------------------------------------+
//| Get Close for specified bar index                                |
//+------------------------------------------------------------------+
double Close(int index)
{
    double arr[];
    double close = 0;
    ArraySetAsSeries(arr, true);
    int copied = CopyClose(Symbol(), PERIOD_CURRENT, 0, Bars(Symbol(), PERIOD_CURRENT), arr);
    if (copied>0 && index<copied) close = arr[index];
    return (close);
}
//+------------------------------------------------------------------+
//| Get Open for specified bar index                                 |
//+------------------------------------------------------------------+
double Open(int index)
{
    double arr[];
    double open = 0;
    ArraySetAsSeries(arr, true);
    int copied = CopyOpen(Symbol(), PERIOD_CURRENT, 0, Bars(Symbol(), PERIOD_CURRENT), arr);
    if (copied>0 && index<copied) open = arr[index];
    return (open);
}
//+------------------------------------------------------------------+
//| Get current bid value                                            |
//+------------------------------------------------------------------+
double Bid()
{
    return (SymbolInfoDouble(Symbol(), SYMBOL_BID));
}

//+------------------------------------------------------------------+
//| Get current ask value                                            |
//+------------------------------------------------------------------+
double Ask()
{
    return (SymbolInfoDouble(Symbol(), SYMBOL_ASK));
}

//+------------------------------------------------------------------+
//| Is there an error                                                |
//+------------------------------------------------------------------+
bool IsError(MqlTradeResult& result, string function)
{
    if (result.retcode != 0 && result.retcode != TRADE_RETCODE_DONE && result.retcode != TRADE_RETCODE_PLACED)
    {
        Print("Function: ", function, " Error: ", result.retcode, " ", result.comment);
        return (true);
    }
    else
    Print("> Executed: [", function, "]");
    return (false);
}

bool IsError(CTrade& trade, string function)
{
    if (trade.ResultRetcode() != 0 && trade.ResultRetcode() != TRADE_RETCODE_DONE && trade.ResultRetcode() != TRADE_RETCODE_PLACED)
    {
        Print("Function: ", function, " Error: ", trade.ResultRetcode(), " ", trade.ResultRetcodeDescription());
        return (true);
    }
    else
    Print("> Executed: [", function, "]");
    return (false);
}

//+------------------------------------------------------------------+
//| Get indicator value back                                         |
//+------------------------------------------------------------------+
double GetIndicator(int handle, int buffer_num, int index)
{
    //--- array for the indicator values
    double arr[];   
    //--- obtain the indicator value in the last two bars
    if (CopyBuffer(handle, buffer_num, 0, index+1, arr) <= 0)
    {       
        Sleep(5);
        for(int i=0; i<100; i++)
        {
            if (BarsCalculated(handle) > 0)
            break;
            Sleep(50);
        }
        int copied = CopyBuffer(handle, buffer_num, 0, index+1, arr);
        if (copied <= 0)
        {
            Print("CopyBuffer Failed. Error = ", GetLastError());
            return -1;
        }
        else
        {
            IndicatorRelease(handle);
            return (arr[index]);
        }
    }
    else
    {
        IndicatorRelease(handle);
        return (arr[index]);
    }
   
    IndicatorRelease(handle);
    return 0;
}

//+------------------------------------------------------------------+
//| Building blocks                                                  |
//+------------------------------------------------------------------+
void OnEveryTick5()
{
   
    if (NDigits == 3 || NDigits == 5) PipValue = 10;
   
    PrintInfoToChart8();
   
}

void PrintInfoToChart8()
{
    string temp = "Some Text\nExecuted : " + IntegerToString(Count8) + "\n"
    + "Spread: " + DoubleToString(SymbolInfoInteger(Symbol(),SYMBOL_SPREAD)/PipValue, 2)+ "\n"
    + "------------------------------------------------\n"
    + "ACCOUNT INFORMATION:\n"
    + "\n"
    + "Account Name:     " + AccountInfoString(ACCOUNT_NAME) + "\n"
    + "Account Leverage:     " + IntegerToString(AccountInfoInteger(ACCOUNT_LEVERAGE)) + "\n"
    + "Account Balance:     " + DoubleToString(AccountInfoDouble(ACCOUNT_BALANCE), 2)+ "\n"
    + "Account Equity:     " + DoubleToString(AccountInfoDouble(ACCOUNT_EQUITY), 2)+ "\n"
    + "Free Margin:     " + DoubleToString(AccountInfoDouble(ACCOUNT_FREEMARGIN), 2)+ "\n"
    + "Used Margin:     " + DoubleToString(AccountInfoDouble(ACCOUNT_MARGIN_LEVEL), 2)+ "\n"
    + "------------------------------------------------\n";
    Comment(temp);
    Count8++;
    TechnicalAnalysis9();
   
}

void TechnicalAnalysis9()
{
   
    if (GetIndicator(iMA(NULL, PERIOD_M2,20,0,MODE_SMA,PRICE_CLOSE),0,current) < GetIndicator(iMA(NULL, PERIOD_M2,8,0,MODE_SMA,PRICE_CLOSE),0,current))
    {
        IfPositionDoesNotExist4();
       
    }
}

void IfPositionDoesNotExist4()
{
   
    bool exists = false;
   
    // go through all positions
    for (int i=PositionsTotal()-1;i>=0;i--)
    {
        if (PositionSelect(Symbol()))
        // position with appropriate ORDER_MAGIC, symbol and order type
        if (PositionGetInteger(POSITION_MAGIC) == 1 && PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
        exists = true;
    }
   
    if (exists == false)
    {
        BuyOrder3();
       
    }
}

void BuyOrder3()
{
   
    //--- prepare a request
    MqlTradeRequest request;
    request.action = TRADE_ACTION_DEAL;          // setting a deal order
    request.magic = 1;                   // ORDER_MAGIC
    request.symbol = Symbol();                   // symbol
    request.volume= Lots3;                      // volume in lots
    request.price = Ask();
    request.sl = Ask() - Stoploss3*PipValue*Point();      // Stop Loss specified
    request.tp = Ask() + Takeprofit3*PipValue*Point();    // Take Profit specified
    request.deviation= 4;             // deviation in points
    request.type = ORDER_TYPE_BUY;
    request.comment = "Order";
   
    MqlTradeResult result;
    OrderSend(request,result);
    // check the result
    if (!IsError(result, __FUNCTION__))
    {
           
    }
}
 
Sarsali:

Hi

I wrote a EA But buy order don't execute and i get this error. pl help !

Error:
2014.05.12 11 36.000 2014.04.04 05:01:06 Function: BuyOrder3 Error: 10013 Invalid request

2014.05.12 11 36.000 2014.04.04 05:01:07 failed exchange buy 0.20 EURUSD at 1.37150 sl: 1.36950 tp: 1.37450 [Invalid request]

Thank You

Try to change this line :

    //--- prepare a request
    MqlTradeRequest request={0};
 
angevoyageur:

Try to change this line :

that's right. Thank you a lot angevoyageur
 

I have the same problem.
Pleasehelp me.

2021.01.11 11:16:55.474 EA_Sophie (AUDUSD.R2.5pip,M1) Ordem de Compra  - com falha. ResultRetcode: 10013, RetcodeDescription: invalid request

input double                  lote = 0.01;                      //Volume
input double                  StopLoss = 0.0003;                   //Stop Loss
input double                  TakeProfit = 0.0004;                 //Take Profit
input bool                    Breakeven = true;                //Active Break Even
input double                  Trigger_Breakeven = 0.00/035;          //Trigger Break Even
input bool                    TrailingStop = true;             //Active Trailing Stop
input double                  Trigger_TrailingStop = 0.00035;       //Trigger Trailing Stop
input double                  Step_TrailingStop = 0.00035;          //Step Trailing Stop

input ulong                   MagicNumber = 80008;             //Magic Number
input ulong                   DesvPoints = 0;                  //Desvio em Pontos
input ENUM_ORDER_TYPE_FILLING Fill = ORDER_FILLING_FOK;        //Order Filling (Fill or Kill / Imed. or Cancel / Exec)

double                        PRC;  //Preço normalizado
double                        STL;  //StopLoss normalizado
double                        TKP;  //TakeProfit normalizado

            PRC = NormalizeDouble(ultimoTick.ask, _Digits);
            STL = NormalizeDouble(PRC - StopLoss, _Digits);
            TKP = NormalizeDouble(PRC + TakeProfit, _Digits);
            if(trade.Buy(lote, _Symbol, PRC, STL, TKP, ""))
              {
               Print("Ordem de Compra AUTOMÁTICA - RENKO - sem falha. ResultRetcode: ", trade.ResultRetcode(), ", RetcodeDescription: ", trade.ResultRetcodeDescription());
              }
            else
              {
               Print("Ordem de Compra AUTOMÁTICA - RENKO - com falha. ResultRetcode: ", trade.ResultRetcode(), ", RetcodeDescription: ", trade.ResultRetcodeDescription());
              }


Reason: