# MQL4 Biggest body between last 20 candle

186

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

186

by last 20 candle i mean, complete candles...
17411

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.
186

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?

25838

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.
17411

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
186

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
186

```Hey Guys

//+------------------------------------------------------------------+
//|                                                         test.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+

extern int nOfCandle =25;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
{
double O = Open [1];
double C= Close[1];
if(C<O)
{
}
if(C>O)
{
}

if (nOfCandle>Bars)
{
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);
```
186

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

42595

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.
186

Hello Guys,

'(' - function definition unexpected

```//+------------------------------------------------------------------+
//|                                                         test.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                        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)
{
}
if(C>O)
{
}

if (nOfCandle>Bars)
{
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++;
}

{
}

{
string B="بزرگ";
}
{
string M="متوسط";
}
{
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);
}
//+------------------------------------------------------------------+
```