Questions from Beginners MQL5 MT5 MetaTrader 5 - page 679
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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?
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?
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 include the print in the log of any values and find out. If it doesn't print, it doesn't work.
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.
That's clear ...I was wondering if someone could share their experience with a newbie.
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:
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;
}
}
}
//+------------------------------------------------------------------+
This is not the way to do it:
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.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.