263 lines
5.2 KiB
Plaintext
263 lines
5.2 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center XZoneTest MQL5 Expert Advisor
|
|
// -------------------------------------------------
|
|
// Name: XZoneTest
|
|
// Description: an Exper Advisor which used RSI and MA
|
|
// to Analyse Market ...
|
|
//
|
|
// Maintainer:
|
|
// ------------
|
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
//
|
|
//////////////////////////////////////////////////////x
|
|
//
|
|
// Global Properties ...
|
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
#property link "https://saherelm.ir"
|
|
#property version "1.00"
|
|
#property description "SaherElm XZoneTest"
|
|
#property strict
|
|
|
|
//
|
|
#include "../Classes/x-saherelm.xczone.class.mq5"
|
|
|
|
//
|
|
#define ShortName "XZoneTest"
|
|
|
|
//
|
|
// Inputs ...
|
|
input int zoneRange = 21;
|
|
input ENUM_TIMEFRAMES zonePeriod = PERIOD_M1;
|
|
|
|
//
|
|
// Variables ...
|
|
int barsTotal;
|
|
|
|
//
|
|
// Initialization ...
|
|
int OnInit()
|
|
{
|
|
//
|
|
if (!InitialEA())
|
|
{
|
|
return INIT_PARAMETERS_INCORRECT;
|
|
}
|
|
|
|
//
|
|
// Init Succeed ...
|
|
return INIT_SUCCEEDED;
|
|
}
|
|
|
|
//
|
|
// DeInitialization ...
|
|
void OnDeinit(const int reason)
|
|
{
|
|
//
|
|
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
// REASON_REMOVE 1 Program removed from a chart
|
|
// REASON_RECOMPILE 2 Program recompiled
|
|
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
// REASON_CHARTCLOSE 4 Chart closed
|
|
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
// REASON_TEMPLATE 7 Another chart template applied
|
|
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
// REASON_CLOSE 9 Terminal closed
|
|
|
|
//
|
|
// De Initialize XSampleEA Providers ...
|
|
}
|
|
|
|
//
|
|
// On Tick Handler ...
|
|
void OnTick()
|
|
{
|
|
//
|
|
int bars = iBars(
|
|
_Symbol,
|
|
zonePeriod //
|
|
);
|
|
if (barsTotal == bars)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
barsTotal = bars;
|
|
|
|
//
|
|
datetime startTime = iTime(
|
|
_Symbol,
|
|
zonePeriod,
|
|
zoneRange + 1 //
|
|
);
|
|
datetime endTime = iTime(
|
|
_Symbol,
|
|
zonePeriod,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
MqlTick ticks[];
|
|
CopyTicksRange(
|
|
_Symbol,
|
|
ticks,
|
|
COPY_TICKS_ALL,
|
|
startTime * 1000,
|
|
endTime * 1000 //
|
|
);
|
|
|
|
//
|
|
double highs[];
|
|
CopyHigh(
|
|
_Symbol,
|
|
zonePeriod,
|
|
startTime,
|
|
endTime,
|
|
highs //
|
|
);
|
|
double iHigh = highs[ArrayMaximum(highs)];
|
|
|
|
//
|
|
double lows[];
|
|
CopyLow(
|
|
_Symbol,
|
|
zonePeriod,
|
|
startTime,
|
|
endTime,
|
|
lows //
|
|
);
|
|
double iLow = lows[ArrayMinimum(lows)];
|
|
|
|
//
|
|
double iSize = iHigh - iLow;
|
|
|
|
//
|
|
CArrayObj zones;
|
|
int zCount = 10;
|
|
for (int i = 0; i < zCount; i++)
|
|
{
|
|
//
|
|
double iH = iHigh - iSize * i / zCount;
|
|
double iL = iHigh - iSize * (i + 1) / zCount;
|
|
|
|
//
|
|
XSCZone *iZone = new XSCZone();
|
|
iZone.high = iH;
|
|
iZone.low = iL;
|
|
|
|
//
|
|
zones.Add(iZone);
|
|
}
|
|
|
|
//
|
|
// Fill Ticks ...
|
|
for (int i = 0; i < ArraySize(ticks); i++)
|
|
{
|
|
//
|
|
MqlTick iTick = ticks[i];
|
|
|
|
//
|
|
for (int j = 0; j < zones.Total(); j++)
|
|
{
|
|
//
|
|
XSCZone *jZone = zones.At(j);
|
|
|
|
//
|
|
bool isInRange = iTick.bid >= jZone.low && iTick.bid <= jZone.high;
|
|
if (isInRange)
|
|
{
|
|
//
|
|
jZone.ticks++;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Sorting Zones ...
|
|
zones.Sort();
|
|
|
|
//
|
|
CArrayObj mChartObjects;
|
|
for (int i = 0; i < zones.Total(); i++)
|
|
{
|
|
//
|
|
XSCZone *iZone = zones.At(i);
|
|
|
|
//
|
|
string iZoneName = "Zone " + IntegerToString(i);
|
|
|
|
//
|
|
// Create Zone Rectangle ...
|
|
CChartObjectRectangle *iRect = new CChartObjectRectangle();
|
|
iRect.Create(
|
|
0,
|
|
iZoneName,
|
|
0,
|
|
startTime,
|
|
iZone.high,
|
|
endTime,
|
|
iZone.low //
|
|
);
|
|
iRect.Fill(true);
|
|
|
|
//
|
|
// Create Zone Label ...
|
|
CChartObjectLabel *iLabel = new CChartObjectLabel();
|
|
iLabel.Create(
|
|
0,
|
|
iZoneName + "_lbl",
|
|
0,
|
|
startTime,
|
|
iZone.high //
|
|
);
|
|
iLabel.Color(clrWhite);
|
|
|
|
//
|
|
// Calculate TickPercent ...
|
|
double iZoneTickPercent = (double)iZone.ticks / ArraySize(ticks) * 100;
|
|
iZoneTickPercent = NormalizeDouble(iZoneTickPercent, 2);
|
|
string iZoneTickPercentStr = (string)iZoneTickPercent + "%";
|
|
|
|
//
|
|
iLabel.Description(iZoneTickPercentStr);
|
|
|
|
//
|
|
if (iZone.ticks > ArraySize(ticks) * 0.15)
|
|
{
|
|
iRect.Color(clrOrangeRed);
|
|
}
|
|
else if (iZone.ticks > ArraySize(ticks) * 0.10)
|
|
{
|
|
iRect.Color(clrOrange);
|
|
}
|
|
else
|
|
{
|
|
iRect.Color(clrLightGray);
|
|
}
|
|
|
|
//
|
|
// mChartObjects.Add(iRect);
|
|
// mChartObjects.Add(iLabel);
|
|
}
|
|
}
|
|
|
|
//
|
|
//
|
|
|
|
//
|
|
bool InitialEA()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = true;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
// |