commit 0a19e0f4e1de64051aa1ded083d0835d19e10b17 Author: Hadi Khazaee Asl Date: Thu Jan 25 04:03:36 2024 +0330 Initial Commit ... diff --git a/.gitkeep b/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Docs/R&D/Candlestick.Patterns.md b/Docs/R&D/Candlestick.Patterns.md new file mode 100644 index 0000000..4222bba --- /dev/null +++ b/Docs/R&D/Candlestick.Patterns.md @@ -0,0 +1,134 @@ +# Candlestick Patters + +## Doji + +X_CT_DOJI + +- Continue Trend +- Maybe end of a Trend + +## Evening Star + +X_CT_EVENING_STAR + +- Bearish +- End of Bullish Trend + +## Morning Star + +X_CT_MORNING_STAR + +- Bullish +- End of Bearish Trend + +## Shooting Star + +X_CT_SHOOTING_STAR + +- Bearish +- End of Bullish Trend + +## Hammer + +X_CT_HAMMER + +- Bullish +- End of Bearish Trend + +## Inverted Hammer + +X_CT_INVERTED_HAMMER + +- Bullish +- End of Bearish Trend + +## Bearish Harami + +X_CT_BEARISH_HARAMI + +- Bearish +- End Of Bullish Trend + +## Bullish Harami + +X_CT_BULLISH_HARAMI + +- Bullish +- End of Bearish Trend + +## Bearish Engulfing + +X_CT_BEARISH_ENGULFING + +- Bearish +- End of Bullish Trend + +## Bullish Engulfing + +X_CT_BULLISH_ENGULFING + +- Bullish +- End of Bearish Trend + +## Piercing Line + +X_CT_PRICE_LINE + +- Bearish +- End of Bullish Trend + +## Bullish Belt + +X_CT_BULLISH_BELT + +- Bullish +- End of Bearish Trend + +## Bullish Kicker + +X_CT_BULLISH_KICKER + +- Bullish +- End of Bearish Trend + +## Bearish Kicker + +X_CT_BEARISH_KICKER + +- Bearish +- End of Bullish Trend + +## Hanging Man + +X_CT_HANGING_MAN + +- Bearish +- End of Bullish Trend + +## Dark Cloud Cover + +X_CT_DARK_CLOUD_COVER + +- Bearish +- End of Bullish Trend + +## Bullish Candles + +X_CT_HAMMER +X_CT_BULLISH_BELT +X_CT_MORNING_STAR +X_CT_BULLISH_KICKER +X_CT_BULLISH_HARAMI +X_CT_INVERTED_HAMMER +X_CT_BULLISH_ENGULFING + +## Bearish Candles + +X_CT_PRICE_LINE +X_CT_HANGING_MAN +X_CT_EVENING_STAR +X_CT_SHOOTING_STAR +X_CT_BEARISH_HARAMI +X_CT_BEARISH_KICKER +X_CT_DARK_CLOUD_COVER +X_CT_BEARISH_ENGULFING diff --git a/Docs/R&D/EMA.md b/Docs/R&D/EMA.md new file mode 100644 index 0000000..8516441 --- /dev/null +++ b/Docs/R&D/EMA.md @@ -0,0 +1,15 @@ +# EMA + +The EMA is designed to improve on the idea of an SMA by giving more weight to the most recent price data, which is considered to be more relevant than older data. Since new data carries greater weight, the EMA responds more quickly to price changes than the SMA does. + +## Fromula + +EMA = Price(t) × k + EMA(y) × (1−k) + +where: + +t = today +y = yesterday +N = number of days in EMA +k = 2 ÷ (N + 1) +​ diff --git a/Docs/R&D/ichimoku.md b/Docs/R&D/ichimoku.md new file mode 100644 index 0000000..f58e80b --- /dev/null +++ b/Docs/R&D/ichimoku.md @@ -0,0 +1,14 @@ +# Ichimoku + +1. **Conversion Line** (*tenkan sen*) => **9-PH+9-PL**/**2** +2. **Base Line** (*kijun sen*) => **26-PH + 26-PL**/**2** +3. **Leading Span A** (*senkou span A*) => **CL + Base Line**/**2** +4. **Leading Span B** (*senkou span B*) => **52-PH + 52-PL**/**2** +5. **Lagging Span** (*chikou span*) => **Close plotted 26 periods in the past** + +## where + +**PH** = Period high +**PL** = Period low +**CL** = Conversion line +​ diff --git a/Docs/Samples/Angle.md b/Docs/Samples/Angle.md new file mode 100644 index 0000000..6f4c0b6 --- /dev/null +++ b/Docs/Samples/Angle.md @@ -0,0 +1,3 @@ +# Angle + +tan A = | (m - m’) / (1 + mm’ ) | diff --git a/Docs/Samples/ArraySetAsSeries.md b/Docs/Samples/ArraySetAsSeries.md new file mode 100644 index 0000000..81be7d8 --- /dev/null +++ b/Docs/Samples/ArraySetAsSeries.md @@ -0,0 +1,26 @@ +# ArraySetAsSeries + +The function sets the AS_SERIES flag to a selected object of a dynamic array, and elements will be indexed like in timeseries. + +bool ArraySetAsSeries( + const void& array[], // array by reference + bool flag // true denotes reverse order of indexing + ); + +Parameters + +array[] + +[in][out] Numeric array to set. + +flag + +[in] Array indexing direction. + +Return Value + +The function returns true on success, otherwise - false. + +Note + +The AS_SERIES flag can't be set for multi-dimensional arrays or static arrays (arrays, whose size in square brackets is preset already on the compilation stage). Indexing in timeseries differs from a common array in that the elements of timeseries are indexed from the end towards the beginning (from the newest to oldest data). \ No newline at end of file diff --git a/Docs/Samples/Ask&Bid.md b/Docs/Samples/Ask&Bid.md new file mode 100644 index 0000000..91bb5d9 --- /dev/null +++ b/Docs/Samples/Ask&Bid.md @@ -0,0 +1,3 @@ +# Note on Bid and Ask + +The Bid price is what you see on the MT4 charts, and the Ask price is just a few pips above the bid price, with the difference between them being the spread. We open buy orders and close sell orders on the Ask price; we open sell orders and close buy orders on the Bid price. diff --git a/Docs/Samples/BarIndex.md b/Docs/Samples/BarIndex.md new file mode 100644 index 0000000..2d6910c --- /dev/null +++ b/Docs/Samples/BarIndex.md @@ -0,0 +1,50 @@ +# BarIndex + +in pine script bar_index reffers to current candle number, in reversal indexing. +in MQL for accessing bar_index to calculate indicator data, we have to do something like this: + +```mq4 +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[]) + { + // + // here we define our limit ... + int limit = rates_total - prev_calculated; + + // + // if our indicator requires some candles to pass as a length, + // and then start calculating by past passed values, by this way + // we are going to inform MQL Compiler, which do nothing, until + // required length passed ... + if(rates_total <= InpBullsPeriod) { + return(0); + } + + // + // because bar index a zero start indexing system, for fixing + // qctual indexing in for loops, we have to call this ... + if(prev_calculated > 0) { + limit++; + } + + // + // Loop through Bar Indexes ... + for(int i = 0; i < limit; i++) { + // + // Filling Exists Buffers, based on current Bar Index and required Conditions ... + ExtTempBuffer[i]=iMA(NULL,0,InpBullsPeriod,0,MODE_EMA,PRICE_CLOSE,i); + ExtBullsBuffer[i]=high[i]-ExtTempBuffer[i]; + } + + // + return(rates_total); +} +``` diff --git a/Docs/Samples/CCI.EA.SL.TP.Tutorial.md b/Docs/Samples/CCI.EA.SL.TP.Tutorial.md new file mode 100644 index 0000000..131f86a --- /dev/null +++ b/Docs/Samples/CCI.EA.SL.TP.Tutorial.md @@ -0,0 +1,407 @@ +# CCI EA With SL and TP + +this tutorial consists 5 part: + +1. Create a CCI EA with SL and TP; +2. add a Moving Average Filter on a higher Timeframe; +3. add a Partial Close; +4. add a Break Event Stop; +5. Backtesting; + +## Create a CCI EA with SL and TP + +CCI is an Oscillator which provides some usefull data about iver baughts and over solds. +each of this situations can used as a signal. + +the general idea in this tutorial is to use this states as a signal and then open and close positions based on them ... + +Create a Expert Advisor and named it what you want. + +now we have to read CCI data. create a pointer to it's iFunction and then create a buffer based on it on OnTick function. +we can now create a buy and sell conditions and check where this happens to open the positions. + +the idea is when cci going above special level we get buy signal and when going below special level we get sell signal. + +for implement this mechanism, first add two input for buyLevel and sellLevel and give them default values. + +```mq4 +#include + +// +CTrade trader; + +// +input double Lots = 1; +input double TpPoints = 100; +input double SlPoints = 100; + +// +input double CciBuyLevel = -150; +input double CciSellLevel = 150; + +// +int barsTotal; + +// +int OnInit() { + // + barsTotal = iBars(_Symbol, CciTimeFrame); + + // + OnTick(); + + // + return INIT_SUCCEEDED; +} + +// +void OnTick() { + // + // for every single tick, we check current amount of bars + // for preventing double signaling on single bar ... + int bars = iBars(_Symbol, CciTimeframe); + if (barsTotal < bars) { + // + barsTotal = bars; + + // + double cci[]; + CopyBuffer(cciPointer, 0, 1, 2, cci); + + // + // Buy Signal Condition ... + if (cci[1] < CciBuyLevel && cci[0] > CciBuyLevel) { + // + // Do Buy Trade ... + + // + // retrieve ask price ... + // since trader.Buy alway use market price (ask price) ... + double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Normalize ask price ... + ask = NormalizeDouble(ask, _Digits); + + // + // Calculating Tp based on Ask price ... + double tp = ask + TpPoints * _Point; + tp = NormalizeDouble(tp, _Digits); + + + // + // Calculating Sl based on Ask price ... + double sl = ask - SlPoints * _Point; + sl = NormalizeDouble(sl, _Digits); + + // + trader.Buy(Lots, _Symbol, ask, sl, tp, "CCI Buy ..."); + } else + // + // Sell Signal Condition ... + if (cci[1] > CciSellLevel && cci[0] < CciSellLevel) { + // + // Do Sell Trade ... + + // + // retrieve bid price ... + // since trader.Sell alway use market price (bid price) ... + double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID); + + // + // Normalize bid price ... + bid = NormalizeDouble(bid, _Digits); + + // + // Calculating Tp based on Bid price ... + double tp = bid - TpPoints * _Point; + tp = NormalizeDouble(tp, _Digits); + + + // + // Calculating Sl based on Bid price ... + double sl = bid + SlPoints * _Point; + sl = NormalizeDouble(sl, _Digits); + + // + trader.Sell(Lots, _Symbol, bid, sl, tp, "CCI Sell ..."); + } + + // + // Show data on Chart side ... + Comment("\nCCI[0]: ", cci[0], + "\nCCI[1]: ", cci[1] + ); + } +} +``` + +## add a Moving Average Filter on a higher Timeframe + +moving average is another usefull indicator which provides a way to following market trend direction. +the idea is to accdept signals in direction of ma result. +so we have to implement Moving average in our EA then use it's values for filtering signals, this is what we call MA Verifications. + +attached proper inputs related to MA Indicator to your advisor. + +then create a Pointer(Handler) for iFunction of MA indicator. + +we have to check for buy signals, that the ask price is above than moving average. and for sell signals the bid price is below than moving average, then if this conditions +are full filled, enter the positions. + +```mq4 +void OnTick() { + ... + + // + // reading ma series, buffer ... + double ma[]; + CopyBuffer(maPointer, 0, 1, 1, ma); + + // + // Buy Signal Condition ... + if (cci[1] < CciBuyLevel && cci[0] > CciBuyLevel) { + // + // Do Buy Trade ... + + // + // retrieve ask price ... + // since trader.Buy alway use market price (ask price) ... + double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Filter by Moving Average ... + if (ask > ma[0]) { + ... + } + } else + // + // Sell Signal Condition ... + if (cci[1] > CciSellLevel && cci[0] < CciSellLevel) { + // + // Do Sell Trade ... + + // + // retrieve bid price ... + // since trader.Sell alway use market price (bid price) ... + double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID); + + // + // Filter by Moving Average ... + if (bid < ma[0]) { + ... + } + } + + ... + + // + // Show data on Chart side ... + Comment("\nCCI[0]: ", cci[0], + "\nCCI[1]: ", cci[1], + "\nMA[0]: ", ma[0], + ); +} +``` + +## add a Partial Close + +partial close positions is an idea to save money more than usual in trading exit strategy. +actually implementing CTrade instance provide this for us. and we can use it in our EAs. + +in this section we are going to review how we can do it ... + +```mq4 +// +// Define Some Inputs for Partial Close Positions Management ... +input int PartialClosePoints = 70; +input double PartialCloseFactor = 0.5; + +... + +// +void OnTick() { + + ... + + // + // Calculate Ask and Bid Price values ... + double ask = ... + double bid = ... + + // + // here we loop through all open Positions ... + for (int i = PositionsTotal() - 1; i >=0; i--) { + // + // retrieve position ticket ... + ulong positionTicket = PositionGetTicket(i); + + // + // retrieve Position by it's Ticket ... + if (PositionSelectByTicket(positionTicket)) { + // + // now we can check conditions ... + + // + // Retrieve Position Open Price ... + double positionOpenPrice = PositionGetDouble(POSITION_PRICE_OPEN); + + // + // Retrieve Position Volume ... + double positionVolume = PositionGetDouble(POSITION_VOLUME); + + // + // Retrieve Position Type: Buy or Sell Position ... + ENUM_POSITION_TYPE positionType = (ENUM_POSITION_TYPE) PositionGetInteger(POSITION_TYPE); + + // + // now we have check position volume, for prevent partialy closing a partial closed position ... + if (positionVolume == Lots) { + // + // Calculate Partially close volume ... + double lotsToClose = positionVolume * PartialCloseFactor; + lotsToClose = NormalizeDouble(lotsToClose, 2); + + // + // Check Position Type and do Partial Close based on Separation Type ... + if (positionType == POSITION_TYPE_BUY) { + // + // Partialy Close Buy Positions ... + if (bid > positionOpenPrice + PartialClosePoints * _Point) { + // + // Try to Partially Close Position ... + if (trade.PositionClosePartial(positionTicket, lotsToClose)) { + // + // show a simple message ... + Print("Pos ", positionTicket, " was closed partially ..."); + } + } + } else if (positionType == POSITION_TYPE_SELL) { + // + // Partialy Close Sell Positions ... + if (ask < positionOpenPrice - PartialClosePoints * _Point) { + // + // Try to Partially Close Position ... + if (trade.PositionClosePartial(positionTicket, lotsToClose)) { + // + // show a simple message ... + Print("Pos ", positionTicket, " was closed partially ..."); + } + } + } + } + } + } +} +``` + +## add a Break Event Stop + +some times is some trades we need to make a position risk free. +this means when a position triggered at specified point of profits, move sl to specified point. + +for example we have a buy position of 100.100 price. +we need to move it's sl when bid price touch 100.150 to 100.105 + +moving sl of a position called Break Event ... + +for this reason we have to specify 2 pqarams: + +- TriggerPoint: this is a value which we change sl of position when or open price of position changed by this point; +- PufferPoint: this is a value which we change sl based on it. + +```mq4 +void OnTick() { + + ... + + // + // here we loop through all open Positions ... + for (int i = PositionsTotal() - 1; i >=0; i--) { + // + // retrieve position ticket ... + ulong positionTicket = PositionGetTicket(i); + + // + // retrieve Position by it's Ticket ... + if (PositionSelectByTicket(positionTicket)) { + // + // now we can check conditions ... + + // + // Retrieve Position Open Price ... + double positionOpenPrice = PositionGetDouble(POSITION_PRICE_OPEN); + + // + // Retrieve Position TP ... + double positionTP = PositionGetDouble(POSITION_TP); + + // + // Retrieve Position SL ... + double positionSL = PositionGetDouble(POSITION_SL); + + // + // Retrieve Position Volume ... + double positionVolume = PositionGetDouble(POSITION_VOLUME); + + // + // Retrieve Position Type: Buy or Sell Position ... + ENUM_POSITION_TYPE positionType = (ENUM_POSITION_TYPE) PositionGetInteger(POSITION_TYPE); + + // + // Check Position Type and do Partial Close based on Separation Type ... + if (positionType == POSITION_TYPE_BUY) { + // + // Break Event Buy Positions ... + + // + // Check if Price recive to value for changing sl ... + if (bid > positionOpenPrice + BETriggerPoint * _Point) { + // + // Calculate new SL Price ... + double sl = positionOpenPrice + BEPufferPoint * _Points; + sl = NormalizeDouble(sl, _Digits); + + // + // Check new Calculated SL be Bigger than current SL ... + if (sl > positionSL) { + // + // Modify Trade and Change it's SL ... + if (trader.PositionModify(positionTicket, sl, positionTp)) { + // + Print("Pos ", poistionTicket, " was saved as Break Event ..."); + } + } + } + } else if (positionType == POSITION_TYPE_SELL) { + // + // Break Event Sell Positions ... + + // + // Check if Price recive to value for changing sl ... + if (ask < positionOpenPrice - BETriggerPoint * _Point) { + // + // Calculate new SL Price ... + double sl = positionOpenPrice - BEPufferPoint * _Points; + sl = NormalizeDouble(sl, _Digits); + + // + // Check new Calculated SL be Bigger than current SL ... + if (sl < positionSL) { + // + // Modify Trade and Change it's SL ... + if (trader.PositionModify(positionTicket, sl, positionTp)) { + // + Print("Pos ", poistionTicket, " was saved as Break Event ..."); + } + } + } + } + } + } +} +``` + +## Backtesting + +you must use Strategy tester in back test ... \ No newline at end of file diff --git a/Docs/Samples/CandleIndexing.md b/Docs/Samples/CandleIndexing.md new file mode 100644 index 0000000..e6c3422 --- /dev/null +++ b/Docs/Samples/CandleIndexing.md @@ -0,0 +1,4 @@ +# Candle Indexing + +like Pine Script, in MQL 4 or 5 Candles, Buffers and Series indexed in reversal pattern. +this is an important note ... diff --git a/Docs/Samples/Chart.Indicator.Tutorial.md b/Docs/Samples/Chart.Indicator.Tutorial.md new file mode 100644 index 0000000..f121b5f --- /dev/null +++ b/Docs/Samples/Chart.Indicator.Tutorial.md @@ -0,0 +1,129 @@ +# Chart Indicator Tutorial + +## Create Indicator + +open meta editor and create a new custom indicator. + +## Inputs + +we have to show 2 lines in chart as my indicator, so in creation time, i specified these on input window: + +line 1 => Line => Red +line 2 => Line => Yellow + +in this section if you check the Indicator in separate window, you tell the MT4 which this is an Oscillator. + +after finish this section and source code will opened in meta editor. +you can see how it defined as source code ... + +i will complete all next works on the source code, and comment it ... + +## Source Code + +```mq4 +// +// these line are comment lines and no necessary ... +//+------------------------------------------------------------------+ +//| x-saherelm-custom-indicator.mq4 | +//| Copyright 2023, SaherElm IT Center. | +//| https://www.saherelm.ir | +//+------------------------------------------------------------------+ + +// +// all compiler options defines using # sign ... + +// +// here define some global properties of indicator ... +// these are not necessary, but provides some usefull info about indicator itself ... +#property copyright "Copyright 2023, SaherElm IT Center." +#property link "https://www.saherelm.ir" +#property version "1.00" + +// +// use for improvement compiling ... +#property strict + +// +// here we tell this is usually indicator which +// represent's on chart itself ... +#property indicator_chart_window + +// +// define which buffers processed using this indicator ... +#property indicator_buffers 2 + +// +// define which plots represent using this indicator ... +#property indicator_plots 2 + +// +// here we declare plot line1 to system ... +#property indicator_label1 "line1" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrLime +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +// +// here we declare plot line2 to system ... +#property indicator_label2 "line2" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_SOLID +#property indicator_width2 1 + +// +// here we declare indicator buffers ... +double line1Buffer[]; +double line2Buffer[]; + +// +//+------------------------------------------------------------------+ +//| Custom indicator initialization function | +//+------------------------------------------------------------------+ + +// +// this event handle used to initialize what we want to use and what we +// can do on indicator ... +int OnInit() { + // + // indicator buffers mapping ... + // we must assign which buffer must used to drawn which plot ... + SetIndexBuffer(0,line1Buffer); + SetIndexBuffer(1,line2Buffer); + + // + // this means initialization end's successfully ... + return(INIT_SUCCEEDED); +} + +// +//+------------------------------------------------------------------+ +//| Custom indicator iteration function | +//+------------------------------------------------------------------+ + +// +// this event handler calls with system every time a change happens on price ( new tick ) ... +// all of calculatings must be done in this section ... +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[] +) { + // + // here we must do all of indicator related calculations and fill buffers for drawing plots on chart ... + + // + // return value of prev_calculated for next call + return(rates_total); +} + +// +//+------------------------------------------------------------------+ +``` diff --git a/Docs/Samples/ChartRedraw.md b/Docs/Samples/ChartRedraw.md new file mode 100644 index 0000000..4831483 --- /dev/null +++ b/Docs/Samples/ChartRedraw.md @@ -0,0 +1,6 @@ +# ChartRedraw + +```mq4 +//--- redraw the chart and wait for 1 second + ChartRedraw(); +``` diff --git a/Docs/Samples/Comment.md b/Docs/Samples/Comment.md new file mode 100644 index 0000000..a9b67eb --- /dev/null +++ b/Docs/Samples/Comment.md @@ -0,0 +1,5 @@ +# Comment + +by this command you can show som data on charts window itself. +this data can be change through candles. + diff --git a/Docs/Samples/CopyBuffer.md b/Docs/Samples/CopyBuffer.md new file mode 100644 index 0000000..e69de29 diff --git a/Docs/Samples/DrawFibonnaciTemplate.md b/Docs/Samples/DrawFibonnaciTemplate.md new file mode 100644 index 0000000..2ba4183 --- /dev/null +++ b/Docs/Samples/DrawFibonnaciTemplate.md @@ -0,0 +1,203 @@ +# DrawFibonnaci + +```mq4 + // + // START Draw Fibonachi Retracement Object ... + // + // // + // int fibIndex = 0; + // int fibLevelsCount = 6; + // int fibLevelWidths[6]; + // color fibLevelColors[6]; + // double fibLevelValues[6]; + // string fibLevelDescriptions[6]; + // ENUM_LINE_STYLE fibLevelStyles[6]; + + // // + // // Level 1 ... + // // 0.0 + // // clrGray ... + // fibLevelValues[fibIndex] = 0.0; + // fibLevelColors[fibIndex] = clrGray; + // fibLevelStyles[fibIndex] = STYLE_DOT; + // fibLevelWidths[fibIndex] = 1; + // fibLevelDescriptions[fibIndex] = "0.0 @ %$"; + // fibIndex++; + + // // + // // Level 2 ... + // // 0.236 + // // clrOliveDrab ... + // fibLevelValues[fibIndex] = 0.236; + // fibLevelColors[fibIndex] = clrOliveDrab; + // fibLevelStyles[fibIndex] = STYLE_DOT; + // fibLevelWidths[fibIndex] = 1; + // fibLevelDescriptions[fibIndex] = "0.236 @ %$"; + // fibIndex++; + + // // + // // Level 3 ... + // // 0.382 + // // clrYellow ... + // fibLevelValues[fibIndex] = 0.382; + // fibLevelColors[fibIndex] = clrYellow; + // fibLevelStyles[fibIndex] = STYLE_DASHDOTDOT; + // fibLevelWidths[fibIndex] = 1; + // fibLevelDescriptions[fibIndex] = "0.382 @ %$"; + // fibIndex++; + + // // + // // Level 4 ... + // // 0.5 + // // clrLime ... + // fibLevelValues[fibIndex] = 0.5; + // fibLevelColors[fibIndex] = clrLime; + // fibLevelStyles[fibIndex] = STYLE_DASHDOT; + // fibLevelWidths[fibIndex] = 1; + // fibLevelDescriptions[fibIndex] = "0.5 @ %$"; + // fibIndex++; + + // // + // // Level 5 ... + // // 0.618 + // // clrYellow ... + // fibLevelValues[fibIndex] = 0.618; + // fibLevelColors[fibIndex] = clrYellow; + // fibLevelStyles[fibIndex] = STYLE_DASHDOTDOT; + // fibLevelWidths[fibIndex] = 1; + // fibLevelDescriptions[fibIndex] = "0.618 @ %$"; + // fibIndex++; + + // // + // // Level 6 ... + // // 1 + // // clrGray ... + // fibLevelValues[fibIndex] = 1.0; + // fibLevelColors[fibIndex] = clrGray; + // fibLevelStyles[fibIndex] = STYLE_DOT; + // fibLevelWidths[fibIndex] = 1; + // fibLevelDescriptions[fibIndex] = "1.0 @ %$"; + // fibIndex++; + + // // + // string fibName = StringConcatenate( + // signalPrefix, + // "_[", totalSignals, "]_", + // "[Fibo]" + // ); + + // // + // double fibDestPrice = hasLongSignal ? + // slInfo.longSL : + // slInfo.shortSL; + + // // + // // Draw Fibonacci on Signal Propposed Area ... + // DrawCustomFibonacci( + // fibLevelsCount, + // fibLevelValues, + // fibLevelColors, + // fibLevelStyles, + // fibLevelWidths, + // fibLevelDescriptions, + // 0, // Chart ID ... + // fibName, // Object Name ... + // 0, // SubWindow ... + // zigZagHighTime, // Time 1 ... + // zigZagHigh, // Price 1 ... + // time, // Time 2 ... + // fibDestPrice, // Price 2 ... + // clrCadetBlue // Fib Aroow Color ... + // ); + + // + // TODO: now we have to analyse Entry Point (price), using Fib ... + // string fibLevel3Description = ""; + // fibLevel3Description = ObjectGetFiboDescription(fibName, 2); + // string message = StringConcatenate( + // "Fib Level 3 Desc: ", + // fibLevel3Description + // ); + // LogMessage(fibLevel3Description); + + // // + // // + // string fibLevel5Description = ""; + + // + double fibDestPrice = hasLongSignal ? + slInfo.longSL : + slInfo.shortSL; + + // + datetime fibTime1 = iTime( + _Symbol, + _Period, + 1 + ); + + // + datetime fibTime2 = iTime( + _Symbol, + _Period, + 0 + ); + + // + double minFibLevelValue = 0.382; + double minFibLevel = GetFibonacciLevel( + zigZagHigh, // Up ... + fibDestPrice, // Down ... + minFibLevelValue, // Level ... + X_DOWN // Direction ... + ); + string minFibLevelName = StringConcatenate( + signalPrefix, + "_[", totalSignals, "]_", + "[Fibo_0.382]" + ); + + // + // Draw minFibLevel ... + DrawTrendLine( + 0, + minFibLevelName, + 0, + fibTime1, + minFibLevel, + fibTime2, + minFibLevel, + clrYellow + ); + + // + double maxFibLevelValue = 0.618; + double maxFibLevel = GetFibonacciLevel( + zigZagHigh, // Up ... + fibDestPrice, // Down ... + maxFibLevelValue, // Level ... + X_DOWN // Direction ... + ); + string maxFibLevelName = StringConcatenate( + signalPrefix, + "_[", totalSignals, "]_", + "[Fibo_0.618]" + ); + + // + // Draw minFibLevel ... + DrawTrendLine( + 0, + minFibLevelName, + 0, + fibTime1, + maxFibLevel, + fibTime2, + maxFibLevel, + clrYellow + ); + + // + // END Draw Fibonachi Retracement Object ... + // +``` \ No newline at end of file diff --git a/Docs/Samples/DrawSignal.md b/Docs/Samples/DrawSignal.md new file mode 100644 index 0000000..f2e0318 --- /dev/null +++ b/Docs/Samples/DrawSignal.md @@ -0,0 +1,102 @@ +# Draw Signal + +```mql + // + // Draw a shape On Chart ... + if (hasLongSignal) { + // + arrowups++; + + // + string arrowUpName = StringConcatenate(signalPrefix, "_ArrowUp_", arrowups); + + // + datetime arrowTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + double arrowPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + arrowPrice = arrowPrice - (100 * _Point); + + // + // Draw Signal Arrow Shape ... + bool isDraw = DrawArrow( + 0, + arrowUpName, + 0, + arrowTime, + arrowPrice, + SYMBOL_ARROWUP, + ANCHOR_BOTTOM, + clrAqua, + STYLE_SOLID, + 3, + false, + false, + false, + 0 + ); + + // + // SL Info ... + XSLInfo slInfo = GetSwngSL(bar_index); + + // + // TP Info ... + XTPInfo tpInfo = GetTP(bar_index); + + + // + string arrowUpSLName = StringConcatenate(signalPrefix, "_SL_", arrowups); + string arrowUpTPName = StringConcatenate(signalPrefix, "_TP_", arrowups); + + // + datetime time1 = iTime( + _Symbol, + _Period, + bar_index + 1 + ); + datetime time2 = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Draw Signal SL ... + DrawTrendLine( + 0, + arrowUpSLName, + 0, + time1, + slInfo.longSL, + time2, + slInfo.longSL, + clrFuchsia, + STYLE_SOLID, + 2 + ); + + // + // Draw Signal TP ... + DrawTrendLine( + 0, + arrowUpTPName, + 0, + time1, + tpInfo.longTP, + time2, + tpInfo.longTP, + clrAqua, + STYLE_SOLID, + 2 + ); + } +``` \ No newline at end of file diff --git a/Docs/Samples/Expert.Advisor.Tutorial.md b/Docs/Samples/Expert.Advisor.Tutorial.md new file mode 100644 index 0000000..56d28ce --- /dev/null +++ b/Docs/Samples/Expert.Advisor.Tutorial.md @@ -0,0 +1,309 @@ +# EA Tutorials + +in this tutorial we cover this titles step by step: + +1. Create new Expert Advisor +2. Variables +3. Functions +4. Control Structures +5. Read Indicator Data +6. Open Trades +7. Modify Trades +8. Close Trades + +## Create new Expert Advisor + +in meta editor (f4, tools > meta editor), click on new and select expert adviser. + +as you know all mql programs runing based on event handlers. + +there are three main event handlers, which used in an EA: + +- OnInit // runs each time tf changes, or ea attached ... +- OnDeinit // runs when ea removed from chart ... +- OnTick // most important function, all of business logics implemented here ... + +you can see all of it's documents on proppered file. + +the main feature of an EA in MQL, is there are some features which helps us. such as notification of signals and auto trading abbility. + +## Variables + +usually used to store some values of specific Data Types. +so this is much better to see supported datat types in documentations. + +for using variables, you had to define a variable, also you can set init value of it's supported data type. +each variable must be specific it's own data type. + +each variable defined by assign a name to it. + +so by using this name you can assign value to it or read it assigned value ... + +## Functions + +in programming, a function can get some params and do some actions on them and return a result. +doing some actions is the permanent part of it's definition. +this means a function can only do a simple action and not have any params, and not have any return type. + +each function must contain a unioque name. + +in scope of project you can call a function by providing it's name and passing required params and also gives it's result. + +## Control Structures + +conditional operators gives an expression and determines it's result is true or false. +there are many commands in programming which used a conditional expression to act based on it's result. +by this way you can make your own business logic to control programming flow, or data flow or anything you want. + +most commonly used conditional command is if command, which used like this syntax: + +```mq4 +// +if (conditional_expression) { + // + // Blocks of code which run when conditional expression is true ... +} else { + // + // Blocks of code which run when conditional expression is false ... +} + +// +also we can make loops in programing, a loop is a code blocks which runs until a condition happens. +there are many type of loops in programming languages. + +most commonly used loops is create using for command by following this syntax: + +for (int i; i <= 6; i++) { + // + // Loop Code Block ... + Print("Loop Itrator: ", i); +} +``` + +## Read Indicator Data + +in this example we specially use RSI indicator. +but you can replace this by any other indicator you want, strusture is same; + +RSI Indicator provide a value for each candle and draw a line. this value is between 0 and 100; + +**Note** each standard indicator in MQL has a related function, which is usually starts with i{IndicatorName}, such as iRSI, iIchimoku and etc. +this functions, return specific values related to Indicator Data. +by calling this functions you can capture Indicator data for specific types of inputs. + +there are some standard inputs which usually used as params in iFunctions which i describe them in following: + +- Symbol: reffer to which symbol you need to inject it's data from indicator. (_Symbol) +- Period: reffer to which Time Frame you need to inject symbol's data on it from indicator (CURRENT_PERIOD). +- ... + +as i described before all candle related data, or indicators data, usually stores in Buffers. +by calling iFunctions, you retrieve an integer result, which it's an index number that point to a Buffer. +for using it's value, you had to create a Buffer on top of it. + +```mq4 +// +// here we define a pointer to iFunction buffer ... +// for reading values, each time we need we had to define +// a global pointer and then fill it on Init handler ... +int rsiPointer = iRSI(_Symbol, _Period, 14, PRICE_CLOSE); + +// +// define a dynamic size array, which calls Buffer ... +double rsiBuffer[]; + +// +// fill defined Buffer by iFunction Pointer ... +CopyBuffer(rsiPointer, 0, 1, 1, s); +``` + +**Note** there are some different ways in MQL4 and MQL5 to read the Pointer value. as i think this above described method is for MQL5, since in MQL4 for each bar_index, you shoud to call the iFunction once, by passing the bar to it ... + +## Open Trades + +as i described before, one of the main features an EA Programs, which used commonly is to Open Trade positions and specific conditions. + +imagine that we want to send signal for Long and Short positions, based on rsi value. +the condition is when rsi value at the current candle is abopve than 70, means Bullish Signal, and otherwise if it is below than 30 means Bearish Signal. + +we can handle this in OnTick event handler like this: + +```mq4 +// +// Prepare RSI Buffer ... +double rsi[]; +CopyBuffer(rsiPointer, 0, 1, 1, rsi); + +// +// Prepare Signal Conditions ... +if (rsi[0] > 70) { + // + // Bullish Signal ... +} else if (rsi[0] < 30) { + // + // Bearish Signal ... +} +``` + +we need to open position based on above Trading Conditions. + +at the first step we have to include Trade library in our EA Project. + +```mq4 +// +// here we include header file ... +#include + +... + +// +// now we have to define an instance of CTrade class to manipulate Positions ... +CTrade trader; +... +``` + +after create CTrade instance, we have to use it in right way and right place to manipulate positions: + +```mq4 +// +// Prepare Signal Conditions ... +if (rsi[0] > 70) { + // + // Bearish Signal ... + trader.Sell(0.001, _Symbol); +} else if (rsi[0] < 30) { + // + // Bullish Signal ... + trader.Buy(0.01. _Symbol); +} +``` + +in above example, we just open positions and there is no access to them for manipulate them. +we have to specify unique id to each position and store them somewhere in our EA to next times we have to manage or manipulate positions, simply reffer to them ... + +```mq4 +// +// Prepare Signal Conditions ... +if (rsi[0] > 70) { + // + // Bearish Signal ... + trader.Sell(0.001, _Symbol); + ulong ticket = trader.ResultOrder(); +} else if (rsi[0] < 30) { + // + // Bullish Signal ... + // we can provide tp and sl on positions ... + trader.Buy(0.01. _Symbol); + ulong ticket = trader.ResultOrder(); +} +``` + +we can simply check ticket as a global variable and then before opening new position, check it's value and then provide business logic ... + +## Modify Trades + +before do any manipulation on a position, we have to select the position itself ... + +PositionSelectByTicket is a Method which used to select a position by providing it's ticket id. +this returns a boolean value which determines position selected correctly or not ... + +[here](https://www.mql5.com/en/docs/constants/tradingconstants/positionproperties) are some resources related to position. + +for modifying an specific position, we have to use this function like following: + +```mq4 +// +// assume that this value filled on opening a position ... +ulong positionTicket; + +// +// validate position selectedsuccessfully, then try +// to manipulate it ... +if (PositionSelectByTicket(positionTicket)) { + // + // Do what ever we want to modify on popsition ... + + // + // reading some Position info ... + double positionPrice = PositionGetDouble(POSITION_PRICE_OPEN); + double positionTP = PositionGetDouble(POSITION_TP); + double positionSL = PositionGetDouble(POSITION_SL); + + // + // detect Position Type ... + // POSITION_TYPE_BUY + // POSITION_TYPE_SELL + int positionType = PositionGetInteger(POSITION_TYPE); + + // + // Check Position has SL ... + if (positionSL == 0) { + // + // here we calculate and define SL and TP for position ... + double sl = 0; + double tp = 0; + + // + // then we use PositionModify method to apply our changes on specified Position ... + trader.PositionModify(positionTicket, sl, tp); + } +} +``` + +## Close Trades + +some times we need to conditionally close an open position. maybe some times we got a reversal signal or anything else, based on our EA Business Logic. +for this we can also check positionTicket must be greater than zero. + +in following code, we update above sample to add supports for close last open position, before opening another one ... + +```mq4 +// +// Prepare Signal Conditions ... +if (rsi[0] > 70) { + // + // close last open position ... + // this condition means there are an open position ... + if (positionTicket > 0 && PositionSelectByTicket(positionTicket)) { + // + // retrieve Position Type ... + int positionType = PositionGetInteger(POSITION_TYPE); + if (positionType == POSITION_TYPE_BUY) { + // + // Close Position ... + trade.PositionClose(positionTicket); + + // + positionTicket = 0; + } + } + + // + // Bearish Signal ... + trader.Sell(0.001, _Symbol); + positionTicket = trader.ResultOrder(); +} else if (rsi[0] < 30) { + // + // close last open position ... + // this condition means there are an open position ... + if (positionTicket > 0 && PositionSelectByTicket(positionTicket)) { + // + // retrieve Position Type ... + int positionType = PositionGetInteger(POSITION_TYPE); + if (positionType == POSITION_TYPE_SELL) { + // + // Close Position ... + trade.PositionClose(positionTicket); + + // + positionTicket = 0; + } + } + + // + // Bullish Signal ... + // we can provide tp and sl on positions ... + trader.Buy(0.01. _Symbol); + positionTicket = trader.ResultOrder(); +} +``` diff --git a/Docs/Samples/ExpertAdviser.md b/Docs/Samples/ExpertAdviser.md new file mode 100644 index 0000000..df745c1 --- /dev/null +++ b/Docs/Samples/ExpertAdviser.md @@ -0,0 +1,4 @@ +# Expert Adviser + +a complete combination of all of features in meta trader to calculate anything in business logic and draw wath we want on chart. even mopre, advice some position related data to user. + diff --git a/Docs/Samples/Get.Account.Balance.md b/Docs/Samples/Get.Account.Balance.md new file mode 100644 index 0000000..6a62bf0 --- /dev/null +++ b/Docs/Samples/Get.Account.Balance.md @@ -0,0 +1,13 @@ +# Get Account Balance + +[Resource](https://docs.mql4.com/account/accountinfodouble) + +```mq4 +// +// Retrieve Account Balance ... +double Balance = AccountInfoDouble(ACCOUNT_BALANCE); + +// +// Retrieve Account Equity ... +double Equity = AccountInfoDouble(ACCOUNT_EQUITY); +``` diff --git a/Docs/Samples/Get.BID.Price.md b/Docs/Samples/Get.BID.Price.md new file mode 100644 index 0000000..8fbe777 --- /dev/null +++ b/Docs/Samples/Get.BID.Price.md @@ -0,0 +1,7 @@ +# Get Bid Price + +bid price means our buy price. + +```mq4 +double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID, _Digits)); +``` diff --git a/Docs/Samples/Input.md b/Docs/Samples/Input.md new file mode 100644 index 0000000..a907815 --- /dev/null +++ b/Docs/Samples/Input.md @@ -0,0 +1,32 @@ +# Input + +Input Variables +The input storage class defines the external variable. The input modifier is indicated before the data type. A variable with the input modifier can't be changed inside mql4-programs, such variables can be accessed for reading only. Values of input variables can be changed only by a user from the program properties window. External variables are always reinitialized immediately before the OnInit() is called. + +Example: + +//--- input parameters +input int MA_Period=13; +input int MA_Shift=0; +input ENUM_MA_METHOD MA_Method=MODE_SMMA; + +There is another way to set how your input parameter will look like in the Inputs tab. For this, place a string comment after the description of an input parameter in the same line. In this way you can make names of input parameters more understandable for users. + +//--- input parameters +input int InpMAPeriod=13; // Smoothing period +input int InpMAShift=0; // Line horizontal shift +input ENUM_MA_METHOD InpMAMethod=MODE_SMMA; // Smoothing method + +input ENUM_MA_METHOD MAMethod = MODE_EMA; + +// +// Gives time frame as an input ... +input ENUM_TIMEFRAMES Timeframe = PERIOD_CURRENT; + + +in adding input data to your advisors, indicators or etc, you can groups your input's together. +for this following below descriptions: + +int group "Moving Avarage Filter" + +every inputs appears after this, attached to created group ... diff --git a/Docs/Samples/IsNewBar.md b/Docs/Samples/IsNewBar.md new file mode 100644 index 0000000..7abeab9 --- /dev/null +++ b/Docs/Samples/IsNewBar.md @@ -0,0 +1,17 @@ +# IsNewBar + +this is a best way to find is in new bar or not ... + +```mq4 +bool IsNewBar() +{ + static datetime lastbar; + datetime curbar = (datetime)SeriesInfoInteger(_Symbol,_Period,SERIES_LASTBAR_DATE); + if(lastbar != curbar) + { + lastbar = curbar; + return true; + } + return false; +} +``` diff --git a/Docs/Samples/Libraries.md b/Docs/Samples/Libraries.md new file mode 100644 index 0000000..e220164 --- /dev/null +++ b/Docs/Samples/Libraries.md @@ -0,0 +1,12 @@ +# Libraries + +in programming there is concept which named Library, Module, Package or etc, and this concept is a place which consist of some classes and grouped functions. +this package and compiled and other programmers can only used this packages provided tools and stuffs regarding less to access it's source code. it is a BlackBox. + +in MQL Libraries compiled to files by .mqh extension, like C++, and can imports using include reserved key. + +```mq4 +#include +``` + +see Include file ... diff --git a/Docs/Samples/MQL.md b/Docs/Samples/MQL.md new file mode 100644 index 0000000..9d8e247 --- /dev/null +++ b/Docs/Samples/MQL.md @@ -0,0 +1,106 @@ +# MQL + +MetaQuotes Language 4 (MQL4) is a built-in language for programming trading strategies. This language is developed by MetaQuotes Software Corp. based on their long experience in the creation of online trading platforms. Using this language, you can create your own Expert Advisors that make trading management automated and are perfectly suitable for implementing your own trading strategies. Besides, using MQL4 you can create your own technical indicators (custom indicators), scripts and libraries. + +[Resource](https://docs.mql4.com/) + +Programs written in MetaQuotes Language 4 have different features and purposes: + +Expert Advisor is a mechanical trading system linked up to a certain chart. An Expert Advisor starts to run when an event happens that can be handled by it: events of initialization and deinitialization, event of a new tick receipt, a timer event, depth of market changing event, chart event and custom events. +An Expert Advisor can both inform you about a possibility to trade and automatically trade on an account sending orders directly to a trade server. Expert Advisors are stored in terminal_directory\MQL4\Experts. +Custom Indicator is a technical indicator written independently in addition to those already integrated into the client terminal. Like built-in indicators, they cannot trade automatically and are intended for implementing of analytical functions only. +Custom indicators are stored in terminal_directory\MQL4\Indicators +Script is a program intended for a single execution of some actions. Unlike Expert Advisors, scripts do not process any actions, except for the start event (this requires the OnStart handler function in a script). Scripts are stored in terminal_directory\MQL4\Scripts +Library is a set of custom functions intended for storing and distributing frequently used blocks of custom programs. Libraries cannot start executing by themselves. +Libraries are stored in terminal_directory\MQL4\Libraries +Include File is a source text of the most frequently used blocks of custom programs. Such files can be included into the source texts of Expert Advisors, scripts, custom indicators, and libraries at the compiling stage. The use of included files is more preferable than the use of libraries because of additional burden occurring at calling library functions. +Include files can be stored in the same directory as a source file - in this case the #include directive with double quotes is used. Another place to store include files is terminal_directory\MQL4\Include, in this case the #include directive is used with angle brackets. + +## Language Basics + +The MetaQuotes Language 4 (MQL4) is an object-oriented high-level programming language intended for writing automated trading strategies, custom technical indicators for the analysis of various financial markets. It allows not only to write a variety of expert systems, designed to operate in real time, but also create their own graphical tools to help you make trade decisions. + +MQL4 is based on the concept of the popular programming language C++. The language has enumerations, structures, classes and event handling. By increasing the number of embedded main types, the interaction of executable programs in MQL4 with other applications through dll is now as easy as possible. MQL4 syntax is similar to the syntax of C++, and this makes it easy to translate into it programs from modern programming languages. + +## Constants, Enumerations and Structures + +[Resource](https://docs.mql4.com/constants) + +To simplify the program writing and to make program texts more convenient for perception, the MQL4 language provides predefined standard constants and enumerations. Besides that, service structures are used for storing information. + +Standard constants are similar to macros and are of int type. + +The constants are grouped by their purposes: + +- [Chart constants](https://docs.mql4.com/constants/chartconstants): are used when working with price charts: opening, navigation, setting parameters; +- [Objects constants](https://docs.mql4.com/constants/objectconstants): are intended for processing graphical objects that can be created and displayed in charts; +- [Indicators constants](https://docs.mql4.com/constants/indicatorconstants): are used for working with standard and custom indicators; +- [Environment state](https://docs.mql4.com/constants/environment_state): constants describe properties of a MQL4-program, show information about a client terminal, financial instrument and current account; +- [Trade constants](https://docs.mql4.com/constants/tradingconstants): allow to specify a variety of information in the course of trading; +- [Named constants](https://docs.mql4.com/constants/namedconstants): are constants of the MQL4 language; +- [Data structures](https://docs.mql4.com/constants/structures): describe data storage formats used; +- [Codes of errors and warnings](https://docs.mql4.com/constants/errorswarnings): describe compiler messages and trading server answers to trade requests; +- [In/out constants](https://docs.mql4.com/constants/io_constants): are designed for working with file functions and displaying messages on the screen by the MessageBox() function. + +## MQL4 Programs + +For the mql4-program to operate, it must be compiled (Compile button or F7 key). Compilation should pass without errors (some warnings are possible; they should be analyzed). At this process, an executable file with the same name and with EX4 extension must be created in the corresponding directory, terminal_dir\MQL4\Experts, terminal_dir\MQL4\indicators or terminal_dir\MQL4\scripts. This file can be run. + +Operating features of MQL4 programs are described in the following sections: + +- [Program running](https://docs.mql4.com/runtime/running): order of calling predefined event-handlers. +- [Client terminal events](https://docs.mql4.com/runtime/event_fire): description of events, which can be processed in programs. +- [Call of imported functions](https://docs.mql4.com/runtime/imports): description order, allowed parameters, search details and call agreement for imported functions. +- [Runtime errors](https://docs.mql4.com/runtime/errors): getting information about runtime and critical errors. + +Expert Advisors, custom indicators and scripts are attached to one of opened charts by Drag'n'Drop method from the Navigator window. + +For an expert Advisor to stop operating, it should be removed from a chart. To do it select "Expert list" in chart context menu, then select an Expert Advisor from list and click "Remove" button. Operation of Expert Advisors is also affected by the state of the "AutoTrading" button. + +In order to stop a custom indicator, it should be removed from a chart. + +Custom indicators and Expert Advisors work until they are explicitly removed from a chart; information about attached Expert Advisors and Indicators is saved between client terminal sessions. + +Scripts are executed once and are deleted automatically upon operation completion or change of the current chart state, or upon client terminal shutdown. After the restart of the client terminal scripts are not started, because the information about them is not saved. + +Maximum one Expert Advisor, one script and unlimited number of indicators can operate in one chart. + +## How MQL Programs Run + +[Resource](https://docs.mql4.com/runtime/running) + +Right after a program is attached to a chart, it is uploaded to the client terminal memory, as well as global variable are initialized. If some global variable of the class type has a constructor, this constructor will be called during initialization of global variables. + +After that the program is waiting for an event from the client terminal. Each mql4-program should have at least one event-handler, otherwise the loaded program will not be executed. Event handlers have predefined names, parameters and return types. + +| Type | Function Name | Params | App Type | Comment | +| :-: | :-: | :-: | :-: | :-: | +int | [OnInit](https://docs.mql4.com/basis/function/events#oninit) | none | Expert Advisors, indicators and scripts | [Init](https://docs.mql4.com/runtime/event_fire#init) event handler. It allows to use the void return type. | +void | [OnDeinit](https://docs.mql4.com/basis/function/events#ondeinit) | const int reason | Expert Advisors, indicators and scripts | [Deinit](https://docs.mql4.com/runtime/event_fire#deinit) event handler. | +void | [OnStart](https://docs.mql4.com/basis/function/events#onstart) | none | scripts | [Start](https://docs.mql4.com/runtime/event_fire#start) event handler. +int | [OnCalculate](https://docs.mql4.com/basis/function/events#oncalculate) | const int rates_total,const int prev_calculated,const datetime &Time[],const double &Open[],const double &High[],const double &Low[],const double &Close[],const long &TickVolume[],const long &Volume[],const int &Spread[] | indicators | Calculate event handler for all prices. | +void | [OnTick](https://docs.mql4.com/basis/function/events#ontick) | none | Expert Advisors | [NewTick](https://docs.mql4.com/runtime/event_fire#newtick) event handler. While the event of a new tick receipt is being processed, no other events of this type are received. | +void | [OnTimer](https://docs.mql4.com/basis/function/events#ontimer) | none | Expert Advisors and indicators | [Timer](https://docs.mql4.com/runtime/event_fire#timer) event handler | +double | [OnTester](https://docs.mql4.com/basis/function/events#ontester) | none | Expert Advisors | [Tester](https://docs.mql4.com/runtime/event_fire#tester) event handler. | +void | [OnChartEvent](https://docs.mql4.com/basis/function/events#onchartevent) | const int id,const long &lparam,const double &dparam,const string &sparam | Expert Advisors and indicators | [ChartEvent](https://docs.mql4.com/runtime/event_fire#chartevent) event handler. | + +**Libraries** do not handle any events. + +## Functions prohibited in Indicators and Expert Advisors + +Indicators, scripts and Expert Advisors are executable programs written in MQL4. They are designed for different types of tasks. Therefore there are some restrictions on the use of certain functions, depending on the type of program. The following functions are prohibited in indicators: + +- [OrderSend()](https://docs.mql4.com/trading/ordersend); +- [SendFTP()](https://docs.mql4.com/common/sendftp); +- [Sleep()](https://docs.mql4.com/common/sleep); +- [ExpertRemove()](https://docs.mql4.com/common/expertremove); +- [MessageBox()](https://docs.mql4.com/common/messagebox). + +All functions designed for indicators are prohibited in Expert Advisors and scripts: + +- [SetIndexBuffer()](https://docs.mql4.com/customind/setindexbuffer); +- [IndicatorSetDouble()](https://docs.mql4.com/customind/indicatorsetdouble); +- [IndicatorSetInteger()](https://docs.mql4.com/customind/indicatorsetinteger); +- [IndicatorSetString()](https://docs.mql4.com/customind/indicatorsetstring). + +The library is not an independent program and is executed in the context of the MQL4 program that has called it: script, indicator or Expert Advisor. Accordingly, the above restrictions apply to the called library. diff --git a/Docs/Samples/MetaTrader.StrategyTester.md b/Docs/Samples/MetaTrader.StrategyTester.md new file mode 100644 index 0000000..7c88696 --- /dev/null +++ b/Docs/Samples/MetaTrader.StrategyTester.md @@ -0,0 +1,49 @@ +# Meta Trader Strategy Tester + +[Resource](https://www.mql5.com/en/blogs/post/702993) + +To get the most out of your expert advisor, you'll need to optimize and backtest your strategy using MetaTrader's Strategy Tester. While forward testing on a demo account is essential, backtesting allows you to simulate trading over a long period of time in just minutes. And with the optimization feature, you can find out which settings performed best over a selected historical chart period. + +There is considerable debate over the accuracy of MetaTrader's strategy tester. At best, backtesting offers only a close approximation of how trades would be executed in real-time. But it's the only tool available to rapidly test any strategy over a wide range of trading situations, and one that you should learn how to use well. + +Open the Strategy Tester in MetaTrader by clicking the appropriate button on the toolbar or by selecting Strategy Tester from the View menu. + +## History Center + +Before backtesting or optimizing, it's important to make sure that your history data is complete and accurate, especially if you're using 'Every tick' as your testing model. If you see 'mismatched chart' errors in your Journal log or if your modeling quality is less than 90%, your history data is insufficient to generate accurate ticks. + +Open the History Center from the Tools menu or by pressing F2 on your keyboard. Double click the chart pair in the left column that you plan to backtest for. A list of time periods will appear below. Start by double clicking on 1 Minute (M1) to load the history data for that period. The backtester uses M1 data to generate ticks, so it is important that your M1 data is complete. + +From the History Center, you can download or import data to use in backtesting. Your broker will automatically provide some recent data, but it may not be enough for a longer backtest. In addition, the free downloadable data from MetaTrader (accessible via the Download button) is not always complete, and can contain large gaps. + +You can download free M1 data from http://www.forextester.com/data/datasources.html. First, select the M1 period for the symbol from the list on the left-hand side. Click the Import button, and then click Browse in the Import dialog to select the M1 data file you just downloaded. Press OK to import the data -- it may take several minutes. You now have several years of M1 data for that symbol. + +To make use of this data on higher timeframes, you'll need to use the period_converter script that comes with MetaTrader. Open a chart window and set it to M1. Drag and drop the period_converter script from the Navigator window onto the chart, and set the ExtPeriodMultiplier setting to the number of minutes to convert to. For M15, use 15; for H1, use 60; for H4, use 240, and so on. + +Repeat this process for all of the symbols/periods you plan to test on. Once you have sufficient history data, you can begin testing. The video below demonstrates the process of importing and converting the M1 data:Optimization + +The optimization feature of MetaTrader 4 allows you to test thousands of combinations of expert advisor settings to find the most profitable settings for the selected chart, period and date range. Indicator-based strategies will need to be optimized for maximum profitability. However, almost all EAs will benefit from optimization - even those that trade on tick data, provided you have complete M1 history data (see above). + +While the optimizer will return the most profitable settings for the selected date range, this is no guarantee that these settings will be profitable in the future. Market conditions change often, so it is important to regularly re-optimize your expert advisor for best results. + +To optimize your expert advisor, first select it from the Expert Advisor drop-down box. Select the currency pair from the Symbol box and chart period from the Period box. For Model, you'll generally want to select "Open Prices Only," unless you are optimizing an EA that runs on tick data. In that case, select "Every Tick." Check the Use Date option and select a range of dates to optimize for. Lastly, make sure that Optimization is checked. + +Click the Expert Properties button to open your expert advisor settings. Under the Inputs tab is where you'll enter the range of values to optimize for. The Start column will be the lowest value for a given setting, while the Stop column will be the highest. The Step column is the amount that the optimizer will "step through" from the Start to the Stop setting. + +## Backtesting + +By now, it should be obvious how the backtester works. Select your Expert Advisor, Symbol, Period and Model, check the Use Date box and select a date range. Select Visual Mode only if you want a visual walkthrough of the backtesting. Leave Optimization unchecked. + +Hit the Expert Properties button and enter your settings in the Value column under the Inputs tab. You can also load or save settings using the buttons in the bottom right. The Start, Step and Stop columns are ignored, as are the checkboxes. + +Close the Expert Properties dialog and press Start to begin testing. It will take anywhere from a few seconds to several minutes depending on your settings. Once testing has finished, open the Report tab on the bottom to see your results. + +A few statistics to take note of: + +- **Total net profit** - The **Gross profit** minus the **Gross loss**. +- **Profit factor** - The **ratio** of **gross profit** to **gross loss**. Higher is better, anything above 1.5 is good. +- **Absolute drawdown** - The **drawdown** of your *initial deposit*. High drawdowns increase the likelihood that your account will be blown out. +- **Profit trades** - Your overall **win percentage**. +- **Modeling quality** - Only important if your testing model is **Every Tick**. If so, this should be at 90%. If not, follow the instructions above to update your history with accurate M1 data. + +The Results tab at the bottom of the strategy tester will give you the details on opened and closed orders, including trailing stop, take profit and stop loss. Click the Open Chart button to get a visual representation of your results. When testing your new EA, examine these closely to ensure that your strategy is working as intended. diff --git a/Docs/Samples/OBJPROP_CORNER.md b/Docs/Samples/OBJPROP_CORNER.md new file mode 100644 index 0000000..26daebe --- /dev/null +++ b/Docs/Samples/OBJPROP_CORNER.md @@ -0,0 +1,14 @@ +# OBJPROP_CORBNER + +defines the chart corner relative to which the anchor point coordinates are specified. Can be one of the 4 values of the ENUM_BASE_CORNER enumeration; + +## ENUM_BASE_CORNER + +- CORNER_LEFT_UPPER: + Center of coordinates is in the upper left corner of the chart. +- CORNER_LEFT_LOWER: + Center of coordinates is in the lower left corner of the chart. +- CORNER_RIGHT_LOWER: + Center of coordinates is in the lower right corner of the chart. +- CORNER_RIGHT_UPPER: + Center of coordinates is in the upper right corner of the chart. diff --git a/Docs/Samples/Object Types.md b/Docs/Samples/Object Types.md new file mode 100644 index 0000000..30b1a7f --- /dev/null +++ b/Docs/Samples/Object Types.md @@ -0,0 +1,7 @@ +# Object Types + +When a graphical object is created using the ObjectCreate() function, it's necessary to specify the type of object being created, which can be one of the values of the ENUM_OBJECT enumeration. Object type identifiers are used in ObjectCreate(), ObjectsDeleteAll() and ObjectType() functions. + +Further specifications of object properties are possible using functions for working with graphical objects. + +[Reference](https://docs.mql4.com/constants/objectconstants/enum_object) diff --git a/Docs/Samples/OnCalculate.md b/Docs/Samples/OnCalculate.md new file mode 100644 index 0000000..c412756 --- /dev/null +++ b/Docs/Samples/OnCalculate.md @@ -0,0 +1,32 @@ +# OnCalculate + +The OnCalculate() function is called only in custom indicators when it's necessary to calculate the indicator values by the Calculate event. This usually happens when a new tick is received for the symbol, for which the indicator is calculated. This indicator is not required to be attached to any price chart of this symbol. + +The OnCalculate() function must have a return type int. + +```MQL4 +int OnCalculate ( + const int rates_total, // size of input time series + const int prev_calculated, // bars handled in previous call + const datetime& time[], // Time + const double& open[], // Open + const double& high[], // High + const double& low[], // Low + const double& close[], // Close + const long& tick_volume[], // Tick Volume + const long& volume[], // Real Volume + const int& spread[] // Spread +); +``` + +Parameters of open[], high[], low[] and close[] contain arrays with open prices, high and low prices and close prices of the current time frame. The time[] parameter contains an array with open time values, the spread[] parameter has an array containing the history of spreads (if any spread is provided for the traded security). The parameters of volume[] and tick_volume[] contain the history of trade and tick volume, respectively. + +**Note** +To determine the indexing direction of time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[], call ArrayGetAsSeries(). In order not to depend on default values, you should unconditionally call the ArraySetAsSeries() function for those arrays, which are expected to work with. + +**Note** +The first rates_total parameter contains the number of bars, available to the indicator for calculation, and corresponds to the number of bars available in the chart. + +We should note the connection between the return value of OnCalculate() and the second input parameter prev_calculated. During the function call, the prev_calculated parameter contains a value returned by OnCalculate() during previous call. This allows for economical algorithms for calculating the custom indicator in order to avoid repeated calculations for those bars that haven't changed since the previous run of this function. + +For this, it is usually enough to return the value of the rates_total parameter, which contains the number of bars in the current function call. If since the last call of OnCalculate() price data has changed (a deeper history downloaded or history blanks filled), the value of the input parameter prev_calculated will be set to zero by the terminal. diff --git a/Docs/Samples/OnDeinit.md b/Docs/Samples/OnDeinit.md new file mode 100644 index 0000000..f8bce5e --- /dev/null +++ b/Docs/Samples/OnDeinit.md @@ -0,0 +1,26 @@ +# OnDeinit + +The OnDeinit() function is called during deinitialization and is the Deinit event handler. It must be declared as the void type and should have one parameter of the const int type, which contains the code of deinitialization reason. If a different type is declared, the compiler will generate a warning, but the function will not be called. + +The Deinit event is generated for Expert Advisors and indicators in the following cases: + +before reinitialization due to the change of a symbol or chart period, to which the mql4 program is attached; +before reinitialization due to the change of input parameters; +before unloading the mql4 program. + +```mq4 +void OnDeinit(const int reason); +``` + +| Constant | Value | Description | +| -------- | ----- | ----------- | +| REASON_PROGRAM | 0 | Expert Advisor terminated its operation by calling the ExpertRemove() function| +| REASON_REMOVE | 1 | Program has been deleted from the chart | +| REASON_RECOMPILE | 2 | Program has been recompiled | +| REASON_CHARTCHANGE | 3 | Symbol or chart period has been changed | +| REASON_CHARTCLOSE | 4 | Chart has been closed | +| REASON_PARAMETERS | 5 | Input parameters have been changed by a user | +| REASON_ACCOUNT | 6 | Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings | +| REASON_TEMPLATE | 7 | A new template has been applied | +| REASON_INITFAILED | 8 | This value means that OnInit() handler has returned a nonzero value | +| REASON_CLOSE | 9 | Terminal has been closed | diff --git a/Docs/Samples/OnInit.md b/Docs/Samples/OnInit.md new file mode 100644 index 0000000..00ea010 --- /dev/null +++ b/Docs/Samples/OnInit.md @@ -0,0 +1,9 @@ +# OnInit + +The Init event is generated immediately after an Expert Advisor or an indicator is downloaded; The OnInit() function is used for initialization. If OnInit() has the int type of the return value, the non-zero return code means unsuccessful initialization, and it generates the Deinit event with the code of deinitialization reason REASON_INITFAILED. + +OnInit() function execution result is analyzed by the terminal's runtime subsystem only if the program has been compiled using #property strict. + +INIT_SUCCEEDED +INIT_FAILED +INIT_PARAMETERS_INCORRECT diff --git a/Docs/Samples/OnTick.md b/Docs/Samples/OnTick.md new file mode 100644 index 0000000..555cb19 --- /dev/null +++ b/Docs/Samples/OnTick.md @@ -0,0 +1,7 @@ +# OnTick Event Handler Function + +as i told before, this is main and most important event handler function in an EA. + +each tick represent a price change, som during an EA there are some cases which same price or etc maybe occures twice or more. +we have to handle this situations to prevent double signaling, or opening positions more than once. + diff --git a/Docs/Samples/OrderSend.md b/Docs/Samples/OrderSend.md new file mode 100644 index 0000000..041bbd4 --- /dev/null +++ b/Docs/Samples/OrderSend.md @@ -0,0 +1,56 @@ +# OrderSend + +[Trade Functions](https://docs.mql4.com/trading) + +The main function used to open an order or place a pending order. + +```mq4 +int OrderSend( + string symbol, // symbol + int cmd, // operation + double volume, // volume + double price, // price + int slippage, // slippage + double stoploss, // stop loss + double takeprofit, // take profit + string comment=NULL, // comment + int magic=0, // magic number + datetime expiration=0, // pending order expiration + color arrow_color=clrNONE // color + );dg +``` + +## Order Properties (CMD) + +| ID | Value | Description | +| -- | ----- | ----------- | +| OP_BUY | 0 | Buy operation | +| OP_SELL | 1 | Sell operation | +| OP_BUYLIMIT | 2 | Buy limit pending order | +| OP_SELLLIMIT | 3 | Sell limit pending order | +| OP_BUYSTOP | 4 | Buy stop pending order | +| OP_SELLSTOP | 5 | Sell stop pending order | + +## Market Order + +There are three types of orders that can be placed in MetaTrader: market, stop and limit orders. Being the most common, a market order opens a position immediately at the nearest Bid or Ask price. + +### Buy + +OrderSend(Symbol(),OP_BUY,0.1,Ask,2,Bid-15*Point,Bid+15*Point); + +double bid =MarketInfo("GBPUSD",MODE_BID); // Request for the value of Bid + double ask =MarketInfo("GBPUSD",MODE_ASK); // Request for the value of Ask + double point =MarketInfo("GBPUSD",MODE_POINT);//Request for Point + // Opening BUY + OrderSend("GBPUSD",OP_BUY,0.1,ask,2,bid-15*Point,bid+15*Point); + Alert (GetLastError()); // Error message + return; // Exit start() + + +OrderSend (Symbol(), OP_BUY, Lots, Ask, Slippage, Bid-StopLoss *Point, Bid+TakeProfit*Point, “EAName”, MagicNumber, 0, Blue) +Here is an example of a sell market order: + +### Sell + +OrderSend (Symbol(), OP_SELL, Lots, Bid, Slippage, Ask+StopLoss *Point, Ask-TakeProfit*Point, “EAName”, MagicNumber, 0, Blue) diff --git a/Docs/Samples/Pine.Calculation.md b/Docs/Samples/Pine.Calculation.md new file mode 100644 index 0000000..dd98862 --- /dev/null +++ b/Docs/Samples/Pine.Calculation.md @@ -0,0 +1,27 @@ +# Create a loop for rights + +```mq4 +int OnCalculate(...) { + // + // wait to pass bars until we have rights ... + if (rates_total <= InpPeriod) { + // + // return not calculated ... + return 0; + } + + // + // find loop count for bars manipulation ... + int count = (prev_calculated == 0) ? rates_total - InpPeriod - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = count - 1; i >= 0; i--) { + + } + + // + // return current calculated ... + return rates_totlat; +} +``` diff --git a/Docs/Samples/Plot.md b/Docs/Samples/Plot.md new file mode 100644 index 0000000..e89827e --- /dev/null +++ b/Docs/Samples/Plot.md @@ -0,0 +1,14 @@ +# Define Plots using Compiler + +```MQL +#property indicator_chart_window +#property indicator_buffers 1 + +// +//--- plot Line +#property indicator_label1 "Line" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrDarkBlue +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 +``` diff --git a/Docs/Samples/Position.Counting.md b/Docs/Samples/Position.Counting.md new file mode 100644 index 0000000..cc02435 --- /dev/null +++ b/Docs/Samples/Position.Counting.md @@ -0,0 +1,4 @@ +# Position Counting + +- **PositionTotal()**: counts all positions; +- **OrdersTotal()**: counts all orders; \ No newline at end of file diff --git a/Docs/Samples/PositionGetTicket.md b/Docs/Samples/PositionGetTicket.md new file mode 100644 index 0000000..99b4f3f --- /dev/null +++ b/Docs/Samples/PositionGetTicket.md @@ -0,0 +1,3 @@ +# PositionGetTicket + +it is a function which get position index and retrieve and returns the specified position ticket ... diff --git a/Docs/Samples/PositionsTotal.md b/Docs/Samples/PositionsTotal.md new file mode 100644 index 0000000..2238d75 --- /dev/null +++ b/Docs/Samples/PositionsTotal.md @@ -0,0 +1,3 @@ +# PositionsTotal + +a function which returns number of open position diff --git a/Docs/Samples/Print.md b/Docs/Samples/Print.md new file mode 100644 index 0000000..86ce94f --- /dev/null +++ b/Docs/Samples/Print.md @@ -0,0 +1,3 @@ +# Print + +this command used to show some data in MT Log window. diff --git a/Docs/Samples/RMA.md b/Docs/Samples/RMA.md new file mode 100644 index 0000000..f567e36 --- /dev/null +++ b/Docs/Samples/RMA.md @@ -0,0 +1,39 @@ +# RMA + +Relative Moving Average (RMA) with the ta.rma() function. + +A Relative Moving Average adds more weight to recent data (and gives less importance to older data). This makes the RMA similar to the Exponential Moving Average, although it’s somewhat slower to respond than an EMA is. + +ta.rma(source, length) + +source is the series of numerical values to process. It’s the (price) data we calculate the RMA on. +length is an integer with the moving average length in bars. This is the lookback period over which Pine Script calculates the average. +ta.rma() returns the Relative Moving Average as a floating-point value [1] . + +The RMA is obtained by dividing a stock's short-term moving average of price by its long-term moving average of price. Stocks rising in price the fastest always have the highest RMAs, and those going down in price the fastest always have the lowest RMAs. + +[Formula](https://www.hybrid-solutions.com/plugins/client-vtl-plugins/free/rma.html) + +This indicator represents the relative moving average indicator (RMA). RMA = SMA(3 x Period) - SMA(2 x Period) + SMA(1 x Period) per formula: https://www.hybrid-solutions.com/plugins/client-vtl-plugins/free/rma.html + +ShortAverage = new SimpleMovingAverage(name + "_Short", period); +MediumAverage = new SimpleMovingAverage(name + "_Medium", period * 2); +LongAverage = new SimpleMovingAverage(name + "_Long", period * 3); + +LongAverage.Current.Value - MediumAverage.Current.Value + ShortAverage.Current.Value; + +rma = sma(price,period*3) + sma (price,period*2) - sma(price,period) + +[Fromula 1](https://www.tradingcode.net/tradingview/relative-moving-average/) + +alpha = 1 / length + +rma = alpha * source + (1 - alpha) * RMA[1] + +pine_rma(source, length) => + alpha = 1 / length + sum = 0.0 + sum := na(sum[1]) ? + ta.sma(source, length) : + alpha * source + (1 - alpha) * nz(sum[1]) + diff --git a/Docs/Samples/RSI Moving Average Cross EA.Tutorial.md b/Docs/Samples/RSI Moving Average Cross EA.Tutorial.md new file mode 100644 index 0000000..559e8f6 --- /dev/null +++ b/Docs/Samples/RSI Moving Average Cross EA.Tutorial.md @@ -0,0 +1,149 @@ +# RSI MA Cross Strategy + +EURUSD M15 Chart is Open + +## Strategy Used + +- 10 Period RSI: + - ; + - ; +- 5 Period EMA; +- 10 Period MA; + +works by over solde and over baughts on rsi and then check mas; + +## Implementation + +```mq4 +// +// Fast MA ... +input int fastMaPeriod = 20; // Fast MA Bars +input ENUM_MA_METHOD fastMaMethod = MODE_EMA; // Fast MA Method +input ENUM_APPLIED_PRICE fastMaAppliedPrice = PRICE_CLOSE; // Fast MA Applied Price + +// +// Slow MA ... +input int slowMaPeriod = 50; // Slow MA Bars +input ENUM_MA_METHOD slowMaMethod = MODE_EMA; // Slow MA Method +input ENUM_APPLIED_PRICE slowMaAppliedPrice = PRICE_CLOSE; // Slow MA Applied Price + +// +// SL / TP ... +input int stopLossPips = 50; // SL Pips +input int takeProfitPips = 50; // TP Pips + +// +// Trade ... +intput double orderSize = 0.01; // Order size in Lots + +// +// Buffers ... +double fastMaBuffer[]; +double slowMaBuffer[]; + +const int buffersValuesRequired = 3; + +// +// Global Variables ... +double stopLoss; +double takeProfit; + +// +int OnInit() { + // + stopLoss = PipsToDouble(stopLossPips); + takeProfit = PipsToDouble(takeProfitPips); + + // + IsNewBar(); +} +``` + +## Calculating SL and TP Gaps on Trading Open + +```mq4 +// +// Define Some Variables ... +double price; +double closePrice; +double tp = 0; +double sl = 0; +double slGap = PointsToDouble((int) SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL)); + +// +if (stopLoss > 0 && stopLoss < slGap) { + return; +} + +// +if (takeProfit > 0 && takeProfit < slGap) { + return; +} + +// +RefreshRates(); + +// +if (type == ORDER_TYPE_BUY) { + // + price = SymbolInfoDouble(_Symbol, SYMBOL_ASK); + closePrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); + + // + if (stopLoss > 0) { + sl = closePrice - stopLoss; + } + + // + if (takeProfit > 0) { + tp = price + takeProfit; + } +} else { + // + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + closePrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if (stopLoss > 0) { + sl = closePrice + stopLoss; + } + + // + if (takeProfit > 0) { + tp = price - takeProfit; + } +} + +// +price = NormalizeDouble(price, _Digits); +sl = NormalizeDouble(sl, _Digits); +tp = NormalizeDouble(tp, _Digits); +``` + +## Usefull Library Methods + +```mq4 +// +// Convert points to Actual Point ... +double PointsToDouble(int points) { + // + double result = points * _Point; + return result; +} + +// +// Converts Pips to Points ... +int PipsToPoints(int pips) { + // + int result = pips * ((_Digits == 3 || _Digits == 5) ? 10 : 1); + return result; +} + +// +// Converts Pips to Double ... +double PipsToDouble(int pips) { + // + double result = PointsToDouble(PipsToPoints(pips)); + return result; +} +``` diff --git a/Docs/Samples/SMA.md b/Docs/Samples/SMA.md new file mode 100644 index 0000000..984b860 --- /dev/null +++ b/Docs/Samples/SMA.md @@ -0,0 +1,36 @@ +# SMA + +Simple Moving Average + +[Resource 1](https://www.investopedia.com/terms/s/sma.asp) + +A simple moving average (SMA) calculates the average of a selected range of prices, usually closing prices, by the number of periods in that range. + +Simple moving averages calculate the average of a range of prices by the number of periods within that range. +A simple moving average is a technical indicator that can aid in determining if an asset price will continue or if it will reverse a bull or bear trend. +A simple moving average can be enhanced as an exponential moving average (EMA) that is more heavily weighted on recent price action. + +## Formula + +SMA = (A1 + A2 + ... + An) / n + +An = price of an asset at period n +n = the number of total periods + +[Tutorial](https://mql4tutorial.com/mql4-tutorial-english/mql4-tutorial-basics-11-how-to-calculate-a-simple-moving-average) + +```mq4 +double sma = iMA(_Symbol, _Period, numOfCandles, 0, MODE_SMA, PRICE_CLOSE, 0) +``` + +## Calculation process + +```pine +pine_sma(source, length) => + sum = 0.0 + for i = 0 to length - 1 + sum += source[i] / length + sum + +plot(pine_sma(close, 15)) +``` \ No newline at end of file diff --git a/Docs/Samples/SampleOrder.md b/Docs/Samples/SampleOrder.md new file mode 100644 index 0000000..8d3d8e4 --- /dev/null +++ b/Docs/Samples/SampleOrder.md @@ -0,0 +1,66 @@ +# Some Usefull Tutorials + +## Open Order + +for opening a sample order in mql4 follow following syntax: + +// +buy => ASK Price ... +sell => BID Price ... + +```mql4 +void OnTick() { + // + if (OrdersTotal() > 0) { + return; + } + + // + // we are on bullish candle ... + if (close[1] > open[1]) { + // + OrderSend( + _Symbol, // Symbol ... + OP_BUY, // Operation ... + 0.1 // Lot Size ( Volume ) ... + Ask, // Open Order Price ... + 3, // tolerance ... + Ask - 300 * _Point, // SL ... + Ask + 150 * _Point, // TP ... + NULL, // Trade Comment ... + 0, // Magic Number (user unique number) ... + 0, // Expiration ... + Green // Arrow Line ... + ); + } +} +``` + +## Counting Open Buy Positions + +```mql4 +int CountOpenBuyOrders() { + // + int result = 0; + + // + for (int i = OrdersTotal() - 1; i >= 0; i--) { + // + OrderSelect(i, SELECT_BY_POSITION, MODE_TRADES); + + // + string orderSymbol = OrderSymbol(); + + // + if ( + orderSymbol == _Symbol && + OrderType() == OP_BUY + ) { + result++; + } + } + + // + return result; +} +``` \ No newline at end of file diff --git a/Docs/Samples/Simple.Oscillator.md b/Docs/Samples/Simple.Oscillator.md new file mode 100644 index 0000000..2767213 --- /dev/null +++ b/Docs/Samples/Simple.Oscillator.md @@ -0,0 +1,5 @@ +# Oscillator + +usually oscillators is visualized some additional data related to chart, but not price momentums, and drwn on spearate window by default. +specially works on volumes. + diff --git a/Docs/Samples/Simple.indicator.md b/Docs/Samples/Simple.indicator.md new file mode 100644 index 0000000..eec82f5 --- /dev/null +++ b/Docs/Samples/Simple.indicator.md @@ -0,0 +1,221 @@ +# Indicator + +usually indicators is visualized some additional data on chart, and drwn on candle charts by default. +specially works on prices. + +```mq4 +#property indicator_buffers numOfBuffers +``` + +for example: + +```mq4 +#property indicator_buffers 2 +``` + +here we define 2 buffer to system for processing in each candle ... + +then we have to define arrays ... + +double BufferFast[]; +double BufferSlow[]; + +usually for each indicator buffers we can define a constant to hold it's index on chart queue. + +```mq4 +#define FastIndicator 0 +#define SlowIndicator 1 +``` + +each buffer holds data to use in candle calculation time and then draw things on chart. + +we have to define Indexes for Buffers to draw themon chart. +this happens on OnInit() event handler method. + +```mq4 +int OnInit() { + // + // Fast Indicator ... + SetIndexStyle(FastIndicator, DRAW_LINE, STYLE_DOT, 1, clrFireBrick); + SetIndexBuffer(FastIndicator, BufferFast); + SetIndexLabel(FastIndicator, "Fast"); + + // + // Slow Indicator ... + SetIndexStyle(SlowIndicator, DRAW_LINE, STYLE_DOT, 1, clrGreen); + SetIndexBuffer(SlowIndicator, BufferSlow); + SetIndexLabel(SlowIndicator, "Slow"); + + // + return INIT_SUCCEEDED; +} +``` + +after define styling of indicators parts, we have to fill buffers by required data's, in OnCalculate() event handler. +since at initialization time, there is no data in Buffers to use them. + +in OnCalculate event handler, also some usefull args and params to use them for calculation steps or implement our business logic. + +if you need to know them completely, see proppered documentation file. + +```mq4 +int OnCalculate( + const int rates_total, // size of input time series + const int prev_calculated, // bars handled in previous call + const datetime& time[], // Time + const double& open[], // Open + const double& high[], // High + const double& low[], // Low + const double& close[], // Close + const long& tick_volume[], // Tick Volume + const long& volume[], // Real Volume + const int& spread[] // Spread +) { + // + // Here we defined some variables to use them ... + int limit; + double signalMa, + fastMa, + slowMa; + + // + // in this example, SlowMAPeriod is an input for + // using in Calculations ... + // so as we don't reach to this input candle, we cant calculate + // anything ... + // for this reasin we check rates_total param, and if not reach to our + // input variable, we return 0 means nothing passed ... + if (rates_total <= SlowMAPeriod) { + return 0; + } + + // + // found which candles calculated before ... + limit = rates_total - prev_calculated; + if (prev_calculated>0) { + limit++; + } + + // + // Do Calculation ... + // Symbol() => retrieve current chart window symbol ... + // Period() => retrieve current period ... + for (int i = limit - 1; i>0; i--) { + // + signalMa = iMa(Symbol(), Period(), SignalMaPeriod, 0, MAMethod, PRICE_CLOSE, i); + + // + fastMa = iMa(Symbol(), Period(), FastMaPeriod, 0, MAMethod, PRICE_CLOSE, i); + + // + slowMa = iMa(Symbol(), Period(), SlowMaPeriod, 0, MAMethod, PRICE_CLOSE, i); + + // + // Here we have to do some calculation, and check some conditions, then + // fill up buffers based on conditions ... + // Trending Up Condition ... + if (signalMa > fastMa && fastMa < slowMa) { + // + BufferFast[i] = fastMa; + BufferSlow[i] = slowMa; + // + // Trending Down Condition ... + } else if (signalMa < fastMa && fastMa < slowMa>) { + // + BufferFast[i] = fastMa; + BufferSlow[i] = slowMa; + } + // + // NOTE: it could be possible to combine above two condition, but + // we separate them for learning purposed ... + } + + // + // this tells meta trader how many candles we used ... + return rate_total; +} +``` + +in above example we just show two line, and there is no histogram. +in mt4 for drawing histogram we have to do some unusual works ... + +we are going to complete the example to support histogram. + +for showing histogram, we need two more buffers. + +```mq4 +// +// Increase System Defined Buffers ... +#property indicator_buffers 4 + +// +// Next we have to define two more Buffer ... +double BufferUp[]; +double BufferDown[]; + +// +// then we have to change definition of indexes of buffers for supporting histograms ... +// wen MT draws Histogram, it's used area between next indicator and selected one ... +#define UpIndicator 0 +#define DownIndicator 2 +#define FastIndicator 3 +#define SlowIndicator 1 + +// +// Then we have to define Styling for histogram ... +int OnInit() { + // + // Fast Indicator ... + SetIndexStyle(FastIndicator, DRAW_LINE, STYLE_DOT, 1, clrFireBrick); + SetIndexBuffer(FastIndicator, BufferFast); + SetIndexLabel(FastIndicator, "Fast"); + + // + // Slow Indicator ... + SetIndexStyle(SlowIndicator, DRAW_LINE, STYLE_DOT, 1, clrGreen); + SetIndexBuffer(SlowIndicator, BufferSlow); + SetIndexLabel(SlowIndicator, "Slow"); + + // + // Up Indicator ... + SetIndexStyle(UpIndicator, DRAW_HISTOGRAM, STYLE_DOT, 1, clrGreen); + SetIndexBuffer(UpIndicator, BufferUp); + SetIndexEmptyValue(UpIndicator, 0.0); + + // + // Down Indicator ... + SetIndexStyle(DownIndicator, DRAW_HISTOGRAM, STYLE_DOT, 1, clrFireBrick); + SetIndexBuffer(DownIndicator, BufferDown); + SetIndexEmptyValue(DownIndicator, 0.0); + + // + return INIT_SUCCEEDED; +} + +// +// then we have to change calculation for filling bufferup and bufferdown ... +// +// the reason which we separate this conditions, for drawing histograms ... +// Trending Up Condition ... +if (signalMa > fastMa && fastMa < slowMa) { + // + BufferFast[i] = fastMa; + BufferSlow[i] = slowMa; + + // + // the histogram drawn between fast line and slow line ... + // so up indicator draws between itself and slow ... + BufferUp[i] = fastMa; +// +// Trending Down Condition ... +} else if (signalMa < fastMa && fastMa < slowMa>) { + // + BufferFast[i] = fastMa; + BufferSlow[i] = slowMa; + + // + // the histogram drawn between slow line and fast line ... + // so up indicator draws between itself and fast ... + BufferDown[i] = slowMa; +} +``` diff --git a/Docs/Samples/Slope.md b/Docs/Samples/Slope.md new file mode 100644 index 0000000..1646f7a --- /dev/null +++ b/Docs/Samples/Slope.md @@ -0,0 +1,5 @@ +# Slope + +Shib + +m = (y2 - y1) / (x2 - x1) diff --git a/Docs/Samples/Stochastic EA Tutorial.md b/Docs/Samples/Stochastic EA Tutorial.md new file mode 100644 index 0000000..e4a1705 --- /dev/null +++ b/Docs/Samples/Stochastic EA Tutorial.md @@ -0,0 +1,31 @@ +# Stochastic EA + +we want to buy on bottom of stochastic when cross over stock with signal +and sell when cross under stock with signall on top ... + +```mql4 +// +int totalBars; + +// +int OnInit() { + // + totalBars = iBars(Symbol, _Period); + + // + ... +}; + +// +void OnTick() { + // + int bars = iBars(_Symbol, _Period); + if (totlaBars != bars) { + // + totalBars = bars; + + // + // Do Actions here ... + } +} +``` diff --git a/Docs/Samples/SymbolInfoDouble.md b/Docs/Samples/SymbolInfoDouble.md new file mode 100644 index 0000000..45e63b8 --- /dev/null +++ b/Docs/Samples/SymbolInfoDouble.md @@ -0,0 +1,71 @@ +# SymbolInfoDouble + +[Reference](https://docs.mql4.com/marketinformation/symbolinfodouble); + +Returns the corresponding property of a specified symbol. There are 2 variants of the function. + +1. Immediately returns the property value. + +```mq4 +double SymbolInfoDouble( + string name, // symbol + ENUM_SYMBOL_INFO_DOUBLE prop_id // identifier of the property + ); +``` + +2. Returns true or false depending on whether a function is successfully performed. In case of success, the value of the property is placed into a recipient variable, passed by reference by the last parameter. + +```mq4 +bool SymbolInfoDouble( + string name, // symbol + ENUM_SYMBOL_INFO_DOUBLE prop_id, // identifier of the property + double& double_var // here we accept the property value + ); +``` + +Parameters + +name + +[in] Symbol name. + +prop_id + +[in] Identifier of a symbol property. The value can be one of the values of the ENUM_SYMBOL_INFO_DOUBLE enumeration. + +double_var + +[out] Variable of double type receiving the value of the requested property. + +Return Value + +The value of double type. In case of execution failure, information about the error can be obtained using GetLastError() function: + +4106 — symbol is not selected in "Market Watch" (not found in the list of available ones), +4051 — invalid identifier of a symbol property, +4024 — internal error. +Note + +It is recommended to use SymbolInfoTick() if the function is used for getting information about the last tick. It may well be that not a single quote has appeared yet since the terminal is connected to a trading account. In such a case, the requested value will be indefinite. + +In most cases, it is enough to use SymbolInfoTick() function allowing a user to receive the values of Ask, Bid, Last, Volume and the time of the last tick's arrival during a single call. + +Example: + +```mq4 +void OnTick() + { +//--- obtain spread from the symbol properties + bool spreadfloat=SymbolInfoInteger(Symbol(),SYMBOL_SPREAD_FLOAT); + string comm=StringFormat("Spread %s = %I64d points\r\n", + spreadfloat?"floating":"fixed", + SymbolInfoInteger(Symbol(),SYMBOL_SPREAD)); +//--- now let's calculate the spread by ourselves + double ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK); + double bid=SymbolInfoDouble(Symbol(),SYMBOL_BID); + double spread=ask-bid; + int spread_points=(int)MathRound(spread/SymbolInfoDouble(Symbol(),SYMBOL_POINT)); + comm=comm+"Calculated spread = "+(string)spread_points+" points"; + Comment(comm); + } +``` diff --git a/Docs/Samples/TP-SL Calculation.md b/Docs/Samples/TP-SL Calculation.md new file mode 100644 index 0000000..11c7c1d --- /dev/null +++ b/Docs/Samples/TP-SL Calculation.md @@ -0,0 +1,22 @@ +# How to Calculate TP based on SL and Risk To Reward Ratio + +```solo + // Long: + // + // ask Price: 1.14443 + // sl: 1.14325 + // tp: 1.14620 + // risk: askprice - sl = 0.00118 + // reward: risk * ration = 0.00177 + // tp: ask + reward + // + // Short: + // + // ask price: 1.14214 + // sl: 1.14325 + // tp: 1.14048 + // + // risk: sl - ask = 0.00111 + // reward: risk * ration = 0.001665 + // tp: ask - reward +``` diff --git a/Docs/Samples/Trade.md b/Docs/Samples/Trade.md new file mode 100644 index 0000000..dc007da --- /dev/null +++ b/Docs/Samples/Trade.md @@ -0,0 +1,27 @@ +# Trade Libnrary + +a built-in library in MQL which is used to manipulate and manage Trade Positions in Expert Advisors. + +for using this library, at the first step yopu have to include it oin your EA. this happens like this: + +```mq4 +#include +``` + +then you can access to it's provided stuffs. + +## CTrade + +it is a Class, which provides Trading Management functionalities for MQL Programmers ... + +[here](https://www.mql5.com/en/docs/standardlibrary/tradeclasses/ctrade) are it's documentation. + +this class is an static class and there is no need to call any constructor for it's usage. simple making it's instance by assigning a name to it's type: + +```mq4 +CTrade trader; +``` + +now you can acssess to all of it's provided actions, methods and etc to manipulate trade positions ... + +**NOTE** for using this class you have to enable Auto Trading and also for your EA check it's checkbox for allow AutoTrading ... \ No newline at end of file diff --git a/Docs/Samples/TradeOncePerBar.md b/Docs/Samples/TradeOncePerBar.md new file mode 100644 index 0000000..1f80254 --- /dev/null +++ b/Docs/Samples/TradeOncePerBar.md @@ -0,0 +1,38 @@ +# Best Way to Code Trade Once per Bar at Open on MT4 + +So there are various ways to code an EA to trade once per bar. + +```mq4 +int BarsCount = 0; +if (Bars>BarsCount) { + Do the algo and then + BarsCount = Bars; +} +``` + +```mq4 +static datetime prevtime = 0; +if(prevtime == Time[0]) return; +prevtime = Time[0]; +Do the algo here after the code +``` + +```mq4 +if (Time[0] >= TimeCurrent()) { + Do the algo here +} +``` + +```mq4 +int BarsCount = 0 +if (Bars>BarsCount) etc. +``` + +```mq4 +static datetime prevtime = Time[0]; +if (prevtime == Time[0]) return; +prevtime = Time[0]; +``` + +```mq4 +``` diff --git a/Docs/Samples/VWMA.md b/Docs/Samples/VWMA.md new file mode 100644 index 0000000..f353abe --- /dev/null +++ b/Docs/Samples/VWMA.md @@ -0,0 +1,12 @@ +# VWMA + +Volume-Weighted Moving Average (VWMA) + +## Calculation process + +TradingView calculates the Volume-Weighted Moving Average with two Simple Moving Averages (SMAs) [1] . The first SMA multiplies each bar’s data with that bar’s volume. The second SMA is the volume average. Dividing those gives the VWMA. + +```pine +pine_vwma(source, length) => + ta.sma(source * volume, length) / ta.sma(volume, length) +``` diff --git a/Docs/Samples/_Point.md b/Docs/Samples/_Point.md new file mode 100644 index 0000000..f53e70a --- /dev/null +++ b/Docs/Samples/_Point.md @@ -0,0 +1,9 @@ +# _Point + +[Resource](https://docs.mql4.com/predefined/_point) + +The _Point variable contains the point size of the current symbol in the quote currency. + +You may also use the Point() function. + +smallest price changes corresponding to Symbol diff --git a/Docs/Samples/iBarShift.md b/Docs/Samples/iBarShift.md new file mode 100644 index 0000000..528411b --- /dev/null +++ b/Docs/Samples/iBarShift.md @@ -0,0 +1,5 @@ +# iBarShift + +Search for a bar by its time. The function returns the index of the bar which covers the specified time. + +[Resource](https://docs.mql4.com/series/ibarshift) diff --git a/Docs/Samples/iCustom.md b/Docs/Samples/iCustom.md new file mode 100644 index 0000000..dd12adb --- /dev/null +++ b/Docs/Samples/iCustom.md @@ -0,0 +1,36 @@ +# iCustom + +Calculates the specified custom indicator and returns its value. + +```mq4 +double iCustom( + string symbol, // symbol + int timeframe, // timeframe + string name, // path/name of the custom indicator compiled program + ... // custom indicator input parameters (if necessary) + int mode, // line index + int shift // shift + ); +``` + +## Parameters + +- **symbol** - Symbol name on the data of which the indicator will be calculated. NULL means the current symbol. +- **timeframe** - Timeframe. It can be any of ENUM_TIMEFRAMES enumeration values. 0 means the current chart timeframe. +- **name** - Custom indicator compiled program name, relative to the root indicators directory (MQL4/Indicators/). If the indicator is located in subdirectory, for example, in MQL4/Indicators/Examples, its name must be specified as "Examples\\indicator_name" (double backslash "\\"must be specified as separator instead of a single one). +- **...** -Custom indicator input-parameters, separated by commas. + + The passed parameters and their order must correspond with the declaration order and the type of extern variables of the custom indicator. If the values of input parameters is not specified, the default values will be used. + +- **mode** - Line index. Can be from 0 to 7 and must correspond with the index, specified in call of the SetIndexBuffer() function. +- **shift** - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). + +## Returned value + +Numerical value of the specified custom indicator. The custom indicator must be compiled (*.EX4 file) and be in the terminal_directory\MQL4\Indicators\ directory. + +## Example + +```mq4 + double val=iCustom(NULL,0,"SampleInd",13,1,0); +``` diff --git a/Docs/Samples/include.mql.md b/Docs/Samples/include.mql.md new file mode 100644 index 0000000..7361f06 --- /dev/null +++ b/Docs/Samples/include.mql.md @@ -0,0 +1,10 @@ +# Including files + +in MQL Language we can put some functions on separated files, then include them in our main MQL Program (such as Indicator or EA) ... +then we can call it's functions ... + +```mq4 +#include "file.mq4" +``` + +see Library file ... \ No newline at end of file diff --git a/Docs/Samples/indicator_buffers.md b/Docs/Samples/indicator_buffers.md new file mode 100644 index 0000000..0e22cac --- /dev/null +++ b/Docs/Samples/indicator_buffers.md @@ -0,0 +1,53 @@ +# Buffers + +simply they are arrays which store information for using them as series in candles ... +in each mql program you had to define which buffers youi have to use in your program. + +this happens by the following pattern + +```mq4 +#property indicator_buffers numOfBuffers +``` + +for example: + +```mq4 +#property indicator_buffers 2 +``` +here we define 2 buffer to system for processing in each candle ... + +then we have to define arrays ... + +double BufferFast[]; +double BufferSlow[]; + +usually for each indicator buffers we can define a constant to hold it's index on chart queue. + +```mq4 +#define FastIndicator 0 +#define SlowIndicator 1 +``` + +each buffer holds data to use in candle calculation time and then draw things on chart. + +we have to define Indexes for Buffers to draw themon chart. +this happens on OnInit() event handler method. + +```mq4 +int OnInit() { + // + // Fast Indicator ... + SetIndexStyle(FastIndicator, DRAW_LINE, STYLE_DOT, 1, clrFireBrick); + SetIndexBuffer(FastIndicator, BufferFast); + SetIndexLabel(FastIndicator, "Fast"); + + // + // Slow Indicator ... + SetIndexStyle(SlowIndicator, DRAW_LINE, STYLE_DOT, 1, clrGreen); + SetIndexBuffer(SlowIndicator, BufferSlow); + SetIndexLabel(SlowIndicator, "Slow"); + + // + return INIT_SUCCEEDED; +} +``` diff --git a/Docs/Samples/nz.md b/Docs/Samples/nz.md new file mode 100644 index 0000000..cbf139b --- /dev/null +++ b/Docs/Samples/nz.md @@ -0,0 +1,6 @@ +# nz + +nz is a “filler”, as it fills na values of a series with zeros (in the case of nz(x) ) or with a user-specified value (in the case of nz(x, y) ). + +[Resources](https://www.tradingview.com/pine-script-docs/en/v3/language/Expressions_declarations_and_statements.html#preventing-na-values-functions-na-and-nz) + diff --git a/Docs/Samples/property.md b/Docs/Samples/property.md new file mode 100644 index 0000000..2c0cbaf --- /dev/null +++ b/Docs/Samples/property.md @@ -0,0 +1,9 @@ +# Property + +[Resource](https://docs.mql4.com/basis/preprosessor/compilation) + +Every MQL4-program allows to specify additional specific parameters named #property that help client terminal in proper servicing for programs without the necessity to launch them explicitly. This concerns external settings of indicators, first of all. Properties described in included files are completely ignored. Properties must be specified in the main mq4 file. + +#property identifier value + +The compiler will write declared values in the configuration of the module executed. diff --git a/Docs/Samples/show_label_on_last_candle.pine b/Docs/Samples/show_label_on_last_candle.pine new file mode 100644 index 0000000..f06a1c2 --- /dev/null +++ b/Docs/Samples/show_label_on_last_candle.pine @@ -0,0 +1,5 @@ + +var label l = na +if (barstate.islast) + l := label.new(bar_index, high, text="CE ATR Multiplier: " + str.tostring(chandelierExitATRMultiplier)) + label.delete(l[1]) diff --git a/Docs/Strategies/XST_SR15M.md b/Docs/Strategies/XST_SR15M.md new file mode 100644 index 0000000..e2703c7 --- /dev/null +++ b/Docs/Strategies/XST_SR15M.md @@ -0,0 +1,64 @@ +# Support and Resistance Scalping (XTS_SR15M) + +## Setup + +- **TF**: 15m +- **Asset**: AAPL +- **R2R**: 1:1.5 +- **Indicators**: + - Leledc Levels (IS) InSillico: + - Change Exhaustion bar count to 42; + - Change Line Tickness to 7; + - Hide Support Level line; + - Hide Resistance Level linel; + - ATR Stop Loss garethyeo: + - Change Source to low; +- **Oscillators**: + - Kurutoga Histogram (D7R): + - Hide Kurutuga Lead 4x; + +## Descriptions + +since Kurutoga Histogram doesn't provides it's source code, i try to implement +Cycle Channel Oscillator, instead of it. + +after i try to do back testing usage of CCH and KUH, i found this rules: + +- kurutuga histogram green color, means both red and green line in Cycle Channel must be above than 0.5 (Middle) line and green line above than red line. +- kurutuga histogram red color, means both red and green line in Cycle Channel must be below than 0.5 (Middle) line and red line below than green line. + +so we have to implement cycle channel oscillator and it's verifications on signals ... + +## Using the Strategy + +### Long/Buy Conditions + +- Leledc Level gives **Support Signal** (green to up side triangle); +- kurutuga histogram is **red** color; +- market forms a **bullish** candle; + +#### Long SL + +place sl at low of ATR Stop Loss Purple(red) Line. + +#### Long TP + +calculate based on R2R; + +### Short/Sell Conditions + +- Leledc Level gives **Resistance Signal** (red to down side triangle); +- kurutuga histogram is **green** color; +- market forms a **bearish** candle; + +#### Short SL + +place sl at high of ATR Stop Loss Green Line. + +#### Short TP + +calculate based on R2R; + +### Signals Overlap + +how to handle signals overlaps. diff --git a/Docs/Templates/ee.mq4 b/Docs/Templates/ee.mq4 new file mode 100644 index 0000000..524d8bf --- /dev/null +++ b/Docs/Templates/ee.mq4 @@ -0,0 +1,30 @@ + // // + // // Long Signal ... + // if ( + // // + // hasLongSignal && + // // + // price xmaBigHigh && + // tp > xmaHigh + // ) { + // tp = MathMin(xmaHigh, xmaBigHigh); + // } else + // // + // // Short Signal ... + // // TODO: Change ... + // if ( + // // + // hasShortSignal && + // // + // price < xmaHigh && + // price < xmaBigHigh && + // price > xmaLow && + // // + // tp < xmaLow + // ) { + // tp = xmaLow; + // } diff --git a/Docs/Templates/raw-strategy.doc.md b/Docs/Templates/raw-strategy.doc.md new file mode 100644 index 0000000..3e2bf1a --- /dev/null +++ b/Docs/Templates/raw-strategy.doc.md @@ -0,0 +1,38 @@ +## Strategy Title + +### Setup + +- **TF**: +- **Asset**: +- **R2R**: 1:1.5 +- **Indicators**: + -- + -- +- **Oscillators**: + -- + +### Using the Strategy + +#### Long/Buy Conditions + +- ; + +##### Long SL + +place sl below of previous market. + +##### Long TP + +calculate based on R2R; + +#### Short/Sell Conditions + +- ; + +##### Short SL + +place sl below of previous market. + +##### Short TP + +calculate based on R2R; diff --git a/Docs/Templates/report.md b/Docs/Templates/report.md new file mode 100644 index 0000000..e489b23 --- /dev/null +++ b/Docs/Templates/report.md @@ -0,0 +1,96 @@ +# XST_??? + +## Report + +### Makret + +??? + +### Exchange + +??? + +### Time Frame + +???min + +### Start Date + +14 may 2023 | 07:25 UTC + +### End Date + +22 may 2023 | 08:55 UTC + +### Risk to Reward + +1:1.5 + +### Reports + +#### Longs + +| ID | Position Type | TP | SL | Description | +| :--: | :-----------: | :--: | :--: | :---------- | +| 1 | Long | | | | +| 2 | Long | | | | +| 3 | Long | | | | +| 4 | Long | | | | +| 5 | Long | | | | +| 6 | Long | | | | +| 7 | Long | | | | +| 8 | Long | | | | +| 9 | Long | | | | +| 10 | Long | | | | +| 11 | Long | | | | +| 12 | Long | | | | +| 13 | Long | | | | +| 14 | Long | | | | +| 15 | Long | | | | +| 16 | Long | | | | +| 17 | Long | | | | +| 18 | Long | | | | +| 19 | Long | | | | +| 20 | Long | | | | + +#### Shorts + +| ID | Position Type | TP | SL | Description | +| :--: | :-----------: | :--: | :--: | :---------- | +| 1 | Short | | | | +| 2 | Short | | | | +| 3 | Short | | | | +| 4 | Short | | | | +| 5 | Short | | | | +| 6 | Short | | | | +| 7 | Short | | | | +| 8 | Short | | | | +| 9 | Short | | | | +| 10 | Short | | | | +| 11 | Short | | | | +| 12 | Short | | | | +| 13 | Short | | | | +| 14 | Short | | | | +| 15 | Short | | | | +| 16 | Short | | | | +| 17 | Short | | | | +| 18 | Short | | | | +| 19 | Short | | | | +| 20 | Short | | | | + +#### Signals Results + +| Type | Count | TPs | SLs | +| :----: | :-: | :-: | :-: | +| Longs | 00 | 00 | 00 | +| Shorts | 00 | 00 | 00 | +| Total | 00 | 00 | 00 | + +#### Analysis + +per trade volume: 10$ +total drawdown: 200$ +total lose: $ +total reward: $ +total cash: $ +win rate: % diff --git a/Docs/Templates/strategy.report.md b/Docs/Templates/strategy.report.md new file mode 100644 index 0000000..da62a67 --- /dev/null +++ b/Docs/Templates/strategy.report.md @@ -0,0 +1,16 @@ +# ???? + +## Makret + +## Exchange + +## Time Frame + +## Start Date + +## End Date + +## Reports + +| ID | Position Type | TP | SL | Description | +| -- | ------------- | -- | -- | ----------- | diff --git a/Docs/Templates/x-lib.candle.mq4 b/Docs/Templates/x-lib.candle.mq4 new file mode 100644 index 0000000..75fdeb6 --- /dev/null +++ b/Docs/Templates/x-lib.candle.mq4 @@ -0,0 +1,39 @@ + +// +// Check if a Candle is Bullish based on CRT Indicator ... +bool isBullishCRT(X_CANDLE_TYPE type) { + // + switch(type) { + // + case X_CT_HAMMER: + case X_CT_BULLISH_BELT: + case X_CT_MORNING_STAR: + case X_CT_BULLISH_KICKER: + case X_CT_BULLISH_HARAMI: + case X_CT_INVERTED_HAMMER: + case X_CT_BULLISH_ENGULFING: + return true; + default: + return false; + } +} + +// +// Check if a Candle is Bearish based on CRT Indicator ... +bool isBearishCRT(X_CANDLE_TYPE type) { + // + switch(type) { + // + case X_CT_PRICE_LINE: + case X_CT_HANGING_MAN: + case X_CT_EVENING_STAR: + case X_CT_SHOOTING_STAR: + case X_CT_BEARISH_HARAMI: + case X_CT_BEARISH_KICKER: + case X_CT_DARK_CLOUD_COVER: + case X_CT_BEARISH_ENGULFING: + return true; + default: + return false; + } +} diff --git a/Docs/Templates/x-mql.ea.template.mq4 b/Docs/Templates/x-mql.ea.template.mq4 new file mode 100644 index 0000000..1aff0b1 --- /dev/null +++ b/Docs/Templates/x-mql.ea.template.mq4 @@ -0,0 +1,53 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center ??? Strategy Expert Advisor +// --------------------------------------------- +// saherelm implementation of strategy expert advisor ... +// +// ShortName: ??? +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm ??? Strategy Expert Advisor" +#property strict + +// +// START Inputs ... +// +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Ticker Event Handler ... +void OnTick() +{ +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// END Functions ... +// \ No newline at end of file diff --git a/Docs/Templates/x-mql.indicator.template.mq4 b/Docs/Templates/x-mql.indicator.template.mq4 new file mode 100644 index 0000000..57cdd00 --- /dev/null +++ b/Docs/Templates/x-mql.indicator.template.mq4 @@ -0,0 +1,104 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center ??? Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm ??? Indicator" +#property strict + +// +// START Inputs ... +// +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + return(INIT_SUCCEEDED); +} + +// +// Calculating what we want ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, 0); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// END Functions ... +// \ No newline at end of file diff --git a/Docs/Templates/x-mql.lib.template.mq4 b/Docs/Templates/x-mql.lib.template.mq4 new file mode 100644 index 0000000..4cc1a17 --- /dev/null +++ b/Docs/Templates/x-mql.lib.template.mq4 @@ -0,0 +1,25 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center Library +// --------------------------------------------- +// saherelm implementation of strategy expert advisor ... +// +// ShortName: ??? +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// START Functions ... +// +// +// END Functions ... +// \ No newline at end of file diff --git a/Docs/Templates/x-mql.oscillator.template.mq4 b/Docs/Templates/x-mql.oscillator.template.mq4 new file mode 100644 index 0000000..32ab8eb --- /dev/null +++ b/Docs/Templates/x-mql.oscillator.template.mq4 @@ -0,0 +1,56 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center ??? Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm ??? Oscillator" +#property strict + +// +// START Inputs ... +// +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_separate_window +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + return(INIT_SUCCEEDED); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// END Functions ... +// \ No newline at end of file diff --git a/Docs/Templates/x-pine-script.indicator.template.pine b/Docs/Templates/x-pine-script.indicator.template.pine new file mode 100644 index 0000000..5a5dabe --- /dev/null +++ b/Docs/Templates/x-pine-script.indicator.template.pine @@ -0,0 +1,57 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center ??? Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// + +// +//@version=5 +indicator(title="SaherElm ??? Indicator", shorttitle = "XS_??_IND", overlay = true) + +// +// START Inputs .... +// +// +// END Inputs .... +// + +// +// START Functions .... +// +// +// END Functions .... +// + +// +// START Calculations .... +// +// +// END Calculations .... +// + +// +// START Plots .... +// +plot(close) +// +// END Plots .... +// + +// +// START Alerts ... +// +// +// END Alerts ... +// + +////////////////////////////////////////////////////// +// TODOS: +// ------- +// - [] +////////////////////////////////////////////////////// diff --git a/Docs/Templates/x-pine-script.oscillator.template.pine b/Docs/Templates/x-pine-script.oscillator.template.pine new file mode 100644 index 0000000..f95cc78 --- /dev/null +++ b/Docs/Templates/x-pine-script.oscillator.template.pine @@ -0,0 +1,57 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center ??? Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// + +// +//@version=5 +indicator(title="SaherElm ??? Oscillator", shorttitle = "XS_??_OSC", overlay = false) + +// +// START Inputs .... +// +// +// END Inputs .... +// + +// +// START Functions .... +// +// +// END Functions .... +// + +// +// START Calculations .... +// +// +// END Calculations .... +// + +// +// START Plots .... +// +plot(close) +// +// END Plots .... +// + +// +// START Alerts ... +// +// +// END Alerts ... +// + +////////////////////////////////////////////////////// +// TODOS: +// ------- +// - [] +////////////////////////////////////////////////////// diff --git a/Docs/Templates/x-pine-script.strategy.template.pine b/Docs/Templates/x-pine-script.strategy.template.pine new file mode 100644 index 0000000..f80bbd7 --- /dev/null +++ b/Docs/Templates/x-pine-script.strategy.template.pine @@ -0,0 +1,195 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XTrade ??? Strategy +// --------------------------------------------- +// in this strategy i must use: +// - ; +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// + +// +//@version=5 +indicator(title="SaherElm XTrade ??? Strategy", shorttitle = "XST_???", overlay = true) + +// +// START Inputs .... +// +// +// Determines Show Signals or not ... +showSignals = input.bool(defval = true, title = "Show Signals", group = "Strategy") +showStopLosses = input.bool(defval = true, title = "Show Stop Losses", group = "Strategy") + +// +// Show Signals based on their types ... +showLongSignals = input.bool(defval = true, title = "Show Long Signals", group = "Signals") +showShortSignals = input.bool(defval = true, title = "Show Short Signals", group = "Signals") + +// +// Show Stop Losses based on their types ... +swingLoopback = input.int(defval = 7, title = "Swing Loopback Period", group = "Stop Loss") +showLongStopLosses = input.bool(defval = true, title = "Show Long Stop Losses", group = "Stop Loss") +showShortStopLosses = input.bool(defval = true, title = "Show Short Stop Losses", group = "Stop Loss") +// +// END Inputs .... +// + +// +// START Functions .... +// +////////////////////////////// +// START Price Action Candles +////////////////////////////// +// +// Retrieve Specific Candle Height (based on low and high) ... +getCandleRange() => + high - low + +// +// Retrieve Candle Ranges Thirs Section ... +getCandleThird() => + getCandleRange() / 3 + +// +// Determines a Candle is Bullish or not ... +isBullishCandle() => + close > low + (getCandleThird() * 2) + +// +// Determines a Candle is Bearish or not ... +isNeutralCandle() => + close < low + (getCandleThird() * 2) and close > low + getCandleThird() + +// +// Determines a Candle is Neutral or not ... +isBearishCandle() => + close < low + getCandleThird() +///////////////////////////// +// END Price Action Candles +///////////////////////////// +// +// END Functions .... +// + +// +// START Calculations .... +// +// +var shortColor = color.red +var longColor = color.lime + +////////////////////////////// +// START Price Action Candles +////////////////////////////// +// +var bullishColor = color.lime +var bullishShape = shape.arrowup +var bullishTitle = "Bullish" +var bullishType = 1 + +// +var bearishColor = color.red +var bearishShape = shape.arrowdown +var bearishTitle = "Bearish" +var bearishType = -1 + +// +var neutralColor = color.gray +var neutralShape = shape.circle +var neutralTitle = "Neutral" +var neutralType = 0 + +// +candleType = isBullishCandle() ? bullishType : isNeutralCandle() ? neutralType : isBearishCandle() ? bearishType : neutralType + +// +prevCandleType = not na(candleType[1]) ? candleType[1] : neutralType + +// +candleNeighborhoodBaseType = prevCandleType + candleType +///////////////////////////// +// END Price Action Candles +///////////////////////////// + +//////////////////////////// +// START Last Market Price +//////////////////////////// +// +lastMarketLowest = ta.lowest(low, swingLoopback) +lastMarketLowest2 = ta.lowest(low, swingLoopback * 2) +lastMarketLowest3 = ta.lowest(low, swingLoopback * 3) + +// +lastMarketHighest = ta.highest(high, swingLoopback) +lastMarketHighest2 = ta.highest(high, swingLoopback * 2) +lastMarketHighest3 = ta.highest(high, swingLoopback * 3) +//////////////////////////// +// END Last Market Price +//////////////////////////// + +/////////////////////// +// START Strategy ... +/////////////////////// +// +canShowStopLoss = showSignals and showStopLosses and (showLongSignals or showShortSignals) and (showLongStopLosses or showShortStopLosses) +canShowLongStopLoss = canShowStopLoss and showLongStopLosses // and not na(ATRSLLongStopLoss) +canShowShortStopLoss = canShowStopLoss and showShortStopLosses // and not na(ATRSLShortStopLoss) + +// +hasSignal = false // HUTRHasSignal + +// +hasLongSignal = hasSignal and isBullishCandle() and false // HUTRHasLongSignal +longSignal = hasLongSignal ? na : na // HUTRLongSignal : na +float longStopLoss = lastMarketLowest + +// +hasShortSignal = hasSignal and isBearishCandle() and false // HUTRHasShortSignal +shortSignal = hasShortSignal ? na : na // HUTRShortSignal : na +float shortStopLoss = lastMarketHighest + +// +canShowSignal = showSignals and (showLongSignals or showShortSignals) +canShowLongSignal = canShowSignal and showLongSignals and hasLongSignal +canShowShortSignal = canShowSignal and showShortSignals and hasShortSignal +/////////////////////// +// END Strategy ... +/////////////////////// +// +// END Calculations .... +// + +// +// START Plots .... +// +// +// Signals ... +plotshape(canShowLongSignal ? longSignal : na, title = "Long Signal", color = longColor, location = location.belowbar, style = shape.triangleup, size = size.normal) +plotshape(canShowShortSignal ? shortSignal : na, title = "Short Signal", color = shortColor, location = location.abovebar, style = shape.triangledown, size = size.normal) + +// +// Stop Losses ... +plot(series = canShowLongStopLoss ? longStopLoss : na, color = color.fuchsia, linewidth = 1, style = plot.style_stepline, title = "Long Stop Loss") +plot(series = canShowShortStopLoss ? shortStopLoss : na, color = color.aqua, linewidth = 1, style = plot.style_stepline, title = "Short Stop Loss") +// +// END Plots .... +// + +// +// START Alerts ... +// +alertcondition(hasSignal, "XST_SHULL5M > Signal") +alertcondition(hasLongSignal, "XST_SHULL5M > Long Signal") +alertcondition(hasShortSignal, "XST_SHULL5M > Short Signal") +// +// END Alerts ... +// + +////////////////////////////////////////////////////// +// TODOS: +// ------- +// - [] +////////////////////////////////////////////////////// diff --git a/Docs/Templates/x-trade.tempolate.report.txt b/Docs/Templates/x-trade.tempolate.report.txt new file mode 100644 index 0000000..1c44a5b --- /dev/null +++ b/Docs/Templates/x-trade.tempolate.report.txt @@ -0,0 +1,55 @@ +Daily Time Frame: +------------------ + +------------------------- +LONGS: +------------------------- + +XTrade Strong Buy Signals +------------------------- +R2R => 1 risk to 2 reward + +Signals: +--------- +Found: +TP: +SL: +Open: + +XTrade Buy Signals +------------------- +R2R => 1 risk to 1.5 reward + +Signals: +--------- +Found: +TP: +SL: +Open: + + +-------------------------- +SHORTS: +-------------------------- + +XTrade Strong SELl Signals +-------------------------- +R2R => 1 risk to 2 reward + +Signals: +--------- +Found: +TP: +SL: +Open: + +XTrade Sell Signals +-------------------- +R2R => 1 risk to 1.5 reward + +Signals: +--------- +Found: +TP: +SL: +Open: diff --git a/Packed/XAUUSD-15M/Configs/3000 - 0.75.set b/Packed/XAUUSD-15M/Configs/3000 - 0.75.set new file mode 100644 index 0000000..32e95b8 --- /dev/null +++ b/Packed/XAUUSD-15M/Configs/3000 - 0.75.set @@ -0,0 +1,296 @@ +signalPrefix=XST_EA +bullishSignalLabel=X_BUY +bullishSignalColor=16776960 +bearishSignalLabel=X_SELL +bearishSignalColor=16711935 +signalEntryColor=13959039 +signalSLColor=255 +signalTPColor=32768 +candleGapBetweenSignals=7 +candleGapBetweenSignals,F=0 +candleGapBetweenSignals,1=6 +candleGapBetweenSignals,2=0 +candleGapBetweenSignals,3=0 +allowTrade=1 +allowTrade,F=0 +allowTrade,1=0 +allowTrade,2=1 +allowTrade,3=1 +allowLongTrades=1 +allowLongTrades,F=0 +allowLongTrades,1=0 +allowLongTrades,2=1 +allowLongTrades,3=1 +allowShortTrades=1 +allowShortTrades,F=0 +allowShortTrades,1=0 +allowShortTrades,2=1 +allowShortTrades,3=1 +alertEvents=1 +alertEvents,F=0 +alertEvents,1=0 +alertEvents,2=1 +alertEvents,3=1 +alertPositions=1 +alertPositions,F=0 +alertPositions,1=0 +alertPositions,2=1 +alertPositions,3=1 +longPositionAlerts=1 +longPositionAlerts,F=0 +longPositionAlerts,1=0 +longPositionAlerts,2=1 +longPositionAlerts,3=1 +shortPositionAlerts=1 +shortPositionAlerts,F=0 +shortPositionAlerts,1=0 +shortPositionAlerts,2=1 +shortPositionAlerts,3=1 +terminalAlert=0 +terminalAlert,F=0 +terminalAlert,1=0 +terminalAlert,2=1 +terminalAlert,3=1 +pushAlert=0 +pushAlert,F=0 +pushAlert,1=0 +pushAlert,2=1 +pushAlert,3=1 +lotsPerTradePercent=0.00001000 +lotsPerTradePercent,F=0 +lotsPerTradePercent,1=0.00030000 +lotsPerTradePercent,2=0.00000000 +lotsPerTradePercent,3=0.00000000 +maxOpenTrades=4 +maxOpenTrades,F=0 +maxOpenTrades,1=4 +maxOpenTrades,2=0 +maxOpenTrades,3=0 +maxDrawdownPercentPerPTrade=0.10000000 +maxDrawdownPercentPerPTrade,F=0 +maxDrawdownPercentPerPTrade,1=0.30000000 +maxDrawdownPercentPerPTrade,2=0.00000000 +maxDrawdownPercentPerPTrade,3=0.00000000 +minBalancePercent=0.50000000 +minBalancePercent,F=0 +minBalancePercent,1=0.50000000 +minBalancePercent,2=0.00000000 +minBalancePercent,3=0.00000000 +maxEquityPercent=0.10000000 +maxEquityPercent,F=0 +maxEquityPercent,1=0.10000000 +maxEquityPercent,2=0.00000000 +maxEquityPercent,3=0.00000000 +xStarter=- X Signal Provider - +enableXSignalling=1 +enableXSignalling,F=0 +enableXSignalling,1=0 +enableXSignalling,2=1 +enableXSignalling,3=1 +enableXLong=1 +enableXLong,F=0 +enableXLong,1=0 +enableXLong,2=1 +enableXLong,3=1 +enableXShort=1 +enableXShort,F=0 +enableXShort,1=0 +enableXShort,2=1 +enableXShort,3=1 +xShortR2R=3.00000000 +xShortR2R,F=0 +xShortR2R,1=2.50000000 +xShortR2R,2=0.00000000 +xShortR2R,3=0.00000000 +xShortLotsPerTradePercent=0.00025000 +xShortLotsPerTradePercent,F=0 +xShortLotsPerTradePercent,1=0.00002000 +xShortLotsPerTradePercent,2=0.00000000 +xShortLotsPerTradePercent,3=0.00000000 +xShortMaxDrawdownPerTradePercent=0.45000000 +xShortMaxDrawdownPerTradePercent,F=0 +xShortMaxDrawdownPerTradePercent,1=0.02000000 +xShortMaxDrawdownPerTradePercent,2=0.00000000 +xShortMaxDrawdownPerTradePercent,3=0.00000000 +xLongR2R=3.00000000 +xLongR2R,F=0 +xLongR2R,1=2.50000000 +xLongR2R,2=0.00000000 +xLongR2R,3=0.00000000 +xLongLotsPerTradePercent=0.00025000 +xLongLotsPerTradePercent,F=0 +xLongLotsPerTradePercent,1=0.00002000 +xLongLotsPerTradePercent,2=0.00000000 +xLongLotsPerTradePercent,3=0.00000000 +xLongMaxDrawdownPerTradePercent=0.45000000 +xLongMaxDrawdownPerTradePercent,F=0 +xLongMaxDrawdownPerTradePercent,1=0.02000000 +xLongMaxDrawdownPerTradePercent,2=0.00000000 +xLongMaxDrawdownPerTradePercent,3=0.00000000 +xSharpDetectorFactor=700.00000000 +xSharpDetectorFactor,F=0 +xSharpDetectorFactor,1=700.00000000 +xSharpDetectorFactor,2=0.00000000 +xSharpDetectorFactor,3=0.00000000 +xMaximumCandlesPerTrade=206 +xMaximumCandlesPerTrade,F=0 +xMaximumCandlesPerTrade,1=504 +xMaximumCandlesPerTrade,2=0 +xMaximumCandlesPerTrade,3=0 +xOscillatorLength=7 +xOscillatorLength,F=0 +xOscillatorLength,1=7 +xOscillatorLength,2=0 +xOscillatorLength,3=0 +xPSarStep=0.02000000 +xPSarStep,F=0 +xPSarStep,1=0.02000000 +xPSarStep,2=0.00000000 +xPSarStep,3=0.00000000 +xPSarMaximum=0.20000000 +xPSarMaximum,F=0 +xPSarMaximum,1=0.20000000 +xPSarMaximum,2=0.00000000 +xPSarMaximum,3=0.00000000 +xRangeMarketLength=5 +xRangeMarketLength,F=0 +xRangeMarketLength,1=35 +xRangeMarketLength,2=0 +xRangeMarketLength,3=0 +xSwingLength=7 +xSwingLength,F=0 +xSwingLength,1=7 +xSwingLength,2=0 +xSwingLength,3=0 +xRStarter=- XR Signal Provider - +enableXRSignalling=0 +enableXRSignalling,F=0 +enableXRSignalling,1=0 +enableXRSignalling,2=1 +enableXRSignalling,3=1 +enableXRLong=1 +enableXRLong,F=0 +enableXRLong,1=0 +enableXRLong,2=1 +enableXRLong,3=1 +enableXRShort=1 +enableXRShort,F=0 +enableXRShort,1=0 +enableXRShort,2=1 +enableXRShort,3=1 +xRShortR2R=1.50000000 +xRShortR2R,F=0 +xRShortR2R,1=2.00000000 +xRShortR2R,2=0.00000000 +xRShortR2R,3=0.00000000 +xRShortLotsPerTradePercent=0.00020000 +xRShortLotsPerTradePercent,F=0 +xRShortLotsPerTradePercent,1=0.00001000 +xRShortLotsPerTradePercent,2=0.00000000 +xRShortLotsPerTradePercent,3=0.00000000 +xRShortMaxDrawdownPerTradePercent=0.15000000 +xRShortMaxDrawdownPerTradePercent,F=0 +xRShortMaxDrawdownPerTradePercent,1=0.01000000 +xRShortMaxDrawdownPerTradePercent,2=0.00000000 +xRShortMaxDrawdownPerTradePercent,3=0.00000000 +xRLongR2R=1.50000000 +xRLongR2R,F=0 +xRLongR2R,1=2.00000000 +xRLongR2R,2=0.00000000 +xRLongR2R,3=0.00000000 +xRLongLotsPerTradePercent=0.00020000 +xRLongLotsPerTradePercent,F=0 +xRLongLotsPerTradePercent,1=0.00001000 +xRLongLotsPerTradePercent,2=0.00000000 +xRLongLotsPerTradePercent,3=0.00000000 +xRLongMaxDrawdownPerTradePercent=0.15000000 +xRLongMaxDrawdownPerTradePercent,F=0 +xRLongMaxDrawdownPerTradePercent,1=0.01000000 +xRLongMaxDrawdownPerTradePercent,2=0.00000000 +xRLongMaxDrawdownPerTradePercent,3=0.00000000 +xRMaximumCandlesPerTrade=96 +xRMaximumCandlesPerTrade,F=0 +xRMaximumCandlesPerTrade,1=252 +xRMaximumCandlesPerTrade,2=0 +xRMaximumCandlesPerTrade,3=0 +xRSwingLength=48 +xRSwingLength,F=0 +xRSwingLength,1=7 +xRSwingLength,2=0 +xRSwingLength,3=0 +xRSharpDetectionFactor=1350.00000000 +xRSharpDetectionFactor,F=0 +xRSharpDetectionFactor,1=650.00000000 +xRSharpDetectionFactor,2=0.00000000 +xRSharpDetectionFactor,3=0.00000000 +xTPWStarter=- XTPW Signal Provider - +enableXTPWSignalling=1 +enableXTPWSignalling,F=0 +enableXTPWSignalling,1=0 +enableXTPWSignalling,2=1 +enableXTPWSignalling,3=1 +enableXTPWLong=1 +enableXTPWLong,F=0 +enableXTPWLong,1=0 +enableXTPWLong,2=1 +enableXTPWLong,3=1 +enableXTPWShort=1 +enableXTPWShort,F=0 +enableXTPWShort,1=0 +enableXTPWShort,2=1 +enableXTPWShort,3=1 +xTPWShortR2R=2.00000000 +xTPWShortR2R,F=0 +xTPWShortR2R,1=1.50000000 +xTPWShortR2R,2=0.00000000 +xTPWShortR2R,3=0.00000000 +xTPWShortLotsPerTradePercent=0.00025000 +xTPWShortLotsPerTradePercent,F=0 +xTPWShortLotsPerTradePercent,1=0.00001000 +xTPWShortLotsPerTradePercent,2=0.00000000 +xTPWShortLotsPerTradePercent,3=0.00000000 +xTPWShortMaxDrawdownPerTradePercent=0.30000000 +xTPWShortMaxDrawdownPerTradePercent,F=0 +xTPWShortMaxDrawdownPerTradePercent,1=0.01000000 +xTPWShortMaxDrawdownPerTradePercent,2=0.00000000 +xTPWShortMaxDrawdownPerTradePercent,3=0.00000000 +xTPWLongR2R=2.00000000 +xTPWLongR2R,F=0 +xTPWLongR2R,1=1.50000000 +xTPWLongR2R,2=0.00000000 +xTPWLongR2R,3=0.00000000 +xTPWLongLotsPerTradePercent=0.00025000 +xTPWLongLotsPerTradePercent,F=0 +xTPWLongLotsPerTradePercent,1=0.00001000 +xTPWLongLotsPerTradePercent,2=0.00000000 +xTPWLongLotsPerTradePercent,3=0.00000000 +xTPWLongMaxDrawdownPerTradePercent=0.30000000 +xTPWLongMaxDrawdownPerTradePercent,F=0 +xTPWLongMaxDrawdownPerTradePercent,1=0.01000000 +xTPWLongMaxDrawdownPerTradePercent,2=0.00000000 +xTPWLongMaxDrawdownPerTradePercent,3=0.00000000 +xTPWMaximumCandlesPerTrade=206 +xTPWMaximumCandlesPerTrade,F=0 +xTPWMaximumCandlesPerTrade,1=206 +xTPWMaximumCandlesPerTrade,2=0 +xTPWMaximumCandlesPerTrade,3=0 +xTPWPSarStep=0.02000000 +xTPWPSarStep,F=0 +xTPWPSarStep,1=0.02000000 +xTPWPSarStep,2=0.00000000 +xTPWPSarStep,3=0.00000000 +xTPWPSarMaximum=0.20000000 +xTPWPSarMaximum,F=0 +xTPWPSarMaximum,1=0.20000000 +xTPWPSarMaximum,2=0.00000000 +xTPWPSarMaximum,3=0.00000000 +xTPWSwingLength=7 +xTPWSwingLength,F=0 +xTPWSwingLength,1=7 +xTPWSwingLength,2=0 +xTPWSwingLength,3=0 +xTPWSharpDetectionFactor=650.00000000 +xTPWSharpDetectionFactor,F=0 +xTPWSharpDetectionFactor,1=700.00000000 +xTPWSharpDetectionFactor,2=0.00000000 +xTPWSharpDetectionFactor,3=0.00000000 diff --git a/Packed/XAUUSD-15M/EX4/EA/x-saherelm.ea.ex4 b/Packed/XAUUSD-15M/EX4/EA/x-saherelm.ea.ex4 new file mode 100644 index 0000000..aef5abd Binary files /dev/null and b/Packed/XAUUSD-15M/EX4/EA/x-saherelm.ea.ex4 differ diff --git a/Packed/XAUUSD-15M/EX4/Indicators/x-saherelm.ma.ex4 b/Packed/XAUUSD-15M/EX4/Indicators/x-saherelm.ma.ex4 new file mode 100644 index 0000000..9748437 Binary files /dev/null and b/Packed/XAUUSD-15M/EX4/Indicators/x-saherelm.ma.ex4 differ diff --git a/Packed/XAUUSD-15M/EX4/Indicators/x-saherelm.xrange.ex4 b/Packed/XAUUSD-15M/EX4/Indicators/x-saherelm.xrange.ex4 new file mode 100644 index 0000000..448c8e1 Binary files /dev/null and b/Packed/XAUUSD-15M/EX4/Indicators/x-saherelm.xrange.ex4 differ diff --git a/Packed/XAUUSD-15M/EX4/Indicators/x-saherelm.xtpow.ex4 b/Packed/XAUUSD-15M/EX4/Indicators/x-saherelm.xtpow.ex4 new file mode 100644 index 0000000..2ec4f57 Binary files /dev/null and b/Packed/XAUUSD-15M/EX4/Indicators/x-saherelm.xtpow.ex4 differ diff --git a/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.draw.lib.ex4 b/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.draw.lib.ex4 new file mode 100644 index 0000000..2e4494b Binary files /dev/null and b/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.draw.lib.ex4 differ diff --git a/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.indicator.lib.ex4 b/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.indicator.lib.ex4 new file mode 100644 index 0000000..2675757 Binary files /dev/null and b/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.indicator.lib.ex4 differ diff --git a/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.lib.ex4 b/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.lib.ex4 new file mode 100644 index 0000000..e33c004 Binary files /dev/null and b/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.lib.ex4 differ diff --git a/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.log.lib.ex4 b/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.log.lib.ex4 new file mode 100644 index 0000000..89c1f41 Binary files /dev/null and b/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.log.lib.ex4 differ diff --git a/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.models.lib.ex4 b/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.models.lib.ex4 new file mode 100644 index 0000000..7fcdc65 Binary files /dev/null and b/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.models.lib.ex4 differ diff --git a/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.signal.lib.ex4 b/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.signal.lib.ex4 new file mode 100644 index 0000000..0332293 Binary files /dev/null and b/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.signal.lib.ex4 differ diff --git a/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.x.signal.lib.ex4 b/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.x.signal.lib.ex4 new file mode 100644 index 0000000..890d254 Binary files /dev/null and b/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.x.signal.lib.ex4 differ diff --git a/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.xr.signal.lib.ex4 b/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.xr.signal.lib.ex4 new file mode 100644 index 0000000..2495863 Binary files /dev/null and b/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.xr.signal.lib.ex4 differ diff --git a/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.xtpw.signal.lib.ex4 b/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.xtpw.signal.lib.ex4 new file mode 100644 index 0000000..88f353a Binary files /dev/null and b/Packed/XAUUSD-15M/EX4/Libraries/x-saherelm.xtpw.signal.lib.ex4 differ diff --git a/Packed/XAUUSD-15M/MQL4/EA/x-saherelm.ea.mq4 b/Packed/XAUUSD-15M/MQL4/EA/x-saherelm.ea.mq4 new file mode 100644 index 0000000..d8a63ca --- /dev/null +++ b/Packed/XAUUSD-15M/MQL4/EA/x-saherelm.ea.mq4 @@ -0,0 +1,1038 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XST Strategy Expert Advisor +// --------------------------------------------- +// saherelm implementation of strategy expert advisor ... +// in this EA, we try to combine multiple tools, to ashive best +// results ... +// +// ShortName: XST +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +989121694056 +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XST Strategy Expert Advisor" +#property strict + +// +// START Inputs ... +// +// +// Signal Prefixe ... +input string signalPrefix = "XST_EA"; // Signal Prefix + +// +// Signal Draw Specifications ... +input string bullishSignalLabel = "X_BUY"; // Bullish Signal Label +input color bullishSignalColor = clrAqua; // Bullish Signal Color + +// +input string bearishSignalLabel = "X_SELL"; // Bearish Signal Label +input color bearishSignalColor = clrFuchsia; // Bearish Signal Color + +// +input color signalEntryColor = clrAquamarine; // Signal Entry Ptice Color +input color signalSLColor = clrRed; // Signal SL Color +input color signalTPColor = clrGreen; // Signal TP Color + +// +input int candleGapBetweenSignals = 7; // How many Candle waits to new Signal from last one + +// +// Trade ... +input bool allowTrade = true; // Allow Trade Based on given Signals +input bool allowLongTrades = true; // Allow Long Trades +input bool allowShortTrades = true; // Allow Short Trades + +// +// Alerts ... +input bool alertEvents = true; // Alert Events +input bool alertPositions = true; // Alert Positions +input bool longPositionAlerts = true; // Alert Long Positions +input bool shortPositionAlerts = true; // Alert Short Positions + +// +// Alert Types ... +input bool terminalAlert = false; // Terminal Alert +input bool pushAlert = false; // Push Notification Alerts + +// +// Balance and Finanical Specifications ... +input double lotsPerTradePercent = 0.00001; // Lots Per Trade Percent +input int maxOpenTrades = 4; // Maximum Open Trade +input double maxDrawdownPercentPerPTrade = 0.1; // Maximum DrawDown Per Trade +input double minBalancePercent = 0.5; // Minimum Balance for Trading +input double maxEquityPercent = 0.1; // Maximum Trade Equity + +// +// START Global Definitions: Variables, Properties and etc ... +// +int lastSignalledBar = 0; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.signal.lib.mq4" + +// +int maxMarketLength = 0; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Validate Inputs ... + bool inputsNotValiid = + // + // EA ... + maxOpenTrades <= 0 + || maxEquityPercent < 0 + || minBalancePercent < 0 + || lotsPerTradePercent < 0 + || maxDrawdownPercentPerPTrade < 0 + ; + + // + if (inputsNotValiid) { + return INIT_PARAMETERS_INCORRECT; + } + + // + totalSignals = 0; + totalLongSignals = 0; + totalShortSignals = 0; + + // + initialBalance = 0; + + // + // START Define Array Series ... + // + // + // END Define Array Series ... + // + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST"; + + // + ClearSignalConditions(); + + // + maxMarketLength = MathMax(0, GetDailyCandleCount()); + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { +} + +// +// Ticker Event Handler ... +void OnTick() { + // + isNewDay = IsNewDay(); + if (isNewDay) { + // + LogMessage( + StringConcatenate( + "New Day ..." + ) + ); + } + + // + // Process Signals to Open Positions ... + ProcessSignals(); + + // + // Checking State for Signal Handling ... + CheckState(); + + // + // Process Open Positions for Trailing Stop Loss or Close ... + ProcessOpenPositions(); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Check State for Signal Handling ... +void CheckState() { + // + // Here we Must to Check Market State for enable or disable + // Signal Handlers and also make dection to close all long/short + // trades ... +} + +// +// Calculate Signals and Process Based on Exists Signals ... +void ProcessSignals() { + // + XSignalRequest request = {}; + request.type = X_SIGNAL_NONE; + request.hasSignal = false; + + // + // Prevent Multiple Calculating on Same Bars ... + isNewBar = IsNewBar(); + if (isNewBar) { + countedBars++; + } + + // + if (countedBars < maxMarketLength) { + return; + } + + // + bool allowDoTrade = true; + + // + // Check Balance ... + if (initialBalance > 0) { + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double minimumBalanceForTrade = + balance > initialBalance + ? + minBalancePercent * balance + : + minBalancePercent * initialBalance; + + // + // Retrieve Account Equity ... + double equity = AccountInfoDouble(ACCOUNT_EQUITY); + double maxAllowedEquity = balance - (balance * maxEquityPercent); + + // + // Retrieve Free Marigin ... + double freeMargin = AccountFreeMargin(); + double maximumMariginRisk = balance - (balance * maxEquityPercent); + + // + if ( + // + // Do not Open Positions if equity not passed ... + equity < maxAllowedEquity || + // + // Do not Open Positions if free margin not passed ... + freeMargin <= maximumMariginRisk || + // + // Do not open positions if balance less than minimum ... + balance <= minimumBalanceForTrade + ) { + // + static bool tradingPauseAlerted; + + // + allowDoTrade = false; + + // + if (!tradingPauseAlerted) { + // + string message = StringConcatenate( + "Trading Pause => ", + "Balance: ", balance, + ", Equity: ", equity, + ", FreeMargin: ", freeMargin + ); + + // + LogMessage(message); + SendAlert(message); + + // + tradingPauseAlerted = true; + } + } + } + + // + // Retrieve Signal Exists ... + request = GenerateSignal(0); + + // + // Prevent doing anything else, if there is no signals ... + if ( + !allowDoTrade || + !request.hasSignal || + request.type == X_SIGNAL_NONE + ) { + return; + } + + // + bool hasLongSignal = request.type == X_SIGNAL_LONG; + + // + // Check last Signalled Bar with Counted Bars ... + // Prevent Multiple Signalling on Same Bar ... + bool isInLastSignalledBars = false; + for (int i=0; i < candleGapBetweenSignals; i++) { + // + isInLastSignalledBars = + isInLastSignalledBars + || lastSignalledBar == countedBars - i + ; + } + if (isInLastSignalledBars) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + return; + } + + // + // increase last signalled bar ... + lastSignalledBar = countedBars; + + // + // Calculate Can Trade or not ... + allowDoTrade = allowTrade + && ( + hasLongSignal ? + allowLongTrades : + allowShortTrades + ); + + // + // Chack Maximum Open Positions ... + int openTrades = CountOpenTrades(); + if (maxOpenTrades > 0) { + // + if (openTrades >= maxOpenTrades) { + // + allowDoTrade = false; + + // + if (!allowDoTrade) { + // + string message = StringConcatenate( + "Trading Pause => ", + "Max Open Trades (", + maxOpenTrades, + ") reached ..." + ); + + // + LogMessage(message); + SendAlert(message); + } + } + } + + // + // Check Trading is Enable or not ... + // nothing to do if trading is disabled ... + if (!allowDoTrade) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + string message = StringConcatenate( + "Trading Not Allowed ..." + ); + + // + LogMessage(message); + SendAlert(message); + return; + } + + // + // Retrieve Signal Lots Per Trade ... + double lPTradePercent = GetSignalLottage( + request.signal, + lotsPerTradePercent + ); + + // + bool isPositionOpened = TradeSignal( + request.signal, + lPTradePercent, + // + bullishSignalLabel, + bullishSignalColor, + bearishSignalLabel, + bearishSignalColor + ); + + // + totalSignals++; + if (hasLongSignal) { + // + totalLongSignals++; + ClearLongSignalConditions(); + } else { + // + totalShortSignals++; + ClearShortSignalConditions(); + } + + // + if (isPositionOpened) { + // + bool canAlert = + alertPositions + && ( + hasLongSignal ? + longPositionAlerts + : + shortPositionAlerts + ); + + // + if (canAlert) { + // + // Alert Message ... + string message = StringConcatenate( + "Trade on Signal ID: ", request.signal.id, + ", ProvidedBy: ", GetSignalProviderIdentifier(request.signal.provider), + ", Entry: ", request.signal.entry, + ", TP: ", request.signal.tp + ); + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } + } + } +} + +// +// Process All Open Positions ... +void ProcessOpenPositions() { + // + // XSignalling ... + if (enableXSignalling) { + // + // Close All XXX Provided Signals on it's Specific Condition ... + if (xCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XXX_PROVIDER); + + // + xCloseLongTrades = false; + } + + // + if (xCloseShortTrades) { + // + CloseAllProviderShortTrades(X_XTPW_PROVIDER); + + // + xCloseShortTrades = false; + } + + // + // Close Maximum DrawDown Passed Trades ... + + // + // Longs ... + bool hasClosedLongInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xLongMaxDrawdownPerTradePercent, + X_SIGNAL_LONG, + X_XXX_PROVIDER + ); + + // + // Shorts ... + bool hasClosedShortInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xShortMaxDrawdownPerTradePercent, + X_SIGNAL_SHORT, + X_XXX_PROVIDER + ); + + // + // Close All Long Time Trades based on Provider provided Length ... + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + xMaximumCandlesPerTrade, + X_XXX_PROVIDER + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedLongInDrawDownLongTrade + || hasClosedShortInDrawDownLongTrade + ) { + xFailedSignals++; + } + } + + // + // XR Signalling ... + if (enableXRSignalling) { + // + if (xRCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XR_PROVIDER); + + // + xRCloseLongTrades = false; + } + + // + if (xRCloseShortTrades) { + // + CloseAllProviderShortTrades(X_XR_PROVIDER); + + // + xRCloseShortTrades = false; + } + + // + // Close Maximum DrawDown Passed Trades ... + + // + // Longs ... + bool hasClosedLongInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xRLongMaxDrawdownPerTradePercent, + X_SIGNAL_LONG, + X_XR_PROVIDER + ); + + // + // Shorts ... + bool hasClosedShortInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xRShortMaxDrawdownPerTradePercent, + X_SIGNAL_SHORT, + X_XR_PROVIDER + ); + + // + // Close All Long Time Trades based on Provider provided Length ... + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + xRMaximumCandlesPerTrade, + X_XR_PROVIDER + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedLongInDrawDownLongTrade + || hasClosedShortInDrawDownLongTrade + ) { + xRFailedSignals++; + } + } + + // + // XTPW Signalling ... + if (enableXTPWSignalling) { + // + if (xTPWCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XTPW_PROVIDER); + + // + xTPWCloseLongTrades = false; + } + + // + if (xTPWCloseShortTrades) { + // + CloseAllProviderShortTrades(X_XTPW_PROVIDER); + + // + xTPWCloseShortTrades = false; + } + + // + // Close Maximum DrawDown Passed Trades ... + + // + // Longs ... + bool hasClosedLongInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xTPWLongMaxDrawdownPerTradePercent, + X_SIGNAL_LONG, + X_XTPW_PROVIDER + ); + + // + // Shorts ... + bool hasClosedShortInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xTPWShortMaxDrawdownPerTradePercent, + X_SIGNAL_SHORT, + X_XTPW_PROVIDER + ); + + // + // Close All Long Time Trades based on Provider provided Length ... + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + xTPWMaximumCandlesPerTrade, + X_XTPW_PROVIDER + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedLongInDrawDownLongTrade + || hasClosedShortInDrawDownLongTrade + ) { + xTPWFailedSignals++; + } + } + + // + // Close Maximum DrawDown Passed Trades ... + // this is the Maximum Controller ... + // + double maxOfXPercent = enableXSignalling ? + MathMax( + xLongMaxDrawdownPerTradePercent, + xShortMaxDrawdownPerTradePercent + ) : 0 + ; + + // + double maxOfXRPercent = enableXRSignalling ? + MathMax( + xRLongMaxDrawdownPerTradePercent, + xRShortMaxDrawdownPerTradePercent + ) : 0 + ; + + // + double maxOfXTPWPercent = enableXTPWSignalling ? + MathMax( + xTPWLongMaxDrawdownPerTradePercent, + xTPWShortMaxDrawdownPerTradePercent + ) : 0 + ; + + // + double maxDrawDownPercent = MathMax( + maxOfXPercent, + maxOfXRPercent + ); + maxDrawDownPercent = MathMax( + maxDrawDownPercent, + maxOfXTPWPercent + ); + maxDrawDownPercent = MathMax( + maxDrawDownPercent, + maxDrawdownPercentPerPTrade + ); + + // + // we Calculate Max DrawDown Percent Per Trade ... + // then try to Close based on them ... + bool hasClosedInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + maxDrawDownPercent + ); +} + +// +// Send Special Type of Alerts ... +void SendAlert(string message) { + // + if (!alertEvents) { + return; + } + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } +} +// +// END Functions ... +// + +// +// +// Calculate Signal ... +// in this function we calculate a signal exists in +// specific bar or not ... +XSignalRequest GenerateSignal( + const int bar_index // Bar Index ... +) { + // + // create temp result ... + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + bool hasSignal = false; + bool hasLongSignal = false; + bool hasShortSignal = false; + + // + XSignal signal = {}; + + // + // Define Template Signal Requests for Managing Multiple Signals ... + // + // X ... + XSignalRequest xLongSignalRequest = {}; + XSignalRequest xShortSignalRequest = {}; + // + // XR ... + XSignalRequest xrLongSignalRequest = {}; + XSignalRequest xrShortSignalRequest = {}; + // + // XTPW ... + XSignalRequest xTPWLongSignalRequest = {}; + XSignalRequest xTPWShortSignalRequest = {}; + + // + // START XR Signal Handler ... + // + // + if (enableXRSignalling) { + // + CheckXRSignalHandler( + bar_index + ); + + // + // Long Trades ... + if (allowTrade && allowLongTrades) { + // + if (xRWaitForLongSignals) { + // + CheckXRLongSignalConditions( + bar_index + ); + + // + xrLongSignalRequest = GenerateXRSignal( + X_SIGNAL_LONG, + signalPrefix, + bar_index + ); + + // + if (xrLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXRSignals( + xrLongSignalRequest.signal + ); + + // + if (isReady && xRWaitForLongSignals) { + // + hasLongSignal = true; + signal = xrLongSignalRequest.signal; + } else { + ClearXRLongSignalConditions(); + } + } + } else { + ClearXRLongSignalConditions(); + } + } + + // + // Short Trades ... + if (allowTrade && allowShortTrades) { + // + if (xRWaitForShortSignals) { + // + CheckXRShortSignalConditions( + bar_index + ); + + // + xrShortSignalRequest = GenerateXRSignal( + X_SIGNAL_SHORT, + signalPrefix, + bar_index + ); + + // + if (xrShortSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXRSignals( + xrShortSignalRequest.signal + ); + + // + if (isReady && xRWaitForShortSignals) { + // + hasShortSignal = true; + signal = xrShortSignalRequest.signal; + } else { + ClearXRShortSignalConditions(); + } + } + } else { + ClearXRShortSignalConditions(); + } + } + } + // + // END XR Signal Handler ... + // + + // + // START XTPW Signal Handler ... + // + if (enableXTPWSignalling) { + // + CheckXTPWSignalHandler( + bar_index + ); + + // + // Long Trades ... + if (allowTrade && allowLongTrades) { + // + if (xTPWWaitForLongSignals) { + // + CheckXTPWLongSignalConditions( + bar_index + ); + + // + xTPWLongSignalRequest = GenerateXTPWSignal( + X_SIGNAL_LONG, + signalPrefix, + bar_index + ); + + // + if (xTPWLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXTPWSignals( + xTPWLongSignalRequest.signal + ); + + // + if (isReady && xTPWWaitForLongSignals) { + // + hasLongSignal = true; + signal = xTPWLongSignalRequest.signal; + } else { + ClearXTPWLongSignalConditions(); + } + } + } else { + ClearXTPWLongSignalConditions(); + } + } + + // + // Short Trades ... + if (allowTrade && allowShortTrades) { + // + if (xTPWWaitForShortSignals) { + // + CheckXTPWShortSignalConditions( + bar_index + ); + + // + xTPWShortSignalRequest = GenerateXTPWSignal( + X_SIGNAL_SHORT, + signalPrefix, + bar_index + ); + + // + if (xTPWShortSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXTPWSignals( + xTPWShortSignalRequest.signal + ); + + // + if (isReady && xTPWWaitForShortSignals) { + // + hasShortSignal = true; + signal = xTPWShortSignalRequest.signal; + } else { + ClearXTPWShortSignalConditions(); + } + } + } else { + ClearXTPWShortSignalConditions(); + } + } + } + // + // END XTPW Signal Handler ... + // + + // + // START X Signal Handler ... + // + // + if (enableXSignalling) { + // + CheckXSignalHandler( + bar_index + ); + + // + // Long Trades ... + if (allowTrade && allowLongTrades) { + // + if (xWaitForLongSignals) { + // + CheckXLongSignalConditions( + bar_index + ); + + // + xLongSignalRequest = GenerateXSignal( + X_SIGNAL_LONG, + signalPrefix, + bar_index + ); + + // + if (xLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXSignals( + xLongSignalRequest.signal + ); + + // + if (isReady && xWaitForLongSignals) { + // + hasLongSignal = true; + signal = xLongSignalRequest.signal; + } else { + ClearXLongSignalConditions(); + } + } + } else { + ClearXLongSignalConditions(); + } + } + + // + // Short Trades ... + if (allowTrade && allowShortTrades) { + // + if (xWaitForShortSignals) { + // + CheckXShortSignalConditions( + bar_index + ); + + // + xShortSignalRequest = GenerateXSignal( + X_SIGNAL_SHORT, + signalPrefix, + bar_index + ); + + // + if (xShortSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXSignals( + xShortSignalRequest.signal + ); + + // + if (isReady && xWaitForShortSignals) { + // + hasShortSignal = true; + signal = xShortSignalRequest.signal; + } else { + ClearXShortSignalConditions(); + } + } + } else { + ClearXShortSignalConditions(); + } + } + } + // + // END XR Signal Handler ... + // + + // + hasSignal = hasLongSignal || hasShortSignal; + + // + if (!hasSignal) { + // + signal.type = X_SIGNAL_NONE; + result.type = X_SIGNAL_NONE; + } + + // + // Normalize TP, SL and Entry Price ... + signal.tp = NormalizeDouble(signal.tp, _Digits); + signal.sl = NormalizeDouble(signal.sl, _Digits); + signal.entry = NormalizeDouble(signal.entry, _Digits); + + // + result.signal = signal; + result.type = signal.type; + result.hasSignal = hasSignal; + result.provider = signal.provider; + + // + // Return Result ... + return result; +} diff --git a/Packed/XAUUSD-15M/MQL4/Indicators/x-saherelm.ma.mq4 b/Packed/XAUUSD-15M/MQL4/Indicators/x-saherelm.ma.mq4 new file mode 100644 index 0000000..e3a5737 --- /dev/null +++ b/Packed/XAUUSD-15M/MQL4/Indicators/x-saherelm.ma.mq4 @@ -0,0 +1,173 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MA Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm MA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Fast MA ... +input int maLength = 20; // MA Length +input int maShift = 0; // MA Shift +input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method +input ENUM_APPLIED_PRICE maAppliedPrice = PRICE_CLOSE; // MA Applied Price + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 1 + +// +#property indicator_plots 1 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Fast Ma Buffer ... +#property indicator_label1 "Ma" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrYellow +#property indicator_style1 STYLE_DOT +#property indicator_width1 2 + +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define maBufferIndex 0 + +double maBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (maLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + // + // Ma ... + SetIndexBuffer(maBufferIndex, maBuffer); + SetIndexDrawBegin(maBufferIndex, maLength + 1); + // + // End Set Index Buffers ... + // + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, maLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Ma ... + CalculateMa(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateMa( + const int &bar_index +) { + // + // Calculating Fast Ma ... + double ma = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + maAppliedPrice, + bar_index + ); + + // + maBuffer[bar_index] = ma; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Packed/XAUUSD-15M/MQL4/Indicators/x-saherelm.xrange.mq4 b/Packed/XAUUSD-15M/MQL4/Indicators/x-saherelm.xrange.mq4 new file mode 100644 index 0000000..1359f57 --- /dev/null +++ b/Packed/XAUUSD-15M/MQL4/Indicators/x-saherelm.xrange.mq4 @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XRange Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XRange Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 14; +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 3 + +// +#property indicator_plots 3 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Highest High Buffer ... +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +// Lowest Low Buffer ... +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +// Middle Buffer ... +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_DASH +#property indicator_width3 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +// +#define highestHighBufferIndex 0 +#define lowestLowBufferIndex 1 +#define middleBufferIndex 2 + +// +double highestHighBuffer[]; +double lowestLowBuffer[]; +double middleBuffer[]; + +// +datetime startTime; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if ( + marketLength <= 0 + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + string hhLbl = StringConcatenate( + "XR HH(", marketLength, ")" + ); + SetIndexBuffer(highestHighBufferIndex, highestHighBuffer); + SetIndexLabel(highestHighBufferIndex, hhLbl); + + // + string llLbl = StringConcatenate( + "XR LL(", marketLength, ")" + ); + SetIndexBuffer(lowestLowBufferIndex, lowestLowBuffer); + SetIndexLabel(lowestLowBufferIndex, llLbl); + + // + string midLbl = StringConcatenate( + "XR Mid(", marketLength, ")" + ); + SetIndexBuffer(middleBufferIndex, middleBuffer); + SetIndexLabel(middleBufferIndex, midLbl); + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculations ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculations ... +void CalculateBuffers( + const int &bar_index +) { + // + // Retrieve Bar Time ... + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + if (startTime == 0) { + // + startTime = barTime; + SetIndicatorBuffersNone(bar_index); + return; + } + + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + startTime + ); + + // + int startDistance = startBarIndex - bar_index; + if (startDistance < marketLength) { + // + SetIndicatorBuffersNone(bar_index); + return; + } + + // + // Highest High ... + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLength, + bar_index + ); + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + highestHighBuffer[bar_index] = hh; + + // + // Lowest Low ... + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLength, + bar_index + ); + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + lowestLowBuffer[bar_index] = ll; + + // + // Middle Buffer ... + double mid = (hh + ll) / 2; + middleBuffer[bar_index] = mid; + + // + // Reset Start Time ... + startTime = 0; +} + +// +void SetIndicatorBuffersNone( + const int bar_index +) { + // + int lastBarIndex = bar_index + 1; + + // + double lastHighestHigh; + double lastLowestLow; + + // + // Highest High ... + if (ArraySize(highestHighBuffer) > lastBarIndex) { + lastHighestHigh = highestHighBuffer[lastBarIndex]; + } else { + lastHighestHigh = 0; + } + + // + // Lowest Low ... + if (ArraySize(lowestLowBuffer) > lastBarIndex) { + lastLowestLow = lowestLowBuffer[lastBarIndex]; + } else { + lastLowestLow = 0; + } + + // + highestHighBuffer[bar_index] = lastHighestHigh; + lowestLowBuffer[bar_index] = lastLowestLow; + + // + double mid = (lastHighestHigh + lastLowestLow) / 2; + middleBuffer[bar_index] = mid; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Packed/XAUUSD-15M/MQL4/Indicators/x-saherelm.xtpow.mq4 b/Packed/XAUUSD-15M/MQL4/Indicators/x-saherelm.xtpow.mq4 new file mode 100644 index 0000000..46ff59e --- /dev/null +++ b/Packed/XAUUSD-15M/MQL4/Indicators/x-saherelm.xtpow.mq4 @@ -0,0 +1,275 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center Trend Power Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm MA Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 7; // Market Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_separate_window + +// +#property indicator_plots 3 +#property indicator_buffers 3 +#property indicator_minimum 0 +#property indicator_maximum 100 + +// +#property indicator_levelcolor clrGray +#property indicator_levelstyle STYLE_DOT + +// +// Start Define Indicator Buffer Styles ... +// +#property indicator_type1 DRAW_HISTOGRAM +#property indicator_color1 clrLime +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +#property indicator_type2 DRAW_HISTOGRAM +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define powerUpBufferIndex 0 +#define powerDownBufferIndex 1 +#define signalBufferIndex 2 + +double powerUpBuffer[]; +double powerDownBuffer[]; +double signalBuffer[]; + +// +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (marketLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + SetLevelValue(0, 0.0); + IndicatorSetString(INDICATOR_LEVELTEXT,0,""); + + // + SetLevelValue(1, 20.0); + IndicatorSetString(INDICATOR_LEVELTEXT,1,""); + + // + SetLevelValue(2, 50); + IndicatorSetString(INDICATOR_LEVELTEXT,2,""); + + // + SetLevelValue(3, 100); + IndicatorSetString(INDICATOR_LEVELTEXT,3,""); + + // + string pUpLbl = StringConcatenate( + "P Up (", marketLength, ")" + ); + SetIndexLabel(powerUpBufferIndex, pUpLbl); + SetIndexBuffer(powerUpBufferIndex, powerUpBuffer); + SetIndexDrawBegin(powerUpBufferIndex, marketLength + 1); + + // + string pDownLbl = StringConcatenate( + "P Down (", marketLength, ")" + ); + SetIndexLabel(powerDownBufferIndex, pDownLbl); + SetIndexBuffer(powerDownBufferIndex, powerDownBuffer); + SetIndexDrawBegin(powerDownBufferIndex, marketLength + 1); + + // + string pSignalLbl = StringConcatenate( + "P Signal (", marketLength, ")" + ); + SetIndexLabel(signalBufferIndex, pSignalLbl); + SetIndexBuffer(signalBufferIndex, signalBuffer); + SetIndexDrawBegin(signalBufferIndex, marketLength + 1); + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "X_TPW_OSC"; + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Buffers ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateBuffers( + const int &bar_index +) { + // + double powerUp = 0; + double powerDown = 0; + + // + int dailyCount = GetDailyCandleCount(); + double dailyHH = GetMarketHighestHigh( + bar_index, + dailyCount + ); + double dailyLL = GetMarketLowestLow( + bar_index, + dailyCount + ); + double dailyDiff = dailyHH - dailyLL; + double rate = dailyDiff / 100; + + // + for (int i = bar_index; i < bar_index + marketLength; i++) { + // + XOHCL c = GetCandleModel(i); + + // + double cRange = + MathAbs(c.open - c.close) + // MathAbs(c.high - c.low) + ; + bool isBullish = c.open < c.close; + + // + if (isBullish) { + powerUp += cRange; + } else { + powerDown += cRange; + } + } + + // + powerUp = powerUp / rate; + powerDown = powerDown / rate; + + // + int doubleMarketLength = (marketLength * 2); + double ema = GetMA( + bar_index, + doubleMarketLength, + 0, + MODE_EMA, + PRICE_WEIGHTED + ); + + // + double emaRate = GetMarketHighestHigh(bar_index, doubleMarketLength) - GetMarketLowestLow(bar_index, doubleMarketLength) / 100; + + // + double signal = (ema / 100) * rate; + double signalAddition = MathMin(powerUp, powerDown); + + // + powerUpBuffer[bar_index] = powerUp; + powerDownBuffer[bar_index] = powerDown; + signalBuffer[bar_index] = signal + signalAddition; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.draw.lib.mq4 b/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.draw.lib.mq4 new file mode 100644 index 0000000..776cde4 --- /dev/null +++ b/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.draw.lib.mq4 @@ -0,0 +1,2010 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Draw Highest High ... +bool DrawHighestHigh( + const int bar_index, + const int marketLen, + const string tag, + const int drawUntilBarIndex = 0, + const long chartID = 0, + const int subWindow = 0, + const color clr = clrAqua, + const ENUM_LINE_STYLE style = STYLE_DOT, + const int width = 1, + const bool back = false, + const bool selection = false, + const bool hidden = false, + const long zOrder = 0 +) { + // + bool result = false; + + // + // Calculate Highest High ... + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + datetime hhTime = iTime( + _Symbol, + _Period, + hhIdx + ); + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + datetime drawUntilTime = + drawUntilBarIndex != bar_index ? + iTime( + _Symbol, + _Period, + drawUntilBarIndex + ) : + barTime + ; + + // + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + int rnd = rand(); + + // + // Define Label ... + string lbl = StringConcatenate( + tag, + "_HH(", marketLen ,")_", + hh, + "_", rnd + ); + + // + result = ObjectDelete( + chartID, + lbl + ); + + // + // Draw a Trend Line ... + result = DrawTrendLine( + chartID, + lbl, + subWindow, + hhTime, + hh, + drawUntilTime, + hh, + clr, + style, + width, + back, + selection, + hidden, + zOrder + ); + + // + return result; +} + +// +// Draw Lowest Low ... +bool DrawLowestLow( + const int bar_index, + const int marketLen, + const string tag, + const int drawUntilBarIndex = 0, + const long chartID = 0, + const int subWindow = 0, + const color clr = clrFuchsia, + const ENUM_LINE_STYLE style = STYLE_DOT, + const int width = 1, + const bool back = false, + const bool selection = false, + const bool hidden = false, + const long zOrder = 0 +) { + // + bool result = false; + + // + // Calculate Highest High ... + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + datetime llTime = iTime( + _Symbol, + _Period, + llIdx + ); + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + datetime drawUntilTime = + drawUntilBarIndex != bar_index ? + iTime( + _Symbol, + _Period, + drawUntilBarIndex + ) : + barTime + ; + + // + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + int rnd = rand(); + + // + // Define Label ... + string lbl = StringConcatenate( + tag, + "_LL(", marketLen ,")_", + ll, + "_", rnd + ); + + // + result = ObjectDelete( + chartID, + lbl + ); + + // + // Draw a Trend Line ... + result = DrawTrendLine( + chartID, + lbl, + subWindow, + llTime, + ll, + drawUntilTime, + ll, + clr, + style, + width, + back, + selection, + hidden, + zOrder + ); + + // + return result; +} + +// +// Draw Market Middle ... +bool DrawMarketMiddle( + const int bar_index, + const int marketLen, + const string tag, + const int drawUntilBarIndex = 0, + const long chartID = 0, + const int subWindow = 0, + const color clr = clrYellow, + const ENUM_LINE_STYLE style = STYLE_DOT, + const int width = 1, + const bool back = false, + const bool selection = false, + const bool hidden = false, + const long zOrder = 0 +) { + // + bool result = false; + + // + // Calculate Highest High ... + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + datetime llTime = iTime( + _Symbol, + _Period, + llIdx + ); + + // + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + // Calculate Highest High ... + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + datetime hhTime = iTime( + _Symbol, + _Period, + hhIdx + ); + + // + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + double middle = ll + ((hh - ll) / 2); + datetime middleTime = hhIdx < llIdx + ? hhTime + : llTime + ; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + datetime drawUntilTime = + drawUntilBarIndex != bar_index ? + iTime( + _Symbol, + _Period, + drawUntilBarIndex + ) : + barTime + ; + + // + int rnd = rand(); + + // + // Define Label ... + string lbl = StringConcatenate( + tag, + "_MID(", marketLen ,")_", + middle, + "_", rnd + ); + + // + result = ObjectDelete( + chartID, + lbl + ); + + // + // Draw a Trend Line ... + result = DrawTrendLine( + chartID, + lbl, + subWindow, + middleTime, + middle, + drawUntilTime, + middle, + clr, + style, + width, + back, + selection, + hidden, + zOrder + ); + + // + return result; +} + +// +// Start Arrow Functions ... +// +// +// Draw an Arrow Object on Chart ... +bool DrawArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // arrow name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const uchar arrowCode = OBJ_ARROW_UP, // arrow code + const ENUM_ARROW_ANCHOR anchor = ANCHOR_BOTTOM, // anchor point position + const color clr = clrAqua, // arrow color + const ENUM_LINE_STYLE style = STYLE_SOLID, // border line style + const int width = 3, // arrow size + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // Order Object ... +) { + // + // set anchor point coordinates if they are not set ... + ChangeArrowEmptyPoint(time, price); + + // + // reset the error value ... + ResetLastError(); + + // + // create an arrow ... + if(!ObjectCreate(chartID, name, OBJ_ARROW, subWindow, time, price)) { + // + string message = StringConcatenate(__FUNCTION__, + ": failed to create an arrow! Error code = ", + GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the arrow code ... + ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, arrowCode); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set the arrow color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set the border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set the arrow's size ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the arrow by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is false by default, if you want making it possible to highlight and move the object + // change it to true ... + ObjectSetInteger(chartID,name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point of Arrow ... +bool MoveArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if(!time) { + time = TimeCurrent(); + } + + // + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete an arrow ... +bool DeleteArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow" // arrow name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete an arrow ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete an arrow! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the arrow code ... +bool ArrowCodeChange( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + const uchar code = 252 // arrow code +) { + // + // reset the error value ... + ResetLastError(); + + // + // change the arrow code ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, code)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the arrow code! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change anchor type ... +bool ArrowAnchorChange( + const long chartID = 0, // chart's ID + const string name="Arrow", // object name + const ENUM_ARROW_ANCHOR anchor = ANCHOR_TOP // anchor type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change anchor type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change anchor type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeArrowEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } +} +// +// End Arrow Functions ... +// + +// +// Start Horizontal Line Functions ... +// +// +// Create, Draw the horizontal line ... +bool DrawHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + const int subWindow = 0, // subwindow index + double price = 0, // line price + const color clr = clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the price is not set, set it at the current Bid price level ... + if(!price) { + price=SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // create a horizontal line ... + if(!ObjectCreate(chartID, name, OBJ_HLINE, subWindow, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move horizontal line ... +bool MoveHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + double price = 0 // line price +) { + // + // if the line price is not set, move it to the current Bid price level ... + if(!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move a horizontal line ... + if(!ObjectMove(chartID, name, 0, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete a horizontal line ... +bool DeleteHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a horizontal line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End Horizontal Line Functions ... +// + +// +// Start Vertical Line Functions ... +// +// +// Create the vertical line ... +bool DrawVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + const int sub_window = 0, // subwindow index + datetime time = 0, // line time + const color clr=clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the line time is not set, draw it via the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value + ResetLastError(); + + // + // create a vertical line ... + if (!ObjectCreate(chartID, name, OBJ_VLINE, sub_window, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return true; +} + +// +// Move the vertical line ... +bool MoveVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + datetime time = 0 // line time +) { + // + // if line time is not set, move the line to the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the vertical line ... + if(!ObjectMove(chartID, name, 0, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the vertical line ... +bool DeleteVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the vertical line ... + if (!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // successful execution ... + return true; +} +// +// End Vertical Line Functions ... +// + +// +// Start RectangleLabel Functions ... +// +// +// Create Rectangle Label Object ... +bool DrawRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int subWindow = 0, // subwindow index + const int x = 0, // X coordinate + const int y = 0, // Y coordinate + const int width = 50, // width + const int height = 18, // height + const color back_clr = C'236,233,216', // background color + const ENUM_BORDER_TYPE border = BORDER_SUNKEN, // border type + const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring + const color clr = clrRed, // flat border color (Flat) + const ENUM_LINE_STYLE style = STYLE_SOLID, // flat border style + const int lineWidth = 1, // flat border width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // reset the error value ... + ResetLastError(); + + // + //--- create a rectangle label + if(!ObjectCreate(chartID, name, OBJ_RECTANGLE_LABEL, subWindow, 0, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set label coordinates ... + ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x); + ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y); + + // + // set label size ... + ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width); + ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height); + + // + // set background color ... + ObjectSetInteger(chartID, name, OBJPROP_BGCOLOR, back_clr); + + // + // set border type ... + ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border); + + // + // set the chart's corner, relative to which point coordinates are defined ... + ObjectSetInteger(chartID, name, OBJPROP_CORNER, corner); + + // + // set flat border color (in Flat mode) ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set flat border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set flat border width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, lineWidth); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the label by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move Rectangle Label .. +bool MoveRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int x = 0, // X coordinate + const int y=0 // Y coordinate +) { + // + // reset the error value ... + ResetLastError(); + + // + // move the rectangle label ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move X coordinate of the label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move Y coordinate of the label! Error code = ",GetLastError() + ); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the rectangle label ... +bool DeleteRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel" // label name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the label ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change Rectangle Label Size ... +bool ChangeSizeRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int width = 50, // label width + const int height = 18 // label height +) { + // + // reset the error value ... + ResetLastError(); + + // + // change label size ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's width! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's height! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change rectangle label border type ... +bool RectLabelChangeBorderType( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const ENUM_BORDER_TYPE border = BORDER_SUNKEN // border type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change border type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the border type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End RectangleLabel Functions ... +// + +// +// Start TrendLine Funcions ... +// +// Create a trend line by the given coordinates ... +bool DrawTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrYellow, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool rayRight = false, // line's continuation to the right + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeTrendLineEmptyPoints( + time1, + price1, + time2, + price2 + ); + + // + // reset the error value ... + ResetLastError(); + + // + // create a trend line by the given coordinates ... + if(!ObjectCreate(chartID, name, OBJ_TREND, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the line's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move trend line anchor point ... | +bool ChangeTrendLinePoint( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int pointindex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move trend line's anchor point ... + if(!ObjectMove(chartID, name, pointindex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// The function deletes the trend line from the chart ... +bool DeleteTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a trend line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of trend line's anchor points and set default ... +// values for empty ones ... +void ChangeTrendLineEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the first point's time is not set, it will be on the current bar ... + if (!time1) { + time1 = TimeCurrent(); + } + + // + // if the first point's price is not set, it will have Bid value ... + if (!price1) { + price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // if the second point's time is not set, it is located 9 bars left from the second one ... + if (!time2) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(), Period(), time1, 10, temp); + + // + // set the second point 9 bars left from the first one ... + time2 = temp[0]; + } + + // + // if the second point's price is not set, it is equal to the first point's one ... + if (!price2) { + price2 = price1; + } +} +// +// End TrendLine Functions ... +// + +// +// Start Text Functions ... +// +// Create and Draw a Text Object ... +bool DrawText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const string text = "Text", // the text itself + const string font = "Arial", // font + const int fontSize = 10, // font size + const color clr = clrRed, // color + const double angle = 0.0, // text slope + const ENUM_ANCHOR_POINT anchor = ANCHOR_CENTER, // anchor type + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor point coordinates if they are not set ... + ChangeTextEmptyPoint(time,price); + + // + // reset the error value ... + ResetLastError(); + + // + //--- create Text object + if(!ObjectCreate(chartID, name, OBJ_TEXT, subWindow, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the text ... + ObjectSetString(chartID, name , OBJPROP_TEXT, text); + + // + // set text font ... + ObjectSetString(chartID, name, OBJPROP_FONT, font); + + // + // set font size ... + ObjectSetInteger(chartID, name, OBJPROP_FONTSIZE, fontSize); + + // + // set the slope angle of the text ... + ObjectSetDouble(chartID, name, OBJPROP_ANGLE, angle); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the object by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID ,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point ... +bool MoveText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + //--- if point position is not set, move it to the current bar having Bid price + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point .. + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the object text ... +bool ChangeText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const string text = "Text" // text +) { + // + // reset the error value ... + ResetLastError(); + + // + // change object text ... + if(!ObjectSetString(chartID, name, OBJPROP_TEXT, text)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the text! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Text object ... +bool DeleteText( + const long chartID = 0, // chart's ID + const string name = "Text" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeTextEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + } +// +// End Text Functions ... +// + +// +// Start Fibonacchi Functions ... +// +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawFibonacci( + const long chartID = 0, // chart's ID + const string name="Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrRed, // object color + const ENUM_LINE_STYLE style = STYLE_SOLID, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawCustomFibonacci( + // + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + // + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrAqua, // object color + const ENUM_LINE_STYLE style = STYLE_DOT, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // Change Levels Of Fibonacci ... + bool result = FibonacciLevelsSet( + levels, + values, + colors, + styles, + widths, + descriptions, + chartID, + name + ); + + // + // successful execution ... + return result; +} + +// +// Set number of levels and their parameters ... +bool FibonacciLevelsSet( + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // check array sizes ... + if( + levels!=ArraySize(colors) || + levels!=ArraySize(styles) || + levels!=ArraySize(widths) || + levels!=ArraySize(widths) + ) { + // + string message = StringConcatenate( + __FUNCTION__, + ": array length does not correspond to the number of levels, error!" + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the number of levels ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELS, levels); + + // + // set the properties of levels in the loop ... + for(int i = 0; i < levels; i++) { + // + // level value ... + ObjectSetDouble(chartID, name, OBJPROP_LEVELVALUE, i, values[i]); + + // + // level color ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELCOLOR, i, colors[i]); + + // + // level style ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELSTYLE, i, styles[i]); + + // + // level width ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELWIDTH, i, widths[i]); + + // + // level description ... + // ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, DoubleToString(100 * values[i], 1)); + ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, descriptions[i]); + } + + // + // successful execution ... + return(true); +} + +// +// Move Fibonacci Retracement anchor point ... +bool FibonacciPointChange( + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int pointIndex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, pointIndex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Fibonacci Retracement ... +bool DeleteFibonachi( + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Fibonacci Retracement\"! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of Fibonacci Retracement anchor points and set +// default values for empty ones ... +void ChangeFibonacciEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the second point's time is not set, it will be on the current bar ... + if (!time2) { + time2 = TimeCurrent(); + } + + // + // if the second point's price is not set, it will have Bid value ... + if (!price2) { + price2 = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // if the first point's time is not set, it is located 9 bars left from the second one ... + if (!time1) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(),Period(),time2,10,temp); + + // + // set the first point 9 bars left from the second one ... + time1 = temp[0]; + } + + // + // if the first point's price is not set, move it 200 points below the second one ... + if (!price1) { + price1 = price2 - 200 * SymbolInfoDouble(_Symbol, SYMBOL_POINT); + } +} +// +// End Fibonacci Functions ... +// + + +// +// Start General Functions ... +// +// +// Remove all Drawn Objects ... +void RemoveDraws(const string &tag) { + // + for(int iObj=ObjectsTotal()-1; iObj >= 0; iObj--) { + // + string on = ObjectName(iObj); + if (StringFind(on, tag) == 0) { + ObjectDelete(on); + } + } +} +// +// End General Functions ... +// \ No newline at end of file diff --git a/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.indicator.lib.mq4 b/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.indicator.lib.mq4 new file mode 100644 index 0000000..0e4b162 --- /dev/null +++ b/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.indicator.lib.mq4 @@ -0,0 +1,450 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Indicator Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// Reading specified Buffer From ADX Indicator ... +double ReadXMABuffer( + const int bar_index, + const int buffer_index, + // + const int marketLen, + // + const double stp, + const double mxm, + // + const int shortCycleMult, + const int mediumCycleMult, + const int longCycleMult +) { + // + string xmaIndicatorName = "x-saherelm.x.xma"; + + // + double result = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // Inputs ... + marketLen, + stp, + mxm, + shortCycleMult, + mediumCycleMult, + longCycleMult, + MODE_SMA, + // + buffer_index, + bar_index + ); + + // + return result; +} + +// +// Reading specified Buffer from XHL Indicator ... +double ReadXHLBuffer( + const int bar_index, + const int buffer_index, + // + const int marketLen, + // + const int shortCycleMult, + const int mediumCycleMult, + const int longCycleMult +) { + // + string xhlIndicatorName = "x-saherelm.x.hl"; + + // + double result = iCustom( + _Symbol, + _Period, + xhlIndicatorName, + // + // Inputs ... + marketLen, + shortCycleMult, + mediumCycleMult, + longCycleMult, + MODE_SMA, + // + buffer_index, + bar_index + ); + + // + return result; +} + +// +// Reading ADX Values ... +double ReadADX( + const int bar_index, + const int marketLen, + const int mult +) { + // + double result; + + // + int period = marketLen * mult; + + // + result = iADX( + _Symbol, + _Period, + period, + PRICE_CLOSE, + MODE_MAIN, + bar_index + ); + + // + return result; +} + +// +// Reading Pivot States ... +XPvtState GetPVTState( + const int bar_index, + const int marketLen +) { + // + XPvtState result = {}; + + // + double hh = GetMarketHighestHigh( + bar_index, + marketLen + ); + + // + double ho = GetMarketHighestOpen( + bar_index, + marketLen + ); + + // + double hc = GetMarketHighestClose( + bar_index, + marketLen + ); + + // + double hl = GetMarketHighestLow( + bar_index, + marketLen + ); + + // + double ll = GetMarketLowestLow( + bar_index, + marketLen + ); + + // + double lo = GetMarketLowestOpen( + bar_index, + marketLen + ); + + // + double lc = GetMarketLowestClose( + bar_index, + marketLen + ); + + // + double lh = GetMarketLowestHigh( + bar_index, + marketLen + ); + + // + // Filling Result ... + // + result.hh = hh; + result.ho = ho; + result.hc = hc; + result.hl = hl; + + // + result.ll = ll; + result.lo = lo; + result.lc = lc; + result.lh = lh; + + // + return result; +} + +// +// Calculate XRange from Market ... +static XRState lastXRState; +XRState GetXRange( + const int bar_index, + const int rangeMarketLength +) { + // + XRState result = {}; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + int marketBarIndex = bar_index + rangeMarketLength; + + // + // Highest High ... + // + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketBarIndex, + bar_index + ); + + // + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + // Lowest Low ... + // + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketBarIndex, + bar_index + ); + + // + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + if (lastXRState.start == 0) { + // + lastXRState.start = barTime; + lastXRState.length = rangeMarketLength; + + // + lastXRState.hh = hh; + lastXRState.ll = ll; + + // + // Middle ... + double mid = (hh + ll) / 2; + lastXRState.mid = mid; + } else { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + lastXRState.start + ); + + // + if (startBarIndex - bar_index >= rangeMarketLength) { + // + lastXRState.start = barTime; + lastXRState.length = rangeMarketLength; + + // + lastXRState.hh = hh; + lastXRState.ll = ll; + + // + // Middle ... + double mid = (hh + ll) / 2; + lastXRState.mid = mid; + } + } + + // + result = lastXRState; + + // + return result; +} + +// +// Reading XTPowState from Indicatoe ... +XTPOWState GetXTPowState( + const int bar_index, + const int marketLen +) { + // + XTPOWState result = {}; + + // + // + double powerUp = 0; + double powerDown = 0; + double signal = 0; + + // + string indicatorName = "x-saherelm.xtpow"; + + // + int pUpIndex = 0; + int pDownIndex = 1; + int signalIndex = 2; + + // + powerUp = iCustom( + _Symbol, + _Period, + indicatorName, + // + marketLen, + // + pUpIndex, + bar_index + ); + + // + powerDown = iCustom( + _Symbol, + _Period, + indicatorName, + // + marketLen, + // + pDownIndex, + bar_index + ); + + // + signal = iCustom( + _Symbol, + _Period, + indicatorName, + // + marketLen, + // + signalIndex, + bar_index + ); + + // + result.signal = signal; + result.powerUp = powerUp; + result.powerDown = powerDown; + + // + return result; +} + +// +// Reading XRState From Indicator ... +XRState ReadXRange( + const int bar_index, + const int marketLen +) { + // + XRState result = {}; + + // + // Define Buffer Indexes ... + int hhBufferIndex = 0; + int llBufferIndex = 1; + int midBufferIndex = 2; + + // + string indicatorName = "x-saherelm.xrange"; + + // + // Read Values From XRange Indicator ... + + // + double hh = iCustom( + _Symbol, + _Period, + indicatorName, + // + // Inputs ... + marketLen, + // + hhBufferIndex, // Buffer Index ... + bar_index + ); + + // + double ll = iCustom( + _Symbol, + _Period, + indicatorName, + // + // Inputs ... + marketLen, + // + llBufferIndex, // Buffer Index ... + bar_index + ); + + // + double mid = iCustom( + _Symbol, + _Period, + indicatorName, + // + // Inputs ... + marketLen, + // + midBufferIndex, // Buffer Index ... + bar_index + ); + + // + // Filling Result ... + result.hh = hh; + result.ll = ll; + result.mid = mid; + + // + return result; +} +// +// END Indicator Reading Data ... +// diff --git a/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.lib.mq4 b/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.lib.mq4 new file mode 100644 index 0000000..cc0e23e --- /dev/null +++ b/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.lib.mq4 @@ -0,0 +1,1662 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +static datetime lastBarTime; + +// +struct XOHCL { + double high; + double open; + double close; + double low; +}; + +// +struct XRange { + // + datetime time; + + // + double highestHigh; + double lowestLow; + + // + int levels; + int marketLength; + + // + double rate; +}; + +// +struct XPrice { + // + double askPrice; + double bidPrice; + double priceGap; + + // + double longEntry; + double longExit; + + // + double shortEntry; + double shortExit; +}; + +// +// START Functions ... +// + +// +// Determines current working is New Bar or not ... +bool IsNewBar() { + // + // Reading Last Bar Date ... + datetime curbar = (datetime)SeriesInfoInteger( + _Symbol, + _Period, + SERIES_LASTBAR_DATE + ); + + // + if(lastBarTime != curbar) { + // + lastBarTime = curbar; + return true; + } + + // + return false; +} + +// +// Determines we are in new Day or not ... +bool IsNewDay() { + // + bool result = false; + + // + // Reading Last Bar Date ... + datetime curbar = (datetime)SeriesInfoInteger( + _Symbol, + _Period, + SERIES_LASTBAR_DATE + ); + + // + if (lastBarTime == 0) { + lastBarTime = curbar; + } + + // + if (curbar == lastBarTime) { + return result; + } + + // + // Retrieve Day and Month and Year for Last Bar Time ... + int lastBarDay = TimeDay(lastBarTime); + int lastBarMonth = TimeMonth(lastBarTime); + int lastBarYear = TimeYear(lastBarTime); + + // + // Retrieve Day and Month and Year for Current Bar Time ... + int curBarDay = TimeDay(curbar); + int curBarMonth = TimeMonth(curbar); + int curBarYear = TimeYear(curbar); + + // + result = curBarDay > lastBarDay + || curBarMonth > lastBarMonth + || curBarYear > lastBarYear; + + // + return result; +} + +// +// Retrieve Number of Candles in a Day ... +int GetDailyCandleCount() { + // + int seconds = PeriodSeconds(_Period); + + // + int daySeconds = 24 * 60 * 60; + + // + int result = daySeconds / seconds; + + // + return result; +} + +// +// XRange Detector ... +XRange GetMarketRange( + const int bar_index, + const int marketLen, + const int levels +) { + // + XRange result = {}; + + // + result.levels = levels; + result.marketLength = marketLen; + + // + datetime time = iTime( + _Symbol, + _Period, + bar_index + ); + result.time = time; + + // + double highestHigh = GetMarketHighestHigh( + bar_index, + marketLen + ); + result.highestHigh = highestHigh; + + // + double lowestLow = GetMarketLowestLow( + bar_index, + marketLen + ); + result.lowestLow = lowestLow; + + // + double diff = highestHigh - lowestLow; + double rate = diff / levels; + + // + result.rate = rate; + + // + return result; +} + +// +// Retrieve RMA on Specific Candle ... +double GetRMA( + int bar_index, + int length +) { + // + double shortSMA = iMA(_Symbol, _Period, length, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double mediumSMA = iMA(_Symbol, _Period, length * 2, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double longSMA = iMA(_Symbol, _Period, length * 3, 0, MODE_SMA, PRICE_CLOSE, bar_index); + + // + double result = longSMA - mediumSMA + shortSMA; + + // + return result; +} + +// +// Retrieve Moving Average ... +double GetMA( + const int bar_index, + const int maLength, + const int maShift, + const ENUM_MA_METHOD maMethod, + const ENUM_APPLIED_PRICE appliedPrice +) { + // + double result = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + appliedPrice, + bar_index + ); + + // + return result; +} + +// +// Calculate Fib Level ... +double GetFibonacciLevel( + double upPrice, + double downPrice, + double level, + int direction +) { + // + double ling = upPrice - downPrice; + double pLevel = (ling / 100) * (level * 100); + + // + double result = direction > 0 ? + upPrice - pLevel : + downPrice + pLevel; + result = NormalizeDouble(result, _Digits); + + // + return result; +} + +// +// Retrieve True Range ... +double GetTR( + const int bar_index +) { + // + double result = 0; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double prevClose = iClose( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double highLowDif = high - low; + double hpCDif = MathAbs(high - prevClose); + double lpCDiff = MathAbs(low - prevClose); + + // + result = MathMax(highLowDif, hpCDif); + result = MathMax(result, lpCDiff); + + // + return result; +} + +// +// Calculate True Range Simple Moving Average ... +double GetMarketTRSMA( + const int bar_index, + const int marketLen +) { + // + double result = 0; + + // + // Create Barket Length Trs ... + double trs[]; + ArrayResize( + trs, + marketLen + ); + int index = 0; + double trSum = 0; + for (int i = bar_index; i < bar_index + marketLen; i++) { + // + double tr = GetTR(i); + trs[index] = tr; + + // + trSum += tr; + + // + index++; + } + + // + result = trSum / marketLen; + + // + return result; +} + +// +// Retrieve Commodity Channel ... +double GetMarketCCI( + const int bar_index, + const int marketLen, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE +) { + // + double result = 0; + + // + result = iCCI( + _Symbol, + _Period, + marketLen, + appliedPrice, + bar_index + ); + + // + return result; +} + +// +// this function check crossing up two Buffers ... +bool IsCrossedOver( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] > arr2[index1]) && !(arr1[index2] > arr2[index2]); + + // + return result; +} + +// +// this function check crossing down two Buffers ... +bool IsCrossedUnder( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] < arr2[index1]) && !(arr1[index2] < arr2[index2]); + + // + return result; +} + +// +// Convert points to Actual Point ... +double PointsToDouble(int points) { + // + double result = points * _Point; + return result; +} + +// +// Converts Pips to Points ... +int PipsToPoints(int pips) { + // + int result = pips * ((_Digits == 3 || _Digits == 5) ? 10 : 1); + return result; +} + +// +// Converts Pips to Double ... +double PipsToDouble(int pips) { + // + double result = PointsToDouble(PipsToPoints(pips)); + return result; +} + +// +// Converts Double Value to Pips ... +int PriceToPips(double value) { + // + if (value <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + int result = (int)(value / pipValue); + + // + return result; +} + +// +// Converts Pips to Double ... +double PipsToPrice(int pips) { + // + if (pips <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + double result = pipValue * pips; + + // + return result; +} + +// +// Generate ATR StopLoss Value ... +double CalculateATRSL( + int period, + double multiplier +) { + // + if (period <= 0 || multiplier <= 0) { + return 0; + } + + // + double atrValue = iATR( + _Symbol, + _Period, + period, + 0 + ); + + // + double result = atrValue * multiplier; + + // + return result; +} + +// +// Detect Candle Type ... +// Bullish => means close > open ... +bool IsBullishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBullishCandle( + open, + close + ); + + // + return result; +} + +bool IsBullishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open < close; + + // + return result; +} + +// +// Detect Candle Type ... +// Bearish => means close < open ... +bool IsBearishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBearishCandle( + open, + close + ); + + // + return result; +} + +bool IsBearishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open > close; + + // + return result; +} + +// +// Retrieve a Candle Info ... +XOHCL GetCandleModel( + const int bar_index +) { + // + XOHCL result = {}; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + result.high = high; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + result.open = open; + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + result.close = close; + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + result.low = low; + + // + return result; +} + +// +// Retrieve Market Current Prices for Signals ... +XPrice GetPrice() { + // + XPrice result = {}; + + // + RefreshRates(); + + // + double askPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double bidPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(bidPrice - askPrice); + + // + result.askPrice = askPrice; + result.bidPrice = bidPrice; + result.priceGap = priceGap; + + // + result.longEntry = askPrice; + result.longExit = bidPrice; + + // + result.shortEntry = bidPrice; + result.shortExit = askPrice; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBullishDetected( + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double shpDetectMultipliers // Sharp Detect Multiplier +) { + // + bool result = false; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double minValue = 0; + double maxValue = 0; + int positionedLength = bar_index + marketLen; + + // + for (int i = bar_index; i < positionedLength; i++) { + // + double cHigh = iHigh( + _Symbol, + _Period, + i + ); + + // + double cLow = iLow( + _Symbol, + _Period, + i + ); + + // + minValue += MathMin(cLow, cHigh); + maxValue += MathMax(cLow, cHigh); + } + + // + double minAvg = minValue / positionedLength; + double maxAvg = maxValue / positionedLength; + + // + double shpValue = shpDetectMultipliers * _Point; + + // + result = (low - minAvg) > shpValue; + + // + int index = bar_index; + while ( + index < positionedLength + || !result + ) { + // + low = iLow( + _Symbol, + _Period, + index + ); + + // + result = result + || (low - minAvg) > shpValue; + + // + index++; + }; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBearishDetected( + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double shpDetectMultipliers // Sharp Detect Multiplier +) { + // + bool result = false; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double minValue = 0; + double maxValue = 0; + int positionedLength = bar_index + marketLen; + + // + for (int i = bar_index; i < positionedLength; i++) { + // + double cHigh = iHigh( + _Symbol, + _Period, + i + ); + + // + double cLow = iLow( + _Symbol, + _Period, + i + ); + + // + minValue += MathMin(cLow, cHigh); + maxValue += MathMax(cLow, cHigh); + } + + // + double minAvg = minValue / positionedLength; + double maxAvg = maxValue / positionedLength; + + // + double shpValue = shpDetectMultipliers * _Point; + + // + result = (high - maxAvg) > shpValue; + + // + int index = bar_index; + while ( + index < positionedLength + || !result + ) { + // + high = iHigh( + _Symbol, + _Period, + index + ); + + // + result = result + || (high - maxAvg) > shpValue; + + // + index++; + }; + + // + return result; +} + +// +// Retrieve Highest High Value based on Given Market ... +double GetMarketHighestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Low Value based on Given Market ... +double GetMarketHighestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Open Value based on Given Market ... +double GetMarketHighestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Close Value based on Given Market ... +double GetMarketHighestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Low Value based on Given Market ... +double GetMarketLowestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest High Value based on Given Market ... +double GetMarketLowestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Open Value based on Given Market ... +double GetMarketLowestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Close Value based on Given Market ... +double GetMarketLowestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// less than given price ... +double GetLowLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// great than given price ... +double GetLowGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// less than given price ... +double GetHighLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// great than given price ... +double GetHighGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// less than given price ... +double GetCloseLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// great than given price ... +double GetCloseGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Get Slope of a Line by it's two Point ... +double GetSlope( + double x1, + double y1, + double x2, + double y2 +) { + // + double result = (y2 - y1)/MathAbs(x2 - x1); + return result; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.log.lib.mq4 b/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.log.lib.mq4 new file mode 100644 index 0000000..066b3f7 --- /dev/null +++ b/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.log.lib.mq4 @@ -0,0 +1,91 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Log Tag ... +static string logTag = ""; + +// +// Enable or Disable Logging ... +static bool enableLogging = false; + +// +// Start Log Messages ... +// + +// +// Logging a Message, specified for this EA ... +// using provided LogTag ... +void LogMessage(string message) { + // + if (!enableLogging) { + return; + } + + // + Print(logTag, " > ", message); +} + +// +// this used for logging series ... +void LogSeries( + double &series[], // which series to Log ... + int length = 0, // number of items to Log, 0 means all ... + int skip = 0 // number of items which skip before logging ... +) { + // + string msg = ""; + + // + int seriesSize = ArraySize(series); + if ( + skip < 0 + || length < 0 + || seriesSize == 0 + || skip > seriesSize + || skip + length > seriesSize + ) { + return; + } + + // + length = length == 0 ? + seriesSize : + length; + int start = skip > 1 ? + skip - 1 : + skip == 1 ? + 1 : + 0; + + // + // Loop through series items ... + for (int i = start; i < start + length; i++) { + // + msg += StringConcatenate( + "i[", i, "]: ", series[i], ", " + ); + } + + // + LogMessage(msg); +} +// +// End Log Messages ... +// + diff --git a/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.models.lib.mq4 b/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.models.lib.mq4 new file mode 100644 index 0000000..fa9903f --- /dev/null +++ b/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.models.lib.mq4 @@ -0,0 +1,154 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Models Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// START STATIC Variables ... +// +// +static int totalSignals = 0; +static int totalLongSignals = 0; +static int totalShortSignals = 0; + +// +static double initialBalance = 0; + +// +static int countedBars = 0; +static bool isNewBar = false; +static bool isNewDay = false; +// +// END STATIC Variables ... +// + +// +// Start Models ... +// +// +// Signal Providers ... +enum ENUM_X_SIGNAL_PROVIDER { + X_UNKNOWN_PROVIDER, + X_XXX_PROVIDER, + X_XR_PROVIDER, + X_XTPW_PROVIDER +}; + +// +// these are different signal types ... +enum ENUM_X_SIGNAL_TYPE { + X_SIGNAL_NONE, + X_SIGNAL_LONG, + X_SIGNAL_SHORT, +}; + +// +// Model Market Highs and Lows ... +struct XPvtState { + // + double hh; + double ho; + double hc; + double hl; + + // + double ll; + double lo; + double lc; + double lh; +}; + +// +// we Model each signals as this type ... +struct XSignal { + // + // Signal Symbol ... + string symbol; + + // + // Signal Type ... + ENUM_X_SIGNAL_TYPE type; + + // + // Signal ID ... + int id; + + // + // Signal Ticket Number, when Opening Trade ... + int ticket; + + // + // Signal Provider ... + ENUM_X_SIGNAL_PROVIDER provider; + + // + // Target Point ... + double tp; + + // + // Stop Loss ... + double sl; + + // + // Signal Entry Price ... + double entry; + + // + // Signalling Time ... + datetime time; + + // + // Signal Comments ... + string comment; + + // + // Signal TAG ... + string tag; +}; + +// +// this is Signal Request Response model ... +struct XSignalRequest { + bool hasSignal; + XSignal signal; + ENUM_X_SIGNAL_TYPE type; + ENUM_X_SIGNAL_PROVIDER provider; +}; + +// +struct XRState { + // + datetime start; + int length; + + // + double hh; + double ll; + double mid; +}; + +// +struct XTPOWState { + // + double powerUp; + double powerDown; + + // + double signal; +}; +// +// End Models ... +// diff --git a/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.signal.lib.mq4 b/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.signal.lib.mq4 new file mode 100644 index 0000000..097ce74 --- /dev/null +++ b/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.signal.lib.mq4 @@ -0,0 +1,1756 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Signal Draw Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +#include "../Libraries/x-saherelm.x.signal.lib.mq4" +#include "../Libraries/x-saherelm.xr.signal.lib.mq4" +#include "../Libraries/x-saherelm.xtpw.signal.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// END Global Requirement Functions ... +// + +// +// START Signal Related Functions ... +// +// +// Retrieve Signal Bar Index ... +int GetSignalBarIndex(XSignal &signal) { + // + // Temp Result ... + int result = -1; + + // + // Retriev Signal Bar Index ... + result = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + return result; +} + +// +string GetSignalProviderIdentifier( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + string result = ""; + + // + switch (provider) { + // + case X_XXX_PROVIDER: + result = "XXX"; + break; + + // + case X_XR_PROVIDER: + result = "XR"; + break; + + // + case X_XTPW_PROVIDER: + result = "XTPW"; + break; + + // + default: + result = ""; + break; + } + + // + return result; +} + +// +ENUM_X_SIGNAL_PROVIDER GetSignalProvider(string identifier) { + // + ENUM_X_SIGNAL_PROVIDER result = X_UNKNOWN_PROVIDER; + + // + if ( + StringFind( + identifier, + GetSignalProviderIdentifier(X_XXX_PROVIDER) + ) > -1 + ) { + result = X_XXX_PROVIDER; + } else if ( + StringFind( + identifier, + GetSignalProviderIdentifier(X_XR_PROVIDER) + ) > -1 + ) { + result = X_XR_PROVIDER; + } else if ( + StringFind( + identifier, + GetSignalProviderIdentifier(X_XTPW_PROVIDER) + ) > -1 + ) { + result = X_XTPW_PROVIDER; + } + + // + return result; +} + +// +// Retrieve Signal Lots Per Trade ... +double GetSignalLottage( + const XSignal &signal, + const double defLotsPerTrade +) { + // + double result = defLotsPerTrade; + + // + bool isLong = signal.type == X_SIGNAL_LONG; + + // + switch (signal.provider) { + // + case X_XR_PROVIDER: + // + result = isLong ? + xRLongLotsPerTradePercent : + xRShortLotsPerTradePercent + ; + break; + + // + case X_XXX_PROVIDER: + // + result = isLong ? + xLongLotsPerTradePercent : + xShortLotsPerTradePercent + ; + break; + + // + case X_XTPW_PROVIDER: + // + result = isLong ? + xTPWLongLotsPerTradePercent : + xTPWShortLotsPerTradePercent + ; + break; + } + + // + return result; +} + +// +// Draw Specific Range On Chart ... +void DrawRange( + const XRange &range, + const long chartID = 0, + const int subWindowID = 0, + const string tag = "", + const color clr = clrYellow +) { + // + // Loop through Levels Count ... + for (int i = 0; i <= range.levels; i++) { + // + datetime time1 = iTime( + _Symbol, + _Period, + 1 + ); + + // + datetime time2 = iTime( + _Symbol, + _Period, + 0 + ); + + // + double price = range.lowestLow + (i * range.rate); + + // + string lbl = StringConcatenate( + tag, + "_XRL_", + price + ); + + // + DrawTrendLine( + chartID, + lbl, + subWindowID, + time1, + price, + time2, + price, + clr, + STYLE_DOT + ); + } +} + +// +// Draw Signal Shapes on Chart ... +bool DrawSignal( + const XSignal &signal, + long chartID = 0, + int subWindowID = 0, + const double positionThresholdFactor = 10, + string longSignalLabel = "X-Long", + color longSignalColor = clrAqua, + string shortSignalLabel = "X-Short", + color shortSignalColor = clrFuchsia +) { + // + // Generate isLongSignal Var ... + bool isLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Signal Bar Index ... + int bar_index = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // START Draw Signal Arrow ... + // + // + // Arrow Shape Name ... + string arrowName = StringConcatenate(signal.tag, "_Arrow_", signal.id); + + // + // Arrow Price ... + double arrowPrice = 0; + if (isLongSignal) { + // + arrowPrice = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice - (positionThresholdFactor * _Point); + } else { + // + arrowPrice = iHigh( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice + (positionThresholdFactor * _Point); + } + + // + // Arrow Code ... + uchar arrowCode = isLongSignal ? SYMBOL_ARROWUP : SYMBOL_ARROWDOWN; + + // + // Arrow Anchor Point ... + ENUM_ARROW_ANCHOR arrowAnchorPoint = isLongSignal ? ANCHOR_BOTTOM : ANCHOR_TOP; + + // + // Arrow Color ... + color arrowColor = isLongSignal ? longSignalColor : shortSignalColor; + + // + // Draw Signal Arrow Shape ... + bool result = DrawArrow( + chartID, + arrowName, + subWindowID, + signal.time, + arrowPrice, + arrowCode, + arrowAnchorPoint, + arrowColor + ); + // + // END Draw Signal Arrow ... + // + + // + // START Draw Signal SL/TP ... + // + string slLineName = StringConcatenate(signal.tag, "_SL_", signal.id); + string tpLineName = StringConcatenate(signal.tag, "_TP_", signal.id); + string entryLineName = StringConcatenate(signal.tag, "_ENTRY_", signal.id); + + // + color slColor = shortSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color tpColor = longSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color entryColor = clrGreen; + + // + datetime time1 = iTime( + _Symbol, + _Period, + bar_index + 1 + ); + + // + // Draw Enrty Price ... + result = DrawTrendLine( + chartID, + entryLineName, + subWindowID, + time1, + signal.entry, + signal.time, + signal.entry, + entryColor, + STYLE_SOLID, + 2 + ); + + // + // Draw Signal SL ... + if (signal.sl > 0) { + // + result = DrawTrendLine( + chartID, + slLineName, + subWindowID, + time1, + signal.sl, + signal.time, + signal.sl, + slColor, + STYLE_SOLID, + 2 + ); + } + + // + // Draw Signal TP ... + if (signal.tp > 0) { + // + result = DrawTrendLine( + chartID, + tpLineName, + subWindowID, + time1, + signal.tp, + signal.time, + signal.tp, + tpColor, + STYLE_SOLID, + 2 + ); + } + // + // END Draw Signal SL/TP ... + // + + // + // Start Draw Signal Label ... + // + // + string labelName = StringConcatenate(signal.tag, "_Label_", signal.id); + + // + double labelPrice = isLongSignal ? arrowPrice - (positionThresholdFactor * _Point) : arrowPrice + (positionThresholdFactor * _Point); + + // + string labelText = isLongSignal ? longSignalLabel : shortSignalLabel; + labelText = StringConcatenate( + labelText, + "_", + GetSignalProviderIdentifier(signal.provider) + ); + + // + result = DrawText( + chartID, + labelName, + subWindowID, + signal.time, + labelPrice, + labelText, + "Arial", + 8, + arrowColor, + 0, + ANCHOR_CENTER + ); + // + // End Draw Signal Label ... + // + + // + return result; +} + +// +// Trade on Specific Signal ... +bool TradeSignal( + XSignal &signal, + // + double volumePercent, + // + // Long ... + const string longSignalLabel, + const color longSignalColor, + // + // Short ... + const string shortSignalLabel, + const color shortSignalColor +) { + // + // Temp Result ... + bool result = false; + + // + if (initialBalance == 0) { + initialBalance = AccountInfoDouble(ACCOUNT_BALANCE); + } + + // + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + int openPositions = CountOpenTrades(); + double volume = (volumePercent * initialBalance); + + // + if ( + signal.type != X_SIGNAL_LONG && + signal.type != X_SIGNAL_SHORT + ) { + return result; + } + + // + bool hasLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Check TP and Entry Price ... + if ( + ( + hasLongSignal + && signal.entry > signal.tp + ) || + ( + !hasLongSignal + && signal.entry < signal.tp + ) + ) { + return result; + } + + // + // Order Operation ... + int operation = hasLongSignal ? + OP_BUY : + OP_SELL; + + // + // Detect Trade Color ... + color clr = hasLongSignal ? + longSignalColor : + shortSignalColor; + + // + // Generate Signal Comment ... + string label = hasLongSignal ? + longSignalLabel : + shortSignalLabel; + + // + // Generate Signal Comment ... + string comment = StringConcatenate( + signal.tag, + "_", signal.id, + "_", GetSignalProviderIdentifier(signal.provider), + "_", label + ); + + // + // Placing Order ... + int orderTicket = OrderSend( + _Symbol, + operation, + volume, + signal.entry, + 3, + signal.sl, + signal.tp, + comment, + signal.id, + 0, + clr + ); + + // + // Draw Signal Shape if Order Opened Successfully ... + if (orderTicket >= 0) { + // + signal.ticket = orderTicket; + + // + // Here i must to Draw Signal Shapes ... + bool isDrawn = DrawSignal( + signal, + 0, + 0, + 50, + longSignalLabel, // Long Signal Label ... + longSignalColor, + shortSignalLabel, // Short Signal Label ... + shortSignalColor + ); + + // + LogMessage( + StringConcatenate( + "Order [", orderTicket ,"]: Provided by: ", GetSignalProviderIdentifier(signal.provider) + ) + ); + + // + // TODO: here we have to check if there are another + // open positions which their entry price is bigger + // than current signal entry price, for long trades and + // their tp is high than current tp, ... + // close in profit trades or modify orders tp to current ... + // // + // if (CountOpenTrades() > 0) { + // // + // // Here we have to + // ModifyOpenTradesBasedOnCurrentTrade(signal); + // } + + // + result = true; + } + + // + return result; +} +// +// END Signal Related Functions ... +// + +// +// START Orders Functions ... +// +// +// Convert To XSignal Model ... +XSignal OrderToSignal() { + // + // Temp Result ... + XSignal result = {}; + result.type = X_SIGNAL_NONE; + + // + // Here we can get some usefull info based on selected order ... + double swap = OrderSwap(); + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + int magicNumber = OrderMagicNumber(); + double takeProfit = OrderTakeProfit(); + string comment = OrderComment(); + + // + ENUM_X_SIGNAL_PROVIDER provider = GetSignalProvider(comment); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // Conver Position to Signal ... + result.sl = stopLoss; + result.tp = takeProfit; + result.time = openTime; + result.symbol = _Symbol; + result.id = magicNumber; + result.comment = comment; + result.entry = openPrice; + result.provider = provider; + result.type = isLongOrder ? X_SIGNAL_LONG : X_SIGNAL_SHORT; + + // + return result; +} + +// +// START Count Orders ... +// +// +// Count Open Positions ... +int CountOpenTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if (OrderSymbol() == _Symbol) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Long Positions ... +int CountOpenLongTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_BUY + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Short Positions ... +int CountOpenShortTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_SELL + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} +// +// END Count Orders ... +// + +// +// START Close Orders ... +// +// +// Close All Open Trades ... +bool CloseAllTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + + // + return result; +} + +// +bool CloseAllProviderTrades( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal(); + + // + if (signal.provider == provider) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +bool CloseAllProviderLongTrades( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal(); + + // + if ( + signal.provider == provider + && signal.type == X_SIGNAL_LONG + ) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +bool CloseAllProviderShortTrades( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal(); + + // + if ( + signal.provider == provider + && signal.type == X_SIGNAL_SHORT + ) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Long Trades ... +bool CloseAllLongTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Long Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Short Trades ... +bool CloseAllShortTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (!isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Short Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In Profit Trades ... +bool CloseAllInProfitTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit > 0 + && profit > 50 * _Point + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InProfit Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In DrawDown Trades ... +bool CloseAllInDrawDownTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if (profit < 0) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close Biggest In DrawDown Trades ... +bool CloseBiggestDrawDownTrade() { + // + // Loop through all Positions ... + bool result = false; + double drawDown = 0; + + // + // Find Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) > drawDown + ) { + drawDown = profit; + } + } + } + } + + // + // Close Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) >= drawDown + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Max InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Long Time Trades ... +bool CloseAllLongTimeTrades( + const int passedCandles, + const ENUM_X_SIGNAL_PROVIDER provider = X_UNKNOWN_PROVIDER +) { + // + bool result = false; + + // + if (passedCandles <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + string comment = OrderComment(); + + // + ENUM_X_SIGNAL_PROVIDER orderProvider = GetSignalProvider(comment); + bool isProviderVerified = + provider == X_UNKNOWN_PROVIDER ? + true : + orderProvider != X_UNKNOWN_PROVIDER + && orderProvider == provider + ; + + // + if ( + profit < 0 + && isProviderVerified + && openBarIndex - currentBarIndex >= passedCandles + // || ( + // profit > 0.5 + // && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 3) + // ) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Long Time issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + // else if ( + // openTrades > 0 + // && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 2) + // ) { + // result = CloseAllInProfitTrades() + // && CloseBiggestDrawDownTrade(); + // } + } + } + } + + // + return result; +} + +// +// Close all trades which passed Maximum Drawdown ... +bool CloseAllMaximumDrawDownPassedTrades( + const double maxDrDownPercentPerPTrade, + const ENUM_X_SIGNAL_TYPE type = X_SIGNAL_NONE, + const ENUM_X_SIGNAL_PROVIDER provider = X_UNKNOWN_PROVIDER +) { + // + if ( + initialBalance <= 0 + || maxDrDownPercentPerPTrade <= 0 + ) { + return false; + } + + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double maxAllowedDrawDown = -1 * (initialBalance * maxDrDownPercentPerPTrade); + + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + string comment = OrderComment(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + bool isTypeVerified = + type == X_SIGNAL_NONE ? + true : + ( isLongOrder + && type == X_SIGNAL_LONG + ) || ( + !isLongOrder + && type == X_SIGNAL_SHORT + ) + ; + + // + ENUM_X_SIGNAL_PROVIDER orderProvider = GetSignalProvider(comment); + bool isProviderVerified = + provider == X_UNKNOWN_PROVIDER ? + true : + orderProvider != X_UNKNOWN_PROVIDER + && orderProvider == provider + ; + + // + if ( + profit < 0 + && isTypeVerified + && isProviderVerified + && MathAbs(profit) >= MathAbs(maxAllowedDrawDown) + ) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Maximum DarwDown issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Trades Which Opens before Specified Length ... +bool CloseAllTradesWhichOpenInPastMarketLength( + const int marketLen +) { + // + bool result = false; + + // + if (marketLen <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + + // + if (openBarIndex <= currentBarIndex + marketLen) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Market Reverse issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } else if (openTrades > 0) { + // + // Close all InProfit Trdes and Biggest InDrawDown Trades ... + // result = CloseAllInProfitTrades(); + // && CloseBiggestDrawDownTrade(); + } + } + } + } + + // + return result; +} +// +// END Close Orders ... +// + +// +// START Modify Orders ... +// +// +void ModifyAllPriceLesserOpenTrades( + const XSignal &signal +) { + // + // Loop through all Open Trades ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + double takeProfit = OrderTakeProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // When new Signal Comming with price less than + // currently open trade and tp less than currently + // open trade, this means a market change happens ... + // here we can Close InProfit Trades or Modify Trades TP ... + if ( + ( + openPrice < signal.entry + || MathAbs(openPrice - signal.entry) < 300 * _Point + ) + && takeProfit > signal.tp + ) { + bool result = OrderModify( + ticket, + openPrice, + signal.sl, + signal.tp, + clrYellow + ); + } + } + } + } +} + +// +void ModifyOpenTradesBasedOnCurrentTrade( + const XSignal &signal +) { + // + ModifyAllPriceLesserOpenTrades(signal); +} +// +// END Modify Orders ... +// +// +// END Orders Functions ... +// + +// +// START Signal Conditions ... +// +// +// Clear Signal Conditions ... +void ClearSignalConditions() { + // + ClearLongSignalConditions(); + ClearShortSignalConditions(); +} + +// +// Clear all Conditions Waiter for Long Signals ... +void ClearLongSignalConditions() { + // + ClearXLongSignalConditions(); + ClearXRLongSignalConditions(); + ClearXTPWLongSignalConditions(); +} + +// +// Clear all Conditions Waiter for Short Signals ... +void ClearShortSignalConditions() { + // + ClearXShortSignalConditions(); + ClearXRShortSignalConditions(); + ClearXTPWShortSignalConditions(); +} +// +// END Signal Conditions ... +// diff --git a/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.x.signal.lib.mq4 b/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.x.signal.lib.mq4 new file mode 100644 index 0000000..834ddb1 --- /dev/null +++ b/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.x.signal.lib.mq4 @@ -0,0 +1,1063 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 X Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Inputs ... +// +// +input string xStarter = "- X Signal Provider -"; // ---> X Signal Provider <--- + +// +input bool enableXSignalling = true; // X Signalling Enable + +// +input bool enableXLong = true; // X Signalling Enable Long +input bool enableXShort = true; // X Signalling Enable Short + +// +input double xShortR2R = 3; // X Short Risk To Reward Ratio +input double xShortLotsPerTradePercent = 0.0002; // X Lots Percent per Short Trades +input double xShortMaxDrawdownPerTradePercent = 0.4; // X Max Allowed DrawDown Percent per Short Trade + +// +input double xLongR2R = 3; // X Long Risk To Reward Ratio +input double xLongLotsPerTradePercent = 0.0002; // X Lots Percent per Short Trades +input double xLongMaxDrawdownPerTradePercent = 0.4; // X Max Allowed DrawDown Percent per Long Trade + +// +input double xSharpDetectorFactor = 700; // X Sharp Detection Factor + +// +input int xMaximumCandlesPerTrade = 206; // X Maximum Candles which a Trade can open + +// +input int xOscillatorLength = 7; // X Oscillator Length + +// +input double xPSarStep = 0.02; // X Parabolic Sar Step +input double xPSarMaximum = 0.2; // X Parabolic Sar Maximum + +// +input int xRangeMarketLength = 5; // X Range Detector Length + +// +input int xSwingLength = 7; // X Signal Swing Length +// +// END Inputs ... +// + +// +// START Global Requirement Functions ... +// +// +// X Based Signal Conditions ... +struct XSignalConditions { + datetime startTime; + datetime signalTime; + datetime entryTime; +}; + +// +struct XMarketState { + double psar; + double fast; + double slow; + double open; + double verifier; + double oscillator; + double oscillatorVerifier; +}; + +// +static XSignalConditions xLongConds; +static bool xCloseLongTrades = false; +static bool xWaitForLongSignals = true; + +// +static XSignalConditions xShortConds; +static bool xCloseShortTrades = false; +static bool xWaitForShortSignals = true; + +// +// Count Number of Closed Maximum DrawDown Trades ... +static int xFailedSignals = 0; + +// +datetime lastVerifierTouched; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckXSignalHandler( + const int bar_index +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + // + if ( + !enableXSignalling + || !(enableXLong || enableXShort) + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XOHCL candle = GetCandleModel(bar_index); + XOHCL pCandle = GetCandleModel(bar_index + 1); + XTPOWState tPowState = GetXTPowState( + bar_index + 1, + xSwingLength + ); + + // + XMarketState state = GetXMarketState( + bar_index + 1 + ); + + // + // Check Verifier Last Touched ... + bool isVerifierTouched = pCandle.high > state.verifier + && pCandle.low < state.verifier; + + // + // Disable Signals if a signal Failed ... + if (xFailedSignals) { + // + // TODO: Complete this ... + } + + // + // Enable Or Disable Signalling ... + if (isVerifierTouched) { + // + lastVerifierTouched = barTime; + + // + if (xWaitForLongSignals) { + xWaitForLongSignals = false; + } + + // + if (xWaitForShortSignals) { + xWaitForShortSignals = false; + } + } else { + // + int lastVerifierTouchedBarIndex = iBarShift( + _Symbol, + _Period, + lastVerifierTouched + ); + + // + int distance = MathAbs(lastVerifierTouchedBarIndex - bar_index); + + // + if ( + !xWaitForLongSignals + && distance > (xSwingLength * 2) + ) { + xWaitForLongSignals = true; + } + + // + if ( + !xWaitForShortSignals + && ( + distance > (xSwingLength * 2) + || ( + tPowState.powerDown > tPowState.powerUp + && tPowState.powerDown < 49 + ) + ) + ) { + xWaitForShortSignals = true; + } + } + + // + // Close All Long Open Trades ... + if ( + tPowState.powerDown > 55 + && tPowState.powerDown > tPowState.powerUp + ) { + // xCloseLongTrades = true; + } +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXLongSignalConditions( + const int bar_index +) { + // + if ( + !enableXLong + || !enableXSignalling + || !xWaitForLongSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + bool isCrossOver = false; + bool isCrossUnder = false; + + // + XMarketState cState = GetXMarketState(1); + XMarketState pState = GetXMarketState(2); + + // + isCrossUnder = + cState.fast < cState.slow + && !(pState.fast < pState.slow) + ; + + // + isCrossOver = + cState.fast > cState.slow + && !(pState.fast > pState.slow) + ; + + // + if ( + isCrossUnder + && xLongConds.startTime == 0 + ) { + // + xLongConds.startTime = barTime; + return; + } + + // + if ( + isCrossOver + && xLongConds.startTime > 0 + && xLongConds.signalTime == 0 + ) { + // + xLongConds.signalTime = barTime; + xLongConds.entryTime = barTime; + return; + } +} + +// +// Check and Fill Short Signal Conditions ... +void CheckXShortSignalConditions( + const int bar_index +) { + // + if ( + !enableXShort + || !enableXSignalling + || !xWaitForShortSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + bool isCrossOver = false; + bool isCrossUnder = false; + + // + XMarketState cState = GetXMarketState(1); + XMarketState pState = GetXMarketState(2); + + // + isCrossUnder = + cState.fast < cState.slow + && !(pState.fast < pState.slow) + ; + + // + isCrossOver = + cState.fast > cState.slow + && !(pState.fast > pState.slow) + ; + + // + if ( + isCrossOver + && xShortConds.startTime == 0 + ) { + // + xShortConds.startTime = barTime; + return; + } + + // + if ( + isCrossUnder + && xShortConds.startTime > 0 + && xShortConds.signalTime == 0 + ) { + // + xShortConds.signalTime = barTime; + xShortConds.entryTime = barTime; + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if ( + !enableXSignalling + || !(enableXLong || enableXShort) + ) { + return result; + } + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + if (requestLong) { + // + if ( + !ValidateXLongConditions() + ) { + return result; + } + } else { + // + if ( + !ValidateXShortConditions() + ) { + return result; + } + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double askPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double bidPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double entryPrice = requestLong ? + askPrice : + bidPrice; + + // + double exitPrice = requestLong ? + bidPrice : + askPrice; + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + // + GetMarketLowestLow( + bar_index, + xSwingLength + ) + ; + + // + double hh = + // + GetMarketHighestHigh( + bar_index, + xSwingLength + ) + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = requestLong ? + MathMin(openPrice, closePrice) - ll : + hh - MathMax(openPrice, closePrice) + ; + + // + double reward = + requestLong ? + risk * xLongR2R : + risk * xShortR2R + ; + + // + double sl = requestLong ? + 0 : + 0; + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward + ; + + // + XRState range = GetXRange( + bar_index, + xRangeMarketLength + ); + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XXX_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XXX_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXLongConditions() { + // + if ( + !enableXLong + || !enableXSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xLongConds.startTime > 0 + && xLongConds.signalTime > 0 + && xLongConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.signalTime + ); + + // + int entryBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.entryTime + ); + + // + isBLFilled = + // + xLongConds.signalTime > xLongConds.startTime + && xLongConds.entryTime >= xLongConds.signalTime + // && MathAbs(signalBarIndex - startBarIndex) >= 1 + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXLongSignalConditions(); + } + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXShortConditions() { + // + if ( + !enableXShort + || !enableXSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xShortConds.startTime > 0 + && xShortConds.signalTime > 0 + && xShortConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.signalTime + ); + + // + int entryBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.entryTime + ); + + // + isBLFilled = + // + xShortConds.signalTime > xShortConds.startTime + && xShortConds.entryTime >= xShortConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xWaitForShortSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXShortSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXLongSignalConditions() { + // + xLongConds.startTime = 0; + xLongConds.entryTime = 0; + xLongConds.signalTime = 0; +} + +// +// Clear Short Signal Conditions for New One ... +void ClearXShortSignalConditions() { + // + xShortConds.startTime = 0; + xShortConds.entryTime = 0; + xShortConds.signalTime = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForXSignals( + const XSignal &signal +) { + // + bool result = false; + + // + if ( + !enableXSignalling + || !(enableXLong || enableXShort) + ) { + return result; + } + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // XOHCL candle = GetCandleModel(0); + XOHCL candle = GetCandleModel(signalBarIndex); + XOHCL pCandle = GetCandleModel(signalBarIndex + 1); + + // + // Retrieve Range ... + XRState range = GetXRange( + signalBarIndex, + xRangeMarketLength + ); + + // + // Retrive XMarket States ... + XMarketState xState0 = GetXMarketState(signalBarIndex); + XMarketState xState1 = GetXMarketState(signalBarIndex + 1); + XMarketState xState2 = GetXMarketState(signalBarIndex + 2); + XMarketState xStateLast = GetXMarketState(signalBarIndex + xSwingLength); + + // + // Retrieve Trend Powers ... + XTPOWState xTPow0 = GetXTPowState( + signalBarIndex, + xSwingLength + ); + XTPOWState xTPow1 = GetXTPowState( + signalBarIndex + 1, + xSwingLength + ); + + // + double hh = GetMarketHighestHigh( + signalBarIndex, + xSwingLength + ); + double ll = GetMarketLowestLow( + signalBarIndex, + xSwingLength + ); + double diffChange = (hh - ll); + bool isBigSharpOccured = + diffChange > (xSharpDetectorFactor * _Point) + ; + + // + bool isPSarVerified = false; + bool isTPowVerified = false; + bool isStateVerified = false; + bool isPriceVerified = false; + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + // Get Price Verification for Long ... + isPriceVerified = + // + // Starter ... + true + // + && !isBigSharpOccured + // + && signal.entry < hh + // + // && signal.entry < range.hh + // && signal.entry > range.mid + // // + // && candle.high > xState0.verifier + // && signal.entry > xState0.verifier + // + // && pCandle.low != ll + && pCandle.high != hh + ; + + // + int above20TPowers = 0; + double signalSlope = 0; + int tPowUnverifyConditions = 0; + int tPowUnverifyConditionsIdx = 0; + for (int i = signalBarIndex; i < signalBarIndex + xSwingLength; i++) { + // + XTPOWState iTPowState = GetXTPowState( + i, + xSwingLength + ); + + // + // Calculate Signal Slope ... + if (i == signalBarIndex) { + // + signalSlope = iTPowState.signal; + } else if (i == signalBarIndex + 1) { + // + signalSlope = GetSlope( + 1, + iTPowState.signal, + 2, + signalSlope + ); + } + + // + if ( + iTPowState.powerUp > iTPowState.powerDown + && MathMax(iTPowState.powerUp, iTPowState.powerDown) > 20 + ) { + above20TPowers++; + } + + // + if (tPowUnverifyConditionsIdx < 3) { + // + if ( + iTPowState.powerUp < iTPowState.powerDown + || iTPowState.signal > MathMax(iTPowState.powerUp, iTPowState.powerDown) + ) { + tPowUnverifyConditions++; + } + + // + tPowUnverifyConditionsIdx++; + } + } + + // + isTPowVerified = + above20TPowers > 1 + && tPowUnverifyConditions == 0 + ; + + // + isPSarVerified = + xState0.psar < signal.entry + && xState0.psar < candle.low; + + // + isStateVerified = + // + // Start ... + true + // + // && xState0.open < xState0.slow + ; + + // + result = + // + // Starter ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + isPSarVerified = + xState0.psar > signal.entry + && xState0.psar > candle.high + ; + + // + // Get Price Verification for Short ... + isPriceVerified = + // + // Starter ... + true + // + && !isBigSharpOccured + // + && signal.entry > ll + && pCandle.low != ll + ; + + // + int above20TPowers = 0; + double signalSlope = 0; + int tPowUnverifyConditions = 0; + int tPowUnverifyConditionsIdx = 0; + for (int i = signalBarIndex; i < signalBarIndex + xSwingLength; i++) { + // + XTPOWState iTPowState = GetXTPowState( + i, + xSwingLength + ); + + // + // Calculate Signal Slope ... + if (i == signalBarIndex) { + // + signalSlope = iTPowState.signal; + } else if (i == signalBarIndex + 1) { + // + signalSlope = GetSlope( + 1, + iTPowState.signal, + 2, + signalSlope + ); + } + + // + if ( + iTPowState.powerUp > iTPowState.powerDown + && MathMax(iTPowState.powerUp, iTPowState.powerDown) > 20 + ) { + above20TPowers++; + } + + // + if (tPowUnverifyConditionsIdx < 3) { + // + if ( + iTPowState.powerUp > iTPowState.powerDown + || iTPowState.signal < MathMax(iTPowState.powerUp, iTPowState.powerDown) + ) { + tPowUnverifyConditions++; + } + + // + tPowUnverifyConditionsIdx++; + } + } + + // + isTPowVerified = + above20TPowers < 1 + && tPowUnverifyConditions == 0 + && MathAbs(xTPow0.powerUp - xTPow0.powerDown) > 50 * _Point + ; + + // + isStateVerified = + // + // Start ... + true + // + // && (xStateLast.verifier - xState0.verifier) >= 0 + // + && xState0.verifier > signal.entry + // + && MathAbs(signal.entry - xState0.verifier) < (xSharpDetectorFactor * _Point) + ; + + // + result = + // + // Starter Condition ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } + + // + return result; +} +// +// END Functions ... +// + +// +// START Data Provider ... +// +XMarketState GetXMarketState( + const int bar_index +) { + // + XMarketState result = {}; + + // + double fast = GetMA( + bar_index, + xSwingLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double open = GetMA( + bar_index, + xSwingLength, + 0, + MODE_SMA, + PRICE_OPEN + ); + + // + double slow = GetMA( + bar_index, + xSwingLength * 2, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double oscillator = GetMA( + bar_index, + xSwingLength, + 0, + MODE_EMA, + PRICE_CLOSE + ); + + // + double oscillatorVerifier = GetMA( + bar_index, + xSwingLength, + 0, + MODE_EMA, + PRICE_WEIGHTED + ); + + // + int dailyCount = GetDailyCandleCount(); + double verifier = GetMA( + bar_index, + dailyCount, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double psar = iSAR( + _Symbol, + _Period, + xPSarStep, + xPSarMaximum, + bar_index + ); + + // + result.psar = psar; + result.fast = fast; + result.open = open; + result.slow = slow; + result.verifier = verifier; + result.oscillator = oscillator; + result.oscillatorVerifier = oscillatorVerifier; + + // + return result; +} +// +// END Data Provider ... +// diff --git a/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.xr.signal.lib.mq4 b/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.xr.signal.lib.mq4 new file mode 100644 index 0000000..d4ae238 --- /dev/null +++ b/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.xr.signal.lib.mq4 @@ -0,0 +1,1142 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 X Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Inputs ... +// +// +input string xRStarter = "- XR Signal Provider -"; // --> XR Signal Provider <-- + +// +input bool enableXRSignalling = true; // XR Signalling Enable + +// +input bool enableXRLong = true; // XR Signalling Enable Long +input bool enableXRShort = true; // XR Signalling Enable Short + +// +input double xRShortR2R = 1.5; // XR Short Risk To Reward Ratio +input double xRShortLotsPerTradePercent = 0.0002; // XR Lots Percent per Short Trades +input double xRShortMaxDrawdownPerTradePercent = 0.15; // XR Max Allowed DrawDown Percent per Short Trade + +// +input double xRLongR2R = 1.5; // XR Long Risk To Reward Ratio +input double xRLongLotsPerTradePercent = 0.0002; // XR Lots Percent per Short Trades +input double xRLongMaxDrawdownPerTradePercent = 0.15; // XR Max Allowed DrawDown Percent per Long Trade + +// +input int xRMaximumCandlesPerTrade = 96; // XR Maximum Candles which a Trade can open + +// +input int xRSwingLength = 48; // XR Swing Length +// +// END Inputs ... +// + +// +input double xRSharpDetectionFactor = 1350; // XR Sharp Detection Factor + +// +// START Global Requirement Functions ... +// +// +// XR Market State ... +struct XRMarketState { + // + double fast; + double slow; + double open; + + // + double range; + double rangeFast; + double rangeSlow; + double rangeOpen; + + // + double verifier; +}; + +// +// XR Based Signal Conditions ... +struct XRSignalConditions { + datetime startTime; + datetime signalTime; + datetime entryTime; +}; + +// +static XRSignalConditions xRLongConds; +static bool xRCloseLongTrades = false; +static bool xRWaitForLongSignals = true; + +// +static XRSignalConditions xRShortConds; +static bool xRCloseShortTrades = false; +static bool xRWaitForShortSignals = true; + +// +// Count Number of Closed Maximum DrawDown Trades ... +static int xRFailedSignals = 0; + +// +double xRMaximumDrawDown = 0; + +// +int fastLength = 0; +int slowLength = 0; + +// +int verifierLength = 0; + +// +int rangeFastLength = 0; +int rangeSlowLength = 0; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckXRSignalHandler( + const int bar_index +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + + // + if ( + !enableXRSignalling + || !(enableXRLong || enableXRShort) + ) { + return; + } +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXRLongSignalConditions( + const int bar_index +) { + // + if ( + !enableXRLong + || !enableXRSignalling + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Read Prices ... + XPrice prices = GetPrice(); + + // + // Read XPVTState ... + XPvtState pvt0 = GetPVTState( + bar_index, + xRSwingLength + ); + + // + // Double Length Pivots ... + XPvtState dblPvt0 = GetPVTState( + bar_index, + (xRSwingLength * 2) + ); + + // + // Reading Required Candles ... + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + XOHCL candle3 = GetCandleModel(bar_index + 3); + + // + // Reding Required XRMarketStates ... + XRMarketState state0 = GetXRMarketState(bar_index); + XRMarketState state1 = GetXRMarketState(bar_index + 1); + XRMarketState state2 = GetXRMarketState(bar_index + 2); + XRMarketState state3 = GetXRMarketState(bar_index + 3); + + // + // Reading required XRangeStates ... + XRState range0 = ReadXRange( + bar_index + xRSwingLength, + xRSwingLength + ); + XRState range1 = ReadXRange( + bar_index + xRSwingLength + 1, + xRSwingLength + ); + XRState range2 = ReadXRange( + bar_index + xRSwingLength + 2, + xRSwingLength + ); + + // + XRState cRange0 = ReadXRange( + bar_index, + xRSwingLength + ); + + // + // Validate Farest Range Values ... + if ( + range2.hh == 0 + || + range2.ll == 0 + || + range2.mid == 0 + ) { + return; + } + + // + // Reading Required XTPowStates ... + XTPOWState tPow0 = GetXTPowState( + bar_index, + xRSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xRSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xRSwingLength + ); + + // + // if state verifier below range middle + // this means market is bullish ... + // + // if state verifier above range middle + // this means market is bearish ... + // + + // + bool isMarketBullish = + state0.verifier < range0.mid + && state1.verifier < range1.mid; + bool isMarketBearish = + state0.verifier > range0.mid + && state1.verifier > range1.mid; + bool isMarketGoingBullish = + state0.verifier > range0.mid + && !(state1.verifier > range1.mid); + bool isMarketGoingBearish = + state0.verifier < range0.mid + && !(state1.verifier < range1.mid); + + // + // Check Highest High Conditions ... + bool isHHVerified = + !( + pvt0.hh == dblPvt0.hh + ) + ; + + // + int sharpDetectionLength = 7; + double sharpDetectionValue = xRSharpDetectionFactor * _Point; + + // + int sharpHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + sharpDetectionLength, + bar_index + ); + double sharpHH = iHigh( + _Symbol, + _Period, + sharpHHIdx + ); + + // + int sharpLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + sharpDetectionLength, + bar_index + ); + double sharpLL = iLow( + _Symbol, + _Period, + sharpLLIdx + ); + + // + double sharpDiff = sharpHH - sharpLL; + bool isSharpOccered = + sharpDiff > sharpDetectionValue; + + // + XRMarketState lastState = GetXRMarketState( + bar_index + sharpDetectionLength + ); + + // + double stateFSDiff = (state0.fast - state0.slow) - (lastState.fast - lastState.slow); + + // + // Start Calculating Long Conditions ... + bool longCondition1 = + // + // Starter ... + true + // + && isMarketBullish + // + && + ( + candle2.high < range2.mid + || ( + candle2.high > range2.mid + && candle2.low < range2.mid + ) + ) + && candle1.low > range1.mid + ; + + // + if ( + // + ( + longCondition1 + ) + // + && xRLongConds.startTime == 0 + && xRLongConds.entryTime == 0 + && xRLongConds.signalTime == 0 + ) { + // + xRLongConds.startTime = barTime; + xRLongConds.entryTime = barTime; + xRLongConds.signalTime = barTime; + + // + return; + } +} + +// +// Check and Fill Short Signal Conditions ... +void CheckXRShortSignalConditions( + const int bar_index +) { + // + if ( + !enableXRShort + || !enableXRSignalling + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Read Prices ... + XPrice prices = GetPrice(); + + // + // Read XPVTState ... + XPvtState pvt0 = GetPVTState( + bar_index, + xRSwingLength + ); + + // + // Double Length Pivots ... + XPvtState dblPvt0 = GetPVTState( + bar_index, + (xRSwingLength * 2) + ); + + // + // Reading Required Candles ... + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + XOHCL candle3 = GetCandleModel(bar_index + 3); + + // + // Reding Required XRMarketStates ... + XRMarketState state0 = GetXRMarketState(bar_index); + XRMarketState state1 = GetXRMarketState(bar_index + 1); + XRMarketState state2 = GetXRMarketState(bar_index + 2); + XRMarketState state3 = GetXRMarketState(bar_index + 3); + + // + // Reading required XRangeStates ... + XRState range0 = ReadXRange( + bar_index + xRSwingLength, + xRSwingLength + ); + XRState range1 = ReadXRange( + bar_index + xRSwingLength + 1, + xRSwingLength + ); + XRState range2 = ReadXRange( + bar_index + xRSwingLength + 2, + xRSwingLength + ); + + // + XRState cRange0 = ReadXRange( + bar_index, + xRSwingLength + ); + + // + // Validate Farest Range Values ... + if ( + range2.hh == 0 + || + range2.ll == 0 + || + range2.mid == 0 + ) { + return; + } + + // + // Reading Required XTPowStates ... + XTPOWState tPow0 = GetXTPowState( + bar_index, + xRSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xRSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xRSwingLength + ); + + // + // if state verifier below range middle + // this means market is bullish ... + // + // if state verifier above range middle + // this means market is bearish ... + // + + // + bool isMarketBullish = + state0.verifier < range0.mid + && state1.verifier < range1.mid; + bool isMarketBearish = + state0.verifier > range0.mid + && state1.verifier > range1.mid; + bool isMarketGoingBullish = + state0.verifier > range0.mid + && !(state1.verifier > range1.mid); + bool isMarketGoingBearish = + state0.verifier < range0.mid + && !(state1.verifier < range1.mid); + + // + // Check Highest High Conditions ... + bool isHHVerified = + !( + pvt0.hh == dblPvt0.hh + ) + ; + + // + int sharpDetectionLength = 7; + double sharpDetectionValue = xRSharpDetectionFactor * _Point; + + // + int sharpHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + sharpDetectionLength, + bar_index + ); + double sharpHH = iHigh( + _Symbol, + _Period, + sharpHHIdx + ); + + // + int sharpLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + sharpDetectionLength, + bar_index + ); + double sharpLL = iLow( + _Symbol, + _Period, + sharpLLIdx + ); + + // + double sharpDiff = sharpHH - sharpLL; + bool isSharpOccered = + sharpDiff > sharpDetectionValue; + + // + XRMarketState lastState = GetXRMarketState( + bar_index + sharpDetectionLength + ); + + // + double stateFSDiff = (state0.fast - state0.slow) - (lastState.fast - lastState.slow); + + // + // Start Calculating Long Conditions ... + bool shortCondition1 = + // + // Starter ... + true + // + && isMarketBearish + // + && + ( + candle2.low > range2.mid + || ( + candle2.high > range2.mid + && candle2.low < range2.mid + ) + ) + && candle1.high < range1.mid + ; + + // + if ( + // + ( + shortCondition1 + ) + // + && xRShortConds.startTime == 0 + && xRShortConds.entryTime == 0 + && xRShortConds.signalTime == 0 + ) { + // + xRShortConds.startTime = barTime; + xRShortConds.entryTime = barTime; + xRShortConds.signalTime = barTime; + + // + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXRSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if ( + !enableXRSignalling + || !(enableXRLong || enableXRShort) + ) { + return result; + } + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + if (requestLong) { + // + if ( + !ValidateXRLongConditions() + ) { + return result; + } + } else { + // + if ( + !ValidateXRShortConditions() + ) { + return result; + } + } + + // + // Price Calculations ... + XPvtState pvts = GetPVTState( + bar_index, + xRSwingLength + ); + XPrice prices = GetPrice(); + + // + double entryPrice = requestLong ? + prices.longEntry : + prices.shortEntry + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = requestLong ? + MathMin(openPrice, closePrice) - pvts.ll : + pvts.hh - MathMax(openPrice, closePrice); + if (risk <= 0) { + // + risk = requestLong ? + MathAbs(pvts.hh - entryPrice) : + MathAbs(pvts.ll - entryPrice) + ; + } + + // + double reward = + requestLong ? + risk * xRLongR2R : + risk * xRShortR2R + ; + + // + double sl = requestLong ? + 0 : + 0; + + // + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward + ; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XR_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XR_PROVIDER; + + // + return result; +} + +// +// Validate Long Signal Conditions ... +bool ValidateXRLongConditions() { + // + if ( + !enableXRLong + || !enableXRSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xRLongConds.startTime > 0 + && xRLongConds.signalTime > 0 + && xRLongConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + isBLFilled = + // + xRLongConds.signalTime >= xRLongConds.startTime + && xRLongConds.entryTime >= xRLongConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xRWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXRLongSignalConditions(); + } + + // + return result; +} + +// +// Validate Short Signal Conditions ... +bool ValidateXRShortConditions() { + // + if ( + !enableXRShort + || !enableXRSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xRShortConds.startTime > 0 + && xRShortConds.signalTime > 0 + && xRShortConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + isBLFilled = + // + xRShortConds.signalTime >= xRShortConds.startTime + && xRShortConds.entryTime >= xRShortConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xRWaitForShortSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXRShortSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXRLongSignalConditions() { + // + xRLongConds.startTime = 0; + xRLongConds.signalTime = 0; + xRLongConds.entryTime = 0; +} + +// +// Clear Short Signal Conditions for New One ... +void ClearXRShortSignalConditions() { + // + xRShortConds.startTime = 0; + xRShortConds.signalTime = 0; + xRShortConds.entryTime = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForXRSignals( + const XSignal &signal +) { + // + bool result = false; + + // + if ( + !enableXRSignalling + || !(enableXRLong || enableXRShort) + ) { + return result; + } + + // + // Find Signal Bar Index ... + int signalBarIndex = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // Read Prices ... + XPrice prices = GetPrice(); + + // + // Read XPVTState ... + XPvtState pvt0 = GetPVTState( + signalBarIndex, + xRSwingLength + ); + + // + // Reading Required Candles ... + XOHCL candle0 = GetCandleModel(signalBarIndex); + XOHCL candle1 = GetCandleModel(signalBarIndex + 1); + XOHCL candle2 = GetCandleModel(signalBarIndex + 2); + XOHCL candle3 = GetCandleModel(signalBarIndex + 3); + + // + // Reding Required XRMarketStates ... + XRMarketState state0 = GetXRMarketState(signalBarIndex); + XRMarketState state1 = GetXRMarketState(signalBarIndex + 1); + XRMarketState state2 = GetXRMarketState(signalBarIndex + 2); + XRMarketState state3 = GetXRMarketState(signalBarIndex + 3); + + // + // Reading required XRangeStates ... + XRState range0 = ReadXRange( + signalBarIndex + xRSwingLength, + xRSwingLength + ); + XRState range1 = ReadXRange( + signalBarIndex + xRSwingLength + 1, + xRSwingLength + ); + XRState range2 = ReadXRange( + signalBarIndex + xRSwingLength + 2, + xRSwingLength + ); + + // + // Reading Required XTPowStates ... + XTPOWState tPow0 = GetXTPowState( + signalBarIndex, + xRSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + signalBarIndex + 1, + xRSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + signalBarIndex + 2, + xRSwingLength + ); + + // + double hhllDiff = MathAbs(pvt0.hh - pvt0.ll); + double sharpDetectionValue = xRSharpDetectionFactor * _Point; + bool isSharpOccured = hhllDiff > sharpDetectionValue; + + // + // Calculate State Min Max Diff ... + // + double state0Min = MathMin(state0.fast, state0.slow); + state0Min = MathMin(state0Min, state0.open); + state0Min = MathMin(state0Min, state0.rangeFast); + state0Min = MathMin(state0Min, state0.rangeSlow); + state0Min = MathMin(state0Min, state0.rangeOpen); + state0Min = MathMin(state0Min, state0.verifier); + + // + double state0Max = MathMax(state0.fast, state0.slow); + state0Max = MathMax(state0Max, state0.open); + state0Max = MathMax(state0Max, state0.rangeFast); + state0Max = MathMax(state0Max, state0.rangeSlow); + state0Max = MathMax(state0Max, state0.rangeOpen); + state0Max = MathMax(state0Max, state0.verifier); + + // + double state0MinMaxDiff = (state0Max - state0Min); + + // + bool isTPowValid = false; + bool isStateValid = false; + bool isRangeValid = false; + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + // Retrieve TPow Verifications ... + isTPowValid = + // + // Starter ... + true + ; + + // + // Retrieve XMarket Verifications ... + isStateValid = + // + // Starter ... + true + // + // && !(state0MinMaxDiff > sharpDetectionValue) + ; + + // + // Retrieve XRange Verifications ... + isRangeValid = + // + // Starter ... + true + ; + + // + result = + // + // Starter ... + true + // + && isTPowValid + && isStateValid + && isRangeValid + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + // Retrieve TPow Verifications ... + isTPowValid = + // + // Starter ... + true + ; + + // + // Retrieve XMarket Verifications ... + isStateValid = + // + // Starter ... + true + ; + + // + // Retrieve XRange Verifications ... + isRangeValid = + // + // Starter ... + true + ; + + // + result = + // + // Starter ... + true + // + && isTPowValid + && isStateValid + && isRangeValid + ; + } + + // + return result; +} +// +// END Functions ... +// + +// +// START Data Providers ... +// +// +XRMarketState GetXRMarketState( + const int bar_index +) { + // + XRMarketState result = {}; + + // + // Calculate Market Lengths ... + + // + if (fastLength == 0) { + fastLength = xRSwingLength; + } + + // + if (slowLength == 0) { + slowLength = xRSwingLength * 2; + } + + // + if (verifierLength == 0) { + verifierLength = (GetDailyCandleCount() * 2); + } + + // + if (rangeFastLength == 0) { + rangeFastLength = (int)(verifierLength / 2); + } + + // + if (rangeSlowLength == 0) { + rangeSlowLength = verifierLength; + } + + // + // Reading Values ... + + // + double fast = GetMA( + bar_index, + fastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double slow = GetMA( + bar_index, + slowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double open = GetMA( + bar_index, + fastLength, + 0, + MODE_SMA, + PRICE_OPEN + ); + + // + double rangeFast = GetMA( + bar_index, + rangeFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double rangeSlow = GetMA( + bar_index, + rangeSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double rangeOpen = GetMA( + bar_index, + rangeFastLength, + 0, + MODE_SMA, + PRICE_OPEN + ); + + // + double verifier = GetMA( + bar_index, + verifierLength, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + // Filling Result ... + result.fast = fast; + result.slow = slow; + result.open = open; + result.verifier = verifier; + result.rangeFast = rangeFast; + result.rangeSlow = rangeSlow; + result.rangeOpen = rangeOpen; + + // + return result; +} +// +// END Data Providers ... +// \ No newline at end of file diff --git a/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.xtpw.signal.lib.mq4 b/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.xtpw.signal.lib.mq4 new file mode 100644 index 0000000..4bf02ce --- /dev/null +++ b/Packed/XAUUSD-15M/MQL4/Libraries/x-saherelm.xtpw.signal.lib.mq4 @@ -0,0 +1,1332 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 XTPW Signal Global Library +// --------------------------------------------------- +// XSaherElm EA Signal Provider based on +// XTPow Indicator... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Inputs ... +// +// +input string xTPWStarter = "- XTPW Signal Provider -"; // ---> XTPW Signal Provider <--- + +// +input bool enableXTPWSignalling = true; // XTPW Signalling Enable + +// +input bool enableXTPWLong = true; // XTPW Signalling Enable Long +input bool enableXTPWShort = true; // XTPW Signalling Enable Short + +// +input double xTPWShortR2R = 2; // XTPW Short Risk To Reward Ratio +input double xTPWShortLotsPerTradePercent = 0.0002; // XTPW Lots Percent per Short Trades +input double xTPWShortMaxDrawdownPerTradePercent = 0.3; // XTPW Max Allowed DrawDown Percent per Short Trade + +// +input double xTPWLongR2R = 2; // XTPW Long Risk To Reward Ratio +input double xTPWLongLotsPerTradePercent = 0.0002; // XTPW Lots Percent per Short Trades +input double xTPWLongMaxDrawdownPerTradePercent = 0.3; // XTPW Max Allowed DrawDown Percent per Long Trade + +// +input int xTPWMaximumCandlesPerTrade = 206; // XTPW Maximum Candles which a Trade can open + +// +input double xTPWPSarStep = 0.02; // XTPW Parabolic Sar Step +input double xTPWPSarMaximum = 0.2; // XTPW Parabolic Sar Maximum + +// +input int xTPWSwingLength = 7; // XTPW Signal Swing Length +// +// END Inputs ... +// + +// +input double xTPWSharpDetectionFactor = 650; // XTPW Sharp Detection Factor + +// +// START Global Requirement Functions ... +// +// +// XTPW Based Signal Conditions ... +struct XTPWSignalConditions { + datetime startTime; + datetime signalTime; + datetime entryTime; +}; + +// +struct XTPWMarketState { + // + double psar; + + // + double scFast; + double scSlow; + double scWeight; + + // + double mcFast; + double mcSlow; + double mcWeight; + + // + double lcFast; + double lcSlow; + double lcWeight; +}; + +// +struct XLHS { + // + double scHH; + double scLL; + + // + double mcHH; + double mcLL; + + // + double lcHH; + double lcLL; +}; + +// +static XTPWSignalConditions xTPWLongConds; +static bool xTPWCloseLongTrades = false; +static bool xTPWWaitForLongSignals = true; + +// +static XTPWSignalConditions xTPWShortConds; +static bool xTPWCloseShortTrades = false; +static bool xTPWWaitForShortSignals = true; + +// +// Count Number of Closed Maximum DrawDown Trades ... +static int xTPWFailedSignals = 0; + +// +double tPowerVerifier = 20; +double tPowerMaxVerifier = 55; + +// +int scFastLength = 0; +int scSlowLength = 0; + +// +int mcFastLength = 0; +int mcSlowLength = 0; + +// +int lcFastLength = 0; +int lcSlowLength = 0; + +// +datetime lastTurnOffLongTradesTime; +datetime lastTurnOffShortTradesTime; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckXTPWSignalHandler( + const int bar_index +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + + // + if ( + !enableXTPWSignalling + || !(enableXTPWLong || enableXTPWShort) + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 1); + + // + XTPOWState tPow0 = GetXTPowState( + bar_index, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xTPWSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xTPWSwingLength + ); + + // + XTPWMarketState state0 = GetXTPWMarketState( + bar_index + ); + XTPWMarketState state1 = GetXTPWMarketState( + bar_index + 1 + ); + XTPWMarketState state2 = GetXTPWMarketState( + bar_index + 2 + ); + + // // + // // Disable Long Conditions ... + // if ( + // xTPWWaitForLongSignals + // && + // ( + // isRangeCrossOverRangeWeight + // || + // isRangeCrossUnderRangeWeight + // || + // isTPowUpperAboveMaxVerifier + // ) + // ) { + // // + // xTPWWaitForLongSignals = false; + // lastTurnOffLongTradesTime = barTime; + // } + + // // + // // Enable Long Conditions ... + // if ( + // !xTPWWaitForLongSignals + // && lastTurnOffLongTradesTime > 0 + // && ( + // // isFastCrossOverSlow + // // || + // // isFastCrossUnderSlow + // isRangeCrossOverRangeWeight + // || + // isRangeCrossUnderRangeWeight + // || + // isTPowUpperBelowMaxVerifier + // ) + // ) { + // // + // // Find Last Turn Off Bar Index ... + // int lastTurnOffLongTradesBarIndex = iBarShift( + // _Symbol, + // _Period, + // lastTurnOffLongTradesTime + // ); + + // // + // // the Distance must be bigger than market length ... + // if (MathAbs(lastTurnOffLongTradesBarIndex - bar_index) > xTPWSwingLength) { + // // + // xTPWWaitForLongSignals = true; + // lastTurnOffLongTradesTime = 0; + // } + // } +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXTPWLongSignalConditions( + const int bar_index +) { + // + if ( + !enableXTPWLong + || !enableXTPWSignalling + || !xTPWWaitForLongSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Retrieve TPow States ... + XTPOWState tPow0 = GetXTPowState( + bar_index, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xTPWSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xTPWSwingLength + ); + + // + // Retrieve TPowMarket State ... + XTPWMarketState state0 = GetXTPWMarketState( + bar_index + ); + XTPWMarketState state1 = GetXTPWMarketState( + bar_index + 1 + ); + XTPWMarketState state2 = GetXTPWMarketState( + bar_index + 2 + ); + + // + // Retrieve XPrice Model ... + XPrice prices = GetPrice(); + + // + // Retrieve Candles ... + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + + // + XLHS lhs = GetXTPWLHS(bar_index); + + // + bool isHHSame = + lhs.scHH == lhs.mcHH + && lhs.mcHH == lhs.lcHH + ; + + // + bool isLLSame = + lhs.scLL == lhs.mcLL + && lhs.mcLL == lhs.lcLL + ; + + // + bool startCondition = false; + bool signalCondition = false; + bool entryCondition = false; + + // + bool longCondition1 = + // + true + // + && !isHHSame + // + && !( + lhs.scLL == lhs.mcLL + ) + // + && !( + lhs.scHH == lhs.mcHH + ) + // + && !( + prices.longEntry + && candle0.high < state0.scFast + && candle0.high < state0.scSlow + && candle0.high < state0.mcFast + && candle0.high < state0.mcSlow + && candle0.high < state0.lcFast + && candle0.high < state0.lcSlow + ) + // + && tPow0.powerDown > tPowerMaxVerifier + && tPow1.powerDown > tPowerMaxVerifier + && tPow0.powerDown < MathMax(tPow1.powerUp, tPow1.powerDown) + && MathMax(tPow1.powerUp, tPow1.powerDown) > tPowerMaxVerifier + ; + + // + // Start Conditions ... + startCondition = ( + longCondition1 + ) + ; + + // + if ( + startCondition + && xTPWLongConds.startTime == 0 + && xTPWLongConds.signalTime == 0 + && xTPWLongConds.entryTime == 0 + ) { + // + xTPWLongConds.startTime = barTime; + xTPWLongConds.signalTime = barTime; + xTPWLongConds.entryTime = barTime; + + // + return; + } +} + +// +// Check and Fill Short Signal Conditions ... +void CheckXTPWShortSignalConditions( + const int bar_index +) { + // + if ( + !enableXTPWShort + || !enableXTPWSignalling + || !xTPWWaitForShortSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Retrieve TPower State ... + XTPOWState tPow0 = GetXTPowState( + bar_index, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xTPWSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xTPWSwingLength + ); + + // + // Retrieve TPWMarket State ... + XTPWMarketState state0 = GetXTPWMarketState( + bar_index + ); + XTPWMarketState state1 = GetXTPWMarketState( + bar_index + 1 + ); + XTPWMarketState state2 = GetXTPWMarketState( + bar_index + 2 + ); + + // + // Retrieve Candles ... + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + + // + XPrice prices = GetPrice(); + XLHS lhs = GetXTPWLHS(bar_index); + + // + double sharpDetectionValue = + xTPWSharpDetectionFactor * _Point; + + // + bool isHHSame = + lhs.scHH == lhs.mcHH + && lhs.mcHH == lhs.lcHH + ; + + // + bool isLLSame = + lhs.scLL == lhs.mcLL + && lhs.mcLL == lhs.lcLL + ; + + // + bool startCondition = false; + bool signalCondition = false; + bool entryCondition = false; + + // + bool shortCondition1 = + // + true + // + && tPow1.powerDown > tPowerMaxVerifier + && tPow2.powerDown < tPowerMaxVerifier + ; + + // + startCondition = ( + shortCondition1 + ) + ; + + // + if ( + startCondition + && xTPWShortConds.startTime == 0 + && xTPWShortConds.signalTime == 0 + && xTPWShortConds.entryTime == 0 + ) { + // + xTPWShortConds.startTime = barTime; + xTPWShortConds.signalTime = barTime; + xTPWShortConds.entryTime = barTime; + + // + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXTPWSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if ( + !enableXTPWSignalling + || !(enableXTPWLong || enableXTPWShort) + ) { + return result; + } + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + // Check Condition Validations ... + if (requestLong) { + // + // Check Long Condtion is Valid, if Long Requested ... + if ( + !ValidateXTPWLongConditions() + ) { + return result; + } + } else { + // + // Check Short Condtion is Valid, if Short Requested ... + if ( + !ValidateXTPWShortConditions() + ) { + return result; + } + } + + // + double ll = + // + GetMarketLowestLow( + bar_index, + xTPWSwingLength + ) + ; + + // + double hh = + // + GetMarketHighestHigh( + bar_index, + xTPWSwingLength + ) + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + // Price Calculations ... + XPrice prices = GetPrice(); + + // + // Read State ... + XTPWMarketState state0 = GetXTPWMarketState(bar_index); + + // + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + XOHCL candle3 = GetCandleModel(bar_index + 2); + + // + double risk = requestLong ? + // + MathMin(openPrice, closePrice) - ll : + hh - MathMax(openPrice, closePrice) + ; + + // + double longR2R = xTPWLongR2R; + double shortR2R = xTPWShortR2R; + + // + double sharpDetectorValue = xTPWSharpDetectionFactor * _Point; + + // + if ( + risk > 0 + && requestLong + ) { + return result; + } + + // + // Define Entry Price ... + double entryPrice = requestLong + ? + prices.longEntry + : + prices.shortEntry + ; + + // + // Fix TP Detects for Short Signals ... + if (!requestLong) { + risk = 0; + } + + // + double reward = requestLong ? + risk * longR2R : + risk * shortR2R + ; + + // + if (risk == 0) { + // + // Calculate Reward ... + reward = requestLong + ? + MathAbs(hh - entryPrice) + : + MathAbs(hh - entryPrice) + ; + + // + // Detect Sharp Change Occured or not ... + bool isSharpOccured = reward > sharpDetectorValue + || MathAbs(reward - sharpDetectorValue) < (50 * _Point); + + // + // Change Rewards on Special Conditions ... + if ( + ( + requestLong + && isSharpOccured + && ( + state0.lcFast < state0.lcSlow + || ( + state0.mcFast > state0.mcSlow + && state0.mcWeight < state0.mcSlow + ) + ) + ) + ) { + reward = reward / 2; + } + + // + if (reward < 50 * _Point) { + reward = (50 * _Point) + prices.priceGap; + } + + // // + // if (!requestLong) { + // reward = reward * shortR2R; + // } + } + + // + double sl = requestLong ? + 0 : + 0; + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward + ; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XTPW_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XTPW_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXTPWLongConditions() { + // + if ( + !enableXTPWLong + || !enableXTPWSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xTPWLongConds.startTime > 0 + && xTPWLongConds.signalTime > 0 + && xTPWLongConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // // + // int startBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWLongConds.startTime + // ); + + // // + // int signalBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWLongConds.signalTime + // ); + + // // + // int entryBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWLongConds.entryTime + // ); + + // // + // int startSignalDiff = (signalBarIndex - startBarIndex); + // int entrySignalDiff = (entryBarIndex - signalBarIndex); + // int maxDiff = MathMax(startSignalDiff, entrySignalDiff); + + // + isBLFilled = + // + // Starter ... + true + // + && xTPWLongConds.signalTime >= xTPWLongConds.startTime + && xTPWLongConds.entryTime >= xTPWLongConds.signalTime + // + // && maxDiff < (xTPWSwingLength * 2) + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xTPWWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXTPWLongSignalConditions(); + } + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXTPWShortConditions() { + // + if ( + !enableXTPWShort + || !enableXTPWSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xTPWShortConds.startTime > 0 + && xTPWShortConds.signalTime > 0 + && xTPWShortConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // // + // int startBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWShortConds.startTime + // ); + + // // + // int signalBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWShortConds.signalTime + // ); + + // // + // int entryBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWShortConds.entryTime + // ); + + // + isBLFilled = + // + // Starter ... + true + // + && xTPWShortConds.signalTime >= xTPWShortConds.startTime + && xTPWShortConds.entryTime >= xTPWShortConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xTPWWaitForShortSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXTPWShortSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXTPWLongSignalConditions() { + // + xTPWLongConds.startTime = 0; + xTPWLongConds.entryTime = 0; + xTPWLongConds.signalTime = 0; +} + +// +// Clear Short Signal Conditions for New One ... +void ClearXTPWShortSignalConditions() { + // + xTPWShortConds.startTime = 0; + xTPWShortConds.entryTime = 0; + xTPWShortConds.signalTime = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForXTPWSignals( + const XSignal &signal +) { + // + bool result = false; + + // + if ( + !enableXTPWSignalling + || !(enableXTPWLong || enableXTPWShort) + ) { + return result; + } + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // XOHCL candle = GetCandleModel(0); + XOHCL candle0 = GetCandleModel(signalBarIndex); + XOHCL candle1 = GetCandleModel(signalBarIndex + 1); + + // + // Retrieve TPow State ... + XTPOWState tPow0 = GetXTPowState( + signalBarIndex, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + signalBarIndex + 1, + xTPWSwingLength + ); + + // + // Retrive XMarket States ... + XTPWMarketState state0 = GetXTPWMarketState(signalBarIndex); + XTPWMarketState state1 = GetXTPWMarketState(signalBarIndex + 1); + XTPWMarketState state2 = GetXTPWMarketState(signalBarIndex + 2); + + // + bool isPSarVerified = false; + bool isTPowVerified = false; + bool isStateVerified = false; + bool isPriceVerified = false; + + // + // Calculate Sharp Detection Value ... + double sharpDetectionValue = + xTPWSharpDetectionFactor * _Point; + + // + // Find State0 Min ... + double state0Min = MathMin(state0.scFast, state0.scSlow); + state0Min = MathMin(state0Min, state0.mcFast); + state0Min = MathMin(state0Min, state0.mcSlow); + state0Min = MathMin(state0Min, state0.lcFast); + state0Min = MathMin(state0Min, state0.lcSlow); + + // + // Find State0 Min ... + double state0Max = MathMax(state0.scFast, state0.scSlow); + state0Max = MathMax(state0Max, state0.mcFast); + state0Max = MathMax(state0Max, state0.mcSlow); + state0Max = MathMax(state0Max, state0.lcFast); + state0Max = MathMax(state0Max, state0.lcSlow); + + // + // Find Distance Between State0 Min and Max ... + double state0MinMaxDistance = MathAbs(state0Max - state0Min); + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + // Get Price Verification for Long ... + isPriceVerified = + // + // Starter ... + true + // + ; + + // + isTPowVerified = + // + // Starter ... + true + // + && tPow0.powerDown > tPowerMaxVerifier + && tPow1.powerDown > tPowerMaxVerifier + && tPow0.powerDown < MathMax(tPow1.powerUp, tPow1.powerDown) + && MathMax(tPow1.powerUp, tPow1.powerDown) > tPowerMaxVerifier + ; + + // + isPSarVerified = + // + // Starter ... + true + // + ; + + // + isStateVerified = + // + // Start ... + true + // + && state0.mcFast > state0.mcSlow + && state1.mcFast > state1.mcSlow + // + && !( + state0.lcFast > state0.mcSlow + && state0.lcFast < state0.mcFast + ) + // + && MathAbs(state1.mcFast - state1.mcSlow) > (50 * _Point) + ; + + // + result = + // + // Starter ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + isPSarVerified = + // + // Starter ... + true + ; + + // + // Get Price Verification for Short ... + isPriceVerified = + // + // Starter ... + true + ; + + // + isTPowVerified = + // + // Starter ... + true + // + && tPow0.signal > MathMax(tPow0.powerUp, tPow0.powerDown) + ; + + // + isStateVerified = + // + // Start ... + true + // + && ( + // + state0.scFast < state0.scSlow + && state0.mcFast < state0.mcSlow + && state0.lcFast < state0.lcSlow + ? + signal.entry > state0.scFast + : + // + // Find Minimum and Maximum Distance of State ... + state0MinMaxDistance > sharpDetectionValue + ? + signal.entry > state0Min + : + true + ) + // + && MathAbs(state0.mcFast - state0.mcSlow) > 50 * _Point + ; + + // + result = + // + // Starter Condition ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } + + // + return result; +} +// +// END Functions ... +// + +// +// START Data Provider ... +// +// +// Retrieve Market State ... +XTPWMarketState GetXTPWMarketState( + const int bar_index +) { + // + XTPWMarketState result = {}; + + // + int dayCount = GetDailyCandleCount(); + int halfDayCount = (int)(dayCount / 2); + + // + if (scFastLength == 0) { + scFastLength = xTPWSwingLength; + } + + // + if (scSlowLength == 0) { + scSlowLength = xTPWSwingLength * 2; + } + + // + if (mcFastLength == 0) { + mcFastLength = halfDayCount; + } + + // + if (mcSlowLength == 0) { + mcSlowLength = dayCount; + } + + // + if (lcFastLength == 0) { + lcFastLength = halfDayCount * 3; + } + + // + if (lcSlowLength == 0) { + lcSlowLength = dayCount * 3; + } + + // + double scFast = GetMA( + bar_index, + scFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double scSlow = GetMA( + bar_index, + scSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double scWeight = GetMA( + bar_index, + scSlowLength, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double mcFast = GetMA( + bar_index, + mcFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double mcSlow = GetMA( + bar_index, + mcSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double mcWeight = GetMA( + bar_index, + mcSlowLength, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double lcFast = GetMA( + bar_index, + lcFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double lcSlow = GetMA( + bar_index, + lcSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double lcWeight = GetMA( + bar_index, + lcSlowLength, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double psar = iSAR( + _Symbol, + _Period, + xTPWPSarStep, + xTPWPSarMaximum, + bar_index + ); + + // + result.psar = psar; + result.scFast = scFast; + result.scSlow = scSlow; + result.mcFast = mcFast; + result.mcSlow = mcSlow; + result.lcFast = lcFast; + result.lcSlow = lcSlow; + result.scWeight = scWeight; + result.mcWeight = mcWeight; + result.lcWeight = lcWeight; + + // + return result; +} + +// +// Retrieve Highest Highs and Lowest Lows in Cycles ... +XLHS GetXTPWLHS( + const int bar_index +) { + // + XLHS result = {}; + + // + // Retrieve LL and HH (s) ... + + // + // SC HH ... + double scHH = GetMarketHighestHigh( + bar_index, + scFastLength + ); + + // + // SC LL ... + double scLL = GetMarketHighestHigh( + bar_index, + scFastLength + ); + + // + // MC HH ... + double mcHH = GetMarketHighestHigh( + bar_index, + mcFastLength + ); + + // + // MC LL ... + double mcLL = GetMarketHighestHigh( + bar_index, + mcFastLength + ); + + // + // LC HH ... + double lcHH = GetMarketHighestHigh( + bar_index, + lcFastLength + ); + + // + // LC LL ... + double lcLL = GetMarketHighestHigh( + bar_index, + lcFastLength + ); + + // + result.scHH = scHH; + result.scLL = scLL; + result.mcHH = mcHH; + result.mcLL = mcLL; + result.lcHH = lcHH; + result.lcLL = lcLL; + + // + return result; +} +// +// END Data Provider ... +// diff --git a/Packed/XAUUSD-15M/Reports/Screenshot 2023-08-03 202922.png b/Packed/XAUUSD-15M/Reports/Screenshot 2023-08-03 202922.png new file mode 100644 index 0000000..98f6bb0 Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/Screenshot 2023-08-03 202922.png differ diff --git a/Packed/XAUUSD-15M/Reports/Screenshot 2023-08-08 174923.png b/Packed/XAUUSD-15M/Reports/Screenshot 2023-08-08 174923.png new file mode 100644 index 0000000..6795066 Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/Screenshot 2023-08-08 174923.png differ diff --git a/Packed/XAUUSD-15M/Reports/Strategy Tester_ x-saherelm.ea.pdf b/Packed/XAUUSD-15M/Reports/Strategy Tester_ x-saherelm.ea.pdf new file mode 100644 index 0000000..5041ce9 Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/Strategy Tester_ x-saherelm.ea.pdf differ diff --git a/Packed/XAUUSD-15M/Reports/Strategy Tester_ x-saherelm.ea_1.pdf b/Packed/XAUUSD-15M/Reports/Strategy Tester_ x-saherelm.ea_1.pdf new file mode 100644 index 0000000..ed4eefa Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/Strategy Tester_ x-saherelm.ea_1.pdf differ diff --git a/Packed/XAUUSD-15M/Reports/StrategyTester X (XR and XXX and XTPW) - 0.2 - Full.gif b/Packed/XAUUSD-15M/Reports/StrategyTester X (XR and XXX and XTPW) - 0.2 - Full.gif new file mode 100644 index 0000000..dcdca94 Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/StrategyTester X (XR and XXX and XTPW) - 0.2 - Full.gif differ diff --git a/Packed/XAUUSD-15M/Reports/StrategyTester X (XR and XXX and XTPW) - 0.2 - Full.htm b/Packed/XAUUSD-15M/Reports/StrategyTester X (XR and XXX and XTPW) - 0.2 - Full.htm new file mode 100644 index 0000000..342d0e7 --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/StrategyTester X (XR and XXX and XTPW) - 0.2 - Full.htm @@ -0,0 +1,445 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.08 12:30 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.0002; xShortMaxDrawdownPerTradePercent=0.4; xLongR2R=3; xLongLotsPerTradePercent=0.0002; xLongMaxDrawdownPerTradePercent=0.4; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=true; +xRShortR2R=1.5; xRShortLotsPerTradePercent=0.0002; xRShortMaxDrawdownPerTradePercent=0.15; xRLongR2R=1.5; xRLongLotsPerTradePercent=0.0002; xRLongMaxDrawdownPerTradePercent=0.15; xRMaximumCandlesPerTrade=96; xRSwingLength=48; xRSharpDetectionFactor=1350; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.0002; xTPWShortMaxDrawdownPerTradePercent=0.3; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.0002; xTPWLongMaxDrawdownPerTradePercent=0.3; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63768Ticks modelled73089409Modelling qualityn/a
Mismatched charts errors905
Initial deposit1000.00SpreadCurrent (51)
Total net profit11549.05Gross profit21988.17Gross loss-10439.12
Profit factor2.11Expected payoff62.43
Absolute drawdown79.00Maximal drawdown2410.03 (23.15%)Relative drawdown52.81% (1054.29)
Total trades185Short positions (won %)105 (59.05%)Long positions (won %)80 (58.75%)
Profit trades (% of total)109 (58.92%)Loss trades (% of total)76 (41.08%)
Largestprofit trade929.92loss trade-408.85
Averageprofit trade201.73loss trade-137.36
Maximumconsecutive wins (profit in money)15 (3323.80)consecutive losses (loss in money)8 (-643.55)
Maximalconsecutive profit (count of wins)4023.21 (12)consecutive loss (count of losses)-1081.46 (7)
Averageconsecutive wins4consecutive losses3
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 06:45sell10.201807.850.001797.08
22020.11.27 15:09t/p10.201797.080.001797.08215.401215.40
32020.11.27 15:09sell20.201796.570.001788.89
42020.11.27 15:36t/p20.201788.890.001788.89153.601369.00
52020.12.01 19:30buy30.201812.580.001853.94
62020.12.02 10:39buy40.201824.820.001839.43
72020.12.02 14:45close40.201817.320.001839.43-150.001219.00
82020.12.04 09:30buy50.201842.380.001854.80
92020.12.07 10:38close50.201822.380.001854.80-408.85810.15
102020.12.07 16:52t/p30.201853.940.001853.94774.121584.28
112021.01.06 02:00buy60.201950.710.001958.51
122021.01.06 12:00t/p60.201958.510.001958.51156.001740.28
132021.01.29 16:54sell70.201865.800.001855.99
142021.01.29 17:39t/p70.201855.990.001855.99196.201936.48
152021.02.04 16:00sell80.201808.190.001779.92
162021.02.05 17:24close80.201808.200.001779.923.921940.40
172021.02.05 19:15buy90.201814.780.001846.22
182021.02.08 14:49buy100.201824.180.001843.47
192021.02.09 09:54t/p100.201843.470.001843.47376.952317.35
202021.02.09 11:24t/p90.201846.220.001846.22611.112928.46
212021.02.09 17:45sell110.201841.990.001838.33
222021.02.09 18:09t/p110.201838.330.001838.3373.203001.66
232021.02.10 17:00sell120.201841.300.001827.41
242021.02.11 19:09t/p120.201827.410.001827.41290.173291.83
252021.02.16 15:15sell130.201811.040.001788.17
262021.02.16 17:09sell140.201804.040.001801.47
272021.02.16 18:49t/p140.201801.470.001801.4751.403343.23
282021.02.16 18:49sell150.201800.960.001767.09
292021.02.17 01:09t/p130.201788.170.001788.17461.523804.75
302021.02.19 02:39t/p150.201767.090.001767.09698.014502.76
312021.02.19 05:15buy160.201769.850.001786.38
322021.02.19 16:09t/p160.201786.380.001786.38330.604833.36
332021.02.23 04:00buy170.201813.570.001842.72
342021.02.23 05:45buy180.201813.260.001827.74
352021.02.23 11:24close170.201806.070.001842.72-150.004683.36
362021.02.23 11:24close180.201805.760.001827.74-150.004533.36
372021.02.23 11:24buy190.201806.260.001820.62
382021.02.23 16:37close190.201798.760.001820.62-150.004383.36
392021.03.03 16:51sell200.201712.530.001708.07
402021.03.03 17:36t/p200.201708.070.001708.0789.204472.56
412021.03.11 16:48buy210.201719.840.001727.97
422021.03.11 20:09t/p210.201727.970.001727.97162.604635.16
432021.03.17 13:48buy220.201728.280.001737.00
442021.03.17 20:06t/p220.201737.000.001737.00174.404809.56
452021.04.08 14:00buy230.201746.240.001756.38
462021.04.08 16:39t/p230.201756.380.001756.38202.805012.36
472021.04.19 15:15buy240.201775.840.001781.87
482021.04.21 04:30buy250.201779.820.001788.61
492021.04.21 04:39t/p240.201781.870.001781.87102.915115.27
502021.04.21 16:39t/p250.201788.610.001788.61175.805291.07
512021.04.27 18:24buy260.201778.360.001784.35
522021.04.28 12:24close260.201763.360.001784.35-308.854982.22
532021.05.04 23:15sell270.201779.150.001777.35
542021.05.05 03:24t/p270.201777.350.001777.3540.125022.34
552021.05.06 18:00buy280.201815.870.001857.41
562021.05.10 17:45sell290.201839.580.001833.85
572021.05.11 03:39t/p290.201833.850.001833.85118.725141.07
582021.05.12 23:21close280.201815.850.001857.41-35.785105.28
592021.05.13 13:15sell300.201810.390.001791.73
602021.05.13 15:07close300.201817.890.001791.73-150.004955.28
612021.05.19 22:00buy310.201863.400.001881.95
622021.05.20 19:49t/p310.201881.950.001881.95344.465299.74
632021.06.17 10:30sell320.201809.210.001762.92
642021.06.18 08:45sell330.201784.490.001777.35
652021.06.18 15:52t/p330.201777.350.001777.35142.805442.54
662021.06.18 22:54t/p320.201762.920.001762.92929.926372.47
672021.07.01 05:00buy340.201771.700.001788.95
682021.07.02 15:39t/p340.201788.950.001788.95336.156708.62
692021.07.06 19:07buy350.201794.020.001807.68
702021.07.07 13:24t/p350.201807.680.001807.68264.356972.97
712021.07.08 14:00buy360.201817.710.001849.35
722021.07.08 16:39close360.201810.210.001849.35-150.006822.97
732021.07.08 18:04buy370.201801.870.001814.59
742021.07.13 15:30buy380.201813.520.001824.52
752021.07.13 15:30close380.201806.020.001824.52-150.006672.97
762021.07.13 15:39t/p370.201814.590.001814.59227.866900.84
772021.07.13 17:21sell390.201811.750.001808.46
782021.07.13 20:34t/p390.201808.460.001808.4665.806966.64
792021.07.14 06:30buy400.201813.380.001826.10
802021.07.14 08:30buy410.201813.760.001827.05
812021.07.14 11:30buy420.201814.800.001828.95
822021.07.14 15:04buy430.201821.020.001839.02
832021.07.14 15:09t/p400.201826.100.001826.10254.407221.04
842021.07.14 15:37t/p410.201827.050.001827.05265.807486.84
852021.07.14 15:39t/p420.201828.950.001828.95283.007769.84
862021.07.15 17:09close430.201821.010.001839.02-26.747743.10
872021.07.16 22:30sell440.201810.350.001786.20
882021.07.19 09:15sell450.201806.190.001789.75
892021.07.19 16:09close450.201813.690.001789.75-150.007593.10
902021.07.19 18:15sell460.201807.210.001794.99
912021.07.19 23:30close440.201811.980.001786.20-28.487564.62
922021.07.19 23:30sell470.201811.480.001805.66
932021.07.20 04:04close460.201814.710.001794.99-145.887418.74
942021.07.20 04:04sell480.201814.210.001812.49
952021.07.20 05:07close470.201818.980.001805.66-145.887272.86
962021.07.20 11:09t/p480.201812.490.001812.4934.407307.26
972021.07.20 18:15sell490.201810.140.001788.26
982021.07.20 20:30sell500.201810.840.001790.01
992021.07.21 10:30sell510.201808.770.001801.56
1002021.07.21 14:03t/p510.201801.560.001801.56144.207451.46
1012021.07.23 10:54close490.201810.150.001788.2620.417471.87
1022021.07.23 14:34t/p500.201790.010.001790.01437.217909.08
1032021.07.29 04:30buy520.201816.130.001850.99
1042021.07.30 19:52close520.201816.120.001850.99-9.057900.04
1052021.07.30 21:45sell530.201810.450.001779.33
1062021.08.02 04:45sell540.201809.440.001783.03
1072021.08.02 06:30sell550.201811.180.001792.46
1082021.08.02 19:24close540.201816.940.001783.03-150.007750.04
1092021.08.02 19:39close530.201817.950.001779.33-145.887604.16
1102021.08.02 19:39sell560.201817.450.001799.74
1112021.08.02 19:54close550.201818.680.001792.46-150.007454.16
1122021.08.03 04:30sell570.201809.740.001795.34
1132021.08.03 06:15sell580.201810.010.001796.02
1142021.08.04 05:30close570.201813.380.001795.34-68.687385.48
1152021.08.04 05:30sell590.201812.880.001810.08
1162021.08.04 07:15close580.201812.750.001796.02-50.687334.80
1172021.08.04 14:36close560.201817.460.001799.748.047342.85
1182021.08.04 15:07close590.201820.380.001810.08-150.007192.85
1192021.08.04 18:30sell600.201806.630.001769.34
1202021.08.04 21:45sell610.201810.860.001779.92
1212021.08.05 08:54sell620.201808.740.001803.00
1222021.08.05 10:52close600.201814.130.001769.34-137.637055.21
1232021.08.05 11:37sell630.201809.130.001802.26
1242021.08.05 16:39sell640.201802.930.001795.96
1252021.08.05 16:39t/p620.201803.000.001803.00114.807170.01
1262021.08.05 16:39t/p630.201802.260.001802.26137.407307.41
1272021.08.06 10:18t/p640.201795.960.001795.96143.527450.94
1282021.08.06 15:39t/p610.201779.920.001779.92635.298086.22
1292021.08.17 17:15buy650.201782.620.001787.73
1302021.08.18 04:09t/p650.201787.730.001787.7393.358179.58
1312021.08.20 17:39sell660.201781.750.001777.75
1322021.08.23 02:18t/p660.201777.750.001777.7584.128263.70
1332021.08.26 13:45buy670.201787.170.001795.30
1342021.08.26 18:04t/p670.201795.300.001795.30162.608426.30
1352021.08.27 19:15buy680.201814.880.001860.66
1362021.08.30 20:15close680.201810.010.001860.66-106.258320.05
1372021.08.31 04:30buy690.201813.980.001822.79
1382021.08.31 14:15buy700.201814.230.001820.43
1392021.08.31 16:06close700.201806.730.001820.43-150.008170.05
1402021.08.31 16:06close690.201806.480.001822.79-150.008020.05
1412021.08.31 20:00buy710.201814.290.001832.64
1422021.09.01 04:30buy720.201812.910.001829.19
1432021.09.01 11:23sell730.201811.910.001804.44
1442021.09.01 15:52close730.201819.410.001804.44-150.007870.05
1452021.09.01 18:19sell740.201812.290.001800.92
1462021.09.01 21:00close710.201812.490.001832.64-44.857825.21
1472021.09.02 06:04close720.201812.900.001829.19-26.747798.47
1482021.09.02 07:30sell750.201811.430.001804.14
1492021.09.02 17:30sell760.201807.760.001793.92
1502021.09.03 04:06close740.201812.300.001800.9216.297814.76
1512021.09.03 04:37sell770.201810.730.001806.97
1522021.09.03 08:30close750.201811.800.001804.14-3.287811.48
1532021.09.03 14:07close760.201815.260.001793.92-145.887665.60
1542021.09.03 14:07sell780.201814.760.001805.79
1552021.09.03 15:34close770.201818.240.001806.97-150.207515.40
1562021.09.03 15:36close780.201822.260.001805.79-150.007365.40
1572021.09.07 13:15sell790.201810.900.001786.66
1582021.09.07 16:15sell800.201810.490.001785.77
1592021.09.08 16:54t/p790.201786.660.001786.66488.927854.32
1602021.09.08 16:54t/p800.201785.770.001785.77498.528352.85
1612021.10.21 09:45buy810.201786.670.001797.59
1622021.10.22 15:22t/p810.201797.590.001797.59209.558562.40
1632021.10.27 18:09sell820.201793.560.001789.11
1642021.10.28 16:30close820.201808.560.001789.11-287.638274.77
1652021.11.03 04:00sell830.201783.060.001779.26
1662021.11.03 08:15t/p830.201779.260.001779.2676.008350.77
1672021.11.05 18:45buy840.201814.330.001857.76
1682021.11.10 16:24t/p840.201857.760.001857.76842.069192.83
1692021.11.22 19:45sell850.201810.200.001755.21
1702021.11.23 04:15sell860.201807.780.001757.35
1712021.11.26 09:54close860.201807.790.001757.3520.419213.24
1722021.11.26 12:03close850.201810.210.001755.2124.539237.77
1732021.11.30 17:48sell870.201794.770.001781.02
1742021.11.30 18:04t/p870.201781.020.001781.02275.009512.77
1752021.12.13 16:49sell880.201785.140.001782.99
1762021.12.14 10:24t/p880.201782.990.001782.9947.129559.89
1772021.12.15 04:45sell890.201771.980.001768.80
1782021.12.15 07:39t/p890.201768.800.001768.8063.609623.49
1792021.12.15 16:54sell900.201769.740.001766.01
1802021.12.15 17:39t/p900.201766.010.001766.0174.609698.09
1812021.12.20 17:01sell910.201793.800.001789.41
1822021.12.20 22:09t/p910.201789.410.001789.4187.809785.89
1832021.12.21 16:52buy920.201793.730.001796.76
1842021.12.22 18:04t/p920.201796.760.001796.7651.759837.65
1852021.12.27 18:00buy930.201812.980.001827.61
1862021.12.28 08:00buy940.201813.200.001822.49
1872021.12.28 17:00buy950.201814.150.001821.35
1882021.12.28 19:00close930.201810.530.001827.61-57.859779.80
1892021.12.28 19:00buy960.201811.050.001813.05
1902021.12.28 20:51close950.201806.650.001821.35-150.009629.80
1912021.12.28 20:54close940.201805.700.001822.49-150.009479.80
1922021.12.29 10:07close960.201803.550.001813.05-158.859320.95
1932021.12.30 19:00buy970.201813.820.001839.85
1942022.01.03 15:09close970.201813.810.001839.85-17.899303.06
1952022.01.03 16:00sell980.201806.970.001776.15
1962022.01.04 17:00close980.201811.720.001776.15-90.889212.18
1972022.01.04 17:45buy990.201817.010.001844.22
1982022.01.04 19:30buy1000.201814.590.001838.17
1992022.01.05 21:09close990.201817.000.001844.22-9.059203.14
2002022.01.05 21:09close1000.201814.580.001838.17-9.059194.09
2012022.01.05 22:30sell1010.201810.000.001780.84
2022022.01.11 08:16close1010.201810.010.001780.8424.539218.62
2032022.01.11 18:30buy1020.201815.670.001836.03
2042022.01.13 17:51close1020.201815.660.001836.03-35.589183.04
2052022.01.18 12:00sell1030.201810.270.001791.81
2062022.01.18 15:30sell1040.201806.890.001783.36
2072022.01.18 15:34close1040.201814.390.001783.36-150.009033.04
2082022.01.18 15:37close1030.201817.770.001791.81-150.008883.04
2092022.01.18 18:19sell1050.201813.030.001806.19
2102022.01.19 05:15sell1060.201810.740.001797.05
2112022.01.19 07:00sell1070.201811.540.001805.36
2122022.01.19 12:34close1060.201818.240.001797.05-150.008733.04
2132022.01.19 12:37close1070.201819.040.001805.36-150.008583.04
2142022.01.19 12:37sell1080.201818.540.001805.81
2152022.01.19 16:37close1080.201826.040.001805.81-150.008433.04
2162022.01.19 16:52close1050.201828.030.001806.19-295.888137.16
2172022.01.27 09:00sell1090.201810.600.001776.66
2182022.01.27 13:15sell1100.201810.700.001793.86
2192022.01.27 18:24t/p1100.201793.860.001793.86336.808473.96
2202022.02.02 17:24close1090.201810.610.001776.6616.298490.25
2212022.02.04 12:30buy1110.201814.020.001827.67
2222022.02.04 15:30buy1120.201813.290.001824.06
2232022.02.04 15:36close1110.201806.520.001827.67-150.008340.25
2242022.02.04 15:36close1120.201805.780.001824.06-150.208190.05
2252022.02.07 02:45buy1130.201812.800.001843.33
2262022.02.07 11:00buy1140.201813.370.001822.93
2272022.02.07 14:00buy1150.201813.930.001821.18
2282022.02.07 18:37buy1160.201818.370.001830.55
2292022.02.07 21:06t/p1150.201821.180.001821.18145.008335.05
2302022.02.07 21:37t/p1140.201822.930.001822.93191.208526.25
2312022.02.09 11:30buy1170.201827.790.001831.60
2322022.02.09 15:07t/p1160.201830.550.001830.55225.918752.16
2332022.02.09 15:09t/p1170.201831.600.001831.6076.208828.36
2342022.02.11 20:34t/p1130.201843.330.001843.33557.529385.88
2352022.02.15 11:19buy1180.201856.870.001866.96
2362022.02.16 19:19t/p1180.201866.960.001866.96192.959578.84
2372022.02.18 17:33sell1190.201895.770.001893.21
2382022.02.18 17:37t/p1190.201893.210.001893.2151.209630.04
2392022.03.02 18:16sell1200.201921.470.001907.56
2402022.03.03 13:34close1200.201936.480.001907.56-287.839342.20
2412022.03.14 08:45sell1210.201975.330.001973.05
2422022.03.14 09:54t/p1210.201973.050.001973.0545.609387.80
2432022.04.22 19:22sell1220.201936.790.001932.93
2442022.04.22 20:28t/p1220.201932.930.001932.9377.209465.00
2452022.04.26 16:08sell1230.201905.800.001905.21
2462022.04.26 16:57t/p1230.201905.210.001905.2111.809476.80
2472022.05.13 16:15sell1240.201802.800.001764.16
2482022.05.13 17:01close1240.201810.300.001764.16-150.009326.80
2492022.05.13 19:00sell1250.201808.990.001779.64
2502022.05.16 02:00sell1260.201810.840.001796.49
2512022.05.16 03:58close1250.201816.490.001779.64-145.889180.92
2522022.05.16 06:45sell1270.201809.830.001798.46
2532022.05.16 10:42t/p1270.201798.460.001798.46227.409408.32
2542022.05.16 10:43t/p1260.201796.490.001796.49287.009695.32
2552022.05.18 06:30sell1280.201808.180.001785.79
2562022.05.18 10:00sell1290.201809.610.001794.63
2572022.05.18 10:28close1280.201815.680.001785.79-150.009545.32
2582022.05.18 11:12close1290.201817.110.001794.63-150.009395.32
2592022.05.18 15:15sell1300.201808.580.001791.15
2602022.05.18 16:43close1300.201816.090.001791.15-150.209245.12
2612022.06.10 16:01sell1310.201839.900.001834.17
2622022.06.10 16:18t/p1310.201834.170.001834.17114.609359.72
2632022.06.14 19:00sell1320.201810.290.001778.72
2642022.06.14 21:30sell1330.201810.070.001778.17
2652022.06.15 04:38close1330.201817.570.001778.17-145.889213.85
2662022.06.15 05:20close1320.201817.790.001778.72-145.889067.97
2672022.06.24 05:00sell1340.201823.760.001819.89
2682022.06.24 16:00t/p1340.201819.890.001819.8977.409145.37
2692022.06.30 13:45sell1350.201810.240.001792.95
2702022.06.30 15:37close1350.201817.750.001792.95-150.208995.17
2712022.06.30 18:00sell1360.201808.930.001784.98
2722022.06.30 20:00sell1370.201809.760.001787.05
2732022.07.01 14:39t/p1370.201787.050.001787.05458.329453.49
2742022.07.01 15:24t/p1360.201784.980.001784.98483.129936.61
2752022.07.20 16:52sell1380.201708.520.001702.79
2762022.07.20 19:48t/p1380.201702.790.001702.79114.6010051.21
2772022.08.01 01:30buy1390.201764.460.001772.38
2782022.08.01 12:57t/p1390.201772.380.001772.38158.4010209.61
2792022.08.02 18:02sell1400.201776.930.001767.92
2802022.08.02 21:02t/p1400.201767.920.001767.92180.2010389.81
2812022.08.22 14:15buy1410.201735.800.001742.64
2822022.08.23 11:42t/p1410.201742.640.001742.64127.9510517.77
2832022.09.05 04:45buy1420.201711.690.001722.31
2842022.09.06 03:46t/p1420.201722.310.001722.31203.5510721.32
2852022.09.30 20:35buy1430.201663.070.001667.31
2862022.10.03 04:30t/p1430.201667.310.001667.3175.9510797.27
2872022.11.02 21:03sell1440.201647.760.001626.40
2882022.11.03 10:26t/p1440.201626.400.001626.40439.5711236.84
2892022.11.15 04:45buy1450.201771.800.001782.63
2902022.11.15 09:47t/p1450.201782.630.001782.63216.6011453.44
2912022.11.21 20:30buy1460.201738.320.001753.50
2922022.11.21 23:45buy1470.201738.430.001742.36
2932022.11.22 03:06t/p1470.201742.360.001742.3669.7511523.19
2942022.11.24 02:26t/p1460.201753.500.001753.50259.3711782.56
2952022.11.30 10:00buy1480.201755.420.001761.93
2962022.11.30 11:36t/p1480.201761.930.001761.93130.2011912.76
2972022.11.30 17:18buy1490.201751.830.001763.12
2982022.11.30 21:20t/p1490.201763.120.001763.12225.8012138.56
2992022.12.09 17:23buy1500.201791.170.001800.19
3002022.12.09 18:20t/p1500.201800.190.001800.19180.4012318.96
3012022.12.13 16:30buy1510.201818.890.001875.11
3022022.12.13 17:47close1510.201811.390.001875.11-150.0012168.96
3032022.12.13 18:45buy1520.201813.270.001859.04
3042022.12.13 19:25close1520.201805.770.001859.04-150.0012018.96
3052022.12.20 17:15buy1530.201820.840.001871.26
3062022.12.21 06:43close1530.201813.340.001871.26-158.8511860.12
3072022.12.21 09:30buy1540.201815.350.001820.14
3082022.12.21 14:00buy1550.201814.060.001816.91
3092022.12.21 15:13t/p1550.201816.910.001816.9157.0011917.12
3102022.12.21 17:07t/p1540.201820.140.001820.1495.8012012.92
3112022.12.22 16:15sell1560.201807.890.001789.40
3122022.12.22 20:02t/p1560.201789.400.001789.40369.8012382.72
3132022.12.27 17:30buy1570.201821.700.001850.34
3142022.12.27 19:56close1570.201814.190.001850.34-150.2012232.52
3152022.12.27 20:15buy1580.201814.990.001833.56
3162022.12.28 03:30buy1590.201814.650.001832.71
3172022.12.28 09:03close1580.201807.490.001833.56-158.8512073.67
3182022.12.28 10:08close1590.201807.130.001832.71-150.4011923.27
3192022.12.29 17:00buy1600.201814.310.001828.76
3202022.12.29 18:45buy1610.201814.680.001829.68
3212022.12.30 18:38close1600.201814.300.001828.76-9.0511914.23
3222023.01.03 01:07t/p1610.201829.680.001829.68273.4612187.69
3232023.01.11 17:38buy1620.201870.920.001874.91
3242023.01.11 19:21t/p1620.201874.910.001874.9179.8012267.49
3252023.01.12 17:10sell1630.201884.680.001867.96
3262023.01.12 21:05close1630.201899.680.001867.96-300.0011967.49
3272023.01.20 09:00buy1640.201926.850.001936.66
3282023.01.20 10:08t/p1640.201936.660.001936.66196.2012163.69
3292023.02.07 16:32sell1650.201869.860.001868.93
3302023.02.07 16:45t/p1650.201868.930.001868.9318.6012182.29
3312023.02.09 17:00sell1660.201879.160.001868.22
3322023.02.09 18:03t/p1660.201868.220.001868.22218.8012401.09
3332023.02.24 18:15sell1670.201809.460.001784.47
3342023.02.24 20:00sell1680.201809.720.001785.12
3352023.02.24 23:15sell1690.201811.200.001791.97
3362023.02.27 05:30sell1700.201810.190.001802.03
3372023.02.27 16:00close1670.201816.960.001784.47-145.8812255.21
3382023.02.27 16:22close1680.201817.220.001785.12-145.8812109.33
3392023.02.27 16:22sell1710.201816.720.001801.36
3402023.02.27 16:23close1700.201817.690.001802.03-150.0011959.33
3412023.02.27 16:57close1690.201818.700.001791.97-145.8811813.45
3422023.02.28 10:00sell1720.201810.360.001797.04
3432023.02.28 12:00sell1730.201810.170.001796.57
3442023.02.28 16:46close1730.201817.670.001796.57-150.0011663.45
3452023.02.28 16:47close1720.201817.860.001797.04-150.0011513.45
3462023.02.28 17:03close1710.201824.220.001801.36-145.8811367.58
3472023.03.01 04:30buy1740.201829.010.001845.24
3482023.03.02 20:35sell1750.201835.870.001834.86
3492023.03.02 20:43t/p1750.201834.860.001834.8620.2011387.78
3502023.03.03 10:41t/p1740.201845.240.001845.24289.2211676.99
3512023.03.08 05:15sell1760.201809.930.001774.74
3522023.03.08 16:32close1760.201817.430.001774.74-150.0011526.99
3532023.04.25 09:30buy1770.201995.350.002008.13
3542023.04.26 16:27t/p1770.202008.130.002008.13246.7511773.75
3552023.04.26 19:17buy1780.201988.980.001995.09
3562023.04.27 05:12t/p1780.201995.090.001995.0995.6611869.41
3572023.05.15 17:34sell1790.202016.660.002011.32
3582023.05.16 09:04t/p1790.202011.320.002011.32110.9211980.33
3592023.05.26 17:09sell1800.201951.200.001949.72
3602023.05.26 17:19t/p1800.201949.720.001949.7229.6012009.93
3612023.06.07 17:32sell1810.201958.950.001947.93
3622023.06.07 18:50t/p1810.201947.930.001947.93220.4012230.33
3632023.07.04 17:45buy1820.201928.500.001932.73
3642023.07.05 16:17t/p1820.201932.730.001932.7375.7512306.08
3652023.07.13 18:04sell1830.201959.610.001957.54
3662023.07.13 18:51t/p1830.201957.540.001957.5441.4012347.48
3672023.07.19 18:12sell1840.201974.940.001970.18
3682023.07.20 17:35t/p1840.201970.180.001970.18107.5712455.05
3692023.07.25 15:30sell1850.201958.580.001953.88
3702023.07.25 17:00t/p1850.201953.880.001953.8894.0012549.05
+
diff --git a/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.2.gif b/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.2.gif new file mode 100644 index 0000000..6b9c0a9 Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.2.gif differ diff --git a/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.2.htm b/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.2.htm new file mode 100644 index 0000000..0f86f87 --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.2.htm @@ -0,0 +1,223 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.01 23:45 (2020.01.01 - 2023.08.02)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.0002; xShortMaxDrawdownPerTradePercent=0.4; xLongR2R=3; xLongLotsPerTradePercent=0.0002; xLongMaxDrawdownPerTradePercent=0.4; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +enableXRLong=true; +enableXRShort=true; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.0002; xTPWShortMaxDrawdownPerTradePercent=0.3; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.0002; xTPWLongMaxDrawdownPerTradePercent=0.3; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63353Ticks modelled72601176Modelling qualityn/a
Mismatched charts errors808
Initial deposit1000.00SpreadCurrent (50)
Total net profit7795.40Gross profit9684.44Gross loss-1889.04
Profit factor5.13Expected payoff105.34
Absolute drawdown601.05Maximal drawdown714.05 (64.16%)Relative drawdown64.16% (714.05)
Total trades74Short positions (won %)39 (89.74%)Long positions (won %)35 (94.29%)
Profit trades (% of total)68 (91.89%)Loss trades (% of total)6 (8.11%)
Largestprofit trade439.57loss trade-409.05
Averageprofit trade142.42loss trade-314.84
Maximumconsecutive wins (profit in money)19 (2789.35)consecutive losses (loss in money)1 (-409.05)
Maximalconsecutive profit (count of wins)2789.35 (19)consecutive loss (count of losses)-409.05 (1)
Averageconsecutive wins11consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 09:30buy10.201842.370.001854.79
22020.12.07 10:38close10.201822.360.001854.79-409.05590.95
32021.01.06 02:00buy20.201950.700.001958.50
42021.01.06 12:00t/p20.201958.500.001958.50156.00746.95
52021.01.29 16:54sell30.201865.800.001855.99
62021.01.29 17:39t/p30.201855.990.001855.99196.20943.15
72021.02.09 17:45sell40.201841.990.001838.33
82021.02.09 18:09t/p40.201838.330.001838.3373.201016.35
92021.02.10 17:00sell50.201841.300.001827.41
102021.02.11 19:09t/p50.201827.410.001827.41290.171306.52
112021.02.16 17:09sell60.201804.040.001801.47
122021.02.16 18:49t/p60.201801.470.001801.4751.401357.92
132021.02.19 05:15buy70.201769.840.001786.37
142021.02.19 16:09t/p70.201786.370.001786.37330.601688.52
152021.03.03 16:51sell80.201712.530.001708.07
162021.03.03 17:36t/p80.201708.070.001708.0789.201777.72
172021.03.11 16:48buy90.201719.830.001727.97
182021.03.11 20:09t/p90.201727.970.001727.97162.801940.52
192021.03.17 13:48buy100.201728.270.001737.00
202021.03.17 20:06t/p100.201737.000.001737.00174.602115.12
212021.04.08 14:00buy110.201746.230.001756.37
222021.04.08 16:39t/p110.201756.370.001756.37202.802317.92
232021.04.19 15:15buy120.201775.830.001781.86
242021.04.21 04:39t/p120.201781.860.001781.86102.912420.83
252021.04.27 18:24buy130.201778.350.001784.35
262021.04.28 12:24close130.201763.350.001784.35-308.852111.98
272021.05.04 23:15sell140.201779.150.001777.35
282021.05.05 03:24t/p140.201777.350.001777.3540.122152.10
292021.05.10 17:45sell150.201839.580.001833.85
302021.05.11 03:39t/p150.201833.850.001833.85118.722270.83
312021.05.19 22:00buy160.201863.390.001881.95
322021.05.20 19:49t/p160.201881.950.001881.95344.662615.49
332021.06.18 08:45sell170.201784.490.001777.35
342021.06.18 15:52t/p170.201777.350.001777.35142.802758.29
352021.07.01 05:00buy180.201771.690.001788.94
362021.07.02 15:39t/p180.201788.940.001788.94336.153094.44
372021.07.06 19:07buy190.201794.010.001807.68
382021.07.07 13:24t/p190.201807.680.001807.68264.553359.00
392021.07.08 18:04buy200.201801.860.001814.59
402021.07.13 15:39t/p200.201814.590.001814.59228.063587.06
412021.07.13 17:21sell210.201811.750.001808.46
422021.07.13 20:34t/p210.201808.460.001808.4665.803652.86
432021.07.14 12:00buy220.201814.410.001822.33
442021.07.14 15:06t/p220.201822.330.001822.33158.403811.26
452021.08.17 17:15buy230.201782.610.001787.72
462021.08.18 04:09t/p230.201787.720.001787.7293.353904.61
472021.08.20 17:39sell240.201781.750.001777.75
482021.08.23 02:18t/p240.201777.750.001777.7584.123988.73
492021.08.26 13:45buy250.201787.160.001795.29
502021.08.26 18:04t/p250.201795.290.001795.29162.604151.33
512021.08.31 15:30sell260.201811.860.001809.11
522021.08.31 16:04t/p260.201809.110.001809.1155.004206.33
532021.10.21 09:45buy270.201786.660.001797.58
542021.10.22 15:22t/p270.201797.580.001797.58209.554415.89
552021.10.27 18:09sell280.201793.560.001789.11
562021.10.28 16:30close280.201808.560.001789.11-287.634128.25
572021.11.03 04:00sell290.201783.060.001779.26
582021.11.03 08:15t/p290.201779.260.001779.2676.004204.25
592021.11.30 17:48sell300.201794.770.001781.02
602021.11.30 18:04t/p300.201781.020.001781.02275.004479.25
612021.12.13 16:49sell310.201785.140.001782.99
622021.12.14 10:24t/p310.201782.990.001782.9947.124526.38
632021.12.15 04:45sell320.201771.980.001768.80
642021.12.15 07:39t/p320.201768.800.001768.8063.604589.98
652021.12.15 16:54sell330.201769.740.001766.01
662021.12.15 17:39t/p330.201766.010.001766.0174.604664.58
672021.12.20 17:01sell340.201793.800.001789.41
682021.12.20 22:09t/p340.201789.410.001789.4187.804752.38
692021.12.21 16:52buy350.201793.720.001796.76
702021.12.22 18:04t/p350.201796.760.001796.7651.954804.33
712022.01.18 18:19sell360.201813.030.001806.19
722022.01.19 16:52close360.201828.030.001806.19-295.884508.45
732022.02.09 11:30buy370.201827.780.001831.59
742022.02.09 15:09t/p370.201831.590.001831.5976.204584.65
752022.02.15 11:19buy380.201856.860.001866.95
762022.02.16 19:19t/p380.201866.950.001866.95192.954777.61
772022.02.18 17:33sell390.201895.770.001893.21
782022.02.18 17:37t/p390.201893.210.001893.2151.204828.81
792022.03.02 18:16sell400.201921.470.001907.56
802022.03.03 13:34close400.201936.470.001907.56-287.634541.17
812022.03.14 08:45sell410.201975.330.001973.05
822022.03.14 09:54t/p410.201973.050.001973.0545.604586.77
832022.04.22 19:22sell420.201936.790.001932.93
842022.04.22 20:28t/p420.201932.930.001932.9377.204663.97
852022.04.26 16:08sell430.201905.800.001905.21
862022.04.26 16:57t/p430.201905.210.001905.2111.804675.77
872022.06.10 16:01sell440.201839.900.001834.17
882022.06.10 16:18t/p440.201834.170.001834.17114.604790.37
892022.06.24 05:00sell450.201823.760.001819.89
902022.06.24 16:00t/p450.201819.890.001819.8977.404867.77
912022.07.20 16:52sell460.201708.520.001702.79
922022.07.20 19:48t/p460.201702.790.001702.79114.604982.37
932022.08.01 01:30buy470.201764.450.001772.37
942022.08.01 12:57t/p470.201772.370.001772.37158.405140.77
952022.08.02 18:02sell480.201776.930.001767.92
962022.08.02 21:02t/p480.201767.920.001767.92180.205320.97
972022.08.22 14:15buy490.201735.790.001742.63
982022.08.23 11:42t/p490.201742.630.001742.63127.955448.93
992022.09.05 04:45buy500.201711.680.001722.30
1002022.09.06 03:46t/p500.201722.300.001722.30203.555652.48
1012022.09.30 20:35buy510.201663.060.001667.30
1022022.10.03 04:30t/p510.201667.300.001667.3075.955728.43
1032022.11.02 21:03sell520.201647.760.001626.40
1042022.11.03 10:26t/p520.201626.400.001626.40439.576168.00
1052022.11.15 04:45buy530.201771.790.001782.62
1062022.11.15 09:47t/p530.201782.620.001782.62216.606384.60
1072022.11.21 20:30buy540.201738.310.001753.49
1082022.11.21 23:45buy550.201738.420.001742.35
1092022.11.22 03:06t/p550.201742.350.001742.3569.756454.35
1102022.11.24 02:26t/p540.201753.490.001753.49259.376713.72
1112022.11.30 10:00buy560.201755.410.001761.92
1122022.11.30 11:36t/p560.201761.920.001761.92130.206843.92
1132022.11.30 17:18buy570.201751.820.001763.12
1142022.11.30 21:20t/p570.201763.120.001763.12226.007069.92
1152022.12.09 17:23buy580.201791.160.001800.19
1162022.12.09 18:20t/p580.201800.190.001800.19180.607250.52
1172023.01.11 17:38buy590.201870.910.001874.91
1182023.01.11 19:21t/p590.201874.910.001874.9180.007330.52
1192023.01.12 17:10sell600.201884.680.001867.96
1202023.01.12 21:05close600.201899.680.001867.96-300.007030.52
1212023.01.20 09:00buy610.201926.840.001936.65
1222023.01.20 10:08t/p610.201936.650.001936.65196.207226.72
1232023.02.07 16:32sell620.201869.860.001868.93
1242023.02.07 16:45t/p620.201868.930.001868.9318.607245.32
1252023.02.09 17:00sell630.201879.160.001868.22
1262023.02.09 18:03t/p630.201868.220.001868.22218.807464.12
1272023.03.01 04:30buy640.201829.000.001845.23
1282023.03.02 20:35sell650.201835.870.001834.87
1292023.03.02 20:43t/p650.201834.870.001834.8720.007484.12
1302023.03.03 10:41t/p640.201845.230.001845.23289.227773.34
1312023.04.25 09:30buy660.201995.340.002008.12
1322023.04.26 16:27t/p660.202008.120.002008.12246.758020.09
1332023.04.26 19:17buy670.201988.970.001995.08
1342023.04.27 05:12t/p670.201995.080.001995.0895.668115.76
1352023.05.15 17:34sell680.202016.660.002011.32
1362023.05.16 09:04t/p680.202011.320.002011.32110.928226.68
1372023.05.26 17:09sell690.201951.200.001949.72
1382023.05.26 17:19t/p690.201949.720.001949.7229.608256.28
1392023.06.07 17:32sell700.201958.950.001947.93
1402023.06.07 18:50t/p700.201947.930.001947.93220.408476.68
1412023.07.04 17:45buy710.201928.490.001932.72
1422023.07.05 16:17t/p710.201932.720.001932.7275.758552.43
1432023.07.13 18:04sell720.201959.610.001957.54
1442023.07.13 18:51t/p720.201957.540.001957.5441.408593.83
1452023.07.19 18:12sell730.201974.940.001970.18
1462023.07.20 17:35t/p730.201970.180.001970.18107.578701.40
1472023.07.25 15:30sell740.201958.580.001953.88
1482023.07.25 17:00t/p740.201953.880.001953.8894.008795.40
+
diff --git a/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.4. - 2000$.gif b/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.4. - 2000$.gif new file mode 100644 index 0000000..5c72c27 Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.4. - 2000$.gif differ diff --git a/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.4. - 2000$.htm b/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.4. - 2000$.htm new file mode 100644 index 0000000..68d4af1 --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.4. - 2000$.htm @@ -0,0 +1,223 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.23 17:30 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.0002; xShortMaxDrawdownPerTradePercent=0.4; xLongR2R=3; xLongLotsPerTradePercent=0.0002; xLongMaxDrawdownPerTradePercent=0.4; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +enableXRLong=true; +enableXRShort=true; +xRShortR2R=1.5; xRShortLotsPerTradePercent=0.0002; xRShortMaxDrawdownPerTradePercent=0.15; xRLongR2R=1.5; xRLongLotsPerTradePercent=0.0002; xRLongMaxDrawdownPerTradePercent=0.15; xRMaximumCandlesPerTrade=96; xRSwingLength=48; xRSharpDetectionFactor=1350; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.0002; xTPWShortMaxDrawdownPerTradePercent=0.3; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.0002; xTPWLongMaxDrawdownPerTradePercent=0.3; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63774Ticks modelled73094491Modelling qualityn/a
Mismatched charts errors1102
Initial deposit2000.00SpreadCurrent (48)
Total net profit15560.04Gross profit19323.70Gross loss-3763.66
Profit factor5.13Expected payoff210.27
Absolute drawdown1204.19Maximal drawdown1430.99 (64.26%)Relative drawdown64.26% (1430.99)
Total trades74Short positions (won %)39 (89.74%)Long positions (won %)35 (94.29%)
Profit trades (% of total)68 (91.89%)Loss trades (% of total)6 (8.11%)
Largestprofit trade887.80loss trade-820.99
Averageprofit trade284.17loss trade-627.28
Maximumconsecutive wins (profit in money)19 (5563.67)consecutive losses (loss in money)1 (-820.99)
Maximalconsecutive profit (count of wins)5563.67 (19)consecutive loss (count of losses)-820.99 (1)
Averageconsecutive wins11consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 09:30buy10.401842.350.001854.77
22020.12.07 10:38close10.401822.340.001854.77-820.991179.01
32021.01.06 02:00buy20.401950.680.001958.48
42021.01.06 12:00t/p20.401958.480.001958.48312.001491.01
52021.01.29 16:54sell30.401865.800.001855.99
62021.01.29 17:39t/p30.401855.990.001855.99392.401883.41
72021.02.09 17:45sell40.401841.990.001838.33
82021.02.09 18:09t/p40.401838.330.001838.33146.402029.81
92021.02.10 17:00sell50.401841.300.001827.41
102021.02.11 19:09t/p50.401827.410.001827.41589.002618.80
112021.02.16 17:09sell60.401804.040.001801.47
122021.02.16 18:49t/p60.401801.470.001801.47102.802721.60
132021.02.19 05:15buy70.401769.820.001786.35
142021.02.19 16:09t/p70.401786.350.001786.35661.203382.80
152021.03.03 16:51sell80.401712.530.001708.07
162021.03.03 17:36t/p80.401708.070.001708.07178.403561.20
172021.03.11 16:48buy90.401719.810.001727.96
182021.03.11 20:09t/p90.401727.960.001727.96326.003887.20
192021.03.17 13:48buy100.401728.250.001737.00
202021.03.17 20:06t/p100.401737.000.001737.00350.004237.20
212021.04.08 14:00buy110.401746.210.001756.35
222021.04.08 16:39t/p110.401756.350.001756.35405.604642.80
232021.04.19 15:15buy120.401775.810.001781.85
242021.04.21 04:39t/p120.401781.850.001781.85200.424843.22
252021.04.27 18:24buy130.401778.330.001781.34
262021.04.28 12:24close130.401763.330.001781.34-620.594222.63
272021.05.04 23:15sell140.401779.150.001777.35
282021.05.05 03:24t/p140.401777.350.001777.3583.134305.76
292021.05.10 17:45sell150.401839.580.001833.85
302021.05.11 03:39t/p150.401833.850.001833.85240.334546.09
312021.05.19 22:00buy160.401863.370.001881.95
322021.05.20 19:49t/p160.401881.950.001881.95681.425227.52
332021.06.18 08:45sell170.401784.490.001777.35
342021.06.18 15:52t/p170.401777.350.001777.35285.605513.12
352021.07.01 05:00buy180.401771.670.001788.92
362021.07.02 15:39t/p180.401788.920.001788.92669.416182.52
372021.07.06 19:07buy190.401793.990.001807.68
382021.07.07 13:24t/p190.401807.680.001807.68527.016709.53
392021.07.08 18:04buy200.401801.840.001814.59
402021.07.13 15:39t/p200.401814.590.001814.59448.227157.76
412021.07.13 17:21sell210.401811.750.001808.46
422021.07.13 20:18t/p210.401808.460.001808.46131.607289.36
432021.07.14 12:00buy220.401814.390.001822.31
442021.07.14 15:06t/p220.401822.310.001822.31316.807606.16
452021.08.17 17:15buy230.401782.590.001787.71
462021.08.18 04:09t/p230.401787.710.001787.71184.217790.36
472021.08.20 17:39sell240.401781.750.001777.75
482021.08.23 02:18t/p240.401777.750.001777.75171.137961.50
492021.08.26 13:45buy250.401787.140.001795.27
502021.08.26 18:04t/p250.401795.270.001795.27325.208286.70
512021.08.31 15:30sell260.401811.860.001809.11
522021.08.31 16:04t/p260.401809.110.001809.11110.008396.70
532021.10.21 09:45buy270.401786.640.001797.56
542021.10.22 15:22t/p270.401797.560.001797.56416.218812.90
552021.10.27 18:09sell280.401793.560.001789.11
562021.10.28 16:30close280.401808.560.001789.11-566.608246.30
572021.11.03 04:00sell290.401783.060.001779.26
582021.11.03 08:15t/p290.401779.260.001779.26152.008398.30
592021.11.30 17:48sell300.401794.770.001781.02
602021.11.30 18:04t/p300.401781.020.001781.02550.008948.30
612021.12.13 16:49sell310.401785.140.001782.99
622021.12.14 10:24t/p310.401782.990.001782.9997.139045.43
632021.12.15 04:45sell320.401771.980.001768.80
642021.12.15 07:39t/p320.401768.800.001768.80127.209172.63
652021.12.15 16:54sell330.401769.740.001766.01
662021.12.15 17:39t/p330.401766.010.001766.01149.209321.83
672021.12.20 17:01sell340.401793.800.001789.41
682021.12.20 22:09t/p340.401789.410.001789.41175.609497.43
692021.12.21 16:52buy350.401793.700.001796.75
702021.12.22 18:04t/p350.401796.750.001796.75101.419598.84
712022.01.18 18:19sell360.401813.030.001806.19
722022.01.19 16:52close360.401828.030.001806.19-588.879009.97
732022.02.09 11:30buy370.401827.760.001831.57
742022.02.09 15:09t/p370.401831.570.001831.57152.409162.37
752022.02.15 11:19buy380.401856.840.001866.94
762022.02.16 19:10t/p380.401866.940.001866.94383.419545.78
772022.02.18 17:33sell390.401895.770.001893.21
782022.02.18 17:37t/p390.401893.210.001893.21102.409648.18
792022.03.02 18:16sell400.401921.470.001907.56
802022.03.03 13:34close400.401936.470.001907.56-566.609081.58
812022.03.14 08:45sell410.401975.330.001973.05
822022.03.14 09:54t/p410.401973.050.001973.0591.209172.78
832022.04.22 19:22sell420.401936.790.001932.93
842022.04.22 20:28t/p420.401932.930.001932.93154.409327.18
852022.04.26 16:08sell430.401905.800.001905.21
862022.04.26 16:57t/p430.401905.210.001905.2123.609350.78
872022.06.10 16:01sell440.401839.900.001834.17
882022.06.10 16:18t/p440.401834.170.001834.17229.209579.98
892022.06.24 05:00sell450.401823.760.001819.89
902022.06.24 16:00t/p450.401819.890.001819.89154.809734.78
912022.07.20 16:52sell460.401708.520.001702.79
922022.07.20 19:48t/p460.401702.790.001702.79229.209963.98
932022.08.01 01:30buy470.401764.430.001772.35
942022.08.01 12:57t/p470.401772.350.001772.35316.8010280.78
952022.08.02 18:02sell480.401776.930.001767.92
962022.08.02 21:02t/p480.401767.920.001767.92360.4010641.18
972022.08.22 14:15buy490.401735.770.001742.61
982022.08.23 11:42t/p490.401742.610.001742.61253.0110894.18
992022.09.05 04:45buy500.401711.660.001722.28
1002022.09.06 03:46t/p500.401722.280.001722.28404.2111298.39
1012022.09.30 20:35buy510.401663.040.001667.29
1022022.10.03 04:30t/p510.401667.290.001667.29149.4111447.80
1032022.11.02 21:03sell520.401647.760.001626.40
1042022.11.03 10:26t/p520.401626.400.001626.40887.8012335.60
1052022.11.15 04:45buy530.401771.770.001782.60
1062022.11.15 09:47t/p530.401782.600.001782.60433.2012768.80
1072022.11.21 20:30buy540.401738.290.001753.47
1082022.11.21 23:45buy550.401738.400.001742.33
1092022.11.22 03:06t/p550.401742.330.001742.33136.6112905.40
1102022.11.24 02:26t/p540.401753.470.001753.47504.2413409.64
1112022.11.30 10:00buy560.401755.390.001761.90
1122022.11.30 11:36t/p560.401761.900.001761.90260.4013670.04
1132022.11.30 17:18buy570.401751.800.001763.12
1142022.11.30 21:20t/p570.401763.120.001763.12452.8014122.84
1152022.12.09 17:23buy580.401791.140.001800.19
1162022.12.09 18:20t/p580.401800.190.001800.19362.0014484.84
1172023.01.11 17:38buy590.401870.890.001874.90
1182023.01.11 19:16t/p590.401874.900.001874.90160.4014645.24
1192023.01.12 17:10sell600.401884.680.001867.96
1202023.01.12 21:05close600.401899.680.001867.96-600.0014045.24
1212023.01.20 09:00buy610.401926.820.001936.63
1222023.01.20 10:08t/p610.401936.630.001936.63392.4014437.64
1232023.02.07 16:32sell620.401869.860.001868.93
1242023.02.07 16:45t/p620.401868.930.001868.9337.2014474.84
1252023.02.09 17:00sell630.401879.160.001868.22
1262023.02.09 18:03t/p630.401868.220.001868.22437.6014912.44
1272023.03.01 04:30buy640.401828.980.001845.21
1282023.03.02 20:35sell650.401835.870.001834.89
1292023.03.02 20:43t/p650.401834.890.001834.8939.2014951.64
1302023.03.03 10:41t/p640.401845.210.001845.21566.8315518.48
1312023.04.25 09:30buy660.401995.320.002008.10
1322023.04.26 16:27t/p660.402008.100.002008.10490.6116009.08
1332023.04.26 19:17buy670.401988.950.001995.07
1342023.04.27 05:12t/p670.401995.070.001995.07183.0216192.11
1352023.05.15 17:34sell680.402016.660.002011.32
1362023.05.16 09:04t/p680.402011.320.002011.32224.7316416.84
1372023.05.26 17:09sell690.401951.200.001949.72
1382023.05.26 17:19t/p690.401949.720.001949.7259.2016476.04
1392023.06.07 17:32sell700.401958.950.001947.93
1402023.06.07 18:50t/p700.401947.930.001947.93440.8016916.84
1412023.07.04 17:45buy710.401928.470.001932.70
1422023.07.05 16:17t/p710.401932.700.001932.70148.6117065.45
1432023.07.13 18:04sell720.401959.610.001957.54
1442023.07.13 18:51t/p720.401957.540.001957.5482.8017148.25
1452023.07.19 18:12sell730.401974.940.001970.18
1462023.07.20 17:35t/p730.401970.180.001970.18223.8017372.04
1472023.07.25 15:30sell740.401958.580.001953.88
1482023.07.25 17:00t/p740.401953.880.001953.88188.0017560.04
+
diff --git a/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.4. - 2000$.pdf b/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.4. - 2000$.pdf new file mode 100644 index 0000000..106e21b Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.4. - 2000$.pdf differ diff --git a/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.75. - 3000$.gif b/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.75. - 3000$.gif new file mode 100644 index 0000000..3fae07b Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.75. - 3000$.gif differ diff --git a/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.75. - 3000$.htm b/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.75. - 3000$.htm new file mode 100644 index 0000000..d64361d --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.75. - 3000$.htm @@ -0,0 +1,227 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.23 18:45 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00025; xShortMaxDrawdownPerTradePercent=0.45; xLongR2R=3; xLongLotsPerTradePercent=0.00025; xLongMaxDrawdownPerTradePercent=0.45; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +enableXRLong=true; +enableXRShort=true; +xRShortR2R=1.5; xRShortLotsPerTradePercent=0.0002; xRShortMaxDrawdownPerTradePercent=0.15; xRLongR2R=1.5; xRLongLotsPerTradePercent=0.0002; xRLongMaxDrawdownPerTradePercent=0.15; xRMaximumCandlesPerTrade=96; xRSwingLength=48; xRSharpDetectionFactor=1350; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00025; xTPWShortMaxDrawdownPerTradePercent=0.3; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00025; xTPWLongMaxDrawdownPerTradePercent=0.3; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test64805Ticks modelled74347108Modelling qualityn/a
Mismatched charts errors908
Initial deposit3000.00SpreadCurrent (48)
Total net profit23928.07Gross profit34457.02Gross loss-10528.94
Profit factor3.27Expected payoff314.84
Absolute drawdown2107.86Maximal drawdown2667.00 (15.33%)Relative drawdown73.95% (2533.11)
Total trades76Short positions (won %)39 (87.18%)Long positions (won %)37 (83.78%)
Profit trades (% of total)65 (85.53%)Loss trades (% of total)11 (14.47%)
Largestprofit trade1664.62loss trade-1389.36
Averageprofit trade530.11loss trade-957.18
Maximumconsecutive wins (profit in money)19 (10431.88)consecutive losses (loss in money)1 (-1389.36)
Maximalconsecutive profit (count of wins)10431.88 (19)consecutive loss (count of losses)-1389.36 (1)
Averageconsecutive wins7consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 09:30buy10.751842.350.001854.77
22020.12.07 10:37close10.751824.340.001854.77-1389.361610.64
32021.01.06 02:00buy20.751950.680.001958.48
42021.01.06 12:00t/p20.751958.480.001958.48585.002195.64
52021.01.29 16:54sell30.751865.800.001855.99
62021.01.29 17:39t/p30.751855.990.001855.99735.752931.39
72021.02.09 17:45sell40.751841.990.001838.33
82021.02.09 18:09t/p40.751838.330.001838.33274.503205.89
92021.02.10 17:00sell50.751841.300.001827.41
102021.02.11 19:09t/p50.751827.410.001827.411104.374310.26
112021.02.16 17:09sell60.751804.040.001801.47
122021.02.16 18:49t/p60.751801.470.001801.47192.754503.01
132021.02.19 05:15buy70.751769.820.001786.35
142021.02.19 16:09t/p70.751786.350.001786.351239.755742.76
152021.03.03 16:51sell80.751712.530.001708.07
162021.03.03 17:36t/p80.751708.070.001708.07334.506077.26
172021.03.11 16:48buy90.751719.810.001727.96
182021.03.11 20:09t/p90.751727.960.001727.96611.256688.51
192021.03.17 13:48buy100.751728.250.001737.00
202021.03.17 20:06t/p100.751737.000.001737.00656.257344.76
212021.04.08 14:00buy110.751746.210.001756.35
222021.04.08 16:39t/p110.751756.350.001756.35760.508105.26
232021.04.19 15:15buy120.751775.810.001781.85
242021.04.20 12:39close120.751763.810.001781.85-938.617166.65
252021.04.21 04:30buy130.751779.790.001788.58
262021.04.21 16:39t/p130.751788.580.001788.58659.257825.90
272021.04.27 18:24buy140.751778.330.001781.34
282021.04.28 04:33close140.751766.330.001781.34-938.616887.29
292021.05.04 23:15sell150.751779.150.001777.35
302021.05.05 03:24t/p150.751777.350.001777.35155.877043.16
312021.05.10 17:45sell160.751839.580.001833.85
322021.05.11 03:39t/p160.751833.850.001833.85450.627493.78
332021.05.19 22:00buy170.751863.370.001881.95
342021.05.20 19:49t/p170.751881.950.001881.951277.678771.45
352021.06.18 08:45sell180.751784.490.001777.35
362021.06.18 15:52t/p180.751777.350.001777.35535.509306.95
372021.07.01 05:00buy190.751771.670.001788.92
382021.07.02 15:39t/p190.751788.920.001788.921255.1410562.09
392021.07.06 19:07buy200.751793.990.001807.68
402021.07.07 13:24t/p200.751807.680.001807.68988.1411550.23
412021.07.08 18:04buy210.751801.840.001814.59
422021.07.13 15:39t/p210.751814.590.001814.59840.4212390.65
432021.07.13 17:21sell220.751811.750.001808.46
442021.07.13 20:18t/p220.751808.460.001808.46246.7512637.40
452021.07.14 12:00buy230.751814.390.001822.31
462021.07.14 15:06t/p230.751822.310.001822.31594.0013231.40
472021.08.17 17:15buy240.751782.590.001787.71
482021.08.18 04:09t/p240.751787.710.001787.71345.3913576.79
492021.08.20 17:39sell250.751781.750.001777.75
502021.08.23 02:18t/p250.751777.750.001777.75320.8713897.67
512021.08.26 13:45buy260.751787.140.001795.27
522021.08.26 18:04t/p260.751795.270.001795.27609.7514507.42
532021.08.31 15:30sell270.751811.860.001809.11
542021.08.31 16:04t/p270.751809.110.001809.11206.2514713.67
552021.10.21 09:45buy280.751786.640.001797.56
562021.10.22 15:22t/p280.751797.560.001797.56780.3915494.06
572021.10.27 18:09sell290.751793.560.001789.11
582021.10.28 15:22close290.751805.560.001789.11-837.3814656.67
592021.11.03 04:00sell300.751783.060.001779.26
602021.11.03 08:15t/p300.751779.260.001779.26285.0014941.67
612021.11.30 17:48sell310.751794.770.001781.02
622021.11.30 18:04t/p310.751781.020.001781.021031.2515972.92
632021.12.13 16:49sell320.751785.140.001782.99
642021.12.14 10:24t/p320.751782.990.001782.99182.1216155.05
652021.12.15 04:45sell330.751771.980.001768.80
662021.12.15 07:39t/p330.751768.800.001768.80238.5016393.54
672021.12.15 16:54sell340.751769.740.001766.01
682021.12.15 17:39t/p340.751766.010.001766.01279.7516673.29
692021.12.20 17:01sell350.751793.800.001789.41
702021.12.20 22:09t/p350.751789.410.001789.41329.2517002.54
712021.12.21 16:52buy360.751793.700.001796.75
722021.12.22 18:04t/p360.751796.750.001796.75190.1417192.68
732022.01.18 18:19sell370.751813.030.001806.19
742022.01.19 15:31close370.751825.030.001806.19-879.1316313.56
752022.02.09 11:30buy380.751827.760.001831.57
762022.02.09 15:09t/p380.751831.570.001831.57285.7516599.31
772022.02.15 11:19buy390.751856.840.001866.94
782022.02.15 14:24close390.751844.830.001866.94-900.7515698.56
792022.02.18 17:33sell400.751895.770.001893.21
802022.02.18 17:37t/p400.751893.210.001893.21192.0015890.56
812022.03.02 18:16sell410.751921.470.001907.56
822022.03.02 22:09close410.751933.480.001907.56-900.7514989.81
832022.03.14 08:45sell420.751975.330.001973.05
842022.03.14 09:54t/p420.751973.050.001973.05171.0015160.81
852022.04.22 19:22sell430.751936.790.001932.93
862022.04.22 20:28t/p430.751932.930.001932.93289.5015450.31
872022.04.26 16:08sell440.751905.800.001905.21
882022.04.26 16:57t/p440.751905.210.001905.2144.2515494.56
892022.06.10 16:01sell450.751839.900.001834.17
902022.06.10 16:18t/p450.751834.170.001834.17429.7515924.31
912022.06.24 05:00sell460.751823.760.001819.89
922022.06.24 16:00t/p460.751819.890.001819.89290.2516214.56
932022.07.20 16:52sell470.751708.520.001702.79
942022.07.20 19:48t/p470.751702.790.001702.79429.7516644.31
952022.08.01 01:30buy480.751764.430.001772.35
962022.08.01 12:57t/p480.751772.350.001772.35594.0017238.31
972022.08.02 18:02sell490.751776.930.001767.92
982022.08.02 21:02t/p490.751767.920.001767.92675.7517914.06
992022.08.22 14:15buy500.751735.770.001742.61
1002022.08.23 11:42t/p500.751742.610.001742.61474.3918388.45
1012022.09.05 04:45buy510.751711.660.001722.28
1022022.09.06 03:46t/p510.751722.280.001722.28757.8919146.34
1032022.09.30 20:35buy520.751663.040.001667.29
1042022.10.03 04:30t/p520.751667.290.001667.29280.1419426.48
1052022.11.02 21:03sell530.751647.760.001626.40
1062022.11.03 10:26t/p530.751626.400.001626.401664.6221091.09
1072022.11.15 04:45buy540.751771.770.001782.60
1082022.11.15 09:47t/p540.751782.600.001782.60812.2521903.34
1092022.11.21 20:30buy550.751738.290.001753.47
1102022.11.21 23:45buy560.751738.400.001742.33
1112022.11.22 03:06t/p560.751742.330.001742.33256.1422159.48
1122022.11.24 02:26t/p550.751753.470.001753.47945.4523104.93
1132022.11.30 10:00buy570.751755.390.001761.90
1142022.11.30 11:36t/p570.751761.900.001761.90488.2523593.18
1152022.11.30 17:18buy580.751751.800.001763.12
1162022.11.30 21:20t/p580.751763.120.001763.12849.0024442.18
1172022.12.09 17:23buy590.751791.140.001800.19
1182022.12.09 18:20t/p590.751800.190.001800.19678.7525120.93
1192023.01.11 17:38buy600.751870.890.001874.90
1202023.01.11 19:16t/p600.751874.900.001874.90300.7525421.68
1212023.01.12 17:10sell610.751884.680.001867.96
1222023.01.12 19:28close610.751896.680.001867.96-900.0024521.68
1232023.01.20 09:00buy620.751926.820.001936.63
1242023.01.20 10:08t/p620.751936.630.001936.63735.7525257.43
1252023.02.07 16:32sell630.751869.860.001868.93
1262023.02.07 16:45t/p630.751868.930.001868.9369.7525327.18
1272023.02.09 17:00sell640.751879.160.001868.22
1282023.02.09 18:03t/p640.751868.220.001868.22820.5026147.68
1292023.03.01 04:30buy650.751828.980.001845.21
1302023.03.02 20:35sell660.751835.870.001834.89
1312023.03.02 20:43t/p660.751834.890.001834.8973.5026221.18
1322023.03.03 10:41t/p650.751845.210.001845.211062.8127283.99
1332023.04.25 09:30buy670.751995.320.002008.10
1342023.04.25 14:57close670.751977.310.002008.10-1350.7525933.24
1352023.04.26 19:17buy680.751988.950.001995.07
1362023.04.27 05:12t/p680.751995.070.001995.07343.1726276.41
1372023.05.15 17:34sell690.752016.660.002011.32
1382023.05.16 09:04t/p690.752011.320.002011.32421.3726697.79
1392023.05.26 17:09sell700.751951.200.001949.72
1402023.05.26 17:19t/p700.751949.720.001949.72111.0026808.79
1412023.06.07 17:32sell710.751958.950.001947.93
1422023.06.07 18:50t/p710.751947.930.001947.93826.5027635.29
1432023.07.04 17:45buy720.751928.470.001932.70
1442023.07.05 16:17t/p720.751932.700.001932.70278.6427913.93
1452023.07.13 18:04sell730.751959.610.001957.54
1462023.07.13 18:51t/p730.751957.540.001957.54155.2528069.18
1472023.07.19 18:12sell740.751974.940.001970.18
1482023.07.20 06:09close740.751986.950.001970.18-838.1327231.04
1492023.07.25 15:30sell750.751958.580.001953.88
1502023.07.25 17:00t/p750.751953.880.001953.88352.5027583.54
1512023.08.14 06:15buy760.751912.540.001917.46
1522023.08.16 11:45close760.751904.830.001917.46-655.4726928.07
+
diff --git a/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.75. - 3000$.pdf b/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.75. - 3000$.pdf new file mode 100644 index 0000000..77789fe Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full - 0.75. - 3000$.pdf differ diff --git a/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full.gif b/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full.gif new file mode 100644 index 0000000..b8382b5 Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full.gif differ diff --git a/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full.htm b/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full.htm new file mode 100644 index 0000000..c78b557 --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/StrategyTester X (XXX and XTPW) Full.htm @@ -0,0 +1,227 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.01 23:45 (2020.01.01 - 2023.08.02)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +enableXRLong=true; +enableXRShort=true; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63353Ticks modelled72601176Modelling qualityn/a
Mismatched charts errors808
Initial deposit1000.00SpreadCurrent (51)
Total net profit410.10Gross profit504.55Gross loss-94.45
Profit factor5.34Expected payoff5.40
Absolute drawdown18.44Maximal drawdown26.23 (2.16%)Relative drawdown2.39% (24.08)
Total trades76Short positions (won %)40 (90.00%)Long positions (won %)36 (94.44%)
Profit trades (% of total)70 (92.11%)Loss trades (% of total)6 (7.89%)
Largestprofit trade21.98loss trade-20.44
Averageprofit trade7.21loss trade-15.74
Maximumconsecutive wins (profit in money)19 (139.44)consecutive losses (loss in money)1 (-20.44)
Maximalconsecutive profit (count of wins)139.44 (19)consecutive loss (count of losses)-20.44 (1)
Averageconsecutive wins10consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 09:30buy10.011842.380.001854.80
22020.12.04 17:39sell20.011836.610.001825.20
32020.12.07 10:37t/p20.011825.200.001825.2011.621011.62
42020.12.07 10:38close10.011822.380.001854.80-20.44991.17
52021.01.06 02:00buy30.011950.710.001958.51
62021.01.06 12:00t/p30.011958.510.001958.517.80998.97
72021.01.29 16:54sell40.011865.800.001855.99
82021.01.29 17:39t/p40.011855.990.001855.999.811008.78
92021.02.09 17:45sell50.011841.990.001838.33
102021.02.09 18:09t/p50.011838.330.001838.333.661012.44
112021.02.10 17:00sell60.011841.300.001827.41
122021.02.11 19:09t/p60.011827.410.001827.4114.511026.95
132021.02.16 17:09sell70.011804.040.001801.47
142021.02.16 18:49t/p70.011801.470.001801.472.571029.52
152021.02.19 05:15buy80.011769.850.001786.38
162021.02.19 16:09t/p80.011786.380.001786.3816.531046.05
172021.03.03 16:51sell90.011712.530.001708.07
182021.03.03 17:36t/p90.011708.070.001708.074.461050.51
192021.03.11 16:48buy100.011719.840.001727.97
202021.03.11 20:09t/p100.011727.970.001727.978.131058.64
212021.03.17 13:48buy110.011728.280.001737.00
222021.03.17 20:06t/p110.011737.000.001737.008.721067.36
232021.04.08 14:00buy120.011746.240.001756.38
242021.04.08 16:39t/p120.011756.380.001756.3810.141077.50
252021.04.19 15:15buy130.011775.840.001781.87
262021.04.21 04:30buy140.011779.820.001788.61
272021.04.21 04:39t/p130.011781.870.001781.875.151082.65
282021.04.21 16:39t/p140.011788.610.001788.618.791091.44
292021.04.27 18:24buy150.011778.360.001784.35
302021.04.28 12:24close150.011763.360.001784.35-15.441076.00
312021.05.04 23:15sell160.011779.150.001777.35
322021.05.05 03:24t/p160.011777.350.001777.352.011078.00
332021.05.10 17:45sell170.011839.580.001833.85
342021.05.11 03:39t/p170.011833.850.001833.855.941083.94
352021.05.19 22:00buy180.011863.400.001881.95
362021.05.20 19:49t/p180.011881.950.001881.9517.221101.16
372021.06.18 08:45sell190.011784.490.001777.35
382021.06.18 15:52t/p190.011777.350.001777.357.141108.30
392021.07.01 05:00buy200.011771.700.001788.95
402021.07.02 15:39t/p200.011788.950.001788.9516.811125.11
412021.07.06 19:07buy210.011794.020.001807.68
422021.07.07 13:24t/p210.011807.680.001807.6813.221138.33
432021.07.08 18:04buy220.011801.870.001814.59
442021.07.13 15:39t/p220.011814.590.001814.5911.391149.72
452021.07.13 17:21sell230.011811.750.001808.46
462021.07.13 20:34t/p230.011808.460.001808.463.291153.01
472021.07.14 12:00buy240.011814.420.001822.34
482021.07.14 15:06t/p240.011822.340.001822.347.921160.93
492021.08.17 17:15buy250.011782.620.001787.73
502021.08.18 04:09t/p250.011787.730.001787.734.671165.60
512021.08.20 17:39sell260.011781.750.001777.75
522021.08.23 02:18t/p260.011777.750.001777.754.211169.80
532021.08.26 13:45buy270.011787.170.001795.30
542021.08.26 18:04t/p270.011795.300.001795.308.131177.93
552021.08.31 15:30sell280.011811.860.001809.11
562021.08.31 16:04t/p280.011809.110.001809.112.751180.68
572021.10.21 09:45buy290.011786.670.001797.59
582021.10.22 15:22t/p290.011797.590.001797.5910.481191.16
592021.10.27 18:09sell300.011793.560.001789.11
602021.10.28 16:30close300.011808.560.001789.11-14.381176.78
612021.11.03 04:00sell310.011783.060.001779.26
622021.11.03 08:15t/p310.011779.260.001779.263.801180.58
632021.11.30 17:48sell320.011794.770.001781.02
642021.11.30 18:04t/p320.011781.020.001781.0213.751194.33
652021.12.13 16:49sell330.011785.140.001782.99
662021.12.14 10:24t/p330.011782.990.001782.992.361196.68
672021.12.15 04:45sell340.011771.980.001768.80
682021.12.15 07:39t/p340.011768.800.001768.803.181199.86
692021.12.15 16:54sell350.011769.740.001766.01
702021.12.15 17:39t/p350.011766.010.001766.013.731203.59
712021.12.20 17:01sell360.011793.800.001789.41
722021.12.20 22:09t/p360.011789.410.001789.414.391207.98
732021.12.21 16:52buy370.011793.730.001796.76
742021.12.22 18:04t/p370.011796.760.001796.762.591210.57
752022.01.18 18:19sell380.011813.030.001806.19
762022.01.19 16:52close380.011828.030.001806.19-14.791195.78
772022.02.09 11:30buy390.011827.790.001831.60
782022.02.09 15:09t/p390.011831.600.001831.603.811199.59
792022.02.15 11:19buy400.011856.870.001866.96
802022.02.16 19:19t/p400.011866.960.001866.969.651209.24
812022.02.18 17:33sell410.011895.770.001893.21
822022.02.18 17:37t/p410.011893.210.001893.212.561211.80
832022.03.02 18:16sell420.011921.470.001907.56
842022.03.03 13:34close420.011936.480.001907.56-14.391197.40
852022.03.14 08:45sell430.011975.330.001973.05
862022.03.14 09:54t/p430.011973.050.001973.052.281199.68
872022.04.22 19:22sell440.011936.790.001932.93
882022.04.22 20:28t/p440.011932.930.001932.933.861203.54
892022.04.26 16:08sell450.011905.800.001905.21
902022.04.26 16:57t/p450.011905.210.001905.210.591204.13
912022.06.10 16:01sell460.011839.900.001834.17
922022.06.10 16:18t/p460.011834.170.001834.175.731209.86
932022.06.24 05:00sell470.011823.760.001819.89
942022.06.24 16:00t/p470.011819.890.001819.893.871213.73
952022.07.20 16:52sell480.011708.520.001702.79
962022.07.20 19:48t/p480.011702.790.001702.795.731219.46
972022.08.01 01:30buy490.011764.460.001772.38
982022.08.01 12:57t/p490.011772.380.001772.387.921227.38
992022.08.02 18:02sell500.011776.930.001767.92
1002022.08.02 21:02t/p500.011767.920.001767.929.011236.39
1012022.08.22 14:15buy510.011735.800.001742.64
1022022.08.23 11:42t/p510.011742.640.001742.646.401242.79
1032022.09.05 04:45buy520.011711.690.001722.31
1042022.09.06 03:46t/p520.011722.310.001722.3110.181252.97
1052022.09.30 20:35buy530.011663.070.001667.31
1062022.10.03 04:30t/p530.011667.310.001667.313.801256.77
1072022.11.02 21:03sell540.011647.760.001626.40
1082022.11.03 10:26t/p540.011626.400.001626.4021.981278.75
1092022.11.15 04:45buy550.011771.800.001782.63
1102022.11.15 09:47t/p550.011782.630.001782.6310.831289.58
1112022.11.21 20:30buy560.011738.320.001753.50
1122022.11.21 23:45buy570.011738.430.001742.36
1132022.11.22 03:06t/p570.011742.360.001742.363.491293.06
1142022.11.24 02:26t/p560.011753.500.001753.5012.971306.03
1152022.11.30 10:00buy580.011755.420.001761.93
1162022.11.30 11:36t/p580.011761.930.001761.936.511312.54
1172022.11.30 17:18buy590.011751.830.001763.12
1182022.11.30 21:20t/p590.011763.120.001763.1211.291323.83
1192022.12.09 17:23buy600.011791.170.001800.19
1202022.12.09 18:20t/p600.011800.190.001800.199.021332.85
1212023.01.11 17:38buy610.011870.920.001874.91
1222023.01.11 19:21t/p610.011874.910.001874.913.991336.84
1232023.01.12 17:10sell620.011884.680.001867.96
1242023.01.12 21:05close620.011899.680.001867.96-15.001321.84
1252023.01.20 09:00buy630.011926.850.001936.66
1262023.01.20 10:08t/p630.011936.660.001936.669.811331.65
1272023.02.07 16:32sell640.011869.860.001868.93
1282023.02.07 16:45t/p640.011868.930.001868.930.931332.58
1292023.02.09 17:00sell650.011879.160.001868.22
1302023.02.09 18:03t/p650.011868.220.001868.2210.941343.52
1312023.03.01 04:30buy660.011829.010.001845.24
1322023.03.02 20:35sell670.011835.870.001834.86
1332023.03.02 20:43t/p670.011834.860.001834.861.011344.53
1342023.03.03 10:41t/p660.011845.240.001845.2414.461358.99
1352023.04.25 09:30buy680.011995.350.002008.13
1362023.04.26 16:27t/p680.012008.130.002008.1312.341371.33
1372023.04.26 19:17buy690.011988.980.001995.09
1382023.04.27 05:12t/p690.011995.090.001995.094.781376.11
1392023.05.15 17:34sell700.012016.660.002011.32
1402023.05.16 09:04t/p700.012011.320.002011.325.551381.66
1412023.05.26 17:09sell710.011951.200.001949.72
1422023.05.26 17:19t/p710.011949.720.001949.721.481383.14
1432023.06.07 17:32sell720.011958.950.001947.93
1442023.06.07 18:50t/p720.011947.930.001947.9311.021394.16
1452023.07.04 17:45buy730.011928.500.001932.73
1462023.07.05 16:17t/p730.011932.730.001932.733.791397.95
1472023.07.13 18:04sell740.011959.610.001957.54
1482023.07.13 18:51t/p740.011957.540.001957.542.071400.02
1492023.07.19 18:12sell750.011974.940.001970.18
1502023.07.20 17:35t/p750.011970.180.001970.185.381405.40
1512023.07.25 15:30sell760.011958.580.001953.88
1522023.07.25 17:00t/p760.011953.880.001953.884.701410.10
+
diff --git a/Packed/XAUUSD-15M/Reports/X/Long/StrategyTester.gif b/Packed/XAUUSD-15M/Reports/X/Long/StrategyTester.gif new file mode 100644 index 0000000..bb981a8 Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/X/Long/StrategyTester.gif differ diff --git a/Packed/XAUUSD-15M/Reports/X/Long/StrategyTester.htm b/Packed/XAUUSD-15M/Reports/X/Long/StrategyTester.htm new file mode 100644 index 0000000..692fc34 --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/X/Long/StrategyTester.htm @@ -0,0 +1,111 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.01 23:45 (2020.01.01 - 2023.08.02)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63353Ticks modelled72601176Modelling qualityn/a
Mismatched charts errors808
Initial deposit1000.00SpreadCurrent (60)
Total net profit167.90Gross profit188.39Gross loss-20.49
Profit factor9.20Expected payoff8.00
Absolute drawdown30.19Maximal drawdown35.74 (3.55%)Relative drawdown3.55% (35.74)
Total trades21Short positions (won %)0 (0.00%)Long positions (won %)21 (95.24%)
Profit trades (% of total)20 (95.24%)Loss trades (% of total)1 (4.76%)
Largestprofit trade16.76loss trade-20.49
Averageprofit trade9.42loss trade-20.49
Maximumconsecutive wins (profit in money)20 (188.39)consecutive losses (loss in money)1 (-20.49)
Maximalconsecutive profit (count of wins)188.39 (20)consecutive loss (count of losses)-20.49 (1)
Averageconsecutive wins20consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 09:30buy10.011842.470.001854.89
22020.12.07 10:38close10.011822.470.001854.89-20.49979.51
32021.01.06 02:00buy20.011950.800.001958.60
42021.01.06 12:00t/p20.011958.600.001958.607.80987.31
52021.02.19 05:15buy30.011769.940.001786.47
62021.02.19 16:09t/p30.011786.470.001786.4716.531003.84
72021.04.08 14:00buy40.011746.330.001756.47
82021.04.08 16:39t/p40.011756.470.001756.4710.141013.98
92021.04.21 04:30buy50.011779.910.001788.70
102021.04.21 16:39t/p50.011788.700.001788.708.791022.77
112021.07.01 05:00buy60.011771.790.001789.04
122021.07.02 15:39t/p60.011789.040.001789.0416.761039.54
132021.07.14 12:00buy70.011814.510.001822.43
142021.07.14 15:07t/p70.011822.430.001822.437.921047.46
152021.08.26 13:45buy80.011787.260.001795.39
162021.08.26 18:04t/p80.011795.390.001795.398.131055.59
172021.10.21 09:45buy90.011786.760.001797.68
182021.10.22 15:22t/p90.011797.680.001797.6810.431066.02
192022.02.09 11:30buy100.011827.880.001831.69
202022.02.09 15:09t/p100.011831.690.001831.693.811069.83
212022.08.01 01:30buy110.011764.550.001772.47
222022.08.01 12:57t/p110.011772.470.001772.477.921077.75
232022.08.22 14:15buy120.011735.890.001742.73
242022.08.23 11:42t/p120.011742.730.001742.736.351084.10
252022.09.05 04:45buy130.011711.780.001722.40
262022.09.06 03:47t/p130.011722.400.001722.4010.131094.24
272022.11.15 04:45buy140.011771.890.001782.72
282022.11.15 09:47t/p140.011782.720.001782.7210.831105.07
292022.11.21 20:30buy150.011738.410.001753.59
302022.11.21 23:45buy160.011738.520.001742.45
312022.11.22 03:07t/p160.011742.450.001742.453.441108.51
322022.11.24 02:26t/p150.011753.590.001753.5912.751121.26
332022.11.30 10:00buy170.011755.510.001762.02
342022.11.30 12:00t/p170.011762.020.001762.026.511127.77
352023.01.20 09:00buy180.011926.940.001936.75
362023.01.20 10:08t/p180.011936.750.001936.759.811137.58
372023.03.01 04:30buy190.011829.100.001845.33
382023.03.03 10:42t/p190.011845.330.001845.3314.281151.87
392023.04.25 09:30buy200.011995.440.002008.22
402023.04.26 16:28t/p200.012008.220.002008.2212.291164.16
412023.07.04 17:45buy210.011928.590.001932.82
422023.07.05 16:17t/p210.011932.820.001932.823.741167.90
+
diff --git a/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 1.gif b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 1.gif new file mode 100644 index 0000000..e16f6e5 Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 1.gif differ diff --git a/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 1.htm b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 1.htm new file mode 100644 index 0000000..1c5b449 --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 1.htm @@ -0,0 +1,217 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.01 23:45 (2020.01.01 - 2023.08.02)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=true; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63353Ticks modelled72601176Modelling qualityn/a
Mismatched charts errors808
Initial deposit1000.00SpreadCurrent (51)
Total net profit95.44Gross profit261.37Gross loss-165.93
Profit factor1.58Expected payoff1.34
Absolute drawdown5.38Maximal drawdown31.55 (2.87%)Relative drawdown2.87% (31.55)
Total trades71Short positions (won %)0 (0.00%)Long positions (won %)71 (57.75%)
Profit trades (% of total)41 (57.75%)Loss trades (% of total)30 (42.25%)
Largestprofit trade17.60loss trade-10.50
Averageprofit trade6.37loss trade-5.53
Maximumconsecutive wins (profit in money)4 (33.04)consecutive losses (loss in money)3 (-6.71)
Maximalconsecutive profit (count of wins)33.04 (4)consecutive loss (count of losses)-16.35 (2)
Averageconsecutive wins2consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.03 23:30buy10.011841.350.001845.81
22020.12.04 15:31t/p10.011845.810.001845.814.021004.02
32020.12.08 18:30buy20.011870.260.001886.04
42020.12.09 03:19close20.011867.580.001886.04-3.121000.90
52020.12.30 03:45buy30.011883.200.001893.66
62020.12.30 10:00close30.011878.490.001893.66-4.71996.19
72020.12.30 18:00buy40.011885.770.001895.53
82020.12.31 02:15t/p40.011895.530.001895.538.431004.62
92020.12.31 13:45buy50.011894.790.001901.55
102021.01.04 01:00t/p50.011901.550.001901.555.881010.49
112021.01.05 11:30buy60.011944.620.001954.40
122021.01.06 03:09t/p60.011954.400.001954.409.341019.83
132021.04.05 17:30buy70.011729.330.001742.53
142021.04.05 22:00close70.011725.680.001742.53-3.651016.18
152021.04.26 21:00buy80.011779.920.001781.68
162021.04.26 23:39t/p80.011781.680.001781.681.761017.94
172021.05.11 09:00buy90.011837.320.001840.12
182021.05.11 09:51close90.011834.840.001840.12-2.481015.46
192021.05.18 23:45buy100.011870.120.001872.90
202021.05.19 05:00close100.011867.630.001872.90-2.931012.53
212021.05.20 08:15buy110.011876.000.001876.98
222021.05.20 08:30t/p110.011876.980.001876.980.981013.51
232021.05.21 11:30buy120.011876.440.001882.56
242021.05.21 15:21t/p120.011882.560.001882.566.121019.63
252021.05.24 19:15buy130.011883.920.001887.18
262021.05.25 01:15close130.011880.910.001887.18-3.451016.18
272021.05.25 10:45buy140.011884.070.001898.65
282021.05.25 21:06t/p140.011898.650.001898.6514.581030.76
292021.06.28 20:30buy150.011780.420.001785.26
302021.06.28 21:15close150.011778.020.001785.26-2.401028.36
312021.07.02 02:00buy160.011776.540.001777.70
322021.07.02 03:39t/p160.011777.700.001777.701.161029.52
332021.07.06 04:15buy170.011792.850.001796.01
342021.07.06 04:53t/p170.011796.010.001796.013.161032.68
352021.07.09 17:45buy180.011806.300.001814.82
362021.07.12 07:16close180.011801.870.001814.82-4.871027.80
372021.07.13 17:45buy190.011811.780.001825.18
382021.07.13 21:07close190.011806.200.001825.18-5.581022.22
392021.08.11 05:30buy200.011732.160.001747.52
402021.08.11 18:06t/p200.011747.520.001747.5215.361037.58
412021.08.12 23:00buy210.011753.700.001757.12
422021.08.13 09:09t/p210.011757.120.001757.122.981040.56
432021.08.18 04:30buy220.011789.060.001796.30
442021.08.18 12:30close220.011787.880.001796.30-1.181039.38
452021.09.01 22:30buy230.011815.240.001820.60
462021.09.02 02:45close230.011813.220.001820.60-3.351036.04
472021.09.02 03:15buy240.011815.340.001819.70
482021.09.02 05:30close240.011813.160.001819.70-2.181033.86
492021.09.03 05:15buy250.011813.400.001819.26
502021.09.03 15:34t/p250.011819.260.001819.265.861039.72
512021.09.27 03:45buy260.011753.840.001763.88
522021.09.27 12:49close260.011749.120.001763.88-4.721035.00
532021.10.22 02:15buy270.011785.940.001793.12
542021.10.22 09:52t/p270.011793.120.001793.127.181042.18
552021.11.16 04:45buy280.011867.770.001877.31
562021.11.16 09:45close280.011863.300.001877.31-4.471037.71
572021.12.07 04:30buy290.011780.920.001785.14
582021.12.07 05:45close290.011778.500.001785.14-2.421035.29
592021.12.07 20:30buy300.011784.340.001788.42
602021.12.08 04:07t/p300.011788.420.001788.423.641038.92
612021.12.28 08:15buy310.011813.060.001819.28
622021.12.28 15:36t/p310.011819.280.001819.286.221045.14
632022.01.10 21:30buy320.011801.130.001805.89
642022.01.11 04:24t/p320.011805.890.001805.894.321049.46
652022.01.19 11:15buy330.011816.040.001824.86
662022.01.19 15:33t/p330.011824.860.001824.868.821058.28
672022.01.24 23:15buy340.011843.290.001853.65
682022.01.25 12:36close340.011836.700.001853.65-7.031051.25
692022.01.31 11:30buy350.011791.190.001798.83
702022.01.31 16:39t/p350.011798.830.001798.837.641058.89
712022.02.16 09:30buy360.011856.020.001860.76
722022.02.16 15:00close360.011852.740.001860.76-3.281055.61
732022.02.28 16:15buy370.011914.370.001926.79
742022.02.28 18:09close370.011904.370.001926.79-10.001045.61
752022.03.03 22:15buy380.011937.320.001946.64
762022.03.04 02:36t/p380.011946.640.001946.648.881054.49
772022.03.04 13:00buy390.011947.540.001961.66
782022.03.04 18:09t/p390.011961.660.001961.6614.121068.61
792022.03.11 21:30buy400.011986.860.001999.16
802022.03.14 00:22close400.011976.800.001999.16-10.501058.10
812022.03.24 13:30buy410.011946.410.001957.33
822022.03.24 14:03t/p410.011957.330.001957.3310.921069.02
832022.04.05 16:15buy420.011935.180.001956.54
842022.04.05 18:24close420.011925.180.001956.54-10.001059.02
852022.04.13 08:30buy430.011969.770.001973.31
862022.04.13 08:48t/p430.011973.310.001973.313.541062.56
872022.05.20 09:45buy440.011848.250.001859.53
882022.05.20 16:31close440.011840.590.001859.53-7.661054.90
892022.05.23 01:15buy450.011845.220.001848.46
902022.05.23 02:07t/p450.011848.460.001848.463.241058.14
912022.05.30 06:45buy460.011859.710.001862.85
922022.05.30 08:42t/p460.011862.850.001862.853.141061.28
932022.06.08 15:15buy470.011851.230.001858.73
942022.06.08 18:07t/p470.011858.730.001858.737.501068.78
952022.07.05 02:15buy480.011809.920.001814.70
962022.07.05 10:30close480.011806.730.001814.70-3.191065.59
972022.10.27 08:45buy490.011669.880.001683.00
982022.10.27 09:45close490.011661.850.001683.00-8.031057.56
992022.11.02 04:00buy500.011650.370.001653.27
1002022.11.02 10:00t/p500.011653.270.001653.272.901060.46
1012022.11.16 12:15buy510.011783.530.001796.87
1022022.11.16 16:43close510.011773.530.001796.87-10.001050.46
1032022.11.30 05:45buy520.011754.060.001759.10
1042022.11.30 10:53t/p520.011759.100.001759.105.041055.50
1052022.12.08 15:15buy530.011787.270.001794.47
1062022.12.08 17:28t/p530.011794.470.001794.477.201062.70
1072022.12.21 16:45buy540.011818.210.001822.71
1082022.12.21 17:36t/p540.011822.710.001822.714.501067.20
1092023.01.09 18:45buy550.011876.890.001885.73
1102023.01.10 02:26close550.011868.360.001885.73-8.971058.23
1112023.01.11 06:30buy560.011877.530.001882.75
1122023.01.11 07:37t/p560.011882.750.001882.755.221063.45
1132023.02.09 05:00buy570.011879.440.001889.90
1142023.02.09 16:00t/p570.011889.900.001889.9010.461073.91
1152023.02.16 21:30buy580.011843.430.001847.45
1162023.02.17 01:15close580.011835.010.001847.45-8.861065.05
1172023.02.22 05:15buy590.011837.090.001840.59
1182023.02.22 10:03t/p590.011840.590.001840.593.501068.55
1192023.03.17 04:45buy600.011929.050.001946.65
1202023.03.17 15:02t/p600.011946.650.001946.6517.601086.15
1212023.03.28 17:00buy610.011963.600.001968.68
1222023.03.28 17:57t/p610.011968.680.001968.685.081091.23
1232023.03.30 10:45buy620.011969.470.001976.33
1242023.03.30 19:01t/p620.011976.330.001976.336.861098.09
1252023.04.26 13:30buy630.012000.050.002005.35
1262023.04.26 15:30close630.011993.710.002005.35-6.341091.75
1272023.04.27 06:00buy640.011999.070.002014.41
1282023.04.27 15:35close640.011989.060.002014.41-10.011081.74
1292023.05.09 08:15buy650.012026.970.002032.23
1302023.05.09 14:30t/p650.012032.230.002032.235.261087.00
1312023.05.15 19:45buy660.012020.210.002031.69
1322023.05.15 22:00close660.012014.590.002031.69-5.621081.38
1332023.06.09 17:30buy670.011967.540.001988.74
1342023.06.09 18:30close670.011962.630.001988.74-4.911076.47
1352023.06.13 03:15buy680.011960.910.001966.27
1362023.06.13 15:30t/p680.011966.270.001966.275.361081.83
1372023.07.12 03:45buy690.011936.010.001941.67
1382023.07.12 15:30t/p690.011941.670.001941.675.661087.49
1392023.07.19 23:00buy700.011978.690.001982.47
1402023.07.20 04:30t/p700.011982.470.001982.472.451089.94
1412023.07.31 15:00buy710.011959.430.001964.93
1422023.07.31 15:31t/p710.011964.930.001964.935.501095.44
+
diff --git a/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 10.gif b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 10.gif new file mode 100644 index 0000000..605ff8a Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 10.gif differ diff --git a/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 10.htm b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 10.htm new file mode 100644 index 0000000..4dcf5fd --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 10.htm @@ -0,0 +1,89 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.04 23:45 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=false; +xRShortR2R=1.5; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.015; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xRSwingLength=48; xRSharpDetectionFactor=1350; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63629Ticks modelled72967510Modelling qualityn/a
Mismatched charts errors826
Initial deposit1000.00SpreadCurrent (60)
Total net profit100.29Gross profit131.18Gross loss-30.88
Profit factor4.25Expected payoff14.33
Absolute drawdown5.87Maximal drawdown29.76 (2.81%)Relative drawdown2.81% (29.76)
Total trades7Short positions (won %)0 (0.00%)Long positions (won %)7 (57.14%)
Profit trades (% of total)4 (57.14%)Loss trades (% of total)3 (42.86%)
Largestprofit trade53.90loss trade-10.88
Averageprofit trade32.79loss trade-10.29
Maximumconsecutive wins (profit in money)2 (24.79)consecutive losses (loss in money)2 (-20.88)
Maximalconsecutive profit (count of wins)53.90 (1)consecutive loss (count of losses)-20.88 (2)
Averageconsecutive wins1consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.01 19:30buy10.011812.670.001867.81
22020.12.07 18:09t/p10.011867.810.001867.8152.491052.49
32021.02.23 04:07buy20.011813.000.001850.54
42021.02.23 16:34close20.011803.000.001850.54-10.001042.49
52021.07.29 04:30buy30.011816.220.001862.70
62021.08.02 15:16close30.011806.220.001862.70-10.881031.60
72021.11.05 18:45buy40.011814.410.001872.29
82021.11.16 10:54t/p40.011872.290.001872.2953.901085.50
92022.02.04 15:30buy50.011813.380.001827.74
102022.02.04 15:37close50.011803.380.001827.74-10.001075.50
112022.02.07 11:01buy60.011813.370.001825.93
122022.02.07 16:19buy70.011815.990.001829.55
132022.02.08 17:22t/p60.011825.930.001825.9312.121087.62
142022.02.09 15:04t/p70.011829.550.001829.5512.681100.29
+
diff --git a/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 11.gif b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 11.gif new file mode 100644 index 0000000..bd320fc Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 11.gif differ diff --git a/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 11.htm b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 11.htm new file mode 100644 index 0000000..12a09e2 --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 11.htm @@ -0,0 +1,167 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.07 23:45 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=false; +xRShortR2R=1.5; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=1.5; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xRSwingLength=48; xRSharpDetectionFactor=1350; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63721Ticks modelled73052669Modelling qualityn/a
Mismatched charts errors959
Initial deposit1000.00SpreadCurrent (60)
Total net profit66.06Gross profit313.93Gross loss-247.87
Profit factor1.27Expected payoff1.44
Absolute drawdown11.93Maximal drawdown111.45 (9.77%)Relative drawdown9.77% (111.45)
Total trades46Short positions (won %)0 (0.00%)Long positions (won %)46 (43.48%)
Profit trades (% of total)20 (43.48%)Loss trades (% of total)26 (56.52%)
Largestprofit trade42.10loss trade-11.77
Averageprofit trade15.70loss trade-9.53
Maximumconsecutive wins (profit in money)4 (58.47)consecutive losses (loss in money)9 (-88.41)
Maximalconsecutive profit (count of wins)61.47 (3)consecutive loss (count of losses)-88.41 (9)
Averageconsecutive wins3consecutive losses4
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.01 19:30buy10.011812.670.001854.03
22020.12.02 02:30buy20.011813.300.001827.99
32020.12.02 08:45buy30.011813.220.001821.29
42020.12.02 10:36t/p30.011821.290.001821.298.071008.07
52020.12.02 12:22t/p20.011827.990.001827.9914.691022.76
62020.12.07 16:54t/p10.011854.030.001854.0338.711061.47
72021.02.05 19:15buy40.011814.870.001846.31
82021.02.08 01:15buy50.011817.920.001853.94
92021.02.08 07:30buy60.011815.770.001825.97
102021.02.08 10:54close50.011807.920.001853.94-10.001051.47
112021.02.08 11:45buy70.011813.190.001820.66
122021.02.08 13:36t/p70.011820.660.001820.667.471058.94
132021.02.08 14:53t/p60.011825.970.001825.9710.201069.14
142021.02.09 11:24t/p40.011846.310.001846.3130.561099.69
152021.02.23 04:00buy80.011813.660.001842.81
162021.02.23 05:45buy90.011813.350.001827.83
172021.02.23 12:03close80.011803.660.001842.81-10.001089.69
182021.02.23 16:34close90.011803.350.001827.83-10.001079.69
192021.05.06 18:00buy100.011815.960.001857.50
202021.05.12 23:21close100.011815.950.001857.50-1.781077.91
212021.07.08 14:00buy110.011817.800.001849.44
222021.07.08 16:54close110.011807.800.001849.44-10.001067.91
232021.07.13 15:30buy120.011813.610.001824.61
242021.07.13 15:33close120.011803.610.001824.61-10.001057.91
252021.07.13 18:15buy130.011812.880.001833.64
262021.07.14 06:30buy140.011813.470.001826.19
272021.07.14 08:30buy150.011813.850.001827.14
282021.07.14 10:45buy160.011813.970.001827.44
292021.07.14 15:09t/p140.011826.190.001826.1912.721070.63
302021.07.14 15:37t/p150.011827.140.001827.1413.291083.92
312021.07.14 15:37t/p160.011827.440.001827.4413.471097.39
322021.07.15 10:09t/p130.011833.640.001833.6418.991116.38
332021.07.29 04:30buy170.011816.220.001851.08
342021.08.02 15:16close170.011806.220.001851.08-10.881105.50
352021.08.27 19:15buy180.011814.970.001860.75
362021.08.31 04:30buy190.011814.070.001822.88
372021.08.31 14:15buy200.011814.320.001820.52
382021.08.31 16:07close180.011804.970.001860.75-10.881094.61
392021.08.31 16:09close200.011804.320.001820.52-10.001084.61
402021.08.31 16:09close190.011804.070.001822.88-10.001074.61
412021.08.31 20:00buy210.011814.380.001832.73
422021.09.01 04:30buy220.011813.000.001829.28
432021.09.03 14:00close210.011813.360.001832.73-3.231071.38
442021.09.03 17:37t/p220.011829.280.001829.2814.511085.89
452021.11.05 18:45buy230.011814.420.001857.85
462021.11.10 16:24t/p230.011857.850.001857.8542.101128.00
472021.12.27 18:00buy240.011813.070.001827.70
482021.12.28 08:00buy250.011813.290.001822.58
492021.12.28 17:00buy260.011814.240.001821.44
502021.12.29 02:08close260.011804.240.001821.44-10.441117.55
512021.12.29 10:07close250.011803.290.001822.58-10.441107.11
522021.12.29 10:09close240.011803.070.001827.70-10.881096.23
532021.12.30 19:00buy270.011813.910.001839.94
542022.01.03 16:54close270.011803.910.001839.94-10.881085.34
552022.01.04 17:45buy280.011817.100.001844.31
562022.01.04 19:30buy290.011814.680.001838.26
572022.01.06 03:09close280.011807.100.001844.31-11.771073.57
582022.01.06 07:37close290.011804.680.001838.26-11.771061.80
592022.01.11 18:30buy300.011815.760.001836.12
602022.01.14 19:18close300.011815.750.001836.12-2.221059.58
612022.02.04 12:30buy310.011814.110.001827.76
622022.02.04 15:30buy320.011813.380.001824.15
632022.02.04 15:37close310.011804.110.001827.76-10.001049.58
642022.02.04 15:37close320.011803.380.001824.15-10.001039.58
652022.02.07 02:45buy330.011812.890.001843.42
662022.02.07 11:00buy340.011813.460.001823.02
672022.02.07 14:00buy350.011814.020.001821.27
682022.02.07 16:15buy360.011816.190.001826.66
692022.02.07 21:07t/p350.011821.270.001821.277.251046.83
702022.02.07 21:39t/p340.011823.020.001823.029.561056.39
712022.02.08 17:24t/p360.011826.660.001826.6610.031066.42
722022.02.11 20:34t/p330.011843.420.001843.4227.881094.30
732022.12.13 16:30buy370.011818.980.001875.20
742022.12.13 17:50close370.011808.980.001875.20-10.001084.30
752022.12.13 18:45buy380.011813.360.001859.13
762022.12.14 21:01close380.011803.350.001859.13-10.451073.84
772022.12.20 17:15buy390.011820.930.001871.35
782022.12.21 09:30buy400.011815.440.001820.23
792022.12.21 14:00buy410.011814.150.001817.00
802022.12.21 15:13t/p410.011817.000.001817.002.851076.69
812022.12.21 17:08t/p400.011820.230.001820.234.791081.48
822022.12.22 15:38close390.011810.930.001871.35-11.771069.72
832022.12.27 17:30buy420.011821.790.001850.43
842022.12.27 19:58close420.011811.790.001850.43-10.001059.72
852022.12.27 20:15buy430.011815.080.001833.65
862022.12.28 03:30buy440.011814.740.001832.80
872022.12.28 10:15close430.011805.080.001833.65-10.441049.27
882022.12.28 10:15close440.011804.730.001832.80-10.011039.26
892022.12.29 17:00buy450.011814.400.001828.85
902022.12.29 18:45buy460.011814.770.001829.77
912023.01.03 01:05t/p450.011828.850.001828.8513.121052.39
922023.01.03 01:07t/p460.011829.770.001829.7713.671066.06
+
diff --git a/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 2.gif b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 2.gif new file mode 100644 index 0000000..4ec49d5 Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 2.gif differ diff --git a/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 2.htm b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 2.htm new file mode 100644 index 0000000..c9d8a08 --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 2.htm @@ -0,0 +1,91 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.01.29 23:45 (2020.01.01 - 2021.01.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xRSwingLength=11; xRSharpDetectionFactor=650; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test4192Ticks modelled3544155Modelling quality24.42%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (51)
Total net profit59.63Gross profit79.64Gross loss-20.01
Profit factor3.98Expected payoff7.45
Absolute drawdown24.68Maximal drawdown42.62 (4.07%)Relative drawdown4.07% (42.62)
Total trades8Short positions (won %)0 (0.00%)Long positions (won %)8 (75.00%)
Profit trades (% of total)6 (75.00%)Loss trades (% of total)2 (25.00%)
Largestprofit trade19.99loss trade-10.01
Averageprofit trade13.27loss trade-10.00
Maximumconsecutive wins (profit in money)3 (49.04)consecutive losses (loss in money)1 (-10.01)
Maximalconsecutive profit (count of wins)49.04 (3)consecutive loss (count of losses)-10.01 (1)
Averageconsecutive wins3consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 02:45buy10.011813.240.001823.26
22020.11.27 07:31close10.011803.230.001823.26-10.01989.99
32020.12.01 16:15buy20.011814.300.001836.06
42020.12.01 19:15buy30.011813.970.001831.39
52020.12.02 01:00buy40.011812.820.001812.82
62020.12.02 02:09t/p40.011812.820.001812.820.00989.99
72020.12.02 08:30buy50.011814.560.001828.18
82020.12.02 10:45buy60.011824.380.001851.10
92020.12.02 12:22t/p50.011828.180.001828.1813.621003.61
102020.12.02 12:39t/p30.011831.390.001831.3916.981020.59
112020.12.02 15:54close60.011814.380.001851.10-10.001010.59
122020.12.02 16:15buy70.011819.680.001832.70
132020.12.03 05:19t/p70.011832.700.001832.7011.691022.28
142020.12.03 05:37t/p20.011836.060.001836.0619.991042.27
152021.01.18 02:45buy80.011819.330.001836.69
162021.01.18 07:37t/p80.011836.690.001836.6917.361059.63
+
diff --git a/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 3.gif b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 3.gif new file mode 100644 index 0000000..da54e45 Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 3.gif differ diff --git a/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 3.htm b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 3.htm new file mode 100644 index 0000000..868efaf --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 3.htm @@ -0,0 +1,87 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.01.29 23:45 (2020.01.01 - 2021.01.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xRSwingLength=11; xRSharpDetectionFactor=650; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test4192Ticks modelled3544155Modelling quality24.42%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (51)
Total net profit57.80Gross profit67.80Gross loss-10.00
Profit factor6.78Expected payoff9.63
Absolute drawdown20.25Maximal drawdown42.62 (4.01%)Relative drawdown4.01% (42.62)
Total trades6Short positions (won %)0 (0.00%)Long positions (won %)6 (83.33%)
Profit trades (% of total)5 (83.33%)Loss trades (% of total)1 (16.67%)
Largestprofit trade19.99loss trade-10.00
Averageprofit trade13.56loss trade-10.00
Maximumconsecutive wins (profit in money)3 (36.12)consecutive losses (loss in money)1 (-10.00)
Maximalconsecutive profit (count of wins)36.12 (3)consecutive loss (count of losses)-10.00 (1)
Averageconsecutive wins3consecutive losses1
+Graph
+ + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.01 16:15buy10.011814.300.001836.06
22020.12.01 19:15buy20.011813.970.001831.39
32020.12.02 01:00buy30.011812.820.001818.34
42020.12.02 08:30buy40.011814.560.001828.18
52020.12.02 10:34t/p30.011818.340.001818.345.521005.52
62020.12.02 10:45buy50.011824.380.001851.10
72020.12.02 12:22t/p40.011828.180.001828.1813.621019.14
82020.12.02 12:39t/p20.011831.390.001831.3916.981036.12
92020.12.02 15:54close50.011814.380.001851.10-10.001026.12
102020.12.02 16:15buy60.011819.680.001832.70
112020.12.03 05:19t/p60.011832.700.001832.7011.691037.81
122020.12.03 05:37t/p10.011836.060.001836.0619.991057.80
+
diff --git a/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 4.gif b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 4.gif new file mode 100644 index 0000000..5d8f0b3 Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 4.gif differ diff --git a/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 4.htm b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 4.htm new file mode 100644 index 0000000..0d2ba8e --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 4.htm @@ -0,0 +1,85 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.01.29 23:45 (2020.01.01 - 2021.01.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.015; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.015; xRMaximumCandlesPerTrade=252; xRSwingLength=11; xRSharpDetectionFactor=650; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test4192Ticks modelled3544155Modelling quality24.42%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (51)
Total net profit67.80Gross profit67.80Gross loss-0.00
Profit factorExpected payoff13.56
Absolute drawdown20.25Maximal drawdown26.20 (2.60%)Relative drawdown2.60% (26.20)
Total trades5Short positions (won %)0 (0.00%)Long positions (won %)5 (100.00%)
Profit trades (% of total)5 (100.00%)Loss trades (% of total)0 (0.00%)
Largestprofit trade19.99loss trade-0.00
Averageprofit trade13.56loss trade-0.00
Maximumconsecutive wins (profit in money)5 (67.80)consecutive losses (loss in money)0 (-0.00)
Maximalconsecutive profit (count of wins)67.80 (5)consecutive loss (count of losses)-0.00 (0)
Averageconsecutive wins5consecutive losses0
+Graph
+ + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.01 16:15buy10.011814.300.001836.06
22020.12.01 19:15buy20.011813.970.001831.39
32020.12.02 01:00buy30.011812.820.001818.34
42020.12.02 08:30buy40.011814.560.001828.18
52020.12.02 10:34t/p30.011818.340.001818.345.521005.52
62020.12.02 12:22t/p40.011828.180.001828.1813.621019.14
72020.12.02 12:39t/p20.011831.390.001831.3916.981036.12
82020.12.02 16:15buy50.011819.680.001832.70
92020.12.03 05:19t/p50.011832.700.001832.7011.691047.81
102020.12.03 05:37t/p10.011836.060.001836.0619.991067.80
+
diff --git a/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 5.gif b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 5.gif new file mode 100644 index 0000000..f2053e2 Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 5.gif differ diff --git a/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 5.htm b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 5.htm new file mode 100644 index 0000000..42889ef --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 5.htm @@ -0,0 +1,103 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.03.30 23:45 (2020.01.01 - 2021.03.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.015; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.015; xRMaximumCandlesPerTrade=252; xRSwingLength=11; xRSharpDetectionFactor=650; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test8040Ticks modelled9476561Modelling quality24.70%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (50)
Total net profit63.48Gross profit123.48Gross loss-60.00
Profit factor2.06Expected payoff4.53
Absolute drawdown20.22Maximal drawdown67.32 (5.95%)Relative drawdown5.95% (67.32)
Total trades14Short positions (won %)0 (0.00%)Long positions (won %)14 (71.43%)
Profit trades (% of total)10 (71.43%)Loss trades (% of total)4 (28.57%)
Largestprofit trade19.99loss trade-15.00
Averageprofit trade12.35loss trade-15.00
Maximumconsecutive wins (profit in money)10 (123.48)consecutive losses (loss in money)4 (-60.00)
Maximalconsecutive profit (count of wins)123.48 (10)consecutive loss (count of losses)-60.00 (4)
Averageconsecutive wins10consecutive losses4
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.01 16:15buy10.011814.290.001836.05
22020.12.01 19:15buy20.011813.960.001831.38
32020.12.02 01:00buy30.011812.810.001818.35
42020.12.02 08:30buy40.011814.550.001828.17
52020.12.02 10:34t/p30.011818.350.001818.355.541005.54
62020.12.02 12:22t/p40.011828.170.001828.1713.621019.16
72020.12.02 12:39t/p20.011831.380.001831.3816.981036.14
82020.12.02 16:15buy50.011819.670.001832.69
92020.12.03 05:19t/p50.011832.690.001832.6911.691047.83
102020.12.03 05:37t/p10.011836.050.001836.0519.991067.82
112021.02.05 22:30buy60.011812.580.001817.60
122021.02.08 01:07t/p60.011817.600.001817.604.581072.40
132021.02.08 01:15buy70.011817.820.001833.66
142021.02.08 05:15buy80.011811.700.001817.36
152021.02.08 09:21buy90.011816.730.001827.67
162021.02.08 09:30t/p80.011817.360.001817.365.661078.06
172021.02.08 13:22buy100.011817.990.001836.63
182021.02.08 15:37t/p90.011827.670.001827.6710.941089.00
192021.02.08 16:09t/p70.011833.660.001833.6615.841104.84
202021.02.08 17:24t/p100.011836.630.001836.6318.641123.48
212021.02.23 02:00buy110.011810.780.001816.74
222021.02.23 04:00buy120.011813.560.001827.54
232021.02.23 08:00buy130.011813.000.001818.80
242021.02.23 16:38close120.011798.560.001827.54-15.001108.48
252021.02.23 16:38close130.011798.000.001818.80-15.001093.48
262021.02.23 16:48close110.011795.780.001816.74-15.001078.48
272021.02.24 04:19buy140.011811.640.001823.28
282021.02.24 15:47close140.011796.640.001823.28-15.001063.48
+
diff --git a/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 6.gif b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 6.gif new file mode 100644 index 0000000..ca3bdd7 Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 6.gif differ diff --git a/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 6.htm b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 6.htm new file mode 100644 index 0000000..e7f7192 --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 6.htm @@ -0,0 +1,89 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2022.01.03 01:00 - 2023.08.04 23:45 (2022.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=false; +xRShortR2R=1.5; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.015; xRLongR2R=1.5; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.015; xRMaximumCandlesPerTrade=252; xRSwingLength=7; xRSharpDetectionFactor=650; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test38648Ticks modelled45067506Modelling qualityn/a
Mismatched charts errors826
Initial deposit1000.00SpreadCurrent (60)
Total net profit30.68Gross profit30.68Gross loss-0.00
Profit factorExpected payoff4.38
Absolute drawdown1.72Maximal drawdown11.16 (1.10%)Relative drawdown1.10% (11.16)
Total trades7Short positions (won %)0 (0.00%)Long positions (won %)7 (100.00%)
Profit trades (% of total)7 (100.00%)Loss trades (% of total)0 (0.00%)
Largestprofit trade14.90loss trade-0.00
Averageprofit trade4.38loss trade-0.00
Maximumconsecutive wins (profit in money)7 (30.68)consecutive losses (loss in money)0 (-0.00)
Maximalconsecutive profit (count of wins)30.68 (7)consecutive loss (count of losses)-0.00 (0)
Averageconsecutive wins7consecutive losses0
+Graph
+ + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12022.01.11 02:39buy10.011803.570.001808.31
22022.01.11 07:54t/p10.011808.310.001808.314.741004.74
32022.01.11 16:48buy20.011803.580.001805.67
42022.01.11 16:52t/p20.011805.670.001805.672.091006.83
52022.02.01 10:19buy30.011803.580.001806.07
62022.02.01 11:09t/p30.011806.070.001806.072.491009.32
72022.02.01 16:03buy40.011803.580.001805.05
82022.02.01 16:09t/p40.011805.050.001805.051.471010.79
92022.02.02 14:02buy50.011803.480.001805.27
102022.02.02 15:21t/p50.011805.270.001805.271.791012.58
112022.12.20 11:15buy60.011803.390.001818.29
122022.12.20 17:10t/p60.011818.290.001818.2914.901027.48
132022.12.27 02:30buy70.011802.870.001806.07
142022.12.27 04:45t/p70.011806.070.001806.073.201030.68
+
diff --git a/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 7.gif b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 7.gif new file mode 100644 index 0000000..9e04b0a Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 7.gif differ diff --git a/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 7.htm b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 7.htm new file mode 100644 index 0000000..e5b9cca --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 7.htm @@ -0,0 +1,143 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.04 23:45 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=false; +xRShortR2R=1.5; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.015; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xRSwingLength=48; xRSharpDetectionFactor=650; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63629Ticks modelled72967510Modelling qualityn/a
Mismatched charts errors826
Initial deposit1000.00SpreadCurrent (60)
Total net profit125.81Gross profit290.45Gross loss-164.65
Profit factor1.76Expected payoff3.70
Absolute drawdown11.93Maximal drawdown74.32 (6.57%)Relative drawdown6.57% (74.32)
Total trades34Short positions (won %)0 (0.00%)Long positions (won %)34 (44.12%)
Profit trades (% of total)15 (44.12%)Loss trades (% of total)19 (55.88%)
Largestprofit trade53.92loss trade-11.77
Averageprofit trade19.36loss trade-8.67
Maximumconsecutive wins (profit in money)6 (82.82)consecutive losses (loss in money)6 (-46.65)
Maximalconsecutive profit (count of wins)105.06 (5)consecutive loss (count of losses)-46.65 (6)
Averageconsecutive wins4consecutive losses5
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.01 19:30buy10.011812.670.001867.81
22020.12.02 02:30buy20.011813.300.001832.88
32020.12.02 08:45buy30.011813.220.001823.98
42020.12.02 10:39t/p30.011823.980.001823.9810.761010.76
52020.12.03 05:19t/p20.011832.880.001832.8818.251029.01
62020.12.07 18:09t/p10.011867.810.001867.8152.491081.50
72021.02.08 07:30buy40.011816.010.001829.61
82021.02.08 11:45buy50.011813.190.001823.15
92021.02.08 14:46t/p50.011823.150.001823.159.961091.46
102021.02.08 15:49t/p40.011829.610.001829.6113.601105.06
112021.02.23 04:00buy60.011813.660.001852.52
122021.02.23 05:45buy70.011813.350.001832.65
132021.02.23 12:03close60.011803.660.001852.52-10.001095.06
142021.02.23 16:34close70.011803.350.001832.65-10.001085.06
152021.05.06 18:00buy80.011815.960.001871.34
162021.05.12 23:21close80.011815.950.001871.34-1.781083.28
172021.07.08 14:00buy90.011817.800.001859.98
182021.07.08 16:54close90.011807.800.001859.98-10.001073.28
192021.07.13 15:30buy100.011813.610.001828.27
202021.07.13 15:33close100.011803.610.001828.27-10.001063.28
212021.07.13 18:15buy110.011812.880.001840.56
222021.07.14 06:30buy120.011813.470.001830.43
232021.07.14 08:33buy130.011814.130.001831.85
242021.07.14 10:45buy140.011813.970.001831.93
252021.07.15 09:06t/p120.011830.430.001830.4315.631078.91
262021.07.15 09:09t/p130.011831.850.001831.8516.391095.31
272021.07.15 09:09t/p140.011831.930.001831.9316.631111.94
282021.07.16 17:52close110.011812.870.001840.56-2.221109.72
292021.07.29 04:30buy150.011816.220.001862.70
302021.08.02 15:16close150.011806.220.001862.70-10.881098.83
312021.08.27 19:15buy160.011814.970.001876.01
322021.08.31 04:30buy170.011814.070.001825.81
332021.08.31 14:15buy180.011814.320.001822.58
342021.08.31 16:07close160.011804.970.001876.01-10.881087.95
352021.08.31 16:09close180.011804.320.001822.58-10.001077.95
362021.08.31 16:09close170.011804.070.001825.81-10.001067.95
372021.09.01 06:00buy190.011814.440.001834.00
382021.09.07 11:09close190.011814.430.001834.00-2.661065.28
392021.11.05 18:45buy200.011814.420.001872.32
402021.11.16 10:54t/p200.011872.320.001872.3253.921119.20
412021.12.27 18:00buy210.011813.070.001832.57
422021.12.28 08:00buy220.011813.290.001825.67
432021.12.28 17:00buy230.011814.240.001823.84
442021.12.29 02:08close230.011804.240.001823.84-10.441108.76
452021.12.29 10:07close220.011803.290.001825.67-10.441098.32
462021.12.29 10:09close210.011803.070.001832.57-10.881087.43
472022.01.11 18:30buy240.011815.760.001842.90
482022.01.14 19:18close240.011815.750.001842.90-2.221085.21
492022.02.04 15:30buy250.011813.380.001827.74
502022.02.04 15:37close250.011803.380.001827.74-10.001075.21
512022.02.07 02:49buy260.011813.160.001853.86
522022.02.07 11:00buy270.011813.460.001826.20
532022.02.07 14:00buy280.011814.020.001823.68
542022.02.07 16:15buy290.011816.190.001830.15
552022.02.08 15:54t/p280.011823.680.001823.689.221084.43
562022.02.08 17:22t/p270.011826.200.001826.2012.301096.73
572022.02.09 15:06t/p290.011830.150.001830.1513.081109.80
582022.02.11 20:49t/p260.011853.860.001853.8638.051147.85
592022.12.20 17:22buy300.011818.080.001879.60
602022.12.21 09:31buy310.011815.890.001822.27
612022.12.21 14:00buy320.011814.150.001817.95
622022.12.21 15:20t/p320.011817.950.001817.953.801151.65
632022.12.21 17:36t/p310.011822.270.001822.276.381158.03
642022.12.22 15:53close300.011808.080.001879.60-11.771146.26
652022.12.27 20:15buy330.011815.080.001839.84
662022.12.28 03:30buy340.011814.740.001838.82
672022.12.28 10:15close330.011805.080.001839.84-10.441135.82
682022.12.28 10:15close340.011804.730.001838.82-10.011125.81
+
diff --git a/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 8.gif b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 8.gif new file mode 100644 index 0000000..de9b6fb Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 8.gif differ diff --git a/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 8.htm b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 8.htm new file mode 100644 index 0000000..1daf914 --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 8.htm @@ -0,0 +1,97 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.04 23:45 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=false; +xRShortR2R=1.5; xRShortLotsPerTradePercent=0.0001; xRShortMaxDrawdownPerTradePercent=0.15; xRLongR2R=2; xRLongLotsPerTradePercent=0.0001; xRLongMaxDrawdownPerTradePercent=0.1; xRMaximumCandlesPerTrade=252; xRSwingLength=48; xRSharpDetectionFactor=1350; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63629Ticks modelled72967510Modelling qualityn/a
Mismatched charts errors826
Initial deposit1000.00SpreadCurrent (60)
Total net profit1586.83Gross profit2026.73Gross loss-439.91
Profit factor4.61Expected payoff144.26
Absolute drawdown96.42Maximal drawdown616.71 (32.38%)Relative drawdown32.38% (616.71)
Total trades11Short positions (won %)0 (0.00%)Long positions (won %)11 (54.55%)
Profit trades (% of total)6 (54.55%)Loss trades (% of total)5 (45.45%)
Largestprofit trade538.99loss trade-108.85
Averageprofit trade337.79loss trade-87.98
Maximumconsecutive wins (profit in money)2 (1072.41)consecutive losses (loss in money)3 (-317.69)
Maximalconsecutive profit (count of wins)1072.41 (2)consecutive loss (count of losses)-317.69 (3)
Averageconsecutive wins2consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.01 19:30buy10.101812.670.001867.81
22020.12.02 10:36buy20.101821.850.001841.33
32020.12.03 09:52t/p20.101841.330.001841.33181.531181.53
42020.12.07 18:09t/p10.101867.810.001867.81524.861706.39
52021.02.23 04:07buy30.101813.000.001850.54
62021.02.23 16:34close30.101803.000.001850.54-100.001606.39
72021.07.29 04:30buy40.101816.220.001862.70
82021.07.29 09:52buy50.101818.920.001868.58
92021.08.02 04:39close50.101808.920.001868.58-108.851497.55
102021.08.02 15:16close40.101806.220.001862.70-108.851388.70
112021.11.05 18:45buy60.101814.410.001872.29
122021.11.08 03:07buy70.101819.710.001876.59
132021.11.16 10:54t/p60.101872.290.001872.29538.991927.69
142021.11.16 15:18t/p70.101876.590.001876.59533.422461.11
152022.02.04 15:30buy80.101813.380.001827.74
162022.02.04 15:37close80.101803.380.001827.74-100.002361.11
172022.02.07 11:01buy90.101813.370.001825.93
182022.02.07 16:19buy100.101815.990.001829.55
192022.02.07 20:25buy110.101821.630.001843.73
202022.02.08 17:22t/p90.101825.930.001825.93121.182482.29
212022.02.09 15:04t/p100.101829.550.001829.55126.752609.04
222022.02.10 15:33close110.101821.620.001843.73-22.222586.83
+
diff --git a/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 9.gif b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 9.gif new file mode 100644 index 0000000..13f7a09 Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 9.gif differ diff --git a/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 9.htm b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 9.htm new file mode 100644 index 0000000..eb87f44 --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/XR/Long/StrategyTester 9.htm @@ -0,0 +1,123 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.04 23:45 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=false; +xRShortR2R=1.5; xRShortLotsPerTradePercent=0.0001; xRShortMaxDrawdownPerTradePercent=0.15; xRLongR2R=2; xRLongLotsPerTradePercent=0.0001; xRLongMaxDrawdownPerTradePercent=0.1; xRMaximumCandlesPerTrade=252; xRSwingLength=48; xRSharpDetectionFactor=1350; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63629Ticks modelled72967510Modelling qualityn/a
Mismatched charts errors826
Initial deposit1000.00SpreadCurrent (60)
Total net profit868.35Gross profit2155.53Gross loss-1287.18
Profit factor1.67Expected payoff36.18
Absolute drawdown96.42Maximal drawdown851.58 (44.06%)Relative drawdown44.06% (851.58)
Total trades24Short positions (won %)0 (0.00%)Long positions (won %)24 (37.50%)
Profit trades (% of total)9 (37.50%)Loss trades (% of total)15 (62.50%)
Largestprofit trade539.19loss trade-117.69
Averageprofit trade239.50loss trade-85.81
Maximumconsecutive wins (profit in money)3 (842.39)consecutive losses (loss in money)5 (-489.58)
Maximalconsecutive profit (count of wins)842.39 (3)consecutive loss (count of losses)-489.58 (5)
Averageconsecutive wins2consecutive losses4
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.01 19:30buy10.101812.670.001867.81
22020.12.02 10:36buy20.101821.850.001841.33
32020.12.03 09:52t/p20.101841.330.001841.33181.531181.53
42020.12.07 18:09t/p10.101867.810.001867.81524.861706.39
52021.02.08 07:30buy30.101815.770.001829.37
62021.02.08 15:49t/p30.101829.370.001829.37136.001842.39
72021.02.23 04:00buy40.101813.660.001852.52
82021.02.23 08:07buy50.101813.980.001826.90
92021.02.23 11:54close50.101803.980.001826.90-100.001742.39
102021.02.23 12:03close40.101803.660.001852.52-100.001642.39
112021.05.06 18:04buy60.101815.740.001870.68
122021.05.12 23:21close60.101815.730.001870.68-17.791624.60
132021.07.13 15:30buy70.101813.610.001828.27
142021.07.13 15:33close70.101803.610.001828.27-100.001524.60
152021.07.14 10:45buy80.101813.970.001831.93
162021.07.14 13:37buy90.101817.470.001838.05
172021.07.15 09:09t/p80.101831.930.001831.93166.331690.93
182021.07.19 07:30close90.101813.820.001838.05-58.621632.32
192021.07.29 04:30buy100.101816.220.001862.70
202021.07.29 09:51buy110.101818.660.001868.32
212021.08.02 04:39close110.101808.660.001868.32-108.851523.47
222021.08.02 15:16close100.101806.220.001862.70-108.851414.62
232021.08.27 19:21buy120.101814.650.001875.05
242021.08.27 22:54buy130.101819.260.001887.44
252021.08.30 18:39close130.101809.260.001887.44-104.421310.20
262021.08.31 16:09close120.101804.650.001875.05-108.851201.36
272021.11.05 18:45buy140.101814.420.001872.32
282021.11.08 07:54buy150.101821.600.001845.16
292021.11.10 15:39t/p150.101845.160.001845.16226.751428.11
302021.11.16 10:54t/p140.101872.320.001872.32539.191967.30
312022.01.11 18:43buy160.101816.350.001843.49
322022.01.14 19:15close160.101816.340.001843.49-22.221945.09
332022.02.04 15:30buy170.101813.380.001827.74
342022.02.04 15:37close170.101803.380.001827.74-100.001845.09
352022.02.07 11:00buy180.101813.460.001826.20
362022.02.07 14:00buy190.101814.020.001823.68
372022.02.07 21:36buy200.101823.260.001848.06
382022.02.08 15:54t/p190.101823.680.001823.6892.181937.26
392022.02.08 17:22t/p180.101826.200.001826.20122.982060.24
402022.02.10 15:31close200.101823.250.001848.06-22.222038.03
412022.12.20 17:22buy210.101818.080.001879.60
422022.12.21 10:00buy220.101816.930.001825.99
432022.12.22 15:53close210.101808.080.001879.60-117.691920.33
442022.12.22 15:58close220.101806.930.001825.99-113.271807.07
452022.12.27 20:15buy230.101815.080.001839.84
462022.12.28 10:15close230.101805.080.001839.84-104.421702.64
472022.12.28 10:15buy240.101805.660.001824.00
482022.12.30 16:07t/p240.101824.000.001824.00165.711868.35
+
diff --git a/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 1.gif b/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 1.gif new file mode 100644 index 0000000..848a4a0 Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 1.gif differ diff --git a/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 1.htm b/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 1.htm new file mode 100644 index 0000000..e95644f --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 1.htm @@ -0,0 +1,283 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.04 23:45 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=false; +enableXRShort=true; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xRSwingLength=48; xRSharpDetectionFactor=1350; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63629Ticks modelled72967534Modelling qualityn/a
Mismatched charts errors826
Initial deposit1000.00SpreadCurrent (51)
Total net profit138.50Gross profit694.79Gross loss-556.29
Profit factor1.25Expected payoff1.33
Absolute drawdown75.42Maximal drawdown148.46 (13.84%)Relative drawdown13.84% (148.46)
Total trades104Short positions (won %)104 (44.23%)Long positions (won %)0 (0.00%)
Profit trades (% of total)46 (44.23%)Loss trades (% of total)58 (55.77%)
Largestprofit trade50.75loss trade-11.05
Averageprofit trade15.10loss trade-9.59
Maximumconsecutive wins (profit in money)10 (194.09)consecutive losses (loss in money)11 (-108.64)
Maximalconsecutive profit (count of wins)194.09 (10)consecutive loss (count of losses)-108.64 (11)
Averageconsecutive wins4consecutive losses5
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 06:45sell10.011807.850.001793.49
22020.11.27 12:30sell20.011808.700.001798.70
32020.11.27 15:07t/p20.011798.700.001798.7010.001010.00
42020.11.27 15:09t/p10.011793.490.001793.4914.361024.36
52020.12.01 17:30sell30.011806.320.001788.90
62020.12.01 20:15close30.011816.330.001788.90-10.011014.35
72020.12.02 05:15sell40.011809.570.001794.49
82020.12.02 10:34close40.011819.570.001794.49-10.001004.35
92021.02.04 16:00sell50.011808.190.001770.49
102021.02.05 21:00sell60.011810.160.001800.30
112021.02.05 23:00sell70.011810.890.001802.49
122021.02.08 01:09close50.011818.190.001770.49-9.59994.76
132021.02.08 04:45sell80.011810.250.001793.39
142021.02.08 11:00sell90.011809.020.001789.70
152021.02.08 13:31close90.011819.020.001789.70-10.00984.76
162021.02.08 13:34close60.011820.170.001800.30-9.80974.96
172021.02.08 13:34close80.011820.250.001793.39-10.00964.96
182021.02.08 13:36close70.011820.890.001802.49-9.79955.16
192021.02.16 15:15sell100.011811.040.001780.54
202021.02.16 18:30sell110.011803.470.001759.29
212021.02.17 15:24t/p100.011780.540.001780.5430.71985.87
222021.02.22 16:37close110.011803.480.001759.291.23987.10
232021.02.22 19:30sell120.011809.990.001805.03
242021.02.23 09:45sell130.011809.820.001797.80
252021.02.23 11:54t/p120.011805.030.001805.035.17992.26
262021.02.23 14:45sell140.011810.320.001799.30
272021.02.23 16:37t/p140.011799.300.001799.3011.021003.28
282021.02.23 16:45t/p130.011797.800.001797.8012.021015.30
292021.02.24 05:00sell150.011810.060.001802.60
302021.02.24 15:21t/p150.011802.600.001802.607.461022.76
312021.05.13 13:15sell160.011810.390.001785.51
322021.05.13 15:39close160.011820.390.001785.51-10.001012.76
332021.06.17 10:30sell170.011809.210.001747.49
342021.07.06 10:54close170.011809.220.001747.493.491016.26
352021.07.06 16:15sell180.011806.750.001790.71
362021.07.06 19:24t/p180.011790.710.001790.7116.041032.30
372021.07.08 17:00sell190.011808.270.001788.55
382021.07.09 21:45sell200.011811.020.001808.80
392021.07.09 22:54t/p200.011808.800.001808.802.221034.52
402021.07.13 06:15sell210.011811.020.001808.06
412021.07.13 08:37t/p210.011808.060.001808.062.961037.48
422021.07.13 10:15sell220.011811.280.001808.84
432021.07.13 11:00close190.011810.250.001788.55-1.361036.12
442021.07.13 11:06t/p220.011808.840.001808.842.441038.56
452021.07.13 16:15sell230.011809.710.001795.17
462021.07.13 20:15sell240.011808.830.001792.53
472021.07.14 15:04close240.011818.830.001792.53-9.791028.76
482021.07.14 15:04close230.011819.710.001795.17-9.791018.97
492021.07.16 22:30sell250.011810.350.001778.15
502021.07.19 09:15sell260.011806.190.001784.27
512021.07.19 18:15sell270.011807.210.001790.91
522021.07.19 23:30sell280.011811.470.001803.69
532021.07.20 04:09close260.011816.190.001784.27-9.791009.17
542021.07.20 04:31close270.011817.210.001790.91-9.79999.38
552021.07.20 15:36close250.011820.350.001778.15-9.59989.79
562021.07.20 15:37close280.011821.470.001803.69-9.79980.00
572021.07.20 18:15sell290.011810.140.001780.96
582021.07.20 20:30sell300.011810.840.001783.06
592021.07.21 10:30sell310.011808.770.001799.15
602021.07.21 15:09t/p310.011799.150.001799.159.62989.62
612021.07.26 10:22close290.011810.150.001780.961.23990.84
622021.07.26 10:24close300.011810.850.001783.061.23992.07
632021.07.30 21:45sell320.011810.450.001768.95
642021.08.02 04:45sell330.011809.440.001774.22
652021.08.02 06:30sell340.011811.380.001786.42
662021.08.02 09:15sell350.011810.310.001797.51
672021.08.02 20:09close330.011819.440.001774.22-10.00982.07
682021.08.03 04:30sell360.011809.740.001790.54
692021.08.04 15:06close360.011819.740.001790.54-9.79972.28
702021.08.04 15:07close350.011820.310.001797.51-9.59962.69
712021.08.04 15:07close320.011820.450.001768.95-9.38953.31
722021.08.04 15:09close340.011821.380.001786.42-9.59943.72
732021.08.04 18:30sell370.011806.630.001756.91
742021.08.04 21:45sell380.011810.860.001769.60
752021.08.05 01:00sell390.011811.890.001772.69
762021.08.05 03:15sell400.011810.920.001769.78
772021.08.06 16:07t/p390.011772.690.001772.6939.41983.13
782021.08.06 16:39t/p400.011769.780.001769.7841.351024.47
792021.08.06 16:39t/p380.011769.600.001769.6042.081066.56
802021.08.09 01:22t/p370.011756.910.001756.9150.751117.31
812021.08.30 18:30sell410.011811.210.001797.55
822021.08.31 16:15sell420.011803.320.001771.96
832021.08.31 16:37close420.011813.320.001771.96-10.001107.31
842021.08.31 18:15sell430.011805.950.001779.85
852021.08.31 20:09close430.011815.950.001779.85-10.001097.31
862021.09.01 11:15sell440.011809.570.001794.93
872021.09.01 15:52close440.011819.570.001794.93-10.001087.31
882021.09.01 18:15sell450.011810.930.001793.05
892021.09.02 07:30sell460.011811.430.001801.71
902021.09.02 12:30close410.011815.680.001797.55-3.441083.87
912021.09.02 17:30sell470.011807.760.001789.30
922021.09.03 04:45sell480.011811.190.001806.13
932021.09.03 15:18close470.011817.760.001789.30-9.791074.07
942021.09.03 15:34close450.011820.930.001793.05-9.181064.90
952021.09.03 15:34close480.011821.190.001806.13-10.001054.90
962021.09.03 15:34close460.011821.430.001801.71-9.791045.10
972021.09.07 13:15sell490.011810.900.001778.58
982021.09.07 16:15sell500.011810.490.001777.53
992021.09.16 12:54t/p490.011778.580.001778.5834.591079.69
1002021.09.16 13:00t/p500.011777.530.001777.5335.231114.92
1012021.10.22 18:30sell510.011800.480.001774.18
1022021.10.28 05:24close510.011800.490.001774.181.231116.14
1032021.11.22 19:45sell520.011810.200.001736.88
1042021.11.23 04:15sell530.011807.780.001740.54
1052021.11.26 09:54close530.011807.790.001740.541.021117.17
1062021.11.26 12:03close520.011810.210.001736.881.231118.39
1072021.11.26 14:30sell540.011809.150.001796.79
1082021.11.26 16:54t/p540.011796.790.001796.7912.361130.75
1092021.12.17 16:00sell550.011806.620.001791.74
1102021.12.20 21:49t/p550.011791.740.001791.7415.091145.84
1112021.12.27 19:15sell560.011809.010.001800.49
1122021.12.27 23:30sell570.011811.240.001807.18
1132021.12.28 02:30sell580.011811.150.001806.91
1142021.12.28 15:24close560.011819.010.001800.49-9.791136.04
1152021.12.28 18:15sell590.011809.840.001789.48
1162021.12.28 20:00sell600.011810.260.001790.74
1172021.12.28 20:51t/p570.011807.180.001807.184.271140.31
1182021.12.28 20:51t/p580.011806.910.001806.914.241144.55
1192021.12.29 15:09t/p600.011790.740.001790.7419.731164.28
1202021.12.31 09:07close590.011819.840.001789.48-8.971155.31
1212022.01.03 16:00sell610.011806.970.001765.87
1222022.01.04 17:39close610.011816.970.001765.87-9.791145.51
1232022.01.05 22:30sell620.011810.000.001771.12
1242022.01.11 08:16close620.011810.010.001771.121.231146.74
1252022.01.18 12:00sell630.011810.270.001785.65
1262022.01.18 15:30sell640.011806.890.001775.51
1272022.01.18 15:37close640.011816.890.001775.51-10.001136.74
1282022.01.18 16:04close630.011820.270.001785.65-10.001126.74
1292022.01.19 05:15sell650.011810.740.001792.48
1302022.01.19 07:00sell660.011811.540.001803.30
1312022.01.19 15:19close650.011820.740.001792.48-10.001116.74
1322022.01.19 15:19close660.011821.540.001803.30-10.001106.74
1332022.01.27 09:00sell670.011810.600.001765.34
1342022.01.27 13:15sell680.011810.700.001788.24
1352022.01.28 12:52t/p680.011788.240.001788.2422.671129.41
1362022.02.02 17:24close670.011810.610.001765.340.811130.22
1372022.02.04 13:45sell690.011810.330.001802.37
1382022.02.04 15:39t/p690.011802.370.001802.377.961138.18
1392022.02.04 16:00sell700.011795.320.001756.60
1402022.02.04 16:39close700.011805.320.001756.60-10.001128.18
1412022.02.07 03:45sell710.011809.750.001799.03
1422022.02.07 10:30sell720.011811.100.001803.08
1432022.02.07 12:30sell730.011811.530.001804.37
1442022.02.07 19:37close710.011819.750.001799.03-10.001118.18
1452022.02.07 20:22close720.011821.100.001803.08-10.001108.18
1462022.02.07 20:24close730.011821.530.001804.37-10.001098.18
1472022.05.13 16:15sell740.011802.800.001751.28
1482022.05.13 17:02close740.011812.800.001751.28-10.001088.18
1492022.05.13 19:00sell750.011808.990.001769.85
1502022.05.16 02:00sell760.011810.840.001791.70
1512022.05.16 06:45sell770.011809.830.001794.67
1522022.05.16 10:43t/p770.011794.670.001794.6715.161103.34
1532022.05.16 10:51t/p760.011791.700.001791.7019.141122.48
1542022.05.16 21:55close750.011819.020.001769.85-9.821112.66
1552022.05.18 06:30sell780.011808.180.001778.32
1562022.05.18 10:00sell790.011809.610.001789.63
1572022.05.18 12:33close780.011818.190.001778.32-10.011102.65
1582022.05.18 12:37close790.011819.610.001789.63-10.001092.65
1592022.05.18 15:15sell800.011808.580.001785.34
1602022.05.18 18:32close800.011818.580.001785.34-10.001082.65
1612022.06.14 19:00sell810.011810.290.001768.19
1622022.06.14 21:30sell820.011810.070.001767.53
1632022.06.15 09:22close820.011820.070.001767.53-9.791072.85
1642022.06.15 09:28close810.011820.290.001768.19-9.791063.06
1652022.06.30 13:45sell830.011810.240.001787.18
1662022.06.30 15:39close830.011820.240.001787.18-10.001053.06
1672022.06.30 18:00sell840.011808.930.001776.99
1682022.06.30 20:00sell850.011809.760.001779.48
1692022.07.04 05:45sell860.011809.120.001799.24
1702022.07.04 07:45sell870.011811.720.001807.04
1712022.07.04 11:39t/p870.011807.040.001807.044.681057.74
1722022.07.05 05:30sell880.011810.210.001806.77
1732022.07.05 10:24t/p880.011806.770.001806.773.441061.18
1742022.07.05 14:18t/p860.011799.240.001799.2410.091071.26
1752022.07.05 17:03t/p850.011779.480.001779.4830.901102.16
1762022.07.05 17:05t/p840.011776.990.001776.9932.561134.72
1772022.12.13 19:45sell890.011809.040.001778.50
1782022.12.13 21:30sell900.011809.730.001780.57
1792022.12.14 04:00sell910.011810.570.001783.09
1802022.12.14 06:15sell920.011809.880.001798.28
1812022.12.14 21:02t/p920.011798.280.001798.2811.601146.32
1822022.12.14 22:45sell930.011808.630.001797.87
1832022.12.15 03:53t/p930.011797.870.001797.8711.381157.70
1842022.12.15 10:12t/p910.011783.090.001783.0928.101185.80
1852022.12.15 10:20t/p900.011780.570.001780.5729.981215.78
1862022.12.15 10:31t/p890.011778.500.001778.5031.361247.15
1872022.12.22 16:15sell940.011807.890.001783.23
1882022.12.27 17:20close940.011817.890.001783.23-9.381237.76
1892022.12.28 02:30sell950.011810.310.001764.09
1902022.12.28 04:30sell960.011810.330.001764.15
1912022.12.28 08:00sell970.011810.300.001787.62
1922022.12.29 20:25close970.011820.300.001787.62-9.381228.38
1932022.12.29 20:25close950.011820.310.001764.09-9.381219.00
1942022.12.29 20:25close960.011820.330.001764.15-9.381209.62
1952023.02.24 18:15sell980.011809.460.001776.14
1962023.02.24 20:00sell990.011809.720.001776.92
1972023.02.24 23:15sell1000.011811.200.001785.56
1982023.02.27 05:30sell1010.011810.190.001799.31
1992023.02.27 17:03close980.011819.460.001776.14-9.791199.83
2002023.02.27 17:03close990.011819.720.001776.92-9.791190.03
2012023.02.27 17:18close1010.011820.190.001799.31-10.001180.03
2022023.02.28 10:00sell1020.011810.360.001792.60
2032023.02.28 12:00sell1030.011810.170.001792.03
2042023.02.28 17:00close1030.011821.220.001792.03-11.051168.98
2052023.02.28 17:00close1020.011821.220.001792.60-10.861158.12
2062023.02.28 17:00close1000.011821.220.001785.56-9.611148.51
2072023.03.08 05:15sell1040.011809.930.001763.01
2082023.03.08 16:48close1040.011819.940.001763.01-10.011138.50
+
diff --git a/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 2.gif b/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 2.gif new file mode 100644 index 0000000..fa9c0ff Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 2.gif differ diff --git a/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 2.htm b/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 2.htm new file mode 100644 index 0000000..4268d4a --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 2.htm @@ -0,0 +1,97 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.07 01:15 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=false; +enableXRShort=true; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xRSwingLength=48; xRSharpDetectionFactor=1350; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63631Ticks modelled72968765Modelling qualityn/a
Mismatched charts errors826
Initial deposit1000.00SpreadCurrent (60)
Total net profit43.39Gross profit91.75Gross loss-48.35
Profit factor1.90Expected payoff3.94
Absolute drawdown1.08Maximal drawdown32.09 (3.09%)Relative drawdown3.09% (32.09)
Total trades11Short positions (won %)11 (54.55%)Long positions (won %)0 (0.00%)
Profit trades (% of total)6 (54.55%)Loss trades (% of total)5 (45.45%)
Largestprofit trade40.11loss trade-10.00
Averageprofit trade15.29loss trade-9.67
Maximumconsecutive wins (profit in money)3 (33.04)consecutive losses (loss in money)2 (-19.59)
Maximalconsecutive profit (count of wins)49.09 (2)consecutive loss (count of losses)-19.59 (2)
Averageconsecutive wins2consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 12:34sell10.011808.470.001798.47
22020.11.27 15:09t/p10.011798.470.001798.4710.001010.00
32021.02.23 09:54sell20.011808.360.001796.34
42021.02.23 14:54sell30.011809.080.001798.06
52021.02.23 16:45t/p30.011798.060.001798.0611.021021.02
62021.02.23 16:48t/p20.011796.340.001796.3412.021033.04
72021.07.13 16:15sell40.011808.460.001793.92
82021.07.13 20:16sell50.011808.250.001791.95
92021.07.14 15:01close50.011818.250.001791.95-9.791023.25
102021.07.14 15:02close40.011818.460.001793.92-9.791013.45
112021.07.21 10:34sell60.011808.650.001799.03
122021.07.21 15:09t/p60.011799.030.001799.039.621023.07
132021.08.03 04:39sell70.011811.070.001794.53
142021.08.04 15:09close70.011821.070.001794.53-9.791013.28
152021.08.05 01:39sell80.011811.540.001771.64
162021.08.05 15:30sell90.011809.510.001800.53
172021.08.05 16:45t/p90.011800.530.001800.538.981022.26
182021.08.06 16:08t/p80.011771.640.001771.6440.111062.36
192021.10.22 18:39sell100.011786.660.001760.36
202021.10.22 19:39close100.011796.660.001760.36-10.001052.36
212021.12.28 18:19sell110.011809.950.001789.81
222021.12.31 09:09close110.011819.950.001789.81-8.971043.39
+
diff --git a/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 3.gif b/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 3.gif new file mode 100644 index 0000000..32e8d5e Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 3.gif differ diff --git a/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 3.htm b/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 3.htm new file mode 100644 index 0000000..6203c5b --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 3.htm @@ -0,0 +1,95 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.07 01:45 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=false; +enableXRShort=true; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xRSwingLength=48; xRSharpDetectionFactor=1350; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63633Ticks modelled72969323Modelling qualityn/a
Mismatched charts errors826
Initial deposit1000.00SpreadCurrent (60)
Total net profit44.66Gross profit83.01Gross loss-38.35
Profit factor2.16Expected payoff4.47
Absolute drawdown12.08Maximal drawdown40.24 (3.91%)Relative drawdown3.91% (40.24)
Total trades10Short positions (won %)10 (60.00%)Long positions (won %)0 (0.00%)
Profit trades (% of total)6 (60.00%)Loss trades (% of total)4 (40.00%)
Largestprofit trade40.11loss trade-9.79
Averageprofit trade13.84loss trade-9.59
Maximumconsecutive wins (profit in money)3 (21.88)consecutive losses (loss in money)3 (-29.38)
Maximalconsecutive profit (count of wins)40.11 (1)consecutive loss (count of losses)-29.38 (3)
Averageconsecutive wins2consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 12:34sell10.011808.470.001798.47
22020.11.27 15:09t/p10.011798.470.001798.4710.001010.00
32021.02.23 14:54sell20.011809.080.001798.06
42021.02.23 16:45t/p20.011798.060.001798.0611.021021.02
52021.07.13 16:15sell30.011808.460.001793.92
62021.07.13 20:16sell40.011808.250.001791.95
72021.07.14 15:01close40.011818.250.001791.95-9.791011.23
82021.07.14 15:02close30.011818.460.001793.92-9.791001.43
92021.08.03 04:39sell50.011811.070.001794.53
102021.08.04 15:09close50.011821.070.001794.53-9.79991.64
112021.08.05 01:39sell60.011811.540.001771.64
122021.08.06 16:08t/p60.011771.640.001771.6440.111031.74
132021.12.28 18:19sell70.011809.950.001789.81
142021.12.31 09:09close70.011819.950.001789.81-8.971022.77
152022.12.14 19:11sell80.011808.980.001804.16
162022.12.14 21:01t/p80.011804.160.001804.164.821027.59
172022.12.14 22:47sell90.011808.170.001797.41
182022.12.15 04:13t/p90.011797.410.001797.4111.381038.97
192023.02.27 14:00sell100.011811.310.001805.83
202023.02.28 10:18t/p100.011805.830.001805.835.691044.66
+
diff --git a/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 4.gif b/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 4.gif new file mode 100644 index 0000000..e109724 Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 4.gif differ diff --git a/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 4.htm b/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 4.htm new file mode 100644 index 0000000..2382333 --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/XR/Short/StrategyTester 4.htm @@ -0,0 +1,174 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.07 17:45 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
Bars in test63697Ticks modelled73031931Modelling qualityn/a
Mismatched charts errors826
Initial deposit1000.00SpreadCurrent (51)
Total net profit64.59Gross profit429.97Gross loss-365.38
Profit factor1.18Expected payoff1.09
Absolute drawdown64.19Maximal drawdown151.17 (13.91%)Relative drawdown13.91% (151.17)
Total trades59Short positions (won %)59 (37.29%)Long positions (won %)0 (0.00%)
Profit trades (% of total)22 (37.29%)Loss trades (% of total)37 (62.71%)
Largestprofit trade50.75loss trade-11.05
Averageprofit trade19.54loss trade-9.88
Maximumconsecutive wins (profit in money)4 (173.59)consecutive losses (loss in money)8 (-80.50)
Maximalconsecutive profit (count of wins)173.59 (4)consecutive loss (count of losses)-80.50 (8)
Averageconsecutive wins2consecutive losses4
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 06:45sell10.011807.850.001793.49
22020.11.27 15:09t/p10.011793.490.001793.4914.361014.36
32021.02.04 16:00sell20.011808.190.001770.49
42021.02.08 01:09close20.011818.190.001770.49-9.591004.77
52021.02.16 15:15sell30.011811.040.001780.54
62021.02.16 18:30sell40.011803.470.001759.29
72021.02.17 15:24t/p30.011780.540.001780.5430.711035.48
82021.02.22 16:37close40.011803.480.001759.291.231036.70
92021.05.13 13:15sell50.011810.390.001785.51
102021.05.13 15:39close50.011820.390.001785.51-10.001026.70
112021.06.17 10:30sell60.011809.210.001747.49
122021.07.06 10:54close60.011809.220.001747.493.491030.20
132021.07.16 22:30sell70.011810.350.001778.15
142021.07.19 09:15sell80.011806.190.001784.27
152021.07.19 18:15sell90.011807.210.001790.91
162021.07.19 23:30sell100.011811.470.001803.69
172021.07.20 04:09close80.011816.190.001784.27-9.791020.40
182021.07.20 04:31close90.011817.210.001790.91-9.791010.61
192021.07.20 15:36close70.011820.350.001778.15-9.591001.02
202021.07.20 15:37close100.011821.470.001803.69-9.79991.23
212021.07.20 18:15sell110.011810.140.001780.96
222021.07.20 20:30sell120.011810.840.001783.06
232021.07.21 10:30sell130.011808.770.001799.15
242021.07.21 15:09t/p130.011799.150.001799.159.621000.85
252021.07.26 10:22close110.011810.150.001780.961.231002.08
262021.07.26 10:24close120.011810.850.001783.061.231003.30
272021.07.30 21:45sell140.011810.450.001768.95
282021.08.02 04:45sell150.011809.440.001774.22
292021.08.02 06:30sell160.011811.380.001786.42
302021.08.02 09:15sell170.011810.310.001797.51
312021.08.02 20:09close150.011819.440.001774.22-10.00993.30
322021.08.03 04:30sell180.011809.740.001790.54
332021.08.04 15:06close180.011819.740.001790.54-9.79983.51
342021.08.04 15:07close170.011820.310.001797.51-9.59973.92
352021.08.04 15:07close140.011820.450.001768.95-9.38964.54
362021.08.04 15:09close160.011821.380.001786.42-9.59954.95
372021.08.04 18:30sell190.011806.630.001756.91
382021.08.04 21:45sell200.011810.860.001769.60
392021.08.05 01:00sell210.011811.890.001772.69
402021.08.05 03:15sell220.011810.920.001769.78
412021.08.06 16:07t/p210.011772.690.001772.6939.41994.36
422021.08.06 16:39t/p220.011769.780.001769.7841.351035.70
432021.08.06 16:39t/p200.011769.600.001769.6042.081077.79
442021.08.09 01:22t/p190.011756.910.001756.9150.751128.54
452021.09.01 11:15sell230.011809.570.001794.93
462021.09.01 15:52close230.011819.570.001794.93-10.001118.54
472021.09.01 18:15sell240.011810.930.001793.05
482021.09.02 07:30sell250.011811.430.001801.71
492021.09.02 17:30sell260.011807.760.001789.30
502021.09.03 04:45sell270.011811.190.001806.13
512021.09.03 15:18close260.011817.760.001789.30-9.791108.74
522021.09.03 15:34close240.011820.930.001793.05-9.181099.57
532021.09.03 15:34close270.011821.190.001806.13-10.001089.57
542021.09.03 15:34close250.011821.430.001801.71-9.791079.77
552021.09.07 13:15sell280.011810.900.001778.58
562021.09.07 16:15sell290.011810.490.001777.53
572021.09.16 12:54t/p280.011778.580.001778.5834.591114.36
582021.09.16 13:00t/p290.011777.530.001777.5335.231149.59
592021.11.22 19:45sell300.011810.200.001736.88
602021.11.23 04:15sell310.011807.780.001740.54
612021.11.26 09:54close310.011807.790.001740.541.021150.61
622021.11.26 12:03close300.011810.210.001736.881.231151.84
632022.01.03 16:00sell320.011806.970.001765.87
642022.01.04 17:39close320.011816.970.001765.87-9.791142.04
652022.01.05 22:30sell330.011810.000.001771.12
662022.01.11 08:16close330.011810.010.001771.121.231143.27
672022.01.18 12:00sell340.011810.270.001785.65
682022.01.18 15:30sell350.011806.890.001775.51
692022.01.18 15:37close350.011816.890.001775.51-10.001133.27
702022.01.18 16:04close340.011820.270.001785.65-10.001123.27
712022.01.19 05:15sell360.011810.740.001792.48
722022.01.19 07:00sell370.011811.540.001803.30
732022.01.19 15:19close360.011820.740.001792.48-10.001113.27
742022.01.19 15:19close370.011821.540.001803.30-10.001103.27
752022.01.27 09:00sell380.011810.600.001765.34
762022.01.27 13:15sell390.011810.700.001788.24
772022.01.28 12:52t/p390.011788.240.001788.2422.671125.93
782022.02.02 17:24close380.011810.610.001765.340.811126.75
792022.05.13 16:15sell400.011802.800.001751.28
802022.05.13 17:02close400.011812.800.001751.28-10.001116.75
812022.05.13 19:00sell410.011808.990.001769.85
822022.05.16 02:00sell420.011810.840.001791.70
832022.05.16 06:45sell430.011809.830.001794.67
842022.05.16 10:43t/p430.011794.670.001794.6715.161131.91
852022.05.16 10:51t/p420.011791.700.001791.7019.141151.05
862022.05.16 21:55close410.011819.020.001769.85-9.821141.23
872022.05.18 06:30sell440.011808.180.001778.32
882022.05.18 10:00sell450.011809.610.001789.63
892022.05.18 12:33close440.011818.190.001778.32-10.011131.22
902022.05.18 12:37close450.011819.610.001789.63-10.001121.22
912022.05.18 15:15sell460.011808.580.001785.34
922022.05.18 18:32close460.011818.580.001785.34-10.001111.22
932022.06.14 19:00sell470.011810.290.001768.19
942022.06.14 21:30sell480.011810.070.001767.53
952022.06.15 09:22close480.011820.070.001767.53-9.791101.42
962022.06.15 09:28close470.011820.290.001768.19-9.791091.63
972022.06.30 13:45sell490.011810.240.001787.18
982022.06.30 15:39close490.011820.240.001787.18-10.001081.63
992022.06.30 18:00sell500.011808.930.001776.99
1002022.06.30 20:00sell510.011809.760.001779.48
1012022.07.05 17:03t/p510.011779.480.001779.4830.901112.53
1022022.07.05 17:05t/p500.011776.990.001776.9932.561145.08
1032022.12.22 16:15sell520.011807.890.001783.23
1042022.12.27 17:20close520.011817.890.001783.23-9.381135.70
1052023.02.24 18:15sell530.011809.460.001776.14
1062023.02.24 20:00sell540.011809.720.001776.92
1072023.02.24 23:15sell550.011811.200.001785.56
1082023.02.27 05:30sell560.011810.190.001799.31
1092023.02.27 17:03close530.011819.460.001776.14-9.791125.91
1102023.02.27 17:03close540.011819.720.001776.92-9.791116.11
1112023.02.27 17:18close560.011820.190.001799.31-10.001106.11
1122023.02.28 10:00sell570.011810.360.001792.60
1132023.02.28 12:00sell580.011810.170.001792.03
1142023.02.28 17:00close580.011821.220.001792.03-11.051095.06
1152023.02.28 17:00close570.011821.220.001792.60-10.861084.20
1162023.02.28 17:00close550.011821.220.001785.56-9.611074.60
1172023.03.08 05:15sell590.011809.930.001763.01
1182023.03.08 16:48close590.011819.940.001763.01-10.011064.59
+
diff --git a/Packed/XAUUSD-15M/Reports/XR/StrategyTester 1 - Full.gif b/Packed/XAUUSD-15M/Reports/XR/StrategyTester 1 - Full.gif new file mode 100644 index 0000000..b08e5bc Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/XR/StrategyTester 1 - Full.gif differ diff --git a/Packed/XAUUSD-15M/Reports/XR/StrategyTester 1 - Full.htm b/Packed/XAUUSD-15M/Reports/XR/StrategyTester 1 - Full.htm new file mode 100644 index 0000000..67b4780 --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/XR/StrategyTester 1 - Full.htm @@ -0,0 +1,297 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.08 10:00 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=true; +xRShortR2R=1.5; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.008; xRLongR2R=1.5; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.008; xRMaximumCandlesPerTrade=96; xRSwingLength=48; xRSharpDetectionFactor=1350; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63758Ticks modelled73078285Modelling qualityn/a
Mismatched charts errors901
Initial deposit1000.00SpreadCurrent (57)
Total net profit210.35Gross profit662.75Gross loss-452.40
Profit factor1.46Expected payoff1.90
Absolute drawdown4.01Maximal drawdown124.53 (9.39%)Relative drawdown9.39% (124.53)
Total trades111Short positions (won %)65 (38.46%)Long positions (won %)46 (34.78%)
Profit trades (% of total)41 (36.94%)Loss trades (% of total)70 (63.06%)
Largestprofit trade46.50loss trade-8.45
Averageprofit trade16.16loss trade-6.46
Maximumconsecutive wins (profit in money)5 (72.43)consecutive losses (loss in money)10 (-52.73)
Maximalconsecutive profit (count of wins)99.30 (4)consecutive loss (count of losses)-55.38 (7)
Averageconsecutive wins3consecutive losses5
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 06:45sell10.011807.850.001797.08
22020.11.27 15:09t/p10.011797.080.001797.0810.771010.77
32020.12.01 19:30buy20.011812.640.001854.00
42020.12.02 02:30buy30.011813.270.001827.96
52020.12.02 08:45buy40.011813.190.001821.26
62020.12.02 10:36t/p40.011821.260.001821.268.071018.84
72020.12.02 12:22t/p30.011827.960.001827.9614.691033.53
82020.12.07 16:52t/p20.011854.000.001854.0038.711072.24
92021.02.04 16:00sell50.011808.190.001779.92
102021.02.05 17:24close50.011808.200.001779.920.201072.43
112021.02.05 19:15buy60.011814.840.001846.28
122021.02.08 01:15buy70.011817.890.001853.91
132021.02.08 04:24close70.011809.890.001853.91-8.001064.43
142021.02.08 07:30buy80.011815.740.001825.94
152021.02.08 10:54close80.011807.740.001825.94-8.001056.43
162021.02.08 11:45buy90.011813.160.001820.63
172021.02.08 13:36t/p90.011820.630.001820.637.471063.90
182021.02.09 11:24t/p60.011846.280.001846.2830.561094.46
192021.02.16 15:15sell100.011811.040.001788.17
202021.02.16 18:30sell110.011803.470.001770.34
212021.02.17 01:09t/p100.011788.170.001788.1723.081117.53
222021.02.17 18:09t/p110.011770.340.001770.3433.341150.87
232021.02.23 04:00buy120.011813.630.001842.78
242021.02.23 05:45buy130.011813.320.001827.80
252021.02.23 11:24close120.011805.630.001842.78-8.001142.87
262021.02.23 11:24close130.011805.320.001827.80-8.001134.87
272021.05.06 18:00buy140.011815.930.001857.47
282021.05.12 23:21close140.011815.910.001857.47-1.791133.08
292021.05.13 13:15sell150.011810.390.001791.73
302021.05.13 15:36close150.011818.390.001791.73-8.001125.08
312021.06.17 10:30sell160.011809.210.001762.92
322021.06.18 22:54t/p160.011762.920.001762.9246.501171.58
332021.07.08 14:00buy170.011817.770.001849.41
342021.07.08 16:39close170.011809.770.001849.41-8.001163.58
352021.07.13 15:30buy180.011813.580.001824.58
362021.07.13 15:31close180.011805.570.001824.58-8.011155.57
372021.07.13 18:15buy190.011812.850.001833.61
382021.07.14 03:09close190.011804.840.001833.61-8.451147.11
392021.07.14 06:30buy200.011813.440.001826.16
402021.07.14 08:30buy210.011813.820.001827.11
412021.07.14 10:45buy220.011813.940.001827.41
422021.07.14 15:09t/p200.011826.160.001826.1612.721159.83
432021.07.14 15:37t/p210.011827.110.001827.1113.291173.12
442021.07.14 15:37t/p220.011827.410.001827.4113.471186.59
452021.07.16 22:30sell230.011810.350.001786.20
462021.07.19 09:15sell240.011806.190.001789.75
472021.07.19 16:18close240.011814.190.001789.75-8.001178.59
482021.07.19 18:15sell250.011807.210.001794.99
492021.07.19 23:30sell260.011811.470.001805.64
502021.07.19 23:30close230.011812.040.001786.20-1.481177.11
512021.07.20 03:00sell270.011811.350.001805.34
522021.07.20 04:06close250.011815.210.001794.99-7.791169.32
532021.07.20 05:08close270.011819.350.001805.34-8.001161.32
542021.07.20 05:18close260.011819.470.001805.64-7.791153.52
552021.07.20 18:15sell280.011810.140.001788.26
562021.07.20 20:30sell290.011810.840.001790.01
572021.07.21 10:30sell300.011808.770.001801.56
582021.07.21 14:03t/p300.011801.560.001801.567.211160.73
592021.07.23 10:54close280.011810.150.001788.261.021161.75
602021.07.23 14:34t/p290.011790.010.001790.0121.861183.61
612021.07.29 04:30buy310.011816.190.001851.05
622021.07.30 19:51close310.011816.180.001851.05-0.451183.16
632021.07.30 21:45sell320.011810.450.001779.33
642021.08.02 04:45sell330.011809.440.001783.03
652021.08.02 06:30sell340.011811.380.001792.66
662021.08.02 09:15sell350.011810.310.001800.71
672021.08.02 19:36close330.011817.440.001783.03-8.001175.16
682021.08.02 19:39close350.011818.310.001800.71-8.001167.16
692021.08.02 19:52close320.011818.450.001779.33-7.791159.37
702021.08.02 20:07close340.011819.380.001792.66-8.001151.37
712021.08.03 04:30sell360.011809.740.001795.34
722021.08.03 06:15sell370.011810.010.001796.02
732021.08.03 08:15sell380.011810.150.001796.37
742021.08.03 12:00sell390.011810.640.001805.50
752021.08.04 05:30close360.011813.440.001795.34-3.491147.87
762021.08.04 07:15close370.011812.810.001796.02-2.591145.28
772021.08.04 09:15close380.011813.010.001796.37-2.651142.63
782021.08.04 13:00close390.011815.210.001805.50-4.361138.26
792021.08.04 18:30sell400.011806.630.001769.34
802021.08.04 21:45sell410.011810.860.001779.92
812021.08.05 01:00sell420.011811.890.001782.49
822021.08.05 03:15sell430.011810.920.001780.07
832021.08.05 10:54close400.011814.630.001769.34-7.381130.88
842021.08.05 11:30sell440.011809.830.001802.96
852021.08.05 16:39t/p440.011802.960.001802.966.871137.75
862021.08.06 15:39t/p420.011782.490.001782.4929.611167.36
872021.08.06 15:39t/p430.011780.070.001780.0731.061198.41
882021.08.06 15:39t/p410.011779.920.001779.9231.761230.18
892021.08.27 19:15buy450.011814.940.001860.72
902021.08.30 20:15close450.011810.010.001860.72-5.371224.80
912021.08.31 04:30buy460.011814.040.001822.85
922021.08.31 14:15buy470.011814.290.001820.49
932021.08.31 16:06close470.011806.290.001820.49-8.001216.80
942021.08.31 16:06close460.011806.040.001822.85-8.001208.80
952021.08.31 20:00buy480.011814.350.001832.70
962021.09.01 04:30buy490.011812.970.001829.25
972021.09.01 11:15sell500.011809.570.001798.59
982021.09.01 15:39close500.011817.570.001798.59-8.001200.80
992021.09.01 18:15sell510.011810.930.001797.52
1002021.09.01 21:00close480.011812.490.001832.70-2.301198.50
1012021.09.02 06:04close490.011812.960.001829.25-1.341197.17
1022021.09.02 07:30sell520.011811.430.001804.14
1032021.09.02 17:30sell530.011807.760.001793.92
1042021.09.02 21:07close510.011810.940.001797.520.611197.77
1052021.09.03 04:45sell540.011811.190.001807.40
1062021.09.03 07:45sell550.011811.510.001806.85
1072021.09.03 08:30close520.011811.860.001804.14-0.221197.55
1082021.09.03 15:06close530.011815.760.001793.92-7.791189.76
1092021.09.03 15:34close540.011819.190.001807.40-8.001181.76
1102021.09.03 15:34close550.011819.510.001806.85-8.001173.76
1112021.09.07 13:15sell560.011810.900.001786.66
1122021.09.07 16:15sell570.011810.490.001785.77
1132021.09.08 16:54t/p560.011786.660.001786.6624.451198.20
1142021.09.08 16:54t/p570.011785.770.001785.7724.931223.13
1152021.11.05 18:45buy580.011814.390.001857.82
1162021.11.10 16:24t/p580.011857.820.001857.8242.101265.23
1172021.11.22 19:45sell590.011810.200.001755.21
1182021.11.23 04:15sell600.011807.780.001757.35
1192021.11.26 09:54close600.011807.790.001757.351.021266.25
1202021.11.26 11:55close590.011810.210.001755.211.231267.48
1212021.12.27 18:00buy610.011813.040.001827.67
1222021.12.28 08:00buy620.011813.260.001822.55
1232021.12.28 17:00buy630.011814.210.001821.41
1242021.12.28 19:00close610.011810.530.001827.67-2.951264.53
1252021.12.28 20:52close630.011806.210.001821.41-8.001256.53
1262021.12.28 20:54close620.011805.250.001822.55-8.011248.52
1272021.12.30 19:00buy640.011813.880.001839.91
1282022.01.03 15:09close640.011813.860.001839.91-0.901247.61
1292022.01.03 16:00sell650.011806.970.001776.15
1302022.01.04 17:00close650.011811.780.001776.15-4.601243.01
1312022.01.04 17:45buy660.011817.070.001844.28
1322022.01.04 19:30buy670.011814.650.001838.23
1332022.01.05 21:09close660.011817.050.001844.28-0.461242.55
1342022.01.05 21:09close670.011814.640.001838.23-0.451242.09
1352022.01.05 22:30sell680.011810.000.001780.84
1362022.01.11 08:09close680.011810.010.001780.841.231243.32
1372022.01.11 18:30buy690.011815.730.001836.09
1382022.01.13 17:51close690.011815.720.001836.09-1.781241.54
1392022.01.18 12:00sell700.011810.270.001791.81
1402022.01.18 15:30sell710.011806.890.001783.36
1412022.01.18 15:34close710.011814.890.001783.36-8.001233.54
1422022.01.18 15:37close700.011818.270.001791.81-8.001225.54
1432022.01.19 05:15sell720.011810.740.001797.05
1442022.01.19 07:00sell730.011811.540.001805.36
1452022.01.19 12:35close720.011818.740.001797.05-8.001217.54
1462022.01.19 12:39close730.011819.540.001805.36-8.001209.54
1472022.01.27 09:00sell740.011810.600.001776.66
1482022.01.27 13:15sell750.011810.700.001793.86
1492022.01.27 18:24t/p750.011793.860.001793.8616.841226.38
1502022.02.02 17:24close740.011810.610.001776.660.811227.19
1512022.02.04 12:30buy760.011814.080.001827.73
1522022.02.04 15:30buy770.011813.350.001824.12
1532022.02.04 15:36close760.011806.080.001827.73-8.001219.19
1542022.02.04 15:36close770.011805.350.001824.12-8.001211.19
1552022.02.07 02:45buy780.011812.860.001843.39
1562022.02.07 11:00buy790.011813.430.001822.99
1572022.02.07 14:00buy800.011813.990.001821.24
1582022.02.07 16:15buy810.011816.160.001826.63
1592022.02.07 21:06t/p800.011821.240.001821.247.251218.44
1602022.02.07 21:39t/p790.011822.990.001822.999.561228.00
1612022.02.08 17:24t/p810.011826.630.001826.6310.031238.03
1622022.02.11 20:34t/p780.011843.390.001843.3927.881265.91
1632022.05.13 16:15sell820.011802.800.001764.16
1642022.05.13 17:01close820.011810.800.001764.16-8.001257.91
1652022.05.13 19:00sell830.011808.990.001779.64
1662022.05.16 02:00sell840.011810.840.001796.49
1672022.05.16 04:08close830.011817.000.001779.64-7.801250.10
1682022.05.16 06:45sell850.011809.830.001798.46
1692022.05.16 10:42t/p850.011798.460.001798.4611.371261.47
1702022.05.16 10:43t/p840.011796.490.001796.4914.351275.82
1712022.05.18 06:30sell860.011808.180.001785.79
1722022.05.18 10:00sell870.011809.610.001794.63
1732022.05.18 10:31close860.011816.190.001785.79-8.011267.81
1742022.05.18 12:32close870.011817.620.001794.63-8.011259.80
1752022.05.18 15:15sell880.011808.580.001791.15
1762022.05.18 18:08close880.011816.580.001791.15-8.001251.80
1772022.06.14 19:00sell890.011810.290.001778.72
1782022.06.14 21:30sell900.011810.070.001778.17
1792022.06.15 05:31close900.011818.070.001778.17-7.791244.01
1802022.06.15 05:31close890.011818.290.001778.72-7.791236.22
1812022.06.30 13:45sell910.011810.240.001792.95
1822022.06.30 15:37close910.011818.240.001792.95-8.001228.22
1832022.06.30 18:00sell920.011808.930.001784.98
1842022.06.30 20:00sell930.011809.760.001787.05
1852022.07.01 14:39t/p930.011787.050.001787.0522.921251.13
1862022.07.01 15:25t/p920.011784.980.001784.9824.161275.29
1872022.12.13 16:30buy940.011818.950.001875.17
1882022.12.13 17:48close940.011810.950.001875.17-8.001267.29
1892022.12.13 18:45buy950.011813.330.001859.10
1902022.12.13 19:25close950.011805.330.001859.10-8.001259.29
1912022.12.20 17:15buy960.011820.900.001871.32
1922022.12.21 07:23close960.011812.900.001871.32-8.441250.85
1932022.12.21 09:30buy970.011815.410.001820.20
1942022.12.21 14:00buy980.011814.120.001816.97
1952022.12.21 15:13t/p980.011816.970.001816.972.851253.70
1962022.12.21 17:07t/p970.011820.200.001820.204.791258.49
1972022.12.22 16:15sell990.011807.890.001789.40
1982022.12.22 20:02t/p990.011789.400.001789.4018.491276.98
1992022.12.27 17:30buy1000.011821.760.001850.40
2002022.12.27 19:56close1000.011813.760.001850.40-8.001268.98
2012022.12.27 20:15buy1010.011815.050.001833.62
2022022.12.28 03:30buy1020.011814.710.001832.77
2032022.12.28 10:08close1010.011807.040.001833.62-8.451260.52
2042022.12.28 10:08close1020.011806.710.001832.77-8.001252.52
2052022.12.29 17:00buy1030.011814.370.001828.82
2062022.12.29 18:45buy1040.011814.740.001829.74
2072022.12.30 18:38close1030.011814.350.001828.82-0.461252.06
2082023.01.03 01:07t/p1040.011829.740.001829.7413.671265.74
2092023.02.24 18:15sell1050.011809.460.001784.47
2102023.02.24 20:00sell1060.011809.720.001785.12
2112023.02.24 23:15sell1070.011811.200.001791.97
2122023.02.27 05:30sell1080.011810.190.001802.03
2132023.02.27 16:23close1050.011817.460.001784.47-7.791257.94
2142023.02.27 16:23close1060.011817.720.001785.12-7.791250.15
2152023.02.27 16:55close1080.011818.190.001802.03-8.001242.15
2162023.02.27 16:57close1070.011819.200.001791.97-7.791234.35
2172023.02.28 10:00sell1090.011810.360.001797.04
2182023.02.28 12:00sell1100.011810.170.001796.57
2192023.02.28 16:47close1100.011818.170.001796.57-8.001226.35
2202023.02.28 16:47close1090.011818.360.001797.04-8.001218.35
2212023.03.08 05:15sell1110.011809.930.001774.74
2222023.03.08 16:32close1110.011817.930.001774.74-8.001210.35
+
diff --git a/Packed/XAUUSD-15M/Reports/XR/StrategyTester 2 - 0.2 - Full.gif b/Packed/XAUUSD-15M/Reports/XR/StrategyTester 2 - 0.2 - Full.gif new file mode 100644 index 0000000..0ce41b5 Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/XR/StrategyTester 2 - 0.2 - Full.gif differ diff --git a/Packed/XAUUSD-15M/Reports/XR/StrategyTester 2 - 0.2 - Full.htm b/Packed/XAUUSD-15M/Reports/XR/StrategyTester 2 - 0.2 - Full.htm new file mode 100644 index 0000000..73d7435 --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/XR/StrategyTester 2 - 0.2 - Full.htm @@ -0,0 +1,301 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.08 11:00 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=true; +xRShortR2R=1.5; xRShortLotsPerTradePercent=0.0002; xRShortMaxDrawdownPerTradePercent=0.15; xRLongR2R=1.5; xRLongLotsPerTradePercent=0.0002; xRLongMaxDrawdownPerTradePercent=0.15; xRMaximumCandlesPerTrade=96; xRSwingLength=48; xRSharpDetectionFactor=1350; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63762Ticks modelled73083601Modelling qualityn/a
Mismatched charts errors902
Initial deposit1000.00SpreadCurrent (50)
Total net profit3076.78Gross profit11645.54Gross loss-8568.76
Profit factor1.36Expected payoff27.23
Absolute drawdown78.80Maximal drawdown2946.14 (44.93%)Relative drawdown44.93% (2946.14)
Total trades113Short positions (won %)66 (46.97%)Long positions (won %)47 (25.53%)
Profit trades (% of total)43 (38.05%)Loss trades (% of total)70 (61.95%)
Largestprofit trade929.92loss trade-159.05
Averageprofit trade270.83loss trade-122.41
Maximumconsecutive wins (profit in money)6 (2894.35)consecutive losses (loss in money)9 (-793.75)
Maximalconsecutive profit (count of wins)2894.35 (6)consecutive loss (count of losses)-1042.16 (7)
Averageconsecutive wins2consecutive losses4
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 06:45sell10.201807.850.001797.08
22020.11.27 15:09t/p10.201797.080.001797.08215.401215.40
32020.11.27 15:09sell20.201796.570.001788.89
42020.11.27 15:36t/p20.201788.890.001788.89153.601369.00
52020.12.01 19:30buy30.201812.570.001853.93
62020.12.02 10:39buy40.201824.800.001839.41
72020.12.02 14:45close40.201817.290.001839.41-150.201218.80
82020.12.07 16:52t/p30.201853.930.001853.93774.121992.92
92021.02.04 16:00sell50.201808.190.001779.92
102021.02.05 17:24close50.201808.200.001779.923.921996.85
112021.02.05 19:15buy60.201814.770.001846.21
122021.02.08 14:48buy70.201823.880.001843.17
132021.02.09 09:54t/p70.201843.170.001843.17376.952373.80
142021.02.09 11:24t/p60.201846.210.001846.21611.112984.91
152021.02.16 15:15sell80.201811.040.001788.17
162021.02.16 18:30sell90.201803.470.001770.34
172021.02.17 01:09t/p80.201788.170.001788.17461.523446.43
182021.02.17 18:09t/p90.201770.340.001770.34666.724113.15
192021.02.23 04:00buy100.201813.560.001842.71
202021.02.23 05:45buy110.201813.250.001827.73
212021.02.23 11:24close100.201806.060.001842.71-150.003963.15
222021.02.23 11:24close110.201805.750.001827.73-150.003813.15
232021.02.23 11:24buy120.201806.240.001820.63
242021.02.23 16:38close120.201798.740.001820.63-150.003663.15
252021.05.06 18:00buy130.201815.860.001857.40
262021.05.12 23:21close130.201815.850.001857.40-35.583627.57
272021.05.13 13:15sell140.201810.390.001791.73
282021.05.13 15:08close140.201817.890.001791.73-150.003477.57
292021.05.13 15:08sell150.201817.380.001809.21
302021.05.13 17:52close150.201824.880.001809.21-150.003327.57
312021.06.17 10:30sell160.201809.210.001762.92
322021.06.18 22:54t/p160.201762.920.001762.92929.924257.49
332021.07.08 14:00buy170.201817.700.001849.34
342021.07.08 16:39close170.201810.200.001849.34-150.004107.49
352021.07.13 15:30buy180.201813.510.001824.51
362021.07.13 15:30close180.201806.000.001824.51-150.203957.29
372021.07.13 18:15buy190.201812.780.001833.54
382021.07.13 21:09close190.201805.280.001833.54-150.003807.29
392021.07.14 06:30buy200.201813.370.001826.09
402021.07.14 08:30buy210.201813.750.001827.04
412021.07.14 15:06buy220.201822.680.001840.68
422021.07.14 15:09t/p200.201826.090.001826.09254.404061.69
432021.07.14 15:37t/p210.201827.040.001827.04265.804327.49
442021.07.15 16:00close220.201822.670.001840.68-26.744300.75
452021.07.16 22:30sell230.201810.350.001786.20
462021.07.19 09:15sell240.201806.190.001789.75
472021.07.19 14:54sell250.201800.540.001777.82
482021.07.19 15:52close250.201808.040.001777.82-150.004150.75
492021.07.19 16:09close240.201813.690.001789.75-150.004000.75
502021.07.19 18:15sell260.201807.210.001794.99
512021.07.19 23:30close230.201811.970.001786.20-28.283972.47
522021.07.20 04:04close260.201814.710.001794.99-145.883826.60
532021.07.20 04:04sell270.201814.220.001812.51
542021.07.20 11:09t/p270.201812.510.001812.5134.203860.80
552021.07.20 18:15sell280.201810.140.001788.26
562021.07.20 20:30sell290.201810.840.001790.01
572021.07.21 13:54sell300.201801.740.001784.64
582021.07.22 15:36close300.201801.750.001784.6412.173872.96
592021.07.23 10:54close280.201810.150.001788.2620.413893.37
602021.07.23 14:34t/p290.201790.010.001790.01437.214330.58
612021.07.29 04:30buy310.201816.120.001850.98
622021.07.30 19:52close310.201816.110.001850.98-9.054321.54
632021.07.30 21:45sell320.201810.450.001779.33
642021.08.02 04:45sell330.201809.440.001783.03
652021.08.02 19:24close330.201816.940.001783.03-150.004171.54
662021.08.02 19:39close320.201817.950.001779.33-145.884025.66
672021.08.02 19:39sell340.201817.460.001799.73
682021.08.03 04:30sell350.201809.740.001795.34
692021.08.04 05:30close350.201813.370.001795.34-68.483957.18
702021.08.04 05:30sell360.201812.880.001810.08
712021.08.04 14:36close340.201817.470.001799.738.043965.22
722021.08.04 15:07close360.201820.380.001810.08-150.003815.22
732021.08.04 18:30sell370.201806.630.001769.34
742021.08.05 10:52close370.201814.130.001769.34-137.633677.59
752021.08.05 10:52sell380.201813.640.001805.63
762021.08.05 15:30sell390.201810.170.001803.44
772021.08.05 16:37t/p380.201805.630.001805.63160.203837.79
782021.08.05 16:39t/p390.201803.440.001803.44134.603972.39
792021.08.27 19:15buy400.201814.870.001860.65
802021.08.30 20:15close400.201810.010.001860.65-106.053866.34
812021.08.31 04:30buy410.201813.970.001822.78
822021.08.31 14:15buy420.201814.220.001820.42
832021.08.31 16:06close420.201806.720.001820.42-150.003716.34
842021.08.31 16:06close410.201806.470.001822.78-150.003566.34
852021.08.31 16:06buy430.201806.960.001825.02
862021.08.31 20:00buy440.201814.280.001832.63
872021.09.01 21:00close440.201812.490.001832.63-44.653521.70
882021.09.01 21:00sell450.201812.480.001801.41
892021.09.02 07:30sell460.201811.430.001804.14
902021.09.02 17:09close430.201806.950.001825.02-35.583486.11
912021.09.03 04:07close450.201812.490.001801.4116.293502.40
922021.09.03 04:39sell470.201810.530.001806.77
932021.09.03 08:30close460.201811.790.001804.14-3.083499.32
942021.09.03 15:34close470.201818.030.001806.77-150.003349.32
952021.09.03 15:34sell480.201817.540.001806.17
962021.09.03 15:37close480.201825.040.001806.17-150.003199.32
972021.09.07 13:15sell490.201810.900.001786.66
982021.09.07 17:01sell500.201808.280.001782.29
992021.09.08 16:54t/p490.201786.660.001786.66488.923688.25
1002021.09.14 15:30t/p500.201782.290.001782.29548.654236.90
1012021.11.05 18:45buy510.201814.320.001857.75
1022021.11.10 16:24t/p510.201857.750.001857.75842.065078.96
1032021.11.22 19:45sell520.201810.200.001755.21
1042021.11.23 04:15sell530.201807.780.001757.35
1052021.11.23 08:48sell540.201803.200.001790.24
1062021.11.23 15:07t/p540.201790.240.001790.24259.205338.16
1072021.11.26 09:54close530.201807.790.001757.3520.415358.57
1082021.11.26 12:03close520.201810.210.001755.2124.535383.10
1092021.12.27 18:00buy550.201812.970.001827.60
1102021.12.28 08:00buy560.201813.190.001822.48
1112021.12.28 13:01buy570.201818.480.001832.73
1122021.12.28 16:09close570.201810.980.001832.73-150.005233.10
1132021.12.28 19:00close550.201810.530.001827.60-57.655175.46
1142021.12.28 19:00buy580.201811.040.001813.04
1152021.12.28 20:54close560.201805.680.001822.48-150.205025.26
1162021.12.29 10:07close580.201803.540.001813.04-158.854866.41
1172021.12.30 19:00buy590.201813.810.001839.84
1182022.01.03 15:09close590.201813.790.001839.84-18.094848.32
1192022.01.03 16:00sell600.201806.970.001776.15
1202022.01.04 17:00close600.201811.710.001776.15-90.684757.64
1212022.01.04 17:45buy610.201817.000.001844.21
1222022.01.04 19:30buy620.201814.580.001838.16
1232022.01.05 15:30buy630.201823.000.001835.98
1242022.01.05 21:09close610.201816.980.001844.21-9.254748.40
1252022.01.05 21:09close630.201815.500.001835.98-150.004598.40
1262022.01.05 21:09close620.201814.570.001838.16-9.054589.35
1272022.01.05 22:30sell640.201810.000.001780.84
1282022.01.11 08:16close640.201810.010.001780.8424.534613.88
1292022.01.11 18:30buy650.201815.660.001836.02
1302022.01.13 17:51close650.201815.650.001836.02-35.584578.30
1312022.01.18 12:00sell660.201810.270.001791.81
1322022.01.18 15:30sell670.201806.890.001783.36
1332022.01.18 15:34close670.201814.390.001783.36-150.004428.30
1342022.01.18 15:37close660.201817.770.001791.81-150.004278.30
1352022.01.19 05:15sell680.201810.740.001797.05
1362022.01.19 07:00sell690.201811.540.001805.36
1372022.01.19 12:34close680.201818.240.001797.05-150.004128.30
1382022.01.19 12:37close690.201819.040.001805.36-150.003978.30
1392022.01.19 12:37sell700.201818.550.001805.80
1402022.01.19 16:37close700.201826.050.001805.80-150.003828.30
1412022.01.27 09:00sell710.201810.600.001776.66
1422022.01.27 13:15sell720.201810.700.001793.86
1432022.01.27 15:49sell730.201801.610.001779.70
1442022.01.27 16:39close730.201809.110.001779.70-150.003678.30
1452022.01.27 18:24t/p720.201793.860.001793.86336.804015.10
1462022.02.02 17:24close710.201810.610.001776.6616.294031.39
1472022.02.04 12:30buy740.201814.010.001827.66
1482022.02.04 15:30buy750.201813.280.001824.05
1492022.02.04 15:36close740.201806.510.001827.66-150.003881.39
1502022.02.04 15:36close750.201805.780.001824.05-150.003731.39
1512022.02.07 02:45buy760.201812.790.001843.32
1522022.02.07 11:00buy770.201813.360.001822.92
1532022.02.07 21:24buy780.201822.380.001840.10
1542022.02.07 21:37t/p770.201822.920.001822.92191.203922.59
1552022.02.10 15:33close780.201822.370.001840.10-44.433878.16
1562022.02.11 20:34t/p760.201843.320.001843.32557.524435.68
1572022.05.13 16:15sell790.201802.800.001764.16
1582022.05.13 17:01close790.201810.310.001764.16-150.204285.48
1592022.05.13 19:00sell800.201808.990.001779.64
1602022.05.16 02:00sell810.201810.840.001796.49
1612022.05.16 03:58close800.201816.500.001779.64-146.084139.40
1622022.05.16 05:01sell820.201812.910.001807.12
1632022.05.16 08:05t/p820.201807.120.001807.12115.804255.20
1642022.05.16 08:05sell830.201806.620.001791.70
1652022.05.16 10:43t/p810.201796.490.001796.49287.004542.20
1662022.05.16 10:51t/p830.201791.700.001791.70298.404840.60
1672022.05.18 06:30sell840.201808.180.001785.79
1682022.05.18 10:00sell850.201809.610.001794.63
1692022.05.18 10:28close840.201815.680.001785.79-150.004690.60
1702022.05.18 11:12close850.201817.120.001794.63-150.204540.40
1712022.05.18 15:15sell860.201808.580.001791.15
1722022.05.18 16:43close860.201816.080.001791.15-150.004390.40
1732022.06.14 19:00sell870.201810.290.001778.72
1742022.06.14 21:30sell880.201810.070.001778.17
1752022.06.15 04:38close880.201817.580.001778.17-146.084244.32
1762022.06.15 05:20close870.201817.790.001778.72-145.884098.45
1772022.06.15 05:20sell890.201817.300.001812.70
1782022.06.15 12:40close890.201824.800.001812.70-150.003948.45
1792022.06.30 13:45sell900.201810.240.001792.95
1802022.06.30 15:37close900.201817.740.001792.95-150.003798.45
1812022.06.30 18:00sell910.201808.930.001784.98
1822022.06.30 20:06sell920.201809.330.001786.62
1832022.07.01 08:31sell930.201800.240.001786.49
1842022.07.01 14:39t/p920.201786.620.001786.62458.324256.77
1852022.07.01 14:39t/p930.201786.490.001786.49275.004531.77
1862022.07.01 15:24t/p910.201784.980.001784.98483.125014.89
1872022.12.13 16:30buy940.201818.880.001875.10
1882022.12.13 17:47close940.201811.380.001875.10-150.004864.89
1892022.12.13 18:45buy950.201813.260.001859.03
1902022.12.13 19:25close950.201805.760.001859.03-150.004714.89
1912022.12.20 17:15buy960.201820.830.001871.25
1922022.12.21 06:43close960.201813.330.001871.25-158.854556.04
1932022.12.21 09:30buy970.201815.340.001820.13
1942022.12.21 14:00buy980.201814.050.001816.90
1952022.12.21 15:13t/p980.201816.900.001816.9057.004613.04
1962022.12.21 17:07t/p970.201820.130.001820.1395.804708.84
1972022.12.22 16:15sell990.201807.890.001789.40
1982022.12.22 20:02t/p990.201789.400.001789.40369.805078.64
1992022.12.27 17:30buy1000.201821.690.001850.33
2002022.12.27 19:56close1000.201814.190.001850.33-150.004928.64
2012022.12.27 20:15buy1010.201814.980.001833.55
2022022.12.28 03:30buy1020.201814.640.001832.70
2032022.12.28 09:03close1010.201807.470.001833.55-159.054769.60
2042022.12.28 09:16buy1030.201809.440.001810.49
2052022.12.28 10:00t/p1030.201810.490.001810.4921.004790.60
2062022.12.28 10:08close1020.201807.130.001832.70-150.204640.40
2072022.12.29 17:00buy1040.201814.300.001828.75
2082022.12.29 18:45buy1050.201814.670.001829.67
2092022.12.30 09:01buy1060.201821.980.001831.55
2102022.12.30 12:31close1060.201814.470.001831.55-150.204490.20
2112022.12.30 18:38close1040.201814.280.001828.75-9.254480.95
2122023.01.03 01:07t/p1050.201829.670.001829.67273.464754.41
2132023.02.24 18:15sell1070.201809.460.001784.47
2142023.02.24 20:00sell1080.201809.720.001785.12
2152023.02.27 16:00close1070.201816.960.001784.47-145.884608.54
2162023.02.27 16:08sell1090.201814.370.001811.82
2172023.02.27 16:22close1080.201817.220.001785.12-145.884462.66
2182023.02.28 09:22t/p1090.201811.820.001811.8255.124517.78
2192023.02.28 10:00sell1100.201810.360.001797.04
2202023.02.28 12:00sell1110.201810.170.001796.57
2212023.02.28 16:46close1110.201817.670.001796.57-150.004367.78
2222023.02.28 16:47close1100.201817.860.001797.04-150.004217.78
2232023.02.28 16:47sell1120.201817.370.001816.92
2242023.02.28 16:51t/p1120.201816.920.001816.929.004226.78
2252023.03.08 05:15sell1130.201809.930.001774.74
2262023.03.08 16:32close1130.201817.430.001774.74-150.004076.78
+
diff --git a/Packed/XAUUSD-15M/Reports/XTPW/Full/StrategyTester 1.gif b/Packed/XAUUSD-15M/Reports/XTPW/Full/StrategyTester 1.gif new file mode 100644 index 0000000..dabf25d Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/XTPW/Full/StrategyTester 1.gif differ diff --git a/Packed/XAUUSD-15M/Reports/XTPW/Full/StrategyTester 1.htm b/Packed/XAUUSD-15M/Reports/XTPW/Full/StrategyTester 1.htm new file mode 100644 index 0000000..e6ae90d --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/XTPW/Full/StrategyTester 1.htm @@ -0,0 +1,169 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.01 23:45 (2020.01.01 - 2023.08.02)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63353Ticks modelled72601176Modelling qualityn/a
Mismatched charts errors808
Initial deposit1000.00SpreadCurrent (57)
Total net profit209.11Gross profit297.85Gross loss-88.73
Profit factor3.36Expected payoff4.18
Absolute drawdown5.97Maximal drawdown30.04 (2.64%)Relative drawdown2.64% (30.04)
Total trades50Short positions (won %)35 (85.71%)Long positions (won %)15 (93.33%)
Profit trades (% of total)44 (88.00%)Loss trades (% of total)6 (12.00%)
Largestprofit trade22.02loss trade-15.49
Averageprofit trade6.77loss trade-14.79
Maximumconsecutive wins (profit in money)10 (74.81)consecutive losses (loss in money)1 (-15.49)
Maximalconsecutive profit (count of wins)74.81 (10)consecutive loss (count of losses)-15.49 (1)
Averageconsecutive wins6consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 17:39sell10.011836.610.001825.20
22020.12.07 10:37t/p10.011825.200.001825.2011.631011.63
32021.01.29 16:54sell20.011865.800.001855.99
42021.01.29 19:22t/p20.011855.990.001855.999.811021.44
52021.02.09 17:45sell30.011841.990.001838.33
62021.02.09 18:09t/p30.011838.330.001838.333.661025.10
72021.02.10 17:00sell40.011841.300.001827.41
82021.02.11 19:09t/p40.011827.410.001827.4114.551039.65
92021.02.16 17:09sell50.011804.040.001801.47
102021.02.16 18:49t/p50.011801.470.001801.472.571042.22
112021.03.03 16:51sell60.011712.530.001708.07
122021.03.03 17:36t/p60.011708.070.001708.074.461046.68
132021.03.11 16:48buy70.011719.900.001728.00
142021.03.11 20:09t/p70.011728.000.001728.008.101054.78
152021.03.17 13:48buy80.011728.340.001737.00
162021.03.17 20:06t/p80.011737.000.001737.008.661063.44
172021.04.19 15:15buy90.011775.900.001781.90
182021.04.21 04:39t/p90.011781.900.001781.905.031068.46
192021.04.27 18:24buy100.011778.420.001784.35
202021.04.28 12:24close100.011763.420.001784.35-15.491052.98
212021.05.10 17:45sell110.011839.580.001833.85
222021.05.11 03:39t/p110.011833.850.001833.855.951058.93
232021.05.19 22:00buy120.011863.460.001881.95
242021.05.20 19:49t/p120.011881.950.001881.9517.031075.96
252021.07.06 19:07buy130.011794.080.001807.68
262021.07.07 13:24t/p130.011807.680.001807.6813.111089.07
272021.07.08 18:04buy140.011801.930.001814.59
282021.07.13 15:39t/p140.011814.590.001814.5911.201100.27
292021.07.13 17:21sell150.011811.750.001808.46
302021.07.13 20:37t/p150.011808.460.001808.463.291103.56
312021.08.17 17:15buy160.011782.680.001787.76
322021.08.18 04:09t/p160.011787.760.001787.764.591108.16
332021.08.20 17:39sell170.011781.750.001777.75
342021.08.23 03:16t/p170.011777.750.001777.754.221112.38
352021.08.31 15:30sell180.011811.860.001809.11
362021.08.31 16:04t/p180.011809.110.001809.112.751115.13
372021.10.27 18:09sell190.011793.560.001789.11
382021.10.28 16:30close190.011808.560.001789.11-14.341100.78
392021.11.03 04:00sell200.011783.060.001779.26
402021.11.03 08:15t/p200.011779.260.001779.263.801104.58
412021.11.30 17:48sell210.011794.770.001781.02
422021.11.30 18:04t/p210.011781.020.001781.0213.751118.33
432021.12.13 16:49sell220.011785.140.001782.99
442021.12.14 10:24t/p220.011782.990.001782.992.371120.70
452021.12.15 16:54sell230.011769.740.001766.01
462021.12.15 17:39t/p230.011766.010.001766.013.731124.43
472021.12.20 17:01sell240.011793.800.001789.41
482021.12.20 22:09t/p240.011789.410.001789.414.391128.82
492021.12.21 16:52buy250.011793.790.001799.79
502021.12.22 20:09t/p250.011799.790.001799.795.511134.34
512022.01.18 18:19sell260.011813.030.001806.19
522022.01.19 16:51close260.011828.030.001806.19-14.781119.55
532022.02.15 11:19buy270.011856.930.001866.99
542022.02.16 19:19t/p270.011866.990.001866.999.571129.13
552022.02.18 17:33sell280.011895.770.001893.21
562022.02.18 17:37t/p280.011893.210.001893.212.561131.69
572022.03.02 18:16sell290.011921.470.001907.56
582022.03.03 13:34close290.011936.470.001907.56-14.341117.35
592022.04.22 19:22sell300.011936.790.001932.93
602022.04.22 20:28t/p300.011932.930.001932.933.861121.21
612022.04.26 16:08sell310.011905.800.001905.21
622022.04.26 16:57t/p310.011905.210.001905.210.591121.80
632022.06.10 16:01sell320.011839.900.001834.17
642022.06.10 16:18t/p320.011834.170.001834.175.731127.53
652022.07.20 16:52sell330.011708.520.001702.79
662022.07.20 19:48t/p330.011702.790.001702.795.731133.26
672022.08.02 18:02sell340.011776.930.001767.92
682022.08.02 21:02t/p340.011767.920.001767.929.011142.27
692022.09.30 20:35buy350.011663.130.001667.34
702022.10.03 04:30t/p350.011667.340.001667.343.721145.99
712022.11.02 21:03sell360.011647.760.001626.40
722022.11.03 10:26t/p360.011626.400.001626.4022.021168.01
732022.11.30 17:18buy370.011751.890.001763.12
742022.11.30 21:20t/p370.011763.120.001763.1211.231179.24
752022.12.09 17:23buy380.011791.230.001800.19
762022.12.09 18:20t/p380.011800.190.001800.198.961188.20
772023.01.11 17:38buy390.011870.980.001874.94
782023.01.11 19:21t/p390.011874.940.001874.943.961192.16
792023.01.12 17:10sell400.011884.680.001867.96
802023.01.12 21:03close400.011899.680.001867.96-15.001177.16
812023.02.07 16:32sell410.011869.860.001868.93
822023.02.07 16:45t/p410.011868.930.001868.930.931178.09
832023.02.09 17:00sell420.011879.160.001868.22
842023.02.09 18:03t/p420.011868.220.001868.2210.941189.03
852023.03.02 20:35sell430.011835.870.001834.80
862023.03.03 21:27close430.011850.870.001834.80-14.781174.25
872023.04.26 19:17buy440.011989.040.001995.12
882023.04.27 05:13t/p440.011995.120.001995.124.621178.87
892023.05.15 17:34sell450.012016.660.002011.32
902023.05.16 09:04t/p450.012011.320.002011.325.561184.43
912023.05.26 17:09sell460.011951.200.001949.72
922023.05.26 17:19t/p460.011949.720.001949.721.481185.91
932023.06.07 17:32sell470.011958.950.001947.93
942023.06.07 18:51t/p470.011947.930.001947.9311.021196.93
952023.07.13 18:04sell480.011959.610.001957.54
962023.07.13 18:51t/p480.011957.540.001957.542.071199.00
972023.07.19 18:12sell490.011974.940.001970.18
982023.07.20 17:35t/p490.011970.180.001970.185.421204.41
992023.07.25 15:30sell500.011958.580.001953.88
1002023.07.25 17:00t/p500.011953.880.001953.884.701209.11
+
diff --git a/Packed/XAUUSD-15M/Reports/XTPW/Long/StrategyTester Long 13.gif b/Packed/XAUUSD-15M/Reports/XTPW/Long/StrategyTester Long 13.gif new file mode 100644 index 0000000..36be70d Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/XTPW/Long/StrategyTester Long 13.gif differ diff --git a/Packed/XAUUSD-15M/Reports/XTPW/Long/StrategyTester Long 13.htm b/Packed/XAUUSD-15M/Reports/XTPW/Long/StrategyTester Long 13.htm new file mode 100644 index 0000000..bb47461 --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/XTPW/Long/StrategyTester Long 13.htm @@ -0,0 +1,103 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.02 06:00 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63374Ticks modelled72620713Modelling qualityn/a
Mismatched charts errors809
Initial deposit1000.00SpreadCurrent (57)
Total net profit91.72Gross profit107.20Gross loss-15.49
Profit factor6.92Expected payoff5.40
Absolute drawdown0.80Maximal drawdown21.17 (2.03%)Relative drawdown2.03% (21.17)
Total trades17Short positions (won %)0 (0.00%)Long positions (won %)17 (94.12%)
Profit trades (% of total)16 (94.12%)Loss trades (% of total)1 (5.88%)
Largestprofit trade17.03loss trade-15.49
Averageprofit trade6.70loss trade-15.49
Maximumconsecutive wins (profit in money)13 (89.63)consecutive losses (loss in money)1 (-15.49)
Maximalconsecutive profit (count of wins)89.63 (13)consecutive loss (count of losses)-15.49 (1)
Averageconsecutive wins8consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12021.03.11 16:48buy10.011719.900.001725.30
22021.03.11 17:07t/p10.011725.300.001725.305.401005.40
32021.03.17 13:48buy20.011728.340.001737.00
42021.03.17 20:06t/p20.011737.000.001737.008.661014.06
52021.04.19 15:15buy30.011775.900.001779.90
62021.04.20 19:24t/p30.011779.900.001779.903.511017.57
72021.04.27 18:24buy40.011778.420.001784.35
82021.04.28 12:24close40.011763.420.001784.35-15.491002.09
92021.05.19 22:00buy50.011863.460.001881.95
102021.05.20 19:49t/p50.011881.950.001881.9517.031019.12
112021.07.06 19:07buy60.011794.080.001807.68
122021.07.07 13:24t/p60.011807.680.001807.6813.111032.23
132021.07.08 18:04buy70.011801.930.001814.59
142021.07.13 15:39t/p70.011814.590.001814.5911.201043.43
152021.08.17 17:15buy80.011782.680.001786.06
162021.08.17 17:24t/p80.011786.060.001786.063.381046.81
172021.12.21 16:52buy90.011793.790.001799.79
182021.12.22 20:09t/p90.011799.790.001799.795.511052.33
192022.02.15 11:19buy100.011856.930.001863.63
202022.02.16 16:39t/p100.011863.630.001863.636.211058.54
212022.04.26 17:36buy110.011901.340.001904.58
222022.04.26 17:38t/p110.011904.580.001904.583.241061.78
232022.09.30 20:35buy120.011663.130.001665.93
242022.10.03 04:23t/p120.011665.930.001665.932.311064.09
252022.11.30 17:18buy130.011751.890.001763.12
262022.11.30 21:20t/p130.011763.120.001763.1211.231075.32
272022.12.09 17:23buy140.011791.230.001800.19
282022.12.09 18:20t/p140.011800.190.001800.198.961084.28
292023.01.11 17:38buy150.011870.980.001873.62
302023.01.11 18:51t/p150.011873.620.001873.622.641086.92
312023.04.26 19:17buy160.011989.040.001993.09
322023.04.27 04:34t/p160.011993.090.001993.092.591089.52
332023.07.13 19:00buy170.011955.090.001957.29
342023.07.13 19:18t/p170.011957.290.001957.292.201091.72
+
diff --git a/Packed/XAUUSD-15M/Reports/XTPW/Short/StrategyTester 13.gif b/Packed/XAUUSD-15M/Reports/XTPW/Short/StrategyTester 13.gif new file mode 100644 index 0000000..8e75c52 Binary files /dev/null and b/Packed/XAUUSD-15M/Reports/XTPW/Short/StrategyTester 13.gif differ diff --git a/Packed/XAUUSD-15M/Reports/XTPW/Short/StrategyTester 13.htm b/Packed/XAUUSD-15M/Reports/XTPW/Short/StrategyTester 13.htm new file mode 100644 index 0000000..b78cc40 --- /dev/null +++ b/Packed/XAUUSD-15M/Reports/XTPW/Short/StrategyTester 13.htm @@ -0,0 +1,139 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.01 23:45 (2020.01.01 - 2023.08.02)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=false; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63353Ticks modelled72601176Modelling qualityn/a
Mismatched charts errors808
Initial deposit1000.00SpreadCurrent (59)
Total net profit109.29Gross profit182.54Gross loss-73.25
Profit factor2.49Expected payoff3.12
Absolute drawdown5.99Maximal drawdown31.30 (2.90%)Relative drawdown2.90% (31.30)
Total trades35Short positions (won %)35 (85.71%)Long positions (won %)0 (0.00%)
Profit trades (% of total)30 (85.71%)Loss trades (% of total)5 (14.29%)
Largestprofit trade22.02loss trade-15.00
Averageprofit trade6.08loss trade-14.65
Maximumconsecutive wins (profit in money)10 (62.88)consecutive losses (loss in money)1 (-15.00)
Maximalconsecutive profit (count of wins)62.88 (10)consecutive loss (count of losses)-15.00 (1)
Averageconsecutive wins5consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 17:39sell10.011836.610.001825.20
22020.12.07 10:37t/p10.011825.200.001825.2011.631011.63
32021.01.29 16:54sell20.011865.800.001855.99
42021.01.29 19:22t/p20.011855.990.001855.999.811021.44
52021.02.09 17:45sell30.011841.990.001838.33
62021.02.09 18:09t/p30.011838.330.001838.333.661025.10
72021.02.10 17:00sell40.011841.300.001827.41
82021.02.11 19:09t/p40.011827.410.001827.4114.551039.65
92021.02.16 17:09sell50.011804.040.001801.47
102021.02.16 18:49t/p50.011801.470.001801.472.571042.22
112021.03.03 16:51sell60.011712.530.001708.07
122021.03.03 17:36t/p60.011708.070.001708.074.461046.68
132021.05.10 17:45sell70.011839.580.001833.85
142021.05.11 03:39t/p70.011833.850.001833.855.951052.63
152021.07.13 17:21sell80.011811.750.001808.46
162021.07.13 20:37t/p80.011808.460.001808.463.291055.92
172021.08.20 17:39sell90.011781.750.001777.75
182021.08.23 03:16t/p90.011777.750.001777.754.221060.13
192021.08.31 15:30sell100.011811.860.001809.11
202021.08.31 16:04t/p100.011809.110.001809.112.751062.88
212021.10.27 18:09sell110.011793.560.001789.11
222021.10.28 16:30close110.011808.560.001789.11-14.341048.54
232021.11.03 04:00sell120.011783.060.001779.26
242021.11.03 08:16t/p120.011779.260.001779.263.801052.34
252021.11.30 17:48sell130.011794.770.001781.02
262021.11.30 18:04t/p130.011781.020.001781.0213.751066.09
272021.12.13 16:49sell140.011785.140.001782.99
282021.12.14 10:24t/p140.011782.990.001782.992.371068.46
292021.12.15 16:54sell150.011769.740.001766.01
302021.12.15 17:39t/p150.011766.010.001766.013.731072.19
312021.12.20 17:01sell160.011793.800.001789.41
322021.12.20 22:09t/p160.011789.410.001789.414.391076.58
332022.01.18 18:19sell170.011813.030.001806.19
342022.01.19 16:51close170.011828.030.001806.19-14.781061.80
352022.02.18 17:33sell180.011895.770.001893.21
362022.02.18 17:37t/p180.011893.210.001893.212.561064.36
372022.03.02 18:16sell190.011921.470.001907.56
382022.03.03 13:34close190.011936.470.001907.56-14.341050.02
392022.04.22 19:22sell200.011936.790.001932.93
402022.04.22 20:28t/p200.011932.930.001932.933.861053.88
412022.04.26 16:08sell210.011905.800.001905.21
422022.04.26 16:57t/p210.011905.210.001905.210.591054.47
432022.06.10 16:01sell220.011839.900.001834.17
442022.06.10 16:18t/p220.011834.170.001834.175.731060.20
452022.07.20 16:52sell230.011708.520.001702.79
462022.07.20 19:48t/p230.011702.790.001702.795.731065.93
472022.08.02 18:02sell240.011776.930.001767.92
482022.08.02 21:02t/p240.011767.920.001767.929.011074.94
492022.11.02 21:03sell250.011647.760.001626.40
502022.11.03 10:26t/p250.011626.400.001626.4022.021096.95
512023.01.12 17:10sell260.011884.680.001867.96
522023.01.12 21:03close260.011899.680.001867.96-15.001081.95
532023.02.07 16:32sell270.011869.860.001868.93
542023.02.07 16:45t/p270.011868.930.001868.930.931082.88
552023.02.09 17:00sell280.011879.160.001868.22
562023.02.09 18:03t/p280.011868.220.001868.2210.941093.82
572023.03.02 20:35sell290.011835.870.001834.78
582023.03.03 21:27close290.011850.870.001834.78-14.781079.04
592023.05.15 17:34sell300.012016.660.002011.32
602023.05.16 09:05t/p300.012011.320.002011.325.561084.60
612023.05.26 17:09sell310.011951.200.001949.72
622023.05.26 17:19t/p310.011949.720.001949.721.481086.08
632023.06.07 17:32sell320.011958.950.001947.93
642023.06.07 18:51t/p320.011947.930.001947.9311.021097.10
652023.07.13 18:04sell330.011959.610.001957.54
662023.07.13 18:51t/p330.011957.540.001957.542.071099.17
672023.07.19 18:12sell340.011974.940.001970.18
682023.07.20 17:35t/p340.011970.180.001970.185.421104.59
692023.07.25 15:30sell350.011958.580.001953.88
702023.07.25 17:00t/p350.011953.880.001953.884.701109.29
+
diff --git a/README.md b/README.md new file mode 100644 index 0000000..1372b4c --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# xMQL4 + +this is a workspace which contains all requirements for implementing new indicators and oscillators on MetaTrader 4 Platform using MQL4 to satisfied SaherElm IT Center Trading Strategies. + +## Maintainer + +Hadi Khazaee asl + +[https://www.saherelm.ir](https://www.saherelm.ir) + +[hadi_khazaee_asl@yahoo.com](mailto:hadi_khazaee_asl@yahoo.com) diff --git a/xEAs/x-saherelm.ea.mq4 b/xEAs/x-saherelm.ea.mq4 new file mode 100644 index 0000000..d8a63ca --- /dev/null +++ b/xEAs/x-saherelm.ea.mq4 @@ -0,0 +1,1038 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XST Strategy Expert Advisor +// --------------------------------------------- +// saherelm implementation of strategy expert advisor ... +// in this EA, we try to combine multiple tools, to ashive best +// results ... +// +// ShortName: XST +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +989121694056 +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XST Strategy Expert Advisor" +#property strict + +// +// START Inputs ... +// +// +// Signal Prefixe ... +input string signalPrefix = "XST_EA"; // Signal Prefix + +// +// Signal Draw Specifications ... +input string bullishSignalLabel = "X_BUY"; // Bullish Signal Label +input color bullishSignalColor = clrAqua; // Bullish Signal Color + +// +input string bearishSignalLabel = "X_SELL"; // Bearish Signal Label +input color bearishSignalColor = clrFuchsia; // Bearish Signal Color + +// +input color signalEntryColor = clrAquamarine; // Signal Entry Ptice Color +input color signalSLColor = clrRed; // Signal SL Color +input color signalTPColor = clrGreen; // Signal TP Color + +// +input int candleGapBetweenSignals = 7; // How many Candle waits to new Signal from last one + +// +// Trade ... +input bool allowTrade = true; // Allow Trade Based on given Signals +input bool allowLongTrades = true; // Allow Long Trades +input bool allowShortTrades = true; // Allow Short Trades + +// +// Alerts ... +input bool alertEvents = true; // Alert Events +input bool alertPositions = true; // Alert Positions +input bool longPositionAlerts = true; // Alert Long Positions +input bool shortPositionAlerts = true; // Alert Short Positions + +// +// Alert Types ... +input bool terminalAlert = false; // Terminal Alert +input bool pushAlert = false; // Push Notification Alerts + +// +// Balance and Finanical Specifications ... +input double lotsPerTradePercent = 0.00001; // Lots Per Trade Percent +input int maxOpenTrades = 4; // Maximum Open Trade +input double maxDrawdownPercentPerPTrade = 0.1; // Maximum DrawDown Per Trade +input double minBalancePercent = 0.5; // Minimum Balance for Trading +input double maxEquityPercent = 0.1; // Maximum Trade Equity + +// +// START Global Definitions: Variables, Properties and etc ... +// +int lastSignalledBar = 0; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.signal.lib.mq4" + +// +int maxMarketLength = 0; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Validate Inputs ... + bool inputsNotValiid = + // + // EA ... + maxOpenTrades <= 0 + || maxEquityPercent < 0 + || minBalancePercent < 0 + || lotsPerTradePercent < 0 + || maxDrawdownPercentPerPTrade < 0 + ; + + // + if (inputsNotValiid) { + return INIT_PARAMETERS_INCORRECT; + } + + // + totalSignals = 0; + totalLongSignals = 0; + totalShortSignals = 0; + + // + initialBalance = 0; + + // + // START Define Array Series ... + // + // + // END Define Array Series ... + // + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST"; + + // + ClearSignalConditions(); + + // + maxMarketLength = MathMax(0, GetDailyCandleCount()); + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { +} + +// +// Ticker Event Handler ... +void OnTick() { + // + isNewDay = IsNewDay(); + if (isNewDay) { + // + LogMessage( + StringConcatenate( + "New Day ..." + ) + ); + } + + // + // Process Signals to Open Positions ... + ProcessSignals(); + + // + // Checking State for Signal Handling ... + CheckState(); + + // + // Process Open Positions for Trailing Stop Loss or Close ... + ProcessOpenPositions(); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Check State for Signal Handling ... +void CheckState() { + // + // Here we Must to Check Market State for enable or disable + // Signal Handlers and also make dection to close all long/short + // trades ... +} + +// +// Calculate Signals and Process Based on Exists Signals ... +void ProcessSignals() { + // + XSignalRequest request = {}; + request.type = X_SIGNAL_NONE; + request.hasSignal = false; + + // + // Prevent Multiple Calculating on Same Bars ... + isNewBar = IsNewBar(); + if (isNewBar) { + countedBars++; + } + + // + if (countedBars < maxMarketLength) { + return; + } + + // + bool allowDoTrade = true; + + // + // Check Balance ... + if (initialBalance > 0) { + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double minimumBalanceForTrade = + balance > initialBalance + ? + minBalancePercent * balance + : + minBalancePercent * initialBalance; + + // + // Retrieve Account Equity ... + double equity = AccountInfoDouble(ACCOUNT_EQUITY); + double maxAllowedEquity = balance - (balance * maxEquityPercent); + + // + // Retrieve Free Marigin ... + double freeMargin = AccountFreeMargin(); + double maximumMariginRisk = balance - (balance * maxEquityPercent); + + // + if ( + // + // Do not Open Positions if equity not passed ... + equity < maxAllowedEquity || + // + // Do not Open Positions if free margin not passed ... + freeMargin <= maximumMariginRisk || + // + // Do not open positions if balance less than minimum ... + balance <= minimumBalanceForTrade + ) { + // + static bool tradingPauseAlerted; + + // + allowDoTrade = false; + + // + if (!tradingPauseAlerted) { + // + string message = StringConcatenate( + "Trading Pause => ", + "Balance: ", balance, + ", Equity: ", equity, + ", FreeMargin: ", freeMargin + ); + + // + LogMessage(message); + SendAlert(message); + + // + tradingPauseAlerted = true; + } + } + } + + // + // Retrieve Signal Exists ... + request = GenerateSignal(0); + + // + // Prevent doing anything else, if there is no signals ... + if ( + !allowDoTrade || + !request.hasSignal || + request.type == X_SIGNAL_NONE + ) { + return; + } + + // + bool hasLongSignal = request.type == X_SIGNAL_LONG; + + // + // Check last Signalled Bar with Counted Bars ... + // Prevent Multiple Signalling on Same Bar ... + bool isInLastSignalledBars = false; + for (int i=0; i < candleGapBetweenSignals; i++) { + // + isInLastSignalledBars = + isInLastSignalledBars + || lastSignalledBar == countedBars - i + ; + } + if (isInLastSignalledBars) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + return; + } + + // + // increase last signalled bar ... + lastSignalledBar = countedBars; + + // + // Calculate Can Trade or not ... + allowDoTrade = allowTrade + && ( + hasLongSignal ? + allowLongTrades : + allowShortTrades + ); + + // + // Chack Maximum Open Positions ... + int openTrades = CountOpenTrades(); + if (maxOpenTrades > 0) { + // + if (openTrades >= maxOpenTrades) { + // + allowDoTrade = false; + + // + if (!allowDoTrade) { + // + string message = StringConcatenate( + "Trading Pause => ", + "Max Open Trades (", + maxOpenTrades, + ") reached ..." + ); + + // + LogMessage(message); + SendAlert(message); + } + } + } + + // + // Check Trading is Enable or not ... + // nothing to do if trading is disabled ... + if (!allowDoTrade) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + string message = StringConcatenate( + "Trading Not Allowed ..." + ); + + // + LogMessage(message); + SendAlert(message); + return; + } + + // + // Retrieve Signal Lots Per Trade ... + double lPTradePercent = GetSignalLottage( + request.signal, + lotsPerTradePercent + ); + + // + bool isPositionOpened = TradeSignal( + request.signal, + lPTradePercent, + // + bullishSignalLabel, + bullishSignalColor, + bearishSignalLabel, + bearishSignalColor + ); + + // + totalSignals++; + if (hasLongSignal) { + // + totalLongSignals++; + ClearLongSignalConditions(); + } else { + // + totalShortSignals++; + ClearShortSignalConditions(); + } + + // + if (isPositionOpened) { + // + bool canAlert = + alertPositions + && ( + hasLongSignal ? + longPositionAlerts + : + shortPositionAlerts + ); + + // + if (canAlert) { + // + // Alert Message ... + string message = StringConcatenate( + "Trade on Signal ID: ", request.signal.id, + ", ProvidedBy: ", GetSignalProviderIdentifier(request.signal.provider), + ", Entry: ", request.signal.entry, + ", TP: ", request.signal.tp + ); + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } + } + } +} + +// +// Process All Open Positions ... +void ProcessOpenPositions() { + // + // XSignalling ... + if (enableXSignalling) { + // + // Close All XXX Provided Signals on it's Specific Condition ... + if (xCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XXX_PROVIDER); + + // + xCloseLongTrades = false; + } + + // + if (xCloseShortTrades) { + // + CloseAllProviderShortTrades(X_XTPW_PROVIDER); + + // + xCloseShortTrades = false; + } + + // + // Close Maximum DrawDown Passed Trades ... + + // + // Longs ... + bool hasClosedLongInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xLongMaxDrawdownPerTradePercent, + X_SIGNAL_LONG, + X_XXX_PROVIDER + ); + + // + // Shorts ... + bool hasClosedShortInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xShortMaxDrawdownPerTradePercent, + X_SIGNAL_SHORT, + X_XXX_PROVIDER + ); + + // + // Close All Long Time Trades based on Provider provided Length ... + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + xMaximumCandlesPerTrade, + X_XXX_PROVIDER + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedLongInDrawDownLongTrade + || hasClosedShortInDrawDownLongTrade + ) { + xFailedSignals++; + } + } + + // + // XR Signalling ... + if (enableXRSignalling) { + // + if (xRCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XR_PROVIDER); + + // + xRCloseLongTrades = false; + } + + // + if (xRCloseShortTrades) { + // + CloseAllProviderShortTrades(X_XR_PROVIDER); + + // + xRCloseShortTrades = false; + } + + // + // Close Maximum DrawDown Passed Trades ... + + // + // Longs ... + bool hasClosedLongInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xRLongMaxDrawdownPerTradePercent, + X_SIGNAL_LONG, + X_XR_PROVIDER + ); + + // + // Shorts ... + bool hasClosedShortInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xRShortMaxDrawdownPerTradePercent, + X_SIGNAL_SHORT, + X_XR_PROVIDER + ); + + // + // Close All Long Time Trades based on Provider provided Length ... + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + xRMaximumCandlesPerTrade, + X_XR_PROVIDER + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedLongInDrawDownLongTrade + || hasClosedShortInDrawDownLongTrade + ) { + xRFailedSignals++; + } + } + + // + // XTPW Signalling ... + if (enableXTPWSignalling) { + // + if (xTPWCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XTPW_PROVIDER); + + // + xTPWCloseLongTrades = false; + } + + // + if (xTPWCloseShortTrades) { + // + CloseAllProviderShortTrades(X_XTPW_PROVIDER); + + // + xTPWCloseShortTrades = false; + } + + // + // Close Maximum DrawDown Passed Trades ... + + // + // Longs ... + bool hasClosedLongInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xTPWLongMaxDrawdownPerTradePercent, + X_SIGNAL_LONG, + X_XTPW_PROVIDER + ); + + // + // Shorts ... + bool hasClosedShortInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xTPWShortMaxDrawdownPerTradePercent, + X_SIGNAL_SHORT, + X_XTPW_PROVIDER + ); + + // + // Close All Long Time Trades based on Provider provided Length ... + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + xTPWMaximumCandlesPerTrade, + X_XTPW_PROVIDER + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedLongInDrawDownLongTrade + || hasClosedShortInDrawDownLongTrade + ) { + xTPWFailedSignals++; + } + } + + // + // Close Maximum DrawDown Passed Trades ... + // this is the Maximum Controller ... + // + double maxOfXPercent = enableXSignalling ? + MathMax( + xLongMaxDrawdownPerTradePercent, + xShortMaxDrawdownPerTradePercent + ) : 0 + ; + + // + double maxOfXRPercent = enableXRSignalling ? + MathMax( + xRLongMaxDrawdownPerTradePercent, + xRShortMaxDrawdownPerTradePercent + ) : 0 + ; + + // + double maxOfXTPWPercent = enableXTPWSignalling ? + MathMax( + xTPWLongMaxDrawdownPerTradePercent, + xTPWShortMaxDrawdownPerTradePercent + ) : 0 + ; + + // + double maxDrawDownPercent = MathMax( + maxOfXPercent, + maxOfXRPercent + ); + maxDrawDownPercent = MathMax( + maxDrawDownPercent, + maxOfXTPWPercent + ); + maxDrawDownPercent = MathMax( + maxDrawDownPercent, + maxDrawdownPercentPerPTrade + ); + + // + // we Calculate Max DrawDown Percent Per Trade ... + // then try to Close based on them ... + bool hasClosedInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + maxDrawDownPercent + ); +} + +// +// Send Special Type of Alerts ... +void SendAlert(string message) { + // + if (!alertEvents) { + return; + } + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } +} +// +// END Functions ... +// + +// +// +// Calculate Signal ... +// in this function we calculate a signal exists in +// specific bar or not ... +XSignalRequest GenerateSignal( + const int bar_index // Bar Index ... +) { + // + // create temp result ... + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + bool hasSignal = false; + bool hasLongSignal = false; + bool hasShortSignal = false; + + // + XSignal signal = {}; + + // + // Define Template Signal Requests for Managing Multiple Signals ... + // + // X ... + XSignalRequest xLongSignalRequest = {}; + XSignalRequest xShortSignalRequest = {}; + // + // XR ... + XSignalRequest xrLongSignalRequest = {}; + XSignalRequest xrShortSignalRequest = {}; + // + // XTPW ... + XSignalRequest xTPWLongSignalRequest = {}; + XSignalRequest xTPWShortSignalRequest = {}; + + // + // START XR Signal Handler ... + // + // + if (enableXRSignalling) { + // + CheckXRSignalHandler( + bar_index + ); + + // + // Long Trades ... + if (allowTrade && allowLongTrades) { + // + if (xRWaitForLongSignals) { + // + CheckXRLongSignalConditions( + bar_index + ); + + // + xrLongSignalRequest = GenerateXRSignal( + X_SIGNAL_LONG, + signalPrefix, + bar_index + ); + + // + if (xrLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXRSignals( + xrLongSignalRequest.signal + ); + + // + if (isReady && xRWaitForLongSignals) { + // + hasLongSignal = true; + signal = xrLongSignalRequest.signal; + } else { + ClearXRLongSignalConditions(); + } + } + } else { + ClearXRLongSignalConditions(); + } + } + + // + // Short Trades ... + if (allowTrade && allowShortTrades) { + // + if (xRWaitForShortSignals) { + // + CheckXRShortSignalConditions( + bar_index + ); + + // + xrShortSignalRequest = GenerateXRSignal( + X_SIGNAL_SHORT, + signalPrefix, + bar_index + ); + + // + if (xrShortSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXRSignals( + xrShortSignalRequest.signal + ); + + // + if (isReady && xRWaitForShortSignals) { + // + hasShortSignal = true; + signal = xrShortSignalRequest.signal; + } else { + ClearXRShortSignalConditions(); + } + } + } else { + ClearXRShortSignalConditions(); + } + } + } + // + // END XR Signal Handler ... + // + + // + // START XTPW Signal Handler ... + // + if (enableXTPWSignalling) { + // + CheckXTPWSignalHandler( + bar_index + ); + + // + // Long Trades ... + if (allowTrade && allowLongTrades) { + // + if (xTPWWaitForLongSignals) { + // + CheckXTPWLongSignalConditions( + bar_index + ); + + // + xTPWLongSignalRequest = GenerateXTPWSignal( + X_SIGNAL_LONG, + signalPrefix, + bar_index + ); + + // + if (xTPWLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXTPWSignals( + xTPWLongSignalRequest.signal + ); + + // + if (isReady && xTPWWaitForLongSignals) { + // + hasLongSignal = true; + signal = xTPWLongSignalRequest.signal; + } else { + ClearXTPWLongSignalConditions(); + } + } + } else { + ClearXTPWLongSignalConditions(); + } + } + + // + // Short Trades ... + if (allowTrade && allowShortTrades) { + // + if (xTPWWaitForShortSignals) { + // + CheckXTPWShortSignalConditions( + bar_index + ); + + // + xTPWShortSignalRequest = GenerateXTPWSignal( + X_SIGNAL_SHORT, + signalPrefix, + bar_index + ); + + // + if (xTPWShortSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXTPWSignals( + xTPWShortSignalRequest.signal + ); + + // + if (isReady && xTPWWaitForShortSignals) { + // + hasShortSignal = true; + signal = xTPWShortSignalRequest.signal; + } else { + ClearXTPWShortSignalConditions(); + } + } + } else { + ClearXTPWShortSignalConditions(); + } + } + } + // + // END XTPW Signal Handler ... + // + + // + // START X Signal Handler ... + // + // + if (enableXSignalling) { + // + CheckXSignalHandler( + bar_index + ); + + // + // Long Trades ... + if (allowTrade && allowLongTrades) { + // + if (xWaitForLongSignals) { + // + CheckXLongSignalConditions( + bar_index + ); + + // + xLongSignalRequest = GenerateXSignal( + X_SIGNAL_LONG, + signalPrefix, + bar_index + ); + + // + if (xLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXSignals( + xLongSignalRequest.signal + ); + + // + if (isReady && xWaitForLongSignals) { + // + hasLongSignal = true; + signal = xLongSignalRequest.signal; + } else { + ClearXLongSignalConditions(); + } + } + } else { + ClearXLongSignalConditions(); + } + } + + // + // Short Trades ... + if (allowTrade && allowShortTrades) { + // + if (xWaitForShortSignals) { + // + CheckXShortSignalConditions( + bar_index + ); + + // + xShortSignalRequest = GenerateXSignal( + X_SIGNAL_SHORT, + signalPrefix, + bar_index + ); + + // + if (xShortSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXSignals( + xShortSignalRequest.signal + ); + + // + if (isReady && xWaitForShortSignals) { + // + hasShortSignal = true; + signal = xShortSignalRequest.signal; + } else { + ClearXShortSignalConditions(); + } + } + } else { + ClearXShortSignalConditions(); + } + } + } + // + // END XR Signal Handler ... + // + + // + hasSignal = hasLongSignal || hasShortSignal; + + // + if (!hasSignal) { + // + signal.type = X_SIGNAL_NONE; + result.type = X_SIGNAL_NONE; + } + + // + // Normalize TP, SL and Entry Price ... + signal.tp = NormalizeDouble(signal.tp, _Digits); + signal.sl = NormalizeDouble(signal.sl, _Digits); + signal.entry = NormalizeDouble(signal.entry, _Digits); + + // + result.signal = signal; + result.type = signal.type; + result.hasSignal = hasSignal; + result.provider = signal.provider; + + // + // Return Result ... + return result; +} diff --git a/xIndicators/x-saherelm.adx.mq4 b/xIndicators/x-saherelm.adx.mq4 new file mode 100644 index 0000000..3271a4e --- /dev/null +++ b/xIndicators/x-saherelm.adx.mq4 @@ -0,0 +1,220 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center ADX Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm ADX Oscillator" +#property strict + +// +// START Inputs ... +// +input int length = 7; // Averaging Length +input ENUM_APPLIED_PRICE appliedPrice = PRICE_WEIGHTED; // Averaging Applied Price +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_separate_window + +// +#property indicator_minimum 0 +#property indicator_maximum 100 + +// +#property indicator_buffers 3 + +// +#property indicator_level1 0.0 +#property indicator_level2 50.0 +#property indicator_level3 70.0 +#property indicator_level4 100.0 +#property indicator_levelcolor clrSilver +#property indicator_levelstyle STYLE_DOT + +// +// ADX ... +#property indicator_width1 1 +#property indicator_color1 clrLightBlue +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_SOLID + +// +// Positive Direction ... +#property indicator_width2 1 +#property indicator_color2 clrLime +#property indicator_type2 DRAW_LINE +#property indicator_style2 STYLE_DOT + +// +// Negative Direction ... +#property indicator_width3 1 +#property indicator_color3 clrRed +#property indicator_type3 DRAW_LINE +#property indicator_style3 STYLE_DOT + +// +// Declare Buffers ... +#define adxBufferIndex 0 +#define positiveBufferIndex 1 +#define negativeBufferIndex 2 + +double adxBuffer[]; +double positiveBuffer[]; +double negativeBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (length < 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + IndicatorBuffers(3); + + // + SetIndexBuffer(positiveBufferIndex, positiveBuffer); + SetIndexLabel(positiveBufferIndex, "DI+"); + + // + SetIndexBuffer(negativeBufferIndex, negativeBuffer); + SetIndexLabel(negativeBufferIndex, "DI-"); + + // + SetIndexBuffer(adxBufferIndex, adxBuffer); + SetIndexLabel(adxBufferIndex, "ADX"); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, length); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Long TP ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index +) { + // + // Calculate Buffers ... + + // + // Retrieves the current ADX value ... + double adx = iADX( + _Symbol, + _Period, + length, + appliedPrice, + MODE_MAIN, + bar_index + ); + adxBuffer[bar_index] = adx; + + // + // Retrieves the current DI+ value ... + double plusDi = iADX( + _Symbol, + _Period, + length, + appliedPrice, + MODE_PLUSDI, + bar_index + ); + positiveBuffer[bar_index] = plusDi; + + // + // Retrieves the current DI- value ... + double minusDi = iADX( + _Symbol, + _Period, + length, + appliedPrice, + MODE_MINUSDI, + bar_index + ); + negativeBuffer[bar_index] = minusDi; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.ma.mq4 b/xIndicators/x-saherelm.ma.mq4 new file mode 100644 index 0000000..e3a5737 --- /dev/null +++ b/xIndicators/x-saherelm.ma.mq4 @@ -0,0 +1,173 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MA Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm MA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Fast MA ... +input int maLength = 20; // MA Length +input int maShift = 0; // MA Shift +input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method +input ENUM_APPLIED_PRICE maAppliedPrice = PRICE_CLOSE; // MA Applied Price + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 1 + +// +#property indicator_plots 1 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Fast Ma Buffer ... +#property indicator_label1 "Ma" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrYellow +#property indicator_style1 STYLE_DOT +#property indicator_width1 2 + +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define maBufferIndex 0 + +double maBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (maLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + // + // Ma ... + SetIndexBuffer(maBufferIndex, maBuffer); + SetIndexDrawBegin(maBufferIndex, maLength + 1); + // + // End Set Index Buffers ... + // + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, maLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Ma ... + CalculateMa(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateMa( + const int &bar_index +) { + // + // Calculating Fast Ma ... + double ma = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + maAppliedPrice, + bar_index + ); + + // + maBuffer[bar_index] = ma; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.momentum.mq4 b/xIndicators/x-saherelm.momentum.mq4 new file mode 100644 index 0000000..ea6e419 --- /dev/null +++ b/xIndicators/x-saherelm.momentum.mq4 @@ -0,0 +1,160 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center Momentum Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm Momentum Oscillator" +#property strict + +// +// START Inputs ... +// +input int length = 7; // Market Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_separate_window + +// +#property indicator_buffers 1 + +// +#property indicator_level1 0.0 +#property indicator_level2 100.0 +#property indicator_levelcolor clrSilver +#property indicator_levelstyle STYLE_DOT + +// +// MOMENTUM ... +#property indicator_width1 1 +#property indicator_color1 clrLightBlue +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_SOLID + +// +// Declare Buffers ... +#define momentumBufferIndex 0 + +double momentumBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (length < 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + IndicatorBuffers(1); + + // + SetIndexBuffer(momentumBufferIndex, momentumBuffer); + SetIndexLabel(momentumBufferIndex, "Momentum"); + SetIndexDrawBegin(momentumBufferIndex, length); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, length); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Long TP ... + CalculateBuffers( + i, + close + ); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index, + const double &close[] +) { + // + // Calculate Buffers ... + double momentum = close[bar_index] * 100 / close[bar_index + length]; + + // + momentumBuffer[bar_index] = momentum; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.osc.mq4 b/xIndicators/x-saherelm.osc.mq4 new file mode 100644 index 0000000..829f32c --- /dev/null +++ b/xIndicators/x-saherelm.osc.mq4 @@ -0,0 +1,257 @@ +///////////////////////////////////////////////////////////////// +// +// SaherElm IT Center OSC Indicator +// ------------------------------------------------------------- +// this indicator provides OSC ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +//////////////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm OSC Indicator" +#property strict + +// +// START Inputs ... +// +// +// FastOSC ... +// Short Cycle (Fast OSC) ... +input int fastOSCLength = 10; // FastOSC Length +input double fastOSCMultiplier = 1.0; // FastOSC Multiplier + +// +// SlowOSC ... +// Medium Cycle (Slow OSC) ... +input int slowOSCLength = 30; // SlowOSC Length +input double slowOSCMultiplier = 3.0; // SlowOSC Multiplier +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +#property indicator_separate_window + +// +// we have 2 buffer in this indicator ... +#property indicator_buffers 2 + +// +// also we have 2 line for draw on this indicator ... +#property indicator_plots 2 + +// +// Fast OSC ... +#property indicator_width1 1 +#property indicator_color1 clrAqua +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_SOLID + +// +// Slow OSC ... +#property indicator_width2 1 +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrFuchsia +#property indicator_style2 STYLE_SOLID + +// +// set color of horizontal levels ... +#property indicator_levelcolor clrGray + +// +// set style of horizontal levels ... +#property indicator_levelstyle STYLE_DOT + +// +// Declare Buffers ... +#define fastOSCBufferIndex 0 +#define slowOSCBufferIndex 1 + +// +double fastOSCBuffer[]; +double slowOSCBuffer[]; + +// +// Used Indicators List ... +string rmaIndicatorName = "x-saherelm.rma"; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + fastOSCLength < 0 || + slowOSCLength < 0 || + slowOSCLength <= fastOSCLength + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XS_OSC"; + + // + // set descriptions of horizontal levels ... + SetLevelValue(0, 0.0); + IndicatorSetString(INDICATOR_LEVELTEXT,0,""); + + // + // set descriptions of horizontal levels ... + SetLevelValue(1, 0.5); + IndicatorSetString(INDICATOR_LEVELTEXT,1,""); + + // + // set descriptions of horizontal levels ... + SetLevelValue(2, 1); + IndicatorSetString(INDICATOR_LEVELTEXT,2,""); + + // + // Fast OSC Buffer ... + SetIndexBuffer(fastOSCBufferIndex, fastOSCBuffer); + SetIndexLabel(fastOSCBufferIndex, "Fast OSC"); + SetIndexDrawBegin(fastOSCBufferIndex, fastOSCLength - 1); + + // + // Slow OSC Buffer ... + SetIndexBuffer(slowOSCBufferIndex, slowOSCBuffer); + SetIndexLabel(slowOSCBufferIndex, "Slow OSC"); + SetIndexDrawBegin(slowOSCBufferIndex, slowOSCLength - 1); + + // + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(fastOSCLength, slowOSCLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + CalculateOscillators(close, i); + } + + // + return rates_total; +} + +// +// De Initialization ... +void OnDeinit(const int reason) { +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +void CalculateOscillators( + const double &close[], + const int &bar_index +) { + // + // FastOSC ... + // Short Cycle Calculations ... + int scl = fastOSCLength / 2; + int scl2 = scl / 2; + double maScl = iCustom(_Symbol, _Period, rmaIndicatorName, scl, 0, bar_index); + double scmAtr = iATR(_Symbol, _Period, scl, bar_index); + double scmOff = fastOSCMultiplier * scmAtr; + double maScl2 = iCustom(_Symbol, _Period, rmaIndicatorName, scl2, 0, bar_index); + double sctParam = maScl2 != 0 ? maScl2 : close[bar_index + 1]; + double sct = sctParam + scmOff; + double scb = sctParam - scmOff; + + // + // SlowOSC ... + // Medium Cycle Calculations ... + int mcl = slowOSCLength / 2; + int mcl2 = mcl / 2; + double maMcl = iCustom(_Symbol, _Period, rmaIndicatorName, mcl, 0, bar_index); + double mcmAtr = iATR(_Symbol, _Period, mcl, bar_index); + double mcmOff = slowOSCMultiplier * mcmAtr; + double maMcl2 = iCustom(_Symbol, _Period, rmaIndicatorName, mcl2, 0, bar_index); + double mctParam = maMcl2 != 0 ? maMcl2 : close[bar_index + 1]; + double mct = mctParam + mcmOff; + double mcb = mctParam - mcmOff; + + // + double scMM = (sct + scb) / 2; + + // + double fastOCS = (close[bar_index] - mcb) / (mct - mcb); + fastOSCBuffer[bar_index] = fastOCS; + + // + double slowOCS = (scMM - mcb) / (mct - mcb); + slowOSCBuffer[bar_index] = slowOCS; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.psar.mq4 b/xIndicators/x-saherelm.psar.mq4 new file mode 100644 index 0000000..a263cdb --- /dev/null +++ b/xIndicators/x-saherelm.psar.mq4 @@ -0,0 +1,215 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center PSAR Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm PSAR Oscillator" +#property strict + +// +// START Inputs ... +// +input int shift = 0; // Shift +input double step = 0.02; // Step +input double maximum = 0.2; // Maximum +input bool drawAsDots = false; // Draw As Dots +// +input int priceSmoothing = 0; // Price Smoothing +input ENUM_APPLIED_PRICE priceLow = PRICE_CLOSE; // Psar low price +input ENUM_APPLIED_PRICE priceHigh = PRICE_OPEN; // Psar high price +input ENUM_MA_METHOD priceSmoothingMethod = MODE_SMA; // Price Smoothing Method +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 3 + +// +#property indicator_color1 clrLimeGreen +#property indicator_width1 1 +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_DOT + +// +#property indicator_color2 clrAqua +#property indicator_width2 1 +#property indicator_type2 DRAW_LINE +#property indicator_style2 STYLE_DOT + +// +#property indicator_color3 clrFuchsia +#property indicator_width3 1 +#property indicator_type3 DRAW_LINE +#property indicator_style3 STYLE_DOT + +// +// +// Declare Buffers ... +// +#define sarBufferIndex 0 +#define upBufferIndex 1 +#define downBufferIndex 2 + +// +double sarBuffer[]; +double upBuffer[]; +double downBuffer[]; + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + SetIndexBuffer(sarBufferIndex, sarBuffer); + SetIndexLabel(sarBufferIndex, "SAR"); + + // + SetIndexBuffer(upBufferIndex, upBuffer); + SetIndexLabel(upBufferIndex, "Up"); + + // + SetIndexBuffer(downBufferIndex, downBuffer); + SetIndexLabel(downBufferIndex, "Down"); + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XS_PSAR"; + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + // int maxLength = MathMax(0, length); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < 0) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Long TP ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index +) { + // + // Calculate isarValue ... + double sarValue = iSAR( + NULL, + _Period, + step, + maximum, + bar_index + ); + + // + double pHigh = iMA( + NULL, + _Period, + priceSmoothing, + 0, + priceSmoothingMethod, + priceHigh, + bar_index + ); + + // + double pLow = iMA( + _Symbol, + _Period, + priceSmoothing, + 0, + priceSmoothingMethod, + priceLow, + bar_index + ); + + // + upBuffer[bar_index] = pHigh; + sarBuffer[bar_index] = sarValue; + downBuffer[bar_index] = pLow; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.rma.mq4 b/xIndicators/x-saherelm.rma.mq4 new file mode 100644 index 0000000..0fc70fd --- /dev/null +++ b/xIndicators/x-saherelm.rma.mq4 @@ -0,0 +1,141 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center RMA Indicator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm RMA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Set the RMA Length ... +input int RMALength = 10; // Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// we have 2 buffer in this indicator ... +#property indicator_buffers 1 + +// +// also we have 1 line for draw on this indicator ... +#property indicator_plots 1 + +// +// here we declare plot SlowOCS to system ... +#property indicator_label1 "RMA" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrFuchsia +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +// +// Declare Buffers ... +#define RMABufferIndex 0 + +// +double RMABuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + SetIndexBuffer(RMABufferIndex, RMABuffer); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + int maxLength = MathMax(0, RMALength); + + // + // wait to pass bars until we have rights ... + if (rates_total <= maxLength) { + // + // return not calculated ... + return 0; + } + + // + // find loop count for bars manipulation ... + int count = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // Print("Count: ", count, ", Bars: ", Bars); + + // + // this is the main loop of calculations, for each bar index ... + for (int i = count - 1; i >= 0; i--) { + // + // Start Calculation with Formula 1 ... + // + double shortSMA = iMA(_Symbol, _Period, RMALength, 0, MODE_SMA, PRICE_CLOSE, i); + double mediumSMA = iMA(_Symbol, _Period, RMALength * 2, 0, MODE_SMA, PRICE_CLOSE, i); + double longSMA = iMA(_Symbol, _Period, RMALength * 3, 0, MODE_SMA, PRICE_CLOSE, i); + + // + double rma1 = longSMA - mediumSMA + shortSMA; + rma1 = NormalizeDouble(rma1, _Digits); + // + // End Calculation with Formula 1 ... + // + + // + RMABuffer[i] = rma1; + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.rsi.mq4 b/xIndicators/x-saherelm.rsi.mq4 new file mode 100644 index 0000000..448f732 --- /dev/null +++ b/xIndicators/x-saherelm.rsi.mq4 @@ -0,0 +1,234 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center RSI Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm RSI Oscillator" +#property strict + +// +// START Inputs ... +// +input int rsiPeriod=14; // RSI Period +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_separate_window + +// +#property indicator_minimum 0 +#property indicator_maximum 100 + +// +#property indicator_buffers 1 +#property indicator_color1 DodgerBlue + +// +#property indicator_level1 30.0 +#property indicator_level2 50.0 +#property indicator_level3 70.0 +#property indicator_levelcolor clrSilver +#property indicator_levelstyle STYLE_DOT + +// +// Declare Buffers ... +#define rsiBufferIndex 0 +#define positiveBufferIndex 1 +#define negativeBufferIndex 2 + +double rsiBuffer[]; +double positiveBuffer[]; +double negativeBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + string short_name; + + // + IndicatorBuffers(3); + + // + SetIndexBuffer(positiveBufferIndex, positiveBuffer); + SetIndexBuffer(negativeBufferIndex, negativeBuffer); + + // + SetIndexStyle(rsiBufferIndex, DRAW_LINE); + SetIndexBuffer(rsiBufferIndex, rsiBuffer); + + // + // name for DataWindow and indicator subwindow label + short_name="RSI("+string(rsiPeriod)+")"; + IndicatorShortName(short_name); + SetIndexLabel(rsiBufferIndex, short_name); + + // + // check for input + if (rsiPeriod < 2) { + // + Print("Incorrect value for input variable InpRSIPeriod = ", rsiPeriod); + + // + // Failed Initialization ... + return INIT_PARAMETERS_INCORRECT; + } + + // + // set where to start draw ... + SetIndexDrawBegin(0, rsiPeriod); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + int i,pos; + double diff; + + // + // Prevent from run calculations if there is no fulfilled conditions ... + if (Bars <= rsiPeriod || rsiPeriod < 2) { + // + // return nothing calculated result ... + return 0; + } + + // + // counting from 0 to rates_total, this is most important ... + ArraySetAsSeries(rsiBuffer, false); + ArraySetAsSeries(positiveBuffer, false); + ArraySetAsSeries(negativeBuffer, false); + + // + ArraySetAsSeries(close, false); + + // + // preliminary calculations ... + pos = prev_calculated - 1; + if (pos <= rsiPeriod) { + // + // first RSIPeriod values of the indicator are not calculated + rsiBuffer[0] = 0.0; + positiveBuffer[0] = 0.0; + negativeBuffer[0] = 0.0; + + // + double sump=0.0; + double sumn=0.0; + for (i = 1; i <= rsiPeriod; i++) { + // + rsiBuffer[i]=0.0; + positiveBuffer[i]=0.0; + negativeBuffer[i]=0.0; + + // + diff = close[i] - close[i - 1]; + if(diff > 0) { + sump += diff; + } else { + sumn -= diff; + } + } + + // + // calculate first visible value ... + positiveBuffer[rsiPeriod] = sump / rsiPeriod; + negativeBuffer[rsiPeriod] = sumn / rsiPeriod; + if (negativeBuffer[rsiPeriod] != 0.0) { + // + rsiBuffer[rsiPeriod] = 100.0 - ( + 100.0 / ( + 1.0 + positiveBuffer[rsiPeriod] / negativeBuffer[rsiPeriod] + ) + ); + } else { + // + if (positiveBuffer[rsiPeriod] != 0.0) { + rsiBuffer[rsiPeriod] = 100.0; + } else { + rsiBuffer[rsiPeriod] = 50.0; + } + } + + // + // prepare the position value for main calculation ... + pos = rsiPeriod + 1; + } + + // + // the main loop of calculations ... + for (i = pos; i < rates_total && !IsStopped(); i++) { + // + diff = close[i] - close[i-1]; + + // + positiveBuffer[i] = (positiveBuffer[i-1] * (rsiPeriod - 1) + (diff > 0.0 ? diff : 0.0)) / rsiPeriod; + negativeBuffer[i] = (negativeBuffer[i-1] * (rsiPeriod - 1) + (diff < 0.0 ? -diff : 0.0)) / rsiPeriod; + + // + if (negativeBuffer[i] != 0.0) { + rsiBuffer[i] = 100.0 - 100.0 / (1 + positiveBuffer[i] / negativeBuffer[i]); + } else { + // + if (positiveBuffer[i] != 0.0) { + rsiBuffer[i] = 100.0; + } else { + rsiBuffer[i] = 50.0; + } + } + } + + // + return(rates_total); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.shpd.mq4 b/xIndicators/x-saherelm.shpd.mq4 new file mode 100644 index 0000000..7c02a84 --- /dev/null +++ b/xIndicators/x-saherelm.shpd.mq4 @@ -0,0 +1,402 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XSHPD Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XSHPD Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 7; // Market Length ... +input double sharpDetectMultiplier = 70; // Sharp Detect Multiplier + +// +input bool drawLabels = true; // Draw Labels on Founded Sharps + +// +input string sharpBullishLabel = "SH_BULL"; // Sharp Bullish Label +input color sharpBullishColor = clrAqua; // Sharp Bullish color + +// +input string sharpBearishLabel = "SH_BEAR"; // Sharp Bearish Label +input color sharpBearishColor = clrFuchsia; // Sharp Bearish color +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +#property indicator_buffers 4 +#property indicator_plots 4 + +// +// Declare Buffers ... +#define marketHighestHighBufferIndex 0 +#define marketLowestLowBufferIndex 1 +#define sharpBullishBufferIndex 2 +#define sharpBearishBufferIndex 3 + +// +double marketHighestHighBuffer[]; +double marketLowestLowBuffer[]; +double sharpBullishBuffer[]; +double sharpBearishBuffer[]; + +// +#include "../Libraries/x-saherelm.lib.mq4" +#include "../Libraries/x-saherelm.draw.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if ( + marketLength <= 0 + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + enableLogging = true; + + // + logTag = "X_SHPD"; + + // + // Highest High ... + SetIndexLabel(marketHighestHighBufferIndex, ""); + SetIndexBuffer(marketHighestHighBufferIndex, marketHighestHighBuffer); + SetIndexStyle( + marketHighestHighBufferIndex, + DRAW_LINE, // DRAW_NONE, + STYLE_DOT, + 1, // 0, + clrAqua // clrNONE + ); + + // + // Lowest Low ... + SetIndexLabel(marketLowestLowBufferIndex, ""); + SetIndexBuffer(marketLowestLowBufferIndex, marketLowestLowBuffer); + SetIndexStyle( + marketLowestLowBufferIndex, + DRAW_NONE, + STYLE_DOT, + 0, + clrNONE + ); + + // + // Sharp Bullish Buffer ... + SetIndexLabel(sharpBullishBufferIndex, ""); + SetIndexBuffer(sharpBullishBufferIndex, sharpBullishBuffer); + SetIndexStyle( + sharpBullishBufferIndex, + DRAW_NONE, + STYLE_DOT, + 0, + clrNONE + ); + + // + // Sharp Bearish Buffer ... + SetIndexLabel(sharpBearishBufferIndex, ""); + SetIndexBuffer(sharpBearishBufferIndex, sharpBearishBuffer); + SetIndexStyle( + sharpBearishBufferIndex, + DRAW_NONE, + STYLE_DOT, + 0, + clrNONE + ); + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + RemoveDraws(logTag); +} + +// +// Calculating what we want ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Sharp ... + CalculateSharp(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Sharp ... +void CalculateSharp( + const int &bar_index +) { + // + int index = 0; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + 1 + ); + + // + marketHighestHighBuffer[bar_index] = GetMarketHighestHigh( + bar_index, + marketLength + ); + + // + marketLowestLowBuffer[bar_index] = GetMarketLowestLow( + bar_index, + marketLength + ); + + // + double maHHs[]; + ArrayResize( + maHHs, + marketLength + ); + + // + double maLLs[]; + ArrayResize( + maLLs, + marketLength + ); + + // + index = 0; + for (int i = bar_index; i < bar_index + marketLength; i++) { + // + maLLs[index] = marketLowestLowBuffer[i]; + maHHs[index] = marketHighestHighBuffer[i]; + + // + index++; + } + + // + int maxHighIdx = ArrayMaximum(maHHs); + double maxHigh = maHHs[maxHighIdx]; + + // + int minHighIdx = ArrayMinimum(maHHs); + double minHigh = maHHs[minHighIdx]; + + // + double highDiffRate = (maxHigh - minHigh) / 100; + + // + int maxLowIdx = ArrayMaximum(maLLs); + double maxLow = maLLs[maxLowIdx]; + + // + int minLowIdx = ArrayMinimum(maLLs); + double minLow = maLLs[minLowIdx]; + + // + double lowDiffRate = (maxLow - minLow) / 100; + + // + bool isSharpBullishDetected = + high == maxHigh + && low > minLow + && marketHighestHighBuffer[bar_index] == maxHigh + && maxHigh - minHigh > highDiffRate * sharpDetectMultiplier + ; + sharpBullishBuffer[bar_index] = isSharpBullishDetected ? 1 : 0; + + // + bool isSharpBearishDetected = + low == minLow + && high < maxHigh + && marketLowestLowBuffer[bar_index] == minLow + && maxLow - minLow > lowDiffRate * sharpDetectMultiplier + ; + sharpBearishBuffer[bar_index] = isSharpBearishDetected ? 1 : 0; + + // + if ( + drawLabels + && ( + isSharpBearishDetected + || isSharpBullishDetected + ) + ) { + // + datetime time = iTime( + _Symbol, + _Period, + bar_index + ); + + // + string lbl = StringConcatenate( + logTag, + isSharpBullishDetected ? "Bullish_" : "Bearish_", + bar_index + ); + + // + double price = + isSharpBullishDetected + ? + marketLowestLowBuffer[bar_index] - (10 * _Point) + : + marketHighestHighBuffer[bar_index] + (10 * _Point) + ; + + // + uchar arrowCode = + isSharpBullishDetected + ? + SYMBOL_ARROWUP + : + SYMBOL_ARROWDOWN + ; + + // + ENUM_ARROW_ANCHOR anchor = + isSharpBullishDetected + ? + ANCHOR_BOTTOM + : + ANCHOR_TOP + ; + + // + color clr = + isSharpBullishDetected + ? + sharpBullishColor + : + sharpBearishColor + ; + + // + string lblText = + isSharpBullishDetected + ? + sharpBullishLabel + : + sharpBearishLabel + ; + + // + DrawText( + 0, + lbl, + 0, + time, + price, + lblText, + "Tahoma", + 5, + clr + ); + } +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.sl.mq4 b/xIndicators/x-saherelm.sl.mq4 new file mode 100644 index 0000000..9ab0e00 --- /dev/null +++ b/xIndicators/x-saherelm.sl.mq4 @@ -0,0 +1,154 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center StopLoss Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm StopLoss Indicator" +#property strict + +// +// START Inputs ... +// +input int swingLoopback = 7; // Swing Loopback +input double thrshold = 10; // Threshold +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +// Specify this is an Chart Indicator ... +#property indicator_chart_window + +// +// we have 2 buffer in this indicator ... +#property indicator_buffers 2 + +// +// also we have 2 line for draw on this indicator ... +#property indicator_plots 2 + +// +// here we declare plot Long Stop Loss to system ... +#property indicator_label1 "Long Stop Loss" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrFuchsia +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +// +// here we declare plot Short Stop Loss to system ... +#property indicator_label2 "Short Stop Loss" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrAqua +#property indicator_style2 STYLE_SOLID +#property indicator_width2 1 + +// +// here we declare indicator buffers ... +// +double longStopLossBuffer[]; +double shortStopLossBuffer[]; + +// +#define longStopLossIndex 0 +#define shortStopLossIndex 1 +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + SetIndexBuffer(longStopLossIndex, longStopLossBuffer); + SetIndexBuffer(shortStopLossIndex, shortStopLossBuffer); + + // + return(INIT_SUCCEEDED); +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + int limit; + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < swingLoopback) { + return 0; + } + + // + // found which candles calculated before ... + limit = rates_total - prev_calculated; + if (prev_calculated > 0) { + limit++; + } + + // + // Do Calculation ... + for (int i = limit - 1; i >= 0; i--) { + // + int lastMarketHighestIndex = iHighest(_Symbol, _Period, MODE_HIGH, swingLoopback, i); + double lastMarketHighest = high[lastMarketHighestIndex]; + + // + int lastMarketLowestIndex = iLowest(_Symbol, _Period, MODE_LOW, swingLoopback, i); + double lastMarketLowest = low[lastMarketLowestIndex]; + + // + double longStopLoss = lastMarketLowest - (thrshold * _Point); + longStopLoss = NormalizeDouble(longStopLoss, _Digits); + + // + double shortStopLoss = lastMarketHighest + (thrshold * _Point); + shortStopLoss = NormalizeDouble(shortStopLoss, _Digits); + + // + longStopLossBuffer[i] = longStopLoss; + shortStopLossBuffer[i] = shortStopLoss; + } + + // + // return value of prev_calculated for next call + return(rates_total); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.tp.mq4 b/xIndicators/x-saherelm.tp.mq4 new file mode 100644 index 0000000..89bfeba --- /dev/null +++ b/xIndicators/x-saherelm.tp.mq4 @@ -0,0 +1,221 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center TP Indicator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm TP Indicator" +#property strict + +// +// START Inputs ... +// +// +// Set the R2R Length ... +input int swingLoopback = 7; // Swing Loopback +input double slThrshold = 10; // SL Threshold +input double riskToRewardRatio = 1.5; // Risk to Reward Ratio +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// define indicator buffers ... +#property indicator_buffers 2 +#property indicator_plots 2 + +// +// here we declare plot to system ... +#property indicator_label1 "Long TP" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrLime +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +// +// here we declare plot to system ... +#property indicator_label2 "Short TP" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_SOLID +#property indicator_width2 1 + +// +// Declare Buffers ... +#define longTPBufferIndex 0 +#define shortTPBufferIndex 1 + +// +double longTPBuffer[]; +double shortTPBuffer[]; + +// +string slIndicatorName = "x-saherelm.sl"; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + SetIndexBuffer(longTPBufferIndex, longTPBuffer); + SetIndexDrawBegin(longTPBufferIndex, swingLoopback); + + // + SetIndexBuffer(shortTPBufferIndex, shortTPBuffer); + SetIndexDrawBegin(shortTPBufferIndex, swingLoopback); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, swingLoopback); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Long TP ... + CalculateLongTP( + open, + i + ); + + // + // Calculate Short TP ... + CalculateShortTP( + open, + i + ); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculate Long TPs based on SL and Open Price ... +void CalculateLongTP( + const double &open[], + const int &bar_index +) { + // + // read long sl ... + double longSL = iCustom( + _Symbol, + _Period, + slIndicatorName, + swingLoopback, + slThrshold, + 0, // Long SL Buffer Index ... + bar_index + ); + + // + double longRisk = open[bar_index] - longSL; + double longReward = longRisk * riskToRewardRatio; + + // + double longTP = open[bar_index] + longReward; + longTP = NormalizeDouble(longTP, _Digits); + + // + longTPBuffer[bar_index] = longTP; +} + +// +// Calculate Short TPs based on SL and Open Price ... +void CalculateShortTP( + const double &open[], + const int &bar_index +) { + // + // read short sl ... + double shortSL = iCustom( + _Symbol, + _Period, + slIndicatorName, + swingLoopback, + slThrshold, + 1, // Short SL Buffer Index ... + bar_index + ); + + // + double shortRisk = shortSL - open[bar_index]; + double shortReward = shortRisk * riskToRewardRatio; + + // + double shortTP = open[bar_index] - shortReward; + shortTP = NormalizeDouble(shortTP, _Digits); + + // + shortTPBuffer[bar_index] = shortTP; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.trend.mq4 b/xIndicators/x-saherelm.trend.mq4 new file mode 100644 index 0000000..17873e7 --- /dev/null +++ b/xIndicators/x-saherelm.trend.mq4 @@ -0,0 +1,250 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center ADX Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm ADX Oscillator" +#property strict + +// +// START Inputs ... +// +input int length = 7; // Averaging Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_chart_window + +// +// #property indicator_buffers 3 + +// +// Declare Buffers ... +// +datetime startTime; +double lHigh; +double lLow; + +// +datetime highTimes[]; + +// +datetime lowTimes[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (length < 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, length); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Long TP ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index +) { + // + // Calculate Buffers ... + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + startTime + ); + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + if (startTime == 0) { + // + startTime = barTime; + return; + } + + // + if ( + startTime > 0 + && startBarIndex - bar_index == length + ) { + // + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + length, + bar_index + ); + datetime hhTime = iTime( + _Symbol, + _Period, + hhIdx + ); + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + int hhSize = ArraySize(highTimes); + datetime tempTimes[]; + ArrayResize( + tempTimes, + hhSize + ); + ArrayCopy( + tempTimes, + highTimes + ); + ArrayResize( + highTimes, + hhSize + 1 + ); + highTimes[0] = hhTime; + ArrayCopy( + highTimes, + tempTimes, + 1 + ); + + // + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + length, + bar_index + ); + datetime llTime = iTime( + _Symbol, + _Period, + llIdx + ); + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + int llSize = ArraySize(lowTimes); + ArrayFree(tempTimes); + ArrayResize( + tempTimes, + llSize + ); + ArrayCopy( + tempTimes, + lowTimes + ); + ArrayResize( + lowTimes, + llSize + 1 + ); + lowTimes[0] = llTime; + ArrayCopy( + lowTimes, + tempTimes, + 1 + ); + + // + startTime = 0; + ArrayFree(tempTimes); + } +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.volume.mq4 b/xIndicators/x-saherelm.volume.mq4 new file mode 100644 index 0000000..eb4aa73 --- /dev/null +++ b/xIndicators/x-saherelm.volume.mq4 @@ -0,0 +1,270 @@ +///////////////////////////////////////////////////////////////// +// +// SaherElm IT Center Volume Indicator +// ------------------------------------------------------------- +// this indicator provides Volume ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +//////////////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm Volume Indicator" +#property strict + +// +// START Inputs ... +// +input int length = 11; // Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +#property indicator_separate_window + +// +// we have 2 buffer in this indicator ... +#property indicator_buffers 3 + +// +// also we have 2 line for draw on this indicator ... +#property indicator_plots 3 + +// +// Buy Volume ... +#property indicator_width1 1 +#property indicator_color1 clrGreen +#property indicator_type1 DRAW_HISTOGRAM +#property indicator_style1 STYLE_DOT + +// +// Sell Volume ... +#property indicator_width2 1 +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT + +// +// Diff ... +#property indicator_width3 1 +#property indicator_type3 DRAW_HISTOGRAM +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_SOLID + +// +//#property indicator_minimum 0 +//#property indicator_maximum 1 + +// +// set color of horizontal levels ... +#property indicator_levelcolor clrGray + +// +// set style of horizontal levels ... +#property indicator_levelstyle STYLE_DOT + +// +// Declare Buffers ... +#define buyVolumeBufferIndex 0 +#define sellVolumeBufferIndex 1 +#define diffBufferIndex 2 + +// +double buyVolumeBuffer[]; +double sellVolumeBuffer[]; +double diffBuffer[]; + +// +// here we specify logging enabled or not ... +bool enableLogging = true; + +// +// this is a Tag which attached to our Logger ... +string logTag = "XS_VOLUME"; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (length < 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // set descriptions of horizontal levels ... + SetLevelValue(0, 0.0); + IndicatorSetString(INDICATOR_LEVELTEXT,0,""); + + // + // Buy Volume Buffer ... + SetIndexBuffer(buyVolumeBufferIndex, buyVolumeBuffer); + SetIndexLabel(buyVolumeBufferIndex, "Buy Volume"); + + // + // Sell Volume Buffer ... + SetIndexBuffer(sellVolumeBufferIndex, sellVolumeBuffer); + SetIndexLabel(sellVolumeBufferIndex, "Sell Volume"); + + // + // Diff Buffer ... + SetIndexBuffer(diffBufferIndex, diffBuffer); + SetIndexLabel(diffBufferIndex, "Diff"); + + // + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, length); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + CalculateBuffers( + open, + close, + high, + low, + i + ); + } + + // + return rates_total; +} + +// +// De Initialization ... +void OnDeinit(const int reason) { +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +void CalculateBuffers( + const double &open[], + const double &close[], + const double &high[], + const double &low[], + const int &bar_index +) { + // + long volume = iVolume( + _Symbol, + _Period, + bar_index + ); + + // + double buyVolume = 0.0; + double sellVolume = 0.0; + + // + // Up ... + if (close[bar_index] > open[bar_index]) { + // + double cuenta = (high[bar_index] - low[bar_index]) * 10000; + double cuenta1 = volume - cuenta; + + // + buyVolume = ((volume - cuenta) / 2) + cuenta; + + // + buyVolumeBuffer[bar_index] = buyVolume; + sellVolumeBuffer[bar_index] = volume - buyVolume; + } else + // + // Down ... + if (close[bar_index] < open[bar_index]) { + // + double cuenta1 = (high[bar_index] - low[bar_index]) * 10000; + double cuenta = volume - cuenta1; + + // + sellVolume = ((volume - cuenta1) / 2) + cuenta1; + + // + sellVolumeBuffer[bar_index] = sellVolume; + buyVolumeBuffer[bar_index] = volume - sellVolume; + } else + // + // Neutral ... + if (close[bar_index] == open[bar_index]) { + // + double cuenta = (volume / 2) * 1.0; + + // + sellVolumeBuffer[bar_index] = cuenta; + buyVolumeBuffer[bar_index] = volume - cuenta; + } + + // + diffBuffer[bar_index] = MathAbs(buyVolumeBuffer[bar_index]) - MathAbs(sellVolumeBuffer[bar_index]); +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.x.hl.mq4 b/xIndicators/x-saherelm.x.hl.mq4 new file mode 100644 index 0000000..f08a975 --- /dev/null +++ b/xIndicators/x-saherelm.x.hl.mq4 @@ -0,0 +1,412 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center X Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm X Indicator" +#property strict + +// +// START Inputs ... +// +// +input int marketLength = 7; // Market Length + +// +input int shortCycleMultiplier = 2; // Market Short Cycle Multiplier +input int mediumCycleMultiplier = 6; // Market Medium Cycle Multiplier +input int longCycleMultiplier = 36; // Market Medium Cycle Multiplier + +// +input ENUM_MA_METHOD maMethod = MODE_SMA; // Ma Method +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 6 + +// +#property indicator_plots 6 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Short Cycle Highest High Buffer ... +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +// Short Cycle Lowest Low Buffer ... +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +// Medium Cycle Highest High Buffer ... +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrAqua +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 + +// +// Medium Cycle Lowest Low Buffer ... +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrFuchsia +#property indicator_style4 STYLE_DOT +#property indicator_width4 1 + +// +// Long Cycle Highest High Buffer ... +#property indicator_type5 DRAW_LINE +#property indicator_color5 C'62,82,6' +#property indicator_style5 STYLE_DOT +#property indicator_width5 1 + +// +// Long Cycle Lowest Low Buffer ... +#property indicator_type6 DRAW_LINE +#property indicator_color6 C'255,81,0' +#property indicator_style6 STYLE_DOT +#property indicator_width6 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +// +// HH Buffers ... +#define scHHBufferIndex 0 +#define scLLBufferIndex 1 +#define mcHHBufferIndex 2 +#define mcLLBufferIndex 3 +#define lcHHBufferIndex 4 +#define lcLLBufferIndex 5 + +double scHHBuffer[]; +double scLLBuffer[]; +double mcHHBuffer[]; +double mcLLBuffer[]; +double lcHHBuffer[]; +double lcLLBuffer[]; + +// +// Variables ... +int shortCycleLength; +int mediumCycleLength; +int longCycleLength; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if ( + marketLength <= 0 || + shortCycleMultiplier <= 0 || + mediumCycleMultiplier <= 0 || + shortCycleMultiplier > mediumCycleMultiplier + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + shortCycleLength = shortCycleMultiplier * marketLength; + mediumCycleLength = mediumCycleMultiplier * marketLength; + longCycleLength = longCycleMultiplier * marketLength; + + // + // Highest High and Lowest Low Buffers ... + // + // Short Cycle Highest High ... + string scHHLbl = StringConcatenate( + "SC HH(", shortCycleLength, ")" + ); + SetIndexBuffer(scHHBufferIndex, scHHBuffer); + SetIndexLabel(scHHBufferIndex, scHHLbl); + + // + // Short Cycle Lowest Low ... + string scLLLbl = StringConcatenate( + "SC LL(", shortCycleLength, ")" + ); + SetIndexBuffer(scLLBufferIndex, scLLBuffer); + SetIndexLabel(scLLBufferIndex, scLLLbl); + + // + // Medium Cycle Highest High ... + string mcHHLbl = StringConcatenate( + "MC HH(", mediumCycleLength, ")" + ); + SetIndexBuffer(mcHHBufferIndex, mcHHBuffer); + SetIndexLabel(mcHHBufferIndex, mcHHLbl); + + // + // Medium Cycle Lowest Low ... + string mcLLLbl = StringConcatenate( + "MC LL(", mediumCycleLength, ")" + ); + SetIndexBuffer(mcLLBufferIndex, mcLLBuffer); + SetIndexLabel(mcLLBufferIndex, mcLLLbl); + + // + // Long Cycle Highest High ... + string lcHHLbl = StringConcatenate( + "LC HH(", longCycleLength, ")" + ); + SetIndexBuffer(lcHHBufferIndex, lcHHBuffer); + SetIndexLabel(lcHHBufferIndex, lcHHLbl); + + // + // Long Cycle Lowest Low ... + string lcLLLbl = StringConcatenate( + "LC LL(", longCycleLength, ")" + ); + SetIndexBuffer(lcLLBufferIndex, lcLLBuffer); + SetIndexLabel(lcLLBufferIndex, lcLLLbl); + // + // End Set Index Buffers ... + // + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculat Ma's ... + // + CalculateShortCycle(i); + + // + CalculateMediumCycle(i); + + // + CalculateLongCycle(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Short Cycle ... +void CalculateShortCycle( + const int &bar_index +) { + // + // Short Cycle Highest High ... + // + int scHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + shortCycleLength, + bar_index + ); + + // + double scHH = iHigh( + _Symbol, + _Period, + scHHIdx + ); + + // + scHHBuffer[bar_index] = scHH; + + // + // Short Cycle Lowest Low ... + // + int scLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + shortCycleLength, + bar_index + ); + + // + double scLL = iLow( + _Symbol, + _Period, + scLLIdx + ); + + // + scLLBuffer[bar_index] = scLL; +} + +// +// Calculating Medium Cycle ... +void CalculateMediumCycle( + const int &bar_index +) { + // + // Medium Cycle Highest High ... + // + int mcHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + mediumCycleLength, + bar_index + ); + + // + double mcHH = iHigh( + _Symbol, + _Period, + mcHHIdx + ); + + // + mcHHBuffer[bar_index] = mcHH; + + // + // Medium Cycle Lowest Low ... + // + int mcLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + mediumCycleLength, + bar_index + ); + + // + double mcLL = iLow( + _Symbol, + _Period, + mcLLIdx + ); + + // + mcLLBuffer[bar_index] = mcLL; +} + +// +// Calculating Long Cycle ... +void CalculateLongCycle( + const int &bar_index +) { + // + // Long Cycle Highest High ... + // + int lcHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + longCycleLength, + bar_index + ); + + // + double lcHH = iHigh( + _Symbol, + _Period, + lcHHIdx + ); + + // + lcHHBuffer[bar_index] = lcHH; + + // + // Long Cycle Lowest Low ... + // + int lcLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + longCycleLength, + bar_index + ); + + // + double lcLL = iLow( + _Symbol, + _Period, + lcLLIdx + ); + + // + lcLLBuffer[bar_index] = lcLL; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.x.trend.power.mq4 b/xIndicators/x-saherelm.x.trend.power.mq4 new file mode 100644 index 0000000..dc70f81 --- /dev/null +++ b/xIndicators/x-saherelm.x.trend.power.mq4 @@ -0,0 +1,265 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center Trend Power Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm MA Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 7; // Market Length +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_separate_window + +// +#property indicator_plots 3 +#property indicator_buffers 3 +#property indicator_minimum 0 +#property indicator_maximum 100 + +// +#property indicator_levelcolor clrGray +#property indicator_levelstyle STYLE_DOT + +// +// Start Define Indicator Buffer Styles ... +// +#property indicator_type1 DRAW_HISTOGRAM +#property indicator_color1 clrLime +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +#property indicator_type2 DRAW_HISTOGRAM +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define powerUpBufferIndex 0 +#define powerDownBufferIndex 1 +#define signalBufferIndex 2 +#define diBufferIndex 3 + +double powerUpBuffer[]; +double powerDownBuffer[]; +double signalBuffer[]; +double diBuffer[]; + +// +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (marketLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + SetLevelValue(0, 0.0); + IndicatorSetString(INDICATOR_LEVELTEXT,0,""); + + // + SetLevelValue(1, 50); + IndicatorSetString(INDICATOR_LEVELTEXT,1,""); + + // + SetLevelValue(2, 100); + IndicatorSetString(INDICATOR_LEVELTEXT,2,""); + + // + string pUpLbl = StringConcatenate( + "P Up (", marketLength, ")" + ); + SetIndexLabel(powerUpBufferIndex, pUpLbl); + SetIndexBuffer(powerUpBufferIndex, powerUpBuffer); + SetIndexDrawBegin(powerUpBufferIndex, marketLength + 1); + + // + string pDownLbl = StringConcatenate( + "P Down (", marketLength, ")" + ); + SetIndexLabel(powerDownBufferIndex, pDownLbl); + SetIndexBuffer(powerDownBufferIndex, powerDownBuffer); + SetIndexDrawBegin(powerDownBufferIndex, marketLength + 1); + + // + string pSignalLbl = StringConcatenate( + "P Signal (", marketLength, ")" + ); + SetIndexLabel(signalBufferIndex, pSignalLbl); + SetIndexBuffer(signalBufferIndex, signalBuffer); + SetIndexDrawBegin(signalBufferIndex, marketLength + 1); + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "X_TPW_OSC"; + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Buffers ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateBuffers( + const int &bar_index +) { + // + double powerUp = 0; + double powerDown = 0; + + // + int dailyCount = GetDailyCandleCount(); + double dailyHH = GetMarketHighestHigh( + bar_index, + dailyCount + ); + double dailyLL = GetMarketLowestLow( + bar_index, + dailyCount + ); + double dailyDiff = dailyHH - dailyLL; + double rate = dailyDiff / 100; + + // + for (int i = bar_index; i < bar_index + marketLength; i++) { + // + XOHCL c = GetCandleModel(i); + + // + double cRange = + MathAbs(c.open - c.close) + // MathAbs(c.high - c.low) + ; + bool isBullish = c.open < c.close; + + // + if (isBullish) { + powerUp += cRange; + } else { + powerDown += cRange; + } + } + + // + powerUp = powerUp / rate; + powerDown = powerDown / rate; + + // + double ema = GetMA( + bar_index, + marketLength, + 0, + MODE_EMA, + PRICE_WEIGHTED + ); + + // + double signal = (ema / 100) * rate; + double signalAddition = MathMin(powerUp, powerDown); + + // + powerUpBuffer[bar_index] = powerUp; + powerDownBuffer[bar_index] = powerDown; + signalBuffer[bar_index] = signal + signalAddition; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.x.trend.power.v2.mq4 b/xIndicators/x-saherelm.x.trend.power.v2.mq4 new file mode 100644 index 0000000..de50c39 --- /dev/null +++ b/xIndicators/x-saherelm.x.trend.power.v2.mq4 @@ -0,0 +1,291 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center Trend Power Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm MA Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 7; // Market Length +input int shift = 0; // Shift +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_separate_window + +// +#property indicator_plots 3 +#property indicator_buffers 3 +// #property indicator_minimum 0 +// #property indicator_maximum 200 + +// +#property indicator_levelcolor clrGray +#property indicator_levelstyle STYLE_DOT + +// +// Start Define Indicator Buffer Styles ... +// +#property indicator_type1 DRAW_HISTOGRAM +#property indicator_color1 clrLime +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +#property indicator_type2 DRAW_HISTOGRAM +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 + +// +// #property indicator_type4 DRAW_LINE +// #property indicator_color4 clrAqua +// #property indicator_style4 STYLE_DASHDOT +// #property indicator_width4 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define powerUpBufferIndex 0 +#define powerDownBufferIndex 1 +#define signalBufferIndex 2 +// #define diBufferIndex 3 + +double powerUpBuffer[]; +double powerDownBuffer[]; +double signalBuffer[]; +// double diBuffer[]; + +// +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (marketLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // // + // SetLevelValue(0, 0.0); + // IndicatorSetString(INDICATOR_LEVELTEXT,0,""); + + // // + // SetLevelValue(1, 50); + // IndicatorSetString(INDICATOR_LEVELTEXT,1,""); + + // // + // SetLevelValue(2, 100); + // IndicatorSetString(INDICATOR_LEVELTEXT,2,""); + + // + string pUpLbl = StringConcatenate( + "P Up (", marketLength, ")" + ); + SetIndexLabel(powerUpBufferIndex, pUpLbl); + SetIndexBuffer(powerUpBufferIndex, powerUpBuffer); + SetIndexDrawBegin(powerUpBufferIndex, marketLength + 1); + + // + string pDownLbl = StringConcatenate( + "P Down (", marketLength, ")" + ); + SetIndexLabel(powerDownBufferIndex, pDownLbl); + SetIndexBuffer(powerDownBufferIndex, powerDownBuffer); + SetIndexDrawBegin(powerDownBufferIndex, marketLength + 1); + + // + string pSignalLbl = StringConcatenate( + "P Signal (", marketLength, ")" + ); + SetIndexLabel(signalBufferIndex, pSignalLbl); + SetIndexBuffer(signalBufferIndex, signalBuffer); + SetIndexDrawBegin(signalBufferIndex, marketLength + 1); + + // // + // string pDiLbl = StringConcatenate( + // "P DI (", marketLength, ")" + // ); + // SetIndexLabel(diBufferIndex, pDiLbl); + // SetIndexBuffer(diBufferIndex, diBuffer); + // SetIndexDrawBegin(diBufferIndex, marketLength + 1); + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "X_TPW_OSC"; + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Buffers ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateBuffers( + const int &bar_index +) { + // + double powerUp = 0; + double powerDown = 0; + + // + int dailyCount = GetDailyCandleCount(); + double dailyHH = GetMarketHighestHigh( + bar_index, + dailyCount + ); + double dailyLL = GetMarketLowestLow( + bar_index, + dailyCount + ); + double dailyDiff = dailyHH - dailyLL; + double rate = dailyDiff / 100; + + // + for (int i = bar_index + shift; i < bar_index + marketLength + shift; i++) { + // + XOHCL c = GetCandleModel(i); + + // + double cRange = + MathAbs(c.open - c.close) + // MathAbs(c.high - c.low) + ; + bool isBullish = c.open < c.close; + + // + if (isBullish) { + powerUp += cRange; + } else { + powerDown += cRange; + } + } + + // + powerUp = powerUp / rate; + powerDown = powerDown / rate; + + + // + double ema = GetMA( + bar_index, + (marketLength * 2), + 0, + MODE_EMA, + PRICE_WEIGHTED + ); + + // + powerUpBuffer[bar_index] = powerUp; + + // + powerDownBuffer[bar_index] = -1 * powerDown; + + // + double emaRate = MathAbs(powerUp - MathAbs(powerDown)) / 100; + double signal = (ema / 100) * emaRate; + + // + bool isPowerUp = powerUp > MathAbs(powerDown); + double signalAddition = isPowerUp ? (-1 * powerDown) : powerUp; + signalBuffer[bar_index] = signal + signalAddition; + // + // double pDiff = powerUpBuffer[bar_index] - powerDownBuffer[bar_index]; + // double cDiValue = pDiff + signalBuffer[bar_index]; + // diBuffer[bar_index] = cDiValue; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.x.xma.mq4 b/xIndicators/x-saherelm.x.xma.mq4 new file mode 100644 index 0000000..68b4f32 --- /dev/null +++ b/xIndicators/x-saherelm.x.xma.mq4 @@ -0,0 +1,355 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center X Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm X Indicator" +#property strict + +// +// START Inputs ... +// +// +input int marketLength = 7; // Market Length + +// +input int shortCycleMultiplier = 2; // Market Short Cycle Multiplier +input int mediumCycleMultiplier = 6; // Market Medium Cycle Multiplier +input int longCycleMultiplier = 36; // Market Medium Cycle Multiplier + +// +input ENUM_MA_METHOD maMethod = MODE_SMA; // Ma Method +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 6 + +// +#property indicator_plots 6 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Short Cycle Fast Buffer ... +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +// Short Cycle Slow Buffer ... +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +// Medium Cycle Fast Buffer ... +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrAqua +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 + +// +// Medium Cycle Slow Buffer ... +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrFuchsia +#property indicator_style4 STYLE_DOT +#property indicator_width4 1 + +// +// Long Cycle Fast Buffer ... +#property indicator_type5 DRAW_LINE +#property indicator_color5 C'62,82,6' +#property indicator_style5 STYLE_DOT +#property indicator_width5 1 + +// +// Long Cycle Slow Buffer ... +#property indicator_type6 DRAW_LINE +#property indicator_color6 C'255,81,0' +#property indicator_style6 STYLE_DOT +#property indicator_width6 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +// +// Ma Buffers ... +#define scFastBufferIndex 0 +#define scSlowBufferIndex 1 +#define mcFastBufferIndex 2 +#define mcSlowBufferIndex 3 +#define lcFastBufferIndex 4 +#define lcSlowBufferIndex 5 + +double scFastBuffer[]; +double scSlowBuffer[]; +double mcFastBuffer[]; +double mcSlowBuffer[]; +double lcFastBuffer[]; +double lcSlowBuffer[]; + +// +// Variables ... +int shortCycleLength; +int mediumCycleLength; +int longCycleLength; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if ( + marketLength <= 0 || + shortCycleMultiplier <= 0 || + mediumCycleMultiplier <= 0 || + shortCycleMultiplier > mediumCycleMultiplier + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + shortCycleLength = shortCycleMultiplier * marketLength; + mediumCycleLength = mediumCycleMultiplier * marketLength; + longCycleLength = longCycleMultiplier * marketLength; + + // + // Ma Buffers ... + // + // Short Cycle ... + string scFLbl = StringConcatenate( + "SC F(", shortCycleLength, ")" + ); + SetIndexBuffer(scFastBufferIndex, scFastBuffer); + SetIndexLabel(scFastBufferIndex, scFLbl); + + // + string scSLbl = StringConcatenate( + "SC S(", shortCycleLength, ")" + ); + SetIndexBuffer(scSlowBufferIndex, scSlowBuffer); + SetIndexLabel(scSlowBufferIndex, scSLbl); + + // + // Medium Cycle ... + string mcFLbl = StringConcatenate( + "MC F(", mediumCycleLength, ")" + ); + SetIndexBuffer(mcFastBufferIndex, mcFastBuffer); + SetIndexLabel(mcFastBufferIndex, mcFLbl); + + // + string mcSLbl = StringConcatenate( + "MC S(", mediumCycleLength, ")" + ); + SetIndexBuffer(mcSlowBufferIndex, mcSlowBuffer); + SetIndexLabel(mcSlowBufferIndex, mcSLbl); + + // + // Long Cycle ... + string lcFLbl = StringConcatenate( + "LC F(", longCycleLength, ")" + ); + SetIndexBuffer(lcFastBufferIndex, lcFastBuffer); + SetIndexLabel(lcFastBufferIndex, lcFLbl); + + // + string lcSLbl = StringConcatenate( + "LC S(", longCycleLength, ")" + ); + SetIndexBuffer(lcSlowBufferIndex, lcSlowBuffer); + SetIndexLabel(lcSlowBufferIndex, lcSLbl); + // + // End Set Index Buffers ... + // + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculat Ma's ... + // + CalculateShortCycle(i); + + // + CalculateMediumCycle(i); + + // + CalculateLongCycle(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Short Cycle ... +void CalculateShortCycle( + const int &bar_index +) { + // + double scFast = iMA( + _Symbol, + _Period, + shortCycleLength, + 0, + maMethod, + PRICE_OPEN, + bar_index + ); + scFastBuffer[bar_index] = scFast; + + // + double scSlow = iMA( + _Symbol, + _Period, + shortCycleLength, + 0, + maMethod, + PRICE_CLOSE, + bar_index + ); + scSlowBuffer[bar_index] = scSlow; +} + +// +// Calculating Medium Cycle ... +void CalculateMediumCycle( + const int &bar_index +) { + // + double mcFast = iMA( + _Symbol, + _Period, + mediumCycleLength, + 0, + maMethod, + PRICE_OPEN, + bar_index + ); + mcFastBuffer[bar_index] = mcFast; + + // + double mcSlow = iMA( + _Symbol, + _Period, + mediumCycleLength, + 0, + maMethod, + PRICE_CLOSE, + bar_index + ); + mcSlowBuffer[bar_index] = mcSlow; +} + +// +// Calculating Long Cycle ... +void CalculateLongCycle( + const int &bar_index +) { + // + double lcFast = iMA( + _Symbol, + _Period, + longCycleLength, + 0, + maMethod, + PRICE_OPEN, + bar_index + ); + lcFastBuffer[bar_index] = lcFast; + + // + double lcSlow = iMA( + _Symbol, + _Period, + longCycleLength, + 0, + maMethod, + PRICE_CLOSE, + bar_index + ); + lcSlowBuffer[bar_index] = lcSlow; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.xbnd.mq4 b/xIndicators/x-saherelm.xbnd.mq4 new file mode 100644 index 0000000..5cea8fd --- /dev/null +++ b/xIndicators/x-saherelm.xbnd.mq4 @@ -0,0 +1,425 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XBand Indicator +// --------------------------------------------- +// saherelm implementation of xBand Indicator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XBND Indicator" +#property strict + +// +#include "../Libraries/x-saherelm.lib.mq4" +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +// START Inputs ... +// +input int marketLength = 5; // Averaging Length +input int ignoreLastCross = 4; // Ignore Last Cross +input int shift = 0; // Averaging Shift +input ENUM_MA_METHOD method = MODE_SMA; // Averaging Mode +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_chart_window + +// +#property indicator_buffers 4 + +// +// Declare Buffers ... +// +// High ... +#property indicator_width1 1 +#property indicator_color1 clrAqua +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_DASHDOT + +// +// Open ... +#property indicator_width2 1 +#property indicator_color2 clrGreen +#property indicator_type2 DRAW_LINE +#property indicator_style2 STYLE_DASH + +// +// Close ... +#property indicator_width3 1 +#property indicator_color3 clrRed +#property indicator_type3 DRAW_LINE +#property indicator_style3 STYLE_DASH + +// +// Low ... +#property indicator_width4 1 +#property indicator_color4 clrFuchsia +#property indicator_type4 DRAW_LINE +#property indicator_style4 STYLE_DASHDOT + +// +#define highBufferIndex 0 +#define openBufferIndex 1 +#define closeBufferIndex 2 +#define lowBufferIndex 3 + +// +double highBuffer[]; +double openBuffer[]; +double closeBuffer[]; +double lowBuffer[]; + +// +datetime lastCrossTime; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + marketLength < 2 + || ignoreLastCross < 0 + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XBND"; + + // + // High ... + string highLabel = StringConcatenate( + "High(", marketLength, ")" + ); + SetIndexBuffer(highBufferIndex, highBuffer); + SetIndexLabel(highBufferIndex, highLabel); + + // + // Open ... + string openLabel = StringConcatenate( + "Open(", marketLength, ")" + ); + SetIndexBuffer(openBufferIndex, openBuffer); + SetIndexLabel(openBufferIndex, openLabel); + + // + // Close ... + string closeLabel = StringConcatenate( + "Close(", marketLength, ")" + ); + SetIndexBuffer(closeBufferIndex, closeBuffer); + SetIndexLabel(closeBufferIndex, closeLabel); + + // + // Low ... + string lowLabel = StringConcatenate( + "Low(", marketLength, ")" + ); + SetIndexBuffer(lowBufferIndex, lowBuffer); + SetIndexLabel(lowBufferIndex, lowLabel); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + RemoveDraws(logTag); +} + +// +// Do Calculation ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Buffers ... + CalculateBuffers(i); + + // + // Calculate Market Changes ... + CalculateInfo(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index +) { + // + // High ... + double high = iMA( + _Symbol, + _Period, + marketLength, + shift, + method, + PRICE_HIGH, + bar_index + ); + + // + highBuffer[bar_index] = high; + + // + // Open ... + double open = iMA( + _Symbol, + _Period, + marketLength, + shift, + method, + PRICE_OPEN, + bar_index + ); + + // + openBuffer[bar_index] = open; + + // + // Close ... + double close = iMA( + _Symbol, + _Period, + marketLength, + shift, + method, + PRICE_CLOSE, + bar_index + ); + + // + closeBuffer[bar_index] = close; + + // + // Low ... + double low = iMA( + _Symbol, + _Period, + marketLength, + shift, + method, + PRICE_LOW, + bar_index + ); + + // + lowBuffer[bar_index] = low; +} + +// +void CalculateInfo( + const int bar_index +) { + // + XOHCL pCandle = GetCandleModel(bar_index); + + // + bool isTrendingUp = + pCandle.low > highBuffer[bar_index] + && pCandle.high > highBuffer[bar_index]; + + // + bool isTrendingDown = + pCandle.high < lowBuffer[bar_index] + && pCandle.low < lowBuffer[bar_index]; + + // + bool isOpenCrossOverClose = + true + // && + // ( + // pCandle.high > highBuffer[bar_index + 1] + // || pCandle.low < lowBuffer[bar_index + 1] + // ) + && openBuffer[bar_index + 1] > closeBuffer[bar_index + 1] + && !(openBuffer[bar_index + 2] >= closeBuffer[bar_index + 2]) + ; + + // + bool isOpenCrossUnderClose = + true + // && + // ( + // pCandle.high > highBuffer[bar_index + 1] + // || pCandle.low < lowBuffer[bar_index + 1] + // ) + && openBuffer[bar_index + 1] < closeBuffer[bar_index + 1] + && !(openBuffer[bar_index + 2] <= closeBuffer[bar_index + 2]) + ; + + // + isTrendingUp = isOpenCrossUnderClose; + isTrendingDown = isOpenCrossOverClose; + + // + datetime time = iTime( + _Symbol, + _Period, + bar_index + ); + + // + if ( + isTrendingUp + || isTrendingDown + ) { + // + if (lastCrossTime == 0) { + lastCrossTime = time; + } else { + // + int lastCrossBarIndex = iBarShift( + _Symbol, + _Period, + lastCrossTime + ); + + // + int diff = lastCrossBarIndex - bar_index; + if (diff <= ignoreLastCross) { + return; + } else { + lastCrossTime = time; + } + } + } + + // + string lbl = StringConcatenate( + logTag, + "_Arrow_", + isTrendingUp ? "UP" : "Down", + "_", time + ); + + // + color clr = isTrendingUp ? + clrAqua : + clrFuchsia; + + // + ENUM_ARROW_ANCHOR anchor = isTrendingUp ? + ANCHOR_BOTTOM : + ANCHOR_TOP; + + // + uchar arrowCode = isTrendingUp ? + SYMBOL_ARROWUP : + SYMBOL_ARROWDOWN; + + // + double price = isTrendingUp ? + pCandle.low - 20 * _Point : + pCandle.high + 20 * _Point; + + // + if (isTrendingUp) { + // + // this means Market Going Up ... + + } + + // + if (isTrendingDown) { + // + // this means Market Going Downm ... + } + + // + if ( + isTrendingUp + || isTrendingDown + ) { + // + bool isDrawn = DrawArrow( + 0, + lbl, + 0, + time, + price, + arrowCode, + anchor, + clr + ); + } +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.xhh.mq4 b/xIndicators/x-saherelm.xhh.mq4 new file mode 100644 index 0000000..dfbc2cd --- /dev/null +++ b/xIndicators/x-saherelm.xhh.mq4 @@ -0,0 +1,410 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XHH Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XHH Indicator" +#property strict + +// +// START Inputs ... +// +// +input int marketLength = 7; // Market Length + +// +input int shortCycleMultiplier = 4; // Market Short Cycle Multiplier +input int mediumCycleMultiplier = 14; // Market Medium Cycle Multiplier +input int longCycleMultiplier = 27; // Market Medium Cycle Multiplier +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 6 + +// +#property indicator_plots 6 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Short Cycle Highest High Buffer ... +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +// Short Cycle Lowest Low Buffer ... +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +// Medium Cycle Highest High Buffer ... +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrAqua +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 + +// +// Medium Cycle Lowest Low Buffer ... +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrFuchsia +#property indicator_style4 STYLE_DOT +#property indicator_width4 1 + +// +// Long Cycle Highest High Buffer ... +#property indicator_type5 DRAW_LINE +#property indicator_color5 C'62,82,6' +#property indicator_style5 STYLE_DOT +#property indicator_width5 1 + +// +// Long Cycle Lowest Low Buffer ... +#property indicator_type6 DRAW_LINE +#property indicator_color6 C'255,81,0' +#property indicator_style6 STYLE_DOT +#property indicator_width6 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define shortCycleHighestHighBufferIndex 0 +#define shortCycleLowestLowBufferIndex 1 +#define mediumCycleHighestHighBufferIndex 2 +#define mediumCycleLowestLowBufferIndex 3 +#define longCycleHighestHighBufferIndex 4 +#define longCycleLowestLowBufferIndex 5 + +double shortCycleHighestHighBuffer[]; +double shortCycleLowestLowBuffer[]; +double mediumCycleHighestHighBuffer[]; +double mediumCycleLowestLowBuffer[]; +double longCycleHighestHighBuffer[]; +double longCycleLowestLowBuffer[]; + +// +// Variables ... +int shortCycleLength; +int mediumCycleLength; +int longCycleLength; + +// +double highestHighTimes[]; +double lowestLowTimes[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if ( + marketLength <= 0 || + shortCycleMultiplier <= 0 || + mediumCycleMultiplier <= 0 || + shortCycleMultiplier > mediumCycleMultiplier + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + shortCycleLength = shortCycleMultiplier * marketLength; + mediumCycleLength = mediumCycleMultiplier * marketLength; + longCycleLength = longCycleMultiplier * marketLength; + + // + // Short Cycle Highest High ... + string scHHLbl = StringConcatenate( + "SC HH(", shortCycleLength, ")" + ); + SetIndexBuffer(shortCycleHighestHighBufferIndex, shortCycleHighestHighBuffer); + SetIndexLabel(shortCycleHighestHighBufferIndex, scHHLbl); + + // + // Short Cycle Lowest Low ... + string scLLLbl = StringConcatenate( + "SC LL(", shortCycleLength, ")" + ); + SetIndexBuffer(shortCycleLowestLowBufferIndex, shortCycleLowestLowBuffer); + SetIndexLabel(shortCycleLowestLowBufferIndex, scLLLbl); + + // + // Medium Cycle Highest High ... + string mcHHLbl = StringConcatenate( + "MC HH(", mediumCycleLength, ")" + ); + SetIndexBuffer(mediumCycleHighestHighBufferIndex, mediumCycleHighestHighBuffer); + SetIndexLabel(mediumCycleHighestHighBufferIndex, mcHHLbl); + + // + // Medium Cycle Lowest Low ... + string mcLLLbl = StringConcatenate( + "MC LL(", mediumCycleLength, ")" + ); + SetIndexBuffer(mediumCycleLowestLowBufferIndex, mediumCycleLowestLowBuffer); + SetIndexLabel(mediumCycleLowestLowBufferIndex, mcLLLbl); + + // + // Long Cycle Highest High ... + string lcHHLbl = StringConcatenate( + "LC HH(", longCycleLength, ")" + ); + SetIndexBuffer(longCycleHighestHighBufferIndex, longCycleHighestHighBuffer); + SetIndexLabel(longCycleHighestHighBufferIndex, lcHHLbl); + + // + // Long Cycle Lowest Low ... + string lcLLLbl = StringConcatenate( + "LC LL(", longCycleLength, ")" + ); + SetIndexBuffer(longCycleLowestLowBufferIndex, longCycleLowestLowBuffer); + SetIndexLabel(longCycleLowestLowBufferIndex, lcLLLbl); + // + // End Set Index Buffers ... + // + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + CalculateShortCycle(i); + + // + CalculateMediumCycle(i); + + // + CalculateLongCycle(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Short Cycle ... +void CalculateShortCycle( + const int &bar_index +) { + // + // Short Cycle Highest High ... + // + int scHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + shortCycleLength, + bar_index + ); + + // + double scHH = iHigh( + _Symbol, + _Period, + scHHIdx + ); + + // + shortCycleHighestHighBuffer[bar_index] = scHH; + + // + // Short Cycle Lowest Low ... + // + int scLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + shortCycleLength, + bar_index + ); + + // + double scLL = iLow( + _Symbol, + _Period, + scLLIdx + ); + + // + shortCycleLowestLowBuffer[bar_index] = scLL; +} + +// +// Calculating Medium Cycle ... +void CalculateMediumCycle( + const int &bar_index +) { + // + // Medium Cycle Highest High ... + // + int mcHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + mediumCycleLength, + bar_index + ); + + // + double mcHH = iHigh( + _Symbol, + _Period, + mcHHIdx + ); + + // + mediumCycleHighestHighBuffer[bar_index] = mcHH; + + // + // Medium Cycle Lowest Low ... + // + int mcLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + mediumCycleLength, + bar_index + ); + + // + double mcLL = iLow( + _Symbol, + _Period, + mcLLIdx + ); + + // + mediumCycleLowestLowBuffer[bar_index] = mcLL; +} + +// +// Calculating Long Cycle ... +void CalculateLongCycle( + const int &bar_index +) { + // + // Long Cycle Highest High ... + // + int lcHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + longCycleLength, + bar_index + ); + + // + double lcHH = iHigh( + _Symbol, + _Period, + lcHHIdx + ); + + // + longCycleHighestHighBuffer[bar_index] = lcHH; + + // + // Long Cycle Lowest Low ... + // + int lcLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + longCycleLength, + bar_index + ); + + // + double lcLL = iLow( + _Symbol, + _Period, + lcLLIdx + ); + + // + longCycleLowestLowBuffer[bar_index] = lcLL; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.xma.1.mq4 b/xIndicators/x-saherelm.xma.1.mq4 new file mode 100644 index 0000000..4c96e36 --- /dev/null +++ b/xIndicators/x-saherelm.xma.1.mq4 @@ -0,0 +1,337 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XMA Indicator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XMA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Set the R2R Length ... +input int swingLoopback = 7; // Swing Loopback +input int xmaFlowMultiplier = 3; // XMA Flow Multiplier +input int xmaMarkMultiplier = 5; // XMA Mark Multiplier +input int xmaFastMultiplier = 7; // XMA Fast Multiplier +input int xmaSlowMultiplier = 14; // XMA Slow Multiplier +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// define indicator buffers ... +#property indicator_buffers 6 +#property indicator_plots 6 + +// +// XMA High ... +#property indicator_label1 "XMA High" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrLime +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +// +// XMA Low ... +#property indicator_label2 "XMA Low" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrOrange +#property indicator_style2 STYLE_SOLID +#property indicator_width2 1 + +// +// XMA Mark ... +#property indicator_label3 "XMA Mark" +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrCornflowerBlue +#property indicator_style3 STYLE_DASH +#property indicator_width3 1 + +// +// XMA Mid ... +#property indicator_label4 "XMA Mid" +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrBisque +#property indicator_style4 STYLE_DASHDOT +#property indicator_width4 1 + +// +// XMA Fast ... +#property indicator_label5 "XMA Fast" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrGreen +#property indicator_style5 STYLE_DOT +#property indicator_width5 1 + +// +// XMA Slow ... +#property indicator_label6 "XMA Slow" +#property indicator_type6 DRAW_LINE +#property indicator_color6 clrRed +#property indicator_style6 STYLE_DOT +#property indicator_width6 1 + +// +// Declare Buffers ... +#define xmaHighBufferIndex 0 +#define xmaLowBufferIndex 1 +#define xmaMarkBufferIndex 2 +#define xmaMidBufferIndex 3 +#define xmaFastBufferIndex 4 +#define xmaSlowBufferIndex 5 + +// +double xmaHighBuffer[]; +double xmaLowBuffer[]; +double xmaMarkBuffer[]; +double xmaMidBuffer[]; +double xmaFastBuffer[]; +double xmaSlowBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + + // + // Validating Input Parameters ... + if (swingLoopback <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // XMA High ... + SetIndexBuffer(xmaHighBufferIndex, xmaHighBuffer); + SetIndexDrawBegin(xmaHighBufferIndex, swingLoopback * xmaFlowMultiplier); + + // + // XMA Low ... + SetIndexBuffer(xmaLowBufferIndex, xmaLowBuffer); + SetIndexDrawBegin(xmaLowBufferIndex, swingLoopback * xmaFlowMultiplier); + + // + // XMA Mark ... + SetIndexBuffer(xmaMarkBufferIndex, xmaMarkBuffer); + SetIndexDrawBegin(xmaMarkBufferIndex, swingLoopback * xmaMarkMultiplier); + + // + // XMA Mid ... + SetIndexBuffer(xmaMidBufferIndex, xmaMidBuffer); + SetIndexDrawBegin(xmaMidBufferIndex, swingLoopback); + + // + // XMA Fast ... + SetIndexBuffer(xmaFastBufferIndex, xmaFastBuffer); + SetIndexDrawBegin(xmaFastBufferIndex, swingLoopback * xmaFastMultiplier); + + // + // XMA Slow ... + SetIndexBuffer(xmaSlowBufferIndex, xmaSlowBuffer); + SetIndexDrawBegin(xmaSlowBufferIndex, swingLoopback * xmaSlowMultiplier); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, swingLoopback); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate XMA Flow ... + CalculateXMAFlow(i); + + // + // Calculate XMA Mark ... + CalculateXMAMark(i); + + // + // Calculate XMA Mid ... + CalculateXMAMid(i); + + // + // Calculate XMA Fast/Slow ... + CalculateXMAFastSlow(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculate XMA Flow ... +void CalculateXMAFlow(const int &bar_index) { + // + int xmaFlowLength = swingLoopback * xmaFlowMultiplier; + + // + // Calculating XMa High ... + double xmaHigh = iMA( + _Symbol, + _Period, + xmaFlowLength, + 0, + MODE_SMA, + PRICE_HIGH, + bar_index + ); + xmaHighBuffer[bar_index] = xmaHigh; + + // + // Calculating XMa Low ... + double xmaLow = iMA( + _Symbol, + _Period, + xmaFlowLength, + 0, + MODE_SMA, + PRICE_LOW, + bar_index + ); + xmaLowBuffer[bar_index] = xmaLow; +} + +// +// Calculate XMA Mark ... +void CalculateXMAMark(const int &bar_index) { + // + int xmaMarkLength = swingLoopback * xmaMarkMultiplier; + + // + // Calculating XMa Mark ... + double xmaMark = iMA( + _Symbol, + _Period, + xmaMarkLength, + 0, + MODE_SMA, + PRICE_HIGH, + bar_index + ); + xmaMarkBuffer[bar_index] = xmaMark; +} + +// +// Calculate XMA Mid ... +void CalculateXMAMid(const int &bar_index) { + // + // Calculating XMa Mid ... + double xmaMid = iMA( + _Symbol, + _Period, + swingLoopback, + 0, + MODE_EMA, + PRICE_HIGH, + bar_index + ); + xmaMidBuffer[bar_index] = xmaMid; +} + +// +// Calculate XMA Fast/Slow ... +void CalculateXMAFastSlow(const int &bar_index) { + // + int xmaFastLength = swingLoopback * xmaFastMultiplier; + int xmaSlowLength = swingLoopback * xmaSlowMultiplier; + + // + // Calculating XMa Fast ... + double xmaFast = iMA( + _Symbol, + _Period, + xmaFastLength, + 0, + MODE_SMA, + PRICE_CLOSE, + bar_index + ); + xmaFastBuffer[bar_index] = xmaFast; + + // + // Calculating XMa Slow ... + double xmaSlow = iMA( + _Symbol, + _Period, + xmaSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE, + bar_index + ); + xmaSlowBuffer[bar_index] = xmaSlow; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.xma.mq4 b/xIndicators/x-saherelm.xma.mq4 new file mode 100644 index 0000000..4a599f9 --- /dev/null +++ b/xIndicators/x-saherelm.xma.mq4 @@ -0,0 +1,695 @@ + /////////////////////////////////////////////////////// +// +// SaherElm IT Center XMA Indicator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XMA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Market Specifications ... +input int marketLength = 7; // Market Length +input double step = 0.02; // SAR Step +input double maximum = 0.2; // SAR Maximum +// +// Cycle Definitions ... +input int shortCycleFastMultiplier = 1; // Short Cycle Fast Multiplier +input int shortCycleSlowMultiplier = 4; // Short Cycle Slow Multiplier +input int mediumCycleFastMultiplier = 7; // Medium Cycle Fast Multiplier +input int mediumCycleSlowMultiplier = 14; // Medium Cycle Slow Multiplier +input int longCycleFastMultiplier = 70; // Long Cycle Fast Multiplier +input int longCycleSlowMultiplier = 140; // Long Cycle Slow Multiplier +// +// Show Inputs ... +input bool showPSar = true; // Show Parabolic Sar +input bool showMarketMiddle = true; // Show Market Middle +input bool showShortCycle = true; // Show Short Cycle +input bool showShortCycleCrossLines = true; // Show Short Cycle Vertical Lines +input bool showMediumCycle = true; // Show Medium Cycle +input bool showMediumCycleCrossLines = true; // Show Medium Cycle Vertical Lines +input bool showLongCycle = true; // Show Long Cycle +input bool showLongCycleCrossLines = true; // Show Long Cycle Vertical Lines +// +// Color Inputs ... +input color pSarColor = clrCornflowerBlue; // Parabolic Sar Color +input color shortCycleFastColor = clrGreen; // Short Cycle Fast Color +input color shortCycleSlowColor = clrRed; // Short Cycle Slow Color +input color mediumCycleFastColor = clrAqua; // Medium Cycle Fast Color +input color mediumCycleSlowColor = clrFuchsia; // Medium Cycle Slow Color +input color longCycleFastColor = clrGoldenrod; // Medium Cycle Fast Color +input color longCycleSlowColor = clrBrown; // Medium Cycle Slow Color +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// define indicator buffers ... +#property indicator_buffers 8 +#property indicator_plots 8 + +// +// Declare Buffers ... +#define scFastBufferIndex 0 +#define scSlowBufferIndex 1 +#define mcFastBufferIndex 2 +#define mcSlowBufferIndex 3 +#define lcFastBufferIndex 4 +#define lcSlowBufferIndex 5 +#define midBufferIndex 6 +#define pSarBufferIndex 7 + +// +double scFastBuffer[]; +double scSlowBuffer[]; +double mcFastBuffer[]; +double mcSlowBuffer[]; +double lcFastBuffer[]; +double lcSlowBuffer[]; +double midBuffer[]; +double pSarBuffer[]; + +// +int shortCycleFastLength; +int shortCycleSlowLength; +int mediumCycleFastLength; +int mediumCycleSlowLength; +int longCycleFastLength; +int longCycleSlowLength; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + // + // Validate Market Length ... + marketLength <= 0 + // + // Validate Short Cycle ... + || shortCycleFastMultiplier <= 0 + || shortCycleSlowMultiplier <= 0 + || shortCycleFastMultiplier >= shortCycleSlowMultiplier + // + // Validate Medium Cycle ... + || mediumCycleFastMultiplier <= 0 + || mediumCycleSlowMultiplier <= 0 + || mediumCycleFastMultiplier >= mediumCycleSlowMultiplier + // + // Validate Long Cycle ... + || longCycleFastMultiplier <= 0 + || longCycleSlowMultiplier <= 0 + || longCycleFastMultiplier >= longCycleSlowMultiplier + // + // Validate Series of Multipliers ... + || shortCycleFastMultiplier >= mediumCycleFastMultiplier + || mediumCycleFastMultiplier >= longCycleFastMultiplier + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST_XMA"; + + // + // Calculate Cycle Length based on given Multipliers ... + shortCycleFastLength = marketLength * shortCycleFastMultiplier; + shortCycleSlowLength = marketLength * shortCycleSlowMultiplier; + mediumCycleFastLength = marketLength * mediumCycleFastMultiplier; + mediumCycleSlowLength = marketLength * mediumCycleSlowMultiplier; + longCycleFastLength = marketLength * longCycleFastMultiplier; + longCycleSlowLength = marketLength * longCycleSlowMultiplier; + + // + // Short Cycle Fast ... + SetIndexLabel(scFastBufferIndex, "SCFast"); + SetIndexBuffer(scFastBufferIndex, scFastBuffer); + SetIndexDrawBegin(scFastBufferIndex, shortCycleFastLength); + SetIndexStyle( + scFastBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showShortCycle ? + shortCycleFastColor : + clrNONE + ); + + // + // Short Cycle Slow ... + SetIndexLabel(scSlowBufferIndex, "SCSLow"); + SetIndexBuffer(scSlowBufferIndex, scSlowBuffer); + SetIndexDrawBegin(scSlowBufferIndex, shortCycleSlowLength); + SetIndexStyle( + scSlowBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showShortCycle ? + shortCycleSlowColor : + clrNONE + ); + + // + // Medium Cycle Fast ... + SetIndexLabel(mcFastBufferIndex, "MCFast"); + SetIndexBuffer(mcFastBufferIndex, mcFastBuffer); + SetIndexDrawBegin(mcFastBufferIndex, mediumCycleFastLength); + SetIndexStyle( + mcFastBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showMediumCycle ? + mediumCycleFastColor : + clrNONE + ); + + // + // Medium Cycle Slow ... + SetIndexLabel(mcSlowBufferIndex, "MCSlow"); + SetIndexBuffer(mcSlowBufferIndex, mcSlowBuffer); + SetIndexDrawBegin(mcSlowBufferIndex, mediumCycleSlowLength); + SetIndexStyle( + mcSlowBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showMediumCycle ? + mediumCycleSlowColor : + clrNONE + ); + + // + // Long Cycle Fast ... + SetIndexLabel(lcFastBufferIndex, "LCFast"); + SetIndexBuffer(lcFastBufferIndex, lcFastBuffer); + SetIndexDrawBegin(lcFastBufferIndex, longCycleFastLength); + SetIndexStyle( + lcFastBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showLongCycle ? + longCycleFastColor : + clrNONE + ); + + // + // Long Cycle Slow ... + SetIndexLabel(lcSlowBufferIndex, "LCSlow"); + SetIndexBuffer(lcSlowBufferIndex, lcSlowBuffer); + SetIndexDrawBegin(lcSlowBufferIndex, longCycleSlowLength); + SetIndexStyle( + lcSlowBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showLongCycle ? + longCycleSlowColor : + clrNONE + ); + + // + // Market Middleage ... + SetIndexBuffer(midBufferIndex, midBuffer); + SetIndexDrawBegin(midBufferIndex, marketLength); + SetIndexLabel(midBufferIndex, "Market Mid"); + + // + // Parabolic Sar ... + SetIndexBuffer(pSarBufferIndex, pSarBuffer); + SetIndexLabel(pSarBufferIndex, "P Sar"); + SetIndexStyle( + pSarBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showPSar ? + pSarColor : + clrNONE + ); + + // + // Market Middle ... + SetIndexBuffer(midBufferIndex, midBuffer); + SetIndexLabel(midBufferIndex, "Mid"); + SetIndexStyle( + midBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showMarketMiddle ? + clrAntiqueWhite : + clrNONE + ); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + RemoveDraws(logTag); +} + +// +// Do Calculation ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(marketLength, longCycleSlowLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Short Cycle ... + CalculateShortCycle(i); + + // + // Calculate Medium Cycle ... + CalculateMediumCycle(i); + + // + // Calculate Long Cycle ... + CalculateLongCycle(i); + + // + // Calculate Market Middleage ... + CalculateMarketMiddleage(i); + + // + // Calculate Cross Points ... + CalculateCrossPoints(i); + + // + // Calculate Parabolic Sar ... + CalculateParabolicSar(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculate Short Cycle ... +void CalculateShortCycle( + const int bar_index +) { + // + // Fast ... + double shortCycleFast = iMA( + _Symbol, + _Period, + shortCycleFastLength, + 0, + MODE_SMA, + PRICE_WEIGHTED, + bar_index + ); + scFastBuffer[bar_index] = shortCycleFast; + + // + // Slow ... + double shortCycleSlow = iMA( + _Symbol, + _Period, + shortCycleSlowLength, + 0, + MODE_SMA, + PRICE_WEIGHTED, + bar_index + ); + scSlowBuffer[bar_index] = shortCycleSlow; +} + +// +// Calculate Medium Cycle ... +void CalculateMediumCycle( + const int bar_index +) { + // + // Fast ... + double mediumCycleFast = iMA( + _Symbol, + _Period, + mediumCycleFastLength, + 0, + MODE_SMA, + PRICE_MEDIAN, + bar_index + ); + mcFastBuffer[bar_index] = mediumCycleFast; + + // + // Slow ... + double mediumCycleSlow = iMA( + _Symbol, + _Period, + mediumCycleSlowLength, + 0, + MODE_SMA, + PRICE_MEDIAN, + bar_index + ); + mcSlowBuffer[bar_index] = mediumCycleSlow; +} + +// +// Calculate Long Cycle ... +void CalculateLongCycle( + const int bar_index +) { + // + // Fast ... + double longCycleFast = iMA( + _Symbol, + _Period, + longCycleFastLength, + 0, + MODE_SMA, + PRICE_CLOSE, + bar_index + ); + lcFastBuffer[bar_index] = longCycleFast; + + // + // Slow ... + double longCycleSlow = iMA( + _Symbol, + _Period, + longCycleSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE, + bar_index + ); + lcSlowBuffer[bar_index] = longCycleSlow; +} + +// +// Calculate Market Middleage ... +void CalculateMarketMiddleage( + const int bar_index +) { + // + // Mid ... + double marketMiddleage = iMA( + _Symbol, + _Period, + (int)(marketLength * 1.5), + 0, + MODE_EMA, + PRICE_MEDIAN, + bar_index + ); + midBuffer[bar_index] = marketMiddleage; +} + +// +// Calculate Cross Points and Draw Section Line on theme ... +void CalculateCrossPoints( + const int bar_index +) { + // + // START Draw Cross Lines ... + // + // + // Short Cycle ... + bool isSCFastCrossOverSlow = scFastBuffer[bar_index] > scSlowBuffer[bar_index] + && !(scFastBuffer[bar_index + 1] > scSlowBuffer[bar_index + 1]); + + // + bool isSCFastCrossUnderSlow = scFastBuffer[bar_index] < scSlowBuffer[bar_index] + && !(scFastBuffer[bar_index + 1] < scSlowBuffer[bar_index + 1]); + + // + // Medium Cycle ... + bool isMCFastCrossOverSlow = mcFastBuffer[bar_index] > mcSlowBuffer[bar_index] + && !(mcFastBuffer[bar_index + 1] > mcSlowBuffer[bar_index + 1]); + + // + bool isMCFastCrossUnderSlow = mcFastBuffer[bar_index] < mcSlowBuffer[bar_index] + && !(mcFastBuffer[bar_index + 1] < mcSlowBuffer[bar_index + 1]); + + // + // Long Cycle ... + bool isLCFastCrossOverSlow = lcFastBuffer[bar_index] > lcSlowBuffer[bar_index] + && !(lcFastBuffer[bar_index + 1] > lcSlowBuffer[bar_index + 1]); + + // + bool isLCFastCrossUnderSlow = lcFastBuffer[bar_index] < lcSlowBuffer[bar_index] + && !(lcFastBuffer[bar_index + 1] < lcSlowBuffer[bar_index + 1]); + + // + // START Drawing CrossPoints ... + // + // + datetime currentTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + if (showShortCycleCrossLines) { + // + // Draw Line ... + if (isSCFastCrossOverSlow) { + // + string lbl = StringConcatenate( + logTag, + "_SC_F_OV_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showShortCycleCrossLines ? + shortCycleFastColor : + clrNONE + ); + } + + // + // Draw Line ... + if (isSCFastCrossUnderSlow) { + // + string lbl = StringConcatenate( + logTag, + "_SC_F_UN_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showShortCycleCrossLines ? + shortCycleSlowColor : + clrNONE + ); + } + } + + // + if (showMediumCycleCrossLines) { + // + // Draw Line ... + if (isMCFastCrossOverSlow) { + // + string lbl = StringConcatenate( + logTag, + "_MC_F_OV_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showMediumCycleCrossLines ? + mediumCycleFastColor : + clrNONE + ); + } + + // + // Draw Line ... + if (isMCFastCrossUnderSlow) { + // + string lbl = StringConcatenate( + logTag, + "_MC_F_UN_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showMediumCycleCrossLines ? + mediumCycleSlowColor : + clrNONE + ); + } + } + + // + if (showLongCycleCrossLines) { + // + // Draw Line ... + if (isLCFastCrossOverSlow) { + // + string lbl = StringConcatenate( + logTag, + "_LC_F_OV_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showLongCycleCrossLines ? + longCycleFastColor : + clrNONE + ); + } + + // + // Draw Line ... + if (isLCFastCrossUnderSlow) { + // + string lbl = StringConcatenate( + logTag, + "_LC_F_UN_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showLongCycleCrossLines ? + longCycleSlowColor : + clrNONE + ); + } + } + // + // END Drawing CrossPoints ... + // +} + +void CalculateParabolicSar( + const int bar_index +) { + // + double sarValue = iSAR( + NULL, + _Period, + step, + maximum, + bar_index + ); + + // + pSarBuffer[bar_index] = sarValue; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.xmarket.mq4 b/xIndicators/x-saherelm.xmarket.mq4 new file mode 100644 index 0000000..71b2e2c --- /dev/null +++ b/xIndicators/x-saherelm.xmarket.mq4 @@ -0,0 +1,394 @@ + /////////////////////////////////////////////////////// +// +// SaherElm IT Center XMKT Indicator +// --------------------------------------------- +// retrieve market base info ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XMKT Indicator" +#property strict + +// +// START Inputs ... +// +// +// Market Specifications ... +input int marketLength = 7; // Market Length +// +input bool showHighestHigh = true; // Show Market Highest High +input bool showHighestLow = true; // Show Market Highest Low +input bool showHighestOpen = true; // Show Market Highest Open +input bool showHighestClose = true; // Show Market Highest Close +input bool showLowestHigh = true; // Show Market Lowest High +input bool showLowestLow = true; // Show Market Lowest Low +input bool showLowestOpen = true; // Show Market Lowest Open +input bool showLowestClose = true; // Show Market Lowest Close +// +input color highestHighColor = clrDeepPink; // Market Highest High Color +input color highestLowColor = clrDarkOrange; // Market Highest Low Color +input color highestOpenColor = clrDodgerBlue; // Market Highest Open Color +input color highestCloseColor = clrOrchid; // Market Highest Close Color +input color lowestHighColor = clrHotPink; // Market Lowest High Color +input color lowestLowColor = clrOrange; // Market Lowest Low Color +input color lowestOpenColor = clrPowderBlue; // Market Lowest Open Color +input color lowestCloseColor = clrMediumOrchid; // Market Lowest Close Color +// +input ENUM_LINE_STYLE highestHighStyle = STYLE_DOT; // Market Highest High Line Style +input ENUM_LINE_STYLE highestLowStyle = STYLE_DOT; // Market Highest Low Line Style +input ENUM_LINE_STYLE highestOpenStyle = STYLE_DOT; // Market Highest Open Line Style +input ENUM_LINE_STYLE highestCloseStyle = STYLE_DOT; // Market Highest Close Line Style +input ENUM_LINE_STYLE lowestHighStyle = STYLE_DOT; // Market Lowest High Line Style +input ENUM_LINE_STYLE lowestLowStyle = STYLE_DOT; // Market Lowest Low Line Style +input ENUM_LINE_STYLE lowestOpenStyle = STYLE_DOT; // Market Lowest Open Line Style +input ENUM_LINE_STYLE lowestCloseStyle = STYLE_DOT; // Market Lowest Close Line Style +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// define indicator buffers ... +#property indicator_buffers 8 +#property indicator_plots 8 + +// +// Declare Buffers ... +#define marketHighestHighBufferIndex 0 +#define marketHighestLowBufferIndex 1 +#define marketHighestOpenBufferIndex 2 +#define marketHighestCloseBufferIndex 3 +#define marketLowestHighBufferIndex 4 +#define marketLowestLowBufferIndex 5 +#define marketLowestOpenBufferIndex 6 +#define marketLowestCloseBufferIndex 7 + +// +double marketHighestHighBuffer[]; +double marketHighestLowBuffer[]; +double marketHighestOpenBuffer[]; +double marketHighestCloseBuffer[]; +double marketLowestHighBuffer[]; +double marketLowestLowBuffer[]; +double marketLowestOpenBuffer[]; +double marketLowestCloseBuffer[]; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (marketLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST_XMKT"; + + // + // Highest High ... + string highestHighLbl = StringConcatenate("HH(", marketLength,")"); + SetIndexLabel(marketHighestHighBufferIndex, highestHighLbl); + SetIndexBuffer(marketHighestHighBufferIndex, marketHighestHighBuffer); + SetIndexStyle( + marketHighestHighBufferIndex, + showHighestHigh ? + DRAW_LINE : + DRAW_NONE, + highestHighStyle, + 1, + showHighestHigh ? + highestHighColor : + clrNONE + ); + + // + // Highest Low ... + string highestLowLbl = StringConcatenate("HL(", marketLength,")"); + SetIndexLabel(marketHighestLowBufferIndex, highestLowLbl); + SetIndexBuffer(marketHighestLowBufferIndex, marketHighestLowBuffer); + SetIndexStyle( + marketHighestLowBufferIndex, + showHighestLow ? + DRAW_LINE : + DRAW_NONE, + highestLowStyle, + 1, + showHighestLow ? + highestLowColor : + clrNONE + ); + + // + // Highest Open ... + string highestOpenLbl = StringConcatenate("HO(", marketLength,")"); + SetIndexLabel(marketHighestOpenBufferIndex, highestOpenLbl); + SetIndexBuffer(marketHighestOpenBufferIndex, marketHighestOpenBuffer); + SetIndexStyle( + marketHighestOpenBufferIndex, + showHighestOpen ? + DRAW_LINE : + DRAW_NONE, + highestOpenStyle, + 1, + showHighestOpen ? + highestOpenColor : + clrNONE + ); + + // + // Highest Close ... + string highestCloseLbl = StringConcatenate("HC(", marketLength,")"); + SetIndexLabel(marketHighestCloseBufferIndex, highestCloseLbl); + SetIndexBuffer(marketHighestCloseBufferIndex, marketHighestCloseBuffer); + SetIndexStyle( + marketHighestCloseBufferIndex, + showHighestClose ? + DRAW_LINE : + DRAW_NONE, + highestCloseStyle, + 1, + showHighestClose ? + highestCloseColor : + clrNONE + ); + + // + // Lowest High ... + string lowestHighLbl = StringConcatenate("LH(", marketLength,")"); + SetIndexLabel(marketLowestHighBufferIndex, lowestHighLbl); + SetIndexBuffer(marketLowestHighBufferIndex, marketLowestHighBuffer); + SetIndexStyle( + marketLowestHighBufferIndex, + showLowestHigh ? + DRAW_LINE : + DRAW_NONE, + lowestHighStyle, + 1, + showLowestHigh ? + lowestHighColor : + clrNONE + ); + + // + // Lowest Low ... + string lowestLowLbl = StringConcatenate("LL(", marketLength,")"); + SetIndexLabel(marketLowestLowBufferIndex, lowestLowLbl); + SetIndexBuffer(marketLowestLowBufferIndex, marketLowestLowBuffer); + SetIndexStyle( + marketLowestLowBufferIndex, + showLowestLow ? + DRAW_LINE : + DRAW_NONE, + lowestLowStyle, + 1, + showLowestLow ? + lowestLowColor : + clrNONE + ); + + // + // Lowest Open ... + string lowestOpenLbl = StringConcatenate("LO(", marketLength,")"); + SetIndexLabel(marketLowestOpenBufferIndex, lowestOpenLbl); + SetIndexBuffer(marketLowestOpenBufferIndex, marketLowestOpenBuffer); + SetIndexStyle( + marketLowestOpenBufferIndex, + showLowestOpen ? + DRAW_LINE : + DRAW_NONE, + lowestOpenStyle, + 1, + showLowestOpen ? + lowestOpenColor : + clrNONE + ); + + // + // Lowest Close ... + string lowestCloseLbl = StringConcatenate("LC(", marketLength,")"); + SetIndexLabel(marketLowestCloseBufferIndex, lowestCloseLbl); + SetIndexBuffer(marketLowestCloseBufferIndex, marketLowestCloseBuffer); + SetIndexStyle( + marketLowestCloseBufferIndex, + showLowestClose ? + DRAW_LINE : + DRAW_NONE, + lowestCloseStyle, + 1, + showLowestClose ? + lowestCloseColor : + clrNONE + ); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + RemoveDraws(logTag); +} + +// +// Do Calculation ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(marketLength, 3); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Short Cycle ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculate Short Cycle ... +void CalculateBuffers( + const int bar_index +) { + // + // Highest High ... + double highestHighValue = GetMarketHighestHigh( + bar_index, + marketLength + ); + marketHighestHighBuffer[bar_index] = highestHighValue; + + // + // Highest Low ... + double highestLowValue = GetMarketHighestLow( + bar_index, + marketLength + ); + marketHighestLowBuffer[bar_index] = highestLowValue; + + // + // Highest Open ... + double highestOpenValue = GetMarketHighestOpen( + bar_index, + marketLength + ); + marketHighestOpenBuffer[bar_index] = highestOpenValue; + + // + // Highest Close ... + double highestCloseValue = GetMarketHighestClose( + bar_index, + marketLength + ); + marketHighestCloseBuffer[bar_index] = highestCloseValue; + + // + // Lowest High ... + double lowestHighValue = GetMarketLowestHigh( + bar_index, + marketLength + ); + marketLowestHighBuffer[bar_index] = lowestHighValue; + + // + // Lowest Low ... + double lowestLowValue = GetMarketLowestLow( + bar_index, + marketLength + ); + marketLowestLowBuffer[bar_index] = lowestLowValue; + + // + // Lowest Open ... + double lowestOpenValue = GetMarketLowestOpen( + bar_index, + marketLength + ); + marketLowestOpenBuffer[bar_index] = lowestOpenValue; + + // + // Lowest Close ... + double lowestCloseValue = GetMarketLowestClose( + bar_index, + marketLength + ); + marketLowestCloseBuffer[bar_index] = lowestCloseValue; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.xmma.mq4 b/xIndicators/x-saherelm.xmma.mq4 new file mode 100644 index 0000000..835aae4 --- /dev/null +++ b/xIndicators/x-saherelm.xmma.mq4 @@ -0,0 +1,408 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XMMA Indicator +// --------------------------------------------- +// this is an indicator which going to analyse +// Market based on Price Movements and provide +// some informations to act based on current market +// state ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm Market Analyser (XMMA) Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 7; // Market Length +input int fastShift = 1; // Fast Shift +input int slowShift = 3; // Slow Shift +input int longMarketFastMultiplier = 100; // Long Market Fast Multiplier +input int longMarketSlowMultiplier = 200; // Long Market Slow Multiplier +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// define indicator buffers ... +#property indicator_buffers 7 +#property indicator_plots 7 + +// +// Fast ... +#property indicator_label1 "Fast" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +// Slow ... +#property indicator_label2 "SLow" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +// Mid ... +#property indicator_label3 "Mid" +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrBisque +#property indicator_style3 STYLE_DASH +#property indicator_width3 1 + +// +// Long SL ... +#property indicator_label4 "Long SL" +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrAqua +#property indicator_style4 STYLE_DASH +#property indicator_width4 1 + +// +// Short SL ... +#property indicator_label5 "Short SL" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrFuchsia +#property indicator_style5 STYLE_DASH +#property indicator_width5 1 + +// +// Long Market Fast ... +#property indicator_label6 "Long Fast" +#property indicator_type6 DRAW_LINE +#property indicator_color6 clrAqua +#property indicator_style6 STYLE_DOT +#property indicator_width6 1 +// +// Long Market Slow ... +#property indicator_label7 "Long Market Slow" +#property indicator_type7 DRAW_LINE +#property indicator_color7 clrFuchsia +#property indicator_style7 STYLE_DOT +#property indicator_width7 1 + +// +// Declare Buffers ... +#define fastBufferIndex 0 +#define slowBufferIndex 1 +#define midBufferIndex 2 +#define longSLBufferIndex 3 +#define shortSLBufferIndex 4 +#define longMarketFastBufferIndex 5 +#define longMarketSlowBufferIndex 6 + +// +double fastBuffer[]; +double slowBuffer[]; +double midBuffer[]; +double longSLBuffer[]; +double shortSLBuffer[]; +double longMarketFastBuffer[]; +double longMarketSlowBuffer[]; + +// +int lastCrossOverIndex = 0; +double lastCrossOver = 0.0; + +// +int lastCrossUnderIndex = 0; +double lastCrossUnder = 0.0; + +// +double lastLongSL = 0.0; +int lastLongSLIndex = 0; + +// +double lastShortSL = 0.0; +int lastShortSLIndex = 0; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + fastShift < 0 || + slowShift < 0 || + marketLength <= 0 || + slowShift < fastShift + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Fast ... + SetIndexBuffer(fastBufferIndex, fastBuffer); + + // + // Slow ... + SetIndexBuffer(slowBufferIndex, slowBuffer); + + // + // Mid ... + SetIndexBuffer(midBufferIndex, midBuffer); + + // + // Long SL ... + SetIndexBuffer(longSLBufferIndex, longSLBuffer); + + // + // Short SL ... + SetIndexBuffer(shortSLBufferIndex, shortSLBuffer); + + // + // Long Market Fast ... + SetIndexBuffer(longMarketFastBufferIndex, longMarketFastBuffer); + + // + // Long Market Slow ... + SetIndexBuffer(longMarketSlowBufferIndex, longMarketSlowBuffer); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Flow ... + CalculateFlow(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculate Flow ... +void CalculateFlow( + const int &bar_index +) { + // + int fastLength = marketLength + fastShift; + int slowLength = marketLength + fastShift + slowShift; + + // + // Calculating Fast ... + double fast = iMA( + _Symbol, + _Period, + fastLength, + 0, + MODE_EMA, + PRICE_WEIGHTED, + bar_index + ); + fastBuffer[bar_index] = fast; + + // + // Calculating Slow ... + double slow = iMA( + _Symbol, + _Period, + slowLength, + 0, + MODE_EMA, + PRICE_WEIGHTED, + bar_index + ); + slowBuffer[bar_index] = slow; + + // + // Calculating XMa Mid ... + double xmaMid = iMA( + _Symbol, + _Period, + marketLength, + 0, + MODE_EMA, + PRICE_HIGH, + bar_index + ); + midBuffer[bar_index] = xmaMid; + + // + // Calculating XMa Long Market Fast ... + double xmaLongMarketFast = iMA( + _Symbol, + _Period, + marketLength * longMarketFastMultiplier, + 0, + MODE_SMA, + PRICE_CLOSE, + bar_index + ); + longMarketFastBuffer[bar_index] = xmaLongMarketFast; + + // + // Calculating XMa Long Market Slow ... + double xmaLongMarketSlow = iMA( + _Symbol, + _Period, + marketLength * longMarketSlowMultiplier, + 0, + MODE_SMA, + PRICE_CLOSE, + bar_index + ); + longMarketSlowBuffer[bar_index] = xmaLongMarketSlow; + + // + // Find Cross Points ... + // + bool isCrossOver = fastBuffer[bar_index] > slowBuffer[bar_index] + && !( + fastBuffer[bar_index + 1] > slowBuffer[bar_index + 1] + ); + + // + bool isCrossUnder = fastBuffer[bar_index] < slowBuffer[bar_index] + && !( + fastBuffer[bar_index + 1] < slowBuffer[bar_index + 1] + ); + + // + // Find Trending ... + // + bool isTrendUp = fastBuffer[bar_index] > slowBuffer[bar_index] + && fastBuffer[bar_index] > fastBuffer[bar_index + 1] + && slowBuffer[bar_index] > slowBuffer[bar_index + 1]; + + // + bool isTrendDown = fastBuffer[bar_index] < slowBuffer[bar_index] + && fastBuffer[bar_index] < fastBuffer[bar_index + 1] + && slowBuffer[bar_index] < slowBuffer[bar_index + 1]; + + // + // Do Some Calculations ... + if (isCrossOver) { + // + lastCrossOverIndex = bar_index; + lastCrossOver = fastBuffer[bar_index]; + } else if (isCrossUnder) { + // + lastCrossUnderIndex = bar_index; + lastCrossUnder = fastBuffer[bar_index]; + } + + // + // Calculate SLs ... + // + // Long SL ... + if (lastCrossOver > 0) { + // + lastLongSLIndex = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLength, + lastCrossOverIndex + ); + + // + lastLongSL = iLow( + _Symbol, + _Period, + lastLongSLIndex + ); + } + + // + // Short SL ... + if (lastCrossUnder > 0) { + // + lastShortSLIndex = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLength, + lastCrossUnderIndex + ); + + // + lastShortSL = iHigh( + _Symbol, + _Period, + lastShortSLIndex + ); + } + + // + longSLBuffer[bar_index] = lastLongSL; + shortSLBuffer[bar_index] = lastShortSL; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.xmma.signalling.mq4 b/xIndicators/x-saherelm.xmma.signalling.mq4 new file mode 100644 index 0000000..2d4a0d8 --- /dev/null +++ b/xIndicators/x-saherelm.xmma.signalling.mq4 @@ -0,0 +1,249 @@ +///////////////////////////////////////////////////////////////// +// +// SaherElm IT Center XMMA Signalling Indicator +// ------------------------------------------------------------- +// this indicator provides signals for XMMA Based Strategy ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +//////////////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XMMA Signalling Indicator" +#property strict + +// +// START Inputs ... +// +// +// Signal Show/Hide ... +input bool showSignals = true; // Show Signals +input bool showLongSignals = true; // Show Long Signals +input bool showShortSignals = true; // Show Short Signals + +// +// Signal Prefixe ... +input string signalPrefix = "XS_SG_OSC"; // Signal Prefix +input double signalArrowPositionThresholdFactor = 100; // Signal Arrow Dist of Price + +// +// Signal Colors ... +input string bullishSignalLabel = "X_BUY"; // Bullish Signal Label +input color bullishSignalColor = clrAqua; // Bullish Signal Color + +// +input string bearishSignalLabel = "X_SELL"; // Bearish Signal Label +input color bearishSignalColor = clrFuchsia; // Bearish Signal Color + +// +// here we specify alerting signals ... +input bool alertSignals = false; // Alert Signals +input bool pushNotificationSignals = false; // Push Notification Alert Signals + +// +// Indicator Inputs ... +input int marketLength = 7; // Market Length +input int fastShift = 1; // Fast Shift +input int slowShift = 3; // Slow Shift +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_chart_window + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.xmma.signal.lib.mq4" + +// +// Last Signalled Bar ... +int lastSignalledBar = 0; + +// +// here we specify logging enabled or not ... +bool enableLogging = true; + +// +// this is a Tag which attached to our Logger ... +string logTag = "XS_SG_OSC"; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + fastShift < 0 || + slowShift < 0 || + marketLength <= 0 || + slowShift < fastShift + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + CalculateSignals(i); + } + + // + return rates_total; +} + +// +// De Initialization ... +void OnDeinit(const int reason) { + // + RemoveDraws(signalPrefix); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Here we are Calculate Signals based on Oscillators and fill up +// related buffers ... +void CalculateSignals(const int &bar_index) { + // + // Retrieve Signal Exists ... + XSignalRequest request = CalculateSignal( + bar_index, + marketLength, + fastShift, + slowShift + ); + + // + if (!request.hasSignal) { + return; + } + + // + // Prevent Multiple Alerting at same Candle ... + if (lastSignalledBar == bar_index) { + return; + } + + // + lastSignalledBar = bar_index; + + // + bool hasLongSignal = request.type == X_LONG; + bool hasShortSignal = request.type == X_SHORT; + + // + // Signal Tag ... + string signalTAG = GenerateSignalTAG( + request.signal, + signalPrefix, + bullishSignalLabel, + bearishSignalLabel + ); + + // + // Handle Alerts ... + if (alertSignals && bar_index == 0) { + // + // General Alert ... + Alert(signalTAG); + + // + // Push Notifications ... + if (pushNotificationSignals) { + SendNotification(signalTAG); + } + } + + // + // Handle Can Show Signals ... + bool canShowSignals = showSignals && + (hasLongSignal ? showLongSignals : hasShortSignal ? showShortSignals : false); + if (canShowSignals) { + // + // Here i must to Draw Signal Shapes ... + DrawSignal( + request.signal, + 0, + 0, + signalArrowPositionThresholdFactor, + signalPrefix, // Signal Tag ... + bullishSignalLabel, // Long Signal Label ... + bullishSignalColor, + bearishSignalLabel, // Short Signal Label ... + bearishSignalColor + ); + } +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.xmtrend.mq4 b/xIndicators/x-saherelm.xmtrend.mq4 new file mode 100644 index 0000000..aa89e7b --- /dev/null +++ b/xIndicators/x-saherelm.xmtrend.mq4 @@ -0,0 +1,221 @@ + /////////////////////////////////////////////////////// +// +// SaherElm IT Center XMTR Indicator +// --------------------------------------------- +// retrieve market base info ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XMKT Indicator" +#property strict + +// +// START Inputs ... +// +// +// Market Specifications ... +input int marketLength = 20; // Market Length +input int atrMultiplier = 1; // ATR Multiplier +input int atrLength = 5; // ATR Period +input ENUM_APPLIED_PRICE source = PRICE_CLOSE; // Source +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// define indicator buffers ... +#property indicator_buffers 3 +#property indicator_plots 3 + +// +// Declare Buffers ... +#define trendBufferIndex 0 +#define upTrendBufferIndex 1 +#define downTrendBufferIndex 2 + +// +double trendBuffer[]; +double upTrendBuffer[]; +double downTrendBuffer[]; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (marketLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XMTR"; + + // + // TREND ... + SetIndexLabel(trendBufferIndex, "Trend"); + SetIndexBuffer(trendBufferIndex, trendBuffer); + SetIndexStyle( + trendBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + clrNONE + ); + + // + // UP Trend ... + SetIndexLabel(upTrendBufferIndex, "Up Trend"); + SetIndexBuffer(upTrendBufferIndex, upTrendBuffer); + SetIndexStyle( + upTrendBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + clrNONE + ); + + // + // DOWN Trend ... + SetIndexLabel(downTrendBufferIndex, "Down Trend"); + SetIndexBuffer(downTrendBufferIndex, downTrendBuffer); + SetIndexStyle( + downTrendBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + clrNONE + ); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + RemoveDraws(logTag); +} + +// +// Do Calculation ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(marketLength, 3); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Short Cycle ... + CalculateBuffers( + i, + low + ); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculate Short Cycle ... +void CalculateBuffers( + const int bar_index, + const double &low[] +) { + // + double atr = GetMarketTRSMA( + bar_index, + atrLength + ); + + // + double smoothedAtr = (atr * atrMultiplier); + double upTrend = low[bar_index] - smoothedAtr; + double downTrend = low[bar_index] + smoothedAtr; + + // + double cciValue = GetMarketCCI( + bar_index, + marketLength, + source + ); + + // + // TODO: Complete this ... +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.xrange.mq4 b/xIndicators/x-saherelm.xrange.mq4 new file mode 100644 index 0000000..1359f57 --- /dev/null +++ b/xIndicators/x-saherelm.xrange.mq4 @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XRange Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XRange Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 14; +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 3 + +// +#property indicator_plots 3 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Highest High Buffer ... +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +// Lowest Low Buffer ... +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +// Middle Buffer ... +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_DASH +#property indicator_width3 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +// +#define highestHighBufferIndex 0 +#define lowestLowBufferIndex 1 +#define middleBufferIndex 2 + +// +double highestHighBuffer[]; +double lowestLowBuffer[]; +double middleBuffer[]; + +// +datetime startTime; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if ( + marketLength <= 0 + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + string hhLbl = StringConcatenate( + "XR HH(", marketLength, ")" + ); + SetIndexBuffer(highestHighBufferIndex, highestHighBuffer); + SetIndexLabel(highestHighBufferIndex, hhLbl); + + // + string llLbl = StringConcatenate( + "XR LL(", marketLength, ")" + ); + SetIndexBuffer(lowestLowBufferIndex, lowestLowBuffer); + SetIndexLabel(lowestLowBufferIndex, llLbl); + + // + string midLbl = StringConcatenate( + "XR Mid(", marketLength, ")" + ); + SetIndexBuffer(middleBufferIndex, middleBuffer); + SetIndexLabel(middleBufferIndex, midLbl); + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculations ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculations ... +void CalculateBuffers( + const int &bar_index +) { + // + // Retrieve Bar Time ... + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + if (startTime == 0) { + // + startTime = barTime; + SetIndicatorBuffersNone(bar_index); + return; + } + + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + startTime + ); + + // + int startDistance = startBarIndex - bar_index; + if (startDistance < marketLength) { + // + SetIndicatorBuffersNone(bar_index); + return; + } + + // + // Highest High ... + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLength, + bar_index + ); + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + highestHighBuffer[bar_index] = hh; + + // + // Lowest Low ... + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLength, + bar_index + ); + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + lowestLowBuffer[bar_index] = ll; + + // + // Middle Buffer ... + double mid = (hh + ll) / 2; + middleBuffer[bar_index] = mid; + + // + // Reset Start Time ... + startTime = 0; +} + +// +void SetIndicatorBuffersNone( + const int bar_index +) { + // + int lastBarIndex = bar_index + 1; + + // + double lastHighestHigh; + double lastLowestLow; + + // + // Highest High ... + if (ArraySize(highestHighBuffer) > lastBarIndex) { + lastHighestHigh = highestHighBuffer[lastBarIndex]; + } else { + lastHighestHigh = 0; + } + + // + // Lowest Low ... + if (ArraySize(lowestLowBuffer) > lastBarIndex) { + lastLowestLow = lowestLowBuffer[lastBarIndex]; + } else { + lastLowestLow = 0; + } + + // + highestHighBuffer[bar_index] = lastHighestHigh; + lowestLowBuffer[bar_index] = lastLowestLow; + + // + double mid = (lastHighestHigh + lastLowestLow) / 2; + middleBuffer[bar_index] = mid; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.xtpow.mq4 b/xIndicators/x-saherelm.xtpow.mq4 new file mode 100644 index 0000000..46ff59e --- /dev/null +++ b/xIndicators/x-saherelm.xtpow.mq4 @@ -0,0 +1,275 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center Trend Power Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm MA Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 7; // Market Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_separate_window + +// +#property indicator_plots 3 +#property indicator_buffers 3 +#property indicator_minimum 0 +#property indicator_maximum 100 + +// +#property indicator_levelcolor clrGray +#property indicator_levelstyle STYLE_DOT + +// +// Start Define Indicator Buffer Styles ... +// +#property indicator_type1 DRAW_HISTOGRAM +#property indicator_color1 clrLime +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +#property indicator_type2 DRAW_HISTOGRAM +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define powerUpBufferIndex 0 +#define powerDownBufferIndex 1 +#define signalBufferIndex 2 + +double powerUpBuffer[]; +double powerDownBuffer[]; +double signalBuffer[]; + +// +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (marketLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + SetLevelValue(0, 0.0); + IndicatorSetString(INDICATOR_LEVELTEXT,0,""); + + // + SetLevelValue(1, 20.0); + IndicatorSetString(INDICATOR_LEVELTEXT,1,""); + + // + SetLevelValue(2, 50); + IndicatorSetString(INDICATOR_LEVELTEXT,2,""); + + // + SetLevelValue(3, 100); + IndicatorSetString(INDICATOR_LEVELTEXT,3,""); + + // + string pUpLbl = StringConcatenate( + "P Up (", marketLength, ")" + ); + SetIndexLabel(powerUpBufferIndex, pUpLbl); + SetIndexBuffer(powerUpBufferIndex, powerUpBuffer); + SetIndexDrawBegin(powerUpBufferIndex, marketLength + 1); + + // + string pDownLbl = StringConcatenate( + "P Down (", marketLength, ")" + ); + SetIndexLabel(powerDownBufferIndex, pDownLbl); + SetIndexBuffer(powerDownBufferIndex, powerDownBuffer); + SetIndexDrawBegin(powerDownBufferIndex, marketLength + 1); + + // + string pSignalLbl = StringConcatenate( + "P Signal (", marketLength, ")" + ); + SetIndexLabel(signalBufferIndex, pSignalLbl); + SetIndexBuffer(signalBufferIndex, signalBuffer); + SetIndexDrawBegin(signalBufferIndex, marketLength + 1); + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "X_TPW_OSC"; + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Buffers ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateBuffers( + const int &bar_index +) { + // + double powerUp = 0; + double powerDown = 0; + + // + int dailyCount = GetDailyCandleCount(); + double dailyHH = GetMarketHighestHigh( + bar_index, + dailyCount + ); + double dailyLL = GetMarketLowestLow( + bar_index, + dailyCount + ); + double dailyDiff = dailyHH - dailyLL; + double rate = dailyDiff / 100; + + // + for (int i = bar_index; i < bar_index + marketLength; i++) { + // + XOHCL c = GetCandleModel(i); + + // + double cRange = + MathAbs(c.open - c.close) + // MathAbs(c.high - c.low) + ; + bool isBullish = c.open < c.close; + + // + if (isBullish) { + powerUp += cRange; + } else { + powerDown += cRange; + } + } + + // + powerUp = powerUp / rate; + powerDown = powerDown / rate; + + // + int doubleMarketLength = (marketLength * 2); + double ema = GetMA( + bar_index, + doubleMarketLength, + 0, + MODE_EMA, + PRICE_WEIGHTED + ); + + // + double emaRate = GetMarketHighestHigh(bar_index, doubleMarketLength) - GetMarketLowestLow(bar_index, doubleMarketLength) / 100; + + // + double signal = (ema / 100) * rate; + double signalAddition = MathMin(powerUp, powerDown); + + // + powerUpBuffer[bar_index] = powerUp; + powerDownBuffer[bar_index] = powerDown; + signalBuffer[bar_index] = signal + signalAddition; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xIndicators/x-saherelm.zigzag.mq4 b/xIndicators/x-saherelm.zigzag.mq4 new file mode 100644 index 0000000..fbb073c --- /dev/null +++ b/xIndicators/x-saherelm.zigzag.mq4 @@ -0,0 +1,476 @@ +///////////////////////////////////////////////////////////////// +// +// SaherElm IT Center ZigZag Indicator +// ------------------------------------------------------------- +// this indicator provides signals for Main strategy ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +//////////////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm ZigZag Indicator" +#property strict + +// +// START Inputs ... +// +input int depth = 12; // Depth +input int deviation = 5; // Deviation +input int backStep = 3; // BackStep +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// here we specify logging enabled or not ... +bool enableLogging = true; + +// +// this is a Tag which attached to our Logger ... +string logTag = "XS_ZG"; + +// +#property indicator_chart_window + +// +#property indicator_buffers 1 + +// +#property indicator_width1 1 +#property indicator_color1 clrAqua +// #property indicator_type1 DRAW_SECTION +// #property indicator_style1 STYLE_SOLID + +// // +// #property indicator_width2 1 +// #property indicator_color2 clrNONE +// #property indicator_type2 DRAW_NONE +// #property indicator_style2 STYLE_SOLID + +// // +// #property indicator_width3 1 +// #property indicator_color3 clrNONE +// #property indicator_type3 DRAW_NONE +// #property indicator_style3 STYLE_SOLID + +// +// Buffers ... +// +#define zigzagBufferIndex 0 +#define highBufferIndex 1 +#define lowBufferIndex 2 +// #define ziggyBufferIndex 3 + +// +double zigzagBuffer[]; +double highBuffer[]; +double lowBuffer[]; +// double ziggyBuffer[]; + +// +// recounting's depth of extremums ... +int level=3; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + depth <= 0 || + backStep < 0 || + deviation < 0 || + backStep >= depth + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Set Index Buffers of ZigZag ... + IndicatorBuffers(3); + + // + // ZigZag Buffer ... + SetIndexBuffer(zigzagBufferIndex, zigzagBuffer); + SetIndexStyle(zigzagBufferIndex, DRAW_SECTION); + SetIndexLabel(zigzagBufferIndex, "ZigZag"); + + // + // High Buffer ... + SetIndexBuffer(highBufferIndex, highBuffer); + SetIndexLabel(highBufferIndex, ""); + + // + // Low Buffer ... + SetIndexBuffer(lowBufferIndex, lowBuffer); + SetIndexLabel(lowBufferIndex, ""); + + // + // Ziggy Buffer ... + // SetIndexBuffer(ziggyBufferIndex, ziggyBuffer); + // SetIndexLabel(ziggyBufferIndex, ""); + + // + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +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[] +) { + // + // this counts Available Bars ... + int limit; + + // + int maxLength = MathMax(depth, backStep); + + int i; + int counterZ; + int back; + int pos; + + // + int lastlowpos = 0; + int lasthighpos = 0; + int whatlookfor = 0; + + // + double extremum; + + // + double curlow = 0.0; + double curhigh = 0.0; + double lasthigh = 0.0; + double lastlow = 0.0; + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // first calculations ... + if (prev_calculated == 0) { + limit = InitializeBuffers(); + } else { + // + // find first extremum in the depth ExtLevel or 100 last bars ... + i = counterZ = 0; + while(counterZ < level && i < 100) { + // + if(zigzagBuffer[i] != 0.0) { + counterZ++; + } + + // + i++; + } + + // + // no extremum found - recounting all from begin ... + if(counterZ == 0) { + limit = InitializeBuffers(); + } else { + // + // set start position to found extremum position ... + limit = i-1; + + // + //--- what kind of extremum? + if(lowBuffer[i] != 0.0) { + // + // low extremum ... + curlow = lowBuffer[i]; + + // + // will look for the next high extremum ... + whatlookfor=1; + } else { + // + // high extremum ... + curhigh = highBuffer[i]; + + // + // will look for the next low extremum ... + whatlookfor=-1; + } + + // + // clear the rest data ... + for(i = limit - 1; i >= 0; i--) { + // + lowBuffer[i]=0.0; + highBuffer[i]=0.0; + zigzagBuffer[i]=0.0; + } + } + } + + // + // Main Calculation Loop ... + for (i = limit; i >= 0; i--) { + // + // find lowest low in depth of bars ... + extremum = low[ + iLowest( + _Symbol, + _Period, + MODE_LOW, + depth, + i + ) + ]; + + // + // this lowest has been found previously ... + if (extremum == lastlow) { + extremum = 0.0; + } else { + // + // new last low ... + lastlow=extremum; + + // + // discard extremum if current low is too high ... + if(low[i] - extremum > deviation * _Point) { + extremum=0.0; + } else { + // + // clear previous extremums in backstep bars ... + for(back = 1; back <= backStep; back++) { + // + pos = i + back; + + // + if(lowBuffer[pos] != 0 && lowBuffer[pos] > extremum) { + lowBuffer[pos] = 0.0; + } + } + } + } + + // + // found extremum is current low ... + if (low[i] == extremum) { + lowBuffer[i] = extremum; + } else { + lowBuffer[i] = 0.0; + } + + // + // find highest high in depth of bars ... + extremum = high[ + iHighest( + _Symbol, + _Period, + MODE_HIGH, + depth, + i + ) + ]; + + // + // this highest has been found previously ... + if (extremum == lasthigh) { + extremum = 0.0; + } else { + // + // new last high ... + lasthigh=extremum; + + // + // discard extremum if current high is too low ... + if (extremum - high[i] > deviation * Point) { + extremum = 0.0; + } else { + // + // clear previous extremums in backstep bars ... + for(back = 1; back <= backStep; back++) { + // + pos = i + back; + + // + if (highBuffer[pos] != 0 && highBuffer[pos] < extremum) { + highBuffer[pos] = 0.0; + } + } + } + } + + // + // found extremum is current high ... + if (high[i] == extremum) { + highBuffer[i] = extremum; + } else { + highBuffer[i] = 0.0; + } + } + + // + // final cutting ... + if( whatlookfor == 0) { + // + lastlow = 0.0; + lasthigh = 0.0; + } else { + // + lastlow = curlow; + lasthigh = curhigh; + } + + // + for(i = limit; i >= 0; i--) { + switch(whatlookfor) { + // + // look for peak or lawn ... + case 0: + // + if (lastlow == 0.0 && lasthigh == 0.0) { + if(highBuffer[i]!=0.0) { + // + lasthigh = High[i]; + lasthighpos = i; + whatlookfor = -1; + + // + zigzagBuffer[i] = lasthigh; + } + + // + if(lowBuffer[i] != 0.0) { + // + lastlow = Low[i]; + lastlowpos = i; + whatlookfor = 1; + + // + zigzagBuffer[i] = lastlow; + } + } + break; + + // + // look for peak ... + case 1: + // + if ( + lowBuffer[i] != 0.0 && + lowBuffer[i] < lastlow && + highBuffer[i] == 0.0 + ) { + // + zigzagBuffer[lastlowpos] = 0.0; + lastlowpos = i; + lastlow = lowBuffer[i]; + zigzagBuffer[i] = lastlow; + } + + // + if(highBuffer[i] != 0.0 && lowBuffer[i] == 0.0) { + // + lasthigh = highBuffer[i]; + lasthighpos = i; + zigzagBuffer[i] = lasthigh; + + // + whatlookfor=-1; + } + break; + + // + // look for lawn ... + case -1: + // + if( + highBuffer[i] != 0.0 && + highBuffer[i] > lasthigh && + lowBuffer[i] == 0.0 + ) { + // + zigzagBuffer[lasthighpos] = 0.0; + lasthighpos = i; + lasthigh = highBuffer[i]; + zigzagBuffer[i] = lasthigh; + } + + // + if( + lowBuffer[i] !=0.0 && + highBuffer[i] == 0.0 + ) { + // + lastlow = lowBuffer[i]; + lastlowpos = i; + zigzagBuffer[i] = lastlow; + whatlookfor=1; + } + break; + } + } + + // + // Done ... + return rates_total; +} + +// +// De Initialization ... +void OnDeinit(const int reason) { + // + // RemoveDraws(signalPrefix); + ChartRedraw(0); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +int InitializeBuffers() { + // + ArrayInitialize(lowBuffer,0.0); + ArrayInitialize(highBuffer, 0.0); + ArrayInitialize(zigzagBuffer, 0.0); + + // + //--- first counting position + return(Bars - depth); +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xLibraries/x-saherelm.draw.lib.mq4 b/xLibraries/x-saherelm.draw.lib.mq4 new file mode 100644 index 0000000..776cde4 --- /dev/null +++ b/xLibraries/x-saherelm.draw.lib.mq4 @@ -0,0 +1,2010 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Draw Highest High ... +bool DrawHighestHigh( + const int bar_index, + const int marketLen, + const string tag, + const int drawUntilBarIndex = 0, + const long chartID = 0, + const int subWindow = 0, + const color clr = clrAqua, + const ENUM_LINE_STYLE style = STYLE_DOT, + const int width = 1, + const bool back = false, + const bool selection = false, + const bool hidden = false, + const long zOrder = 0 +) { + // + bool result = false; + + // + // Calculate Highest High ... + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + datetime hhTime = iTime( + _Symbol, + _Period, + hhIdx + ); + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + datetime drawUntilTime = + drawUntilBarIndex != bar_index ? + iTime( + _Symbol, + _Period, + drawUntilBarIndex + ) : + barTime + ; + + // + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + int rnd = rand(); + + // + // Define Label ... + string lbl = StringConcatenate( + tag, + "_HH(", marketLen ,")_", + hh, + "_", rnd + ); + + // + result = ObjectDelete( + chartID, + lbl + ); + + // + // Draw a Trend Line ... + result = DrawTrendLine( + chartID, + lbl, + subWindow, + hhTime, + hh, + drawUntilTime, + hh, + clr, + style, + width, + back, + selection, + hidden, + zOrder + ); + + // + return result; +} + +// +// Draw Lowest Low ... +bool DrawLowestLow( + const int bar_index, + const int marketLen, + const string tag, + const int drawUntilBarIndex = 0, + const long chartID = 0, + const int subWindow = 0, + const color clr = clrFuchsia, + const ENUM_LINE_STYLE style = STYLE_DOT, + const int width = 1, + const bool back = false, + const bool selection = false, + const bool hidden = false, + const long zOrder = 0 +) { + // + bool result = false; + + // + // Calculate Highest High ... + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + datetime llTime = iTime( + _Symbol, + _Period, + llIdx + ); + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + datetime drawUntilTime = + drawUntilBarIndex != bar_index ? + iTime( + _Symbol, + _Period, + drawUntilBarIndex + ) : + barTime + ; + + // + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + int rnd = rand(); + + // + // Define Label ... + string lbl = StringConcatenate( + tag, + "_LL(", marketLen ,")_", + ll, + "_", rnd + ); + + // + result = ObjectDelete( + chartID, + lbl + ); + + // + // Draw a Trend Line ... + result = DrawTrendLine( + chartID, + lbl, + subWindow, + llTime, + ll, + drawUntilTime, + ll, + clr, + style, + width, + back, + selection, + hidden, + zOrder + ); + + // + return result; +} + +// +// Draw Market Middle ... +bool DrawMarketMiddle( + const int bar_index, + const int marketLen, + const string tag, + const int drawUntilBarIndex = 0, + const long chartID = 0, + const int subWindow = 0, + const color clr = clrYellow, + const ENUM_LINE_STYLE style = STYLE_DOT, + const int width = 1, + const bool back = false, + const bool selection = false, + const bool hidden = false, + const long zOrder = 0 +) { + // + bool result = false; + + // + // Calculate Highest High ... + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + datetime llTime = iTime( + _Symbol, + _Period, + llIdx + ); + + // + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + // Calculate Highest High ... + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + datetime hhTime = iTime( + _Symbol, + _Period, + hhIdx + ); + + // + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + double middle = ll + ((hh - ll) / 2); + datetime middleTime = hhIdx < llIdx + ? hhTime + : llTime + ; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + datetime drawUntilTime = + drawUntilBarIndex != bar_index ? + iTime( + _Symbol, + _Period, + drawUntilBarIndex + ) : + barTime + ; + + // + int rnd = rand(); + + // + // Define Label ... + string lbl = StringConcatenate( + tag, + "_MID(", marketLen ,")_", + middle, + "_", rnd + ); + + // + result = ObjectDelete( + chartID, + lbl + ); + + // + // Draw a Trend Line ... + result = DrawTrendLine( + chartID, + lbl, + subWindow, + middleTime, + middle, + drawUntilTime, + middle, + clr, + style, + width, + back, + selection, + hidden, + zOrder + ); + + // + return result; +} + +// +// Start Arrow Functions ... +// +// +// Draw an Arrow Object on Chart ... +bool DrawArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // arrow name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const uchar arrowCode = OBJ_ARROW_UP, // arrow code + const ENUM_ARROW_ANCHOR anchor = ANCHOR_BOTTOM, // anchor point position + const color clr = clrAqua, // arrow color + const ENUM_LINE_STYLE style = STYLE_SOLID, // border line style + const int width = 3, // arrow size + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // Order Object ... +) { + // + // set anchor point coordinates if they are not set ... + ChangeArrowEmptyPoint(time, price); + + // + // reset the error value ... + ResetLastError(); + + // + // create an arrow ... + if(!ObjectCreate(chartID, name, OBJ_ARROW, subWindow, time, price)) { + // + string message = StringConcatenate(__FUNCTION__, + ": failed to create an arrow! Error code = ", + GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the arrow code ... + ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, arrowCode); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set the arrow color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set the border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set the arrow's size ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the arrow by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is false by default, if you want making it possible to highlight and move the object + // change it to true ... + ObjectSetInteger(chartID,name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point of Arrow ... +bool MoveArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if(!time) { + time = TimeCurrent(); + } + + // + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete an arrow ... +bool DeleteArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow" // arrow name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete an arrow ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete an arrow! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the arrow code ... +bool ArrowCodeChange( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + const uchar code = 252 // arrow code +) { + // + // reset the error value ... + ResetLastError(); + + // + // change the arrow code ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, code)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the arrow code! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change anchor type ... +bool ArrowAnchorChange( + const long chartID = 0, // chart's ID + const string name="Arrow", // object name + const ENUM_ARROW_ANCHOR anchor = ANCHOR_TOP // anchor type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change anchor type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change anchor type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeArrowEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } +} +// +// End Arrow Functions ... +// + +// +// Start Horizontal Line Functions ... +// +// +// Create, Draw the horizontal line ... +bool DrawHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + const int subWindow = 0, // subwindow index + double price = 0, // line price + const color clr = clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the price is not set, set it at the current Bid price level ... + if(!price) { + price=SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // create a horizontal line ... + if(!ObjectCreate(chartID, name, OBJ_HLINE, subWindow, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move horizontal line ... +bool MoveHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + double price = 0 // line price +) { + // + // if the line price is not set, move it to the current Bid price level ... + if(!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move a horizontal line ... + if(!ObjectMove(chartID, name, 0, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete a horizontal line ... +bool DeleteHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a horizontal line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End Horizontal Line Functions ... +// + +// +// Start Vertical Line Functions ... +// +// +// Create the vertical line ... +bool DrawVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + const int sub_window = 0, // subwindow index + datetime time = 0, // line time + const color clr=clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the line time is not set, draw it via the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value + ResetLastError(); + + // + // create a vertical line ... + if (!ObjectCreate(chartID, name, OBJ_VLINE, sub_window, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return true; +} + +// +// Move the vertical line ... +bool MoveVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + datetime time = 0 // line time +) { + // + // if line time is not set, move the line to the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the vertical line ... + if(!ObjectMove(chartID, name, 0, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the vertical line ... +bool DeleteVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the vertical line ... + if (!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // successful execution ... + return true; +} +// +// End Vertical Line Functions ... +// + +// +// Start RectangleLabel Functions ... +// +// +// Create Rectangle Label Object ... +bool DrawRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int subWindow = 0, // subwindow index + const int x = 0, // X coordinate + const int y = 0, // Y coordinate + const int width = 50, // width + const int height = 18, // height + const color back_clr = C'236,233,216', // background color + const ENUM_BORDER_TYPE border = BORDER_SUNKEN, // border type + const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring + const color clr = clrRed, // flat border color (Flat) + const ENUM_LINE_STYLE style = STYLE_SOLID, // flat border style + const int lineWidth = 1, // flat border width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // reset the error value ... + ResetLastError(); + + // + //--- create a rectangle label + if(!ObjectCreate(chartID, name, OBJ_RECTANGLE_LABEL, subWindow, 0, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set label coordinates ... + ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x); + ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y); + + // + // set label size ... + ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width); + ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height); + + // + // set background color ... + ObjectSetInteger(chartID, name, OBJPROP_BGCOLOR, back_clr); + + // + // set border type ... + ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border); + + // + // set the chart's corner, relative to which point coordinates are defined ... + ObjectSetInteger(chartID, name, OBJPROP_CORNER, corner); + + // + // set flat border color (in Flat mode) ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set flat border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set flat border width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, lineWidth); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the label by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move Rectangle Label .. +bool MoveRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int x = 0, // X coordinate + const int y=0 // Y coordinate +) { + // + // reset the error value ... + ResetLastError(); + + // + // move the rectangle label ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move X coordinate of the label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move Y coordinate of the label! Error code = ",GetLastError() + ); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the rectangle label ... +bool DeleteRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel" // label name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the label ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change Rectangle Label Size ... +bool ChangeSizeRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int width = 50, // label width + const int height = 18 // label height +) { + // + // reset the error value ... + ResetLastError(); + + // + // change label size ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's width! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's height! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change rectangle label border type ... +bool RectLabelChangeBorderType( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const ENUM_BORDER_TYPE border = BORDER_SUNKEN // border type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change border type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the border type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End RectangleLabel Functions ... +// + +// +// Start TrendLine Funcions ... +// +// Create a trend line by the given coordinates ... +bool DrawTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrYellow, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool rayRight = false, // line's continuation to the right + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeTrendLineEmptyPoints( + time1, + price1, + time2, + price2 + ); + + // + // reset the error value ... + ResetLastError(); + + // + // create a trend line by the given coordinates ... + if(!ObjectCreate(chartID, name, OBJ_TREND, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the line's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move trend line anchor point ... | +bool ChangeTrendLinePoint( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int pointindex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move trend line's anchor point ... + if(!ObjectMove(chartID, name, pointindex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// The function deletes the trend line from the chart ... +bool DeleteTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a trend line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of trend line's anchor points and set default ... +// values for empty ones ... +void ChangeTrendLineEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the first point's time is not set, it will be on the current bar ... + if (!time1) { + time1 = TimeCurrent(); + } + + // + // if the first point's price is not set, it will have Bid value ... + if (!price1) { + price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // if the second point's time is not set, it is located 9 bars left from the second one ... + if (!time2) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(), Period(), time1, 10, temp); + + // + // set the second point 9 bars left from the first one ... + time2 = temp[0]; + } + + // + // if the second point's price is not set, it is equal to the first point's one ... + if (!price2) { + price2 = price1; + } +} +// +// End TrendLine Functions ... +// + +// +// Start Text Functions ... +// +// Create and Draw a Text Object ... +bool DrawText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const string text = "Text", // the text itself + const string font = "Arial", // font + const int fontSize = 10, // font size + const color clr = clrRed, // color + const double angle = 0.0, // text slope + const ENUM_ANCHOR_POINT anchor = ANCHOR_CENTER, // anchor type + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor point coordinates if they are not set ... + ChangeTextEmptyPoint(time,price); + + // + // reset the error value ... + ResetLastError(); + + // + //--- create Text object + if(!ObjectCreate(chartID, name, OBJ_TEXT, subWindow, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the text ... + ObjectSetString(chartID, name , OBJPROP_TEXT, text); + + // + // set text font ... + ObjectSetString(chartID, name, OBJPROP_FONT, font); + + // + // set font size ... + ObjectSetInteger(chartID, name, OBJPROP_FONTSIZE, fontSize); + + // + // set the slope angle of the text ... + ObjectSetDouble(chartID, name, OBJPROP_ANGLE, angle); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the object by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID ,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point ... +bool MoveText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + //--- if point position is not set, move it to the current bar having Bid price + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point .. + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the object text ... +bool ChangeText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const string text = "Text" // text +) { + // + // reset the error value ... + ResetLastError(); + + // + // change object text ... + if(!ObjectSetString(chartID, name, OBJPROP_TEXT, text)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the text! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Text object ... +bool DeleteText( + const long chartID = 0, // chart's ID + const string name = "Text" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeTextEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + } +// +// End Text Functions ... +// + +// +// Start Fibonacchi Functions ... +// +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawFibonacci( + const long chartID = 0, // chart's ID + const string name="Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrRed, // object color + const ENUM_LINE_STYLE style = STYLE_SOLID, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawCustomFibonacci( + // + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + // + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrAqua, // object color + const ENUM_LINE_STYLE style = STYLE_DOT, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // Change Levels Of Fibonacci ... + bool result = FibonacciLevelsSet( + levels, + values, + colors, + styles, + widths, + descriptions, + chartID, + name + ); + + // + // successful execution ... + return result; +} + +// +// Set number of levels and their parameters ... +bool FibonacciLevelsSet( + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // check array sizes ... + if( + levels!=ArraySize(colors) || + levels!=ArraySize(styles) || + levels!=ArraySize(widths) || + levels!=ArraySize(widths) + ) { + // + string message = StringConcatenate( + __FUNCTION__, + ": array length does not correspond to the number of levels, error!" + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the number of levels ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELS, levels); + + // + // set the properties of levels in the loop ... + for(int i = 0; i < levels; i++) { + // + // level value ... + ObjectSetDouble(chartID, name, OBJPROP_LEVELVALUE, i, values[i]); + + // + // level color ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELCOLOR, i, colors[i]); + + // + // level style ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELSTYLE, i, styles[i]); + + // + // level width ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELWIDTH, i, widths[i]); + + // + // level description ... + // ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, DoubleToString(100 * values[i], 1)); + ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, descriptions[i]); + } + + // + // successful execution ... + return(true); +} + +// +// Move Fibonacci Retracement anchor point ... +bool FibonacciPointChange( + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int pointIndex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, pointIndex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Fibonacci Retracement ... +bool DeleteFibonachi( + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Fibonacci Retracement\"! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of Fibonacci Retracement anchor points and set +// default values for empty ones ... +void ChangeFibonacciEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the second point's time is not set, it will be on the current bar ... + if (!time2) { + time2 = TimeCurrent(); + } + + // + // if the second point's price is not set, it will have Bid value ... + if (!price2) { + price2 = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // if the first point's time is not set, it is located 9 bars left from the second one ... + if (!time1) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(),Period(),time2,10,temp); + + // + // set the first point 9 bars left from the second one ... + time1 = temp[0]; + } + + // + // if the first point's price is not set, move it 200 points below the second one ... + if (!price1) { + price1 = price2 - 200 * SymbolInfoDouble(_Symbol, SYMBOL_POINT); + } +} +// +// End Fibonacci Functions ... +// + + +// +// Start General Functions ... +// +// +// Remove all Drawn Objects ... +void RemoveDraws(const string &tag) { + // + for(int iObj=ObjectsTotal()-1; iObj >= 0; iObj--) { + // + string on = ObjectName(iObj); + if (StringFind(on, tag) == 0) { + ObjectDelete(on); + } + } +} +// +// End General Functions ... +// \ No newline at end of file diff --git a/xLibraries/x-saherelm.indicator.lib.mq4 b/xLibraries/x-saherelm.indicator.lib.mq4 new file mode 100644 index 0000000..0e4b162 --- /dev/null +++ b/xLibraries/x-saherelm.indicator.lib.mq4 @@ -0,0 +1,450 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Indicator Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// Reading specified Buffer From ADX Indicator ... +double ReadXMABuffer( + const int bar_index, + const int buffer_index, + // + const int marketLen, + // + const double stp, + const double mxm, + // + const int shortCycleMult, + const int mediumCycleMult, + const int longCycleMult +) { + // + string xmaIndicatorName = "x-saherelm.x.xma"; + + // + double result = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // Inputs ... + marketLen, + stp, + mxm, + shortCycleMult, + mediumCycleMult, + longCycleMult, + MODE_SMA, + // + buffer_index, + bar_index + ); + + // + return result; +} + +// +// Reading specified Buffer from XHL Indicator ... +double ReadXHLBuffer( + const int bar_index, + const int buffer_index, + // + const int marketLen, + // + const int shortCycleMult, + const int mediumCycleMult, + const int longCycleMult +) { + // + string xhlIndicatorName = "x-saherelm.x.hl"; + + // + double result = iCustom( + _Symbol, + _Period, + xhlIndicatorName, + // + // Inputs ... + marketLen, + shortCycleMult, + mediumCycleMult, + longCycleMult, + MODE_SMA, + // + buffer_index, + bar_index + ); + + // + return result; +} + +// +// Reading ADX Values ... +double ReadADX( + const int bar_index, + const int marketLen, + const int mult +) { + // + double result; + + // + int period = marketLen * mult; + + // + result = iADX( + _Symbol, + _Period, + period, + PRICE_CLOSE, + MODE_MAIN, + bar_index + ); + + // + return result; +} + +// +// Reading Pivot States ... +XPvtState GetPVTState( + const int bar_index, + const int marketLen +) { + // + XPvtState result = {}; + + // + double hh = GetMarketHighestHigh( + bar_index, + marketLen + ); + + // + double ho = GetMarketHighestOpen( + bar_index, + marketLen + ); + + // + double hc = GetMarketHighestClose( + bar_index, + marketLen + ); + + // + double hl = GetMarketHighestLow( + bar_index, + marketLen + ); + + // + double ll = GetMarketLowestLow( + bar_index, + marketLen + ); + + // + double lo = GetMarketLowestOpen( + bar_index, + marketLen + ); + + // + double lc = GetMarketLowestClose( + bar_index, + marketLen + ); + + // + double lh = GetMarketLowestHigh( + bar_index, + marketLen + ); + + // + // Filling Result ... + // + result.hh = hh; + result.ho = ho; + result.hc = hc; + result.hl = hl; + + // + result.ll = ll; + result.lo = lo; + result.lc = lc; + result.lh = lh; + + // + return result; +} + +// +// Calculate XRange from Market ... +static XRState lastXRState; +XRState GetXRange( + const int bar_index, + const int rangeMarketLength +) { + // + XRState result = {}; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + int marketBarIndex = bar_index + rangeMarketLength; + + // + // Highest High ... + // + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketBarIndex, + bar_index + ); + + // + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + // Lowest Low ... + // + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketBarIndex, + bar_index + ); + + // + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + if (lastXRState.start == 0) { + // + lastXRState.start = barTime; + lastXRState.length = rangeMarketLength; + + // + lastXRState.hh = hh; + lastXRState.ll = ll; + + // + // Middle ... + double mid = (hh + ll) / 2; + lastXRState.mid = mid; + } else { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + lastXRState.start + ); + + // + if (startBarIndex - bar_index >= rangeMarketLength) { + // + lastXRState.start = barTime; + lastXRState.length = rangeMarketLength; + + // + lastXRState.hh = hh; + lastXRState.ll = ll; + + // + // Middle ... + double mid = (hh + ll) / 2; + lastXRState.mid = mid; + } + } + + // + result = lastXRState; + + // + return result; +} + +// +// Reading XTPowState from Indicatoe ... +XTPOWState GetXTPowState( + const int bar_index, + const int marketLen +) { + // + XTPOWState result = {}; + + // + // + double powerUp = 0; + double powerDown = 0; + double signal = 0; + + // + string indicatorName = "x-saherelm.xtpow"; + + // + int pUpIndex = 0; + int pDownIndex = 1; + int signalIndex = 2; + + // + powerUp = iCustom( + _Symbol, + _Period, + indicatorName, + // + marketLen, + // + pUpIndex, + bar_index + ); + + // + powerDown = iCustom( + _Symbol, + _Period, + indicatorName, + // + marketLen, + // + pDownIndex, + bar_index + ); + + // + signal = iCustom( + _Symbol, + _Period, + indicatorName, + // + marketLen, + // + signalIndex, + bar_index + ); + + // + result.signal = signal; + result.powerUp = powerUp; + result.powerDown = powerDown; + + // + return result; +} + +// +// Reading XRState From Indicator ... +XRState ReadXRange( + const int bar_index, + const int marketLen +) { + // + XRState result = {}; + + // + // Define Buffer Indexes ... + int hhBufferIndex = 0; + int llBufferIndex = 1; + int midBufferIndex = 2; + + // + string indicatorName = "x-saherelm.xrange"; + + // + // Read Values From XRange Indicator ... + + // + double hh = iCustom( + _Symbol, + _Period, + indicatorName, + // + // Inputs ... + marketLen, + // + hhBufferIndex, // Buffer Index ... + bar_index + ); + + // + double ll = iCustom( + _Symbol, + _Period, + indicatorName, + // + // Inputs ... + marketLen, + // + llBufferIndex, // Buffer Index ... + bar_index + ); + + // + double mid = iCustom( + _Symbol, + _Period, + indicatorName, + // + // Inputs ... + marketLen, + // + midBufferIndex, // Buffer Index ... + bar_index + ); + + // + // Filling Result ... + result.hh = hh; + result.ll = ll; + result.mid = mid; + + // + return result; +} +// +// END Indicator Reading Data ... +// diff --git a/xLibraries/x-saherelm.lib.mq4 b/xLibraries/x-saherelm.lib.mq4 new file mode 100644 index 0000000..cc0e23e --- /dev/null +++ b/xLibraries/x-saherelm.lib.mq4 @@ -0,0 +1,1662 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +static datetime lastBarTime; + +// +struct XOHCL { + double high; + double open; + double close; + double low; +}; + +// +struct XRange { + // + datetime time; + + // + double highestHigh; + double lowestLow; + + // + int levels; + int marketLength; + + // + double rate; +}; + +// +struct XPrice { + // + double askPrice; + double bidPrice; + double priceGap; + + // + double longEntry; + double longExit; + + // + double shortEntry; + double shortExit; +}; + +// +// START Functions ... +// + +// +// Determines current working is New Bar or not ... +bool IsNewBar() { + // + // Reading Last Bar Date ... + datetime curbar = (datetime)SeriesInfoInteger( + _Symbol, + _Period, + SERIES_LASTBAR_DATE + ); + + // + if(lastBarTime != curbar) { + // + lastBarTime = curbar; + return true; + } + + // + return false; +} + +// +// Determines we are in new Day or not ... +bool IsNewDay() { + // + bool result = false; + + // + // Reading Last Bar Date ... + datetime curbar = (datetime)SeriesInfoInteger( + _Symbol, + _Period, + SERIES_LASTBAR_DATE + ); + + // + if (lastBarTime == 0) { + lastBarTime = curbar; + } + + // + if (curbar == lastBarTime) { + return result; + } + + // + // Retrieve Day and Month and Year for Last Bar Time ... + int lastBarDay = TimeDay(lastBarTime); + int lastBarMonth = TimeMonth(lastBarTime); + int lastBarYear = TimeYear(lastBarTime); + + // + // Retrieve Day and Month and Year for Current Bar Time ... + int curBarDay = TimeDay(curbar); + int curBarMonth = TimeMonth(curbar); + int curBarYear = TimeYear(curbar); + + // + result = curBarDay > lastBarDay + || curBarMonth > lastBarMonth + || curBarYear > lastBarYear; + + // + return result; +} + +// +// Retrieve Number of Candles in a Day ... +int GetDailyCandleCount() { + // + int seconds = PeriodSeconds(_Period); + + // + int daySeconds = 24 * 60 * 60; + + // + int result = daySeconds / seconds; + + // + return result; +} + +// +// XRange Detector ... +XRange GetMarketRange( + const int bar_index, + const int marketLen, + const int levels +) { + // + XRange result = {}; + + // + result.levels = levels; + result.marketLength = marketLen; + + // + datetime time = iTime( + _Symbol, + _Period, + bar_index + ); + result.time = time; + + // + double highestHigh = GetMarketHighestHigh( + bar_index, + marketLen + ); + result.highestHigh = highestHigh; + + // + double lowestLow = GetMarketLowestLow( + bar_index, + marketLen + ); + result.lowestLow = lowestLow; + + // + double diff = highestHigh - lowestLow; + double rate = diff / levels; + + // + result.rate = rate; + + // + return result; +} + +// +// Retrieve RMA on Specific Candle ... +double GetRMA( + int bar_index, + int length +) { + // + double shortSMA = iMA(_Symbol, _Period, length, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double mediumSMA = iMA(_Symbol, _Period, length * 2, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double longSMA = iMA(_Symbol, _Period, length * 3, 0, MODE_SMA, PRICE_CLOSE, bar_index); + + // + double result = longSMA - mediumSMA + shortSMA; + + // + return result; +} + +// +// Retrieve Moving Average ... +double GetMA( + const int bar_index, + const int maLength, + const int maShift, + const ENUM_MA_METHOD maMethod, + const ENUM_APPLIED_PRICE appliedPrice +) { + // + double result = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + appliedPrice, + bar_index + ); + + // + return result; +} + +// +// Calculate Fib Level ... +double GetFibonacciLevel( + double upPrice, + double downPrice, + double level, + int direction +) { + // + double ling = upPrice - downPrice; + double pLevel = (ling / 100) * (level * 100); + + // + double result = direction > 0 ? + upPrice - pLevel : + downPrice + pLevel; + result = NormalizeDouble(result, _Digits); + + // + return result; +} + +// +// Retrieve True Range ... +double GetTR( + const int bar_index +) { + // + double result = 0; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double prevClose = iClose( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double highLowDif = high - low; + double hpCDif = MathAbs(high - prevClose); + double lpCDiff = MathAbs(low - prevClose); + + // + result = MathMax(highLowDif, hpCDif); + result = MathMax(result, lpCDiff); + + // + return result; +} + +// +// Calculate True Range Simple Moving Average ... +double GetMarketTRSMA( + const int bar_index, + const int marketLen +) { + // + double result = 0; + + // + // Create Barket Length Trs ... + double trs[]; + ArrayResize( + trs, + marketLen + ); + int index = 0; + double trSum = 0; + for (int i = bar_index; i < bar_index + marketLen; i++) { + // + double tr = GetTR(i); + trs[index] = tr; + + // + trSum += tr; + + // + index++; + } + + // + result = trSum / marketLen; + + // + return result; +} + +// +// Retrieve Commodity Channel ... +double GetMarketCCI( + const int bar_index, + const int marketLen, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE +) { + // + double result = 0; + + // + result = iCCI( + _Symbol, + _Period, + marketLen, + appliedPrice, + bar_index + ); + + // + return result; +} + +// +// this function check crossing up two Buffers ... +bool IsCrossedOver( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] > arr2[index1]) && !(arr1[index2] > arr2[index2]); + + // + return result; +} + +// +// this function check crossing down two Buffers ... +bool IsCrossedUnder( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] < arr2[index1]) && !(arr1[index2] < arr2[index2]); + + // + return result; +} + +// +// Convert points to Actual Point ... +double PointsToDouble(int points) { + // + double result = points * _Point; + return result; +} + +// +// Converts Pips to Points ... +int PipsToPoints(int pips) { + // + int result = pips * ((_Digits == 3 || _Digits == 5) ? 10 : 1); + return result; +} + +// +// Converts Pips to Double ... +double PipsToDouble(int pips) { + // + double result = PointsToDouble(PipsToPoints(pips)); + return result; +} + +// +// Converts Double Value to Pips ... +int PriceToPips(double value) { + // + if (value <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + int result = (int)(value / pipValue); + + // + return result; +} + +// +// Converts Pips to Double ... +double PipsToPrice(int pips) { + // + if (pips <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + double result = pipValue * pips; + + // + return result; +} + +// +// Generate ATR StopLoss Value ... +double CalculateATRSL( + int period, + double multiplier +) { + // + if (period <= 0 || multiplier <= 0) { + return 0; + } + + // + double atrValue = iATR( + _Symbol, + _Period, + period, + 0 + ); + + // + double result = atrValue * multiplier; + + // + return result; +} + +// +// Detect Candle Type ... +// Bullish => means close > open ... +bool IsBullishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBullishCandle( + open, + close + ); + + // + return result; +} + +bool IsBullishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open < close; + + // + return result; +} + +// +// Detect Candle Type ... +// Bearish => means close < open ... +bool IsBearishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBearishCandle( + open, + close + ); + + // + return result; +} + +bool IsBearishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open > close; + + // + return result; +} + +// +// Retrieve a Candle Info ... +XOHCL GetCandleModel( + const int bar_index +) { + // + XOHCL result = {}; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + result.high = high; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + result.open = open; + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + result.close = close; + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + result.low = low; + + // + return result; +} + +// +// Retrieve Market Current Prices for Signals ... +XPrice GetPrice() { + // + XPrice result = {}; + + // + RefreshRates(); + + // + double askPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double bidPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(bidPrice - askPrice); + + // + result.askPrice = askPrice; + result.bidPrice = bidPrice; + result.priceGap = priceGap; + + // + result.longEntry = askPrice; + result.longExit = bidPrice; + + // + result.shortEntry = bidPrice; + result.shortExit = askPrice; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBullishDetected( + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double shpDetectMultipliers // Sharp Detect Multiplier +) { + // + bool result = false; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double minValue = 0; + double maxValue = 0; + int positionedLength = bar_index + marketLen; + + // + for (int i = bar_index; i < positionedLength; i++) { + // + double cHigh = iHigh( + _Symbol, + _Period, + i + ); + + // + double cLow = iLow( + _Symbol, + _Period, + i + ); + + // + minValue += MathMin(cLow, cHigh); + maxValue += MathMax(cLow, cHigh); + } + + // + double minAvg = minValue / positionedLength; + double maxAvg = maxValue / positionedLength; + + // + double shpValue = shpDetectMultipliers * _Point; + + // + result = (low - minAvg) > shpValue; + + // + int index = bar_index; + while ( + index < positionedLength + || !result + ) { + // + low = iLow( + _Symbol, + _Period, + index + ); + + // + result = result + || (low - minAvg) > shpValue; + + // + index++; + }; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBearishDetected( + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double shpDetectMultipliers // Sharp Detect Multiplier +) { + // + bool result = false; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double minValue = 0; + double maxValue = 0; + int positionedLength = bar_index + marketLen; + + // + for (int i = bar_index; i < positionedLength; i++) { + // + double cHigh = iHigh( + _Symbol, + _Period, + i + ); + + // + double cLow = iLow( + _Symbol, + _Period, + i + ); + + // + minValue += MathMin(cLow, cHigh); + maxValue += MathMax(cLow, cHigh); + } + + // + double minAvg = minValue / positionedLength; + double maxAvg = maxValue / positionedLength; + + // + double shpValue = shpDetectMultipliers * _Point; + + // + result = (high - maxAvg) > shpValue; + + // + int index = bar_index; + while ( + index < positionedLength + || !result + ) { + // + high = iHigh( + _Symbol, + _Period, + index + ); + + // + result = result + || (high - maxAvg) > shpValue; + + // + index++; + }; + + // + return result; +} + +// +// Retrieve Highest High Value based on Given Market ... +double GetMarketHighestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Low Value based on Given Market ... +double GetMarketHighestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Open Value based on Given Market ... +double GetMarketHighestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Close Value based on Given Market ... +double GetMarketHighestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Low Value based on Given Market ... +double GetMarketLowestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest High Value based on Given Market ... +double GetMarketLowestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Open Value based on Given Market ... +double GetMarketLowestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Close Value based on Given Market ... +double GetMarketLowestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// less than given price ... +double GetLowLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// great than given price ... +double GetLowGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// less than given price ... +double GetHighLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// great than given price ... +double GetHighGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// less than given price ... +double GetCloseLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// great than given price ... +double GetCloseGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Get Slope of a Line by it's two Point ... +double GetSlope( + double x1, + double y1, + double x2, + double y2 +) { + // + double result = (y2 - y1)/MathAbs(x2 - x1); + return result; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/xLibraries/x-saherelm.log.lib.mq4 b/xLibraries/x-saherelm.log.lib.mq4 new file mode 100644 index 0000000..066b3f7 --- /dev/null +++ b/xLibraries/x-saherelm.log.lib.mq4 @@ -0,0 +1,91 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Log Tag ... +static string logTag = ""; + +// +// Enable or Disable Logging ... +static bool enableLogging = false; + +// +// Start Log Messages ... +// + +// +// Logging a Message, specified for this EA ... +// using provided LogTag ... +void LogMessage(string message) { + // + if (!enableLogging) { + return; + } + + // + Print(logTag, " > ", message); +} + +// +// this used for logging series ... +void LogSeries( + double &series[], // which series to Log ... + int length = 0, // number of items to Log, 0 means all ... + int skip = 0 // number of items which skip before logging ... +) { + // + string msg = ""; + + // + int seriesSize = ArraySize(series); + if ( + skip < 0 + || length < 0 + || seriesSize == 0 + || skip > seriesSize + || skip + length > seriesSize + ) { + return; + } + + // + length = length == 0 ? + seriesSize : + length; + int start = skip > 1 ? + skip - 1 : + skip == 1 ? + 1 : + 0; + + // + // Loop through series items ... + for (int i = start; i < start + length; i++) { + // + msg += StringConcatenate( + "i[", i, "]: ", series[i], ", " + ); + } + + // + LogMessage(msg); +} +// +// End Log Messages ... +// + diff --git a/xLibraries/x-saherelm.models.lib.mq4 b/xLibraries/x-saherelm.models.lib.mq4 new file mode 100644 index 0000000..fa9903f --- /dev/null +++ b/xLibraries/x-saherelm.models.lib.mq4 @@ -0,0 +1,154 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Models Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// START STATIC Variables ... +// +// +static int totalSignals = 0; +static int totalLongSignals = 0; +static int totalShortSignals = 0; + +// +static double initialBalance = 0; + +// +static int countedBars = 0; +static bool isNewBar = false; +static bool isNewDay = false; +// +// END STATIC Variables ... +// + +// +// Start Models ... +// +// +// Signal Providers ... +enum ENUM_X_SIGNAL_PROVIDER { + X_UNKNOWN_PROVIDER, + X_XXX_PROVIDER, + X_XR_PROVIDER, + X_XTPW_PROVIDER +}; + +// +// these are different signal types ... +enum ENUM_X_SIGNAL_TYPE { + X_SIGNAL_NONE, + X_SIGNAL_LONG, + X_SIGNAL_SHORT, +}; + +// +// Model Market Highs and Lows ... +struct XPvtState { + // + double hh; + double ho; + double hc; + double hl; + + // + double ll; + double lo; + double lc; + double lh; +}; + +// +// we Model each signals as this type ... +struct XSignal { + // + // Signal Symbol ... + string symbol; + + // + // Signal Type ... + ENUM_X_SIGNAL_TYPE type; + + // + // Signal ID ... + int id; + + // + // Signal Ticket Number, when Opening Trade ... + int ticket; + + // + // Signal Provider ... + ENUM_X_SIGNAL_PROVIDER provider; + + // + // Target Point ... + double tp; + + // + // Stop Loss ... + double sl; + + // + // Signal Entry Price ... + double entry; + + // + // Signalling Time ... + datetime time; + + // + // Signal Comments ... + string comment; + + // + // Signal TAG ... + string tag; +}; + +// +// this is Signal Request Response model ... +struct XSignalRequest { + bool hasSignal; + XSignal signal; + ENUM_X_SIGNAL_TYPE type; + ENUM_X_SIGNAL_PROVIDER provider; +}; + +// +struct XRState { + // + datetime start; + int length; + + // + double hh; + double ll; + double mid; +}; + +// +struct XTPOWState { + // + double powerUp; + double powerDown; + + // + double signal; +}; +// +// End Models ... +// diff --git a/xLibraries/x-saherelm.signal.lib.mq4 b/xLibraries/x-saherelm.signal.lib.mq4 new file mode 100644 index 0000000..097ce74 --- /dev/null +++ b/xLibraries/x-saherelm.signal.lib.mq4 @@ -0,0 +1,1756 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Signal Draw Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +#include "../Libraries/x-saherelm.x.signal.lib.mq4" +#include "../Libraries/x-saherelm.xr.signal.lib.mq4" +#include "../Libraries/x-saherelm.xtpw.signal.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// END Global Requirement Functions ... +// + +// +// START Signal Related Functions ... +// +// +// Retrieve Signal Bar Index ... +int GetSignalBarIndex(XSignal &signal) { + // + // Temp Result ... + int result = -1; + + // + // Retriev Signal Bar Index ... + result = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + return result; +} + +// +string GetSignalProviderIdentifier( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + string result = ""; + + // + switch (provider) { + // + case X_XXX_PROVIDER: + result = "XXX"; + break; + + // + case X_XR_PROVIDER: + result = "XR"; + break; + + // + case X_XTPW_PROVIDER: + result = "XTPW"; + break; + + // + default: + result = ""; + break; + } + + // + return result; +} + +// +ENUM_X_SIGNAL_PROVIDER GetSignalProvider(string identifier) { + // + ENUM_X_SIGNAL_PROVIDER result = X_UNKNOWN_PROVIDER; + + // + if ( + StringFind( + identifier, + GetSignalProviderIdentifier(X_XXX_PROVIDER) + ) > -1 + ) { + result = X_XXX_PROVIDER; + } else if ( + StringFind( + identifier, + GetSignalProviderIdentifier(X_XR_PROVIDER) + ) > -1 + ) { + result = X_XR_PROVIDER; + } else if ( + StringFind( + identifier, + GetSignalProviderIdentifier(X_XTPW_PROVIDER) + ) > -1 + ) { + result = X_XTPW_PROVIDER; + } + + // + return result; +} + +// +// Retrieve Signal Lots Per Trade ... +double GetSignalLottage( + const XSignal &signal, + const double defLotsPerTrade +) { + // + double result = defLotsPerTrade; + + // + bool isLong = signal.type == X_SIGNAL_LONG; + + // + switch (signal.provider) { + // + case X_XR_PROVIDER: + // + result = isLong ? + xRLongLotsPerTradePercent : + xRShortLotsPerTradePercent + ; + break; + + // + case X_XXX_PROVIDER: + // + result = isLong ? + xLongLotsPerTradePercent : + xShortLotsPerTradePercent + ; + break; + + // + case X_XTPW_PROVIDER: + // + result = isLong ? + xTPWLongLotsPerTradePercent : + xTPWShortLotsPerTradePercent + ; + break; + } + + // + return result; +} + +// +// Draw Specific Range On Chart ... +void DrawRange( + const XRange &range, + const long chartID = 0, + const int subWindowID = 0, + const string tag = "", + const color clr = clrYellow +) { + // + // Loop through Levels Count ... + for (int i = 0; i <= range.levels; i++) { + // + datetime time1 = iTime( + _Symbol, + _Period, + 1 + ); + + // + datetime time2 = iTime( + _Symbol, + _Period, + 0 + ); + + // + double price = range.lowestLow + (i * range.rate); + + // + string lbl = StringConcatenate( + tag, + "_XRL_", + price + ); + + // + DrawTrendLine( + chartID, + lbl, + subWindowID, + time1, + price, + time2, + price, + clr, + STYLE_DOT + ); + } +} + +// +// Draw Signal Shapes on Chart ... +bool DrawSignal( + const XSignal &signal, + long chartID = 0, + int subWindowID = 0, + const double positionThresholdFactor = 10, + string longSignalLabel = "X-Long", + color longSignalColor = clrAqua, + string shortSignalLabel = "X-Short", + color shortSignalColor = clrFuchsia +) { + // + // Generate isLongSignal Var ... + bool isLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Signal Bar Index ... + int bar_index = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // START Draw Signal Arrow ... + // + // + // Arrow Shape Name ... + string arrowName = StringConcatenate(signal.tag, "_Arrow_", signal.id); + + // + // Arrow Price ... + double arrowPrice = 0; + if (isLongSignal) { + // + arrowPrice = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice - (positionThresholdFactor * _Point); + } else { + // + arrowPrice = iHigh( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice + (positionThresholdFactor * _Point); + } + + // + // Arrow Code ... + uchar arrowCode = isLongSignal ? SYMBOL_ARROWUP : SYMBOL_ARROWDOWN; + + // + // Arrow Anchor Point ... + ENUM_ARROW_ANCHOR arrowAnchorPoint = isLongSignal ? ANCHOR_BOTTOM : ANCHOR_TOP; + + // + // Arrow Color ... + color arrowColor = isLongSignal ? longSignalColor : shortSignalColor; + + // + // Draw Signal Arrow Shape ... + bool result = DrawArrow( + chartID, + arrowName, + subWindowID, + signal.time, + arrowPrice, + arrowCode, + arrowAnchorPoint, + arrowColor + ); + // + // END Draw Signal Arrow ... + // + + // + // START Draw Signal SL/TP ... + // + string slLineName = StringConcatenate(signal.tag, "_SL_", signal.id); + string tpLineName = StringConcatenate(signal.tag, "_TP_", signal.id); + string entryLineName = StringConcatenate(signal.tag, "_ENTRY_", signal.id); + + // + color slColor = shortSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color tpColor = longSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color entryColor = clrGreen; + + // + datetime time1 = iTime( + _Symbol, + _Period, + bar_index + 1 + ); + + // + // Draw Enrty Price ... + result = DrawTrendLine( + chartID, + entryLineName, + subWindowID, + time1, + signal.entry, + signal.time, + signal.entry, + entryColor, + STYLE_SOLID, + 2 + ); + + // + // Draw Signal SL ... + if (signal.sl > 0) { + // + result = DrawTrendLine( + chartID, + slLineName, + subWindowID, + time1, + signal.sl, + signal.time, + signal.sl, + slColor, + STYLE_SOLID, + 2 + ); + } + + // + // Draw Signal TP ... + if (signal.tp > 0) { + // + result = DrawTrendLine( + chartID, + tpLineName, + subWindowID, + time1, + signal.tp, + signal.time, + signal.tp, + tpColor, + STYLE_SOLID, + 2 + ); + } + // + // END Draw Signal SL/TP ... + // + + // + // Start Draw Signal Label ... + // + // + string labelName = StringConcatenate(signal.tag, "_Label_", signal.id); + + // + double labelPrice = isLongSignal ? arrowPrice - (positionThresholdFactor * _Point) : arrowPrice + (positionThresholdFactor * _Point); + + // + string labelText = isLongSignal ? longSignalLabel : shortSignalLabel; + labelText = StringConcatenate( + labelText, + "_", + GetSignalProviderIdentifier(signal.provider) + ); + + // + result = DrawText( + chartID, + labelName, + subWindowID, + signal.time, + labelPrice, + labelText, + "Arial", + 8, + arrowColor, + 0, + ANCHOR_CENTER + ); + // + // End Draw Signal Label ... + // + + // + return result; +} + +// +// Trade on Specific Signal ... +bool TradeSignal( + XSignal &signal, + // + double volumePercent, + // + // Long ... + const string longSignalLabel, + const color longSignalColor, + // + // Short ... + const string shortSignalLabel, + const color shortSignalColor +) { + // + // Temp Result ... + bool result = false; + + // + if (initialBalance == 0) { + initialBalance = AccountInfoDouble(ACCOUNT_BALANCE); + } + + // + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + int openPositions = CountOpenTrades(); + double volume = (volumePercent * initialBalance); + + // + if ( + signal.type != X_SIGNAL_LONG && + signal.type != X_SIGNAL_SHORT + ) { + return result; + } + + // + bool hasLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Check TP and Entry Price ... + if ( + ( + hasLongSignal + && signal.entry > signal.tp + ) || + ( + !hasLongSignal + && signal.entry < signal.tp + ) + ) { + return result; + } + + // + // Order Operation ... + int operation = hasLongSignal ? + OP_BUY : + OP_SELL; + + // + // Detect Trade Color ... + color clr = hasLongSignal ? + longSignalColor : + shortSignalColor; + + // + // Generate Signal Comment ... + string label = hasLongSignal ? + longSignalLabel : + shortSignalLabel; + + // + // Generate Signal Comment ... + string comment = StringConcatenate( + signal.tag, + "_", signal.id, + "_", GetSignalProviderIdentifier(signal.provider), + "_", label + ); + + // + // Placing Order ... + int orderTicket = OrderSend( + _Symbol, + operation, + volume, + signal.entry, + 3, + signal.sl, + signal.tp, + comment, + signal.id, + 0, + clr + ); + + // + // Draw Signal Shape if Order Opened Successfully ... + if (orderTicket >= 0) { + // + signal.ticket = orderTicket; + + // + // Here i must to Draw Signal Shapes ... + bool isDrawn = DrawSignal( + signal, + 0, + 0, + 50, + longSignalLabel, // Long Signal Label ... + longSignalColor, + shortSignalLabel, // Short Signal Label ... + shortSignalColor + ); + + // + LogMessage( + StringConcatenate( + "Order [", orderTicket ,"]: Provided by: ", GetSignalProviderIdentifier(signal.provider) + ) + ); + + // + // TODO: here we have to check if there are another + // open positions which their entry price is bigger + // than current signal entry price, for long trades and + // their tp is high than current tp, ... + // close in profit trades or modify orders tp to current ... + // // + // if (CountOpenTrades() > 0) { + // // + // // Here we have to + // ModifyOpenTradesBasedOnCurrentTrade(signal); + // } + + // + result = true; + } + + // + return result; +} +// +// END Signal Related Functions ... +// + +// +// START Orders Functions ... +// +// +// Convert To XSignal Model ... +XSignal OrderToSignal() { + // + // Temp Result ... + XSignal result = {}; + result.type = X_SIGNAL_NONE; + + // + // Here we can get some usefull info based on selected order ... + double swap = OrderSwap(); + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + int magicNumber = OrderMagicNumber(); + double takeProfit = OrderTakeProfit(); + string comment = OrderComment(); + + // + ENUM_X_SIGNAL_PROVIDER provider = GetSignalProvider(comment); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // Conver Position to Signal ... + result.sl = stopLoss; + result.tp = takeProfit; + result.time = openTime; + result.symbol = _Symbol; + result.id = magicNumber; + result.comment = comment; + result.entry = openPrice; + result.provider = provider; + result.type = isLongOrder ? X_SIGNAL_LONG : X_SIGNAL_SHORT; + + // + return result; +} + +// +// START Count Orders ... +// +// +// Count Open Positions ... +int CountOpenTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if (OrderSymbol() == _Symbol) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Long Positions ... +int CountOpenLongTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_BUY + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Short Positions ... +int CountOpenShortTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_SELL + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} +// +// END Count Orders ... +// + +// +// START Close Orders ... +// +// +// Close All Open Trades ... +bool CloseAllTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + + // + return result; +} + +// +bool CloseAllProviderTrades( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal(); + + // + if (signal.provider == provider) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +bool CloseAllProviderLongTrades( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal(); + + // + if ( + signal.provider == provider + && signal.type == X_SIGNAL_LONG + ) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +bool CloseAllProviderShortTrades( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal(); + + // + if ( + signal.provider == provider + && signal.type == X_SIGNAL_SHORT + ) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Long Trades ... +bool CloseAllLongTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Long Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Short Trades ... +bool CloseAllShortTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (!isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Short Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In Profit Trades ... +bool CloseAllInProfitTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit > 0 + && profit > 50 * _Point + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InProfit Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In DrawDown Trades ... +bool CloseAllInDrawDownTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if (profit < 0) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close Biggest In DrawDown Trades ... +bool CloseBiggestDrawDownTrade() { + // + // Loop through all Positions ... + bool result = false; + double drawDown = 0; + + // + // Find Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) > drawDown + ) { + drawDown = profit; + } + } + } + } + + // + // Close Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) >= drawDown + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Max InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Long Time Trades ... +bool CloseAllLongTimeTrades( + const int passedCandles, + const ENUM_X_SIGNAL_PROVIDER provider = X_UNKNOWN_PROVIDER +) { + // + bool result = false; + + // + if (passedCandles <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + string comment = OrderComment(); + + // + ENUM_X_SIGNAL_PROVIDER orderProvider = GetSignalProvider(comment); + bool isProviderVerified = + provider == X_UNKNOWN_PROVIDER ? + true : + orderProvider != X_UNKNOWN_PROVIDER + && orderProvider == provider + ; + + // + if ( + profit < 0 + && isProviderVerified + && openBarIndex - currentBarIndex >= passedCandles + // || ( + // profit > 0.5 + // && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 3) + // ) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Long Time issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + // else if ( + // openTrades > 0 + // && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 2) + // ) { + // result = CloseAllInProfitTrades() + // && CloseBiggestDrawDownTrade(); + // } + } + } + } + + // + return result; +} + +// +// Close all trades which passed Maximum Drawdown ... +bool CloseAllMaximumDrawDownPassedTrades( + const double maxDrDownPercentPerPTrade, + const ENUM_X_SIGNAL_TYPE type = X_SIGNAL_NONE, + const ENUM_X_SIGNAL_PROVIDER provider = X_UNKNOWN_PROVIDER +) { + // + if ( + initialBalance <= 0 + || maxDrDownPercentPerPTrade <= 0 + ) { + return false; + } + + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double maxAllowedDrawDown = -1 * (initialBalance * maxDrDownPercentPerPTrade); + + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + string comment = OrderComment(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + bool isTypeVerified = + type == X_SIGNAL_NONE ? + true : + ( isLongOrder + && type == X_SIGNAL_LONG + ) || ( + !isLongOrder + && type == X_SIGNAL_SHORT + ) + ; + + // + ENUM_X_SIGNAL_PROVIDER orderProvider = GetSignalProvider(comment); + bool isProviderVerified = + provider == X_UNKNOWN_PROVIDER ? + true : + orderProvider != X_UNKNOWN_PROVIDER + && orderProvider == provider + ; + + // + if ( + profit < 0 + && isTypeVerified + && isProviderVerified + && MathAbs(profit) >= MathAbs(maxAllowedDrawDown) + ) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Maximum DarwDown issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Trades Which Opens before Specified Length ... +bool CloseAllTradesWhichOpenInPastMarketLength( + const int marketLen +) { + // + bool result = false; + + // + if (marketLen <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + + // + if (openBarIndex <= currentBarIndex + marketLen) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Market Reverse issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } else if (openTrades > 0) { + // + // Close all InProfit Trdes and Biggest InDrawDown Trades ... + // result = CloseAllInProfitTrades(); + // && CloseBiggestDrawDownTrade(); + } + } + } + } + + // + return result; +} +// +// END Close Orders ... +// + +// +// START Modify Orders ... +// +// +void ModifyAllPriceLesserOpenTrades( + const XSignal &signal +) { + // + // Loop through all Open Trades ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + double takeProfit = OrderTakeProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // When new Signal Comming with price less than + // currently open trade and tp less than currently + // open trade, this means a market change happens ... + // here we can Close InProfit Trades or Modify Trades TP ... + if ( + ( + openPrice < signal.entry + || MathAbs(openPrice - signal.entry) < 300 * _Point + ) + && takeProfit > signal.tp + ) { + bool result = OrderModify( + ticket, + openPrice, + signal.sl, + signal.tp, + clrYellow + ); + } + } + } + } +} + +// +void ModifyOpenTradesBasedOnCurrentTrade( + const XSignal &signal +) { + // + ModifyAllPriceLesserOpenTrades(signal); +} +// +// END Modify Orders ... +// +// +// END Orders Functions ... +// + +// +// START Signal Conditions ... +// +// +// Clear Signal Conditions ... +void ClearSignalConditions() { + // + ClearLongSignalConditions(); + ClearShortSignalConditions(); +} + +// +// Clear all Conditions Waiter for Long Signals ... +void ClearLongSignalConditions() { + // + ClearXLongSignalConditions(); + ClearXRLongSignalConditions(); + ClearXTPWLongSignalConditions(); +} + +// +// Clear all Conditions Waiter for Short Signals ... +void ClearShortSignalConditions() { + // + ClearXShortSignalConditions(); + ClearXRShortSignalConditions(); + ClearXTPWShortSignalConditions(); +} +// +// END Signal Conditions ... +// diff --git a/xLibraries/x-saherelm.x.signal.lib.mq4 b/xLibraries/x-saherelm.x.signal.lib.mq4 new file mode 100644 index 0000000..834ddb1 --- /dev/null +++ b/xLibraries/x-saherelm.x.signal.lib.mq4 @@ -0,0 +1,1063 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 X Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Inputs ... +// +// +input string xStarter = "- X Signal Provider -"; // ---> X Signal Provider <--- + +// +input bool enableXSignalling = true; // X Signalling Enable + +// +input bool enableXLong = true; // X Signalling Enable Long +input bool enableXShort = true; // X Signalling Enable Short + +// +input double xShortR2R = 3; // X Short Risk To Reward Ratio +input double xShortLotsPerTradePercent = 0.0002; // X Lots Percent per Short Trades +input double xShortMaxDrawdownPerTradePercent = 0.4; // X Max Allowed DrawDown Percent per Short Trade + +// +input double xLongR2R = 3; // X Long Risk To Reward Ratio +input double xLongLotsPerTradePercent = 0.0002; // X Lots Percent per Short Trades +input double xLongMaxDrawdownPerTradePercent = 0.4; // X Max Allowed DrawDown Percent per Long Trade + +// +input double xSharpDetectorFactor = 700; // X Sharp Detection Factor + +// +input int xMaximumCandlesPerTrade = 206; // X Maximum Candles which a Trade can open + +// +input int xOscillatorLength = 7; // X Oscillator Length + +// +input double xPSarStep = 0.02; // X Parabolic Sar Step +input double xPSarMaximum = 0.2; // X Parabolic Sar Maximum + +// +input int xRangeMarketLength = 5; // X Range Detector Length + +// +input int xSwingLength = 7; // X Signal Swing Length +// +// END Inputs ... +// + +// +// START Global Requirement Functions ... +// +// +// X Based Signal Conditions ... +struct XSignalConditions { + datetime startTime; + datetime signalTime; + datetime entryTime; +}; + +// +struct XMarketState { + double psar; + double fast; + double slow; + double open; + double verifier; + double oscillator; + double oscillatorVerifier; +}; + +// +static XSignalConditions xLongConds; +static bool xCloseLongTrades = false; +static bool xWaitForLongSignals = true; + +// +static XSignalConditions xShortConds; +static bool xCloseShortTrades = false; +static bool xWaitForShortSignals = true; + +// +// Count Number of Closed Maximum DrawDown Trades ... +static int xFailedSignals = 0; + +// +datetime lastVerifierTouched; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckXSignalHandler( + const int bar_index +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + // + if ( + !enableXSignalling + || !(enableXLong || enableXShort) + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XOHCL candle = GetCandleModel(bar_index); + XOHCL pCandle = GetCandleModel(bar_index + 1); + XTPOWState tPowState = GetXTPowState( + bar_index + 1, + xSwingLength + ); + + // + XMarketState state = GetXMarketState( + bar_index + 1 + ); + + // + // Check Verifier Last Touched ... + bool isVerifierTouched = pCandle.high > state.verifier + && pCandle.low < state.verifier; + + // + // Disable Signals if a signal Failed ... + if (xFailedSignals) { + // + // TODO: Complete this ... + } + + // + // Enable Or Disable Signalling ... + if (isVerifierTouched) { + // + lastVerifierTouched = barTime; + + // + if (xWaitForLongSignals) { + xWaitForLongSignals = false; + } + + // + if (xWaitForShortSignals) { + xWaitForShortSignals = false; + } + } else { + // + int lastVerifierTouchedBarIndex = iBarShift( + _Symbol, + _Period, + lastVerifierTouched + ); + + // + int distance = MathAbs(lastVerifierTouchedBarIndex - bar_index); + + // + if ( + !xWaitForLongSignals + && distance > (xSwingLength * 2) + ) { + xWaitForLongSignals = true; + } + + // + if ( + !xWaitForShortSignals + && ( + distance > (xSwingLength * 2) + || ( + tPowState.powerDown > tPowState.powerUp + && tPowState.powerDown < 49 + ) + ) + ) { + xWaitForShortSignals = true; + } + } + + // + // Close All Long Open Trades ... + if ( + tPowState.powerDown > 55 + && tPowState.powerDown > tPowState.powerUp + ) { + // xCloseLongTrades = true; + } +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXLongSignalConditions( + const int bar_index +) { + // + if ( + !enableXLong + || !enableXSignalling + || !xWaitForLongSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + bool isCrossOver = false; + bool isCrossUnder = false; + + // + XMarketState cState = GetXMarketState(1); + XMarketState pState = GetXMarketState(2); + + // + isCrossUnder = + cState.fast < cState.slow + && !(pState.fast < pState.slow) + ; + + // + isCrossOver = + cState.fast > cState.slow + && !(pState.fast > pState.slow) + ; + + // + if ( + isCrossUnder + && xLongConds.startTime == 0 + ) { + // + xLongConds.startTime = barTime; + return; + } + + // + if ( + isCrossOver + && xLongConds.startTime > 0 + && xLongConds.signalTime == 0 + ) { + // + xLongConds.signalTime = barTime; + xLongConds.entryTime = barTime; + return; + } +} + +// +// Check and Fill Short Signal Conditions ... +void CheckXShortSignalConditions( + const int bar_index +) { + // + if ( + !enableXShort + || !enableXSignalling + || !xWaitForShortSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + bool isCrossOver = false; + bool isCrossUnder = false; + + // + XMarketState cState = GetXMarketState(1); + XMarketState pState = GetXMarketState(2); + + // + isCrossUnder = + cState.fast < cState.slow + && !(pState.fast < pState.slow) + ; + + // + isCrossOver = + cState.fast > cState.slow + && !(pState.fast > pState.slow) + ; + + // + if ( + isCrossOver + && xShortConds.startTime == 0 + ) { + // + xShortConds.startTime = barTime; + return; + } + + // + if ( + isCrossUnder + && xShortConds.startTime > 0 + && xShortConds.signalTime == 0 + ) { + // + xShortConds.signalTime = barTime; + xShortConds.entryTime = barTime; + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if ( + !enableXSignalling + || !(enableXLong || enableXShort) + ) { + return result; + } + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + if (requestLong) { + // + if ( + !ValidateXLongConditions() + ) { + return result; + } + } else { + // + if ( + !ValidateXShortConditions() + ) { + return result; + } + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double askPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double bidPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double entryPrice = requestLong ? + askPrice : + bidPrice; + + // + double exitPrice = requestLong ? + bidPrice : + askPrice; + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + // + GetMarketLowestLow( + bar_index, + xSwingLength + ) + ; + + // + double hh = + // + GetMarketHighestHigh( + bar_index, + xSwingLength + ) + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = requestLong ? + MathMin(openPrice, closePrice) - ll : + hh - MathMax(openPrice, closePrice) + ; + + // + double reward = + requestLong ? + risk * xLongR2R : + risk * xShortR2R + ; + + // + double sl = requestLong ? + 0 : + 0; + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward + ; + + // + XRState range = GetXRange( + bar_index, + xRangeMarketLength + ); + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XXX_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XXX_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXLongConditions() { + // + if ( + !enableXLong + || !enableXSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xLongConds.startTime > 0 + && xLongConds.signalTime > 0 + && xLongConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.signalTime + ); + + // + int entryBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.entryTime + ); + + // + isBLFilled = + // + xLongConds.signalTime > xLongConds.startTime + && xLongConds.entryTime >= xLongConds.signalTime + // && MathAbs(signalBarIndex - startBarIndex) >= 1 + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXLongSignalConditions(); + } + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXShortConditions() { + // + if ( + !enableXShort + || !enableXSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xShortConds.startTime > 0 + && xShortConds.signalTime > 0 + && xShortConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.signalTime + ); + + // + int entryBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.entryTime + ); + + // + isBLFilled = + // + xShortConds.signalTime > xShortConds.startTime + && xShortConds.entryTime >= xShortConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xWaitForShortSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXShortSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXLongSignalConditions() { + // + xLongConds.startTime = 0; + xLongConds.entryTime = 0; + xLongConds.signalTime = 0; +} + +// +// Clear Short Signal Conditions for New One ... +void ClearXShortSignalConditions() { + // + xShortConds.startTime = 0; + xShortConds.entryTime = 0; + xShortConds.signalTime = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForXSignals( + const XSignal &signal +) { + // + bool result = false; + + // + if ( + !enableXSignalling + || !(enableXLong || enableXShort) + ) { + return result; + } + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // XOHCL candle = GetCandleModel(0); + XOHCL candle = GetCandleModel(signalBarIndex); + XOHCL pCandle = GetCandleModel(signalBarIndex + 1); + + // + // Retrieve Range ... + XRState range = GetXRange( + signalBarIndex, + xRangeMarketLength + ); + + // + // Retrive XMarket States ... + XMarketState xState0 = GetXMarketState(signalBarIndex); + XMarketState xState1 = GetXMarketState(signalBarIndex + 1); + XMarketState xState2 = GetXMarketState(signalBarIndex + 2); + XMarketState xStateLast = GetXMarketState(signalBarIndex + xSwingLength); + + // + // Retrieve Trend Powers ... + XTPOWState xTPow0 = GetXTPowState( + signalBarIndex, + xSwingLength + ); + XTPOWState xTPow1 = GetXTPowState( + signalBarIndex + 1, + xSwingLength + ); + + // + double hh = GetMarketHighestHigh( + signalBarIndex, + xSwingLength + ); + double ll = GetMarketLowestLow( + signalBarIndex, + xSwingLength + ); + double diffChange = (hh - ll); + bool isBigSharpOccured = + diffChange > (xSharpDetectorFactor * _Point) + ; + + // + bool isPSarVerified = false; + bool isTPowVerified = false; + bool isStateVerified = false; + bool isPriceVerified = false; + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + // Get Price Verification for Long ... + isPriceVerified = + // + // Starter ... + true + // + && !isBigSharpOccured + // + && signal.entry < hh + // + // && signal.entry < range.hh + // && signal.entry > range.mid + // // + // && candle.high > xState0.verifier + // && signal.entry > xState0.verifier + // + // && pCandle.low != ll + && pCandle.high != hh + ; + + // + int above20TPowers = 0; + double signalSlope = 0; + int tPowUnverifyConditions = 0; + int tPowUnverifyConditionsIdx = 0; + for (int i = signalBarIndex; i < signalBarIndex + xSwingLength; i++) { + // + XTPOWState iTPowState = GetXTPowState( + i, + xSwingLength + ); + + // + // Calculate Signal Slope ... + if (i == signalBarIndex) { + // + signalSlope = iTPowState.signal; + } else if (i == signalBarIndex + 1) { + // + signalSlope = GetSlope( + 1, + iTPowState.signal, + 2, + signalSlope + ); + } + + // + if ( + iTPowState.powerUp > iTPowState.powerDown + && MathMax(iTPowState.powerUp, iTPowState.powerDown) > 20 + ) { + above20TPowers++; + } + + // + if (tPowUnverifyConditionsIdx < 3) { + // + if ( + iTPowState.powerUp < iTPowState.powerDown + || iTPowState.signal > MathMax(iTPowState.powerUp, iTPowState.powerDown) + ) { + tPowUnverifyConditions++; + } + + // + tPowUnverifyConditionsIdx++; + } + } + + // + isTPowVerified = + above20TPowers > 1 + && tPowUnverifyConditions == 0 + ; + + // + isPSarVerified = + xState0.psar < signal.entry + && xState0.psar < candle.low; + + // + isStateVerified = + // + // Start ... + true + // + // && xState0.open < xState0.slow + ; + + // + result = + // + // Starter ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + isPSarVerified = + xState0.psar > signal.entry + && xState0.psar > candle.high + ; + + // + // Get Price Verification for Short ... + isPriceVerified = + // + // Starter ... + true + // + && !isBigSharpOccured + // + && signal.entry > ll + && pCandle.low != ll + ; + + // + int above20TPowers = 0; + double signalSlope = 0; + int tPowUnverifyConditions = 0; + int tPowUnverifyConditionsIdx = 0; + for (int i = signalBarIndex; i < signalBarIndex + xSwingLength; i++) { + // + XTPOWState iTPowState = GetXTPowState( + i, + xSwingLength + ); + + // + // Calculate Signal Slope ... + if (i == signalBarIndex) { + // + signalSlope = iTPowState.signal; + } else if (i == signalBarIndex + 1) { + // + signalSlope = GetSlope( + 1, + iTPowState.signal, + 2, + signalSlope + ); + } + + // + if ( + iTPowState.powerUp > iTPowState.powerDown + && MathMax(iTPowState.powerUp, iTPowState.powerDown) > 20 + ) { + above20TPowers++; + } + + // + if (tPowUnverifyConditionsIdx < 3) { + // + if ( + iTPowState.powerUp > iTPowState.powerDown + || iTPowState.signal < MathMax(iTPowState.powerUp, iTPowState.powerDown) + ) { + tPowUnverifyConditions++; + } + + // + tPowUnverifyConditionsIdx++; + } + } + + // + isTPowVerified = + above20TPowers < 1 + && tPowUnverifyConditions == 0 + && MathAbs(xTPow0.powerUp - xTPow0.powerDown) > 50 * _Point + ; + + // + isStateVerified = + // + // Start ... + true + // + // && (xStateLast.verifier - xState0.verifier) >= 0 + // + && xState0.verifier > signal.entry + // + && MathAbs(signal.entry - xState0.verifier) < (xSharpDetectorFactor * _Point) + ; + + // + result = + // + // Starter Condition ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } + + // + return result; +} +// +// END Functions ... +// + +// +// START Data Provider ... +// +XMarketState GetXMarketState( + const int bar_index +) { + // + XMarketState result = {}; + + // + double fast = GetMA( + bar_index, + xSwingLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double open = GetMA( + bar_index, + xSwingLength, + 0, + MODE_SMA, + PRICE_OPEN + ); + + // + double slow = GetMA( + bar_index, + xSwingLength * 2, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double oscillator = GetMA( + bar_index, + xSwingLength, + 0, + MODE_EMA, + PRICE_CLOSE + ); + + // + double oscillatorVerifier = GetMA( + bar_index, + xSwingLength, + 0, + MODE_EMA, + PRICE_WEIGHTED + ); + + // + int dailyCount = GetDailyCandleCount(); + double verifier = GetMA( + bar_index, + dailyCount, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double psar = iSAR( + _Symbol, + _Period, + xPSarStep, + xPSarMaximum, + bar_index + ); + + // + result.psar = psar; + result.fast = fast; + result.open = open; + result.slow = slow; + result.verifier = verifier; + result.oscillator = oscillator; + result.oscillatorVerifier = oscillatorVerifier; + + // + return result; +} +// +// END Data Provider ... +// diff --git a/xLibraries/x-saherelm.xr.signal.lib.mq4 b/xLibraries/x-saherelm.xr.signal.lib.mq4 new file mode 100644 index 0000000..d4ae238 --- /dev/null +++ b/xLibraries/x-saherelm.xr.signal.lib.mq4 @@ -0,0 +1,1142 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 X Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Inputs ... +// +// +input string xRStarter = "- XR Signal Provider -"; // --> XR Signal Provider <-- + +// +input bool enableXRSignalling = true; // XR Signalling Enable + +// +input bool enableXRLong = true; // XR Signalling Enable Long +input bool enableXRShort = true; // XR Signalling Enable Short + +// +input double xRShortR2R = 1.5; // XR Short Risk To Reward Ratio +input double xRShortLotsPerTradePercent = 0.0002; // XR Lots Percent per Short Trades +input double xRShortMaxDrawdownPerTradePercent = 0.15; // XR Max Allowed DrawDown Percent per Short Trade + +// +input double xRLongR2R = 1.5; // XR Long Risk To Reward Ratio +input double xRLongLotsPerTradePercent = 0.0002; // XR Lots Percent per Short Trades +input double xRLongMaxDrawdownPerTradePercent = 0.15; // XR Max Allowed DrawDown Percent per Long Trade + +// +input int xRMaximumCandlesPerTrade = 96; // XR Maximum Candles which a Trade can open + +// +input int xRSwingLength = 48; // XR Swing Length +// +// END Inputs ... +// + +// +input double xRSharpDetectionFactor = 1350; // XR Sharp Detection Factor + +// +// START Global Requirement Functions ... +// +// +// XR Market State ... +struct XRMarketState { + // + double fast; + double slow; + double open; + + // + double range; + double rangeFast; + double rangeSlow; + double rangeOpen; + + // + double verifier; +}; + +// +// XR Based Signal Conditions ... +struct XRSignalConditions { + datetime startTime; + datetime signalTime; + datetime entryTime; +}; + +// +static XRSignalConditions xRLongConds; +static bool xRCloseLongTrades = false; +static bool xRWaitForLongSignals = true; + +// +static XRSignalConditions xRShortConds; +static bool xRCloseShortTrades = false; +static bool xRWaitForShortSignals = true; + +// +// Count Number of Closed Maximum DrawDown Trades ... +static int xRFailedSignals = 0; + +// +double xRMaximumDrawDown = 0; + +// +int fastLength = 0; +int slowLength = 0; + +// +int verifierLength = 0; + +// +int rangeFastLength = 0; +int rangeSlowLength = 0; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckXRSignalHandler( + const int bar_index +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + + // + if ( + !enableXRSignalling + || !(enableXRLong || enableXRShort) + ) { + return; + } +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXRLongSignalConditions( + const int bar_index +) { + // + if ( + !enableXRLong + || !enableXRSignalling + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Read Prices ... + XPrice prices = GetPrice(); + + // + // Read XPVTState ... + XPvtState pvt0 = GetPVTState( + bar_index, + xRSwingLength + ); + + // + // Double Length Pivots ... + XPvtState dblPvt0 = GetPVTState( + bar_index, + (xRSwingLength * 2) + ); + + // + // Reading Required Candles ... + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + XOHCL candle3 = GetCandleModel(bar_index + 3); + + // + // Reding Required XRMarketStates ... + XRMarketState state0 = GetXRMarketState(bar_index); + XRMarketState state1 = GetXRMarketState(bar_index + 1); + XRMarketState state2 = GetXRMarketState(bar_index + 2); + XRMarketState state3 = GetXRMarketState(bar_index + 3); + + // + // Reading required XRangeStates ... + XRState range0 = ReadXRange( + bar_index + xRSwingLength, + xRSwingLength + ); + XRState range1 = ReadXRange( + bar_index + xRSwingLength + 1, + xRSwingLength + ); + XRState range2 = ReadXRange( + bar_index + xRSwingLength + 2, + xRSwingLength + ); + + // + XRState cRange0 = ReadXRange( + bar_index, + xRSwingLength + ); + + // + // Validate Farest Range Values ... + if ( + range2.hh == 0 + || + range2.ll == 0 + || + range2.mid == 0 + ) { + return; + } + + // + // Reading Required XTPowStates ... + XTPOWState tPow0 = GetXTPowState( + bar_index, + xRSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xRSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xRSwingLength + ); + + // + // if state verifier below range middle + // this means market is bullish ... + // + // if state verifier above range middle + // this means market is bearish ... + // + + // + bool isMarketBullish = + state0.verifier < range0.mid + && state1.verifier < range1.mid; + bool isMarketBearish = + state0.verifier > range0.mid + && state1.verifier > range1.mid; + bool isMarketGoingBullish = + state0.verifier > range0.mid + && !(state1.verifier > range1.mid); + bool isMarketGoingBearish = + state0.verifier < range0.mid + && !(state1.verifier < range1.mid); + + // + // Check Highest High Conditions ... + bool isHHVerified = + !( + pvt0.hh == dblPvt0.hh + ) + ; + + // + int sharpDetectionLength = 7; + double sharpDetectionValue = xRSharpDetectionFactor * _Point; + + // + int sharpHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + sharpDetectionLength, + bar_index + ); + double sharpHH = iHigh( + _Symbol, + _Period, + sharpHHIdx + ); + + // + int sharpLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + sharpDetectionLength, + bar_index + ); + double sharpLL = iLow( + _Symbol, + _Period, + sharpLLIdx + ); + + // + double sharpDiff = sharpHH - sharpLL; + bool isSharpOccered = + sharpDiff > sharpDetectionValue; + + // + XRMarketState lastState = GetXRMarketState( + bar_index + sharpDetectionLength + ); + + // + double stateFSDiff = (state0.fast - state0.slow) - (lastState.fast - lastState.slow); + + // + // Start Calculating Long Conditions ... + bool longCondition1 = + // + // Starter ... + true + // + && isMarketBullish + // + && + ( + candle2.high < range2.mid + || ( + candle2.high > range2.mid + && candle2.low < range2.mid + ) + ) + && candle1.low > range1.mid + ; + + // + if ( + // + ( + longCondition1 + ) + // + && xRLongConds.startTime == 0 + && xRLongConds.entryTime == 0 + && xRLongConds.signalTime == 0 + ) { + // + xRLongConds.startTime = barTime; + xRLongConds.entryTime = barTime; + xRLongConds.signalTime = barTime; + + // + return; + } +} + +// +// Check and Fill Short Signal Conditions ... +void CheckXRShortSignalConditions( + const int bar_index +) { + // + if ( + !enableXRShort + || !enableXRSignalling + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Read Prices ... + XPrice prices = GetPrice(); + + // + // Read XPVTState ... + XPvtState pvt0 = GetPVTState( + bar_index, + xRSwingLength + ); + + // + // Double Length Pivots ... + XPvtState dblPvt0 = GetPVTState( + bar_index, + (xRSwingLength * 2) + ); + + // + // Reading Required Candles ... + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + XOHCL candle3 = GetCandleModel(bar_index + 3); + + // + // Reding Required XRMarketStates ... + XRMarketState state0 = GetXRMarketState(bar_index); + XRMarketState state1 = GetXRMarketState(bar_index + 1); + XRMarketState state2 = GetXRMarketState(bar_index + 2); + XRMarketState state3 = GetXRMarketState(bar_index + 3); + + // + // Reading required XRangeStates ... + XRState range0 = ReadXRange( + bar_index + xRSwingLength, + xRSwingLength + ); + XRState range1 = ReadXRange( + bar_index + xRSwingLength + 1, + xRSwingLength + ); + XRState range2 = ReadXRange( + bar_index + xRSwingLength + 2, + xRSwingLength + ); + + // + XRState cRange0 = ReadXRange( + bar_index, + xRSwingLength + ); + + // + // Validate Farest Range Values ... + if ( + range2.hh == 0 + || + range2.ll == 0 + || + range2.mid == 0 + ) { + return; + } + + // + // Reading Required XTPowStates ... + XTPOWState tPow0 = GetXTPowState( + bar_index, + xRSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xRSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xRSwingLength + ); + + // + // if state verifier below range middle + // this means market is bullish ... + // + // if state verifier above range middle + // this means market is bearish ... + // + + // + bool isMarketBullish = + state0.verifier < range0.mid + && state1.verifier < range1.mid; + bool isMarketBearish = + state0.verifier > range0.mid + && state1.verifier > range1.mid; + bool isMarketGoingBullish = + state0.verifier > range0.mid + && !(state1.verifier > range1.mid); + bool isMarketGoingBearish = + state0.verifier < range0.mid + && !(state1.verifier < range1.mid); + + // + // Check Highest High Conditions ... + bool isHHVerified = + !( + pvt0.hh == dblPvt0.hh + ) + ; + + // + int sharpDetectionLength = 7; + double sharpDetectionValue = xRSharpDetectionFactor * _Point; + + // + int sharpHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + sharpDetectionLength, + bar_index + ); + double sharpHH = iHigh( + _Symbol, + _Period, + sharpHHIdx + ); + + // + int sharpLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + sharpDetectionLength, + bar_index + ); + double sharpLL = iLow( + _Symbol, + _Period, + sharpLLIdx + ); + + // + double sharpDiff = sharpHH - sharpLL; + bool isSharpOccered = + sharpDiff > sharpDetectionValue; + + // + XRMarketState lastState = GetXRMarketState( + bar_index + sharpDetectionLength + ); + + // + double stateFSDiff = (state0.fast - state0.slow) - (lastState.fast - lastState.slow); + + // + // Start Calculating Long Conditions ... + bool shortCondition1 = + // + // Starter ... + true + // + && isMarketBearish + // + && + ( + candle2.low > range2.mid + || ( + candle2.high > range2.mid + && candle2.low < range2.mid + ) + ) + && candle1.high < range1.mid + ; + + // + if ( + // + ( + shortCondition1 + ) + // + && xRShortConds.startTime == 0 + && xRShortConds.entryTime == 0 + && xRShortConds.signalTime == 0 + ) { + // + xRShortConds.startTime = barTime; + xRShortConds.entryTime = barTime; + xRShortConds.signalTime = barTime; + + // + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXRSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if ( + !enableXRSignalling + || !(enableXRLong || enableXRShort) + ) { + return result; + } + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + if (requestLong) { + // + if ( + !ValidateXRLongConditions() + ) { + return result; + } + } else { + // + if ( + !ValidateXRShortConditions() + ) { + return result; + } + } + + // + // Price Calculations ... + XPvtState pvts = GetPVTState( + bar_index, + xRSwingLength + ); + XPrice prices = GetPrice(); + + // + double entryPrice = requestLong ? + prices.longEntry : + prices.shortEntry + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = requestLong ? + MathMin(openPrice, closePrice) - pvts.ll : + pvts.hh - MathMax(openPrice, closePrice); + if (risk <= 0) { + // + risk = requestLong ? + MathAbs(pvts.hh - entryPrice) : + MathAbs(pvts.ll - entryPrice) + ; + } + + // + double reward = + requestLong ? + risk * xRLongR2R : + risk * xRShortR2R + ; + + // + double sl = requestLong ? + 0 : + 0; + + // + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward + ; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XR_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XR_PROVIDER; + + // + return result; +} + +// +// Validate Long Signal Conditions ... +bool ValidateXRLongConditions() { + // + if ( + !enableXRLong + || !enableXRSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xRLongConds.startTime > 0 + && xRLongConds.signalTime > 0 + && xRLongConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + isBLFilled = + // + xRLongConds.signalTime >= xRLongConds.startTime + && xRLongConds.entryTime >= xRLongConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xRWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXRLongSignalConditions(); + } + + // + return result; +} + +// +// Validate Short Signal Conditions ... +bool ValidateXRShortConditions() { + // + if ( + !enableXRShort + || !enableXRSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xRShortConds.startTime > 0 + && xRShortConds.signalTime > 0 + && xRShortConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + isBLFilled = + // + xRShortConds.signalTime >= xRShortConds.startTime + && xRShortConds.entryTime >= xRShortConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xRWaitForShortSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXRShortSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXRLongSignalConditions() { + // + xRLongConds.startTime = 0; + xRLongConds.signalTime = 0; + xRLongConds.entryTime = 0; +} + +// +// Clear Short Signal Conditions for New One ... +void ClearXRShortSignalConditions() { + // + xRShortConds.startTime = 0; + xRShortConds.signalTime = 0; + xRShortConds.entryTime = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForXRSignals( + const XSignal &signal +) { + // + bool result = false; + + // + if ( + !enableXRSignalling + || !(enableXRLong || enableXRShort) + ) { + return result; + } + + // + // Find Signal Bar Index ... + int signalBarIndex = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // Read Prices ... + XPrice prices = GetPrice(); + + // + // Read XPVTState ... + XPvtState pvt0 = GetPVTState( + signalBarIndex, + xRSwingLength + ); + + // + // Reading Required Candles ... + XOHCL candle0 = GetCandleModel(signalBarIndex); + XOHCL candle1 = GetCandleModel(signalBarIndex + 1); + XOHCL candle2 = GetCandleModel(signalBarIndex + 2); + XOHCL candle3 = GetCandleModel(signalBarIndex + 3); + + // + // Reding Required XRMarketStates ... + XRMarketState state0 = GetXRMarketState(signalBarIndex); + XRMarketState state1 = GetXRMarketState(signalBarIndex + 1); + XRMarketState state2 = GetXRMarketState(signalBarIndex + 2); + XRMarketState state3 = GetXRMarketState(signalBarIndex + 3); + + // + // Reading required XRangeStates ... + XRState range0 = ReadXRange( + signalBarIndex + xRSwingLength, + xRSwingLength + ); + XRState range1 = ReadXRange( + signalBarIndex + xRSwingLength + 1, + xRSwingLength + ); + XRState range2 = ReadXRange( + signalBarIndex + xRSwingLength + 2, + xRSwingLength + ); + + // + // Reading Required XTPowStates ... + XTPOWState tPow0 = GetXTPowState( + signalBarIndex, + xRSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + signalBarIndex + 1, + xRSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + signalBarIndex + 2, + xRSwingLength + ); + + // + double hhllDiff = MathAbs(pvt0.hh - pvt0.ll); + double sharpDetectionValue = xRSharpDetectionFactor * _Point; + bool isSharpOccured = hhllDiff > sharpDetectionValue; + + // + // Calculate State Min Max Diff ... + // + double state0Min = MathMin(state0.fast, state0.slow); + state0Min = MathMin(state0Min, state0.open); + state0Min = MathMin(state0Min, state0.rangeFast); + state0Min = MathMin(state0Min, state0.rangeSlow); + state0Min = MathMin(state0Min, state0.rangeOpen); + state0Min = MathMin(state0Min, state0.verifier); + + // + double state0Max = MathMax(state0.fast, state0.slow); + state0Max = MathMax(state0Max, state0.open); + state0Max = MathMax(state0Max, state0.rangeFast); + state0Max = MathMax(state0Max, state0.rangeSlow); + state0Max = MathMax(state0Max, state0.rangeOpen); + state0Max = MathMax(state0Max, state0.verifier); + + // + double state0MinMaxDiff = (state0Max - state0Min); + + // + bool isTPowValid = false; + bool isStateValid = false; + bool isRangeValid = false; + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + // Retrieve TPow Verifications ... + isTPowValid = + // + // Starter ... + true + ; + + // + // Retrieve XMarket Verifications ... + isStateValid = + // + // Starter ... + true + // + // && !(state0MinMaxDiff > sharpDetectionValue) + ; + + // + // Retrieve XRange Verifications ... + isRangeValid = + // + // Starter ... + true + ; + + // + result = + // + // Starter ... + true + // + && isTPowValid + && isStateValid + && isRangeValid + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + // Retrieve TPow Verifications ... + isTPowValid = + // + // Starter ... + true + ; + + // + // Retrieve XMarket Verifications ... + isStateValid = + // + // Starter ... + true + ; + + // + // Retrieve XRange Verifications ... + isRangeValid = + // + // Starter ... + true + ; + + // + result = + // + // Starter ... + true + // + && isTPowValid + && isStateValid + && isRangeValid + ; + } + + // + return result; +} +// +// END Functions ... +// + +// +// START Data Providers ... +// +// +XRMarketState GetXRMarketState( + const int bar_index +) { + // + XRMarketState result = {}; + + // + // Calculate Market Lengths ... + + // + if (fastLength == 0) { + fastLength = xRSwingLength; + } + + // + if (slowLength == 0) { + slowLength = xRSwingLength * 2; + } + + // + if (verifierLength == 0) { + verifierLength = (GetDailyCandleCount() * 2); + } + + // + if (rangeFastLength == 0) { + rangeFastLength = (int)(verifierLength / 2); + } + + // + if (rangeSlowLength == 0) { + rangeSlowLength = verifierLength; + } + + // + // Reading Values ... + + // + double fast = GetMA( + bar_index, + fastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double slow = GetMA( + bar_index, + slowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double open = GetMA( + bar_index, + fastLength, + 0, + MODE_SMA, + PRICE_OPEN + ); + + // + double rangeFast = GetMA( + bar_index, + rangeFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double rangeSlow = GetMA( + bar_index, + rangeSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double rangeOpen = GetMA( + bar_index, + rangeFastLength, + 0, + MODE_SMA, + PRICE_OPEN + ); + + // + double verifier = GetMA( + bar_index, + verifierLength, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + // Filling Result ... + result.fast = fast; + result.slow = slow; + result.open = open; + result.verifier = verifier; + result.rangeFast = rangeFast; + result.rangeSlow = rangeSlow; + result.rangeOpen = rangeOpen; + + // + return result; +} +// +// END Data Providers ... +// \ No newline at end of file diff --git a/xLibraries/x-saherelm.xtpw.signal.lib.mq4 b/xLibraries/x-saherelm.xtpw.signal.lib.mq4 new file mode 100644 index 0000000..4bf02ce --- /dev/null +++ b/xLibraries/x-saherelm.xtpw.signal.lib.mq4 @@ -0,0 +1,1332 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 XTPW Signal Global Library +// --------------------------------------------------- +// XSaherElm EA Signal Provider based on +// XTPow Indicator... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Inputs ... +// +// +input string xTPWStarter = "- XTPW Signal Provider -"; // ---> XTPW Signal Provider <--- + +// +input bool enableXTPWSignalling = true; // XTPW Signalling Enable + +// +input bool enableXTPWLong = true; // XTPW Signalling Enable Long +input bool enableXTPWShort = true; // XTPW Signalling Enable Short + +// +input double xTPWShortR2R = 2; // XTPW Short Risk To Reward Ratio +input double xTPWShortLotsPerTradePercent = 0.0002; // XTPW Lots Percent per Short Trades +input double xTPWShortMaxDrawdownPerTradePercent = 0.3; // XTPW Max Allowed DrawDown Percent per Short Trade + +// +input double xTPWLongR2R = 2; // XTPW Long Risk To Reward Ratio +input double xTPWLongLotsPerTradePercent = 0.0002; // XTPW Lots Percent per Short Trades +input double xTPWLongMaxDrawdownPerTradePercent = 0.3; // XTPW Max Allowed DrawDown Percent per Long Trade + +// +input int xTPWMaximumCandlesPerTrade = 206; // XTPW Maximum Candles which a Trade can open + +// +input double xTPWPSarStep = 0.02; // XTPW Parabolic Sar Step +input double xTPWPSarMaximum = 0.2; // XTPW Parabolic Sar Maximum + +// +input int xTPWSwingLength = 7; // XTPW Signal Swing Length +// +// END Inputs ... +// + +// +input double xTPWSharpDetectionFactor = 650; // XTPW Sharp Detection Factor + +// +// START Global Requirement Functions ... +// +// +// XTPW Based Signal Conditions ... +struct XTPWSignalConditions { + datetime startTime; + datetime signalTime; + datetime entryTime; +}; + +// +struct XTPWMarketState { + // + double psar; + + // + double scFast; + double scSlow; + double scWeight; + + // + double mcFast; + double mcSlow; + double mcWeight; + + // + double lcFast; + double lcSlow; + double lcWeight; +}; + +// +struct XLHS { + // + double scHH; + double scLL; + + // + double mcHH; + double mcLL; + + // + double lcHH; + double lcLL; +}; + +// +static XTPWSignalConditions xTPWLongConds; +static bool xTPWCloseLongTrades = false; +static bool xTPWWaitForLongSignals = true; + +// +static XTPWSignalConditions xTPWShortConds; +static bool xTPWCloseShortTrades = false; +static bool xTPWWaitForShortSignals = true; + +// +// Count Number of Closed Maximum DrawDown Trades ... +static int xTPWFailedSignals = 0; + +// +double tPowerVerifier = 20; +double tPowerMaxVerifier = 55; + +// +int scFastLength = 0; +int scSlowLength = 0; + +// +int mcFastLength = 0; +int mcSlowLength = 0; + +// +int lcFastLength = 0; +int lcSlowLength = 0; + +// +datetime lastTurnOffLongTradesTime; +datetime lastTurnOffShortTradesTime; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckXTPWSignalHandler( + const int bar_index +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + + // + if ( + !enableXTPWSignalling + || !(enableXTPWLong || enableXTPWShort) + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 1); + + // + XTPOWState tPow0 = GetXTPowState( + bar_index, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xTPWSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xTPWSwingLength + ); + + // + XTPWMarketState state0 = GetXTPWMarketState( + bar_index + ); + XTPWMarketState state1 = GetXTPWMarketState( + bar_index + 1 + ); + XTPWMarketState state2 = GetXTPWMarketState( + bar_index + 2 + ); + + // // + // // Disable Long Conditions ... + // if ( + // xTPWWaitForLongSignals + // && + // ( + // isRangeCrossOverRangeWeight + // || + // isRangeCrossUnderRangeWeight + // || + // isTPowUpperAboveMaxVerifier + // ) + // ) { + // // + // xTPWWaitForLongSignals = false; + // lastTurnOffLongTradesTime = barTime; + // } + + // // + // // Enable Long Conditions ... + // if ( + // !xTPWWaitForLongSignals + // && lastTurnOffLongTradesTime > 0 + // && ( + // // isFastCrossOverSlow + // // || + // // isFastCrossUnderSlow + // isRangeCrossOverRangeWeight + // || + // isRangeCrossUnderRangeWeight + // || + // isTPowUpperBelowMaxVerifier + // ) + // ) { + // // + // // Find Last Turn Off Bar Index ... + // int lastTurnOffLongTradesBarIndex = iBarShift( + // _Symbol, + // _Period, + // lastTurnOffLongTradesTime + // ); + + // // + // // the Distance must be bigger than market length ... + // if (MathAbs(lastTurnOffLongTradesBarIndex - bar_index) > xTPWSwingLength) { + // // + // xTPWWaitForLongSignals = true; + // lastTurnOffLongTradesTime = 0; + // } + // } +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXTPWLongSignalConditions( + const int bar_index +) { + // + if ( + !enableXTPWLong + || !enableXTPWSignalling + || !xTPWWaitForLongSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Retrieve TPow States ... + XTPOWState tPow0 = GetXTPowState( + bar_index, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xTPWSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xTPWSwingLength + ); + + // + // Retrieve TPowMarket State ... + XTPWMarketState state0 = GetXTPWMarketState( + bar_index + ); + XTPWMarketState state1 = GetXTPWMarketState( + bar_index + 1 + ); + XTPWMarketState state2 = GetXTPWMarketState( + bar_index + 2 + ); + + // + // Retrieve XPrice Model ... + XPrice prices = GetPrice(); + + // + // Retrieve Candles ... + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + + // + XLHS lhs = GetXTPWLHS(bar_index); + + // + bool isHHSame = + lhs.scHH == lhs.mcHH + && lhs.mcHH == lhs.lcHH + ; + + // + bool isLLSame = + lhs.scLL == lhs.mcLL + && lhs.mcLL == lhs.lcLL + ; + + // + bool startCondition = false; + bool signalCondition = false; + bool entryCondition = false; + + // + bool longCondition1 = + // + true + // + && !isHHSame + // + && !( + lhs.scLL == lhs.mcLL + ) + // + && !( + lhs.scHH == lhs.mcHH + ) + // + && !( + prices.longEntry + && candle0.high < state0.scFast + && candle0.high < state0.scSlow + && candle0.high < state0.mcFast + && candle0.high < state0.mcSlow + && candle0.high < state0.lcFast + && candle0.high < state0.lcSlow + ) + // + && tPow0.powerDown > tPowerMaxVerifier + && tPow1.powerDown > tPowerMaxVerifier + && tPow0.powerDown < MathMax(tPow1.powerUp, tPow1.powerDown) + && MathMax(tPow1.powerUp, tPow1.powerDown) > tPowerMaxVerifier + ; + + // + // Start Conditions ... + startCondition = ( + longCondition1 + ) + ; + + // + if ( + startCondition + && xTPWLongConds.startTime == 0 + && xTPWLongConds.signalTime == 0 + && xTPWLongConds.entryTime == 0 + ) { + // + xTPWLongConds.startTime = barTime; + xTPWLongConds.signalTime = barTime; + xTPWLongConds.entryTime = barTime; + + // + return; + } +} + +// +// Check and Fill Short Signal Conditions ... +void CheckXTPWShortSignalConditions( + const int bar_index +) { + // + if ( + !enableXTPWShort + || !enableXTPWSignalling + || !xTPWWaitForShortSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Retrieve TPower State ... + XTPOWState tPow0 = GetXTPowState( + bar_index, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xTPWSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xTPWSwingLength + ); + + // + // Retrieve TPWMarket State ... + XTPWMarketState state0 = GetXTPWMarketState( + bar_index + ); + XTPWMarketState state1 = GetXTPWMarketState( + bar_index + 1 + ); + XTPWMarketState state2 = GetXTPWMarketState( + bar_index + 2 + ); + + // + // Retrieve Candles ... + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + + // + XPrice prices = GetPrice(); + XLHS lhs = GetXTPWLHS(bar_index); + + // + double sharpDetectionValue = + xTPWSharpDetectionFactor * _Point; + + // + bool isHHSame = + lhs.scHH == lhs.mcHH + && lhs.mcHH == lhs.lcHH + ; + + // + bool isLLSame = + lhs.scLL == lhs.mcLL + && lhs.mcLL == lhs.lcLL + ; + + // + bool startCondition = false; + bool signalCondition = false; + bool entryCondition = false; + + // + bool shortCondition1 = + // + true + // + && tPow1.powerDown > tPowerMaxVerifier + && tPow2.powerDown < tPowerMaxVerifier + ; + + // + startCondition = ( + shortCondition1 + ) + ; + + // + if ( + startCondition + && xTPWShortConds.startTime == 0 + && xTPWShortConds.signalTime == 0 + && xTPWShortConds.entryTime == 0 + ) { + // + xTPWShortConds.startTime = barTime; + xTPWShortConds.signalTime = barTime; + xTPWShortConds.entryTime = barTime; + + // + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXTPWSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if ( + !enableXTPWSignalling + || !(enableXTPWLong || enableXTPWShort) + ) { + return result; + } + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + // Check Condition Validations ... + if (requestLong) { + // + // Check Long Condtion is Valid, if Long Requested ... + if ( + !ValidateXTPWLongConditions() + ) { + return result; + } + } else { + // + // Check Short Condtion is Valid, if Short Requested ... + if ( + !ValidateXTPWShortConditions() + ) { + return result; + } + } + + // + double ll = + // + GetMarketLowestLow( + bar_index, + xTPWSwingLength + ) + ; + + // + double hh = + // + GetMarketHighestHigh( + bar_index, + xTPWSwingLength + ) + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + // Price Calculations ... + XPrice prices = GetPrice(); + + // + // Read State ... + XTPWMarketState state0 = GetXTPWMarketState(bar_index); + + // + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + XOHCL candle3 = GetCandleModel(bar_index + 2); + + // + double risk = requestLong ? + // + MathMin(openPrice, closePrice) - ll : + hh - MathMax(openPrice, closePrice) + ; + + // + double longR2R = xTPWLongR2R; + double shortR2R = xTPWShortR2R; + + // + double sharpDetectorValue = xTPWSharpDetectionFactor * _Point; + + // + if ( + risk > 0 + && requestLong + ) { + return result; + } + + // + // Define Entry Price ... + double entryPrice = requestLong + ? + prices.longEntry + : + prices.shortEntry + ; + + // + // Fix TP Detects for Short Signals ... + if (!requestLong) { + risk = 0; + } + + // + double reward = requestLong ? + risk * longR2R : + risk * shortR2R + ; + + // + if (risk == 0) { + // + // Calculate Reward ... + reward = requestLong + ? + MathAbs(hh - entryPrice) + : + MathAbs(hh - entryPrice) + ; + + // + // Detect Sharp Change Occured or not ... + bool isSharpOccured = reward > sharpDetectorValue + || MathAbs(reward - sharpDetectorValue) < (50 * _Point); + + // + // Change Rewards on Special Conditions ... + if ( + ( + requestLong + && isSharpOccured + && ( + state0.lcFast < state0.lcSlow + || ( + state0.mcFast > state0.mcSlow + && state0.mcWeight < state0.mcSlow + ) + ) + ) + ) { + reward = reward / 2; + } + + // + if (reward < 50 * _Point) { + reward = (50 * _Point) + prices.priceGap; + } + + // // + // if (!requestLong) { + // reward = reward * shortR2R; + // } + } + + // + double sl = requestLong ? + 0 : + 0; + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward + ; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XTPW_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XTPW_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXTPWLongConditions() { + // + if ( + !enableXTPWLong + || !enableXTPWSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xTPWLongConds.startTime > 0 + && xTPWLongConds.signalTime > 0 + && xTPWLongConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // // + // int startBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWLongConds.startTime + // ); + + // // + // int signalBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWLongConds.signalTime + // ); + + // // + // int entryBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWLongConds.entryTime + // ); + + // // + // int startSignalDiff = (signalBarIndex - startBarIndex); + // int entrySignalDiff = (entryBarIndex - signalBarIndex); + // int maxDiff = MathMax(startSignalDiff, entrySignalDiff); + + // + isBLFilled = + // + // Starter ... + true + // + && xTPWLongConds.signalTime >= xTPWLongConds.startTime + && xTPWLongConds.entryTime >= xTPWLongConds.signalTime + // + // && maxDiff < (xTPWSwingLength * 2) + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xTPWWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXTPWLongSignalConditions(); + } + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXTPWShortConditions() { + // + if ( + !enableXTPWShort + || !enableXTPWSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xTPWShortConds.startTime > 0 + && xTPWShortConds.signalTime > 0 + && xTPWShortConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // // + // int startBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWShortConds.startTime + // ); + + // // + // int signalBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWShortConds.signalTime + // ); + + // // + // int entryBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWShortConds.entryTime + // ); + + // + isBLFilled = + // + // Starter ... + true + // + && xTPWShortConds.signalTime >= xTPWShortConds.startTime + && xTPWShortConds.entryTime >= xTPWShortConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xTPWWaitForShortSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXTPWShortSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXTPWLongSignalConditions() { + // + xTPWLongConds.startTime = 0; + xTPWLongConds.entryTime = 0; + xTPWLongConds.signalTime = 0; +} + +// +// Clear Short Signal Conditions for New One ... +void ClearXTPWShortSignalConditions() { + // + xTPWShortConds.startTime = 0; + xTPWShortConds.entryTime = 0; + xTPWShortConds.signalTime = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForXTPWSignals( + const XSignal &signal +) { + // + bool result = false; + + // + if ( + !enableXTPWSignalling + || !(enableXTPWLong || enableXTPWShort) + ) { + return result; + } + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // XOHCL candle = GetCandleModel(0); + XOHCL candle0 = GetCandleModel(signalBarIndex); + XOHCL candle1 = GetCandleModel(signalBarIndex + 1); + + // + // Retrieve TPow State ... + XTPOWState tPow0 = GetXTPowState( + signalBarIndex, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + signalBarIndex + 1, + xTPWSwingLength + ); + + // + // Retrive XMarket States ... + XTPWMarketState state0 = GetXTPWMarketState(signalBarIndex); + XTPWMarketState state1 = GetXTPWMarketState(signalBarIndex + 1); + XTPWMarketState state2 = GetXTPWMarketState(signalBarIndex + 2); + + // + bool isPSarVerified = false; + bool isTPowVerified = false; + bool isStateVerified = false; + bool isPriceVerified = false; + + // + // Calculate Sharp Detection Value ... + double sharpDetectionValue = + xTPWSharpDetectionFactor * _Point; + + // + // Find State0 Min ... + double state0Min = MathMin(state0.scFast, state0.scSlow); + state0Min = MathMin(state0Min, state0.mcFast); + state0Min = MathMin(state0Min, state0.mcSlow); + state0Min = MathMin(state0Min, state0.lcFast); + state0Min = MathMin(state0Min, state0.lcSlow); + + // + // Find State0 Min ... + double state0Max = MathMax(state0.scFast, state0.scSlow); + state0Max = MathMax(state0Max, state0.mcFast); + state0Max = MathMax(state0Max, state0.mcSlow); + state0Max = MathMax(state0Max, state0.lcFast); + state0Max = MathMax(state0Max, state0.lcSlow); + + // + // Find Distance Between State0 Min and Max ... + double state0MinMaxDistance = MathAbs(state0Max - state0Min); + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + // Get Price Verification for Long ... + isPriceVerified = + // + // Starter ... + true + // + ; + + // + isTPowVerified = + // + // Starter ... + true + // + && tPow0.powerDown > tPowerMaxVerifier + && tPow1.powerDown > tPowerMaxVerifier + && tPow0.powerDown < MathMax(tPow1.powerUp, tPow1.powerDown) + && MathMax(tPow1.powerUp, tPow1.powerDown) > tPowerMaxVerifier + ; + + // + isPSarVerified = + // + // Starter ... + true + // + ; + + // + isStateVerified = + // + // Start ... + true + // + && state0.mcFast > state0.mcSlow + && state1.mcFast > state1.mcSlow + // + && !( + state0.lcFast > state0.mcSlow + && state0.lcFast < state0.mcFast + ) + // + && MathAbs(state1.mcFast - state1.mcSlow) > (50 * _Point) + ; + + // + result = + // + // Starter ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + isPSarVerified = + // + // Starter ... + true + ; + + // + // Get Price Verification for Short ... + isPriceVerified = + // + // Starter ... + true + ; + + // + isTPowVerified = + // + // Starter ... + true + // + && tPow0.signal > MathMax(tPow0.powerUp, tPow0.powerDown) + ; + + // + isStateVerified = + // + // Start ... + true + // + && ( + // + state0.scFast < state0.scSlow + && state0.mcFast < state0.mcSlow + && state0.lcFast < state0.lcSlow + ? + signal.entry > state0.scFast + : + // + // Find Minimum and Maximum Distance of State ... + state0MinMaxDistance > sharpDetectionValue + ? + signal.entry > state0Min + : + true + ) + // + && MathAbs(state0.mcFast - state0.mcSlow) > 50 * _Point + ; + + // + result = + // + // Starter Condition ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } + + // + return result; +} +// +// END Functions ... +// + +// +// START Data Provider ... +// +// +// Retrieve Market State ... +XTPWMarketState GetXTPWMarketState( + const int bar_index +) { + // + XTPWMarketState result = {}; + + // + int dayCount = GetDailyCandleCount(); + int halfDayCount = (int)(dayCount / 2); + + // + if (scFastLength == 0) { + scFastLength = xTPWSwingLength; + } + + // + if (scSlowLength == 0) { + scSlowLength = xTPWSwingLength * 2; + } + + // + if (mcFastLength == 0) { + mcFastLength = halfDayCount; + } + + // + if (mcSlowLength == 0) { + mcSlowLength = dayCount; + } + + // + if (lcFastLength == 0) { + lcFastLength = halfDayCount * 3; + } + + // + if (lcSlowLength == 0) { + lcSlowLength = dayCount * 3; + } + + // + double scFast = GetMA( + bar_index, + scFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double scSlow = GetMA( + bar_index, + scSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double scWeight = GetMA( + bar_index, + scSlowLength, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double mcFast = GetMA( + bar_index, + mcFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double mcSlow = GetMA( + bar_index, + mcSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double mcWeight = GetMA( + bar_index, + mcSlowLength, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double lcFast = GetMA( + bar_index, + lcFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double lcSlow = GetMA( + bar_index, + lcSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double lcWeight = GetMA( + bar_index, + lcSlowLength, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double psar = iSAR( + _Symbol, + _Period, + xTPWPSarStep, + xTPWPSarMaximum, + bar_index + ); + + // + result.psar = psar; + result.scFast = scFast; + result.scSlow = scSlow; + result.mcFast = mcFast; + result.mcSlow = mcSlow; + result.lcFast = lcFast; + result.lcSlow = lcSlow; + result.scWeight = scWeight; + result.mcWeight = mcWeight; + result.lcWeight = lcWeight; + + // + return result; +} + +// +// Retrieve Highest Highs and Lowest Lows in Cycles ... +XLHS GetXTPWLHS( + const int bar_index +) { + // + XLHS result = {}; + + // + // Retrieve LL and HH (s) ... + + // + // SC HH ... + double scHH = GetMarketHighestHigh( + bar_index, + scFastLength + ); + + // + // SC LL ... + double scLL = GetMarketHighestHigh( + bar_index, + scFastLength + ); + + // + // MC HH ... + double mcHH = GetMarketHighestHigh( + bar_index, + mcFastLength + ); + + // + // MC LL ... + double mcLL = GetMarketHighestHigh( + bar_index, + mcFastLength + ); + + // + // LC HH ... + double lcHH = GetMarketHighestHigh( + bar_index, + lcFastLength + ); + + // + // LC LL ... + double lcLL = GetMarketHighestHigh( + bar_index, + lcFastLength + ); + + // + result.scHH = scHH; + result.scLL = scLL; + result.mcHH = mcHH; + result.mcLL = mcLL; + result.lcHH = lcHH; + result.lcLL = lcLL; + + // + return result; +} +// +// END Data Provider ... +// diff --git a/xSamples/ATR.mq4 b/xSamples/ATR.mq4 new file mode 100644 index 0000000..026565c --- /dev/null +++ b/xSamples/ATR.mq4 @@ -0,0 +1,104 @@ +//+------------------------------------------------------------------+ +//| ATR.mq4 | +//| Copyright 2005-2014, MetaQuotes Software Corp. | +//| http://www.mql4.com | +//+------------------------------------------------------------------+ +#property copyright "2005-2014, MetaQuotes Software Corp." +#property link "http://www.mql4.com" +#property description "Average True Range" +#property strict + +//--- indicator settings +#property indicator_separate_window +#property indicator_buffers 1 +#property indicator_color1 DodgerBlue +//--- input parameter +input int InpAtrPeriod=14; // ATR Period +//--- buffers +double ExtATRBuffer[]; +double ExtTRBuffer[]; +//+------------------------------------------------------------------+ +//| Custom indicator initialization function | +//+------------------------------------------------------------------+ +int OnInit(void) + { + string short_name; +//--- 1 additional buffer used for counting. + IndicatorBuffers(2); + IndicatorDigits(Digits); +//--- indicator line + SetIndexStyle(0,DRAW_LINE); + SetIndexBuffer(0,ExtATRBuffer); + SetIndexBuffer(1,ExtTRBuffer); +//--- name for DataWindow and indicator subwindow label + short_name="ATR("+IntegerToString(InpAtrPeriod)+")"; + IndicatorShortName(short_name); + SetIndexLabel(0,short_name); +//--- check for input parameter + if(InpAtrPeriod<=0) + { + Print("Wrong input parameter ATR Period=",InpAtrPeriod); + return(INIT_FAILED); + } +//--- + SetIndexDrawBegin(0,InpAtrPeriod); +//--- + return(INIT_SUCCEEDED); + } +//+------------------------------------------------------------------+ +//| Average True Range | +//+------------------------------------------------------------------+ +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[]) + { + int i,limit; +//--- check for bars count and input parameter + if(rates_total<=InpAtrPeriod || InpAtrPeriod<=0) + return(0); +//--- counting from 0 to rates_total + ArraySetAsSeries(ExtATRBuffer,false); + ArraySetAsSeries(ExtTRBuffer,false); + ArraySetAsSeries(open,false); + ArraySetAsSeries(high,false); + ArraySetAsSeries(low,false); + ArraySetAsSeries(close,false); +//--- preliminary calculations + if(prev_calculated==0) + { + ExtTRBuffer[0]=0.0; + ExtATRBuffer[0]=0.0; + //--- filling out the array of True Range values for each period + for(i=1; i + +//--- indicator settings +#property indicator_separate_window +#property indicator_buffers 3 +#property indicator_color1 Black +#property indicator_color2 Green +#property indicator_color3 Red +//--- indicator buffers +double ExtACBuffer[]; +double ExtUpBuffer[]; +double ExtDnBuffer[]; +double ExtMacdBuffer[]; +double ExtSignalBuffer[]; +//--- +#define PERIOD_FAST 5 +#define PERIOD_SLOW 34 +//--- bars minimum for calculation +#define DATA_LIMIT 38 +//+------------------------------------------------------------------+ +//| Custom indicator initialization function | +//+------------------------------------------------------------------+ +void OnInit(void) + { + IndicatorShortName("AC"); +//--- 2 additional buffers are used for counting. + IndicatorBuffers(5); +//--- drawing settings + SetIndexStyle(0,DRAW_NONE); + SetIndexStyle(1,DRAW_HISTOGRAM); + SetIndexStyle(2,DRAW_HISTOGRAM); + IndicatorDigits(Digits+2); + SetIndexDrawBegin(0,DATA_LIMIT); + SetIndexDrawBegin(1,DATA_LIMIT); + SetIndexDrawBegin(2,DATA_LIMIT); +//--- all indicator buffers mapping + SetIndexBuffer(0,ExtACBuffer); + SetIndexBuffer(1,ExtUpBuffer); + SetIndexBuffer(2,ExtDnBuffer); + SetIndexBuffer(3,ExtMacdBuffer); + SetIndexBuffer(4,ExtSignalBuffer); +//--- name for DataWindow and indicator subwindow label + SetIndexLabel(1,NULL); + SetIndexLabel(2,NULL); + } +//+------------------------------------------------------------------+ +//| Accelerator/Decelerator Oscillator | +//+------------------------------------------------------------------+ +int OnCalculate (const int rates_total, + const int prev_calculated, + const datetime& time[], + const double& open[], + const double& high[], + const double& low[], + const double& close[], + const long& tick_volume[], + const long& volume[], + const int& spread[]) + { + int i,limit; + double prev=0.0,current; +//--- check for rates total + if(rates_total<=DATA_LIMIT) + return(0); +//--- last counted bar will be recounted + limit=rates_total-prev_calculated; + if(prev_calculated>0) + { + limit++; + prev=ExtMacdBuffer[limit]-ExtSignalBuffer[limit]; + } +//--- macd counted in the 1-st additional buffer + for(i=0; i=0;) + { + current=ExtMacdBuffer[i]-ExtSignalBuffer[i]; + if(current>prev) + up=true; + if(current=0) + { + ExtADbuffer[i]=(close[i]-low[i])-(high[i]-close[i]); + if(ExtADbuffer[i]!=0.0) + { + double diff=high[i]-low[i]; + if(diff<0.000000001) + ExtADbuffer[i]=0.0; + else + { + ExtADbuffer[i]/=diff; + ExtADbuffer[i]*=(double)tick_volume[i]; + } + } + if(i0) + { + limit++; + prev=ExtAOBuffer[limit]; + } +//--- macd + for(i=0; i=0; i--) + { + current=ExtAOBuffer[i]; + if(current>prev) + up=true; + if(current + +#property indicator_chart_window +#property indicator_buffers 3 +#property indicator_color1 LightSeaGreen +#property indicator_color2 LightSeaGreen +#property indicator_color3 LightSeaGreen +//--- indicator parameters +input int InpBandsPeriod=20; // Bands Period +input int InpBandsShift=0; // Bands Shift +input double InpBandsDeviations=2.0; // Bands Deviations +//--- buffers +double ExtMovingBuffer[]; +double ExtUpperBuffer[]; +double ExtLowerBuffer[]; +double ExtStdDevBuffer[]; +//+------------------------------------------------------------------+ +//| Custom indicator initialization function | +//+------------------------------------------------------------------+ +int OnInit(void) + { +//--- 1 additional buffer used for counting. + IndicatorBuffers(4); + IndicatorDigits(Digits); +//--- middle line + SetIndexStyle(0,DRAW_LINE); + SetIndexBuffer(0,ExtMovingBuffer); + SetIndexShift(0,InpBandsShift); + SetIndexLabel(0,"Bands SMA"); +//--- upper band + SetIndexStyle(1,DRAW_LINE); + SetIndexBuffer(1,ExtUpperBuffer); + SetIndexShift(1,InpBandsShift); + SetIndexLabel(1,"Bands Upper"); +//--- lower band + SetIndexStyle(2,DRAW_LINE); + SetIndexBuffer(2,ExtLowerBuffer); + SetIndexShift(2,InpBandsShift); + SetIndexLabel(2,"Bands Lower"); +//--- work buffer + SetIndexBuffer(3,ExtStdDevBuffer); +//--- check for input parameter + if(InpBandsPeriod<=0) + { + Print("Wrong input parameter Bands Period=",InpBandsPeriod); + return(INIT_FAILED); + } +//--- + SetIndexDrawBegin(0,InpBandsPeriod+InpBandsShift); + SetIndexDrawBegin(1,InpBandsPeriod+InpBandsShift); + SetIndexDrawBegin(2,InpBandsPeriod+InpBandsShift); +//--- initialization done + return(INIT_SUCCEEDED); + } +//+------------------------------------------------------------------+ +//| Bollinger Bands | +//+------------------------------------------------------------------+ +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[]) + { + int i,pos; +//--- + if(rates_total<=InpBandsPeriod || InpBandsPeriod<=0) + return(0); +//--- counting from 0 to rates_total + ArraySetAsSeries(ExtMovingBuffer,false); + ArraySetAsSeries(ExtUpperBuffer,false); + ArraySetAsSeries(ExtLowerBuffer,false); + ArraySetAsSeries(ExtStdDevBuffer,false); + ArraySetAsSeries(close,false); +//--- initial zero + if(prev_calculated<1) + { + for(i=0; i1) + pos=prev_calculated-1; + else + pos=0; +//--- main cycle + for(i=pos; i=period) + { + //--- calcualte StdDev + for(int i=0; i0) + limit++; + for(int i=0; i0) + limit++; + for(int i=0; i + +#property indicator_separate_window +#property indicator_buffers 1 +#property indicator_color1 LightSeaGreen +#property indicator_level1 -100.0 +#property indicator_level2 100.0 +#property indicator_levelcolor clrSilver +#property indicator_levelstyle STYLE_DOT +//--- input parameter +input int InpCCIPeriod=14; // CCI Period +//--- buffers +double ExtCCIBuffer[]; +double ExtPriceBuffer[]; +double ExtMovBuffer[]; +//+------------------------------------------------------------------+ +//| Custom indicator initialization function | +//+------------------------------------------------------------------+ +int OnInit(void) + { + string short_name; +//--- 2 additional buffers are used for counting. + IndicatorBuffers(3); + SetIndexBuffer(1,ExtPriceBuffer); + SetIndexBuffer(2,ExtMovBuffer); +//--- indicator line + SetIndexStyle(0,DRAW_LINE); + SetIndexBuffer(0,ExtCCIBuffer); +//--- check for input parameter + if(InpCCIPeriod<=1) + { + Print("Wrong input parameter CCI Period=",InpCCIPeriod); + return(INIT_FAILED); + } +//--- + SetIndexDrawBegin(0,InpCCIPeriod); +//--- name for DataWindow and indicator subwindow label + short_name="CCI("+IntegerToString(InpCCIPeriod)+")"; + IndicatorShortName(short_name); + SetIndexLabel(0,short_name); +//--- initialization done + return(INIT_SUCCEEDED); + } +//+------------------------------------------------------------------+ +//| Commodity Channel Index | +//+------------------------------------------------------------------+ +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[]) + { + int i,k,pos; + double dSum,dMul; +//--- + if(rates_total<=InpCCIPeriod || InpCCIPeriod<=1) + return(0); +//--- counting from 0 to rates_total + ArraySetAsSeries(ExtCCIBuffer,false); + ArraySetAsSeries(ExtPriceBuffer,false); + ArraySetAsSeries(ExtMovBuffer,false); + ArraySetAsSeries(high,false); + ArraySetAsSeries(low,false); + ArraySetAsSeries(close,false); +//--- initial zero + if(prev_calculated<1) + { + for(i=0; i'Properties...'):" +#property description " - on 'Color' Tab select 'Black' for 'Line Graph'" +#property description " - on 'Common' Tab disable 'Chart on Foreground' checkbox and select 'Line Chart' radiobutton" +#property strict + +#property indicator_chart_window +#property indicator_buffers 4 +#property indicator_color1 Red +#property indicator_color2 White +#property indicator_color3 Red +#property indicator_color4 White +#property indicator_width1 1 +#property indicator_width2 1 +#property indicator_width3 3 +#property indicator_width4 3 + +//--- +input color ExtColor1 = Red; // Shadow of bear candlestick +input color ExtColor2 = White; // Shadow of bull candlestick +input color ExtColor3 = Red; // Bear candlestick body +input color ExtColor4 = White; // Bull candlestick body +//--- buffers +double ExtLowHighBuffer[]; +double ExtHighLowBuffer[]; +double ExtOpenBuffer[]; +double ExtCloseBuffer[]; +//+------------------------------------------------------------------+ +//| Custom indicator initialization function | +//|------------------------------------------------------------------| +void OnInit(void) + { + IndicatorShortName("Heiken Ashi"); + IndicatorDigits(Digits); +//--- indicator lines + SetIndexStyle(0,DRAW_HISTOGRAM,0,1,ExtColor1); + SetIndexBuffer(0,ExtLowHighBuffer); + SetIndexStyle(1,DRAW_HISTOGRAM,0,1,ExtColor2); + SetIndexBuffer(1,ExtHighLowBuffer); + SetIndexStyle(2,DRAW_HISTOGRAM,0,3,ExtColor3); + SetIndexBuffer(2,ExtOpenBuffer); + SetIndexStyle(3,DRAW_HISTOGRAM,0,3,ExtColor4); + SetIndexBuffer(3,ExtCloseBuffer); +//--- + SetIndexLabel(0,"Low/High"); + SetIndexLabel(1,"High/Low"); + SetIndexLabel(2,"Open"); + SetIndexLabel(3,"Close"); + SetIndexDrawBegin(0,10); + SetIndexDrawBegin(1,10); + SetIndexDrawBegin(2,10); + SetIndexDrawBegin(3,10); +//--- indicator buffers mapping + SetIndexBuffer(0,ExtLowHighBuffer); + SetIndexBuffer(1,ExtHighLowBuffer); + SetIndexBuffer(2,ExtOpenBuffer); + SetIndexBuffer(3,ExtCloseBuffer); +//--- initialization done + } +//+------------------------------------------------------------------+ +//| Heiken Ashi | +//+------------------------------------------------------------------+ +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[]) + { + int i,pos; + double haOpen,haHigh,haLow,haClose; +//--- + if(rates_total<=10) + return(0); +//--- counting from 0 to rates_total + ArraySetAsSeries(ExtLowHighBuffer,false); + ArraySetAsSeries(ExtHighLowBuffer,false); + ArraySetAsSeries(ExtOpenBuffer,false); + ArraySetAsSeries(ExtCloseBuffer,false); + ArraySetAsSeries(open,false); + ArraySetAsSeries(high,false); + ArraySetAsSeries(low,false); + ArraySetAsSeries(close,false); +//--- preliminary calculation + if(prev_calculated>1) + pos=prev_calculated-1; + else + { + //--- set first candle + if(open[0]InpTenkan) + pos=prev_calculated-1; + for(i=pos; ilow[k]) + low_value=low[k]; + k++; + } + ExtTenkanBuffer[i]=(high_value+low_value)/2; + } +//--- Kijun Sen + pos=InpKijun-1; + if(prev_calculated>InpKijun) + pos=prev_calculated-1; + for(i=pos; ilow[k]) + low_value=low[k]; + k++; + } + ExtKijunBuffer[i]=(high_value+low_value)/2; + } +//--- Senkou Span A + pos=ExtBegin-1; + if(prev_calculated>ExtBegin) + pos=prev_calculated-1; + for(i=pos; iInpSenkou) + pos=prev_calculated-1; + for(i=pos; ilow[k]) + low_value=low[k]; + k++; + } + ExtSpanB_Buffer[i]=(high_value+low_value)/2; + ExtSpanB2_Buffer[i]=ExtSpanB_Buffer[i]; + } +//--- Chikou Span + pos=0; + if(prev_calculated>1) + pos=prev_calculated-1; + for(i=pos; i + +//--- indicator settings +#property indicator_separate_window +#property indicator_buffers 2 +#property indicator_color1 Silver +#property indicator_color2 Red +#property indicator_width1 2 +//--- indicator parameters +input int InpFastEMA=12; // Fast EMA Period +input int InpSlowEMA=26; // Slow EMA Period +input int InpSignalSMA=9; // Signal SMA Period +//--- indicator buffers +double ExtMacdBuffer[]; +double ExtSignalBuffer[]; +//--- right input parameters flag +bool ExtParameters=false; + +//+------------------------------------------------------------------+ +//| Custom indicator initialization function | +//+------------------------------------------------------------------+ +int OnInit(void) + { + IndicatorDigits(Digits+1); +//--- drawing settings + SetIndexStyle(0,DRAW_HISTOGRAM); + SetIndexStyle(1,DRAW_LINE); + SetIndexDrawBegin(1,InpSignalSMA); +//--- indicator buffers mapping + SetIndexBuffer(0,ExtMacdBuffer); + SetIndexBuffer(1,ExtSignalBuffer); +//--- name for DataWindow and indicator subwindow label + IndicatorShortName("MACD("+IntegerToString(InpFastEMA)+","+IntegerToString(InpSlowEMA)+","+IntegerToString(InpSignalSMA)+")"); + SetIndexLabel(0,"MACD"); + SetIndexLabel(1,"Signal"); +//--- check for input parameters + if(InpFastEMA<=1 || InpSlowEMA<=1 || InpSignalSMA<=1 || InpFastEMA>=InpSlowEMA) + { + Print("Wrong input parameters"); + ExtParameters=false; + return(INIT_FAILED); + } + else + ExtParameters=true; +//--- initialization done + return(INIT_SUCCEEDED); + } +//+------------------------------------------------------------------+ +//| 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[]) + { + int i,limit; +//--- + if(rates_total<=InpSignalSMA || !ExtParameters) + return(0); +//--- last counted bar will be recounted + limit=rates_total-prev_calculated; + if(prev_calculated>0) + limit++; +//--- macd counted in the 1-st buffer + for(i=0; i + +//--- indicator settings +#property indicator_separate_window +#property indicator_buffers 1 +#property indicator_color1 Silver +#property indicator_width1 2 +//--- indicator parameters +input int InpFastEMA=12; // Fast EMA Period +input int InpSlowEMA=26; // Slow EMA Period +input int InpSignalSMA=9; // Signal SMA Period +//--- indicator buffers +double ExtOsmaBuffer[]; +double ExtMacdBuffer[]; +double ExtSignalBuffer[]; +//--- right input parameters flag +bool ExtParameters=false; +//+------------------------------------------------------------------+ +//| Custom indicator initialization function | +//+------------------------------------------------------------------+ +int OnInit(void) + { +//--- 2 additional buffers are used for counting. + IndicatorBuffers(3); +//--- drawing settings + SetIndexStyle(0,DRAW_HISTOGRAM); + SetIndexDrawBegin(0,InpSignalSMA); + IndicatorDigits(Digits+2); +//--- 3 indicator buffers mapping + SetIndexBuffer(0,ExtOsmaBuffer); + SetIndexBuffer(1,ExtMacdBuffer); + SetIndexBuffer(2,ExtSignalBuffer); +//--- name for DataWindow and indicator subwindow label + IndicatorShortName("OsMA("+IntegerToString(InpFastEMA)+","+IntegerToString(InpSlowEMA)+","+IntegerToString(InpSignalSMA)+")"); +//--- check for input parameters + if(InpFastEMA<=1 || InpSlowEMA<=1 || InpSignalSMA<=1 || InpFastEMA>=InpSlowEMA) + { + Print("Wrong input parameters"); + ExtParameters=false; + return(INIT_FAILED); + } + else + ExtParameters=true; +//--- initialization done + return(INIT_SUCCEEDED); + } +//+------------------------------------------------------------------+ +//| Moving Average of Oscillator | +//+------------------------------------------------------------------+ +int OnCalculate (const int rates_total, + const int prev_calculated, + const datetime& time[], + const double& open[], + const double& high[], + const double& low[], + const double& close[], + const long& tick_volume[], + const long& volume[], + const int& spread[]) + { + int i,limit; +//--- + if(rates_total<=InpSignalSMA || !ExtParameters) + return(0); +//--- last counted bar will be recounted + limit=rates_total-prev_calculated; + if(prev_calculated>0) + limit++; +//--- macd counted in the 1-st buffer + for(i=0; ilow[i]) + last_low=low[i]; + if(last_highhigh[i-1] && low[i]>low[i-1]) + break; + if(high[i]ExtSARBuffer[i-1]) + { + SaveLastReverse(i,false,step,last_low,high[i],ep,sar); + step=ExtSarStep; + dir_long=true; + ep=high[i]; + last_high=high[i]; + ExtSARBuffer[i++]=last_low; + continue; + } + //--- + sar=ExtSARBuffer[i-1]+step*(ep-ExtSARBuffer[i-1]); + //--- LONG? + if(dir_long) + { + if(eplow[i-1]) + sar=low[i-1]; + if(sar>low[i-2]) + sar=low[i-2]; + if(sar>low[i]) + { + SaveLastReverse(i,true,step,low[i],last_high,ep,sar); + step=ExtSarStep; dir_long=false; ep=low[i]; + last_low=low[i]; + ExtSARBuffer[i++]=last_high; + continue; + } + if(eplow[i]) + { + if((step+ExtSarStep)<=ExtSarMaximum) + step+=ExtSarStep; + } + if(low[i]low[i]) + ep=last_low=low[i]; + } + ExtSARBuffer[i++]=sar; + } +//---- OnCalculate done. Return new prev_calculated. + return(rates_total); + } +//+------------------------------------------------------------------+ +//| save last values to continue further calculations | +//+------------------------------------------------------------------+ +void SaveLastReverse(int reverse,bool dir,double step,double last_low,double last_high,double ep,double sar) + { + ExtLastReverse=reverse; + if(ExtLastReverse<2) + ExtLastReverse=2; + ExtDirectionLong=dir; + ExtLastStep=step; + ExtLastLow=last_low; + ExtLastHigh=last_high; + ExtLastEP=ep; + ExtLastSAR=sar; + } +//+------------------------------------------------------------------+ diff --git a/xSamples/ParabolicSar.mq4 b/xSamples/ParabolicSar.mq4 new file mode 100644 index 0000000..261808a --- /dev/null +++ b/xSamples/ParabolicSar.mq4 @@ -0,0 +1,333 @@ +//------------------------------------------------------------------ +#property copyright "www.forex-station.com" +#property link "www.forex-station.com" +//------------------------------------------------------------------ +#property indicator_chart_window +#property indicator_buffers 4 +#property indicator_color1 clrLimeGreen +#property indicator_color2 clrOrange +#property indicator_color3 clrLimeGreen +#property indicator_color4 clrOrange +#property indicator_width3 3 +#property indicator_width4 3 +#property strict + +// +// +// +// +// + +extern ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; // Time frame to use +extern double AccStep = 0.02; // Accumulation step +extern double AccLimit = 0.2; // Accumulation limit +extern ENUM_APPLIED_PRICE PriceHigh = PRICE_CLOSE; // Psar high price +extern ENUM_APPLIED_PRICE PriceLow = PRICE_CLOSE; // Psar low price +extern int PriceSmoothing = 0; // Psar smoothing +extern ENUM_MA_METHOD PriceSmoothingMethod = MODE_SMA; // Psar ma smoothing method +extern bool alertsOn = true; // Alerts on? +extern bool alertsOnCurrent = false; // Alerts on current open bar? +extern bool alertsMessage = true; // Alerts message? +extern bool alertsSound = false; // Alerts sound? +extern bool alertsEmail = false; // Alerts email? +extern bool alertsNotify = false; // Alerts notification by phone? +extern bool DrawAsDots = true; // Draw as dots or solid line +extern int Shift = 0; // Shift + +double sarUp[]; +double sarDn[]; +double saraUp[]; +double saraDn[]; +int timeFrame; +string indicatorFileName; +bool returnBars; + +//------------------------------------------------------------------ +// +//------------------------------------------------------------------ +// +// +// +// +// + +int init() +{ + int type = DRAW_LINE; if (DrawAsDots) type = DRAW_ARROW; + SetIndexBuffer(0,sarUp); SetIndexStyle(0,type); SetIndexArrow(0,159); + SetIndexBuffer(1,sarDn); SetIndexStyle(1,type); SetIndexArrow(1,159); + SetIndexBuffer(2,saraUp); SetIndexStyle(2,DRAW_ARROW); SetIndexArrow(2,159); + SetIndexBuffer(3,saraDn); SetIndexStyle(3,DRAW_ARROW); SetIndexArrow(3,159); + + // + // + // + // + // + + indicatorFileName = WindowExpertName(); + returnBars = (TimeFrame==-99); + TimeFrame = MathMax(TimeFrame,_Period); + PriceSmoothing = MathMax(PriceSmoothing,1); + for (int i=0; i<4; i++) SetIndexShift(i,Shift*timeFrame/Period()); + + // + // + // + // + // + + return(0); +} +int deinit() { return(0); } + +//------------------------------------------------------------------ +// +//------------------------------------------------------------------ +// +// +// +// +// + +int start() +{ + int i,counted_bars=IndicatorCounted(); + if(counted_bars < 0) return(-1); + if(counted_bars>0) counted_bars--; + int limit = MathMin(Bars-counted_bars,Bars-1); + if (returnBars) { sarUp[0] = limit+1; return(0); } + + // + // + // + // + // + + if (TimeFrame == Period()) + { + for(i = limit; i >= 0; i--) + { + double sarClose; + double sarOpen; + double sarPosition; + double sarChange; + double pHigh = iMA(NULL,0,PriceSmoothing,0,PriceSmoothingMethod,PriceHigh,i); + double pLow = iMA(NULL,0,PriceSmoothing,0,PriceSmoothingMethod,PriceLow ,i); + iParabolic(fmax(pHigh,pLow),fmin(pHigh,pLow),AccStep,AccLimit,sarClose,sarOpen,sarPosition,sarChange,i); + sarUp[i] = EMPTY_VALUE; + sarDn[i] = EMPTY_VALUE; + saraUp[i] = EMPTY_VALUE; + saraDn[i] = EMPTY_VALUE; + if (sarPosition==1) + sarUp[i] = sarClose; + else sarDn[i] = sarClose; + if (sarChange!=0) + if (sarChange==1) + saraUp[i] = sarClose; + else saraDn[i] = sarClose; + } + manageAlerts(); + return(0); + } + + // + // + // + // + // + + limit = (int)fmax(limit,fmin(Bars-1,iCustom(NULL,TimeFrame,indicatorFileName,-99,0,0)*TimeFrame/Period())); + for(i=limit; i>=0; i--) + { + int y = iBarShift(NULL,TimeFrame,Time[i]); + int x = iBarShift(NULL,TimeFrame,Time[i+1]); + sarUp[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,AccStep,AccLimit,PriceHigh,PriceLow,PriceSmoothing,PriceSmoothingMethod,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,0,0,y); + sarDn[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,AccStep,AccLimit,PriceHigh,PriceLow,PriceSmoothing,PriceSmoothingMethod,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,0,1,y); + saraUp[i] = EMPTY_VALUE; + saraDn[i] = EMPTY_VALUE; + if (x!=y) + { + saraUp[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,AccStep,AccLimit,PriceHigh,PriceLow,PriceSmoothing,PriceSmoothingMethod,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,0,2,y); + saraDn[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,AccStep,AccLimit,PriceHigh,PriceLow,PriceSmoothing,PriceSmoothingMethod,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,0,3,y); + } + } + return(0); + +} + +//------------------------------------------------------------------ +// +//------------------------------------------------------------------ +// +// +// +// +// + +double work[][7]; +#define _high 0 +#define _low 1 +#define _ohigh 2 +#define _olow 3 +#define _open 4 +#define _position 5 +#define _af 6 + + +void iParabolic(double high, double low, double step, double limit, double& pClose, double& pOpen, double& pPosition, double& pChange, int i) +{ + if (ArrayRange(work,0)!=Bars) ArrayResize(work,Bars); i = Bars-i-1; + + // + // + // + // + // + + pChange = 0; + work[i][_ohigh] = high; + work[i][_olow] = low; + if (i<1) + { + work[i][_high] = high; + work[i][_low] = low; + work[i][_open] = high; + work[i][_position] = -1; + return; + } + work[i][_open] = work[i-1][_open]; + work[i][_af] = work[i-1][_af]; + work[i][_position] = work[i-1][_position]; + work[i][_high] = fmax(work[i-1][_high],high); + work[i][_low] = fmin(work[i-1][_low] ,low ); + + // + // + // + // + // + + if (work[i][_position] == 1) + if (low<=work[i][_open]) + { + work[i][_position] = -1; + pChange = -1; + pClose = work[i][_high]; + work[i][_high] = high; + work[i][_low] = low; + work[i][_af] = step; + work[i][_open] = pClose + work[i][_af]*(work[i][_low]-pClose); + if (work[i][_open]work[i-1][_high] && work[i][_af]work[i ][_olow]) work[i][_open] = work[i ][_olow]; + if (work[i][_open]>work[i-1][_olow]) work[i][_open] = work[i-1][_olow]; + } + else + if (high>=work[i][_open]) + { + work[i][_position] = 1; + pChange = 1; + pClose = work[i][_low]; + work[i][_low] = low; + work[i][_high] = high; + work[i][_af] = step; + work[i][_open] = pClose + work[i][_af]*(work[i][_high]-pClose); + if (work[i][_open]>work[i ][_olow]) work[i][_open] = work[i ][_olow]; + if (work[i][_open]>work[i-1][_olow]) work[i][_open] = work[i-1][_olow]; + } + else + { + pClose = work[i][_open]; + if (work[i][_low]=0; i--) + if (tf==iTfTable[i]) return(sTfTable[i]); + return(""); +} \ No newline at end of file diff --git a/xSamples/RSI.mq4 b/xSamples/RSI.mq4 new file mode 100644 index 0000000..f5aee97 --- /dev/null +++ b/xSamples/RSI.mq4 @@ -0,0 +1,133 @@ +//+------------------------------------------------------------------+ +//| RSI.mq4 | +//| Copyright 2005-2014, MetaQuotes Software Corp. | +//| http://www.mql4.com | +//+------------------------------------------------------------------+ +#property copyright "2005-2014, MetaQuotes Software Corp." +#property link "http://www.mql4.com" +#property description "Relative Strength Index" +#property strict + +#property indicator_separate_window +#property indicator_minimum 0 +#property indicator_maximum 100 +#property indicator_buffers 1 +#property indicator_color1 DodgerBlue +#property indicator_level1 30.0 +#property indicator_level2 70.0 +#property indicator_levelcolor clrSilver +#property indicator_levelstyle STYLE_DOT +//--- input parameters +input int InpRSIPeriod=14; // RSI Period +//--- buffers +double ExtRSIBuffer[]; +double ExtPosBuffer[]; +double ExtNegBuffer[]; +//+------------------------------------------------------------------+ +//| Custom indicator initialization function | +//+------------------------------------------------------------------+ +int OnInit(void) + { + string short_name; +//--- 2 additional buffers are used for counting. + IndicatorBuffers(3); + SetIndexBuffer(1,ExtPosBuffer); + SetIndexBuffer(2,ExtNegBuffer); +//--- indicator line + SetIndexStyle(0,DRAW_LINE); + SetIndexBuffer(0,ExtRSIBuffer); +//--- name for DataWindow and indicator subwindow label + short_name="RSI("+string(InpRSIPeriod)+")"; + IndicatorShortName(short_name); + SetIndexLabel(0,short_name); +//--- check for input + if(InpRSIPeriod<2) + { + Print("Incorrect value for input variable InpRSIPeriod = ",InpRSIPeriod); + return(INIT_FAILED); + } +//--- + SetIndexDrawBegin(0,InpRSIPeriod); +//--- initialization done + return(INIT_SUCCEEDED); + } +//+------------------------------------------------------------------+ +//| Relative Strength Index | +//+------------------------------------------------------------------+ +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[]) + { + int i,pos; + double diff; +//--- + if(Bars<=InpRSIPeriod || InpRSIPeriod<2) + return(0); +//--- counting from 0 to rates_total + ArraySetAsSeries(ExtRSIBuffer,false); + ArraySetAsSeries(ExtPosBuffer,false); + ArraySetAsSeries(ExtNegBuffer,false); + ArraySetAsSeries(close,false); +//--- preliminary calculations + pos=prev_calculated-1; + if(pos<=InpRSIPeriod) + { + //--- first RSIPeriod values of the indicator are not calculated + ExtRSIBuffer[0]=0.0; + ExtPosBuffer[0]=0.0; + ExtNegBuffer[0]=0.0; + double sump=0.0; + double sumn=0.0; + for(i=1; i<=InpRSIPeriod; i++) + { + ExtRSIBuffer[i]=0.0; + ExtPosBuffer[i]=0.0; + ExtNegBuffer[i]=0.0; + diff=close[i]-close[i-1]; + if(diff>0) + sump+=diff; + else + sumn-=diff; + } + //--- calculate first visible value + ExtPosBuffer[InpRSIPeriod]=sump/InpRSIPeriod; + ExtNegBuffer[InpRSIPeriod]=sumn/InpRSIPeriod; + if(ExtNegBuffer[InpRSIPeriod]!=0.0) + ExtRSIBuffer[InpRSIPeriod]=100.0-(100.0/(1.0+ExtPosBuffer[InpRSIPeriod]/ExtNegBuffer[InpRSIPeriod])); + else + { + if(ExtPosBuffer[InpRSIPeriod]!=0.0) + ExtRSIBuffer[InpRSIPeriod]=100.0; + else + ExtRSIBuffer[InpRSIPeriod]=50.0; + } + //--- prepare the position value for main calculation + pos=InpRSIPeriod+1; + } +//--- the main loop of calculations + for(i=pos; i0.0?diff:0.0))/InpRSIPeriod; + ExtNegBuffer[i]=(ExtNegBuffer[i-1]*(InpRSIPeriod-1)+(diff<0.0?-diff:0.0))/InpRSIPeriod; + if(ExtNegBuffer[i]!=0.0) + ExtRSIBuffer[i]=100.0-100.0/(1+ExtPosBuffer[i]/ExtNegBuffer[i]); + else + { + if(ExtPosBuffer[i]!=0.0) + ExtRSIBuffer[i]=100.0; + else + ExtRSIBuffer[i]=50.0; + } + } +//--- + return(rates_total); + } +//+------------------------------------------------------------------+ diff --git a/xSamples/Stochastic.mq4 b/xSamples/Stochastic.mq4 new file mode 100644 index 0000000..858296e --- /dev/null +++ b/xSamples/Stochastic.mq4 @@ -0,0 +1,157 @@ +//+------------------------------------------------------------------+ +//| Stochastic.mq4 | +//| Copyright 2005-2014, MetaQuotes Software Corp. | +//| http://www.mql4.com | +//+------------------------------------------------------------------+ +#property copyright "2005-2014, MetaQuotes Software Corp." +#property link "http://www.mql4.com" +#property description "Stochastic Oscillator" +#property strict + +#property indicator_separate_window +#property indicator_minimum 0 +#property indicator_maximum 100 +#property indicator_buffers 2 +#property indicator_color1 LightSeaGreen +#property indicator_color2 Red +#property indicator_level1 20.0 +#property indicator_level2 80.0 +#property indicator_levelcolor clrSilver +#property indicator_levelstyle STYLE_DOT +//--- input parameters +input int InpKPeriod=5; // K Period +input int InpDPeriod=3; // D Period +input int InpSlowing=3; // Slowing +//--- buffers +double ExtMainBuffer[]; +double ExtSignalBuffer[]; +double ExtHighesBuffer[]; +double ExtLowesBuffer[]; +//--- +int draw_begin1=0; +int draw_begin2=0; +//+------------------------------------------------------------------+ +//| Custom indicator initialization function | +//+------------------------------------------------------------------+ +int OnInit(void) + { + string short_name; +//--- 2 additional buffers are used for counting. + IndicatorBuffers(4); + SetIndexBuffer(2, ExtHighesBuffer); + SetIndexBuffer(3, ExtLowesBuffer); +//--- indicator lines + SetIndexStyle(0,DRAW_LINE); + SetIndexBuffer(0, ExtMainBuffer); + SetIndexStyle(1,DRAW_LINE); + SetIndexBuffer(1, ExtSignalBuffer); +//--- name for DataWindow and indicator subwindow label + short_name="Sto("+IntegerToString(InpKPeriod)+","+IntegerToString(InpDPeriod)+","+IntegerToString(InpSlowing)+")"; + IndicatorShortName(short_name); + SetIndexLabel(0,short_name); + SetIndexLabel(1,"Signal"); +//--- + draw_begin1=InpKPeriod+InpSlowing; + draw_begin2=draw_begin1+InpDPeriod; + SetIndexDrawBegin(0,draw_begin1); + SetIndexDrawBegin(1,draw_begin2); +//--- initialization done + return(INIT_SUCCEEDED); + } +//+------------------------------------------------------------------+ +//| Stochastic oscillator | +//+------------------------------------------------------------------+ +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[]) + { + int i,k,pos; +//--- check for bars count + if(rates_total<=InpKPeriod+InpDPeriod+InpSlowing) + return(0); +//--- counting from 0 to rates_total + ArraySetAsSeries(ExtMainBuffer,false); + ArraySetAsSeries(ExtSignalBuffer,false); + ArraySetAsSeries(ExtHighesBuffer,false); + ArraySetAsSeries(ExtLowesBuffer,false); + ArraySetAsSeries(low,false); + ArraySetAsSeries(high,false); + ArraySetAsSeries(close,false); +//--- + pos=InpKPeriod-1; + if(pos+1low[k]) + dmin=low[k]; + if(dmax=InpDepth) + { + Print("Backstep cannot be greater or equal to Depth"); + return(INIT_FAILED); + } +//--- 2 additional buffers + IndicatorBuffers(3); +//---- drawing settings + SetIndexStyle(0,DRAW_SECTION); +//---- indicator buffers + SetIndexBuffer(0,ExtZigzagBuffer); + SetIndexBuffer(1,ExtHighBuffer); + SetIndexBuffer(2,ExtLowBuffer); + SetIndexEmptyValue(0,0.0); +//---- indicator short name + IndicatorShortName("ZigZag("+string(InpDepth)+","+string(InpDeviation)+","+string(InpBackstep)+")"); +//---- initialization done + 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[]) + { + int i,limit,counterZ,whatlookfor=0; + int back,pos,lasthighpos=0,lastlowpos=0; + double extremum; + double curlow=0.0,curhigh=0.0,lasthigh=0.0,lastlow=0.0; +//--- check for history and inputs + if(rates_total=InpDepth) + return(0); +//--- first calculations + if(prev_calculated==0) + limit=InitializeAll(); + else + { + //--- find first extremum in the depth ExtLevel or 100 last bars + i=counterZ=0; + while(counterZ=0; i--) + { + ExtZigzagBuffer[i]=0.0; + ExtLowBuffer[i]=0.0; + ExtHighBuffer[i]=0.0; + } + } + } + +//--- main loop + for(i=limit; i>=0; i--) + { + //--- find lowest low in depth of bars + extremum=low[iLowest(NULL,0,MODE_LOW,InpDepth,i)]; + //--- this lowest has been found previously + if(extremum==lastlow) + extremum=0.0; + else + { + //--- new last low + lastlow=extremum; + //--- discard extremum if current low is too high + if(low[i]-extremum>InpDeviation*Point) + extremum=0.0; + else + { + //--- clear previous extremums in backstep bars + for(back=1; back<=InpBackstep; back++) + { + pos=i+back; + if(ExtLowBuffer[pos]!=0 && ExtLowBuffer[pos]>extremum) + ExtLowBuffer[pos]=0.0; + } + } + } + //--- found extremum is current low + if(low[i]==extremum) + ExtLowBuffer[i]=extremum; + else + ExtLowBuffer[i]=0.0; + //--- find highest high in depth of bars + extremum=high[iHighest(NULL,0,MODE_HIGH,InpDepth,i)]; + //--- this highest has been found previously + if(extremum==lasthigh) + extremum=0.0; + else + { + //--- new last high + lasthigh=extremum; + //--- discard extremum if current high is too low + if(extremum-high[i]>InpDeviation*Point) + extremum=0.0; + else + { + //--- clear previous extremums in backstep bars + for(back=1; back<=InpBackstep; back++) + { + pos=i+back; + if(ExtHighBuffer[pos]!=0 && ExtHighBuffer[pos]=0; i--) + { + switch(whatlookfor) + { + case 0: // look for peak or lawn + if(lastlow==0.0 && lasthigh==0.0) + { + if(ExtHighBuffer[i]!=0.0) + { + lasthigh=High[i]; + lasthighpos=i; + whatlookfor=-1; + ExtZigzagBuffer[i]=lasthigh; + } + if(ExtLowBuffer[i]!=0.0) + { + lastlow=Low[i]; + lastlowpos=i; + whatlookfor=1; + ExtZigzagBuffer[i]=lastlow; + } + } + break; + case 1: // look for peak + if(ExtLowBuffer[i]!=0.0 && ExtLowBuffer[i]lasthigh && ExtLowBuffer[i]==0.0) + { + ExtZigzagBuffer[lasthighpos]=0.0; + lasthighpos=i; + lasthigh=ExtHighBuffer[i]; + ExtZigzagBuffer[i]=lasthigh; + } + if(ExtLowBuffer[i]!=0.0 && ExtHighBuffer[i]==0.0) + { + lastlow=ExtLowBuffer[i]; + lastlowpos=i; + ExtZigzagBuffer[i]=lastlow; + whatlookfor=1; + } + break; + } + } + +//--- done + return(rates_total); + } +//+------------------------------------------------------------------+ +//| | +//+------------------------------------------------------------------+ +int InitializeAll() + { + ArrayInitialize(ExtZigzagBuffer,0.0); + ArrayInitialize(ExtHighBuffer,0.0); + ArrayInitialize(ExtLowBuffer,0.0); +//--- first counting position + return(Bars-InpDepth); + } +//+------------------------------------------------------------------+ \ No newline at end of file diff --git a/xSamples/iExposure.mq4 b/xSamples/iExposure.mq4 new file mode 100644 index 0000000..33de30a --- /dev/null +++ b/xSamples/iExposure.mq4 @@ -0,0 +1,249 @@ +//+------------------------------------------------------------------+ +//| iExposure.mq4 | +//| Copyright 2007-2014, MetaQuotes Software Corp. | +//| http://www.mql4.com | +//+------------------------------------------------------------------+ +#property copyright "2007-2014, MetaQuotes Software Corp." +#property link "http://www.mql4.com" +#property strict + +#property indicator_separate_window +#property indicator_buffers 1 +#property indicator_minimum 0.0 +#property indicator_maximum 0.1 + +#define SYMBOLS_MAX 1024 +#define DEALS 0 +#define BUY_LOTS 1 +#define BUY_PRICE 2 +#define SELL_LOTS 3 +#define SELL_PRICE 4 +#define NET_LOTS 5 +#define PROFIT 6 + +input color InpColor=LightSeaGreen; // Text color + +string ExtName="Exposure"; +string ExtSymbols[SYMBOLS_MAX]; +int ExtSymbolsTotal=0; +double ExtSymbolsSummaries[SYMBOLS_MAX][7]; +int ExtLines=-1; +string ExtCols[8]={"Symbol", + "Deals", + "Buy lots", + "Buy price", + "Sell lots", + "Sell price", + "Net lots", + "Profit"}; +int ExtShifts[8]={ 10, 80, 130, 180, 260, 310, 390, 460 }; +int ExtVertShift=14; +double ExtMapBuffer[]; +//+------------------------------------------------------------------+ +//| Custom indicator initialization function | +//+------------------------------------------------------------------+ +void OnInit() + { + IndicatorShortName(ExtName); + SetIndexBuffer(0,ExtMapBuffer); + SetIndexStyle(0,DRAW_NONE); + IndicatorDigits(0); + SetIndexEmptyValue(0,0.0); + } +//+------------------------------------------------------------------+ +//| | +//+------------------------------------------------------------------+ +void OnDeinit(const int reason) + { + int windex=WindowFind(ExtName); + if(windex>0) + ObjectsDeleteAll(windex); + } +//+------------------------------------------------------------------+ +//| 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[]) + { + string name; + int i,col,line,windex=WindowFind(ExtName); +//---- + if(windex<0) + return(rates_total); +//---- header line + if(ExtLines<0) + { + for(col=0; col<8; col++) + { + name="Head_"+string(col); + if(ObjectCreate(name,OBJ_LABEL,windex,0,0)) + { + ObjectSet(name,OBJPROP_XDISTANCE,ExtShifts[col]); + ObjectSet(name,OBJPROP_YDISTANCE,ExtVertShift); + ObjectSetText(name,ExtCols[col],9,"Arial",InpColor); + } + } + ExtLines=0; + } +//---- + ArrayInitialize(ExtSymbolsSummaries,0.0); + int total=Analyze(); + if(total>0) + { + line=0; + for(i=0; iExtLines) + { + int y_dist=ExtVertShift*(line+1)+1; + for(col=0; col<8; col++) + { + name="Line_"+string(line)+"_"+string(col); + if(ObjectCreate(name,OBJ_LABEL,windex,0,0)) + { + ObjectSet(name,OBJPROP_XDISTANCE,ExtShifts[col]); + ObjectSet(name,OBJPROP_YDISTANCE,y_dist); + } + } + ExtLines++; + } + //---- set line + int digits=(int)MarketInfo(ExtSymbols[i],MODE_DIGITS); + double buy_lots=ExtSymbolsSummaries[i][BUY_LOTS]; + double sell_lots=ExtSymbolsSummaries[i][SELL_LOTS]; + double buy_price=0.0; + double sell_price=0.0; + if(buy_lots!=0) buy_price=ExtSymbolsSummaries[i][BUY_PRICE]/buy_lots; + if(sell_lots!=0) sell_price=ExtSymbolsSummaries[i][SELL_PRICE]/sell_lots; + name="Line_"+string(line)+"_0"; + ObjectSetText(name,ExtSymbols[i],9,"Arial",InpColor); + name="Line_"+string(line)+"_1"; + ObjectSetText(name,DoubleToStr(ExtSymbolsSummaries[i][DEALS],0),9,"Arial",InpColor); + name="Line_"+string(line)+"_2"; + ObjectSetText(name,DoubleToStr(buy_lots,2),9,"Arial",InpColor); + name="Line_"+string(line)+"_3"; + ObjectSetText(name,DoubleToStr(buy_price,digits),9,"Arial",InpColor); + name="Line_"+string(line)+"_4"; + ObjectSetText(name,DoubleToStr(sell_lots,2),9,"Arial",InpColor); + name="Line_"+string(line)+"_5"; + ObjectSetText(name,DoubleToStr(sell_price,digits),9,"Arial",InpColor); + name="Line_"+string(line)+"_6"; + ObjectSetText(name,DoubleToStr(buy_lots-sell_lots,2),9,"Arial",InpColor); + name="Line_"+string(line)+"_7"; + ObjectSetText(name,DoubleToStr(ExtSymbolsSummaries[i][PROFIT],2),9,"Arial",InpColor); + } + } +//---- remove lines + if(totaltotal; line--) + { + name="Line_"+string(line)+"_0"; + ObjectSetText(name,""); + name="Line_"+string(line)+"_1"; + ObjectSetText(name,""); + name="Line_"+string(line)+"_2"; + ObjectSetText(name,""); + name="Line_"+string(line)+"_3"; + ObjectSetText(name,""); + name="Line_"+string(line)+"_4"; + ObjectSetText(name,""); + name="Line_"+string(line)+"_5"; + ObjectSetText(name,""); + name="Line_"+string(line)+"_6"; + ObjectSetText(name,""); + name="Line_"+string(line)+"_7"; + ObjectSetText(name,""); + } + } +//---- to avoid minimum==maximum + ExtMapBuffer[Bars-1]=-1; +//---- + return(rates_total); + } +//+------------------------------------------------------------------+ +//| | +//+------------------------------------------------------------------+ +int Analyze() + { + double profit; + int i,index,type,total=OrdersTotal(); +//---- + for(i=0; i=SYMBOLS_MAX) continue; + //---- + ExtSymbolsSummaries[index][DEALS]++; + profit=OrderProfit()+OrderCommission()+OrderSwap(); + ExtSymbolsSummaries[index][PROFIT]+=profit; + if(type==OP_BUY) + { + ExtSymbolsSummaries[index][BUY_LOTS]+=OrderLots(); + ExtSymbolsSummaries[index][BUY_PRICE]+=OrderOpenPrice()*OrderLots(); + } + else + { + ExtSymbolsSummaries[index][SELL_LOTS]+=OrderLots(); + ExtSymbolsSummaries[index][SELL_PRICE]+=OrderOpenPrice()*OrderLots(); + } + } +//---- + total=0; + for(i=0; i0) total++; + } +//---- + return(total); + } +//+------------------------------------------------------------------+ +//| | +//+------------------------------------------------------------------+ +int SymbolsIndex(string SymbolName) + { + bool found=false; + int i; +//---- + for(i=0; i=SYMBOLS_MAX) + return(-1); +//---- + i=ExtSymbolsTotal; + ExtSymbolsTotal++; + ExtSymbols[i]=SymbolName; + ExtSymbolsSummaries[i][DEALS]=0; + ExtSymbolsSummaries[i][BUY_LOTS]=0; + ExtSymbolsSummaries[i][BUY_PRICE]=0; + ExtSymbolsSummaries[i][SELL_LOTS]=0; + ExtSymbolsSummaries[i][SELL_PRICE]=0; + ExtSymbolsSummaries[i][NET_LOTS]=0; + ExtSymbolsSummaries[i][PROFIT]=0; +//---- + return(i); + } +//+------------------------------------------------------------------+ \ No newline at end of file