//+------------------------------------------------------------------+
//| MACD_Arrows.mq4 |
//| Copyright 2023, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2023, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Green
double UpArrowBuffer[];
double DownArrowBuffer[];
double MACDBuffer[];
int OnInit()
{
SetIndexStyle(0, DRAW_LINE);
SetIndexStyle(1, DRAW_ARROW);
SetIndexStyle(2, DRAW_ARROW);
SetIndexArrow(1, 241); // 241 is the code for an up arrow
SetIndexArrow(2, 242); // 242 is the code for a down arrow
SetIndexBuffer(0, MACDBuffer);
SetIndexBuffer(1, UpArrowBuffer);
SetIndexBuffer(2, DownArrowBuffer);
IndicatorShortName("MACD Arrows");
return(INIT_SUCCEEDED);
}
int start()
{
int rates_total = Bars;
int prev_calculated = IndicatorCounted();
int limit = rates_total - prev_calculated;
if(prev_calculated > 0)
limit++;
for(int i = 0; i < limit; i++)
{
int index = rates_total - i - 1;
MACDBuffer[index] = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, index);
double diff = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, index) - iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, index);
double prev_diff = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, index + 1) - iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, index + 1);
UpArrowBuffer[index] = EMPTY_VALUE;
DownArrowBuffer[index] = EMPTY_VALUE;
if(MACDBuffer[index] < 0 && diff > 0 && prev_diff <= 0)
UpArrowBuffer[index] = MACDBuffer[index] + 0.0001;
if(MACDBuffer[index] > 0 && diff < 0 && prev_diff >= 0)
DownArrowBuffer[index] = MACDBuffer[index] - 0.0001;
}
return(0);
}
//+------------------------------------------------------------------+
这是源码 |