Hi
Wondering if anyone can point me in the right direction with what is probably a really simple problem.
I have created a simple MA crossover script which is the same as presented by jimdandy1958 on YouTube - https://www.youtube.com/watch?v=ny6qFnPyauo&t=35s
The only difference I can see is that my MetaEditor software creates a predefined code template that has 'void' functions rather than the 'int' functions that jimdandy1958 uses.
I've replaced the void functions with the int functions as per the video and compiled with 2 warnings as per below:
)
However, when I run the code in strategy tester it does not seem to execute orders - control does not even seem to get into the start() function. It's frustrating as I'm only trying to execute two functions.
I'd appreciate any help if anyone can assist.
Many thks
Glen
A copy of my code is below:
//+------------------------------------------------------------------+
//| GS_MACross.mq4 |
//| Copyright 2017, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
extern int TakeProfit = 50;
extern int StopLoss = 25;
extern int FastMA = 5;
extern int FastMAShift = 0;
extern int FastMAMethod = 0;
extern int FastMAAppliedTo = 0;
extern int SlowMA = 21;
extern int SlowMAShift = 0;
extern int SlowMAMethod = 0;
extern int SlowMAAppliedTo = 0;
extern double LotSize = 0.;
extern int MagicNumber = 2244;
double pips;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//---
// translate for JPY vs others
double TickSize=MarketInfo(Symbol(),MODE_TICKSIZE);
if (TickSize==0.00001 || Point==0.001)
pips = TickSize*10;
else
pips = TickSize;
return(0);
//---
//return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---
return(0);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
double PreviousFast = iMA(NULL,0,FastMA,FastMAShift,FastMAMethod,FastMAAppliedTo,2);
double CurrentFast = iMA(NULL,0,FastMA,FastMAShift,FastMAMethod,FastMAAppliedTo,1);
double PreviousSlow = iMA(NULL,0,SlowMA,SlowMAShift,SlowMAMethod,SlowMAAppliedTo,2);
double CurrentSlow = iMA(NULL,0,SlowMA,SlowMAShift,SlowMAMethod,SlowMAAppliedTo,1);
if (PreviousFast<PreviousSlow && CurrentFast>CurrentSlow)
if (OrdersTotal()>=0)
OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,Ask-(StopLoss*pips),Ask+(TakeProfit*pips),"",MagicNumber,0,Green);
if (PreviousFast>PreviousSlow && CurrentFast<CurrentSlow)
if (OrdersTotal()>=0)
OrderSend(Symbol(),OP_SELL,LotSize,Bid,3,Bid+(StopLoss*pips),Bid-(TakeProfit*pips),"",MagicNumber,0,Red);
//----
return(0);
}
//+------------------------------------------------------------------+
![]() Play video | Please edit your
post. For large amounts of code, attach it |

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi
Wondering if anyone can point me in the right direction with what is probably a really simple problem.
I have created a simple MA crossover script which is the same as presented by jimdandy1958 on YouTube - https://www.youtube.com/watch?v=ny6qFnPyauo&t=35s
The only difference I can see is that my MetaEditor software creates a predefined code template that has 'void' functions rather than the 'int' functions that jimdandy1958 uses.
I've replaced the void functions with the int functions as per the video and compiled with 2 warnings as per below:
However, when I run the code in strategy tester it does not seem to execute orders - control does not even seem to get into the start() function. It's frustrating as I'm only trying to execute two functions.
I'd appreciate any help if anyone can assist.
Many thks
Glen
A copy of my code is below:
//+------------------------------------------------------------------+
//| GS_MACross.mq4 |
//| Copyright 2017, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
extern int TakeProfit = 50;
extern int StopLoss = 25;
extern int FastMA = 5;
extern int FastMAShift = 0;
extern int FastMAMethod = 0;
extern int FastMAAppliedTo = 0;
extern int SlowMA = 21;
extern int SlowMAShift = 0;
extern int SlowMAMethod = 0;
extern int SlowMAAppliedTo = 0;
extern double LotSize = 0.;
extern int MagicNumber = 2244;
double pips;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//---
// translate for JPY vs others
double TickSize=MarketInfo(Symbol(),MODE_TICKSIZE);
if (TickSize==0.00001 || Point==0.001)
pips = TickSize*10;
else
pips = TickSize;
return(0);
//---
//return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---
return(0);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
double PreviousFast = iMA(NULL,0,FastMA,FastMAShift,FastMAMethod,FastMAAppliedTo,2);
double CurrentFast = iMA(NULL,0,FastMA,FastMAShift,FastMAMethod,FastMAAppliedTo,1);
double PreviousSlow = iMA(NULL,0,SlowMA,SlowMAShift,SlowMAMethod,SlowMAAppliedTo,2);
double CurrentSlow = iMA(NULL,0,SlowMA,SlowMAShift,SlowMAMethod,SlowMAAppliedTo,1);
if (PreviousFast<PreviousSlow && CurrentFast>CurrentSlow)
if (OrdersTotal()>=0)
OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,Ask-(StopLoss*pips),Ask+(TakeProfit*pips),"",MagicNumber,0,Green);
if (PreviousFast>PreviousSlow && CurrentFast<CurrentSlow)
if (OrdersTotal()>=0)
OrderSend(Symbol(),OP_SELL,LotSize,Bid,3,Bid+(StopLoss*pips),Bid-(TakeProfit*pips),"",MagicNumber,0,Red);
//----
return(0);
}
//+------------------------------------------------------------------+