Indication Collection
Indication Collection
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
Binary file not shown.
@@ -0,0 +1,368 @@
|
||||
#property link "https://www.earnforex.com/"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
#property copyright "EarnForex.com - 2020"
|
||||
#property description ""
|
||||
#property description ""
|
||||
#property description ""
|
||||
#property description ""
|
||||
#property description "Find More on EarnForex.com"
|
||||
|
||||
#define OP_BUY 0 //Buy
|
||||
#define OP_SELL 1 //Sell
|
||||
#define OP_BUYLIMIT 2 //Pending order of BUY LIMIT type
|
||||
#define OP_SELLLIMIT 3 //Pending order of SELL LIMIT type
|
||||
#define OP_BUYSTOP 4 //Pending order of BUY STOP type
|
||||
#define OP_SELLSTOP 5 //Pending order of SELL STOP type
|
||||
//---
|
||||
#define MODE_OPEN 0
|
||||
#define MODE_CLOSE 3
|
||||
#define MODE_VOLUME 4
|
||||
#define MODE_REAL_VOLUME 5
|
||||
#define MODE_TRADES 0
|
||||
#define MODE_HISTORY 1
|
||||
#define SELECT_BY_POS 0
|
||||
#define SELECT_BY_TICKET 1
|
||||
//---
|
||||
#define DOUBLE_VALUE 0
|
||||
#define FLOAT_VALUE 1
|
||||
#define LONG_VALUE INT_VALUE
|
||||
//---
|
||||
#define CHART_BAR 0
|
||||
#define CHART_CANDLE 1
|
||||
//---
|
||||
#define MODE_ASCEND 0
|
||||
#define MODE_DESCEND 1
|
||||
//---
|
||||
#define MODE_LOW 1
|
||||
#define MODE_HIGH 2
|
||||
#define MODE_TIME 5
|
||||
#define MODE_BID 9
|
||||
#define MODE_ASK 10
|
||||
#define MODE_POINT 11
|
||||
#define MODE_DIGITS 12
|
||||
#define MODE_SPREAD 13
|
||||
#define MODE_STOPLEVEL 14
|
||||
#define MODE_LOTSIZE 15
|
||||
#define MODE_TICKVALUE 16
|
||||
#define MODE_TICKSIZE 17
|
||||
#define MODE_SWAPLONG 18
|
||||
#define MODE_SWAPSHORT 19
|
||||
#define MODE_STARTING 20
|
||||
#define MODE_EXPIRATION 21
|
||||
#define MODE_TRADEALLOWED 22
|
||||
#define MODE_MINLOT 23
|
||||
#define MODE_LOTSTEP 24
|
||||
#define MODE_MAXLOT 25
|
||||
#define MODE_SWAPTYPE 26
|
||||
#define MODE_PROFITCALCMODE 27
|
||||
#define MODE_MARGINCALCMODE 28
|
||||
#define MODE_MARGININIT 29
|
||||
#define MODE_MARGINMAINTENANCE 30
|
||||
#define MODE_MARGINHEDGED 31
|
||||
#define MODE_MARGINREQUIRED 32
|
||||
|
||||
enum ENUM_HOUR{
|
||||
h00=00, //00:00
|
||||
h01=01, //01:00
|
||||
h02=02, //02:00
|
||||
h03=03, //03:00
|
||||
h04=04, //04:00
|
||||
h05=05, //05:00
|
||||
h06=06, //06:00
|
||||
h07=07, //07:00
|
||||
h08=08, //08:00
|
||||
h09=09, //09:00
|
||||
h10=10, //10:00
|
||||
h11=11, //11:00
|
||||
h12=12, //12:00
|
||||
h13=13, //13:00
|
||||
h14=14, //14:00
|
||||
h15=15, //15:00
|
||||
h16=16, //16:00
|
||||
h17=17, //17:00
|
||||
h18=18, //18:00
|
||||
h19=19, //19:00
|
||||
h20=20, //20:00
|
||||
h21=21, //21:00
|
||||
h22=22, //22:00
|
||||
h23=23, //23:00
|
||||
};
|
||||
|
||||
ENUM_TIMEFRAMES TimeFrames[]={
|
||||
PERIOD_M1,
|
||||
PERIOD_M2,
|
||||
PERIOD_M3,
|
||||
PERIOD_M4,
|
||||
PERIOD_M5,
|
||||
PERIOD_M6,
|
||||
PERIOD_M10,
|
||||
PERIOD_M12,
|
||||
PERIOD_M15,
|
||||
PERIOD_M20,
|
||||
PERIOD_M30,
|
||||
PERIOD_H1,
|
||||
PERIOD_H2,
|
||||
PERIOD_H3,
|
||||
PERIOD_H4,
|
||||
PERIOD_H6,
|
||||
PERIOD_H8,
|
||||
PERIOD_H12,
|
||||
PERIOD_D1,
|
||||
PERIOD_W1,
|
||||
PERIOD_MN1
|
||||
};
|
||||
|
||||
|
||||
//Return the index of the requested time frame in the array TimeFrames
|
||||
int TimeFrameIndex(ENUM_TIMEFRAMES TimeFrame){
|
||||
int j=0;
|
||||
if(TimeFrame==PERIOD_CURRENT) TimeFrame=Period();
|
||||
for(int i=0;i<ArraySize(TimeFrames);i++){
|
||||
if(TimeFrame==TimeFrames[i]) return i;
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
//Check if the current time is within the period
|
||||
bool IsCurrentTimeInInterval(ENUM_HOUR Start,ENUM_HOUR End){
|
||||
if(Start==End && Hour()==Start) return true;
|
||||
if(Start<End && Hour()>=Start && Hour()<=End) return true;
|
||||
if(Start>End && ((Hour()>=Start && Hour()<=23) || (Hour()<=End && Hour()>=0))) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//Check if the software is over the date of use, throw a message and return true if it is
|
||||
bool UpdateCheckOver(string Name, datetime ExpiryDate, bool ShowAlert){
|
||||
if(TimeCurrent()>ExpiryDate){
|
||||
string EditText="Version Expired, This Product Must Be Updated";
|
||||
string AlertText="Version Expired, Please Download The New Version From MQL4TradingAutomation.com";
|
||||
DrawExpiry(Name,EditText);
|
||||
if(ShowAlert){
|
||||
Alert(AlertText);
|
||||
Print(AlertText);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
//Check if the software is over the warning date and throw a message if it is
|
||||
void UpdateCheckWarning(string Name, datetime WarnDate, datetime ExpDate, bool ShowAlert){
|
||||
if(TimeCurrent()>WarnDate){
|
||||
MqlDateTime WarningDate,ExpiryDate;
|
||||
TimeToStruct(WarnDate,WarningDate);
|
||||
TimeToStruct(ExpDate,ExpiryDate);
|
||||
string WarningDateStr=(string)ExpiryDate.day+"/"+(string)ExpiryDate.mon+"/"+(string)ExpiryDate.year;
|
||||
string EditText="This Product Version Will Stop Working On The "+WarningDateStr+"";
|
||||
string AlertText="This Product Version Will Stop Working On The "+WarningDateStr+", Please Download The New Version From MQL4TradingAutomation.com";
|
||||
DrawExpiry(Name,EditText);
|
||||
if(ShowAlert){
|
||||
Alert(AlertText);
|
||||
Print(AlertText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Draw a box to advise of the warning/expiry of the product
|
||||
void DrawExpiry(string Name, string Text){
|
||||
string TextBoxName=Name+"ExpirationTextBox";
|
||||
if(ObjectFind(0,TextBoxName)<0){
|
||||
DrawEdit(TextBoxName,20,20,300,20,true,8,"",ALIGN_CENTER,"Arial",Text,true,clrNavy,clrKhaki,clrBlack);
|
||||
}
|
||||
}
|
||||
|
||||
//Draw an edit box with the specified parameters
|
||||
void DrawEdit( string Name,
|
||||
int XStart,
|
||||
int YStart,
|
||||
int Width,
|
||||
int Height,
|
||||
bool ReadOnly,
|
||||
int EditFontSize,
|
||||
string Tooltip,
|
||||
int Align,
|
||||
string EditFont,
|
||||
string Text,
|
||||
bool Selectable,
|
||||
color TextColor=clrBlack,
|
||||
color BGColor=clrWhiteSmoke,
|
||||
color BDColor=clrBlack
|
||||
){
|
||||
|
||||
ObjectCreate(0,Name,OBJ_EDIT,0,0,0);
|
||||
ObjectSetInteger(0,Name,OBJPROP_XDISTANCE,XStart);
|
||||
ObjectSetInteger(0,Name,OBJPROP_YDISTANCE,YStart);
|
||||
ObjectSetInteger(0,Name,OBJPROP_XSIZE,Width);
|
||||
ObjectSetInteger(0,Name,OBJPROP_YSIZE,Height);
|
||||
ObjectSetInteger(0,Name,OBJPROP_BORDER_TYPE,BORDER_FLAT);
|
||||
ObjectSetInteger(0,Name,OBJPROP_STATE,false);
|
||||
ObjectSetInteger(0,Name,OBJPROP_HIDDEN,true);
|
||||
ObjectSetInteger(0,Name,OBJPROP_READONLY,ReadOnly);
|
||||
ObjectSetInteger(0,Name,OBJPROP_FONTSIZE,EditFontSize);
|
||||
ObjectSetString(0,Name,OBJPROP_TOOLTIP,Tooltip);
|
||||
ObjectSetInteger(0,Name,OBJPROP_ALIGN,Align);
|
||||
ObjectSetString(0,Name,OBJPROP_FONT,EditFont);
|
||||
ObjectSetString(0,Name,OBJPROP_TEXT,Text);
|
||||
ObjectSetInteger(0,Name,OBJPROP_SELECTABLE,Selectable);
|
||||
ObjectSetInteger(0,Name,OBJPROP_COLOR,TextColor);
|
||||
ObjectSetInteger(0,Name,OBJPROP_BGCOLOR,BGColor);
|
||||
ObjectSetInteger(0,Name,OBJPROP_BORDER_COLOR,BDColor);
|
||||
}
|
||||
|
||||
|
||||
string AccountCompany(){
|
||||
return AccountInfoString(ACCOUNT_COMPANY);
|
||||
}
|
||||
|
||||
|
||||
string AccountName(){
|
||||
return AccountInfoString(ACCOUNT_NAME);
|
||||
}
|
||||
|
||||
|
||||
long AccountNumber(){
|
||||
return AccountInfoInteger(ACCOUNT_LOGIN);
|
||||
}
|
||||
|
||||
string AccountCurrency(){
|
||||
return AccountInfoString(ACCOUNT_CURRENCY);
|
||||
}
|
||||
|
||||
double AccountBalance(){
|
||||
return AccountInfoDouble(ACCOUNT_BALANCE);
|
||||
}
|
||||
|
||||
double AccountEquity(){
|
||||
return AccountInfoDouble(ACCOUNT_EQUITY);
|
||||
}
|
||||
|
||||
double AccountFreeMargin(){
|
||||
return AccountInfoDouble(ACCOUNT_MARGIN_FREE);
|
||||
}
|
||||
|
||||
void SetIndex(int Index, int Type, int Style, int Width, int Color, string Label){
|
||||
PlotIndexSetInteger(Index,PLOT_DRAW_TYPE,Type);
|
||||
PlotIndexSetInteger(Index,PLOT_LINE_STYLE,Style);
|
||||
PlotIndexSetInteger(Index,PLOT_LINE_WIDTH,Width);
|
||||
PlotIndexSetInteger(Index,PLOT_LINE_COLOR,Color);
|
||||
PlotIndexSetString(Index,PLOT_LABEL,Label);
|
||||
}
|
||||
|
||||
int WindowFind(string Name){
|
||||
return ChartWindowFind(0,Name);
|
||||
}
|
||||
|
||||
string TimeFrameDescription(int TimeFrame){
|
||||
string PeriodDesc="";
|
||||
switch (TimeFrame){
|
||||
case PERIOD_M1:
|
||||
PeriodDesc="M1";
|
||||
break;
|
||||
case PERIOD_M2:
|
||||
PeriodDesc="M2";
|
||||
break;
|
||||
case PERIOD_M3:
|
||||
PeriodDesc="M3";
|
||||
break;
|
||||
case PERIOD_M4:
|
||||
PeriodDesc="M4";
|
||||
break;
|
||||
case PERIOD_M5:
|
||||
PeriodDesc="M5";
|
||||
break;
|
||||
case PERIOD_M6:
|
||||
PeriodDesc="M6";
|
||||
break;
|
||||
case PERIOD_M10:
|
||||
PeriodDesc="M10";
|
||||
break;
|
||||
case PERIOD_M12:
|
||||
PeriodDesc="M12";
|
||||
break;
|
||||
case PERIOD_M15:
|
||||
PeriodDesc="M15";
|
||||
break;
|
||||
case PERIOD_M20:
|
||||
PeriodDesc="M20";
|
||||
break;
|
||||
case PERIOD_M30:
|
||||
PeriodDesc="M30";
|
||||
break;
|
||||
case PERIOD_H1:
|
||||
PeriodDesc="H1";
|
||||
break;
|
||||
case PERIOD_H2:
|
||||
PeriodDesc="H2";
|
||||
break;
|
||||
case PERIOD_H3:
|
||||
PeriodDesc="H3";
|
||||
break;
|
||||
case PERIOD_H4:
|
||||
PeriodDesc="H4";
|
||||
break;
|
||||
case PERIOD_H6:
|
||||
PeriodDesc="H6";
|
||||
break;
|
||||
case PERIOD_H8:
|
||||
PeriodDesc="H8";
|
||||
break;
|
||||
case PERIOD_H12:
|
||||
PeriodDesc="H12";
|
||||
break;
|
||||
case PERIOD_D1:
|
||||
PeriodDesc="D1";
|
||||
break;
|
||||
case PERIOD_W1:
|
||||
PeriodDesc="W1";
|
||||
break;
|
||||
case PERIOD_MN1:
|
||||
PeriodDesc="MN1";
|
||||
break;
|
||||
}
|
||||
return PeriodDesc;
|
||||
}
|
||||
|
||||
|
||||
string OrderSymbol(){
|
||||
return OrderGetString(ORDER_SYMBOL);
|
||||
}
|
||||
|
||||
long OrderMagicNumber(){
|
||||
return OrderGetInteger(ORDER_MAGIC);
|
||||
}
|
||||
|
||||
double OrderStopLoss(){
|
||||
return OrderGetDouble(ORDER_SL);
|
||||
}
|
||||
|
||||
double OrderTakeProfit(){
|
||||
return OrderGetDouble(ORDER_TP);
|
||||
}
|
||||
|
||||
ENUM_ORDER_TYPE OrderType(){
|
||||
return (ENUM_ORDER_TYPE)OrderGetInteger(ORDER_TYPE);
|
||||
}
|
||||
|
||||
long OrderTicket(){
|
||||
return OrderGetInteger(ORDER_TICKET);
|
||||
}
|
||||
|
||||
long OrderOpenTime(){
|
||||
return OrderGetInteger(ORDER_TIME_DONE);
|
||||
}
|
||||
|
||||
double OrderOpenPrice(){
|
||||
return OrderGetDouble(ORDER_PRICE_OPEN);
|
||||
}
|
||||
|
||||
double OrderLots(){
|
||||
return OrderGetDouble(ORDER_VOLUME_CURRENT);
|
||||
}
|
||||
|
||||
int Hour(){
|
||||
MqlDateTime mTime;
|
||||
TimeCurrent(mTime);
|
||||
return(mTime.hour);
|
||||
}
|
||||
@@ -0,0 +1,383 @@
|
||||
#property link "https://www.earnforex.com/metatrader-indicators/macd-alert/"
|
||||
#property version "1.02"
|
||||
|
||||
#property copyright "EarnForex.com - 2019-2023"
|
||||
#property description "The MACD indicator with alerts."
|
||||
#property description " "
|
||||
#property description "WARNING: Use this software at your own risk."
|
||||
#property description "The creator of these plugins cannot be held responsible for any damage or loss."
|
||||
#property description " "
|
||||
#property description "Find More on www.EarnForex.com"
|
||||
#property icon "\\Files\\EF-Icon-64x64px.ico"
|
||||
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 2
|
||||
#property indicator_color1 clrGray
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_level1 0
|
||||
#property indicator_levelcolor clrGray
|
||||
#property indicator_levelstyle STYLE_DOT
|
||||
|
||||
#include <MQLTA ErrorHandling.mqh>
|
||||
#include <MQLTA Utils.mqh>
|
||||
|
||||
enum ENUM_TRADE_SIGNAL
|
||||
{
|
||||
SIGNAL_BUY_SWITCH = 1, // BUY (SWITCH)
|
||||
SIGNAL_SELL_SWITCH = -1, // SELL (SWITCH)
|
||||
SIGNAL_BUY_CROSS = 2, // BUY (CROSS)
|
||||
SIGNAL_SELL_CROSS = -2, // SELL (CROSS)
|
||||
SIGNAL_NEUTRAL = 0 // NEUTRAL
|
||||
};
|
||||
|
||||
enum ENUM_CANDLE_TO_CHECK
|
||||
{
|
||||
CURRENT_CANDLE = 0, // CURRENT CANDLE
|
||||
CLOSED_CANDLE = 1 // PREVIOUS CANDLE
|
||||
};
|
||||
|
||||
enum ENUM_ALERT_SIGNAL
|
||||
{
|
||||
MACD_MAIN_SWITCH_SIDE = 0, // MACD MAIN SWITCH SIDE
|
||||
MACD_MAIN_SIGNAL_CROSS = 1, // MACD MAIN AND SIGNAL CROSS
|
||||
MACD_MAIN_ALL = 2 // ALL SIGNALS
|
||||
};
|
||||
|
||||
enum ENUM_MACD_TYPE
|
||||
{
|
||||
MACD_TYPE_HISTOGRAM, // Histogram
|
||||
MACD_TYPE_LINE // Line
|
||||
};
|
||||
|
||||
input string Comment1 = "========================"; // MQLTA MACD With Alert
|
||||
input string IndicatorName = "MQLTA-MACDWA"; // Indicator Short Name
|
||||
input string Comment2 = "========================"; // Indicator Parameters
|
||||
input int MACDFastEMA = 12; // MACD Fast EMA Period
|
||||
input int MACDSlowEMA = 26; // MACD Slow EMA Period
|
||||
input int MACDSMA = 9; // MACD SMA Period
|
||||
input ENUM_APPLIED_PRICE MACDAppliedPrice = PRICE_CLOSE; // MACD Applied Price
|
||||
input ENUM_ALERT_SIGNAL AlertSignal = MACD_MAIN_SIGNAL_CROSS; // Alert Signal When
|
||||
input ENUM_CANDLE_TO_CHECK CandleToCheck = CURRENT_CANDLE; // Candle To Use For Analysis
|
||||
input ENUM_MACD_TYPE MACDType = MACD_TYPE_HISTOGRAM; // MACD Type
|
||||
input int BarsToScan = 500; // Number Of Candles To Analyse
|
||||
input string Comment_3 = "===================="; // Notification Options
|
||||
input bool EnableNotify = false; // Enable Notifications Feature
|
||||
input bool SendAlert = true; // Send Alert Notification
|
||||
input bool SendApp = false; // Send Notification to Mobile
|
||||
input bool SendEmail = false; // Send Notification via Email
|
||||
input string Comment_4 = "===================="; // Drawing Options
|
||||
input bool EnableDrawArrows = true; // Draw Signal Arrows
|
||||
input int ArrowBuySwitch = 241; // Buy Arrow Code (Switch)
|
||||
input int ArrowSellSwitch = 242; // Sell Arrow Code (Switch)
|
||||
input int ArrowSizeSwitch = 3; // Arrow Size (1-5) (Switch)
|
||||
input color ArrowColorBuySwitch = clrGreen; // Arrow Color Sell (Switch)
|
||||
input color ArrowColorSellSwitch = clrRed; // Arrow Color Sell (Switch)
|
||||
input int ArrowBuyCross = 233; // Buy Arrow Code (Cross)
|
||||
input int ArrowSellCross = 234; // Sell Arrow Code (Cross)
|
||||
input int ArrowSizeCross = 3; // Arrow Size (1-5) (Cross)
|
||||
input color ArrowColorBuyCross = clrGreen; // Arrow Color Sell (Switch)
|
||||
input color ArrowColorSellCross = clrRed; // Arrow Color Sell (Switch)
|
||||
|
||||
double BufferMain[];
|
||||
double BufferSignal[];
|
||||
|
||||
int BufferMACDHandle;
|
||||
|
||||
double Open[], Close[], High[], Low[];
|
||||
datetime Time[];
|
||||
|
||||
datetime LastNotificationTime;
|
||||
ENUM_TRADE_SIGNAL LastNotificationDirection;
|
||||
int Shift = 0;
|
||||
|
||||
int OnInit(void)
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, IndicatorName);
|
||||
|
||||
OnInitInitialization();
|
||||
if (!OnInitPreChecksPass())
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
InitialiseHandles();
|
||||
InitialiseBuffers();
|
||||
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
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[])
|
||||
{
|
||||
bool IsNewCandle = CheckIfNewCandle();
|
||||
|
||||
int counted_bars = 0;
|
||||
if (prev_calculated > 0) counted_bars = prev_calculated - 1;
|
||||
|
||||
if (counted_bars < 0) return -1;
|
||||
if (counted_bars > 0) counted_bars--;
|
||||
int limit = rates_total - counted_bars;
|
||||
if (limit > BarsToScan)
|
||||
{
|
||||
limit = BarsToScan;
|
||||
if (rates_total < BarsToScan + MACDSlowEMA) limit = rates_total - MACDSlowEMA;
|
||||
}
|
||||
if (limit > rates_total - MACDSlowEMA) limit = rates_total - MACDSlowEMA;
|
||||
|
||||
if ((CopyBuffer(BufferMACDHandle, 0, 0, limit, BufferMain) <= 0) ||
|
||||
(CopyBuffer(BufferMACDHandle, 1, 0, limit, BufferSignal) <= 0))
|
||||
{
|
||||
Print("Failed to create the indicator! Error: ", GetLastErrorText(GetLastError()), " - ", GetLastError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (IsStopped()) return 0;
|
||||
|
||||
for (int i = limit - 1; (i >= 0) && (!IsStopped()); i--)
|
||||
{
|
||||
Open[i] = iOpen(Symbol(), PERIOD_CURRENT, i);
|
||||
Low[i] = iLow(Symbol(), PERIOD_CURRENT, i);
|
||||
High[i] = iHigh(Symbol(), PERIOD_CURRENT, i);
|
||||
Close[i] = iClose(Symbol(), PERIOD_CURRENT, i);
|
||||
Time[i] = iTime(Symbol(), PERIOD_CURRENT, i);
|
||||
}
|
||||
|
||||
if ((IsNewCandle) || (prev_calculated == 0))
|
||||
{
|
||||
if (EnableDrawArrows) DrawArrows(limit);
|
||||
CleanUpOldArrows();
|
||||
}
|
||||
|
||||
if (EnableDrawArrows) DrawArrow(0);
|
||||
|
||||
if (EnableNotify) NotifyHit();
|
||||
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
CleanChart();
|
||||
}
|
||||
|
||||
void OnInitInitialization()
|
||||
{
|
||||
LastNotificationTime = TimeCurrent();
|
||||
Shift = CandleToCheck;
|
||||
}
|
||||
|
||||
bool OnInitPreChecksPass()
|
||||
{
|
||||
if ((MACDFastEMA <= 0) || (MACDFastEMA > MACDSlowEMA) || (MACDSMA <= 0))
|
||||
{
|
||||
Print("Wrong input parameters.");
|
||||
return false;
|
||||
}
|
||||
if ((Bars(Symbol(), PERIOD_CURRENT) < MACDSlowEMA) || (Bars(Symbol(), PERIOD_CURRENT) < MACDSMA))
|
||||
{
|
||||
Print("Not enough historical candles.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CleanChart()
|
||||
{
|
||||
ObjectsDeleteAll(ChartID(), IndicatorName);
|
||||
}
|
||||
|
||||
void InitialiseHandles()
|
||||
{
|
||||
BufferMACDHandle = iMACD(Symbol(), PERIOD_CURRENT, MACDFastEMA, MACDSlowEMA, MACDSMA, MACDAppliedPrice);
|
||||
ArrayResize(Open, BarsToScan);
|
||||
ArrayResize(High, BarsToScan);
|
||||
ArrayResize(Low, BarsToScan);
|
||||
ArrayResize(Close, BarsToScan);
|
||||
ArrayResize(Time, BarsToScan);
|
||||
}
|
||||
|
||||
void InitialiseBuffers()
|
||||
{
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
|
||||
ArraySetAsSeries(BufferMain, true);
|
||||
ArraySetAsSeries(BufferSignal, true);
|
||||
SetIndexBuffer(0, BufferMain, INDICATOR_DATA);
|
||||
SetIndexBuffer(1, BufferSignal, INDICATOR_DATA);
|
||||
if (MACDType == MACD_TYPE_HISTOGRAM) PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_HISTOGRAM);
|
||||
else PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_LINE);
|
||||
PlotIndexSetString(0, PLOT_LABEL, "MACD MAIN");
|
||||
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, MACDSlowEMA);
|
||||
PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_LINE);
|
||||
PlotIndexSetString(1, PLOT_LABEL, "MACD SIGNAL");
|
||||
PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, MACDSMA);
|
||||
}
|
||||
|
||||
datetime NewCandleTime = TimeCurrent();
|
||||
bool CheckIfNewCandle()
|
||||
{
|
||||
if (NewCandleTime == iTime(Symbol(), 0, 0)) return false;
|
||||
else
|
||||
{
|
||||
NewCandleTime = iTime(Symbol(), 0, 0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check whether there is a trade signal and return it.
|
||||
ENUM_TRADE_SIGNAL IsSignal(int i)
|
||||
{
|
||||
int j = i + Shift;
|
||||
if ((AlertSignal == MACD_MAIN_SWITCH_SIDE) || (AlertSignal == MACD_MAIN_ALL))
|
||||
{
|
||||
if ((BufferMain[j + 1] < 0) && (BufferMain[j] > 0)) return SIGNAL_BUY_SWITCH;
|
||||
if ((BufferMain[j + 1] > 0) && (BufferMain[j] < 0)) return SIGNAL_SELL_SWITCH;
|
||||
}
|
||||
if ((AlertSignal == MACD_MAIN_SIGNAL_CROSS) || (AlertSignal == MACD_MAIN_ALL))
|
||||
{
|
||||
if ((BufferMain[j + 1] < BufferSignal[j + 1]) && (BufferMain[j] > BufferSignal[j])) return SIGNAL_BUY_CROSS;
|
||||
if ((BufferMain[j + 1] > BufferSignal[j + 1]) && (BufferMain[j] < BufferSignal[j])) return SIGNAL_SELL_CROSS;
|
||||
}
|
||||
|
||||
return SIGNAL_NEUTRAL;
|
||||
}
|
||||
|
||||
void NotifyHit()
|
||||
{
|
||||
if (!EnableNotify) return;
|
||||
if ((!SendAlert) && (!SendApp) && (!SendEmail)) return;
|
||||
if ((CandleToCheck == CLOSED_CANDLE) && (Time[0] <= LastNotificationTime)) return;
|
||||
ENUM_TRADE_SIGNAL Signal = IsSignal(0);
|
||||
if (Signal == SIGNAL_NEUTRAL)
|
||||
{
|
||||
LastNotificationDirection = Signal;
|
||||
return;
|
||||
}
|
||||
if (Signal == LastNotificationDirection) return;
|
||||
string EmailSubject = IndicatorName + " " + Symbol() + " Notification";
|
||||
string EmailBody = AccountCompany() + " - " + AccountName() + " - " + IntegerToString(AccountNumber()) + "\r\n" + IndicatorName + " Notification for " + Symbol() + " @ " + EnumToString((ENUM_TIMEFRAMES)Period()) + "\r\n";
|
||||
string AlertText = "";
|
||||
string AppText = AccountCompany() + " - " + AccountName() + " - " + IntegerToString(AccountNumber()) + " - " + IndicatorName + " - " + Symbol() + " @ " + EnumToString((ENUM_TIMEFRAMES)Period()) + " - ";
|
||||
string Text = "";
|
||||
|
||||
Text += EnumToString(Signal);
|
||||
|
||||
EmailBody += Text;
|
||||
AlertText += Text;
|
||||
AppText += Text;
|
||||
if (SendAlert) Alert(AlertText);
|
||||
if (SendEmail)
|
||||
{
|
||||
if (!SendMail(EmailSubject, EmailBody)) Print("Error sending email " + IntegerToString(GetLastError()));
|
||||
}
|
||||
if (SendApp)
|
||||
{
|
||||
if (!SendNotification(AppText)) Print("Error sending notification " + IntegerToString(GetLastError()));
|
||||
}
|
||||
LastNotificationTime = Time[0];
|
||||
LastNotificationDirection = Signal;
|
||||
}
|
||||
|
||||
void DrawArrows(int limit)
|
||||
{
|
||||
for (int i = limit - 1; i >= 1; i--)
|
||||
{
|
||||
DrawArrow(i);
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveArrows()
|
||||
{
|
||||
ObjectsDeleteAll(ChartID(), IndicatorName + "-ARWS-");
|
||||
}
|
||||
|
||||
void DrawArrow(int i)
|
||||
{
|
||||
RemoveArrowCurr();
|
||||
ENUM_TRADE_SIGNAL Signal = IsSignal(i);
|
||||
if (Signal == SIGNAL_NEUTRAL) return;
|
||||
datetime ArrowDate = iTime(Symbol(), 0, i);
|
||||
string ArrowName = IndicatorName + "-ARWS-" + IntegerToString(ArrowDate);
|
||||
double ArrowPrice = 0;
|
||||
int ArrowType = 0;
|
||||
color ArrowColor = 0;
|
||||
int ArrowAnchor = 0;
|
||||
string ArrowDesc = "";
|
||||
int ArrowSize = 0;
|
||||
|
||||
if (Signal == SIGNAL_BUY_SWITCH)
|
||||
{
|
||||
ArrowPrice = Low[i];
|
||||
ArrowType = ArrowBuySwitch;
|
||||
ArrowColor = ArrowColorBuySwitch;
|
||||
ArrowSize = ArrowSizeSwitch;
|
||||
ArrowAnchor = ANCHOR_TOP;
|
||||
ArrowDesc = "BUY (SWITCH)";
|
||||
}
|
||||
else if (Signal == SIGNAL_SELL_SWITCH)
|
||||
{
|
||||
ArrowPrice = High[i];
|
||||
ArrowType = ArrowSellSwitch;
|
||||
ArrowColor = ArrowColorSellSwitch;
|
||||
ArrowSize = ArrowSizeSwitch;
|
||||
ArrowAnchor = ANCHOR_BOTTOM;
|
||||
ArrowDesc = "SELL (SWITCH)";
|
||||
}
|
||||
else if (Signal == SIGNAL_BUY_CROSS)
|
||||
{
|
||||
ArrowPrice = Low[i];
|
||||
ArrowType = ArrowBuyCross;
|
||||
ArrowColor = ArrowColorBuyCross;
|
||||
ArrowSize = ArrowSizeCross;
|
||||
ArrowAnchor = ANCHOR_TOP;
|
||||
ArrowDesc = "BUY (CROSS)";
|
||||
}
|
||||
else if (Signal == SIGNAL_SELL_CROSS)
|
||||
{
|
||||
ArrowPrice = High[i];
|
||||
ArrowType = ArrowSellCross;
|
||||
ArrowColor = ArrowColorSellCross;
|
||||
ArrowSize = ArrowSizeCross;
|
||||
ArrowAnchor = ANCHOR_BOTTOM;
|
||||
ArrowDesc = "SELL (CROSS)";
|
||||
}
|
||||
ObjectCreate(0, ArrowName, OBJ_ARROW, 0, ArrowDate, ArrowPrice);
|
||||
ObjectSetInteger(0, ArrowName, OBJPROP_COLOR, ArrowColor);
|
||||
ObjectSetInteger(0, ArrowName, OBJPROP_SELECTABLE, false);
|
||||
ObjectSetInteger(0, ArrowName, OBJPROP_HIDDEN, true);
|
||||
ObjectSetInteger(0, ArrowName, OBJPROP_ANCHOR, ArrowAnchor);
|
||||
ObjectSetInteger(0, ArrowName, OBJPROP_ARROWCODE, ArrowType);
|
||||
ObjectSetInteger(0, ArrowName, OBJPROP_WIDTH, ArrowSize);
|
||||
ObjectSetInteger(0, ArrowName, OBJPROP_STYLE, STYLE_SOLID);
|
||||
ObjectSetInteger(0, ArrowName, OBJPROP_BGCOLOR, ArrowColor);
|
||||
ObjectSetString(0, ArrowName, OBJPROP_TEXT, ArrowDesc);
|
||||
}
|
||||
|
||||
void RemoveArrowCurr()
|
||||
{
|
||||
datetime ArrowDate = iTime(Symbol(), 0, 0);
|
||||
string ArrowName = IndicatorName + "-ARWS-" + IntegerToString(ArrowDate);
|
||||
ObjectDelete(0, ArrowName);
|
||||
}
|
||||
|
||||
// Delete all arrows that are older than BarsToScan bars.
|
||||
void CleanUpOldArrows()
|
||||
{
|
||||
int total = ObjectsTotal(ChartID(), 0, OBJ_ARROW);
|
||||
for (int i = total - 1; i >= 0; i--)
|
||||
{
|
||||
string ArrowName = ObjectName(ChartID(), i, 0, OBJ_ARROW);
|
||||
datetime time = (datetime)ObjectGetInteger(ChartID(), ArrowName, OBJPROP_TIME);
|
||||
int bar = iBarShift(Symbol(), Period(), time);
|
||||
if (bar >= BarsToScan) ObjectDelete(ChartID(), ArrowName);
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Reference in New Issue
Block a user