Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 75a0f76352 | |||
| 4f56445d60 | |||
| a23213f3e1 |
@@ -0,0 +1,134 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| MACD.mq5 |
|
||||
//| Copyright 2009, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "2009, MetaQuotes Software Corp."
|
||||
#property link "http://www.mql5.com"
|
||||
#property description "Moving Average Convergence/Divergence"
|
||||
#include <MovingAverages.mqh>
|
||||
//--- indicator settings
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 2
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color1 clrMagenta
|
||||
#property indicator_color2 clrBlue
|
||||
#property indicator_width1 2
|
||||
#property indicator_width2 2
|
||||
#property indicator_label1 "Main"
|
||||
#property indicator_label2 "Signal"
|
||||
//--- input parameters
|
||||
input int InpFastEMA=12; // Fast EMA period
|
||||
input int InpSlowEMA=26; // Slow EMA period
|
||||
input int InpSignalSMA=9; // Signal SMA period
|
||||
//--- indicator buffers
|
||||
//double ExtMacdBufferUp[];
|
||||
//double ExtMacdBufferDn[];
|
||||
double ExtSignalBuffer[];
|
||||
double ExtFastMaBuffer[];
|
||||
double ExtSlowMaBuffer[];
|
||||
double ExtMacdBuffer[];
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtMacdBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtSignalBuffer,INDICATOR_DATA);
|
||||
//SetIndexBuffer(2,ExtSignalBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(2,ExtFastMaBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(3,ExtSlowMaBuffer,INDICATOR_CALCULATIONS);
|
||||
//SetIndexBuffer(4,ExtMacdBuffer,INDICATOR_CALCULATIONS);
|
||||
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,InpSignalSMA-1);
|
||||
//--- name for Dindicator subwindow label
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"MACD("+string(InpFastEMA)+","+string(InpSlowEMA)+","+string(InpSignalSMA)+")");
|
||||
//--- initialization done
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Moving Averages Convergence/Divergence |
|
||||
//+------------------------------------------------------------------+
|
||||
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 &TickVolume[],
|
||||
const long &Volume[],
|
||||
const int &Spread[])
|
||||
{
|
||||
//
|
||||
// Precoess data through MedianRenko indicator
|
||||
//
|
||||
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,Time))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//--- check for data
|
||||
if(rates_total<InpSignalSMA)
|
||||
return(0);
|
||||
//--- we can copy not all data
|
||||
int to_copy;
|
||||
if(_prev_calculated>rates_total || _prev_calculated<0) to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-_prev_calculated;
|
||||
if(_prev_calculated>0) to_copy++;
|
||||
}
|
||||
//--- get Fast EMA buffer
|
||||
if(IsStopped()) return(0); //Checking for stop flag
|
||||
ExponentialMAOnBuffer(rates_total,_prev_calculated,0,InpFastEMA,customChartIndicator.Close,ExtFastMaBuffer);
|
||||
//--- get SlowSMA buffer
|
||||
if(IsStopped()) return(0); //Checking for stop flag
|
||||
ExponentialMAOnBuffer(rates_total,_prev_calculated,0,InpSlowEMA,customChartIndicator.Close,ExtSlowMaBuffer);
|
||||
//---
|
||||
int limit;
|
||||
if(_prev_calculated==0)
|
||||
limit=0;
|
||||
else limit=_prev_calculated-1;
|
||||
//--- calculate MACD
|
||||
for(int i=limit;i<rates_total && !IsStopped();i++)
|
||||
{
|
||||
ExtMacdBuffer[i] = ExtFastMaBuffer[i]-ExtSlowMaBuffer[i];
|
||||
/*
|
||||
if(ExtMacdBuffer[i] > 0)
|
||||
{
|
||||
ExtMacdBufferUp[i] = ExtFastMaBuffer[i]-ExtSlowMaBuffer[i];
|
||||
ExtMacdBufferDn[i] = 0;
|
||||
}
|
||||
else if(ExtMacdBuffer[i] < 0)
|
||||
{
|
||||
ExtMacdBufferDn[i] = ExtFastMaBuffer[i]-ExtSlowMaBuffer[i];
|
||||
ExtMacdBufferUp[i] = 0;
|
||||
}
|
||||
*/
|
||||
}
|
||||
//--- calculate Signal
|
||||
SimpleMAOnBuffer(rates_total,_prev_calculated,0,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer);
|
||||
//--- OnCalculate done. Return new _prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,188 @@
|
||||
#property copyright "Copyright 2018, AZ-iNVEST"
|
||||
#property link "http://www.az-invest.eu"
|
||||
#property version "1.01"
|
||||
#property indicator_separate_window
|
||||
#property indicator_plots 0
|
||||
|
||||
#include <AZ-INVEST/SDK/RangeBarIndicator.mqh>
|
||||
RangeBarIndicator customChartIndicator;
|
||||
|
||||
#define PREFIX_SEED "6D4E6"
|
||||
|
||||
static long __chartId = ChartID();
|
||||
static int __subWinId = ChartWindowFind();
|
||||
|
||||
enum ENUM_DISPLAY_FORMAT
|
||||
{
|
||||
DisplayFormat1 = 0, // 25 Jan 10:55
|
||||
DisplayFormat2, // 25.01 10:55
|
||||
};
|
||||
|
||||
input color InpTextColor = clrWhiteSmoke; // Font color
|
||||
input int InpFontSize = 9; // Font size
|
||||
input int InpSpacing = 8; // Date/Time spacing
|
||||
input ENUM_DISPLAY_FORMAT InpDispFormat = DisplayFormat1; // Display format
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"\n");
|
||||
IndicatorSetDouble(INDICATOR_MINIMUM,0);
|
||||
IndicatorSetDouble(INDICATOR_MAXIMUM,9);
|
||||
IndicatorSetInteger(INDICATOR_HEIGHT,28);
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,0);
|
||||
//---
|
||||
|
||||
customChartIndicator.SetGetTimeFlag();
|
||||
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
void OnDeinit(const int r)
|
||||
{
|
||||
ObjectsDeleteAll(__chartId,PREFIX_SEED);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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[])
|
||||
{
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time))
|
||||
return(0);
|
||||
|
||||
int start = customChartIndicator.GetPrevCalculated() - 1;
|
||||
//--- correct position
|
||||
if(start<0)
|
||||
start=0;
|
||||
|
||||
if((start == 0) || customChartIndicator.IsNewBar)
|
||||
{
|
||||
ObjectsDeleteAll(__chartId,PREFIX_SEED);
|
||||
DrawTimeLine(0,rates_total,time);
|
||||
}
|
||||
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
|
||||
void DrawTimeLine(const int nPosition, const int nRatesCount, const datetime &canvasTime[])
|
||||
{
|
||||
datetime curBarTime = 0;
|
||||
bool _start = false;
|
||||
int c = 0;
|
||||
|
||||
for(int i=nPosition;i<nRatesCount;i++)
|
||||
{
|
||||
curBarTime = (datetime)customChartIndicator.Time[i];
|
||||
if(curBarTime == 0)
|
||||
continue;
|
||||
else
|
||||
_start = true;
|
||||
|
||||
if(c%InpSpacing == 0)
|
||||
DrawDateTimeMarker(i,curBarTime,canvasTime[i]);
|
||||
|
||||
if(_start)
|
||||
c++;
|
||||
}
|
||||
|
||||
ChartRedraw();
|
||||
}
|
||||
|
||||
bool DrawDateTimeMarker(const int ix, const datetime timeStamp, const datetime canvasTime)
|
||||
{
|
||||
if(timeStamp == 0)
|
||||
return false;
|
||||
|
||||
TextCreate(__chartId,PREFIX_SEED+(string)timeStamp,__subWinId,canvasTime,9,NormalizeTime(timeStamp),"Calibri",InpFontSize,InpTextColor);
|
||||
return true;
|
||||
}
|
||||
|
||||
string NormalizeTime(datetime _dt)
|
||||
{
|
||||
static string __months[12] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
|
||||
MqlDateTime dt;
|
||||
|
||||
TimeToStruct(_dt,dt);
|
||||
string minute = (dt.min<10) ? ("0"+(string)dt.min) : (string)dt.min;
|
||||
string hour = (dt.hour<10) ? ("0"+(string)dt.hour) : (string)dt.hour;
|
||||
|
||||
if(InpDispFormat == DisplayFormat1)
|
||||
return ( "'"+(string)dt.day+" "+__months[dt.mon-1]+" "+hour+":"+minute );
|
||||
else
|
||||
{
|
||||
string month = (dt.mon<10) ? ("0"+(string)dt.mon) : (string)dt.mon;
|
||||
return ( "'"+(string)dt.day+"."+month+" "+hour+":"+minute );
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// GUI wrapper function
|
||||
// https://www.mql5.com/en/docs/constants/objectconstants/enum_object/obj_text
|
||||
//
|
||||
|
||||
bool TextCreate(const long chart_ID=0, // chart's ID
|
||||
const string name="Text", // object name
|
||||
const int sub_window=0, // subwindow index
|
||||
datetime time=0, // anchor point time
|
||||
double price=0, // anchor point price
|
||||
const string text="Text", // the text itself
|
||||
const string font="Calibri", // font
|
||||
const int font_size=9, // font size
|
||||
const color clr=clrWhiteSmoke, // color
|
||||
const double angle=0.0, // text slope
|
||||
const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // anchor type
|
||||
const bool back=false, // in the background
|
||||
const bool selection=false, // highlight to move
|
||||
const bool hidden=true, // hidden in the object list
|
||||
const long z_order=0) // priority for mouse click
|
||||
{
|
||||
//--- reset the error value
|
||||
ResetLastError();
|
||||
//--- create Text object
|
||||
if(!ObjectCreate(chart_ID,name,OBJ_TEXT,sub_window,time,price))
|
||||
{
|
||||
Print(__FUNCTION__,": failed to create \"Text\" object! Error code = ",GetLastError());
|
||||
return(false);
|
||||
}
|
||||
//--- set the text
|
||||
ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
|
||||
//--- set text font
|
||||
ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
|
||||
//--- set font size
|
||||
ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
|
||||
//--- set the slope angle of the text
|
||||
ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);
|
||||
//--- set anchor type
|
||||
ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);
|
||||
//--- set color
|
||||
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
|
||||
//--- display in the foreground (false) or background (true)
|
||||
ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
|
||||
//--- enable (true) or disable (false) the mode of moving the object by mouse
|
||||
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
|
||||
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
|
||||
//--- hide (true) or display (false) graphical object name in the object list
|
||||
ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
|
||||
//--- set the priority for receiving the event of a mouse click in the chart
|
||||
ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
|
||||
//--- switch off tooltips
|
||||
ObjectSetString(chart_ID,name,OBJPROP_TOOLTIP,"\n");
|
||||
//--- successful execution
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user