MQL5: Execution orders

 

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);
  }
//+------------------------------------------------------------------+
 

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


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

  2. Indicators can not trade.
Reason: