Questions from Beginners MQL5 MT5 MetaTrader 5 - page 679

 

I'm writing a robot, connecting Ctrade, first I want to use logic, according to which at the beginning of each hour it will make a Buy deal at market price, after half an hour it will sell everything (Sell) at a new market price. When I test it in the tester, I get error Invalid order type.

My instrument is SBER, my client is Otkritie. My order is in manual mode, my order is not passed in real or demo account.

What might be the error? Is it true that the stock market is not allowed to trade at the market price?

 
post_ek:

I am writing a robot, connecting Ctrade, first I want to start with a logic where it will make a Buy deal at market price at the beginning of each hour, after half an hour it will sell everything at a new market price. When I test it in the tester, I get error Invalid order type.

My instrument is SBER, my client is Otkritie. My order is in manual mode, my order is not passed in real or demo account.

What might be the error? Is it true that the stock market is not allowed to trade at the market price?

I can't understand what you've written without your code and why it's not working for you.
 
Hello .If the EA is running on a laptop and it is in hibernation mode will the plugged in EA work in this case ?
 
Movlat Baghiyev:
Good afternoon .If the EA is running on a laptop and it has gone into hibernation mode will the connected EA work in this case ?
And you will enable the printer in the log of any values and you will find out. If it does not print then it is not working.
 
Vitalie Postolache:
And you will include the print in the log of any values and find out. If it doesn't print, it doesn't work.
That's clear ... I thought someone might share their experience with a newbie
 
Movlat Baghiyev:
Good day .If the EA is running on a laptop and it has gone to sleep mode will the connected EA work in this case ?

The hibernation mode is usually the one that shuts down the drive,

I recently installed a server, and only on day 3 I saw that the computer was asleep, i.e. not working, i.e. all the EAs were not working,

I disabled the hibernation mode and everything is fine.

 
Movlat Baghiyev:
That's clear ...I was wondering if someone could share their experience with a newbie.
Well in my experience not much works in hibernation, only some system services.
 
Movlat Baghiyev:
Hello .If the advisor is running on a laptop and it is in hibernation mode will the connected advisor work in this case ?

No. It won't work. In the power settings, set the power supply:

NO to sleep mode!

 
Sergey Gritsay:
Without your code, it's hard to understand what you've written and why it doesn't work.
//+------------------------------------------------------------------+
//|                                                         Gear.mq5 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

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

bool TimeFlag, FLG;
int TimeScale=50, TimeInMemory, TimeNow;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  
  //---Блок получения информации с биржи    
  MqlTick oCurrentTick;
  SymbolInfoTick(Symbol(), oCurrentTick);
//---Блок определения начала нового временного интервала
   TimeFlag=false;
   datetime tm=TimeCurrent();
   MqlDateTime stm;
   TimeToStruct(tm,stm);
   if(MathMod(StringToInteger((string)stm.min),TimeScale)==0)
     {
      TimeNow=StringToInteger((string)stm.min);
     }
   if(TimeNow != TimeInMemory)
     {
      TimeInMemory=TimeNow;
      TimeFlag=true;
      //Print(_Symbol);
     }
    
     if(TimeFlag)
       {
       if(FLG)
         {
   if(!trade.Buy(1,_Symbol))
     {
      //--- сообщим о неудаче
      Print("Метод Buy() потерпел неудачу. Код возврата=",trade.ResultRetcode(),
            ". Описание кода: ",trade.ResultRetcodeDescription());
     }
   else
     {
      Print("Метод Buy() выполнен успешно. Код возврата=",trade.ResultRetcode(),
            " (",trade.ResultRetcodeDescription(),")");
     }
         FLG=false;
         }
       else
         {
         trade.Sell(1);
         FLG=true;
         }
       }
  }
//+------------------------------------------------------------------+
 
post_ek:

This is not the way to do it:

bool TimeFlag,FLG;
int TimeScale=50,TimeInMemory,TimeNow;

or rather, after such a declaration, you must explicitly initialise(assign values to) these variables in OnInit().

The Sell method must also be surrounded by checks, such as

trade.ResultRetcode(),
            " (",trade.ResultRetcodeDescription(),")");

And there can also be one catch - in the morning, at the opening of trading, the auction does not start immediately, not from the first second - that's when errors are possible.