MQL4 Biggest body between last 20 candle - page 2

To add comments, please log in or register
Simon Gniadkowski
17644
Simon Gniadkowski  
mostafa:

Hello Guys,

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

'(' - function definition unexpected


What does this mean ?

if (Totaldarsad>=40 , Totaldarsad<60)
mostafalotfi
184
mostafalotfi  
RaptorUK:

What does this mean ?


Hi Rapatork

i fixed my issue,

string X;
if (Totaldarsad>=60) X="بزرگ";if (Totaldarsad<60 && Totaldarsad>=40) X="متوسط";if (Totaldarsad<40) X="کوچک";

i used some thing like this :)

now it works :) now i want to work on some other idea that i need for my strategy

//+------------------------------------------------------------------+
//|                                                         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);
   
}   
string X;
if (Totaldarsad>=60) X="بزرگ";if (Totaldarsad<60 && Totaldarsad>=40) X="متوسط";if (Totaldarsad<40) X="کوچک";

  Comment("\n   اندازه بدنه کندل مورد ارزيابي ","   ",badaneh,"\n   :اندازه بدنه کندل مورد ارزيابي ","   ",badaneh2,"\n","\n","\n   :اندازي بدنه کندل مبنا","   ",MaxBody,"\n   :شماره بزرگترين کندل محيط","   ",MaxN,"\n   :نسبت بدنه کندل مورد ارزيابي به بدنه مبنا","   ",Totaldarsad,"\n","\n","   نوع کندل","   ",X);
  
    
//----
   return(0);
  }
  
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
Comment("");   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
mostafalotfi
184
mostafalotfi  

Hello Guys

i tried to add the below line to my expert, but i dono why the result is not correct on the chart

}
double TL;
double LL;   
string X;
if (Totaldarsad>=60) X="بزرگ";if (Totaldarsad<60 && Totaldarsad>=40) X="متوسط";if (Totaldarsad<40) X="کوچک";

if (Totaldarsad>=60 && badaneh2>0) TL=High [q];LL=(Open [q]+(0.75*(badaneh2*Point)));
if (Totaldarsad>=60 && badaneh>0) LL=Low [q];TL=(Close [q]+(0.25*(badaneh*Point)));

if (Totaldarsad<=60 && Totaldarsad>=40 && badaneh2>0) TL=High [q];LL=(Open [q]+(0.5*(badaneh2*Point)));
if (Totaldarsad<=60 && Totaldarsad>=40 && badaneh>0) LL=Low [q];TL=(Close [q]+(0.5*(badaneh*Point)));

if (Totaldarsad<39 && badaneh2>0) TL=High [q]; LL=Low[q];
if (Totaldarsad<39 && badaneh>0) LL=Low [q]; TL=High[q]; 
Simon Gniadkowski
17644
Simon Gniadkowski  
mostafa:

Hello Guys

i tried to add the below line to my expert, but i dono why the result is not correct on the chart

Why is all your code in init() ? did you want it to run only once ? if that is the case make it a script and put your code in start() . . .
mostafalotfi
184
mostafalotfi  
RaptorUK:
Why is all your code in init() ? did you want it to run only once ? if that is the case make it a script and put your code in start() . . .


:) I just start to learn coding yesterday :D i know i made lots of mess .. but i will improve it:D

actually yes i want to run this code only one time every week on Sunday afternoon, thanks for advise for using Script.

could you please let me know the above code that is correct or not? for calculating the TL (top level) and LL (low level)

Simon Gniadkowski
17644
Simon Gniadkowski  
mostafa:


:) I just start to learn coding yesterday :D i know i made lots of mess .. but i will improve it:D

actually yes i want to run this code only one time every week on Sunday afternoon, thanks for advise for using Script.

could you please let me know the above code that is correct or not? for calculating the TL (top level) and LL (low level)

Yep I know, my questions are meant to help and guide you not to embarrass you .
mostafalotfi
184
mostafalotfi  

