diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index 875f27e..ca47653 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -29,11 +29,14 @@ jobs: id: get-files run: | import glob, json, os - files = glob.glob("**/*.mq?") - print("::set-output name=filelist::{}".format(json.dumps(files))) + fghout = os.environ["GITHUB_OUTPUT"] + files = glob.glob("**/*.mq?", recursive=True) + filelist = "filelist={}".format(json.dumps(files)) + with open(fghout, "a") as fd: + fd.write(filelist) shell: python - - name: Display output - run: echo ${{ steps.get-files.outputs.filelist }} + - name: Display outputs + run: echo "${{ toJson(steps.get-files.outputs) }}" Compile: defaults: run: @@ -48,7 +51,7 @@ jobs: - uses: actions/checkout@v3 with: path: Include/EA31337-classes - ref: v2.012.1 + ref: v3.000.1 repository: EA31337/EA31337-classes - name: Compile (build 2361) uses: fx31337/mql-compile-action@master @@ -71,7 +74,7 @@ jobs: run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname' - run: Get-Location - name: Upload indicator artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: Indicators-other path: '**/*.ex?' diff --git a/Oscillators/Arrows/ATR_MA_Slope.mq4 b/Oscillators/Arrows/ATR_MA_Slope.mq4 new file mode 100644 index 0000000..6cd86f2 --- /dev/null +++ b/Oscillators/Arrows/ATR_MA_Slope.mq4 @@ -0,0 +1,87 @@ +#property indicator_buffers 4 +#property indicator_separate_window + +extern int NumberOfBars = 100; +extern double SlopeThreshold = 2.0; +extern int SlopeMAPeriod = 7; +extern int SlopeATRPeriod = 50; + +extern color SlopeColor = Gray; +extern color LongColor = Lime; +extern color ShortColor = Red; + +double Slope[]; +double Long[]; +double Short[]; +double Flat[]; + +//+------------------------------------------------------------------+ +//| Custom indicator initialization function | +//+------------------------------------------------------------------+ +int init() { + IndicatorShortName(WindowExpertName()); + + SetIndexBuffer(0, Slope); + SetIndexBuffer(1, Long); + SetIndexBuffer(2, Short); + SetIndexBuffer(3, Flat); + + SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 1, SlopeColor); + SetIndexLabel(0, "Slope"); + SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID, 1, LongColor); + SetIndexLabel(1, "Long"); + SetIndexArrow(1, 159); + SetIndexStyle(2, DRAW_ARROW, STYLE_SOLID, 1, ShortColor); + SetIndexLabel(2, "Short"); + SetIndexArrow(2, 159); + SetIndexStyle(3, DRAW_ARROW, STYLE_SOLID, 1, SlopeColor); + SetIndexLabel(3, "Flat"); + SetIndexArrow(3, 159); + +#ifdef __MQL4__ + SetLevelStyle(STYLE_SOLID, 1, SlopeColor); + SetLevelValue(0, SlopeThreshold * 0.5); + SetLevelValue(1, -SlopeThreshold * 0.5); +#endif + + return (INIT_SUCCEEDED); +} + +int start() { + int prev_calculated = IndicatorCounted(); + int rates_total = Bars; + int limit = MathMin(NumberOfBars, rates_total - prev_calculated); + if (limit == rates_total) + limit--; + + for (int shift = limit; shift >= 0; shift--) { + Slope[shift] = 0; + + double dblTma, dblPrev; + double atr = iATR(NULL, PERIOD_CURRENT, SlopeATRPeriod, shift + 10) / 10; + + if (atr != 0) { + dblTma = iMA(NULL, PERIOD_CURRENT, SlopeMAPeriod, 0, MODE_LWMA, + PRICE_CLOSE, shift); + dblPrev = (iMA(NULL, PERIOD_CURRENT, SlopeMAPeriod, 0, MODE_LWMA, + PRICE_CLOSE, shift + 1) * + 231 + + iClose(NULL, (int)PERIOD_CURRENT, shift) * 20) / + 251; + Slope[shift] = (dblTma - dblPrev) / atr; + } + + Long[shift] = EMPTY_VALUE; + Short[shift] = EMPTY_VALUE; + Flat[shift] = EMPTY_VALUE; + + if (Slope[shift] > SlopeThreshold * 0.5) + Long[shift] = Slope[shift]; + else if (Slope[shift] < -SlopeThreshold * 0.5) + Short[shift] = Slope[shift]; + else + Flat[shift] = Slope[shift]; + } + + return (0); +} diff --git a/Oscillators/Arrows/ATR_MA_Slope.mq5 b/Oscillators/Arrows/ATR_MA_Slope.mq5 new file mode 100644 index 0000000..61ee144 --- /dev/null +++ b/Oscillators/Arrows/ATR_MA_Slope.mq5 @@ -0,0 +1,68 @@ +/** + * @file + * Implements indicator under MQL5. + */ + +// Defines indicator properties. +#property indicator_separate_window + +#property indicator_buffers 4 +#property indicator_plots 4 + +// Define indicator properties +#property indicator_type1 DRAW_LINE +#property indicator_color1 Gray +#property indicator_label1 "Slope" + +#property indicator_type2 DRAW_ARROW +#property indicator_color2 Lime +#property indicator_label2 "Long" + +#property indicator_type3 DRAW_ARROW +#property indicator_color3 Red +#property indicator_label3 "Short" + +#property indicator_type4 DRAW_ARROW +#property indicator_color4 Gray +#property indicator_label4 "Flat" + +#property indicator_level1 0.0 + +// Includes EA31337 framework. +#include +#include +#include +#include + +// Defines macros. +#define extern input +#define Bars (ChartStatic::iBars(_Symbol, _Period)) + +// Includes the main file. +#include "ATR_MA_Slope.mq4" + +// Custom indicator initialization function. +void OnInit() { + init(); + if (!ArrayGetAsSeries(Slope)) { + ArraySetAsSeries(Slope, true); + ArraySetAsSeries(Long, true); + ArraySetAsSeries(Short, true); + ArraySetAsSeries(Flat, true); + } + PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetDouble(2, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetDouble(3, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, SlopeMAPeriod); + PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, SlopeMAPeriod); + PlotIndexSetInteger(2, PLOT_DRAW_BEGIN, SlopeMAPeriod); + PlotIndexSetInteger(3, PLOT_DRAW_BEGIN, SlopeMAPeriod); +} + +// Custom indicator iteration function. +int OnCalculate(const int rates_total, const int prev_calculated, + const int begin, const double &price[]) { + IndicatorCounted(fmin(prev_calculated, Bars)); + ResetLastError(); + return start() >= 0 ? rates_total : 0; +} diff --git a/Oscillators/Arrows/README.md b/Oscillators/Arrows/README.md new file mode 100644 index 0000000..279ab67 --- /dev/null +++ b/Oscillators/Arrows/README.md @@ -0,0 +1,43 @@ +# Arrow-like Oscillators + +Arrow-like oscillators are a category of technical indicators that +provide trading signals in the form of arrows or other visual markers +on a chart. These indicators are designed to generate signals for both +long (buy) and short (sell) positions, indicating potential entry and +exit points for traders. + +Here are the key characteristics of arrow-like oscillators: + +- Signal Generation: Arrow-like oscillators generate signals by +analyzing price movements, trends, and other relevant market +conditions. When a specific set of criteria is met, these indicators +plot an arrow pointing up (for long/buy) or down (for short/sell) on +the chart, indicating a potential trade entry or exit point. + +- Trend Reversals: These indicators often focus on identifying +potential trend reversals. When the market is transitioning from an +upward trend to a downward trend (or vice versa), arrow-like +oscillators aim to capture these turning points and provide traders +with signals to take advantage of the changing trend. + +- Confirmation: Traders often use arrow-like oscillators in +conjunction with other technical analysis tools to confirm their +trading decisions. These indicators can help traders avoid false +signals by waiting for confirmation from multiple sources before +entering a trade. + +- User-Defined Parameters: Many arrow-like oscillators allow traders +to customize their parameters, such as sensitivity levels, timeframes, +and overbought/oversold thresholds. This customization enables +traders to tailor the indicator to their specific trading style and +preferences. + +- Risk Management: While these indicators provide entry and exit +signals, traders should still employ proper risk management +techniques, such as setting stop-loss and take-profit levels, to +protect their capital. + +Arrow-like oscillators are particularly popular among traders who +prefer visual signals for their trading decisions. They simplify +the process of identifying potential trade opportunities and can +enhance the efficiency of a trader's decision-making process. diff --git a/Oscillator/Elliott_Wave_Oscillator2.mq4 b/Oscillators/Elliott_Wave_Oscillator2.mq4 similarity index 100% rename from Oscillator/Elliott_Wave_Oscillator2.mq4 rename to Oscillators/Elliott_Wave_Oscillator2.mq4 diff --git a/Oscillator/Elliott_Wave_Oscillator2.mq5 b/Oscillators/Elliott_Wave_Oscillator2.mq5 similarity index 100% rename from Oscillator/Elliott_Wave_Oscillator2.mq5 rename to Oscillators/Elliott_Wave_Oscillator2.mq5 diff --git a/Oscillators/README.md b/Oscillators/README.md new file mode 100644 index 0000000..b56bfad --- /dev/null +++ b/Oscillators/README.md @@ -0,0 +1,38 @@ +# Oscillator indicators + +Oscillators are a category of technical indicators used in financial markets +analysis. They are designed to identify overbought or oversold conditions and +potential trend reversals. Oscillators typically oscillate within a specific +range or between certain values, indicating the momentum or strength of a price +movement. + +Oscillators are considered a subset of indicators since they are technical +tools used to analyze price data and generate signals. They differ from other +types of indicators like trend-following or volume-based indicators because +oscillators are designed to provide information about the short-term price +behavior rather than long-term trends or volume patterns. + +Common examples of oscillators include the Relative Strength Index (RSI), +Stochastic Oscillator, Moving Average Convergence Divergence (MACD), and +the Williams %R. These indicators generate values that fluctuate within +predefined boundaries, typically between 0 and 100 or -100 and +100, +indicating the relative strength or weakness of price movements. + +Traders and analysts use oscillators to identify potential buying or +selling opportunities, divergences, and to gauge market conditions such +as overbought or oversold levels. They can be helpful in identifying +potential trend reversals or determining the strength of an ongoing +trend. + +In summary, oscillators are a type of indicator used in technical +analysis that measure price momentum and provide insights into +overbought or oversold conditions. They are considered a subset of +indicators due to their specific function and characteristics. + +## TDI (Traders Dynamic Index) + +The Traders Dynamic Index (TDI) is a versatile trading indicator designed to +aid traders in analyzing market conditions related to trend direction, market +strength, and volatility. It combines RSI, Moving Averages, and volatility +bands to offer insights into trend direction, market strength, and volatility +which gives comprehensive overview of the market's behavior. diff --git a/Oscillator/SVE_Bollinger_Bands.mq4 b/Oscillators/SVE_Bollinger_Bands.mq4 similarity index 100% rename from Oscillator/SVE_Bollinger_Bands.mq4 rename to Oscillators/SVE_Bollinger_Bands.mq4 diff --git a/Oscillator/SVE_Bollinger_Bands.mq5 b/Oscillators/SVE_Bollinger_Bands.mq5 similarity index 100% rename from Oscillator/SVE_Bollinger_Bands.mq5 rename to Oscillators/SVE_Bollinger_Bands.mq5 diff --git a/Oscillators/SuperSlope.mq4 b/Oscillators/SuperSlope.mq4 new file mode 100644 index 0000000..c3303d7 --- /dev/null +++ b/Oscillators/SuperSlope.mq4 @@ -0,0 +1,1125 @@ +//+------------------------------------------------------------------+ +//| SuperSlope.mq4 | +//| Copyright 2016, Paul Geirnaerdt | +//| http://www.delabron.nl | +//+------------------------------------------------------------------+ +//09/05/2016 arrows and mtf currency table by gprince66 SHF +//09/18/2016 Combined Baluda's and Gary's work into one project. Colors updated by Nanningbob +//10/10/2016 SS now works on all pairs, including exotics. by VirtualFM SHF +#property copyright "Copyright 2016, Paul Geirnaerdt" +#property link "http://www.delabron.nl" +#property indicator_separate_window +#property indicator_buffers 2 +#property strict + +#define version "v2.2" +#define CURRENCYCOUNT 9 + +extern string gen = "----General Inputs----"; //---- +extern int maxBars = 0; //maxBars>0 turns off WindowFirstVisibleBar() +extern string nonPropFont = "Lucida Console"; +extern string spac751 = "----"; //---- +extern bool autoTimeFrame = false; +extern string ind_tf = "timeFrame M1,M5,M15,M30,H1,H4,D1,W1,MN"; //---- +extern string timeFrame = "D1"; //timeFrame: CSS & left column +extern string extraTimeFrame = "W1"; //extraTimeFrame: center column +extern string extraTimeFrame2 = "MN"; //extraTimeFrame2: right column +extern int NoOfTimeFrames = 3; //NoOfTimeFrames: num of TF to display +extern string spac756 = "---- Slope Inputs ----"; //---- +extern double differenceThreshold = 0.0; +extern double levelCrossValue = 2.0; +extern int SlopeMAPeriod = 7; +extern int SlopeATRPeriod = 50; +extern string spac754 = "---- Send Alerts ----"; //---- +extern bool sendCrossAlerts = true; +extern bool sendLevelCrossAlerts = true; +extern bool sendExitCrossAlerts = true; +extern bool sendMTFAgreeAlerts = true; //sendMTFAgreeAlerts: timeFrame regulates alerts +extern string spac754a = "----"; //---- +extern bool PopupAlert = true; +extern bool EmailAlert = true; +extern bool PushAlert = true; +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +int leftBarPrev=0, rightBarPrev=0; +bool _BrokerHasSundayCandles; +int userNoOfTimeFrames; +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +extern string disp = "----Display Inputs----"; //---- +extern int displayTextSize = 10; +extern int horizontalOffset = 10; +extern int verticalOffset = 5; +extern int horizontalShift = 20; //horizontalShift: columns +extern int verticalShift = 15; //verticalShift: rows +extern string spc1134 = "---- Multiple Indis ----"; //---- +extern bool showSlopeValues = true; +extern bool showCurrencyLines = true; +extern bool showLevelCrossLines = true; +extern bool showBackgroundColor = true; +extern bool showDifferenceThreshold = true; +extern color differenceThresholdColor = clrYellow; +extern string spac8574 = "----"; //---- +extern int levelCrossLineSize = 2; +extern int backgroundLineWidth = 8; //backgroundLineWidth: 80% zoom ~ 14 line width +/////////////////////////////////////////////////////////////////////////////////////////////////// + +extern string gen2 = "----Arrow Display----"; //---- +extern bool showArrows = true; +extern color BuyArrowColor = clrDarkGreen; +extern int BuyArrowFontSize = 14; +extern color SellArrowColor = clrMaroon; +extern int SellArrowFontSize = 14; +extern string spac456 = "----"; //---- +extern bool showSignalLine = true; +extern color SignalLineBuyColor = clrDarkGreen; +extern color SignalLineSellColor = clrDeepPink; +extern int SignalLineSize = 1; +///////////////////////////////////////////////////////////////////////////////////////// +int ATRPeriodArrows=20; +double ATRMultiplierArrows=1.0; +uchar BuyArrowStyle=225; +uchar SellArrowStyle=226; +bool TradeLong=false, TradeShort=false; +bool BuyArrowActive=false, SellArrowActive=false; +bool OnlyDrawArrowsOnNewBar=true; +///////////////////////////////////////////////////////////////////////////////////////// + +extern string rede = "---- Read Delay ----"; //---- +extern bool EveryTickMode = true; +extern bool ReadEveryNewBar = false; //ReadEveryNewBar: Reads every new bar even if ReadEveryXSeconds hasn't expired +extern int ReadEveryXSeconds = 5; //ReadEveryXSeconds: Set EveryTickMode to false +////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +bool IsItNewBar=false, userEveryTickMode, userReadEveryNewBar; +datetime lastBarTime = -1, nextReadTime = -1, lastBarTime2 = -1; +int userReadEveryXSeconds; +////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +extern string colour="----Colo(u)r inputs----"; //---- +extern color Color_USD = clrRed; +extern color Color_EUR = clrDeepSkyBlue; +extern color Color_GBP = clrRoyalBlue; +extern color Color_CHF = clrPaleTurquoise; +extern color Color_JPY = clrGold; +extern color Color_AUD = clrDarkOrange; +extern color Color_CAD = clrPink; +extern color Color_NZD = clrTan; +extern color Color_default = clrWhite; +extern int line_width_USD = 3; +extern int line_style_USD = 0; +extern int line_width_EUR = 3; +extern int line_style_EUR = 0; +extern int line_width_GBP = 3; +extern int line_style_GBP = 0; +extern int line_width_JPY = 3; +extern int line_style_JPY = 0; +extern int line_width_AUD = 3; +extern int line_style_AUD = 0; +extern int line_width_CAD = 3; +extern int line_style_CAD = 0; +extern int line_width_NZD = 3; +extern int line_style_NZD = 0; +extern int line_width_CHF = 3; +extern int line_style_CHF = 0; +extern color colorWeakCross = clrGold; +extern color colorNormalCross = clrGold; +extern color colorStrongCross = clrGold; +extern color colorDifferenceUp = 0x303000; +extern color colorDifferenceDn = 0x000030; +extern color colorDifferenceLo = 0x005454; +extern color colorTimeframe = clrWhite; +extern color colorLevelHigh = clrLimeGreen; +extern color colorLevelLow = clrCrimson; +///////////////////////////////////////////////////////////////////////////////////////////////// + +//global variables +string indicatorName="SuperSlope"; +string shortName, almostUniqueIndex; +int windex, size; +string ObjSuff, ObjSuff2; +int userTimeFrame; +int userExtraTimeFrame; +int userExtraTimeFrame2; +bool IsInit=false; +string objectName=""; +double Slope_2, Slope_3; + +//bufffers +double Slope1[]; +double Slope2[]; + +//currency variables +string currencyNames[CURRENCYCOUNT]={ "USD","EUR","GBP","JPY","AUD","CAD","NZD","CHF","" }; +int line_width[CURRENCYCOUNT]; +int line_style[CURRENCYCOUNT]; +color currencyColors[CURRENCYCOUNT]; +int index, index2; + + +//+------------------------------------------------------------------+ +//| Custom indicator initialization function | +//+------------------------------------------------------------------+ +int OnInit() +{ + int i; + IsInit=true; + + initTimeFrames(); + + //unique indicator name + string now=string(TimeCurrent()); + almostUniqueIndex=StringSubstrOld(now,StringLen(now)-3)+IntegerToString(WindowsTotal())+IntegerToString(WindowOnDropped()); + shortName=indicatorName+" - "+version+" - id"+almostUniqueIndex; + IndicatorShortName(shortName); + windex=WindowFind(shortName); + + ObjSuff="_"+almostUniqueIndex+"_BSS"; + ObjSuff2="_"+almostUniqueIndex+"_objdel"; + + //---- + + currencyColors[0]=Color_USD; + line_width[0]=line_width_USD; + line_style[0]=line_style_USD; + + currencyColors[1]=Color_EUR; + line_width[1]=line_width_EUR; + line_style[1]=line_style_EUR; + + currencyColors[2]=Color_GBP; + line_width[2]=line_width_GBP; + line_style[2]=line_style_GBP; + + currencyColors[3]=Color_JPY; + line_width[3]=line_width_JPY; + line_style[3]=line_style_JPY; + + currencyColors[4]=Color_AUD; + line_width[4]=line_width_AUD; + line_style[4]=line_style_AUD; + + currencyColors[5]=Color_CAD; + line_width[5]=line_width_CAD; + line_style[5]=line_style_CAD; + + currencyColors[6]=Color_NZD; + line_width[6]=line_width_NZD; + line_style[6]=line_style_NZD; + + currencyColors[7]=Color_CHF; + line_width[7]=line_width_CHF; + line_style[7]=line_style_CHF; + + currencyColors[8]=Color_default; + line_width[8]=line_width_USD; + line_style[8]=line_style_USD; + + //---- + + if(CSS_Available(StringSubstrOld(Symbol(),0,3)) && CSS_Available(StringSubstrOld(Symbol(),3,3))) + { + index=getCurrencyIndex(StringSubstrOld(Symbol(),0,3)); + index2=getCurrencyIndex(StringSubstrOld(Symbol(),3,3)); + } + else + { + index=8; + index2=index; + } + + SetIndexBuffer( 0, Slope1 ); + SetIndexLabel(0, currencyNames[index]); + + SetIndexBuffer( 1, Slope2 ); + SetIndexLabel(1, currencyNames[index2]); + + //display currency lines + if(showCurrencyLines) + { + SetIndexStyle(0,DRAW_LINE,line_style[index],line_width[index],currencyColors[index]); + SetIndexStyle(1,DRAW_LINE,line_style[index2],line_width[index2],currencyColors[index2]); + } + else + { + SetIndexStyle(0,DRAW_NONE); + SetIndexStyle(1,DRAW_NONE); + } + + //---- + + _BrokerHasSundayCandles = false; + for ( i = 0; i < 8; i++ ) + { + if ( TimeDayOfWeek( iTime( NULL, PERIOD_D1, i ) ) == 0 ) + { + _BrokerHasSundayCandles = true; + break; + } + } + + //input variables + userNoOfTimeFrames = NoOfTimeFrames; + userEveryTickMode = EveryTickMode; + userReadEveryNewBar = ReadEveryNewBar; + userReadEveryXSeconds = ReadEveryXSeconds; + + if(userNoOfTimeFrames > 3) userNoOfTimeFrames = 3; + if(userNoOfTimeFrames < 1) userNoOfTimeFrames = 1; + + return(INIT_SUCCEEDED); + +}//OnInit() + +//+------------------------------------------------------------------+ +//| Custom indicator deinitialization function | +//+------------------------------------------------------------------+ +void OnDeinit(const int reason) +{ + //Remove objects that belong to this indicator + //Add suffix "_xxx" to object name + for(int i=ObjectsTotal()-1;i>=0;i--) + { + if(StringFind(ObjectName(i),ObjSuff,0)>0) + { + ObjectDelete(ObjectName(i)); + } + } + +}//OnDeinit(const int reason) + +//+------------------------------------------------------------------+ +//| 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[]) +{ + //variables + int i=0, j=0, leftBar=0, rightBar=0, bar=0; + double ATR=0, ArrowHigh=0, ArrowLow=0; + datetime myTime=0; + + //read delay + if(IsNewReadTime()) + { + IsItNewBar = IsNewBar(); + + //maxBars>0 turns off WindowFirstVisibleBar() + //maxBars>300 ~ visual backtesting only + if(maxBars > 0) + { + //turn off WindowFirstVisibleBar() + leftBar=MathMin(maxBars,Bars-10); + rightBar = 0; + + //prevent mt4 crash + if(maxBars > 300) + { + userEveryTickMode = false; + userReadEveryNewBar = false; + userReadEveryXSeconds = 86400; + } + } + else + { + //loop only what's visible on chart + leftBar = WindowFirstVisibleBar(); + rightBar = leftBar - WindowBarsPerChart(); + if(rightBar < 0) rightBar = 0; + } + + ////////////////////////////////////////////////////////////////////// + + + //main loop + for(i=leftBar; i>=rightBar; i--) + { + //ignore last 50 bars + if (i > rates_total - 50) continue; + + //skip first 'i' + if(i < leftBar) + { + //arrow spacing + ATR = iATR(_Symbol,_Period,ATRPeriodArrows,i); + ArrowHigh = iHigh(_Symbol,_Period,i) + ATR*ATRMultiplierArrows; + ArrowLow = iLow(_Symbol,_Period,i) - ATR*ATRMultiplierArrows; + + //get slope ~ must use chart's Time[i] for css lines to display properly + bar=iBarShift(NULL,userTimeFrame,Time[i]); + Slope1[i] = GetSlope(userTimeFrame, SlopeMAPeriod, SlopeATRPeriod, bar); + Slope2[i] = -Slope1[i]; + + //Set trade direction + TradeLong=false; TradeShort=false; + if(Slope1[i] > differenceThreshold*0.5) + TradeLong=true; + if(Slope1[i] < -differenceThreshold*0.5) + TradeShort=true; + + //////////////////////////////////////////////////////////////////////////////// + + + if(i==rightBar) + { + //get slope for extra time frames + if(userNoOfTimeFrames > 1 || (sendMTFAgreeAlerts && rightBar == 0)) + Slope_2 = GetSlope(userExtraTimeFrame, SlopeMAPeriod, SlopeATRPeriod, rightBar); + + if(userNoOfTimeFrames > 2 || (sendMTFAgreeAlerts && rightBar == 0)) + Slope_3 = GetSlope(userExtraTimeFrame2, SlopeMAPeriod, SlopeATRPeriod, rightBar); + + + //Show ordered tables + if(userNoOfTimeFrames == 1) + { + ShowCurrencyTable(userTimeFrame, 1, rightBar); //css & left column + ShowCurrencyTable(userTimeFrame, 4, rightBar); //threshold + } + else if(userNoOfTimeFrames == 2) + { + ShowCurrencyTable(userTimeFrame, 1, rightBar); + ShowCurrencyTable(userExtraTimeFrame, 2, rightBar); //center column + ShowCurrencyTable(userTimeFrame, 4, rightBar); + } + else if(userNoOfTimeFrames == 3) + { + ShowCurrencyTable(userTimeFrame, 1, rightBar); + ShowCurrencyTable(userExtraTimeFrame, 2, rightBar); + ShowCurrencyTable(userExtraTimeFrame2, 3, rightBar); //right column + ShowCurrencyTable(userTimeFrame, 4, rightBar); + } + + }//if(i==rightBar) + + /////////////////////////////////////////////////////////////////////////////////////////// + + + //delete arrows if leftBar changes or viewable bars change + if(!IsInit && i==leftBar-1) + { + if(leftBar != leftBarPrev || leftBar-rightBar != leftBarPrev-rightBarPrev) + { + //Remove objects + for(j=ObjectsTotal()-1;j>=0;j--) + { + if(StringFind(ObjectName(j),ObjSuff2,0) > 0) + { + ObjectDelete(ObjectName(j)); + } + } + + //css buffers + double slopeTemp=Slope1[0]; + ArrayInitialize(Slope1,EMPTY_VALUE); + ArrayInitialize(Slope2,EMPTY_VALUE); + Slope1[0] = slopeTemp; + Slope2[0] = -slopeTemp; + + }//if(leftBar != leftBarPrev || leftBar-rightBar != leftBarPrev-rightBarPrev) + + }//if(!IsInit && i==leftBar-1) + + ///////////////////////////////////////////////////////////////////////////////////// + + + //Create background object + if(showBackgroundColor) + { + objectName=almostUniqueIndex+"_diff_"+TimeToString(Time[i])+ObjSuff+ObjSuff2; + if(ObjectFind(objectName)==-1) + { + if(ObjectCreate(objectName,OBJ_VLINE,windex,Time[i],0)) + { + ObjectSet(objectName,OBJPROP_BACK,true); + ObjectSet(objectName,OBJPROP_HIDDEN,true); + ObjectSet(objectName,OBJPROP_WIDTH,backgroundLineWidth); + } + } + + //Draw background color + if(MathAbs(Slope1[i])>differenceThreshold*0.5) + { + if(TradeLong) + ObjectSet(objectName,OBJPROP_COLOR,colorDifferenceUp); + if(TradeShort) + ObjectSet(objectName,OBJPROP_COLOR,colorDifferenceDn); + } + else + { + //Below threshold + ObjectSet(objectName,OBJPROP_COLOR,colorDifferenceLo); + } + + }//if(showBackgroundColor) + + ////////////////////////////////////////////////////////////////////////////////////// + + + //avoid trivial crosses + bool OkToDrawArrows = false; + if(OnlyDrawArrowsOnNewBar) + if(IsItNewBar) OkToDrawArrows=true; + else + OkToDrawArrows=true; + + //draw arrows + if(showArrows && OkToDrawArrows) + { + //Buy + if(TradeLong && !BuyArrowActive) + { + objectName = "Buy Arrow "+IntegerToString((int)time[i])+ObjSuff+ObjSuff2; + if(ObjectFind(objectName)==-1) + { + TextCreate(objectName, time[i], ArrowLow, CharToString(BuyArrowStyle), BuyArrowColor, ANCHOR_LOWER, "wingdings", BuyArrowFontSize); + } + + //signal line + if(showSignalLine && i==0) + { + objectName = "Buy Signal Line "+IntegerToString((int)time[i])+ObjSuff; + if(ObjectFind(objectName)==-1) + { + if(ObjectCreate(objectName,OBJ_TREND,0,time[i+1],close[0],time[i]+Period()*60,close[0])) + { + ObjectSet(objectName,OBJPROP_BACK,true); + ObjectSet(objectName,OBJPROP_WIDTH,SignalLineSize); + ObjectSet(objectName,OBJPROP_COLOR,SignalLineBuyColor); + ObjectSet(objectName,OBJPROP_RAY,false); + ObjectSet(objectName,OBJPROP_HIDDEN,true); + } + } + } + + BuyArrowActive=true; + SellArrowActive=false; + + }//if(TradeLong && !BuyArrowActive) + + //Sell + if(TradeShort && !SellArrowActive) + { + objectName = "Sell Arrow "+IntegerToString((int)time[i])+ObjSuff+ObjSuff2; + if(ObjectFind(objectName)==-1) + { + TextCreate(objectName, time[i], ArrowHigh, CharToString(SellArrowStyle), SellArrowColor, ANCHOR_UPPER, "wingdings", SellArrowFontSize); + } + + //signal line + if(showSignalLine && i==0) + { + objectName = "Sell Signal Line "+IntegerToString((int)time[i])+ObjSuff; + if(ObjectFind(objectName)==-1) + { + if(ObjectCreate(objectName,OBJ_TREND,0,time[i+1],close[0],time[i]+Period()*60,close[0])) + { + ObjectSet(objectName,OBJPROP_BACK,true); + ObjectSet(objectName,OBJPROP_WIDTH,SignalLineSize); + ObjectSet(objectName,OBJPROP_COLOR,SignalLineSellColor); + ObjectSet(objectName,OBJPROP_RAY,false); + ObjectSet(objectName,OBJPROP_HIDDEN,true); + } + } + } + + BuyArrowActive=false; + SellArrowActive=true; + + }//if(TradeShort && !SellArrowActive) + + //difference Lo + if(!TradeLong && !TradeShort) + { + BuyArrowActive=false; + SellArrowActive=false; + } + + }//if(showArrows && OkToDrawArrows) + + }//if(i < leftBar) + + }//for(i=leftBar; i>=rightBar; i--) + + + //Draw 0.2 & -0.2 green/red lines + if(showLevelCrossLines) + { + objectName=almostUniqueIndex+"_high"+ObjSuff; + ObjectDelete(objectName); + if(ObjectFind(objectName)==-1) + { + if(ObjectCreate(objectName,OBJ_TREND,windex,Time[leftBar],levelCrossValue,Time[rightBar],levelCrossValue)) + { + ObjectSet(objectName,OBJPROP_BACK,true); + ObjectSet(objectName,OBJPROP_WIDTH,levelCrossLineSize); + ObjectSet(objectName,OBJPROP_COLOR,colorLevelHigh); + ObjectSet(objectName,OBJPROP_RAY,false); + ObjectSet(objectName,OBJPROP_HIDDEN,true); + } + } + objectName=almostUniqueIndex+"_low"+ObjSuff; + ObjectDelete(objectName); + if(ObjectFind(objectName)==-1) + { + if(ObjectCreate(objectName,OBJ_TREND,windex,Time[leftBar],-levelCrossValue,Time[rightBar],-levelCrossValue)) + { + ObjectSet(objectName,OBJPROP_BACK,true); + ObjectSet(objectName,OBJPROP_WIDTH,levelCrossLineSize); + ObjectSet(objectName,OBJPROP_COLOR,colorLevelLow); + ObjectSet(objectName,OBJPROP_RAY,false); + ObjectSet(objectName,OBJPROP_HIDDEN,true); + } + } + } + + }//if(IsNewReadTime()) + + //no alerts on initialization + IsInit=false; + + //delete stuff if new leftBar + leftBarPrev=leftBar; + rightBarPrev=rightBar; + + return(rates_total); + +}//OnCalculate() + +//+------------------------------------------------------------------+ +//| | +//+------------------------------------------------------------------+ +bool IsNewReadTime() +{ + bool NewReadTime = false; + bool IsReadEveryNewBar = false; + + if(userEveryTickMode) + { + NewReadTime = true; + } + else + { + if(userReadEveryNewBar) + { + if(lastBarTime < iTime(_Symbol, _Period, 0)) + { + lastBarTime = iTime(_Symbol, _Period, 0) + 1; + IsReadEveryNewBar = true; + } + } + else + { + IsReadEveryNewBar = true; + } + + if(nextReadTime <= TimeCurrent() || IsReadEveryNewBar) + { + nextReadTime = TimeCurrent() + userReadEveryXSeconds; + NewReadTime = true; + } + } + + return(NewReadTime); + +}//IsNewReadTime() + +//+------------------------------------------------------------------+ +//| | +//+------------------------------------------------------------------+ +bool IsNewBar() +{ + //many thanks renexxxx + //+1 deals with multiple ticks per second + + bool newBar = false; + + if ( lastBarTime2 < iTime( _Symbol, _Period, 0 ) ) { + lastBarTime2 = iTime( _Symbol, _Period, 0 ) + 1; + newBar = true; + } + return(newBar); + +}//IsNewBar() + +//+------------------------------------------------------------------+ +//| getSlope() | +//+------------------------------------------------------------------+ +double GetSlope( int tf, int maperiod, int atrperiod, int pShift ) +{ + double dblTma, dblPrev; + int shiftWithoutSunday = pShift; + if ( _BrokerHasSundayCandles && PERIOD_CURRENT == PERIOD_D1 ) + { + if ( TimeDayOfWeek( iTime( NULL, PERIOD_D1, pShift ) ) == 0 ) shiftWithoutSunday++; + } + + double atr = iATR( NULL, tf, atrperiod, shiftWithoutSunday + 10 ) / 10; + double result = 0.0; + if ( atr != 0 ) + { + dblTma = iMA( NULL, tf, maperiod, 0, MODE_LWMA, PRICE_CLOSE, shiftWithoutSunday ); + dblPrev = ( iMA( NULL, tf, maperiod, 0, MODE_LWMA, PRICE_CLOSE, shiftWithoutSunday + 1 ) * 231 + iClose( NULL, tf, shiftWithoutSunday ) * 20 ) / 251; + + result = ( dblTma - dblPrev ) / atr; + } + + return ( result ); + +}//GetSlope(} + +//+------------------------------------------------------------------+ +//| | +//+------------------------------------------------------------------+ +void fireAlerts(string sMsg) +{ + if(PopupAlert) + Alert(sMsg); + if(EmailAlert) + SendMail("CSS Alert "+"",sMsg); + if(PushAlert) + SendNotification(sMsg); + +}//fireAlerts() + +//+------------------------------------------------------------------+ +// StrToTF(string str) | +//+------------------------------------------------------------------+ +// Converts a timeframe string to its MT4-numeric value +// Usage: int x=StrToTF("M15") returns x=15 +int StrToTF(string str) +{ + str = StringUpper(str); + str = StringTrimLeft(str); + str = StringTrimRight(str); + + if (str == "M1") return(1); + if (str == "M5") return(5); + if (str == "M15") return(15); + if (str == "M30") return(30); + if (str == "H1") return(60); + if (str == "H4") return(240); + if (str == "D1") return(1440); + if (str == "W1") return(10080); + if (str == "MN" || str == "MN1") return(43200); + + return(0); + +} //End StrToTF(string str) + +//+------------------------------------------------------------------+ +//| StringUpper(string str) | +//+------------------------------------------------------------------+ +// Converts any lowercase characters in a string to uppercase +// Usage: string x=StringUpper("The Quick Brown Fox") returns x = "THE QUICK BROWN FOX" +string StringUpper(string str) +{ + string outstr = ""; + string lower = "abcdefghijklmnopqrstuvwxyz"; + string upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + for(int i=0; i=0) + outstr = outstr + StringSubstr(upper,t1,1); + else + outstr = outstr + StringSubstr(str,i,1); + } + return(outstr); + +}//StringUpper(string str) + +//+------------------------------------------------------------------+ +//| TF to String | +//+------------------------------------------------------------------+ +string TFToString(int tf) +{ + switch(tf) { + case 1: return("M1"); break; + case 5: return("M5"); break; + case 15: return("M15"); break; + case 30: return("M30"); break; + case 60: return("H1"); break; + case 240: return("H4"); break; + case 1440: return("D1"); break; + case 10080: return("W1"); break; + case 43200: return("MN"); break; + default: return(TFToString(_Period)); + } + + return(TFToString(_Period)); + +}//TFToString(int tf) + +//+------------------------------------------------------------------+ +//| | +//+------------------------------------------------------------------+ +string StringSubstrOld(string x, int a, int b=-1) +{ + if(a<0) a=0; //stop odd behaviour + if(b<=0) b=-1; //new MQL4 EOL flag + + return StringSubstr(x,a,b); + +}//StringSubstrOld() + +//+------------------------------------------------------------------+ +//| Creating Text object | +//+------------------------------------------------------------------+ +void TextCreate(const string pName = "Text", // object name + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const string text = "Text", // the text itself + const color clr = clrRed, // color + const ENUM_ANCHOR_POINT anchor = ANCHOR_LEFT_UPPER, // anchor type + const string font = "Wingdings", // font + const int font_size = 14, // font size + const double angle = 0.0, // text slope + const bool back = true, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long z_order = 0 + ) +{ + long chart_ID = ChartID(); + string name = pName; + + if ( ObjectFind( chart_ID, name ) < 0 ) + { + if ( !ObjectCreate( chart_ID, name, OBJ_TEXT, 0, time, price ) ) + { + Print(__FUNCTION__, ": failed to create \"Text\" object! Error code = ", GetLastError() ); + return; + } + } + + ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); + ObjectSetString(chart_ID,name,OBJPROP_FONT,font); + ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size); + ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle); + ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor); + ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); + ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); + ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); + ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); + ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); + ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); + +}//TextCreate() + +//+------------------------------------------------------------------+ +//| | +//+------------------------------------------------------------------+ +void initTimeFrames() +{ + if(!autoTimeFrame) + { + userTimeFrame = StrToTF(timeFrame); //css & left column + userExtraTimeFrame = StrToTF(extraTimeFrame); //center column + userExtraTimeFrame2 = StrToTF(extraTimeFrame2); //right column + } + else + { + //Auto Time Frame + + //userTimeFrame = css & left column = chart tf + //userExtraTimeFrame = center column = higher tf + //userExtraTimeFrame2 = right column = lower tf + + //---- + + //Chart TF ~ css & left column + userTimeFrame=_Period; + + //Higher TF ~ center column + if( userTimeFrame == PERIOD_M1 ) userExtraTimeFrame = PERIOD_M5; + else if( userTimeFrame == PERIOD_M5 ) userExtraTimeFrame = PERIOD_M15; + else if( userTimeFrame == PERIOD_M15 ) userExtraTimeFrame = PERIOD_M30; + else if( userTimeFrame == PERIOD_M30 ) userExtraTimeFrame = PERIOD_H1; + else if( userTimeFrame == PERIOD_H1 ) userExtraTimeFrame = PERIOD_H4; + else if( userTimeFrame == PERIOD_H4 ) userExtraTimeFrame = PERIOD_D1; + else if( userTimeFrame == PERIOD_D1 ) userExtraTimeFrame = PERIOD_W1; + else if( userTimeFrame == PERIOD_W1 ) userExtraTimeFrame = PERIOD_MN1; + else if( userTimeFrame == PERIOD_MN1 ) userExtraTimeFrame = PERIOD_MN1; + + //Lower TF ~ right column + if( userTimeFrame == PERIOD_M1 ) userExtraTimeFrame2 = PERIOD_M1; + else if( userTimeFrame == PERIOD_M5 ) userExtraTimeFrame2 = PERIOD_M1; + else if( userTimeFrame == PERIOD_M15 ) userExtraTimeFrame2 = PERIOD_M5; + else if( userTimeFrame == PERIOD_M30 ) userExtraTimeFrame2 = PERIOD_M15; + else if( userTimeFrame == PERIOD_H1 ) userExtraTimeFrame2 = PERIOD_M30; + else if( userTimeFrame == PERIOD_H4 ) userExtraTimeFrame2 = PERIOD_H1; + else if( userTimeFrame == PERIOD_D1 ) userExtraTimeFrame2 = PERIOD_H4; + else if( userTimeFrame == PERIOD_W1 ) userExtraTimeFrame2 = PERIOD_D1; + else if( userTimeFrame == PERIOD_MN1 ) userExtraTimeFrame2 = PERIOD_W1; + } + +}//initTimeFrames() + +//+------------------------------------------------------------------+ +//| ShowCurrencyTable() | +//+------------------------------------------------------------------+ +void ShowCurrencyTable(int tf, int column, int rightBar2) +{ + int i=0; + string showText; + + //get diff digits for display + int diffdigits=GetDecimalValue(differenceThreshold); + + //no alerts on initialization or visual backtests + bool OkToSendAlerts = (!IsInit && column == 1 && rightBar2 == 0 && IsItNewBar); + + if(showSlopeValues) + { + //first time frame + if(column == 1) + { + //header + objectName=almostUniqueIndex+"_css_obj_column1_tf"+ObjSuff; + if(ObjectFind(objectName)==-1) + { + if(ObjectCreate(objectName,OBJ_LABEL,windex,0,0)) + { + ObjectSet(objectName,OBJPROP_CORNER,1); + ObjectSet(objectName,OBJPROP_XDISTANCE,horizontalOffset+10+horizontalShift*6); + ObjectSet(objectName,OBJPROP_YDISTANCE,verticalOffset); + ObjectSet(objectName,OBJPROP_HIDDEN,true); + } + } + ObjectSetText(objectName,TFToString(userTimeFrame),displayTextSize,nonPropFont,colorTimeframe); + + //value + objectName=almostUniqueIndex+"_css_obj_column1_value1"+ObjSuff; + if(ObjectFind(objectName)==-1) + { + if(ObjectCreate(objectName,OBJ_LABEL,windex,0,0)) + { + ObjectSet(objectName,OBJPROP_CORNER,1); + ObjectSet(objectName,OBJPROP_XDISTANCE,horizontalOffset+horizontalShift*6); + ObjectSet(objectName,OBJPROP_YDISTANCE,verticalOffset+verticalShift*1.5); + ObjectSet(objectName,OBJPROP_HIDDEN,true); + } + } + showText=DoubleToStr(Slope1[rightBar2],2); + ObjectSetText(objectName,showText,displayTextSize,nonPropFont,currencyColors[index]); + + }//if(column == 1) + + //second time frame + if(column == 2) + { + //header + objectName=almostUniqueIndex+"_css_obj_column2_tf"+ObjSuff; + if(ObjectFind(objectName)==-1) + { + if(ObjectCreate(objectName,OBJ_LABEL,windex,0,0)) + { + ObjectSet(objectName,OBJPROP_CORNER,1); + ObjectSet(objectName,OBJPROP_XDISTANCE,horizontalOffset+10+horizontalShift*3); + ObjectSet(objectName,OBJPROP_YDISTANCE,verticalOffset); + ObjectSet(objectName,OBJPROP_HIDDEN,true); + } + } + ObjectSetText(objectName,TFToString(userExtraTimeFrame),displayTextSize,nonPropFont,colorTimeframe); + + //value + objectName=almostUniqueIndex+"_css_obj_column2_value1"+ObjSuff; + if(ObjectFind(objectName)==-1) + { + if(ObjectCreate(objectName,OBJ_LABEL,windex,0,0)) + { + ObjectSet(objectName,OBJPROP_CORNER,1); + ObjectSet(objectName,OBJPROP_XDISTANCE,horizontalOffset+horizontalShift*3); + ObjectSet(objectName,OBJPROP_YDISTANCE,verticalOffset+verticalShift*1.5); + ObjectSet(objectName,OBJPROP_HIDDEN,true); + } + } + showText=DoubleToStr(Slope_2,2); + ObjectSetText(objectName,showText,displayTextSize,nonPropFont,currencyColors[index]); + + }//if(column == 2) + + //third time frame + if(column == 3) + { + //header + objectName=almostUniqueIndex+"_css_obj_column3_tf"+ObjSuff; + if(ObjectFind(objectName)==-1) + { + if(ObjectCreate(objectName,OBJ_LABEL,windex,0,0)) + { + ObjectSet(objectName,OBJPROP_CORNER,1); + ObjectSet(objectName,OBJPROP_XDISTANCE,horizontalOffset+10); + ObjectSet(objectName,OBJPROP_YDISTANCE,verticalOffset); + ObjectSet(objectName,OBJPROP_HIDDEN,true); + } + } + ObjectSetText(objectName,TFToString(userExtraTimeFrame2),displayTextSize,nonPropFont,colorTimeframe); + + //value + objectName=almostUniqueIndex+"_css_obj_column3_value1"+ObjSuff; + if(ObjectFind(objectName)==-1) + { + if(ObjectCreate(objectName,OBJ_LABEL,windex,0,0)) + { + ObjectSet(objectName,OBJPROP_CORNER,1); + ObjectSet(objectName,OBJPROP_XDISTANCE,horizontalOffset); + ObjectSet(objectName,OBJPROP_YDISTANCE,verticalOffset+verticalShift*1.5); + ObjectSet(objectName,OBJPROP_HIDDEN,true); + } + } + showText=DoubleToStr(Slope_3,2); + ObjectSetText(objectName,showText,displayTextSize,nonPropFont,currencyColors[index]); + + }//if(column == 3) + + }//if(showSlopeValues) + + /////////////////////////////////////////////////////////////////////////// + + + //threshold + if(showDifferenceThreshold && column == 4) + { + objectName=almostUniqueIndex+"_css_obj_diff"+ObjSuff; + if(ObjectFind(objectName)==-1) + { + if(ObjectCreate(objectName,OBJ_LABEL,windex,0,0)) + { + ObjectSet(objectName,OBJPROP_CORNER,1); + ObjectSet(objectName,OBJPROP_XDISTANCE,horizontalOffset+horizontalShift*0.25); + ObjectSet(objectName,OBJPROP_YDISTANCE,verticalOffset+verticalShift*3.75); + ObjectSet(objectName,OBJPROP_HIDDEN,true); + } + } + showText=StringSubstrOld(_Symbol,0,6)+" thresh = "+DoubleToStr(differenceThreshold,diffdigits); + ObjectSetText(objectName,showText,8,nonPropFont,differenceThresholdColor); + + }//if(showDifferenceThreshold && column == 4) + + //////////////////////////////////////////////////////////////////////////////////////////// + + + //PopUp alert Stuff + if(OkToSendAlerts) + { + if(sendCrossAlerts) + { + //curr1 crosses up curr2 (buy) + if(Slope1[i+1] < differenceThreshold*0.5 && Slope1[i] > differenceThreshold*0.5) + fireAlerts(_Symbol+" did a cross up "+TFToString(tf)+" @"+DoubleToStr(Bid,_Digits)+"__"+TimeToStr(TimeCurrent(), TIME_MINUTES)); + + //curr1 crosses down curr2 (sell) + if(Slope1[i+1] > -differenceThreshold*0.5 && Slope1[i] < -differenceThreshold*0.5) + fireAlerts(_Symbol+" did a cross down "+TFToString(tf)+" @"+DoubleToStr(Bid,_Digits)+"__"+TimeToStr(TimeCurrent(), TIME_MINUTES)); + + }//if(sendCrossAlerts) + + if(sendLevelCrossAlerts) + { + //curr1 crosses up levelCrossValue +2.0 + if(Slope1[i+1] < levelCrossValue && Slope1[i] > levelCrossValue) + fireAlerts(_Symbol+" did a cross up "+DoubleToStr(levelCrossValue,2)+" "+TFToString(tf)+" @"+DoubleToStr(Bid,_Digits)+"__"+TimeToStr(TimeCurrent(), TIME_MINUTES)); + + //curr1 crosses down levelCrossValue -2.0 + if(Slope1[i+1] > -levelCrossValue && Slope1[i] < -levelCrossValue) + fireAlerts(_Symbol+" did a cross down "+DoubleToStr(-levelCrossValue,2)+" "+TFToString(tf)+" @"+DoubleToStr(Bid,_Digits)+"__"+TimeToStr(TimeCurrent(), TIME_MINUTES)); + + }//if(sendLevelCrossAlerts) + + if(sendExitCrossAlerts) + { + //curr1 crosses down levelCrossValue +2.0 ~ exit buy + if(Slope1[i+1] > levelCrossValue && Slope1[i] < levelCrossValue) + fireAlerts(_Symbol+" did an 'exit buy' cross down "+DoubleToStr(levelCrossValue,2)+" "+TFToString(tf)+" @"+DoubleToStr(Bid,_Digits)+"__"+TimeToStr(TimeCurrent(), TIME_MINUTES)); + + //curr1 crosses up levelCrossValue -2.0 ~ exit sell + if(Slope1[i+1] < -levelCrossValue && Slope1[i] > -levelCrossValue) + fireAlerts(_Symbol+" did an 'exit sell' cross up "+DoubleToStr(-levelCrossValue,2)+" "+TFToString(tf)+" @"+DoubleToStr(Bid,_Digits)+"__"+TimeToStr(TimeCurrent(), TIME_MINUTES)); + + }//if(sendExitCrossAlerts) + + if(sendMTFAgreeAlerts) + { + //mtf agree and curr1 crosses up curr2 (buy) + if(Slope_2 > differenceThreshold*0.5 && Slope_3 > differenceThreshold*0.5 && Slope1[i+1] < differenceThreshold*0.5 && Slope1[i] > differenceThreshold*0.5) + fireAlerts(_Symbol+" MTF agree with a cross up "+TFToString(tf)+" @"+DoubleToStr(Bid,_Digits)+"__"+TimeToStr(TimeCurrent(), TIME_MINUTES)); + + //mtf agree and curr1 crosses down curr2 (sell) + if(Slope_2 < -differenceThreshold*0.5 && Slope_3 < -differenceThreshold*0.5 && Slope1[i+1] > -differenceThreshold*0.5 && Slope1[i] < -differenceThreshold*0.5) + fireAlerts(_Symbol+" MTF agree with a cross down "+TFToString(tf)+" @"+DoubleToStr(Bid,_Digits)+"__"+TimeToStr(TimeCurrent(), TIME_MINUTES)); + + }//if(sendMTFAgreeAlerts) + + }//if(OkToSendAlerts) + +}//showCurrencyTable() + +//+------------------------------------------------------------------+ +//| getCurrencyIndex(string currency) | +//+------------------------------------------------------------------+ +int getCurrencyIndex(string currency) + { + for(int i=0; i=1;i--) + { + if(StringSubstrOld(str,i-1,1) == "0") + count++; + else + break; + } + + decval = slen - count - leftofdec; + + if(decval < 1) decval=1; + + return(decval); + +}//GetDecimalValue(double val) + +//+------------------------------------------------------------------+ +//| CSS_Available() | +//+------------------------------------------------------------------+ +bool CSS_Available(string symbol2check) +{ + for(int i = 0; i < ArraySize(currencyNames); i++){ + if(StringSubstr(symbol2check, 0, 3)== currencyNames[i]) + return(true); + } + return(false); +} + +//+------------------------------------------------------------------+ diff --git a/Oscillators/SuperSlope.mq5.fixme b/Oscillators/SuperSlope.mq5.fixme new file mode 100644 index 0000000..8d7c8bc --- /dev/null +++ b/Oscillators/SuperSlope.mq5.fixme @@ -0,0 +1,83 @@ +/** + * @file + * Implements indicator under MQL5. + */ + +// Defines indicator properties. +#property indicator_separate_window + +#property indicator_buffers 4 +#property indicator_plots 4 + +// Define indicator properties +#property indicator_type1 DRAW_LINE +#property indicator_color1 Gray +#property indicator_label1 "Slope" + +#property indicator_type2 DRAW_ARROW +#property indicator_color2 Lime +#property indicator_label2 "Long" + +#property indicator_type3 DRAW_ARROW +#property indicator_color3 Red +#property indicator_label3 "Short" + +#property indicator_type4 DRAW_ARROW +#property indicator_color4 Gray +#property indicator_label4 "Flat" + +#property indicator_level1 0.0 + +// Includes. +#include + +// Includes EA31337 framework. +#include +#include +#include +#include + +// Defines macros. +#define extern input +#define Bars (ChartStatic::iBars(_Symbol, _Period)) +#define Bid (SymbolInfoStatic::GetBid(_Symbol)) +#define TimeDayOfWeek (DateTime::DateOfWeek()) + +// Define global functions. +#undef DoubleToStr +string DoubleToStr(double _value) { return ::DoubleToString(_value); } +string DoubleToStr(double _value, int _digits) { + return ::DoubleToString(_value, _digits); +} +int WindowsTotal(const long _cid = 0) { + long result = -1; + ResetLastError(); + if (!ChartGetInteger(_cid, CHART_WINDOWS_TOTAL, 0, result)) { + Print(__FUNCTION__ + "(): Error code = ", GetLastError()); + } + return (int)result; +} + +// Includes the main file. +#include "SuperSlope.mq4" + +// Custom indicator initialization function. +/* +void OnInit() { + init(); + if (!ArrayGetAsSeries(Slope1)) { + ArraySetAsSeries(Slope1, true); + ArraySetAsSeries(Slope2, true); + } +} +*/ + +// Custom indicator iteration function. +/* +int OnCalculate(const int rates_total, const int prev_calculated, + const int begin, const double &price[]) { + IndicatorCounted(fmin(prev_calculated, Bars)); + ResetLastError(); + return start() >= 0 ? rates_total : 0; +} +*/ diff --git a/Oscillators/TDI-RT-Clone.mq4 b/Oscillators/TDI-RT-Clone.mq4 new file mode 100644 index 0000000..bed4889 --- /dev/null +++ b/Oscillators/TDI-RT-Clone.mq4 @@ -0,0 +1,122 @@ +/*------------------------------------------------------------------------------------ + Name: TDI-RT-Clone.mq4 + + Description: A clone of the TDI indicator. + The volatility bands and the market base line are not exactly the same + but they are close enough. + +-------------------------------------------------------------------------------------*/ +// Indicator properties +#property copyright "www.xaphod.com" +#property link "www.xaphod.com" +#property strict +#property version "1.600" +#property description "A clone of the TDI-RT indicator" +#property description "RT indicating that it updates in Real Time, ie on every tick." +#property description "The volatility bands and the market base line are not exactly the same but they are close enough." +#property indicator_separate_window +#property indicator_buffers 6 +#property indicator_color1 clrBlue +#property indicator_width1 1 +#property indicator_color2 clrBlue +#property indicator_width2 1 +#property indicator_color3 clrYellow +#property indicator_width3 1 +#property indicator_color4 clrRed +#property indicator_width4 2 +#property indicator_color5 clrGreen +#property indicator_width5 2 +#property indicator_color6 CLR_NONE +#property indicator_width6 1 +#property indicator_level1 32 +#property indicator_level2 50 +#property indicator_level3 68 +#property indicator_levelstyle STYLE_DOT +#property indicator_levelcolor DimGray + +#define INDICATOR_NAME "TDI-RT-Clone" + +// Indicator parameters +extern int RSI_Period=13; +extern ENUM_APPLIED_PRICE RSI_Price=PRICE_CLOSE; +extern int Volatility_Band=34; +extern int RSISignal_Period=2; +extern ENUM_MA_METHOD RSISignal_Mode=MODE_SMA; +extern int TradeSignal_Period=7; +extern ENUM_MA_METHOD TradeSignal_Mode=MODE_SMA; + + +// Global module varables +double gdaRSI[]; +double gdaRSISig[]; +double gdaTradeSig[]; +double gdaMktBase[]; +double gdaVolaTop[]; +double gdaVolaBtm[]; + + +//----------------------------------------------------------------------------- +// function: init() +// Description: Custom indicator initialization function. +//----------------------------------------------------------------------------- +int init() { + SetIndexStyle(0, DRAW_LINE); + SetIndexBuffer(0, gdaVolaTop); + SetIndexLabel(0,"Volatility Top"); + SetIndexStyle(1, DRAW_LINE); + SetIndexBuffer(1, gdaVolaBtm); + SetIndexLabel(1,"Volatility Bottom"); + SetIndexStyle(2, DRAW_LINE); + SetIndexBuffer(2, gdaMktBase); + SetIndexLabel(3,"Market Base"); + SetIndexStyle(3, DRAW_LINE); + SetIndexBuffer(3, gdaTradeSig); + SetIndexLabel(3,"Trade Signal"); + SetIndexStyle(4, DRAW_LINE); + SetIndexBuffer(4, gdaRSISig); + SetIndexLabel(4,"RSI Signal"); + + SetIndexStyle(5, DRAW_NONE); + SetIndexBuffer(5, gdaRSI); + SetIndexLabel(5,NULL); + IndicatorDigits(1); + IndicatorShortName(INDICATOR_NAME); + return(0); +} + +//----------------------------------------------------------------------------- +// function: deinit() +// Description: Custom indicator deinitialization function. +//----------------------------------------------------------------------------- +int deinit() { + return (0); +} + + +///----------------------------------------------------------------------------- +// function: start() +// Description: Custom indicator iteration function. +//----------------------------------------------------------------------------- +int start() { + int iNewBars, iCountedBars, i; + + // Get unprocessed bars + iCountedBars=IndicatorCounted(); + if(iCountedBars < 0) return (-1); + if(iCountedBars>0) iCountedBars--; + iNewBars=MathMin(Bars-iCountedBars, Bars-1); + + // Calc TDI data + for(i=iNewBars-1; i>=0; i--) { + gdaRSI[i] = iRSI(NULL,0,RSI_Period,RSI_Price,i); + } + for(i=iNewBars-1; i>=0; i--) { + gdaRSISig[i]=iMAOnArray(gdaRSI,iNewBars,RSISignal_Period,0,RSISignal_Mode,i); + gdaTradeSig[i]=iMAOnArray(gdaRSI,iNewBars,TradeSignal_Period,0,TradeSignal_Mode,i); + gdaMktBase[i]=iMAOnArray(gdaRSI,iNewBars,Volatility_Band,0,MODE_SMA,i); + gdaVolaTop[i]=gdaMktBase[i]+1.6185 * iStdDevOnArray(gdaRSI,iNewBars,Volatility_Band,0,MODE_SMA,i); + gdaVolaBtm[i]=gdaMktBase[i]-1.6185 * iStdDevOnArray(gdaRSI,iNewBars,Volatility_Band,0,MODE_SMA,i); + } + return(0); +} +//+------------------------------------------------------------------+ diff --git a/Oscillators/TDI-RT-Clone.mq5 b/Oscillators/TDI-RT-Clone.mq5 new file mode 100644 index 0000000..f53a6f5 --- /dev/null +++ b/Oscillators/TDI-RT-Clone.mq5 @@ -0,0 +1,62 @@ +/** + * @file + * Implements indicator under MQL5. + */ + +// Defines indicator properties. +#property indicator_separate_window + +#property indicator_buffers 6 +#property indicator_plots 5 +#property indicator_color1 clrBlue +#property indicator_width1 1 +#property indicator_color2 clrBlue +#property indicator_width2 1 +#property indicator_color3 clrYellow +#property indicator_width3 1 +#property indicator_color4 clrRed +#property indicator_width4 2 +#property indicator_color5 clrGreen +#property indicator_width5 2 +#property indicator_color6 CLR_NONE +#property indicator_width6 1 +#property indicator_level1 32 +#property indicator_level2 50 +#property indicator_level3 68 +#property indicator_levelstyle STYLE_DOT +#property indicator_levelcolor DimGray + +// Includes EA31337 framework. +#include +#include +#include + +// Defines macros. +#define extern input +#define Bars fmin(10000, (ChartStatic::iBars(_Symbol, _Period))) +#define Bid (SymbolInfoStatic::GetBid(_Symbol)) +#define TimeDayOfWeek (DateTime::DateOfWeek()) + +// Includes the main file. +#include "TDI-RT-Clone.mq4" + +// Custom indicator initialization function. +void OnInit() { + init(); + if (!ArrayGetAsSeries(gdaRSI)) { + ArraySetAsSeries(gdaRSI, true); + ArraySetAsSeries(gdaRSISig, true); + ArraySetAsSeries(gdaTradeSig, true); + ArraySetAsSeries(gdaMktBase, true); + ArraySetAsSeries(gdaVolaTop, true); + ArraySetAsSeries(gdaVolaBtm, true); + } +} + +// Custom indicator iteration function. +int OnCalculate(const int rates_total, const int prev_calculated, + const int begin, const double &price[]) { + IndicatorCounted(fmin(prev_calculated, Bars)); + ResetLastError(); + return start() >= 0 ? rates_total : 0; +} diff --git a/Oscillators/Traders Dynamic Index.mq4 b/Oscillators/Traders Dynamic Index.mq4 new file mode 100644 index 0000000..7900b8f --- /dev/null +++ b/Oscillators/Traders Dynamic Index.mq4 @@ -0,0 +1,180 @@ +//+------------------------------------------------------------------+ +//| Traders Dynamic Index.mq4 | +//| Copyright © 2006, Dean Malone | +//| www.compassfx.com | +//+------------------------------------------------------------------+ + +//+------------------------------------------------------------------+ +//| | +//| Traders Dynamic Index | +//| | +//| This hybrid indicator is developed to assist traders in their | +//| ability to decipher and monitor market conditions related to | +//| trend direction, market strength, and market volatility. | +//| | +//| Even though comprehensive, the T.D.I. is easy to read and use. | +//| | +//| Green line = RSI Price line | +//| Red line = Trade Signal line | +//| Blue lines = Volatility Band | +//| Yellow line = Market Base Line | +//| | +//| Trend Direction - Immediate and Overall | +//| Immediate = Green over Red...price action is moving up. | +//| Red over Green...price action is moving down. | +//| | +//| Overall = Yellow line trends up and down generally between the | +//| lines 32 & 68. Watch for Yellow line to bounces off | +//| these lines for market reversal. Trade long when | +//| price is above the Yellow line, and trade short when | +//| price is below. | +//| | +//| Market Strength & Volatility - Immediate and Overall | +//| Immediate = Green Line - Strong = Steep slope up or down. | +//| Weak = Moderate to Flat slope. | +//| | +//| Overall = Blue Lines - When expanding, market is strong and | +//| trending. When constricting, market is weak and | +//| in a range. When the Blue lines are extremely tight | +//| in a narrow range, expect an economic announcement | +//| or other market condition to spike the market. | +//| | +//| | +//| Entry conditions | +//| Scalping - Long = Green over Red, Short = Red over Green | +//| Active - Long = Green over Red & Yellow lines | +//| Short = Red over Green & Yellow lines | +//| Moderate - Long = Green over Red, Yellow, & 50 lines | +//| Short= Red over Green, Green below Yellow & 50 line | +//| | +//| Exit conditions* | +//| Long = Green crosses below Red | +//| Short = Green crosses above Red | +//| * If Green crosses either Blue lines, consider exiting when | +//| when the Green line crosses back over the Blue line. | +//| | +//| | +//| IMPORTANT: The default settings are well tested and proven. | +//| But, you can change the settings to fit your | +//| trading style. | +//| | +//| | +//| Price & Line Type settings: | +//| RSI Price settings | +//| 0 = Close price [DEFAULT] | +//| 1 = Open price. | +//| 2 = High price. | +//| 3 = Low price. | +//| 4 = Median price, (high+low)/2. | +//| 5 = Typical price, (high+low+close)/3. | +//| 6 = Weighted close price, (high+low+close+close)/4. | +//| | +//| RSI Price Line & Signal Line Type settings | +//| 0 = Simple moving average [DEFAULT] | +//| 1 = Exponential moving average | +//| 2 = Smoothed moving average | +//| 3 = Linear weighted moving average | +//| | +//| Good trading, | +//| | +//| Dean | +//+------------------------------------------------------------------+ + + + +#property indicator_buffers 6 +#property indicator_color1 Black +#property indicator_color2 0XFFFFFFFF // MediumBlue +#property indicator_color3 0xFFFFFFFF // Yellow +#property indicator_color4 0XFFFFFFFF // MediumBlue +#property indicator_color5 Green +#property indicator_color6 Red +#property indicator_separate_window + +extern int RSI_Period = 13; //8-25 +extern int RSI_Price = 0; //0-6 +extern int Volatility_Band = 34; //20-40 +extern int RSI_Price_Line = 2; +extern int RSI_Price_Type = 0; //0-3 +extern int Trade_Signal_Line = 7; +extern int Trade_Signal_Type = 0; //0-3 + +double RSIBuf[],UpZone[],MdZone[],DnZone[],MaBuf[],MbBuf[]; + +int init() + { + IndicatorShortName("TDI"); + SetIndexBuffer(0,RSIBuf); + SetIndexBuffer(1,UpZone); + SetIndexBuffer(2,MdZone); + SetIndexBuffer(3,DnZone); + SetIndexBuffer(4,MaBuf); + SetIndexBuffer(5,MbBuf); + + SetIndexStyle(0,DRAW_NONE); + SetIndexStyle(1,DRAW_LINE); + SetIndexStyle(2,DRAW_LINE); //,0,2 + SetIndexStyle(3,DRAW_LINE); + SetIndexStyle(4,DRAW_LINE); //,0,2 + SetIndexStyle(5,DRAW_LINE); //,0,2 + + SetIndexLabel(0,NULL); + SetIndexLabel(1,"VB High"); + SetIndexLabel(2,"Market Base Line"); + SetIndexLabel(3,"VB Low"); + SetIndexLabel(4,"RSI Price Line"); + SetIndexLabel(5,"Trade Signal Line"); + +#ifdef __MQL4__ + SetLevelValue(0,50); + SetLevelValue(1,68); + SetLevelValue(2,32); + SetLevelStyle(STYLE_DOT,1,DimGray); +#endif + + return(0); + } + +int start() + { + double MA,RSI[]; + ArrayResize(RSI,Volatility_Band); + int counted_bars=IndicatorCounted(); + int i; + int limit = Bars-counted_bars-1; + for(i=limit; i>=0; i--) + { + RSIBuf[i] = (iRSI(NULL,0,RSI_Period,RSI_Price,i)); + MA = 0; + for(int x=i; x=0;i--) + { + MaBuf[i] = (iMAOnArray(RSIBuf,0,RSI_Price_Line,0,RSI_Price_Type,i)); + MbBuf[i] = (iMAOnArray(RSIBuf,0,Trade_Signal_Line,0,Trade_Signal_Type,i)); + } +//---- + return(0); + } + +double StDev(double& Data[], int Per) +{ + return(MathSqrt(Variance(Data,Per))); +} +double Variance(double& Data[], int Per) +{ + double sum = 0.0, ssum = 0.0; + for (int i=0; i +#include +#include + +// Defines macros. +#define extern input +#define Bars fmin(10000, (ChartStatic::iBars(_Symbol, _Period))) +#define Bid (SymbolInfoStatic::GetBid(_Symbol)) +#define TimeDayOfWeek (DateTime::DateOfWeek()) + +// Includes the main file. +#include "Traders Dynamic Index.mq4" + +// Custom indicator initialization function. +void OnInit() { + init(); + if (!ArrayGetAsSeries(RSIBuf)) { + ArraySetAsSeries(RSIBuf, true); + ArraySetAsSeries(UpZone, true); + ArraySetAsSeries(MdZone, true); + ArraySetAsSeries(DnZone, true); + ArraySetAsSeries(MaBuf, true); + ArraySetAsSeries(MbBuf, true); + } +} + +// Custom indicator iteration function. +int OnCalculate(const int rates_total, const int prev_calculated, + const int begin, const double &price[]) { + IndicatorCounted(fmin(prev_calculated, Bars)); + ResetLastError(); + return start() >= 0 ? rates_total : 0; +} diff --git a/Price/Multi/OHLC/Heiken_Ashi_Smoothed.mq4 b/Price/Multi/OHLC/Heiken_Ashi_Smoothed.mq4 new file mode 100644 index 0000000..da5f7dc --- /dev/null +++ b/Price/Multi/OHLC/Heiken_Ashi_Smoothed.mq4 @@ -0,0 +1,123 @@ +//+------------------------------------------------------------------+ +//| Heiken Ashi Smoothed.mq4 | +//+------------------------------------------------------------------+ +//| mod by Raff | +//+------------------------------------------------------------------+ +#property copyright "Copyright © 2006, Forex-TSD.com " +#property link "http://www.forex-tsd.com/" + +#property indicator_chart_window +#property indicator_buffers 4 +#property indicator_color1 LightSalmon +#property indicator_color2 Lime +#property indicator_color3 LightSalmon +#property indicator_color4 Lime +//---- parameters +extern int MaMetod = 2; +extern int MaPeriod = 6; +extern int MaMetod2 = 3; +extern int MaPeriod2 = 2; +//---- buffers +double ExtMapBuffer1[]; +double ExtMapBuffer2[]; +double ExtMapBuffer3[]; +double ExtMapBuffer4[]; +double ExtMapBuffer5[]; +double ExtMapBuffer6[]; +double ExtMapBuffer7[]; +double ExtMapBuffer8[]; +//---- +int ExtCountedBars=0; +//+------------------------------------------------------------------+ +//| Custom indicator initialization function | +//|------------------------------------------------------------------| +int init() + { +//---- indicators + IndicatorBuffers(8); + + SetIndexStyle(0,DRAW_HISTOGRAM, 0, 1, LightSalmon); + SetIndexBuffer(0, ExtMapBuffer1); + SetIndexStyle(1,DRAW_HISTOGRAM, 0, 1, Lime); + SetIndexBuffer(1, ExtMapBuffer2); + SetIndexStyle(2,DRAW_HISTOGRAM, 0, 3, LightSalmon); + SetIndexBuffer(2, ExtMapBuffer3); + SetIndexStyle(3,DRAW_HISTOGRAM, 0, 3, Lime); + SetIndexBuffer(3, ExtMapBuffer4); +//---- + SetIndexDrawBegin(0,5); +//---- indicator buffers mapping + SetIndexBuffer(0,ExtMapBuffer1); + SetIndexBuffer(1,ExtMapBuffer2); + SetIndexBuffer(2,ExtMapBuffer3); + SetIndexBuffer(3,ExtMapBuffer4); + SetIndexBuffer(4,ExtMapBuffer5); + SetIndexBuffer(5,ExtMapBuffer6); + SetIndexBuffer(6,ExtMapBuffer7); + SetIndexBuffer(7,ExtMapBuffer8); +//---- initialization done + return(0); + } +//+------------------------------------------------------------------+ +//| Custor indicator deinitialization function | +//+------------------------------------------------------------------+ +int deinit() + { +//---- TODO: add your code here + +//---- + return(0); + } +//+------------------------------------------------------------------+ +//| Custom indicator iteration function | +//+------------------------------------------------------------------+ +int start() + { + double maOpen, maClose, maLow, maHigh; + double haOpen, haHigh, haLow, haClose; + if(Bars<=10) return(0); + ExtCountedBars=IndicatorCounted(); +//---- check for possible errors + if (ExtCountedBars<0) return(-1); +//---- last counted bar will be recounted + if (ExtCountedBars>0) ExtCountedBars--; + int pos=Bars-ExtCountedBars-1; + int pos2=pos; + while(pos>=0) + { + maOpen=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_OPEN,pos); + maClose=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_CLOSE,pos); + maLow=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_LOW,pos); + maHigh=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_HIGH,pos); + + haOpen=(ExtMapBuffer5[pos+1]+ExtMapBuffer6[pos+1])/2; + haClose=(maOpen+maHigh+maLow+maClose)/4; + haHigh=MathMax(maHigh, MathMax(haOpen, haClose)); + haLow=MathMin(maLow, MathMin(haOpen, haClose)); + + if (haOpen +#include +#include + +// Defines macros. +#define extern input +#define Bars fmin(10000, (ChartStatic::iBars(_Symbol, _Period))) +#define Bid (SymbolInfoStatic::GetBid(_Symbol)) +#define TimeDayOfWeek (DateTime::DateOfWeek()) + +// Includes the main file. +#include "Heiken_Ashi_Smoothed.mq4" + +// Custom indicator initialization function. +void OnInit() { + init(); + if (!ArrayGetAsSeries(ExtMapBuffer1)) { + ArraySetAsSeries(ExtMapBuffer1, true); + ArraySetAsSeries(ExtMapBuffer2, true); + ArraySetAsSeries(ExtMapBuffer3, true); + ArraySetAsSeries(ExtMapBuffer4, true); + ArraySetAsSeries(ExtMapBuffer5, true); + ArraySetAsSeries(ExtMapBuffer6, true); + ArraySetAsSeries(ExtMapBuffer7, true); + ArraySetAsSeries(ExtMapBuffer8, true); + } +} + +// Custom indicator iteration function. +int OnCalculate(const int rates_total, const int prev_calculated, + const int begin, const double &price[]) { + IndicatorCounted(fmin(prev_calculated, Bars)); + ResetLastError(); + return start() >= 0 ? rates_total : 0; +} diff --git a/Price/Multi/OHLC/README.md b/Price/Multi/OHLC/README.md new file mode 100644 index 0000000..b384718 --- /dev/null +++ b/Price/Multi/OHLC/README.md @@ -0,0 +1,38 @@ +# OHLC indicators + +OHLC (Open-High-Low-Close) indicators are a specific category of technical indicators +used to generate values based on the open, high, low, and close prices of an asset. +The OHLC values can be used to construct candlestick charts, +which visually represent the price movements in the market. + +One example of an OHLC indicator is the Heikin-Ashi (HA) indicator. +Heikin-Ashi is known for its ability to filter out the noise +of day-to-day price fluctuations and provide a smoother representation of price data. +It achieves this by using a modified formula based on average price values. + +The Heikin-Ashi method calculates the open, high, low, and close values +based on the average of the previous candle's OHLC values. +This averaging technique helps to reduce the impact of sudden price spikes or gaps, +resulting in smoother candlestick patterns. +The modified candlestick charts generated by the Heikin-Ashi indicator +can provide clearer signals for identifying market trends and forecasting price movements. + +OHLC indicators, can be used in conjunction with other indicators or analysis +techniques. The OHLC values they produce can serve as input for other +indicators allowing traders to derive additional insights or develop trading +strategies based on the price data. + +By utilizing OHLC indicators, traders can gain a better understanding of price dynamics, +identify key support and resistance levels, and recognize patterns +that may indicate potential trading opportunities. +The visual representation of OHLC values through candlestick charts +facilitates the interpretation of market sentiment and price action. + +## Heikin Ashi Smoothed + +The Heikin Ashi Smoothed indicator is a variation of the Heikin Ashi indicator, +which itself is a type of OHLC indicator used to represent price movements +more smoothly and filter out noise. The Heikin Ashi Smoothed indicator +takes the concept of Heikin Ashi a step further by applying smoothing +techniques to the calculations by The calculating the moving averages (MA) +of the open, close, low, and high prices for a specified MA period. diff --git a/Price/Multi/XTrendLineX.mq4 b/Price/Multi/XTrendLineX.mq4 new file mode 100644 index 0000000..3fb6766 --- /dev/null +++ b/Price/Multi/XTrendLineX.mq4 @@ -0,0 +1,112 @@ +#property indicator_chart_window +#property indicator_buffers 5 +#property indicator_color1 Yellow +#property indicator_color2 Magenta // Sell +#property indicator_color3 DodgerBlue // Buy +#property indicator_color4 LimeGreen // Buy +#property indicator_color5 Plum // Buy + +extern ENUM_TIMEFRAMES TickChartPeriod = PERIOD_CURRENT; // Period of the original tick chart data in minutes + +bool TrendLine = true; +int TrendLineStyle = STYLE_DOT; +int TrendLineWidth = 1; +color UpperTrendLineColour = clrLimeGreen; +color LowerTrendLineColour = clrRed; + +double ChartOpen[]; // Array to store opening prices of current bars +double ChartHigh[]; // Array to store highest prices of current bars +double ChartLow[]; // Array to store lowest prices of current bars +double ChartClose[]; // Array to store closing prices of current bars +int BarNumber; // Number of bars in offline chart + +int ChartPrecision = 5; // Number of decimal places in displayed tick chart prices + +double M2O; // Multiplier used to convert ticks to offline chart bars +double LastPrice[]; // Array to store last prices received from tick chart data + +int init() { + IndicatorShortName("Tick Chart"); + + string plotLabel = "tick_chart"; + PlotIndexSetString(0, PLOT_LABEL, plotLabel); + + // Set up buffers for the arrays + SetIndexBuffer(0, ChartOpen); + SetIndexBuffer(1, ChartHigh); + SetIndexBuffer(2, ChartLow); + SetIndexBuffer(3, ChartClose); + SetIndexBuffer(4, LastPrice); + + return (0); +} + +int start() { + M2O = PeriodSeconds(Period()) / PeriodSeconds(Period()); // Calculate multiplier + BarNumber = iBars(NULL, 0) - 1; // Get number of bars in current offline chart + + // Main loop for updating offline chart data + for (int i = BarNumber; i > 0; i--) { + ChartOpen[i] = iOpen(NULL, 0, i); // Get open price of current bar + ChartHigh[i] = iHigh(NULL, 0, i); // Get high price of current bar + ChartLow[i] = iLow(NULL, 0, i); // Get low price of current bar + ChartClose[i] = iClose(NULL, 0, i); // Get close price of current bar + + // Determine current tick chart price + if (LastPrice[i] == 0) + LastPrice[i] = iClose(NULL, (int)TickChartPeriod, 0); + else + LastPrice[i] = iClose(NULL, (int)TickChartPeriod, 1); + + // Update offline chart data + if (LastPrice[i] > ChartHigh[i]) ChartHigh[i] = LastPrice[i]; + if (LastPrice[i] < ChartLow[i]) ChartLow[i] = LastPrice[i]; + ChartClose[i] = LastPrice[i]; + + RefreshRates(); // Refresh market data + LastPrice[i] = NormalizeDouble(LastPrice[i], ChartPrecision); // Round tick chart price + + PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, 0.0); + ChartOpen[i - 1] = LastPrice[i]; + // PlotIndexSetDouble(0, i - 1, ChartOpen[i - 1]); + } + + if (TrendLine) { + // Delete previous trendlines + // Delete previous trendlines + for (int j = ObjectsTotal() - 1; j >= 0; j--) { + string objName = ObjectName(j); + if (StringSubstr(objName, 0, 4) == "HHL_") ObjectDelete(objName); + } + + // Draw trendlines + int numBars = iBars(NULL, 0); + int stepSize = (int)MathPow(10, ChartPrecision); // Step size for trendline drawing + int startBar = (int)(numBars - MathFloor((double)numBars / stepSize * stepSize)); + int endBar = numBars - 1; + + if (TrendLine) { + for (int k = startBar; k < endBar; k += stepSize) { + TrendLineLowTD(k, endBar, k, TrendLineStyle, LowerTrendLineColour); + } + } + } + + return (0); +} + +int TrendLineLowTD(int L1, int i, int Step, double St, int Col) { + double price = ChartLow[i] + (ChartLow[L1] - ChartLow[i]) / (i - L1) * i; + ObjectSet("HHL_" + (string)Step, OBJPROP_TIME1, Time[i]); + ObjectSet("LL_" + (string)Step, OBJPROP_TIME2, Time[L1]); + ObjectCreate("HHL_" + (string)Step, OBJ_HLINE, 0, 0, price); + ObjectSet("HHL_" + (string)Step, OBJPROP_STYLE, St); + + ObjectSet("HHL_" + (string)Step, OBJPROP_BACK, true); // Line added + ObjectSet("HHL_" + (string)Step, OBJPROP_COLOR, LowerTrendLineColour); + if (Step == 1) + ObjectSet("HHL_" + (string)Step, OBJPROP_WIDTH, TrendLineWidth); + else + ObjectSet("HHL_" + (string)Step, OBJPROP_WIDTH, 1); + return (0); +} diff --git a/Price/Multi/XTrendLineX.mq5 b/Price/Multi/XTrendLineX.mq5 new file mode 100644 index 0000000..c2ed03b --- /dev/null +++ b/Price/Multi/XTrendLineX.mq5 @@ -0,0 +1,70 @@ +/** + * @file + * Implements indicator under MQL5. + */ + +// Defines indicator properties. +#property indicator_chart_window +#property indicator_buffers 5 +#property indicator_plots 5 +#property indicator_color1 Yellow +#property indicator_color2 Magenta // Sell +#property indicator_color3 DodgerBlue // Buy +#property indicator_color4 LimeGreen // Buy +#property indicator_color5 Plum // Buy +#property indicator_label1 "Open" +#property indicator_label2 "High" +#property indicator_label3 "Low" +#property indicator_label4 "Close" +#property indicator_label5 "Last Price" +#property indicator_type1 DRAW_LINE +#property indicator_type2 DRAW_LINE +#property indicator_type3 DRAW_LINE +#property indicator_type4 DRAW_LINE +#property indicator_type5 DRAW_LINE +#property indicator_style1 STYLE_DOT +#property indicator_style2 STYLE_DOT +#property indicator_style3 STYLE_DOT +#property indicator_style4 STYLE_DOT +#property indicator_style5 STYLE_DOT + +// Includes EA31337 framework. +#include +#include + +// Defines macros. +#define extern input +#define Bars (ChartStatic::iBars(_Symbol, _Period)) +bool RefreshRates() { return Market::RefreshRates(); } + +// Includes the main file. +#include "XTrendLineX.mq4" + +// Custom indicator initialization function. +void OnInit() { + init(); + PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, 0); + PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, 0); + PlotIndexSetInteger(2, PLOT_DRAW_BEGIN, 0); + PlotIndexSetInteger(3, PLOT_DRAW_BEGIN, 0); + PlotIndexSetInteger(4, PLOT_DRAW_BEGIN, 0); + PlotIndexSetString(0, PLOT_LABEL, "Open"); + PlotIndexSetString(1, PLOT_LABEL, "High"); + PlotIndexSetString(2, PLOT_LABEL, "Low"); + PlotIndexSetString(3, PLOT_LABEL, "Close"); + PlotIndexSetString(4, PLOT_LABEL, "Price"); + if (!ArrayGetAsSeries(ChartOpen)) { + ArraySetAsSeries(ChartOpen, true); + ArraySetAsSeries(ChartHigh, true); + ArraySetAsSeries(ChartLow, true); + ArraySetAsSeries(ChartClose, true); + ArraySetAsSeries(LastPrice, true); + } +} + +// Custom indicator iteration function. +int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { + IndicatorCounted(fmin(prev_calculated, Bars)); + ResetLastError(); + return start() >= 0 ? rates_total : 0; +} diff --git a/PriceBands/SAWA.mq4 b/Price/Range/SAWA.mq4 similarity index 100% rename from PriceBands/SAWA.mq4 rename to Price/Range/SAWA.mq4 diff --git a/PriceBands/SAWA.mq5 b/Price/Range/SAWA.mq5 similarity index 100% rename from PriceBands/SAWA.mq5 rename to Price/Range/SAWA.mq5 diff --git a/PriceBands/TMA+CG_mladen_NRP.mq4 b/Price/Range/TMA+CG_mladen_NRP.mq4 similarity index 100% rename from PriceBands/TMA+CG_mladen_NRP.mq4 rename to Price/Range/TMA+CG_mladen_NRP.mq4 diff --git a/PriceBands/TMA+CG_mladen_NRP.mq5 b/Price/Range/TMA+CG_mladen_NRP.mq5 similarity index 100% rename from PriceBands/TMA+CG_mladen_NRP.mq5 rename to Price/Range/TMA+CG_mladen_NRP.mq5 diff --git a/PriceBands/TMA_True.mq4 b/Price/Range/TMA_True.mq4 similarity index 100% rename from PriceBands/TMA_True.mq4 rename to Price/Range/TMA_True.mq4 diff --git a/PriceBands/TMA_True.mq5 b/Price/Range/TMA_True.mq5 similarity index 100% rename from PriceBands/TMA_True.mq5 rename to Price/Range/TMA_True.mq5 diff --git a/README.md b/README.md index 0b5841c..689abd8 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Related project: | v1.011 | v1.011.1 | | v1.012 | v2.012.1 | | v1.013 | v2.013 | +| v2.000 | v3.000.1 | diff --git a/enum.h b/enum.h new file mode 100644 index 0000000..ff73a76 --- /dev/null +++ b/enum.h @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 - multi-strategy advanced trading robot | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://github.com/EA31337 | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef ENUM_INDICATOR_OTHER_DEFINED +// Defines enum with supported indicator list. +enum ENUM_INDICATOR_OTHER { + INDI_OTHER_0_NONE = 0, // (None) + INDI_OTHER_MISC_ATR_MA_TREND, // Misc: ATR MA Trend + INDI_OTHER_OSC_SUPERSLOPE, // Oscillator: Super Slope + INDI_OTHER_OSC_TDI, // Oscillator: TDI (Traders Dynamic Index) + INDI_OTHER_OSC_TDI_RT_CLONE, // Oscillator: TDI-RT-Clone + INDI_OTHER_OSC_TMA_CG, // Oscillator: TMA CG + INDI_OTHER_PRICE_EWO2, // Oscillator: Elliott Wave Oscillator 2 + INDI_OTHER_PRICE_MULTI_OHLC_HA_SMOOTHED, // Price/Range: SVE Bollinger Bands + INDI_OTHER_PRICE_RANGE_SVE_BB, // Price/Range: SVE Bollinger Bands +}; +#define ENUM_INDICATOR_OTHER_DEFINED +#endif