Indication Collection

Indication Collection
This commit is contained in:
Coding for Dummies
2024-08-28 00:09:11 +07:00
parent 9003b29674
commit 1c95ea380b
31 changed files with 1234 additions and 0 deletions
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
+128
View File
@@ -0,0 +1,128 @@
//+------------------------------------------------------------------+
//| MACD+Alert.mq5 |
//| Copyright 2022, MzcpDev |
//| https://github.com/MzcpDev |
//+------------------------------------------------------------------+
#property copyright "2022, MzcpDev"
#property link "https://github.com/MzcpDev"
#property description "Moving Average Convergence/Divergence with Alert"
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots 2
#property indicator_type1 DRAW_HISTOGRAM
#property indicator_type2 DRAW_LINE
#property indicator_color1 Silver
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 1
#property indicator_label1 "MACD"
#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
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE; // Applied price
//--- indicator buffers
double ExtMacdBuffer[];
double ExtSignalBuffer[];
double ExtFastMaBuffer[];
double ExtSlowMaBuffer[];
//--- MA handles
int ExtFastMaHandle;
int ExtSlowMaHandle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtMacdBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtSignalBuffer,INDICATOR_DATA);
SetIndexBuffer(2,ExtFastMaBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(3,ExtSlowMaBuffer,INDICATOR_CALCULATIONS);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpSignalSMA-1);
//--- name for Dindicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"MACD("+string(InpFastEMA)+","+string(InpSlowEMA)+","+string(InpSignalSMA)+")");
//--- get MA handles
ExtFastMaHandle=iMA(NULL,0,InpFastEMA,0,MODE_EMA,InpAppliedPrice);
ExtSlowMaHandle=iMA(NULL,0,InpSlowEMA,0,MODE_EMA,InpAppliedPrice);
//--- 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 &tick_volume[],
const long &volume[],
const int &spread[])
{
//--- check for data
if(rates_total<InpSignalSMA)
return(0);
//--- not all data may be calculated
int calculated=BarsCalculated(ExtFastMaHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtFastMaHandle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
calculated=BarsCalculated(ExtSlowMaHandle);
if(calculated<rates_total)
{
Print("Not all data of ExtSlowMaHandle is calculated (",calculated,"bars ). Error",GetLastError());
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
if(CopyBuffer(ExtFastMaHandle,0,0,to_copy,ExtFastMaBuffer)<=0)
{
Print("Getting fast EMA is failed! Error",GetLastError());
return(0);
}
//--- get SlowSMA buffer
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(ExtSlowMaHandle,0,0,to_copy,ExtSlowMaBuffer)<=0)
{
Print("Getting slow SMA is failed! Error",GetLastError());
return(0);
}
//---
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];
//--- calculate Signal
SimpleMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer);
if(ExtMacdBuffer[0] - ExtSignalBuffer[0] > 0 && ExtSignalBuffer[1] - ExtMacdBuffer[1] >= 0)
{
Alert("sMACD (", Symbol(), ", ", Period(), ") - BUY!!!");
// Print("sMACD (", Symbol(), ", ", Period(), ") - BUY!!!");
// Comment("sMACD (", Symbol(), ", ", Period(), ") - BUY!!!");
// PlaySound("Alert.wav");
}
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
+201
View File
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

