Inserted Code
//+------------------------------------------------------------------+
//| Indicator: MACD_Zero_Cross.mq4 |
//+------------------------------------------------------------------+
#property description "https://www.forexfactory.com/thread/post/15243194#post15243194"
#include <stdlib.mqh>
#include <stderror.mqh>
//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 1
#property strict
input int BarsBack = 180;
input int Fast_EMA = 12; // Fast EMA
input int Slow_EMA = 26; // Slow EMA
input int MACD_SMA = 9; // Signal SMA
int PLOT_MAXIMUM_BARS_BACK =BarsBack;
#define OMIT_OLDEST_BARS 50
//--- indicator buffers
double MacdLine[];
#define ObjPrefix "@FxArt.Trader_"
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
IndicatorBuffers(1);
int ibuf = 0;
SetIndexBuffer(ibuf,MacdLine);
SetIndexStyle(ibuf,DRAW_NONE);
SetIndexEmptyValue(ibuf, EMPTY_VALUE);
SetIndexDrawBegin(ibuf, MathMax(Bars(Symbol(), PERIOD_CURRENT)-PLOT_MAXIMUM_BARS_BACK+1, OMIT_OLDEST_BARS+1));
SetIndexLabel(ibuf,"");
//---
ObjectsDeleteAll(0,ObjPrefix,-1,-1);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
ObjectsDeleteAll(0,ObjPrefix,-1,-1);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
int limit = rates_total - prev_calculated;
//--- counting from 0 to rates_total
ArraySetAsSeries(MacdLine, true);
ArraySetAsSeries(time, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
//--- initial zero
if(prev_calculated < 1)
{
ArrayInitialize(MacdLine, EMPTY_VALUE);
}
else
limit++;
//--- main loop
for(int i = limit-1; i >= 0; i--)
{
if (i >= MathMin(PLOT_MAXIMUM_BARS_BACK-1, rates_total-1-OMIT_OLDEST_BARS)) continue; //omit some old rates to prevent "Array out of range" or slow calculation
MacdLine[i] = iMACD(NULL, PERIOD_CURRENT, Fast_EMA, Slow_EMA, MACD_SMA, PRICE_CLOSE, MODE_MAIN, i);
int tsh = 2; //time Shift
//MACD crosses above
if(MacdLine[i+1] > 0 && MacdLine[i+2] < 0 //MACD crosses above fixed value
)
{
CreateVLine(string(time[i+1]), clrRoyalBlue, STYLE_DOT, 1, true, time[i+1],"Buy");
CreateTrendLine("H_"+string(time[i+1]), clrRoyalBlue, STYLE_DOT, 3, true, time[i+1], high[i+1], time[i+1]+(time[0]-time[tsh]), high[i+1], "High");
CreateTrendLine("L_"+string(time[i+1]), clrIndianRed, STYLE_DOT, 3, true, time[i+1], low[i+1], time[i+1]+(time[0]-time[tsh]), low[i+1], "Low");
}
//MACD crosses below
if(MacdLine[i+1] < 0 && MacdLine[i+2] > 0 //MACD crosses below fixed value
)
{
CreateVLine(string(time[i+1]), clrIndianRed, STYLE_DOT, 1, true, time[i+1],"Sell");
CreateTrendLine("H_"+string(time[i+1]), clrRoyalBlue, STYLE_DOT, 3, true, time[i+1], high[i+1], time[i+1]+(time[0]-time[tsh]), high[i+1], "High");
CreateTrendLine("L_"+string(time[i+1]), clrIndianRed, STYLE_DOT, 3, true, time[i+1], low[i+1], time[i+1]+(time[0]-time[tsh]), low[i+1], "Low");
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|Create VLine |
//+------------------------------------------------------------------+
void CreateVLine(string objName, color cl, ENUM_LINE_STYLE st, int wd, int back, datetime t1, string tooltip)
{
string name = ObjPrefix + objName;
if(ObjectFind(0,name)<0)
{
ObjectCreate(0,name,OBJ_VLINE,0,t1,0);
ObjectSetInteger(0,name,OBJPROP_COLOR,cl);
ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
ObjectSetInteger(0,name,OBJPROP_STYLE,st);
ObjectSetInteger(0,name,OBJPROP_WIDTH,wd);
ObjectSetInteger(0,name,OBJPROP_BACK,back);
ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
ObjectSetInteger(0,name,OBJPROP_SELECTED,false);
ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
ObjectSetInteger(0,name,OBJPROP_TIME,0,t1);
ObjectSetString(0,name,OBJPROP_TOOLTIP,tooltip);
}
else
{
ObjectSetInteger(0,name,OBJPROP_TIME,0,t1);
}
}
//+------------------------------------------------------------------+
//| CreateTrendLine |
//+------------------------------------------------------------------+
void CreateTrendLine(string objName, color cl, ENUM_LINE_STYLE st, int wd, int back,
datetime t1, double price1, datetime t2, double price2, string tooltip)
{
string name = ObjPrefix + objName;
if(ObjectFind(0,name) < 0)
{
ObjectCreate(0, name, OBJ_TREND, 0, t1, price1, t2, price2);
ObjectSetInteger(0, name, OBJPROP_COLOR, cl);
ObjectSetInteger(0, name, OBJPROP_STYLE, st);
ObjectSetInteger(0, name, OBJPROP_WIDTH, wd);
ObjectSetInteger(0, name, OBJPROP_BACK, back);
ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, name, OBJPROP_SELECTED, false);
ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
ObjectSetInteger(0,name, OBJPROP_RAY_RIGHT,false);
ObjectSetString(0, name, OBJPROP_TOOLTIP, tooltip);
}
else
{
ObjectSetInteger(0, name, OBJPROP_TIME, 0, t1);
ObjectSetDouble(0, name, OBJPROP_PRICE, 0, price1);
ObjectSetInteger(0, name, OBJPROP_TIME, 1, t2);
ObjectSetDouble(0, name, OBJPROP_PRICE, 1, price2);
}
} Theory of Everything is Liquidity...https://www.youtube.com/@FxArt.Trader