Hello guys

i solved my problem with below code

int big;
int medium;
int small;
double TL;
double LL;   
string X;
if (Totaldarsad>=60) X="بزرگ";if (Totaldarsad<60 && Totaldarsad>=40) X="متوسط";if (Totaldarsad<40) X="کوچک";
if (Totaldarsad>=60) big=1;if (Totaldarsad<60 && Totaldarsad>=40) medium=1;if (Totaldarsad<40) small=1;


if (big>=1 && badaneh2>0) TL=High [q];if (big>=1 && badaneh2>0)LL=(Open [q]+(0.75*(badaneh2*Point)));
if (big>=1 && badaneh>0) LL=Low [q];if (big>=1 && badaneh>0)TL=(Close [q]+(0.25*(badaneh*Point)));

if (small>=1 && badaneh2>0) TL=High [q];if (small>=1 && badaneh2>0) LL=Low[q];
if (small>=1 && badaneh>0) LL=Low [q];if (small>=1 && badaneh>0) TL=High[q];

if (medium >=1 && badaneh>0) LL=Low [q];if (medium >=1 && badaneh>0)TL=(Close [q]+(0.5*(badaneh*Point)));
if (medium >=1 && badaneh2>0) TL=High [q];if (medium >=1 && badaneh2>0)LL=(Open [q]+(0.5*(badaneh2*Point)));
mostafalotfi
184
mostafalotfi  

Dear RaptorUK / WHRoeder

i really appreciate your kind support :) i have to learn aloooot .... :D

Simon Gniadkowski
17644
Simon Gniadkowski  
mostafa:
Could you please tell me why i cannot use = in "if"? imagine if i want to say if(X=2 && Q>3) then something happen, like a trigger that only happen when X=2 and Q>3

You don't use = to say equal . . . you use == for example . . .

if (small == 1 && badaneh2 == 0)

. . . get in the habit of using spaces before and after == >= <= < > etc. when you get a zero divide error in a large piece of code you will be glad that you did, you will be able to search for space / space instead of just / which will find all your comments.

whroeder1
17954
whroeder1  
Don't use ints when you mean Boolean or multiple ints when you mean Enumeration.
int big;
int medium;
int small;
double TL;
double LL;   
string X;
if (Totaldarsad>=60) X="بزرگ";if (Totaldarsad<60 && Totaldarsad>=40) X="متوسط";if (Totaldarsad<40) X="کوچک";
if (Totaldarsad>=60) big=1;if (Totaldarsad<60 && Totaldarsad>=40) medium=1;if (Totaldarsad<40) small=1;

if (big>=1 && badaneh2>0) TL=High [q];if (big>=1 && badaneh2>0)LL=(Open [q]+(0.75*(badaneh2*Point)));
Use Boolean self documenting variable names and simplify your code
double TL;
double LL;   
string X;
bool isBig    = (Totaldarsad>=60);
bool isMedium = (Totaldarsad<60 && Totaldarsad>=40);
bool isSmall  = (Totaldarsad<40);
if (isBig)    X="بزرگ";
if (isMedium) X="متوسط";
if (isSmall)  X="کوچک";

if (isBig && badaneh2>0){
   TL=High [q];
   LL=(Open [q]+(0.75*(badaneh2*Point)));
}
Use self documenting Enumerations
   #define eSize_BIG    0
   #define eSize_MEDIUM 1
   #define eSize_SMALL  2
static string size2txt[] = { "بزرگ", "متوسط" ,"کوچک" }

int eSize;
if(     Totaldarsad>=60) esize = eSize_BIG;
else if(Totaldarsad>=40) esize = eSize_MEDIUM;
else                     eSize = eSize_SMALL;
string X = size2txt[eSize];

double TL;
double LL;
if (eSize == eSize_BIG && badaneh2>0){
   TL=High [q];
   LL=(Open [q]+(0.75*(badaneh2*Point)));
}
123
To add comments, please log in or register