last works on xki ...

This commit is contained in:
2025-12-30 21:38:58 +03:30
parent 5850164aab
commit b1731af03c
8 changed files with 6662 additions and 66 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,871 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Expert Advisor
// -------------------------------------------------
// Name: X121XKIEABackTester
// Description: Base Expert Advisor as Template ...
//
// 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 icon "../Images/SaherElm_Logo_Color.ico"
#property description "SaherElm XFIMA Expert Advisor"
#property strict
//
#define ShortName "X121XKIEABackTester"
//
// Importts ...
#include "../Classes/x-saherelm.x-backtester.expert.class.mq5"
#include "../X121XKIEA/Classes/x-saherelm.x121.xki.signaller.class.mq5"
// #region Inputs ...
// #region Commons ...
input group "Common";
input long eaMagicNumber = 78692110; // Magic Number
input int eaSlippage = 10; // Slippgae
input string eaLogSuffix = ""; // Log Suffix
// #endregion
// #region Volume ...
input group "Volume";
input ENUM_X_VOLUME_SELECT_TYPE eaVolumeSelect = X_VOLUME_CONSTANT; // Volume Applying Type
input double eaStaticVoluem = 0.0; // Static Volume
input double eaDynamicVolumeStepBalance = 0.0; // Step of Balance for Increase Volume
input double eaDynamicVolumeStepVolume = X_MIN_VOLUME; // Step of Volume Increasing
input double eaConstantRiskBalance = 0.0; // Constant Risk Balance per Trade
input double eaConstantPercent = 1; // Constant Percent of Balance Per Trade
input double eaConstantBalance = 1000.0; // Constant Balance for Calculations
// #endregion
// #region Alert ...
input group "Alert";
input bool eaEnableAlerts = true; // Enable Alerts
input bool eaLogAlerts = true; // Log Alerts
input bool eaMailAlerts = false; // Mail Alerts
input bool eaPushAlerts = false; // Push Alerts
input bool eaTerminalAlerts = false; // Terminal Alerts
// #endregion
// #region Configurations ...
input group "Configuration";
input bool eaProcessAllTicks = false; // Process All Ticks
input double eaSignallerR2R = 2.0; // Risk To Reward Ratio
input double eaSignallerVolume = 0.01; // Default Volume
input double eaSignallerRiskInPoint = 50; // Default Risk In Point
// #endregion
// #region Bar Time ...
input group "Bar Timer";
input int barTimeFontSize = 10; // Font Size
input string barTimeFont = "Arial"; // Font
input color barTimeColor = clrYellow; // Text Color
input ENUM_BASE_CORNER barTimeCorner = CORNER_RIGHT_LOWER; // Text Position
input bool showBars = true; // Show Bars
input bool showBarTime = true; // Show Bar Time
// #endregion
// #region Indicator Inputs ...
//
input group "Calculation";
input int kiFastLength = 26; // KI Fast Length
input int kiSlowLength = 104; // KI Slow Length
input int maFastLength = 9; // MA Fast Length
input int maSlowLength = 26; // MA Slow Length
input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Mode
input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // MA Applied To
input int rsiLength = 14; // RSI Length
input ENUM_APPLIED_PRICE rsiAppliedTo = PRICE_CLOSE; // RSI Applied To
input int kiWaveSmoothingLength = 14; // RSI KI Wave Smoothing Length
input ENUM_X_MA_METHOD kiWaveSmoothingMode = X_MA_MODE_EMA; // RSI KI Wave Smoothing Method
input double rsiMultiplier = 0.5; // RSI Multiplier
input int atrLength = 14; // ATR Length
input double atrMultiplier = 2; // ATR Multiplier
input int atrSmoothingLength = 14; // ATR Smoothing Length
input ENUM_X_MA_METHOD atrSmoothingMode = X_MA_MODE_EMA; // ATR Smoothing Method
input ENUM_X_PRICE atrUpperPriceType = X_PRICE_HIGH; // ATR Upper Price Type
input ENUM_X_PRICE atrLowerPriceType = X_PRICE_LOW; // ATR Lower Price Type
//
// Presentation ...
input group "Presentation";
input bool showKIFast = true; // Show KI Fast
input bool showKISlow = true; // Show KI Slow
input bool showMaFast = true; // Show Ma Fast
input bool showMaSlow = true; // Show MA Slow
input bool showKIWave = true; // Show KI Wave
input bool showKIUpper = true; // Show KI Upper
input bool showKILower = true; // Show KI Lower
//
input int startCalculationForLastBars = 1500; // Calculate Last n Bars
// #endregion
// #endregion
// #region Local Variables ...
//
// Requirements ...
string eaLogTag; // EA Log Prefix ...
XCBackTesterEA *eaExpert; // EA Expert ...
//
// Registered Signallers ...
XCX121XKIStrategy1Signaller *signaller1; // XFIMA1 Signaller ...
//
XBarTracker eaBarTracker; // EA Bar Traker ...
//
// Registered Handlers ...
int eaCTHandler = INVALID_HANDLE; // Candle Timer Handler ...
int eaCCHandler = INVALID_HANDLE; // Candle Cleaner Handler ...
//
bool eaIsNewBar; // Check New Bar ...
//
ENUM_CHART_MODE eaBarMode = CHART_CANDLES;
//
color eaBarUpColor = clrLime;
color eaBarDownColor = clrRed;
color eaBarLineColor = clrLime;
color eaBarBearishColor = clrRed;
color eaBarBullishColor = clrLime;
color eaBarVolumesColor = clrGreen;
// #endregion
// #region Event Handlers ...
//
// Initialization ...
int OnInit()
{
//
// Preparing Tags ...
string eaTag =
(IsValid(eaLogSuffix)
? eaLogSuffix + "_"
: "") +
ShortName;
//
// Validate Inputs and Required Parameters
// for EA to Works fine ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initialize Timer ...
if (!InitTimer())
{
return INIT_FAILED;
}
//
// Configure EA Expert Class ...
eaExpert = new XCBackTesterEA();
//
// Symbol / Period ...
eaExpert.symbol = _Symbol;
eaExpert.period = _Period;
//
// Common ...
eaExpert.eaMagicNumber = eaMagicNumber;
eaExpert.eaSlippage = eaSlippage;
eaExpert.eaLogSuffix = eaTag;
//
// Volume ...
eaExpert.eaVolumeSelect = eaVolumeSelect;
eaExpert.eaStaticVoluem = eaStaticVoluem;
eaExpert.eaDynamicVolumeStepBalance = eaDynamicVolumeStepBalance;
eaExpert.eaDynamicVolumeStepVolume = eaDynamicVolumeStepVolume;
eaExpert.eaConstantRiskBalance = eaConstantRiskBalance;
eaExpert.eaConstantPercent = eaConstantPercent;
eaExpert.eaConstantBalance = eaConstantBalance;
//
// Alert ...
eaExpert.eaEnableAlerts = eaEnableAlerts;
eaExpert.eaLogAlerts = eaLogAlerts;
eaExpert.eaMailAlerts = eaMailAlerts;
eaExpert.eaPushAlerts = eaPushAlerts;
eaExpert.eaTerminalAlerts = eaTerminalAlerts;
//
// Attach Event Handlers ...
eaExpert.AddOnDealsChangedEventHandler(OnDealsChanged);
eaExpert.AddOnStopLossEventHandler(OnStopLossTriggered);
eaExpert.AddOnOrdersChangedEventHandler(OnOrdersChanged);
eaExpert.AddOnSignalExecutedEventHandler(OnSignalExecuted);
eaExpert.AddOnTakeProfitEventHandler(OnTakeProfitTriggered);
eaExpert.AddOnModifyPositionEventHandler(OnPositionModified);
eaExpert.AddOnPositionsChangedEventHandler(OnPositionsChanged);
eaExpert.AddOnTradeStateChangedEventHandler(OnTradeStateChanged);
eaExpert.AddOnForceClosePositionEventHandler(OnPositionForceClosed);
eaExpert.AddOnPartialClosePositionEventHandler(OnPositionPartialClosed);
//
// Configure Other Requirements ...
eaExpert.allowedTPSLStep = 10;
eaExpert.minAllowedRiskInPoint = 20;
eaExpert.volume = eaSignallerVolume;
eaExpert.riskToRewardRatio = eaSignallerR2R;
eaExpert.riskInPoint = eaSignallerRiskInPoint;
//
// Try to Initialize eaExpert ...
bool isInited = eaExpert.HandleOnInit();
if (!isInited)
{
//
Print(ShortName, ": Initialization Failed ...");
return INIT_FAILED;
}
//
// Here Instantiate Signaller Class ...
//
// Preparing Indicator Inputs ...
X121XKIInputs kiInputs;
//
// This is Default Configuration ...
kiInputs.Default();
kiInputs.Hide();
//
// Here we Attach Inputs to Indicator ...
kiInputs.kiFastLength = kiFastLength;
kiInputs.kiSlowLength = kiSlowLength;
kiInputs.maFastLength = maFastLength;
kiInputs.maSlowLength = maSlowLength;
kiInputs.maMethod = maMethod;
kiInputs.maAppliedTo = maAppliedTo;
kiInputs.rsiLength = rsiLength;
kiInputs.rsiAppliedTo = rsiAppliedTo;
kiInputs.kiWaveSmoothingLength = kiWaveSmoothingLength;
kiInputs.kiWaveSmoothingMode = kiWaveSmoothingMode;
kiInputs.rsiMultiplier = rsiMultiplier;
kiInputs.atrLength = atrLength;
kiInputs.atrMultiplier = atrMultiplier;
kiInputs.atrSmoothingLength = atrSmoothingLength;
kiInputs.atrSmoothingMode = atrSmoothingMode;
kiInputs.atrUpperPriceType = atrUpperPriceType;
kiInputs.atrLowerPriceType = atrLowerPriceType;
kiInputs.showKIFast = showKIFast;
kiInputs.showKISlow = showKISlow;
kiInputs.showMaFast = showMaFast;
kiInputs.showMaSlow = showMaSlow;
kiInputs.showKIWave = showKIWave;
kiInputs.showKIUpper = showKIUpper;
kiInputs.showKILower = showKILower;
kiInputs.startCalculationForLastBars = startCalculationForLastBars;
//
// Instantiate Signaller ...
//
// X121XKI1 Signaller ...
signaller1 = new XCX121XKIStrategy1Signaller(
_Symbol,
_Period,
kiInputs,
eaProcessAllTicks, // Process All Ticks ...
eaSignallerR2R, // Signaller Risk to Reward Ratio ...
eaSignallerRiskInPoint, // Default Risk In Points ...
eaSignallerVolume // Defaul Volume ...
);
//
// Configure Signaller ...
signaller1.ignoreTargets = false;
signaller1.slAdditionDistance = 30;
signaller1.maxAllowedRiskDistance = 350;
signaller1.AddOnSignalEventHandler(OnSignalTriggered);
//
isInited =
signaller1.IsValid();
if (!isInited)
{
//
Print(ShortName, ": Initialization Failed ...");
return INIT_FAILED;
}
//
// Initialize Candle Timer Handler ...
eaCTHandler = iCustom(
_Symbol,
_Period,
"x-saherelm.x121.xct",
//
// Inputs ...
barTimeFontSize, // Font Size ...
barTimeFont, // Font ...
barTimeColor, // Text Color ...
barTimeCorner, // Text Position ...
//
// Presentation ...
"",
showBarTime // Show Candle Time
//
);
isInited = eaCTHandler != INVALID_HANDLE;
if (!isInited)
{
//
Print(ShortName, ": Initialization Failed ...");
return INIT_FAILED;
}
//
// Initialize Candle Cleaner Handler ...
eaCCHandler = iCustom(
_Symbol,
_Period,
"x-saherelm.x121.xcc",
//
// Inputs ...
//
// Chart Style ...
"",
eaBarMode, // Mode
eaBarUpColor, // Up Color
eaBarDownColor, // Down Color
eaBarLineColor, // Line mode and Doji candlestick Color
eaBarBullishColor, // Bearish Color
eaBarBearishColor, // Bullish Color
eaBarVolumesColor, // Volumes Color
//
// Presentation ...
"",
showBars // Show Candles
//
);
isInited = eaCCHandler != INVALID_HANDLE;
if (!isInited)
{
//
Print(ShortName, ": Initialization Failed ...");
return INIT_FAILED;
}
//
// Initialize Bar Tracker ...
isInited = eaBarTracker.Init(
_Symbol,
_Period //
);
if (!isInited)
{
//
Print(ShortName, ": Initialization Failed ...");
return INIT_FAILED;
}
//
// Configure XFIMA POI Detector / Drawer ...
// detectorConfig.Default();
// detectorConfig.FullDetect();
// marketStructureDrawerConfig.FullDraw();
//
// Ignoring Position Drawer ...
delete eaExpert.eaPositionDrawer;
ZeroMemory(eaExpert.eaPositionDrawer);
eaExpert.eaPositionDrawer = NULL;
//
Print(ShortName, ": Initialized Successfully ...");
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
//
// Destroy Timer ...
eaExpert.HandleOnDeInit();
//
// De Init Indicator ...
IndicatorRelease(eaCTHandler);
//
eaBarTracker.Clean();
//
delete signaller1;
ZeroMemory(signaller1);
//
delete eaExpert;
ZeroMemory(eaExpert);
}
//
// On Tick Handler ...
void OnTick()
{
//
eaIsNewBar = eaBarTracker.IsNewBar();
bool canProcess = eaProcessAllTicks
? true
: eaIsNewBar;
//
eaExpert.HandleOnTick();
//
if (!canProcess)
{
return;
}
//
// Bar Index ...
int barIndex = 0;
//
// Signallers Calling OnTick ...
signaller1.OnTick(barIndex);
//
// Checking For Guard only When has Position ...
XPosition positions[];
int positionsCount = eaExpert.eaTrader.GetPositions(
positions,
signaller1.symbol,
signaller1.name,
signaller1.period,
NULL, // All Types ...
true, // Filter By Magic ...
true // Force Clean ...
);
if (IsValidSize(positionsCount))
{
//
XGuard guards[];
int guardsCount = signaller1.CheckForGuard(
guards,
positions,
barIndex //
);
if (IsValidSize(guardsCount))
{
//
// Handling Guards ...
eaExpert.eaGuard.DoGuards(guards);
}
}
}
//
// Handle On Trade Event ...
void OnTrade()
{
eaExpert.HandleOnTrade();
}
//
// On Timer ...
void OnTimer()
{
eaExpert.HandleOnTimer();
}
//
// Chart Event Handler ...
void OnChartEvent(
const int id,
const long &lparam,
const double &dparam,
const string &sparam //
)
{
eaExpert.HandleOnChartEvent(id, lparam, dparam, sparam);
}
// #endregion
// #region Custom Event Handlers ...
/**
* Validate all Inputs of Expert Adviser ...
*
* @return ( bool )
*/
bool ValidateInputs()
{
//
bool result = false;
//
string errMessage = "";
//
bool isCommonValid = (
//
eaSlippage > 0 &&
eaMagicNumber > 0 &&
//
// Indicator Inputs ...
//
// KI ...
kiFastLength >= 5 &&
kiSlowLength > kiFastLength &&
//
// ATR ...
atrLength >= 5 &&
//
// RSI ...
rsiLength >= 5
//
//
);
if (!isCommonValid)
{
//
errMessage += "common configurations error;" + "\n";
}
//
result =
//
// Common ...
isCommonValid &&
//
// Otere ...
true
//
;
//
if (!result)
{
//
// Since here Logger not Initiallized, we Use Raw Print Command ...
Print(ShortName + " Errors: \n", errMessage);
}
//
return result;
}
/**
* Initialize Timer ...
*
* @return ( bool )
*/
bool InitTimer()
{
//
bool result = false;
//
// TODO: Initialize Timer if necessary ...
// result = EventSetTimer(1);
// result = EventSetMillisecondTimer(100);
result = true;
//
return result;
}
/**
* Destroy Timer ...
*/
void DestroyTimer()
{
//
// TODO: Use This ...
// EventKillTimer();
}
/**
* Trigger OnSignal Event ...
*
* @param signal: XSignal
*/
void OnSignalTriggered(XSignal &signal)
{
// //
// // Draw Signal on Chart ...
// XCSignalObject *iSignalObj;
// bool has = signaller1.poiDrawer.DrawSignal(
// signal,
// iSignalObj,
// 7 //
// );
//
eaExpert.HandleOnSignalTriggered(signal);
}
/**
* Trigger OnSignal Executed Event ...
*
* @param signal: XSignal
*/
void OnSignalExecuted(XSignal &signal)
{
eaExpert.HandleOnSignalExecuted(signal);
}
/**
* Check For Guard ...
*
* @param guards: XGuard, reference Collection to holds result ...
* @param positions: XPosition, refrence collection to Provides Positions ...
* @param barIndex: int, Specified Bar index ...
*
* @return ( int )
*/
int CheckForGuard(
XGuard &guards[],
XPosition &positions[],
int barIndex = 0 //
)
{
//
int result = signaller1.CheckForGuard(
guards,
positions,
barIndex //
);
//
return result;
}
//
// Trade Event Handlers ...
/**
* Handle StopLoss Triggered Positions ...
*
* @param deal: XDeal instance ...
*/
void OnStopLossTriggered(const XDeal &deal)
{
//
eaExpert.HandleOnStopLossTriggered(deal);
//
HandleBalanceReport();
HandleWinTrade(deal.positionId, deal.profit);
HandleLoseTrade(deal.positionId, deal.profit);
}
/**
* Handle Take Profit Triggered Positions ...
*
* @param deal: XDeal instance ...
*/
void OnTakeProfitTriggered(const XDeal &deal)
{
//
eaExpert.HandleOnTakeProfitTriggered(deal);
//
HandleBalanceReport();
HandleWinTrade(deal.positionId, deal.profit);
}
/**
* Handle Force Close a Position ...
*
* @param ticket: ULONG ...
* @param position: XPosition instance ...
* @param comment: String ...
*/
void OnPositionForceClosed(
const ulong ticket,
const XPosition &position,
const string comment //
)
{
//
eaExpert.HandleOnPositionForceClosed(
ticket,
position,
comment //
);
//
HandleBalanceReport();
HandleWinTrade(ticket, position.profit);
HandleLoseTrade(ticket, position.profit);
}
/**
* Handle Deals Changes ...
*
* @param count: Integer, Number of Changes ...
*/
void OnDealsChanged(int count)
{
eaExpert.HandleOnDealsChanged(count);
}
/**
* Handle Orders Changes ...
*
* @param count: Integer, Number of Changes ...
*/
void OnOrdersChanged(int count)
{
eaExpert.HandleOnOrdersChanged(count);
}
/**
* Handle Positions Changes ...
*
* @param count: Integer, Number of Changes ...
*/
void OnPositionsChanged(int count)
{
eaExpert.HandleOnPositionsChanged(count);
}
/**
* Handle Position Modified ...
*
* @param ticket: ulong, Position Ticket ...
* @param profit: double, Position Profit ...
* @param comment: string, Comment ...
*/
void OnPositionModified(
const ulong ticket,
const double profit,
const string comment //
)
{
//
eaExpert.HandleOnPositionModified(
ticket,
profit,
comment //
);
}
/**
* Handle Position Partial Closed ...
*
* @param ticket: ulong, Position Ticket ...
* @param profit: double, Position Profit ...
* @param comment: string, Comment ...
*/
void OnPositionPartialClosed(
const ulong ticket,
const double profit,
const string comment //
)
{
//
eaExpert.HandleOnPositionPartialClosed(
ticket,
profit,
comment //
);
}
/**
* Handle Trade State Changed ...
*
* @param state: XOnTradeHandlerState instance ...
*/
void OnTradeStateChanged(const XOnTradeHandlerState &state)
{
eaExpert.HandleOnTradeStateChanged(state);
}
/**
* Test Resting Signals ...
*
* @param ticket: ulong, Position Ticket ...
* @param profit: double, Position Profit ...
*/
void HandleLoseTrade(
ulong ticket = 0,
double profit = 0 //
)
{
//
// Check Position Loose ...
bool has = ticket > 0 &&
profit < 0;
if (!has)
{
return;
}
//
// NOTE: Here we Can Add Restrictions on Signaller based on our Requirements ...
// restingSignals: Specified Number of Signals which must to Ignore ...
// restUntil: Specified DateTime to Ignore all Signals before it Expiration ...
// restingDelay: Specified Bars Delay to Ignore all Signals before it passed ...
//
// Increase Resting Signals of Signallers ...
signaller1.LoseTrade();
}
/**
* Handle Win Trade ...
*
* @param ticket: ulong, Position Ticket ...
* @param profit: double, Position Profit ...
*/
void HandleWinTrade(
ulong ticket = 0,
double profit = 0 //
)
{
//
bool has = ticket > 0 &&
profit > 0;
if (!has)
{
return;
}
//
signaller1.WinTrade();
}
/**
* Handle Balance Report ...
*/
void HandleBalanceReport()
{
//
string message = eaExpert.eaTrader.mAccount.GetBalanceReportMessage();
eaExpert.eaAlert.SendAlert(message);
}
// #endregion
+181 -48
View File
@@ -28,16 +28,21 @@
enum ENUM_X121_XKI_BUFFERS enum ENUM_X121_XKI_BUFFERS
{ {
// //
// KI ... // KI Fast ...
X121_XKI_KI_LINE = 0, X121_XKI_KI_FAST_LINE = 0,
X121_XKI_KI_COLOR_LINE = 1, X121_XKI_KI_FAST_COLOR_LINE = 1,
X121_XKI_KI_STATE_LINE = 8, X121_XKI_KI_FAST_STATE_LINE = 10,
//
// KI Slow ...
X121_XKI_KI_SLOW_LINE = 8,
X121_XKI_KI_SLOW_COLOR_LINE = 9,
X121_XKI_KI_SLOW_STATE_LINE = 17,
// //
// KI Wave ... // KI Wave ...
X121_XKI_KI_WAVE_LINE = 2, X121_XKI_KI_WAVE_LINE = 2,
X121_XKI_KI_WAVE_RAW_LINE = 13, X121_XKI_KI_WAVE_RAW_LINE = 15,
X121_XKI_KI_WAVE_COLOR_LINE = 3, X121_XKI_KI_WAVE_COLOR_LINE = 3,
X121_XKI_KI_WAVE_STATE_LINE = 14, X121_XKI_KI_WAVE_STATE_LINE = 16,
// //
// Upper/Lower ... // Upper/Lower ...
X121_XKI_KI_UPPER_LINE = 4, X121_XKI_KI_UPPER_LINE = 4,
@@ -48,12 +53,12 @@ enum ENUM_X121_XKI_BUFFERS
X121_XKI_MA_SLOW_LINE = 7, X121_XKI_MA_SLOW_LINE = 7,
// //
// ATR ... // ATR ...
X121_XKI_ATR_LINE = 9, X121_XKI_ATR_LINE = 11,
X121_XKI_ATR_RAW_UPPER_LINE = 10, X121_XKI_ATR_RAW_UPPER_LINE = 12,
X121_XKI_ATR_RAW_LOWER_LINE = 11, X121_XKI_ATR_RAW_LOWER_LINE = 13,
// //
// RSI ... // RSI ...
X121_XKI_RSI_LINE = 12, X121_XKI_RSI_LINE = 14,
}; };
// #endregion // #endregion
@@ -62,7 +67,8 @@ struct X121XKIInputs
{ {
// #region Props ... // #region Props ...
// #region Calculations ... // #region Calculations ...
int kiLength; // KI Length int kiFastLength; // KI Fast Length
int kiSlowLength; // KI Slow Length
int maFastLength; // MA Fast Length int maFastLength; // MA Fast Length
int maSlowLength; // MA Slow Length int maSlowLength; // MA Slow Length
ENUM_MA_METHOD maMethod; // MA Mode ENUM_MA_METHOD maMethod; // MA Mode
@@ -81,7 +87,8 @@ struct X121XKIInputs
// #endregion // #endregion
// #region Presentations ... // #region Presentations ...
bool showKI; // Show KI bool showKIFast; // Show KI
bool showKISlow; // Show Slow
bool showMaFast; // Show Ma Fast bool showMaFast; // Show Ma Fast
bool showMaSlow; // Show MA Slow bool showMaSlow; // Show MA Slow
bool showKIWave; // Show KI Wave bool showKIWave; // Show KI Wave
@@ -114,7 +121,8 @@ struct X121XKIInputs
{ {
// //
// Calculations ... // Calculations ...
kiLength = 26; kiFastLength = 26;
kiSlowLength = 104;
maFastLength = 9; maFastLength = 9;
maSlowLength = 26; maSlowLength = 26;
maMethod = MODE_EMA; maMethod = MODE_EMA;
@@ -133,7 +141,8 @@ struct X121XKIInputs
// //
// Presentations ... // Presentations ...
showKI = true; showKIFast = true;
showKISlow = true;
showMaFast = true; showMaFast = true;
showMaSlow = true; showMaSlow = true;
showKIWave = true; showKIWave = true;
@@ -150,7 +159,8 @@ struct X121XKIInputs
{ {
// //
// Presentations ... // Presentations ...
showKI = false; showKIFast = false;
showKISlow = false;
showMaFast = false; showMaFast = false;
showMaSlow = false; showMaSlow = false;
showKIWave = false; showKIWave = false;
@@ -169,7 +179,8 @@ struct X121XKIInputs
result = result =
// //
// KI ... // KI ...
kiLength >= 5 && kiFastLength >= 5 &&
kiSlowLength > kiFastLength &&
// //
// ATR ... // ATR ...
atrLength >= 5 && atrLength >= 5 &&
@@ -201,15 +212,18 @@ struct X121XKIConditions
// #endregion // #endregion
// #region Buffers ... // #region Buffers ...
double kiBuffer[]; double kiFastBuffer[];
double kiColorBuffer[]; double kiFastColorBuffer[];
double kiFastStateBuffer[];
double kiSlowBuffer[];
double kiSlowColorBuffer[];
double kiSlowStateBuffer[];
double kiWaveBuffer[]; double kiWaveBuffer[];
double kiWaveColorBuffer[]; double kiWaveColorBuffer[];
double kiUpperBuffer[]; double kiUpperBuffer[];
double kiLowerBuffer[]; double kiLowerBuffer[];
double maFastBuffer[]; double maFastBuffer[];
double maSlowBuffer[]; double maSlowBuffer[];
double kiStateBuffer[];
double atrBuffer[]; double atrBuffer[];
double atrRawUpperBuffer[]; double atrRawUpperBuffer[];
double atrRawLowerBuffer[]; double atrRawLowerBuffer[];
@@ -243,15 +257,18 @@ struct X121XKIConditions
// Buffers ... // Buffers ...
// //
XClean(kiBuffer); XClean(kiFastBuffer);
XClean(kiColorBuffer); XClean(kiFastColorBuffer);
XClean(kiFastStateBuffer);
XClean(kiSlowBuffer);
XClean(kiSlowColorBuffer);
XClean(kiSlowStateBuffer);
XClean(kiWaveBuffer); XClean(kiWaveBuffer);
XClean(kiWaveColorBuffer); XClean(kiWaveColorBuffer);
XClean(kiUpperBuffer); XClean(kiUpperBuffer);
XClean(kiLowerBuffer); XClean(kiLowerBuffer);
XClean(maFastBuffer); XClean(maFastBuffer);
XClean(maSlowBuffer); XClean(maSlowBuffer);
XClean(kiStateBuffer);
XClean(atrBuffer); XClean(atrBuffer);
XClean(atrRawUpperBuffer); XClean(atrRawUpperBuffer);
XClean(atrRawLowerBuffer); XClean(atrRawLowerBuffer);
@@ -260,15 +277,18 @@ struct X121XKIConditions
XClean(kiWaveStateBuffer); XClean(kiWaveStateBuffer);
// //
ArraySetAsSeries(kiBuffer, true); ArraySetAsSeries(kiFastBuffer, true);
ArraySetAsSeries(kiColorBuffer, true); ArraySetAsSeries(kiFastColorBuffer, true);
ArraySetAsSeries(kiFastStateBuffer, true);
ArraySetAsSeries(kiSlowBuffer, true);
ArraySetAsSeries(kiSlowColorBuffer, true);
ArraySetAsSeries(kiSlowStateBuffer, true);
ArraySetAsSeries(kiWaveBuffer, true); ArraySetAsSeries(kiWaveBuffer, true);
ArraySetAsSeries(kiWaveColorBuffer, true); ArraySetAsSeries(kiWaveColorBuffer, true);
ArraySetAsSeries(kiUpperBuffer, true); ArraySetAsSeries(kiUpperBuffer, true);
ArraySetAsSeries(kiLowerBuffer, true); ArraySetAsSeries(kiLowerBuffer, true);
ArraySetAsSeries(maFastBuffer, true); ArraySetAsSeries(maFastBuffer, true);
ArraySetAsSeries(maSlowBuffer, true); ArraySetAsSeries(maSlowBuffer, true);
ArraySetAsSeries(kiStateBuffer, true);
ArraySetAsSeries(atrBuffer, true); ArraySetAsSeries(atrBuffer, true);
ArraySetAsSeries(atrRawUpperBuffer, true); ArraySetAsSeries(atrRawUpperBuffer, true);
ArraySetAsSeries(atrRawLowerBuffer, true); ArraySetAsSeries(atrRawLowerBuffer, true);
@@ -342,7 +362,8 @@ class XCX121XKIHelper : public XCBaseHelper
mPeriod, mPeriod,
"x-saherelm.x121.xki", "x-saherelm.x121.xki",
"", // Calculation ... "", // Calculation ...
mInputs.kiLength, mInputs.kiFastLength,
mInputs.kiSlowLength,
mInputs.maFastLength, mInputs.maFastLength,
mInputs.maSlowLength, mInputs.maSlowLength,
mInputs.maMethod, mInputs.maMethod,
@@ -359,7 +380,8 @@ class XCX121XKIHelper : public XCBaseHelper
mInputs.atrUpperPriceType, mInputs.atrUpperPriceType,
mInputs.atrLowerPriceType, mInputs.atrLowerPriceType,
"", // Presentation ... "", // Presentation ...
mInputs.showKI, mInputs.showKIFast,
mInputs.showKISlow,
mInputs.showMaFast, mInputs.showMaFast,
mInputs.showMaSlow, mInputs.showMaSlow,
mInputs.showKIWave, mInputs.showKIWave,
@@ -450,20 +472,35 @@ class XCX121XKIHelper : public XCBaseHelper
int zIndex = barIndex; int zIndex = barIndex;
// #region Reading Buffers ... // #region Reading Buffers ...
CopyKI( CopyKIFast(
zIndex, zIndex,
loopback, loopback,
conditions.kiBuffer // conditions.kiFastBuffer //
); );
CopyKIColor( CopyKIFastColor(
zIndex, zIndex,
loopback, loopback,
conditions.kiColorBuffer // conditions.kiFastColorBuffer //
); );
CopyKIState( CopyKIFastState(
zIndex, zIndex,
loopback, loopback,
conditions.kiStateBuffer // conditions.kiFastStateBuffer //
);
CopyKISlow(
zIndex,
loopback,
conditions.kiSlowBuffer //
);
CopyKISlowColor(
zIndex,
loopback,
conditions.kiSlowColorBuffer //
);
CopyKISlowState(
zIndex,
loopback,
conditions.kiSlowStateBuffer //
); );
CopyKIWave( CopyKIWave(
zIndex, zIndex,
@@ -533,21 +570,21 @@ class XCX121XKIHelper : public XCBaseHelper
// #endregion // #endregion
// #region Buffer Readers ... // #region Buffer Readers ...
// #region KI ... // #region KI Fast ...
// //
double GetKI( double GetKIFast(
int barIndex // Bar Index int barIndex // Bar Index
) )
{ {
// //
return ReadValue( return ReadValue(
(int)X121_XKI_KI_LINE, (int)X121_XKI_KI_FAST_LINE,
barIndex // barIndex //
); );
} }
// //
int CopyKI( int CopyKIFast(
int start, // Start int start, // Start
int count, // Number of Items for read int count, // Number of Items for read
double &buffer[], // Dest Buffer double &buffer[], // Dest Buffer
@@ -557,7 +594,7 @@ class XCX121XKIHelper : public XCBaseHelper
// //
return ReadValues( return ReadValues(
buffer, buffer,
(int)X121_XKI_KI_LINE, (int)X121_XKI_KI_FAST_LINE,
start, start,
count, count,
asSeries // asSeries //
@@ -565,21 +602,21 @@ class XCX121XKIHelper : public XCBaseHelper
} }
// #endregion // #endregion
// #region KI Color ... // #region KI Fast Color ...
// //
double GetKIColor( double GetKIFastColor(
int barIndex // Bar Index int barIndex // Bar Index
) )
{ {
// //
return ReadValue( return ReadValue(
(int)X121_XKI_KI_COLOR_LINE, (int)X121_XKI_KI_FAST_COLOR_LINE,
barIndex // barIndex //
); );
} }
// //
int CopyKIColor( int CopyKIFastColor(
int start, // Start int start, // Start
int count, // Number of Items for read int count, // Number of Items for read
double &buffer[], // Dest Buffer double &buffer[], // Dest Buffer
@@ -589,7 +626,7 @@ class XCX121XKIHelper : public XCBaseHelper
// //
return ReadValues( return ReadValues(
buffer, buffer,
(int)X121_XKI_KI_COLOR_LINE, (int)X121_XKI_KI_FAST_COLOR_LINE,
start, start,
count, count,
asSeries // asSeries //
@@ -597,21 +634,21 @@ class XCX121XKIHelper : public XCBaseHelper
} }
// #endregion // #endregion
// #region KI State ... // #region KI Fast State ...
// //
double GetKIState( double GetKIFastState(
int barIndex // Bar Index int barIndex // Bar Index
) )
{ {
// //
return ReadValue( return ReadValue(
(int)X121_XKI_KI_STATE_LINE, (int)X121_XKI_KI_FAST_STATE_LINE,
barIndex // barIndex //
); );
} }
// //
int CopyKIState( int CopyKIFastState(
int start, // Start int start, // Start
int count, // Number of Items for read int count, // Number of Items for read
double &buffer[], // Dest Buffer double &buffer[], // Dest Buffer
@@ -621,7 +658,103 @@ class XCX121XKIHelper : public XCBaseHelper
// //
return ReadValues( return ReadValues(
buffer, buffer,
(int)X121_XKI_KI_STATE_LINE, (int)X121_XKI_KI_FAST_STATE_LINE,
start,
count,
asSeries //
);
}
// #endregion
// #region KI Slow ...
//
double GetKISlow(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)X121_XKI_KI_SLOW_LINE,
barIndex //
);
}
//
int CopyKISlow(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)X121_XKI_KI_SLOW_LINE,
start,
count,
asSeries //
);
}
// #endregion
// #region KI Slow Color ...
//
double GetKISlowColor(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)X121_XKI_KI_SLOW_COLOR_LINE,
barIndex //
);
}
//
int CopyKISlowColor(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)X121_XKI_KI_SLOW_COLOR_LINE,
start,
count,
asSeries //
);
}
// #endregion
// #region KI Slow State ...
//
double GetKISlowState(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)X121_XKI_KI_SLOW_STATE_LINE,
barIndex //
);
}
//
int CopyKISlowState(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)X121_XKI_KI_SLOW_STATE_LINE,
start, start,
count, count,
asSeries // asSeries //
+170 -18
View File
@@ -33,7 +33,8 @@
// #region Inputs ... // #region Inputs ...
// //
input group "Calculation"; input group "Calculation";
input int kiLength = 26; // KI Length input int kiFastLength = 26; // KI Fast Length
input int kiSlowLength = 104; // KI Slow Length
input int maFastLength = 9; // MA Fast Length input int maFastLength = 9; // MA Fast Length
input int maSlowLength = 26; // MA Slow Length input int maSlowLength = 26; // MA Slow Length
input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Mode input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Mode
@@ -53,7 +54,8 @@ input ENUM_X_PRICE atrLowerPriceType = X_PRICE_LOW; // ATR Lower Price T
// //
// Presentation ... // Presentation ...
input group "Presentation"; input group "Presentation";
input bool showKI = true; // Show KI input bool showKIFast = true; // Show KI Fast
input bool showKISlow = true; // Show KI Slow
input bool showMaFast = true; // Show Ma Fast input bool showMaFast = true; // Show Ma Fast
input bool showMaSlow = true; // Show MA Slow input bool showMaSlow = true; // Show MA Slow
input bool showKIWave = true; // Show KI Wave input bool showKIWave = true; // Show KI Wave
@@ -85,8 +87,8 @@ input int startCalculationForLastBars = 1500; // Calculate Last n Bars
#property indicator_chart_window #property indicator_chart_window
// //
#property indicator_buffers 15 #property indicator_buffers 18
#property indicator_plots 6 #property indicator_plots 7
// #region Plot Buffers ... // #region Plot Buffers ...
// #region KI ... // #region KI ...
@@ -100,7 +102,7 @@ double kiBuffer[];
double kiColorBuffer[]; double kiColorBuffer[];
// //
#property indicator_label1 "KI" #property indicator_label1 "KI Fast"
#property indicator_type1 DRAW_COLOR_LINE #property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 CLR_NONE, clrGreen, clrRed, clrGray #property indicator_color1 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style1 STYLE_SOLID #property indicator_style1 STYLE_SOLID
@@ -110,7 +112,7 @@ double kiColorBuffer[];
// #region KI Wave ... // #region KI Wave ...
// //
#define kiWaveBufferIndex 2 #define kiWaveBufferIndex 2
#define kiWaveBufferPlotIndex 2 #define kiWaveBufferPlotIndex 1
double kiWaveBuffer[]; double kiWaveBuffer[];
// //
@@ -128,7 +130,7 @@ double kiWaveColorBuffer[];
// #region KI Upper ... // #region KI Upper ...
// //
#define kiUpperBufferIndex 4 #define kiUpperBufferIndex 4
#define kiUpperBufferPlotIndex 4 #define kiUpperBufferPlotIndex 2
double kiUpperBuffer[]; double kiUpperBuffer[];
// //
@@ -142,7 +144,7 @@ double kiUpperBuffer[];
// #region KI Lower ... // #region KI Lower ...
// //
#define kiLowerBufferIndex 5 #define kiLowerBufferIndex 5
#define kiLowerBufferPlotIndex 5 #define kiLowerBufferPlotIndex 3
double kiLowerBuffer[]; double kiLowerBuffer[];
// //
@@ -156,7 +158,7 @@ double kiLowerBuffer[];
// #region MA Fast ... // #region MA Fast ...
// //
#define maFastBufferIndex 6 #define maFastBufferIndex 6
#define maFastBufferPlotIndex 6 #define maFastBufferPlotIndex 4
double maFastBuffer[]; double maFastBuffer[];
// //
@@ -170,7 +172,7 @@ double maFastBuffer[];
// #region MA Slow ... // #region MA Slow ...
// //
#define maSlowBufferIndex 7 #define maSlowBufferIndex 7
#define maSlowBufferPlotIndex 7 #define maSlowBufferPlotIndex 5
double maSlowBuffer[]; double maSlowBuffer[];
// //
@@ -180,10 +182,28 @@ double maSlowBuffer[];
#property indicator_style6 STYLE_DOT #property indicator_style6 STYLE_DOT
#property indicator_width6 1 #property indicator_width6 1
// #endregion // #endregion
// #region KI Slow ...
//
#define kiSlowBufferIndex 8
#define kiSlowBufferPlotIndex 6
double kiSlowBuffer[];
//
#define kiSlowColorBufferIndex 9
double kiSlowColorBuffer[];
//
#property indicator_label7 "KI Slow"
#property indicator_type7 DRAW_COLOR_LINE
#property indicator_color7 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style7 STYLE_SOLID
#property indicator_width7 2
// #endregion
// #endregion // #endregion
// //
#define mLastBufferIndex 7 #define mLastBufferIndex 9
// #region Data Buffers ... // #region Data Buffers ...
// //
@@ -213,6 +233,10 @@ double kiWaveRawBuffer[];
// //
#define kiWaveStateBufferIndex mLastBufferIndex + 7 #define kiWaveStateBufferIndex mLastBufferIndex + 7
double kiWaveStateBuffer[]; double kiWaveStateBuffer[];
//
#define kiSlowStateBufferIndex mLastBufferIndex + 8
double kiSlowStateBuffer[];
// #endregion // #endregion
// #endregion // #endregion
@@ -497,7 +521,8 @@ bool ValidateInputs()
result = result =
// //
// KI ... // KI ...
kiLength >= 5 && kiFastLength >= 5 &&
kiSlowLength > kiFastLength &&
// //
// ATR ... // ATR ...
atrLength >= 5 && atrLength >= 5 &&
@@ -522,7 +547,8 @@ int ExtractMaxLengthOfInputs()
int result = 0; int result = 0;
// //
result = MathMax(kiLength, atrLength); result = MathMax(kiFastLength, atrLength);
result = MathMax(result, kiSlowLength);
result = MathMax(result, rsiLength); result = MathMax(result, rsiLength);
// //
@@ -550,7 +576,7 @@ void DefineBuffers()
SetIndexBuffer(kiBufferIndex, kiBuffer, INDICATOR_DATA); SetIndexBuffer(kiBufferIndex, kiBuffer, INDICATOR_DATA);
// //
PlotIndexSetInteger(kiBufferPlotIndex, PLOT_SHOW_DATA, showKI); PlotIndexSetInteger(kiBufferPlotIndex, PLOT_SHOW_DATA, showKIFast);
PlotIndexSetDouble(kiBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); PlotIndexSetDouble(kiBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
// //
@@ -562,6 +588,24 @@ void DefineBuffers()
SetIndexBuffer(kiStateBufferIndex, kiStateBuffer, INDICATOR_CALCULATIONS); SetIndexBuffer(kiStateBufferIndex, kiStateBuffer, INDICATOR_CALCULATIONS);
// #endregion // #endregion
// #region KI Slow ...
//
ArraySetAsSeries(kiSlowBuffer, true);
SetIndexBuffer(kiSlowBufferIndex, kiSlowBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(kiSlowBufferPlotIndex, PLOT_SHOW_DATA, showKISlow);
PlotIndexSetDouble(kiSlowBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
ArraySetAsSeries(kiSlowColorBuffer, true);
SetIndexBuffer(kiSlowColorBufferIndex, kiSlowColorBuffer, INDICATOR_COLOR_INDEX);
//
ArraySetAsSeries(kiSlowStateBuffer, true);
SetIndexBuffer(kiSlowStateBufferIndex, kiSlowStateBuffer, INDICATOR_CALCULATIONS);
// #endregion
// #region KI Upper ... // #region KI Upper ...
// //
ENUM_DRAW_TYPE kiUpperDrawType = showKIUpper ? DRAW_LINE : DRAW_NONE; ENUM_DRAW_TYPE kiUpperDrawType = showKIUpper ? DRAW_LINE : DRAW_NONE;
@@ -865,6 +909,19 @@ void CalculateValues(
); );
// #endregion // #endregion
// #region KI Slow ...
CalculateKISlow(
barIndex,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
// #endregion
// #region ATR (Ki Upper/Lower) ... // #region ATR (Ki Upper/Lower) ...
CalculateATR( CalculateATR(
barIndex, barIndex,
@@ -943,8 +1000,8 @@ void CalculateKI(
if (isInited) if (isInited)
{ {
// //
double iLLKI = iBar.FindLowest(kiLength, MODE_LOW); double iLLKI = iBar.FindLowest(kiFastLength, MODE_LOW);
double iHHKI = iBar.FindHighest(kiLength, MODE_HIGH); double iHHKI = iBar.FindHighest(kiFastLength, MODE_HIGH);
// //
iKI = (iHHKI + iLLKI) / 2; iKI = (iHHKI + iLLKI) / 2;
@@ -967,7 +1024,7 @@ void CalculateKI(
// //
iKIState = bullishState; iKIState = bullishState;
iKIColor = iKIColor =
!showKI !showKIFast
? hideColorIDX ? hideColorIDX
: bullishColorIDX; : bullishColorIDX;
} }
@@ -976,7 +1033,7 @@ void CalculateKI(
// //
iKIState = bearishState; iKIState = bearishState;
iKIColor = iKIColor =
!showKI !showKIFast
? hideColorIDX ? hideColorIDX
: bearishColorIDX; : bearishColorIDX;
} }
@@ -987,6 +1044,101 @@ void CalculateKI(
iBar.Clean(); iBar.Clean();
} }
/**
* Calculate KI Slow Bufer ...
*
* @param barIndex: int, Specified Bar Index ...
* @param prevCalculated: int, Provides Previous Calculated Bars ...
* @param ratesTotal: int, Provides All Availabled Bars ...
* @param open: double Collection, Provides Open Prices Time Series ...
* @param high: double Collection, Provides High Prices Time Series ...
* @param close: double Collection, Provides Close Prices Time Series ...
* @param low: double Collection, Provides Low Prices Time Series ...
* @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ...
*/
void CalculateKISlow(
int barIndex,
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int lastBarIndex = barIndex + 1;
bool isFirstBar =
startCalculationForLastBars > 0
? barIndex == startCalculationForLastBars
: barIndex == firstBarIndex;
//
XOHCL iBar;
bool isInited = iBar.Init(
_Symbol,
_Period,
barIndex //
);
//
double iClose = close[barIndex];
//
// Calculate KI / Color ...
double lastKI =
isFirstBar
? emptyValue
: kiSlowBuffer[lastBarIndex];
double iKI = lastKI;
if (isInited)
{
//
double iLLKI = iBar.FindLowest(kiSlowLength, MODE_LOW);
double iHHKI = iBar.FindHighest(kiSlowLength, MODE_HIGH);
//
iKI = (iHHKI + iLLKI) / 2;
if (iLLKI == 0 || iHHKI == 0)
{
iKI = lastKI;
}
}
else
{
iKI = lastKI;
}
kiSlowBuffer[barIndex] = iKI;
//
double iKIState = neuturalState;
double iKIColor = neuturalColorIDX;
if (iClose > iKI)
{
//
iKIState = bullishState;
iKIColor =
!showKISlow
? hideColorIDX
: bullishColorIDX;
}
else if (iClose < iKI)
{
//
iKIState = bearishState;
iKIColor =
!showKISlow
? hideColorIDX
: bearishColorIDX;
}
kiSlowStateBuffer[barIndex] = iKIState;
kiSlowColorBuffer[barIndex] = iKIColor;
//
iBar.Clean();
}
/** /**
* Calculate ATR and Ki Upper/Lower Buffers ... * Calculate ATR and Ki Upper/Lower Buffers ...
* *
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,973 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class
// -------------------------------------------------
// Name: XCX121XKIPoiDetector ...
// Description: X121XKI POI Detector Class ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm X121XKI POI Detector Class"
#property strict
//
// Imports ...
#include "../../Classes/x-saherelm.base.class.mq5"
#include "../../Classes/x-saherelm.x-bar.analyser.class.mq5"
#include "../../Classes/x-saherelm.x-market.pattern.class.mq5"
#include "../../Helpers/x-saherelm.x121.xki.helper.mq5"
#include "../Classes/x-saherelm.x121.xki.parser.class.mq5"
//
// Definitions ...
//
// Implementation ...
class XCX121XKIPOIDetector : public XCMarketPatternDetector
{
//
// Public ...
public:
//
// Props ...
//
string symbol;
ENUM_TIMEFRAMES period;
//
XCBarAnalyser *barAnalyser; // Bar Analyser ...
XCX121XKIHelper *kiHelper; // X121XKI Helper ...
XCX121XKIHelperParser *kiParser; // X121XKI Helper Parser ...
//
// Constructor ...
XCX121XKIPOIDetector(
XCX121XKIHelper *_kiHelper,
XCX121XKIHelperParser *_kiParser //
) : XCMarketPatternDetector()
{
//
barAnalyser = new XCBarAnalyser();
kiHelper = _kiHelper;
kiParser = _kiParser;
//
symbol = kiHelper.GetSymbol();
period = kiHelper.GetPeriod();
}
//
// Deconstructor ...
~XCX121XKIPOIDetector()
{
Destroy();
}
//
// Actions and Tools ...
// #region POI Detectors ...
bool NearestKIFastBullish(
int &index,
int barIndex = 0,
int loopback = 50 //
)
{
//
bool result = false;
//
index = -1;
//
// Normalize ...
barIndex = kiParser.NormalizeBarIndex(barIndex);
//
// Loop Back ...
bool isPassed = false;
for (int i = barIndex; i < barIndex + loopback; i++)
{
//
isPassed = kiParser.IsKIFastBullish(i);
if (isPassed)
{
//
index = i;
break;
}
}
//
result = IsValidIndex(index);
//
return result;
}
bool NearestKIFastBearish(
int &index,
int barIndex = 0,
int loopback = 50 //
)
{
//
bool result = false;
//
index = -1;
//
// Normalize ...
barIndex = kiParser.NormalizeBarIndex(barIndex);
//
// Loop Back ...
bool isPassed = false;
for (int i = barIndex; i < barIndex + loopback; i++)
{
//
isPassed = kiParser.IsKIFastBearish(i);
if (isPassed)
{
//
index = i;
break;
}
}
//
result = IsValidIndex(index);
//
return result;
}
bool NearestKIFastSwitchedToBullish(
int &index,
int barIndex = 0,
int loopback = 50 //
)
{
//
bool result = false;
//
index = -1;
//
// Normalize ...
barIndex = kiParser.NormalizeBarIndex(barIndex);
//
// Loop Back ...
bool isPassed = false;
for (int i = barIndex; i < barIndex + loopback; i++)
{
//
isPassed = kiParser.IsKIFastSwitchedToBullish(i);
if (isPassed)
{
//
index = i;
break;
}
}
//
result = IsValidIndex(index);
//
return result;
}
bool NearestKIFastSwitchedToBearish(
int &index,
int barIndex = 0,
int loopback = 50 //
)
{
//
bool result = false;
//
index = -1;
//
// Normalize ...
barIndex = kiParser.NormalizeBarIndex(barIndex);
//
// Loop Back ...
bool isPassed = false;
for (int i = barIndex; i < barIndex + loopback; i++)
{
//
isPassed = kiParser.IsKIFastSwitchedToBearish(i);
if (isPassed)
{
//
index = i;
break;
}
}
//
result = IsValidIndex(index);
//
return result;
}
bool NearestKISlowBullish(
int &index,
int barIndex = 0,
int loopback = 50 //
)
{
//
bool result = false;
//
index = -1;
//
// Normalize ...
barIndex = kiParser.NormalizeBarIndex(barIndex);
//
// Loop Back ...
bool isPassed = false;
for (int i = barIndex; i < barIndex + loopback; i++)
{
//
isPassed = kiParser.IsKISlowBullish(i);
if (isPassed)
{
//
index = i;
break;
}
}
//
result = IsValidIndex(index);
//
return result;
}
bool NearestKISlowBearish(
int &index,
int barIndex = 0,
int loopback = 50 //
)
{
//
bool result = false;
//
index = -1;
//
// Normalize ...
barIndex = kiParser.NormalizeBarIndex(barIndex);
//
// Loop Back ...
bool isPassed = false;
for (int i = barIndex; i < barIndex + loopback; i++)
{
//
isPassed = kiParser.IsKISlowBearish(i);
if (isPassed)
{
//
index = i;
break;
}
}
//
result = IsValidIndex(index);
//
return result;
}
bool NearestKISlowSwitchedToBullish(
int &index,
int barIndex = 0,
int loopback = 50 //
)
{
//
bool result = false;
//
index = -1;
//
// Normalize ...
barIndex = kiParser.NormalizeBarIndex(barIndex);
//
// Loop Back ...
bool isPassed = false;
for (int i = barIndex; i < barIndex + loopback; i++)
{
//
isPassed = kiParser.IsKISlowSwitchedToBullish(i);
if (isPassed)
{
//
index = i;
break;
}
}
//
result = IsValidIndex(index);
//
return result;
}
bool NearestKISlowSwitchedToBearish(
int &index,
int barIndex = 0,
int loopback = 50 //
)
{
//
bool result = false;
//
index = -1;
//
// Normalize ...
barIndex = kiParser.NormalizeBarIndex(barIndex);
//
// Loop Back ...
bool isPassed = false;
for (int i = barIndex; i < barIndex + loopback; i++)
{
//
isPassed = kiParser.IsKISlowSwitchedToBearish(i);
if (isPassed)
{
//
index = i;
break;
}
}
//
result = IsValidIndex(index);
//
return result;
}
// #endregion
// #region Detectors ...
bool IsBullishPOI(int barIndex = 0)
{
//
bool result = false;
//
barIndex = kiParser.NormalizeBarIndex(barIndex);
//
result = kiParser.IsTrendBullish(barIndex) &&
kiParser.IsRSIBullish(barIndex);
if (!result)
{
return result;
}
//
// Add candlestick confirmation ...
XOHCL bar;
ENUM_X_DIRECTION dir;
result = result &&
bar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
result = result &&
IsPinnedBar(bar, dir) &&
IsXBullish(dir);
//
bar.Clean();
//
return result;
}
bool IsBearishPOI(int barIndex = 0)
{
//
bool result = false;
//
barIndex = kiParser.NormalizeBarIndex(barIndex);
//
result = kiParser.IsTrendBearish(barIndex) &&
kiParser.IsRSIBearish(barIndex);
if (!result)
{
return result;
}
//
// Add candlestick confirmation ...
XOHCL bar;
ENUM_X_DIRECTION dir;
result = result &&
bar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
result = result &&
IsPinnedBar(bar, dir) &&
IsXBearish(dir);
//
bar.Clean();
//
return result;
}
bool IsBullishBreakoutPOI(int barIndex = 0)
{
//
bool result = false;
//
barIndex = kiParser.NormalizeBarIndex(barIndex);
//
result = kiParser.IsBullishBreakout(barIndex);
if (!result)
{
return result;
}
//
// Add candlestick confirmation ...
XOHCL bar;
ENUM_X_DIRECTION dir;
result = result &&
bar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
result = result &&
IsMomentumBar(bar, dir) &&
IsXBullish(dir);
//
bar.Clean();
//
return result;
}
bool IsBearishBreakoutPOI(int barIndex = 0)
{
//
bool result = false;
//
barIndex = kiParser.NormalizeBarIndex(barIndex);
//
result = kiParser.IsBearishBreakout(barIndex);
if (!result)
{
return result;
}
//
// Add candlestick confirmation ...
XOHCL bar;
ENUM_X_DIRECTION dir;
result = result &&
bar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
result = result &&
IsMomentumBar(bar, dir) &&
IsXBearish(dir);
//
bar.Clean();
//
return result;
}
bool IsBullishReversalPOI(int barIndex = 0)
{
//
bool result = false;
//
barIndex = kiParser.NormalizeBarIndex(barIndex);
//
result = kiParser.IsBullishReversal(barIndex);
if (!result)
{
return result;
}
//
// Add candlestick confirmation ...
XOHCL bar;
ENUM_X_DIRECTION dir;
result = result &&
bar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
result = result &&
IsStarPattern(bar, dir) &&
IsXBullish(dir);
//
bar.Clean();
//
return result;
}
bool IsBearishReversalPOI(int barIndex = 0)
{
//
bool result = false;
//
barIndex = kiParser.NormalizeBarIndex(barIndex);
//
result = kiParser.IsBearishReversal(barIndex);
if (!result)
{
return result;
}
//
// Add candlestick confirmation ...
XOHCL bar;
ENUM_X_DIRECTION dir;
result = result &&
bar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
result = result &&
IsStarPattern(bar, dir) &&
IsXBearish(dir);
//
bar.Clean();
//
return result;
}
bool IsBullishContinuationPOI(int barIndex = 0)
{
//
bool result = false;
//
barIndex = kiParser.NormalizeBarIndex(barIndex);
//
result = kiParser.IsTrendStrongBullish(barIndex);
if (!result)
{
return result;
}
//
// Add candlestick confirmation ...
XOHCL bar;
ENUM_X_DIRECTION dir;
result = result &&
bar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
XOHCL swingBar;
result = result &&
IsFlagPattern(bar, dir, swingBar) &&
IsXBullish(dir);
//
bar.Clean();
swingBar.Clean();
//
return result;
}
bool IsBearishContinuationPOI(int barIndex = 0)
{
//
bool result = false;
//
barIndex = kiParser.NormalizeBarIndex(barIndex);
//
result = kiParser.IsTrendStrongBearish(barIndex);
if (!result)
{
return result;
}
//
// Add candlestick confirmation ...
XOHCL bar;
ENUM_X_DIRECTION dir;
result = result &&
bar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
XOHCL swingBar;
result = result &&
IsFlagPattern(bar, dir, swingBar) &&
IsXBearish(dir);
//
bar.Clean();
swingBar.Clean();
//
return result;
}
bool IsBullishExhaustionPOI(int barIndex = 0)
{
//
bool result = false;
//
barIndex = kiParser.NormalizeBarIndex(barIndex);
//
result = kiParser.IsTrendStrongBullish(barIndex) &&
kiParser.IsRSIOverbought(barIndex);
if (!result)
{
return result;
}
//
// Add candlestick confirmation ...
XOHCL bar;
ENUM_X_DIRECTION dir;
result = result &&
bar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
result = result &&
IsPiercingPattern(bar, dir) &&
IsXBullish(dir);
//
bar.Clean();
//
return result;
}
bool IsBearishExhaustionPOI(int barIndex = 0)
{
//
bool result = false;
//
barIndex = kiParser.NormalizeBarIndex(barIndex);
//
result = kiParser.IsTrendStrongBearish(barIndex) &&
kiParser.IsRSIOversold(barIndex);
if (!result)
{
return result;
}
//
// Add candlestick confirmation ...
XOHCL bar;
ENUM_X_DIRECTION dir;
result = result &&
bar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
result = result &&
IsPiercingPattern(bar, dir) &&
IsXBearish(dir);
//
bar.Clean();
//
return result;
}
bool IsBullishTrendExhaustedPOI(int barIndex = 0)
{
//
bool result = false;
//
barIndex = kiParser.NormalizeBarIndex(barIndex);
//
result = kiParser.IsTrendStrongBullish(barIndex) &&
kiParser.IsVolatilityLow(barIndex, 20) &&
kiParser.IsRSIOverbought(barIndex);
if (!result)
{
return result;
}
//
// Add candlestick confirmation ...
XOHCL bar;
ENUM_X_DIRECTION dir;
result = result &&
bar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
result = result &&
IsPiercingPattern(bar, dir) &&
IsXBullish(dir);
//
bar.Clean();
//
return result;
}
bool IsBearishTrendExhaustedPOI(int barIndex = 0)
{
//
bool result = false;
//
barIndex = kiParser.NormalizeBarIndex(barIndex);
//
result = kiParser.IsTrendStrongBearish(barIndex) &&
kiParser.IsVolatilityLow(barIndex, 20) &&
kiParser.IsRSIOversold(barIndex);
if (!result)
{
return result;
}
//
// Add candlestick confirmation ...
XOHCL bar;
ENUM_X_DIRECTION dir;
result = result &&
bar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
result = result &&
IsPiercingPattern(bar, dir) &&
IsXBearish(dir);
//
bar.Clean();
//
return result;
}
// #endregion
// #region XDetectors ...
bool IsKISignal(
ENUM_X_DIRECTION &dir, //
int barIndex = 0 //
)
{
//
bool result = false;
//
dir = X_DIRECTION_NONE;
barIndex = kiParser.NormalizeBarIndex(barIndex);
//
// Retrieve KI State ...
bool isBullish = kiParser.IsKIFastSwitchedToBullish(barIndex + 1) &&
kiParser.IsKIFastBullish(barIndex) &&
kiParser.IsKISlowBullish(barIndex);
bool isBearish = kiParser.IsKIFastSwitchedToBearish(barIndex + 1) &&
kiParser.IsKIFastBearish(barIndex) &&
kiParser.IsKISlowBearish(barIndex);
result = isBullish ||
isBearish;
if (!result)
{
return result;
}
//
dir = isBullish
? X_DIRECTION_BULLISH
: isBearish
? X_DIRECTION_BEARISH
: X_DIRECTION_NONE;
result = HasDirection(dir);
if (!result)
{
return result;
}
//
XOHCL bar;
result = bar.Init(symbol, period, barIndex + 1);
if (!result)
{
return result;
}
//
// Bar Direction Same as Dir ...
//
// Price Place Check ...
double kiFast = kiHelper.GetKIFast(barIndex + 1);
double kiSlow = kiHelper.GetKISlow(barIndex + 1);
isBullish =
isBullish &&
bar.close > kiFast &&
kiFast > kiSlow &&
(kiParser.IsKIFastOverLast(barIndex + 1) ||
kiParser.IsKISlowOverLast(barIndex + 1));
isBearish =
isBearish &&
bar.close < kiFast &&
kiFast < kiSlow &&
(kiParser.IsKIFastUnderLast(barIndex + 1) ||
kiParser.IsKISlowUnderLast(barIndex + 1));
//
result =
result &&
(isBullish ||
isBearish);
//
// Cleanup Resources ...
bar.Clean();
//
return result;
}
// #endregion
//
// Others ...
/**
* Destroy ...
*/
void Destroy()
{
//
delete barAnalyser;
ZeroMemory(barAnalyser);
//
ZeroMemory(kiHelper);
ZeroMemory(kiParser);
}
//
// Testers ...
//
// Protected ...
protected:
//
// Props ...
//
// Private ...
private:
//
//
};
//
@@ -0,0 +1,707 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class
// -------------------------------------------------
// Name: XCX121XKIPoiDrawer ...
// Description: X121XKI POI Drawer Class ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm X121XKI POI Drawer Class"
#property strict
//
// Imports ...
#include "../../Classes/x-saherelm.x-poi.drawer.class.mq5"
//
// Implementation ...
class XCX121XKIPOIDrawer : public XCPOIDrawer
{
//
public:
//
// Props ...
//
// Tested Zones ...
color testedBullishColor;
color testedBearishColor;
//
// Breaked Zones ...
color breakedBullishColor;
color breakedBearishColor;
//
// FakeBreaked Zones ...
color fakeBreakedBullishColor;
color fakeBreakedBearishColor;
//
// Constructor ...
XCX121XKIPOIDrawer() : XCPOIDrawer()
{
Default();
}
//
// Deconstructor ...
~XCX121XKIPOIDrawer()
{
}
//
// Overrides ...
/**
* Do additional Configurations for Child Classes ...
*/
void virtual Default() override
{
//
// Apply Default Props ...
//
Prefix(NULL);
ChartIdentification(0);
SubWindowIdentification(0);
//
defaultBullishStyle.width = 1;
defaultBullishStyle.clr = clrAqua;
defaultBullishStyle.style = STYLE_SOLID;
//
defaultBearishStyle.width = 1;
defaultBearishStyle.clr = clrMagenta;
defaultBearishStyle.style = STYLE_SOLID;
//
boxBullishStyle = defaultBullishStyle;
boxBearishStyle = defaultBearishStyle;
//
testedBullishColor = clrLime;
breakedBullishColor = clrGreen;
fakeBreakedBullishColor = clrYellow;
//
testedBearishColor = clrRed;
breakedBearishColor = clrDarkRed;
fakeBreakedBearishColor = clrDarkOrange;
}
//
// Get Specified Directional Arrow Anchor ...
ENUM_ARROW_ANCHOR GetArrowAnchor(ENUM_X_DIRECTION forDir)
{
//
ENUM_ARROW_ANCHOR result = ANCHOR_BOTTOM;
//
if (HasDirection(forDir))
{
//
result =
IsSpecifiedBullish(forDir)
? ANCHOR_TOP
: ANCHOR_BOTTOM;
}
//
return result;
}
//
// Get Specified Directional Arrow Code ...
int GetArrowCode(ENUM_X_DIRECTION forDir)
{
//
int result = 159;
//
if (HasDirection(forDir))
{
//
result =
IsSpecifiedBullish(forDir)
? 233
: 234;
}
//
return result;
}
//
// Get Specified Directional Arrow Code ...
color GetArrowColor(ENUM_X_DIRECTION forDir)
{
//
color result = clrYellow;
//
if (HasDirection(forDir))
{
//
result =
IsSpecifiedBullish(forDir)
? clrAqua
: clrMagenta;
}
//
return result;
}
//
// Get Specified Directional Arrow Price Type ...
ENUM_X_PRICE GetArrowPriceType(ENUM_X_DIRECTION forDir)
{
//
ENUM_X_PRICE result = X_PRICE_CLOSE;
//
if (HasDirection(forDir))
{
//
result =
IsSpecifiedBullish(forDir)
? X_PRICE_LOW
: X_PRICE_HIGH;
}
//
return result;
}
/**
* Get Tested Zone Style ...
*
* @param style: reference to hold result ...
* @param zone: Specified Zone ...
*
* @return ( bool )
*/
bool GetTestedStyle(
XPOIStyle &style,
XBoxZone &zone //
)
{
//
bool result = false;
//
style.Clean();
//
result = zone.IsValid();
if (!result)
{
return result;
}
//
GetBoxStyle(
style,
zone.dir //
);
//
style.width = 3;
style.clr =
zone.IsBullish()
? testedBullishColor
: testedBearishColor;
//
return result;
}
/**
* Get Patterns Zone Style ...
*
* @param style: reference to hold result ...
* @param zone: Specified Zone ...
*
* @return ( bool )
*/
bool GetPatternStyle(
XPOIStyle &style,
XBoxZone &zone //
)
{
//
bool result = false;
//
style.Clean();
//
result = zone.IsValid();
if (!result)
{
return result;
}
//
GetPatternStyle(
style,
zone.dir //
);
//
return result;
}
/**
* Get Patterns Zone Style ...
*
* @param style: reference to hold result ...
* @param forDir: Specified Direction ...
*
* @return ( bool )
*/
bool GetPatternStyle(
XPOIStyle &style,
ENUM_X_DIRECTION forDir //
)
{
//
bool result = false;
//
style.Clean();
//
result = HasDirection(forDir);
if (!result)
{
return result;
}
//
GetBoxStyle(
style,
forDir //
);
//
style.width = 2;
style.style = STYLE_DASH;
//
return result;
}
/**
* Get Breaked Zone Style ...
*
* @param style: reference to hold result ...
* @param zone: Specified Zone ...
*
* @return ( bool )
*/
bool GetBreakedStyle(
XPOIStyle &style,
XBoxZone &zone //
)
{
//
bool result = false;
//
style.Clean();
//
result = zone.IsValid();
if (!result)
{
return result;
}
//
GetBoxStyle(
style,
zone.dir //
);
//
style.width = 3;
style.clr =
zone.IsBullish()
? breakedBullishColor
: breakedBearishColor;
//
return result;
}
/**
* Get Fake Breaked Zone Style ...
*
* @param style: reference to hold result ...
* @param zone: Specified Zone ...
*
* @return ( bool )
*/
bool GetFakeBreakedStyle(
XPOIStyle &style,
XBoxZone &zone //
)
{
//
bool result = false;
//
style.Clean();
//
result = zone.IsValid();
if (!result)
{
return result;
}
//
GetBoxStyle(
style,
zone.dir //
);
//
style.width = 3;
style.clr =
zone.IsBullish()
? fakeBreakedBullishColor
: fakeBreakedBearishColor;
//
return result;
}
/**
* Fill Arrow Based Drawing Specs ...
*
* @param forDir: Specified Direction ...
* @param arrowPriceType: ENUM_X_PRICE, refrence for Arrow Price ...
* @param arrowCode: int, reference for Arrow Code ...
* @param arrowWidth: int, reference for Arrow Width ...
* @param arrowColor: color, reference for Arrow Color ...
* @param arrowAnchor: ENUM_ARROW_ANCHOR, reference for Arrow Anchor ...
*/
void FillArrowSpecs(
ENUM_X_DIRECTION forDir,
ENUM_X_PRICE &arrowPriceType,
int &arrowCode,
int &arrowWidth,
color &arrowColor,
ENUM_ARROW_ANCHOR &arrowAnchor //
)
{
//
// Prepare ...
arrowCode = 159;
arrowWidth = 2;
arrowColor = CLR_NONE;
arrowAnchor = ANCHOR_BOTTOM;
arrowPriceType = X_PRICE_CLOSE;
//
if (HasDirection(forDir))
{
//
arrowCode = GetArrowCode(forDir);
arrowColor = GetArrowColor(forDir);
arrowAnchor = GetArrowAnchor(forDir);
arrowPriceType = GetArrowPriceType(forDir);
}
}
/**
* Apply Tested Style ...
*
* @param object: reference pointer to Object ...
* @param zone: reference to Zone ...
*/
void ApplyTestedStyle(
XCBoxObject *&object,
XBoxZone &zone //
)
{
//
if (!zone.IsValid() ||
object == NULL)
{
return;
}
//
XPOIStyle style;
if (!GetTestedStyle(style, zone))
{
return;
}
//
ApplyBoxStyle(
object,
style //
);
}
/**
* Apply Breaked Style ...
*
* @param object: reference pointer to Object ...
* @param zone: reference to Zone ...
*/
void ApplyBreakedStyle(
XCBoxObject *&object,
XBoxZone &zone //
)
{
//
if (!zone.IsValid() ||
object == NULL)
{
return;
}
//
XPOIStyle style;
if (!GetBreakedStyle(style, zone))
{
return;
}
//
ApplyBoxStyle(
object,
style //
);
}
/**
* Apply Tested Style ...
*
* @param object: reference pointer to Object ...
* @param zone: reference to Zone ...
*/
void ApplyFakeBreakStyle(
XCBoxObject *&object,
XBoxZone &zone //
)
{
//
if (!zone.IsValid() ||
object == NULL)
{
return;
}
//
XPOIStyle style;
if (!GetFakeBreakedStyle(style, zone))
{
return;
}
//
ApplyBoxStyle(
object,
style //
);
}
/**
* Apply Pattern Style ...
*
* @param object: reference pointer to Object ...
* @param zone: reference to Zone ...
*/
void ApplyPatternStyle(
XCBoxObject *&object,
XBoxZone &zone //
)
{
//
if (!zone.IsValid() ||
object == NULL)
{
return;
}
//
XPOIStyle style;
if (!GetPatternStyle(style, zone))
{
return;
}
//
ApplyBoxStyle(
object,
style //
);
}
/**
* Apply Patterns Style ...
*
* @param object: reference pointer to Object ...
*/
void ApplyPatternsStyle(
CArrayObj *&objects //
)
{
//
if (objects == NULL ||
objects.Total() == 0)
{
return;
}
//
bool has = false;
XPOIStyle iStyle;
string iName = NULL;
XCBoxObject *iBoxObj = NULL;
ENUM_X_DIRECTION iDir = X_DIRECTION_NONE;
for (int i = 0; i < objects.Total(); i++)
{
//
iBoxObj = (XCBoxObject *)objects.At(i);
iName = iBoxObj.ObjName();
//
iDir =
IsSpecifiedValid(iName) &&
Contains(
"BULL",
iName //
)
? X_DIRECTION_BULLISH
: IsSpecifiedValid(iName) &&
Contains(
"BEAR",
iName //
)
? X_DIRECTION_BEARISH
: X_DIRECTION_NONE;
//
has = GetPatternStyle(iStyle, iDir);
if (has)
{
//
ApplyBoxStyle(
iBoxObj,
iStyle //
);
}
//
iStyle.Clean();
ZeroMemory(iBoxObj);
}
}
/**
* Apply Style to Specified Pivot Object ...
*
* @param object: reference pointer to Object ...
* @param zone: reference to Zone ...
*/
void ApplyPivotStyle(
XCBarArrowObject *&object,
XPOIStyle &style //
)
{
//
if (object == NULL)
{
return;
}
//
object.ArrowColor(style.clr);
object.ArrowWidth(style.width);
}
/**
* Apply Patterns Style ...
*
* @param object: reference pointer to Object ...
*/
void ApplyPivotsStyle(
CArrayObj *&objects //
)
{
//
if (objects == NULL ||
objects.Total() == 0)
{
return;
}
//
bool has = false;
XPOIStyle iStyle;
string iName = NULL;
XCBarArrowObject *iObj = NULL;
ENUM_X_DIRECTION iDir = X_DIRECTION_NONE;
for (int i = 0; i < objects.Total(); i++)
{
//
iObj = (XCBarArrowObject *)objects.At(i);
iName = iObj.ObjName();
//
iDir =
IsSpecifiedValid(iName) &&
Contains(
"BULL",
iName //
)
? X_DIRECTION_BULLISH
: IsSpecifiedValid(iName) &&
Contains(
"BEAR",
iName //
)
? X_DIRECTION_BEARISH
: X_DIRECTION_NONE;
//
has = GetPatternStyle(iStyle, iDir);
if (has)
{
//
ApplyPivotStyle(
iObj,
iStyle //
);
}
//
iStyle.Clean();
ZeroMemory(iObj);
}
}
//
};
//