0% found this document useful (0 votes)
137 views3 pages

Macd Arrows

This document is a code for a MACD Arrows indicator, which displays buy and sell signals based on the crossing of MACD and Signal lines. It includes customizable parameters for EMAs and alerts, and it uses buffers to plot arrows on the chart. The indicator is designed to provide visual cues for trading decisions in financial markets.

Uploaded by

baskeniboy7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
137 views3 pages

Macd Arrows

This document is a code for a MACD Arrows indicator, which displays buy and sell signals based on the crossing of MACD and Signal lines. It includes customizable parameters for EMAs and alerts, and it uses buffers to plot arrows on the chart. The indicator is designed to provide visual cues for trading decisions in financial markets.

Uploaded by

baskeniboy7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

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

//| MACD Arrows |


//| Modified from original CCI Arrows |
//+------------------------------------------------------------------+
#property copyright "Modified from EarnForex's CCI Arrows"
#property version "1.00"

#property description "MACD arrows based on the crossing of MACD and Signal lines."
#property description "Displays red and blue arrows for Short and Long signals."

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2
#property indicator_color1 clrBlue
#property indicator_type1 DRAW_ARROW
#property indicator_width1 2
#property indicator_color2 clrRed
#property indicator_type2 DRAW_ARROW
#property indicator_width2 2

enum enum_candle_to_check
{
Current,
Previous
};

// MACD parameters
input int Fast_EMA = 12; // Fast EMA Period
input int Slow_EMA = 26; // Slow EMA Period
input int Signal_SMA = 9; // Signal SMA Period
input bool EnableNativeAlerts = false;
input bool EnableEmailAlerts = false;
input bool EnablePushAlerts = false;
input enum_candle_to_check TriggerCandle = Previous;

double dUpMACDBuffer[];
double dDownMACDBuffer[];

int myMACD;

int LastAlertDirection;
datetime LastAlertTime;
bool FirstRun;

void OnInit()
{
FirstRun = true;
LastAlertDirection = 0;
LastAlertTime = D'01.01.1970';

IndicatorSetString(INDICATOR_SHORTNAME, "MACD Arrows (" +


IntegerToString(Fast_EMA) + "," + IntegerToString(Slow_EMA) + "," +
IntegerToString(Signal_SMA) + ")");

SetIndexBuffer(0, dUpMACDBuffer, INDICATOR_DATA);


SetIndexBuffer(1, dDownMACDBuffer, INDICATOR_DATA);

ArraySetAsSeries(dUpMACDBuffer, true);
ArraySetAsSeries(dDownMACDBuffer, true);
PlotIndexSetInteger(0, PLOT_ARROW, 233);
PlotIndexSetInteger(1, PLOT_ARROW, 234);

PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, 0.0);


PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, 0.0);

PlotIndexSetString(0, PLOT_LABEL, "MACD Buy");


PlotIndexSetString(1, PLOT_LABEL, "MACD Sell");

myMACD = iMACD(NULL, 0, Fast_EMA, Slow_EMA, Signal_SMA, PRICE_CLOSE);


}

int OnCalculate(const int rates_total,


const int prev_calculated,
const datetime &Time[],
const double &open[],
const double &High[],
const double &Low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
ArraySetAsSeries(High, true);
ArraySetAsSeries(Low, true);
ArraySetAsSeries(Time, true);

int counted_bars = prev_calculated;


if (counted_bars > 0) counted_bars--;
int limit = rates_total - 1 - counted_bars;

double MACDBuffer[];
double SignalBuffer[];
CopyBuffer(myMACD, 0, 0, rates_total, MACDBuffer); // MACD line
CopyBuffer(myMACD, 1, 0, rates_total, SignalBuffer); // Signal line
ArraySetAsSeries(MACDBuffer, true);
ArraySetAsSeries(SignalBuffer, true);

if (limit == 1) limit++; // Always redraw latest two bars.


for (int i = 0; i < limit; i++)
{
dUpMACDBuffer[i] = 0;
dDownMACDBuffer[i] = 0;

double MACDnow = MACDBuffer[i];


double MACDprev = MACDBuffer[i + 1];
double Signalnow = SignalBuffer[i];
double Signalprev = SignalBuffer[i + 1];

// Bullish crossover (MACD crosses above Signal)


if ((MACDnow > Signalnow) && (MACDprev <= Signalprev))
{
double distance = (High[iHighest(Symbol(), Period(), MODE_HIGH, 20, i)]
- Low[iLowest(Symbol(), Period(), MODE_LOW, 20, i)]) * 0.02;
dUpMACDBuffer[i] = Low[i] - 2 * distance;
}

// Bearish crossover (MACD crosses below Signal)


if ((MACDnow < Signalnow) && (MACDprev >= Signalprev))
{
double distance = (High[iHighest(Symbol(), Period(), MODE_HIGH, 20, i)]
- Low[iLowest(Symbol(), Period(), MODE_LOW, 20, i)]) * 0.02;
dDownMACDBuffer[i] = High[i] + 2 * distance;
}
}

if ((!FirstRun) && ((EnableNativeAlerts) || (EnableEmailAlerts) ||


(EnablePushAlerts)))
{
if (((TriggerCandle > 0) && (Time[0] > LastAlertTime)) || (TriggerCandle ==
0))
{
string Text;
// Up arrow alert
if ((dUpMACDBuffer[TriggerCandle] != 0) && (LastAlertDirection != 1))
{
Text = "MACD Up Arrow";
if (EnableNativeAlerts) Alert(Text);
Text = "MACD Arrows: " + Symbol() + " - " +
StringSubstr(EnumToString((ENUM_TIMEFRAMES)Period()), 7) + " - " + Text + ".";
if (EnableEmailAlerts) SendMail("MACD Arrows Alert", Text);
if (EnablePushAlerts) SendNotification(Text);
LastAlertTime = Time[0];
LastAlertDirection = 1;
}
// Down arrow alert
if ((dDownMACDBuffer[TriggerCandle] != 0) && (LastAlertDirection != -
1))
{
Text = "MACD Down Arrow";
if (EnableNativeAlerts) Alert(Text);
Text = "MACD Arrows: " + Symbol() + " - " +
StringSubstr(EnumToString((ENUM_TIMEFRAMES)Period()), 7) + " - " + Text + ".";
if (EnableEmailAlerts) SendMail("MACD Arrows Alert", Text);
if (EnablePushAlerts) SendNotification(Text);
LastAlertTime = Time[0];
LastAlertDirection = -1;
}
}
}

FirstRun = false;

return rates_total;
}
//+------------------------------------------------------------------+

You might also like