MQL5: Execution orders

To add comments, please log in or register
mariogharib
28
mariogharib  

Dear Metatraders,

I am receiving an error when trying to execute an order, it is giving me an unknown retcode 0 in the backtesting

Any idea why ?

Many thanks,


//+------------------------------------------------------------------+
//|                                                PlacingOrders.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_plots 0

#include <Trade\Trade.mqh>
CTrade trade;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   if (TimeCurrent()==D'2018.01.02 10:36:00') {
      Print("Long NZDCHF");
      double ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
      // Print(trade.Buy(0.1, NULL, ask, 0, 0, "OK"));
      if(!trade.Buy(1, NULL, ask, 0, 0, "")) {
         Print("Buy() method failed. Return code=",trade.ResultRetcode()," Code description: ",trade.ResultRetcodeDescription());
      } else {
         Print("Buy() method executed successfully. Return code=",trade.ResultRetcode()," (",trade.ResultRetcodeDescription(),")");
      }
   }
   return(rates_total);
  }
//+------------------------------------------------------------------+
Juvenille Emperor Limited
Moderator
9356
Eleni Anna Branou  

Please use the </> button to insert your code.


William Roeder
19975
William Roeder  
  1. You should have edited your original post, not reposted.
              Messages Editor

  2. Indicators can not trade.
To add comments, please log in or register