indicator crossing

 

Hey Readers!

I am going through a problem. I want that when two indicators line crosses each other i should get an Alert.

The method i try was that  i get values of both indicators at  candle 1 and check that if the both values i get are equal or not but this method did not work because the indicators were of different scales.

On the screen when they cross each other they were having different values. So that's why i am here for help.

I will be very grateful if any reader can me guide to the right path.

Thanks!

 
The method i try was that  i get values of both indicators at  candle 1 and check that if the both values i get are equal or not but this method did not work because the indicators were of different scales.

If they are different scales then it is not possible to accurately define a cross.

It's like trying to log when 2 racing cars overtake each other when they are not driving on the same track.

 
GumRai:

If they are different scales then it is not possible to accurately define a cross.

It's like trying to log when 2 racing cars overtake each other when they are not driving on the same track.

 
ceaser234: On the screen when they cross each other they were having different values. I was trying to get the cross of DSS Bresert and CCI indicator.
If they cross on the screen they have the same scale, the scale of that window. But those two indicators have separate windows. Your post is contradictory.
 
WHRoeder:
If they cross on the screen they have the same scale, the scale of that window. But those two indicators have separate windows. Your post is contradictory.

Not necessarily true. In the sub-windows (not the main window), you can have two or more independent indicators (on the same sub-window) that by default differ in scale or range.

The exceptions, and thus a possible solution, is when you set the same "Fixed Minimum" and "Fixed Maximum" value for all the indicators in question, or when the "Apply to" of one indicator is based on the value of another (such as a moving average based on the value of a previous indicator).

Other than that, they will scale independently of each other, and hence, probably the difficulty the OP is having.

 
ceaser234:

Hey Readers!

I am going through a problem. I want that when two indicators line crosses each other i should get an Alert.

The method i try was that  i get values of both indicators at  candle 1 and check that if the both values i get are equal or not but this method did not work because the indicators were of different scales.

On the screen when they cross each other they were having different values. So that's why i am here for help.

I will be very grateful if any reader can me guide to the right path.

Thanks!

Hey Ceaser234!

It is my first reply to Mql4 Forum.

You can try the following method.

You first have to Fix Minimum and Fix Maximum of both indicators. Then u can get the difference of both indicators at the current candle by getting the values of both indi and then subtract them.Then add them.

Suppose if the value of CCI at current candle is  92.7845  and the value of DSS is 23.8952 then subtract them DSS-CCI=difference   then add difference to DSS and get the Alert.

I am not sure but may this method work.

 
William_paul:

Hey Ceaser234!

It is my first reply to Mql4 Forum.

You can try the following method.

You first have to Fix Minimum and Fix Maximum of both indicators. Then u can get the difference of both indicators at the current candle by getting the values of both indi and then subtract them.Then add them.

Suppose if the value of CCI at current candle is  92.7845  and the value of DSS is 23.8952 then subtract them DSS-CCI=difference   then add difference to DSS and get the Alert.

I am not sure but may this method work.

Thanks for the response but sorry william that will not work because when we will add this both values become equal.

If there is any other method then u can tell me.It will be helpful for learning.

 
ceaser234:

Thanks for the response but sorry william that will not work because when we will add this both values become equal.

If there is any other method then u can tell me.It will be helpful for learning.

You don't seem to be understanding the concept of the "Fixed Maximum" and "Fixed Minimum", so first off, let us get some things clear:

  1. Which Indicators are you using for detecting crosses?
  2. When you mention an Alert, to what are you referring?
  3. Are you coding your own indicator for the detecting the crosses or are you simply referring to the on-screen visualisation.
  4. If you are coding your own Indicator, then please post your code, otherwise we are not able to help you.
  5. Please post some screenshots as well so that we can better understand you.
 
FMIC:

