Download MetaTrader 5
To add comments, please log in or register
Add our Facebook page to friends. Follow the latest news!
ramram1975
128
ramram1975 2014.04.29 01:50 

I request if some one help me in compiling and making error free for attached code,

This is my first time to open the programe file and write code from seen video's.

Ajay

Keith Watford
Moderator
7907
Keith Watford 2014.04.29 02:31  
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
 input int TakeProfit=50; 
 input int Stoploss=25;
 input int FastMA=5;
 input int FastMAShift=0;
 input int FastMAmethod=0;
 input int FastMAAppliedTo=0;
 input int SlowMA=21;
 input int SlowMAShift=0;
 input int SlowMAmethod=0;
 input int SlowMAAppliedTo=0;
 input double LotSize=0.01;
 input int MagicNumber = 1234;
 double Pips;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
{
//-------------
  double ticksize= MarketInfo(Symbol(),MODE_TICKSIZE);
  if(ticksize == 0.00001 || Point == 0.001)
  Pips = ticksize*10;
  else Pips = ticksize ;
//-------------
 return (0);
 }
 int deint()
 {
 //----------
 
 //----------
  return(0);
  }
  //+----------------------------------------------------------------+
  //| 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),NULL,MagicNumber,0,Green);
   if(PreviousFast>PreviousSlow && CurrentFast<CurrentSlow)
    if(OrdersTotal()==0)
      OrderSend(Symbol(),OP_SELL,LotSize,Bid,3,Bid+(Stoploss*Pips),Bid-(TakeProfit*Pips),NULL,MagicNumber,0,Red);
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+

Variables are case sensitive and cannot have spaces. If you declare a variable starting with a capital letter, it has to be written with the same capital letter when you access it.

After an if() condition, do not put a ";"

ramram1975
128
ramram1975 2014.04.29 09:43  
Do you mean i should not add semicolon at the end of if statement.
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.04.29 09:48  
if(you-condition-matches) { do-something-here; do-more-here; }

Something like that is correct.

whroeder1
13610
whroeder1 2014.04.29 12:04  
08021976: Do you mean i should not add semicolon at the end of if statement.
It's
if(condition) aStatement
  // or ignoring white space.
if(condition) 
   aStatement
The semicolon is part of aStatement not part of the if.
and braces is a statement
if(condition) { aStatement1; ... }
No semicolon after the closing brace.
But you wrote
if(condition) /* DO NOTHING */;
Same as
if(condition) {/* DO NOTHING */}
ramram1975
128
ramram1975 2014.04.29 16:49  

Thanks very much After compling like on the top i get two warnings and when i apply this on chart and test it doesnot open any trade what could be reason.

'Ajay New Moving Average EA.mq4' Ajay New Moving Average EA.mq4 1 1

return value of 'OrderSend' should be checked Ajay New Moving Average EA.mq4 57 6

return value of 'OrderSend' should be checked Ajay New Moving Average EA.mq4 60 7

0 error(s), 2 warning(s) 1 3

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.04.29 16:58  
It is just a warning and you EA should still run. So, there must be some code inside which isn't triggered to open any trade.
ramram1975
128
ramram1975 2014.05.01 07:03  

Sir,

I tried my best and updated the code some wht but i am getting two errors which i am failing to understand and the same two warnings which are not opening any trade.

I have a deep heart request pls help me come out of this trouble.

honest_knave
961
honest_knave 2014.05.01 07:48  

Your code:

 void CheckForMaTrade(); 
{
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)OrderEntry(0);
if(PreviousFast>PreviousSlow && CurrentFast<CurrentSlow)OrderEntry(1);

 }

Correction (removal of semicolon on first line)

 void CheckForMaTrade()  
{
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)OrderEntry(0);
if(PreviousFast>PreviousSlow && CurrentFast<CurrentSlow)OrderEntry(1);

 }

You might want to look here about the other warnings

ramram1975
128
ramram1975 2014.05.01 16:12  

I am sorry i tried to to do that after reading every thing but i could not suceed in writing and compling,

i request if you could do this for me.

ramram1975
128
ramram1975 2014.05.03 11:05  
Hi i tried a lot so the code could send the order. But After all my efforts.i did not suceed to write order send function. Pls help me to write order send function for above attached code. Thanks
/
To add comments, please log in or register