114 lines
No EOL
4.9 KiB
MQL4
114 lines
No EOL
4.9 KiB
MQL4
//+------------------------------------------------------------------+
|
|
//| acm_common.mqh |
|
|
//| Copyright 2025, Anderson Mourão |
|
|
//| https://mql5.com |
|
|
//| 15.09.2025 - Initial release |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2025, Anderson Mourão"
|
|
#property link "https://mql5.com"
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| defines |
|
|
//+------------------------------------------------------------------+
|
|
|
|
// #define MacrosHello "Hello, world!"
|
|
// #define MacrosYear 2025
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| DLL imports |
|
|
//+------------------------------------------------------------------+
|
|
|
|
// #import "user32.dll"
|
|
// int SendMessageA(int hWnd,int Msg,int wParam,int lParam);
|
|
// #import "my_expert.dll"
|
|
// int ExpertRecalculate(int wParam,int lParam);
|
|
// #import
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| EX5 imports |
|
|
//+------------------------------------------------------------------+
|
|
|
|
// #import "stdlib.ex5"
|
|
// string ErrorDescription(int error_code);
|
|
// #import
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Global variables |
|
|
//+------------------------------------------------------------------+
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Functions |
|
|
//+------------------------------------------------------------------+
|
|
|
|
void SetChartProperties()
|
|
{
|
|
//--- set chart properties
|
|
ChartSetInteger(0, CHART_SHOW_TICKER, true); // Display a symbol ticker in the upper left corner. Setting CHART_SHOW_TICKER to 'false' also sets CHART_SHOW_OHLC to 'false' and disables OHLC
|
|
ChartSetInteger(0, CHART_SHOW_OHLC, true); // Display OHLC values in the upper left corner. Setting CHART_SHOW_OHLC to 'true' also sets CHART_SHOW_TICKER to 'true' and enables the ticker
|
|
ChartSetInteger(0, CHART_SHOW_BID_LINE, true); // Display Bid values as a horizontal line in a chart
|
|
ChartSetInteger(0, CHART_SHOW_ASK_LINE, true); // Display Ask values as a horizontal line in a chart
|
|
ChartSetInteger(0, CHART_SHOW_LAST_LINE, true); // Display Last values as a horizontal line in a chart
|
|
ChartSetInteger(0, CHART_SHOW_PERIOD_SEP, false); // Remove vertical separators between adjacent periods
|
|
ChartSetInteger(0, CHART_SHOW_GRID, false); // Remove grid in the chart
|
|
ChartSetInteger(0, CHART_SHOW_VOLUMES, false); // Remove volume in the chart
|
|
}
|
|
|
|
double Media(int intervalo = 14, ENUM_APPLIED_PRICE applied_price = PRICE_WEIGHTED)
|
|
{
|
|
double dMA[1] = {0.0};
|
|
int ma_handle = iMA(_Symbol, _Period, intervalo, 0, MODE_SMA, applied_price);
|
|
CopyBuffer(ma_handle, 0, 0, 1, dMA);
|
|
IndicatorRelease(ma_handle);
|
|
// double close_price = iClose(_Symbol, _Period, 0);
|
|
return (NormalizeDouble(dMA[0], _Digits));
|
|
}
|
|
|
|
double Atr(int intervalo = 14)
|
|
{
|
|
double dATR[1] = {0.0};
|
|
int atr_handle = iATR(_Symbol, _Period, intervalo);
|
|
CopyBuffer(atr_handle, 0, 0, 1, dATR);
|
|
IndicatorRelease(atr_handle);
|
|
double close_price = iClose(_Symbol, _Period, 0);
|
|
return (NormalizeDouble(MathAbs(close_price - dATR[0]), _Digits));
|
|
}
|
|
|
|
double nAtr(int intervalo = 14)
|
|
{
|
|
// nTR := ((HIGH - LOW) + ABS(CLOSE - OPEN)) * 0.5;
|
|
// aTR := Media(iMl,nTR);
|
|
double dHigh[1] = {0.0};
|
|
double dLow[1] = {0.0};
|
|
double dClose[1] = {0.0};
|
|
double dOpen[1] = {0.0};
|
|
int ma_handle = 0;
|
|
|
|
ma_handle = iMA(_Symbol, _Period, intervalo, 0, MODE_SMA, PRICE_HIGH);
|
|
CopyBuffer(ma_handle, 0, 0, 1, dHigh);
|
|
IndicatorRelease(ma_handle);
|
|
|
|
ma_handle = iMA(_Symbol, _Period, intervalo, 0, MODE_SMA, PRICE_LOW);
|
|
CopyBuffer(ma_handle, 0, 0, 1, dLow);
|
|
IndicatorRelease(ma_handle);
|
|
|
|
ma_handle = iMA(_Symbol, _Period, intervalo, 0, MODE_SMA, PRICE_OPEN);
|
|
CopyBuffer(ma_handle, 0, 0, 1, dOpen);
|
|
IndicatorRelease(ma_handle);
|
|
|
|
ma_handle = iMA(_Symbol, _Period, intervalo, 0, MODE_SMA, PRICE_CLOSE);
|
|
CopyBuffer(ma_handle, 0, 0, 1, dClose);
|
|
IndicatorRelease(ma_handle);
|
|
|
|
// double high_price = iHigh(_Symbol, _Period, 0);
|
|
// double low_price = iLow(_Symbol, _Period, 0);
|
|
double close_price = iClose(_Symbol, _Period, 0);
|
|
// double open_price = iOpen(_Symbol, _Period, 0);
|
|
|
|
double nTR = ((dHigh[0] - dLow[0]) + MathAbs(dClose[0] - dOpen[0])) * 0.5;
|
|
|
|
return (NormalizeDouble(MathAbs(close_price - nTR), _Digits));
|
|
// double true_range = MathMax(MathMax(high_price - low_price, MathAbs(high_price - close_price)), MathAbs(low_price - close_price));
|
|
// int ma_handle = iMA(_Symbol, _Period, intervalo, 0, MODE_SMA, PRICE_HIGH);
|
|
// CopyBuffer(ma_handle, 0, 0, 1, dMA);
|
|
// IndicatorRelease(ma_handle);
|
|
} |