Download MetaTrader 5

Help with Indicator- New to programming

To add comments, please log in or register
Find out how to install MetaTrader on Linux
Matthew Hull
608
Matthew Hull 2016.01.12 21:46 

Hello, I am trying to code an indicator that draws a line of the average movement in pips. I don't know what function to use to return the applied price; Please have a look at my code below. I appreciate your help

//+------------------------------------------------------------------+

//|                                              AverageMovement.mq4 |

//|                        Copyright 2015, MetaQuotes Software Corp. |

//|                                             https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "Matt"

#property link      "https://www.mql5.com"

#property version   "1.00"

#property strict

//#property indicator_chart_window

 

#property indicator_separate_window

//#property indicator_chart_window

 

#property indicator_buffers 2


#property indicator_level1     3.0

#property indicator_level2     -3.0

#property indicator_level3     0.0

#property indicator_levelcolor clrDarkGray

#property indicator_levelstyle STYLE_DOT

 #property indicator_width1 0

#property indicator_width2 0

  #property indicator_color1 Red//wick

#property indicator_color2 Blue//wick

#include <WinUser32.mqh>


//---- stoch settings

extern string AM_SetUp   =  "------< AM_SetUP >------";

extern ENUM_APPLIED_PRICE applied_price     = PRICE_CLOSE;

extern int Y_Bars_check = 5;

 

 


//---- buffers

double AverageMovement[];


//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int init()

{

//---- indicators

 

IndicatorBuffers(1);

SetIndexBuffer(0,AverageMovement);

   

SetIndexStyle(0,DRAW_LINE,0,0);  

 

return(0);

}


//+------------------------------------------------------------------+

 



//+------------------------------------------------------------------+

 

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int start()

{

for(int i=0  ; i<=MathMax(Bars-1-IndicatorCounted(),1); i++)

{

double ma1 = iCustom(Symbol(),0, applied_price ,i);

double ma2 = iCustom(Symbol(),0, applied_price ,i+Y_Bars_check);

 

 

 AverageMovement[i] =NormalizeDouble( MathAbs((ma1 -ma2) /MathAbs(i-( i+Y_Bars_check))),Digits)*10000  ;

 

  

}

return(0);

}

//+------------------------------------------------------------------+ 

Automated Trading and Strategy Testing
Automated Trading and Strategy Testing
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
To add comments, please log in or register