Cleanup Work Space after Backup 14040203 ...

This commit is contained in:
2025-04-23 05:10:12 +03:30
parent 5316d60869
commit f48d272bba
76 changed files with 0 additions and 81839 deletions
-128
View File
@@ -1,128 +0,0 @@
#property copyright "Your Name"
#property link "https://www.example.com"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots 0
// Input parameters
input int SwingPeriod = 5; // Lookback period for swing detection
// Global variables
double LastSwingHigh = 0, LastSwingLow = 0;
bool IsBullish = false;
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
// Start from the latest bar
for(int i = rates_total - prev_calculated - 1; i >= 0; i--)
{
// Detect swing high and low
if(IsSwingHigh(high, low, i, SwingPeriod))
{
LastSwingHigh = high[i];
CheckStructure(i, high[i], low[i], time[i]);
}
if(IsSwingLow(high, low, i, SwingPeriod))
{
LastSwingLow = low[i];
CheckStructure(i, high[i], low[i], time[i]);
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
bool IsSwingHigh(const double &high[], const double &low[], int index, int period)
{
if(index < period || index >= ArraySize(high) - period) return false;
for(int i = 1; i <= period; i++)
{
if(high[index] <= high[index - i] || high[index] <= high[index + i])
return false;
}
return true;
}
//+------------------------------------------------------------------+
bool IsSwingLow(const double &high[], const double &low[], int index, int period)
{
if(index < period || index >= ArraySize(low) - period) return false;
for(int i = 1; i <= period; i++)
{
if(low[index] >= low[index - i] || low[index] >= low[index + i])
return false;
}
return true;
}
//+------------------------------------------------------------------+
void CheckStructure(int index, double high, double low, datetime time)
{
// Determine trend direction
if(LastSwingHigh > 0 && LastSwingLow > 0)
{
IsBullish = (LastSwingHigh > LastSwingLow);
// Check for BOS
if(IsBullish && high > LastSwingHigh)
{
LastSwingHigh = high;
ObjectCreate(0, "BOS_" + TimeToString(time), OBJ_TEXT, 0, time, high);
ObjectSetString(0, "BOS_" + TimeToString(time), OBJPROP_TEXT, "BOS");
ObjectSetInteger(0, "BOS_" + TimeToString(time), OBJPROP_COLOR, clrGreen);
Alert("Break of Structure (BOS) detected at " + DoubleToString(high, 5));
}
else if(!IsBullish && low < LastSwingLow)
{
LastSwingLow = low;
ObjectCreate(0, "BOS_" + TimeToString(time), OBJ_TEXT, 0, time, low);
ObjectSetString(0, "BOS_" + TimeToString(time), OBJPROP_TEXT, "BOS");
ObjectSetInteger(0, "BOS_" + TimeToString(time), OBJPROP_COLOR, clrRed);
Alert("Break of Structure (BOS) detected at " + DoubleToString(low, 5));
}
// Check for CHoCH
if(IsBullish && low < LastSwingLow)
{
LastSwingLow = low;
ObjectCreate(0, "CHoCH_" + TimeToString(time), OBJ_TEXT, 0, time, low);
ObjectSetString(0, "CHoCH_" + TimeToString(time), OBJPROP_TEXT, "CHoCH");
ObjectSetInteger(0, "CHoCH_" + TimeToString(time), OBJPROP_COLOR, clrRed);
Alert("Change of Character (CHoCH) detected at " + DoubleToString(low, 5));
IsBullish = false; // Trend may reverse
}
else if(!IsBullish && high > LastSwingHigh)
{
LastSwingHigh = high;
ObjectCreate(0, "CHoCH_" + TimeToString(time), OBJ_TEXT, 0, time, high);
ObjectSetString(0, "CHoCH_" + TimeToString(time), OBJPROP_TEXT, "CHoCH");
ObjectSetInteger(0, "CHoCH_" + TimeToString(time), OBJPROP_COLOR, clrGreen);
Alert("Change of Character (CHoCH) detected at " + DoubleToString(high, 5));
IsBullish = true; // Trend may reverse
}
}
}
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
ObjectsDeleteAll(0, "BOS_");
ObjectsDeleteAll(0, "CHoCH_");
}
@@ -1,888 +0,0 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: X121 XSMC
// Description: XSMC ...
//
//
// 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 XSMC Indicator"
#property strict
//
// Definitions ...
//
#define ShortName "X121 XSMC"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
input int swingLength = 5; // Swing Length
//
input group "Presentation";
//
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
input int trendArrowCode = 117; // Trend Arrow
input int swingLowsArrowCode = 159; // Swing Lows Arrow
input int swingHighsArrowCode = 159; // Swing Highs Arrow
input int swingLowBOSArrowCode = 233; // Swing Low BOS Arrow
input int swingHighBOSArrowCode = 234; // Swing High BOS Arrow
input int swingLowCHOCHArrowCode = 225; // Swing Low CHOCH Arrow
input int swingHighCHOCHArrowCode = 226; // Swing High CHOCH Arrow
//
input bool showTrend = true; // Show Trend
input bool showSwingLows = true; // Show Swing Lows
input bool showSwingHighs = true; // Show Swing Highs
input bool showSwingLowBOS = true; // Show Swing Low BOS
input bool showSwingHighBOS = true; // Show Swing High BOS
input bool showSwingLowCHOCH = true; // Show Swing Low CHOCH
input bool showSwingHighCHOCH = true; // Show Swing High CHOCH
//
// Buffers ...
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
#define neuturalColorIDX 3
//
#define emptyValue 0.0
//
#property indicator_chart_window
//
#property indicator_buffers 9
#property indicator_plots 7
//
// Plot Buffers ...
//
// Swing Lows ...
//
#define swingLowsBufferIndex 0
double swingLowsBuffer[];
//
#property indicator_label1 "X121 SWL"
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrAqua
#property indicator_width1 1
//
// Swng Highs ...
//
#define swingHighsBufferIndex 1
double swingHighsBuffer[];
//
#property indicator_label2 "X121 SWH"
#property indicator_type2 DRAW_ARROW
#property indicator_color2 clrMagenta
#property indicator_width2 1
//
// Swing Low BOS ...
#define swingLowsBOSBufferIndex 2
double swingLowsBOSBuffer[];
//
#property indicator_label3 "X121 SWLBOS"
#property indicator_type3 DRAW_ARROW
#property indicator_color3 clrAqua
#property indicator_width3 3
//
// Swing High BOS ...
#define swingHighsBOSBufferIndex 3
double swingHighsBOSBuffer[];
//
#property indicator_label4 "X121 SWHBOS"
#property indicator_type4 DRAW_ARROW
#property indicator_color4 clrMagenta
#property indicator_width4 3
//
// Swing Low CHOCH ...
#define swingLowsCHOCHBufferIndex 4
double swingLowsCHOCHBuffer[];
//
#property indicator_label5 "X121 SWLCHOCH"
#property indicator_type5 DRAW_ARROW
#property indicator_color5 clrYellow
#property indicator_width5 3
//
// Swing High CHOCH ...
#define swingHighsCHOCHBufferIndex 5
double swingHighsCHOCHBuffer[];
//
#property indicator_label6 "X121 SWHCHOCH"
#property indicator_type6 DRAW_ARROW
#property indicator_color6 clrYellow
#property indicator_width6 3
//
// Trend ...
#define trendBufferIndex 6
double trendBuffer[];
#define trendColorBufferIndex 7
double trendColorBuffer[];
//
#property indicator_label7 "X121 TRND"
#property indicator_type7 DRAW_COLOR_ARROW
#property indicator_color7 CLR_NONE, clrAqua, clrMagenta, clrGray
#property indicator_width7 3
//
// Data Buffers ...
//
int mLastBufferIndex = 7;
//
// Trend State ...
#define trendStateBufferIndex mLastBufferIndex + 1
double trendStateBuffer[];
//
// Variables, Properties and etc ...
//
// this counts Available Bars ...
int limit;
//
int maxLength;
//
double lastSwing = 0.0;
ENUM_X_DIRECTION lastSwingDir = X_DIRECTION_NONE;
//
// 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);
//
limit = (prev_calculated > rates_total || prev_calculated <= 0)
? rates_total
: (rates_total - prev_calculated) + 1;
//
// 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 =
//
swingLength > 0
//
;
//
return result;
}
/**
* Extract Max Length of Inputs ...
*
* @return ( int )
*/
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = swingLength;
//
return result;
}
/**
* Define Required Buffers ...
*/
void DefineBuffers()
{
//
// Plot Buffers ...
//
// Swing Lows ...
//
ENUM_DRAW_TYPE swingLowsDrawType = showSwingLows ? DRAW_ARROW : DRAW_NONE;
//
ArraySetAsSeries(swingLowsBuffer, true);
SetIndexBuffer(swingLowsBufferIndex, swingLowsBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(swingLowsBufferIndex, PLOT_SHOW_DATA, showSwingLows);
PlotIndexSetInteger(swingLowsBufferIndex, PLOT_DRAW_TYPE, swingLowsDrawType);
//
PlotIndexSetDouble(swingLowsBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(swingLowsBufferIndex, PLOT_ARROW, swingLowsArrowCode);
//
// Swing Highs ...
//
ENUM_DRAW_TYPE swingHighsDrawType = showSwingHighs ? DRAW_ARROW : DRAW_NONE;
//
ArraySetAsSeries(swingHighsBuffer, true);
SetIndexBuffer(swingHighsBufferIndex, swingHighsBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(swingHighsBufferIndex, PLOT_SHOW_DATA, showSwingHighs);
PlotIndexSetInteger(swingHighsBufferIndex, PLOT_DRAW_TYPE, swingHighsDrawType);
//
PlotIndexSetDouble(swingHighsBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(swingHighsBufferIndex, PLOT_ARROW, swingHighsArrowCode);
//
// Trends ...
//
ENUM_DRAW_TYPE trendDrawType = showTrend ? DRAW_COLOR_ARROW : DRAW_NONE;
//
ArraySetAsSeries(trendBuffer, true);
SetIndexBuffer(trendBufferIndex, trendBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(trendBufferIndex, PLOT_SHOW_DATA, showTrend);
PlotIndexSetInteger(trendBufferIndex, PLOT_DRAW_TYPE, trendDrawType);
//
PlotIndexSetDouble(trendBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(trendBufferIndex, PLOT_ARROW, trendArrowCode);
//
ArraySetAsSeries(trendColorBuffer, true);
SetIndexBuffer(trendColorBufferIndex, trendColorBuffer, INDICATOR_COLOR_INDEX);
//
// SWLBOS ...
//
ENUM_DRAW_TYPE swingLowBOSDrawType = showSwingLowBOS ? DRAW_ARROW : DRAW_NONE;
//
ArraySetAsSeries(swingLowsBOSBuffer, true);
SetIndexBuffer(swingLowsBOSBufferIndex, swingLowsBOSBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(swingLowsBOSBufferIndex, PLOT_SHOW_DATA, showSwingLowBOS);
PlotIndexSetInteger(swingLowsBOSBufferIndex, PLOT_DRAW_TYPE, swingLowBOSDrawType);
//
PlotIndexSetDouble(swingLowsBOSBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(swingLowsBOSBufferIndex, PLOT_ARROW, swingLowBOSArrowCode);
//
// SWHBOS ...
//
ENUM_DRAW_TYPE swingHighBOSDrawType = showSwingHighBOS ? DRAW_ARROW : DRAW_NONE;
//
ArraySetAsSeries(swingHighsBOSBuffer, true);
SetIndexBuffer(swingHighsBOSBufferIndex, swingHighsBOSBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(swingHighsBOSBufferIndex, PLOT_SHOW_DATA, showSwingHighBOS);
PlotIndexSetInteger(swingHighsBOSBufferIndex, PLOT_DRAW_TYPE, swingHighBOSDrawType);
//
PlotIndexSetDouble(swingHighsBOSBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(swingHighsBOSBufferIndex, PLOT_ARROW, swingHighBOSArrowCode);
//
// SWLCHOCH ...
//
ENUM_DRAW_TYPE swingLowCHOCHDrawType = showSwingLowCHOCH ? DRAW_ARROW : DRAW_NONE;
//
ArraySetAsSeries(swingLowsCHOCHBuffer, true);
SetIndexBuffer(swingLowsCHOCHBufferIndex, swingLowsCHOCHBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(swingLowsCHOCHBufferIndex, PLOT_SHOW_DATA, showSwingLowCHOCH);
PlotIndexSetInteger(swingLowsCHOCHBufferIndex, PLOT_DRAW_TYPE, swingLowCHOCHDrawType);
//
PlotIndexSetDouble(swingLowsCHOCHBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(swingLowsCHOCHBufferIndex, PLOT_ARROW, swingLowCHOCHArrowCode);
//
// SWHCHOCH ...
//
ENUM_DRAW_TYPE swingHighCHOCHDrawType = showSwingHighCHOCH ? DRAW_ARROW : DRAW_NONE;
//
ArraySetAsSeries(swingHighsCHOCHBuffer, true);
SetIndexBuffer(swingHighsCHOCHBufferIndex, swingHighsCHOCHBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(swingHighsCHOCHBufferIndex, PLOT_SHOW_DATA, showSwingHighCHOCH);
PlotIndexSetInteger(swingHighsCHOCHBufferIndex, PLOT_DRAW_TYPE, swingHighCHOCHDrawType);
//
PlotIndexSetDouble(swingHighsCHOCHBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(swingHighsCHOCHBufferIndex, PLOT_ARROW, swingHighCHOCHArrowCode);
//
// Data Buffers ...
//
ArraySetAsSeries(trendStateBuffer, true);
SetIndexBuffer(trendStateBufferIndex, trendStateBuffer, INDICATOR_CALCULATIONS);
}
/**
* Set Indicator Short Name and also we can define Buffers Labels ...
*/
void SetIndicatorName()
{
//
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
IndicatorSetInteger(INDICATOR_DIGITS, 2);
}
/**
* 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)
{
//
CalculateValues(
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)
{
//
trendBuffer[barIndex] = emptyValue;
swingLowsBuffer[barIndex] = emptyValue;
swingHighsBuffer[barIndex] = emptyValue;
swingLowsBOSBuffer[barIndex] = emptyValue;
swingHighsBOSBuffer[barIndex] = emptyValue;
swingLowsCHOCHBuffer[barIndex] = emptyValue;
swingHighsCHOCHBuffer[barIndex] = emptyValue;
//
trendColorBuffer[barIndex] = hideColorIDX;
trendStateBuffer[barIndex] = (double)((int)X_DIRECTION_NONE);
}
/**
* Calculate Values ...
*
* @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 CalculateValues(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[] //
)
{
//
int lastBarIndex = bar_index + 1;
bool isFirstBar =
startCalculationForLastBars > 0
? bar_index == startCalculationForLastBars
: bar_index == ratesTotal;
//
double iLow = low[bar_index];
double iHigh = high[bar_index];
//
// Swing Low ...
double lastSwingLow = isFirstBar
? emptyValue
: swingLowsBuffer[lastBarIndex];
bool isSwingLow = IsSwingLow(high, low, bar_index, swingLength);
double iSwingLow =
!isSwingLow
? lastSwingLow
: iLow;
swingLowsBuffer[bar_index] = iSwingLow;
//
// Swing High ...
double lastSwingHigh = isFirstBar
? emptyValue
: swingHighsBuffer[lastBarIndex];
bool isSwingHigh = IsSwingHigh(high, low, bar_index, swingLength);
double iSwingHigh =
!isSwingHigh
? lastSwingHigh
: iHigh;
swingHighsBuffer[bar_index] = iSwingHigh;
//
// Detect Last Swing/Last Swing Direction ...
bool isSwing = isSwingLow ||
isSwingHigh;
if (isSwing)
{
//
if (isSwingLow)
{
//
lastSwing = iSwingLow;
lastSwingDir = X_DIRECTION_BULLISH;
}
else if (isSwingHigh)
{
//
lastSwing = iSwingHigh;
lastSwingDir = X_DIRECTION_BEARISH;
}
}
//
// Detect Trend ...
//
// Detecting Trend Direction ...
ENUM_X_DIRECTION lastTendDir =
isFirstBar
? X_DIRECTION_NONE
: (ENUM_X_DIRECTION)((int)trendStateBuffer[lastBarIndex]);
ENUM_X_DIRECTION iTrendDir =
isSwingLow &&
iSwingLow > lastSwingLow
? X_DIRECTION_BULLISH
: isSwingHigh &&
iSwingHigh < lastSwingHigh
? X_DIRECTION_BEARISH
: lastTendDir;
bool isTrendChanged =
HasDirection(lastTendDir) &&
HasDirection(iTrendDir) &&
lastTendDir != iTrendDir;
//
// Detecting Trend State ...
double iTrendState = (int)iTrendDir;
trendStateBuffer[bar_index] = iTrendState;
//
// Detecting Trend Value ...
double lastTrendValue =
isFirstBar
? emptyValue
: trendBuffer[lastBarIndex];
double iTrendValue =
IsBullish(iTrendDir)
? isTrendChanged
? iLow
: lastTrendValue
: IsBearish(iTrendDir)
? isTrendChanged
? iHigh
: lastTrendValue
: lastTrendValue;
trendBuffer[bar_index] = iTrendValue;
//
// Detecting Trend Color ...
double iTrendColorValue =
IsBullish(iTrendDir)
? bullishColorIDX
: IsBearish(iTrendDir)
? bearishColorIDX
: hideColorIDX;
bool isTrendBreaked = false;
if (IsBullish(iTrendDir))
{
//
isTrendBreaked = iHigh < lastTrendValue;
if (isTrendBreaked)
{
iTrendColorValue = bearishColorIDX;
}
}
else if (IsBearish(iTrendDir))
{
//
isTrendBreaked = iLow > lastTrendValue;
if (isTrendBreaked)
{
iTrendColorValue = bullishColorIDX;
}
}
trendColorBuffer[bar_index] = iTrendColorValue;
//
bool isTrendBullish = iTrendColorValue == bullishColorIDX;
bool isTrendBearish = iTrendColorValue == bearishColorIDX;
//
// Detecting BOS ...
//
// Swing Low BOS ...
double lastSwingLowBOSValue =
isFirstBar
? emptyValue
: swingLowsBOSBuffer[lastBarIndex];
double iSwingLowBOSValue =
isTrendBullish &&
iHigh > lastSwing
? iLow
: emptyValue;
bool isSwingLowBOSBreaked =
iSwingLowBOSValue != emptyValue &&
iLow < iSwingLowBOSValue;
if (isSwingLowBOSBreaked)
{
iSwingLowBOSValue = emptyValue;
}
swingLowsBOSBuffer[bar_index] = iSwingLowBOSValue;
//
// Swing High BOS ...
double lastSwingHighBOSValue =
isFirstBar
? emptyValue
: swingHighsBOSBuffer[lastBarIndex];
double iSwingHighBOSValue =
isTrendBearish &&
iLow < lastSwing
? iHigh
: emptyValue;
bool isSwingHighBOSBreaked =
iSwingHighBOSValue != emptyValue &&
iHigh > iSwingHighBOSValue;
if (isSwingHighBOSBreaked)
{
iSwingHighBOSValue = emptyValue;
}
swingHighsBOSBuffer[bar_index] = iSwingHighBOSValue;
//
// Detecting CHOCHs ...
//
// Swing Low CHOCH ...
double lastSwingLowCHOCHValue =
isFirstBar
? emptyValue
: swingLowsCHOCHBuffer[lastBarIndex];
double iSwingLowCHOCHValue =
isTrendBullish &&
iLow < lastSwing
? iLow
: emptyValue;
swingLowsCHOCHBuffer[bar_index] = iSwingLowCHOCHValue;
//
// Swing High CHOCH ...
double lastSwingHighCHOCHValue =
isFirstBar
? emptyValue
: swingHighsCHOCHBuffer[lastBarIndex];
double iSwingHighCHOCHValue =
isTrendBearish &&
iHigh > lastSwing
? iHigh
: emptyValue;
swingHighsCHOCHBuffer[bar_index] = iSwingHighCHOCHValue;
}
//
// Tools ...
//
bool IsSwingLow(
const double &high[],
const double &low[],
int index,
int length //
)
{
//
bool result = false;
//
result = index - length > 0;
if (!result)
{
return result;
}
//
for (int i = 1; i <= length; i++)
{
//
result = low[index] < low[index - 1] &&
low[index] < low[index + i];
if (!result)
{
break;
}
}
//
return result;
}
//
bool IsSwingHigh(
const double &high[],
const double &low[],
int index,
int length //
)
{
//
bool result = false;
//
result = index - length > 0;
if (!result)
{
return result;
}
//
for (int i = 1; i <= length; i++)
{
//
result = high[index] > high[index - 1] &&
high[index] > high[index + i];
if (!result)
{
break;
}
}
//
return result;
}
//
File diff suppressed because it is too large Load Diff
@@ -1,637 +0,0 @@
///////////////////////////////////////////////////////
//
// 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 "../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
input bool showStrUpper = true; // Show Str Upper
input bool showStrLower = true; // Show Str Lower
//
// Buffers ...
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
#define neuturalColorIDX 3
//
#property indicator_chart_window
//
#property indicator_buffers 7
#property indicator_plots 3
//
// STR ...
#define strBufferIndex 0
double strBuffer[];
#define strColorBufferIndex 1
double strColorBuffer[];
//
#define strPlotBufferIndex 0
#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
//
// Up ...
#define strUpBufferIndex 2
double strUpBuffer[];
//
#define strUpPlotBufferIndex 1
#property indicator_label2 "X121 STR U"
#property indicator_type2 DRAW_LINE
#property indicator_color2 C'255,106,0'
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//
// Down ...
#define strDownBufferIndex 3
double strDownBuffer[];
//
#define strDownPlotBufferIndex 2
#property indicator_label3 "X121 STR D"
#property indicator_type3 DRAW_LINE
#property indicator_color3 C'255,106,0'
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
//
// Data Buffers ...
//
int mLastBufferIndex = 3;
//
// STR ...
//
// Atr ...
#define atrBufferIndex mLastBufferIndex + 1
double atrBuffer[];
//
// Price ...
#define strPriceBufferIndex mLastBufferIndex + 2
double strPriceBuffer[];
//
// Trend ...
#define strStateBufferIndex mLastBufferIndex + 3
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 ...
//
// Validate Calculated Bars ...
//
// ATR ...
int atrCalculatedBars = BarsCalculated(atrHandler);
//
bool isPassedRequiredCalculatedBars =
//
// ATR ...
atrCalculatedBars >= 0
//
;
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, rates_total, atrBuffer);
//
// Validate Copied Items ...
bool isPassedRequiredCopiedItems =
//
// ATR ...
copiedAtrs >= 0
//
;
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);
//
ENUM_DRAW_TYPE strUpDrawType = showStrUpper ? DRAW_LINE : DRAW_NONE;
SetIndexBuffer(strUpBufferIndex, strUpBuffer, INDICATOR_DATA);
PlotIndexSetDouble(strUpPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(strUpPlotBufferIndex, PLOT_SHOW_DATA, showStrUpper);
PlotIndexSetInteger(strUpPlotBufferIndex, PLOT_DRAW_TYPE, strUpDrawType);
//
ENUM_DRAW_TYPE strDownDrawType = showStrLower ? DRAW_LINE : DRAW_NONE;
SetIndexBuffer(strDownBufferIndex, strDownBuffer, INDICATOR_DATA);
PlotIndexSetDouble(strDownPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(strDownPlotBufferIndex, PLOT_SHOW_DATA, showStrLower);
PlotIndexSetInteger(strDownPlotBufferIndex, PLOT_DRAW_TYPE, strDownDrawType);
//
// Data Buffers ...
//
// STR ...
//
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 ...
ENUM_X_PRICE mPTYpe = ToXPrice(strAppliedTo);
double price = GetAppliedPrice(
mPTYpe,
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;
}
}
//
@@ -1,793 +0,0 @@
///////////////////////////////////////////////////////
//
// 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 "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
input int strLength = 14; // Length
input double strMultiplier = 3; // Multiplier
input ENUM_MA_METHOD strBoundaryMode = MODE_SMA; // Boundary Mode
input ENUM_APPLIED_PRICE strAppliedTo = PRICE_MEDIAN; // Applied To
//
input group "Presentation";
input bool showStr = true; // Show Str
input bool showStrMid = true; // Show Str Mid
input bool showStrUpper = true; // Show Str Upper
input bool showStrLower = true; // Show Str Lower
input bool showStrLowMa = true; // Show Low Smoothed Buffer
input bool showStrHighMa = true; // Show High Smoothed Buffer
//
// Buffers ...
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
#define neuturalColorIDX 3
//
#define emptyValue 0.0
//
#property indicator_chart_window
//
#property indicator_buffers 11
#property indicator_plots 6
//
// STR ...
#define strBufferIndex 0
double strBuffer[];
#define strColorBufferIndex 1
double strColorBuffer[];
//
#define strPlotBufferIndex 0
#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
//
// Up ...
#define strUpBufferIndex 2
double strUpBuffer[];
//
#define strUpPlotBufferIndex 1
#property indicator_label2 "X121 STR U"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrBlueViolet
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//
// Down ...
#define strDownBufferIndex 3
double strDownBuffer[];
//
#define strDownPlotBufferIndex 2
#property indicator_label3 "X121 STR D"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrBlueViolet
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
//
// High MA ...
#define strHighMaBufferIndex 4
double strHighMaBuffer[];
//
#define strHighMaPlotBufferIndex 3
#property indicator_label4 "X121 STR HSM"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrAqua
#property indicator_style4 STYLE_SOLID
#property indicator_width4 1
//
// Low Ma ...
#define strLowMaBufferIndex 5
double strLowMaBuffer[];
//
#define strLowMaPlotBufferIndex 4
#property indicator_label5 "X121 STR LSM"
#property indicator_type5 DRAW_LINE
#property indicator_color5 clrMagenta
#property indicator_style5 STYLE_SOLID
#property indicator_width5 1
//
// STR Mmid ...
#define strMidBufferIndex 6
double strMidBuffer[];
#define strMidColorBufferIndex 7
double strMidColorBuffer[];
//
#define strMidPlotBufferIndex 5
#property indicator_label6 "X121 STR Mid"
#property indicator_type6 DRAW_COLOR_LINE
#property indicator_color6 CLR_NONE, clrLime, clrRed, clrGray
#property indicator_style6 STYLE_SOLID
#property indicator_width6 1
//
// Data Buffers ...
//
int mLastBufferIndex = 7;
//
// STR ...
//
// Atr ...
#define atrBufferIndex mLastBufferIndex + 1
double atrBuffer[];
//
// Price ...
#define strPriceBufferIndex mLastBufferIndex + 2
double strPriceBuffer[];
//
// Trend ...
#define strStateBufferIndex mLastBufferIndex + 3
double strStateBuffer[];
//
// Variables, Properties and etc ...
//
// this counts Available Bars ...
int limit;
//
int maxLength;
//
// ATR Handler ...
int atrHandler = INVALID_HANDLE;
//
// MA Handler ...
int lowMaHandler = INVALID_HANDLE;
int highMaHandler = 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;
}
//
// Low Ma ...
lowMaHandler = iMA(
_Symbol,
_Period,
strLength,
0,
strBoundaryMode,
PRICE_LOW //
);
isInited = lowMaHandler != INVALID_HANDLE;
if (!isInited)
{
return INIT_FAILED;
}
//
// High Ma ...
highMaHandler = iMA(
_Symbol,
_Period,
strLength,
0,
strBoundaryMode,
PRICE_HIGH //
);
isInited = highMaHandler != 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);
IndicatorRelease(lowMaHandler);
IndicatorRelease(highMaHandler);
}
/**
* 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 ...
//
// Validate Calculated Bars ...
//
// ATR ...
int atrCalculatedBars = BarsCalculated(atrHandler);
//
// Low Ma ...
int lowMaCalculatedBars = BarsCalculated(lowMaHandler);
//
// High Ma ...
int highMaCalculatedBars = BarsCalculated(highMaHandler);
//
bool isPassedRequiredCalculatedBars =
//
// ATR ...
atrCalculatedBars >= 0 &&
//
// Low Ma ...
lowMaCalculatedBars >= 0 &&
//
// High Ma ...
highMaCalculatedBars >= 0
//
;
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, rates_total, atrBuffer);
//
// Low Ma ...
int copiedLowMas = CopyBuffer(lowMaHandler, 0, 0, rates_total, strLowMaBuffer);
//
// High Ma ...
int copiedHighMas = CopyBuffer(highMaHandler, 0, 0, rates_total, strHighMaBuffer);
//
// Validate Copied Items ...
bool isPassedRequiredCopiedItems =
//
// ATR ...
copiedAtrs >= 0 &&
//
// Low Ma ...
copiedLowMas >= 0 &&
//
// Hig Ma ...
copiedHighMas >= 0
//
;
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);
//
ENUM_DRAW_TYPE strUpDrawType = showStrUpper ? DRAW_LINE : DRAW_NONE;
SetIndexBuffer(strUpBufferIndex, strUpBuffer, INDICATOR_DATA);
PlotIndexSetDouble(strUpPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(strUpPlotBufferIndex, PLOT_SHOW_DATA, showStrUpper);
PlotIndexSetInteger(strUpPlotBufferIndex, PLOT_DRAW_TYPE, strUpDrawType);
//
ENUM_DRAW_TYPE strDownDrawType = showStrLower ? DRAW_LINE : DRAW_NONE;
SetIndexBuffer(strDownBufferIndex, strDownBuffer, INDICATOR_DATA);
PlotIndexSetDouble(strDownPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(strDownPlotBufferIndex, PLOT_SHOW_DATA, showStrLower);
PlotIndexSetInteger(strDownPlotBufferIndex, PLOT_DRAW_TYPE, strDownDrawType);
//
ENUM_DRAW_TYPE strLowMaDrawType = showStrLowMa ? DRAW_LINE : DRAW_NONE;
SetIndexBuffer(strLowMaBufferIndex, strLowMaBuffer, INDICATOR_DATA);
PlotIndexSetDouble(strLowMaPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(strLowMaPlotBufferIndex, PLOT_SHOW_DATA, showStrLowMa);
PlotIndexSetInteger(strLowMaPlotBufferIndex, PLOT_DRAW_TYPE, strLowMaDrawType);
//
ENUM_DRAW_TYPE strHighMaDrawType = showStrHighMa ? DRAW_LINE : DRAW_NONE;
SetIndexBuffer(strHighMaBufferIndex, strHighMaBuffer, INDICATOR_DATA);
PlotIndexSetDouble(strHighMaPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(strHighMaPlotBufferIndex, PLOT_SHOW_DATA, showStrHighMa);
PlotIndexSetInteger(strHighMaPlotBufferIndex, PLOT_DRAW_TYPE, strHighMaDrawType);
//
ENUM_DRAW_TYPE strMidDrawType = showStrMid ? DRAW_COLOR_LINE : DRAW_NONE;
SetIndexBuffer(strMidBufferIndex, strMidBuffer, INDICATOR_DATA);
SetIndexBuffer(strMidColorBufferIndex, strMidColorBuffer, INDICATOR_COLOR_INDEX);
PlotIndexSetDouble(strMidPlotBufferIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(strMidPlotBufferIndex, PLOT_SHOW_DATA, showStrMid);
PlotIndexSetInteger(strMidPlotBufferIndex, PLOT_DRAW_TYPE, strMidDrawType);
//
// Data Buffers ...
//
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] = emptyValue;
strUpBuffer[barIndex] = emptyValue;
strMidBuffer[barIndex] = emptyValue;
strMidBuffer[barIndex] = emptyValue;
strDownBuffer[barIndex] = emptyValue;
strPriceBuffer[barIndex] = emptyValue;
strLowMaBuffer[barIndex] = emptyValue;
strHighMaBuffer[barIndex] = emptyValue;
//
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 ...
ENUM_X_PRICE mPType = ToXPrice(strAppliedTo);
double price = GetAppliedPrice(
mPType,
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;
}
//
// Str Mid ...
//
double iStrMid = strDownBuffer[bar_index] + ((strUpBuffer[bar_index] - strDownBuffer[bar_index]) / 2);
strMidBuffer[bar_index] = iStrMid;
//
double iStrColor = close[bar_index] > strMidBuffer[bar_index]
? bullishColorIDX
: close[bar_index] < strMidBuffer[bar_index]
? bearishColorIDX
: neuturalColorIDX;
strMidColorBuffer[bar_index] = iStrColor;
//
}
//