Last Works ...

This commit is contained in:
2024-11-28 17:02:02 +03:30
parent 9ba70d733a
commit eca4870c03
8 changed files with 14181 additions and 548 deletions
File diff suppressed because it is too large Load Diff
+8 -8
View File
@@ -73,9 +73,9 @@ double fastColorBuffer[];
#define fastPlotBufferIndex 0 #define fastPlotBufferIndex 0
#property indicator_label1 "X3VWAP F" #property indicator_label1 "X3VWAP F"
#property indicator_type1 DRAW_COLOR_LINE #property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 CLR_NONE, clrGreen, clrRed, clrGray #property indicator_color1 CLR_NONE, clrAqua, clrMagenta, clrGray
#property indicator_style1 STYLE_DOT #property indicator_style1 STYLE_SOLID
#property indicator_width1 1 #property indicator_width1 2
// //
// Mid ... // Mid ...
@@ -90,8 +90,8 @@ double midColorBuffer[];
#property indicator_label2 "X3VWAP M" #property indicator_label2 "X3VWAP M"
#property indicator_type2 DRAW_COLOR_LINE #property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 CLR_NONE, clrGreen, clrRed, clrGray #property indicator_color2 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style2 STYLE_DOT #property indicator_style2 STYLE_SOLID
#property indicator_width2 1 #property indicator_width2 2
// //
// Slow ... // Slow ...
@@ -105,9 +105,9 @@ double slowColorBuffer[];
#define slowPlotBufferIndex 2 #define slowPlotBufferIndex 2
#property indicator_label3 "X3VWAP S" #property indicator_label3 "X3VWAP S"
#property indicator_type3 DRAW_COLOR_LINE #property indicator_type3 DRAW_COLOR_LINE
#property indicator_color3 CLR_NONE, clrGreen, clrRed, clrGray #property indicator_color3 CLR_NONE, clrSteelBlue, clrDarkRed, clrGray
#property indicator_style3 STYLE_DOT #property indicator_style3 STYLE_SOLID
#property indicator_width3 1 #property indicator_width3 2
// //
// Data Buffers ... // Data Buffers ...
+4 -4
View File
@@ -107,11 +107,11 @@ struct XChartStyle
// //
input group "Chart Style"; input group "Chart Style";
input ENUM_CHART_MODE mode = CHART_CANDLES; // Mode input ENUM_CHART_MODE mode = CHART_CANDLES; // Mode
input color upColor = clrLime; // Up Color input color upColor = clrGreen; // Up Color
input color downColor = clrRed; // Down Color input color downColor = clrRed; // Down Color
input color lineColor = clrLime; // Line mode and Doji candlestick Color input color lineColor = clrGreen; // Line mode and Doji candlestick Color
input color bearishColor = clrRed; // Bullish Color input color bullishColor = clrGreen; // Bullish Color
input color bullishColor = clrLime; // Bearish Color input color bearishColor = clrRed; // Bearish Color
input color volumesColor = clrGreen; // Volumes Color input color volumesColor = clrGreen; // Volumes Color
// //
+11 -11
View File
@@ -69,10 +69,10 @@ input int hArrowCode = 225; // Hind Cycle Arrow Code
// //
input bool showCurrent = true; // Show Current Cycle input bool showCurrent = true; // Show Current Cycle
input bool showShort = true; // Show Short Cycle input bool showShort = false; // Show Short Cycle
input bool showMedium = true; // Show Medium Cycle input bool showMedium = false; // Show Medium Cycle
input bool showLong = true; // Show Long Cycle input bool showLong = false; // Show Long Cycle
input bool showHind = true; // Show Hind Cycle input bool showHind = false; // Show Hind Cycle
// //
// Buffers ... // Buffers ...
@@ -92,8 +92,8 @@ double cBuffer[];
// //
#property indicator_label1 "XCHSAR C" #property indicator_label1 "XCHSAR C"
#property indicator_type1 DRAW_ARROW #property indicator_type1 DRAW_ARROW
#property indicator_color1 clrRed #property indicator_color1 clrYellow
#property indicator_width1 1 #property indicator_width1 2
// //
// Short ... // Short ...
@@ -104,7 +104,7 @@ double sBuffer[];
#property indicator_label2 "XCHSAR S" #property indicator_label2 "XCHSAR S"
#property indicator_type2 DRAW_ARROW #property indicator_type2 DRAW_ARROW
#property indicator_color2 clrMagenta #property indicator_color2 clrMagenta
#property indicator_width2 1 #property indicator_width2 2
// //
// Medium ... // Medium ...
@@ -115,7 +115,7 @@ double mBuffer[];
#property indicator_label3 "XCHSAR M" #property indicator_label3 "XCHSAR M"
#property indicator_type3 DRAW_ARROW #property indicator_type3 DRAW_ARROW
#property indicator_color3 clrDodgerBlue #property indicator_color3 clrDodgerBlue
#property indicator_width3 1 #property indicator_width3 2
// //
// Long ... // Long ...
@@ -126,7 +126,7 @@ double lBuffer[];
#property indicator_label4 "XCHSAR L" #property indicator_label4 "XCHSAR L"
#property indicator_type4 DRAW_ARROW #property indicator_type4 DRAW_ARROW
#property indicator_color4 clrLime #property indicator_color4 clrLime
#property indicator_width4 1 #property indicator_width4 2
// //
// Hind ... // Hind ...
@@ -136,8 +136,8 @@ double hBuffer[];
// //
#property indicator_label5 "XCHSAR H" #property indicator_label5 "XCHSAR H"
#property indicator_type5 DRAW_ARROW #property indicator_type5 DRAW_ARROW
#property indicator_color5 clrYellow #property indicator_color5 clrRed
#property indicator_width5 1 #property indicator_width5 2
// //
// Variables ... // Variables ...
+643
View File
@@ -0,0 +1,643 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------------
// Name: XTick Oscillator
// Description: Tick Charts ...
//
//
// 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 XTick Oscillator"
#property strict
//
// Definitions ...
//
#define ShortName "XTick"
//
// Declaration of the enumeration
enum ENUM_X_PRICE_TYPES
{
X_Bid, // Bid
X_Ask // Ask
};
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
input group "Makret";
//
input group "Chart Config";
input int ticksCount = 3; // Ticks Count
input ENUM_X_PRICE_TYPES appliedPrice = 0; // Price
//
input group "Moving Average";
input int maLength = 10; // Length
input int maShift = 0; // Shift
input ENUM_MA_METHOD maMethod = MODE_SMA; // Mode
input ENUM_X_PRICE maAppliedTo = X_PRICE_CLOSE; // Applied To
//
input group "Presentation";
input bool showBars = true; // Show Bars
input bool showMa = true; // Show Moving Average
//
// Buffers ...
//
#property indicator_separate_window
//
#property indicator_buffers 8
#property indicator_plots 2
//
double openBuffer[];
#define openBufferIndex 0
//
double highBuffer[];
#define highBufferIndex 1
//
double lowBuffer[];
#define lowBufferIndex 2
//
double closeBuffer[];
#define closeBufferIndex 3
//
double colorBuffer[];
#define colorBufferIndex 4
//
#define barBufferIndex 0
#property indicator_label1 "Open;High;Low;Close"
#property indicator_type1 DRAW_COLOR_CANDLES
#property indicator_color1 CLR_NONE, clrGray, clrAqua, clrMagenta
//
double maBuffer[];
#define maBufferIndex 5
#define maPlotBufferIndex 1
//
#property indicator_label2 "MA"
#property indicator_type2 DRAW_LINE // DRAW_COLOR_LINE
#property indicator_color2 clrRoyalBlue // CLR_NONE, clrGreen, clrRed
#property indicator_style2 STYLE_DOT
#property indicator_width2 1
//
double ticksBuffer[];
#define ticksBufferIndex 6
//
double maPriceBuffer[];
#define maPriceBufferIndex 7
//
#define hideColorIDX 0;
#define neuturalColorIDX 1;
#define bullishColorIDX 2;
#define bearishColorIDX 3;
//
// The variable contains the number of stored quotes ...
int ticks_stored;
//
// The variable specifies the path and prefix to the file name ...
string path_prefix = ""; // FileName Prefix
//
// Event Handlers ...
/**
* Initialize Indicator ...
*
* @return ( int )
*/
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// 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);
//
int file_handle; // is a file handle
int bidPosition; // are positions of Bid prices in the string
int askPosition; // are positions of Ask prices in the string
int line_string_len; // is a length of a string, read from the file
int barNumber; // number of candle, for which the prices OHLC are determined
int i; // loop counter
//
// the recent received Bid price ...
double last_price_bid = SymbolInfoDouble(Symbol(), SYMBOL_BID);
//
// the recent received Ask price ...
double last_price_ask = SymbolInfoDouble(Symbol(), SYMBOL_ASK);
//
string filename; // name of a file, the file_buffer is a string
string file_buffer; // a buffer for reading and writing of string data
//
// Setting the size of ticksBuffer array ...
ArrayResize(ticksBuffer, ArraySize(closeBuffer));
//
// File name formation from the path_prefix variable, name
// of financial instrument and ".Txt" symbols
StringConcatenate(filename, path_prefix, Symbol(), ".txt");
//
// Opening a file for reading and writing, codepage ANSI, shared reading mode
file_handle = FileOpen(filename, FILE_READ | FILE_WRITE | FILE_ANSI | FILE_SHARE_READ);
if (prev_calculated == 0)
{
//
// Reading the first line from the file and determine the length of a string ...
line_string_len = StringLen(FileReadString(file_handle)) + 2;
//
// if file is large (contains more quotes than rates_total/2) ...
if (FileSize(file_handle) > (ulong)line_string_len * rates_total / 2)
{
//
// Setting file pointer to read the latest rates_total/2 quotes
FileSeek(file_handle, -line_string_len * rates_total / 2, SEEK_END);
//
// Moving file pointer to the beginning of the next line
FileReadString(file_handle);
}
//
// if file size is small
else
{
//
// Moving file pointer at the beginning of a file
FileSeek(file_handle, 0, SEEK_SET);
}
//
// Reset the counter of stored quotes
ticks_stored = 0;
//
// Reading until the end of the file
while (FileIsEnding(file_handle) == false)
{
//
// Reading a string from thefile
file_buffer = FileReadString(file_handle);
//
// Processing of string if its length is larger than 6 characters
if (StringLen(file_buffer) > 6)
{
//
// Finding the start position of Bid price in the line
bidPosition = StringFind(file_buffer, " ", StringFind(file_buffer, " ") + 1) + 1;
//
// Finding the start position of Ask price in the line
askPosition = StringFind(file_buffer, " ", bidPosition) + 1;
//
// If the Bid prices are used, adding the Bid price to ticksBuffer[] array
if (appliedPrice == 0)
{
ticksBuffer[ticks_stored] = StringToDouble(StringSubstr(file_buffer, bidPosition, askPosition - bidPosition - 1));
}
//
// If the Ask prices are used, adding the Ask price to ticksBuffer[] array
if (appliedPrice == 1)
{
ticksBuffer[ticks_stored] = StringToDouble(StringSubstr(file_buffer, askPosition));
}
//
// Increasing the counter of stored quotes
ticks_stored++;
}
}
}
//
// If the data have been read before
else
{
//
// Moving file pointer at the end of the file
FileSeek(file_handle, 0, SEEK_END);
//
// Forming a string, that should be written to the file
StringConcatenate(file_buffer, TimeCurrent(), " ", DoubleToString(last_price_bid, _Digits), " ", DoubleToString(last_price_ask, _Digits));
//
// Writing a string to the file
FileWrite(file_handle, file_buffer);
//
// If the Bid prices are used, adding the last Bid price to ticksBuffer[] array
if (appliedPrice == 0)
{
ticksBuffer[ticks_stored] = last_price_bid;
}
//
// If the Ask prices are used, adding the last Ask price to ticksBuffer[] array
if (appliedPrice == 1)
{
ticksBuffer[ticks_stored] = last_price_ask;
}
//
// Increasing the quotes counter
ticks_stored++;
}
//
// Closing the file
FileClose(file_handle);
//
// If number of quotes is more or equal than number of bars in the chart
if (ticks_stored >= rates_total)
{
//
// Removing the first tick_stored/2 quotes and shifting remaining quotes
for (i = ticks_stored / 2; i < ticks_stored; i++)
{
//
// Shifting the data to the beginning in the ticksBuffer[] array on tick_stored/2
ticksBuffer[i - ticks_stored / 2] = ticksBuffer[i];
}
//
// Changing the quotes counter
ticks_stored -= ticks_stored / 2;
}
//
// We assign the barNumber with a number of invalid candle
barNumber = -1;
//
// Search for all the price data available for candle formation
for (i = 0; i < ticks_stored; i++)
{
//
// If this candle is forming already
if (barNumber == (int)(MathFloor((ticks_stored - 1) / ticksCount) - MathFloor(i / ticksCount)))
{
//
// The current quote is still closing price of the current candle
closeBuffer[barNumber] = ticksBuffer[i];
//
// If the current price is greater than the highest price of the current candle, it will be a new highest price of the candle
if (ticksBuffer[i] > highBuffer[barNumber])
{
highBuffer[barNumber] = ticksBuffer[i];
}
//
// If the current price is lower than the lowest price of the current candle, it will be a new lowest price of the candle
if (ticksBuffer[i] < lowBuffer[barNumber])
{
lowBuffer[barNumber] = ticksBuffer[i];
}
//
// If the candle is bullish ...
if (closeBuffer[barNumber] > openBuffer[barNumber])
{
colorBuffer[barNumber] = bullishColorIDX;
}
//
// If the candle is bearish ...
if (closeBuffer[barNumber] < openBuffer[barNumber])
{
colorBuffer[barNumber] = bearishColorIDX;
}
//
// If the opening and closing prices are equal, then the candle will have a color with index 0 (grey)
if (closeBuffer[barNumber] == openBuffer[barNumber])
{
colorBuffer[barNumber] = neuturalColorIDX;
}
}
//
// If this candle hasn't benn calculated yet
else
{
//
// Let's determine the index of a candle
barNumber = (int)(MathFloor((ticks_stored - 1) / ticksCount) - MathFloor(i / ticksCount));
//
// The current quote will be the opening price of a candle
openBuffer[barNumber] = ticksBuffer[i];
//
// The current quote will be the highest price of a candle
highBuffer[barNumber] = ticksBuffer[i];
//
// The current quote will be the lowest price of a candle
lowBuffer[barNumber] = ticksBuffer[i];
//
// The current quote will be the closing price of a candle
closeBuffer[barNumber] = ticksBuffer[i];
//
// The candle will have a color with index 0 (gray)
colorBuffer[barNumber] = 0;
}
}
//
// Custom Calculations ...
//
int 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 //
);
}
//
// Return from OnCalculate(), return a value, different from zero
return (rates_total);
}
//
// Functions ...
/**
* Validate Input Args for Initialization ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result =
//
ticksCount > 0
//
;
//
return result;
}
/**
* Define Required Buffers ...
*/
void DefineBuffers()
{
//
// Color ...
ArraySetAsSeries(colorBuffer, true);
SetIndexBuffer(colorBufferIndex, colorBuffer, INDICATOR_COLOR_INDEX);
//
// Set EMPTY_VALUE on Bar Buffer ...
PlotIndexSetDouble(barBufferIndex, PLOT_EMPTY_VALUE, 0.0);
//
PlotIndexSetInteger(barBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(colorBufferIndex, PLOT_SHOW_DATA, false);
//
// Open ...
ArraySetAsSeries(openBuffer, true);
PlotIndexSetInteger(openBufferIndex, PLOT_SHOW_DATA, true);
SetIndexBuffer(openBufferIndex, openBuffer, INDICATOR_DATA);
//
// High ...
ArraySetAsSeries(highBuffer, true);
PlotIndexSetInteger(highBufferIndex, PLOT_SHOW_DATA, true);
SetIndexBuffer(highBufferIndex, highBuffer, INDICATOR_DATA);
//
// Close ...
ArraySetAsSeries(closeBuffer, true);
PlotIndexSetInteger(closeBufferIndex, PLOT_SHOW_DATA, true);
SetIndexBuffer(closeBufferIndex, closeBuffer, INDICATOR_DATA);
//
// Low ...
ArraySetAsSeries(lowBuffer, true);
PlotIndexSetInteger(lowBufferIndex, PLOT_SHOW_DATA, true);
SetIndexBuffer(lowBufferIndex, lowBuffer, INDICATOR_DATA);
//
bool canShowMa = showMa;
ArraySetAsSeries(maBuffer, true);
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA);
PlotIndexSetDouble(maPlotBufferIndex, PLOT_EMPTY_VALUE, 0);
PlotIndexSetInteger(maPlotBufferIndex, PLOT_DRAW_BEGIN, maLength);
PlotIndexSetInteger(maPlotBufferIndex, PLOT_SHOW_DATA, showMa);
//
// Data Buffers ...
//
// The TicksBuffer[] array is used for intermediate calculations
SetIndexBuffer(ticksBufferIndex, ticksBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(maPriceBuffer, true);
SetIndexBuffer(maPriceBufferIndex, maPriceBuffer, INDICATOR_CALCULATIONS);
}
/**
* Set Indicator Short Name and also we can define Buffers Labels ...
*/
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
/**
* Calculate Custom Buffers ...
*
* @param barIndex: Integer ...
*/
void CalculateBuffers(
int barIndex,
int prevCalculated,
int ratesTotal //
)
{
//
bool canDoMovingAverage =
maLength > 0 &&
maAppliedTo != X_PRICE_UP &&
maAppliedTo != X_PRICE_DOWN;
if (canDoMovingAverage)
{
//
// Do Moving Average Calculations ...
//
// Select Ma Price ...
double iPrice = 0;
switch (maAppliedTo)
{
//
case X_PRICE_HIGH:
iPrice = highBuffer[barIndex];
break;
//
case X_PRICE_OPEN:
iPrice = openBuffer[barIndex];
break;
//
case X_PRICE_CLOSE:
iPrice = closeBuffer[barIndex];
break;
//
case X_PRICE_LOW:
iPrice = lowBuffer[barIndex];
break;
}
//
maPriceBuffer[barIndex] = iPrice;
int total = ArraySize(closeBuffer);
//
int calculatedMas = iMAOnBuffer(
total,
prevCalculated,
barIndex,
maLength,
maPriceBuffer,
maBuffer,
maMethod //
);
}
}
//
+188 -521
View File
@@ -23,6 +23,9 @@
// Imports ... // Imports ...
#include "../Classes/x-saherelm.x-md5.class.mq5" #include "../Classes/x-saherelm.x-md5.class.mq5"
//
#include <MovingAverages.mqh>
// //
// Models ... // Models ...
@@ -6918,247 +6921,6 @@ struct XMarketParser
// //
}; };
//
// Styling Buffers ...
//
struct XBufferPlotStyle
{
//
int width; // Width
color clr; // Color
uchar arrow; // Arrow Code
ENUM_DRAW_TYPE type; // Type
ENUM_LINE_STYLE style; // Style
//
// Constructor ...
XBufferPlotStyle()
{
Default();
}
//
// Tools ...
//
// Default ...
void Default()
{
//
width = 1;
arrow = 0;
clr = CLR_NONE;
type = DRAW_NONE;
style = STYLE_SOLID;
}
};
//
// Register a Buffer as Indexed Buffer ...
void SetIndexBuffer(
int &index, // the Index refrence for Buffer
double &buffer[], // Buffer to Set
XBufferPlotStyle &style, // Style to Apply to Buffer
double &colorBuffer[], // Color Buffer
string label = NULL, // Buffer Label
bool showData = true, // Show Data on Data Window
double empty = -1, // Set 0 or EMPTY_VALUE used for setting Empty Value
int drawBegin = -1 // if Set More Than -1 applied
)
{
//
// Set Buffer Index ...
SetIndexBuffer(index, buffer, INDICATOR_DATA);
//
// Show Date ...
PlotIndexSetInteger(index, PLOT_SHOW_DATA, showData);
//
// Set Buffer Label ...
if (IsValid(label))
{
PlotIndexSetString(index, PLOT_LABEL, label);
}
//
if (empty == 0 || empty == EMPTY_VALUE)
{
PlotIndexSetDouble(index, PLOT_EMPTY_VALUE, empty);
}
//
if (drawBegin > -1)
{
PlotIndexSetInteger(index, PLOT_DRAW_BEGIN, drawBegin);
}
//
if (style.type == DRAW_ARROW)
{
PlotIndexSetInteger(index, PLOT_ARROW, style.arrow);
}
//
PlotIndexSetInteger(index, PLOT_LINE_STYLE, style.style);
PlotIndexSetInteger(index, PLOT_LINE_WIDTH, style.width);
//
string drawTypeStr = EnumToString(style.type);
bool hasColorBuffer = Contains("COLOR", drawTypeStr);
//
if (!hasColorBuffer)
{
PlotIndexSetInteger(index, PLOT_LINE_COLOR, style.clr);
}
else
{
//
// Since Color Buffers must add as next Index of it's own Buffer
// here before applied Color Buffer increase index ...
index++;
//
SetIndexBuffer(index, colorBuffer, INDICATOR_COLOR_INDEX);
}
//
// Increase Index for Next Buffer ...
index++;
}
//
void SetIndexCandleBuffers(
int &index, // the Index refrence for Buffer
string openLabel, // Open Label
double &open[], // Open Buffer
string highLabel, // High Label
double &high[], // High Buffer
string lowLabel, // Low Label
double &low[], // Low Buffer
string closeLabel, // Close Label
double &close[], // Close Buffer
bool showData = true, // Show Data on Data Window
double empty = -1, // Set 0 or EMPTY_VALUE used for setting Empty Value
int drawBegin = -1 // if Set More Than -1 applied
)
{
//
bool hasLabel =
//
IsValid(openLabel) &&
IsValid(highLabel) &&
IsValid(lowLabel) &&
IsValid(closeLabel)
//
;
//
string label =
!hasLabel
? NULL
: openLabel + ";" + highLabel + ";" + lowLabel + ";" + closeLabel;
//
// Set Buffer Index ...
SetIndexBuffer(index, open, INDICATOR_DATA);
//
// Set Draw Candles Type ...
PlotIndexSetInteger(index, PLOT_LINE_STYLE, DRAW_CANDLES);
//
// Show Date ...
PlotIndexSetInteger(index, PLOT_SHOW_DATA, showData);
//
// Set Buffer Label ...
if (IsValid(label))
{
PlotIndexSetString(index, PLOT_LABEL, label);
}
//
if (empty == 0 || empty == EMPTY_VALUE)
{
PlotIndexSetDouble(index, PLOT_EMPTY_VALUE, empty);
}
//
if (drawBegin > -1)
{
PlotIndexSetInteger(index, PLOT_DRAW_BEGIN, drawBegin);
}
//
index++;
//
// Set Buffer Index ...
SetIndexBuffer(index, high, INDICATOR_DATA);
index++;
//
// Set Buffer Index ...
SetIndexBuffer(index, low, INDICATOR_DATA);
index++;
//
// Set Buffer Index ...
SetIndexBuffer(index, close, INDICATOR_DATA);
index++;
}
//
void SetIndexCandleBuffers(
int &index, // the Index refrence for Buffer
string openLabel, // Open Label
double &open[], // Open Buffer
string highLabel, // High Label
double &high[], // High Buffer
string lowLabel, // Low Label
double &low[], // Low Buffer
string closeLabel, // Close Label
double &close[], // Close Buffer
double &colorBuffer[], // Candle Color Buffer
bool showData = true, // Show Data on Data Window
double empty = -1, // Set 0 or EMPTY_VALUE used for setting Empty Value
int drawBegin = -1 // if Set More Than -1 applied
)
{
//
SetIndexCandleBuffers(
index,
openLabel,
open,
highLabel,
high,
lowLabel,
low,
closeLabel,
close,
showData,
empty,
drawBegin //
);
//
int mFirstIndex = index - 4;
//
// Set Draw Candles Type ...
PlotIndexSetInteger(mFirstIndex, PLOT_LINE_STYLE, DRAW_COLOR_CANDLES);
//
// Set Color Buffer ...
SetIndexBuffer(index, colorBuffer, INDICATOR_COLOR_INDEX);
//
index++;
}
// //
// Functions ... // Functions ...
@@ -9785,212 +9547,6 @@ double GetFibonacciLevel(
return result; return result;
} }
//
double MAOnArray(
double &array[],
int total,
int period,
int ma_shift,
int ma_method,
int shift //
)
{
//
double result = 0;
//
double buf[];
double arr[];
//
if (total == 0)
{
total = ArraySize(array);
}
//
if (total > 0 && total <= period)
{
return result;
}
//
if (shift > total - period - ma_shift)
{
return result;
}
//
// MA Method ...
switch (ma_method)
{
//
// Mode SMA ...
case MODE_SMA: {
//
total = ArrayCopy(arr, array, 0, shift + ma_shift, period);
if (ArrayResize(buf, total) < 0)
{
return result;
}
//
double sum = 0;
int i, pos = total - 1;
for (i = 1; i < period; i++, pos--)
{
sum += arr[pos];
}
//
while (pos >= 0)
{
//
sum += arr[pos];
buf[pos] = sum / period;
sum -= arr[pos + period - 1];
pos--;
}
//
result = buf[0];
return result;
}
//
// Mode EMA ...
case MODE_EMA: {
//
if (ArrayResize(buf, total) < 0)
{
return result;
}
//
int pos = total - 2;
double pr = 2.0 / (period + 1);
//
while (pos >= 0)
{
//
if (pos == total - 2)
{
buf[pos + 1] = array[pos + 1];
}
//
buf[pos] = array[pos] * pr + buf[pos + 1] * (1 - pr);
pos--;
}
//
result = buf[shift + ma_shift];
return result;
}
//
// Mode SMMA ...
case MODE_SMMA: {
//
if (ArrayResize(buf, total) < 0)
{
return result;
}
//
int i, kk, pos;
double sum = 0;
pos = total - period;
//
while (pos >= 0)
{
//
if (pos == total - period)
{
//
for (i = 0, kk = pos; i < period; i++, kk++)
{
//
sum += array[kk];
buf[kk] = 0;
}
}
else
{
sum = buf[pos + 1] * (period - 1) + array[pos];
}
//
buf[pos] = sum / period;
pos--;
}
//
result = buf[shift + ma_shift];
return result;
}
//
// Mode LWMA ...
case MODE_LWMA: {
//
if (ArrayResize(buf, total) < 0)
{
return result;
}
//
double price;
double sum = 0.0, lsum = 0.0;
int i, weight = 0, pos = total - 1;
//
for (i = 1; i <= period; i++, pos--)
{
//
price = array[pos];
sum += price * i;
lsum += price;
weight += i;
}
//
pos++;
i = pos + period;
while (pos >= 0)
{
//
buf[pos] = sum / weight;
if (pos == 0)
{
break;
}
//
i--;
pos--;
price = array[pos];
sum = sum - lsum + price * period;
lsum -= array[i];
lsum += price;
}
//
result = buf[shift + ma_shift];
return result;
}
//
default:
return result;
}
//
return result;
}
// //
// Method 1 // Method 1
// Normalize between 1 and 0 ... // Normalize between 1 and 0 ...
@@ -12869,55 +12425,59 @@ ENUM_TIMEFRAMES GetNearestPeriod(ENUM_TIMEFRAMES mPeriod)
// //
case PERIOD_M1: case PERIOD_M1:
case PERIOD_M2: case PERIOD_M2:
result = PERIOD_M4; case PERIOD_M3:
result = PERIOD_M5;
break; break;
// //
case PERIOD_M3:
case PERIOD_M4: case PERIOD_M4:
result = PERIOD_M6;
break;
//
case PERIOD_M5: case PERIOD_M5:
case PERIOD_M6: case PERIOD_M6:
case PERIOD_M10: result = PERIOD_M10;
case PERIOD_M12:
result = PERIOD_M15;
break; break;
// //
case PERIOD_M10:
case PERIOD_M12:
case PERIOD_M15: case PERIOD_M15:
result = PERIOD_M20;
break;
//
case PERIOD_M20: case PERIOD_M20:
result = PERIOD_M30; case PERIOD_M30:
result = PERIOD_H1;
break; break;
// //
case PERIOD_H1: case PERIOD_H1:
case PERIOD_H2: case PERIOD_H2:
result = PERIOD_H3;
break;
//
case PERIOD_H3: case PERIOD_H3:
result = PERIOD_H4; result = PERIOD_H4;
break; break;
//
case PERIOD_H4:
result = PERIOD_H6;
break;
// //
case PERIOD_H6: case PERIOD_H6:
result = PERIOD_H8;
break;
//
case PERIOD_H8: case PERIOD_H8:
result = PERIOD_H12; result = PERIOD_H12;
break; break;
//
case PERIOD_H12:
result = PERIOD_D1;
break;
//
case PERIOD_D1:
result = PERIOD_W1;
break;
// //
default: default:
result = PERIOD_MN1; result = mPeriod;
break; break;
} }
@@ -12941,55 +12501,59 @@ ENUM_TIMEFRAMES GetMediestPeriod(ENUM_TIMEFRAMES mPeriod)
// //
case PERIOD_M1: case PERIOD_M1:
case PERIOD_M2: case PERIOD_M2:
result = PERIOD_M15; case PERIOD_M3:
result = PERIOD_M10;
break; break;
// //
case PERIOD_M3:
case PERIOD_M4: case PERIOD_M4:
case PERIOD_M5:
case PERIOD_M6:
result = PERIOD_M15;
break;
//
case PERIOD_M10:
case PERIOD_M12:
case PERIOD_M15:
result = PERIOD_M30; result = PERIOD_M30;
break; break;
// //
case PERIOD_M5:
case PERIOD_M6:
case PERIOD_M10:
case PERIOD_M12:
result = PERIOD_H1;
break;
//
case PERIOD_M15:
case PERIOD_M20: case PERIOD_M20:
case PERIOD_M30:
result = PERIOD_H2; result = PERIOD_H2;
break; break;
// //
case PERIOD_H1: case PERIOD_H1:
case PERIOD_H2: case PERIOD_H2:
result = PERIOD_H4;
break;
//
case PERIOD_H3: case PERIOD_H3:
result = PERIOD_H6;
break;
//
case PERIOD_H4:
result = PERIOD_H8; result = PERIOD_H8;
break; break;
// //
case PERIOD_H6: case PERIOD_H6:
result = PERIOD_H12;
break;
//
case PERIOD_H8: case PERIOD_H8:
result = PERIOD_D1; result = PERIOD_D1;
break; break;
//
case PERIOD_H12:
result = PERIOD_W1;
break;
//
case PERIOD_D1:
result = PERIOD_MN1;
break;
// //
default: default:
result = PERIOD_MN1; result = mPeriod;
break; break;
} }
@@ -13013,55 +12577,59 @@ ENUM_TIMEFRAMES GetLongestPeriod(ENUM_TIMEFRAMES mPeriod)
// //
case PERIOD_M1: case PERIOD_M1:
case PERIOD_M2: case PERIOD_M2:
case PERIOD_M3:
result = PERIOD_M30; result = PERIOD_M30;
break; break;
// //
case PERIOD_M3:
case PERIOD_M4: case PERIOD_M4:
case PERIOD_M5:
case PERIOD_M6:
result = PERIOD_H1; result = PERIOD_H1;
break; break;
// //
case PERIOD_M5:
case PERIOD_M6:
case PERIOD_M10: case PERIOD_M10:
case PERIOD_M12: case PERIOD_M12:
case PERIOD_M15:
result = PERIOD_H2; result = PERIOD_H2;
break; break;
// //
case PERIOD_M15:
case PERIOD_M20: case PERIOD_M20:
case PERIOD_M30:
result = PERIOD_H4; result = PERIOD_H4;
break; break;
// //
case PERIOD_H1: case PERIOD_H1:
case PERIOD_H2: case PERIOD_H2:
result = PERIOD_H6;
break;
//
case PERIOD_H3: case PERIOD_H3:
result = PERIOD_H8;
break;
//
case PERIOD_H4:
result = PERIOD_H12; result = PERIOD_H12;
break; break;
// //
case PERIOD_H6: case PERIOD_H6:
result = PERIOD_D1;
break;
//
case PERIOD_H8: case PERIOD_H8:
result = PERIOD_W1; result = PERIOD_W1;
break; break;
//
case PERIOD_H12:
result = PERIOD_MN1;
break;
//
case PERIOD_D1:
result = PERIOD_MN1;
break;
// //
default: default:
result = PERIOD_MN1; result = mPeriod;
break; break;
} }
@@ -13085,55 +12653,59 @@ ENUM_TIMEFRAMES GetHindMostPeriod(ENUM_TIMEFRAMES mPeriod)
// //
case PERIOD_M1: case PERIOD_M1:
case PERIOD_M2: case PERIOD_M2:
case PERIOD_M3:
result = PERIOD_H1; result = PERIOD_H1;
break; break;
// //
case PERIOD_M3:
case PERIOD_M4: case PERIOD_M4:
case PERIOD_M5:
case PERIOD_M6:
result = PERIOD_H2; result = PERIOD_H2;
break; break;
// //
case PERIOD_M5:
case PERIOD_M6:
case PERIOD_M10: case PERIOD_M10:
case PERIOD_M12: case PERIOD_M12:
case PERIOD_M15:
result = PERIOD_H4; result = PERIOD_H4;
break; break;
// //
case PERIOD_M15:
case PERIOD_M20: case PERIOD_M20:
result = PERIOD_H8; case PERIOD_M30:
result = PERIOD_H6;
break; break;
// //
case PERIOD_H1: case PERIOD_H1:
case PERIOD_H2: case PERIOD_H2:
result = PERIOD_H8;
break;
//
case PERIOD_H3: case PERIOD_H3:
result = PERIOD_H12;
break;
//
case PERIOD_H4:
result = PERIOD_D1; result = PERIOD_D1;
break; break;
// //
case PERIOD_H6: case PERIOD_H6:
result = PERIOD_W1;
break;
//
case PERIOD_H8: case PERIOD_H8:
result = PERIOD_MN1; result = PERIOD_MN1;
break; break;
//
case PERIOD_H12:
result = PERIOD_MN1;
break;
//
case PERIOD_D1:
result = PERIOD_MN1;
break;
// //
default: default:
result = PERIOD_MN1; result = mPeriod;
break; break;
} }
@@ -13321,3 +12893,98 @@ bool IsSpecifiedBearish(ENUM_X_DIRECTION value)
} }
// //
// Moving Average ...
/**
* Calculate Sspecified Buffer's Moving Averages ...
*
* @param rates_total: Integer, number of items ...
* @param prev_calculated: Integer, Previous Calculate Items ...
* @param begin: Integer, Bar Index ...
* @param period: Integer, Moving Average Length ...
* @param price: Double Array, Specified Array for Calculating Moving Averages ...
* @param buffer: Double Array, Specified Array to Apply Calculated Moving Average on it ...
* @param method: ENUM_MA_METHOD member Specified Moving Average Calculation Method ...
*
* @return ( int )
*/
int iMAOnBuffer(
const int rates_total,
const int prev_calculated,
const int begin,
const int period,
const double &price[],
double &buffer[],
ENUM_MA_METHOD method = MODE_SMA //
)
{
//
int result = 0;
//
if (
period < 0 ||
rates_total <= 0 ||
prev_calculated < 0 ||
prev_calculated > rates_total)
{
return result;
}
//
switch (method)
{
//
case MODE_SMA:
result = SimpleMAOnBuffer(
rates_total,
prev_calculated,
begin,
period,
price,
buffer //
);
break;
//
case MODE_EMA:
result = ExponentialMAOnBuffer(
rates_total,
prev_calculated,
begin,
period,
price,
buffer //
);
break;
//
case MODE_LWMA:
result = LinearWeightedMAOnBuffer(
rates_total,
prev_calculated,
begin,
period,
price,
buffer //
);
break;
//
case MODE_SMMA:
result = SmoothedMAOnBuffer(
rates_total,
prev_calculated,
begin,
period,
price,
buffer //
);
break;
}
//
return result;
}
//
@@ -588,10 +588,10 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy
if (IsBullish(marketStructureDir)) if (IsBullish(marketStructureDir))
{ {
// //
ignoreSwingLows = false; ignoreSwingLows = true;
ignoreSupportZones = false; ignoreSupportZones = true;
ignoreDemandZones = false; ignoreDemandZones = true;
ignoreBullishOrderBlocks = false; ignoreBullishOrderBlocks = true;
ignoreBullishFairValueGaps = false; ignoreBullishFairValueGaps = false;
ignoreBullishRejectionBars = false; ignoreBullishRejectionBars = false;
ignoreBullishMomentumBars = false; ignoreBullishMomentumBars = false;