Download MetaTrader 5

MQL4 Biggest body between last 20 candle

To add comments, please log in or register
Articles can help you to solidify your knowledge. Come and read them!
mostafalotfi
185
mostafalotfi 2014.01.10 16:40 

Hello All

Im new to MQL4 and programming :) i just started to learn,

i need to know how can i write an expert to

1) find the biggest body of last 20 candle

2) calculate the size of body

i really appreciate if you help me to learn :)

Thanks

Mostafa

mostafalotfi
185
mostafalotfi 2014.01.10 16:43  
by last 20 candle i mean, complete candles...
Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2014.01.10 16:46  
mostafa:

Hello All

Im new to MQL4 and programming :) i just started to learn,

i need to know how can i write an expert to

1) find the biggest body of last 20 candle

2) calculate the size of body

i really appreciate if you help me to learn :)

Use a loop to go through the last 20 candles . . . save the MathAbs() difference between the Open and Close, then compare the next difference for the next candle to the last one saved, if it is larger save it instead, repeat for all the candles.
mostafalotfi
185
mostafalotfi 2014.01.10 17:11  
RaptorUK:
Use a loop to go through the last 20 candles . . . save the MathAbs() difference between the Open and Close, then compare the next difference for the next candle to the last one saved, if it is larger save it instead, repeat for all the candles.


Hey buddy

its little bit complicated for me as a starter :) i really appreciate your support ... let me try if i can handle it :d i should start from one place its the best time

P.S do you know any good book that explain all functions ? with sample?

whroeder1
14477
whroeder1 2014.01.10 17:19  
learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2014.01.10 17:28  
mostafa:


Hey buddy

its little bit complicated for me as a starter :) i really appreciate your support ... let me try if i can handle it :d i should start from one place its the best time

P.S do you know any good book that explain all functions ? with sample?

The free book on this site: Book
mostafalotfi
185
mostafalotfi 2014.01.10 18:11  
WHRoeder:
learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.

Sure, undrestood
mostafalotfi
185
mostafalotfi 2014.01.10 20:26  
Hey Guys

could you please put your comments?
//+------------------------------------------------------------------+ //|                                                         test.mq4 | //|                        Copyright 2014, MetaQuotes Software Corp. | //|                                        http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright 2014, MetaQuotes Software Corp." #property link      "http://www.metaquotes.net" extern int nOfCandle =25; //+------------------------------------------------------------------+ //| expert initialization function                                   | //+------------------------------------------------------------------+ int init()   {   double O = Open [1];   double C= Close[1];   if(C<O)   {   double badaneh = (O-C)/Point;   Comment (badaneh);   }   if(C>O)   {   double badaneh2 = (C-O)/Point;   Comment (badaneh2);   }      if (nOfCandle>Bars) { Alert("تعداد کندل اشتباه است"); return(-1); } int n =0; int MaxN=0; double MaxBody=0; while(n<nOfCandle) {    double Body=(Open[n]-Close[n])/Point;    int dy=MathAbs Body;    if (dy>MaxBody)    {       MaxBody=dy;       MaxN=n;    }    n++; } Comment("\n","\n",MaxBody,"\n",MaxN);
mostafalotfi
185
mostafalotfi 2014.01.10 20:49  

i think i have problem with below section

int dy=MathAbs Body; 

if (dy>MaxBody)

can you please let me know how can i handle this part? i

Alain Verleyen
Moderator
30719
Alain Verleyen 2014.01.10 20:53  
mostafa:

i think i have problem with below section

if (dy>MaxBody)

can you please let me know how can i handle this part? i

int dy=MathAbs(Body); 
MathAbs is a function, you have to use parenthesis.
mostafalotfi
185
mostafalotfi 2014.01.11 07:29  

Hello Guys,

Could you please help me why i face the below error?

'(' - function definition unexpected

//+------------------------------------------------------------------+
//|                                                         test.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

extern int q=1;
extern int nOfCandle =25;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
  double O = Open [q];
  double C= Close[q];
   if(C<O)
   {
      double badaneh = (O-C)/Point;
   }
   if(C>O)
   {
      double badaneh2 = (C-O)/Point;  
   }
 
   if (nOfCandle>Bars)
   {
      Alert("تعداد کندل اشتباه است");
      return(-1);
   }

 
 int n =0;
 int MaxN=0;
 double MaxBody=0;
 while(n<nOfCandle)
 {
   double Body=(Open[n]-Close[n])/Point;
   double dy=MathAbs (Body);
   if (dy>MaxBody)
   {
      MaxBody=dy;
      MaxN=n;
   }
   n++;
 } 
 

   {
   double darsad = (badaneh/MaxBody)*100;
   double darsad2 = (badaneh2/MaxBody)*100;
   double Totaldarsad=(darsad+darsad2);
}

   if (Totaldarsad>=60)
      {
         string B="بزرگ";
      }
   if (Totaldarsad>=40,Totaldarsad<60)
      {
      string M="متوسط";
      }
   if (Totaldarsad=<40)
      {
      string S="کوچک";
      }
   
  Comment("\n   اندازه بدنه کندل مورد ارزيابي ",badaneh,"\n   :اندازه بدنه کندل مورد ارزيابي ",badaneh2,"\n","\n","\n   :اندازي بدنه کندل مبنا",MaxBody,"\n   :شماره بزرگترين کندل محيط",MaxN,"\n   :نسبت بدنه کندل مورد ارزيابي به بدنه مبنا",Totaldarsad);
  
    
//----
   return(0);
  }
  
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
Comment("");   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

123
To add comments, please log in or register