This commit is contained in:
2025-01-06 06:09:50 +03:30
parent 6f61bc6d30
commit 9d4b2ee578
21 changed files with 17827 additions and 4044 deletions
+580
View File
@@ -0,0 +1,580 @@
//////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// ---------------------------------------------
// Name: XSTR
// Description: Super Trend 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 X121_XAMA Indicator"
#property strict
//
// START Constants ...
//
#define ShortName "XSTR"
//
// END Constants ...
//
//
// START Inputs ...
//
//
// Market ...
input group "ATR";
input int atrLength = 14; // Length
input double atrMultiplier = 3.0; // Multiplier
input ENUM_APPLIED_PRICE atrAppliedTo = PRICE_MEDIAN; // Applied To
//
// Presentation ...
input group "Presentation";
input bool showTrends = true; // Show Trends
input bool fillTrends = true; // Fill Trends
//
// END Inputs ...
//
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// START Buffers ...
//
//
#property indicator_chart_window
//
#property indicator_buffers 9
#property indicator_plots 2
//
#define fillUpBufferIndex 0
double fillUpBuffer[];
#define fillDownBufferIndex 1
double fillDownBuffer[];
//
#define fillingPlotBufferIndex 0
//
#property indicator_label1 "XSTR Filling"
#property indicator_type1 DRAW_FILLING
#property indicator_color1 clrBisque, clrPaleGreen
//
#define mainBufferIndex 2
#define mainPlotBufferIndex 1
double mainBuffer[];
//
#define mainColorBufferIndex 3
double mainColorBuffer[];
//
#property indicator_label2 "XSTR"
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 CLR_NONE, clrGreen, clrDarkRed
#property indicator_style2 STYLE_DOT
//
// DATA Buffers ...
//
#define atrBufferIndex 4
double atrBuffer[];
//
#define trendBufferIndex 5
double trendBuffer[];
//
#define upBufferIndex 6
double upBuffer[];
//
#define downBufferIndex 7
double downBuffer[];
//
#define priceBufferIndex 8
double priceBuffer[];
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
int atrHandler = INVALID_HANDLE;
//
int changeOfTrend;
int startBearishTrend;
int startBullishTrend;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// 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 ...
maxLength = ExtractMaxLengthOfInputs();
//
atrHandler = iATR(
_Symbol,
_Period,
atrLength);
if (atrHandler == INVALID_HANDLE)
{
return INIT_FAILED;
}
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs 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 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
//
// Here we can handle De Initialization Reasons ...
IndicatorRelease(atrHandler);
}
//
// Calculating what we want ...
int OnCalculate(
//
// total Candles on chart ...
const int rates_total,
//
// total calculated Candles on charts ...
const int prev_calculated,
//
// history of Candles Open Time ...
const datetime &time[],
//
// history of Candles Open Price ...
const double &open[],
//
// history of Candles High Price ...
const double &high[],
//
// history of Candles Low Price ...
const double &low[],
//
// history of Candles Close Price ...
const double &close[],
//
// history of Tick Volumes on Candle ...
const long &tick_volume[],
//
// history of Trade Volumes ...
const long &volume[],
//
// history of Candles Spread Price ...
const int &spread[])
{
//
int numOfRequiredAtrs;
if (prev_calculated > rates_total || prev_calculated < 0)
{
numOfRequiredAtrs = rates_total;
}
else
{
//
numOfRequiredAtrs = rates_total - prev_calculated;
if (prev_calculated > 0)
{
numOfRequiredAtrs++;
}
}
//
// Checking for stop ...
if (IsStopped())
{
return 0;
}
//
// Check Number of items Copy or not ...
int copiedATRs = CopyBuffer(atrHandler, 0, 0, numOfRequiredAtrs, atrBuffer);
if (copiedATRs <= 0)
{
return 0;
}
//
int limit;
//
// checking for the limit start of calculation of an indicator ...
if (prev_calculated > rates_total || prev_calculated <= 0)
{
//
// starting index for calculation of all bars ...
limit = maxLength;
}
else
{
//
// starting number for calculation of new bars
limit = prev_calculated - 1;
}
//
// Main Loop ...
for (int i = limit; i < rates_total && !IsStopped(); i++)
{
//
// Calculated Price ...
double price = getPrice(
atrAppliedTo,
open,
high,
low,
close,
i);
// price = (high[i] + low[i]) / 2;
priceBuffer[i] = price;
//
double atr = atrBuffer[i];
//
// Up ...
upBuffer[i] = price + (atrMultiplier * atr);
//
// Down ...
downBuffer[i] = price - (atrMultiplier * atr);
//
if (close[i] > upBuffer[i - 1])
{
//
trendBuffer[i] = 1;
if (trendBuffer[i - 1] == -1)
{
changeOfTrend = 1;
}
}
else if (close[i] < downBuffer[i - 1])
{
//
trendBuffer[i] = -1;
if (trendBuffer[i - 1] == 1)
{
changeOfTrend = 1;
}
}
else if (trendBuffer[i - 1] == 1)
{
//
trendBuffer[i] = 1;
changeOfTrend = 0;
}
else if (trendBuffer[i - 1] == -1)
{
//
trendBuffer[i] = -1;
changeOfTrend = 0;
}
//
// Down Trend Starting ...
if (trendBuffer[i] < 0 && trendBuffer[i - 1] > 0)
{
startBearishTrend = 1;
}
else
{
startBearishTrend = 0;
}
//
// Up Trend Starting ...
if (trendBuffer[i] > 0 && trendBuffer[i - 1] < 0)
{
startBullishTrend = 1;
}
else
{
startBullishTrend = 0;
}
//
if (trendBuffer[i] > 0 && downBuffer[i] < downBuffer[i - 1])
{
downBuffer[i] = downBuffer[i - 1];
}
//
if (trendBuffer[i] < 0 && upBuffer[i] > upBuffer[i - 1])
{
upBuffer[i] = upBuffer[i - 1];
}
//
if (startBearishTrend == 1)
{
upBuffer[i] = priceBuffer[i] + (atrMultiplier * atr);
}
//
if (startBullishTrend == 1)
{
downBuffer[i] = priceBuffer[i] - (atrMultiplier * atr);
}
//
// Draw the indicator ...
//
double colorIDX = 0;
mainColorBuffer[i] = colorIDX;
//
if (trendBuffer[i] == 1)
{
//
mainBuffer[i] = downBuffer[i];
if (changeOfTrend == 1)
{
mainBuffer[i - 1] = mainBuffer[i - 2];
changeOfTrend = 0;
}
//
colorIDX = 1;
}
else if (trendBuffer[i] == -1)
{
//
mainBuffer[i] = upBuffer[i];
if (changeOfTrend == 1)
{
//
mainBuffer[i - 1] = mainBuffer[i - 2];
changeOfTrend = 0;
}
//
colorIDX = 2;
}
//
if (showTrends)
{
mainColorBuffer[i] = colorIDX;
}
//
// Filling ...
if (fillTrends)
{
//
fillUpBuffer[i] = mainBuffer[i];
fillDownBuffer[i] = close[i];
}
else
{
//
fillUpBuffer[i] = EMPTY_VALUE;
fillDownBuffer[i] = EMPTY_VALUE;
}
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
// Validate Args ...
result =
//
atrLength >= 2
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = atrLength;
//
return result;
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// PLOT Buffers ...
//
// FILLINGS ...
SetIndexBuffer(fillUpBufferIndex, fillUpBuffer, INDICATOR_DATA);
SetIndexBuffer(fillDownBufferIndex, fillDownBuffer, INDICATOR_DATA);
PlotIndexSetInteger(fillingPlotBufferIndex, PLOT_SHOW_DATA, false);
//
// MAIN ...
SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA);
PlotIndexSetInteger(mainPlotBufferIndex, PLOT_SHOW_DATA, showTrends);
SetIndexBuffer(mainColorBufferIndex, mainColorBuffer, INDICATOR_COLOR_INDEX);
//
// DATA Buffers ...
//
// ATR ...
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
//
// TREND ...
SetIndexBuffer(trendBufferIndex, trendBuffer, INDICATOR_CALCULATIONS);
//
// UP ...
SetIndexBuffer(upBufferIndex, upBuffer, INDICATOR_CALCULATIONS);
//
// DOWN ...
SetIndexBuffer(downBufferIndex, downBuffer, INDICATOR_CALCULATIONS);
//
// PRICE ...
SetIndexBuffer(priceBufferIndex, priceBuffer, INDICATOR_CALCULATIONS);
}
//
// END Functions ...
//
//
// TEMPLATE Function ...
template <typename T>
double getPrice(ENUM_APPLIED_PRICE tprice, T &open[], T &high[], T &low[], T &close[], int i)
{
switch (tprice)
{
case PRICE_CLOSE:
return (close[i]);
case PRICE_OPEN:
return (open[i]);
case PRICE_HIGH:
return (high[i]);
case PRICE_LOW:
return (low[i]);
case PRICE_MEDIAN:
return ((high[i] + low[i]) / 2.0);
case PRICE_TYPICAL:
return ((high[i] + low[i] + close[i]) / 3.0);
case PRICE_WEIGHTED:
return ((high[i] + low[i] + close[i] + close[i]) / 4.0);
}
return (0);
}
+195
View File
@@ -0,0 +1,195 @@
//+------------------------------------------------------------------+
//| SuperTrend.mq5 |
//| Copyright 2011, FxGeek |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, FxGeek"
#property link " http://www.mql5.com"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 9
#property indicator_plots 2
#property indicator_label1 "Filling"
#property indicator_type1 DRAW_FILLING
#property indicator_color1 clrBisque, clrPaleGreen
#property indicator_label2 "SuperTrend"
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 clrGreen, clrRed
input int Periode=10;
input double Multiplier=3;
input bool Show_Filling=true; // Show as DRAW_FILLING
double Filled_a[];
double Filled_b[];
double SuperTrend[];
double ColorBuffer[];
double Atr[];
double Up[];
double Down[];
double Middle[];
double trend[];
int atrHandle;
int changeOfTrend;
int flag;
int flagh;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,Filled_a,INDICATOR_DATA);
SetIndexBuffer(1,Filled_b,INDICATOR_DATA);
SetIndexBuffer(2,SuperTrend,INDICATOR_DATA);
SetIndexBuffer(3,ColorBuffer,INDICATOR_COLOR_INDEX);
SetIndexBuffer(4,Atr,INDICATOR_CALCULATIONS);
SetIndexBuffer(5,Up,INDICATOR_CALCULATIONS);
SetIndexBuffer(6,Down,INDICATOR_CALCULATIONS);
SetIndexBuffer(7,Middle,INDICATOR_CALCULATIONS);
SetIndexBuffer(8,trend,INDICATOR_CALCULATIONS);
atrHandle=iATR(_Symbol,_Period,Periode);
//---
return(0);
}
//+------------------------------------------------------------------+
//| 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[])
{
//---
int to_copy;
if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
else
{
to_copy=rates_total-prev_calculated;
if(prev_calculated>0) to_copy++;
}
if(IsStopped()) return(0); //Checking for stop flag
if(CopyBuffer(atrHandle,0,0,to_copy,Atr)<=0)
{
Print("Getting Atr is failed! Error",GetLastError());
return(0);
}
int first;
if(prev_calculated>rates_total || prev_calculated<=0) // checking for the first start of calculation of an indicator
{
first=Periode; // starting index for calculation of all bars
}
else
{
first=prev_calculated-1; // starting number for calculation of new bars
}
for(int i=first; i<rates_total && !IsStopped(); i++)
{
Middle[i]=(high[i]+low[i])/2;
Up[i] = Middle[i] +(Multiplier*Atr[i]);
Down[i]= Middle[i] -(Multiplier*Atr[i]);
if(close[i]>Up[i-1])
{
trend[i]=1;
if(trend[i-1]==-1) changeOfTrend=1;
}
else if(close[i]<Down[i-1])
{
trend[i]=-1;
if(trend[i-1]==1) changeOfTrend=1;
}
else if(trend[i-1]==1)
{
trend[i]=1;
changeOfTrend=0;
}
else if(trend[i-1]==-1)
{
trend[i]=-1;
changeOfTrend=0;
}
if(trend[i]<0 && trend[i-1]>0)
{
flag=1;
}
else
{
flag=0;
}
if(trend[i]>0 && trend[i-1]<0)
{
flagh=1;
}
else
{
flagh=0;
}
if(trend[i]>0 && Down[i]<Down[i-1])
Down[i]=Down[i-1];
if(trend[i]<0 && Up[i]>Up[i-1])
Up[i]=Up[i-1];
if(flag==1)
Up[i]=Middle[i]+(Multiplier*Atr[i]);
if(flagh==1)
Down[i]=Middle[i]-(Multiplier*Atr[i]);
//-- Draw the indicator
if(trend[i]==1)
{
SuperTrend[i]=Down[i];
if(changeOfTrend==1)
{
SuperTrend[i-1]=SuperTrend[i-2];
changeOfTrend=0;
}
ColorBuffer[i]=0.0;
}
else if(trend[i]==-1)
{
SuperTrend[i]=Up[i];
if(changeOfTrend==1)
{
SuperTrend[i-1]= SuperTrend[i-2];
changeOfTrend = 0;
}
ColorBuffer[i]=1.0;
}
if(Show_Filling)
{
Filled_a[i]= SuperTrend[i];
Filled_b[i]= close[i];
}else{
Filled_a[i]= EMPTY_VALUE;
Filled_b[i]= EMPTY_VALUE;
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
File diff suppressed because it is too large Load Diff
@@ -80,6 +80,10 @@ input ENUM_APPLIED_PRICE atrUpperAppliedTo = PRICE_HIGH; // Upper Zone Applied T
input ENUM_APPLIED_PRICE atrLowerAppliedTo = PRICE_LOW; // Lower Zone Applied To
input ENUM_X_MA_METHOD atrSmoothingMode = X_MA_MODE_EMA; // Smoothing Method
//
input group "Str Detecttion";
input ENUM_APPLIED_PRICE strAppliedTo = PRICE_MEDIAN; // Applied To
//
input group "VWap Detection";
input int vwapFastLength = 20; // Fast Length
@@ -105,6 +109,7 @@ input int valesArrowCode = 159; // Vales Arrow Code
//
input bool showSar = true; // Show Parabolic Sar
input bool showAtr = true; // Show Atr
input bool showStr = true; // Show Str
input bool showPeaks = true; // Show Peaks
input bool showVales = true; // Show Vales
input bool showVWap = true; // Show VWap
@@ -143,8 +148,8 @@ input bool showLow = false; // Show Low
#property indicator_chart_window
//
#property indicator_buffers 38
#property indicator_plots 16
#property indicator_buffers 44
#property indicator_plots 17
//
// PEAKS ...
@@ -215,55 +220,71 @@ double atrLowerBuffer[];
#property indicator_width5 2
//
// VWAP ...
// STR ...
#define strBufferIndex 5
double strBuffer[];
#define strColorBufferIndex 6
double strColorBuffer[];
//
// FAST ...
#define vwapFastBufferIndex 5
double vwapFastBuffer[];
#define vwapFastColorBufferIndex 6
double vwapFastColorBuffer[];
//
#define vwapFastPlotBufferIndex 5
#property indicator_label6 "X121 VWF"
#define strPlotBufferIndex 5
#property indicator_label6 "X121 STR"
#property indicator_type6 DRAW_COLOR_LINE
#property indicator_color6 CLR_NONE, clrAqua, clrMagenta, clrGray
#property indicator_color6 CLR_NONE, clrLime, clrRed, clrGray
#property indicator_style6 STYLE_SOLID
#property indicator_width6 2
//
// MID ...
#define vwapMidBufferIndex 7
double vwapMidBuffer[];
#define vwapMidColorBufferIndex 8
double vwapMidColorBuffer[];
// VWAP ...
//
#define vwapMidPlotBufferIndex 6
#property indicator_label7 "X121 VWM"
// FAST ...
#define vwapFastBufferIndex 7
double vwapFastBuffer[];
#define vwapFastColorBufferIndex 8
double vwapFastColorBuffer[];
//
#define vwapFastPlotBufferIndex 6
#property indicator_label7 "X121 VWF"
#property indicator_type7 DRAW_COLOR_LINE
#property indicator_color7 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_color7 CLR_NONE, clrAqua, clrMagenta, clrGray
#property indicator_style7 STYLE_SOLID
#property indicator_width7 2
//
// MID ...
#define vwapMidBufferIndex 9
double vwapMidBuffer[];
#define vwapMidColorBufferIndex 10
double vwapMidColorBuffer[];
//
#define vwapMidPlotBufferIndex 7
#property indicator_label8 "X121 VWM"
#property indicator_type8 DRAW_COLOR_LINE
#property indicator_color8 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style8 STYLE_SOLID
#property indicator_width8 2
//
// SLOW ...
#define vwapSlowBufferIndex 9
#define vwapSlowBufferIndex 11
double vwapSlowBuffer[];
#define vwapSlowColorBufferIndex 10
#define vwapSlowColorBufferIndex 12
double vwapSlowColorBuffer[];
//
#define vwapSlowPlotBufferIndex 7
#property indicator_label8 "X121 VWS"
#property indicator_type8 DRAW_COLOR_LINE
#property indicator_color8 CLR_NONE, clrSteelBlue, clrDarkRed, clrGray
#property indicator_style8 STYLE_SOLID
#property indicator_width8 2
#define vwapSlowPlotBufferIndex 8
#property indicator_label9 "X121 VWS"
#property indicator_type9 DRAW_COLOR_LINE
#property indicator_color9 CLR_NONE, clrSteelBlue, clrDarkRed, clrGray
#property indicator_style9 STYLE_SOLID
#property indicator_width9 2
//
// XDON ...
@@ -272,107 +293,107 @@ double vwapSlowColorBuffer[];
// Open ...
//
#define donOpenUpperBufferIndex 11
#define donOpenUpperBufferIndex 13
double donOpenUpperBuffer[];
//
#define donOpenUpperPlotBufferIndex 8
#property indicator_label9 "X121 O U"
#property indicator_type9 DRAW_LINE
#property indicator_color9 clrCornflowerBlue
#property indicator_width9 1
//
#define donOpenLowerBufferIndex 12
double donOpenLowerBuffer[];
//
#define donOpenLowerPlotBufferIndex 9
#property indicator_label10 "X121 O L"
#define donOpenUpperPlotBufferIndex 9
#property indicator_label10 "X121 O U"
#property indicator_type10 DRAW_LINE
#property indicator_color10 clrCornflowerBlue
#property indicator_width10 1
//
// High ...
#define donOpenLowerBufferIndex 14
double donOpenLowerBuffer[];
//
#define donHighUpperBufferIndex 13
double donHighUpperBuffer[];
//
#define donHighUpperPlotBufferIndex 10
#property indicator_label11 "X121 H U"
#define donOpenLowerPlotBufferIndex 10
#property indicator_label11 "X121 O L"
#property indicator_type11 DRAW_LINE
#property indicator_color11 clrAquamarine
#property indicator_color11 clrCornflowerBlue
#property indicator_width11 1
//
#define donHighLowerBufferIndex 14
double donHighLowerBuffer[];
// High ...
//
#define donHighLowerPlotBufferIndex 11
#property indicator_label12 "X121 H L"
#define donHighUpperBufferIndex 15
double donHighUpperBuffer[];
//
#define donHighUpperPlotBufferIndex 11
#property indicator_label12 "X121 H U"
#property indicator_type12 DRAW_LINE
#property indicator_color12 clrAquamarine
#property indicator_width12 1
//
// Low ...
#define donHighLowerBufferIndex 16
double donHighLowerBuffer[];
//
#define donLowUpperBufferIndex 15
double donLowUpperBuffer[];
//
#define donLowUpperPlotBufferIndex 12
#property indicator_label13 "X121 L U"
#define donHighLowerPlotBufferIndex 12
#property indicator_label13 "X121 H L"
#property indicator_type13 DRAW_LINE
#property indicator_color13 clrDarkOrchid
#property indicator_color13 clrAquamarine
#property indicator_width13 1
//
#define donLowLowerBufferIndex 16
double donLowLowerBuffer[];
// Low ...
//
#define donLowLowerPlotBufferIndex 13
#property indicator_label14 "X121 L L"
#define donLowUpperBufferIndex 17
double donLowUpperBuffer[];
//
#define donLowUpperPlotBufferIndex 13
#property indicator_label14 "X121 L U"
#property indicator_type14 DRAW_LINE
#property indicator_color14 clrDarkOrchid
#property indicator_width14 1
//
// Close ...
#define donLowLowerBufferIndex 18
double donLowLowerBuffer[];
//
#define donCloseUpperBufferIndex 17
double donCloseUpperBuffer[];
//
#define donCloseUpperPlotBufferIndex 14
#property indicator_label15 "X121 C U"
#define donLowLowerPlotBufferIndex 14
#property indicator_label15 "X121 L L"
#property indicator_type15 DRAW_LINE
#property indicator_color15 clrCoral
#property indicator_color15 clrDarkOrchid
#property indicator_width15 1
//
#define donCloseLowerBufferIndex 18
double donCloseLowerBuffer[];
// Close ...
//
#define donCloseLowerPlotBufferIndex 15
#property indicator_label16 "X121 C L"
#define donCloseUpperBufferIndex 19
double donCloseUpperBuffer[];
//
#define donCloseUpperPlotBufferIndex 15
#property indicator_label16 "X121 C U"
#property indicator_type16 DRAW_LINE
#property indicator_color16 clrCoral
#property indicator_width16 1
//
#define donCloseLowerBufferIndex 20
double donCloseLowerBuffer[];
//
#define donCloseLowerPlotBufferIndex 16
#property indicator_label17 "X121 C L"
#property indicator_type17 DRAW_LINE
#property indicator_color17 clrCoral
#property indicator_width17 1
//
// Data Buffers ...
//
int mLastBufferIndex = 18;
int mLastBufferIndex = 20;
//
// CURRENT ...
@@ -471,12 +492,36 @@ double atrLowerRawBuffer[];
#define rsiBufferIndex mLastBufferIndex + 19
double rsiBuffer[];
//
// STR ...
//
// Price ...
#define strPriceBufferIndex mLastBufferIndex + 20
double strPriceBuffer[];
//
// Up ...
#define strUpBufferIndex mLastBufferIndex + 21
double strUpBuffer[];
//
// Down ...
#define strDownBufferIndex mLastBufferIndex + 22
double strDownBuffer[];
//
// Trend ...
#define strStateBufferIndex mLastBufferIndex + 23
double strStateBuffer[];
//
// Variables, Properties and etc ...
//
// this counts Available Bars ...
int limit;
int rlimit;
//
int maxLength;
@@ -494,7 +539,9 @@ int sarHandler = INVALID_HANDLE;
int atrHandler = INVALID_HANDLE;
//
double mHideColorIDX = 0;
bool isStrTrendChanged;
bool isStrStartBearishTrend;
bool isStrStartBullishTrend;
//
// XMarketCycle sc;
@@ -712,7 +759,12 @@ int OnCalculate(
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
limit = (prev_calculated > rates_total || prev_calculated <= 0)
? rates_total
: (rates_total - prev_calculated) + 1;
rlimit = (prev_calculated > rates_total || prev_calculated <= 0)
? maxLength
: prev_calculated - 1;
//
// Buffers Copy ...
@@ -932,6 +984,13 @@ void DefineBuffers()
PlotIndexSetInteger(atrLowerBufferIndex, PLOT_SHOW_DATA, canShowAtrLower);
PlotIndexSetInteger(atrLowerBufferIndex, PLOT_DRAW_TYPE, atrLowerDrawType);
//
// STR ...
ArraySetAsSeries(strBuffer, true);
ArraySetAsSeries(strColorBuffer, true);
SetIndexBuffer(strBufferIndex, strBuffer, INDICATOR_DATA);
SetIndexBuffer(strColorBufferIndex, strColorBuffer, INDICATOR_COLOR_INDEX);
//
// XVWAP ...
@@ -1158,6 +1217,25 @@ void DefineBuffers()
//
ArraySetAsSeries(rsiBuffer, true);
SetIndexBuffer(rsiBufferIndex, rsiBuffer, INDICATOR_CALCULATIONS);
//
// STR ...
//
ArraySetAsSeries(strPriceBuffer, true);
SetIndexBuffer(strPriceBufferIndex, strPriceBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(strUpBuffer, true);
SetIndexBuffer(strUpBufferIndex, strUpBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(strDownBuffer, true);
SetIndexBuffer(strDownBufferIndex, strDownBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(strStateBuffer, true);
SetIndexBuffer(strStateBufferIndex, strStateBuffer, INDICATOR_CALCULATIONS);
}
/**
@@ -1233,6 +1311,17 @@ void CalculateBuffers(
low //
);
//
CalculateStr(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low //
);
//
// Calculate Required VWAP Data Buffers ...
if (ratesTotal - bar_index <= maxLength)
@@ -1455,6 +1544,15 @@ void FillBuffersZero(int barIndex)
atrUpperBuffer[barIndex] = 0;
atrLowerRawBuffer[barIndex] = 0;
//
// STR ...
strBuffer[barIndex] = 0;
strUpBuffer[barIndex] = 0;
strDownBuffer[barIndex] = 0;
strPriceBuffer[barIndex] = 0;
strColorBuffer[barIndex] = hideColorIDX;
strStateBuffer[barIndex] = hideColorIDX;
//
// VWAP ...
@@ -2017,7 +2115,7 @@ void CalculateDonchains(
}
/**
* Calculate Different VWaps ...
* Calculate ATR Zones ...
*
* @param bar_index: Integer, Represent Current Bar ...
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
@@ -2114,4 +2212,196 @@ void CalculateAtrZones(
}
}
/**
* Calculate STR ...
*
* @param bar_index: Integer, Represent Current Bar ...
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
* @param ratesTotal: Integer, Represents All Available Bars ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param close: Double Array, History of Close Prices ...
* @param low: Double Array, History of Low Prices ...
*/
void CalculateStr(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[] //
)
{
//
// Calculated Price ...
double price = GetAppliedPrice(
strAppliedTo,
open,
high,
low,
close,
bar_index //
);
//
strPriceBuffer[bar_index] = price;
//
double atr = atrBuffer[bar_index];
//
double appliedAtr = (atrMultiplier * atr);
double strUp = price + appliedAtr;
double strDown = price - appliedAtr;
//
strUpBuffer[bar_index] = strUp;
strDownBuffer[bar_index] = strDown;
//
int currIDX = bar_index;
int prevIDX = currIDX + 1;
int prevOfPrevIDX = prevIDX + 1;
//
double prevState = strStateBuffer[prevIDX];
bool isCloseOverUp = close[currIDX] > strUpBuffer[prevIDX];
bool isCloseUnderDown = close[currIDX] < strUpBuffer[prevIDX];
//
if (isCloseOverUp)
{
//
strStateBuffer[currIDX] = 1;
if (strStateBuffer[prevIDX] == -1)
{
isStrTrendChanged = true;
}
}
else if (isCloseUnderDown)
{
//
strStateBuffer[currIDX] = -1;
if (strStateBuffer[prevIDX] == 1)
{
isStrTrendChanged = true;
}
}
else if (strStateBuffer[prevIDX] == 1)
{
//
isStrTrendChanged = false;
strStateBuffer[currIDX] = 1;
}
else if (strStateBuffer[prevIDX] == -1)
{
//
isStrTrendChanged = false;
strStateBuffer[currIDX] = -1;
}
//
// Calculate Trend Starting ...
//
if (strStateBuffer[currIDX] < 0 &&
strStateBuffer[prevIDX] > 0)
{
isStrStartBearishTrend = true;
}
else
{
isStrStartBearishTrend = false;
}
//
if (strStateBuffer[currIDX] > 0 &&
strStateBuffer[prevIDX] < 0)
{
isStrStartBullishTrend = true;
}
else
{
isStrStartBullishTrend = false;
}
//
// Re new Up and Down Buffer ...
//
if (strStateBuffer[currIDX] > 0 &&
strDownBuffer[currIDX] < strDownBuffer[prevIDX])
{
strDownBuffer[currIDX] = strDownBuffer[prevIDX];
}
//
if (strStateBuffer[currIDX] < 0 &&
strUpBuffer[currIDX] > strUpBuffer[prevIDX])
{
strUpBuffer[currIDX] = strUpBuffer[prevIDX];
}
//
// Handle Strat Trends ...
//
if (isStrStartBearishTrend)
{
strUpBuffer[currIDX] = strPriceBuffer[currIDX] + (atrMultiplier * atr);
}
//
if (isStrStartBullishTrend)
{
strDownBuffer[currIDX] = strPriceBuffer[currIDX] - (atrMultiplier * atr);
}
//
double clr = hideColorIDX;
double state = hideColorIDX;
//
if (strStateBuffer[currIDX] == 1)
{
//
strBuffer[currIDX] = strDownBuffer[currIDX];
if (isStrTrendChanged)
{
//
isStrTrendChanged = false;
strBuffer[prevIDX] = strBuffer[prevOfPrevIDX];
}
//
clr = bullishColorIDX;
}
else if (state == -1)
{
//
strBuffer[currIDX] = strUpBuffer[currIDX];
if (isStrTrendChanged)
{
//
isStrTrendChanged = false;
strBuffer[prevIDX] = strBuffer[prevOfPrevIDX];
}
//
clr = bearishColorIDX;
}
//
if (!showStr)
{
clr = hideColorIDX;
}
//
strColorBuffer[bar_index] = clr;
//
}
//
+325
View File
@@ -0,0 +1,325 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: X121 ???
// Description: ??? ...
//
//
// 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 X121 ??? Indicator"
#property strict
//
// Definitions ...
//
#define ShortName "X121 ???"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
//
// Presentation ...
input group "Presentation";
//
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
//
// Buffers ...
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
#define neuturalColorIDX 3
//
#property indicator_chart_window
//
#property indicator_buffers 0
#property indicator_plots 0
//
// Plot Buffers ...
//
// Data Buffers ...
//
int mLastBufferIndex = 20;
//
// Variables, Properties and etc ...
//
// this counts Available Bars ...
int limit;
//
int maxLength;
//
// Event Handlers ...
/**
* Initialize Indicator ...
*
* @return ( int )
*/
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initialize Indicator Handlers ...
//
// 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 ...
maxLength = ExtractMaxLengthOfInputs();
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
/**
* De Initialize Indicator ...
*
* @param reason: Integer, De Initialization Reason ...
*/
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs 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 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
}
/**
* Calculate Bars ...
*
* @param rates_total: Integer, Total Bars on Chart ...
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
* @param time: DateTime Array, History of Open Time ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param low: Double Array, History of Low Prices ...
* @param close: Double Array, History of Close Prices ...
* @param tick_volume: Long, History of Tick Volumes on Bar ...
* @param volume: Long, History of Trade Volumes ...
* @param spread: Double, History of Spread Price ...
*
* @return ( int )
*/
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[] //
)
{
//
// Prepare Buffers ...
ArraySetAsSeries(time, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
ArraySetAsSeries(volume, true);
ArraySetAsSeries(spread, true);
//
// Validate Calculated Bars ...
//
limit = (prev_calculated > rates_total || prev_calculated <= 0)
? rates_total
: (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
//
CalculateBuffers(
i,
prev_calculated,
rates_total,
//
open,
high,
close,
low,
tick_volume //
);
}
//
return rates_total;
}
//
// Functions ...
/**
* Validate Input Args for Initialization ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result = false;
//
result =
//
false
//
;
//
return result;
}
/**
* Extract Max Length of Inputs ...
*
* @return ( int )
*/
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
return result;
}
/**
* Define Required Buffers ...
*/
void DefineBuffers()
{
//
// Plot Buffers ...
//
// Data Buffers ...
}
/**
* Set Indicator Short Name and also we can define Buffers Labels ...
*/
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
/**
* Calculate Custom Buffers ...
*
* @param bar_index: Integer, Represent Current Bar ...
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
* @param ratesTotal: Integer, Represents All Available Bars ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param close: Double Array, History of Close Prices ...
* @param low: Double Array, History of Low Prices ...
* @param tickVolume: Long, History of Tick Volumes on Bar ...
*/
void CalculateBuffers(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int barsLimit = startCalculationForLastBars > 0
? startCalculationForLastBars
: 0;
//
// bool canCalculate = true;
bool canCalculate =
barsLimit == 0 ||
bar_index <= barsLimit;
if (canCalculate)
{
}
else
{
FillBuffersZero(bar_index);
}
}
//
// Custom ...
/**
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
*
* @param barIndex: Integer ...
*/
void FillBuffersZero(int barIndex)
{
}
//
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+983
View File
@@ -0,0 +1,983 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XCX121XSTRHelper
// Description: provides all Indicator
// Helper requirements ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// Imports ...
#include "../Classes/x-saherelm.x-helper.class.mq5"
//
// Definitions ...
//
// Definitions ...
enum ENUM_X121_XSTR_BUFFERS
{
//
X121_XSTR_LINE = 0,
X121_XSTR_ATR_LINE = 2,
X121_XSTR_PRICE_LINE = 3,
X121_XSTR_UP_LINE = 4,
X121_XSTR_DOWN_LINE = 5,
X121_XSTR_STATE_LINE = 6,
};
//
// Input Models ...
struct X121XSTRInputs
{
//
// Props ...
int strLength; // Length
double strMultiplier; // Multiplier
ENUM_APPLIED_PRICE strAppliedTo; // Applied To
//
bool showStr; // Show Upper Zone
//
// Constructor(s) ...
X121XSTRInputs()
{
//
Clean();
}
//
// Tools ...
//
// Clean ...
void Clean()
{
//
strLength = 0;
strMultiplier = 0.0;
strAppliedTo = PRICE_MEDIAN;
//
showStr = false;
}
//
// Default ...
void Default()
{
//
strLength = 14;
strMultiplier = 3.0;
strAppliedTo = PRICE_MEDIAN;
//
showStr = true;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
strLength > 0 &&
strMultiplier > 0
//
;
//
return result;
}
//
// Retrieve MAx Length ...
int Max()
{
//
int result = 0;
//
result = MathMax(1, strLength);
//
return result;
}
};
//
// Conditions ...
struct X121XSTRConditions
{
//
// Common ...
string symbol;
ENUM_TIMEFRAMES period;
datetime time;
//
// Buffers ...
double strBuffer[];
double atrBuffer[];
double strPriceBuffer[];
double strUpBuffer[];
double strDownBuffer[];
double strStateBuffer[];
//
// Conditions ...
//
bool isStrBullish;
bool isStrBearish;
//
bool isStrSwitchedToBullish;
bool isStrSwitchedToBearish;
//
// bool isCloseLower
//
// Constructor ...
X121XSTRConditions()
{
Clean();
}
//
// Tools ...
/**
* Cleaning Up ...
*/
void Clean()
{
//
// Commons ...
symbol = NULL;
period = NULL;
time = NULL;
//
// Buffers ...
//
Clean(strBuffer);
Clean(atrBuffer);
Clean(strPriceBuffer);
Clean(strUpBuffer);
Clean(strDownBuffer);
Clean(strStateBuffer);
//
ArraySetAsSeries(strBuffer, true);
ArraySetAsSeries(atrBuffer, true);
ArraySetAsSeries(strPriceBuffer, true);
ArraySetAsSeries(strUpBuffer, true);
ArraySetAsSeries(strDownBuffer, true);
ArraySetAsSeries(strStateBuffer, true);
//
// Conditions ...
//
isStrBullish = false;
isStrBearish = false;
//
isStrSwitchedToBullish = false;
isStrSwitchedToBearish = false;
//
// XDON ...
}
/**
* Generate Conditions Scores ...
*
* @param bullishScore: Double, Directional Scores Reference ...
* @param bearishScore: Double, Directional Scores Reference ...
*/
void GenerateScore(
double &bullishScore,
double &bearishScore //
)
{
//
bullishScore = 0;
bearishScore = 0;
//
// TODO: Implement if Required ...
}
/**
* Generate Summary String for Represent Conditions State ...
*
* @param onlyCommons: Boolean, Just Generate Only Commons Conditions ...
* @param onlyConditions: Boolean, Just Generate Only Conditions ...
* @param includeScores: Boolean, Attach Scores Representations on Result ...
* @param ignoreFalseConditions: Boolean, Ignore False Conditions on Result ...
* @param separator: String, Separate Lines ...
*
* @return ( string )
*/
string GenerateSummary(
bool onlyCommons = false,
bool onlyConditions = false,
bool includeScores = true,
bool ignoreFalseConditions = true,
string separator = "\n" //
)
{
//
string result = NULL;
//
double bullishScore = 0;
double bearishScore = 0;
GenerateScore(
bullishScore,
bearishScore //
);
//
string scoresStr =
//
"Scores: " + separator +
"---------------" + separator +
"Bullish: " + ToString(bullishScore) + separator +
"Bearish: " + ToString(bearishScore) + separator +
""
//
;
//
string commonStr = GenerateSpecifiedCommonSummary(
this,
separator,
includeScores //
);
//
string conditionsStr =
//
ToString("isStrBullish", isStrBullish, ignoreFalseConditions, separator) +
ToString("isStrBearish", isStrBearish, ignoreFalseConditions, separator) +
ToString("isStrSwitchedToBullish", isStrSwitchedToBullish, ignoreFalseConditions, separator) +
ToString("isStrSwitchedToBearish", isStrSwitchedToBearish, ignoreFalseConditions, separator) +
//
""
//
;
//
result =
//
"[" + GetTag() + "]" + separator +
(onlyConditions
? ""
: commonStr) +
(!includeScores
? ""
: scoresStr) +
" " + separator +
(onlyCommons
? ""
: conditionsStr) +
""
//
;
//
return result;
}
/**
* Retrieve nique Tag Identifier ...
*
* @return ( string )
*/
string GetTag()
{
return GetTypeName(this);
}
//
};
//
// Class ...
class XCX121XSTRHelper : public XCBaseHelper
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XCX121XSTRHelper()
: XCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XCX121XSTRHelper()
{
}
//
// Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
X121XSTRInputs &inputs // Inputs
)
{
//
bool result = false;
//
mSymbol = symbol;
mPeriod = period;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
ArraySetAsSeries(strBuffer, true);
ArraySetAsSeries(atrBuffer, true);
ArraySetAsSeries(strPriceBuffer, true);
ArraySetAsSeries(strUpBuffer, true);
ArraySetAsSeries(strDownBuffer, true);
ArraySetAsSeries(strStateBuffer, true);
//
mInputs = inputs;
//
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.x121.xstr",
//
// Inputs ...
//
// Market ...
"",
mInputs.strLength,
mInputs.strMultiplier,
mInputs.strAppliedTo,
//
// Presentation ...
"",
mInputs.showStr
//
);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Inputs ...
//
X121XSTRInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
X121XSTRInputs &inputs // Configs
)
{
//
return Init(
mSymbol,
mPeriod,
inputs
//
);
}
//
// Readers ...
//
// ATR ...
//
double GetATR(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(atrBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return atrBuffer[barIndex];
}
//
int CopyATR(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
atrBuffer,
buffer,
forceClean
//
);
}
//
double GetSTR(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(strBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return strBuffer[barIndex];
}
//
int CopySTR(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
strBuffer,
buffer,
forceClean
//
);
}
//
double GetSTRState(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(strStateBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return strStateBuffer[barIndex];
}
//
int CopySTRState(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
strStateBuffer,
buffer,
forceClean
//
);
}
//
double GetSTRPrice(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(strPriceBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return strPriceBuffer[barIndex];
}
//
int CopySTRPrice(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
strPriceBuffer,
buffer,
forceClean
//
);
}
//
double GetSTRUp(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(strUpBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return strUpBuffer[barIndex];
}
//
int CopySTRUp(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
strUpBuffer,
buffer,
forceClean
//
);
}
//
double GetSTRDown(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(strDownBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return strDownBuffer[barIndex];
}
//
int CopySTRDown(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
strDownBuffer,
buffer,
forceClean
//
);
}
//
bool GetConditions(
X121XSTRConditions &conditions, //
int barIndex = 0, //
int loopback = 5 //
)
{
//
bool result = true;
//
if (loopback < 5)
{
loopback = 5;
}
//
conditions.Clean();
//
conditions.symbol = mSymbol;
conditions.period = mPeriod;
conditions.time = TimeCurrent();
//
int zIndex = barIndex;
int cIndex = zIndex + 1;
int pIndex = cIndex + 1;
int ppIndex = pIndex + 1;
//
XOHCL zBar;
result = zBar.Init(
mSymbol,
mPeriod,
zIndex //
);
if (!result)
{
return result;
}
//
XOHCL cBar;
result = cBar.Init(
mSymbol,
mPeriod,
cIndex //
);
if (!result)
{
return result;
}
//
XOHCL pBar;
result = pBar.Init(
mSymbol,
mPeriod,
pIndex //
);
if (!result)
{
return result;
}
//
// Buffers ...
//
CopyATR(
zIndex,
loopback,
conditions.atrBuffer //
);
//
CopySTR(
zIndex,
loopback,
conditions.strBuffer //
);
//
CopySTRState(
zIndex,
loopback,
conditions.strStateBuffer //
);
//
CopySTRPrice(
zIndex,
loopback,
conditions.strPriceBuffer //
);
//
CopySTRUp(
zIndex,
loopback,
conditions.strUpBuffer //
);
//
CopySTRDown(
zIndex,
loopback,
conditions.strDownBuffer //
);
//
// Conditions ...
//
int cIDX = 1;
int pIDX = cIDX + 1;
//
bool isStrBullish = strStateBuffer[cIDX] > 0;
bool isStrBullishPrev = strStateBuffer[pIDX] > 0;
//
bool isStrBearish = strStateBuffer[cIDX] < 0;
bool isStrBearishPrev = strStateBuffer[pIDX] < 0;
//
bool isStrSwitchedToBullish = isStrBullish &&
!isStrBullishPrev;
bool isStrSwitchedToBearish = isStrBearish &&
!isStrBearishPrev;
//
conditions.isStrBullish = isStrBullish;
conditions.isStrBearish = isStrBearish;
conditions.isStrSwitchedToBullish = isStrSwitchedToBullish;
conditions.isStrSwitchedToBearish = isStrSwitchedToBearish;
//
return result;
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
X121XSTRInputs mInputs; // Inputs ...
//
// Buffers ...
double strBuffer[];
double atrBuffer[];
double strPriceBuffer[];
double strUpBuffer[];
double strDownBuffer[];
double strStateBuffer[];
//
void Calculate()
{
//
int totalBars = CountBars();
if (totalBars > 1000)
{
totalBars = 1000;
}
//
// Buffers ...
//
// STR ...
CopyBuffer(
mHandler,
X121_XSTR_LINE,
0,
totalBars,
strBuffer
//
);
//
// State ...
CopyBuffer(
mHandler,
X121_XSTR_STATE_LINE,
0,
totalBars,
strStateBuffer
//
);
//
// Price ...
CopyBuffer(
mHandler,
X121_XSTR_PRICE_LINE,
0,
totalBars,
strPriceBuffer
//
);
//
// Up ...
CopyBuffer(
mHandler,
X121_XSTR_UP_LINE,
0,
totalBars,
strUpBuffer
//
);
//
// STR ...
CopyBuffer(
mHandler,
X121_XSTR_DOWN_LINE,
0,
totalBars,
strDownBuffer
//
);
//
// ATR ...
//
CopyBuffer(
mHandler,
X121_XSTR_ATR_LINE,
0,
totalBars,
atrBuffer
//
);
}
};
//
// Tools ...
File diff suppressed because it is too large Load Diff
+650
View File
@@ -0,0 +1,650 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: X121 XATR
// Description: XATR ...
//
//
// 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 X121 XATR Indicator"
#property strict
//
// Definitions ...
//
#define ShortName "X121 XATR"
//
// Includes Common Library ...
#include "../Classes/x-saherelm.x-poi.class.mq5"
#include "../Classes/x-saherelm.x-poi.drawer.class.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
//
input group "RSI Detection";
input int rsiLength = 14; // Length
input ENUM_APPLIED_PRICE rsiAppliedTo = PRICE_CLOSE; // Applied To
//
input group "ATR Detection";
input int atrLength = 14; // Length
input double atrMultiplier = 1; // Multiplier
input ENUM_APPLIED_PRICE atrUpperAppliedTo = PRICE_HIGH; // Upper Zone Applied To
input ENUM_APPLIED_PRICE atrLowerAppliedTo = PRICE_LOW; // Lower Zone Applied To
input ENUM_X_MA_METHOD atrSmoothingMode = X_MA_MODE_EMA; // Smoothing Method
//
input group "Presentation";
//
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
//
input bool showAtrUpper = true; // Show Upper Zone
input bool showAtrLower = true; // Show Lower Zone
//
// Buffers ...
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
#define neuturalColorIDX 3
//
#property indicator_chart_window
//
#property indicator_buffers 6
#property indicator_plots 2
//
// ATR ...
//
// Upper ...
//
#define atrUpperBufferIndex 0
double atrUpperBuffer[];
#property indicator_label1 "X121 ATRU"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrYellow
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
//
// Lower ...
//
#define atrLowerBufferIndex 1
double atrLowerBuffer[];
#property indicator_label2 "X121 ATRL"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrYellow
#property indicator_style2 STYLE_SOLID
#property indicator_width2 2
//
// Data Buffers ...
//
int mLastBufferIndex = 1;
//
// ATR ...
#define atrBufferIndex mLastBufferIndex + 1
double atrBuffer[];
#define atrUpperRawBufferIndex mLastBufferIndex + 2
double atrUpperRawBuffer[];
#define atrLowerRawBufferIndex mLastBufferIndex + 3
double atrLowerRawBuffer[];
//
// RSI ...
#define rsiBufferIndex mLastBufferIndex + 4
double rsiBuffer[];
//
// Variables, Properties and etc ...
//
// this counts Available Bars ...
int limit;
//
int maxLength;
//
// RSI Handler ...
int rsiHandler = INVALID_HANDLE;
//
// ATR Handler ...
int atrHandler = INVALID_HANDLE;
//
bool isStrTrendChanged;
bool isStrStartBearishTrend;
bool isStrStartBullishTrend;
//
// Event Handlers ...
/**
* Initialize Indicator ...
*
* @return ( int )
*/
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initialize Indicator Handlers ...
//
// RSI ...
rsiHandler = iRSI(
_Symbol,
_Period,
rsiLength,
rsiAppliedTo //
);
bool isInited = rsiHandler != INVALID_HANDLE;
if (!isInited)
{
return INIT_FAILED;
}
//
// ATR ...
atrHandler = iATR(
_Symbol,
_Period,
atrLength //
);
isInited = atrHandler != INVALID_HANDLE;
if (!isInited)
{
return INIT_FAILED;
}
//
// 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 ...
maxLength = ExtractMaxLengthOfInputs();
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
/**
* De Initialize Indicator ...
*
* @param reason: Integer, De Initialization Reason ...
*/
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs 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 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
//
IndicatorRelease(rsiHandler);
IndicatorRelease(atrHandler);
}
/**
* Calculate Bars ...
*
* @param rates_total: Integer, Total Bars on Chart ...
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
* @param time: DateTime Array, History of Open Time ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param low: Double Array, History of Low Prices ...
* @param close: Double Array, History of Close Prices ...
* @param tick_volume: Long, History of Tick Volumes on Bar ...
* @param volume: Long, History of Trade Volumes ...
* @param spread: Double, History of Spread Price ...
*
* @return ( int )
*/
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[] //
)
{
//
// Prepare Buffers ...
ArraySetAsSeries(time, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
ArraySetAsSeries(volume, true);
ArraySetAsSeries(spread, true);
//
// Fill All Buffers by Zero ...
if (prev_calculated == 0)
{
}
//
// Validate Calculated Bars ...
//
// RSI ...
int rsiCalculatedBars = BarsCalculated(rsiHandler);
//
// ATR ...
int atrCalculatedBars = BarsCalculated(atrHandler);
//
bool isPassedRequiredCalculatedBars =
//
// RSI ...
rsiCalculatedBars >= maxLength &&
//
// ATR ...
atrCalculatedBars >= maxLength
//
;
if (!isPassedRequiredCalculatedBars)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0)
? rates_total
: (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
//
// RSI ...
int copiedRsis = CopyBuffer(rsiHandler, 0, 0, limit, rsiBuffer);
//
// ATR ...
int copiedAtrs = CopyBuffer(atrHandler, 0, 0, limit, atrBuffer);
//
// Validate Copied Items ...
bool isPassedRequiredCopiedItems =
//
//
// RSI ...
copiedRsis > 0 &&
//
// ATR ...
copiedAtrs > 0
//
;
if (!isPassedRequiredCopiedItems)
{
return prev_calculated;
}
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
//
CalculateBuffers(
i,
prev_calculated,
rates_total,
//
open,
high,
close,
low,
tick_volume //
);
}
//
return rates_total;
}
//
// Functions ...
/**
* Validate Input Args for Initialization ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result =
//
// RSI ...
rsiLength > 0 &&
//
// ATR ...
atrLength > 0 &&
atrMultiplier > 0
//
;
//
return result;
}
/**
* Extract Max Length of Inputs ...
*
* @return ( int )
*/
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(rsiLength, atrLength);
//
return result;
}
/**
* Define Required Buffers ...
*/
void DefineBuffers()
{
//
// ATR ...
//
// UPPER ...
bool canShowAtrUpper = showAtrUpper;
ENUM_DRAW_TYPE atrUpperDrawType = canShowAtrUpper ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(atrUpperBuffer, true);
SetIndexBuffer(atrUpperBufferIndex, atrUpperBuffer, INDICATOR_DATA);
PlotIndexSetDouble(atrUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(atrUpperBufferIndex, PLOT_SHOW_DATA, canShowAtrUpper);
PlotIndexSetInteger(atrUpperBufferIndex, PLOT_DRAW_TYPE, atrUpperDrawType);
//
// LOWER ...
bool canShowAtrLower = showAtrLower;
ENUM_DRAW_TYPE atrLowerDrawType = canShowAtrLower ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(atrLowerBuffer, true);
SetIndexBuffer(atrLowerBufferIndex, atrLowerBuffer, INDICATOR_DATA);
PlotIndexSetDouble(atrLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(atrLowerBufferIndex, PLOT_SHOW_DATA, canShowAtrLower);
PlotIndexSetInteger(atrLowerBufferIndex, PLOT_DRAW_TYPE, atrLowerDrawType);
//
// Data Buffers ...
//
// ATR ...
//
ArraySetAsSeries(atrBuffer, true);
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(atrUpperRawBuffer, true);
SetIndexBuffer(atrUpperRawBufferIndex, atrUpperRawBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(atrLowerRawBuffer, true);
SetIndexBuffer(atrLowerRawBufferIndex, atrLowerRawBuffer, INDICATOR_CALCULATIONS);
//
// RSI ...
//
ArraySetAsSeries(rsiBuffer, true);
SetIndexBuffer(rsiBufferIndex, rsiBuffer, INDICATOR_CALCULATIONS);
}
/**
* Set Indicator Short Name and also we can define Buffers Labels ...
*/
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
/**
* Calculate Custom Buffers ...
*
* @param bar_index: Integer, Represent Current Bar ...
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
* @param ratesTotal: Integer, Represents All Available Bars ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param close: Double Array, History of Close Prices ...
* @param low: Double Array, History of Low Prices ...
* @param tickVolume: Long, History of Tick Volumes on Bar ...
*/
void CalculateBuffers(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int barsLimit = startCalculationForLastBars > 0
? startCalculationForLastBars
: 0;
//
// bool canCalculate = true;
bool canCalculate =
barsLimit == 0 ||
bar_index <= barsLimit;
if (canCalculate)
{
//
CalculateAtrZones(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low //
);
}
else
{
FillBuffersZero(bar_index);
}
}
//
// Custom ...
/**
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
*
* @param barIndex: Integer ...
*/
void FillBuffersZero(int barIndex)
{
//
// RSIS ...
rsiBuffer[barIndex] = 0;
//
// ATRS ...
atrBuffer[barIndex] = 0;
atrUpperBuffer[barIndex] = 0;
atrUpperRawBuffer[barIndex] = 0;
atrUpperBuffer[barIndex] = 0;
atrLowerRawBuffer[barIndex] = 0;
}
/**
* Calculate ATR Zones ...
*
* @param bar_index: Integer, Represent Current Bar ...
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
* @param ratesTotal: Integer, Represents All Available Bars ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param close: Double Array, History of Close Prices ...
* @param low: Double Array, History of Low Prices ...
*/
void CalculateAtrZones(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[] //
)
{
//
// Select ATr Value ...
double atrValue = atrBuffer[bar_index];
double appliedAtrMultiplierValue = atrValue * atrMultiplier;
//
// Select Upper Price ...
double upperPrice = GetAppliedPrice(
atrUpperAppliedTo,
open,
high,
low,
close,
bar_index //
);
//
// Select Lower Price ...
double lowerPrice = GetAppliedPrice(
atrLowerAppliedTo,
open,
high,
low,
close,
bar_index //
);
//
// Calculate Raw Atrs ...
//
// Upper ...
double atrUpperRawValue = upperPrice + appliedAtrMultiplierValue;
atrUpperRawBuffer[bar_index] = atrUpperRawValue;
//
// Lower ...
double atrLowerRawValue = lowerPrice - appliedAtrMultiplierValue;
atrLowerRawBuffer[bar_index] = atrLowerRawValue;
//
bool canSmooth = atrSmoothingMode != X_MA_MODE_NONE;
if (canSmooth)
{
//
// Upper ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
atrLength,
atrUpperRawBuffer,
atrUpperBuffer,
atrSmoothingMode //
);
//
// Lower ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
atrLength,
atrLowerRawBuffer,
atrLowerBuffer,
atrSmoothingMode //
);
}
else
{
//
// Use Raw Values ...
atrUpperBuffer[bar_index] = atrUpperRawValue;
atrLowerBuffer[bar_index] = atrLowerRawValue;
}
}
//
+692
View File
@@ -0,0 +1,692 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: X121 XDON
// Description: XDON ...
//
//
// 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 X121 XDON Indicator"
#property strict
//
// Definitions ...
//
#define ShortName "X121 XDON"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
input int donchainLength = 40; // Donchain Length
//
// Presentation ...
input group "Presentation";
//
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
//
input bool showUpper = true; // Show Upper Band
input bool showLower = true; // Show Lower Band
//
input bool showOpen = true; // Show Open
input bool showHigh = true; // Show High
input bool showClose = true; // Show Close
input bool showLow = true; // Show Low
//
// Buffers ...
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
#define neuturalColorIDX 3
//
#property indicator_chart_window
//
#property indicator_buffers 8
#property indicator_plots 8
//
// Plot Buffers ...
//
// Open ...
//
#define donOpenUpperBufferIndex 0
double donOpenUpperBuffer[];
//
#define donOpenUpperPlotBufferIndex 0
#property indicator_label1 "X121 O U"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrCornflowerBlue
#property indicator_width1 1
//
#define donOpenLowerBufferIndex 1
double donOpenLowerBuffer[];
//
#define donOpenLowerPlotBufferIndex 1
#property indicator_label2 "X121 O L"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrCornflowerBlue
#property indicator_width2 1
//
// High ...
//
#define donHighUpperBufferIndex 2
double donHighUpperBuffer[];
//
#define donHighUpperPlotBufferIndex 2
#property indicator_label3 "X121 H U"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrAquamarine
#property indicator_width3 1
//
#define donHighLowerBufferIndex 3
double donHighLowerBuffer[];
//
#define donHighLowerPlotBufferIndex 3
#property indicator_label4 "X121 H L"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrAquamarine
#property indicator_width4 1
//
// Low ...
//
#define donLowUpperBufferIndex 4
double donLowUpperBuffer[];
//
#define donLowUpperPlotBufferIndex 4
#property indicator_label5 "X121 L U"
#property indicator_type5 DRAW_LINE
#property indicator_color5 clrDarkOrchid
#property indicator_width5 1
//
#define donLowLowerBufferIndex 5
double donLowLowerBuffer[];
//
#define donLowLowerPlotBufferIndex 5
#property indicator_label6 "X121 L L"
#property indicator_type6 DRAW_LINE
#property indicator_color6 clrDarkOrchid
#property indicator_width6 1
//
// Close ...
//
#define donCloseUpperBufferIndex 6
double donCloseUpperBuffer[];
//
#define donCloseUpperPlotBufferIndex 6
#property indicator_label7 "X121 C U"
#property indicator_type7 DRAW_LINE
#property indicator_color7 clrCoral
#property indicator_width7 1
//
#define donCloseLowerBufferIndex 7
double donCloseLowerBuffer[];
//
#define donCloseLowerPlotBufferIndex 7
#property indicator_label8 "X121 C L"
#property indicator_type8 DRAW_LINE
#property indicator_color8 clrCoral
#property indicator_width8 1
//
// Data Buffers ...
//
int mLastBufferIndex = 7;
//
// Variables, Properties and etc ...
//
// this counts Available Bars ...
int limit;
//
int maxLength;
//
// Event Handlers ...
/**
* Initialize Indicator ...
*
* @return ( int )
*/
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initialize Indicator Handlers ...
//
// 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 ...
maxLength = ExtractMaxLengthOfInputs();
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
/**
* De Initialize Indicator ...
*
* @param reason: Integer, De Initialization Reason ...
*/
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs 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 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
}
/**
* Calculate Bars ...
*
* @param rates_total: Integer, Total Bars on Chart ...
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
* @param time: DateTime Array, History of Open Time ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param low: Double Array, History of Low Prices ...
* @param close: Double Array, History of Close Prices ...
* @param tick_volume: Long, History of Tick Volumes on Bar ...
* @param volume: Long, History of Trade Volumes ...
* @param spread: Double, History of Spread Price ...
*
* @return ( int )
*/
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[] //
)
{
//
// Prepare Buffers ...
ArraySetAsSeries(time, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
ArraySetAsSeries(volume, true);
ArraySetAsSeries(spread, true);
//
// Validate Calculated Bars ...
//
limit = (prev_calculated > rates_total || prev_calculated <= 0)
? rates_total
: (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
//
CalculateBuffers(
i,
prev_calculated,
rates_total,
//
open,
high,
close,
low,
tick_volume //
);
}
//
return rates_total;
}
//
// Functions ...
/**
* Validate Input Args for Initialization ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result = false;
//
result =
//
donchainLength > 0
//
;
//
return result;
}
/**
* Extract Max Length of Inputs ...
*
* @return ( int )
*/
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
return result;
}
/**
* Define Required Buffers ...
*/
void DefineBuffers()
{
//
// Plot Buffers ...
//
// Open ...
//
// UPPER ...
bool canShowCOpenUpper = showUpper && showOpen;
ENUM_DRAW_TYPE donOpenUpperDrawType = canShowCOpenUpper ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(donOpenUpperBuffer, true);
SetIndexBuffer(donOpenUpperBufferIndex, donOpenUpperBuffer, INDICATOR_DATA);
PlotIndexSetDouble(donOpenUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(donOpenUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCOpenUpper);
PlotIndexSetInteger(donOpenUpperPlotBufferIndex, PLOT_DRAW_TYPE, donOpenUpperDrawType);
//
// LOWER ...
bool canShowCOpenLower = showLower && showOpen;
ENUM_DRAW_TYPE donOpenLowerDrawType = canShowCOpenLower ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(donOpenLowerBuffer, true);
SetIndexBuffer(donOpenLowerBufferIndex, donOpenLowerBuffer, INDICATOR_DATA);
PlotIndexSetDouble(donOpenLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(donOpenLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCOpenLower);
PlotIndexSetInteger(donOpenLowerPlotBufferIndex, PLOT_DRAW_TYPE, donOpenLowerDrawType);
//
// Close ...
//
// UPPER ...
bool canShowCCloseUpper = showUpper && showClose;
ENUM_DRAW_TYPE donCloseUpperDrawType = canShowCCloseUpper ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(donCloseUpperBuffer, true);
SetIndexBuffer(donCloseUpperBufferIndex, donCloseUpperBuffer, INDICATOR_DATA);
PlotIndexSetDouble(donCloseUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(donCloseUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCCloseUpper);
PlotIndexSetInteger(donCloseUpperPlotBufferIndex, PLOT_DRAW_TYPE, donCloseUpperDrawType);
//
// LOWER ...
bool canShowCCloseLower = showLower && showClose;
ENUM_DRAW_TYPE donCloseLowerDrawType = canShowCCloseLower ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(donCloseLowerBuffer, true);
SetIndexBuffer(donCloseLowerBufferIndex, donCloseLowerBuffer, INDICATOR_DATA);
PlotIndexSetDouble(donCloseLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(donCloseLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCCloseLower);
PlotIndexSetInteger(donCloseLowerPlotBufferIndex, PLOT_DRAW_TYPE, donCloseLowerDrawType);
//
// High ...
//
// UPPER ...
bool canShowCHighUpper = showUpper && showHigh;
ENUM_DRAW_TYPE donHighUpperDrawType = canShowCHighUpper ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(donHighUpperBuffer, true);
SetIndexBuffer(donHighUpperBufferIndex, donHighUpperBuffer, INDICATOR_DATA);
PlotIndexSetDouble(donHighUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(donHighUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCHighUpper);
PlotIndexSetInteger(donHighUpperPlotBufferIndex, PLOT_DRAW_TYPE, donHighUpperDrawType);
//
// LOWER ...
bool canShowCHighLower = showLower && showHigh;
ENUM_DRAW_TYPE donHighLowerDrawType = canShowCHighLower ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(donHighLowerBuffer, true);
SetIndexBuffer(donHighLowerBufferIndex, donHighLowerBuffer, INDICATOR_DATA);
PlotIndexSetDouble(donHighLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(donHighLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCHighLower);
PlotIndexSetInteger(donHighLowerPlotBufferIndex, PLOT_DRAW_TYPE, donHighLowerDrawType);
//
// Low ...
//
// UPPER ...
bool canShowCLowUpper = showUpper && showLow;
ENUM_DRAW_TYPE donLowUpperDrawType = canShowCLowUpper ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(donLowUpperBuffer, true);
SetIndexBuffer(donLowUpperBufferIndex, donLowUpperBuffer, INDICATOR_DATA);
PlotIndexSetDouble(donLowUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(donLowUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCLowUpper);
PlotIndexSetInteger(donLowUpperPlotBufferIndex, PLOT_DRAW_TYPE, donLowUpperDrawType);
//
// LOWER ...
bool canShowCLowLower = showLower && showLow;
ENUM_DRAW_TYPE donLowLowerDrawType = canShowCLowLower ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(donLowLowerBuffer, true);
SetIndexBuffer(donLowLowerBufferIndex, donLowLowerBuffer, INDICATOR_DATA);
PlotIndexSetDouble(donLowLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(donLowLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCLowLower);
PlotIndexSetInteger(donLowLowerPlotBufferIndex, PLOT_DRAW_TYPE, donLowLowerDrawType);
//
// Data Buffers ...
}
/**
* Set Indicator Short Name and also we can define Buffers Labels ...
*/
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
/**
* Calculate Custom Buffers ...
*
* @param bar_index: Integer, Represent Current Bar ...
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
* @param ratesTotal: Integer, Represents All Available Bars ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param close: Double Array, History of Close Prices ...
* @param low: Double Array, History of Low Prices ...
* @param tickVolume: Long, History of Tick Volumes on Bar ...
*/
void CalculateBuffers(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int barsLimit = startCalculationForLastBars > 0
? startCalculationForLastBars
: 0;
//
// bool canCalculate = true;
bool canCalculate =
barsLimit == 0 ||
bar_index <= barsLimit;
if (canCalculate)
{
//
CalculateDonchains(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
}
else
{
FillBuffersZero(bar_index);
}
}
//
// Custom ...
/**
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
*
* @param barIndex: Integer ...
*/
void FillBuffersZero(int barIndex)
{
//
donOpenUpperBuffer[barIndex] = EMPTY_VALUE;
donOpenLowerBuffer[barIndex] = EMPTY_VALUE;
donCloseUpperBuffer[barIndex] = EMPTY_VALUE;
donCloseLowerBuffer[barIndex] = EMPTY_VALUE;
donHighUpperBuffer[barIndex] = EMPTY_VALUE;
donHighLowerBuffer[barIndex] = EMPTY_VALUE;
donLowUpperBuffer[barIndex] = EMPTY_VALUE;
donLowLowerBuffer[barIndex] = EMPTY_VALUE;
}
/**
* Calculate Donchain ...
*
* @param bar_index: Integer, Bar Index ...
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
* @param ratesTotal: Integer, Represents All Available Bars ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param close: Double Array, History of Close Prices ...
* @param low: Double Array, History of Low Prices ...
* @param tickVolume: Long, History of Tick Volumes on Bar ...
* @param _length: Integer, Donchain Length ...
* @param _ouBuffer: Double Array Reference ...
* @param _olBuffer: Double Array Reference ...
* @param _huBuffer: Double Array Reference ...
* @param _hlBuffer: Double Array Reference ...
* @param _luBuffer: Double Array Reference ...
* @param _llBuffer: Double Array Reference ...
* @param _cuBuffer: Double Array Reference ...
* @param _clBuffer: Double Array Reference ...
*/
void CalculateDonchain(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
//
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[],
//
int _length,
//
double &_ouBuffer[],
double &_olBuffer[],
double &_huBuffer[],
double &_hlBuffer[],
double &_luBuffer[],
double &_llBuffer[],
double &_cuBuffer[],
double &_clBuffer[] //
)
{
//
double iUpper = 0;
double iLower = 0;
//
// OPEN ...
//
int from = bar_index;
//
iUpper = open[ArrayMaximum(open, from, _length)];
iLower = open[ArrayMinimum(open, from, _length)];
//
_ouBuffer[bar_index] = iUpper;
_olBuffer[bar_index] = iLower;
//
// HIGH ...
//
iUpper = high[ArrayMaximum(high, from, _length)];
iLower = high[ArrayMinimum(high, from, _length)];
//
_huBuffer[bar_index] = iUpper;
_hlBuffer[bar_index] = iLower;
//
// LOW ...
//
iUpper = low[ArrayMaximum(low, from, _length)];
iLower = low[ArrayMinimum(low, from, _length)];
//
_luBuffer[bar_index] = iUpper;
_llBuffer[bar_index] = iLower;
//
// CLOSE ...
//
iUpper = close[ArrayMaximum(close, from, _length)];
iLower = close[ArrayMinimum(close, from, _length)];
//
_cuBuffer[bar_index] = iUpper;
_clBuffer[bar_index] = iLower;
}
/**
* Calculate Different VWaps ...
*
* @param bar_index: Integer, Represent Current Bar ...
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
* @param ratesTotal: Integer, Represents All Available Bars ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param close: Double Array, History of Close Prices ...
* @param low: Double Array, History of Low Prices ...
* @param tickVolume: Long, History of Tick Volumes on Bar ...
*/
void CalculateDonchains(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
CalculateDonchain(
//
bar_index,
prevCalculated,
ratesTotal,
//
open,
high,
close,
low,
tickVolume,
//
donchainLength,
//
donOpenUpperBuffer,
donOpenLowerBuffer,
donHighUpperBuffer,
donHighLowerBuffer,
donLowUpperBuffer,
donLowLowerBuffer,
donCloseUpperBuffer,
donCloseLowerBuffer //
);
}
//
File diff suppressed because it is too large Load Diff
+623
View File
@@ -0,0 +1,623 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: X121 XSTR
// Description: XSTR ...
//
//
// 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 X121 XSTR Indicator"
#property strict
//
// Definitions ...
//
#define ShortName "X121 XSTR"
//
// Includes Common Library ...
#include "../Classes/x-saherelm.x-poi.class.mq5"
#include "../Classes/x-saherelm.x-poi.drawer.class.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
input int strLength = 14; // Length
input double strMultiplier = 3; // Multiplier
input ENUM_APPLIED_PRICE strAppliedTo = PRICE_MEDIAN; // Applied To
//
input group "Presentation";
//
input bool showStr = true; // Show Str
//
// Buffers ...
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
#define neuturalColorIDX 3
//
#property indicator_chart_window
//
#property indicator_buffers 7
#property indicator_plots 1
//
// STR ...
#define strBufferIndex 0
double strBuffer[];
#define strColorBufferIndex 1
double strColorBuffer[];
//
#define strPlotBufferIndex 1
#property indicator_label1 "X121 STR"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 CLR_NONE, clrLime, clrRed, clrGray
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
//
// Data Buffers ...
//
int mLastBufferIndex = 1;
//
// STR ...
//
// Atr ...
#define atrBufferIndex mLastBufferIndex + 1
double atrBuffer[];
//
// Price ...
#define strPriceBufferIndex mLastBufferIndex + 2
double strPriceBuffer[];
//
// Up ...
#define strUpBufferIndex mLastBufferIndex + 3
double strUpBuffer[];
//
// Down ...
#define strDownBufferIndex mLastBufferIndex + 4
double strDownBuffer[];
//
// Trend ...
#define strStateBufferIndex mLastBufferIndex + 5
double strStateBuffer[];
//
// Variables, Properties and etc ...
//
// this counts Available Bars ...
int limit;
//
int maxLength;
//
// ATR Handler ...
int atrHandler = INVALID_HANDLE;
//
bool isStrTrendChanged;
bool isStrStartBearishTrend;
bool isStrStartBullishTrend;
//
int changeOfTrend;
int startBearishTrend;
int startBullishTrend;
//
// Event Handlers ...
/**
* Initialize Indicator ...
*
* @return ( int )
*/
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initialize Indicator Handlers ...
//
// ATR ...
atrHandler = iATR(
_Symbol,
_Period,
strLength //
);
bool isInited = atrHandler != INVALID_HANDLE;
if (!isInited)
{
return INIT_FAILED;
}
//
// 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 ...
maxLength = ExtractMaxLengthOfInputs();
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
/**
* De Initialize Indicator ...
*
* @param reason: Integer, De Initialization Reason ...
*/
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs 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 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
//
IndicatorRelease(atrHandler);
}
/**
* Calculate Bars ...
*
* @param rates_total: Integer, Total Bars on Chart ...
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
* @param time: DateTime Array, History of Open Time ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param low: Double Array, History of Low Prices ...
* @param close: Double Array, History of Close Prices ...
* @param tick_volume: Long, History of Tick Volumes on Bar ...
* @param volume: Long, History of Trade Volumes ...
* @param spread: Double, History of Spread Price ...
*
* @return ( int )
*/
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[] //
)
{
//
// Prepare Buffers ...
//
// Fill All Buffers by Zero ...
if (prev_calculated == 0)
{
}
//
int numOfRequiredAtrs = (prev_calculated > rates_total || prev_calculated < 0)
? rates_total
: rates_total - prev_calculated;
if (prev_calculated > 0)
{
numOfRequiredAtrs++;
}
//
// Validate Calculated Bars ...
//
// ATR ...
int atrCalculatedBars = BarsCalculated(atrHandler);
//
bool isPassedRequiredCalculatedBars =
//
// ATR ...
atrCalculatedBars >= numOfRequiredAtrs
//
;
if (!isPassedRequiredCalculatedBars)
{
return prev_calculated;
}
//
//
// checking for the limit start of calculation of an indicator ...
limit =
(prev_calculated > rates_total || prev_calculated <= 0)
? maxLength
: prev_calculated - 1;
//
// Buffers Copy ...
//
// ATR ...
int copiedAtrs = CopyBuffer(atrHandler, 0, 0, numOfRequiredAtrs, atrBuffer);
//
// Validate Copied Items ...
bool isPassedRequiredCopiedItems =
//
// ATR ...
copiedAtrs >= numOfRequiredAtrs
//
;
if (!isPassedRequiredCopiedItems)
{
return prev_calculated;
}
//
// Main Loop ...
for (int i = limit; i < rates_total && !IsStopped(); i++)
{
//
CalculateBuffers(
i,
prev_calculated,
rates_total,
//
open,
high,
close,
low,
tick_volume //
);
}
//
return rates_total;
}
//
// Functions ...
/**
* Validate Input Args for Initialization ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result =
//
// STR ...
strLength > 0 &&
strMultiplier > 0
//
;
//
return result;
}
/**
* Extract Max Length of Inputs ...
*
* @return ( int )
*/
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(1, strLength);
//
return result;
}
/**
* Define Required Buffers ...
*/
void DefineBuffers()
{
//
// STR ...
SetIndexBuffer(strBufferIndex, strBuffer, INDICATOR_DATA);
SetIndexBuffer(strColorBufferIndex, strColorBuffer, INDICATOR_COLOR_INDEX);
//
// Data Buffers ...
//
// STR ...
//
SetIndexBuffer(strUpBufferIndex, strUpBuffer, INDICATOR_CALCULATIONS);
SetIndexBuffer(strDownBufferIndex, strDownBuffer, INDICATOR_CALCULATIONS);
SetIndexBuffer(strPriceBufferIndex, strPriceBuffer, INDICATOR_CALCULATIONS);
SetIndexBuffer(strStateBufferIndex, strStateBuffer, INDICATOR_CALCULATIONS);
}
/**
* Set Indicator Short Name and also we can define Buffers Labels ...
*/
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
/**
* Calculate Custom Buffers ...
*
* @param bar_index: Integer, Represent Current Bar ...
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
* @param ratesTotal: Integer, Represents All Available Bars ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param close: Double Array, History of Close Prices ...
* @param low: Double Array, History of Low Prices ...
* @param tickVolume: Long, History of Tick Volumes on Bar ...
*/
void CalculateBuffers(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
CalculateStr(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low //
);
}
//
// Custom ...
/**
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
*
* @param barIndex: Integer ...
*/
void FillBuffersZero(int barIndex)
{
//
// STR ...
strBuffer[barIndex] = 0;
strUpBuffer[barIndex] = 0;
strDownBuffer[barIndex] = 0;
strPriceBuffer[barIndex] = 0;
strColorBuffer[barIndex] = hideColorIDX;
strStateBuffer[barIndex] = hideColorIDX;
}
/**
* Calculate STR ...
*
* @param bar_index: Integer, Represent Current Bar ...
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
* @param ratesTotal: Integer, Represents All Available Bars ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param close: Double Array, History of Close Prices ...
* @param low: Double Array, History of Low Prices ...
*/
void CalculateStr(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[] //
)
{
//
// Calculated Price ...
double price = GetAppliedPrice(
strAppliedTo,
open,
high,
low,
close,
bar_index //
);
strPriceBuffer[bar_index] = price;
//
double atr = atrBuffer[bar_index];
//
// Up ...
strUpBuffer[bar_index] = price + (strMultiplier * atr);
//
// Down ...
strDownBuffer[bar_index] = price - (strMultiplier * atr);
//
if (close[bar_index] > strUpBuffer[bar_index - 1])
{
//
strStateBuffer[bar_index] = 1;
if (strStateBuffer[bar_index - 1] == -1)
{
changeOfTrend = 1;
}
}
else if (close[bar_index] < strDownBuffer[bar_index - 1])
{
//
strStateBuffer[bar_index] = -1;
if (strStateBuffer[bar_index - 1] == 1)
{
changeOfTrend = 1;
}
}
else if (strStateBuffer[bar_index - 1] == 1)
{
//
strStateBuffer[bar_index] = 1;
changeOfTrend = 0;
}
else if (strStateBuffer[bar_index - 1] == -1)
{
//
strStateBuffer[bar_index] = -1;
changeOfTrend = 0;
}
//
// Down Trend Starting ...
if (strStateBuffer[bar_index] < 0 && strStateBuffer[bar_index - 1] > 0)
{
startBearishTrend = 1;
}
else
{
startBearishTrend = 0;
}
//
// Up Trend Starting ...
if (strStateBuffer[bar_index] > 0 && strStateBuffer[bar_index - 1] < 0)
{
startBullishTrend = 1;
}
else
{
startBullishTrend = 0;
}
//
if (strStateBuffer[bar_index] > 0 && strDownBuffer[bar_index] < strDownBuffer[bar_index - 1])
{
strDownBuffer[bar_index] = strDownBuffer[bar_index - 1];
}
//
if (strStateBuffer[bar_index] < 0 && strUpBuffer[bar_index] > strUpBuffer[bar_index - 1])
{
strUpBuffer[bar_index] = strUpBuffer[bar_index - 1];
}
//
if (startBearishTrend == 1)
{
strUpBuffer[bar_index] = strPriceBuffer[bar_index] + (strMultiplier * atr);
}
//
if (startBullishTrend == 1)
{
strDownBuffer[bar_index] = strPriceBuffer[bar_index] - (strMultiplier * atr);
}
//
// Draw the indicator ...
//
double colorIDX = hideColorIDX;
strColorBuffer[bar_index] = colorIDX;
//
if (strStateBuffer[bar_index] == 1)
{
//
strBuffer[bar_index] = strDownBuffer[bar_index];
if (changeOfTrend == 1)
{
strBuffer[bar_index - 1] = strBuffer[bar_index - 2];
changeOfTrend = 0;
}
//
colorIDX = bullishColorIDX;
}
else if (strStateBuffer[bar_index] == -1)
{
//
strBuffer[bar_index] = strUpBuffer[bar_index];
if (changeOfTrend == 1)
{
//
strBuffer[bar_index - 1] = strBuffer[bar_index - 2];
changeOfTrend = 0;
}
//
colorIDX = bearishColorIDX;
}
//
if (showStr)
{
strColorBuffer[bar_index] = colorIDX;
}
}
//
+711
View File
@@ -0,0 +1,711 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: X121 XVWAP
// Description: XVWAP ...
//
//
// 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 X121 XVWAP Indicator"
#property strict
//
// Definitions ...
//
#define ShortName "X121 XVWAP"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
input int vwapFastLength = 20; // Fast Length
input int vwapMidLength = 40; // Mid Length
input int vwapSlowLength = 60; // Slow Length
input ENUM_APPLIED_PRICE vwapAppliedTo = PRICE_CLOSE; // Applied To
//
// Presentation ...
input group "Presentation";
//
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
//
input bool showVWapFast = true; // Show VWap Fast
input bool showVWapMedium = true; // Show VWap Medium
input bool showVWapSlow = true; // Show VWap Slow
//
// Buffers ...
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
#define neuturalColorIDX 3
//
#property indicator_chart_window
//
#property indicator_buffers 11
#property indicator_plots 3
//
// Plot Buffers ...
//
// FAST ...
#define vwapFastBufferIndex 0
double vwapFastBuffer[];
#define vwapFastColorBufferIndex 1
double vwapFastColorBuffer[];
//
#define vwapFastPlotBufferIndex 0
#property indicator_label1 "X121 VWF"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 CLR_NONE, clrAqua, clrMagenta, clrGray
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
//
// MID ...
#define vwapMidBufferIndex 2
double vwapMidBuffer[];
#define vwapMidColorBufferIndex 3
double vwapMidColorBuffer[];
//
#define vwapMidPlotBufferIndex 1
#property indicator_label2 "X121 VWM"
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style2 STYLE_SOLID
#property indicator_width2 2
//
// SLOW ...
#define vwapSlowBufferIndex 4
double vwapSlowBuffer[];
#define vwapSlowColorBufferIndex 5
double vwapSlowColorBuffer[];
//
#define vwapSlowPlotBufferIndex 2
#property indicator_label3 "X121 VWS"
#property indicator_type3 DRAW_COLOR_LINE
#property indicator_color3 CLR_NONE, clrSteelBlue, clrDarkRed, clrGray
#property indicator_style3 STYLE_SOLID
#property indicator_width3 2
//
// Data Buffers ...
//
int mLastBufferIndex = 5;
//
// Volume ...
#define vwapVolumeBufferIndex mLastBufferIndex + 1
double vwapVolumeBuffer[];
//
// Price ...
#define vwapPriceBufferIndex mLastBufferIndex + 2
double vwapPriceBuffer[];
//
// Fast State ...
#define vwapFastStateBufferIndex mLastBufferIndex + 3
double vwapFastStateBuffer[];
//
// Mid State ...
#define vwapMidStateBufferIndex mLastBufferIndex + 4
double vwapMidStateBuffer[];
//
// Slow State ...
#define vwapSlowStateBufferIndex mLastBufferIndex + 5
double vwapSlowStateBuffer[];
//
// Variables, Properties and etc ...
//
// this counts Available Bars ...
int limit;
//
int maxLength;
//
// Event Handlers ...
/**
* Initialize Indicator ...
*
* @return ( int )
*/
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initialize Indicator Handlers ...
//
// 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 ...
maxLength = ExtractMaxLengthOfInputs();
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
/**
* De Initialize Indicator ...
*
* @param reason: Integer, De Initialization Reason ...
*/
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs 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 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
}
/**
* Calculate Bars ...
*
* @param rates_total: Integer, Total Bars on Chart ...
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
* @param time: DateTime Array, History of Open Time ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param low: Double Array, History of Low Prices ...
* @param close: Double Array, History of Close Prices ...
* @param tick_volume: Long, History of Tick Volumes on Bar ...
* @param volume: Long, History of Trade Volumes ...
* @param spread: Double, History of Spread Price ...
*
* @return ( int )
*/
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[] //
)
{
//
// Prepare Buffers ...
ArraySetAsSeries(time, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
ArraySetAsSeries(volume, true);
ArraySetAsSeries(spread, true);
//
// Validate Calculated Bars ...
//
limit = (prev_calculated > rates_total || prev_calculated <= 0)
? rates_total
: (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
//
CalculateBuffers(
i,
prev_calculated,
rates_total,
//
open,
high,
close,
low,
tick_volume //
);
}
//
return rates_total;
}
//
// Functions ...
/**
* Validate Input Args for Initialization ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result = false;
//
result =
//
vwapFastLength > 2 &&
vwapMidLength > vwapFastLength &&
vwapSlowLength > vwapMidLength
//
;
//
return result;
}
/**
* Extract Max Length of Inputs ...
*
* @return ( int )
*/
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
// XVWAP ...
result = MathMax(result, vwapFastLength);
result = MathMax(result, vwapMidLength);
result = MathMax(result, vwapSlowLength);
//
return result;
}
/**
* Define Required Buffers ...
*/
void DefineBuffers()
{
//
// Plot Buffers ...
//
// Fast ...
ArraySetAsSeries(vwapFastBuffer, true);
ArraySetAsSeries(vwapFastColorBuffer, true);
SetIndexBuffer(vwapFastBufferIndex, vwapFastBuffer, INDICATOR_DATA);
SetIndexBuffer(vwapFastColorBufferIndex, vwapFastColorBuffer, INDICATOR_COLOR_INDEX);
//
// Mid ...
ArraySetAsSeries(vwapMidBuffer, true);
ArraySetAsSeries(vwapMidColorBuffer, true);
SetIndexBuffer(vwapMidBufferIndex, vwapMidBuffer, INDICATOR_DATA);
SetIndexBuffer(vwapMidColorBufferIndex, vwapMidColorBuffer, INDICATOR_COLOR_INDEX);
//
// Slow ...
ArraySetAsSeries(vwapSlowBuffer, true);
ArraySetAsSeries(vwapSlowColorBuffer, true);
SetIndexBuffer(vwapSlowBufferIndex, vwapSlowBuffer, INDICATOR_DATA);
SetIndexBuffer(vwapSlowColorBufferIndex, vwapSlowColorBuffer, INDICATOR_COLOR_INDEX);
//
// Data Buffers ...
//
// Volumes ...
ArraySetAsSeries(vwapVolumeBuffer, true);
SetIndexBuffer(vwapVolumeBufferIndex, vwapVolumeBuffer, INDICATOR_CALCULATIONS);
//
// Price ...
ArraySetAsSeries(vwapPriceBuffer, true);
SetIndexBuffer(vwapPriceBufferIndex, vwapPriceBuffer, INDICATOR_CALCULATIONS);
//
// Fast State ...
ArraySetAsSeries(vwapFastStateBuffer, true);
SetIndexBuffer(vwapFastStateBufferIndex, vwapFastStateBuffer, INDICATOR_CALCULATIONS);
//
// Mid State ...
ArraySetAsSeries(vwapMidStateBuffer, true);
SetIndexBuffer(vwapMidStateBufferIndex, vwapMidStateBuffer, INDICATOR_CALCULATIONS);
//
// Slow State ...
ArraySetAsSeries(vwapSlowStateBuffer, true);
SetIndexBuffer(vwapSlowStateBufferIndex, vwapSlowStateBuffer, INDICATOR_CALCULATIONS);
}
/**
* Set Indicator Short Name and also we can define Buffers Labels ...
*/
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
/**
* Calculate Custom Buffers ...
*
* @param bar_index: Integer, Represent Current Bar ...
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
* @param ratesTotal: Integer, Represents All Available Bars ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param close: Double Array, History of Close Prices ...
* @param low: Double Array, History of Low Prices ...
* @param tickVolume: Long, History of Tick Volumes on Bar ...
*/
void CalculateBuffers(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int barsLimit = startCalculationForLastBars > 0
? startCalculationForLastBars
: 0;
//
// bool canCalculate = true;
bool canCalculate =
barsLimit == 0 ||
bar_index <= barsLimit;
if (canCalculate)
{
//
// Calculate Required VWAP Data Buffers ...
if (ratesTotal - bar_index <= maxLength)
{
//
CalculateVWAPDataBuffers(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
// Prevent Moving Forward ...
}
else
{
//
CalculateVWAPDataBuffers(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
CalculateVWAPS(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
}
}
else
{
FillBuffersZero(bar_index);
}
}
//
// Custom ...
/**
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
*
* @param barIndex: Integer ...
*/
void FillBuffersZero(int barIndex)
{
//
vwapFastBuffer[barIndex] = EMPTY_VALUE;
vwapMidBuffer[barIndex] = EMPTY_VALUE;
vwapSlowBuffer[barIndex] = EMPTY_VALUE;
vwapVolumeBuffer[barIndex] = EMPTY_VALUE;
vwapPriceBuffer[barIndex] = EMPTY_VALUE;
//
vwapFastColorBuffer[barIndex] = hideColorIDX;
vwapMidColorBuffer[barIndex] = hideColorIDX;
vwapSlowColorBuffer[barIndex] = hideColorIDX;
vwapFastStateBuffer[barIndex] = hideColorIDX;
vwapMidStateBuffer[barIndex] = hideColorIDX;
vwapSlowStateBuffer[barIndex] = hideColorIDX;
}
/**
* Calculate VWAP Value for Specified Bar ...
*
* @param bar_index: Integer, Represent Current Bar ...
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
* @param ratesTotal: Integer, Represents All Available Bars ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param close: Double Array, History of Close Prices ...
* @param low: Double Array, History of Low Prices ...
* @param tickVolume: Long, History of Tick Volumes on Bar ...
* @param _length: Integer, Specified VWAP Length ...
* @param _show: Boolean, Specified Show Buffer or not ...
* @param _buffer: Double Array Reference, Points to Buffer ...
* @param _colorBuffer: Double Array Reference, Points to Color Buffer ...
* @param _stateBuffer: Double Array Reference, Points to State Buffer ...
*/
void CalculateVWAP(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[],
//
int _length, // Calculation Length
bool _show,
double &_buffer[],
double &_colorBuffer[],
double &_stateBuffer[] //
)
{
//
double vSum = 0;
double pSum = 0;
double mSum = 0;
for (int x = 0; x < _length; x++)
{
//
pSum += vwapPriceBuffer[x + bar_index];
vSum += vwapVolumeBuffer[x + bar_index];
mSum += vwapPriceBuffer[x + bar_index] * vwapVolumeBuffer[x + bar_index];
}
//
double iValue = mSum / vSum;
iValue = NormalizeDouble(iValue, _Digits);
//
_buffer[bar_index] = iValue;
//
bool isBullish = low[bar_index] > iValue;
bool isBearish = high[bar_index] < iValue;
//
double iColor =
isBullish
? bullishColorIDX
: isBearish
? bearishColorIDX
: neuturalColorIDX;
//
_colorBuffer[bar_index] = hideColorIDX;
_stateBuffer[bar_index] = iColor;
if (_show)
{
_colorBuffer[bar_index] = iColor;
}
}
/**
* Calculate VWAP Required Data Buffers ...
*
* @param bar_index: Integer, Represent Current Bar ...
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
* @param ratesTotal: Integer, Represents All Available Bars ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param close: Double Array, History of Close Prices ...
* @param low: Double Array, History of Low Prices ...
* @param tickVolume: Long, History of Tick Volumes on Bar ...
*/
void CalculateVWAPDataBuffers(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
double price = GetAppliedPrice(
vwapAppliedTo,
open,
high,
low,
close,
bar_index //
);
vwapPriceBuffer[bar_index] = price;
vwapVolumeBuffer[bar_index] = (double)tickVolume[bar_index];
}
/**
* Calculate Different VWaps ...
*
* @param bar_index: Integer, Represent Current Bar ...
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
* @param ratesTotal: Integer, Represents All Available Bars ...
* @param open: Double Array, History of Open Prices ...
* @param high: Double Array, History of High Prices ...
* @param close: Double Array, History of Close Prices ...
* @param low: Double Array, History of Low Prices ...
* @param tickVolume: Long, History of Tick Volumes on Bar ...
*/
void CalculateVWAPS(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
// Fast ...
CalculateVWAP(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
vwapFastLength,
showVWapFast,
vwapFastBuffer,
vwapFastColorBuffer,
vwapFastStateBuffer //
);
//
// Mid ...
CalculateVWAP(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
vwapMidLength,
showVWapMedium,
vwapMidBuffer,
vwapMidColorBuffer,
vwapMidStateBuffer //
);
//
// Fast ...
CalculateVWAP(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
vwapSlowLength,
showVWapSlow,
vwapSlowBuffer,
vwapSlowColorBuffer,
vwapSlowStateBuffer //
);
}
//
+88 -90
View File
@@ -1848,96 +1848,6 @@ struct XOHCL
return result;
}
//
// Check Bar Breaked Up ...
bool IsBreakeUp(double value)
{
//
bool result = false;
//
result =
value > 0 &&
IsValid();
if (!result)
{
return result;
}
//
XOHCL pBar;
result = GetPreviousBar(pBar);
if (!result)
{
return result;
}
//
result =
//
low > value &&
(
//
(pBar.low < value &&
pBar.high > value)
//
||
//
(pBar.high < value)
//
)
//
;
//
return result;
}
//
// Check Bar Breaked Down ...
bool IsBreakeDown(double value)
{
//
bool result = false;
//
result =
value > 0 &&
IsValid();
if (!result)
{
return result;
}
//
XOHCL pBar;
result = GetPreviousBar(pBar);
if (!result)
{
return result;
}
//
result =
//
high < value &&
(
//
(pBar.high > value &&
pBar.low < value)
//
||
//
(pBar.low > value)
//
)
//
;
//
return result;
}
//
// Other ...
string GetTag(string prefix = "")
@@ -6462,6 +6372,94 @@ double GetSlope(
return result;
}
//
// Check Bar Reject Specified Value ...
bool IsBarReject(
double value,
ENUM_X_DIRECTION dir,
XOHCL &bar //
)
{
//
bool result = false;
//
result = value > 0 &&
bar.IsValid() &&
HasDirection(dir);
if (!result)
{
return result;
}
//
bool isUp = IsBullish(dir);
bool isDown = IsBearish(dir);
//
result =
isUp
? bar.low < value &&
bar.GetDown() > value
: isDown
? bar.high > value &&
bar.GetUp() < value
: false;
//
return result;
}
//
// Check Bar Break Specified Value ...
bool IsBarBreak(
double value,
ENUM_X_DIRECTION dir,
XOHCL &bar //
)
{
//
bool result = false;
//
result = value > 0 &&
bar.IsValid() &&
HasDirection(dir);
if (!result)
{
return result;
}
//
XOHCL pBar;
result = bar.GetPreviousBar(pBar);
if (!result)
{
return result;
}
//
bool isUp = IsBullish(dir);
bool isDown = IsBearish(dir);
//
result =
isUp
? (bar.GetDown() < value &&
bar.GetUp() > value) ||
(bar.close > value &&
pBar.close < value)
: isDown
? (bar.GetUp() > value &&
bar.GetDown() < value) ||
(bar.close < value &&
pBar.close > value)
: false;
//
return result;
}
//
// Calculate Fib Level ...
double GetFibonacciLevel(
@@ -450,22 +450,26 @@ class XC121SMCCycleHelper : public XCBase
//
int highestPeakIndex = -1;
double highestPeakVale = 0;
double highestPeak = mX121Helper
.GetHighestPeak(
barIndex,
highestPeakIndex,
highestPeakVale //
);
double highestPeak =
mX121Helper
.xpvHelper
.GetHighestPeak(
barIndex,
highestPeakIndex,
highestPeakVale //
);
//
int lowestValeIndex = -1;
double lowestValePeak = 0;
double lowestVale = mX121Helper
.GetLowestVale(
barIndex,
lowestValeIndex,
lowestValePeak //
);
double lowestVale =
mX121Helper
.xpvHelper
.GetLowestVale(
barIndex,
lowestValeIndex,
lowestValePeak //
);
//
result = IsValidIndex(highestPeakIndex) &&
@@ -520,7 +524,11 @@ class XC121SMCCycleHelper : public XCBase
}
//
bool isBreake = iBar.IsBreakeUp(lowestValePeak);
bool isBreake = IsBarBreak(
lowestValePeak,
X_DIRECTION_BULLISH,
iBar //
);
if (isBreake)
{
//
@@ -545,7 +553,11 @@ class XC121SMCCycleHelper : public XCBase
}
//
bool isBreake = iBar.IsBreakeDown(highestPeakVale);
bool isBreake = IsBarBreak(
highestPeakVale,
X_DIRECTION_BEARISH,
iBar //
);
if (isBreake)
{
//
@@ -571,7 +583,7 @@ class XC121SMCCycleHelper : public XCBase
for (int i = lowestValePeakBreakeUpIndex; i >= barIndex; i--)
{
//
double iVale = mX121Helper.GetVale(i);
double iVale = mX121Helper.xpvHelper.GetVale(i);
//
bool isValid =
@@ -581,7 +593,7 @@ class XC121SMCCycleHelper : public XCBase
{
//
valeAboveLowestValePeakIndex = i;
valeAboveLowestValePeakPeak = mX121Helper.GetPeak(i);
valeAboveLowestValePeakPeak = mX121Helper.xpvHelper.GetPeak(i);
break;
}
}
@@ -595,7 +607,7 @@ class XC121SMCCycleHelper : public XCBase
for (int i = highestPeakValeBreakeDownIndex; i >= barIndex; i--)
{
//
double iPeak = mX121Helper.GetPeak(i);
double iPeak = mX121Helper.xpvHelper.GetPeak(i);
//
bool isValid =
@@ -605,7 +617,7 @@ class XC121SMCCycleHelper : public XCBase
{
//
peakBelowHighestPeakValeIndex = i;
peakBelowHighestPeakValeVale = mX121Helper.GetVale(i);
peakBelowHighestPeakValeVale = mX121Helper.xpvHelper.GetVale(i);
break;
}
}
@@ -651,8 +663,8 @@ class XC121SMCCycleHelper : public XCBase
bool isInited = GetBar(iBar, i);
//
double iPeak = mX121Helper.GetPeak(i);
double iVale = mX121Helper.GetVale(i);
double iPeak = mX121Helper.xpvHelper.GetPeak(i);
double iVale = mX121Helper.xpvHelper.GetVale(i);
//
bool hasPeakPriceInsideZone = CalculatePriceInsideZones(
@@ -3279,9 +3279,9 @@ class XC121SMCTradeHandler : public XCBaseAlert
conditions,
conditionsObjects,
mDrawer,
true,
false,
true, // Analyse Price Zones ...
true, // Decision Zone ...
false, // Decision Zone ...
true // Only Box ...
);
}
@@ -1096,6 +1096,18 @@ bool DetectX121SMCXTWPVSiganlTrigger(
//
// Trigger Conditions ...
//
// Detect Bullish Conditions ...
isBullish =
isBullish &&
cBar.IsBullish();
//
// Detect Bearish Conditions ...
isBearish =
isBearish &&
cBar.IsBearish();
//
result = isBullish ||
isBearish;
@@ -1163,7 +1175,7 @@ bool DetectX121SMCXTWPVSiganlTrigger(
if (isBullish)
{
//
double lowerVale = triggerCycleHelper.mX121Helper.GetLowerVale(vale);
double lowerVale = triggerCycleHelper.mX121Helper.xpvHelper.GetLowerVale(vale);
if (lowerVale > 0)
{
//
@@ -1176,7 +1188,7 @@ bool DetectX121SMCXTWPVSiganlTrigger(
else if (isBearish)
{
//
double higherPeak = triggerCycleHelper.mX121Helper.GetHigherPeak(peak);
double higherPeak = triggerCycleHelper.mX121Helper.xpvHelper.GetHigherPeak(peak);
if (higherPeak > 0)
{
//
+31 -20
View File
@@ -614,34 +614,45 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy
x121Inputs.Default();
//
x121Inputs.scMethod = scMethod;
x121Inputs.scPeriod = scPeriod;
x121Inputs.mcMethod = mcMethod;
x121Inputs.mcPeriod = mcPeriod;
x121Inputs.lcMethod = lcMethod;
x121Inputs.lcPeriod = lcPeriod;
x121Inputs.hcMethod = hcMethod;
x121Inputs.hcPeriod = hcPeriod;
bool isInited = false;
//
x121Inputs.showSar = true;
x121Inputs.showPeaks = true;
x121Inputs.showVales = true;
x121Inputs.showVWap = true;
x121Inputs.showDonchain = true;
// XPV ...
//
x121Inputs.showOpen = false;
x121Inputs.showHigh = false;
x121Inputs.showClose = true;
x121Inputs.showLow = false;
x121Inputs.xpvInputs.scMethod = scMethod;
x121Inputs.xpvInputs.scPeriod = scPeriod;
x121Inputs.xpvInputs.mcMethod = mcMethod;
x121Inputs.xpvInputs.mcPeriod = mcPeriod;
x121Inputs.xpvInputs.lcMethod = lcMethod;
x121Inputs.xpvInputs.lcPeriod = lcPeriod;
x121Inputs.xpvInputs.hcMethod = hcMethod;
x121Inputs.xpvInputs.hcPeriod = hcPeriod;
//
// XATR ...
x121Inputs.xatrInputs.showATRUpper = false;
x121Inputs.xatrInputs.showATRLower = false;
//
// XSTR ...
//
// XDON ...
x121Inputs.xdonInputs.showOpen = false;
x121Inputs.xdonInputs.showClose = true;
x121Inputs.xdonInputs.showLow = false;
x121Inputs.xdonInputs.showHigh = false;
//
// XVWAP ...
x121Inputs.xvwapInputs.showVWapFast = true;
x121Inputs.xvwapInputs.showVWapFast = true;
x121Inputs.xvwapInputs.showVWapSlow = false;
//
// Initialize Cycle Helpers ...
//
bool isInited = false;
//
mTriggerCycleHelper = new XC121SMCCycleHelper();
isInited = mTriggerCycleHelper.Init(