Initial Commit ...

This commit is contained in:
2024-01-25 04:05:58 +03:30
commit dac3101466
520 changed files with 186332 additions and 0 deletions
@@ -0,0 +1,141 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center RMA Indicator
// ---------------------------------------------
// saherelm implementation of above oscillator ...
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm RMA Indicator"
#property strict
//
// START Inputs ...
//
//
// Set the RMA Length ...
input int RMALength = 10; // Length
//
// END Inputs ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
#property indicator_chart_window
//
// we have 2 buffer in this indicator ...
#property indicator_buffers 1
//
// also we have 1 line for draw on this indicator ...
#property indicator_plots 1
//
// here we declare plot SlowOCS to system ...
#property indicator_label1 "RMA"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrFuchsia
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
// Declare Buffers ...
#define RMABufferIndex 0
//
double RMABuffer[];
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// Start Event Handlers ...
//
//
// Initialization ...
int OnInit() {
//
// Initialize what we want ...
SetIndexBuffer(RMABufferIndex, RMABuffer);
//
// initialization done ...
return(INIT_SUCCEEDED);
}
//
// Do Calculation ...
int OnCalculate(
const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[]
) {
//
int maxLength = MathMax(0, RMALength);
//
// wait to pass bars until we have rights ...
if (rates_total <= maxLength) {
//
// return not calculated ...
return 0;
}
//
// find loop count for bars manipulation ...
int count = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1;
//
// Print("Count: ", count, ", Bars: ", Bars);
//
// this is the main loop of calculations, for each bar index ...
for (int i = count - 1; i >= 0; i--) {
//
// Start Calculation with Formula 1 ...
//
double shortSMA = iMA(_Symbol, _Period, RMALength, 0, MODE_SMA, PRICE_CLOSE, i);
double mediumSMA = iMA(_Symbol, _Period, RMALength * 2, 0, MODE_SMA, PRICE_CLOSE, i);
double longSMA = iMA(_Symbol, _Period, RMALength * 3, 0, MODE_SMA, PRICE_CLOSE, i);
//
double rma1 = longSMA - mediumSMA + shortSMA;
rma1 = NormalizeDouble(rma1, _Digits);
//
// End Calculation with Formula 1 ...
//
//
RMABuffer[i] = rma1;
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// END Functions ...
//
@@ -0,0 +1,270 @@
/////////////////////////////////////////////////////////////////
//
// SaherElm IT Center Volume Indicator
// -------------------------------------------------------------
// this indicator provides Volume ...
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
////////////////////////////////////////////////////////////////
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm Volume Indicator"
#property strict
//
// START Inputs ...
//
input int length = 11; // Length
//
// END Inputs ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
// Includes our shared library ...
#include "../Libraries/x-saherelm.lib.mq4"
//
#property indicator_separate_window
//
// we have 2 buffer in this indicator ...
#property indicator_buffers 3
//
// also we have 2 line for draw on this indicator ...
#property indicator_plots 3
//
// Buy Volume ...
#property indicator_width1 1
#property indicator_color1 clrGreen
#property indicator_type1 DRAW_HISTOGRAM
#property indicator_style1 STYLE_DOT
//
// Sell Volume ...
#property indicator_width2 1
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrRed
#property indicator_style2 STYLE_DOT
//
// Diff ...
#property indicator_width3 1
#property indicator_type3 DRAW_HISTOGRAM
#property indicator_color3 clrYellow
#property indicator_style3 STYLE_SOLID
//
//#property indicator_minimum 0
//#property indicator_maximum 1
//
// set color of horizontal levels ...
#property indicator_levelcolor clrGray
//
// set style of horizontal levels ...
#property indicator_levelstyle STYLE_DOT
//
// Declare Buffers ...
#define buyVolumeBufferIndex 0
#define sellVolumeBufferIndex 1
#define diffBufferIndex 2
//
double buyVolumeBuffer[];
double sellVolumeBuffer[];
double diffBuffer[];
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// Start Event Handlers ...
//
//
// Initialization ...
int OnInit() {
//
// Initialize what we want ...
//
// Validating Input Parameters ...
if (length < 0) {
return INIT_PARAMETERS_INCORRECT;
}
//
// set descriptions of horizontal levels ...
SetLevelValue(0, 0.0);
IndicatorSetString(INDICATOR_LEVELTEXT,0,"");
//
// Buy Volume Buffer ...
SetIndexBuffer(buyVolumeBufferIndex, buyVolumeBuffer);
SetIndexLabel(buyVolumeBufferIndex, "Buy Volume");
//
// Sell Volume Buffer ...
SetIndexBuffer(sellVolumeBufferIndex, sellVolumeBuffer);
SetIndexLabel(sellVolumeBufferIndex, "Sell Volume");
//
// Diff Buffer ...
SetIndexBuffer(diffBufferIndex, diffBuffer);
SetIndexLabel(diffBufferIndex, "Diff");
//
// here we specify logging enabled or not ...
enableLogging = true;
//
// this is a Tag which attached to our Logger ...
logTag = "XS_VOLUME";
//
return(INIT_SUCCEEDED);
}
//
// Do Calculation ...
int OnCalculate(
const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[]
) {
//
// this counts Available Bars ...
int limit;
//
// because in some cases we may have more than one input for
// calculation and we must prevent any calculation
// untill we pass the biggest input length, here we get max Input length
// and then wait until pass it ...
int maxLength = MathMax(0, length);
//
// input variable, we return 0 means nothing passed ...
if (rates_total < maxLength) {
return 0;
}
//
// found which candles calculated before ...
limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1;
//
// this is the main loop of calculations, for each bar index ...
for (int i = limit - 1; i >= 0; i--) {
//
// Start Calculation here ...
// i is bar_index ...
//
CalculateBuffers(
open,
close,
high,
low,
i
);
}
//
return rates_total;
}
//
// De Initialization ...
void OnDeinit(const int reason) {
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
void CalculateBuffers(
const double &open[],
const double &close[],
const double &high[],
const double &low[],
const int &bar_index
) {
//
long volume = iVolume(
_Symbol,
_Period,
bar_index
);
//
double buyVolume = 0.0;
double sellVolume = 0.0;
//
// Up ...
if (close[bar_index] > open[bar_index]) {
//
double cuenta = (high[bar_index] - low[bar_index]) * 10000;
double cuenta1 = volume - cuenta;
//
buyVolume = ((volume - cuenta) / 2) + cuenta;
//
buyVolumeBuffer[bar_index] = buyVolume;
sellVolumeBuffer[bar_index] = volume - buyVolume;
} else
//
// Down ...
if (close[bar_index] < open[bar_index]) {
//
double cuenta1 = (high[bar_index] - low[bar_index]) * 10000;
double cuenta = volume - cuenta1;
//
sellVolume = ((volume - cuenta1) / 2) + cuenta1;
//
sellVolumeBuffer[bar_index] = sellVolume;
buyVolumeBuffer[bar_index] = volume - sellVolume;
} else
//
// Neutral ...
if (close[bar_index] == open[bar_index]) {
//
double cuenta = (volume / 2) * 1.0;
//
sellVolumeBuffer[bar_index] = cuenta;
buyVolumeBuffer[bar_index] = volume - cuenta;
}
//
diffBuffer[bar_index] = MathAbs(buyVolumeBuffer[bar_index]) - MathAbs(sellVolumeBuffer[bar_index]);
}
//
// END Functions ...
//
@@ -0,0 +1,394 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center XMKT Indicator
// ---------------------------------------------
// retrieve market base info ...
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XMKT Indicator"
#property strict
//
// START Inputs ...
//
//
// Market Specifications ...
input int marketLength = 7; // Market Length
//
input bool showHighestHigh = true; // Show Market Highest High
input bool showHighestLow = true; // Show Market Highest Low
input bool showHighestOpen = true; // Show Market Highest Open
input bool showHighestClose = true; // Show Market Highest Close
input bool showLowestHigh = true; // Show Market Lowest High
input bool showLowestLow = true; // Show Market Lowest Low
input bool showLowestOpen = true; // Show Market Lowest Open
input bool showLowestClose = true; // Show Market Lowest Close
//
input color highestHighColor = clrDeepPink; // Market Highest High Color
input color highestLowColor = clrDarkOrange; // Market Highest Low Color
input color highestOpenColor = clrDodgerBlue; // Market Highest Open Color
input color highestCloseColor = clrOrchid; // Market Highest Close Color
input color lowestHighColor = clrHotPink; // Market Lowest High Color
input color lowestLowColor = clrOrange; // Market Lowest Low Color
input color lowestOpenColor = clrPowderBlue; // Market Lowest Open Color
input color lowestCloseColor = clrMediumOrchid; // Market Lowest Close Color
//
input ENUM_LINE_STYLE highestHighStyle = STYLE_DOT; // Market Highest High Line Style
input ENUM_LINE_STYLE highestLowStyle = STYLE_DOT; // Market Highest Low Line Style
input ENUM_LINE_STYLE highestOpenStyle = STYLE_DOT; // Market Highest Open Line Style
input ENUM_LINE_STYLE highestCloseStyle = STYLE_DOT; // Market Highest Close Line Style
input ENUM_LINE_STYLE lowestHighStyle = STYLE_DOT; // Market Lowest High Line Style
input ENUM_LINE_STYLE lowestLowStyle = STYLE_DOT; // Market Lowest Low Line Style
input ENUM_LINE_STYLE lowestOpenStyle = STYLE_DOT; // Market Lowest Open Line Style
input ENUM_LINE_STYLE lowestCloseStyle = STYLE_DOT; // Market Lowest Close Line Style
//
// END Inputs ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
#property indicator_chart_window
//
// define indicator buffers ...
#property indicator_buffers 8
#property indicator_plots 8
//
// Declare Buffers ...
#define marketHighestHighBufferIndex 0
#define marketHighestLowBufferIndex 1
#define marketHighestOpenBufferIndex 2
#define marketHighestCloseBufferIndex 3
#define marketLowestHighBufferIndex 4
#define marketLowestLowBufferIndex 5
#define marketLowestOpenBufferIndex 6
#define marketLowestCloseBufferIndex 7
//
double marketHighestHighBuffer[];
double marketHighestLowBuffer[];
double marketHighestOpenBuffer[];
double marketHighestCloseBuffer[];
double marketLowestHighBuffer[];
double marketLowestLowBuffer[];
double marketLowestOpenBuffer[];
double marketLowestCloseBuffer[];
//
// Includes our shared library ...
#include "../Libraries/x-saherelm.lib.mq4"
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// Start Event Handlers ...
//
//
// Initialization ...
int OnInit() {
//
// Initialize what we want ...
//
// Validating Input Parameters ...
if (marketLength <= 0) {
return INIT_PARAMETERS_INCORRECT;
}
//
// here we specify logging enabled or not ...
enableLogging = true;
//
// this is a Tag which attached to our Logger ...
logTag = "XST_XMKT";
//
// Highest High ...
string highestHighLbl = StringConcatenate("HH(", marketLength,")");
SetIndexLabel(marketHighestHighBufferIndex, highestHighLbl);
SetIndexBuffer(marketHighestHighBufferIndex, marketHighestHighBuffer);
SetIndexStyle(
marketHighestHighBufferIndex,
showHighestHigh ?
DRAW_LINE :
DRAW_NONE,
highestHighStyle,
1,
showHighestHigh ?
highestHighColor :
clrNONE
);
//
// Highest Low ...
string highestLowLbl = StringConcatenate("HL(", marketLength,")");
SetIndexLabel(marketHighestLowBufferIndex, highestLowLbl);
SetIndexBuffer(marketHighestLowBufferIndex, marketHighestLowBuffer);
SetIndexStyle(
marketHighestLowBufferIndex,
showHighestLow ?
DRAW_LINE :
DRAW_NONE,
highestLowStyle,
1,
showHighestLow ?
highestLowColor :
clrNONE
);
//
// Highest Open ...
string highestOpenLbl = StringConcatenate("HO(", marketLength,")");
SetIndexLabel(marketHighestOpenBufferIndex, highestOpenLbl);
SetIndexBuffer(marketHighestOpenBufferIndex, marketHighestOpenBuffer);
SetIndexStyle(
marketHighestOpenBufferIndex,
showHighestOpen ?
DRAW_LINE :
DRAW_NONE,
highestOpenStyle,
1,
showHighestOpen ?
highestOpenColor :
clrNONE
);
//
// Highest Close ...
string highestCloseLbl = StringConcatenate("HC(", marketLength,")");
SetIndexLabel(marketHighestCloseBufferIndex, highestCloseLbl);
SetIndexBuffer(marketHighestCloseBufferIndex, marketHighestCloseBuffer);
SetIndexStyle(
marketHighestCloseBufferIndex,
showHighestClose ?
DRAW_LINE :
DRAW_NONE,
highestCloseStyle,
1,
showHighestClose ?
highestCloseColor :
clrNONE
);
//
// Lowest High ...
string lowestHighLbl = StringConcatenate("LH(", marketLength,")");
SetIndexLabel(marketLowestHighBufferIndex, lowestHighLbl);
SetIndexBuffer(marketLowestHighBufferIndex, marketLowestHighBuffer);
SetIndexStyle(
marketLowestHighBufferIndex,
showLowestHigh ?
DRAW_LINE :
DRAW_NONE,
lowestHighStyle,
1,
showLowestHigh ?
lowestHighColor :
clrNONE
);
//
// Lowest Low ...
string lowestLowLbl = StringConcatenate("LL(", marketLength,")");
SetIndexLabel(marketLowestLowBufferIndex, lowestLowLbl);
SetIndexBuffer(marketLowestLowBufferIndex, marketLowestLowBuffer);
SetIndexStyle(
marketLowestLowBufferIndex,
showLowestLow ?
DRAW_LINE :
DRAW_NONE,
lowestLowStyle,
1,
showLowestLow ?
lowestLowColor :
clrNONE
);
//
// Lowest Open ...
string lowestOpenLbl = StringConcatenate("LO(", marketLength,")");
SetIndexLabel(marketLowestOpenBufferIndex, lowestOpenLbl);
SetIndexBuffer(marketLowestOpenBufferIndex, marketLowestOpenBuffer);
SetIndexStyle(
marketLowestOpenBufferIndex,
showLowestOpen ?
DRAW_LINE :
DRAW_NONE,
lowestOpenStyle,
1,
showLowestOpen ?
lowestOpenColor :
clrNONE
);
//
// Lowest Close ...
string lowestCloseLbl = StringConcatenate("LC(", marketLength,")");
SetIndexLabel(marketLowestCloseBufferIndex, lowestCloseLbl);
SetIndexBuffer(marketLowestCloseBufferIndex, marketLowestCloseBuffer);
SetIndexStyle(
marketLowestCloseBufferIndex,
showLowestClose ?
DRAW_LINE :
DRAW_NONE,
lowestCloseStyle,
1,
showLowestClose ?
lowestCloseColor :
clrNONE
);
//
// initialization done ...
return(INIT_SUCCEEDED);
}
//
// DeInitialization ...
void OnDeinit(const int reason) {
//
RemoveDraws(logTag);
}
//
// Do Calculation ...
int OnCalculate(
const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[]
) {
//
// this counts Available Bars ...
int limit;
//
// because in some cases we may have more than one input for
// calculation and we must prevent any calculation
// untill we pass the biggest input length, here we get max Input length
// and then wait until pass it ...
int maxLength = MathMax(marketLength, 3);
//
// input variable, we return 0 means nothing passed ...
if (rates_total < maxLength) {
return 0;
}
//
// found which candles calculated before ...
limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1;
//
// this is the main loop of calculations, for each bar index ...
for (int i = limit - 1; i >= 0; i--) {
//
// Start Calculation here ...
// i is bar_index ...
//
// Calculate Short Cycle ...
CalculateBuffers(i);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Calculate Short Cycle ...
void CalculateBuffers(
const int bar_index
) {
//
// Highest High ...
double highestHighValue = GetMarketHighestHigh(
bar_index,
marketLength
);
marketHighestHighBuffer[bar_index] = highestHighValue;
//
// Highest Low ...
double highestLowValue = GetMarketHighestLow(
bar_index,
marketLength
);
marketHighestLowBuffer[bar_index] = highestLowValue;
//
// Highest Open ...
double highestOpenValue = GetMarketHighestOpen(
bar_index,
marketLength
);
marketHighestOpenBuffer[bar_index] = highestOpenValue;
//
// Highest Close ...
double highestCloseValue = GetMarketHighestClose(
bar_index,
marketLength
);
marketHighestCloseBuffer[bar_index] = highestCloseValue;
//
// Lowest High ...
double lowestHighValue = GetMarketLowestHigh(
bar_index,
marketLength
);
marketLowestHighBuffer[bar_index] = lowestHighValue;
//
// Lowest Low ...
double lowestLowValue = GetMarketLowestLow(
bar_index,
marketLength
);
marketLowestLowBuffer[bar_index] = lowestLowValue;
//
// Lowest Open ...
double lowestOpenValue = GetMarketLowestOpen(
bar_index,
marketLength
);
marketLowestOpenBuffer[bar_index] = lowestOpenValue;
//
// Lowest Close ...
double lowestCloseValue = GetMarketLowestClose(
bar_index,
marketLength
);
marketLowestCloseBuffer[bar_index] = lowestCloseValue;
}
//
// END Functions ...
//
@@ -0,0 +1,476 @@
/////////////////////////////////////////////////////////////////
//
// SaherElm IT Center ZigZag Indicator
// -------------------------------------------------------------
// this indicator provides signals for Main strategy ...
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
////////////////////////////////////////////////////////////////
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm ZigZag Indicator"
#property strict
//
// START Inputs ...
//
input int depth = 12; // Depth
input int deviation = 5; // Deviation
input int backStep = 3; // BackStep
//
// END Inputs ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
// Includes our shared library ...
#include "../Libraries/x-saherelm.lib.mq4"
//
#property indicator_chart_window
//
#property indicator_buffers 1
//
#property indicator_width1 1
#property indicator_color1 clrAqua
// #property indicator_type1 DRAW_SECTION
// #property indicator_style1 STYLE_SOLID
// //
// #property indicator_width2 1
// #property indicator_color2 clrNONE
// #property indicator_type2 DRAW_NONE
// #property indicator_style2 STYLE_SOLID
// //
// #property indicator_width3 1
// #property indicator_color3 clrNONE
// #property indicator_type3 DRAW_NONE
// #property indicator_style3 STYLE_SOLID
//
// Buffers ...
//
#define zigzagBufferIndex 0
#define highBufferIndex 1
#define lowBufferIndex 2
// #define ziggyBufferIndex 3
//
double zigzagBuffer[];
double highBuffer[];
double lowBuffer[];
// double ziggyBuffer[];
//
// recounting's depth of extremums ...
int level=3;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// Start Event Handlers ...
//
//
// Initialization ...
int OnInit() {
//
// Initialize what we want ...
//
// Validating Input Parameters ...
if (
depth <= 0 ||
backStep < 0 ||
deviation < 0 ||
backStep >= depth
) {
return INIT_PARAMETERS_INCORRECT;
}
//
// Set Index Buffers of ZigZag ...
IndicatorBuffers(3);
//
// ZigZag Buffer ...
SetIndexBuffer(zigzagBufferIndex, zigzagBuffer);
SetIndexStyle(zigzagBufferIndex, DRAW_SECTION);
SetIndexLabel(zigzagBufferIndex, "ZigZag");
//
// High Buffer ...
SetIndexBuffer(highBufferIndex, highBuffer);
SetIndexLabel(highBufferIndex, "");
//
// Low Buffer ...
SetIndexBuffer(lowBufferIndex, lowBuffer);
SetIndexLabel(lowBufferIndex, "");
//
// Ziggy Buffer ...
// SetIndexBuffer(ziggyBufferIndex, ziggyBuffer);
// SetIndexLabel(ziggyBufferIndex, "");
//
// here we specify logging enabled or not ...
enableLogging = true;
//
// this is a Tag which attached to our Logger ...
logTag = "XS_ZG";
//
return(INIT_SUCCEEDED);
}
//
// Do Calculation ...
int OnCalculate(
const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[]
) {
//
// this counts Available Bars ...
int limit;
//
int maxLength = MathMax(depth, backStep);
int i;
int counterZ;
int back;
int pos;
//
int lastlowpos = 0;
int lasthighpos = 0;
int whatlookfor = 0;
//
double extremum;
//
double curlow = 0.0;
double curhigh = 0.0;
double lasthigh = 0.0;
double lastlow = 0.0;
//
// input variable, we return 0 means nothing passed ...
if (rates_total < maxLength) {
return 0;
}
//
// first calculations ...
if (prev_calculated == 0) {
limit = InitializeBuffers();
} else {
//
// find first extremum in the depth ExtLevel or 100 last bars ...
i = counterZ = 0;
while(counterZ < level && i < 100) {
//
if(zigzagBuffer[i] != 0.0) {
counterZ++;
}
//
i++;
}
//
// no extremum found - recounting all from begin ...
if(counterZ == 0) {
limit = InitializeBuffers();
} else {
//
// set start position to found extremum position ...
limit = i-1;
//
//--- what kind of extremum?
if(lowBuffer[i] != 0.0) {
//
// low extremum ...
curlow = lowBuffer[i];
//
// will look for the next high extremum ...
whatlookfor=1;
} else {
//
// high extremum ...
curhigh = highBuffer[i];
//
// will look for the next low extremum ...
whatlookfor=-1;
}
//
// clear the rest data ...
for(i = limit - 1; i >= 0; i--) {
//
lowBuffer[i]=0.0;
highBuffer[i]=0.0;
zigzagBuffer[i]=0.0;
}
}
}
//
// Main Calculation Loop ...
for (i = limit; i >= 0; i--) {
//
// find lowest low in depth of bars ...
extremum = low[
iLowest(
_Symbol,
_Period,
MODE_LOW,
depth,
i
)
];
//
// this lowest has been found previously ...
if (extremum == lastlow) {
extremum = 0.0;
} else {
//
// new last low ...
lastlow=extremum;
//
// discard extremum if current low is too high ...
if(low[i] - extremum > deviation * _Point) {
extremum=0.0;
} else {
//
// clear previous extremums in backstep bars ...
for(back = 1; back <= backStep; back++) {
//
pos = i + back;
//
if(lowBuffer[pos] != 0 && lowBuffer[pos] > extremum) {
lowBuffer[pos] = 0.0;
}
}
}
}
//
// found extremum is current low ...
if (low[i] == extremum) {
lowBuffer[i] = extremum;
} else {
lowBuffer[i] = 0.0;
}
//
// find highest high in depth of bars ...
extremum = high[
iHighest(
_Symbol,
_Period,
MODE_HIGH,
depth,
i
)
];
//
// this highest has been found previously ...
if (extremum == lasthigh) {
extremum = 0.0;
} else {
//
// new last high ...
lasthigh=extremum;
//
// discard extremum if current high is too low ...
if (extremum - high[i] > deviation * Point) {
extremum = 0.0;
} else {
//
// clear previous extremums in backstep bars ...
for(back = 1; back <= backStep; back++) {
//
pos = i + back;
//
if (highBuffer[pos] != 0 && highBuffer[pos] < extremum) {
highBuffer[pos] = 0.0;
}
}
}
}
//
// found extremum is current high ...
if (high[i] == extremum) {
highBuffer[i] = extremum;
} else {
highBuffer[i] = 0.0;
}
}
//
// final cutting ...
if( whatlookfor == 0) {
//
lastlow = 0.0;
lasthigh = 0.0;
} else {
//
lastlow = curlow;
lasthigh = curhigh;
}
//
for(i = limit; i >= 0; i--) {
switch(whatlookfor) {
//
// look for peak or lawn ...
case 0:
//
if (lastlow == 0.0 && lasthigh == 0.0) {
if(highBuffer[i]!=0.0) {
//
lasthigh = High[i];
lasthighpos = i;
whatlookfor = -1;
//
zigzagBuffer[i] = lasthigh;
}
//
if(lowBuffer[i] != 0.0) {
//
lastlow = Low[i];
lastlowpos = i;
whatlookfor = 1;
//
zigzagBuffer[i] = lastlow;
}
}
break;
//
// look for peak ...
case 1:
//
if (
lowBuffer[i] != 0.0 &&
lowBuffer[i] < lastlow &&
highBuffer[i] == 0.0
) {
//
zigzagBuffer[lastlowpos] = 0.0;
lastlowpos = i;
lastlow = lowBuffer[i];
zigzagBuffer[i] = lastlow;
}
//
if(highBuffer[i] != 0.0 && lowBuffer[i] == 0.0) {
//
lasthigh = highBuffer[i];
lasthighpos = i;
zigzagBuffer[i] = lasthigh;
//
whatlookfor=-1;
}
break;
//
// look for lawn ...
case -1:
//
if(
highBuffer[i] != 0.0 &&
highBuffer[i] > lasthigh &&
lowBuffer[i] == 0.0
) {
//
zigzagBuffer[lasthighpos] = 0.0;
lasthighpos = i;
lasthigh = highBuffer[i];
zigzagBuffer[i] = lasthigh;
}
//
if(
lowBuffer[i] !=0.0 &&
highBuffer[i] == 0.0
) {
//
lastlow = lowBuffer[i];
lastlowpos = i;
zigzagBuffer[i] = lastlow;
whatlookfor=1;
}
break;
}
}
//
// Done ...
return rates_total;
}
//
// De Initialization ...
void OnDeinit(const int reason) {
//
// RemoveDraws(signalPrefix);
ChartRedraw(0);
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
int InitializeBuffers() {
//
ArrayInitialize(lowBuffer,0.0);
ArrayInitialize(highBuffer, 0.0);
ArrayInitialize(zigzagBuffer, 0.0);
//
//--- first counting position
return(Bars - depth);
}
//
// END Functions ...
//