Might you mean error code 4756?
Are you sure that trading by Experts is enabled on your real account?
Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Account Properties
- www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Account Properties - Documentation on MQL5
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
Hi!
The following code works perfectly with demo accounts, but it doesn't work with real account. It gives 4746 error, when it try to open position.
Help me please.
#include <Trade/Trade.mqh>
input double Lots = 0.1;
string state;
double StopLoss;
double TakeProfit;
string PrevState;
CTrade order;
int OnInit(){
order.SetExpertMagicNumber(321);
return(0);
}
void OnDeinit(const int reason){
}
void OnTick(){
int handle = FileOpen(Symbol() + "_state.txt", FILE_READ|FILE_TXT|FILE_ANSI);
state = FileReadString(handle);
TakeProfit = (double)FileReadString(handle);
StopLoss = (double)FileReadString(handle);
FileClose(handle);
if(state == "close" && PositionSelect(Symbol())){
order.PositionClose(Symbol());
return;
}
if(!state || PositionSelect(Symbol()) || state == PrevState){
return;
}
PrevState = state;
if(state == "buy"){
order.Buy(Lots, Symbol(), NULL, StopLoss, TakeProfit);
}
if(state == "sell"){
order.Sell(Lots, Symbol(), NULL, StopLoss, TakeProfit);
}
if(PositionSelect(Symbol())){
order.PositionModify(Symbol(),StopLoss, TakeProfit);
}
}