Average of moving average difference

 

Hello!

 I would like to know how can I get average of moving average difference. I have this but not working.

for(int i=0; i<Bars; i++)  {
  double EUR_MA=iMA("EURUSD",0,1,0,MODE_SMA,PRICE_CLOSE,i);
  double GBP_MA=iMA("GBPUSD",0,1,0,MODE_SMA,PRICE_CLOSE,i);
    
  double diff =(GBP_MA-EUR_MA)/places/Point;  
  double ave_diff=(length+ave_diff)/Bars; // I know this is not ok, but don't have idea how to solve this.
}

 Any idea?

 
Do you know how an average is calculated?
 
Yes, SUM of ALL values/Number of values
 
01005379: Yes, SUM of ALL values/Number of values
  1. So where are you getting multiple values, summing and dividing?
  2. Or where are you putting the values in a buffer and using iMAOnArray to a secondary buffer? Like MACD
 
WHRoeder:
  1. So where are you getting multiple values, summing and dividing?
  2. Or where are you putting the values in a buffer and using iMAOnArray to a secondary buffer? Like MACD

Can you help me with the code, please? Thank you.
 
01005379: Can you help me with the code, please?
You have only three choices: Search for it, 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.
 
WHRoeder:
You have only three choices: Search for it,learnto 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) andthe nature of your problem.


If you read first post you'll see I did post my attempt via SRC.
 
01005379: If you read first post you'll see I did post my attempt via SRC.
What part of "post your attempt" was unclear?
 
WHRoeder:
What part of "post your attempt" was unclear?


How much do you want?
 
01005379: How much do you want?

The source code you have shown in your first post, cannot in any way be considered a true and serious attempt, because it seems to only convey just a short description of what you want to achieve, even though it makes very little sense at that.

When asked if you knew how a Moving Average is calculated, you responded by saying "SUM of ALL values/Number of values". However, that is not a moving average, that is just a normal single average value over the entire population of data, but even that simple task you did not do in your code and that is why WHRoeder asked where you were "getting the multiple values, summing and dividing" or where you were "putting the values in a buffer and using iMAOnArray to a secondary buffer", showing you that it is much more elaborate and not as simple as just a few lines of code that you presented.

So, since it is obvious that you don't know what a Moving Average is or how it is calculated, or how to make use of the indicator buffers, it is suggested to you that you:
  1. ... go do your research and learn some more about this subject by searching for relevant information and reading up the documentation and example code on this site or on others;
  2. ... or that you hire someone to code it for you or to mentor or teach you about this subject;
  3. ... or that you submit a serious attempt at coding this, but unfortunately, at this moment you do not have the knowledge for this, so you are left only with points 1 and 2.
 
for(int i=0; i<Bars; i++)  {
  double EUR_MA=iMA("EURUSD",0,1,0,MODE_SMA,PRICE_CLOSE,i);
  double GBP_MA=iMA("GBPUSD",0,1,0,MODE_SMA,PRICE_CLOSE,i);
    
  double diff =(GBP_MA-EUR_MA)/places/Point;  
  double ave_diff=(length+ave_diff)/Bars; // I know this is not ok, but don't have idea how to solve this.
}

We have no idea what the above highlighted variables are, where they get their values and why you are using them in your calculations.

As WHRoeder has already said.

Place values in a buffer, then use iMAOnArray() to calculate the average.

Your code assumes that Bars has the same value for both symbols. It also assumes that i will access the same time bar for both symbols. This may not be the case if there are missing bars for either symbol.