Backup works ...
This commit is contained in:
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,288 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| ZigzagColor.mq5 |
|
||||
//| Copyright 2000-2025, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
//--- indicator settings
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 5
|
||||
#property indicator_plots 1
|
||||
#property indicator_type1 DRAW_COLOR_ZIGZAG
|
||||
#property indicator_width1 3
|
||||
#property indicator_color1 clrAqua, clrMagenta
|
||||
//--- input parameters
|
||||
input int InpDepth =12; // Depth
|
||||
input int InpDeviation=5; // Deviation
|
||||
input int InpBackstep =3; // Back Step
|
||||
//--- indicator buffers
|
||||
double ZigzagPeakBuffer[];
|
||||
double ZigzagBottomBuffer[];
|
||||
double HighMapBuffer[];
|
||||
double LowMapBuffer[];
|
||||
double ColorBuffer[];
|
||||
|
||||
int ExtRecalc=3; // recounting's depth
|
||||
|
||||
enum EnSearchMode
|
||||
{
|
||||
Extremum=0, // searching for the first extremum
|
||||
Peak=1, // searching for the next ZigZag peak
|
||||
Bottom=-1 // searching for the next ZigZag bottom
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ZigzagPeakBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ZigzagBottomBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(2,ColorBuffer,INDICATOR_COLOR_INDEX);
|
||||
SetIndexBuffer(3,HighMapBuffer,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(4,LowMapBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- set accuracy
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
//--- name for DataWindow and indicator subwindow label
|
||||
string short_name=StringFormat("ZigZagColor(%d,%d,%d)",InpDepth,InpDeviation,InpBackstep);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
PlotIndexSetString(0,PLOT_LABEL,short_name);
|
||||
//--- set an empty value
|
||||
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| ZigZag 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[])
|
||||
{
|
||||
if(rates_total<100)
|
||||
return(0);
|
||||
//---
|
||||
int i,start=0;
|
||||
int extreme_counter=0,extreme_search=Extremum;
|
||||
int shift,back=0,last_high_pos=0,last_low_pos=0;
|
||||
double val=0,res=0;
|
||||
double cur_low=0,cur_high=0,last_high=0,last_low=0;
|
||||
//--- initializing
|
||||
if(prev_calculated==0)
|
||||
{
|
||||
ArrayInitialize(ZigzagPeakBuffer,0.0);
|
||||
ArrayInitialize(ZigzagBottomBuffer,0.0);
|
||||
ArrayInitialize(HighMapBuffer,0.0);
|
||||
ArrayInitialize(LowMapBuffer,0.0);
|
||||
//--- start calculation from bar number InpDepth
|
||||
start=InpDepth-1;
|
||||
}
|
||||
//--- ZigZag was already calculated before
|
||||
if(prev_calculated>0)
|
||||
{
|
||||
i=rates_total-1;
|
||||
//--- searching for the third extremum from the last uncompleted bar
|
||||
while(extreme_counter<ExtRecalc && i>rates_total -100)
|
||||
{
|
||||
res=(ZigzagPeakBuffer[i]+ZigzagBottomBuffer[i]);
|
||||
//---
|
||||
if(res!=0)
|
||||
extreme_counter++;
|
||||
i--;
|
||||
}
|
||||
i++;
|
||||
start=i;
|
||||
//--- what type of exremum we search for
|
||||
if(LowMapBuffer[i]!=0)
|
||||
{
|
||||
cur_low=LowMapBuffer[i];
|
||||
extreme_search=Peak;
|
||||
}
|
||||
else
|
||||
{
|
||||
cur_high=HighMapBuffer[i];
|
||||
extreme_search=Bottom;
|
||||
}
|
||||
//--- clear indicator values
|
||||
for(i=start+1; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
ZigzagPeakBuffer[i] =0.0;
|
||||
ZigzagBottomBuffer[i]=0.0;
|
||||
LowMapBuffer[i] =0.0;
|
||||
HighMapBuffer[i] =0.0;
|
||||
}
|
||||
}
|
||||
//--- searching for high and low extremes
|
||||
for(shift=start; shift<rates_total && !IsStopped(); shift++)
|
||||
{
|
||||
//--- low
|
||||
val=Lowest(low,InpDepth,shift);
|
||||
if(val==last_low)
|
||||
val=0.0;
|
||||
else
|
||||
{
|
||||
last_low=val;
|
||||
if((low[shift]-val)>(InpDeviation*_Point))
|
||||
val=0.0;
|
||||
else
|
||||
{
|
||||
for(back=InpBackstep; back>=1; back--)
|
||||
{
|
||||
res=LowMapBuffer[shift-back];
|
||||
//---
|
||||
if((res!=0) && (res>val))
|
||||
LowMapBuffer[shift-back]=0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(low[shift]==val)
|
||||
LowMapBuffer[shift]=val;
|
||||
else
|
||||
LowMapBuffer[shift]=0.0;
|
||||
//--- high
|
||||
val=Highest(high,InpDepth,shift);
|
||||
if(val==last_high)
|
||||
val=0.0;
|
||||
else
|
||||
{
|
||||
last_high=val;
|
||||
if((val-high[shift])>(InpDeviation*_Point))
|
||||
val=0.0;
|
||||
else
|
||||
{
|
||||
for(back=InpBackstep; back>=1; back--)
|
||||
{
|
||||
res=HighMapBuffer[shift-back];
|
||||
//---
|
||||
if((res!=0) && (res<val))
|
||||
HighMapBuffer[shift-back]=0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(high[shift]==val)
|
||||
HighMapBuffer[shift]=val;
|
||||
else
|
||||
HighMapBuffer[shift]=0.0;
|
||||
}
|
||||
//--- set last values
|
||||
if(extreme_search==0) // undefined values
|
||||
{
|
||||
last_low=0;
|
||||
last_high=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
last_low=cur_low;
|
||||
last_high=cur_high;
|
||||
}
|
||||
//--- final selection of extreme points for ZigZag
|
||||
for(shift=start; shift<rates_total && !IsStopped(); shift++)
|
||||
{
|
||||
res=0.0;
|
||||
switch(extreme_search)
|
||||
{
|
||||
case Extremum:
|
||||
if(last_low==0 && last_high==0)
|
||||
{
|
||||
if(HighMapBuffer[shift]!=0)
|
||||
{
|
||||
last_high=high[shift];
|
||||
last_high_pos=shift;
|
||||
extreme_search=-1;
|
||||
ZigzagPeakBuffer[shift]=last_high;
|
||||
ColorBuffer[shift]=0;
|
||||
res=1;
|
||||
}
|
||||
if(LowMapBuffer[shift]!=0)
|
||||
{
|
||||
last_low=low[shift];
|
||||
last_low_pos=shift;
|
||||
extreme_search=1;
|
||||
ZigzagBottomBuffer[shift]=last_low;
|
||||
ColorBuffer[shift]=1;
|
||||
res=1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Peak:
|
||||
if(LowMapBuffer[shift]!=0.0 && LowMapBuffer[shift]<last_low &&
|
||||
HighMapBuffer[shift]==0.0)
|
||||
{
|
||||
ZigzagBottomBuffer[last_low_pos]=0.0;
|
||||
last_low_pos=shift;
|
||||
last_low=LowMapBuffer[shift];
|
||||
ZigzagBottomBuffer[shift]=last_low;
|
||||
ColorBuffer[shift]=1;
|
||||
res=1;
|
||||
}
|
||||
if(HighMapBuffer[shift]!=0.0 && LowMapBuffer[shift]==0.0)
|
||||
{
|
||||
last_high=HighMapBuffer[shift];
|
||||
last_high_pos=shift;
|
||||
ZigzagPeakBuffer[shift]=last_high;
|
||||
ColorBuffer[shift]=0;
|
||||
extreme_search=Bottom;
|
||||
res=1;
|
||||
}
|
||||
break;
|
||||
case Bottom:
|
||||
if(HighMapBuffer[shift]!=0.0 &&
|
||||
HighMapBuffer[shift]>last_high &&
|
||||
LowMapBuffer[shift]==0.0)
|
||||
{
|
||||
ZigzagPeakBuffer[last_high_pos]=0.0;
|
||||
last_high_pos=shift;
|
||||
last_high=HighMapBuffer[shift];
|
||||
ZigzagPeakBuffer[shift]=last_high;
|
||||
ColorBuffer[shift]=0;
|
||||
}
|
||||
if(LowMapBuffer[shift]!=0.0 && HighMapBuffer[shift]==0.0)
|
||||
{
|
||||
last_low=LowMapBuffer[shift];
|
||||
last_low_pos=shift;
|
||||
ZigzagBottomBuffer[shift]=last_low;
|
||||
ColorBuffer[shift]=1;
|
||||
extreme_search=Peak;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return(rates_total);
|
||||
}
|
||||
}
|
||||
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Get highest value for range |
|
||||
//+------------------------------------------------------------------+
|
||||
double Highest(const double&array[],int count,int start)
|
||||
{
|
||||
double res=array[start];
|
||||
//---
|
||||
for(int i=start-1; i>start-count && i>=0; i--)
|
||||
if(res<array[i])
|
||||
res=array[i];
|
||||
//---
|
||||
return(res);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Get lowest value for range |
|
||||
//+------------------------------------------------------------------+
|
||||
double Lowest(const double&array[],int count,int start)
|
||||
{
|
||||
double res=array[start];
|
||||
//---
|
||||
for(int i=start-1; i>start-count && i>=0; i--)
|
||||
if(res>array[i])
|
||||
res=array[i];
|
||||
//---
|
||||
return(res);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,383 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| ZigZag Analyzer.mq5|
|
||||
//| Copyright 2025, MetaQuotes Ltd.|
|
||||
//| https://www.mql5.com/en/users/lynnchris|
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2025, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com/en/users/lynnchris"
|
||||
#property version "1.0"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
// Input parameters
|
||||
input ENUM_TIMEFRAMES InpTimeFrame = PERIOD_CURRENT; // Timeframe to analyze
|
||||
input int ZZ_Depth = 12; // ZigZag depth
|
||||
input int ZZ_Deviation = 5; // ZigZag deviation
|
||||
input int ZZ_Backstep = 3; // ZigZag backstep
|
||||
input int LookBackBars = 500; // Bars to search for pivots
|
||||
input int ExtendFutureBars = 100; // Bars to extend trendlines into the future
|
||||
|
||||
// Global indicator handle for ZigZag
|
||||
int zzHandle;
|
||||
|
||||
// Arrays for ZigZag data and pivot storage
|
||||
double zzBuffer[];
|
||||
bool pivotIsPeak[];
|
||||
double pivotPrices[];
|
||||
datetime pivotTimes[];
|
||||
|
||||
// Variable to detect new bars
|
||||
datetime lastBarTime = 0;
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
zzHandle = iCustom(
|
||||
_Symbol,
|
||||
InpTimeFrame,
|
||||
"x-saherelm.xzg",
|
||||
"",
|
||||
ZZ_Depth,
|
||||
ZZ_Deviation,
|
||||
ZZ_Backstep,
|
||||
X_PRICE_HIGH,
|
||||
X_PRICE_LOW,
|
||||
"",
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
159,
|
||||
159 //
|
||||
);
|
||||
if (zzHandle == INVALID_HANDLE)
|
||||
{
|
||||
Print("Error creating ZigZag handle");
|
||||
return (INIT_FAILED);
|
||||
}
|
||||
return (INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Deinitialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
ObjectDelete(0, "Downtrend_HighLine");
|
||||
ObjectDelete(0, "Downtrend_LowLine");
|
||||
ObjectDelete(0, "Major_Resistance");
|
||||
ObjectDelete(0, "Major_Support");
|
||||
ObjectDelete(0, "Minor_Resistance");
|
||||
ObjectDelete(0, "Minor_Support");
|
||||
IndicatorRelease(zzHandle);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Tick function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnTick()
|
||||
{
|
||||
datetime currentBarTime = iTime(_Symbol, InpTimeFrame, 0);
|
||||
if (currentBarTime == lastBarTime)
|
||||
return;
|
||||
lastBarTime = currentBarTime;
|
||||
|
||||
// Remove previous objects
|
||||
ObjectDelete(0, "Downtrend_HighLine");
|
||||
ObjectDelete(0, "Downtrend_LowLine");
|
||||
ObjectDelete(0, "Major_Resistance");
|
||||
ObjectDelete(0, "Major_Support");
|
||||
ObjectDelete(0, "Minor_Resistance");
|
||||
ObjectDelete(0, "Minor_Support");
|
||||
|
||||
if (CopyBuffer(zzHandle, 0, 0, LookBackBars, zzBuffer) <= 0)
|
||||
{
|
||||
Print("Failed to copy ZigZag data");
|
||||
return;
|
||||
}
|
||||
ArraySetAsSeries(zzBuffer, true);
|
||||
|
||||
DrawZigZagTrendlines();
|
||||
DrawSupportResistance();
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Draw ZigZag-based Trendlines |
|
||||
//+------------------------------------------------------------------+
|
||||
void DrawZigZagTrendlines()
|
||||
{
|
||||
double highPrices[10], lowPrices[10];
|
||||
datetime highTimes[10], lowTimes[10];
|
||||
int highCount = 0, lowCount = 0;
|
||||
|
||||
// Extract swing points from the ZigZag buffer
|
||||
for (int i = 0; i < LookBackBars - 1; i++)
|
||||
{
|
||||
if (zzBuffer[i] != 0)
|
||||
{
|
||||
if (iHigh(_Symbol, InpTimeFrame, i) == zzBuffer[i] && highCount < 10)
|
||||
{
|
||||
highPrices[highCount] = zzBuffer[i];
|
||||
highTimes[highCount] = iTime(_Symbol, InpTimeFrame, i);
|
||||
highCount++;
|
||||
}
|
||||
else if (iLow(_Symbol, InpTimeFrame, i) == zzBuffer[i] && lowCount < 10)
|
||||
{
|
||||
lowPrices[lowCount] = zzBuffer[i];
|
||||
lowTimes[lowCount] = iTime(_Symbol, InpTimeFrame, i);
|
||||
lowCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Exclude the most recent swing if possible
|
||||
int usedHighCount = (highCount >= 4) ? highCount - 1 : highCount;
|
||||
int usedLowCount = (lowCount >= 4) ? lowCount - 1 : lowCount;
|
||||
|
||||
double mHigh = 0, bHigh = 0, mLow = 0, bLow = 0;
|
||||
bool validHigh = false, validLow = false;
|
||||
|
||||
// Regression for highs
|
||||
if (usedHighCount >= 3)
|
||||
{
|
||||
double sumT = 0, sumP = 0, sumTP = 0, sumT2 = 0;
|
||||
for (int i = 0; i < usedHighCount; i++)
|
||||
{
|
||||
double t = (double)highTimes[i];
|
||||
double p = highPrices[i];
|
||||
sumT += t;
|
||||
sumP += p;
|
||||
sumTP += t * p;
|
||||
sumT2 += t * t;
|
||||
}
|
||||
int N = usedHighCount;
|
||||
double denominator = N * sumT2 - sumT * sumT;
|
||||
if (denominator != 0)
|
||||
{
|
||||
mHigh = (N * sumTP - sumT * sumP) / denominator;
|
||||
bHigh = (sumP - mHigh * sumT) / N;
|
||||
}
|
||||
else
|
||||
bHigh = sumP / N;
|
||||
validHigh = true;
|
||||
}
|
||||
|
||||
// Regression for lows
|
||||
if (usedLowCount >= 3)
|
||||
{
|
||||
double sumT = 0, sumP = 0, sumTP = 0, sumT2 = 0;
|
||||
for (int i = 0; i < usedLowCount; i++)
|
||||
{
|
||||
double t = (double)lowTimes[i];
|
||||
double p = lowPrices[i];
|
||||
sumT += t;
|
||||
sumP += p;
|
||||
sumTP += t * p;
|
||||
sumT2 += t * t;
|
||||
}
|
||||
int N = usedLowCount;
|
||||
double denominator = N * sumT2 - sumT * sumT;
|
||||
if (denominator != 0)
|
||||
{
|
||||
mLow = (N * sumTP - sumT * sumP) / denominator;
|
||||
bLow = (sumP - mLow * sumT) / N;
|
||||
}
|
||||
else
|
||||
bLow = sumP / N;
|
||||
validLow = true;
|
||||
}
|
||||
|
||||
// Define time limits for trendlines
|
||||
datetime pastTime = iTime(_Symbol, InpTimeFrame, LookBackBars - 1);
|
||||
datetime futureTime = lastBarTime + ExtendFutureBars * PeriodSeconds();
|
||||
|
||||
// Draw trendlines if both regressions are valid
|
||||
if (validHigh && validLow)
|
||||
{
|
||||
// When slopes have the same sign, use average slope
|
||||
if (mHigh * mLow > 0)
|
||||
{
|
||||
double mParallel = (mHigh + mLow) / 2.0;
|
||||
double bHighParallel = highPrices[0] - mParallel * (double)highTimes[0];
|
||||
double bLowParallel = lowPrices[0] - mParallel * (double)lowTimes[0];
|
||||
|
||||
datetime highStartTime = pastTime;
|
||||
double highStartPrice = mParallel * (double)highStartTime + bHighParallel;
|
||||
double highEndPrice = mParallel * (double)futureTime + bHighParallel;
|
||||
if (!ObjectCreate(0, "Downtrend_HighLine", OBJ_TREND, 0, highStartTime, highStartPrice, futureTime, highEndPrice))
|
||||
Print("Failed to create High Trendline");
|
||||
else
|
||||
{
|
||||
ObjectSetInteger(0, "Downtrend_HighLine", OBJPROP_COLOR, clrRed);
|
||||
ObjectSetInteger(0, "Downtrend_HighLine", OBJPROP_RAY_LEFT, true);
|
||||
ObjectSetInteger(0, "Downtrend_HighLine", OBJPROP_RAY_RIGHT, true);
|
||||
}
|
||||
|
||||
datetime lowStartTime = pastTime;
|
||||
double lowStartPrice = mParallel * (double)lowStartTime + bLowParallel;
|
||||
double lowEndPrice = mParallel * (double)futureTime + bLowParallel;
|
||||
if (!ObjectCreate(0, "Downtrend_LowLine", OBJ_TREND, 0, lowStartTime, lowStartPrice, futureTime, lowEndPrice))
|
||||
Print("Failed to create Low Trendline");
|
||||
else
|
||||
{
|
||||
ObjectSetInteger(0, "Downtrend_LowLine", OBJPROP_COLOR, clrGreen);
|
||||
ObjectSetInteger(0, "Downtrend_LowLine", OBJPROP_RAY_LEFT, true);
|
||||
ObjectSetInteger(0, "Downtrend_LowLine", OBJPROP_RAY_RIGHT, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
datetime highStartTime = pastTime;
|
||||
double highStartPrice = mHigh * (double)highStartTime + bHigh;
|
||||
double highEndPrice = mHigh * (double)futureTime + bHigh;
|
||||
if (!ObjectCreate(0, "Downtrend_HighLine", OBJ_TREND, 0, highStartTime, highStartPrice, futureTime, highEndPrice))
|
||||
Print("Failed to create High Trendline");
|
||||
else
|
||||
{
|
||||
ObjectSetInteger(0, "Downtrend_HighLine", OBJPROP_COLOR, clrRed);
|
||||
ObjectSetInteger(0, "Downtrend_HighLine", OBJPROP_RAY_LEFT, true);
|
||||
ObjectSetInteger(0, "Downtrend_HighLine", OBJPROP_RAY_RIGHT, true);
|
||||
}
|
||||
|
||||
datetime lowStartTime = pastTime;
|
||||
double lowStartPrice = mLow * (double)lowStartTime + bLow;
|
||||
double lowEndPrice = mLow * (double)futureTime + bLow;
|
||||
if (!ObjectCreate(0, "Downtrend_LowLine", OBJ_TREND, 0, lowStartTime, lowStartPrice, futureTime, lowEndPrice))
|
||||
Print("Failed to create Low Trendline");
|
||||
else
|
||||
{
|
||||
ObjectSetInteger(0, "Downtrend_LowLine", OBJPROP_COLOR, clrGreen);
|
||||
ObjectSetInteger(0, "Downtrend_LowLine", OBJPROP_RAY_LEFT, true);
|
||||
ObjectSetInteger(0, "Downtrend_LowLine", OBJPROP_RAY_RIGHT, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (validHigh)
|
||||
{
|
||||
datetime highStartTime = pastTime;
|
||||
double highStartPrice = mHigh * (double)highStartTime + bHigh;
|
||||
double highEndPrice = mHigh * (double)futureTime + bHigh;
|
||||
if (!ObjectCreate(0, "Downtrend_HighLine", OBJ_TREND, 0, highStartTime, highStartPrice, futureTime, highEndPrice))
|
||||
Print("Failed to create High Trendline");
|
||||
else
|
||||
{
|
||||
ObjectSetInteger(0, "Downtrend_HighLine", OBJPROP_COLOR, clrRed);
|
||||
ObjectSetInteger(0, "Downtrend_HighLine", OBJPROP_RAY_LEFT, true);
|
||||
ObjectSetInteger(0, "Downtrend_HighLine", OBJPROP_RAY_RIGHT, true);
|
||||
}
|
||||
}
|
||||
if (validLow)
|
||||
{
|
||||
datetime lowStartTime = pastTime;
|
||||
double lowStartPrice = mLow * (double)lowStartTime + bLow;
|
||||
double lowEndPrice = mLow * (double)futureTime + bLow;
|
||||
if (!ObjectCreate(0, "Downtrend_LowLine", OBJ_TREND, 0, lowStartTime, lowStartPrice, futureTime, lowEndPrice))
|
||||
Print("Failed to create Low Trendline");
|
||||
else
|
||||
{
|
||||
ObjectSetInteger(0, "Downtrend_LowLine", OBJPROP_COLOR, clrGreen);
|
||||
ObjectSetInteger(0, "Downtrend_LowLine", OBJPROP_RAY_LEFT, true);
|
||||
ObjectSetInteger(0, "Downtrend_LowLine", OBJPROP_RAY_RIGHT, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Draw Support and Resistance Levels |
|
||||
//+------------------------------------------------------------------+
|
||||
void DrawSupportResistance()
|
||||
{
|
||||
double confirmedHighs[10], confirmedLows[10];
|
||||
int confHighCount = 0, confLowCount = 0;
|
||||
|
||||
for (int i = 0; i < LookBackBars - 1; i++)
|
||||
{
|
||||
if (zzBuffer[i] != 0)
|
||||
{
|
||||
if (iHigh(_Symbol, InpTimeFrame, i) == zzBuffer[i] && confHighCount < 10)
|
||||
{
|
||||
confirmedHighs[confHighCount] = zzBuffer[i];
|
||||
confHighCount++;
|
||||
}
|
||||
else if (iLow(_Symbol, InpTimeFrame, i) == zzBuffer[i] && confLowCount < 10)
|
||||
{
|
||||
confirmedLows[confLowCount] = zzBuffer[i];
|
||||
confLowCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int usedHighCount = (confHighCount >= 4) ? confHighCount - 1 : confHighCount;
|
||||
int usedLowCount = (confLowCount >= 4) ? confLowCount - 1 : confLowCount;
|
||||
|
||||
double majorResistance = -1e9, majorSupport = 1e9;
|
||||
double minorResistance = -1e9, minorSupport = 1e9;
|
||||
double tempHigh = -1e9, tempLow = -1e9;
|
||||
for (int i = 0; i < usedHighCount; i++)
|
||||
{
|
||||
if (confirmedHighs[i] > majorResistance)
|
||||
{
|
||||
tempHigh = majorResistance;
|
||||
majorResistance = confirmedHighs[i];
|
||||
}
|
||||
else if (confirmedHighs[i] > tempHigh)
|
||||
{
|
||||
tempHigh = confirmedHighs[i];
|
||||
}
|
||||
}
|
||||
if (tempHigh > -1e9)
|
||||
minorResistance = tempHigh;
|
||||
for (int i = 0; i < usedLowCount; i++)
|
||||
{
|
||||
if (confirmedLows[i] < majorSupport)
|
||||
{
|
||||
tempLow = majorSupport;
|
||||
majorSupport = confirmedLows[i];
|
||||
}
|
||||
else if (confirmedLows[i] < tempLow)
|
||||
{
|
||||
tempLow = confirmedLows[i];
|
||||
}
|
||||
}
|
||||
if (tempLow < 1e9)
|
||||
minorSupport = tempLow;
|
||||
|
||||
if (usedHighCount > 0)
|
||||
{
|
||||
if (!ObjectCreate(0, "Major_Resistance", OBJ_HLINE, 0, 0, majorResistance))
|
||||
Print("Failed to create Major Resistance");
|
||||
else
|
||||
ObjectSetInteger(0, "Major_Resistance", OBJPROP_COLOR, clrMagenta);
|
||||
|
||||
if (minorResistance > -1e9 && minorResistance < majorResistance)
|
||||
{
|
||||
if (!ObjectCreate(0, "Minor_Resistance", OBJ_HLINE, 0, 0, minorResistance))
|
||||
Print("Failed to create Minor Resistance");
|
||||
else
|
||||
ObjectSetInteger(0, "Minor_Resistance", OBJPROP_COLOR, clrFuchsia);
|
||||
}
|
||||
}
|
||||
if (usedLowCount > 0)
|
||||
{
|
||||
if (!ObjectCreate(0, "Major_Support", OBJ_HLINE, 0, 0, majorSupport))
|
||||
Print("Failed to create Major Support");
|
||||
else
|
||||
ObjectSetInteger(0, "Major_Support", OBJPROP_COLOR, clrAqua);
|
||||
|
||||
if (minorSupport < 1e9 && minorSupport > majorSupport)
|
||||
{
|
||||
if (!ObjectCreate(0, "Minor_Support", OBJ_HLINE, 0, 0, minorSupport))
|
||||
Print("Failed to create Minor Support");
|
||||
else
|
||||
ObjectSetInteger(0, "Minor_Support", OBJPROP_COLOR, clrBlue);
|
||||
}
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Reference in New Issue
Block a user