Calculate the distance between two moving averages

 

Hi, I was in a form and still did not get the correct answer after the overall search.
I'm looking for a way to get the distance between the two pipelines between the two moving averages of 15 and 60
Is there anyone who can help me on this topic?
Thanks
Translated by Google Translator

//+------------------------------------------------------------------+
//|                                                  ghaderifar1.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
extern int MA1 = 15;
extern int MA2 = 60;
extern string Comment1 = "// 0 - PRICE_CLOSE, 1 - PRICE_OPEN, 2 - PRICE_HIGH, 3 - PRICE_LOW, 4 - PRICE_MEDIAN, 5 - PRICE_TYPICAL, 6 - PRICE_WEIGHTED";
extern int PriceType = 0;
extern string Comment2 = "// 0 - MODE_SMA, 1 - MODE_EMA, 2 - MODE_SMMA, 3 - MODE_LWMA";
extern int MA_MODE = 0;
extern int Tolerance = 5;
extern int Distance = 30;
extern double sVolume = 0.1;
extern int Tradepip = 92;
double MA11=iMA(NULL,0,MA1,0,MA_MODE,PriceType,0);
double MA22=iMA(NULL,0,MA2,0,MA_MODE,PriceType,0);
int pipsMAsell = (int)MathFloor( MathAbs(MA22-MA11)/(_Point) );
int pipsMAbuy = (int)MathFloor( MathAbs(MA11-MA22)/(_Point) );
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

   if( pipsMAbuy == Tradepip && Close[0]>MA11 && MA22>MA11)
   {
   
   Print("buy");
   
   }
   else if(pipsMAsell == Tradepip && Close[0]<MA11 && MA22<MA11)
          {
          
           Print("sell");
           
          }
   
  }
//+------------------------------------------------------------------+
 
aliebnehosseini: I'm looking for a way to get the distance between the two pipelines between the two moving averages of 15 and 60 Is there anyone who can help me on this topic?
  1. Help you with what? You already have the code.
  2. int pipsMAsell = (int)MathFloor( MathAbs(MA22-MA11)/(_Point) );
    A point is not a pip.
              What is a TICK? - MQL4 and MetaTrader 4 - MQL4 programming forum

  3. It is unlikely that the differences will be exactly your Tradepip. What if they are larger?
 
whroeder1:
  1. Help you with what? You already have the code.
  2. A point is not a pip.
              What is a TICK? - MQL4 and MetaTrader 4 - MQL4 programming forum

  3. It is unlikely that the differences will be exactly your Tradepip. What if they are larger?

hi whroeder1

Yes I found the code but it does not work.
My intention is, when the distance between the moving average of 15 and 60 is 20 pips, expert will begin to buy or sell, look carefully at the picture.

sorry i cannot speak english very well.


 
The wheel you're trying to reinvent is called MACD or Awesome Oscillator.
 
//+------------------------------------------------------------------+
//|                                                  ghaderifar1.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
extern int MA1 = 15;
extern int MA2 = 60;
extern string Comment1 = "// 0 - PRICE_CLOSE, 1 - PRICE_OPEN, 2 - PRICE_HIGH, 3 - PRICE_LOW, 4 - PRICE_MEDIAN, 5 - PRICE_TYPICAL, 6 - PRICE_WEIGHTED";
extern int PriceType = 0;
extern string Comment2 = "// 0 - MODE_SMA, 1 - MODE_EMA, 2 - MODE_SMMA, 3 - MODE_LWMA";
extern int MA_MODE = 0;
extern int Tolerance = 5;
extern int Distance = 30;
extern double sVolume = 0.1;
extern int Tradepip = 92;
double MA11, MA22;
int pipsMAsell, pipsMAbuy;
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   MA11=iMA(NULL,0,MA1,0,MA_MODE,PriceType,0);
   MA22=iMA(NULL,0,MA2,0,MA_MODE,PriceType,0);
   pipsMAsell = (int)MathFloor( MathAbs(MA22-MA11)/(_Point) );
   pipsMAbuy = (int)MathFloor( MathAbs(MA11-MA22)/(_Point) );

   if( pipsMAbuy == Tradepip && Close[0]>MA11 && MA22>MA11)
   {
   
   Print("buy");
   
   }
   else if(pipsMAsell == Tradepip && Close[0]<MA11 && MA22<MA11)
          {
          
           Print("sell");
           
          }
   
  }
//+------------------------------------------------------------------+
 
What is the Close[0]  for ?
Reason: