MT4 newbie - simple problem driving me crazy

 

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:

Compile warnings)

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);

  }

//+------------------------------------------------------------------+


Mql4_Lesson_10 Writing an Expert Advisor Based on Moving Averages
Mql4_Lesson_10 Writing an Expert Advisor Based on Moving Averages
  • 2013.03.23
  • www.youtube.com
Mql4 Progamming Tutorials and Forex Trading Training. http://learnmql4.com Download my Trade Management Tool at https://www.mql5.com/en/market/product/11862 ...
 
gns_zw:

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);

  }

//+------------------------------------------------------------------+


Your code needs to be inside of the ontick function and not the start function. 
 
Fantastic - thks for your help It's working a treat now
 
Don't paste code
Play video
Please edit your post.
For large amounts of code, attach it
Reason: