agu2a:
When opening orders you should check them like
bool Buy = OrderSend(....
No, OrderSend returns an integer, the ticket number or -1 if it fails.
OP, check the return value and if it is -1, then you know the order failed, so take appropiate action, check for last error.
You can use this :
void OnTick()
{
//---
double previousfast = iMA(NULL,0,fastma,fastmashift,fastmamethod,fastmaappliedto,1);
double currentfast = iMA(NULL,0,fastma,fastmashift,fastmamethod,fastmaappliedto,1);
//^(NULL=moving average on the current currency pair. 0=the current timeframe. fastma= the moving average period.
double previousslow = iMA(NULL,0,slowma,slowmashift,slowmamethod,slowmaappliedto,1);
double currentslow = iMA(NULL,0,slowma,slowmashift,slowmamethod,slowmaappliedto,1);
int ticket = 0;
if(previousfast<previousslow && currentfast>currentslow)
//^sell
if(OrdersTotal()==0)
ticket = OrderSend(Symbol(),OP_BUY,lotsize,Ask,3,Ask-(stoploss*pips),Ask+(takeprofit*pips),"EA Jim Dandy MA Trade",magicnumber,0,Green);
if(previousfast>previousslow && currentfast<currentslow)
//^buy
if(OrdersTotal()==0)
ticket = OrderSend(Symbol(),OP_SELL,lotsize,Bid,3,Bid+(stoploss*pips),Bid-(takeprofit*pips),"EA Jim Dandy MA Trade",magicnumber,0,Red);
}
{
//---
double previousfast = iMA(NULL,0,fastma,fastmashift,fastmamethod,fastmaappliedto,1);
double currentfast = iMA(NULL,0,fastma,fastmashift,fastmamethod,fastmaappliedto,1);
//^(NULL=moving average on the current currency pair. 0=the current timeframe. fastma= the moving average period.
double previousslow = iMA(NULL,0,slowma,slowmashift,slowmamethod,slowmaappliedto,1);
double currentslow = iMA(NULL,0,slowma,slowmashift,slowmamethod,slowmaappliedto,1);
int ticket = 0;
if(previousfast<previousslow && currentfast>currentslow)
//^sell
if(OrdersTotal()==0)
ticket = OrderSend(Symbol(),OP_BUY,lotsize,Ask,3,Ask-(stoploss*pips),Ask+(takeprofit*pips),"EA Jim Dandy MA Trade",magicnumber,0,Green);
if(previousfast>previousslow && currentfast<currentslow)
//^buy
if(OrdersTotal()==0)
ticket = OrderSend(Symbol(),OP_SELL,lotsize,Bid,3,Bid+(stoploss*pips),Bid-(takeprofit*pips),"EA Jim Dandy MA Trade",magicnumber,0,Red);
}
ReillyFox: getting a couple warnings I dont know how to fix
if(OrdersTotal()==0)
ticket = OrderSend(...);
ticket = OrderSend(...);
- What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
- Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum

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
Hey so I wrote up my first ea, but im getting a couple warnings I dont know how to fix, can someone please help?
here is the whole ea
//| Jim Dandy Course EA.mq4 |
//| Reilly |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Reilly"
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//////////////////////////////////////////////////////////////////////
//INPUT//
//////////////////////////////////////////////////////////////////////
extern int takeprofit=50;
extern double stoploss=25;
extern int fastma=5;
extern int fastmashift=0;
//^ ma shift is offset of linegraph on chart
extern int fastmamethod=0;
//^ma method is simple/exponential moving average etc
extern int fastmaappliedto=0;
//^applied to is basing the moving average on the closing price of the bar or the opening price etc
extern int slowma=21;
extern int slowmashift=0;
extern int slowmamethod=0;
extern int slowmaappliedto=0;
extern double lotsize=0.01;
extern int magicnumber = 1337;
double pips;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
double ticksize = MarketInfo(Symbol(),MODE_TICKSIZE);
if (ticksize = 0.00001 || 0.001)
double pips = (ticksize*10);
else pips = ticksize;
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
double previousfast = iMA(NULL,0,fastma,fastmashift,fastmamethod,fastmaappliedto,1);
double currentfast = iMA(NULL,0,fastma,fastmashift,fastmamethod,fastmaappliedto,1);
//^(NULL=moving average on the current currency pair. 0=the current timeframe. fastma= the moving average period.
double previousslow = iMA(NULL,0,slowma,slowmashift,slowmamethod,slowmaappliedto,1);
double currentslow = iMA(NULL,0,slowma,slowmashift,slowmamethod,slowmaappliedto,1);
if(previousfast<previousslow && currentfast>currentslow)
//^sell
if(OrdersTotal()==0)
OrderSend(Symbol(),OP_BUY,lotsize,Ask,3,Ask-(stoploss*pips),Ask+(takeprofit*pips),"EA Jim Dandy MA Trade",magicnumber,0,Green);
if(previousfast>previousslow && currentfast<currentslow)
//^buy
if(OrdersTotal()==0)
OrderSend(Symbol(),OP_SELL,lotsize,Bid,3,Bid+(stoploss*pips),Bid-(takeprofit*pips),"EA Jim Dandy MA Trade",magicnumber,0,Red);
}
//+------------------------------------------------------------------+