@@ -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);
}
}
//+------------------------------------------------------------------+
+14
View File
@@ -0,0 +1,14 @@
# MACD with Alert
MACD with Alert is an indicator for MT4 and MT5 by EarnForex.com. It is based on the Moving Average Convergence/Divergence (MACD) indicator. It finds points where the main line crosses either the zero level or the signal line. This indicator supports all types of alerts.
The indicator draws its arrows in the main chart window while the MACD itself is displayed in the separate chart window.
It is a non-repainting indicator.
![MACD with Alert shows some example arrows on this EUR/USD chart](https://github.com/EarnForex/MACD-with-Alert/blob/main/README_Images/macd-with-alert-example-arrows.png)
A detailed description of the indicator can be found here:
https://www.earnforex.com/metatrader-indicators/macd-alert/
Any contributions to the code are welcome!
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.
Binary file not shown.
+140
View File
@@ -0,0 +1,140 @@
//+------------------------------------------------------------------+
//| BB.mq5 |
//| Copyright 2009, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
#property description ""
#include <MovingAverages.mqh>
//---
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots 3
#property indicator_type1 DRAW_LINE
#property indicator_color1 LightSeaGreen
#property indicator_type2 DRAW_LINE
#property indicator_color2 LightSeaGreen
#property indicator_type3 DRAW_LINE
#property indicator_color3 LightSeaGreen
#property indicator_label1 "Bands middle"
#property indicator_label2 "Bands upper"
#property indicator_label3 "Bands lower"
//--- input parametrs
input int InpBandsPeriod=20; // Period
input int InpBandsShift=0; // Shift
input double InpBandsDeviations=2.0; // Deviation
//--- global variables
int ExtBandsPeriod,ExtBandsShift;
double ExtBandsDeviations;
int ExtPlotBegin=0;
//---- indicator buffer
double ExtMLBuffer[];
double ExtTLBuffer[];
double ExtBLBuffer[];
double ExtStdDevBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- check for input values
if(InpBandsPeriod<2)
{
ExtBandsPeriod=20;
printf("Incorrect value for input variable InpBandsPeriod=%d. Indicator will use value=%d for calculations.",InpBandsPeriod,ExtBandsPeriod);
}
else ExtBandsPeriod=InpBandsPeriod;
if(InpBandsShift<0)
{
ExtBandsShift=0;
printf("Incorrect value for input variable InpBandsShift=%d. Indicator will use value=%d for calculations.",InpBandsShift,ExtBandsShift);
}
else
ExtBandsShift=InpBandsShift;
if(InpBandsDeviations==0.0)
{
ExtBandsDeviations=2.0;
printf("Incorrect value for input variable InpBandsDeviations=%f. Indicator will use value=%f for calculations.",InpBandsDeviations,ExtBandsDeviations);
}
else ExtBandsDeviations=InpBandsDeviations;
//--- define buffers
SetIndexBuffer(0,ExtMLBuffer);
SetIndexBuffer(1,ExtTLBuffer);
SetIndexBuffer(2,ExtBLBuffer);
SetIndexBuffer(3,ExtStdDevBuffer,INDICATOR_CALCULATIONS);
//--- set index labels
PlotIndexSetString(0,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Middle");
PlotIndexSetString(1,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Upper");
PlotIndexSetString(2,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Lower");
//--- indicator name
IndicatorSetString(INDICATOR_SHORTNAME,"Bollinger Bands");
//--- indexes draw begin settings
ExtPlotBegin=ExtBandsPeriod-1;
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtBandsPeriod);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtBandsPeriod);
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtBandsPeriod);
//--- indexes shift settings
PlotIndexSetInteger(0,PLOT_SHIFT,ExtBandsShift);
PlotIndexSetInteger(1,PLOT_SHIFT,ExtBandsShift);
PlotIndexSetInteger(2,PLOT_SHIFT,ExtBandsShift);
//--- number of digits of indicator value
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//---- OnInit done
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
//--- variables
int pos;
//--- indexes draw begin settings, when we've recieved previous begin
if(ExtPlotBegin!=ExtBandsPeriod+begin)
{
ExtPlotBegin=ExtBandsPeriod+begin;
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPlotBegin);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtPlotBegin);
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtPlotBegin);
}
//--- check for bars count
if(rates_total<ExtPlotBegin)
return(0);
//--- starting calculation
if(prev_calculated>1) pos=prev_calculated-1;
else pos=0;
//--- main cycle
for(int i=pos;i<rates_total && !IsStopped();i++)
{
//--- middle line
ExtMLBuffer[i]=SimpleMA(i,ExtBandsPeriod,price);
//--- calculate and write down StdDev
ExtStdDevBuffer[i]=StdDev_Func(i,price,ExtMLBuffer,ExtBandsPeriod);
//--- upper line
ExtTLBuffer[i]=ExtMLBuffer[i]+ExtBandsDeviations*ExtStdDevBuffer[i];
//--- lower line
ExtBLBuffer[i]=ExtMLBuffer[i]-ExtBandsDeviations*ExtStdDevBuffer[i];
//---
}
//---- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
//| Calculate Standard Deviation |
//+------------------------------------------------------------------+
double StdDev_Func(int position,const double &price[],const double &MAprice[],int period)
{
//--- variables
double StdDev_dTmp=0.0;
//--- check for position
if(position<period) return(StdDev_dTmp);
//--- calcualte StdDev
for(int i=0;i<period;i++) StdDev_dTmp+=MathPow(price[position-i]-MAprice[position],2);
StdDev_dTmp=MathSqrt(StdDev_dTmp/period);
//--- return calculated value
return(StdDev_dTmp);
}
//+------------------------------------------------------------------+
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.