You don't seem to be understanding the concept of the "Fixed Maximum" and "Fixed Minimum", so first off, let us get some things clear:

  1. Which Indicators are you using for detecting crosses?
  2. When you mention an Alert, to what are you referring?
  3. Are you coding your own indicator for the detecting the crosses or are you simply referring to the on-screen visualisation.
  4. If you are coding your own Indicator, then please post your code, otherwise we are not able to help you.
  5. Please post some screenshots as well so that we can better understand you.

1.I am using CCI and custom indicator StochRSI.

2.When i mention Alert i mean that when these indicators lines crosses each other i should get an alert.

3. I am using iCCI and iCustom functions to get the values of these indicators at  candle 1 and check whether these indicators values are equal or not.If equal then give me Alert.But this did not work due to different scales.

I have attatch the picture

.

 
  1. CCI and Stoch are not exactly compatible with each other. "Stoch" has a fixed range of 0-100 but CCI has a larger variable range of which the -100 to 100 range is considered significant. So the main question is:
    1. What is the range of values for CCI that you want to overlay over the 0 to 100 range of Stoch?
      If for example you want the values -200 to 200 of CCI to overlay on the 0-100 range of Stock, then Set the "Fixed Minimum" of CCI to -200 and the "Fixed Maximum" to 200, while on the "Stoch" if not already set by default, set the "Fixed Minimum" to 0 and the "Fixed Maximum" to 100.
  2. There are no "automatic" Alerts for indicator values or crosses, only for simple price changes. Alerts for indicator values or cross have to be coded (programmed with MQL4 Code). It cannot be simply created with the Alert Manager.
  3. If you say, that you are using "iCCI" and "iCustom", then that would suggest that you are using these in your own code and not just on the screen visually. If that is the case, then post your code for us to help.
 
FMIC:
  1. CCI and Stoch are not exactly compatible with each other. "Stoch" has a fixed range of 0-100 but CCI has a larger variable range of which the -100 to 100 range is considered significant. So the main question is:
    1. What is the range of values for CCI that you want to overlay over the 0 to 100 range of Stoch?
      If for example you want the values -200 to 200 of CCI to overlay on the 0-100 range of Stock, then Set the "Fixed Minimum" of CCI to -200 and the "Fixed Maximum" to 200, while on the "Stoch" if not already set by default, set the "Fixed Minimum" to 0 and the "Fixed Maximum" to 100.
  2. There are no "automatic" Alerts for indicator values or crosses, only for simple price changes. Alerts for indicator values or cross have to be coded (programmed with MQL4 Code). It cannot be simply created with the Alert Manager.
  3. If you say, that you are using "iCCI" and "iCustom", then that would suggest that you are using these in your own code and not just on the screen visually. If that is the case, then post your code for us to help.
void OnTick()
{

double  CCI2      = iCCI   (NULL,0,14,PRICE_CLOSE,2);          // value of CCI at  candle 2
double  StochRSI2 = iCustom(NULL,0,"StochRSI",14,14,9,2);      // value of StochRSI at candle 2
double  CCI1      = iCCI   (NULL,0,14,PRICE_CLOSE,1);          // value of CCI at  candle 1
double  StochRSI1 = iCustom(NULL,0,"StochRSI",14,14,9,1);      // value of StochRSI at candle 1

if(CCI2 == StochRSI2)           // check if there is a cross
{
Alert("There is a cross ");     // alert there is a cross
 if(CCI1 > StochRSI1)           // check after cross at candle 1 if cci is above StochRSI
 {
  Alert("Take buy trade");      // Alert take buy trade
 }
 else if(StochRSI1 > CCI1 )     // if upper condition is false check after cross at candle 1 if StochRSI is above CCI 
  {
  Alert("Take a sell trade");   // Alert take sell trade
  }  
 else
  {
   Alert(GetLastError());
  }   
}
else if ( CCI2 != StochRSI2 )
{
Alert("there is no cross");
}
else
{
Alert(GetLastError());
}
   
}

1.The range for CCI approximately will be -439.9512  to 385.5916.

and the range for StochRSI will be -5 to 105.


Reason: