Cleanup Workspace ...

This commit is contained in:
2024-11-15 10:50:11 +03:30
parent 45a0d9b5a5
commit 6557f4f1ce
1201 changed files with 15953471 additions and 0 deletions
+317
View File
@@ -0,0 +1,317 @@
//
// Select a Supply Zone which Price is Inside it ...
XZone aSupplyZone;
XZone aSupplyZoneTrigger;
bool hasSupplyZoneArroundCBar = false;
bool hasTriggerSupplyZoneArroundCBar = false;
int aSupplyZonesCount = ArraySize(_15MState.supplyZones);
int aSupplyZonesTriggerCount = ArraySize(_5MState.supplyZones);
if (!hasSupplyZoneArroundCBar ||
!hasTriggerSupplyZoneArroundCBar)
{
for (int i = 0; i < aSupplyZonesCount; i++)
{
//
XZone iZone = _15MState.supplyZones[i];
//
bool canSetZone = (!hasSupplyZoneArroundCBar &&
iZone.lower < cBar.low &&
iZone.upper > cBar.high) ||
(hasSupplyZoneArroundCBar &&
aSupplyZone.lower < cBar.low &&
aSupplyZone.upper > cBar.high &&
iZone.lower < cBar.low &&
iZone.upper > cBar.high &&
iZone.GetRange() < aSupplyZone.GetRange());
if (canSetZone &&
!hasTriggerSupplyZoneArroundCBar &&
IsValidSize(aSupplyZonesTriggerCount))
{
//
for (int j = 0; j < aSupplyZonesTriggerCount; j++)
{
//
XZone jZone = _5MState.supplyZones[j];
//
bool canSetTriggerZone = (!hasTriggerSupplyZoneArroundCBar &&
jZone.lower < cBar.low &&
jZone.upper > cBar.high) ||
(hasTriggerSupplyZoneArroundCBar &&
aSupplyZoneTrigger.lower < cBar.low &&
aSupplyZoneTrigger.upper > cBar.high &&
jZone.lower < cBar.low &&
jZone.upper > cBar.high &&
jZone.GetRange() < aSupplyZoneTrigger.GetRange());
if (canSetTriggerZone)
{
//
iZone.to = cTime;
jZone.to = cTime;
aSupplyZone = iZone;
aSupplyZoneTrigger = jZone;
hasSupplyZoneArroundCBar = true;
hasTriggerSupplyZoneArroundCBar = true;
//
break;
}
}
}
}
}
//
// XZone supplyZone;
// int supplyZonesCount = ArraySize(_5MState.supplyZones);
// bool hasSupplyZoneOverCBar = IsValidSize(supplyZonesCount);
// if (hasSupplyZoneOverCBar)
// {
// //
// hasSupplyZoneOverCBar = false;
// for (int i = 0; i < supplyZonesCount; i++)
// {
// //
// XZone iZone = _5MState.supplyZones[i];
// //
// if (!hasSupplyZoneOverCBar &&
// iZone.lower > cBar.high)
// {
// //
// iZone.to = cTime;
// supplyZone = iZone;
// hasSupplyZoneOverCBar = true;
// // //
// // break;
// }
// }
// }
//
XZone demandZone;
int demandZonesCount = ArraySize(_5MState.demandZones);
bool hasDemandZoneUnderCBar = IsValidSize(demandZonesCount);
if (hasDemandZoneUnderCBar)
{
//
hasDemandZoneUnderCBar = false;
for (int i = 0; i < demandZonesCount; i++)
{
//
XZone iZone = _5MState.demandZones[i];
//
if (!hasDemandZoneUnderCBar &&
iZone.upper < cBar.low)
{
//
iZone.to = cTime;
demandZone = iZone;
hasDemandZoneUnderCBar = true;
//
break;
}
}
}
//
XOHCL swingHigh;
int swingHighsCount = ArraySize(_5MState.swingHighs);
bool hasSwingHighOverCBar = IsValidSize(swingHighsCount);
if (hasSwingHighOverCBar)
{
//
hasSwingHighOverCBar = false;
for (int i = 0; i < swingHighsCount; i++)
{
//
XOHCL iBar = _5MState.swingHighs[i];
//
if (!hasSwingHighOverCBar &&
iBar.high > cBar.high)
{
//
swingHigh = iBar;
hasSwingHighOverCBar = true;
//
break;
}
}
}
//
XOHCL swingLow;
int swingLowsCount = ArraySize(_5MState.swingLows);
bool hasSwingLowUnderCBar = IsValidSize(swingLowsCount);
if (hasSwingLowUnderCBar)
{
//
hasSwingLowUnderCBar = false;
for (int i = 0; i < swingLowsCount; i++)
{
//
XOHCL iBar = _5MState.swingLows[i];
//
if (!hasSwingLowUnderCBar &&
iBar.low < cBar.low)
{
//
swingLow = iBar;
hasSwingLowUnderCBar = true;
//
break;
}
}
}
//
XOHCL bullishRejectionBar;
XOHCL bearishRejectionBar;
bool hasBullishRejectionBarUnderCBar = false;
bool hasBearishRejectionBarOverCBar = false;
int rejectionBarsCount = ArraySize(_5MState.rejectionBars);
if (IsValidSize(rejectionBarsCount))
{
//
for (int i = 0; i < rejectionBarsCount; i++)
{
//
XOHCL iBar = _5MState.rejectionBars[i];
//
bool isBullish = iBar.GetLowShadow() > iBar.GetHighShadow();
bool isBearish = iBar.GetHighShadow() > iBar.GetLowShadow();
//
if (isBullish &&
!hasBullishRejectionBarUnderCBar &&
iBar.high < cBar.low)
{
//
bullishRejectionBar = iBar;
hasBullishRejectionBarUnderCBar = true;
}
//
if (isBearish &&
!hasBearishRejectionBarOverCBar &&
iBar.low > cBar.high)
{
//
bearishRejectionBar = iBar;
hasBearishRejectionBarOverCBar = true;
}
}
}
//
// XZone bullishOB;
// XZone bearishOB;
// XPOIState state = _15MState;
// int obsCount = ArraySize(state.bullishOrderBlocks);
// // for (int i = 0; i < obsCount; i++)
// {
// //
// XZone iZone = state.bullishOrderBlocks[i];
// bool canRefine = CanRefineZone(
// iZone,
// bullishOB,
// cBar //
// );
// //
// if (canRefine &&
// isVWapBullish)
// {
// //
// iZone.to = cTime;
// XCBullishOrderBlockObject *iObj;
// bool isCreated = mPOIDrawer.CreateBullishOrderBlock(
// iZone,
// iObj //
// );
// if (isCreated)
// {
// mDrawnObjects.Add(iObj);
// }
// }
// }
// obsCount = ArraySize(state.bearishOrderBlocks);
// for (int i = 0; i < obsCount; i++)
// {
// //
// XZone iZone = state.bearishOrderBlocks[i];
// bool canRefine = CanRefineZone(
// iZone,
// bearishOB,
// cBar //
// );
// //
// if (canRefine &&
// isVWapBearish)
// {
// //
// iZone.to = cTime;
// XCBearishOrderBlockObject *iObj;
// bool isCreated = mPOIDrawer.CreateBearishOrderBlock(
// iZone,
// iObj //
// );
// if (isCreated)
// {
// mDrawnObjects.Add(iObj);
// }
// }
// }
// int m15Count = ArraySize(_15MState.resistanceZones);
//
// Detect Resistance ....
// if (!mConditions.resistance.IsValid())
// {
// //
// // XZone h4Resistance;
// // XZone m15Resistance;
// // XZone m5Resistance;
// // //
// // int h4Count = ArraySize(_4HState.resistanceZones);
// // int m15Count = ArraySize(_15MState.resistanceZones);
// // int m5Count = ArraySize(_5MState.resistanceZones);
// // //
// // for (int i = 0; i < h4Count; i++)
// // {
// // //
// // XOHCL iBar = _4HState.resistanceZones[i];
// // }
// }
@@ -0,0 +1,836 @@
//
// Draw Functions ...
/**
* Draw Specific Condition ...
*
* @param conditions: X121SMCStrategyConditions instance ...
*/
void DrawConditions(X121SMCStrategyConditions &conditions)
{
//
// Draw Configurations ...
//
bool drawMainDemand = true;
bool drawMainSupply = true;
//
bool drawMainBullishOrderBlock = true;
bool drawMainBearishOrderBlock = true;
//
bool drawMainBullishFVG = true;
bool drawMainBearishFVG = true;
//
bool drawOrderBlocks = false;
bool drawFVGs = false;
bool drawSupportResistances = false;
bool drawSwings = false;
bool drawMomentumBars = false;
bool drawRejectionBars = false;
//
if (!conditions.IsValid())
{
return;
}
//
datetime time = TimeCurrent();
bool hasValidDemand = conditions.ValidateDemand();
bool hasValidSupply = conditions.ValidateSupply();
if (!hasValidDemand && !hasValidSupply)
{
return;
}
//
// Demand Zone ...
if (hasValidDemand)
{
//
// Demand ...
if (drawMainDemand)
{
//
XCDemandZoneObject *iObj;
bool isCreated = mPOIDrawer.CreateDemandZone(
conditions.demandZone,
iObj //
);
if (isCreated)
{
mDrawnObjects.Add(iObj);
}
}
//
if (drawMainBullishOrderBlock)
{
//
XCBullishOrderBlockObject *iObj;
bool isCreated = mPOIDrawer.CreateBullishOrderBlock(
conditions.bullishOrderBlock,
iObj //
);
if (isCreated)
{
mDrawnObjects.Add(iObj);
}
}
//
if (drawMainBullishFVG)
{
//
XCBullishFVGObject *iObj;
bool isCreated = mPOIDrawer.CreateBullishFVG(
conditions.bullishFVG,
iObj //
);
if (isCreated)
{
mDrawnObjects.Add(iObj);
}
}
//
// Order Blocks ...
int obsCount = ArraySize(conditions.bullishOrderBlocks);
if (drawOrderBlocks &&
IsValidSize(obsCount))
{
//
for (int i = 0; i < obsCount; i++)
{
//
XZone iZone = conditions.bullishOrderBlocks[i];
//
XCBullishOrderBlockObject *iObj;
bool isCreated = mPOIDrawer.CreateBullishOrderBlock(
iZone,
iObj //
);
if (isCreated)
{
mDrawnObjects.Add(iObj);
}
}
}
//
// Fair Value Gaps ...
int fvgsCount = ArraySize(conditions.bullishFVGs);
if (drawFVGs &&
IsValidSize(fvgsCount))
{
//
for (int i = 0; i < fvgsCount; i++)
{
//
XZone iZone = conditions.bullishFVGs[i];
//
XCBullishFVGObject *iObj;
bool isCreated = mPOIDrawer.CreateBullishFVG(
iZone,
iObj //
);
if (isCreated)
{
mDrawnObjects.Add(iObj);
}
}
}
//
// Supports ...
int supportsCount = ArraySize(conditions.supports);
if (drawSupportResistances &&
IsValidSize(supportsCount))
{
//
for (int i = 0; i < supportsCount; i++)
{
//
XOHCL iBar = conditions.supports[i];
//
XCSupportZoneObject *iObj;
bool isCreated = mPOIDrawer.CreateSupportZone(
iBar,
iObj,
time //
);
if (isCreated)
{
mDrawnObjects.Add(iObj);
}
}
}
//
// Swings ...
int swingsCount = ArraySize(conditions.swingLows);
if (drawSwings &&
IsValidSize(swingsCount))
{
//
for (int i = 0; i < swingsCount; i++)
{
//
XOHCL iBar = conditions.swingLows[i];
//
XCSwingLowObject *iObj;
bool isCreated = mPOIDrawer.CreateSwingLow(
iBar,
iObj //
);
if (isCreated)
{
mDrawnObjects.Add(iObj);
}
}
}
//
// Momentum Bars ...
int momentumBarsCount = ArraySize(conditions.bullishMomentumBars);
if (drawMomentumBars &&
IsValidSize(momentumBarsCount))
{
//
for (int i = 0; i < momentumBarsCount; i++)
{
//
XOHCL iBar = conditions.bullishMomentumBars[i];
//
XCBullishMomentumBarObject *iObj;
bool isCreated = mPOIDrawer.CreateBullishMomentumBar(
iBar,
iObj //
);
if (isCreated)
{
mDrawnObjects.Add(iObj);
}
}
}
//
// Rejection Bars ...
int rejectionBarsCount = ArraySize(conditions.bullishRejectionBars);
if (drawRejectionBars &&
IsValidSize(rejectionBarsCount))
{
//
for (int i = 0; i < rejectionBarsCount; i++)
{
//
XOHCL iBar = conditions.bullishRejectionBars[i];
//
XCBullishRejectionBarObject *iObj;
bool isCreated = mPOIDrawer.CreateBullishRejectionBar(
iBar,
iObj //
);
if (isCreated)
{
mDrawnObjects.Add(iObj);
}
}
}
}
//
// Supply Zone ...
if (hasValidSupply)
{
//
// Supply ...
if (drawMainSupply)
{
//
XCSupplyZoneObject *iObj;
bool isCreated = mPOIDrawer.CreateSupplyZone(
conditions.supplyZone,
iObj //
);
if (isCreated)
{
mDrawnObjects.Add(iObj);
}
}
//
if (drawMainBearishOrderBlock)
{
//
XCBearishOrderBlockObject *iObj;
bool isCreated = mPOIDrawer.CreateBearishOrderBlock(
conditions.bearishOrderBlock,
iObj //
);
if (isCreated)
{
mDrawnObjects.Add(iObj);
}
}
//
if (drawMainBearishFVG)
{
//
XCBearishFVGObject *iObj;
bool isCreated = mPOIDrawer.CreateBearishFVG(
conditions.bearishFVG,
iObj //
);
if (isCreated)
{
mDrawnObjects.Add(iObj);
}
}
//
// Order Blocks ...
int obsCount = ArraySize(conditions.bearishOrderBlocks);
if (drawOrderBlocks &&
IsValidSize(obsCount))
{
//
for (int i = 0; i < obsCount; i++)
{
//
XZone iZone = conditions.bearishOrderBlocks[i];
//
XCBearishOrderBlockObject *iObj;
bool isCreated = mPOIDrawer.CreateBearishOrderBlock(
iZone,
iObj //
);
if (isCreated)
{
mDrawnObjects.Add(iObj);
}
}
}
//
// Fair Value Gaps ...
int fvgsCount = ArraySize(conditions.bearishFVGs);
if (drawFVGs &&
IsValidSize(fvgsCount))
{
//
for (int i = 0; i < fvgsCount; i++)
{
//
XZone iZone = conditions.bearishFVGs[i];
//
XCBearishFVGObject *iObj;
bool isCreated = mPOIDrawer.CreateBearishFVG(
iZone,
iObj //
);
if (isCreated)
{
mDrawnObjects.Add(iObj);
}
}
}
//
// Resistances ...
int resistancesCount = ArraySize(conditions.resistances);
if (drawSupportResistances &&
IsValidSize(resistancesCount))
{
//
for (int i = 0; i < resistancesCount; i++)
{
//
XOHCL iBar = conditions.resistances[i];
//
XCResistanceZoneObject *iObj;
bool isCreated = mPOIDrawer.CreateResistanceZone(
iBar,
iObj,
time //
);
if (isCreated)
{
mDrawnObjects.Add(iObj);
}
}
}
//
// Swings ...
int swingsCount = ArraySize(conditions.swingHighs);
if (drawSwings &&
IsValidSize(swingsCount))
{
//
for (int i = 0; i < swingsCount; i++)
{
//
XOHCL iBar = conditions.swingHighs[i];
//
XCSwingHighObject *iObj;
bool isCreated = mPOIDrawer.CreateSwingHigh(
iBar,
iObj //
);
if (isCreated)
{
mDrawnObjects.Add(iObj);
}
}
}
//
// Momentum Bars ...
int momentumBarsCount = ArraySize(conditions.bearishMomentumBars);
if (drawMomentumBars &&
IsValidSize(momentumBarsCount))
{
//
for (int i = 0; i < momentumBarsCount; i++)
{
//
XOHCL iBar = conditions.bearishMomentumBars[i];
//
XCBearishMomentumBarObject *iObj;
bool isCreated = mPOIDrawer.CreateBearishMomentumBar(
iBar,
iObj //
);
if (isCreated)
{
mDrawnObjects.Add(iObj);
}
}
}
//
// Rejection Bars ...
int rejectionBarsCount = ArraySize(conditions.bearishRejectionBars);
if (drawRejectionBars &&
IsValidSize(rejectionBarsCount))
{
//
for (int i = 0; i < rejectionBarsCount; i++)
{
//
XOHCL iBar = conditions.bearishRejectionBars[i];
//
XCBearishRejectionBarObject *iObj;
bool isCreated = mPOIDrawer.CreateBearishRejectionBar(
iBar,
iObj //
);
if (isCreated)
{
mDrawnObjects.Add(iObj);
}
}
}
}
}
/**
* Draw Specified Market Struture ...
*
* @param structure: X121SMCMarketStructure instance ...
*/
void DrawMarketStructure(
X121SMCMarketStructure &structure,
ENUM_X_POSITION_TYPES type = X_POSITION_TYPE_ALL //
)
{
//
datetime cTime = TimeCurrent();
//
bool canAll = type == X_POSITION_TYPE_ALL;
bool canLong = type == X_POSITION_TYPE_LONG;
bool canShort = type == X_POSITION_TYPE_SHORT;
//
// Supply Zones ...
int supplysCount = ArraySize(structure.supplyZones);
if ((canAll || canLong) && IsValidSize(supplysCount))
{
//
for (int i = 0; i < supplysCount; i++)
{
//
XZone iZone = structure.supplyZones[i];
//
XCSupplyZoneObject *iObj;
bool isCreated = mPOIDrawer.CreateSupplyZone(
iZone,
iObj //
);
if (isCreated)
{
//
mDrawnObjects.Add(iObj);
}
}
}
//
// Demand Zones ...
int demandsCount = ArraySize(structure.demandZones);
if ((canAll || canShort) && IsValidSize(demandsCount))
{
//
for (int i = 0; i < demandsCount; i++)
{
//
XZone iZone = structure.demandZones[i];
//
XCDemandZoneObject *iObj;
bool isCreated = mPOIDrawer.CreateDemandZone(
iZone,
iObj //
);
if (isCreated)
{
//
mDrawnObjects.Add(iObj);
}
}
}
//
// Order Blocks ...
//
// Bullish OBs ...
int bullishOBsCount = ArraySize(structure.bullishOrderBlocks);
if ((canAll || canShort) && IsValidSize(bullishOBsCount))
{
//
for (int i = 0; i < bullishOBsCount; i++)
{
//
XZone iZone = structure.bullishOrderBlocks[i];
//
XCBullishOrderBlockObject *iObj;
bool isCreated = mPOIDrawer.CreateBullishOrderBlock(
iZone,
iObj //
);
if (isCreated)
{
//
mDrawnObjects.Add(iObj);
}
}
}
//
// Bearish OBs ...
int bearishOBsCount = ArraySize(structure.bearishOrderBlocks);
if ((canAll || canLong) && IsValidSize(bearishOBsCount))
{
//
for (int i = 0; i < bearishOBsCount; i++)
{
//
XZone iZone = structure.bearishOrderBlocks[i];
//
XCBearishOrderBlockObject *iObj;
bool isCreated = mPOIDrawer.CreateBearishOrderBlock(
iZone,
iObj //
);
if (isCreated)
{
//
mDrawnObjects.Add(iObj);
}
}
}
//
// Fair Value Gaps ...
//
// Bullish FVGs ...
int bullishFVGsCount = ArraySize(structure.bullishFVGs);
if ((canAll || canShort) && IsValidSize(bullishFVGsCount))
{
//
for (int i = 0; i < bullishFVGsCount; i++)
{
//
XZone iZone = structure.bullishFVGs[i];
//
XCBullishFVGObject *iObj;
bool isCreated = mPOIDrawer.CreateBullishFVG(
iZone,
iObj //
);
if (isCreated)
{
//
mDrawnObjects.Add(iObj);
}
}
}
//
// Bearish FVGs ...
int bearishFVGsCount = ArraySize(structure.bearishFVGs);
if ((canAll || canLong) && IsValidSize(bearishFVGsCount))
{
//
for (int i = 0; i < bearishFVGsCount; i++)
{
//
XZone iZone = structure.bearishFVGs[i];
//
XCBearishFVGObject *iObj;
bool isCreated = mPOIDrawer.CreateBearishFVG(
iZone,
iObj //
);
if (isCreated)
{
//
mDrawnObjects.Add(iObj);
}
}
}
//
// Swing Highs ...
int swingHighsCount = ArraySize(structure.swingHighs);
if ((canAll || canLong) && IsValidSize(swingHighsCount))
{
//
for (int i = 0; i < swingHighsCount; i++)
{
//
XOHCL iBar = structure.swingHighs[i];
//
XCSwingHighObject *iObj;
bool isCreated = mPOIDrawer.CreateSwingHigh(
iBar,
iObj //
);
if (isCreated)
{
//
mDrawnObjects.Add(iObj);
}
}
}
//
// Swing Lows ...
int swingLowsCount = ArraySize(structure.swingLows);
if ((canAll || canShort) && IsValidSize(swingLowsCount))
{
//
for (int i = 0; i < swingLowsCount; i++)
{
//
XOHCL iBar = structure.swingLows[i];
//
XCSwingLowObject *iObj;
bool isCreated = mPOIDrawer.CreateSwingLow(
iBar,
iObj //
);
if (isCreated)
{
//
mDrawnObjects.Add(iObj);
}
}
}
//
// Support Zones ...
int supportsCount = ArraySize(structure.supports);
if ((canAll || canShort) && IsValidSize(supportsCount))
{
//
for (int i = 0; i < supportsCount; i++)
{
//
XOHCL iBar = structure.supports[i];
//
XCSupportZoneObject *iObj;
bool isCreated = mPOIDrawer.CreateSupportZone(
iBar,
iObj,
cTime //
);
if (isCreated)
{
//
mDrawnObjects.Add(iObj);
}
}
}
//
// Resistance Zones ...
int resistancesCount = ArraySize(structure.resistances);
if ((canAll || canLong) && IsValidSize(resistancesCount))
{
//
for (int i = 0; i < resistancesCount; i++)
{
//
XOHCL iBar = structure.resistances[i];
//
XCResistanceZoneObject *iObj;
bool isCreated = mPOIDrawer.CreateResistanceZone(
iBar,
iObj,
cTime //
);
if (isCreated)
{
//
mDrawnObjects.Add(iObj);
}
}
}
//
// Momentum Bars ...
//
// Bullish Momentum Bars ...
int momentumBarCount = ArraySize(structure.bullishMomentumBars);
if ((canAll || canShort) && IsValidSize(momentumBarCount))
{
//
for (int i = 0; i < momentumBarCount; i++)
{
//
XOHCL iBar = structure.bullishMomentumBars[i];
//
XCBullishMomentumBarObject *iObj;
bool isCreated = mPOIDrawer.CreateBullishMomentumBar(
iBar,
iObj //
);
if (isCreated)
{
//
mDrawnObjects.Add(iObj);
}
}
}
//
// Bearish Momentum Bars ...
momentumBarCount = ArraySize(structure.bearishMomentumBars);
if ((canAll || canLong) && IsValidSize(momentumBarCount))
{
//
for (int i = 0; i < momentumBarCount; i++)
{
//
XOHCL iBar = structure.bearishMomentumBars[i];
//
XCBearishMomentumBarObject *iObj;
bool isCreated = mPOIDrawer.CreateBearishMomentumBar(
iBar,
iObj //
);
if (isCreated)
{
//
mDrawnObjects.Add(iObj);
}
}
}
//
// Rejection Bars ...
//
// Bullish Rejection Bars ...
int rejectionBarCount = ArraySize(structure.bullishRejectionBars);
if ((canAll || canShort) && IsValidSize(rejectionBarCount))
{
//
for (int i = 0; i < rejectionBarCount; i++)
{
//
XOHCL iBar = structure.bullishRejectionBars[i];
//
XCBullishRejectionBarObject *iObj;
bool isCreated = mPOIDrawer.CreateBullishRejectionBar(
iBar,
iObj //
);
if (isCreated)
{
//
mDrawnObjects.Add(iObj);
}
}
}
//
// Bearish Rejection Bars ...
rejectionBarCount = ArraySize(structure.bearishRejectionBars);
if ((canAll || canLong) && IsValidSize(rejectionBarCount))
{
//
for (int i = 0; i < rejectionBarCount; i++)
{
//
XOHCL iBar = structure.bearishRejectionBars[i];
//
XCBearishRejectionBarObject *iObj;
bool isCreated = mPOIDrawer.CreateBearishRejectionBar(
iBar,
iObj //
);
if (isCreated)
{
//
mDrawnObjects.Add(iObj);
}
}
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,156 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XCButton
// Description: provides all based classes for use ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
#include "../XCObjects/x-saherelm.xcobject.class.mq5"
//
// Definitions ...
//
// Implementation ...
//
// a Button Creation Class ...
class XCButton : public XCObject
{
//
// Public ...
public:
//
// Constructor(s) ...
void XCButton()
{
}
//
// Deconstructor ...
void ~XCButton()
{
}
//
// Actions ...
/**
* Create an Instance of Class Object ...
*
* @param name: Object Name
* @param xDis: X Distance
* @param yDis: Y Distance
* @param xSize: X Size
* @param ySize: Y Size
*/
bool Create(
string name,
int xDis,
int yDis,
int xSize,
int ySize,
long chartID = 0 //
)
{
//
// Object creation and property settings
bool result = false;
//
result = ObjectCreate(chartID, name, OBJ_BUTTON, 0, 0, 0);
if (!result)
{
return result;
}
//
ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, xDis);
ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, yDis);
ObjectSetInteger(chartID, name, OBJPROP_XSIZE, xSize);
ObjectSetInteger(chartID, name, OBJPROP_YSIZE, ySize);
//
mName = name;
mChartID = chartID;
//
return result;
}
//
// Getter(s) / Setter(s) ...
/**
* Set Object Border Color ...
*
* @param value: color
*/
void BorderColor(color value)
{
ObjectSetInteger(mChartID, mName, OBJPROP_BORDER_COLOR, value);
}
/**
* Set Object Background Color ...
*
* @param value: color
*/
void BGColor(color value)
{
ObjectSetInteger(mChartID, mName, OBJPROP_BGCOLOR, value);
}
/**
* Set Object Text Color ...
*
* @param value: Color
*/
void Color(color value)
{
ObjectSetInteger(mChartID, mName, OBJPROP_COLOR, value);
}
/**
* Set Object Text ...
*
* @param value: text
*/
void Text(string value)
{
ObjectSetString(mChartID, mName, OBJPROP_TEXT, value);
}
/**
* Set Button Click State ...
*
* @param value: state
*/
void State(bool value)
{
ObjectSetInteger(mChartID, mName, OBJPROP_STATE, value);
}
//
// Protected ...
protected:
//
// Private ...
private:
//
};
@@ -0,0 +1,186 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XCEdit
// Description: provides all based classes for use ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
#include "../XCObjects/x-saherelm.xcobject.class.mq5"
//
// Definitions ...
//
// Implementation ...
//
// a Label Creation Class ...
class XCEdit : public XCObject
{
//
// Public ...
public:
//
// Constructor(s) ...
void XCEdit()
{
}
//
// Deconstructor ...
void ~XCEdit()
{
}
//
// Actions ...
/**
* Create an Instance of Class Object ...
*
* @param name: Object Name
* @param xDis: X Distance
* @param yDis: Y Distance
* @param xSize: X Size
* @param ySize: Y Size
*/
bool Create(
string name,
int xDis,
int yDis,
int xSize,
int ySize,
long chartID = 0 //
)
{
//
// Object creation and property settings
bool result = false;
//
result = ObjectCreate(chartID, name, OBJ_EDIT, 0, 0, 0);
if (!result)
{
return result;
}
//
ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, xDis);
ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, yDis);
ObjectSetInteger(chartID, name, OBJPROP_XSIZE, xSize);
ObjectSetInteger(chartID, name, OBJPROP_YSIZE, ySize);
//
mName = name;
mChartID = chartID;
//
return result;
}
//
// Getter(s) / Setter(s) ...
/**
* Set Object Border Color ...
*
* @param value: color
*/
void BorderColor(color value)
{
ObjectSetInteger(mChartID, mName, OBJPROP_BORDER_COLOR, value);
}
/**
* Set Background Color of Object ...
*
* @param value: color
*/
void BGColor(color value)
{
ObjectSetInteger(mChartID, mName, OBJPROP_BGCOLOR, value);
}
/**
* Set Object Text Color ...
*
* @param value: color
*/
void Color(color value)
{
ObjectSetInteger(mChartID, mName, OBJPROP_COLOR, value);
}
/**
* Set Text of Object ...
*
* @param value: text
*/
void Text(string value)
{
ObjectSetString(mChartID, mName, OBJPROP_TEXT, value);
}
/**
* Get Current Text of Object ...
*
* @return ( string )
*/
string Text()
{
return ObjectGetString(mChartID, mName, OBJPROP_TEXT);
}
/**
* Set Font Size of Object ...
*
* @param value: size
*/
void FontSize(int value)
{
ObjectSetInteger(mChartID, mName, OBJPROP_FONTSIZE, value);
}
/**
* Set Font Name Of Object ...
*
* @param value: font name
*/
void Font(string value)
{
ObjectSetString(mChartID, mName, OBJPROP_FONT, value);
}
/**
* Set ReadOnly State of Object ...
*
* @param value: boolean value
*/
void ReadOnly(bool value)
{
ObjectSetInteger(mChartID, mName, OBJPROP_READONLY, value);
}
//
// Protected ...
protected:
//
// Private ...
private:
//
};
@@ -0,0 +1,160 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XCLabel
// Description: provides all based classes for use ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
#include "../XCObjects/x-saherelm.xcobject.class.mq5"
//
// Definitions ...
//
// Implementation ...
//
// a Label Creation Class ...
class XCLabel : public XCObject
{
//
// Public ...
public:
//
// Constructor(s) ...
void XCLabel()
{
}
//
// Deconstructor ...
void ~XCLabel()
{
}
//
// Actions ...
/**
* Create an Instance of Class Object ...
*
* @param name: Object Name
* @param xDis: X Distance
* @param yDis: Y Distance
*/
bool Create(
string name,
int xDis,
int yDis,
long chartID = 0 //
)
{
//
// Object creation and property settings
bool result = false;
//
result = ObjectCreate(chartID, name, OBJ_LABEL, 0, 0, 0);
if (!result)
{
return result;
}
//
ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, xDis);
ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, yDis);
//
mName = name;
mChartID = chartID;
//
return result;
}
//
// Getter(s) / Setter(s) ...
/**
* Set Text Color ...
*
* @param value: color
*/
void Color(color value)
{
ObjectSetInteger(mChartID, mName, OBJPROP_COLOR, value);
}
/**
* Set Text of Object ...
*
* @param value: text
*/
void Text(string value)
{
ObjectSetString(mChartID, mName, OBJPROP_TEXT, value);
}
/**
* Get Text Of Object ...
*
* @return ( string )
*/
string Text()
{
return ObjectGetString(mChartID, mName, OBJPROP_TEXT);
}
/**
* Set Font Size of Object ...
*
* @param value: size
*/
void FontSize(int value)
{
ObjectSetInteger(mChartID, mName, OBJPROP_FONTSIZE, value);
}
/**
* Set Font Name Of Object ...
*
* @param value: font name
*/
void Font(string value)
{
ObjectSetString(mChartID, mName, OBJPROP_FONT, value);
}
/**
* Set Object Anchor ...
*
* @param value: anchor
*/
void Anchor(ENUM_ANCHOR_POINT value)
{
ObjectSetInteger(mChartID, mName, OBJPROP_ANCHOR, value);
}
//
// Protected ...
protected:
//
// Private ...
private:
//
};
@@ -0,0 +1,299 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XCPanel
// Description: provides all based classes for use ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// Imports ...
#include "../XCObjects/x-saherelm.x-button.class.mq5"
#include "../XCObjects/x-saherelm.x-edit.class.mq5"
#include "../XCObjects/x-saherelm.x-label.class.mq5"
#include "../XCObjects/x-saherelm.x-rectangle.label.class.mq5"
//
// Implementation ...
//
class XCPanel : XCObject
{
public:
//
// Constructor(s) ...
void XCPanel()
{
}
//
// Deconstructor ...
void ~XCPanel()
{
Destroy();
}
//
// Action ...
/**
* Create an instance of Panel Object ...
*
* @param name: Object name
* @param xDis: X Distance
* @param yDis: Y Distance
* @param xSize: X Size
* @param ySize: Y Size
* @param titleBarBorderType: Border Type of Panel TitleBar
* @param titleBarBGColor: Background Color of Panel TitleBar
* @param caption: Caption Text of Panel TitleBar
* @param captionontSize: Font Size of Panel Caption
* @param captionColor: Text Color of Panel Caption
* @param captionAnchor: Anchor Point of Panel Caption
* @param bodyBorderType: Border Type of Panel Body
* @param bodyBGColor: Background Color of Panel Body
*
* @return ( bool )
*/
bool Create(
string name,
int xDis,
int yDis,
int xSize,
int ySize,
//
long chartID = 0,
//
// Title Bar ...
ENUM_BORDER_TYPE titleBarBorderType = BORDER_FLAT,
color titleBarBGColor = clrBlueViolet,
//
// Caption ...
string caption = "",
int captionontSize = 9,
color captionColor = clrWhite,
ENUM_ANCHOR_POINT captionAnchor = ANCHOR_LEFT_UPPER,
//
// Body ...
ENUM_BORDER_TYPE bodyBorderType = BORDER_FLAT,
color bodyBGColor = clrMediumSlateBlue //
)
{
//
bool result = false;
//
// Enables mouse move events on the chart
ChartSetInteger(chartID, CHART_EVENT_MOUSE_MOVE, true);
//
result = IsValid(name);
if (!result)
{
//
Destroy();
return result;
}
//
mTitleBarName = name + "_TITLE_BAR";
mCaptionLblName = name + "_CAPTION";
mBodyName = name + "_BODY";
//
if (!IsValid(caption))
{
caption = name;
}
//
// Title Bar ...
int titleBarHeight = 20;
result = mTitleBar.Create(
mTitleBarName,
xDis,
yDis,
xSize,
titleBarHeight //
);
if (!result)
{
//
Destroy();
return result;
}
mTitleBar.BorderType(titleBarBorderType);
mTitleBar.BGColor(titleBarBGColor);
//
// Body ...
result = mBody.Create(
mBodyName,
xDis,
yDis + titleBarHeight - 1,
xSize,
ySize //
);
if (!result)
{
//
Destroy();
return result;
}
mBody.BorderType(bodyBorderType);
mBody.BGColor(bodyBGColor);
mBody.AsBackGround(true);
//
// Caption ...
result = mCaptionLbl.Create(mCaptionLblName, xDis, yDis);
if (!result)
{
//
Destroy();
return result;
}
mCaptionLbl.Text(caption);
mCaptionLbl.Color(captionColor);
mCaptionLbl.Anchor(captionAnchor);
mCaptionLbl.FontSize(captionontSize);
//
// Adding Child Objects ...
mTitleBar.Add(mBodyName);
mTitleBar.Add(mCaptionLblName);
//
return result;
}
/**
* Destroy Panel Object and all of it's Child
*/
void Destroy()
{
//
mBodyName = NULL;
mTitleBarName = NULL;
mCaptionLblName = NULL;
//
mBody.Destroy();
mTitleBar.Destroy();
mCaptionLbl.Destroy();
}
/**
* Event Handling for Mouse Movement ...
* @param id: Event ID
* @param lparam: Event parameter of long type
* @param dparam: Event parameter of double type
* @param sparam: Event parameter of string type
*/
void OnEvent(
int id,
long lparam,
double dparam,
string sparam //
)
{
//
mTitleBar.OnEvent(
id,
lparam,
dparam,
sparam //
);
}
/**
* Add Specific Child Object ...
*
* @param name: object name
*/
void Add(string name)
{
mTitleBar.Add(name);
}
/**
* Retrieve Panel Caption ...
*
* @return ( string )
*/
string Caption()
{
return mCaptionLbl.Text();
}
/**
* Set Panel Caption ...
*
* @param value: Caption
*/
void Caption(string value)
{
mCaptionLbl.Text(value);
}
/**
* Set Caption Color ...
*
* @param value: Color
*/
void CptionColor(color value)
{
mCaptionLbl.Color(value);
}
/**
* Set Panel Body BG Color ...
*
* @param value: Color
*/
void BodyColor(color value)
{
mBody.BGColor(value);
}
/**
* Set Panel Titlebar BG Color ...
*
* @param value: Color
*/
void TitleBarBGColor(color value)
{
mTitleBar.BGColor(value);
}
//
protected:
private:
//
// Props ...
//
string mBodyName;
string mTitleBarName;
string mCaptionLblName;
//
XCLabel mCaptionLbl;
XCRectangleLabel mBody;
XCRectangleLabel mTitleBar;
//
};
@@ -0,0 +1,259 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XCRectangleLabel
// Description: provides all based classes for use ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
#include "../XCObjects/x-saherelm.xcobject.class.mq5"
//
// Definitions ...
//
// Implementation ...
//
// a Rectangle Label Creation Class ...
class XCRectangleLabel : public XCObject
{
//
// Public ...
public:
//
// Constructor(s) ...
void XCRectangleLabel()
{
}
//
// Deconstructor ...
void ~XCRectangleLabel()
{
}
//
// Actions ...
/**
* Create an Instance of Class Object ...
*
* @param name: Object Name
* @param xDis: X Distance
* @param yDis: Y Distance
* @param xSize: X Size
* @param ySize: Y Size
*/
bool Create(
string name,
int xDis,
int yDis,
int xSize,
int ySize,
long chartID = 0 //
)
{
//
// Object creation and property settings
bool result = false;
//
result = ObjectCreate(chartID, name, OBJ_RECTANGLE_LABEL, 0, 0, 0);
if (!result)
{
return result;
}
//
ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, xDis);
ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, yDis);
ObjectSetInteger(chartID, name, OBJPROP_XSIZE, xSize);
ObjectSetInteger(chartID, name, OBJPROP_YSIZE, ySize);
//
mName = name;
mChartID = chartID;
//
return result;
}
/**
* Add a Name to Object
* @param name: name
*/
void Add(string name)
{
//
// Add a new object by name to the rectangle label and track distances
ArrayResize(mAddedNames, ArraySize(mAddedNames) + 1);
ArrayResize(mAddedXDisDiffrence, ArraySize(mAddedXDisDiffrence) + 1);
ArrayResize(mAddedYDisDiffrence, ArraySize(mAddedYDisDiffrence) + 1);
//
mAddedNames[ArraySize(mAddedNames) - 1] = name;
mAddedXDisDiffrence[ArraySize(mAddedXDisDiffrence) - 1] = ObjectGetInteger(0, mName, OBJPROP_XDISTANCE) - ObjectGetInteger(0, name, OBJPROP_XDISTANCE);
mAddedYDisDiffrence[ArraySize(mAddedYDisDiffrence) - 1] = ObjectGetInteger(0, mName, OBJPROP_YDISTANCE) - ObjectGetInteger(0, name, OBJPROP_YDISTANCE);
}
//
// Handlers ...
/**
* Event Handling for Mouse Movement ...
* @param id: Event ID
* @param lparam: Event parameter of long type
* @param dparam: Event parameter of double type
* @param sparam: Event parameter of string type
*/
void OnEvent(
int id,
long lparam,
double dparam,
string sparam //
)
{
//
// Handle mouse movement events for dragging the rectangle label
if (id == CHARTEVENT_MOUSE_MOVE)
{
//
int X = (int)lparam;
int Y = (int)dparam;
int MouseState = (int)sparam;
//
string name = mName;
int XSize = (int)ObjectGetInteger(0, name, OBJPROP_XSIZE);
int YSize = (int)ObjectGetInteger(0, name, OBJPROP_YSIZE);
int XDistance = (int)ObjectGetInteger(0, name, OBJPROP_XDISTANCE);
int YDistance = (int)ObjectGetInteger(0, name, OBJPROP_YDISTANCE);
//
if (MouseState == 1 &&
mPreviousMouseState == 0)
{
//
mlbDownX = X;
mlbDownY = Y;
mlbDownXDistance = XDistance;
mlbDownYDistance = YDistance;
//
if (X >= XDistance &&
Y >= YDistance &&
X <= XDistance + XSize &&
Y <= YDistance + YSize)
{
mMovingState = true;
}
}
//
if (mMovingState)
{
//
ChartSetInteger(0, CHART_MOUSE_SCROLL, false);
ObjectSetInteger(0, name, OBJPROP_XDISTANCE, mlbDownXDistance + X - mlbDownX);
ObjectSetInteger(0, name, OBJPROP_YDISTANCE, mlbDownYDistance + Y - mlbDownY);
//
for (int i = 0; i < ArraySize(mAddedNames); i++)
{
//
ObjectSetInteger(0, mAddedNames[i], OBJPROP_XDISTANCE, mlbDownXDistance + X - mlbDownX - mAddedXDisDiffrence[i]);
ObjectSetInteger(0, mAddedNames[i], OBJPROP_YDISTANCE, mlbDownYDistance + Y - mlbDownY - mAddedYDisDiffrence[i]);
}
//
ChartRedraw(0);
}
//
if (MouseState == 0)
{
//
mMovingState = false;
ChartSetInteger(0, CHART_MOUSE_SCROLL, true);
}
//
mPreviousMouseState = MouseState;
}
}
//
// Getter(s) / Setter(s) ...
/**
* Set Object Border Type ...
*
* @param borderType: Specified border type
*/
void BorderType(ENUM_BORDER_TYPE borderType)
{
//
ObjectSetInteger(
mChartID,
mName,
OBJPROP_BORDER_TYPE,
borderType //
);
}
/**
* Set Object Background Color
*
* @param value: color
*/
void BGColor(color value)
{
//
ObjectSetInteger(
mChartID,
mName,
OBJPROP_BGCOLOR,
value //
);
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
//
// Mouse state tracking variables ...
int mlbDownX;
int mlbDownY;
int mlbDownXDistance;
int mlbDownYDistance;
int mPreviousMouseState;
//
bool mMovingState; // State for whether the object is moving
//
string mAddedNames[]; // Array of added names
long mAddedXDisDiffrence[]; // Arrays to store added distance differences
long mAddedYDisDiffrence[]; // Arrays to store added distance differences
};
@@ -0,0 +1,116 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XCObject
// Description: Base Class Of Chart Object Class
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
#include "../x-saherelm.base.class.mq5"
//
// Definitions ...
//
// Implementation ...
//
// a Button Creation Class ...
class XCObject : XSCBase
{
//
// Public ...
public:
//
// Constructor(s) ...
void XCObject()
{
mChartID = 0;
}
//
// Deconstructor ...
void ~XCObject()
{
Destroy();
}
/**
* Destroy Class Instance ...
*/
void Destroy()
{
//
mName = NULL;
ObjectDelete(0, mName);
}
//
// Getter(s) / Setter(s) ...
/**
* Retrieve Object Name ...
*
* @return ( string )
*/
string Name()
{
return mName;
}
/**
* Retrieve Registered Chart ID ...
*
* @return ( long )
*/
long ChartID()
{
return mChartID;
}
/**
* Set Object ZOrder ...
*
* @param value: z order
*/
void ZOrder(int value)
{
ObjectSetInteger(0, mName, OBJPROP_ZORDER, value);
}
/**
* Set Object as Background ...
*
* @param value: boolean value
*/
void AsBackGround(bool value)
{
ObjectSetInteger(0, mName, OBJPROP_BACK, value);
}
//
// Protected ...
protected:
//
string mName; // Name of Object ...
long mChartID; // Chart ID ...
//
// Private ...
private:
//
};
@@ -0,0 +1,97 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XBaseClass
// Description: provides all based classes for use ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// XBase Class ...
class XSCBase
{
//
// Public ...
public:
//
// Protected ...
//
// Represent Basic Unique Tag ...
virtual string GetTag();
//
// Retrieve Class Token ...
virtual string GetToken();
//
// Protected
protected:
//
// Private ...
private:
};
//
template <typename T>
string GenerateSpecifiedCommonSummary(
T &mItem,
string separator = "\n",
bool includeScores = true,
bool setLabel = false //
)
{
//
string result = NULL;
//
double bullishScore = 0;
double bearishScore = 0;
mItem.GenerateScore(
bullishScore,
bearishScore //
);
//
result =
//
(!setLabel
? ""
: "Commons:" + separator) +
"---------------" + separator +
"Symbol: " + mItem.symbol + separator +
"Period: " + ToString(mItem.period) + separator +
"Time: " + ToString(mItem.time) + separator +
(includeScores
? "---------------" + separator +
"Scores:" + separator +
"---------------" + separator +
"Bullish: " + ToString(bullishScore) + separator +
"Bearish: " + ToString(bearishScore) + separator +
"---------------" + separator
: "") +
""
//
;
//
return result;
}
//
@@ -0,0 +1,398 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCAccount
// Description: provides all Account requirements ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// START Definitions ...
//
//
// END Definitions ...
//
//
// START Import and Inclused requirements ...
//
//
// Includes ...
#include <Trade/AccountInfo.mqh>
#include "../Classes/x-saherelm.base.class.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
//
// a Class for Manage Account ...
class XSCAccount : public XSCBase
{
//
// Public ...
public:
//
// Constructor ...
void XSCAccount()
{
//
mAccountInfo = new CAccountInfo();
}
//
// Deconstructor ...
void ~XSCAccount()
{
}
//
// START Provided Functions ...
//
//
// User Account ...
long GetUserAccount()
{
return mAccountInfo.Login();
}
//
// Account Leverage ...
long GetLeverage()
{
return mAccountInfo.Leverage();
}
//
// Get Trade Expert State ...
bool CanExpertTrade()
{
return mAccountInfo.TradeExpert();
}
//
// User Account Trade Mopde (ENUM_ACCOUNT_TRADE_MODE) ...
// --------------------------
// ACCOUNT_TRADE_MODE_DEMO
// ACCOUNT_TRADE_MODE_CONTEST
// ACCOUNT_TRADE_MODE_REAL
ENUM_ACCOUNT_TRADE_MODE GetTradeMode()
{
return mAccountInfo.TradeMode();
}
//
// Get Account Balance ...
double GetBalance()
{
return mAccountInfo.Balance();
}
//
// Get the amount of give Credit ...
double GetCredit()
{
return mAccountInfo.Credit();
}
//
// Get the amount of current Profit on account ...
double GetProfit()
{
return mAccountInfo.Profit();
}
//
// Get the amount of current Equity on account ...
double GetEquity()
{
return mAccountInfo.Equity();
}
//
// Get the amount of reserved Margin ...
double GetMargin()
{
return mAccountInfo.Margin();
}
//
// Get the amount of free Margin ...
double GetFreeMargin()
{
return mAccountInfo.FreeMargin();
}
//
// Get the Level of Margin ...
double GetMarginLevel()
{
return mAccountInfo.MarginLevel();
}
//
// Get the Level Of Margin for a Deposit ...
double GetMarginCall()
{
return mAccountInfo.MarginCall();
}
//
// Get the Level of Margin for Stop out ...
double GetMarginStopOut()
{
return mAccountInfo.MarginStopOut();
}
//
// Get the Client Name ...
string GetName()
{
return mAccountInfo.Name();
}
//
// Get the Trade Server Name ...
string GetServerName()
{
return mAccountInfo.Server();
}
//
// Get deposit Currency Name ...
string GetCurrency()
{
return mAccountInfo.Currency();
}
//
// Get the Company Name that serves an Account ...
string GetCompany()
{
return mAccountInfo.Company();
}
//
// Calculate Profits for the current account based on passed parameters ...
double CalculateTradeProfit(
const string symbol, // trading symbol
ENUM_ORDER_TYPE type, // order type
double volume, // volume
double entry, // open price
double exit // close price
)
{
//
double result = mAccountInfo.OrderProfitCheck(
symbol,
type,
volume,
entry,
exit);
//
return result;
}
//
// Calculate amount of margin which required for trade operation ...
double CalculateMarging(
const string symbol, // trading symbol
ENUM_ORDER_TYPE type, // order type
double volume, // volume
double entry // open price
)
{
//
double result = mAccountInfo.MarginCheck(
symbol,
type,
volume,
entry);
//
return result;
}
//
// Calculate amount of free margin left after trade operation ...
double CalculateFreeMarging(
const string symbol, // trading symbol
ENUM_ORDER_TYPE type, // order type
double volume, // volume
double entry // open price
)
{
//
double result = mAccountInfo.FreeMarginCheck(
symbol,
type,
volume,
entry);
//
return result;
}
//
// Calculate the Maximum possible volume of trade operation ...
double CalculateMaxVolume(
const string symbol, // trading symbol
ENUM_ORDER_TYPE type, // order type
double entry, // open price
double percent = 100 // percent of available margin
)
{
//
double result = mAccountInfo.MaxLotCheck(
symbol,
type,
entry,
percent);
//
return result;
}
//
// Calculate Point Value for Given Symbol based on Account ...
double GetPointValue(
string symbol // trading symbol
)
{
//
double result = 0;
//
double tickSize = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE);
double tickValue = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_VALUE);
double point = SymbolInfoDouble(symbol, SYMBOL_POINT);
//
double ticksPerPoint = tickSize / point;
//
result = tickValue / ticksPerPoint;
//
return result;
}
//
// Calculate Risk Amount based on account Currency by Providing:
// Points and Volume ...
double CalculateRiskAmount(
string symbol, // trading symbol
double points, // amount of Risk Points
double volume // position Volume
)
{
//
double result = 0;
//
double pointValue = GetPointValue(symbol);
//
result = pointValue * volume * points;
//
return result;
}
//
// Calculate Risk Points based on account Currency by Providing:
// Volume and Amount ...
double CalculateRiskPoints(
string symbol, // trading symbol
double volume, // position Volume
double amount // amount of Risk based on Account Currency
)
{
//
double result = 0;
//
double pointValue = GetPointValue(symbol);
//
result = amount / (pointValue * volume);
//
return result;
}
//
// Calculate Volume based on account Currency by Providing:
// Amount and Risk Points ...
double CalculateVolume(
string symbol, // trading symbol
double amount, // amount of Risk based on Account Currency
double points // amount of Risk Points
)
{
//
double result = 0;
//
points =
points <= 0
? 10
: points;
//
double pointValue = GetPointValue(symbol);
//
result = amount / (pointValue * points);
//
return result;
}
//
// END Provided Functions ...
//
//
// Protected ...
protected:
//
// Private ...
private:
//
// Account Info ...
CAccountInfo mAccountInfo;
};
//
// START Usefull Functions ...
//
//
// END Usefull Functions ...
//
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,148 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCBaseHelper
// Description: provides all Base Indicator
// Helper requirements ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// Includes ...
#include "../Classes/x-saherelm.base.class.mq5"
//
// Definitions ...
//
// a Class for Handle base requirements ...
// for indicators ...
class XSCBaseHelper : public XSCBase
{
//
// Public ...
public:
//
// Constructor ...
void XSCBaseHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period // Trading Time Frame
)
{
//
mSymbol = symbol;
mPeriod = period;
}
//
// Deconstructor ...
void ~XSCBaseHelper()
{
//
IndicatorRelease(mHandler);
}
//
// Setter(s) / Getter(s) ...
//
// Symbol ...
string GetSymbol()
{
return mSymbol;
}
//
// Period ...
ENUM_TIMEFRAMES GetPeriod()
{
return mPeriod;
}
//
// Retrieve Bars ...
int CountBars()
{
//
int result =
Bars(
mSymbol,
mPeriod
//
);
//
return result;
}
//
// Retrieve Indicator Calculated Bars ...
int CountCalculatedBars()
{
return BarsCalculated(mHandler);
}
//
// Generate Tag ...
virtual string GetTag()
{
//
string result = NULL;
//
result =
//
GetToken() +
"[" +
GetSymbol() + "|" +
ToString(GetPeriod()) +
"]"
//
;
//
return result;
}
//
// Functions ...
//
// Protected ...
protected:
//
// Props ...
//
// Symbol ...
string mSymbol;
//
// Period ...
ENUM_TIMEFRAMES mPeriod;
//
// Indicator Handler ...
int mHandler;
//
// Private ...
private:
//
};
//
// Tools ....
@@ -0,0 +1,373 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCHttp
// Description: provides all HTTP requirements ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// Definitions ...
//
enum X_HTTP_METHOD
{
X_HTTP_GET,
X_HTTP_POST
};
//
// Imports ...
//
// Includes ...
#include "../Classes/x-saherelm.base.class.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// a Class for Manage Account ...
class XSCHttp : public XSCBase
{
//
// Public ...
public:
//
// Constructor ...
void XSCHttp()
{
XSCHttp("", 10000);
}
void XSCHttp(
string path, // Base Folder to Store Data
int timeout // base timeout for Requests
)
{
//
Path(path);
Timeout(timeout);
}
//
// Deconstructor ...
void ~XSCHttp()
{
}
//
// Properties Getter(s) / Setter(s) ...
//
// Path ...
void Path(string value)
{
//
mPath = value;
//
if (!IsValid(mPath))
{
mPath = GetTag();
}
}
string Path()
{
return mPath;
}
//
// Timeout ...
void Timeout(int value)
{
mTimeout = value;
}
//
int Timeout()
{
return mTimeout;
}
//
// Error ...
int Error()
{
return mError;
}
//
// Response ...
string Response()
{
return mResponse;
}
//
// Overrides ...
string GetTag() override
{
return GetSpecificToken(this);
}
//
// Tools ...
//
// Send Global Request ...
int SendRequest(
X_HTTP_METHOD method, // Httm Request Method
const string url, // Server Address
const string headers, // Headers providing
const char &payload[], // the Data which needs to Send
char &response[], // Response of request
string responseHeaders, // Response Headers
int timeout = 500 // Timeout for response default is 500
)
{
//
int result = -1;
//
string strMethod = ToString(method);
if (StringLen(strMethod) == 0)
{
return result;
}
//
// Reset State ...
ResetState();
//
result = WebRequest(
strMethod,
url,
headers,
timeout,
payload,
response,
responseHeaders);
//
if (result < 0)
{
mError = GetLastError();
}
else
{
mResponse = CharArrayToString(response);
}
//
return result;
}
//
// Get Request ...
int GetRequest(
const string url, // Server Address
const string headers, // Headers providing
const char &payload[], // the Data which needs to Send
char &response[], // Response of request
string responseHeaders, // Response Headers
int timeout = 500 // Timeout for response default is 500
)
{
//
int result = SendRequest(
X_HTTP_GET,
url,
headers,
payload,
response,
responseHeaders,
timeout);
//
return result;
}
//
// Post Request ...
int PostRequest(
const string url, // Server Address
const string headers, // Headers providing
const char &payload[], // the Data which needs to Send
char &response[], // Response of request
string responseHeaders, // Response Headers
int timeout = 500 // Timeout for response default is 500
)
{
//
int result = SendRequest(
X_HTTP_POST,
url,
headers,
payload,
response,
responseHeaders,
timeout);
//
return result;
}
//
// Handle Download Specific URL Content to Specific Path and File Name ...
bool Download(
string url, // the URL address which going to download
string fileName // Specify Destination file name to Store Response
)
{
//
bool result = false;
//
string filePath = GetFilePath(fileName);
string cookie = NULL;
string referer = NULL;
int timeout = Timeout();
//
char payload[];
string headers;
char response[];
string responseHeaders;
//
// Send Request ...
int requestResult = GetRequest(
url,
headers,
payload,
response,
responseHeaders,
timeout);
//
// Define File Handler ...
int mFileHandler = FileOpen(
filePath,
FILE_WRITE | FILE_BIN);
if (mFileHandler == INVALID_HANDLE)
{
//
mError = GetLastError();
return result;
}
//
// Write Response to File ...
uint writed = FileWriteArray(
mFileHandler,
response,
0,
ArraySize(response));
FileFlush(mFileHandler);
FileClose(mFileHandler);
//
result = writed > 0;
//
return result;
}
//
// END Provided Functions ...
//
//
// Protected ...
protected:
//
// Destintion Folder Path ...
string mPath;
//
// WEB Request Timeout Value ...
int mTimeout;
//
// WEB Request's Response ...
string mResponse;
//
// Error Value ...
int mError;
//
// Private ...
private:
//
// Reset Errors State ...
void ResetState()
{
//
// Reset Errors ...
mError = -1;
mResponse = "";
ResetLastError();
}
//
// Generate Full File Path ...
string GetFilePath(string fileName)
{
//
string result = "";
//
result =
//
Path() + "\\" + fileName
//
;
//
return result;
}
};
//
// Tools ...
//
// Convert enum to String ...
string ToString(X_HTTP_METHOD method)
{
//
string result = "";
//
switch (method)
{
//
case X_HTTP_GET:
result = "GET";
break;
//
case X_HTTP_POST:
result = "POST";
break;
}
//
return result;
}
//
@@ -0,0 +1,441 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCMD5
// Description: Provides MD5 Hashing Requirements ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// START Definitions ...
//
//
static uchar _md5_PADDING[64] =
{
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
//
#define _md5_F(x, y, z) (((x) & (y)) | ((~x) & (z)))
#define _md5_G(x, y, z) (((x) & (z)) | ((y) & (~z)))
#define _md5_H(x, y, z) ((x) ^ (y) ^ (z))
#define _md5_I(x, y, z) ((y) ^ ((x) | (~z)))
#define _md5_ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
//
#define _md5_FF(a, b, c, d, x, s, ac) \
{ \
(a) += _md5_F((b), (c), (d)) + (x) + (uint)(ac); \
(a) = _md5_ROTATE_LEFT((a), (s)); \
(a) += (b); \
}
//
#define _md5_GG(a, b, c, d, x, s, ac) \
{ \
(a) += _md5_G((b), (c), (d)) + (x) + (uint)(ac); \
(a) = _md5_ROTATE_LEFT((a), (s)); \
(a) += (b); \
}
//
#define _md5_HH(a, b, c, d, x, s, ac) \
{ \
(a) += _md5_H((b), (c), (d)) + (x) + (uint)(ac); \
(a) = _md5_ROTATE_LEFT((a), (s)); \
(a) += (b); \
}
//
#define _md5_II(a, b, c, d, x, s, ac) \
{ \
(a) += _md5_I((b), (c), (d)) + (x) + (uint)(ac); \
(a) = _md5_ROTATE_LEFT((a), (s)); \
(a) += (b); \
}
//
#define _md5_INIT_STATE_0 0x67452301
#define _md5_INIT_STATE_1 0xefcdab89
#define _md5_INIT_STATE_2 0x98badcfe
#define _md5_INIT_STATE_3 0x10325476
//
#define _md5_S11 7
#define _md5_S12 12
#define _md5_S13 17
#define _md5_S14 22
//
#define _md5_S21 5
#define _md5_S22 9
#define _md5_S23 14
#define _md5_S24 20
//
#define _md5_S31 4
#define _md5_S32 11
#define _md5_S33 16
#define _md5_S34 23
//
#define _md5_S41 6
#define _md5_S42 10
#define _md5_S43 15
#define _md5_S44 21
//
// END Definitions ...
//
//
// XCMD5 a library for Hashing ...
class XSCMD5
{
//
// Public Provides ...
public:
//
// Protected Provides ...
//
// Constructor ...
XSCMD5(void) {}
//
// Deconstructor ...
~XSCMD5(void) {}
//
// Hash Specified Char Array ...
string Hash(
uchar &mSource[], // Specify Char Array to Hash
int mLength = 0 // Specify Length of Char Array which required to hash
)
{
//
string result = "";
//
int sourceCount = ArraySize(mSource);
//
// Validate Args ...
if (
sourceCount <= 0 ||
(sourceCount > 0 && mLength > sourceCount))
{
return result;
}
//
// Normalize Args ...
if (mLength == 0)
{
mLength = sourceCount;
}
//
// Init MD5 ...
MD5Init();
//
// Update Buffer ...
MD5Update(mSource, mLength);
//
// Calculate Result ...
result = MD5Final();
//
return result;
}
//
// Hash Specified String ...
string Hash(
string mSource // Specified String
)
{
//
string result = "";
//
// Converts String to Char Array ...
uchar bytes[];
StringToCharArray(
mSource,
bytes,
0,
StringLen(mSource));
//
result = Hash(
bytes,
ArraySize(bytes));
//
return result;
}
protected:
//
// Private Provides ...
private:
//
uint m_lMD5[4];
uint m_nCount[2];
uchar m_lpszBuffer[64];
//
// Convert Byte to DWord ...
void ByteToDWord(int &out[], uint &in[], uint len)
{
//
uint i = 0;
uint j = 0;
//
for (; j < len; i++, j += 4)
{
out[i] = (int)in[j] | (int)in[j + 1] << 8 | (int)in[j + 2] << 16 | (int)in[j + 3] << 24;
}
}
//
// Convert DWord to Byte ...
void DWordToByte(uchar &out[], int &in[], uint len)
{
//
uint i = 0;
uint j = 0;
//
for (; j < len; i++, j += 4)
{
//
out[j] = (uchar)(in[i] & 0xff);
out[j + 1] = (uchar)((in[i] >> 8) & 0xff);
out[j + 2] = (uchar)((in[i] >> 16) & 0xff);
out[j + 3] = (uchar)((in[i] >> 24) & 0xff);
}
}
//
// Init MD5 Array ...
void MD5Init()
{
//
ArrayInitialize(m_lpszBuffer, 64);
//
m_nCount[0] = m_nCount[1] = 0;
m_lMD5[0] = _md5_INIT_STATE_0;
m_lMD5[1] = _md5_INIT_STATE_1;
m_lMD5[2] = _md5_INIT_STATE_2;
m_lMD5[3] = _md5_INIT_STATE_3;
}
//
// Update MD5 ...
void MD5Update(uchar &inBuf[], uint inLen)
{
//
int i, ii;
int mdi;
//
uint in[16];
int i0 = 0;
//
mdi = (int)((m_nCount[0] >> 3) & 0x3F);
//
if ((m_nCount[0] + ((uint)inLen << 3)) < m_nCount[0])
{
m_nCount[1]++;
}
//
m_nCount[0] += ((uint)inLen << 3);
m_nCount[1] += ((uint)inLen >> 29);
//
while ((inLen--) > 0)
{
//
m_lpszBuffer[mdi++] = inBuf[i0++];
if (mdi == 0x40)
{
//
for (i = 0, ii = 0; i < 16; i++, ii += 4)
{
in[i] = (((uint)m_lpszBuffer[ii + 3]) << 24) | (((uint)m_lpszBuffer[ii + 2]) << 16) | (((uint)m_lpszBuffer[ii + 1]) << 8) | ((uint)m_lpszBuffer[ii]);
}
//
Transform(m_lMD5, in);
//
mdi = 0;
}
}
}
//
// Finalize an MD5 Expression ...
string MD5Final()
{
//
uchar bits[8];
int nIndex;
uint nPadLen;
const int nMD5Size = 16;
uchar lpszMD5[16];
string temp;
string out = "";
int i;
//
DWordToByte(bits, m_nCount, 8);
nIndex = (int)((m_nCount[0] >> 3) & 0x3f);
nPadLen = (nIndex < 56) ? (56 - nIndex) : (120 - nIndex);
MD5Update(_md5_PADDING, nPadLen);
MD5Update(bits, 8);
DWordToByte(lpszMD5, m_lMD5, nMD5Size);
//
for (i = 0; i < nMD5Size; i++)
{
//
if (lpszMD5[i] == 0)
{
temp = "00";
}
else if (lpszMD5[i] <= 15)
{
temp = StringFormat("0%x", lpszMD5[i]);
}
else
{
temp = StringFormat("%x", lpszMD5[i]);
}
//
out += temp;
}
//
lpszMD5[0] = '\0';
//
return (out);
}
//
// Transform Buffers ...
void Transform(uint &buf[], uint &in[])
{
//
uint a = buf[0], b = buf[1], c = buf[2], d = buf[3];
//
_md5_FF(a, b, c, d, in[0], _md5_S11, 0xD76AA478);
_md5_FF(d, a, b, c, in[1], _md5_S12, 0xE8C7B756);
_md5_FF(c, d, a, b, in[2], _md5_S13, 0x242070DB);
_md5_FF(b, c, d, a, in[3], _md5_S14, 0xC1BDCEEE);
_md5_FF(a, b, c, d, in[4], _md5_S11, 0xF57C0FAF);
_md5_FF(d, a, b, c, in[5], _md5_S12, 0x4787C62A);
_md5_FF(c, d, a, b, in[6], _md5_S13, 0xA8304613);
_md5_FF(b, c, d, a, in[7], _md5_S14, 0xFD469501);
_md5_FF(a, b, c, d, in[8], _md5_S11, 0x698098D8);
_md5_FF(d, a, b, c, in[9], _md5_S12, 0x8B44F7AF);
_md5_FF(c, d, a, b, in[10], _md5_S13, 0xFFFF5BB1);
_md5_FF(b, c, d, a, in[11], _md5_S14, 0x895CD7BE);
_md5_FF(a, b, c, d, in[12], _md5_S11, 0x6B901122);
_md5_FF(d, a, b, c, in[13], _md5_S12, 0xFD987193);
_md5_FF(c, d, a, b, in[14], _md5_S13, 0xA679438E);
_md5_FF(b, c, d, a, in[15], _md5_S14, 0x49B40821);
//
_md5_GG(a, b, c, d, in[1], _md5_S21, 0xF61E2562);
_md5_GG(d, a, b, c, in[6], _md5_S22, 0xC040B340);
_md5_GG(c, d, a, b, in[11], _md5_S23, 0x265E5A51);
_md5_GG(b, c, d, a, in[0], _md5_S24, 0xE9B6C7AA);
_md5_GG(a, b, c, d, in[5], _md5_S21, 0xD62F105D);
_md5_GG(d, a, b, c, in[10], _md5_S22, 0x02441453);
_md5_GG(c, d, a, b, in[15], _md5_S23, 0xD8A1E681);
_md5_GG(b, c, d, a, in[4], _md5_S24, 0xE7D3FBC8);
_md5_GG(a, b, c, d, in[9], _md5_S21, 0x21E1CDE6);
_md5_GG(d, a, b, c, in[14], _md5_S22, 0xC33707D6);
_md5_GG(c, d, a, b, in[3], _md5_S23, 0xF4D50D87);
_md5_GG(b, c, d, a, in[8], _md5_S24, 0x455A14ED);
_md5_GG(a, b, c, d, in[13], _md5_S21, 0xA9E3E905);
_md5_GG(d, a, b, c, in[2], _md5_S22, 0xFCEFA3F8);
_md5_GG(c, d, a, b, in[7], _md5_S23, 0x676F02D9);
_md5_GG(b, c, d, a, in[12], _md5_S24, 0x8D2A4C8A);
//
_md5_HH(a, b, c, d, in[5], _md5_S31, 0xFFFA3942);
_md5_HH(d, a, b, c, in[8], _md5_S32, 0x8771F681);
_md5_HH(c, d, a, b, in[11], _md5_S33, 0x6D9D6122);
_md5_HH(b, c, d, a, in[14], _md5_S34, 0xFDE5380C);
_md5_HH(a, b, c, d, in[1], _md5_S31, 0xA4BEEA44);
_md5_HH(d, a, b, c, in[4], _md5_S32, 0x4BDECFA9);
_md5_HH(c, d, a, b, in[7], _md5_S33, 0xF6BB4B60);
_md5_HH(b, c, d, a, in[10], _md5_S34, 0xBEBFBC70);
_md5_HH(a, b, c, d, in[13], _md5_S31, 0x289B7EC6);
_md5_HH(d, a, b, c, in[0], _md5_S32, 0xEAA127FA);
_md5_HH(c, d, a, b, in[3], _md5_S33, 0xD4EF3085);
_md5_HH(b, c, d, a, in[6], _md5_S34, 0x04881D05);
_md5_HH(a, b, c, d, in[9], _md5_S31, 0xD9D4D039);
_md5_HH(d, a, b, c, in[12], _md5_S32, 0xE6DB99E5);
_md5_HH(c, d, a, b, in[15], _md5_S33, 0x1FA27CF8);
_md5_HH(b, c, d, a, in[2], _md5_S34, 0xC4AC5665);
//
_md5_II(a, b, c, d, in[0], _md5_S41, 0xF4292244);
_md5_II(d, a, b, c, in[7], _md5_S42, 0x432AFF97);
_md5_II(c, d, a, b, in[14], _md5_S43, 0xAB9423A7);
_md5_II(b, c, d, a, in[5], _md5_S44, 0xFC93A039);
_md5_II(a, b, c, d, in[12], _md5_S41, 0x655B59C3);
_md5_II(d, a, b, c, in[3], _md5_S42, 0x8F0CCC92);
_md5_II(c, d, a, b, in[10], _md5_S43, 0xFFEFF47D);
_md5_II(b, c, d, a, in[1], _md5_S44, 0x85845DD1);
_md5_II(a, b, c, d, in[8], _md5_S41, 0x6FA87E4F);
_md5_II(d, a, b, c, in[15], _md5_S42, 0xFE2CE6E0);
_md5_II(c, d, a, b, in[6], _md5_S43, 0xA3014314);
_md5_II(b, c, d, a, in[13], _md5_S44, 0x4E0811A1);
_md5_II(a, b, c, d, in[4], _md5_S41, 0xF7537E82);
_md5_II(d, a, b, c, in[11], _md5_S42, 0xBD3AF235);
_md5_II(c, d, a, b, in[2], _md5_S43, 0x2AD7D2BB);
_md5_II(b, c, d, a, in[9], _md5_S44, 0xEB86D391);
//
buf[0] += a;
buf[1] += b;
buf[2] += c;
buf[3] += d;
}
};
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,79 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCZone
// Description: provides all Zone requirements ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// Imports ...
#include <Arrays/ArrayObj.mqh>
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Specific Zone ...
class XSCZone : public CObject
{
//
// Public ...
public:
//
// Props ...
double high;
double low;
int ticks;
double percent;
//
ENUM_TIMEFRAMES period;
datetime start;
datetime end;
//
// Compare Two Zone With Each Other ...
virtual int Compare(
const CObject *node,
const int mode = 0 //
) const
{
//
const XSCZone *other = (XSCZone *)node;
//
return other.ticks - ticks;
}
//
// Props ...
string GetTag() {
//
string result = "";
//
result = "XZ_" + ToString(period) + "_" + ToString(start);
//
return result;
}
//
// Protected ...
protected:
//
// Private ...
private:
};
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,245 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXCCHelper
// Description: provides all Indicator
// Helper requirements ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// Imports ...
#include "../Classes/x-saherelm.xhelper.class.mq5"
//
// Definitions ...
//
// Input Models ...
struct XCCInputs
{
//
// Props ...
//
// Chart Style ...
ENUM_CHART_MODE mode; // Mode
color upColor; // Up Color
color downColor; // Down Color
color lineColor; // Line mode and Doji candlestick Color
color bearishColor; // Bullish Color
color bullishColor; // Bearish Color
color volumesColor; // Volumes Color
//
// Presentation ...
bool showCandles; // Show Candles
//
// Constructor(s) ...
XCCInputs()
{
//
Clean();
}
//
// Tools ...
//
// Clean ...
void Clean()
{
//
mode = CHART_CANDLES;
//
upColor = CLR_NONE;
downColor = CLR_NONE;
lineColor = CLR_NONE;
bearishColor = CLR_NONE;
bullishColor = CLR_NONE;
volumesColor = CLR_NONE;
//
showCandles = false;
}
//
// Default ...
void Default()
{
//
mode = CHART_CANDLES;
//
upColor = clrLime;
downColor = clrRed;
lineColor = clrLime;
bearishColor = clrRed;
bullishColor = clrLime;
volumesColor = clrGreen;
//
showCandles = true;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
true
//
;
//
return result;
}
//
// Retrieve MAx Length ...
int Max()
{
//
int result = 0;
//
result = MathMax(0, 0);
//
return result;
}
};
//
// Class ...
class XSCXCCHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XSCXCCHelper() : XSCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCXCCHelper() {}
//
// Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
XCCInputs &inputs // Inputs
)
{
//
bool result = false;
//
mSymbol = symbol;
mPeriod = period;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
mInputs = inputs;
//
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.xcc",
//
// Inputs ...
//
// Chart Style ...
"",
mInputs.mode, // Mode
mInputs.upColor, // Up Color
mInputs.downColor, // Down Color
mInputs.lineColor, // Line mode and Doji candlestick Color
mInputs.bearishColor, // Bullish Color
mInputs.bullishColor, // Bearish Color
mInputs.volumesColor, // Volumes Color
//
// Presentation ...
"",
mInputs.showCandles // Show Candles
//
);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Inputs ...
//
XCCInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
XCCInputs &inputs // Configs
)
{
//
return Init(
mSymbol,
mPeriod,
inputs
//
);
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
XCCInputs mInputs; // Inputs ...
};
//
// Tools ...
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,220 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXCTHelper
// Description: provides all Indicator
// Helper requirements ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// Imports ...
#include "../Classes/x-saherelm.xhelper.class.mq5"
//
// Definitions ...
//
// Input Models ...
struct XCTInputs
{
//
// Props ...
//
color clr; // Text Color
ENUM_BASE_CORNER corner; // Text Position
//
// Presentation ...
bool showCandleTime; // Show Candle Time
//
// Constructor(s) ...
XCTInputs()
{
//
Clean();
}
//
// Tools ...
//
// Clean ...
void Clean()
{
//
clr = CLR_NONE;
corner = CORNER_RIGHT_LOWER;
//
// Presentation ...
showCandleTime = false;
}
//
// Default ...
void Default()
{
//
clr = clrYellow;
corner = CORNER_RIGHT_LOWER;
//
// Presentation ...
showCandleTime = true;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
true
//
;
//
return result;
}
//
// Retrieve MAx Length ...
int Max()
{
//
int result = 0;
//
result = MathMax(0, 0);
//
return result;
}
};
//
// Class ...
class XSCXCTHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XSCXCTHelper() : XSCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCXCTHelper() {}
//
// Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
XCTInputs &inputs // Inputs
)
{
//
bool result = false;
//
mSymbol = symbol;
mPeriod = period;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
mInputs = inputs;
//
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.xct",
//
// Inputs ...
mInputs.clr, // Text Color
mInputs.corner, // Text Position
//
// Presentation ...
"",
mInputs.showCandleTime // Show Candle Time
//
);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Inputs ...
//
XCTInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
XCTInputs &inputs // Configs
)
{
//
return Init(
mSymbol,
mPeriod,
inputs
//
);
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
XCTInputs mInputs; // Inputs ...
};
//
// Tools ...
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,237 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// ---------------------------------------------
// Name: XCTime
// Description: Timing Indicator ...
//
//
// 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 XCTime Indicator"
#property strict
//
// START Constants ...
//
//
#define ShortName "XCTime"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Constants ...
//
//
// START Inputs ...
//
//
input color clr = clrYellow; // Text Color
input ENUM_BASE_CORNER corner = CORNER_LEFT_LOWER; // Text Position
//
input group "Presentation";
input bool showTime = true; // Show Time
//
// END Inputs ...
//
//
// START Buffers ...
//
//
#property indicator_chart_window
//
#property indicator_buffers 0
#property indicator_plots 0
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (showTime)
{
CreateIndicatorObject();
}
else
{
ObjectDelete(0, ShortName);
}
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// 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
//
ulong chID = FindChartID(
_Symbol,
_Period
//
);
//
// Delete Object ...
ObjectDelete(chID, ShortName);
//
Comment("");
}
//
// Calculating what we want ...
int OnCalculate(
const int rates_total, // Total Bars on Chart ...
const int prev_calculated, // Total Calculated Bars on Charts ...
const datetime &time[], // History of Open Time ...
const double &open[], // History of Open Price ...
const double &high[], // History of High Price ...
const double &low[], // History of Low Price ...
const double &close[], // History of Close Price ...
const long &tick_volume[], // History of Tick Volumes on Bar ...
const long &volume[], // History of Trade Volumes ...
const int &spread[] // History of Spread Price ...
)
{
//
ArraySetAsSeries(time, true);
//
if (!showTime)
{
return rates_total;
}
//
ulong chID = FindChartID(
_Symbol,
_Period
//
);
//s
int offset = TimeGMTOffset();
string timeString =
"Local: " + string(TimeLocal()) +
", Server: " + string(TimeTradeServer());
timeString = timeString;
//
string objText = timeString;
//
ObjectSetInteger(chID, ShortName, OBJPROP_COLOR, clr);
ObjectSetString(chID, ShortName, OBJPROP_TEXT, objText);
ObjectSetInteger(chID, ShortName, OBJPROP_FONTSIZE, 10);
ObjectSetString(chID, ShortName, OBJPROP_FONT, "Arial");
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
void CreateIndicatorObject()
{
//
if (!showTime)
{
return;
}
//
ObjectCreate(0, ShortName, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, ShortName, OBJPROP_CORNER, corner);
ObjectSetInteger(0, ShortName, OBJPROP_XDISTANCE, 10);
ObjectSetInteger(0, ShortName, OBJPROP_YDISTANCE, 2);
//
ENUM_ANCHOR_POINT Anchor = ANCHOR_LEFT_UPPER;
switch (corner)
{
case CORNER_LEFT_UPPER:
Anchor = ANCHOR_LEFT_UPPER;
break;
case CORNER_RIGHT_UPPER:
Anchor = ANCHOR_RIGHT_UPPER;
break;
case CORNER_LEFT_LOWER:
Anchor = ANCHOR_LEFT_LOWER;
break;
case CORNER_RIGHT_LOWER:
Anchor = ANCHOR_RIGHT_LOWER;
break;
}
//
ObjectSetInteger(0, ShortName, OBJPROP_ANCHOR, Anchor);
}
//
// END Functions ...
//
@@ -0,0 +1,437 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Candle Styles
// ---------------------------------------------------
// Name: XCC
// Description: Candle Styles ...
//
//
// 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 XCC Indicator"
#property strict
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "XCC"
//
// Holds an SnapShot of Charts Configuration ...
struct XChartStyle
{
//
// chart's ID ...
long chartId;
//
// chart's mode ...
ENUM_CHART_MODE mode;
//
// show bid line ...
bool showBidLine;
//
// show ask line ...
bool showAskLine;
//
// show grids on chart ...
bool showGrid;
//
// show volumes ...
bool showVolumes;
//
// Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders) ...
bool showTradeLevels;
//
// chart autoscroll ...
bool autoScroll;
//
// chart quick navigation state ...
bool quickNavigation;
//
// chart's foreground color ...
color foreGroundColor;
//
// chart's background color ...
color backGroundColor;
//
// Up Color ...
color upColor;
//
// Down Color ...
color downColor;
//
// Bullish color ...
color bullishColor;
//
// Bearish color ...
color bearishColor;
//
// grid color ...
color gridColor;
//
// bid line color ...
color bidLineColor;
//
// ask line color ...
color askLineColor;
//
// line mode and doji candlestick color ...
color lineColor;
//
// Color of stop order levels (Stop Loss and Take Profit) ...
color stopColor;
//
// volumes color ...
color volumesColor;
};
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Chart Style";
input ENUM_CHART_MODE mode = CHART_CANDLES; // Mode
input color upColor = clrLime; // Up Color
input color downColor = clrRed; // Down Color
input color lineColor = clrLime; // Line mode and Doji candlestick Color
input color bearishColor = clrRed; // Bullish Color
input color bullishColor = clrLime; // Bearish Color
input color volumesColor = clrGreen; // Volumes Color
//
input group "Presentation";
input bool showCandles = true; // Show Candles
//
// END Inputs ...
//
//
// START Includes and Imports ...
//
//
// Includes Draw Library ...
#include "../Libraries/x-saherelm.draw.lib.mq5"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes and Imports ...
//
//
// START Buffers ...
//
//
#property indicator_chart_window
//
#property indicator_buffers 0
#property indicator_plots 0
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
XChartStyle chartStyle;
XChartStyle clearStyle;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
drawPrefix = ShortName;
//
// 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();
//
// Apply Chart Style ...
ApplyCustomChartStyle();
//
// 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
}
//
// Calculating what we want ...
int OnCalculate(
const int rates_total, // Total Bars on Chart ...
const int prev_calculated, // Total Calculated Bars on Charts ...
const datetime &time[], // History of Open Time ...
const double &open[], // History of Open Price ...
const double &high[], // History of High Price ...
const double &low[], // History of Low Price ...
const double &close[], // History of Close Price ...
const long &tick_volume[], // History of Tick Volumes on Bar ...
const long &volume[], // History of Trade Volumes ...
const int &spread[] // History of Spread Price ...
)
{
//
// 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);
//
// this counts Available Bars ...
int limit;
//
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);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = true;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index // Selected Bar Index
)
{
}
//
// Apply Custom Chart Style ...
void ApplyCustomChartStyle()
{
//
// Read Current Chart Config and Store it ...
ReadChartStyle();
//
// After Reading Current Chart Style ...
// we have to Save Configs and Change Styles ...
clearStyle = chartStyle;
//
clearStyle.upColor = CLR_NONE;
clearStyle.downColor = CLR_NONE;
clearStyle.lineColor = CLR_NONE;
clearStyle.bullishColor = CLR_NONE;
clearStyle.bearishColor = CLR_NONE;
//
// Decide to Show or not Candles based on User Input ...
if (showCandles)
{
SetChartStyle(chartStyle);
}
else
{
SetChartStyle(clearStyle);
}
}
//
// Read Previous Chart Style ...
void ReadChartStyle()
{
//
// Retrieve Current Chart ID ...
long chartId = ChartID();
chartStyle.chartId = chartId;
//
// Retrieve Chart Mode ...
chartStyle.mode = (ENUM_CHART_MODE)ChartGetInteger(chartId, CHART_MODE);
//
chartStyle.showBidLine = (bool)ChartGetInteger(chartId, CHART_SHOW_BID_LINE);
chartStyle.showAskLine = (bool)ChartGetInteger(chartId, CHART_SHOW_ASK_LINE);
chartStyle.showGrid = (bool)ChartGetInteger(chartId, CHART_SHOW_GRID);
chartStyle.showVolumes = (bool)ChartGetInteger(chartId, CHART_SHOW_VOLUMES);
chartStyle.showTradeLevels = (bool)ChartGetInteger(chartId, CHART_SHOW_TRADE_LEVELS);
chartStyle.autoScroll = (bool)ChartGetInteger(chartId, CHART_AUTOSCROLL);
chartStyle.quickNavigation = (bool)ChartGetInteger(chartId, CHART_QUICK_NAVIGATION);
//
chartStyle.foreGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_FOREGROUND);
chartStyle.backGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_BACKGROUND);
chartStyle.upColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_UP);
chartStyle.downColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_DOWN);
chartStyle.bullishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BULL);
chartStyle.bearishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BEAR);
chartStyle.gridColor = (color)ChartGetInteger(chartId, CHART_COLOR_GRID);
chartStyle.bidLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_BID);
chartStyle.askLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_ASK);
chartStyle.stopColor = (color)ChartGetInteger(chartId, CHART_COLOR_STOP_LEVEL);
chartStyle.lineColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_LINE);
chartStyle.volumesColor = (color)ChartGetInteger(chartId, CHART_COLOR_VOLUME);
//
chartStyle.mode = mode;
chartStyle.upColor = upColor;
chartStyle.downColor = downColor;
chartStyle.lineColor = lineColor;
chartStyle.bearishColor = bearishColor;
chartStyle.bullishColor = bullishColor;
chartStyle.volumesColor = volumesColor;
}
//
// Set Chart Style ...
void SetChartStyle(
XChartStyle &mChartStyle // Chart Style to Apply
)
{
//
ApplyChartStyle(
mChartStyle.chartId,
mChartStyle.mode,
mChartStyle.showBidLine,
mChartStyle.showAskLine,
mChartStyle.showGrid,
mChartStyle.showVolumes,
mChartStyle.showTradeLevels,
mChartStyle.autoScroll,
mChartStyle.quickNavigation,
mChartStyle.foreGroundColor,
mChartStyle.backGroundColor,
mChartStyle.upColor,
mChartStyle.downColor,
mChartStyle.bullishColor,
mChartStyle.bearishColor,
mChartStyle.gridColor,
mChartStyle.bidLineColor,
mChartStyle.askLineColor,
mChartStyle.lineColor,
mChartStyle.stopColor,
mChartStyle.volumesColor);
}
//
// END Functions ...
//
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,993 @@
///////////////////////////////////////////////////////
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------
// Name: XCHSwings
// Description: XCHSwings Detector ...
//
// 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 XCHVWAP Indicator"
#property strict
//
#define ShortName "XCHVWAP"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
input int length = 12; // Length
//
input group "Cycles";
//
input group "Short";
input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period
//
input group "Medium";
input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period
//
input group "Long";
input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period
//
input group "Hind";
input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period
//
// Presentation ...
input group "Presentation";
//
input bool showSwingHighs = true; // Show Swing Highs
input bool showSwingLows = true; // Show Swing Lows
//
input bool showCurrent = true; // Show Cycle Cycle
input bool showShort = true; // Show Short Cycle
input bool showMedium = true; // Show Medium Cycle
input bool showLong = true; // Show Long Cycle
input bool showHind = true; // Show Hind Cycle
//
#property indicator_chart_window
//
#property indicator_buffers 10
#property indicator_plots 10
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
//
// Current ...
//
#define cSHBufferIndex 0
double cSHBuffer[];
//
#property indicator_label1 "XCHVSwings CH"
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrMagenta
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
//
#define cSLBufferIndex 1
double cSLBuffer[];
//
#property indicator_label2 "XCHVSwings CL"
#property indicator_type2 DRAW_ARROW
#property indicator_color2 clrAqua
#property indicator_style2 STYLE_SOLID
#property indicator_width2 2
//
// Short ...
//
#define sSHBufferIndex 2
double sSHBuffer[];
//
#property indicator_label3 "XCHVSwings SH"
#property indicator_type3 DRAW_ARROW
#property indicator_color3 clrMagenta
#property indicator_style3 STYLE_SOLID
#property indicator_width3 2
//
#define sSLBufferIndex 3
double sSLBuffer[];
//
#property indicator_label4 "XCHVSwings SL"
#property indicator_type4 DRAW_ARROW
#property indicator_color4 clrAqua
#property indicator_style4 STYLE_SOLID
#property indicator_width4 2
//
// Medium ...
//
#define mSHBufferIndex 4
double mSHBuffer[];
//
#property indicator_label5 "XCHVSwings MH"
#property indicator_type5 DRAW_ARROW
#property indicator_color5 clrMagenta
#property indicator_style5 STYLE_SOLID
#property indicator_width5 2
//
#define mSLBufferIndex 5
double mSLBuffer[];
//
#property indicator_label6 "XCHVSwings ML"
#property indicator_type6 DRAW_ARROW
#property indicator_color6 clrAqua
#property indicator_style6 STYLE_SOLID
#property indicator_width6 2
//
// Long ...
//
#define lSHBufferIndex 6
double lSHBuffer[];
//
#property indicator_label7 "XCHVSwings LH"
#property indicator_type7 DRAW_ARROW
#property indicator_color7 clrMagenta
#property indicator_style7 STYLE_SOLID
#property indicator_width7 2
//
#define lSLBufferIndex 7
double lSLBuffer[];
//
#property indicator_label8 "XCHVSwings LL"
#property indicator_type8 DRAW_ARROW
#property indicator_color8 clrAqua
#property indicator_style8 STYLE_SOLID
#property indicator_width8 2
//
// Hind ...
//
#define hSHBufferIndex 8
double hSHBuffer[];
//
#property indicator_label9 "XCHVSwings HH"
#property indicator_type9 DRAW_ARROW
#property indicator_color9 clrMagenta
#property indicator_style9 STYLE_SOLID
#property indicator_width9 2
//
#define hSLBufferIndex 9
double hSLBuffer[];
//
#property indicator_label10 "XCHVSwings HL"
#property indicator_type10 DRAW_ARROW
#property indicator_color10 clrAqua
#property indicator_style10 STYLE_SOLID
#property indicator_width10 2
//
// Variables ...
//
int maxLength;
//
// Cuurent ...
int mCMarketLength = length;
//
double cH1 = 0;
double cL1 = 0;
datetime cH1Time = 0;
datetime cL1Time = 0;
//
// Short ...
int mSCycleLength = 0;
int mSMarketLength = 0;
ENUM_TIMEFRAMES mSCPeriod = NULL;
//
double sH1 = 0;
double sL1 = 0;
datetime sH1Time = 0;
datetime sL1Time = 0;
//
// Medium ...
int mMCycleLength = 0;
int mMMarketLength = 0;
ENUM_TIMEFRAMES mMCPeriod = NULL;
//
double mH1 = 0;
double mL1 = 0;
datetime mH1Time = 0;
datetime mL1Time = 0;
//
// Long ...
int mLCycleLength = 0;
int mLMarketLength = 0;
ENUM_TIMEFRAMES mLCPeriod = NULL;
//
double lH1 = 0;
double lL1 = 0;
datetime lH1Time = 0;
datetime lL1Time = 0;
//
// Hind ...
int mHCycleLength = 0;
int mHMarketLength = 0;
ENUM_TIMEFRAMES mHCPeriod = NULL;
//
double hH1 = 0;
double hL1 = 0;
datetime hH1Time = 0;
datetime hL1Time = 0;
//
// Event Handlers ...
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
if (!InitMarketCycles())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// 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;
}
//
// 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
}
//
// Calculating what we want ...
int OnCalculate(
const int rates_total, // Total Bars on Chart ...
const int prev_calculated, // Total Calculated Bars on Charts ...
const datetime &time[], // History of Open Time ...
const double &open[], // History of Open Price ...
const double &high[], // History of High Price ...
const double &low[], // History of Low Price ...
const double &close[], // History of Close Price ...
const long &tick_volume[], // History of Tick Volumes on Bar ...
const long &volume[], // History of Trade Volumes ...
const int &spread[] // History of Spread Price ...
)
{
//
int start;
//
if (prev_calculated == 0)
{
start = maxLength;
}
else
{
start = prev_calculated - 1;
}
//
for (int i = start; i < rates_total - maxLength && !IsStopped(); i++)
{
//
CalculateBuffers(
i,
prev_calculated,
rates_total,
//
time,
open,
high,
close,
low,
tick_volume //
);
}
//
return rates_total;
}
//
// Functions ...
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
result =
//
length >= 2 &&
//
(IsValid(scMethod, scPeriod) &&
IsValid(mcMethod, mcPeriod) &&
IsValid(lcMethod, lcPeriod) &&
IsValid(hcMethod, hcPeriod))
//
;
//
return result;
}
//
// Initialize Market Cycles ...
bool InitMarketCycles()
{
//
bool result = false;
//
// Current Cycle Initialization ...
//
int cPeriodSeconds = PeriodSeconds(_Period);
//
// Short Cycle Initialization ...
//
// Find Cycle Period ...
if (scMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mSCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_SHORT,
_Period //
);
}
else
{
mSCPeriod = scPeriod;
}
//
result = IsValid(mSCPeriod);
if (!result)
{
return result;
}
//
mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds;
mSMarketLength = mSCycleLength * mCMarketLength;
result = mSCycleLength > 0;
if (!result)
{
return result;
}
//
// Medium Cycle Initialization ...
//
// Find Cycle Period ...
if (mcMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mMCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_MEDIUM,
_Period //
);
}
else
{
mMCPeriod = mcPeriod;
}
//
result = IsValid(mMCPeriod);
if (!result)
{
return result;
}
//
mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds;
mMMarketLength = mMCycleLength * mCMarketLength;
result = mMCycleLength > 0;
if (!result)
{
return result;
}
//
// Long Cycle Initialization ...
//
// Find Cycle Period ...
if (lcMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mLCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_LONG,
_Period //
);
}
else
{
mLCPeriod = lcPeriod;
}
//
result = IsValid(mLCPeriod);
if (!result)
{
return result;
}
//
mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds;
mLMarketLength = mLCycleLength * mCMarketLength;
result = mLCycleLength > 0;
if (!result)
{
return result;
}
//
// Hind Cycle Initialization ...
//
// Find Cycle Period ...
if (hcMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mHCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_HIND,
_Period //
);
}
else
{
mHCPeriod = hcPeriod;
}
//
result = IsValid(mHCPeriod);
if (!result)
{
return result;
}
//
mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds;
mHMarketLength = mHCycleLength * mCMarketLength;
result = mHCycleLength > 0;
if (!result)
{
return result;
}
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(mCMarketLength, mSMarketLength);
result = MathMax(result, mMMarketLength);
result = MathMax(result, mLMarketLength);
result = MathMax(result, mHMarketLength);
//
return result;
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
// Setting Indicator Digits
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// Current ...
//
ENUM_DRAW_TYPE cSHDrawType =
showCurrent && showSwingHighs
? DRAW_ARROW
: DRAW_NONE;
//
SetIndexBuffer(cSHBufferIndex, cSHBuffer, INDICATOR_DATA);
PlotIndexSetDouble(cSHBufferIndex, PLOT_EMPTY_VALUE, 0);
PlotIndexSetInteger(cSHBufferIndex, PLOT_ARROW, 234);
PlotIndexSetInteger(cSHBufferIndex, PLOT_SHOW_DATA, showCurrent && showSwingHighs);
PlotIndexSetInteger(cSHBufferIndex, PLOT_DRAW_TYPE, cSHDrawType);
//
ENUM_DRAW_TYPE cSLDrawType =
showCurrent && showSwingLows
? DRAW_ARROW
: DRAW_NONE;
//
SetIndexBuffer(cSLBufferIndex, cSLBuffer, INDICATOR_DATA);
PlotIndexSetDouble(cSLBufferIndex, PLOT_EMPTY_VALUE, 0);
PlotIndexSetInteger(cSLBufferIndex, PLOT_ARROW, 233);
PlotIndexSetInteger(cSLBufferIndex, PLOT_SHOW_DATA, showCurrent && showSwingLows);
PlotIndexSetInteger(cSLBufferIndex, PLOT_DRAW_TYPE, cSLDrawType);
//
// Short ...
//
ENUM_DRAW_TYPE sSHDrawType =
showShort && showSwingHighs
? DRAW_ARROW
: DRAW_NONE;
//
SetIndexBuffer(sSHBufferIndex, sSHBuffer, INDICATOR_DATA);
PlotIndexSetDouble(sSHBufferIndex, PLOT_EMPTY_VALUE, 0);
PlotIndexSetInteger(sSHBufferIndex, PLOT_ARROW, 234);
PlotIndexSetInteger(sSHBufferIndex, PLOT_SHOW_DATA, showShort && showSwingHighs);
PlotIndexSetInteger(sSHBufferIndex, PLOT_DRAW_TYPE, sSHDrawType);
//
ENUM_DRAW_TYPE sSLDrawType =
showShort && showSwingLows
? DRAW_ARROW
: DRAW_NONE;
//
SetIndexBuffer(sSLBufferIndex, sSLBuffer, INDICATOR_DATA);
PlotIndexSetDouble(sSLBufferIndex, PLOT_EMPTY_VALUE, 0);
PlotIndexSetInteger(sSLBufferIndex, PLOT_ARROW, 233);
PlotIndexSetInteger(sSLBufferIndex, PLOT_SHOW_DATA, showShort && showSwingLows);
PlotIndexSetInteger(sSLBufferIndex, PLOT_DRAW_TYPE, sSLDrawType);
//
// Medium ...
//
ENUM_DRAW_TYPE mSHDrawType =
showMedium && showSwingHighs
? DRAW_ARROW
: DRAW_NONE;
//
SetIndexBuffer(mSHBufferIndex, mSHBuffer, INDICATOR_DATA);
PlotIndexSetDouble(mSHBufferIndex, PLOT_EMPTY_VALUE, 0);
PlotIndexSetInteger(mSHBufferIndex, PLOT_ARROW, 234);
PlotIndexSetInteger(mSHBufferIndex, PLOT_SHOW_DATA, showMedium && showSwingHighs);
PlotIndexSetInteger(mSHBufferIndex, PLOT_DRAW_TYPE, mSHDrawType);
//
ENUM_DRAW_TYPE mSLDrawType =
showMedium && showSwingLows
? DRAW_ARROW
: DRAW_NONE;
//
SetIndexBuffer(mSLBufferIndex, mSLBuffer, INDICATOR_DATA);
PlotIndexSetDouble(mSLBufferIndex, PLOT_EMPTY_VALUE, 0);
PlotIndexSetInteger(mSLBufferIndex, PLOT_ARROW, 233);
PlotIndexSetInteger(mSLBufferIndex, PLOT_SHOW_DATA, showMedium && showSwingLows);
PlotIndexSetInteger(mSLBufferIndex, PLOT_DRAW_TYPE, mSLDrawType);
//
// Long ...
//
ENUM_DRAW_TYPE lSHDrawType =
showLong && showSwingHighs
? DRAW_ARROW
: DRAW_NONE;
//
SetIndexBuffer(lSHBufferIndex, lSHBuffer, INDICATOR_DATA);
PlotIndexSetDouble(lSHBufferIndex, PLOT_EMPTY_VALUE, 0);
PlotIndexSetInteger(lSHBufferIndex, PLOT_ARROW, 234);
PlotIndexSetInteger(lSHBufferIndex, PLOT_SHOW_DATA, showLong && showSwingHighs);
PlotIndexSetInteger(lSHBufferIndex, PLOT_DRAW_TYPE, lSHDrawType);
//
ENUM_DRAW_TYPE lSLDrawType =
showLong && showSwingLows
? DRAW_ARROW
: DRAW_NONE;
//
SetIndexBuffer(lSLBufferIndex, lSLBuffer, INDICATOR_DATA);
PlotIndexSetDouble(lSLBufferIndex, PLOT_EMPTY_VALUE, 0);
PlotIndexSetInteger(lSLBufferIndex, PLOT_ARROW, 233);
PlotIndexSetInteger(lSLBufferIndex, PLOT_SHOW_DATA, showLong && showSwingLows);
PlotIndexSetInteger(lSLBufferIndex, PLOT_DRAW_TYPE, lSLDrawType);
//
// Hind ...
//
ENUM_DRAW_TYPE hSHDrawType =
showHind && showSwingHighs
? DRAW_ARROW
: DRAW_NONE;
//
SetIndexBuffer(hSHBufferIndex, hSHBuffer, INDICATOR_DATA);
PlotIndexSetDouble(hSHBufferIndex, PLOT_EMPTY_VALUE, 0);
PlotIndexSetInteger(hSHBufferIndex, PLOT_ARROW, 234);
PlotIndexSetInteger(hSHBufferIndex, PLOT_SHOW_DATA, showHind && showSwingHighs);
PlotIndexSetInteger(hSHBufferIndex, PLOT_DRAW_TYPE, hSHDrawType);
//
ENUM_DRAW_TYPE hSLDrawType =
showHind && showSwingLows
? DRAW_ARROW
: DRAW_NONE;
//
SetIndexBuffer(hSLBufferIndex, hSLBuffer, INDICATOR_DATA);
PlotIndexSetDouble(hSLBufferIndex, PLOT_EMPTY_VALUE, 0);
PlotIndexSetInteger(hSLBufferIndex, PLOT_ARROW, 233);
PlotIndexSetInteger(hSLBufferIndex, PLOT_SHOW_DATA, showHind && showSwingLows);
PlotIndexSetInteger(hSLBufferIndex, PLOT_DRAW_TYPE, hSLDrawType);
}
//
// Calculations ...
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
//
const datetime &time[],
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
CalculateCycles(
//
bar_index,
prevCalculated,
ratesTotal,
//
time,
open,
high,
close,
low,
tickVolume //
);
}
//
void CalculateCycles(
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
//
const datetime &time[],
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
// CURRENT ...
CalculateCycle(
bar_index,
prevCalculated,
ratesTotal,
//
time,
open,
high,
close,
low,
tickVolume,
//
mCMarketLength,
showCurrent,
cSHBuffer,
cSLBuffer,
cH1,
cH1Time,
cL1,
cL1Time //
);
//
// SHORT ...
CalculateCycle(
bar_index,
prevCalculated,
ratesTotal,
//
time,
open,
high,
close,
low,
tickVolume,
//
mSMarketLength,
showShort,
sSHBuffer,
sSLBuffer,
sH1,
sH1Time,
sL1,
sL1Time //
);
//
// MEDIUM ...
CalculateCycle(
bar_index,
prevCalculated,
ratesTotal,
//
time,
open,
high,
close,
low,
tickVolume,
//
mMMarketLength,
showMedium,
mSHBuffer,
mSLBuffer,
mH1,
mH1Time,
mL1,
mL1Time //
);
//
// LONG ...
CalculateCycle(
bar_index,
prevCalculated,
ratesTotal,
//
time,
open,
high,
close,
low,
tickVolume,
//
mLMarketLength,
showLong,
lSHBuffer,
lSLBuffer,
lH1,
lH1Time,
lL1,
lL1Time //
);
//
// HIND ...
CalculateCycle(
bar_index,
prevCalculated,
ratesTotal,
//
time,
open,
high,
close,
low,
tickVolume,
//
mHMarketLength,
showHind,
hSHBuffer,
hSLBuffer,
hH1,
hH1Time,
hL1,
hL1Time //
);
}
//
void CalculateCycle(
//
int bar_index, // Selected Bar Index
const int prevCalculated,
const int ratesTotal,
//
const datetime &time[],
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[],
//
int _length, // Calculation Length
bool _show,
double &_hBuffer[],
double &_lBuffer[],
double &_h1,
datetime &_h1Time,
double &_l1,
datetime &_l1Time //
)
{
//
bool isSwingHigh = true;
bool isSwingLow = true;
//
_hBuffer[bar_index] = 0;
_lBuffer[bar_index] = 0;
//
// Check for Swing High
for (int j = 1; j <= _length; j++)
{
//
if (high[bar_index] <= high[bar_index + j] || high[bar_index] <= high[bar_index - j])
{
//
isSwingHigh = false;
break;
}
}
//
// Check for Swing Low
for (int j = 1; j <= _length; j++)
{
//
if (low[bar_index] >= low[bar_index + j] || low[bar_index] >= low[bar_index - j])
{
//
isSwingLow = false;
break;
}
}
//
if (isSwingHigh)
{
//
_hBuffer[bar_index] = high[bar_index];
if (high[bar_index] > _h1 || _h1 == 0)
{
//
_h1 = high[bar_index];
_h1Time = time[bar_index];
}
}
//
if (isSwingLow)
{
//
_lBuffer[bar_index] = low[bar_index];
if (low[bar_index] < _l1 || _l1 == 0)
{
//
_l1 = low[bar_index];
_l1Time = time[bar_index];
}
}
}
@@ -0,0 +1,900 @@
///////////////////////////////////////////////////////
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------
// Name: XCHTD
// Description: XCHTD Cycles ...
//
// 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 XCHTD Indicator"
#property strict
//
#define ShortName "XCHTD"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
enum ENUM_XCHTD_MODE
{
XCHTD_POWER_MODE = 0, // Using Power
XCHTD_PRESSURE_MODE = 1, // Using Pressure
XCHTD_TYPE_MODE = 2, // Using Type
XCHTD_STRONG_MODE = 3, // Using Power and Pressures
};
//
// Inputs ...
//
input group "Market";
input int length = 14; // Length
input ENUM_XCHTD_MODE mode = XCHTD_POWER_MODE; // Mode
//
input group "Cycles";
//
input group "Short";
input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period
//
input group "Medium";
input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period
//
input group "Long";
input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period
//
input group "Hind";
input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period
//
// Presentation ...
input group "Presentation";
//
// Current ...
input bool showCurrent = true; // Show Current Cycle
input bool showShort = true; // Show Short Cycle
input bool showMedium = true; // Show Medium Cycle
input bool showLong = true; // Show Long Cycle
input bool showHind = true; // Show Hind Cycle
//
// Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 10
#property indicator_plots 0
//
// Current ...
//
#define cBullBufferIndex 0
double cBullBuffer[];
//
#property indicator_label1 "XCHTD C Bull"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrLime
#property indicator_style1 STYLE_SOLID
//
#define cBearBufferIndex 1
double cBearBuffer[];
//
#property indicator_label2 "XCHTD C Bear"
#property indicator_type2 DRAW_LINE
#property indicator_style2 STYLE_SOLID
#property indicator_color2 clrRed
//
// Short ...
//
#define sBullBufferIndex 2
double sBullBuffer[];
//
#property indicator_label3 "XCHTD S Bull"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrLime
#property indicator_style3 STYLE_SOLID
//
#define sBearBufferIndex 3
double sBearBuffer[];
//
#property indicator_label4 "XCHTD S Bear"
#property indicator_type4 DRAW_LINE
#property indicator_style4 STYLE_SOLID
#property indicator_color4 clrRed
//
// Medium ...
//
#define mBullBufferIndex 4
double mBullBuffer[];
//
#property indicator_label5 "XCHTD M Bull"
#property indicator_type5 DRAW_LINE
#property indicator_color5 clrLime
#property indicator_style5 STYLE_SOLID
//
#define mBearBufferIndex 5
double mBearBuffer[];
//
#property indicator_label6 "XCHTD M Bear"
#property indicator_type6 DRAW_LINE
#property indicator_style6 STYLE_SOLID
#property indicator_color6 clrRed
//
// Long ...
//
#define lBullBufferIndex 6
double lBullBuffer[];
//
#property indicator_label7 "XCHTD L Bull"
#property indicator_type7 DRAW_LINE
#property indicator_color7 clrLime
#property indicator_style7 STYLE_SOLID
//
#define lBearBufferIndex 7
double lBearBuffer[];
//
#property indicator_label8 "XCHTD L Bear"
#property indicator_type8 DRAW_LINE
#property indicator_style8 STYLE_SOLID
#property indicator_color8 clrRed
//
// Hind ...
//
#define hBullBufferIndex 8
double hBullBuffer[];
//
#property indicator_label9 "XCHTD H Bull"
#property indicator_type9 DRAW_LINE
#property indicator_color9 clrLime
#property indicator_style9 STYLE_SOLID
//
#define hBearBufferIndex 9
double hBearBuffer[];
//
#property indicator_label10 "XCHTD H Bear"
#property indicator_type10 DRAW_LINE
#property indicator_style10 STYLE_SOLID
#property indicator_color10 clrRed
//
// Variables, Properties and etc ...
//
int maxLength;
//
// Current ...
int mCMarketLength = length;
//
// Short ...
int mSCycleLength = 0;
int mSMarketLength = 0;
ENUM_TIMEFRAMES mSCPeriod = NULL;
//
// Medium ...
int mMCycleLength = 0;
int mMMarketLength = 0;
ENUM_TIMEFRAMES mMCPeriod = NULL;
//
// Long ...
int mLCycleLength = 0;
int mLMarketLength = 0;
ENUM_TIMEFRAMES mLCPeriod = NULL;
//
// Hind ...
int mHCycleLength = 0;
int mHMarketLength = 0;
ENUM_TIMEFRAMES mHCPeriod = NULL;
//
// Event Handlers ...
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
if (!InitMarketCycles())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// 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;
}
//
// 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
}
//
// Calculating what we want ...
int OnCalculate(
const int rates_total, // Total Bars on Chart ...
const int prev_calculated, // Total Calculated Bars on Charts ...
const datetime &time[], // History of Open Time ...
const double &open[], // History of Open Price ...
const double &high[], // History of High Price ...
const double &low[], // History of Low Price ...
const double &close[], // History of Close Price ...
const long &tick_volume[], // History of Tick Volumes on Bar ...
const long &volume[], // History of Trade Volumes ...
const int &spread[] // History of Spread Price ...
)
{
//
// 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);
//
// 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 ...
//
limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated;
//
// Main Loop ...
for (int i = limit; 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 ...
bool ValidateInputs()
{
//
bool result = false;
//
result =
//
length >= 2 &&
//
(IsValid(scMethod, scPeriod) &&
IsValid(mcMethod, mcPeriod) &&
IsValid(lcMethod, lcPeriod) &&
IsValid(hcMethod, hcPeriod))
//
;
//
return result;
}
//
// Initialize Market Cycles ...
bool InitMarketCycles()
{
//
bool result = false;
//
// Current Cycle Initialization ...
//
int cPeriodSeconds = PeriodSeconds(_Period);
//
// Short Cycle Initialization ...
//
// Find Cycle Period ...
if (scMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mSCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_SHORT,
_Period //
);
}
else
{
mSCPeriod = scPeriod;
}
//
result = IsValid(mSCPeriod);
if (!result)
{
return result;
}
//
mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds;
mSMarketLength = mSCycleLength * mCMarketLength;
result = mSCycleLength > 0;
if (!result)
{
return result;
}
//
// Medium Cycle Initialization ...
//
// Find Cycle Period ...
if (mcMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mMCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_MEDIUM,
_Period //
);
}
else
{
mMCPeriod = mcPeriod;
}
//
result = IsValid(mMCPeriod);
if (!result)
{
return result;
}
//
mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds;
mMMarketLength = mMCycleLength * mCMarketLength;
result = mMCycleLength > 0;
if (!result)
{
return result;
}
//
// Long Cycle Initialization ...
//
// Find Cycle Period ...
if (lcMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mLCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_LONG,
_Period //
);
}
else
{
mLCPeriod = lcPeriod;
}
//
result = IsValid(mLCPeriod);
if (!result)
{
return result;
}
//
mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds;
mLMarketLength = mLCycleLength * mCMarketLength;
result = mLCycleLength > 0;
if (!result)
{
return result;
}
//
// Hind Cycle Initialization ...
//
// Find Cycle Period ...
if (hcMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mHCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_HIND,
_Period //
);
}
else
{
mHCPeriod = hcPeriod;
}
//
result = IsValid(mHCPeriod);
if (!result)
{
return result;
}
//
mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds;
mHMarketLength = mHCycleLength * mCMarketLength;
result = mHCycleLength > 0;
if (!result)
{
return result;
}
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(mCMarketLength, mSMarketLength);
result = MathMax(result, mMMarketLength);
result = MathMax(result, mLMarketLength);
result = MathMax(result, mHMarketLength);
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// Current ...
//
// ENUM_DRAW_TYPE cDrawType = showCurrent ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(cBullBuffer, true);
SetIndexBuffer(cBullBufferIndex, cBullBuffer, INDICATOR_CALCULATIONS);
// PlotIndexSetInteger(cBullBufferIndex, PLOT_DRAW_TYPE, cDrawType);
// PlotIndexSetInteger(cBullBufferIndex, PLOT_SHOW_DATA, showCurrent);
//
ArraySetAsSeries(cBearBuffer, true);
SetIndexBuffer(cBearBufferIndex, cBearBuffer, INDICATOR_CALCULATIONS);
// PlotIndexSetInteger(cBearBufferIndex, PLOT_DRAW_TYPE, cDrawType);
// PlotIndexSetInteger(cBearBufferIndex, PLOT_SHOW_DATA, showCurrent);
//
// Short ...
//
// ENUM_DRAW_TYPE sDrawType = showShort ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(sBullBuffer, true);
SetIndexBuffer(sBullBufferIndex, sBullBuffer, INDICATOR_CALCULATIONS);
// PlotIndexSetInteger(sBullBufferIndex, PLOT_DRAW_TYPE, sDrawType);
// PlotIndexSetInteger(sBullBufferIndex, PLOT_SHOW_DATA, showShort);
//
ArraySetAsSeries(sBearBuffer, true);
SetIndexBuffer(sBearBufferIndex, sBearBuffer, INDICATOR_CALCULATIONS);
// PlotIndexSetInteger(sBearBufferIndex, PLOT_DRAW_TYPE, sDrawType);
// PlotIndexSetInteger(sBearBufferIndex, PLOT_SHOW_DATA, showShort);
//
// Medium ...
//
// ENUM_DRAW_TYPE mDrawType = showMedium ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(mBullBuffer, true);
SetIndexBuffer(mBullBufferIndex, mBullBuffer, INDICATOR_CALCULATIONS);
// PlotIndexSetInteger(mBullBufferIndex, PLOT_DRAW_TYPE, mDrawType);
// PlotIndexSetInteger(mBullBufferIndex, PLOT_SHOW_DATA, showMedium);
//
ArraySetAsSeries(mBearBuffer, true);
SetIndexBuffer(mBearBufferIndex, mBearBuffer, INDICATOR_CALCULATIONS);
// PlotIndexSetInteger(mBearBufferIndex, PLOT_DRAW_TYPE, mDrawType);
// PlotIndexSetInteger(mBearBufferIndex, PLOT_SHOW_DATA, showMedium);
//
// Long ...
//
// ENUM_DRAW_TYPE lDrawType = showLong ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(lBullBuffer, true);
SetIndexBuffer(lBullBufferIndex, lBullBuffer, INDICATOR_CALCULATIONS);
// PlotIndexSetInteger(lBullBufferIndex, PLOT_DRAW_TYPE, lDrawType);
// PlotIndexSetInteger(lBullBufferIndex, PLOT_SHOW_DATA, showLong);
//
ArraySetAsSeries(lBearBuffer, true);
SetIndexBuffer(lBearBufferIndex, lBearBuffer, INDICATOR_CALCULATIONS);
// PlotIndexSetInteger(lBearBufferIndex, PLOT_DRAW_TYPE, lDrawType);
// PlotIndexSetInteger(lBearBufferIndex, PLOT_SHOW_DATA, showLong);
//
// Hind ...
//
// ENUM_DRAW_TYPE hDrawType = showHind ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(hBullBuffer, true);
SetIndexBuffer(hBullBufferIndex, hBullBuffer, INDICATOR_CALCULATIONS);
// PlotIndexSetInteger(hBullBufferIndex, PLOT_DRAW_TYPE, hDrawType);
// PlotIndexSetInteger(hBullBufferIndex, PLOT_SHOW_DATA, showHind);
//
ArraySetAsSeries(hBearBuffer, true);
SetIndexBuffer(hBearBufferIndex, hBearBuffer, INDICATOR_CALCULATIONS);
// PlotIndexSetInteger(hBearBufferIndex, PLOT_DRAW_TYPE, hDrawType);
// PlotIndexSetInteger(hBearBufferIndex, PLOT_SHOW_DATA, showHind);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
// Calculations ...
//
// Calculate Buffers ...
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[] //
)
{
//
CalculateCycles(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
}
//
void CalculateCycles(
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[] //
)
{
//
// CURRENT ...
CalculateCycle(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
mCMarketLength,
showCurrent,
cBullBuffer,
cBearBuffer //
);
//
// SHORT ...
CalculateCycle(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
mSMarketLength,
showShort,
sBullBuffer,
sBearBuffer //
);
//
// MEDIUM ...
CalculateCycle(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
mMMarketLength,
showMedium,
mBullBuffer,
mBearBuffer //
);
//
// LONG ...
CalculateCycle(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
mLMarketLength,
showLong,
lBullBuffer,
lBearBuffer //
);
//
// HIND ...
CalculateCycle(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
mHMarketLength,
showHind,
hBullBuffer,
hBearBuffer //
);
}
//
void CalculateCycle(
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 _length, // Calculation Length
bool _show,
double &_bull[],
double &_bear[] //
)
{
//
double bullPower = 0;
double bearPower = 0;
//
double lowShadow = 0;
double highShadow = 0;
//
double bullPressure = 0;
double bearPressure = 0;
//
double bullRange = 0;
double bearRange = 0;
//
for (int i = bar_index; i < bar_index + _length; i++)
{
//
bool isBullish =
//
close[i] > open[i]
//
;
//
bool isBearish =
//
close[i] < open[i]
//
;
//
double iUpper = MathMax(open[i], close[i]);
double iLower = MathMin(open[i], close[i]);
//
double iBody = iUpper - iLower;
double iRange = high[i] - low[i];
//
double iHighShadow = high[i] - iUpper;
double iLowShadow = iLower - low[i];
//
if (isBullish)
{
//
bullPower += iBody;
bullRange += iRange;
bearPressure += iHighShadow;
}
else if (isBearish)
{
//
bearPower += iBody;
bearRange += iRange;
bullPressure += iLowShadow;
}
//
lowShadow += iLowShadow;
highShadow += iHighShadow;
}
//
if (mode == XCHTD_POWER_MODE)
{
//
_bull[bar_index] = bullPower;
_bear[bar_index] = bearPower;
}
else if (mode == XCHTD_PRESSURE_MODE)
{
//
_bull[bar_index] = bullPressure;
_bear[bar_index] = bearPressure;
}
else if (mode == XCHTD_TYPE_MODE)
{
//
_bull[bar_index] = bullRange;
_bear[bar_index] = bearRange;
}
else if (mode == XCHTD_STRONG_MODE)
{
//
_bull[bar_index] = bullPower + bullPressure;
_bear[bar_index] = bearPower + bearPressure;
}
}
//
@@ -0,0 +1,814 @@
///////////////////////////////////////////////////////
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------
// Name: XCHVLM
// Description: XCHVLM Cycles ...
//
// 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 XCHVLM Indicator"
#property strict
//
#define ShortName "XCHVLM"
//
// Includes Common Library ...
#include <Math/Stat/Normal.mqh>
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
input group "Market";
input int length = 14; // Length
//
input group "Cycles";
//
input group "Short";
input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period
//
input group "Medium";
input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period
//
input group "Long";
input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period
//
input group "Hind";
input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period
//
// Presentation ...
input group "Presentation";
//
input bool showCurrent = true; // Show Current Cycle
input bool showShort = true; // Show Short Cycle
input bool showMedium = true; // Show Medium Cycle
input bool showLong = true; // Show Long Cycle
input bool showHind = true; // Show Hind Cycle
//
// Buffers ...
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
//
#property indicator_chart_window
//
#property indicator_buffers 10
#property indicator_plots 0
//
// Current ...
//
#define cBufferIndex 0
double cBuffer[];
//
#define cColorBufferIndex 1
double cColorBuffer[];
//
#define cPlotBufferIndex 0
#property indicator_label1 "XCHVLM C"
#property indicator_style1 STYLE_SOLID
#property indicator_type1 DRAW_COLOR_HISTOGRAM
#property indicator_color1 CLR_NONE, clrLime, clrRed
//
// Short ...
//
#define sBufferIndex 2
double sBuffer[];
//
#define sColorBufferIndex 3
double sColorBuffer[];
//
#define sPlotBufferIndex 1
#property indicator_label2 "XCHVLM S"
#property indicator_style2 STYLE_SOLID
#property indicator_type2 DRAW_COLOR_HISTOGRAM
#property indicator_color2 CLR_NONE, clrLime, clrRed
//
// Medium ...
//
#define mBufferIndex 4
double mBuffer[];
//
#define mColorBufferIndex 5
double mColorBuffer[];
//
#define mPlotBufferIndex 2
#property indicator_label3 "XCHVLM M"
#property indicator_style3 STYLE_SOLID
#property indicator_type3 DRAW_COLOR_HISTOGRAM
#property indicator_color3 CLR_NONE, clrLime, clrRed
//
// Long ...
//
#define lBufferIndex 6
double lBuffer[];
//
#define lColorBufferIndex 7
double lColorBuffer[];
//
#define lPlotBufferIndex 3
#property indicator_label4 "XCHVLM L"
#property indicator_style4 STYLE_SOLID
#property indicator_type4 DRAW_COLOR_HISTOGRAM
#property indicator_color4 CLR_NONE, clrLime, clrRed
//
// Hind ...
//
#define hBufferIndex 8
double hBuffer[];
//
#define hColorBufferIndex 9
double hColorBuffer[];
//
#define hPlotBufferIndex 4
#property indicator_label5 "XCHVLM H"
#property indicator_style5 STYLE_SOLID
#property indicator_type5 DRAW_COLOR_HISTOGRAM
#property indicator_color5 CLR_NONE, clrLime, clrRed
//
// Variables, Properties and etc ...
//
int maxLength;
//
// Current ...
int mCMarketLength = length;
double cVolumes[];
double cDistances[];
//
// Short ...
int mSCycleLength = 0;
int mSMarketLength = 0;
ENUM_TIMEFRAMES mSCPeriod = NULL;
double sVolumes[];
double sDistances[];
//
// Medium ...
int mMCycleLength = 0;
int mMMarketLength = 0;
ENUM_TIMEFRAMES mMCPeriod = NULL;
double mVolumes[];
double mDistances[];
//
// Long ...
int mLCycleLength = 0;
int mLMarketLength = 0;
ENUM_TIMEFRAMES mLCPeriod = NULL;
double lVolumes[];
double lDistances[];
//
// Hind ...
int mHCycleLength = 0;
int mHMarketLength = 0;
ENUM_TIMEFRAMES mHCPeriod = NULL;
double hVolumes[];
double hDistances[];
//
// Event Handlers ...
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
if (!InitMarketCycles())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// 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();
//
// Current ...
ArrayResize(cVolumes, maxLength, 0);
ArrayResize(cDistances, maxLength, 0);
//
// Short ...
ArrayResize(sVolumes, maxLength, 0);
ArrayResize(sDistances, maxLength, 0);
//
// Medium ...
ArrayResize(mVolumes, maxLength, 0);
ArrayResize(mDistances, maxLength, 0);
//
// Long ...
ArrayResize(lVolumes, maxLength, 0);
ArrayResize(lDistances, maxLength, 0);
//
// Hind ...
ArrayResize(hVolumes, maxLength, 0);
ArrayResize(hDistances, maxLength, 0);
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// 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
//
Clean(cVolumes);
Clean(cDistances);
//
Clean(sVolumes);
Clean(sDistances);
//
Clean(mVolumes);
Clean(mDistances);
//
Clean(lVolumes);
Clean(lDistances);
//
Clean(hVolumes);
Clean(hDistances);
}
//
// Calculating what we want ...
int OnCalculate(
const int rates_total, // Total Bars on Chart ...
const int prev_calculated, // Total Calculated Bars on Charts ...
const datetime &time[], // History of Open Time ...
const double &open[], // History of Open Price ...
const double &high[], // History of High Price ...
const double &low[], // History of Low Price ...
const double &close[], // History of Close Price ...
const long &tick_volume[], // History of Tick Volumes on Bar ...
const long &volume[], // History of Trade Volumes ...
const int &spread[] // History of Spread Price ...
)
{
//
static int i = maxLength * 2;
for (i; i < rates_total; i++)
{
//
CalculateBuffers(
i,
prev_calculated,
rates_total,
//
open,
high,
close,
low,
tick_volume //
);
}
//
i = rates_total - 1;
//
return rates_total;
}
//
// Functions ...
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
result =
//
length >= 2 &&
//
(IsValid(scMethod, scPeriod) &&
IsValid(mcMethod, mcPeriod) &&
IsValid(lcMethod, lcPeriod) &&
IsValid(hcMethod, hcPeriod))
//
;
//
return result;
}
//
// Initialize Market Cycles ...
bool InitMarketCycles()
{
//
bool result = false;
//
// Current Cycle Initialization ...
//
int cPeriodSeconds = PeriodSeconds(_Period);
//
// Short Cycle Initialization ...
//
// Find Cycle Period ...
if (scMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mSCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_SHORT,
_Period //
);
}
else
{
mSCPeriod = scPeriod;
}
//
result = IsValid(mSCPeriod);
if (!result)
{
return result;
}
//
mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds;
mSMarketLength = mSCycleLength * mCMarketLength;
result = mSCycleLength > 0;
if (!result)
{
return result;
}
//
// Medium Cycle Initialization ...
//
// Find Cycle Period ...
if (mcMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mMCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_MEDIUM,
_Period //
);
}
else
{
mMCPeriod = mcPeriod;
}
//
result = IsValid(mMCPeriod);
if (!result)
{
return result;
}
//
mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds;
mMMarketLength = mMCycleLength * mCMarketLength;
result = mMCycleLength > 0;
if (!result)
{
return result;
}
//
// Long Cycle Initialization ...
//
// Find Cycle Period ...
if (lcMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mLCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_LONG,
_Period //
);
}
else
{
mLCPeriod = lcPeriod;
}
//
result = IsValid(mLCPeriod);
if (!result)
{
return result;
}
//
mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds;
mLMarketLength = mLCycleLength * mCMarketLength;
result = mLCycleLength > 0;
if (!result)
{
return result;
}
//
// Hind Cycle Initialization ...
//
// Find Cycle Period ...
if (hcMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mHCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_HIND,
_Period //
);
}
else
{
mHCPeriod = hcPeriod;
}
//
result = IsValid(mHCPeriod);
if (!result)
{
return result;
}
//
mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds;
mHMarketLength = mHCycleLength * mCMarketLength;
result = mHCycleLength > 0;
if (!result)
{
return result;
}
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(mCMarketLength, mSMarketLength);
result = MathMax(result, mMMarketLength);
result = MathMax(result, mLMarketLength);
result = MathMax(result, mHMarketLength);
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// Current ...
//
// ENUM_DRAW_TYPE cDrawType = showCurrent ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
// PlotIndexSetInteger(cPlotBufferIndex, PLOT_DRAW_TYPE, cDrawType);
// PlotIndexSetInteger(cPlotBufferIndex, PLOT_SHOW_DATA, showCurrent);
// SetIndexBuffer(cColorBufferIndex, cColorBuffer, INDICATOR_COLOR_INDEX);
SetIndexBuffer(cBufferIndex, cBuffer, INDICATOR_CALCULATIONS);
SetIndexBuffer(cColorBufferIndex, cColorBuffer, INDICATOR_CALCULATIONS);
//
// Short ...
//
// ENUM_DRAW_TYPE sDrawType = showShort ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
// PlotIndexSetInteger(sPlotBufferIndex, PLOT_DRAW_TYPE, sDrawType);
// PlotIndexSetInteger(sPlotBufferIndex, PLOT_SHOW_DATA, showShort);
// SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX);
SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_CALCULATIONS);
SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_CALCULATIONS);
//
// Medium ...
//
// ENUM_DRAW_TYPE mDrawType = showMedium ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
// PlotIndexSetInteger(mPlotBufferIndex, PLOT_DRAW_TYPE, mDrawType);
// PlotIndexSetInteger(mPlotBufferIndex, PLOT_SHOW_DATA, showMedium);
// SetIndexBuffer(mColorBufferIndex, mColorBuffer, INDICATOR_COLOR_INDEX);
SetIndexBuffer(mBufferIndex, mBuffer, INDICATOR_CALCULATIONS);
SetIndexBuffer(mColorBufferIndex, mColorBuffer, INDICATOR_CALCULATIONS);
//
// Long ...
//
// ENUM_DRAW_TYPE lDrawType = showLong ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
// PlotIndexSetInteger(lPlotBufferIndex, PLOT_DRAW_TYPE, lDrawType);
// PlotIndexSetInteger(lPlotBufferIndex, PLOT_SHOW_DATA, showLong);
// SetIndexBuffer(lColorBufferIndex, lColorBuffer, INDICATOR_COLOR_INDEX);
SetIndexBuffer(lBufferIndex, lBuffer, INDICATOR_CALCULATIONS);
SetIndexBuffer(lColorBufferIndex, lColorBuffer, INDICATOR_CALCULATIONS);
//
// Hind ...
//
// ENUM_DRAW_TYPE hDrawType = showHind ? DRAW_COLOR_HISTOGRAM : DRAW_NONE;
// PlotIndexSetInteger(hPlotBufferIndex, PLOT_DRAW_TYPE, hDrawType);
// PlotIndexSetInteger(hPlotBufferIndex, PLOT_SHOW_DATA, showHind);
// SetIndexBuffer(hColorBufferIndex, hColorBuffer, INDICATOR_COLOR_INDEX);
SetIndexBuffer(hBufferIndex, hBuffer, INDICATOR_CALCULATIONS);
SetIndexBuffer(hColorBufferIndex, hColorBuffer, INDICATOR_CALCULATIONS);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
// Calculations ...
//
// Calculate Buffers ...
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[] //
)
{
//
CalculateCycles(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
}
//
void CalculateCycles(
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[] //
)
{
//
// CURRENT ...
CalculateCycle(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
mCMarketLength,
showCurrent,
cVolumes,
cDistances,
cBuffer,
cColorBuffer //
);
//
// SHORT ...
CalculateCycle(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
mSMarketLength,
showShort,
sVolumes,
sDistances,
sBuffer,
sColorBuffer //
);
//
// MEDIUM ...
CalculateCycle(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
mMMarketLength,
showMedium,
mVolumes,
mDistances,
mBuffer,
mColorBuffer //
);
//
// LONG ...
CalculateCycle(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
mLMarketLength,
showLong,
lVolumes,
lDistances,
lBuffer,
lColorBuffer //
);
//
// HIND ...
CalculateCycle(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
mHMarketLength,
showHind,
hVolumes,
hDistances,
hBuffer,
hColorBuffer //
);
}
//
void CalculateCycle(
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 _length, // Calculation Length
bool _show,
double &_volumes[],
double &_distances[],
double &_buffer[],
double &_colorBuffer[] //
)
{
//
for (int x = 0; x < _length; x++)
{
//
_volumes[x] = (double)tickVolume[bar_index - x];
_distances[x] =
(close[bar_index - x] > open[bar_index - x])
? high[bar_index - x] - low[bar_index - x]
: low[bar_index - x] - high[bar_index - x];
}
//
double iValue = MathMean(_volumes) * MathMean(_distances);
//
_buffer[bar_index] = iValue;
_colorBuffer[bar_index] = iValue > 0
? _show
? bullishColorIDX
: hideColorIDX
: _show
? bearishColorIDX
: hideColorIDX;
}
//
@@ -0,0 +1,830 @@
///////////////////////////////////////////////////////
// SaherElm IT Center MQL5 Indicator
// -------------------------------------------
// Name: XCHVWAP
// Description: XCHVWAP Trend Detector ...
//
// 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 XCHVWAP Indicator"
#property strict
//
#define ShortName "XCHVWAP"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Inputs ...
//
// Market ...
input group "Market";
input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To
//
input group "Cycles";
//
input group "Short";
input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period
//
input group "Medium";
input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period
//
input group "Long";
input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period
//
input group "Hind";
input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period
input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period
//
// Presentation ...
input group "Presentation";
input bool showShort = true; // Show Short Cycle
input bool showMedium = true; // Show Medium Cycle
input bool showLong = true; // Show Long Cycle
input bool showHind = true; // Show Hind Cycle
//
// Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 14
#property indicator_plots 8
//
#define hideColorIDX 0
#define bullishColorIDX 1
#define bearishColorIDX 2
#define neuturalColorIDX 3
//
// Short ...
//
#define sBufferIndex 0
double sBuffer[];
//
#define sColorBufferIndex 1
double sColorBuffer[];
//
#define sPlotBufferIndex 0
#property indicator_label1 "XCHVWAP S"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style1 STYLE_DOT
#property indicator_width1 1
//
// Medium ...
//
#define mBufferIndex 2
double mBuffer[];
//
#define mColorBufferIndex 3
double mColorBuffer[];
//
#define mPlotBufferIndex 1
#property indicator_label2 "XCHVWAP M"
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style2 STYLE_DOT
#property indicator_width2 1
//
// Long ...
//
#define lBufferIndex 4
double lBuffer[];
//
#define lColorBufferIndex 5
double lColorBuffer[];
//
#define lPlotBufferIndex 2
#property indicator_label3 "XCHVWAP L"
#property indicator_type3 DRAW_COLOR_LINE
#property indicator_color3 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
//
// Hind ...
//
#define hBufferIndex 6
double hBuffer[];
//
#define hColorBufferIndex 7
double hColorBuffer[];
//
#define hPlotBufferIndex 3
#property indicator_label4 "XCHVWAP H"
#property indicator_type4 DRAW_COLOR_LINE
#property indicator_color4 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style4 STYLE_DOT
#property indicator_width4 1
//
// Data Buffers ...
//
// Volumes ...
#define volumeBufferIndex 8
double volumeBuffer[];
//
// Price ...
#define priceBufferIndex 9
double priceBuffer[];
//
// SHORT ...
#define sStateBufferIndex 10
double sStateBuffer[];
//
// MEDIUM ...
#define mStateBufferIndex 11
double mStateBuffer[];
//
// LONG ...
#define lStateBufferIndex 12
double lStateBuffer[];
//
// HIND ...
#define hStateBufferIndex 13
double hStateBuffer[];
//
// Variables ...
//
int maxLength;
//
// Short ...
int mSCycleLength = 0;
ENUM_TIMEFRAMES mSCPeriod = NULL;
//
// Medium ...
int mMCycleLength = 0;
ENUM_TIMEFRAMES mMCPeriod = NULL;
//
// Long ...
int mLCycleLength = 0;
ENUM_TIMEFRAMES mLCPeriod = NULL;
//
// Hind ...
int mHCycleLength = 0;
ENUM_TIMEFRAMES mHCPeriod = NULL;
//
// EVENT Handlers ...
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
if (!InitMarketCycles())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// 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;
}
//
// 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
}
//
// Calculating what we want ...
int OnCalculate(
const int rates_total, // Total Bars on Chart ...
const int prev_calculated, // Total Calculated Bars on Charts ...
const datetime &time[], // History of Open Time ...
const double &open[], // History of Open Price ...
const double &high[], // History of High Price ...
const double &low[], // History of Low Price ...
const double &close[], // History of Close Price ...
const long &tick_volume[], // History of Tick Volumes on Bar ...
const long &volume[], // History of Trade Volumes ...
const int &spread[] // History of Spread Price ...
)
{
//
ArraySetAsSeries(low, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
//
// this counts Available Bars ...
int limit;
//
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;
}
//
// CUSTOM Functions ...
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result =
//
(IsValid(scMethod, scPeriod) &&
IsValid(mcMethod, mcPeriod) &&
IsValid(lcMethod, lcPeriod) &&
IsValid(hcMethod, hcPeriod))
//
;
//
return result;
}
//
// Initialize Market Cycles ...
bool InitMarketCycles()
{
//
bool result = false;
//
// Current Cycle Initialization ...
//
int cPeriodSeconds = PeriodSeconds(_Period);
//
// Short Cycle Initialization ...
//
// Find Cycle Period ...
if (scMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mSCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_SHORT,
_Period //
);
}
else
{
mSCPeriod = scPeriod;
}
//
result = IsValid(mSCPeriod);
if (!result)
{
return result;
}
//
mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds;
result = mSCycleLength > 0;
if (!result)
{
return result;
}
//
// Medium Cycle Initialization ...
//
// Find Cycle Period ...
if (mcMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mMCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_MEDIUM,
_Period //
);
}
else
{
mMCPeriod = mcPeriod;
}
//
result = IsValid(mMCPeriod);
if (!result)
{
return result;
}
//
mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds;
result = mMCycleLength > 0;
if (!result)
{
return result;
}
//
// Long Cycle Initialization ...
//
// Find Cycle Period ...
if (lcMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mLCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_LONG,
_Period //
);
}
else
{
mLCPeriod = lcPeriod;
}
//
result = IsValid(mLCPeriod);
if (!result)
{
return result;
}
//
mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds;
result = mLCycleLength > 0;
if (!result)
{
return result;
}
//
// Hind Cycle Initialization ...
//
// Find Cycle Period ...
if (hcMethod == X_PERIOD_AUTO)
{
//
// Select Period ...
mHCPeriod = GetCyclePeriod(
X_MARKET_CYCLE_HIND,
_Period //
);
}
else
{
mHCPeriod = hcPeriod;
}
//
result = IsValid(mHCPeriod);
if (!result)
{
return result;
}
//
mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds;
result = mHCycleLength > 0;
if (!result)
{
return result;
}
//
return result;
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// Short ...
//
ArraySetAsSeries(sBuffer, true);
ArraySetAsSeries(sColorBuffer, true);
SetIndexBuffer(sBufferIndex, sBuffer, INDICATOR_DATA);
SetIndexBuffer(sColorBufferIndex, sColorBuffer, INDICATOR_COLOR_INDEX);
//
// Medium ...
//
ArraySetAsSeries(mBuffer, true);
ArraySetAsSeries(mColorBuffer, true);
SetIndexBuffer(mBufferIndex, mBuffer, INDICATOR_DATA);
SetIndexBuffer(mColorBufferIndex, mColorBuffer, INDICATOR_COLOR_INDEX);
//
// Long ...
//
ArraySetAsSeries(lBuffer, true);
ArraySetAsSeries(lColorBuffer, true);
SetIndexBuffer(lBufferIndex, lBuffer, INDICATOR_DATA);
SetIndexBuffer(lColorBufferIndex, lColorBuffer, INDICATOR_COLOR_INDEX);
//
// Hind ...
//
ArraySetAsSeries(hBuffer, true);
ArraySetAsSeries(hColorBuffer, true);
SetIndexBuffer(hBufferIndex, hBuffer, INDICATOR_DATA);
SetIndexBuffer(hColorBufferIndex, hColorBuffer, INDICATOR_COLOR_INDEX);
//
// Data Buffers ...
//
// Volumes ...
ArraySetAsSeries(volumeBuffer, true);
SetIndexBuffer(volumeBufferIndex, volumeBuffer, INDICATOR_CALCULATIONS);
//
// Price ...
ArraySetAsSeries(priceBuffer, true);
SetIndexBuffer(priceBufferIndex, priceBuffer, INDICATOR_CALCULATIONS);
//
// Short State ...
ArraySetAsSeries(sStateBuffer, true);
SetIndexBuffer(sStateBufferIndex, sStateBuffer, INDICATOR_CALCULATIONS);
//
// Medium State ...
ArraySetAsSeries(mStateBuffer, true);
SetIndexBuffer(mStateBufferIndex, mStateBuffer, INDICATOR_CALCULATIONS);
//
// Long State ...
ArraySetAsSeries(lStateBuffer, true);
SetIndexBuffer(lStateBufferIndex, lStateBuffer, INDICATOR_CALCULATIONS);
//
// Hind State ...
ArraySetAsSeries(hStateBuffer, true);
SetIndexBuffer(hStateBufferIndex, hStateBuffer, INDICATOR_CALCULATIONS);
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
result = MathMax(mSCycleLength, mMCycleLength);
result = MathMax(result, mLCycleLength);
result = MathMax(result, mHCycleLength);
//
return result;
}
//
// Calculate Buffers ...
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[] //
)
{
//
// Calculate Volumes and Price ...
//
if (ratesTotal - bar_index <= maxLength)
{
//
CalculateDataBuffers(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
return;
}
//
CalculateDataBuffers(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
CalculateCycles(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
}
//
void CalculateDataBuffers(
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[] //
)
{
//
double price = GetAppliedPrice(
appliedTo,
open,
high,
low,
close,
bar_index //
);
priceBuffer[bar_index] = price;
volumeBuffer[bar_index] = (double)tickVolume[bar_index];
}
//
void CalculateCycles(
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[] //
)
{
//
// SHORT ...
CalculateCycle(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
mSCycleLength,
showShort,
sBuffer,
sColorBuffer,
sStateBuffer //
);
//
// MEDIUM ...
CalculateCycle(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
mMCycleLength,
showMedium,
mBuffer,
mColorBuffer,
mStateBuffer //
);
//
// LONG ...
CalculateCycle(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
mLCycleLength,
showLong,
lBuffer,
lColorBuffer,
lStateBuffer //
);
//
// HIND ...
CalculateCycle(
bar_index,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume,
//
mHCycleLength,
showHind,
hBuffer,
hColorBuffer,
hStateBuffer //
);
}
//
void CalculateCycle(
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 _length, // Calculation Length
bool _show,
double &_buffer[],
double &_colorBuffer[],
double &_stateBuffer[] //
)
{
//
double vSum = 0;
double pSum = 0;
double mSum = 0;
for (int x = 0; x < _length; x++)
{
//
pSum += priceBuffer[x + bar_index];
vSum += volumeBuffer[x + bar_index];
mSum += priceBuffer[x + bar_index] * volumeBuffer[x + bar_index];
}
//
double iValue = mSum / vSum;
iValue = NormalizeDouble(iValue, _Digits);
//
_buffer[bar_index] = iValue;
//
bool isBullish = low[bar_index] > iValue;
bool isBearish = high[bar_index] < iValue;
//
double iColor =
isBullish
? bullishColorIDX
: isBearish
? bearishColorIDX
: neuturalColorIDX;
//
_colorBuffer[bar_index] = hideColorIDX;
_stateBuffer[bar_index] = iColor;
if (_show)
{
_colorBuffer[bar_index] = iColor;
}
}
//
@@ -0,0 +1,270 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Indicator
// ---------------------------------------------
// Name: XCT
// Description: Trend Magic Indicator ...
//
//
// 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 XCT Indicator"
#property strict
//
// START Constants ...
//
//
#define ShortName "XCT"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Constants ...
//
//
// START Inputs ...
//
//
input color clr = clrYellow; // Text Color
input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER; // Text Position
//
input group "Presentation";
input bool showCandleTime = true; // Show Candle Time
//
// END Inputs ...
//
//
// START Buffers ...
//
//
#property indicator_chart_window
//
#property indicator_buffers 0
#property indicator_plots 0
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (showCandleTime)
{
CreateIndicatorObject();
}
else
{
ObjectDelete(0, ShortName);
}
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// 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
//
ulong chID = FindChartID(
_Symbol,
_Period
//
);
//
// Delete Object ...
ObjectDelete(chID, ShortName);
//
Comment("");
}
//
// Calculating what we want ...
int OnCalculate(
const int rates_total, // Total Bars on Chart ...
const int prev_calculated, // Total Calculated Bars on Charts ...
const datetime &time[], // History of Open Time ...
const double &open[], // History of Open Price ...
const double &high[], // History of High Price ...
const double &low[], // History of Low Price ...
const double &close[], // History of Close Price ...
const long &tick_volume[], // History of Tick Volumes on Bar ...
const long &volume[], // History of Trade Volumes ...
const int &spread[] // History of Spread Price ...
)
{
//
ArraySetAsSeries(time, true);
//
if (!showCandleTime)
{
return rates_total;
}
//
ulong chID = FindChartID(
_Symbol,
_Period
//
);
//
XBarRemainsTime barRemains;
barRemains.Init(
_Symbol,
_Period
//
);
//
string msg = barRemains
.ToString(
"",
"",
"",
"",
"",
":",
true
//
);
//
long mSpread = SymbolInfoInteger(Symbol(), SYMBOL_SPREAD);
//
string _sp = "";
if (mSpread < 10)
_sp = "..";
else if (mSpread < 100)
_sp = ".";
//
// int offset = TimeGMTOffset();
// string timeString =
// ", Time: " + string(TimeCurrent()) + "\n" +
// ", ServerTime: " + string(TimeTradeServer()) + "\n" +
// ", GMT Offset: " + (string)offset;
// timeString = timeString;
// Comment(timeString);
//
string objText = "Spread: " + IntegerToString(mSpread) + _sp + ", Next Bar in: " + msg;
//
ObjectSetInteger(chID, ShortName, OBJPROP_COLOR, clr);
ObjectSetString(chID, ShortName, OBJPROP_TEXT, objText);
ObjectSetInteger(chID, ShortName, OBJPROP_FONTSIZE, 10);
ObjectSetString(chID, ShortName, OBJPROP_FONT, "Courier");
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
}
//
void CreateIndicatorObject()
{
//
if (!showCandleTime)
{
return;
}
//
ObjectCreate(0, ShortName, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, ShortName, OBJPROP_CORNER, corner);
ObjectSetInteger(0, ShortName, OBJPROP_XDISTANCE, 10);
ObjectSetInteger(0, ShortName, OBJPROP_YDISTANCE, 2);
//
ENUM_ANCHOR_POINT Anchor = ANCHOR_LEFT_UPPER;
switch (corner)
{
case CORNER_LEFT_UPPER:
Anchor = ANCHOR_LEFT_UPPER;
break;
case CORNER_RIGHT_UPPER:
Anchor = ANCHOR_RIGHT_UPPER;
break;
case CORNER_LEFT_LOWER:
Anchor = ANCHOR_LEFT_LOWER;
break;
case CORNER_RIGHT_LOWER:
Anchor = ANCHOR_RIGHT_LOWER;
break;
}
//
ObjectSetInteger(0, ShortName, OBJPROP_ANCHOR, Anchor);
}
//
// END Functions ...
//
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More