Download MetaTrader 5

Is my code correct?

To add comments, please log in or register
frappemocha
26
frappemocha  

Hi, can someone help ? Can someone check if this code is correct? 

 

Description 

CCI A cross above 100

CCI B below 0

 

An alert should pop out when this 2 condition happen. 

 

 

 

#define UPPER_LEVEL     100

#define MIDDLE_LEVEL    0

#define LOWER_LEVEL    -100

#define INDICATOR_NAME "iCCIAlert"


   if( cci1[0] >= UPPER_LEVEL

       && cci2[0] <= MIDDLE_LEVEL && repeat )

   {

      SendInfo(INDICATOR_NAME, StringConcatenate(INDICATOR_NAME, " ", Symbol(), " ", TfToString(Period()), " Opportunity Alert "));

      repeat = false;

   }

   

   if( cci1[0] < UPPER_LEVEL || cci2[0] > MIDDLE_LEVEL )

      repeat = true; 

Irwan Adnan
925
Irwan Adnan  
frappemocha:

Hi, can someone help ? Can someone check if this code is correct? 

 


You can ask for help to debugger in your MetaEditor. It will tell you error(s) if any.
frappemocha
26
frappemocha  
Irwan Adnan:
You can ask for help to debugger in your MetaEditor. It will tell you error(s) if any.

 

I need help to see if the 1st cci cross above 100 and 2nd cci below 0 is correct or not?? Like this part


" if( cci1[0] >= UPPER_LEVEL

      && cci2[0] <= MIDDLE_LEVEL && repeat ) " 

Does it match to my description above?? 


And one more thing what does this code do?

"    if( cci1[0] < UPPER_LEVEL || cci2[0] > MIDDLE_LEVEL )

      repeat = true; " 

Icham Aidibe
10315
Icham Aidibe  
Usually when you're looking for a cross :
if ((cci[1] < level) && (cci[0] > level))
Depending on if your array is set (asseries or no) :
  • cci[0] being the last bar.
  • cci[1] being the last-second bar.

Then if you want to insure that cci2[lastbar=0] is in the same moment superior to mid level :

if ((cci[1] < upper_level) && (cci[0] > upper_level) && (cci2[0]>midlevel))
That last code line says : "The second bar reading from right to left is below the upper level AND the first bar reading from right to left is above the upper level (level crossed from a bar to another) AND the last bar from right to left of CCI2 is upper than the midlevel".

When you're using || you're meaning OR :

if ((repeat) || (!repeat))
Whatever repeat is set to : true OR to false ...
Irwan Adnan
925
Irwan Adnan  
frappemocha:

 

I need help to see if the 1st cci cross above 100 and 2nd cci below 0 is correct or not?? Like this part


" if( cci1[0] >= UPPER_LEVEL

      && cci2[0] <= MIDDLE_LEVEL && repeat ) " 

Does it match to my description above?? 


And one more thing what does this code do?

"    if( cci1[0] < UPPER_LEVEL || cci2[0] > MIDDLE_LEVEL )

      repeat = true; " 

No, it is not read as a cross. It is just say as when cci1 is above or equal to UPPER_LEVEL AND cci2 is less than or equal to MIDDLE_LEVEL AND repeat is TRUE then  DO sendinfo and also then set repeat to false.

 

The second one is to set variable repeat with "true" when cci1 less than upperlevel OR when cci2 more than middlelevel.

 

When you looking for a cross, then look Icham post above. 

To add comments, please log in or register