commit dac3101466f6e5227764147926664ed84c54120f Author: Hadi Khazaee Asl Date: Thu Jan 25 04:05:58 2024 +0330 Initial Commit ... diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e79ca76 --- /dev/null +++ b/.gitignore @@ -0,0 +1,44 @@ +# +SharedProjects/* +Scripts/* +Projects/* +Presets/* +Logs/* +Include/* +Images/* +Files/* + +# +*.dat +*.ex4 +Indicators/Examples/* + +# +ZigZag.mq4 +Stochastic.mq4 +RSI.mq4 +Parabolic.mq4 +OsMA.mq4 +MACD.mq4 +Momentum.mq4 +iExposure.mq4 +Ichimoku.mq4 +Heiken Ashi.mq4 +Custom Moving Averages.mq4 +CCI.mq4 +Bulls.mq4 +Bears.mq4 +Bands.mq4 +Awesome.mq4 +ATR.mq4 +Alligator.mq4 +Accumulation.mq4 +Accelerator.mq4 +stdlib.mq4 +MACD Sample.mq4 +Moving Average.mq4 + +# +# Node Based ... +Publishes/* +!Publishes/.gitkeep \ No newline at end of file diff --git a/.gitkeep b/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..1569039 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "C_Cpp.errorSquiggles": "disabled", + "C_Cpp.intelliSenseEngineFallback": "enabled", + "C_Cpp.default.compilerPath": "" +} \ No newline at end of file diff --git a/.vscode/vscode-kanban.json b/.vscode/vscode-kanban.json new file mode 100644 index 0000000..7d281cd --- /dev/null +++ b/.vscode/vscode-kanban.json @@ -0,0 +1,16 @@ +{ + "todo": [ + { + "assignedTo": { + "name": "Hadi Khazaee Asl" + }, + "creation_time": "2023-06-22T02:10:44.343Z", + "id": "2", + "references": [], + "title": "Complete Panel for OSC" + } + ], + "in-progress": [], + "testing": [], + "done": [] +} \ No newline at end of file diff --git a/Bkp/BTCUSD-15M/Experts/x-saherelm.ea.mq4 b/Bkp/BTCUSD-15M/Experts/x-saherelm.ea.mq4 new file mode 100644 index 0000000..d8a63ca --- /dev/null +++ b/Bkp/BTCUSD-15M/Experts/x-saherelm.ea.mq4 @@ -0,0 +1,1038 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XST Strategy Expert Advisor +// --------------------------------------------- +// saherelm implementation of strategy expert advisor ... +// in this EA, we try to combine multiple tools, to ashive best +// results ... +// +// ShortName: XST +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +989121694056 +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XST Strategy Expert Advisor" +#property strict + +// +// START Inputs ... +// +// +// Signal Prefixe ... +input string signalPrefix = "XST_EA"; // Signal Prefix + +// +// Signal Draw Specifications ... +input string bullishSignalLabel = "X_BUY"; // Bullish Signal Label +input color bullishSignalColor = clrAqua; // Bullish Signal Color + +// +input string bearishSignalLabel = "X_SELL"; // Bearish Signal Label +input color bearishSignalColor = clrFuchsia; // Bearish Signal Color + +// +input color signalEntryColor = clrAquamarine; // Signal Entry Ptice Color +input color signalSLColor = clrRed; // Signal SL Color +input color signalTPColor = clrGreen; // Signal TP Color + +// +input int candleGapBetweenSignals = 7; // How many Candle waits to new Signal from last one + +// +// Trade ... +input bool allowTrade = true; // Allow Trade Based on given Signals +input bool allowLongTrades = true; // Allow Long Trades +input bool allowShortTrades = true; // Allow Short Trades + +// +// Alerts ... +input bool alertEvents = true; // Alert Events +input bool alertPositions = true; // Alert Positions +input bool longPositionAlerts = true; // Alert Long Positions +input bool shortPositionAlerts = true; // Alert Short Positions + +// +// Alert Types ... +input bool terminalAlert = false; // Terminal Alert +input bool pushAlert = false; // Push Notification Alerts + +// +// Balance and Finanical Specifications ... +input double lotsPerTradePercent = 0.00001; // Lots Per Trade Percent +input int maxOpenTrades = 4; // Maximum Open Trade +input double maxDrawdownPercentPerPTrade = 0.1; // Maximum DrawDown Per Trade +input double minBalancePercent = 0.5; // Minimum Balance for Trading +input double maxEquityPercent = 0.1; // Maximum Trade Equity + +// +// START Global Definitions: Variables, Properties and etc ... +// +int lastSignalledBar = 0; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.signal.lib.mq4" + +// +int maxMarketLength = 0; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Validate Inputs ... + bool inputsNotValiid = + // + // EA ... + maxOpenTrades <= 0 + || maxEquityPercent < 0 + || minBalancePercent < 0 + || lotsPerTradePercent < 0 + || maxDrawdownPercentPerPTrade < 0 + ; + + // + if (inputsNotValiid) { + return INIT_PARAMETERS_INCORRECT; + } + + // + totalSignals = 0; + totalLongSignals = 0; + totalShortSignals = 0; + + // + initialBalance = 0; + + // + // START Define Array Series ... + // + // + // END Define Array Series ... + // + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST"; + + // + ClearSignalConditions(); + + // + maxMarketLength = MathMax(0, GetDailyCandleCount()); + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { +} + +// +// Ticker Event Handler ... +void OnTick() { + // + isNewDay = IsNewDay(); + if (isNewDay) { + // + LogMessage( + StringConcatenate( + "New Day ..." + ) + ); + } + + // + // Process Signals to Open Positions ... + ProcessSignals(); + + // + // Checking State for Signal Handling ... + CheckState(); + + // + // Process Open Positions for Trailing Stop Loss or Close ... + ProcessOpenPositions(); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Check State for Signal Handling ... +void CheckState() { + // + // Here we Must to Check Market State for enable or disable + // Signal Handlers and also make dection to close all long/short + // trades ... +} + +// +// Calculate Signals and Process Based on Exists Signals ... +void ProcessSignals() { + // + XSignalRequest request = {}; + request.type = X_SIGNAL_NONE; + request.hasSignal = false; + + // + // Prevent Multiple Calculating on Same Bars ... + isNewBar = IsNewBar(); + if (isNewBar) { + countedBars++; + } + + // + if (countedBars < maxMarketLength) { + return; + } + + // + bool allowDoTrade = true; + + // + // Check Balance ... + if (initialBalance > 0) { + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double minimumBalanceForTrade = + balance > initialBalance + ? + minBalancePercent * balance + : + minBalancePercent * initialBalance; + + // + // Retrieve Account Equity ... + double equity = AccountInfoDouble(ACCOUNT_EQUITY); + double maxAllowedEquity = balance - (balance * maxEquityPercent); + + // + // Retrieve Free Marigin ... + double freeMargin = AccountFreeMargin(); + double maximumMariginRisk = balance - (balance * maxEquityPercent); + + // + if ( + // + // Do not Open Positions if equity not passed ... + equity < maxAllowedEquity || + // + // Do not Open Positions if free margin not passed ... + freeMargin <= maximumMariginRisk || + // + // Do not open positions if balance less than minimum ... + balance <= minimumBalanceForTrade + ) { + // + static bool tradingPauseAlerted; + + // + allowDoTrade = false; + + // + if (!tradingPauseAlerted) { + // + string message = StringConcatenate( + "Trading Pause => ", + "Balance: ", balance, + ", Equity: ", equity, + ", FreeMargin: ", freeMargin + ); + + // + LogMessage(message); + SendAlert(message); + + // + tradingPauseAlerted = true; + } + } + } + + // + // Retrieve Signal Exists ... + request = GenerateSignal(0); + + // + // Prevent doing anything else, if there is no signals ... + if ( + !allowDoTrade || + !request.hasSignal || + request.type == X_SIGNAL_NONE + ) { + return; + } + + // + bool hasLongSignal = request.type == X_SIGNAL_LONG; + + // + // Check last Signalled Bar with Counted Bars ... + // Prevent Multiple Signalling on Same Bar ... + bool isInLastSignalledBars = false; + for (int i=0; i < candleGapBetweenSignals; i++) { + // + isInLastSignalledBars = + isInLastSignalledBars + || lastSignalledBar == countedBars - i + ; + } + if (isInLastSignalledBars) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + return; + } + + // + // increase last signalled bar ... + lastSignalledBar = countedBars; + + // + // Calculate Can Trade or not ... + allowDoTrade = allowTrade + && ( + hasLongSignal ? + allowLongTrades : + allowShortTrades + ); + + // + // Chack Maximum Open Positions ... + int openTrades = CountOpenTrades(); + if (maxOpenTrades > 0) { + // + if (openTrades >= maxOpenTrades) { + // + allowDoTrade = false; + + // + if (!allowDoTrade) { + // + string message = StringConcatenate( + "Trading Pause => ", + "Max Open Trades (", + maxOpenTrades, + ") reached ..." + ); + + // + LogMessage(message); + SendAlert(message); + } + } + } + + // + // Check Trading is Enable or not ... + // nothing to do if trading is disabled ... + if (!allowDoTrade) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + string message = StringConcatenate( + "Trading Not Allowed ..." + ); + + // + LogMessage(message); + SendAlert(message); + return; + } + + // + // Retrieve Signal Lots Per Trade ... + double lPTradePercent = GetSignalLottage( + request.signal, + lotsPerTradePercent + ); + + // + bool isPositionOpened = TradeSignal( + request.signal, + lPTradePercent, + // + bullishSignalLabel, + bullishSignalColor, + bearishSignalLabel, + bearishSignalColor + ); + + // + totalSignals++; + if (hasLongSignal) { + // + totalLongSignals++; + ClearLongSignalConditions(); + } else { + // + totalShortSignals++; + ClearShortSignalConditions(); + } + + // + if (isPositionOpened) { + // + bool canAlert = + alertPositions + && ( + hasLongSignal ? + longPositionAlerts + : + shortPositionAlerts + ); + + // + if (canAlert) { + // + // Alert Message ... + string message = StringConcatenate( + "Trade on Signal ID: ", request.signal.id, + ", ProvidedBy: ", GetSignalProviderIdentifier(request.signal.provider), + ", Entry: ", request.signal.entry, + ", TP: ", request.signal.tp + ); + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } + } + } +} + +// +// Process All Open Positions ... +void ProcessOpenPositions() { + // + // XSignalling ... + if (enableXSignalling) { + // + // Close All XXX Provided Signals on it's Specific Condition ... + if (xCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XXX_PROVIDER); + + // + xCloseLongTrades = false; + } + + // + if (xCloseShortTrades) { + // + CloseAllProviderShortTrades(X_XTPW_PROVIDER); + + // + xCloseShortTrades = false; + } + + // + // Close Maximum DrawDown Passed Trades ... + + // + // Longs ... + bool hasClosedLongInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xLongMaxDrawdownPerTradePercent, + X_SIGNAL_LONG, + X_XXX_PROVIDER + ); + + // + // Shorts ... + bool hasClosedShortInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xShortMaxDrawdownPerTradePercent, + X_SIGNAL_SHORT, + X_XXX_PROVIDER + ); + + // + // Close All Long Time Trades based on Provider provided Length ... + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + xMaximumCandlesPerTrade, + X_XXX_PROVIDER + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedLongInDrawDownLongTrade + || hasClosedShortInDrawDownLongTrade + ) { + xFailedSignals++; + } + } + + // + // XR Signalling ... + if (enableXRSignalling) { + // + if (xRCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XR_PROVIDER); + + // + xRCloseLongTrades = false; + } + + // + if (xRCloseShortTrades) { + // + CloseAllProviderShortTrades(X_XR_PROVIDER); + + // + xRCloseShortTrades = false; + } + + // + // Close Maximum DrawDown Passed Trades ... + + // + // Longs ... + bool hasClosedLongInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xRLongMaxDrawdownPerTradePercent, + X_SIGNAL_LONG, + X_XR_PROVIDER + ); + + // + // Shorts ... + bool hasClosedShortInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xRShortMaxDrawdownPerTradePercent, + X_SIGNAL_SHORT, + X_XR_PROVIDER + ); + + // + // Close All Long Time Trades based on Provider provided Length ... + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + xRMaximumCandlesPerTrade, + X_XR_PROVIDER + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedLongInDrawDownLongTrade + || hasClosedShortInDrawDownLongTrade + ) { + xRFailedSignals++; + } + } + + // + // XTPW Signalling ... + if (enableXTPWSignalling) { + // + if (xTPWCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XTPW_PROVIDER); + + // + xTPWCloseLongTrades = false; + } + + // + if (xTPWCloseShortTrades) { + // + CloseAllProviderShortTrades(X_XTPW_PROVIDER); + + // + xTPWCloseShortTrades = false; + } + + // + // Close Maximum DrawDown Passed Trades ... + + // + // Longs ... + bool hasClosedLongInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xTPWLongMaxDrawdownPerTradePercent, + X_SIGNAL_LONG, + X_XTPW_PROVIDER + ); + + // + // Shorts ... + bool hasClosedShortInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xTPWShortMaxDrawdownPerTradePercent, + X_SIGNAL_SHORT, + X_XTPW_PROVIDER + ); + + // + // Close All Long Time Trades based on Provider provided Length ... + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + xTPWMaximumCandlesPerTrade, + X_XTPW_PROVIDER + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedLongInDrawDownLongTrade + || hasClosedShortInDrawDownLongTrade + ) { + xTPWFailedSignals++; + } + } + + // + // Close Maximum DrawDown Passed Trades ... + // this is the Maximum Controller ... + // + double maxOfXPercent = enableXSignalling ? + MathMax( + xLongMaxDrawdownPerTradePercent, + xShortMaxDrawdownPerTradePercent + ) : 0 + ; + + // + double maxOfXRPercent = enableXRSignalling ? + MathMax( + xRLongMaxDrawdownPerTradePercent, + xRShortMaxDrawdownPerTradePercent + ) : 0 + ; + + // + double maxOfXTPWPercent = enableXTPWSignalling ? + MathMax( + xTPWLongMaxDrawdownPerTradePercent, + xTPWShortMaxDrawdownPerTradePercent + ) : 0 + ; + + // + double maxDrawDownPercent = MathMax( + maxOfXPercent, + maxOfXRPercent + ); + maxDrawDownPercent = MathMax( + maxDrawDownPercent, + maxOfXTPWPercent + ); + maxDrawDownPercent = MathMax( + maxDrawDownPercent, + maxDrawdownPercentPerPTrade + ); + + // + // we Calculate Max DrawDown Percent Per Trade ... + // then try to Close based on them ... + bool hasClosedInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + maxDrawDownPercent + ); +} + +// +// Send Special Type of Alerts ... +void SendAlert(string message) { + // + if (!alertEvents) { + return; + } + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } +} +// +// END Functions ... +// + +// +// +// Calculate Signal ... +// in this function we calculate a signal exists in +// specific bar or not ... +XSignalRequest GenerateSignal( + const int bar_index // Bar Index ... +) { + // + // create temp result ... + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + bool hasSignal = false; + bool hasLongSignal = false; + bool hasShortSignal = false; + + // + XSignal signal = {}; + + // + // Define Template Signal Requests for Managing Multiple Signals ... + // + // X ... + XSignalRequest xLongSignalRequest = {}; + XSignalRequest xShortSignalRequest = {}; + // + // XR ... + XSignalRequest xrLongSignalRequest = {}; + XSignalRequest xrShortSignalRequest = {}; + // + // XTPW ... + XSignalRequest xTPWLongSignalRequest = {}; + XSignalRequest xTPWShortSignalRequest = {}; + + // + // START XR Signal Handler ... + // + // + if (enableXRSignalling) { + // + CheckXRSignalHandler( + bar_index + ); + + // + // Long Trades ... + if (allowTrade && allowLongTrades) { + // + if (xRWaitForLongSignals) { + // + CheckXRLongSignalConditions( + bar_index + ); + + // + xrLongSignalRequest = GenerateXRSignal( + X_SIGNAL_LONG, + signalPrefix, + bar_index + ); + + // + if (xrLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXRSignals( + xrLongSignalRequest.signal + ); + + // + if (isReady && xRWaitForLongSignals) { + // + hasLongSignal = true; + signal = xrLongSignalRequest.signal; + } else { + ClearXRLongSignalConditions(); + } + } + } else { + ClearXRLongSignalConditions(); + } + } + + // + // Short Trades ... + if (allowTrade && allowShortTrades) { + // + if (xRWaitForShortSignals) { + // + CheckXRShortSignalConditions( + bar_index + ); + + // + xrShortSignalRequest = GenerateXRSignal( + X_SIGNAL_SHORT, + signalPrefix, + bar_index + ); + + // + if (xrShortSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXRSignals( + xrShortSignalRequest.signal + ); + + // + if (isReady && xRWaitForShortSignals) { + // + hasShortSignal = true; + signal = xrShortSignalRequest.signal; + } else { + ClearXRShortSignalConditions(); + } + } + } else { + ClearXRShortSignalConditions(); + } + } + } + // + // END XR Signal Handler ... + // + + // + // START XTPW Signal Handler ... + // + if (enableXTPWSignalling) { + // + CheckXTPWSignalHandler( + bar_index + ); + + // + // Long Trades ... + if (allowTrade && allowLongTrades) { + // + if (xTPWWaitForLongSignals) { + // + CheckXTPWLongSignalConditions( + bar_index + ); + + // + xTPWLongSignalRequest = GenerateXTPWSignal( + X_SIGNAL_LONG, + signalPrefix, + bar_index + ); + + // + if (xTPWLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXTPWSignals( + xTPWLongSignalRequest.signal + ); + + // + if (isReady && xTPWWaitForLongSignals) { + // + hasLongSignal = true; + signal = xTPWLongSignalRequest.signal; + } else { + ClearXTPWLongSignalConditions(); + } + } + } else { + ClearXTPWLongSignalConditions(); + } + } + + // + // Short Trades ... + if (allowTrade && allowShortTrades) { + // + if (xTPWWaitForShortSignals) { + // + CheckXTPWShortSignalConditions( + bar_index + ); + + // + xTPWShortSignalRequest = GenerateXTPWSignal( + X_SIGNAL_SHORT, + signalPrefix, + bar_index + ); + + // + if (xTPWShortSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXTPWSignals( + xTPWShortSignalRequest.signal + ); + + // + if (isReady && xTPWWaitForShortSignals) { + // + hasShortSignal = true; + signal = xTPWShortSignalRequest.signal; + } else { + ClearXTPWShortSignalConditions(); + } + } + } else { + ClearXTPWShortSignalConditions(); + } + } + } + // + // END XTPW Signal Handler ... + // + + // + // START X Signal Handler ... + // + // + if (enableXSignalling) { + // + CheckXSignalHandler( + bar_index + ); + + // + // Long Trades ... + if (allowTrade && allowLongTrades) { + // + if (xWaitForLongSignals) { + // + CheckXLongSignalConditions( + bar_index + ); + + // + xLongSignalRequest = GenerateXSignal( + X_SIGNAL_LONG, + signalPrefix, + bar_index + ); + + // + if (xLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXSignals( + xLongSignalRequest.signal + ); + + // + if (isReady && xWaitForLongSignals) { + // + hasLongSignal = true; + signal = xLongSignalRequest.signal; + } else { + ClearXLongSignalConditions(); + } + } + } else { + ClearXLongSignalConditions(); + } + } + + // + // Short Trades ... + if (allowTrade && allowShortTrades) { + // + if (xWaitForShortSignals) { + // + CheckXShortSignalConditions( + bar_index + ); + + // + xShortSignalRequest = GenerateXSignal( + X_SIGNAL_SHORT, + signalPrefix, + bar_index + ); + + // + if (xShortSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXSignals( + xShortSignalRequest.signal + ); + + // + if (isReady && xWaitForShortSignals) { + // + hasShortSignal = true; + signal = xShortSignalRequest.signal; + } else { + ClearXShortSignalConditions(); + } + } + } else { + ClearXShortSignalConditions(); + } + } + } + // + // END XR Signal Handler ... + // + + // + hasSignal = hasLongSignal || hasShortSignal; + + // + if (!hasSignal) { + // + signal.type = X_SIGNAL_NONE; + result.type = X_SIGNAL_NONE; + } + + // + // Normalize TP, SL and Entry Price ... + signal.tp = NormalizeDouble(signal.tp, _Digits); + signal.sl = NormalizeDouble(signal.sl, _Digits); + signal.entry = NormalizeDouble(signal.entry, _Digits); + + // + result.signal = signal; + result.type = signal.type; + result.hasSignal = hasSignal; + result.provider = signal.provider; + + // + // Return Result ... + return result; +} diff --git a/Bkp/BTCUSD-15M/Indicators/x-saherelm.ma.mq4 b/Bkp/BTCUSD-15M/Indicators/x-saherelm.ma.mq4 new file mode 100644 index 0000000..e3a5737 --- /dev/null +++ b/Bkp/BTCUSD-15M/Indicators/x-saherelm.ma.mq4 @@ -0,0 +1,173 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MA Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 MA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Fast MA ... +input int maLength = 20; // MA Length +input int maShift = 0; // MA Shift +input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method +input ENUM_APPLIED_PRICE maAppliedPrice = PRICE_CLOSE; // MA Applied Price + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 1 + +// +#property indicator_plots 1 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Fast Ma Buffer ... +#property indicator_label1 "Ma" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrYellow +#property indicator_style1 STYLE_DOT +#property indicator_width1 2 + +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define maBufferIndex 0 + +double maBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (maLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + // + // Ma ... + SetIndexBuffer(maBufferIndex, maBuffer); + SetIndexDrawBegin(maBufferIndex, maLength + 1); + // + // End Set Index Buffers ... + // + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, maLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Ma ... + CalculateMa(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateMa( + const int &bar_index +) { + // + // Calculating Fast Ma ... + double ma = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + maAppliedPrice, + bar_index + ); + + // + maBuffer[bar_index] = ma; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/BTCUSD-15M/Indicators/x-saherelm.xrange.mq4 b/Bkp/BTCUSD-15M/Indicators/x-saherelm.xrange.mq4 new file mode 100644 index 0000000..1359f57 --- /dev/null +++ b/Bkp/BTCUSD-15M/Indicators/x-saherelm.xrange.mq4 @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XRange Indicator +// --------------------------------------------- +// saherelm implementation of above 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 XRange Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 14; +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 3 + +// +#property indicator_plots 3 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Highest High Buffer ... +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +// Lowest Low Buffer ... +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +// Middle Buffer ... +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_DASH +#property indicator_width3 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +// +#define highestHighBufferIndex 0 +#define lowestLowBufferIndex 1 +#define middleBufferIndex 2 + +// +double highestHighBuffer[]; +double lowestLowBuffer[]; +double middleBuffer[]; + +// +datetime startTime; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if ( + marketLength <= 0 + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + string hhLbl = StringConcatenate( + "XR HH(", marketLength, ")" + ); + SetIndexBuffer(highestHighBufferIndex, highestHighBuffer); + SetIndexLabel(highestHighBufferIndex, hhLbl); + + // + string llLbl = StringConcatenate( + "XR LL(", marketLength, ")" + ); + SetIndexBuffer(lowestLowBufferIndex, lowestLowBuffer); + SetIndexLabel(lowestLowBufferIndex, llLbl); + + // + string midLbl = StringConcatenate( + "XR Mid(", marketLength, ")" + ); + SetIndexBuffer(middleBufferIndex, middleBuffer); + SetIndexLabel(middleBufferIndex, midLbl); + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculations ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculations ... +void CalculateBuffers( + const int &bar_index +) { + // + // Retrieve Bar Time ... + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + if (startTime == 0) { + // + startTime = barTime; + SetIndicatorBuffersNone(bar_index); + return; + } + + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + startTime + ); + + // + int startDistance = startBarIndex - bar_index; + if (startDistance < marketLength) { + // + SetIndicatorBuffersNone(bar_index); + return; + } + + // + // Highest High ... + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLength, + bar_index + ); + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + highestHighBuffer[bar_index] = hh; + + // + // Lowest Low ... + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLength, + bar_index + ); + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + lowestLowBuffer[bar_index] = ll; + + // + // Middle Buffer ... + double mid = (hh + ll) / 2; + middleBuffer[bar_index] = mid; + + // + // Reset Start Time ... + startTime = 0; +} + +// +void SetIndicatorBuffersNone( + const int bar_index +) { + // + int lastBarIndex = bar_index + 1; + + // + double lastHighestHigh; + double lastLowestLow; + + // + // Highest High ... + if (ArraySize(highestHighBuffer) > lastBarIndex) { + lastHighestHigh = highestHighBuffer[lastBarIndex]; + } else { + lastHighestHigh = 0; + } + + // + // Lowest Low ... + if (ArraySize(lowestLowBuffer) > lastBarIndex) { + lastLowestLow = lowestLowBuffer[lastBarIndex]; + } else { + lastLowestLow = 0; + } + + // + highestHighBuffer[bar_index] = lastHighestHigh; + lowestLowBuffer[bar_index] = lastLowestLow; + + // + double mid = (lastHighestHigh + lastLowestLow) / 2; + middleBuffer[bar_index] = mid; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/BTCUSD-15M/Indicators/x-saherelm.xtpow.mq4 b/Bkp/BTCUSD-15M/Indicators/x-saherelm.xtpow.mq4 new file mode 100644 index 0000000..46ff59e --- /dev/null +++ b/Bkp/BTCUSD-15M/Indicators/x-saherelm.xtpow.mq4 @@ -0,0 +1,275 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center Trend Power Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 MA Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 7; // Market Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_separate_window + +// +#property indicator_plots 3 +#property indicator_buffers 3 +#property indicator_minimum 0 +#property indicator_maximum 100 + +// +#property indicator_levelcolor clrGray +#property indicator_levelstyle STYLE_DOT + +// +// Start Define Indicator Buffer Styles ... +// +#property indicator_type1 DRAW_HISTOGRAM +#property indicator_color1 clrLime +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +#property indicator_type2 DRAW_HISTOGRAM +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define powerUpBufferIndex 0 +#define powerDownBufferIndex 1 +#define signalBufferIndex 2 + +double powerUpBuffer[]; +double powerDownBuffer[]; +double signalBuffer[]; + +// +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (marketLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + SetLevelValue(0, 0.0); + IndicatorSetString(INDICATOR_LEVELTEXT,0,""); + + // + SetLevelValue(1, 20.0); + IndicatorSetString(INDICATOR_LEVELTEXT,1,""); + + // + SetLevelValue(2, 50); + IndicatorSetString(INDICATOR_LEVELTEXT,2,""); + + // + SetLevelValue(3, 100); + IndicatorSetString(INDICATOR_LEVELTEXT,3,""); + + // + string pUpLbl = StringConcatenate( + "P Up (", marketLength, ")" + ); + SetIndexLabel(powerUpBufferIndex, pUpLbl); + SetIndexBuffer(powerUpBufferIndex, powerUpBuffer); + SetIndexDrawBegin(powerUpBufferIndex, marketLength + 1); + + // + string pDownLbl = StringConcatenate( + "P Down (", marketLength, ")" + ); + SetIndexLabel(powerDownBufferIndex, pDownLbl); + SetIndexBuffer(powerDownBufferIndex, powerDownBuffer); + SetIndexDrawBegin(powerDownBufferIndex, marketLength + 1); + + // + string pSignalLbl = StringConcatenate( + "P Signal (", marketLength, ")" + ); + SetIndexLabel(signalBufferIndex, pSignalLbl); + SetIndexBuffer(signalBufferIndex, signalBuffer); + SetIndexDrawBegin(signalBufferIndex, marketLength + 1); + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "X_TPW_OSC"; + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Buffers ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateBuffers( + const int &bar_index +) { + // + double powerUp = 0; + double powerDown = 0; + + // + int dailyCount = GetDailyCandleCount(); + double dailyHH = GetMarketHighestHigh( + bar_index, + dailyCount + ); + double dailyLL = GetMarketLowestLow( + bar_index, + dailyCount + ); + double dailyDiff = dailyHH - dailyLL; + double rate = dailyDiff / 100; + + // + for (int i = bar_index; i < bar_index + marketLength; i++) { + // + XOHCL c = GetCandleModel(i); + + // + double cRange = + MathAbs(c.open - c.close) + // MathAbs(c.high - c.low) + ; + bool isBullish = c.open < c.close; + + // + if (isBullish) { + powerUp += cRange; + } else { + powerDown += cRange; + } + } + + // + powerUp = powerUp / rate; + powerDown = powerDown / rate; + + // + int doubleMarketLength = (marketLength * 2); + double ema = GetMA( + bar_index, + doubleMarketLength, + 0, + MODE_EMA, + PRICE_WEIGHTED + ); + + // + double emaRate = GetMarketHighestHigh(bar_index, doubleMarketLength) - GetMarketLowestLow(bar_index, doubleMarketLength) / 100; + + // + double signal = (ema / 100) * rate; + double signalAddition = MathMin(powerUp, powerDown); + + // + powerUpBuffer[bar_index] = powerUp; + powerDownBuffer[bar_index] = powerDown; + signalBuffer[bar_index] = signal + signalAddition; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/BTCUSD-15M/Libraries/x-saherelm.draw.lib.mq4 b/Bkp/BTCUSD-15M/Libraries/x-saherelm.draw.lib.mq4 new file mode 100644 index 0000000..776cde4 --- /dev/null +++ b/Bkp/BTCUSD-15M/Libraries/x-saherelm.draw.lib.mq4 @@ -0,0 +1,2010 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Draw Highest High ... +bool DrawHighestHigh( + const int bar_index, + const int marketLen, + const string tag, + const int drawUntilBarIndex = 0, + const long chartID = 0, + const int subWindow = 0, + const color clr = clrAqua, + const ENUM_LINE_STYLE style = STYLE_DOT, + const int width = 1, + const bool back = false, + const bool selection = false, + const bool hidden = false, + const long zOrder = 0 +) { + // + bool result = false; + + // + // Calculate Highest High ... + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + datetime hhTime = iTime( + _Symbol, + _Period, + hhIdx + ); + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + datetime drawUntilTime = + drawUntilBarIndex != bar_index ? + iTime( + _Symbol, + _Period, + drawUntilBarIndex + ) : + barTime + ; + + // + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + int rnd = rand(); + + // + // Define Label ... + string lbl = StringConcatenate( + tag, + "_HH(", marketLen ,")_", + hh, + "_", rnd + ); + + // + result = ObjectDelete( + chartID, + lbl + ); + + // + // Draw a Trend Line ... + result = DrawTrendLine( + chartID, + lbl, + subWindow, + hhTime, + hh, + drawUntilTime, + hh, + clr, + style, + width, + back, + selection, + hidden, + zOrder + ); + + // + return result; +} + +// +// Draw Lowest Low ... +bool DrawLowestLow( + const int bar_index, + const int marketLen, + const string tag, + const int drawUntilBarIndex = 0, + const long chartID = 0, + const int subWindow = 0, + const color clr = clrFuchsia, + const ENUM_LINE_STYLE style = STYLE_DOT, + const int width = 1, + const bool back = false, + const bool selection = false, + const bool hidden = false, + const long zOrder = 0 +) { + // + bool result = false; + + // + // Calculate Highest High ... + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + datetime llTime = iTime( + _Symbol, + _Period, + llIdx + ); + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + datetime drawUntilTime = + drawUntilBarIndex != bar_index ? + iTime( + _Symbol, + _Period, + drawUntilBarIndex + ) : + barTime + ; + + // + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + int rnd = rand(); + + // + // Define Label ... + string lbl = StringConcatenate( + tag, + "_LL(", marketLen ,")_", + ll, + "_", rnd + ); + + // + result = ObjectDelete( + chartID, + lbl + ); + + // + // Draw a Trend Line ... + result = DrawTrendLine( + chartID, + lbl, + subWindow, + llTime, + ll, + drawUntilTime, + ll, + clr, + style, + width, + back, + selection, + hidden, + zOrder + ); + + // + return result; +} + +// +// Draw Market Middle ... +bool DrawMarketMiddle( + const int bar_index, + const int marketLen, + const string tag, + const int drawUntilBarIndex = 0, + const long chartID = 0, + const int subWindow = 0, + const color clr = clrYellow, + const ENUM_LINE_STYLE style = STYLE_DOT, + const int width = 1, + const bool back = false, + const bool selection = false, + const bool hidden = false, + const long zOrder = 0 +) { + // + bool result = false; + + // + // Calculate Highest High ... + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + datetime llTime = iTime( + _Symbol, + _Period, + llIdx + ); + + // + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + // Calculate Highest High ... + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + datetime hhTime = iTime( + _Symbol, + _Period, + hhIdx + ); + + // + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + double middle = ll + ((hh - ll) / 2); + datetime middleTime = hhIdx < llIdx + ? hhTime + : llTime + ; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + datetime drawUntilTime = + drawUntilBarIndex != bar_index ? + iTime( + _Symbol, + _Period, + drawUntilBarIndex + ) : + barTime + ; + + // + int rnd = rand(); + + // + // Define Label ... + string lbl = StringConcatenate( + tag, + "_MID(", marketLen ,")_", + middle, + "_", rnd + ); + + // + result = ObjectDelete( + chartID, + lbl + ); + + // + // Draw a Trend Line ... + result = DrawTrendLine( + chartID, + lbl, + subWindow, + middleTime, + middle, + drawUntilTime, + middle, + clr, + style, + width, + back, + selection, + hidden, + zOrder + ); + + // + return result; +} + +// +// Start Arrow Functions ... +// +// +// Draw an Arrow Object on Chart ... +bool DrawArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // arrow name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const uchar arrowCode = OBJ_ARROW_UP, // arrow code + const ENUM_ARROW_ANCHOR anchor = ANCHOR_BOTTOM, // anchor point position + const color clr = clrAqua, // arrow color + const ENUM_LINE_STYLE style = STYLE_SOLID, // border line style + const int width = 3, // arrow size + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // Order Object ... +) { + // + // set anchor point coordinates if they are not set ... + ChangeArrowEmptyPoint(time, price); + + // + // reset the error value ... + ResetLastError(); + + // + // create an arrow ... + if(!ObjectCreate(chartID, name, OBJ_ARROW, subWindow, time, price)) { + // + string message = StringConcatenate(__FUNCTION__, + ": failed to create an arrow! Error code = ", + GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the arrow code ... + ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, arrowCode); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set the arrow color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set the border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set the arrow's size ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the arrow by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is false by default, if you want making it possible to highlight and move the object + // change it to true ... + ObjectSetInteger(chartID,name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point of Arrow ... +bool MoveArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if(!time) { + time = TimeCurrent(); + } + + // + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete an arrow ... +bool DeleteArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow" // arrow name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete an arrow ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete an arrow! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the arrow code ... +bool ArrowCodeChange( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + const uchar code = 252 // arrow code +) { + // + // reset the error value ... + ResetLastError(); + + // + // change the arrow code ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, code)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the arrow code! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change anchor type ... +bool ArrowAnchorChange( + const long chartID = 0, // chart's ID + const string name="Arrow", // object name + const ENUM_ARROW_ANCHOR anchor = ANCHOR_TOP // anchor type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change anchor type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change anchor type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeArrowEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } +} +// +// End Arrow Functions ... +// + +// +// Start Horizontal Line Functions ... +// +// +// Create, Draw the horizontal line ... +bool DrawHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + const int subWindow = 0, // subwindow index + double price = 0, // line price + const color clr = clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the price is not set, set it at the current Bid price level ... + if(!price) { + price=SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // create a horizontal line ... + if(!ObjectCreate(chartID, name, OBJ_HLINE, subWindow, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move horizontal line ... +bool MoveHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + double price = 0 // line price +) { + // + // if the line price is not set, move it to the current Bid price level ... + if(!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move a horizontal line ... + if(!ObjectMove(chartID, name, 0, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete a horizontal line ... +bool DeleteHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a horizontal line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End Horizontal Line Functions ... +// + +// +// Start Vertical Line Functions ... +// +// +// Create the vertical line ... +bool DrawVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + const int sub_window = 0, // subwindow index + datetime time = 0, // line time + const color clr=clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the line time is not set, draw it via the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value + ResetLastError(); + + // + // create a vertical line ... + if (!ObjectCreate(chartID, name, OBJ_VLINE, sub_window, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return true; +} + +// +// Move the vertical line ... +bool MoveVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + datetime time = 0 // line time +) { + // + // if line time is not set, move the line to the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the vertical line ... + if(!ObjectMove(chartID, name, 0, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the vertical line ... +bool DeleteVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the vertical line ... + if (!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // successful execution ... + return true; +} +// +// End Vertical Line Functions ... +// + +// +// Start RectangleLabel Functions ... +// +// +// Create Rectangle Label Object ... +bool DrawRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int subWindow = 0, // subwindow index + const int x = 0, // X coordinate + const int y = 0, // Y coordinate + const int width = 50, // width + const int height = 18, // height + const color back_clr = C'236,233,216', // background color + const ENUM_BORDER_TYPE border = BORDER_SUNKEN, // border type + const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring + const color clr = clrRed, // flat border color (Flat) + const ENUM_LINE_STYLE style = STYLE_SOLID, // flat border style + const int lineWidth = 1, // flat border width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // reset the error value ... + ResetLastError(); + + // + //--- create a rectangle label + if(!ObjectCreate(chartID, name, OBJ_RECTANGLE_LABEL, subWindow, 0, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set label coordinates ... + ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x); + ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y); + + // + // set label size ... + ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width); + ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height); + + // + // set background color ... + ObjectSetInteger(chartID, name, OBJPROP_BGCOLOR, back_clr); + + // + // set border type ... + ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border); + + // + // set the chart's corner, relative to which point coordinates are defined ... + ObjectSetInteger(chartID, name, OBJPROP_CORNER, corner); + + // + // set flat border color (in Flat mode) ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set flat border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set flat border width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, lineWidth); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the label by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move Rectangle Label .. +bool MoveRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int x = 0, // X coordinate + const int y=0 // Y coordinate +) { + // + // reset the error value ... + ResetLastError(); + + // + // move the rectangle label ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move X coordinate of the label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move Y coordinate of the label! Error code = ",GetLastError() + ); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the rectangle label ... +bool DeleteRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel" // label name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the label ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change Rectangle Label Size ... +bool ChangeSizeRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int width = 50, // label width + const int height = 18 // label height +) { + // + // reset the error value ... + ResetLastError(); + + // + // change label size ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's width! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's height! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change rectangle label border type ... +bool RectLabelChangeBorderType( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const ENUM_BORDER_TYPE border = BORDER_SUNKEN // border type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change border type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the border type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End RectangleLabel Functions ... +// + +// +// Start TrendLine Funcions ... +// +// Create a trend line by the given coordinates ... +bool DrawTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrYellow, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool rayRight = false, // line's continuation to the right + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeTrendLineEmptyPoints( + time1, + price1, + time2, + price2 + ); + + // + // reset the error value ... + ResetLastError(); + + // + // create a trend line by the given coordinates ... + if(!ObjectCreate(chartID, name, OBJ_TREND, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the line's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move trend line anchor point ... | +bool ChangeTrendLinePoint( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int pointindex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move trend line's anchor point ... + if(!ObjectMove(chartID, name, pointindex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// The function deletes the trend line from the chart ... +bool DeleteTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a trend line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of trend line's anchor points and set default ... +// values for empty ones ... +void ChangeTrendLineEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the first point's time is not set, it will be on the current bar ... + if (!time1) { + time1 = TimeCurrent(); + } + + // + // if the first point's price is not set, it will have Bid value ... + if (!price1) { + price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // if the second point's time is not set, it is located 9 bars left from the second one ... + if (!time2) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(), Period(), time1, 10, temp); + + // + // set the second point 9 bars left from the first one ... + time2 = temp[0]; + } + + // + // if the second point's price is not set, it is equal to the first point's one ... + if (!price2) { + price2 = price1; + } +} +// +// End TrendLine Functions ... +// + +// +// Start Text Functions ... +// +// Create and Draw a Text Object ... +bool DrawText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const string text = "Text", // the text itself + const string font = "Arial", // font + const int fontSize = 10, // font size + const color clr = clrRed, // color + const double angle = 0.0, // text slope + const ENUM_ANCHOR_POINT anchor = ANCHOR_CENTER, // anchor type + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor point coordinates if they are not set ... + ChangeTextEmptyPoint(time,price); + + // + // reset the error value ... + ResetLastError(); + + // + //--- create Text object + if(!ObjectCreate(chartID, name, OBJ_TEXT, subWindow, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the text ... + ObjectSetString(chartID, name , OBJPROP_TEXT, text); + + // + // set text font ... + ObjectSetString(chartID, name, OBJPROP_FONT, font); + + // + // set font size ... + ObjectSetInteger(chartID, name, OBJPROP_FONTSIZE, fontSize); + + // + // set the slope angle of the text ... + ObjectSetDouble(chartID, name, OBJPROP_ANGLE, angle); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the object by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID ,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point ... +bool MoveText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + //--- if point position is not set, move it to the current bar having Bid price + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point .. + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the object text ... +bool ChangeText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const string text = "Text" // text +) { + // + // reset the error value ... + ResetLastError(); + + // + // change object text ... + if(!ObjectSetString(chartID, name, OBJPROP_TEXT, text)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the text! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Text object ... +bool DeleteText( + const long chartID = 0, // chart's ID + const string name = "Text" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeTextEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + } +// +// End Text Functions ... +// + +// +// Start Fibonacchi Functions ... +// +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawFibonacci( + const long chartID = 0, // chart's ID + const string name="Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrRed, // object color + const ENUM_LINE_STYLE style = STYLE_SOLID, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawCustomFibonacci( + // + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + // + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrAqua, // object color + const ENUM_LINE_STYLE style = STYLE_DOT, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // Change Levels Of Fibonacci ... + bool result = FibonacciLevelsSet( + levels, + values, + colors, + styles, + widths, + descriptions, + chartID, + name + ); + + // + // successful execution ... + return result; +} + +// +// Set number of levels and their parameters ... +bool FibonacciLevelsSet( + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // check array sizes ... + if( + levels!=ArraySize(colors) || + levels!=ArraySize(styles) || + levels!=ArraySize(widths) || + levels!=ArraySize(widths) + ) { + // + string message = StringConcatenate( + __FUNCTION__, + ": array length does not correspond to the number of levels, error!" + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the number of levels ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELS, levels); + + // + // set the properties of levels in the loop ... + for(int i = 0; i < levels; i++) { + // + // level value ... + ObjectSetDouble(chartID, name, OBJPROP_LEVELVALUE, i, values[i]); + + // + // level color ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELCOLOR, i, colors[i]); + + // + // level style ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELSTYLE, i, styles[i]); + + // + // level width ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELWIDTH, i, widths[i]); + + // + // level description ... + // ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, DoubleToString(100 * values[i], 1)); + ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, descriptions[i]); + } + + // + // successful execution ... + return(true); +} + +// +// Move Fibonacci Retracement anchor point ... +bool FibonacciPointChange( + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int pointIndex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, pointIndex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Fibonacci Retracement ... +bool DeleteFibonachi( + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Fibonacci Retracement\"! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of Fibonacci Retracement anchor points and set +// default values for empty ones ... +void ChangeFibonacciEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the second point's time is not set, it will be on the current bar ... + if (!time2) { + time2 = TimeCurrent(); + } + + // + // if the second point's price is not set, it will have Bid value ... + if (!price2) { + price2 = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // if the first point's time is not set, it is located 9 bars left from the second one ... + if (!time1) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(),Period(),time2,10,temp); + + // + // set the first point 9 bars left from the second one ... + time1 = temp[0]; + } + + // + // if the first point's price is not set, move it 200 points below the second one ... + if (!price1) { + price1 = price2 - 200 * SymbolInfoDouble(_Symbol, SYMBOL_POINT); + } +} +// +// End Fibonacci Functions ... +// + + +// +// Start General Functions ... +// +// +// Remove all Drawn Objects ... +void RemoveDraws(const string &tag) { + // + for(int iObj=ObjectsTotal()-1; iObj >= 0; iObj--) { + // + string on = ObjectName(iObj); + if (StringFind(on, tag) == 0) { + ObjectDelete(on); + } + } +} +// +// End General Functions ... +// \ No newline at end of file diff --git a/Bkp/BTCUSD-15M/Libraries/x-saherelm.indicator.lib.mq4 b/Bkp/BTCUSD-15M/Libraries/x-saherelm.indicator.lib.mq4 new file mode 100644 index 0000000..0e4b162 --- /dev/null +++ b/Bkp/BTCUSD-15M/Libraries/x-saherelm.indicator.lib.mq4 @@ -0,0 +1,450 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Indicator Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// Reading specified Buffer From ADX Indicator ... +double ReadXMABuffer( + const int bar_index, + const int buffer_index, + // + const int marketLen, + // + const double stp, + const double mxm, + // + const int shortCycleMult, + const int mediumCycleMult, + const int longCycleMult +) { + // + string xmaIndicatorName = "x-saherelm.x.xma"; + + // + double result = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // Inputs ... + marketLen, + stp, + mxm, + shortCycleMult, + mediumCycleMult, + longCycleMult, + MODE_SMA, + // + buffer_index, + bar_index + ); + + // + return result; +} + +// +// Reading specified Buffer from XHL Indicator ... +double ReadXHLBuffer( + const int bar_index, + const int buffer_index, + // + const int marketLen, + // + const int shortCycleMult, + const int mediumCycleMult, + const int longCycleMult +) { + // + string xhlIndicatorName = "x-saherelm.x.hl"; + + // + double result = iCustom( + _Symbol, + _Period, + xhlIndicatorName, + // + // Inputs ... + marketLen, + shortCycleMult, + mediumCycleMult, + longCycleMult, + MODE_SMA, + // + buffer_index, + bar_index + ); + + // + return result; +} + +// +// Reading ADX Values ... +double ReadADX( + const int bar_index, + const int marketLen, + const int mult +) { + // + double result; + + // + int period = marketLen * mult; + + // + result = iADX( + _Symbol, + _Period, + period, + PRICE_CLOSE, + MODE_MAIN, + bar_index + ); + + // + return result; +} + +// +// Reading Pivot States ... +XPvtState GetPVTState( + const int bar_index, + const int marketLen +) { + // + XPvtState result = {}; + + // + double hh = GetMarketHighestHigh( + bar_index, + marketLen + ); + + // + double ho = GetMarketHighestOpen( + bar_index, + marketLen + ); + + // + double hc = GetMarketHighestClose( + bar_index, + marketLen + ); + + // + double hl = GetMarketHighestLow( + bar_index, + marketLen + ); + + // + double ll = GetMarketLowestLow( + bar_index, + marketLen + ); + + // + double lo = GetMarketLowestOpen( + bar_index, + marketLen + ); + + // + double lc = GetMarketLowestClose( + bar_index, + marketLen + ); + + // + double lh = GetMarketLowestHigh( + bar_index, + marketLen + ); + + // + // Filling Result ... + // + result.hh = hh; + result.ho = ho; + result.hc = hc; + result.hl = hl; + + // + result.ll = ll; + result.lo = lo; + result.lc = lc; + result.lh = lh; + + // + return result; +} + +// +// Calculate XRange from Market ... +static XRState lastXRState; +XRState GetXRange( + const int bar_index, + const int rangeMarketLength +) { + // + XRState result = {}; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + int marketBarIndex = bar_index + rangeMarketLength; + + // + // Highest High ... + // + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketBarIndex, + bar_index + ); + + // + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + // Lowest Low ... + // + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketBarIndex, + bar_index + ); + + // + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + if (lastXRState.start == 0) { + // + lastXRState.start = barTime; + lastXRState.length = rangeMarketLength; + + // + lastXRState.hh = hh; + lastXRState.ll = ll; + + // + // Middle ... + double mid = (hh + ll) / 2; + lastXRState.mid = mid; + } else { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + lastXRState.start + ); + + // + if (startBarIndex - bar_index >= rangeMarketLength) { + // + lastXRState.start = barTime; + lastXRState.length = rangeMarketLength; + + // + lastXRState.hh = hh; + lastXRState.ll = ll; + + // + // Middle ... + double mid = (hh + ll) / 2; + lastXRState.mid = mid; + } + } + + // + result = lastXRState; + + // + return result; +} + +// +// Reading XTPowState from Indicatoe ... +XTPOWState GetXTPowState( + const int bar_index, + const int marketLen +) { + // + XTPOWState result = {}; + + // + // + double powerUp = 0; + double powerDown = 0; + double signal = 0; + + // + string indicatorName = "x-saherelm.xtpow"; + + // + int pUpIndex = 0; + int pDownIndex = 1; + int signalIndex = 2; + + // + powerUp = iCustom( + _Symbol, + _Period, + indicatorName, + // + marketLen, + // + pUpIndex, + bar_index + ); + + // + powerDown = iCustom( + _Symbol, + _Period, + indicatorName, + // + marketLen, + // + pDownIndex, + bar_index + ); + + // + signal = iCustom( + _Symbol, + _Period, + indicatorName, + // + marketLen, + // + signalIndex, + bar_index + ); + + // + result.signal = signal; + result.powerUp = powerUp; + result.powerDown = powerDown; + + // + return result; +} + +// +// Reading XRState From Indicator ... +XRState ReadXRange( + const int bar_index, + const int marketLen +) { + // + XRState result = {}; + + // + // Define Buffer Indexes ... + int hhBufferIndex = 0; + int llBufferIndex = 1; + int midBufferIndex = 2; + + // + string indicatorName = "x-saherelm.xrange"; + + // + // Read Values From XRange Indicator ... + + // + double hh = iCustom( + _Symbol, + _Period, + indicatorName, + // + // Inputs ... + marketLen, + // + hhBufferIndex, // Buffer Index ... + bar_index + ); + + // + double ll = iCustom( + _Symbol, + _Period, + indicatorName, + // + // Inputs ... + marketLen, + // + llBufferIndex, // Buffer Index ... + bar_index + ); + + // + double mid = iCustom( + _Symbol, + _Period, + indicatorName, + // + // Inputs ... + marketLen, + // + midBufferIndex, // Buffer Index ... + bar_index + ); + + // + // Filling Result ... + result.hh = hh; + result.ll = ll; + result.mid = mid; + + // + return result; +} +// +// END Indicator Reading Data ... +// diff --git a/Bkp/BTCUSD-15M/Libraries/x-saherelm.lib.mq4 b/Bkp/BTCUSD-15M/Libraries/x-saherelm.lib.mq4 new file mode 100644 index 0000000..cc0e23e --- /dev/null +++ b/Bkp/BTCUSD-15M/Libraries/x-saherelm.lib.mq4 @@ -0,0 +1,1662 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +static datetime lastBarTime; + +// +struct XOHCL { + double high; + double open; + double close; + double low; +}; + +// +struct XRange { + // + datetime time; + + // + double highestHigh; + double lowestLow; + + // + int levels; + int marketLength; + + // + double rate; +}; + +// +struct XPrice { + // + double askPrice; + double bidPrice; + double priceGap; + + // + double longEntry; + double longExit; + + // + double shortEntry; + double shortExit; +}; + +// +// START Functions ... +// + +// +// Determines current working is New Bar or not ... +bool IsNewBar() { + // + // Reading Last Bar Date ... + datetime curbar = (datetime)SeriesInfoInteger( + _Symbol, + _Period, + SERIES_LASTBAR_DATE + ); + + // + if(lastBarTime != curbar) { + // + lastBarTime = curbar; + return true; + } + + // + return false; +} + +// +// Determines we are in new Day or not ... +bool IsNewDay() { + // + bool result = false; + + // + // Reading Last Bar Date ... + datetime curbar = (datetime)SeriesInfoInteger( + _Symbol, + _Period, + SERIES_LASTBAR_DATE + ); + + // + if (lastBarTime == 0) { + lastBarTime = curbar; + } + + // + if (curbar == lastBarTime) { + return result; + } + + // + // Retrieve Day and Month and Year for Last Bar Time ... + int lastBarDay = TimeDay(lastBarTime); + int lastBarMonth = TimeMonth(lastBarTime); + int lastBarYear = TimeYear(lastBarTime); + + // + // Retrieve Day and Month and Year for Current Bar Time ... + int curBarDay = TimeDay(curbar); + int curBarMonth = TimeMonth(curbar); + int curBarYear = TimeYear(curbar); + + // + result = curBarDay > lastBarDay + || curBarMonth > lastBarMonth + || curBarYear > lastBarYear; + + // + return result; +} + +// +// Retrieve Number of Candles in a Day ... +int GetDailyCandleCount() { + // + int seconds = PeriodSeconds(_Period); + + // + int daySeconds = 24 * 60 * 60; + + // + int result = daySeconds / seconds; + + // + return result; +} + +// +// XRange Detector ... +XRange GetMarketRange( + const int bar_index, + const int marketLen, + const int levels +) { + // + XRange result = {}; + + // + result.levels = levels; + result.marketLength = marketLen; + + // + datetime time = iTime( + _Symbol, + _Period, + bar_index + ); + result.time = time; + + // + double highestHigh = GetMarketHighestHigh( + bar_index, + marketLen + ); + result.highestHigh = highestHigh; + + // + double lowestLow = GetMarketLowestLow( + bar_index, + marketLen + ); + result.lowestLow = lowestLow; + + // + double diff = highestHigh - lowestLow; + double rate = diff / levels; + + // + result.rate = rate; + + // + return result; +} + +// +// Retrieve RMA on Specific Candle ... +double GetRMA( + int bar_index, + int length +) { + // + double shortSMA = iMA(_Symbol, _Period, length, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double mediumSMA = iMA(_Symbol, _Period, length * 2, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double longSMA = iMA(_Symbol, _Period, length * 3, 0, MODE_SMA, PRICE_CLOSE, bar_index); + + // + double result = longSMA - mediumSMA + shortSMA; + + // + return result; +} + +// +// Retrieve Moving Average ... +double GetMA( + const int bar_index, + const int maLength, + const int maShift, + const ENUM_MA_METHOD maMethod, + const ENUM_APPLIED_PRICE appliedPrice +) { + // + double result = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + appliedPrice, + bar_index + ); + + // + return result; +} + +// +// Calculate Fib Level ... +double GetFibonacciLevel( + double upPrice, + double downPrice, + double level, + int direction +) { + // + double ling = upPrice - downPrice; + double pLevel = (ling / 100) * (level * 100); + + // + double result = direction > 0 ? + upPrice - pLevel : + downPrice + pLevel; + result = NormalizeDouble(result, _Digits); + + // + return result; +} + +// +// Retrieve True Range ... +double GetTR( + const int bar_index +) { + // + double result = 0; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double prevClose = iClose( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double highLowDif = high - low; + double hpCDif = MathAbs(high - prevClose); + double lpCDiff = MathAbs(low - prevClose); + + // + result = MathMax(highLowDif, hpCDif); + result = MathMax(result, lpCDiff); + + // + return result; +} + +// +// Calculate True Range Simple Moving Average ... +double GetMarketTRSMA( + const int bar_index, + const int marketLen +) { + // + double result = 0; + + // + // Create Barket Length Trs ... + double trs[]; + ArrayResize( + trs, + marketLen + ); + int index = 0; + double trSum = 0; + for (int i = bar_index; i < bar_index + marketLen; i++) { + // + double tr = GetTR(i); + trs[index] = tr; + + // + trSum += tr; + + // + index++; + } + + // + result = trSum / marketLen; + + // + return result; +} + +// +// Retrieve Commodity Channel ... +double GetMarketCCI( + const int bar_index, + const int marketLen, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE +) { + // + double result = 0; + + // + result = iCCI( + _Symbol, + _Period, + marketLen, + appliedPrice, + bar_index + ); + + // + return result; +} + +// +// this function check crossing up two Buffers ... +bool IsCrossedOver( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] > arr2[index1]) && !(arr1[index2] > arr2[index2]); + + // + return result; +} + +// +// this function check crossing down two Buffers ... +bool IsCrossedUnder( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] < arr2[index1]) && !(arr1[index2] < arr2[index2]); + + // + return result; +} + +// +// Convert points to Actual Point ... +double PointsToDouble(int points) { + // + double result = points * _Point; + return result; +} + +// +// Converts Pips to Points ... +int PipsToPoints(int pips) { + // + int result = pips * ((_Digits == 3 || _Digits == 5) ? 10 : 1); + return result; +} + +// +// Converts Pips to Double ... +double PipsToDouble(int pips) { + // + double result = PointsToDouble(PipsToPoints(pips)); + return result; +} + +// +// Converts Double Value to Pips ... +int PriceToPips(double value) { + // + if (value <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + int result = (int)(value / pipValue); + + // + return result; +} + +// +// Converts Pips to Double ... +double PipsToPrice(int pips) { + // + if (pips <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + double result = pipValue * pips; + + // + return result; +} + +// +// Generate ATR StopLoss Value ... +double CalculateATRSL( + int period, + double multiplier +) { + // + if (period <= 0 || multiplier <= 0) { + return 0; + } + + // + double atrValue = iATR( + _Symbol, + _Period, + period, + 0 + ); + + // + double result = atrValue * multiplier; + + // + return result; +} + +// +// Detect Candle Type ... +// Bullish => means close > open ... +bool IsBullishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBullishCandle( + open, + close + ); + + // + return result; +} + +bool IsBullishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open < close; + + // + return result; +} + +// +// Detect Candle Type ... +// Bearish => means close < open ... +bool IsBearishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBearishCandle( + open, + close + ); + + // + return result; +} + +bool IsBearishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open > close; + + // + return result; +} + +// +// Retrieve a Candle Info ... +XOHCL GetCandleModel( + const int bar_index +) { + // + XOHCL result = {}; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + result.high = high; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + result.open = open; + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + result.close = close; + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + result.low = low; + + // + return result; +} + +// +// Retrieve Market Current Prices for Signals ... +XPrice GetPrice() { + // + XPrice result = {}; + + // + RefreshRates(); + + // + double askPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double bidPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(bidPrice - askPrice); + + // + result.askPrice = askPrice; + result.bidPrice = bidPrice; + result.priceGap = priceGap; + + // + result.longEntry = askPrice; + result.longExit = bidPrice; + + // + result.shortEntry = bidPrice; + result.shortExit = askPrice; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBullishDetected( + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double shpDetectMultipliers // Sharp Detect Multiplier +) { + // + bool result = false; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double minValue = 0; + double maxValue = 0; + int positionedLength = bar_index + marketLen; + + // + for (int i = bar_index; i < positionedLength; i++) { + // + double cHigh = iHigh( + _Symbol, + _Period, + i + ); + + // + double cLow = iLow( + _Symbol, + _Period, + i + ); + + // + minValue += MathMin(cLow, cHigh); + maxValue += MathMax(cLow, cHigh); + } + + // + double minAvg = minValue / positionedLength; + double maxAvg = maxValue / positionedLength; + + // + double shpValue = shpDetectMultipliers * _Point; + + // + result = (low - minAvg) > shpValue; + + // + int index = bar_index; + while ( + index < positionedLength + || !result + ) { + // + low = iLow( + _Symbol, + _Period, + index + ); + + // + result = result + || (low - minAvg) > shpValue; + + // + index++; + }; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBearishDetected( + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double shpDetectMultipliers // Sharp Detect Multiplier +) { + // + bool result = false; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double minValue = 0; + double maxValue = 0; + int positionedLength = bar_index + marketLen; + + // + for (int i = bar_index; i < positionedLength; i++) { + // + double cHigh = iHigh( + _Symbol, + _Period, + i + ); + + // + double cLow = iLow( + _Symbol, + _Period, + i + ); + + // + minValue += MathMin(cLow, cHigh); + maxValue += MathMax(cLow, cHigh); + } + + // + double minAvg = minValue / positionedLength; + double maxAvg = maxValue / positionedLength; + + // + double shpValue = shpDetectMultipliers * _Point; + + // + result = (high - maxAvg) > shpValue; + + // + int index = bar_index; + while ( + index < positionedLength + || !result + ) { + // + high = iHigh( + _Symbol, + _Period, + index + ); + + // + result = result + || (high - maxAvg) > shpValue; + + // + index++; + }; + + // + return result; +} + +// +// Retrieve Highest High Value based on Given Market ... +double GetMarketHighestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Low Value based on Given Market ... +double GetMarketHighestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Open Value based on Given Market ... +double GetMarketHighestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Close Value based on Given Market ... +double GetMarketHighestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Low Value based on Given Market ... +double GetMarketLowestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest High Value based on Given Market ... +double GetMarketLowestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Open Value based on Given Market ... +double GetMarketLowestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Close Value based on Given Market ... +double GetMarketLowestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// less than given price ... +double GetLowLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// great than given price ... +double GetLowGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// less than given price ... +double GetHighLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// great than given price ... +double GetHighGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// less than given price ... +double GetCloseLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// great than given price ... +double GetCloseGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Get Slope of a Line by it's two Point ... +double GetSlope( + double x1, + double y1, + double x2, + double y2 +) { + // + double result = (y2 - y1)/MathAbs(x2 - x1); + return result; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/BTCUSD-15M/Libraries/x-saherelm.log.lib.mq4 b/Bkp/BTCUSD-15M/Libraries/x-saherelm.log.lib.mq4 new file mode 100644 index 0000000..066b3f7 --- /dev/null +++ b/Bkp/BTCUSD-15M/Libraries/x-saherelm.log.lib.mq4 @@ -0,0 +1,91 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Log Tag ... +static string logTag = ""; + +// +// Enable or Disable Logging ... +static bool enableLogging = false; + +// +// Start Log Messages ... +// + +// +// Logging a Message, specified for this EA ... +// using provided LogTag ... +void LogMessage(string message) { + // + if (!enableLogging) { + return; + } + + // + Print(logTag, " > ", message); +} + +// +// this used for logging series ... +void LogSeries( + double &series[], // which series to Log ... + int length = 0, // number of items to Log, 0 means all ... + int skip = 0 // number of items which skip before logging ... +) { + // + string msg = ""; + + // + int seriesSize = ArraySize(series); + if ( + skip < 0 + || length < 0 + || seriesSize == 0 + || skip > seriesSize + || skip + length > seriesSize + ) { + return; + } + + // + length = length == 0 ? + seriesSize : + length; + int start = skip > 1 ? + skip - 1 : + skip == 1 ? + 1 : + 0; + + // + // Loop through series items ... + for (int i = start; i < start + length; i++) { + // + msg += StringConcatenate( + "i[", i, "]: ", series[i], ", " + ); + } + + // + LogMessage(msg); +} +// +// End Log Messages ... +// + diff --git a/Bkp/BTCUSD-15M/Libraries/x-saherelm.models.lib.mq4 b/Bkp/BTCUSD-15M/Libraries/x-saherelm.models.lib.mq4 new file mode 100644 index 0000000..fa9903f --- /dev/null +++ b/Bkp/BTCUSD-15M/Libraries/x-saherelm.models.lib.mq4 @@ -0,0 +1,154 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Models Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// START STATIC Variables ... +// +// +static int totalSignals = 0; +static int totalLongSignals = 0; +static int totalShortSignals = 0; + +// +static double initialBalance = 0; + +// +static int countedBars = 0; +static bool isNewBar = false; +static bool isNewDay = false; +// +// END STATIC Variables ... +// + +// +// Start Models ... +// +// +// Signal Providers ... +enum ENUM_X_SIGNAL_PROVIDER { + X_UNKNOWN_PROVIDER, + X_XXX_PROVIDER, + X_XR_PROVIDER, + X_XTPW_PROVIDER +}; + +// +// these are different signal types ... +enum ENUM_X_SIGNAL_TYPE { + X_SIGNAL_NONE, + X_SIGNAL_LONG, + X_SIGNAL_SHORT, +}; + +// +// Model Market Highs and Lows ... +struct XPvtState { + // + double hh; + double ho; + double hc; + double hl; + + // + double ll; + double lo; + double lc; + double lh; +}; + +// +// we Model each signals as this type ... +struct XSignal { + // + // Signal Symbol ... + string symbol; + + // + // Signal Type ... + ENUM_X_SIGNAL_TYPE type; + + // + // Signal ID ... + int id; + + // + // Signal Ticket Number, when Opening Trade ... + int ticket; + + // + // Signal Provider ... + ENUM_X_SIGNAL_PROVIDER provider; + + // + // Target Point ... + double tp; + + // + // Stop Loss ... + double sl; + + // + // Signal Entry Price ... + double entry; + + // + // Signalling Time ... + datetime time; + + // + // Signal Comments ... + string comment; + + // + // Signal TAG ... + string tag; +}; + +// +// this is Signal Request Response model ... +struct XSignalRequest { + bool hasSignal; + XSignal signal; + ENUM_X_SIGNAL_TYPE type; + ENUM_X_SIGNAL_PROVIDER provider; +}; + +// +struct XRState { + // + datetime start; + int length; + + // + double hh; + double ll; + double mid; +}; + +// +struct XTPOWState { + // + double powerUp; + double powerDown; + + // + double signal; +}; +// +// End Models ... +// diff --git a/Bkp/BTCUSD-15M/Libraries/x-saherelm.signal.lib.mq4 b/Bkp/BTCUSD-15M/Libraries/x-saherelm.signal.lib.mq4 new file mode 100644 index 0000000..097ce74 --- /dev/null +++ b/Bkp/BTCUSD-15M/Libraries/x-saherelm.signal.lib.mq4 @@ -0,0 +1,1756 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Signal Draw Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +#include "../Libraries/x-saherelm.x.signal.lib.mq4" +#include "../Libraries/x-saherelm.xr.signal.lib.mq4" +#include "../Libraries/x-saherelm.xtpw.signal.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// END Global Requirement Functions ... +// + +// +// START Signal Related Functions ... +// +// +// Retrieve Signal Bar Index ... +int GetSignalBarIndex(XSignal &signal) { + // + // Temp Result ... + int result = -1; + + // + // Retriev Signal Bar Index ... + result = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + return result; +} + +// +string GetSignalProviderIdentifier( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + string result = ""; + + // + switch (provider) { + // + case X_XXX_PROVIDER: + result = "XXX"; + break; + + // + case X_XR_PROVIDER: + result = "XR"; + break; + + // + case X_XTPW_PROVIDER: + result = "XTPW"; + break; + + // + default: + result = ""; + break; + } + + // + return result; +} + +// +ENUM_X_SIGNAL_PROVIDER GetSignalProvider(string identifier) { + // + ENUM_X_SIGNAL_PROVIDER result = X_UNKNOWN_PROVIDER; + + // + if ( + StringFind( + identifier, + GetSignalProviderIdentifier(X_XXX_PROVIDER) + ) > -1 + ) { + result = X_XXX_PROVIDER; + } else if ( + StringFind( + identifier, + GetSignalProviderIdentifier(X_XR_PROVIDER) + ) > -1 + ) { + result = X_XR_PROVIDER; + } else if ( + StringFind( + identifier, + GetSignalProviderIdentifier(X_XTPW_PROVIDER) + ) > -1 + ) { + result = X_XTPW_PROVIDER; + } + + // + return result; +} + +// +// Retrieve Signal Lots Per Trade ... +double GetSignalLottage( + const XSignal &signal, + const double defLotsPerTrade +) { + // + double result = defLotsPerTrade; + + // + bool isLong = signal.type == X_SIGNAL_LONG; + + // + switch (signal.provider) { + // + case X_XR_PROVIDER: + // + result = isLong ? + xRLongLotsPerTradePercent : + xRShortLotsPerTradePercent + ; + break; + + // + case X_XXX_PROVIDER: + // + result = isLong ? + xLongLotsPerTradePercent : + xShortLotsPerTradePercent + ; + break; + + // + case X_XTPW_PROVIDER: + // + result = isLong ? + xTPWLongLotsPerTradePercent : + xTPWShortLotsPerTradePercent + ; + break; + } + + // + return result; +} + +// +// Draw Specific Range On Chart ... +void DrawRange( + const XRange &range, + const long chartID = 0, + const int subWindowID = 0, + const string tag = "", + const color clr = clrYellow +) { + // + // Loop through Levels Count ... + for (int i = 0; i <= range.levels; i++) { + // + datetime time1 = iTime( + _Symbol, + _Period, + 1 + ); + + // + datetime time2 = iTime( + _Symbol, + _Period, + 0 + ); + + // + double price = range.lowestLow + (i * range.rate); + + // + string lbl = StringConcatenate( + tag, + "_XRL_", + price + ); + + // + DrawTrendLine( + chartID, + lbl, + subWindowID, + time1, + price, + time2, + price, + clr, + STYLE_DOT + ); + } +} + +// +// Draw Signal Shapes on Chart ... +bool DrawSignal( + const XSignal &signal, + long chartID = 0, + int subWindowID = 0, + const double positionThresholdFactor = 10, + string longSignalLabel = "X-Long", + color longSignalColor = clrAqua, + string shortSignalLabel = "X-Short", + color shortSignalColor = clrFuchsia +) { + // + // Generate isLongSignal Var ... + bool isLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Signal Bar Index ... + int bar_index = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // START Draw Signal Arrow ... + // + // + // Arrow Shape Name ... + string arrowName = StringConcatenate(signal.tag, "_Arrow_", signal.id); + + // + // Arrow Price ... + double arrowPrice = 0; + if (isLongSignal) { + // + arrowPrice = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice - (positionThresholdFactor * _Point); + } else { + // + arrowPrice = iHigh( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice + (positionThresholdFactor * _Point); + } + + // + // Arrow Code ... + uchar arrowCode = isLongSignal ? SYMBOL_ARROWUP : SYMBOL_ARROWDOWN; + + // + // Arrow Anchor Point ... + ENUM_ARROW_ANCHOR arrowAnchorPoint = isLongSignal ? ANCHOR_BOTTOM : ANCHOR_TOP; + + // + // Arrow Color ... + color arrowColor = isLongSignal ? longSignalColor : shortSignalColor; + + // + // Draw Signal Arrow Shape ... + bool result = DrawArrow( + chartID, + arrowName, + subWindowID, + signal.time, + arrowPrice, + arrowCode, + arrowAnchorPoint, + arrowColor + ); + // + // END Draw Signal Arrow ... + // + + // + // START Draw Signal SL/TP ... + // + string slLineName = StringConcatenate(signal.tag, "_SL_", signal.id); + string tpLineName = StringConcatenate(signal.tag, "_TP_", signal.id); + string entryLineName = StringConcatenate(signal.tag, "_ENTRY_", signal.id); + + // + color slColor = shortSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color tpColor = longSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color entryColor = clrGreen; + + // + datetime time1 = iTime( + _Symbol, + _Period, + bar_index + 1 + ); + + // + // Draw Enrty Price ... + result = DrawTrendLine( + chartID, + entryLineName, + subWindowID, + time1, + signal.entry, + signal.time, + signal.entry, + entryColor, + STYLE_SOLID, + 2 + ); + + // + // Draw Signal SL ... + if (signal.sl > 0) { + // + result = DrawTrendLine( + chartID, + slLineName, + subWindowID, + time1, + signal.sl, + signal.time, + signal.sl, + slColor, + STYLE_SOLID, + 2 + ); + } + + // + // Draw Signal TP ... + if (signal.tp > 0) { + // + result = DrawTrendLine( + chartID, + tpLineName, + subWindowID, + time1, + signal.tp, + signal.time, + signal.tp, + tpColor, + STYLE_SOLID, + 2 + ); + } + // + // END Draw Signal SL/TP ... + // + + // + // Start Draw Signal Label ... + // + // + string labelName = StringConcatenate(signal.tag, "_Label_", signal.id); + + // + double labelPrice = isLongSignal ? arrowPrice - (positionThresholdFactor * _Point) : arrowPrice + (positionThresholdFactor * _Point); + + // + string labelText = isLongSignal ? longSignalLabel : shortSignalLabel; + labelText = StringConcatenate( + labelText, + "_", + GetSignalProviderIdentifier(signal.provider) + ); + + // + result = DrawText( + chartID, + labelName, + subWindowID, + signal.time, + labelPrice, + labelText, + "Arial", + 8, + arrowColor, + 0, + ANCHOR_CENTER + ); + // + // End Draw Signal Label ... + // + + // + return result; +} + +// +// Trade on Specific Signal ... +bool TradeSignal( + XSignal &signal, + // + double volumePercent, + // + // Long ... + const string longSignalLabel, + const color longSignalColor, + // + // Short ... + const string shortSignalLabel, + const color shortSignalColor +) { + // + // Temp Result ... + bool result = false; + + // + if (initialBalance == 0) { + initialBalance = AccountInfoDouble(ACCOUNT_BALANCE); + } + + // + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + int openPositions = CountOpenTrades(); + double volume = (volumePercent * initialBalance); + + // + if ( + signal.type != X_SIGNAL_LONG && + signal.type != X_SIGNAL_SHORT + ) { + return result; + } + + // + bool hasLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Check TP and Entry Price ... + if ( + ( + hasLongSignal + && signal.entry > signal.tp + ) || + ( + !hasLongSignal + && signal.entry < signal.tp + ) + ) { + return result; + } + + // + // Order Operation ... + int operation = hasLongSignal ? + OP_BUY : + OP_SELL; + + // + // Detect Trade Color ... + color clr = hasLongSignal ? + longSignalColor : + shortSignalColor; + + // + // Generate Signal Comment ... + string label = hasLongSignal ? + longSignalLabel : + shortSignalLabel; + + // + // Generate Signal Comment ... + string comment = StringConcatenate( + signal.tag, + "_", signal.id, + "_", GetSignalProviderIdentifier(signal.provider), + "_", label + ); + + // + // Placing Order ... + int orderTicket = OrderSend( + _Symbol, + operation, + volume, + signal.entry, + 3, + signal.sl, + signal.tp, + comment, + signal.id, + 0, + clr + ); + + // + // Draw Signal Shape if Order Opened Successfully ... + if (orderTicket >= 0) { + // + signal.ticket = orderTicket; + + // + // Here i must to Draw Signal Shapes ... + bool isDrawn = DrawSignal( + signal, + 0, + 0, + 50, + longSignalLabel, // Long Signal Label ... + longSignalColor, + shortSignalLabel, // Short Signal Label ... + shortSignalColor + ); + + // + LogMessage( + StringConcatenate( + "Order [", orderTicket ,"]: Provided by: ", GetSignalProviderIdentifier(signal.provider) + ) + ); + + // + // TODO: here we have to check if there are another + // open positions which their entry price is bigger + // than current signal entry price, for long trades and + // their tp is high than current tp, ... + // close in profit trades or modify orders tp to current ... + // // + // if (CountOpenTrades() > 0) { + // // + // // Here we have to + // ModifyOpenTradesBasedOnCurrentTrade(signal); + // } + + // + result = true; + } + + // + return result; +} +// +// END Signal Related Functions ... +// + +// +// START Orders Functions ... +// +// +// Convert To XSignal Model ... +XSignal OrderToSignal() { + // + // Temp Result ... + XSignal result = {}; + result.type = X_SIGNAL_NONE; + + // + // Here we can get some usefull info based on selected order ... + double swap = OrderSwap(); + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + int magicNumber = OrderMagicNumber(); + double takeProfit = OrderTakeProfit(); + string comment = OrderComment(); + + // + ENUM_X_SIGNAL_PROVIDER provider = GetSignalProvider(comment); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // Conver Position to Signal ... + result.sl = stopLoss; + result.tp = takeProfit; + result.time = openTime; + result.symbol = _Symbol; + result.id = magicNumber; + result.comment = comment; + result.entry = openPrice; + result.provider = provider; + result.type = isLongOrder ? X_SIGNAL_LONG : X_SIGNAL_SHORT; + + // + return result; +} + +// +// START Count Orders ... +// +// +// Count Open Positions ... +int CountOpenTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if (OrderSymbol() == _Symbol) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Long Positions ... +int CountOpenLongTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_BUY + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Short Positions ... +int CountOpenShortTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_SELL + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} +// +// END Count Orders ... +// + +// +// START Close Orders ... +// +// +// Close All Open Trades ... +bool CloseAllTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + + // + return result; +} + +// +bool CloseAllProviderTrades( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal(); + + // + if (signal.provider == provider) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +bool CloseAllProviderLongTrades( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal(); + + // + if ( + signal.provider == provider + && signal.type == X_SIGNAL_LONG + ) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +bool CloseAllProviderShortTrades( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal(); + + // + if ( + signal.provider == provider + && signal.type == X_SIGNAL_SHORT + ) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Long Trades ... +bool CloseAllLongTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Long Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Short Trades ... +bool CloseAllShortTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (!isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Short Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In Profit Trades ... +bool CloseAllInProfitTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit > 0 + && profit > 50 * _Point + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InProfit Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In DrawDown Trades ... +bool CloseAllInDrawDownTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if (profit < 0) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close Biggest In DrawDown Trades ... +bool CloseBiggestDrawDownTrade() { + // + // Loop through all Positions ... + bool result = false; + double drawDown = 0; + + // + // Find Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) > drawDown + ) { + drawDown = profit; + } + } + } + } + + // + // Close Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) >= drawDown + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Max InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Long Time Trades ... +bool CloseAllLongTimeTrades( + const int passedCandles, + const ENUM_X_SIGNAL_PROVIDER provider = X_UNKNOWN_PROVIDER +) { + // + bool result = false; + + // + if (passedCandles <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + string comment = OrderComment(); + + // + ENUM_X_SIGNAL_PROVIDER orderProvider = GetSignalProvider(comment); + bool isProviderVerified = + provider == X_UNKNOWN_PROVIDER ? + true : + orderProvider != X_UNKNOWN_PROVIDER + && orderProvider == provider + ; + + // + if ( + profit < 0 + && isProviderVerified + && openBarIndex - currentBarIndex >= passedCandles + // || ( + // profit > 0.5 + // && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 3) + // ) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Long Time issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + // else if ( + // openTrades > 0 + // && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 2) + // ) { + // result = CloseAllInProfitTrades() + // && CloseBiggestDrawDownTrade(); + // } + } + } + } + + // + return result; +} + +// +// Close all trades which passed Maximum Drawdown ... +bool CloseAllMaximumDrawDownPassedTrades( + const double maxDrDownPercentPerPTrade, + const ENUM_X_SIGNAL_TYPE type = X_SIGNAL_NONE, + const ENUM_X_SIGNAL_PROVIDER provider = X_UNKNOWN_PROVIDER +) { + // + if ( + initialBalance <= 0 + || maxDrDownPercentPerPTrade <= 0 + ) { + return false; + } + + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double maxAllowedDrawDown = -1 * (initialBalance * maxDrDownPercentPerPTrade); + + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + string comment = OrderComment(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + bool isTypeVerified = + type == X_SIGNAL_NONE ? + true : + ( isLongOrder + && type == X_SIGNAL_LONG + ) || ( + !isLongOrder + && type == X_SIGNAL_SHORT + ) + ; + + // + ENUM_X_SIGNAL_PROVIDER orderProvider = GetSignalProvider(comment); + bool isProviderVerified = + provider == X_UNKNOWN_PROVIDER ? + true : + orderProvider != X_UNKNOWN_PROVIDER + && orderProvider == provider + ; + + // + if ( + profit < 0 + && isTypeVerified + && isProviderVerified + && MathAbs(profit) >= MathAbs(maxAllowedDrawDown) + ) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Maximum DarwDown issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Trades Which Opens before Specified Length ... +bool CloseAllTradesWhichOpenInPastMarketLength( + const int marketLen +) { + // + bool result = false; + + // + if (marketLen <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + + // + if (openBarIndex <= currentBarIndex + marketLen) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Market Reverse issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } else if (openTrades > 0) { + // + // Close all InProfit Trdes and Biggest InDrawDown Trades ... + // result = CloseAllInProfitTrades(); + // && CloseBiggestDrawDownTrade(); + } + } + } + } + + // + return result; +} +// +// END Close Orders ... +// + +// +// START Modify Orders ... +// +// +void ModifyAllPriceLesserOpenTrades( + const XSignal &signal +) { + // + // Loop through all Open Trades ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + double takeProfit = OrderTakeProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // When new Signal Comming with price less than + // currently open trade and tp less than currently + // open trade, this means a market change happens ... + // here we can Close InProfit Trades or Modify Trades TP ... + if ( + ( + openPrice < signal.entry + || MathAbs(openPrice - signal.entry) < 300 * _Point + ) + && takeProfit > signal.tp + ) { + bool result = OrderModify( + ticket, + openPrice, + signal.sl, + signal.tp, + clrYellow + ); + } + } + } + } +} + +// +void ModifyOpenTradesBasedOnCurrentTrade( + const XSignal &signal +) { + // + ModifyAllPriceLesserOpenTrades(signal); +} +// +// END Modify Orders ... +// +// +// END Orders Functions ... +// + +// +// START Signal Conditions ... +// +// +// Clear Signal Conditions ... +void ClearSignalConditions() { + // + ClearLongSignalConditions(); + ClearShortSignalConditions(); +} + +// +// Clear all Conditions Waiter for Long Signals ... +void ClearLongSignalConditions() { + // + ClearXLongSignalConditions(); + ClearXRLongSignalConditions(); + ClearXTPWLongSignalConditions(); +} + +// +// Clear all Conditions Waiter for Short Signals ... +void ClearShortSignalConditions() { + // + ClearXShortSignalConditions(); + ClearXRShortSignalConditions(); + ClearXTPWShortSignalConditions(); +} +// +// END Signal Conditions ... +// diff --git a/Bkp/BTCUSD-15M/Libraries/x-saherelm.x.signal.lib.mq4 b/Bkp/BTCUSD-15M/Libraries/x-saherelm.x.signal.lib.mq4 new file mode 100644 index 0000000..8534420 --- /dev/null +++ b/Bkp/BTCUSD-15M/Libraries/x-saherelm.x.signal.lib.mq4 @@ -0,0 +1,1063 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 X Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Inputs ... +// +// +input string xStarter = "- X Signal Provider -"; // ---> X Signal Provider <--- + +// +input bool enableXSignalling = false; // X Signalling Enable + +// +input bool enableXLong = true; // X Signalling Enable Long +input bool enableXShort = true; // X Signalling Enable Short + +// +input double xShortR2R = 3; // X Short Risk To Reward Ratio +input double xShortLotsPerTradePercent = 0.0002; // X Lots Percent per Short Trades +input double xShortMaxDrawdownPerTradePercent = 0.4; // X Max Allowed DrawDown Percent per Short Trade + +// +input double xLongR2R = 3; // X Long Risk To Reward Ratio +input double xLongLotsPerTradePercent = 0.0002; // X Lots Percent per Short Trades +input double xLongMaxDrawdownPerTradePercent = 0.4; // X Max Allowed DrawDown Percent per Long Trade + +// +input double xSharpDetectorFactor = 700; // X Sharp Detection Factor + +// +input int xMaximumCandlesPerTrade = 206; // X Maximum Candles which a Trade can open + +// +input int xOscillatorLength = 7; // X Oscillator Length + +// +input double xPSarStep = 0.02; // X Parabolic Sar Step +input double xPSarMaximum = 0.2; // X Parabolic Sar Maximum + +// +input int xRangeMarketLength = 5; // X Range Detector Length + +// +input int xSwingLength = 7; // X Signal Swing Length +// +// END Inputs ... +// + +// +// START Global Requirement Functions ... +// +// +// X Based Signal Conditions ... +struct XSignalConditions { + datetime startTime; + datetime signalTime; + datetime entryTime; +}; + +// +struct XMarketState { + double psar; + double fast; + double slow; + double open; + double verifier; + double oscillator; + double oscillatorVerifier; +}; + +// +static XSignalConditions xLongConds; +static bool xCloseLongTrades = false; +static bool xWaitForLongSignals = true; + +// +static XSignalConditions xShortConds; +static bool xCloseShortTrades = false; +static bool xWaitForShortSignals = true; + +// +// Count Number of Closed Maximum DrawDown Trades ... +static int xFailedSignals = 0; + +// +datetime lastVerifierTouched; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckXSignalHandler( + const int bar_index +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + // + if ( + !enableXSignalling + || !(enableXLong || enableXShort) + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XOHCL candle = GetCandleModel(bar_index); + XOHCL pCandle = GetCandleModel(bar_index + 1); + XTPOWState tPowState = GetXTPowState( + bar_index + 1, + xSwingLength + ); + + // + XMarketState state = GetXMarketState( + bar_index + 1 + ); + + // + // Check Verifier Last Touched ... + bool isVerifierTouched = pCandle.high > state.verifier + && pCandle.low < state.verifier; + + // + // Disable Signals if a signal Failed ... + if (xFailedSignals) { + // + // TODO: Complete this ... + } + + // + // Enable Or Disable Signalling ... + if (isVerifierTouched) { + // + lastVerifierTouched = barTime; + + // + if (xWaitForLongSignals) { + xWaitForLongSignals = false; + } + + // + if (xWaitForShortSignals) { + xWaitForShortSignals = false; + } + } else { + // + int lastVerifierTouchedBarIndex = iBarShift( + _Symbol, + _Period, + lastVerifierTouched + ); + + // + int distance = MathAbs(lastVerifierTouchedBarIndex - bar_index); + + // + if ( + !xWaitForLongSignals + && distance > (xSwingLength * 2) + ) { + xWaitForLongSignals = true; + } + + // + if ( + !xWaitForShortSignals + && ( + distance > (xSwingLength * 2) + || ( + tPowState.powerDown > tPowState.powerUp + && tPowState.powerDown < 49 + ) + ) + ) { + xWaitForShortSignals = true; + } + } + + // + // Close All Long Open Trades ... + if ( + tPowState.powerDown > 55 + && tPowState.powerDown > tPowState.powerUp + ) { + // xCloseLongTrades = true; + } +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXLongSignalConditions( + const int bar_index +) { + // + if ( + !enableXLong + || !enableXSignalling + || !xWaitForLongSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + bool isCrossOver = false; + bool isCrossUnder = false; + + // + XMarketState cState = GetXMarketState(1); + XMarketState pState = GetXMarketState(2); + + // + isCrossUnder = + cState.fast < cState.slow + && !(pState.fast < pState.slow) + ; + + // + isCrossOver = + cState.fast > cState.slow + && !(pState.fast > pState.slow) + ; + + // + if ( + isCrossUnder + && xLongConds.startTime == 0 + ) { + // + xLongConds.startTime = barTime; + return; + } + + // + if ( + isCrossOver + && xLongConds.startTime > 0 + && xLongConds.signalTime == 0 + ) { + // + xLongConds.signalTime = barTime; + xLongConds.entryTime = barTime; + return; + } +} + +// +// Check and Fill Short Signal Conditions ... +void CheckXShortSignalConditions( + const int bar_index +) { + // + if ( + !enableXShort + || !enableXSignalling + || !xWaitForShortSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + bool isCrossOver = false; + bool isCrossUnder = false; + + // + XMarketState cState = GetXMarketState(1); + XMarketState pState = GetXMarketState(2); + + // + isCrossUnder = + cState.fast < cState.slow + && !(pState.fast < pState.slow) + ; + + // + isCrossOver = + cState.fast > cState.slow + && !(pState.fast > pState.slow) + ; + + // + if ( + isCrossOver + && xShortConds.startTime == 0 + ) { + // + xShortConds.startTime = barTime; + return; + } + + // + if ( + isCrossUnder + && xShortConds.startTime > 0 + && xShortConds.signalTime == 0 + ) { + // + xShortConds.signalTime = barTime; + xShortConds.entryTime = barTime; + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if ( + !enableXSignalling + || !(enableXLong || enableXShort) + ) { + return result; + } + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + if (requestLong) { + // + if ( + !ValidateXLongConditions() + ) { + return result; + } + } else { + // + if ( + !ValidateXShortConditions() + ) { + return result; + } + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double askPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double bidPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double entryPrice = requestLong ? + askPrice : + bidPrice; + + // + double exitPrice = requestLong ? + bidPrice : + askPrice; + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + // + GetMarketLowestLow( + bar_index, + xSwingLength + ) + ; + + // + double hh = + // + GetMarketHighestHigh( + bar_index, + xSwingLength + ) + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = requestLong ? + MathMin(openPrice, closePrice) - ll : + hh - MathMax(openPrice, closePrice) + ; + + // + double reward = + requestLong ? + risk * xLongR2R : + risk * xShortR2R + ; + + // + double sl = requestLong ? + 0 : + 0; + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward + ; + + // + XRState range = GetXRange( + bar_index, + xRangeMarketLength + ); + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XXX_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XXX_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXLongConditions() { + // + if ( + !enableXLong + || !enableXSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xLongConds.startTime > 0 + && xLongConds.signalTime > 0 + && xLongConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.signalTime + ); + + // + int entryBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.entryTime + ); + + // + isBLFilled = + // + xLongConds.signalTime > xLongConds.startTime + && xLongConds.entryTime >= xLongConds.signalTime + // && MathAbs(signalBarIndex - startBarIndex) >= 1 + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXLongSignalConditions(); + } + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXShortConditions() { + // + if ( + !enableXShort + || !enableXSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xShortConds.startTime > 0 + && xShortConds.signalTime > 0 + && xShortConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.signalTime + ); + + // + int entryBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.entryTime + ); + + // + isBLFilled = + // + xShortConds.signalTime > xShortConds.startTime + && xShortConds.entryTime >= xShortConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xWaitForShortSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXShortSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXLongSignalConditions() { + // + xLongConds.startTime = 0; + xLongConds.entryTime = 0; + xLongConds.signalTime = 0; +} + +// +// Clear Short Signal Conditions for New One ... +void ClearXShortSignalConditions() { + // + xShortConds.startTime = 0; + xShortConds.entryTime = 0; + xShortConds.signalTime = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForXSignals( + const XSignal &signal +) { + // + bool result = false; + + // + if ( + !enableXSignalling + || !(enableXLong || enableXShort) + ) { + return result; + } + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // XOHCL candle = GetCandleModel(0); + XOHCL candle = GetCandleModel(signalBarIndex); + XOHCL pCandle = GetCandleModel(signalBarIndex + 1); + + // + // Retrieve Range ... + XRState range = GetXRange( + signalBarIndex, + xRangeMarketLength + ); + + // + // Retrive XMarket States ... + XMarketState xState0 = GetXMarketState(signalBarIndex); + XMarketState xState1 = GetXMarketState(signalBarIndex + 1); + XMarketState xState2 = GetXMarketState(signalBarIndex + 2); + XMarketState xStateLast = GetXMarketState(signalBarIndex + xSwingLength); + + // + // Retrieve Trend Powers ... + XTPOWState xTPow0 = GetXTPowState( + signalBarIndex, + xSwingLength + ); + XTPOWState xTPow1 = GetXTPowState( + signalBarIndex + 1, + xSwingLength + ); + + // + double hh = GetMarketHighestHigh( + signalBarIndex, + xSwingLength + ); + double ll = GetMarketLowestLow( + signalBarIndex, + xSwingLength + ); + double diffChange = (hh - ll); + bool isBigSharpOccured = + diffChange > (xSharpDetectorFactor * _Point) + ; + + // + bool isPSarVerified = false; + bool isTPowVerified = false; + bool isStateVerified = false; + bool isPriceVerified = false; + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + // Get Price Verification for Long ... + isPriceVerified = + // + // Starter ... + true + // + && !isBigSharpOccured + // + && signal.entry < hh + // + // && signal.entry < range.hh + // && signal.entry > range.mid + // // + // && candle.high > xState0.verifier + // && signal.entry > xState0.verifier + // + // && pCandle.low != ll + && pCandle.high != hh + ; + + // + int above20TPowers = 0; + double signalSlope = 0; + int tPowUnverifyConditions = 0; + int tPowUnverifyConditionsIdx = 0; + for (int i = signalBarIndex; i < signalBarIndex + xSwingLength; i++) { + // + XTPOWState iTPowState = GetXTPowState( + i, + xSwingLength + ); + + // + // Calculate Signal Slope ... + if (i == signalBarIndex) { + // + signalSlope = iTPowState.signal; + } else if (i == signalBarIndex + 1) { + // + signalSlope = GetSlope( + 1, + iTPowState.signal, + 2, + signalSlope + ); + } + + // + if ( + iTPowState.powerUp > iTPowState.powerDown + && MathMax(iTPowState.powerUp, iTPowState.powerDown) > 20 + ) { + above20TPowers++; + } + + // + if (tPowUnverifyConditionsIdx < 3) { + // + if ( + iTPowState.powerUp < iTPowState.powerDown + || iTPowState.signal > MathMax(iTPowState.powerUp, iTPowState.powerDown) + ) { + tPowUnverifyConditions++; + } + + // + tPowUnverifyConditionsIdx++; + } + } + + // + isTPowVerified = + above20TPowers > 1 + && tPowUnverifyConditions == 0 + ; + + // + isPSarVerified = + xState0.psar < signal.entry + && xState0.psar < candle.low; + + // + isStateVerified = + // + // Start ... + true + // + // && xState0.open < xState0.slow + ; + + // + result = + // + // Starter ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + isPSarVerified = + xState0.psar > signal.entry + && xState0.psar > candle.high + ; + + // + // Get Price Verification for Short ... + isPriceVerified = + // + // Starter ... + true + // + && !isBigSharpOccured + // + && signal.entry > ll + && pCandle.low != ll + ; + + // + int above20TPowers = 0; + double signalSlope = 0; + int tPowUnverifyConditions = 0; + int tPowUnverifyConditionsIdx = 0; + for (int i = signalBarIndex; i < signalBarIndex + xSwingLength; i++) { + // + XTPOWState iTPowState = GetXTPowState( + i, + xSwingLength + ); + + // + // Calculate Signal Slope ... + if (i == signalBarIndex) { + // + signalSlope = iTPowState.signal; + } else if (i == signalBarIndex + 1) { + // + signalSlope = GetSlope( + 1, + iTPowState.signal, + 2, + signalSlope + ); + } + + // + if ( + iTPowState.powerUp > iTPowState.powerDown + && MathMax(iTPowState.powerUp, iTPowState.powerDown) > 20 + ) { + above20TPowers++; + } + + // + if (tPowUnverifyConditionsIdx < 3) { + // + if ( + iTPowState.powerUp > iTPowState.powerDown + || iTPowState.signal < MathMax(iTPowState.powerUp, iTPowState.powerDown) + ) { + tPowUnverifyConditions++; + } + + // + tPowUnverifyConditionsIdx++; + } + } + + // + isTPowVerified = + above20TPowers < 1 + && tPowUnverifyConditions == 0 + && MathAbs(xTPow0.powerUp - xTPow0.powerDown) > 50 * _Point + ; + + // + isStateVerified = + // + // Start ... + true + // + // && (xStateLast.verifier - xState0.verifier) >= 0 + // + && xState0.verifier > signal.entry + // + && MathAbs(signal.entry - xState0.verifier) < (xSharpDetectorFactor * _Point) + ; + + // + result = + // + // Starter Condition ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } + + // + return result; +} +// +// END Functions ... +// + +// +// START Data Provider ... +// +XMarketState GetXMarketState( + const int bar_index +) { + // + XMarketState result = {}; + + // + double fast = GetMA( + bar_index, + xSwingLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double open = GetMA( + bar_index, + xSwingLength, + 0, + MODE_SMA, + PRICE_OPEN + ); + + // + double slow = GetMA( + bar_index, + xSwingLength * 2, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double oscillator = GetMA( + bar_index, + xSwingLength, + 0, + MODE_EMA, + PRICE_CLOSE + ); + + // + double oscillatorVerifier = GetMA( + bar_index, + xSwingLength, + 0, + MODE_EMA, + PRICE_WEIGHTED + ); + + // + int dailyCount = GetDailyCandleCount(); + double verifier = GetMA( + bar_index, + dailyCount, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double psar = iSAR( + _Symbol, + _Period, + xPSarStep, + xPSarMaximum, + bar_index + ); + + // + result.psar = psar; + result.fast = fast; + result.open = open; + result.slow = slow; + result.verifier = verifier; + result.oscillator = oscillator; + result.oscillatorVerifier = oscillatorVerifier; + + // + return result; +} +// +// END Data Provider ... +// diff --git a/Bkp/BTCUSD-15M/Libraries/x-saherelm.xr.signal.lib.mq4 b/Bkp/BTCUSD-15M/Libraries/x-saherelm.xr.signal.lib.mq4 new file mode 100644 index 0000000..53785cf --- /dev/null +++ b/Bkp/BTCUSD-15M/Libraries/x-saherelm.xr.signal.lib.mq4 @@ -0,0 +1,1142 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 X Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Inputs ... +// +// +input string xRStarter = "- XR Signal Provider -"; // --> XR Signal Provider <-- + +// +input bool enableXRSignalling = false; // XR Signalling Enable + +// +input bool enableXRLong = true; // XR Signalling Enable Long +input bool enableXRShort = true; // XR Signalling Enable Short + +// +input double xRShortR2R = 1.5; // XR Short Risk To Reward Ratio +input double xRShortLotsPerTradePercent = 0.0002; // XR Lots Percent per Short Trades +input double xRShortMaxDrawdownPerTradePercent = 0.15; // XR Max Allowed DrawDown Percent per Short Trade + +// +input double xRLongR2R = 1.5; // XR Long Risk To Reward Ratio +input double xRLongLotsPerTradePercent = 0.0002; // XR Lots Percent per Short Trades +input double xRLongMaxDrawdownPerTradePercent = 0.15; // XR Max Allowed DrawDown Percent per Long Trade + +// +input int xRMaximumCandlesPerTrade = 96; // XR Maximum Candles which a Trade can open + +// +input int xRSwingLength = 48; // XR Swing Length +// +// END Inputs ... +// + +// +input double xRSharpDetectionFactor = 1350; // XR Sharp Detection Factor + +// +// START Global Requirement Functions ... +// +// +// XR Market State ... +struct XRMarketState { + // + double fast; + double slow; + double open; + + // + double range; + double rangeFast; + double rangeSlow; + double rangeOpen; + + // + double verifier; +}; + +// +// XR Based Signal Conditions ... +struct XRSignalConditions { + datetime startTime; + datetime signalTime; + datetime entryTime; +}; + +// +static XRSignalConditions xRLongConds; +static bool xRCloseLongTrades = false; +static bool xRWaitForLongSignals = true; + +// +static XRSignalConditions xRShortConds; +static bool xRCloseShortTrades = false; +static bool xRWaitForShortSignals = true; + +// +// Count Number of Closed Maximum DrawDown Trades ... +static int xRFailedSignals = 0; + +// +double xRMaximumDrawDown = 0; + +// +int fastLength = 0; +int slowLength = 0; + +// +int verifierLength = 0; + +// +int rangeFastLength = 0; +int rangeSlowLength = 0; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckXRSignalHandler( + const int bar_index +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + + // + if ( + !enableXRSignalling + || !(enableXRLong || enableXRShort) + ) { + return; + } +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXRLongSignalConditions( + const int bar_index +) { + // + if ( + !enableXRLong + || !enableXRSignalling + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Read Prices ... + XPrice prices = GetPrice(); + + // + // Read XPVTState ... + XPvtState pvt0 = GetPVTState( + bar_index, + xRSwingLength + ); + + // + // Double Length Pivots ... + XPvtState dblPvt0 = GetPVTState( + bar_index, + (xRSwingLength * 2) + ); + + // + // Reading Required Candles ... + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + XOHCL candle3 = GetCandleModel(bar_index + 3); + + // + // Reding Required XRMarketStates ... + XRMarketState state0 = GetXRMarketState(bar_index); + XRMarketState state1 = GetXRMarketState(bar_index + 1); + XRMarketState state2 = GetXRMarketState(bar_index + 2); + XRMarketState state3 = GetXRMarketState(bar_index + 3); + + // + // Reading required XRangeStates ... + XRState range0 = ReadXRange( + bar_index + xRSwingLength, + xRSwingLength + ); + XRState range1 = ReadXRange( + bar_index + xRSwingLength + 1, + xRSwingLength + ); + XRState range2 = ReadXRange( + bar_index + xRSwingLength + 2, + xRSwingLength + ); + + // + XRState cRange0 = ReadXRange( + bar_index, + xRSwingLength + ); + + // + // Validate Farest Range Values ... + if ( + range2.hh == 0 + || + range2.ll == 0 + || + range2.mid == 0 + ) { + return; + } + + // + // Reading Required XTPowStates ... + XTPOWState tPow0 = GetXTPowState( + bar_index, + xRSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xRSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xRSwingLength + ); + + // + // if state verifier below range middle + // this means market is bullish ... + // + // if state verifier above range middle + // this means market is bearish ... + // + + // + bool isMarketBullish = + state0.verifier < range0.mid + && state1.verifier < range1.mid; + bool isMarketBearish = + state0.verifier > range0.mid + && state1.verifier > range1.mid; + bool isMarketGoingBullish = + state0.verifier > range0.mid + && !(state1.verifier > range1.mid); + bool isMarketGoingBearish = + state0.verifier < range0.mid + && !(state1.verifier < range1.mid); + + // + // Check Highest High Conditions ... + bool isHHVerified = + !( + pvt0.hh == dblPvt0.hh + ) + ; + + // + int sharpDetectionLength = 7; + double sharpDetectionValue = xRSharpDetectionFactor * _Point; + + // + int sharpHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + sharpDetectionLength, + bar_index + ); + double sharpHH = iHigh( + _Symbol, + _Period, + sharpHHIdx + ); + + // + int sharpLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + sharpDetectionLength, + bar_index + ); + double sharpLL = iLow( + _Symbol, + _Period, + sharpLLIdx + ); + + // + double sharpDiff = sharpHH - sharpLL; + bool isSharpOccered = + sharpDiff > sharpDetectionValue; + + // + XRMarketState lastState = GetXRMarketState( + bar_index + sharpDetectionLength + ); + + // + double stateFSDiff = (state0.fast - state0.slow) - (lastState.fast - lastState.slow); + + // + // Start Calculating Long Conditions ... + bool longCondition1 = + // + // Starter ... + true + // + && isMarketBullish + // + && + ( + candle2.high < range2.mid + || ( + candle2.high > range2.mid + && candle2.low < range2.mid + ) + ) + && candle1.low > range1.mid + ; + + // + if ( + // + ( + longCondition1 + ) + // + && xRLongConds.startTime == 0 + && xRLongConds.entryTime == 0 + && xRLongConds.signalTime == 0 + ) { + // + xRLongConds.startTime = barTime; + xRLongConds.entryTime = barTime; + xRLongConds.signalTime = barTime; + + // + return; + } +} + +// +// Check and Fill Short Signal Conditions ... +void CheckXRShortSignalConditions( + const int bar_index +) { + // + if ( + !enableXRShort + || !enableXRSignalling + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Read Prices ... + XPrice prices = GetPrice(); + + // + // Read XPVTState ... + XPvtState pvt0 = GetPVTState( + bar_index, + xRSwingLength + ); + + // + // Double Length Pivots ... + XPvtState dblPvt0 = GetPVTState( + bar_index, + (xRSwingLength * 2) + ); + + // + // Reading Required Candles ... + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + XOHCL candle3 = GetCandleModel(bar_index + 3); + + // + // Reding Required XRMarketStates ... + XRMarketState state0 = GetXRMarketState(bar_index); + XRMarketState state1 = GetXRMarketState(bar_index + 1); + XRMarketState state2 = GetXRMarketState(bar_index + 2); + XRMarketState state3 = GetXRMarketState(bar_index + 3); + + // + // Reading required XRangeStates ... + XRState range0 = ReadXRange( + bar_index + xRSwingLength, + xRSwingLength + ); + XRState range1 = ReadXRange( + bar_index + xRSwingLength + 1, + xRSwingLength + ); + XRState range2 = ReadXRange( + bar_index + xRSwingLength + 2, + xRSwingLength + ); + + // + XRState cRange0 = ReadXRange( + bar_index, + xRSwingLength + ); + + // + // Validate Farest Range Values ... + if ( + range2.hh == 0 + || + range2.ll == 0 + || + range2.mid == 0 + ) { + return; + } + + // + // Reading Required XTPowStates ... + XTPOWState tPow0 = GetXTPowState( + bar_index, + xRSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xRSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xRSwingLength + ); + + // + // if state verifier below range middle + // this means market is bullish ... + // + // if state verifier above range middle + // this means market is bearish ... + // + + // + bool isMarketBullish = + state0.verifier < range0.mid + && state1.verifier < range1.mid; + bool isMarketBearish = + state0.verifier > range0.mid + && state1.verifier > range1.mid; + bool isMarketGoingBullish = + state0.verifier > range0.mid + && !(state1.verifier > range1.mid); + bool isMarketGoingBearish = + state0.verifier < range0.mid + && !(state1.verifier < range1.mid); + + // + // Check Highest High Conditions ... + bool isHHVerified = + !( + pvt0.hh == dblPvt0.hh + ) + ; + + // + int sharpDetectionLength = 7; + double sharpDetectionValue = xRSharpDetectionFactor * _Point; + + // + int sharpHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + sharpDetectionLength, + bar_index + ); + double sharpHH = iHigh( + _Symbol, + _Period, + sharpHHIdx + ); + + // + int sharpLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + sharpDetectionLength, + bar_index + ); + double sharpLL = iLow( + _Symbol, + _Period, + sharpLLIdx + ); + + // + double sharpDiff = sharpHH - sharpLL; + bool isSharpOccered = + sharpDiff > sharpDetectionValue; + + // + XRMarketState lastState = GetXRMarketState( + bar_index + sharpDetectionLength + ); + + // + double stateFSDiff = (state0.fast - state0.slow) - (lastState.fast - lastState.slow); + + // + // Start Calculating Long Conditions ... + bool shortCondition1 = + // + // Starter ... + true + // + && isMarketBearish + // + && + ( + candle2.low > range2.mid + || ( + candle2.high > range2.mid + && candle2.low < range2.mid + ) + ) + && candle1.high < range1.mid + ; + + // + if ( + // + ( + shortCondition1 + ) + // + && xRShortConds.startTime == 0 + && xRShortConds.entryTime == 0 + && xRShortConds.signalTime == 0 + ) { + // + xRShortConds.startTime = barTime; + xRShortConds.entryTime = barTime; + xRShortConds.signalTime = barTime; + + // + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXRSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if ( + !enableXRSignalling + || !(enableXRLong || enableXRShort) + ) { + return result; + } + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + if (requestLong) { + // + if ( + !ValidateXRLongConditions() + ) { + return result; + } + } else { + // + if ( + !ValidateXRShortConditions() + ) { + return result; + } + } + + // + // Price Calculations ... + XPvtState pvts = GetPVTState( + bar_index, + xRSwingLength + ); + XPrice prices = GetPrice(); + + // + double entryPrice = requestLong ? + prices.longEntry : + prices.shortEntry + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = requestLong ? + MathMin(openPrice, closePrice) - pvts.ll : + pvts.hh - MathMax(openPrice, closePrice); + if (risk <= 0) { + // + risk = requestLong ? + MathAbs(pvts.hh - entryPrice) : + MathAbs(pvts.ll - entryPrice) + ; + } + + // + double reward = + requestLong ? + risk * xRLongR2R : + risk * xRShortR2R + ; + + // + double sl = requestLong ? + 0 : + 0; + + // + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward + ; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XR_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XR_PROVIDER; + + // + return result; +} + +// +// Validate Long Signal Conditions ... +bool ValidateXRLongConditions() { + // + if ( + !enableXRLong + || !enableXRSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xRLongConds.startTime > 0 + && xRLongConds.signalTime > 0 + && xRLongConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + isBLFilled = + // + xRLongConds.signalTime >= xRLongConds.startTime + && xRLongConds.entryTime >= xRLongConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xRWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXRLongSignalConditions(); + } + + // + return result; +} + +// +// Validate Short Signal Conditions ... +bool ValidateXRShortConditions() { + // + if ( + !enableXRShort + || !enableXRSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xRShortConds.startTime > 0 + && xRShortConds.signalTime > 0 + && xRShortConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + isBLFilled = + // + xRShortConds.signalTime >= xRShortConds.startTime + && xRShortConds.entryTime >= xRShortConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xRWaitForShortSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXRShortSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXRLongSignalConditions() { + // + xRLongConds.startTime = 0; + xRLongConds.signalTime = 0; + xRLongConds.entryTime = 0; +} + +// +// Clear Short Signal Conditions for New One ... +void ClearXRShortSignalConditions() { + // + xRShortConds.startTime = 0; + xRShortConds.signalTime = 0; + xRShortConds.entryTime = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForXRSignals( + const XSignal &signal +) { + // + bool result = false; + + // + if ( + !enableXRSignalling + || !(enableXRLong || enableXRShort) + ) { + return result; + } + + // + // Find Signal Bar Index ... + int signalBarIndex = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // Read Prices ... + XPrice prices = GetPrice(); + + // + // Read XPVTState ... + XPvtState pvt0 = GetPVTState( + signalBarIndex, + xRSwingLength + ); + + // + // Reading Required Candles ... + XOHCL candle0 = GetCandleModel(signalBarIndex); + XOHCL candle1 = GetCandleModel(signalBarIndex + 1); + XOHCL candle2 = GetCandleModel(signalBarIndex + 2); + XOHCL candle3 = GetCandleModel(signalBarIndex + 3); + + // + // Reding Required XRMarketStates ... + XRMarketState state0 = GetXRMarketState(signalBarIndex); + XRMarketState state1 = GetXRMarketState(signalBarIndex + 1); + XRMarketState state2 = GetXRMarketState(signalBarIndex + 2); + XRMarketState state3 = GetXRMarketState(signalBarIndex + 3); + + // + // Reading required XRangeStates ... + XRState range0 = ReadXRange( + signalBarIndex + xRSwingLength, + xRSwingLength + ); + XRState range1 = ReadXRange( + signalBarIndex + xRSwingLength + 1, + xRSwingLength + ); + XRState range2 = ReadXRange( + signalBarIndex + xRSwingLength + 2, + xRSwingLength + ); + + // + // Reading Required XTPowStates ... + XTPOWState tPow0 = GetXTPowState( + signalBarIndex, + xRSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + signalBarIndex + 1, + xRSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + signalBarIndex + 2, + xRSwingLength + ); + + // + double hhllDiff = MathAbs(pvt0.hh - pvt0.ll); + double sharpDetectionValue = xRSharpDetectionFactor * _Point; + bool isSharpOccured = hhllDiff > sharpDetectionValue; + + // + // Calculate State Min Max Diff ... + // + double state0Min = MathMin(state0.fast, state0.slow); + state0Min = MathMin(state0Min, state0.open); + state0Min = MathMin(state0Min, state0.rangeFast); + state0Min = MathMin(state0Min, state0.rangeSlow); + state0Min = MathMin(state0Min, state0.rangeOpen); + state0Min = MathMin(state0Min, state0.verifier); + + // + double state0Max = MathMax(state0.fast, state0.slow); + state0Max = MathMax(state0Max, state0.open); + state0Max = MathMax(state0Max, state0.rangeFast); + state0Max = MathMax(state0Max, state0.rangeSlow); + state0Max = MathMax(state0Max, state0.rangeOpen); + state0Max = MathMax(state0Max, state0.verifier); + + // + double state0MinMaxDiff = (state0Max - state0Min); + + // + bool isTPowValid = false; + bool isStateValid = false; + bool isRangeValid = false; + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + // Retrieve TPow Verifications ... + isTPowValid = + // + // Starter ... + true + ; + + // + // Retrieve XMarket Verifications ... + isStateValid = + // + // Starter ... + true + // + // && !(state0MinMaxDiff > sharpDetectionValue) + ; + + // + // Retrieve XRange Verifications ... + isRangeValid = + // + // Starter ... + true + ; + + // + result = + // + // Starter ... + true + // + && isTPowValid + && isStateValid + && isRangeValid + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + // Retrieve TPow Verifications ... + isTPowValid = + // + // Starter ... + true + ; + + // + // Retrieve XMarket Verifications ... + isStateValid = + // + // Starter ... + true + ; + + // + // Retrieve XRange Verifications ... + isRangeValid = + // + // Starter ... + true + ; + + // + result = + // + // Starter ... + true + // + && isTPowValid + && isStateValid + && isRangeValid + ; + } + + // + return result; +} +// +// END Functions ... +// + +// +// START Data Providers ... +// +// +XRMarketState GetXRMarketState( + const int bar_index +) { + // + XRMarketState result = {}; + + // + // Calculate Market Lengths ... + + // + if (fastLength == 0) { + fastLength = xRSwingLength; + } + + // + if (slowLength == 0) { + slowLength = xRSwingLength * 2; + } + + // + if (verifierLength == 0) { + verifierLength = (GetDailyCandleCount() * 2); + } + + // + if (rangeFastLength == 0) { + rangeFastLength = (int)(verifierLength / 2); + } + + // + if (rangeSlowLength == 0) { + rangeSlowLength = verifierLength; + } + + // + // Reading Values ... + + // + double fast = GetMA( + bar_index, + fastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double slow = GetMA( + bar_index, + slowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double open = GetMA( + bar_index, + fastLength, + 0, + MODE_SMA, + PRICE_OPEN + ); + + // + double rangeFast = GetMA( + bar_index, + rangeFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double rangeSlow = GetMA( + bar_index, + rangeSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double rangeOpen = GetMA( + bar_index, + rangeFastLength, + 0, + MODE_SMA, + PRICE_OPEN + ); + + // + double verifier = GetMA( + bar_index, + verifierLength, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + // Filling Result ... + result.fast = fast; + result.slow = slow; + result.open = open; + result.verifier = verifier; + result.rangeFast = rangeFast; + result.rangeSlow = rangeSlow; + result.rangeOpen = rangeOpen; + + // + return result; +} +// +// END Data Providers ... +// \ No newline at end of file diff --git a/Bkp/BTCUSD-15M/Libraries/x-saherelm.xtpw.signal.lib.mq4 b/Bkp/BTCUSD-15M/Libraries/x-saherelm.xtpw.signal.lib.mq4 new file mode 100644 index 0000000..11c7340 --- /dev/null +++ b/Bkp/BTCUSD-15M/Libraries/x-saherelm.xtpw.signal.lib.mq4 @@ -0,0 +1,1251 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 XTPW Signal Global Library +// --------------------------------------------------- +// XSaherElm EA Signal Provider based on +// XTPow Indicator... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Inputs ... +// +// +input string xTPWStarter = "- XTPW Signal Provider -"; // ---> XTPW Signal Provider <--- + +// +input bool enableXTPWSignalling = true; // XTPW Signalling Enable + +// +input bool enableXTPWLong = true; // XTPW Signalling Enable Long +input bool enableXTPWShort = false; // XTPW Signalling Enable Short + +// +input double xTPWShortR2R = 2; // XTPW Short Risk To Reward Ratio +input double xTPWShortLotsPerTradePercent = 0.0002; // XTPW Lots Percent per Short Trades +input double xTPWShortMaxDrawdownPerTradePercent = 0.3; // XTPW Max Allowed DrawDown Percent per Short Trade + +// +input double xTPWLongR2R = 3; // XTPW Long Risk To Reward Ratio +input double xTPWLongLotsPerTradePercent = 0.00001; // XTPW Lots Percent per Short Trades +input double xTPWLongMaxDrawdownPerTradePercent = 0.03; // XTPW Max Allowed DrawDown Percent per Long Trade + +// +input int xTPWMaximumCandlesPerTrade = 144; // XTPW Maximum Candles which a Trade can open + +// +input double xTPWPSarStep = 0.02; // XTPW Parabolic Sar Step +input double xTPWPSarMaximum = 0.2; // XTPW Parabolic Sar Maximum + +// +input int xTPWSwingLength = 7; // XTPW Signal Swing Length +// +// END Inputs ... +// + +// +input double xTPWSharpDetectionFactor = 650; // XTPW Sharp Detection Factor + +// +// START Global Requirement Functions ... +// +// +// XTPW Based Signal Conditions ... +struct XTPWSignalConditions { + datetime startTime; + datetime signalTime; + datetime entryTime; +}; + +// +struct XTPWMarketState { + // + double psar; + + // + double scFast; + double scSlow; + double scWeight; + + // + double mcFast; + double mcSlow; + double mcWeight; + + // + double lcFast; + double lcSlow; + double lcWeight; +}; + +// +struct XLHS { + // + double scHH; + double scLL; + + // + double mcHH; + double mcLL; + + // + double lcHH; + double lcLL; +}; + +// +static XTPWSignalConditions xTPWLongConds; +static bool xTPWCloseLongTrades = false; +static bool xTPWWaitForLongSignals = true; + +// +static XTPWSignalConditions xTPWShortConds; +static bool xTPWCloseShortTrades = false; +static bool xTPWWaitForShortSignals = true; + +// +// Count Number of Closed Maximum DrawDown Trades ... +static int xTPWFailedSignals = 0; + +// +double tPowerVerifier = 20; +double tPowerMaxVerifier = 55; + +// +int scFastLength = 0; +int scSlowLength = 0; + +// +int mcFastLength = 0; +int mcSlowLength = 0; + +// +int lcFastLength = 0; +int lcSlowLength = 0; + +// +datetime lastTurnOffLongTradesTime; +datetime lastTurnOffShortTradesTime; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckXTPWSignalHandler( + const int bar_index +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + + // + if ( + !enableXTPWSignalling + || !(enableXTPWLong || enableXTPWShort) + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 1); + + // + XTPOWState tPow0 = GetXTPowState( + bar_index, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xTPWSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xTPWSwingLength + ); + + // + XTPWMarketState state0 = GetXTPWMarketState( + bar_index + ); + XTPWMarketState state1 = GetXTPWMarketState( + bar_index + 1 + ); + XTPWMarketState state2 = GetXTPWMarketState( + bar_index + 2 + ); + + // // + // // Disable Long Conditions ... + // if ( + // xTPWWaitForLongSignals + // && + // ( + // isRangeCrossOverRangeWeight + // || + // isRangeCrossUnderRangeWeight + // || + // isTPowUpperAboveMaxVerifier + // ) + // ) { + // // + // xTPWWaitForLongSignals = false; + // lastTurnOffLongTradesTime = barTime; + // } + + // // + // // Enable Long Conditions ... + // if ( + // !xTPWWaitForLongSignals + // && lastTurnOffLongTradesTime > 0 + // && ( + // // isFastCrossOverSlow + // // || + // // isFastCrossUnderSlow + // isRangeCrossOverRangeWeight + // || + // isRangeCrossUnderRangeWeight + // || + // isTPowUpperBelowMaxVerifier + // ) + // ) { + // // + // // Find Last Turn Off Bar Index ... + // int lastTurnOffLongTradesBarIndex = iBarShift( + // _Symbol, + // _Period, + // lastTurnOffLongTradesTime + // ); + + // // + // // the Distance must be bigger than market length ... + // if (MathAbs(lastTurnOffLongTradesBarIndex - bar_index) > xTPWSwingLength) { + // // + // xTPWWaitForLongSignals = true; + // lastTurnOffLongTradesTime = 0; + // } + // } +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXTPWLongSignalConditions( + const int bar_index +) { + // + if ( + !enableXTPWLong + || !enableXTPWSignalling + || !xTPWWaitForLongSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Retrieve TPow States ... + XTPOWState tPow0 = GetXTPowState( + bar_index, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xTPWSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xTPWSwingLength + ); + + // + // Retrieve TPowMarket State ... + XTPWMarketState state0 = GetXTPWMarketState( + bar_index + ); + XTPWMarketState state1 = GetXTPWMarketState( + bar_index + 1 + ); + XTPWMarketState state2 = GetXTPWMarketState( + bar_index + 2 + ); + + // + // Retrieve XPrice Model ... + XPrice prices = GetPrice(); + + // + // Retrieve Candles ... + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + + // + XLHS lhs = GetXTPWLHS(bar_index); + + // + bool isHHSame = + lhs.scHH == lhs.mcHH + && lhs.mcHH == lhs.lcHH + ; + + // + bool isLLSame = + lhs.scLL == lhs.mcLL + && lhs.mcLL == lhs.lcLL + ; + + // + bool startCondition = false; + bool signalCondition = false; + bool entryCondition = false; + + // + bool longCondition1 = + // + true + // + && tPow2.powerDown > tPow2.powerUp + && tPow1.powerUp > tPow1.powerDown + && tPow1.powerUp > tPowerVerifier + && tPow1.powerUp < tPowerMaxVerifier + ; + + // + // Start Conditions ... + startCondition = ( + longCondition1 + ) + ; + + // + if ( + startCondition + && xTPWLongConds.startTime == 0 + && xTPWLongConds.signalTime == 0 + && xTPWLongConds.entryTime == 0 + ) { + // + xTPWLongConds.startTime = barTime; + xTPWLongConds.signalTime = barTime; + xTPWLongConds.entryTime = barTime; + + // + return; + } +} + +// +// Check and Fill Short Signal Conditions ... +void CheckXTPWShortSignalConditions( + const int bar_index +) { + // + if ( + !enableXTPWShort + || !enableXTPWSignalling + || !xTPWWaitForShortSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Retrieve TPower State ... + XTPOWState tPow0 = GetXTPowState( + bar_index, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xTPWSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xTPWSwingLength + ); + + // + // Retrieve TPWMarket State ... + XTPWMarketState state0 = GetXTPWMarketState( + bar_index + ); + XTPWMarketState state1 = GetXTPWMarketState( + bar_index + 1 + ); + XTPWMarketState state2 = GetXTPWMarketState( + bar_index + 2 + ); + + // + // Retrieve Candles ... + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + + // + XPrice prices = GetPrice(); + XLHS lhs = GetXTPWLHS(bar_index); + + // + double sharpDetectionValue = + xTPWSharpDetectionFactor * _Point; + + // + bool isHHSame = + lhs.scHH == lhs.mcHH + && lhs.mcHH == lhs.lcHH + ; + + // + bool isLLSame = + lhs.scLL == lhs.mcLL + && lhs.mcLL == lhs.lcLL + ; + + // + bool startCondition = false; + bool signalCondition = false; + bool entryCondition = false; + + // + bool shortCondition1 = + // + true + // + && tPow1.powerDown > tPowerMaxVerifier + && tPow2.powerDown < tPowerMaxVerifier + ; + + // + startCondition = ( + shortCondition1 + ) + ; + + // + if ( + startCondition + && xTPWShortConds.startTime == 0 + && xTPWShortConds.signalTime == 0 + && xTPWShortConds.entryTime == 0 + ) { + // + xTPWShortConds.startTime = barTime; + xTPWShortConds.signalTime = barTime; + xTPWShortConds.entryTime = barTime; + + // + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXTPWSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if ( + !enableXTPWSignalling + || !(enableXTPWLong || enableXTPWShort) + ) { + return result; + } + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + // Check Condition Validations ... + if (requestLong) { + // + // Check Long Condtion is Valid, if Long Requested ... + if ( + !ValidateXTPWLongConditions() + ) { + return result; + } + } else { + // + // Check Short Condtion is Valid, if Short Requested ... + if ( + !ValidateXTPWShortConditions() + ) { + return result; + } + } + + // + double ll = + // + GetMarketLowestLow( + bar_index, + xTPWSwingLength + ) + ; + + // + double hh = + // + GetMarketHighestHigh( + bar_index, + xTPWSwingLength + ) + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + // Price Calculations ... + XPrice prices = GetPrice(); + + // + // Read State ... + XTPWMarketState state0 = GetXTPWMarketState(bar_index); + + // + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + XOHCL candle3 = GetCandleModel(bar_index + 2); + + // + double risk = requestLong ? + // + MathMin(openPrice, closePrice) - ll : + hh - MathMax(openPrice, closePrice) + ; + + // + double longR2R = xTPWLongR2R; + double shortR2R = xTPWShortR2R; + + // + double sharpDetectorValue = xTPWSharpDetectionFactor * _Point; + + // + if ( + risk > 0 + && requestLong + ) { + return result; + } + + // + // Define Entry Price ... + double entryPrice = requestLong + ? + prices.longEntry + : + prices.shortEntry + ; + + // + // Fix TP Detects for Short Signals ... + if (!requestLong) { + risk = 0; + } + + // + double reward = requestLong ? + risk * longR2R : + risk * shortR2R + ; + + // + if (risk == 0) { + // + // Calculate Reward ... + reward = requestLong + ? + MathAbs(hh - entryPrice) + : + MathAbs(hh - entryPrice) + ; + + // + // Detect Sharp Change Occured or not ... + bool isSharpOccured = reward > sharpDetectorValue + || MathAbs(reward - sharpDetectorValue) < (50 * _Point); + + // + // Change Rewards on Special Conditions ... + if ( + ( + requestLong + && isSharpOccured + && ( + state0.lcFast < state0.lcSlow + || ( + state0.mcFast > state0.mcSlow + && state0.mcWeight < state0.mcSlow + ) + ) + ) + ) { + reward = reward / 2; + } + + // + if (reward < 50 * _Point) { + reward = (50 * _Point) + prices.priceGap; + } + + // // + // if (!requestLong) { + // reward = reward * shortR2R; + // } + } + + // + double sl = requestLong ? + 0 : + 0; + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward + ; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XTPW_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XTPW_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXTPWLongConditions() { + // + if ( + !enableXTPWLong + || !enableXTPWSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xTPWLongConds.startTime > 0 + && xTPWLongConds.signalTime > 0 + && xTPWLongConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + isBLFilled = + // + // Starter ... + true + // + && xTPWLongConds.signalTime >= xTPWLongConds.startTime + && xTPWLongConds.entryTime >= xTPWLongConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xTPWWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXTPWLongSignalConditions(); + } + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXTPWShortConditions() { + // + if ( + !enableXTPWShort + || !enableXTPWSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xTPWShortConds.startTime > 0 + && xTPWShortConds.signalTime > 0 + && xTPWShortConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // // + // int startBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWShortConds.startTime + // ); + + // // + // int signalBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWShortConds.signalTime + // ); + + // // + // int entryBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWShortConds.entryTime + // ); + + // + isBLFilled = + // + // Starter ... + true + // + && xTPWShortConds.signalTime >= xTPWShortConds.startTime + && xTPWShortConds.entryTime >= xTPWShortConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xTPWWaitForShortSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXTPWShortSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXTPWLongSignalConditions() { + // + xTPWLongConds.startTime = 0; + xTPWLongConds.entryTime = 0; + xTPWLongConds.signalTime = 0; +} + +// +// Clear Short Signal Conditions for New One ... +void ClearXTPWShortSignalConditions() { + // + xTPWShortConds.startTime = 0; + xTPWShortConds.entryTime = 0; + xTPWShortConds.signalTime = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForXTPWSignals( + const XSignal &signal +) { + // + bool result = false; + + // + if ( + !enableXTPWSignalling + || !(enableXTPWLong || enableXTPWShort) + ) { + return result; + } + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // XOHCL candle = GetCandleModel(0); + XOHCL candle0 = GetCandleModel(signalBarIndex); + XOHCL candle1 = GetCandleModel(signalBarIndex + 1); + + // + // Retrieve TPow State ... + XTPOWState tPow0 = GetXTPowState( + signalBarIndex, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + signalBarIndex + 1, + xTPWSwingLength + ); + + // + // Retrive XMarket States ... + XTPWMarketState state0 = GetXTPWMarketState(signalBarIndex); + XTPWMarketState state1 = GetXTPWMarketState(signalBarIndex + 1); + XTPWMarketState state2 = GetXTPWMarketState(signalBarIndex + 2); + + // + bool isPSarVerified = false; + bool isTPowVerified = false; + bool isStateVerified = false; + bool isPriceVerified = false; + + // + // Calculate Sharp Detection Value ... + double sharpDetectionValue = + xTPWSharpDetectionFactor * _Point; + + // + // Find State0 Min ... + double state0Min = MathMin(state0.scFast, state0.scSlow); + state0Min = MathMin(state0Min, state0.mcFast); + state0Min = MathMin(state0Min, state0.mcSlow); + state0Min = MathMin(state0Min, state0.lcFast); + state0Min = MathMin(state0Min, state0.lcSlow); + + // + // Find State0 Min ... + double state0Max = MathMax(state0.scFast, state0.scSlow); + state0Max = MathMax(state0Max, state0.mcFast); + state0Max = MathMax(state0Max, state0.mcSlow); + state0Max = MathMax(state0Max, state0.lcFast); + state0Max = MathMax(state0Max, state0.lcSlow); + + // + // Find Distance Between State0 Min and Max ... + double state0MinMaxDistance = MathAbs(state0Max - state0Min); + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + // Get Price Verification for Long ... + isPriceVerified = + // + // Starter ... + true + // + ; + + // + isTPowVerified = + // + // Starter ... + true + ; + + // + isPSarVerified = + // + // Starter ... + true + // + ; + + // + isStateVerified = + // + // Start ... + true + // + && state0.lcSlow > 0 + && state0.lcFast > state0.lcSlow + ; + + // + result = + // + // Starter ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + isPSarVerified = + // + // Starter ... + true + ; + + // + // Get Price Verification for Short ... + isPriceVerified = + // + // Starter ... + true + ; + + // + isTPowVerified = + // + // Starter ... + true + ; + + // + isStateVerified = + // + // Start ... + true + ; + + // + result = + // + // Starter Condition ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } + + // + return result; +} +// +// END Functions ... +// + +// +// START Data Provider ... +// +// +// Retrieve Market State ... +XTPWMarketState GetXTPWMarketState( + const int bar_index +) { + // + XTPWMarketState result = {}; + + // + int dayCount = GetDailyCandleCount(); + int halfDayCount = (int)(dayCount / 2); + + // + if (scFastLength == 0) { + scFastLength = xTPWSwingLength; + } + + // + if (scSlowLength == 0) { + scSlowLength = xTPWSwingLength * 2; + } + + // + if (mcFastLength == 0) { + mcFastLength = halfDayCount; + } + + // + if (mcSlowLength == 0) { + mcSlowLength = dayCount; + } + + // + if (lcFastLength == 0) { + lcFastLength = halfDayCount * 3; + } + + // + if (lcSlowLength == 0) { + lcSlowLength = dayCount * 3; + } + + // + double scFast = GetMA( + bar_index, + scFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double scSlow = GetMA( + bar_index, + scSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double scWeight = GetMA( + bar_index, + scSlowLength, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double mcFast = GetMA( + bar_index, + mcFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double mcSlow = GetMA( + bar_index, + mcSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double mcWeight = GetMA( + bar_index, + mcSlowLength, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double lcFast = GetMA( + bar_index, + lcFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double lcSlow = GetMA( + bar_index, + lcSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double lcWeight = GetMA( + bar_index, + lcSlowLength, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double psar = iSAR( + _Symbol, + _Period, + xTPWPSarStep, + xTPWPSarMaximum, + bar_index + ); + + // + result.psar = psar; + result.scFast = scFast; + result.scSlow = scSlow; + result.mcFast = mcFast; + result.mcSlow = mcSlow; + result.lcFast = lcFast; + result.lcSlow = lcSlow; + result.scWeight = scWeight; + result.mcWeight = mcWeight; + result.lcWeight = lcWeight; + + // + return result; +} + +// +// Retrieve Highest Highs and Lowest Lows in Cycles ... +XLHS GetXTPWLHS( + const int bar_index +) { + // + XLHS result = {}; + + // + // Retrieve LL and HH (s) ... + + // + // SC HH ... + double scHH = GetMarketHighestHigh( + bar_index, + scFastLength + ); + + // + // SC LL ... + double scLL = GetMarketHighestHigh( + bar_index, + scFastLength + ); + + // + // MC HH ... + double mcHH = GetMarketHighestHigh( + bar_index, + mcFastLength + ); + + // + // MC LL ... + double mcLL = GetMarketHighestHigh( + bar_index, + mcFastLength + ); + + // + // LC HH ... + double lcHH = GetMarketHighestHigh( + bar_index, + lcFastLength + ); + + // + // LC LL ... + double lcLL = GetMarketHighestHigh( + bar_index, + lcFastLength + ); + + // + result.scHH = scHH; + result.scLL = scLL; + result.mcHH = mcHH; + result.mcLL = mcLL; + result.lcHH = lcHH; + result.lcLL = lcLL; + + // + return result; +} +// +// END Data Provider ... +// diff --git a/Bkp/UnUsed/Experts/x-saherelm.osc.1.ea.mq4 b/Bkp/UnUsed/Experts/x-saherelm.osc.1.ea.mq4 new file mode 100644 index 0000000..e197cbf --- /dev/null +++ b/Bkp/UnUsed/Experts/x-saherelm.osc.1.ea.mq4 @@ -0,0 +1,733 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XST_OSC Strategy Expert Advisor +// --------------------------------------------- +// saherelm implementation of strategy expert advisor ... +// +// ShortName: XST_OSC +// +// 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 XST_OSC Strategy Expert Advisor" +#property strict + +// +// START Inputs ... +// +// +// Signal Prefixe ... +input string signalPrefix = "XST_OSC"; // Signal Prefix + +// +// Signal Draw Specifications ... +input string bullishSignalLabel = "X_BUY"; // Bullish Signal Label +input color bullishSignalColor = clrAqua; // Bullish Signal Color + +// +input string bearishSignalLabel = "X_SELL"; // Bearish Signal Label +input color bearishSignalColor = clrFuchsia; // Bearish Signal Color + +// +input color signalEntryColor = clrAquamarine; // Signal Entry Ptice Color +input color signalSLColor = clrRed; // Signal SL Color +input color signalTPColor = clrGreen; // Signal TP Color + +// +// Trade ... +input bool allowTrade = true; // Allow Trade Based on given Signals +input bool allowLongTrades = true; // Allow Long Trades +input bool allowShortTrades = false; // Allow Short Trades + +// +// Market Specification Inpouts ... +input int marketLength = 7; // Market Length +input double riskToRewardRatio = 1.5; // Risk to Reward Ratio + +// +// Alerts ... +input bool alertEvents = true; // Alert Events +input bool alertPositions = true; // Alert Positions +input bool longPositionAlerts = true; // Alert Long Positions +input bool shortPositionAlerts = true; // Alert Short Positions + +// +// Alert Types ... +input bool terminalAlert = false; // Terminal Alert +input bool pushAlert = false; // Push Notification Alerts + +// +// Balance and Finanical Specifications ... +input double lotsPerTradePercent = 0.0001; // Lots Per Trade Percent +input int maxOpenTrades = 4; // Maximum Open Trade +input double maxDrawdownPercentPerPTrade = 0; // Maximum DrawDown Per Trade +input double minBalancePercent = 0.5; // Minimum Balance for Trading +input double maxEquityPercent = 0.2; // Maximum Trade Equity + +// +// OSC Inputs ... +// +// FastOSC ... +// Short Cycle (Fast OSC) ... +input int fastOSCLength = 10; // FastOSC Length +input double fastOSCMultiplier = 1.0; // FastOSC Multiplier + +// +// SlowOSC ... +// Medium Cycle (Slow OSC) ... +input int slowOSCLength = 30; // SlowOSC Length +input double slowOSCMultiplier = 3.0; // SlowOSC Multiplier + +// +// Power OSC ... +input double minPowerOSC = 0; // Minimum Signal Power + +// +// Variance OSC ... +input double minVarianceOSC = 0; // Minimum Var Power + +// +// ZIGZAG Inputs ... +input int zDeviation = 5; // ZigZag Deviation +input int zBackStep = 3; // ZigZag Back Step + +// +// XMA Inputs ... +// +input int shortCycleFastMultiplier = 1; // Short Cycle Fast Multiplier +input int shortCycleSlowMultiplier = 4; // Short Cycle Slow Multiplier +input int mediumCycleFastMultiplier = 7; // Medium Cycle Fast Multiplier +input int mediumCycleSlowMultiplier = 14; // Medium Cycle Slow Multiplier +input int longCycleFastMultiplier = 70; // Long Cycle Fast Multiplier +input int longCycleSlowMultiplier = 140; // Long Cycle Slow Multiplier +// +// Show/Hide Inputs ... +input bool showShortCycle = false; // Show Short Cycle +input bool showShortCycleCrossLines = false; // Show Short Cycle Vertical Lines +input bool showMediumCycle = false; // Show Medium Cycle +input bool showMediumCycleCrossLines = false; // Show Medium Cycle Vertical Lines +input bool showLongCycle = false; // Show Long Cycle +input bool showLongCycleCrossLines = false; // Show Long Cycle Vertical Lines +// +// Color Inputs ... +input color shortCycleFastColor = clrGreen; // Short Cycle Fast Color ... +input color shortCycleSlowColor = clrRed; // Short Cycle Slow Color ... +input color mediumCycleFastColor = clrAqua; // Medium Cycle Fast Color ... +input color mediumCycleSlowColor = clrFuchsia; // Medium Cycle Slow Color ... +input color longCycleFastColor = clrGoldenrod; // Medium Cycle Fast Color ... +input color longCycleSlowColor = clrBrown; // Medium Cycle Slow Color ... +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +int totalBars; +int countedBars = 0; +int lastSignalledBar = 0; + +// +int signalTradeRetry = 0; + +// +bool waitForLongSignals = true; +bool closeLongTrades = false; + +// +bool waitForShortSignals = true; +bool closeShortTrades = false; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.osc.signal.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Validate Inputs ... + bool inputsNotValiid = + // + // MARKET ... + marketLength < 0 + || riskToRewardRatio < 0 + // + // EA ... + || lotsPerTradePercent < 0 + || maxOpenTrades <= 0 + || maxDrawdownPercentPerPTrade < 0 + || minBalancePercent < 0 + || maxEquityPercent < 0 + || marketLength < 0 + // + // OSC ... + || fastOSCLength < 0 + || fastOSCMultiplier < 0 + || slowOSCLength < 0 + || slowOSCMultiplier < 0 + || minPowerOSC < 0 + || minVarianceOSC < 0 + || slowOSCLength <= fastOSCLength + // + // ZIGZAG ... + || zDeviation < 0 + || zBackStep < 0 + || zBackStep >= marketLength + // + // XMA ... + // + // Validate Short Cycle ... + || shortCycleFastMultiplier <= 0 + || shortCycleSlowMultiplier <= 0 + || shortCycleFastMultiplier >= shortCycleSlowMultiplier + // + // Validate Medium Cycle ... + || mediumCycleFastMultiplier <= 0 + || mediumCycleSlowMultiplier <= 0 + || mediumCycleFastMultiplier >= mediumCycleSlowMultiplier + // + // Validate Long Cycle ... + || longCycleFastMultiplier <= 0 + || longCycleSlowMultiplier <= 0 + || longCycleFastMultiplier >= longCycleSlowMultiplier + // + // Validate Series of Multipliers ... + || shortCycleFastMultiplier >= mediumCycleFastMultiplier + || mediumCycleFastMultiplier >= longCycleFastMultiplier + ; + + if (inputsNotValiid) { + return INIT_PARAMETERS_INCORRECT; + } + + // + totalSignals = 0; + totalLongSignals = 0; + totalShortSignals = 0; + + // + initialBalance = 0; + + // + ArraySetAsSeries( + scTrendPower, + true + ); + + // + ArraySetAsSeries( + shortMarketCrossPointsTime, + true + ); + + // + ArraySetAsSeries( + mcTrendPower, + true + ); + + // + ArraySetAsSeries( + mediumMarketCrossPointsTime, + true + ); + + // + ArraySetAsSeries( + lcTrendPower, + true + ); + + // + ArraySetAsSeries( + longMarketCrossPointsTime, + true + ); + + // + // here we specify logging enabled or not ... + enableLogging = false; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST_OSC"; + + // // + // // Set Event Timer on One Seccond ... + // bool isEventSet = EventSetTimer(1); + // if (!isEventSet) { + // LogMessage("Error: " + GetLastError()); + // return INIT_FAILED; + // } + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + // Killing Event Timer ... + EventKillTimer(); +} + +// +// Ticker Event Handler ... +void OnTick() { + // + // Checking State for Signal Handling ... + CheckState(); + + // + // Process Signals to Open Positions ... + ProcessSignals(); + + // + // Process Open Positions for Trailing Stop Loss or Close ... + ProcessOpenPositions(); +} + +// +// Timer Event Handler ... +void OnTimer() { + // + CheckState(); + ProcessOpenPositions(); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Check State for Signal Handling ... +void CheckState() { + // + // Here we Must to Check Market State in Big Picture ... + + // + // Retrieve XMA State ... + // XMAState xmaState = GetXMAState( + // // + // // Bar Index ... + // 0, + // // + // // Market Specification Inpouts ... + // marketLength, // Market Length ... + // // + // // XMA Inputs ... + // shortCycleFastMultiplier, // Short Cycle Fast Multiplier ... + // shortCycleSlowMultiplier, // Short Cycle Slow Multiplier ... + // mediumCycleFastMultiplier, // Medium Cycle Fast Multiplier ... + // mediumCycleSlowMultiplier, // Medium Cycle Slow Multiplier ... + // longCycleFastMultiplier, // Long Cycle Fast Multiplier ... + // longCycleSlowMultiplier, // Long Cycle Slow Multiplier ... + // // + // // Show/Hide Inputs ... + // showShortCycle, + // showShortCycleCrossLines, + // showMediumCycle, + // showMediumCycleCrossLines, + // showLongCycle, + // showLongCycleCrossLines, + // // + // // Color Inputs ... + // shortCycleFastColor, + // shortCycleSlowColor, + // mediumCycleFastColor, + // mediumCycleSlowColor, + // longCycleFastColor, + // longCycleSlowColor + // ); + + // // + // bool isMCFastCrossUnderSCSlow = + // xmaState.mcFast < xmaState.scSlow + // && !(xmaState.mcFastPrev < xmaState.scSlowPrev); + + // // + // if ( + // waitForLongSignals + // && xmaState.isSCTrendDown + // && isMCFastCrossUnderSCSlow + // ) { + // // + // closeLongTrades = true; + // waitForLongSignals = false; + + // // // + // // string message = "Pause Long Trades ..."; + + // // // + // // LogMessage(message); + + // // + // return; + // } + + // // + // if ( + // !waitForLongSignals + // && xmaState.isSCFastCrossOverSlow + // ) { + // // + // waitForLongSignals = true; + + // // // + // // string message = "Play Long Trades ..."; + + // // // + // // LogMessage(message); + + // // + // return; + // } +} + +// +// Calculate Signals and Process Based on Exists Signals ... +void ProcessSignals() { + // + // Prevent Multiple Calculating on Same Bars ... + if (IsNewBar()) { + // // + // LogMessage( + // StringConcatenate( + // "Current Time: ", + // TimeCurrent() + // ) + // ); + + // + countedBars++; + } + + // + // Retrieve Signal Exists ... + XSignalRequest request = CalculateSignal( + // + // Bar Index ... + 0, + // + // Market Specification Inpouts ... + marketLength, // Market Length ... + // + // Risk To Reward Ratio ... + riskToRewardRatio, + // + // XMA Inputs ... + shortCycleFastMultiplier, // Short Cycle Fast Multiplier ... + shortCycleSlowMultiplier, // Short Cycle Slow Multiplier ... + mediumCycleFastMultiplier, // Medium Cycle Fast Multiplier ... + mediumCycleSlowMultiplier, // Medium Cycle Slow Multiplier ... + longCycleFastMultiplier, // Long Cycle Fast Multiplier ... + longCycleSlowMultiplier, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + // + // OSC ... + fastOSCLength, // FastOSC Length ... + fastOSCMultiplier, // FastOSC Multiplier ... + slowOSCLength, // SlowOSC Length ... + slowOSCMultiplier, // SlowOSC Multiplier ... + minPowerOSC, // Minimum Signal Power ... + minVarianceOSC, // Minimum Var Power ... + // + // ZIGZAG Inputs ... + zDeviation, // ZigZag Deviation ... + zBackStep // ZigZag Back Step ... + ); + + // + // Prevent doing anything else, if there is no signals ... + if ( + !request.hasSignal || + request.type == X_NONE + ) { + return; + } + + // + bool hasLongSignal = request.type == X_LONG; + + // + // Check For Bot State ... + if ( + (hasLongSignal && !waitForLongSignals) + || (!hasLongSignal && !waitForShortSignals) + ) { + return; + } + + // + // Check last Signalled Bar with Counted Bars ... + // Prevent Multiple Signalling on Same Bar ... + if (lastSignalledBar == countedBars) { + // + totalSignals--; + if (hasLongSignal) { + totalLongSignals--; + } else { + totalShortSignals--; + } + return; + } + + // + // increase last signalled bar ... + lastSignalledBar = countedBars; + + // + // Calculate Can Trade or not ... + bool allowDoTrade = allowTrade + && ( + hasLongSignal ? + allowLongTrades : + allowShortTrades + ); + + // + // Check Balance ... + if (initialBalance > 0) { + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double minimumBalanceForTrade = minBalancePercent * initialBalance; + + // + // Retrieve Account Equity ... + double equity = AccountInfoDouble(ACCOUNT_EQUITY); + double maxAllowedEquity = balance - (balance * maxEquityPercent); + + // + // Retrieve Free Marigin ... + double freeMargin = AccountFreeMargin(); + double maximumMariginRisk = balance - (balance * maxEquityPercent); + + // + if ( + // + // Do not Open Positions if equity not passed ... + equity < maxAllowedEquity || + // + // Do not Open Positions if free margin not passed ... + freeMargin <= maximumMariginRisk || + // + // Do not open positions if balance less than minimum ... + balance <= minimumBalanceForTrade + ) { + // + allowDoTrade = false; + + // // + // string message = StringConcatenate( + // "Trading Pause => ", + // "Balance: ", balance, + // ", Equity: ", equity, + // ", FreeMargin: ", freeMargin + // ); + + // // + // LogMessage(message); + // SendAlert(message); + } + + // + if ( + !allowDoTrade + && signalTradeRetry < 2 + ) { + // + signalTradeRetry++; + CloseAllInProfitTrades(); + ProcessSignals(); + } else { + signalTradeRetry = 0; + } + } + + // + // Chack Maximum Open Positions ... + int openTrades = CountOpenTrades(); + if (maxOpenTrades > 0) { + // + if (openTrades >= maxOpenTrades) { + // + allowDoTrade = false; + + // // + // string message = StringConcatenate( + // "Trading Pause => ", + // "Max Open Trades (", + // maxOpenTrades, + // ") reached ..." + // ); + + // // + // LogMessage(message); + // SendAlert(message); + } + } + + // + // Retrieve Signal Verification ... + bool isVerified = true; + if (!isVerified) { + // + allowDoTrade = false; + + // // + // string message = StringConcatenate( + // "Trading Pause => ", + // "Signal Verification failed ..." + // ); + + // // + // LogMessage(message); + // SendAlert(message); + } + + // + // Check Trading is Enable or not ... + // nothing to do if trading is disabled ... + if (!allowDoTrade) { + // // + // string message = StringConcatenate( + // "Trading Not Allowed ..." + // ); + + // // + // LogMessage(message); + // SendAlert(message); + return; + } + + // + bool isPositionOpened = TradeSignal( + request.signal, + signalPrefix, + lotsPerTradePercent, + bullishSignalLabel, + bullishSignalColor, + bearishSignalLabel, + bearishSignalColor + ); + + // + if (isPositionOpened) { + // + bool canAlert = + alertPositions + && ( + hasLongSignal ? + longPositionAlerts + : + shortPositionAlerts + ); + + // + if (canAlert) { + // + // Alert Message ... + string message = StringConcatenate( + "Trade on Signal ID: ", request.signal.id, + ", Entry: ", request.signal.entryPrice, + ", TP: ", request.signal.tp + ); + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } + } + } +} + +// +// Process All Open Positions ... +void ProcessOpenPositions() { + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double minimumBalanceForTrade = minBalancePercent * initialBalance; + + // + // Retrieve Account Equity ... + double equity = AccountInfoDouble(ACCOUNT_EQUITY); + double maxAllowedEquity = balance - (balance * maxEquityPercent); + + // + // Retrieve Free Marigin ... + double freeMargin = AccountFreeMargin(); + double maximumMariginRisk = balance - (balance * maxEquityPercent); + + // + if (closeLongTrades) { + // + closeLongTrades = false; + + // // + // CloseAllLongTrades(); + // LogMessage("Close All Long Trades ..."); + } + + // + if (closeShortTrades) { + // + closeShortTrades = false; + // CloseAllShortTrades(); + // LogMessage("Close All Short Trades ..."); + } +} + +// +// Send Special Type of Alerts ... +void SendAlert(string message) { + // + if (!alertEvents) { + return; + } + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/UnUsed/Experts/x-saherelm.xma.ea.mq4 b/Bkp/UnUsed/Experts/x-saherelm.xma.ea.mq4 new file mode 100644 index 0000000..bc16075 --- /dev/null +++ b/Bkp/UnUsed/Experts/x-saherelm.xma.ea.mq4 @@ -0,0 +1,700 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XST_XMA Strategy Expert Advisor +// --------------------------------------------- +// saherelm implementation of strategy expert advisor ... +// +// ShortName: XST_XMA +// +// 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 XST_XMA Strategy Expert Advisor" +#property strict + +// +// START Inputs ... +// +// +// Signal Prefixe ... +input string signalPrefix = "XST_XMA"; // Signal Prefix + +// +// Signal Draw Specifications ... +input string bullishSignalLabel = "X_BUY"; // Bullish Signal Label +input color bullishSignalColor = clrAqua; // Bullish Signal Color + +// +input string bearishSignalLabel = "X_SELL"; // Bearish Signal Label +input color bearishSignalColor = clrFuchsia; // Bearish Signal Color + +// +input color signalEntryColor = clrAquamarine; // Signal Entry Ptice Color +input color signalSLColor = clrRed; // Signal SL Color +input color signalTPColor = clrGreen; // Signal TP Color + +// +// Trade ... +input bool allowTrade = true; // Allow Trade Based on given Signals +input bool allowLongTrades = true; // Allow Long Trades +input bool allowShortTrades = true; // Allow Short Trades + +// +// Alerts ... +input bool alertEvents = true; // Alert Events +input bool alertPositions = true; // Alert Positions +input bool longPositionAlerts = true; // Alert Long Positions +input bool shortPositionAlerts = true; // Alert Short Positions + +// +// Alert Types ... +input bool terminalAlert = false; // Terminal Alert +input bool pushAlert = false; // Push Notification Alerts + +// +// Balance and Finanical Specifications ... +input double lotsPerTradePercent = 0.0001; // Lots Per Trade Percent +input int maxOpenTrades = 3; // Maximum Open Trade +input double maxDrawdownPercentPerPTrade = 0; // Maximum DrawDown Per Trade +input double minBalancePercent = 0.5; // Minimum Balance for Trading +input double maxEquityPercent = 0.1; // Maximum Trade Equity + +// +// XMA Inputs ... +// +// Market Specification Inpouts ... +input int marketLength = 7; // Market Length +input double riskToRewardRatio = 2; // Risk to Reward Ratio +// +input int shortCycleFastMultiplier = 1; // Short Cycle Fast Multiplier +input int shortCycleSlowMultiplier = 4; // Short Cycle Slow Multiplier +input int mediumCycleFastMultiplier = 7; // Medium Cycle Fast Multiplier +input int mediumCycleSlowMultiplier = 14; // Medium Cycle Slow Multiplier +input int longCycleFastMultiplier = 70; // Long Cycle Fast Multiplier +input int longCycleSlowMultiplier = 140; // Long Cycle Slow Multiplier +// +// Show/Hide Inputs ... +input bool showShortCycle = false; // Show Short Cycle +input bool showShortCycleCrossLines = false; // Show Short Cycle Vertical Lines +input bool showMediumCycle = false; // Show Medium Cycle +input bool showMediumCycleCrossLines = false; // Show Medium Cycle Vertical Lines +input bool showLongCycle = false; // Show Long Cycle +input bool showLongCycleCrossLines = false; // Show Long Cycle Vertical Lines +// +// Color Inputs ... +input color shortCycleFastColor = clrGreen; // Short Cycle Fast Color ... +input color shortCycleSlowColor = clrRed; // Short Cycle Slow Color ... +input color mediumCycleFastColor = clrAqua; // Medium Cycle Fast Color ... +input color mediumCycleSlowColor = clrFuchsia; // Medium Cycle Slow Color ... +input color longCycleFastColor = clrGoldenrod; // Medium Cycle Fast Color ... +input color longCycleSlowColor = clrBrown; // Medium Cycle Slow Color ... +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +int totalBars; +int countedBars = 0; +int lastSignalledBar = 0; + +// +bool waitForLongSignals = true; +bool closeLongTrades = false; + +// +bool waitForShortSignals = true; +bool closeShortTrades = false; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.xma.signal.lib.mq4" + +// +// here we specify logging enabled or not ... +bool enableLogging = true; + +// +// this is a Tag which attached to our Logger ... +string logTag = "XST_XMA"; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Validate Inputs ... + bool inputsNotValiid = + // + // EA ... + lotsPerTradePercent < 0 + || maxOpenTrades <= 0 + || maxDrawdownPercentPerPTrade < 0 + || minBalancePercent < 0 + || maxEquityPercent < 0 + || marketLength < 0 + // + // XMA ... + // + // Validate Short Cycle ... + || shortCycleFastMultiplier <= 0 + || shortCycleSlowMultiplier <= 0 + || shortCycleFastMultiplier >= shortCycleSlowMultiplier + // + // Validate Medium Cycle ... + || mediumCycleFastMultiplier <= 0 + || mediumCycleSlowMultiplier <= 0 + || mediumCycleFastMultiplier >= mediumCycleSlowMultiplier + // + // Validate Long Cycle ... + || longCycleFastMultiplier <= 0 + || longCycleSlowMultiplier <= 0 + || longCycleFastMultiplier >= longCycleSlowMultiplier + // + // Validate Series of Multipliers ... + || shortCycleFastMultiplier >= mediumCycleFastMultiplier + || mediumCycleFastMultiplier >= longCycleFastMultiplier + ; + + // + if (inputsNotValiid) { + return INIT_PARAMETERS_INCORRECT; + } + + // + totalSignals = 0; + totalLongSignals = 0; + totalShortSignals = 0; + + // + initialBalance = 0; + + // + ArraySetAsSeries( + scTrendPower, + true + ); + + // + ArraySetAsSeries( + shortMarketCrossPointsTime, + true + ); + + // + ArraySetAsSeries( + mcTrendPower, + true + ); + + // + ArraySetAsSeries( + mediumMarketCrossPointsTime, + true + ); + + // + ArraySetAsSeries( + lcTrendPower, + true + ); + + // + ArraySetAsSeries( + longMarketCrossPointsTime, + true + ); + + // // + // // Set Event Timer on One Seccond ... + // bool isEventSet = EventSetTimer(1); + // if (!isEventSet) { + // LogMessage("Error: " + GetLastError()); + // return INIT_FAILED; + // } + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + // Killing Event Timer ... + EventKillTimer(); +} + +// +// Ticker Event Handler ... +void OnTick() { + // + // Checking State for Signal Handling ... + CheckState(); + + // + // Process Signals to Open Positions ... + ProcessSignals(); + + // + // Process Open Positions for Trailing Stop Loss or Close ... + // ProcessOpenPositions(); +} + +// +// Timer Event Handler ... +void OnTimer() { + // + CheckState(); + ProcessOpenPositions(); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Check State for Signal Handling ... +void CheckState() { + // + // Here we Must to Check Market State in Big Picture ... + + // + // Check if Medium Cycle Fast cross Short Cycle Slow + // Turn off Longs ... + + // // + // if ( + // waitForLongSignals + // && ( + // xmaState.isMCFastCrossUnderSlow || + // xmaState.isLCFastCrossUnderSlow + // ) + // ) { + // // + // closeLongTrades = true; + // waitForLongSignals = false; + + // // + // string msg = "Pause Long Handler ..."; + // LogMessage(msg); + // SendAlert(msg); + // return; + // } + + // // + // if ( + // !waitForLongSignals + // && ( + // xmaState.isMCFastCrossOverSlow || + // xmaState.isLCFastCrossOverSlow + // ) + // ) { + // // + // closeShortTrades = true; + // waitForLongSignals = true; + + // // + // string msg = "Play Long Handler ..."; + // LogMessage(msg); + // SendAlert(msg); + // return; + // } + + // // + // bool isXMASlowCrossOverXMMALongFast = + // xmaState.xmaSlow > xmmaState.longFast + // && !( + // xmaState.xmaSlowPrev > xmmaState.longFastPrev + // ); + + // // + // bool isXMASlowCrossOverXMMALongSlow = + // xmaState.xmaSlow > xmmaState.longSlow + // && !( + // xmaState.xmaSlowPrev > xmmaState.longSlowPrev + // ); + + // // + // bool isXMASlowCrossUnderXMMALongFast = + // xmaState.xmaSlow < xmmaState.longFast + // && !( + // xmaState.xmaSlowPrev < xmmaState.longFastPrev + // ); + + // // + // bool isXMASlowCrossUnderXMMALongSlow = + // xmaState.xmaSlow < xmmaState.longSlow + // && !( + // xmaState.xmaSlowPrev < xmmaState.longSlowPrev + // ); + + // // + // // Find Sharp Dump and Sharp Pump ... + // bool isMarketSharpDump = false; + + // // + // bool isMarketSharpPump = false; + + // // // + // // if ( + // // waitForLongSignals + // // && ( + // // isMarketSharpDump || + // // isXMASlowCrossOverXMMALongFast + // // ) + // // ) { + // // // + // // closeLongTrades = true; + // // waitForLongSignals = false; + + // // // + // // string msg = "Pause Long Handler ..."; + // // LogMessage(msg); + // // SendAlert(msg); + // // return; + // // } + + // // // + // // if ( + // // !waitForLongSignals + // // && ( + // // isMarketSharpPump || + // // isXMASlowCrossOverXMMALongSlow + // // ) + // // ) { + // // // + // // closeShortTrades = true; + // // waitForLongSignals = true; + + // // // + // // string msg = "Play Long Handler ..."; + // // LogMessage(msg); + // // SendAlert(msg); + // // return; + // // } +} + +// +// Calculate Signals and Process Based on Exists Signals ... +void ProcessSignals() { + // + // Prevent Multiple Calculating on Same Bars ... + if (IsNewBar()) { + countedBars++; + } + + // + // Retrieve Signal Exists ... + XSignalRequest request = CalculateSignal( + // + // Bar Index ... + 0, + // + // Market Specification Inpouts ... + marketLength, // Market Length ... + // + // Risk To Reward Ratio ... + riskToRewardRatio, + // + // XMA Inputs ... + shortCycleFastMultiplier, // Short Cycle Fast Multiplier ... + shortCycleSlowMultiplier, // Short Cycle Slow Multiplier ... + mediumCycleFastMultiplier, // Medium Cycle Fast Multiplier ... + mediumCycleSlowMultiplier, // Medium Cycle Slow Multiplier ... + longCycleFastMultiplier, // Long Cycle Fast Multiplier ... + longCycleSlowMultiplier, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showShortCycle, + showShortCycleCrossLines, + showMediumCycle, + showMediumCycleCrossLines, + showLongCycle, + showLongCycleCrossLines, + // + // Color Inputs ... + shortCycleFastColor, + shortCycleSlowColor, + mediumCycleFastColor, + mediumCycleSlowColor, + longCycleFastColor, + longCycleSlowColor + ); + + // + // Prevent doing anything else, if there is no signals ... + if ( + !request.hasSignal || + request.type == X_NONE + ) { + return; + } + + // + bool hasLongSignal = request.type == X_LONG; + + // + // Check For Bot State ... + if ( + (hasLongSignal && !waitForLongSignals) + || (!hasLongSignal && !waitForShortSignals) + ) { + return; + } + + // + // Check last Signalled Bar with Counted Bars ... + // Prevent Multiple Signalling on Same Bar ... + if (lastSignalledBar == countedBars) { + // + totalSignals--; + if (hasLongSignal) { + totalLongSignals--; + } else { + totalShortSignals--; + } + return; + } + + // + // increase last signalled bar ... + lastSignalledBar = countedBars; + + // + // Calculate Can Trade or not ... + bool allowDoTrade = allowTrade + && ( + hasLongSignal ? + allowLongTrades : + allowShortTrades + ); + + // + // Check Balance ... + if (initialBalance > 0) { + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double minimumBalanceForTrade = minBalancePercent * initialBalance; + + // + // Retrieve Account Equity ... + double equity = AccountInfoDouble(ACCOUNT_EQUITY); + double maxAllowedEquity = balance - (balance * maxEquityPercent); + + // + // Retrieve Free Marigin ... + double freeMargin = AccountFreeMargin(); + double maximumMariginRisk = balance - (balance * maxEquityPercent); + + // + if ( + // + // Do not Open Positions if equity not passed ... + equity < maxAllowedEquity || + // + // Do not Open Positions if free margin not passed ... + freeMargin <= maximumMariginRisk || + // + // Do not open positions if balance less than minimum ... + balance <= minimumBalanceForTrade + ) { + // + allowDoTrade = false; + + // + string message = StringConcatenate( + "Trading Pause => ", + "Balance: ", balance, + ", Equity: ", equity, + ", FreeMargin: ", freeMargin + ); + + // + LogMessage(message); + SendAlert(message); + } + } + + // + // Chack Maximum Open Positions ... + int openTrades = CountOpenTrades(); + if (maxOpenTrades > 0) { + // + if (openTrades >= maxOpenTrades) { + // + allowDoTrade = false; + + // + string message = StringConcatenate( + "Trading Pause => ", + "Max Open Trades (", + maxOpenTrades, + ") reached ..." + ); + + // + LogMessage(message); + SendAlert(message); + } + } + + // + // Retrieve Signal Verification ... + bool isVerified = true; + if (!isVerified) { + // + allowDoTrade = false; + + // + string message = StringConcatenate( + "Trading Pause => ", + "Signal Verification failed ..." + ); + + // + LogMessage(message); + SendAlert(message); + } + + // + // Check Trading is Enable or not ... + // nothing to do if trading is disabled ... + if (!allowDoTrade) { + // + string message = StringConcatenate( + "Trading Not Allowed ..." + ); + + // + LogMessage(message); + SendAlert(message); + return; + } + + // + bool isPositionOpened = TradeSignal( + request.signal, + signalPrefix, + lotsPerTradePercent, + bullishSignalLabel, + bullishSignalColor, + bearishSignalLabel, + bearishSignalColor + ); + + // + if (isPositionOpened) { + // + bool canAlert = + alertPositions + && ( + hasLongSignal ? + longPositionAlerts + : + shortPositionAlerts + ); + + // + if (canAlert) { + // + // Alert Message ... + string message = StringConcatenate( + "Trade on Signal ID: ", request.signal.id, + ", Entry: ", request.signal.entryPrice, + ", TP: ", request.signal.tp + ); + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } + } + } +} + +// +// Process All Open Positions ... +void ProcessOpenPositions() { + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double minimumBalanceForTrade = minBalancePercent * initialBalance; + + // + // Retrieve Account Equity ... + double equity = AccountInfoDouble(ACCOUNT_EQUITY); + double maxAllowedEquity = balance - (balance * maxEquityPercent); + + // + // Retrieve Free Marigin ... + double freeMargin = AccountFreeMargin(); + double maximumMariginRisk = balance - (balance * maxEquityPercent); + + // + if (closeLongTrades) { + // + closeLongTrades = false; + + // + CloseAllLongTrades(); + LogMessage("Close All Long Trades ..."); + } + + // + if (closeShortTrades) { + // + closeShortTrades = false; + CloseAllShortTrades(); + LogMessage("Close All Short Trades ..."); + } +} + +// +// Send Special Type of Alerts ... +void SendAlert(string message) { + // + if (!alertEvents) { + return; + } + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } +} +// \ No newline at end of file diff --git a/Bkp/UnUsed/Indicators/ParabolicSar.mq4 b/Bkp/UnUsed/Indicators/ParabolicSar.mq4 new file mode 100644 index 0000000..261808a --- /dev/null +++ b/Bkp/UnUsed/Indicators/ParabolicSar.mq4 @@ -0,0 +1,333 @@ +//------------------------------------------------------------------ +#property copyright "www.forex-station.com" +#property link "www.forex-station.com" +//------------------------------------------------------------------ +#property indicator_chart_window +#property indicator_buffers 4 +#property indicator_color1 clrLimeGreen +#property indicator_color2 clrOrange +#property indicator_color3 clrLimeGreen +#property indicator_color4 clrOrange +#property indicator_width3 3 +#property indicator_width4 3 +#property strict + +// +// +// +// +// + +extern ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; // Time frame to use +extern double AccStep = 0.02; // Accumulation step +extern double AccLimit = 0.2; // Accumulation limit +extern ENUM_APPLIED_PRICE PriceHigh = PRICE_CLOSE; // Psar high price +extern ENUM_APPLIED_PRICE PriceLow = PRICE_CLOSE; // Psar low price +extern int PriceSmoothing = 0; // Psar smoothing +extern ENUM_MA_METHOD PriceSmoothingMethod = MODE_SMA; // Psar ma smoothing method +extern bool alertsOn = true; // Alerts on? +extern bool alertsOnCurrent = false; // Alerts on current open bar? +extern bool alertsMessage = true; // Alerts message? +extern bool alertsSound = false; // Alerts sound? +extern bool alertsEmail = false; // Alerts email? +extern bool alertsNotify = false; // Alerts notification by phone? +extern bool DrawAsDots = true; // Draw as dots or solid line +extern int Shift = 0; // Shift + +double sarUp[]; +double sarDn[]; +double saraUp[]; +double saraDn[]; +int timeFrame; +string indicatorFileName; +bool returnBars; + +//------------------------------------------------------------------ +// +//------------------------------------------------------------------ +// +// +// +// +// + +int init() +{ + int type = DRAW_LINE; if (DrawAsDots) type = DRAW_ARROW; + SetIndexBuffer(0,sarUp); SetIndexStyle(0,type); SetIndexArrow(0,159); + SetIndexBuffer(1,sarDn); SetIndexStyle(1,type); SetIndexArrow(1,159); + SetIndexBuffer(2,saraUp); SetIndexStyle(2,DRAW_ARROW); SetIndexArrow(2,159); + SetIndexBuffer(3,saraDn); SetIndexStyle(3,DRAW_ARROW); SetIndexArrow(3,159); + + // + // + // + // + // + + indicatorFileName = WindowExpertName(); + returnBars = (TimeFrame==-99); + TimeFrame = MathMax(TimeFrame,_Period); + PriceSmoothing = MathMax(PriceSmoothing,1); + for (int i=0; i<4; i++) SetIndexShift(i,Shift*timeFrame/Period()); + + // + // + // + // + // + + return(0); +} +int deinit() { return(0); } + +//------------------------------------------------------------------ +// +//------------------------------------------------------------------ +// +// +// +// +// + +int start() +{ + int i,counted_bars=IndicatorCounted(); + if(counted_bars < 0) return(-1); + if(counted_bars>0) counted_bars--; + int limit = MathMin(Bars-counted_bars,Bars-1); + if (returnBars) { sarUp[0] = limit+1; return(0); } + + // + // + // + // + // + + if (TimeFrame == Period()) + { + for(i = limit; i >= 0; i--) + { + double sarClose; + double sarOpen; + double sarPosition; + double sarChange; + double pHigh = iMA(NULL,0,PriceSmoothing,0,PriceSmoothingMethod,PriceHigh,i); + double pLow = iMA(NULL,0,PriceSmoothing,0,PriceSmoothingMethod,PriceLow ,i); + iParabolic(fmax(pHigh,pLow),fmin(pHigh,pLow),AccStep,AccLimit,sarClose,sarOpen,sarPosition,sarChange,i); + sarUp[i] = EMPTY_VALUE; + sarDn[i] = EMPTY_VALUE; + saraUp[i] = EMPTY_VALUE; + saraDn[i] = EMPTY_VALUE; + if (sarPosition==1) + sarUp[i] = sarClose; + else sarDn[i] = sarClose; + if (sarChange!=0) + if (sarChange==1) + saraUp[i] = sarClose; + else saraDn[i] = sarClose; + } + manageAlerts(); + return(0); + } + + // + // + // + // + // + + limit = (int)fmax(limit,fmin(Bars-1,iCustom(NULL,TimeFrame,indicatorFileName,-99,0,0)*TimeFrame/Period())); + for(i=limit; i>=0; i--) + { + int y = iBarShift(NULL,TimeFrame,Time[i]); + int x = iBarShift(NULL,TimeFrame,Time[i+1]); + sarUp[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,AccStep,AccLimit,PriceHigh,PriceLow,PriceSmoothing,PriceSmoothingMethod,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,0,0,y); + sarDn[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,AccStep,AccLimit,PriceHigh,PriceLow,PriceSmoothing,PriceSmoothingMethod,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,0,1,y); + saraUp[i] = EMPTY_VALUE; + saraDn[i] = EMPTY_VALUE; + if (x!=y) + { + saraUp[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,AccStep,AccLimit,PriceHigh,PriceLow,PriceSmoothing,PriceSmoothingMethod,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,0,2,y); + saraDn[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,AccStep,AccLimit,PriceHigh,PriceLow,PriceSmoothing,PriceSmoothingMethod,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,0,3,y); + } + } + return(0); + +} + +//------------------------------------------------------------------ +// +//------------------------------------------------------------------ +// +// +// +// +// + +double work[][7]; +#define _high 0 +#define _low 1 +#define _ohigh 2 +#define _olow 3 +#define _open 4 +#define _position 5 +#define _af 6 + + +void iParabolic(double high, double low, double step, double limit, double& pClose, double& pOpen, double& pPosition, double& pChange, int i) +{ + if (ArrayRange(work,0)!=Bars) ArrayResize(work,Bars); i = Bars-i-1; + + // + // + // + // + // + + pChange = 0; + work[i][_ohigh] = high; + work[i][_olow] = low; + if (i<1) + { + work[i][_high] = high; + work[i][_low] = low; + work[i][_open] = high; + work[i][_position] = -1; + return; + } + work[i][_open] = work[i-1][_open]; + work[i][_af] = work[i-1][_af]; + work[i][_position] = work[i-1][_position]; + work[i][_high] = fmax(work[i-1][_high],high); + work[i][_low] = fmin(work[i-1][_low] ,low ); + + // + // + // + // + // + + if (work[i][_position] == 1) + if (low<=work[i][_open]) + { + work[i][_position] = -1; + pChange = -1; + pClose = work[i][_high]; + work[i][_high] = high; + work[i][_low] = low; + work[i][_af] = step; + work[i][_open] = pClose + work[i][_af]*(work[i][_low]-pClose); + if (work[i][_open]work[i-1][_high] && work[i][_af]work[i ][_olow]) work[i][_open] = work[i ][_olow]; + if (work[i][_open]>work[i-1][_olow]) work[i][_open] = work[i-1][_olow]; + } + else + if (high>=work[i][_open]) + { + work[i][_position] = 1; + pChange = 1; + pClose = work[i][_low]; + work[i][_low] = low; + work[i][_high] = high; + work[i][_af] = step; + work[i][_open] = pClose + work[i][_af]*(work[i][_high]-pClose); + if (work[i][_open]>work[i ][_olow]) work[i][_open] = work[i ][_olow]; + if (work[i][_open]>work[i-1][_olow]) work[i][_open] = work[i-1][_olow]; + } + else + { + pClose = work[i][_open]; + if (work[i][_low]=0; i--) + if (tf==iTfTable[i]) return(sTfTable[i]); + return(""); +} \ No newline at end of file diff --git a/Bkp/UnUsed/Indicators/SimplePanel/PanelDialog.mqh b/Bkp/UnUsed/Indicators/SimplePanel/PanelDialog.mqh new file mode 100644 index 0000000..2004efe --- /dev/null +++ b/Bkp/UnUsed/Indicators/SimplePanel/PanelDialog.mqh @@ -0,0 +1,359 @@ +//+------------------------------------------------------------------+ +//| PanelDialog.mqh | +//| Copyright 2009-2015, MetaQuotes Software Corp. | +//| http://www.mql5.com | +//+------------------------------------------------------------------+ +#include +#include +#include +#include +#include +#include +#include +#include +//+------------------------------------------------------------------+ +//| defines | +//+------------------------------------------------------------------+ +//--- indents and gaps +#define INDENT_LEFT (11) // indent from left (with allowance for border width) +#define INDENT_TOP (11) // indent from top (with allowance for border width) +#define INDENT_RIGHT (11) // indent from right (with allowance for border width) +#define INDENT_BOTTOM (11) // indent from bottom (with allowance for border width) +#define CONTROLS_GAP_X (10) // gap by X coordinate +#define CONTROLS_GAP_Y (10) // gap by Y coordinate +//--- for buttons +#define BUTTON_WIDTH (100) // size by X coordinate +#define BUTTON_HEIGHT (20) // size by Y coordinate +//--- for the indication area +#define EDIT_HEIGHT (20) // size by Y coordinate +//+------------------------------------------------------------------+ +//| Class CPanelDialog | +//| Usage: main dialog of the SimplePanel application | +//+------------------------------------------------------------------+ +class CPanelDialog : public CAppDialog + { +private: + CEdit m_edit; // the display field object + CButton m_button1; // the button object + CButton m_button2; // the button object + CButton m_button3; // the fixed button object + CListView m_list_view; // the list object + CRadioGroup m_radio_group; // the radio buttons group object + CCheckGroup m_check_group; // the check box group object + +public: + CPanelDialog(void); + ~CPanelDialog(void); + //--- create + virtual bool Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2); + //--- chart event handler + virtual bool OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam); + +protected: + //--- create dependent controls + bool CreateEdit(void); + bool CreateButton1(void); + bool CreateButton2(void); + bool CreateButton3(void); + bool CreateRadioGroup(void); + bool CreateCheckGroup(void); + bool CreateListView(void); + //--- internal event handlers + virtual bool OnResize(void); + //--- handlers of the dependent controls events + void OnClickButton1(void); + void OnClickButton2(void); + void OnClickButton3(void); + void OnChangeRadioGroup(void); + void OnChangeCheckGroup(void); + void OnChangeListView(void); + bool OnDefault(const int id,const long &lparam,const double &dparam,const string &sparam); + }; +//+------------------------------------------------------------------+ +//| Event Handling | +//+------------------------------------------------------------------+ +EVENT_MAP_BEGIN(CPanelDialog) +ON_EVENT(ON_CLICK,m_button1,OnClickButton1) +ON_EVENT(ON_CLICK,m_button2,OnClickButton2) +ON_EVENT(ON_CLICK,m_button3,OnClickButton3) +ON_EVENT(ON_CHANGE,m_radio_group,OnChangeRadioGroup) +ON_EVENT(ON_CHANGE,m_check_group,OnChangeCheckGroup) +ON_EVENT(ON_CHANGE,m_list_view,OnChangeListView) +ON_OTHER_EVENTS(OnDefault) +EVENT_MAP_END(CAppDialog) +//+------------------------------------------------------------------+ +//| Constructor | +//+------------------------------------------------------------------+ +CPanelDialog::CPanelDialog(void) + { + } +//+------------------------------------------------------------------+ +//| Destructor | +//+------------------------------------------------------------------+ +CPanelDialog::~CPanelDialog(void) + { + } +//+------------------------------------------------------------------+ +//| Create | +//+------------------------------------------------------------------+ +bool CPanelDialog::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2) + { + if(!CAppDialog::Create(chart,name,subwin,x1,y1,x2,y2)) + return(false); +//--- create dependent controls + if(!CreateEdit()) + return(false); + if(!CreateButton1()) + return(false); + if(!CreateButton2()) + return(false); + if(!CreateButton3()) + return(false); + if(!CreateRadioGroup()) + return(false); + if(!CreateCheckGroup()) + return(false); + if(!CreateListView()) + return(false); +//--- succeed + return(true); + } +//+------------------------------------------------------------------+ +//| Create the display field | +//+------------------------------------------------------------------+ +bool CPanelDialog::CreateEdit(void) + { +//--- coordinates + int x1=INDENT_LEFT; + int y1=INDENT_TOP; + int x2=ClientAreaWidth()-(INDENT_RIGHT+BUTTON_WIDTH+CONTROLS_GAP_X); + int y2=y1+EDIT_HEIGHT; +//--- create + if(!m_edit.Create(m_chart_id,m_name+"Edit",m_subwin,x1,y1,x2,y2)) + return(false); + if(!m_edit.ReadOnly(true)) + return(false); + if(!Add(m_edit)) + return(false); + m_edit.Alignment(WND_ALIGN_WIDTH,INDENT_LEFT,0,INDENT_RIGHT+BUTTON_WIDTH+CONTROLS_GAP_X,0); +//--- succeed + return(true); + } +//+------------------------------------------------------------------+ +//| Create the "Button1" button | +//+------------------------------------------------------------------+ +bool CPanelDialog::CreateButton1(void) + { +//--- coordinates + int x1=ClientAreaWidth()-(INDENT_RIGHT+BUTTON_WIDTH); + int y1=INDENT_TOP; + int x2=x1+BUTTON_WIDTH; + int y2=y1+BUTTON_HEIGHT; +//--- create + if(!m_button1.Create(m_chart_id,m_name+"Button1",m_subwin,x1,y1,x2,y2)) + return(false); + if(!m_button1.Text("Button1")) + return(false); + if(!Add(m_button1)) + return(false); + m_button1.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHT,0); +//--- succeed + return(true); + } +//+------------------------------------------------------------------+ +//| Create the "Button2" button | +//+------------------------------------------------------------------+ +bool CPanelDialog::CreateButton2(void) + { +//--- coordinates + int x1=ClientAreaWidth()-(INDENT_RIGHT+BUTTON_WIDTH); + int y1=INDENT_TOP+BUTTON_HEIGHT+CONTROLS_GAP_Y; + int x2=x1+BUTTON_WIDTH; + int y2=y1+BUTTON_HEIGHT; +//--- create + if(!m_button2.Create(m_chart_id,m_name+"Button2",m_subwin,x1,y1,x2,y2)) + return(false); + if(!m_button2.Text("Button2")) + return(false); + if(!Add(m_button2)) + return(false); + m_button2.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHT,0); +//--- succeed + return(true); + } +//+------------------------------------------------------------------+ +//| Create the "Button3" fixed button | +//+------------------------------------------------------------------+ +bool CPanelDialog::CreateButton3(void) + { +//--- coordinates + int x1=ClientAreaWidth()-(INDENT_RIGHT+BUTTON_WIDTH); + int y1=ClientAreaHeight()-(INDENT_BOTTOM+BUTTON_HEIGHT); + int x2=x1+BUTTON_WIDTH; + int y2=y1+BUTTON_HEIGHT; +//--- create + if(!m_button3.Create(m_chart_id,m_name+"Button3",m_subwin,x1,y1,x2,y2)) + return(false); + if(!m_button3.Text("Locked")) + return(false); + if(!Add(m_button3)) + return(false); + m_button3.Locking(true); + m_button3.Alignment(WND_ALIGN_RIGHT|WND_ALIGN_BOTTOM,0,0,INDENT_RIGHT,INDENT_BOTTOM); +//--- succeed + return(true); + } +//+------------------------------------------------------------------+ +//| Create the "RadioGroup" element | +//+------------------------------------------------------------------+ +bool CPanelDialog::CreateRadioGroup(void) + { + int sx=(ClientAreaWidth()-(INDENT_LEFT+INDENT_RIGHT+BUTTON_WIDTH))/3-CONTROLS_GAP_X; +//--- coordinates + int x1=INDENT_LEFT; + int y1=INDENT_TOP+EDIT_HEIGHT+CONTROLS_GAP_Y; + int x2=x1+sx; + int y2=ClientAreaHeight()-INDENT_BOTTOM; +//--- create + if(!m_radio_group.Create(m_chart_id,m_name+"RadioGroup",m_subwin,x1,y1,x2,y2)) + return(false); + if(!Add(m_radio_group)) + return(false); + m_radio_group.Alignment(WND_ALIGN_HEIGHT,0,y1,0,INDENT_BOTTOM); +//--- fill out with strings + for(int i=0;i<4;i++) + if(!m_radio_group.AddItem("Item "+IntegerToString(i),1<= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + CalculatePanel(i); + } + + // + return rates_total; +} + +// +// De Initialization ... +void OnDeinit(const int reason) { +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +void CalculatePanel( + const int &bar_index +) { +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/UnUsed/Indicators/x-saherelm.psar.mq4 b/Bkp/UnUsed/Indicators/x-saherelm.psar.mq4 new file mode 100644 index 0000000..a263cdb --- /dev/null +++ b/Bkp/UnUsed/Indicators/x-saherelm.psar.mq4 @@ -0,0 +1,215 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center PSAR Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm PSAR Oscillator" +#property strict + +// +// START Inputs ... +// +input int shift = 0; // Shift +input double step = 0.02; // Step +input double maximum = 0.2; // Maximum +input bool drawAsDots = false; // Draw As Dots +// +input int priceSmoothing = 0; // Price Smoothing +input ENUM_APPLIED_PRICE priceLow = PRICE_CLOSE; // Psar low price +input ENUM_APPLIED_PRICE priceHigh = PRICE_OPEN; // Psar high price +input ENUM_MA_METHOD priceSmoothingMethod = MODE_SMA; // Price Smoothing Method +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 3 + +// +#property indicator_color1 clrLimeGreen +#property indicator_width1 1 +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_DOT + +// +#property indicator_color2 clrAqua +#property indicator_width2 1 +#property indicator_type2 DRAW_LINE +#property indicator_style2 STYLE_DOT + +// +#property indicator_color3 clrFuchsia +#property indicator_width3 1 +#property indicator_type3 DRAW_LINE +#property indicator_style3 STYLE_DOT + +// +// +// Declare Buffers ... +// +#define sarBufferIndex 0 +#define upBufferIndex 1 +#define downBufferIndex 2 + +// +double sarBuffer[]; +double upBuffer[]; +double downBuffer[]; + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + SetIndexBuffer(sarBufferIndex, sarBuffer); + SetIndexLabel(sarBufferIndex, "SAR"); + + // + SetIndexBuffer(upBufferIndex, upBuffer); + SetIndexLabel(upBufferIndex, "Up"); + + // + SetIndexBuffer(downBufferIndex, downBuffer); + SetIndexLabel(downBufferIndex, "Down"); + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XS_PSAR"; + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + // int maxLength = MathMax(0, length); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < 0) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Long TP ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index +) { + // + // Calculate isarValue ... + double sarValue = iSAR( + NULL, + _Period, + step, + maximum, + bar_index + ); + + // + double pHigh = iMA( + NULL, + _Period, + priceSmoothing, + 0, + priceSmoothingMethod, + priceHigh, + bar_index + ); + + // + double pLow = iMA( + _Symbol, + _Period, + priceSmoothing, + 0, + priceSmoothingMethod, + priceLow, + bar_index + ); + + // + upBuffer[bar_index] = pHigh; + sarBuffer[bar_index] = sarValue; + downBuffer[bar_index] = pLow; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/UnUsed/Indicators/x-saherelm.shpd.mq4 b/Bkp/UnUsed/Indicators/x-saherelm.shpd.mq4 new file mode 100644 index 0000000..76ee426 --- /dev/null +++ b/Bkp/UnUsed/Indicators/x-saherelm.shpd.mq4 @@ -0,0 +1,533 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center Sharp Market Pump/Dump Indicator +// --------------------------------------------- +// this indicator detects market +// sharp pump and dumps ... +// +// 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 SHPD Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 7; // Market Length +input int loopback = 5; // Loopback for Sharp +input double multiplier = 2.0; // Multiplier +input double minimumMarketGap = 0.03; // Minimum Market Gap +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +// Specify this is an Chart Indicator ... +// #property indicator_chart_window +#property indicator_separate_window + +// +#property indicator_buffers 6 +#property indicator_plots 6 + +// +#property indicator_label1 "Market Highest" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrAqua +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +// +#property indicator_label2 "Market Lowest" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrAqua +#property indicator_style2 STYLE_SOLID +#property indicator_width2 1 + +// +#property indicator_label3 "Market Highest Low" +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrFuchsia +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 + +// +#property indicator_label4 "Market Lowest High" +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrBlueViolet +#property indicator_style4 STYLE_DOT +#property indicator_width4 1 + +// +#property indicator_label5 "Market Moving Average" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrYellow +#property indicator_style5 STYLE_DASHDOT +#property indicator_width5 1 + +// +#property indicator_label6 "Market Moving Average T" +#property indicator_type6 DRAW_LINE +#property indicator_color6 clrLime +#property indicator_style6 STYLE_DASHDOT +#property indicator_width6 1 + +// +// here we declare indicator buffers ... +// +double marketHighestBuffer[]; +double marketLowestBuffer[]; +double marketHighestLowBuffer[]; +double marketLowestHighBuffer[]; + +// +double marketMovingAverageBuffer[]; +double marketMovingAverageTBuffer[]; + +// +#define marketHighestBufferIndex 0 +#define marketLowestBufferIndex 1 +#define marketHighestLowBufferIndex 2 +#define marketLowestHighBufferIndex 3 +#define marketMovingAverageBufferIndex 4 +#define marketMovingAverageTBufferIndex 5 + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// here we specify logging enabled or not ... +bool enableLogging = true; + +// +// this is a Tag which attached to our Logger ... +string logTag = "X_SHPD_IND"; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Validate Inputs ... + if ( + loopback < 0 + || marketLength < 0 + || loopback > marketLength + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Initialize what we want ... + SetIndexBuffer(marketHighestBufferIndex, marketHighestBuffer); + SetIndexBuffer(marketLowestBufferIndex, marketLowestBuffer); + // + SetIndexBuffer(marketHighestLowBufferIndex, marketHighestLowBuffer); + SetIndexBuffer(marketLowestHighBufferIndex, marketLowestHighBuffer); + // + SetIndexBuffer(marketMovingAverageBufferIndex, marketMovingAverageBuffer); + SetIndexBuffer(marketMovingAverageTBufferIndex, marketMovingAverageTBuffer); + + // + return INIT_SUCCEEDED; +} + +// +// De Initialization ... +void OnDeinit(const int reason) { + RemoveDraws(logTag); +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + int limit; + + // + static int lastMarketTrend = 0; + static datetime lastMarketTrendTime = 0; + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < marketLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = rates_total - prev_calculated; + if (prev_calculated > 0) { + limit++; + } + + // + // Do Calculation ... + for (int i = limit - 1 - (loopback + 1); i >= 0; i--) { + // + int lastMarketHighestIndex = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLength, + i + ); + double lastMarketHighest = high[lastMarketHighestIndex]; + marketHighestBuffer[i] = lastMarketHighest; + + // + int lastMarketLowestIndex = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLength, + i + ); + double lastMarketLowest = low[lastMarketLowestIndex]; + marketLowestBuffer[i] = lastMarketLowest; + + // + int lastMarketHighestLowIndex = iLowest( + _Symbol, + _Period, + MODE_HIGH, + marketLength, + i + ); + double lastMarketHighestLow = high[lastMarketHighestLowIndex]; + marketHighestLowBuffer[i] = lastMarketHighestLow; + + // + int lastMarketLowestHighIndex = iHighest( + _Symbol, + _Period, + MODE_LOW, + marketLength, + i + ); + double lastMarketLowestHigh = low[lastMarketLowestHighIndex]; + marketLowestHighBuffer[i] = lastMarketLowestHigh; + + // + double marketMovingAverage = iMA( + _Symbol, + _Period, + marketLength * 2, // Ma Length ... + 0, // Ma Shift ... + MODE_SMA, // Ma Method ... + PRICE_MEDIAN, // Ma Applied Price ... + i // Bar Index ... + ); + marketMovingAverageBuffer[i] = marketMovingAverage; + + // + double marketMovingAverageT = iMA( + _Symbol, + _Period, + marketLength * 2, // Ma Length ... + 0, // Ma Shift ... + MODE_SMA, // Ma Method ... + PRICE_TYPICAL, // Ma Applied Price ... + i // Bar Index ... + ); + marketMovingAverageTBuffer[i] = marketMovingAverageT; + + // + double marketGap = MathAbs(marketMovingAverageBuffer[i] - marketMovingAverageTBuffer[i]); + + // + // this means Market Going to Trend Down ... + bool isMCrossOverMT = marketMovingAverageBuffer[i] > marketMovingAverageTBuffer[i] + && !( + marketMovingAverageBuffer[i + 1] > marketMovingAverageTBuffer[i + 1] + ); + bool isTrendDown = isMCrossOverMT && + marketGap > minimumMarketGap; + + // + // this means Market Going to Trend Up ... + bool isMCrossUnderMT = marketMovingAverageBuffer[i] < marketMovingAverageTBuffer[i] + && !( + marketMovingAverageBuffer[i + 1] < marketMovingAverageTBuffer[i + 1] + ); + bool isTrendUp = + // !isTrendDown + // && + isMCrossUnderMT + && marketGap > minimumMarketGap; + + // + bool isTrendRange = ( + !isMCrossUnderMT + && !isMCrossOverMT + ) || ( + !isTrendUp + && !isTrendDown + ); + + // + // Detect Last Market Trend State & Last Market Trend Time ... + int currentMarketTrend = + isTrendDown ? -1 : + isTrendUp ? 1 : + 0; + if (currentMarketTrend != lastMarketTrend) { + // + lastMarketTrend = currentMarketTrend; + lastMarketTrendTime = iTime( + _Symbol, + _Period, + i + ); + + // + if (isTrendDown) { + // + datetime arrowTime = iTime( + _Symbol, + _Period, + i + ); + + // + double arrowPrice = iHigh( + _Symbol, + _Period, + i + ); + arrowPrice = arrowPrice + (50 * _Point); + + // + string lbl = StringConcatenate( + logTag, + "_TrendDown_", + arrowTime + ); + + // + DrawArrow( + 0, + lbl, + 0, + arrowTime, + arrowPrice, + SYMBOL_ARROWDOWN, + ANCHOR_TOP, + clrFuchsia, + STYLE_SOLID, + 3 + ); + } + + // + if (isTrendUp) { + // + datetime arrowTime = iTime( + _Symbol, + _Period, + i + ); + + // + double arrowPrice = iLow( + _Symbol, + _Period, + i + ); + arrowPrice = arrowPrice - (50 * _Point); + + // + string lbl = StringConcatenate( + logTag, + "_TrendUp_", + arrowTime + ); + + // + DrawArrow( + 0, + lbl, + 0, + arrowTime, + arrowPrice, + SYMBOL_ARROWUP, + ANCHOR_BOTTOM, + clrAqua, + STYLE_SOLID, + 3 + ); + } + + // + if (isTrendRange) { + // + datetime arrowTime = iTime( + _Symbol, + _Period, + i + ); + + // + double arrowUpPrice = iHigh( + _Symbol, + _Period, + i + ); + arrowUpPrice = arrowUpPrice + (50 * _Point); + + // + double arrowDownPrice = iLow( + _Symbol, + _Period, + i + ); + arrowDownPrice = arrowDownPrice - (50 * _Point); + + // + string lblUp = StringConcatenate( + logTag, + "_TrendRange_UP_", + arrowTime + ); + + // + string lblDown = StringConcatenate( + logTag, + "_TrendRange_DOWN_", + arrowTime + ); + + // + DrawArrow( + 0, + lblUp, + 0, + arrowTime, + arrowUpPrice, + SYMBOL_ARROWDOWN, + ANCHOR_TOP, + clrGray, + STYLE_SOLID, + 3 + ); + + // + DrawArrow( + 0, + lblDown, + 0, + arrowTime, + arrowDownPrice, + SYMBOL_ARROWUP, + ANCHOR_BOTTOM, + clrGray, + STYLE_SOLID, + 3 + ); + } + + // + bool isSharp = false; + double marketHLGap = marketHighestBuffer[i] - marketLowestBuffer[i]; + for (int j = i + loopback; j > i; j--) { + // + double prevMarketHLGap = marketHighestBuffer[j] - marketLowestBuffer[j + 1]; + bool isThisSharp = + marketHLGap > prevMarketHLGap * multiplier; + + // + isSharp = isSharp || + ( + // ( + // isTrendUp || isTrendDown + // ) + // && + ( + isThisSharp + && marketGap > minimumMarketGap + ) + ); + } + + // + if (isSharp) { + // + datetime arrowTime = iTime( + _Symbol, + _Period, + i + ); + + // + double arrowPrice = iHigh( + _Symbol, + _Period, + i + ); + arrowPrice = arrowPrice + (50 * _Point); + + // + string lbl = StringConcatenate( + logTag, + "_SHARP_", + arrowTime + ); + + // + DrawArrow( + 0, + lbl, + 0, + arrowTime, + arrowPrice, + SYMBOL_ARROWDOWN, + ANCHOR_TOP, + clrYellow, + STYLE_SOLID, + 3 + ); + } + } + } + + // + // return value of prev_calculated for next call + return(rates_total); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/UnUsed/Indicators/x-saherelm.sl.mq4 b/Bkp/UnUsed/Indicators/x-saherelm.sl.mq4 new file mode 100644 index 0000000..9ab0e00 --- /dev/null +++ b/Bkp/UnUsed/Indicators/x-saherelm.sl.mq4 @@ -0,0 +1,154 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center StopLoss Indicator +// --------------------------------------------- +// saherelm implementation of above 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 StopLoss Indicator" +#property strict + +// +// START Inputs ... +// +input int swingLoopback = 7; // Swing Loopback +input double thrshold = 10; // Threshold +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +// Specify this is an Chart Indicator ... +#property indicator_chart_window + +// +// we have 2 buffer in this indicator ... +#property indicator_buffers 2 + +// +// also we have 2 line for draw on this indicator ... +#property indicator_plots 2 + +// +// here we declare plot Long Stop Loss to system ... +#property indicator_label1 "Long Stop Loss" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrFuchsia +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +// +// here we declare plot Short Stop Loss to system ... +#property indicator_label2 "Short Stop Loss" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrAqua +#property indicator_style2 STYLE_SOLID +#property indicator_width2 1 + +// +// here we declare indicator buffers ... +// +double longStopLossBuffer[]; +double shortStopLossBuffer[]; + +// +#define longStopLossIndex 0 +#define shortStopLossIndex 1 +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + SetIndexBuffer(longStopLossIndex, longStopLossBuffer); + SetIndexBuffer(shortStopLossIndex, shortStopLossBuffer); + + // + return(INIT_SUCCEEDED); +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + int limit; + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < swingLoopback) { + return 0; + } + + // + // found which candles calculated before ... + limit = rates_total - prev_calculated; + if (prev_calculated > 0) { + limit++; + } + + // + // Do Calculation ... + for (int i = limit - 1; i >= 0; i--) { + // + int lastMarketHighestIndex = iHighest(_Symbol, _Period, MODE_HIGH, swingLoopback, i); + double lastMarketHighest = high[lastMarketHighestIndex]; + + // + int lastMarketLowestIndex = iLowest(_Symbol, _Period, MODE_LOW, swingLoopback, i); + double lastMarketLowest = low[lastMarketLowestIndex]; + + // + double longStopLoss = lastMarketLowest - (thrshold * _Point); + longStopLoss = NormalizeDouble(longStopLoss, _Digits); + + // + double shortStopLoss = lastMarketHighest + (thrshold * _Point); + shortStopLoss = NormalizeDouble(shortStopLoss, _Digits); + + // + longStopLossBuffer[i] = longStopLoss; + shortStopLossBuffer[i] = shortStopLoss; + } + + // + // return value of prev_calculated for next call + return(rates_total); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/UnUsed/Indicators/x-saherelm.tp.mq4 b/Bkp/UnUsed/Indicators/x-saherelm.tp.mq4 new file mode 100644 index 0000000..89bfeba --- /dev/null +++ b/Bkp/UnUsed/Indicators/x-saherelm.tp.mq4 @@ -0,0 +1,221 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center TP Indicator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm TP Indicator" +#property strict + +// +// START Inputs ... +// +// +// Set the R2R Length ... +input int swingLoopback = 7; // Swing Loopback +input double slThrshold = 10; // SL Threshold +input double riskToRewardRatio = 1.5; // Risk to Reward Ratio +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// define indicator buffers ... +#property indicator_buffers 2 +#property indicator_plots 2 + +// +// here we declare plot to system ... +#property indicator_label1 "Long TP" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrLime +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +// +// here we declare plot to system ... +#property indicator_label2 "Short TP" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_SOLID +#property indicator_width2 1 + +// +// Declare Buffers ... +#define longTPBufferIndex 0 +#define shortTPBufferIndex 1 + +// +double longTPBuffer[]; +double shortTPBuffer[]; + +// +string slIndicatorName = "x-saherelm.sl"; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + SetIndexBuffer(longTPBufferIndex, longTPBuffer); + SetIndexDrawBegin(longTPBufferIndex, swingLoopback); + + // + SetIndexBuffer(shortTPBufferIndex, shortTPBuffer); + SetIndexDrawBegin(shortTPBufferIndex, swingLoopback); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, swingLoopback); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Long TP ... + CalculateLongTP( + open, + i + ); + + // + // Calculate Short TP ... + CalculateShortTP( + open, + i + ); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculate Long TPs based on SL and Open Price ... +void CalculateLongTP( + const double &open[], + const int &bar_index +) { + // + // read long sl ... + double longSL = iCustom( + _Symbol, + _Period, + slIndicatorName, + swingLoopback, + slThrshold, + 0, // Long SL Buffer Index ... + bar_index + ); + + // + double longRisk = open[bar_index] - longSL; + double longReward = longRisk * riskToRewardRatio; + + // + double longTP = open[bar_index] + longReward; + longTP = NormalizeDouble(longTP, _Digits); + + // + longTPBuffer[bar_index] = longTP; +} + +// +// Calculate Short TPs based on SL and Open Price ... +void CalculateShortTP( + const double &open[], + const int &bar_index +) { + // + // read short sl ... + double shortSL = iCustom( + _Symbol, + _Period, + slIndicatorName, + swingLoopback, + slThrshold, + 1, // Short SL Buffer Index ... + bar_index + ); + + // + double shortRisk = shortSL - open[bar_index]; + double shortReward = shortRisk * riskToRewardRatio; + + // + double shortTP = open[bar_index] - shortReward; + shortTP = NormalizeDouble(shortTP, _Digits); + + // + shortTPBuffer[bar_index] = shortTP; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/UnUsed/Indicators/x-saherelm.volume.mq4 b/Bkp/UnUsed/Indicators/x-saherelm.volume.mq4 new file mode 100644 index 0000000..eb4aa73 --- /dev/null +++ b/Bkp/UnUsed/Indicators/x-saherelm.volume.mq4 @@ -0,0 +1,270 @@ +///////////////////////////////////////////////////////////////// +// +// SaherElm IT Center Volume Indicator +// ------------------------------------------------------------- +// this indicator provides Volume ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +//////////////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm Volume Indicator" +#property strict + +// +// START Inputs ... +// +input int length = 11; // Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +#property indicator_separate_window + +// +// we have 2 buffer in this indicator ... +#property indicator_buffers 3 + +// +// also we have 2 line for draw on this indicator ... +#property indicator_plots 3 + +// +// Buy Volume ... +#property indicator_width1 1 +#property indicator_color1 clrGreen +#property indicator_type1 DRAW_HISTOGRAM +#property indicator_style1 STYLE_DOT + +// +// Sell Volume ... +#property indicator_width2 1 +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT + +// +// Diff ... +#property indicator_width3 1 +#property indicator_type3 DRAW_HISTOGRAM +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_SOLID + +// +//#property indicator_minimum 0 +//#property indicator_maximum 1 + +// +// set color of horizontal levels ... +#property indicator_levelcolor clrGray + +// +// set style of horizontal levels ... +#property indicator_levelstyle STYLE_DOT + +// +// Declare Buffers ... +#define buyVolumeBufferIndex 0 +#define sellVolumeBufferIndex 1 +#define diffBufferIndex 2 + +// +double buyVolumeBuffer[]; +double sellVolumeBuffer[]; +double diffBuffer[]; + +// +// here we specify logging enabled or not ... +bool enableLogging = true; + +// +// this is a Tag which attached to our Logger ... +string logTag = "XS_VOLUME"; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (length < 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // set descriptions of horizontal levels ... + SetLevelValue(0, 0.0); + IndicatorSetString(INDICATOR_LEVELTEXT,0,""); + + // + // Buy Volume Buffer ... + SetIndexBuffer(buyVolumeBufferIndex, buyVolumeBuffer); + SetIndexLabel(buyVolumeBufferIndex, "Buy Volume"); + + // + // Sell Volume Buffer ... + SetIndexBuffer(sellVolumeBufferIndex, sellVolumeBuffer); + SetIndexLabel(sellVolumeBufferIndex, "Sell Volume"); + + // + // Diff Buffer ... + SetIndexBuffer(diffBufferIndex, diffBuffer); + SetIndexLabel(diffBufferIndex, "Diff"); + + // + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, length); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + CalculateBuffers( + open, + close, + high, + low, + i + ); + } + + // + return rates_total; +} + +// +// De Initialization ... +void OnDeinit(const int reason) { +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +void CalculateBuffers( + const double &open[], + const double &close[], + const double &high[], + const double &low[], + const int &bar_index +) { + // + long volume = iVolume( + _Symbol, + _Period, + bar_index + ); + + // + double buyVolume = 0.0; + double sellVolume = 0.0; + + // + // Up ... + if (close[bar_index] > open[bar_index]) { + // + double cuenta = (high[bar_index] - low[bar_index]) * 10000; + double cuenta1 = volume - cuenta; + + // + buyVolume = ((volume - cuenta) / 2) + cuenta; + + // + buyVolumeBuffer[bar_index] = buyVolume; + sellVolumeBuffer[bar_index] = volume - buyVolume; + } else + // + // Down ... + if (close[bar_index] < open[bar_index]) { + // + double cuenta1 = (high[bar_index] - low[bar_index]) * 10000; + double cuenta = volume - cuenta1; + + // + sellVolume = ((volume - cuenta1) / 2) + cuenta1; + + // + sellVolumeBuffer[bar_index] = sellVolume; + buyVolumeBuffer[bar_index] = volume - sellVolume; + } else + // + // Neutral ... + if (close[bar_index] == open[bar_index]) { + // + double cuenta = (volume / 2) * 1.0; + + // + sellVolumeBuffer[bar_index] = cuenta; + buyVolumeBuffer[bar_index] = volume - cuenta; + } + + // + diffBuffer[bar_index] = MathAbs(buyVolumeBuffer[bar_index]) - MathAbs(sellVolumeBuffer[bar_index]); +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/UnUsed/Indicators/x-saherelm.xma.1.mq4 b/Bkp/UnUsed/Indicators/x-saherelm.xma.1.mq4 new file mode 100644 index 0000000..4c96e36 --- /dev/null +++ b/Bkp/UnUsed/Indicators/x-saherelm.xma.1.mq4 @@ -0,0 +1,337 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XMA Indicator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XMA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Set the R2R Length ... +input int swingLoopback = 7; // Swing Loopback +input int xmaFlowMultiplier = 3; // XMA Flow Multiplier +input int xmaMarkMultiplier = 5; // XMA Mark Multiplier +input int xmaFastMultiplier = 7; // XMA Fast Multiplier +input int xmaSlowMultiplier = 14; // XMA Slow Multiplier +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// define indicator buffers ... +#property indicator_buffers 6 +#property indicator_plots 6 + +// +// XMA High ... +#property indicator_label1 "XMA High" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrLime +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +// +// XMA Low ... +#property indicator_label2 "XMA Low" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrOrange +#property indicator_style2 STYLE_SOLID +#property indicator_width2 1 + +// +// XMA Mark ... +#property indicator_label3 "XMA Mark" +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrCornflowerBlue +#property indicator_style3 STYLE_DASH +#property indicator_width3 1 + +// +// XMA Mid ... +#property indicator_label4 "XMA Mid" +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrBisque +#property indicator_style4 STYLE_DASHDOT +#property indicator_width4 1 + +// +// XMA Fast ... +#property indicator_label5 "XMA Fast" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrGreen +#property indicator_style5 STYLE_DOT +#property indicator_width5 1 + +// +// XMA Slow ... +#property indicator_label6 "XMA Slow" +#property indicator_type6 DRAW_LINE +#property indicator_color6 clrRed +#property indicator_style6 STYLE_DOT +#property indicator_width6 1 + +// +// Declare Buffers ... +#define xmaHighBufferIndex 0 +#define xmaLowBufferIndex 1 +#define xmaMarkBufferIndex 2 +#define xmaMidBufferIndex 3 +#define xmaFastBufferIndex 4 +#define xmaSlowBufferIndex 5 + +// +double xmaHighBuffer[]; +double xmaLowBuffer[]; +double xmaMarkBuffer[]; +double xmaMidBuffer[]; +double xmaFastBuffer[]; +double xmaSlowBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + + // + // Validating Input Parameters ... + if (swingLoopback <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // XMA High ... + SetIndexBuffer(xmaHighBufferIndex, xmaHighBuffer); + SetIndexDrawBegin(xmaHighBufferIndex, swingLoopback * xmaFlowMultiplier); + + // + // XMA Low ... + SetIndexBuffer(xmaLowBufferIndex, xmaLowBuffer); + SetIndexDrawBegin(xmaLowBufferIndex, swingLoopback * xmaFlowMultiplier); + + // + // XMA Mark ... + SetIndexBuffer(xmaMarkBufferIndex, xmaMarkBuffer); + SetIndexDrawBegin(xmaMarkBufferIndex, swingLoopback * xmaMarkMultiplier); + + // + // XMA Mid ... + SetIndexBuffer(xmaMidBufferIndex, xmaMidBuffer); + SetIndexDrawBegin(xmaMidBufferIndex, swingLoopback); + + // + // XMA Fast ... + SetIndexBuffer(xmaFastBufferIndex, xmaFastBuffer); + SetIndexDrawBegin(xmaFastBufferIndex, swingLoopback * xmaFastMultiplier); + + // + // XMA Slow ... + SetIndexBuffer(xmaSlowBufferIndex, xmaSlowBuffer); + SetIndexDrawBegin(xmaSlowBufferIndex, swingLoopback * xmaSlowMultiplier); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, swingLoopback); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate XMA Flow ... + CalculateXMAFlow(i); + + // + // Calculate XMA Mark ... + CalculateXMAMark(i); + + // + // Calculate XMA Mid ... + CalculateXMAMid(i); + + // + // Calculate XMA Fast/Slow ... + CalculateXMAFastSlow(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculate XMA Flow ... +void CalculateXMAFlow(const int &bar_index) { + // + int xmaFlowLength = swingLoopback * xmaFlowMultiplier; + + // + // Calculating XMa High ... + double xmaHigh = iMA( + _Symbol, + _Period, + xmaFlowLength, + 0, + MODE_SMA, + PRICE_HIGH, + bar_index + ); + xmaHighBuffer[bar_index] = xmaHigh; + + // + // Calculating XMa Low ... + double xmaLow = iMA( + _Symbol, + _Period, + xmaFlowLength, + 0, + MODE_SMA, + PRICE_LOW, + bar_index + ); + xmaLowBuffer[bar_index] = xmaLow; +} + +// +// Calculate XMA Mark ... +void CalculateXMAMark(const int &bar_index) { + // + int xmaMarkLength = swingLoopback * xmaMarkMultiplier; + + // + // Calculating XMa Mark ... + double xmaMark = iMA( + _Symbol, + _Period, + xmaMarkLength, + 0, + MODE_SMA, + PRICE_HIGH, + bar_index + ); + xmaMarkBuffer[bar_index] = xmaMark; +} + +// +// Calculate XMA Mid ... +void CalculateXMAMid(const int &bar_index) { + // + // Calculating XMa Mid ... + double xmaMid = iMA( + _Symbol, + _Period, + swingLoopback, + 0, + MODE_EMA, + PRICE_HIGH, + bar_index + ); + xmaMidBuffer[bar_index] = xmaMid; +} + +// +// Calculate XMA Fast/Slow ... +void CalculateXMAFastSlow(const int &bar_index) { + // + int xmaFastLength = swingLoopback * xmaFastMultiplier; + int xmaSlowLength = swingLoopback * xmaSlowMultiplier; + + // + // Calculating XMa Fast ... + double xmaFast = iMA( + _Symbol, + _Period, + xmaFastLength, + 0, + MODE_SMA, + PRICE_CLOSE, + bar_index + ); + xmaFastBuffer[bar_index] = xmaFast; + + // + // Calculating XMa Slow ... + double xmaSlow = iMA( + _Symbol, + _Period, + xmaSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE, + bar_index + ); + xmaSlowBuffer[bar_index] = xmaSlow; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/UnUsed/Indicators/x-saherelm.xmma.mq4 b/Bkp/UnUsed/Indicators/x-saherelm.xmma.mq4 new file mode 100644 index 0000000..835aae4 --- /dev/null +++ b/Bkp/UnUsed/Indicators/x-saherelm.xmma.mq4 @@ -0,0 +1,408 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XMMA Indicator +// --------------------------------------------- +// this is an indicator which going to analyse +// Market based on Price Movements and provide +// some informations to act based on current market +// state ... +// +// 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 Market Analyser (XMMA) Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 7; // Market Length +input int fastShift = 1; // Fast Shift +input int slowShift = 3; // Slow Shift +input int longMarketFastMultiplier = 100; // Long Market Fast Multiplier +input int longMarketSlowMultiplier = 200; // Long Market Slow Multiplier +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// define indicator buffers ... +#property indicator_buffers 7 +#property indicator_plots 7 + +// +// Fast ... +#property indicator_label1 "Fast" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +// Slow ... +#property indicator_label2 "SLow" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +// Mid ... +#property indicator_label3 "Mid" +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrBisque +#property indicator_style3 STYLE_DASH +#property indicator_width3 1 + +// +// Long SL ... +#property indicator_label4 "Long SL" +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrAqua +#property indicator_style4 STYLE_DASH +#property indicator_width4 1 + +// +// Short SL ... +#property indicator_label5 "Short SL" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrFuchsia +#property indicator_style5 STYLE_DASH +#property indicator_width5 1 + +// +// Long Market Fast ... +#property indicator_label6 "Long Fast" +#property indicator_type6 DRAW_LINE +#property indicator_color6 clrAqua +#property indicator_style6 STYLE_DOT +#property indicator_width6 1 +// +// Long Market Slow ... +#property indicator_label7 "Long Market Slow" +#property indicator_type7 DRAW_LINE +#property indicator_color7 clrFuchsia +#property indicator_style7 STYLE_DOT +#property indicator_width7 1 + +// +// Declare Buffers ... +#define fastBufferIndex 0 +#define slowBufferIndex 1 +#define midBufferIndex 2 +#define longSLBufferIndex 3 +#define shortSLBufferIndex 4 +#define longMarketFastBufferIndex 5 +#define longMarketSlowBufferIndex 6 + +// +double fastBuffer[]; +double slowBuffer[]; +double midBuffer[]; +double longSLBuffer[]; +double shortSLBuffer[]; +double longMarketFastBuffer[]; +double longMarketSlowBuffer[]; + +// +int lastCrossOverIndex = 0; +double lastCrossOver = 0.0; + +// +int lastCrossUnderIndex = 0; +double lastCrossUnder = 0.0; + +// +double lastLongSL = 0.0; +int lastLongSLIndex = 0; + +// +double lastShortSL = 0.0; +int lastShortSLIndex = 0; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + fastShift < 0 || + slowShift < 0 || + marketLength <= 0 || + slowShift < fastShift + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Fast ... + SetIndexBuffer(fastBufferIndex, fastBuffer); + + // + // Slow ... + SetIndexBuffer(slowBufferIndex, slowBuffer); + + // + // Mid ... + SetIndexBuffer(midBufferIndex, midBuffer); + + // + // Long SL ... + SetIndexBuffer(longSLBufferIndex, longSLBuffer); + + // + // Short SL ... + SetIndexBuffer(shortSLBufferIndex, shortSLBuffer); + + // + // Long Market Fast ... + SetIndexBuffer(longMarketFastBufferIndex, longMarketFastBuffer); + + // + // Long Market Slow ... + SetIndexBuffer(longMarketSlowBufferIndex, longMarketSlowBuffer); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Flow ... + CalculateFlow(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculate Flow ... +void CalculateFlow( + const int &bar_index +) { + // + int fastLength = marketLength + fastShift; + int slowLength = marketLength + fastShift + slowShift; + + // + // Calculating Fast ... + double fast = iMA( + _Symbol, + _Period, + fastLength, + 0, + MODE_EMA, + PRICE_WEIGHTED, + bar_index + ); + fastBuffer[bar_index] = fast; + + // + // Calculating Slow ... + double slow = iMA( + _Symbol, + _Period, + slowLength, + 0, + MODE_EMA, + PRICE_WEIGHTED, + bar_index + ); + slowBuffer[bar_index] = slow; + + // + // Calculating XMa Mid ... + double xmaMid = iMA( + _Symbol, + _Period, + marketLength, + 0, + MODE_EMA, + PRICE_HIGH, + bar_index + ); + midBuffer[bar_index] = xmaMid; + + // + // Calculating XMa Long Market Fast ... + double xmaLongMarketFast = iMA( + _Symbol, + _Period, + marketLength * longMarketFastMultiplier, + 0, + MODE_SMA, + PRICE_CLOSE, + bar_index + ); + longMarketFastBuffer[bar_index] = xmaLongMarketFast; + + // + // Calculating XMa Long Market Slow ... + double xmaLongMarketSlow = iMA( + _Symbol, + _Period, + marketLength * longMarketSlowMultiplier, + 0, + MODE_SMA, + PRICE_CLOSE, + bar_index + ); + longMarketSlowBuffer[bar_index] = xmaLongMarketSlow; + + // + // Find Cross Points ... + // + bool isCrossOver = fastBuffer[bar_index] > slowBuffer[bar_index] + && !( + fastBuffer[bar_index + 1] > slowBuffer[bar_index + 1] + ); + + // + bool isCrossUnder = fastBuffer[bar_index] < slowBuffer[bar_index] + && !( + fastBuffer[bar_index + 1] < slowBuffer[bar_index + 1] + ); + + // + // Find Trending ... + // + bool isTrendUp = fastBuffer[bar_index] > slowBuffer[bar_index] + && fastBuffer[bar_index] > fastBuffer[bar_index + 1] + && slowBuffer[bar_index] > slowBuffer[bar_index + 1]; + + // + bool isTrendDown = fastBuffer[bar_index] < slowBuffer[bar_index] + && fastBuffer[bar_index] < fastBuffer[bar_index + 1] + && slowBuffer[bar_index] < slowBuffer[bar_index + 1]; + + // + // Do Some Calculations ... + if (isCrossOver) { + // + lastCrossOverIndex = bar_index; + lastCrossOver = fastBuffer[bar_index]; + } else if (isCrossUnder) { + // + lastCrossUnderIndex = bar_index; + lastCrossUnder = fastBuffer[bar_index]; + } + + // + // Calculate SLs ... + // + // Long SL ... + if (lastCrossOver > 0) { + // + lastLongSLIndex = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLength, + lastCrossOverIndex + ); + + // + lastLongSL = iLow( + _Symbol, + _Period, + lastLongSLIndex + ); + } + + // + // Short SL ... + if (lastCrossUnder > 0) { + // + lastShortSLIndex = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLength, + lastCrossUnderIndex + ); + + // + lastShortSL = iHigh( + _Symbol, + _Period, + lastShortSLIndex + ); + } + + // + longSLBuffer[bar_index] = lastLongSL; + shortSLBuffer[bar_index] = lastShortSL; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/UnUsed/Indicators/x-saherelm.xmma.signalling.mq4 b/Bkp/UnUsed/Indicators/x-saherelm.xmma.signalling.mq4 new file mode 100644 index 0000000..2d4a0d8 --- /dev/null +++ b/Bkp/UnUsed/Indicators/x-saherelm.xmma.signalling.mq4 @@ -0,0 +1,249 @@ +///////////////////////////////////////////////////////////////// +// +// SaherElm IT Center XMMA Signalling Indicator +// ------------------------------------------------------------- +// this indicator provides signals for XMMA Based Strategy ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +//////////////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XMMA Signalling Indicator" +#property strict + +// +// START Inputs ... +// +// +// Signal Show/Hide ... +input bool showSignals = true; // Show Signals +input bool showLongSignals = true; // Show Long Signals +input bool showShortSignals = true; // Show Short Signals + +// +// Signal Prefixe ... +input string signalPrefix = "XS_SG_OSC"; // Signal Prefix +input double signalArrowPositionThresholdFactor = 100; // Signal Arrow Dist of Price + +// +// Signal Colors ... +input string bullishSignalLabel = "X_BUY"; // Bullish Signal Label +input color bullishSignalColor = clrAqua; // Bullish Signal Color + +// +input string bearishSignalLabel = "X_SELL"; // Bearish Signal Label +input color bearishSignalColor = clrFuchsia; // Bearish Signal Color + +// +// here we specify alerting signals ... +input bool alertSignals = false; // Alert Signals +input bool pushNotificationSignals = false; // Push Notification Alert Signals + +// +// Indicator Inputs ... +input int marketLength = 7; // Market Length +input int fastShift = 1; // Fast Shift +input int slowShift = 3; // Slow Shift +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_chart_window + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.xmma.signal.lib.mq4" + +// +// Last Signalled Bar ... +int lastSignalledBar = 0; + +// +// here we specify logging enabled or not ... +bool enableLogging = true; + +// +// this is a Tag which attached to our Logger ... +string logTag = "XS_SG_OSC"; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + fastShift < 0 || + slowShift < 0 || + marketLength <= 0 || + slowShift < fastShift + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + CalculateSignals(i); + } + + // + return rates_total; +} + +// +// De Initialization ... +void OnDeinit(const int reason) { + // + RemoveDraws(signalPrefix); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Here we are Calculate Signals based on Oscillators and fill up +// related buffers ... +void CalculateSignals(const int &bar_index) { + // + // Retrieve Signal Exists ... + XSignalRequest request = CalculateSignal( + bar_index, + marketLength, + fastShift, + slowShift + ); + + // + if (!request.hasSignal) { + return; + } + + // + // Prevent Multiple Alerting at same Candle ... + if (lastSignalledBar == bar_index) { + return; + } + + // + lastSignalledBar = bar_index; + + // + bool hasLongSignal = request.type == X_LONG; + bool hasShortSignal = request.type == X_SHORT; + + // + // Signal Tag ... + string signalTAG = GenerateSignalTAG( + request.signal, + signalPrefix, + bullishSignalLabel, + bearishSignalLabel + ); + + // + // Handle Alerts ... + if (alertSignals && bar_index == 0) { + // + // General Alert ... + Alert(signalTAG); + + // + // Push Notifications ... + if (pushNotificationSignals) { + SendNotification(signalTAG); + } + } + + // + // Handle Can Show Signals ... + bool canShowSignals = showSignals && + (hasLongSignal ? showLongSignals : hasShortSignal ? showShortSignals : false); + if (canShowSignals) { + // + // Here i must to Draw Signal Shapes ... + DrawSignal( + request.signal, + 0, + 0, + signalArrowPositionThresholdFactor, + signalPrefix, // Signal Tag ... + bullishSignalLabel, // Long Signal Label ... + bullishSignalColor, + bearishSignalLabel, // Short Signal Label ... + bearishSignalColor + ); + } +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/UnUsed/Libs/x-saherelm.lib.1.mq4 b/Bkp/UnUsed/Libs/x-saherelm.lib.1.mq4 new file mode 100644 index 0000000..fc7b528 --- /dev/null +++ b/Bkp/UnUsed/Libs/x-saherelm.lib.1.mq4 @@ -0,0 +1,203 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +// START Functions ... +// + +// +// Determines current working is New Bar or not ... +bool IsNewBar() { + // + static datetime lastbar; + datetime curbar = (datetime)SeriesInfoInteger(_Symbol, _Period, SERIES_LASTBAR_DATE); + + // + if(lastbar != curbar) { + // + lastbar = curbar; + return true; + } + + // + return false; +} + +// +// this function check crossing up two Buffers ... +bool IsCrossedOver( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] > arr2[index1]) && !(arr1[index2] > arr2[index2]); + + // + return result; +} + +// +// this function check crossing down two Buffers ... +bool IsCrossedUnder( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] < arr2[index1]) && !(arr1[index2] < arr2[index2]); + + // + return result; +} + +// +// Convert points to Actual Point ... +double PointsToDouble(int points) { + // + double result = points * _Point; + return result; +} + +// +// Converts Pips to Points ... +int PipsToPoints(int pips) { + // + int result = pips * ((_Digits == 3 || _Digits == 5) ? 10 : 1); + return result; +} + +// +// Converts Pips to Double ... +double PipsToDouble(int pips) { + // + double result = PointsToDouble(PipsToPoints(pips)); + return result; +} + +// +// Multiply two Buffer ... +void MultiplyBuffer( + const double &buffer1[], + const double &buffer2[], + double &result[] +) { + // + int buffer1Size = ArraySize(buffer1); + int buffer2Size = ArraySize(buffer2); + + // + int size = MathMax(buffer1Size, buffer2Size); + + // + ArrayResize(result, size); + ArrayFill(result, 0, size, 0.0); + + // + for (int i = 0; i < size; i++) { + result[i] = buffer1[i] * buffer2[i]; + } +} + +// +// Calculate SMA ... +double iSMA( + const double &src[], + const int len = 7, + const int bar_index = 0 +) { + // + double result = 0.0; + + // + for (int i = bar_index + (len - 1); i >= bar_index; i--) { + result += src[bar_index] / len; + } + + // + return result; +} + +// +// Calculat VMA ... +double iVWMA( + const double &src[], + const long &volume[], + const int len = 7, + const int bar_index = 0 +) { + // + double result = 0.0; + + // + // double volume ... + int volumeSize = ArraySize(volume); + double dVolume[]; + ArrayResize(dVolume, volumeSize); + ArrayFill(dVolume, 0, volumeSize, 0.0); + for (int i = 0; i < volumeSize; i++) { + dVolume[i] = volume[i] * 1.0; + }; + + + // + double multipliedSourceVolume[]; + MultiplyBuffer( + src, + dVolume, + multipliedSourceVolume + ); + + // + result = iSMA( + multipliedSourceVolume, + len + ) / iSMA( + dVolume, + len + ); + + // + return result; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/UnUsed/Libs/x-saherelm.models.lib.mq4 b/Bkp/UnUsed/Libs/x-saherelm.models.lib.mq4 new file mode 100644 index 0000000..b8618f2 --- /dev/null +++ b/Bkp/UnUsed/Libs/x-saherelm.models.lib.mq4 @@ -0,0 +1,271 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Models Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Start Models ... +// + +// +// Used Indicators List ... +const string slIndicatorName = "x-saherelm.sl"; +const string tpIndicatorName = "x-saherelm.tp"; +const string maIndicatorName = "x-saherelm.ma"; +const string xmaIndicatorName = "x-saherelm.xma"; +const string oscIndicatorName = "x-saherelm.osc"; +const string sslIndicatorName = "x-saherelm.ssl"; +const string pcrtIndicatorName = "x-saherelm.pcrt"; +const string volumeIndicatorName = "x-saherelm.volume"; +const string zigZagIndicatorName = "x-saherelm.zigzag"; + +// +// Direction ... +enum X_DIRECTION { + X_UP, + X_DOWN +}; + +// +// these are different signal types ... +enum X_SIGNAL_TYPE { + X_NONE, + X_LONG, + X_SHORT, +}; + +// +// Define an Specific Arrow Code enum ... +enum X_ARROW_CODE { + // + X_ARROW_UP = OBJ_ARROW_UP, + X_ARROW_DOWN = OBJ_ARROW_DOWN, + // + X_ARROW_THUMB_UP = OBJ_ARROW_THUMB_UP, + X_ARROW_THUMB_DOWN = OBJ_ARROW_THUMB_DOWN, + // + X_ARROW_BUY = OBJ_ARROW_BUY, + X_ARROW_SELL = OBJ_ARROW_SELL, + // + X_ARROW_STOP = OBJ_ARROW_STOP, + X_ARROW_CHECK = OBJ_ARROW_CHECK, + // + X_ARROW_LEFT_PRICE = OBJ_ARROW_LEFT_PRICE, + X_ARROW_RIGHT_PRICE = OBJ_ARROW_RIGHT_PRICE, +}; + +// +// Pricae Action Theory Candle Types ... +enum X_P_CANDLE_TYPE { + X_P_CT_BULLISH = 1, + X_P_CT_NEUTRAL = 2, + X_P_CT_BEARISH = 3, +}; + +// +// Candlestick Theory Candle Types ... +enum X_CANDLE_TYPE { + X_CT_DOJI = 1, + X_CT_EVENING_STAR = 2, + X_CT_MORNING_STAR = 3, + X_CT_SHOOTING_STAR = 4, + X_CT_HAMMER = 5, + X_CT_INVERTED_HAMMER = 6, + X_CT_BEARISH_HARAMI = 7, + X_CT_BULLISH_HARAMI = 8, + X_CT_BEARISH_ENGULFING = 9, + X_CT_BULLISH_ENGULFING = 10, + X_CT_PRICE_LINE = 11, + X_CT_BULLISH_BELT = 12, + X_CT_BULLISH_KICKER = 13, + X_CT_BEARISH_KICKER = 14, + X_CT_HANGING_MAN = 15, + X_CT_DARK_CLOUD_COVER = 16 +}; + +// +// we model OSC Return Data ... +struct XOSCState { + // + double fastOSC; + double fastOSCPrev; + + // + double slowOSC; + double slowOSCPrev; + + // + double powerOSC; + double powerOSCPrev; + + // + double varOSC; + double varOSCPrev; + + // + double tanFSOSC; +}; + +// +// we Model MACD State ... +struct XMACDState { + double MACD; + double signal; +}; + +// +// model ssl State ... +struct XSSLState { + // + double sslUp; + double sslUpPrev; + + // + double sslDown; + double sslDownPrev; +}; + +// +// Model Volume Indicator Result ... +struct XVolumeState { + double buyVolume; + double sellVolume; +}; + +// +// Signal Info Model ... +struct XSignalInfo { + // + bool hasSignal; + // + bool hasLongSignal; + bool hasShortSignal; +}; + +// +// Model SLs as this ... +struct XSLInfo { + double longSL; + double shortSL; +}; + +// +// Model TPs as this ... +struct XTPInfo { + double longTP; + double shortTP; +}; + +// +// ZigZag State ... +struct XZigZagState { + // + double zigZag; + datetime zigZagTime; + + // + double zigZagPrev; + datetime zigZagPrevTime; + + // + double low; + int lowBarIndex; + datetime lowTime; + + // + double high; + int highBarIndex; + datetime highTime; + + // + double delta; + + // + bool isWaitForTrendUp; + bool isWaitForTrendDown; + + // + bool isLowIsLastLow; + bool isHighIsLastHigh; +}; + +// +// we Model each signals as this type ... +struct XSignal { + int id; + X_SIGNAL_TYPE type; + double tp; + double sl; + string symbol; + datetime time; + double entryPrice; +}; + +// +// this is Signal Request Response model ... +struct XSignalRequest { + bool hasSignal; + X_SIGNAL_TYPE type; + XSignal signal; +}; + +// +// State of Market based on XMA ... +struct XMAState { + // + double xmaFast; + double xmaFastPrev; + + // + double xmaSlow; + double xmaSlowPrev; + + // + bool isBullishTrend; + bool isBearishTrend; + + // + double trendPower; + + // + double xmaHigh; + double xmaHighPrev; + + // + double xmaLow; + double xmaLowPrev; + + // + bool isFlowUp; + bool isFlowDown; + + // + double xmaMark; + + // + double xmaMid; + double xmaMidPrev; +}; + +// +// Define an enum for Detection Rules on Candlestick Indicator ... +enum X_CD_DETECTION_RULES { + X_PRICE_50_SMA, + X_PRICE_50_200_SMA +}; +// +// End Models ... +// diff --git a/Bkp/UnUsed/Libs/x-saherelm.signal.lib.mq4 b/Bkp/UnUsed/Libs/x-saherelm.signal.lib.mq4 new file mode 100644 index 0000000..4fe3dd4 --- /dev/null +++ b/Bkp/UnUsed/Libs/x-saherelm.signal.lib.mq4 @@ -0,0 +1,1467 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Signal Draw Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +// Start Signal Functions ... +// +// +// Generate a Unique ID for Signal ... +string GenerateSignalTAG( + const XSignal &signal, + const string tag = "", + const string longSignalLabel = "", + const string shortSignalLabel = "" +) { + // + // Generate Propper Label for Signal ... + string label = signal.type == X_LONG ? longSignalLabel : signal.type == X_SHORT ? shortSignalLabel : "UN_KNOWN"; + + // + // Generate Unique String Identifier for Signal ... + string result = tag + + "_[ID:" + IntegerToString(signal.id) + "]" + + "_[" + label + "]" + + "_[" + signal.symbol + "]" + + "_[Time:" + TimeToStr(signal.time) + "]" + + "_[TP:" + DoubleToString(signal.tp) + "]" + + "_[SL:" + DoubleToString(signal.sl) + "]"; + + // + return result; +} + +// +// Logging a Signal ... +void LogSignal( + const XSignal &signal, + const string tag = "", + const string longSignalLabel = "", + const string shortSignalLabel = "" +) { + // + // Generate Message ... + string signalMessage = GenerateSignalTAG( + signal, + tag, + longSignalLabel, + shortSignalLabel + ); + + // + LogMessage(signalMessage); +} + +// +// Retrieve Price Action Candlestick Type ... +double GetPCandleType(const int bar_index) { + // + double result = iCustom( + _Symbol, + _Period, + pcrtIndicatorName, + 0, + bar_index + ); + + // + return result; +} + +// +// Retrieve OSC Snapshot State ... +XOSCState GetOSCState(const int bar_index) { + // + // Temp Result ... + XOSCState result = {}; + + // + // Start Extract Data from Oscillator ... + // + // + // Fast OSC ... + double fastOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + fastOSCLength, + fastOSCMultiplier, + slowOSCLength, + slowOSCMultiplier, + 0, // Fast OSC Buffer Index ... + bar_index + ); + result.fastOSC = fastOSC; + + // + // Prev FastOSC ... + double fastOSCPrev = iCustom( + _Symbol, + _Period, + oscIndicatorName, + fastOSCLength, + fastOSCMultiplier, + slowOSCLength, + slowOSCMultiplier, + 0, // Fast OSC Buffer Index ... + bar_index + 1 + ); + result.fastOSCPrev = fastOSCPrev; + + // + // Slow OSC ... + double slowOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + fastOSCLength, + fastOSCMultiplier, + slowOSCLength, + slowOSCMultiplier, + 1, // Slow OSC Buffer Index ... + bar_index + ); + result.slowOSC = slowOSC; + + // + // Prev Slow OSC ... + double slowOSCPrev = iCustom( + _Symbol, + _Period, + oscIndicatorName, + fastOSCLength, + fastOSCMultiplier, + slowOSCLength, + slowOSCMultiplier, + 1, // Slow OSC Buffer Index ... + bar_index + 1 + ); + result.slowOSCPrev = slowOSCPrev; + + // + // Power OSC ... + double powerOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + fastOSCLength, + fastOSCMultiplier, + slowOSCLength, + slowOSCMultiplier, + 2, // Power OSC Buffer Index ... + bar_index + ); + result.powerOSC = powerOSC; + + // + double powerOSCPrev = iCustom( + _Symbol, + _Period, + oscIndicatorName, + fastOSCLength, + fastOSCMultiplier, + slowOSCLength, + slowOSCMultiplier, + 2, // Power OSC Buffer Index ... + bar_index + 1 + ); + result.powerOSCPrev = powerOSCPrev; + + // + // Var OSC ... + double varOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + fastOSCLength, + fastOSCMultiplier, + slowOSCLength, + slowOSCMultiplier, + 3, // Var OSC Buffer Index ... + bar_index + ); + result.varOSC = varOSC; + + // + double varOSCPrev = iCustom( + _Symbol, + _Period, + oscIndicatorName, + fastOSCLength, + fastOSCMultiplier, + slowOSCLength, + slowOSCMultiplier, + 3, // Var OSC Buffer Index ... + bar_index + 1 + ); + result.varOSCPrev = varOSCPrev; + + // + // Tan FS OSC ... + double tanFSOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + fastOSCLength, + fastOSCMultiplier, + slowOSCLength, + slowOSCMultiplier, + 4, // Tan F/S OSC Buffer Index ... + bar_index + ); + result.tanFSOSC = tanFSOSC; + // + // End Extract Data from Oscillator ... + // + + // + return result; +} + +// +// Retrieve Ma Snapshot State ... +XMaState GetMaState( + const int bar_index, + int fastMaPeriod = 20, + ENUM_MA_METHOD fastMaMethod = MODE_EMA, + ENUM_APPLIED_PRICE fastMaAppliedPrice = PRICE_CLOSE, + int slowMaPeriod = 50, + ENUM_MA_METHOD slowMaMethod = MODE_EMA, + ENUM_APPLIED_PRICE slowMaAppliedPrice = PRICE_CLOSE +) { + // + XMaState result = {}; + + // + double fastMa = iCustom( + _Symbol, + _Period, + maIndicatorName, + fastMaPeriod, + fastMaMethod, + fastMaAppliedPrice, + slowMaPeriod, + slowMaMethod, + slowMaAppliedPrice, + 0, + bar_index + ); + result.fastMa = fastMa; + + // + double fastMaPrev = iCustom( + _Symbol, + _Period, + maIndicatorName, + fastMaPeriod, + fastMaMethod, + fastMaAppliedPrice, + slowMaPeriod, + slowMaMethod, + slowMaAppliedPrice, + 0, + bar_index + 1 + ); + result.fastMaPrev = fastMaPrev; + + // + double slowMa = iCustom( + _Symbol, + _Period, + maIndicatorName, + fastMaPeriod, + fastMaMethod, + fastMaAppliedPrice, + slowMaPeriod, + slowMaMethod, + slowMaAppliedPrice, + 1, + bar_index + ); + result.slowMa = slowMa; + + // + double slowMaPrev = iCustom( + _Symbol, + _Period, + maIndicatorName, + fastMaPeriod, + fastMaMethod, + fastMaAppliedPrice, + slowMaPeriod, + slowMaMethod, + slowMaAppliedPrice, + 1, + bar_index + 1 + ); + result.slowMaPrev = slowMaPrev; + + // + Print(fastMa, slowMa, fastMaPrev, slowMaPrev); + + // + return result; +} + +// +// Retrieve MACD info ... +XMACDState GetMACDState() { + // + XMACDState result = {}; + + // + // TODO: Complete this later ... + + // + return result; +} + +// +// Check OSC Has Signal ... +// default Method ... +XSignalInfo OSCHasSignal( + const XOSCState &oscState, + const double &minimumSignalPower, + const double &minimumVarPower +) { + // + // Genrate Temp Result ... + XSignalInfo result = {}; + + // + bool isCrossedOver = oscState.fastOSC > oscState.slowOSC && !(oscState.fastOSCPrev > oscState.slowOSCPrev); + bool hasLongSignal = isCrossedOver && oscState.powerOSC >= minimumSignalPower; + result.hasLongSignal = hasLongSignal; + + // + bool isCrossedUnder = oscState.fastOSC < oscState.slowOSC && !(oscState.fastOSCPrev < oscState.slowOSCPrev); + bool hasShortSignal = isCrossedUnder && oscState.powerOSC >= minimumSignalPower; + result.hasShortSignal = hasShortSignal; + + // + bool hasSignal = hasLongSignal || hasShortSignal; + result.hasSignal = hasSignal; + + // + return result; +} + +// +// Check OSC Has Signal ... +// Method 1 ... +XSignalInfo OSCHasSignal_1( + const XOSCState &oscState, + const double &minimumSignalPower, + const double &minimumVarPower +) { + // + static bool canSignalLong = true; + static bool canSignalShort = true; + + // + // Genrate Temp Result ... + XSignalInfo result = {}; + //return result; + + // + // bool hasLongSignal = false; + bool isCrossedOver = oscState.fastOSC > oscState.slowOSC && + !(oscState.fastOSCPrev > oscState.slowOSCPrev); + bool hasLongSignal = isCrossedOver && + oscState.powerOSC >= minimumSignalPower && + oscState.varOSC >= minimumVarPower; + result.hasLongSignal = hasLongSignal; + // if (hasLongSignal) { + // canSignalLong = false; + // } + + // + // bool hasShortSignal = false; + bool isCrossedUnder = oscState.fastOSC < oscState.slowOSC && !(oscState.fastOSCPrev < oscState.slowOSCPrev); + bool hasShortSignal = isCrossedUnder && + oscState.powerOSC >= minimumSignalPower && + oscState.varOSC >= minimumVarPower; + result.hasShortSignal = hasShortSignal; + // if (hasShortSignal) { + // canSignalShort = false; + // } + + // + bool hasSignal = hasLongSignal || hasShortSignal; + result.hasSignal = hasSignal; + + // + // Fix can Signal Long ... + //if (oscState.fastOSC >= 0 && !canSignalLong) { + // canSignalLong = true; + //} + + // + // Fix can Signal Short ... + //if (oscState.fastOSC <= 1 && !canSignalShort) { + // canSignalShort = true; + //} + + // + return result; +} + +// +// Check OSC Has Signal ... +// Method 2 ... +XSignalInfo OSCHasSignal_2( + const XOSCState &oscState, + const int &bar_index +) { + // + static bool canSignalLong = true; + static bool canSignalShort = true; + + // + // Genrate Temp Result ... + XSignalInfo result = {}; + //return result; + + // + // bool hasLongSignal = false; + bool isCrossedOver = oscState.fastOSC > oscState.slowOSC && + !(oscState.fastOSCPrev > oscState.slowOSCPrev); + + // + // Get Prev Price Action Candle Type ... + int pCandleType = (int) GetPCandleType(bar_index + 1); + + bool hasLongSignal = isCrossedOver + && oscState.slowOSC > 0.5 + && oscState.varOSC > 0; + + // && oscState.powerOSC >= 0.006 + // && oscState.powerOSC - oscState.powerOSCPrev > 0 + // && oscState.tanFSOSC >= 0.06 + + // && ( + // pCandleType == X_CT_HAMMER || + // pCandleType == X_CT_BULLISH_BELT || + // pCandleType == X_CT_MORNING_STAR || + // pCandleType == X_CT_BULLISH_KICKER || + // pCandleType == X_CT_BULLISH_HARAMI || + // pCandleType == X_CT_INVERTED_HAMMER || + // pCandleType == X_CT_BULLISH_ENGULFING || + // pCandleType == 0 + // ) + result.hasLongSignal = hasLongSignal; + if (hasLongSignal) { + // + // Print("Tan: " + oscState.tanFSOSC); + } + // if (hasLongSignal) { + // canSignalLong = false; + // } + + // + // bool hasShortSignal = false; + bool isCrossedUnder = oscState.fastOSC < oscState.slowOSC && !(oscState.fastOSCPrev < oscState.slowOSCPrev); + bool hasShortSignal = false; + result.hasShortSignal = hasShortSignal; + // if (hasShortSignal) { + // canSignalShort = false; + // } + + // + bool hasSignal = hasLongSignal || hasShortSignal; + result.hasSignal = hasSignal; + + // + // Fix can Signal Long ... + //if (oscState.fastOSC >= 0 && !canSignalLong) { + // canSignalLong = true; + //} + + // + // Fix can Signal Short ... + //if (oscState.fastOSC <= 1 && !canSignalShort) { + // canSignalShort = true; + //} + + // + return result; +} + +// +// Check Ma Has Signal ... +XSignalInfo MaHasSignal( + const XMaState &maState, + const int &bar_index +) { + // + XSignalInfo result = {}; + result.hasSignal = false; + + // + // Long ... + bool isFastCrossOverSlow = maState.fastMa > maState.slowMa + && !(maState.fastMaPrev > maState.slowMaPrev); + bool hasLongSignal = isFastCrossOverSlow; + result.hasLongSignal = hasLongSignal; + + // + // Short ... + bool isFastCrossUnderSlow = maState.fastMa < maState.slowMa + && !(maState.fastMaPrev < maState.slowMaPrev); + bool hasShortSignal = isFastCrossUnderSlow; + result.hasShortSignal = hasShortSignal; + + // + bool hasSignal = hasLongSignal || hasShortSignal; + result.hasSignal = hasSignal; + + // + return result; +} + +// +// Reading Swing SL ... +XSLInfo GetSwngSL(const int &bar_index) { + // + // Temp result ... + XSLInfo result = {}; + + // + // Start Reading SL ... + // + // + // Long SL ... + double longSL = iCustom( + _Symbol, + _Period, + slIndicatorName, + slLoopback, // SL IND Inputs ... + slThrshold, // SL IND Inputs ... + 0, // Long SL Buffer Index ... + bar_index + ); + longSL = NormalizeDouble(longSL, _Digits); + result.longSL = longSL; + + // + // Short SL ... + double shortSL = iCustom( + _Symbol, + _Period, + slIndicatorName, + slLoopback, // SL IND Inputs ... + slThrshold, // SL IND Inputs ... + 1, // Short SL Buffer Index ... + bar_index + ); + shortSL = NormalizeDouble(shortSL, _Digits); + result.shortSL = shortSL; + // + // End Reading SL ... + // + + // + return result; +} + +// +// Reading TP based on SwingSL ... +XTPInfo GetTP(const int &bar_index) { + // + // Temp result ... + XTPInfo result = {}; + + // + // Start Reading TP ... + // + // + // Long TP ... + double longTP = iCustom( + _Symbol, + _Period, + tpIndicatorName, + slLoopback, // TP IND Inputs ... + slThrshold, // SL IND Inputs ... + riskToRewardRatio, // TP IND Inputs ... + 0, // Long TP Buffer Index ... + bar_index + ); + longTP = NormalizeDouble(longTP, _Digits); + result.longTP = longTP; + + // + // Short TP ... + double shortTP = iCustom( + _Symbol, + _Period, + tpIndicatorName, + slLoopback, // TP IND Inputs ... + slThrshold, // SL IND Inputs ... + riskToRewardRatio, // TP IND Inputs ... + 1, // Short TP Buffer Index ... + bar_index + ); + shortTP = NormalizeDouble(shortTP, _Digits); + result.shortTP = shortTP; + // + // End Reading TP ... + // + + // + return result; +} + +// +// Calculate Signal ... +// Default Method ... +XSignalRequest CalculateOSCSignal( + const int bar_index, + const double minimumSignalPower = 0.03, + const double minimumVarPower = 0.01 +) { + // + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_NONE; + + // + // Reading Oscillator State ... + XOSCState oscState = GetOSCState(bar_index); + + // + // Generate Signals From OSC ... + XSignalInfo signalInfo = OSCHasSignal( + oscState, + minimumSignalPower, + minimumVarPower + ); + + // + result.hasSignal = signalInfo.hasSignal; + if (!signalInfo.hasSignal) { + return result; + } + + // + // increase signal count ... + signalCount++; + + // + // increase long/short signal count ... + if (signalInfo.hasLongSignal) { + longSignalCount++; + } else if (signalInfo.hasShortSignal) { + shortSignalCount++; + } + + // + // Retrieve Open Price ... + double openPrice = iOpen(_Symbol, _Period, bar_index); + openPrice = NormalizeDouble(openPrice, _Digits); + + // + // Signal Entry Price ... + double signalEntryPrice = signalInfo.hasLongSignal ? Ask : Bid; + signalEntryPrice = NormalizeDouble(signalEntryPrice, _Digits); + + // + // Signal Time ... + datetime signalTime = iTime(_Symbol, _Period, bar_index); + + // + // Signal Type ... + X_SIGNAL_TYPE signalType = signalInfo.hasLongSignal ? X_LONG : X_SHORT; + result.type = signalType; + + // + // Reading SL ... + XSLInfo slInfo = GetSwngSL(bar_index); + + // + // Reading TP ... + XTPInfo tpInfo = GetTP(bar_index); + + // + // Generate Signal SL ... + double signalSL = signalInfo.hasLongSignal ? slInfo.longSL : slInfo.shortSL; + + // + // Generate Signal TP ... + double signalTP = signalInfo.hasLongSignal ? tpInfo.longTP : tpInfo.shortTP; + + // + // Generate XSignal Instance based on received Data ... + XSignal signal = {}; + signal.id = signalCount; + signal.sl = signalSL; + signal.tp = signalTP; + signal.time = signalTime; + signal.type = signalType; + signal.symbol = _Symbol; + // signal.openPrice = openPrice; + // signal.entryPrice = signalEntryPrice; + + // + result.signal = signal; + + // + return result; +} + +// +// Calculate Signal ... +// Method 1 ... +XSignalRequest CalculateSignal_1( + const int bar_index, + const double minimumSignalPower = 0.03, + const double minimumVarPower = 0.01 +) { + // + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_NONE; + + // + // Reading Oscillator State ... + XOSCState oscState = GetOSCState(bar_index); + + // + // Retrieve Price Action Theory based Candlestick Type ... + int pCandleType = (int) GetPCandleType(bar_index); + + // + // Generate Signals From OSC ... + XSignalInfo signalInfo = OSCHasSignal_1( + oscState, + minimumSignalPower, + minimumVarPower + ); + + // + result.hasSignal = signalInfo.hasSignal; + if (!signalInfo.hasSignal) { + return result; + } + + // + // Get Price Action Candlestick Verification on Long Signals ... + if (signalInfo.hasLongSignal) { + // + // Check current Candle Type based on Price Action Theory ... + if (pCandleType == X_P_CT_BEARISH) { + // + result.hasSignal = false; + return result; + } else if (pCandleType == X_P_CT_NEUTRAL) { + // + // Here we must loop through back bar indexes until find a + // candle which no NEUTRAL ... + int barCounter = bar_index + 1; + int prevUnNeutralPCandleType = -1; + while( + barCounter <= Bars && + prevUnNeutralPCandleType == -1 + ) { + // + int cPCType = (int) GetPCandleType(barCounter); + if (cPCType != X_P_CT_NEUTRAL) { + prevUnNeutralPCandleType = cPCType; + } else { + barCounter++; + } + } + + // + result.hasSignal = false; + if (prevUnNeutralPCandleType != X_P_CT_BULLISH) { + return result; + } + + // + result.hasSignal = true; + } + } + + // + // Get Price Action Candlestick Verification on Short Signals ... + if (signalInfo.hasShortSignal) { + // + // Check current Candle Type based on Price Action Theory ... + if (pCandleType == X_P_CT_BULLISH) { + // + result.hasSignal = false; + return result; + } else if (pCandleType == X_P_CT_NEUTRAL) { + // + // Here we must loop through back bar indexes until find a + // candle which no NEUTRAL ... + int barCounter = bar_index + 1; + int prevUnNeutralPCandleType = -1; + while( + barCounter <= Bars && + prevUnNeutralPCandleType == -1 + ) { + // + int cPCType = (int) GetPCandleType(barCounter); + if (cPCType != X_P_CT_NEUTRAL) { + prevUnNeutralPCandleType = cPCType; + } else { + barCounter++; + } + } + + // + result.hasSignal = false; + if (prevUnNeutralPCandleType != X_P_CT_BEARISH) { + return result; + } + + // + result.hasSignal = true; + } + } + + // + // increase signal count ... + signalCount++; + + // + // increase long/short signal count ... + if (signalInfo.hasLongSignal) { + longSignalCount++; + } else if (signalInfo.hasShortSignal) { + shortSignalCount++; + } + + // + // Retrieve Open Price ... + double openPrice = iOpen(_Symbol, _Period, bar_index); + openPrice = NormalizeDouble(openPrice, _Digits); + + // + // Signal Entry Price ... + RefreshRates(); + double signalEntryPrice = signalInfo.hasLongSignal ? SymbolInfoDouble(_Symbol, SYMBOL_ASK) : SymbolInfoDouble(_Symbol, SYMBOL_BID); + // signalInfo.hasLongSignal ? SymbolInfoDouble(_Symbol, SYMBOL_ASK) : SymbolInfoDouble(_Symbol, SYMBOL_BID); + signalEntryPrice = NormalizeDouble(signalEntryPrice, _Digits); + + // + // Signal Time ... + datetime signalTime = iTime(_Symbol, _Period, bar_index); + + // + // Signal Type ... + X_SIGNAL_TYPE signalType = signalInfo.hasLongSignal ? X_LONG : X_SHORT; + result.type = signalType; + + // + // Reading SL ... + XSLInfo slInfo = GetSwngSL(bar_index); + + // + // Reading TP ... + XTPInfo tpInfo = GetTP(bar_index); + + // + // Generate Signal SL ... + double signalSL = signalInfo.hasLongSignal ? slInfo.longSL : slInfo.shortSL; + + // + // Generate Signal TP ... + double signalTP = signalInfo.hasLongSignal ? tpInfo.longTP : slInfo.longSL; // tpInfo.shortTP; + + // + // Generate XSignal Instance based on received Data ... + XSignal signal = {}; + signal.id = signalCount; + signal.sl = signalSL; + signal.tp = signalTP; + signal.time = signalTime; + signal.type = signalType; + signal.symbol = _Symbol; + // signal.openPrice = openPrice; + // signal.entryPrice = signalEntryPrice; + + // + result.signal = signal; + + // + return result; +} + +// +// Calculate Signal ... +// Method 2 ... +XSignalRequest CalculateSignal_2(const int bar_index) { + // + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_NONE; + + // + // Reading Oscillator State ... + XOSCState oscState = GetOSCState(bar_index); + + // + // Generate Signals From OSC ... + XSignalInfo signalInfo = OSCHasSignal_2( + oscState, + bar_index + ); + + // + result.hasSignal = signalInfo.hasSignal; + if (!signalInfo.hasSignal) { + return result; + } + + // + // increase signal count ... + signalCount++; + + // + // increase long/short signal count ... + if (signalInfo.hasLongSignal) { + longSignalCount++; + } else if (signalInfo.hasShortSignal) { + shortSignalCount++; + } + + // + // Signal Time ... + datetime signalTime = iTime(_Symbol, _Period, bar_index); + + // + // Signal Type ... + X_SIGNAL_TYPE signalType = signalInfo.hasLongSignal ? X_LONG : X_SHORT; + result.type = signalType; + + // + // Reading SL ... + XSLInfo slInfo = GetSwngSL(bar_index); + + // + // Reading TP ... + XTPInfo tpInfo = GetTP(bar_index); + + // + // Generate Signal SL ... + double signalSL = signalInfo.hasLongSignal ? slInfo.longSL : slInfo.shortSL; + + // + // Generate Signal TP ... + double signalTP = signalInfo.hasLongSignal ? tpInfo.longTP : tpInfo.shortTP; + + // + // Generate XSignal Instance based on received Data ... + XSignal signal = {}; + signal.id = signalCount; + signal.sl = signalSL; + signal.tp = signalTP; + signal.time = signalTime; + signal.type = signalType; + signal.symbol = _Symbol; + + // + result.signal = signal; + + // + return result; +} + +// +// Calculate Signal ... +// Using Ma ... +XSignalRequest CalculateMaSignal(const int bar_index) { + // + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_NONE; + + // + // Reading Moving Average State ... + XMaState maState = GetMaState(bar_index); + + // + // Generate Signals From OSC ... + XSignalInfo signalInfo = MaHasSignal( + maState, + bar_index + ); + Print("Ma HasSignal: ", signalInfo.hasSignal); + + // + result.hasSignal = signalInfo.hasSignal; + if (!signalInfo.hasSignal) { + return result; + } + + // + // increase signal count ... + signalCount++; + + // + // increase long/short signal count ... + if (signalInfo.hasLongSignal) { + longSignalCount++; + } else if (signalInfo.hasShortSignal) { + shortSignalCount++; + } + + // + // Signal Time ... + datetime signalTime = iTime(_Symbol, _Period, bar_index); + + // + // Signal Type ... + X_SIGNAL_TYPE signalType = signalInfo.hasLongSignal ? X_LONG : X_SHORT; + result.type = signalType; + + // + // Reading SL ... + XSLInfo slInfo = GetSwngSL(bar_index); + + // + // Reading TP ... + XTPInfo tpInfo = GetTP(bar_index); + + // + // Generate Signal SL ... + double signalSL = signalInfo.hasLongSignal ? slInfo.longSL : slInfo.shortSL; + + // + // Generate Signal TP ... + double signalTP = signalInfo.hasLongSignal ? tpInfo.longTP : tpInfo.shortTP; + + // + // Generate XSignal Instance based on received Data ... + XSignal signal = {}; + signal.id = signalCount; + signal.sl = signalSL; + signal.tp = signalTP; + signal.time = signalTime; + signal.type = signalType; + signal.symbol = _Symbol; + + // + result.signal = signal; + + // + return result; +} + +// +// Count Open Positions ... +int CountOpenPositions() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if (OrderSymbol() == _Symbol) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Handle Trading On Signals ... +void TradeOnSignal( + const XSignal &signal, + double tradeVolume = 0.1, + string signalTag = "X-Signal", + string longSignalLabel = "X-Long", + color longSignalColor = clrLime, + string shortSignalLabel = "X-Short", + color shortSignalColor = clrRed +) { + // + // Start Genearting required data ... + // + // + // START implementing Money Management ... + // + if (tradeCount == 0) { + // + initialBalance = AccountBalance(); + + // + string msg = StringConcatenate("Initial Account Balance: ", initialBalance); + LogMessage(msg); + } + + // + // Retrieve current Account balance + double currentBalance = AccountBalance(); + if (currentBalance < initialBalance / 2) { + // + string msg = StringConcatenate("Account Balance less than minimum allowed, trading off ..."); + LogMessage(msg); + + // + return; + } + // + // END implementing Money Management ... + // + + // + // Detect Trade is Long or Short ... + bool isLongSignal = signal.type == X_LONG; + + // + // Generate Trade Comment ... + string tradeComment = GenerateSignalTAG( + signal, + signalTag, + longSignalLabel, + shortSignalLabel + ); + + // + // Detect Trade Operation ... + int tradeOperation = isLongSignal ? OP_BUY : OP_SELL; + + // + // Detect Trade Color ... + color tradeColor = isLongSignal ? longSignalColor : shortSignalColor; + // + // End Genearting required data ... + // + + // + double price = 0; + double closePrice = 0; + double priceGap = 0; + double tp = 0; + double sl = 0; + + // + RefreshRates(); + + // + // Calculating Open, SL, TP for Positions ... + if (isLongSignal) { + // + // Long Positions ... + + // + // Prices ... + price = SymbolInfoDouble(_Symbol, SYMBOL_ASK); + closePrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); + + // + priceGap = closePrice - price; + + // + // SL ... + if (signal.sl > 0) { + sl = signal.sl + priceGap; + } + + // + // TP ... + if (signal.tp > 0) { + tp = signal.tp - priceGap; + } + } else { + // + // Short Positions ... + + // + // Prices ... + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + closePrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // SL ... + if (signal.sl > 0) { + sl = signal.sl - priceGap; + } + + // + // TP ... + if (signal.tp > 0) { + tp = signal.tp + priceGap; + } + } + + // + // Ignore last TP and SL Calculation and Use Default ... + // sl = signal.sl; + // tp = signal.tp; + + // + // Normalize Prices ... + price = NormalizeDouble(price, _Digits); + sl = NormalizeDouble(sl, _Digits); + tp = NormalizeDouble(tp, _Digits); + + // + // Define Trade Variables ... + double slGap = SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL) * _Point; + + // + // Price Check ... + if (price == 0) { + return; + } + + // + // Prevent Open Trading when price doesn't fill slGap ...' + if (signal.sl > 0 && signal.sl < slGap) { + return; + } + + // + // Prevent Open Trading when price doesn't fill slGap ...' + if (signal.tp > 0 && signal.tp < slGap) { + return; + } + + // + // Fix Signal SL and Price Same issue ... + if (price == sl || MathAbs(price - sl) <= slGap) { + // + // string msg = StringConcatenate("id: ", signal.id , ", Price: ", price, ", sl: ", sl); + // LogMessage(msg); + + // + return; + } + + // + // Placing Order ... + int orderTicket = OrderSend( + signal.symbol, + tradeOperation, + tradeVolume, + price, + 3, + sl, + tp, + tradeComment, + (int)signal.id, + 0, + tradeColor + ); + + // + if (orderTicket >= 0) { + tradeCount++; + } +} + +// +// Draw Signal Shapes on Chart ... +bool DrawSignalShape( + const XSignal &signal, + long chartID = 0, + int subWindowID = 0, + const double positionThresholdFactor = 10, + string signalTag = "X-Signal", + string longSignalLabel = "X-Long", + color longSignalColor = clrAqua, + string shortSignalLabel = "X-Short", + color shortSignalColor = clrFuchsia +) { + // + // Generate isLongSignal Var ... + bool isLongSignal = signal.type == X_LONG; + + // + // Signal Bar Index ... + int bar_index = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // START Draw Signal Arrow ... + // + // + // Arrow Shape Name ... + string arrowName = StringConcatenate(signalTag, "_Arrow_", signal.id); + + // + // Arrow Price ... + double arrowPrice = 0; + if (isLongSignal) { + // + arrowPrice = iLow( + _Symbol, + _Period, + bar_index + ); + + // + arrowPrice = arrowPrice - (positionThresholdFactor * _Point); + } else { + // + arrowPrice = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + arrowPrice = arrowPrice + (positionThresholdFactor * _Point); + } + + // + // Arrow Code ... + uchar arrowCode = isLongSignal ? SYMBOL_ARROWUP : SYMBOL_ARROWDOWN; + + // + // Arrow Anchor Point ... + ENUM_ARROW_ANCHOR arrowAnchorPoint = isLongSignal ? ANCHOR_BOTTOM : ANCHOR_TOP; + + // + // Arrow Color ... + color arrowColor = isLongSignal ? longSignalColor : shortSignalColor; + + // + // Draw Signal Arrow Shape ... + bool result = DrawArrow( + chartID, + arrowName, + subWindowID, + signal.time, + arrowPrice, + arrowCode, + arrowAnchorPoint, + arrowColor, + STYLE_SOLID, + 3, + false, + false, + false, + 0 + ); + // + // END Draw Signal Arrow ... + // + + // + // START Draw Signal SL/TP ... + // + string slLineName = StringConcatenate(signalTag, "_SL_", signal.id); + string tpLineName = StringConcatenate(signalTag, "_TP_", signal.id); + + // + color slColor = isLongSignal ? shortSignalColor : longSignalColor; + + // + datetime time1 = iTime( + _Symbol, + _Period, + bar_index + 1 + ); + + // + // Draw Signal SL ... + result = DrawTrendLine( + chartID, + slLineName, + subWindowID, + time1, + signal.sl, + signal.time, + signal.sl, + slColor, + STYLE_SOLID, + 2 + ); + + // + // Draw Signal TP ... + result = DrawTrendLine( + chartID, + tpLineName, + subWindowID, + time1, + signal.tp, + signal.time, + signal.tp, + arrowColor, + STYLE_SOLID, + 2 + ); + // + // END Draw Signal SL/TP ... + // + + // + // Start Draw Signal Label ... + // + // + string labelName = StringConcatenate(signalTag, "_Label_", signal.id); + + // + double labelPrice = isLongSignal ? arrowPrice - (positionThresholdFactor * _Point) : arrowPrice + (positionThresholdFactor * _Point); + + // + string labelText = isLongSignal ? longSignalLabel : shortSignalLabel; + + // + result = DrawText( + chartID, + labelName, + subWindowID, + signal.time, + labelPrice, + labelText, + "Arial", + 10, + arrowColor, + 0, + ANCHOR_CENTER + ); + // + // End Draw Signal Label ... + // + + // + return result; +} +// +// End Signal Functions ... +// diff --git a/Bkp/UnUsed/Libs/x-saherelm.xma.models.lib.mq4 b/Bkp/UnUsed/Libs/x-saherelm.xma.models.lib.mq4 new file mode 100644 index 0000000..cc7b803 --- /dev/null +++ b/Bkp/UnUsed/Libs/x-saherelm.xma.models.lib.mq4 @@ -0,0 +1,138 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Models Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Start Models ... +// + +// +// Used Indicators List ... +const string xmaIndicatorName = "x-saherelm.xma"; + +// +// these are different signal types ... +enum X_SIGNAL_TYPE { + X_NONE, + X_LONG, + X_SHORT, +}; + +// +// we Model each signals as this type ... +struct XSignal { + int id; + X_SIGNAL_TYPE type; + double tp; + double sl; + string symbol; + datetime time; + double entryPrice; +}; + +// +// this is Signal Request Response model ... +struct XSignalRequest { + bool hasSignal; + X_SIGNAL_TYPE type; + XSignal signal; +}; + +// +// Define a Model to Represent Snapshot of XMA Indicator ... +struct XMAState { + // + // Short Cycle ... + // + // FAST ... + double scFast; + double scFastPrev; + + // + // SLOW ... + double scSlow; + double scSlowPrev; + + // + bool isSCTrendUp; + bool isSCTrendDown; + bool isSCFastCrossOverSlow; + bool isSCFastCrossUnderSlow; + + // + // Medium Cycle ... + // + // FAST ... + double mcFast; + double mcFastPrev; + + // + // SLOW ... + double mcSlow; + double mcSlowPrev; + + // + bool isMCTrendUp; + bool isMCTrendDown; + bool isMCFastCrossOverSlow; + bool isMCFastCrossUnderSlow; + + // + // Long Cycle ... + // + // FAST ... + double lcFast; + double lcFastPrev; + + // + // SLOW ... + double lcSlow; + double lcSlowPrev; + + // + bool isLCTrendUp; + bool isLCTrendDown; + bool isLCFastCrossOverSlow; + bool isLCFastCrossUnderSlow; + + // + // MIDDLEAGE ... + double marketMiddleage; + double marketMiddleagePrev; + + // + // Hot Cross Points ... + // + bool isHotCrossOver; + bool isHottestCrossOver; + + // + bool isHotCrossUnder; + bool isHottestCrossUnder; + + // + // Signal ... + bool hasSignal; + bool hasLongSignal; + bool hasShortSignal; + + // + XSignal signal; +}; +// +// End Models ... +// diff --git a/Bkp/UnUsed/Libs/x-saherelm.xma.signal.lib.mq4 b/Bkp/UnUsed/Libs/x-saherelm.xma.signal.lib.mq4 new file mode 100644 index 0000000..1e016b1 --- /dev/null +++ b/Bkp/UnUsed/Libs/x-saherelm.xma.signal.lib.mq4 @@ -0,0 +1,1855 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 XMA Signal Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.xma.models.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +// START Global Requirement Functions ... +// +static int totalSignals = 0; +static int totalLongSignals = 0; +static int totalShortSignals = 0; + +// +static double initialBalance = 0; + +// +static double scTrendPower[]; +static double scMinTrendPower = -1; +static double scMaxTrendPower = -1; +static datetime shortMarketCrossPointsTime[]; + +// +static double mcTrendPower[]; +static double mcMaxTrendPower = -1; +static double mcMinTrendPower = -1; +static datetime mediumMarketCrossPointsTime[]; + +// +static double lcTrendPower[]; +static double lcMaxTrendPower = -1; +static double lcMinTrendPower = -1; +static datetime longMarketCrossPointsTime[]; + +// +static double minMidInSC = -1; +static double maxMidInSC = -1; + + +// +// +// Retrieve and Calculate XMA State ... +XMAState GetXMAState( + const int bar_index, // Bar Index ... + // + // Market Length ... + const int marketLen, // Market Length ... + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + const int scFastMul, // Short Cycle Fast Multiplier ... + const int scSlowMul, // Short Cycle Slow Multiplier ... + const int mcFastMul, // Medium Cycle Fast Multiplier ... + const int mcSlowMul, // Medium Cycle Slow Multiplier ... + const int lcFastMul, // Long Cycle Fast Multiplier ... + const int lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + const bool showSC, // Show Short Cycle + const bool showSCCrossLines, // Show Short Cycle Vertical Lines + const bool showMC, // Show Medium Cycle + const bool showMCCrossLines, // Show Medium Cycle Vertical Lines + const bool showLC, // Show Long Cycle + const bool showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + const color sxFastColor, // Short Cycle Fast Color ... + const color scSlowColor, // Short Cycle Slow Color ... + const color mcFastColor, // Medium Cycle Fast Color ... + const color mcSlowColor, // Medium Cycle Slow Color ... + const color lcFastColor, // Medium Cycle Fast Color ... + const color lcSlowColor // Medium Cycle Slow Color ... +) { + // + // Temp Result ... + XMAState result = {}; + + // + // START Reading Buffers ... + // + // + // Define BufferIndexes ... + int scFastBufIndex = 0; + int scSlowBufIndex = 1; + int mcFastBufIndex = 2; + int mcSlowBufIndex = 3; + int lcFastBufIndex = 4; + int lcSlowBufIndex = 5; + int midBufIndex = 6; + + // + // START Short Cycle ... + // + // + // Short Cycle Fast ... + double scFast = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + scFastBufIndex, // Buffer Index ... + bar_index + ); + result.scFast = scFast; + + // + // Short Cycle Previous Fast ... + double scFastPrev = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + scFastBufIndex, // Buffer Index ... + bar_index + 1 + ); + result.scFastPrev = scFastPrev; + + // + // Short Cycle Slow ... + double scSlow = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + scSlowBufIndex, // Buffer Index ... + bar_index + ); + result.scSlow = scSlow; + + // + // Short Cycle Previous Slow ... + double scSlowPrev = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + scSlowBufIndex, // Buffer Index ... + bar_index + 1 + ); + result.scSlowPrev = scSlowPrev; + // + // END Short Cycle ... + // + + // + // START Medium Cycle ... + // + // + // Medium Cycle Fast ... + double mcFast = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + mcFastBufIndex, // Buffer Index ... + bar_index + ); + result.mcFast = mcFast; + + // + // Medium Cycle Previous Fast ... + double mcFastPrev = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + mcFastBufIndex, // Buffer Index ... + bar_index + 1 + ); + result.mcFastPrev = mcFastPrev; + + // + // Medium Cycle Slow ... + double mcSlow = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + mcSlowBufIndex, // Buffer Index ... + bar_index + ); + result.mcSlow = mcSlow; + + // + // Medium Cycle Previous Slow ... + double mcSlowPrev = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + mcSlowBufIndex, // Buffer Index ... + bar_index + 1 + ); + result.mcSlowPrev = mcSlowPrev; + // + // END Medium Cycle ... + // + + // + // START Long Cycle ... + // + // + // Long Cycle Fast ... + double lcFast = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + lcFastBufIndex, // Buffer Index ... + bar_index + ); + result.lcFast = lcFast; + + // + // Long Cycle Previous Fast ... + double lcFastPrev = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + lcFastBufIndex, // Buffer Index ... + bar_index + 1 + ); + result.lcFastPrev = lcFastPrev; + + // + // Long Cycle Slow ... + double lcSlow = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + lcSlowBufIndex, // Buffer Index ... + bar_index + ); + result.lcSlow = lcSlow; + + // + // Long Cycle Previous Slow ... + double lcSlowPrev = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + lcSlowBufIndex, // Buffer Index ... + bar_index + 1 + ); + result.lcSlowPrev = lcSlowPrev; + // + // END Long Cycle ... + // + + // + // START Makret Middleage ... + // + // + // Market Middleage ... + double marketMiddleage = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + midBufIndex, // Buffer Index ... + bar_index + ); + result.marketMiddleage = marketMiddleage; + + // + // Previous Market Middleage ... + double marketMiddleagePrev = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + midBufIndex, // Buffer Index ... + bar_index + 1 + ); + result.marketMiddleagePrev = marketMiddleagePrev; + // + // END Makret Middleage ... + // + // + // END Reading Buffers ... + // + + // + // START Calculating ... + // + // + datetime currentTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Short Cycle ... + bool isSCFastCrossOverSlow = scFast > scSlow + && !(scFastPrev > scSlowPrev); + result.isSCFastCrossOverSlow = isSCFastCrossOverSlow; + + // + bool isSCFastCrossUnderSlow = scFast < scSlow + && !(scFastPrev < scSlowPrev); + result.isSCFastCrossUnderSlow = isSCFastCrossUnderSlow; + + // + bool isSCTrendUp = scFast > scSlow && + scFastPrev > scSlowPrev; + result.isSCTrendUp = isSCTrendUp; + + // + bool isSCTrendDown = !isSCTrendUp + && scFast < scSlow + && scFastPrev < scSlowPrev; + result.isSCTrendDown = isSCTrendDown; + + // + // Fill Cycle Min/Max Trend Powers ... + double scTrendPowerCurrent = MathAbs(scFast - scSlow); + ArrayResize( + scTrendPower, + ArraySize(scTrendPower) + 1 + ); + scTrendPower[0] = scTrendPowerCurrent; + if (scTrendPowerCurrent > scMaxTrendPower) { + scMaxTrendPower = scTrendPowerCurrent; + } + if ( + scMinTrendPower < 0 || + scTrendPowerCurrent < scMinTrendPower) { + scMinTrendPower = scTrendPowerCurrent; + } + + // + // Fill Time Series ... + if ( + isSCFastCrossOverSlow + || isSCFastCrossUnderSlow + ) { + // + // Increase Array Size ... + ArrayResize( + shortMarketCrossPointsTime, + ArraySize(shortMarketCrossPointsTime) + 1 + ); + + // + shortMarketCrossPointsTime[0] = currentTime; + + // + scMinTrendPower = -1; + scMaxTrendPower = -1; + } + + // + // Medium Cycle ... + bool isMCFastCrossOverSlow = mcFast > mcSlow + && !(mcFastPrev > mcSlowPrev); + result.isMCFastCrossOverSlow = isMCFastCrossOverSlow; + + // + bool isMCFastCrossUnderSlow = mcFast < mcSlow + && !(mcFastPrev < mcSlowPrev); + result.isMCFastCrossUnderSlow = isMCFastCrossUnderSlow; + + // + bool isMCTrendUp = mcFast > mcSlow && + mcFastPrev > mcSlowPrev; + result.isMCTrendUp = isMCTrendUp; + + // + bool isMCTrendDown = !isMCTrendUp + && mcFast < mcSlow + && mcFastPrev < mcSlowPrev; + result.isMCTrendDown = isMCTrendDown; + + // + // Fill Cycle Min/Max Trend Powers ... + double mcTrendPowerCurrent = MathAbs(mcFast - mcSlow); + ArrayResize( + mcTrendPower, + ArraySize(mcTrendPower) + 1 + ); + mcTrendPower[bar_index] = mcTrendPowerCurrent; + if (mcTrendPowerCurrent > mcMaxTrendPower) { + mcMaxTrendPower = mcTrendPowerCurrent; + } + if ( + mcMinTrendPower < 0 || + mcTrendPowerCurrent < mcMinTrendPower) { + mcMinTrendPower = mcTrendPowerCurrent; + } + + // + // Fill Time Series ... + if ( + isMCFastCrossOverSlow + || isMCFastCrossUnderSlow + ) { + // + // Increase Array Size ... + ArrayResize( + mediumMarketCrossPointsTime, + ArraySize(mediumMarketCrossPointsTime) + 1 + ); + + // + mediumMarketCrossPointsTime[0] = currentTime; + + // + mcMinTrendPower = -1; + mcMaxTrendPower = -1; + } + + // + // Long Cycle ... + bool isLCFastCrossOverSlow = lcFast > lcSlow + && !(lcFastPrev > lcSlowPrev); + result.isLCFastCrossOverSlow = isLCFastCrossOverSlow; + + // + bool isLCFastCrossUnderSlow = lcFast < lcSlow + && !(lcFastPrev < lcSlowPrev); + result.isLCFastCrossUnderSlow = isLCFastCrossUnderSlow; + + // + bool isLCTrendUp = lcFast > lcSlow && + lcFastPrev > lcSlowPrev; + result.isLCTrendUp = isLCTrendUp; + + // + bool isLCTrendDown = !isLCTrendUp + && lcFast < lcSlow + && lcFastPrev < lcSlowPrev; + result.isLCTrendDown = isLCTrendDown; + + // + // Fill Cycle Min/Max Trend Powers ... + double lcTrendPowerCurrent = MathAbs(mcFast - mcSlow); + ArrayResize( + lcTrendPower, + ArraySize(lcTrendPower) + 1 + ); + lcTrendPower[bar_index] = lcTrendPowerCurrent; + if (lcTrendPowerCurrent > lcMaxTrendPower) { + lcMaxTrendPower = lcTrendPowerCurrent; + } + if ( + lcMinTrendPower < 0 || + lcTrendPowerCurrent < lcMinTrendPower) { + lcMinTrendPower = lcTrendPowerCurrent; + } + + // + // Fill Time Series ... + if ( + isLCFastCrossOverSlow + || isLCFastCrossUnderSlow + ) { + // + // Increase Array Size ... + ArrayResize( + longMarketCrossPointsTime, + ArraySize(longMarketCrossPointsTime) + 1 + ); + + // + longMarketCrossPointsTime[0] = currentTime; + + // + lcMinTrendPower = -1; + lcMaxTrendPower = -1; + } + + // + // Reset MinMid and MaxMid ... + if ( + isSCFastCrossOverSlow || + isSCFastCrossUnderSlow + ) { + // + minMidInSC = -1; + maxMidInSC = -1; + } + + // + // Find Hottest Area ... + // + bool isHottestCrossOver = isSCFastCrossOverSlow + && isMCFastCrossOverSlow + && isLCFastCrossOverSlow; + result.isHottestCrossOver = isHottestCrossOver; + + // + bool isHotCrossOver = !isHottestCrossOver + && isSCFastCrossOverSlow + && isMCFastCrossOverSlow; + result.isHotCrossOver = isHotCrossOver; + + // + bool isHottestCrossUnder = isSCFastCrossUnderSlow + && isMCFastCrossUnderSlow + && isLCFastCrossUnderSlow; + result.isHottestCrossUnder = isHottestCrossUnder; + + // + bool isHotCrossUnder = !isHottestCrossUnder + && isMCFastCrossUnderSlow + && isLCFastCrossUnderSlow; + result.isHotCrossUnder = isHotCrossUnder; + // + // END Calculating ... + // + + // + // START Calculate Signal ... + // + // + // Long: + // Entry: + // - prev candle open below Mid line ... + // - current candle price above Mid Line ... + // SL: + // - prev candle High ... + // Exit: + // - r2r 1.5 + // - close < mid ... + + // + // Short: + // Entry: + // - prev candle open above Mid Line ... + // - current candle price below Mid Line + // SL: + // - prev candle Low ... + // Exit: + // - r2r 1.5 + // - close > mid + // + RefreshRates(); + + // + double prevCandleOpen = iOpen( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double prevCandleHigh = iHigh( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double prevCandleLow = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + // LONG Prices ... + double longEntryPrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK); + double longClosePrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); + double longPriceGap = longClosePrice - longEntryPrice; + + // + // SHORT Prices ... + double shortEntryPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); + double shortClosePrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK); + double shortPriceGap = shortEntryPrice - shortClosePrice; + + // + bool hasLongSignal = + true + && isSCTrendDown + && marketMiddleage > minMidInSC + && prevCandleOpen < marketMiddleage + && longEntryPrice > marketMiddleage + ; + result.hasLongSignal = hasLongSignal; + + // + bool hasShortSignal = + true + && isSCTrendUp + && marketMiddleage < maxMidInSC + && prevCandleOpen > marketMiddleage + && shortEntryPrice < marketMiddleage; + result.hasShortSignal = hasShortSignal; + + // + bool hasSignal = hasLongSignal || hasShortSignal; + result.hasSignal = hasSignal; + // + // END Calculate Signal ... + // + + // + return result; +} +// +// END Global Requirement Functions ... +// + +// +// START Signal Related Functions ... +// +// +// Calculate Signal ... +// in this function we calculate a signal exists in +// specific bar or not ... +XSignalRequest CalculateSignal( + const int bar_index, // Bar Index ... + // + // Market Length ... + const int marketLen, // Market Length ... + // + // Risk To Reward Ratio ... + const double r2r, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + const int scFastMul, // Short Cycle Fast Multiplier ... + const int scSlowMul, // Short Cycle Slow Multiplier ... + const int mcFastMul, // Medium Cycle Fast Multiplier ... + const int mcSlowMul, // Medium Cycle Slow Multiplier ... + const int lcFastMul, // Long Cycle Fast Multiplier ... + const int lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + const bool showSC, // Show Short Cycle + const bool showSCCrossLines, // Show Short Cycle Vertical Lines + const bool showMC, // Show Medium Cycle + const bool showMCCrossLines, // Show Medium Cycle Vertical Lines + const bool showLC, // Show Long Cycle + const bool showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + const color sxFastColor, // Short Cycle Fast Color ... + const color scSlowColor, // Short Cycle Slow Color ... + const color mcFastColor, // Medium Cycle Fast Color ... + const color mcSlowColor, // Medium Cycle Slow Color ... + const color lcFastColor, // Medium Cycle Fast Color ... + const color lcSlowColor // Medium Cycle Slow Color ... +) { + // + // create temp result ... + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_NONE; + + // + XSignal signal = {}; + + // + // Get Fully XMA Indicator State ... + XMAState state = GetXMAState( + // + // Bar Index ... + bar_index, // Bar Index ... + // + // Market Length ... + marketLen, // Market Length ... + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor // Medium Cycle Slow Color ... + ); + + // + if (!state.hasSignal) { + // + result.signal = signal; + return result; + } + + // + totalSignals++; + + // + // Define Price Related Variables ... + // + double price = 0; + double priceGap; + double sl = 0; + double risk; + double reward; + double tp = 0; + double xmaRiskToReward = r2r; + datetime time = iTime( + _Symbol, + _Period, + bar_index + ); + + // + RefreshRates(); + + // + double prevCandleOpen = iOpen( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double prevCandleHigh = iHigh( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double prevCandleLow = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + // LONG Prices ... + double longEntryPrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK); + double longClosePrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); + double longPriceGap = longClosePrice - longEntryPrice; + + // + // SHORT Prices ... + double shortEntryPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); + double shortClosePrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK); + double shortPriceGap = shortEntryPrice - shortClosePrice; + + // + // Fill Signal Related Variables ... + if (state.hasLongSignal) { + // + totalLongSignals++; + + // + price = longEntryPrice; + priceGap = longPriceGap; + + // + sl = prevCandleLow; + + // + risk = price - sl; + reward = risk * xmaRiskToReward; + tp = price + reward; + } else if (state.hasShortSignal) { + // + totalShortSignals++; + + // + price = shortEntryPrice; + priceGap = shortPriceGap; + + // + sl = prevCandleHigh; + + // + risk = sl - price; + reward = risk * xmaRiskToReward; + tp = price - reward; + } + + // + // Normalize Prices ... + price = NormalizeDouble(price, _Digits); + sl = NormalizeDouble(sl, _Digits); + tp = NormalizeDouble(tp, _Digits); + + // + // Generate Signal Structure ... + signal.type = state.hasLongSignal ? + X_LONG : + X_SHORT; + signal.tp = tp; + signal.sl = 0; // sl; + signal.time = time; + signal.symbol = _Symbol; + signal.entryPrice = price; + signal.id = totalLongSignals; + + // + // Fill Result ... + result.hasSignal = state.hasSignal; + result.signal = signal; + result.type = signal.type; + + // + return result; +} + +// +// Retrieve Signal Bar Index ... +int GetSignalBarIndex(XSignal &signal) { + // + // Temp Result ... + int result = -1; + + // + // Retriev Signal Bar Index ... + result = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + return result; +} + +// +// Generate a Unique ID for Signal ... +string GenerateSignalTAG( + const XSignal &signal, + const string tag, + const string longSignalLabel, + const string shortSignalLabel +) { + // + // Generate Propper Label for Signal ... + string label = signal.type == X_LONG ? longSignalLabel : signal.type == X_SHORT ? shortSignalLabel : "UN_KNOWN"; + + // + // Generate Unique String Identifier for Signal ... + string result = tag + + "_[ID:" + IntegerToString(signal.id) + "]" + + "_[" + label + "]" + + "_[" + signal.symbol + "]" + + "_[Time:" + TimeToStr(signal.time) + "]" + + "_[TP:" + DoubleToString(signal.tp) + "]" + + "_[SL:" + DoubleToString(signal.sl) + "]"; + + // + return result; +} + +// +// Draw Signal Shapes on Chart ... +bool DrawSignal( + const XSignal &signal, + long chartID = 0, + int subWindowID = 0, + const double positionThresholdFactor = 10, + string signalTag = "X-Signal", + string longSignalLabel = "X-Long", + color longSignalColor = clrAqua, + string shortSignalLabel = "X-Short", + color shortSignalColor = clrFuchsia +) { + // + // Generate isLongSignal Var ... + bool isLongSignal = signal.type == X_LONG; + + // + // Signal Bar Index ... + int bar_index = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // START Draw Signal Arrow ... + // + // + // Arrow Shape Name ... + string arrowName = StringConcatenate(signalTag, "_Arrow_", signal.id); + + // + // Arrow Price ... + double arrowPrice = 0; + if (isLongSignal) { + // + arrowPrice = iLow( + _Symbol, + _Period, + bar_index + ); + + // + arrowPrice = arrowPrice - (positionThresholdFactor * _Point); + } else { + // + arrowPrice = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + arrowPrice = arrowPrice + (positionThresholdFactor * _Point); + } + + // + // Arrow Code ... + uchar arrowCode = isLongSignal ? SYMBOL_ARROWUP : SYMBOL_ARROWDOWN; + + // + // Arrow Anchor Point ... + ENUM_ARROW_ANCHOR arrowAnchorPoint = isLongSignal ? ANCHOR_BOTTOM : ANCHOR_TOP; + + // + // Arrow Color ... + color arrowColor = isLongSignal ? longSignalColor : shortSignalColor; + + // + // Draw Signal Arrow Shape ... + bool result = DrawArrow( + chartID, + arrowName, + subWindowID, + signal.time, + arrowPrice, + arrowCode, + arrowAnchorPoint, + arrowColor, + STYLE_SOLID, + 3, + false, + false, + false, + 0 + ); + // + // END Draw Signal Arrow ... + // + + // + // START Draw Signal SL/TP ... + // + string slLineName = StringConcatenate(signalTag, "_SL_", signal.id); + string tpLineName = StringConcatenate(signalTag, "_TP_", signal.id); + string entryLineName = StringConcatenate(signalTag, "_ENTRY_", signal.id); + + // + color slColor = shortSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color tpColor = longSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color entryColor = clrGreen; + + // + datetime time1 = iTime( + _Symbol, + _Period, + bar_index + 1 + ); + + // + // Draw Enrty Price ... + result = DrawTrendLine( + chartID, + entryLineName, + subWindowID, + time1, + signal.entryPrice, + signal.time, + signal.entryPrice, + entryColor, + STYLE_SOLID, + 2 + ); + + // + // Draw Signal SL ... + if (signal.sl > 0) { + // + result = DrawTrendLine( + chartID, + slLineName, + subWindowID, + time1, + signal.sl, + signal.time, + signal.sl, + slColor, + STYLE_SOLID, + 2 + ); + } + + // + // Draw Signal TP ... + if (signal.tp > 0) { + // + result = DrawTrendLine( + chartID, + tpLineName, + subWindowID, + time1, + signal.tp, + signal.time, + signal.tp, + tpColor, + STYLE_SOLID, + 2 + ); + } + // + // END Draw Signal SL/TP ... + // + + // + // Start Draw Signal Label ... + // + // + string labelName = StringConcatenate(signalTag, "_Label_", signal.id); + + // + double labelPrice = isLongSignal ? arrowPrice - (positionThresholdFactor * _Point) : arrowPrice + (positionThresholdFactor * _Point); + + // + string labelText = isLongSignal ? longSignalLabel : shortSignalLabel; + + // + result = DrawText( + chartID, + labelName, + subWindowID, + signal.time, + labelPrice, + labelText, + "Arial", + 10, + arrowColor, + 0, + ANCHOR_CENTER + ); + // + // End Draw Signal Label ... + // + + // + return result; +} + +// +// Trade on Specific Signal ... +bool TradeSignal( + XSignal &signal, + // + string prefix, + // + double volumePercent, + // + // Long ... + const string longSignalLabel, + const color longSignalColor, + // + // Short ... + const string shortSignalLabel, + const color shortSignalColor +) { + // + // Temp Result ... + bool result = false; + + // + if (initialBalance == 0) { + initialBalance = AccountInfoDouble(ACCOUNT_BALANCE); + } + + // + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + int openPositions = CountOpenTrades(); + double volume = (volumePercent * initialBalance); + // openPositions == 0 ? + // (volumePercent * balance) : + // (volumePercent * initialBalance); + + // + if ( + signal.type != X_LONG && + signal.type != X_SHORT + ) { + return result; + } + + // + bool hasLongSignal = signal.type == X_LONG; + + // + // Check TP and Entry Price ... + if ( + ( + hasLongSignal + && signal.entryPrice > signal.tp + ) || + ( + !hasLongSignal + && signal.entryPrice < signal.tp + ) + ) { + return result; + } + + // + // Order Operation ... + int operation = hasLongSignal ? + OP_BUY : + OP_SELL; + + // + // Detect Trade Color ... + color clr = hasLongSignal ? + longSignalColor : + shortSignalColor; + + // + // Generate Signal Comment ... + string label = hasLongSignal ? + longSignalLabel : + shortSignalLabel; + + // + // Generate Signal Comment ... + string comment = StringConcatenate( + prefix, + "_", signal.id, "_", + label + ); + + // + // Placing Order ... + int orderTicket = OrderSend( + _Symbol, + operation, + volume, + signal.entryPrice, + 3, + signal.sl, + signal.tp, + comment, + signal.id, + 0, + clr + ); + + // + // Draw Signal Shape if Order Opened Successfully ... + if (orderTicket >= 0) { + // + // Here i must to Draw Signal Shapes ... + DrawSignal( + signal, + 0, + 0, + 50, + prefix, // Signal Tag ... + longSignalLabel, // Long Signal Label ... + longSignalColor, + shortSignalLabel, // Short Signal Label ... + shortSignalColor + ); + + // + result = true; + } + + // + return result; +} +// +// END Signal Related Functions ... +// + +// +// START Orders Functions ... +// + +// +// Convert To XSignal Model ... +XSignal OrderToSignal() { + // + // Temp Result ... + XSignal result = {}; + result.type = X_NONE; + + // + // Here we can get some usefull info based on selected order ... + double swap = OrderSwap(); + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + int magicNumber = OrderMagicNumber(); + double takeProfit = OrderTakeProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // Conver Position to Signal ... + result.sl = stopLoss; + result.tp = takeProfit; + result.time = openTime; + result.symbol = _Symbol; + result.id = magicNumber; + result.entryPrice = openPrice; + result.type = isLongOrder ? X_LONG : X_SHORT; + + // + return result; +} + +// +// START Count Orders ... +// +// +// Count Open Positions ... +int CountOpenTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if (OrderSymbol() == _Symbol) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Long Positions ... +int CountOpenLongTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_BUY + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Short Positions ... +int CountOpenShortTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_SELL + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} +// +// END Count Orders ... +// + +// +// START Close Orders ... +// +// +// Close All Open Trades ... +void CloseAllTrades() { + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + } + } + } +} + +// +// Close All Open Long Trades ... +void CloseAllLongTrades() { + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + } + } + } + } +} + +// +// Close All Open Short Trades ... +void CloseAllShortTrades() { + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (!isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + } + } + } + } +} +// +// END Close Orders ... +// +// +// END Orders Functions ... +// diff --git a/Bkp/UnUsed/Libs/x-saherelm.xmma.models.lib.mq4 b/Bkp/UnUsed/Libs/x-saherelm.xmma.models.lib.mq4 new file mode 100644 index 0000000..c8081d9 --- /dev/null +++ b/Bkp/UnUsed/Libs/x-saherelm.xmma.models.lib.mq4 @@ -0,0 +1,84 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XMMA Models Library +// --------------------------------------------- +// contains all data model definitions related to +// an specific Indicator/Oscillator/Expert ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property description "SaherElm XMMA Models Library" +#property strict + +// +// START Models ... +// + +// +// Used Indicators List ... +const string xmmaIndicatorName = "x-saherelm.xmma"; + +// +// these are different signal types ... +enum X_SIGNAL_TYPE { + X_NONE, + X_LONG, + X_SHORT, +}; + +// +// we Model each signals as this type ... +struct XSignal { + int id; + X_SIGNAL_TYPE type; + double tp; + double sl; + string symbol; + datetime time; + double entryPrice; +}; + +// +// this is Signal Request Response model ... +struct XSignalRequest { + bool hasSignal; + X_SIGNAL_TYPE type; + XSignal signal; +}; + +// +struct XMMAState { + // + double fast; + double fastPrev; + + // + double slow; + double slowPrev; + + // + double mid; + + // + double longSL; + double shortSL; + + // + bool isCrossOver; + bool isCrossUnder; + + // + bool isTrendUp; + bool isTrendDown; +}; +// +// END Models ... +// diff --git a/Bkp/UnUsed/Libs/x-saherelm.xmma.signal.lib.mq4 b/Bkp/UnUsed/Libs/x-saherelm.xmma.signal.lib.mq4 new file mode 100644 index 0000000..5dc36a7 --- /dev/null +++ b/Bkp/UnUsed/Libs/x-saherelm.xmma.signal.lib.mq4 @@ -0,0 +1,1045 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XMMA Signalling Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property description "SaherElm XMMA Signalling Librarie" +#property strict + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.xmma.models.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +// START Global Requirement Functions ... +// +static int totalSignals = 0; +static int totalLongSignals = 0; +static int totalShortSignals = 0; + +// +static double initialBalance = 0; + +// +XMMAState GetXMMAState( + const int bar_index, + const int mLen, // Market Length ... + const int fShift, // Fast Shift ... + const int sShift // Shift Shift ... +) { + // + // Temp Result ... + XMMAState result = {}; + + // + // Fast ... + double fast = iCustom( + _Symbol, + _Period, + xmmaIndicatorName, + // + // Inputs ... + mLen, // Market Length ... + fShift, // Fast Shift ... + sShift, // Slow Shift ... + // + 0, // Buffer Index ... + bar_index + ); + result.fast = fast; + + // + // FastPrev ... + double fastPrev = iCustom( + _Symbol, + _Period, + xmmaIndicatorName, + // + // Inputs ... + mLen, // Market Length ... + fShift, // Fast Shift ... + sShift, // Slow Shift ... + // + 0, // Buffer Index ... + bar_index + 1 + ); + result.fastPrev = fastPrev; + + // + // Slow ... + double slow = iCustom( + _Symbol, + _Period, + xmmaIndicatorName, + // + // Inputs ... + mLen, // Market Length ... + fShift, // Fast Shift ... + sShift, // Slow Shift ... + // + 1, // Buffer Index ... + bar_index + ); + result.slow = slow; + + // + // SlowPrev ... + double slowPrev = iCustom( + _Symbol, + _Period, + xmmaIndicatorName, + // + // Inputs ... + mLen, // Market Length ... + fShift, // Fast Shift ... + sShift, // Slow Shift ... + // + 1, // Buffer Index ... + bar_index + 1 + ); + result.slowPrev = slowPrev; + + // + // Mid ... + double mid = iCustom( + _Symbol, + _Period, + xmmaIndicatorName, + // + // Inputs ... + mLen, // Market Length ... + fShift, // Fast Shift ... + sShift, // Slow Shift ... + // + 2, // Buffer Index ... + bar_index + ); + result.mid = mid; + + // + // LongSL ... + double longSL = iCustom( + _Symbol, + _Period, + xmmaIndicatorName, + // + // Inputs ... + mLen, // Market Length ... + fShift, // Fast Shift ... + sShift, // Slow Shift ... + // + 3, // Buffer Index ... + bar_index + ); + result.longSL = longSL; + + // + // ShortSL ... + double shortSL = iCustom( + _Symbol, + _Period, + xmmaIndicatorName, + // + // Inputs ... + mLen, // Market Length ... + fShift, // Fast Shift ... + sShift, // Slow Shift ... + // + 4, // Buffer Index ... + bar_index + ); + result.shortSL = shortSL; + + // + // Do Calculations ... + // + // Find Cross Points ... + // + bool isCrossOver = fast >= slow + && !( + fastPrev >= slowPrev + ); + result.isCrossOver = isCrossOver; + + // + bool isCrossUnder = fast <= slow + && !( + fastPrev <= slowPrev + ); + result.isCrossUnder = isCrossUnder; + + // + // Find Trending ... + // + bool isTrendUp = fast > slow + && fast > fastPrev + && slow > slowPrev; + result.isTrendUp = isTrendUp; + + // + bool isTrendDown = fast < slow + && fast < fastPrev + && slow < slowPrev; + result.isTrendDown = isTrendDown; + + // + return result; +} +// +// END Global Requirement Functions ... +// + +// +// START Signal Related Functions ... +// +// +// Convert To XSignal Model ... +XSignal OrderToSignal() { + // + // Temp Result ... + XSignal result = {}; + result.type = X_NONE; + + // + // Here we can get some usefull info based on selected order ... + double swap = OrderSwap(); + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + int magicNumber = OrderMagicNumber(); + double takeProfit = OrderTakeProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // Conver Position to Signal ... + result.sl = stopLoss; + result.tp = takeProfit; + result.time = openTime; + result.symbol = _Symbol; + result.id = magicNumber; + result.entryPrice = openPrice; + result.type = isLongOrder ? X_LONG : X_SHORT; + + // + return result; +} + +// +// Calculate Signal ... +// in this function we calculate a signal exists in +// specific bar or not ... +XSignalRequest CalculateSignal( + const int bar_index, + // + // Inputs ... + const int mLen, // Market Length ... + const int fShift, // Fast Shift ... + const int sShift // Shift Shift ... +) { + // + // create temp result ... + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_NONE; + + // + XSignal signal = {}; + + // + // Define Price Related Variables ... + double tp = 0; + double sl = 0; + double price = 0; + datetime time = 0; + double priceGap = 0; + color clr = clrNONE; + string comment = ""; + double closePrice = 0; + + // + // START Capturing Signal ... + // + // + // START Retrieve Statets ... + // + // Reading Oscillator State ... + XMMAState xmmaState = GetXMMAState( + bar_index, + mLen, + fShift, + sShift + ); + // + // END Retrieve Statets ... + // + + // + // START States Calculations ... + // + // + // START PRICE Calculations ... + // + // + // LONG Prices ... + double longEntryPrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK); + double longClosePrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); + double longPriceGap = longClosePrice - longEntryPrice; + + // + // SHORT Prices ... + double shortEntryPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); + double shortClosePrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK); + double shortPriceGap = shortEntryPrice - shortClosePrice; + // + // END PRICE Calculations ... + // + // + // END States Calculations ... + // + + // + // START LONG Signals ... + // + bool hasLongSignal = false; + + // + hasLongSignal = + xmmaState.isCrossOver + && xmmaState.isTrendUp + && !xmmaState.isCrossUnder + && !xmmaState.isTrendDown + ; + // + // END LONG Signals ... + // + + // + // START SHORT Signals ... + // + bool hasShortSignal = + false; + + // + hasShortSignal = + xmmaState.isCrossUnder + && xmmaState.isTrendDown + && !xmmaState.isCrossOver + && !xmmaState.isTrendUp + ; + // + // END SHORT Signals ... + // + + // + // Check Signal Exists regardless of Long or Short ... + bool hasSignal = hasLongSignal || hasShortSignal; + + // + // Prevent from Going forward if there is not a Signal ... + if (!hasSignal) { + return result; + } + + // + // Price ... + price = hasLongSignal ? + longEntryPrice : + shortEntryPrice; + + // + // Close Price ... + closePrice = hasLongSignal ? + longClosePrice : + shortClosePrice; + + // + // Price Gap ... + priceGap = hasLongSignal ? + longPriceGap : + shortPriceGap; + + // + // Calculate Time ... + time = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Set TP ... + tp = hasLongSignal ? + // + // Long ... + longClosePrice * (150 * _Point) + : + // + // Short ... + shortClosePrice * (150 * _Point) + ; + + + // + // Set SL ... + sl = hasLongSignal ? + // + // Long ... + xmmaState.longSL + : + // + // Short ... + xmmaState.shortSL + ; + + // + // Normalize Prices ... + price = NormalizeDouble(price, _Digits); + sl = NormalizeDouble(sl, _Digits); + tp = NormalizeDouble(tp, _Digits); + + // + // Generate Signal Structure ... + signal.type = hasLongSignal ? + X_LONG : + X_SHORT; + signal.tp = tp; + signal.sl = sl; + signal.time = time; + signal.symbol = _Symbol; + signal.entryPrice = price; + // + // END Capturing Signal ... + // + + // + // Retrieve Signal Verifications ... + bool isSignalVerified = + true + && ( + hasLongSignal ? + price > xmmaState.fast + : + true + ) + ; + // GetSignalVerifications( + // signal, + // fOSCLength, + // fOSCMultiplier, + // sOSCLength, + // sOSCMultiplier, + // minPOSC, + // minVOSC, + // zDev, + // zBkStep, + // swingLoopback, + // slThrsh, + // flowMul, + // markMul, + // fastMul, + // slowMul + // ); + + // + // Apply Verifications ... + hasSignal = hasSignal + && isSignalVerified; + + // + result.hasSignal = hasSignal; + if (hasSignal) { + // + // Count Signals ... + totalSignals++; + if (hasLongSignal) { + totalLongSignals++; + } else { + totalShortSignals++; + } + + // + signal.id = totalSignals; + + // + result.signal = signal; + result.type = signal.type; + } + + // + return result; +} + +// +// Generate a Unique ID for Signal ... +string GenerateSignalTAG( + const XSignal &signal, + const string tag, + const string longSignalLabel, + const string shortSignalLabel +) { + // + // Generate Propper Label for Signal ... + string label = signal.type == X_LONG ? longSignalLabel : signal.type == X_SHORT ? shortSignalLabel : "UN_KNOWN"; + + // + // Generate Unique String Identifier for Signal ... + string result = tag + + "_[ID:" + IntegerToString(signal.id) + "]" + + "_[" + label + "]" + + "_[" + signal.symbol + "]" + + "_[Time:" + TimeToStr(signal.time) + "]" + + "_[TP:" + DoubleToString(signal.tp) + "]" + + "_[SL:" + DoubleToString(signal.sl) + "]"; + + // + return result; +} + +// +// Retrieve Signal Bar Index ... +int GetSignalBarIndex(XSignal &signal) { + // + // Temp Result ... + int result = -1; + + // + // Retriev Signal Bar Index ... + result = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + return result; +} + +// +// Draw Signal Shapes on Chart ... +bool DrawSignal( + const XSignal &signal, + long chartID = 0, + int subWindowID = 0, + const double positionThresholdFactor = 10, + string signalTag = "X-Signal", + string longSignalLabel = "X-Long", + color longSignalColor = clrAqua, + string shortSignalLabel = "X-Short", + color shortSignalColor = clrFuchsia +) { + // + // Generate isLongSignal Var ... + bool isLongSignal = signal.type == X_LONG; + + // + // Signal Bar Index ... + int bar_index = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // START Draw Signal Arrow ... + // + // + // Arrow Shape Name ... + string arrowName = StringConcatenate(signalTag, "_Arrow_", signal.id); + + // + // Arrow Price ... + double arrowPrice = 0; + if (isLongSignal) { + // + arrowPrice = iLow( + _Symbol, + _Period, + bar_index + ); + + // + arrowPrice = arrowPrice - (positionThresholdFactor * _Point); + } else { + // + arrowPrice = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + arrowPrice = arrowPrice + (positionThresholdFactor * _Point); + } + + // + // Arrow Code ... + uchar arrowCode = isLongSignal ? SYMBOL_ARROWUP : SYMBOL_ARROWDOWN; + + // + // Arrow Anchor Point ... + ENUM_ARROW_ANCHOR arrowAnchorPoint = isLongSignal ? ANCHOR_BOTTOM : ANCHOR_TOP; + + // + // Arrow Color ... + color arrowColor = isLongSignal ? longSignalColor : shortSignalColor; + + // + // Draw Signal Arrow Shape ... + bool result = DrawArrow( + chartID, + arrowName, + subWindowID, + signal.time, + arrowPrice, + arrowCode, + arrowAnchorPoint, + arrowColor, + STYLE_SOLID, + 3, + false, + false, + false, + 0 + ); + // + // END Draw Signal Arrow ... + // + + // + // START Draw Signal SL/TP ... + // + string slLineName = StringConcatenate(signalTag, "_SL_", signal.id); + string tpLineName = StringConcatenate(signalTag, "_TP_", signal.id); + + // + color slColor = shortSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color tpColor = longSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + + // + datetime time1 = iTime( + _Symbol, + _Period, + bar_index + 1 + ); + + // + // Draw Signal SL ... + if (signal.sl > 0) { + // + result = DrawTrendLine( + chartID, + slLineName, + subWindowID, + time1, + signal.sl, + signal.time, + signal.sl, + slColor, + STYLE_SOLID, + 2 + ); + } + + // + // Draw Signal TP ... + if (signal.tp > 0) { + //s + result = DrawTrendLine( + chartID, + tpLineName, + subWindowID, + time1, + signal.tp, + signal.time, + signal.tp, + tpColor, + STYLE_SOLID, + 2 + ); + } + // + // END Draw Signal SL/TP ... + // + + // + // Start Draw Signal Label ... + // + // + string labelName = StringConcatenate(signalTag, "_Label_", signal.id); + + // + double labelPrice = isLongSignal ? arrowPrice - (positionThresholdFactor * _Point) : arrowPrice + (positionThresholdFactor * _Point); + + // + string labelText = isLongSignal ? longSignalLabel : shortSignalLabel; + + // + result = DrawText( + chartID, + labelName, + subWindowID, + signal.time, + labelPrice, + labelText, + "Arial", + 10, + arrowColor, + 0, + ANCHOR_CENTER + ); + // + // End Draw Signal Label ... + // + + // + return result; +} + +// +// Trade on Specific Signal ... +bool TradeSignal( + XSignal &signal, + // + string prefix, + // + double volumePercent, + // + // Long ... + const string longSignalLabel, + const color longSignalColor, + // + // Short ... + const string shortSignalLabel, + const color shortSignalColor +) { + // + // Temp Result ... + bool result = false; + + // + if (initialBalance == 0) { + initialBalance = AccountInfoDouble(ACCOUNT_BALANCE); + } + + // + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + int openPositions = CountOpenPositions(); + double volume = (volumePercent * initialBalance); + // openPositions == 0 ? + // (volumePercent * balance) : + // (volumePercent * initialBalance); + + // + if ( + signal.type != X_LONG && + signal.type != X_SHORT + ) { + return result; + } + + // + bool hasLongSignal = signal.type == X_LONG; + + // + // Order Operation ... + int operation = hasLongSignal ? + OP_BUY : + OP_SELL; + + // + // Detect Trade Color ... + color clr = hasLongSignal ? + longSignalColor : + shortSignalColor; + + // + // Generate Signal Comment ... + string label = hasLongSignal ? + longSignalLabel : + shortSignalLabel; + + // + // Generate Signal Comment ... + string comment = StringConcatenate( + prefix, + "_", signal.id, "_", + label + ); + + // + // Placing Order ... + int orderTicket = OrderSend( + _Symbol, + operation, + volume, + signal.entryPrice, + 3, + signal.sl, + signal.tp, + comment, + signal.id, + 0, + clr + ); + + // + // Draw Signal Shape if Order Opened Successfully ... + if (orderTicket >= 0) { + // + // Here i must to Draw Signal Shapes ... + DrawSignal( + signal, + 0, + 0, + 50, + prefix, // Signal Tag ... + longSignalLabel, // Long Signal Label ... + longSignalColor, + shortSignalLabel, // Short Signal Label ... + shortSignalColor + ); + + // + result = true; + } + + // + return result; +} +// +// END Signal Related Functions ... +// + +// +// START Orders Related Functions ... +// +// +// Count Open Positions ... +int CountOpenPositions() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if (OrderSymbol() == _Symbol) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Long Positions ... +int CountOpenLongPositions() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_BUY + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Short Positions ... +int CountOpenShortPositions() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_SELL + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Close All Open Trades ... +void CloseAllTrades() { + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + } + } + } +} + +// +// Close All Open Trades ... +void CloseAllLongTrades() { + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + } + } + } + } +} + +// +// Close All Open Trades ... +void CloseAllShortTrades() { + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (!isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + } + } + } + } +} +// +// END Orders Related Functions ... +// diff --git a/Bkp/Used/14020419/x-saherelm.ea.mq4 b/Bkp/Used/14020419/x-saherelm.ea.mq4 new file mode 100644 index 0000000..0ca92fd --- /dev/null +++ b/Bkp/Used/14020419/x-saherelm.ea.mq4 @@ -0,0 +1,1444 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XST Strategy Expert Advisor +// --------------------------------------------- +// saherelm implementation of strategy expert advisor ... +// in this EA, we try to combine multiple tools, to ashive best +// results ... +// +// ShortName: XST +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +989121694056 +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XST Strategy Expert Advisor" +#property strict + +// +// START Inputs ... +// +// +// Signal Prefixe ... +input string signalPrefix = "XST"; // Signal Prefix + +// +// Signal Draw Specifications ... +input string bullishSignalLabel = "X_BUY"; // Bullish Signal Label +input color bullishSignalColor = clrAqua; // Bullish Signal Color + +// +input string bearishSignalLabel = "X_SELL"; // Bearish Signal Label +input color bearishSignalColor = clrFuchsia; // Bearish Signal Color + +// +input bool useOSCSignalling = false; // Use XOSC Signalling +input string oscSignalIdentifier = "XOSC"; // XOSC Signal Identifier + +// +input bool useXMASignalling = false; // Use XMA Signalling +input string xmaSignalIdentifier = "XMA"; // XMA Signal Identifier + +// +input bool useXSHPSignalling = true; // Use XSHP Signalling +input string xshpSignalIdentifier = "XSHP"; // XSHP Signal Identifier + +// +input bool useXMNTMSignalling = false; // Use XMNTM Signalling +input string xmntmSignalIdentifier = "XMNTM"; // XMNTM Signal Identifier + +// +input bool useXRSISignalling = true; // Use XRSI Signalling +input string xrsiSignalIdentifier = "XRSI"; // XRSI Signal Identifier + +// +input color signalEntryColor = clrAquamarine; // Signal Entry Ptice Color +input color signalSLColor = clrRed; // Signal SL Color +input color signalTPColor = clrGreen; // Signal TP Color + +// +// Trade ... +input bool allowTrade = true; // Allow Trade Based on given Signals +input bool allowLongTrades = true; // Allow Long Trades +input bool allowShortTrades = false; // Allow Short Trades + +// +// Market Specification Inpouts ... +input int marketLength = 7; // Market Length +input double riskToRewardRatio = 2; // Risk to Reward Ratio + +// +// Alerts ... +input bool alertEvents = true; // Alert Events +input bool alertPositions = true; // Alert Positions +input bool longPositionAlerts = true; // Alert Long Positions +input bool shortPositionAlerts = true; // Alert Short Positions + +// +// Alert Types ... +input bool terminalAlert = false; // Terminal Alert +input bool pushAlert = false; // Push Notification Alerts + +// +// Balance and Finanical Specifications ... +input double lotsPerTradePercent = 0.00001; // Lots Per Trade Percent +input int maxOpenTrades = 4; // Maximum Open Trade +input double maxDrawdownPercentPerPTrade = 0.015; // Maximum DrawDown Per Trade +input double minBalancePercent = 0.5; // Minimum Balance for Trading +input double maxEquityPercent = 0.1; // Maximum Trade Equity +input int closeAllOpenTradesAfterCandle = 504; // Close All Open Trades After Passed Candles +input bool closeAllInProfitOpenTradesWhenMaxOpenTradesReached = false; // Close All In Profit Open Trades When Max Open Trades Reached and New Signal Income + +// +// OSC Inputs ... +// +// FastOSC ... +// Short Cycle (Fast OSC) ... +input int fastOSCLength = 10; // FastOSC Length +input double fastOSCMultiplier = 1.0; // FastOSC Multiplier + +// +// SlowOSC ... +// Medium Cycle (Slow OSC) ... +input int slowOSCLength = 30; // SlowOSC Length +input double slowOSCMultiplier = 3.0; // SlowOSC Multiplier + +// +// Power OSC ... +input double minPowerOSC = 0.04; // Minimum Signal Power + +// +// Variance OSC ... +input double minVarianceOSC = 0.1; // Minimum Var Power + +// +// ZIGZAG Inputs ... +input int zDeviation = 5; // ZigZag Deviation +input int zBackStep = 3; // ZigZag Back Step + +// +// XMA Inputs ... +// +input double step = 0.02; // SAR Step +input double maximum = 0.2; // SAR Maximum +input int shortCycleFastMultiplier = 2; // Short Cycle Fast Multiplier +input int shortCycleSlowMultiplier = 4; // Short Cycle Slow Multiplier +input int mediumCycleFastMultiplier = 6; // Medium Cycle Fast Multiplier +input int mediumCycleSlowMultiplier = 12; // Medium Cycle Slow Multiplier +input int longCycleFastMultiplier = 36; // Long Cycle Fast Multiplier +input int longCycleSlowMultiplier = 72; // Long Cycle Slow Multiplier +// +// Show/Hide Inputs ... +input bool showPSar = false; // Show Parabolic Sar +input bool showMarketMiddle = false; // Show Market Middle +input bool showShortCycle = false; // Show Short Cycle +input bool showShortCycleCrossLines = false; // Show Short Cycle Vertical Lines +input bool showMediumCycle = false; // Show Medium Cycle +input bool showMediumCycleCrossLines = false; // Show Medium Cycle Vertical Lines +input bool showLongCycle = false; // Show Long Cycle +input bool showLongCycleCrossLines = false; // Show Long Cycle Vertical Lines +// +// Color Inputs ... +input color pSarColor = clrCornflowerBlue; // Parabolic Sar Color +input color shortCycleFastColor = clrGreen; // Short Cycle Fast Color ... +input color shortCycleSlowColor = clrRed; // Short Cycle Slow Color ... +input color mediumCycleFastColor = clrAqua; // Medium Cycle Fast Color ... +input color mediumCycleSlowColor = clrFuchsia; // Medium Cycle Slow Color ... +input color longCycleFastColor = clrGoldenrod; // Medium Cycle Fast Color ... +input color longCycleSlowColor = clrBrown; // Medium Cycle Slow Color ... + +// +// XMKT Inputs ... +// +// Market Specifications ... +input bool showHighestHigh = false; // Show Market Highest High +input bool showHighestLow = false; // Show Market Highest Low +input bool showHighestOpen = false; // Show Market Highest Open +input bool showHighestClose = false; // Show Market Highest Close +input bool showLowestHigh = false; // Show Market Lowest High +input bool showLowestLow = false; // Show Market Lowest Low +input bool showLowestOpen = false; // Show Market Lowest Open +input bool showLowestClose = false; // Show Market Lowest Close +// +input color highestHighColor = clrDeepPink; // Market Highest High Color +input color highestLowColor = clrDarkOrange; // Market Highest Low Color +input color highestOpenColor = clrDodgerBlue; // Market Highest Open Color +input color highestCloseColor = clrOrchid; // Market Highest Close Color +input color lowestHighColor = clrHotPink; // Market Lowest High Color +input color lowestLowColor = clrOrange; // Market Lowest Low Color +input color lowestOpenColor = clrPowderBlue; // Market Lowest Open Color +input color lowestCloseColor = clrMediumOrchid; // Market Lowest Close Color +// +input ENUM_LINE_STYLE highestHighStyle = STYLE_DOT; // Market Highest High Line Style +input ENUM_LINE_STYLE highestLowStyle = STYLE_DOT; // Market Highest Low Line Style +input ENUM_LINE_STYLE highestOpenStyle = STYLE_DOT; // Market Highest Open Line Style +input ENUM_LINE_STYLE highestCloseStyle = STYLE_DOT; // Market Highest Close Line Style +input ENUM_LINE_STYLE lowestHighStyle = STYLE_DOT; // Market Lowest High Line Style +input ENUM_LINE_STYLE lowestLowStyle = STYLE_DOT; // Market Lowest Low Line Style +input ENUM_LINE_STYLE lowestOpenStyle = STYLE_DOT; // Market Lowest Open Line Style +input ENUM_LINE_STYLE lowestCloseStyle = STYLE_DOT; // Market Lowest Close Line Style + +// +// SHPD Indicator ... +input double sharpDetectMultiplier = 500; // Sharp Detect Multiplier + +// // +// input bool drawSharpDetectedLabels = false; // Draw Labels on Founded Sharps + +// // +// input string sharpBullishLabel = "SH_BULL"; // Sharp Bullish Label +// input color sharpBullishColor = clrAqua; // Sharp Bullish color + +// // +// input string sharpBearishLabel = "SH_BEAR"; // Sharp Bearish Label +// input color sharpBearishColor = clrFuchsia; // Sharp Bearish color +// // +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +int lastSignalledBar = 0; + +// +bool waitForLongSignals = true; +bool closeLongTrades = false; + +// +bool waitForShortSignals = true; +bool closeShortTrades = false; + +// +bool isMCGoingToClose; +bool isSharpBullishHappens; +bool isSharpBearishHappens; + +// +datetime startMarketTime; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.signal.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Validate Inputs ... + bool inputsNotValiid = + // + // MARKET ... + marketLength < 0 + || riskToRewardRatio < 0 + // + // EA ... + || lotsPerTradePercent < 0 + || maxOpenTrades <= 0 + || maxDrawdownPercentPerPTrade < 0 + || minBalancePercent < 0 + || maxEquityPercent < 0 + || marketLength < 0 + // + // OSC ... + || fastOSCLength < 0 + || fastOSCMultiplier < 0 + || slowOSCLength < 0 + || slowOSCMultiplier < 0 + || minPowerOSC < 0 + || minVarianceOSC < 0 + || slowOSCLength <= fastOSCLength + // + // ZIGZAG ... + || zDeviation < 0 + || zBackStep < 0 + || zBackStep >= marketLength + // + // XMA ... + // + // Validate Short Cycle ... + || shortCycleFastMultiplier <= 0 + || shortCycleSlowMultiplier <= 0 + || shortCycleFastMultiplier >= shortCycleSlowMultiplier + // + // Validate Medium Cycle ... + || mediumCycleFastMultiplier <= 0 + || mediumCycleSlowMultiplier <= 0 + || mediumCycleFastMultiplier >= mediumCycleSlowMultiplier + // + // Validate Long Cycle ... + || longCycleFastMultiplier <= 0 + || longCycleSlowMultiplier <= 0 + || longCycleFastMultiplier >= longCycleSlowMultiplier + // + // Validate Series of Multipliers ... + || shortCycleFastMultiplier >= mediumCycleFastMultiplier + || mediumCycleFastMultiplier >= longCycleFastMultiplier + ; + + if (inputsNotValiid) { + return INIT_PARAMETERS_INCORRECT; + } + + // + totalSignals = 0; + totalLongSignals = 0; + totalShortSignals = 0; + + // + initialBalance = 0; + + // + // START Define Array Series ... + // + // + // END Define Array Series ... + // + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST"; + + // // + // // Set Event Timer on One Seccond ... + // bool isEventSet = EventSetTimer(1); + // if (!isEventSet) { + // LogMessage("Error: " + GetLastError()); + // return INIT_FAILED; + // } + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + // Killing Event Timer ... + EventKillTimer(); +} + +// +// Ticker Event Handler ... +void OnTick() { + // + isNewDay = IsNewDay(); + if (isNewDay) { + // + LogMessage( + StringConcatenate( + "New Day: ", TimeCurrent() + ) + ); + } + + // + // Process Signals to Open Positions ... + ProcessSignals(); + + // + // Checking State for Signal Handling ... + CheckState(); + + // + // Process Open Positions for Trailing Stop Loss or Close ... + ProcessOpenPositions(); +} + +// +// Timer Event Handler ... +void OnTimer() { + // + CheckState(); + + // + ProcessOpenPositions(); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// START Signal Related Functions ... +// +// +// Calculate Signal ... +// in this function we calculate a signal exists in +// specific bar or not ... +XSignalRequest GenerateSignal( + const int bar_index // Bar Index ... +) { + // + // create temp result ... + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_NONE; + + // + XSignal signal = {}; + + // + XOSCState emptyOscState = {}; + ArrayFree(oscStates); + ArrayResize( + oscStates, + marketLength + ); + for (int i = 0; i < marketLength; i++) { + oscStates[i] = emptyOscState; + } + + // + XMAState emptyXmaState = {}; + ArrayFree(xmaStates); + ArrayResize( + xmaStates, + shortCycleSlowMultiplier * marketLength + ); + for (int i = 0; i < shortCycleSlowMultiplier * marketLength; i++) { + xmaStates[i] = emptyXmaState; + } + + // + XMKTState emptyXmktState = {}; + ArrayFree(xmktStates); + ArrayResize( + xmktStates, + marketLength + ); + for (int i = 0; i < marketLength; i++) { + xmktStates[i] = emptyXmktState; + } + + // + // Retrieve Bar Index Time ... + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + 1 + ); + + // + // START Retrieve Statets ... + // + // + // Loop through Market Length ... + int index = 0; + for (int i = bar_index; i < bar_index + marketLength; i++) { + // + // Retrieve Index OSC State ... + XOSCState oscState = GetOSCState( + i, // Bar Index ... + fastOSCLength, + fastOSCMultiplier, + slowOSCLength, + slowOSCMultiplier + ); + + // + // Retrieve XMarketState ... + XMKTState xmktState = GetMarketState( + // + i, + marketLength, + // + showHighestHigh, + highestHighColor, + highestHighStyle, + // + showHighestLow, + highestLowColor, + highestLowStyle, + // + showHighestOpen, + highestOpenColor, + highestOpenStyle, + // + showHighestClose, + highestCloseColor, + highestCloseStyle, + // + showLowestHigh, + lowestHighColor, + lowestHighStyle, + // + showLowestLow, + lowestLowColor, + lowestLowStyle, + // + showLowestOpen, + lowestOpenColor, + lowestOpenStyle, + // + showLowestClose, + lowestCloseColor, + lowestCloseStyle + ); + + // + // Set Retrieved Index States ... + oscStates[index] = oscState; + xmktStates[index] = xmktState; + + // + index++; + } + + index = 0; + for (int i = bar_index; i < bar_index + (shortCycleSlowMultiplier * marketLength); i++) { + // + // Retrieve XMA State ... + XMAState xmaState = GetXMAState( + i, // Bar Index ... + marketLength, // Market Length ... + step, // SAR Step ... + maximum, // SAR Maximum ... + shortCycleFastMultiplier, // Short Cycle Fast Multiplier ... + shortCycleSlowMultiplier, // Short Cycle Slow Multiplier ... + mediumCycleFastMultiplier, // Medium Cycle Fast Multiplier ... + mediumCycleSlowMultiplier, // Medium Cycle Slow Multiplier ... + longCycleFastMultiplier, // Long Cycle Fast Multiplier ... + longCycleSlowMultiplier, // Long Cycle Slow Multiplier ... + showPSar, // Show Parabolic Sar + showMarketMiddle, // Show Market Middle ... + showShortCycle, // Show Short Cycle + showShortCycleCrossLines, // Show Short Cycle Vertical Lines + showMediumCycle, // Show Medium Cycle + showMediumCycleCrossLines, // Show Medium Cycle Vertical Lines + showLongCycle, // Show Long Cycle + showLongCycleCrossLines, // Show Long Cycle Vertical Lines + pSarColor, // Parabolic Sar Color + shortCycleFastColor, // Short Cycle Fast Color ... + shortCycleSlowColor, // Short Cycle Slow Color ... + mediumCycleFastColor, // Medium Cycle Fast Color ... + mediumCycleSlowColor, // Medium Cycle Slow Color ... + longCycleFastColor, // Medium Cycle Fast Color ... + longCycleSlowColor // Medium Cycle Slow Color ... + ); + + // + xmaStates[index] = xmaState; + + // + index++; + } + // + // END Retrieve Statets ... + // + + // + // START States Calculations ... + // + + // + // START OSC Calculations ... + // + // + // END OSC Calculations ... + // + + // + // START XMA Calculations ... + // + + // + // END XMA Calculations ... + // + + // + // START Momentum Calculations ... + // + // + // END Momentum Calculations ... + // + + // + // START RSI Calculations ... + // + // + // END RSI Calculations ... + // + + // + // START PRICE Calculations ... + // + RefreshRates(); + + // + double marketLow[]; + double marketOpen[]; + double marketHigh[]; + double marketClose[]; + // + double marketUp[]; + double marketDown[]; + // + ArrayResize( + marketLow, + marketLength + ); + ArrayResize( + marketOpen, + marketLength + ); + ArrayResize( + marketHigh, + marketLength + ); + ArrayResize( + marketClose, + marketLength + ); + // + ArrayResize( + marketUp, + marketLength + ); + ArrayResize( + marketDown, + marketLength + ); + + // + index = 0; + for (int i = bar_index; i < marketLength + bar_index; i++) { + // + marketLow[index] = iLow( + _Symbol, + _Period, + i + ); + + // + marketOpen[index] = iOpen( + _Symbol, + _Period, + i + ); + + // + marketHigh[index] = iHigh( + _Symbol, + _Period, + i + ); + + // + marketClose[index] = iClose( + _Symbol, + _Period, + i + ); + + // + // marketUp[i] = MathMax(marketOpen[i], marketClose[i]); + marketUp[index] = marketHigh[i]; + + // + // marketDown[i] = MathMin(marketOpen[i], marketClose[i]); + marketDown[index] = marketLow[i]; + + // + index++; + } + + // + // LONG Prices ... + double longEntryPrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK); + double longClosePrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); + double longPriceGap = longClosePrice - longEntryPrice; + + // + // SHORT Prices ... + double shortEntryPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); + double shortClosePrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK); + double shortPriceGap = shortEntryPrice - shortClosePrice; + + // + if (startMarketTime == 0) { + startMarketTime = barTime; + } + + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + startMarketTime + ); + + // + if (startBarIndex > bar_index + marketLength) { + // + startBarIndex = 0; + startMarketTime = 0; + } + + // + bool isSharpBullishDetected = false; + bool isShareBearishDetected = false; + double sharpDetectionValue = sharpDetectMultiplier * _Point; + if (startBarIndex > bar_index + 1) { + // + double marketStartHigh = iHigh( + _Symbol, + _Period, + startBarIndex + ); + + double marketStartLow = iLow( + _Symbol, + _Period, + startBarIndex + ); + + // + double prevCandleOpen = iOpen( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double prevCandleHigh = iHigh( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double prevCandleClose = iClose( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double candleOpen = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double prevCandleComparedPrice = MathMin(prevCandleOpen, prevCandleClose); + isShareBearishDetected = + prevCandleHigh < marketStartHigh + && prevCandleComparedPrice < marketStartHigh + && marketStartHigh - prevCandleComparedPrice >= sharpDetectionValue; + + // // + // isSharpBullishDetected = + // marketStartHigh - MathMin(prevCandleOpen, prevCandleClose) >= sharpDetectionValue; + } + // + if ( + isShareBearishDetected + || isSharpBullishDetected + ) { + startBarIndex = 0; + startMarketTime = 0; + } + // + // + // END PRICE Calculations ... + // + + // + // START Capturing Signal ... + // + + // + // START LONG Signals ... + // + // + // NOTES: + // when MC Fast is Over MC Slow, + // All Long Trades must be down when Market Middle is above MCSlow ... + // and must be paused when Market Middle is Going Under MCSlow ... + + // + // OSC ... + bool oscHasLongSignal = false; + if (useOSCSignalling) { + // + oscHasLongSignal = + true + && ( + oscStates[0].fastOSC < 0 + ) + ; + } + + // + // XMA ... + bool xmaHasLongSignal = false; + if (useXMASignalling) { + // + xmaHasLongSignal = + // + // Long Cycle Trend Up ... + xmaStates[0].lcFast > xmaStates[0].lcSlow + // Lowest Low Must be Higher than lcFast ... + && xmktStates[0].lowestLow > xmaStates[0].lcFast + // + // Medium Cycle in Up Trend ... + && xmaStates[0].mcFast > xmaStates[0].mcSlow + // + // and the Medium Cycle Distance must be at least 100 Point ... + && (xmaStates[0].mcFast - xmaStates[0].mcSlow) > (100 * _Point) + // + // then looking for parabolic sar cross down market middleage ... + && xmaStates[0].parabolicSAR < xmaStates[0].marketMiddleage + && !(xmaStates[1].parabolicSAR <= xmaStates[1].marketMiddleage) + // + && xmaStates[0].scFast > xmaStates[0].marketMiddleage + // + // in crossing time Parabolic SAR must be greater than mcFast ... + && xmaStates[0].parabolicSAR > xmaStates[0].mcFast + // + // in this conditions, entry price must below than highest high, in market ... + && longEntryPrice < xmktStates[0].highestHigh + ; + } + + // + bool xshpHasLongSignal = false; + if (useXSHPSignalling) { + // + xshpHasLongSignal = + // + isShareBearishDetected + // + && xmaStates[0].mcFast > xmaStates[0].mcSlow + && xmaStates[1].mcFast > xmaStates[1].mcSlow + && xmaStates[2].mcFast > xmaStates[3].mcSlow + // + && xmaStates[1].mcFast - xmaStates[1].mcSlow > (100 * _Point) + // + && xmktStates[1].lowestLow > xmaStates[1].mcSlow + && xmktStates[1].highestLow > xmktStates[1].lowestHigh + && MathAbs(xmktStates[0].highestLow - xmktStates[0].lowestHigh) > (50 * _Point) + // + && longEntryPrice != xmktStates[0].lowestHigh + && MathAbs(longEntryPrice - xmktStates[0].lowestHigh) > (50 * _Point) + // + && (xmaStates[0].marketMiddleage > xmaStates[0].mcFast + || ( + xmaStates[0].marketMiddleage > xmaStates[0].mcSlow + && xmaStates[0].marketMiddleage < xmaStates[0].mcFast + ) + ) ? + !(longEntryPrice < xmaStates[0].mcSlow) + && !( + longEntryPrice > xmaStates[0].mcSlow + && longEntryPrice < xmaStates[0].mcFast + ) : + true + ; + } + + // + bool xmntmHasLongSignal = false; + if (useXMNTMSignalling) { + } + + // + bool xrsiHasLongSignal = false; + if (useXRSISignalling) { + } + + // + bool hasLongSignal = + // + // OSC Signals ... + oscHasLongSignal + || xmaHasLongSignal + || xshpHasLongSignal + || xmntmHasLongSignal + || xrsiHasLongSignal + ; + // + // END LONG Signals ... + // + + // + // START SHORT Signals ... + // + bool hasShortSignal = false; + // + // END SHORT Signals ... + // + + // + // Check Signal Exists regardless of Long or Short ... + bool hasSignal = hasLongSignal || hasShortSignal; + + // // + // // Check Short Cycle For Double Crossing ... + // int scCrosses = 0; + // int pSarCrosses = 0; + + // // + // // SC Crosses ... + // for (int i = bar_index; i < bar_index + (shortCycleSlowMultiplier * marketLength) - 1; i++) { + // // + // bool isPSarCrossUnderMarketMid = + // xmaStates[0].parabolicSAR < xmaStates[0].marketMiddleage + // && !(xmaStates[1].parabolicSAR < xmaStates[1].marketMiddleage); + + // // + // bool isPSarCrossOverMarketMid = + // xmaStates[0].parabolicSAR > xmaStates[0].marketMiddleage + // && !(xmaStates[1].parabolicSAR > xmaStates[1].marketMiddleage); + + // // + // if ( + // isPSarCrossUnderMarketMid + // || isPSarCrossOverMarketMid + // ) { + // pSarCrosses++; + // } + + // // + // bool isSCFastCrossOverSlow = + // xmaStates[i].scFast > xmaStates[i].scSlow + // && !(xmaStates[i].scFast > xmaStates[i].scSlow); + + // // + // bool isSCFastCrossUnderSlow = + // xmaStates[i].scFast < xmaStates[i].scSlow + // && !(xmaStates[i].scFast < xmaStates[i].scSlow); + + // // + // if ( + // isSCFastCrossOverSlow + // || isSCFastCrossUnderSlow + // ) { + // scCrosses++; + // } + // } + + // // + // // Parabolic SAR ... + // for (int i = bar_index; i < bar_index + (shortCycleFastMultiplier * marketLength) - 1; i++) { + // // + // bool isPSarCrossUnderMarketMid = + // xmaStates[0].parabolicSAR < xmaStates[0].marketMiddleage + // && !(xmaStates[1].parabolicSAR < xmaStates[1].marketMiddleage); + + // // + // bool isPSarCrossOverMarketMid = + // xmaStates[0].parabolicSAR > xmaStates[0].marketMiddleage + // && !(xmaStates[1].parabolicSAR > xmaStates[1].marketMiddleage); + + // // + // if ( + // isPSarCrossUnderMarketMid + // || isPSarCrossOverMarketMid + // ) { + // pSarCrosses++; + // } + // } + + // // + // if ( + // scCrosses > 1 + // || pSarCrosses > 1 + // ) { + // LogMessage("Crosses Exceed ..."); + // hasSignal = false; + // } + + // + // Prevent from Going forward if there is not a Signal ... + if (!hasSignal) { + // + result.signal = signal; + return result; + } + + // + totalSignals++; + + // + // Define Price Related Variables ... + // + double price = 0; + double priceGap = 0; + double sl = 0; + double risk; + double reward; + double tp = 0; + double r2rRatio = riskToRewardRatio; + + // + datetime time = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Fill Signal Related Variables ... + if (hasLongSignal) { + // + price = longEntryPrice; + priceGap = longPriceGap; + + // + // Setting Up SL Based on Last Market Lowest ... + sl = GetMarketLowestLow( + bar_index, + marketLength + ); + + // + risk = price - sl; + if (risk > (MathAbs(xmaStates[0].mcFast - xmaStates[0].mcSlow) / 2)) { + risk = risk / 3; + } + + reward = risk * r2rRatio; + tp = price + reward; + + // + // Check TP based on Spread ... + if (tp < price + priceGap) { + tp = tp + priceGap; + } + + // + sl = 0; + + // + totalLongSignals++; + } else if (hasShortSignal) { + // + totalShortSignals++; + + // + price = shortEntryPrice; + priceGap = shortPriceGap; + + // + risk = sl - price; + reward = risk * r2rRatio; + tp = price - reward; + } + + // + // Normalize Prices ... + price = NormalizeDouble(price, _Digits); + sl = NormalizeDouble(sl, _Digits); + tp = NormalizeDouble(tp, _Digits); + + // + // Generate Signal Structure ... + signal.type = hasLongSignal ? + X_LONG : + X_SHORT; + signal.tp = tp; + signal.sl = sl; + signal.time = time; + signal.symbol = _Symbol; + signal.entryPrice = price; + signal.id = totalLongSignals; + // + // TODO: Fill Signal Comment By Sgnal Provider + signal.comment = + useOSCSignalling && oscHasLongSignal + ? oscSignalIdentifier + : useXMASignalling && xmaHasLongSignal + ? xmaSignalIdentifier + : useXSHPSignalling && xshpHasLongSignal + ? xshpSignalIdentifier + : useXMNTMSignalling && xmntmHasLongSignal + ? xmntmSignalIdentifier + : useXRSISignalling && xrsiHasLongSignal + ? xrsiSignalIdentifier + : "" + ; + // + // END Capturing Signal ... + // + + // + // Fill Result ... + result.hasSignal = hasSignal; + result.signal = signal; + result.type = signal.type; + + // + // Return Result ... + return result; +} + +// +// Check State for Signal Handling ... +void CheckState() { + // + // Here we Must to Check Market State for enable or disable + // Signal Handlers and also make dection to close all long/short + // trades ... + + // + // Prevent from Checking, if there is no states available ... + if (ArraySize(xmaStates) == 0) { + return; + } + + // // + // closeLongTrades = + // xmaStates[0].parabolicSAR > xmaStates[0].marketMiddleage + // && !(xmaStates[1].parabolicSAR > xmaStates[1].marketMiddleage) + // ; + + // // + // closeLongTrades = + // false + // ; +} + +// +// Calculate Signals and Process Based on Exists Signals ... +void ProcessSignals() { + // + XSignalRequest request = {}; + request.type = X_NONE; + request.hasSignal = false; + + // + // Prevent Multiple Calculating on Same Bars ... + isNewBar = IsNewBar(); + if (isNewBar) { + // + countedBars++; + } + + // + bool allowDoTrade = true; + + // + // Check Balance ... + if (initialBalance > 0) { + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double minimumBalanceForTrade = + balance > initialBalance + ? + minBalancePercent * balance + : + minBalancePercent * initialBalance; + + // + // Retrieve Account Equity ... + double equity = AccountInfoDouble(ACCOUNT_EQUITY); + double maxAllowedEquity = balance - (balance * maxEquityPercent); + + // + // Retrieve Free Marigin ... + double freeMargin = AccountFreeMargin(); + double maximumMariginRisk = balance - (balance * maxEquityPercent); + + // + if ( + // + // Do not Open Positions if equity not passed ... + equity < maxAllowedEquity || + // + // Do not Open Positions if free margin not passed ... + freeMargin <= maximumMariginRisk || + // + // Do not open positions if balance less than minimum ... + balance <= minimumBalanceForTrade + ) { + // + allowDoTrade = false; + + // // + // string message = StringConcatenate( + // "Trading Pause => ", + // "Balance: ", balance, + // ", Equity: ", equity, + // ", FreeMargin: ", freeMargin + // ); + + // // + // LogMessage(message); + // SendAlert(message); + } + } + + // + // Retrieve Signal Exists ... + request = GenerateSignal(0); + + // + // Prevent doing anything else, if there is no signals ... + if ( + !allowDoTrade || + !request.hasSignal || + request.type == X_NONE + ) { + return; + } + + // + bool hasLongSignal = request.type == X_LONG; + + // + // Check For Bot State ... + if ( + (hasLongSignal && !waitForLongSignals) + || (!hasLongSignal && !waitForShortSignals) + ) { + return; + } + + // + // Check last Signalled Bar with Counted Bars ... + // Prevent Multiple Signalling on Same Bar ... + bool isInLastSignalledBars = false; + for (int i=0; i < marketLength; i++) { + // + isInLastSignalledBars = + isInLastSignalledBars + || lastSignalledBar == countedBars - i + ; + } + if (isInLastSignalledBars) { + // + totalSignals--; + if (hasLongSignal) { + totalLongSignals--; + } else { + totalShortSignals--; + } + return; + } + + // + // increase last signalled bar ... + lastSignalledBar = countedBars; + + // + // Calculate Can Trade or not ... + allowDoTrade = allowTrade + && ( + hasLongSignal ? + allowLongTrades : + allowShortTrades + ); + + // + // Chack Maximum Open Positions ... + int openTrades = CountOpenTrades(); + if (maxOpenTrades > 0) { + // + if (openTrades >= maxOpenTrades) { + // + allowDoTrade = false; + + // + if (closeAllInProfitOpenTradesWhenMaxOpenTradesReached) { + // + // Close All In Profit Trades ... + bool hasClosedInProfitTrade = CloseAllInProfitTrades(); + if (hasClosedInProfitTrade) { + // + openTrades = CountOpenTrades(); + + // + allowDoTrade = !(openTrades >= maxOpenTrades); + } + } + + // + if (!allowDoTrade) { + // + string message = StringConcatenate( + "Trading Pause => ", + "Max Open Trades (", + maxOpenTrades, + ") reached ..." + ); + + // + LogMessage(message); + SendAlert(message); + } + } + } + + // + // Check Trading is Enable or not ... + // nothing to do if trading is disabled ... + if (!allowDoTrade) { + // // + // string message = StringConcatenate( + // "Trading Not Allowed ..." + // ); + + // // + // LogMessage(message); + // SendAlert(message); + return; + } + + // + bool isPositionOpened = TradeSignal( + request.signal, + signalPrefix, + lotsPerTradePercent, + // + bullishSignalLabel, + bullishSignalColor, + bearishSignalLabel, + bearishSignalColor, + // + // Signal Identifiers ... + oscSignalIdentifier, + xmaSignalIdentifier, + xshpSignalIdentifier, + xmntmSignalIdentifier, + xrsiSignalIdentifier + ); + + // + if (isPositionOpened) { + // + bool canAlert = + alertPositions + && ( + hasLongSignal ? + longPositionAlerts + : + shortPositionAlerts + ); + + // + if (canAlert) { + // + // Alert Message ... + string message = StringConcatenate( + "Trade on Signal ID: ", request.signal.id, + ", Entry: ", request.signal.entryPrice, + ", TP: ", request.signal.tp + ); + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } + } + } +} + +// +// Process All Open Positions ... +void ProcessOpenPositions() { + // + // this comes from check state ... + if (closeLongTrades) { + // + closeLongTrades = false; + + // + bool isAllLongTradesClosed = CloseAllLongTrades(); + if (isAllLongTradesClosed) { + // waitForLongSignals = false; + } + } + + // + // this comes from check state ... + if (closeShortTrades) { + // + closeShortTrades = false; + + // + bool isAllShortTradesClosed = CloseAllShortTrades(); + if (isAllShortTradesClosed) { + // waitForShortSignals = false; + } + } + + // + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + closeAllOpenTradesAfterCandle + ); + + // + // Close Maximum DrawDown Passed Trades ... + bool hasClosedInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + maxDrawdownPercentPerPTrade + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedInDrawDownLongTrade + ) { + // + // waitForLongSignals = false; + // waitForShortSignals = false; + } +} + +// +// Send Special Type of Alerts ... +void SendAlert(string message) { + // + if (!alertEvents) { + return; + } + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020419/x-saherelm.signal.lib.mq4 b/Bkp/Used/14020419/x-saherelm.signal.lib.mq4 new file mode 100644 index 0000000..34b539d --- /dev/null +++ b/Bkp/Used/14020419/x-saherelm.signal.lib.mq4 @@ -0,0 +1,2522 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Signal Draw Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +static int totalSignals = 0; +static int totalLongSignals = 0; +static int totalShortSignals = 0; + +// +static double initialBalance = 0; + +// +static int countedBars = 0; +static bool isNewBar = false; +static bool isNewDay = false; + +// +static XMAState xmaStates[]; +static XOSCState oscStates[]; +static XMKTState xmktStates[]; +static XSHPDState shpdStates[]; + +// +// Retrieve State ... +XOSCState GetOSCState( + const int bar_index, + const int foLen, + const double foMul, + const int slLen, + const double slMul +) { + // + // Define Trend Direction Related Values ... + // + XOSCState result = {}; + + // + // START Extract Data from Oscillator ... + // + // + // Fast OSC ... + double fastOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 0, // Fast OSC Buffer Index ... + bar_index + ); + result.fastOSC = fastOSC; + + // + // Slow OSC ... + double slowOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 1, // Slow OSC Buffer Index ... + bar_index + ); + result.slowOSC = slowOSC; + + // + // Power OSC ... + double powerOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 2, // Power OSC Buffer Index ... + bar_index + ); + result.powerOSC = powerOSC; + + // + // Var OSC ... + double varOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 3, // Var OSC Buffer Index ... + bar_index + ); + result.varOSC = varOSC; + + // + // Tan FS OSC ... + double tanFSOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 4, // Tan F/S OSC Buffer Index ... + bar_index + ); + result.tanFSOSC = tanFSOSC; + // + // END Extract Data from Oscillator ... + // + + // + return result; +} + +// +// Check Market Ranging or not based on OSC ... +bool IsOSCMarketRanging( + // + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double rangingThreshold, // Detect Ranging based On Power OSC ... + // + // OSC Specifications ... + const int foLen, // Fast OSC Length ... + const double foMul, // Fast OSC Multiplier ... + const int slLen, // Slow OSC Length ... + const double slMul // Slow OSC Multiplier ... +) { + // + bool result = false; + + // + // Detect Buffer Size ... + const int bufferSize = marketLen + bar_index; + double powerOSCBuffer[]; + ArraySetAsSeries( + powerOSCBuffer, + true + ); + ArrayResize( + powerOSCBuffer, + bufferSize + ); + + // + // Loop through Market for Extract PowerOSC from OSC Indicator ... + for (int i = bufferSize - 1; i >= 0; i--) { + // + // Retrieve OSC State at Specific Bar Index ... + XOSCState state = GetOSCState( + i, + foLen, + foMul, + slLen, + slMul + ); + + // + powerOSCBuffer[i] = state.powerOSC; + } + + // + // now we have to extract min and max value of Splitted Buffer ... + XMinMax minMax = GetBufferMinMax(powerOSCBuffer); + + // + // now Check Min and Max Direction and Compare them with Ranging Value ... + result = MathAbs(minMax.min) > rangingThreshold + || MathAbs(minMax.max) > rangingThreshold; + + // + return result; +} + +// +// Retrieve and Calculate XMA State ... +XMAState GetXMAState( + // + // Market Specification Inpouts ... + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + const double stp, // SAR Step ... + const double maxm, // SAR Maximum ... + // + // XMA Inputs ... + const int scFastMul, // Short Cycle Fast Multiplier ... + const int scSlowMul, // Short Cycle Slow Multiplier ... + const int mcFastMul, // Medium Cycle Fast Multiplier ... + const int mcSlowMul, // Medium Cycle Slow Multiplier ... + const int lcFastMul, // Long Cycle Fast Multiplier ... + const int lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + const bool showPSr, // Show Parabolic Sar + const bool showMMiddle, // Show Market Middle ... + const bool showSC, // Show Short Cycle + const bool showSCCrossLines, // Show Short Cycle Vertical Lines + const bool showMC, // Show Medium Cycle + const bool showMCCrossLines, // Show Medium Cycle Vertical Lines + const bool showLC, // Show Long Cycle + const bool showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + const color pSrColor, // Parabolic Sar Color + const color scFastColor, // Short Cycle Fast Color ... + const color scSlowColor, // Short Cycle Slow Color ... + const color mcFastColor, // Medium Cycle Fast Color ... + const color mcSlowColor, // Medium Cycle Slow Color ... + const color lcFastColor, // Medium Cycle Fast Color ... + const color lcSlowColor // Medium Cycle Slow Color ... +) { + // + // Temp Result ... + XMAState result = {}; + + // + // START Reading Buffers ... + // + // + // Define BufferIndexes ... + int scFastBufIndex = 0; + int scSlowBufIndex = 1; + int mcFastBufIndex = 2; + int mcSlowBufIndex = 3; + int lcFastBufIndex = 4; + int lcSlowBufIndex = 5; + int midBufIndex = 6; + int pSarBufIndex = 7; + + // + // START Short Cycle ... + // + // + // Short Cycle Fast ... + double scFast = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + stp, // PSAR Step ... + maxm, // PSAR Maximum ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showPSr, // Show Parabolic SAR ... + showMMiddle, // Show Market Middle ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + pSrColor, // Parabolic Sar Color ... + scFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + scFastBufIndex, // Buffer Index ... + bar_index + ); + result.scFast = scFast; + + // + // Short Cycle Slow ... + double scSlow = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + stp, // PSAR Step ... + maxm, // PSAR Maximum ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showPSr, // Show Parabolic SAR ... + showMMiddle, // Show Market Middle ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + pSrColor, // Parabolic Sar Color ... + scFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + scSlowBufIndex, // Buffer Index ... + bar_index + ); + result.scSlow = scSlow; + // + // END Short Cycle ... + // + + // + // START Medium Cycle ... + // + // + // Medium Cycle Fast ... + double mcFast = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + stp, // PSAR Step ... + maxm, // PSAR Maximum ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showPSr, // Show Parabolic SAR ... + showMMiddle, // Show Market Middle ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + pSrColor, // Parabolic Sar Color ... + scFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + mcFastBufIndex, // Buffer Index ... + bar_index + ); + result.mcFast = mcFast; + + // + // Medium Cycle Slow ... + double mcSlow = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + stp, // PSAR Step ... + maxm, // PSAR Maximum ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showPSr, // Show Parabolic SAR ... + showMMiddle, // Show Market Middle ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + pSrColor, // Parabolic Sar Color ... + scFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + mcSlowBufIndex, // Buffer Index ... + bar_index + ); + result.mcSlow = mcSlow; + // + // END Medium Cycle ... + // + + // + // START Long Cycle ... + // + // + // Long Cycle Fast ... + double lcFast = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + stp, // PSAR Step ... + maxm, // PSAR Maximum ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showPSr, // Show Parabolic SAR ... + showMMiddle, // Show Market Middle ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + pSrColor, // Parabolic Sar Color ... + scFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + lcFastBufIndex, // Buffer Index ... + bar_index + ); + result.lcFast = lcFast; + + // + // Long Cycle Slow ... + double lcSlow = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + stp, // PSAR Step ... + maxm, // PSAR Maximum ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showPSr, // Show Parabolic SAR ... + showMMiddle, // Show Market Middle ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + pSrColor, // Parabolic Sar Color ... + scFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + lcSlowBufIndex, // Buffer Index ... + bar_index + ); + result.lcSlow = lcSlow; + // + // END Long Cycle ... + // + + // + // START Makret Middleage ... + // + // + // Market Middleage ... + double marketMiddleage = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + stp, // PSAR Step ... + maxm, // PSAR Maximum ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showPSr, // Show Parabolic SAR ... + showMMiddle, // Show Market Middle ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + pSrColor, // Parabolic Sar Color ... + scFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + midBufIndex, // Buffer Index ... + bar_index + ); + result.marketMiddleage = marketMiddleage; + // + // END Makret Middleage ... + // + + // + // START Parabolic SAR ... + // + // + // Parabolic ... + double parabolicSAR = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + stp, // PSAR Step ... + maxm, // PSAR Maximum ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showPSr, // Show Parabolic SAR ... + showMMiddle, // Show Market Middle ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + pSrColor, // Parabolic Sar Color ... + scFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + pSarBufIndex, // Buffer Index ... + bar_index + ); + result.parabolicSAR = parabolicSAR; + // + // END Makret Middleage ... + // + // + // END Reading Buffers ... + // + + // + return result; +} + +// +// Retrieve Market State ... +XMKTState GetMarketState( + // + const int bar_index, + // + const int marketLen, + // + const bool showHH, // Show Highest High ... + const color hhColor, // Show Highest High ... + const ENUM_LINE_STYLE hhStyle, // Show Highest High ... + // + const bool showHL, // Show Highest Low ... + const color hlColor, // Show Highest Low ... + const ENUM_LINE_STYLE hlStyle, // Show Highest Low ... + // + const bool showHO, // Show Highest Open ... + const color hoColor, // Show Highest Open ... + const ENUM_LINE_STYLE hoStyle, // Show Highest Open ... + // + const bool showHC, // Show Highest Close ... + const color hcColor, // Show Highest Close ... + const ENUM_LINE_STYLE hcStyle, // Show Highest Close ... + // + const bool showLH, // Show Lowest High ... + const color lhColor, // Show Lowest High ... + const ENUM_LINE_STYLE lhStyle, // Show Lowest High ... + // + const bool showLL, // Show Lowest Low ... + const color llColor, // Show Lowest Low ... + const ENUM_LINE_STYLE llStyle, // Show Lowest Low ... + // + const bool showLO, // Show Lowest Open ... + const color loColor, // Show Lowest Open ... + const ENUM_LINE_STYLE loStyle, // Show Lowest Open ... + // + const bool showLC, // Show Lowest Close ... + const color lcColor, // Show Lowest Close ... + const ENUM_LINE_STYLE lcStyle // Show Lowest Close ... +) { + // + XMKTState result = {}; + + // + int hHBufIndex = 0; + int hLBufIndex = 1; + int hOBufIndex = 2; + int hCBufIndex = 3; + int lHBufIndex = 4; + int lLBufIndex = 5; + int lOBufIndex = 6; + int lCBufIndex = 7; + + // + // START Reading Buffers ... + // + // + // Highest High ... + double hhValue = iCustom( + _Symbol, + _Period, + xmarketIndicatorName, + // + // Inputs ... + marketLen, // Market Length ... + // + // Show/Hide ... + showHH, // Show Highest High ... + showHL, // Show Highest Low ... + showHO, // Show Highest Open ... + showHC, // Show Highest Close ... + showLH, // Show Lowest High ... + showLL, // Show Lowest Low ... + showLO, // Show Lowest Open ... + showLC, // Show Lowest Close ... + // + // Colors ... + hhColor, // Show Highest High ... + hlColor, // Show Highest Low ... + hoColor, // Show Highest Open ... + hcColor, // Show Highest Close ... + lhColor, // Show Lowest High ... + llColor, // Show Lowest Low ... + loColor, // Show Lowest Open ... + lcColor, // Show Lowest Close ... + // + // Styles ... + hhStyle, // Show Highest High ... + hlStyle, // Show Highest Low ... + hoStyle, // Show Highest Open ... + hcStyle, // Show Highest Close ... + lhStyle, // Show Lowest High ... + llStyle, // Show Lowest Low ... + loStyle, // Show Lowest Open ... + lcStyle, // Show Lowest Close ... + // + hHBufIndex, // Buffer Index ... + bar_index // Bar Index ... + ); + result.highestHigh = hhValue; + + // + // Highest Low ... + double hlValue = iCustom( + _Symbol, + _Period, + xmarketIndicatorName, + // + // Inputs ... + marketLen, // Market Length ... + // + // Show/Hide ... + showHH, // Show Highest High ... + showHL, // Show Highest Low ... + showHO, // Show Highest Open ... + showHC, // Show Highest Close ... + showLH, // Show Lowest High ... + showLL, // Show Lowest Low ... + showLO, // Show Lowest Open ... + showLC, // Show Lowest Close ... + // + // Colors ... + hhColor, // Show Highest High ... + hlColor, // Show Highest Low ... + hoColor, // Show Highest Open ... + hcColor, // Show Highest Close ... + lhColor, // Show Lowest High ... + llColor, // Show Lowest Low ... + loColor, // Show Lowest Open ... + lcColor, // Show Lowest Close ... + // + // Styles ... + hhStyle, // Show Highest High ... + hlStyle, // Show Highest Low ... + hoStyle, // Show Highest Open ... + hcStyle, // Show Highest Close ... + lhStyle, // Show Lowest High ... + llStyle, // Show Lowest Low ... + loStyle, // Show Lowest Open ... + lcStyle, // Show Lowest Close ... + // + hLBufIndex, // Buffer Index ... + bar_index // Bar Index ... + ); + result.highestLow = hlValue; + + // + // Highest Open ... + double hoValue = iCustom( + _Symbol, + _Period, + xmarketIndicatorName, + // + // Inputs ... + marketLen, // Market Length ... + // + // Show/Hide ... + showHH, // Show Highest High ... + showHL, // Show Highest Low ... + showHO, // Show Highest Open ... + showHC, // Show Highest Close ... + showLH, // Show Lowest High ... + showLL, // Show Lowest Low ... + showLO, // Show Lowest Open ... + showLC, // Show Lowest Close ... + // + // Colors ... + hhColor, // Show Highest High ... + hlColor, // Show Highest Low ... + hoColor, // Show Highest Open ... + hcColor, // Show Highest Close ... + lhColor, // Show Lowest High ... + llColor, // Show Lowest Low ... + loColor, // Show Lowest Open ... + lcColor, // Show Lowest Close ... + // + // Styles ... + hhStyle, // Show Highest High ... + hlStyle, // Show Highest Low ... + hoStyle, // Show Highest Open ... + hcStyle, // Show Highest Close ... + lhStyle, // Show Lowest High ... + llStyle, // Show Lowest Low ... + loStyle, // Show Lowest Open ... + lcStyle, // Show Lowest Close ... + // + hOBufIndex, // Buffer Index ... + bar_index // Bar Index ... + ); + result.highestOpen = hoValue; + + // + // Highest Close ... + double hcValue = iCustom( + _Symbol, + _Period, + xmarketIndicatorName, + // + // Inputs ... + marketLen, // Market Length ... + // + // Show/Hide ... + showHH, // Show Highest High ... + showHL, // Show Highest Low ... + showHO, // Show Highest Open ... + showHC, // Show Highest Close ... + showLH, // Show Lowest High ... + showLL, // Show Lowest Low ... + showLO, // Show Lowest Open ... + showLC, // Show Lowest Close ... + // + // Colors ... + hhColor, // Show Highest High ... + hlColor, // Show Highest Low ... + hoColor, // Show Highest Open ... + hcColor, // Show Highest Close ... + lhColor, // Show Lowest High ... + llColor, // Show Lowest Low ... + loColor, // Show Lowest Open ... + lcColor, // Show Lowest Close ... + // + // Styles ... + hhStyle, // Show Highest High ... + hlStyle, // Show Highest Low ... + hoStyle, // Show Highest Open ... + hcStyle, // Show Highest Close ... + lhStyle, // Show Lowest High ... + llStyle, // Show Lowest Low ... + loStyle, // Show Lowest Open ... + lcStyle, // Show Lowest Close ... + // + hCBufIndex, // Buffer Index ... + bar_index // Bar Index ... + ); + result.highestClose = hcValue; + + // + // Lowest High ... + double lhValue = iCustom( + _Symbol, + _Period, + xmarketIndicatorName, + // + // Inputs ... + marketLen, // Market Length ... + // + // Show/Hide ... + showHH, // Show Highest High ... + showHL, // Show Highest Low ... + showHO, // Show Highest Open ... + showHC, // Show Highest Close ... + showLH, // Show Lowest High ... + showLL, // Show Lowest Low ... + showLO, // Show Lowest Open ... + showLC, // Show Lowest Close ... + // + // Colors ... + hhColor, // Show Highest High ... + hlColor, // Show Highest Low ... + hoColor, // Show Highest Open ... + hcColor, // Show Highest Close ... + lhColor, // Show Lowest High ... + llColor, // Show Lowest Low ... + loColor, // Show Lowest Open ... + lcColor, // Show Lowest Close ... + // + // Styles ... + hhStyle, // Show Highest High ... + hlStyle, // Show Highest Low ... + hoStyle, // Show Highest Open ... + hcStyle, // Show Highest Close ... + lhStyle, // Show Lowest High ... + llStyle, // Show Lowest Low ... + loStyle, // Show Lowest Open ... + lcStyle, // Show Lowest Close ... + // + lHBufIndex, // Buffer Index ... + bar_index // Bar Index ... + ); + result.lowestHigh = lhValue; + + // + // Lowest Low ... + double llValue = iCustom( + _Symbol, + _Period, + xmarketIndicatorName, + // + // Inputs ... + marketLen, // Market Length ... + // + // Show/Hide ... + showHH, // Show Highest High ... + showHL, // Show Highest Low ... + showHO, // Show Highest Open ... + showHC, // Show Highest Close ... + showLH, // Show Lowest High ... + showLL, // Show Lowest Low ... + showLO, // Show Lowest Open ... + showLC, // Show Lowest Close ... + // + // Colors ... + hhColor, // Show Highest High ... + hlColor, // Show Highest Low ... + hoColor, // Show Highest Open ... + hcColor, // Show Highest Close ... + lhColor, // Show Lowest High ... + llColor, // Show Lowest Low ... + loColor, // Show Lowest Open ... + lcColor, // Show Lowest Close ... + // + // Styles ... + hhStyle, // Show Highest High ... + hlStyle, // Show Highest Low ... + hoStyle, // Show Highest Open ... + hcStyle, // Show Highest Close ... + lhStyle, // Show Lowest High ... + llStyle, // Show Lowest Low ... + loStyle, // Show Lowest Open ... + lcStyle, // Show Lowest Close ... + // + lLBufIndex, // Buffer Index ... + bar_index // Bar Index ... + ); + result.lowestLow = llValue; + + // + // Lowest Open ... + double loValue = iCustom( + _Symbol, + _Period, + xmarketIndicatorName, + // + // Inputs ... + marketLen, // Market Length ... + // + // Show/Hide ... + showHH, // Show Highest High ... + showHL, // Show Highest Low ... + showHO, // Show Highest Open ... + showHC, // Show Highest Close ... + showLH, // Show Lowest High ... + showLL, // Show Lowest Low ... + showLO, // Show Lowest Open ... + showLC, // Show Lowest Close ... + // + // Colors ... + hhColor, // Show Highest High ... + hlColor, // Show Highest Low ... + hoColor, // Show Highest Open ... + hcColor, // Show Highest Close ... + lhColor, // Show Lowest High ... + llColor, // Show Lowest Low ... + loColor, // Show Lowest Open ... + lcColor, // Show Lowest Close ... + // + // Styles ... + hhStyle, // Show Highest High ... + hlStyle, // Show Highest Low ... + hoStyle, // Show Highest Open ... + hcStyle, // Show Highest Close ... + lhStyle, // Show Lowest High ... + llStyle, // Show Lowest Low ... + loStyle, // Show Lowest Open ... + lcStyle, // Show Lowest Close ... + // + lOBufIndex, // Buffer Index ... + bar_index // Bar Index ... + ); + result.lowestOpen = loValue; + + // + // Lowest Close ... + double lcValue = iCustom( + _Symbol, + _Period, + xmarketIndicatorName, + // + // Inputs ... + marketLen, // Market Length ... + // + // Show/Hide ... + showHH, // Show Highest High ... + showHL, // Show Highest Low ... + showHO, // Show Highest Open ... + showHC, // Show Highest Close ... + showLH, // Show Lowest High ... + showLL, // Show Lowest Low ... + showLO, // Show Lowest Open ... + showLC, // Show Lowest Close ... + // + // Colors ... + hhColor, // Show Highest High ... + hlColor, // Show Highest Low ... + hoColor, // Show Highest Open ... + hcColor, // Show Highest Close ... + lhColor, // Show Lowest High ... + llColor, // Show Lowest Low ... + loColor, // Show Lowest Open ... + lcColor, // Show Lowest Close ... + // + // Styles ... + hhStyle, // Show Highest High ... + hlStyle, // Show Highest Low ... + hoStyle, // Show Highest Open ... + hcStyle, // Show Highest Close ... + lhStyle, // Show Lowest High ... + llStyle, // Show Lowest Low ... + loStyle, // Show Lowest Open ... + lcStyle, // Show Lowest Close ... + // + lCBufIndex, // Buffer Index ... + bar_index // Bar Index ... + ); + result.lowestClose = lcValue; + + // + // END Reading Buffers ... + // + + // + return result; +} + +// +// Retrieve XSHPD State ... +XSHPDState GetXSHPDState( + // + const int bar_index, + // + const int marketLen, + // + const double shpDetectMul, // Sharp Detect Multiplier ... + const bool drwLbls, // Draw Labels on Founded Sharps ... + // + const string shpBullLabel, // Sharp Bullish Label ... + const color shpBullColor, // Sharp Bullish color ... + // + const string shpBearLabel, // Sharp Bearish Label ... + const color shpBearColor // Sharp Bearish color ... +) { + // + // Temp result ... + XSHPDState result = {}; + + // + int sharpBullishBufIndex = 2; + int sharpBearishBufIndex = 3; + + // + double sharpBullishValue = iCustom( + _Symbol, + _Period, + shpdIndicatorName, + // + // Inputs ... + marketLen, + shpDetectMul, + drwLbls, + shpBullLabel, + shpBullColor, + shpBearLabel, + shpBearColor, + // + sharpBullishBufIndex, // Buffer Index ... + bar_index // Bar Index ... + ); + result.isSharpBullishDetected = + (int) sharpBullishValue == 1 + ? true + : false; + + // + double sharpBearishValue = iCustom( + _Symbol, + _Period, + shpdIndicatorName, + // + // Inputs ... + marketLen, + shpDetectMul, + drwLbls, + shpBullLabel, + shpBullColor, + shpBearLabel, + shpBearColor, + // + sharpBearishBufIndex, // Buffer Index ... + bar_index // Bar Index ... + ); + result.isSharpBearishDetected = + (int) sharpBearishValue == 1 + ? true + : false; + + // + return result; +} + +// +// Calculate Fib Level ... +double GetFibonacciLevel( + double upPrice, + double downPrice, + double level, + X_DIRECTION direction +) { + // + double ling = upPrice - downPrice; + double pLevel = (ling / 100) * (level * 100); + + // + double result = direction == X_UP ? + upPrice - pLevel : + downPrice + pLevel; + result = NormalizeDouble(result, _Digits); + + // + return result; +} +// +// END Global Requirement Functions ... +// + +// +// START Signal Verification Functions ... +// +// +// END Signal Verification Functions ... +// + +// +// START Market State Functions ... +// +// +// END Market State Functions ... +// + +// +// Retrieve Signal Bar Index ... +int GetSignalBarIndex(XSignal &signal) { + // + // Temp Result ... + int result = -1; + + // + // Retriev Signal Bar Index ... + result = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + return result; +} + +// +// Generate a Unique ID for Signal ... +string GenerateSignalTAG( + const XSignal &signal, + const string tag, + const string longSignalLabel, + const string shortSignalLabel +) { + // + // Generate Propper Label for Signal ... + string label = signal.type == X_LONG ? longSignalLabel : signal.type == X_SHORT ? shortSignalLabel : "UN_KNOWN"; + + // + // Generate Unique String Identifier for Signal ... + string result = tag + + "_[ID:" + IntegerToString(signal.id) + "]" + + "_[SG:" + signal.comment + "]" + + "_[" + label + "]" + + "_[" + signal.symbol + "]" + + "_[Time:" + TimeToStr(signal.time) + "]" + + "_[TP:" + DoubleToString(signal.tp) + "]" + + "_[SL:" + DoubleToString(signal.sl) + "]"; + + // + return result; +} + +// +// Draw Signal Shapes on Chart ... +bool DrawSignal( + const XSignal &signal, + long chartID = 0, + int subWindowID = 0, + const double positionThresholdFactor = 10, + string signalTag = "X-Signal", + string longSignalLabel = "X-Long", + color longSignalColor = clrAqua, + string shortSignalLabel = "X-Short", + color shortSignalColor = clrFuchsia +) { + // + // Generate isLongSignal Var ... + bool isLongSignal = signal.type == X_LONG; + + // + // Signal Bar Index ... + int bar_index = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // START Draw Signal Arrow ... + // + // + // Arrow Shape Name ... + string arrowName = StringConcatenate(signalTag, "_Arrow_", signal.id); + + // + // Arrow Price ... + double arrowPrice = 0; + if (isLongSignal) { + // + arrowPrice = iLow( + _Symbol, + _Period, + bar_index + ); + + // + arrowPrice = arrowPrice - (positionThresholdFactor * _Point); + } else { + // + arrowPrice = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + arrowPrice = arrowPrice + (positionThresholdFactor * _Point); + } + + // + // Arrow Code ... + uchar arrowCode = isLongSignal ? SYMBOL_ARROWUP : SYMBOL_ARROWDOWN; + + // + // Arrow Anchor Point ... + ENUM_ARROW_ANCHOR arrowAnchorPoint = isLongSignal ? ANCHOR_BOTTOM : ANCHOR_TOP; + + // + // Arrow Color ... + color arrowColor = isLongSignal ? longSignalColor : shortSignalColor; + + // + // Draw Signal Arrow Shape ... + bool result = DrawArrow( + chartID, + arrowName, + subWindowID, + signal.time, + arrowPrice, + arrowCode, + arrowAnchorPoint, + arrowColor, + STYLE_SOLID, + 3, + false, + false, + false, + 0 + ); + // + // END Draw Signal Arrow ... + // + + // + // START Draw Signal SL/TP ... + // + string slLineName = StringConcatenate(signalTag, "_SL_", signal.id); + string tpLineName = StringConcatenate(signalTag, "_TP_", signal.id); + string entryLineName = StringConcatenate(signalTag, "_ENTRY_", signal.id); + + // + color slColor = shortSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color tpColor = longSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color entryColor = clrGreen; + + // + datetime time1 = iTime( + _Symbol, + _Period, + bar_index + 1 + ); + + // + // Draw Enrty Price ... + result = DrawTrendLine( + chartID, + entryLineName, + subWindowID, + time1, + signal.entryPrice, + signal.time, + signal.entryPrice, + entryColor, + STYLE_SOLID, + 2 + ); + + // + // Draw Signal SL ... + if (signal.sl > 0) { + // + result = DrawTrendLine( + chartID, + slLineName, + subWindowID, + time1, + signal.sl, + signal.time, + signal.sl, + slColor, + STYLE_SOLID, + 2 + ); + } + + // + // Draw Signal TP ... + if (signal.tp > 0) { + // + result = DrawTrendLine( + chartID, + tpLineName, + subWindowID, + time1, + signal.tp, + signal.time, + signal.tp, + tpColor, + STYLE_SOLID, + 2 + ); + } + // + // END Draw Signal SL/TP ... + // + + // + // Start Draw Signal Label ... + // + // + string labelName = StringConcatenate(signalTag, "_Label_", signal.id); + + // + double labelPrice = isLongSignal ? arrowPrice - (positionThresholdFactor * _Point) : arrowPrice + (positionThresholdFactor * _Point); + + // + string labelText = isLongSignal ? longSignalLabel : shortSignalLabel; + labelText = StringConcatenate( + labelText, + "\n", + signal.comment + ); + + // + result = DrawText( + chartID, + labelName, + subWindowID, + signal.time, + labelPrice, + labelText, + "Arial", + 8, + arrowColor, + 0, + ANCHOR_CENTER + ); + // + // End Draw Signal Label ... + // + + // + return result; +} + +// +// Trade on Specific Signal ... +bool TradeSignal( + XSignal &signal, + // + string prefix, + // + double volumePercent, + // + // Long ... + const string longSignalLabel, + const color longSignalColor, + // + // Short ... + const string shortSignalLabel, + const color shortSignalColor, + // + // Define Signal Identifiers ... + const string oscSignalId, // Signal Identifier ... + const string xmaSignalId, // Signal Identifier ... + const string xshpSignalId, // Signal Identifier ... + const string xmntmSignalId, // Signal Identifier ... + const string xrsiSignalId // Signal Identifier ... +) { + // + // Temp Result ... + bool result = false; + + // + if (initialBalance == 0) { + initialBalance = AccountInfoDouble(ACCOUNT_BALANCE); + } + + // + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + int openPositions = CountOpenTrades(); + double volume = (volumePercent * initialBalance); + + // + if ( + signal.type != X_LONG && + signal.type != X_SHORT + ) { + return result; + } + + // + bool hasLongSignal = signal.type == X_LONG; + + // + // Check TP and Entry Price ... + if ( + ( + hasLongSignal + && signal.entryPrice > signal.tp + ) || + ( + !hasLongSignal + && signal.entryPrice < signal.tp + ) + ) { + return result; + } + + // + // Order Operation ... + int operation = hasLongSignal ? + OP_BUY : + OP_SELL; + + // + // Detect Trade Color ... + color clr = hasLongSignal ? + longSignalColor : + shortSignalColor; + + // + // Generate Signal Comment ... + string label = hasLongSignal ? + longSignalLabel : + shortSignalLabel; + + // + // Generate Signal Comment ... + string comment = StringConcatenate( + prefix, + "_", signal.id, + "_", label, + "_", signal.comment + ); + + // + // Placing Order ... + int orderTicket = OrderSend( + _Symbol, + operation, + volume, + signal.entryPrice, + 3, + signal.sl, + signal.tp, + comment, + signal.id, + 0, + clr + ); + + // + // Draw Signal Shape if Order Opened Successfully ... + if (orderTicket >= 0) { + // + signal.ticket = orderTicket; + + // + // Here i must to Draw Signal Shapes ... + DrawSignal( + signal, + 0, + 0, + 50, + prefix, // Signal Tag ... + longSignalLabel, // Long Signal Label ... + longSignalColor, + shortSignalLabel, // Short Signal Label ... + shortSignalColor + ); + + // + // Logging Signal Provider ... + LogMessage( + StringConcatenate( + "Order [", orderTicket ,"]: Provided by: ", signal.comment + ) + ); + + // + // TODO: Add Exit Strategy ... + // // + // if (signal.comment == oscSignalId) { + // // + // ArrayResize( + // oscSignals, + // ArraySize(oscSignals) + 1 + // ); + + // // + // oscSignals[ArraySize(oscSignals) - 1] = signal; + // } else if (signal.comment == xmaSignalId) { + // // + // ArrayResize( + // xmaSignals, + // ArraySize(xmaSignals) + 1 + // ); + + // // + // xmaSignals[ArraySize(xmaSignals) - 1] = signal; + // } else if (signal.comment == xshpSignalId) { + // // + // ArrayResize( + // xshpSignals, + // ArraySize(xshpSignals) + 1 + // ); + + // // + // xshpSignals[ArraySize(xshpSignals) - 1] = signal; + // } + + // + // TODO: here we have to check if there are another + // open positions which their entry price is bigger + // than current signal entry price, for long trades and + // their tp is high than current tp, ... + // close in profit trades or modify orders tp to current ... + // // + // if (CountOpenTrades() > 0) { + // // + // // Here we have to + // // ModifyOpenTradesBasedOnCurrentTrade(signal); + // } + + // + result = true; + } + + // + return result; +} +// +// END Signal Related Functions ... +// + +// +// START Orders Functions ... +// +// +// Convert To XSignal Model ... +XSignal OrderToSignal() { + // + // Temp Result ... + XSignal result = {}; + result.type = X_NONE; + + // + // Here we can get some usefull info based on selected order ... + double swap = OrderSwap(); + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + int magicNumber = OrderMagicNumber(); + double takeProfit = OrderTakeProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // Conver Position to Signal ... + result.sl = stopLoss; + result.tp = takeProfit; + result.time = openTime; + result.symbol = _Symbol; + result.id = magicNumber; + result.entryPrice = openPrice; + result.type = isLongOrder ? X_LONG : X_SHORT; + + // + return result; +} + +// +// START Count Orders ... +// +// +// Count Open Positions ... +int CountOpenTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if (OrderSymbol() == _Symbol) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Long Positions ... +int CountOpenLongTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_BUY + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Short Positions ... +int CountOpenShortTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_SELL + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} +// +// END Count Orders ... +// + +// +// START Close Orders ... +// +// +// Close All Open Trades ... +bool CloseAllTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + + // + return result; +} + +// +// Close All Open Long Trades ... +bool CloseAllLongTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Long Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Short Trades ... +bool CloseAllShortTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (!isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Short Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In Profit Trades ... +bool CloseAllInProfitTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if (profit > 0) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InProfit Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In DrawDown Trades ... +bool CloseAllInDrawDownTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if (profit < 0) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close Biggest In DrawDown Trades ... +bool CloseBiggestDrawDownTrade() { + // + // Loop through all Positions ... + bool result = false; + double drawDown = 0; + + // + // Find Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) > drawDown + ) { + drawDown = profit; + } + } + } + } + + // + // Close Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) >= drawDown + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Max InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Long Time Trades ... +bool CloseAllLongTimeTrades( + const int passedCandles +) { + // + bool result = false; + + // + if (passedCandles <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + + // + if ( + openBarIndex - currentBarIndex >= passedCandles + || ( + profit > 0.5 + && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 3) + ) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Long Time issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } else if ( + openTrades > 0 + && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 2) + ) { + result = CloseAllInProfitTrades(); + // && CloseBiggestDrawDownTrade(); + } + } + } + } + + // + return result; +} + +// +// Close all trades which passed Maximum Drawdown ... +bool CloseAllMaximumDrawDownPassedTrades( + const double maxDrDownPercentPerPTrade +) { + // + if ( + initialBalance <= 0 + || maxDrDownPercentPerPTrade <= 0 + ) { + return false; + } + + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double maxAllowedDrawDown = -1 * (initialBalance * maxDrDownPercentPerPTrade); + + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + if ( + profit < 0 + && MathAbs(profit) >= MathAbs(maxAllowedDrawDown) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Maximum DarwDown issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Trades Which Opens before Specified Length ... +bool CloseAllTradesWhichOpenInPastMarketLength( + const int marketLen +) { + // + bool result = false; + + // + if (marketLen <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + + // + if (openBarIndex <= currentBarIndex + marketLen) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Market Reverse issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } else if (openTrades > 0) { + // + // Close all InProfit Trdes and Biggest InDrawDown Trades ... + result = CloseAllInProfitTrades(); + // && CloseBiggestDrawDownTrade(); + } + } + } + } + + // + return result; +} +// +// END Close Orders ... +// + +// +// START Modify Orders ... +// +// +void ModifyAllPriceLesserOpenTrades( + const XSignal &signal +) { + // + // Loop through all Open Trades ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + double takeProfit = OrderTakeProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // When new Signal Comming with price less than + // currently open trade and tp less than currently + // open trade, this means a market change happens ... + // here we can Close InProfit Trades or Modify Trades TP ... + if ( + openPrice < signal.entryPrice + && takeProfit > signal.tp + ) { + bool result = OrderModify( + ticket, + openPrice, + signal.sl, + signal.tp, + clrYellow + ); + } + } + } + } +} + +// +void ModifyOpenTradesBasedOnCurrentTrade( + const XSignal &signal +) { + // + ModifyAllPriceLesserOpenTrades(signal); +} +// +// END Modify Orders ... +// +// +// END Orders Functions ... +// diff --git a/Bkp/Used/14020420/x-saherelm.cci.ea.mq4 b/Bkp/Used/14020420/x-saherelm.cci.ea.mq4 new file mode 100644 index 0000000..3697d14 --- /dev/null +++ b/Bkp/Used/14020420/x-saherelm.cci.ea.mq4 @@ -0,0 +1,532 @@ +//+------------------------------------------------------------------+ +//| x-saherelm.ea | +//| Copyright 2023, SaherElm IT Center | +//| https://www.saherelm.ir | +//+------------------------------------------------------------------+ +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Inputs ... +input double riskToReward = 1.5; // Risk To Reward Ratio + +// +// Define Models ... +// +// Signal Providers ... +enum ENUM_XSIGNAL_PROVIDER { + X_UNKNOWN_PROVIDER = 0, + X_CCI_PROVIDER = 1 +}; + +// +// Signal Type ... +enum ENUM_XSIGNAL_TYPE { + X_NONE = 0, + X_BUY = 1, + X_SELL = 2 +}; + +// +// Signal ... +struct XSignal { + // + // Signal Type ... + ENUM_XSIGNAL_TYPE type; + + // + // Signal ID ... + int id; + + // + // Signal Ticket Number, when Opening Trade ... + int ticket; + + // + // Signal Provider ... + ENUM_XSIGNAL_PROVIDER provider; + + // + // Target Point ... + double tp; + + // + // Stop Loss ... + double sl; + + // + // Signal Entry Price ... + double price; + + // + // Signalling Time ... + datetime time; +}; + +// +// CCI Based Signal Conditions ... +struct XCCILongSignalConditions { + // + datetime start; + + // + datetime crossOverMinusHundredTime; + datetime crossUnderMinusHundredTime; + + // + double crossOverSlope; +}; + +// +bool isNewBar = false; + +// +int countedBars = 0; +int totalSignals = 0; +int lastSignalledBar = 0; + +// +XCCILongSignalConditions cciLongConds = {}; + +//+------------------------------------------------------------------+ +//| Expert initialization function | +//+------------------------------------------------------------------+ +int OnInit() +{ + return(INIT_SUCCEEDED); +} + +//+------------------------------------------------------------------+ +//| Expert tick function | +//+------------------------------------------------------------------+ +void OnTick() +{ + // + isNewBar = IsNewBar(); + + // + if (isNewBar) { + // + countedBars++; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + 0 + ); + + // + bool hasSignal = false; + bool hasLongSignal = false; + bool hasShortSignal = false; + + // + // Generate Signals Based On iCCI ... + CheckCCILongSignalConditions(0); + + // + // Long Signal ... + hasLongSignal = + // + // Check CCI Long Signal is Valid ... + ValidateCCILongConditions(); + + // + // Signal ... + hasSignal = hasLongSignal || hasShortSignal; + + // + // Prevent Going Forward when there is no Signal ... + if (!hasSignal) { + return; + } + + // + if (lastSignalledBar == countedBars) { + return; + } + + // + totalSignals++; + lastSignalledBar = countedBars; + + // + // Get CCI Long Signal ... + XSignal signal = {}; + + // + if (hasLongSignal) { + signal = GenerateCCILongSignal(); + } + + // + TradeOnSignal(signal); + + // + Print("CCI Long Signal ..."); + + // + ClearCCILongSignalConditions(); +} + +// +// Trade Based On Signal ... +void TradeOnSignal( + XSignal &signal +) { + // + if (signal.type == X_NONE) { + return; + } + + // + bool isLongSignal = signal.type == X_BUY; + + // + // Order Operation ... + int operation = isLongSignal ? + OP_BUY : + OP_SELL; + + // + // Detect Trade Color ... + color clr = isLongSignal ? + clrAqua : + clrFuchsia; + + // + // Generate Signal Comment ... + string label = isLongSignal ? + "BUY" : + "SELL"; + + // + // Generate Signal Comment ... + string comment = StringConcatenate( + "XCCI", + "_", signal.id, + "_", label + ); + + // + // Placing Order ... + int orderTicket = OrderSend( + _Symbol, + operation, + 0.01, + signal.price, + 3, + signal.sl, + signal.tp, + comment, + signal.id, + 0, + clr + ); + + // + // Draw Signal Shape if Order Opened Successfully ... + if (orderTicket >= 0) { + // + signal.ticket = orderTicket; + Print("Order: ", orderTicket, " ..."); + } +} + +// +// Convert CCI Long Signal Conditions to XSignal ... +XSignal GenerateCCILongSignal() { + // + XSignal result = {}; + + // + // Price Calculations ... + // + RefreshRates(); + + // + double entryPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double exitPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = GetLowestLow(); + double hh = GetHighestHigh(); + double pSar = iSAR( + _Symbol, + _Period, + 0.002, + 0.02, + 0 + ); + + // + double sl = ll; + + // + double risk = entryPrice - ll; + double reward = risk * riskToReward; + + // + double tp = entryPrice + reward; + + // + if (tp > hh) { + tp = hh; + } + + // + if (tp < entryPrice + priceGap) { + tp = entryPrice + priceGap; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + 0 + ); + + // + result.tp = tp; + result.sl = 0; // sl; + result.type = X_BUY; + result.id = totalSignals; + result.price = entryPrice; + result.provider = X_CCI_PROVIDER; + result.time = barTime; + + // + return result; +} + +// +// Validate CCI Signal Conditions ... +bool ValidateCCILongConditions() { + // + bool result = + cciLongConds.start != 0 + && cciLongConds.crossUnderMinusHundredTime != 0 + && cciLongConds.crossOverMinusHundredTime != 0 + && cciLongConds.crossUnderMinusHundredTime >= cciLongConds.start + && cciLongConds.crossOverMinusHundredTime > cciLongConds.crossUnderMinusHundredTime + && cciLongConds.crossOverSlope > 0; + + // + return result; +} + +// +// Clear CCI Long Signal Conditions for New One ... +void ClearCCILongSignalConditions() { + // + cciLongConds.start = 0; + cciLongConds.crossOverSlope = 0; + cciLongConds.crossOverMinusHundredTime = 0; + cciLongConds.crossUnderMinusHundredTime = 0; +} + +// +// Check and Fill CC Signal Conditions ... +void CheckCCILongSignalConditions( + const int bar_index +) { + // + // Retrieve Bar Time ... + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // LONG: + // wait for cci cross under -100 + // then wait for cross over -100 + // slope of crossing over ??? ... + if (cciLongConds.start == 0) { + cciLongConds.start = barTime; + } + + // + // Check Start Time ... + if (cciLongConds.start == 0) { + return; + } + + // + // Read current, prev, and prevPrev CCI ... + double cci = GetCCI(bar_index); + double cci1 = GetCCI(bar_index + 1); + double cci2 = GetCCI(bar_index + 2); + + // + // Find Cross Under -100 ... + bool isCrossUnderMinusHundred = + cci < -100 && !(cci1 < -100); + + // + // Fill Conditions ... + if ( + isCrossUnderMinusHundred + && cciLongConds.crossUnderMinusHundredTime == 0 + ) { + // + cciLongConds.crossUnderMinusHundredTime = barTime; + } + + // + // Prevent Going forward untill Cross Under Happens ... + if (cciLongConds.crossUnderMinusHundredTime == 0) { + return; + } + + // + // Find Cross Over -100 ... + bool isCrossOverMinusHundred = + cci > -100 && !(cci1 > -100); + + // + // Fill Conditions ... + if ( + isCrossOverMinusHundred + && cciLongConds.crossOverMinusHundredTime == 0 + ) { + // + cciLongConds.crossOverMinusHundredTime = barTime; + } + + // + // Prevent from Going forward untill Cross Over Happens ... + if (cciLongConds.crossOverMinusHundredTime == 0) { + return; + } + + // + // Calculate Slope ... + double x1 = 0; + double y1 = cci1; + double x2 = 1; + double y2 = cci; + + // + // Calculat Line Slope ... + double tSlope = GetSlope( + x1, y1, x2, y2 + ); + + // + cciLongConds.crossOverSlope = tSlope; +} + + +// +// Retrieve CCI Value ... +double GetCCI( + const int bar_index, + const int marketLength = 504, + const ENUM_APPLIED_PRICE source = PRICE_TYPICAL +) { + // + double result = iCCI( + _Symbol, + _Period, + marketLength, + source, + bar_index + ); + + // + return result; +} + +// +// Determines current working is New Bar or not ... +bool IsNewBar() { + // + static datetime lastbar; + datetime curbar = (datetime)SeriesInfoInteger(_Symbol, _Period, SERIES_LASTBAR_DATE); + + // + if(lastbar != curbar) { + // + lastbar = curbar; + return true; + } + + // + return false; +} + +// +// Get Slope of a Line by it's two Point ... +double GetSlope( + double x1, + double y1, + double x2, + double y2 +) { + // + double result = (y2 - y1)/(x2 - x1); + return result; +} + +// +// Market Related Functions ... +// +double GetLowestLow() { + // + int index = iLowest( + _Symbol, + _Period, + MODE_LOW, + 14, + 0 + ); + + // + double result = iLow( + _Symbol, + _Period, + index + ); + + // + return result; +} + +// +double GetHighestHigh() { + // + int index = iHighest( + _Symbol, + _Period, + MODE_HIGH, + 14, + 0 + ); + + // + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + return result; +} \ No newline at end of file diff --git a/Bkp/Used/14020420/x-saherelm.ea.mq4 b/Bkp/Used/14020420/x-saherelm.ea.mq4 new file mode 100644 index 0000000..978d81d --- /dev/null +++ b/Bkp/Used/14020420/x-saherelm.ea.mq4 @@ -0,0 +1,1277 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XST Strategy Expert Advisor +// --------------------------------------------- +// saherelm implementation of strategy expert advisor ... +// in this EA, we try to combine multiple tools, to ashive best +// results ... +// +// ShortName: XST +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +989121694056 +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XST Strategy Expert Advisor" +#property strict + +// +// START Inputs ... +// +// +// Signal Prefixe ... +input string signalPrefix = "XST"; // Signal Prefix + +// +// Signal Draw Specifications ... +input string bullishSignalLabel = "X_BUY"; // Bullish Signal Label +input color bullishSignalColor = clrAqua; // Bullish Signal Color + +// +input string bearishSignalLabel = "X_SELL"; // Bearish Signal Label +input color bearishSignalColor = clrFuchsia; // Bearish Signal Color + +// +input bool useOSCSignalling = false; // Use XOSC Signalling +input string oscSignalIdentifier = "XOSC"; // XOSC Signal Identifier + +// +input bool useXMASignalling = false; // Use XMA Signalling +input string xmaSignalIdentifier = "XMA"; // XMA Signal Identifier + +// +input bool useXSHPSignalling = true; // Use XSHP Signalling +input string xshpSignalIdentifier = "XSHP"; // XSHP Signal Identifier + +// +input bool useXMNTMSignalling = false; // Use XMNTM Signalling +input string xmntmSignalIdentifier = "XMNTM"; // XMNTM Signal Identifier + +// +input bool useXRSISignalling = true; // Use XRSI Signalling +input string xrsiSignalIdentifier = "XRSI"; // XRSI Signal Identifier + +// +input color signalEntryColor = clrAquamarine; // Signal Entry Ptice Color +input color signalSLColor = clrRed; // Signal SL Color +input color signalTPColor = clrGreen; // Signal TP Color + +// +// Trade ... +input bool allowTrade = true; // Allow Trade Based on given Signals +input bool allowLongTrades = true; // Allow Long Trades +input bool allowShortTrades = false; // Allow Short Trades + +// +// Market Specification Inpouts ... +input int marketLength = 7; // Market Length +input double riskToRewardRatio = 2; // Risk to Reward Ratio + +// +// Alerts ... +input bool alertEvents = true; // Alert Events +input bool alertPositions = true; // Alert Positions +input bool longPositionAlerts = true; // Alert Long Positions +input bool shortPositionAlerts = true; // Alert Short Positions + +// +// Alert Types ... +input bool terminalAlert = false; // Terminal Alert +input bool pushAlert = false; // Push Notification Alerts + +// +// Balance and Finanical Specifications ... +input double lotsPerTradePercent = 0.00001; // Lots Per Trade Percent +input int maxOpenTrades = 4; // Maximum Open Trade +input double maxDrawdownPercentPerPTrade = 0.01; // Maximum DrawDown Per Trade +input double minBalancePercent = 0.5; // Minimum Balance for Trading +input double maxEquityPercent = 0.1; // Maximum Trade Equity +input int closeAllOpenTradesAfterCandle = 504; // Close All Open Trades After Passed Candles +input bool closeAllInProfitOpenTradesWhenMaxOpenTradesReached = false; // Close All In Profit Open Trades When Max Open Trades Reached and New Signal Income + +// +// OSC Inputs ... +// +// FastOSC ... +// Short Cycle (Fast OSC) ... +input int fastOSCLength = 10; // FastOSC Length +input double fastOSCMultiplier = 1.0; // FastOSC Multiplier + +// +// SlowOSC ... +// Medium Cycle (Slow OSC) ... +input int slowOSCLength = 30; // SlowOSC Length +input double slowOSCMultiplier = 3.0; // SlowOSC Multiplier + +// +// XMA Inputs ... +// +input double step = 0.02; // SAR Step +input double maximum = 0.2; // SAR Maximum +input int shortCycleFastMultiplier = 2; // Short Cycle Fast Multiplier +input int shortCycleSlowMultiplier = 4; // Short Cycle Slow Multiplier +input int mediumCycleFastMultiplier = 6; // Medium Cycle Fast Multiplier +input int mediumCycleSlowMultiplier = 12; // Medium Cycle Slow Multiplier +input int longCycleFastMultiplier = 36; // Long Cycle Fast Multiplier +input int longCycleSlowMultiplier = 72; // Long Cycle Slow Multiplier +// +// SHPD Indicator ... +input double sharpDetectMultiplier = 500; // Sharp Detect Multiplier +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +int lastSignalledBar = 0; + +// +bool waitForLongSignals = true; +bool closeLongTrades = false; + +// +bool waitForShortSignals = true; +bool closeShortTrades = false; + +// +bool isSharpBullishHappens; +bool isSharpBearishHappens; + +// +datetime startMarketTime; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.signal.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Validate Inputs ... + bool inputsNotValiid = + // + // MARKET ... + marketLength < 0 + || riskToRewardRatio < 0 + // + // EA ... + || lotsPerTradePercent < 0 + || maxOpenTrades <= 0 + || maxDrawdownPercentPerPTrade < 0 + || minBalancePercent < 0 + || maxEquityPercent < 0 + || marketLength < 0 + // + // OSC ... + || fastOSCLength < 0 + || fastOSCMultiplier < 0 + || slowOSCLength < 0 + || slowOSCMultiplier < 0 + || slowOSCLength <= fastOSCLength + // + // XMA ... + // + // Validate Short Cycle ... + || shortCycleFastMultiplier <= 0 + || shortCycleSlowMultiplier <= 0 + || shortCycleFastMultiplier >= shortCycleSlowMultiplier + // + // Validate Medium Cycle ... + || mediumCycleFastMultiplier <= 0 + || mediumCycleSlowMultiplier <= 0 + || mediumCycleFastMultiplier >= mediumCycleSlowMultiplier + // + // Validate Long Cycle ... + || longCycleFastMultiplier <= 0 + || longCycleSlowMultiplier <= 0 + || longCycleFastMultiplier >= longCycleSlowMultiplier + // + // Validate Series of Multipliers ... + || shortCycleFastMultiplier >= mediumCycleFastMultiplier + || mediumCycleFastMultiplier >= longCycleFastMultiplier + ; + + if (inputsNotValiid) { + return INIT_PARAMETERS_INCORRECT; + } + + // + totalSignals = 0; + totalLongSignals = 0; + totalShortSignals = 0; + + // + initialBalance = 0; + + // + // START Define Array Series ... + // + // + // END Define Array Series ... + // + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST"; + + // // + // // Set Event Timer on One Seccond ... + // bool isEventSet = EventSetTimer(1); + // if (!isEventSet) { + // LogMessage("Error: " + GetLastError()); + // return INIT_FAILED; + // } + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + // Killing Event Timer ... + EventKillTimer(); +} + +// +// Ticker Event Handler ... +void OnTick() { + // + isNewDay = IsNewDay(); + if (isNewDay) { + // + LogMessage( + StringConcatenate( + "New Day: ", TimeCurrent() + ) + ); + } + + // + // Process Signals to Open Positions ... + ProcessSignals(); + + // + // Checking State for Signal Handling ... + CheckState(); + + // + // Process Open Positions for Trailing Stop Loss or Close ... + ProcessOpenPositions(); +} + +// +// Timer Event Handler ... +void OnTimer() { + // + CheckState(); + + // + ProcessOpenPositions(); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// START Signal Related Functions ... +// +// +// Calculate Signal ... +// in this function we calculate a signal exists in +// specific bar or not ... +XSignalRequest GenerateSignal( + const int bar_index // Bar Index ... +) { + // + // create temp result ... + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_NONE; + + // + XSignal signal = {}; + + // + if (countedBars < (longCycleSlowMultiplier * marketLength)) { + return result; + } + + // + int marketArraySize = shortCycleSlowMultiplier * marketLength; + ArrayResize( + oscStates, + marketArraySize + ); + ArrayResize( + xmaStates, + marketArraySize + ); + ArrayResize( + cciStates, + marketArraySize + ); + + // + // Retrieve Bar Index Time ... + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + 1 + ); + + // + // START Retrieve Statets ... + // + // + // Loop through Market Length ... + int index = 0; + for (int i = bar_index; i < bar_index + marketArraySize; i++) { + // + // Retrieve XMA State ... + XMAState xmaState = {}; + + // + // Short Cycle ... + XMACycleState sc = GetXMASC( + i, + marketLength, + shortCycleFastMultiplier, + shortCycleSlowMultiplier + ); + xmaState.sc = sc; + + // + // Medium Cycle ... + XMACycleState mc = GetXMAMC( + i, + marketLength, + mediumCycleFastMultiplier, + mediumCycleSlowMultiplier + ); + xmaState.mc = mc; + + // + // Long Cycle ... + XMACycleState lc = GetXMAMC( + i, + marketLength, + longCycleFastMultiplier, + longCycleSlowMultiplier + ); + xmaState.lc = lc; + + // + // Market Middleage ... + double marketMiddle = GetXMAMM( + i, + marketLength, + 1.5 + ); + xmaState.marketMiddleage = marketMiddle; + + // + // Parabolic SAR ... + double pSar = GetXMAPSAR( + i, + step, + maximum + ); + xmaState.parabolicSAR = pSar; + + // + xmaStates[index] = xmaState; + + // + // Retrieve OSC State ... + // TODO Complete this ... + XMACycleState oscState = {}; + + // + // Retriec CCI ... + double cciValue = GetMarketCCI( + bar_index, + longCycleSlowMultiplier * marketLength, + PRICE_CLOSE + ); + cciStates[index] = cciValue; + + // + index++; + } + // + // END Retrieve Statets ... + // + + // + // START States Calculations ... + // + + // + // START OSC Calculations ... + // + // + // END OSC Calculations ... + // + + // + // START XMA Calculations ... + // + + // + // END XMA Calculations ... + // + + // + // START Momentum Calculations ... + // + // + // END Momentum Calculations ... + // + + // + // START RSI Calculations ... + // + // + // END RSI Calculations ... + // + + // + // START PRICE Calculations ... + // + RefreshRates(); + + // + double marketLow[]; + double marketOpen[]; + double marketHigh[]; + double marketClose[]; + // + double marketUp[]; + double marketDown[]; + // + ArrayResize( + marketLow, + marketLength + ); + ArrayResize( + marketOpen, + marketLength + ); + ArrayResize( + marketHigh, + marketLength + ); + ArrayResize( + marketClose, + marketLength + ); + // + ArrayResize( + marketUp, + marketLength + ); + ArrayResize( + marketDown, + marketLength + ); + + // + index = 0; + for (int i = bar_index; i < marketLength + bar_index; i++) { + // + marketLow[index] = iLow( + _Symbol, + _Period, + i + ); + + // + marketOpen[index] = iOpen( + _Symbol, + _Period, + i + ); + + // + marketHigh[index] = iHigh( + _Symbol, + _Period, + i + ); + + // + marketClose[index] = iClose( + _Symbol, + _Period, + i + ); + + // + // marketUp[i] = MathMax(marketOpen[i], marketClose[i]); + marketUp[index] = marketHigh[i]; + + // + // marketDown[i] = MathMin(marketOpen[i], marketClose[i]); + marketDown[index] = marketLow[i]; + + // + index++; + } + + // + // LONG Prices ... + double longEntryPrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK); + double longClosePrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); + double longPriceGap = longClosePrice - longEntryPrice; + + // + // SHORT Prices ... + double shortEntryPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); + double shortClosePrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK); + double shortPriceGap = shortEntryPrice - shortClosePrice; + + // + if (startMarketTime == 0) { + startMarketTime = barTime; + } + + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + startMarketTime + ); + + // + if (startBarIndex > bar_index + marketLength) { + // + startBarIndex = 0; + startMarketTime = 0; + } + + // + bool isSharpBullishDetected = false; + bool isShareBearishDetected = false; + double sharpDetectionValue = sharpDetectMultiplier * _Point; + if (startBarIndex > bar_index + 1) { + // + double marketStartHigh = iHigh( + _Symbol, + _Period, + startBarIndex + ); + + double marketStartLow = iLow( + _Symbol, + _Period, + startBarIndex + ); + + // + double prevCandleOpen = iOpen( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double prevCandleHigh = iHigh( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double prevCandleClose = iClose( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double candleOpen = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double prevCandleComparedPrice = MathMin(prevCandleOpen, prevCandleClose); + isShareBearishDetected = + prevCandleHigh < marketStartHigh + && prevCandleComparedPrice < marketStartHigh + && marketStartHigh - prevCandleComparedPrice >= sharpDetectionValue; + + // // + // isSharpBullishDetected = + // marketStartHigh - MathMin(prevCandleOpen, prevCandleClose) >= sharpDetectionValue; + } + // + if ( + isShareBearishDetected + || isSharpBullishDetected + ) { + startBarIndex = 0; + startMarketTime = 0; + } + // + // + // END PRICE Calculations ... + // + + // + // START Capturing Signal ... + // + + // + // START LONG Signals ... + // + // + // NOTES: + // when MC Fast is Over MC Slow, + // All Long Trades must be down when Market Middle is above MCSlow ... + // and must be paused when Market Middle is Going Under MCSlow ... + double rewardMultiplier = 1; + + // + // OSC ... + bool oscHasLongSignal = false; + if (useOSCSignalling) { + // // + // oscHasLongSignal = + // true + // && ( + // oscStates[0].fastOSC < 0 + // ) + // ; + } + + // + // XMA ... + bool xmaHasLongSignal = false; + if (useXMASignalling) { + // // + // xmaHasLongSignal = + // // + // // Long Cycle Trend Up ... + // xmaStates[0].lcFast > xmaStates[0].lcSlow + // // Lowest Low Must be Higher than lcFast ... + // && xmktStates[0].lowestLow > xmaStates[0].lcFast + // // + // // Medium Cycle in Up Trend ... + // && xmaStates[0].mcFast > xmaStates[0].mcSlow + // // + // // and the Medium Cycle Distance must be at least 100 Point ... + // && (xmaStates[0].mcFast - xmaStates[0].mcSlow) > (100 * _Point) + // // + // // then looking for parabolic sar cross down market middleage ... + // && xmaStates[0].parabolicSAR < xmaStates[0].marketMiddleage + // && !(xmaStates[1].parabolicSAR <= xmaStates[1].marketMiddleage) + // // + // && xmaStates[0].scFast > xmaStates[0].marketMiddleage + // // + // // in crossing time Parabolic SAR must be greater than mcFast ... + // && xmaStates[0].parabolicSAR > xmaStates[0].mcFast + // // + // // in this conditions, entry price must below than highest high, in market ... + // && longEntryPrice < xmktStates[0].highestHigh + // ; + } + + // + bool xshpHasLongSignal = false; + if (useXSHPSignalling) { + // + bool condition1 = + // + xmaStates[0].sc.fast > xmaStates[0].sc.slow + && xmaStates[0].mc.fast > xmaStates[0].mc.slow + && xmaStates[0].lc.fast > xmaStates[0].lc.slow + // + && MathAbs(xmaStates[0].mc.fast - xmaStates[0].mc.slow) > (20 * _Point) + // + && ( + cciStates[0] > 0 + || cciStates[0] > cciStates[1] + ) + // + && !( + longEntryPrice < xmaStates[0].lc.fast + && longEntryPrice > xmaStates[0].lc.slow + && ( + ( + longEntryPrice < xmaStates[0].sc.fast + && marketHigh[1] < xmaStates[0].sc.fast + ) || ( + longEntryPrice < xmaStates[0].lc.fast + && marketHigh[1] < xmaStates[0].lc.fast + ) + ) + ) + //&& longEntryPrice < marketHigh[0] + ; + + // + xshpHasLongSignal = + // + isShareBearishDetected + // + && (condition1) + ; + + // + // Check Reward Multiplier ... + if (xshpHasLongSignal) { + // + double prevCandleLow = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double marketLowest = GetMarketLowestLow( + bar_index, + marketLength + ); + + // + if ( + prevCandleLow == marketLowest + || marketLowest < xmaStates[0].mc.slow + || MathAbs(prevCandleLow - marketLowest) < (50 * _Point) + ) { + rewardMultiplier = 0.3; + } + } + } + + // + bool xmntmHasLongSignal = false; + if (useXMNTMSignalling) { + } + + // + bool xrsiHasLongSignal = false; + if (useXRSISignalling) { + } + + // + bool hasLongSignal = + // + // OSC Signals ... + oscHasLongSignal + || xmaHasLongSignal + || xshpHasLongSignal + || xmntmHasLongSignal + || xrsiHasLongSignal + ; + // + // END LONG Signals ... + // + + // + // START SHORT Signals ... + // + bool hasShortSignal = false; + // + // END SHORT Signals ... + // + + // + // Check Signal Exists regardless of Long or Short ... + bool hasSignal = hasLongSignal || hasShortSignal; + + // + // Prevent from Going forward if there is not a Signal ... + if (!hasSignal) { + // + result.signal = signal; + return result; + } + + // + totalSignals++; + + // + // Define Price Related Variables ... + // + double price = 0; + double priceGap = 0; + double sl = 0; + double risk; + double reward; + double tp = 0; + double r2rRatio = riskToRewardRatio; + + // + datetime time = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Fill Signal Related Variables ... + if (hasLongSignal) { + // + price = longEntryPrice; + priceGap = longPriceGap; + + // + // Setting Up SL Based on Last Market Lowest ... + sl = GetMarketLowestLow( + bar_index, + marketLength + ); + + // + risk = price - sl; + reward = risk * r2rRatio; + reward = reward * rewardMultiplier; + tp = price + reward; + + // + // Check TP based on Spread ... + if (tp < price + priceGap) { + tp = tp + priceGap; + } + + // + sl = 0; + + // + totalLongSignals++; + } else if (hasShortSignal) { + // + totalShortSignals++; + + // + price = shortEntryPrice; + priceGap = shortPriceGap; + + // + risk = sl - price; + reward = risk * r2rRatio; + reward = reward * rewardMultiplier; + tp = price - reward; + } + + // + // Normalize Prices ... + price = NormalizeDouble(price, _Digits); + sl = NormalizeDouble(sl, _Digits); + tp = NormalizeDouble(tp, _Digits); + + // + // Generate Signal Structure ... + signal.type = hasLongSignal ? + X_LONG : + X_SHORT; + signal.tp = tp; + signal.sl = sl; + signal.time = time; + signal.symbol = _Symbol; + signal.entryPrice = price; + signal.id = totalLongSignals; + // + // TODO: Fill Signal Comment By Sgnal Provider + signal.comment = + useOSCSignalling && oscHasLongSignal + ? oscSignalIdentifier + : useXMASignalling && xmaHasLongSignal + ? xmaSignalIdentifier + : useXSHPSignalling && xshpHasLongSignal + ? xshpSignalIdentifier + : useXMNTMSignalling && xmntmHasLongSignal + ? xmntmSignalIdentifier + : useXRSISignalling && xrsiHasLongSignal + ? xrsiSignalIdentifier + : "" + ; + // + // END Capturing Signal ... + // + + // + // Fill Result ... + result.hasSignal = hasSignal; + result.signal = signal; + result.type = signal.type; + + // + // Return Result ... + return result; +} + +// +// Check State for Signal Handling ... +void CheckState() { + // + // Here we Must to Check Market State for enable or disable + // Signal Handlers and also make dection to close all long/short + // trades ... + + // + // Prevent from Checking, if there is no states available ... + if (ArraySize(xmaStates) == 0) { + return; + } + + // // + // closeLongTrades = + // xmaStates[0].parabolicSAR > xmaStates[0].marketMiddleage + // && !(xmaStates[1].parabolicSAR > xmaStates[1].marketMiddleage) + // ; + + // // + // closeLongTrades = + // false + // ; +} + +// +// Calculate Signals and Process Based on Exists Signals ... +void ProcessSignals() { + // + XSignalRequest request = {}; + request.type = X_NONE; + request.hasSignal = false; + + // + // Prevent Multiple Calculating on Same Bars ... + isNewBar = IsNewBar(); + if (isNewBar) { + // + countedBars++; + } + + // + bool allowDoTrade = true; + + // + // Check Balance ... + if (initialBalance > 0) { + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double minimumBalanceForTrade = + balance > initialBalance + ? + minBalancePercent * balance + : + minBalancePercent * initialBalance; + + // + // Retrieve Account Equity ... + double equity = AccountInfoDouble(ACCOUNT_EQUITY); + double maxAllowedEquity = balance - (balance * maxEquityPercent); + + // + // Retrieve Free Marigin ... + double freeMargin = AccountFreeMargin(); + double maximumMariginRisk = balance - (balance * maxEquityPercent); + + // + if ( + // + // Do not Open Positions if equity not passed ... + equity < maxAllowedEquity || + // + // Do not Open Positions if free margin not passed ... + freeMargin <= maximumMariginRisk || + // + // Do not open positions if balance less than minimum ... + balance <= minimumBalanceForTrade + ) { + // + allowDoTrade = false; + + // // + // string message = StringConcatenate( + // "Trading Pause => ", + // "Balance: ", balance, + // ", Equity: ", equity, + // ", FreeMargin: ", freeMargin + // ); + + // // + // LogMessage(message); + // SendAlert(message); + } + } + + // + // Retrieve Signal Exists ... + request = GenerateSignal(0); + + // + // Prevent doing anything else, if there is no signals ... + if ( + !allowDoTrade || + !request.hasSignal || + request.type == X_NONE + ) { + return; + } + + // + bool hasLongSignal = request.type == X_LONG; + + // + // Check For Bot State ... + if ( + (hasLongSignal && !waitForLongSignals) + || (!hasLongSignal && !waitForShortSignals) + ) { + return; + } + + // + // Check last Signalled Bar with Counted Bars ... + // Prevent Multiple Signalling on Same Bar ... + bool isInLastSignalledBars = false; + for (int i=0; i < marketLength; i++) { + // + isInLastSignalledBars = + isInLastSignalledBars + || lastSignalledBar == countedBars - i + ; + } + if (isInLastSignalledBars) { + // + totalSignals--; + if (hasLongSignal) { + totalLongSignals--; + } else { + totalShortSignals--; + } + return; + } + + // + // increase last signalled bar ... + lastSignalledBar = countedBars; + + // + // Calculate Can Trade or not ... + allowDoTrade = allowTrade + && ( + hasLongSignal ? + allowLongTrades : + allowShortTrades + ); + + // + // Chack Maximum Open Positions ... + int openTrades = CountOpenTrades(); + if (maxOpenTrades > 0) { + // + if (openTrades >= maxOpenTrades) { + // + allowDoTrade = false; + + // + if (closeAllInProfitOpenTradesWhenMaxOpenTradesReached) { + // + // Close All In Profit Trades ... + bool hasClosedInProfitTrade = CloseAllInProfitTrades(); + if (hasClosedInProfitTrade) { + // + openTrades = CountOpenTrades(); + + // + allowDoTrade = !(openTrades >= maxOpenTrades); + } + } + + // + if (!allowDoTrade) { + // + string message = StringConcatenate( + "Trading Pause => ", + "Max Open Trades (", + maxOpenTrades, + ") reached ..." + ); + + // + LogMessage(message); + SendAlert(message); + } + } + } + + // + // Check Trading is Enable or not ... + // nothing to do if trading is disabled ... + if (!allowDoTrade) { + // // + // string message = StringConcatenate( + // "Trading Not Allowed ..." + // ); + + // // + // LogMessage(message); + // SendAlert(message); + return; + } + + // + bool isPositionOpened = TradeSignal( + request.signal, + signalPrefix, + lotsPerTradePercent, + // + bullishSignalLabel, + bullishSignalColor, + bearishSignalLabel, + bearishSignalColor, + // + // Signal Identifiers ... + oscSignalIdentifier, + xmaSignalIdentifier, + xshpSignalIdentifier, + xmntmSignalIdentifier, + xrsiSignalIdentifier + ); + + // + if (isPositionOpened) { + // + bool canAlert = + alertPositions + && ( + hasLongSignal ? + longPositionAlerts + : + shortPositionAlerts + ); + + // + if (canAlert) { + // + // Alert Message ... + string message = StringConcatenate( + "Trade on Signal ID: ", request.signal.id, + ", Entry: ", request.signal.entryPrice, + ", TP: ", request.signal.tp + ); + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } + } + } +} + +// +// Process All Open Positions ... +void ProcessOpenPositions() { + // + // this comes from check state ... + if (closeLongTrades) { + // + closeLongTrades = false; + + // + bool isAllLongTradesClosed = CloseAllLongTrades(); + if (isAllLongTradesClosed) { + // waitForLongSignals = false; + } + } + + // + // this comes from check state ... + if (closeShortTrades) { + // + closeShortTrades = false; + + // + bool isAllShortTradesClosed = CloseAllShortTrades(); + if (isAllShortTradesClosed) { + // waitForShortSignals = false; + } + } + + // + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + closeAllOpenTradesAfterCandle + ); + + // + // Close Maximum DrawDown Passed Trades ... + bool hasClosedInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + maxDrawdownPercentPerPTrade + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedInDrawDownLongTrade + ) { + // + // waitForLongSignals = false; + // waitForShortSignals = false; + } +} + +// +// Send Special Type of Alerts ... +void SendAlert(string message) { + // + if (!alertEvents) { + return; + } + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020420/x-saherelm.models.lib.mq4 b/Bkp/Used/14020420/x-saherelm.models.lib.mq4 new file mode 100644 index 0000000..c772d86 --- /dev/null +++ b/Bkp/Used/14020420/x-saherelm.models.lib.mq4 @@ -0,0 +1,100 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Models Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Start Models ... +// +// +// Used Indicators List ... +const string xmaIndicatorName = "x-saherelm.xma"; +const string adxIndicatorName = "x-saherelm.adx"; +const string oscIndicatorName = "x-saherelm.osc"; +const string shpdIndicatorName = "x-saherelm.shpd"; +const string zigZagIndicatorName = "x-saherelm.zigzag"; +const string xmarketIndicatorName = "x-saherelm.xmarket"; +const string momentumIndicatorName = "x-saherelm.momentum"; + +// +// Direction ... +enum X_DIRECTION { + X_UP, + X_DOWN +}; + +// +// these are different signal types ... +enum X_SIGNAL_TYPE { + X_NONE, + X_LONG, + X_SHORT, +}; + +// +// we Model each signals as this type ... +struct XSignal { + int id; + int ticket; + X_SIGNAL_TYPE type; + double tp; + double sl; + string symbol; + datetime time; + string comment; + double entryPrice; +}; + +// +// this is Signal Request Response model ... +struct XSignalRequest { + bool hasSignal; + X_SIGNAL_TYPE type; + XSignal signal; +}; + +// +struct XMACycleState { + double fast; + double slow; +}; + +// +// Define a Model to Represent Snapshot of XMA Indicator ... +struct XMAState { + // + // SC ... + XMACycleState sc; + + // + // MC ... + XMACycleState mc; + + // + // LC ... + XMACycleState lc; + + // + // MIDDLEAGE ... + double marketMiddleage; + + // + // PARABOLIC-SAR ... + double parabolicSAR; +}; +// +// End Models ... +// diff --git a/Bkp/Used/14020420/x-saherelm.osc.mq4 b/Bkp/Used/14020420/x-saherelm.osc.mq4 new file mode 100644 index 0000000..220bd33 --- /dev/null +++ b/Bkp/Used/14020420/x-saherelm.osc.mq4 @@ -0,0 +1,330 @@ +///////////////////////////////////////////////////////////////// +// +// SaherElm IT Center OSC Indicator +// ------------------------------------------------------------- +// this indicator provides OSC ... +// +// 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 OSC Indicator" +#property strict + +// +// START Inputs ... +// +// +// FastOSC ... +// Short Cycle (Fast OSC) ... +input int fastOSCLength = 10; // FastOSC Length +input double fastOSCMultiplier = 1.0; // FastOSC Multiplier + +// +// SlowOSC ... +// Medium Cycle (Slow OSC) ... +input int slowOSCLength = 30; // SlowOSC Length +input double slowOSCMultiplier = 3.0; // SlowOSC Multiplier +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +#property indicator_separate_window + +// +// we have 2 buffer in this indicator ... +#property indicator_buffers 5 + +// +// also we have 2 line for draw on this indicator ... +#property indicator_plots 5 + +// +// Fast OSC ... +#property indicator_width1 1 +#property indicator_color1 clrAqua +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_SOLID + +// +// Slow OSC ... +#property indicator_width2 1 +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrFuchsia +#property indicator_style2 STYLE_SOLID + +// +// Power OSC ... +#property indicator_width3 1 +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_DASHDOTDOT + +// +// Var OSC ... +#property indicator_width4 1 +#property indicator_type4 DRAW_HISTOGRAM +#property indicator_color4 clrBlueViolet +#property indicator_style4 STYLE_SOLID + +// +// Tan Fast/Slow OSC ... +#property indicator_width5 0 +#property indicator_type5 DRAW_NONE +#property indicator_color5 clrNONE +#property indicator_style5 STYLE_SOLID + +// +//#property indicator_minimum 0 +//#property indicator_maximum 1 + +// +// set color of horizontal levels ... +#property indicator_levelcolor clrGray + +// +// set style of horizontal levels ... +#property indicator_levelstyle STYLE_DOT + +// +// Declare Buffers ... +#define fastOSCBufferIndex 0 +#define slowOSCBufferIndex 1 +#define powerOSCBufferIndex 2 +#define varOSCBufferIndex 3 +#define fastSlowOSCAngleBufferIndex 4 + +// +double fastOSCBuffer[]; +double slowOSCBuffer[]; +double fastSlowOSCAngleBuffer[]; +double powerOSCBuffer[]; +double varOSCBuffer[]; + +// +// Used Indicators List ... +string rmaIndicatorName = "x-saherelm.rma"; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + fastOSCLength < 0 || + slowOSCLength < 0 || + slowOSCLength <= fastOSCLength + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XS_OSC"; + + // + // set descriptions of horizontal levels ... + SetLevelValue(0, 0.0); + IndicatorSetString(INDICATOR_LEVELTEXT,0,""); + + // + // set descriptions of horizontal levels ... + SetLevelValue(1, 0.5); + IndicatorSetString(INDICATOR_LEVELTEXT,1,""); + + // + // set descriptions of horizontal levels ... + SetLevelValue(2, 1); + IndicatorSetString(INDICATOR_LEVELTEXT,2,""); + + // + // Fast OSC Buffer ... + SetIndexBuffer(fastOSCBufferIndex, fastOSCBuffer); + SetIndexLabel(fastOSCBufferIndex, "Fast OSC"); + SetIndexDrawBegin(fastOSCBufferIndex, fastOSCLength - 1); + + // + // Slow OSC Buffer ... + SetIndexBuffer(slowOSCBufferIndex, slowOSCBuffer); + SetIndexLabel(slowOSCBufferIndex, "Slow OSC"); + SetIndexDrawBegin(slowOSCBufferIndex, slowOSCLength - 1); + + // + // Power OSC Buffer ... + SetIndexBuffer(powerOSCBufferIndex, powerOSCBuffer); + SetIndexLabel(powerOSCBufferIndex, "Power OSC"); + + // + // Var OSC Buffer ... + SetIndexBuffer(varOSCBufferIndex, varOSCBuffer); + SetIndexLabel(varOSCBufferIndex, "Var OSC"); + + // + // Tan Fast/Slow OSC Buffer ... + SetIndexBuffer(fastSlowOSCAngleBufferIndex, fastSlowOSCAngleBuffer); + SetIndexLabel(fastSlowOSCAngleBufferIndex, "F/L OSC Angle"); + + // + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(fastOSCLength, slowOSCLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + CalculateOscillators(close, i); + } + + // + return rates_total; +} + +// +// De Initialization ... +void OnDeinit(const int reason) { +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +void CalculateOscillators( + const double &close[], + const int &bar_index +) { + // + // FastOSC ... + // Short Cycle Calculations ... + int scl = fastOSCLength / 2; + int scl2 = scl / 2; + double maScl = iCustom(_Symbol, _Period, rmaIndicatorName, scl, 0, bar_index); + double scmAtr = iATR(_Symbol, _Period, scl, bar_index); + double scmOff = fastOSCMultiplier * scmAtr; + double maScl2 = iCustom(_Symbol, _Period, rmaIndicatorName, scl2, 0, bar_index); + double sctParam = maScl2 != 0 ? maScl2 : close[bar_index + 1]; + double sct = sctParam + scmOff; + double scb = sctParam - scmOff; + + // + // SlowOSC ... + // Medium Cycle Calculations ... + int mcl = slowOSCLength / 2; + int mcl2 = mcl / 2; + double maMcl = iCustom(_Symbol, _Period, rmaIndicatorName, mcl, 0, bar_index); + double mcmAtr = iATR(_Symbol, _Period, mcl, bar_index); + double mcmOff = slowOSCMultiplier * mcmAtr; + double maMcl2 = iCustom(_Symbol, _Period, rmaIndicatorName, mcl2, 0, bar_index); + double mctParam = maMcl2 != 0 ? maMcl2 : close[bar_index + 1]; + double mct = mctParam + mcmOff; + double mcb = mctParam - mcmOff; + + // + double scMM = (sct + scb) / 2; + + // + double fastOCS = (close[bar_index] - mcb) / (mct - mcb); + fastOSCBuffer[bar_index] = fastOCS; + + // + double slowOCS = (scMM - mcb) / (mct - mcb); + slowOSCBuffer[bar_index] = slowOCS; + + // + // Signal Power ... + // Difference Variant between FastOSC and Slow OSC ... + double powerOSC = fastOCS - slowOCS; + powerOSCBuffer[bar_index] = powerOSC; + + // + // Var OSC ... + double varOSC = fastOCS - 0.5; + varOSCBuffer[bar_index] = varOSC; + + // + // Calculate Tan Fast/Slow OSC ... + double fastOSCSlope = fastOSCBuffer[bar_index] - fastOSCBuffer[bar_index + 1]; + double slowOSCSlope = slowOSCBuffer[bar_index] - slowOSCBuffer[bar_index + 1]; + double tanFastSlowOSC = MathAbs( + (fastOSCSlope - slowOSCSlope) / (1 + (fastOSCSlope * slowOSCSlope)) + ); + + // + // here we pass Tan of angle ... + // fastSlowOSCAngleBuffer[bar_index] = tanFastSlowOSC; + + // + // here we pass degree of angle ... + fastSlowOSCAngleBuffer[bar_index] = MathArctan(tanFastSlowOSC); +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020420/x-saherelm.x.hl.mq4 b/Bkp/Used/14020420/x-saherelm.x.hl.mq4 new file mode 100644 index 0000000..f08a975 --- /dev/null +++ b/Bkp/Used/14020420/x-saherelm.x.hl.mq4 @@ -0,0 +1,412 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center X Indicator +// --------------------------------------------- +// saherelm implementation of above 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 X Indicator" +#property strict + +// +// START Inputs ... +// +// +input int marketLength = 7; // Market Length + +// +input int shortCycleMultiplier = 2; // Market Short Cycle Multiplier +input int mediumCycleMultiplier = 6; // Market Medium Cycle Multiplier +input int longCycleMultiplier = 36; // Market Medium Cycle Multiplier + +// +input ENUM_MA_METHOD maMethod = MODE_SMA; // Ma Method +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 6 + +// +#property indicator_plots 6 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Short Cycle Highest High Buffer ... +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +// Short Cycle Lowest Low Buffer ... +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +// Medium Cycle Highest High Buffer ... +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrAqua +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 + +// +// Medium Cycle Lowest Low Buffer ... +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrFuchsia +#property indicator_style4 STYLE_DOT +#property indicator_width4 1 + +// +// Long Cycle Highest High Buffer ... +#property indicator_type5 DRAW_LINE +#property indicator_color5 C'62,82,6' +#property indicator_style5 STYLE_DOT +#property indicator_width5 1 + +// +// Long Cycle Lowest Low Buffer ... +#property indicator_type6 DRAW_LINE +#property indicator_color6 C'255,81,0' +#property indicator_style6 STYLE_DOT +#property indicator_width6 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +// +// HH Buffers ... +#define scHHBufferIndex 0 +#define scLLBufferIndex 1 +#define mcHHBufferIndex 2 +#define mcLLBufferIndex 3 +#define lcHHBufferIndex 4 +#define lcLLBufferIndex 5 + +double scHHBuffer[]; +double scLLBuffer[]; +double mcHHBuffer[]; +double mcLLBuffer[]; +double lcHHBuffer[]; +double lcLLBuffer[]; + +// +// Variables ... +int shortCycleLength; +int mediumCycleLength; +int longCycleLength; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if ( + marketLength <= 0 || + shortCycleMultiplier <= 0 || + mediumCycleMultiplier <= 0 || + shortCycleMultiplier > mediumCycleMultiplier + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + shortCycleLength = shortCycleMultiplier * marketLength; + mediumCycleLength = mediumCycleMultiplier * marketLength; + longCycleLength = longCycleMultiplier * marketLength; + + // + // Highest High and Lowest Low Buffers ... + // + // Short Cycle Highest High ... + string scHHLbl = StringConcatenate( + "SC HH(", shortCycleLength, ")" + ); + SetIndexBuffer(scHHBufferIndex, scHHBuffer); + SetIndexLabel(scHHBufferIndex, scHHLbl); + + // + // Short Cycle Lowest Low ... + string scLLLbl = StringConcatenate( + "SC LL(", shortCycleLength, ")" + ); + SetIndexBuffer(scLLBufferIndex, scLLBuffer); + SetIndexLabel(scLLBufferIndex, scLLLbl); + + // + // Medium Cycle Highest High ... + string mcHHLbl = StringConcatenate( + "MC HH(", mediumCycleLength, ")" + ); + SetIndexBuffer(mcHHBufferIndex, mcHHBuffer); + SetIndexLabel(mcHHBufferIndex, mcHHLbl); + + // + // Medium Cycle Lowest Low ... + string mcLLLbl = StringConcatenate( + "MC LL(", mediumCycleLength, ")" + ); + SetIndexBuffer(mcLLBufferIndex, mcLLBuffer); + SetIndexLabel(mcLLBufferIndex, mcLLLbl); + + // + // Long Cycle Highest High ... + string lcHHLbl = StringConcatenate( + "LC HH(", longCycleLength, ")" + ); + SetIndexBuffer(lcHHBufferIndex, lcHHBuffer); + SetIndexLabel(lcHHBufferIndex, lcHHLbl); + + // + // Long Cycle Lowest Low ... + string lcLLLbl = StringConcatenate( + "LC LL(", longCycleLength, ")" + ); + SetIndexBuffer(lcLLBufferIndex, lcLLBuffer); + SetIndexLabel(lcLLBufferIndex, lcLLLbl); + // + // End Set Index Buffers ... + // + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculat Ma's ... + // + CalculateShortCycle(i); + + // + CalculateMediumCycle(i); + + // + CalculateLongCycle(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Short Cycle ... +void CalculateShortCycle( + const int &bar_index +) { + // + // Short Cycle Highest High ... + // + int scHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + shortCycleLength, + bar_index + ); + + // + double scHH = iHigh( + _Symbol, + _Period, + scHHIdx + ); + + // + scHHBuffer[bar_index] = scHH; + + // + // Short Cycle Lowest Low ... + // + int scLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + shortCycleLength, + bar_index + ); + + // + double scLL = iLow( + _Symbol, + _Period, + scLLIdx + ); + + // + scLLBuffer[bar_index] = scLL; +} + +// +// Calculating Medium Cycle ... +void CalculateMediumCycle( + const int &bar_index +) { + // + // Medium Cycle Highest High ... + // + int mcHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + mediumCycleLength, + bar_index + ); + + // + double mcHH = iHigh( + _Symbol, + _Period, + mcHHIdx + ); + + // + mcHHBuffer[bar_index] = mcHH; + + // + // Medium Cycle Lowest Low ... + // + int mcLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + mediumCycleLength, + bar_index + ); + + // + double mcLL = iLow( + _Symbol, + _Period, + mcLLIdx + ); + + // + mcLLBuffer[bar_index] = mcLL; +} + +// +// Calculating Long Cycle ... +void CalculateLongCycle( + const int &bar_index +) { + // + // Long Cycle Highest High ... + // + int lcHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + longCycleLength, + bar_index + ); + + // + double lcHH = iHigh( + _Symbol, + _Period, + lcHHIdx + ); + + // + lcHHBuffer[bar_index] = lcHH; + + // + // Long Cycle Lowest Low ... + // + int lcLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + longCycleLength, + bar_index + ); + + // + double lcLL = iLow( + _Symbol, + _Period, + lcLLIdx + ); + + // + lcLLBuffer[bar_index] = lcLL; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020420/x-saherelm.x.trend.power.mq4 b/Bkp/Used/14020420/x-saherelm.x.trend.power.mq4 new file mode 100644 index 0000000..dc70f81 --- /dev/null +++ b/Bkp/Used/14020420/x-saherelm.x.trend.power.mq4 @@ -0,0 +1,265 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center Trend Power Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 MA Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 7; // Market Length +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_separate_window + +// +#property indicator_plots 3 +#property indicator_buffers 3 +#property indicator_minimum 0 +#property indicator_maximum 100 + +// +#property indicator_levelcolor clrGray +#property indicator_levelstyle STYLE_DOT + +// +// Start Define Indicator Buffer Styles ... +// +#property indicator_type1 DRAW_HISTOGRAM +#property indicator_color1 clrLime +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +#property indicator_type2 DRAW_HISTOGRAM +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define powerUpBufferIndex 0 +#define powerDownBufferIndex 1 +#define signalBufferIndex 2 +#define diBufferIndex 3 + +double powerUpBuffer[]; +double powerDownBuffer[]; +double signalBuffer[]; +double diBuffer[]; + +// +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (marketLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + SetLevelValue(0, 0.0); + IndicatorSetString(INDICATOR_LEVELTEXT,0,""); + + // + SetLevelValue(1, 50); + IndicatorSetString(INDICATOR_LEVELTEXT,1,""); + + // + SetLevelValue(2, 100); + IndicatorSetString(INDICATOR_LEVELTEXT,2,""); + + // + string pUpLbl = StringConcatenate( + "P Up (", marketLength, ")" + ); + SetIndexLabel(powerUpBufferIndex, pUpLbl); + SetIndexBuffer(powerUpBufferIndex, powerUpBuffer); + SetIndexDrawBegin(powerUpBufferIndex, marketLength + 1); + + // + string pDownLbl = StringConcatenate( + "P Down (", marketLength, ")" + ); + SetIndexLabel(powerDownBufferIndex, pDownLbl); + SetIndexBuffer(powerDownBufferIndex, powerDownBuffer); + SetIndexDrawBegin(powerDownBufferIndex, marketLength + 1); + + // + string pSignalLbl = StringConcatenate( + "P Signal (", marketLength, ")" + ); + SetIndexLabel(signalBufferIndex, pSignalLbl); + SetIndexBuffer(signalBufferIndex, signalBuffer); + SetIndexDrawBegin(signalBufferIndex, marketLength + 1); + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "X_TPW_OSC"; + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Buffers ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateBuffers( + const int &bar_index +) { + // + double powerUp = 0; + double powerDown = 0; + + // + int dailyCount = GetDailyCandleCount(); + double dailyHH = GetMarketHighestHigh( + bar_index, + dailyCount + ); + double dailyLL = GetMarketLowestLow( + bar_index, + dailyCount + ); + double dailyDiff = dailyHH - dailyLL; + double rate = dailyDiff / 100; + + // + for (int i = bar_index; i < bar_index + marketLength; i++) { + // + XOHCL c = GetCandleModel(i); + + // + double cRange = + MathAbs(c.open - c.close) + // MathAbs(c.high - c.low) + ; + bool isBullish = c.open < c.close; + + // + if (isBullish) { + powerUp += cRange; + } else { + powerDown += cRange; + } + } + + // + powerUp = powerUp / rate; + powerDown = powerDown / rate; + + // + double ema = GetMA( + bar_index, + marketLength, + 0, + MODE_EMA, + PRICE_WEIGHTED + ); + + // + double signal = (ema / 100) * rate; + double signalAddition = MathMin(powerUp, powerDown); + + // + powerUpBuffer[bar_index] = powerUp; + powerDownBuffer[bar_index] = powerDown; + signalBuffer[bar_index] = signal + signalAddition; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020420/x-saherelm.x.trend.power.v2.mq4 b/Bkp/Used/14020420/x-saherelm.x.trend.power.v2.mq4 new file mode 100644 index 0000000..de50c39 --- /dev/null +++ b/Bkp/Used/14020420/x-saherelm.x.trend.power.v2.mq4 @@ -0,0 +1,291 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center Trend Power Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 MA Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 7; // Market Length +input int shift = 0; // Shift +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_separate_window + +// +#property indicator_plots 3 +#property indicator_buffers 3 +// #property indicator_minimum 0 +// #property indicator_maximum 200 + +// +#property indicator_levelcolor clrGray +#property indicator_levelstyle STYLE_DOT + +// +// Start Define Indicator Buffer Styles ... +// +#property indicator_type1 DRAW_HISTOGRAM +#property indicator_color1 clrLime +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +#property indicator_type2 DRAW_HISTOGRAM +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 + +// +// #property indicator_type4 DRAW_LINE +// #property indicator_color4 clrAqua +// #property indicator_style4 STYLE_DASHDOT +// #property indicator_width4 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define powerUpBufferIndex 0 +#define powerDownBufferIndex 1 +#define signalBufferIndex 2 +// #define diBufferIndex 3 + +double powerUpBuffer[]; +double powerDownBuffer[]; +double signalBuffer[]; +// double diBuffer[]; + +// +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (marketLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // // + // SetLevelValue(0, 0.0); + // IndicatorSetString(INDICATOR_LEVELTEXT,0,""); + + // // + // SetLevelValue(1, 50); + // IndicatorSetString(INDICATOR_LEVELTEXT,1,""); + + // // + // SetLevelValue(2, 100); + // IndicatorSetString(INDICATOR_LEVELTEXT,2,""); + + // + string pUpLbl = StringConcatenate( + "P Up (", marketLength, ")" + ); + SetIndexLabel(powerUpBufferIndex, pUpLbl); + SetIndexBuffer(powerUpBufferIndex, powerUpBuffer); + SetIndexDrawBegin(powerUpBufferIndex, marketLength + 1); + + // + string pDownLbl = StringConcatenate( + "P Down (", marketLength, ")" + ); + SetIndexLabel(powerDownBufferIndex, pDownLbl); + SetIndexBuffer(powerDownBufferIndex, powerDownBuffer); + SetIndexDrawBegin(powerDownBufferIndex, marketLength + 1); + + // + string pSignalLbl = StringConcatenate( + "P Signal (", marketLength, ")" + ); + SetIndexLabel(signalBufferIndex, pSignalLbl); + SetIndexBuffer(signalBufferIndex, signalBuffer); + SetIndexDrawBegin(signalBufferIndex, marketLength + 1); + + // // + // string pDiLbl = StringConcatenate( + // "P DI (", marketLength, ")" + // ); + // SetIndexLabel(diBufferIndex, pDiLbl); + // SetIndexBuffer(diBufferIndex, diBuffer); + // SetIndexDrawBegin(diBufferIndex, marketLength + 1); + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "X_TPW_OSC"; + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Buffers ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateBuffers( + const int &bar_index +) { + // + double powerUp = 0; + double powerDown = 0; + + // + int dailyCount = GetDailyCandleCount(); + double dailyHH = GetMarketHighestHigh( + bar_index, + dailyCount + ); + double dailyLL = GetMarketLowestLow( + bar_index, + dailyCount + ); + double dailyDiff = dailyHH - dailyLL; + double rate = dailyDiff / 100; + + // + for (int i = bar_index + shift; i < bar_index + marketLength + shift; i++) { + // + XOHCL c = GetCandleModel(i); + + // + double cRange = + MathAbs(c.open - c.close) + // MathAbs(c.high - c.low) + ; + bool isBullish = c.open < c.close; + + // + if (isBullish) { + powerUp += cRange; + } else { + powerDown += cRange; + } + } + + // + powerUp = powerUp / rate; + powerDown = powerDown / rate; + + + // + double ema = GetMA( + bar_index, + (marketLength * 2), + 0, + MODE_EMA, + PRICE_WEIGHTED + ); + + // + powerUpBuffer[bar_index] = powerUp; + + // + powerDownBuffer[bar_index] = -1 * powerDown; + + // + double emaRate = MathAbs(powerUp - MathAbs(powerDown)) / 100; + double signal = (ema / 100) * emaRate; + + // + bool isPowerUp = powerUp > MathAbs(powerDown); + double signalAddition = isPowerUp ? (-1 * powerDown) : powerUp; + signalBuffer[bar_index] = signal + signalAddition; + // + // double pDiff = powerUpBuffer[bar_index] - powerDownBuffer[bar_index]; + // double cDiValue = pDiff + signalBuffer[bar_index]; + // diBuffer[bar_index] = cDiValue; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020420/x-saherelm.x.xma.mq4 b/Bkp/Used/14020420/x-saherelm.x.xma.mq4 new file mode 100644 index 0000000..b8c64d7 --- /dev/null +++ b/Bkp/Used/14020420/x-saherelm.x.xma.mq4 @@ -0,0 +1,395 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center X Indicator +// --------------------------------------------- +// saherelm implementation of above 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 X Indicator" +#property strict + +// +// START Inputs ... +// +// +input int marketLength = 7; // Market Length + +// +input double step = 0.02; // P SAR Step +input double maximum = 0.2; // P SAR Maximum + +// +input int shortCycleMultiplier = 2; // Market Short Cycle Multiplier +input int mediumCycleMultiplier = 6; // Market Medium Cycle Multiplier +input int longCycleMultiplier = 36; // Market Medium Cycle Multiplier + +// +input ENUM_MA_METHOD maMethod = MODE_SMA; // Ma Method +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 7 + +// +#property indicator_plots 7 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Short Cycle Fast Buffer ... +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +// Short Cycle Slow Buffer ... +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +// Medium Cycle Fast Buffer ... +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrAqua +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 + +// +// Medium Cycle Slow Buffer ... +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrFuchsia +#property indicator_style4 STYLE_DOT +#property indicator_width4 1 + +// +// Long Cycle Fast Buffer ... +#property indicator_type5 DRAW_LINE +#property indicator_color5 C'62,82,6' +#property indicator_style5 STYLE_DOT +#property indicator_width5 1 + +// +// Long Cycle Slow Buffer ... +#property indicator_type6 DRAW_LINE +#property indicator_color6 C'255,81,0' +#property indicator_style6 STYLE_DOT +#property indicator_width6 1 + +// +// Parabolic SAR ... +#property indicator_type7 DRAW_LINE +#property indicator_color7 C'0,174,255' +#property indicator_style7 STYLE_DASHDOT +#property indicator_width7 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +// +// Ma Buffers ... +#define scFastBufferIndex 0 +#define scSlowBufferIndex 1 +#define mcFastBufferIndex 2 +#define mcSlowBufferIndex 3 +#define lcFastBufferIndex 4 +#define lcSlowBufferIndex 5 +#define psarBufferIndex 6 + +double scFastBuffer[]; +double scSlowBuffer[]; +double mcFastBuffer[]; +double mcSlowBuffer[]; +double lcFastBuffer[]; +double lcSlowBuffer[]; +double psarBuffer[]; + +// +// Variables ... +int shortCycleLength; +int mediumCycleLength; +int longCycleLength; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if ( + marketLength <= 0 || + shortCycleMultiplier <= 0 || + mediumCycleMultiplier <= 0 || + shortCycleMultiplier > mediumCycleMultiplier + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + shortCycleLength = shortCycleMultiplier * marketLength; + mediumCycleLength = mediumCycleMultiplier * marketLength; + longCycleLength = longCycleMultiplier * marketLength; + + // + // Ma Buffers ... + // + // Short Cycle ... + string scFLbl = StringConcatenate( + "SC F(", shortCycleLength, ")" + ); + SetIndexBuffer(scFastBufferIndex, scFastBuffer); + SetIndexLabel(scFastBufferIndex, scFLbl); + + // + string scSLbl = StringConcatenate( + "SC S(", shortCycleLength, ")" + ); + SetIndexBuffer(scSlowBufferIndex, scSlowBuffer); + SetIndexLabel(scSlowBufferIndex, scSLbl); + + // + // Medium Cycle ... + string mcFLbl = StringConcatenate( + "MC F(", mediumCycleLength, ")" + ); + SetIndexBuffer(mcFastBufferIndex, mcFastBuffer); + SetIndexLabel(mcFastBufferIndex, mcFLbl); + + // + string mcSLbl = StringConcatenate( + "MC S(", mediumCycleLength, ")" + ); + SetIndexBuffer(mcSlowBufferIndex, mcSlowBuffer); + SetIndexLabel(mcSlowBufferIndex, mcSLbl); + + // + // Long Cycle ... + string lcFLbl = StringConcatenate( + "LC F(", longCycleLength, ")" + ); + SetIndexBuffer(lcFastBufferIndex, lcFastBuffer); + SetIndexLabel(lcFastBufferIndex, lcFLbl); + + // + string lcSLbl = StringConcatenate( + "LC S(", longCycleLength, ")" + ); + SetIndexBuffer(lcSlowBufferIndex, lcSlowBuffer); + SetIndexLabel(lcSlowBufferIndex, lcSLbl); + // + // End Set Index Buffers ... + // + + // + // Parabolic Sar ... + SetIndexBuffer(psarBufferIndex, psarBuffer); + SetIndexLabel(psarBufferIndex, "P Sar"); + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculat Ma's ... + // + CalculateShortCycle(i); + + // + CalculateMediumCycle(i); + + // + CalculateLongCycle(i); + + // + // Parabolic SAR ... + CalculateParabolicSAR(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Short Cycle ... +void CalculateShortCycle( + const int &bar_index +) { + // + double scFast = iMA( + _Symbol, + _Period, + shortCycleLength, + 0, + maMethod, + PRICE_OPEN, + bar_index + ); + scFastBuffer[bar_index] = scFast; + + // + double scSlow = iMA( + _Symbol, + _Period, + shortCycleLength, + 0, + maMethod, + PRICE_CLOSE, + bar_index + ); + scSlowBuffer[bar_index] = scSlow; +} + +// +// Calculating Medium Cycle ... +void CalculateMediumCycle( + const int &bar_index +) { + // + double mcFast = iMA( + _Symbol, + _Period, + mediumCycleLength, + 0, + maMethod, + PRICE_OPEN, + bar_index + ); + mcFastBuffer[bar_index] = mcFast; + + // + double mcSlow = iMA( + _Symbol, + _Period, + mediumCycleLength, + 0, + maMethod, + PRICE_CLOSE, + bar_index + ); + mcSlowBuffer[bar_index] = mcSlow; +} + +// +// Calculating Long Cycle ... +void CalculateLongCycle( + const int &bar_index +) { + // + double lcFast = iMA( + _Symbol, + _Period, + longCycleLength, + 0, + maMethod, + PRICE_OPEN, + bar_index + ); + lcFastBuffer[bar_index] = lcFast; + + // + double lcSlow = iMA( + _Symbol, + _Period, + longCycleLength, + 0, + maMethod, + PRICE_CLOSE, + bar_index + ); + lcSlowBuffer[bar_index] = lcSlow; +} + +// +// Calculate Parabolic SAR ... +void CalculateParabolicSAR( + const int &bar_index +) { + // + double pSar = iSAR( + _Symbol, + _Period, + step, + maximum, + bar_index + ); + + // + psarBuffer[bar_index] = pSar; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/21-00/Experts/x-saherelm.ea.mq4 b/Bkp/Used/14020425/21-00/Experts/x-saherelm.ea.mq4 new file mode 100644 index 0000000..7c8692f --- /dev/null +++ b/Bkp/Used/14020425/21-00/Experts/x-saherelm.ea.mq4 @@ -0,0 +1,790 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XST Strategy Expert Advisor +// --------------------------------------------- +// saherelm implementation of strategy expert advisor ... +// in this EA, we try to combine multiple tools, to ashive best +// results ... +// +// ShortName: XST +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +989121694056 +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XST Strategy Expert Advisor" +#property strict + +// +// START Inputs ... +// +// +// Signal Prefixe ... +input string signalPrefix = "XST"; // Signal Prefix + +// +// Signal Draw Specifications ... +input string bullishSignalLabel = "X_BUY"; // Bullish Signal Label +input color bullishSignalColor = clrAqua; // Bullish Signal Color + +// +input string bearishSignalLabel = "X_SELL"; // Bearish Signal Label +input color bearishSignalColor = clrFuchsia; // Bearish Signal Color + +// +input color signalEntryColor = clrAquamarine; // Signal Entry Ptice Color +input color signalSLColor = clrRed; // Signal SL Color +input color signalTPColor = clrGreen; // Signal TP Color + +// +// Trade ... +input bool allowTrade = true; // Allow Trade Based on given Signals +input bool allowLongTrades = true; // Allow Long Trades +input bool allowShortTrades = false; // Allow Short Trades + +// +// Market Specification Inpouts ... +input int marketLength = 7; // Market Length +input double riskToRewardRatio = 1.5; // Risk to Reward Ratio +// input double maxTPMultiplier = 1000; // Max Allowed TP + +// +// Alerts ... +input bool alertEvents = true; // Alert Events +input bool alertPositions = true; // Alert Positions +input bool longPositionAlerts = true; // Alert Long Positions +input bool shortPositionAlerts = true; // Alert Short Positions + +// +// Alert Types ... +input bool terminalAlert = false; // Terminal Alert +input bool pushAlert = false; // Push Notification Alerts + +// +// Balance and Finanical Specifications ... +input double lotsPerTradePercent = 0.00001; // Lots Per Trade Percent +input int maxOpenTrades = 4; // Maximum Open Trade +input double maxDrawdownPercentPerPTrade = 0.05; // Maximum DrawDown Per Trade +input double minBalancePercent = 0.5; // Minimum Balance for Trading +input double maxEquityPercent = 0.1; // Maximum Trade Equity +input int closeAllOpenTradesAfterCandle = 408; // Close All Open Trades After Passed Candles +input bool closeAllInProfitOpenTradesWhenMaxOpenTradesReached = false; // Close All In Profit Open Trades When Max Open Trades Reached and New Signal Income + +// +// Indicators ... +// +// CCI Inputs ... +input double step = 0.01; // SAR Step +input double maximum = 0.1; // SAR Maximum + +// +// XMA Inputs ... +// +input int shortCycleFastMultiplier = 2; // Short Cycle Fast Multiplier +input int shortCycleSlowMultiplier = 4; // Short Cycle Slow Multiplier +input int mediumCycleFastMultiplier = 6; // Medium Cycle Fast Multiplier +input int mediumCycleSlowMultiplier = 12; // Medium Cycle Slow Multiplier +input int longCycleFastMultiplier = 36; // Long Cycle Fast Multiplier +input int longCycleSlowMultiplier = 72; // Long Cycle Slow Multiplier + +// +// SHPD Indicator ... +input double sharpDetectMultiplier = 800; // Sharp Detect Multiplier +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +int lastSignalledBar = 0; + +// +bool waitForLongSignals = true; +bool closeLongTrades = false; + +// +bool waitForShortSignals = true; +bool closeShortTrades = false; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.signal.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Validate Inputs ... + bool inputsNotValiid = + // + // MARKET ... + marketLength < 0 + || riskToRewardRatio < 0 + // + // EA ... + || lotsPerTradePercent < 0 + || maxOpenTrades <= 0 + || maxDrawdownPercentPerPTrade < 0 + || minBalancePercent < 0 + || maxEquityPercent < 0 + || marketLength < 0 + // + // XMA ... + // + // Validate Short Cycle ... + || shortCycleFastMultiplier <= 0 + || shortCycleSlowMultiplier <= 0 + || shortCycleFastMultiplier >= shortCycleSlowMultiplier + // + // Validate Medium Cycle ... + || mediumCycleFastMultiplier <= 0 + || mediumCycleSlowMultiplier <= 0 + || mediumCycleFastMultiplier >= mediumCycleSlowMultiplier + // + // Validate Long Cycle ... + || longCycleFastMultiplier <= 0 + || longCycleSlowMultiplier <= 0 + || longCycleFastMultiplier >= longCycleSlowMultiplier + // + // Validate Series of Multipliers ... + || shortCycleFastMultiplier >= mediumCycleFastMultiplier + || mediumCycleFastMultiplier >= longCycleFastMultiplier + ; + + // + if (inputsNotValiid) { + return INIT_PARAMETERS_INCORRECT; + } + + // + totalSignals = 0; + totalLongSignals = 0; + totalShortSignals = 0; + + // + initialBalance = 0; + + // + // START Define Array Series ... + // + // + // END Define Array Series ... + // + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST"; + + // // + // // Set Event Timer on One Seccond ... + // bool isEventSet = EventSetTimer(1); + // if (!isEventSet) { + // LogMessage("Error: " + GetLastError()); + // return INIT_FAILED; + // } + + // + ClearSignalConditions(); + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + // Killing Event Timer ... + EventKillTimer(); +} + +// +// Ticker Event Handler ... +void OnTick() { + // + isNewDay = IsNewDay(); + if (isNewDay) { + // + LogMessage( + StringConcatenate( + "New Day: ", TimeCurrent() + ) + ); + } + + // + // Process Signals to Open Positions ... + ProcessSignals(); + + // + // Checking State for Signal Handling ... + CheckState(); + + // + // Process Open Positions for Trailing Stop Loss or Close ... + ProcessOpenPositions(); +} + +// +// Timer Event Handler ... +void OnTimer() { + // + CheckState(); + + // + ProcessOpenPositions(); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Check State for Signal Handling ... +void CheckState() { + // + // Here we Must to Check Market State for enable or disable + // Signal Handlers and also make dection to close all long/short + // trades ... + + // // + // closeLongTrades = xCloseLongTrades; + // waitForLongSignals = xWaitForLongSignals; + + // // + // closeShortTrades = xCloseShortTrades; + // waitForShortSignals = xWaitForShortSignals; + + // // + // xCloseLongTrades = false; + // xCloseShortTrades = false; +} + +// +// Calculate Signals and Process Based on Exists Signals ... +void ProcessSignals() { + // + XSignalRequest request = {}; + request.type = X_SIGNAL_NONE; + request.hasSignal = false; + + // + // Prevent Multiple Calculating on Same Bars ... + isNewBar = IsNewBar(); + if (isNewBar) { + countedBars++; + } + + // + if (countedBars < longCycleSlowMultiplier * marketLength) { + return; + } + + // + bool allowDoTrade = true; + + // + // Check Balance ... + if (initialBalance > 0) { + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double minimumBalanceForTrade = + balance > initialBalance + ? + minBalancePercent * balance + : + minBalancePercent * initialBalance; + + // + // Retrieve Account Equity ... + double equity = AccountInfoDouble(ACCOUNT_EQUITY); + double maxAllowedEquity = balance - (balance * maxEquityPercent); + + // + // Retrieve Free Marigin ... + double freeMargin = AccountFreeMargin(); + double maximumMariginRisk = balance - (balance * maxEquityPercent); + + // + if ( + // + // Do not Open Positions if equity not passed ... + equity < maxAllowedEquity || + // + // Do not Open Positions if free margin not passed ... + freeMargin <= maximumMariginRisk || + // + // Do not open positions if balance less than minimum ... + balance <= minimumBalanceForTrade + ) { + // + allowDoTrade = false; + + // // + // string message = StringConcatenate( + // "Trading Pause => ", + // "Balance: ", balance, + // ", Equity: ", equity, + // ", FreeMargin: ", freeMargin + // ); + + // // + // LogMessage(message); + // SendAlert(message); + } + } + + // + // Retrieve Signal Exists ... + request = GenerateSignal(0); + + // + // Prevent doing anything else, if there is no signals ... + if ( + !allowDoTrade || + !request.hasSignal || + request.type == X_SIGNAL_NONE + ) { + return; + } + + // + bool hasLongSignal = request.type == X_SIGNAL_LONG; + + // + // Check For Bot State ... + if ( + (hasLongSignal && !waitForLongSignals) + || (!hasLongSignal && !waitForShortSignals) + ) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + return; + } + + // + // Check last Signalled Bar with Counted Bars ... + // Prevent Multiple Signalling on Same Bar ... + bool isInLastSignalledBars = false; + for (int i=0; i < marketLength; i++) { + // + isInLastSignalledBars = + isInLastSignalledBars + || lastSignalledBar == countedBars - i + ; + } + if (isInLastSignalledBars) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + return; + } + + // + // increase last signalled bar ... + lastSignalledBar = countedBars; + + // + // Calculate Can Trade or not ... + allowDoTrade = allowTrade + && ( + hasLongSignal ? + allowLongTrades : + allowShortTrades + ); + + // + // Chack Maximum Open Positions ... + int openTrades = CountOpenTrades(); + if (maxOpenTrades > 0) { + // + if (openTrades >= maxOpenTrades) { + // + allowDoTrade = false; + + // + if (closeAllInProfitOpenTradesWhenMaxOpenTradesReached) { + // + // Close All In Profit Trades ... + bool hasClosedInProfitTrade = CloseAllInProfitTrades(); + if (hasClosedInProfitTrade) { + // + openTrades = CountOpenTrades(); + + // + allowDoTrade = !(openTrades >= maxOpenTrades); + } + } + + // + if (!allowDoTrade) { + // + string message = StringConcatenate( + "Trading Pause => ", + "Max Open Trades (", + maxOpenTrades, + ") reached ..." + ); + + // + LogMessage(message); + SendAlert(message); + } + } + } + + // + // Check Trading is Enable or not ... + // nothing to do if trading is disabled ... + if (!allowDoTrade) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // // + // string message = StringConcatenate( + // "Trading Not Allowed ..." + // ); + + // // + // LogMessage(message); + // SendAlert(message); + return; + } + + // + bool isPositionOpened = TradeSignal( + request.signal, + signalPrefix, + lotsPerTradePercent, + // + bullishSignalLabel, + bullishSignalColor, + bearishSignalLabel, + bearishSignalColor + ); + + // + totalSignals++; + if (hasLongSignal) { + // + totalLongSignals++; + ClearLongSignalConditions(); + } else { + // + totalShortSignals++; + ClearShortSignalConditions(); + } + + // + if (isPositionOpened) { + // + bool canAlert = + alertPositions + && ( + hasLongSignal ? + longPositionAlerts + : + shortPositionAlerts + ); + + // + if (canAlert) { + // + // Alert Message ... + string message = StringConcatenate( + "Trade on Signal ID: ", request.signal.id, + ", Entry: ", request.signal.entry, + ", TP: ", request.signal.tp + ); + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } + } + } +} + +// +// Process All Open Positions ... +void ProcessOpenPositions() { + // + // this comes from check state ... + if (closeLongTrades) { + // + closeLongTrades = false; + + // + bool isAllLongTradesClosed = CloseAllLongTrades(); + if (isAllLongTradesClosed) { + } + } + + // + // this comes from check state ... + if (closeShortTrades) { + // + closeShortTrades = false; + + // + bool isAllShortTradesClosed = CloseAllShortTrades(); + if (isAllShortTradesClosed) { + } + } + + // + // Close All XXX Provided Signals on it's Specific Condition ... + if (xCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XXX_PROVIDER); + + // + xCloseLongTrades = false; + } + + // + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + closeAllOpenTradesAfterCandle + ); + + // + // Close Maximum DrawDown Passed Trades ... + bool hasClosedInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + maxDrawdownPercentPerPTrade + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedInDrawDownLongTrade + ) { + // + // waitForLongSignals = false; + } +} + +// +// Send Special Type of Alerts ... +void SendAlert(string message) { + // + if (!alertEvents) { + return; + } + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } +} +// +// END Functions ... +// + +// +// +// Calculate Signal ... +// in this function we calculate a signal exists in +// specific bar or not ... +XSignalRequest GenerateSignal( + const int bar_index // Bar Index ... +) { + // + // create temp result ... + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + bool hasSignal = false; + bool hasLongSignal = false; + bool hasShortSignal = false; + + // + XSignal signal = {}; + + // + // Retrieve XMA States ... + // based on medium cycle slow ... + XState states[]; + ArrayFree(states); + ArrayResize( + states, + marketLength + ); + + // + int index = 0; + for (int i = bar_index; i < bar_index + marketLength; i++) { + // + states[index] = GetXState( + i, + marketLength, + // + step, + maximum, + // + shortCycleFastMultiplier, + shortCycleSlowMultiplier, + mediumCycleFastMultiplier, + mediumCycleSlowMultiplier, + longCycleFastMultiplier, + longCycleSlowMultiplier + ); + + // + index++; + } + + // + CheckXLongSignalConditions( + bar_index, + marketLength, + states + ); + + // + CheckXShortSignalConditions( + bar_index, + marketLength, + states + ); + + // + XSignalRequest xLongSignalRequest = GenerateXSignal( + X_SIGNAL_LONG, + bar_index, + marketLength, + riskToRewardRatio, + states + ); + + // + XSignalRequest xShortSignalRequest = GenerateXSignal( + X_SIGNAL_SHORT, + bar_index, + marketLength, + riskToRewardRatio, + states + ); + + // + if (xLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXSignals( + xLongSignalRequest.signal, + states, + marketLength + ); + + // + if (isReady && xWaitForLongSignals) { + // + hasLongSignal = true; + signal = xLongSignalRequest.signal; + } else { + ClearXLongSignalConditions(); + } + } else if (xShortSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXSignals( + xShortSignalRequest.signal, + states, + marketLength + ); + + // + if (isReady) { + // + hasShortSignal = true; + signal = xShortSignalRequest.signal; + } else { + ClearXShortSignalConditions(); + } + } + + // + hasSignal = hasLongSignal || hasShortSignal; + + // + if (!hasSignal) { + // + signal.type = X_SIGNAL_NONE; + result.type = X_SIGNAL_NONE; + } + + // + // Normalize TP, SL and Entry Price ... + signal.tp = NormalizeDouble(signal.tp, _Digits); + signal.sl = NormalizeDouble(signal.sl, _Digits); + signal.entry = NormalizeDouble(signal.entry, _Digits); + + // + result.signal = signal; + result.type = signal.type; + result.hasSignal = hasSignal; + result.provider = signal.provider; + + // + // Return Result ... + return result; +} diff --git a/Bkp/Used/14020425/21-00/Indicators/x-saherelm.adx.mq4 b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.adx.mq4 new file mode 100644 index 0000000..3271a4e --- /dev/null +++ b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.adx.mq4 @@ -0,0 +1,220 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center ADX Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm ADX Oscillator" +#property strict + +// +// START Inputs ... +// +input int length = 7; // Averaging Length +input ENUM_APPLIED_PRICE appliedPrice = PRICE_WEIGHTED; // Averaging Applied Price +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_separate_window + +// +#property indicator_minimum 0 +#property indicator_maximum 100 + +// +#property indicator_buffers 3 + +// +#property indicator_level1 0.0 +#property indicator_level2 50.0 +#property indicator_level3 70.0 +#property indicator_level4 100.0 +#property indicator_levelcolor clrSilver +#property indicator_levelstyle STYLE_DOT + +// +// ADX ... +#property indicator_width1 1 +#property indicator_color1 clrLightBlue +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_SOLID + +// +// Positive Direction ... +#property indicator_width2 1 +#property indicator_color2 clrLime +#property indicator_type2 DRAW_LINE +#property indicator_style2 STYLE_DOT + +// +// Negative Direction ... +#property indicator_width3 1 +#property indicator_color3 clrRed +#property indicator_type3 DRAW_LINE +#property indicator_style3 STYLE_DOT + +// +// Declare Buffers ... +#define adxBufferIndex 0 +#define positiveBufferIndex 1 +#define negativeBufferIndex 2 + +double adxBuffer[]; +double positiveBuffer[]; +double negativeBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (length < 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + IndicatorBuffers(3); + + // + SetIndexBuffer(positiveBufferIndex, positiveBuffer); + SetIndexLabel(positiveBufferIndex, "DI+"); + + // + SetIndexBuffer(negativeBufferIndex, negativeBuffer); + SetIndexLabel(negativeBufferIndex, "DI-"); + + // + SetIndexBuffer(adxBufferIndex, adxBuffer); + SetIndexLabel(adxBufferIndex, "ADX"); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, length); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Long TP ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index +) { + // + // Calculate Buffers ... + + // + // Retrieves the current ADX value ... + double adx = iADX( + _Symbol, + _Period, + length, + appliedPrice, + MODE_MAIN, + bar_index + ); + adxBuffer[bar_index] = adx; + + // + // Retrieves the current DI+ value ... + double plusDi = iADX( + _Symbol, + _Period, + length, + appliedPrice, + MODE_PLUSDI, + bar_index + ); + positiveBuffer[bar_index] = plusDi; + + // + // Retrieves the current DI- value ... + double minusDi = iADX( + _Symbol, + _Period, + length, + appliedPrice, + MODE_MINUSDI, + bar_index + ); + negativeBuffer[bar_index] = minusDi; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/21-00/Indicators/x-saherelm.ma.mq4 b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.ma.mq4 new file mode 100644 index 0000000..e3a5737 --- /dev/null +++ b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.ma.mq4 @@ -0,0 +1,173 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MA Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 MA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Fast MA ... +input int maLength = 20; // MA Length +input int maShift = 0; // MA Shift +input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method +input ENUM_APPLIED_PRICE maAppliedPrice = PRICE_CLOSE; // MA Applied Price + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 1 + +// +#property indicator_plots 1 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Fast Ma Buffer ... +#property indicator_label1 "Ma" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrYellow +#property indicator_style1 STYLE_DOT +#property indicator_width1 2 + +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define maBufferIndex 0 + +double maBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (maLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + // + // Ma ... + SetIndexBuffer(maBufferIndex, maBuffer); + SetIndexDrawBegin(maBufferIndex, maLength + 1); + // + // End Set Index Buffers ... + // + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, maLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Ma ... + CalculateMa(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateMa( + const int &bar_index +) { + // + // Calculating Fast Ma ... + double ma = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + maAppliedPrice, + bar_index + ); + + // + maBuffer[bar_index] = ma; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/21-00/Indicators/x-saherelm.momentum.mq4 b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.momentum.mq4 new file mode 100644 index 0000000..ea6e419 --- /dev/null +++ b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.momentum.mq4 @@ -0,0 +1,160 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center Momentum Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm Momentum Oscillator" +#property strict + +// +// START Inputs ... +// +input int length = 7; // Market Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_separate_window + +// +#property indicator_buffers 1 + +// +#property indicator_level1 0.0 +#property indicator_level2 100.0 +#property indicator_levelcolor clrSilver +#property indicator_levelstyle STYLE_DOT + +// +// MOMENTUM ... +#property indicator_width1 1 +#property indicator_color1 clrLightBlue +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_SOLID + +// +// Declare Buffers ... +#define momentumBufferIndex 0 + +double momentumBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (length < 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + IndicatorBuffers(1); + + // + SetIndexBuffer(momentumBufferIndex, momentumBuffer); + SetIndexLabel(momentumBufferIndex, "Momentum"); + SetIndexDrawBegin(momentumBufferIndex, length); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, length); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Long TP ... + CalculateBuffers( + i, + close + ); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index, + const double &close[] +) { + // + // Calculate Buffers ... + double momentum = close[bar_index] * 100 / close[bar_index + length]; + + // + momentumBuffer[bar_index] = momentum; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/21-00/Indicators/x-saherelm.osc.mq4 b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.osc.mq4 new file mode 100644 index 0000000..829f32c --- /dev/null +++ b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.osc.mq4 @@ -0,0 +1,257 @@ +///////////////////////////////////////////////////////////////// +// +// SaherElm IT Center OSC Indicator +// ------------------------------------------------------------- +// this indicator provides OSC ... +// +// 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 OSC Indicator" +#property strict + +// +// START Inputs ... +// +// +// FastOSC ... +// Short Cycle (Fast OSC) ... +input int fastOSCLength = 10; // FastOSC Length +input double fastOSCMultiplier = 1.0; // FastOSC Multiplier + +// +// SlowOSC ... +// Medium Cycle (Slow OSC) ... +input int slowOSCLength = 30; // SlowOSC Length +input double slowOSCMultiplier = 3.0; // SlowOSC Multiplier +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +#property indicator_separate_window + +// +// we have 2 buffer in this indicator ... +#property indicator_buffers 2 + +// +// also we have 2 line for draw on this indicator ... +#property indicator_plots 2 + +// +// Fast OSC ... +#property indicator_width1 1 +#property indicator_color1 clrAqua +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_SOLID + +// +// Slow OSC ... +#property indicator_width2 1 +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrFuchsia +#property indicator_style2 STYLE_SOLID + +// +// set color of horizontal levels ... +#property indicator_levelcolor clrGray + +// +// set style of horizontal levels ... +#property indicator_levelstyle STYLE_DOT + +// +// Declare Buffers ... +#define fastOSCBufferIndex 0 +#define slowOSCBufferIndex 1 + +// +double fastOSCBuffer[]; +double slowOSCBuffer[]; + +// +// Used Indicators List ... +string rmaIndicatorName = "x-saherelm.rma"; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + fastOSCLength < 0 || + slowOSCLength < 0 || + slowOSCLength <= fastOSCLength + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XS_OSC"; + + // + // set descriptions of horizontal levels ... + SetLevelValue(0, 0.0); + IndicatorSetString(INDICATOR_LEVELTEXT,0,""); + + // + // set descriptions of horizontal levels ... + SetLevelValue(1, 0.5); + IndicatorSetString(INDICATOR_LEVELTEXT,1,""); + + // + // set descriptions of horizontal levels ... + SetLevelValue(2, 1); + IndicatorSetString(INDICATOR_LEVELTEXT,2,""); + + // + // Fast OSC Buffer ... + SetIndexBuffer(fastOSCBufferIndex, fastOSCBuffer); + SetIndexLabel(fastOSCBufferIndex, "Fast OSC"); + SetIndexDrawBegin(fastOSCBufferIndex, fastOSCLength - 1); + + // + // Slow OSC Buffer ... + SetIndexBuffer(slowOSCBufferIndex, slowOSCBuffer); + SetIndexLabel(slowOSCBufferIndex, "Slow OSC"); + SetIndexDrawBegin(slowOSCBufferIndex, slowOSCLength - 1); + + // + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(fastOSCLength, slowOSCLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + CalculateOscillators(close, i); + } + + // + return rates_total; +} + +// +// De Initialization ... +void OnDeinit(const int reason) { +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +void CalculateOscillators( + const double &close[], + const int &bar_index +) { + // + // FastOSC ... + // Short Cycle Calculations ... + int scl = fastOSCLength / 2; + int scl2 = scl / 2; + double maScl = iCustom(_Symbol, _Period, rmaIndicatorName, scl, 0, bar_index); + double scmAtr = iATR(_Symbol, _Period, scl, bar_index); + double scmOff = fastOSCMultiplier * scmAtr; + double maScl2 = iCustom(_Symbol, _Period, rmaIndicatorName, scl2, 0, bar_index); + double sctParam = maScl2 != 0 ? maScl2 : close[bar_index + 1]; + double sct = sctParam + scmOff; + double scb = sctParam - scmOff; + + // + // SlowOSC ... + // Medium Cycle Calculations ... + int mcl = slowOSCLength / 2; + int mcl2 = mcl / 2; + double maMcl = iCustom(_Symbol, _Period, rmaIndicatorName, mcl, 0, bar_index); + double mcmAtr = iATR(_Symbol, _Period, mcl, bar_index); + double mcmOff = slowOSCMultiplier * mcmAtr; + double maMcl2 = iCustom(_Symbol, _Period, rmaIndicatorName, mcl2, 0, bar_index); + double mctParam = maMcl2 != 0 ? maMcl2 : close[bar_index + 1]; + double mct = mctParam + mcmOff; + double mcb = mctParam - mcmOff; + + // + double scMM = (sct + scb) / 2; + + // + double fastOCS = (close[bar_index] - mcb) / (mct - mcb); + fastOSCBuffer[bar_index] = fastOCS; + + // + double slowOCS = (scMM - mcb) / (mct - mcb); + slowOSCBuffer[bar_index] = slowOCS; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/21-00/Indicators/x-saherelm.rma.mq4 b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.rma.mq4 new file mode 100644 index 0000000..0fc70fd --- /dev/null +++ b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.rma.mq4 @@ -0,0 +1,141 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center RMA Indicator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm RMA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Set the RMA Length ... +input int RMALength = 10; // Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// we have 2 buffer in this indicator ... +#property indicator_buffers 1 + +// +// also we have 1 line for draw on this indicator ... +#property indicator_plots 1 + +// +// here we declare plot SlowOCS to system ... +#property indicator_label1 "RMA" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrFuchsia +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +// +// Declare Buffers ... +#define RMABufferIndex 0 + +// +double RMABuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + SetIndexBuffer(RMABufferIndex, RMABuffer); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + int maxLength = MathMax(0, RMALength); + + // + // wait to pass bars until we have rights ... + if (rates_total <= maxLength) { + // + // return not calculated ... + return 0; + } + + // + // find loop count for bars manipulation ... + int count = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // Print("Count: ", count, ", Bars: ", Bars); + + // + // this is the main loop of calculations, for each bar index ... + for (int i = count - 1; i >= 0; i--) { + // + // Start Calculation with Formula 1 ... + // + double shortSMA = iMA(_Symbol, _Period, RMALength, 0, MODE_SMA, PRICE_CLOSE, i); + double mediumSMA = iMA(_Symbol, _Period, RMALength * 2, 0, MODE_SMA, PRICE_CLOSE, i); + double longSMA = iMA(_Symbol, _Period, RMALength * 3, 0, MODE_SMA, PRICE_CLOSE, i); + + // + double rma1 = longSMA - mediumSMA + shortSMA; + rma1 = NormalizeDouble(rma1, _Digits); + // + // End Calculation with Formula 1 ... + // + + // + RMABuffer[i] = rma1; + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/21-00/Indicators/x-saherelm.rsi.mq4 b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.rsi.mq4 new file mode 100644 index 0000000..448f732 --- /dev/null +++ b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.rsi.mq4 @@ -0,0 +1,234 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center RSI Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm RSI Oscillator" +#property strict + +// +// START Inputs ... +// +input int rsiPeriod=14; // RSI Period +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_separate_window + +// +#property indicator_minimum 0 +#property indicator_maximum 100 + +// +#property indicator_buffers 1 +#property indicator_color1 DodgerBlue + +// +#property indicator_level1 30.0 +#property indicator_level2 50.0 +#property indicator_level3 70.0 +#property indicator_levelcolor clrSilver +#property indicator_levelstyle STYLE_DOT + +// +// Declare Buffers ... +#define rsiBufferIndex 0 +#define positiveBufferIndex 1 +#define negativeBufferIndex 2 + +double rsiBuffer[]; +double positiveBuffer[]; +double negativeBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + string short_name; + + // + IndicatorBuffers(3); + + // + SetIndexBuffer(positiveBufferIndex, positiveBuffer); + SetIndexBuffer(negativeBufferIndex, negativeBuffer); + + // + SetIndexStyle(rsiBufferIndex, DRAW_LINE); + SetIndexBuffer(rsiBufferIndex, rsiBuffer); + + // + // name for DataWindow and indicator subwindow label + short_name="RSI("+string(rsiPeriod)+")"; + IndicatorShortName(short_name); + SetIndexLabel(rsiBufferIndex, short_name); + + // + // check for input + if (rsiPeriod < 2) { + // + Print("Incorrect value for input variable InpRSIPeriod = ", rsiPeriod); + + // + // Failed Initialization ... + return INIT_PARAMETERS_INCORRECT; + } + + // + // set where to start draw ... + SetIndexDrawBegin(0, rsiPeriod); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + int i,pos; + double diff; + + // + // Prevent from run calculations if there is no fulfilled conditions ... + if (Bars <= rsiPeriod || rsiPeriod < 2) { + // + // return nothing calculated result ... + return 0; + } + + // + // counting from 0 to rates_total, this is most important ... + ArraySetAsSeries(rsiBuffer, false); + ArraySetAsSeries(positiveBuffer, false); + ArraySetAsSeries(negativeBuffer, false); + + // + ArraySetAsSeries(close, false); + + // + // preliminary calculations ... + pos = prev_calculated - 1; + if (pos <= rsiPeriod) { + // + // first RSIPeriod values of the indicator are not calculated + rsiBuffer[0] = 0.0; + positiveBuffer[0] = 0.0; + negativeBuffer[0] = 0.0; + + // + double sump=0.0; + double sumn=0.0; + for (i = 1; i <= rsiPeriod; i++) { + // + rsiBuffer[i]=0.0; + positiveBuffer[i]=0.0; + negativeBuffer[i]=0.0; + + // + diff = close[i] - close[i - 1]; + if(diff > 0) { + sump += diff; + } else { + sumn -= diff; + } + } + + // + // calculate first visible value ... + positiveBuffer[rsiPeriod] = sump / rsiPeriod; + negativeBuffer[rsiPeriod] = sumn / rsiPeriod; + if (negativeBuffer[rsiPeriod] != 0.0) { + // + rsiBuffer[rsiPeriod] = 100.0 - ( + 100.0 / ( + 1.0 + positiveBuffer[rsiPeriod] / negativeBuffer[rsiPeriod] + ) + ); + } else { + // + if (positiveBuffer[rsiPeriod] != 0.0) { + rsiBuffer[rsiPeriod] = 100.0; + } else { + rsiBuffer[rsiPeriod] = 50.0; + } + } + + // + // prepare the position value for main calculation ... + pos = rsiPeriod + 1; + } + + // + // the main loop of calculations ... + for (i = pos; i < rates_total && !IsStopped(); i++) { + // + diff = close[i] - close[i-1]; + + // + positiveBuffer[i] = (positiveBuffer[i-1] * (rsiPeriod - 1) + (diff > 0.0 ? diff : 0.0)) / rsiPeriod; + negativeBuffer[i] = (negativeBuffer[i-1] * (rsiPeriod - 1) + (diff < 0.0 ? -diff : 0.0)) / rsiPeriod; + + // + if (negativeBuffer[i] != 0.0) { + rsiBuffer[i] = 100.0 - 100.0 / (1 + positiveBuffer[i] / negativeBuffer[i]); + } else { + // + if (positiveBuffer[i] != 0.0) { + rsiBuffer[i] = 100.0; + } else { + rsiBuffer[i] = 50.0; + } + } + } + + // + return(rates_total); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/21-00/Indicators/x-saherelm.shpd.mq4 b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.shpd.mq4 new file mode 100644 index 0000000..7c02a84 --- /dev/null +++ b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.shpd.mq4 @@ -0,0 +1,402 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XSHPD Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 XSHPD Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 7; // Market Length ... +input double sharpDetectMultiplier = 70; // Sharp Detect Multiplier + +// +input bool drawLabels = true; // Draw Labels on Founded Sharps + +// +input string sharpBullishLabel = "SH_BULL"; // Sharp Bullish Label +input color sharpBullishColor = clrAqua; // Sharp Bullish color + +// +input string sharpBearishLabel = "SH_BEAR"; // Sharp Bearish Label +input color sharpBearishColor = clrFuchsia; // Sharp Bearish color +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +#property indicator_buffers 4 +#property indicator_plots 4 + +// +// Declare Buffers ... +#define marketHighestHighBufferIndex 0 +#define marketLowestLowBufferIndex 1 +#define sharpBullishBufferIndex 2 +#define sharpBearishBufferIndex 3 + +// +double marketHighestHighBuffer[]; +double marketLowestLowBuffer[]; +double sharpBullishBuffer[]; +double sharpBearishBuffer[]; + +// +#include "../Libraries/x-saherelm.lib.mq4" +#include "../Libraries/x-saherelm.draw.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if ( + marketLength <= 0 + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + enableLogging = true; + + // + logTag = "X_SHPD"; + + // + // Highest High ... + SetIndexLabel(marketHighestHighBufferIndex, ""); + SetIndexBuffer(marketHighestHighBufferIndex, marketHighestHighBuffer); + SetIndexStyle( + marketHighestHighBufferIndex, + DRAW_LINE, // DRAW_NONE, + STYLE_DOT, + 1, // 0, + clrAqua // clrNONE + ); + + // + // Lowest Low ... + SetIndexLabel(marketLowestLowBufferIndex, ""); + SetIndexBuffer(marketLowestLowBufferIndex, marketLowestLowBuffer); + SetIndexStyle( + marketLowestLowBufferIndex, + DRAW_NONE, + STYLE_DOT, + 0, + clrNONE + ); + + // + // Sharp Bullish Buffer ... + SetIndexLabel(sharpBullishBufferIndex, ""); + SetIndexBuffer(sharpBullishBufferIndex, sharpBullishBuffer); + SetIndexStyle( + sharpBullishBufferIndex, + DRAW_NONE, + STYLE_DOT, + 0, + clrNONE + ); + + // + // Sharp Bearish Buffer ... + SetIndexLabel(sharpBearishBufferIndex, ""); + SetIndexBuffer(sharpBearishBufferIndex, sharpBearishBuffer); + SetIndexStyle( + sharpBearishBufferIndex, + DRAW_NONE, + STYLE_DOT, + 0, + clrNONE + ); + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + RemoveDraws(logTag); +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Sharp ... + CalculateSharp(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Sharp ... +void CalculateSharp( + const int &bar_index +) { + // + int index = 0; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + 1 + ); + + // + marketHighestHighBuffer[bar_index] = GetMarketHighestHigh( + bar_index, + marketLength + ); + + // + marketLowestLowBuffer[bar_index] = GetMarketLowestLow( + bar_index, + marketLength + ); + + // + double maHHs[]; + ArrayResize( + maHHs, + marketLength + ); + + // + double maLLs[]; + ArrayResize( + maLLs, + marketLength + ); + + // + index = 0; + for (int i = bar_index; i < bar_index + marketLength; i++) { + // + maLLs[index] = marketLowestLowBuffer[i]; + maHHs[index] = marketHighestHighBuffer[i]; + + // + index++; + } + + // + int maxHighIdx = ArrayMaximum(maHHs); + double maxHigh = maHHs[maxHighIdx]; + + // + int minHighIdx = ArrayMinimum(maHHs); + double minHigh = maHHs[minHighIdx]; + + // + double highDiffRate = (maxHigh - minHigh) / 100; + + // + int maxLowIdx = ArrayMaximum(maLLs); + double maxLow = maLLs[maxLowIdx]; + + // + int minLowIdx = ArrayMinimum(maLLs); + double minLow = maLLs[minLowIdx]; + + // + double lowDiffRate = (maxLow - minLow) / 100; + + // + bool isSharpBullishDetected = + high == maxHigh + && low > minLow + && marketHighestHighBuffer[bar_index] == maxHigh + && maxHigh - minHigh > highDiffRate * sharpDetectMultiplier + ; + sharpBullishBuffer[bar_index] = isSharpBullishDetected ? 1 : 0; + + // + bool isSharpBearishDetected = + low == minLow + && high < maxHigh + && marketLowestLowBuffer[bar_index] == minLow + && maxLow - minLow > lowDiffRate * sharpDetectMultiplier + ; + sharpBearishBuffer[bar_index] = isSharpBearishDetected ? 1 : 0; + + // + if ( + drawLabels + && ( + isSharpBearishDetected + || isSharpBullishDetected + ) + ) { + // + datetime time = iTime( + _Symbol, + _Period, + bar_index + ); + + // + string lbl = StringConcatenate( + logTag, + isSharpBullishDetected ? "Bullish_" : "Bearish_", + bar_index + ); + + // + double price = + isSharpBullishDetected + ? + marketLowestLowBuffer[bar_index] - (10 * _Point) + : + marketHighestHighBuffer[bar_index] + (10 * _Point) + ; + + // + uchar arrowCode = + isSharpBullishDetected + ? + SYMBOL_ARROWUP + : + SYMBOL_ARROWDOWN + ; + + // + ENUM_ARROW_ANCHOR anchor = + isSharpBullishDetected + ? + ANCHOR_BOTTOM + : + ANCHOR_TOP + ; + + // + color clr = + isSharpBullishDetected + ? + sharpBullishColor + : + sharpBearishColor + ; + + // + string lblText = + isSharpBullishDetected + ? + sharpBullishLabel + : + sharpBearishLabel + ; + + // + DrawText( + 0, + lbl, + 0, + time, + price, + lblText, + "Tahoma", + 5, + clr + ); + } +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/21-00/Indicators/x-saherelm.trend.mq4 b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.trend.mq4 new file mode 100644 index 0000000..17873e7 --- /dev/null +++ b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.trend.mq4 @@ -0,0 +1,250 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center ADX Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm ADX Oscillator" +#property strict + +// +// START Inputs ... +// +input int length = 7; // Averaging Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_chart_window + +// +// #property indicator_buffers 3 + +// +// Declare Buffers ... +// +datetime startTime; +double lHigh; +double lLow; + +// +datetime highTimes[]; + +// +datetime lowTimes[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (length < 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, length); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Long TP ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index +) { + // + // Calculate Buffers ... + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + startTime + ); + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + if (startTime == 0) { + // + startTime = barTime; + return; + } + + // + if ( + startTime > 0 + && startBarIndex - bar_index == length + ) { + // + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + length, + bar_index + ); + datetime hhTime = iTime( + _Symbol, + _Period, + hhIdx + ); + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + int hhSize = ArraySize(highTimes); + datetime tempTimes[]; + ArrayResize( + tempTimes, + hhSize + ); + ArrayCopy( + tempTimes, + highTimes + ); + ArrayResize( + highTimes, + hhSize + 1 + ); + highTimes[0] = hhTime; + ArrayCopy( + highTimes, + tempTimes, + 1 + ); + + // + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + length, + bar_index + ); + datetime llTime = iTime( + _Symbol, + _Period, + llIdx + ); + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + int llSize = ArraySize(lowTimes); + ArrayFree(tempTimes); + ArrayResize( + tempTimes, + llSize + ); + ArrayCopy( + tempTimes, + lowTimes + ); + ArrayResize( + lowTimes, + llSize + 1 + ); + lowTimes[0] = llTime; + ArrayCopy( + lowTimes, + tempTimes, + 1 + ); + + // + startTime = 0; + ArrayFree(tempTimes); + } +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/21-00/Indicators/x-saherelm.xbnd.mq4 b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.xbnd.mq4 new file mode 100644 index 0000000..5cea8fd --- /dev/null +++ b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.xbnd.mq4 @@ -0,0 +1,425 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XBand Indicator +// --------------------------------------------- +// saherelm implementation of xBand 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 XBND Indicator" +#property strict + +// +#include "../Libraries/x-saherelm.lib.mq4" +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +// START Inputs ... +// +input int marketLength = 5; // Averaging Length +input int ignoreLastCross = 4; // Ignore Last Cross +input int shift = 0; // Averaging Shift +input ENUM_MA_METHOD method = MODE_SMA; // Averaging Mode +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_chart_window + +// +#property indicator_buffers 4 + +// +// Declare Buffers ... +// +// High ... +#property indicator_width1 1 +#property indicator_color1 clrAqua +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_DASHDOT + +// +// Open ... +#property indicator_width2 1 +#property indicator_color2 clrGreen +#property indicator_type2 DRAW_LINE +#property indicator_style2 STYLE_DASH + +// +// Close ... +#property indicator_width3 1 +#property indicator_color3 clrRed +#property indicator_type3 DRAW_LINE +#property indicator_style3 STYLE_DASH + +// +// Low ... +#property indicator_width4 1 +#property indicator_color4 clrFuchsia +#property indicator_type4 DRAW_LINE +#property indicator_style4 STYLE_DASHDOT + +// +#define highBufferIndex 0 +#define openBufferIndex 1 +#define closeBufferIndex 2 +#define lowBufferIndex 3 + +// +double highBuffer[]; +double openBuffer[]; +double closeBuffer[]; +double lowBuffer[]; + +// +datetime lastCrossTime; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + marketLength < 2 + || ignoreLastCross < 0 + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XBND"; + + // + // High ... + string highLabel = StringConcatenate( + "High(", marketLength, ")" + ); + SetIndexBuffer(highBufferIndex, highBuffer); + SetIndexLabel(highBufferIndex, highLabel); + + // + // Open ... + string openLabel = StringConcatenate( + "Open(", marketLength, ")" + ); + SetIndexBuffer(openBufferIndex, openBuffer); + SetIndexLabel(openBufferIndex, openLabel); + + // + // Close ... + string closeLabel = StringConcatenate( + "Close(", marketLength, ")" + ); + SetIndexBuffer(closeBufferIndex, closeBuffer); + SetIndexLabel(closeBufferIndex, closeLabel); + + // + // Low ... + string lowLabel = StringConcatenate( + "Low(", marketLength, ")" + ); + SetIndexBuffer(lowBufferIndex, lowBuffer); + SetIndexLabel(lowBufferIndex, lowLabel); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + RemoveDraws(logTag); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Buffers ... + CalculateBuffers(i); + + // + // Calculate Market Changes ... + CalculateInfo(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index +) { + // + // High ... + double high = iMA( + _Symbol, + _Period, + marketLength, + shift, + method, + PRICE_HIGH, + bar_index + ); + + // + highBuffer[bar_index] = high; + + // + // Open ... + double open = iMA( + _Symbol, + _Period, + marketLength, + shift, + method, + PRICE_OPEN, + bar_index + ); + + // + openBuffer[bar_index] = open; + + // + // Close ... + double close = iMA( + _Symbol, + _Period, + marketLength, + shift, + method, + PRICE_CLOSE, + bar_index + ); + + // + closeBuffer[bar_index] = close; + + // + // Low ... + double low = iMA( + _Symbol, + _Period, + marketLength, + shift, + method, + PRICE_LOW, + bar_index + ); + + // + lowBuffer[bar_index] = low; +} + +// +void CalculateInfo( + const int bar_index +) { + // + XOHCL pCandle = GetCandleModel(bar_index); + + // + bool isTrendingUp = + pCandle.low > highBuffer[bar_index] + && pCandle.high > highBuffer[bar_index]; + + // + bool isTrendingDown = + pCandle.high < lowBuffer[bar_index] + && pCandle.low < lowBuffer[bar_index]; + + // + bool isOpenCrossOverClose = + true + // && + // ( + // pCandle.high > highBuffer[bar_index + 1] + // || pCandle.low < lowBuffer[bar_index + 1] + // ) + && openBuffer[bar_index + 1] > closeBuffer[bar_index + 1] + && !(openBuffer[bar_index + 2] >= closeBuffer[bar_index + 2]) + ; + + // + bool isOpenCrossUnderClose = + true + // && + // ( + // pCandle.high > highBuffer[bar_index + 1] + // || pCandle.low < lowBuffer[bar_index + 1] + // ) + && openBuffer[bar_index + 1] < closeBuffer[bar_index + 1] + && !(openBuffer[bar_index + 2] <= closeBuffer[bar_index + 2]) + ; + + // + isTrendingUp = isOpenCrossUnderClose; + isTrendingDown = isOpenCrossOverClose; + + // + datetime time = iTime( + _Symbol, + _Period, + bar_index + ); + + // + if ( + isTrendingUp + || isTrendingDown + ) { + // + if (lastCrossTime == 0) { + lastCrossTime = time; + } else { + // + int lastCrossBarIndex = iBarShift( + _Symbol, + _Period, + lastCrossTime + ); + + // + int diff = lastCrossBarIndex - bar_index; + if (diff <= ignoreLastCross) { + return; + } else { + lastCrossTime = time; + } + } + } + + // + string lbl = StringConcatenate( + logTag, + "_Arrow_", + isTrendingUp ? "UP" : "Down", + "_", time + ); + + // + color clr = isTrendingUp ? + clrAqua : + clrFuchsia; + + // + ENUM_ARROW_ANCHOR anchor = isTrendingUp ? + ANCHOR_BOTTOM : + ANCHOR_TOP; + + // + uchar arrowCode = isTrendingUp ? + SYMBOL_ARROWUP : + SYMBOL_ARROWDOWN; + + // + double price = isTrendingUp ? + pCandle.low - 20 * _Point : + pCandle.high + 20 * _Point; + + // + if (isTrendingUp) { + // + // this means Market Going Up ... + + } + + // + if (isTrendingDown) { + // + // this means Market Going Downm ... + } + + // + if ( + isTrendingUp + || isTrendingDown + ) { + // + bool isDrawn = DrawArrow( + 0, + lbl, + 0, + time, + price, + arrowCode, + anchor, + clr + ); + } +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/21-00/Indicators/x-saherelm.xhh.mq4 b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.xhh.mq4 new file mode 100644 index 0000000..dfbc2cd --- /dev/null +++ b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.xhh.mq4 @@ -0,0 +1,410 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XHH Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 XHH Indicator" +#property strict + +// +// START Inputs ... +// +// +input int marketLength = 7; // Market Length + +// +input int shortCycleMultiplier = 4; // Market Short Cycle Multiplier +input int mediumCycleMultiplier = 14; // Market Medium Cycle Multiplier +input int longCycleMultiplier = 27; // Market Medium Cycle Multiplier +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 6 + +// +#property indicator_plots 6 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Short Cycle Highest High Buffer ... +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +// Short Cycle Lowest Low Buffer ... +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +// Medium Cycle Highest High Buffer ... +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrAqua +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 + +// +// Medium Cycle Lowest Low Buffer ... +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrFuchsia +#property indicator_style4 STYLE_DOT +#property indicator_width4 1 + +// +// Long Cycle Highest High Buffer ... +#property indicator_type5 DRAW_LINE +#property indicator_color5 C'62,82,6' +#property indicator_style5 STYLE_DOT +#property indicator_width5 1 + +// +// Long Cycle Lowest Low Buffer ... +#property indicator_type6 DRAW_LINE +#property indicator_color6 C'255,81,0' +#property indicator_style6 STYLE_DOT +#property indicator_width6 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define shortCycleHighestHighBufferIndex 0 +#define shortCycleLowestLowBufferIndex 1 +#define mediumCycleHighestHighBufferIndex 2 +#define mediumCycleLowestLowBufferIndex 3 +#define longCycleHighestHighBufferIndex 4 +#define longCycleLowestLowBufferIndex 5 + +double shortCycleHighestHighBuffer[]; +double shortCycleLowestLowBuffer[]; +double mediumCycleHighestHighBuffer[]; +double mediumCycleLowestLowBuffer[]; +double longCycleHighestHighBuffer[]; +double longCycleLowestLowBuffer[]; + +// +// Variables ... +int shortCycleLength; +int mediumCycleLength; +int longCycleLength; + +// +double highestHighTimes[]; +double lowestLowTimes[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if ( + marketLength <= 0 || + shortCycleMultiplier <= 0 || + mediumCycleMultiplier <= 0 || + shortCycleMultiplier > mediumCycleMultiplier + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + shortCycleLength = shortCycleMultiplier * marketLength; + mediumCycleLength = mediumCycleMultiplier * marketLength; + longCycleLength = longCycleMultiplier * marketLength; + + // + // Short Cycle Highest High ... + string scHHLbl = StringConcatenate( + "SC HH(", shortCycleLength, ")" + ); + SetIndexBuffer(shortCycleHighestHighBufferIndex, shortCycleHighestHighBuffer); + SetIndexLabel(shortCycleHighestHighBufferIndex, scHHLbl); + + // + // Short Cycle Lowest Low ... + string scLLLbl = StringConcatenate( + "SC LL(", shortCycleLength, ")" + ); + SetIndexBuffer(shortCycleLowestLowBufferIndex, shortCycleLowestLowBuffer); + SetIndexLabel(shortCycleLowestLowBufferIndex, scLLLbl); + + // + // Medium Cycle Highest High ... + string mcHHLbl = StringConcatenate( + "MC HH(", mediumCycleLength, ")" + ); + SetIndexBuffer(mediumCycleHighestHighBufferIndex, mediumCycleHighestHighBuffer); + SetIndexLabel(mediumCycleHighestHighBufferIndex, mcHHLbl); + + // + // Medium Cycle Lowest Low ... + string mcLLLbl = StringConcatenate( + "MC LL(", mediumCycleLength, ")" + ); + SetIndexBuffer(mediumCycleLowestLowBufferIndex, mediumCycleLowestLowBuffer); + SetIndexLabel(mediumCycleLowestLowBufferIndex, mcLLLbl); + + // + // Long Cycle Highest High ... + string lcHHLbl = StringConcatenate( + "LC HH(", longCycleLength, ")" + ); + SetIndexBuffer(longCycleHighestHighBufferIndex, longCycleHighestHighBuffer); + SetIndexLabel(longCycleHighestHighBufferIndex, lcHHLbl); + + // + // Long Cycle Lowest Low ... + string lcLLLbl = StringConcatenate( + "LC LL(", longCycleLength, ")" + ); + SetIndexBuffer(longCycleLowestLowBufferIndex, longCycleLowestLowBuffer); + SetIndexLabel(longCycleLowestLowBufferIndex, lcLLLbl); + // + // End Set Index Buffers ... + // + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + CalculateShortCycle(i); + + // + CalculateMediumCycle(i); + + // + CalculateLongCycle(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Short Cycle ... +void CalculateShortCycle( + const int &bar_index +) { + // + // Short Cycle Highest High ... + // + int scHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + shortCycleLength, + bar_index + ); + + // + double scHH = iHigh( + _Symbol, + _Period, + scHHIdx + ); + + // + shortCycleHighestHighBuffer[bar_index] = scHH; + + // + // Short Cycle Lowest Low ... + // + int scLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + shortCycleLength, + bar_index + ); + + // + double scLL = iLow( + _Symbol, + _Period, + scLLIdx + ); + + // + shortCycleLowestLowBuffer[bar_index] = scLL; +} + +// +// Calculating Medium Cycle ... +void CalculateMediumCycle( + const int &bar_index +) { + // + // Medium Cycle Highest High ... + // + int mcHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + mediumCycleLength, + bar_index + ); + + // + double mcHH = iHigh( + _Symbol, + _Period, + mcHHIdx + ); + + // + mediumCycleHighestHighBuffer[bar_index] = mcHH; + + // + // Medium Cycle Lowest Low ... + // + int mcLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + mediumCycleLength, + bar_index + ); + + // + double mcLL = iLow( + _Symbol, + _Period, + mcLLIdx + ); + + // + mediumCycleLowestLowBuffer[bar_index] = mcLL; +} + +// +// Calculating Long Cycle ... +void CalculateLongCycle( + const int &bar_index +) { + // + // Long Cycle Highest High ... + // + int lcHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + longCycleLength, + bar_index + ); + + // + double lcHH = iHigh( + _Symbol, + _Period, + lcHHIdx + ); + + // + longCycleHighestHighBuffer[bar_index] = lcHH; + + // + // Long Cycle Lowest Low ... + // + int lcLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + longCycleLength, + bar_index + ); + + // + double lcLL = iLow( + _Symbol, + _Period, + lcLLIdx + ); + + // + longCycleLowestLowBuffer[bar_index] = lcLL; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/21-00/Indicators/x-saherelm.xma.mq4 b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.xma.mq4 new file mode 100644 index 0000000..4a599f9 --- /dev/null +++ b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.xma.mq4 @@ -0,0 +1,695 @@ + /////////////////////////////////////////////////////// +// +// SaherElm IT Center XMA Indicator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XMA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Market Specifications ... +input int marketLength = 7; // Market Length +input double step = 0.02; // SAR Step +input double maximum = 0.2; // SAR Maximum +// +// Cycle Definitions ... +input int shortCycleFastMultiplier = 1; // Short Cycle Fast Multiplier +input int shortCycleSlowMultiplier = 4; // Short Cycle Slow Multiplier +input int mediumCycleFastMultiplier = 7; // Medium Cycle Fast Multiplier +input int mediumCycleSlowMultiplier = 14; // Medium Cycle Slow Multiplier +input int longCycleFastMultiplier = 70; // Long Cycle Fast Multiplier +input int longCycleSlowMultiplier = 140; // Long Cycle Slow Multiplier +// +// Show Inputs ... +input bool showPSar = true; // Show Parabolic Sar +input bool showMarketMiddle = true; // Show Market Middle +input bool showShortCycle = true; // Show Short Cycle +input bool showShortCycleCrossLines = true; // Show Short Cycle Vertical Lines +input bool showMediumCycle = true; // Show Medium Cycle +input bool showMediumCycleCrossLines = true; // Show Medium Cycle Vertical Lines +input bool showLongCycle = true; // Show Long Cycle +input bool showLongCycleCrossLines = true; // Show Long Cycle Vertical Lines +// +// Color Inputs ... +input color pSarColor = clrCornflowerBlue; // Parabolic Sar Color +input color shortCycleFastColor = clrGreen; // Short Cycle Fast Color +input color shortCycleSlowColor = clrRed; // Short Cycle Slow Color +input color mediumCycleFastColor = clrAqua; // Medium Cycle Fast Color +input color mediumCycleSlowColor = clrFuchsia; // Medium Cycle Slow Color +input color longCycleFastColor = clrGoldenrod; // Medium Cycle Fast Color +input color longCycleSlowColor = clrBrown; // Medium Cycle Slow Color +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// define indicator buffers ... +#property indicator_buffers 8 +#property indicator_plots 8 + +// +// Declare Buffers ... +#define scFastBufferIndex 0 +#define scSlowBufferIndex 1 +#define mcFastBufferIndex 2 +#define mcSlowBufferIndex 3 +#define lcFastBufferIndex 4 +#define lcSlowBufferIndex 5 +#define midBufferIndex 6 +#define pSarBufferIndex 7 + +// +double scFastBuffer[]; +double scSlowBuffer[]; +double mcFastBuffer[]; +double mcSlowBuffer[]; +double lcFastBuffer[]; +double lcSlowBuffer[]; +double midBuffer[]; +double pSarBuffer[]; + +// +int shortCycleFastLength; +int shortCycleSlowLength; +int mediumCycleFastLength; +int mediumCycleSlowLength; +int longCycleFastLength; +int longCycleSlowLength; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + // + // Validate Market Length ... + marketLength <= 0 + // + // Validate Short Cycle ... + || shortCycleFastMultiplier <= 0 + || shortCycleSlowMultiplier <= 0 + || shortCycleFastMultiplier >= shortCycleSlowMultiplier + // + // Validate Medium Cycle ... + || mediumCycleFastMultiplier <= 0 + || mediumCycleSlowMultiplier <= 0 + || mediumCycleFastMultiplier >= mediumCycleSlowMultiplier + // + // Validate Long Cycle ... + || longCycleFastMultiplier <= 0 + || longCycleSlowMultiplier <= 0 + || longCycleFastMultiplier >= longCycleSlowMultiplier + // + // Validate Series of Multipliers ... + || shortCycleFastMultiplier >= mediumCycleFastMultiplier + || mediumCycleFastMultiplier >= longCycleFastMultiplier + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST_XMA"; + + // + // Calculate Cycle Length based on given Multipliers ... + shortCycleFastLength = marketLength * shortCycleFastMultiplier; + shortCycleSlowLength = marketLength * shortCycleSlowMultiplier; + mediumCycleFastLength = marketLength * mediumCycleFastMultiplier; + mediumCycleSlowLength = marketLength * mediumCycleSlowMultiplier; + longCycleFastLength = marketLength * longCycleFastMultiplier; + longCycleSlowLength = marketLength * longCycleSlowMultiplier; + + // + // Short Cycle Fast ... + SetIndexLabel(scFastBufferIndex, "SCFast"); + SetIndexBuffer(scFastBufferIndex, scFastBuffer); + SetIndexDrawBegin(scFastBufferIndex, shortCycleFastLength); + SetIndexStyle( + scFastBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showShortCycle ? + shortCycleFastColor : + clrNONE + ); + + // + // Short Cycle Slow ... + SetIndexLabel(scSlowBufferIndex, "SCSLow"); + SetIndexBuffer(scSlowBufferIndex, scSlowBuffer); + SetIndexDrawBegin(scSlowBufferIndex, shortCycleSlowLength); + SetIndexStyle( + scSlowBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showShortCycle ? + shortCycleSlowColor : + clrNONE + ); + + // + // Medium Cycle Fast ... + SetIndexLabel(mcFastBufferIndex, "MCFast"); + SetIndexBuffer(mcFastBufferIndex, mcFastBuffer); + SetIndexDrawBegin(mcFastBufferIndex, mediumCycleFastLength); + SetIndexStyle( + mcFastBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showMediumCycle ? + mediumCycleFastColor : + clrNONE + ); + + // + // Medium Cycle Slow ... + SetIndexLabel(mcSlowBufferIndex, "MCSlow"); + SetIndexBuffer(mcSlowBufferIndex, mcSlowBuffer); + SetIndexDrawBegin(mcSlowBufferIndex, mediumCycleSlowLength); + SetIndexStyle( + mcSlowBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showMediumCycle ? + mediumCycleSlowColor : + clrNONE + ); + + // + // Long Cycle Fast ... + SetIndexLabel(lcFastBufferIndex, "LCFast"); + SetIndexBuffer(lcFastBufferIndex, lcFastBuffer); + SetIndexDrawBegin(lcFastBufferIndex, longCycleFastLength); + SetIndexStyle( + lcFastBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showLongCycle ? + longCycleFastColor : + clrNONE + ); + + // + // Long Cycle Slow ... + SetIndexLabel(lcSlowBufferIndex, "LCSlow"); + SetIndexBuffer(lcSlowBufferIndex, lcSlowBuffer); + SetIndexDrawBegin(lcSlowBufferIndex, longCycleSlowLength); + SetIndexStyle( + lcSlowBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showLongCycle ? + longCycleSlowColor : + clrNONE + ); + + // + // Market Middleage ... + SetIndexBuffer(midBufferIndex, midBuffer); + SetIndexDrawBegin(midBufferIndex, marketLength); + SetIndexLabel(midBufferIndex, "Market Mid"); + + // + // Parabolic Sar ... + SetIndexBuffer(pSarBufferIndex, pSarBuffer); + SetIndexLabel(pSarBufferIndex, "P Sar"); + SetIndexStyle( + pSarBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showPSar ? + pSarColor : + clrNONE + ); + + // + // Market Middle ... + SetIndexBuffer(midBufferIndex, midBuffer); + SetIndexLabel(midBufferIndex, "Mid"); + SetIndexStyle( + midBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showMarketMiddle ? + clrAntiqueWhite : + clrNONE + ); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + RemoveDraws(logTag); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(marketLength, longCycleSlowLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Short Cycle ... + CalculateShortCycle(i); + + // + // Calculate Medium Cycle ... + CalculateMediumCycle(i); + + // + // Calculate Long Cycle ... + CalculateLongCycle(i); + + // + // Calculate Market Middleage ... + CalculateMarketMiddleage(i); + + // + // Calculate Cross Points ... + CalculateCrossPoints(i); + + // + // Calculate Parabolic Sar ... + CalculateParabolicSar(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculate Short Cycle ... +void CalculateShortCycle( + const int bar_index +) { + // + // Fast ... + double shortCycleFast = iMA( + _Symbol, + _Period, + shortCycleFastLength, + 0, + MODE_SMA, + PRICE_WEIGHTED, + bar_index + ); + scFastBuffer[bar_index] = shortCycleFast; + + // + // Slow ... + double shortCycleSlow = iMA( + _Symbol, + _Period, + shortCycleSlowLength, + 0, + MODE_SMA, + PRICE_WEIGHTED, + bar_index + ); + scSlowBuffer[bar_index] = shortCycleSlow; +} + +// +// Calculate Medium Cycle ... +void CalculateMediumCycle( + const int bar_index +) { + // + // Fast ... + double mediumCycleFast = iMA( + _Symbol, + _Period, + mediumCycleFastLength, + 0, + MODE_SMA, + PRICE_MEDIAN, + bar_index + ); + mcFastBuffer[bar_index] = mediumCycleFast; + + // + // Slow ... + double mediumCycleSlow = iMA( + _Symbol, + _Period, + mediumCycleSlowLength, + 0, + MODE_SMA, + PRICE_MEDIAN, + bar_index + ); + mcSlowBuffer[bar_index] = mediumCycleSlow; +} + +// +// Calculate Long Cycle ... +void CalculateLongCycle( + const int bar_index +) { + // + // Fast ... + double longCycleFast = iMA( + _Symbol, + _Period, + longCycleFastLength, + 0, + MODE_SMA, + PRICE_CLOSE, + bar_index + ); + lcFastBuffer[bar_index] = longCycleFast; + + // + // Slow ... + double longCycleSlow = iMA( + _Symbol, + _Period, + longCycleSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE, + bar_index + ); + lcSlowBuffer[bar_index] = longCycleSlow; +} + +// +// Calculate Market Middleage ... +void CalculateMarketMiddleage( + const int bar_index +) { + // + // Mid ... + double marketMiddleage = iMA( + _Symbol, + _Period, + (int)(marketLength * 1.5), + 0, + MODE_EMA, + PRICE_MEDIAN, + bar_index + ); + midBuffer[bar_index] = marketMiddleage; +} + +// +// Calculate Cross Points and Draw Section Line on theme ... +void CalculateCrossPoints( + const int bar_index +) { + // + // START Draw Cross Lines ... + // + // + // Short Cycle ... + bool isSCFastCrossOverSlow = scFastBuffer[bar_index] > scSlowBuffer[bar_index] + && !(scFastBuffer[bar_index + 1] > scSlowBuffer[bar_index + 1]); + + // + bool isSCFastCrossUnderSlow = scFastBuffer[bar_index] < scSlowBuffer[bar_index] + && !(scFastBuffer[bar_index + 1] < scSlowBuffer[bar_index + 1]); + + // + // Medium Cycle ... + bool isMCFastCrossOverSlow = mcFastBuffer[bar_index] > mcSlowBuffer[bar_index] + && !(mcFastBuffer[bar_index + 1] > mcSlowBuffer[bar_index + 1]); + + // + bool isMCFastCrossUnderSlow = mcFastBuffer[bar_index] < mcSlowBuffer[bar_index] + && !(mcFastBuffer[bar_index + 1] < mcSlowBuffer[bar_index + 1]); + + // + // Long Cycle ... + bool isLCFastCrossOverSlow = lcFastBuffer[bar_index] > lcSlowBuffer[bar_index] + && !(lcFastBuffer[bar_index + 1] > lcSlowBuffer[bar_index + 1]); + + // + bool isLCFastCrossUnderSlow = lcFastBuffer[bar_index] < lcSlowBuffer[bar_index] + && !(lcFastBuffer[bar_index + 1] < lcSlowBuffer[bar_index + 1]); + + // + // START Drawing CrossPoints ... + // + // + datetime currentTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + if (showShortCycleCrossLines) { + // + // Draw Line ... + if (isSCFastCrossOverSlow) { + // + string lbl = StringConcatenate( + logTag, + "_SC_F_OV_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showShortCycleCrossLines ? + shortCycleFastColor : + clrNONE + ); + } + + // + // Draw Line ... + if (isSCFastCrossUnderSlow) { + // + string lbl = StringConcatenate( + logTag, + "_SC_F_UN_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showShortCycleCrossLines ? + shortCycleSlowColor : + clrNONE + ); + } + } + + // + if (showMediumCycleCrossLines) { + // + // Draw Line ... + if (isMCFastCrossOverSlow) { + // + string lbl = StringConcatenate( + logTag, + "_MC_F_OV_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showMediumCycleCrossLines ? + mediumCycleFastColor : + clrNONE + ); + } + + // + // Draw Line ... + if (isMCFastCrossUnderSlow) { + // + string lbl = StringConcatenate( + logTag, + "_MC_F_UN_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showMediumCycleCrossLines ? + mediumCycleSlowColor : + clrNONE + ); + } + } + + // + if (showLongCycleCrossLines) { + // + // Draw Line ... + if (isLCFastCrossOverSlow) { + // + string lbl = StringConcatenate( + logTag, + "_LC_F_OV_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showLongCycleCrossLines ? + longCycleFastColor : + clrNONE + ); + } + + // + // Draw Line ... + if (isLCFastCrossUnderSlow) { + // + string lbl = StringConcatenate( + logTag, + "_LC_F_UN_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showLongCycleCrossLines ? + longCycleSlowColor : + clrNONE + ); + } + } + // + // END Drawing CrossPoints ... + // +} + +void CalculateParabolicSar( + const int bar_index +) { + // + double sarValue = iSAR( + NULL, + _Period, + step, + maximum, + bar_index + ); + + // + pSarBuffer[bar_index] = sarValue; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/21-00/Indicators/x-saherelm.xmarket.mq4 b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.xmarket.mq4 new file mode 100644 index 0000000..71b2e2c --- /dev/null +++ b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.xmarket.mq4 @@ -0,0 +1,394 @@ + /////////////////////////////////////////////////////// +// +// SaherElm IT Center XMKT Indicator +// --------------------------------------------- +// retrieve market base info ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XMKT Indicator" +#property strict + +// +// START Inputs ... +// +// +// Market Specifications ... +input int marketLength = 7; // Market Length +// +input bool showHighestHigh = true; // Show Market Highest High +input bool showHighestLow = true; // Show Market Highest Low +input bool showHighestOpen = true; // Show Market Highest Open +input bool showHighestClose = true; // Show Market Highest Close +input bool showLowestHigh = true; // Show Market Lowest High +input bool showLowestLow = true; // Show Market Lowest Low +input bool showLowestOpen = true; // Show Market Lowest Open +input bool showLowestClose = true; // Show Market Lowest Close +// +input color highestHighColor = clrDeepPink; // Market Highest High Color +input color highestLowColor = clrDarkOrange; // Market Highest Low Color +input color highestOpenColor = clrDodgerBlue; // Market Highest Open Color +input color highestCloseColor = clrOrchid; // Market Highest Close Color +input color lowestHighColor = clrHotPink; // Market Lowest High Color +input color lowestLowColor = clrOrange; // Market Lowest Low Color +input color lowestOpenColor = clrPowderBlue; // Market Lowest Open Color +input color lowestCloseColor = clrMediumOrchid; // Market Lowest Close Color +// +input ENUM_LINE_STYLE highestHighStyle = STYLE_DOT; // Market Highest High Line Style +input ENUM_LINE_STYLE highestLowStyle = STYLE_DOT; // Market Highest Low Line Style +input ENUM_LINE_STYLE highestOpenStyle = STYLE_DOT; // Market Highest Open Line Style +input ENUM_LINE_STYLE highestCloseStyle = STYLE_DOT; // Market Highest Close Line Style +input ENUM_LINE_STYLE lowestHighStyle = STYLE_DOT; // Market Lowest High Line Style +input ENUM_LINE_STYLE lowestLowStyle = STYLE_DOT; // Market Lowest Low Line Style +input ENUM_LINE_STYLE lowestOpenStyle = STYLE_DOT; // Market Lowest Open Line Style +input ENUM_LINE_STYLE lowestCloseStyle = STYLE_DOT; // Market Lowest Close Line Style +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// define indicator buffers ... +#property indicator_buffers 8 +#property indicator_plots 8 + +// +// Declare Buffers ... +#define marketHighestHighBufferIndex 0 +#define marketHighestLowBufferIndex 1 +#define marketHighestOpenBufferIndex 2 +#define marketHighestCloseBufferIndex 3 +#define marketLowestHighBufferIndex 4 +#define marketLowestLowBufferIndex 5 +#define marketLowestOpenBufferIndex 6 +#define marketLowestCloseBufferIndex 7 + +// +double marketHighestHighBuffer[]; +double marketHighestLowBuffer[]; +double marketHighestOpenBuffer[]; +double marketHighestCloseBuffer[]; +double marketLowestHighBuffer[]; +double marketLowestLowBuffer[]; +double marketLowestOpenBuffer[]; +double marketLowestCloseBuffer[]; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (marketLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST_XMKT"; + + // + // Highest High ... + string highestHighLbl = StringConcatenate("HH(", marketLength,")"); + SetIndexLabel(marketHighestHighBufferIndex, highestHighLbl); + SetIndexBuffer(marketHighestHighBufferIndex, marketHighestHighBuffer); + SetIndexStyle( + marketHighestHighBufferIndex, + showHighestHigh ? + DRAW_LINE : + DRAW_NONE, + highestHighStyle, + 1, + showHighestHigh ? + highestHighColor : + clrNONE + ); + + // + // Highest Low ... + string highestLowLbl = StringConcatenate("HL(", marketLength,")"); + SetIndexLabel(marketHighestLowBufferIndex, highestLowLbl); + SetIndexBuffer(marketHighestLowBufferIndex, marketHighestLowBuffer); + SetIndexStyle( + marketHighestLowBufferIndex, + showHighestLow ? + DRAW_LINE : + DRAW_NONE, + highestLowStyle, + 1, + showHighestLow ? + highestLowColor : + clrNONE + ); + + // + // Highest Open ... + string highestOpenLbl = StringConcatenate("HO(", marketLength,")"); + SetIndexLabel(marketHighestOpenBufferIndex, highestOpenLbl); + SetIndexBuffer(marketHighestOpenBufferIndex, marketHighestOpenBuffer); + SetIndexStyle( + marketHighestOpenBufferIndex, + showHighestOpen ? + DRAW_LINE : + DRAW_NONE, + highestOpenStyle, + 1, + showHighestOpen ? + highestOpenColor : + clrNONE + ); + + // + // Highest Close ... + string highestCloseLbl = StringConcatenate("HC(", marketLength,")"); + SetIndexLabel(marketHighestCloseBufferIndex, highestCloseLbl); + SetIndexBuffer(marketHighestCloseBufferIndex, marketHighestCloseBuffer); + SetIndexStyle( + marketHighestCloseBufferIndex, + showHighestClose ? + DRAW_LINE : + DRAW_NONE, + highestCloseStyle, + 1, + showHighestClose ? + highestCloseColor : + clrNONE + ); + + // + // Lowest High ... + string lowestHighLbl = StringConcatenate("LH(", marketLength,")"); + SetIndexLabel(marketLowestHighBufferIndex, lowestHighLbl); + SetIndexBuffer(marketLowestHighBufferIndex, marketLowestHighBuffer); + SetIndexStyle( + marketLowestHighBufferIndex, + showLowestHigh ? + DRAW_LINE : + DRAW_NONE, + lowestHighStyle, + 1, + showLowestHigh ? + lowestHighColor : + clrNONE + ); + + // + // Lowest Low ... + string lowestLowLbl = StringConcatenate("LL(", marketLength,")"); + SetIndexLabel(marketLowestLowBufferIndex, lowestLowLbl); + SetIndexBuffer(marketLowestLowBufferIndex, marketLowestLowBuffer); + SetIndexStyle( + marketLowestLowBufferIndex, + showLowestLow ? + DRAW_LINE : + DRAW_NONE, + lowestLowStyle, + 1, + showLowestLow ? + lowestLowColor : + clrNONE + ); + + // + // Lowest Open ... + string lowestOpenLbl = StringConcatenate("LO(", marketLength,")"); + SetIndexLabel(marketLowestOpenBufferIndex, lowestOpenLbl); + SetIndexBuffer(marketLowestOpenBufferIndex, marketLowestOpenBuffer); + SetIndexStyle( + marketLowestOpenBufferIndex, + showLowestOpen ? + DRAW_LINE : + DRAW_NONE, + lowestOpenStyle, + 1, + showLowestOpen ? + lowestOpenColor : + clrNONE + ); + + // + // Lowest Close ... + string lowestCloseLbl = StringConcatenate("LC(", marketLength,")"); + SetIndexLabel(marketLowestCloseBufferIndex, lowestCloseLbl); + SetIndexBuffer(marketLowestCloseBufferIndex, marketLowestCloseBuffer); + SetIndexStyle( + marketLowestCloseBufferIndex, + showLowestClose ? + DRAW_LINE : + DRAW_NONE, + lowestCloseStyle, + 1, + showLowestClose ? + lowestCloseColor : + clrNONE + ); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + RemoveDraws(logTag); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(marketLength, 3); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Short Cycle ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculate Short Cycle ... +void CalculateBuffers( + const int bar_index +) { + // + // Highest High ... + double highestHighValue = GetMarketHighestHigh( + bar_index, + marketLength + ); + marketHighestHighBuffer[bar_index] = highestHighValue; + + // + // Highest Low ... + double highestLowValue = GetMarketHighestLow( + bar_index, + marketLength + ); + marketHighestLowBuffer[bar_index] = highestLowValue; + + // + // Highest Open ... + double highestOpenValue = GetMarketHighestOpen( + bar_index, + marketLength + ); + marketHighestOpenBuffer[bar_index] = highestOpenValue; + + // + // Highest Close ... + double highestCloseValue = GetMarketHighestClose( + bar_index, + marketLength + ); + marketHighestCloseBuffer[bar_index] = highestCloseValue; + + // + // Lowest High ... + double lowestHighValue = GetMarketLowestHigh( + bar_index, + marketLength + ); + marketLowestHighBuffer[bar_index] = lowestHighValue; + + // + // Lowest Low ... + double lowestLowValue = GetMarketLowestLow( + bar_index, + marketLength + ); + marketLowestLowBuffer[bar_index] = lowestLowValue; + + // + // Lowest Open ... + double lowestOpenValue = GetMarketLowestOpen( + bar_index, + marketLength + ); + marketLowestOpenBuffer[bar_index] = lowestOpenValue; + + // + // Lowest Close ... + double lowestCloseValue = GetMarketLowestClose( + bar_index, + marketLength + ); + marketLowestCloseBuffer[bar_index] = lowestCloseValue; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/21-00/Indicators/x-saherelm.xmtrend.mq4 b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.xmtrend.mq4 new file mode 100644 index 0000000..aa89e7b --- /dev/null +++ b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.xmtrend.mq4 @@ -0,0 +1,221 @@ + /////////////////////////////////////////////////////// +// +// SaherElm IT Center XMTR Indicator +// --------------------------------------------- +// retrieve market base info ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XMKT Indicator" +#property strict + +// +// START Inputs ... +// +// +// Market Specifications ... +input int marketLength = 20; // Market Length +input int atrMultiplier = 1; // ATR Multiplier +input int atrLength = 5; // ATR Period +input ENUM_APPLIED_PRICE source = PRICE_CLOSE; // Source +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// define indicator buffers ... +#property indicator_buffers 3 +#property indicator_plots 3 + +// +// Declare Buffers ... +#define trendBufferIndex 0 +#define upTrendBufferIndex 1 +#define downTrendBufferIndex 2 + +// +double trendBuffer[]; +double upTrendBuffer[]; +double downTrendBuffer[]; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (marketLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XMTR"; + + // + // TREND ... + SetIndexLabel(trendBufferIndex, "Trend"); + SetIndexBuffer(trendBufferIndex, trendBuffer); + SetIndexStyle( + trendBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + clrNONE + ); + + // + // UP Trend ... + SetIndexLabel(upTrendBufferIndex, "Up Trend"); + SetIndexBuffer(upTrendBufferIndex, upTrendBuffer); + SetIndexStyle( + upTrendBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + clrNONE + ); + + // + // DOWN Trend ... + SetIndexLabel(downTrendBufferIndex, "Down Trend"); + SetIndexBuffer(downTrendBufferIndex, downTrendBuffer); + SetIndexStyle( + downTrendBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + clrNONE + ); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + RemoveDraws(logTag); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(marketLength, 3); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Short Cycle ... + CalculateBuffers( + i, + low + ); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculate Short Cycle ... +void CalculateBuffers( + const int bar_index, + const double &low[] +) { + // + double atr = GetMarketTRSMA( + bar_index, + atrLength + ); + + // + double smoothedAtr = (atr * atrMultiplier); + double upTrend = low[bar_index] - smoothedAtr; + double downTrend = low[bar_index] + smoothedAtr; + + // + double cciValue = GetMarketCCI( + bar_index, + marketLength, + source + ); + + // + // TODO: Complete this ... +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/21-00/Indicators/x-saherelm.zigzag.mq4 b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.zigzag.mq4 new file mode 100644 index 0000000..fbb073c --- /dev/null +++ b/Bkp/Used/14020425/21-00/Indicators/x-saherelm.zigzag.mq4 @@ -0,0 +1,476 @@ +///////////////////////////////////////////////////////////////// +// +// SaherElm IT Center ZigZag Indicator +// ------------------------------------------------------------- +// this indicator provides signals for Main strategy ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +//////////////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm ZigZag Indicator" +#property strict + +// +// START Inputs ... +// +input int depth = 12; // Depth +input int deviation = 5; // Deviation +input int backStep = 3; // BackStep +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// here we specify logging enabled or not ... +bool enableLogging = true; + +// +// this is a Tag which attached to our Logger ... +string logTag = "XS_ZG"; + +// +#property indicator_chart_window + +// +#property indicator_buffers 1 + +// +#property indicator_width1 1 +#property indicator_color1 clrAqua +// #property indicator_type1 DRAW_SECTION +// #property indicator_style1 STYLE_SOLID + +// // +// #property indicator_width2 1 +// #property indicator_color2 clrNONE +// #property indicator_type2 DRAW_NONE +// #property indicator_style2 STYLE_SOLID + +// // +// #property indicator_width3 1 +// #property indicator_color3 clrNONE +// #property indicator_type3 DRAW_NONE +// #property indicator_style3 STYLE_SOLID + +// +// Buffers ... +// +#define zigzagBufferIndex 0 +#define highBufferIndex 1 +#define lowBufferIndex 2 +// #define ziggyBufferIndex 3 + +// +double zigzagBuffer[]; +double highBuffer[]; +double lowBuffer[]; +// double ziggyBuffer[]; + +// +// recounting's depth of extremums ... +int level=3; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + depth <= 0 || + backStep < 0 || + deviation < 0 || + backStep >= depth + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Set Index Buffers of ZigZag ... + IndicatorBuffers(3); + + // + // ZigZag Buffer ... + SetIndexBuffer(zigzagBufferIndex, zigzagBuffer); + SetIndexStyle(zigzagBufferIndex, DRAW_SECTION); + SetIndexLabel(zigzagBufferIndex, "ZigZag"); + + // + // High Buffer ... + SetIndexBuffer(highBufferIndex, highBuffer); + SetIndexLabel(highBufferIndex, ""); + + // + // Low Buffer ... + SetIndexBuffer(lowBufferIndex, lowBuffer); + SetIndexLabel(lowBufferIndex, ""); + + // + // Ziggy Buffer ... + // SetIndexBuffer(ziggyBufferIndex, ziggyBuffer); + // SetIndexLabel(ziggyBufferIndex, ""); + + // + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + int maxLength = MathMax(depth, backStep); + + int i; + int counterZ; + int back; + int pos; + + // + int lastlowpos = 0; + int lasthighpos = 0; + int whatlookfor = 0; + + // + double extremum; + + // + double curlow = 0.0; + double curhigh = 0.0; + double lasthigh = 0.0; + double lastlow = 0.0; + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // first calculations ... + if (prev_calculated == 0) { + limit = InitializeBuffers(); + } else { + // + // find first extremum in the depth ExtLevel or 100 last bars ... + i = counterZ = 0; + while(counterZ < level && i < 100) { + // + if(zigzagBuffer[i] != 0.0) { + counterZ++; + } + + // + i++; + } + + // + // no extremum found - recounting all from begin ... + if(counterZ == 0) { + limit = InitializeBuffers(); + } else { + // + // set start position to found extremum position ... + limit = i-1; + + // + //--- what kind of extremum? + if(lowBuffer[i] != 0.0) { + // + // low extremum ... + curlow = lowBuffer[i]; + + // + // will look for the next high extremum ... + whatlookfor=1; + } else { + // + // high extremum ... + curhigh = highBuffer[i]; + + // + // will look for the next low extremum ... + whatlookfor=-1; + } + + // + // clear the rest data ... + for(i = limit - 1; i >= 0; i--) { + // + lowBuffer[i]=0.0; + highBuffer[i]=0.0; + zigzagBuffer[i]=0.0; + } + } + } + + // + // Main Calculation Loop ... + for (i = limit; i >= 0; i--) { + // + // find lowest low in depth of bars ... + extremum = low[ + iLowest( + _Symbol, + _Period, + MODE_LOW, + depth, + i + ) + ]; + + // + // this lowest has been found previously ... + if (extremum == lastlow) { + extremum = 0.0; + } else { + // + // new last low ... + lastlow=extremum; + + // + // discard extremum if current low is too high ... + if(low[i] - extremum > deviation * _Point) { + extremum=0.0; + } else { + // + // clear previous extremums in backstep bars ... + for(back = 1; back <= backStep; back++) { + // + pos = i + back; + + // + if(lowBuffer[pos] != 0 && lowBuffer[pos] > extremum) { + lowBuffer[pos] = 0.0; + } + } + } + } + + // + // found extremum is current low ... + if (low[i] == extremum) { + lowBuffer[i] = extremum; + } else { + lowBuffer[i] = 0.0; + } + + // + // find highest high in depth of bars ... + extremum = high[ + iHighest( + _Symbol, + _Period, + MODE_HIGH, + depth, + i + ) + ]; + + // + // this highest has been found previously ... + if (extremum == lasthigh) { + extremum = 0.0; + } else { + // + // new last high ... + lasthigh=extremum; + + // + // discard extremum if current high is too low ... + if (extremum - high[i] > deviation * Point) { + extremum = 0.0; + } else { + // + // clear previous extremums in backstep bars ... + for(back = 1; back <= backStep; back++) { + // + pos = i + back; + + // + if (highBuffer[pos] != 0 && highBuffer[pos] < extremum) { + highBuffer[pos] = 0.0; + } + } + } + } + + // + // found extremum is current high ... + if (high[i] == extremum) { + highBuffer[i] = extremum; + } else { + highBuffer[i] = 0.0; + } + } + + // + // final cutting ... + if( whatlookfor == 0) { + // + lastlow = 0.0; + lasthigh = 0.0; + } else { + // + lastlow = curlow; + lasthigh = curhigh; + } + + // + for(i = limit; i >= 0; i--) { + switch(whatlookfor) { + // + // look for peak or lawn ... + case 0: + // + if (lastlow == 0.0 && lasthigh == 0.0) { + if(highBuffer[i]!=0.0) { + // + lasthigh = High[i]; + lasthighpos = i; + whatlookfor = -1; + + // + zigzagBuffer[i] = lasthigh; + } + + // + if(lowBuffer[i] != 0.0) { + // + lastlow = Low[i]; + lastlowpos = i; + whatlookfor = 1; + + // + zigzagBuffer[i] = lastlow; + } + } + break; + + // + // look for peak ... + case 1: + // + if ( + lowBuffer[i] != 0.0 && + lowBuffer[i] < lastlow && + highBuffer[i] == 0.0 + ) { + // + zigzagBuffer[lastlowpos] = 0.0; + lastlowpos = i; + lastlow = lowBuffer[i]; + zigzagBuffer[i] = lastlow; + } + + // + if(highBuffer[i] != 0.0 && lowBuffer[i] == 0.0) { + // + lasthigh = highBuffer[i]; + lasthighpos = i; + zigzagBuffer[i] = lasthigh; + + // + whatlookfor=-1; + } + break; + + // + // look for lawn ... + case -1: + // + if( + highBuffer[i] != 0.0 && + highBuffer[i] > lasthigh && + lowBuffer[i] == 0.0 + ) { + // + zigzagBuffer[lasthighpos] = 0.0; + lasthighpos = i; + lasthigh = highBuffer[i]; + zigzagBuffer[i] = lasthigh; + } + + // + if( + lowBuffer[i] !=0.0 && + highBuffer[i] == 0.0 + ) { + // + lastlow = lowBuffer[i]; + lastlowpos = i; + zigzagBuffer[i] = lastlow; + whatlookfor=1; + } + break; + } + } + + // + // Done ... + return rates_total; +} + +// +// De Initialization ... +void OnDeinit(const int reason) { + // + // RemoveDraws(signalPrefix); + ChartRedraw(0); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +int InitializeBuffers() { + // + ArrayInitialize(lowBuffer,0.0); + ArrayInitialize(highBuffer, 0.0); + ArrayInitialize(zigzagBuffer, 0.0); + + // + //--- first counting position + return(Bars - depth); +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/21-00/Libraries/x-saherelm.cci.signal.lib.mq4 b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.cci.signal.lib.mq4 new file mode 100644 index 0000000..c572f3d --- /dev/null +++ b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.cci.signal.lib.mq4 @@ -0,0 +1,472 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 CCI Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// Based Signal Conditions ... +struct XCCILongSignalConditions { + // + datetime start; + + // + datetime crossOverMinusHundredTime; + datetime crossUnderMinusHundredTime; + + // + double crossOverSlope; +}; + +// +static XCCILongSignalConditions cciLongConds; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Signal Conditions ... +void CheckCCILongSignalConditions( + const int bar_index, + const int marketLen, + // + const double smoother = 10 +) { + // + // Retrieve Bar Time ... + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // LONG: + // wait for cci cross under -100 + // then wait for cross over -100 + // slope of crossing over ??? ... + if (cciLongConds.start == 0) { + // LogMessage("Start"); + cciLongConds.start = barTime; + return; + } + + // + // Check Start Time ... + if (cciLongConds.start == 0) { + return; + } + + // + // Read current, prev, and prevPrev CCI ... + double cci = GetMarketCCI( + bar_index, + marketLen + ); + double cci1 = GetMarketCCI( + bar_index + 1, + marketLen + ); + double cci2 = GetMarketCCI( + bar_index + 2, + marketLen + ); + + // + // Find Cross Under -100 ... + bool isCrossUnderMinusHundred = + cci < -105 && !(cci1 < -105) + && MathAbs(MathAbs(cci) - MathAbs(cci1)) > smoother + ; + + // + // Find Cross Over -100 ... + bool isCrossOverMinusHundred = + cci > -105 && !(cci1 > -105) + && MathAbs(cci - cci1) > smoother + ; + + // + // Fill Conditions ... + if ( + isCrossUnderMinusHundred + && cciLongConds.crossUnderMinusHundredTime == 0 + && cciLongConds.crossOverMinusHundredTime == 0 + ) { + // LogMessage("Cross Under ..."); + cciLongConds.crossUnderMinusHundredTime = barTime; + return; + } + + // + // Fill Conditions ... + if ( + isCrossOverMinusHundred + && cciLongConds.crossOverMinusHundredTime == 0 + && cciLongConds.crossUnderMinusHundredTime != 0 + ) { + // + // LogMessage("Cross Over ..."); + cciLongConds.crossOverMinusHundredTime = barTime; + } + + // + // Prevent Going forward untill Cross Under Happens ... + if (cciLongConds.crossUnderMinusHundredTime == 0) { + return; + } + + // + // Prevent from Going forward untill Cross Over Happens ... + if (cciLongConds.crossOverMinusHundredTime == 0) { + return; + } + + // + // Calculate Slope ... + double x1 = 0; + double y1 = cci1; + double x2 = 1; + double y2 = cci; + + // + // Calculat Line Slope ... + double tSlope = GetSlope( + x1, y1, x2, y2 + ); + + // + cciLongConds.crossOverSlope = tSlope; + // LogMessage("Slope: " + tSlope); +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateCCILongSignal( + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r // Risk to Reward ratio ... +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if (!ValidateCCILongConditions()) { + return result; + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double entryPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double exitPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + int llIdx = GetLowestLowOFCCILongPeriodIndex(); + double ll = + GetMarketLowestLow( + bar_index, + marketLen + ); + // GetLowestLowOFCCILongPeriod(); + + // + int hhIdx = GetHighestHighOfCCILongPeriodIndex(); + double hh = GetHighestHighOfCCILongPeriod(); + // GetMarketHighestHigh( + // bar_index, + // marketLen + // ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = MathMin(openPrice, closePrice) - ll; + double reward = risk * r2r; + + // + double sl = 0; // ll; + double tp = entryPrice + reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = X_SIGNAL_LONG; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_CCI_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = X_SIGNAL_LONG; + result.provider = X_CCI_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateCCILongConditions() { + // + int crossUnderBarIndex = + cciLongConds.crossUnderMinusHundredTime != 0 + ? iBarShift( + _Symbol, + _Period, + cciLongConds.crossUnderMinusHundredTime + ) + : -1 + ; + + // + int crossOverBarIndex = + cciLongConds.crossOverMinusHundredTime != 0 + ? iBarShift( + _Symbol, + _Period, + cciLongConds.crossOverMinusHundredTime + ) + : -1 + ; + + // + bool isConditionsFilled = + // + cciLongConds.start != 0 + && cciLongConds.crossUnderMinusHundredTime != 0 + && cciLongConds.crossOverMinusHundredTime != 0 + && cciLongConds.crossUnderMinusHundredTime >= cciLongConds.start + && cciLongConds.crossOverMinusHundredTime > cciLongConds.crossUnderMinusHundredTime + ; + + // + bool isLogicPassed = + // + crossOverBarIndex > 0 + && crossUnderBarIndex > 0 + && crossUnderBarIndex > crossOverBarIndex + && (crossUnderBarIndex - crossOverBarIndex) >= 5 + ; + + // + bool result = + // + isConditionsFilled + && isLogicPassed + && cciLongConds.crossOverSlope > 0 + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearCCILongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearCCILongSignalConditions() { + // + cciLongConds.start = 0; + cciLongConds.crossOverSlope = 0; + cciLongConds.crossOverMinusHundredTime = 0; + cciLongConds.crossUnderMinusHundredTime = 0; +} + +// +int GetHighestHighOfCCILongPeriodIndex() { + // + int crossUnderBarIndex = iBarShift( + _Symbol, + _Period, + cciLongConds.crossUnderMinusHundredTime + ); + + // + int crossOverBarIndex = iBarShift( + _Symbol, + _Period, + cciLongConds.crossOverMinusHundredTime + ); + + // + int result = iHighest( + _Symbol, + _Period, + MODE_HIGH, + crossUnderBarIndex - crossOverBarIndex, + crossOverBarIndex + ); + + // + return result; +} + +// +double GetHighestHighOfCCILongPeriod() { + // + int index = GetHighestHighOfCCILongPeriodIndex(); + + // + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + return result; +} + +// +int GetLowestLowOFCCILongPeriodIndex() { + // + int crossUnderBarIndex = iBarShift( + _Symbol, + _Period, + cciLongConds.crossUnderMinusHundredTime + ); + + // + int crossOverBarIndex = iBarShift( + _Symbol, + _Period, + cciLongConds.crossOverMinusHundredTime + ); + + // + int result = iLowest( + _Symbol, + _Period, + MODE_LOW, + crossUnderBarIndex - crossOverBarIndex, + crossOverBarIndex + ); + + // + return result; +} + +// +double GetLowestLowOFCCILongPeriod() { + // + int index = GetLowestLowOFCCILongPeriodIndex(); + + // + double result = iLow( + _Symbol, + _Period, + index + ); + + // + return result; +} + +// +// Check XMA State for Long Signals ... +bool IsReadyForCCILongSignals( + const XState &states[] +) { + // + bool result = false; + + // + XStateInfo info = ParseXMAStates(states); + + // + result = + // + true + // + // && states[1].mc.fast > states[1].mc.slow + // && MathAbs(states[1].mc.fast - states[1].mc.slow) > 100 * _Point + // && states[1].marketMiddleage > states[1].sc.fast + // && states[1].marketMiddleage > states[1].mc.fast + ; + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020425/21-00/Libraries/x-saherelm.draw.lib.mq4 b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.draw.lib.mq4 new file mode 100644 index 0000000..08fefa7 --- /dev/null +++ b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.draw.lib.mq4 @@ -0,0 +1,1670 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Start Arrow Functions ... +// +// +// Draw an Arrow Object on Chart ... +bool DrawArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // arrow name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const uchar arrowCode = OBJ_ARROW_UP, // arrow code + const ENUM_ARROW_ANCHOR anchor = ANCHOR_BOTTOM, // anchor point position + const color clr = clrAqua, // arrow color + const ENUM_LINE_STYLE style = STYLE_SOLID, // border line style + const int width = 3, // arrow size + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // Order Object ... +) { + // + // set anchor point coordinates if they are not set ... + ChangeArrowEmptyPoint(time, price); + + // + // reset the error value ... + ResetLastError(); + + // + // create an arrow ... + if(!ObjectCreate(chartID, name, OBJ_ARROW, subWindow, time, price)) { + // + string message = StringConcatenate(__FUNCTION__, + ": failed to create an arrow! Error code = ", + GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the arrow code ... + ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, arrowCode); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set the arrow color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set the border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set the arrow's size ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the arrow by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is false by default, if you want making it possible to highlight and move the object + // change it to true ... + ObjectSetInteger(chartID,name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point of Arrow ... +bool MoveArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if(!time) { + time = TimeCurrent(); + } + + // + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete an arrow ... +bool DeleteArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow" // arrow name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete an arrow ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete an arrow! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the arrow code ... +bool ArrowCodeChange( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + const uchar code = 252 // arrow code +) { + // + // reset the error value ... + ResetLastError(); + + // + // change the arrow code ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, code)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the arrow code! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change anchor type ... +bool ArrowAnchorChange( + const long chartID = 0, // chart's ID + const string name="Arrow", // object name + const ENUM_ARROW_ANCHOR anchor = ANCHOR_TOP // anchor type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change anchor type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change anchor type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeArrowEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } +} +// +// End Arrow Functions ... +// + +// +// Start Horizontal Line Functions ... +// +// +// Create, Draw the horizontal line ... +bool DrawHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + const int subWindow = 0, // subwindow index + double price = 0, // line price + const color clr = clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the price is not set, set it at the current Bid price level ... + if(!price) { + price=SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // create a horizontal line ... + if(!ObjectCreate(chartID, name, OBJ_HLINE, subWindow, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move horizontal line ... +bool MoveHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + double price = 0 // line price +) { + // + // if the line price is not set, move it to the current Bid price level ... + if(!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move a horizontal line ... + if(!ObjectMove(chartID, name, 0, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete a horizontal line ... +bool DeleteHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a horizontal line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End Horizontal Line Functions ... +// + +// +// Start Vertical Line Functions ... +// +// +// Create the vertical line ... +bool DrawVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + const int sub_window = 0, // subwindow index + datetime time = 0, // line time + const color clr=clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the line time is not set, draw it via the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value + ResetLastError(); + + // + // create a vertical line ... + if (!ObjectCreate(chartID, name, OBJ_VLINE, sub_window, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return true; +} + +// +// Move the vertical line ... +bool MoveVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + datetime time = 0 // line time +) { + // + // if line time is not set, move the line to the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the vertical line ... + if(!ObjectMove(chartID, name, 0, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the vertical line ... +bool DeleteVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the vertical line ... + if (!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // successful execution ... + return true; +} +// +// End Vertical Line Functions ... +// + +// +// Start RectangleLabel Functions ... +// +// +// Create Rectangle Label Object ... +bool DrawRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int subWindow = 0, // subwindow index + const int x = 0, // X coordinate + const int y = 0, // Y coordinate + const int width = 50, // width + const int height = 18, // height + const color back_clr = C'236,233,216', // background color + const ENUM_BORDER_TYPE border = BORDER_SUNKEN, // border type + const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring + const color clr = clrRed, // flat border color (Flat) + const ENUM_LINE_STYLE style = STYLE_SOLID, // flat border style + const int lineWidth = 1, // flat border width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // reset the error value ... + ResetLastError(); + + // + //--- create a rectangle label + if(!ObjectCreate(chartID, name, OBJ_RECTANGLE_LABEL, subWindow, 0, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set label coordinates ... + ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x); + ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y); + + // + // set label size ... + ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width); + ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height); + + // + // set background color ... + ObjectSetInteger(chartID, name, OBJPROP_BGCOLOR, back_clr); + + // + // set border type ... + ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border); + + // + // set the chart's corner, relative to which point coordinates are defined ... + ObjectSetInteger(chartID, name, OBJPROP_CORNER, corner); + + // + // set flat border color (in Flat mode) ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set flat border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set flat border width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, lineWidth); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the label by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move Rectangle Label .. +bool MoveRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int x = 0, // X coordinate + const int y=0 // Y coordinate +) { + // + // reset the error value ... + ResetLastError(); + + // + // move the rectangle label ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move X coordinate of the label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move Y coordinate of the label! Error code = ",GetLastError() + ); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the rectangle label ... +bool DeleteRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel" // label name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the label ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change Rectangle Label Size ... +bool ChangeSizeRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int width = 50, // label width + const int height = 18 // label height +) { + // + // reset the error value ... + ResetLastError(); + + // + // change label size ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's width! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's height! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change rectangle label border type ... +bool RectLabelChangeBorderType( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const ENUM_BORDER_TYPE border = BORDER_SUNKEN // border type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change border type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the border type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End RectangleLabel Functions ... +// + +// +// Start TrendLine Funcions ... +// +// Create a trend line by the given coordinates ... +bool DrawTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrYellow, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool rayRight = false, // line's continuation to the right + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeTrendLineEmptyPoints( + time1, + price1, + time2, + price2 + ); + + // + // reset the error value ... + ResetLastError(); + + // + // create a trend line by the given coordinates ... + if(!ObjectCreate(chartID, name, OBJ_TREND, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the line's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move trend line anchor point ... | +bool ChangeTrendLinePoint( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int pointindex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move trend line's anchor point ... + if(!ObjectMove(chartID, name, pointindex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// The function deletes the trend line from the chart ... +bool DeleteTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a trend line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of trend line's anchor points and set default ... +// values for empty ones ... +void ChangeTrendLineEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the first point's time is not set, it will be on the current bar ... + if (!time1) { + time1 = TimeCurrent(); + } + + // + // if the first point's price is not set, it will have Bid value ... + if (!price1) { + price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // if the second point's time is not set, it is located 9 bars left from the second one ... + if (!time2) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(), Period(), time1, 10, temp); + + // + // set the second point 9 bars left from the first one ... + time2 = temp[0]; + } + + // + // if the second point's price is not set, it is equal to the first point's one ... + if (!price2) { + price2 = price1; + } +} +// +// End TrendLine Functions ... +// + +// +// Start Text Functions ... +// +// Create and Draw a Text Object ... +bool DrawText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const string text = "Text", // the text itself + const string font = "Arial", // font + const int fontSize = 10, // font size + const color clr = clrRed, // color + const double angle = 0.0, // text slope + const ENUM_ANCHOR_POINT anchor = ANCHOR_CENTER, // anchor type + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor point coordinates if they are not set ... + ChangeTextEmptyPoint(time,price); + + // + // reset the error value ... + ResetLastError(); + + // + //--- create Text object + if(!ObjectCreate(chartID, name, OBJ_TEXT, subWindow, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the text ... + ObjectSetString(chartID, name , OBJPROP_TEXT, text); + + // + // set text font ... + ObjectSetString(chartID, name, OBJPROP_FONT, font); + + // + // set font size ... + ObjectSetInteger(chartID, name, OBJPROP_FONTSIZE, fontSize); + + // + // set the slope angle of the text ... + ObjectSetDouble(chartID, name, OBJPROP_ANGLE, angle); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the object by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID ,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point ... +bool MoveText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + //--- if point position is not set, move it to the current bar having Bid price + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point .. + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the object text ... +bool ChangeText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const string text = "Text" // text +) { + // + // reset the error value ... + ResetLastError(); + + // + // change object text ... + if(!ObjectSetString(chartID, name, OBJPROP_TEXT, text)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the text! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Text object ... +bool DeleteText( + const long chartID = 0, // chart's ID + const string name = "Text" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeTextEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + } +// +// End Text Functions ... +// + +// +// Start Fibonacchi Functions ... +// +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawFibonacci( + const long chartID = 0, // chart's ID + const string name="Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrRed, // object color + const ENUM_LINE_STYLE style = STYLE_SOLID, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawCustomFibonacci( + // + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + // + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrAqua, // object color + const ENUM_LINE_STYLE style = STYLE_DOT, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // Change Levels Of Fibonacci ... + bool result = FibonacciLevelsSet( + levels, + values, + colors, + styles, + widths, + descriptions, + chartID, + name + ); + + // + // successful execution ... + return result; +} + +// +// Set number of levels and their parameters ... +bool FibonacciLevelsSet( + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // check array sizes ... + if( + levels!=ArraySize(colors) || + levels!=ArraySize(styles) || + levels!=ArraySize(widths) || + levels!=ArraySize(widths) + ) { + // + string message = StringConcatenate( + __FUNCTION__, + ": array length does not correspond to the number of levels, error!" + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the number of levels ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELS, levels); + + // + // set the properties of levels in the loop ... + for(int i = 0; i < levels; i++) { + // + // level value ... + ObjectSetDouble(chartID, name, OBJPROP_LEVELVALUE, i, values[i]); + + // + // level color ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELCOLOR, i, colors[i]); + + // + // level style ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELSTYLE, i, styles[i]); + + // + // level width ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELWIDTH, i, widths[i]); + + // + // level description ... + // ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, DoubleToString(100 * values[i], 1)); + ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, descriptions[i]); + } + + // + // successful execution ... + return(true); +} + +// +// Move Fibonacci Retracement anchor point ... +bool FibonacciPointChange( + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int pointIndex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, pointIndex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Fibonacci Retracement ... +bool DeleteFibonachi( + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Fibonacci Retracement\"! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of Fibonacci Retracement anchor points and set +// default values for empty ones ... +void ChangeFibonacciEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the second point's time is not set, it will be on the current bar ... + if (!time2) { + time2 = TimeCurrent(); + } + + // + // if the second point's price is not set, it will have Bid value ... + if (!price2) { + price2 = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // if the first point's time is not set, it is located 9 bars left from the second one ... + if (!time1) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(),Period(),time2,10,temp); + + // + // set the first point 9 bars left from the second one ... + time1 = temp[0]; + } + + // + // if the first point's price is not set, move it 200 points below the second one ... + if (!price1) { + price1 = price2 - 200 * SymbolInfoDouble(_Symbol, SYMBOL_POINT); + } +} +// +// End Fibonacci Functions ... +// + + +// +// Start General Functions ... +// +// +// Remove all Drawn Objects ... +void RemoveDraws(const string &tag) { + // + for(int iObj=ObjectsTotal()-1; iObj >= 0; iObj--) { + // + string on = ObjectName(iObj); + if (StringFind(on, tag) == 0) { + ObjectDelete(on); + } + } +} +// +// End General Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/21-00/Libraries/x-saherelm.indicator.lib.mq4 b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.indicator.lib.mq4 new file mode 100644 index 0000000..28beaf9 --- /dev/null +++ b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.indicator.lib.mq4 @@ -0,0 +1,948 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Indicator Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +static double zigZags[]; +// +// END Global Requirement Functions ... +// + +// +// START Indicator Reading Data ... +// +// +// START XMKT Data ... +// +XMKTState GetXMKT( + const int bar_index, + const int marketLen, + // + const bool showHighestHigh = true, + const bool showHighestLow = true, + const bool showHighestOpen = true, + const bool showHighestClose = true, + const bool showLowestHigh = true, + const bool showLowestLow = true, + const bool showLowestOpen = true, + const bool showLowestClose = true, + const color highestHighColor = clrDeepPink, + const color highestLowColor = clrDarkOrange, + const color highestOpenColor = clrDodgerBlue, + const color highestCloseColor = clrOrchid, + const color lowestHighColor = clrHotPink, + const color lowestLowColor = clrOrange, + const color lowestOpenColor = clrPowderBlue, + const color lowestCloseColor = clrMediumOrchid, + const ENUM_LINE_STYLE highestHighStyle = STYLE_DOT, + const ENUM_LINE_STYLE highestLowStyle = STYLE_DOT, + const ENUM_LINE_STYLE highestOpenStyle = STYLE_DOT, + const ENUM_LINE_STYLE highestCloseStyle = STYLE_DOT, + const ENUM_LINE_STYLE lowestHighStyle = STYLE_DOT, + const ENUM_LINE_STYLE lowestLowStyle = STYLE_DOT, + const ENUM_LINE_STYLE lowestOpenStyle = STYLE_DOT, + const ENUM_LINE_STYLE lowestCloseStyle = STYLE_DOT +) { + // + XMKTState result = {}; + + // + string xmktIndName = "x-saherelm.xmarket"; + + // + int highestHighBufferIndex = 0; + int highestLowBufferIndex = 1; + int highestOpenBufferIndex = 2; + int highestCloseBufferIndex = 3; + int lowestHighBufferIndex = 4; + int lowestLowBufferIndex = 5; + int lowestOpenBufferIndex = 6; + int lowestCloseBufferIndex = 7; + + // + // Highest High ... + double highestHigh = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + highestHighBufferIndex, // Buffer Index ... + bar_index + ); + result.highestHigh = highestHigh; + + // + // Highest Low ... + double highestLow = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + highestLowBufferIndex, // Buffer Index ... + bar_index + ); + result.highestLow = highestLow; + + // + // Highest Open ... + double highestOpen = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + highestOpenBufferIndex, // Buffer Index ... + bar_index + ); + result.highestOpen = highestOpen; + + // + // Highest Close ... + double highestClose = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + highestCloseBufferIndex, // Buffer Index ... + bar_index + ); + result.highestClose = highestClose; + + // + // Lowest High ... + double lowestHigh = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + lowestHighBufferIndex, // Buffer Index ... + bar_index + ); + result.lowestHigh = lowestHigh; + + // + // Lowest Low ... + double lowestLow = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + lowestLowBufferIndex, // Buffer Index ... + bar_index + ); + result.lowestLow = lowestLow; + + // + // Lowest Open ... + double lowestOpen = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + lowestOpenBufferIndex, // Buffer Index ... + bar_index + ); + result.lowestOpen = lowestOpen; + + // + // Lowest Close ... + double lowestClose = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + lowestCloseBufferIndex, // Buffer Index ... + bar_index + ); + result.lowestClose = lowestClose; + + // + return result; +} +// +// END XMKT Data ... +// + +// +// START XOSC Data ... +// +XCycleState GetXOSC( + const int bar_index, + const int marketLen, + // + const int fastMult, + const int slowMult, + // + const double fastMMul = 1.0, + const double slowMMul = 3.0 +) { + // + XCycleState result = {}; + + // + string oscIndName = "x-saherelm.osc"; + + // + // Prepare OSC Inputs ... + // + int fastLength = fastMult * marketLen; + int slowLength = slowMult * marketLen; + + // + // Fast ... + double fast = iCustom( + _Symbol, + _Period, + oscIndName, + // + // Inputs ... + fastLength, + fastMMul, + slowLength, + slowMMul, + // + 0, // Buffer Index ... + bar_index + ); + result.fast = fast; + + // + // Slow ... + double slow = iCustom( + _Symbol, + _Period, + oscIndName, + // + // Inputs ... + fastLength, + fastMMul, + slowLength, + slowMMul, + // + 1, // Buffer Index ... + bar_index + ); + result.slow = slow; + + // + return result; +} +// +// END XOSC Data ... +// + +// +// START XBND Data ... +// +XBndState GetXBND( + const int bar_index, + // + const int marketLen = 10, // Market Length ... + const int shift = 0, // MA Shift ... + const ENUM_MA_METHOD method = MODE_SMA // MA Method ... +) { + // + XBndState result = {}; + + // + double high = GetMA( + bar_index, + marketLen, + shift, + method, + PRICE_HIGH + ); + result.high = high; + + // + double open = GetMA( + bar_index, + marketLen, + shift, + method, + PRICE_OPEN + ); + result.open = open; + + // + double close = GetMA( + bar_index, + marketLen, + shift, + method, + PRICE_CLOSE + ); + result.close = close; + + // + double low = GetMA( + bar_index, + marketLen, + shift, + method, + PRICE_LOW + ); + result.low = low; + + // + return result; +} +// +// END XBND Data ... +// + +// +// START ZigZag Data ... +// +void PrepareZigZagState( + const int bar_index, + // + const int depth = 12, + const int deviation = 5, + const int backStep = 3 +) { + // + string zigzagIndName = "x-saherelm.zigzag"; + + // + ArrayFree(zigZags); + ArrayResize( + zigZags, + 3 + ); + + // + double zigZag = 0; + int index = 0; + int i = bar_index; + while (index < 3) { + // + zigZag = iCustom( + _Symbol, + _Period, + zigzagIndName, + // + // Inputs ... + depth, + deviation, + backStep, + // + 0, // Buffer Index ... + i + ); + + // + if (zigZag > 0) { + // + zigZags[index] = zigZag; + index++; + } + + // + i++; + } +} +// +// END ZigZag Data ... +// + +// +// START XMA Data ... +// +// +// Retrieve Short Cycle ... +XCycleState GetXMASC( + const int bar_index, + const int marketLen, + const int fastMultiplier, + const int slowMultiplier, + // + const int shift = 0, + const ENUM_MA_METHOD method = MODE_SMA, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE +) { + // + XCycleState result = {}; + + // + int fastLength = marketLen * fastMultiplier; + int slowLength = marketLen * slowMultiplier; + + // + double fast = iMA( + _Symbol, + _Period, + fastLength, + shift, + method, + appliedPrice, + bar_index + ); + result.fast = fast; + + // + double slow = iMA( + _Symbol, + _Period, + slowLength, + shift, + method, + appliedPrice, + bar_index + ); + result.slow= slow; + + // + return result; +} + +// +// Retrieve Medium Cycle ... +XCycleState GetXMAMC( + const int bar_index, + const int marketLen, + const int fastMultiplier, + const int slowMultiplier, + // + const int shift = 0, + const ENUM_MA_METHOD method = MODE_SMA, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE +) { + // + XCycleState result = {}; + + // + int fastLength = marketLen * fastMultiplier; + int slowLength = marketLen * slowMultiplier; + + // + double fast = iMA( + _Symbol, + _Period, + fastLength, + shift, + method, + appliedPrice, + bar_index + ); + result.fast = fast; + + // + double slow = iMA( + _Symbol, + _Period, + slowLength, + shift, + method, + appliedPrice, + bar_index + ); + result.slow= slow; + + // + return result; +} + +// +// Retrieve Long Cycle ... +XCycleState GetXMALC( + const int bar_index, + const int marketLen, + const int fastMultiplier, + const int slowMultiplier, + // + const int shift = 0, + const ENUM_MA_METHOD method = MODE_SMA, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE +) { + // + XCycleState result = {}; + + // + int fastLength = marketLen * fastMultiplier; + int slowLength = marketLen * slowMultiplier; + + // + double fast = iMA( + _Symbol, + _Period, + fastLength, + shift, + method, + appliedPrice, + bar_index + ); + result.fast = fast; + + // + double slow = iMA( + _Symbol, + _Period, + slowLength, + shift, + method, + appliedPrice, + bar_index + ); + result.slow = slow; + + // + return result; +} + +// +// Retrieve Long Cycle ... +XCycleState GetXMANN( + const int bar_index, + // + const int shift = 0, + const ENUM_MA_METHOD method = MODE_SMA, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE +) { + // + XCycleState result = {}; + + // + int fastLength = 10; + int slowLength = 50; + + // + double fast = iMA( + _Symbol, + _Period, + fastLength, + shift, + method, + appliedPrice, + bar_index + ); + result.fast = fast; + + // + double slow = iMA( + _Symbol, + _Period, + slowLength, + shift, + method, + appliedPrice, + bar_index + ); + result.slow = slow; + + // + return result; +} + +// +// Retrieve Middle ... +double GetXMAMM( + const int bar_index, + const int marketLen, + const double multiplier, + // + const int shift = 0, + const ENUM_MA_METHOD method = MODE_EMA, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_MEDIAN +) { + // + double result = 0; + + // + int length = (int)(marketLen * multiplier); + + // + double middle = iMA( + _Symbol, + _Period, + length, + shift, + method, + appliedPrice, + bar_index + ); + result = middle; + + // + return result; +} + +// +// Retrieve XMA Parabolic SAR ... +double GetXMAPSAR( + const int bar_index, + // + double stp = 0.02, + double mxm = 0.2 +) { + // + double result = 0; + + // + double pSar = iSAR( + _Symbol, + _Period, + stp, + mxm, + bar_index + ); + result = pSar; + + // + return result; +} + +// +XState GetXState( + const int bar_index, + const int marketLen, + // + const double stp, + const double mxm, + // + const int shortCycleFastMult, + const int shortCycleSlowMult, + const int mediumCycleFastMult, + const int mediumCycleSlowMult, + const int longCycleFastMult, + const int longCycleSlowMult +) { + // + XState result = {}; + + // + // Short Cycle ... + XCycleState sc = GetXMASC( + bar_index, + marketLen, + shortCycleFastMult, + shortCycleSlowMult + ); + result.sc = sc; + + // + // Medium Cycle ... + XCycleState mc = GetXMAMC( + bar_index, + marketLen, + mediumCycleFastMult, + mediumCycleSlowMult + ); + result.mc = mc; + + // + // Long Cycle ... + XCycleState lc = GetXMALC( + bar_index, + marketLen, + longCycleFastMult, + longCycleSlowMult + ); + result.lc = lc; + + // + // OSC ... + XCycleState osc = GetXOSC( + // + bar_index, + marketLen, + // + shortCycleFastMult, + shortCycleSlowMult + ); + result.osc = osc; + + // + // Market Middleage ... + double marketMiddleage = GetXMAMM( + bar_index, + marketLen, + 1.5 + ); + result.marketMiddleage = marketMiddleage; + + // + // Parabolic SAR ... + double parabolicSAR = GetXMAPSAR( + bar_index, + stp, + mxm + ); + result.parabolicSAR = parabolicSAR; + + // // + // int cciMarketLength = longCycleSlowMult * marketLen; + // double cci = GetMarketCCI( + // bar_index, + // cciMarketLength + // ); + // result.cci = cci; + + // + XBndState bnd = GetXBND( + bar_index + ); + result.bnd = bnd; + + // + XMKTState mkt = GetXMKT( + bar_index, + marketLen + ); + result.mkt = mkt; + + // + double longCycleHighestHigh = GetMarketHighestHigh( + bar_index, + longCycleFastMult * marketLen + ); + result.longCycleHighestHigh = longCycleHighestHigh; + + // + return result; +} +// +// END XMA Data ... +// +// +// END Indicator Reading Data ... +// diff --git a/Bkp/Used/14020425/21-00/Libraries/x-saherelm.lib.mq4 b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.lib.mq4 new file mode 100644 index 0000000..658c90a --- /dev/null +++ b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.lib.mq4 @@ -0,0 +1,1502 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +struct XOHCL { + double high; + double open; + double close; + double low; +}; + +// +static datetime lastBarTime; + +// +// START Functions ... +// + +// +// Determines current working is New Bar or not ... +bool IsNewBar() { + // + // Reading Last Bar Date ... + datetime curbar = (datetime)SeriesInfoInteger( + _Symbol, + _Period, + SERIES_LASTBAR_DATE + ); + + // + if(lastBarTime != curbar) { + // + lastBarTime = curbar; + return true; + } + + // + return false; +} + +// +// Determines we are in new Day or not ... +bool IsNewDay() { + // + bool result = false; + + // + // Reading Last Bar Date ... + datetime curbar = (datetime)SeriesInfoInteger( + _Symbol, + _Period, + SERIES_LASTBAR_DATE + ); + + // + if (lastBarTime == 0) { + lastBarTime = curbar; + } + + // + if (curbar == lastBarTime) { + return result; + } + + // + // Retrieve Day and Month and Year for Last Bar Time ... + int lastBarDay = TimeDay(lastBarTime); + int lastBarMonth = TimeMonth(lastBarTime); + int lastBarYear = TimeYear(lastBarTime); + + // + // Retrieve Day and Month and Year for Current Bar Time ... + int curBarDay = TimeDay(curbar); + int curBarMonth = TimeMonth(curbar); + int curBarYear = TimeYear(curbar); + + // + result = curBarDay > lastBarDay + || curBarMonth > lastBarMonth + || curBarYear > lastBarYear; + + // + return result; +} + +// +// Retrieve RMA on Specific Candle ... +double GetRMA( + int bar_index, + int length +) { + // + double shortSMA = iMA(_Symbol, _Period, length, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double mediumSMA = iMA(_Symbol, _Period, length * 2, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double longSMA = iMA(_Symbol, _Period, length * 3, 0, MODE_SMA, PRICE_CLOSE, bar_index); + + // + double result = longSMA - mediumSMA + shortSMA; + + // + return result; +} + +// +double GetMA( + const int bar_index, + const int maLength, + const int maShift, + const ENUM_MA_METHOD maMethod, + const ENUM_APPLIED_PRICE appliedPrice +) { + // + double result = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + appliedPrice, + bar_index + ); + + // + return result; +} + +// +// Retrieve True Range ... +double GetTR( + const int bar_index +) { + // + double result = 0; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double prevClose = iClose( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double highLowDif = high - low; + double hpCDif = MathAbs(high - prevClose); + double lpCDiff = MathAbs(low - prevClose); + + // + result = MathMax(highLowDif, hpCDif); + result = MathMax(result, lpCDiff); + + // + return result; +} + +// +// Calculate True Range Simple Moving Average ... +double GetMarketTRSMA( + const int bar_index, + const int marketLen +) { + // + double result = 0; + + // + // Create Barket Length Trs ... + double trs[]; + ArrayResize( + trs, + marketLen + ); + int index = 0; + double trSum = 0; + for (int i = bar_index; i < bar_index + marketLen; i++) { + // + double tr = GetTR(i); + trs[index] = tr; + + // + trSum += tr; + + // + index++; + } + + // + result = trSum / marketLen; + + // + return result; +} + +// +// Retrieve Commodity Channel ... +double GetMarketCCI( + const int bar_index, + const int marketLen, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE +) { + // + double result = 0; + + // + result = iCCI( + _Symbol, + _Period, + marketLen, + appliedPrice, + bar_index + ); + + // + return result; +} + +// +// this function check crossing up two Buffers ... +bool IsCrossedOver( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] > arr2[index1]) && !(arr1[index2] > arr2[index2]); + + // + return result; +} + +// +// this function check crossing down two Buffers ... +bool IsCrossedUnder( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] < arr2[index1]) && !(arr1[index2] < arr2[index2]); + + // + return result; +} + +// +// Convert points to Actual Point ... +double PointsToDouble(int points) { + // + double result = points * _Point; + return result; +} + +// +// Converts Pips to Points ... +int PipsToPoints(int pips) { + // + int result = pips * ((_Digits == 3 || _Digits == 5) ? 10 : 1); + return result; +} + +// +// Converts Pips to Double ... +double PipsToDouble(int pips) { + // + double result = PointsToDouble(PipsToPoints(pips)); + return result; +} + +// +// Converts Double Value to Pips ... +int PriceToPips(double value) { + // + if (value <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + int result = (int)(value / pipValue); + + // + return result; +} + +// +// Converts Pips to Double ... +double PipsToPrice(int pips) { + // + if (pips <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + double result = pipValue * pips; + + // + return result; +} + +// +// Generate ATR StopLoss Value ... +double CalculateATRSL( + int period, + double multiplier +) { + // + if (period <= 0 || multiplier <= 0) { + return 0; + } + + // + double atrValue = iATR( + _Symbol, + _Period, + period, + 0 + ); + + // + double result = atrValue * multiplier; + + // + return result; +} + +// +// Detect Candle Type ... +// Bullish => means close > open ... +bool IsBullishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBullishCandle( + open, + close + ); + + // + return result; +} + +bool IsBullishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open < close; + + // + return result; +} + +// +// Detect Candle Type ... +// Bearish => means close < open ... +bool IsBearishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBearishCandle( + open, + close + ); + + // + return result; +} + +bool IsBearishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open > close; + + // + return result; +} + +// +// Retrieve a Candle Info ... +XOHCL GetCandleModel( + const int bar_index +) { + // + XOHCL result = {}; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + result.high = high; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + result.open = open; + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + result.close = close; + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + result.low = low; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBullishDetected( + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double shpDetectMultipliers // Sharp Detect Multiplier +) { + // + bool result = false; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double minValue = 0; + double maxValue = 0; + int positionedLength = bar_index + marketLen; + + // + for (int i = bar_index; i < positionedLength; i++) { + // + double cHigh = iHigh( + _Symbol, + _Period, + i + ); + + // + double cLow = iLow( + _Symbol, + _Period, + i + ); + + // + minValue += MathMin(cLow, cHigh); + maxValue += MathMax(cLow, cHigh); + } + + // + double minAvg = minValue / positionedLength; + double maxAvg = maxValue / positionedLength; + + // + double shpValue = shpDetectMultipliers * _Point; + + // + result = (low - minAvg) > shpValue; + + // + int index = bar_index; + while ( + index < positionedLength + || !result + ) { + // + low = iLow( + _Symbol, + _Period, + index + ); + + // + result = result + || (low - minAvg) > shpValue; + + // + index++; + }; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBearishDetected( + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double shpDetectMultipliers // Sharp Detect Multiplier +) { + // + bool result = false; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double minValue = 0; + double maxValue = 0; + int positionedLength = bar_index + marketLen; + + // + for (int i = bar_index; i < positionedLength; i++) { + // + double cHigh = iHigh( + _Symbol, + _Period, + i + ); + + // + double cLow = iLow( + _Symbol, + _Period, + i + ); + + // + minValue += MathMin(cLow, cHigh); + maxValue += MathMax(cLow, cHigh); + } + + // + double minAvg = minValue / positionedLength; + double maxAvg = maxValue / positionedLength; + + // + double shpValue = shpDetectMultipliers * _Point; + + // + result = (high - maxAvg) > shpValue; + + // + int index = bar_index; + while ( + index < positionedLength + || !result + ) { + // + high = iHigh( + _Symbol, + _Period, + index + ); + + // + result = result + || (high - maxAvg) > shpValue; + + // + index++; + }; + + // + return result; +} + +// +// Retrieve Highest High Value based on Given Market ... +double GetMarketHighestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Low Value based on Given Market ... +double GetMarketHighestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Open Value based on Given Market ... +double GetMarketHighestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Close Value based on Given Market ... +double GetMarketHighestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Low Value based on Given Market ... +double GetMarketLowestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest High Value based on Given Market ... +double GetMarketLowestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Open Value based on Given Market ... +double GetMarketLowestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Close Value based on Given Market ... +double GetMarketLowestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// less than given price ... +double GetLowLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// great than given price ... +double GetLowGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// less than given price ... +double GetHighLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// great than given price ... +double GetHighGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// less than given price ... +double GetCloseLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// great than given price ... +double GetCloseGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Get Slope of a Line by it's two Point ... +double GetSlope( + double x1, + double y1, + double x2, + double y2 +) { + // + double result = (y2 - y1)/(x2 - x1); + return result; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/21-00/Libraries/x-saherelm.log.lib.mq4 b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.log.lib.mq4 new file mode 100644 index 0000000..066b3f7 --- /dev/null +++ b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.log.lib.mq4 @@ -0,0 +1,91 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Log Tag ... +static string logTag = ""; + +// +// Enable or Disable Logging ... +static bool enableLogging = false; + +// +// Start Log Messages ... +// + +// +// Logging a Message, specified for this EA ... +// using provided LogTag ... +void LogMessage(string message) { + // + if (!enableLogging) { + return; + } + + // + Print(logTag, " > ", message); +} + +// +// this used for logging series ... +void LogSeries( + double &series[], // which series to Log ... + int length = 0, // number of items to Log, 0 means all ... + int skip = 0 // number of items which skip before logging ... +) { + // + string msg = ""; + + // + int seriesSize = ArraySize(series); + if ( + skip < 0 + || length < 0 + || seriesSize == 0 + || skip > seriesSize + || skip + length > seriesSize + ) { + return; + } + + // + length = length == 0 ? + seriesSize : + length; + int start = skip > 1 ? + skip - 1 : + skip == 1 ? + 1 : + 0; + + // + // Loop through series items ... + for (int i = start; i < start + length; i++) { + // + msg += StringConcatenate( + "i[", i, "]: ", series[i], ", " + ); + } + + // + LogMessage(msg); +} +// +// End Log Messages ... +// + diff --git a/Bkp/Used/14020425/21-00/Libraries/x-saherelm.models.lib.mq4 b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.models.lib.mq4 new file mode 100644 index 0000000..58e1e25 --- /dev/null +++ b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.models.lib.mq4 @@ -0,0 +1,225 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Models Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// START STATIC Variables ... +// +// +static int totalSignals = 0; +static int totalLongSignals = 0; +static int totalShortSignals = 0; + +// +static double initialBalance = 0; + +// +static int countedBars = 0; +static bool isNewBar = false; +static bool isNewDay = false; +// +// END STATIC Variables ... +// + +// +// Start Models ... +// +// +// Signal Providers ... +enum ENUM_X_SIGNAL_PROVIDER { + X_UNKNOWN_PROVIDER, + X_OSC_PROVIDER, + X_CCI_PROVIDER, + X_SHP_PROVIDER, + X_XMA_PROVIDER, + X_RMA_PROVIDER, + X_XXX_PROVIDER +}; + +// +// these are different signal types ... +enum ENUM_X_SIGNAL_TYPE { + X_SIGNAL_NONE, + X_SIGNAL_LONG, + X_SIGNAL_SHORT, +}; + +// +// we Model each signals as this type ... +struct XSignal { + // + // Signal Symbol ... + string symbol; + + // + // Signal Type ... + ENUM_X_SIGNAL_TYPE type; + + // + // Signal ID ... + int id; + + // + // Signal Ticket Number, when Opening Trade ... + int ticket; + + // + // Signal Provider ... + ENUM_X_SIGNAL_PROVIDER provider; + + // + // Target Point ... + double tp; + + // + // Stop Loss ... + double sl; + + // + // Signal Entry Price ... + double entry; + + // + // Signalling Time ... + datetime time; + + // + // Signal Comments ... + string comment; +}; + +// +// this is Signal Request Response model ... +struct XSignalRequest { + bool hasSignal; + XSignal signal; + ENUM_X_SIGNAL_TYPE type; + ENUM_X_SIGNAL_PROVIDER provider; +}; + +// +struct XBndState { + double high; + double open; + double close; + double low; +}; + +// +struct XMKTState { + // + double highestHigh; + double highestLow; + double highestOpen; + double highestClose; + + // + double lowestHigh; + double lowestLow; + double lowestOpen; + double lowestClose; +}; + +// +struct XCycleState { + double fast; + double slow; +}; + +// +// Define a Model to Represent Snapshot of XMA Indicator ... +struct XState { + // + // SC ... + XCycleState sc; + + // + // MC ... + XCycleState mc; + + // + // LC ... + XCycleState lc; + + // + // OSC ... + XCycleState osc; + + // + // MIDDLEAGE ... + double marketMiddleage; + + // + // PARABOLIC-SAR ... + double parabolicSAR; + + // + double cci; + + // + XBndState bnd; + + // + XMKTState mkt; + + // + double longCycleHighestHigh; +}; + +// +// Parsed XMA Buffer ... +struct XStateInfo { + // + // Check Market Cross Exists or not ... + // + bool isSCFastCrossOverSlow; + bool isSCFastCrossUnderSlow; + + // + double scMin; + double scMax; + + // + bool isMCFastCrossOverSlow; + bool isMCFastCrossUnderSlow; + + // + double mcMin; + double mcMax; + + bool isLCFastCrossOverSlow; + bool isLCFastCrossUnderSlow; + + // + double lcMin; + double lcMax; + + // + bool isMMCrossOverSCFast; + bool isMMCrossUnderSCFast; + + // + bool isMMCrossOverMCFast; + bool isMMCrossUnderMCFast; + + // + double mmMin; + double mmMax; +}; +// +// End Models ... +// diff --git a/Bkp/Used/14020425/21-00/Libraries/x-saherelm.osc.signal.lib.mq4 b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.osc.signal.lib.mq4 new file mode 100644 index 0000000..84f0386 --- /dev/null +++ b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.osc.signal.lib.mq4 @@ -0,0 +1,363 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 OSC Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// SHP Based Signal Conditions ... +struct XOSCLongSignalConditions { + // + datetime crossOverTime; + double slowOnCrossOver; + + // + datetime crossUnderTime; + double slowOnCrossUnder; +}; + +// +static XOSCLongSignalConditions oscLongConds; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill CC Signal Conditions ... +void CheckOSCLongSignalConditions( + const int bar_index, + const int marketLen, + // + double stp, + double mxm, + // + int scFMult, + int scSMult, + // + int mcFMult, + int mcSMult, + // + int lcFMult, + int lcSMult, + // + const double smoother = 5 +) { + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XState states[]; + ArrayResize( + states, + marketLen + ); + + // + int index = 0; + for (int i = bar_index; i < marketLen; i++) { + // + XState state = GetXState( + i, + marketLen, + // + stp, + mxm, + scFMult, + scSMult, + mcFMult, + mcSMult, + lcFMult, + lcSMult + ); + + // + states[index] = state; + + // + index++; + } + + // + bool isCrossUnder = + states[0].osc.fast < 0 + && !(states[1].osc.fast < 0) + ; + + // + bool isCrossOver = + states[0].osc.fast > 0 + && !(states[1].osc.fast > 0) + ; + + // + int oneTouches = 0; + int halfTouches = 0; + int minusOneTouches = 0; + for (int i = 0; i < marketLen - 1; i++) { + // + // One Touches ... + if ( + states[i].osc.fast > 1 + && !(states[i + 1].osc.fast > 1) + ) { + oneTouches++; + } + + // + // Half Touches ... + if ( + states[i].osc.fast > 0.5 + && !(states[i + 1].osc.fast > 0.5) + ) { + halfTouches++; + } + + // + // Minus One Touches ... + if ( + states[i].osc.fast < -1 + && !(states[i + 1].osc.fast < -1) + ) { + minusOneTouches++; + } + } + + // + if ( + isCrossUnder + && oscLongConds.crossUnderTime == 0 + ) { + // + oscLongConds.crossUnderTime = barTime; + oscLongConds.slowOnCrossUnder = states[0].osc.slow; + return; + } + + // + if ( + isCrossOver + && oscLongConds.crossUnderTime > 0 + && oscLongConds.crossOverTime == 0 + ) { + // + oscLongConds.crossOverTime = barTime; + oscLongConds.slowOnCrossOver = states[0].osc.slow; + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateOSCLongSignal( + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r // Risk to Reward ratio ... +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if (!ValidateOSCLongConditions()) { + return result; + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double entryPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double exitPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + GetMarketLowestLow( + bar_index, + marketLen + ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = MathMin(openPrice, closePrice) - ll; + double reward = risk * r2r; // 300 * _Point; + + // + double sl = 0; // ll; + double tp = entryPrice + reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = X_SIGNAL_LONG; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_OSC_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = X_SIGNAL_LONG; + result.provider = X_OSC_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateOSCLongConditions() { + // + bool isConditionsFilled = + oscLongConds.crossOverTime > 0 + && oscLongConds.crossUnderTime > 0 + && oscLongConds.slowOnCrossOver > 0 + && oscLongConds.slowOnCrossUnder > 0 + && oscLongConds.crossOverTime > oscLongConds.crossUnderTime + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int crossUnderBarIndex = iBarShift( + _Symbol, + _Period, + oscLongConds.crossUnderTime + ); + + // + int crossOverBarIndex = iBarShift( + _Symbol, + _Period, + oscLongConds.crossOverTime + ); + + // + isBLFilled = + crossUnderBarIndex > crossOverBarIndex + // && oscLongConds.slowOnCrossOver > oscLongConds.slowOnCrossUnder + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearOSCLongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearOSCLongSignalConditions() { + // + oscLongConds.crossOverTime = 0;; + oscLongConds.crossUnderTime = 0;; +} + +// +// Check State for Long Signals ... +bool IsReadyForOSCLongSignals( + const XSignal &signal, + const XState &states[] +) { + // + bool result = false; + + // + result = + // + true + ; + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020425/21-00/Libraries/x-saherelm.rma.signal.lib.mq4 b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.rma.signal.lib.mq4 new file mode 100644 index 0000000..4b9637a --- /dev/null +++ b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.rma.signal.lib.mq4 @@ -0,0 +1,363 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 RMA Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// RMA Based Signal Conditions ... +struct XRMALongSignalConditions { + // + datetime crossUnderTime; + + // + datetime crossOverTime; +}; + +// +static XRMALongSignalConditions xrmaLongConds; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill CC Signal Conditions ... +void CheckXRMALongSignalConditions( + const int bar_index, + const int marketLen, + // + const double smoother = 5 +) { + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XCycleState states[]; + ArrayResize( + states, + marketLen + ); + + // + int index = 0; + for (int i = bar_index; i < marketLen; i++) { + // + XCycleState state = GetXMANN(i); + + // + states[index] = state; + + // + index++; + } + + // + bool isCrossUnder = + states[1].fast < states[1].slow + && !(states[2].fast < states[2].slow) + ; + + // + bool isCrossOver = + states[1].fast > states[1].slow + && !(states[2].fast > states[2].slow) + ; + + // + if ( + isCrossUnder + && xrmaLongConds.crossUnderTime == 0 + ) { + // + xrmaLongConds.crossUnderTime = barTime; + return; + } + + // + if ( + isCrossOver + && xrmaLongConds.crossUnderTime > 0 + && xrmaLongConds.crossOverTime == 0 + ) { + // + xrmaLongConds.crossOverTime = barTime; + return; + } +} + +// +// Convert XMA Long Signal Conditions to XSignal ... +XSignalRequest GenerateXRMALongSignal( + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r // Risk to Reward ratio ... +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if (!ValidateXRMALongConditions(marketLen)) { + return result; + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double entryPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double exitPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + GetMarketLowestLow( + bar_index, + marketLen + ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = MathMin(openPrice, closePrice) - ll; + double reward = risk * r2r; // 300 * _Point; + + // + double sl = 0; // entryPrice - (300 * _Point); // ll; + double tp = entryPrice + reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = X_SIGNAL_LONG; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_RMA_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = X_SIGNAL_LONG; + result.provider = X_RMA_PROVIDER; + + // + return result; +} + +// +// Validate XMA Signal Conditions ... +bool ValidateXRMALongConditions( + const int marketLen +) { + // + bool isConditionsFilled = + true + && xrmaLongConds.crossOverTime > 0 + && xrmaLongConds.crossUnderTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int crossOverBarIndex = iBarShift( + _Symbol, + _Period, + xrmaLongConds.crossOverTime + ); + + // + int crossUnderBarIndex = iBarShift( + _Symbol, + _Period, + xrmaLongConds.crossUnderTime + ); + + // + XCycleState stateOnCrossUnder = GetXMANN( + crossUnderBarIndex + ); + + // + XCycleState stateOnCrossOver = GetXMANN( + crossOverBarIndex + ); + + // + double maC = iMA( + _Symbol, + _Period, + 14, + 0, + MODE_SMA, + PRICE_CLOSE, + crossOverBarIndex + ); + + // // + // double rmaOnCrossOver = GetRMA( + // crossOverBarIndex, + // 10 + // ); + + // // + // double rmaOnMarketLength = GetRMA( + // crossOverBarIndex + marketLen, + // 10 + // ); + + // // + // double prevCandleHigh = iHigh( + // _Symbol, + // _Period, + // crossOverBarIndex + // ); + + // // + // PrepareZigZagState(crossOverBarIndex); + // double zigZagDelta = zigZags[1] - zigZags[2]; + // bool isZigZagWaitForHigh = zigZagDelta < 0; + + // + isBLFilled = + true + // + && (crossUnderBarIndex - crossOverBarIndex) > 5 + // + && xrmaLongConds.crossOverTime > xrmaLongConds.crossUnderTime + // + && stateOnCrossOver.slow < stateOnCrossUnder.slow + // + && MathAbs(stateOnCrossOver.fast - stateOnCrossOver.slow) > (70 * _Point) + // + && maC >= stateOnCrossOver.slow + // // + // && !(rmaOnCrossOver < stateOnCrossOver.slow) + // // + // && MathAbs(rmaOnCrossOver - rmaOnMarketLength) < (600 * _Point) + // // + // && !isZigZagWaitForHigh + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXRMALongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXRMALongSignalConditions() { + // + xrmaLongConds.crossOverTime = 0; + xrmaLongConds.crossUnderTime = 0; +} + +// +// Check XMA State for Long Signals ... +bool IsReadyForXRMALongSignals( + const XSignal &signal, + const XState &states[], + const int marketLen +) { + // + bool result = false; + + // + result = + // + true + ; + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020425/21-00/Libraries/x-saherelm.shp.signal.lib.mq4 b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.shp.signal.lib.mq4 new file mode 100644 index 0000000..dd0f767 --- /dev/null +++ b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.shp.signal.lib.mq4 @@ -0,0 +1,391 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 SHP Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// SHP Based Signal Conditions ... +struct XSHPLongSignalConditions { + // + datetime start; + datetime stop; +}; + +// +static XSHPLongSignalConditions shpLongConds; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill CC Signal Conditions ... +void CheckSHPLongSignalConditions( + const int bar_index, + const int marketLen, + const double shpDetectMult, + const double smoother = 30 +) { + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double mHH = GetMarketHighestHigh( + bar_index, + marketLen + ); + + // + double mLL = GetMarketLowestLow( + bar_index, + marketLen + ); + + double m2LL = GetMarketLowestLow( + bar_index, + marketLen * 2 + ); + + // + int mHLIdx = iHighest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + datetime mHLTime = iTime( + _Symbol, + _Period, + mHLIdx + ); + double mHL = iHigh( + _Symbol, + _Period, + mHLIdx + ); + + // + double hlDiff = (mHL - mLL); + double sharpDetectValue = shpDetectMult * _Point; + + // + bool isSharpDetected = + // ( + // low == mLL + // || MathAbs(mLL - low) < (smoother * _Point) + // ) + // && + // !( + // mLL > m2LL + // && MathAbs(m2LL - mLL) > sharpDetectValue / 2 + // ) + // && + ( + hlDiff > sharpDetectValue + || hlDiff > sharpDetectValue - (smoother * _Point) + ) + ; + + // + if (isSharpDetected) { + // + shpLongConds.start = mHLTime; + shpLongConds.stop = barTime; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateSHPLongSignal( + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r, // Risk to Reward ratio ... + const double shpDetectMultiplier // Sharp Detect Multiplier ... +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if (!ValidateSHPLongConditions(shpDetectMultiplier)) { + return result; + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double entryPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double exitPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + GetMarketLowestLow( + bar_index, + marketLen + ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = MathMin(openPrice, closePrice) - ll; + double reward = 300 * _Point; // risk * r2r; + + // + double sl = 0; // ll; + + // + // this means Market Lowest Low ... + double shpValue = shpDetectMultiplier * _Point; + if ( + reward == 0 + || reward < 20 * _Point + ) { + reward = shpValue; + } + double tp = entryPrice + reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = X_SIGNAL_LONG; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_SHP_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = X_SIGNAL_LONG; + result.provider = X_SHP_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateSHPLongConditions( + const double shpDetectMultiplier +) { + // + double shpDetectValue = shpDetectMultiplier * _Point; + + // + bool isConditionsFilled = + shpLongConds.stop != 0 + && shpLongConds.start != 0 + && shpLongConds.stop > shpLongConds.start + ; + + // + bool isBLFilled = true; + + // + bool result = + isBLFilled + && isConditionsFilled + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearSHPLongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearSHPLongSignalConditions() { + // + shpLongConds.stop = 0; + shpLongConds.start = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForSHPLongSignals( + const XSignal &signal, + const XState &states[] +) { + // + bool result = false; + + // + XStateInfo info = ParseXMAStates(states); + + // + int xmaMarketLen = ArraySize(states); + double mHH = GetMarketHighestHigh(0, xmaMarketLen); + double m2HH = GetMarketHighestHigh(0, (int) (xmaMarketLen * 1.5)); + + // + int lcUpDownTouches = 0; + int cciHundredTouches = 0; + for (int i = 0; i < xmaMarketLen; i++) { + // + double high = iHigh( + _Symbol, + _Period, + i + ); + + // + double low = iLow( + _Symbol, + _Period, + i + ); + + // + double up = MathMax(states[i].lc.fast, states[i].lc.slow); + double down = MathMax(states[i].lc.fast, states[i].lc.slow); + + // + if (high >= up && low <= down) { + lcUpDownTouches++; + } + + // + if ( + i < xmaMarketLen - 1 + && i < 10 + ) { + if ( + states[i].cci < 100 + && states[i + 1].cci > 100 + ) { + cciHundredTouches++; + } + } + } + + // + result = + // + true + // + && states[0].mc.fast > states[0].mc.slow + && states[0].lc.fast > states[0].lc.slow + // + && states[0].sc.fast < states[0].sc.slow + && states[1].sc.fast < states[1].sc.slow + // + && states[0].marketMiddleage < states[0].sc.fast + && states[1].marketMiddleage < states[1].sc.fast + && !( + states[1].sc.fast < states[1].mc.fast + && states[1].sc.slow < states[1].mc.fast + && states[1].sc.fast > states[1].mc.slow + && states[1].sc.slow > states[1].mc.slow + ) + && !( + states[0].marketMiddleage < states[0].mc.fast + && states[0].marketMiddleage > states[0].mc.slow + ) + // + && mHH != m2HH + && lcUpDownTouches == 0 + && cciHundredTouches == 0 + ; + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020425/21-00/Libraries/x-saherelm.signal.lib.mq4 b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.signal.lib.mq4 new file mode 100644 index 0000000..2b4fa56 --- /dev/null +++ b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.signal.lib.mq4 @@ -0,0 +1,1456 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Signal Draw Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +#include "../Libraries/x-saherelm.x.signal.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// END Global Requirement Functions ... +// + +// +// START Signal Related Functions ... +// +// +// Retrieve Signal Bar Index ... +int GetSignalBarIndex(XSignal &signal) { + // + // Temp Result ... + int result = -1; + + // + // Retriev Signal Bar Index ... + result = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + return result; +} + +// +string GetProviderIdentifier( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + string result = ""; + + // + switch (provider) + { + case X_XXX_PROVIDER: + result = "XXX"; + break; + + default: + result = ""; + break; + } + + // + return result; +} + +// +ENUM_X_SIGNAL_PROVIDER GetProvider(string identifier) { + // + ENUM_X_SIGNAL_PROVIDER result = X_UNKNOWN_PROVIDER; + + // + if ( + StringFind( + identifier, + GetProviderIdentifier(X_XXX_PROVIDER) + ) > -1 + ) { + result = X_XXX_PROVIDER; + } + + // + return result; +} + +// +// Draw Signal Shapes on Chart ... +bool DrawSignal( + const XSignal &signal, + long chartID = 0, + int subWindowID = 0, + const double positionThresholdFactor = 10, + string signalTag = "X-Signal", + string longSignalLabel = "X-Long", + color longSignalColor = clrAqua, + string shortSignalLabel = "X-Short", + color shortSignalColor = clrFuchsia +) { + // + // Generate isLongSignal Var ... + bool isLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Signal Bar Index ... + int bar_index = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // START Draw Signal Arrow ... + // + // + // Arrow Shape Name ... + string arrowName = StringConcatenate(signalTag, "_Arrow_", signal.id); + + // + // Arrow Price ... + double arrowPrice = 0; + if (isLongSignal) { + // + arrowPrice = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice - (positionThresholdFactor * _Point); + } else { + // + arrowPrice = iHigh( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice + (positionThresholdFactor * _Point); + } + + // + // Arrow Code ... + uchar arrowCode = isLongSignal ? SYMBOL_ARROWUP : SYMBOL_ARROWDOWN; + + // + // Arrow Anchor Point ... + ENUM_ARROW_ANCHOR arrowAnchorPoint = isLongSignal ? ANCHOR_BOTTOM : ANCHOR_TOP; + + // + // Arrow Color ... + color arrowColor = isLongSignal ? longSignalColor : shortSignalColor; + + // + // Draw Signal Arrow Shape ... + bool result = DrawArrow( + chartID, + arrowName, + subWindowID, + signal.time, + arrowPrice, + arrowCode, + arrowAnchorPoint, + arrowColor + ); + // + // END Draw Signal Arrow ... + // + + // + // START Draw Signal SL/TP ... + // + string slLineName = StringConcatenate(signalTag, "_SL_", signal.id); + string tpLineName = StringConcatenate(signalTag, "_TP_", signal.id); + string entryLineName = StringConcatenate(signalTag, "_ENTRY_", signal.id); + + // + color slColor = shortSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color tpColor = longSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color entryColor = clrGreen; + + // + datetime time1 = iTime( + _Symbol, + _Period, + bar_index + 1 + ); + + // + // Draw Enrty Price ... + result = DrawTrendLine( + chartID, + entryLineName, + subWindowID, + time1, + signal.entry, + signal.time, + signal.entry, + entryColor, + STYLE_SOLID, + 2 + ); + + // + // Draw Signal SL ... + if (signal.sl > 0) { + // + result = DrawTrendLine( + chartID, + slLineName, + subWindowID, + time1, + signal.sl, + signal.time, + signal.sl, + slColor, + STYLE_SOLID, + 2 + ); + } + + // + // Draw Signal TP ... + if (signal.tp > 0) { + // + result = DrawTrendLine( + chartID, + tpLineName, + subWindowID, + time1, + signal.tp, + signal.time, + signal.tp, + tpColor, + STYLE_SOLID, + 2 + ); + } + // + // END Draw Signal SL/TP ... + // + + // + // Start Draw Signal Label ... + // + // + string labelName = StringConcatenate(signalTag, "_Label_", signal.id); + + // + double labelPrice = isLongSignal ? arrowPrice - (positionThresholdFactor * _Point) : arrowPrice + (positionThresholdFactor * _Point); + + // + string labelText = isLongSignal ? longSignalLabel : shortSignalLabel; + labelText = StringConcatenate( + labelText, + "_", + GetProviderIdentifier(signal.provider) + ); + + // + result = DrawText( + chartID, + labelName, + subWindowID, + signal.time, + labelPrice, + labelText, + "Arial", + 8, + arrowColor, + 0, + ANCHOR_CENTER + ); + // + // End Draw Signal Label ... + // + + // + return result; +} + +// +// Trade on Specific Signal ... +bool TradeSignal( + XSignal &signal, + // + string prefix, + // + double volumePercent, + // + // Long ... + const string longSignalLabel, + const color longSignalColor, + // + // Short ... + const string shortSignalLabel, + const color shortSignalColor +) { + // + // Temp Result ... + bool result = false; + + // + if (initialBalance == 0) { + initialBalance = AccountInfoDouble(ACCOUNT_BALANCE); + } + + // + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + int openPositions = CountOpenTrades(); + double volume = (volumePercent * initialBalance); + + // + if ( + signal.type != X_SIGNAL_LONG && + signal.type != X_SIGNAL_SHORT + ) { + return result; + } + + // + bool hasLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Check TP and Entry Price ... + if ( + ( + hasLongSignal + && signal.entry > signal.tp + ) || + ( + !hasLongSignal + && signal.entry < signal.tp + ) + ) { + return result; + } + + // + // Order Operation ... + int operation = hasLongSignal ? + OP_BUY : + OP_SELL; + + // + // Detect Trade Color ... + color clr = hasLongSignal ? + longSignalColor : + shortSignalColor; + + // + // Generate Signal Comment ... + string label = hasLongSignal ? + longSignalLabel : + shortSignalLabel; + + // + // Generate Signal Comment ... + string comment = StringConcatenate( + prefix, + "_", signal.id, + "_", GetProviderIdentifier(signal.provider), + "_", label + ); + + // + // Placing Order ... + int orderTicket = OrderSend( + _Symbol, + operation, + volume, + signal.entry, + 3, + signal.sl, + signal.tp, + comment, + signal.id, + 0, + clr + ); + + // + // Draw Signal Shape if Order Opened Successfully ... + if (orderTicket >= 0) { + // + signal.ticket = orderTicket; + + // + // Here i must to Draw Signal Shapes ... + bool isDrawn = DrawSignal( + signal, + 0, + 0, + 50, + prefix, // Signal Tag ... + longSignalLabel, // Long Signal Label ... + longSignalColor, + shortSignalLabel, // Short Signal Label ... + shortSignalColor + ); + + // + LogMessage( + StringConcatenate( + "Order [", orderTicket ,"]: Provided by: ", GetProviderIdentifier(signal.provider) + ) + ); + + // + // TODO: here we have to check if there are another + // open positions which their entry price is bigger + // than current signal entry price, for long trades and + // their tp is high than current tp, ... + // close in profit trades or modify orders tp to current ... + // // + // if (CountOpenTrades() > 0) { + // // + // // Here we have to + // // ModifyOpenTradesBasedOnCurrentTrade(signal); + // } + + // + result = true; + } + + // + return result; +} +// +// END Signal Related Functions ... +// + +// +// START Orders Functions ... +// +// +// Convert To XSignal Model ... +XSignal OrderToSignal() { + // + // Temp Result ... + XSignal result = {}; + result.type = X_SIGNAL_NONE; + + // + // Here we can get some usefull info based on selected order ... + double swap = OrderSwap(); + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + int magicNumber = OrderMagicNumber(); + double takeProfit = OrderTakeProfit(); + string comment = OrderComment(); + + // + ENUM_X_SIGNAL_PROVIDER provider = GetProvider(comment); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // Conver Position to Signal ... + result.sl = stopLoss; + result.tp = takeProfit; + result.time = openTime; + result.symbol = _Symbol; + result.id = magicNumber; + result.comment = comment; + result.entry = openPrice; + result.provider = provider; + result.type = isLongOrder ? X_SIGNAL_LONG : X_SIGNAL_SHORT; + + // + return result; +} + +// +// START Count Orders ... +// +// +// Count Open Positions ... +int CountOpenTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if (OrderSymbol() == _Symbol) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Long Positions ... +int CountOpenLongTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_BUY + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Short Positions ... +int CountOpenShortTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_SELL + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} +// +// END Count Orders ... +// + +// +// START Close Orders ... +// +// +// Close All Open Trades ... +bool CloseAllTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + + // + return result; +} + +// +bool CloseAllProviderLongTrades( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal(); + + // + if (signal.provider == provider) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Long Trades ... +bool CloseAllLongTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Long Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Short Trades ... +bool CloseAllShortTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (!isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Short Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In Profit Trades ... +bool CloseAllInProfitTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit > 0 + && profit > 50 * _Point + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InProfit Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In DrawDown Trades ... +bool CloseAllInDrawDownTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if (profit < 0) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close Biggest In DrawDown Trades ... +bool CloseBiggestDrawDownTrade() { + // + // Loop through all Positions ... + bool result = false; + double drawDown = 0; + + // + // Find Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) > drawDown + ) { + drawDown = profit; + } + } + } + } + + // + // Close Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) >= drawDown + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Max InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Long Time Trades ... +bool CloseAllLongTimeTrades( + const int passedCandles +) { + // + bool result = false; + + // + if (passedCandles <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + + // + if ( + openBarIndex - currentBarIndex >= passedCandles + || ( + profit > 0.5 + && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 3) + ) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Long Time issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } else if ( + openTrades > 0 + && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 2) + ) { + // result = CloseAllInProfitTrades(); + // && CloseBiggestDrawDownTrade(); + } + } + } + } + + // + return result; +} + +// +// Close all trades which passed Maximum Drawdown ... +bool CloseAllMaximumDrawDownPassedTrades( + const double maxDrDownPercentPerPTrade +) { + // + if ( + initialBalance <= 0 + || maxDrDownPercentPerPTrade <= 0 + ) { + return false; + } + + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double maxAllowedDrawDown = -1 * (initialBalance * maxDrDownPercentPerPTrade); + + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + if ( + profit < 0 + && MathAbs(profit) >= MathAbs(maxAllowedDrawDown) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Maximum DarwDown issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Trades Which Opens before Specified Length ... +bool CloseAllTradesWhichOpenInPastMarketLength( + const int marketLen +) { + // + bool result = false; + + // + if (marketLen <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + + // + if (openBarIndex <= currentBarIndex + marketLen) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Market Reverse issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } else if (openTrades > 0) { + // + // Close all InProfit Trdes and Biggest InDrawDown Trades ... + // result = CloseAllInProfitTrades(); + // && CloseBiggestDrawDownTrade(); + } + } + } + } + + // + return result; +} +// +// END Close Orders ... +// + +// +// START Modify Orders ... +// +// +void ModifyAllPriceLesserOpenTrades( + const XSignal &signal +) { + // + // Loop through all Open Trades ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + double takeProfit = OrderTakeProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // When new Signal Comming with price less than + // currently open trade and tp less than currently + // open trade, this means a market change happens ... + // here we can Close InProfit Trades or Modify Trades TP ... + if ( + openPrice < signal.entry + && takeProfit > signal.tp + ) { + bool result = OrderModify( + ticket, + openPrice, + signal.sl, + signal.tp, + clrYellow + ); + } + } + } + } +} + +// +void ModifyOpenTradesBasedOnCurrentTrade( + const XSignal &signal +) { + // + ModifyAllPriceLesserOpenTrades(signal); +} +// +// END Modify Orders ... +// +// +// END Orders Functions ... +// + +// +// START Signal Conditions ... +// +// +// Clear Signal Conditions ... +void ClearSignalConditions() { + // + ClearLongSignalConditions(); + ClearShortSignalConditions(); +} + +// +// Clear all Conditions Waiter for Long Signals ... +void ClearLongSignalConditions() { + // + ClearXLongSignalConditions(); + // + // ClearOSCLongSignalConditions(); + // ClearCCILongSignalConditions(); + // ClearSHPLongSignalConditions(); + // ClearXRMALongSignalConditions(); + // // + // ClearXMASCLongSignalConditions(); + // ClearXMAMCLongSignalConditions(); + // ClearXMAMMLongSignalConditions(); +} + +// +// Clear all Conditions Waiter for Short Signals ... +void ClearShortSignalConditions() { +} +// +// END Signal Conditions ... +// diff --git a/Bkp/Used/14020425/21-00/Libraries/x-saherelm.x.signal.lib.mq4 b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.x.signal.lib.mq4 new file mode 100644 index 0000000..3863381 --- /dev/null +++ b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.x.signal.lib.mq4 @@ -0,0 +1,676 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 X Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// X Based Signal Conditions ... +struct XSignalConditions { + datetime startTime; + datetime signalTime; +}; + +// +static XSignalConditions xLongConds; +static XSignalConditions xShortConds; + +// +static bool xCloseLongTrades = false; +static bool xWaitForLongSignals = true; +static datetime xWaitForLongSignalChangeTime; + +// +static bool xWaitForShortSignals = true; +static bool xCloseShortTrades = false; + +// +bool isLastTrendUp = false; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long Signal Conditions ... +void CheckXLongSignalConditions( + const int bar_index, + const int marketLen, + const XState &states[], + // + const double smoother = 5 +) { + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // // + // bool isCrossUnder = + // states[1].osc.fast < states[1].osc.slow + // && !(states[2].osc.fast < states[2].osc.slow) + // ; + + // // + // bool isCrossOver = + // states[1].osc.fast > states[1].osc.slow + // && !(states[2].osc.fast > states[2].osc.slow) + // ; + + // + XOHCL pCandle = GetCandleModel(1); + + // // + // bool isTrendingUp = + // pCandle.low > states[0].bnd.high + // && pCandle.high > states[0].bnd.high; + + // // + // bool isTrendingDown = + // pCandle.high < states[0].bnd.low + // && pCandle.low < states[0].bnd.low; + + // + bool isTrendingUp = + states[1].bnd.open < states[1].bnd.close + && !(states[2].bnd.open < states[2].bnd.close) + ; + + // + bool isTrendingDown = + states[1].bnd.open > states[1].bnd.close + && !(states[2].bnd.open > states[2].bnd.close) + ; + + // + bool isCrossUnder = + isTrendingDown + && !isTrendingUp + ; + + // + bool isCrossOver = + isTrendingUp + && !isTrendingDown + ; + + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + if (xWaitForLongSignals) { + // + bool isLCFastOnTrendingUpTouchLowestLow = + // + // LC Trending Up ... + states[1].lc.fast > states[1].lc.slow + && states[2].lc.fast > states[2].lc.slow + // + // LC Fast Touch Market Lowest Low ... + && states[1].lc.fast > states[1].mkt.lowestLow + && !(states[2].lc.fast > states[2].mkt.lowestLow) + ; + + // + bool isMCSlowCrossOverBNDHigh = + states[1].mc.fast > states[1].mc.slow + && states[1].mc.slow > states[1].bnd.high + && !(states[2].mc.slow > states[2].bnd.high) + ; + + // + // Disable Long Trade Handlers ... + if ( + isMCSlowCrossOverBNDHigh + || isLCFastOnTrendingUpTouchLowestLow + ) { + // + xWaitForLongSignals = false; + xWaitForLongSignalChangeTime = TimeCurrent(); + LogMessage("Disable Long: " + TimeCurrent()); + } + } else { + // + bool isAllTrendingUp = + // + // SC ... + states[1].sc.fast > states[1].sc.slow + // + // MC ... + && states[1].mc.fast > states[1].mc.slow + && !(states[2].mc.fast > states[2].mc.slow) + // + // LC ... + && states[1].lc.fast > states[1].lc.slow + ; + + // + int lastWaitChangeBarIndex = iBarShift( + _Symbol, + _Period, + xWaitForLongSignalChangeTime + ); + + // + // Enable Long Trade Handlers ... + if ( + isAllTrendingUp + && lastWaitChangeBarIndex - bar_index >= marketLen + ) { + xWaitForLongSignals = true; + LogMessage("Enable Long: " + TimeCurrent()); + } + } + + // + if ( + isCrossUnder + && xLongConds.startTime == 0 + ) { + // + xLongConds.startTime = barTime; + return; + } + + // + if ( + isCrossOver + && xLongConds.startTime > 0 + && xLongConds.signalTime == 0 + ) { + // + xLongConds.signalTime = barTime; + return; + } +} + +// +// Check and Fill Short Signal Conditions ... +void CheckXShortSignalConditions( + const int bar_index, + const int marketLen, + const XState &states[], + // + const double smoother = 5 +) { + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + bool isCrossUnder = + states[1].osc.fast < states[1].osc.slow + && !(states[2].osc.fast < states[2].osc.slow) + ; + + // + bool isCrossOver = + states[1].osc.fast > states[1].osc.slow + && !(states[2].osc.fast > states[2].osc.slow) + ; + + // + if ( + isCrossOver + && xShortConds.startTime == 0 + ) { + // + xShortConds.startTime = barTime; + return; + } + + // + if ( + isCrossUnder + && xShortConds.startTime > 0 + && xShortConds.signalTime == 0 + ) { + // + xShortConds.signalTime = barTime; + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r, // Risk to Reward ratio ... + const XState &states[], + // + const double smoother = 5 +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + if (requestLong) { + // + if ( + !ValidateXLongConditions( + marketLen, + states, + smoother + ) + ) { + return result; + } + } else { + // + if ( + !ValidateXShortConditions( + marketLen, + states, + smoother + ) + ) { + return result; + } + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double askPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double bidPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double entryPrice = requestLong ? + askPrice : + bidPrice; + + // + double exitPrice = requestLong ? + bidPrice : + askPrice; + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + GetMarketLowestLow( + bar_index, + marketLen + ); + + // + double hh = + GetMarketHighestHigh( + bar_index, + marketLen + ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = requestLong ? + MathMin(openPrice, closePrice) - ll : + hh - MathMax(openPrice, closePrice); + double reward = risk * r2r; // risk * r2r; // 300 * _Point; + // if (risk > (500 * _Point)) { + // reward = 300 * _Point; + // } + + // + double sl = 0; // ll; + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = type; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_XXX_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XXX_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXLongConditions( + const int marketLen, + const XState &states[], + // + const double smoother = 5 +) { + // + bool isConditionsFilled = + xLongConds.startTime > 0 + && xLongConds.signalTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.signalTime + ); + + // + isBLFilled = + // + xLongConds.signalTime > xLongConds.startTime + && MathAbs(signalBarIndex - startBarIndex) > 2 + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXLongSignalConditions(); + } + + // + return result; +} + +bool ValidateXShortConditions( + const int marketLen, + const XState &states[], + // + const double smoother = 5 +) { + // + bool isConditionsFilled = + xShortConds.startTime > 0 + && xShortConds.signalTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.signalTime + ); + + // + isBLFilled = + // + xShortConds.signalTime > xShortConds.startTime + && MathAbs(signalBarIndex - startBarIndex) > 2 + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXShortSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXLongSignalConditions() { + // + xLongConds.startTime = 0; + xLongConds.signalTime = 0; +} + +// +// Clear Short Signal Conditions for New One ... +void ClearXShortSignalConditions() { + // + xShortConds.startTime = 0; + xShortConds.signalTime = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForXSignals( + const XSignal &signal, + const XState &states[], + const int marketLen, + // + double smoother = 100 +) { + // + bool result = false; + + // + bool isSCTrendUp = + states[1].sc.fast > states[1].sc.slow + && states[2].sc.fast > states[2].sc.slow; + + // // + // bool isSCTrendDown = + // states[1].sc.fast < states[1].sc.slow + // && states[2].sc.fast < states[2].sc.slow; + + // + bool isMCTrendUp = + states[1].mc.fast > states[1].mc.slow + && states[2].mc.fast > states[2].mc.slow; + + // // + // bool isMCTrendDown = + // states[1].mc.fast < states[1].mc.slow + // && states[2].mc.fast < states[2].mc.slow; + + // + bool isLCTrendUp = + states[1].lc.fast > states[1].lc.slow + && states[2].lc.fast > states[2].lc.slow; + + // // + // bool isLCTrendDown = + // states[1].lc.fast < states[1].lc.slow + // && states[2].lc.fast < states[2].lc.slow; + + // // + // bool isTrendingUp = + // pCandle.low > states[0].bnd.high + // && pCandle.high > states[0].bnd.high; + + // // + // bool isTrendingDown = + // pCandle.high < states[0].bnd.low + // && pCandle.low < states[0].bnd.low; + + // // + // if (isTrendingUp && !isTrendingDown) { + // isLastTrendUp = true; + // } else if (isTrendingDown && !isTrendingUp) { + // isLastTrendUp = false; + // } + + // // + // if (isLastTrendUp) { + // // + // LogMessage( + // StringConcatenate( + // "isLastTrendUp: ", isLastTrendUp + // ) + // ); + // } + + // + XOHCL pCandle = GetCandleModel(1); + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + result = + // + true + // + && isSCTrendUp + && isMCTrendUp + && isLCTrendUp + // + && + ( + pCandle.high < states[1].longCycleHighestHigh + && !(MathAbs(states[1].longCycleHighestHigh - pCandle.high) < 20 * _Point) + ) + // + && ( + states[1].lc.fast > states[1].mc.fast + && states[1].lc.slow > states[1].mc.fast + ? + states[1].lc.slow < states[1].mkt.lowestLow + : + true + ) + // + // && signal.entry <= states[1].mkt.highestOpen + // // + // && ( + // ( + // states[1].mc.slow < states[1].bnd.low + // && states[1].mc.fast < MathMin(states[1].bnd.open, states[1].bnd.close) + // ) || ( + // states[1].lc.fast > states[1].bnd.low + // && states[1].lc.fast > states[1].mc.fast + // ) + // ) + // && MathAbs(states[1].mc.fast - states[1].bnd.low) > 50 * _Point + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + result = + false + ; + } + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020425/21-00/Libraries/x-saherelm.xma.mc.signal.lib.mq4 b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.xma.mc.signal.lib.mq4 new file mode 100644 index 0000000..13b787e --- /dev/null +++ b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.xma.mc.signal.lib.mq4 @@ -0,0 +1,490 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 XMA Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// XMA Based Signal Conditions ... +struct XMAMCLongSignalConditions { + // + datetime mcFastCrossUnderSlowTime; + double crossUnderMCFast; + double crossUnderMCSlow; + + // + datetime mcFastCrossOverSlowTime; + double crossOverMCFast; + double crossOverMCSlow; + + // + datetime mcFastBiggerThanCrossUnderSlowTime; +}; + +// +static XMAMCLongSignalConditions xmaMCLongConds; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill CC Signal Conditions ... +void CheckXMAMCLongSignalConditions( + const int bar_index, + const int marketLen, + // + double stp, + double mxm, + // + int scFMult, + int scSMult, + // + int mcFMult, + int mcSMult +) { + // + XCycleState mcs[]; + int positionsMarketLen = bar_index + marketLen; + + // + // Retrieve Bar Time ... + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Resize Arrays ... + ArrayResize( + mcs, + marketLen + ); + + // + int index = 0; + for (int i = bar_index; i < positionsMarketLen; i++) { + // + XCycleState mc = GetXMAMC( + i, + marketLen, + mcFMult, + mcSMult + ); + mcs[index] = mc; + + // + index++; + } + + // + bool isMCFastCrossUnderSlow = + mcs[0].fast < mcs[0].slow + && !(mcs[1].fast <= mcs[1].slow) + ; + bool isMCFastCrossOverSlow = + mcs[0].fast > mcs[0].slow + && !(mcs[1].fast >= mcs[1].slow) + ; + + // + if ( + isMCFastCrossUnderSlow + && xmaMCLongConds.mcFastCrossUnderSlowTime == 0 + ) { + // + xmaMCLongConds.crossUnderMCFast = mcs[0].fast; + xmaMCLongConds.crossUnderMCSlow = mcs[0].slow; + xmaMCLongConds.mcFastCrossUnderSlowTime = barTime; + return; + } + + // + if ( + isMCFastCrossUnderSlow + && xmaMCLongConds.mcFastCrossUnderSlowTime > 0 + ) { + // + ClearXMAMCLongSignalConditions(); + + // + xmaMCLongConds.crossUnderMCFast = mcs[0].fast; + xmaMCLongConds.crossUnderMCSlow = mcs[0].slow; + xmaMCLongConds.mcFastCrossUnderSlowTime = barTime; + return; + } + + // + if ( + isMCFastCrossOverSlow + && xmaMCLongConds.mcFastCrossUnderSlowTime > 0 + && xmaMCLongConds.mcFastCrossOverSlowTime == 0 + ) { + // + xmaMCLongConds.crossOverMCFast = mcs[0].fast; + xmaMCLongConds.crossOverMCSlow = mcs[0].slow; + xmaMCLongConds.mcFastCrossOverSlowTime = barTime; + return; + } + + // + if ( + xmaMCLongConds.mcFastCrossUnderSlowTime > 0 + && xmaMCLongConds.mcFastCrossOverSlowTime > 0 + && mcs[0].fast > xmaMCLongConds.crossUnderMCSlow + && xmaMCLongConds.mcFastBiggerThanCrossUnderSlowTime == 0 + ) { + // + xmaMCLongConds.mcFastBiggerThanCrossUnderSlowTime = barTime; + return; + } +} + +// +// Convert XMA Long Signal Conditions to XSignal ... +XSignalRequest GenerateXMAMCLongSignal( + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r, // Risk to Reward ratio ... + const double shpDetectMult, + const double smoother = 50 +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if ( + !ValidateXMAMCLongConditions( + marketLen, + shpDetectMult, + smoother + ) + ) { + return result; + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double entryPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double exitPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + GetMarketLowestLow( + bar_index, + 3 + ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = MathMin(openPrice, closePrice) - ll; + double reward = risk * r2r; + + // + double sl = 0; + double tp = entryPrice + reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = X_SIGNAL_LONG; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_XMA_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = X_SIGNAL_LONG; + result.provider = X_XMA_PROVIDER; + + // + return result; +} + +// +// Validate XMA Signal Conditions ... +bool ValidateXMAMCLongConditions( + const int marketLen, + const double shpDetectMult, + const double smoother = 50 +) { + // + bool isConditionsFilled = + xmaMCLongConds.crossOverMCSlow > 0 + && xmaMCLongConds.crossOverMCFast > 0 + && xmaMCLongConds.crossUnderMCFast > 0 + && xmaMCLongConds.crossUnderMCSlow > 0 + && xmaMCLongConds.mcFastCrossOverSlowTime != 0 + && xmaMCLongConds.mcFastCrossUnderSlowTime != 0 + && xmaMCLongConds.mcFastBiggerThanCrossUnderSlowTime != 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int crossUnderBarIndex = iBarShift( + _Symbol, + _Period, + xmaMCLongConds.mcFastCrossUnderSlowTime + ); + + // + int crossOverAndBiggerBarIndex = iBarShift( + _Symbol, + _Period, + xmaMCLongConds.mcFastBiggerThanCrossUnderSlowTime + ); + + // + int cycleMarketLen = MathMin( + MathAbs(crossUnderBarIndex - crossOverAndBiggerBarIndex), + marketLen * 2 + ); + double hh = GetMarketHighestHigh( + crossOverAndBiggerBarIndex, + cycleMarketLen + ); + double ll = GetMarketLowestLow( + crossOverAndBiggerBarIndex, + cycleMarketLen + ); + + // + double high = iHigh( + _Symbol, + _Period, + crossOverAndBiggerBarIndex + ); + double pcHigh = iHigh( + _Symbol, + _Period, + crossOverAndBiggerBarIndex + 1 + ); + + // + double diff = (hh - ll); + double shpValue = shpDetectMult * _Point; + + // + bool isPriceRegular = + // + true + // + && + ( + diff < shpValue + || diff < shpValue - (smoother * _Point) + ) + && + !( + high == hh + || pcHigh == hh + || MathAbs(hh - high) < (smoother * _Point) + || MathAbs(hh - pcHigh) < (smoother * _Point) + ) + ; + + // + // LogMessage("Price Regular: " + isPriceRegular); + + // + isBLFilled = + isPriceRegular + && xmaMCLongConds.mcFastCrossUnderSlowTime < xmaMCLongConds.mcFastCrossOverSlowTime + && xmaMCLongConds.mcFastBiggerThanCrossUnderSlowTime >= xmaMCLongConds.mcFastCrossUnderSlowTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXMAMCLongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXMAMCLongSignalConditions() { + // + xmaMCLongConds.mcFastCrossUnderSlowTime = 0; + xmaMCLongConds.crossUnderMCFast = 0; + xmaMCLongConds.crossUnderMCSlow = 0; + + // + xmaMCLongConds.mcFastCrossOverSlowTime = 0; + xmaMCLongConds.crossOverMCFast = 0; + xmaMCLongConds.crossOverMCSlow = 0; + + // + xmaMCLongConds.mcFastBiggerThanCrossUnderSlowTime = 0; +} + +// +// Check XMA State for Long Signals ... +bool IsReadyForXMAMCLongSignals( + const XSignal &signal, + const XState &states[], + const int marketLen +) { + // + bool result = false; + + // + int countRangedCandles = 0; + bool isMarketRanging = false; + for (int i = 1; i < marketLen; i++) { + // + double high = iHigh( + _Symbol, + _Period, + i + ); + + // + double low = iLow( + _Symbol, + _Period, + i + ); + + // + bool isRanging = + // + high > states[i].mc.fast + && high > states[i].mc.slow + // + && low < states[i].mc.fast + && low < states[i].mc.slow + ; + if (isRanging) { + countRangedCandles++; + } + } + + // + XStateInfo info = ParseXMAStates(states); + double mmSlope = GetSlope( + 1, + states[1].marketMiddleage, + 2, + states[0].marketMiddleage + ); + double mmSlope1 = GetSlope( + 1, + states[2].marketMiddleage, + 2, + states[1].marketMiddleage + ); + double mmSlopeDiff = mmSlope - mmSlope1; + + // + isMarketRanging = countRangedCandles > 0; + + // + result = + // + true + // + && mmSlope > 0 + && mmSlope1 > 0 + && mmSlopeDiff > 0 + && !isMarketRanging + && states[0].marketMiddleage < info.mmMax + ; + // if (result) { + // LogMessage("mmSlope: " + mmSlope + ", mmSlope1: " + mmSlope1 + ", Diff: " + mmSlopeDiff); + // } + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020425/21-00/Libraries/x-saherelm.xma.mm.signal.lib.mq4 b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.xma.mm.signal.lib.mq4 new file mode 100644 index 0000000..d883803 --- /dev/null +++ b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.xma.mm.signal.lib.mq4 @@ -0,0 +1,338 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 XMA Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// XMA Based Signal Conditions ... +struct XMAMMLongSignalConditions { + // + datetime crossUnderTime; + + // + datetime crossOverTime; +}; + +// +static XMAMMLongSignalConditions xmaMMLongConds; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill CC Signal Conditions ... +void CheckXMAMMLongSignalConditions( + const int bar_index, + const int marketLen, + // + double stp, + double mxm, + // + int scFMult, + int scSMult, + // + int mcFMult, + int mcSMult, + // + int lcFMult, + int lcSMult, + // + const double smoother = 5 +) { + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XState states[]; + ArrayResize( + states, + marketLen + ); + + // + int index = 0; + for (int i = bar_index; i < marketLen; i++) { + // + XState state = GetXState( + i, + marketLen, + // + stp, + mxm, + scFMult, + scSMult, + mcFMult, + mcSMult, + lcFMult, + lcSMult + ); + + // + states[index] = state; + + // + index++; + } + + // + bool isCrossUnder = + states[1].marketMiddleage < states[1].sc.fast + && !(states[2].marketMiddleage < states[2].sc.fast) + ; + + // + bool isCrossOver = + states[1].marketMiddleage > states[1].sc.fast + && !(states[2].marketMiddleage > states[2].sc.fast) + ; + + // + if ( + isCrossUnder + && xmaMMLongConds.crossUnderTime == 0 + ) { + // + xmaMMLongConds.crossUnderTime = barTime; + return; + } + + // + if ( + isCrossOver + && xmaMMLongConds.crossUnderTime > 0 + && xmaMMLongConds.crossOverTime == 0 + ) { + // + xmaMMLongConds.crossOverTime = barTime; + return; + } +} + +// +// Convert XMA Long Signal Conditions to XSignal ... +XSignalRequest GenerateXMAMMLongSignal( + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r // Risk to Reward ratio ... +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if (!ValidateXMAMMLongConditions()) { + return result; + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double entryPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double exitPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + GetMarketLowestLow( + bar_index, + marketLen + ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = MathMin(openPrice, closePrice) - ll; + double reward = 300 * _Point; // risk * r2r; + + // + double sl = 0; // entryPrice - (300 * _Point); // ll; + double tp = entryPrice + reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = X_SIGNAL_LONG; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_XMA_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = X_SIGNAL_LONG; + result.provider = X_XMA_PROVIDER; + + // + return result; +} + +// +// Validate XMA Signal Conditions ... +bool ValidateXMAMMLongConditions() { + // + bool isConditionsFilled = + true + && xmaMMLongConds.crossOverTime > 0 + && xmaMMLongConds.crossUnderTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int crossOverBarIndex = iBarShift( + _Symbol, + _Period, + xmaMMLongConds.crossOverTime + ); + + // + int crossUnderBarIndex = iBarShift( + _Symbol, + _Period, + xmaMMLongConds.crossUnderTime + ); + + // + isBLFilled = + true + // + && (crossUnderBarIndex - crossOverBarIndex) > 5 + // + && xmaMMLongConds.crossOverTime > xmaMMLongConds.crossUnderTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXMAMMLongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXMAMMLongSignalConditions() { + // + xmaMMLongConds.crossOverTime = 0; + xmaMMLongConds.crossUnderTime = 0; +} + +// +// Check XMA State for Long Signals ... +bool IsReadyForXMAMMLongSignals( + const XSignal &signal, + const XState &states[], + const int marketLen +) { + // + bool result = false; + + // + result = + // + true + // + // && states[0].parabolicSAR < states[0].marketMiddleage + // && !( + // states[0].parabolicSAR < states[0].mc.fast + // && states[0].parabolicSAR < states[0].mc.slow + // ) + // + // && states[0].mc.fast > states[0].mc.slow + // + // && MathAbs(states[0].mc.fast - states[0].mc.slow) > (150 * _Point) + ; + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020425/21-00/Libraries/x-saherelm.xma.sc.signal.lib.mq4 b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.xma.sc.signal.lib.mq4 new file mode 100644 index 0000000..218759c --- /dev/null +++ b/Bkp/Used/14020425/21-00/Libraries/x-saherelm.xma.sc.signal.lib.mq4 @@ -0,0 +1,360 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 XMA Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// XMA Based Signal Conditions ... +struct XMASCLongSignalConditions { + // + datetime scFastCrossUnderSlowTime; + double crossUnderSCFast; + double crossUnderSCSlow; + + // + datetime scFastCrossOverSlowTime; + double crossOverSCFast; + double crossOverSCSlow; + + // + datetime scFastBiggerThanCrossUnderSlowTime; +}; + +// +static XMASCLongSignalConditions xmaSCLongConds; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill CC Signal Conditions ... +void CheckXMASCLongSignalConditions( + const int bar_index, + const int marketLen, + // + double stp, + double mxm, + // + int scFMult, + int scSMult, + // + int mcFMult, + int mcSMult +) { + // + XCycleState scs[]; + int positionsMarketLen = bar_index + marketLen; + + // + // Retrieve Bar Time ... + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Resize Arrays ... + ArrayResize( + scs, + marketLen + ); + + // + int index = 0; + for (int i = bar_index; i < positionsMarketLen; i++) { + // + XCycleState sc = GetXMASC( + i, + marketLen, + scFMult, + scSMult + ); + scs[index] = sc; + + // + index++; + } + + // + bool isSCFastCrossUnderSlow = + scs[0].fast < scs[0].slow + && !(scs[1].fast <= scs[1].slow) + ; + bool isSCFastCrossOverSlow = + scs[0].fast > scs[0].slow + && !(scs[1].fast >= scs[1].slow) + ; + + // + if ( + isSCFastCrossUnderSlow + && xmaSCLongConds.scFastCrossUnderSlowTime == 0 + ) { + // + xmaSCLongConds.crossUnderSCFast = scs[0].fast; + xmaSCLongConds.crossUnderSCSlow = scs[0].slow; + xmaSCLongConds.scFastCrossUnderSlowTime = barTime; + return; + } + + // + if ( + isSCFastCrossOverSlow + && xmaSCLongConds.scFastCrossUnderSlowTime > 0 + && xmaSCLongConds.scFastCrossOverSlowTime == 0 + ) { + // + xmaSCLongConds.crossOverSCFast = scs[0].fast; + xmaSCLongConds.crossOverSCSlow = scs[0].slow; + xmaSCLongConds.scFastCrossOverSlowTime = barTime; + return; + } + + // + if ( + xmaSCLongConds.scFastCrossUnderSlowTime > 0 + && xmaSCLongConds.scFastCrossOverSlowTime > 0 + && scs[0].fast > xmaSCLongConds.crossUnderSCSlow + && xmaSCLongConds.scFastBiggerThanCrossUnderSlowTime == 0 + ) { + // + xmaSCLongConds.scFastBiggerThanCrossUnderSlowTime = barTime; + return; + } + + // + if ( + isSCFastCrossUnderSlow + && xmaSCLongConds.scFastCrossUnderSlowTime > 0 + && xmaSCLongConds.scFastCrossOverSlowTime > 0 + ) { + // + ClearXMASCLongSignalConditions(); + return; + } +} + +// +// Convert XMA Long Signal Conditions to XSignal ... +XSignalRequest GenerateXMASCLongSignal( + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r // Risk to Reward ratio ... + // + // const double shpDetectMultiplier +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if (!ValidateXMASCLongConditions()) { + return result; + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double entryPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double exitPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + GetMarketLowestLow( + bar_index, + marketLen + ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + 1 + ); + + // // + // double sharpDetectValue = shpDetectMultiplier * _Point; + // double lowPrice = iLow( + // _Symbol, + // _Period, + // bar_index + 1 + // ); + + // + double risk = MathMin(openPrice, closePrice) - ll; + double reward = risk * r2r; + + // + double sl = 0; + double tp = entryPrice + reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = X_SIGNAL_LONG; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_XMA_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = X_SIGNAL_LONG; + result.provider = X_XMA_PROVIDER; + + // + return result; +} + +// +// Validate XMA Signal Conditions ... +bool ValidateXMASCLongConditions() { + // + bool isConditionsFilled = + xmaSCLongConds.crossOverSCSlow > 0 + && xmaSCLongConds.crossOverSCFast > 0 + && xmaSCLongConds.crossUnderSCFast > 0 + && xmaSCLongConds.crossUnderSCSlow > 0 + && xmaSCLongConds.scFastCrossOverSlowTime != 0 + && xmaSCLongConds.scFastCrossUnderSlowTime != 0 + && xmaSCLongConds.scFastBiggerThanCrossUnderSlowTime !=0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + isBLFilled = + xmaSCLongConds.crossOverSCFast > xmaSCLongConds.crossUnderSCSlow + && xmaSCLongConds.scFastCrossUnderSlowTime < xmaSCLongConds.scFastCrossOverSlowTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXMASCLongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXMASCLongSignalConditions() { + // + xmaSCLongConds.crossUnderSCFast = 0; + xmaSCLongConds.crossUnderSCSlow = 0; + xmaSCLongConds.scFastCrossUnderSlowTime = 0; + + // + xmaSCLongConds.crossOverSCFast = 0; + xmaSCLongConds.crossOverSCSlow = 0; + xmaSCLongConds.scFastCrossOverSlowTime = 0; + + // + xmaSCLongConds.scFastBiggerThanCrossUnderSlowTime = 0; +} + +// +// Check XMA State for Long Signals ... +bool IsReadyForXMASCLongSignals( + const XSignal &signal, + const XState &states[], + const int marketLen +) { + // + bool result = false; + + // + result = + // + true + // + && states[0].sc.fast > states[0].sc.slow + && states[1].sc.fast > states[1].sc.slow + ; + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020425/Experts/x-saherelm.ea.mq4 b/Bkp/Used/14020425/Experts/x-saherelm.ea.mq4 new file mode 100644 index 0000000..26c92ca --- /dev/null +++ b/Bkp/Used/14020425/Experts/x-saherelm.ea.mq4 @@ -0,0 +1,780 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XST Strategy Expert Advisor +// --------------------------------------------- +// saherelm implementation of strategy expert advisor ... +// in this EA, we try to combine multiple tools, to ashive best +// results ... +// +// ShortName: XST +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +989121694056 +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XST Strategy Expert Advisor" +#property strict + +// +// START Inputs ... +// +// +// Signal Prefixe ... +input string signalPrefix = "XST"; // Signal Prefix + +// +// Signal Draw Specifications ... +input string bullishSignalLabel = "X_BUY"; // Bullish Signal Label +input color bullishSignalColor = clrAqua; // Bullish Signal Color + +// +input string bearishSignalLabel = "X_SELL"; // Bearish Signal Label +input color bearishSignalColor = clrFuchsia; // Bearish Signal Color + +// +input color signalEntryColor = clrAquamarine; // Signal Entry Ptice Color +input color signalSLColor = clrRed; // Signal SL Color +input color signalTPColor = clrGreen; // Signal TP Color + +// +// Trade ... +input bool allowTrade = true; // Allow Trade Based on given Signals +input bool allowLongTrades = true; // Allow Long Trades +input bool allowShortTrades = false; // Allow Short Trades + +// +// Market Specification Inpouts ... +input int marketLength = 7; // Market Length +input double riskToRewardRatio = 1.5; // Risk to Reward Ratio +// input double maxTPMultiplier = 1000; // Max Allowed TP + +// +// Alerts ... +input bool alertEvents = true; // Alert Events +input bool alertPositions = true; // Alert Positions +input bool longPositionAlerts = true; // Alert Long Positions +input bool shortPositionAlerts = true; // Alert Short Positions + +// +// Alert Types ... +input bool terminalAlert = false; // Terminal Alert +input bool pushAlert = false; // Push Notification Alerts + +// +// Balance and Finanical Specifications ... +input double lotsPerTradePercent = 0.00001; // Lots Per Trade Percent +input int maxOpenTrades = 4; // Maximum Open Trade +input double maxDrawdownPercentPerPTrade = 0.05; // Maximum DrawDown Per Trade +input double minBalancePercent = 0.5; // Minimum Balance for Trading +input double maxEquityPercent = 0.1; // Maximum Trade Equity +input int closeAllOpenTradesAfterCandle = 408; // Close All Open Trades After Passed Candles +input bool closeAllInProfitOpenTradesWhenMaxOpenTradesReached = false; // Close All In Profit Open Trades When Max Open Trades Reached and New Signal Income + +// +// Indicators ... +// +// CCI Inputs ... +input double step = 0.01; // SAR Step +input double maximum = 0.1; // SAR Maximum + +// +// XMA Inputs ... +// +input int shortCycleFastMultiplier = 2; // Short Cycle Fast Multiplier +input int shortCycleSlowMultiplier = 4; // Short Cycle Slow Multiplier +input int mediumCycleFastMultiplier = 6; // Medium Cycle Fast Multiplier +input int mediumCycleSlowMultiplier = 12; // Medium Cycle Slow Multiplier +input int longCycleFastMultiplier = 36; // Long Cycle Fast Multiplier +input int longCycleSlowMultiplier = 72; // Long Cycle Slow Multiplier + +// +// SHPD Indicator ... +input double sharpDetectMultiplier = 800; // Sharp Detect Multiplier +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +int lastSignalledBar = 0; + +// +bool waitForLongSignals = true; +bool closeLongTrades = false; + +// +bool waitForShortSignals = true; +bool closeShortTrades = false; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.signal.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Validate Inputs ... + bool inputsNotValiid = + // + // MARKET ... + marketLength < 0 + || riskToRewardRatio < 0 + // + // EA ... + || lotsPerTradePercent < 0 + || maxOpenTrades <= 0 + || maxDrawdownPercentPerPTrade < 0 + || minBalancePercent < 0 + || maxEquityPercent < 0 + || marketLength < 0 + // + // XMA ... + // + // Validate Short Cycle ... + || shortCycleFastMultiplier <= 0 + || shortCycleSlowMultiplier <= 0 + || shortCycleFastMultiplier >= shortCycleSlowMultiplier + // + // Validate Medium Cycle ... + || mediumCycleFastMultiplier <= 0 + || mediumCycleSlowMultiplier <= 0 + || mediumCycleFastMultiplier >= mediumCycleSlowMultiplier + // + // Validate Long Cycle ... + || longCycleFastMultiplier <= 0 + || longCycleSlowMultiplier <= 0 + || longCycleFastMultiplier >= longCycleSlowMultiplier + // + // Validate Series of Multipliers ... + || shortCycleFastMultiplier >= mediumCycleFastMultiplier + || mediumCycleFastMultiplier >= longCycleFastMultiplier + ; + + // + if (inputsNotValiid) { + return INIT_PARAMETERS_INCORRECT; + } + + // + totalSignals = 0; + totalLongSignals = 0; + totalShortSignals = 0; + + // + initialBalance = 0; + + // + // START Define Array Series ... + // + // + // END Define Array Series ... + // + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST"; + + // // + // // Set Event Timer on One Seccond ... + // bool isEventSet = EventSetTimer(1); + // if (!isEventSet) { + // LogMessage("Error: " + GetLastError()); + // return INIT_FAILED; + // } + + // + ClearSignalConditions(); + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + // Killing Event Timer ... + EventKillTimer(); +} + +// +// Ticker Event Handler ... +void OnTick() { + // + isNewDay = IsNewDay(); + if (isNewDay) { + // + LogMessage( + StringConcatenate( + "New Day: ", TimeCurrent() + ) + ); + } + + // + // Process Signals to Open Positions ... + ProcessSignals(); + + // + // Checking State for Signal Handling ... + CheckState(); + + // + // Process Open Positions for Trailing Stop Loss or Close ... + ProcessOpenPositions(); +} + +// +// Timer Event Handler ... +void OnTimer() { + // + CheckState(); + + // + ProcessOpenPositions(); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Check State for Signal Handling ... +void CheckState() { + // + // Here we Must to Check Market State for enable or disable + // Signal Handlers and also make dection to close all long/short + // trades ... + + // // + // closeLongTrades = xCloseLongTrades; + // waitForLongSignals = xWaitForLongSignals; + + // // + // closeShortTrades = xCloseShortTrades; + // waitForShortSignals = xWaitForShortSignals; + + // // + // xCloseLongTrades = false; + // xCloseShortTrades = false; +} + +// +// Calculate Signals and Process Based on Exists Signals ... +void ProcessSignals() { + // + XSignalRequest request = {}; + request.type = X_SIGNAL_NONE; + request.hasSignal = false; + + // + // Prevent Multiple Calculating on Same Bars ... + isNewBar = IsNewBar(); + if (isNewBar) { + countedBars++; + } + + // + if (countedBars < longCycleSlowMultiplier * marketLength) { + return; + } + + // + bool allowDoTrade = true; + + // + // Check Balance ... + if (initialBalance > 0) { + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double minimumBalanceForTrade = + balance > initialBalance + ? + minBalancePercent * balance + : + minBalancePercent * initialBalance; + + // + // Retrieve Account Equity ... + double equity = AccountInfoDouble(ACCOUNT_EQUITY); + double maxAllowedEquity = balance - (balance * maxEquityPercent); + + // + // Retrieve Free Marigin ... + double freeMargin = AccountFreeMargin(); + double maximumMariginRisk = balance - (balance * maxEquityPercent); + + // + if ( + // + // Do not Open Positions if equity not passed ... + equity < maxAllowedEquity || + // + // Do not Open Positions if free margin not passed ... + freeMargin <= maximumMariginRisk || + // + // Do not open positions if balance less than minimum ... + balance <= minimumBalanceForTrade + ) { + // + allowDoTrade = false; + + // // + // string message = StringConcatenate( + // "Trading Pause => ", + // "Balance: ", balance, + // ", Equity: ", equity, + // ", FreeMargin: ", freeMargin + // ); + + // // + // LogMessage(message); + // SendAlert(message); + } + } + + // + // Retrieve Signal Exists ... + request = GenerateSignal(0); + + // + // Prevent doing anything else, if there is no signals ... + if ( + !allowDoTrade || + !request.hasSignal || + request.type == X_SIGNAL_NONE + ) { + return; + } + + // + bool hasLongSignal = request.type == X_SIGNAL_LONG; + + // + // Check For Bot State ... + if ( + (hasLongSignal && !waitForLongSignals) + || (!hasLongSignal && !waitForShortSignals) + ) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + return; + } + + // + // Check last Signalled Bar with Counted Bars ... + // Prevent Multiple Signalling on Same Bar ... + bool isInLastSignalledBars = false; + for (int i=0; i < marketLength; i++) { + // + isInLastSignalledBars = + isInLastSignalledBars + || lastSignalledBar == countedBars - i + ; + } + if (isInLastSignalledBars) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + return; + } + + // + // increase last signalled bar ... + lastSignalledBar = countedBars; + + // + // Calculate Can Trade or not ... + allowDoTrade = allowTrade + && ( + hasLongSignal ? + allowLongTrades : + allowShortTrades + ); + + // + // Chack Maximum Open Positions ... + int openTrades = CountOpenTrades(); + if (maxOpenTrades > 0) { + // + if (openTrades >= maxOpenTrades) { + // + allowDoTrade = false; + + // + if (closeAllInProfitOpenTradesWhenMaxOpenTradesReached) { + // + // Close All In Profit Trades ... + bool hasClosedInProfitTrade = CloseAllInProfitTrades(); + if (hasClosedInProfitTrade) { + // + openTrades = CountOpenTrades(); + + // + allowDoTrade = !(openTrades >= maxOpenTrades); + } + } + + // + if (!allowDoTrade) { + // + string message = StringConcatenate( + "Trading Pause => ", + "Max Open Trades (", + maxOpenTrades, + ") reached ..." + ); + + // + LogMessage(message); + SendAlert(message); + } + } + } + + // + // Check Trading is Enable or not ... + // nothing to do if trading is disabled ... + if (!allowDoTrade) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // // + // string message = StringConcatenate( + // "Trading Not Allowed ..." + // ); + + // // + // LogMessage(message); + // SendAlert(message); + return; + } + + // + bool isPositionOpened = TradeSignal( + request.signal, + signalPrefix, + lotsPerTradePercent, + // + bullishSignalLabel, + bullishSignalColor, + bearishSignalLabel, + bearishSignalColor + ); + + // + totalSignals++; + if (hasLongSignal) { + // + totalLongSignals++; + ClearLongSignalConditions(); + } else { + // + totalShortSignals++; + ClearShortSignalConditions(); + } + + // + if (isPositionOpened) { + // + bool canAlert = + alertPositions + && ( + hasLongSignal ? + longPositionAlerts + : + shortPositionAlerts + ); + + // + if (canAlert) { + // + // Alert Message ... + string message = StringConcatenate( + "Trade on Signal ID: ", request.signal.id, + ", Entry: ", request.signal.entry, + ", TP: ", request.signal.tp + ); + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } + } + } +} + +// +// Process All Open Positions ... +void ProcessOpenPositions() { + // + // this comes from check state ... + if (closeLongTrades) { + // + closeLongTrades = false; + + // + bool isAllLongTradesClosed = CloseAllLongTrades(); + if (isAllLongTradesClosed) { + } + } + + // + // this comes from check state ... + if (closeShortTrades) { + // + closeShortTrades = false; + + // + bool isAllShortTradesClosed = CloseAllShortTrades(); + if (isAllShortTradesClosed) { + } + } + + // + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + closeAllOpenTradesAfterCandle + ); + + // + // Close Maximum DrawDown Passed Trades ... + bool hasClosedInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + maxDrawdownPercentPerPTrade + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedInDrawDownLongTrade + ) { + // + // waitForLongSignals = false; + } +} + +// +// Send Special Type of Alerts ... +void SendAlert(string message) { + // + if (!alertEvents) { + return; + } + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } +} +// +// END Functions ... +// + +// +// +// Calculate Signal ... +// in this function we calculate a signal exists in +// specific bar or not ... +XSignalRequest GenerateSignal( + const int bar_index // Bar Index ... +) { + // + // create temp result ... + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + bool hasSignal = false; + bool hasLongSignal = false; + bool hasShortSignal = false; + + // + XSignal signal = {}; + + // + // Retrieve XMA States ... + // based on medium cycle slow ... + XState states[]; + ArrayFree(states); + ArrayResize( + states, + marketLength + ); + + // + int index = 0; + for (int i = bar_index; i < bar_index + marketLength; i++) { + // + states[index] = GetXState( + i, + marketLength, + // + step, + maximum, + // + shortCycleFastMultiplier, + shortCycleSlowMultiplier, + mediumCycleFastMultiplier, + mediumCycleSlowMultiplier, + longCycleFastMultiplier, + longCycleSlowMultiplier + ); + + // + index++; + } + + // + CheckXLongSignalConditions( + bar_index, + marketLength, + states + ); + + // + CheckXShortSignalConditions( + bar_index, + marketLength, + states + ); + + // + XSignalRequest xLongSignalRequest = GenerateXSignal( + X_SIGNAL_LONG, + bar_index, + marketLength, + riskToRewardRatio, + states + ); + + // + XSignalRequest xShortSignalRequest = GenerateXSignal( + X_SIGNAL_SHORT, + bar_index, + marketLength, + riskToRewardRatio, + states + ); + + // + if (xLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXSignals( + xLongSignalRequest.signal, + states, + marketLength + ); + + // + if (isReady) { + // + hasLongSignal = true; + signal = xLongSignalRequest.signal; + } else { + ClearXLongSignalConditions(); + } + } else if (xShortSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXSignals( + xShortSignalRequest.signal, + states, + marketLength + ); + + // + if (isReady) { + // + hasShortSignal = true; + signal = xShortSignalRequest.signal; + } else { + ClearXShortSignalConditions(); + } + } + + // + hasSignal = hasLongSignal || hasShortSignal; + + // + if (!hasSignal) { + // + signal.type = X_SIGNAL_NONE; + result.type = X_SIGNAL_NONE; + } + + // + // Normalize TP, SL and Entry Price ... + signal.tp = NormalizeDouble(signal.tp, _Digits); + signal.sl = NormalizeDouble(signal.sl, _Digits); + signal.entry = NormalizeDouble(signal.entry, _Digits); + + // + result.signal = signal; + result.type = signal.type; + result.hasSignal = hasSignal; + result.provider = signal.provider; + + // + // Return Result ... + return result; +} diff --git a/Bkp/Used/14020425/Indicators/x-saherelm.adx.mq4 b/Bkp/Used/14020425/Indicators/x-saherelm.adx.mq4 new file mode 100644 index 0000000..3271a4e --- /dev/null +++ b/Bkp/Used/14020425/Indicators/x-saherelm.adx.mq4 @@ -0,0 +1,220 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center ADX Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm ADX Oscillator" +#property strict + +// +// START Inputs ... +// +input int length = 7; // Averaging Length +input ENUM_APPLIED_PRICE appliedPrice = PRICE_WEIGHTED; // Averaging Applied Price +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_separate_window + +// +#property indicator_minimum 0 +#property indicator_maximum 100 + +// +#property indicator_buffers 3 + +// +#property indicator_level1 0.0 +#property indicator_level2 50.0 +#property indicator_level3 70.0 +#property indicator_level4 100.0 +#property indicator_levelcolor clrSilver +#property indicator_levelstyle STYLE_DOT + +// +// ADX ... +#property indicator_width1 1 +#property indicator_color1 clrLightBlue +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_SOLID + +// +// Positive Direction ... +#property indicator_width2 1 +#property indicator_color2 clrLime +#property indicator_type2 DRAW_LINE +#property indicator_style2 STYLE_DOT + +// +// Negative Direction ... +#property indicator_width3 1 +#property indicator_color3 clrRed +#property indicator_type3 DRAW_LINE +#property indicator_style3 STYLE_DOT + +// +// Declare Buffers ... +#define adxBufferIndex 0 +#define positiveBufferIndex 1 +#define negativeBufferIndex 2 + +double adxBuffer[]; +double positiveBuffer[]; +double negativeBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (length < 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + IndicatorBuffers(3); + + // + SetIndexBuffer(positiveBufferIndex, positiveBuffer); + SetIndexLabel(positiveBufferIndex, "DI+"); + + // + SetIndexBuffer(negativeBufferIndex, negativeBuffer); + SetIndexLabel(negativeBufferIndex, "DI-"); + + // + SetIndexBuffer(adxBufferIndex, adxBuffer); + SetIndexLabel(adxBufferIndex, "ADX"); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, length); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Long TP ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index +) { + // + // Calculate Buffers ... + + // + // Retrieves the current ADX value ... + double adx = iADX( + _Symbol, + _Period, + length, + appliedPrice, + MODE_MAIN, + bar_index + ); + adxBuffer[bar_index] = adx; + + // + // Retrieves the current DI+ value ... + double plusDi = iADX( + _Symbol, + _Period, + length, + appliedPrice, + MODE_PLUSDI, + bar_index + ); + positiveBuffer[bar_index] = plusDi; + + // + // Retrieves the current DI- value ... + double minusDi = iADX( + _Symbol, + _Period, + length, + appliedPrice, + MODE_MINUSDI, + bar_index + ); + negativeBuffer[bar_index] = minusDi; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/Indicators/x-saherelm.ma.mq4 b/Bkp/Used/14020425/Indicators/x-saherelm.ma.mq4 new file mode 100644 index 0000000..e3a5737 --- /dev/null +++ b/Bkp/Used/14020425/Indicators/x-saherelm.ma.mq4 @@ -0,0 +1,173 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MA Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 MA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Fast MA ... +input int maLength = 20; // MA Length +input int maShift = 0; // MA Shift +input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method +input ENUM_APPLIED_PRICE maAppliedPrice = PRICE_CLOSE; // MA Applied Price + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 1 + +// +#property indicator_plots 1 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Fast Ma Buffer ... +#property indicator_label1 "Ma" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrYellow +#property indicator_style1 STYLE_DOT +#property indicator_width1 2 + +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define maBufferIndex 0 + +double maBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (maLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + // + // Ma ... + SetIndexBuffer(maBufferIndex, maBuffer); + SetIndexDrawBegin(maBufferIndex, maLength + 1); + // + // End Set Index Buffers ... + // + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, maLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Ma ... + CalculateMa(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateMa( + const int &bar_index +) { + // + // Calculating Fast Ma ... + double ma = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + maAppliedPrice, + bar_index + ); + + // + maBuffer[bar_index] = ma; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/Indicators/x-saherelm.momentum.mq4 b/Bkp/Used/14020425/Indicators/x-saherelm.momentum.mq4 new file mode 100644 index 0000000..ea6e419 --- /dev/null +++ b/Bkp/Used/14020425/Indicators/x-saherelm.momentum.mq4 @@ -0,0 +1,160 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center Momentum Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm Momentum Oscillator" +#property strict + +// +// START Inputs ... +// +input int length = 7; // Market Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_separate_window + +// +#property indicator_buffers 1 + +// +#property indicator_level1 0.0 +#property indicator_level2 100.0 +#property indicator_levelcolor clrSilver +#property indicator_levelstyle STYLE_DOT + +// +// MOMENTUM ... +#property indicator_width1 1 +#property indicator_color1 clrLightBlue +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_SOLID + +// +// Declare Buffers ... +#define momentumBufferIndex 0 + +double momentumBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (length < 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + IndicatorBuffers(1); + + // + SetIndexBuffer(momentumBufferIndex, momentumBuffer); + SetIndexLabel(momentumBufferIndex, "Momentum"); + SetIndexDrawBegin(momentumBufferIndex, length); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, length); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Long TP ... + CalculateBuffers( + i, + close + ); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index, + const double &close[] +) { + // + // Calculate Buffers ... + double momentum = close[bar_index] * 100 / close[bar_index + length]; + + // + momentumBuffer[bar_index] = momentum; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/Indicators/x-saherelm.osc.mq4 b/Bkp/Used/14020425/Indicators/x-saherelm.osc.mq4 new file mode 100644 index 0000000..829f32c --- /dev/null +++ b/Bkp/Used/14020425/Indicators/x-saherelm.osc.mq4 @@ -0,0 +1,257 @@ +///////////////////////////////////////////////////////////////// +// +// SaherElm IT Center OSC Indicator +// ------------------------------------------------------------- +// this indicator provides OSC ... +// +// 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 OSC Indicator" +#property strict + +// +// START Inputs ... +// +// +// FastOSC ... +// Short Cycle (Fast OSC) ... +input int fastOSCLength = 10; // FastOSC Length +input double fastOSCMultiplier = 1.0; // FastOSC Multiplier + +// +// SlowOSC ... +// Medium Cycle (Slow OSC) ... +input int slowOSCLength = 30; // SlowOSC Length +input double slowOSCMultiplier = 3.0; // SlowOSC Multiplier +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +#property indicator_separate_window + +// +// we have 2 buffer in this indicator ... +#property indicator_buffers 2 + +// +// also we have 2 line for draw on this indicator ... +#property indicator_plots 2 + +// +// Fast OSC ... +#property indicator_width1 1 +#property indicator_color1 clrAqua +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_SOLID + +// +// Slow OSC ... +#property indicator_width2 1 +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrFuchsia +#property indicator_style2 STYLE_SOLID + +// +// set color of horizontal levels ... +#property indicator_levelcolor clrGray + +// +// set style of horizontal levels ... +#property indicator_levelstyle STYLE_DOT + +// +// Declare Buffers ... +#define fastOSCBufferIndex 0 +#define slowOSCBufferIndex 1 + +// +double fastOSCBuffer[]; +double slowOSCBuffer[]; + +// +// Used Indicators List ... +string rmaIndicatorName = "x-saherelm.rma"; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + fastOSCLength < 0 || + slowOSCLength < 0 || + slowOSCLength <= fastOSCLength + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XS_OSC"; + + // + // set descriptions of horizontal levels ... + SetLevelValue(0, 0.0); + IndicatorSetString(INDICATOR_LEVELTEXT,0,""); + + // + // set descriptions of horizontal levels ... + SetLevelValue(1, 0.5); + IndicatorSetString(INDICATOR_LEVELTEXT,1,""); + + // + // set descriptions of horizontal levels ... + SetLevelValue(2, 1); + IndicatorSetString(INDICATOR_LEVELTEXT,2,""); + + // + // Fast OSC Buffer ... + SetIndexBuffer(fastOSCBufferIndex, fastOSCBuffer); + SetIndexLabel(fastOSCBufferIndex, "Fast OSC"); + SetIndexDrawBegin(fastOSCBufferIndex, fastOSCLength - 1); + + // + // Slow OSC Buffer ... + SetIndexBuffer(slowOSCBufferIndex, slowOSCBuffer); + SetIndexLabel(slowOSCBufferIndex, "Slow OSC"); + SetIndexDrawBegin(slowOSCBufferIndex, slowOSCLength - 1); + + // + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(fastOSCLength, slowOSCLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + CalculateOscillators(close, i); + } + + // + return rates_total; +} + +// +// De Initialization ... +void OnDeinit(const int reason) { +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +void CalculateOscillators( + const double &close[], + const int &bar_index +) { + // + // FastOSC ... + // Short Cycle Calculations ... + int scl = fastOSCLength / 2; + int scl2 = scl / 2; + double maScl = iCustom(_Symbol, _Period, rmaIndicatorName, scl, 0, bar_index); + double scmAtr = iATR(_Symbol, _Period, scl, bar_index); + double scmOff = fastOSCMultiplier * scmAtr; + double maScl2 = iCustom(_Symbol, _Period, rmaIndicatorName, scl2, 0, bar_index); + double sctParam = maScl2 != 0 ? maScl2 : close[bar_index + 1]; + double sct = sctParam + scmOff; + double scb = sctParam - scmOff; + + // + // SlowOSC ... + // Medium Cycle Calculations ... + int mcl = slowOSCLength / 2; + int mcl2 = mcl / 2; + double maMcl = iCustom(_Symbol, _Period, rmaIndicatorName, mcl, 0, bar_index); + double mcmAtr = iATR(_Symbol, _Period, mcl, bar_index); + double mcmOff = slowOSCMultiplier * mcmAtr; + double maMcl2 = iCustom(_Symbol, _Period, rmaIndicatorName, mcl2, 0, bar_index); + double mctParam = maMcl2 != 0 ? maMcl2 : close[bar_index + 1]; + double mct = mctParam + mcmOff; + double mcb = mctParam - mcmOff; + + // + double scMM = (sct + scb) / 2; + + // + double fastOCS = (close[bar_index] - mcb) / (mct - mcb); + fastOSCBuffer[bar_index] = fastOCS; + + // + double slowOCS = (scMM - mcb) / (mct - mcb); + slowOSCBuffer[bar_index] = slowOCS; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/Indicators/x-saherelm.rma.mq4 b/Bkp/Used/14020425/Indicators/x-saherelm.rma.mq4 new file mode 100644 index 0000000..0fc70fd --- /dev/null +++ b/Bkp/Used/14020425/Indicators/x-saherelm.rma.mq4 @@ -0,0 +1,141 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center RMA Indicator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm RMA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Set the RMA Length ... +input int RMALength = 10; // Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// we have 2 buffer in this indicator ... +#property indicator_buffers 1 + +// +// also we have 1 line for draw on this indicator ... +#property indicator_plots 1 + +// +// here we declare plot SlowOCS to system ... +#property indicator_label1 "RMA" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrFuchsia +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +// +// Declare Buffers ... +#define RMABufferIndex 0 + +// +double RMABuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + SetIndexBuffer(RMABufferIndex, RMABuffer); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + int maxLength = MathMax(0, RMALength); + + // + // wait to pass bars until we have rights ... + if (rates_total <= maxLength) { + // + // return not calculated ... + return 0; + } + + // + // find loop count for bars manipulation ... + int count = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // Print("Count: ", count, ", Bars: ", Bars); + + // + // this is the main loop of calculations, for each bar index ... + for (int i = count - 1; i >= 0; i--) { + // + // Start Calculation with Formula 1 ... + // + double shortSMA = iMA(_Symbol, _Period, RMALength, 0, MODE_SMA, PRICE_CLOSE, i); + double mediumSMA = iMA(_Symbol, _Period, RMALength * 2, 0, MODE_SMA, PRICE_CLOSE, i); + double longSMA = iMA(_Symbol, _Period, RMALength * 3, 0, MODE_SMA, PRICE_CLOSE, i); + + // + double rma1 = longSMA - mediumSMA + shortSMA; + rma1 = NormalizeDouble(rma1, _Digits); + // + // End Calculation with Formula 1 ... + // + + // + RMABuffer[i] = rma1; + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/Indicators/x-saherelm.rsi.mq4 b/Bkp/Used/14020425/Indicators/x-saherelm.rsi.mq4 new file mode 100644 index 0000000..448f732 --- /dev/null +++ b/Bkp/Used/14020425/Indicators/x-saherelm.rsi.mq4 @@ -0,0 +1,234 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center RSI Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm RSI Oscillator" +#property strict + +// +// START Inputs ... +// +input int rsiPeriod=14; // RSI Period +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_separate_window + +// +#property indicator_minimum 0 +#property indicator_maximum 100 + +// +#property indicator_buffers 1 +#property indicator_color1 DodgerBlue + +// +#property indicator_level1 30.0 +#property indicator_level2 50.0 +#property indicator_level3 70.0 +#property indicator_levelcolor clrSilver +#property indicator_levelstyle STYLE_DOT + +// +// Declare Buffers ... +#define rsiBufferIndex 0 +#define positiveBufferIndex 1 +#define negativeBufferIndex 2 + +double rsiBuffer[]; +double positiveBuffer[]; +double negativeBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + string short_name; + + // + IndicatorBuffers(3); + + // + SetIndexBuffer(positiveBufferIndex, positiveBuffer); + SetIndexBuffer(negativeBufferIndex, negativeBuffer); + + // + SetIndexStyle(rsiBufferIndex, DRAW_LINE); + SetIndexBuffer(rsiBufferIndex, rsiBuffer); + + // + // name for DataWindow and indicator subwindow label + short_name="RSI("+string(rsiPeriod)+")"; + IndicatorShortName(short_name); + SetIndexLabel(rsiBufferIndex, short_name); + + // + // check for input + if (rsiPeriod < 2) { + // + Print("Incorrect value for input variable InpRSIPeriod = ", rsiPeriod); + + // + // Failed Initialization ... + return INIT_PARAMETERS_INCORRECT; + } + + // + // set where to start draw ... + SetIndexDrawBegin(0, rsiPeriod); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + int i,pos; + double diff; + + // + // Prevent from run calculations if there is no fulfilled conditions ... + if (Bars <= rsiPeriod || rsiPeriod < 2) { + // + // return nothing calculated result ... + return 0; + } + + // + // counting from 0 to rates_total, this is most important ... + ArraySetAsSeries(rsiBuffer, false); + ArraySetAsSeries(positiveBuffer, false); + ArraySetAsSeries(negativeBuffer, false); + + // + ArraySetAsSeries(close, false); + + // + // preliminary calculations ... + pos = prev_calculated - 1; + if (pos <= rsiPeriod) { + // + // first RSIPeriod values of the indicator are not calculated + rsiBuffer[0] = 0.0; + positiveBuffer[0] = 0.0; + negativeBuffer[0] = 0.0; + + // + double sump=0.0; + double sumn=0.0; + for (i = 1; i <= rsiPeriod; i++) { + // + rsiBuffer[i]=0.0; + positiveBuffer[i]=0.0; + negativeBuffer[i]=0.0; + + // + diff = close[i] - close[i - 1]; + if(diff > 0) { + sump += diff; + } else { + sumn -= diff; + } + } + + // + // calculate first visible value ... + positiveBuffer[rsiPeriod] = sump / rsiPeriod; + negativeBuffer[rsiPeriod] = sumn / rsiPeriod; + if (negativeBuffer[rsiPeriod] != 0.0) { + // + rsiBuffer[rsiPeriod] = 100.0 - ( + 100.0 / ( + 1.0 + positiveBuffer[rsiPeriod] / negativeBuffer[rsiPeriod] + ) + ); + } else { + // + if (positiveBuffer[rsiPeriod] != 0.0) { + rsiBuffer[rsiPeriod] = 100.0; + } else { + rsiBuffer[rsiPeriod] = 50.0; + } + } + + // + // prepare the position value for main calculation ... + pos = rsiPeriod + 1; + } + + // + // the main loop of calculations ... + for (i = pos; i < rates_total && !IsStopped(); i++) { + // + diff = close[i] - close[i-1]; + + // + positiveBuffer[i] = (positiveBuffer[i-1] * (rsiPeriod - 1) + (diff > 0.0 ? diff : 0.0)) / rsiPeriod; + negativeBuffer[i] = (negativeBuffer[i-1] * (rsiPeriod - 1) + (diff < 0.0 ? -diff : 0.0)) / rsiPeriod; + + // + if (negativeBuffer[i] != 0.0) { + rsiBuffer[i] = 100.0 - 100.0 / (1 + positiveBuffer[i] / negativeBuffer[i]); + } else { + // + if (positiveBuffer[i] != 0.0) { + rsiBuffer[i] = 100.0; + } else { + rsiBuffer[i] = 50.0; + } + } + } + + // + return(rates_total); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/Indicators/x-saherelm.shpd.mq4 b/Bkp/Used/14020425/Indicators/x-saherelm.shpd.mq4 new file mode 100644 index 0000000..7c02a84 --- /dev/null +++ b/Bkp/Used/14020425/Indicators/x-saherelm.shpd.mq4 @@ -0,0 +1,402 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XSHPD Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 XSHPD Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 7; // Market Length ... +input double sharpDetectMultiplier = 70; // Sharp Detect Multiplier + +// +input bool drawLabels = true; // Draw Labels on Founded Sharps + +// +input string sharpBullishLabel = "SH_BULL"; // Sharp Bullish Label +input color sharpBullishColor = clrAqua; // Sharp Bullish color + +// +input string sharpBearishLabel = "SH_BEAR"; // Sharp Bearish Label +input color sharpBearishColor = clrFuchsia; // Sharp Bearish color +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +#property indicator_buffers 4 +#property indicator_plots 4 + +// +// Declare Buffers ... +#define marketHighestHighBufferIndex 0 +#define marketLowestLowBufferIndex 1 +#define sharpBullishBufferIndex 2 +#define sharpBearishBufferIndex 3 + +// +double marketHighestHighBuffer[]; +double marketLowestLowBuffer[]; +double sharpBullishBuffer[]; +double sharpBearishBuffer[]; + +// +#include "../Libraries/x-saherelm.lib.mq4" +#include "../Libraries/x-saherelm.draw.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if ( + marketLength <= 0 + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + enableLogging = true; + + // + logTag = "X_SHPD"; + + // + // Highest High ... + SetIndexLabel(marketHighestHighBufferIndex, ""); + SetIndexBuffer(marketHighestHighBufferIndex, marketHighestHighBuffer); + SetIndexStyle( + marketHighestHighBufferIndex, + DRAW_LINE, // DRAW_NONE, + STYLE_DOT, + 1, // 0, + clrAqua // clrNONE + ); + + // + // Lowest Low ... + SetIndexLabel(marketLowestLowBufferIndex, ""); + SetIndexBuffer(marketLowestLowBufferIndex, marketLowestLowBuffer); + SetIndexStyle( + marketLowestLowBufferIndex, + DRAW_NONE, + STYLE_DOT, + 0, + clrNONE + ); + + // + // Sharp Bullish Buffer ... + SetIndexLabel(sharpBullishBufferIndex, ""); + SetIndexBuffer(sharpBullishBufferIndex, sharpBullishBuffer); + SetIndexStyle( + sharpBullishBufferIndex, + DRAW_NONE, + STYLE_DOT, + 0, + clrNONE + ); + + // + // Sharp Bearish Buffer ... + SetIndexLabel(sharpBearishBufferIndex, ""); + SetIndexBuffer(sharpBearishBufferIndex, sharpBearishBuffer); + SetIndexStyle( + sharpBearishBufferIndex, + DRAW_NONE, + STYLE_DOT, + 0, + clrNONE + ); + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + RemoveDraws(logTag); +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Sharp ... + CalculateSharp(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Sharp ... +void CalculateSharp( + const int &bar_index +) { + // + int index = 0; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + 1 + ); + + // + marketHighestHighBuffer[bar_index] = GetMarketHighestHigh( + bar_index, + marketLength + ); + + // + marketLowestLowBuffer[bar_index] = GetMarketLowestLow( + bar_index, + marketLength + ); + + // + double maHHs[]; + ArrayResize( + maHHs, + marketLength + ); + + // + double maLLs[]; + ArrayResize( + maLLs, + marketLength + ); + + // + index = 0; + for (int i = bar_index; i < bar_index + marketLength; i++) { + // + maLLs[index] = marketLowestLowBuffer[i]; + maHHs[index] = marketHighestHighBuffer[i]; + + // + index++; + } + + // + int maxHighIdx = ArrayMaximum(maHHs); + double maxHigh = maHHs[maxHighIdx]; + + // + int minHighIdx = ArrayMinimum(maHHs); + double minHigh = maHHs[minHighIdx]; + + // + double highDiffRate = (maxHigh - minHigh) / 100; + + // + int maxLowIdx = ArrayMaximum(maLLs); + double maxLow = maLLs[maxLowIdx]; + + // + int minLowIdx = ArrayMinimum(maLLs); + double minLow = maLLs[minLowIdx]; + + // + double lowDiffRate = (maxLow - minLow) / 100; + + // + bool isSharpBullishDetected = + high == maxHigh + && low > minLow + && marketHighestHighBuffer[bar_index] == maxHigh + && maxHigh - minHigh > highDiffRate * sharpDetectMultiplier + ; + sharpBullishBuffer[bar_index] = isSharpBullishDetected ? 1 : 0; + + // + bool isSharpBearishDetected = + low == minLow + && high < maxHigh + && marketLowestLowBuffer[bar_index] == minLow + && maxLow - minLow > lowDiffRate * sharpDetectMultiplier + ; + sharpBearishBuffer[bar_index] = isSharpBearishDetected ? 1 : 0; + + // + if ( + drawLabels + && ( + isSharpBearishDetected + || isSharpBullishDetected + ) + ) { + // + datetime time = iTime( + _Symbol, + _Period, + bar_index + ); + + // + string lbl = StringConcatenate( + logTag, + isSharpBullishDetected ? "Bullish_" : "Bearish_", + bar_index + ); + + // + double price = + isSharpBullishDetected + ? + marketLowestLowBuffer[bar_index] - (10 * _Point) + : + marketHighestHighBuffer[bar_index] + (10 * _Point) + ; + + // + uchar arrowCode = + isSharpBullishDetected + ? + SYMBOL_ARROWUP + : + SYMBOL_ARROWDOWN + ; + + // + ENUM_ARROW_ANCHOR anchor = + isSharpBullishDetected + ? + ANCHOR_BOTTOM + : + ANCHOR_TOP + ; + + // + color clr = + isSharpBullishDetected + ? + sharpBullishColor + : + sharpBearishColor + ; + + // + string lblText = + isSharpBullishDetected + ? + sharpBullishLabel + : + sharpBearishLabel + ; + + // + DrawText( + 0, + lbl, + 0, + time, + price, + lblText, + "Tahoma", + 5, + clr + ); + } +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/Indicators/x-saherelm.trend.mq4 b/Bkp/Used/14020425/Indicators/x-saherelm.trend.mq4 new file mode 100644 index 0000000..17873e7 --- /dev/null +++ b/Bkp/Used/14020425/Indicators/x-saherelm.trend.mq4 @@ -0,0 +1,250 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center ADX Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm ADX Oscillator" +#property strict + +// +// START Inputs ... +// +input int length = 7; // Averaging Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_chart_window + +// +// #property indicator_buffers 3 + +// +// Declare Buffers ... +// +datetime startTime; +double lHigh; +double lLow; + +// +datetime highTimes[]; + +// +datetime lowTimes[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (length < 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, length); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Long TP ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index +) { + // + // Calculate Buffers ... + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + startTime + ); + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + if (startTime == 0) { + // + startTime = barTime; + return; + } + + // + if ( + startTime > 0 + && startBarIndex - bar_index == length + ) { + // + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + length, + bar_index + ); + datetime hhTime = iTime( + _Symbol, + _Period, + hhIdx + ); + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + int hhSize = ArraySize(highTimes); + datetime tempTimes[]; + ArrayResize( + tempTimes, + hhSize + ); + ArrayCopy( + tempTimes, + highTimes + ); + ArrayResize( + highTimes, + hhSize + 1 + ); + highTimes[0] = hhTime; + ArrayCopy( + highTimes, + tempTimes, + 1 + ); + + // + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + length, + bar_index + ); + datetime llTime = iTime( + _Symbol, + _Period, + llIdx + ); + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + int llSize = ArraySize(lowTimes); + ArrayFree(tempTimes); + ArrayResize( + tempTimes, + llSize + ); + ArrayCopy( + tempTimes, + lowTimes + ); + ArrayResize( + lowTimes, + llSize + 1 + ); + lowTimes[0] = llTime; + ArrayCopy( + lowTimes, + tempTimes, + 1 + ); + + // + startTime = 0; + ArrayFree(tempTimes); + } +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/Indicators/x-saherelm.xbnd.mq4 b/Bkp/Used/14020425/Indicators/x-saherelm.xbnd.mq4 new file mode 100644 index 0000000..b8d2b43 --- /dev/null +++ b/Bkp/Used/14020425/Indicators/x-saherelm.xbnd.mq4 @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XBand Indicator +// --------------------------------------------- +// saherelm implementation of xBand 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 XBND Indicator" +#property strict + +// +#include "../Libraries/x-saherelm.lib.mq4" +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +// START Inputs ... +// +input int marketLength = 5; // Averaging Length +input int ignoreLastCross = 4; // Ignore Last Cross +input int shift = 0; // Averaging Shift +input ENUM_MA_METHOD method = MODE_SMA; // Averaging Mode +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_chart_window + +// +#property indicator_buffers 4 + +// +// Declare Buffers ... +// +// High ... +#property indicator_width1 1 +#property indicator_color1 clrAqua +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_DASHDOT + +// +// Open ... +#property indicator_width2 1 +#property indicator_color2 clrGreen +#property indicator_type2 DRAW_LINE +#property indicator_style2 STYLE_DASH + +// +// Close ... +#property indicator_width3 1 +#property indicator_color3 clrRed +#property indicator_type3 DRAW_LINE +#property indicator_style3 STYLE_DASH + +// +// Low ... +#property indicator_width4 1 +#property indicator_color4 clrFuchsia +#property indicator_type4 DRAW_LINE +#property indicator_style4 STYLE_DASHDOT + +// +#define highBufferIndex 0 +#define openBufferIndex 1 +#define closeBufferIndex 2 +#define lowBufferIndex 3 + +// +double highBuffer[]; +double openBuffer[]; +double closeBuffer[]; +double lowBuffer[]; + +// +datetime lastCrossTime; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (marketLength < 5) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XBND"; + + // + // High ... + string highLabel = StringConcatenate( + "High(", marketLength, ")" + ); + SetIndexBuffer(highBufferIndex, highBuffer); + SetIndexLabel(highBufferIndex, highLabel); + + // + // Open ... + string openLabel = StringConcatenate( + "Open(", marketLength, ")" + ); + SetIndexBuffer(openBufferIndex, openBuffer); + SetIndexLabel(openBufferIndex, openLabel); + + // + // Close ... + string closeLabel = StringConcatenate( + "Close(", marketLength, ")" + ); + SetIndexBuffer(closeBufferIndex, closeBuffer); + SetIndexLabel(closeBufferIndex, closeLabel); + + // + // Low ... + string lowLabel = StringConcatenate( + "Low(", marketLength, ")" + ); + SetIndexBuffer(lowBufferIndex, lowBuffer); + SetIndexLabel(lowBufferIndex, lowLabel); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + RemoveDraws(logTag); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Buffers ... + CalculateBuffers(i); + + // + // Calculate Market Changes ... + CalculateInfo(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index +) { + // + // High ... + double high = iMA( + _Symbol, + _Period, + marketLength, + shift, + method, + PRICE_HIGH, + bar_index + ); + + // + highBuffer[bar_index] = high; + + // + // Open ... + double open = iMA( + _Symbol, + _Period, + marketLength, + shift, + method, + PRICE_OPEN, + bar_index + ); + + // + openBuffer[bar_index] = open; + + // + // Close ... + double close = iMA( + _Symbol, + _Period, + marketLength, + shift, + method, + PRICE_CLOSE, + bar_index + ); + + // + closeBuffer[bar_index] = close; + + // + // Low ... + double low = iMA( + _Symbol, + _Period, + marketLength, + shift, + method, + PRICE_LOW, + bar_index + ); + + // + lowBuffer[bar_index] = low; +} + +// +void CalculateInfo( + const int bar_index +) { + // + XOHCL pCandle = GetCandleModel(bar_index); + + // + bool isTrendingUp = + pCandle.low > highBuffer[bar_index] + && pCandle.high > highBuffer[bar_index]; + + // + bool isTrendingDown = + pCandle.high < lowBuffer[bar_index] + && pCandle.low < lowBuffer[bar_index]; + + // + bool isOpenCrossOverClose = + true + && + ( + pCandle.high > highBuffer[bar_index + 1] + || pCandle.low < lowBuffer[bar_index + 1] + ) + && openBuffer[bar_index + 1] > closeBuffer[bar_index + 1] + && !(openBuffer[bar_index + 2] >= closeBuffer[bar_index + 2]) + ; + + // + bool isOpenCrossUnderClose = + true + && + ( + pCandle.high > highBuffer[bar_index + 1] + || pCandle.low < lowBuffer[bar_index + 1] + ) + && openBuffer[bar_index + 1] < closeBuffer[bar_index + 1] + && !(openBuffer[bar_index + 2] <= closeBuffer[bar_index + 2]) + ; + + // + isTrendingUp = isOpenCrossUnderClose; + isTrendingDown = isOpenCrossOverClose; + + // + datetime time = iTime( + _Symbol, + _Period, + bar_index + ); + + // + if ( + isTrendingUp + || isTrendingDown + ) { + // + if (lastCrossTime == 0) { + lastCrossTime = time; + } else { + // + int lastCrossBarIndex = iBarShift( + _Symbol, + _Period, + lastCrossTime + ); + + // + int diff = lastCrossBarIndex - bar_index; + if (diff <= ignoreLastCross) { + return; + } else { + lastCrossTime = time; + } + } + } + + // + string lbl = StringConcatenate( + logTag, + "_Arrow_", + isTrendingUp ? "UP" : "Down", + "_", time + ); + + // + color clr = isTrendingUp ? + clrAqua : + clrFuchsia; + + // + ENUM_ARROW_ANCHOR anchor = isTrendingUp ? + ANCHOR_BOTTOM : + ANCHOR_TOP; + + // + uchar arrowCode = isTrendingUp ? + SYMBOL_ARROWUP : + SYMBOL_ARROWDOWN; + + // + double price = isTrendingUp ? + pCandle.low - 20 * _Point : + pCandle.high + 20 * _Point; + + // + if (isTrendingUp) { + // + // this means Market Going Up ... + + } + + // + if (isTrendingDown) { + // + // this means Market Going Downm ... + } + + // + if ( + isTrendingUp + || isTrendingDown + ) { + // + bool isDrawn = DrawArrow( + 0, + lbl, + 0, + time, + price, + arrowCode, + anchor, + clr + ); + } +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/Indicators/x-saherelm.xma.mq4 b/Bkp/Used/14020425/Indicators/x-saherelm.xma.mq4 new file mode 100644 index 0000000..4a599f9 --- /dev/null +++ b/Bkp/Used/14020425/Indicators/x-saherelm.xma.mq4 @@ -0,0 +1,695 @@ + /////////////////////////////////////////////////////// +// +// SaherElm IT Center XMA Indicator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XMA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Market Specifications ... +input int marketLength = 7; // Market Length +input double step = 0.02; // SAR Step +input double maximum = 0.2; // SAR Maximum +// +// Cycle Definitions ... +input int shortCycleFastMultiplier = 1; // Short Cycle Fast Multiplier +input int shortCycleSlowMultiplier = 4; // Short Cycle Slow Multiplier +input int mediumCycleFastMultiplier = 7; // Medium Cycle Fast Multiplier +input int mediumCycleSlowMultiplier = 14; // Medium Cycle Slow Multiplier +input int longCycleFastMultiplier = 70; // Long Cycle Fast Multiplier +input int longCycleSlowMultiplier = 140; // Long Cycle Slow Multiplier +// +// Show Inputs ... +input bool showPSar = true; // Show Parabolic Sar +input bool showMarketMiddle = true; // Show Market Middle +input bool showShortCycle = true; // Show Short Cycle +input bool showShortCycleCrossLines = true; // Show Short Cycle Vertical Lines +input bool showMediumCycle = true; // Show Medium Cycle +input bool showMediumCycleCrossLines = true; // Show Medium Cycle Vertical Lines +input bool showLongCycle = true; // Show Long Cycle +input bool showLongCycleCrossLines = true; // Show Long Cycle Vertical Lines +// +// Color Inputs ... +input color pSarColor = clrCornflowerBlue; // Parabolic Sar Color +input color shortCycleFastColor = clrGreen; // Short Cycle Fast Color +input color shortCycleSlowColor = clrRed; // Short Cycle Slow Color +input color mediumCycleFastColor = clrAqua; // Medium Cycle Fast Color +input color mediumCycleSlowColor = clrFuchsia; // Medium Cycle Slow Color +input color longCycleFastColor = clrGoldenrod; // Medium Cycle Fast Color +input color longCycleSlowColor = clrBrown; // Medium Cycle Slow Color +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// define indicator buffers ... +#property indicator_buffers 8 +#property indicator_plots 8 + +// +// Declare Buffers ... +#define scFastBufferIndex 0 +#define scSlowBufferIndex 1 +#define mcFastBufferIndex 2 +#define mcSlowBufferIndex 3 +#define lcFastBufferIndex 4 +#define lcSlowBufferIndex 5 +#define midBufferIndex 6 +#define pSarBufferIndex 7 + +// +double scFastBuffer[]; +double scSlowBuffer[]; +double mcFastBuffer[]; +double mcSlowBuffer[]; +double lcFastBuffer[]; +double lcSlowBuffer[]; +double midBuffer[]; +double pSarBuffer[]; + +// +int shortCycleFastLength; +int shortCycleSlowLength; +int mediumCycleFastLength; +int mediumCycleSlowLength; +int longCycleFastLength; +int longCycleSlowLength; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + // + // Validate Market Length ... + marketLength <= 0 + // + // Validate Short Cycle ... + || shortCycleFastMultiplier <= 0 + || shortCycleSlowMultiplier <= 0 + || shortCycleFastMultiplier >= shortCycleSlowMultiplier + // + // Validate Medium Cycle ... + || mediumCycleFastMultiplier <= 0 + || mediumCycleSlowMultiplier <= 0 + || mediumCycleFastMultiplier >= mediumCycleSlowMultiplier + // + // Validate Long Cycle ... + || longCycleFastMultiplier <= 0 + || longCycleSlowMultiplier <= 0 + || longCycleFastMultiplier >= longCycleSlowMultiplier + // + // Validate Series of Multipliers ... + || shortCycleFastMultiplier >= mediumCycleFastMultiplier + || mediumCycleFastMultiplier >= longCycleFastMultiplier + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST_XMA"; + + // + // Calculate Cycle Length based on given Multipliers ... + shortCycleFastLength = marketLength * shortCycleFastMultiplier; + shortCycleSlowLength = marketLength * shortCycleSlowMultiplier; + mediumCycleFastLength = marketLength * mediumCycleFastMultiplier; + mediumCycleSlowLength = marketLength * mediumCycleSlowMultiplier; + longCycleFastLength = marketLength * longCycleFastMultiplier; + longCycleSlowLength = marketLength * longCycleSlowMultiplier; + + // + // Short Cycle Fast ... + SetIndexLabel(scFastBufferIndex, "SCFast"); + SetIndexBuffer(scFastBufferIndex, scFastBuffer); + SetIndexDrawBegin(scFastBufferIndex, shortCycleFastLength); + SetIndexStyle( + scFastBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showShortCycle ? + shortCycleFastColor : + clrNONE + ); + + // + // Short Cycle Slow ... + SetIndexLabel(scSlowBufferIndex, "SCSLow"); + SetIndexBuffer(scSlowBufferIndex, scSlowBuffer); + SetIndexDrawBegin(scSlowBufferIndex, shortCycleSlowLength); + SetIndexStyle( + scSlowBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showShortCycle ? + shortCycleSlowColor : + clrNONE + ); + + // + // Medium Cycle Fast ... + SetIndexLabel(mcFastBufferIndex, "MCFast"); + SetIndexBuffer(mcFastBufferIndex, mcFastBuffer); + SetIndexDrawBegin(mcFastBufferIndex, mediumCycleFastLength); + SetIndexStyle( + mcFastBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showMediumCycle ? + mediumCycleFastColor : + clrNONE + ); + + // + // Medium Cycle Slow ... + SetIndexLabel(mcSlowBufferIndex, "MCSlow"); + SetIndexBuffer(mcSlowBufferIndex, mcSlowBuffer); + SetIndexDrawBegin(mcSlowBufferIndex, mediumCycleSlowLength); + SetIndexStyle( + mcSlowBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showMediumCycle ? + mediumCycleSlowColor : + clrNONE + ); + + // + // Long Cycle Fast ... + SetIndexLabel(lcFastBufferIndex, "LCFast"); + SetIndexBuffer(lcFastBufferIndex, lcFastBuffer); + SetIndexDrawBegin(lcFastBufferIndex, longCycleFastLength); + SetIndexStyle( + lcFastBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showLongCycle ? + longCycleFastColor : + clrNONE + ); + + // + // Long Cycle Slow ... + SetIndexLabel(lcSlowBufferIndex, "LCSlow"); + SetIndexBuffer(lcSlowBufferIndex, lcSlowBuffer); + SetIndexDrawBegin(lcSlowBufferIndex, longCycleSlowLength); + SetIndexStyle( + lcSlowBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showLongCycle ? + longCycleSlowColor : + clrNONE + ); + + // + // Market Middleage ... + SetIndexBuffer(midBufferIndex, midBuffer); + SetIndexDrawBegin(midBufferIndex, marketLength); + SetIndexLabel(midBufferIndex, "Market Mid"); + + // + // Parabolic Sar ... + SetIndexBuffer(pSarBufferIndex, pSarBuffer); + SetIndexLabel(pSarBufferIndex, "P Sar"); + SetIndexStyle( + pSarBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showPSar ? + pSarColor : + clrNONE + ); + + // + // Market Middle ... + SetIndexBuffer(midBufferIndex, midBuffer); + SetIndexLabel(midBufferIndex, "Mid"); + SetIndexStyle( + midBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showMarketMiddle ? + clrAntiqueWhite : + clrNONE + ); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + RemoveDraws(logTag); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(marketLength, longCycleSlowLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Short Cycle ... + CalculateShortCycle(i); + + // + // Calculate Medium Cycle ... + CalculateMediumCycle(i); + + // + // Calculate Long Cycle ... + CalculateLongCycle(i); + + // + // Calculate Market Middleage ... + CalculateMarketMiddleage(i); + + // + // Calculate Cross Points ... + CalculateCrossPoints(i); + + // + // Calculate Parabolic Sar ... + CalculateParabolicSar(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculate Short Cycle ... +void CalculateShortCycle( + const int bar_index +) { + // + // Fast ... + double shortCycleFast = iMA( + _Symbol, + _Period, + shortCycleFastLength, + 0, + MODE_SMA, + PRICE_WEIGHTED, + bar_index + ); + scFastBuffer[bar_index] = shortCycleFast; + + // + // Slow ... + double shortCycleSlow = iMA( + _Symbol, + _Period, + shortCycleSlowLength, + 0, + MODE_SMA, + PRICE_WEIGHTED, + bar_index + ); + scSlowBuffer[bar_index] = shortCycleSlow; +} + +// +// Calculate Medium Cycle ... +void CalculateMediumCycle( + const int bar_index +) { + // + // Fast ... + double mediumCycleFast = iMA( + _Symbol, + _Period, + mediumCycleFastLength, + 0, + MODE_SMA, + PRICE_MEDIAN, + bar_index + ); + mcFastBuffer[bar_index] = mediumCycleFast; + + // + // Slow ... + double mediumCycleSlow = iMA( + _Symbol, + _Period, + mediumCycleSlowLength, + 0, + MODE_SMA, + PRICE_MEDIAN, + bar_index + ); + mcSlowBuffer[bar_index] = mediumCycleSlow; +} + +// +// Calculate Long Cycle ... +void CalculateLongCycle( + const int bar_index +) { + // + // Fast ... + double longCycleFast = iMA( + _Symbol, + _Period, + longCycleFastLength, + 0, + MODE_SMA, + PRICE_CLOSE, + bar_index + ); + lcFastBuffer[bar_index] = longCycleFast; + + // + // Slow ... + double longCycleSlow = iMA( + _Symbol, + _Period, + longCycleSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE, + bar_index + ); + lcSlowBuffer[bar_index] = longCycleSlow; +} + +// +// Calculate Market Middleage ... +void CalculateMarketMiddleage( + const int bar_index +) { + // + // Mid ... + double marketMiddleage = iMA( + _Symbol, + _Period, + (int)(marketLength * 1.5), + 0, + MODE_EMA, + PRICE_MEDIAN, + bar_index + ); + midBuffer[bar_index] = marketMiddleage; +} + +// +// Calculate Cross Points and Draw Section Line on theme ... +void CalculateCrossPoints( + const int bar_index +) { + // + // START Draw Cross Lines ... + // + // + // Short Cycle ... + bool isSCFastCrossOverSlow = scFastBuffer[bar_index] > scSlowBuffer[bar_index] + && !(scFastBuffer[bar_index + 1] > scSlowBuffer[bar_index + 1]); + + // + bool isSCFastCrossUnderSlow = scFastBuffer[bar_index] < scSlowBuffer[bar_index] + && !(scFastBuffer[bar_index + 1] < scSlowBuffer[bar_index + 1]); + + // + // Medium Cycle ... + bool isMCFastCrossOverSlow = mcFastBuffer[bar_index] > mcSlowBuffer[bar_index] + && !(mcFastBuffer[bar_index + 1] > mcSlowBuffer[bar_index + 1]); + + // + bool isMCFastCrossUnderSlow = mcFastBuffer[bar_index] < mcSlowBuffer[bar_index] + && !(mcFastBuffer[bar_index + 1] < mcSlowBuffer[bar_index + 1]); + + // + // Long Cycle ... + bool isLCFastCrossOverSlow = lcFastBuffer[bar_index] > lcSlowBuffer[bar_index] + && !(lcFastBuffer[bar_index + 1] > lcSlowBuffer[bar_index + 1]); + + // + bool isLCFastCrossUnderSlow = lcFastBuffer[bar_index] < lcSlowBuffer[bar_index] + && !(lcFastBuffer[bar_index + 1] < lcSlowBuffer[bar_index + 1]); + + // + // START Drawing CrossPoints ... + // + // + datetime currentTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + if (showShortCycleCrossLines) { + // + // Draw Line ... + if (isSCFastCrossOverSlow) { + // + string lbl = StringConcatenate( + logTag, + "_SC_F_OV_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showShortCycleCrossLines ? + shortCycleFastColor : + clrNONE + ); + } + + // + // Draw Line ... + if (isSCFastCrossUnderSlow) { + // + string lbl = StringConcatenate( + logTag, + "_SC_F_UN_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showShortCycleCrossLines ? + shortCycleSlowColor : + clrNONE + ); + } + } + + // + if (showMediumCycleCrossLines) { + // + // Draw Line ... + if (isMCFastCrossOverSlow) { + // + string lbl = StringConcatenate( + logTag, + "_MC_F_OV_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showMediumCycleCrossLines ? + mediumCycleFastColor : + clrNONE + ); + } + + // + // Draw Line ... + if (isMCFastCrossUnderSlow) { + // + string lbl = StringConcatenate( + logTag, + "_MC_F_UN_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showMediumCycleCrossLines ? + mediumCycleSlowColor : + clrNONE + ); + } + } + + // + if (showLongCycleCrossLines) { + // + // Draw Line ... + if (isLCFastCrossOverSlow) { + // + string lbl = StringConcatenate( + logTag, + "_LC_F_OV_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showLongCycleCrossLines ? + longCycleFastColor : + clrNONE + ); + } + + // + // Draw Line ... + if (isLCFastCrossUnderSlow) { + // + string lbl = StringConcatenate( + logTag, + "_LC_F_UN_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showLongCycleCrossLines ? + longCycleSlowColor : + clrNONE + ); + } + } + // + // END Drawing CrossPoints ... + // +} + +void CalculateParabolicSar( + const int bar_index +) { + // + double sarValue = iSAR( + NULL, + _Period, + step, + maximum, + bar_index + ); + + // + pSarBuffer[bar_index] = sarValue; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/Indicators/x-saherelm.xmarket.mq4 b/Bkp/Used/14020425/Indicators/x-saherelm.xmarket.mq4 new file mode 100644 index 0000000..71b2e2c --- /dev/null +++ b/Bkp/Used/14020425/Indicators/x-saherelm.xmarket.mq4 @@ -0,0 +1,394 @@ + /////////////////////////////////////////////////////// +// +// SaherElm IT Center XMKT Indicator +// --------------------------------------------- +// retrieve market base info ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XMKT Indicator" +#property strict + +// +// START Inputs ... +// +// +// Market Specifications ... +input int marketLength = 7; // Market Length +// +input bool showHighestHigh = true; // Show Market Highest High +input bool showHighestLow = true; // Show Market Highest Low +input bool showHighestOpen = true; // Show Market Highest Open +input bool showHighestClose = true; // Show Market Highest Close +input bool showLowestHigh = true; // Show Market Lowest High +input bool showLowestLow = true; // Show Market Lowest Low +input bool showLowestOpen = true; // Show Market Lowest Open +input bool showLowestClose = true; // Show Market Lowest Close +// +input color highestHighColor = clrDeepPink; // Market Highest High Color +input color highestLowColor = clrDarkOrange; // Market Highest Low Color +input color highestOpenColor = clrDodgerBlue; // Market Highest Open Color +input color highestCloseColor = clrOrchid; // Market Highest Close Color +input color lowestHighColor = clrHotPink; // Market Lowest High Color +input color lowestLowColor = clrOrange; // Market Lowest Low Color +input color lowestOpenColor = clrPowderBlue; // Market Lowest Open Color +input color lowestCloseColor = clrMediumOrchid; // Market Lowest Close Color +// +input ENUM_LINE_STYLE highestHighStyle = STYLE_DOT; // Market Highest High Line Style +input ENUM_LINE_STYLE highestLowStyle = STYLE_DOT; // Market Highest Low Line Style +input ENUM_LINE_STYLE highestOpenStyle = STYLE_DOT; // Market Highest Open Line Style +input ENUM_LINE_STYLE highestCloseStyle = STYLE_DOT; // Market Highest Close Line Style +input ENUM_LINE_STYLE lowestHighStyle = STYLE_DOT; // Market Lowest High Line Style +input ENUM_LINE_STYLE lowestLowStyle = STYLE_DOT; // Market Lowest Low Line Style +input ENUM_LINE_STYLE lowestOpenStyle = STYLE_DOT; // Market Lowest Open Line Style +input ENUM_LINE_STYLE lowestCloseStyle = STYLE_DOT; // Market Lowest Close Line Style +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// define indicator buffers ... +#property indicator_buffers 8 +#property indicator_plots 8 + +// +// Declare Buffers ... +#define marketHighestHighBufferIndex 0 +#define marketHighestLowBufferIndex 1 +#define marketHighestOpenBufferIndex 2 +#define marketHighestCloseBufferIndex 3 +#define marketLowestHighBufferIndex 4 +#define marketLowestLowBufferIndex 5 +#define marketLowestOpenBufferIndex 6 +#define marketLowestCloseBufferIndex 7 + +// +double marketHighestHighBuffer[]; +double marketHighestLowBuffer[]; +double marketHighestOpenBuffer[]; +double marketHighestCloseBuffer[]; +double marketLowestHighBuffer[]; +double marketLowestLowBuffer[]; +double marketLowestOpenBuffer[]; +double marketLowestCloseBuffer[]; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (marketLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST_XMKT"; + + // + // Highest High ... + string highestHighLbl = StringConcatenate("HH(", marketLength,")"); + SetIndexLabel(marketHighestHighBufferIndex, highestHighLbl); + SetIndexBuffer(marketHighestHighBufferIndex, marketHighestHighBuffer); + SetIndexStyle( + marketHighestHighBufferIndex, + showHighestHigh ? + DRAW_LINE : + DRAW_NONE, + highestHighStyle, + 1, + showHighestHigh ? + highestHighColor : + clrNONE + ); + + // + // Highest Low ... + string highestLowLbl = StringConcatenate("HL(", marketLength,")"); + SetIndexLabel(marketHighestLowBufferIndex, highestLowLbl); + SetIndexBuffer(marketHighestLowBufferIndex, marketHighestLowBuffer); + SetIndexStyle( + marketHighestLowBufferIndex, + showHighestLow ? + DRAW_LINE : + DRAW_NONE, + highestLowStyle, + 1, + showHighestLow ? + highestLowColor : + clrNONE + ); + + // + // Highest Open ... + string highestOpenLbl = StringConcatenate("HO(", marketLength,")"); + SetIndexLabel(marketHighestOpenBufferIndex, highestOpenLbl); + SetIndexBuffer(marketHighestOpenBufferIndex, marketHighestOpenBuffer); + SetIndexStyle( + marketHighestOpenBufferIndex, + showHighestOpen ? + DRAW_LINE : + DRAW_NONE, + highestOpenStyle, + 1, + showHighestOpen ? + highestOpenColor : + clrNONE + ); + + // + // Highest Close ... + string highestCloseLbl = StringConcatenate("HC(", marketLength,")"); + SetIndexLabel(marketHighestCloseBufferIndex, highestCloseLbl); + SetIndexBuffer(marketHighestCloseBufferIndex, marketHighestCloseBuffer); + SetIndexStyle( + marketHighestCloseBufferIndex, + showHighestClose ? + DRAW_LINE : + DRAW_NONE, + highestCloseStyle, + 1, + showHighestClose ? + highestCloseColor : + clrNONE + ); + + // + // Lowest High ... + string lowestHighLbl = StringConcatenate("LH(", marketLength,")"); + SetIndexLabel(marketLowestHighBufferIndex, lowestHighLbl); + SetIndexBuffer(marketLowestHighBufferIndex, marketLowestHighBuffer); + SetIndexStyle( + marketLowestHighBufferIndex, + showLowestHigh ? + DRAW_LINE : + DRAW_NONE, + lowestHighStyle, + 1, + showLowestHigh ? + lowestHighColor : + clrNONE + ); + + // + // Lowest Low ... + string lowestLowLbl = StringConcatenate("LL(", marketLength,")"); + SetIndexLabel(marketLowestLowBufferIndex, lowestLowLbl); + SetIndexBuffer(marketLowestLowBufferIndex, marketLowestLowBuffer); + SetIndexStyle( + marketLowestLowBufferIndex, + showLowestLow ? + DRAW_LINE : + DRAW_NONE, + lowestLowStyle, + 1, + showLowestLow ? + lowestLowColor : + clrNONE + ); + + // + // Lowest Open ... + string lowestOpenLbl = StringConcatenate("LO(", marketLength,")"); + SetIndexLabel(marketLowestOpenBufferIndex, lowestOpenLbl); + SetIndexBuffer(marketLowestOpenBufferIndex, marketLowestOpenBuffer); + SetIndexStyle( + marketLowestOpenBufferIndex, + showLowestOpen ? + DRAW_LINE : + DRAW_NONE, + lowestOpenStyle, + 1, + showLowestOpen ? + lowestOpenColor : + clrNONE + ); + + // + // Lowest Close ... + string lowestCloseLbl = StringConcatenate("LC(", marketLength,")"); + SetIndexLabel(marketLowestCloseBufferIndex, lowestCloseLbl); + SetIndexBuffer(marketLowestCloseBufferIndex, marketLowestCloseBuffer); + SetIndexStyle( + marketLowestCloseBufferIndex, + showLowestClose ? + DRAW_LINE : + DRAW_NONE, + lowestCloseStyle, + 1, + showLowestClose ? + lowestCloseColor : + clrNONE + ); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + RemoveDraws(logTag); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(marketLength, 3); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Short Cycle ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculate Short Cycle ... +void CalculateBuffers( + const int bar_index +) { + // + // Highest High ... + double highestHighValue = GetMarketHighestHigh( + bar_index, + marketLength + ); + marketHighestHighBuffer[bar_index] = highestHighValue; + + // + // Highest Low ... + double highestLowValue = GetMarketHighestLow( + bar_index, + marketLength + ); + marketHighestLowBuffer[bar_index] = highestLowValue; + + // + // Highest Open ... + double highestOpenValue = GetMarketHighestOpen( + bar_index, + marketLength + ); + marketHighestOpenBuffer[bar_index] = highestOpenValue; + + // + // Highest Close ... + double highestCloseValue = GetMarketHighestClose( + bar_index, + marketLength + ); + marketHighestCloseBuffer[bar_index] = highestCloseValue; + + // + // Lowest High ... + double lowestHighValue = GetMarketLowestHigh( + bar_index, + marketLength + ); + marketLowestHighBuffer[bar_index] = lowestHighValue; + + // + // Lowest Low ... + double lowestLowValue = GetMarketLowestLow( + bar_index, + marketLength + ); + marketLowestLowBuffer[bar_index] = lowestLowValue; + + // + // Lowest Open ... + double lowestOpenValue = GetMarketLowestOpen( + bar_index, + marketLength + ); + marketLowestOpenBuffer[bar_index] = lowestOpenValue; + + // + // Lowest Close ... + double lowestCloseValue = GetMarketLowestClose( + bar_index, + marketLength + ); + marketLowestCloseBuffer[bar_index] = lowestCloseValue; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/Indicators/x-saherelm.xmtrend.mq4 b/Bkp/Used/14020425/Indicators/x-saherelm.xmtrend.mq4 new file mode 100644 index 0000000..aa89e7b --- /dev/null +++ b/Bkp/Used/14020425/Indicators/x-saherelm.xmtrend.mq4 @@ -0,0 +1,221 @@ + /////////////////////////////////////////////////////// +// +// SaherElm IT Center XMTR Indicator +// --------------------------------------------- +// retrieve market base info ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XMKT Indicator" +#property strict + +// +// START Inputs ... +// +// +// Market Specifications ... +input int marketLength = 20; // Market Length +input int atrMultiplier = 1; // ATR Multiplier +input int atrLength = 5; // ATR Period +input ENUM_APPLIED_PRICE source = PRICE_CLOSE; // Source +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// define indicator buffers ... +#property indicator_buffers 3 +#property indicator_plots 3 + +// +// Declare Buffers ... +#define trendBufferIndex 0 +#define upTrendBufferIndex 1 +#define downTrendBufferIndex 2 + +// +double trendBuffer[]; +double upTrendBuffer[]; +double downTrendBuffer[]; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (marketLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XMTR"; + + // + // TREND ... + SetIndexLabel(trendBufferIndex, "Trend"); + SetIndexBuffer(trendBufferIndex, trendBuffer); + SetIndexStyle( + trendBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + clrNONE + ); + + // + // UP Trend ... + SetIndexLabel(upTrendBufferIndex, "Up Trend"); + SetIndexBuffer(upTrendBufferIndex, upTrendBuffer); + SetIndexStyle( + upTrendBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + clrNONE + ); + + // + // DOWN Trend ... + SetIndexLabel(downTrendBufferIndex, "Down Trend"); + SetIndexBuffer(downTrendBufferIndex, downTrendBuffer); + SetIndexStyle( + downTrendBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + clrNONE + ); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + RemoveDraws(logTag); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(marketLength, 3); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Short Cycle ... + CalculateBuffers( + i, + low + ); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculate Short Cycle ... +void CalculateBuffers( + const int bar_index, + const double &low[] +) { + // + double atr = GetMarketTRSMA( + bar_index, + atrLength + ); + + // + double smoothedAtr = (atr * atrMultiplier); + double upTrend = low[bar_index] - smoothedAtr; + double downTrend = low[bar_index] + smoothedAtr; + + // + double cciValue = GetMarketCCI( + bar_index, + marketLength, + source + ); + + // + // TODO: Complete this ... +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/Indicators/x-saherelm.zigzag.mq4 b/Bkp/Used/14020425/Indicators/x-saherelm.zigzag.mq4 new file mode 100644 index 0000000..fbb073c --- /dev/null +++ b/Bkp/Used/14020425/Indicators/x-saherelm.zigzag.mq4 @@ -0,0 +1,476 @@ +///////////////////////////////////////////////////////////////// +// +// SaherElm IT Center ZigZag Indicator +// ------------------------------------------------------------- +// this indicator provides signals for Main strategy ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +//////////////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm ZigZag Indicator" +#property strict + +// +// START Inputs ... +// +input int depth = 12; // Depth +input int deviation = 5; // Deviation +input int backStep = 3; // BackStep +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// here we specify logging enabled or not ... +bool enableLogging = true; + +// +// this is a Tag which attached to our Logger ... +string logTag = "XS_ZG"; + +// +#property indicator_chart_window + +// +#property indicator_buffers 1 + +// +#property indicator_width1 1 +#property indicator_color1 clrAqua +// #property indicator_type1 DRAW_SECTION +// #property indicator_style1 STYLE_SOLID + +// // +// #property indicator_width2 1 +// #property indicator_color2 clrNONE +// #property indicator_type2 DRAW_NONE +// #property indicator_style2 STYLE_SOLID + +// // +// #property indicator_width3 1 +// #property indicator_color3 clrNONE +// #property indicator_type3 DRAW_NONE +// #property indicator_style3 STYLE_SOLID + +// +// Buffers ... +// +#define zigzagBufferIndex 0 +#define highBufferIndex 1 +#define lowBufferIndex 2 +// #define ziggyBufferIndex 3 + +// +double zigzagBuffer[]; +double highBuffer[]; +double lowBuffer[]; +// double ziggyBuffer[]; + +// +// recounting's depth of extremums ... +int level=3; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + depth <= 0 || + backStep < 0 || + deviation < 0 || + backStep >= depth + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Set Index Buffers of ZigZag ... + IndicatorBuffers(3); + + // + // ZigZag Buffer ... + SetIndexBuffer(zigzagBufferIndex, zigzagBuffer); + SetIndexStyle(zigzagBufferIndex, DRAW_SECTION); + SetIndexLabel(zigzagBufferIndex, "ZigZag"); + + // + // High Buffer ... + SetIndexBuffer(highBufferIndex, highBuffer); + SetIndexLabel(highBufferIndex, ""); + + // + // Low Buffer ... + SetIndexBuffer(lowBufferIndex, lowBuffer); + SetIndexLabel(lowBufferIndex, ""); + + // + // Ziggy Buffer ... + // SetIndexBuffer(ziggyBufferIndex, ziggyBuffer); + // SetIndexLabel(ziggyBufferIndex, ""); + + // + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + int maxLength = MathMax(depth, backStep); + + int i; + int counterZ; + int back; + int pos; + + // + int lastlowpos = 0; + int lasthighpos = 0; + int whatlookfor = 0; + + // + double extremum; + + // + double curlow = 0.0; + double curhigh = 0.0; + double lasthigh = 0.0; + double lastlow = 0.0; + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // first calculations ... + if (prev_calculated == 0) { + limit = InitializeBuffers(); + } else { + // + // find first extremum in the depth ExtLevel or 100 last bars ... + i = counterZ = 0; + while(counterZ < level && i < 100) { + // + if(zigzagBuffer[i] != 0.0) { + counterZ++; + } + + // + i++; + } + + // + // no extremum found - recounting all from begin ... + if(counterZ == 0) { + limit = InitializeBuffers(); + } else { + // + // set start position to found extremum position ... + limit = i-1; + + // + //--- what kind of extremum? + if(lowBuffer[i] != 0.0) { + // + // low extremum ... + curlow = lowBuffer[i]; + + // + // will look for the next high extremum ... + whatlookfor=1; + } else { + // + // high extremum ... + curhigh = highBuffer[i]; + + // + // will look for the next low extremum ... + whatlookfor=-1; + } + + // + // clear the rest data ... + for(i = limit - 1; i >= 0; i--) { + // + lowBuffer[i]=0.0; + highBuffer[i]=0.0; + zigzagBuffer[i]=0.0; + } + } + } + + // + // Main Calculation Loop ... + for (i = limit; i >= 0; i--) { + // + // find lowest low in depth of bars ... + extremum = low[ + iLowest( + _Symbol, + _Period, + MODE_LOW, + depth, + i + ) + ]; + + // + // this lowest has been found previously ... + if (extremum == lastlow) { + extremum = 0.0; + } else { + // + // new last low ... + lastlow=extremum; + + // + // discard extremum if current low is too high ... + if(low[i] - extremum > deviation * _Point) { + extremum=0.0; + } else { + // + // clear previous extremums in backstep bars ... + for(back = 1; back <= backStep; back++) { + // + pos = i + back; + + // + if(lowBuffer[pos] != 0 && lowBuffer[pos] > extremum) { + lowBuffer[pos] = 0.0; + } + } + } + } + + // + // found extremum is current low ... + if (low[i] == extremum) { + lowBuffer[i] = extremum; + } else { + lowBuffer[i] = 0.0; + } + + // + // find highest high in depth of bars ... + extremum = high[ + iHighest( + _Symbol, + _Period, + MODE_HIGH, + depth, + i + ) + ]; + + // + // this highest has been found previously ... + if (extremum == lasthigh) { + extremum = 0.0; + } else { + // + // new last high ... + lasthigh=extremum; + + // + // discard extremum if current high is too low ... + if (extremum - high[i] > deviation * Point) { + extremum = 0.0; + } else { + // + // clear previous extremums in backstep bars ... + for(back = 1; back <= backStep; back++) { + // + pos = i + back; + + // + if (highBuffer[pos] != 0 && highBuffer[pos] < extremum) { + highBuffer[pos] = 0.0; + } + } + } + } + + // + // found extremum is current high ... + if (high[i] == extremum) { + highBuffer[i] = extremum; + } else { + highBuffer[i] = 0.0; + } + } + + // + // final cutting ... + if( whatlookfor == 0) { + // + lastlow = 0.0; + lasthigh = 0.0; + } else { + // + lastlow = curlow; + lasthigh = curhigh; + } + + // + for(i = limit; i >= 0; i--) { + switch(whatlookfor) { + // + // look for peak or lawn ... + case 0: + // + if (lastlow == 0.0 && lasthigh == 0.0) { + if(highBuffer[i]!=0.0) { + // + lasthigh = High[i]; + lasthighpos = i; + whatlookfor = -1; + + // + zigzagBuffer[i] = lasthigh; + } + + // + if(lowBuffer[i] != 0.0) { + // + lastlow = Low[i]; + lastlowpos = i; + whatlookfor = 1; + + // + zigzagBuffer[i] = lastlow; + } + } + break; + + // + // look for peak ... + case 1: + // + if ( + lowBuffer[i] != 0.0 && + lowBuffer[i] < lastlow && + highBuffer[i] == 0.0 + ) { + // + zigzagBuffer[lastlowpos] = 0.0; + lastlowpos = i; + lastlow = lowBuffer[i]; + zigzagBuffer[i] = lastlow; + } + + // + if(highBuffer[i] != 0.0 && lowBuffer[i] == 0.0) { + // + lasthigh = highBuffer[i]; + lasthighpos = i; + zigzagBuffer[i] = lasthigh; + + // + whatlookfor=-1; + } + break; + + // + // look for lawn ... + case -1: + // + if( + highBuffer[i] != 0.0 && + highBuffer[i] > lasthigh && + lowBuffer[i] == 0.0 + ) { + // + zigzagBuffer[lasthighpos] = 0.0; + lasthighpos = i; + lasthigh = highBuffer[i]; + zigzagBuffer[i] = lasthigh; + } + + // + if( + lowBuffer[i] !=0.0 && + highBuffer[i] == 0.0 + ) { + // + lastlow = lowBuffer[i]; + lastlowpos = i; + zigzagBuffer[i] = lastlow; + whatlookfor=1; + } + break; + } + } + + // + // Done ... + return rates_total; +} + +// +// De Initialization ... +void OnDeinit(const int reason) { + // + // RemoveDraws(signalPrefix); + ChartRedraw(0); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +int InitializeBuffers() { + // + ArrayInitialize(lowBuffer,0.0); + ArrayInitialize(highBuffer, 0.0); + ArrayInitialize(zigzagBuffer, 0.0); + + // + //--- first counting position + return(Bars - depth); +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/Libraries/x-saherelm.cci.signal.lib.mq4 b/Bkp/Used/14020425/Libraries/x-saherelm.cci.signal.lib.mq4 new file mode 100644 index 0000000..c572f3d --- /dev/null +++ b/Bkp/Used/14020425/Libraries/x-saherelm.cci.signal.lib.mq4 @@ -0,0 +1,472 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 CCI Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// Based Signal Conditions ... +struct XCCILongSignalConditions { + // + datetime start; + + // + datetime crossOverMinusHundredTime; + datetime crossUnderMinusHundredTime; + + // + double crossOverSlope; +}; + +// +static XCCILongSignalConditions cciLongConds; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Signal Conditions ... +void CheckCCILongSignalConditions( + const int bar_index, + const int marketLen, + // + const double smoother = 10 +) { + // + // Retrieve Bar Time ... + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // LONG: + // wait for cci cross under -100 + // then wait for cross over -100 + // slope of crossing over ??? ... + if (cciLongConds.start == 0) { + // LogMessage("Start"); + cciLongConds.start = barTime; + return; + } + + // + // Check Start Time ... + if (cciLongConds.start == 0) { + return; + } + + // + // Read current, prev, and prevPrev CCI ... + double cci = GetMarketCCI( + bar_index, + marketLen + ); + double cci1 = GetMarketCCI( + bar_index + 1, + marketLen + ); + double cci2 = GetMarketCCI( + bar_index + 2, + marketLen + ); + + // + // Find Cross Under -100 ... + bool isCrossUnderMinusHundred = + cci < -105 && !(cci1 < -105) + && MathAbs(MathAbs(cci) - MathAbs(cci1)) > smoother + ; + + // + // Find Cross Over -100 ... + bool isCrossOverMinusHundred = + cci > -105 && !(cci1 > -105) + && MathAbs(cci - cci1) > smoother + ; + + // + // Fill Conditions ... + if ( + isCrossUnderMinusHundred + && cciLongConds.crossUnderMinusHundredTime == 0 + && cciLongConds.crossOverMinusHundredTime == 0 + ) { + // LogMessage("Cross Under ..."); + cciLongConds.crossUnderMinusHundredTime = barTime; + return; + } + + // + // Fill Conditions ... + if ( + isCrossOverMinusHundred + && cciLongConds.crossOverMinusHundredTime == 0 + && cciLongConds.crossUnderMinusHundredTime != 0 + ) { + // + // LogMessage("Cross Over ..."); + cciLongConds.crossOverMinusHundredTime = barTime; + } + + // + // Prevent Going forward untill Cross Under Happens ... + if (cciLongConds.crossUnderMinusHundredTime == 0) { + return; + } + + // + // Prevent from Going forward untill Cross Over Happens ... + if (cciLongConds.crossOverMinusHundredTime == 0) { + return; + } + + // + // Calculate Slope ... + double x1 = 0; + double y1 = cci1; + double x2 = 1; + double y2 = cci; + + // + // Calculat Line Slope ... + double tSlope = GetSlope( + x1, y1, x2, y2 + ); + + // + cciLongConds.crossOverSlope = tSlope; + // LogMessage("Slope: " + tSlope); +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateCCILongSignal( + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r // Risk to Reward ratio ... +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if (!ValidateCCILongConditions()) { + return result; + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double entryPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double exitPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + int llIdx = GetLowestLowOFCCILongPeriodIndex(); + double ll = + GetMarketLowestLow( + bar_index, + marketLen + ); + // GetLowestLowOFCCILongPeriod(); + + // + int hhIdx = GetHighestHighOfCCILongPeriodIndex(); + double hh = GetHighestHighOfCCILongPeriod(); + // GetMarketHighestHigh( + // bar_index, + // marketLen + // ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = MathMin(openPrice, closePrice) - ll; + double reward = risk * r2r; + + // + double sl = 0; // ll; + double tp = entryPrice + reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = X_SIGNAL_LONG; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_CCI_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = X_SIGNAL_LONG; + result.provider = X_CCI_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateCCILongConditions() { + // + int crossUnderBarIndex = + cciLongConds.crossUnderMinusHundredTime != 0 + ? iBarShift( + _Symbol, + _Period, + cciLongConds.crossUnderMinusHundredTime + ) + : -1 + ; + + // + int crossOverBarIndex = + cciLongConds.crossOverMinusHundredTime != 0 + ? iBarShift( + _Symbol, + _Period, + cciLongConds.crossOverMinusHundredTime + ) + : -1 + ; + + // + bool isConditionsFilled = + // + cciLongConds.start != 0 + && cciLongConds.crossUnderMinusHundredTime != 0 + && cciLongConds.crossOverMinusHundredTime != 0 + && cciLongConds.crossUnderMinusHundredTime >= cciLongConds.start + && cciLongConds.crossOverMinusHundredTime > cciLongConds.crossUnderMinusHundredTime + ; + + // + bool isLogicPassed = + // + crossOverBarIndex > 0 + && crossUnderBarIndex > 0 + && crossUnderBarIndex > crossOverBarIndex + && (crossUnderBarIndex - crossOverBarIndex) >= 5 + ; + + // + bool result = + // + isConditionsFilled + && isLogicPassed + && cciLongConds.crossOverSlope > 0 + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearCCILongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearCCILongSignalConditions() { + // + cciLongConds.start = 0; + cciLongConds.crossOverSlope = 0; + cciLongConds.crossOverMinusHundredTime = 0; + cciLongConds.crossUnderMinusHundredTime = 0; +} + +// +int GetHighestHighOfCCILongPeriodIndex() { + // + int crossUnderBarIndex = iBarShift( + _Symbol, + _Period, + cciLongConds.crossUnderMinusHundredTime + ); + + // + int crossOverBarIndex = iBarShift( + _Symbol, + _Period, + cciLongConds.crossOverMinusHundredTime + ); + + // + int result = iHighest( + _Symbol, + _Period, + MODE_HIGH, + crossUnderBarIndex - crossOverBarIndex, + crossOverBarIndex + ); + + // + return result; +} + +// +double GetHighestHighOfCCILongPeriod() { + // + int index = GetHighestHighOfCCILongPeriodIndex(); + + // + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + return result; +} + +// +int GetLowestLowOFCCILongPeriodIndex() { + // + int crossUnderBarIndex = iBarShift( + _Symbol, + _Period, + cciLongConds.crossUnderMinusHundredTime + ); + + // + int crossOverBarIndex = iBarShift( + _Symbol, + _Period, + cciLongConds.crossOverMinusHundredTime + ); + + // + int result = iLowest( + _Symbol, + _Period, + MODE_LOW, + crossUnderBarIndex - crossOverBarIndex, + crossOverBarIndex + ); + + // + return result; +} + +// +double GetLowestLowOFCCILongPeriod() { + // + int index = GetLowestLowOFCCILongPeriodIndex(); + + // + double result = iLow( + _Symbol, + _Period, + index + ); + + // + return result; +} + +// +// Check XMA State for Long Signals ... +bool IsReadyForCCILongSignals( + const XState &states[] +) { + // + bool result = false; + + // + XStateInfo info = ParseXMAStates(states); + + // + result = + // + true + // + // && states[1].mc.fast > states[1].mc.slow + // && MathAbs(states[1].mc.fast - states[1].mc.slow) > 100 * _Point + // && states[1].marketMiddleage > states[1].sc.fast + // && states[1].marketMiddleage > states[1].mc.fast + ; + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020425/Libraries/x-saherelm.draw.lib.mq4 b/Bkp/Used/14020425/Libraries/x-saherelm.draw.lib.mq4 new file mode 100644 index 0000000..08fefa7 --- /dev/null +++ b/Bkp/Used/14020425/Libraries/x-saherelm.draw.lib.mq4 @@ -0,0 +1,1670 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Start Arrow Functions ... +// +// +// Draw an Arrow Object on Chart ... +bool DrawArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // arrow name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const uchar arrowCode = OBJ_ARROW_UP, // arrow code + const ENUM_ARROW_ANCHOR anchor = ANCHOR_BOTTOM, // anchor point position + const color clr = clrAqua, // arrow color + const ENUM_LINE_STYLE style = STYLE_SOLID, // border line style + const int width = 3, // arrow size + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // Order Object ... +) { + // + // set anchor point coordinates if they are not set ... + ChangeArrowEmptyPoint(time, price); + + // + // reset the error value ... + ResetLastError(); + + // + // create an arrow ... + if(!ObjectCreate(chartID, name, OBJ_ARROW, subWindow, time, price)) { + // + string message = StringConcatenate(__FUNCTION__, + ": failed to create an arrow! Error code = ", + GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the arrow code ... + ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, arrowCode); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set the arrow color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set the border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set the arrow's size ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the arrow by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is false by default, if you want making it possible to highlight and move the object + // change it to true ... + ObjectSetInteger(chartID,name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point of Arrow ... +bool MoveArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if(!time) { + time = TimeCurrent(); + } + + // + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete an arrow ... +bool DeleteArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow" // arrow name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete an arrow ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete an arrow! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the arrow code ... +bool ArrowCodeChange( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + const uchar code = 252 // arrow code +) { + // + // reset the error value ... + ResetLastError(); + + // + // change the arrow code ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, code)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the arrow code! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change anchor type ... +bool ArrowAnchorChange( + const long chartID = 0, // chart's ID + const string name="Arrow", // object name + const ENUM_ARROW_ANCHOR anchor = ANCHOR_TOP // anchor type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change anchor type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change anchor type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeArrowEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } +} +// +// End Arrow Functions ... +// + +// +// Start Horizontal Line Functions ... +// +// +// Create, Draw the horizontal line ... +bool DrawHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + const int subWindow = 0, // subwindow index + double price = 0, // line price + const color clr = clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the price is not set, set it at the current Bid price level ... + if(!price) { + price=SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // create a horizontal line ... + if(!ObjectCreate(chartID, name, OBJ_HLINE, subWindow, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move horizontal line ... +bool MoveHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + double price = 0 // line price +) { + // + // if the line price is not set, move it to the current Bid price level ... + if(!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move a horizontal line ... + if(!ObjectMove(chartID, name, 0, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete a horizontal line ... +bool DeleteHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a horizontal line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End Horizontal Line Functions ... +// + +// +// Start Vertical Line Functions ... +// +// +// Create the vertical line ... +bool DrawVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + const int sub_window = 0, // subwindow index + datetime time = 0, // line time + const color clr=clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the line time is not set, draw it via the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value + ResetLastError(); + + // + // create a vertical line ... + if (!ObjectCreate(chartID, name, OBJ_VLINE, sub_window, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return true; +} + +// +// Move the vertical line ... +bool MoveVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + datetime time = 0 // line time +) { + // + // if line time is not set, move the line to the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the vertical line ... + if(!ObjectMove(chartID, name, 0, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the vertical line ... +bool DeleteVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the vertical line ... + if (!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // successful execution ... + return true; +} +// +// End Vertical Line Functions ... +// + +// +// Start RectangleLabel Functions ... +// +// +// Create Rectangle Label Object ... +bool DrawRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int subWindow = 0, // subwindow index + const int x = 0, // X coordinate + const int y = 0, // Y coordinate + const int width = 50, // width + const int height = 18, // height + const color back_clr = C'236,233,216', // background color + const ENUM_BORDER_TYPE border = BORDER_SUNKEN, // border type + const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring + const color clr = clrRed, // flat border color (Flat) + const ENUM_LINE_STYLE style = STYLE_SOLID, // flat border style + const int lineWidth = 1, // flat border width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // reset the error value ... + ResetLastError(); + + // + //--- create a rectangle label + if(!ObjectCreate(chartID, name, OBJ_RECTANGLE_LABEL, subWindow, 0, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set label coordinates ... + ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x); + ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y); + + // + // set label size ... + ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width); + ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height); + + // + // set background color ... + ObjectSetInteger(chartID, name, OBJPROP_BGCOLOR, back_clr); + + // + // set border type ... + ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border); + + // + // set the chart's corner, relative to which point coordinates are defined ... + ObjectSetInteger(chartID, name, OBJPROP_CORNER, corner); + + // + // set flat border color (in Flat mode) ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set flat border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set flat border width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, lineWidth); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the label by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move Rectangle Label .. +bool MoveRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int x = 0, // X coordinate + const int y=0 // Y coordinate +) { + // + // reset the error value ... + ResetLastError(); + + // + // move the rectangle label ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move X coordinate of the label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move Y coordinate of the label! Error code = ",GetLastError() + ); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the rectangle label ... +bool DeleteRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel" // label name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the label ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change Rectangle Label Size ... +bool ChangeSizeRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int width = 50, // label width + const int height = 18 // label height +) { + // + // reset the error value ... + ResetLastError(); + + // + // change label size ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's width! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's height! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change rectangle label border type ... +bool RectLabelChangeBorderType( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const ENUM_BORDER_TYPE border = BORDER_SUNKEN // border type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change border type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the border type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End RectangleLabel Functions ... +// + +// +// Start TrendLine Funcions ... +// +// Create a trend line by the given coordinates ... +bool DrawTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrYellow, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool rayRight = false, // line's continuation to the right + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeTrendLineEmptyPoints( + time1, + price1, + time2, + price2 + ); + + // + // reset the error value ... + ResetLastError(); + + // + // create a trend line by the given coordinates ... + if(!ObjectCreate(chartID, name, OBJ_TREND, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the line's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move trend line anchor point ... | +bool ChangeTrendLinePoint( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int pointindex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move trend line's anchor point ... + if(!ObjectMove(chartID, name, pointindex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// The function deletes the trend line from the chart ... +bool DeleteTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a trend line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of trend line's anchor points and set default ... +// values for empty ones ... +void ChangeTrendLineEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the first point's time is not set, it will be on the current bar ... + if (!time1) { + time1 = TimeCurrent(); + } + + // + // if the first point's price is not set, it will have Bid value ... + if (!price1) { + price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // if the second point's time is not set, it is located 9 bars left from the second one ... + if (!time2) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(), Period(), time1, 10, temp); + + // + // set the second point 9 bars left from the first one ... + time2 = temp[0]; + } + + // + // if the second point's price is not set, it is equal to the first point's one ... + if (!price2) { + price2 = price1; + } +} +// +// End TrendLine Functions ... +// + +// +// Start Text Functions ... +// +// Create and Draw a Text Object ... +bool DrawText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const string text = "Text", // the text itself + const string font = "Arial", // font + const int fontSize = 10, // font size + const color clr = clrRed, // color + const double angle = 0.0, // text slope + const ENUM_ANCHOR_POINT anchor = ANCHOR_CENTER, // anchor type + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor point coordinates if they are not set ... + ChangeTextEmptyPoint(time,price); + + // + // reset the error value ... + ResetLastError(); + + // + //--- create Text object + if(!ObjectCreate(chartID, name, OBJ_TEXT, subWindow, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the text ... + ObjectSetString(chartID, name , OBJPROP_TEXT, text); + + // + // set text font ... + ObjectSetString(chartID, name, OBJPROP_FONT, font); + + // + // set font size ... + ObjectSetInteger(chartID, name, OBJPROP_FONTSIZE, fontSize); + + // + // set the slope angle of the text ... + ObjectSetDouble(chartID, name, OBJPROP_ANGLE, angle); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the object by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID ,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point ... +bool MoveText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + //--- if point position is not set, move it to the current bar having Bid price + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point .. + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the object text ... +bool ChangeText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const string text = "Text" // text +) { + // + // reset the error value ... + ResetLastError(); + + // + // change object text ... + if(!ObjectSetString(chartID, name, OBJPROP_TEXT, text)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the text! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Text object ... +bool DeleteText( + const long chartID = 0, // chart's ID + const string name = "Text" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeTextEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + } +// +// End Text Functions ... +// + +// +// Start Fibonacchi Functions ... +// +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawFibonacci( + const long chartID = 0, // chart's ID + const string name="Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrRed, // object color + const ENUM_LINE_STYLE style = STYLE_SOLID, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawCustomFibonacci( + // + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + // + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrAqua, // object color + const ENUM_LINE_STYLE style = STYLE_DOT, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // Change Levels Of Fibonacci ... + bool result = FibonacciLevelsSet( + levels, + values, + colors, + styles, + widths, + descriptions, + chartID, + name + ); + + // + // successful execution ... + return result; +} + +// +// Set number of levels and their parameters ... +bool FibonacciLevelsSet( + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // check array sizes ... + if( + levels!=ArraySize(colors) || + levels!=ArraySize(styles) || + levels!=ArraySize(widths) || + levels!=ArraySize(widths) + ) { + // + string message = StringConcatenate( + __FUNCTION__, + ": array length does not correspond to the number of levels, error!" + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the number of levels ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELS, levels); + + // + // set the properties of levels in the loop ... + for(int i = 0; i < levels; i++) { + // + // level value ... + ObjectSetDouble(chartID, name, OBJPROP_LEVELVALUE, i, values[i]); + + // + // level color ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELCOLOR, i, colors[i]); + + // + // level style ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELSTYLE, i, styles[i]); + + // + // level width ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELWIDTH, i, widths[i]); + + // + // level description ... + // ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, DoubleToString(100 * values[i], 1)); + ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, descriptions[i]); + } + + // + // successful execution ... + return(true); +} + +// +// Move Fibonacci Retracement anchor point ... +bool FibonacciPointChange( + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int pointIndex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, pointIndex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Fibonacci Retracement ... +bool DeleteFibonachi( + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Fibonacci Retracement\"! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of Fibonacci Retracement anchor points and set +// default values for empty ones ... +void ChangeFibonacciEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the second point's time is not set, it will be on the current bar ... + if (!time2) { + time2 = TimeCurrent(); + } + + // + // if the second point's price is not set, it will have Bid value ... + if (!price2) { + price2 = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // if the first point's time is not set, it is located 9 bars left from the second one ... + if (!time1) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(),Period(),time2,10,temp); + + // + // set the first point 9 bars left from the second one ... + time1 = temp[0]; + } + + // + // if the first point's price is not set, move it 200 points below the second one ... + if (!price1) { + price1 = price2 - 200 * SymbolInfoDouble(_Symbol, SYMBOL_POINT); + } +} +// +// End Fibonacci Functions ... +// + + +// +// Start General Functions ... +// +// +// Remove all Drawn Objects ... +void RemoveDraws(const string &tag) { + // + for(int iObj=ObjectsTotal()-1; iObj >= 0; iObj--) { + // + string on = ObjectName(iObj); + if (StringFind(on, tag) == 0) { + ObjectDelete(on); + } + } +} +// +// End General Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/Libraries/x-saherelm.indicator.lib.mq4 b/Bkp/Used/14020425/Libraries/x-saherelm.indicator.lib.mq4 new file mode 100644 index 0000000..01424b5 --- /dev/null +++ b/Bkp/Used/14020425/Libraries/x-saherelm.indicator.lib.mq4 @@ -0,0 +1,941 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Indicator Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +static double zigZags[]; +// +// END Global Requirement Functions ... +// + +// +// START Indicator Reading Data ... +// +// +// START XMKT Data ... +// +XMKTState GetXMKT( + const int bar_index, + const int marketLen, + // + const bool showHighestHigh = true, + const bool showHighestLow = true, + const bool showHighestOpen = true, + const bool showHighestClose = true, + const bool showLowestHigh = true, + const bool showLowestLow = true, + const bool showLowestOpen = true, + const bool showLowestClose = true, + const color highestHighColor = clrDeepPink, + const color highestLowColor = clrDarkOrange, + const color highestOpenColor = clrDodgerBlue, + const color highestCloseColor = clrOrchid, + const color lowestHighColor = clrHotPink, + const color lowestLowColor = clrOrange, + const color lowestOpenColor = clrPowderBlue, + const color lowestCloseColor = clrMediumOrchid, + const ENUM_LINE_STYLE highestHighStyle = STYLE_DOT, + const ENUM_LINE_STYLE highestLowStyle = STYLE_DOT, + const ENUM_LINE_STYLE highestOpenStyle = STYLE_DOT, + const ENUM_LINE_STYLE highestCloseStyle = STYLE_DOT, + const ENUM_LINE_STYLE lowestHighStyle = STYLE_DOT, + const ENUM_LINE_STYLE lowestLowStyle = STYLE_DOT, + const ENUM_LINE_STYLE lowestOpenStyle = STYLE_DOT, + const ENUM_LINE_STYLE lowestCloseStyle = STYLE_DOT +) { + // + XMKTState result = {}; + + // + string xmktIndName = "x-saherelm.xmarket"; + + // + int highestHighBufferIndex = 0; + int highestLowBufferIndex = 1; + int highestOpenBufferIndex = 2; + int highestCloseBufferIndex = 3; + int lowestHighBufferIndex = 4; + int lowestLowBufferIndex = 5; + int lowestOpenBufferIndex = 6; + int lowestCloseBufferIndex = 7; + + // + // Highest High ... + double highestHigh = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + highestHighBufferIndex, // Buffer Index ... + bar_index + ); + result.highestHigh = highestHigh; + + // + // Highest Low ... + double highestLow = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + highestLowBufferIndex, // Buffer Index ... + bar_index + ); + result.highestLow = highestLow; + + // + // Highest Open ... + double highestOpen = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + highestOpenBufferIndex, // Buffer Index ... + bar_index + ); + result.highestOpen = highestOpen; + + // + // Highest Close ... + double highestClose = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + highestCloseBufferIndex, // Buffer Index ... + bar_index + ); + result.highestClose = highestClose; + + // + // Lowest High ... + double lowestHigh = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + lowestHighBufferIndex, // Buffer Index ... + bar_index + ); + result.lowestHigh = lowestHigh; + + // + // Lowest Low ... + double lowestLow = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + lowestLowBufferIndex, // Buffer Index ... + bar_index + ); + result.lowestLow = lowestLow; + + // + // Lowest Open ... + double lowestOpen = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + lowestOpenBufferIndex, // Buffer Index ... + bar_index + ); + result.lowestOpen = lowestOpen; + + // + // Lowest Close ... + double lowestClose = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + lowestCloseBufferIndex, // Buffer Index ... + bar_index + ); + result.lowestClose = lowestClose; + + // + return result; +} +// +// END XMKT Data ... +// + +// +// START XOSC Data ... +// +XCycleState GetXOSC( + const int bar_index, + const int marketLen, + // + const int fastMult, + const int slowMult, + // + const double fastMMul = 1.0, + const double slowMMul = 3.0 +) { + // + XCycleState result = {}; + + // + string oscIndName = "x-saherelm.osc"; + + // + // Prepare OSC Inputs ... + // + int fastLength = fastMult * marketLen; + int slowLength = slowMult * marketLen; + + // + // Fast ... + double fast = iCustom( + _Symbol, + _Period, + oscIndName, + // + // Inputs ... + fastLength, + fastMMul, + slowLength, + slowMMul, + // + 0, // Buffer Index ... + bar_index + ); + result.fast = fast; + + // + // Slow ... + double slow = iCustom( + _Symbol, + _Period, + oscIndName, + // + // Inputs ... + fastLength, + fastMMul, + slowLength, + slowMMul, + // + 1, // Buffer Index ... + bar_index + ); + result.slow = slow; + + // + return result; +} +// +// END XOSC Data ... +// + +// +// START XBND Data ... +// +XBndState GetXBND( + const int bar_index, + // + const int marketLen = 10, // Market Length ... + const int shift = 0, // MA Shift ... + const ENUM_MA_METHOD method = MODE_SMA // MA Method ... +) { + // + XBndState result = {}; + + // + double high = GetMA( + bar_index, + marketLen, + shift, + method, + PRICE_HIGH + ); + result.high = high; + + // + double open = GetMA( + bar_index, + marketLen, + shift, + method, + PRICE_OPEN + ); + result.open = open; + + // + double close = GetMA( + bar_index, + marketLen, + shift, + method, + PRICE_CLOSE + ); + result.close = close; + + // + double low = GetMA( + bar_index, + marketLen, + shift, + method, + PRICE_LOW + ); + result.low = low; + + // + return result; +} +// +// END XBND Data ... +// + +// +// START ZigZag Data ... +// +void PrepareZigZagState( + const int bar_index, + // + const int depth = 12, + const int deviation = 5, + const int backStep = 3 +) { + // + string zigzagIndName = "x-saherelm.zigzag"; + + // + ArrayFree(zigZags); + ArrayResize( + zigZags, + 3 + ); + + // + double zigZag = 0; + int index = 0; + int i = bar_index; + while (index < 3) { + // + zigZag = iCustom( + _Symbol, + _Period, + zigzagIndName, + // + // Inputs ... + depth, + deviation, + backStep, + // + 0, // Buffer Index ... + i + ); + + // + if (zigZag > 0) { + // + zigZags[index] = zigZag; + index++; + } + + // + i++; + } +} +// +// END ZigZag Data ... +// + +// +// START XMA Data ... +// +// +// Retrieve Short Cycle ... +XCycleState GetXMASC( + const int bar_index, + const int marketLen, + const int fastMultiplier, + const int slowMultiplier, + // + const int shift = 0, + const ENUM_MA_METHOD method = MODE_SMA, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE +) { + // + XCycleState result = {}; + + // + int fastLength = marketLen * fastMultiplier; + int slowLength = marketLen * slowMultiplier; + + // + double fast = iMA( + _Symbol, + _Period, + fastLength, + shift, + method, + appliedPrice, + bar_index + ); + result.fast = fast; + + // + double slow = iMA( + _Symbol, + _Period, + slowLength, + shift, + method, + appliedPrice, + bar_index + ); + result.slow= slow; + + // + return result; +} + +// +// Retrieve Medium Cycle ... +XCycleState GetXMAMC( + const int bar_index, + const int marketLen, + const int fastMultiplier, + const int slowMultiplier, + // + const int shift = 0, + const ENUM_MA_METHOD method = MODE_SMA, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE +) { + // + XCycleState result = {}; + + // + int fastLength = marketLen * fastMultiplier; + int slowLength = marketLen * slowMultiplier; + + // + double fast = iMA( + _Symbol, + _Period, + fastLength, + shift, + method, + appliedPrice, + bar_index + ); + result.fast = fast; + + // + double slow = iMA( + _Symbol, + _Period, + slowLength, + shift, + method, + appliedPrice, + bar_index + ); + result.slow= slow; + + // + return result; +} + +// +// Retrieve Long Cycle ... +XCycleState GetXMALC( + const int bar_index, + const int marketLen, + const int fastMultiplier, + const int slowMultiplier, + // + const int shift = 0, + const ENUM_MA_METHOD method = MODE_SMA, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE +) { + // + XCycleState result = {}; + + // + int fastLength = marketLen * fastMultiplier; + int slowLength = marketLen * slowMultiplier; + + // + double fast = iMA( + _Symbol, + _Period, + fastLength, + shift, + method, + appliedPrice, + bar_index + ); + result.fast = fast; + + // + double slow = iMA( + _Symbol, + _Period, + slowLength, + shift, + method, + appliedPrice, + bar_index + ); + result.slow = slow; + + // + return result; +} + +// +// Retrieve Long Cycle ... +XCycleState GetXMANN( + const int bar_index, + // + const int shift = 0, + const ENUM_MA_METHOD method = MODE_SMA, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE +) { + // + XCycleState result = {}; + + // + int fastLength = 10; + int slowLength = 50; + + // + double fast = iMA( + _Symbol, + _Period, + fastLength, + shift, + method, + appliedPrice, + bar_index + ); + result.fast = fast; + + // + double slow = iMA( + _Symbol, + _Period, + slowLength, + shift, + method, + appliedPrice, + bar_index + ); + result.slow = slow; + + // + return result; +} + +// +// Retrieve Middle ... +double GetXMAMM( + const int bar_index, + const int marketLen, + const double multiplier, + // + const int shift = 0, + const ENUM_MA_METHOD method = MODE_EMA, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_MEDIAN +) { + // + double result = 0; + + // + int length = (int)(marketLen * multiplier); + + // + double middle = iMA( + _Symbol, + _Period, + length, + shift, + method, + appliedPrice, + bar_index + ); + result = middle; + + // + return result; +} + +// +// Retrieve XMA Parabolic SAR ... +double GetXMAPSAR( + const int bar_index, + // + double stp = 0.02, + double mxm = 0.2 +) { + // + double result = 0; + + // + double pSar = iSAR( + _Symbol, + _Period, + stp, + mxm, + bar_index + ); + result = pSar; + + // + return result; +} + +// +XState GetXState( + const int bar_index, + const int marketLen, + // + const double stp, + const double mxm, + // + const int shortCycleFastMult, + const int shortCycleSlowMult, + const int mediumCycleFastMult, + const int mediumCycleSlowMult, + const int longCycleFastMult, + const int longCycleSlowMult +) { + // + XState result = {}; + + // + // Short Cycle ... + XCycleState sc = GetXMASC( + bar_index, + marketLen, + shortCycleFastMult, + shortCycleSlowMult + ); + result.sc = sc; + + // + // Medium Cycle ... + XCycleState mc = GetXMAMC( + bar_index, + marketLen, + mediumCycleFastMult, + mediumCycleSlowMult + ); + result.mc = mc; + + // + // Long Cycle ... + XCycleState lc = GetXMALC( + bar_index, + marketLen, + longCycleFastMult, + longCycleSlowMult + ); + result.lc = lc; + + // + // OSC ... + XCycleState osc = GetXOSC( + // + bar_index, + marketLen, + // + shortCycleFastMult, + shortCycleSlowMult + ); + result.osc = osc; + + // + // Parabolic SAR ... + double parabolicSAR = GetXMAPSAR( + bar_index, + stp, + mxm + ); + result.parabolicSAR = parabolicSAR; + + // + // Market Middleage ... + double marketMiddleage = GetXMAMM( + bar_index, + marketLen, + 1.5 + ); + result.marketMiddleage = marketMiddleage; + + // // + // int cciMarketLength = longCycleSlowMult * marketLen; + // double cci = GetMarketCCI( + // bar_index, + // cciMarketLength + // ); + // result.cci = cci; + + // + XBndState bnd = GetXBND( + bar_index + ); + result.bnd = bnd; + + // + XMKTState mkt = GetXMKT( + bar_index, + marketLen + ); + result.mkt = mkt; + + // + return result; +} +// +// END XMA Data ... +// +// +// END Indicator Reading Data ... +// diff --git a/Bkp/Used/14020425/Libraries/x-saherelm.lib.mq4 b/Bkp/Used/14020425/Libraries/x-saherelm.lib.mq4 new file mode 100644 index 0000000..658c90a --- /dev/null +++ b/Bkp/Used/14020425/Libraries/x-saherelm.lib.mq4 @@ -0,0 +1,1502 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +struct XOHCL { + double high; + double open; + double close; + double low; +}; + +// +static datetime lastBarTime; + +// +// START Functions ... +// + +// +// Determines current working is New Bar or not ... +bool IsNewBar() { + // + // Reading Last Bar Date ... + datetime curbar = (datetime)SeriesInfoInteger( + _Symbol, + _Period, + SERIES_LASTBAR_DATE + ); + + // + if(lastBarTime != curbar) { + // + lastBarTime = curbar; + return true; + } + + // + return false; +} + +// +// Determines we are in new Day or not ... +bool IsNewDay() { + // + bool result = false; + + // + // Reading Last Bar Date ... + datetime curbar = (datetime)SeriesInfoInteger( + _Symbol, + _Period, + SERIES_LASTBAR_DATE + ); + + // + if (lastBarTime == 0) { + lastBarTime = curbar; + } + + // + if (curbar == lastBarTime) { + return result; + } + + // + // Retrieve Day and Month and Year for Last Bar Time ... + int lastBarDay = TimeDay(lastBarTime); + int lastBarMonth = TimeMonth(lastBarTime); + int lastBarYear = TimeYear(lastBarTime); + + // + // Retrieve Day and Month and Year for Current Bar Time ... + int curBarDay = TimeDay(curbar); + int curBarMonth = TimeMonth(curbar); + int curBarYear = TimeYear(curbar); + + // + result = curBarDay > lastBarDay + || curBarMonth > lastBarMonth + || curBarYear > lastBarYear; + + // + return result; +} + +// +// Retrieve RMA on Specific Candle ... +double GetRMA( + int bar_index, + int length +) { + // + double shortSMA = iMA(_Symbol, _Period, length, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double mediumSMA = iMA(_Symbol, _Period, length * 2, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double longSMA = iMA(_Symbol, _Period, length * 3, 0, MODE_SMA, PRICE_CLOSE, bar_index); + + // + double result = longSMA - mediumSMA + shortSMA; + + // + return result; +} + +// +double GetMA( + const int bar_index, + const int maLength, + const int maShift, + const ENUM_MA_METHOD maMethod, + const ENUM_APPLIED_PRICE appliedPrice +) { + // + double result = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + appliedPrice, + bar_index + ); + + // + return result; +} + +// +// Retrieve True Range ... +double GetTR( + const int bar_index +) { + // + double result = 0; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double prevClose = iClose( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double highLowDif = high - low; + double hpCDif = MathAbs(high - prevClose); + double lpCDiff = MathAbs(low - prevClose); + + // + result = MathMax(highLowDif, hpCDif); + result = MathMax(result, lpCDiff); + + // + return result; +} + +// +// Calculate True Range Simple Moving Average ... +double GetMarketTRSMA( + const int bar_index, + const int marketLen +) { + // + double result = 0; + + // + // Create Barket Length Trs ... + double trs[]; + ArrayResize( + trs, + marketLen + ); + int index = 0; + double trSum = 0; + for (int i = bar_index; i < bar_index + marketLen; i++) { + // + double tr = GetTR(i); + trs[index] = tr; + + // + trSum += tr; + + // + index++; + } + + // + result = trSum / marketLen; + + // + return result; +} + +// +// Retrieve Commodity Channel ... +double GetMarketCCI( + const int bar_index, + const int marketLen, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE +) { + // + double result = 0; + + // + result = iCCI( + _Symbol, + _Period, + marketLen, + appliedPrice, + bar_index + ); + + // + return result; +} + +// +// this function check crossing up two Buffers ... +bool IsCrossedOver( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] > arr2[index1]) && !(arr1[index2] > arr2[index2]); + + // + return result; +} + +// +// this function check crossing down two Buffers ... +bool IsCrossedUnder( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] < arr2[index1]) && !(arr1[index2] < arr2[index2]); + + // + return result; +} + +// +// Convert points to Actual Point ... +double PointsToDouble(int points) { + // + double result = points * _Point; + return result; +} + +// +// Converts Pips to Points ... +int PipsToPoints(int pips) { + // + int result = pips * ((_Digits == 3 || _Digits == 5) ? 10 : 1); + return result; +} + +// +// Converts Pips to Double ... +double PipsToDouble(int pips) { + // + double result = PointsToDouble(PipsToPoints(pips)); + return result; +} + +// +// Converts Double Value to Pips ... +int PriceToPips(double value) { + // + if (value <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + int result = (int)(value / pipValue); + + // + return result; +} + +// +// Converts Pips to Double ... +double PipsToPrice(int pips) { + // + if (pips <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + double result = pipValue * pips; + + // + return result; +} + +// +// Generate ATR StopLoss Value ... +double CalculateATRSL( + int period, + double multiplier +) { + // + if (period <= 0 || multiplier <= 0) { + return 0; + } + + // + double atrValue = iATR( + _Symbol, + _Period, + period, + 0 + ); + + // + double result = atrValue * multiplier; + + // + return result; +} + +// +// Detect Candle Type ... +// Bullish => means close > open ... +bool IsBullishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBullishCandle( + open, + close + ); + + // + return result; +} + +bool IsBullishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open < close; + + // + return result; +} + +// +// Detect Candle Type ... +// Bearish => means close < open ... +bool IsBearishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBearishCandle( + open, + close + ); + + // + return result; +} + +bool IsBearishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open > close; + + // + return result; +} + +// +// Retrieve a Candle Info ... +XOHCL GetCandleModel( + const int bar_index +) { + // + XOHCL result = {}; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + result.high = high; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + result.open = open; + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + result.close = close; + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + result.low = low; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBullishDetected( + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double shpDetectMultipliers // Sharp Detect Multiplier +) { + // + bool result = false; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double minValue = 0; + double maxValue = 0; + int positionedLength = bar_index + marketLen; + + // + for (int i = bar_index; i < positionedLength; i++) { + // + double cHigh = iHigh( + _Symbol, + _Period, + i + ); + + // + double cLow = iLow( + _Symbol, + _Period, + i + ); + + // + minValue += MathMin(cLow, cHigh); + maxValue += MathMax(cLow, cHigh); + } + + // + double minAvg = minValue / positionedLength; + double maxAvg = maxValue / positionedLength; + + // + double shpValue = shpDetectMultipliers * _Point; + + // + result = (low - minAvg) > shpValue; + + // + int index = bar_index; + while ( + index < positionedLength + || !result + ) { + // + low = iLow( + _Symbol, + _Period, + index + ); + + // + result = result + || (low - minAvg) > shpValue; + + // + index++; + }; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBearishDetected( + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double shpDetectMultipliers // Sharp Detect Multiplier +) { + // + bool result = false; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double minValue = 0; + double maxValue = 0; + int positionedLength = bar_index + marketLen; + + // + for (int i = bar_index; i < positionedLength; i++) { + // + double cHigh = iHigh( + _Symbol, + _Period, + i + ); + + // + double cLow = iLow( + _Symbol, + _Period, + i + ); + + // + minValue += MathMin(cLow, cHigh); + maxValue += MathMax(cLow, cHigh); + } + + // + double minAvg = minValue / positionedLength; + double maxAvg = maxValue / positionedLength; + + // + double shpValue = shpDetectMultipliers * _Point; + + // + result = (high - maxAvg) > shpValue; + + // + int index = bar_index; + while ( + index < positionedLength + || !result + ) { + // + high = iHigh( + _Symbol, + _Period, + index + ); + + // + result = result + || (high - maxAvg) > shpValue; + + // + index++; + }; + + // + return result; +} + +// +// Retrieve Highest High Value based on Given Market ... +double GetMarketHighestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Low Value based on Given Market ... +double GetMarketHighestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Open Value based on Given Market ... +double GetMarketHighestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Close Value based on Given Market ... +double GetMarketHighestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Low Value based on Given Market ... +double GetMarketLowestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest High Value based on Given Market ... +double GetMarketLowestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Open Value based on Given Market ... +double GetMarketLowestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Close Value based on Given Market ... +double GetMarketLowestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// less than given price ... +double GetLowLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// great than given price ... +double GetLowGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// less than given price ... +double GetHighLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// great than given price ... +double GetHighGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// less than given price ... +double GetCloseLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// great than given price ... +double GetCloseGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Get Slope of a Line by it's two Point ... +double GetSlope( + double x1, + double y1, + double x2, + double y2 +) { + // + double result = (y2 - y1)/(x2 - x1); + return result; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020425/Libraries/x-saherelm.log.lib.mq4 b/Bkp/Used/14020425/Libraries/x-saherelm.log.lib.mq4 new file mode 100644 index 0000000..066b3f7 --- /dev/null +++ b/Bkp/Used/14020425/Libraries/x-saherelm.log.lib.mq4 @@ -0,0 +1,91 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Log Tag ... +static string logTag = ""; + +// +// Enable or Disable Logging ... +static bool enableLogging = false; + +// +// Start Log Messages ... +// + +// +// Logging a Message, specified for this EA ... +// using provided LogTag ... +void LogMessage(string message) { + // + if (!enableLogging) { + return; + } + + // + Print(logTag, " > ", message); +} + +// +// this used for logging series ... +void LogSeries( + double &series[], // which series to Log ... + int length = 0, // number of items to Log, 0 means all ... + int skip = 0 // number of items which skip before logging ... +) { + // + string msg = ""; + + // + int seriesSize = ArraySize(series); + if ( + skip < 0 + || length < 0 + || seriesSize == 0 + || skip > seriesSize + || skip + length > seriesSize + ) { + return; + } + + // + length = length == 0 ? + seriesSize : + length; + int start = skip > 1 ? + skip - 1 : + skip == 1 ? + 1 : + 0; + + // + // Loop through series items ... + for (int i = start; i < start + length; i++) { + // + msg += StringConcatenate( + "i[", i, "]: ", series[i], ", " + ); + } + + // + LogMessage(msg); +} +// +// End Log Messages ... +// + diff --git a/Bkp/Used/14020425/Libraries/x-saherelm.models.lib.mq4 b/Bkp/Used/14020425/Libraries/x-saherelm.models.lib.mq4 new file mode 100644 index 0000000..d068d53 --- /dev/null +++ b/Bkp/Used/14020425/Libraries/x-saherelm.models.lib.mq4 @@ -0,0 +1,222 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Models Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// START STATIC Variables ... +// +// +static int totalSignals = 0; +static int totalLongSignals = 0; +static int totalShortSignals = 0; + +// +static double initialBalance = 0; + +// +static int countedBars = 0; +static bool isNewBar = false; +static bool isNewDay = false; +// +// END STATIC Variables ... +// + +// +// Start Models ... +// +// +// Signal Providers ... +enum ENUM_X_SIGNAL_PROVIDER { + X_UNKNOWN_PROVIDER, + X_OSC_PROVIDER, + X_CCI_PROVIDER, + X_SHP_PROVIDER, + X_XMA_PROVIDER, + X_RMA_PROVIDER, + X_XXX_PROVIDER +}; + +// +// these are different signal types ... +enum ENUM_X_SIGNAL_TYPE { + X_SIGNAL_NONE, + X_SIGNAL_LONG, + X_SIGNAL_SHORT, +}; + +// +// we Model each signals as this type ... +struct XSignal { + // + // Signal Symbol ... + string symbol; + + // + // Signal Type ... + ENUM_X_SIGNAL_TYPE type; + + // + // Signal ID ... + int id; + + // + // Signal Ticket Number, when Opening Trade ... + int ticket; + + // + // Signal Provider ... + ENUM_X_SIGNAL_PROVIDER provider; + + // + // Target Point ... + double tp; + + // + // Stop Loss ... + double sl; + + // + // Signal Entry Price ... + double entry; + + // + // Signalling Time ... + datetime time; + + // + // Signal Comments ... + string comment; +}; + +// +// this is Signal Request Response model ... +struct XSignalRequest { + bool hasSignal; + XSignal signal; + ENUM_X_SIGNAL_TYPE type; + ENUM_X_SIGNAL_PROVIDER provider; +}; + +// +struct XBndState { + double high; + double open; + double close; + double low; +}; + +// +struct XMKTState { + // + double highestHigh; + double highestLow; + double highestOpen; + double highestClose; + + // + double lowestHigh; + double lowestLow; + double lowestOpen; + double lowestClose; +}; + +// +struct XCycleState { + double fast; + double slow; +}; + +// +// Define a Model to Represent Snapshot of XMA Indicator ... +struct XState { + // + // SC ... + XCycleState sc; + + // + // MC ... + XCycleState mc; + + // + // LC ... + XCycleState lc; + + // + // OSC ... + XCycleState osc; + + // + // MIDDLEAGE ... + double marketMiddleage; + + // + // PARABOLIC-SAR ... + double parabolicSAR; + + // + double cci; + + // + XBndState bnd; + + // + XMKTState mkt; +}; + +// +// Parsed XMA Buffer ... +struct XStateInfo { + // + // Check Market Cross Exists or not ... + // + bool isSCFastCrossOverSlow; + bool isSCFastCrossUnderSlow; + + // + double scMin; + double scMax; + + // + bool isMCFastCrossOverSlow; + bool isMCFastCrossUnderSlow; + + // + double mcMin; + double mcMax; + + bool isLCFastCrossOverSlow; + bool isLCFastCrossUnderSlow; + + // + double lcMin; + double lcMax; + + // + bool isMMCrossOverSCFast; + bool isMMCrossUnderSCFast; + + // + bool isMMCrossOverMCFast; + bool isMMCrossUnderMCFast; + + // + double mmMin; + double mmMax; +}; +// +// End Models ... +// diff --git a/Bkp/Used/14020425/Libraries/x-saherelm.osc.signal.lib.mq4 b/Bkp/Used/14020425/Libraries/x-saherelm.osc.signal.lib.mq4 new file mode 100644 index 0000000..84f0386 --- /dev/null +++ b/Bkp/Used/14020425/Libraries/x-saherelm.osc.signal.lib.mq4 @@ -0,0 +1,363 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 OSC Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// SHP Based Signal Conditions ... +struct XOSCLongSignalConditions { + // + datetime crossOverTime; + double slowOnCrossOver; + + // + datetime crossUnderTime; + double slowOnCrossUnder; +}; + +// +static XOSCLongSignalConditions oscLongConds; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill CC Signal Conditions ... +void CheckOSCLongSignalConditions( + const int bar_index, + const int marketLen, + // + double stp, + double mxm, + // + int scFMult, + int scSMult, + // + int mcFMult, + int mcSMult, + // + int lcFMult, + int lcSMult, + // + const double smoother = 5 +) { + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XState states[]; + ArrayResize( + states, + marketLen + ); + + // + int index = 0; + for (int i = bar_index; i < marketLen; i++) { + // + XState state = GetXState( + i, + marketLen, + // + stp, + mxm, + scFMult, + scSMult, + mcFMult, + mcSMult, + lcFMult, + lcSMult + ); + + // + states[index] = state; + + // + index++; + } + + // + bool isCrossUnder = + states[0].osc.fast < 0 + && !(states[1].osc.fast < 0) + ; + + // + bool isCrossOver = + states[0].osc.fast > 0 + && !(states[1].osc.fast > 0) + ; + + // + int oneTouches = 0; + int halfTouches = 0; + int minusOneTouches = 0; + for (int i = 0; i < marketLen - 1; i++) { + // + // One Touches ... + if ( + states[i].osc.fast > 1 + && !(states[i + 1].osc.fast > 1) + ) { + oneTouches++; + } + + // + // Half Touches ... + if ( + states[i].osc.fast > 0.5 + && !(states[i + 1].osc.fast > 0.5) + ) { + halfTouches++; + } + + // + // Minus One Touches ... + if ( + states[i].osc.fast < -1 + && !(states[i + 1].osc.fast < -1) + ) { + minusOneTouches++; + } + } + + // + if ( + isCrossUnder + && oscLongConds.crossUnderTime == 0 + ) { + // + oscLongConds.crossUnderTime = barTime; + oscLongConds.slowOnCrossUnder = states[0].osc.slow; + return; + } + + // + if ( + isCrossOver + && oscLongConds.crossUnderTime > 0 + && oscLongConds.crossOverTime == 0 + ) { + // + oscLongConds.crossOverTime = barTime; + oscLongConds.slowOnCrossOver = states[0].osc.slow; + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateOSCLongSignal( + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r // Risk to Reward ratio ... +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if (!ValidateOSCLongConditions()) { + return result; + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double entryPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double exitPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + GetMarketLowestLow( + bar_index, + marketLen + ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = MathMin(openPrice, closePrice) - ll; + double reward = risk * r2r; // 300 * _Point; + + // + double sl = 0; // ll; + double tp = entryPrice + reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = X_SIGNAL_LONG; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_OSC_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = X_SIGNAL_LONG; + result.provider = X_OSC_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateOSCLongConditions() { + // + bool isConditionsFilled = + oscLongConds.crossOverTime > 0 + && oscLongConds.crossUnderTime > 0 + && oscLongConds.slowOnCrossOver > 0 + && oscLongConds.slowOnCrossUnder > 0 + && oscLongConds.crossOverTime > oscLongConds.crossUnderTime + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int crossUnderBarIndex = iBarShift( + _Symbol, + _Period, + oscLongConds.crossUnderTime + ); + + // + int crossOverBarIndex = iBarShift( + _Symbol, + _Period, + oscLongConds.crossOverTime + ); + + // + isBLFilled = + crossUnderBarIndex > crossOverBarIndex + // && oscLongConds.slowOnCrossOver > oscLongConds.slowOnCrossUnder + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearOSCLongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearOSCLongSignalConditions() { + // + oscLongConds.crossOverTime = 0;; + oscLongConds.crossUnderTime = 0;; +} + +// +// Check State for Long Signals ... +bool IsReadyForOSCLongSignals( + const XSignal &signal, + const XState &states[] +) { + // + bool result = false; + + // + result = + // + true + ; + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020425/Libraries/x-saherelm.rma.signal.lib.mq4 b/Bkp/Used/14020425/Libraries/x-saherelm.rma.signal.lib.mq4 new file mode 100644 index 0000000..4b9637a --- /dev/null +++ b/Bkp/Used/14020425/Libraries/x-saherelm.rma.signal.lib.mq4 @@ -0,0 +1,363 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 RMA Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// RMA Based Signal Conditions ... +struct XRMALongSignalConditions { + // + datetime crossUnderTime; + + // + datetime crossOverTime; +}; + +// +static XRMALongSignalConditions xrmaLongConds; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill CC Signal Conditions ... +void CheckXRMALongSignalConditions( + const int bar_index, + const int marketLen, + // + const double smoother = 5 +) { + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XCycleState states[]; + ArrayResize( + states, + marketLen + ); + + // + int index = 0; + for (int i = bar_index; i < marketLen; i++) { + // + XCycleState state = GetXMANN(i); + + // + states[index] = state; + + // + index++; + } + + // + bool isCrossUnder = + states[1].fast < states[1].slow + && !(states[2].fast < states[2].slow) + ; + + // + bool isCrossOver = + states[1].fast > states[1].slow + && !(states[2].fast > states[2].slow) + ; + + // + if ( + isCrossUnder + && xrmaLongConds.crossUnderTime == 0 + ) { + // + xrmaLongConds.crossUnderTime = barTime; + return; + } + + // + if ( + isCrossOver + && xrmaLongConds.crossUnderTime > 0 + && xrmaLongConds.crossOverTime == 0 + ) { + // + xrmaLongConds.crossOverTime = barTime; + return; + } +} + +// +// Convert XMA Long Signal Conditions to XSignal ... +XSignalRequest GenerateXRMALongSignal( + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r // Risk to Reward ratio ... +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if (!ValidateXRMALongConditions(marketLen)) { + return result; + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double entryPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double exitPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + GetMarketLowestLow( + bar_index, + marketLen + ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = MathMin(openPrice, closePrice) - ll; + double reward = risk * r2r; // 300 * _Point; + + // + double sl = 0; // entryPrice - (300 * _Point); // ll; + double tp = entryPrice + reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = X_SIGNAL_LONG; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_RMA_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = X_SIGNAL_LONG; + result.provider = X_RMA_PROVIDER; + + // + return result; +} + +// +// Validate XMA Signal Conditions ... +bool ValidateXRMALongConditions( + const int marketLen +) { + // + bool isConditionsFilled = + true + && xrmaLongConds.crossOverTime > 0 + && xrmaLongConds.crossUnderTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int crossOverBarIndex = iBarShift( + _Symbol, + _Period, + xrmaLongConds.crossOverTime + ); + + // + int crossUnderBarIndex = iBarShift( + _Symbol, + _Period, + xrmaLongConds.crossUnderTime + ); + + // + XCycleState stateOnCrossUnder = GetXMANN( + crossUnderBarIndex + ); + + // + XCycleState stateOnCrossOver = GetXMANN( + crossOverBarIndex + ); + + // + double maC = iMA( + _Symbol, + _Period, + 14, + 0, + MODE_SMA, + PRICE_CLOSE, + crossOverBarIndex + ); + + // // + // double rmaOnCrossOver = GetRMA( + // crossOverBarIndex, + // 10 + // ); + + // // + // double rmaOnMarketLength = GetRMA( + // crossOverBarIndex + marketLen, + // 10 + // ); + + // // + // double prevCandleHigh = iHigh( + // _Symbol, + // _Period, + // crossOverBarIndex + // ); + + // // + // PrepareZigZagState(crossOverBarIndex); + // double zigZagDelta = zigZags[1] - zigZags[2]; + // bool isZigZagWaitForHigh = zigZagDelta < 0; + + // + isBLFilled = + true + // + && (crossUnderBarIndex - crossOverBarIndex) > 5 + // + && xrmaLongConds.crossOverTime > xrmaLongConds.crossUnderTime + // + && stateOnCrossOver.slow < stateOnCrossUnder.slow + // + && MathAbs(stateOnCrossOver.fast - stateOnCrossOver.slow) > (70 * _Point) + // + && maC >= stateOnCrossOver.slow + // // + // && !(rmaOnCrossOver < stateOnCrossOver.slow) + // // + // && MathAbs(rmaOnCrossOver - rmaOnMarketLength) < (600 * _Point) + // // + // && !isZigZagWaitForHigh + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXRMALongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXRMALongSignalConditions() { + // + xrmaLongConds.crossOverTime = 0; + xrmaLongConds.crossUnderTime = 0; +} + +// +// Check XMA State for Long Signals ... +bool IsReadyForXRMALongSignals( + const XSignal &signal, + const XState &states[], + const int marketLen +) { + // + bool result = false; + + // + result = + // + true + ; + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020425/Libraries/x-saherelm.shp.signal.lib.mq4 b/Bkp/Used/14020425/Libraries/x-saherelm.shp.signal.lib.mq4 new file mode 100644 index 0000000..dd0f767 --- /dev/null +++ b/Bkp/Used/14020425/Libraries/x-saherelm.shp.signal.lib.mq4 @@ -0,0 +1,391 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 SHP Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// SHP Based Signal Conditions ... +struct XSHPLongSignalConditions { + // + datetime start; + datetime stop; +}; + +// +static XSHPLongSignalConditions shpLongConds; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill CC Signal Conditions ... +void CheckSHPLongSignalConditions( + const int bar_index, + const int marketLen, + const double shpDetectMult, + const double smoother = 30 +) { + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double mHH = GetMarketHighestHigh( + bar_index, + marketLen + ); + + // + double mLL = GetMarketLowestLow( + bar_index, + marketLen + ); + + double m2LL = GetMarketLowestLow( + bar_index, + marketLen * 2 + ); + + // + int mHLIdx = iHighest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + datetime mHLTime = iTime( + _Symbol, + _Period, + mHLIdx + ); + double mHL = iHigh( + _Symbol, + _Period, + mHLIdx + ); + + // + double hlDiff = (mHL - mLL); + double sharpDetectValue = shpDetectMult * _Point; + + // + bool isSharpDetected = + // ( + // low == mLL + // || MathAbs(mLL - low) < (smoother * _Point) + // ) + // && + // !( + // mLL > m2LL + // && MathAbs(m2LL - mLL) > sharpDetectValue / 2 + // ) + // && + ( + hlDiff > sharpDetectValue + || hlDiff > sharpDetectValue - (smoother * _Point) + ) + ; + + // + if (isSharpDetected) { + // + shpLongConds.start = mHLTime; + shpLongConds.stop = barTime; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateSHPLongSignal( + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r, // Risk to Reward ratio ... + const double shpDetectMultiplier // Sharp Detect Multiplier ... +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if (!ValidateSHPLongConditions(shpDetectMultiplier)) { + return result; + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double entryPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double exitPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + GetMarketLowestLow( + bar_index, + marketLen + ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = MathMin(openPrice, closePrice) - ll; + double reward = 300 * _Point; // risk * r2r; + + // + double sl = 0; // ll; + + // + // this means Market Lowest Low ... + double shpValue = shpDetectMultiplier * _Point; + if ( + reward == 0 + || reward < 20 * _Point + ) { + reward = shpValue; + } + double tp = entryPrice + reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = X_SIGNAL_LONG; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_SHP_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = X_SIGNAL_LONG; + result.provider = X_SHP_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateSHPLongConditions( + const double shpDetectMultiplier +) { + // + double shpDetectValue = shpDetectMultiplier * _Point; + + // + bool isConditionsFilled = + shpLongConds.stop != 0 + && shpLongConds.start != 0 + && shpLongConds.stop > shpLongConds.start + ; + + // + bool isBLFilled = true; + + // + bool result = + isBLFilled + && isConditionsFilled + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearSHPLongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearSHPLongSignalConditions() { + // + shpLongConds.stop = 0; + shpLongConds.start = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForSHPLongSignals( + const XSignal &signal, + const XState &states[] +) { + // + bool result = false; + + // + XStateInfo info = ParseXMAStates(states); + + // + int xmaMarketLen = ArraySize(states); + double mHH = GetMarketHighestHigh(0, xmaMarketLen); + double m2HH = GetMarketHighestHigh(0, (int) (xmaMarketLen * 1.5)); + + // + int lcUpDownTouches = 0; + int cciHundredTouches = 0; + for (int i = 0; i < xmaMarketLen; i++) { + // + double high = iHigh( + _Symbol, + _Period, + i + ); + + // + double low = iLow( + _Symbol, + _Period, + i + ); + + // + double up = MathMax(states[i].lc.fast, states[i].lc.slow); + double down = MathMax(states[i].lc.fast, states[i].lc.slow); + + // + if (high >= up && low <= down) { + lcUpDownTouches++; + } + + // + if ( + i < xmaMarketLen - 1 + && i < 10 + ) { + if ( + states[i].cci < 100 + && states[i + 1].cci > 100 + ) { + cciHundredTouches++; + } + } + } + + // + result = + // + true + // + && states[0].mc.fast > states[0].mc.slow + && states[0].lc.fast > states[0].lc.slow + // + && states[0].sc.fast < states[0].sc.slow + && states[1].sc.fast < states[1].sc.slow + // + && states[0].marketMiddleage < states[0].sc.fast + && states[1].marketMiddleage < states[1].sc.fast + && !( + states[1].sc.fast < states[1].mc.fast + && states[1].sc.slow < states[1].mc.fast + && states[1].sc.fast > states[1].mc.slow + && states[1].sc.slow > states[1].mc.slow + ) + && !( + states[0].marketMiddleage < states[0].mc.fast + && states[0].marketMiddleage > states[0].mc.slow + ) + // + && mHH != m2HH + && lcUpDownTouches == 0 + && cciHundredTouches == 0 + ; + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020425/Libraries/x-saherelm.signal.lib.mq4 b/Bkp/Used/14020425/Libraries/x-saherelm.signal.lib.mq4 new file mode 100644 index 0000000..439d9ad --- /dev/null +++ b/Bkp/Used/14020425/Libraries/x-saherelm.signal.lib.mq4 @@ -0,0 +1,1463 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Signal Draw Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +#include "../Libraries/x-saherelm.x.signal.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// END Global Requirement Functions ... +// + +// +// START Signal Related Functions ... +// +// +// Retrieve Signal Bar Index ... +int GetSignalBarIndex(XSignal &signal) { + // + // Temp Result ... + int result = -1; + + // + // Retriev Signal Bar Index ... + result = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + return result; +} + +// +// Draw Signal Shapes on Chart ... +bool DrawSignal( + const XSignal &signal, + long chartID = 0, + int subWindowID = 0, + const double positionThresholdFactor = 10, + string signalTag = "X-Signal", + string longSignalLabel = "X-Long", + color longSignalColor = clrAqua, + string shortSignalLabel = "X-Short", + color shortSignalColor = clrFuchsia, + string provider = "" +) { + // + // Generate isLongSignal Var ... + bool isLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Signal Bar Index ... + int bar_index = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // START Draw Signal Arrow ... + // + // + // Arrow Shape Name ... + string arrowName = StringConcatenate(signalTag, "_Arrow_", signal.id); + + // + // Arrow Price ... + double arrowPrice = 0; + if (isLongSignal) { + // + arrowPrice = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice - (positionThresholdFactor * _Point); + } else { + // + arrowPrice = iHigh( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice + (positionThresholdFactor * _Point); + } + + // + // Arrow Code ... + uchar arrowCode = isLongSignal ? SYMBOL_ARROWUP : SYMBOL_ARROWDOWN; + + // + // Arrow Anchor Point ... + ENUM_ARROW_ANCHOR arrowAnchorPoint = isLongSignal ? ANCHOR_BOTTOM : ANCHOR_TOP; + + // + // Arrow Color ... + color arrowColor = isLongSignal ? longSignalColor : shortSignalColor; + + // + // Draw Signal Arrow Shape ... + bool result = DrawArrow( + chartID, + arrowName, + subWindowID, + signal.time, + arrowPrice, + arrowCode, + arrowAnchorPoint, + arrowColor + ); + // + // END Draw Signal Arrow ... + // + + // + // START Draw Signal SL/TP ... + // + string slLineName = StringConcatenate(signalTag, "_SL_", signal.id); + string tpLineName = StringConcatenate(signalTag, "_TP_", signal.id); + string entryLineName = StringConcatenate(signalTag, "_ENTRY_", signal.id); + + // + color slColor = shortSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color tpColor = longSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color entryColor = clrGreen; + + // + datetime time1 = iTime( + _Symbol, + _Period, + bar_index + 1 + ); + + // + // Draw Enrty Price ... + result = DrawTrendLine( + chartID, + entryLineName, + subWindowID, + time1, + signal.entry, + signal.time, + signal.entry, + entryColor, + STYLE_SOLID, + 2 + ); + + // + // Draw Signal SL ... + if (signal.sl > 0) { + // + result = DrawTrendLine( + chartID, + slLineName, + subWindowID, + time1, + signal.sl, + signal.time, + signal.sl, + slColor, + STYLE_SOLID, + 2 + ); + } + + // + // Draw Signal TP ... + if (signal.tp > 0) { + // + result = DrawTrendLine( + chartID, + tpLineName, + subWindowID, + time1, + signal.tp, + signal.time, + signal.tp, + tpColor, + STYLE_SOLID, + 2 + ); + } + // + // END Draw Signal SL/TP ... + // + + // + // Start Draw Signal Label ... + // + // + string labelName = StringConcatenate(signalTag, "_Label_", signal.id); + + // + double labelPrice = isLongSignal ? arrowPrice - (positionThresholdFactor * _Point) : arrowPrice + (positionThresholdFactor * _Point); + + // + string labelText = isLongSignal ? longSignalLabel : shortSignalLabel; + labelText = StringConcatenate( + labelText, + "_", + provider + ); + + // + result = DrawText( + chartID, + labelName, + subWindowID, + signal.time, + labelPrice, + labelText, + "Arial", + 8, + arrowColor, + 0, + ANCHOR_CENTER + ); + // + // End Draw Signal Label ... + // + + // + return result; +} + +// +// Trade on Specific Signal ... +bool TradeSignal( + XSignal &signal, + // + string prefix, + // + double volumePercent, + // + // Long ... + const string longSignalLabel, + const color longSignalColor, + // + // Short ... + const string shortSignalLabel, + const color shortSignalColor +) { + // + // Temp Result ... + bool result = false; + + // + if (initialBalance == 0) { + initialBalance = AccountInfoDouble(ACCOUNT_BALANCE); + } + + // + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + int openPositions = CountOpenTrades(); + double volume = (volumePercent * initialBalance); + + // + if ( + signal.type != X_SIGNAL_LONG && + signal.type != X_SIGNAL_SHORT + ) { + return result; + } + + // + bool hasLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Check TP and Entry Price ... + if ( + ( + hasLongSignal + && signal.entry > signal.tp + ) || + ( + !hasLongSignal + && signal.entry < signal.tp + ) + ) { + return result; + } + + // + // Order Operation ... + int operation = hasLongSignal ? + OP_BUY : + OP_SELL; + + // + // Detect Trade Color ... + color clr = hasLongSignal ? + longSignalColor : + shortSignalColor; + + // + // Generate Signal Comment ... + string label = hasLongSignal ? + longSignalLabel : + shortSignalLabel; + + // + string provider = + // signal.provider == X_CCI_PROVIDER + // ? cciSignalId : + // signal.provider == X_SHP_PROVIDER + // ? shpSignalId : + // signal.provider == X_XMA_PROVIDER + // ? xmaSignalId : + // signal.provider == X_OSC_PROVIDER + // ? oscSignalId : + // signal.provider == X_RMA_PROVIDER + // ? rmaSignalId : + "" + ; + + // + // Generate Signal Comment ... + string comment = StringConcatenate( + prefix, + "_", signal.id, + "_", provider, + "_", label + ); + + // + // Placing Order ... + int orderTicket = OrderSend( + _Symbol, + operation, + volume, + signal.entry, + 3, + signal.sl, + signal.tp, + comment, + signal.id, + 0, + clr + ); + + // + // Draw Signal Shape if Order Opened Successfully ... + if (orderTicket >= 0) { + // + signal.ticket = orderTicket; + + // + // Here i must to Draw Signal Shapes ... + bool isDrawn = DrawSignal( + signal, + 0, + 0, + 50, + prefix, // Signal Tag ... + longSignalLabel, // Long Signal Label ... + longSignalColor, + shortSignalLabel, // Short Signal Label ... + shortSignalColor, + provider + ); + + // + LogMessage( + StringConcatenate( + "Order [", orderTicket ,"]: Provided by: ", provider + ) + ); + + // + // TODO: here we have to check if there are another + // open positions which their entry price is bigger + // than current signal entry price, for long trades and + // their tp is high than current tp, ... + // close in profit trades or modify orders tp to current ... + // // + // if (CountOpenTrades() > 0) { + // // + // // Here we have to + // // ModifyOpenTradesBasedOnCurrentTrade(signal); + // } + + // + result = true; + } + + // + return result; +} +// +// END Signal Related Functions ... +// + +// +// START Orders Functions ... +// +// +// Convert To XSignal Model ... +XSignal OrderToSignal( + // + // Define Signal Identifiers ... + const string cciSignalId, // Signal Identifier ... + const string shpSignalId, // Signal Identifier ... + const string xmaSignalId // Signal Identifier ... +) { + // + // Temp Result ... + XSignal result = {}; + result.type = X_SIGNAL_NONE; + + // + // Here we can get some usefull info based on selected order ... + double swap = OrderSwap(); + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + int magicNumber = OrderMagicNumber(); + double takeProfit = OrderTakeProfit(); + string comment = OrderComment(); + + // + ENUM_X_SIGNAL_PROVIDER provider = + StringFind( + comment, + cciSignalId + ) ? + X_CCI_PROVIDER : + StringFind( + comment, + shpSignalId + ) ? + X_SHP_PROVIDER : + StringFind( + comment, + xmaSignalId + ) ? + X_XMA_PROVIDER : + X_UNKNOWN_PROVIDER + ; + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // Conver Position to Signal ... + result.sl = stopLoss; + result.tp = takeProfit; + result.time = openTime; + result.symbol = _Symbol; + result.id = magicNumber; + result.comment = comment; + result.entry = openPrice; + result.provider = provider; + result.type = isLongOrder ? X_SIGNAL_LONG : X_SIGNAL_SHORT; + + // + return result; +} + +// +// START Count Orders ... +// +// +// Count Open Positions ... +int CountOpenTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if (OrderSymbol() == _Symbol) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Long Positions ... +int CountOpenLongTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_BUY + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Short Positions ... +int CountOpenShortTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_SELL + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} +// +// END Count Orders ... +// + +// +// START Close Orders ... +// +// +// Close All Open Trades ... +bool CloseAllTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + + // + return result; +} + +// +bool CloseAllProviderLongTrades( + const ENUM_X_SIGNAL_PROVIDER provider, + // + // Define Signal Identifiers ... + const string cciSignalId, // Signal Identifier ... + const string shpSignalId, // Signal Identifier ... + const string xmaSignalId // Signal Identifier ... +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal( + cciSignalId, + shpSignalId, + xmaSignalId + ); + + // + if (signal.provider == provider) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Long Trades ... +bool CloseAllLongTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Long Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Short Trades ... +bool CloseAllShortTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (!isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Short Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In Profit Trades ... +bool CloseAllInProfitTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit > 0 + && profit > 50 * _Point + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InProfit Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In DrawDown Trades ... +bool CloseAllInDrawDownTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if (profit < 0) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close Biggest In DrawDown Trades ... +bool CloseBiggestDrawDownTrade() { + // + // Loop through all Positions ... + bool result = false; + double drawDown = 0; + + // + // Find Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) > drawDown + ) { + drawDown = profit; + } + } + } + } + + // + // Close Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) >= drawDown + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Max InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Long Time Trades ... +bool CloseAllLongTimeTrades( + const int passedCandles +) { + // + bool result = false; + + // + if (passedCandles <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + + // + if ( + openBarIndex - currentBarIndex >= passedCandles + || ( + profit > 0.5 + && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 3) + ) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Long Time issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } else if ( + openTrades > 0 + && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 2) + ) { + // result = CloseAllInProfitTrades(); + // && CloseBiggestDrawDownTrade(); + } + } + } + } + + // + return result; +} + +// +// Close all trades which passed Maximum Drawdown ... +bool CloseAllMaximumDrawDownPassedTrades( + const double maxDrDownPercentPerPTrade +) { + // + if ( + initialBalance <= 0 + || maxDrDownPercentPerPTrade <= 0 + ) { + return false; + } + + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double maxAllowedDrawDown = -1 * (initialBalance * maxDrDownPercentPerPTrade); + + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + if ( + profit < 0 + && MathAbs(profit) >= MathAbs(maxAllowedDrawDown) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Maximum DarwDown issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Trades Which Opens before Specified Length ... +bool CloseAllTradesWhichOpenInPastMarketLength( + const int marketLen +) { + // + bool result = false; + + // + if (marketLen <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + + // + if (openBarIndex <= currentBarIndex + marketLen) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Market Reverse issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } else if (openTrades > 0) { + // + // Close all InProfit Trdes and Biggest InDrawDown Trades ... + // result = CloseAllInProfitTrades(); + // && CloseBiggestDrawDownTrade(); + } + } + } + } + + // + return result; +} +// +// END Close Orders ... +// + +// +// START Modify Orders ... +// +// +void ModifyAllPriceLesserOpenTrades( + const XSignal &signal +) { + // + // Loop through all Open Trades ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + double takeProfit = OrderTakeProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // When new Signal Comming with price less than + // currently open trade and tp less than currently + // open trade, this means a market change happens ... + // here we can Close InProfit Trades or Modify Trades TP ... + if ( + openPrice < signal.entry + && takeProfit > signal.tp + ) { + bool result = OrderModify( + ticket, + openPrice, + signal.sl, + signal.tp, + clrYellow + ); + } + } + } + } +} + +// +void ModifyOpenTradesBasedOnCurrentTrade( + const XSignal &signal +) { + // + ModifyAllPriceLesserOpenTrades(signal); +} +// +// END Modify Orders ... +// +// +// END Orders Functions ... +// + +// +// START Signal Conditions ... +// +// +// Clear Signal Conditions ... +void ClearSignalConditions() { + // + ClearLongSignalConditions(); + ClearShortSignalConditions(); +} + +// +// Clear all Conditions Waiter for Long Signals ... +void ClearLongSignalConditions() { + // + ClearXLongSignalConditions(); + // + // ClearOSCLongSignalConditions(); + // ClearCCILongSignalConditions(); + // ClearSHPLongSignalConditions(); + // ClearXRMALongSignalConditions(); + // // + // ClearXMASCLongSignalConditions(); + // ClearXMAMCLongSignalConditions(); + // ClearXMAMMLongSignalConditions(); +} + +// +// Clear all Conditions Waiter for Short Signals ... +void ClearShortSignalConditions() { +} +// +// END Signal Conditions ... +// diff --git a/Bkp/Used/14020425/Libraries/x-saherelm.x.signal.lib.mq4 b/Bkp/Used/14020425/Libraries/x-saherelm.x.signal.lib.mq4 new file mode 100644 index 0000000..d147bf1 --- /dev/null +++ b/Bkp/Used/14020425/Libraries/x-saherelm.x.signal.lib.mq4 @@ -0,0 +1,592 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 X Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// X Based Signal Conditions ... +struct XSignalConditions { + datetime startTime; + datetime signalTime; +}; + +// +static XSignalConditions xLongConds; +static XSignalConditions xShortConds; + +// +static bool xWaitForLongSignals = true; +static bool xCloseLongTrades = false; + +// +static bool xWaitForShortSignals = true; +static bool xCloseShortTrades = false; + +// +bool isLastTrendUp = false; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long Signal Conditions ... +void CheckXLongSignalConditions( + const int bar_index, + const int marketLen, + const XState &states[], + // + const double smoother = 5 +) { + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // // + // bool isCrossUnder = + // states[1].osc.fast < states[1].osc.slow + // && !(states[2].osc.fast < states[2].osc.slow) + // ; + + // // + // bool isCrossOver = + // states[1].osc.fast > states[1].osc.slow + // && !(states[2].osc.fast > states[2].osc.slow) + // ; + + // + XOHCL pCandle = GetCandleModel(1); + + // + bool isTrendingUp = + pCandle.low > states[0].bnd.high + && pCandle.high > states[0].bnd.high; + + // + bool isTrendingDown = + pCandle.high < states[0].bnd.low + && pCandle.low < states[0].bnd.low; + + // + bool isCrossUnder = + isTrendingDown + && !isTrendingUp + ; + + // + bool isCrossOver = + isTrendingUp + && !isTrendingDown + ; + + // // + // if (isTrendingUp && !isTrendingDown) { + // isLastTrendUp = true; + // } else if (isTrendingDown && !isTrendingUp) { + // isLastTrendUp = false; + // } + + // + // if (isLastTrendUp) { + // + // LogMessage( + // StringConcatenate( + // "isLastTrendUp: ", isLastTrendUp + // ) + // ); + // } + + // + if ( + isCrossUnder + && xLongConds.startTime == 0 + ) { + // + xLongConds.startTime = barTime; + return; + } + + // + if ( + isCrossOver + && xLongConds.startTime > 0 + && xLongConds.signalTime == 0 + ) { + // + xLongConds.signalTime = barTime; + return; + } +} + +// +// Check and Fill Short Signal Conditions ... +void CheckXShortSignalConditions( + const int bar_index, + const int marketLen, + const XState &states[], + // + const double smoother = 5 +) { + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + bool isCrossUnder = + states[1].osc.fast < states[1].osc.slow + && !(states[2].osc.fast < states[2].osc.slow) + ; + + // + bool isCrossOver = + states[1].osc.fast > states[1].osc.slow + && !(states[2].osc.fast > states[2].osc.slow) + ; + + // + if ( + isCrossOver + && xShortConds.startTime == 0 + ) { + // + xShortConds.startTime = barTime; + return; + } + + // + if ( + isCrossUnder + && xShortConds.startTime > 0 + && xShortConds.signalTime == 0 + ) { + // + xShortConds.signalTime = barTime; + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r, // Risk to Reward ratio ... + const XState &states[], + // + const double smoother = 5 +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + if (requestLong) { + // + if ( + !ValidateXLongConditions( + marketLen, + states, + smoother + ) + ) { + return result; + } + } else { + // + if ( + !ValidateXShortConditions( + marketLen, + states, + smoother + ) + ) { + return result; + } + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double askPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double bidPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double entryPrice = requestLong ? + askPrice : + bidPrice; + + // + double exitPrice = requestLong ? + bidPrice : + askPrice; + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + GetMarketLowestLow( + bar_index, + marketLen + ); + + // + double hh = + GetMarketHighestHigh( + bar_index, + marketLen + ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = requestLong ? + MathMin(openPrice, closePrice) - ll : + hh - MathMax(openPrice, closePrice); + double reward = risk * r2r; // risk * r2r; // 300 * _Point; + // if (risk > (500 * _Point)) { + // reward = 300 * _Point; + // } + + // + double sl = 0; // ll; + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = type; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_XXX_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XXX_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXLongConditions( + const int marketLen, + const XState &states[], + // + const double smoother = 5 +) { + // + bool isConditionsFilled = + xLongConds.startTime > 0 + && xLongConds.signalTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.signalTime + ); + + // + isBLFilled = + // + xLongConds.signalTime > xLongConds.startTime + && MathAbs(signalBarIndex - startBarIndex) > 2 + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXLongSignalConditions(); + } + + // + return result; +} + +bool ValidateXShortConditions( + const int marketLen, + const XState &states[], + // + const double smoother = 5 +) { + // + bool isConditionsFilled = + xShortConds.startTime > 0 + && xShortConds.signalTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.signalTime + ); + + // + isBLFilled = + // + xShortConds.signalTime > xShortConds.startTime + && MathAbs(signalBarIndex - startBarIndex) > 2 + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXShortSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXLongSignalConditions() { + // + xLongConds.startTime = 0; + xLongConds.signalTime = 0; +} + +// +// Clear Short Signal Conditions for New One ... +void ClearXShortSignalConditions() { + // + xShortConds.startTime = 0; + xShortConds.signalTime = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForXSignals( + const XSignal &signal, + const XState &states[], + const int marketLen, + // + double smoother = 100 +) { + // + bool result = false; + + // + bool isSCTrendUp = + states[1].sc.fast > states[1].sc.slow + && states[2].sc.fast > states[2].sc.slow; + + // // + // bool isSCTrendDown = + // states[1].sc.fast < states[1].sc.slow + // && states[2].sc.fast < states[2].sc.slow; + + // + bool isMCTrendUp = + states[1].mc.fast > states[1].mc.slow + && states[2].mc.fast > states[2].mc.slow; + + // // + // bool isMCTrendDown = + // states[1].mc.fast < states[1].mc.slow + // && states[2].mc.fast < states[2].mc.slow; + + // + bool isLCTrendUp = + states[1].lc.fast > states[1].lc.slow + && states[2].lc.fast > states[2].lc.slow; + + // // + // bool isLCTrendDown = + // states[1].lc.fast < states[1].lc.slow + // && states[2].lc.fast < states[2].lc.slow; + + // // + // bool isTrendingUp = + // pCandle.low > states[0].bnd.high + // && pCandle.high > states[0].bnd.high; + + // // + // bool isTrendingDown = + // pCandle.high < states[0].bnd.low + // && pCandle.low < states[0].bnd.low; + + // // + // if (isTrendingUp && !isTrendingDown) { + // isLastTrendUp = true; + // } else if (isTrendingDown && !isTrendingUp) { + // isLastTrendUp = false; + // } + + // // + // if (isLastTrendUp) { + // // + // LogMessage( + // StringConcatenate( + // "isLastTrendUp: ", isLastTrendUp + // ) + // ); + // } + + // + // XOHCL pCandle = GetCandleModel(1); + + // + if (signal.type == X_SIGNAL_LONG) { + // + result = + // + true + // + && isSCTrendUp + && isMCTrendUp + && isLCTrendUp + // + && ( + ( + states[1].mc.slow < states[1].bnd.low + && states[1].mc.fast < MathMin(states[1].bnd.open, states[1].bnd.close) + ) || ( + states[1].lc.fast > states[1].bnd.low + && states[1].lc.fast > states[1].mc.fast + ) + ) + && MathAbs(states[1].mc.fast - states[1].bnd.low) > 50 * _Point + ; + } else if (signal.type == X_SIGNAL_SHORT) { + // + result = + false + ; + } + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020425/Libraries/x-saherelm.xma.mc.signal.lib.mq4 b/Bkp/Used/14020425/Libraries/x-saherelm.xma.mc.signal.lib.mq4 new file mode 100644 index 0000000..13b787e --- /dev/null +++ b/Bkp/Used/14020425/Libraries/x-saherelm.xma.mc.signal.lib.mq4 @@ -0,0 +1,490 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 XMA Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// XMA Based Signal Conditions ... +struct XMAMCLongSignalConditions { + // + datetime mcFastCrossUnderSlowTime; + double crossUnderMCFast; + double crossUnderMCSlow; + + // + datetime mcFastCrossOverSlowTime; + double crossOverMCFast; + double crossOverMCSlow; + + // + datetime mcFastBiggerThanCrossUnderSlowTime; +}; + +// +static XMAMCLongSignalConditions xmaMCLongConds; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill CC Signal Conditions ... +void CheckXMAMCLongSignalConditions( + const int bar_index, + const int marketLen, + // + double stp, + double mxm, + // + int scFMult, + int scSMult, + // + int mcFMult, + int mcSMult +) { + // + XCycleState mcs[]; + int positionsMarketLen = bar_index + marketLen; + + // + // Retrieve Bar Time ... + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Resize Arrays ... + ArrayResize( + mcs, + marketLen + ); + + // + int index = 0; + for (int i = bar_index; i < positionsMarketLen; i++) { + // + XCycleState mc = GetXMAMC( + i, + marketLen, + mcFMult, + mcSMult + ); + mcs[index] = mc; + + // + index++; + } + + // + bool isMCFastCrossUnderSlow = + mcs[0].fast < mcs[0].slow + && !(mcs[1].fast <= mcs[1].slow) + ; + bool isMCFastCrossOverSlow = + mcs[0].fast > mcs[0].slow + && !(mcs[1].fast >= mcs[1].slow) + ; + + // + if ( + isMCFastCrossUnderSlow + && xmaMCLongConds.mcFastCrossUnderSlowTime == 0 + ) { + // + xmaMCLongConds.crossUnderMCFast = mcs[0].fast; + xmaMCLongConds.crossUnderMCSlow = mcs[0].slow; + xmaMCLongConds.mcFastCrossUnderSlowTime = barTime; + return; + } + + // + if ( + isMCFastCrossUnderSlow + && xmaMCLongConds.mcFastCrossUnderSlowTime > 0 + ) { + // + ClearXMAMCLongSignalConditions(); + + // + xmaMCLongConds.crossUnderMCFast = mcs[0].fast; + xmaMCLongConds.crossUnderMCSlow = mcs[0].slow; + xmaMCLongConds.mcFastCrossUnderSlowTime = barTime; + return; + } + + // + if ( + isMCFastCrossOverSlow + && xmaMCLongConds.mcFastCrossUnderSlowTime > 0 + && xmaMCLongConds.mcFastCrossOverSlowTime == 0 + ) { + // + xmaMCLongConds.crossOverMCFast = mcs[0].fast; + xmaMCLongConds.crossOverMCSlow = mcs[0].slow; + xmaMCLongConds.mcFastCrossOverSlowTime = barTime; + return; + } + + // + if ( + xmaMCLongConds.mcFastCrossUnderSlowTime > 0 + && xmaMCLongConds.mcFastCrossOverSlowTime > 0 + && mcs[0].fast > xmaMCLongConds.crossUnderMCSlow + && xmaMCLongConds.mcFastBiggerThanCrossUnderSlowTime == 0 + ) { + // + xmaMCLongConds.mcFastBiggerThanCrossUnderSlowTime = barTime; + return; + } +} + +// +// Convert XMA Long Signal Conditions to XSignal ... +XSignalRequest GenerateXMAMCLongSignal( + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r, // Risk to Reward ratio ... + const double shpDetectMult, + const double smoother = 50 +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if ( + !ValidateXMAMCLongConditions( + marketLen, + shpDetectMult, + smoother + ) + ) { + return result; + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double entryPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double exitPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + GetMarketLowestLow( + bar_index, + 3 + ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = MathMin(openPrice, closePrice) - ll; + double reward = risk * r2r; + + // + double sl = 0; + double tp = entryPrice + reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = X_SIGNAL_LONG; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_XMA_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = X_SIGNAL_LONG; + result.provider = X_XMA_PROVIDER; + + // + return result; +} + +// +// Validate XMA Signal Conditions ... +bool ValidateXMAMCLongConditions( + const int marketLen, + const double shpDetectMult, + const double smoother = 50 +) { + // + bool isConditionsFilled = + xmaMCLongConds.crossOverMCSlow > 0 + && xmaMCLongConds.crossOverMCFast > 0 + && xmaMCLongConds.crossUnderMCFast > 0 + && xmaMCLongConds.crossUnderMCSlow > 0 + && xmaMCLongConds.mcFastCrossOverSlowTime != 0 + && xmaMCLongConds.mcFastCrossUnderSlowTime != 0 + && xmaMCLongConds.mcFastBiggerThanCrossUnderSlowTime != 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int crossUnderBarIndex = iBarShift( + _Symbol, + _Period, + xmaMCLongConds.mcFastCrossUnderSlowTime + ); + + // + int crossOverAndBiggerBarIndex = iBarShift( + _Symbol, + _Period, + xmaMCLongConds.mcFastBiggerThanCrossUnderSlowTime + ); + + // + int cycleMarketLen = MathMin( + MathAbs(crossUnderBarIndex - crossOverAndBiggerBarIndex), + marketLen * 2 + ); + double hh = GetMarketHighestHigh( + crossOverAndBiggerBarIndex, + cycleMarketLen + ); + double ll = GetMarketLowestLow( + crossOverAndBiggerBarIndex, + cycleMarketLen + ); + + // + double high = iHigh( + _Symbol, + _Period, + crossOverAndBiggerBarIndex + ); + double pcHigh = iHigh( + _Symbol, + _Period, + crossOverAndBiggerBarIndex + 1 + ); + + // + double diff = (hh - ll); + double shpValue = shpDetectMult * _Point; + + // + bool isPriceRegular = + // + true + // + && + ( + diff < shpValue + || diff < shpValue - (smoother * _Point) + ) + && + !( + high == hh + || pcHigh == hh + || MathAbs(hh - high) < (smoother * _Point) + || MathAbs(hh - pcHigh) < (smoother * _Point) + ) + ; + + // + // LogMessage("Price Regular: " + isPriceRegular); + + // + isBLFilled = + isPriceRegular + && xmaMCLongConds.mcFastCrossUnderSlowTime < xmaMCLongConds.mcFastCrossOverSlowTime + && xmaMCLongConds.mcFastBiggerThanCrossUnderSlowTime >= xmaMCLongConds.mcFastCrossUnderSlowTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXMAMCLongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXMAMCLongSignalConditions() { + // + xmaMCLongConds.mcFastCrossUnderSlowTime = 0; + xmaMCLongConds.crossUnderMCFast = 0; + xmaMCLongConds.crossUnderMCSlow = 0; + + // + xmaMCLongConds.mcFastCrossOverSlowTime = 0; + xmaMCLongConds.crossOverMCFast = 0; + xmaMCLongConds.crossOverMCSlow = 0; + + // + xmaMCLongConds.mcFastBiggerThanCrossUnderSlowTime = 0; +} + +// +// Check XMA State for Long Signals ... +bool IsReadyForXMAMCLongSignals( + const XSignal &signal, + const XState &states[], + const int marketLen +) { + // + bool result = false; + + // + int countRangedCandles = 0; + bool isMarketRanging = false; + for (int i = 1; i < marketLen; i++) { + // + double high = iHigh( + _Symbol, + _Period, + i + ); + + // + double low = iLow( + _Symbol, + _Period, + i + ); + + // + bool isRanging = + // + high > states[i].mc.fast + && high > states[i].mc.slow + // + && low < states[i].mc.fast + && low < states[i].mc.slow + ; + if (isRanging) { + countRangedCandles++; + } + } + + // + XStateInfo info = ParseXMAStates(states); + double mmSlope = GetSlope( + 1, + states[1].marketMiddleage, + 2, + states[0].marketMiddleage + ); + double mmSlope1 = GetSlope( + 1, + states[2].marketMiddleage, + 2, + states[1].marketMiddleage + ); + double mmSlopeDiff = mmSlope - mmSlope1; + + // + isMarketRanging = countRangedCandles > 0; + + // + result = + // + true + // + && mmSlope > 0 + && mmSlope1 > 0 + && mmSlopeDiff > 0 + && !isMarketRanging + && states[0].marketMiddleage < info.mmMax + ; + // if (result) { + // LogMessage("mmSlope: " + mmSlope + ", mmSlope1: " + mmSlope1 + ", Diff: " + mmSlopeDiff); + // } + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020425/Libraries/x-saherelm.xma.mm.signal.lib.mq4 b/Bkp/Used/14020425/Libraries/x-saherelm.xma.mm.signal.lib.mq4 new file mode 100644 index 0000000..d883803 --- /dev/null +++ b/Bkp/Used/14020425/Libraries/x-saherelm.xma.mm.signal.lib.mq4 @@ -0,0 +1,338 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 XMA Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// XMA Based Signal Conditions ... +struct XMAMMLongSignalConditions { + // + datetime crossUnderTime; + + // + datetime crossOverTime; +}; + +// +static XMAMMLongSignalConditions xmaMMLongConds; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill CC Signal Conditions ... +void CheckXMAMMLongSignalConditions( + const int bar_index, + const int marketLen, + // + double stp, + double mxm, + // + int scFMult, + int scSMult, + // + int mcFMult, + int mcSMult, + // + int lcFMult, + int lcSMult, + // + const double smoother = 5 +) { + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XState states[]; + ArrayResize( + states, + marketLen + ); + + // + int index = 0; + for (int i = bar_index; i < marketLen; i++) { + // + XState state = GetXState( + i, + marketLen, + // + stp, + mxm, + scFMult, + scSMult, + mcFMult, + mcSMult, + lcFMult, + lcSMult + ); + + // + states[index] = state; + + // + index++; + } + + // + bool isCrossUnder = + states[1].marketMiddleage < states[1].sc.fast + && !(states[2].marketMiddleage < states[2].sc.fast) + ; + + // + bool isCrossOver = + states[1].marketMiddleage > states[1].sc.fast + && !(states[2].marketMiddleage > states[2].sc.fast) + ; + + // + if ( + isCrossUnder + && xmaMMLongConds.crossUnderTime == 0 + ) { + // + xmaMMLongConds.crossUnderTime = barTime; + return; + } + + // + if ( + isCrossOver + && xmaMMLongConds.crossUnderTime > 0 + && xmaMMLongConds.crossOverTime == 0 + ) { + // + xmaMMLongConds.crossOverTime = barTime; + return; + } +} + +// +// Convert XMA Long Signal Conditions to XSignal ... +XSignalRequest GenerateXMAMMLongSignal( + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r // Risk to Reward ratio ... +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if (!ValidateXMAMMLongConditions()) { + return result; + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double entryPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double exitPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + GetMarketLowestLow( + bar_index, + marketLen + ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = MathMin(openPrice, closePrice) - ll; + double reward = 300 * _Point; // risk * r2r; + + // + double sl = 0; // entryPrice - (300 * _Point); // ll; + double tp = entryPrice + reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = X_SIGNAL_LONG; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_XMA_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = X_SIGNAL_LONG; + result.provider = X_XMA_PROVIDER; + + // + return result; +} + +// +// Validate XMA Signal Conditions ... +bool ValidateXMAMMLongConditions() { + // + bool isConditionsFilled = + true + && xmaMMLongConds.crossOverTime > 0 + && xmaMMLongConds.crossUnderTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int crossOverBarIndex = iBarShift( + _Symbol, + _Period, + xmaMMLongConds.crossOverTime + ); + + // + int crossUnderBarIndex = iBarShift( + _Symbol, + _Period, + xmaMMLongConds.crossUnderTime + ); + + // + isBLFilled = + true + // + && (crossUnderBarIndex - crossOverBarIndex) > 5 + // + && xmaMMLongConds.crossOverTime > xmaMMLongConds.crossUnderTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXMAMMLongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXMAMMLongSignalConditions() { + // + xmaMMLongConds.crossOverTime = 0; + xmaMMLongConds.crossUnderTime = 0; +} + +// +// Check XMA State for Long Signals ... +bool IsReadyForXMAMMLongSignals( + const XSignal &signal, + const XState &states[], + const int marketLen +) { + // + bool result = false; + + // + result = + // + true + // + // && states[0].parabolicSAR < states[0].marketMiddleage + // && !( + // states[0].parabolicSAR < states[0].mc.fast + // && states[0].parabolicSAR < states[0].mc.slow + // ) + // + // && states[0].mc.fast > states[0].mc.slow + // + // && MathAbs(states[0].mc.fast - states[0].mc.slow) > (150 * _Point) + ; + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020425/Libraries/x-saherelm.xma.sc.signal.lib.mq4 b/Bkp/Used/14020425/Libraries/x-saherelm.xma.sc.signal.lib.mq4 new file mode 100644 index 0000000..218759c --- /dev/null +++ b/Bkp/Used/14020425/Libraries/x-saherelm.xma.sc.signal.lib.mq4 @@ -0,0 +1,360 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 XMA Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// XMA Based Signal Conditions ... +struct XMASCLongSignalConditions { + // + datetime scFastCrossUnderSlowTime; + double crossUnderSCFast; + double crossUnderSCSlow; + + // + datetime scFastCrossOverSlowTime; + double crossOverSCFast; + double crossOverSCSlow; + + // + datetime scFastBiggerThanCrossUnderSlowTime; +}; + +// +static XMASCLongSignalConditions xmaSCLongConds; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill CC Signal Conditions ... +void CheckXMASCLongSignalConditions( + const int bar_index, + const int marketLen, + // + double stp, + double mxm, + // + int scFMult, + int scSMult, + // + int mcFMult, + int mcSMult +) { + // + XCycleState scs[]; + int positionsMarketLen = bar_index + marketLen; + + // + // Retrieve Bar Time ... + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Resize Arrays ... + ArrayResize( + scs, + marketLen + ); + + // + int index = 0; + for (int i = bar_index; i < positionsMarketLen; i++) { + // + XCycleState sc = GetXMASC( + i, + marketLen, + scFMult, + scSMult + ); + scs[index] = sc; + + // + index++; + } + + // + bool isSCFastCrossUnderSlow = + scs[0].fast < scs[0].slow + && !(scs[1].fast <= scs[1].slow) + ; + bool isSCFastCrossOverSlow = + scs[0].fast > scs[0].slow + && !(scs[1].fast >= scs[1].slow) + ; + + // + if ( + isSCFastCrossUnderSlow + && xmaSCLongConds.scFastCrossUnderSlowTime == 0 + ) { + // + xmaSCLongConds.crossUnderSCFast = scs[0].fast; + xmaSCLongConds.crossUnderSCSlow = scs[0].slow; + xmaSCLongConds.scFastCrossUnderSlowTime = barTime; + return; + } + + // + if ( + isSCFastCrossOverSlow + && xmaSCLongConds.scFastCrossUnderSlowTime > 0 + && xmaSCLongConds.scFastCrossOverSlowTime == 0 + ) { + // + xmaSCLongConds.crossOverSCFast = scs[0].fast; + xmaSCLongConds.crossOverSCSlow = scs[0].slow; + xmaSCLongConds.scFastCrossOverSlowTime = barTime; + return; + } + + // + if ( + xmaSCLongConds.scFastCrossUnderSlowTime > 0 + && xmaSCLongConds.scFastCrossOverSlowTime > 0 + && scs[0].fast > xmaSCLongConds.crossUnderSCSlow + && xmaSCLongConds.scFastBiggerThanCrossUnderSlowTime == 0 + ) { + // + xmaSCLongConds.scFastBiggerThanCrossUnderSlowTime = barTime; + return; + } + + // + if ( + isSCFastCrossUnderSlow + && xmaSCLongConds.scFastCrossUnderSlowTime > 0 + && xmaSCLongConds.scFastCrossOverSlowTime > 0 + ) { + // + ClearXMASCLongSignalConditions(); + return; + } +} + +// +// Convert XMA Long Signal Conditions to XSignal ... +XSignalRequest GenerateXMASCLongSignal( + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r // Risk to Reward ratio ... + // + // const double shpDetectMultiplier +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if (!ValidateXMASCLongConditions()) { + return result; + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double entryPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double exitPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + GetMarketLowestLow( + bar_index, + marketLen + ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + 1 + ); + + // // + // double sharpDetectValue = shpDetectMultiplier * _Point; + // double lowPrice = iLow( + // _Symbol, + // _Period, + // bar_index + 1 + // ); + + // + double risk = MathMin(openPrice, closePrice) - ll; + double reward = risk * r2r; + + // + double sl = 0; + double tp = entryPrice + reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = X_SIGNAL_LONG; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_XMA_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = X_SIGNAL_LONG; + result.provider = X_XMA_PROVIDER; + + // + return result; +} + +// +// Validate XMA Signal Conditions ... +bool ValidateXMASCLongConditions() { + // + bool isConditionsFilled = + xmaSCLongConds.crossOverSCSlow > 0 + && xmaSCLongConds.crossOverSCFast > 0 + && xmaSCLongConds.crossUnderSCFast > 0 + && xmaSCLongConds.crossUnderSCSlow > 0 + && xmaSCLongConds.scFastCrossOverSlowTime != 0 + && xmaSCLongConds.scFastCrossUnderSlowTime != 0 + && xmaSCLongConds.scFastBiggerThanCrossUnderSlowTime !=0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + isBLFilled = + xmaSCLongConds.crossOverSCFast > xmaSCLongConds.crossUnderSCSlow + && xmaSCLongConds.scFastCrossUnderSlowTime < xmaSCLongConds.scFastCrossOverSlowTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXMASCLongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXMASCLongSignalConditions() { + // + xmaSCLongConds.crossUnderSCFast = 0; + xmaSCLongConds.crossUnderSCSlow = 0; + xmaSCLongConds.scFastCrossUnderSlowTime = 0; + + // + xmaSCLongConds.crossOverSCFast = 0; + xmaSCLongConds.crossOverSCSlow = 0; + xmaSCLongConds.scFastCrossOverSlowTime = 0; + + // + xmaSCLongConds.scFastBiggerThanCrossUnderSlowTime = 0; +} + +// +// Check XMA State for Long Signals ... +bool IsReadyForXMASCLongSignals( + const XSignal &signal, + const XState &states[], + const int marketLen +) { + // + bool result = false; + + // + result = + // + true + // + && states[0].sc.fast > states[0].sc.slow + && states[1].sc.fast > states[1].sc.slow + ; + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020425/x-saherelm.ea.mq4 b/Bkp/Used/14020425/x-saherelm.ea.mq4 new file mode 100644 index 0000000..4e5ea07 --- /dev/null +++ b/Bkp/Used/14020425/x-saherelm.ea.mq4 @@ -0,0 +1,1130 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XST Strategy Expert Advisor +// --------------------------------------------- +// saherelm implementation of strategy expert advisor ... +// in this EA, we try to combine multiple tools, to ashive best +// results ... +// +// ShortName: XST +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +989121694056 +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XST Strategy Expert Advisor" +#property strict + +// +// START Inputs ... +// +// +// Signal Prefixe ... +input string signalPrefix = "XST"; // Signal Prefix + +// +// Signal Draw Specifications ... +input string bullishSignalLabel = "X_BUY"; // Bullish Signal Label +input color bullishSignalColor = clrAqua; // Bullish Signal Color + +// +input string bearishSignalLabel = "X_SELL"; // Bearish Signal Label +input color bearishSignalColor = clrFuchsia; // Bearish Signal Color + +// // +// input bool useCCISignalling = false; // Use XCCI Signalling +// input string cciSignalIdentifier = "XCCI"; // XCCI Signal Identifier + +// // +// input bool useOSCSignalling = false; // Use XOSC Signalling +// input string oscSignalIdentifier = "XOSC"; // XOSC Signal Identifier + +// // +// input bool useSHPSignalling = false; // Use XSHP Signalling +// input string shpSignalIdentifier = "XSHP"; // XSHP Signal Identifier + +// // +// input bool useRMASignalling = false; // Use RMA Signalling +// input string rmaSignalIdentifier = "XRMA"; // XRMA Signal Identifier + +// // +// input bool useXMASCSignalling = false; // Use XMA SC Signalling +// input bool useXMAMCSignalling = false; // Use XMA MC Signalling +// input bool useXMAMMSignalling = false; // Use XMA MM Signalling +// input string xmaSignalIdentifier = "XMA"; // XMA MM Signal Identifier + +// +input color signalEntryColor = clrAquamarine; // Signal Entry Ptice Color +input color signalSLColor = clrRed; // Signal SL Color +input color signalTPColor = clrGreen; // Signal TP Color + +// +// Trade ... +input bool allowTrade = true; // Allow Trade Based on given Signals +input bool allowLongTrades = true; // Allow Long Trades +input bool allowShortTrades = false; // Allow Short Trades + +// +// Market Specification Inpouts ... +input int marketLength = 7; // Market Length +input double riskToRewardRatio = 1.5; // Risk to Reward Ratio +// input double maxTPMultiplier = 1000; // Max Allowed TP + +// +// Alerts ... +input bool alertEvents = true; // Alert Events +input bool alertPositions = true; // Alert Positions +input bool longPositionAlerts = true; // Alert Long Positions +input bool shortPositionAlerts = true; // Alert Short Positions + +// +// Alert Types ... +input bool terminalAlert = false; // Terminal Alert +input bool pushAlert = false; // Push Notification Alerts + +// +// Balance and Finanical Specifications ... +input double lotsPerTradePercent = 0.00001; // Lots Per Trade Percent +input int maxOpenTrades = 4; // Maximum Open Trade +input double maxDrawdownPercentPerPTrade = 0.01; // Maximum DrawDown Per Trade +input double minBalancePercent = 0.5; // Minimum Balance for Trading +input double maxEquityPercent = 0.1; // Maximum Trade Equity +input int closeAllOpenTradesAfterCandle = 504; // Close All Open Trades After Passed Candles +input bool closeAllInProfitOpenTradesWhenMaxOpenTradesReached = false; // Close All In Profit Open Trades When Max Open Trades Reached and New Signal Income + +// +// Indicators ... +// +// CCI Inputs ... +input double step = 0.01; // SAR Step +input double maximum = 0.1; // SAR Maximum + +// +// XMA Inputs ... +// +input int shortCycleFastMultiplier = 2; // Short Cycle Fast Multiplier +input int shortCycleSlowMultiplier = 4; // Short Cycle Slow Multiplier +input int mediumCycleFastMultiplier = 6; // Medium Cycle Fast Multiplier +input int mediumCycleSlowMultiplier = 12; // Medium Cycle Slow Multiplier +input int longCycleFastMultiplier = 36; // Long Cycle Fast Multiplier +input int longCycleSlowMultiplier = 72; // Long Cycle Slow Multiplier + +// +// SHPD Indicator ... +input double sharpDetectMultiplier = 800; // Sharp Detect Multiplier +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +int lastSignalledBar = 0; + +// +// bool waitForXMAMMLongSignal = true; +// bool waitForXMAMCLongSignal = true; +// bool waitForXMASCLongSignal = true; +// bool waitForOSCLongSignal = true; +// bool waitForSHPLongSignal = true; +// bool waitForCCILongSignal = true; +// bool waitForRMALongSignal = true; + +// +bool waitForLongSignals = true; +bool closeLongTrades = false; + +// +bool waitForShortSignals = true; +bool closeShortTrades = false; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.signal.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Validate Inputs ... + bool inputsNotValiid = + // + // MARKET ... + marketLength < 0 + || riskToRewardRatio < 0 + // + // EA ... + || lotsPerTradePercent < 0 + || maxOpenTrades <= 0 + || maxDrawdownPercentPerPTrade < 0 + || minBalancePercent < 0 + || maxEquityPercent < 0 + || marketLength < 0 + // + // XMA ... + // + // Validate Short Cycle ... + || shortCycleFastMultiplier <= 0 + || shortCycleSlowMultiplier <= 0 + || shortCycleFastMultiplier >= shortCycleSlowMultiplier + // + // Validate Medium Cycle ... + || mediumCycleFastMultiplier <= 0 + || mediumCycleSlowMultiplier <= 0 + || mediumCycleFastMultiplier >= mediumCycleSlowMultiplier + // + // Validate Long Cycle ... + || longCycleFastMultiplier <= 0 + || longCycleSlowMultiplier <= 0 + || longCycleFastMultiplier >= longCycleSlowMultiplier + // + // Validate Series of Multipliers ... + || shortCycleFastMultiplier >= mediumCycleFastMultiplier + || mediumCycleFastMultiplier >= longCycleFastMultiplier + ; + + // + if (inputsNotValiid) { + return INIT_PARAMETERS_INCORRECT; + } + + // + totalSignals = 0; + totalLongSignals = 0; + totalShortSignals = 0; + + // + initialBalance = 0; + + // + // START Define Array Series ... + // + // + // END Define Array Series ... + // + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST"; + + // // + // // Set Event Timer on One Seccond ... + // bool isEventSet = EventSetTimer(1); + // if (!isEventSet) { + // LogMessage("Error: " + GetLastError()); + // return INIT_FAILED; + // } + + // + ClearSignalConditions(); + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + // Killing Event Timer ... + EventKillTimer(); +} + +// +// Ticker Event Handler ... +void OnTick() { + // + isNewDay = IsNewDay(); + if (isNewDay) { + // + LogMessage( + StringConcatenate( + "New Day: ", TimeCurrent() + ) + ); + } + + // + // Process Signals to Open Positions ... + ProcessSignals(); + + // + // Checking State for Signal Handling ... + CheckState(); + + // + // Process Open Positions for Trailing Stop Loss or Close ... + ProcessOpenPositions(); +} + +// +// Timer Event Handler ... +void OnTimer() { + // + CheckState(); + + // + ProcessOpenPositions(); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Check State for Signal Handling ... +void CheckState() { + // + // Here we Must to Check Market State for enable or disable + // Signal Handlers and also make dection to close all long/short + // trades ... + + // + // Prevent from Checking, if there is no states available ... + // if (ArraySize(mStates) == 0) { + // return; + // } + + // // + // // XMA MM Long ... + // if (waitForXMAMMLongSignal) { + // } else { + // } + + // // + // // XMA MC Long ... + // if (waitForXMAMCLongSignal) { + // } else { + // } + + // // + // // OSC Long ... + // if (waitForOSCLongSignal) { + // } else { + // } + + // // + // // SHP Long ... + // if (waitForSHPLongSignal) { + // } else { + // } + + // // + // // CCI Long ... + // if (waitForCCILongSignal) { + // } else { + // } + + // // + // closeLongTrades = + // xmaStates[0].parabolicSAR > xmaStates[0].marketMiddleage + // && !(xmaStates[1].parabolicSAR > xmaStates[1].marketMiddleage) + // ; + + // // + // closeLongTrades = + // false + // ; +} + +// +// Calculate Signals and Process Based on Exists Signals ... +void ProcessSignals() { + // + XSignalRequest request = {}; + request.type = X_SIGNAL_NONE; + request.hasSignal = false; + + // + // Prevent Multiple Calculating on Same Bars ... + isNewBar = IsNewBar(); + if (isNewBar) { + countedBars++; + } + + // + if (countedBars < longCycleSlowMultiplier * marketLength) { + return; + } + + // + bool allowDoTrade = true; + + // + // Check Balance ... + if (initialBalance > 0) { + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double minimumBalanceForTrade = + balance > initialBalance + ? + minBalancePercent * balance + : + minBalancePercent * initialBalance; + + // + // Retrieve Account Equity ... + double equity = AccountInfoDouble(ACCOUNT_EQUITY); + double maxAllowedEquity = balance - (balance * maxEquityPercent); + + // + // Retrieve Free Marigin ... + double freeMargin = AccountFreeMargin(); + double maximumMariginRisk = balance - (balance * maxEquityPercent); + + // + if ( + // + // Do not Open Positions if equity not passed ... + equity < maxAllowedEquity || + // + // Do not Open Positions if free margin not passed ... + freeMargin <= maximumMariginRisk || + // + // Do not open positions if balance less than minimum ... + balance <= minimumBalanceForTrade + ) { + // + allowDoTrade = false; + + // // + // string message = StringConcatenate( + // "Trading Pause => ", + // "Balance: ", balance, + // ", Equity: ", equity, + // ", FreeMargin: ", freeMargin + // ); + + // // + // LogMessage(message); + // SendAlert(message); + } + } + + // + // Retrieve Signal Exists ... + request = GenerateSignal(0); + + // + // Prevent doing anything else, if there is no signals ... + if ( + !allowDoTrade || + !request.hasSignal || + request.type == X_SIGNAL_NONE + ) { + return; + } + + // + bool hasLongSignal = request.type == X_SIGNAL_LONG; + + // + // Check For Bot State ... + if ( + (hasLongSignal && !waitForLongSignals) + || (!hasLongSignal && !waitForShortSignals) + ) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + return; + } + + // + // Check last Signalled Bar with Counted Bars ... + // Prevent Multiple Signalling on Same Bar ... + bool isInLastSignalledBars = false; + for (int i=0; i < marketLength; i++) { + // + isInLastSignalledBars = + isInLastSignalledBars + || lastSignalledBar == countedBars - i + ; + } + if (isInLastSignalledBars) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + return; + } + + // + // increase last signalled bar ... + lastSignalledBar = countedBars; + + // + // Calculate Can Trade or not ... + allowDoTrade = allowTrade + && ( + hasLongSignal ? + allowLongTrades : + allowShortTrades + ); + + // + // Chack Maximum Open Positions ... + int openTrades = CountOpenTrades(); + if (maxOpenTrades > 0) { + // + if (openTrades >= maxOpenTrades) { + // + allowDoTrade = false; + + // + if (closeAllInProfitOpenTradesWhenMaxOpenTradesReached) { + // + // Close All In Profit Trades ... + bool hasClosedInProfitTrade = CloseAllInProfitTrades(); + if (hasClosedInProfitTrade) { + // + openTrades = CountOpenTrades(); + + // + allowDoTrade = !(openTrades >= maxOpenTrades); + } + } + + // + if (!allowDoTrade) { + // + string message = StringConcatenate( + "Trading Pause => ", + "Max Open Trades (", + maxOpenTrades, + ") reached ..." + ); + + // + LogMessage(message); + SendAlert(message); + } + } + } + + // + // Check Trading is Enable or not ... + // nothing to do if trading is disabled ... + if (!allowDoTrade) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // // + // string message = StringConcatenate( + // "Trading Not Allowed ..." + // ); + + // // + // LogMessage(message); + // SendAlert(message); + return; + } + + // + bool isPositionOpened = TradeSignal( + request.signal, + signalPrefix, + lotsPerTradePercent, + // + bullishSignalLabel, + bullishSignalColor, + bearishSignalLabel, + bearishSignalColor + // , + // // + // cciSignalIdentifier, + // shpSignalIdentifier, + // xmaSignalIdentifier, + // oscSignalIdentifier, + // rmaSignalIdentifier + ); + + // + totalSignals++; + if (hasLongSignal) { + // + totalLongSignals++; + ClearLongSignalConditions(); + } else { + // + totalShortSignals++; + ClearShortSignalConditions(); + } + + // + if (isPositionOpened) { + // + bool canAlert = + alertPositions + && ( + hasLongSignal ? + longPositionAlerts + : + shortPositionAlerts + ); + + // + if (canAlert) { + // + // Alert Message ... + string message = StringConcatenate( + "Trade on Signal ID: ", request.signal.id, + ", Entry: ", request.signal.entry, + ", TP: ", request.signal.tp + ); + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } + } + } +} + +// +// Process All Open Positions ... +void ProcessOpenPositions() { + // + // this comes from check state ... + if (closeLongTrades) { + // + closeLongTrades = false; + + // + bool isAllLongTradesClosed = CloseAllLongTrades(); + if (isAllLongTradesClosed) { + // waitForLongSignals = false; + } + } + + // + // this comes from check state ... + if (closeShortTrades) { + // + closeShortTrades = false; + + // + bool isAllShortTradesClosed = CloseAllShortTrades(); + if (isAllShortTradesClosed) { + // waitForShortSignals = false; + } + } + + // // + // bool closeAllXMALongTrades = CloseAllXMALongTrades( + // mStates + // ); + // if (closeAllXMALongTrades) { + // CloseAllProviderLongTrades( + // X_XMA_PROVIDER, + // // + // cciSignalIdentifier, + // shpSignalIdentifier, + // xmaSignalIdentifier + // ); + // } + + // + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + closeAllOpenTradesAfterCandle + ); + + // + // Close Maximum DrawDown Passed Trades ... + bool hasClosedInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + maxDrawdownPercentPerPTrade + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedInDrawDownLongTrade + ) { + // + // waitForLongSignals = false; + // waitForShortSignals = false; + } +} + +// +// Send Special Type of Alerts ... +void SendAlert(string message) { + // + if (!alertEvents) { + return; + } + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } +} +// +// END Functions ... +// + +// +// +// Calculate Signal ... +// in this function we calculate a signal exists in +// specific bar or not ... +XSignalRequest GenerateSignal( + const int bar_index // Bar Index ... +) { + // + // create temp result ... + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + bool hasSignal = false; + bool hasLongSignal = false; + bool hasShortSignal = false; + + // + XSignal signal = {}; + + // + // Retrieve XMA States ... + // based on medium cycle slow ... + XState states[]; + // int xmaMarketSize = 2 * marketLength; + ArrayFree(states); + ArrayResize( + states, + marketLength + ); + + // + int index = 0; + for (int i = bar_index; i < bar_index + marketLength; i++) { + // + states[index] = GetXState( + i, + marketLength, + // + step, + maximum, + // + shortCycleFastMultiplier, + shortCycleSlowMultiplier, + mediumCycleFastMultiplier, + mediumCycleSlowMultiplier, + longCycleFastMultiplier, + longCycleSlowMultiplier + ); + + // + index++; + } + + // // + // // Check if Use CCI Signalling true ... + // if (useCCISignalling) { + // // + // int cciMarketLength = longCycleSlowMultiplier * marketLength; + + // // + // if (waitForOSCLongSignal) { + // // + // CheckCCILongSignalConditions( + // bar_index + 1, + // cciMarketLength + // ); + + // // + // XSignalRequest cciLongSignalRequest = GenerateCCILongSignal( + // bar_index, + // marketLength, + // riskToRewardRatio + // ); + + // // + // if (cciLongSignalRequest.hasSignal) { + // // + // // Here we can Check and Filter Signals Based On XMA State ... + // bool isReady = IsReadyForCCILongSignals(mStates); + + // // + // if (isReady) { + // // + // hasLongSignal = true; + // signal = cciLongSignalRequest.signal; + // } else { + // // LogMessage("CCi Has Long Signal, but XMA not Verify ..."); + // ClearCCILongSignalConditions(); + // } + // } + // } + // } + + // // + // if (useSHPSignalling) { + // // + // if (waitForSHPLongSignal) { + // CheckSHPLongSignalConditions( + // bar_index, + // marketLength, + // sharpDetectMultiplier + // ); + + // // + // XSignalRequest shpLongSignalRequest = GenerateSHPLongSignal( + // bar_index, + // marketLength, + // riskToRewardRatio, + // sharpDetectMultiplier + // ); + + // // + // if (shpLongSignalRequest.hasSignal) { + // // + // // Here we can Check and Filter Signals Based On XMA State ... + // bool isReady = IsReadyForSHPLongSignals( + // shpLongSignalRequest.signal, + // mStates + // ); + + // // + // if (isReady) { + // // + // hasLongSignal = true; + // signal = shpLongSignalRequest.signal; + // } else { + // // LogMessage("SHP Has Long Signal, but XMA not Verify ..."); + // ClearSHPLongSignalConditions(); + // } + // } + // } + // } + + // // + // if (useOSCSignalling) { + // // + // if (waitForOSCLongSignal) { + // // + // CheckOSCLongSignalConditions( + // bar_index, + // marketLength, + // step, + // maximum, + // shortCycleFastMultiplier, + // shortCycleSlowMultiplier, + // mediumCycleFastMultiplier, + // mediumCycleSlowMultiplier, + // longCycleFastMultiplier, + // longCycleSlowMultiplier + // ); + + // // + // XSignalRequest oscLongSignalRequest = GenerateOSCLongSignal( + // bar_index, + // marketLength, + // riskToRewardRatio + // ); + + // // + // if (oscLongSignalRequest.hasSignal) { + // // + // // Here we can Check and Filter Signals Based On XMA State ... + // bool isReady = IsReadyForOSCLongSignals( + // oscLongSignalRequest.signal, + // mStates + // ); + + // // + // if (isReady) { + // // + // hasLongSignal = true; + // signal = oscLongSignalRequest.signal; + // } else { + // ClearOSCLongSignalConditions(); + // } + // } + // } + // } + + // // + // if (useRMASignalling) { + // // + // if (waitForRMALongSignal) { + // // + // CheckXRMALongSignalConditions( + // bar_index, + // marketLength + // ); + + // // + // XSignalRequest rmaLongSignalRequest = GenerateXRMALongSignal( + // bar_index, + // marketLength, + // riskToRewardRatio + // ); + + // // + // if (rmaLongSignalRequest.hasSignal) { + // // + // // Here we can Check and Filter Signals Based On XMA State ... + // bool isReady = IsReadyForXRMALongSignals( + // rmaLongSignalRequest.signal, + // mStates, + // marketLength + // ); + + // // + // if (isReady) { + // // + // hasLongSignal = true; + // signal = rmaLongSignalRequest.signal; + // } else { + // ClearXRMALongSignalConditions(); + // } + // } + // } + // } + + // // + // if (useXMASCSignalling) { + // // + // if (waitForXMASCLongSignal) { + // // + // CheckXMASCLongSignalConditions( + // bar_index, + // marketLength, + // step, + // maximum, + // shortCycleFastMultiplier, + // shortCycleSlowMultiplier, + // mediumCycleFastMultiplier, + // mediumCycleSlowMultiplier + // ); + + // // + // XSignalRequest xmaLongSignalRequest = GenerateXMASCLongSignal( + // bar_index, + // marketLength, + // riskToRewardRatio + // ); + + // // + // if (xmaLongSignalRequest.hasSignal) { + // // + // // Here we can Check and Filter Signals Based On XMA State ... + // bool isReady = IsReadyForXMASCLongSignals( + // xmaLongSignalRequest.signal, + // mStates, + // marketLength + // ); + + // // + // if (isReady) { + // // + // hasLongSignal = true; + // signal = xmaLongSignalRequest.signal; + // } else { + // ClearXMASCLongSignalConditions(); + // } + // } + // } + // } + + // // + // if (useXMAMCSignalling) { + // // + // if (waitForXMAMCLongSignal) { + // // + // CheckXMAMCLongSignalConditions( + // bar_index, + // marketLength, + // step, + // maximum, + // shortCycleFastMultiplier, + // shortCycleSlowMultiplier, + // mediumCycleFastMultiplier, + // mediumCycleSlowMultiplier + // ); + + // // + // XSignalRequest xmaLongSignalRequest = GenerateXMAMCLongSignal( + // bar_index, + // marketLength, + // riskToRewardRatio, + // sharpDetectMultiplier + // ); + + // // + // if (xmaLongSignalRequest.hasSignal) { + // // + // // Here we can Check and Filter Signals Based On XMA State ... + // bool isReady = IsReadyForXMAMCLongSignals( + // xmaLongSignalRequest.signal, + // mStates, + // marketLength + // ); + + // // + // if (isReady) { + // // + // hasLongSignal = true; + // signal = xmaLongSignalRequest.signal; + // } else { + // ClearXMAMCLongSignalConditions(); + // } + // } + // } + // } + + // // + // if (useXMAMMSignalling) { + // // + // if (waitForXMAMMLongSignal) { + // // + // CheckXMAMMLongSignalConditions( + // bar_index, + // marketLength, + // step, + // maximum, + // shortCycleFastMultiplier, + // shortCycleSlowMultiplier, + // mediumCycleFastMultiplier, + // mediumCycleSlowMultiplier, + // longCycleFastMultiplier, + // longCycleSlowMultiplier + // ); + + // // + // XSignalRequest xmaLongSignalRequest = GenerateXMAMMLongSignal( + // bar_index, + // marketLength, + // riskToRewardRatio + // ); + + // // + // if (xmaLongSignalRequest.hasSignal) { + // // + // // Here we can Check and Filter Signals Based On XMA State ... + // bool isReady = IsReadyForXMAMMLongSignals( + // xmaLongSignalRequest.signal, + // mStates, + // marketLength + // ); + + // // + // if (isReady) { + // // + // hasLongSignal = true; + // signal = xmaLongSignalRequest.signal; + // } else { + // ClearXMAMMLongSignalConditions(); + // } + // } + // } + // } + + // + hasSignal = hasLongSignal || hasShortSignal; + + // + if (!hasSignal) { + // + signal.type = X_SIGNAL_NONE; + result.type = X_SIGNAL_NONE; + } + + // + if (hasLongSignal) { + // // + // // Check TP and Fix it if it's too high ... + // double maxAllowedTP = signal.entry + (maxTPMultiplier * _Point); + // if (signal.tp > maxAllowedTP) { + // signal.tp = maxAllowedTP; + // } + + // // + // bool increaseTP = + // mStates[1].sc.fast < mStates[1].sc.slow + // && mStates[1].mc.fast < mStates[1].mc.slow + // ; + // if (increaseTP) { + // signal.tp = signal.entry + ((signal.tp - signal.entry) / 3); + // } + + // // + // bool decreaseTP = false; + // if (decreaseTP) { + // signal.tp = maxAllowedTP; + // } + } + + // + // Normalize TP, SL and Entry Price ... + signal.tp = NormalizeDouble(signal.tp, _Digits); + signal.sl = NormalizeDouble(signal.sl, _Digits); + signal.entry = NormalizeDouble(signal.entry, _Digits); + + // + result.signal = signal; + result.type = signal.type; + result.hasSignal = hasSignal; + result.provider = signal.provider; + + // + // Return Result ... + return result; +} diff --git a/Bkp/Used/14020425/x-saherelm.signal.lib.mq4 b/Bkp/Used/14020425/x-saherelm.signal.lib.mq4 new file mode 100644 index 0000000..19fef2b --- /dev/null +++ b/Bkp/Used/14020425/x-saherelm.signal.lib.mq4 @@ -0,0 +1,1478 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Signal Draw Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +#include "../Libraries/x-saherelm.x.signal.lib.mq4" +// #include "../Libraries/x-saherelm.osc.signal.lib.mq4" +// #include "../Libraries/x-saherelm.cci.signal.lib.mq4" +// #include "../Libraries/x-saherelm.shp.signal.lib.mq4" +// #include "../Libraries/x-saherelm.rma.signal.lib.mq4" +// #include "../Libraries/x-saherelm.xma.mm.signal.lib.mq4" +// #include "../Libraries/x-saherelm.xma.sc.signal.lib.mq4" +// #include "../Libraries/x-saherelm.xma.mc.signal.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// END Global Requirement Functions ... +// + +// +// START Signal Related Functions ... +// +// +// Retrieve Signal Bar Index ... +int GetSignalBarIndex(XSignal &signal) { + // + // Temp Result ... + int result = -1; + + // + // Retriev Signal Bar Index ... + result = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + return result; +} + +// +// Draw Signal Shapes on Chart ... +bool DrawSignal( + const XSignal &signal, + long chartID = 0, + int subWindowID = 0, + const double positionThresholdFactor = 10, + string signalTag = "X-Signal", + string longSignalLabel = "X-Long", + color longSignalColor = clrAqua, + string shortSignalLabel = "X-Short", + color shortSignalColor = clrFuchsia, + string provider = "" +) { + // + // Generate isLongSignal Var ... + bool isLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Signal Bar Index ... + int bar_index = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // START Draw Signal Arrow ... + // + // + // Arrow Shape Name ... + string arrowName = StringConcatenate(signalTag, "_Arrow_", signal.id); + + // + // Arrow Price ... + double arrowPrice = 0; + if (isLongSignal) { + // + arrowPrice = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice - (positionThresholdFactor * _Point); + } else { + // + arrowPrice = iHigh( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice + (positionThresholdFactor * _Point); + } + + // + // Arrow Code ... + uchar arrowCode = isLongSignal ? SYMBOL_ARROWUP : SYMBOL_ARROWDOWN; + + // + // Arrow Anchor Point ... + ENUM_ARROW_ANCHOR arrowAnchorPoint = isLongSignal ? ANCHOR_BOTTOM : ANCHOR_TOP; + + // + // Arrow Color ... + color arrowColor = isLongSignal ? longSignalColor : shortSignalColor; + + // + // Draw Signal Arrow Shape ... + bool result = DrawArrow( + chartID, + arrowName, + subWindowID, + signal.time, + arrowPrice, + arrowCode, + arrowAnchorPoint, + arrowColor + ); + // + // END Draw Signal Arrow ... + // + + // + // START Draw Signal SL/TP ... + // + string slLineName = StringConcatenate(signalTag, "_SL_", signal.id); + string tpLineName = StringConcatenate(signalTag, "_TP_", signal.id); + string entryLineName = StringConcatenate(signalTag, "_ENTRY_", signal.id); + + // + color slColor = shortSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color tpColor = longSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color entryColor = clrGreen; + + // + datetime time1 = iTime( + _Symbol, + _Period, + bar_index + 1 + ); + + // + // Draw Enrty Price ... + result = DrawTrendLine( + chartID, + entryLineName, + subWindowID, + time1, + signal.entry, + signal.time, + signal.entry, + entryColor, + STYLE_SOLID, + 2 + ); + + // + // Draw Signal SL ... + if (signal.sl > 0) { + // + result = DrawTrendLine( + chartID, + slLineName, + subWindowID, + time1, + signal.sl, + signal.time, + signal.sl, + slColor, + STYLE_SOLID, + 2 + ); + } + + // + // Draw Signal TP ... + if (signal.tp > 0) { + // + result = DrawTrendLine( + chartID, + tpLineName, + subWindowID, + time1, + signal.tp, + signal.time, + signal.tp, + tpColor, + STYLE_SOLID, + 2 + ); + } + // + // END Draw Signal SL/TP ... + // + + // + // Start Draw Signal Label ... + // + // + string labelName = StringConcatenate(signalTag, "_Label_", signal.id); + + // + double labelPrice = isLongSignal ? arrowPrice - (positionThresholdFactor * _Point) : arrowPrice + (positionThresholdFactor * _Point); + + // + string labelText = isLongSignal ? longSignalLabel : shortSignalLabel; + labelText = StringConcatenate( + labelText, + "_", + provider + ); + + // + result = DrawText( + chartID, + labelName, + subWindowID, + signal.time, + labelPrice, + labelText, + "Arial", + 8, + arrowColor, + 0, + ANCHOR_CENTER + ); + // + // End Draw Signal Label ... + // + + // + return result; +} + +// +// Trade on Specific Signal ... +bool TradeSignal( + XSignal &signal, + // + string prefix, + // + double volumePercent, + // + // Long ... + const string longSignalLabel, + const color longSignalColor, + // + // Short ... + const string shortSignalLabel, + const color shortSignalColor + // , + // + // Define Signal Identifiers ... + // const string cciSignalId, // Signal Identifier ... + // const string shpSignalId, // Signal Identifier ... + // const string xmaSignalId, // Signal Identifier ... + // const string oscSignalId, // Signal Identifier ... + // const string rmaSignalId // Signal Identifier ... +) { + // + // Temp Result ... + bool result = false; + + // + if (initialBalance == 0) { + initialBalance = AccountInfoDouble(ACCOUNT_BALANCE); + } + + // + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + int openPositions = CountOpenTrades(); + double volume = (volumePercent * initialBalance); + + // + if ( + signal.type != X_SIGNAL_LONG && + signal.type != X_SIGNAL_SHORT + ) { + return result; + } + + // + bool hasLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Check TP and Entry Price ... + if ( + ( + hasLongSignal + && signal.entry > signal.tp + ) || + ( + !hasLongSignal + && signal.entry < signal.tp + ) + ) { + return result; + } + + // + // Order Operation ... + int operation = hasLongSignal ? + OP_BUY : + OP_SELL; + + // + // Detect Trade Color ... + color clr = hasLongSignal ? + longSignalColor : + shortSignalColor; + + // + // Generate Signal Comment ... + string label = hasLongSignal ? + longSignalLabel : + shortSignalLabel; + + // + string provider = + // signal.provider == X_CCI_PROVIDER + // ? cciSignalId : + // signal.provider == X_SHP_PROVIDER + // ? shpSignalId : + // signal.provider == X_XMA_PROVIDER + // ? xmaSignalId : + // signal.provider == X_OSC_PROVIDER + // ? oscSignalId : + // signal.provider == X_RMA_PROVIDER + // ? rmaSignalId : + "" + ; + + // + // Generate Signal Comment ... + string comment = StringConcatenate( + prefix, + "_", signal.id, + "_", provider, + "_", label + ); + + // + // Placing Order ... + int orderTicket = OrderSend( + _Symbol, + operation, + volume, + signal.entry, + 3, + signal.sl, + signal.tp, + comment, + signal.id, + 0, + clr + ); + + // + // Draw Signal Shape if Order Opened Successfully ... + if (orderTicket >= 0) { + // + signal.ticket = orderTicket; + + // + // Here i must to Draw Signal Shapes ... + bool isDrawn = DrawSignal( + signal, + 0, + 0, + 50, + prefix, // Signal Tag ... + longSignalLabel, // Long Signal Label ... + longSignalColor, + shortSignalLabel, // Short Signal Label ... + shortSignalColor, + provider + ); + + // + LogMessage( + StringConcatenate( + "Order [", orderTicket ,"]: Provided by: ", provider + ) + ); + + // + // TODO: here we have to check if there are another + // open positions which their entry price is bigger + // than current signal entry price, for long trades and + // their tp is high than current tp, ... + // close in profit trades or modify orders tp to current ... + // // + // if (CountOpenTrades() > 0) { + // // + // // Here we have to + // // ModifyOpenTradesBasedOnCurrentTrade(signal); + // } + + // + result = true; + } + + // + return result; +} +// +// END Signal Related Functions ... +// + +// +// START Orders Functions ... +// +// +// Convert To XSignal Model ... +XSignal OrderToSignal( + // + // Define Signal Identifiers ... + const string cciSignalId, // Signal Identifier ... + const string shpSignalId, // Signal Identifier ... + const string xmaSignalId // Signal Identifier ... +) { + // + // Temp Result ... + XSignal result = {}; + result.type = X_SIGNAL_NONE; + + // + // Here we can get some usefull info based on selected order ... + double swap = OrderSwap(); + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + int magicNumber = OrderMagicNumber(); + double takeProfit = OrderTakeProfit(); + string comment = OrderComment(); + + // + ENUM_X_SIGNAL_PROVIDER provider = + StringFind( + comment, + cciSignalId + ) ? + X_CCI_PROVIDER : + StringFind( + comment, + shpSignalId + ) ? + X_SHP_PROVIDER : + StringFind( + comment, + xmaSignalId + ) ? + X_XMA_PROVIDER : + X_UNKNOWN_PROVIDER + ; + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // Conver Position to Signal ... + result.sl = stopLoss; + result.tp = takeProfit; + result.time = openTime; + result.symbol = _Symbol; + result.id = magicNumber; + result.comment = comment; + result.entry = openPrice; + result.provider = provider; + result.type = isLongOrder ? X_SIGNAL_LONG : X_SIGNAL_SHORT; + + // + return result; +} + +// +// START Count Orders ... +// +// +// Count Open Positions ... +int CountOpenTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if (OrderSymbol() == _Symbol) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Long Positions ... +int CountOpenLongTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_BUY + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Short Positions ... +int CountOpenShortTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_SELL + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} +// +// END Count Orders ... +// + +// +// START Close Orders ... +// +// +// Close All Open Trades ... +bool CloseAllTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + + // + return result; +} + +// +bool CloseAllProviderLongTrades( + const ENUM_X_SIGNAL_PROVIDER provider, + // + // Define Signal Identifiers ... + const string cciSignalId, // Signal Identifier ... + const string shpSignalId, // Signal Identifier ... + const string xmaSignalId // Signal Identifier ... +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal( + cciSignalId, + shpSignalId, + xmaSignalId + ); + + // + if (signal.provider == provider) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Long Trades ... +bool CloseAllLongTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Long Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Short Trades ... +bool CloseAllShortTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (!isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Short Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In Profit Trades ... +bool CloseAllInProfitTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit > 0 + && profit > 50 * _Point + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InProfit Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In DrawDown Trades ... +bool CloseAllInDrawDownTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if (profit < 0) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close Biggest In DrawDown Trades ... +bool CloseBiggestDrawDownTrade() { + // + // Loop through all Positions ... + bool result = false; + double drawDown = 0; + + // + // Find Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) > drawDown + ) { + drawDown = profit; + } + } + } + } + + // + // Close Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) >= drawDown + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Max InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Long Time Trades ... +bool CloseAllLongTimeTrades( + const int passedCandles +) { + // + bool result = false; + + // + if (passedCandles <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + + // + if ( + openBarIndex - currentBarIndex >= passedCandles + || ( + profit > 0.5 + && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 3) + ) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Long Time issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } else if ( + openTrades > 0 + && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 2) + ) { + // result = CloseAllInProfitTrades(); + // && CloseBiggestDrawDownTrade(); + } + } + } + } + + // + return result; +} + +// +// Close all trades which passed Maximum Drawdown ... +bool CloseAllMaximumDrawDownPassedTrades( + const double maxDrDownPercentPerPTrade +) { + // + if ( + initialBalance <= 0 + || maxDrDownPercentPerPTrade <= 0 + ) { + return false; + } + + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double maxAllowedDrawDown = -1 * (initialBalance * maxDrDownPercentPerPTrade); + + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + if ( + profit < 0 + && MathAbs(profit) >= MathAbs(maxAllowedDrawDown) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Maximum DarwDown issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Trades Which Opens before Specified Length ... +bool CloseAllTradesWhichOpenInPastMarketLength( + const int marketLen +) { + // + bool result = false; + + // + if (marketLen <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + + // + if (openBarIndex <= currentBarIndex + marketLen) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Market Reverse issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } else if (openTrades > 0) { + // + // Close all InProfit Trdes and Biggest InDrawDown Trades ... + // result = CloseAllInProfitTrades(); + // && CloseBiggestDrawDownTrade(); + } + } + } + } + + // + return result; +} +// +// END Close Orders ... +// + +// +// START Modify Orders ... +// +// +void ModifyAllPriceLesserOpenTrades( + const XSignal &signal +) { + // + // Loop through all Open Trades ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + double takeProfit = OrderTakeProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // When new Signal Comming with price less than + // currently open trade and tp less than currently + // open trade, this means a market change happens ... + // here we can Close InProfit Trades or Modify Trades TP ... + if ( + openPrice < signal.entry + && takeProfit > signal.tp + ) { + bool result = OrderModify( + ticket, + openPrice, + signal.sl, + signal.tp, + clrYellow + ); + } + } + } + } +} + +// +void ModifyOpenTradesBasedOnCurrentTrade( + const XSignal &signal +) { + // + ModifyAllPriceLesserOpenTrades(signal); +} +// +// END Modify Orders ... +// +// +// END Orders Functions ... +// + +// +// START Signal Conditions ... +// +// +// Clear Signal Conditions ... +void ClearSignalConditions() { + // + ClearLongSignalConditions(); + ClearShortSignalConditions(); +} + +// +// Clear all Conditions Waiter for Long Signals ... +void ClearLongSignalConditions() { + // + ClearXLongSignalConditions(); + // + // ClearOSCLongSignalConditions(); + // ClearCCILongSignalConditions(); + // ClearSHPLongSignalConditions(); + // ClearXRMALongSignalConditions(); + // // + // ClearXMASCLongSignalConditions(); + // ClearXMAMCLongSignalConditions(); + // ClearXMAMMLongSignalConditions(); +} + +// +// Clear all Conditions Waiter for Short Signals ... +void ClearShortSignalConditions() { +} +// +// END Signal Conditions ... +// diff --git a/Bkp/Used/14020428/Experts/x-saherelm.ea.mq4 b/Bkp/Used/14020428/Experts/x-saherelm.ea.mq4 new file mode 100644 index 0000000..7c8692f --- /dev/null +++ b/Bkp/Used/14020428/Experts/x-saherelm.ea.mq4 @@ -0,0 +1,790 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XST Strategy Expert Advisor +// --------------------------------------------- +// saherelm implementation of strategy expert advisor ... +// in this EA, we try to combine multiple tools, to ashive best +// results ... +// +// ShortName: XST +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +989121694056 +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XST Strategy Expert Advisor" +#property strict + +// +// START Inputs ... +// +// +// Signal Prefixe ... +input string signalPrefix = "XST"; // Signal Prefix + +// +// Signal Draw Specifications ... +input string bullishSignalLabel = "X_BUY"; // Bullish Signal Label +input color bullishSignalColor = clrAqua; // Bullish Signal Color + +// +input string bearishSignalLabel = "X_SELL"; // Bearish Signal Label +input color bearishSignalColor = clrFuchsia; // Bearish Signal Color + +// +input color signalEntryColor = clrAquamarine; // Signal Entry Ptice Color +input color signalSLColor = clrRed; // Signal SL Color +input color signalTPColor = clrGreen; // Signal TP Color + +// +// Trade ... +input bool allowTrade = true; // Allow Trade Based on given Signals +input bool allowLongTrades = true; // Allow Long Trades +input bool allowShortTrades = false; // Allow Short Trades + +// +// Market Specification Inpouts ... +input int marketLength = 7; // Market Length +input double riskToRewardRatio = 1.5; // Risk to Reward Ratio +// input double maxTPMultiplier = 1000; // Max Allowed TP + +// +// Alerts ... +input bool alertEvents = true; // Alert Events +input bool alertPositions = true; // Alert Positions +input bool longPositionAlerts = true; // Alert Long Positions +input bool shortPositionAlerts = true; // Alert Short Positions + +// +// Alert Types ... +input bool terminalAlert = false; // Terminal Alert +input bool pushAlert = false; // Push Notification Alerts + +// +// Balance and Finanical Specifications ... +input double lotsPerTradePercent = 0.00001; // Lots Per Trade Percent +input int maxOpenTrades = 4; // Maximum Open Trade +input double maxDrawdownPercentPerPTrade = 0.05; // Maximum DrawDown Per Trade +input double minBalancePercent = 0.5; // Minimum Balance for Trading +input double maxEquityPercent = 0.1; // Maximum Trade Equity +input int closeAllOpenTradesAfterCandle = 408; // Close All Open Trades After Passed Candles +input bool closeAllInProfitOpenTradesWhenMaxOpenTradesReached = false; // Close All In Profit Open Trades When Max Open Trades Reached and New Signal Income + +// +// Indicators ... +// +// CCI Inputs ... +input double step = 0.01; // SAR Step +input double maximum = 0.1; // SAR Maximum + +// +// XMA Inputs ... +// +input int shortCycleFastMultiplier = 2; // Short Cycle Fast Multiplier +input int shortCycleSlowMultiplier = 4; // Short Cycle Slow Multiplier +input int mediumCycleFastMultiplier = 6; // Medium Cycle Fast Multiplier +input int mediumCycleSlowMultiplier = 12; // Medium Cycle Slow Multiplier +input int longCycleFastMultiplier = 36; // Long Cycle Fast Multiplier +input int longCycleSlowMultiplier = 72; // Long Cycle Slow Multiplier + +// +// SHPD Indicator ... +input double sharpDetectMultiplier = 800; // Sharp Detect Multiplier +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +int lastSignalledBar = 0; + +// +bool waitForLongSignals = true; +bool closeLongTrades = false; + +// +bool waitForShortSignals = true; +bool closeShortTrades = false; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.signal.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Validate Inputs ... + bool inputsNotValiid = + // + // MARKET ... + marketLength < 0 + || riskToRewardRatio < 0 + // + // EA ... + || lotsPerTradePercent < 0 + || maxOpenTrades <= 0 + || maxDrawdownPercentPerPTrade < 0 + || minBalancePercent < 0 + || maxEquityPercent < 0 + || marketLength < 0 + // + // XMA ... + // + // Validate Short Cycle ... + || shortCycleFastMultiplier <= 0 + || shortCycleSlowMultiplier <= 0 + || shortCycleFastMultiplier >= shortCycleSlowMultiplier + // + // Validate Medium Cycle ... + || mediumCycleFastMultiplier <= 0 + || mediumCycleSlowMultiplier <= 0 + || mediumCycleFastMultiplier >= mediumCycleSlowMultiplier + // + // Validate Long Cycle ... + || longCycleFastMultiplier <= 0 + || longCycleSlowMultiplier <= 0 + || longCycleFastMultiplier >= longCycleSlowMultiplier + // + // Validate Series of Multipliers ... + || shortCycleFastMultiplier >= mediumCycleFastMultiplier + || mediumCycleFastMultiplier >= longCycleFastMultiplier + ; + + // + if (inputsNotValiid) { + return INIT_PARAMETERS_INCORRECT; + } + + // + totalSignals = 0; + totalLongSignals = 0; + totalShortSignals = 0; + + // + initialBalance = 0; + + // + // START Define Array Series ... + // + // + // END Define Array Series ... + // + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST"; + + // // + // // Set Event Timer on One Seccond ... + // bool isEventSet = EventSetTimer(1); + // if (!isEventSet) { + // LogMessage("Error: " + GetLastError()); + // return INIT_FAILED; + // } + + // + ClearSignalConditions(); + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + // Killing Event Timer ... + EventKillTimer(); +} + +// +// Ticker Event Handler ... +void OnTick() { + // + isNewDay = IsNewDay(); + if (isNewDay) { + // + LogMessage( + StringConcatenate( + "New Day: ", TimeCurrent() + ) + ); + } + + // + // Process Signals to Open Positions ... + ProcessSignals(); + + // + // Checking State for Signal Handling ... + CheckState(); + + // + // Process Open Positions for Trailing Stop Loss or Close ... + ProcessOpenPositions(); +} + +// +// Timer Event Handler ... +void OnTimer() { + // + CheckState(); + + // + ProcessOpenPositions(); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Check State for Signal Handling ... +void CheckState() { + // + // Here we Must to Check Market State for enable or disable + // Signal Handlers and also make dection to close all long/short + // trades ... + + // // + // closeLongTrades = xCloseLongTrades; + // waitForLongSignals = xWaitForLongSignals; + + // // + // closeShortTrades = xCloseShortTrades; + // waitForShortSignals = xWaitForShortSignals; + + // // + // xCloseLongTrades = false; + // xCloseShortTrades = false; +} + +// +// Calculate Signals and Process Based on Exists Signals ... +void ProcessSignals() { + // + XSignalRequest request = {}; + request.type = X_SIGNAL_NONE; + request.hasSignal = false; + + // + // Prevent Multiple Calculating on Same Bars ... + isNewBar = IsNewBar(); + if (isNewBar) { + countedBars++; + } + + // + if (countedBars < longCycleSlowMultiplier * marketLength) { + return; + } + + // + bool allowDoTrade = true; + + // + // Check Balance ... + if (initialBalance > 0) { + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double minimumBalanceForTrade = + balance > initialBalance + ? + minBalancePercent * balance + : + minBalancePercent * initialBalance; + + // + // Retrieve Account Equity ... + double equity = AccountInfoDouble(ACCOUNT_EQUITY); + double maxAllowedEquity = balance - (balance * maxEquityPercent); + + // + // Retrieve Free Marigin ... + double freeMargin = AccountFreeMargin(); + double maximumMariginRisk = balance - (balance * maxEquityPercent); + + // + if ( + // + // Do not Open Positions if equity not passed ... + equity < maxAllowedEquity || + // + // Do not Open Positions if free margin not passed ... + freeMargin <= maximumMariginRisk || + // + // Do not open positions if balance less than minimum ... + balance <= minimumBalanceForTrade + ) { + // + allowDoTrade = false; + + // // + // string message = StringConcatenate( + // "Trading Pause => ", + // "Balance: ", balance, + // ", Equity: ", equity, + // ", FreeMargin: ", freeMargin + // ); + + // // + // LogMessage(message); + // SendAlert(message); + } + } + + // + // Retrieve Signal Exists ... + request = GenerateSignal(0); + + // + // Prevent doing anything else, if there is no signals ... + if ( + !allowDoTrade || + !request.hasSignal || + request.type == X_SIGNAL_NONE + ) { + return; + } + + // + bool hasLongSignal = request.type == X_SIGNAL_LONG; + + // + // Check For Bot State ... + if ( + (hasLongSignal && !waitForLongSignals) + || (!hasLongSignal && !waitForShortSignals) + ) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + return; + } + + // + // Check last Signalled Bar with Counted Bars ... + // Prevent Multiple Signalling on Same Bar ... + bool isInLastSignalledBars = false; + for (int i=0; i < marketLength; i++) { + // + isInLastSignalledBars = + isInLastSignalledBars + || lastSignalledBar == countedBars - i + ; + } + if (isInLastSignalledBars) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + return; + } + + // + // increase last signalled bar ... + lastSignalledBar = countedBars; + + // + // Calculate Can Trade or not ... + allowDoTrade = allowTrade + && ( + hasLongSignal ? + allowLongTrades : + allowShortTrades + ); + + // + // Chack Maximum Open Positions ... + int openTrades = CountOpenTrades(); + if (maxOpenTrades > 0) { + // + if (openTrades >= maxOpenTrades) { + // + allowDoTrade = false; + + // + if (closeAllInProfitOpenTradesWhenMaxOpenTradesReached) { + // + // Close All In Profit Trades ... + bool hasClosedInProfitTrade = CloseAllInProfitTrades(); + if (hasClosedInProfitTrade) { + // + openTrades = CountOpenTrades(); + + // + allowDoTrade = !(openTrades >= maxOpenTrades); + } + } + + // + if (!allowDoTrade) { + // + string message = StringConcatenate( + "Trading Pause => ", + "Max Open Trades (", + maxOpenTrades, + ") reached ..." + ); + + // + LogMessage(message); + SendAlert(message); + } + } + } + + // + // Check Trading is Enable or not ... + // nothing to do if trading is disabled ... + if (!allowDoTrade) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // // + // string message = StringConcatenate( + // "Trading Not Allowed ..." + // ); + + // // + // LogMessage(message); + // SendAlert(message); + return; + } + + // + bool isPositionOpened = TradeSignal( + request.signal, + signalPrefix, + lotsPerTradePercent, + // + bullishSignalLabel, + bullishSignalColor, + bearishSignalLabel, + bearishSignalColor + ); + + // + totalSignals++; + if (hasLongSignal) { + // + totalLongSignals++; + ClearLongSignalConditions(); + } else { + // + totalShortSignals++; + ClearShortSignalConditions(); + } + + // + if (isPositionOpened) { + // + bool canAlert = + alertPositions + && ( + hasLongSignal ? + longPositionAlerts + : + shortPositionAlerts + ); + + // + if (canAlert) { + // + // Alert Message ... + string message = StringConcatenate( + "Trade on Signal ID: ", request.signal.id, + ", Entry: ", request.signal.entry, + ", TP: ", request.signal.tp + ); + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } + } + } +} + +// +// Process All Open Positions ... +void ProcessOpenPositions() { + // + // this comes from check state ... + if (closeLongTrades) { + // + closeLongTrades = false; + + // + bool isAllLongTradesClosed = CloseAllLongTrades(); + if (isAllLongTradesClosed) { + } + } + + // + // this comes from check state ... + if (closeShortTrades) { + // + closeShortTrades = false; + + // + bool isAllShortTradesClosed = CloseAllShortTrades(); + if (isAllShortTradesClosed) { + } + } + + // + // Close All XXX Provided Signals on it's Specific Condition ... + if (xCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XXX_PROVIDER); + + // + xCloseLongTrades = false; + } + + // + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + closeAllOpenTradesAfterCandle + ); + + // + // Close Maximum DrawDown Passed Trades ... + bool hasClosedInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + maxDrawdownPercentPerPTrade + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedInDrawDownLongTrade + ) { + // + // waitForLongSignals = false; + } +} + +// +// Send Special Type of Alerts ... +void SendAlert(string message) { + // + if (!alertEvents) { + return; + } + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } +} +// +// END Functions ... +// + +// +// +// Calculate Signal ... +// in this function we calculate a signal exists in +// specific bar or not ... +XSignalRequest GenerateSignal( + const int bar_index // Bar Index ... +) { + // + // create temp result ... + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + bool hasSignal = false; + bool hasLongSignal = false; + bool hasShortSignal = false; + + // + XSignal signal = {}; + + // + // Retrieve XMA States ... + // based on medium cycle slow ... + XState states[]; + ArrayFree(states); + ArrayResize( + states, + marketLength + ); + + // + int index = 0; + for (int i = bar_index; i < bar_index + marketLength; i++) { + // + states[index] = GetXState( + i, + marketLength, + // + step, + maximum, + // + shortCycleFastMultiplier, + shortCycleSlowMultiplier, + mediumCycleFastMultiplier, + mediumCycleSlowMultiplier, + longCycleFastMultiplier, + longCycleSlowMultiplier + ); + + // + index++; + } + + // + CheckXLongSignalConditions( + bar_index, + marketLength, + states + ); + + // + CheckXShortSignalConditions( + bar_index, + marketLength, + states + ); + + // + XSignalRequest xLongSignalRequest = GenerateXSignal( + X_SIGNAL_LONG, + bar_index, + marketLength, + riskToRewardRatio, + states + ); + + // + XSignalRequest xShortSignalRequest = GenerateXSignal( + X_SIGNAL_SHORT, + bar_index, + marketLength, + riskToRewardRatio, + states + ); + + // + if (xLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXSignals( + xLongSignalRequest.signal, + states, + marketLength + ); + + // + if (isReady && xWaitForLongSignals) { + // + hasLongSignal = true; + signal = xLongSignalRequest.signal; + } else { + ClearXLongSignalConditions(); + } + } else if (xShortSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXSignals( + xShortSignalRequest.signal, + states, + marketLength + ); + + // + if (isReady) { + // + hasShortSignal = true; + signal = xShortSignalRequest.signal; + } else { + ClearXShortSignalConditions(); + } + } + + // + hasSignal = hasLongSignal || hasShortSignal; + + // + if (!hasSignal) { + // + signal.type = X_SIGNAL_NONE; + result.type = X_SIGNAL_NONE; + } + + // + // Normalize TP, SL and Entry Price ... + signal.tp = NormalizeDouble(signal.tp, _Digits); + signal.sl = NormalizeDouble(signal.sl, _Digits); + signal.entry = NormalizeDouble(signal.entry, _Digits); + + // + result.signal = signal; + result.type = signal.type; + result.hasSignal = hasSignal; + result.provider = signal.provider; + + // + // Return Result ... + return result; +} diff --git a/Bkp/Used/14020428/Indicators/ROCv2.2.mq4 b/Bkp/Used/14020428/Indicators/ROCv2.2.mq4 new file mode 100644 index 0000000..5308449 --- /dev/null +++ b/Bkp/Used/14020428/Indicators/ROCv2.2.mq4 @@ -0,0 +1,335 @@ +//+------------------------------------------------------------------+ +//| ROCv2.1.mq4 | +//| Copyright 2015, mrak297. | +//| https://www.mql5.com/ru/users/mrak297 | +//+------------------------------------------------------------------+ +#property copyright "Copyright 2015, mrak297." +#property link "https://www.mql5.com/ru/users/mrak297" +#property version "2.1" +#property strict +#property indicator_separate_window +//--- input parameters +input string Pairs="USDJPY,AUDUSD,EURJPY,EURCHF,EURGBP,EURUSD,GBPUSD,USDCHF,USDCAD"; +input ENUM_TIMEFRAMES TimeFrame=PERIOD_D1;//Period for calculating +input ENUM_TIMEFRAMES Per = PERIOD_M15; //Period for new opened charts +input color UPcolor = clrLimeGreen; //Color when moved up +input color DownColor = clrTomato; //Color when moved down +input int PSize = 6; // Pair string size including pre- & suffix +input bool InverseUSD = false; // Invert USDXXX pairs to XXXUSD +//--- +int Size=10; //Font size +string Font= "Arial Black"; +int BGcolor; //Bars background color +int cF = 100; //Coefficient of scale +int num,Zero,Wbar,Hbar,Xsize,Ysize; +string PairsArray[]; //Array for Pairs Name +double ChangeArray[]; //Array for Pairs Change +//+------------------------------------------------------------------+ +//| | +//+------------------------------------------------------------------+ +int OnInit() + { + EventSetMillisecondTimer(250); +//--- + IndicatorShortName("Rate Of Change ("+PeriodToString(TimeFrame)+")"); + IndicatorSetDouble(INDICATOR_MAXIMUM,1); + IndicatorSetDouble(INDICATOR_MINIMUM,-1); +//--- + BGcolor=(int)ChartGetInteger(0,CHART_COLOR_BACKGROUND); +//--- + ushort sep=StringGetCharacter(Pairs,PSize); + num=StringSplit(Pairs,sep,PairsArray); +//--- + ArrayResize(ChangeArray,num,num); +//--- + Xsize = (int)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,1); + Ysize = (int)ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,1); +//--- + Zero=(int)MathRound(ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,1)/2); +//--- + Wbar=(int)MathRound((Xsize-15)/num); +//--- + if(MathRound(Wbar/5)MathAbs(ChangeArray[min])) tmp=ChangeArray[max]; + else tmp=MathAbs(ChangeArray[min]); +//--- + if(tmp*cF>Ysize/2) cF--; + if((Ysize/2-tmp*cF)>20) cF++; + } +//+------------------------------------------------------------------+ +//| | +//+------------------------------------------------------------------+ +void OnChartEvent(const int id, + const long &lparam, + const double &dparam, + const string &sparam) + { + if(id==CHARTEVENT_OBJECT_CLICK) + { + string name=StringSubstr(sparam,0,6); + ChartOpen(name,Per); + } + if(id==CHARTEVENT_CHART_CHANGE) OnInit(); + } +//+------------------------------------------------------------------+ +//| | +//+------------------------------------------------------------------+ +double SymbolChange(string symbol,ENUM_TIMEFRAMES period) + { + SymbolSelect(symbol,true); + double perf = 0; + double open = iOpen(symbol, period, 0); + double close = iClose(symbol, period, 0); +//--- + if(open!=0) + { + perf=(close-open); + perf /= open; + perf *= 100; + } + else Print("Change NaN"); +//--- + return(NormalizeDouble(perf, 2)); + } +//+------------------------------------------------------------------+ +//| | +//+------------------------------------------------------------------+ +double SymbolChange2(string symbol,ENUM_TIMEFRAMES period) + { + SymbolSelect(symbol,true); + double perf = 0; + double open = iOpen(symbol, period, 0); + double close = iClose(symbol, period, 0); +//--- + if(open!=0) + { + perf=(open-close); + perf /= open; + perf *= 100; + } + else Print("Change NaN"); +//--- + return(NormalizeDouble(perf, 2)); + } +//+------------------------------------------------------------------+ +//| | +//+------------------------------------------------------------------+ +void CreateTextLabel(string name,int x,int y,string text,ENUM_ANCHOR_POINT anchor) + { + ObjectDelete(0,name); + ResetLastError(); +//--- + if(ObjectCreate(0,name,OBJ_LABEL,1,0,0)) + { + ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x); + ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y); + ObjectSetInteger(0,name,OBJPROP_CORNER,CORNER_LEFT_UPPER); + ObjectSetString(0,name,OBJPROP_TEXT,text); + ObjectSetString(0,name,OBJPROP_FONT,Font); + ObjectSetInteger(0,name,OBJPROP_FONTSIZE,Size); + ObjectSetDouble(0,name,OBJPROP_ANGLE,0.0); + ObjectSetInteger(0,name,OBJPROP_ANCHOR,anchor); + ObjectSetInteger(0,name,OBJPROP_COLOR,clrBlue); + ObjectSetInteger(0,name,OBJPROP_BACK,false); + ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false); + ObjectSetInteger(0,name,OBJPROP_HIDDEN,true); + ObjectSetInteger(0,name,OBJPROP_ZORDER,1); + ObjectSetString(0,name,OBJPROP_TOOLTIP,"\n"); + } + else Print("ERROR Creating object.",GetLastError()); + } +//+------------------------------------------------------------------+ +//| | +//+------------------------------------------------------------------+ +void CreateRecLabel(string name,int x,int y,int xsize,int ysize) + { + ObjectDelete(0,name); + ResetLastError(); +//--- + if(ObjectCreate(0,name,OBJ_RECTANGLE_LABEL,1,0,0)) + { + ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x); + ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y); + ObjectSetInteger(0,name,OBJPROP_XSIZE,xsize); + ObjectSetInteger(0,name,OBJPROP_YSIZE,ysize); + ObjectSetInteger(0,name,OBJPROP_BGCOLOR,BGcolor); + ObjectSetInteger(0,name,OBJPROP_BORDER_TYPE,BORDER_FLAT); + ObjectSetInteger(0,name,OBJPROP_CORNER,CORNER_LEFT_UPPER); + ObjectSetInteger(0,name,OBJPROP_COLOR,clrDodgerBlue); + ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_SOLID); + ObjectSetInteger(0,name,OBJPROP_WIDTH,1); + ObjectSetInteger(0,name,OBJPROP_BACK,false); + ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false); + ObjectSetInteger(0,name,OBJPROP_HIDDEN,true); + ObjectSetInteger(0,name,OBJPROP_ZORDER,0); + ObjectSetString(0,name,OBJPROP_TOOLTIP,"\n"); + } + else Print("ERROR Creating object.",GetLastError()); + } +//+------------------------------------------------------------------+ +//| | +//+------------------------------------------------------------------+ +int PixToPoints(int pix) + { + int pt=0; + int ems[28][2]= + { + 6,8,7,9,7,10,8,11,9,12,10,13,10,14,11,15,12,16,13,17,13,18,14,19,14,20,15,21,16,22, + 17,23,18,24,20,26,22,29,24,32,26,35,27,36,28,37,29,38,30,40,32,42,34,45,36,48 + }; +//--- + if(pix<8) + return(6); + if(pix>48) + return(36); +//--- + for(int i=0; i<28; i++) + { + if(pix==ems[i][1]) + { + pt=ems[i][0]; + break; + } + } + return(pt); + } +//+------------------------------------------------------------------+ +//| | +//+------------------------------------------------------------------+ +string PeriodToString(ENUM_TIMEFRAMES tframe) + { + string result=" "; + string PeriodArray[9][2]= + { + "M1","1", + "M5","5", + "M15","15", + "M30","30", + "H1","60", + "H4","240", + "D1","1440", + "W1","10080", + "MN1","43200" + }; + for(int i=0; i<9; i++) + { + if((string)tframe==PeriodArray[i][1]) + { + result=PeriodArray[i][0]; + break; + } + } + return(result); + } +//+--------------------------------------------------------------------+ diff --git a/Bkp/Used/14020428/Indicators/roc2.mq4 b/Bkp/Used/14020428/Indicators/roc2.mq4 new file mode 100644 index 0000000..2f025b0 --- /dev/null +++ b/Bkp/Used/14020428/Indicators/roc2.mq4 @@ -0,0 +1,62 @@ +#property copyright "www.forex-station.com" +#property link "www.forex-station.com" +//---- indicator settings +#property indicator_separate_window +#property indicator_buffers 1 +#property indicator_color1 Red +//---- indicator parameters +extern int RPeriod = 10; +extern bool UsePercent = false; +//---- indicator buffers +double RateOfChange[]; +//+------------------------------------------------------------------+ +//| Custom indicator initialization function | +//+------------------------------------------------------------------+ +int init() + { +//---- drawing settings + SetIndexStyle(0, DRAW_LINE); + SetIndexDrawBegin(0, RPeriod); + IndicatorDigits(Digits + 1); +//---- indicator buffers mapping + if(!SetIndexBuffer(0, RateOfChange)) + Print("cannot set indicator buffers!"); +//---- name for DataWindow and indicator subwindow label + IndicatorShortName("ROC(" + RPeriod + ")"); +//---- initialization done + return(0); + } +//+------------------------------------------------------------------+ +//| Moving Averages Convergence/Divergence | +//+------------------------------------------------------------------+ +int start() + { + int limit; + double ROC, CurrentClose, PrevClose; + int counted_bars = IndicatorCounted(); +//---- check for possible errors + if(counted_bars < 0) + return(-1); +//---- last counted bar will be recounted + if(counted_bars > 0) + counted_bars--; + limit = MathMin(Bars - counted_bars,Bars-1); +//---- ROC calculation + for(int i = 0; i < limit; i++) + { + CurrentClose = iClose(NULL, 0, i); + PrevClose = iClose(NULL, 0, i + RPeriod); + ROC = CurrentClose - PrevClose; + //---- + if(UsePercent) + { + if(PrevClose != 0) + RateOfChange[i] = 100 * ROC / PrevClose; + } + else + RateOfChange[i] = ROC; + } +//---- done + return(0); + } +//+------------------------------------------------------------------+ \ No newline at end of file diff --git a/Bkp/Used/14020428/Indicators/roc_smoothed.mq4 b/Bkp/Used/14020428/Indicators/roc_smoothed.mq4 new file mode 100644 index 0000000..da2e3bf --- /dev/null +++ b/Bkp/Used/14020428/Indicators/roc_smoothed.mq4 @@ -0,0 +1,190 @@ +#property copyright "www.forex-station.com" +#property link "www.forex-station.com" +//---- indicator settings +#property indicator_separate_window +#property indicator_buffers 1 +#property indicator_color1 Red +//---- indicator parameters +extern string strROC = "ROC Period for lookback"; +extern int RPeriod = 10; +extern string sep0 = "----------------------------------"; +extern string strMA = "MA input parameters"; +extern int MAPeriod=14; +extern string sep1 = "----------------------------------"; +extern string strType = "Moving Average Types" ; +extern string str0 = "0 = SMA, 1 = EMA, 2 = SMMA"; +extern string str1 = "3 = LWMA, 4 = LSMA, 5 = NLMA"; +extern int MAType = 1; +extern string sep2 = "----------------------------------"; +extern string strAP = "Applied Price Types"; +extern string str2 = "0=close, 1=open, 2=high"; +extern string str3 = "3=low, 4=median(high+low)/2"; +extern string str4 = " 5=typical(high+low+close)/3"; +extern string str5 = "6=weighted(high+low+close+close)/4"; +extern int MAAppliedPrice = 0; +extern string sep3 = "----------------------------------"; +extern string str6 = "NonLagMA Deviation"; +extern double Deviation = 0; +extern bool UsePercent = false; + +//---- indicator buffers +double RateOfChange[]; + +//---- variables + +int MAMode; +string strMAType; + +// Variables for NonLag +int Phase; +double Len; +double Cycle = 4; +double pi = 3.1415926535; +//+------------------------------------------------------------------+ +//| Custom indicator initialization function | +//+------------------------------------------------------------------+ +int init() + { +//---- drawing settings + SetIndexStyle(0,DRAW_LINE); + SetIndexDrawBegin(0,RPeriod); + IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1); +//---- indicator buffers mapping + if(!SetIndexBuffer(0,RateOfChange)) + Print("cannot set indicator buffers!"); +switch (MAType) + { + case 1: strMAType="EMA"; MAMode=MODE_EMA; break; + case 2: strMAType="SMMA"; MAMode=MODE_SMMA; break; + case 3: strMAType="LWMA"; MAMode=MODE_LWMA; break; + case 4: strMAType="LSMA"; break; + case 5: strMAType="NLMA";break; + default: strMAType="SMA"; MAMode=MODE_SMA; break; + } + IndicatorShortName( "ROC (" + RPeriod + ")_Smoothed_" + strMAType+ " (" +MAPeriod + ") "); +//---- name for DataWindow and indicator subwindow label + SetIndexLabel(0,"ROC_Smoothed"); + +// Variables for NonLag + Phase = MAPeriod-1; + Len = MAPeriod*Cycle + Phase; + +//---- initialization done + return(0); + } + +//+------------------------------------------------------------------+ +//| LSMA with PriceMode | +//| PrMode 0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2, | +//| 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4 | +//+------------------------------------------------------------------+ + +double LSMA(int Rperiod, int prMode, int shift) +{ + int i; + double sum, pr; + int length; + double lengthvar; + double tmp; + double wt; + + length = Rperiod; + + sum = 0; + for(i = length; i >= 1 ; i--) + { + lengthvar = length + 1; + lengthvar /= 3; + tmp = 0; + switch (prMode) + { + case 0: pr = Close[length-i+shift];break; + case 1: pr = Open[length-i+shift];break; + case 2: pr = High[length-i+shift];break; + case 3: pr = Low[length-i+shift];break; + case 4: pr = (High[length-i+shift] + Low[length-i+shift])/2;break; + case 5: pr = (High[length-i+shift] + Low[length-i+shift] + Close[length-i+shift])/3;break; + case 6: pr = (High[length-i+shift] + Low[length-i+shift] + Close[length-i+shift] + Close[length-i+shift])/4;break; + } + tmp = ( i - lengthvar)*pr; + sum+=tmp; + } + + wt = MathFloor(sum*6/(length*(length+1))/Point)*Point; + + return(wt); +} + +double NonLag(int RPeriod, int myLen, double myPhase, int myShift) +{ + + int i; + double alfa, beta, t, Sum, Weight,g; + double myPrice; + double Coeff = 3*pi; + + Weight=0; Sum=0; t=0; + + for (i=0;i<=myLen-1;i++) + { + g = 1.0/(Coeff*t+1); + if (t <= 0.5 ) g = 1; + beta = MathCos(pi*t); + alfa = g * beta; + myPrice = iMA(NULL,0,1,0,MODE_SMA,MAAppliedPrice,myShift+i); + Sum += alfa*myPrice; + Weight += alfa; + if ( t < 1 ) t += 1.0/(myPhase-1); + else if ( t < myLen-1 ) t += (2*Cycle-1)/(Cycle*RPeriod-1); + } + if (Weight > 0) Weight = (1.0+Deviation/100)*Sum/Weight; + Weight = MathFloor(Weight/Point)*Point; + return (Weight); + +} + +//+------------------------------------------------------------------+ +//| Rate of Change Smoothed | +//+------------------------------------------------------------------+ +int start() + { + int limit; + double ROC, MA_Cur, MA_Prev; + int counted_bars=IndicatorCounted(); +//---- check for possible errors + if(counted_bars<0) return(-1); +//---- last counted bar will be recounted + if(counted_bars>0) counted_bars--; + limit=Bars-counted_bars; +//---- ROC calculation + for(int i=0; i= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Long TP ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index +) { + // + // Calculate Buffers ... + + // + // Retrieves the current ADX value ... + double adx = iADX( + _Symbol, + _Period, + length, + appliedPrice, + MODE_MAIN, + bar_index + ); + adxBuffer[bar_index] = adx; + + // + // Retrieves the current DI+ value ... + double plusDi = iADX( + _Symbol, + _Period, + length, + appliedPrice, + MODE_PLUSDI, + bar_index + ); + positiveBuffer[bar_index] = plusDi; + + // + // Retrieves the current DI- value ... + double minusDi = iADX( + _Symbol, + _Period, + length, + appliedPrice, + MODE_MINUSDI, + bar_index + ); + negativeBuffer[bar_index] = minusDi; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020428/Indicators/x-saherelm.ma.mq4 b/Bkp/Used/14020428/Indicators/x-saherelm.ma.mq4 new file mode 100644 index 0000000..e3a5737 --- /dev/null +++ b/Bkp/Used/14020428/Indicators/x-saherelm.ma.mq4 @@ -0,0 +1,173 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MA Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 MA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Fast MA ... +input int maLength = 20; // MA Length +input int maShift = 0; // MA Shift +input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method +input ENUM_APPLIED_PRICE maAppliedPrice = PRICE_CLOSE; // MA Applied Price + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 1 + +// +#property indicator_plots 1 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Fast Ma Buffer ... +#property indicator_label1 "Ma" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrYellow +#property indicator_style1 STYLE_DOT +#property indicator_width1 2 + +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define maBufferIndex 0 + +double maBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (maLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + // + // Ma ... + SetIndexBuffer(maBufferIndex, maBuffer); + SetIndexDrawBegin(maBufferIndex, maLength + 1); + // + // End Set Index Buffers ... + // + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, maLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Ma ... + CalculateMa(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateMa( + const int &bar_index +) { + // + // Calculating Fast Ma ... + double ma = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + maAppliedPrice, + bar_index + ); + + // + maBuffer[bar_index] = ma; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020428/Indicators/x-saherelm.momentum.mq4 b/Bkp/Used/14020428/Indicators/x-saherelm.momentum.mq4 new file mode 100644 index 0000000..ea6e419 --- /dev/null +++ b/Bkp/Used/14020428/Indicators/x-saherelm.momentum.mq4 @@ -0,0 +1,160 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center Momentum Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm Momentum Oscillator" +#property strict + +// +// START Inputs ... +// +input int length = 7; // Market Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_separate_window + +// +#property indicator_buffers 1 + +// +#property indicator_level1 0.0 +#property indicator_level2 100.0 +#property indicator_levelcolor clrSilver +#property indicator_levelstyle STYLE_DOT + +// +// MOMENTUM ... +#property indicator_width1 1 +#property indicator_color1 clrLightBlue +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_SOLID + +// +// Declare Buffers ... +#define momentumBufferIndex 0 + +double momentumBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (length < 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + IndicatorBuffers(1); + + // + SetIndexBuffer(momentumBufferIndex, momentumBuffer); + SetIndexLabel(momentumBufferIndex, "Momentum"); + SetIndexDrawBegin(momentumBufferIndex, length); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, length); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Long TP ... + CalculateBuffers( + i, + close + ); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index, + const double &close[] +) { + // + // Calculate Buffers ... + double momentum = close[bar_index] * 100 / close[bar_index + length]; + + // + momentumBuffer[bar_index] = momentum; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020428/Indicators/x-saherelm.osc.mq4 b/Bkp/Used/14020428/Indicators/x-saherelm.osc.mq4 new file mode 100644 index 0000000..829f32c --- /dev/null +++ b/Bkp/Used/14020428/Indicators/x-saherelm.osc.mq4 @@ -0,0 +1,257 @@ +///////////////////////////////////////////////////////////////// +// +// SaherElm IT Center OSC Indicator +// ------------------------------------------------------------- +// this indicator provides OSC ... +// +// 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 OSC Indicator" +#property strict + +// +// START Inputs ... +// +// +// FastOSC ... +// Short Cycle (Fast OSC) ... +input int fastOSCLength = 10; // FastOSC Length +input double fastOSCMultiplier = 1.0; // FastOSC Multiplier + +// +// SlowOSC ... +// Medium Cycle (Slow OSC) ... +input int slowOSCLength = 30; // SlowOSC Length +input double slowOSCMultiplier = 3.0; // SlowOSC Multiplier +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +#property indicator_separate_window + +// +// we have 2 buffer in this indicator ... +#property indicator_buffers 2 + +// +// also we have 2 line for draw on this indicator ... +#property indicator_plots 2 + +// +// Fast OSC ... +#property indicator_width1 1 +#property indicator_color1 clrAqua +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_SOLID + +// +// Slow OSC ... +#property indicator_width2 1 +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrFuchsia +#property indicator_style2 STYLE_SOLID + +// +// set color of horizontal levels ... +#property indicator_levelcolor clrGray + +// +// set style of horizontal levels ... +#property indicator_levelstyle STYLE_DOT + +// +// Declare Buffers ... +#define fastOSCBufferIndex 0 +#define slowOSCBufferIndex 1 + +// +double fastOSCBuffer[]; +double slowOSCBuffer[]; + +// +// Used Indicators List ... +string rmaIndicatorName = "x-saherelm.rma"; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + fastOSCLength < 0 || + slowOSCLength < 0 || + slowOSCLength <= fastOSCLength + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XS_OSC"; + + // + // set descriptions of horizontal levels ... + SetLevelValue(0, 0.0); + IndicatorSetString(INDICATOR_LEVELTEXT,0,""); + + // + // set descriptions of horizontal levels ... + SetLevelValue(1, 0.5); + IndicatorSetString(INDICATOR_LEVELTEXT,1,""); + + // + // set descriptions of horizontal levels ... + SetLevelValue(2, 1); + IndicatorSetString(INDICATOR_LEVELTEXT,2,""); + + // + // Fast OSC Buffer ... + SetIndexBuffer(fastOSCBufferIndex, fastOSCBuffer); + SetIndexLabel(fastOSCBufferIndex, "Fast OSC"); + SetIndexDrawBegin(fastOSCBufferIndex, fastOSCLength - 1); + + // + // Slow OSC Buffer ... + SetIndexBuffer(slowOSCBufferIndex, slowOSCBuffer); + SetIndexLabel(slowOSCBufferIndex, "Slow OSC"); + SetIndexDrawBegin(slowOSCBufferIndex, slowOSCLength - 1); + + // + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(fastOSCLength, slowOSCLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + CalculateOscillators(close, i); + } + + // + return rates_total; +} + +// +// De Initialization ... +void OnDeinit(const int reason) { +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +void CalculateOscillators( + const double &close[], + const int &bar_index +) { + // + // FastOSC ... + // Short Cycle Calculations ... + int scl = fastOSCLength / 2; + int scl2 = scl / 2; + double maScl = iCustom(_Symbol, _Period, rmaIndicatorName, scl, 0, bar_index); + double scmAtr = iATR(_Symbol, _Period, scl, bar_index); + double scmOff = fastOSCMultiplier * scmAtr; + double maScl2 = iCustom(_Symbol, _Period, rmaIndicatorName, scl2, 0, bar_index); + double sctParam = maScl2 != 0 ? maScl2 : close[bar_index + 1]; + double sct = sctParam + scmOff; + double scb = sctParam - scmOff; + + // + // SlowOSC ... + // Medium Cycle Calculations ... + int mcl = slowOSCLength / 2; + int mcl2 = mcl / 2; + double maMcl = iCustom(_Symbol, _Period, rmaIndicatorName, mcl, 0, bar_index); + double mcmAtr = iATR(_Symbol, _Period, mcl, bar_index); + double mcmOff = slowOSCMultiplier * mcmAtr; + double maMcl2 = iCustom(_Symbol, _Period, rmaIndicatorName, mcl2, 0, bar_index); + double mctParam = maMcl2 != 0 ? maMcl2 : close[bar_index + 1]; + double mct = mctParam + mcmOff; + double mcb = mctParam - mcmOff; + + // + double scMM = (sct + scb) / 2; + + // + double fastOCS = (close[bar_index] - mcb) / (mct - mcb); + fastOSCBuffer[bar_index] = fastOCS; + + // + double slowOCS = (scMM - mcb) / (mct - mcb); + slowOSCBuffer[bar_index] = slowOCS; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020428/Indicators/x-saherelm.rma.mq4 b/Bkp/Used/14020428/Indicators/x-saherelm.rma.mq4 new file mode 100644 index 0000000..0fc70fd --- /dev/null +++ b/Bkp/Used/14020428/Indicators/x-saherelm.rma.mq4 @@ -0,0 +1,141 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center RMA Indicator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm RMA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Set the RMA Length ... +input int RMALength = 10; // Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// we have 2 buffer in this indicator ... +#property indicator_buffers 1 + +// +// also we have 1 line for draw on this indicator ... +#property indicator_plots 1 + +// +// here we declare plot SlowOCS to system ... +#property indicator_label1 "RMA" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrFuchsia +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +// +// Declare Buffers ... +#define RMABufferIndex 0 + +// +double RMABuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + SetIndexBuffer(RMABufferIndex, RMABuffer); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + int maxLength = MathMax(0, RMALength); + + // + // wait to pass bars until we have rights ... + if (rates_total <= maxLength) { + // + // return not calculated ... + return 0; + } + + // + // find loop count for bars manipulation ... + int count = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // Print("Count: ", count, ", Bars: ", Bars); + + // + // this is the main loop of calculations, for each bar index ... + for (int i = count - 1; i >= 0; i--) { + // + // Start Calculation with Formula 1 ... + // + double shortSMA = iMA(_Symbol, _Period, RMALength, 0, MODE_SMA, PRICE_CLOSE, i); + double mediumSMA = iMA(_Symbol, _Period, RMALength * 2, 0, MODE_SMA, PRICE_CLOSE, i); + double longSMA = iMA(_Symbol, _Period, RMALength * 3, 0, MODE_SMA, PRICE_CLOSE, i); + + // + double rma1 = longSMA - mediumSMA + shortSMA; + rma1 = NormalizeDouble(rma1, _Digits); + // + // End Calculation with Formula 1 ... + // + + // + RMABuffer[i] = rma1; + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020428/Indicators/x-saherelm.rsi.mq4 b/Bkp/Used/14020428/Indicators/x-saherelm.rsi.mq4 new file mode 100644 index 0000000..448f732 --- /dev/null +++ b/Bkp/Used/14020428/Indicators/x-saherelm.rsi.mq4 @@ -0,0 +1,234 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center RSI Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm RSI Oscillator" +#property strict + +// +// START Inputs ... +// +input int rsiPeriod=14; // RSI Period +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_separate_window + +// +#property indicator_minimum 0 +#property indicator_maximum 100 + +// +#property indicator_buffers 1 +#property indicator_color1 DodgerBlue + +// +#property indicator_level1 30.0 +#property indicator_level2 50.0 +#property indicator_level3 70.0 +#property indicator_levelcolor clrSilver +#property indicator_levelstyle STYLE_DOT + +// +// Declare Buffers ... +#define rsiBufferIndex 0 +#define positiveBufferIndex 1 +#define negativeBufferIndex 2 + +double rsiBuffer[]; +double positiveBuffer[]; +double negativeBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + string short_name; + + // + IndicatorBuffers(3); + + // + SetIndexBuffer(positiveBufferIndex, positiveBuffer); + SetIndexBuffer(negativeBufferIndex, negativeBuffer); + + // + SetIndexStyle(rsiBufferIndex, DRAW_LINE); + SetIndexBuffer(rsiBufferIndex, rsiBuffer); + + // + // name for DataWindow and indicator subwindow label + short_name="RSI("+string(rsiPeriod)+")"; + IndicatorShortName(short_name); + SetIndexLabel(rsiBufferIndex, short_name); + + // + // check for input + if (rsiPeriod < 2) { + // + Print("Incorrect value for input variable InpRSIPeriod = ", rsiPeriod); + + // + // Failed Initialization ... + return INIT_PARAMETERS_INCORRECT; + } + + // + // set where to start draw ... + SetIndexDrawBegin(0, rsiPeriod); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + int i,pos; + double diff; + + // + // Prevent from run calculations if there is no fulfilled conditions ... + if (Bars <= rsiPeriod || rsiPeriod < 2) { + // + // return nothing calculated result ... + return 0; + } + + // + // counting from 0 to rates_total, this is most important ... + ArraySetAsSeries(rsiBuffer, false); + ArraySetAsSeries(positiveBuffer, false); + ArraySetAsSeries(negativeBuffer, false); + + // + ArraySetAsSeries(close, false); + + // + // preliminary calculations ... + pos = prev_calculated - 1; + if (pos <= rsiPeriod) { + // + // first RSIPeriod values of the indicator are not calculated + rsiBuffer[0] = 0.0; + positiveBuffer[0] = 0.0; + negativeBuffer[0] = 0.0; + + // + double sump=0.0; + double sumn=0.0; + for (i = 1; i <= rsiPeriod; i++) { + // + rsiBuffer[i]=0.0; + positiveBuffer[i]=0.0; + negativeBuffer[i]=0.0; + + // + diff = close[i] - close[i - 1]; + if(diff > 0) { + sump += diff; + } else { + sumn -= diff; + } + } + + // + // calculate first visible value ... + positiveBuffer[rsiPeriod] = sump / rsiPeriod; + negativeBuffer[rsiPeriod] = sumn / rsiPeriod; + if (negativeBuffer[rsiPeriod] != 0.0) { + // + rsiBuffer[rsiPeriod] = 100.0 - ( + 100.0 / ( + 1.0 + positiveBuffer[rsiPeriod] / negativeBuffer[rsiPeriod] + ) + ); + } else { + // + if (positiveBuffer[rsiPeriod] != 0.0) { + rsiBuffer[rsiPeriod] = 100.0; + } else { + rsiBuffer[rsiPeriod] = 50.0; + } + } + + // + // prepare the position value for main calculation ... + pos = rsiPeriod + 1; + } + + // + // the main loop of calculations ... + for (i = pos; i < rates_total && !IsStopped(); i++) { + // + diff = close[i] - close[i-1]; + + // + positiveBuffer[i] = (positiveBuffer[i-1] * (rsiPeriod - 1) + (diff > 0.0 ? diff : 0.0)) / rsiPeriod; + negativeBuffer[i] = (negativeBuffer[i-1] * (rsiPeriod - 1) + (diff < 0.0 ? -diff : 0.0)) / rsiPeriod; + + // + if (negativeBuffer[i] != 0.0) { + rsiBuffer[i] = 100.0 - 100.0 / (1 + positiveBuffer[i] / negativeBuffer[i]); + } else { + // + if (positiveBuffer[i] != 0.0) { + rsiBuffer[i] = 100.0; + } else { + rsiBuffer[i] = 50.0; + } + } + } + + // + return(rates_total); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020428/Indicators/x-saherelm.shpd.mq4 b/Bkp/Used/14020428/Indicators/x-saherelm.shpd.mq4 new file mode 100644 index 0000000..7c02a84 --- /dev/null +++ b/Bkp/Used/14020428/Indicators/x-saherelm.shpd.mq4 @@ -0,0 +1,402 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XSHPD Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 XSHPD Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 7; // Market Length ... +input double sharpDetectMultiplier = 70; // Sharp Detect Multiplier + +// +input bool drawLabels = true; // Draw Labels on Founded Sharps + +// +input string sharpBullishLabel = "SH_BULL"; // Sharp Bullish Label +input color sharpBullishColor = clrAqua; // Sharp Bullish color + +// +input string sharpBearishLabel = "SH_BEAR"; // Sharp Bearish Label +input color sharpBearishColor = clrFuchsia; // Sharp Bearish color +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +#property indicator_buffers 4 +#property indicator_plots 4 + +// +// Declare Buffers ... +#define marketHighestHighBufferIndex 0 +#define marketLowestLowBufferIndex 1 +#define sharpBullishBufferIndex 2 +#define sharpBearishBufferIndex 3 + +// +double marketHighestHighBuffer[]; +double marketLowestLowBuffer[]; +double sharpBullishBuffer[]; +double sharpBearishBuffer[]; + +// +#include "../Libraries/x-saherelm.lib.mq4" +#include "../Libraries/x-saherelm.draw.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if ( + marketLength <= 0 + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + enableLogging = true; + + // + logTag = "X_SHPD"; + + // + // Highest High ... + SetIndexLabel(marketHighestHighBufferIndex, ""); + SetIndexBuffer(marketHighestHighBufferIndex, marketHighestHighBuffer); + SetIndexStyle( + marketHighestHighBufferIndex, + DRAW_LINE, // DRAW_NONE, + STYLE_DOT, + 1, // 0, + clrAqua // clrNONE + ); + + // + // Lowest Low ... + SetIndexLabel(marketLowestLowBufferIndex, ""); + SetIndexBuffer(marketLowestLowBufferIndex, marketLowestLowBuffer); + SetIndexStyle( + marketLowestLowBufferIndex, + DRAW_NONE, + STYLE_DOT, + 0, + clrNONE + ); + + // + // Sharp Bullish Buffer ... + SetIndexLabel(sharpBullishBufferIndex, ""); + SetIndexBuffer(sharpBullishBufferIndex, sharpBullishBuffer); + SetIndexStyle( + sharpBullishBufferIndex, + DRAW_NONE, + STYLE_DOT, + 0, + clrNONE + ); + + // + // Sharp Bearish Buffer ... + SetIndexLabel(sharpBearishBufferIndex, ""); + SetIndexBuffer(sharpBearishBufferIndex, sharpBearishBuffer); + SetIndexStyle( + sharpBearishBufferIndex, + DRAW_NONE, + STYLE_DOT, + 0, + clrNONE + ); + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + RemoveDraws(logTag); +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Sharp ... + CalculateSharp(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Sharp ... +void CalculateSharp( + const int &bar_index +) { + // + int index = 0; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + 1 + ); + + // + marketHighestHighBuffer[bar_index] = GetMarketHighestHigh( + bar_index, + marketLength + ); + + // + marketLowestLowBuffer[bar_index] = GetMarketLowestLow( + bar_index, + marketLength + ); + + // + double maHHs[]; + ArrayResize( + maHHs, + marketLength + ); + + // + double maLLs[]; + ArrayResize( + maLLs, + marketLength + ); + + // + index = 0; + for (int i = bar_index; i < bar_index + marketLength; i++) { + // + maLLs[index] = marketLowestLowBuffer[i]; + maHHs[index] = marketHighestHighBuffer[i]; + + // + index++; + } + + // + int maxHighIdx = ArrayMaximum(maHHs); + double maxHigh = maHHs[maxHighIdx]; + + // + int minHighIdx = ArrayMinimum(maHHs); + double minHigh = maHHs[minHighIdx]; + + // + double highDiffRate = (maxHigh - minHigh) / 100; + + // + int maxLowIdx = ArrayMaximum(maLLs); + double maxLow = maLLs[maxLowIdx]; + + // + int minLowIdx = ArrayMinimum(maLLs); + double minLow = maLLs[minLowIdx]; + + // + double lowDiffRate = (maxLow - minLow) / 100; + + // + bool isSharpBullishDetected = + high == maxHigh + && low > minLow + && marketHighestHighBuffer[bar_index] == maxHigh + && maxHigh - minHigh > highDiffRate * sharpDetectMultiplier + ; + sharpBullishBuffer[bar_index] = isSharpBullishDetected ? 1 : 0; + + // + bool isSharpBearishDetected = + low == minLow + && high < maxHigh + && marketLowestLowBuffer[bar_index] == minLow + && maxLow - minLow > lowDiffRate * sharpDetectMultiplier + ; + sharpBearishBuffer[bar_index] = isSharpBearishDetected ? 1 : 0; + + // + if ( + drawLabels + && ( + isSharpBearishDetected + || isSharpBullishDetected + ) + ) { + // + datetime time = iTime( + _Symbol, + _Period, + bar_index + ); + + // + string lbl = StringConcatenate( + logTag, + isSharpBullishDetected ? "Bullish_" : "Bearish_", + bar_index + ); + + // + double price = + isSharpBullishDetected + ? + marketLowestLowBuffer[bar_index] - (10 * _Point) + : + marketHighestHighBuffer[bar_index] + (10 * _Point) + ; + + // + uchar arrowCode = + isSharpBullishDetected + ? + SYMBOL_ARROWUP + : + SYMBOL_ARROWDOWN + ; + + // + ENUM_ARROW_ANCHOR anchor = + isSharpBullishDetected + ? + ANCHOR_BOTTOM + : + ANCHOR_TOP + ; + + // + color clr = + isSharpBullishDetected + ? + sharpBullishColor + : + sharpBearishColor + ; + + // + string lblText = + isSharpBullishDetected + ? + sharpBullishLabel + : + sharpBearishLabel + ; + + // + DrawText( + 0, + lbl, + 0, + time, + price, + lblText, + "Tahoma", + 5, + clr + ); + } +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020428/Indicators/x-saherelm.trend.mq4 b/Bkp/Used/14020428/Indicators/x-saherelm.trend.mq4 new file mode 100644 index 0000000..17873e7 --- /dev/null +++ b/Bkp/Used/14020428/Indicators/x-saherelm.trend.mq4 @@ -0,0 +1,250 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center ADX Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm ADX Oscillator" +#property strict + +// +// START Inputs ... +// +input int length = 7; // Averaging Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_chart_window + +// +// #property indicator_buffers 3 + +// +// Declare Buffers ... +// +datetime startTime; +double lHigh; +double lLow; + +// +datetime highTimes[]; + +// +datetime lowTimes[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (length < 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, length); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Long TP ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index +) { + // + // Calculate Buffers ... + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + startTime + ); + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + if (startTime == 0) { + // + startTime = barTime; + return; + } + + // + if ( + startTime > 0 + && startBarIndex - bar_index == length + ) { + // + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + length, + bar_index + ); + datetime hhTime = iTime( + _Symbol, + _Period, + hhIdx + ); + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + int hhSize = ArraySize(highTimes); + datetime tempTimes[]; + ArrayResize( + tempTimes, + hhSize + ); + ArrayCopy( + tempTimes, + highTimes + ); + ArrayResize( + highTimes, + hhSize + 1 + ); + highTimes[0] = hhTime; + ArrayCopy( + highTimes, + tempTimes, + 1 + ); + + // + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + length, + bar_index + ); + datetime llTime = iTime( + _Symbol, + _Period, + llIdx + ); + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + int llSize = ArraySize(lowTimes); + ArrayFree(tempTimes); + ArrayResize( + tempTimes, + llSize + ); + ArrayCopy( + tempTimes, + lowTimes + ); + ArrayResize( + lowTimes, + llSize + 1 + ); + lowTimes[0] = llTime; + ArrayCopy( + lowTimes, + tempTimes, + 1 + ); + + // + startTime = 0; + ArrayFree(tempTimes); + } +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020428/Indicators/x-saherelm.x.hl.mq4 b/Bkp/Used/14020428/Indicators/x-saherelm.x.hl.mq4 new file mode 100644 index 0000000..f08a975 --- /dev/null +++ b/Bkp/Used/14020428/Indicators/x-saherelm.x.hl.mq4 @@ -0,0 +1,412 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center X Indicator +// --------------------------------------------- +// saherelm implementation of above 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 X Indicator" +#property strict + +// +// START Inputs ... +// +// +input int marketLength = 7; // Market Length + +// +input int shortCycleMultiplier = 2; // Market Short Cycle Multiplier +input int mediumCycleMultiplier = 6; // Market Medium Cycle Multiplier +input int longCycleMultiplier = 36; // Market Medium Cycle Multiplier + +// +input ENUM_MA_METHOD maMethod = MODE_SMA; // Ma Method +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 6 + +// +#property indicator_plots 6 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Short Cycle Highest High Buffer ... +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +// Short Cycle Lowest Low Buffer ... +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +// Medium Cycle Highest High Buffer ... +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrAqua +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 + +// +// Medium Cycle Lowest Low Buffer ... +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrFuchsia +#property indicator_style4 STYLE_DOT +#property indicator_width4 1 + +// +// Long Cycle Highest High Buffer ... +#property indicator_type5 DRAW_LINE +#property indicator_color5 C'62,82,6' +#property indicator_style5 STYLE_DOT +#property indicator_width5 1 + +// +// Long Cycle Lowest Low Buffer ... +#property indicator_type6 DRAW_LINE +#property indicator_color6 C'255,81,0' +#property indicator_style6 STYLE_DOT +#property indicator_width6 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +// +// HH Buffers ... +#define scHHBufferIndex 0 +#define scLLBufferIndex 1 +#define mcHHBufferIndex 2 +#define mcLLBufferIndex 3 +#define lcHHBufferIndex 4 +#define lcLLBufferIndex 5 + +double scHHBuffer[]; +double scLLBuffer[]; +double mcHHBuffer[]; +double mcLLBuffer[]; +double lcHHBuffer[]; +double lcLLBuffer[]; + +// +// Variables ... +int shortCycleLength; +int mediumCycleLength; +int longCycleLength; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if ( + marketLength <= 0 || + shortCycleMultiplier <= 0 || + mediumCycleMultiplier <= 0 || + shortCycleMultiplier > mediumCycleMultiplier + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + shortCycleLength = shortCycleMultiplier * marketLength; + mediumCycleLength = mediumCycleMultiplier * marketLength; + longCycleLength = longCycleMultiplier * marketLength; + + // + // Highest High and Lowest Low Buffers ... + // + // Short Cycle Highest High ... + string scHHLbl = StringConcatenate( + "SC HH(", shortCycleLength, ")" + ); + SetIndexBuffer(scHHBufferIndex, scHHBuffer); + SetIndexLabel(scHHBufferIndex, scHHLbl); + + // + // Short Cycle Lowest Low ... + string scLLLbl = StringConcatenate( + "SC LL(", shortCycleLength, ")" + ); + SetIndexBuffer(scLLBufferIndex, scLLBuffer); + SetIndexLabel(scLLBufferIndex, scLLLbl); + + // + // Medium Cycle Highest High ... + string mcHHLbl = StringConcatenate( + "MC HH(", mediumCycleLength, ")" + ); + SetIndexBuffer(mcHHBufferIndex, mcHHBuffer); + SetIndexLabel(mcHHBufferIndex, mcHHLbl); + + // + // Medium Cycle Lowest Low ... + string mcLLLbl = StringConcatenate( + "MC LL(", mediumCycleLength, ")" + ); + SetIndexBuffer(mcLLBufferIndex, mcLLBuffer); + SetIndexLabel(mcLLBufferIndex, mcLLLbl); + + // + // Long Cycle Highest High ... + string lcHHLbl = StringConcatenate( + "LC HH(", longCycleLength, ")" + ); + SetIndexBuffer(lcHHBufferIndex, lcHHBuffer); + SetIndexLabel(lcHHBufferIndex, lcHHLbl); + + // + // Long Cycle Lowest Low ... + string lcLLLbl = StringConcatenate( + "LC LL(", longCycleLength, ")" + ); + SetIndexBuffer(lcLLBufferIndex, lcLLBuffer); + SetIndexLabel(lcLLBufferIndex, lcLLLbl); + // + // End Set Index Buffers ... + // + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculat Ma's ... + // + CalculateShortCycle(i); + + // + CalculateMediumCycle(i); + + // + CalculateLongCycle(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Short Cycle ... +void CalculateShortCycle( + const int &bar_index +) { + // + // Short Cycle Highest High ... + // + int scHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + shortCycleLength, + bar_index + ); + + // + double scHH = iHigh( + _Symbol, + _Period, + scHHIdx + ); + + // + scHHBuffer[bar_index] = scHH; + + // + // Short Cycle Lowest Low ... + // + int scLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + shortCycleLength, + bar_index + ); + + // + double scLL = iLow( + _Symbol, + _Period, + scLLIdx + ); + + // + scLLBuffer[bar_index] = scLL; +} + +// +// Calculating Medium Cycle ... +void CalculateMediumCycle( + const int &bar_index +) { + // + // Medium Cycle Highest High ... + // + int mcHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + mediumCycleLength, + bar_index + ); + + // + double mcHH = iHigh( + _Symbol, + _Period, + mcHHIdx + ); + + // + mcHHBuffer[bar_index] = mcHH; + + // + // Medium Cycle Lowest Low ... + // + int mcLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + mediumCycleLength, + bar_index + ); + + // + double mcLL = iLow( + _Symbol, + _Period, + mcLLIdx + ); + + // + mcLLBuffer[bar_index] = mcLL; +} + +// +// Calculating Long Cycle ... +void CalculateLongCycle( + const int &bar_index +) { + // + // Long Cycle Highest High ... + // + int lcHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + longCycleLength, + bar_index + ); + + // + double lcHH = iHigh( + _Symbol, + _Period, + lcHHIdx + ); + + // + lcHHBuffer[bar_index] = lcHH; + + // + // Long Cycle Lowest Low ... + // + int lcLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + longCycleLength, + bar_index + ); + + // + double lcLL = iLow( + _Symbol, + _Period, + lcLLIdx + ); + + // + lcLLBuffer[bar_index] = lcLL; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020428/Indicators/x-saherelm.x.xma.mq4 b/Bkp/Used/14020428/Indicators/x-saherelm.x.xma.mq4 new file mode 100644 index 0000000..68b4f32 --- /dev/null +++ b/Bkp/Used/14020428/Indicators/x-saherelm.x.xma.mq4 @@ -0,0 +1,355 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center X Indicator +// --------------------------------------------- +// saherelm implementation of above 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 X Indicator" +#property strict + +// +// START Inputs ... +// +// +input int marketLength = 7; // Market Length + +// +input int shortCycleMultiplier = 2; // Market Short Cycle Multiplier +input int mediumCycleMultiplier = 6; // Market Medium Cycle Multiplier +input int longCycleMultiplier = 36; // Market Medium Cycle Multiplier + +// +input ENUM_MA_METHOD maMethod = MODE_SMA; // Ma Method +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 6 + +// +#property indicator_plots 6 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Short Cycle Fast Buffer ... +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +// Short Cycle Slow Buffer ... +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +// Medium Cycle Fast Buffer ... +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrAqua +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 + +// +// Medium Cycle Slow Buffer ... +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrFuchsia +#property indicator_style4 STYLE_DOT +#property indicator_width4 1 + +// +// Long Cycle Fast Buffer ... +#property indicator_type5 DRAW_LINE +#property indicator_color5 C'62,82,6' +#property indicator_style5 STYLE_DOT +#property indicator_width5 1 + +// +// Long Cycle Slow Buffer ... +#property indicator_type6 DRAW_LINE +#property indicator_color6 C'255,81,0' +#property indicator_style6 STYLE_DOT +#property indicator_width6 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +// +// Ma Buffers ... +#define scFastBufferIndex 0 +#define scSlowBufferIndex 1 +#define mcFastBufferIndex 2 +#define mcSlowBufferIndex 3 +#define lcFastBufferIndex 4 +#define lcSlowBufferIndex 5 + +double scFastBuffer[]; +double scSlowBuffer[]; +double mcFastBuffer[]; +double mcSlowBuffer[]; +double lcFastBuffer[]; +double lcSlowBuffer[]; + +// +// Variables ... +int shortCycleLength; +int mediumCycleLength; +int longCycleLength; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if ( + marketLength <= 0 || + shortCycleMultiplier <= 0 || + mediumCycleMultiplier <= 0 || + shortCycleMultiplier > mediumCycleMultiplier + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + shortCycleLength = shortCycleMultiplier * marketLength; + mediumCycleLength = mediumCycleMultiplier * marketLength; + longCycleLength = longCycleMultiplier * marketLength; + + // + // Ma Buffers ... + // + // Short Cycle ... + string scFLbl = StringConcatenate( + "SC F(", shortCycleLength, ")" + ); + SetIndexBuffer(scFastBufferIndex, scFastBuffer); + SetIndexLabel(scFastBufferIndex, scFLbl); + + // + string scSLbl = StringConcatenate( + "SC S(", shortCycleLength, ")" + ); + SetIndexBuffer(scSlowBufferIndex, scSlowBuffer); + SetIndexLabel(scSlowBufferIndex, scSLbl); + + // + // Medium Cycle ... + string mcFLbl = StringConcatenate( + "MC F(", mediumCycleLength, ")" + ); + SetIndexBuffer(mcFastBufferIndex, mcFastBuffer); + SetIndexLabel(mcFastBufferIndex, mcFLbl); + + // + string mcSLbl = StringConcatenate( + "MC S(", mediumCycleLength, ")" + ); + SetIndexBuffer(mcSlowBufferIndex, mcSlowBuffer); + SetIndexLabel(mcSlowBufferIndex, mcSLbl); + + // + // Long Cycle ... + string lcFLbl = StringConcatenate( + "LC F(", longCycleLength, ")" + ); + SetIndexBuffer(lcFastBufferIndex, lcFastBuffer); + SetIndexLabel(lcFastBufferIndex, lcFLbl); + + // + string lcSLbl = StringConcatenate( + "LC S(", longCycleLength, ")" + ); + SetIndexBuffer(lcSlowBufferIndex, lcSlowBuffer); + SetIndexLabel(lcSlowBufferIndex, lcSLbl); + // + // End Set Index Buffers ... + // + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculat Ma's ... + // + CalculateShortCycle(i); + + // + CalculateMediumCycle(i); + + // + CalculateLongCycle(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Short Cycle ... +void CalculateShortCycle( + const int &bar_index +) { + // + double scFast = iMA( + _Symbol, + _Period, + shortCycleLength, + 0, + maMethod, + PRICE_OPEN, + bar_index + ); + scFastBuffer[bar_index] = scFast; + + // + double scSlow = iMA( + _Symbol, + _Period, + shortCycleLength, + 0, + maMethod, + PRICE_CLOSE, + bar_index + ); + scSlowBuffer[bar_index] = scSlow; +} + +// +// Calculating Medium Cycle ... +void CalculateMediumCycle( + const int &bar_index +) { + // + double mcFast = iMA( + _Symbol, + _Period, + mediumCycleLength, + 0, + maMethod, + PRICE_OPEN, + bar_index + ); + mcFastBuffer[bar_index] = mcFast; + + // + double mcSlow = iMA( + _Symbol, + _Period, + mediumCycleLength, + 0, + maMethod, + PRICE_CLOSE, + bar_index + ); + mcSlowBuffer[bar_index] = mcSlow; +} + +// +// Calculating Long Cycle ... +void CalculateLongCycle( + const int &bar_index +) { + // + double lcFast = iMA( + _Symbol, + _Period, + longCycleLength, + 0, + maMethod, + PRICE_OPEN, + bar_index + ); + lcFastBuffer[bar_index] = lcFast; + + // + double lcSlow = iMA( + _Symbol, + _Period, + longCycleLength, + 0, + maMethod, + PRICE_CLOSE, + bar_index + ); + lcSlowBuffer[bar_index] = lcSlow; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020428/Indicators/x-saherelm.xbnd.mq4 b/Bkp/Used/14020428/Indicators/x-saherelm.xbnd.mq4 new file mode 100644 index 0000000..5cea8fd --- /dev/null +++ b/Bkp/Used/14020428/Indicators/x-saherelm.xbnd.mq4 @@ -0,0 +1,425 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XBand Indicator +// --------------------------------------------- +// saherelm implementation of xBand 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 XBND Indicator" +#property strict + +// +#include "../Libraries/x-saherelm.lib.mq4" +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +// START Inputs ... +// +input int marketLength = 5; // Averaging Length +input int ignoreLastCross = 4; // Ignore Last Cross +input int shift = 0; // Averaging Shift +input ENUM_MA_METHOD method = MODE_SMA; // Averaging Mode +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_chart_window + +// +#property indicator_buffers 4 + +// +// Declare Buffers ... +// +// High ... +#property indicator_width1 1 +#property indicator_color1 clrAqua +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_DASHDOT + +// +// Open ... +#property indicator_width2 1 +#property indicator_color2 clrGreen +#property indicator_type2 DRAW_LINE +#property indicator_style2 STYLE_DASH + +// +// Close ... +#property indicator_width3 1 +#property indicator_color3 clrRed +#property indicator_type3 DRAW_LINE +#property indicator_style3 STYLE_DASH + +// +// Low ... +#property indicator_width4 1 +#property indicator_color4 clrFuchsia +#property indicator_type4 DRAW_LINE +#property indicator_style4 STYLE_DASHDOT + +// +#define highBufferIndex 0 +#define openBufferIndex 1 +#define closeBufferIndex 2 +#define lowBufferIndex 3 + +// +double highBuffer[]; +double openBuffer[]; +double closeBuffer[]; +double lowBuffer[]; + +// +datetime lastCrossTime; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + marketLength < 2 + || ignoreLastCross < 0 + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XBND"; + + // + // High ... + string highLabel = StringConcatenate( + "High(", marketLength, ")" + ); + SetIndexBuffer(highBufferIndex, highBuffer); + SetIndexLabel(highBufferIndex, highLabel); + + // + // Open ... + string openLabel = StringConcatenate( + "Open(", marketLength, ")" + ); + SetIndexBuffer(openBufferIndex, openBuffer); + SetIndexLabel(openBufferIndex, openLabel); + + // + // Close ... + string closeLabel = StringConcatenate( + "Close(", marketLength, ")" + ); + SetIndexBuffer(closeBufferIndex, closeBuffer); + SetIndexLabel(closeBufferIndex, closeLabel); + + // + // Low ... + string lowLabel = StringConcatenate( + "Low(", marketLength, ")" + ); + SetIndexBuffer(lowBufferIndex, lowBuffer); + SetIndexLabel(lowBufferIndex, lowLabel); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + RemoveDraws(logTag); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Buffers ... + CalculateBuffers(i); + + // + // Calculate Market Changes ... + CalculateInfo(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index +) { + // + // High ... + double high = iMA( + _Symbol, + _Period, + marketLength, + shift, + method, + PRICE_HIGH, + bar_index + ); + + // + highBuffer[bar_index] = high; + + // + // Open ... + double open = iMA( + _Symbol, + _Period, + marketLength, + shift, + method, + PRICE_OPEN, + bar_index + ); + + // + openBuffer[bar_index] = open; + + // + // Close ... + double close = iMA( + _Symbol, + _Period, + marketLength, + shift, + method, + PRICE_CLOSE, + bar_index + ); + + // + closeBuffer[bar_index] = close; + + // + // Low ... + double low = iMA( + _Symbol, + _Period, + marketLength, + shift, + method, + PRICE_LOW, + bar_index + ); + + // + lowBuffer[bar_index] = low; +} + +// +void CalculateInfo( + const int bar_index +) { + // + XOHCL pCandle = GetCandleModel(bar_index); + + // + bool isTrendingUp = + pCandle.low > highBuffer[bar_index] + && pCandle.high > highBuffer[bar_index]; + + // + bool isTrendingDown = + pCandle.high < lowBuffer[bar_index] + && pCandle.low < lowBuffer[bar_index]; + + // + bool isOpenCrossOverClose = + true + // && + // ( + // pCandle.high > highBuffer[bar_index + 1] + // || pCandle.low < lowBuffer[bar_index + 1] + // ) + && openBuffer[bar_index + 1] > closeBuffer[bar_index + 1] + && !(openBuffer[bar_index + 2] >= closeBuffer[bar_index + 2]) + ; + + // + bool isOpenCrossUnderClose = + true + // && + // ( + // pCandle.high > highBuffer[bar_index + 1] + // || pCandle.low < lowBuffer[bar_index + 1] + // ) + && openBuffer[bar_index + 1] < closeBuffer[bar_index + 1] + && !(openBuffer[bar_index + 2] <= closeBuffer[bar_index + 2]) + ; + + // + isTrendingUp = isOpenCrossUnderClose; + isTrendingDown = isOpenCrossOverClose; + + // + datetime time = iTime( + _Symbol, + _Period, + bar_index + ); + + // + if ( + isTrendingUp + || isTrendingDown + ) { + // + if (lastCrossTime == 0) { + lastCrossTime = time; + } else { + // + int lastCrossBarIndex = iBarShift( + _Symbol, + _Period, + lastCrossTime + ); + + // + int diff = lastCrossBarIndex - bar_index; + if (diff <= ignoreLastCross) { + return; + } else { + lastCrossTime = time; + } + } + } + + // + string lbl = StringConcatenate( + logTag, + "_Arrow_", + isTrendingUp ? "UP" : "Down", + "_", time + ); + + // + color clr = isTrendingUp ? + clrAqua : + clrFuchsia; + + // + ENUM_ARROW_ANCHOR anchor = isTrendingUp ? + ANCHOR_BOTTOM : + ANCHOR_TOP; + + // + uchar arrowCode = isTrendingUp ? + SYMBOL_ARROWUP : + SYMBOL_ARROWDOWN; + + // + double price = isTrendingUp ? + pCandle.low - 20 * _Point : + pCandle.high + 20 * _Point; + + // + if (isTrendingUp) { + // + // this means Market Going Up ... + + } + + // + if (isTrendingDown) { + // + // this means Market Going Downm ... + } + + // + if ( + isTrendingUp + || isTrendingDown + ) { + // + bool isDrawn = DrawArrow( + 0, + lbl, + 0, + time, + price, + arrowCode, + anchor, + clr + ); + } +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020428/Indicators/x-saherelm.xhh.mq4 b/Bkp/Used/14020428/Indicators/x-saherelm.xhh.mq4 new file mode 100644 index 0000000..dfbc2cd --- /dev/null +++ b/Bkp/Used/14020428/Indicators/x-saherelm.xhh.mq4 @@ -0,0 +1,410 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XHH Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 XHH Indicator" +#property strict + +// +// START Inputs ... +// +// +input int marketLength = 7; // Market Length + +// +input int shortCycleMultiplier = 4; // Market Short Cycle Multiplier +input int mediumCycleMultiplier = 14; // Market Medium Cycle Multiplier +input int longCycleMultiplier = 27; // Market Medium Cycle Multiplier +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 6 + +// +#property indicator_plots 6 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Short Cycle Highest High Buffer ... +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +// Short Cycle Lowest Low Buffer ... +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +// Medium Cycle Highest High Buffer ... +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrAqua +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 + +// +// Medium Cycle Lowest Low Buffer ... +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrFuchsia +#property indicator_style4 STYLE_DOT +#property indicator_width4 1 + +// +// Long Cycle Highest High Buffer ... +#property indicator_type5 DRAW_LINE +#property indicator_color5 C'62,82,6' +#property indicator_style5 STYLE_DOT +#property indicator_width5 1 + +// +// Long Cycle Lowest Low Buffer ... +#property indicator_type6 DRAW_LINE +#property indicator_color6 C'255,81,0' +#property indicator_style6 STYLE_DOT +#property indicator_width6 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define shortCycleHighestHighBufferIndex 0 +#define shortCycleLowestLowBufferIndex 1 +#define mediumCycleHighestHighBufferIndex 2 +#define mediumCycleLowestLowBufferIndex 3 +#define longCycleHighestHighBufferIndex 4 +#define longCycleLowestLowBufferIndex 5 + +double shortCycleHighestHighBuffer[]; +double shortCycleLowestLowBuffer[]; +double mediumCycleHighestHighBuffer[]; +double mediumCycleLowestLowBuffer[]; +double longCycleHighestHighBuffer[]; +double longCycleLowestLowBuffer[]; + +// +// Variables ... +int shortCycleLength; +int mediumCycleLength; +int longCycleLength; + +// +double highestHighTimes[]; +double lowestLowTimes[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if ( + marketLength <= 0 || + shortCycleMultiplier <= 0 || + mediumCycleMultiplier <= 0 || + shortCycleMultiplier > mediumCycleMultiplier + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + shortCycleLength = shortCycleMultiplier * marketLength; + mediumCycleLength = mediumCycleMultiplier * marketLength; + longCycleLength = longCycleMultiplier * marketLength; + + // + // Short Cycle Highest High ... + string scHHLbl = StringConcatenate( + "SC HH(", shortCycleLength, ")" + ); + SetIndexBuffer(shortCycleHighestHighBufferIndex, shortCycleHighestHighBuffer); + SetIndexLabel(shortCycleHighestHighBufferIndex, scHHLbl); + + // + // Short Cycle Lowest Low ... + string scLLLbl = StringConcatenate( + "SC LL(", shortCycleLength, ")" + ); + SetIndexBuffer(shortCycleLowestLowBufferIndex, shortCycleLowestLowBuffer); + SetIndexLabel(shortCycleLowestLowBufferIndex, scLLLbl); + + // + // Medium Cycle Highest High ... + string mcHHLbl = StringConcatenate( + "MC HH(", mediumCycleLength, ")" + ); + SetIndexBuffer(mediumCycleHighestHighBufferIndex, mediumCycleHighestHighBuffer); + SetIndexLabel(mediumCycleHighestHighBufferIndex, mcHHLbl); + + // + // Medium Cycle Lowest Low ... + string mcLLLbl = StringConcatenate( + "MC LL(", mediumCycleLength, ")" + ); + SetIndexBuffer(mediumCycleLowestLowBufferIndex, mediumCycleLowestLowBuffer); + SetIndexLabel(mediumCycleLowestLowBufferIndex, mcLLLbl); + + // + // Long Cycle Highest High ... + string lcHHLbl = StringConcatenate( + "LC HH(", longCycleLength, ")" + ); + SetIndexBuffer(longCycleHighestHighBufferIndex, longCycleHighestHighBuffer); + SetIndexLabel(longCycleHighestHighBufferIndex, lcHHLbl); + + // + // Long Cycle Lowest Low ... + string lcLLLbl = StringConcatenate( + "LC LL(", longCycleLength, ")" + ); + SetIndexBuffer(longCycleLowestLowBufferIndex, longCycleLowestLowBuffer); + SetIndexLabel(longCycleLowestLowBufferIndex, lcLLLbl); + // + // End Set Index Buffers ... + // + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + CalculateShortCycle(i); + + // + CalculateMediumCycle(i); + + // + CalculateLongCycle(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Short Cycle ... +void CalculateShortCycle( + const int &bar_index +) { + // + // Short Cycle Highest High ... + // + int scHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + shortCycleLength, + bar_index + ); + + // + double scHH = iHigh( + _Symbol, + _Period, + scHHIdx + ); + + // + shortCycleHighestHighBuffer[bar_index] = scHH; + + // + // Short Cycle Lowest Low ... + // + int scLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + shortCycleLength, + bar_index + ); + + // + double scLL = iLow( + _Symbol, + _Period, + scLLIdx + ); + + // + shortCycleLowestLowBuffer[bar_index] = scLL; +} + +// +// Calculating Medium Cycle ... +void CalculateMediumCycle( + const int &bar_index +) { + // + // Medium Cycle Highest High ... + // + int mcHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + mediumCycleLength, + bar_index + ); + + // + double mcHH = iHigh( + _Symbol, + _Period, + mcHHIdx + ); + + // + mediumCycleHighestHighBuffer[bar_index] = mcHH; + + // + // Medium Cycle Lowest Low ... + // + int mcLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + mediumCycleLength, + bar_index + ); + + // + double mcLL = iLow( + _Symbol, + _Period, + mcLLIdx + ); + + // + mediumCycleLowestLowBuffer[bar_index] = mcLL; +} + +// +// Calculating Long Cycle ... +void CalculateLongCycle( + const int &bar_index +) { + // + // Long Cycle Highest High ... + // + int lcHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + longCycleLength, + bar_index + ); + + // + double lcHH = iHigh( + _Symbol, + _Period, + lcHHIdx + ); + + // + longCycleHighestHighBuffer[bar_index] = lcHH; + + // + // Long Cycle Lowest Low ... + // + int lcLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + longCycleLength, + bar_index + ); + + // + double lcLL = iLow( + _Symbol, + _Period, + lcLLIdx + ); + + // + longCycleLowestLowBuffer[bar_index] = lcLL; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020428/Indicators/x-saherelm.xma.mq4 b/Bkp/Used/14020428/Indicators/x-saherelm.xma.mq4 new file mode 100644 index 0000000..4a599f9 --- /dev/null +++ b/Bkp/Used/14020428/Indicators/x-saherelm.xma.mq4 @@ -0,0 +1,695 @@ + /////////////////////////////////////////////////////// +// +// SaherElm IT Center XMA Indicator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XMA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Market Specifications ... +input int marketLength = 7; // Market Length +input double step = 0.02; // SAR Step +input double maximum = 0.2; // SAR Maximum +// +// Cycle Definitions ... +input int shortCycleFastMultiplier = 1; // Short Cycle Fast Multiplier +input int shortCycleSlowMultiplier = 4; // Short Cycle Slow Multiplier +input int mediumCycleFastMultiplier = 7; // Medium Cycle Fast Multiplier +input int mediumCycleSlowMultiplier = 14; // Medium Cycle Slow Multiplier +input int longCycleFastMultiplier = 70; // Long Cycle Fast Multiplier +input int longCycleSlowMultiplier = 140; // Long Cycle Slow Multiplier +// +// Show Inputs ... +input bool showPSar = true; // Show Parabolic Sar +input bool showMarketMiddle = true; // Show Market Middle +input bool showShortCycle = true; // Show Short Cycle +input bool showShortCycleCrossLines = true; // Show Short Cycle Vertical Lines +input bool showMediumCycle = true; // Show Medium Cycle +input bool showMediumCycleCrossLines = true; // Show Medium Cycle Vertical Lines +input bool showLongCycle = true; // Show Long Cycle +input bool showLongCycleCrossLines = true; // Show Long Cycle Vertical Lines +// +// Color Inputs ... +input color pSarColor = clrCornflowerBlue; // Parabolic Sar Color +input color shortCycleFastColor = clrGreen; // Short Cycle Fast Color +input color shortCycleSlowColor = clrRed; // Short Cycle Slow Color +input color mediumCycleFastColor = clrAqua; // Medium Cycle Fast Color +input color mediumCycleSlowColor = clrFuchsia; // Medium Cycle Slow Color +input color longCycleFastColor = clrGoldenrod; // Medium Cycle Fast Color +input color longCycleSlowColor = clrBrown; // Medium Cycle Slow Color +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// define indicator buffers ... +#property indicator_buffers 8 +#property indicator_plots 8 + +// +// Declare Buffers ... +#define scFastBufferIndex 0 +#define scSlowBufferIndex 1 +#define mcFastBufferIndex 2 +#define mcSlowBufferIndex 3 +#define lcFastBufferIndex 4 +#define lcSlowBufferIndex 5 +#define midBufferIndex 6 +#define pSarBufferIndex 7 + +// +double scFastBuffer[]; +double scSlowBuffer[]; +double mcFastBuffer[]; +double mcSlowBuffer[]; +double lcFastBuffer[]; +double lcSlowBuffer[]; +double midBuffer[]; +double pSarBuffer[]; + +// +int shortCycleFastLength; +int shortCycleSlowLength; +int mediumCycleFastLength; +int mediumCycleSlowLength; +int longCycleFastLength; +int longCycleSlowLength; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + // + // Validate Market Length ... + marketLength <= 0 + // + // Validate Short Cycle ... + || shortCycleFastMultiplier <= 0 + || shortCycleSlowMultiplier <= 0 + || shortCycleFastMultiplier >= shortCycleSlowMultiplier + // + // Validate Medium Cycle ... + || mediumCycleFastMultiplier <= 0 + || mediumCycleSlowMultiplier <= 0 + || mediumCycleFastMultiplier >= mediumCycleSlowMultiplier + // + // Validate Long Cycle ... + || longCycleFastMultiplier <= 0 + || longCycleSlowMultiplier <= 0 + || longCycleFastMultiplier >= longCycleSlowMultiplier + // + // Validate Series of Multipliers ... + || shortCycleFastMultiplier >= mediumCycleFastMultiplier + || mediumCycleFastMultiplier >= longCycleFastMultiplier + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST_XMA"; + + // + // Calculate Cycle Length based on given Multipliers ... + shortCycleFastLength = marketLength * shortCycleFastMultiplier; + shortCycleSlowLength = marketLength * shortCycleSlowMultiplier; + mediumCycleFastLength = marketLength * mediumCycleFastMultiplier; + mediumCycleSlowLength = marketLength * mediumCycleSlowMultiplier; + longCycleFastLength = marketLength * longCycleFastMultiplier; + longCycleSlowLength = marketLength * longCycleSlowMultiplier; + + // + // Short Cycle Fast ... + SetIndexLabel(scFastBufferIndex, "SCFast"); + SetIndexBuffer(scFastBufferIndex, scFastBuffer); + SetIndexDrawBegin(scFastBufferIndex, shortCycleFastLength); + SetIndexStyle( + scFastBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showShortCycle ? + shortCycleFastColor : + clrNONE + ); + + // + // Short Cycle Slow ... + SetIndexLabel(scSlowBufferIndex, "SCSLow"); + SetIndexBuffer(scSlowBufferIndex, scSlowBuffer); + SetIndexDrawBegin(scSlowBufferIndex, shortCycleSlowLength); + SetIndexStyle( + scSlowBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showShortCycle ? + shortCycleSlowColor : + clrNONE + ); + + // + // Medium Cycle Fast ... + SetIndexLabel(mcFastBufferIndex, "MCFast"); + SetIndexBuffer(mcFastBufferIndex, mcFastBuffer); + SetIndexDrawBegin(mcFastBufferIndex, mediumCycleFastLength); + SetIndexStyle( + mcFastBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showMediumCycle ? + mediumCycleFastColor : + clrNONE + ); + + // + // Medium Cycle Slow ... + SetIndexLabel(mcSlowBufferIndex, "MCSlow"); + SetIndexBuffer(mcSlowBufferIndex, mcSlowBuffer); + SetIndexDrawBegin(mcSlowBufferIndex, mediumCycleSlowLength); + SetIndexStyle( + mcSlowBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showMediumCycle ? + mediumCycleSlowColor : + clrNONE + ); + + // + // Long Cycle Fast ... + SetIndexLabel(lcFastBufferIndex, "LCFast"); + SetIndexBuffer(lcFastBufferIndex, lcFastBuffer); + SetIndexDrawBegin(lcFastBufferIndex, longCycleFastLength); + SetIndexStyle( + lcFastBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showLongCycle ? + longCycleFastColor : + clrNONE + ); + + // + // Long Cycle Slow ... + SetIndexLabel(lcSlowBufferIndex, "LCSlow"); + SetIndexBuffer(lcSlowBufferIndex, lcSlowBuffer); + SetIndexDrawBegin(lcSlowBufferIndex, longCycleSlowLength); + SetIndexStyle( + lcSlowBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showLongCycle ? + longCycleSlowColor : + clrNONE + ); + + // + // Market Middleage ... + SetIndexBuffer(midBufferIndex, midBuffer); + SetIndexDrawBegin(midBufferIndex, marketLength); + SetIndexLabel(midBufferIndex, "Market Mid"); + + // + // Parabolic Sar ... + SetIndexBuffer(pSarBufferIndex, pSarBuffer); + SetIndexLabel(pSarBufferIndex, "P Sar"); + SetIndexStyle( + pSarBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showPSar ? + pSarColor : + clrNONE + ); + + // + // Market Middle ... + SetIndexBuffer(midBufferIndex, midBuffer); + SetIndexLabel(midBufferIndex, "Mid"); + SetIndexStyle( + midBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showMarketMiddle ? + clrAntiqueWhite : + clrNONE + ); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + RemoveDraws(logTag); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(marketLength, longCycleSlowLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Short Cycle ... + CalculateShortCycle(i); + + // + // Calculate Medium Cycle ... + CalculateMediumCycle(i); + + // + // Calculate Long Cycle ... + CalculateLongCycle(i); + + // + // Calculate Market Middleage ... + CalculateMarketMiddleage(i); + + // + // Calculate Cross Points ... + CalculateCrossPoints(i); + + // + // Calculate Parabolic Sar ... + CalculateParabolicSar(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculate Short Cycle ... +void CalculateShortCycle( + const int bar_index +) { + // + // Fast ... + double shortCycleFast = iMA( + _Symbol, + _Period, + shortCycleFastLength, + 0, + MODE_SMA, + PRICE_WEIGHTED, + bar_index + ); + scFastBuffer[bar_index] = shortCycleFast; + + // + // Slow ... + double shortCycleSlow = iMA( + _Symbol, + _Period, + shortCycleSlowLength, + 0, + MODE_SMA, + PRICE_WEIGHTED, + bar_index + ); + scSlowBuffer[bar_index] = shortCycleSlow; +} + +// +// Calculate Medium Cycle ... +void CalculateMediumCycle( + const int bar_index +) { + // + // Fast ... + double mediumCycleFast = iMA( + _Symbol, + _Period, + mediumCycleFastLength, + 0, + MODE_SMA, + PRICE_MEDIAN, + bar_index + ); + mcFastBuffer[bar_index] = mediumCycleFast; + + // + // Slow ... + double mediumCycleSlow = iMA( + _Symbol, + _Period, + mediumCycleSlowLength, + 0, + MODE_SMA, + PRICE_MEDIAN, + bar_index + ); + mcSlowBuffer[bar_index] = mediumCycleSlow; +} + +// +// Calculate Long Cycle ... +void CalculateLongCycle( + const int bar_index +) { + // + // Fast ... + double longCycleFast = iMA( + _Symbol, + _Period, + longCycleFastLength, + 0, + MODE_SMA, + PRICE_CLOSE, + bar_index + ); + lcFastBuffer[bar_index] = longCycleFast; + + // + // Slow ... + double longCycleSlow = iMA( + _Symbol, + _Period, + longCycleSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE, + bar_index + ); + lcSlowBuffer[bar_index] = longCycleSlow; +} + +// +// Calculate Market Middleage ... +void CalculateMarketMiddleage( + const int bar_index +) { + // + // Mid ... + double marketMiddleage = iMA( + _Symbol, + _Period, + (int)(marketLength * 1.5), + 0, + MODE_EMA, + PRICE_MEDIAN, + bar_index + ); + midBuffer[bar_index] = marketMiddleage; +} + +// +// Calculate Cross Points and Draw Section Line on theme ... +void CalculateCrossPoints( + const int bar_index +) { + // + // START Draw Cross Lines ... + // + // + // Short Cycle ... + bool isSCFastCrossOverSlow = scFastBuffer[bar_index] > scSlowBuffer[bar_index] + && !(scFastBuffer[bar_index + 1] > scSlowBuffer[bar_index + 1]); + + // + bool isSCFastCrossUnderSlow = scFastBuffer[bar_index] < scSlowBuffer[bar_index] + && !(scFastBuffer[bar_index + 1] < scSlowBuffer[bar_index + 1]); + + // + // Medium Cycle ... + bool isMCFastCrossOverSlow = mcFastBuffer[bar_index] > mcSlowBuffer[bar_index] + && !(mcFastBuffer[bar_index + 1] > mcSlowBuffer[bar_index + 1]); + + // + bool isMCFastCrossUnderSlow = mcFastBuffer[bar_index] < mcSlowBuffer[bar_index] + && !(mcFastBuffer[bar_index + 1] < mcSlowBuffer[bar_index + 1]); + + // + // Long Cycle ... + bool isLCFastCrossOverSlow = lcFastBuffer[bar_index] > lcSlowBuffer[bar_index] + && !(lcFastBuffer[bar_index + 1] > lcSlowBuffer[bar_index + 1]); + + // + bool isLCFastCrossUnderSlow = lcFastBuffer[bar_index] < lcSlowBuffer[bar_index] + && !(lcFastBuffer[bar_index + 1] < lcSlowBuffer[bar_index + 1]); + + // + // START Drawing CrossPoints ... + // + // + datetime currentTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + if (showShortCycleCrossLines) { + // + // Draw Line ... + if (isSCFastCrossOverSlow) { + // + string lbl = StringConcatenate( + logTag, + "_SC_F_OV_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showShortCycleCrossLines ? + shortCycleFastColor : + clrNONE + ); + } + + // + // Draw Line ... + if (isSCFastCrossUnderSlow) { + // + string lbl = StringConcatenate( + logTag, + "_SC_F_UN_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showShortCycleCrossLines ? + shortCycleSlowColor : + clrNONE + ); + } + } + + // + if (showMediumCycleCrossLines) { + // + // Draw Line ... + if (isMCFastCrossOverSlow) { + // + string lbl = StringConcatenate( + logTag, + "_MC_F_OV_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showMediumCycleCrossLines ? + mediumCycleFastColor : + clrNONE + ); + } + + // + // Draw Line ... + if (isMCFastCrossUnderSlow) { + // + string lbl = StringConcatenate( + logTag, + "_MC_F_UN_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showMediumCycleCrossLines ? + mediumCycleSlowColor : + clrNONE + ); + } + } + + // + if (showLongCycleCrossLines) { + // + // Draw Line ... + if (isLCFastCrossOverSlow) { + // + string lbl = StringConcatenate( + logTag, + "_LC_F_OV_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showLongCycleCrossLines ? + longCycleFastColor : + clrNONE + ); + } + + // + // Draw Line ... + if (isLCFastCrossUnderSlow) { + // + string lbl = StringConcatenate( + logTag, + "_LC_F_UN_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showLongCycleCrossLines ? + longCycleSlowColor : + clrNONE + ); + } + } + // + // END Drawing CrossPoints ... + // +} + +void CalculateParabolicSar( + const int bar_index +) { + // + double sarValue = iSAR( + NULL, + _Period, + step, + maximum, + bar_index + ); + + // + pSarBuffer[bar_index] = sarValue; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020428/Indicators/x-saherelm.xmarket.mq4 b/Bkp/Used/14020428/Indicators/x-saherelm.xmarket.mq4 new file mode 100644 index 0000000..71b2e2c --- /dev/null +++ b/Bkp/Used/14020428/Indicators/x-saherelm.xmarket.mq4 @@ -0,0 +1,394 @@ + /////////////////////////////////////////////////////// +// +// SaherElm IT Center XMKT Indicator +// --------------------------------------------- +// retrieve market base info ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XMKT Indicator" +#property strict + +// +// START Inputs ... +// +// +// Market Specifications ... +input int marketLength = 7; // Market Length +// +input bool showHighestHigh = true; // Show Market Highest High +input bool showHighestLow = true; // Show Market Highest Low +input bool showHighestOpen = true; // Show Market Highest Open +input bool showHighestClose = true; // Show Market Highest Close +input bool showLowestHigh = true; // Show Market Lowest High +input bool showLowestLow = true; // Show Market Lowest Low +input bool showLowestOpen = true; // Show Market Lowest Open +input bool showLowestClose = true; // Show Market Lowest Close +// +input color highestHighColor = clrDeepPink; // Market Highest High Color +input color highestLowColor = clrDarkOrange; // Market Highest Low Color +input color highestOpenColor = clrDodgerBlue; // Market Highest Open Color +input color highestCloseColor = clrOrchid; // Market Highest Close Color +input color lowestHighColor = clrHotPink; // Market Lowest High Color +input color lowestLowColor = clrOrange; // Market Lowest Low Color +input color lowestOpenColor = clrPowderBlue; // Market Lowest Open Color +input color lowestCloseColor = clrMediumOrchid; // Market Lowest Close Color +// +input ENUM_LINE_STYLE highestHighStyle = STYLE_DOT; // Market Highest High Line Style +input ENUM_LINE_STYLE highestLowStyle = STYLE_DOT; // Market Highest Low Line Style +input ENUM_LINE_STYLE highestOpenStyle = STYLE_DOT; // Market Highest Open Line Style +input ENUM_LINE_STYLE highestCloseStyle = STYLE_DOT; // Market Highest Close Line Style +input ENUM_LINE_STYLE lowestHighStyle = STYLE_DOT; // Market Lowest High Line Style +input ENUM_LINE_STYLE lowestLowStyle = STYLE_DOT; // Market Lowest Low Line Style +input ENUM_LINE_STYLE lowestOpenStyle = STYLE_DOT; // Market Lowest Open Line Style +input ENUM_LINE_STYLE lowestCloseStyle = STYLE_DOT; // Market Lowest Close Line Style +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// define indicator buffers ... +#property indicator_buffers 8 +#property indicator_plots 8 + +// +// Declare Buffers ... +#define marketHighestHighBufferIndex 0 +#define marketHighestLowBufferIndex 1 +#define marketHighestOpenBufferIndex 2 +#define marketHighestCloseBufferIndex 3 +#define marketLowestHighBufferIndex 4 +#define marketLowestLowBufferIndex 5 +#define marketLowestOpenBufferIndex 6 +#define marketLowestCloseBufferIndex 7 + +// +double marketHighestHighBuffer[]; +double marketHighestLowBuffer[]; +double marketHighestOpenBuffer[]; +double marketHighestCloseBuffer[]; +double marketLowestHighBuffer[]; +double marketLowestLowBuffer[]; +double marketLowestOpenBuffer[]; +double marketLowestCloseBuffer[]; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (marketLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST_XMKT"; + + // + // Highest High ... + string highestHighLbl = StringConcatenate("HH(", marketLength,")"); + SetIndexLabel(marketHighestHighBufferIndex, highestHighLbl); + SetIndexBuffer(marketHighestHighBufferIndex, marketHighestHighBuffer); + SetIndexStyle( + marketHighestHighBufferIndex, + showHighestHigh ? + DRAW_LINE : + DRAW_NONE, + highestHighStyle, + 1, + showHighestHigh ? + highestHighColor : + clrNONE + ); + + // + // Highest Low ... + string highestLowLbl = StringConcatenate("HL(", marketLength,")"); + SetIndexLabel(marketHighestLowBufferIndex, highestLowLbl); + SetIndexBuffer(marketHighestLowBufferIndex, marketHighestLowBuffer); + SetIndexStyle( + marketHighestLowBufferIndex, + showHighestLow ? + DRAW_LINE : + DRAW_NONE, + highestLowStyle, + 1, + showHighestLow ? + highestLowColor : + clrNONE + ); + + // + // Highest Open ... + string highestOpenLbl = StringConcatenate("HO(", marketLength,")"); + SetIndexLabel(marketHighestOpenBufferIndex, highestOpenLbl); + SetIndexBuffer(marketHighestOpenBufferIndex, marketHighestOpenBuffer); + SetIndexStyle( + marketHighestOpenBufferIndex, + showHighestOpen ? + DRAW_LINE : + DRAW_NONE, + highestOpenStyle, + 1, + showHighestOpen ? + highestOpenColor : + clrNONE + ); + + // + // Highest Close ... + string highestCloseLbl = StringConcatenate("HC(", marketLength,")"); + SetIndexLabel(marketHighestCloseBufferIndex, highestCloseLbl); + SetIndexBuffer(marketHighestCloseBufferIndex, marketHighestCloseBuffer); + SetIndexStyle( + marketHighestCloseBufferIndex, + showHighestClose ? + DRAW_LINE : + DRAW_NONE, + highestCloseStyle, + 1, + showHighestClose ? + highestCloseColor : + clrNONE + ); + + // + // Lowest High ... + string lowestHighLbl = StringConcatenate("LH(", marketLength,")"); + SetIndexLabel(marketLowestHighBufferIndex, lowestHighLbl); + SetIndexBuffer(marketLowestHighBufferIndex, marketLowestHighBuffer); + SetIndexStyle( + marketLowestHighBufferIndex, + showLowestHigh ? + DRAW_LINE : + DRAW_NONE, + lowestHighStyle, + 1, + showLowestHigh ? + lowestHighColor : + clrNONE + ); + + // + // Lowest Low ... + string lowestLowLbl = StringConcatenate("LL(", marketLength,")"); + SetIndexLabel(marketLowestLowBufferIndex, lowestLowLbl); + SetIndexBuffer(marketLowestLowBufferIndex, marketLowestLowBuffer); + SetIndexStyle( + marketLowestLowBufferIndex, + showLowestLow ? + DRAW_LINE : + DRAW_NONE, + lowestLowStyle, + 1, + showLowestLow ? + lowestLowColor : + clrNONE + ); + + // + // Lowest Open ... + string lowestOpenLbl = StringConcatenate("LO(", marketLength,")"); + SetIndexLabel(marketLowestOpenBufferIndex, lowestOpenLbl); + SetIndexBuffer(marketLowestOpenBufferIndex, marketLowestOpenBuffer); + SetIndexStyle( + marketLowestOpenBufferIndex, + showLowestOpen ? + DRAW_LINE : + DRAW_NONE, + lowestOpenStyle, + 1, + showLowestOpen ? + lowestOpenColor : + clrNONE + ); + + // + // Lowest Close ... + string lowestCloseLbl = StringConcatenate("LC(", marketLength,")"); + SetIndexLabel(marketLowestCloseBufferIndex, lowestCloseLbl); + SetIndexBuffer(marketLowestCloseBufferIndex, marketLowestCloseBuffer); + SetIndexStyle( + marketLowestCloseBufferIndex, + showLowestClose ? + DRAW_LINE : + DRAW_NONE, + lowestCloseStyle, + 1, + showLowestClose ? + lowestCloseColor : + clrNONE + ); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + RemoveDraws(logTag); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(marketLength, 3); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Short Cycle ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculate Short Cycle ... +void CalculateBuffers( + const int bar_index +) { + // + // Highest High ... + double highestHighValue = GetMarketHighestHigh( + bar_index, + marketLength + ); + marketHighestHighBuffer[bar_index] = highestHighValue; + + // + // Highest Low ... + double highestLowValue = GetMarketHighestLow( + bar_index, + marketLength + ); + marketHighestLowBuffer[bar_index] = highestLowValue; + + // + // Highest Open ... + double highestOpenValue = GetMarketHighestOpen( + bar_index, + marketLength + ); + marketHighestOpenBuffer[bar_index] = highestOpenValue; + + // + // Highest Close ... + double highestCloseValue = GetMarketHighestClose( + bar_index, + marketLength + ); + marketHighestCloseBuffer[bar_index] = highestCloseValue; + + // + // Lowest High ... + double lowestHighValue = GetMarketLowestHigh( + bar_index, + marketLength + ); + marketLowestHighBuffer[bar_index] = lowestHighValue; + + // + // Lowest Low ... + double lowestLowValue = GetMarketLowestLow( + bar_index, + marketLength + ); + marketLowestLowBuffer[bar_index] = lowestLowValue; + + // + // Lowest Open ... + double lowestOpenValue = GetMarketLowestOpen( + bar_index, + marketLength + ); + marketLowestOpenBuffer[bar_index] = lowestOpenValue; + + // + // Lowest Close ... + double lowestCloseValue = GetMarketLowestClose( + bar_index, + marketLength + ); + marketLowestCloseBuffer[bar_index] = lowestCloseValue; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020428/Indicators/x-saherelm.xmtrend.mq4 b/Bkp/Used/14020428/Indicators/x-saherelm.xmtrend.mq4 new file mode 100644 index 0000000..aa89e7b --- /dev/null +++ b/Bkp/Used/14020428/Indicators/x-saherelm.xmtrend.mq4 @@ -0,0 +1,221 @@ + /////////////////////////////////////////////////////// +// +// SaherElm IT Center XMTR Indicator +// --------------------------------------------- +// retrieve market base info ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XMKT Indicator" +#property strict + +// +// START Inputs ... +// +// +// Market Specifications ... +input int marketLength = 20; // Market Length +input int atrMultiplier = 1; // ATR Multiplier +input int atrLength = 5; // ATR Period +input ENUM_APPLIED_PRICE source = PRICE_CLOSE; // Source +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// define indicator buffers ... +#property indicator_buffers 3 +#property indicator_plots 3 + +// +// Declare Buffers ... +#define trendBufferIndex 0 +#define upTrendBufferIndex 1 +#define downTrendBufferIndex 2 + +// +double trendBuffer[]; +double upTrendBuffer[]; +double downTrendBuffer[]; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (marketLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XMTR"; + + // + // TREND ... + SetIndexLabel(trendBufferIndex, "Trend"); + SetIndexBuffer(trendBufferIndex, trendBuffer); + SetIndexStyle( + trendBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + clrNONE + ); + + // + // UP Trend ... + SetIndexLabel(upTrendBufferIndex, "Up Trend"); + SetIndexBuffer(upTrendBufferIndex, upTrendBuffer); + SetIndexStyle( + upTrendBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + clrNONE + ); + + // + // DOWN Trend ... + SetIndexLabel(downTrendBufferIndex, "Down Trend"); + SetIndexBuffer(downTrendBufferIndex, downTrendBuffer); + SetIndexStyle( + downTrendBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + clrNONE + ); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + RemoveDraws(logTag); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(marketLength, 3); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Short Cycle ... + CalculateBuffers( + i, + low + ); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculate Short Cycle ... +void CalculateBuffers( + const int bar_index, + const double &low[] +) { + // + double atr = GetMarketTRSMA( + bar_index, + atrLength + ); + + // + double smoothedAtr = (atr * atrMultiplier); + double upTrend = low[bar_index] - smoothedAtr; + double downTrend = low[bar_index] + smoothedAtr; + + // + double cciValue = GetMarketCCI( + bar_index, + marketLength, + source + ); + + // + // TODO: Complete this ... +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020428/Indicators/x-saherelm.zigzag.mq4 b/Bkp/Used/14020428/Indicators/x-saherelm.zigzag.mq4 new file mode 100644 index 0000000..fbb073c --- /dev/null +++ b/Bkp/Used/14020428/Indicators/x-saherelm.zigzag.mq4 @@ -0,0 +1,476 @@ +///////////////////////////////////////////////////////////////// +// +// SaherElm IT Center ZigZag Indicator +// ------------------------------------------------------------- +// this indicator provides signals for Main strategy ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +//////////////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm ZigZag Indicator" +#property strict + +// +// START Inputs ... +// +input int depth = 12; // Depth +input int deviation = 5; // Deviation +input int backStep = 3; // BackStep +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// here we specify logging enabled or not ... +bool enableLogging = true; + +// +// this is a Tag which attached to our Logger ... +string logTag = "XS_ZG"; + +// +#property indicator_chart_window + +// +#property indicator_buffers 1 + +// +#property indicator_width1 1 +#property indicator_color1 clrAqua +// #property indicator_type1 DRAW_SECTION +// #property indicator_style1 STYLE_SOLID + +// // +// #property indicator_width2 1 +// #property indicator_color2 clrNONE +// #property indicator_type2 DRAW_NONE +// #property indicator_style2 STYLE_SOLID + +// // +// #property indicator_width3 1 +// #property indicator_color3 clrNONE +// #property indicator_type3 DRAW_NONE +// #property indicator_style3 STYLE_SOLID + +// +// Buffers ... +// +#define zigzagBufferIndex 0 +#define highBufferIndex 1 +#define lowBufferIndex 2 +// #define ziggyBufferIndex 3 + +// +double zigzagBuffer[]; +double highBuffer[]; +double lowBuffer[]; +// double ziggyBuffer[]; + +// +// recounting's depth of extremums ... +int level=3; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + depth <= 0 || + backStep < 0 || + deviation < 0 || + backStep >= depth + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Set Index Buffers of ZigZag ... + IndicatorBuffers(3); + + // + // ZigZag Buffer ... + SetIndexBuffer(zigzagBufferIndex, zigzagBuffer); + SetIndexStyle(zigzagBufferIndex, DRAW_SECTION); + SetIndexLabel(zigzagBufferIndex, "ZigZag"); + + // + // High Buffer ... + SetIndexBuffer(highBufferIndex, highBuffer); + SetIndexLabel(highBufferIndex, ""); + + // + // Low Buffer ... + SetIndexBuffer(lowBufferIndex, lowBuffer); + SetIndexLabel(lowBufferIndex, ""); + + // + // Ziggy Buffer ... + // SetIndexBuffer(ziggyBufferIndex, ziggyBuffer); + // SetIndexLabel(ziggyBufferIndex, ""); + + // + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + int maxLength = MathMax(depth, backStep); + + int i; + int counterZ; + int back; + int pos; + + // + int lastlowpos = 0; + int lasthighpos = 0; + int whatlookfor = 0; + + // + double extremum; + + // + double curlow = 0.0; + double curhigh = 0.0; + double lasthigh = 0.0; + double lastlow = 0.0; + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // first calculations ... + if (prev_calculated == 0) { + limit = InitializeBuffers(); + } else { + // + // find first extremum in the depth ExtLevel or 100 last bars ... + i = counterZ = 0; + while(counterZ < level && i < 100) { + // + if(zigzagBuffer[i] != 0.0) { + counterZ++; + } + + // + i++; + } + + // + // no extremum found - recounting all from begin ... + if(counterZ == 0) { + limit = InitializeBuffers(); + } else { + // + // set start position to found extremum position ... + limit = i-1; + + // + //--- what kind of extremum? + if(lowBuffer[i] != 0.0) { + // + // low extremum ... + curlow = lowBuffer[i]; + + // + // will look for the next high extremum ... + whatlookfor=1; + } else { + // + // high extremum ... + curhigh = highBuffer[i]; + + // + // will look for the next low extremum ... + whatlookfor=-1; + } + + // + // clear the rest data ... + for(i = limit - 1; i >= 0; i--) { + // + lowBuffer[i]=0.0; + highBuffer[i]=0.0; + zigzagBuffer[i]=0.0; + } + } + } + + // + // Main Calculation Loop ... + for (i = limit; i >= 0; i--) { + // + // find lowest low in depth of bars ... + extremum = low[ + iLowest( + _Symbol, + _Period, + MODE_LOW, + depth, + i + ) + ]; + + // + // this lowest has been found previously ... + if (extremum == lastlow) { + extremum = 0.0; + } else { + // + // new last low ... + lastlow=extremum; + + // + // discard extremum if current low is too high ... + if(low[i] - extremum > deviation * _Point) { + extremum=0.0; + } else { + // + // clear previous extremums in backstep bars ... + for(back = 1; back <= backStep; back++) { + // + pos = i + back; + + // + if(lowBuffer[pos] != 0 && lowBuffer[pos] > extremum) { + lowBuffer[pos] = 0.0; + } + } + } + } + + // + // found extremum is current low ... + if (low[i] == extremum) { + lowBuffer[i] = extremum; + } else { + lowBuffer[i] = 0.0; + } + + // + // find highest high in depth of bars ... + extremum = high[ + iHighest( + _Symbol, + _Period, + MODE_HIGH, + depth, + i + ) + ]; + + // + // this highest has been found previously ... + if (extremum == lasthigh) { + extremum = 0.0; + } else { + // + // new last high ... + lasthigh=extremum; + + // + // discard extremum if current high is too low ... + if (extremum - high[i] > deviation * Point) { + extremum = 0.0; + } else { + // + // clear previous extremums in backstep bars ... + for(back = 1; back <= backStep; back++) { + // + pos = i + back; + + // + if (highBuffer[pos] != 0 && highBuffer[pos] < extremum) { + highBuffer[pos] = 0.0; + } + } + } + } + + // + // found extremum is current high ... + if (high[i] == extremum) { + highBuffer[i] = extremum; + } else { + highBuffer[i] = 0.0; + } + } + + // + // final cutting ... + if( whatlookfor == 0) { + // + lastlow = 0.0; + lasthigh = 0.0; + } else { + // + lastlow = curlow; + lasthigh = curhigh; + } + + // + for(i = limit; i >= 0; i--) { + switch(whatlookfor) { + // + // look for peak or lawn ... + case 0: + // + if (lastlow == 0.0 && lasthigh == 0.0) { + if(highBuffer[i]!=0.0) { + // + lasthigh = High[i]; + lasthighpos = i; + whatlookfor = -1; + + // + zigzagBuffer[i] = lasthigh; + } + + // + if(lowBuffer[i] != 0.0) { + // + lastlow = Low[i]; + lastlowpos = i; + whatlookfor = 1; + + // + zigzagBuffer[i] = lastlow; + } + } + break; + + // + // look for peak ... + case 1: + // + if ( + lowBuffer[i] != 0.0 && + lowBuffer[i] < lastlow && + highBuffer[i] == 0.0 + ) { + // + zigzagBuffer[lastlowpos] = 0.0; + lastlowpos = i; + lastlow = lowBuffer[i]; + zigzagBuffer[i] = lastlow; + } + + // + if(highBuffer[i] != 0.0 && lowBuffer[i] == 0.0) { + // + lasthigh = highBuffer[i]; + lasthighpos = i; + zigzagBuffer[i] = lasthigh; + + // + whatlookfor=-1; + } + break; + + // + // look for lawn ... + case -1: + // + if( + highBuffer[i] != 0.0 && + highBuffer[i] > lasthigh && + lowBuffer[i] == 0.0 + ) { + // + zigzagBuffer[lasthighpos] = 0.0; + lasthighpos = i; + lasthigh = highBuffer[i]; + zigzagBuffer[i] = lasthigh; + } + + // + if( + lowBuffer[i] !=0.0 && + highBuffer[i] == 0.0 + ) { + // + lastlow = lowBuffer[i]; + lastlowpos = i; + zigzagBuffer[i] = lastlow; + whatlookfor=1; + } + break; + } + } + + // + // Done ... + return rates_total; +} + +// +// De Initialization ... +void OnDeinit(const int reason) { + // + // RemoveDraws(signalPrefix); + ChartRedraw(0); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +int InitializeBuffers() { + // + ArrayInitialize(lowBuffer,0.0); + ArrayInitialize(highBuffer, 0.0); + ArrayInitialize(zigzagBuffer, 0.0); + + // + //--- first counting position + return(Bars - depth); +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020428/Libraries/x-saherelm.cci.signal.lib.mq4 b/Bkp/Used/14020428/Libraries/x-saherelm.cci.signal.lib.mq4 new file mode 100644 index 0000000..c572f3d --- /dev/null +++ b/Bkp/Used/14020428/Libraries/x-saherelm.cci.signal.lib.mq4 @@ -0,0 +1,472 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 CCI Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// Based Signal Conditions ... +struct XCCILongSignalConditions { + // + datetime start; + + // + datetime crossOverMinusHundredTime; + datetime crossUnderMinusHundredTime; + + // + double crossOverSlope; +}; + +// +static XCCILongSignalConditions cciLongConds; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Signal Conditions ... +void CheckCCILongSignalConditions( + const int bar_index, + const int marketLen, + // + const double smoother = 10 +) { + // + // Retrieve Bar Time ... + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // LONG: + // wait for cci cross under -100 + // then wait for cross over -100 + // slope of crossing over ??? ... + if (cciLongConds.start == 0) { + // LogMessage("Start"); + cciLongConds.start = barTime; + return; + } + + // + // Check Start Time ... + if (cciLongConds.start == 0) { + return; + } + + // + // Read current, prev, and prevPrev CCI ... + double cci = GetMarketCCI( + bar_index, + marketLen + ); + double cci1 = GetMarketCCI( + bar_index + 1, + marketLen + ); + double cci2 = GetMarketCCI( + bar_index + 2, + marketLen + ); + + // + // Find Cross Under -100 ... + bool isCrossUnderMinusHundred = + cci < -105 && !(cci1 < -105) + && MathAbs(MathAbs(cci) - MathAbs(cci1)) > smoother + ; + + // + // Find Cross Over -100 ... + bool isCrossOverMinusHundred = + cci > -105 && !(cci1 > -105) + && MathAbs(cci - cci1) > smoother + ; + + // + // Fill Conditions ... + if ( + isCrossUnderMinusHundred + && cciLongConds.crossUnderMinusHundredTime == 0 + && cciLongConds.crossOverMinusHundredTime == 0 + ) { + // LogMessage("Cross Under ..."); + cciLongConds.crossUnderMinusHundredTime = barTime; + return; + } + + // + // Fill Conditions ... + if ( + isCrossOverMinusHundred + && cciLongConds.crossOverMinusHundredTime == 0 + && cciLongConds.crossUnderMinusHundredTime != 0 + ) { + // + // LogMessage("Cross Over ..."); + cciLongConds.crossOverMinusHundredTime = barTime; + } + + // + // Prevent Going forward untill Cross Under Happens ... + if (cciLongConds.crossUnderMinusHundredTime == 0) { + return; + } + + // + // Prevent from Going forward untill Cross Over Happens ... + if (cciLongConds.crossOverMinusHundredTime == 0) { + return; + } + + // + // Calculate Slope ... + double x1 = 0; + double y1 = cci1; + double x2 = 1; + double y2 = cci; + + // + // Calculat Line Slope ... + double tSlope = GetSlope( + x1, y1, x2, y2 + ); + + // + cciLongConds.crossOverSlope = tSlope; + // LogMessage("Slope: " + tSlope); +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateCCILongSignal( + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r // Risk to Reward ratio ... +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if (!ValidateCCILongConditions()) { + return result; + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double entryPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double exitPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + int llIdx = GetLowestLowOFCCILongPeriodIndex(); + double ll = + GetMarketLowestLow( + bar_index, + marketLen + ); + // GetLowestLowOFCCILongPeriod(); + + // + int hhIdx = GetHighestHighOfCCILongPeriodIndex(); + double hh = GetHighestHighOfCCILongPeriod(); + // GetMarketHighestHigh( + // bar_index, + // marketLen + // ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = MathMin(openPrice, closePrice) - ll; + double reward = risk * r2r; + + // + double sl = 0; // ll; + double tp = entryPrice + reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = X_SIGNAL_LONG; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_CCI_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = X_SIGNAL_LONG; + result.provider = X_CCI_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateCCILongConditions() { + // + int crossUnderBarIndex = + cciLongConds.crossUnderMinusHundredTime != 0 + ? iBarShift( + _Symbol, + _Period, + cciLongConds.crossUnderMinusHundredTime + ) + : -1 + ; + + // + int crossOverBarIndex = + cciLongConds.crossOverMinusHundredTime != 0 + ? iBarShift( + _Symbol, + _Period, + cciLongConds.crossOverMinusHundredTime + ) + : -1 + ; + + // + bool isConditionsFilled = + // + cciLongConds.start != 0 + && cciLongConds.crossUnderMinusHundredTime != 0 + && cciLongConds.crossOverMinusHundredTime != 0 + && cciLongConds.crossUnderMinusHundredTime >= cciLongConds.start + && cciLongConds.crossOverMinusHundredTime > cciLongConds.crossUnderMinusHundredTime + ; + + // + bool isLogicPassed = + // + crossOverBarIndex > 0 + && crossUnderBarIndex > 0 + && crossUnderBarIndex > crossOverBarIndex + && (crossUnderBarIndex - crossOverBarIndex) >= 5 + ; + + // + bool result = + // + isConditionsFilled + && isLogicPassed + && cciLongConds.crossOverSlope > 0 + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearCCILongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearCCILongSignalConditions() { + // + cciLongConds.start = 0; + cciLongConds.crossOverSlope = 0; + cciLongConds.crossOverMinusHundredTime = 0; + cciLongConds.crossUnderMinusHundredTime = 0; +} + +// +int GetHighestHighOfCCILongPeriodIndex() { + // + int crossUnderBarIndex = iBarShift( + _Symbol, + _Period, + cciLongConds.crossUnderMinusHundredTime + ); + + // + int crossOverBarIndex = iBarShift( + _Symbol, + _Period, + cciLongConds.crossOverMinusHundredTime + ); + + // + int result = iHighest( + _Symbol, + _Period, + MODE_HIGH, + crossUnderBarIndex - crossOverBarIndex, + crossOverBarIndex + ); + + // + return result; +} + +// +double GetHighestHighOfCCILongPeriod() { + // + int index = GetHighestHighOfCCILongPeriodIndex(); + + // + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + return result; +} + +// +int GetLowestLowOFCCILongPeriodIndex() { + // + int crossUnderBarIndex = iBarShift( + _Symbol, + _Period, + cciLongConds.crossUnderMinusHundredTime + ); + + // + int crossOverBarIndex = iBarShift( + _Symbol, + _Period, + cciLongConds.crossOverMinusHundredTime + ); + + // + int result = iLowest( + _Symbol, + _Period, + MODE_LOW, + crossUnderBarIndex - crossOverBarIndex, + crossOverBarIndex + ); + + // + return result; +} + +// +double GetLowestLowOFCCILongPeriod() { + // + int index = GetLowestLowOFCCILongPeriodIndex(); + + // + double result = iLow( + _Symbol, + _Period, + index + ); + + // + return result; +} + +// +// Check XMA State for Long Signals ... +bool IsReadyForCCILongSignals( + const XState &states[] +) { + // + bool result = false; + + // + XStateInfo info = ParseXMAStates(states); + + // + result = + // + true + // + // && states[1].mc.fast > states[1].mc.slow + // && MathAbs(states[1].mc.fast - states[1].mc.slow) > 100 * _Point + // && states[1].marketMiddleage > states[1].sc.fast + // && states[1].marketMiddleage > states[1].mc.fast + ; + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020428/Libraries/x-saherelm.draw.lib.mq4 b/Bkp/Used/14020428/Libraries/x-saherelm.draw.lib.mq4 new file mode 100644 index 0000000..08fefa7 --- /dev/null +++ b/Bkp/Used/14020428/Libraries/x-saherelm.draw.lib.mq4 @@ -0,0 +1,1670 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Start Arrow Functions ... +// +// +// Draw an Arrow Object on Chart ... +bool DrawArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // arrow name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const uchar arrowCode = OBJ_ARROW_UP, // arrow code + const ENUM_ARROW_ANCHOR anchor = ANCHOR_BOTTOM, // anchor point position + const color clr = clrAqua, // arrow color + const ENUM_LINE_STYLE style = STYLE_SOLID, // border line style + const int width = 3, // arrow size + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // Order Object ... +) { + // + // set anchor point coordinates if they are not set ... + ChangeArrowEmptyPoint(time, price); + + // + // reset the error value ... + ResetLastError(); + + // + // create an arrow ... + if(!ObjectCreate(chartID, name, OBJ_ARROW, subWindow, time, price)) { + // + string message = StringConcatenate(__FUNCTION__, + ": failed to create an arrow! Error code = ", + GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the arrow code ... + ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, arrowCode); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set the arrow color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set the border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set the arrow's size ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the arrow by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is false by default, if you want making it possible to highlight and move the object + // change it to true ... + ObjectSetInteger(chartID,name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point of Arrow ... +bool MoveArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if(!time) { + time = TimeCurrent(); + } + + // + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete an arrow ... +bool DeleteArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow" // arrow name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete an arrow ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete an arrow! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the arrow code ... +bool ArrowCodeChange( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + const uchar code = 252 // arrow code +) { + // + // reset the error value ... + ResetLastError(); + + // + // change the arrow code ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, code)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the arrow code! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change anchor type ... +bool ArrowAnchorChange( + const long chartID = 0, // chart's ID + const string name="Arrow", // object name + const ENUM_ARROW_ANCHOR anchor = ANCHOR_TOP // anchor type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change anchor type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change anchor type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeArrowEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } +} +// +// End Arrow Functions ... +// + +// +// Start Horizontal Line Functions ... +// +// +// Create, Draw the horizontal line ... +bool DrawHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + const int subWindow = 0, // subwindow index + double price = 0, // line price + const color clr = clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the price is not set, set it at the current Bid price level ... + if(!price) { + price=SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // create a horizontal line ... + if(!ObjectCreate(chartID, name, OBJ_HLINE, subWindow, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move horizontal line ... +bool MoveHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + double price = 0 // line price +) { + // + // if the line price is not set, move it to the current Bid price level ... + if(!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move a horizontal line ... + if(!ObjectMove(chartID, name, 0, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete a horizontal line ... +bool DeleteHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a horizontal line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End Horizontal Line Functions ... +// + +// +// Start Vertical Line Functions ... +// +// +// Create the vertical line ... +bool DrawVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + const int sub_window = 0, // subwindow index + datetime time = 0, // line time + const color clr=clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the line time is not set, draw it via the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value + ResetLastError(); + + // + // create a vertical line ... + if (!ObjectCreate(chartID, name, OBJ_VLINE, sub_window, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return true; +} + +// +// Move the vertical line ... +bool MoveVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + datetime time = 0 // line time +) { + // + // if line time is not set, move the line to the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the vertical line ... + if(!ObjectMove(chartID, name, 0, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the vertical line ... +bool DeleteVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the vertical line ... + if (!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // successful execution ... + return true; +} +// +// End Vertical Line Functions ... +// + +// +// Start RectangleLabel Functions ... +// +// +// Create Rectangle Label Object ... +bool DrawRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int subWindow = 0, // subwindow index + const int x = 0, // X coordinate + const int y = 0, // Y coordinate + const int width = 50, // width + const int height = 18, // height + const color back_clr = C'236,233,216', // background color + const ENUM_BORDER_TYPE border = BORDER_SUNKEN, // border type + const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring + const color clr = clrRed, // flat border color (Flat) + const ENUM_LINE_STYLE style = STYLE_SOLID, // flat border style + const int lineWidth = 1, // flat border width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // reset the error value ... + ResetLastError(); + + // + //--- create a rectangle label + if(!ObjectCreate(chartID, name, OBJ_RECTANGLE_LABEL, subWindow, 0, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set label coordinates ... + ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x); + ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y); + + // + // set label size ... + ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width); + ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height); + + // + // set background color ... + ObjectSetInteger(chartID, name, OBJPROP_BGCOLOR, back_clr); + + // + // set border type ... + ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border); + + // + // set the chart's corner, relative to which point coordinates are defined ... + ObjectSetInteger(chartID, name, OBJPROP_CORNER, corner); + + // + // set flat border color (in Flat mode) ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set flat border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set flat border width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, lineWidth); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the label by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move Rectangle Label .. +bool MoveRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int x = 0, // X coordinate + const int y=0 // Y coordinate +) { + // + // reset the error value ... + ResetLastError(); + + // + // move the rectangle label ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move X coordinate of the label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move Y coordinate of the label! Error code = ",GetLastError() + ); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the rectangle label ... +bool DeleteRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel" // label name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the label ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change Rectangle Label Size ... +bool ChangeSizeRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int width = 50, // label width + const int height = 18 // label height +) { + // + // reset the error value ... + ResetLastError(); + + // + // change label size ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's width! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's height! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change rectangle label border type ... +bool RectLabelChangeBorderType( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const ENUM_BORDER_TYPE border = BORDER_SUNKEN // border type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change border type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the border type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End RectangleLabel Functions ... +// + +// +// Start TrendLine Funcions ... +// +// Create a trend line by the given coordinates ... +bool DrawTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrYellow, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool rayRight = false, // line's continuation to the right + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeTrendLineEmptyPoints( + time1, + price1, + time2, + price2 + ); + + // + // reset the error value ... + ResetLastError(); + + // + // create a trend line by the given coordinates ... + if(!ObjectCreate(chartID, name, OBJ_TREND, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the line's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move trend line anchor point ... | +bool ChangeTrendLinePoint( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int pointindex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move trend line's anchor point ... + if(!ObjectMove(chartID, name, pointindex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// The function deletes the trend line from the chart ... +bool DeleteTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a trend line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of trend line's anchor points and set default ... +// values for empty ones ... +void ChangeTrendLineEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the first point's time is not set, it will be on the current bar ... + if (!time1) { + time1 = TimeCurrent(); + } + + // + // if the first point's price is not set, it will have Bid value ... + if (!price1) { + price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // if the second point's time is not set, it is located 9 bars left from the second one ... + if (!time2) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(), Period(), time1, 10, temp); + + // + // set the second point 9 bars left from the first one ... + time2 = temp[0]; + } + + // + // if the second point's price is not set, it is equal to the first point's one ... + if (!price2) { + price2 = price1; + } +} +// +// End TrendLine Functions ... +// + +// +// Start Text Functions ... +// +// Create and Draw a Text Object ... +bool DrawText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const string text = "Text", // the text itself + const string font = "Arial", // font + const int fontSize = 10, // font size + const color clr = clrRed, // color + const double angle = 0.0, // text slope + const ENUM_ANCHOR_POINT anchor = ANCHOR_CENTER, // anchor type + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor point coordinates if they are not set ... + ChangeTextEmptyPoint(time,price); + + // + // reset the error value ... + ResetLastError(); + + // + //--- create Text object + if(!ObjectCreate(chartID, name, OBJ_TEXT, subWindow, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the text ... + ObjectSetString(chartID, name , OBJPROP_TEXT, text); + + // + // set text font ... + ObjectSetString(chartID, name, OBJPROP_FONT, font); + + // + // set font size ... + ObjectSetInteger(chartID, name, OBJPROP_FONTSIZE, fontSize); + + // + // set the slope angle of the text ... + ObjectSetDouble(chartID, name, OBJPROP_ANGLE, angle); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the object by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID ,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point ... +bool MoveText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + //--- if point position is not set, move it to the current bar having Bid price + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point .. + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the object text ... +bool ChangeText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const string text = "Text" // text +) { + // + // reset the error value ... + ResetLastError(); + + // + // change object text ... + if(!ObjectSetString(chartID, name, OBJPROP_TEXT, text)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the text! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Text object ... +bool DeleteText( + const long chartID = 0, // chart's ID + const string name = "Text" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeTextEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + } +// +// End Text Functions ... +// + +// +// Start Fibonacchi Functions ... +// +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawFibonacci( + const long chartID = 0, // chart's ID + const string name="Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrRed, // object color + const ENUM_LINE_STYLE style = STYLE_SOLID, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawCustomFibonacci( + // + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + // + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrAqua, // object color + const ENUM_LINE_STYLE style = STYLE_DOT, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // Change Levels Of Fibonacci ... + bool result = FibonacciLevelsSet( + levels, + values, + colors, + styles, + widths, + descriptions, + chartID, + name + ); + + // + // successful execution ... + return result; +} + +// +// Set number of levels and their parameters ... +bool FibonacciLevelsSet( + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // check array sizes ... + if( + levels!=ArraySize(colors) || + levels!=ArraySize(styles) || + levels!=ArraySize(widths) || + levels!=ArraySize(widths) + ) { + // + string message = StringConcatenate( + __FUNCTION__, + ": array length does not correspond to the number of levels, error!" + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the number of levels ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELS, levels); + + // + // set the properties of levels in the loop ... + for(int i = 0; i < levels; i++) { + // + // level value ... + ObjectSetDouble(chartID, name, OBJPROP_LEVELVALUE, i, values[i]); + + // + // level color ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELCOLOR, i, colors[i]); + + // + // level style ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELSTYLE, i, styles[i]); + + // + // level width ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELWIDTH, i, widths[i]); + + // + // level description ... + // ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, DoubleToString(100 * values[i], 1)); + ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, descriptions[i]); + } + + // + // successful execution ... + return(true); +} + +// +// Move Fibonacci Retracement anchor point ... +bool FibonacciPointChange( + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int pointIndex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, pointIndex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Fibonacci Retracement ... +bool DeleteFibonachi( + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Fibonacci Retracement\"! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of Fibonacci Retracement anchor points and set +// default values for empty ones ... +void ChangeFibonacciEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the second point's time is not set, it will be on the current bar ... + if (!time2) { + time2 = TimeCurrent(); + } + + // + // if the second point's price is not set, it will have Bid value ... + if (!price2) { + price2 = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // if the first point's time is not set, it is located 9 bars left from the second one ... + if (!time1) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(),Period(),time2,10,temp); + + // + // set the first point 9 bars left from the second one ... + time1 = temp[0]; + } + + // + // if the first point's price is not set, move it 200 points below the second one ... + if (!price1) { + price1 = price2 - 200 * SymbolInfoDouble(_Symbol, SYMBOL_POINT); + } +} +// +// End Fibonacci Functions ... +// + + +// +// Start General Functions ... +// +// +// Remove all Drawn Objects ... +void RemoveDraws(const string &tag) { + // + for(int iObj=ObjectsTotal()-1; iObj >= 0; iObj--) { + // + string on = ObjectName(iObj); + if (StringFind(on, tag) == 0) { + ObjectDelete(on); + } + } +} +// +// End General Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020428/Libraries/x-saherelm.indicator.lib.mq4 b/Bkp/Used/14020428/Libraries/x-saherelm.indicator.lib.mq4 new file mode 100644 index 0000000..a5f3fd8 --- /dev/null +++ b/Bkp/Used/14020428/Libraries/x-saherelm.indicator.lib.mq4 @@ -0,0 +1,948 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Indicator Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +static double zigZags[]; +// +// END Global Requirement Functions ... +// + +// +// START Indicator Reading Data ... +// +// +// START XMKT Data ... +// +XMKTState GetXMKT( + const int bar_index, + const int marketLen, + // + const bool showHighestHigh = true, + const bool showHighestLow = true, + const bool showHighestOpen = true, + const bool showHighestClose = true, + const bool showLowestHigh = true, + const bool showLowestLow = true, + const bool showLowestOpen = true, + const bool showLowestClose = true, + const color highestHighColor = clrDeepPink, + const color highestLowColor = clrDarkOrange, + const color highestOpenColor = clrDodgerBlue, + const color highestCloseColor = clrOrchid, + const color lowestHighColor = clrHotPink, + const color lowestLowColor = clrOrange, + const color lowestOpenColor = clrPowderBlue, + const color lowestCloseColor = clrMediumOrchid, + const ENUM_LINE_STYLE highestHighStyle = STYLE_DOT, + const ENUM_LINE_STYLE highestLowStyle = STYLE_DOT, + const ENUM_LINE_STYLE highestOpenStyle = STYLE_DOT, + const ENUM_LINE_STYLE highestCloseStyle = STYLE_DOT, + const ENUM_LINE_STYLE lowestHighStyle = STYLE_DOT, + const ENUM_LINE_STYLE lowestLowStyle = STYLE_DOT, + const ENUM_LINE_STYLE lowestOpenStyle = STYLE_DOT, + const ENUM_LINE_STYLE lowestCloseStyle = STYLE_DOT +) { + // + XMKTState result = {}; + + // + string xmktIndName = "x-saherelm.xmarket"; + + // + int highestHighBufferIndex = 0; + int highestLowBufferIndex = 1; + int highestOpenBufferIndex = 2; + int highestCloseBufferIndex = 3; + int lowestHighBufferIndex = 4; + int lowestLowBufferIndex = 5; + int lowestOpenBufferIndex = 6; + int lowestCloseBufferIndex = 7; + + // + // Highest High ... + double highestHigh = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + highestHighBufferIndex, // Buffer Index ... + bar_index + ); + result.highestHigh = highestHigh; + + // + // Highest Low ... + double highestLow = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + highestLowBufferIndex, // Buffer Index ... + bar_index + ); + result.highestLow = highestLow; + + // + // Highest Open ... + double highestOpen = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + highestOpenBufferIndex, // Buffer Index ... + bar_index + ); + result.highestOpen = highestOpen; + + // + // Highest Close ... + double highestClose = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + highestCloseBufferIndex, // Buffer Index ... + bar_index + ); + result.highestClose = highestClose; + + // + // Lowest High ... + double lowestHigh = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + lowestHighBufferIndex, // Buffer Index ... + bar_index + ); + result.lowestHigh = lowestHigh; + + // + // Lowest Low ... + double lowestLow = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + lowestLowBufferIndex, // Buffer Index ... + bar_index + ); + result.lowestLow = lowestLow; + + // + // Lowest Open ... + double lowestOpen = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + lowestOpenBufferIndex, // Buffer Index ... + bar_index + ); + result.lowestOpen = lowestOpen; + + // + // Lowest Close ... + double lowestClose = iCustom( + _Symbol, + _Period, + xmktIndName, + // + // Inputs ... + marketLen, + showHighestHigh, + showHighestLow, + showHighestOpen, + showHighestClose, + showLowestHigh, + showLowestLow, + showLowestOpen, + showLowestClose, + highestHighColor, + highestLowColor, + highestOpenColor, + highestCloseColor, + lowestHighColor, + lowestLowColor, + lowestOpenColor, + lowestCloseColor, + highestHighStyle, + highestLowStyle, + highestOpenStyle, + highestCloseStyle, + lowestHighStyle, + lowestLowStyle, + lowestOpenStyle, + lowestCloseStyle, + // + lowestCloseBufferIndex, // Buffer Index ... + bar_index + ); + result.lowestClose = lowestClose; + + // + return result; +} +// +// END XMKT Data ... +// + +// +// START XOSC Data ... +// +XCycleState GetXOSC( + const int bar_index, + const int marketLen, + // + const int fastMult, + const int slowMult, + // + const double fastMMul = 1.0, + const double slowMMul = 3.0 +) { + // + XCycleState result = {}; + + // + string oscIndName = "x-saherelm.osc"; + + // + // Prepare OSC Inputs ... + // + int fastLength = fastMult * marketLen; + int slowLength = slowMult * marketLen; + + // + // Fast ... + double fast = iCustom( + _Symbol, + _Period, + oscIndName, + // + // Inputs ... + fastLength, + fastMMul, + slowLength, + slowMMul, + // + 0, // Buffer Index ... + bar_index + ); + result.fast = fast; + + // + // Slow ... + double slow = iCustom( + _Symbol, + _Period, + oscIndName, + // + // Inputs ... + fastLength, + fastMMul, + slowLength, + slowMMul, + // + 1, // Buffer Index ... + bar_index + ); + result.slow = slow; + + // + return result; +} +// +// END XOSC Data ... +// + +// +// START XBND Data ... +// +XBndState GetXBND( + const int bar_index, + // + const int marketLen = 10, // Market Length ... + const int shift = 0, // MA Shift ... + const ENUM_MA_METHOD method = MODE_SMA // MA Method ... +) { + // + XBndState result = {}; + + // + double high = GetMA( + bar_index, + marketLen, + shift, + method, + PRICE_HIGH + ); + result.high = high; + + // + double open = GetMA( + bar_index, + marketLen, + shift, + method, + PRICE_OPEN + ); + result.open = open; + + // + double close = GetMA( + bar_index, + marketLen, + shift, + method, + PRICE_CLOSE + ); + result.close = close; + + // + double low = GetMA( + bar_index, + marketLen, + shift, + method, + PRICE_LOW + ); + result.low = low; + + // + return result; +} +// +// END XBND Data ... +// + +// +// START ZigZag Data ... +// +void PrepareZigZagState( + const int bar_index, + // + const int depth = 12, + const int deviation = 5, + const int backStep = 3 +) { + // + string zigzagIndName = "x-saherelm.zigzag"; + + // + ArrayFree(zigZags); + ArrayResize( + zigZags, + 3 + ); + + // + double zigZag = 0; + int index = 0; + int i = bar_index; + while (index < 3) { + // + zigZag = iCustom( + _Symbol, + _Period, + zigzagIndName, + // + // Inputs ... + depth, + deviation, + backStep, + // + 0, // Buffer Index ... + i + ); + + // + if (zigZag > 0) { + // + zigZags[index] = zigZag; + index++; + } + + // + i++; + } +} +// +// END ZigZag Data ... +// + +// +// START XMA Data ... +// +// +// Retrieve Short Cycle ... +XCycleState GetXMASC( + const int bar_index, + const int marketLen, + const int fastMultiplier, + const int slowMultiplier, + // + const int shift = 0, + const ENUM_MA_METHOD method = MODE_SMA, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE +) { + // + XCycleState result = {}; + + // + int fastLength = marketLen * fastMultiplier; + int slowLength = marketLen * slowMultiplier; + + // + double fast = iMA( + _Symbol, + _Period, + fastLength, + shift, + method, + appliedPrice, + bar_index + ); + result.fast = fast; + + // + double slow = iMA( + _Symbol, + _Period, + slowLength, + shift, + method, + appliedPrice, + bar_index + ); + result.slow= slow; + + // + return result; +} + +// +// Retrieve Medium Cycle ... +XCycleState GetXMAMC( + const int bar_index, + const int marketLen, + const int fastMultiplier, + const int slowMultiplier, + // + const int shift = 0, + const ENUM_MA_METHOD method = MODE_SMA, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE +) { + // + XCycleState result = {}; + + // + int fastLength = marketLen * fastMultiplier; + int slowLength = marketLen * slowMultiplier; + + // + double fast = iMA( + _Symbol, + _Period, + fastLength, + shift, + method, + appliedPrice, + bar_index + ); + result.fast = fast; + + // + double slow = iMA( + _Symbol, + _Period, + slowLength, + shift, + method, + appliedPrice, + bar_index + ); + result.slow= slow; + + // + return result; +} + +// +// Retrieve Long Cycle ... +XCycleState GetXMALC( + const int bar_index, + const int marketLen, + const int fastMultiplier, + const int slowMultiplier, + // + const int shift = 0, + const ENUM_MA_METHOD method = MODE_SMA, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE +) { + // + XCycleState result = {}; + + // + int fastLength = marketLen * fastMultiplier; + int slowLength = marketLen * slowMultiplier; + + // + double fast = iMA( + _Symbol, + _Period, + fastLength, + shift, + method, + appliedPrice, + bar_index + ); + result.fast = fast; + + // + double slow = iMA( + _Symbol, + _Period, + slowLength, + shift, + method, + appliedPrice, + bar_index + ); + result.slow = slow; + + // + return result; +} + +// +// Retrieve Long Cycle ... +XCycleState GetXMANN( + const int bar_index, + // + const int shift = 0, + const ENUM_MA_METHOD method = MODE_SMA, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE +) { + // + XCycleState result = {}; + + // + int fastLength = 10; + int slowLength = 50; + + // + double fast = iMA( + _Symbol, + _Period, + fastLength, + shift, + method, + appliedPrice, + bar_index + ); + result.fast = fast; + + // + double slow = iMA( + _Symbol, + _Period, + slowLength, + shift, + method, + appliedPrice, + bar_index + ); + result.slow = slow; + + // + return result; +} + +// +// Retrieve Middle ... +double GetXMAMM( + const int bar_index, + const int marketLen, + const double multiplier, + // + const int shift = 0, + const ENUM_MA_METHOD method = MODE_EMA, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_MEDIAN +) { + // + double result = 0; + + // + int length = (int)(marketLen * multiplier); + + // + double middle = iMA( + _Symbol, + _Period, + length, + shift, + method, + appliedPrice, + bar_index + ); + result = middle; + + // + return result; +} + +// +// Retrieve XMA Parabolic SAR ... +double GetXMAPSAR( + const int bar_index, + // + double stp = 0.02, + double mxm = 0.2 +) { + // + double result = 0; + + // + double pSar = iSAR( + _Symbol, + _Period, + stp, + mxm, + bar_index + ); + result = pSar; + + // + return result; +} + +// +XState GetXState( + const int bar_index, + const int marketLen, + // + const double stp, + const double mxm, + // + const int shortCycleFastMult, + const int shortCycleSlowMult, + const int mediumCycleFastMult, + const int mediumCycleSlowMult, + const int longCycleFastMult, + const int longCycleSlowMult +) { + // + XState result = {}; + + // + // Short Cycle ... + XCycleState sc = GetXMASC( + bar_index, + marketLen, + shortCycleFastMult, + shortCycleSlowMult + ); + result.sc = sc; + + // + // Medium Cycle ... + XCycleState mc = GetXMAMC( + bar_index, + marketLen, + mediumCycleFastMult, + mediumCycleSlowMult + ); + result.mc = mc; + + // + // Long Cycle ... + XCycleState lc = GetXMALC( + bar_index, + marketLen, + longCycleFastMult, + longCycleSlowMult + ); + result.lc = lc; + + // // + // // OSC ... + // XCycleState osc = GetXOSC( + // // + // bar_index, + // marketLen, + // // + // shortCycleFastMult, + // shortCycleSlowMult + // ); + // result.osc = osc; + + // + // Market Middleage ... + double marketMiddleage = GetXMAMM( + bar_index, + marketLen, + 1.5 + ); + result.marketMiddleage = marketMiddleage; + + // + // Parabolic SAR ... + double parabolicSAR = GetXMAPSAR( + bar_index, + stp, + mxm + ); + result.parabolicSAR = parabolicSAR; + + // // + // int cciMarketLength = longCycleSlowMult * marketLen; + // double cci = GetMarketCCI( + // bar_index, + // cciMarketLength + // ); + // result.cci = cci; + + // + XBndState bnd = GetXBND( + bar_index + ); + result.bnd = bnd; + + // + XMKTState mkt = GetXMKT( + bar_index, + marketLen + ); + result.mkt = mkt; + + // + double longCycleHighestHigh = GetMarketHighestHigh( + bar_index, + longCycleFastMult * marketLen + ); + result.longCycleHighestHigh = longCycleHighestHigh; + + // + return result; +} +// +// END XMA Data ... +// +// +// END Indicator Reading Data ... +// diff --git a/Bkp/Used/14020428/Libraries/x-saherelm.lib.mq4 b/Bkp/Used/14020428/Libraries/x-saherelm.lib.mq4 new file mode 100644 index 0000000..658c90a --- /dev/null +++ b/Bkp/Used/14020428/Libraries/x-saherelm.lib.mq4 @@ -0,0 +1,1502 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +struct XOHCL { + double high; + double open; + double close; + double low; +}; + +// +static datetime lastBarTime; + +// +// START Functions ... +// + +// +// Determines current working is New Bar or not ... +bool IsNewBar() { + // + // Reading Last Bar Date ... + datetime curbar = (datetime)SeriesInfoInteger( + _Symbol, + _Period, + SERIES_LASTBAR_DATE + ); + + // + if(lastBarTime != curbar) { + // + lastBarTime = curbar; + return true; + } + + // + return false; +} + +// +// Determines we are in new Day or not ... +bool IsNewDay() { + // + bool result = false; + + // + // Reading Last Bar Date ... + datetime curbar = (datetime)SeriesInfoInteger( + _Symbol, + _Period, + SERIES_LASTBAR_DATE + ); + + // + if (lastBarTime == 0) { + lastBarTime = curbar; + } + + // + if (curbar == lastBarTime) { + return result; + } + + // + // Retrieve Day and Month and Year for Last Bar Time ... + int lastBarDay = TimeDay(lastBarTime); + int lastBarMonth = TimeMonth(lastBarTime); + int lastBarYear = TimeYear(lastBarTime); + + // + // Retrieve Day and Month and Year for Current Bar Time ... + int curBarDay = TimeDay(curbar); + int curBarMonth = TimeMonth(curbar); + int curBarYear = TimeYear(curbar); + + // + result = curBarDay > lastBarDay + || curBarMonth > lastBarMonth + || curBarYear > lastBarYear; + + // + return result; +} + +// +// Retrieve RMA on Specific Candle ... +double GetRMA( + int bar_index, + int length +) { + // + double shortSMA = iMA(_Symbol, _Period, length, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double mediumSMA = iMA(_Symbol, _Period, length * 2, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double longSMA = iMA(_Symbol, _Period, length * 3, 0, MODE_SMA, PRICE_CLOSE, bar_index); + + // + double result = longSMA - mediumSMA + shortSMA; + + // + return result; +} + +// +double GetMA( + const int bar_index, + const int maLength, + const int maShift, + const ENUM_MA_METHOD maMethod, + const ENUM_APPLIED_PRICE appliedPrice +) { + // + double result = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + appliedPrice, + bar_index + ); + + // + return result; +} + +// +// Retrieve True Range ... +double GetTR( + const int bar_index +) { + // + double result = 0; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double prevClose = iClose( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double highLowDif = high - low; + double hpCDif = MathAbs(high - prevClose); + double lpCDiff = MathAbs(low - prevClose); + + // + result = MathMax(highLowDif, hpCDif); + result = MathMax(result, lpCDiff); + + // + return result; +} + +// +// Calculate True Range Simple Moving Average ... +double GetMarketTRSMA( + const int bar_index, + const int marketLen +) { + // + double result = 0; + + // + // Create Barket Length Trs ... + double trs[]; + ArrayResize( + trs, + marketLen + ); + int index = 0; + double trSum = 0; + for (int i = bar_index; i < bar_index + marketLen; i++) { + // + double tr = GetTR(i); + trs[index] = tr; + + // + trSum += tr; + + // + index++; + } + + // + result = trSum / marketLen; + + // + return result; +} + +// +// Retrieve Commodity Channel ... +double GetMarketCCI( + const int bar_index, + const int marketLen, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE +) { + // + double result = 0; + + // + result = iCCI( + _Symbol, + _Period, + marketLen, + appliedPrice, + bar_index + ); + + // + return result; +} + +// +// this function check crossing up two Buffers ... +bool IsCrossedOver( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] > arr2[index1]) && !(arr1[index2] > arr2[index2]); + + // + return result; +} + +// +// this function check crossing down two Buffers ... +bool IsCrossedUnder( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] < arr2[index1]) && !(arr1[index2] < arr2[index2]); + + // + return result; +} + +// +// Convert points to Actual Point ... +double PointsToDouble(int points) { + // + double result = points * _Point; + return result; +} + +// +// Converts Pips to Points ... +int PipsToPoints(int pips) { + // + int result = pips * ((_Digits == 3 || _Digits == 5) ? 10 : 1); + return result; +} + +// +// Converts Pips to Double ... +double PipsToDouble(int pips) { + // + double result = PointsToDouble(PipsToPoints(pips)); + return result; +} + +// +// Converts Double Value to Pips ... +int PriceToPips(double value) { + // + if (value <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + int result = (int)(value / pipValue); + + // + return result; +} + +// +// Converts Pips to Double ... +double PipsToPrice(int pips) { + // + if (pips <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + double result = pipValue * pips; + + // + return result; +} + +// +// Generate ATR StopLoss Value ... +double CalculateATRSL( + int period, + double multiplier +) { + // + if (period <= 0 || multiplier <= 0) { + return 0; + } + + // + double atrValue = iATR( + _Symbol, + _Period, + period, + 0 + ); + + // + double result = atrValue * multiplier; + + // + return result; +} + +// +// Detect Candle Type ... +// Bullish => means close > open ... +bool IsBullishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBullishCandle( + open, + close + ); + + // + return result; +} + +bool IsBullishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open < close; + + // + return result; +} + +// +// Detect Candle Type ... +// Bearish => means close < open ... +bool IsBearishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBearishCandle( + open, + close + ); + + // + return result; +} + +bool IsBearishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open > close; + + // + return result; +} + +// +// Retrieve a Candle Info ... +XOHCL GetCandleModel( + const int bar_index +) { + // + XOHCL result = {}; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + result.high = high; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + result.open = open; + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + result.close = close; + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + result.low = low; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBullishDetected( + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double shpDetectMultipliers // Sharp Detect Multiplier +) { + // + bool result = false; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double minValue = 0; + double maxValue = 0; + int positionedLength = bar_index + marketLen; + + // + for (int i = bar_index; i < positionedLength; i++) { + // + double cHigh = iHigh( + _Symbol, + _Period, + i + ); + + // + double cLow = iLow( + _Symbol, + _Period, + i + ); + + // + minValue += MathMin(cLow, cHigh); + maxValue += MathMax(cLow, cHigh); + } + + // + double minAvg = minValue / positionedLength; + double maxAvg = maxValue / positionedLength; + + // + double shpValue = shpDetectMultipliers * _Point; + + // + result = (low - minAvg) > shpValue; + + // + int index = bar_index; + while ( + index < positionedLength + || !result + ) { + // + low = iLow( + _Symbol, + _Period, + index + ); + + // + result = result + || (low - minAvg) > shpValue; + + // + index++; + }; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBearishDetected( + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double shpDetectMultipliers // Sharp Detect Multiplier +) { + // + bool result = false; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double minValue = 0; + double maxValue = 0; + int positionedLength = bar_index + marketLen; + + // + for (int i = bar_index; i < positionedLength; i++) { + // + double cHigh = iHigh( + _Symbol, + _Period, + i + ); + + // + double cLow = iLow( + _Symbol, + _Period, + i + ); + + // + minValue += MathMin(cLow, cHigh); + maxValue += MathMax(cLow, cHigh); + } + + // + double minAvg = minValue / positionedLength; + double maxAvg = maxValue / positionedLength; + + // + double shpValue = shpDetectMultipliers * _Point; + + // + result = (high - maxAvg) > shpValue; + + // + int index = bar_index; + while ( + index < positionedLength + || !result + ) { + // + high = iHigh( + _Symbol, + _Period, + index + ); + + // + result = result + || (high - maxAvg) > shpValue; + + // + index++; + }; + + // + return result; +} + +// +// Retrieve Highest High Value based on Given Market ... +double GetMarketHighestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Low Value based on Given Market ... +double GetMarketHighestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Open Value based on Given Market ... +double GetMarketHighestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Close Value based on Given Market ... +double GetMarketHighestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Low Value based on Given Market ... +double GetMarketLowestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest High Value based on Given Market ... +double GetMarketLowestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Open Value based on Given Market ... +double GetMarketLowestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Close Value based on Given Market ... +double GetMarketLowestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// less than given price ... +double GetLowLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// great than given price ... +double GetLowGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// less than given price ... +double GetHighLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// great than given price ... +double GetHighGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// less than given price ... +double GetCloseLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// great than given price ... +double GetCloseGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Get Slope of a Line by it's two Point ... +double GetSlope( + double x1, + double y1, + double x2, + double y2 +) { + // + double result = (y2 - y1)/(x2 - x1); + return result; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020428/Libraries/x-saherelm.log.lib.mq4 b/Bkp/Used/14020428/Libraries/x-saherelm.log.lib.mq4 new file mode 100644 index 0000000..066b3f7 --- /dev/null +++ b/Bkp/Used/14020428/Libraries/x-saherelm.log.lib.mq4 @@ -0,0 +1,91 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Log Tag ... +static string logTag = ""; + +// +// Enable or Disable Logging ... +static bool enableLogging = false; + +// +// Start Log Messages ... +// + +// +// Logging a Message, specified for this EA ... +// using provided LogTag ... +void LogMessage(string message) { + // + if (!enableLogging) { + return; + } + + // + Print(logTag, " > ", message); +} + +// +// this used for logging series ... +void LogSeries( + double &series[], // which series to Log ... + int length = 0, // number of items to Log, 0 means all ... + int skip = 0 // number of items which skip before logging ... +) { + // + string msg = ""; + + // + int seriesSize = ArraySize(series); + if ( + skip < 0 + || length < 0 + || seriesSize == 0 + || skip > seriesSize + || skip + length > seriesSize + ) { + return; + } + + // + length = length == 0 ? + seriesSize : + length; + int start = skip > 1 ? + skip - 1 : + skip == 1 ? + 1 : + 0; + + // + // Loop through series items ... + for (int i = start; i < start + length; i++) { + // + msg += StringConcatenate( + "i[", i, "]: ", series[i], ", " + ); + } + + // + LogMessage(msg); +} +// +// End Log Messages ... +// + diff --git a/Bkp/Used/14020428/Libraries/x-saherelm.models.lib.mq4 b/Bkp/Used/14020428/Libraries/x-saherelm.models.lib.mq4 new file mode 100644 index 0000000..205e39a --- /dev/null +++ b/Bkp/Used/14020428/Libraries/x-saherelm.models.lib.mq4 @@ -0,0 +1,225 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Models Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// START STATIC Variables ... +// +// +static int totalSignals = 0; +static int totalLongSignals = 0; +static int totalShortSignals = 0; + +// +static double initialBalance = 0; + +// +static int countedBars = 0; +static bool isNewBar = false; +static bool isNewDay = false; +// +// END STATIC Variables ... +// + +// +// Start Models ... +// +// +// Signal Providers ... +enum ENUM_X_SIGNAL_PROVIDER { + X_UNKNOWN_PROVIDER, + X_OSC_PROVIDER, + X_CCI_PROVIDER, + X_SHP_PROVIDER, + X_XMA_PROVIDER, + X_RMA_PROVIDER, + X_XXX_PROVIDER +}; + +// +// these are different signal types ... +enum ENUM_X_SIGNAL_TYPE { + X_SIGNAL_NONE, + X_SIGNAL_LONG, + X_SIGNAL_SHORT, +}; + +// +// we Model each signals as this type ... +struct XSignal { + // + // Signal Symbol ... + string symbol; + + // + // Signal Type ... + ENUM_X_SIGNAL_TYPE type; + + // + // Signal ID ... + int id; + + // + // Signal Ticket Number, when Opening Trade ... + int ticket; + + // + // Signal Provider ... + ENUM_X_SIGNAL_PROVIDER provider; + + // + // Target Point ... + double tp; + + // + // Stop Loss ... + double sl; + + // + // Signal Entry Price ... + double entry; + + // + // Signalling Time ... + datetime time; + + // + // Signal Comments ... + string comment; +}; + +// +// this is Signal Request Response model ... +struct XSignalRequest { + bool hasSignal; + XSignal signal; + ENUM_X_SIGNAL_TYPE type; + ENUM_X_SIGNAL_PROVIDER provider; +}; + +// +struct XBndState { + double high; + double open; + double close; + double low; +}; + +// +struct XMKTState { + // + double highestHigh; + double highestLow; + double highestOpen; + double highestClose; + + // + double lowestHigh; + double lowestLow; + double lowestOpen; + double lowestClose; +}; + +// +struct XCycleState { + double fast; + double slow; +}; + +// +// Define a Model to Represent Snapshot of XMA Indicator ... +struct XState { + // + // SC ... + XCycleState sc; + + // + // MC ... + XCycleState mc; + + // + // LC ... + XCycleState lc; + + // + // OSC ... + // XCycleState osc; + + // + // MIDDLEAGE ... + double marketMiddleage; + + // + // PARABOLIC-SAR ... + double parabolicSAR; + + // + double cci; + + // + XBndState bnd; + + // + XMKTState mkt; + + // + double longCycleHighestHigh; +}; + +// +// Parsed XMA Buffer ... +struct XStateInfo { + // + // Check Market Cross Exists or not ... + // + bool isSCFastCrossOverSlow; + bool isSCFastCrossUnderSlow; + + // + double scMin; + double scMax; + + // + bool isMCFastCrossOverSlow; + bool isMCFastCrossUnderSlow; + + // + double mcMin; + double mcMax; + + bool isLCFastCrossOverSlow; + bool isLCFastCrossUnderSlow; + + // + double lcMin; + double lcMax; + + // + bool isMMCrossOverSCFast; + bool isMMCrossUnderSCFast; + + // + bool isMMCrossOverMCFast; + bool isMMCrossUnderMCFast; + + // + double mmMin; + double mmMax; +}; +// +// End Models ... +// diff --git a/Bkp/Used/14020428/Libraries/x-saherelm.osc.signal.lib.mq4 b/Bkp/Used/14020428/Libraries/x-saherelm.osc.signal.lib.mq4 new file mode 100644 index 0000000..84f0386 --- /dev/null +++ b/Bkp/Used/14020428/Libraries/x-saherelm.osc.signal.lib.mq4 @@ -0,0 +1,363 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 OSC Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// SHP Based Signal Conditions ... +struct XOSCLongSignalConditions { + // + datetime crossOverTime; + double slowOnCrossOver; + + // + datetime crossUnderTime; + double slowOnCrossUnder; +}; + +// +static XOSCLongSignalConditions oscLongConds; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill CC Signal Conditions ... +void CheckOSCLongSignalConditions( + const int bar_index, + const int marketLen, + // + double stp, + double mxm, + // + int scFMult, + int scSMult, + // + int mcFMult, + int mcSMult, + // + int lcFMult, + int lcSMult, + // + const double smoother = 5 +) { + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XState states[]; + ArrayResize( + states, + marketLen + ); + + // + int index = 0; + for (int i = bar_index; i < marketLen; i++) { + // + XState state = GetXState( + i, + marketLen, + // + stp, + mxm, + scFMult, + scSMult, + mcFMult, + mcSMult, + lcFMult, + lcSMult + ); + + // + states[index] = state; + + // + index++; + } + + // + bool isCrossUnder = + states[0].osc.fast < 0 + && !(states[1].osc.fast < 0) + ; + + // + bool isCrossOver = + states[0].osc.fast > 0 + && !(states[1].osc.fast > 0) + ; + + // + int oneTouches = 0; + int halfTouches = 0; + int minusOneTouches = 0; + for (int i = 0; i < marketLen - 1; i++) { + // + // One Touches ... + if ( + states[i].osc.fast > 1 + && !(states[i + 1].osc.fast > 1) + ) { + oneTouches++; + } + + // + // Half Touches ... + if ( + states[i].osc.fast > 0.5 + && !(states[i + 1].osc.fast > 0.5) + ) { + halfTouches++; + } + + // + // Minus One Touches ... + if ( + states[i].osc.fast < -1 + && !(states[i + 1].osc.fast < -1) + ) { + minusOneTouches++; + } + } + + // + if ( + isCrossUnder + && oscLongConds.crossUnderTime == 0 + ) { + // + oscLongConds.crossUnderTime = barTime; + oscLongConds.slowOnCrossUnder = states[0].osc.slow; + return; + } + + // + if ( + isCrossOver + && oscLongConds.crossUnderTime > 0 + && oscLongConds.crossOverTime == 0 + ) { + // + oscLongConds.crossOverTime = barTime; + oscLongConds.slowOnCrossOver = states[0].osc.slow; + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateOSCLongSignal( + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r // Risk to Reward ratio ... +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if (!ValidateOSCLongConditions()) { + return result; + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double entryPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double exitPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + GetMarketLowestLow( + bar_index, + marketLen + ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = MathMin(openPrice, closePrice) - ll; + double reward = risk * r2r; // 300 * _Point; + + // + double sl = 0; // ll; + double tp = entryPrice + reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = X_SIGNAL_LONG; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_OSC_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = X_SIGNAL_LONG; + result.provider = X_OSC_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateOSCLongConditions() { + // + bool isConditionsFilled = + oscLongConds.crossOverTime > 0 + && oscLongConds.crossUnderTime > 0 + && oscLongConds.slowOnCrossOver > 0 + && oscLongConds.slowOnCrossUnder > 0 + && oscLongConds.crossOverTime > oscLongConds.crossUnderTime + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int crossUnderBarIndex = iBarShift( + _Symbol, + _Period, + oscLongConds.crossUnderTime + ); + + // + int crossOverBarIndex = iBarShift( + _Symbol, + _Period, + oscLongConds.crossOverTime + ); + + // + isBLFilled = + crossUnderBarIndex > crossOverBarIndex + // && oscLongConds.slowOnCrossOver > oscLongConds.slowOnCrossUnder + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearOSCLongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearOSCLongSignalConditions() { + // + oscLongConds.crossOverTime = 0;; + oscLongConds.crossUnderTime = 0;; +} + +// +// Check State for Long Signals ... +bool IsReadyForOSCLongSignals( + const XSignal &signal, + const XState &states[] +) { + // + bool result = false; + + // + result = + // + true + ; + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020428/Libraries/x-saherelm.rma.signal.lib.mq4 b/Bkp/Used/14020428/Libraries/x-saherelm.rma.signal.lib.mq4 new file mode 100644 index 0000000..4b9637a --- /dev/null +++ b/Bkp/Used/14020428/Libraries/x-saherelm.rma.signal.lib.mq4 @@ -0,0 +1,363 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 RMA Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// RMA Based Signal Conditions ... +struct XRMALongSignalConditions { + // + datetime crossUnderTime; + + // + datetime crossOverTime; +}; + +// +static XRMALongSignalConditions xrmaLongConds; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill CC Signal Conditions ... +void CheckXRMALongSignalConditions( + const int bar_index, + const int marketLen, + // + const double smoother = 5 +) { + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XCycleState states[]; + ArrayResize( + states, + marketLen + ); + + // + int index = 0; + for (int i = bar_index; i < marketLen; i++) { + // + XCycleState state = GetXMANN(i); + + // + states[index] = state; + + // + index++; + } + + // + bool isCrossUnder = + states[1].fast < states[1].slow + && !(states[2].fast < states[2].slow) + ; + + // + bool isCrossOver = + states[1].fast > states[1].slow + && !(states[2].fast > states[2].slow) + ; + + // + if ( + isCrossUnder + && xrmaLongConds.crossUnderTime == 0 + ) { + // + xrmaLongConds.crossUnderTime = barTime; + return; + } + + // + if ( + isCrossOver + && xrmaLongConds.crossUnderTime > 0 + && xrmaLongConds.crossOverTime == 0 + ) { + // + xrmaLongConds.crossOverTime = barTime; + return; + } +} + +// +// Convert XMA Long Signal Conditions to XSignal ... +XSignalRequest GenerateXRMALongSignal( + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r // Risk to Reward ratio ... +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if (!ValidateXRMALongConditions(marketLen)) { + return result; + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double entryPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double exitPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + GetMarketLowestLow( + bar_index, + marketLen + ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = MathMin(openPrice, closePrice) - ll; + double reward = risk * r2r; // 300 * _Point; + + // + double sl = 0; // entryPrice - (300 * _Point); // ll; + double tp = entryPrice + reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = X_SIGNAL_LONG; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_RMA_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = X_SIGNAL_LONG; + result.provider = X_RMA_PROVIDER; + + // + return result; +} + +// +// Validate XMA Signal Conditions ... +bool ValidateXRMALongConditions( + const int marketLen +) { + // + bool isConditionsFilled = + true + && xrmaLongConds.crossOverTime > 0 + && xrmaLongConds.crossUnderTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int crossOverBarIndex = iBarShift( + _Symbol, + _Period, + xrmaLongConds.crossOverTime + ); + + // + int crossUnderBarIndex = iBarShift( + _Symbol, + _Period, + xrmaLongConds.crossUnderTime + ); + + // + XCycleState stateOnCrossUnder = GetXMANN( + crossUnderBarIndex + ); + + // + XCycleState stateOnCrossOver = GetXMANN( + crossOverBarIndex + ); + + // + double maC = iMA( + _Symbol, + _Period, + 14, + 0, + MODE_SMA, + PRICE_CLOSE, + crossOverBarIndex + ); + + // // + // double rmaOnCrossOver = GetRMA( + // crossOverBarIndex, + // 10 + // ); + + // // + // double rmaOnMarketLength = GetRMA( + // crossOverBarIndex + marketLen, + // 10 + // ); + + // // + // double prevCandleHigh = iHigh( + // _Symbol, + // _Period, + // crossOverBarIndex + // ); + + // // + // PrepareZigZagState(crossOverBarIndex); + // double zigZagDelta = zigZags[1] - zigZags[2]; + // bool isZigZagWaitForHigh = zigZagDelta < 0; + + // + isBLFilled = + true + // + && (crossUnderBarIndex - crossOverBarIndex) > 5 + // + && xrmaLongConds.crossOverTime > xrmaLongConds.crossUnderTime + // + && stateOnCrossOver.slow < stateOnCrossUnder.slow + // + && MathAbs(stateOnCrossOver.fast - stateOnCrossOver.slow) > (70 * _Point) + // + && maC >= stateOnCrossOver.slow + // // + // && !(rmaOnCrossOver < stateOnCrossOver.slow) + // // + // && MathAbs(rmaOnCrossOver - rmaOnMarketLength) < (600 * _Point) + // // + // && !isZigZagWaitForHigh + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXRMALongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXRMALongSignalConditions() { + // + xrmaLongConds.crossOverTime = 0; + xrmaLongConds.crossUnderTime = 0; +} + +// +// Check XMA State for Long Signals ... +bool IsReadyForXRMALongSignals( + const XSignal &signal, + const XState &states[], + const int marketLen +) { + // + bool result = false; + + // + result = + // + true + ; + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020428/Libraries/x-saherelm.shp.signal.lib.mq4 b/Bkp/Used/14020428/Libraries/x-saherelm.shp.signal.lib.mq4 new file mode 100644 index 0000000..dd0f767 --- /dev/null +++ b/Bkp/Used/14020428/Libraries/x-saherelm.shp.signal.lib.mq4 @@ -0,0 +1,391 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 SHP Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// SHP Based Signal Conditions ... +struct XSHPLongSignalConditions { + // + datetime start; + datetime stop; +}; + +// +static XSHPLongSignalConditions shpLongConds; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill CC Signal Conditions ... +void CheckSHPLongSignalConditions( + const int bar_index, + const int marketLen, + const double shpDetectMult, + const double smoother = 30 +) { + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double mHH = GetMarketHighestHigh( + bar_index, + marketLen + ); + + // + double mLL = GetMarketLowestLow( + bar_index, + marketLen + ); + + double m2LL = GetMarketLowestLow( + bar_index, + marketLen * 2 + ); + + // + int mHLIdx = iHighest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + datetime mHLTime = iTime( + _Symbol, + _Period, + mHLIdx + ); + double mHL = iHigh( + _Symbol, + _Period, + mHLIdx + ); + + // + double hlDiff = (mHL - mLL); + double sharpDetectValue = shpDetectMult * _Point; + + // + bool isSharpDetected = + // ( + // low == mLL + // || MathAbs(mLL - low) < (smoother * _Point) + // ) + // && + // !( + // mLL > m2LL + // && MathAbs(m2LL - mLL) > sharpDetectValue / 2 + // ) + // && + ( + hlDiff > sharpDetectValue + || hlDiff > sharpDetectValue - (smoother * _Point) + ) + ; + + // + if (isSharpDetected) { + // + shpLongConds.start = mHLTime; + shpLongConds.stop = barTime; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateSHPLongSignal( + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r, // Risk to Reward ratio ... + const double shpDetectMultiplier // Sharp Detect Multiplier ... +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if (!ValidateSHPLongConditions(shpDetectMultiplier)) { + return result; + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double entryPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double exitPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + GetMarketLowestLow( + bar_index, + marketLen + ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = MathMin(openPrice, closePrice) - ll; + double reward = 300 * _Point; // risk * r2r; + + // + double sl = 0; // ll; + + // + // this means Market Lowest Low ... + double shpValue = shpDetectMultiplier * _Point; + if ( + reward == 0 + || reward < 20 * _Point + ) { + reward = shpValue; + } + double tp = entryPrice + reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = X_SIGNAL_LONG; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_SHP_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = X_SIGNAL_LONG; + result.provider = X_SHP_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateSHPLongConditions( + const double shpDetectMultiplier +) { + // + double shpDetectValue = shpDetectMultiplier * _Point; + + // + bool isConditionsFilled = + shpLongConds.stop != 0 + && shpLongConds.start != 0 + && shpLongConds.stop > shpLongConds.start + ; + + // + bool isBLFilled = true; + + // + bool result = + isBLFilled + && isConditionsFilled + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearSHPLongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearSHPLongSignalConditions() { + // + shpLongConds.stop = 0; + shpLongConds.start = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForSHPLongSignals( + const XSignal &signal, + const XState &states[] +) { + // + bool result = false; + + // + XStateInfo info = ParseXMAStates(states); + + // + int xmaMarketLen = ArraySize(states); + double mHH = GetMarketHighestHigh(0, xmaMarketLen); + double m2HH = GetMarketHighestHigh(0, (int) (xmaMarketLen * 1.5)); + + // + int lcUpDownTouches = 0; + int cciHundredTouches = 0; + for (int i = 0; i < xmaMarketLen; i++) { + // + double high = iHigh( + _Symbol, + _Period, + i + ); + + // + double low = iLow( + _Symbol, + _Period, + i + ); + + // + double up = MathMax(states[i].lc.fast, states[i].lc.slow); + double down = MathMax(states[i].lc.fast, states[i].lc.slow); + + // + if (high >= up && low <= down) { + lcUpDownTouches++; + } + + // + if ( + i < xmaMarketLen - 1 + && i < 10 + ) { + if ( + states[i].cci < 100 + && states[i + 1].cci > 100 + ) { + cciHundredTouches++; + } + } + } + + // + result = + // + true + // + && states[0].mc.fast > states[0].mc.slow + && states[0].lc.fast > states[0].lc.slow + // + && states[0].sc.fast < states[0].sc.slow + && states[1].sc.fast < states[1].sc.slow + // + && states[0].marketMiddleage < states[0].sc.fast + && states[1].marketMiddleage < states[1].sc.fast + && !( + states[1].sc.fast < states[1].mc.fast + && states[1].sc.slow < states[1].mc.fast + && states[1].sc.fast > states[1].mc.slow + && states[1].sc.slow > states[1].mc.slow + ) + && !( + states[0].marketMiddleage < states[0].mc.fast + && states[0].marketMiddleage > states[0].mc.slow + ) + // + && mHH != m2HH + && lcUpDownTouches == 0 + && cciHundredTouches == 0 + ; + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020428/Libraries/x-saherelm.signal.lib.mq4 b/Bkp/Used/14020428/Libraries/x-saherelm.signal.lib.mq4 new file mode 100644 index 0000000..2b4fa56 --- /dev/null +++ b/Bkp/Used/14020428/Libraries/x-saherelm.signal.lib.mq4 @@ -0,0 +1,1456 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Signal Draw Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +#include "../Libraries/x-saherelm.x.signal.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// END Global Requirement Functions ... +// + +// +// START Signal Related Functions ... +// +// +// Retrieve Signal Bar Index ... +int GetSignalBarIndex(XSignal &signal) { + // + // Temp Result ... + int result = -1; + + // + // Retriev Signal Bar Index ... + result = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + return result; +} + +// +string GetProviderIdentifier( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + string result = ""; + + // + switch (provider) + { + case X_XXX_PROVIDER: + result = "XXX"; + break; + + default: + result = ""; + break; + } + + // + return result; +} + +// +ENUM_X_SIGNAL_PROVIDER GetProvider(string identifier) { + // + ENUM_X_SIGNAL_PROVIDER result = X_UNKNOWN_PROVIDER; + + // + if ( + StringFind( + identifier, + GetProviderIdentifier(X_XXX_PROVIDER) + ) > -1 + ) { + result = X_XXX_PROVIDER; + } + + // + return result; +} + +// +// Draw Signal Shapes on Chart ... +bool DrawSignal( + const XSignal &signal, + long chartID = 0, + int subWindowID = 0, + const double positionThresholdFactor = 10, + string signalTag = "X-Signal", + string longSignalLabel = "X-Long", + color longSignalColor = clrAqua, + string shortSignalLabel = "X-Short", + color shortSignalColor = clrFuchsia +) { + // + // Generate isLongSignal Var ... + bool isLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Signal Bar Index ... + int bar_index = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // START Draw Signal Arrow ... + // + // + // Arrow Shape Name ... + string arrowName = StringConcatenate(signalTag, "_Arrow_", signal.id); + + // + // Arrow Price ... + double arrowPrice = 0; + if (isLongSignal) { + // + arrowPrice = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice - (positionThresholdFactor * _Point); + } else { + // + arrowPrice = iHigh( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice + (positionThresholdFactor * _Point); + } + + // + // Arrow Code ... + uchar arrowCode = isLongSignal ? SYMBOL_ARROWUP : SYMBOL_ARROWDOWN; + + // + // Arrow Anchor Point ... + ENUM_ARROW_ANCHOR arrowAnchorPoint = isLongSignal ? ANCHOR_BOTTOM : ANCHOR_TOP; + + // + // Arrow Color ... + color arrowColor = isLongSignal ? longSignalColor : shortSignalColor; + + // + // Draw Signal Arrow Shape ... + bool result = DrawArrow( + chartID, + arrowName, + subWindowID, + signal.time, + arrowPrice, + arrowCode, + arrowAnchorPoint, + arrowColor + ); + // + // END Draw Signal Arrow ... + // + + // + // START Draw Signal SL/TP ... + // + string slLineName = StringConcatenate(signalTag, "_SL_", signal.id); + string tpLineName = StringConcatenate(signalTag, "_TP_", signal.id); + string entryLineName = StringConcatenate(signalTag, "_ENTRY_", signal.id); + + // + color slColor = shortSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color tpColor = longSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color entryColor = clrGreen; + + // + datetime time1 = iTime( + _Symbol, + _Period, + bar_index + 1 + ); + + // + // Draw Enrty Price ... + result = DrawTrendLine( + chartID, + entryLineName, + subWindowID, + time1, + signal.entry, + signal.time, + signal.entry, + entryColor, + STYLE_SOLID, + 2 + ); + + // + // Draw Signal SL ... + if (signal.sl > 0) { + // + result = DrawTrendLine( + chartID, + slLineName, + subWindowID, + time1, + signal.sl, + signal.time, + signal.sl, + slColor, + STYLE_SOLID, + 2 + ); + } + + // + // Draw Signal TP ... + if (signal.tp > 0) { + // + result = DrawTrendLine( + chartID, + tpLineName, + subWindowID, + time1, + signal.tp, + signal.time, + signal.tp, + tpColor, + STYLE_SOLID, + 2 + ); + } + // + // END Draw Signal SL/TP ... + // + + // + // Start Draw Signal Label ... + // + // + string labelName = StringConcatenate(signalTag, "_Label_", signal.id); + + // + double labelPrice = isLongSignal ? arrowPrice - (positionThresholdFactor * _Point) : arrowPrice + (positionThresholdFactor * _Point); + + // + string labelText = isLongSignal ? longSignalLabel : shortSignalLabel; + labelText = StringConcatenate( + labelText, + "_", + GetProviderIdentifier(signal.provider) + ); + + // + result = DrawText( + chartID, + labelName, + subWindowID, + signal.time, + labelPrice, + labelText, + "Arial", + 8, + arrowColor, + 0, + ANCHOR_CENTER + ); + // + // End Draw Signal Label ... + // + + // + return result; +} + +// +// Trade on Specific Signal ... +bool TradeSignal( + XSignal &signal, + // + string prefix, + // + double volumePercent, + // + // Long ... + const string longSignalLabel, + const color longSignalColor, + // + // Short ... + const string shortSignalLabel, + const color shortSignalColor +) { + // + // Temp Result ... + bool result = false; + + // + if (initialBalance == 0) { + initialBalance = AccountInfoDouble(ACCOUNT_BALANCE); + } + + // + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + int openPositions = CountOpenTrades(); + double volume = (volumePercent * initialBalance); + + // + if ( + signal.type != X_SIGNAL_LONG && + signal.type != X_SIGNAL_SHORT + ) { + return result; + } + + // + bool hasLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Check TP and Entry Price ... + if ( + ( + hasLongSignal + && signal.entry > signal.tp + ) || + ( + !hasLongSignal + && signal.entry < signal.tp + ) + ) { + return result; + } + + // + // Order Operation ... + int operation = hasLongSignal ? + OP_BUY : + OP_SELL; + + // + // Detect Trade Color ... + color clr = hasLongSignal ? + longSignalColor : + shortSignalColor; + + // + // Generate Signal Comment ... + string label = hasLongSignal ? + longSignalLabel : + shortSignalLabel; + + // + // Generate Signal Comment ... + string comment = StringConcatenate( + prefix, + "_", signal.id, + "_", GetProviderIdentifier(signal.provider), + "_", label + ); + + // + // Placing Order ... + int orderTicket = OrderSend( + _Symbol, + operation, + volume, + signal.entry, + 3, + signal.sl, + signal.tp, + comment, + signal.id, + 0, + clr + ); + + // + // Draw Signal Shape if Order Opened Successfully ... + if (orderTicket >= 0) { + // + signal.ticket = orderTicket; + + // + // Here i must to Draw Signal Shapes ... + bool isDrawn = DrawSignal( + signal, + 0, + 0, + 50, + prefix, // Signal Tag ... + longSignalLabel, // Long Signal Label ... + longSignalColor, + shortSignalLabel, // Short Signal Label ... + shortSignalColor + ); + + // + LogMessage( + StringConcatenate( + "Order [", orderTicket ,"]: Provided by: ", GetProviderIdentifier(signal.provider) + ) + ); + + // + // TODO: here we have to check if there are another + // open positions which their entry price is bigger + // than current signal entry price, for long trades and + // their tp is high than current tp, ... + // close in profit trades or modify orders tp to current ... + // // + // if (CountOpenTrades() > 0) { + // // + // // Here we have to + // // ModifyOpenTradesBasedOnCurrentTrade(signal); + // } + + // + result = true; + } + + // + return result; +} +// +// END Signal Related Functions ... +// + +// +// START Orders Functions ... +// +// +// Convert To XSignal Model ... +XSignal OrderToSignal() { + // + // Temp Result ... + XSignal result = {}; + result.type = X_SIGNAL_NONE; + + // + // Here we can get some usefull info based on selected order ... + double swap = OrderSwap(); + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + int magicNumber = OrderMagicNumber(); + double takeProfit = OrderTakeProfit(); + string comment = OrderComment(); + + // + ENUM_X_SIGNAL_PROVIDER provider = GetProvider(comment); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // Conver Position to Signal ... + result.sl = stopLoss; + result.tp = takeProfit; + result.time = openTime; + result.symbol = _Symbol; + result.id = magicNumber; + result.comment = comment; + result.entry = openPrice; + result.provider = provider; + result.type = isLongOrder ? X_SIGNAL_LONG : X_SIGNAL_SHORT; + + // + return result; +} + +// +// START Count Orders ... +// +// +// Count Open Positions ... +int CountOpenTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if (OrderSymbol() == _Symbol) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Long Positions ... +int CountOpenLongTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_BUY + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Short Positions ... +int CountOpenShortTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_SELL + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} +// +// END Count Orders ... +// + +// +// START Close Orders ... +// +// +// Close All Open Trades ... +bool CloseAllTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + + // + return result; +} + +// +bool CloseAllProviderLongTrades( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal(); + + // + if (signal.provider == provider) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Long Trades ... +bool CloseAllLongTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Long Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Short Trades ... +bool CloseAllShortTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (!isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Short Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In Profit Trades ... +bool CloseAllInProfitTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit > 0 + && profit > 50 * _Point + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InProfit Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In DrawDown Trades ... +bool CloseAllInDrawDownTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if (profit < 0) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close Biggest In DrawDown Trades ... +bool CloseBiggestDrawDownTrade() { + // + // Loop through all Positions ... + bool result = false; + double drawDown = 0; + + // + // Find Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) > drawDown + ) { + drawDown = profit; + } + } + } + } + + // + // Close Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) >= drawDown + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Max InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Long Time Trades ... +bool CloseAllLongTimeTrades( + const int passedCandles +) { + // + bool result = false; + + // + if (passedCandles <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + + // + if ( + openBarIndex - currentBarIndex >= passedCandles + || ( + profit > 0.5 + && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 3) + ) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Long Time issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } else if ( + openTrades > 0 + && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 2) + ) { + // result = CloseAllInProfitTrades(); + // && CloseBiggestDrawDownTrade(); + } + } + } + } + + // + return result; +} + +// +// Close all trades which passed Maximum Drawdown ... +bool CloseAllMaximumDrawDownPassedTrades( + const double maxDrDownPercentPerPTrade +) { + // + if ( + initialBalance <= 0 + || maxDrDownPercentPerPTrade <= 0 + ) { + return false; + } + + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double maxAllowedDrawDown = -1 * (initialBalance * maxDrDownPercentPerPTrade); + + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + if ( + profit < 0 + && MathAbs(profit) >= MathAbs(maxAllowedDrawDown) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Maximum DarwDown issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Trades Which Opens before Specified Length ... +bool CloseAllTradesWhichOpenInPastMarketLength( + const int marketLen +) { + // + bool result = false; + + // + if (marketLen <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + + // + if (openBarIndex <= currentBarIndex + marketLen) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Market Reverse issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } else if (openTrades > 0) { + // + // Close all InProfit Trdes and Biggest InDrawDown Trades ... + // result = CloseAllInProfitTrades(); + // && CloseBiggestDrawDownTrade(); + } + } + } + } + + // + return result; +} +// +// END Close Orders ... +// + +// +// START Modify Orders ... +// +// +void ModifyAllPriceLesserOpenTrades( + const XSignal &signal +) { + // + // Loop through all Open Trades ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + double takeProfit = OrderTakeProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // When new Signal Comming with price less than + // currently open trade and tp less than currently + // open trade, this means a market change happens ... + // here we can Close InProfit Trades or Modify Trades TP ... + if ( + openPrice < signal.entry + && takeProfit > signal.tp + ) { + bool result = OrderModify( + ticket, + openPrice, + signal.sl, + signal.tp, + clrYellow + ); + } + } + } + } +} + +// +void ModifyOpenTradesBasedOnCurrentTrade( + const XSignal &signal +) { + // + ModifyAllPriceLesserOpenTrades(signal); +} +// +// END Modify Orders ... +// +// +// END Orders Functions ... +// + +// +// START Signal Conditions ... +// +// +// Clear Signal Conditions ... +void ClearSignalConditions() { + // + ClearLongSignalConditions(); + ClearShortSignalConditions(); +} + +// +// Clear all Conditions Waiter for Long Signals ... +void ClearLongSignalConditions() { + // + ClearXLongSignalConditions(); + // + // ClearOSCLongSignalConditions(); + // ClearCCILongSignalConditions(); + // ClearSHPLongSignalConditions(); + // ClearXRMALongSignalConditions(); + // // + // ClearXMASCLongSignalConditions(); + // ClearXMAMCLongSignalConditions(); + // ClearXMAMMLongSignalConditions(); +} + +// +// Clear all Conditions Waiter for Short Signals ... +void ClearShortSignalConditions() { +} +// +// END Signal Conditions ... +// diff --git a/Bkp/Used/14020428/Libraries/x-saherelm.x.signal.lib.mq4 b/Bkp/Used/14020428/Libraries/x-saherelm.x.signal.lib.mq4 new file mode 100644 index 0000000..755df37 --- /dev/null +++ b/Bkp/Used/14020428/Libraries/x-saherelm.x.signal.lib.mq4 @@ -0,0 +1,678 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 X Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// X Based Signal Conditions ... +struct XSignalConditions { + datetime startTime; + datetime signalTime; +}; + +// +static XSignalConditions xLongConds; +static XSignalConditions xShortConds; + +// +static bool xCloseLongTrades = false; +static bool xWaitForLongSignals = true; +static datetime xWaitForLongSignalChangeTime; + +// +static bool xWaitForShortSignals = true; +static bool xCloseShortTrades = false; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long Signal Conditions ... +void CheckXLongSignalConditions( + const int bar_index, + const int marketLen, + const XState &states[], + // + const double smoother = 5 +) { + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // // + // bool isCrossUnder = + // states[1].osc.fast < states[1].osc.slow + // && !(states[2].osc.fast < states[2].osc.slow) + // ; + + // // + // bool isCrossOver = + // states[1].osc.fast > states[1].osc.slow + // && !(states[2].osc.fast > states[2].osc.slow) + // ; + + // + XOHCL pCandle = GetCandleModel(1); + + // // + // bool isTrendingUp = + // pCandle.low > states[0].bnd.high + // && pCandle.high > states[0].bnd.high; + + // // + // bool isTrendingDown = + // pCandle.high < states[0].bnd.low + // && pCandle.low < states[0].bnd.low; + + // + bool isTrendingUp = + states[1].bnd.open < states[1].bnd.close + && !(states[2].bnd.open < states[2].bnd.close) + ; + + // + bool isTrendingDown = + states[1].bnd.open > states[1].bnd.close + && !(states[2].bnd.open > states[2].bnd.close) + ; + + // + bool isCrossUnder = + isTrendingDown + && !isTrendingUp + ; + + // + bool isCrossOver = + isTrendingUp + && !isTrendingDown + ; + + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + if (xWaitForLongSignals) { + // + bool isLCFastOnTrendingUpTouchLowestLow = + // + // LC Trending Up ... + states[1].lc.fast > states[1].lc.slow + && states[2].lc.fast > states[2].lc.slow + // + // LC Fast Touch Market Lowest Low ... + && states[1].lc.fast > states[1].mkt.lowestLow + && !(states[2].lc.fast > states[2].mkt.lowestLow) + ; + + // + bool isMCSlowCrossOverBNDHigh = + states[1].mc.fast > states[1].mc.slow + && states[1].mc.slow > states[1].bnd.high + && !(states[2].mc.slow > states[2].bnd.high) + ; + + // + // Disable Long Trade Handlers ... + if ( + isMCSlowCrossOverBNDHigh + || isLCFastOnTrendingUpTouchLowestLow + ) { + // + xWaitForLongSignals = false; + xWaitForLongSignalChangeTime = TimeCurrent(); + LogMessage("Disable Long ..."); + } + } else { + // + bool isAllTrendingUp = + // + // SC ... + states[1].sc.fast > states[1].sc.slow + // + // MC ... + && states[1].mc.fast > states[1].mc.slow + && !(states[2].mc.fast > states[2].mc.slow) + // + // LC ... + && states[1].lc.fast > states[1].lc.slow + ; + + // + int lastWaitChangeBarIndex = iBarShift( + _Symbol, + _Period, + xWaitForLongSignalChangeTime + ); + + // + // Enable Long Trade Handlers ... + if ( + isAllTrendingUp + && lastWaitChangeBarIndex - bar_index >= marketLen + ) { + xWaitForLongSignals = true; + LogMessage("Enable Long ..."); + } + } + + // + if ( + isCrossUnder + && xLongConds.startTime == 0 + ) { + // + xLongConds.startTime = barTime; + return; + } + + // + if ( + isCrossOver + && xLongConds.startTime > 0 + && xLongConds.signalTime == 0 + ) { + // + xLongConds.signalTime = barTime; + return; + } +} + +// +// Check and Fill Short Signal Conditions ... +void CheckXShortSignalConditions( + const int bar_index, + const int marketLen, + const XState &states[], + // + const double smoother = 5 +) { + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + bool isCrossUnder = + false; + + // + bool isCrossOver = + false; + + // // + // bool isCrossUnder = + // states[1].osc.fast < states[1].osc.slow + // && !(states[2].osc.fast < states[2].osc.slow) + // ; + + // // + // bool isCrossOver = + // states[1].osc.fast > states[1].osc.slow + // && !(states[2].osc.fast > states[2].osc.slow) + // ; + + // + if ( + isCrossOver + && xShortConds.startTime == 0 + ) { + // + xShortConds.startTime = barTime; + return; + } + + // + if ( + isCrossUnder + && xShortConds.startTime > 0 + && xShortConds.signalTime == 0 + ) { + // + xShortConds.signalTime = barTime; + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r, // Risk to Reward ratio ... + const XState &states[], + // + const double smoother = 5 +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + if (requestLong) { + // + if ( + !ValidateXLongConditions( + marketLen, + states, + smoother + ) + ) { + return result; + } + } else { + // + if ( + !ValidateXShortConditions( + marketLen, + states, + smoother + ) + ) { + return result; + } + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double askPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double bidPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double entryPrice = requestLong ? + askPrice : + bidPrice; + + // + double exitPrice = requestLong ? + bidPrice : + askPrice; + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + GetMarketLowestLow( + bar_index, + marketLen + ); + + // + double hh = + GetMarketHighestHigh( + bar_index, + marketLen + ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = requestLong ? + MathMin(openPrice, closePrice) - ll : + hh - MathMax(openPrice, closePrice); + double reward = risk * r2r; // risk * r2r; // 300 * _Point; + // if (risk > (500 * _Point)) { + // reward = 300 * _Point; + // } + + // + double sl = 0; // ll; + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = type; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_XXX_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XXX_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXLongConditions( + const int marketLen, + const XState &states[], + // + const double smoother = 5 +) { + // + bool isConditionsFilled = + xLongConds.startTime > 0 + && xLongConds.signalTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.signalTime + ); + + // + isBLFilled = + // + xLongConds.signalTime > xLongConds.startTime + && MathAbs(signalBarIndex - startBarIndex) > 2 + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXLongSignalConditions(); + } + + // + return result; +} + +bool ValidateXShortConditions( + const int marketLen, + const XState &states[], + // + const double smoother = 5 +) { + // + bool isConditionsFilled = + xShortConds.startTime > 0 + && xShortConds.signalTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.signalTime + ); + + // + isBLFilled = + // + xShortConds.signalTime > xShortConds.startTime + && MathAbs(signalBarIndex - startBarIndex) > 2 + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXShortSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXLongSignalConditions() { + // + xLongConds.startTime = 0; + xLongConds.signalTime = 0; +} + +// +// Clear Short Signal Conditions for New One ... +void ClearXShortSignalConditions() { + // + xShortConds.startTime = 0; + xShortConds.signalTime = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForXSignals( + const XSignal &signal, + const XState &states[], + const int marketLen, + // + double smoother = 100 +) { + // + bool result = false; + + // + bool isSCTrendUp = + states[1].sc.fast > states[1].sc.slow + && states[2].sc.fast > states[2].sc.slow; + + // // + // bool isSCTrendDown = + // states[1].sc.fast < states[1].sc.slow + // && states[2].sc.fast < states[2].sc.slow; + + // + bool isMCTrendUp = + states[1].mc.fast > states[1].mc.slow + && states[2].mc.fast > states[2].mc.slow; + + // // + // bool isMCTrendDown = + // states[1].mc.fast < states[1].mc.slow + // && states[2].mc.fast < states[2].mc.slow; + + // + bool isLCTrendUp = + states[1].lc.fast > states[1].lc.slow + && states[2].lc.fast > states[2].lc.slow; + + // // + // bool isLCTrendDown = + // states[1].lc.fast < states[1].lc.slow + // && states[2].lc.fast < states[2].lc.slow; + + // // + // bool isTrendingUp = + // pCandle.low > states[0].bnd.high + // && pCandle.high > states[0].bnd.high; + + // // + // bool isTrendingDown = + // pCandle.high < states[0].bnd.low + // && pCandle.low < states[0].bnd.low; + + // + XOHCL candle = GetCandleModel(0); + XOHCL pCandle = GetCandleModel(1); + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + result = + // + // Starter ... + true + // + // Trending State ... + && isSCTrendUp + && isMCTrendUp + && isLCTrendUp + // + // Checking Signal Entry ... + && ( + signal.entry < candle.high + || signal.entry < states[0].mkt.highestHigh + ) + // + // Checking Signal TP ... + && ( + signal.tp < states[1].longCycleHighestHigh + && MathAbs(states[1].longCycleHighestHigh - signal.tp) > 100 * _Point + ) + // + // Checking Market Sharpness ... + && + ( + pCandle.high < states[1].longCycleHighestHigh + && !(MathAbs(states[1].longCycleHighestHigh - pCandle.high) < 20 * _Point) + ) + // + // Checking Special Conditions ... + // Condition 1 ... + && ( + states[1].lc.fast > states[1].mc.fast + && states[1].lc.slow > states[1].mc.fast + ? + states[1].lc.slow < states[1].mkt.lowestLow + : + true + ) + // + // Condition 2 ... + && !( + states[1].lc.fast > states[1].mkt.highestHigh + && states[1].lc.slow < states[1].mkt.lowestLow + ) + // + // Condition 3 ... + && MathAbs(states[1].sc.fast - states[1].sc.slow) > 20 * _Point + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + result = + false + ; + } + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020428/Libraries/x-saherelm.xma.mc.signal.lib.mq4 b/Bkp/Used/14020428/Libraries/x-saherelm.xma.mc.signal.lib.mq4 new file mode 100644 index 0000000..13b787e --- /dev/null +++ b/Bkp/Used/14020428/Libraries/x-saherelm.xma.mc.signal.lib.mq4 @@ -0,0 +1,490 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 XMA Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// XMA Based Signal Conditions ... +struct XMAMCLongSignalConditions { + // + datetime mcFastCrossUnderSlowTime; + double crossUnderMCFast; + double crossUnderMCSlow; + + // + datetime mcFastCrossOverSlowTime; + double crossOverMCFast; + double crossOverMCSlow; + + // + datetime mcFastBiggerThanCrossUnderSlowTime; +}; + +// +static XMAMCLongSignalConditions xmaMCLongConds; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill CC Signal Conditions ... +void CheckXMAMCLongSignalConditions( + const int bar_index, + const int marketLen, + // + double stp, + double mxm, + // + int scFMult, + int scSMult, + // + int mcFMult, + int mcSMult +) { + // + XCycleState mcs[]; + int positionsMarketLen = bar_index + marketLen; + + // + // Retrieve Bar Time ... + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Resize Arrays ... + ArrayResize( + mcs, + marketLen + ); + + // + int index = 0; + for (int i = bar_index; i < positionsMarketLen; i++) { + // + XCycleState mc = GetXMAMC( + i, + marketLen, + mcFMult, + mcSMult + ); + mcs[index] = mc; + + // + index++; + } + + // + bool isMCFastCrossUnderSlow = + mcs[0].fast < mcs[0].slow + && !(mcs[1].fast <= mcs[1].slow) + ; + bool isMCFastCrossOverSlow = + mcs[0].fast > mcs[0].slow + && !(mcs[1].fast >= mcs[1].slow) + ; + + // + if ( + isMCFastCrossUnderSlow + && xmaMCLongConds.mcFastCrossUnderSlowTime == 0 + ) { + // + xmaMCLongConds.crossUnderMCFast = mcs[0].fast; + xmaMCLongConds.crossUnderMCSlow = mcs[0].slow; + xmaMCLongConds.mcFastCrossUnderSlowTime = barTime; + return; + } + + // + if ( + isMCFastCrossUnderSlow + && xmaMCLongConds.mcFastCrossUnderSlowTime > 0 + ) { + // + ClearXMAMCLongSignalConditions(); + + // + xmaMCLongConds.crossUnderMCFast = mcs[0].fast; + xmaMCLongConds.crossUnderMCSlow = mcs[0].slow; + xmaMCLongConds.mcFastCrossUnderSlowTime = barTime; + return; + } + + // + if ( + isMCFastCrossOverSlow + && xmaMCLongConds.mcFastCrossUnderSlowTime > 0 + && xmaMCLongConds.mcFastCrossOverSlowTime == 0 + ) { + // + xmaMCLongConds.crossOverMCFast = mcs[0].fast; + xmaMCLongConds.crossOverMCSlow = mcs[0].slow; + xmaMCLongConds.mcFastCrossOverSlowTime = barTime; + return; + } + + // + if ( + xmaMCLongConds.mcFastCrossUnderSlowTime > 0 + && xmaMCLongConds.mcFastCrossOverSlowTime > 0 + && mcs[0].fast > xmaMCLongConds.crossUnderMCSlow + && xmaMCLongConds.mcFastBiggerThanCrossUnderSlowTime == 0 + ) { + // + xmaMCLongConds.mcFastBiggerThanCrossUnderSlowTime = barTime; + return; + } +} + +// +// Convert XMA Long Signal Conditions to XSignal ... +XSignalRequest GenerateXMAMCLongSignal( + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r, // Risk to Reward ratio ... + const double shpDetectMult, + const double smoother = 50 +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if ( + !ValidateXMAMCLongConditions( + marketLen, + shpDetectMult, + smoother + ) + ) { + return result; + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double entryPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double exitPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + GetMarketLowestLow( + bar_index, + 3 + ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = MathMin(openPrice, closePrice) - ll; + double reward = risk * r2r; + + // + double sl = 0; + double tp = entryPrice + reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = X_SIGNAL_LONG; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_XMA_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = X_SIGNAL_LONG; + result.provider = X_XMA_PROVIDER; + + // + return result; +} + +// +// Validate XMA Signal Conditions ... +bool ValidateXMAMCLongConditions( + const int marketLen, + const double shpDetectMult, + const double smoother = 50 +) { + // + bool isConditionsFilled = + xmaMCLongConds.crossOverMCSlow > 0 + && xmaMCLongConds.crossOverMCFast > 0 + && xmaMCLongConds.crossUnderMCFast > 0 + && xmaMCLongConds.crossUnderMCSlow > 0 + && xmaMCLongConds.mcFastCrossOverSlowTime != 0 + && xmaMCLongConds.mcFastCrossUnderSlowTime != 0 + && xmaMCLongConds.mcFastBiggerThanCrossUnderSlowTime != 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int crossUnderBarIndex = iBarShift( + _Symbol, + _Period, + xmaMCLongConds.mcFastCrossUnderSlowTime + ); + + // + int crossOverAndBiggerBarIndex = iBarShift( + _Symbol, + _Period, + xmaMCLongConds.mcFastBiggerThanCrossUnderSlowTime + ); + + // + int cycleMarketLen = MathMin( + MathAbs(crossUnderBarIndex - crossOverAndBiggerBarIndex), + marketLen * 2 + ); + double hh = GetMarketHighestHigh( + crossOverAndBiggerBarIndex, + cycleMarketLen + ); + double ll = GetMarketLowestLow( + crossOverAndBiggerBarIndex, + cycleMarketLen + ); + + // + double high = iHigh( + _Symbol, + _Period, + crossOverAndBiggerBarIndex + ); + double pcHigh = iHigh( + _Symbol, + _Period, + crossOverAndBiggerBarIndex + 1 + ); + + // + double diff = (hh - ll); + double shpValue = shpDetectMult * _Point; + + // + bool isPriceRegular = + // + true + // + && + ( + diff < shpValue + || diff < shpValue - (smoother * _Point) + ) + && + !( + high == hh + || pcHigh == hh + || MathAbs(hh - high) < (smoother * _Point) + || MathAbs(hh - pcHigh) < (smoother * _Point) + ) + ; + + // + // LogMessage("Price Regular: " + isPriceRegular); + + // + isBLFilled = + isPriceRegular + && xmaMCLongConds.mcFastCrossUnderSlowTime < xmaMCLongConds.mcFastCrossOverSlowTime + && xmaMCLongConds.mcFastBiggerThanCrossUnderSlowTime >= xmaMCLongConds.mcFastCrossUnderSlowTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXMAMCLongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXMAMCLongSignalConditions() { + // + xmaMCLongConds.mcFastCrossUnderSlowTime = 0; + xmaMCLongConds.crossUnderMCFast = 0; + xmaMCLongConds.crossUnderMCSlow = 0; + + // + xmaMCLongConds.mcFastCrossOverSlowTime = 0; + xmaMCLongConds.crossOverMCFast = 0; + xmaMCLongConds.crossOverMCSlow = 0; + + // + xmaMCLongConds.mcFastBiggerThanCrossUnderSlowTime = 0; +} + +// +// Check XMA State for Long Signals ... +bool IsReadyForXMAMCLongSignals( + const XSignal &signal, + const XState &states[], + const int marketLen +) { + // + bool result = false; + + // + int countRangedCandles = 0; + bool isMarketRanging = false; + for (int i = 1; i < marketLen; i++) { + // + double high = iHigh( + _Symbol, + _Period, + i + ); + + // + double low = iLow( + _Symbol, + _Period, + i + ); + + // + bool isRanging = + // + high > states[i].mc.fast + && high > states[i].mc.slow + // + && low < states[i].mc.fast + && low < states[i].mc.slow + ; + if (isRanging) { + countRangedCandles++; + } + } + + // + XStateInfo info = ParseXMAStates(states); + double mmSlope = GetSlope( + 1, + states[1].marketMiddleage, + 2, + states[0].marketMiddleage + ); + double mmSlope1 = GetSlope( + 1, + states[2].marketMiddleage, + 2, + states[1].marketMiddleage + ); + double mmSlopeDiff = mmSlope - mmSlope1; + + // + isMarketRanging = countRangedCandles > 0; + + // + result = + // + true + // + && mmSlope > 0 + && mmSlope1 > 0 + && mmSlopeDiff > 0 + && !isMarketRanging + && states[0].marketMiddleage < info.mmMax + ; + // if (result) { + // LogMessage("mmSlope: " + mmSlope + ", mmSlope1: " + mmSlope1 + ", Diff: " + mmSlopeDiff); + // } + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020428/Libraries/x-saherelm.xma.mm.signal.lib.mq4 b/Bkp/Used/14020428/Libraries/x-saherelm.xma.mm.signal.lib.mq4 new file mode 100644 index 0000000..d883803 --- /dev/null +++ b/Bkp/Used/14020428/Libraries/x-saherelm.xma.mm.signal.lib.mq4 @@ -0,0 +1,338 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 XMA Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// XMA Based Signal Conditions ... +struct XMAMMLongSignalConditions { + // + datetime crossUnderTime; + + // + datetime crossOverTime; +}; + +// +static XMAMMLongSignalConditions xmaMMLongConds; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill CC Signal Conditions ... +void CheckXMAMMLongSignalConditions( + const int bar_index, + const int marketLen, + // + double stp, + double mxm, + // + int scFMult, + int scSMult, + // + int mcFMult, + int mcSMult, + // + int lcFMult, + int lcSMult, + // + const double smoother = 5 +) { + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XState states[]; + ArrayResize( + states, + marketLen + ); + + // + int index = 0; + for (int i = bar_index; i < marketLen; i++) { + // + XState state = GetXState( + i, + marketLen, + // + stp, + mxm, + scFMult, + scSMult, + mcFMult, + mcSMult, + lcFMult, + lcSMult + ); + + // + states[index] = state; + + // + index++; + } + + // + bool isCrossUnder = + states[1].marketMiddleage < states[1].sc.fast + && !(states[2].marketMiddleage < states[2].sc.fast) + ; + + // + bool isCrossOver = + states[1].marketMiddleage > states[1].sc.fast + && !(states[2].marketMiddleage > states[2].sc.fast) + ; + + // + if ( + isCrossUnder + && xmaMMLongConds.crossUnderTime == 0 + ) { + // + xmaMMLongConds.crossUnderTime = barTime; + return; + } + + // + if ( + isCrossOver + && xmaMMLongConds.crossUnderTime > 0 + && xmaMMLongConds.crossOverTime == 0 + ) { + // + xmaMMLongConds.crossOverTime = barTime; + return; + } +} + +// +// Convert XMA Long Signal Conditions to XSignal ... +XSignalRequest GenerateXMAMMLongSignal( + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r // Risk to Reward ratio ... +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if (!ValidateXMAMMLongConditions()) { + return result; + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double entryPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double exitPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + GetMarketLowestLow( + bar_index, + marketLen + ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = MathMin(openPrice, closePrice) - ll; + double reward = 300 * _Point; // risk * r2r; + + // + double sl = 0; // entryPrice - (300 * _Point); // ll; + double tp = entryPrice + reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = X_SIGNAL_LONG; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_XMA_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = X_SIGNAL_LONG; + result.provider = X_XMA_PROVIDER; + + // + return result; +} + +// +// Validate XMA Signal Conditions ... +bool ValidateXMAMMLongConditions() { + // + bool isConditionsFilled = + true + && xmaMMLongConds.crossOverTime > 0 + && xmaMMLongConds.crossUnderTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int crossOverBarIndex = iBarShift( + _Symbol, + _Period, + xmaMMLongConds.crossOverTime + ); + + // + int crossUnderBarIndex = iBarShift( + _Symbol, + _Period, + xmaMMLongConds.crossUnderTime + ); + + // + isBLFilled = + true + // + && (crossUnderBarIndex - crossOverBarIndex) > 5 + // + && xmaMMLongConds.crossOverTime > xmaMMLongConds.crossUnderTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXMAMMLongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXMAMMLongSignalConditions() { + // + xmaMMLongConds.crossOverTime = 0; + xmaMMLongConds.crossUnderTime = 0; +} + +// +// Check XMA State for Long Signals ... +bool IsReadyForXMAMMLongSignals( + const XSignal &signal, + const XState &states[], + const int marketLen +) { + // + bool result = false; + + // + result = + // + true + // + // && states[0].parabolicSAR < states[0].marketMiddleage + // && !( + // states[0].parabolicSAR < states[0].mc.fast + // && states[0].parabolicSAR < states[0].mc.slow + // ) + // + // && states[0].mc.fast > states[0].mc.slow + // + // && MathAbs(states[0].mc.fast - states[0].mc.slow) > (150 * _Point) + ; + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020428/Libraries/x-saherelm.xma.sc.signal.lib.mq4 b/Bkp/Used/14020428/Libraries/x-saherelm.xma.sc.signal.lib.mq4 new file mode 100644 index 0000000..218759c --- /dev/null +++ b/Bkp/Used/14020428/Libraries/x-saherelm.xma.sc.signal.lib.mq4 @@ -0,0 +1,360 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 XMA Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// XMA Based Signal Conditions ... +struct XMASCLongSignalConditions { + // + datetime scFastCrossUnderSlowTime; + double crossUnderSCFast; + double crossUnderSCSlow; + + // + datetime scFastCrossOverSlowTime; + double crossOverSCFast; + double crossOverSCSlow; + + // + datetime scFastBiggerThanCrossUnderSlowTime; +}; + +// +static XMASCLongSignalConditions xmaSCLongConds; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill CC Signal Conditions ... +void CheckXMASCLongSignalConditions( + const int bar_index, + const int marketLen, + // + double stp, + double mxm, + // + int scFMult, + int scSMult, + // + int mcFMult, + int mcSMult +) { + // + XCycleState scs[]; + int positionsMarketLen = bar_index + marketLen; + + // + // Retrieve Bar Time ... + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Resize Arrays ... + ArrayResize( + scs, + marketLen + ); + + // + int index = 0; + for (int i = bar_index; i < positionsMarketLen; i++) { + // + XCycleState sc = GetXMASC( + i, + marketLen, + scFMult, + scSMult + ); + scs[index] = sc; + + // + index++; + } + + // + bool isSCFastCrossUnderSlow = + scs[0].fast < scs[0].slow + && !(scs[1].fast <= scs[1].slow) + ; + bool isSCFastCrossOverSlow = + scs[0].fast > scs[0].slow + && !(scs[1].fast >= scs[1].slow) + ; + + // + if ( + isSCFastCrossUnderSlow + && xmaSCLongConds.scFastCrossUnderSlowTime == 0 + ) { + // + xmaSCLongConds.crossUnderSCFast = scs[0].fast; + xmaSCLongConds.crossUnderSCSlow = scs[0].slow; + xmaSCLongConds.scFastCrossUnderSlowTime = barTime; + return; + } + + // + if ( + isSCFastCrossOverSlow + && xmaSCLongConds.scFastCrossUnderSlowTime > 0 + && xmaSCLongConds.scFastCrossOverSlowTime == 0 + ) { + // + xmaSCLongConds.crossOverSCFast = scs[0].fast; + xmaSCLongConds.crossOverSCSlow = scs[0].slow; + xmaSCLongConds.scFastCrossOverSlowTime = barTime; + return; + } + + // + if ( + xmaSCLongConds.scFastCrossUnderSlowTime > 0 + && xmaSCLongConds.scFastCrossOverSlowTime > 0 + && scs[0].fast > xmaSCLongConds.crossUnderSCSlow + && xmaSCLongConds.scFastBiggerThanCrossUnderSlowTime == 0 + ) { + // + xmaSCLongConds.scFastBiggerThanCrossUnderSlowTime = barTime; + return; + } + + // + if ( + isSCFastCrossUnderSlow + && xmaSCLongConds.scFastCrossUnderSlowTime > 0 + && xmaSCLongConds.scFastCrossOverSlowTime > 0 + ) { + // + ClearXMASCLongSignalConditions(); + return; + } +} + +// +// Convert XMA Long Signal Conditions to XSignal ... +XSignalRequest GenerateXMASCLongSignal( + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const double r2r // Risk to Reward ratio ... + // + // const double shpDetectMultiplier +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if (!ValidateXMASCLongConditions()) { + return result; + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double entryPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double exitPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + GetMarketLowestLow( + bar_index, + marketLen + ); + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + 1 + ); + + // // + // double sharpDetectValue = shpDetectMultiplier * _Point; + // double lowPrice = iLow( + // _Symbol, + // _Period, + // bar_index + 1 + // ); + + // + double risk = MathMin(openPrice, closePrice) - ll; + double reward = risk * r2r; + + // + double sl = 0; + double tp = entryPrice + reward; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.symbol = _Symbol; + result.signal.type = X_SIGNAL_LONG; + result.signal.id = totalSignals + 1; + result.signal.entry = entryPrice; + result.signal.provider = X_XMA_PROVIDER; + result.signal.time = barTime; + + // + result.hasSignal = true; + result.type = X_SIGNAL_LONG; + result.provider = X_XMA_PROVIDER; + + // + return result; +} + +// +// Validate XMA Signal Conditions ... +bool ValidateXMASCLongConditions() { + // + bool isConditionsFilled = + xmaSCLongConds.crossOverSCSlow > 0 + && xmaSCLongConds.crossOverSCFast > 0 + && xmaSCLongConds.crossUnderSCFast > 0 + && xmaSCLongConds.crossUnderSCSlow > 0 + && xmaSCLongConds.scFastCrossOverSlowTime != 0 + && xmaSCLongConds.scFastCrossUnderSlowTime != 0 + && xmaSCLongConds.scFastBiggerThanCrossUnderSlowTime !=0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + isBLFilled = + xmaSCLongConds.crossOverSCFast > xmaSCLongConds.crossUnderSCSlow + && xmaSCLongConds.scFastCrossUnderSlowTime < xmaSCLongConds.scFastCrossOverSlowTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXMASCLongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXMASCLongSignalConditions() { + // + xmaSCLongConds.crossUnderSCFast = 0; + xmaSCLongConds.crossUnderSCSlow = 0; + xmaSCLongConds.scFastCrossUnderSlowTime = 0; + + // + xmaSCLongConds.crossOverSCFast = 0; + xmaSCLongConds.crossOverSCSlow = 0; + xmaSCLongConds.scFastCrossOverSlowTime = 0; + + // + xmaSCLongConds.scFastBiggerThanCrossUnderSlowTime = 0; +} + +// +// Check XMA State for Long Signals ... +bool IsReadyForXMASCLongSignals( + const XSignal &signal, + const XState &states[], + const int marketLen +) { + // + bool result = false; + + // + result = + // + true + // + && states[0].sc.fast > states[0].sc.slow + && states[1].sc.fast > states[1].sc.slow + ; + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020430/Indicators/x-saherelm.rma.mq4 b/Bkp/Used/14020430/Indicators/x-saherelm.rma.mq4 new file mode 100644 index 0000000..0fc70fd --- /dev/null +++ b/Bkp/Used/14020430/Indicators/x-saherelm.rma.mq4 @@ -0,0 +1,141 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center RMA Indicator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm RMA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Set the RMA Length ... +input int RMALength = 10; // Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// we have 2 buffer in this indicator ... +#property indicator_buffers 1 + +// +// also we have 1 line for draw on this indicator ... +#property indicator_plots 1 + +// +// here we declare plot SlowOCS to system ... +#property indicator_label1 "RMA" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrFuchsia +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +// +// Declare Buffers ... +#define RMABufferIndex 0 + +// +double RMABuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + SetIndexBuffer(RMABufferIndex, RMABuffer); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + int maxLength = MathMax(0, RMALength); + + // + // wait to pass bars until we have rights ... + if (rates_total <= maxLength) { + // + // return not calculated ... + return 0; + } + + // + // find loop count for bars manipulation ... + int count = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // Print("Count: ", count, ", Bars: ", Bars); + + // + // this is the main loop of calculations, for each bar index ... + for (int i = count - 1; i >= 0; i--) { + // + // Start Calculation with Formula 1 ... + // + double shortSMA = iMA(_Symbol, _Period, RMALength, 0, MODE_SMA, PRICE_CLOSE, i); + double mediumSMA = iMA(_Symbol, _Period, RMALength * 2, 0, MODE_SMA, PRICE_CLOSE, i); + double longSMA = iMA(_Symbol, _Period, RMALength * 3, 0, MODE_SMA, PRICE_CLOSE, i); + + // + double rma1 = longSMA - mediumSMA + shortSMA; + rma1 = NormalizeDouble(rma1, _Digits); + // + // End Calculation with Formula 1 ... + // + + // + RMABuffer[i] = rma1; + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020430/Indicators/x-saherelm.volume.mq4 b/Bkp/Used/14020430/Indicators/x-saherelm.volume.mq4 new file mode 100644 index 0000000..54bed44 --- /dev/null +++ b/Bkp/Used/14020430/Indicators/x-saherelm.volume.mq4 @@ -0,0 +1,270 @@ +///////////////////////////////////////////////////////////////// +// +// SaherElm IT Center Volume Indicator +// ------------------------------------------------------------- +// this indicator provides Volume ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +//////////////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm Volume Indicator" +#property strict + +// +// START Inputs ... +// +input int length = 11; // Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +#property indicator_separate_window + +// +// we have 2 buffer in this indicator ... +#property indicator_buffers 3 + +// +// also we have 2 line for draw on this indicator ... +#property indicator_plots 3 + +// +// Buy Volume ... +#property indicator_width1 1 +#property indicator_color1 clrGreen +#property indicator_type1 DRAW_HISTOGRAM +#property indicator_style1 STYLE_DOT + +// +// Sell Volume ... +#property indicator_width2 1 +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT + +// +// Diff ... +#property indicator_width3 1 +#property indicator_type3 DRAW_HISTOGRAM +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_SOLID + +// +//#property indicator_minimum 0 +//#property indicator_maximum 1 + +// +// set color of horizontal levels ... +#property indicator_levelcolor clrGray + +// +// set style of horizontal levels ... +#property indicator_levelstyle STYLE_DOT + +// +// Declare Buffers ... +#define buyVolumeBufferIndex 0 +#define sellVolumeBufferIndex 1 +#define diffBufferIndex 2 + +// +double buyVolumeBuffer[]; +double sellVolumeBuffer[]; +double diffBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (length < 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // set descriptions of horizontal levels ... + SetLevelValue(0, 0.0); + IndicatorSetString(INDICATOR_LEVELTEXT,0,""); + + // + // Buy Volume Buffer ... + SetIndexBuffer(buyVolumeBufferIndex, buyVolumeBuffer); + SetIndexLabel(buyVolumeBufferIndex, "Buy Volume"); + + // + // Sell Volume Buffer ... + SetIndexBuffer(sellVolumeBufferIndex, sellVolumeBuffer); + SetIndexLabel(sellVolumeBufferIndex, "Sell Volume"); + + // + // Diff Buffer ... + SetIndexBuffer(diffBufferIndex, diffBuffer); + SetIndexLabel(diffBufferIndex, "Diff"); + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XS_VOLUME"; + + // + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, length); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + CalculateBuffers( + open, + close, + high, + low, + i + ); + } + + // + return rates_total; +} + +// +// De Initialization ... +void OnDeinit(const int reason) { +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +void CalculateBuffers( + const double &open[], + const double &close[], + const double &high[], + const double &low[], + const int &bar_index +) { + // + long volume = iVolume( + _Symbol, + _Period, + bar_index + ); + + // + double buyVolume = 0.0; + double sellVolume = 0.0; + + // + // Up ... + if (close[bar_index] > open[bar_index]) { + // + double cuenta = (high[bar_index] - low[bar_index]) * 10000; + double cuenta1 = volume - cuenta; + + // + buyVolume = ((volume - cuenta) / 2) + cuenta; + + // + buyVolumeBuffer[bar_index] = buyVolume; + sellVolumeBuffer[bar_index] = volume - buyVolume; + } else + // + // Down ... + if (close[bar_index] < open[bar_index]) { + // + double cuenta1 = (high[bar_index] - low[bar_index]) * 10000; + double cuenta = volume - cuenta1; + + // + sellVolume = ((volume - cuenta1) / 2) + cuenta1; + + // + sellVolumeBuffer[bar_index] = sellVolume; + buyVolumeBuffer[bar_index] = volume - sellVolume; + } else + // + // Neutral ... + if (close[bar_index] == open[bar_index]) { + // + double cuenta = (volume / 2) * 1.0; + + // + sellVolumeBuffer[bar_index] = cuenta; + buyVolumeBuffer[bar_index] = volume - cuenta; + } + + // + diffBuffer[bar_index] = MathAbs(buyVolumeBuffer[bar_index]) - MathAbs(sellVolumeBuffer[bar_index]); +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020430/Indicators/x-saherelm.xmarket.mq4 b/Bkp/Used/14020430/Indicators/x-saherelm.xmarket.mq4 new file mode 100644 index 0000000..71b2e2c --- /dev/null +++ b/Bkp/Used/14020430/Indicators/x-saherelm.xmarket.mq4 @@ -0,0 +1,394 @@ + /////////////////////////////////////////////////////// +// +// SaherElm IT Center XMKT Indicator +// --------------------------------------------- +// retrieve market base info ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XMKT Indicator" +#property strict + +// +// START Inputs ... +// +// +// Market Specifications ... +input int marketLength = 7; // Market Length +// +input bool showHighestHigh = true; // Show Market Highest High +input bool showHighestLow = true; // Show Market Highest Low +input bool showHighestOpen = true; // Show Market Highest Open +input bool showHighestClose = true; // Show Market Highest Close +input bool showLowestHigh = true; // Show Market Lowest High +input bool showLowestLow = true; // Show Market Lowest Low +input bool showLowestOpen = true; // Show Market Lowest Open +input bool showLowestClose = true; // Show Market Lowest Close +// +input color highestHighColor = clrDeepPink; // Market Highest High Color +input color highestLowColor = clrDarkOrange; // Market Highest Low Color +input color highestOpenColor = clrDodgerBlue; // Market Highest Open Color +input color highestCloseColor = clrOrchid; // Market Highest Close Color +input color lowestHighColor = clrHotPink; // Market Lowest High Color +input color lowestLowColor = clrOrange; // Market Lowest Low Color +input color lowestOpenColor = clrPowderBlue; // Market Lowest Open Color +input color lowestCloseColor = clrMediumOrchid; // Market Lowest Close Color +// +input ENUM_LINE_STYLE highestHighStyle = STYLE_DOT; // Market Highest High Line Style +input ENUM_LINE_STYLE highestLowStyle = STYLE_DOT; // Market Highest Low Line Style +input ENUM_LINE_STYLE highestOpenStyle = STYLE_DOT; // Market Highest Open Line Style +input ENUM_LINE_STYLE highestCloseStyle = STYLE_DOT; // Market Highest Close Line Style +input ENUM_LINE_STYLE lowestHighStyle = STYLE_DOT; // Market Lowest High Line Style +input ENUM_LINE_STYLE lowestLowStyle = STYLE_DOT; // Market Lowest Low Line Style +input ENUM_LINE_STYLE lowestOpenStyle = STYLE_DOT; // Market Lowest Open Line Style +input ENUM_LINE_STYLE lowestCloseStyle = STYLE_DOT; // Market Lowest Close Line Style +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// define indicator buffers ... +#property indicator_buffers 8 +#property indicator_plots 8 + +// +// Declare Buffers ... +#define marketHighestHighBufferIndex 0 +#define marketHighestLowBufferIndex 1 +#define marketHighestOpenBufferIndex 2 +#define marketHighestCloseBufferIndex 3 +#define marketLowestHighBufferIndex 4 +#define marketLowestLowBufferIndex 5 +#define marketLowestOpenBufferIndex 6 +#define marketLowestCloseBufferIndex 7 + +// +double marketHighestHighBuffer[]; +double marketHighestLowBuffer[]; +double marketHighestOpenBuffer[]; +double marketHighestCloseBuffer[]; +double marketLowestHighBuffer[]; +double marketLowestLowBuffer[]; +double marketLowestOpenBuffer[]; +double marketLowestCloseBuffer[]; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (marketLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST_XMKT"; + + // + // Highest High ... + string highestHighLbl = StringConcatenate("HH(", marketLength,")"); + SetIndexLabel(marketHighestHighBufferIndex, highestHighLbl); + SetIndexBuffer(marketHighestHighBufferIndex, marketHighestHighBuffer); + SetIndexStyle( + marketHighestHighBufferIndex, + showHighestHigh ? + DRAW_LINE : + DRAW_NONE, + highestHighStyle, + 1, + showHighestHigh ? + highestHighColor : + clrNONE + ); + + // + // Highest Low ... + string highestLowLbl = StringConcatenate("HL(", marketLength,")"); + SetIndexLabel(marketHighestLowBufferIndex, highestLowLbl); + SetIndexBuffer(marketHighestLowBufferIndex, marketHighestLowBuffer); + SetIndexStyle( + marketHighestLowBufferIndex, + showHighestLow ? + DRAW_LINE : + DRAW_NONE, + highestLowStyle, + 1, + showHighestLow ? + highestLowColor : + clrNONE + ); + + // + // Highest Open ... + string highestOpenLbl = StringConcatenate("HO(", marketLength,")"); + SetIndexLabel(marketHighestOpenBufferIndex, highestOpenLbl); + SetIndexBuffer(marketHighestOpenBufferIndex, marketHighestOpenBuffer); + SetIndexStyle( + marketHighestOpenBufferIndex, + showHighestOpen ? + DRAW_LINE : + DRAW_NONE, + highestOpenStyle, + 1, + showHighestOpen ? + highestOpenColor : + clrNONE + ); + + // + // Highest Close ... + string highestCloseLbl = StringConcatenate("HC(", marketLength,")"); + SetIndexLabel(marketHighestCloseBufferIndex, highestCloseLbl); + SetIndexBuffer(marketHighestCloseBufferIndex, marketHighestCloseBuffer); + SetIndexStyle( + marketHighestCloseBufferIndex, + showHighestClose ? + DRAW_LINE : + DRAW_NONE, + highestCloseStyle, + 1, + showHighestClose ? + highestCloseColor : + clrNONE + ); + + // + // Lowest High ... + string lowestHighLbl = StringConcatenate("LH(", marketLength,")"); + SetIndexLabel(marketLowestHighBufferIndex, lowestHighLbl); + SetIndexBuffer(marketLowestHighBufferIndex, marketLowestHighBuffer); + SetIndexStyle( + marketLowestHighBufferIndex, + showLowestHigh ? + DRAW_LINE : + DRAW_NONE, + lowestHighStyle, + 1, + showLowestHigh ? + lowestHighColor : + clrNONE + ); + + // + // Lowest Low ... + string lowestLowLbl = StringConcatenate("LL(", marketLength,")"); + SetIndexLabel(marketLowestLowBufferIndex, lowestLowLbl); + SetIndexBuffer(marketLowestLowBufferIndex, marketLowestLowBuffer); + SetIndexStyle( + marketLowestLowBufferIndex, + showLowestLow ? + DRAW_LINE : + DRAW_NONE, + lowestLowStyle, + 1, + showLowestLow ? + lowestLowColor : + clrNONE + ); + + // + // Lowest Open ... + string lowestOpenLbl = StringConcatenate("LO(", marketLength,")"); + SetIndexLabel(marketLowestOpenBufferIndex, lowestOpenLbl); + SetIndexBuffer(marketLowestOpenBufferIndex, marketLowestOpenBuffer); + SetIndexStyle( + marketLowestOpenBufferIndex, + showLowestOpen ? + DRAW_LINE : + DRAW_NONE, + lowestOpenStyle, + 1, + showLowestOpen ? + lowestOpenColor : + clrNONE + ); + + // + // Lowest Close ... + string lowestCloseLbl = StringConcatenate("LC(", marketLength,")"); + SetIndexLabel(marketLowestCloseBufferIndex, lowestCloseLbl); + SetIndexBuffer(marketLowestCloseBufferIndex, marketLowestCloseBuffer); + SetIndexStyle( + marketLowestCloseBufferIndex, + showLowestClose ? + DRAW_LINE : + DRAW_NONE, + lowestCloseStyle, + 1, + showLowestClose ? + lowestCloseColor : + clrNONE + ); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + RemoveDraws(logTag); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(marketLength, 3); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Short Cycle ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculate Short Cycle ... +void CalculateBuffers( + const int bar_index +) { + // + // Highest High ... + double highestHighValue = GetMarketHighestHigh( + bar_index, + marketLength + ); + marketHighestHighBuffer[bar_index] = highestHighValue; + + // + // Highest Low ... + double highestLowValue = GetMarketHighestLow( + bar_index, + marketLength + ); + marketHighestLowBuffer[bar_index] = highestLowValue; + + // + // Highest Open ... + double highestOpenValue = GetMarketHighestOpen( + bar_index, + marketLength + ); + marketHighestOpenBuffer[bar_index] = highestOpenValue; + + // + // Highest Close ... + double highestCloseValue = GetMarketHighestClose( + bar_index, + marketLength + ); + marketHighestCloseBuffer[bar_index] = highestCloseValue; + + // + // Lowest High ... + double lowestHighValue = GetMarketLowestHigh( + bar_index, + marketLength + ); + marketLowestHighBuffer[bar_index] = lowestHighValue; + + // + // Lowest Low ... + double lowestLowValue = GetMarketLowestLow( + bar_index, + marketLength + ); + marketLowestLowBuffer[bar_index] = lowestLowValue; + + // + // Lowest Open ... + double lowestOpenValue = GetMarketLowestOpen( + bar_index, + marketLength + ); + marketLowestOpenBuffer[bar_index] = lowestOpenValue; + + // + // Lowest Close ... + double lowestCloseValue = GetMarketLowestClose( + bar_index, + marketLength + ); + marketLowestCloseBuffer[bar_index] = lowestCloseValue; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020430/Indicators/x-saherelm.zigzag.mq4 b/Bkp/Used/14020430/Indicators/x-saherelm.zigzag.mq4 new file mode 100644 index 0000000..b79b724 --- /dev/null +++ b/Bkp/Used/14020430/Indicators/x-saherelm.zigzag.mq4 @@ -0,0 +1,476 @@ +///////////////////////////////////////////////////////////////// +// +// SaherElm IT Center ZigZag Indicator +// ------------------------------------------------------------- +// this indicator provides signals for Main strategy ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +//////////////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm ZigZag Indicator" +#property strict + +// +// START Inputs ... +// +input int depth = 12; // Depth +input int deviation = 5; // Deviation +input int backStep = 3; // BackStep +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +#property indicator_chart_window + +// +#property indicator_buffers 1 + +// +#property indicator_width1 1 +#property indicator_color1 clrAqua +// #property indicator_type1 DRAW_SECTION +// #property indicator_style1 STYLE_SOLID + +// // +// #property indicator_width2 1 +// #property indicator_color2 clrNONE +// #property indicator_type2 DRAW_NONE +// #property indicator_style2 STYLE_SOLID + +// // +// #property indicator_width3 1 +// #property indicator_color3 clrNONE +// #property indicator_type3 DRAW_NONE +// #property indicator_style3 STYLE_SOLID + +// +// Buffers ... +// +#define zigzagBufferIndex 0 +#define highBufferIndex 1 +#define lowBufferIndex 2 +// #define ziggyBufferIndex 3 + +// +double zigzagBuffer[]; +double highBuffer[]; +double lowBuffer[]; +// double ziggyBuffer[]; + +// +// recounting's depth of extremums ... +int level=3; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + depth <= 0 || + backStep < 0 || + deviation < 0 || + backStep >= depth + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Set Index Buffers of ZigZag ... + IndicatorBuffers(3); + + // + // ZigZag Buffer ... + SetIndexBuffer(zigzagBufferIndex, zigzagBuffer); + SetIndexStyle(zigzagBufferIndex, DRAW_SECTION); + SetIndexLabel(zigzagBufferIndex, "ZigZag"); + + // + // High Buffer ... + SetIndexBuffer(highBufferIndex, highBuffer); + SetIndexLabel(highBufferIndex, ""); + + // + // Low Buffer ... + SetIndexBuffer(lowBufferIndex, lowBuffer); + SetIndexLabel(lowBufferIndex, ""); + + // + // Ziggy Buffer ... + // SetIndexBuffer(ziggyBufferIndex, ziggyBuffer); + // SetIndexLabel(ziggyBufferIndex, ""); + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XS_ZG"; + + // + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + int maxLength = MathMax(depth, backStep); + + int i; + int counterZ; + int back; + int pos; + + // + int lastlowpos = 0; + int lasthighpos = 0; + int whatlookfor = 0; + + // + double extremum; + + // + double curlow = 0.0; + double curhigh = 0.0; + double lasthigh = 0.0; + double lastlow = 0.0; + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // first calculations ... + if (prev_calculated == 0) { + limit = InitializeBuffers(); + } else { + // + // find first extremum in the depth ExtLevel or 100 last bars ... + i = counterZ = 0; + while(counterZ < level && i < 100) { + // + if(zigzagBuffer[i] != 0.0) { + counterZ++; + } + + // + i++; + } + + // + // no extremum found - recounting all from begin ... + if(counterZ == 0) { + limit = InitializeBuffers(); + } else { + // + // set start position to found extremum position ... + limit = i-1; + + // + //--- what kind of extremum? + if(lowBuffer[i] != 0.0) { + // + // low extremum ... + curlow = lowBuffer[i]; + + // + // will look for the next high extremum ... + whatlookfor=1; + } else { + // + // high extremum ... + curhigh = highBuffer[i]; + + // + // will look for the next low extremum ... + whatlookfor=-1; + } + + // + // clear the rest data ... + for(i = limit - 1; i >= 0; i--) { + // + lowBuffer[i]=0.0; + highBuffer[i]=0.0; + zigzagBuffer[i]=0.0; + } + } + } + + // + // Main Calculation Loop ... + for (i = limit; i >= 0; i--) { + // + // find lowest low in depth of bars ... + extremum = low[ + iLowest( + _Symbol, + _Period, + MODE_LOW, + depth, + i + ) + ]; + + // + // this lowest has been found previously ... + if (extremum == lastlow) { + extremum = 0.0; + } else { + // + // new last low ... + lastlow=extremum; + + // + // discard extremum if current low is too high ... + if(low[i] - extremum > deviation * _Point) { + extremum=0.0; + } else { + // + // clear previous extremums in backstep bars ... + for(back = 1; back <= backStep; back++) { + // + pos = i + back; + + // + if(lowBuffer[pos] != 0 && lowBuffer[pos] > extremum) { + lowBuffer[pos] = 0.0; + } + } + } + } + + // + // found extremum is current low ... + if (low[i] == extremum) { + lowBuffer[i] = extremum; + } else { + lowBuffer[i] = 0.0; + } + + // + // find highest high in depth of bars ... + extremum = high[ + iHighest( + _Symbol, + _Period, + MODE_HIGH, + depth, + i + ) + ]; + + // + // this highest has been found previously ... + if (extremum == lasthigh) { + extremum = 0.0; + } else { + // + // new last high ... + lasthigh=extremum; + + // + // discard extremum if current high is too low ... + if (extremum - high[i] > deviation * Point) { + extremum = 0.0; + } else { + // + // clear previous extremums in backstep bars ... + for(back = 1; back <= backStep; back++) { + // + pos = i + back; + + // + if (highBuffer[pos] != 0 && highBuffer[pos] < extremum) { + highBuffer[pos] = 0.0; + } + } + } + } + + // + // found extremum is current high ... + if (high[i] == extremum) { + highBuffer[i] = extremum; + } else { + highBuffer[i] = 0.0; + } + } + + // + // final cutting ... + if( whatlookfor == 0) { + // + lastlow = 0.0; + lasthigh = 0.0; + } else { + // + lastlow = curlow; + lasthigh = curhigh; + } + + // + for(i = limit; i >= 0; i--) { + switch(whatlookfor) { + // + // look for peak or lawn ... + case 0: + // + if (lastlow == 0.0 && lasthigh == 0.0) { + if(highBuffer[i]!=0.0) { + // + lasthigh = High[i]; + lasthighpos = i; + whatlookfor = -1; + + // + zigzagBuffer[i] = lasthigh; + } + + // + if(lowBuffer[i] != 0.0) { + // + lastlow = Low[i]; + lastlowpos = i; + whatlookfor = 1; + + // + zigzagBuffer[i] = lastlow; + } + } + break; + + // + // look for peak ... + case 1: + // + if ( + lowBuffer[i] != 0.0 && + lowBuffer[i] < lastlow && + highBuffer[i] == 0.0 + ) { + // + zigzagBuffer[lastlowpos] = 0.0; + lastlowpos = i; + lastlow = lowBuffer[i]; + zigzagBuffer[i] = lastlow; + } + + // + if(highBuffer[i] != 0.0 && lowBuffer[i] == 0.0) { + // + lasthigh = highBuffer[i]; + lasthighpos = i; + zigzagBuffer[i] = lasthigh; + + // + whatlookfor=-1; + } + break; + + // + // look for lawn ... + case -1: + // + if( + highBuffer[i] != 0.0 && + highBuffer[i] > lasthigh && + lowBuffer[i] == 0.0 + ) { + // + zigzagBuffer[lasthighpos] = 0.0; + lasthighpos = i; + lasthigh = highBuffer[i]; + zigzagBuffer[i] = lasthigh; + } + + // + if( + lowBuffer[i] !=0.0 && + highBuffer[i] == 0.0 + ) { + // + lastlow = lowBuffer[i]; + lastlowpos = i; + zigzagBuffer[i] = lastlow; + whatlookfor=1; + } + break; + } + } + + // + // Done ... + return rates_total; +} + +// +// De Initialization ... +void OnDeinit(const int reason) { + // + // RemoveDraws(signalPrefix); + ChartRedraw(0); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +int InitializeBuffers() { + // + ArrayInitialize(lowBuffer,0.0); + ArrayInitialize(highBuffer, 0.0); + ArrayInitialize(zigzagBuffer, 0.0); + + // + //--- first counting position + return(Bars - depth); +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020431/Experts/x-saherelm.ea.mq4 b/Bkp/Used/14020431/Experts/x-saherelm.ea.mq4 new file mode 100644 index 0000000..742c3ec --- /dev/null +++ b/Bkp/Used/14020431/Experts/x-saherelm.ea.mq4 @@ -0,0 +1,839 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XST Strategy Expert Advisor +// --------------------------------------------- +// saherelm implementation of strategy expert advisor ... +// in this EA, we try to combine multiple tools, to ashive best +// results ... +// +// ShortName: XST +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +989121694056 +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XST Strategy Expert Advisor" +#property strict + +// +// START Inputs ... +// +// +// Signal Prefixe ... +input string signalPrefix = "XST"; // Signal Prefix + +// +// Signal Draw Specifications ... +input string bullishSignalLabel = "X_BUY"; // Bullish Signal Label +input color bullishSignalColor = clrAqua; // Bullish Signal Color + +// +input string bearishSignalLabel = "X_SELL"; // Bearish Signal Label +input color bearishSignalColor = clrFuchsia; // Bearish Signal Color + +// +input color signalEntryColor = clrAquamarine; // Signal Entry Ptice Color +input color signalSLColor = clrRed; // Signal SL Color +input color signalTPColor = clrGreen; // Signal TP Color + +// +// Trade ... +input bool allowTrade = true; // Allow Trade Based on given Signals +input bool allowLongTrades = true; // Allow Long Trades +input bool allowShortTrades = false; // Allow Short Trades + +// +// Market Specification Inpouts ... +input int marketLength = 7; // Market Length +input double riskToRewardRatio = 2; // Risk to Reward Ratio +// input double maxTPMultiplier = 1000; // Max Allowed TP + +// +// Alerts ... +input bool alertEvents = true; // Alert Events +input bool alertPositions = true; // Alert Positions +input bool longPositionAlerts = true; // Alert Long Positions +input bool shortPositionAlerts = true; // Alert Short Positions + +// +// Alert Types ... +input bool terminalAlert = false; // Terminal Alert +input bool pushAlert = false; // Push Notification Alerts + +// +// Balance and Finanical Specifications ... +input double lotsPerTradePercent = 0.00001; // Lots Per Trade Percent +input int maxOpenTrades = 4; // Maximum Open Trade +input double maxDrawdownPercentPerPTrade = 0.03; // Maximum DrawDown Per Trade +input double minBalancePercent = 0.5; // Minimum Balance for Trading +input double maxEquityPercent = 0.1; // Maximum Trade Equity +input int closeAllOpenTradesAfterCandle = 252; // Close All Open Trades After Passed Candles +input bool closeAllInProfitOpenTradesWhenMaxOpenTradesReached = false; // Close All In Profit Open Trades When Max Open Trades Reached and New Signal Income + +// +// Indicators ... +// +// CCI Inputs ... +input double step = 0.01; // SAR Step +input double maximum = 0.1; // SAR Maximum + +// +// XMA Inputs ... +// +input int shortCycleMultiplier = 2; // Short Cycle Fast Multiplier +input int mediumCycleMultiplier = 6; // Medium Cycle Fast Multiplier +input int longCycleMultiplier = 36; // Long Cycle Fast Multiplier + +// +// START Global Definitions: Variables, Properties and etc ... +// +int lastSignalledBar = 0; + +// +bool waitForLongSignals = true; +bool closeLongTrades = false; + +// +bool waitForShortSignals = true; +bool closeShortTrades = false; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.signal.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Validate Inputs ... + bool inputsNotValiid = + // + // MARKET ... + marketLength < 0 + || riskToRewardRatio < 0 + // + // EA ... + || lotsPerTradePercent < 0 + || maxOpenTrades <= 0 + || maxDrawdownPercentPerPTrade < 0 + || minBalancePercent < 0 + || maxEquityPercent < 0 + || marketLength < 0 + // + // XMA ... + // + // Validate Short Cycle ... + || shortCycleMultiplier <= 0 + // + // Validate Medium Cycle ... + || mediumCycleMultiplier <= 0 + // + // Validate Long Cycle ... + || longCycleMultiplier <= 0 + // + // Validate Series of Multipliers ... + || shortCycleMultiplier >= mediumCycleMultiplier + || mediumCycleMultiplier >= longCycleMultiplier + ; + + // + if (inputsNotValiid) { + return INIT_PARAMETERS_INCORRECT; + } + + // + totalSignals = 0; + totalLongSignals = 0; + totalShortSignals = 0; + + // + initialBalance = 0; + + // + // START Define Array Series ... + // + // + // END Define Array Series ... + // + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST"; + + // // + // // Set Event Timer on One Seccond ... + // bool isEventSet = EventSetTimer(1); + // if (!isEventSet) { + // LogMessage("Error: " + GetLastError()); + // return INIT_FAILED; + // } + + // + ClearSignalConditions(); + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + // Killing Event Timer ... + EventKillTimer(); +} + +// +// Ticker Event Handler ... +void OnTick() { + // + isNewDay = IsNewDay(); + if (isNewDay) { + // + LogMessage( + StringConcatenate( + "New Day ..." + ) + ); + } + + // + // Process Signals to Open Positions ... + ProcessSignals(); + + // + // Checking State for Signal Handling ... + CheckState(); + + // + // Process Open Positions for Trailing Stop Loss or Close ... + ProcessOpenPositions(); +} + +// +// Timer Event Handler ... +void OnTimer() { + // + CheckState(); + + // + ProcessOpenPositions(); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Check State for Signal Handling ... +void CheckState() { + // + // Here we Must to Check Market State for enable or disable + // Signal Handlers and also make dection to close all long/short + // trades ... +} + +// +// Calculate Signals and Process Based on Exists Signals ... +void ProcessSignals() { + // + XSignalRequest request = {}; + request.type = X_SIGNAL_NONE; + request.hasSignal = false; + + // + // Prevent Multiple Calculating on Same Bars ... + isNewBar = IsNewBar(); + if (isNewBar) { + countedBars++; + } + + // + if (countedBars < longCycleMultiplier * marketLength) { + return; + } + + // + bool allowDoTrade = true; + + // + // Check Balance ... + if (initialBalance > 0) { + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double minimumBalanceForTrade = + balance > initialBalance + ? + minBalancePercent * balance + : + minBalancePercent * initialBalance; + + // + // Retrieve Account Equity ... + double equity = AccountInfoDouble(ACCOUNT_EQUITY); + double maxAllowedEquity = balance - (balance * maxEquityPercent); + + // + // Retrieve Free Marigin ... + double freeMargin = AccountFreeMargin(); + double maximumMariginRisk = balance - (balance * maxEquityPercent); + + // + if ( + // + // Do not Open Positions if equity not passed ... + equity < maxAllowedEquity || + // + // Do not Open Positions if free margin not passed ... + freeMargin <= maximumMariginRisk || + // + // Do not open positions if balance less than minimum ... + balance <= minimumBalanceForTrade + ) { + // + allowDoTrade = false; + + // // + // string message = StringConcatenate( + // "Trading Pause => ", + // "Balance: ", balance, + // ", Equity: ", equity, + // ", FreeMargin: ", freeMargin + // ); + + // // + // LogMessage(message); + // SendAlert(message); + } + } + + // + // Retrieve Signal Exists ... + request = GenerateSignal(0); + + // + // Prevent doing anything else, if there is no signals ... + if ( + !allowDoTrade || + !request.hasSignal || + request.type == X_SIGNAL_NONE + ) { + return; + } + + // + bool hasLongSignal = request.type == X_SIGNAL_LONG; + + // + // Check For Bot State ... + if ( + (hasLongSignal && !waitForLongSignals) + || (!hasLongSignal && !waitForShortSignals) + ) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + return; + } + + // + // Check last Signalled Bar with Counted Bars ... + // Prevent Multiple Signalling on Same Bar ... + bool isInLastSignalledBars = false; + for (int i=0; i < marketLength; i++) { + // + isInLastSignalledBars = + isInLastSignalledBars + || lastSignalledBar == countedBars - i + ; + } + if (isInLastSignalledBars) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + return; + } + + // + // increase last signalled bar ... + lastSignalledBar = countedBars; + + // + // Calculate Can Trade or not ... + allowDoTrade = allowTrade + && ( + hasLongSignal ? + allowLongTrades : + allowShortTrades + ); + + // + // Chack Maximum Open Positions ... + int openTrades = CountOpenTrades(); + if (maxOpenTrades > 0) { + // + if (openTrades >= maxOpenTrades) { + // + allowDoTrade = false; + + // + if (closeAllInProfitOpenTradesWhenMaxOpenTradesReached) { + // + // Close All In Profit Trades ... + bool hasClosedInProfitTrade = CloseAllInProfitTrades(); + if (hasClosedInProfitTrade) { + // + openTrades = CountOpenTrades(); + + // + allowDoTrade = !(openTrades >= maxOpenTrades); + } + } + + // + if (!allowDoTrade) { + // + string message = StringConcatenate( + "Trading Pause => ", + "Max Open Trades (", + maxOpenTrades, + ") reached ..." + ); + + // + LogMessage(message); + SendAlert(message); + } + } + } + + // + // Check Trading is Enable or not ... + // nothing to do if trading is disabled ... + if (!allowDoTrade) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // // + // string message = StringConcatenate( + // "Trading Not Allowed ..." + // ); + + // // + // LogMessage(message); + // SendAlert(message); + return; + } + + // + bool isPositionOpened = TradeSignal( + request.signal, + lotsPerTradePercent, + // + bullishSignalLabel, + bullishSignalColor, + bearishSignalLabel, + bearishSignalColor + ); + + // + totalSignals++; + if (hasLongSignal) { + // + totalLongSignals++; + ClearLongSignalConditions(); + } else { + // + totalShortSignals++; + ClearShortSignalConditions(); + } + + // // + // if (isPositionOpened) { + // // + // int rangeMarketLength = marketLength * longCycleMultiplier; + // XRange range = GetMarketRange( + // 0, + // rangeMarketLength, + // marketLength + // ); + + // // + // DrawRange( + // range, + // 0, + // 0, + // signalPrefix + // ); + // } + + // // + // double fibLevel = 1.618; + // double fibLevelPrice = GetFibonacciLevel( + // request.signal.tp, + // request.signal.entry, + // fibLevel, + // 1 + // ); + // string lbl = StringConcatenate( + // request.signal.tag, + // "_FIB_", + // fibLevel, + // "_", + // fibLevelPrice + // ); + + // // + // datetime time1 = iTime( + // _Symbol, + // _Period, + // 1 + // ); + + // // + // datetime time2 = iTime( + // _Symbol, + // _Period, + // 0 + // ); + + // // + // DrawTrendLine( + // 0, + // lbl, + // 0, + // time1, + // fibLevelPrice, + // time2, + // fibLevelPrice, + // clrYellow, + // STYLE_DOT + // ); + + // + if (isPositionOpened) { + // + bool canAlert = + alertPositions + && ( + hasLongSignal ? + longPositionAlerts + : + shortPositionAlerts + ); + + // + if (canAlert) { + // + // Alert Message ... + string message = StringConcatenate( + "Trade on Signal ID: ", request.signal.id, + ", Entry: ", request.signal.entry, + ", TP: ", request.signal.tp + ); + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } + } + } +} + +// +// Process All Open Positions ... +void ProcessOpenPositions() { + // + // this comes from check state ... + if (closeLongTrades) { + // + closeLongTrades = false; + + // + bool isAllLongTradesClosed = CloseAllLongTrades(); + if (isAllLongTradesClosed) { + } + } + + // + // this comes from check state ... + if (closeShortTrades) { + // + closeShortTrades = false; + + // + bool isAllShortTradesClosed = CloseAllShortTrades(); + if (isAllShortTradesClosed) { + } + } + + // + // Close All XXX Provided Signals on it's Specific Condition ... + if (xCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XXX_PROVIDER); + + // + xCloseLongTrades = false; + } + + // + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + closeAllOpenTradesAfterCandle + ); + + // + // Close Maximum DrawDown Passed Trades ... + bool hasClosedInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + maxDrawdownPercentPerPTrade + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedInDrawDownLongTrade + ) { + // + // waitForLongSignals = false; + } +} + +// +// Send Special Type of Alerts ... +void SendAlert(string message) { + // + if (!alertEvents) { + return; + } + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } +} +// +// END Functions ... +// + +// +// +// Calculate Signal ... +// in this function we calculate a signal exists in +// specific bar or not ... +XSignalRequest GenerateSignal( + const int bar_index // Bar Index ... +) { + // + // create temp result ... + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + bool hasSignal = false; + bool hasLongSignal = false; + bool hasShortSignal = false; + + // + XSignal signal = {}; + + // + // Retrieve XMA States ... + // based on medium cycle slow ... + XState states[]; + ArrayFree(states); + ArrayResize( + states, + marketLength + ); + + // + int index = 0; + for (int i = bar_index; i < bar_index + marketLength; i++) { + // + states[index] = GetXState( + i, + marketLength, + // + step, + maximum, + // + shortCycleMultiplier, + mediumCycleMultiplier, + longCycleMultiplier + ); + + // + index++; + } + + // + CheckSignalHandler( + bar_index, + marketLength, + states + ); + + // + CheckXLongSignalConditions( + bar_index, + marketLength, + states + ); + + // + XSignalRequest xLongSignalRequest = GenerateXSignal( + X_SIGNAL_LONG, + signalPrefix, + bar_index, + marketLength, + longCycleMultiplier, + riskToRewardRatio, + states + ); + + // // + // CheckXShortSignalConditions( + // bar_index, + // marketLength, + // states + // ); + + // // + // XSignalRequest xShortSignalRequest = GenerateXSignal( + // X_SIGNAL_SHORT, + // signalPrefix, + // bar_index, + // marketLength, + // longCycleMultiplier, + // riskToRewardRatio, + // states + // ); + + // + if (xLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXSignals( + xLongSignalRequest.signal, + states, + marketLength, + // + shortCycleMultiplier, + mediumCycleMultiplier, + longCycleMultiplier + ); + + // + if (isReady && xWaitForLongSignals) { + // + hasLongSignal = true; + signal = xLongSignalRequest.signal; + } else { + ClearXLongSignalConditions(); + } + // } else if (xShortSignalRequest.hasSignal) { + // // + // // Here we can Check and Filter Signals Based On State ... + // bool isReady = IsReadyForXSignals( + // xShortSignalRequest.signal, + // states, + // marketLength, + // // + // shortCycleMultiplier, + // mediumCycleMultiplier, + // longCycleMultiplier + // ); + + // // + // if (isReady) { + // // + // hasShortSignal = true; + // signal = xShortSignalRequest.signal; + // } else { + // ClearXShortSignalConditions(); + // } + } + + // + hasSignal = hasLongSignal || hasShortSignal; + + // + if (!hasSignal) { + // + signal.type = X_SIGNAL_NONE; + result.type = X_SIGNAL_NONE; + } + + // + // Normalize TP, SL and Entry Price ... + signal.tp = NormalizeDouble(signal.tp, _Digits); + signal.sl = NormalizeDouble(signal.sl, _Digits); + signal.entry = NormalizeDouble(signal.entry, _Digits); + + // + result.signal = signal; + result.type = signal.type; + result.hasSignal = hasSignal; + result.provider = signal.provider; + + // + // Return Result ... + return result; +} diff --git a/Bkp/Used/14020431/Experts/x-saherelm.xr.ea.mq4 b/Bkp/Used/14020431/Experts/x-saherelm.xr.ea.mq4 new file mode 100644 index 0000000..9ed9a38 --- /dev/null +++ b/Bkp/Used/14020431/Experts/x-saherelm.xr.ea.mq4 @@ -0,0 +1,720 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XST Strategy Expert Advisor +// --------------------------------------------- +// saherelm implementation of strategy expert advisor ... +// in this EA, we try to combine multiple tools, to ashive best +// results ... +// +// ShortName: XST +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +989121694056 +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XST Strategy Expert Advisor" +#property strict + +// +// START Inputs ... +// +// +// Signal Prefixe ... +input string signalPrefix = "XST"; // Signal Prefix + +// +// Signal Draw Specifications ... +input string bullishSignalLabel = "X_BUY"; // Bullish Signal Label +input color bullishSignalColor = clrAqua; // Bullish Signal Color + +// +input string bearishSignalLabel = "X_SELL"; // Bearish Signal Label +input color bearishSignalColor = clrFuchsia; // Bearish Signal Color + +// +input color signalEntryColor = clrAquamarine; // Signal Entry Ptice Color +input color signalSLColor = clrRed; // Signal SL Color +input color signalTPColor = clrGreen; // Signal TP Color + +// +input int candleGapBetweenSignals = 6; // How many Candle waits to new Signal from last one + +// +// Trade ... +input bool allowTrade = true; // Allow Trade Based on given Signals +input bool allowLongTrades = true; // Allow Long Trades +input bool allowShortTrades = false; // Allow Short Trades + +// +// Alerts ... +input bool alertEvents = true; // Alert Events +input bool alertPositions = true; // Alert Positions +input bool longPositionAlerts = true; // Alert Long Positions +input bool shortPositionAlerts = true; // Alert Short Positions + +// +// Alert Types ... +input bool terminalAlert = false; // Terminal Alert +input bool pushAlert = false; // Push Notification Alerts + +// +// Balance and Finanical Specifications ... +input double lotsPerTradePercent = 0.0003; // Lots Per Trade Percent +input int maxOpenTrades = 4; // Maximum Open Trade +input double maxDrawdownPercentPerPTrade = 0.3; // Maximum DrawDown Per Trade +input double minBalancePercent = 0.5; // Minimum Balance for Trading +input double maxEquityPercent = 0.1; // Maximum Trade Equity +input int closeAllOpenTradesAfterCandle = 252; // Close All Open Trades After Passed Candles +input bool closeAllInProfitOpenTradesWhenMaxOpenTradesReached = false; // Close All In Profit Open Trades When Max Open Trades Reached and New Signal Income + +// +// START Global Definitions: Variables, Properties and etc ... +// +int lastSignalledBar = 0; + +// +bool waitForLongSignals = true; +bool closeLongTrades = false; + +// +bool waitForShortSignals = true; +bool closeShortTrades = false; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.signal.lib.mq4" + +// +int maxMarketLength = 0; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Validate Inputs ... + bool inputsNotValiid = + // + // EA ... + lotsPerTradePercent < 0 + || maxOpenTrades <= 0 + || maxDrawdownPercentPerPTrade < 0 + || minBalancePercent < 0 + || maxEquityPercent < 0 + ; + + // + if (inputsNotValiid) { + return INIT_PARAMETERS_INCORRECT; + } + + // + totalSignals = 0; + totalLongSignals = 0; + totalShortSignals = 0; + + // + initialBalance = 0; + + // + // START Define Array Series ... + // + // + // END Define Array Series ... + // + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST"; + + // + ClearSignalConditions(); + + // + maxMarketLength = MathMax(0, GetDailyCandleCount()); + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { +} + +// +// Ticker Event Handler ... +void OnTick() { + // + isNewDay = IsNewDay(); + if (isNewDay) { + // + LogMessage( + StringConcatenate( + "New Day ..." + ) + ); + } + + // + // Process Signals to Open Positions ... + ProcessSignals(); + + // + // Checking State for Signal Handling ... + CheckState(); + + // + // Process Open Positions for Trailing Stop Loss or Close ... + ProcessOpenPositions(); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Check State for Signal Handling ... +void CheckState() { + // + // Here we Must to Check Market State for enable or disable + // Signal Handlers and also make dection to close all long/short + // trades ... +} + +// +// Calculate Signals and Process Based on Exists Signals ... +void ProcessSignals() { + // + XSignalRequest request = {}; + request.type = X_SIGNAL_NONE; + request.hasSignal = false; + + // + // Prevent Multiple Calculating on Same Bars ... + isNewBar = IsNewBar(); + if (isNewBar) { + countedBars++; + } + + // + if (countedBars < maxMarketLength) { + return; + } + + // + bool allowDoTrade = true; + + // + // Check Balance ... + if (initialBalance > 0) { + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double minimumBalanceForTrade = + balance > initialBalance + ? + minBalancePercent * balance + : + minBalancePercent * initialBalance; + + // + // Retrieve Account Equity ... + double equity = AccountInfoDouble(ACCOUNT_EQUITY); + double maxAllowedEquity = balance - (balance * maxEquityPercent); + + // + // Retrieve Free Marigin ... + double freeMargin = AccountFreeMargin(); + double maximumMariginRisk = balance - (balance * maxEquityPercent); + + // + if ( + // + // Do not Open Positions if equity not passed ... + equity < maxAllowedEquity || + // + // Do not Open Positions if free margin not passed ... + freeMargin <= maximumMariginRisk || + // + // Do not open positions if balance less than minimum ... + balance <= minimumBalanceForTrade + ) { + // + allowDoTrade = false; + + // // + // string message = StringConcatenate( + // "Trading Pause => ", + // "Balance: ", balance, + // ", Equity: ", equity, + // ", FreeMargin: ", freeMargin + // ); + + // // + // LogMessage(message); + // SendAlert(message); + } + } + + // + // Retrieve Signal Exists ... + request = GenerateSignal(0); + + // + // Prevent doing anything else, if there is no signals ... + if ( + !allowDoTrade || + !request.hasSignal || + request.type == X_SIGNAL_NONE + ) { + return; + } + + // + bool hasLongSignal = request.type == X_SIGNAL_LONG; + + // + // Check For Bot State ... + if ( + (hasLongSignal && !waitForLongSignals) + || (!hasLongSignal && !waitForShortSignals) + ) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + return; + } + + // + // Check last Signalled Bar with Counted Bars ... + // Prevent Multiple Signalling on Same Bar ... + bool isInLastSignalledBars = false; + for (int i=0; i < candleGapBetweenSignals; i++) { + // + isInLastSignalledBars = + isInLastSignalledBars + || lastSignalledBar == countedBars - i + ; + } + if (isInLastSignalledBars) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + return; + } + + // + // increase last signalled bar ... + lastSignalledBar = countedBars; + + // + // Calculate Can Trade or not ... + allowDoTrade = allowTrade + && ( + hasLongSignal ? + allowLongTrades : + allowShortTrades + ); + + // + // Chack Maximum Open Positions ... + int openTrades = CountOpenTrades(); + if (maxOpenTrades > 0) { + // + if (openTrades >= maxOpenTrades) { + // + allowDoTrade = false; + + // + if (closeAllInProfitOpenTradesWhenMaxOpenTradesReached) { + // + // Close All In Profit Trades ... + bool hasClosedInProfitTrade = CloseAllInProfitTrades(); + if (hasClosedInProfitTrade) { + // + openTrades = CountOpenTrades(); + + // + allowDoTrade = !(openTrades >= maxOpenTrades); + } + } + + // + if (!allowDoTrade) { + // + string message = StringConcatenate( + "Trading Pause => ", + "Max Open Trades (", + maxOpenTrades, + ") reached ..." + ); + + // + LogMessage(message); + SendAlert(message); + } + } + } + + // + // Check Trading is Enable or not ... + // nothing to do if trading is disabled ... + if (!allowDoTrade) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // // + // string message = StringConcatenate( + // "Trading Not Allowed ..." + // ); + + // // + // LogMessage(message); + // SendAlert(message); + return; + } + + // + bool isPositionOpened = TradeSignal( + request.signal, + lotsPerTradePercent, + // + bullishSignalLabel, + bullishSignalColor, + bearishSignalLabel, + bearishSignalColor + ); + + // + totalSignals++; + if (hasLongSignal) { + // + totalLongSignals++; + ClearLongSignalConditions(); + } else { + // + totalShortSignals++; + ClearShortSignalConditions(); + } + + // + // Draw XRState ... + if (isPositionOpened) { + // + XRState state = GetXRange( + 0 + ); + + // + string lblXRHH = StringConcatenate( + request.signal.tag, + "_XR_HH_", state.hh + ); + + // + // HH ... + DrawTrendLine( + 0, + lblXRHH, + 0, + state.start, + state.hh, + request.signal.time, + state.hh, + clrLime, + STYLE_DASH + ); + + // + string lblXRMID = StringConcatenate( + request.signal.tag, + "_XR_MID_", state.mid + ); + + // + // MID ... + DrawTrendLine( + 0, + lblXRMID, + 0, + state.start, + state.mid, + request.signal.time, + state.mid, + clrYellow, + STYLE_DASHDOT + ); + + // + string lblXRLL = StringConcatenate( + request.signal.tag, + "_XR_LL_", state.ll + ); + + // + // HH ... + DrawTrendLine( + 0, + lblXRLL, + 0, + state.start, + state.ll, + request.signal.time, + state.ll, + clrRed, + STYLE_DASH + ); + } + + // + if (isPositionOpened) { + // + bool canAlert = + alertPositions + && ( + hasLongSignal ? + longPositionAlerts + : + shortPositionAlerts + ); + + // + if (canAlert) { + // + // Alert Message ... + string message = StringConcatenate( + "Trade on Signal ID: ", request.signal.id, + ", Entry: ", request.signal.entry, + ", TP: ", request.signal.tp + ); + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } + } + } +} + +// +// Process All Open Positions ... +void ProcessOpenPositions() { + // + // this comes from check state ... + if (closeLongTrades) { + // + closeLongTrades = false; + + // + bool isAllLongTradesClosed = CloseAllLongTrades(); + if (isAllLongTradesClosed) { + } + } + + // + // this comes from check state ... + if (closeShortTrades) { + // + closeShortTrades = false; + + // + bool isAllShortTradesClosed = CloseAllShortTrades(); + if (isAllShortTradesClosed) { + } + } + + // + // Close All XXX Provided Signals on it's Specific Condition ... + if (xCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XXX_PROVIDER); + + // + xCloseLongTrades = false; + } + + // + if (xrCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XR_PROVIDER); + + // + xrCloseLongTrades = false; + } + + // + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + closeAllOpenTradesAfterCandle + ); + + // + // Close Maximum DrawDown Passed Trades ... + bool hasClosedInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + maxDrawdownPercentPerPTrade + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedInDrawDownLongTrade + ) { + // + // waitForLongSignals = false; + } +} + +// +// Send Special Type of Alerts ... +void SendAlert(string message) { + // + if (!alertEvents) { + return; + } + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } +} +// +// END Functions ... +// + +// +// +// Calculate Signal ... +// in this function we calculate a signal exists in +// specific bar or not ... +XSignalRequest GenerateSignal( + const int bar_index // Bar Index ... +) { + // + // create temp result ... + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + bool hasSignal = false; + bool hasLongSignal = false; + bool hasShortSignal = false; + + // + XSignal signal = {}; + + // + CheckXRSignalHandler( + bar_index + ); + + // + CheckXRLongSignalConditions( + bar_index + ); + + // + XSignalRequest xrLongSignalRequest = GenerateXRSignal( + X_SIGNAL_LONG, + signalPrefix, + bar_index + ); + + // + if (xrLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXRSignals( + xrLongSignalRequest.signal + ); + + // + if (isReady && xWaitForLongSignals) { + // + hasLongSignal = true; + signal = xrLongSignalRequest.signal; + } else { + ClearXRLongSignalConditions(); + } + } + + // + hasSignal = hasLongSignal || hasShortSignal; + + // + if (!hasSignal) { + // + signal.type = X_SIGNAL_NONE; + result.type = X_SIGNAL_NONE; + } + + // + // Normalize TP, SL and Entry Price ... + signal.tp = NormalizeDouble(signal.tp, _Digits); + signal.sl = NormalizeDouble(signal.sl, _Digits); + signal.entry = NormalizeDouble(signal.entry, _Digits); + + // + result.signal = signal; + result.type = signal.type; + result.hasSignal = hasSignal; + result.provider = signal.provider; + + // + // Return Result ... + return result; +} diff --git a/Bkp/Used/14020431/Indicators/x-saherelm.ma.mq4 b/Bkp/Used/14020431/Indicators/x-saherelm.ma.mq4 new file mode 100644 index 0000000..e3a5737 --- /dev/null +++ b/Bkp/Used/14020431/Indicators/x-saherelm.ma.mq4 @@ -0,0 +1,173 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MA Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 MA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Fast MA ... +input int maLength = 20; // MA Length +input int maShift = 0; // MA Shift +input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method +input ENUM_APPLIED_PRICE maAppliedPrice = PRICE_CLOSE; // MA Applied Price + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 1 + +// +#property indicator_plots 1 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Fast Ma Buffer ... +#property indicator_label1 "Ma" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrYellow +#property indicator_style1 STYLE_DOT +#property indicator_width1 2 + +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define maBufferIndex 0 + +double maBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (maLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + // + // Ma ... + SetIndexBuffer(maBufferIndex, maBuffer); + SetIndexDrawBegin(maBufferIndex, maLength + 1); + // + // End Set Index Buffers ... + // + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, maLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Ma ... + CalculateMa(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateMa( + const int &bar_index +) { + // + // Calculating Fast Ma ... + double ma = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + maAppliedPrice, + bar_index + ); + + // + maBuffer[bar_index] = ma; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020431/Indicators/x-saherelm.x.hl.mq4 b/Bkp/Used/14020431/Indicators/x-saherelm.x.hl.mq4 new file mode 100644 index 0000000..f08a975 --- /dev/null +++ b/Bkp/Used/14020431/Indicators/x-saherelm.x.hl.mq4 @@ -0,0 +1,412 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center X Indicator +// --------------------------------------------- +// saherelm implementation of above 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 X Indicator" +#property strict + +// +// START Inputs ... +// +// +input int marketLength = 7; // Market Length + +// +input int shortCycleMultiplier = 2; // Market Short Cycle Multiplier +input int mediumCycleMultiplier = 6; // Market Medium Cycle Multiplier +input int longCycleMultiplier = 36; // Market Medium Cycle Multiplier + +// +input ENUM_MA_METHOD maMethod = MODE_SMA; // Ma Method +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 6 + +// +#property indicator_plots 6 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Short Cycle Highest High Buffer ... +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +// Short Cycle Lowest Low Buffer ... +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +// Medium Cycle Highest High Buffer ... +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrAqua +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 + +// +// Medium Cycle Lowest Low Buffer ... +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrFuchsia +#property indicator_style4 STYLE_DOT +#property indicator_width4 1 + +// +// Long Cycle Highest High Buffer ... +#property indicator_type5 DRAW_LINE +#property indicator_color5 C'62,82,6' +#property indicator_style5 STYLE_DOT +#property indicator_width5 1 + +// +// Long Cycle Lowest Low Buffer ... +#property indicator_type6 DRAW_LINE +#property indicator_color6 C'255,81,0' +#property indicator_style6 STYLE_DOT +#property indicator_width6 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +// +// HH Buffers ... +#define scHHBufferIndex 0 +#define scLLBufferIndex 1 +#define mcHHBufferIndex 2 +#define mcLLBufferIndex 3 +#define lcHHBufferIndex 4 +#define lcLLBufferIndex 5 + +double scHHBuffer[]; +double scLLBuffer[]; +double mcHHBuffer[]; +double mcLLBuffer[]; +double lcHHBuffer[]; +double lcLLBuffer[]; + +// +// Variables ... +int shortCycleLength; +int mediumCycleLength; +int longCycleLength; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if ( + marketLength <= 0 || + shortCycleMultiplier <= 0 || + mediumCycleMultiplier <= 0 || + shortCycleMultiplier > mediumCycleMultiplier + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + shortCycleLength = shortCycleMultiplier * marketLength; + mediumCycleLength = mediumCycleMultiplier * marketLength; + longCycleLength = longCycleMultiplier * marketLength; + + // + // Highest High and Lowest Low Buffers ... + // + // Short Cycle Highest High ... + string scHHLbl = StringConcatenate( + "SC HH(", shortCycleLength, ")" + ); + SetIndexBuffer(scHHBufferIndex, scHHBuffer); + SetIndexLabel(scHHBufferIndex, scHHLbl); + + // + // Short Cycle Lowest Low ... + string scLLLbl = StringConcatenate( + "SC LL(", shortCycleLength, ")" + ); + SetIndexBuffer(scLLBufferIndex, scLLBuffer); + SetIndexLabel(scLLBufferIndex, scLLLbl); + + // + // Medium Cycle Highest High ... + string mcHHLbl = StringConcatenate( + "MC HH(", mediumCycleLength, ")" + ); + SetIndexBuffer(mcHHBufferIndex, mcHHBuffer); + SetIndexLabel(mcHHBufferIndex, mcHHLbl); + + // + // Medium Cycle Lowest Low ... + string mcLLLbl = StringConcatenate( + "MC LL(", mediumCycleLength, ")" + ); + SetIndexBuffer(mcLLBufferIndex, mcLLBuffer); + SetIndexLabel(mcLLBufferIndex, mcLLLbl); + + // + // Long Cycle Highest High ... + string lcHHLbl = StringConcatenate( + "LC HH(", longCycleLength, ")" + ); + SetIndexBuffer(lcHHBufferIndex, lcHHBuffer); + SetIndexLabel(lcHHBufferIndex, lcHHLbl); + + // + // Long Cycle Lowest Low ... + string lcLLLbl = StringConcatenate( + "LC LL(", longCycleLength, ")" + ); + SetIndexBuffer(lcLLBufferIndex, lcLLBuffer); + SetIndexLabel(lcLLBufferIndex, lcLLLbl); + // + // End Set Index Buffers ... + // + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculat Ma's ... + // + CalculateShortCycle(i); + + // + CalculateMediumCycle(i); + + // + CalculateLongCycle(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Short Cycle ... +void CalculateShortCycle( + const int &bar_index +) { + // + // Short Cycle Highest High ... + // + int scHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + shortCycleLength, + bar_index + ); + + // + double scHH = iHigh( + _Symbol, + _Period, + scHHIdx + ); + + // + scHHBuffer[bar_index] = scHH; + + // + // Short Cycle Lowest Low ... + // + int scLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + shortCycleLength, + bar_index + ); + + // + double scLL = iLow( + _Symbol, + _Period, + scLLIdx + ); + + // + scLLBuffer[bar_index] = scLL; +} + +// +// Calculating Medium Cycle ... +void CalculateMediumCycle( + const int &bar_index +) { + // + // Medium Cycle Highest High ... + // + int mcHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + mediumCycleLength, + bar_index + ); + + // + double mcHH = iHigh( + _Symbol, + _Period, + mcHHIdx + ); + + // + mcHHBuffer[bar_index] = mcHH; + + // + // Medium Cycle Lowest Low ... + // + int mcLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + mediumCycleLength, + bar_index + ); + + // + double mcLL = iLow( + _Symbol, + _Period, + mcLLIdx + ); + + // + mcLLBuffer[bar_index] = mcLL; +} + +// +// Calculating Long Cycle ... +void CalculateLongCycle( + const int &bar_index +) { + // + // Long Cycle Highest High ... + // + int lcHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + longCycleLength, + bar_index + ); + + // + double lcHH = iHigh( + _Symbol, + _Period, + lcHHIdx + ); + + // + lcHHBuffer[bar_index] = lcHH; + + // + // Long Cycle Lowest Low ... + // + int lcLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + longCycleLength, + bar_index + ); + + // + double lcLL = iLow( + _Symbol, + _Period, + lcLLIdx + ); + + // + lcLLBuffer[bar_index] = lcLL; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020431/Indicators/x-saherelm.x.range.mq4 b/Bkp/Used/14020431/Indicators/x-saherelm.x.range.mq4 new file mode 100644 index 0000000..1359f57 --- /dev/null +++ b/Bkp/Used/14020431/Indicators/x-saherelm.x.range.mq4 @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XRange Indicator +// --------------------------------------------- +// saherelm implementation of above 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 XRange Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 14; +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 3 + +// +#property indicator_plots 3 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Highest High Buffer ... +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +// Lowest Low Buffer ... +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +// Middle Buffer ... +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_DASH +#property indicator_width3 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +// +#define highestHighBufferIndex 0 +#define lowestLowBufferIndex 1 +#define middleBufferIndex 2 + +// +double highestHighBuffer[]; +double lowestLowBuffer[]; +double middleBuffer[]; + +// +datetime startTime; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if ( + marketLength <= 0 + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + string hhLbl = StringConcatenate( + "XR HH(", marketLength, ")" + ); + SetIndexBuffer(highestHighBufferIndex, highestHighBuffer); + SetIndexLabel(highestHighBufferIndex, hhLbl); + + // + string llLbl = StringConcatenate( + "XR LL(", marketLength, ")" + ); + SetIndexBuffer(lowestLowBufferIndex, lowestLowBuffer); + SetIndexLabel(lowestLowBufferIndex, llLbl); + + // + string midLbl = StringConcatenate( + "XR Mid(", marketLength, ")" + ); + SetIndexBuffer(middleBufferIndex, middleBuffer); + SetIndexLabel(middleBufferIndex, midLbl); + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculations ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculations ... +void CalculateBuffers( + const int &bar_index +) { + // + // Retrieve Bar Time ... + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + if (startTime == 0) { + // + startTime = barTime; + SetIndicatorBuffersNone(bar_index); + return; + } + + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + startTime + ); + + // + int startDistance = startBarIndex - bar_index; + if (startDistance < marketLength) { + // + SetIndicatorBuffersNone(bar_index); + return; + } + + // + // Highest High ... + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLength, + bar_index + ); + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + highestHighBuffer[bar_index] = hh; + + // + // Lowest Low ... + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLength, + bar_index + ); + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + lowestLowBuffer[bar_index] = ll; + + // + // Middle Buffer ... + double mid = (hh + ll) / 2; + middleBuffer[bar_index] = mid; + + // + // Reset Start Time ... + startTime = 0; +} + +// +void SetIndicatorBuffersNone( + const int bar_index +) { + // + int lastBarIndex = bar_index + 1; + + // + double lastHighestHigh; + double lastLowestLow; + + // + // Highest High ... + if (ArraySize(highestHighBuffer) > lastBarIndex) { + lastHighestHigh = highestHighBuffer[lastBarIndex]; + } else { + lastHighestHigh = 0; + } + + // + // Lowest Low ... + if (ArraySize(lowestLowBuffer) > lastBarIndex) { + lastLowestLow = lowestLowBuffer[lastBarIndex]; + } else { + lastLowestLow = 0; + } + + // + highestHighBuffer[bar_index] = lastHighestHigh; + lowestLowBuffer[bar_index] = lastLowestLow; + + // + double mid = (lastHighestHigh + lastLowestLow) / 2; + middleBuffer[bar_index] = mid; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020431/Indicators/x-saherelm.x.xma.mq4 b/Bkp/Used/14020431/Indicators/x-saherelm.x.xma.mq4 new file mode 100644 index 0000000..b8c64d7 --- /dev/null +++ b/Bkp/Used/14020431/Indicators/x-saherelm.x.xma.mq4 @@ -0,0 +1,395 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center X Indicator +// --------------------------------------------- +// saherelm implementation of above 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 X Indicator" +#property strict + +// +// START Inputs ... +// +// +input int marketLength = 7; // Market Length + +// +input double step = 0.02; // P SAR Step +input double maximum = 0.2; // P SAR Maximum + +// +input int shortCycleMultiplier = 2; // Market Short Cycle Multiplier +input int mediumCycleMultiplier = 6; // Market Medium Cycle Multiplier +input int longCycleMultiplier = 36; // Market Medium Cycle Multiplier + +// +input ENUM_MA_METHOD maMethod = MODE_SMA; // Ma Method +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 7 + +// +#property indicator_plots 7 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Short Cycle Fast Buffer ... +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +// Short Cycle Slow Buffer ... +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +// Medium Cycle Fast Buffer ... +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrAqua +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 + +// +// Medium Cycle Slow Buffer ... +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrFuchsia +#property indicator_style4 STYLE_DOT +#property indicator_width4 1 + +// +// Long Cycle Fast Buffer ... +#property indicator_type5 DRAW_LINE +#property indicator_color5 C'62,82,6' +#property indicator_style5 STYLE_DOT +#property indicator_width5 1 + +// +// Long Cycle Slow Buffer ... +#property indicator_type6 DRAW_LINE +#property indicator_color6 C'255,81,0' +#property indicator_style6 STYLE_DOT +#property indicator_width6 1 + +// +// Parabolic SAR ... +#property indicator_type7 DRAW_LINE +#property indicator_color7 C'0,174,255' +#property indicator_style7 STYLE_DASHDOT +#property indicator_width7 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +// +// Ma Buffers ... +#define scFastBufferIndex 0 +#define scSlowBufferIndex 1 +#define mcFastBufferIndex 2 +#define mcSlowBufferIndex 3 +#define lcFastBufferIndex 4 +#define lcSlowBufferIndex 5 +#define psarBufferIndex 6 + +double scFastBuffer[]; +double scSlowBuffer[]; +double mcFastBuffer[]; +double mcSlowBuffer[]; +double lcFastBuffer[]; +double lcSlowBuffer[]; +double psarBuffer[]; + +// +// Variables ... +int shortCycleLength; +int mediumCycleLength; +int longCycleLength; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if ( + marketLength <= 0 || + shortCycleMultiplier <= 0 || + mediumCycleMultiplier <= 0 || + shortCycleMultiplier > mediumCycleMultiplier + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + shortCycleLength = shortCycleMultiplier * marketLength; + mediumCycleLength = mediumCycleMultiplier * marketLength; + longCycleLength = longCycleMultiplier * marketLength; + + // + // Ma Buffers ... + // + // Short Cycle ... + string scFLbl = StringConcatenate( + "SC F(", shortCycleLength, ")" + ); + SetIndexBuffer(scFastBufferIndex, scFastBuffer); + SetIndexLabel(scFastBufferIndex, scFLbl); + + // + string scSLbl = StringConcatenate( + "SC S(", shortCycleLength, ")" + ); + SetIndexBuffer(scSlowBufferIndex, scSlowBuffer); + SetIndexLabel(scSlowBufferIndex, scSLbl); + + // + // Medium Cycle ... + string mcFLbl = StringConcatenate( + "MC F(", mediumCycleLength, ")" + ); + SetIndexBuffer(mcFastBufferIndex, mcFastBuffer); + SetIndexLabel(mcFastBufferIndex, mcFLbl); + + // + string mcSLbl = StringConcatenate( + "MC S(", mediumCycleLength, ")" + ); + SetIndexBuffer(mcSlowBufferIndex, mcSlowBuffer); + SetIndexLabel(mcSlowBufferIndex, mcSLbl); + + // + // Long Cycle ... + string lcFLbl = StringConcatenate( + "LC F(", longCycleLength, ")" + ); + SetIndexBuffer(lcFastBufferIndex, lcFastBuffer); + SetIndexLabel(lcFastBufferIndex, lcFLbl); + + // + string lcSLbl = StringConcatenate( + "LC S(", longCycleLength, ")" + ); + SetIndexBuffer(lcSlowBufferIndex, lcSlowBuffer); + SetIndexLabel(lcSlowBufferIndex, lcSLbl); + // + // End Set Index Buffers ... + // + + // + // Parabolic Sar ... + SetIndexBuffer(psarBufferIndex, psarBuffer); + SetIndexLabel(psarBufferIndex, "P Sar"); + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculat Ma's ... + // + CalculateShortCycle(i); + + // + CalculateMediumCycle(i); + + // + CalculateLongCycle(i); + + // + // Parabolic SAR ... + CalculateParabolicSAR(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Short Cycle ... +void CalculateShortCycle( + const int &bar_index +) { + // + double scFast = iMA( + _Symbol, + _Period, + shortCycleLength, + 0, + maMethod, + PRICE_OPEN, + bar_index + ); + scFastBuffer[bar_index] = scFast; + + // + double scSlow = iMA( + _Symbol, + _Period, + shortCycleLength, + 0, + maMethod, + PRICE_CLOSE, + bar_index + ); + scSlowBuffer[bar_index] = scSlow; +} + +// +// Calculating Medium Cycle ... +void CalculateMediumCycle( + const int &bar_index +) { + // + double mcFast = iMA( + _Symbol, + _Period, + mediumCycleLength, + 0, + maMethod, + PRICE_OPEN, + bar_index + ); + mcFastBuffer[bar_index] = mcFast; + + // + double mcSlow = iMA( + _Symbol, + _Period, + mediumCycleLength, + 0, + maMethod, + PRICE_CLOSE, + bar_index + ); + mcSlowBuffer[bar_index] = mcSlow; +} + +// +// Calculating Long Cycle ... +void CalculateLongCycle( + const int &bar_index +) { + // + double lcFast = iMA( + _Symbol, + _Period, + longCycleLength, + 0, + maMethod, + PRICE_OPEN, + bar_index + ); + lcFastBuffer[bar_index] = lcFast; + + // + double lcSlow = iMA( + _Symbol, + _Period, + longCycleLength, + 0, + maMethod, + PRICE_CLOSE, + bar_index + ); + lcSlowBuffer[bar_index] = lcSlow; +} + +// +// Calculate Parabolic SAR ... +void CalculateParabolicSAR( + const int &bar_index +) { + // + double pSar = iSAR( + _Symbol, + _Period, + step, + maximum, + bar_index + ); + + // + psarBuffer[bar_index] = pSar; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020431/Libraries/x-saherelm.draw.lib.mq4 b/Bkp/Used/14020431/Libraries/x-saherelm.draw.lib.mq4 new file mode 100644 index 0000000..08fefa7 --- /dev/null +++ b/Bkp/Used/14020431/Libraries/x-saherelm.draw.lib.mq4 @@ -0,0 +1,1670 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Start Arrow Functions ... +// +// +// Draw an Arrow Object on Chart ... +bool DrawArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // arrow name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const uchar arrowCode = OBJ_ARROW_UP, // arrow code + const ENUM_ARROW_ANCHOR anchor = ANCHOR_BOTTOM, // anchor point position + const color clr = clrAqua, // arrow color + const ENUM_LINE_STYLE style = STYLE_SOLID, // border line style + const int width = 3, // arrow size + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // Order Object ... +) { + // + // set anchor point coordinates if they are not set ... + ChangeArrowEmptyPoint(time, price); + + // + // reset the error value ... + ResetLastError(); + + // + // create an arrow ... + if(!ObjectCreate(chartID, name, OBJ_ARROW, subWindow, time, price)) { + // + string message = StringConcatenate(__FUNCTION__, + ": failed to create an arrow! Error code = ", + GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the arrow code ... + ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, arrowCode); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set the arrow color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set the border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set the arrow's size ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the arrow by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is false by default, if you want making it possible to highlight and move the object + // change it to true ... + ObjectSetInteger(chartID,name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point of Arrow ... +bool MoveArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if(!time) { + time = TimeCurrent(); + } + + // + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete an arrow ... +bool DeleteArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow" // arrow name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete an arrow ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete an arrow! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the arrow code ... +bool ArrowCodeChange( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + const uchar code = 252 // arrow code +) { + // + // reset the error value ... + ResetLastError(); + + // + // change the arrow code ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, code)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the arrow code! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change anchor type ... +bool ArrowAnchorChange( + const long chartID = 0, // chart's ID + const string name="Arrow", // object name + const ENUM_ARROW_ANCHOR anchor = ANCHOR_TOP // anchor type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change anchor type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change anchor type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeArrowEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } +} +// +// End Arrow Functions ... +// + +// +// Start Horizontal Line Functions ... +// +// +// Create, Draw the horizontal line ... +bool DrawHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + const int subWindow = 0, // subwindow index + double price = 0, // line price + const color clr = clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the price is not set, set it at the current Bid price level ... + if(!price) { + price=SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // create a horizontal line ... + if(!ObjectCreate(chartID, name, OBJ_HLINE, subWindow, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move horizontal line ... +bool MoveHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + double price = 0 // line price +) { + // + // if the line price is not set, move it to the current Bid price level ... + if(!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move a horizontal line ... + if(!ObjectMove(chartID, name, 0, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete a horizontal line ... +bool DeleteHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a horizontal line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End Horizontal Line Functions ... +// + +// +// Start Vertical Line Functions ... +// +// +// Create the vertical line ... +bool DrawVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + const int sub_window = 0, // subwindow index + datetime time = 0, // line time + const color clr=clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the line time is not set, draw it via the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value + ResetLastError(); + + // + // create a vertical line ... + if (!ObjectCreate(chartID, name, OBJ_VLINE, sub_window, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return true; +} + +// +// Move the vertical line ... +bool MoveVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + datetime time = 0 // line time +) { + // + // if line time is not set, move the line to the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the vertical line ... + if(!ObjectMove(chartID, name, 0, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the vertical line ... +bool DeleteVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the vertical line ... + if (!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // successful execution ... + return true; +} +// +// End Vertical Line Functions ... +// + +// +// Start RectangleLabel Functions ... +// +// +// Create Rectangle Label Object ... +bool DrawRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int subWindow = 0, // subwindow index + const int x = 0, // X coordinate + const int y = 0, // Y coordinate + const int width = 50, // width + const int height = 18, // height + const color back_clr = C'236,233,216', // background color + const ENUM_BORDER_TYPE border = BORDER_SUNKEN, // border type + const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring + const color clr = clrRed, // flat border color (Flat) + const ENUM_LINE_STYLE style = STYLE_SOLID, // flat border style + const int lineWidth = 1, // flat border width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // reset the error value ... + ResetLastError(); + + // + //--- create a rectangle label + if(!ObjectCreate(chartID, name, OBJ_RECTANGLE_LABEL, subWindow, 0, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set label coordinates ... + ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x); + ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y); + + // + // set label size ... + ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width); + ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height); + + // + // set background color ... + ObjectSetInteger(chartID, name, OBJPROP_BGCOLOR, back_clr); + + // + // set border type ... + ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border); + + // + // set the chart's corner, relative to which point coordinates are defined ... + ObjectSetInteger(chartID, name, OBJPROP_CORNER, corner); + + // + // set flat border color (in Flat mode) ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set flat border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set flat border width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, lineWidth); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the label by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move Rectangle Label .. +bool MoveRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int x = 0, // X coordinate + const int y=0 // Y coordinate +) { + // + // reset the error value ... + ResetLastError(); + + // + // move the rectangle label ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move X coordinate of the label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move Y coordinate of the label! Error code = ",GetLastError() + ); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the rectangle label ... +bool DeleteRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel" // label name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the label ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change Rectangle Label Size ... +bool ChangeSizeRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int width = 50, // label width + const int height = 18 // label height +) { + // + // reset the error value ... + ResetLastError(); + + // + // change label size ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's width! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's height! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change rectangle label border type ... +bool RectLabelChangeBorderType( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const ENUM_BORDER_TYPE border = BORDER_SUNKEN // border type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change border type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the border type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End RectangleLabel Functions ... +// + +// +// Start TrendLine Funcions ... +// +// Create a trend line by the given coordinates ... +bool DrawTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrYellow, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool rayRight = false, // line's continuation to the right + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeTrendLineEmptyPoints( + time1, + price1, + time2, + price2 + ); + + // + // reset the error value ... + ResetLastError(); + + // + // create a trend line by the given coordinates ... + if(!ObjectCreate(chartID, name, OBJ_TREND, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the line's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move trend line anchor point ... | +bool ChangeTrendLinePoint( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int pointindex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move trend line's anchor point ... + if(!ObjectMove(chartID, name, pointindex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// The function deletes the trend line from the chart ... +bool DeleteTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a trend line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of trend line's anchor points and set default ... +// values for empty ones ... +void ChangeTrendLineEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the first point's time is not set, it will be on the current bar ... + if (!time1) { + time1 = TimeCurrent(); + } + + // + // if the first point's price is not set, it will have Bid value ... + if (!price1) { + price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // if the second point's time is not set, it is located 9 bars left from the second one ... + if (!time2) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(), Period(), time1, 10, temp); + + // + // set the second point 9 bars left from the first one ... + time2 = temp[0]; + } + + // + // if the second point's price is not set, it is equal to the first point's one ... + if (!price2) { + price2 = price1; + } +} +// +// End TrendLine Functions ... +// + +// +// Start Text Functions ... +// +// Create and Draw a Text Object ... +bool DrawText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const string text = "Text", // the text itself + const string font = "Arial", // font + const int fontSize = 10, // font size + const color clr = clrRed, // color + const double angle = 0.0, // text slope + const ENUM_ANCHOR_POINT anchor = ANCHOR_CENTER, // anchor type + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor point coordinates if they are not set ... + ChangeTextEmptyPoint(time,price); + + // + // reset the error value ... + ResetLastError(); + + // + //--- create Text object + if(!ObjectCreate(chartID, name, OBJ_TEXT, subWindow, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the text ... + ObjectSetString(chartID, name , OBJPROP_TEXT, text); + + // + // set text font ... + ObjectSetString(chartID, name, OBJPROP_FONT, font); + + // + // set font size ... + ObjectSetInteger(chartID, name, OBJPROP_FONTSIZE, fontSize); + + // + // set the slope angle of the text ... + ObjectSetDouble(chartID, name, OBJPROP_ANGLE, angle); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the object by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID ,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point ... +bool MoveText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + //--- if point position is not set, move it to the current bar having Bid price + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point .. + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the object text ... +bool ChangeText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const string text = "Text" // text +) { + // + // reset the error value ... + ResetLastError(); + + // + // change object text ... + if(!ObjectSetString(chartID, name, OBJPROP_TEXT, text)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the text! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Text object ... +bool DeleteText( + const long chartID = 0, // chart's ID + const string name = "Text" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeTextEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + } +// +// End Text Functions ... +// + +// +// Start Fibonacchi Functions ... +// +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawFibonacci( + const long chartID = 0, // chart's ID + const string name="Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrRed, // object color + const ENUM_LINE_STYLE style = STYLE_SOLID, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawCustomFibonacci( + // + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + // + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrAqua, // object color + const ENUM_LINE_STYLE style = STYLE_DOT, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // Change Levels Of Fibonacci ... + bool result = FibonacciLevelsSet( + levels, + values, + colors, + styles, + widths, + descriptions, + chartID, + name + ); + + // + // successful execution ... + return result; +} + +// +// Set number of levels and their parameters ... +bool FibonacciLevelsSet( + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // check array sizes ... + if( + levels!=ArraySize(colors) || + levels!=ArraySize(styles) || + levels!=ArraySize(widths) || + levels!=ArraySize(widths) + ) { + // + string message = StringConcatenate( + __FUNCTION__, + ": array length does not correspond to the number of levels, error!" + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the number of levels ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELS, levels); + + // + // set the properties of levels in the loop ... + for(int i = 0; i < levels; i++) { + // + // level value ... + ObjectSetDouble(chartID, name, OBJPROP_LEVELVALUE, i, values[i]); + + // + // level color ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELCOLOR, i, colors[i]); + + // + // level style ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELSTYLE, i, styles[i]); + + // + // level width ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELWIDTH, i, widths[i]); + + // + // level description ... + // ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, DoubleToString(100 * values[i], 1)); + ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, descriptions[i]); + } + + // + // successful execution ... + return(true); +} + +// +// Move Fibonacci Retracement anchor point ... +bool FibonacciPointChange( + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int pointIndex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, pointIndex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Fibonacci Retracement ... +bool DeleteFibonachi( + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Fibonacci Retracement\"! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of Fibonacci Retracement anchor points and set +// default values for empty ones ... +void ChangeFibonacciEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the second point's time is not set, it will be on the current bar ... + if (!time2) { + time2 = TimeCurrent(); + } + + // + // if the second point's price is not set, it will have Bid value ... + if (!price2) { + price2 = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // if the first point's time is not set, it is located 9 bars left from the second one ... + if (!time1) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(),Period(),time2,10,temp); + + // + // set the first point 9 bars left from the second one ... + time1 = temp[0]; + } + + // + // if the first point's price is not set, move it 200 points below the second one ... + if (!price1) { + price1 = price2 - 200 * SymbolInfoDouble(_Symbol, SYMBOL_POINT); + } +} +// +// End Fibonacci Functions ... +// + + +// +// Start General Functions ... +// +// +// Remove all Drawn Objects ... +void RemoveDraws(const string &tag) { + // + for(int iObj=ObjectsTotal()-1; iObj >= 0; iObj--) { + // + string on = ObjectName(iObj); + if (StringFind(on, tag) == 0) { + ObjectDelete(on); + } + } +} +// +// End General Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020431/Libraries/x-saherelm.indicator.lib.mq4 b/Bkp/Used/14020431/Libraries/x-saherelm.indicator.lib.mq4 new file mode 100644 index 0000000..f562939 --- /dev/null +++ b/Bkp/Used/14020431/Libraries/x-saherelm.indicator.lib.mq4 @@ -0,0 +1,535 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Indicator Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +double GetMaxRangeAllowedTP( + const ENUM_X_SIGNAL_TYPE type, + const XRange &range +) { + // + bool isLongSignal = + type != X_SIGNAL_NONE + && type == X_SIGNAL_LONG + ; + + // + double maxAllowedTPRange = ((range.levels - 0.5) * range.rate); + + // + double result = + isLongSignal ? + range.lowestLow + maxAllowedTPRange + : + range.highestHigh - maxAllowedTPRange + ; + + // + return result; +} + +// +double GetMaxRangeAllowedEntry( + const ENUM_X_SIGNAL_TYPE type, + const XRange &range +) { + // + bool isLongSignal = + type != X_SIGNAL_NONE + && type == X_SIGNAL_LONG + ; + + // + double maxAllowedEntryRange = (range.levels - 1.5) * range.rate; + + // + double result = + isLongSignal ? + range.lowestLow + maxAllowedEntryRange + : + range.highestHigh - maxAllowedEntryRange + ; + + // + return result; +} + +// +// Range Verification ... +bool IsRangeVerified( + const int bar_index, + const int marketLen, + const int levels, + const ENUM_X_SIGNAL_TYPE type, + const double entry, + const double tp, + const XRange &range +) { + // + bool isLongSignal = + type == X_SIGNAL_LONG + && type != X_SIGNAL_NONE + ; + + // + double maxAllowedTP = + GetMaxRangeAllowedTP( + type, + range + ) + ; + + // + double maxAllowedEntry = + GetMaxRangeAllowedEntry( + type, + range + ) + ; + + // + bool result = + isLongSignal + ? + // + entry < maxAllowedEntry + && tp < maxAllowedTP + : + // + entry > maxAllowedEntry + && tp > maxAllowedTP + ; + + // + return result; +} + +// +// START Global Requirement Functions ... +// +// +// Signal Range Verification ... +bool IsSignalRangeVerified( + const int bar_index, + const int marketLen, + const int levels, + const XSignal &signal, + const XRange &range +) { + // + bool result = + IsRangeVerified( + bar_index, + marketLen, + levels, + signal.type, + signal.entry, + signal.tp, + range + ); + + // + return result; +} + +// +double ReadXMABuffer( + const int bar_index, + const int buffer_index, + // + const int marketLen, + // + const double stp, + const double mxm, + // + const int shortCycleMult, + const int mediumCycleMult, + const int longCycleMult +) { + // + string xmaIndicatorName = "x-saherelm.x.xma"; + + // + double result = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // Inputs ... + marketLen, + stp, + mxm, + shortCycleMult, + mediumCycleMult, + longCycleMult, + MODE_SMA, + // + buffer_index, + bar_index + ); + + // + return result; +} + +// +double ReadXHLBuffer( + const int bar_index, + const int buffer_index, + // + const int marketLen, + // + const int shortCycleMult, + const int mediumCycleMult, + const int longCycleMult +) { + // + string xhlIndicatorName = "x-saherelm.x.hl"; + + // + double result = iCustom( + _Symbol, + _Period, + xhlIndicatorName, + // + // Inputs ... + marketLen, + shortCycleMult, + mediumCycleMult, + longCycleMult, + MODE_SMA, + // + buffer_index, + bar_index + ); + + // + return result; +} + +// +double ReadADX( + const int bar_index, + const int marketLen, + const int mult +) { + // + double result; + + // + int period = marketLen * mult; + + // + result = iADX( + _Symbol, + _Period, + period, + PRICE_CLOSE, + MODE_MAIN, + bar_index + ); + + // + return result; +} + +// +XState GetXState( + const int bar_index, + // + const int marketLen, + // + const double stp, + const double mxm, + // + const int shortCycleMult, + const int mediumCycleMult, + const int longCycleMult +) { + // + XState result = {}; + + // + // Cycle Buffer Indexes ... + int scFastBufferIndex = 0; + int scSlowBufferIndex = 1; + int mcFastBufferIndex = 2; + int mcSlowBufferIndex = 3; + int lcFastBufferIndex = 4; + int lcSlowBufferIndex = 5; + int psarBufferIndex = 6; + + // + // HH and LL Buffer Indexes ... + int scHHBufferIndex = 0; + int scLLBufferIndex = 1; + int mcHHBufferIndex = 2; + int mcLLBufferIndex = 3; + int lcHHBufferIndex = 4; + int lcLLBufferIndex = 5; + + // + // Short Cycle ... + // + // Fast ... + double scFast = ReadXMABuffer( + bar_index, + scFastBufferIndex, + // + marketLen, + stp, + mxm, + shortCycleMult, + mediumCycleMult, + longCycleMult + ); + + // + // Slow ... + double scSlow = ReadXMABuffer( + bar_index, + scSlowBufferIndex, + // + marketLen, + stp, + mxm, + shortCycleMult, + mediumCycleMult, + longCycleMult + ); + + // + // Highest High ... + double scHH = ReadXHLBuffer( + bar_index, + scHHBufferIndex, + // + marketLen, + // + shortCycleMult, + mediumCycleMult, + longCycleMult + ); + + // + // Lowest Low ... + double scLL = ReadXHLBuffer( + bar_index, + scLLBufferIndex, + // + marketLen, + // + shortCycleMult, + mediumCycleMult, + longCycleMult + ); + + // + // Integrate Result ... + XCycleState sc = {}; + sc.fast = scFast; + sc.slow = scSlow; + sc.hh = scHH; + sc.ll = scLL; + + // + // Attach Result ... + result.sc = sc; + + // + // Medium Cycle ... + // + // Fast ... + double mcFast = ReadXMABuffer( + bar_index, + mcFastBufferIndex, + // + marketLen, + stp, + mxm, + shortCycleMult, + mediumCycleMult, + longCycleMult + ); + + // + // Slow ... + double mcSlow = ReadXMABuffer( + bar_index, + mcSlowBufferIndex, + // + marketLen, + stp, + mxm, + shortCycleMult, + mediumCycleMult, + longCycleMult + ); + + // + // Highest High ... + double mcHH = ReadXHLBuffer( + bar_index, + mcHHBufferIndex, + // + marketLen, + // + shortCycleMult, + mediumCycleMult, + longCycleMult + ); + + // + // Lowest Low ... + double mcLL = ReadXHLBuffer( + bar_index, + mcLLBufferIndex, + // + marketLen, + // + shortCycleMult, + mediumCycleMult, + longCycleMult + ); + + // + double di = GetMA( + bar_index, + (mediumCycleMult + 1) * marketLen, + 0, + MODE_SMA, + PRICE_CLOSE + ); + result.di = di; + + // + // Integrate Result ... + XCycleState mc = {}; + mc.fast = mcFast; + mc.slow = mcSlow; + mc.hh = mcHH; + mc.ll = mcLL; + + // + // Attach Result ... + result.mc = mc; + + // + // Long Cycle ... + // + // Fast ... + double lcFast = ReadXMABuffer( + bar_index, + lcFastBufferIndex, + // + marketLen, + stp, + mxm, + shortCycleMult, + mediumCycleMult, + longCycleMult + ); + + // + // Slow ... + double lcSlow = ReadXMABuffer( + bar_index, + lcSlowBufferIndex, + // + marketLen, + stp, + mxm, + shortCycleMult, + mediumCycleMult, + longCycleMult + ); + + // + // Highest High ... + double lcHH = ReadXHLBuffer( + bar_index, + lcHHBufferIndex, + // + marketLen, + // + shortCycleMult, + mediumCycleMult, + longCycleMult + ); + + // + // Lowest Low ... + double lcLL = ReadXHLBuffer( + bar_index, + lcLLBufferIndex, + // + marketLen, + // + shortCycleMult, + mediumCycleMult, + longCycleMult + ); + + // + // Integrate Result ... + XCycleState lc = {}; + lc.fast = lcFast; + lc.slow = lcSlow; + lc.hh = lcHH; + lc.ll = lcLL; + + // + // Attach Result ... + result.lc = lc; + + // + // Parabolic SAR ... + double psar = ReadXMABuffer( + bar_index, + psarBufferIndex, + // + marketLen, + stp, + mxm, + shortCycleMult, + mediumCycleMult, + longCycleMult + ); + + // + result.parabolicSAR = psar; + + // + return result; +} +// +// END XMA Data ... +// +// +// END Indicator Reading Data ... +// diff --git a/Bkp/Used/14020431/Libraries/x-saherelm.lib.mq4 b/Bkp/Used/14020431/Libraries/x-saherelm.lib.mq4 new file mode 100644 index 0000000..e2124e3 --- /dev/null +++ b/Bkp/Used/14020431/Libraries/x-saherelm.lib.mq4 @@ -0,0 +1,1604 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +struct XOHCL { + double high; + double open; + double close; + double low; +}; + +// +struct XRange { + // + datetime time; + + // + double highestHigh; + double lowestLow; + + // + int levels; + int marketLength; + + // + double rate; +}; + +// +static datetime lastBarTime; + +// +// START Functions ... +// + +// +// Determines current working is New Bar or not ... +bool IsNewBar() { + // + // Reading Last Bar Date ... + datetime curbar = (datetime)SeriesInfoInteger( + _Symbol, + _Period, + SERIES_LASTBAR_DATE + ); + + // + if(lastBarTime != curbar) { + // + lastBarTime = curbar; + return true; + } + + // + return false; +} + +// +// Determines we are in new Day or not ... +bool IsNewDay() { + // + bool result = false; + + // + // Reading Last Bar Date ... + datetime curbar = (datetime)SeriesInfoInteger( + _Symbol, + _Period, + SERIES_LASTBAR_DATE + ); + + // + if (lastBarTime == 0) { + lastBarTime = curbar; + } + + // + if (curbar == lastBarTime) { + return result; + } + + // + // Retrieve Day and Month and Year for Last Bar Time ... + int lastBarDay = TimeDay(lastBarTime); + int lastBarMonth = TimeMonth(lastBarTime); + int lastBarYear = TimeYear(lastBarTime); + + // + // Retrieve Day and Month and Year for Current Bar Time ... + int curBarDay = TimeDay(curbar); + int curBarMonth = TimeMonth(curbar); + int curBarYear = TimeYear(curbar); + + // + result = curBarDay > lastBarDay + || curBarMonth > lastBarMonth + || curBarYear > lastBarYear; + + // + return result; +} + +// +// Retrieve Number of Candles in a Day ... +int GetDailyCandleCount() { + // + int seconds = PeriodSeconds(_Period); + + // + int daySeconds = 24 * 60 * 60; + + // + int result = daySeconds / seconds; + + // + return result; +} + +// +// XRange Detector ... +XRange GetMarketRange( + const int bar_index, + const int marketLen, + const int levels +) { + // + XRange result = {}; + + // + result.levels = levels; + result.marketLength = marketLen; + + // + datetime time = iTime( + _Symbol, + _Period, + bar_index + ); + result.time = time; + + // + double highestHigh = GetMarketHighestHigh( + bar_index, + marketLen + ); + result.highestHigh = highestHigh; + + // + double lowestLow = GetMarketLowestLow( + bar_index, + marketLen + ); + result.lowestLow = lowestLow; + + // + double diff = highestHigh - lowestLow; + double rate = diff / levels; + + // + result.rate = rate; + + // + return result; +} + +// +// Retrieve RMA on Specific Candle ... +double GetRMA( + int bar_index, + int length +) { + // + double shortSMA = iMA(_Symbol, _Period, length, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double mediumSMA = iMA(_Symbol, _Period, length * 2, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double longSMA = iMA(_Symbol, _Period, length * 3, 0, MODE_SMA, PRICE_CLOSE, bar_index); + + // + double result = longSMA - mediumSMA + shortSMA; + + // + return result; +} + +// +double GetMA( + const int bar_index, + const int maLength, + const int maShift, + const ENUM_MA_METHOD maMethod, + const ENUM_APPLIED_PRICE appliedPrice +) { + // + double result = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + appliedPrice, + bar_index + ); + + // + return result; +} + +// +// Calculate Fib Level ... +double GetFibonacciLevel( + double upPrice, + double downPrice, + double level, + int direction +) { + // + double ling = upPrice - downPrice; + double pLevel = (ling / 100) * (level * 100); + + // + double result = direction > 0 ? + upPrice - pLevel : + downPrice + pLevel; + result = NormalizeDouble(result, _Digits); + + // + return result; +} + +// +// Retrieve True Range ... +double GetTR( + const int bar_index +) { + // + double result = 0; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double prevClose = iClose( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double highLowDif = high - low; + double hpCDif = MathAbs(high - prevClose); + double lpCDiff = MathAbs(low - prevClose); + + // + result = MathMax(highLowDif, hpCDif); + result = MathMax(result, lpCDiff); + + // + return result; +} + +// +// Calculate True Range Simple Moving Average ... +double GetMarketTRSMA( + const int bar_index, + const int marketLen +) { + // + double result = 0; + + // + // Create Barket Length Trs ... + double trs[]; + ArrayResize( + trs, + marketLen + ); + int index = 0; + double trSum = 0; + for (int i = bar_index; i < bar_index + marketLen; i++) { + // + double tr = GetTR(i); + trs[index] = tr; + + // + trSum += tr; + + // + index++; + } + + // + result = trSum / marketLen; + + // + return result; +} + +// +// Retrieve Commodity Channel ... +double GetMarketCCI( + const int bar_index, + const int marketLen, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE +) { + // + double result = 0; + + // + result = iCCI( + _Symbol, + _Period, + marketLen, + appliedPrice, + bar_index + ); + + // + return result; +} + +// +// this function check crossing up two Buffers ... +bool IsCrossedOver( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] > arr2[index1]) && !(arr1[index2] > arr2[index2]); + + // + return result; +} + +// +// this function check crossing down two Buffers ... +bool IsCrossedUnder( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] < arr2[index1]) && !(arr1[index2] < arr2[index2]); + + // + return result; +} + +// +// Convert points to Actual Point ... +double PointsToDouble(int points) { + // + double result = points * _Point; + return result; +} + +// +// Converts Pips to Points ... +int PipsToPoints(int pips) { + // + int result = pips * ((_Digits == 3 || _Digits == 5) ? 10 : 1); + return result; +} + +// +// Converts Pips to Double ... +double PipsToDouble(int pips) { + // + double result = PointsToDouble(PipsToPoints(pips)); + return result; +} + +// +// Converts Double Value to Pips ... +int PriceToPips(double value) { + // + if (value <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + int result = (int)(value / pipValue); + + // + return result; +} + +// +// Converts Pips to Double ... +double PipsToPrice(int pips) { + // + if (pips <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + double result = pipValue * pips; + + // + return result; +} + +// +// Generate ATR StopLoss Value ... +double CalculateATRSL( + int period, + double multiplier +) { + // + if (period <= 0 || multiplier <= 0) { + return 0; + } + + // + double atrValue = iATR( + _Symbol, + _Period, + period, + 0 + ); + + // + double result = atrValue * multiplier; + + // + return result; +} + +// +// Detect Candle Type ... +// Bullish => means close > open ... +bool IsBullishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBullishCandle( + open, + close + ); + + // + return result; +} + +bool IsBullishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open < close; + + // + return result; +} + +// +// Detect Candle Type ... +// Bearish => means close < open ... +bool IsBearishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBearishCandle( + open, + close + ); + + // + return result; +} + +bool IsBearishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open > close; + + // + return result; +} + +// +// Retrieve a Candle Info ... +XOHCL GetCandleModel( + const int bar_index +) { + // + XOHCL result = {}; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + result.high = high; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + result.open = open; + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + result.close = close; + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + result.low = low; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBullishDetected( + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double shpDetectMultipliers // Sharp Detect Multiplier +) { + // + bool result = false; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double minValue = 0; + double maxValue = 0; + int positionedLength = bar_index + marketLen; + + // + for (int i = bar_index; i < positionedLength; i++) { + // + double cHigh = iHigh( + _Symbol, + _Period, + i + ); + + // + double cLow = iLow( + _Symbol, + _Period, + i + ); + + // + minValue += MathMin(cLow, cHigh); + maxValue += MathMax(cLow, cHigh); + } + + // + double minAvg = minValue / positionedLength; + double maxAvg = maxValue / positionedLength; + + // + double shpValue = shpDetectMultipliers * _Point; + + // + result = (low - minAvg) > shpValue; + + // + int index = bar_index; + while ( + index < positionedLength + || !result + ) { + // + low = iLow( + _Symbol, + _Period, + index + ); + + // + result = result + || (low - minAvg) > shpValue; + + // + index++; + }; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBearishDetected( + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double shpDetectMultipliers // Sharp Detect Multiplier +) { + // + bool result = false; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double minValue = 0; + double maxValue = 0; + int positionedLength = bar_index + marketLen; + + // + for (int i = bar_index; i < positionedLength; i++) { + // + double cHigh = iHigh( + _Symbol, + _Period, + i + ); + + // + double cLow = iLow( + _Symbol, + _Period, + i + ); + + // + minValue += MathMin(cLow, cHigh); + maxValue += MathMax(cLow, cHigh); + } + + // + double minAvg = minValue / positionedLength; + double maxAvg = maxValue / positionedLength; + + // + double shpValue = shpDetectMultipliers * _Point; + + // + result = (high - maxAvg) > shpValue; + + // + int index = bar_index; + while ( + index < positionedLength + || !result + ) { + // + high = iHigh( + _Symbol, + _Period, + index + ); + + // + result = result + || (high - maxAvg) > shpValue; + + // + index++; + }; + + // + return result; +} + +// +// Retrieve Highest High Value based on Given Market ... +double GetMarketHighestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Low Value based on Given Market ... +double GetMarketHighestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Open Value based on Given Market ... +double GetMarketHighestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Close Value based on Given Market ... +double GetMarketHighestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Low Value based on Given Market ... +double GetMarketLowestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest High Value based on Given Market ... +double GetMarketLowestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Open Value based on Given Market ... +double GetMarketLowestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Close Value based on Given Market ... +double GetMarketLowestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// less than given price ... +double GetLowLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// great than given price ... +double GetLowGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// less than given price ... +double GetHighLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// great than given price ... +double GetHighGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// less than given price ... +double GetCloseLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// great than given price ... +double GetCloseGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Get Slope of a Line by it's two Point ... +double GetSlope( + double x1, + double y1, + double x2, + double y2 +) { + // + double result = (y2 - y1)/MathAbs(x2 - x1); + return result; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020431/Libraries/x-saherelm.log.lib.mq4 b/Bkp/Used/14020431/Libraries/x-saherelm.log.lib.mq4 new file mode 100644 index 0000000..066b3f7 --- /dev/null +++ b/Bkp/Used/14020431/Libraries/x-saherelm.log.lib.mq4 @@ -0,0 +1,91 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Log Tag ... +static string logTag = ""; + +// +// Enable or Disable Logging ... +static bool enableLogging = false; + +// +// Start Log Messages ... +// + +// +// Logging a Message, specified for this EA ... +// using provided LogTag ... +void LogMessage(string message) { + // + if (!enableLogging) { + return; + } + + // + Print(logTag, " > ", message); +} + +// +// this used for logging series ... +void LogSeries( + double &series[], // which series to Log ... + int length = 0, // number of items to Log, 0 means all ... + int skip = 0 // number of items which skip before logging ... +) { + // + string msg = ""; + + // + int seriesSize = ArraySize(series); + if ( + skip < 0 + || length < 0 + || seriesSize == 0 + || skip > seriesSize + || skip + length > seriesSize + ) { + return; + } + + // + length = length == 0 ? + seriesSize : + length; + int start = skip > 1 ? + skip - 1 : + skip == 1 ? + 1 : + 0; + + // + // Loop through series items ... + for (int i = start; i < start + length; i++) { + // + msg += StringConcatenate( + "i[", i, "]: ", series[i], ", " + ); + } + + // + LogMessage(msg); +} +// +// End Log Messages ... +// + diff --git a/Bkp/Used/14020431/Libraries/x-saherelm.models.lib.mq4 b/Bkp/Used/14020431/Libraries/x-saherelm.models.lib.mq4 new file mode 100644 index 0000000..f4e1058 --- /dev/null +++ b/Bkp/Used/14020431/Libraries/x-saherelm.models.lib.mq4 @@ -0,0 +1,152 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Models Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// START STATIC Variables ... +// +// +static int totalSignals = 0; +static int totalLongSignals = 0; +static int totalShortSignals = 0; + +// +static double initialBalance = 0; + +// +static int countedBars = 0; +static bool isNewBar = false; +static bool isNewDay = false; +// +// END STATIC Variables ... +// + +// +// Start Models ... +// +// +// Signal Providers ... +enum ENUM_X_SIGNAL_PROVIDER { + X_UNKNOWN_PROVIDER, + X_XXX_PROVIDER, + X_XR_PROVIDER +}; + +// +// these are different signal types ... +enum ENUM_X_SIGNAL_TYPE { + X_SIGNAL_NONE, + X_SIGNAL_LONG, + X_SIGNAL_SHORT, +}; + +// +// we Model each signals as this type ... +struct XSignal { + // + // Signal Symbol ... + string symbol; + + // + // Signal Type ... + ENUM_X_SIGNAL_TYPE type; + + // + // Signal ID ... + int id; + + // + // Signal Ticket Number, when Opening Trade ... + int ticket; + + // + // Signal Provider ... + ENUM_X_SIGNAL_PROVIDER provider; + + // + // Target Point ... + double tp; + + // + // Stop Loss ... + double sl; + + // + // Signal Entry Price ... + double entry; + + // + // Signalling Time ... + datetime time; + + // + // Signal Comments ... + string comment; + + // + // Signal TAG ... + string tag; +}; + +// +// this is Signal Request Response model ... +struct XSignalRequest { + bool hasSignal; + XSignal signal; + ENUM_X_SIGNAL_TYPE type; + ENUM_X_SIGNAL_PROVIDER provider; +}; + +// +struct XCycleState { + // + double fast; + double slow; + + // + double hh; + double ll; + + // + double power; +}; + +// +// Define a Model to Represent Snapshot of XMA Indicator ... +struct XState { + // + // SC ... + XCycleState sc; + + // + // MC ... + XCycleState mc; + + // + double di; + + // + // LC ... + XCycleState lc; + + // + // PARABOLIC-SAR ... + double parabolicSAR; +}; +// +// End Models ... +// diff --git a/Bkp/Used/14020431/Libraries/x-saherelm.signal.lib.mq4 b/Bkp/Used/14020431/Libraries/x-saherelm.signal.lib.mq4 new file mode 100644 index 0000000..76d9e53 --- /dev/null +++ b/Bkp/Used/14020431/Libraries/x-saherelm.signal.lib.mq4 @@ -0,0 +1,1518 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Signal Draw Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +#include "../Libraries/x-saherelm.x.signal.lib.mq4" +#include "../Libraries/x-saherelm.xr.signal.lib.mq4" + +// +// START Global Requirement Functions ... +// +// END Global Requirement Functions ... +// + +// +// START Signal Related Functions ... +// +// +// Retrieve Signal Bar Index ... +int GetSignalBarIndex(XSignal &signal) { + // + // Temp Result ... + int result = -1; + + // + // Retriev Signal Bar Index ... + result = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + return result; +} + +// +string GetProviderIdentifier( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + string result = ""; + + // + switch (provider) { + // + case X_XXX_PROVIDER: + result = "XXX"; + break; + + // + case X_XR_PROVIDER: + result = "XR"; + break; + + // + default: + result = ""; + break; + } + + // + return result; +} + +// +ENUM_X_SIGNAL_PROVIDER GetProvider(string identifier) { + // + ENUM_X_SIGNAL_PROVIDER result = X_UNKNOWN_PROVIDER; + + // + if ( + StringFind( + identifier, + GetProviderIdentifier(X_XXX_PROVIDER) + ) > -1 + ) { + result = X_XXX_PROVIDER; + } else if ( + StringFind( + identifier, + GetProviderIdentifier(X_XR_PROVIDER) + ) > -1 + ) { + result = X_XR_PROVIDER; + } + + // + return result; +} + +// +void DrawRange( + const XRange &range, + const long chartID = 0, + const int subWindowID = 0, + const string tag = "", + const color clr = clrYellow +) { + // + // Loop through Levels Count ... + for (int i = 0; i <= range.levels; i++) { + // + datetime time1 = iTime( + _Symbol, + _Period, + 1 + ); + + // + datetime time2 = iTime( + _Symbol, + _Period, + 0 + ); + + // + double price = range.lowestLow + (i * range.rate); + + // + string lbl = StringConcatenate( + tag, + "_XRL_", + price + ); + + // + DrawTrendLine( + chartID, + lbl, + subWindowID, + time1, + price, + time2, + price, + clr, + STYLE_DOT + ); + } +} + +// +// Draw Signal Shapes on Chart ... +bool DrawSignal( + const XSignal &signal, + long chartID = 0, + int subWindowID = 0, + const double positionThresholdFactor = 10, + string longSignalLabel = "X-Long", + color longSignalColor = clrAqua, + string shortSignalLabel = "X-Short", + color shortSignalColor = clrFuchsia +) { + // + // Generate isLongSignal Var ... + bool isLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Signal Bar Index ... + int bar_index = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // START Draw Signal Arrow ... + // + // + // Arrow Shape Name ... + string arrowName = StringConcatenate(signal.tag, "_Arrow_", signal.id); + + // + // Arrow Price ... + double arrowPrice = 0; + if (isLongSignal) { + // + arrowPrice = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice - (positionThresholdFactor * _Point); + } else { + // + arrowPrice = iHigh( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice + (positionThresholdFactor * _Point); + } + + // + // Arrow Code ... + uchar arrowCode = isLongSignal ? SYMBOL_ARROWUP : SYMBOL_ARROWDOWN; + + // + // Arrow Anchor Point ... + ENUM_ARROW_ANCHOR arrowAnchorPoint = isLongSignal ? ANCHOR_BOTTOM : ANCHOR_TOP; + + // + // Arrow Color ... + color arrowColor = isLongSignal ? longSignalColor : shortSignalColor; + + // + // Draw Signal Arrow Shape ... + bool result = DrawArrow( + chartID, + arrowName, + subWindowID, + signal.time, + arrowPrice, + arrowCode, + arrowAnchorPoint, + arrowColor + ); + // + // END Draw Signal Arrow ... + // + + // + // START Draw Signal SL/TP ... + // + string slLineName = StringConcatenate(signal.tag, "_SL_", signal.id); + string tpLineName = StringConcatenate(signal.tag, "_TP_", signal.id); + string entryLineName = StringConcatenate(signal.tag, "_ENTRY_", signal.id); + + // + color slColor = shortSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color tpColor = longSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color entryColor = clrGreen; + + // + datetime time1 = iTime( + _Symbol, + _Period, + bar_index + 1 + ); + + // + // Draw Enrty Price ... + result = DrawTrendLine( + chartID, + entryLineName, + subWindowID, + time1, + signal.entry, + signal.time, + signal.entry, + entryColor, + STYLE_SOLID, + 2 + ); + + // + // Draw Signal SL ... + if (signal.sl > 0) { + // + result = DrawTrendLine( + chartID, + slLineName, + subWindowID, + time1, + signal.sl, + signal.time, + signal.sl, + slColor, + STYLE_SOLID, + 2 + ); + } + + // + // Draw Signal TP ... + if (signal.tp > 0) { + // + result = DrawTrendLine( + chartID, + tpLineName, + subWindowID, + time1, + signal.tp, + signal.time, + signal.tp, + tpColor, + STYLE_SOLID, + 2 + ); + } + // + // END Draw Signal SL/TP ... + // + + // + // Start Draw Signal Label ... + // + // + string labelName = StringConcatenate(signal.tag, "_Label_", signal.id); + + // + double labelPrice = isLongSignal ? arrowPrice - (positionThresholdFactor * _Point) : arrowPrice + (positionThresholdFactor * _Point); + + // + string labelText = isLongSignal ? longSignalLabel : shortSignalLabel; + labelText = StringConcatenate( + labelText, + "_", + GetProviderIdentifier(signal.provider) + ); + + // + result = DrawText( + chartID, + labelName, + subWindowID, + signal.time, + labelPrice, + labelText, + "Arial", + 8, + arrowColor, + 0, + ANCHOR_CENTER + ); + // + // End Draw Signal Label ... + // + + // + return result; +} + +// +// Trade on Specific Signal ... +bool TradeSignal( + XSignal &signal, + // + double volumePercent, + // + // Long ... + const string longSignalLabel, + const color longSignalColor, + // + // Short ... + const string shortSignalLabel, + const color shortSignalColor +) { + // + // Temp Result ... + bool result = false; + + // + if (initialBalance == 0) { + initialBalance = AccountInfoDouble(ACCOUNT_BALANCE); + } + + // + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + int openPositions = CountOpenTrades(); + double volume = (volumePercent * initialBalance); + + // + if ( + signal.type != X_SIGNAL_LONG && + signal.type != X_SIGNAL_SHORT + ) { + return result; + } + + // + bool hasLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Check TP and Entry Price ... + if ( + ( + hasLongSignal + && signal.entry > signal.tp + ) || + ( + !hasLongSignal + && signal.entry < signal.tp + ) + ) { + return result; + } + + // + // Order Operation ... + int operation = hasLongSignal ? + OP_BUY : + OP_SELL; + + // + // Detect Trade Color ... + color clr = hasLongSignal ? + longSignalColor : + shortSignalColor; + + // + // Generate Signal Comment ... + string label = hasLongSignal ? + longSignalLabel : + shortSignalLabel; + + // + // Generate Signal Comment ... + string comment = StringConcatenate( + signal.tag, + "_", signal.id, + "_", GetProviderIdentifier(signal.provider), + "_", label + ); + + // + // Placing Order ... + int orderTicket = OrderSend( + _Symbol, + operation, + volume, + signal.entry, + 3, + signal.sl, + signal.tp, + comment, + signal.id, + 0, + clr + ); + + // + // Draw Signal Shape if Order Opened Successfully ... + if (orderTicket >= 0) { + // + signal.ticket = orderTicket; + + // + // Here i must to Draw Signal Shapes ... + bool isDrawn = DrawSignal( + signal, + 0, + 0, + 50, + longSignalLabel, // Long Signal Label ... + longSignalColor, + shortSignalLabel, // Short Signal Label ... + shortSignalColor + ); + + // + LogMessage( + StringConcatenate( + "Order [", orderTicket ,"]: Provided by: ", GetProviderIdentifier(signal.provider) + ) + ); + + // + // TODO: here we have to check if there are another + // open positions which their entry price is bigger + // than current signal entry price, for long trades and + // their tp is high than current tp, ... + // close in profit trades or modify orders tp to current ... + // // + // if (CountOpenTrades() > 0) { + // // + // // Here we have to + // // ModifyOpenTradesBasedOnCurrentTrade(signal); + // } + + // + result = true; + } + + // + return result; +} +// +// END Signal Related Functions ... +// + +// +// START Orders Functions ... +// +// +// Convert To XSignal Model ... +XSignal OrderToSignal() { + // + // Temp Result ... + XSignal result = {}; + result.type = X_SIGNAL_NONE; + + // + // Here we can get some usefull info based on selected order ... + double swap = OrderSwap(); + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + int magicNumber = OrderMagicNumber(); + double takeProfit = OrderTakeProfit(); + string comment = OrderComment(); + + // + ENUM_X_SIGNAL_PROVIDER provider = GetProvider(comment); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // Conver Position to Signal ... + result.sl = stopLoss; + result.tp = takeProfit; + result.time = openTime; + result.symbol = _Symbol; + result.id = magicNumber; + result.comment = comment; + result.entry = openPrice; + result.provider = provider; + result.type = isLongOrder ? X_SIGNAL_LONG : X_SIGNAL_SHORT; + + // + return result; +} + +// +// START Count Orders ... +// +// +// Count Open Positions ... +int CountOpenTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if (OrderSymbol() == _Symbol) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Long Positions ... +int CountOpenLongTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_BUY + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Short Positions ... +int CountOpenShortTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_SELL + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} +// +// END Count Orders ... +// + +// +// START Close Orders ... +// +// +// Close All Open Trades ... +bool CloseAllTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + + // + return result; +} + +// +bool CloseAllProviderLongTrades( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal(); + + // + if (signal.provider == provider) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Long Trades ... +bool CloseAllLongTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Long Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Short Trades ... +bool CloseAllShortTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (!isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Short Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In Profit Trades ... +bool CloseAllInProfitTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit > 0 + && profit > 50 * _Point + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InProfit Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In DrawDown Trades ... +bool CloseAllInDrawDownTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if (profit < 0) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close Biggest In DrawDown Trades ... +bool CloseBiggestDrawDownTrade() { + // + // Loop through all Positions ... + bool result = false; + double drawDown = 0; + + // + // Find Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) > drawDown + ) { + drawDown = profit; + } + } + } + } + + // + // Close Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) >= drawDown + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Max InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Long Time Trades ... +bool CloseAllLongTimeTrades( + const int passedCandles +) { + // + bool result = false; + + // + if (passedCandles <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + + // + if ( + profit < 0 + && openBarIndex - currentBarIndex >= passedCandles + // || ( + // profit > 0.5 + // && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 3) + // ) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Long Time issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + // else if ( + // openTrades > 0 + // && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 2) + // ) { + // result = CloseAllInProfitTrades() + // && CloseBiggestDrawDownTrade(); + // } + } + } + } + + // + return result; +} + +// +// Close all trades which passed Maximum Drawdown ... +bool CloseAllMaximumDrawDownPassedTrades( + const double maxDrDownPercentPerPTrade +) { + // + if ( + initialBalance <= 0 + || maxDrDownPercentPerPTrade <= 0 + ) { + return false; + } + + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double maxAllowedDrawDown = -1 * (initialBalance * maxDrDownPercentPerPTrade); + + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + if ( + profit < 0 + && MathAbs(profit) >= MathAbs(maxAllowedDrawDown) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Maximum DarwDown issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Trades Which Opens before Specified Length ... +bool CloseAllTradesWhichOpenInPastMarketLength( + const int marketLen +) { + // + bool result = false; + + // + if (marketLen <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + + // + if (openBarIndex <= currentBarIndex + marketLen) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Market Reverse issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } else if (openTrades > 0) { + // + // Close all InProfit Trdes and Biggest InDrawDown Trades ... + // result = CloseAllInProfitTrades(); + // && CloseBiggestDrawDownTrade(); + } + } + } + } + + // + return result; +} +// +// END Close Orders ... +// + +// +// START Modify Orders ... +// +// +void ModifyAllPriceLesserOpenTrades( + const XSignal &signal +) { + // + // Loop through all Open Trades ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + double takeProfit = OrderTakeProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // When new Signal Comming with price less than + // currently open trade and tp less than currently + // open trade, this means a market change happens ... + // here we can Close InProfit Trades or Modify Trades TP ... + if ( + openPrice < signal.entry + && takeProfit > signal.tp + ) { + bool result = OrderModify( + ticket, + openPrice, + signal.sl, + signal.tp, + clrYellow + ); + } + } + } + } +} + +// +void ModifyOpenTradesBasedOnCurrentTrade( + const XSignal &signal +) { + // + ModifyAllPriceLesserOpenTrades(signal); +} +// +// END Modify Orders ... +// +// +// END Orders Functions ... +// + +// +// START Signal Conditions ... +// +// +// Clear Signal Conditions ... +void ClearSignalConditions() { + // + ClearLongSignalConditions(); + ClearShortSignalConditions(); +} + +// +// Clear all Conditions Waiter for Long Signals ... +void ClearLongSignalConditions() { + // + ClearXLongSignalConditions(); + ClearXRLongSignalConditions(); + // + // ClearOSCLongSignalConditions(); + // ClearCCILongSignalConditions(); + // ClearSHPLongSignalConditions(); + // ClearXRMALongSignalConditions(); + // // + // ClearXMASCLongSignalConditions(); + // ClearXMAMCLongSignalConditions(); + // ClearXMAMMLongSignalConditions(); +} + +// +// Clear all Conditions Waiter for Short Signals ... +void ClearShortSignalConditions() { +} +// +// END Signal Conditions ... +// diff --git a/Bkp/Used/14020431/Libraries/x-saherelm.x.signal.lib.mq4 b/Bkp/Used/14020431/Libraries/x-saherelm.x.signal.lib.mq4 new file mode 100644 index 0000000..11ae62c --- /dev/null +++ b/Bkp/Used/14020431/Libraries/x-saherelm.x.signal.lib.mq4 @@ -0,0 +1,778 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 X Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// X Based Signal Conditions ... +struct XSignalConditions { + datetime startTime; + datetime signalTime; + datetime entryTime; +}; + +// +static XSignalConditions xLongConds; +static bool xCloseLongTrades = false; +static bool xWaitForLongSignals = true; +static datetime lastLCFCrossOverSCLLTime; +static datetime xWaitForLongSignalChangeTime; + +// +static XSignalConditions xShortConds; +static bool xWaitForShortSignals = true; +static bool xCloseShortTrades = false; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckSignalHandler( + const int bar_index, + const int marketLen, + const XState &states[], + // + const double smoother = 10 +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + if (xWaitForLongSignals) { + // // + // bool isLCFastOnTrendingUpTouchLowestLow = + // // + // // LC Trending Up ... + // states[1].lc.fast > states[1].lc.slow + // && states[2].lc.fast > states[2].lc.slow + // // + // // LC Fast Touch Market Lowest Low ... + // && states[1].lc.fast > states[1].mkt.lowestLow + // && !(states[2].lc.fast > states[2].mkt.lowestLow) + // ; + + // // + // bool isMCSlowCrossOverBNDHigh = + // states[1].mc.fast > states[1].mc.slow + // && states[1].mc.slow > states[1].bnd.high + // && !(states[2].mc.slow > states[2].bnd.high) + // ; + + // + // Disable Long Trade Handlers ... + // if ( + // isMCSlowCrossOverBNDHigh + // || isLCFastOnTrendingUpTouchLowestLow + // ) { + // // + // xWaitForLongSignals = false; + // xWaitForLongSignalChangeTime = TimeCurrent(); + // LogMessage("Disable Long ..."); + // } + } else { + // + bool isAllTrendingUp = + // + // SC ... + states[1].sc.fast > states[1].sc.slow + // + // MC ... + && states[1].mc.fast > states[1].mc.slow + && !(states[2].mc.fast > states[2].mc.slow) + // + // LC ... + && states[1].lc.fast > states[1].lc.slow + ; + + // + int lastWaitChangeBarIndex = iBarShift( + _Symbol, + _Period, + xWaitForLongSignalChangeTime + ); + + // + // Enable Long Trade Handlers ... + if ( + isAllTrendingUp + && lastWaitChangeBarIndex - bar_index >= marketLen + ) { + xWaitForLongSignals = true; + LogMessage("Enable Long ..."); + } + } +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXLongSignalConditions( + const int bar_index, + const int marketLen, + const XState &states[], + // + const double smoother = 10 +) { + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // for Long Signals it happens when sc fast cross over slow ... + bool isCrossUnder = + states[0].sc.fast > states[0].sc.slow + && states[1].sc.fast > states[1].sc.slow + && !(states[2].sc.fast > states[2].sc.slow) + ; + + // + // for Long Signals it happens when sc fast cross under slow ... + bool isCrossOver = + states[0].sc.fast < states[0].sc.slow + && states[1].sc.fast < states[1].sc.slow + && !(states[2].sc.fast < states[2].sc.slow) + ; + + // + // Check Special Conditions ... + // XOHCL pCandle = GetCandleModel(bar_index + 1); + // XOHCL ppCandle = GetCandleModel(bar_index + 2); + // XOHCL mCandle = GetCandleModel(bar_index + marketLen); + // bool isLCGoingDownPrice = + // // + // pCandle.low > states[1].lc.slow + // && ppCandle.low > states[2].lc.slow + // && mCandle.low < states[marketLen - 1].lc.slow + // ; + // if () + + // + if ( + isCrossUnder + && xLongConds.startTime == 0 + ) { + // + xLongConds.startTime = barTime; + return; + } + + // + if ( + isCrossOver + && xLongConds.startTime > 0 + && xLongConds.signalTime == 0 + ) { + // + xLongConds.signalTime = barTime; + xLongConds.entryTime = barTime; + + // + // if (states[0].parabolicSAR < states[0].sc.slow) { + // } + return; + } + + // // + // if ( + // xLongConds.startTime > 0 + // && xLongConds.signalTime > 0 + // && xLongConds.entryTime == 0 + // && states[0].parabolicSAR < states[0].sc.slow + // ) { + // // + // xLongConds.entryTime = barTime; + // return; + // } +} + +// +// Check and Fill Short Signal Conditions ... +void CheckXShortSignalConditions( + const int bar_index, + const int marketLen, + const XState &states[], + // + const double smoother = 10 +) { + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + bool isCrossUnder = + false; + + // + bool isCrossOver = + false; + + // + if ( + isCrossOver + && xShortConds.startTime == 0 + ) { + // + xShortConds.startTime = barTime; + return; + } + + // + if ( + isCrossUnder + && xShortConds.startTime > 0 + && xShortConds.signalTime == 0 + ) { + // + xShortConds.signalTime = barTime; + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index, // Bar Index ... + const int marketLen, // MarketLength for TP and SL ... + const int longCycleMult, // Long Cycle Multiplier for XRange Calculations ... + const double r2r, // Risk to Reward ratio ... + const XState &states[], + // + const double smoother = 10 +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + if (requestLong) { + // + if ( + !ValidateXLongConditions( + marketLen, + states, + smoother + ) + ) { + return result; + } + } else { + // + if ( + !ValidateXShortConditions( + marketLen, + states, + smoother + ) + ) { + return result; + } + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double askPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double bidPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double entryPrice = requestLong ? + askPrice : + bidPrice; + + // + double exitPrice = requestLong ? + bidPrice : + askPrice; + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + // + GetMarketLowestLow( + bar_index, + marketLen + ) + ; + + // + double hh = + // + GetMarketHighestHigh( + bar_index, + marketLen + ) + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = requestLong ? + MathMin(openPrice, closePrice) - ll : + hh - MathMax(openPrice, closePrice); + double reward = risk * r2r; // risk * r2r; // 300 * _Point; + // if (risk > (500 * _Point)) { + // reward = 300 * _Point; + // } + + // + double sl = requestLong ? + 0 : // ll : + 0; // ll; + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward; + + // // + // double fibLevel = 1.618; + // double fibLevelPrice = GetFibonacciLevel( + // tp, + // entryPrice, + // fibLevel, + // 1 + // ); + + // // + // if (requestLong) { + // sl = fibLevelPrice; + // } + + // + if ( + // + // Condition 1 ... + ( + tp > states[0].lc.hh + && ll == states[0].sc.ll + && states[0].sc.ll == states[0].mc.ll + ) + || + // + // Condition 2 ... + ( + states[0].sc.hh == states[0].mc.hh + && states[0].lc.hh == states[0].mc.hh + && states[0].sc.ll == states[0].mc.ll + ) + ) { + // + reward = risk * 1; + tp = requestLong ? + entryPrice + reward : + entryPrice - reward; + } + + // // + // int rangeMarketLength = marketLen * longCycleMult; + + // // + // XRange range = GetMarketRange( + // bar_index, + // rangeMarketLength, + // marketLen + // ); + + // // + // bool isRangeVerified = IsRangeVerified( + // bar_index, + // rangeMarketLength, + // marketLen, + // type, + // entryPrice, + // tp, + // range + // ); + + // // + // if (!isRangeVerified) { + // // + // // sl = requestLong ? + // // states[0].mc.ll : + // // states[0].mc.hh + // // ; + // } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XXX_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XXX_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXLongConditions( + const int marketLen, + const XState &states[], + // + const double smoother = 10 +) { + // + bool isConditionsFilled = + xLongConds.startTime > 0 + && xLongConds.signalTime > 0 + && xLongConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.signalTime + ); + + // + isBLFilled = + // + xLongConds.signalTime > xLongConds.startTime + && xLongConds.entryTime >= xLongConds.signalTime + && MathAbs(signalBarIndex - startBarIndex) > 2 + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXLongSignalConditions(); + } + + // + return result; +} + +bool ValidateXShortConditions( + const int marketLen, + const XState &states[], + // + const double smoother = 10 +) { + // + bool isConditionsFilled = + xShortConds.startTime > 0 + && xShortConds.signalTime > 0 + && xShortConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.signalTime + ); + + // + isBLFilled = + // + xShortConds.signalTime > xShortConds.startTime + && xShortConds.entryTime >= xShortConds.signalTime + && MathAbs(signalBarIndex - startBarIndex) > marketLen + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXShortSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXLongSignalConditions() { + // + xLongConds.startTime = 0; + xLongConds.signalTime = 0; +} + +// +// Clear Short Signal Conditions for New One ... +void ClearXShortSignalConditions() { + // + xShortConds.startTime = 0; + xShortConds.signalTime = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForXSignals( + const XSignal &signal, + const XState &states[], + const int marketLen, + // + const int shortCycleMult, + const int mediumCycleMult, + const int longCycleMult, + // + double smoother = 10 +) { + // + bool result = false; + + // + bool isSCTrendUp = false; + bool isSCTrendDown = false; + + // + bool isMCTrendUp = false; + bool isMCTrendDown = false; + + // + bool isLCTrendUp = false; + bool isLCTrendDown = false; + + // + XOHCL candle = GetCandleModel(0); + XOHCL pCandle = GetCandleModel(1); + + // // + // bool isRange = false; + // int rangeMarketLength = 5 * marketLen; + // for (int i = 1; i < rangeMarketLength; i++) { + // // + // XState iState = GetXState( + // i, + // marketLen, + // 0.01, + // 0.1, + // shortCycleMult, + // mediumCycleMult, + // longCycleMult + // ); + + // // + // isRange = + // iState.mc.hh == iState.lc.hh + // && iState.mc.hh == states[0].mc.hh + // ; + // } + + // // + // int statesLast = ArraySize(states) - 1; + // double scSlope = + // GetSlope( + // statesLast, + // states[statesLast].sc.slow, + // 0, + // states[0].sc.slow + // ); + // double mcSlope = + // GetSlope( + // statesLast, + // states[statesLast].mc.slow, + // 0, + // states[0].mc.slow + // ); + // double lcSlope = + // GetSlope( + // statesLast, + // states[statesLast].lc.slow, + // 0, + // states[0].lc.slow + // ); + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + isSCTrendUp = + states[0].sc.fast < states[0].sc.slow + && states[1].sc.fast < states[1].sc.slow + // && states[2].sc.fast < states[2].sc.slow + ; + + // + isMCTrendUp = + states[0].mc.fast < states[0].mc.slow + && states[1].mc.fast < states[1].mc.slow + // && states[2].mc.fast < states[2].mc.slow + ; + + // + isLCTrendUp = + states[0].lc.fast < states[0].lc.slow + && states[1].lc.fast < states[1].lc.slow + // && states[2].lc.fast < states[2].lc.slow + ; + + // + result = + // + // Starter ... + true + // + // Trending State ... + && isSCTrendUp + && isMCTrendUp + && isLCTrendUp + // + // && !isRange + // + // Condition 1 ... + && states[0].mc.fast > states[0].sc.slow + // + && states[0].lc.slow < states[0].sc.ll + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + result = + false + ; + } + + // // + // if (result) { + // // + // LogMessage( + // StringConcatenate( + // "scSlope: ", scSlope, + // ", mcSlope: ", mcSlope, + // ", lcSlope: ", lcSlope + // ) + // ); + // } + + // + return result; +} +// +// END Functions ... +// diff --git a/Bkp/Used/14020431/Libraries/x-saherelm.xr.signal.lib.mq4 b/Bkp/Used/14020431/Libraries/x-saherelm.xr.signal.lib.mq4 new file mode 100644 index 0000000..d8fc763 --- /dev/null +++ b/Bkp/Used/14020431/Libraries/x-saherelm.xr.signal.lib.mq4 @@ -0,0 +1,732 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 X Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Inputs ... +// +input double xrR2R = 2; // XR Risk To Reward Ratio + +// +input int xrOscillatorLength = 7; // XR Oscillator Length +input int xrFastLength = 20; // XR Fast Length +input int xrSlowLength = 50; // XR Slow Length +input int xrMarketRangeLength = 50; // XR Range Detector Length + +// +input int xrSwingLength = 7; // Swing Length +// +// END Inputs ... +// + +// +// START Global Requirement Functions ... +// +// +// XR Market State ... +struct XRMarketState { + // + double fast; + double slow; + + // + double prevFast; + double prevSlow; + + // + double oscillator; + double prevOscillator; + + // + double verifier; +}; + +// +struct XRState { + // + datetime start; + int length; + + // + double hh; + double ll; + double mid; +}; + +// +// XR Based Signal Conditions ... +struct XRSignalConditions { + // + datetime startTime; + datetime signalTime; + datetime entryTime; + + // + double value; + XRState state; +}; + +// +static XRSignalConditions xrLongConds; +static bool xrCloseLongTrades = false; +static bool xrWaitForLongSignals = true; + +// +static double xrMaximumDrawDown = 0; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckXRSignalHandler( + const int bar_index +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + + // + XOHCL candle = GetCandleModel(bar_index); + + // + XRMarketState state = GetXRMarketState( + bar_index + ); + + // + if (xrWaitForLongSignals) { + // + if ( + state.oscillator < state.fast + && state.oscillator < state.slow + && state.prevOscillator < state.prevFast + && state.prevOscillator < state.prevSlow + && candle.low < xrMaximumDrawDown + ) { + // + xrMaximumDrawDown = 0; + xrCloseLongTrades = true; + } + } else { + } +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXRLongSignalConditions( + const int bar_index +) { + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XOHCL candle = GetCandleModel(bar_index + 1); + + // + XRState xrState = GetXRange( + bar_index + ); + + // + double affectedValue = xrState.mid; + + // + XRMarketState state = GetXRMarketState( + bar_index + ); + + // + bool isCrossOver = + state.fast > state.slow + && !(state.prevFast > state.prevSlow) + ; + + // + bool isCrossUnder = + state.fast < state.slow + && !(state.prevFast < state.prevSlow) + ; + + // + if ( + isCrossUnder + && xrLongConds.startTime == 0 + ) { + // + xrLongConds.startTime = barTime; + return; + } + + // + if ( + isCrossOver + && xrLongConds.startTime > 0 + && xrLongConds.signalTime == 0 + ) { + // + xrLongConds.value = affectedValue; + xrLongConds.state = xrState; + + // + xrLongConds.signalTime = barTime; + xrLongConds.entryTime = barTime; + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXRSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + if (requestLong) { + // + if ( + !ValidateXLongConditions() + ) { + return result; + } + } else { + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double askPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double bidPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double entryPrice = requestLong ? + askPrice : + bidPrice; + + // + double exitPrice = requestLong ? + bidPrice : + askPrice; + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + // + GetMarketLowestLow( + bar_index, + xrSwingLength + ) + ; + + // + double hh = + // + GetMarketHighestHigh( + bar_index, + xrSwingLength + ) + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = requestLong ? + MathMin(openPrice, closePrice) - ll : + hh - MathMax(openPrice, closePrice); + double reward = risk * xrR2R; + + // + double sl = requestLong ? + 0 : + ll; + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward + ; + + // + xrMaximumDrawDown = + xrMaximumDrawDown == 0 ? + xrLongConds.state.mid : + xrMaximumDrawDown > xrLongConds.state.mid ? + xrMaximumDrawDown : + xrLongConds.state.mid; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XR_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XR_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXLongConditions() { + // + bool isConditionsFilled = + xrLongConds.startTime > 0 + && xrLongConds.signalTime > 0 + && xrLongConds.entryTime > 0 + // + && xrLongConds.value > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xrLongConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xrLongConds.signalTime + ); + + // + // Count Affected Value Touches ... + int cStartBarIndex = iBarShift( + _Symbol, + _Period, + xrLongConds.state.start + ); + + // + int cEndBarIndex = cStartBarIndex + xrLongConds.state.length; + + // + int highTouched = 0; + int valueTouched = 0; + for (int i = cStartBarIndex; i <= cStartBarIndex + cEndBarIndex; i++) { + // + XOHCL iCandle = GetCandleModel(i); + + // + if ( + iCandle.low < xrLongConds.value + && iCandle.high > xrLongConds.value + ) { + valueTouched++; + } + + // + if ( + iCandle.low < xrLongConds.state.hh + && iCandle.high > xrLongConds.state.hh + ) { + highTouched++; + } + } + + // + isBLFilled = + // + xrLongConds.signalTime > xrLongConds.startTime + && xrLongConds.entryTime >= xrLongConds.signalTime + // + && highTouched < 2 + && valueTouched > (cEndBarIndex - cStartBarIndex) / 6 + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xrWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXRLongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXRLongSignalConditions() { + // + xrLongConds.startTime = 0; + xrLongConds.signalTime = 0; + xrLongConds.entryTime = 0; + + // + xrLongConds.value = 0; + + // + XRState e = {}; + xrLongConds.state = e; +} + +// +// Check State for Long Signals ... +bool IsReadyForXRSignals( + const XSignal &signal +) { + // + bool result = false; + + // + XRMarketState state = GetXRMarketState(0); + + // + double fSDif = MathAbs(state.fast - state.slow); + double fSDifP = MathAbs(state.prevFast - state.prevSlow); + + // + double emaSlope = GetSlope( + 1, + state.prevOscillator, + 2, + state.oscillator + ); + + // + XOHCL pCandle = GetCandleModel(1); + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + result = + // + // Starter ... + true + // + && state.oscillator > state.fast + && emaSlope > 0 + && signal.entry > state.verifier + // + && fSDif > fSDifP + // + && signal.entry < xrLongConds.state.hh + && signal.entry > xrLongConds.state.mid + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + result = + false + ; + } + + // + return result; +} +// +// END Functions ... +// + +// +// START Data Providers ... +// +// +static XRState lastXRState; +XRState GetXRange( + const int bar_index +) { + // + XRState result = {}; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + int marketBarIndex = bar_index + xrMarketRangeLength; + + // + // Highest High ... + // + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketBarIndex, + bar_index + ); + + // + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + // Lowest Low ... + // + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketBarIndex, + bar_index + ); + + // + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + if (lastXRState.start == 0) { + // + lastXRState.start = barTime; + lastXRState.length = xrMarketRangeLength; + + // + lastXRState.hh = hh; + lastXRState.ll = ll; + + // + // Middle ... + double mid = (hh + ll) / 2; + lastXRState.mid = mid; + } else { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + lastXRState.start + ); + + // + if (startBarIndex - bar_index >= xrMarketRangeLength) { + // + lastXRState.start = barTime; + lastXRState.length = xrMarketRangeLength; + + // + lastXRState.hh = hh; + lastXRState.ll = ll; + + // + // Middle ... + double mid = (hh + ll) / 2; + lastXRState.mid = mid; + } + } + + // + result = lastXRState; + + // + return result; +} + +// +XRMarketState GetXRMarketState( + const int bar_index +) { + // + XRMarketState result = {}; + + // + // Prepare Market Length ... + int xrVerifierMarketLength = GetDailyCandleCount(); + + // + // Calculate Fast and Prev Fast ... + // + // Fast ... + double fast = GetMA( + bar_index + 1, + xrFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + // Prev Fast ... + double prevFast = GetMA( + bar_index + 2, + xrFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + // Calculate Slow and Prev Slow ... + + // + // Slow ... + double slow = GetMA( + bar_index + 1, + xrSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + // Prev Slow ... + double prevSlow = GetMA( + bar_index + 2, + xrSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + // Calculate Oscillator and Prev Oscillator ... + + // + // Oscillator ... + double oscillator = GetMA( + bar_index, + xrOscillatorLength, + 0, + MODE_EMA, + PRICE_CLOSE + ); + + // + // Prev Oscillator ... + double prevOscillator = GetMA( + bar_index + 1, + xrOscillatorLength, + 0, + MODE_EMA, + PRICE_CLOSE + ); + + // + // Calculate Verifier ... + double verifier = GetMA( + bar_index, + xrVerifierMarketLength, + 0, + MODE_EMA, + PRICE_CLOSE + ); + + // + result.fast = fast; + result.slow = slow; + result.verifier = verifier; + result.prevFast = prevFast; + result.prevSlow = prevSlow; + result.oscillator = oscillator; + result.prevOscillator = prevOscillator; + + // + return result; +} +// +// END Data Providers ... +// \ No newline at end of file diff --git a/Bkp/Used/14020502/Docs/Reports/14020412/OSC XMA 15Min Long/Only OSC/StrategyTester_1.gif b/Bkp/Used/14020502/Docs/Reports/14020412/OSC XMA 15Min Long/Only OSC/StrategyTester_1.gif new file mode 100644 index 0000000..64e458f Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/14020412/OSC XMA 15Min Long/Only OSC/StrategyTester_1.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/14020412/OSC XMA 15Min Long/Only OSC/StrategyTester_1.htm b/Bkp/Used/14020502/Docs/Reports/14020412/OSC XMA 15Min Long/Only OSC/StrategyTester_1.htm new file mode 100644 index 0000000..9cf344a --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/14020412/OSC XMA 15Min Long/Only OSC/StrategyTester_1.htm @@ -0,0 +1,762 @@ + + + + Strategy Tester: x-saherelm.osc.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.osc.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2023.01.03 01:00 - 2023.06.28 23:45 (2023.01.01 - 2023.06.29)
ModelEvery tick (the most precise method based on all available least timeframes)
Bars in test12551Ticks modelled15360882Modelling qualityn/a
Mismatched charts errors1395
Initial deposit1000.00SpreadCurrent (50)
Total net profit223.50Gross profit1480.53Gross loss-1257.03
Profit factor1.18Expected payoff0.63
Absolute drawdown66.94Maximal drawdown434.20 (31.15%)Relative drawdown31.15% (434.20)
Total trades353Short positions (won %)0 (0.00%)Long positions (won %)353 (89.80%)
Profit trades (% of total)317 (89.80%)Loss trades (% of total)36 (10.20%)
Largestprofit trade33.12loss trade-82.64
Averageprofit trade4.67loss trade-34.92
Maximumconsecutive wins (profit in money)80 (449.04)consecutive losses (loss in money)5 (-149.41)
Maximalconsecutive profit (count of wins)449.04 (80)consecutive loss (count of losses)-225.40 (4)
Averageconsecutive wins26consecutive losses3
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12023.01.03 01:15buy10.011827.450.001843.83
22023.01.03 04:15buy20.011829.930.001835.55
32023.01.03 04:40t/p20.011835.550.001835.555.621005.62
42023.01.03 08:18t/p10.011843.830.001843.8316.381022.00
52023.01.03 11:30buy30.011841.650.001855.25
62023.01.03 12:00buy40.011839.080.001847.54
72023.01.03 14:30buy50.011835.760.001845.00
82023.01.03 16:33t/p50.011845.000.001845.009.241031.24
92023.01.03 16:40t/p40.011847.540.001847.548.461039.70
102023.01.03 18:45buy60.011831.470.001838.67
112023.01.03 19:43t/p60.011838.670.001838.677.201046.90
122023.01.04 02:45buy70.011838.470.001842.41
132023.01.04 03:42t/p70.011842.410.001842.413.941050.84
142023.01.04 09:32t/p30.011855.250.001855.2513.601064.44
152023.01.04 15:30buy80.011859.480.001872.26
162023.01.04 17:43buy90.011858.070.001872.79
172023.01.04 18:15buy100.011859.520.001879.82
182023.01.04 22:13buy110.011852.910.001863.57
192023.01.04 23:00close110.011855.120.001863.572.211066.65
202023.01.04 23:00buy120.011855.620.001866.04
212023.01.05 04:48close120.011855.910.001866.040.291066.94
222023.01.05 04:48buy130.011856.410.001859.81
232023.01.06 17:07t/p130.011859.810.001859.813.401070.34
242023.01.09 03:38t/p80.011872.260.001872.2612.781083.12
252023.01.09 03:42t/p90.011872.790.001872.7914.721097.84
262023.01.09 09:17t/p100.011879.820.001879.8220.301118.14
272023.01.09 14:08buy140.011873.920.001879.06
282023.01.09 16:00buy150.011878.500.001889.38
292023.01.09 16:03t/p140.011879.060.001879.065.141123.28
302023.01.09 18:45buy160.011876.880.001885.72
312023.01.09 20:30buy170.011873.710.001882.41
322023.01.09 21:08buy180.011873.080.001877.60
332023.01.09 21:45close180.011873.900.001877.600.821124.10
342023.01.09 21:45close170.011873.900.001882.410.191124.29
352023.01.09 21:45buy190.011874.400.001882.66
362023.01.09 23:42buy200.011871.550.001875.43
372023.01.10 03:30close200.011873.400.001875.431.851126.14
382023.01.10 03:30buy210.011873.900.001885.50
392023.01.10 19:45close210.011875.230.001885.501.331127.47
402023.01.10 19:45close190.011875.230.001882.660.831128.30
412023.01.10 19:45buy220.011875.730.001884.15
422023.01.10 20:48buy230.011875.450.001880.99
432023.01.10 23:00close230.011877.930.001880.992.481130.78
442023.01.10 23:00close220.011877.930.001884.152.201132.98
452023.01.10 23:00close160.011877.930.001885.721.051134.03
462023.01.10 23:00buy240.011878.430.001883.37
472023.01.10 23:30buy250.011877.800.001880.92
482023.01.11 02:00buy260.011877.490.001878.97
492023.01.11 07:11t/p260.011878.970.001878.971.481135.51
502023.01.11 07:33t/p250.011880.920.001880.923.121138.63
512023.01.11 07:37t/p240.011883.370.001883.374.941143.57
522023.01.11 15:45buy270.011880.230.001888.51
532023.01.11 18:46buy280.011873.780.001885.52
542023.01.12 01:15buy290.011877.590.001880.31
552023.01.12 03:57t/p290.011880.310.001880.312.721146.29
562023.01.12 13:13t/p280.011885.520.001885.5211.741158.03
572023.01.12 14:22t/p270.011888.510.001888.518.281166.31
582023.01.12 14:23t/p150.011889.380.001889.3810.881177.19
592023.01.12 15:45buy300.011892.180.001925.30
602023.01.12 18:00buy310.011889.130.001907.11
612023.01.13 08:30buy320.011895.510.001901.27
622023.01.13 09:45buy330.011897.320.001903.56
632023.01.13 10:08t/p320.011901.270.001901.275.761182.95
642023.01.13 10:12t/p330.011903.560.001903.566.241189.19
652023.01.13 10:42t/p310.011907.110.001907.1117.981207.17
662023.01.13 15:41buy340.011899.570.001908.39
672023.01.13 16:47t/p340.011908.390.001908.398.821215.99
682023.01.16 04:31t/p300.011925.300.001925.3033.121249.11
692023.01.16 15:55buy350.011914.440.001919.66
702023.01.16 16:30buy360.011914.600.001920.40
712023.01.16 20:00buy370.011914.160.001916.24
722023.01.17 01:05t/p370.011916.240.001916.242.081251.19
732023.01.17 04:15buy380.011915.870.001921.35
742023.01.17 09:45buy390.011910.040.001915.68
752023.01.17 10:45close390.011910.310.001915.680.271251.46
762023.01.17 10:45buy400.011910.810.001917.41
772023.01.17 15:30close400.011911.980.001917.411.171252.63
782023.01.17 15:30buy410.011912.480.001922.68
792023.01.17 18:30close410.011912.600.001922.680.121252.75
802023.01.17 18:30buy420.011913.100.001920.64
812023.01.18 15:30t/p350.011919.660.001919.665.221257.97
822023.01.18 15:30t/p360.011920.400.001920.405.801263.77
832023.01.18 15:30t/p420.011920.640.001920.647.541271.31
842023.01.18 15:31t/p380.011921.350.001921.355.481276.79
852023.01.18 23:30buy430.011904.630.001908.69
862023.01.19 01:06buy440.011904.440.001906.46
872023.01.19 01:51t/p440.011906.460.001906.462.021278.81
882023.01.19 02:33t/p430.011908.690.001908.694.061282.87
892023.01.19 04:30buy450.011903.550.001908.11
902023.01.19 05:07t/p450.011908.110.001908.114.561287.43
912023.01.19 13:00buy460.011909.940.001915.62
922023.01.19 13:30buy470.011909.670.001914.81
932023.01.19 14:08buy480.011909.630.001912.57
942023.01.19 14:45buy490.011910.690.001918.15
952023.01.19 15:30close490.011911.860.001918.151.171288.60
962023.01.19 15:30close480.011911.860.001912.572.231290.83
972023.01.19 15:30close470.011911.860.001914.812.191293.02
982023.01.19 15:30close460.011911.860.001915.621.921294.94
992023.01.19 15:30buy500.011912.360.001922.84
1002023.01.19 17:36t/p500.011922.840.001922.8410.481305.42
1012023.01.20 07:45buy510.011927.080.001934.26
1022023.01.20 10:06t/p510.011934.260.001934.267.181312.60
1032023.01.20 11:30buy520.011931.900.001942.00
1042023.01.20 12:15buy530.011929.300.001934.20
1052023.01.20 13:00buy540.011930.340.001935.18
1062023.01.20 15:03buy550.011929.550.001933.49
1072023.01.23 03:50t/p550.011933.490.001933.493.941316.54
1082023.01.23 04:12t/p530.011934.200.001934.204.901321.44
1092023.01.23 04:18t/p540.011935.180.001935.184.841326.28
1102023.01.23 10:37buy560.011923.900.001930.20
1112023.01.23 15:15buy570.011926.780.001933.48
1122023.01.23 17:31buy580.011918.590.001931.51
1132023.01.23 22:38t/p560.011930.200.001930.206.301332.58
1142023.01.23 22:45t/p580.011931.510.001931.5112.921345.50
1152023.01.24 03:36t/p570.011933.480.001933.486.701352.20
1162023.01.24 10:03t/p520.011942.000.001942.0010.101362.30
1172023.01.24 17:27buy590.011930.540.001952.36
1182023.01.25 01:45buy600.011937.100.001937.96
1192023.01.25 02:03t/p600.011937.960.001937.960.861363.16
1202023.01.25 03:00buy610.011937.140.001940.86
1212023.01.25 08:32buy620.011930.890.001938.43
1222023.01.25 10:27buy630.011931.860.001939.26
1232023.01.25 10:45close620.011931.070.001938.430.181363.34
1242023.01.25 10:45close590.011931.070.001952.360.531363.87
1252023.01.25 10:45buy640.011931.570.001939.29
1262023.01.25 14:38buy650.011926.590.001930.55
1272023.01.25 16:42t/p650.011930.550.001930.553.961367.83
1282023.01.25 19:32t/p630.011939.260.001939.267.401375.23
1292023.01.25 19:32t/p640.011939.290.001939.297.721382.95
1302023.01.25 20:21t/p610.011940.860.001940.863.721386.67
1312023.01.26 03:45buy660.011945.510.001950.81
1322023.01.26 04:15buy670.011946.010.001952.31
1332023.01.26 08:00buy680.011947.760.001952.28
1342023.01.26 10:30buy690.011943.920.001955.06
1352023.02.01 22:02close690.011944.430.001955.060.511387.18
1362023.02.01 22:08close660.011946.020.001950.810.511387.69
1372023.02.01 22:08close670.011946.520.001952.310.511388.20
1382023.02.01 22:31close680.011948.270.001952.280.511388.71
1392023.02.02 13:30buy700.011955.460.001962.46
1402023.02.02 14:16buy710.011955.350.001961.87
1412023.02.03 11:15buy720.011913.840.001919.96
1422023.02.09 18:30close700.011872.820.001962.46-82.641306.07
1432023.02.09 19:15close710.011873.210.001961.87-82.141223.93
1442023.02.10 03:00buy730.011863.180.001869.10
1452023.02.10 04:00buy740.011862.590.001868.75
1462023.02.10 04:45buy750.011863.040.001870.28
1472023.02.10 10:06t/p740.011868.750.001868.756.161230.09
1482023.02.10 10:06t/p730.011869.100.001869.105.921236.01
1492023.02.10 10:08t/p750.011870.280.001870.287.241243.25
1502023.02.10 12:30buy760.011864.280.001871.36
1512023.02.10 13:30buy770.011862.320.001865.36
1522023.02.10 14:43buy780.011865.240.001872.48
1532023.02.10 15:47t/p770.011865.360.001865.363.041246.29
1542023.02.10 16:00buy790.011867.310.001877.81
1552023.02.10 16:15close720.011866.390.001919.96-47.451198.84
1562023.02.10 17:15buy800.011865.270.001877.09
1572023.02.17 17:30close760.011833.960.001871.36-30.321168.52
1582023.02.17 19:30close780.011841.780.001872.48-23.461145.06
1592023.02.17 21:00close790.011841.980.001877.81-25.331119.73
1602023.02.17 22:15close800.011842.420.001877.09-22.851096.88
1612023.02.20 03:03buy810.011839.590.001842.75
1622023.02.20 04:06buy820.011840.900.001846.68
1632023.02.20 04:33t/p810.011842.750.001842.753.161100.04
1642023.02.20 05:45buy830.011842.690.001845.15
1652023.02.20 07:45buy840.011843.690.001848.09
1662023.02.20 08:06t/p830.011845.150.001845.152.461102.50
1672023.02.20 08:30buy850.011843.960.001848.90
1682023.02.20 09:15buy860.011845.180.001849.18
1692023.02.20 10:02t/p820.011846.680.001846.685.781108.28
1702023.02.20 11:00buy870.011844.500.001849.72
1712023.02.20 12:00close840.011843.730.001848.090.041108.32
1722023.02.20 12:00buy880.011844.230.001849.89
1732023.02.20 13:15close850.011844.160.001848.900.201108.52
1742023.02.20 13:15buy890.011844.660.001847.74
1752023.02.20 15:30close890.011845.880.001847.741.221109.74
1762023.02.20 15:30close880.011845.880.001849.891.651111.39
1772023.02.20 15:30close870.011845.880.001849.721.381112.77
1782023.02.20 15:30close860.011845.880.001849.180.701113.47
1792023.02.20 15:30buy900.011846.380.001853.38
1802023.02.20 16:00buy910.011846.710.001854.37
1812023.02.20 18:45buy920.011843.700.001845.84
1822023.02.21 01:15buy930.011842.570.001845.95
1832023.02.21 04:30close930.011842.610.001845.950.041113.51
1842023.02.21 04:30buy940.011843.110.001848.65
1852023.02.27 23:00close900.011816.990.001853.38-29.391084.12
1862023.02.27 23:30close910.011816.780.001854.37-29.931054.19
1872023.02.28 03:15close920.011816.580.001845.84-27.121027.07
1882023.02.28 09:30close940.011811.970.001848.65-31.14995.93
1892023.02.28 11:00buy950.011811.070.001823.15
1902023.02.28 13:45buy960.011810.890.001816.49
1912023.02.28 15:30buy970.011809.700.001812.60
1922023.02.28 15:52t/p970.011812.600.001812.602.90998.83
1932023.02.28 16:45t/p960.011816.490.001816.495.601004.43
1942023.02.28 17:02t/p950.011823.150.001823.1512.081016.51
1952023.03.01 16:00buy980.011837.490.001844.13
1962023.03.01 16:30buy990.011839.010.001848.69
1972023.03.01 16:57t/p980.011844.130.001844.136.641023.15
1982023.03.01 17:30buy1000.011838.590.001848.29
1992023.03.02 04:30buy1010.011836.160.001845.80
2002023.03.02 05:00buy1020.011834.900.001841.80
2012023.03.02 16:45close1020.011835.000.001841.800.101023.25
2022023.03.02 16:45buy1030.011835.500.001845.76
2032023.03.02 23:17close1030.011835.890.001845.760.391023.64
2042023.03.02 23:17buy1040.011836.390.001838.65
2052023.03.03 01:15close1040.011836.520.001838.650.131023.77
2062023.03.03 01:15close1010.011836.520.001845.800.361024.13
2072023.03.03 01:15buy1050.011837.020.001839.76
2082023.03.03 02:03t/p1050.011839.760.001839.762.741026.87
2092023.03.03 13:16t/p1000.011848.290.001848.299.701036.57
2102023.03.03 13:17t/p990.011848.690.001848.699.681046.25
2112023.03.03 18:00buy1060.011845.090.001856.21
2122023.03.06 06:13t/p1060.011856.210.001856.2111.121057.37
2132023.03.06 12:30buy1070.011852.960.001857.04
2142023.03.07 03:30buy1080.011846.530.001850.83
2152023.03.07 09:26t/p1080.011850.830.001850.834.301061.67
2162023.03.08 02:01buy1090.011814.410.001816.13
2172023.03.08 03:32buy1100.011813.370.001814.89
2182023.03.08 06:17buy1110.011811.370.001813.33
2192023.03.08 08:53t/p1110.011813.330.001813.331.961063.63
2202023.03.08 08:53buy1120.011813.830.001818.23
2212023.03.08 09:41t/p1100.011814.890.001814.891.521065.15
2222023.03.08 10:30buy1130.011814.330.001816.53
2232023.03.08 13:15close1130.011815.580.001816.531.251066.40
2242023.03.08 13:15close1120.011815.580.001818.231.751068.15
2252023.03.08 13:15close1090.011815.580.001816.131.171069.32
2262023.03.08 13:15buy1140.011816.080.001823.00
2272023.03.08 14:16buy1150.011815.450.001819.45
2282023.03.08 15:00buy1160.011815.410.001818.91
2292023.03.08 16:32close1160.011816.500.001818.911.091070.41
2302023.03.08 16:32close1150.011816.500.001819.451.051071.46
2312023.03.08 16:32close1140.011816.500.001823.000.421071.88
2322023.03.08 16:32buy1170.011817.000.001819.60
2332023.03.08 16:48t/p1170.011819.600.001819.602.601074.48
2342023.03.08 19:45buy1180.011818.290.001823.63
2352023.03.08 21:15buy1190.011816.200.001821.34
2362023.03.09 01:15buy1200.011815.680.001820.58
2372023.03.09 15:32t/p1200.011820.580.001820.584.901079.38
2382023.03.09 15:33t/p1190.011821.340.001821.345.141084.52
2392023.03.09 15:43t/p1180.011823.630.001823.635.341089.86
2402023.03.09 19:15buy1210.011828.400.001833.62
2412023.03.09 20:43t/p1210.011833.620.001833.625.221095.08
2422023.03.09 23:15buy1220.011831.560.001836.08
2432023.03.09 23:45buy1230.011831.330.001835.39
2442023.03.10 04:15buy1240.011832.700.001837.24
2452023.03.10 10:02t/p1230.011835.390.001835.394.061099.14
2462023.03.10 10:02t/p1220.011836.080.001836.084.521103.66
2472023.03.10 12:15buy1250.011833.580.001838.30
2482023.03.10 13:15buy1260.011835.020.001842.60
2492023.03.10 14:00close1250.011834.790.001838.301.211104.87
2502023.03.10 14:00close1240.011834.790.001837.242.091106.96
2512023.03.10 14:00buy1270.011835.290.001840.79
2522023.03.10 15:32t/p1270.011840.790.001840.795.501112.46
2532023.03.10 15:43t/p1260.011842.600.001842.607.581120.04
2542023.03.10 15:45buy1280.011844.210.001868.45
2552023.03.10 16:35close1070.011853.470.001857.040.511120.55
2562023.03.10 19:15buy1290.011859.600.001869.92
2572023.03.10 22:53t/p1280.011868.450.001868.4524.241144.79
2582023.03.10 23:01t/p1290.011869.920.001869.9210.321155.11
2592023.03.13 04:15buy1300.011876.090.001883.31
2602023.03.13 04:30t/p1300.011883.310.001883.317.221162.33
2612023.03.13 08:15buy1310.011882.210.001891.87
2622023.03.13 10:15buy1320.011878.890.001892.99
2632023.03.13 11:37t/p1310.011891.870.001891.879.661171.99
2642023.03.13 11:40t/p1320.011892.990.001892.9914.101186.09
2652023.03.13 13:30buy1330.011888.130.001902.01
2662023.03.13 14:53t/p1330.011902.010.001902.0113.881199.97
2672023.03.13 19:00buy1340.011909.440.001921.90
2682023.03.14 05:20buy1350.011907.130.001911.61
2692023.03.14 08:16t/p1350.011911.610.001911.614.481204.45
2702023.03.14 16:07buy1360.011905.350.001919.23
2712023.03.14 16:45buy1370.011905.430.001924.89
2722023.03.14 18:45buy1380.011906.720.001915.12
2732023.03.15 13:32t/p1380.011915.120.001915.128.401212.85
2742023.03.15 14:01t/p1360.011919.230.001919.2313.881226.73
2752023.03.15 14:03t/p1340.011921.900.001921.9012.461239.19
2762023.03.15 14:13t/p1370.011924.890.001924.8919.461258.65
2772023.03.15 16:00buy1390.011926.410.001943.85
2782023.03.15 16:45buy1400.011922.870.001933.23
2792023.03.15 17:30buy1410.011926.280.001943.20
2802023.03.15 18:00buy1420.011927.410.001943.71
2812023.03.15 18:23t/p1400.011933.230.001933.2310.361269.01
2822023.03.15 21:12buy1430.011919.750.001933.45
2832023.03.16 11:45close1430.011920.120.001933.450.371269.38
2842023.03.16 11:45buy1440.011920.620.001928.32
2852023.03.16 14:08t/p1440.011928.320.001928.327.701277.08
2862023.03.16 16:15buy1450.011928.890.001939.59
2872023.03.16 16:45close1450.011931.480.001939.592.591279.67
2882023.03.16 16:45close1420.011931.480.001943.714.071283.74
2892023.03.16 16:45close1410.011931.480.001943.205.201288.94
2902023.03.16 16:45close1390.011931.480.001943.855.071294.01
2912023.03.16 16:45buy1460.011931.980.001948.86
2922023.03.16 20:47buy1470.011920.920.001929.86
2932023.03.16 22:30buy1480.011919.600.001921.78
2942023.03.17 00:05buy1490.011920.130.001922.77
2952023.03.17 00:30close1490.011920.170.001922.770.041294.05
2962023.03.17 00:30close1480.011920.170.001921.780.571294.62
2972023.03.17 00:30buy1500.011920.670.001924.39
2982023.03.17 01:00buy1510.011920.330.001922.93
2992023.03.17 03:30close1510.011921.630.001922.931.301295.92
3002023.03.17 03:30close1500.011921.630.001924.390.961296.88
3012023.03.17 03:30close1470.011921.630.001929.860.711297.59
3022023.03.17 03:30buy1520.011922.130.001929.29
3032023.03.17 05:27t/p1520.011929.290.001929.297.161304.75
3042023.03.17 15:12t/p1460.011948.860.001948.8616.881321.63
3052023.03.17 18:45buy1530.011960.110.001969.11
3062023.03.17 19:31t/p1530.011969.110.001969.119.001330.63
3072023.03.17 22:30buy1540.011980.400.001993.04
3082023.03.20 02:02buy1550.011978.210.001982.81
3092023.03.20 07:52t/p1550.011982.810.001982.814.601335.23
3102023.03.20 08:03t/p1540.011993.040.001993.0412.641347.87
3112023.03.21 00:15buy1560.011979.290.001983.23
3122023.03.21 02:15buy1570.011979.540.001985.16
3132023.03.21 02:47buy1580.011978.860.001984.78
3142023.03.21 04:53t/p1560.011983.230.001983.233.941351.81
3152023.03.21 05:32t/p1580.011984.780.001984.785.921357.73
3162023.03.21 15:30buy1590.011965.280.001977.62
3172023.03.22 01:00buy1600.011941.500.001944.64
3182023.03.22 02:45buy1610.011943.740.001946.06
3192023.03.22 03:02t/p1600.011944.640.001944.643.141360.87
3202023.03.22 03:13t/p1610.011946.060.001946.062.321363.19
3212023.03.22 03:45buy1620.011945.010.001949.71
3222023.03.22 05:31buy1630.011941.140.001945.66
3232023.03.22 10:15close1630.011943.300.001945.662.161365.35
3242023.03.22 10:15buy1640.011943.800.001962.26
3252023.03.22 16:48t/p1620.011949.710.001949.714.701370.05
3262023.03.22 20:03t/p1640.011962.260.001962.2618.461388.51
3272023.03.22 20:50t/p1590.011977.620.001977.6212.341400.85
3282023.03.23 01:15buy1650.011966.940.001971.16
3292023.03.23 02:03t/p1650.011971.160.001971.164.221405.07
3302023.03.23 10:15buy1660.011978.440.001984.82
3312023.03.23 12:00buy1670.011978.390.001985.17
3322023.03.23 12:30buy1680.011979.800.001988.88
3332023.03.23 14:15close1670.011978.410.001985.170.021405.09
3342023.03.23 14:15buy1690.011978.910.001985.01
3352023.03.23 15:30close1660.011978.450.001984.820.011405.10
3362023.03.23 15:30buy1700.011978.950.002003.17
3372023.03.23 17:22t/p1690.011985.010.001985.016.101411.20
3382023.03.23 17:22t/p1570.011985.160.001985.165.621416.82
3392023.03.23 18:16t/p1680.011988.880.001988.889.081425.90
3402023.03.23 21:15buy1710.011996.500.002012.82
3412023.03.23 22:00buy1720.011998.160.002017.82
3422023.03.24 02:30buy1730.011994.000.002001.48
3432023.03.24 03:00close1700.011993.560.002003.1714.611440.51
3442023.03.24 03:00buy1740.011994.060.002002.12
3452023.03.24 14:00close1740.011995.620.002002.121.561442.07
3462023.03.24 14:00close1730.011995.620.002001.481.621443.69
3472023.03.24 14:00buy1750.011996.120.002006.46
3482023.03.24 14:30buy1760.011997.220.002009.76
3492023.03.24 16:45close1750.011996.950.002006.460.831444.52
3502023.03.24 16:45close1710.011996.950.002012.820.451444.97
3512023.03.24 16:45buy1770.011997.450.002019.99
3522023.03.24 17:15buy1780.011993.810.002008.41
3532023.03.31 05:00close1720.011982.100.002017.82-16.061428.91
3542023.03.31 12:01buy1790.011976.870.001980.91
3552023.03.31 14:07t/p1790.011980.910.001980.914.041432.95
3562023.03.31 15:45buy1800.011982.210.001993.71
3572023.03.31 20:30close1760.011968.440.002009.76-28.781404.17
3582023.03.31 21:45buy1810.011971.180.001979.18
3592023.03.31 22:45close1770.011969.930.002019.99-27.521376.65
3602023.03.31 23:15close1780.011968.940.002008.41-24.871351.78
3612023.04.03 09:34buy1820.011955.270.001962.69
3622023.04.03 10:15buy1830.011958.850.001974.33
3632023.04.03 11:02t/p1820.011962.690.001962.697.421359.20
3642023.04.03 14:17t/p1830.011974.330.001974.3315.481374.68
3652023.04.03 15:03t/p1810.011979.180.001979.188.001382.68
3662023.04.03 17:15buy1840.011983.360.002004.70
3672023.04.03 21:30buy1850.011985.250.001991.47
3682023.04.03 22:16buy1860.011985.360.001989.58
3692023.04.03 22:45close1860.011985.520.001989.580.161382.84
3702023.04.03 22:45close1850.011985.520.001991.470.271383.11
3712023.04.03 22:45close1840.011985.520.002004.702.161385.27
3722023.04.03 22:45close1800.011985.520.001993.713.311388.58
3732023.04.03 22:45buy1870.011986.020.001993.18
3742023.04.04 01:15buy1880.011985.530.001988.81
3752023.04.04 02:06buy1890.011984.590.001985.05
3762023.04.04 02:38t/p1890.011985.050.001985.050.461389.04
3772023.04.04 03:30buy1900.011984.950.001987.71
3782023.04.04 08:18buy1910.011980.650.001984.97
3792023.04.04 11:00close1910.011982.000.001984.971.351390.39
3802023.04.04 11:00buy1920.011982.500.001992.90
3812023.04.04 13:30close1920.011983.790.001992.901.291391.68
3822023.04.04 13:30buy1930.011984.290.001991.91
3832023.04.04 16:25t/p1900.011987.710.001987.712.761394.44
3842023.04.04 16:32t/p1880.011988.810.001988.813.281397.72
3852023.04.04 16:44t/p1930.011991.910.001991.917.621405.34
3862023.04.04 17:00t/p1870.011993.180.001993.187.161412.50
3872023.04.05 18:45buy1940.012021.120.002042.96
3882023.04.05 21:15buy1950.012022.000.002027.24
3892023.04.05 22:30buy1960.012022.220.002024.76
3902023.04.06 01:45buy1970.012020.650.002023.91
3912023.04.12 15:31close1970.012021.180.002023.910.531413.03
3922023.04.12 15:32close1940.012021.640.002042.960.521413.55
3932023.04.12 15:32close1950.012022.510.002027.240.511414.06
3942023.04.12 15:33close1960.012022.730.002024.760.511414.57
3952023.04.12 18:00buy1980.012007.810.002019.03
3962023.04.12 19:15buy1990.012008.540.002014.38
3972023.04.12 21:08t/p1990.012014.380.002014.385.841420.41
3982023.04.13 03:01t/p1980.012019.030.002019.0311.221431.63
3992023.04.13 05:15buy2000.012019.460.002026.04
4002023.04.13 07:15buy2010.012019.060.002025.18
4012023.04.13 09:15buy2020.012018.670.002024.85
4022023.04.13 10:38t/p2020.012024.850.002024.856.181437.81
4032023.04.13 10:40t/p2010.012025.180.002025.186.121443.93
4042023.04.13 11:05t/p2000.012026.040.002026.046.581450.51
4052023.04.13 18:45buy2030.012042.040.002058.26
4062023.04.13 23:00buy2040.012040.760.002048.48
4072023.04.14 03:00buy2050.012040.040.002042.08
4082023.04.14 03:30buy2060.012040.250.002043.07
4092023.04.14 03:42t/p2050.012042.080.002042.082.041452.55
4102023.04.14 03:45t/p2060.012043.070.002043.072.821455.37
4112023.04.14 04:15buy2070.012042.350.002049.37
4122023.04.14 09:00buy2080.012043.110.002049.23
4132023.04.14 09:31close2070.012042.930.002049.370.581455.95
4142023.04.14 09:31close2040.012042.930.002048.482.171458.12
4152023.04.14 09:31close2030.012042.930.002058.260.891459.01
4162023.04.14 09:31buy2090.012043.430.002050.21
4172023.04.14 12:36buy2100.012036.710.002044.67
4182023.04.14 15:30buy2110.012036.920.002045.88
4192023.04.21 14:00close2080.011987.900.002049.23-55.211403.80
4202023.04.21 14:30close2090.011985.170.002050.21-58.261345.54
4212023.04.21 15:32buy2120.011990.420.002004.28
4222023.04.21 17:30close2100.011982.080.002044.67-54.631290.91
4232023.04.21 20:30close2110.011979.620.002045.88-57.301233.61
4242023.04.24 09:00buy2130.011979.680.001983.98
4252023.04.24 10:30buy2140.011982.870.001992.63
4262023.04.24 11:00buy2150.011983.000.001993.02
4272023.04.24 11:54t/p2130.011983.980.001983.984.301237.91
4282023.04.24 17:45buy2160.011986.500.002010.66
4292023.04.25 01:05t/p2140.011992.630.001992.639.761247.67
4302023.04.25 01:08t/p2150.011993.020.001993.0210.021257.69
4312023.04.25 08:15buy2170.011994.120.002000.20
4322023.04.25 08:49buy2180.011994.410.001998.25
4332023.04.25 12:15close2160.011989.730.002010.663.231260.92
4342023.04.25 12:15buy2190.011990.230.001995.91
4352023.04.25 20:26t/p2190.011995.910.001995.915.681266.60
4362023.04.25 20:53t/p2180.011998.250.001998.253.841270.44
4372023.04.25 21:03t/p2170.012000.200.002000.206.081276.52
4382023.04.25 23:00buy2200.011999.540.002009.26
4392023.04.26 01:15buy2210.011997.970.002001.67
4402023.04.26 03:10t/p2210.012001.670.002001.673.701280.22
4412023.04.26 05:00buy2220.011999.190.002005.57
4422023.04.26 05:30buy2230.011998.620.002003.86
4432023.04.26 07:49close2120.011995.770.002004.285.351285.57
4442023.04.26 07:49buy2240.011996.270.002000.57
4452023.04.26 09:22close2240.011996.910.002000.570.641286.21
4462023.04.26 09:22buy2250.011997.410.002000.93
4472023.04.26 10:30close2250.011998.040.002000.930.631286.84
4482023.04.26 10:30buy2260.011998.540.002006.24
4492023.04.26 13:00close2260.011998.660.002006.240.121286.96
4502023.04.26 13:00close2230.011998.660.002003.860.041287.00
4512023.04.26 13:00buy2270.011999.160.002004.66
4522023.04.26 16:00buy2280.011998.260.002011.28
4532023.04.26 16:22t/p2270.012004.660.002004.665.501292.50
4542023.04.26 16:24t/p2220.012005.570.002005.576.381298.88
4552023.04.26 21:56buy2290.011991.040.001996.34
4562023.04.27 05:16t/p2290.011996.340.001996.345.301304.18
4572023.04.27 17:07buy2300.011985.500.002001.28
4582023.04.27 20:00buy2310.011984.770.001991.37
4592023.04.28 17:38t/p2310.011991.370.001991.376.601310.78
4602023.05.01 07:13buy2320.011984.280.001989.62
4612023.05.01 14:42t/p2320.011989.620.001989.625.341316.12
4622023.05.01 15:32close2200.012000.050.002009.260.511316.63
4632023.05.01 15:35t/p2300.012001.280.002001.2815.781332.41
4642023.05.01 23:30buy2330.011981.190.001984.01
4652023.05.02 02:30buy2340.011983.000.001986.00
4662023.05.02 03:15buy2350.011983.330.001987.81
4672023.05.02 03:45close2340.011983.040.001986.000.041332.45
4682023.05.02 03:45close2330.011983.040.001984.011.851334.30
4692023.05.02 03:45buy2360.011983.540.001988.44
4702023.05.02 04:15buy2370.011983.510.001988.35
4712023.05.02 10:00close2370.011984.430.001988.350.921335.22
4722023.05.02 10:00close2360.011984.430.001988.440.891336.11
4732023.05.02 10:00close2350.011984.430.001987.811.101337.21
4742023.05.02 10:00buy2380.011984.930.001989.69
4752023.05.02 11:45buy2390.011981.760.001987.72
4762023.05.02 12:15buy2400.011983.150.001991.89
4772023.05.02 12:45close2400.011984.610.001991.891.461338.67
4782023.05.02 12:45close2390.011984.610.001987.722.851341.52
4792023.05.02 12:45buy2410.011985.110.001997.77
4802023.05.02 14:06t/p2380.011989.690.001989.694.761346.28
4812023.05.02 17:13t/p2410.011997.770.001997.7712.661358.94
4822023.05.02 17:14close2280.011998.790.002011.280.531359.47
4832023.05.02 21:30buy2420.012015.390.002023.23
4842023.05.02 22:00buy2430.012014.620.002020.92
4852023.05.02 23:30buy2440.012016.680.002020.60
4862023.05.03 01:30buy2450.012016.300.002017.22
4872023.05.03 03:00close2430.012015.710.002020.921.091360.56
4882023.05.03 03:00close2420.012015.710.002023.230.321360.88
4892023.05.03 03:00buy2460.012016.210.002016.93
4902023.05.03 03:30buy2470.012016.420.002020.30
4912023.05.03 04:15t/p2460.012016.930.002016.930.721361.60
4922023.05.03 04:16t/p2450.012017.220.002017.220.921362.52
4932023.05.03 05:00buy2480.012017.100.002019.44
4942023.05.03 06:15buy2490.012018.180.002020.84
4952023.05.03 07:00close2490.012018.300.002020.840.121362.64
4962023.05.03 07:00close2480.012018.300.002019.441.201363.84
4972023.05.03 07:00close2470.012018.300.002020.301.881365.72
4982023.05.03 07:00close2440.012018.300.002020.601.621367.34
4992023.05.03 07:00buy2500.012018.800.002021.78
5002023.05.03 07:48buy2510.012017.570.002018.01
5012023.05.03 09:30buy2520.012016.540.002020.22
5022023.05.03 09:50t/p2510.012018.010.002018.010.441367.78
5032023.05.03 10:00buy2530.012018.330.002025.59
5042023.05.03 11:30buy2540.012016.320.002023.16
5052023.05.03 13:36close2540.012016.340.002023.160.021367.80
5062023.05.03 13:36buy2550.012016.840.002018.54
5072023.05.03 16:29t/p2550.012018.540.002018.541.701369.50
5082023.05.03 17:45buy2560.012019.060.002032.86
5092023.05.03 17:52t/p2520.012020.220.002020.223.681373.18
5102023.05.03 18:02t/p2500.012021.780.002021.782.981376.16
5112023.05.03 18:22t/p2530.012025.590.002025.597.261383.42
5122023.05.03 21:02t/p2560.012032.860.002032.8613.801397.22
5132023.05.03 21:15buy2570.012025.830.002038.07
5142023.05.03 22:30buy2580.012025.950.002043.35
5152023.05.03 23:50t/p2570.012038.070.002038.0712.241409.46
5162023.05.04 01:05t/p2580.012043.350.002043.3517.401426.86
5172023.05.04 16:45buy2590.012041.070.002058.53
5182023.05.04 17:44t/p2590.012058.530.002058.5317.461444.32
5192023.05.04 18:36buy2600.012050.470.002060.89
5202023.05.04 19:15buy2610.012054.070.002074.83
5212023.05.04 19:45buy2620.012051.680.002067.66
5222023.05.04 20:45buy2630.012048.670.002056.47
5232023.05.04 22:15close2630.012049.070.002056.470.401444.72
5242023.05.04 22:15buy2640.012049.570.002057.37
5252023.05.04 23:15close2640.012050.140.002057.370.571445.29
5262023.05.04 23:15buy2650.012050.640.002056.98
5272023.05.11 23:30close2600.012013.690.002060.89-36.781408.51
5282023.05.12 01:15close2610.012015.960.002074.83-38.111370.40
5292023.05.12 01:45close2620.012015.350.002067.66-36.331334.07
5302023.05.12 05:15close2650.012011.920.002056.98-38.721295.35
5312023.05.12 10:15buy2660.012010.210.002018.67
5322023.05.12 13:45buy2670.012006.810.002018.07
5332023.05.12 16:05t/p2670.012018.070.002018.0711.261306.61
5342023.05.12 16:06t/p2660.012018.670.002018.678.461315.07
5352023.05.12 19:15buy2680.012010.470.002014.07
5362023.05.12 20:01t/p2680.012014.070.002014.073.601318.67
5372023.05.15 15:30buy2690.012015.350.002021.61
5382023.05.15 16:58t/p2690.012021.610.002021.616.261324.93
5392023.05.15 18:45buy2700.012018.550.002028.39
5402023.05.16 10:52buy2710.012009.630.002019.29
5412023.05.16 13:15buy2720.012010.410.002012.89
5422023.05.16 15:30buy2730.012007.380.002014.36
5432023.05.16 15:43t/p2720.012012.890.002012.892.481327.41
5442023.05.16 15:45t/p2730.012014.360.002014.366.981334.39
5452023.05.17 01:30buy2740.011989.890.001993.11
5462023.05.17 03:00buy2750.011990.150.001991.79
5472023.05.17 03:20t/p2750.011991.790.001991.791.641336.03
5482023.05.17 05:00buy2760.011992.950.001998.57
5492023.05.17 06:00close2740.011992.550.001993.112.661338.69
5502023.05.17 06:00buy2770.011993.050.001997.67
5512023.05.22 23:45close2700.011971.650.002028.39-46.901291.79
5522023.05.23 15:45close2710.011959.200.002019.29-50.431241.36
5532023.05.23 18:45buy2780.011967.250.001972.51
5542023.05.23 19:15buy2790.011968.770.001977.05
5552023.05.23 19:38t/p2780.011972.510.001972.515.261246.62
5562023.05.23 21:26t/p2790.011977.050.001977.058.281254.90
5572023.05.24 10:00close2760.011971.540.001998.57-21.411233.49
5582023.05.24 10:45buy2800.011976.440.001987.36
5592023.05.24 11:00close2770.011973.800.001997.67-19.251214.24
5602023.05.25 01:15buy2810.011959.230.001962.01
5612023.05.25 01:46buy2820.011959.860.001963.14
5622023.05.25 04:00buy2830.011959.650.001963.07
5632023.05.25 11:23t/p2810.011962.010.001962.012.781217.02
5642023.05.25 11:25t/p2830.011963.070.001963.073.421220.44
5652023.05.25 11:25t/p2820.011963.140.001963.143.281223.72
5662023.05.25 17:05buy2840.011949.160.001963.92
5672023.05.26 01:05buy2850.011941.660.001946.72
5682023.05.26 04:00buy2860.011941.280.001949.74
5692023.05.26 04:58t/p2850.011946.720.001946.725.061228.78
5702023.05.26 08:35t/p2860.011949.740.001949.748.461237.24
5712023.05.26 16:45buy2870.011950.430.001962.17
5722023.05.26 17:15buy2880.011950.730.001962.89
5732023.05.30 17:15close2880.011955.910.001962.895.181242.42
5742023.05.30 17:15close2870.011955.910.001962.175.481247.90
5752023.05.30 17:15close2840.011955.910.001963.926.751254.65
5762023.05.30 17:15buy2890.011956.410.001966.61
5772023.05.31 06:00buy2900.011956.510.001961.59
5782023.05.31 08:30buy2910.011959.570.001962.43
5792023.05.31 08:43t/p2900.011961.590.001961.595.081259.73
5802023.05.31 08:50t/p2910.011962.430.001962.432.861262.59
5812023.05.31 11:15buy2920.011958.320.001963.14
5822023.05.31 12:21buy2930.011958.020.001960.36
5832023.05.31 13:00close2930.011958.480.001960.360.461263.05
5842023.05.31 13:00close2920.011958.480.001963.140.161263.21
5852023.05.31 13:00close2890.011958.480.001966.612.071265.28
5862023.05.31 13:00buy2940.011958.980.001966.46
5872023.05.31 14:15buy2950.011958.590.001964.21
5882023.05.31 16:13t/p2950.011964.210.001964.215.621270.90
5892023.05.31 16:42t/p2940.011966.460.001966.467.481278.38
5902023.05.31 17:30buy2960.011966.450.001977.69
5912023.05.31 18:15close2800.011971.120.001987.36-5.321273.06
5922023.05.31 20:45buy2970.011968.340.001978.22
5932023.05.31 21:15buy2980.011967.370.001975.31
5942023.06.01 01:10buy2990.011963.980.001965.92
5952023.06.01 01:46t/p2990.011965.920.001965.921.941275.00
5962023.06.01 03:15buy3000.011966.760.001968.70
5972023.06.01 16:00t/p3000.011968.700.001968.701.941276.94
5982023.06.01 16:30buy3010.011968.550.001987.73
5992023.06.01 17:00t/p2980.011975.310.001975.317.941284.88
6002023.06.01 18:07t/p2960.011977.690.001977.6911.241296.12
6012023.06.01 18:07t/p2970.011978.220.001978.229.881306.00
6022023.06.01 21:00buy3020.011978.390.001982.23
6032023.06.01 21:45buy3030.011977.680.001980.10
6042023.06.01 22:17buy3040.011977.500.001980.26
6052023.06.02 02:49close3010.011976.650.001987.738.101314.10
6062023.06.02 02:49buy3050.011977.150.001978.69
6072023.06.02 05:07t/p3050.011978.690.001978.691.541315.64
6082023.06.02 05:50t/p3030.011980.100.001980.102.421318.06
6092023.06.02 05:51t/p3040.011980.260.001980.262.761320.82
6102023.06.02 06:19t/p3020.011982.230.001982.233.841324.66
6112023.06.05 01:25buy3060.011950.340.001955.26
6122023.06.05 04:45buy3070.011947.480.001949.50
6132023.06.05 06:45buy3080.011947.430.001953.67
6142023.06.05 08:44buy3090.011946.000.001948.80
6152023.06.05 17:00t/p3090.011948.800.001948.802.801327.46
6162023.06.05 17:00t/p3070.011949.500.001949.502.021329.48
6172023.06.05 17:00t/p3080.011953.670.001953.676.241335.72
6182023.06.05 17:01t/p3060.011955.260.001955.264.921340.64
6192023.06.06 17:19buy3100.011961.380.001971.82
6202023.06.06 18:00buy3110.011960.390.001971.81
6212023.06.06 18:31buy3120.011961.070.001968.45
6222023.06.07 11:15buy3130.011959.370.001967.71
6232023.06.07 16:45close3130.011961.830.001967.712.461343.10
6242023.06.07 16:45close3120.011961.830.001968.450.761343.86
6252023.06.07 16:45close3110.011961.830.001971.811.441345.30
6262023.06.07 16:45close3100.011961.830.001971.820.451345.75
6272023.06.07 16:45buy3140.011962.330.001972.03
6282023.06.08 21:46buy3150.011964.760.001969.40
6292023.06.09 01:45buy3160.011966.260.001968.02
6302023.06.09 02:45buy3170.011966.170.001967.65
6312023.06.09 04:15close3140.011964.510.001972.032.181347.93
6322023.06.09 04:15buy3180.011965.010.001967.73
6332023.06.09 09:30close3150.011964.800.001969.400.041347.97
6342023.06.09 09:30buy3190.011965.300.001970.00
6352023.06.09 15:30t/p3170.011967.650.001967.651.481349.45
6362023.06.09 15:30t/p3180.011967.730.001967.732.721352.17
6372023.06.09 15:30t/p3160.011968.020.001968.021.761353.93
6382023.06.09 15:31t/p3190.011970.000.001970.004.701358.63
6392023.06.09 15:45buy3200.011965.820.001969.38
6402023.06.09 17:00buy3210.011962.410.001972.33
6412023.06.12 18:09buy3220.011955.880.001965.98
6422023.06.13 01:45buy3230.011958.430.001961.19
6432023.06.13 04:15close3230.011958.780.001961.190.351358.98
6442023.06.13 04:15close3220.011958.780.001965.982.901361.88
6452023.06.13 04:15buy3240.011959.280.001962.20
6462023.06.13 05:45buy3250.011958.670.001963.47
6472023.06.13 09:21t/p3240.011962.200.001962.202.921364.80
6482023.06.13 10:08t/p3250.011963.470.001963.474.801369.60
6492023.06.13 15:30t/p3200.011969.380.001969.383.561373.16
6502023.06.13 22:52buy3260.011943.360.001948.06
6512023.06.14 01:07buy3270.011944.400.001949.38
6522023.06.14 01:45buy3280.011945.350.001951.23
6532023.06.14 03:00close3260.011943.800.001948.060.441373.60
6542023.06.14 03:00buy3290.011944.300.001947.88
6552023.06.14 05:00close3290.011946.700.001947.882.401376.00
6562023.06.14 05:00close3280.011946.700.001951.231.351377.35
6572023.06.14 05:00close3270.011946.700.001949.382.301379.65
6582023.06.14 05:00buy3300.011947.200.001953.00
6592023.06.14 06:00buy3310.011947.830.001951.31
6602023.06.14 06:30buy3320.011948.020.001951.02
6612023.06.14 07:30close3320.011948.390.001951.020.371380.02
6622023.06.14 07:30close3310.011948.390.001951.310.561380.58
6632023.06.14 07:30close3300.011948.390.001953.001.191381.77
6642023.06.14 07:30buy3330.011948.890.001952.37
6652023.06.14 08:15buy3340.011949.350.001951.81
6662023.06.14 08:45buy3350.011947.950.001950.85
6672023.06.14 10:30close3350.011948.850.001950.850.901382.67
6682023.06.14 10:30buy3360.011949.350.001957.03
6692023.06.14 12:26t/p3340.011951.810.001951.812.461385.13
6702023.06.14 12:34t/p3330.011952.370.001952.373.481388.61
6712023.06.14 15:15buy3370.011948.480.001953.24
6722023.06.14 15:36t/p3370.011953.240.001953.244.761393.37
6732023.06.14 15:43t/p3360.011957.030.001957.037.681401.05
6742023.06.15 08:30buy3380.011935.850.001945.35
6752023.06.15 10:37buy3390.011934.230.001943.29
6762023.06.15 11:15buy3400.011934.480.001944.94
6772023.06.15 12:30close3390.011934.350.001943.290.121401.17
6782023.06.15 12:30buy3410.011934.850.001942.43
6792023.06.15 13:46close3400.011934.710.001944.940.231401.40
6802023.06.15 13:46buy3420.011935.210.001939.41
6812023.06.15 16:25t/p3420.011939.410.001939.414.201405.60
6822023.06.15 16:27t/p3410.011942.430.001942.437.581413.18
6832023.06.15 16:43t/p3380.011945.350.001945.359.501422.68
6842023.06.16 09:33close3210.011962.920.001972.330.511423.19
6852023.06.16 16:45buy3430.011962.910.001975.15
6862023.06.16 17:56buy3440.011960.330.001970.55
6872023.06.16 18:30buy3450.011960.650.001973.45
6882023.06.16 20:25buy3460.011958.100.001965.60
6892023.06.26 01:15close3430.011923.680.001975.15-39.231383.96
6902023.06.26 02:15close3440.011924.300.001970.55-36.031347.93
6912023.06.26 03:00close3450.011925.150.001973.45-35.501312.43
6922023.06.26 04:45close3460.011927.640.001965.60-30.461281.97
6932023.06.26 18:17buy3470.011926.410.001935.09
6942023.06.27 03:30buy3480.011923.740.001928.92
6952023.06.27 04:00buy3490.011922.960.001926.58
6962023.06.27 04:42t/p3490.011926.580.001926.583.621285.59
6972023.06.27 04:49t/p3480.011928.920.001928.925.181290.77
6982023.06.27 10:00buy3500.011927.720.001934.24
6992023.06.27 15:01buy3510.011924.180.001931.16
7002023.06.28 01:15buy3520.011915.060.001918.66
7012023.06.28 04:00close3520.011915.950.001918.660.891291.66
7022023.06.28 04:00buy3530.011916.450.001918.91
7032023.06.28 23:54close at stop3530.011906.650.001918.91-9.801281.86
7042023.06.28 23:54close at stop3510.011906.650.001931.16-17.531264.33
7052023.06.28 23:54close at stop3500.011906.650.001934.24-21.071243.26
7062023.06.28 23:54close at stop3470.011906.650.001935.09-19.761223.50
+
diff --git a/Bkp/Used/14020502/Docs/Reports/14020412/OSC XMA 15Min Long/Only XMA/StrategyTester_1.gif b/Bkp/Used/14020502/Docs/Reports/14020412/OSC XMA 15Min Long/Only XMA/StrategyTester_1.gif new file mode 100644 index 0000000..005d140 Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/14020412/OSC XMA 15Min Long/Only XMA/StrategyTester_1.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/14020412/OSC XMA 15Min Long/Only XMA/StrategyTester_1.htm b/Bkp/Used/14020502/Docs/Reports/14020412/OSC XMA 15Min Long/Only XMA/StrategyTester_1.htm new file mode 100644 index 0000000..78dc9e1 --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/14020412/OSC XMA 15Min Long/Only XMA/StrategyTester_1.htm @@ -0,0 +1,222 @@ + + + + Strategy Tester: x-saherelm.osc.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.osc.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2023.01.03 01:00 - 2023.06.28 23:45 (2023.01.01 - 2023.06.29)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_OSC"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=480; fastOSCLength=10; fastOSCMultiplier=1; slowOSCLength=30; slowOSCMultiplier=3; minPowerOSC=0.055; minVarianceOSC=0; zDeviation=5; zBackStep=3; shortCycleFastMultiplier=1; shortCycleSlowMultiplier=4; mediumCycleFastMultiplier=7; mediumCycleSlowMultiplier=14; longCycleFastMultiplier=70; longCycleSlowMultiplier=140; showShortCycle=false; +showShortCycleCrossLines=false; +showMediumCycle=false; +showMediumCycleCrossLines=false; +showLongCycle=false; +showLongCycleCrossLines=false; +shortCycleFastColor=Green; shortCycleSlowColor=Red; mediumCycleFastColor=Aqua; mediumCycleSlowColor=Magenta; longCycleFastColor=Goldenrod; longCycleSlowColor=Brown;
Bars in test12551Ticks modelled15360882Modelling qualityn/a
Mismatched charts errors1395
Initial deposit1000.00SpreadCurrent (57)
Total net profit58.78Gross profit582.17Gross loss-523.39
Profit factor1.11Expected payoff0.78
Absolute drawdown10.15Maximal drawdown322.36 (23.55%)Relative drawdown23.55% (322.36)
Total trades75Short positions (won %)0 (0.00%)Long positions (won %)75 (80.00%)
Profit trades (% of total)60 (80.00%)Loss trades (% of total)15 (20.00%)
Largestprofit trade32.50loss trade-83.16
Averageprofit trade9.70loss trade-34.89
Maximumconsecutive wins (profit in money)23 (247.24)consecutive losses (loss in money)5 (-152.61)
Maximalconsecutive profit (count of wins)247.24 (23)consecutive loss (count of losses)-224.33 (4)
Averageconsecutive wins12consecutive losses3
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12023.01.06 10:45buy10.011838.920.001843.76
22023.01.06 13:30buy20.011840.110.001852.61
32023.01.06 15:41t/p10.011843.760.001843.764.841004.84
42023.01.06 17:02t/p20.011852.610.001852.6112.501017.34
52023.01.10 10:45buy30.011874.470.001882.55
62023.01.11 07:36t/p30.011882.550.001882.558.081025.42
72023.01.12 04:00buy40.011880.930.001888.89
82023.01.12 14:23t/p40.011888.890.001888.897.961033.38
92023.01.17 16:30buy50.011915.960.001934.12
102023.01.17 17:00buy60.011913.860.001920.64
112023.01.18 10:30buy70.011912.320.001931.62
122023.01.18 10:45buy80.011912.000.001927.60
132023.01.18 15:30t/p60.011920.640.001920.646.781040.16
142023.01.19 06:45buy90.011909.950.001916.75
152023.01.19 16:21t/p90.011916.750.001916.756.801046.96
162023.01.19 21:26t/p80.011927.600.001927.6015.601062.56
172023.01.19 22:07t/p70.011931.620.001931.6219.301081.86
182023.01.19 22:13t/p50.011934.120.001934.1218.161100.02
192023.01.23 02:45buy100.011930.950.001942.63
202023.01.23 21:30buy110.011928.100.001937.10
212023.01.24 08:31t/p110.011937.100.001937.109.001109.02
222023.01.25 18:57buy120.011937.690.001955.77
232023.01.25 21:57t/p100.011942.630.001942.6311.681120.70
242023.01.27 14:15buy130.011932.410.001941.85
252023.01.27 18:45buy140.011931.740.001962.44
262023.01.31 17:15buy150.011922.500.001941.44
272023.02.01 21:43close120.011938.200.001955.770.511121.21
282023.02.01 21:52t/p150.011941.440.001941.4418.941140.15
292023.02.01 21:52t/p130.011941.850.001941.859.441149.59
302023.02.02 06:45close140.011953.230.001962.4421.491171.08
312023.02.07 04:45buy160.011874.080.001882.44
322023.02.07 19:48t/p160.011882.440.001882.448.361179.44
332023.02.08 02:07buy170.011874.940.001882.96
342023.02.08 09:56t/p170.011882.960.001882.968.021187.46
352023.02.09 05:00buy180.011879.500.001891.10
362023.02.10 16:30buy190.011867.550.001879.53
372023.02.10 16:46buy200.011865.500.001873.38
382023.02.10 17:18buy210.011866.930.001883.07
392023.02.16 10:00close180.011841.080.001891.10-38.421149.04
402023.02.17 21:30close190.011842.050.001879.53-25.501123.54
412023.02.17 21:45close200.011841.760.001873.38-23.741099.80
422023.02.17 22:15close210.011842.420.001883.07-24.511075.29
432023.02.22 04:18buy220.011836.810.001840.77
442023.02.22 10:05t/p220.011840.770.001840.773.961079.25
452023.02.24 04:30buy230.011826.890.001832.79
462023.02.24 05:15buy240.011827.540.001834.30
472023.02.24 08:15buy250.011825.790.001829.71
482023.02.24 08:30buy260.011825.830.001829.83
492023.02.28 19:25t/p250.011829.710.001829.713.921083.17
502023.02.28 19:25t/p260.011829.830.001829.834.001087.17
512023.03.01 08:15t/p230.011832.790.001832.795.901093.07
522023.03.01 08:32t/p240.011834.300.001834.306.761099.83
532023.03.02 17:33buy270.011839.300.001854.26
542023.03.02 17:45buy280.011836.180.001842.78
552023.03.02 20:52buy290.011835.880.001843.44
562023.03.03 08:42t/p280.011842.780.001842.786.601106.43
572023.03.03 08:48t/p290.011843.440.001843.447.561113.99
582023.03.03 22:04t/p270.011854.260.001854.2614.961128.95
592023.03.08 17:00buy300.011820.920.001838.76
602023.03.09 10:45buy310.011819.070.001832.05
612023.03.09 17:02t/p310.011832.050.001832.0512.981141.93
622023.03.10 15:31t/p300.011838.760.001838.7617.841159.77
632023.03.14 20:30buy320.011909.590.001918.35
642023.03.14 20:45buy330.011908.470.001914.99
652023.03.15 13:30buy340.011912.290.001944.79
662023.03.15 13:32t/p330.011914.990.001914.996.521166.29
672023.03.15 13:33t/p320.011918.350.001918.358.761175.05
682023.03.17 14:33t/p340.011944.790.001944.7932.501207.55
692023.03.21 04:55buy350.011984.480.001995.38
702023.03.22 16:45buy360.011945.310.001959.07
712023.03.22 20:02t/p360.011959.070.001959.0713.761221.31
722023.03.23 19:34t/p350.011995.380.001995.3810.901232.21
732023.03.28 08:45buy370.011960.000.001967.16
742023.03.28 15:38t/p370.011967.160.001967.167.161239.37
752023.03.30 09:30buy380.011967.110.001981.19
762023.03.30 19:33t/p380.011981.190.001981.1914.081253.45
772023.04.03 14:00buy390.011972.870.001992.83
782023.04.04 15:15buy400.011984.560.001997.18
792023.04.04 16:46t/p390.011992.830.001992.8319.961273.41
802023.04.04 17:00t/p400.011997.180.001997.1812.621286.03
812023.04.06 14:15buy410.012020.250.002025.97
822023.04.11 05:30buy420.011996.090.002011.05
832023.04.12 04:37t/p420.012011.050.002011.0514.961300.99
842023.04.12 15:35t/p410.012025.970.002025.975.721306.71
852023.04.17 15:00buy430.012009.490.002019.07
862023.04.18 10:29buy440.012002.540.002011.86
872023.04.19 22:00buy450.011996.680.002003.18
882023.04.20 13:29t/p450.012003.180.002003.186.501313.21
892023.04.20 17:08t/p440.012011.860.002011.869.321322.53
902023.04.24 12:15buy460.011985.670.001995.83
912023.04.24 20:00close430.011986.450.002019.07-23.041299.49
922023.04.25 02:42t/p460.011995.830.001995.8310.161309.65
932023.04.25 20:30buy470.011994.280.002006.76
942023.04.26 16:26t/p470.012006.760.002006.7612.481322.13
952023.04.27 06:00buy480.011999.130.002015.61
962023.04.28 17:45buy490.011988.940.002003.12
972023.05.01 14:15buy500.011987.350.001996.19
982023.05.01 15:24t/p500.011996.190.001996.198.841330.97
992023.05.01 15:36t/p490.012003.120.002003.1214.181345.15
1002023.05.02 13:45buy510.011988.110.002003.63
1012023.05.02 17:15close480.011999.650.002015.610.521345.67
1022023.05.02 17:28t/p510.012003.630.002003.6315.521361.19
1032023.05.08 11:45buy520.012022.380.002027.64
1042023.05.08 18:29t/p520.012027.640.002027.645.261366.45
1052023.05.10 15:45buy530.012046.500.002090.02
1062023.05.11 03:15buy540.012032.950.002038.13
1072023.05.11 14:32buy550.012038.380.002062.76
1082023.05.11 14:33t/p540.012038.130.002038.135.181371.63
1092023.05.12 16:47buy560.012020.820.002054.00
1102023.05.12 20:02buy570.012014.980.002028.60
1112023.05.17 20:45close530.011981.850.002090.02-64.651306.98
1122023.05.18 19:30close550.011955.220.002062.76-83.161223.82
1132023.05.19 21:45close560.011979.300.002054.00-41.521182.30
1142023.05.22 02:00close570.011979.980.002028.60-35.001147.30
1152023.05.23 17:30buy580.011969.700.001991.80
1162023.05.23 17:45buy590.011967.930.001978.41
1172023.05.24 07:30t/p590.011978.410.001978.4110.481157.78
1182023.05.26 09:45buy600.011951.870.001962.05
1192023.05.29 15:00buy610.011946.780.001952.32
1202023.05.29 15:15buy620.011945.930.001949.77
1212023.05.30 12:55t/p620.011949.770.001949.773.841161.62
1222023.05.30 12:59t/p610.011952.320.001952.325.541167.16
1232023.05.30 15:20t/p600.011962.050.001962.0510.181177.34
1242023.05.31 02:00close580.011958.460.001991.80-11.241166.10
1252023.06.01 14:30buy630.011967.510.001983.01
1262023.06.02 06:21t/p630.011983.010.001983.0115.501181.60
1272023.06.05 17:30buy640.011959.060.001992.22
1282023.06.07 17:00buy650.011970.110.001996.37
1292023.06.07 17:15buy660.011964.900.001980.74
1302023.06.08 15:38buy670.011957.110.001981.87
1312023.06.09 05:30close640.011963.620.001992.224.561186.16
1322023.06.12 11:30buy680.011964.510.001976.49
1332023.06.13 13:55close660.011965.420.001980.740.521186.68
1342023.06.13 15:30close650.011970.760.001996.370.651187.33
1352023.06.14 12:31buy690.011952.480.001961.02
1362023.06.14 15:36buy700.011952.840.001967.32
1372023.06.14 15:44close670.011957.620.001981.870.511187.84
1382023.06.15 17:15buy710.011956.020.002008.72
1392023.06.16 04:46t/p690.011961.020.001961.028.541196.38
1402023.06.16 13:53close680.011965.040.001976.490.531196.91
1412023.06.16 15:15t/p700.011967.320.001967.3214.481211.39
1422023.06.20 10:45buy720.011955.420.001968.94
1432023.06.21 21:45buy730.011937.390.001945.49
1442023.06.21 22:00buy740.011936.290.001941.61
1452023.06.23 01:45close710.011913.380.002008.72-42.641168.75
1462023.06.27 05:45buy750.011928.250.001937.95
1472023.06.27 15:45close720.011927.430.001968.94-27.991140.76
1482023.06.28 23:54close at stop750.011906.650.001937.95-21.601119.16
1492023.06.28 23:54close at stop740.011906.650.001941.61-29.641089.52
1502023.06.28 23:54close at stop730.011906.650.001945.49-30.741058.78
+
diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 1.gif b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 1.gif new file mode 100644 index 0000000..1f3c0ce Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 1.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 1.htm b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 1.htm new file mode 100644 index 0000000..3057841 --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 1.htm @@ -0,0 +1,77 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.01.29 23:45 (2020.01.01 - 2021.02.01)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=408; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +step=0.01; maximum=0.1; shortCycleMultiplier=2; mediumCycleMultiplier=6; longCycleMultiplier=36;
Bars in test4192Ticks modelled3544155Modelling quality24.42%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (51)
Total net profit54.27Gross profit54.27Gross loss-0.00
Profit factorExpected payoff10.85
Absolute drawdown29.71Maximal drawdown53.15 (5.19%)Relative drawdown5.19% (53.15)
Total trades5Short positions (won %)0 (0.00%)Long positions (won %)5 (100.00%)
Profit trades (% of total)5 (100.00%)Loss trades (% of total)0 (0.00%)
Largestprofit trade20.17loss trade-0.00
Averageprofit trade10.85loss trade-0.00
Maximumconsecutive wins (profit in money)5 (54.27)consecutive losses (loss in money)0 (-0.00)
Maximalconsecutive profit (count of wins)54.27 (5)consecutive loss (count of losses)-0.00 (0)
Averageconsecutive wins5consecutive losses0
+Graph
+ + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.02 08:30buy10.011814.560.001828.18
22020.12.02 12:22t/p10.011828.180.001828.1813.621013.62
32020.12.04 14:15buy20.011842.710.001850.47
42020.12.04 16:15buy30.011843.510.001864.07
52020.12.07 16:49t/p20.011850.470.001850.477.371020.99
62020.12.07 17:46t/p30.011864.070.001864.0720.171041.17
72020.12.18 01:00buy40.011884.910.001888.23
82020.12.18 14:09t/p40.011888.230.001888.233.321044.49
92021.01.05 05:45buy50.011942.150.001951.93
102021.01.05 16:16t/p50.011951.930.001951.939.781054.27
+
diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 2.gif b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 2.gif new file mode 100644 index 0000000..e902f9a Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 2.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 2.htm b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 2.htm new file mode 100644 index 0000000..5f7287e --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 2.htm @@ -0,0 +1,81 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.02.26 23:45 (2020.01.01 - 2021.03.01)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=408; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +step=0.01; maximum=0.1; shortCycleMultiplier=2; mediumCycleMultiplier=6; longCycleMultiplier=36;
Bars in test6016Ticks modelled6166924Modelling quality24.60%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (50)
Total net profit35.23Gross profit66.77Gross loss-31.54
Profit factor2.12Expected payoff5.03
Absolute drawdown29.69Maximal drawdown53.15 (5.19%)Relative drawdown5.19% (53.15)
Total trades7Short positions (won %)0 (0.00%)Long positions (won %)7 (85.71%)
Profit trades (% of total)6 (85.71%)Loss trades (% of total)1 (14.29%)
Largestprofit trade20.17loss trade-31.54
Averageprofit trade11.13loss trade-31.54
Maximumconsecutive wins (profit in money)6 (66.77)consecutive losses (loss in money)1 (-31.54)
Maximalconsecutive profit (count of wins)66.77 (6)consecutive loss (count of losses)-31.54 (1)
Averageconsecutive wins6consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.02 08:30buy10.011814.550.001828.17
22020.12.02 12:22t/p10.011828.170.001828.1713.621013.62
32020.12.04 14:15buy20.011842.700.001850.46
42020.12.04 16:15buy30.011843.500.001864.06
52020.12.07 16:49t/p20.011850.460.001850.467.371020.99
62020.12.07 17:46t/p30.011864.060.001864.0620.171041.17
72020.12.18 01:00buy40.011884.900.001888.22
82020.12.18 14:09t/p40.011888.220.001888.223.321044.49
92021.01.05 05:45buy50.011942.140.001951.92
102021.01.05 16:16t/p50.011951.920.001951.929.781054.27
112021.02.09 03:15buy60.011835.680.001848.18
122021.02.09 11:54t/p60.011848.180.001848.1812.501066.77
132021.02.10 15:15buy70.011844.620.001857.72
142021.02.12 10:19close70.011814.620.001857.72-31.541035.23
+
diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 3.gif b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 3.gif new file mode 100644 index 0000000..7728f57 Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 3.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 3.htm b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 3.htm new file mode 100644 index 0000000..0ebb51f --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 3.htm @@ -0,0 +1,81 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.02.26 23:45 (2020.01.01 - 2021.03.01)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=408; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +step=0.01; maximum=0.1; shortCycleMultiplier=2; mediumCycleMultiplier=6; longCycleMultiplier=36;
Bars in test6016Ticks modelled6166924Modelling quality24.60%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (51)
Total net profit56.23Gross profit56.23Gross loss-0.00
Profit factorExpected payoff8.03
Absolute drawdown36.52Maximal drawdown53.15 (5.23%)Relative drawdown5.23% (53.15)
Total trades7Short positions (won %)0 (0.00%)Long positions (won %)7 (100.00%)
Profit trades (% of total)7 (100.00%)Loss trades (% of total)0 (0.00%)
Largestprofit trade12.50loss trade-0.00
Averageprofit trade8.03loss trade-0.00
Maximumconsecutive wins (profit in money)7 (56.23)consecutive losses (loss in money)0 (-0.00)
Maximalconsecutive profit (count of wins)56.23 (7)consecutive loss (count of losses)-0.00 (0)
Averageconsecutive wins7consecutive losses0
+Graph
+ + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.02 08:30buy10.011814.560.001821.37
22020.12.02 10:36t/p10.011821.370.001821.376.811006.81
32020.12.04 14:15buy20.011842.710.001850.47
42020.12.04 16:15buy30.011843.510.001853.79
52020.12.07 16:49t/p20.011850.470.001850.477.371014.18
62020.12.07 16:52t/p30.011853.790.001853.799.891024.08
72020.12.18 01:00buy40.011884.910.001888.23
82020.12.18 14:09t/p40.011888.230.001888.233.321027.40
92021.01.05 05:45buy50.011942.150.001951.93
102021.01.05 16:16t/p50.011951.930.001951.939.781037.18
112021.02.09 03:15buy60.011835.690.001848.19
122021.02.09 11:54t/p60.011848.190.001848.1912.501049.68
132021.02.10 15:15buy70.011844.630.001851.18
142021.02.10 15:37t/p70.011851.180.001851.186.551056.23
+
diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 4.gif b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 4.gif new file mode 100644 index 0000000..190c6f7 Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 4.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 4.htm b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 4.htm new file mode 100644 index 0000000..3f65e6f --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 4.htm @@ -0,0 +1,87 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.03.31 23:45 (2020.01.01 - 2021.04.01)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=408; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +step=0.01; maximum=0.1; shortCycleMultiplier=2; mediumCycleMultiplier=6; longCycleMultiplier=36;
Bars in test8132Ticks modelled9612073Modelling quality24.70%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (50)
Total net profit80.25Gross profit80.25Gross loss-0.00
Profit factorExpected payoff8.03
Absolute drawdown36.50Maximal drawdown53.15 (5.23%)Relative drawdown5.23% (53.15)
Total trades10Short positions (won %)0 (0.00%)Long positions (won %)10 (100.00%)
Profit trades (% of total)10 (100.00%)Loss trades (% of total)0 (0.00%)
Largestprofit trade12.50loss trade-0.00
Averageprofit trade8.03loss trade-0.00
Maximumconsecutive wins (profit in money)10 (80.25)consecutive losses (loss in money)0 (-0.00)
Maximalconsecutive profit (count of wins)80.25 (10)consecutive loss (count of losses)-0.00 (0)
Averageconsecutive wins10consecutive losses0
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.02 08:30buy10.011814.550.001821.36
22020.12.02 10:36t/p10.011821.360.001821.366.811006.81
32020.12.04 14:15buy20.011842.700.001850.46
42020.12.04 16:15buy30.011843.500.001853.78
52020.12.07 16:49t/p20.011850.460.001850.467.371014.18
62020.12.07 16:52t/p30.011853.780.001853.789.891024.08
72020.12.18 01:00buy40.011884.900.001888.22
82020.12.18 14:09t/p40.011888.220.001888.223.321027.40
92021.01.05 05:45buy50.011942.140.001951.92
102021.01.05 16:16t/p50.011951.920.001951.929.781037.18
112021.02.09 03:15buy60.011835.680.001848.18
122021.02.09 11:54t/p60.011848.180.001848.1812.501049.68
132021.02.10 15:15buy70.011844.620.001851.17
142021.02.10 15:37t/p70.011851.170.001851.176.551056.23
152021.03.10 03:15buy80.011718.560.001729.52
162021.03.10 15:15buy90.011714.680.001724.00
172021.03.10 20:33t/p90.011724.000.001724.009.321065.55
182021.03.11 04:07t/p80.011729.520.001729.529.801075.35
192021.03.16 12:30buy100.011733.030.001737.93
202021.03.16 16:22t/p100.011737.930.001737.934.901080.25
+
diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 5.gif b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 5.gif new file mode 100644 index 0000000..a43105a Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 5.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 5.htm b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 5.htm new file mode 100644 index 0000000..9ed9171 --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 5.htm @@ -0,0 +1,99 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.04.30 23:45 (2020.01.01 - 2021.05.01)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=408; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +step=0.01; maximum=0.1; shortCycleMultiplier=2; mediumCycleMultiplier=6; longCycleMultiplier=36;
Bars in test10063Ticks modelled11947707Modelling quality24.76%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (51)
Total net profit76.08Gross profit106.85Gross loss-30.77
Profit factor3.47Expected payoff4.76
Absolute drawdown36.52Maximal drawdown59.05 (5.44%)Relative drawdown5.44% (59.05)
Total trades16Short positions (won %)0 (0.00%)Long positions (won %)16 (93.75%)
Profit trades (% of total)15 (93.75%)Loss trades (% of total)1 (6.25%)
Largestprofit trade12.50loss trade-30.77
Averageprofit trade7.12loss trade-30.77
Maximumconsecutive wins (profit in money)12 (85.99)consecutive losses (loss in money)1 (-30.77)
Maximalconsecutive profit (count of wins)85.99 (12)consecutive loss (count of losses)-30.77 (1)
Averageconsecutive wins8consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.02 08:30buy10.011814.560.001821.37
22020.12.02 10:36t/p10.011821.370.001821.376.811006.81
32020.12.04 14:15buy20.011842.710.001850.47
42020.12.04 16:15buy30.011843.510.001853.79
52020.12.07 16:49t/p20.011850.470.001850.477.371014.18
62020.12.07 16:52t/p30.011853.790.001853.799.891024.08
72020.12.18 01:00buy40.011884.910.001888.23
82020.12.18 14:09t/p40.011888.230.001888.233.321027.40
92021.01.05 05:45buy50.011942.150.001951.93
102021.01.05 16:16t/p50.011951.930.001951.939.781037.18
112021.02.09 03:15buy60.011835.690.001848.19
122021.02.09 11:54t/p60.011848.190.001848.1912.501049.68
132021.02.10 15:15buy70.011844.630.001851.18
142021.02.10 15:37t/p70.011851.180.001851.186.551056.23
152021.03.10 03:15buy80.011718.570.001729.53
162021.03.10 15:15buy90.011714.690.001724.01
172021.03.10 20:33t/p90.011724.010.001724.019.321065.55
182021.03.11 04:07t/p80.011729.530.001729.539.801075.35
192021.03.16 12:30buy100.011733.040.001737.94
202021.03.16 16:22t/p100.011737.940.001737.944.901080.25
212021.04.06 13:30buy110.011732.050.001734.85
222021.04.06 14:24t/p110.011734.850.001734.852.801083.05
232021.04.08 03:00buy120.011737.150.001740.09
242021.04.08 08:01t/p120.011740.090.001740.092.941085.99
252021.04.09 04:30buy130.011756.920.001760.31
262021.04.13 08:37close130.011726.920.001760.31-30.771055.22
272021.04.14 09:15buy140.011746.430.001751.74
282021.04.14 15:39buy150.011746.670.001755.93
292021.04.15 15:19t/p140.011751.740.001751.744.151059.38
302021.04.15 16:54t/p150.011755.930.001755.938.101067.48
312021.04.21 14:15buy160.011782.360.001790.96
322021.04.21 16:49t/p160.011790.960.001790.968.601076.08
+
diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 6.gif b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 6.gif new file mode 100644 index 0000000..c3ebb99 Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 6.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 6.htm b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 6.htm new file mode 100644 index 0000000..70fb1e0 --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/14020427/StrategyTester 6.htm @@ -0,0 +1,127 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.09.30 23:45 (2020.01.01 - 2021.10.01)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=408; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +step=0.01; maximum=0.1; shortCycleMultiplier=2; mediumCycleMultiplier=6; longCycleMultiplier=36;
Bars in test20043Ticks modelled22474457Modelling quality24.88%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (60)
Total net profit87.01Gross profit151.26Gross loss-64.25
Profit factor2.35Expected payoff2.90
Absolute drawdown36.70Maximal drawdown85.54 (7.74%)Relative drawdown7.74% (85.54)
Total trades30Short positions (won %)0 (0.00%)Long positions (won %)30 (83.33%)
Profit trades (% of total)25 (83.33%)Loss trades (% of total)5 (16.67%)
Largestprofit trade12.50loss trade-30.77
Averageprofit trade6.05loss trade-12.85
Maximumconsecutive wins (profit in money)12 (85.99)consecutive losses (loss in money)3 (-32.06)
Maximalconsecutive profit (count of wins)85.99 (12)consecutive loss (count of losses)-32.06 (3)
Averageconsecutive wins6consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.02 08:30buy10.011814.650.001821.46
22020.12.02 10:36t/p10.011821.460.001821.466.811006.81
32020.12.04 14:15buy20.011842.800.001850.56
42020.12.04 16:15buy30.011843.600.001853.88
52020.12.07 16:49t/p20.011850.560.001850.567.371014.18
62020.12.07 16:52t/p30.011853.880.001853.889.891024.08
72020.12.18 01:00buy40.011885.000.001888.32
82020.12.18 14:09t/p40.011888.320.001888.323.321027.40
92021.01.05 05:45buy50.011942.240.001952.02
102021.01.05 16:16t/p50.011952.020.001952.029.781037.18
112021.02.09 03:15buy60.011835.780.001848.28
122021.02.09 11:54t/p60.011848.280.001848.2812.501049.68
132021.02.10 15:15buy70.011844.720.001851.27
142021.02.10 15:37t/p70.011851.270.001851.276.551056.23
152021.03.10 03:15buy80.011718.660.001729.62
162021.03.10 15:15buy90.011714.780.001724.10
172021.03.10 21:06t/p90.011724.100.001724.109.321065.55
182021.03.11 04:07t/p80.011729.620.001729.629.801075.35
192021.03.16 12:30buy100.011733.130.001738.03
202021.03.16 16:24t/p100.011738.030.001738.034.901080.25
212021.04.06 13:30buy110.011732.140.001734.94
222021.04.06 14:24t/p110.011734.940.001734.942.801083.05
232021.04.08 03:00buy120.011737.240.001740.18
242021.04.08 08:03t/p120.011740.180.001740.182.941085.99
252021.04.09 04:30buy130.011757.010.001760.40
262021.04.13 08:36close130.011727.010.001760.40-30.771055.22
272021.04.14 09:15buy140.011746.520.001751.83
282021.04.14 15:39buy150.011746.760.001756.02
292021.04.15 15:19t/p140.011751.830.001751.834.151059.38
302021.04.15 16:54t/p150.011756.020.001756.028.101067.48
312021.04.21 14:15buy160.011782.450.001791.05
322021.04.21 16:49t/p160.011791.050.001791.058.601076.08
332021.05.10 23:15buy170.011837.760.001843.26
342021.05.11 11:45buy180.011837.410.001846.05
352021.05.12 16:04t/p170.011843.260.001843.264.731080.81
362021.05.14 15:16close180.011837.920.001846.05-1.421079.40
372021.05.19 06:45buy190.011869.240.001874.28
382021.05.19 16:00t/p190.011874.280.001874.285.041084.44
392021.07.02 20:45buy200.011785.590.001792.91
402021.07.05 11:06t/p200.011792.910.001792.916.931091.37
412021.07.06 01:06buy210.011791.770.001794.39
422021.07.06 04:45t/p210.011794.390.001794.392.621093.99
432021.07.12 03:30buy220.011809.370.001816.23
442021.07.13 15:39t/p220.011816.230.001816.236.471100.47
452021.07.15 08:45buy230.011828.770.001834.57
462021.07.19 15:06close230.011798.770.001834.57-30.771069.70
472021.07.30 04:30buy240.011829.950.001835.53
482021.07.30 10:15buy250.011830.190.001836.63
492021.08.04 16:09close240.011830.460.001835.53-0.651069.05
502021.08.04 16:22close250.011830.700.001836.63-0.651068.41
512021.08.12 07:30buy260.011752.610.001758.59
522021.08.13 09:24t/p260.011758.590.001758.595.591074.00
532021.08.17 08:15buy270.011787.930.001791.97
542021.08.17 08:52t/p270.011791.970.001791.974.041078.04
552021.09.15 06:45buy280.011804.030.001806.41
562021.09.15 09:15buy290.011803.620.001806.36
572021.09.15 15:24t/p290.011806.360.001806.362.741080.78
582021.09.15 15:24t/p280.011806.410.001806.412.381083.16
592021.09.22 04:45buy300.011776.600.001780.45
602021.09.22 21:07t/p300.011780.450.001780.453.851087.01
+
diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester 1.gif b/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester 1.gif new file mode 100644 index 0000000..db66459 Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester 1.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester 1.htm b/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester 1.htm new file mode 100644 index 0000000..5e808a8 --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester 1.htm @@ -0,0 +1,321 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.06.29 23:45 (2020.01.01 - 2023.06.30)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=408; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +step=0.01; maximum=0.1; shortCycleMultiplier=2; mediumCycleMultiplier=6; longCycleMultiplier=36;
Bars in test61247Ticks modelled69753529Modelling quality40.22%
Mismatched charts errors33
Initial deposit1000.00SpreadCurrent (50)
Total net profit278.17Gross profit741.15Gross loss-462.98
Profit factor1.60Expected payoff2.19
Absolute drawdown36.51Maximal drawdown158.60 (12.94%)Relative drawdown12.94% (158.60)
Total trades127Short positions (won %)0 (0.00%)Long positions (won %)127 (83.46%)
Profit trades (% of total)106 (83.46%)Loss trades (% of total)21 (16.54%)
Largestprofit trade42.29loss trade-31.57
Averageprofit trade6.99loss trade-22.05
Maximumconsecutive wins (profit in money)19 (161.16)consecutive losses (loss in money)4 (-122.74)
Maximalconsecutive profit (count of wins)161.16 (19)consecutive loss (count of losses)-122.74 (4)
Averageconsecutive wins8consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.02 08:30buy10.011814.550.001821.36
22020.12.02 10:36t/p10.011821.360.001821.366.811006.81
32020.12.04 14:15buy20.011842.700.001850.46
42020.12.04 16:15buy30.011843.500.001853.78
52020.12.07 16:49t/p20.011850.460.001850.467.371014.18
62020.12.07 16:52t/p30.011853.780.001853.789.891024.07
72020.12.18 01:00buy40.011884.900.001888.22
82020.12.18 14:09t/p40.011888.220.001888.223.321027.39
92021.01.05 05:45buy50.011942.140.001951.92
102021.01.05 16:16t/p50.011951.920.001951.929.781037.17
112021.02.09 03:15buy60.011835.680.001848.18
122021.02.09 11:54t/p60.011848.180.001848.1812.501049.67
132021.02.10 15:15buy70.011844.620.001851.17
142021.02.10 15:37t/p70.011851.170.001851.176.551056.22
152021.03.10 03:15buy80.011718.560.001729.52
162021.03.10 15:15buy90.011714.680.001724.00
172021.03.10 20:33t/p90.011724.000.001724.009.321065.54
182021.03.11 04:07t/p80.011729.520.001729.529.791075.33
192021.03.16 12:30buy100.011733.030.001737.93
202021.03.16 16:22t/p100.011737.930.001737.934.901080.23
212021.04.06 13:30buy110.011732.040.001734.84
222021.04.06 14:24t/p110.011734.840.001734.842.801083.03
232021.04.08 03:00buy120.011737.140.001740.08
242021.04.08 08:01t/p120.011740.080.001740.082.941085.97
252021.04.09 04:30buy130.011756.910.001760.30
262021.04.13 08:37close130.011726.910.001760.30-30.781055.19
272021.04.14 09:15buy140.011746.420.001751.73
282021.04.14 15:39buy150.011746.660.001755.92
292021.04.15 15:19t/p140.011751.730.001751.734.141059.33
302021.04.15 16:54t/p150.011755.920.001755.928.091067.42
312021.04.21 14:15buy160.011782.350.001790.95
322021.04.21 16:49t/p160.011790.950.001790.958.601076.02
332021.05.10 23:15buy170.011837.660.001843.16
342021.05.11 11:45buy180.011837.310.001845.95
352021.05.12 16:04t/p170.011843.160.001843.164.721080.74
362021.05.14 15:15close180.011837.820.001845.95-1.441079.30
372021.05.19 06:45buy190.011869.140.001874.18
382021.05.19 16:00t/p190.011874.180.001874.185.041084.34
392021.07.02 20:45buy200.011785.490.001792.81
402021.07.05 10:54t/p200.011792.810.001792.816.931091.27
412021.07.06 01:06buy210.011791.670.001794.29
422021.07.06 04:45t/p210.011794.290.001794.292.621093.89
432021.07.12 03:30buy220.011809.270.001816.13
442021.07.13 15:39t/p220.011816.130.001816.136.471100.36
452021.07.15 08:45buy230.011828.670.001834.47
462021.07.19 15:06close230.011798.670.001834.47-30.781069.58
472021.07.30 04:30buy240.011829.850.001835.43
482021.07.30 10:15buy250.011830.090.001836.53
492021.08.04 16:09close240.011830.360.001835.43-0.661068.92
502021.08.04 16:09close250.011830.600.001836.53-0.661068.26
512021.08.12 07:30buy260.011752.510.001758.49
522021.08.13 09:24t/p260.011758.490.001758.495.591073.85
532021.08.17 08:15buy270.011787.830.001791.87
542021.08.17 08:52t/p270.011791.870.001791.874.041077.89
552021.09.15 06:45buy280.011803.930.001806.31
562021.09.15 09:15buy290.011803.520.001806.26
572021.09.15 15:24t/p290.011806.260.001806.262.741080.63
582021.09.15 15:24t/p280.011806.310.001806.312.381083.01
592021.09.22 04:45buy300.011776.500.001780.35
602021.09.22 21:07t/p300.011780.350.001780.353.851086.86
612021.10.01 10:00buy310.011756.070.001765.61
622021.10.04 09:00buy320.011761.720.001765.52
632021.10.04 17:39t/p320.011765.520.001765.523.801090.66
642021.10.04 17:39t/p310.011765.610.001765.619.151099.81
652021.10.13 04:00buy330.011761.780.001765.06
662021.10.13 10:39t/p330.011765.060.001765.063.281103.09
672021.10.21 04:00buy340.011784.190.001789.47
682021.10.22 09:31t/p340.011789.470.001789.474.891107.98
692021.10.25 01:15buy350.011793.840.001796.90
702021.10.25 03:54t/p350.011796.900.001796.903.061111.04
712021.11.05 15:15buy360.011795.930.001806.49
722021.11.05 17:22t/p360.011806.490.001806.4910.561121.60
732021.11.08 12:15buy370.011818.030.001823.33
742021.11.08 15:24t/p370.011823.330.001823.335.301126.90
752021.11.18 09:49buy380.011867.450.001875.47
762021.11.22 12:39close380.011837.450.001875.47-30.781096.12
772021.12.07 08:00buy390.011781.310.001785.35
782021.12.07 18:24t/p390.011785.350.001785.354.041100.16
792021.12.14 03:00buy400.011788.160.001793.66
802021.12.14 08:15buy410.011788.420.001793.70
812021.12.15 21:00close410.011758.410.001793.70-30.401069.76
822021.12.15 21:00close400.011758.150.001793.66-30.401039.36
832021.12.23 15:30buy420.011808.430.001813.23
842021.12.27 17:54t/p420.011813.230.001813.234.021043.38
852021.12.28 06:45buy430.011810.840.001813.84
862021.12.28 08:36t/p430.011813.840.001813.843.001046.38
872022.01.11 15:30buy440.011808.430.001814.37
882022.01.11 18:22t/p440.011814.370.001814.375.941052.32
892022.01.12 07:34buy450.011820.520.001824.18
902022.01.12 15:39t/p450.011824.180.001824.183.661055.98
912022.01.13 05:22buy460.011825.520.001827.44
922022.01.13 07:37t/p460.011827.440.001827.441.921057.90
932022.01.26 04:00buy470.011848.220.001850.96
942022.01.26 21:54close470.011818.220.001850.96-30.001027.90
952022.02.01 18:30buy480.011806.970.001815.85
962022.02.04 06:37close480.011807.480.001815.85-1.441026.46
972022.02.09 03:45buy490.011826.740.001829.48
982022.02.09 14:30buy500.011827.470.001828.75
992022.02.09 15:02t/p500.011828.750.001828.751.281027.74
1002022.02.09 15:04t/p490.011829.480.001829.482.741030.48
1012022.02.18 15:00buy510.011894.270.001904.75
1022022.02.21 01:24t/p510.011904.750.001904.7510.091040.57
1032022.03.02 08:45buy520.011937.680.001948.62
1042022.03.04 02:39t/p520.011948.620.001948.629.381049.95
1052022.03.04 11:15buy530.011941.660.001956.40
1062022.03.04 16:37t/p530.011956.400.001956.4014.741064.69
1072022.03.07 17:45buy540.011989.420.002032.10
1082022.03.08 06:45buy550.011989.920.001999.74
1092022.03.08 08:25t/p550.011999.740.001999.749.821074.51
1102022.03.08 16:49t/p540.012032.100.002032.1042.291116.80
1112022.03.24 08:15buy560.011942.900.001947.97
1122022.03.24 13:31t/p560.011947.970.001947.975.071121.87
1132022.03.25 03:00buy570.011963.080.001972.98
1142022.03.28 08:54close570.011933.080.001972.98-30.391091.49
1152022.04.08 03:00buy580.011933.340.001938.28
1162022.04.08 15:09t/p580.011938.280.001938.284.941096.43
1172022.04.11 08:45buy590.011944.970.001949.67
1182022.04.11 11:19t/p590.011949.670.001949.674.701101.13
1192022.04.12 14:15buy600.011956.680.001966.46
1202022.04.12 15:39t/p600.011966.460.001966.469.781110.91
1212022.04.13 04:49buy610.011968.170.001977.53
1222022.04.13 12:39t/p610.011977.530.001977.539.361120.27
1232022.04.14 02:00buy620.011978.670.001982.69
1242022.04.14 05:00buy630.011980.050.001986.23
1252022.04.14 10:45buy640.011977.510.001984.20
1262022.04.18 02:37t/p620.011982.690.001982.693.241123.51
1272022.04.18 02:46t/p640.011984.200.001984.205.911129.42
1282022.04.18 02:49t/p630.011986.230.001986.235.401134.82
1292022.05.05 13:30buy650.011898.250.001907.69
1302022.05.05 15:49t/p650.011907.690.001907.699.441144.26
1312022.05.20 18:15buy660.011844.180.001855.68
1322022.05.23 08:08t/p660.011855.680.001855.6811.111155.37
1332022.05.24 06:30buy670.011854.920.001865.38
1342022.05.24 16:47t/p670.011865.380.001865.3810.461165.83
1352022.05.30 16:30buy680.011860.850.001873.75
1362022.06.01 08:17close680.011830.850.001873.75-30.781135.05
1372022.06.09 02:15buy690.011854.330.001859.11
1382022.06.10 17:56t/p690.011859.110.001859.114.391139.44
1392022.06.17 08:15buy700.011847.380.001852.76
1402022.06.17 15:53t/p700.011852.760.001852.765.381144.82
1412022.07.22 09:00buy710.011716.260.001721.96
1422022.07.22 12:27t/p710.011721.960.001721.965.701150.52
1432022.07.25 01:15buy720.011726.480.001733.02
1442022.07.25 12:25t/p720.011733.020.001733.026.541157.06
1452022.08.01 05:15buy730.011764.130.001769.45
1462022.08.01 09:45buy740.011764.250.001769.84
1472022.08.01 12:38t/p730.011769.450.001769.455.321162.38
1482022.08.01 12:42t/p740.011769.840.001769.845.591167.97
1492022.08.01 21:00buy750.011769.400.001770.06
1502022.08.01 22:13t/p750.011770.060.001770.060.661168.63
1512022.08.02 12:15buy760.011773.830.001780.03
1522022.08.02 15:15t/p760.011780.030.001780.036.201174.83
1532022.08.05 07:45buy770.011792.040.001793.26
1542022.08.09 13:13close770.011792.550.001793.26-0.271174.56
1552022.08.24 17:00buy780.011746.270.001752.35
1562022.08.24 17:53t/p780.011752.350.001752.356.081180.64
1572022.09.05 20:00buy790.011712.390.001716.49
1582022.09.06 03:22t/p790.011716.490.001716.493.711184.35
1592022.09.08 07:15buy800.011716.950.001722.63
1602022.09.08 13:37t/p800.011722.630.001722.635.681190.03
1612022.09.30 16:45buy810.011669.210.001683.07
1622022.10.03 17:22t/p810.011683.070.001683.0713.471203.50
1632022.10.04 06:45buy820.011700.470.001710.19
1642022.10.04 10:18t/p820.011710.190.001710.199.721213.22
1652022.10.24 07:45buy830.011658.440.001667.68
1662022.10.26 03:00buy840.011653.220.001656.72
1672022.10.26 06:27t/p840.011656.720.001656.723.501216.72
1682022.10.26 10:08t/p830.011667.680.001667.688.461225.18
1692022.10.26 18:15buy850.011672.150.001688.25
1702022.10.27 08:45buy860.011669.870.001682.99
1712022.10.27 11:16buy870.011665.590.001671.30
1722022.10.28 15:30close850.011642.140.001688.25-31.571193.61
1732022.10.28 18:16close860.011639.870.001682.99-30.391163.22
1742022.10.31 10:33close870.011635.590.001671.30-30.781132.44
1752022.11.02 20:15buy880.011664.550.001700.75
1762022.11.02 22:53close880.011634.550.001700.75-30.001102.44
1772022.11.07 05:32buy890.011673.440.001678.96
1782022.11.07 11:23t/p890.011678.960.001678.965.521107.96
1792022.11.10 13:00buy900.011708.650.001717.29
1802022.11.10 15:31t/p900.011717.290.001717.298.641116.60
1812022.11.11 06:45buy910.011752.150.001756.21
1822022.11.11 07:27t/p910.011756.210.001756.214.061120.66
1832022.11.14 05:15buy920.011765.290.001773.39
1842022.11.14 09:45buy930.011762.510.001767.31
1852022.11.14 16:40t/p930.011767.310.001767.314.801125.46
1862022.11.14 17:12t/p920.011773.390.001773.398.101133.56
1872022.11.25 13:15buy940.011753.960.001758.35
1882022.11.28 10:41t/p940.011758.350.001758.354.001137.56
1892022.12.08 13:45buy950.011784.860.001789.50
1902022.12.08 15:23t/p950.011789.500.001789.504.641142.20
1912022.12.09 13:00buy960.011794.910.001806.33
1922022.12.13 15:33t/p960.011806.330.001806.3310.641152.84
1932022.12.14 03:01buy970.011811.600.001816.36
1942022.12.15 10:13close970.011781.590.001816.36-31.181121.66
1952022.12.22 02:15buy980.011816.230.001821.17
1962022.12.22 20:22close980.011786.230.001821.17-30.001091.66
1972022.12.30 03:00buy990.011816.600.001821.40
1982022.12.30 09:01t/p990.011821.400.001821.404.801096.46
1992023.01.05 09:30buy1000.011854.480.001861.84
2002023.01.06 17:21t/p1000.011861.840.001861.846.971103.43
2012023.01.09 14:15buy1010.011875.480.001880.19
2022023.01.09 16:48t/p1010.011880.190.001880.194.711108.14
2032023.01.10 21:15buy1020.011876.190.001884.01
2042023.01.11 06:00buy1030.011878.060.001884.46
2052023.01.11 07:38t/p1020.011884.010.001884.017.431115.57
2062023.01.11 10:47t/p1030.011884.460.001884.466.401121.97
2072023.01.13 10:00buy1040.011899.980.001909.62
2082023.01.13 16:50t/p1040.011909.620.001909.629.641131.61
2092023.01.20 17:30buy1050.011930.400.001939.82
2102023.01.24 08:53t/p1050.011939.820.001939.828.641140.25
2112023.02.01 06:15buy1060.011928.390.001935.43
2122023.02.01 21:42t/p1060.011935.430.001935.437.041147.29
2132023.02.20 04:30buy1070.011842.620.001851.18
2142023.02.22 14:31close1070.011843.130.001851.18-0.271147.02
2152023.03.01 04:00buy1080.011829.430.001841.49
2162023.03.01 15:01t/p1080.011841.490.001841.4912.061159.08
2172023.03.13 11:00buy1090.011885.840.001910.24
2182023.03.13 16:46t/p1090.011910.240.001910.2424.401183.48
2192023.03.14 08:15buy1100.011911.270.001920.74
2202023.03.14 14:15buy1110.011907.600.001919.24
2212023.03.14 19:00buy1120.011909.010.001921.99
2222023.03.15 14:01t/p1110.011919.240.001919.2411.251194.73
2232023.03.15 14:02t/p1100.011920.740.001920.749.081203.81
2242023.03.15 14:03t/p1120.011921.990.001921.9912.591216.40
2252023.03.16 01:15buy1130.011921.480.001928.68
2262023.03.16 14:20t/p1130.011928.680.001928.687.201223.60
2272023.03.16 21:15buy1140.011920.000.001929.92
2282023.03.17 06:53t/p1140.011929.920.001929.929.531233.13
2292023.03.20 06:15buy1150.011974.860.001978.82
2302023.03.20 07:46t/p1150.011978.820.001978.823.961237.09
2312023.03.24 05:58buy1160.011993.650.001997.21
2322023.03.24 12:08t/p1160.011997.210.001997.213.561240.65
2332023.03.31 14:00buy1170.011979.710.001984.51
2342023.03.31 15:33t/p1170.011984.510.001984.514.801245.45
2352023.04.12 15:45buy1180.012022.510.002038.50
2362023.04.13 15:45t/p1180.012038.500.002038.5014.821260.27
2372023.04.26 09:45buy1190.011998.820.002007.08
2382023.04.26 16:26t/p1190.012007.080.002007.088.261268.53
2392023.05.03 11:40buy1200.012016.570.002019.99
2402023.05.03 14:00buy1210.012016.860.002019.56
2412023.05.03 16:30buy1220.012018.960.002029.50
2422023.05.03 16:35t/p1210.012019.560.002019.562.701271.23
2432023.05.03 17:52t/p1200.012019.990.002019.993.421274.65
2442023.05.03 21:00t/p1220.012029.500.002029.5010.541285.19
2452023.05.31 08:00buy1230.011960.380.001966.70
2462023.05.31 13:45buy1240.011958.810.001965.97
2472023.05.31 16:42t/p1240.011965.970.001965.977.161292.35
2482023.05.31 16:42t/p1230.011966.700.001966.706.321298.67
2492023.06.01 02:15buy1250.011966.140.001972.32
2502023.06.01 16:34t/p1250.011972.320.001972.326.181304.85
2512023.06.02 05:00buy1260.011977.670.001981.00
2522023.06.02 06:06t/p1260.011981.000.001981.003.331308.18
2532023.06.02 12:45buy1270.011980.960.001991.34
2542023.06.02 21:02close1270.011950.950.001991.34-30.011278.17
+
diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester 2 - 1 Max Trade.gif b/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester 2 - 1 Max Trade.gif new file mode 100644 index 0000000..47a7b83 Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester 2 - 1 Max Trade.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester 2 - 1 Max Trade.htm b/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester 2 - 1 Max Trade.htm new file mode 100644 index 0000000..fa1f1fb --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester 2 - 1 Max Trade.htm @@ -0,0 +1,273 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.06.29 23:45 (2020.01.01 - 2023.06.30)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=1; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=408; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +step=0.01; maximum=0.1; shortCycleMultiplier=2; mediumCycleMultiplier=6; longCycleMultiplier=36;
Bars in test61247Ticks modelled69753529Modelling quality40.22%
Mismatched charts errors33
Initial deposit1000.00SpreadCurrent (57)
Total net profit247.67Gross profit616.97Gross loss-369.31
Profit factor1.67Expected payoff2.40
Absolute drawdown14.52Maximal drawdown102.26 (8.60%)Relative drawdown8.60% (102.26)
Total trades103Short positions (won %)0 (0.00%)Long positions (won %)103 (84.47%)
Profit trades (% of total)87 (84.47%)Loss trades (% of total)16 (15.53%)
Largestprofit trade42.29loss trade-31.58
Averageprofit trade7.09loss trade-23.08
Maximumconsecutive wins (profit in money)14 (116.92)consecutive losses (loss in money)2 (-61.58)
Maximalconsecutive profit (count of wins)116.92 (14)consecutive loss (count of losses)-61.58 (2)
Averageconsecutive wins7consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.02 08:30buy10.011814.620.001821.43
22020.12.02 10:36t/p10.011821.430.001821.436.811006.81
32020.12.04 14:15buy20.011842.770.001850.53
42020.12.07 16:49t/p20.011850.530.001850.537.371014.18
52020.12.18 01:00buy30.011884.970.001888.29
62020.12.18 14:09t/p30.011888.290.001888.293.321017.50
72021.01.05 05:45buy40.011942.210.001951.99
82021.01.05 16:16t/p40.011951.990.001951.999.781027.28
92021.02.09 03:15buy50.011835.750.001848.25
102021.02.09 11:54t/p50.011848.250.001848.2512.501039.78
112021.02.10 15:15buy60.011844.690.001851.24
122021.02.10 15:37t/p60.011851.240.001851.246.551046.33
132021.03.10 03:15buy70.011718.630.001729.59
142021.03.11 04:07t/p70.011729.590.001729.599.791056.12
152021.03.16 12:30buy80.011733.100.001738.00
162021.03.16 16:22t/p80.011738.000.001738.004.901061.02
172021.04.06 13:30buy90.011732.110.001734.91
182021.04.06 14:24t/p90.011734.910.001734.912.801063.82
192021.04.08 03:00buy100.011737.210.001740.15
202021.04.08 08:01t/p100.011740.150.001740.152.941066.76
212021.04.09 04:30buy110.011756.980.001760.37
222021.04.13 08:37close110.011726.980.001760.37-30.781035.98
232021.04.14 09:15buy120.011746.490.001751.80
242021.04.15 15:19t/p120.011751.800.001751.804.141040.12
252021.04.21 14:15buy130.011782.420.001791.02
262021.04.21 16:49t/p130.011791.020.001791.028.601048.72
272021.05.10 23:15buy140.011837.730.001843.23
282021.05.12 16:04t/p140.011843.230.001843.234.721053.44
292021.05.19 06:45buy150.011869.210.001874.25
302021.05.19 16:00t/p150.011874.250.001874.255.041058.48
312021.07.02 20:45buy160.011785.560.001792.88
322021.07.05 11:06t/p160.011792.880.001792.886.931065.41
332021.07.06 01:06buy170.011791.740.001794.36
342021.07.06 04:45t/p170.011794.360.001794.362.621068.03
352021.07.12 03:30buy180.011809.340.001816.20
362021.07.13 15:39t/p180.011816.200.001816.206.471074.50
372021.07.15 08:45buy190.011828.740.001834.54
382021.07.19 15:06close190.011798.740.001834.54-30.781043.72
392021.07.30 04:30buy200.011829.920.001835.50
402021.08.04 16:09close200.011830.430.001835.50-0.661043.06
412021.08.12 07:30buy210.011752.580.001758.56
422021.08.13 09:24t/p210.011758.560.001758.565.591048.65
432021.08.17 08:15buy220.011787.900.001791.94
442021.08.17 08:52t/p220.011791.940.001791.944.041052.69
452021.09.15 06:45buy230.011804.000.001806.38
462021.09.15 15:24t/p230.011806.380.001806.382.381055.07
472021.09.22 04:45buy240.011776.570.001780.42
482021.09.22 21:07t/p240.011780.420.001780.423.851058.92
492021.10.01 10:00buy250.011756.140.001765.68
502021.10.04 17:39t/p250.011765.680.001765.689.151068.07
512021.10.13 04:00buy260.011761.850.001765.13
522021.10.13 10:39t/p260.011765.130.001765.133.281071.35
532021.10.21 04:00buy270.011784.260.001789.54
542021.10.22 09:31t/p270.011789.540.001789.544.891076.24
552021.10.25 01:15buy280.011793.910.001796.97
562021.10.25 03:54t/p280.011796.970.001796.973.061079.30
572021.11.05 15:15buy290.011796.000.001806.56
582021.11.05 17:22t/p290.011806.560.001806.5610.561089.86
592021.11.08 12:15buy300.011818.100.001823.40
602021.11.08 15:24t/p300.011823.400.001823.405.301095.16
612021.11.18 09:49buy310.011867.520.001875.54
622021.11.22 12:39close310.011837.520.001875.54-30.781064.38
632021.12.07 08:00buy320.011781.380.001785.42
642021.12.07 18:24t/p320.011785.420.001785.424.041068.42
652021.12.14 03:00buy330.011788.230.001793.73
662021.12.15 21:00close330.011758.230.001793.73-30.391038.03
672021.12.23 15:30buy340.011808.500.001813.30
682021.12.28 07:54t/p340.011813.300.001813.303.631041.66
692022.01.11 15:30buy350.011808.500.001814.44
702022.01.11 18:22t/p350.011814.440.001814.445.941047.60
712022.01.12 07:34buy360.011820.590.001824.25
722022.01.12 15:39t/p360.011824.250.001824.253.661051.26
732022.01.13 05:22buy370.011825.590.001827.51
742022.01.13 07:39t/p370.011827.510.001827.511.921053.18
752022.01.26 04:00buy380.011848.290.001851.03
762022.01.26 21:54close380.011818.290.001851.03-30.001023.18
772022.02.01 18:30buy390.011807.040.001815.92
782022.02.04 06:39close390.011807.550.001815.92-1.441021.74
792022.02.09 03:45buy400.011826.810.001829.55
802022.02.09 15:04t/p400.011829.550.001829.552.741024.48
812022.02.18 15:00buy410.011894.340.001904.82
822022.02.21 01:24t/p410.011904.820.001904.8210.091034.57
832022.03.02 08:45buy420.011937.750.001948.69
842022.03.04 02:39t/p420.011948.690.001948.699.381043.95
852022.03.04 11:15buy430.011941.730.001956.47
862022.03.04 16:37t/p430.011956.470.001956.4714.741058.69
872022.03.07 17:45buy440.011989.490.002032.17
882022.03.08 16:49t/p440.012032.170.002032.1742.291100.98
892022.03.24 08:15buy450.011942.970.001948.04
902022.03.24 13:31t/p450.011948.040.001948.045.071106.05
912022.03.25 03:00buy460.011963.150.001973.05
922022.03.28 08:54close460.011933.150.001973.05-30.391075.66
932022.04.08 03:00buy470.011933.410.001938.35
942022.04.08 15:09t/p470.011938.350.001938.354.941080.60
952022.04.11 08:45buy480.011945.040.001949.74
962022.04.11 11:19t/p480.011949.740.001949.744.701085.30
972022.04.12 14:15buy490.011956.750.001966.53
982022.04.12 15:39t/p490.011966.530.001966.539.781095.08
992022.04.13 04:49buy500.011968.240.001977.60
1002022.04.13 12:39t/p500.011977.600.001977.609.361104.44
1012022.04.14 02:00buy510.011978.740.001982.76
1022022.04.18 02:37t/p510.011982.760.001982.763.241107.68
1032022.05.05 13:30buy520.011898.320.001907.76
1042022.05.05 15:49t/p520.011907.760.001907.769.441117.12
1052022.05.20 18:15buy530.011844.250.001855.75
1062022.05.23 08:08t/p530.011855.750.001855.7511.111128.23
1072022.05.24 06:30buy540.011854.990.001865.45
1082022.05.24 16:47t/p540.011865.450.001865.4510.461138.69
1092022.05.30 16:30buy550.011860.920.001873.82
1102022.06.01 08:16close550.011830.910.001873.82-30.791107.90
1112022.06.09 02:15buy560.011854.400.001859.18
1122022.06.10 17:56t/p560.011859.180.001859.184.391112.29
1132022.06.17 08:15buy570.011847.450.001852.83
1142022.06.17 15:53t/p570.011852.830.001852.835.381117.67
1152022.07.22 09:00buy580.011716.330.001722.03
1162022.07.22 12:28t/p580.011722.030.001722.035.701123.37
1172022.07.25 01:15buy590.011726.550.001733.09
1182022.07.25 12:25t/p590.011733.090.001733.096.541129.91
1192022.08.01 05:15buy600.011764.200.001769.52
1202022.08.01 12:41t/p600.011769.520.001769.525.321135.23
1212022.08.01 21:00buy610.011769.470.001770.13
1222022.08.01 22:13t/p610.011770.130.001770.130.661135.89
1232022.08.02 12:15buy620.011773.900.001780.10
1242022.08.02 15:15t/p620.011780.100.001780.106.201142.09
1252022.08.05 07:45buy630.011792.110.001793.33
1262022.08.09 13:13close630.011792.630.001793.33-0.261141.83
1272022.08.24 17:00buy640.011746.340.001752.42
1282022.08.24 17:53t/p640.011752.420.001752.426.081147.91
1292022.09.05 20:00buy650.011712.460.001716.56
1302022.09.06 03:22t/p650.011716.560.001716.563.711151.62
1312022.09.08 07:15buy660.011717.020.001722.70
1322022.09.08 13:37t/p660.011722.700.001722.705.681157.30
1332022.09.30 16:45buy670.011669.280.001683.14
1342022.10.03 17:22t/p670.011683.140.001683.1413.471170.77
1352022.10.04 06:45buy680.011700.540.001710.26
1362022.10.04 10:18t/p680.011710.260.001710.269.721180.49
1372022.10.24 07:45buy690.011658.510.001667.75
1382022.10.26 10:28t/p690.011667.750.001667.758.461188.96
1392022.10.26 18:15buy700.011672.220.001688.32
1402022.10.28 15:30close700.011642.200.001688.32-31.581157.38
1412022.11.02 20:15buy710.011664.620.001700.82
1422022.11.02 22:53close710.011634.620.001700.82-30.001127.38
1432022.11.07 05:32buy720.011673.510.001679.03
1442022.11.07 11:26t/p720.011679.030.001679.035.521132.90
1452022.11.10 13:00buy730.011708.720.001717.36
1462022.11.10 15:31t/p730.011717.360.001717.368.641141.54
1472022.11.11 06:45buy740.011752.220.001756.28
1482022.11.11 07:27t/p740.011756.280.001756.284.061145.60
1492022.11.14 05:15buy750.011765.360.001773.46
1502022.11.14 17:12t/p750.011773.460.001773.468.101153.70
1512022.11.25 13:15buy760.011754.030.001758.42
1522022.11.28 10:41t/p760.011758.420.001758.424.001157.70
1532022.12.08 13:45buy770.011784.930.001789.57
1542022.12.08 15:33t/p770.011789.570.001789.574.641162.34
1552022.12.09 13:00buy780.011794.980.001806.40
1562022.12.13 15:33t/p780.011806.400.001806.4010.641172.98
1572022.12.14 03:01buy790.011811.670.001816.43
1582022.12.15 10:13close790.011781.650.001816.43-31.191141.79
1592022.12.22 02:15buy800.011816.300.001821.24
1602022.12.22 20:22close800.011786.290.001821.24-30.011111.78
1612022.12.30 03:00buy810.011816.670.001821.47
1622022.12.30 09:01t/p810.011821.470.001821.474.801116.58
1632023.01.05 09:30buy820.011854.550.001861.91
1642023.01.06 17:32t/p820.011861.910.001861.916.971123.55
1652023.01.09 14:15buy830.011875.550.001880.26
1662023.01.09 16:48t/p830.011880.260.001880.264.711128.26
1672023.01.10 21:15buy840.011876.260.001884.08
1682023.01.11 07:38t/p840.011884.080.001884.087.431135.69
1692023.01.13 10:00buy850.011900.050.001909.69
1702023.01.13 16:50t/p850.011909.690.001909.699.641145.33
1712023.01.20 17:30buy860.011930.470.001939.89
1722023.01.24 09:02t/p860.011939.890.001939.898.641153.97
1732023.02.01 06:15buy870.011928.460.001935.50
1742023.02.01 21:42t/p870.011935.500.001935.507.041161.01
1752023.02.20 04:30buy880.011842.690.001851.25
1762023.02.22 14:31close880.011843.210.001851.25-0.261160.75
1772023.03.01 04:00buy890.011829.500.001841.56
1782023.03.01 16:38t/p890.011841.560.001841.5612.061172.81
1792023.03.13 11:00buy900.011885.910.001910.31
1802023.03.13 16:46t/p900.011910.310.001910.3124.401197.21
1812023.03.14 08:15buy910.011911.340.001920.81
1822023.03.15 14:02t/p910.011920.810.001920.819.081206.29
1832023.03.16 01:15buy920.011921.550.001928.75
1842023.03.16 14:21t/p920.011928.750.001928.757.201213.49
1852023.03.16 21:15buy930.011920.070.001929.99
1862023.03.17 06:54t/p930.011929.990.001929.999.531223.02
1872023.03.20 06:15buy940.011974.930.001978.89
1882023.03.20 07:46t/p940.011978.890.001978.893.961226.98
1892023.03.24 05:58buy950.011993.720.001997.28
1902023.03.24 12:08t/p950.011997.280.001997.283.561230.54
1912023.03.31 14:00buy960.011979.780.001984.58
1922023.03.31 15:33t/p960.011984.580.001984.584.801235.34
1932023.04.12 15:45buy970.012022.580.002038.57
1942023.04.13 15:46t/p970.012038.570.002038.5714.821250.16
1952023.04.26 09:45buy980.011998.890.002007.15
1962023.04.26 16:26t/p980.012007.150.002007.158.261258.42
1972023.05.03 11:40buy990.012016.640.002020.06
1982023.05.03 17:52t/p990.012020.060.002020.063.421261.84
1992023.05.31 08:00buy1000.011960.450.001966.77
2002023.05.31 16:42t/p1000.011966.770.001966.776.321268.16
2012023.06.01 02:15buy1010.011966.210.001972.39
2022023.06.01 16:35t/p1010.011972.390.001972.396.181274.34
2032023.06.02 05:00buy1020.011977.740.001981.07
2042023.06.02 06:06t/p1020.011981.070.001981.073.331277.67
2052023.06.02 12:45buy1030.011981.030.001991.41
2062023.06.02 21:01close1030.011951.030.001991.41-30.001247.67
+
diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester 3.gif b/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester 3.gif new file mode 100644 index 0000000..83d01e7 Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester 3.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester 3.htm b/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester 3.htm new file mode 100644 index 0000000..11f1abf --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester 3.htm @@ -0,0 +1,321 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.06.29 23:45 (2020.01.01 - 2023.06.30)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=252; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +step=0.01; maximum=0.1; shortCycleMultiplier=2; mediumCycleMultiplier=6; longCycleMultiplier=36;
Bars in test61247Ticks modelled69753529Modelling quality40.22%
Mismatched charts errors33
Initial deposit1000.00SpreadCurrent (60)
Total net profit235.24Gross profit679.38Gross loss-444.14
Profit factor1.53Expected payoff1.85
Absolute drawdown40.51Maximal drawdown135.42 (12.37%)Relative drawdown12.37% (135.42)
Total trades127Short positions (won %)0 (0.00%)Long positions (won %)127 (81.89%)
Profit trades (% of total)104 (81.89%)Loss trades (% of total)23 (18.11%)
Largestprofit trade42.24loss trade-31.31
Averageprofit trade6.53loss trade-19.31
Maximumconsecutive wins (profit in money)21 (167.96)consecutive losses (loss in money)3 (-73.90)
Maximalconsecutive profit (count of wins)167.96 (21)consecutive loss (count of losses)-73.90 (3)
Averageconsecutive wins7consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.02 08:30buy10.011814.650.001821.46
22020.12.02 10:36t/p10.011821.460.001821.466.811006.81
32020.12.04 14:15buy20.011842.800.001850.56
42020.12.04 16:15buy30.011843.600.001853.88
52020.12.07 16:49t/p20.011850.560.001850.567.321014.13
62020.12.07 16:52t/p30.011853.880.001853.889.841023.98
72020.12.18 01:00buy40.011885.000.001888.32
82020.12.18 14:09t/p40.011888.320.001888.323.321027.30
92021.01.05 05:45buy50.011942.240.001952.02
102021.01.05 16:16t/p50.011952.020.001952.029.781037.08
112021.02.09 03:15buy60.011835.780.001848.28
122021.02.09 11:54t/p60.011848.280.001848.2812.501049.58
132021.02.10 15:15buy70.011844.720.001851.27
142021.02.10 15:37t/p70.011851.270.001851.276.551056.13
152021.03.10 03:15buy80.011718.660.001729.62
162021.03.10 15:15buy90.011714.780.001724.10
172021.03.10 21:06t/p90.011724.100.001724.109.321065.45
182021.03.11 04:07t/p80.011729.620.001729.629.651075.10
192021.03.16 12:30buy100.011733.130.001738.03
202021.03.16 16:24t/p100.011738.030.001738.034.901080.00
212021.04.06 13:30buy110.011732.140.001734.94
222021.04.06 14:24t/p110.011734.940.001734.942.801082.80
232021.04.08 03:00buy120.011737.240.001740.18
242021.04.08 08:03t/p120.011740.180.001740.182.941085.74
252021.04.09 04:30buy130.011757.010.001760.40
262021.04.13 08:36close130.011727.010.001760.40-30.871054.87
272021.04.14 09:15buy140.011746.520.001751.83
282021.04.14 15:39buy150.011746.760.001756.02
292021.04.15 15:19t/p140.011751.830.001751.834.001058.88
302021.04.15 16:54t/p150.011756.020.001756.027.951066.83
312021.04.21 14:15buy160.011782.450.001791.05
322021.04.21 16:49t/p160.011791.050.001791.058.601075.43
332021.05.10 23:15buy170.011837.760.001843.26
342021.05.11 11:45buy180.011837.410.001846.05
352021.05.12 15:51close180.011837.920.001846.050.071075.50
362021.05.12 15:52close170.011838.270.001843.26-0.361075.14
372021.05.19 06:45buy190.011869.240.001874.28
382021.05.19 16:00t/p190.011874.280.001874.285.041080.18
392021.07.02 20:45buy200.011785.590.001792.91
402021.07.05 11:06t/p200.011792.910.001792.916.881087.07
412021.07.06 01:06buy210.011791.770.001794.39
422021.07.06 04:45t/p210.011794.390.001794.392.621089.69
432021.07.12 03:30buy220.011809.370.001816.23
442021.07.13 15:04close220.011809.880.001816.230.071089.76
452021.07.15 08:45buy230.011828.770.001834.57
462021.07.19 15:06close230.011798.770.001834.57-30.871058.89
472021.07.30 04:30buy240.011829.950.001835.53
482021.07.30 10:15buy250.011830.190.001836.63
492021.08.03 21:30close240.011810.040.001835.53-20.781038.11
502021.08.04 04:15close250.011809.250.001836.63-22.251015.86
512021.08.12 07:30buy260.011752.610.001758.59
522021.08.13 09:24t/p260.011758.590.001758.595.541021.41
532021.08.17 08:15buy270.011787.930.001791.97
542021.08.17 08:52t/p270.011791.970.001791.974.041025.45
552021.09.15 06:45buy280.011804.030.001806.41
562021.09.15 09:15buy290.011803.620.001806.36
572021.09.15 15:24t/p290.011806.360.001806.362.741028.19
582021.09.15 15:24t/p280.011806.410.001806.412.381030.57
592021.09.22 04:45buy300.011776.600.001780.45
602021.09.22 21:07t/p300.011780.450.001780.453.851034.42
612021.10.01 10:00buy310.011756.170.001765.71
622021.10.04 09:00buy320.011761.820.001765.62
632021.10.04 17:39t/p320.011765.620.001765.623.801038.22
642021.10.04 17:39t/p310.011765.710.001765.719.101047.32
652021.10.13 04:00buy330.011761.880.001765.16
662021.10.13 10:39t/p330.011765.160.001765.163.281050.60
672021.10.21 04:00buy340.011784.290.001789.57
682021.10.22 09:31t/p340.011789.570.001789.574.841055.45
692021.10.25 01:15buy350.011793.940.001797.00
702021.10.25 03:54t/p350.011797.000.001797.003.061058.51
712021.11.05 15:15buy360.011796.030.001806.59
722021.11.05 17:22t/p360.011806.590.001806.5910.561069.07
732021.11.08 12:15buy370.011818.130.001823.43
742021.11.08 15:24t/p370.011823.430.001823.435.301074.37
752021.11.18 09:49buy380.011867.550.001875.57
762021.11.22 12:39close380.011837.550.001875.57-30.871043.50
772021.12.07 08:00buy390.011781.410.001785.45
782021.12.07 18:24t/p390.011785.450.001785.454.041047.54
792021.12.14 03:00buy400.011788.260.001793.76
802021.12.14 08:15buy410.011788.520.001793.80
812021.12.15 21:00close410.011758.510.001793.80-30.451017.09
822021.12.15 21:00close400.011758.250.001793.76-30.45986.65
832021.12.23 15:30buy420.011808.530.001813.33
842021.12.28 01:00close420.011811.350.001813.331.51988.16
852021.12.28 06:45buy430.011810.940.001813.94
862021.12.28 08:36t/p430.011813.940.001813.943.00991.16
872022.01.11 15:30buy440.011808.530.001814.47
882022.01.11 18:22t/p440.011814.470.001814.475.94997.10
892022.01.12 07:34buy450.011820.620.001824.28
902022.01.12 15:39t/p450.011824.280.001824.283.661000.76
912022.01.13 05:22buy460.011825.620.001827.54
922022.01.13 07:39t/p460.011827.540.001827.541.921002.68
932022.01.26 04:00buy470.011848.320.001851.06
942022.01.26 21:54close470.011818.320.001851.06-30.00972.68
952022.02.01 18:30buy480.011807.070.001815.95
962022.02.03 04:00close480.011808.370.001815.95-0.44972.24
972022.02.09 03:45buy490.011826.840.001829.58
982022.02.09 14:30buy500.011827.570.001828.85
992022.02.09 15:04t/p500.011828.850.001828.851.28973.52
1002022.02.09 15:04t/p490.011829.580.001829.582.74976.26
1012022.02.18 15:00buy510.011894.370.001904.85
1022022.02.21 01:24t/p510.011904.850.001904.8510.04986.30
1032022.03.02 08:45buy520.011937.780.001948.72
1042022.03.03 22:19close520.011938.290.001948.72-0.80985.51
1052022.03.04 11:15buy530.011941.760.001956.50
1062022.03.04 16:37t/p530.011956.500.001956.5014.741000.25
1072022.03.07 17:45buy540.011989.520.002032.20
1082022.03.08 06:45buy550.011990.020.001999.84
1092022.03.08 08:30t/p550.011999.840.001999.849.821010.07
1102022.03.08 16:49t/p540.012032.200.002032.2042.241052.31
1112022.03.24 08:15buy560.011943.000.001948.07
1122022.03.24 13:31t/p560.011948.070.001948.075.071057.38
1132022.03.25 03:00buy570.011963.180.001973.08
1142022.03.28 08:54close570.011933.170.001973.08-30.451026.94
1152022.04.08 03:00buy580.011933.440.001938.38
1162022.04.08 15:09t/p580.011938.380.001938.384.941031.88
1172022.04.11 08:45buy590.011945.070.001949.77
1182022.04.11 11:19t/p590.011949.770.001949.774.701036.58
1192022.04.12 14:15buy600.011956.780.001966.56
1202022.04.12 15:39t/p600.011966.560.001966.569.781046.36
1212022.04.13 04:49buy610.011968.270.001977.63
1222022.04.13 12:39t/p610.011977.630.001977.639.361055.72
1232022.04.14 02:00buy620.011978.770.001982.79
1242022.04.14 05:00buy630.011980.150.001986.33
1252022.04.14 10:45buy640.011977.610.001984.30
1262022.04.18 02:37t/p620.011982.790.001982.793.151058.87
1272022.04.18 02:46t/p640.011984.300.001984.305.821064.69
1282022.04.18 02:49t/p630.011986.330.001986.335.311069.99
1292022.05.05 13:30buy650.011898.350.001907.79
1302022.05.05 15:49t/p650.011907.790.001907.799.441079.43
1312022.05.20 18:15buy660.011844.280.001855.78
1322022.05.23 08:08t/p660.011855.780.001855.7811.061090.50
1332022.05.24 06:30buy670.011855.020.001865.48
1342022.05.24 16:47t/p670.011865.480.001865.4810.461100.96
1352022.05.30 16:30buy680.011860.950.001873.85
1362022.06.01 08:16close680.011830.950.001873.85-30.871070.09
1372022.06.09 02:15buy690.011854.430.001859.21
1382022.06.10 17:51close690.011854.940.001859.210.071070.16
1392022.06.17 08:15buy700.011847.480.001852.86
1402022.06.22 04:45close700.011828.420.001852.86-20.371049.80
1412022.07.22 09:00buy710.011716.360.001722.06
1422022.07.22 12:28t/p710.011722.060.001722.065.701055.50
1432022.07.25 01:15buy720.011726.580.001733.12
1442022.07.25 12:25t/p720.011733.120.001733.126.541062.04
1452022.08.01 05:15buy730.011764.230.001769.55
1462022.08.01 09:45buy740.011764.350.001769.94
1472022.08.01 12:41t/p730.011769.550.001769.555.321067.36
1482022.08.01 12:42t/p740.011769.940.001769.945.591072.95
1492022.08.01 21:00buy750.011769.500.001770.16
1502022.08.01 22:13t/p750.011770.160.001770.160.661073.61
1512022.08.02 12:15buy760.011773.930.001780.13
1522022.08.02 15:15t/p760.011780.130.001780.136.201079.81
1532022.08.05 07:45buy770.011792.140.001793.36
1542022.08.09 11:25close770.011792.660.001793.36-0.351079.46
1552022.08.24 17:00buy780.011746.370.001752.45
1562022.08.24 17:53t/p780.011752.450.001752.456.081085.54
1572022.09.05 20:00buy790.011712.490.001716.59
1582022.09.06 03:22t/p790.011716.590.001716.593.661089.20
1592022.09.08 07:15buy800.011717.050.001722.73
1602022.09.08 13:37t/p800.011722.730.001722.735.681094.88
1612022.09.30 16:45buy810.011669.310.001683.17
1622022.10.03 17:22t/p810.011683.170.001683.1713.421108.31
1632022.10.04 06:45buy820.011700.570.001710.29
1642022.10.04 10:18t/p820.011710.290.001710.299.721118.03
1652022.10.24 07:45buy830.011658.540.001667.78
1662022.10.25 16:48close830.011659.050.001667.780.071118.10
1672022.10.26 03:00buy840.011653.320.001656.82
1682022.10.26 06:27t/p840.011656.820.001656.823.501121.60
1692022.10.26 18:15buy850.011672.250.001688.35
1702022.10.27 08:45buy860.011669.970.001683.09
1712022.10.27 11:16buy870.011665.690.001671.40
1722022.10.28 04:58close870.011666.210.001671.400.081121.68
1732022.10.28 04:58close860.011666.210.001683.09-4.201117.49
1742022.10.28 04:58close850.011666.210.001688.35-7.781109.71
1752022.11.02 20:15buy880.011664.650.001682.75
1762022.11.02 22:53close880.011634.640.001682.75-30.011079.70
1772022.11.07 05:32buy890.011673.540.001679.06
1782022.11.07 11:26t/p890.011679.060.001679.065.521085.22
1792022.11.10 13:00buy900.011708.750.001717.39
1802022.11.10 15:31t/p900.011717.390.001717.398.641093.86
1812022.11.11 06:45buy910.011752.250.001756.31
1822022.11.11 07:27t/p910.011756.310.001756.314.061097.92
1832022.11.14 05:15buy920.011765.390.001773.49
1842022.11.14 09:45buy930.011762.610.001767.41
1852022.11.14 16:40t/p930.011767.410.001767.414.801102.72
1862022.11.14 17:12t/p920.011773.490.001773.498.101110.82
1872022.11.25 13:15buy940.011754.060.001758.45
1882022.11.28 10:41t/p940.011758.450.001758.453.951114.77
1892022.12.08 13:45buy950.011784.960.001789.60
1902022.12.08 15:33t/p950.011789.600.001789.604.641119.41
1912022.12.09 13:00buy960.011795.010.001806.43
1922022.12.13 15:31close960.011795.560.001806.43-0.321119.09
1932022.12.14 03:01buy970.011811.700.001816.46
1942022.12.15 10:13close970.011781.700.001816.46-31.311087.78
1952022.12.22 02:15buy980.011816.330.001821.27
1962022.12.22 20:22close980.011786.320.001821.27-30.011057.77
1972022.12.30 03:00buy990.011816.700.001821.50
1982022.12.30 09:01t/p990.011821.500.001821.504.801062.57
1992023.01.05 09:30buy1000.011854.580.001861.94
2002023.01.06 17:42t/p1000.011861.940.001861.946.921069.50
2012023.01.09 14:15buy1010.011875.580.001880.29
2022023.01.09 16:48t/p1010.011880.290.001880.294.711074.21
2032023.01.10 21:15buy1020.011876.290.001884.11
2042023.01.11 06:00buy1030.011878.160.001884.56
2052023.01.11 07:38t/p1020.011884.110.001884.117.381081.59
2062023.01.11 10:48t/p1030.011884.560.001884.566.401087.99
2072023.01.13 10:00buy1040.011900.080.001909.72
2082023.01.13 16:50t/p1040.011909.720.001909.729.641097.63
2092023.01.20 17:30buy1050.011930.500.001939.92
2102023.01.24 03:00close1050.011931.020.001939.92-0.351097.28
2112023.02.01 06:15buy1060.011928.490.001935.53
2122023.02.01 21:42t/p1060.011935.530.001935.537.041104.32
2132023.02.20 04:30buy1070.011842.720.001851.28
2142023.02.21 16:35close1070.011843.230.001851.280.071104.40
2152023.03.01 04:00buy1080.011829.530.001841.59
2162023.03.01 16:38t/p1080.011841.590.001841.5912.061116.46
2172023.03.13 11:00buy1090.011885.940.001910.34
2182023.03.13 16:46t/p1090.011910.340.001910.3424.401140.86
2192023.03.14 08:15buy1100.011911.370.001920.84
2202023.03.14 14:15buy1110.011907.700.001919.34
2212023.03.14 19:00buy1120.011909.110.001922.09
2222023.03.15 14:01t/p1110.011919.340.001919.3411.201152.06
2232023.03.15 14:02t/p1100.011920.840.001920.849.031161.10
2242023.03.15 14:03t/p1120.011922.090.001922.0912.541173.64
2252023.03.16 01:15buy1130.011921.580.001928.78
2262023.03.16 14:21t/p1130.011928.780.001928.787.201180.84
2272023.03.16 21:15buy1140.011920.100.001930.02
2282023.03.17 06:54t/p1140.011930.020.001930.029.481190.33
2292023.03.20 06:15buy1150.011974.960.001978.92
2302023.03.20 07:46t/p1150.011978.920.001978.923.961194.29
2312023.03.24 05:58buy1160.011993.750.001997.31
2322023.03.24 12:08t/p1160.011997.310.001997.313.561197.85
2332023.03.31 14:00buy1170.011979.810.001984.61
2342023.03.31 15:33t/p1170.011984.610.001984.614.801202.65
2352023.04.12 15:45buy1180.012022.610.002038.60
2362023.04.13 15:46t/p1180.012038.600.002038.6014.681217.33
2372023.04.26 09:45buy1190.011998.920.002007.18
2382023.04.26 16:26t/p1190.012007.180.002007.188.261225.59
2392023.05.03 11:40buy1200.012016.670.002020.09
2402023.05.03 14:00buy1210.012016.960.002019.66
2412023.05.03 16:30buy1220.012019.060.002029.60
2422023.05.03 16:35t/p1210.012019.660.002019.662.701228.29
2432023.05.03 17:52t/p1200.012020.090.002020.093.421231.71
2442023.05.03 21:00t/p1220.012029.600.002029.6010.541242.25
2452023.05.31 08:00buy1230.011960.480.001966.80
2462023.05.31 13:45buy1240.011958.910.001966.07
2472023.05.31 16:42t/p1240.011966.070.001966.077.161249.41
2482023.05.31 16:42t/p1230.011966.800.001966.806.321255.73
2492023.06.01 02:15buy1250.011966.240.001972.42
2502023.06.01 16:35t/p1250.011972.420.001972.426.181261.91
2512023.06.02 05:00buy1260.011977.770.001981.10
2522023.06.02 06:06t/p1260.011981.100.001981.103.331265.24
2532023.06.02 12:45buy1270.011981.060.001991.44
2542023.06.02 20:51close1270.011951.060.001991.44-30.001235.24
+
diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester.gif b/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester.gif new file mode 100644 index 0000000..84c508e Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester.htm b/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester.htm new file mode 100644 index 0000000..31e957c --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/14020427/Whole StrategyTester.htm @@ -0,0 +1,333 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.07.19 23:45 (2020.01.01 - 2023.07.20)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=408; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +step=0.01; maximum=0.1; shortCycleMultiplier=2; mediumCycleMultiplier=6; longCycleMultiplier=36;
Bars in test62525Ticks modelled71468432Modelling qualityn/a
Mismatched charts errors753
Initial deposit1000.00SpreadCurrent (60)
Total net profit225.21Gross profit749.40Gross loss-524.19
Profit factor1.43Expected payoff1.69
Absolute drawdown36.70Maximal drawdown158.55 (13.22%)Relative drawdown13.22% (158.55)
Total trades133Short positions (won %)0 (0.00%)Long positions (won %)133 (81.95%)
Profit trades (% of total)109 (81.95%)Loss trades (% of total)24 (18.05%)
Largestprofit trade42.29loss trade-32.32
Averageprofit trade6.88loss trade-21.84
Maximumconsecutive wins (profit in money)19 (161.19)consecutive losses (loss in money)4 (-122.72)
Maximalconsecutive profit (count of wins)161.19 (19)consecutive loss (count of losses)-122.72 (4)
Averageconsecutive wins8consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.02 08:30buy10.011814.650.001821.46
22020.12.02 10:36t/p10.011821.460.001821.466.811006.81
32020.12.04 14:15buy20.011842.800.001850.56
42020.12.04 16:15buy30.011843.600.001853.88
52020.12.07 16:49t/p20.011850.560.001850.567.371014.18
62020.12.07 16:52t/p30.011853.880.001853.889.891024.08
72020.12.18 01:00buy40.011885.000.001888.32
82020.12.18 14:09t/p40.011888.320.001888.323.321027.40
92021.01.05 05:45buy50.011942.240.001952.02
102021.01.05 16:16t/p50.011952.020.001952.029.781037.18
112021.02.09 03:15buy60.011835.780.001848.28
122021.02.09 11:54t/p60.011848.280.001848.2812.501049.68
132021.02.10 15:15buy70.011844.720.001851.27
142021.02.10 15:37t/p70.011851.270.001851.276.551056.23
152021.03.10 03:15buy80.011718.660.001729.62
162021.03.10 15:15buy90.011714.780.001724.10
172021.03.10 21:06t/p90.011724.100.001724.109.321065.55
182021.03.11 04:07t/p80.011729.620.001729.629.801075.35
192021.03.16 12:30buy100.011733.130.001738.03
202021.03.16 16:24t/p100.011738.030.001738.034.901080.25
212021.04.06 13:30buy110.011732.140.001734.94
222021.04.06 14:24t/p110.011734.940.001734.942.801083.05
232021.04.08 03:00buy120.011737.240.001740.18
242021.04.08 08:03t/p120.011740.180.001740.182.941085.99
252021.04.09 04:30buy130.011757.010.001760.40
262021.04.13 08:36close130.011727.010.001760.40-30.771055.22
272021.04.14 09:15buy140.011746.520.001751.83
282021.04.14 15:39buy150.011746.760.001756.02
292021.04.15 15:19t/p140.011751.830.001751.834.151059.38
302021.04.15 16:54t/p150.011756.020.001756.028.101067.48
312021.04.21 14:15buy160.011782.450.001791.05
322021.04.21 16:49t/p160.011791.050.001791.058.601076.08
332021.05.10 23:15buy170.011837.760.001843.26
342021.05.11 11:45buy180.011837.410.001846.05
352021.05.12 16:04t/p170.011843.260.001843.264.731080.81
362021.05.14 15:16close180.011837.920.001846.05-1.421079.40
372021.05.19 06:45buy190.011869.240.001874.28
382021.05.19 16:00t/p190.011874.280.001874.285.041084.44
392021.07.02 20:45buy200.011785.590.001792.91
402021.07.05 11:06t/p200.011792.910.001792.916.931091.37
412021.07.06 01:06buy210.011791.770.001794.39
422021.07.06 04:45t/p210.011794.390.001794.392.621093.99
432021.07.12 03:30buy220.011809.370.001816.23
442021.07.13 15:39t/p220.011816.230.001816.236.471100.47
452021.07.15 08:45buy230.011828.770.001834.57
462021.07.19 15:06close230.011798.770.001834.57-30.771069.70
472021.07.30 04:30buy240.011829.950.001835.53
482021.07.30 10:15buy250.011830.190.001836.63
492021.08.04 16:09close240.011830.460.001835.53-0.651069.05
502021.08.04 16:22close250.011830.700.001836.63-0.651068.41
512021.08.12 07:30buy260.011752.610.001758.59
522021.08.13 09:24t/p260.011758.590.001758.595.591074.00
532021.08.17 08:15buy270.011787.930.001791.97
542021.08.17 08:52t/p270.011791.970.001791.974.041078.04
552021.09.15 06:45buy280.011804.030.001806.41
562021.09.15 09:15buy290.011803.620.001806.36
572021.09.15 15:24t/p290.011806.360.001806.362.741080.78
582021.09.15 15:24t/p280.011806.410.001806.412.381083.16
592021.09.22 04:45buy300.011776.600.001780.45
602021.09.22 21:07t/p300.011780.450.001780.453.851087.01
612021.10.01 10:00buy310.011756.170.001765.71
622021.10.04 09:00buy320.011761.820.001765.62
632021.10.04 17:39t/p320.011765.620.001765.623.801090.81
642021.10.04 17:39t/p310.011765.710.001765.719.151099.97
652021.10.13 04:00buy330.011761.880.001765.16
662021.10.13 10:39t/p330.011765.160.001765.163.281103.25
672021.10.21 04:00buy340.011784.290.001789.57
682021.10.22 09:31t/p340.011789.570.001789.574.891108.14
692021.10.25 01:15buy350.011793.940.001797.00
702021.10.25 03:54t/p350.011797.000.001797.003.061111.20
712021.11.05 15:15buy360.011796.030.001806.59
722021.11.05 17:22t/p360.011806.590.001806.5910.561121.76
732021.11.08 12:15buy370.011818.130.001823.43
742021.11.08 15:24t/p370.011823.430.001823.435.301127.06
752021.11.18 09:49buy380.011867.550.001875.57
762021.11.22 12:39close380.011837.550.001875.57-30.771096.29
772021.12.07 08:00buy390.011781.410.001785.45
782021.12.07 18:24t/p390.011785.450.001785.454.041100.33
792021.12.14 03:00buy400.011788.260.001793.76
802021.12.14 08:15buy410.011788.520.001793.80
812021.12.15 21:00close410.011758.510.001793.80-30.401069.94
822021.12.15 21:00close400.011758.250.001793.76-30.401039.54
832021.12.23 15:30buy420.011808.530.001813.33
842021.12.28 06:45buy430.011810.940.001813.94
852021.12.28 07:54t/p420.011813.330.001813.333.641043.19
862021.12.28 08:36t/p430.011813.940.001813.943.001046.19
872022.01.11 15:30buy440.011808.530.001814.47
882022.01.11 18:22t/p440.011814.470.001814.475.941052.13
892022.01.12 07:34buy450.011820.620.001824.28
902022.01.12 15:39t/p450.011824.280.001824.283.661055.79
912022.01.13 05:22buy460.011825.620.001827.54
922022.01.13 07:39t/p460.011827.540.001827.541.921057.71
932022.01.26 04:00buy470.011848.320.001851.06
942022.01.26 21:54close470.011818.320.001851.06-30.001027.71
952022.02.01 18:30buy480.011807.070.001815.95
962022.02.04 17:30close480.011807.580.001815.95-1.421026.29
972022.02.09 03:45buy490.011826.840.001829.58
982022.02.09 14:30buy500.011827.570.001828.85
992022.02.09 15:04t/p500.011828.850.001828.851.281027.57
1002022.02.09 15:04t/p490.011829.580.001829.582.741030.31
1012022.02.18 15:00buy510.011894.370.001904.85
1022022.02.21 01:24t/p510.011904.850.001904.8510.091040.41
1032022.03.02 08:45buy520.011937.780.001948.72
1042022.03.04 02:39t/p520.011948.720.001948.729.401049.81
1052022.03.04 11:15buy530.011941.760.001956.50
1062022.03.04 16:37t/p530.011956.500.001956.5014.741064.55
1072022.03.07 17:45buy540.011989.520.002032.20
1082022.03.08 06:45buy550.011990.020.001999.84
1092022.03.08 08:30t/p550.011999.840.001999.849.821074.37
1102022.03.08 16:49t/p540.012032.200.002032.2042.291116.66
1112022.03.24 08:15buy560.011943.000.001948.07
1122022.03.24 13:31t/p560.011948.070.001948.075.071121.73
1132022.03.25 03:00buy570.011963.180.001973.08
1142022.03.28 08:54close570.011933.170.001973.08-30.401091.33
1152022.04.08 03:00buy580.011933.440.001938.38
1162022.04.08 15:09t/p580.011938.380.001938.384.941096.27
1172022.04.11 08:45buy590.011945.070.001949.77
1182022.04.11 11:19t/p590.011949.770.001949.774.701100.97
1192022.04.12 14:15buy600.011956.780.001966.56
1202022.04.12 15:39t/p600.011966.560.001966.569.781110.75
1212022.04.13 04:49buy610.011968.270.001977.63
1222022.04.13 12:39t/p610.011977.630.001977.639.361120.11
1232022.04.14 02:00buy620.011978.770.001982.79
1242022.04.14 05:00buy630.011980.150.001986.33
1252022.04.14 10:45buy640.011977.610.001984.30
1262022.04.18 02:37t/p620.011982.790.001982.793.251123.36
1272022.04.18 02:46t/p640.011984.300.001984.305.921129.28
1282022.04.18 02:49t/p630.011986.330.001986.335.411134.69
1292022.05.05 13:30buy650.011898.350.001907.79
1302022.05.05 15:49t/p650.011907.790.001907.799.441144.13
1312022.05.20 18:15buy660.011844.280.001855.78
1322022.05.23 08:08t/p660.011855.780.001855.7811.111155.25
1332022.05.24 06:30buy670.011855.020.001865.48
1342022.05.24 16:47t/p670.011865.480.001865.4810.461165.71
1352022.05.30 16:30buy680.011860.950.001873.85
1362022.06.01 08:16close680.011830.950.001873.85-30.771134.94
1372022.06.09 02:15buy690.011854.430.001859.21
1382022.06.10 17:56t/p690.011859.210.001859.214.391139.33
1392022.06.17 08:15buy700.011847.480.001852.86
1402022.06.23 20:45close700.011828.540.001852.86-21.251118.08
1412022.07.22 09:00buy710.011716.360.001722.06
1422022.07.22 12:28t/p710.011722.060.001722.065.701123.78
1432022.07.25 01:15buy720.011726.580.001733.12
1442022.07.25 12:25t/p720.011733.120.001733.126.541130.32
1452022.08.01 05:15buy730.011764.230.001769.55
1462022.08.01 09:45buy740.011764.350.001769.94
1472022.08.01 12:41t/p730.011769.550.001769.555.321135.64
1482022.08.01 12:42t/p740.011769.940.001769.945.591141.23
1492022.08.01 21:00buy750.011769.500.001770.16
1502022.08.01 22:13t/p750.011770.160.001770.160.661141.89
1512022.08.02 12:15buy760.011773.930.001780.13
1522022.08.02 15:15t/p760.011780.130.001780.136.201148.09
1532022.08.05 07:45buy770.011792.140.001793.36
1542022.08.09 13:42t/p770.011793.360.001793.360.451148.54
1552022.08.24 17:00buy780.011746.370.001752.45
1562022.08.24 17:53t/p780.011752.450.001752.456.081154.62
1572022.09.05 20:00buy790.011712.490.001716.59
1582022.09.06 03:22t/p790.011716.590.001716.593.711158.34
1592022.09.08 07:15buy800.011717.050.001722.73
1602022.09.08 13:37t/p800.011722.730.001722.735.681164.02
1612022.09.30 16:45buy810.011669.310.001683.17
1622022.10.03 17:22t/p810.011683.170.001683.1713.471177.49
1632022.10.04 06:45buy820.011700.570.001710.29
1642022.10.04 10:18t/p820.011710.290.001710.299.721187.21
1652022.10.24 07:45buy830.011658.540.001667.78
1662022.10.26 03:00buy840.011653.320.001656.82
1672022.10.26 06:27t/p840.011656.820.001656.823.501190.71
1682022.10.26 10:28t/p830.011667.780.001667.788.471199.18
1692022.10.26 18:15buy850.011672.250.001688.35
1702022.10.27 08:45buy860.011669.970.001683.09
1712022.10.27 11:16buy870.011665.690.001671.40
1722022.10.28 15:30close850.011642.250.001688.35-31.541167.64
1732022.10.28 18:16close860.011639.970.001683.09-30.391137.26
1742022.10.31 10:33close870.011635.680.001671.40-30.781106.48
1752022.11.02 20:15buy880.011664.650.001700.85
1762022.11.02 22:53close880.011634.640.001700.85-30.011076.47
1772022.11.07 05:32buy890.011673.540.001679.06
1782022.11.07 11:26t/p890.011679.060.001679.065.521081.99
1792022.11.10 13:00buy900.011708.750.001717.39
1802022.11.10 15:31t/p900.011717.390.001717.398.641090.63
1812022.11.11 06:45buy910.011752.250.001756.31
1822022.11.11 07:27t/p910.011756.310.001756.314.061094.69
1832022.11.14 05:15buy920.011765.390.001773.49
1842022.11.14 09:45buy930.011762.610.001767.41
1852022.11.14 16:40t/p930.011767.410.001767.414.801099.49
1862022.11.14 17:12t/p920.011773.490.001773.498.101107.59
1872022.11.25 13:15buy940.011754.060.001758.45
1882022.11.28 10:41t/p940.011758.450.001758.454.001111.59
1892022.12.08 13:45buy950.011784.960.001789.60
1902022.12.08 15:33t/p950.011789.600.001789.604.641116.23
1912022.12.09 13:00buy960.011795.010.001806.43
1922022.12.13 15:33t/p960.011806.430.001806.4310.651126.88
1932022.12.14 03:01buy970.011811.700.001816.46
1942022.12.15 10:13close970.011781.700.001816.46-31.161095.73
1952022.12.22 02:15buy980.011816.330.001821.27
1962022.12.22 20:22close980.011786.320.001821.27-30.011065.72
1972022.12.30 03:00buy990.011816.700.001821.50
1982022.12.30 09:01t/p990.011821.500.001821.504.801070.52
1992023.01.05 09:30buy1000.011854.580.001861.94
2002023.01.06 17:42t/p1000.011861.940.001861.946.971077.49
2012023.01.09 14:15buy1010.011875.580.001880.29
2022023.01.09 16:48t/p1010.011880.290.001880.294.711082.20
2032023.01.10 21:15buy1020.011876.290.001884.11
2042023.01.11 06:00buy1030.011878.160.001884.56
2052023.01.11 07:38t/p1020.011884.110.001884.117.431089.64
2062023.01.11 10:48t/p1030.011884.560.001884.566.401096.04
2072023.01.13 10:00buy1040.011900.080.001909.72
2082023.01.13 16:50t/p1040.011909.720.001909.729.641105.68
2092023.01.20 17:30buy1050.011930.500.001939.92
2102023.01.24 09:02t/p1050.011939.920.001939.928.651114.33
2112023.02.01 06:15buy1060.011928.490.001935.53
2122023.02.01 21:42t/p1060.011935.530.001935.537.041121.37
2132023.02.20 04:30buy1070.011842.720.001851.28
2142023.02.24 15:33close1070.011812.710.001851.28-32.321089.05
2152023.03.01 04:00buy1080.011829.530.001841.59
2162023.03.01 16:38t/p1080.011841.590.001841.5912.061101.11
2172023.03.13 11:00buy1090.011885.940.001910.34
2182023.03.13 16:46t/p1090.011910.340.001910.3424.401125.51
2192023.03.14 08:15buy1100.011911.370.001920.84
2202023.03.14 14:15buy1110.011907.700.001919.34
2212023.03.14 19:00buy1120.011909.110.001922.09
2222023.03.15 14:01t/p1110.011919.340.001919.3411.251136.76
2232023.03.15 14:02t/p1100.011920.840.001920.849.081145.85
2242023.03.15 14:03t/p1120.011922.090.001922.0912.591158.44
2252023.03.16 01:15buy1130.011921.580.001928.78
2262023.03.16 14:21t/p1130.011928.780.001928.787.201165.64
2272023.03.16 21:15buy1140.011920.100.001930.02
2282023.03.17 06:54t/p1140.011930.020.001930.029.531175.17
2292023.03.20 06:15buy1150.011974.960.001978.92
2302023.03.20 07:46t/p1150.011978.920.001978.923.961179.13
2312023.03.24 05:58buy1160.011993.750.001997.31
2322023.03.24 12:08t/p1160.011997.310.001997.313.561182.69
2332023.03.31 14:00buy1170.011979.810.001984.61
2342023.03.31 15:33t/p1170.011984.610.001984.614.801187.49
2352023.04.12 15:45buy1180.012022.610.002038.60
2362023.04.13 15:46t/p1180.012038.600.002038.6014.831202.33
2372023.04.26 09:45buy1190.011998.920.002007.18
2382023.04.26 16:26t/p1190.012007.180.002007.188.261210.59
2392023.05.03 11:40buy1200.012016.670.002020.09
2402023.05.03 14:00buy1210.012016.960.002019.66
2412023.05.03 16:30buy1220.012019.060.002029.60
2422023.05.03 16:35t/p1210.012019.660.002019.662.701213.29
2432023.05.03 17:52t/p1200.012020.090.002020.093.421216.71
2442023.05.03 21:00t/p1220.012029.600.002029.6010.541227.25
2452023.05.31 08:00buy1230.011960.480.001966.80
2462023.05.31 13:45buy1240.011958.910.001966.07
2472023.05.31 16:42t/p1240.011966.070.001966.077.161234.41
2482023.05.31 16:42t/p1230.011966.800.001966.806.321240.73
2492023.06.01 02:15buy1250.011966.240.001972.42
2502023.06.01 16:35t/p1250.011972.420.001972.426.181246.91
2512023.06.02 05:00buy1260.011977.770.001981.10
2522023.06.02 06:06t/p1260.011981.100.001981.103.331250.24
2532023.06.02 12:45buy1270.011981.060.001991.44
2542023.06.02 20:51close1270.011951.060.001991.44-30.001220.24
2552023.07.03 07:00buy1280.011918.700.001922.42
2562023.07.03 16:16t/p1280.011922.420.001922.423.721223.96
2572023.07.11 19:45buy1290.011932.790.001935.57
2582023.07.12 03:35t/p1290.011935.570.001935.572.391226.35
2592023.07.13 16:15buy1300.011961.140.001969.50
2602023.07.18 14:16t/p1300.011969.500.001969.507.201233.56
2612023.07.19 10:15buy1310.011980.120.001986.85
2622023.07.19 15:30buy1320.011978.550.001984.68
2632023.07.19 20:08buy1330.011979.090.001989.95
2642023.07.19 23:54close at stop1330.011976.470.001989.95-2.621230.94
2652023.07.19 23:54close at stop1320.011976.470.001984.68-2.081228.86
2662023.07.19 23:54close at stop1310.011976.470.001986.85-3.651225.21
+
diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/XR Strategy Test 1.gif b/Bkp/Used/14020502/Docs/Reports/14020427/XR Strategy Test 1.gif new file mode 100644 index 0000000..d3f1e22 Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/14020427/XR Strategy Test 1.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/XR Strategy Test 1.htm b/Bkp/Used/14020502/Docs/Reports/14020427/XR Strategy Test 1.htm new file mode 100644 index 0000000..98bc578 --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/14020427/XR Strategy Test 1.htm @@ -0,0 +1,138 @@ + + + + Strategy Tester: x-saherelm.xr.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.xr.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.06.29 23:45 (2020.01.01 - 2023.06.30)
ModelEvery tick (the most precise method based on all available least timeframes)
Bars in test61247Ticks modelled69753529Modelling quality40.22%
Mismatched charts errors33
Initial deposit1000.00SpreadCurrent (60)
Total net profit2337.40Gross profit2533.14Gross loss-195.74
Profit factor12.94Expected payoff57.01
Absolute drawdown600.00Maximal drawdown1787.50 (55.97%)Relative drawdown69.29% (1556.27)
Total trades41Short positions (won %)0 (0.00%)Long positions (won %)41 (95.12%)
Profit trades (% of total)39 (95.12%)Loss trades (% of total)2 (4.88%)
Largestprofit trade75.00loss trade-107.85
Averageprofit trade64.95loss trade-97.87
Maximumconsecutive wins (profit in money)17 (1231.46)consecutive losses (loss in money)1 (-107.85)
Maximalconsecutive profit (count of wins)1231.46 (17)consecutive loss (count of losses)-107.85 (1)
Averageconsecutive wins13consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.02 15:15buy10.501824.660.001826.16
22020.12.02 17:39t/p10.501826.160.001826.1675.001075.00
32021.01.11 04:00buy20.501829.260.001830.76
42021.01.11 04:31t/p20.501830.760.001830.7675.001150.00
52021.02.12 14:00buy30.501819.170.001820.67
62021.02.12 17:46t/p30.501820.670.001820.6775.001225.00
72021.02.15 10:30buy40.501819.510.001821.01
82021.02.15 13:39t/p40.501821.010.001821.0175.001300.00
92021.02.15 18:15buy50.501819.540.001821.04
102021.02.16 02:24t/p50.501821.040.001821.0453.231353.23
112021.05.07 06:15buy60.501819.850.001821.35
122021.05.07 06:24t/p60.501821.350.001821.3575.001428.23
132021.05.07 10:30buy70.501820.000.001821.50
142021.05.07 11:34t/p70.501821.500.001821.5075.001503.23
152021.05.07 16:00buy80.501839.160.001840.66
162021.05.07 16:03t/p80.501840.660.001840.6675.001578.23
172021.05.13 04:30buy90.501822.150.001823.65
182021.05.13 17:51t/p90.501823.650.001823.6575.001653.23
192021.06.17 02:45buy100.501820.030.001821.53
202021.06.17 04:54t/p100.501821.530.001821.5375.001728.23
212021.07.14 15:30buy110.501824.340.001825.84
222021.07.14 15:34t/p110.501825.840.001825.8475.001803.23
232021.07.16 15:45buy120.501823.910.001825.41
242021.07.16 16:39t/p120.501825.410.001825.4175.001878.23
252021.07.29 10:15buy130.501819.440.001820.94
262021.07.29 11:39t/p130.501820.940.001820.9475.001953.23
272021.08.27 22:30buy140.501818.730.001820.23
282021.08.30 03:37t/p140.501820.230.001820.2353.232006.46
292021.08.30 03:45buy150.501820.450.001821.95
302021.08.30 04:06t/p150.501821.950.001821.9575.002081.46
312021.09.03 16:00buy160.501823.920.001825.42
322021.09.03 16:09t/p160.501825.420.001825.4275.002156.46
332021.11.08 15:45buy170.501819.340.001820.84
342021.11.08 15:54t/p170.501820.840.001820.8475.002231.46
352021.12.28 15:45buy180.501819.710.001821.21
362021.12.31 11:09close180.501819.730.001821.21-107.852123.61
372022.01.05 15:15buy190.501820.490.001821.99
382022.01.05 15:24t/p190.501821.990.001821.9975.002198.61
392022.01.12 16:00buy200.501821.690.001823.19
402022.01.12 16:37t/p200.501823.190.001823.1975.002273.61
412022.01.18 18:00buy210.501820.250.001821.75
422022.01.19 15:21t/p210.501821.750.001821.7553.232326.84
432022.01.19 15:21buy220.501822.350.001823.85
442022.01.19 15:24t/p220.501823.850.001823.8575.002401.84
452022.02.08 10:45buy230.501820.380.001821.88
462022.02.08 15:39t/p230.501821.880.001821.8875.002476.84
472022.05.13 02:15buy240.501820.070.001821.57
482022.05.13 02:47t/p240.501821.570.001821.5775.002551.84
492022.05.13 14:15buy250.501818.840.001820.34
502022.05.16 21:56t/p250.501820.340.001820.3453.232605.07
512022.05.18 13:00buy260.501819.810.001821.31
522022.05.18 18:41t/p260.501821.310.001821.3175.002680.07
532022.05.18 19:00buy270.501823.970.001825.47
542022.05.19 12:08t/p270.501825.470.001825.479.692689.76
552022.06.14 16:15buy280.501820.010.001821.51
562022.06.15 09:37t/p280.501821.510.001821.5153.232742.99
572022.06.15 09:37buy290.501822.110.001823.61
582022.06.15 10:42t/p290.501823.610.001823.6175.002817.99
592022.06.16 15:15buy300.501823.900.001825.40
602022.06.16 15:31t/p300.501825.400.001825.4075.002892.99
612022.06.24 16:30buy310.501826.410.001827.91
622022.06.24 17:09t/p310.501827.910.001827.9175.002967.99
632022.06.29 19:15buy320.501818.970.001820.47
642022.06.30 03:49t/p320.501820.470.001820.479.692977.68
652022.12.13 17:00buy330.501822.380.001823.88
662022.12.13 17:00t/p330.501823.880.001823.8875.003052.68
672022.12.21 15:45buy340.501819.140.001820.64
682022.12.21 17:08t/p340.501820.640.001820.6475.003127.68
692022.12.22 05:15buy350.501818.900.001820.40
702022.12.27 17:26t/p350.501820.400.001820.409.693137.37
712022.12.27 17:45buy360.501827.790.001829.29
722023.01.03 01:05close360.501829.080.001829.29-87.893049.48
732023.01.03 01:05buy370.501829.670.001831.17
742023.01.03 02:12t/p370.501831.170.001831.1775.003124.48
752023.02.23 16:00buy380.501825.940.001827.44
762023.02.23 16:17t/p380.501827.440.001827.4475.003199.48
772023.02.27 20:15buy390.501819.340.001820.84
782023.02.28 17:00t/p390.501820.840.001820.8453.233252.71
792023.03.07 18:45buy400.501819.710.001821.21
802023.03.07 19:13t/p400.501821.210.001821.2175.003327.71
812023.03.08 17:45buy410.501820.430.001821.93
822023.03.09 15:33t/p410.501821.930.001821.939.693337.40
+
diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/XR Strategy Test 2.gif b/Bkp/Used/14020502/Docs/Reports/14020427/XR Strategy Test 2.gif new file mode 100644 index 0000000..bbc1222 Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/14020427/XR Strategy Test 2.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/XR Strategy Test 2.htm b/Bkp/Used/14020502/Docs/Reports/14020427/XR Strategy Test 2.htm new file mode 100644 index 0000000..1997074 --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/14020427/XR Strategy Test 2.htm @@ -0,0 +1,241 @@ + + + + Strategy Tester: x-saherelm.xr.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.xr.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.06.29 23:45 (2020.01.01 - 2023.06.30)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=35; swingLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=2; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=96; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +
Bars in test61247Ticks modelled69753529Modelling quality40.22%
Mismatched charts errors33
Initial deposit1000.00SpreadCurrent (60)
Total net profit-22.73Gross profit140.12Gross loss-162.85
Profit factor0.86Expected payoff-0.26
Absolute drawdown35.59Maximal drawdown110.15 (10.25%)Relative drawdown10.25% (110.15)
Total trades87Short positions (won %)0 (0.00%)Long positions (won %)87 (88.51%)
Profit trades (% of total)77 (88.51%)Loss trades (% of total)10 (11.49%)
Largestprofit trade9.07loss trade-31.31
Averageprofit trade1.82loss trade-16.29
Maximumconsecutive wins (profit in money)33 (47.60)consecutive losses (loss in money)3 (-67.46)
Maximalconsecutive profit (count of wins)60.79 (24)consecutive loss (count of losses)-67.46 (3)
Averageconsecutive wins10consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
1652022.07.20 16:45buy830.011710.780.001713.22
1662022.07.21 14:37close830.011680.780.001713.22-31.31967.80
1472022.05.10 14:45buy740.011863.420.001865.19
1482022.05.11 02:53close740.011833.400.001865.19-30.461038.94
792021.10.14 15:45buy400.011799.210.001800.37
802021.10.15 15:52close400.011769.200.001800.37-30.451021.80
1612022.07.05 02:15buy810.011810.010.001813.25
1622022.07.05 17:03close810.011779.990.001813.25-30.021005.24
492021.06.09 06:15buy250.011896.400.001903.47
502021.06.10 07:15close250.011886.580.001903.47-11.131049.67
1532022.06.14 10:00buy770.011830.310.001843.30
1542022.06.15 11:00close770.011820.620.001843.30-10.131031.93
512021.06.15 16:00buy260.011866.010.001868.96
522021.06.16 17:00close260.011858.760.001868.96-7.691041.98
1632022.07.12 13:00buy820.011735.390.001743.99
1642022.07.13 14:00close820.011729.690.001743.99-6.14999.10
732021.10.07 14:15buy370.011764.680.001764.87
762021.10.08 13:54close370.011760.360.001764.87-4.761052.17
672021.09.01 19:00buy340.011815.860.001816.89
682021.09.02 12:39close340.011816.370.001816.89-0.801054.22
692021.09.02 14:45buy350.011815.870.001815.87
702021.09.02 14:54t/p350.011815.870.001815.870.001054.22
1092021.12.22 17:15buy550.011792.860.001792.86
1102021.12.22 17:24t/p550.011792.860.001792.860.001044.70
392021.05.11 12:45buy200.011838.500.001838.54
402021.05.11 13:04t/p200.011838.540.001838.540.041052.35
1412022.03.10 12:15buy710.011995.580.001995.62
1422022.03.10 12:15t/p710.011995.620.001995.620.041066.30
192021.03.22 18:00buy100.011738.750.001742.92
202021.03.23 08:33close100.011739.260.001742.920.071036.18
352021.04.30 14:30buy180.011772.700.001773.44
362021.05.03 05:22close180.011773.210.001773.440.071049.31
592021.07.02 21:15buy300.011791.110.001794.84
602021.07.05 10:37close300.011791.620.001794.840.071051.48
772021.10.11 18:15buy390.011758.580.001760.18
782021.10.12 08:04close390.011759.090.001760.180.071052.24
912021.11.11 19:00buy460.011862.510.001865.78
922021.11.12 17:21close460.011863.020.001865.780.071032.55
1052021.12.10 06:30buy530.011779.380.001779.47
1062021.12.10 15:37t/p530.011779.470.001779.470.091043.66
1292022.02.04 09:00buy650.011807.450.001807.70
1302022.02.04 09:05t/p650.011807.700.001807.700.251057.24
1552022.06.17 15:45buy780.011850.980.001851.29
1562022.06.17 15:46t/p780.011851.290.001851.290.311032.24
972021.11.26 05:00buy490.011794.490.001794.82
982021.11.26 05:04t/p490.011794.820.001794.820.331039.16
332021.04.27 17:00buy170.011783.470.001783.89
342021.04.27 17:09t/p170.011783.890.001783.890.421049.24
132021.02.15 02:45buy70.011822.670.001830.54
142021.02.15 14:46close70.011823.180.001830.540.511023.20
412021.05.19 03:00buy210.011870.540.001874.85
422021.05.19 15:54close210.011871.050.001874.850.511052.86
532021.06.30 05:15buy270.011764.210.001765.55
542021.06.30 17:49close270.011764.720.001765.550.511042.49
742021.10.08 09:30buy380.011759.850.001762.96
752021.10.08 13:54close380.011760.360.001762.960.511056.92
1452022.04.26 06:15buy730.011905.400.001911.36
1462022.04.26 23:23close730.011905.910.001911.360.511069.40
1572022.06.21 05:00buy790.011841.920.001843.00
1582022.06.21 17:39close790.011842.430.001843.000.511032.75
1132021.12.27 07:15buy570.011810.970.001811.49
1142021.12.27 17:19t/p570.011811.490.001811.490.521045.84
1212022.01.07 16:30buy610.011792.620.001793.14
1222022.01.07 16:43t/p610.011793.140.001793.140.521051.06
1112021.12.23 10:15buy560.011807.640.001808.26
1122021.12.23 15:30t/p560.011808.260.001808.260.621045.32
1152022.01.04 11:45buy580.011806.180.001806.85
1162022.01.04 12:24t/p580.011806.850.001806.850.671046.51
252021.04.15 08:30buy130.011741.610.001742.31
262021.04.15 08:45t/p130.011742.310.001742.310.701041.75
892021.11.05 06:30buy450.011795.050.001795.76
902021.11.05 07:04t/p450.011795.760.001795.760.711032.48
1492022.05.12 03:30buy750.011855.500.001856.26
1502022.05.12 03:38t/p750.011856.260.001856.260.761039.70
872021.10.28 05:00buy440.011798.040.001798.85
882021.10.28 05:09t/p440.011798.850.001798.850.811031.77
1172022.01.05 04:00buy590.011815.740.001816.60
1182022.01.05 08:22t/p590.011816.600.001816.600.861047.37
1272022.01.31 01:30buy640.011790.370.001797.78
1282022.01.31 13:30close640.011791.330.001797.780.961056.99
1072021.12.13 10:15buy540.011787.030.001788.07
1082021.12.13 13:39t/p540.011788.070.001788.071.041044.70
1352022.02.11 14:45buy680.011830.390.001831.47
1362022.02.11 15:04t/p680.011831.470.001831.471.081061.35
112021.02.05 07:15buy60.011796.630.001797.72
122021.02.05 07:36t/p60.011797.720.001797.721.091022.69
1032021.12.07 17:45buy520.011783.270.001784.36
1042021.12.07 18:22t/p520.011784.360.001784.361.091043.57
1012021.12.03 18:30buy510.011777.270.001778.37
1022021.12.03 18:51t/p510.011778.370.001778.371.101042.48
632021.08.18 09:00buy320.011791.060.001792.18
642021.08.18 09:09t/p320.011792.180.001792.181.121053.80
1712022.08.23 11:00buy860.011738.700.001739.84
1722022.08.23 11:13t/p860.011739.840.001739.841.14975.10
1252022.01.25 08:30buy630.011842.670.001843.84
1262022.01.25 16:49t/p630.011843.840.001843.841.171056.03
612021.08.03 20:15buy310.011811.680.001813.32
622021.08.04 05:22t/p310.011813.320.001813.321.201052.68
652021.08.26 17:45buy330.011790.620.001791.84
662021.08.26 17:54t/p330.011791.840.001791.841.221055.02
1332022.02.09 12:15buy670.011827.680.001829.06
1342022.02.09 15:04t/p670.011829.060.001829.061.381060.27
832021.10.25 11:00buy420.011799.510.001800.90
842021.10.25 11:15t/p420.011800.900.001800.901.391025.44
92021.02.01 08:15buy50.011863.750.001875.61
102021.02.01 20:15close50.011865.280.001875.611.531021.60
472021.06.07 16:30buy240.011890.190.001891.73
482021.06.07 17:24t/p240.011891.730.001891.731.541060.79
1312022.02.07 11:00buy660.011813.460.001815.11
1322022.02.07 15:09t/p660.011815.110.001815.111.651058.89
272021.04.16 11:45buy140.011765.210.001767.00
282021.04.16 12:09t/p140.011767.000.001767.001.791043.54
1372022.02.18 23:00buy690.011897.400.001899.76
1382022.02.21 01:00t/p690.011899.760.001899.761.921063.28
212021.03.24 21:15buy110.011734.950.001738.29
222021.03.25 05:15t/p110.011738.290.001738.292.031038.21
452021.05.25 12:00buy230.011883.100.001885.26
462021.05.25 16:52t/p230.011885.260.001885.262.161059.25
1732022.08.24 21:00buy870.011749.940.001753.42
1742022.08.25 03:50t/p870.011753.420.001753.422.17977.27
712021.09.08 13:45buy360.011798.650.001800.84
722021.09.08 15:09t/p360.011800.840.001800.842.191056.41
992021.11.30 16:00buy500.011796.060.001798.28
1002021.11.30 16:49t/p500.011798.280.001798.282.221041.38
812021.10.19 16:00buy410.011782.030.001784.28
822021.10.19 16:01t/p410.011784.280.001784.282.251024.05
1512022.06.07 10:30buy760.011846.180.001848.53
1522022.06.07 12:20t/p760.011848.530.001848.532.351042.05
952021.11.16 03:30buy480.011865.160.001867.64
962021.11.16 04:37t/p480.011867.640.001867.642.481038.83
1592022.06.24 20:30buy800.011828.550.001831.50
1602022.06.27 01:00t/p800.011831.500.001831.502.511035.26
1432022.03.21 13:30buy720.011926.050.001928.64
1442022.03.21 15:52t/p720.011928.640.001928.642.591068.89
312021.04.26 21:45buy160.011780.270.001783.33
322021.04.27 04:01t/p160.011783.330.001783.332.621048.82
292021.04.19 09:45buy150.011780.760.001783.41
302021.04.19 10:39t/p150.011783.410.001783.412.651046.19
1672022.07.25 10:30buy840.011728.350.001731.02
1682022.07.25 12:18t/p840.011731.020.001731.022.67970.47
12020.12.03 16:15buy10.011840.090.001843.27
22020.12.04 04:52t/p10.011843.270.001843.272.741002.74
232021.03.31 12:15buy120.011685.800.001688.64
242021.03.31 13:39t/p120.011688.640.001688.642.841041.05
1392022.03.03 12:15buy700.011931.410.001934.39
1402022.03.03 12:30t/p700.011934.390.001934.392.981066.26
552021.07.01 16:45buy280.011779.550.001782.54
562021.07.01 17:03t/p280.011782.540.001782.542.991045.48
372021.05.10 09:00buy190.011839.010.001842.01
382021.05.10 15:09t/p190.011842.010.001842.013.001052.31
1192022.01.07 05:15buy600.011792.220.001795.39
1202022.01.07 15:39t/p600.011795.390.001795.393.171050.54
1692022.08.08 05:30buy850.011775.410.001778.90
1702022.08.08 10:48t/p850.011778.900.001778.903.49973.96
932021.11.15 13:15buy470.011863.840.001867.64
942021.11.15 15:09t/p470.011867.640.001867.643.801036.35
1232022.01.19 11:30buy620.011816.070.001819.87
1242022.01.19 15:17t/p620.011819.870.001819.873.801054.86
172021.03.16 15:30buy90.011733.170.001737.00
182021.03.16 16:21t/p90.011737.000.001737.003.831036.10
52020.12.08 04:00buy30.011864.270.001868.35
62020.12.08 04:54t/p30.011868.350.001868.354.081015.21
432021.05.21 12:30buy220.011877.800.001882.03
442021.05.21 15:19t/p220.011882.030.001882.034.231057.09
72020.12.31 13:45buy40.011894.880.001899.74
82020.12.31 17:31t/p40.011899.740.001899.744.861020.07
852021.10.27 18:00buy430.011792.490.001798.01
862021.10.27 21:27t/p430.011798.010.001798.015.521030.96
572021.07.02 03:30buy290.011776.660.001782.58
582021.07.02 11:22t/p290.011782.580.001782.585.921051.40
32020.12.07 07:15buy20.011839.630.001848.02
42020.12.07 16:49t/p20.011848.020.001848.028.391011.13
152021.03.02 12:30buy80.011727.470.001736.54
162021.03.02 19:36t/p80.011736.540.001736.549.071032.27
+
diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/test 1.gif b/Bkp/Used/14020502/Docs/Reports/14020427/test 1.gif new file mode 100644 index 0000000..39e88dd Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/14020427/test 1.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/14020427/test 1.htm b/Bkp/Used/14020502/Docs/Reports/14020427/test 1.htm new file mode 100644 index 0000000..afc9bc5 --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/14020427/test 1.htm @@ -0,0 +1,299 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.06.29 23:45 (2020.01.01 - 2023.06.30)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=408; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +step=0.01; maximum=0.1; shortCycleMultiplier=2; mediumCycleMultiplier=6; longCycleMultiplier=36;
Bars in test61247Ticks modelled69753529Modelling quality40.22%
Mismatched charts errors33
Initial deposit1000.00SpreadCurrent (50)
Total net profit-1.93Gross profit395.60Gross loss-397.53
Profit factor1.00Expected payoff-0.02
Absolute drawdown93.42Maximal drawdown137.71 (13.19%)Relative drawdown13.19% (137.71)
Total trades116Short positions (won %)0 (0.00%)Long positions (won %)116 (36.21%)
Profit trades (% of total)42 (36.21%)Loss trades (% of total)74 (63.79%)
Largestprofit trade24.00loss trade-15.43
Averageprofit trade9.42loss trade-5.37
Maximumconsecutive wins (profit in money)4 (59.73)consecutive losses (loss in money)9 (-44.59)
Maximalconsecutive profit (count of wins)59.73 (4)consecutive loss (count of losses)-60.13 (8)
Averageconsecutive wins2consecutive losses3
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.01 02:45buy10.011779.481775.151786.48
22020.12.01 06:24t/p10.011786.481775.151786.487.001007.00
32020.12.02 01:30buy20.011812.601812.081813.44
42020.12.02 01:31s/l20.011812.081812.081813.44-0.521006.48
52020.12.02 08:30buy30.011814.551806.131821.36
62020.12.02 10:36t/p30.011821.361806.131821.366.811013.29
72020.12.02 17:45buy40.011825.371811.451847.89
82020.12.03 04:45buy50.011829.931825.741836.71
92020.12.03 05:39t/p50.011836.711825.741836.716.781020.07
102020.12.03 14:00buy60.011842.771833.331858.05
112020.12.03 16:49s/l60.011833.331833.331858.05-9.441010.63
122020.12.03 20:15buy70.011839.001828.731855.62
132020.12.04 04:47buy80.011841.651838.241847.17
142020.12.04 08:00s/l80.011838.241838.241847.17-3.411007.22
152020.12.04 09:00buy90.011843.921836.891849.61
162020.12.04 14:15buy100.011842.701837.901850.46
172020.12.04 15:39s/l100.011837.901837.901850.46-4.801002.42
182020.12.04 15:39s/l90.011836.891836.891849.61-7.03995.39
192020.12.04 16:15buy110.011843.501830.791853.78
202020.12.04 16:18t/p40.011847.891811.451847.8920.781016.17
212020.12.04 17:54s/l110.011830.791830.791853.78-12.711003.46
222020.12.04 21:00buy120.011835.851833.561839.55
232020.12.07 01:23s/l120.011833.561833.561839.55-2.731000.73
242020.12.07 10:34s/l70.011828.731828.731855.62-11.14989.59
252020.12.07 14:15buy130.011832.091826.761840.71
262020.12.07 16:24t/p130.011840.711826.761840.718.62998.21
272020.12.07 23:45buy140.011864.891857.241877.27
282020.12.08 04:15buy150.011866.521860.091876.92
292020.12.08 13:08s/l150.011860.091860.091876.92-6.43991.78
302020.12.08 15:00buy160.011866.011859.711876.21
312020.12.09 02:30buy170.011870.041869.251871.32
322020.12.09 02:31s/l170.011869.251869.251871.32-0.79990.99
332020.12.09 05:39s/l160.011859.711859.711876.21-6.74984.26
342020.12.09 06:07s/l140.011857.241857.241877.27-8.52975.74
352020.12.09 09:45buy180.011861.181857.811866.64
362020.12.09 12:22s/l180.011857.811857.811866.64-3.37972.37
372020.12.09 13:30buy190.011860.241855.381868.10
382020.12.09 13:37s/l190.011855.381855.381868.10-4.86967.51
392020.12.09 15:45buy200.011861.661853.511874.84
402020.12.09 16:24s/l200.011853.511853.511874.84-8.15959.36
412020.12.09 23:45buy210.011839.361831.441852.18
422020.12.10 11:06s/l210.011831.441831.441852.18-9.23950.13
432020.12.10 14:30buy220.011837.621831.881846.90
442020.12.10 16:03t/p220.011846.901831.881846.909.28959.41
452020.12.11 03:30buy230.011838.871835.731843.95
462020.12.11 05:13s/l230.011835.731835.731843.95-3.14956.27
472020.12.11 06:15buy240.011837.261834.581841.60
482020.12.11 07:54s/l240.011834.581834.581841.60-2.68953.59
492020.12.11 08:45buy250.011836.931833.061843.19
502020.12.11 09:45s/l250.011833.061833.061843.19-3.87949.72
512020.12.11 11:30buy260.011836.171830.691845.03
522020.12.11 13:01s/l260.011830.691830.691845.03-5.48944.24
532020.12.11 14:00buy270.011833.331822.081851.53
542020.12.11 15:45buy280.011838.181829.271852.60
552020.12.14 04:45buy290.011837.461833.951843.14
562020.12.14 07:24s/l290.011833.951833.951843.14-3.51940.73
572020.12.14 10:24s/l280.011829.271829.271852.60-9.35931.38
582020.12.14 12:24s/l270.011822.081822.081851.53-11.69919.70
592020.12.14 16:00buy300.011833.081820.001854.24
602020.12.14 20:45buy310.011828.351825.321833.25
612020.12.14 21:54s/l310.011825.321825.321833.25-3.03916.67
622020.12.15 01:15buy320.011829.221827.371832.22
632020.12.15 01:39s/l320.011827.371827.371832.22-1.85914.82
642020.12.15 04:00buy330.011829.931824.801838.23
652020.12.15 07:37t/p330.011838.231824.801838.238.30923.12
662020.12.15 15:37t/p300.011854.241820.001854.2420.72943.84
672020.12.16 04:30buy340.011854.801850.781861.30
682020.12.16 10:45buy350.011860.661851.831874.94
692020.12.16 10:51t/p340.011861.301850.781861.306.50950.34
702020.12.16 15:22s/l350.011851.831851.831874.94-8.83941.51
712020.12.16 19:00buy360.011854.871851.871859.73
722020.12.16 19:25s/l360.011851.871851.871859.73-3.00938.51
732020.12.16 22:00buy370.011861.681841.081878.35
742020.12.17 05:15buy380.011864.961861.721870.20
752020.12.17 07:54t/p380.011870.201861.721870.205.24943.75
762020.12.17 10:24t/p370.011878.351841.081878.3515.36959.12
772020.12.18 01:00buy390.011884.901882.851888.22
782020.12.18 02:39s/l390.011882.851882.851888.22-2.05957.07
792020.12.18 06:15buy400.011883.041878.541890.32
802020.12.18 10:09s/l400.011878.541878.541890.32-4.50952.57
812020.12.18 13:45buy410.011880.781877.751885.68
822020.12.18 14:06t/p410.011885.681877.751885.684.90957.47
832020.12.18 20:00buy420.011884.341881.781888.48
842020.12.18 20:51s/l420.011881.781881.781888.48-2.56954.91
852020.12.21 01:30buy430.011884.501879.311892.90
862020.12.21 03:09t/p430.011892.901879.311892.908.40963.31
872020.12.21 15:45buy440.011883.161868.171907.42
882020.12.21 18:45buy450.011880.781873.551892.48
892020.12.22 01:15buy460.011881.401873.811893.68
902020.12.22 03:30buy470.011881.191874.821891.49
912020.12.22 07:45s/l470.011874.821874.821891.49-6.37956.94
922020.12.22 08:09s/l460.011873.811873.811893.68-7.59949.35
932020.12.22 08:09s/l450.011873.551873.551892.48-7.67941.68
942020.12.22 08:54s/l440.011868.171868.171907.42-15.43926.26
952020.12.22 12:15buy480.011874.671868.761884.23
962020.12.22 17:49s/l480.011868.761868.761884.23-5.91920.35
972020.12.22 21:33buy490.011864.301859.941871.36
982020.12.22 22:39s/l490.011859.941859.941871.36-4.36915.99
992020.12.23 03:00buy500.011864.321861.211869.36
1002020.12.23 09:04buy510.011866.311863.131871.45
1012020.12.23 10:54t/p500.011869.361861.211869.365.04921.03
1022020.12.23 11:09t/p510.011871.451863.131871.455.14926.17
1032020.12.23 15:45buy520.011869.151856.731889.25
1042020.12.24 02:00buy530.011873.011870.881876.45
1052020.12.24 03:24t/p530.011876.451870.881876.453.44929.61
1062020.12.24 08:45buy540.011876.601874.811879.50
1072020.12.24 10:19t/p540.011879.501874.811879.502.90932.51
1082020.12.24 16:00buy550.011874.511872.621877.57
1092020.12.24 16:09s/l550.011872.621872.621877.57-1.89930.62
1102020.12.28 03:00t/p520.011889.251856.731889.2517.92948.54
1112020.12.28 12:00buy560.011885.701880.681893.82
1122020.12.28 12:24s/l560.011880.681880.681893.82-5.02943.52
1132020.12.28 15:45buy570.011885.821872.031908.14
1142020.12.28 23:45s/l570.011872.031872.031908.14-13.79929.73
1152020.12.29 02:04buy580.011877.891871.171888.77
1162020.12.29 10:00buy590.011879.951874.881888.15
1172020.12.29 12:39s/l590.011874.881874.881888.15-5.07924.66
1182020.12.29 16:00buy600.011880.191873.451891.09
1192020.12.29 17:09s/l600.011873.451873.451891.09-6.74917.92
1202020.12.29 17:45buy610.011878.721870.361892.24
1212020.12.30 01:15buy620.011878.371877.131880.37
1222020.12.30 01:34s/l620.011877.131877.131880.37-1.24916.68
1232020.12.30 13:30buy630.011880.591877.181886.11
1242020.12.30 13:54s/l630.011877.181877.181886.11-3.41913.27
1252020.12.30 19:54t/p580.011888.771871.171888.7710.44923.71
1262020.12.30 22:51t/p610.011892.241870.361892.2413.08936.80
1272020.12.31 09:30buy640.011889.801885.361896.98
1282020.12.31 15:22t/p640.011896.981885.361896.987.18943.98
1292020.12.31 15:30buy650.011897.531892.301905.99
1302020.12.31 16:54s/l650.011892.301892.301905.99-5.23938.75
1312021.01.04 01:45buy660.011914.531884.871938.53
1322021.01.04 15:31t/p660.011938.531884.871938.5324.00962.75
1332021.01.04 20:15buy670.011942.881930.611962.74
1342021.01.05 05:45buy680.011942.141936.101951.92
1352021.01.05 16:16t/p680.011951.921936.101951.929.78972.53
1362021.01.05 18:45buy690.011949.061939.151965.10
1372021.01.06 01:22buy700.011951.581947.551958.10
1382021.01.06 03:24s/l700.011947.551947.551958.10-4.03968.50
1392021.01.06 08:30buy710.011944.911943.011947.99
1402021.01.06 09:09t/p710.011947.991943.011947.993.08971.58
1412021.01.06 14:36s/l690.011939.151939.151965.10-10.35961.23
1422021.01.06 14:39s/l670.011930.611930.611962.74-13.14948.09
1432021.01.06 21:30buy720.011914.031904.591929.31
1442021.01.07 07:30buy730.011918.341916.611921.14
1452021.01.07 07:30s/l730.011916.611916.611921.14-1.73946.36
1462021.01.07 15:30buy740.011918.691913.921926.41
1472021.01.07 15:46s/l740.011913.921913.921926.41-4.77941.59
1482021.01.07 20:15buy750.011914.051908.311923.33
1492021.01.08 06:37s/l750.011908.311908.311923.33-6.18935.42
1502021.01.08 09:54s/l720.011904.591904.591929.31-11.18924.24
1512021.01.08 13:45buy760.011894.341889.171902.70
1522021.01.08 14:34s/l760.011889.171889.171902.70-5.17919.07
1532021.01.08 23:00buy770.011848.061840.881859.68
1542021.01.11 03:00s/l770.011840.881840.881859.68-7.62911.45
1552021.01.11 07:00buy780.011834.441825.711848.56
1562021.01.11 08:33t/p780.011848.561825.711848.5614.12925.57
1572021.01.11 18:00buy790.011849.261830.631879.40
1582021.01.12 04:30buy800.011848.811839.871863.27
1592021.01.12 12:09t/p800.011863.271839.871863.2714.46940.03
1602021.01.12 20:15buy810.011844.121836.421856.58
1612021.01.12 21:31t/p810.011856.581836.421856.5812.46952.49
1622021.01.13 08:15buy820.011860.211856.961865.47
1632021.01.13 10:04s/l820.011856.961856.961865.47-3.25949.24
1642021.01.13 14:45buy830.011855.181851.341861.40
1652021.01.13 15:09s/l830.011851.341851.341861.40-3.84945.40
1662021.01.13 20:00buy840.011856.151852.421862.19
1672021.01.13 22:18s/l840.011852.421852.421862.19-3.73941.67
1682021.01.14 03:07close790.011849.771830.631879.40-1.67940.00
1692021.01.14 08:00buy850.011844.821837.821856.14
1702021.01.14 09:37s/l850.011837.821837.821856.14-7.00933.00
1712021.01.14 14:04buy860.011844.011837.041855.29
1722021.01.14 19:53t/p860.011855.291837.041855.2911.28944.28
1732021.01.14 23:04buy870.011848.091843.571855.41
1742021.01.15 02:15buy880.011848.991844.971855.49
1752021.01.15 10:45buy890.011852.821848.581859.68
1762021.01.15 11:39t/p870.011855.411843.571855.416.88951.17
1772021.01.15 11:39t/p880.011855.491844.971855.496.50957.67
1782021.01.15 13:52s/l890.011848.581848.581859.68-4.24953.43
1792021.01.15 21:45buy900.011829.491826.991833.53
1802021.01.15 22:07s/l900.011826.991826.991833.53-2.50950.93
1812021.01.18 04:45buy910.011829.611817.481849.23
1822021.01.18 13:15buy920.011837.471828.661851.73
1832021.01.18 15:00buy930.011835.971828.531848.01
1842021.01.19 08:30buy940.011839.951835.701846.83
1852021.01.19 14:55s/l940.011835.701835.701846.83-4.25946.68
1862021.01.19 18:15buy950.011842.161831.741859.02
1872021.01.20 04:08t/p930.011848.011828.531848.0111.17957.85
1882021.01.20 04:49t/p910.011849.231817.481849.2318.75976.60
1892021.01.20 08:06t/p920.011851.731828.661851.7313.39989.99
1902021.01.20 16:22t/p950.011859.021831.741859.0216.421006.41
1912021.01.20 16:30buy960.011860.281826.301887.77
1922021.01.21 05:00buy970.011872.001867.191879.78
1932021.01.21 09:39s/l970.011867.191867.191879.78-4.811001.60
1942021.01.21 13:00buy980.011870.471866.771876.45
1952021.01.21 14:54s/l980.011866.771866.771876.45-3.70997.90
1962021.01.21 19:39buy990.011864.711863.381866.87
1972021.01.21 20:52t/p990.011866.871863.381866.872.161000.06
1982021.01.22 11:15buy1000.011863.031858.371870.57
1992021.01.22 11:52s/l1000.011858.371858.371870.57-4.66995.40
2002021.01.22 17:00buy1010.011850.661834.621863.64
2012021.01.22 21:30close1010.011856.441834.621863.645.781001.18
2022021.01.22 21:30close960.011856.441826.301887.77-5.58995.60
2032021.01.25 02:45buy1020.011860.211854.601869.29
2042021.01.25 03:24s/l1020.011854.601854.601869.29-5.61989.99
2052021.01.25 07:15buy1030.011855.681853.281859.56
2062021.01.25 07:37s/l1030.011853.281853.281859.56-2.40987.59
2072021.01.25 11:21buy1040.011853.481851.441856.78
2082021.01.25 12:34t/p1040.011856.781851.441856.783.30990.89
2092021.01.25 20:30buy1050.011856.711854.551860.21
2102021.01.25 21:24s/l1050.011854.551854.551860.21-2.16988.73
2112021.01.26 01:30buy1060.011857.191854.101862.19
2122021.01.26 02:07s/l1060.011854.101854.101862.19-3.09985.64
2132021.01.26 13:19buy1070.011851.601848.211857.08
2142021.01.26 15:24t/p1070.011857.081848.211857.085.48991.12
2152021.01.26 22:45buy1080.011853.271849.031860.13
2162021.01.27 01:16s/l1080.011849.031849.031860.13-4.68986.44
2172021.01.27 02:00buy1090.011851.631848.691856.39
2182021.01.27 02:47s/l1090.011848.691848.691856.39-2.94983.50
2192021.01.27 07:15buy1100.011847.881845.011852.52
2202021.01.27 10:01t/p1100.011852.521845.011852.524.64988.14
2212021.01.27 17:15buy1110.011843.871828.841856.03
2222021.01.28 06:45buy1120.011838.361836.231841.80
2232021.01.28 07:53s/l1120.011836.231836.231841.80-2.13986.01
2242021.01.28 08:45buy1130.011838.361834.801844.12
2252021.01.28 09:09s/l1130.011834.801834.801844.12-3.56982.45
2262021.01.28 15:52t/p1110.011856.031828.841856.0310.85993.31
2272021.01.28 22:45buy1140.011843.301840.821847.32
2282021.01.28 23:01s/l1140.011840.821840.821847.32-2.48990.83
2292021.01.29 03:37buy1150.011843.901840.011850.20
2302021.01.29 06:15buy1160.011841.821841.241842.76
2312021.01.29 06:52t/p1160.011842.761841.241842.760.94991.77
2322021.01.29 08:54t/p1150.011850.201840.011850.206.30998.07
+
diff --git a/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 1.gif b/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 1.gif new file mode 100644 index 0000000..7a108b9 Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 1.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 1.htm b/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 1.htm new file mode 100644 index 0000000..9753015 --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 1.htm @@ -0,0 +1,95 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.06.28 23:45 (2020.01.01 - 2023.06.29)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=6; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.0031; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=252; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +xStarter="- X Signal Provider -"; enableXSignalling=true; +xR2R=1.5; xMaximumCandlesPerTrade=144; xShortCycleLength=14; xMediumCycleLength=20; xLongCycleLength=50; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xrR2R=2; xRMaximumCandlesPerTrade=252; xrOscillatorLength=7; xrFastLength=20; xrSlowLength=50; xrRangeMarketLength=50; xrSwingLength=7;
Bars in test61155Ticks modelled69617088Modelling quality40.15%
Mismatched charts errors30
Initial deposit1000.00SpreadCurrent (57)
Total net profit55.05Gross profit55.05Gross loss-0.00
Profit factorExpected payoff4.23
Absolute drawdown2.24Maximal drawdown23.46 (2.25%)Relative drawdown2.25% (23.46)
Total trades13Short positions (won %)0 (0.00%)Long positions (won %)13 (100.00%)
Profit trades (% of total)13 (100.00%)Loss trades (% of total)0 (0.00%)
Largestprofit trade5.42loss trade-0.00
Averageprofit trade4.23loss trade-0.00
Maximumconsecutive wins (profit in money)13 (55.05)consecutive losses (loss in money)0 (-0.00)
Maximalconsecutive profit (count of wins)55.05 (13)consecutive loss (count of losses)-0.00 (0)
Averageconsecutive wins13consecutive losses0
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12021.01.06 02:00buy10.011950.770.001954.67
22021.01.06 03:09t/p10.011954.670.001954.673.901003.90
32021.04.08 14:00buy20.011746.300.001751.37
42021.04.08 16:07t/p20.011751.370.001751.375.071008.97
52021.04.21 04:30buy30.011779.880.001784.28
62021.04.21 06:09t/p30.011784.280.001784.284.401013.37
72021.07.14 12:00buy40.011814.480.001818.44
82021.07.14 15:04t/p40.011818.440.001818.443.961017.33
92021.10.01 23:45buy50.011760.130.001763.70
102021.10.04 01:22t/p50.011763.700.001763.703.131020.46
112021.10.21 09:45buy60.011786.730.001792.19
122021.10.22 09:37t/p60.011792.190.001792.195.021025.49
132021.12.21 14:15buy70.011797.690.001799.57
142021.12.21 15:00t/p70.011799.570.001799.571.881027.37
152022.07.29 21:30buy80.011766.250.001771.53
162022.08.01 12:55t/p80.011771.530.001771.534.841032.21
172022.09.05 04:45buy90.011711.750.001717.06
182022.09.06 03:23t/p90.011717.060.001717.064.871037.09
192022.09.21 13:00buy100.011673.720.001678.33
202022.09.21 21:33t/p100.011678.330.001678.334.611041.70
212022.11.15 04:45buy110.011771.860.001777.28
222022.11.15 09:31t/p110.011777.280.001777.285.421047.12
232022.11.30 10:00buy120.011755.480.001758.74
242022.11.30 10:52t/p120.011758.740.001758.743.261050.38
252023.02.09 13:15buy130.011884.520.001889.19
262023.02.09 15:58t/p130.011889.190.001889.194.671055.05
+
diff --git a/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 2.gif b/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 2.gif new file mode 100644 index 0000000..93e3b74 Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 2.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 2.htm b/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 2.htm new file mode 100644 index 0000000..62ee295 --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 2.htm @@ -0,0 +1,84 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.06.28 23:45 (2020.01.01 - 2023.06.29)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=2; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.0003; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.4; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +xR2R=2.5; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xrR2R=2; xRMaximumCandlesPerTrade=252; xrOscillatorLength=7; xrFastLength=20; xrSlowLength=50; xrRangeMarketLength=50; xrSwingLength=7;
Bars in test61155Ticks modelled69617088Modelling quality40.15%
Mismatched charts errors30
Initial deposit1000.00SpreadCurrent (59)
Total net profit1812.58Gross profit1812.58Gross loss-0.00
Profit factorExpected payoff226.57
Absolute drawdown290.70Maximal drawdown420.90 (37.24%)Relative drawdown37.24% (420.90)
Total trades8Short positions (won %)0 (0.00%)Long positions (won %)8 (100.00%)
Profit trades (% of total)8 (100.00%)Loss trades (% of total)0 (0.00%)
Largestprofit trade270.90loss trade-0.00
Averageprofit trade226.57loss trade-0.00
Maximumconsecutive wins (profit in money)8 (1812.58)consecutive losses (loss in money)0 (-0.00)
Maximalconsecutive profit (count of wins)1812.58 (8)consecutive loss (count of losses)-0.00 (0)
Averageconsecutive wins8consecutive losses0
+Graph
+ + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12021.01.06 02:00buy10.301950.790.001957.29
22021.01.06 11:54t/p10.301957.290.001957.29195.001195.00
32021.04.08 14:00buy20.301746.320.001754.77
42021.04.08 16:36t/p20.301754.770.001754.77253.501448.50
52021.04.21 04:30buy30.301779.900.001787.23
62021.04.21 09:52t/p30.301787.230.001787.23219.901668.40
72021.07.14 12:00buy40.301814.500.001821.10
82021.07.14 15:06t/p40.301821.100.001821.10198.001866.40
92021.10.21 09:45buy50.301786.750.001795.85
102021.10.22 15:19t/p50.301795.850.001795.85259.942126.34
112022.09.05 04:45buy60.301711.770.001720.62
122022.09.06 03:32t/p60.301720.620.001720.62252.442378.78
132022.11.15 04:45buy70.301771.880.001780.91
142022.11.15 09:46t/p70.301780.910.001780.91270.902649.68
152022.11.30 10:00buy80.301755.500.001760.93
162022.11.30 11:08t/p80.301760.930.001760.93162.902812.58
+
diff --git a/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 3 - Short.gif b/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 3 - Short.gif new file mode 100644 index 0000000..e7e420b Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 3 - Short.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 3 - Short.htm b/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 3 - Short.htm new file mode 100644 index 0000000..3d0b7dc --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 3 - Short.htm @@ -0,0 +1,130 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.06.28 23:45 (2020.01.01 - 2023.06.29)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=2; allowTrade=true; +allowLongTrades=false; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +xR2R=2.5; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xrR2R=2; xRMaximumCandlesPerTrade=252; xrOscillatorLength=7; xrFastLength=20; xrSlowLength=50; xrRangeMarketLength=50; xrSwingLength=7;
Bars in test61155Ticks modelled69617088Modelling quality40.15%
Mismatched charts errors30
Initial deposit1000.00SpreadCurrent (50)
Total net profit74.65Gross profit120.83Gross loss-46.18
Profit factor2.62Expected payoff2.41
Absolute drawdown14.66Maximal drawdown31.19 (3.07%)Relative drawdown3.07% (31.19)
Total trades31Short positions (won %)31 (90.32%)Long positions (won %)0 (0.00%)
Profit trades (% of total)28 (90.32%)Loss trades (% of total)3 (9.68%)
Largestprofit trade8.52loss trade-29.37
Averageprofit trade4.32loss trade-15.39
Maximumconsecutive wins (profit in money)14 (65.09)consecutive losses (loss in money)1 (-29.37)
Maximalconsecutive profit (count of wins)65.09 (14)consecutive loss (count of losses)-29.37 (1)
Averageconsecutive wins9consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.18 02:30sell10.011884.040.001881.04
22020.12.18 03:09t/p10.011881.040.001881.043.001003.00
32021.01.21 02:45sell20.011869.150.001862.63
42021.01.21 15:54t/p20.011862.630.001862.636.521009.52
52021.03.09 22:15sell30.011716.740.001710.17
62021.03.10 08:09t/p30.011710.170.001710.176.781016.30
72021.04.01 03:45sell40.011706.320.001699.80
82021.04.06 07:54close40.011736.320.001699.80-29.37986.93
92021.04.15 21:15sell50.011767.210.001764.56
102021.04.15 22:39t/p50.011764.560.001764.562.65989.58
112021.06.03 23:15sell60.011870.990.001865.94
122021.06.04 03:45sell70.011869.320.001862.92
132021.06.04 04:49t/p60.011865.940.001865.945.26994.84
142021.06.04 04:52t/p70.011862.920.001862.926.401001.24
152021.06.17 08:00sell80.011821.330.001815.18
162021.06.17 09:07t/p80.011815.180.001815.186.151007.39
172021.06.18 08:45sell90.011784.490.001778.54
182021.06.18 15:24t/p90.011778.540.001778.545.951013.34
192021.11.23 05:30sell100.011808.910.001803.19
202021.11.23 09:03t/p100.011803.190.001803.195.721019.06
212021.12.15 04:45sell110.011771.980.001769.33
222021.12.15 07:24t/p110.011769.330.001769.332.651021.71
232022.02.14 13:30sell120.011855.860.001851.26
242022.02.15 13:54t/p120.011851.260.001851.264.811026.52
252022.03.14 08:45sell130.011975.330.001973.43
262022.03.14 09:24t/p130.011973.430.001973.431.901028.42
272022.03.16 05:15sell140.011919.680.001911.16
282022.03.16 16:09t/p140.011911.160.001911.168.521036.94
292022.05.17 05:00sell150.011826.120.001823.95
302022.05.17 06:08t/p150.011823.950.001823.952.171039.11
312022.07.06 01:05sell160.011766.830.001763.96
322022.07.06 08:38t/p160.011763.960.001763.962.871041.98
332022.07.07 01:45sell170.011738.940.001734.79
342022.07.07 05:30sell180.011739.930.001734.46
352022.07.08 10:43t/p170.011734.790.001734.794.361046.34
362022.07.08 10:43t/p180.011734.460.001734.465.681052.02
372022.08.08 22:30sell190.011787.280.001782.58
382022.08.11 05:00close190.011788.480.001782.58-0.151051.87
392022.10.10 23:00sell200.011668.780.001663.88
402022.10.11 05:13t/p200.011663.880.001663.885.111056.98
412022.11.09 07:30sell210.011708.410.001706.31
422022.11.09 12:07t/p210.011706.310.001706.312.101059.08
432022.11.15 15:00sell220.011775.140.001769.87
442022.11.15 16:48t/p220.011769.870.001769.875.271064.35
452023.01.09 07:30sell230.011876.700.001874.15
462023.01.09 09:50t/p230.011874.150.001874.152.551066.90
472023.02.02 09:00sell240.011951.910.001946.44
482023.02.02 15:52t/p240.011946.440.001946.445.471072.37
492023.02.03 05:45sell250.011916.370.001914.42
502023.02.03 06:23t/p250.011914.420.001914.421.951074.32
512023.03.31 07:15sell260.011981.510.001980.14
522023.03.31 08:07t/p260.011980.140.001980.141.371075.69
532023.04.04 02:00sell270.011983.600.001979.28
542023.04.04 04:50t/p270.011979.280.001979.284.321080.01
552023.04.05 01:45sell280.012020.810.002019.39
562023.04.05 04:15sell290.012020.920.002016.45
572023.04.05 17:11t/p280.012019.390.002019.391.421081.43
582023.04.05 17:32t/p290.012016.450.002016.454.471085.90
592023.05.02 21:45sell300.012014.740.002009.54
602023.05.03 15:15t/p300.012009.540.002009.545.411091.31
612023.05.08 01:45sell310.012014.730.002007.43
622023.05.10 07:15close310.012031.810.002007.43-16.661074.65
+
diff --git a/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 4 - Short Long 0.3 0.4.gif b/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 4 - Short Long 0.3 0.4.gif new file mode 100644 index 0000000..0cd8541 Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 4 - Short Long 0.3 0.4.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 4 - Short Long 0.3 0.4.htm b/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 4 - Short Long 0.3 0.4.htm new file mode 100644 index 0000000..cc169a5 --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/X/StrategyTester 4 - Short Long 0.3 0.4.htm @@ -0,0 +1,162 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.06.28 23:45 (2020.01.01 - 2023.06.29)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=2; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.0003; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.4; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +xR2R=2.5; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xrR2R=2; xRMaximumCandlesPerTrade=252; xrOscillatorLength=7; xrFastLength=20; xrSlowLength=50; xrRangeMarketLength=50; xrSwingLength=7;
Bars in test61155Ticks modelled69617088Modelling quality40.15%
Mismatched charts errors30
Initial deposit1000.00SpreadCurrent (56)
Total net profit4615.79Gross profit6210.29Gross loss-1594.49
Profit factor3.89Expected payoff98.21
Absolute drawdown199.80Maximal drawdown759.90 (18.60%)Relative drawdown34.47% (420.90)
Total trades47Short positions (won %)33 (87.88%)Long positions (won %)14 (100.00%)
Profit trades (% of total)43 (91.49%)Loss trades (% of total)4 (8.51%)
Largestprofit trade270.90loss trade-400.20
Averageprofit trade144.43loss trade-398.62
Maximumconsecutive wins (profit in money)18 (2440.63)consecutive losses (loss in money)1 (-400.20)
Maximalconsecutive profit (count of wins)2440.63 (18)consecutive loss (count of losses)-400.20 (1)
Averageconsecutive wins11consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.18 02:30sell10.301884.040.001881.04
22020.12.18 03:10t/p10.301881.040.001881.0490.001090.00
32021.01.06 02:00buy20.301950.760.001957.26
42021.01.06 11:54t/p20.301957.260.001957.26195.001285.00
52021.01.21 02:45sell30.301869.150.001862.63
62021.01.21 15:54t/p30.301862.630.001862.63195.601480.60
72021.03.09 22:15sell40.301716.740.001710.17
82021.03.10 08:09t/p40.301710.170.001710.17203.411684.01
92021.04.01 03:45sell50.301706.320.001699.80
102021.04.01 10:24close50.301719.660.001699.80-400.201283.81
112021.04.08 14:00buy60.301746.290.001754.74
122021.04.08 16:36t/p60.301754.740.001754.74253.501537.31
132021.04.15 21:15sell70.301767.210.001764.56
142021.04.15 22:39t/p70.301764.560.001764.5679.501616.81
152021.04.21 04:30buy80.301779.870.001787.20
162021.04.21 09:51t/p80.301787.200.001787.20219.901836.71
172021.05.04 23:15sell90.301779.150.001777.65
182021.05.05 03:09t/p90.301777.650.001777.6551.311888.01
192021.05.07 13:45sell100.301820.100.001817.98
202021.05.07 15:07t/p100.301817.980.001817.9863.601951.61
212021.06.03 23:15sell110.301870.990.001865.94
222021.06.04 04:49t/p110.301865.940.001865.94157.812109.42
232021.06.17 08:00sell120.301821.330.001815.18
242021.06.17 09:07t/p120.301815.180.001815.18184.502293.92
252021.06.18 08:45sell130.301784.490.001778.54
262021.06.18 15:24t/p130.301778.540.001778.54178.502472.42
272021.07.14 12:00buy140.301814.470.001821.07
282021.07.14 15:05t/p140.301821.070.001821.07198.002670.42
292021.08.26 13:45buy150.301787.220.001794.00
302021.08.26 17:31t/p150.301794.000.001794.00203.402873.82
312021.10.21 09:45buy160.301786.720.001795.82
322021.10.22 15:19t/p160.301795.820.001795.82259.943133.76
332021.11.23 05:30sell170.301808.910.001803.19
342021.11.23 10:49t/p170.301803.190.001803.19171.603305.36
352021.12.15 04:45sell180.301771.980.001769.33
362021.12.15 07:24t/p180.301769.330.001769.3379.503384.86
372022.02.09 11:30buy190.301827.840.001831.02
382022.02.09 15:07t/p190.301831.020.001831.0295.403480.26
392022.02.14 13:30sell200.301855.860.001851.26
402022.02.14 17:18close200.301869.200.001851.26-400.203080.06
412022.03.14 08:45sell210.301975.330.001973.43
422022.03.14 09:24t/p210.301973.430.001973.4357.003137.06
432022.03.16 05:15sell220.301919.680.001911.16
442022.03.16 16:09t/p220.301911.160.001911.16255.603392.66
452022.05.17 05:00sell230.301826.120.001823.95
462022.05.17 06:08t/p230.301823.950.001823.9565.103457.76
472022.06.24 05:00sell240.301823.760.001820.54
482022.06.24 16:00t/p240.301820.540.001820.5496.603554.36
492022.07.06 01:05sell250.301766.830.001763.96
502022.07.06 08:38t/p250.301763.960.001763.9686.103640.46
512022.07.07 01:45sell260.301738.940.001734.79
522022.07.08 10:43t/p260.301734.790.001734.79130.813771.26
532022.08.01 01:30buy270.301764.510.001771.11
542022.08.01 12:53t/p270.301771.110.001771.11198.003969.26
552022.08.08 22:30sell280.301787.280.001782.58
562022.08.09 16:33close280.301800.620.001782.58-393.893575.37
572022.08.22 14:15buy290.301735.850.001741.55
582022.08.23 11:20t/p290.301741.550.001741.55157.943733.31
592022.09.05 04:45buy300.301711.740.001720.59
602022.09.06 03:32t/p300.301720.590.001720.59252.443985.74
612022.10.10 23:00sell310.301668.780.001663.88
622022.10.11 05:13t/p310.301663.880.001663.88153.314139.05
632022.11.09 07:30sell320.301708.410.001706.31
642022.11.09 12:07t/p320.301706.310.001706.3163.004202.05
652022.11.15 04:45buy330.301771.850.001780.88
662022.11.15 09:46t/p330.301780.880.001780.88270.904472.95
672022.11.15 15:00sell340.301775.140.001769.87
682022.11.15 16:48t/p340.301769.870.001769.87158.104631.05
692022.11.21 23:45buy350.301738.480.001741.76
702022.11.22 03:03t/p350.301741.760.001741.7685.344716.39
712022.11.30 10:00buy360.301755.470.001760.90
722022.11.30 11:08t/p360.301760.900.001760.90162.904879.29
732023.01.09 07:30sell370.301876.700.001874.15
742023.01.09 09:51t/p370.301874.150.001874.1576.504955.79
752023.01.20 09:00buy380.301926.900.001935.08
762023.01.20 10:07t/p380.301935.080.001935.08245.405201.19
772023.02.02 09:00sell390.301951.910.001946.44
782023.02.02 15:52t/p390.301946.440.001946.44164.105365.29
792023.02.03 05:45sell400.301916.370.001914.42
802023.02.03 06:23t/p400.301914.420.001914.4258.505423.79
812023.03.21 07:45sell410.301981.970.001978.67
822023.03.21 08:22t/p410.301978.670.001978.6799.005522.79
832023.03.31 07:15sell420.301981.510.001980.14
842023.03.31 08:08t/p420.301980.140.001980.1441.105563.89
852023.04.04 02:00sell430.301983.600.001979.28
862023.04.04 04:54t/p430.301979.280.001979.28129.605693.49
872023.04.05 01:45sell440.302020.810.002019.39
882023.04.05 17:11t/p440.302019.390.002019.3942.605736.09
892023.04.14 07:30sell450.302044.780.002040.86
902023.04.14 08:38t/p450.302040.860.002040.86117.605853.69
912023.05.02 21:45sell460.302014.740.002009.54
922023.05.03 15:15t/p460.302009.540.002009.54162.316015.99
932023.05.08 01:45sell470.302014.730.002007.43
942023.05.08 18:29close470.302028.070.002007.43-400.205615.79
+
diff --git a/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 1.gif b/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 1.gif new file mode 100644 index 0000000..bf203ae Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 1.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 1.htm b/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 1.htm new file mode 100644 index 0000000..c94c15d --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 1.htm @@ -0,0 +1,183 @@ + + + + Strategy Tester: x-saherelm.xr.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.xr.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.07.21 23:45 (2020.01.01 - 2023.07.22)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=50; swingLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=252; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +
Bars in test62709Ticks modelled71719330Modelling qualityn/a
Mismatched charts errors777
Initial deposit1000.00SpreadCurrent (60)
Total net profit64.36Gross profit198.76Gross loss-134.40
Profit factor1.48Expected payoff1.11
Absolute drawdown9.15Maximal drawdown38.61 (3.57%)Relative drawdown3.57% (38.61)
Total trades58Short positions (won %)0 (0.00%)Long positions (won %)58 (58.62%)
Profit trades (% of total)34 (58.62%)Loss trades (% of total)24 (41.38%)
Largestprofit trade14.58loss trade-15.38
Averageprofit trade5.85loss trade-5.60
Maximumconsecutive wins (profit in money)4 (23.01)consecutive losses (loss in money)3 (-26.09)
Maximalconsecutive profit (count of wins)23.01 (4)consecutive loss (count of losses)-26.09 (3)
Averageconsecutive wins2consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.03 23:30buy10.011841.440.001845.90
22020.12.04 15:31t/p10.011845.900.001845.904.021004.02
32020.12.08 18:30buy20.011870.350.001886.13
42020.12.09 05:19close20.011864.070.001886.13-6.72997.31
52020.12.30 03:45buy30.011883.290.001893.75
62020.12.30 10:00close30.011878.490.001893.75-4.80992.51
72020.12.30 18:00buy40.011885.860.001895.62
82020.12.31 02:15t/p40.011895.620.001895.628.451000.96
92021.01.05 11:30buy50.011944.710.001954.49
102021.01.06 03:09t/p50.011954.490.001954.499.341010.31
112021.04.05 17:30buy60.011729.420.001742.62
122021.04.05 22:00close60.011725.680.001742.62-3.741006.57
132021.04.19 06:15buy70.011778.720.001785.24
142021.04.19 07:15close70.011776.750.001785.24-1.971004.60
152021.04.26 21:00buy80.011780.010.001781.77
162021.04.26 23:39t/p80.011781.770.001781.771.761006.36
172021.05.18 23:45buy90.011870.210.001872.99
182021.05.19 05:00close90.011867.630.001872.99-3.021003.34
192021.05.20 08:15buy100.011876.090.001877.07
202021.05.20 08:30t/p100.011877.070.001877.070.981004.32
212021.05.21 11:30buy110.011876.530.001882.65
222021.05.21 15:21t/p110.011882.650.001882.656.121010.44
232021.05.24 19:15buy120.011884.010.001887.27
242021.05.25 01:15close120.011880.910.001887.27-3.541006.91
252021.05.25 10:45buy130.011884.160.001898.74
262021.05.25 21:06t/p130.011898.740.001898.7414.581021.49
272021.06.28 20:30buy140.011780.510.001785.35
282021.06.28 21:15close140.011778.020.001785.35-2.491019.00
292021.07.06 04:15buy150.011792.940.001796.10
302021.07.06 04:53t/p150.011796.100.001796.103.161022.16
312021.07.09 17:45buy160.011806.390.001814.91
322021.07.12 07:16close160.011801.870.001814.91-4.961017.20
332021.07.12 19:30buy170.011805.330.001808.45
342021.07.13 04:34t/p170.011808.450.001808.452.681019.89
352021.08.12 23:00buy180.011753.790.001757.21
362021.08.13 09:09t/p180.011757.210.001757.212.981022.87
372021.09.01 22:30buy190.011815.330.001820.69
382021.09.02 02:45close190.011813.220.001820.69-3.421019.45
392021.09.03 05:15buy200.011813.490.001819.35
402021.09.03 15:34t/p200.011819.350.001819.355.861025.31
412021.09.29 06:00buy210.011740.530.001751.43
422021.09.29 16:24close210.011736.210.001751.43-4.321020.99
432021.11.16 04:45buy220.011867.860.001877.40
442021.11.16 09:45close220.011863.300.001877.40-4.561016.43
452021.12.07 04:30buy230.011781.010.001785.23
462021.12.07 05:45close230.011778.500.001785.23-2.511013.92
472021.12.07 20:30buy240.011784.430.001788.51
482021.12.08 04:07t/p240.011788.510.001788.513.641017.57
492021.12.28 08:15buy250.011813.150.001819.37
502021.12.28 15:37t/p250.011819.370.001819.376.221023.79
512022.01.10 21:30buy260.011801.220.001805.98
522022.01.11 04:24t/p260.011805.980.001805.984.321028.11
532022.01.19 11:15buy270.011816.130.001824.95
542022.01.19 15:54t/p270.011824.950.001824.958.821036.93
552022.01.24 23:15buy280.011843.380.001853.74
562022.01.25 11:04close280.011838.270.001853.74-5.551031.39
572022.01.31 11:30buy290.011791.280.001798.92
582022.01.31 16:39t/p290.011798.920.001798.927.641039.03
592022.02.16 09:30buy300.011856.110.001860.85
602022.02.16 15:00close300.011852.740.001860.85-3.371035.66
612022.03.03 22:15buy310.011937.410.001946.73
622022.03.04 02:36t/p310.011946.730.001946.738.881044.54
632022.03.04 13:00buy320.011947.630.001961.75
642022.03.04 18:09t/p320.011961.750.001961.7514.121058.66
652022.03.11 21:30buy330.011986.950.001999.25
662022.03.14 00:45close330.011972.860.001999.25-14.531044.14
672022.03.24 13:30buy340.011946.500.001957.42
682022.03.24 14:03t/p340.011957.420.001957.4210.921055.06
692022.04.05 16:15buy350.011935.270.001956.63
702022.04.05 18:45close350.011925.680.001956.63-9.591045.47
712022.04.13 08:30buy360.011969.860.001973.40
722022.04.13 11:19t/p360.011973.400.001973.403.541049.01
732022.05.20 09:45buy370.011848.340.001859.62
742022.05.20 16:30close370.011840.610.001859.62-7.731041.28
752022.05.23 01:15buy380.011845.310.001848.55
762022.05.23 02:07t/p380.011848.550.001848.553.241044.52
772022.06.08 15:15buy390.011851.320.001858.82
782022.06.08 18:07t/p390.011858.820.001858.827.501052.02
792022.07.05 02:15buy400.011810.010.001814.79
802022.07.05 10:30close400.011806.730.001814.79-3.281048.74
812022.10.26 07:45buy410.011656.860.001658.96
822022.10.26 08:41t/p410.011658.960.001658.962.101050.84
832022.10.27 08:45buy420.011669.970.001683.09
842022.10.27 09:45close420.011661.850.001683.09-8.121042.72
852022.11.02 04:00buy430.011650.460.001653.36
862022.11.02 10:00t/p430.011653.360.001653.362.901045.62
872022.11.14 17:45buy440.011770.180.001784.24
882022.11.15 08:45close440.011769.440.001784.24-1.181044.44
892022.11.30 05:45buy450.011754.150.001759.19
902022.11.30 10:57t/p450.011759.190.001759.195.041049.48
912023.01.11 06:30buy460.011877.620.001882.84
922023.01.11 07:37t/p460.011882.840.001882.845.221054.70
932023.02.09 05:00buy470.011879.530.001889.99
942023.02.09 16:01t/p470.011889.990.001889.9910.461065.16
952023.02.16 21:30buy480.011843.520.001847.54
962023.02.17 01:15close480.011835.010.001847.54-8.951056.22
972023.02.22 05:15buy490.011837.180.001840.68
982023.02.22 10:03t/p490.011840.680.001840.683.501059.72
992023.03.28 17:00buy500.011963.690.001968.77
1002023.03.28 17:57t/p500.011968.770.001968.775.081064.80
1012023.03.30 10:45buy510.011969.560.001976.42
1022023.03.30 19:01t/p510.011976.420.001976.426.861071.66
1032023.04.26 13:30buy520.012000.140.002005.44
1042023.04.26 16:24t/p520.012005.440.002005.445.301076.96
1052023.04.27 06:00buy530.011999.160.002014.50
1062023.04.27 15:45close530.011983.780.002014.50-15.381061.58
1072023.05.15 19:45buy540.012020.300.002031.78
1082023.05.15 22:00close540.012014.590.002031.78-5.711055.87
1092023.06.09 17:30buy550.011967.630.001988.83
1102023.06.09 18:30close550.011962.630.001988.83-5.001050.87
1112023.06.13 03:15buy560.011961.000.001966.36
1122023.06.13 15:30t/p560.011966.360.001966.365.361056.23
1132023.07.12 03:45buy570.011936.100.001941.76
1142023.07.12 15:30t/p570.011941.760.001941.765.661061.89
1152023.07.19 23:00buy580.011978.780.001982.56
1162023.07.20 04:30t/p580.011982.560.001982.562.471064.36
+
diff --git a/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 2.gif b/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 2.gif new file mode 100644 index 0000000..e8b04be Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 2.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 2.htm b/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 2.htm new file mode 100644 index 0000000..e26147c --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 2.htm @@ -0,0 +1,172 @@ + + + + Strategy Tester: x-saherelm.xr.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.xr.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.07.21 23:45 (2020.01.01 - 2023.07.22)
ModelEvery tick (the most precise method based on all available least timeframes)
Bars in test62709Ticks modelled71719330Modelling qualityn/a
Mismatched charts errors777
Initial deposit1000.00SpreadCurrent (60)
Total net profit1287.21Gross profit3975.20Gross loss-2687.99
Profit factor1.48Expected payoff22.19
Absolute drawdown183.02Maximal drawdown772.20 (29.49%)Relative drawdown29.49% (772.20)
Total trades58Short positions (won %)0 (0.00%)Long positions (won %)58 (58.62%)
Profit trades (% of total)34 (58.62%)Loss trades (% of total)24 (41.38%)
Largestprofit trade291.60loss trade-307.60
Averageprofit trade116.92loss trade-112.00
Maximumconsecutive wins (profit in money)4 (460.18)consecutive losses (loss in money)3 (-521.80)
Maximalconsecutive profit (count of wins)460.18 (4)consecutive loss (count of losses)-521.80 (3)
Averageconsecutive wins2consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.03 23:30buy10.201841.440.001845.90
22020.12.04 15:31t/p10.201845.900.001845.9080.491080.49
32020.12.08 18:30buy20.201870.350.001886.13
42020.12.09 05:19close20.201864.070.001886.13-134.31946.18
52020.12.30 03:45buy30.201883.290.001893.75
62020.12.30 10:00close30.201878.490.001893.75-96.00850.18
72020.12.30 18:00buy40.201885.860.001895.62
82020.12.31 02:15t/p40.201895.620.001895.62169.081019.26
92021.01.05 11:30buy50.201944.710.001954.49
102021.01.06 03:09t/p50.201954.490.001954.49186.891206.15
112021.04.05 17:30buy60.201729.420.001742.62
122021.04.05 22:00close60.201725.680.001742.62-74.801131.35
132021.04.19 06:15buy70.201778.720.001785.24
142021.04.19 07:15close70.201776.750.001785.24-39.401091.95
152021.04.26 21:00buy80.201780.010.001781.77
162021.04.26 23:39t/p80.201781.770.001781.7735.201127.15
172021.05.18 23:45buy90.201870.210.001872.99
182021.05.19 05:00close90.201867.630.001872.99-60.311066.84
192021.05.20 08:15buy100.201876.090.001877.07
202021.05.20 08:30t/p100.201877.070.001877.0719.601086.44
212021.05.21 11:30buy110.201876.530.001882.65
222021.05.21 15:21t/p110.201882.650.001882.65122.401208.84
232021.05.24 19:15buy120.201884.010.001887.27
242021.05.25 01:15close120.201880.910.001887.27-70.711138.14
252021.05.25 10:45buy130.201884.160.001898.74
262021.05.25 21:06t/p130.201898.740.001898.74291.601429.74
272021.06.28 20:30buy140.201780.510.001785.35
282021.06.28 21:15close140.201778.020.001785.35-49.801379.94
292021.07.06 04:15buy150.201792.940.001796.10
302021.07.06 04:53t/p150.201796.100.001796.1063.201443.14
312021.07.09 17:45buy160.201806.390.001814.91
322021.07.12 07:16close160.201801.870.001814.91-99.111344.03
332021.07.12 19:30buy170.201805.330.001808.45
342021.07.13 04:34t/p170.201808.450.001808.4553.691397.72
352021.08.12 23:00buy180.201753.790.001757.21
362021.08.13 09:09t/p180.201757.210.001757.2159.691457.41
372021.09.01 22:30buy190.201815.330.001820.69
382021.09.02 02:45close190.201813.220.001820.69-68.321389.09
392021.09.03 05:15buy200.201813.490.001819.35
402021.09.03 15:34t/p200.201819.350.001819.35117.201506.29
412021.09.29 06:00buy210.201740.530.001751.43
422021.09.29 16:24close210.201736.210.001751.43-86.401419.89
432021.11.16 04:45buy220.201867.860.001877.40
442021.11.16 09:45close220.201863.300.001877.40-91.201328.69
452021.12.07 04:30buy230.201781.010.001785.23
462021.12.07 05:45close230.201778.500.001785.23-50.201278.49
472021.12.07 20:30buy240.201784.430.001788.51
482021.12.08 04:07t/p240.201788.510.001788.5172.891351.38
492021.12.28 08:15buy250.201813.150.001819.37
502021.12.28 15:37t/p250.201819.370.001819.37124.401475.78
512022.01.10 21:30buy260.201801.220.001805.98
522022.01.11 04:24t/p260.201805.980.001805.9886.491562.27
532022.01.19 11:15buy270.201816.130.001824.95
542022.01.19 15:54t/p270.201824.950.001824.95176.401738.67
552022.01.24 23:15buy280.201843.380.001853.74
562022.01.25 11:04close280.201838.270.001853.74-110.911627.76
572022.01.31 11:30buy290.201791.280.001798.92
582022.01.31 16:39t/p290.201798.920.001798.92152.801780.56
592022.02.16 09:30buy300.201856.110.001860.85
602022.02.16 15:00close300.201852.740.001860.85-67.401713.16
612022.03.03 22:15buy310.201937.410.001946.73
622022.03.04 02:36t/p310.201946.730.001946.73177.691890.86
632022.03.04 13:00buy320.201947.630.001961.75
642022.03.04 18:09t/p320.201961.750.001961.75282.402173.26
652022.03.11 21:30buy330.201986.950.001999.25
662022.03.14 00:45close330.201972.860.001999.25-290.511882.75
672022.03.24 13:30buy340.201946.500.001957.42
682022.03.24 14:03t/p340.201957.420.001957.42218.402101.15
692022.04.05 16:15buy350.201935.270.001956.63
702022.04.05 18:45close350.201925.680.001956.63-191.801909.35
712022.04.13 08:30buy360.201969.860.001973.40
722022.04.13 11:19t/p360.201973.400.001973.4070.801980.15
732022.05.20 09:45buy370.201848.340.001859.62
742022.05.20 16:30close370.201840.610.001859.62-154.601825.55
752022.05.23 01:15buy380.201845.310.001848.55
762022.05.23 02:07t/p380.201848.550.001848.5564.801890.35
772022.06.08 15:15buy390.201851.320.001858.82
782022.06.08 18:07t/p390.201858.820.001858.82150.002040.35
792022.07.05 02:15buy400.201810.010.001814.79
802022.07.05 10:30close400.201806.730.001814.79-65.601974.75
812022.10.26 07:45buy410.201656.860.001658.96
822022.10.26 08:41t/p410.201658.960.001658.9642.002016.75
832022.10.27 08:45buy420.201669.970.001683.09
842022.10.27 09:45close420.201661.850.001683.09-162.401854.35
852022.11.02 04:00buy430.201650.460.001653.36
862022.11.02 10:00t/p430.201653.360.001653.3658.001912.35
872022.11.14 17:45buy440.201770.180.001784.24
882022.11.15 08:45close440.201769.440.001784.24-23.511888.84
892022.11.30 05:45buy450.201754.150.001759.19
902022.11.30 10:57t/p450.201759.190.001759.19100.801989.64
912023.01.11 06:30buy460.201877.620.001882.84
922023.01.11 07:37t/p460.201882.840.001882.84104.402094.04
932023.02.09 05:00buy470.201879.530.001889.99
942023.02.09 16:01t/p470.201889.990.001889.99209.202303.24
952023.02.16 21:30buy480.201843.520.001847.54
962023.02.17 01:15close480.201835.010.001847.54-178.912124.33
972023.02.22 05:15buy490.201837.180.001840.68
982023.02.22 10:03t/p490.201840.680.001840.6870.002194.33
992023.03.28 17:00buy500.201963.690.001968.77
1002023.03.28 17:57t/p500.201968.770.001968.77101.602295.93
1012023.03.30 10:45buy510.201969.560.001976.42
1022023.03.30 19:01t/p510.201976.420.001976.42137.202433.13
1032023.04.26 13:30buy520.202000.140.002005.44
1042023.04.26 16:24t/p520.202005.440.002005.44106.002539.13
1052023.04.27 06:00buy530.201999.160.002014.50
1062023.04.27 15:45close530.201983.780.002014.50-307.602231.53
1072023.05.15 19:45buy540.202020.300.002031.78
1082023.05.15 22:00close540.202014.590.002031.78-114.202117.33
1092023.06.09 17:30buy550.201967.630.001988.83
1102023.06.09 18:30close550.201962.630.001988.83-100.002017.33
1112023.06.13 03:15buy560.201961.000.001966.36
1122023.06.13 15:30t/p560.201966.360.001966.36107.202124.53
1132023.07.12 03:45buy570.201936.100.001941.76
1142023.07.12 15:30t/p570.201941.760.001941.76113.202237.73
1152023.07.19 23:00buy580.201978.780.001982.56
1162023.07.20 04:30t/p580.201982.560.001982.5649.482287.21
+
diff --git a/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 3.gif b/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 3.gif new file mode 100644 index 0000000..b615ee3 Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 3.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 3.htm b/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 3.htm new file mode 100644 index 0000000..d2417ad --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 3.htm @@ -0,0 +1,183 @@ + + + + Strategy Tester: x-saherelm.xr.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.xr.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.07.21 23:45 (2020.01.01 - 2023.07.22)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=50; swingLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.0003; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=252; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +
Bars in test62709Ticks modelled71719330Modelling qualityn/a
Mismatched charts errors777
Initial deposit1000.00SpreadCurrent (60)
Total net profit1930.81Gross profit5962.79Gross loss-4031.98
Profit factor1.48Expected payoff33.29
Absolute drawdown274.52Maximal drawdown1158.30 (33.79%)Relative drawdown39.80% (479.56)
Total trades58Short positions (won %)0 (0.00%)Long positions (won %)58 (58.62%)
Profit trades (% of total)34 (58.62%)Loss trades (% of total)24 (41.38%)
Largestprofit trade437.40loss trade-461.40
Averageprofit trade175.38loss trade-168.00
Maximumconsecutive wins (profit in money)4 (690.28)consecutive losses (loss in money)3 (-782.70)
Maximalconsecutive profit (count of wins)690.28 (4)consecutive loss (count of losses)-782.70 (3)
Averageconsecutive wins2consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.03 23:30buy10.301841.440.001845.90
22020.12.04 15:31t/p10.301845.900.001845.90120.741120.74
32020.12.08 18:30buy20.301870.350.001886.13
42020.12.09 05:19close20.301864.070.001886.13-201.46919.28
52020.12.30 03:45buy30.301883.290.001893.75
62020.12.30 10:00close30.301878.490.001893.75-144.00775.28
72020.12.30 18:00buy40.301885.860.001895.62
82020.12.31 02:15t/p40.301895.620.001895.62253.611028.89
92021.01.05 11:30buy50.301944.710.001954.49
102021.01.06 03:09t/p50.301954.490.001954.49280.341309.23
112021.04.05 17:30buy60.301729.420.001742.62
122021.04.05 22:00close60.301725.680.001742.62-112.201197.03
132021.04.19 06:15buy70.301778.720.001785.24
142021.04.19 07:15close70.301776.750.001785.24-59.101137.93
152021.04.26 21:00buy80.301780.010.001781.77
162021.04.26 23:39t/p80.301781.770.001781.7752.801190.73
172021.05.18 23:45buy90.301870.210.001872.99
182021.05.19 05:00close90.301867.630.001872.99-90.461100.27
192021.05.20 08:15buy100.301876.090.001877.07
202021.05.20 08:30t/p100.301877.070.001877.0729.401129.67
212021.05.21 11:30buy110.301876.530.001882.65
222021.05.21 15:21t/p110.301882.650.001882.65183.601313.27
232021.05.24 19:15buy120.301884.010.001887.27
242021.05.25 01:15close120.301880.910.001887.27-106.061207.20
252021.05.25 10:45buy130.301884.160.001898.74
262021.05.25 21:06t/p130.301898.740.001898.74437.401644.60
272021.06.28 20:30buy140.301780.510.001785.35
282021.06.28 21:15close140.301778.020.001785.35-74.701569.90
292021.07.06 04:15buy150.301792.940.001796.10
302021.07.06 04:53t/p150.301796.100.001796.1094.801664.70
312021.07.09 17:45buy160.301806.390.001814.91
322021.07.12 07:16close160.301801.870.001814.91-148.661516.04
332021.07.12 19:30buy170.301805.330.001808.45
342021.07.13 04:34t/p170.301808.450.001808.4580.541596.58
352021.08.12 23:00buy180.301753.790.001757.21
362021.08.13 09:09t/p180.301757.210.001757.2189.541686.12
372021.09.01 22:30buy190.301815.330.001820.69
382021.09.02 02:45close190.301813.220.001820.69-102.491583.63
392021.09.03 05:15buy200.301813.490.001819.35
402021.09.03 15:34t/p200.301819.350.001819.35175.801759.43
412021.09.29 06:00buy210.301740.530.001751.43
422021.09.29 16:24close210.301736.210.001751.43-129.601629.83
432021.11.16 04:45buy220.301867.860.001877.40
442021.11.16 09:45close220.301863.300.001877.40-136.801493.03
452021.12.07 04:30buy230.301781.010.001785.23
462021.12.07 05:45close230.301778.500.001785.23-75.301417.73
472021.12.07 20:30buy240.301784.430.001788.51
482021.12.08 04:07t/p240.301788.510.001788.51109.341527.07
492021.12.28 08:15buy250.301813.150.001819.37
502021.12.28 15:37t/p250.301819.370.001819.37186.601713.67
512022.01.10 21:30buy260.301801.220.001805.98
522022.01.11 04:24t/p260.301805.980.001805.98129.741843.41
532022.01.19 11:15buy270.301816.130.001824.95
542022.01.19 15:54t/p270.301824.950.001824.95264.602108.01
552022.01.24 23:15buy280.301843.380.001853.74
562022.01.25 11:04close280.301838.270.001853.74-166.361941.65
572022.01.31 11:30buy290.301791.280.001798.92
582022.01.31 16:39t/p290.301798.920.001798.92229.202170.85
592022.02.16 09:30buy300.301856.110.001860.85
602022.02.16 15:00close300.301852.740.001860.85-101.102069.75
612022.03.03 22:15buy310.301937.410.001946.73
622022.03.04 02:36t/p310.301946.730.001946.73266.542336.28
632022.03.04 13:00buy320.301947.630.001961.75
642022.03.04 18:09t/p320.301961.750.001961.75423.602759.88
652022.03.11 21:30buy330.301986.950.001999.25
662022.03.14 00:45close330.301972.860.001999.25-435.762324.12
672022.03.24 13:30buy340.301946.500.001957.42
682022.03.24 14:03t/p340.301957.420.001957.42327.602651.72
692022.04.05 16:15buy350.301935.270.001956.63
702022.04.05 18:45close350.301925.680.001956.63-287.702364.02
712022.04.13 08:30buy360.301969.860.001973.40
722022.04.13 11:19t/p360.301973.400.001973.40106.202470.22
732022.05.20 09:45buy370.301848.340.001859.62
742022.05.20 16:30close370.301840.610.001859.62-231.902238.32
752022.05.23 01:15buy380.301845.310.001848.55
762022.05.23 02:07t/p380.301848.550.001848.5597.202335.52
772022.06.08 15:15buy390.301851.320.001858.82
782022.06.08 18:07t/p390.301858.820.001858.82225.002560.52
792022.07.05 02:15buy400.301810.010.001814.79
802022.07.05 10:30close400.301806.730.001814.79-98.402462.12
812022.10.26 07:45buy410.301656.860.001658.96
822022.10.26 08:41t/p410.301658.960.001658.9663.002525.12
832022.10.27 08:45buy420.301669.970.001683.09
842022.10.27 09:45close420.301661.850.001683.09-243.602281.52
852022.11.02 04:00buy430.301650.460.001653.36
862022.11.02 10:00t/p430.301653.360.001653.3687.002368.52
872022.11.14 17:45buy440.301770.180.001784.24
882022.11.15 08:45close440.301769.440.001784.24-35.262333.26
892022.11.30 05:45buy450.301754.150.001759.19
902022.11.30 10:57t/p450.301759.190.001759.19151.202484.46
912023.01.11 06:30buy460.301877.620.001882.84
922023.01.11 07:37t/p460.301882.840.001882.84156.602641.06
932023.02.09 05:00buy470.301879.530.001889.99
942023.02.09 16:01t/p470.301889.990.001889.99313.802954.86
952023.02.16 21:30buy480.301843.520.001847.54
962023.02.17 01:15close480.301835.010.001847.54-268.362686.50
972023.02.22 05:15buy490.301837.180.001840.68
982023.02.22 10:03t/p490.301840.680.001840.68105.002791.50
992023.03.28 17:00buy500.301963.690.001968.77
1002023.03.28 17:57t/p500.301968.770.001968.77152.402943.90
1012023.03.30 10:45buy510.301969.560.001976.42
1022023.03.30 19:01t/p510.301976.420.001976.42205.803149.70
1032023.04.26 13:30buy520.302000.140.002005.44
1042023.04.26 16:24t/p520.302005.440.002005.44159.003308.70
1052023.04.27 06:00buy530.301999.160.002014.50
1062023.04.27 15:45close530.301983.780.002014.50-461.402847.30
1072023.05.15 19:45buy540.302020.300.002031.78
1082023.05.15 22:00close540.302014.590.002031.78-171.302676.00
1092023.06.09 17:30buy550.301967.630.001988.83
1102023.06.09 18:30close550.301962.630.001988.83-150.002526.00
1112023.06.13 03:15buy560.301961.000.001966.36
1122023.06.13 15:30t/p560.301966.360.001966.36160.802686.80
1132023.07.12 03:45buy570.301936.100.001941.76
1142023.07.12 15:30t/p570.301941.760.001941.76169.802856.60
1152023.07.19 23:00buy580.301978.780.001982.56
1162023.07.20 04:30t/p580.301982.560.001982.5674.212930.81
+
diff --git a/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 4.gif b/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 4.gif new file mode 100644 index 0000000..2f235e8 Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 4.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 4.htm b/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 4.htm new file mode 100644 index 0000000..6e17ef6 --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 4.htm @@ -0,0 +1,183 @@ + + + + Strategy Tester: x-saherelm.xr.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.xr.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.07.21 23:45 (2020.01.01 - 2023.07.22)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=50; swingLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.0003; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.3; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=252; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +
Bars in test62709Ticks modelled71719330Modelling qualityn/a
Mismatched charts errors777
Initial deposit1000.00SpreadCurrent (60)
Total net profit2201.41Gross profit5962.79Gross loss-3761.38
Profit factor1.59Expected payoff37.96
Absolute drawdown274.52Maximal drawdown997.50 (28.19%)Relative drawdown39.80% (479.56)
Total trades58Short positions (won %)0 (0.00%)Long positions (won %)58 (58.62%)
Profit trades (% of total)34 (58.62%)Loss trades (% of total)24 (41.38%)
Largestprofit trade437.40loss trade-313.66
Averageprofit trade175.38loss trade-156.72
Maximumconsecutive wins (profit in money)4 (690.28)consecutive losses (loss in money)3 (-621.90)
Maximalconsecutive profit (count of wins)690.28 (4)consecutive loss (count of losses)-621.90 (3)
Averageconsecutive wins2consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.03 23:30buy10.301841.440.001845.90
22020.12.04 15:31t/p10.301845.900.001845.90120.741120.74
32020.12.08 18:30buy20.301870.350.001886.13
42020.12.09 05:19close20.301864.070.001886.13-201.46919.28
52020.12.30 03:45buy30.301883.290.001893.75
62020.12.30 10:00close30.301878.490.001893.75-144.00775.28
72020.12.30 18:00buy40.301885.860.001895.62
82020.12.31 02:15t/p40.301895.620.001895.62253.611028.89
92021.01.05 11:30buy50.301944.710.001954.49
102021.01.06 03:09t/p50.301954.490.001954.49280.341309.23
112021.04.05 17:30buy60.301729.420.001742.62
122021.04.05 22:00close60.301725.680.001742.62-112.201197.03
132021.04.19 06:15buy70.301778.720.001785.24
142021.04.19 07:15close70.301776.750.001785.24-59.101137.93
152021.04.26 21:00buy80.301780.010.001781.77
162021.04.26 23:39t/p80.301781.770.001781.7752.801190.73
172021.05.18 23:45buy90.301870.210.001872.99
182021.05.19 05:00close90.301867.630.001872.99-90.461100.27
192021.05.20 08:15buy100.301876.090.001877.07
202021.05.20 08:30t/p100.301877.070.001877.0729.401129.67
212021.05.21 11:30buy110.301876.530.001882.65
222021.05.21 15:21t/p110.301882.650.001882.65183.601313.27
232021.05.24 19:15buy120.301884.010.001887.27
242021.05.25 01:15close120.301880.910.001887.27-106.061207.20
252021.05.25 10:45buy130.301884.160.001898.74
262021.05.25 21:06t/p130.301898.740.001898.74437.401644.60
272021.06.28 20:30buy140.301780.510.001785.35
282021.06.28 21:15close140.301778.020.001785.35-74.701569.90
292021.07.06 04:15buy150.301792.940.001796.10
302021.07.06 04:53t/p150.301796.100.001796.1094.801664.70
312021.07.09 17:45buy160.301806.390.001814.91
322021.07.12 07:16close160.301801.870.001814.91-148.661516.04
332021.07.12 19:30buy170.301805.330.001808.45
342021.07.13 04:34t/p170.301808.450.001808.4580.541596.58
352021.08.12 23:00buy180.301753.790.001757.21
362021.08.13 09:09t/p180.301757.210.001757.2189.541686.12
372021.09.01 22:30buy190.301815.330.001820.69
382021.09.02 02:45close190.301813.220.001820.69-102.491583.63
392021.09.03 05:15buy200.301813.490.001819.35
402021.09.03 15:34t/p200.301819.350.001819.35175.801759.43
412021.09.29 06:00buy210.301740.530.001751.43
422021.09.29 16:24close210.301736.210.001751.43-129.601629.83
432021.11.16 04:45buy220.301867.860.001877.40
442021.11.16 09:45close220.301863.300.001877.40-136.801493.03
452021.12.07 04:30buy230.301781.010.001785.23
462021.12.07 05:45close230.301778.500.001785.23-75.301417.73
472021.12.07 20:30buy240.301784.430.001788.51
482021.12.08 04:07t/p240.301788.510.001788.51109.341527.07
492021.12.28 08:15buy250.301813.150.001819.37
502021.12.28 15:37t/p250.301819.370.001819.37186.601713.67
512022.01.10 21:30buy260.301801.220.001805.98
522022.01.11 04:24t/p260.301805.980.001805.98129.741843.41
532022.01.19 11:15buy270.301816.130.001824.95
542022.01.19 15:54t/p270.301824.950.001824.95264.602108.01
552022.01.24 23:15buy280.301843.380.001853.74
562022.01.25 11:04close280.301838.270.001853.74-166.361941.65
572022.01.31 11:30buy290.301791.280.001798.92
582022.01.31 16:39t/p290.301798.920.001798.92229.202170.85
592022.02.16 09:30buy300.301856.110.001860.85
602022.02.16 15:00close300.301852.740.001860.85-101.102069.75
612022.03.03 22:15buy310.301937.410.001946.73
622022.03.04 02:36t/p310.301946.730.001946.73266.542336.28
632022.03.04 13:00buy320.301947.630.001961.75
642022.03.04 18:09t/p320.301961.750.001961.75423.602759.88
652022.03.11 21:30buy330.301986.950.001999.25
662022.03.14 00:22close330.301976.930.001999.25-313.662446.22
672022.03.24 13:30buy340.301946.500.001957.42
682022.03.24 14:03t/p340.301957.420.001957.42327.602773.82
692022.04.05 16:15buy350.301935.270.001956.63
702022.04.05 18:24close350.301925.270.001956.63-300.002473.82
712022.04.13 08:30buy360.301969.860.001973.40
722022.04.13 11:19t/p360.301973.400.001973.40106.202580.02
732022.05.20 09:45buy370.301848.340.001859.62
742022.05.20 16:30close370.301840.610.001859.62-231.902348.12
752022.05.23 01:15buy380.301845.310.001848.55
762022.05.23 02:07t/p380.301848.550.001848.5597.202445.32
772022.06.08 15:15buy390.301851.320.001858.82
782022.06.08 18:07t/p390.301858.820.001858.82225.002670.32
792022.07.05 02:15buy400.301810.010.001814.79
802022.07.05 10:30close400.301806.730.001814.79-98.402571.92
812022.10.26 07:45buy410.301656.860.001658.96
822022.10.26 08:41t/p410.301658.960.001658.9663.002634.92
832022.10.27 08:45buy420.301669.970.001683.09
842022.10.27 09:45close420.301661.850.001683.09-243.602391.32
852022.11.02 04:00buy430.301650.460.001653.36
862022.11.02 10:00t/p430.301653.360.001653.3687.002478.32
872022.11.14 17:45buy440.301770.180.001784.24
882022.11.15 08:45close440.301769.440.001784.24-35.262443.06
892022.11.30 05:45buy450.301754.150.001759.19
902022.11.30 10:57t/p450.301759.190.001759.19151.202594.26
912023.01.11 06:30buy460.301877.620.001882.84
922023.01.11 07:37t/p460.301882.840.001882.84156.602750.86
932023.02.09 05:00buy470.301879.530.001889.99
942023.02.09 16:01t/p470.301889.990.001889.99313.803064.66
952023.02.16 21:30buy480.301843.520.001847.54
962023.02.17 01:15close480.301835.010.001847.54-268.362796.30
972023.02.22 05:15buy490.301837.180.001840.68
982023.02.22 10:03t/p490.301840.680.001840.68105.002901.30
992023.03.28 17:00buy500.301963.690.001968.77
1002023.03.28 17:57t/p500.301968.770.001968.77152.403053.70
1012023.03.30 10:45buy510.301969.560.001976.42
1022023.03.30 19:01t/p510.301976.420.001976.42205.803259.50
1032023.04.26 13:30buy520.302000.140.002005.44
1042023.04.26 16:24t/p520.302005.440.002005.44159.003418.50
1052023.04.27 06:00buy530.301999.160.002014.50
1062023.04.27 15:35close530.301989.140.002014.50-300.603117.90
1072023.05.15 19:45buy540.302020.300.002031.78
1082023.05.15 22:00close540.302014.590.002031.78-171.302946.60
1092023.06.09 17:30buy550.301967.630.001988.83
1102023.06.09 18:30close550.301962.630.001988.83-150.002796.60
1112023.06.13 03:15buy560.301961.000.001966.36
1122023.06.13 15:30t/p560.301966.360.001966.36160.802957.40
1132023.07.12 03:45buy570.301936.100.001941.76
1142023.07.12 15:30t/p570.301941.760.001941.76169.803127.20
1152023.07.19 23:00buy580.301978.780.001982.56
1162023.07.20 04:30t/p580.301982.560.001982.5674.213201.41
+
diff --git a/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 5.gif b/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 5.gif new file mode 100644 index 0000000..905a6a2 Binary files /dev/null and b/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 5.gif differ diff --git a/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 5.htm b/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 5.htm new file mode 100644 index 0000000..1f7f2fa --- /dev/null +++ b/Bkp/Used/14020502/Docs/Reports/XR/StrategyTester 5.htm @@ -0,0 +1,213 @@ + + + + Strategy Tester: x-saherelm.xr.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.xr.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.07.21 23:45 (2020.01.01 - 2023.07.22)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.0003; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.3; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=252; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +xrR2R=2; xrMarketLength=7; xrMarketRangeMult=7; xrFastMult=3; xrSlowMult=7; xrSwingLength=7;
Bars in test62709Ticks modelled71719330Modelling qualityn/a
Mismatched charts errors777
Initial deposit1000.00SpreadCurrent (60)
Total net profit2656.05Gross profit8026.93Gross loss-5370.88
Profit factor1.49Expected payoff36.38
Absolute drawdown169.22Maximal drawdown954.90 (24.18%)Relative drawdown31.06% (374.26)
Total trades73Short positions (won %)0 (0.00%)Long positions (won %)73 (56.16%)
Profit trades (% of total)41 (56.16%)Loss trades (% of total)32 (43.84%)
Largestprofit trade528.00loss trade-313.66
Averageprofit trade195.78loss trade-167.84
Maximumconsecutive wins (profit in money)4 (991.20)consecutive losses (loss in money)3 (-208.69)
Maximalconsecutive profit (count of wins)991.20 (4)consecutive loss (count of losses)-493.50 (2)
Averageconsecutive wins2consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.03 23:30buy10.301841.440.001845.90
22020.12.04 15:31t/p10.301845.900.001845.90120.741120.74
32020.12.08 18:30buy20.301870.350.001886.13
42020.12.09 03:19close20.301867.580.001886.13-96.161024.58
52020.12.30 03:45buy30.301883.290.001893.75
62020.12.30 10:00close30.301878.490.001893.75-144.00880.58
72020.12.30 18:00buy40.301885.860.001895.62
82020.12.31 02:15t/p40.301895.620.001895.62253.611134.19
92020.12.31 13:45buy50.301894.880.001901.64
102021.01.04 01:00t/p50.301901.640.001901.64176.681310.87
112021.01.05 11:30buy60.301944.710.001954.49
122021.01.06 03:09t/p60.301954.490.001954.49280.341591.20
132021.04.05 17:30buy70.301729.420.001742.62
142021.04.05 22:00close70.301725.680.001742.62-112.201479.00
152021.04.26 21:00buy80.301780.010.001781.77
162021.04.26 23:39t/p80.301781.770.001781.7752.801531.80
172021.05.11 09:00buy90.301837.410.001840.21
182021.05.11 09:51close90.301834.840.001840.21-77.101454.70
192021.05.18 23:45buy100.301870.210.001872.99
202021.05.19 05:00close100.301867.630.001872.99-90.461364.24
212021.05.20 08:15buy110.301876.090.001877.07
222021.05.20 08:30t/p110.301877.070.001877.0729.401393.64
232021.05.21 11:30buy120.301876.530.001882.65
242021.05.21 15:21t/p120.301882.650.001882.65183.601577.24
252021.05.24 19:15buy130.301884.010.001887.27
262021.05.25 01:15close130.301880.910.001887.27-106.061471.18
272021.05.25 10:45buy140.301884.160.001898.74
282021.05.25 21:06t/p140.301898.740.001898.74437.401908.58
292021.06.28 20:30buy150.301780.510.001785.35
302021.06.28 21:15close150.301778.020.001785.35-74.701833.88
312021.07.02 02:00buy160.301776.630.001777.79
322021.07.02 03:39t/p160.301777.790.001777.7934.801868.68
332021.07.06 04:15buy170.301792.940.001796.10
342021.07.06 04:53t/p170.301796.100.001796.1094.801963.48
352021.07.09 17:45buy180.301806.390.001814.91
362021.07.12 07:16close180.301801.870.001814.91-148.661814.82
372021.07.13 17:45buy190.301811.870.001825.27
382021.07.13 21:07close190.301806.200.001825.27-170.101644.72
392021.08.11 05:30buy200.301732.250.001747.61
402021.08.11 18:06t/p200.301747.610.001747.61460.802105.52
412021.08.12 23:00buy210.301753.790.001757.21
422021.08.13 09:09t/p210.301757.210.001757.2189.542195.06
432021.08.18 04:30buy220.301789.150.001796.39
442021.08.18 12:30close220.301787.880.001796.39-38.102156.96
452021.09.01 22:30buy230.301815.330.001820.69
462021.09.02 02:45close230.301813.220.001820.69-102.492054.47
472021.09.02 03:15buy240.301815.430.001819.79
482021.09.02 05:30close240.301813.160.001819.79-68.101986.37
492021.09.03 05:15buy250.301813.490.001819.35
502021.09.03 15:34t/p250.301819.350.001819.35175.802162.17
512021.09.27 03:45buy260.301753.930.001763.97
522021.09.27 12:49close260.301749.120.001763.97-144.302017.87
532021.10.22 02:15buy270.301786.030.001793.21
542021.10.22 09:54t/p270.301793.210.001793.21215.402233.27
552021.11.16 04:45buy280.301867.860.001877.40
562021.11.16 09:45close280.301863.300.001877.40-136.802096.47
572021.12.07 04:30buy290.301781.010.001785.23
582021.12.07 05:45close290.301778.500.001785.23-75.302021.17
592021.12.07 20:30buy300.301784.430.001788.51
602021.12.08 04:07t/p300.301788.510.001788.51109.342130.51
612021.12.28 08:15buy310.301813.150.001819.37
622021.12.28 15:37t/p310.301819.370.001819.37186.602317.11
632022.01.10 21:30buy320.301801.220.001805.98
642022.01.11 04:24t/p320.301805.980.001805.98129.742446.85
652022.01.19 11:15buy330.301816.130.001824.95
662022.01.19 15:54t/p330.301824.950.001824.95264.602711.45
672022.01.24 23:15buy340.301843.380.001853.74
682022.01.25 12:36close340.301836.700.001853.74-213.462497.98
692022.01.31 11:30buy350.301791.280.001798.92
702022.01.31 16:39t/p350.301798.920.001798.92229.202727.18
712022.02.16 09:30buy360.301856.110.001860.85
722022.02.16 15:00close360.301852.740.001860.85-101.102626.08
732022.02.28 16:15buy370.301914.460.001926.88
742022.02.28 18:09close370.301904.460.001926.88-300.002326.08
752022.03.03 22:15buy380.301937.410.001946.73
762022.03.04 02:36t/p380.301946.730.001946.73266.542592.62
772022.03.04 13:00buy390.301947.630.001961.75
782022.03.04 18:09t/p390.301961.750.001961.75423.603016.22
792022.03.11 21:30buy400.301986.950.001999.25
802022.03.14 00:22close400.301976.930.001999.25-313.662702.56
812022.03.21 06:45buy410.301928.320.001933.60
822022.03.21 14:30close410.301923.730.001933.60-137.702564.86
832022.03.24 13:30buy420.301946.500.001957.42
842022.03.24 14:03t/p420.301957.420.001957.42327.602892.46
852022.04.05 16:15buy430.301935.270.001956.63
862022.04.05 18:24close430.301925.270.001956.63-300.002592.46
872022.04.13 08:30buy440.301969.860.001973.40
882022.04.13 11:19t/p440.301973.400.001973.40106.202698.66
892022.05.04 11:30buy450.301869.680.001876.04
902022.05.04 17:15close450.301863.310.001876.04-191.102507.56
912022.05.20 09:45buy460.301848.340.001859.62
922022.05.20 16:31close460.301840.590.001859.62-232.502275.06
932022.05.23 01:15buy470.301845.310.001848.55
942022.05.23 02:07t/p470.301848.550.001848.5597.202372.26
952022.05.30 06:45buy480.301859.800.001862.94
962022.05.30 08:42t/p480.301862.940.001862.9494.202466.46
972022.06.08 15:15buy490.301851.320.001858.82
982022.06.08 18:07t/p490.301858.820.001858.82225.002691.46
992022.07.05 02:15buy500.301810.010.001814.79
1002022.07.05 10:30close500.301806.730.001814.79-98.402593.06
1012022.09.09 04:30buy510.301715.930.001727.53
1022022.09.09 10:22t/p510.301727.530.001727.53348.002941.06
1032022.10.27 08:45buy520.301669.970.001683.09
1042022.10.27 09:45close520.301661.850.001683.09-243.602697.46
1052022.11.02 04:00buy530.301650.460.001653.36
1062022.11.02 10:00t/p530.301653.360.001653.3687.002784.46
1072022.11.16 12:15buy540.301783.620.001796.96
1082022.11.16 16:37close540.301773.620.001796.96-300.002484.46
1092022.11.30 05:45buy550.301754.150.001759.19
1102022.11.30 10:57t/p550.301759.190.001759.19151.202635.66
1112022.12.08 15:15buy560.301787.360.001794.56
1122022.12.08 17:28t/p560.301794.560.001794.56216.002851.66
1132022.12.21 16:45buy570.301818.300.001822.80
1142022.12.21 17:37t/p570.301822.800.001822.80135.002986.66
1152023.01.09 18:45buy580.301876.980.001885.82
1162023.01.10 02:26close580.301868.360.001885.82-271.662715.00
1172023.01.11 06:30buy590.301877.620.001882.84
1182023.01.11 07:37t/p590.301882.840.001882.84156.602871.60
1192023.02.09 05:00buy600.301879.530.001889.99
1202023.02.09 16:01t/p600.301889.990.001889.99313.803185.40
1212023.02.16 21:30buy610.301843.520.001847.54
1222023.02.17 01:15close610.301835.010.001847.54-268.362917.04
1232023.02.22 05:15buy620.301837.180.001840.68
1242023.02.22 10:03t/p620.301840.680.001840.68105.003022.04
1252023.03.17 04:45buy630.301929.140.001946.74
1262023.03.17 15:02t/p630.301946.740.001946.74528.003550.04
1272023.03.28 17:00buy640.301963.690.001968.77
1282023.03.28 17:57t/p640.301968.770.001968.77152.403702.44
1292023.03.30 10:45buy650.301969.560.001976.42
1302023.03.30 19:01t/p650.301976.420.001976.42205.803908.24
1312023.04.26 13:30buy660.302000.140.002005.44
1322023.04.26 15:30close660.301993.710.002005.44-192.903715.34
1332023.04.27 06:00buy670.301999.160.002014.50
1342023.04.27 15:35close670.301989.140.002014.50-300.603414.74
1352023.05.09 08:15buy680.302027.060.002032.32
1362023.05.09 14:30t/p680.302032.320.002032.32157.803572.54
1372023.05.15 19:45buy690.302020.300.002031.78
1382023.05.15 22:00close690.302014.590.002031.78-171.303401.24
1392023.06.09 17:30buy700.301967.630.001988.83
1402023.06.09 18:30close700.301962.630.001988.83-150.003251.24
1412023.06.13 03:15buy710.301961.000.001966.36
1422023.06.13 15:30t/p710.301966.360.001966.36160.803412.04
1432023.07.12 03:45buy720.301936.100.001941.76
1442023.07.12 15:30t/p720.301941.760.001941.76169.803581.84
1452023.07.19 23:00buy730.301978.780.001982.56
1462023.07.20 04:30t/p730.301982.560.001982.5674.213656.05
+
diff --git a/Bkp/Used/14020502/Docs/Signalling Conditions.md b/Bkp/Used/14020502/Docs/Signalling Conditions.md new file mode 100644 index 0000000..ac8aec4 --- /dev/null +++ b/Bkp/Used/14020502/Docs/Signalling Conditions.md @@ -0,0 +1,501 @@ +# OSC Signalling Conditions + +there are some Verifications For signals. +here i described them. + +## Long + +- OSC +- When Market Middleage Cross Over MC Fast +- When MCFast Under MC Slow +- When MakretMiddleage + +```mql4 + // // + // // XMA Based Signals ... + // hasLongSignal = + // // + // // XMA ... + // // + // // SC Fast Cross Over Market Middleage ... + // xmaState.scFast > xmaState.marketMiddleage + // && !(xmaState.scFastPrev > xmaState.marketMiddleage) + // // + // // when Short Cycle is Trending Up ... + // && xmaState.scFast > xmaState.scSlow + // && xmaState.scFastPrev > xmaState.scSlowPrev + // // + // // When Medium Cycle is Trending Up ... + // && xmaState.mcFast > xmaState.mcSlow + // && xmaState.mcFastPrev > xmaState.mcSlowPrev + // // + // // and Medium Cycle TrendPower is Going Up ... + // && MathAbs(xmaState.mcFast - xmaState.mcSlow) > + // MathAbs(xmaState.mcFastPrev - xmaState.mcSlowPrev) + // // + // // When Long Cycle is Trending Up ... + // && xmaState.lcFast > xmaState.lcSlow + // && xmaState.lcFastPrev > xmaState.lcSlowPrev + // // + // // and Long Cycle TrendPower is Going Up ... + // && MathAbs(xmaState.lcFast - xmaState.lcSlow) > + // MathAbs(xmaState.lcFastPrev - xmaState.lcSlowPrev) + // // + // // Short Cycle Slow bigger thhan Medium Cycle Fast ... + // && xmaState.scSlow > xmaState.mcFast + // // + // // OSC ... + // // Check OSC Fast and Slow is Less than 0.5 ... + // && oscState.fastOSC < 0.5 + // && oscState.slowOSC < 0.5 + // && oscState.fastOSCPrev < 0.5 + // && oscState.slowOSCPrev < 0.5 + // && oscState.fastOSC > oscState.fastOSCPrev + // // + // // Check OSC Minimum Signal Power ... + // // this Helps for Detect Market exits from Ranging ... + // && minPowOSC > 0 + // ? + // // + // // Check Conditions only if value provided ... + // oscState.powerOSCPrev < 0 + // && MathAbs(oscState.powerOSCPrev) > minPowOSC + // : + // // + // // ... other wise, ignore ... + // true + // // + // // Check Previous Candle Signal Power must be Lower than + // // Current Signal Power and the Direction Must be Up Trend ... + // && oscState.powerOSCPrev < oscState.powerOSC + // // + // // Also we Have to Check Market not ranging ... + // && !IsOSCMarketRanging( + // bar_index + 1, + // marketLen, + // minPowOSC, + // fastOSCLen, + // fastOSCMul, + // slowOSCLen, + // slowOSCMul + // ) + // // + // // ZIGZAG ... + // && zigZagState.isWaitForTrendDown + // && !zigZagState.isWaitForTrendUp + // // + // // XADX ... + // // TODO: add XADX Base Conditions for Long Trades ... + // // When ADX Trend Power bigger than 20 and less than 50 ... + // && !adxState.trendPower < 23 + // && !adxState.trendPowerPrev < 23 + // // + // // Check Trend Direction for Signals ... + // && adxState.upDirection > adxState.downDirection + // && adxState.upDirectionPrev > adxState.downDirectionPrev + // // && adxState.trendPower < 50 + // // && adxState.trendPower > adxState.trendPowerPrev + // // + // // PRICE Checking ... + // // price must be less than Candle High at openning time ... + // && longEntryPrice <= candleHigh + // // + // // also Candle High and Low must be above than lc Fast & lc Slow ... + // && longEntryPrice > xmaState.lcFast + // && longEntryPrice > xmaState.lcSlow + // && ( + // !IsSharpBullishHappens( + // bar_index, + // marketLen * 2 + // ) + // || IsSharpBearishHappens( + // bar_index, + // marketLen * 2 + // ) + // ) + // ; + + // + // Check for Long Trades if some Sharp Bullish Happens, + // Decrease sl size for fixing tps ... + // if (isSharpBullishHappens) { + // sl = sl / 1.5; + // } + + // + // TODO: Remove this ... + // if (xmaStates[0].marketMiddleage > xmaStates[1].marketMiddleage) { + // r2rRatio = r2rRatio * 2; + // } + + // + hasLongSignal = + // + // Global ... + true + // + && ( + // + // XMA ... + ( + // + true + // + // Check Medium Cycle is in TrendDown ... + && xmaStates[0].mcSlow > xmaStates[0].mcFast + && xmaStates[1].mcSlow > xmaStates[1].mcFast + && xmaStates[2].mcSlow > xmaStates[2].mcFast + // + // Check Market Middleage Cross Over MC Slow ... + // && isMarketMiddleCrossOverMCSlow + // && xmaStates[0].marketMiddleage >= (5 * _Point); + && xmaStates[0].marketMiddleage > xmaStates[0].mcSlow + && !(xmaStates[1].marketMiddleage >= xmaStates[1].mcSlow) + // + // IMPORTANT: by passing this condition i can Increase r2r ration ... + // && xmaStates[0].marketMiddleage > xmaStates[1].marketMiddleage + && MathAbs(xmaStates[0].marketMiddleage - xmaStates[1].marketMiddleage) > _Point + ) + // || + // + // OSC ... + // ( + // // + // true + // // + // // Check osc fast cross over slow ... + // && oscStates[1].fastOSC > oscStates[1].slowOSC + // && !(oscStates[2].fastOSC >= oscStates[2].slowOSC) + // // + // // Check OSC Fast bigger than 0.5 ... + // && oscStates[1].fastOSC > 0.5 + // && ( + // xmaStates[1].mcFast > xmaStates[1].mcSlow + // ? + // // + // xmaStates[1].marketMiddleage > xmaStates[1].mcSlow + // // + // && xmaStates[1].marketMiddleage > xmaStates[2].marketMiddleage + // && xmaStates[1].marketMiddleage > xmaStates[3].marketMiddleage + // && xmaStates[2].marketMiddleage > xmaStates[3].marketMiddleage + // : + // true + // ) + // ) + ) + ; +``` + +```mql4 + // + // TODO: Determines Where and How close Long Trades on Trend Reversal Points ... + closeLongTrades = + false + // + // This is One Conditions ... + // ( + // // + // xmaStates[0].marketMiddleage < xmaStates[0].mcFast + // && ( + // xmaStates[0].marketMiddleage < xmaStates[0].mcSlow + // || xmaStates[1].marketMiddleage < xmaStates[1].mcSlow + // || xmaStates[2].marketMiddleage < xmaStates[2].mcSlow + // ) + // // + // && xmaStates[0].mcFast > xmaStates[0].mcSlow + // // + // && xmaStates[0].marketMiddleage < xmaStates[1].marketMiddleage + // && xmaStates[1].marketMiddleage < xmaStates[2].marketMiddleage + // ) + ; + + // + waitForLongSignals = + true; + // waitForLongSignals + // ? + // // + // true + // // + // // Closing Options ... + // // + // // Trades Doesnt Closed ... + // && !closeLongTrades + // // + // // PRICE ... + // // + // // Bullish Sharp doesnt occured ... + // && !isSharpBullishHappens + // // + // // XMA ... + // // + // && xmaStates[0].marketMiddleage < xmaStates[0].mcFast + // && !( + // // + // // On MC Trend Up ... + // xmaStates[0].mcFast > xmaStates[0].mcSlow + // ? + // // + // // Market Middleage doesnt Trending Down ... + // xmaStates[0].marketMiddleage - xmaStates[0].mcFast > xmaStates[1].marketMiddleage - xmaStates[1].mcFast + // && xmaStates[0].marketMiddleage - xmaStates[0].mcFast > xmaStates[2].marketMiddleage - xmaStates[2].mcFast + // && xmaStates[0].marketMiddleage - xmaStates[0].mcFast > xmaStates[3].marketMiddleage - xmaStates[3].mcFast + // && xmaStates[1].marketMiddleage - xmaStates[1].mcFast > xmaStates[3].marketMiddleage - xmaStates[3].mcFast + // : + // true + // ) + // : + // // + // true + // && ( + // // + // // PRICE ... + // // isSharpBearishHappens + // // + // // XMA ... + // isMCFastCrossUnderSlow + // || isMarketMiddleCrossUnderMCSlow + // ) + ; +``` + +```mql4 + // + bool xmaHasLongSignal = + // + // Global ... + true + // + // XMA ... + // + // Check Medium Cycle is in TrendDown ... + // && xmaStates[0].mcSlow > xmaStates[0].mcFast + // && xmaStates[1].mcSlow > xmaStates[1].mcFast + // && xmaStates[2].mcSlow > xmaStates[2].mcFast + // + // Check Market Middleage Cross Over MC Slow ... + && isMarketMiddleageTrendUp + // + // Check distance between Medium Cycle Market + && isMarketMiddleCrossOverMCSlow + // && xmaStates[0].marketMiddleage > xmaStates[0].mcSlow + // && MathAbs(xmaStates[1].marketMiddleage - xmaStates[2].mcSlow) > _Point + // + // IMPORTANT: by passing this condition i can Increase r2r ration ... + // && xmaStates[0].marketMiddleage > xmaStates[1].marketMiddleage + && MathAbs(xmaStates[1].marketMiddleage - xmaStates[2].marketMiddleage) > _Point + // + // OSC ... + && oscStates[1].fastOSC > 0.5 + && !isOSCPowerTrendDown + && oscStates[1].powerOSC > 0 + // + // PRICE ... + && !isSharpBullishHappens + && longEntryPrice < marketHigh[0] + && marketHigh[0] > marketHigh[1] + && marketHigh[0] > marketHigh[2] + ; + + // + bool oscHasLongSignal = + // + false + // + // OSC ... + // + // Check osc is Trending Up ... + // isOSCTrendUp + // + // Check osc fast cross over slow ... + // isOSCFastCrossOverSlow + // + // Check OSC Market not Ranging ... + // && !isOSCMarketRanging + // + // Check OSC Fast bigger than 0.5 ... + // && oscStates[1].fastOSC > 0.5 + // && oscStates[1].slowOSC > 0.5 + // + // PRICE ... + // && !isSharpBullishHappens + // && longEntryPrice < marketHigh[0] + // && marketHigh[0] > marketHigh[1] + // && marketHigh[0] > marketHigh[2] + ; + + // + bool hasLongSignal = + xmaHasLongSignal + || + oscHasLongSignal + ; +``` + +```mql4 + // + bool hasLongSignal = + // + // Global ... + true + // + && + // XMA ... + // + // Check Parabolic Sar Cross Under Market Middleage + // Or Trending Down ... + isParabolicCrossUnderMarketMiddle + && + // + // Check PSar Value is Bigger Than Market Middleage ... + xmaStates[1].parabolicSAR < xmaStates[1].marketMiddleage + && + // + // Check Parabolic Revrse Change bigger than Prev Cancle Close ... + xmaStates[1].parabolicSAR < MathMin(marketOpen[1], marketClose[1]) + && + // + // Now We Have Separate our Conditions based on + // Market Trends ... + // + // Medium Cycle Market Trends Up ... + isMCTrendUp + ? + ( + // + // Market Middle must be in Trending Up ... + isMarketMiddleageTrendUp + && + // + // Market Middle Must be less than Maximum in Cycle ... + xmaStates[1].marketMiddleage < marketMiddlesMinMax.max + && + // + // Market Middleage must be above of MC Fast ... + xmaStates[1].marketMiddleage > xmaStates[1].mcFast + && + // + // Check Distance between SC Fast and Market Middle ... + MathAbs(xmaStates[1].scFast - xmaStates[1].scSlow) > (3 * _Point) + // + // Minimum Signal Power of OSC ... + // MathAbs(oscStates[1].powerOSC > minPowOSC) + ) + : + // + // Medium Cycle Market Trends Down ... + false + // () + ; +``` + +```mql4 + // + // Based On MC Market Trend Up ... + // + // Based On MC Market Down Trend ... + // isMCTrendDown + // || isMCFastCrossUnderSlow + // ? + // ( + // + // Find SC Fast Cross Over SC Slow, which happens betweentwo of SC Fast Under SC Slow ... + // isSCFastCrossOverSlow + + // // + // // Find the Moment which Market Middleage Cross Over MC Fast ... + // isMarketMiddleCrossOverMCFast + // // + // // Check Parabolix SAR for Long Trades ... + // && xmaStates[0].parabolicSAR < xmaStates[0].marketMiddleage + // && xmaStates[1].parabolicSAR < xmaStates[1].marketMiddleage + // // + // // Check Market Middle and Parabolic SAR Distance ... + // && MathAbs(xmaStates[1].marketMiddleage - xmaStates[1].parabolicSAR) >= 1 + // // + // // Check Distance between MCSlow and MCFast bigger than MarketMiddle and Parabolic SAR ... + // && MathAbs(xmaStates[1].mcFast - xmaStates[1].mcSlow) > MathAbs(xmaStates[1].marketMiddleage - xmaStates[1].parabolicSAR) + // ) + // : + // // + // // Based On MC Market Up Trend ... + // false +``` + +```mql4 + // + oscHasLongSignal = + // + oscStates[0].fastOSC > oscStates[0].slowOSC + && ( + ( + oscStates[0].fastOSC > 0.5 + && oscStates[0].fastOSC < 0.75 + ) + || oscStates[0].fastOSC <= 0.5 + ) + && ( + oscStates[0].powerOSC > 0 + || oscStates[1].powerOSC > 0 + ) + // + && xmaStates[0].scFast > xmaStates[0].marketMiddleage + && MathAbs(xmaStates[0].scFast - xmaStates[0].marketMiddleage) > (20 * _Point) + // + && xmaStates[1].scFast > xmaStates[1].marketMiddleage + && MathAbs(xmaStates[1].scFast - xmaStates[1].marketMiddleage) > (20 * _Point) + // + && xmaStates[2].scFast > xmaStates[2].marketMiddleage + // + && xmaStates[0].mcFast > xmaStates[0].mcSlow + && MathAbs(xmaStates[0].mcFast - xmaStates[0].mcSlow) > (50 * _Point) + // + && xmaStates[0].mcFast < xmaStates[0].scFast + && xmaStates[0].mcFast < xmaStates[0].parabolicSAR + // + && xmaStates[0].parabolicSAR < xmaStates[0].marketMiddleage + && xmaStates[1].parabolicSAR < xmaStates[1].marketMiddleage + // + && !isSharpBullishHappens + // + && longEntryPrice > xmktStates[0].highestLow + && longEntryPrice > xmaStates[0].marketMiddleage + // + && xmktStates[0].highestLow > xmaStates[0].scFast + && xmktStates[0].lowestHigh < xmaStates[0].scFast + && xmktStates[0].lowestHigh < xmaStates[0].marketMiddleage + ; +``` + +```mql4 +``` + +```mql4 +``` + +```mql4 +``` + +```mql4 +``` + +```mql4 +``` + +```mql4 +``` + +```mql4 +``` + +```mql4 +``` + +```mql4 +``` + +```mql4 +``` + +```mql4 +``` diff --git a/Bkp/Used/14020502/Experts/x-saherelm.ea.mq4 b/Bkp/Used/14020502/Experts/x-saherelm.ea.mq4 new file mode 100644 index 0000000..cf8b38d --- /dev/null +++ b/Bkp/Used/14020502/Experts/x-saherelm.ea.mq4 @@ -0,0 +1,710 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XST Strategy Expert Advisor +// --------------------------------------------- +// saherelm implementation of strategy expert advisor ... +// in this EA, we try to combine multiple tools, to ashive best +// results ... +// +// ShortName: XST +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +989121694056 +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XST Strategy Expert Advisor" +#property strict + +// +// START Inputs ... +// +// +// Signal Prefixe ... +input string signalPrefix = "XST_EA"; // Signal Prefix + +// +// Signal Draw Specifications ... +input string bullishSignalLabel = "X_BUY"; // Bullish Signal Label +input color bullishSignalColor = clrAqua; // Bullish Signal Color + +// +input string bearishSignalLabel = "X_SELL"; // Bearish Signal Label +input color bearishSignalColor = clrFuchsia; // Bearish Signal Color + +// +input color signalEntryColor = clrAquamarine; // Signal Entry Ptice Color +input color signalSLColor = clrRed; // Signal SL Color +input color signalTPColor = clrGreen; // Signal TP Color + +// +input int candleGapBetweenSignals = 2; // How many Candle waits to new Signal from last one + +// +// Trade ... +input bool allowTrade = true; // Allow Trade Based on given Signals +input bool allowLongTrades = true; // Allow Long Trades +input bool allowShortTrades = true; // Allow Short Trades + +// +// Alerts ... +input bool alertEvents = true; // Alert Events +input bool alertPositions = true; // Alert Positions +input bool longPositionAlerts = true; // Alert Long Positions +input bool shortPositionAlerts = true; // Alert Short Positions + +// +// Alert Types ... +input bool terminalAlert = false; // Terminal Alert +input bool pushAlert = false; // Push Notification Alerts + +// +// Balance and Finanical Specifications ... +input double lotsPerTradePercent = 0.0003; // Lots Per Trade Percent +input int maxOpenTrades = 4; // Maximum Open Trade +input double maxDrawdownPercentPerPTrade = 0.45; // Maximum DrawDown Per Trade +input double minBalancePercent = 0.5; // Minimum Balance for Trading +input double maxEquityPercent = 0.1; // Maximum Trade Equity + +// +// START Global Definitions: Variables, Properties and etc ... +// +int lastSignalledBar = 0; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.signal.lib.mq4" + +// +int maxMarketLength = 0; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Validate Inputs ... + bool inputsNotValiid = + // + // EA ... + lotsPerTradePercent < 0 + || maxOpenTrades <= 0 + || maxDrawdownPercentPerPTrade < 0 + || minBalancePercent < 0 + || maxEquityPercent < 0 + ; + + // + if (inputsNotValiid) { + return INIT_PARAMETERS_INCORRECT; + } + + // + totalSignals = 0; + totalLongSignals = 0; + totalShortSignals = 0; + + // + initialBalance = 0; + + // + // START Define Array Series ... + // + // + // END Define Array Series ... + // + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST"; + + // + ClearSignalConditions(); + + // + maxMarketLength = MathMax(0, GetDailyCandleCount()); + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { +} + +// +// Ticker Event Handler ... +void OnTick() { + // + isNewDay = IsNewDay(); + if (isNewDay) { + // + LogMessage( + StringConcatenate( + "New Day ..." + ) + ); + } + + // + // Process Signals to Open Positions ... + ProcessSignals(); + + // + // Checking State for Signal Handling ... + CheckState(); + + // + // Process Open Positions for Trailing Stop Loss or Close ... + ProcessOpenPositions(); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Check State for Signal Handling ... +void CheckState() { + // + // Here we Must to Check Market State for enable or disable + // Signal Handlers and also make dection to close all long/short + // trades ... +} + +// +// Calculate Signals and Process Based on Exists Signals ... +void ProcessSignals() { + // + XSignalRequest request = {}; + request.type = X_SIGNAL_NONE; + request.hasSignal = false; + + // + // Prevent Multiple Calculating on Same Bars ... + isNewBar = IsNewBar(); + if (isNewBar) { + countedBars++; + } + + // + if (countedBars < maxMarketLength) { + return; + } + + // + bool allowDoTrade = true; + + // + // Check Balance ... + if (initialBalance > 0) { + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double minimumBalanceForTrade = + balance > initialBalance + ? + minBalancePercent * balance + : + minBalancePercent * initialBalance; + + // + // Retrieve Account Equity ... + double equity = AccountInfoDouble(ACCOUNT_EQUITY); + double maxAllowedEquity = balance - (balance * maxEquityPercent); + + // + // Retrieve Free Marigin ... + double freeMargin = AccountFreeMargin(); + double maximumMariginRisk = balance - (balance * maxEquityPercent); + + // + if ( + // + // Do not Open Positions if equity not passed ... + equity < maxAllowedEquity || + // + // Do not Open Positions if free margin not passed ... + freeMargin <= maximumMariginRisk || + // + // Do not open positions if balance less than minimum ... + balance <= minimumBalanceForTrade + ) { + // + static bool tradingPauseAlerted; + + // + allowDoTrade = false; + + // + if (!tradingPauseAlerted) { + // + string message = StringConcatenate( + "Trading Pause => ", + "Balance: ", balance, + ", Equity: ", equity, + ", FreeMargin: ", freeMargin + ); + + // + LogMessage(message); + SendAlert(message); + + // + tradingPauseAlerted = true; + } + } + } + + // + // Retrieve Signal Exists ... + request = GenerateSignal(0); + + // + // Prevent doing anything else, if there is no signals ... + if ( + !allowDoTrade || + !request.hasSignal || + request.type == X_SIGNAL_NONE + ) { + return; + } + + // + bool hasLongSignal = request.type == X_SIGNAL_LONG; + + // + // Check last Signalled Bar with Counted Bars ... + // Prevent Multiple Signalling on Same Bar ... + bool isInLastSignalledBars = false; + for (int i=0; i < candleGapBetweenSignals; i++) { + // + isInLastSignalledBars = + isInLastSignalledBars + || lastSignalledBar == countedBars - i + ; + } + if (isInLastSignalledBars) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + return; + } + + // + // increase last signalled bar ... + lastSignalledBar = countedBars; + + // + // Calculate Can Trade or not ... + allowDoTrade = allowTrade + && ( + hasLongSignal ? + allowLongTrades : + allowShortTrades + ); + + // + // Chack Maximum Open Positions ... + int openTrades = CountOpenTrades(); + if (maxOpenTrades > 0) { + // + if (openTrades >= maxOpenTrades) { + // + allowDoTrade = false; + + // + if (!allowDoTrade) { + // + string message = StringConcatenate( + "Trading Pause => ", + "Max Open Trades (", + maxOpenTrades, + ") reached ..." + ); + + // + LogMessage(message); + SendAlert(message); + } + } + } + + // + // Check Trading is Enable or not ... + // nothing to do if trading is disabled ... + if (!allowDoTrade) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + string message = StringConcatenate( + "Trading Not Allowed ..." + ); + + // + LogMessage(message); + SendAlert(message); + return; + } + + // + bool isPositionOpened = TradeSignal( + request.signal, + lotsPerTradePercent, + // + bullishSignalLabel, + bullishSignalColor, + bearishSignalLabel, + bearishSignalColor + ); + + // + totalSignals++; + if (hasLongSignal) { + // + totalLongSignals++; + ClearLongSignalConditions(); + } else { + // + totalShortSignals++; + ClearShortSignalConditions(); + } + + // + if (isPositionOpened) { + // + bool canAlert = + alertPositions + && ( + hasLongSignal ? + longPositionAlerts + : + shortPositionAlerts + ); + + // + if (canAlert) { + // + // Alert Message ... + string message = StringConcatenate( + "Trade on Signal ID: ", request.signal.id, + ", ProvidedBy: ", GetProviderIdentifier(request.signal.provider), + ", Entry: ", request.signal.entry, + ", TP: ", request.signal.tp + ); + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } + } + } +} + +// +// Process All Open Positions ... +void ProcessOpenPositions() { + // + // XSignalling ... + if (enableXSignalling) { + // + // Close All XXX Provided Signals on it's Specific Condition ... + if (xCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XXX_PROVIDER); + + // + xCloseLongTrades = false; + } + + // + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + xMaximumCandlesPerTrade, + X_XXX_PROVIDER + ); + } + + // + // XR Signalling ... + if (enableXRSignalling) { + // + if (xrCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XR_PROVIDER); + + // + xrCloseLongTrades = false; + } + + // + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + xRMaximumCandlesPerTrade, + X_XR_PROVIDER + ); + } + + // + // Close Maximum DrawDown Passed Trades ... + bool hasClosedInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + maxDrawdownPercentPerPTrade + ); +} + +// +// Send Special Type of Alerts ... +void SendAlert(string message) { + // + if (!alertEvents) { + return; + } + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } +} +// +// END Functions ... +// + +// +// +// Calculate Signal ... +// in this function we calculate a signal exists in +// specific bar or not ... +XSignalRequest GenerateSignal( + const int bar_index // Bar Index ... +) { + // + // create temp result ... + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + bool hasSignal = false; + bool hasLongSignal = false; + bool hasShortSignal = false; + + // + XSignal signal = {}; + + // + // START XR Signal Handler ... + // + // + if (enableXRSignalling) { + // + CheckXRSignalHandler( + bar_index + ); + + // + // Long Trades ... + if (allowTrade && allowLongTrades) { + // + CheckXRLongSignalConditions( + bar_index + ); + + // + XSignalRequest xrLongSignalRequest = GenerateXRSignal( + X_SIGNAL_LONG, + signalPrefix, + bar_index + ); + + // + if (xrLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXRSignals( + xrLongSignalRequest.signal + ); + + // + if (isReady && xrWaitForLongSignals) { + // + hasLongSignal = true; + signal = xrLongSignalRequest.signal; + } else { + ClearXRLongSignalConditions(); + } + } + } + + // + // Short Trades ... + if (allowTrade && allowShortTrades) { + } + } + // + // END XR Signal Handler ... + // + + // + // START X Signal Handler ... + // + // + if (enableXSignalling) { + // + CheckXSignalHandler( + bar_index + ); + + // + // Long Trades ... + if (allowTrade && allowLongTrades) { + // + if (xWaitForLongSignals) { + // + CheckXLongSignalConditions( + bar_index + ); + + // + XSignalRequest xLongSignalRequest = GenerateXSignal( + X_SIGNAL_LONG, + signalPrefix, + bar_index + ); + + // + if (xLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXSignals( + xLongSignalRequest.signal + ); + + // + if (isReady && xWaitForLongSignals) { + // + hasLongSignal = true; + signal = xLongSignalRequest.signal; + } else { + ClearXLongSignalConditions(); + } + } + } else { + ClearXLongSignalConditions(); + } + } + // + // Short Trades ... + if (allowTrade && allowShortTrades) { + // + if (xWaitForShortSignals) { + // + CheckXShortSignalConditions( + bar_index + ); + + // + XSignalRequest xShortSignalRequest = GenerateXSignal( + X_SIGNAL_SHORT, + signalPrefix, + bar_index + ); + + // + if (xShortSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXSignals( + xShortSignalRequest.signal + ); + + // + if (isReady && xWaitForShortSignals) { + // + hasShortSignal = true; + signal = xShortSignalRequest.signal; + } else { + ClearXShortSignalConditions(); + } + } + } else { + ClearXShortSignalConditions(); + } + } + } + // + // END XR Signal Handler ... + // + + // + hasSignal = hasLongSignal || hasShortSignal; + + // + if (!hasSignal) { + // + signal.type = X_SIGNAL_NONE; + result.type = X_SIGNAL_NONE; + } + + // + // Normalize TP, SL and Entry Price ... + signal.tp = NormalizeDouble(signal.tp, _Digits); + signal.sl = NormalizeDouble(signal.sl, _Digits); + signal.entry = NormalizeDouble(signal.entry, _Digits); + + // + result.signal = signal; + result.type = signal.type; + result.hasSignal = hasSignal; + result.provider = signal.provider; + + // + // Return Result ... + return result; +} diff --git a/Bkp/Used/14020502/Indicators/x-saherelm.ma.mq4 b/Bkp/Used/14020502/Indicators/x-saherelm.ma.mq4 new file mode 100644 index 0000000..e3a5737 --- /dev/null +++ b/Bkp/Used/14020502/Indicators/x-saherelm.ma.mq4 @@ -0,0 +1,173 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MA Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 MA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Fast MA ... +input int maLength = 20; // MA Length +input int maShift = 0; // MA Shift +input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method +input ENUM_APPLIED_PRICE maAppliedPrice = PRICE_CLOSE; // MA Applied Price + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 1 + +// +#property indicator_plots 1 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Fast Ma Buffer ... +#property indicator_label1 "Ma" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrYellow +#property indicator_style1 STYLE_DOT +#property indicator_width1 2 + +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define maBufferIndex 0 + +double maBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (maLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + // + // Ma ... + SetIndexBuffer(maBufferIndex, maBuffer); + SetIndexDrawBegin(maBufferIndex, maLength + 1); + // + // End Set Index Buffers ... + // + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, maLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Ma ... + CalculateMa(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateMa( + const int &bar_index +) { + // + // Calculating Fast Ma ... + double ma = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + maAppliedPrice, + bar_index + ); + + // + maBuffer[bar_index] = ma; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020502/Indicators/x-saherelm.xtpow.mq4 b/Bkp/Used/14020502/Indicators/x-saherelm.xtpow.mq4 new file mode 100644 index 0000000..006b37a --- /dev/null +++ b/Bkp/Used/14020502/Indicators/x-saherelm.xtpow.mq4 @@ -0,0 +1,267 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center Trend Power Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 MA Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 7; // Market Length +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_separate_window + +// +#property indicator_plots 3 +#property indicator_buffers 3 +#property indicator_minimum 0 +#property indicator_maximum 100 + +// +#property indicator_levelcolor clrGray +#property indicator_levelstyle STYLE_DOT + +// +// Start Define Indicator Buffer Styles ... +// +#property indicator_type1 DRAW_HISTOGRAM +#property indicator_color1 clrLime +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +#property indicator_type2 DRAW_HISTOGRAM +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define powerUpBufferIndex 0 +#define powerDownBufferIndex 1 +#define signalBufferIndex 2 + +double powerUpBuffer[]; +double powerDownBuffer[]; +double signalBuffer[]; + +// +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (marketLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + SetLevelValue(0, 0.0); + IndicatorSetString(INDICATOR_LEVELTEXT,0,""); + + // + SetLevelValue(1, 20.0); + IndicatorSetString(INDICATOR_LEVELTEXT,1,""); + + // + SetLevelValue(2, 50); + IndicatorSetString(INDICATOR_LEVELTEXT,2,""); + + // + SetLevelValue(3, 100); + IndicatorSetString(INDICATOR_LEVELTEXT,3,""); + + // + string pUpLbl = StringConcatenate( + "P Up (", marketLength, ")" + ); + SetIndexLabel(powerUpBufferIndex, pUpLbl); + SetIndexBuffer(powerUpBufferIndex, powerUpBuffer); + SetIndexDrawBegin(powerUpBufferIndex, marketLength + 1); + + // + string pDownLbl = StringConcatenate( + "P Down (", marketLength, ")" + ); + SetIndexLabel(powerDownBufferIndex, pDownLbl); + SetIndexBuffer(powerDownBufferIndex, powerDownBuffer); + SetIndexDrawBegin(powerDownBufferIndex, marketLength + 1); + + // + string pSignalLbl = StringConcatenate( + "P Signal (", marketLength, ")" + ); + SetIndexLabel(signalBufferIndex, pSignalLbl); + SetIndexBuffer(signalBufferIndex, signalBuffer); + SetIndexDrawBegin(signalBufferIndex, marketLength + 1); + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "X_TPW_OSC"; + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Buffers ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateBuffers( + const int &bar_index +) { + // + double powerUp = 0; + double powerDown = 0; + + // + int dailyCount = GetDailyCandleCount(); + double dailyHH = GetMarketHighestHigh( + bar_index, + dailyCount + ); + double dailyLL = GetMarketLowestLow( + bar_index, + dailyCount + ); + double dailyDiff = dailyHH - dailyLL; + double rate = dailyDiff / 100; + + // + for (int i = bar_index; i < bar_index + marketLength; i++) { + // + XOHCL c = GetCandleModel(i); + + // + double cRange = + MathAbs(c.open - c.close) + // MathAbs(c.high - c.low) + ; + bool isBullish = c.open < c.close; + + // + if (isBullish) { + powerUp += cRange; + } else { + powerDown += cRange; + } + } + + // + powerUp = powerUp / rate; + powerDown = powerDown / rate; + + // + double ema = GetMA( + bar_index, + marketLength, + 0, + MODE_EMA, + PRICE_WEIGHTED + ); + + // + double signal = (ema / 100) * rate; + double signalAddition = MathMin(powerUp, powerDown); + + // + powerUpBuffer[bar_index] = powerUp; + powerDownBuffer[bar_index] = powerDown; + signalBuffer[bar_index] = signal + signalAddition; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020502/Libraries/x-saherelm.draw.lib.mq4 b/Bkp/Used/14020502/Libraries/x-saherelm.draw.lib.mq4 new file mode 100644 index 0000000..08fefa7 --- /dev/null +++ b/Bkp/Used/14020502/Libraries/x-saherelm.draw.lib.mq4 @@ -0,0 +1,1670 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Start Arrow Functions ... +// +// +// Draw an Arrow Object on Chart ... +bool DrawArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // arrow name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const uchar arrowCode = OBJ_ARROW_UP, // arrow code + const ENUM_ARROW_ANCHOR anchor = ANCHOR_BOTTOM, // anchor point position + const color clr = clrAqua, // arrow color + const ENUM_LINE_STYLE style = STYLE_SOLID, // border line style + const int width = 3, // arrow size + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // Order Object ... +) { + // + // set anchor point coordinates if they are not set ... + ChangeArrowEmptyPoint(time, price); + + // + // reset the error value ... + ResetLastError(); + + // + // create an arrow ... + if(!ObjectCreate(chartID, name, OBJ_ARROW, subWindow, time, price)) { + // + string message = StringConcatenate(__FUNCTION__, + ": failed to create an arrow! Error code = ", + GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the arrow code ... + ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, arrowCode); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set the arrow color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set the border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set the arrow's size ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the arrow by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is false by default, if you want making it possible to highlight and move the object + // change it to true ... + ObjectSetInteger(chartID,name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point of Arrow ... +bool MoveArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if(!time) { + time = TimeCurrent(); + } + + // + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete an arrow ... +bool DeleteArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow" // arrow name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete an arrow ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete an arrow! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the arrow code ... +bool ArrowCodeChange( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + const uchar code = 252 // arrow code +) { + // + // reset the error value ... + ResetLastError(); + + // + // change the arrow code ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, code)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the arrow code! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change anchor type ... +bool ArrowAnchorChange( + const long chartID = 0, // chart's ID + const string name="Arrow", // object name + const ENUM_ARROW_ANCHOR anchor = ANCHOR_TOP // anchor type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change anchor type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change anchor type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeArrowEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } +} +// +// End Arrow Functions ... +// + +// +// Start Horizontal Line Functions ... +// +// +// Create, Draw the horizontal line ... +bool DrawHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + const int subWindow = 0, // subwindow index + double price = 0, // line price + const color clr = clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the price is not set, set it at the current Bid price level ... + if(!price) { + price=SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // create a horizontal line ... + if(!ObjectCreate(chartID, name, OBJ_HLINE, subWindow, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move horizontal line ... +bool MoveHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + double price = 0 // line price +) { + // + // if the line price is not set, move it to the current Bid price level ... + if(!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move a horizontal line ... + if(!ObjectMove(chartID, name, 0, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete a horizontal line ... +bool DeleteHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a horizontal line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End Horizontal Line Functions ... +// + +// +// Start Vertical Line Functions ... +// +// +// Create the vertical line ... +bool DrawVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + const int sub_window = 0, // subwindow index + datetime time = 0, // line time + const color clr=clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the line time is not set, draw it via the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value + ResetLastError(); + + // + // create a vertical line ... + if (!ObjectCreate(chartID, name, OBJ_VLINE, sub_window, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return true; +} + +// +// Move the vertical line ... +bool MoveVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + datetime time = 0 // line time +) { + // + // if line time is not set, move the line to the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the vertical line ... + if(!ObjectMove(chartID, name, 0, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the vertical line ... +bool DeleteVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the vertical line ... + if (!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // successful execution ... + return true; +} +// +// End Vertical Line Functions ... +// + +// +// Start RectangleLabel Functions ... +// +// +// Create Rectangle Label Object ... +bool DrawRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int subWindow = 0, // subwindow index + const int x = 0, // X coordinate + const int y = 0, // Y coordinate + const int width = 50, // width + const int height = 18, // height + const color back_clr = C'236,233,216', // background color + const ENUM_BORDER_TYPE border = BORDER_SUNKEN, // border type + const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring + const color clr = clrRed, // flat border color (Flat) + const ENUM_LINE_STYLE style = STYLE_SOLID, // flat border style + const int lineWidth = 1, // flat border width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // reset the error value ... + ResetLastError(); + + // + //--- create a rectangle label + if(!ObjectCreate(chartID, name, OBJ_RECTANGLE_LABEL, subWindow, 0, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set label coordinates ... + ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x); + ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y); + + // + // set label size ... + ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width); + ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height); + + // + // set background color ... + ObjectSetInteger(chartID, name, OBJPROP_BGCOLOR, back_clr); + + // + // set border type ... + ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border); + + // + // set the chart's corner, relative to which point coordinates are defined ... + ObjectSetInteger(chartID, name, OBJPROP_CORNER, corner); + + // + // set flat border color (in Flat mode) ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set flat border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set flat border width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, lineWidth); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the label by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move Rectangle Label .. +bool MoveRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int x = 0, // X coordinate + const int y=0 // Y coordinate +) { + // + // reset the error value ... + ResetLastError(); + + // + // move the rectangle label ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move X coordinate of the label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move Y coordinate of the label! Error code = ",GetLastError() + ); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the rectangle label ... +bool DeleteRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel" // label name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the label ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change Rectangle Label Size ... +bool ChangeSizeRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int width = 50, // label width + const int height = 18 // label height +) { + // + // reset the error value ... + ResetLastError(); + + // + // change label size ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's width! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's height! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change rectangle label border type ... +bool RectLabelChangeBorderType( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const ENUM_BORDER_TYPE border = BORDER_SUNKEN // border type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change border type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the border type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End RectangleLabel Functions ... +// + +// +// Start TrendLine Funcions ... +// +// Create a trend line by the given coordinates ... +bool DrawTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrYellow, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool rayRight = false, // line's continuation to the right + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeTrendLineEmptyPoints( + time1, + price1, + time2, + price2 + ); + + // + // reset the error value ... + ResetLastError(); + + // + // create a trend line by the given coordinates ... + if(!ObjectCreate(chartID, name, OBJ_TREND, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the line's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move trend line anchor point ... | +bool ChangeTrendLinePoint( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int pointindex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move trend line's anchor point ... + if(!ObjectMove(chartID, name, pointindex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// The function deletes the trend line from the chart ... +bool DeleteTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a trend line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of trend line's anchor points and set default ... +// values for empty ones ... +void ChangeTrendLineEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the first point's time is not set, it will be on the current bar ... + if (!time1) { + time1 = TimeCurrent(); + } + + // + // if the first point's price is not set, it will have Bid value ... + if (!price1) { + price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // if the second point's time is not set, it is located 9 bars left from the second one ... + if (!time2) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(), Period(), time1, 10, temp); + + // + // set the second point 9 bars left from the first one ... + time2 = temp[0]; + } + + // + // if the second point's price is not set, it is equal to the first point's one ... + if (!price2) { + price2 = price1; + } +} +// +// End TrendLine Functions ... +// + +// +// Start Text Functions ... +// +// Create and Draw a Text Object ... +bool DrawText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const string text = "Text", // the text itself + const string font = "Arial", // font + const int fontSize = 10, // font size + const color clr = clrRed, // color + const double angle = 0.0, // text slope + const ENUM_ANCHOR_POINT anchor = ANCHOR_CENTER, // anchor type + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor point coordinates if they are not set ... + ChangeTextEmptyPoint(time,price); + + // + // reset the error value ... + ResetLastError(); + + // + //--- create Text object + if(!ObjectCreate(chartID, name, OBJ_TEXT, subWindow, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the text ... + ObjectSetString(chartID, name , OBJPROP_TEXT, text); + + // + // set text font ... + ObjectSetString(chartID, name, OBJPROP_FONT, font); + + // + // set font size ... + ObjectSetInteger(chartID, name, OBJPROP_FONTSIZE, fontSize); + + // + // set the slope angle of the text ... + ObjectSetDouble(chartID, name, OBJPROP_ANGLE, angle); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the object by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID ,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point ... +bool MoveText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + //--- if point position is not set, move it to the current bar having Bid price + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point .. + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the object text ... +bool ChangeText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const string text = "Text" // text +) { + // + // reset the error value ... + ResetLastError(); + + // + // change object text ... + if(!ObjectSetString(chartID, name, OBJPROP_TEXT, text)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the text! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Text object ... +bool DeleteText( + const long chartID = 0, // chart's ID + const string name = "Text" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeTextEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + } +// +// End Text Functions ... +// + +// +// Start Fibonacchi Functions ... +// +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawFibonacci( + const long chartID = 0, // chart's ID + const string name="Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrRed, // object color + const ENUM_LINE_STYLE style = STYLE_SOLID, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawCustomFibonacci( + // + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + // + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrAqua, // object color + const ENUM_LINE_STYLE style = STYLE_DOT, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // Change Levels Of Fibonacci ... + bool result = FibonacciLevelsSet( + levels, + values, + colors, + styles, + widths, + descriptions, + chartID, + name + ); + + // + // successful execution ... + return result; +} + +// +// Set number of levels and their parameters ... +bool FibonacciLevelsSet( + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // check array sizes ... + if( + levels!=ArraySize(colors) || + levels!=ArraySize(styles) || + levels!=ArraySize(widths) || + levels!=ArraySize(widths) + ) { + // + string message = StringConcatenate( + __FUNCTION__, + ": array length does not correspond to the number of levels, error!" + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the number of levels ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELS, levels); + + // + // set the properties of levels in the loop ... + for(int i = 0; i < levels; i++) { + // + // level value ... + ObjectSetDouble(chartID, name, OBJPROP_LEVELVALUE, i, values[i]); + + // + // level color ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELCOLOR, i, colors[i]); + + // + // level style ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELSTYLE, i, styles[i]); + + // + // level width ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELWIDTH, i, widths[i]); + + // + // level description ... + // ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, DoubleToString(100 * values[i], 1)); + ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, descriptions[i]); + } + + // + // successful execution ... + return(true); +} + +// +// Move Fibonacci Retracement anchor point ... +bool FibonacciPointChange( + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int pointIndex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, pointIndex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Fibonacci Retracement ... +bool DeleteFibonachi( + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Fibonacci Retracement\"! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of Fibonacci Retracement anchor points and set +// default values for empty ones ... +void ChangeFibonacciEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the second point's time is not set, it will be on the current bar ... + if (!time2) { + time2 = TimeCurrent(); + } + + // + // if the second point's price is not set, it will have Bid value ... + if (!price2) { + price2 = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // if the first point's time is not set, it is located 9 bars left from the second one ... + if (!time1) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(),Period(),time2,10,temp); + + // + // set the first point 9 bars left from the second one ... + time1 = temp[0]; + } + + // + // if the first point's price is not set, move it 200 points below the second one ... + if (!price1) { + price1 = price2 - 200 * SymbolInfoDouble(_Symbol, SYMBOL_POINT); + } +} +// +// End Fibonacci Functions ... +// + + +// +// Start General Functions ... +// +// +// Remove all Drawn Objects ... +void RemoveDraws(const string &tag) { + // + for(int iObj=ObjectsTotal()-1; iObj >= 0; iObj--) { + // + string on = ObjectName(iObj); + if (StringFind(on, tag) == 0) { + ObjectDelete(on); + } + } +} +// +// End General Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020502/Libraries/x-saherelm.indicator.lib.mq4 b/Bkp/Used/14020502/Libraries/x-saherelm.indicator.lib.mq4 new file mode 100644 index 0000000..948d5a7 --- /dev/null +++ b/Bkp/Used/14020502/Libraries/x-saherelm.indicator.lib.mq4 @@ -0,0 +1,350 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Indicator Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +double ReadXMABuffer( + const int bar_index, + const int buffer_index, + // + const int marketLen, + // + const double stp, + const double mxm, + // + const int shortCycleMult, + const int mediumCycleMult, + const int longCycleMult +) { + // + string xmaIndicatorName = "x-saherelm.x.xma"; + + // + double result = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // Inputs ... + marketLen, + stp, + mxm, + shortCycleMult, + mediumCycleMult, + longCycleMult, + MODE_SMA, + // + buffer_index, + bar_index + ); + + // + return result; +} + +// +double ReadXHLBuffer( + const int bar_index, + const int buffer_index, + // + const int marketLen, + // + const int shortCycleMult, + const int mediumCycleMult, + const int longCycleMult +) { + // + string xhlIndicatorName = "x-saherelm.x.hl"; + + // + double result = iCustom( + _Symbol, + _Period, + xhlIndicatorName, + // + // Inputs ... + marketLen, + shortCycleMult, + mediumCycleMult, + longCycleMult, + MODE_SMA, + // + buffer_index, + bar_index + ); + + // + return result; +} + +// +double ReadADX( + const int bar_index, + const int marketLen, + const int mult +) { + // + double result; + + // + int period = marketLen * mult; + + // + result = iADX( + _Symbol, + _Period, + period, + PRICE_CLOSE, + MODE_MAIN, + bar_index + ); + + // + return result; +} + +// +static XRState lastXRState; +XRState GetXRange( + const int bar_index, + const int rangeMarketLength +) { + // + XRState result = {}; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + int marketBarIndex = bar_index + rangeMarketLength; + + // + // Highest High ... + // + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketBarIndex, + bar_index + ); + + // + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + // Lowest Low ... + // + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketBarIndex, + bar_index + ); + + // + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + if (lastXRState.start == 0) { + // + lastXRState.start = barTime; + lastXRState.length = rangeMarketLength; + + // + lastXRState.hh = hh; + lastXRState.ll = ll; + + // + // Middle ... + double mid = (hh + ll) / 2; + lastXRState.mid = mid; + } else { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + lastXRState.start + ); + + // + if (startBarIndex - bar_index >= rangeMarketLength) { + // + lastXRState.start = barTime; + lastXRState.length = rangeMarketLength; + + // + lastXRState.hh = hh; + lastXRState.ll = ll; + + // + // Middle ... + double mid = (hh + ll) / 2; + lastXRState.mid = mid; + } + } + + // + result = lastXRState; + + // + return result; +} + +// +XTPOWStatee GetXTPowState( + const int bar_index, + const int marketLen +) { + // + XTPOWStatee result = {}; + + // + // + double powerUp = 0; + double powerDown = 0; + double signal = 0; + + // // + // int dailyCount = GetDailyCandleCount(); + // double dailyHH = GetMarketHighestHigh( + // bar_index, + // dailyCount + // ); + // double dailyLL = GetMarketLowestLow( + // bar_index, + // dailyCount + // ); + // double dailyDiff = dailyHH - dailyLL; + // double rate = dailyDiff / 100; + + // // + // for (int i = bar_index; i < bar_index + marketLen; i++) { + // // + // XOHCL c = GetCandleModel(i); + + // // + // double cRange = + // MathAbs(c.open - c.close) + // // MathAbs(c.high - c.low) + // ; + // bool isBullish = c.open < c.close; + + // // + // if (isBullish) { + // powerUp += cRange; + // } else { + // powerDown += cRange; + // } + // } + + // // + // powerUp = powerUp / rate; + // powerDown = powerDown / rate; + + // // + // double ema = GetMA( + // bar_index, + // marketLen, + // 0, + // MODE_EMA, + // PRICE_WEIGHTED + // ); + + // // + // double signalAddition = MathMin(powerUp, powerDown); + // signal = (ema / 100) * rate + signalAddition; + + // + string indicatorName = "x-saherelm.xtpow"; + + // + int pUpIndex = 0; + int pDownIndex = 1; + int signalIndex = 2; + + // + powerUp = iCustom( + _Symbol, + _Period, + indicatorName, + // + marketLen, + // + pUpIndex, + bar_index + ); + + // + powerDown = iCustom( + _Symbol, + _Period, + indicatorName, + // + marketLen, + // + pDownIndex, + bar_index + ); + + // + signal = iCustom( + _Symbol, + _Period, + indicatorName, + // + marketLen, + // + signalIndex, + bar_index + ); + + // + result.signal = signal; + result.powerUp = powerUp; + result.powerDown = powerDown; + + // + return result; +} +// +// END Indicator Reading Data ... +// diff --git a/Bkp/Used/14020502/Libraries/x-saherelm.lib.mq4 b/Bkp/Used/14020502/Libraries/x-saherelm.lib.mq4 new file mode 100644 index 0000000..e2124e3 --- /dev/null +++ b/Bkp/Used/14020502/Libraries/x-saherelm.lib.mq4 @@ -0,0 +1,1604 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +struct XOHCL { + double high; + double open; + double close; + double low; +}; + +// +struct XRange { + // + datetime time; + + // + double highestHigh; + double lowestLow; + + // + int levels; + int marketLength; + + // + double rate; +}; + +// +static datetime lastBarTime; + +// +// START Functions ... +// + +// +// Determines current working is New Bar or not ... +bool IsNewBar() { + // + // Reading Last Bar Date ... + datetime curbar = (datetime)SeriesInfoInteger( + _Symbol, + _Period, + SERIES_LASTBAR_DATE + ); + + // + if(lastBarTime != curbar) { + // + lastBarTime = curbar; + return true; + } + + // + return false; +} + +// +// Determines we are in new Day or not ... +bool IsNewDay() { + // + bool result = false; + + // + // Reading Last Bar Date ... + datetime curbar = (datetime)SeriesInfoInteger( + _Symbol, + _Period, + SERIES_LASTBAR_DATE + ); + + // + if (lastBarTime == 0) { + lastBarTime = curbar; + } + + // + if (curbar == lastBarTime) { + return result; + } + + // + // Retrieve Day and Month and Year for Last Bar Time ... + int lastBarDay = TimeDay(lastBarTime); + int lastBarMonth = TimeMonth(lastBarTime); + int lastBarYear = TimeYear(lastBarTime); + + // + // Retrieve Day and Month and Year for Current Bar Time ... + int curBarDay = TimeDay(curbar); + int curBarMonth = TimeMonth(curbar); + int curBarYear = TimeYear(curbar); + + // + result = curBarDay > lastBarDay + || curBarMonth > lastBarMonth + || curBarYear > lastBarYear; + + // + return result; +} + +// +// Retrieve Number of Candles in a Day ... +int GetDailyCandleCount() { + // + int seconds = PeriodSeconds(_Period); + + // + int daySeconds = 24 * 60 * 60; + + // + int result = daySeconds / seconds; + + // + return result; +} + +// +// XRange Detector ... +XRange GetMarketRange( + const int bar_index, + const int marketLen, + const int levels +) { + // + XRange result = {}; + + // + result.levels = levels; + result.marketLength = marketLen; + + // + datetime time = iTime( + _Symbol, + _Period, + bar_index + ); + result.time = time; + + // + double highestHigh = GetMarketHighestHigh( + bar_index, + marketLen + ); + result.highestHigh = highestHigh; + + // + double lowestLow = GetMarketLowestLow( + bar_index, + marketLen + ); + result.lowestLow = lowestLow; + + // + double diff = highestHigh - lowestLow; + double rate = diff / levels; + + // + result.rate = rate; + + // + return result; +} + +// +// Retrieve RMA on Specific Candle ... +double GetRMA( + int bar_index, + int length +) { + // + double shortSMA = iMA(_Symbol, _Period, length, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double mediumSMA = iMA(_Symbol, _Period, length * 2, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double longSMA = iMA(_Symbol, _Period, length * 3, 0, MODE_SMA, PRICE_CLOSE, bar_index); + + // + double result = longSMA - mediumSMA + shortSMA; + + // + return result; +} + +// +double GetMA( + const int bar_index, + const int maLength, + const int maShift, + const ENUM_MA_METHOD maMethod, + const ENUM_APPLIED_PRICE appliedPrice +) { + // + double result = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + appliedPrice, + bar_index + ); + + // + return result; +} + +// +// Calculate Fib Level ... +double GetFibonacciLevel( + double upPrice, + double downPrice, + double level, + int direction +) { + // + double ling = upPrice - downPrice; + double pLevel = (ling / 100) * (level * 100); + + // + double result = direction > 0 ? + upPrice - pLevel : + downPrice + pLevel; + result = NormalizeDouble(result, _Digits); + + // + return result; +} + +// +// Retrieve True Range ... +double GetTR( + const int bar_index +) { + // + double result = 0; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double prevClose = iClose( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double highLowDif = high - low; + double hpCDif = MathAbs(high - prevClose); + double lpCDiff = MathAbs(low - prevClose); + + // + result = MathMax(highLowDif, hpCDif); + result = MathMax(result, lpCDiff); + + // + return result; +} + +// +// Calculate True Range Simple Moving Average ... +double GetMarketTRSMA( + const int bar_index, + const int marketLen +) { + // + double result = 0; + + // + // Create Barket Length Trs ... + double trs[]; + ArrayResize( + trs, + marketLen + ); + int index = 0; + double trSum = 0; + for (int i = bar_index; i < bar_index + marketLen; i++) { + // + double tr = GetTR(i); + trs[index] = tr; + + // + trSum += tr; + + // + index++; + } + + // + result = trSum / marketLen; + + // + return result; +} + +// +// Retrieve Commodity Channel ... +double GetMarketCCI( + const int bar_index, + const int marketLen, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE +) { + // + double result = 0; + + // + result = iCCI( + _Symbol, + _Period, + marketLen, + appliedPrice, + bar_index + ); + + // + return result; +} + +// +// this function check crossing up two Buffers ... +bool IsCrossedOver( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] > arr2[index1]) && !(arr1[index2] > arr2[index2]); + + // + return result; +} + +// +// this function check crossing down two Buffers ... +bool IsCrossedUnder( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] < arr2[index1]) && !(arr1[index2] < arr2[index2]); + + // + return result; +} + +// +// Convert points to Actual Point ... +double PointsToDouble(int points) { + // + double result = points * _Point; + return result; +} + +// +// Converts Pips to Points ... +int PipsToPoints(int pips) { + // + int result = pips * ((_Digits == 3 || _Digits == 5) ? 10 : 1); + return result; +} + +// +// Converts Pips to Double ... +double PipsToDouble(int pips) { + // + double result = PointsToDouble(PipsToPoints(pips)); + return result; +} + +// +// Converts Double Value to Pips ... +int PriceToPips(double value) { + // + if (value <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + int result = (int)(value / pipValue); + + // + return result; +} + +// +// Converts Pips to Double ... +double PipsToPrice(int pips) { + // + if (pips <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + double result = pipValue * pips; + + // + return result; +} + +// +// Generate ATR StopLoss Value ... +double CalculateATRSL( + int period, + double multiplier +) { + // + if (period <= 0 || multiplier <= 0) { + return 0; + } + + // + double atrValue = iATR( + _Symbol, + _Period, + period, + 0 + ); + + // + double result = atrValue * multiplier; + + // + return result; +} + +// +// Detect Candle Type ... +// Bullish => means close > open ... +bool IsBullishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBullishCandle( + open, + close + ); + + // + return result; +} + +bool IsBullishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open < close; + + // + return result; +} + +// +// Detect Candle Type ... +// Bearish => means close < open ... +bool IsBearishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBearishCandle( + open, + close + ); + + // + return result; +} + +bool IsBearishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open > close; + + // + return result; +} + +// +// Retrieve a Candle Info ... +XOHCL GetCandleModel( + const int bar_index +) { + // + XOHCL result = {}; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + result.high = high; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + result.open = open; + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + result.close = close; + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + result.low = low; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBullishDetected( + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double shpDetectMultipliers // Sharp Detect Multiplier +) { + // + bool result = false; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double minValue = 0; + double maxValue = 0; + int positionedLength = bar_index + marketLen; + + // + for (int i = bar_index; i < positionedLength; i++) { + // + double cHigh = iHigh( + _Symbol, + _Period, + i + ); + + // + double cLow = iLow( + _Symbol, + _Period, + i + ); + + // + minValue += MathMin(cLow, cHigh); + maxValue += MathMax(cLow, cHigh); + } + + // + double minAvg = minValue / positionedLength; + double maxAvg = maxValue / positionedLength; + + // + double shpValue = shpDetectMultipliers * _Point; + + // + result = (low - minAvg) > shpValue; + + // + int index = bar_index; + while ( + index < positionedLength + || !result + ) { + // + low = iLow( + _Symbol, + _Period, + index + ); + + // + result = result + || (low - minAvg) > shpValue; + + // + index++; + }; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBearishDetected( + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double shpDetectMultipliers // Sharp Detect Multiplier +) { + // + bool result = false; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double minValue = 0; + double maxValue = 0; + int positionedLength = bar_index + marketLen; + + // + for (int i = bar_index; i < positionedLength; i++) { + // + double cHigh = iHigh( + _Symbol, + _Period, + i + ); + + // + double cLow = iLow( + _Symbol, + _Period, + i + ); + + // + minValue += MathMin(cLow, cHigh); + maxValue += MathMax(cLow, cHigh); + } + + // + double minAvg = minValue / positionedLength; + double maxAvg = maxValue / positionedLength; + + // + double shpValue = shpDetectMultipliers * _Point; + + // + result = (high - maxAvg) > shpValue; + + // + int index = bar_index; + while ( + index < positionedLength + || !result + ) { + // + high = iHigh( + _Symbol, + _Period, + index + ); + + // + result = result + || (high - maxAvg) > shpValue; + + // + index++; + }; + + // + return result; +} + +// +// Retrieve Highest High Value based on Given Market ... +double GetMarketHighestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Low Value based on Given Market ... +double GetMarketHighestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Open Value based on Given Market ... +double GetMarketHighestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Close Value based on Given Market ... +double GetMarketHighestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Low Value based on Given Market ... +double GetMarketLowestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest High Value based on Given Market ... +double GetMarketLowestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Open Value based on Given Market ... +double GetMarketLowestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Close Value based on Given Market ... +double GetMarketLowestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// less than given price ... +double GetLowLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// great than given price ... +double GetLowGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// less than given price ... +double GetHighLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// great than given price ... +double GetHighGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// less than given price ... +double GetCloseLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// great than given price ... +double GetCloseGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Get Slope of a Line by it's two Point ... +double GetSlope( + double x1, + double y1, + double x2, + double y2 +) { + // + double result = (y2 - y1)/MathAbs(x2 - x1); + return result; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020502/Libraries/x-saherelm.log.lib.mq4 b/Bkp/Used/14020502/Libraries/x-saherelm.log.lib.mq4 new file mode 100644 index 0000000..066b3f7 --- /dev/null +++ b/Bkp/Used/14020502/Libraries/x-saherelm.log.lib.mq4 @@ -0,0 +1,91 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Log Tag ... +static string logTag = ""; + +// +// Enable or Disable Logging ... +static bool enableLogging = false; + +// +// Start Log Messages ... +// + +// +// Logging a Message, specified for this EA ... +// using provided LogTag ... +void LogMessage(string message) { + // + if (!enableLogging) { + return; + } + + // + Print(logTag, " > ", message); +} + +// +// this used for logging series ... +void LogSeries( + double &series[], // which series to Log ... + int length = 0, // number of items to Log, 0 means all ... + int skip = 0 // number of items which skip before logging ... +) { + // + string msg = ""; + + // + int seriesSize = ArraySize(series); + if ( + skip < 0 + || length < 0 + || seriesSize == 0 + || skip > seriesSize + || skip + length > seriesSize + ) { + return; + } + + // + length = length == 0 ? + seriesSize : + length; + int start = skip > 1 ? + skip - 1 : + skip == 1 ? + 1 : + 0; + + // + // Loop through series items ... + for (int i = start; i < start + length; i++) { + // + msg += StringConcatenate( + "i[", i, "]: ", series[i], ", " + ); + } + + // + LogMessage(msg); +} +// +// End Log Messages ... +// + diff --git a/Bkp/Used/14020502/Libraries/x-saherelm.models.lib.mq4 b/Bkp/Used/14020502/Libraries/x-saherelm.models.lib.mq4 new file mode 100644 index 0000000..150bacf --- /dev/null +++ b/Bkp/Used/14020502/Libraries/x-saherelm.models.lib.mq4 @@ -0,0 +1,137 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Models Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// START STATIC Variables ... +// +// +static int totalSignals = 0; +static int totalLongSignals = 0; +static int totalShortSignals = 0; + +// +static double initialBalance = 0; + +// +static int countedBars = 0; +static bool isNewBar = false; +static bool isNewDay = false; +// +// END STATIC Variables ... +// + +// +// Start Models ... +// +// +// Signal Providers ... +enum ENUM_X_SIGNAL_PROVIDER { + X_UNKNOWN_PROVIDER, + X_XXX_PROVIDER, + X_XR_PROVIDER +}; + +// +// these are different signal types ... +enum ENUM_X_SIGNAL_TYPE { + X_SIGNAL_NONE, + X_SIGNAL_LONG, + X_SIGNAL_SHORT, +}; + +// +// we Model each signals as this type ... +struct XSignal { + // + // Signal Symbol ... + string symbol; + + // + // Signal Type ... + ENUM_X_SIGNAL_TYPE type; + + // + // Signal ID ... + int id; + + // + // Signal Ticket Number, when Opening Trade ... + int ticket; + + // + // Signal Provider ... + ENUM_X_SIGNAL_PROVIDER provider; + + // + // Target Point ... + double tp; + + // + // Stop Loss ... + double sl; + + // + // Signal Entry Price ... + double entry; + + // + // Signalling Time ... + datetime time; + + // + // Signal Comments ... + string comment; + + // + // Signal TAG ... + string tag; +}; + +// +// this is Signal Request Response model ... +struct XSignalRequest { + bool hasSignal; + XSignal signal; + ENUM_X_SIGNAL_TYPE type; + ENUM_X_SIGNAL_PROVIDER provider; +}; + +// +struct XRState { + // + datetime start; + int length; + + // + double hh; + double ll; + double mid; +}; + +// +struct XTPOWStatee { + // + double powerUp; + double powerDown; + + // + double signal; +}; +// +// End Models ... +// diff --git a/Bkp/Used/14020502/Libraries/x-saherelm.signal.lib.mq4 b/Bkp/Used/14020502/Libraries/x-saherelm.signal.lib.mq4 new file mode 100644 index 0000000..db67c0c --- /dev/null +++ b/Bkp/Used/14020502/Libraries/x-saherelm.signal.lib.mq4 @@ -0,0 +1,1525 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Signal Draw Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +#include "../Libraries/x-saherelm.x.signal.lib.mq4" +#include "../Libraries/x-saherelm.xr.signal.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// END Global Requirement Functions ... +// + +// +// START Signal Related Functions ... +// +// +// Retrieve Signal Bar Index ... +int GetSignalBarIndex(XSignal &signal) { + // + // Temp Result ... + int result = -1; + + // + // Retriev Signal Bar Index ... + result = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + return result; +} + +// +string GetProviderIdentifier( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + string result = ""; + + // + switch (provider) { + // + case X_XXX_PROVIDER: + result = "XXX"; + break; + + // + case X_XR_PROVIDER: + result = "XR"; + break; + + // + default: + result = ""; + break; + } + + // + return result; +} + +// +ENUM_X_SIGNAL_PROVIDER GetProvider(string identifier) { + // + ENUM_X_SIGNAL_PROVIDER result = X_UNKNOWN_PROVIDER; + + // + if ( + StringFind( + identifier, + GetProviderIdentifier(X_XXX_PROVIDER) + ) > -1 + ) { + result = X_XXX_PROVIDER; + } else if ( + StringFind( + identifier, + GetProviderIdentifier(X_XR_PROVIDER) + ) > -1 + ) { + result = X_XR_PROVIDER; + } + + // + return result; +} + +// +void DrawRange( + const XRange &range, + const long chartID = 0, + const int subWindowID = 0, + const string tag = "", + const color clr = clrYellow +) { + // + // Loop through Levels Count ... + for (int i = 0; i <= range.levels; i++) { + // + datetime time1 = iTime( + _Symbol, + _Period, + 1 + ); + + // + datetime time2 = iTime( + _Symbol, + _Period, + 0 + ); + + // + double price = range.lowestLow + (i * range.rate); + + // + string lbl = StringConcatenate( + tag, + "_XRL_", + price + ); + + // + DrawTrendLine( + chartID, + lbl, + subWindowID, + time1, + price, + time2, + price, + clr, + STYLE_DOT + ); + } +} + +// +// Draw Signal Shapes on Chart ... +bool DrawSignal( + const XSignal &signal, + long chartID = 0, + int subWindowID = 0, + const double positionThresholdFactor = 10, + string longSignalLabel = "X-Long", + color longSignalColor = clrAqua, + string shortSignalLabel = "X-Short", + color shortSignalColor = clrFuchsia +) { + // + // Generate isLongSignal Var ... + bool isLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Signal Bar Index ... + int bar_index = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // START Draw Signal Arrow ... + // + // + // Arrow Shape Name ... + string arrowName = StringConcatenate(signal.tag, "_Arrow_", signal.id); + + // + // Arrow Price ... + double arrowPrice = 0; + if (isLongSignal) { + // + arrowPrice = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice - (positionThresholdFactor * _Point); + } else { + // + arrowPrice = iHigh( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice + (positionThresholdFactor * _Point); + } + + // + // Arrow Code ... + uchar arrowCode = isLongSignal ? SYMBOL_ARROWUP : SYMBOL_ARROWDOWN; + + // + // Arrow Anchor Point ... + ENUM_ARROW_ANCHOR arrowAnchorPoint = isLongSignal ? ANCHOR_BOTTOM : ANCHOR_TOP; + + // + // Arrow Color ... + color arrowColor = isLongSignal ? longSignalColor : shortSignalColor; + + // + // Draw Signal Arrow Shape ... + bool result = DrawArrow( + chartID, + arrowName, + subWindowID, + signal.time, + arrowPrice, + arrowCode, + arrowAnchorPoint, + arrowColor + ); + // + // END Draw Signal Arrow ... + // + + // + // START Draw Signal SL/TP ... + // + string slLineName = StringConcatenate(signal.tag, "_SL_", signal.id); + string tpLineName = StringConcatenate(signal.tag, "_TP_", signal.id); + string entryLineName = StringConcatenate(signal.tag, "_ENTRY_", signal.id); + + // + color slColor = shortSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color tpColor = longSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color entryColor = clrGreen; + + // + datetime time1 = iTime( + _Symbol, + _Period, + bar_index + 1 + ); + + // + // Draw Enrty Price ... + result = DrawTrendLine( + chartID, + entryLineName, + subWindowID, + time1, + signal.entry, + signal.time, + signal.entry, + entryColor, + STYLE_SOLID, + 2 + ); + + // + // Draw Signal SL ... + if (signal.sl > 0) { + // + result = DrawTrendLine( + chartID, + slLineName, + subWindowID, + time1, + signal.sl, + signal.time, + signal.sl, + slColor, + STYLE_SOLID, + 2 + ); + } + + // + // Draw Signal TP ... + if (signal.tp > 0) { + // + result = DrawTrendLine( + chartID, + tpLineName, + subWindowID, + time1, + signal.tp, + signal.time, + signal.tp, + tpColor, + STYLE_SOLID, + 2 + ); + } + // + // END Draw Signal SL/TP ... + // + + // + // Start Draw Signal Label ... + // + // + string labelName = StringConcatenate(signal.tag, "_Label_", signal.id); + + // + double labelPrice = isLongSignal ? arrowPrice - (positionThresholdFactor * _Point) : arrowPrice + (positionThresholdFactor * _Point); + + // + string labelText = isLongSignal ? longSignalLabel : shortSignalLabel; + labelText = StringConcatenate( + labelText, + "_", + GetProviderIdentifier(signal.provider) + ); + + // + result = DrawText( + chartID, + labelName, + subWindowID, + signal.time, + labelPrice, + labelText, + "Arial", + 8, + arrowColor, + 0, + ANCHOR_CENTER + ); + // + // End Draw Signal Label ... + // + + // + return result; +} + +// +// Trade on Specific Signal ... +bool TradeSignal( + XSignal &signal, + // + double volumePercent, + // + // Long ... + const string longSignalLabel, + const color longSignalColor, + // + // Short ... + const string shortSignalLabel, + const color shortSignalColor +) { + // + // Temp Result ... + bool result = false; + + // + if (initialBalance == 0) { + initialBalance = AccountInfoDouble(ACCOUNT_BALANCE); + } + + // + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + int openPositions = CountOpenTrades(); + double volume = (volumePercent * initialBalance); + + // + if ( + signal.type != X_SIGNAL_LONG && + signal.type != X_SIGNAL_SHORT + ) { + return result; + } + + // + bool hasLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Check TP and Entry Price ... + if ( + ( + hasLongSignal + && signal.entry > signal.tp + ) || + ( + !hasLongSignal + && signal.entry < signal.tp + ) + ) { + return result; + } + + // + // Order Operation ... + int operation = hasLongSignal ? + OP_BUY : + OP_SELL; + + // + // Detect Trade Color ... + color clr = hasLongSignal ? + longSignalColor : + shortSignalColor; + + // + // Generate Signal Comment ... + string label = hasLongSignal ? + longSignalLabel : + shortSignalLabel; + + // + // Generate Signal Comment ... + string comment = StringConcatenate( + signal.tag, + "_", signal.id, + "_", GetProviderIdentifier(signal.provider), + "_", label + ); + + // + // Placing Order ... + int orderTicket = OrderSend( + _Symbol, + operation, + volume, + signal.entry, + 3, + signal.sl, + signal.tp, + comment, + signal.id, + 0, + clr + ); + + // + // Draw Signal Shape if Order Opened Successfully ... + if (orderTicket >= 0) { + // + signal.ticket = orderTicket; + + // + // Here i must to Draw Signal Shapes ... + bool isDrawn = DrawSignal( + signal, + 0, + 0, + 50, + longSignalLabel, // Long Signal Label ... + longSignalColor, + shortSignalLabel, // Short Signal Label ... + shortSignalColor + ); + + // + LogMessage( + StringConcatenate( + "Order [", orderTicket ,"]: Provided by: ", GetProviderIdentifier(signal.provider) + ) + ); + + // + // TODO: here we have to check if there are another + // open positions which their entry price is bigger + // than current signal entry price, for long trades and + // their tp is high than current tp, ... + // close in profit trades or modify orders tp to current ... + // // + // if (CountOpenTrades() > 0) { + // // + // // Here we have to + // // ModifyOpenTradesBasedOnCurrentTrade(signal); + // } + + // + result = true; + } + + // + return result; +} +// +// END Signal Related Functions ... +// + +// +// START Orders Functions ... +// +// +// Convert To XSignal Model ... +XSignal OrderToSignal() { + // + // Temp Result ... + XSignal result = {}; + result.type = X_SIGNAL_NONE; + + // + // Here we can get some usefull info based on selected order ... + double swap = OrderSwap(); + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + int magicNumber = OrderMagicNumber(); + double takeProfit = OrderTakeProfit(); + string comment = OrderComment(); + + // + ENUM_X_SIGNAL_PROVIDER provider = GetProvider(comment); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // Conver Position to Signal ... + result.sl = stopLoss; + result.tp = takeProfit; + result.time = openTime; + result.symbol = _Symbol; + result.id = magicNumber; + result.comment = comment; + result.entry = openPrice; + result.provider = provider; + result.type = isLongOrder ? X_SIGNAL_LONG : X_SIGNAL_SHORT; + + // + return result; +} + +// +// START Count Orders ... +// +// +// Count Open Positions ... +int CountOpenTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if (OrderSymbol() == _Symbol) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Long Positions ... +int CountOpenLongTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_BUY + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Short Positions ... +int CountOpenShortTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_SELL + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} +// +// END Count Orders ... +// + +// +// START Close Orders ... +// +// +// Close All Open Trades ... +bool CloseAllTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + + // + return result; +} + +// +bool CloseAllProviderLongTrades( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal(); + + // + if (signal.provider == provider) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Long Trades ... +bool CloseAllLongTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Long Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Short Trades ... +bool CloseAllShortTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (!isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Short Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In Profit Trades ... +bool CloseAllInProfitTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit > 0 + && profit > 50 * _Point + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InProfit Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In DrawDown Trades ... +bool CloseAllInDrawDownTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if (profit < 0) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close Biggest In DrawDown Trades ... +bool CloseBiggestDrawDownTrade() { + // + // Loop through all Positions ... + bool result = false; + double drawDown = 0; + + // + // Find Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) > drawDown + ) { + drawDown = profit; + } + } + } + } + + // + // Close Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) >= drawDown + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Max InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Long Time Trades ... +bool CloseAllLongTimeTrades( + const int passedCandles, + const ENUM_X_SIGNAL_PROVIDER provider = X_UNKNOWN_PROVIDER +) { + // + bool result = false; + + // + if (passedCandles <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + string comment = OrderComment(); + + // + ENUM_X_SIGNAL_PROVIDER orderProvider = GetProvider(comment); + bool isProviderVerified = + provider == X_UNKNOWN_PROVIDER ? + true : + orderProvider != X_UNKNOWN_PROVIDER + && orderProvider == provider + ; + + // + if ( + profit < 0 + && isProviderVerified + && openBarIndex - currentBarIndex >= passedCandles + // || ( + // profit > 0.5 + // && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 3) + // ) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Long Time issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + // else if ( + // openTrades > 0 + // && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 2) + // ) { + // result = CloseAllInProfitTrades() + // && CloseBiggestDrawDownTrade(); + // } + } + } + } + + // + return result; +} + +// +// Close all trades which passed Maximum Drawdown ... +bool CloseAllMaximumDrawDownPassedTrades( + const double maxDrDownPercentPerPTrade +) { + // + if ( + initialBalance <= 0 + || maxDrDownPercentPerPTrade <= 0 + ) { + return false; + } + + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double maxAllowedDrawDown = -1 * (initialBalance * maxDrDownPercentPerPTrade); + + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + if ( + profit < 0 + && MathAbs(profit) >= MathAbs(maxAllowedDrawDown) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Maximum DarwDown issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Trades Which Opens before Specified Length ... +bool CloseAllTradesWhichOpenInPastMarketLength( + const int marketLen +) { + // + bool result = false; + + // + if (marketLen <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + + // + if (openBarIndex <= currentBarIndex + marketLen) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Market Reverse issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } else if (openTrades > 0) { + // + // Close all InProfit Trdes and Biggest InDrawDown Trades ... + // result = CloseAllInProfitTrades(); + // && CloseBiggestDrawDownTrade(); + } + } + } + } + + // + return result; +} +// +// END Close Orders ... +// + +// +// START Modify Orders ... +// +// +void ModifyAllPriceLesserOpenTrades( + const XSignal &signal +) { + // + // Loop through all Open Trades ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + double takeProfit = OrderTakeProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // When new Signal Comming with price less than + // currently open trade and tp less than currently + // open trade, this means a market change happens ... + // here we can Close InProfit Trades or Modify Trades TP ... + if ( + openPrice < signal.entry + && takeProfit > signal.tp + ) { + bool result = OrderModify( + ticket, + openPrice, + signal.sl, + signal.tp, + clrYellow + ); + } + } + } + } +} + +// +void ModifyOpenTradesBasedOnCurrentTrade( + const XSignal &signal +) { + // + ModifyAllPriceLesserOpenTrades(signal); +} +// +// END Modify Orders ... +// +// +// END Orders Functions ... +// + +// +// START Signal Conditions ... +// +// +// Clear Signal Conditions ... +void ClearSignalConditions() { + // + ClearLongSignalConditions(); + ClearShortSignalConditions(); +} + +// +// Clear all Conditions Waiter for Long Signals ... +void ClearLongSignalConditions() { + // + ClearXLongSignalConditions(); + ClearXRLongSignalConditions(); +} + +// +// Clear all Conditions Waiter for Short Signals ... +void ClearShortSignalConditions() { + // + ClearXShortSignalConditions(); + // ClearXRShortSignalConditions(); +} +// +// END Signal Conditions ... +// diff --git a/Bkp/Used/14020502/Libraries/x-saherelm.x.signal.lib.mq4 b/Bkp/Used/14020502/Libraries/x-saherelm.x.signal.lib.mq4 new file mode 100644 index 0000000..ab23a9d --- /dev/null +++ b/Bkp/Used/14020502/Libraries/x-saherelm.x.signal.lib.mq4 @@ -0,0 +1,1033 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 X Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Inputs ... +// +// +input string xStarter = "- X Signal Provider -"; // ---> X Signal Provider <--- + +// +input bool enableXSignalling = true; // X Signalling Enable + +// +input double xR2R = 2.5; // X Risk To Reward Ratio +input int xMaximumCandlesPerTrade = 206; // X Maximum Candles which a Trade can open + +// +input int xOscillatorLength = 7; // X Oscillator Length + +// +input double xPSarStep = 0.02; // X Parabolic Sar Step +input double xPSarMaximum = 0.2; // X Parabolic Sar Maximum + +// +input int xRangeMarketLength = 5; // X Range Detector Length + +// +input int xSwingLength = 7; // X Signal Swing Length +// +// END Inputs ... +// + +// +// START Global Requirement Functions ... +// +// +// X Based Signal Conditions ... +struct XSignalConditions { + datetime startTime; + datetime signalTime; + datetime entryTime; +}; + +// +struct XMarketState { + double psar; + double fast; + double slow; + double open; + double verifier; + double oscillator; + double oscillatorVerifier; +}; + +// +static XSignalConditions xLongConds; +static bool xCloseLongTrades = false; +static bool xWaitForLongSignals = true; + +// +static XSignalConditions xShortConds; +static bool xCloseShortTrades = false; +static bool xWaitForShortSignals = true; + +// +static double xMaximumDrawDown = 0; + +// +datetime lastVerifierTouched; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckXSignalHandler( + const int bar_index +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + // + if (!enableXSignalling) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XOHCL candle = GetCandleModel(bar_index); + XOHCL pCandle = GetCandleModel(bar_index + 1); + XTPOWStatee tPowState = GetXTPowState( + bar_index + 1, + xSwingLength + ); + + // + XMarketState state = GetXMarketState( + bar_index + 1 + ); + + // + // Check Verifier Last Touched ... + bool isVerifierTouched = pCandle.high > state.verifier + && pCandle.low < state.verifier; + + // + // Enable Or Disable Long Signalling ... + if (isVerifierTouched) { + // + lastVerifierTouched = barTime; + + // + if (xWaitForLongSignals) { + xWaitForLongSignals = false; + } + + // + if (xWaitForShortSignals) { + xWaitForShortSignals = false; + } + } else { + // + int lastVerifierTouchedBarIndex = iBarShift( + _Symbol, + _Period, + lastVerifierTouched + ); + + // + int distance = MathAbs(lastVerifierTouchedBarIndex - bar_index); + + // + if ( + !xWaitForLongSignals + && distance > (xSwingLength * 2) + ) { + xWaitForLongSignals = true; + } + + // + if ( + !xWaitForShortSignals + && ( + distance > (xSwingLength * 2) + || ( + tPowState.powerDown > tPowState.powerUp + && tPowState.powerDown < 49 + ) + ) + ) { + xWaitForShortSignals = true; + } + } + + // + // Close All Long Open Trades ... + if ( + tPowState.powerDown > 55 + && tPowState.powerDown > tPowState.powerUp + ) { + // xCloseLongTrades = true; + } +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXLongSignalConditions( + const int bar_index +) { + // + if ( + !enableXSignalling + || !xWaitForLongSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + bool isCrossOver = false; + bool isCrossUnder = false; + + // + XMarketState cState = GetXMarketState(1); + XMarketState pState = GetXMarketState(2); + + // + isCrossUnder = + cState.fast < cState.slow + && !(pState.fast < pState.slow) + ; + + // + isCrossOver = + cState.fast > cState.slow + && !(pState.fast > pState.slow) + ; + + // + if ( + isCrossUnder + && xLongConds.startTime == 0 + ) { + // + xLongConds.startTime = barTime; + return; + } + + // + if ( + isCrossOver + && xLongConds.startTime > 0 + && xLongConds.signalTime == 0 + ) { + // + xLongConds.signalTime = barTime; + xLongConds.entryTime = barTime; + return; + } +} + +// +// Check and Fill Short Signal Conditions ... +void CheckXShortSignalConditions( + const int bar_index +) { + // + if ( + !enableXSignalling + || !xWaitForShortSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + bool isCrossOver = false; + bool isCrossUnder = false; + + // + XMarketState cState = GetXMarketState(1); + XMarketState pState = GetXMarketState(2); + + // + isCrossUnder = + cState.fast < cState.slow + && !(pState.fast < pState.slow) + ; + + // + isCrossOver = + cState.fast > cState.slow + && !(pState.fast > pState.slow) + ; + + // + if ( + isCrossOver + && xShortConds.startTime == 0 + ) { + // + xShortConds.startTime = barTime; + return; + } + + // + if ( + isCrossUnder + && xShortConds.startTime > 0 + && xShortConds.signalTime == 0 + ) { + // + xShortConds.signalTime = barTime; + xShortConds.entryTime = barTime; + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if (!enableXSignalling) { + return result; + } + + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + if (requestLong) { + // + if ( + !ValidateXLongConditions() + ) { + return result; + } + } else { + // + if ( + !ValidateXShortConditions() + ) { + return result; + } + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double askPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double bidPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double entryPrice = requestLong ? + askPrice : + bidPrice; + + // + double exitPrice = requestLong ? + bidPrice : + askPrice; + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + // + GetMarketLowestLow( + bar_index, + xSwingLength + ) + ; + + // + double hh = + // + GetMarketHighestHigh( + bar_index, + xSwingLength + ) + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = requestLong ? + MathMin(openPrice, closePrice) - ll : + hh - MathMax(openPrice, closePrice); + + // + double reward = risk * xR2R; + + // + double sl = requestLong ? + 0 : + 0; + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward + ; + + // + XRState range = GetXRange( + bar_index, + xRangeMarketLength + ); + + // + double affectedValue = range.ll; + xMaximumDrawDown = + affectedValue > xMaximumDrawDown ? + affectedValue : + xMaximumDrawDown; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XXX_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XXX_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXLongConditions() { + // + if (!enableXSignalling) { + return false; + } + + // + bool isConditionsFilled = + xLongConds.startTime > 0 + && xLongConds.signalTime > 0 + && xLongConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.signalTime + ); + + // + int entryBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.entryTime + ); + + // + isBLFilled = + // + xLongConds.signalTime > xLongConds.startTime + && xLongConds.entryTime >= xLongConds.signalTime + // && MathAbs(signalBarIndex - startBarIndex) >= 1 + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXLongSignalConditions(); + } + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXShortConditions() { + // + if (!enableXSignalling) { + return false; + } + + // + bool isConditionsFilled = + xShortConds.startTime > 0 + && xShortConds.signalTime > 0 + && xShortConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.signalTime + ); + + // + int entryBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.entryTime + ); + + // + isBLFilled = + // + xShortConds.signalTime > xShortConds.startTime + && xShortConds.entryTime >= xShortConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xWaitForShortSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXShortSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXLongSignalConditions() { + // + xLongConds.startTime = 0; + xLongConds.entryTime = 0; + xLongConds.signalTime = 0; +} + +// +// Clear Short Signal Conditions for New One ... +void ClearXShortSignalConditions() { + // + xShortConds.startTime = 0; + xShortConds.entryTime = 0; + xShortConds.signalTime = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForXSignals( + const XSignal &signal +) { + // + bool result = false; + + // + if (!enableXSignalling) { + return result; + } + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // XOHCL candle = GetCandleModel(0); + XOHCL candle = GetCandleModel(signalBarIndex); + XOHCL pCandle = GetCandleModel(signalBarIndex + 1); + + // + // Retrieve Range ... + XRState range = GetXRange( + signalBarIndex, + xRangeMarketLength + ); + + // + // Retrive XMarket States ... + XMarketState xState0 = GetXMarketState(signalBarIndex); + XMarketState xState1 = GetXMarketState(signalBarIndex + 1); + XMarketState xState2 = GetXMarketState(signalBarIndex + 2); + + // + // Retrieve Trend Powers ... + XTPOWStatee xTPow0 = GetXTPowState( + signalBarIndex, + xSwingLength + ); + XTPOWStatee xTPow1 = GetXTPowState( + signalBarIndex + 1, + xSwingLength + ); + + // + double hh = GetMarketHighestHigh( + signalBarIndex, + xSwingLength + ); + double ll = GetMarketLowestLow( + signalBarIndex, + xSwingLength + ); + double diffChange = (hh - ll); + bool isBigSharpOccured = + diffChange > (600 * _Point) + ; + + // + bool isPSarVerified = false; + bool isTPowVerified = false; + bool isStateVerified = false; + bool isPriceVerified = false; + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + // Get Price Verification for Long ... + isPriceVerified = + // + // Starter ... + true + // + && !isBigSharpOccured + // + && signal.entry < hh + // + // && signal.entry < range.hh + // && signal.entry > range.mid + // // + // && candle.high > xState0.verifier + // && signal.entry > xState0.verifier + // + // && pCandle.low != ll + && pCandle.high != hh + ; + + // + int above20TPowers = 0; + double signalSlope = 0; + int tPowUnverifyConditions = 0; + int tPowUnverifyConditionsIdx = 0; + for (int i = signalBarIndex; i < signalBarIndex + xSwingLength; i++) { + // + XTPOWStatee iTPowState = GetXTPowState( + i, + xSwingLength + ); + + // + // Calculate Signal Slope ... + if (i == signalBarIndex) { + // + signalSlope = iTPowState.signal; + } else if (i == signalBarIndex + 1) { + // + signalSlope = GetSlope( + 1, + iTPowState.signal, + 2, + signalSlope + ); + } + + // + if ( + iTPowState.powerUp > iTPowState.powerDown + && MathMax(iTPowState.powerUp, iTPowState.powerDown) > 20 + ) { + above20TPowers++; + } + + // + if (tPowUnverifyConditionsIdx < 3) { + // + if ( + iTPowState.powerUp < iTPowState.powerDown + || iTPowState.signal > MathMax(iTPowState.powerUp, iTPowState.powerDown) + ) { + tPowUnverifyConditions++; + } + + // + tPowUnverifyConditionsIdx++; + } + } + + // + isTPowVerified = + above20TPowers > 1 + && tPowUnverifyConditions == 0 + ; + + // + isPSarVerified = + xState0.psar < signal.entry + && xState0.psar < candle.low; + + // + isStateVerified = + // + // Start ... + true + ; + + // + result = + // + // Starter ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + isPSarVerified = + xState0.psar > signal.entry + && xState0.psar > candle.high + ; + + // + // Get Price Verification for Short ... + isPriceVerified = + // + // Starter ... + true + // + && !isBigSharpOccured + // + && signal.entry > ll + // && signal.entry < hh - (MathAbs(hh - ll) / 2) + // + // && signal.entry > range.ll + // && signal.entry < range.mid + // + // && candle.high < xState0.verifier + // && signal.entry < xState0.verifier + // + && pCandle.low != ll + // && pCandle.high != hh + ; + + // + int above20TPowers = 0; + double signalSlope = 0; + int tPowUnverifyConditions = 0; + int tPowUnverifyConditionsIdx = 0; + for (int i = signalBarIndex; i < signalBarIndex + xSwingLength; i++) { + // + XTPOWStatee iTPowState = GetXTPowState( + i, + xSwingLength + ); + + // + // Calculate Signal Slope ... + if (i == signalBarIndex) { + // + signalSlope = iTPowState.signal; + } else if (i == signalBarIndex + 1) { + // + signalSlope = GetSlope( + 1, + iTPowState.signal, + 2, + signalSlope + ); + } + + // + if ( + iTPowState.powerUp > iTPowState.powerDown + && MathMax(iTPowState.powerUp, iTPowState.powerDown) > 20 + ) { + above20TPowers++; + } + + // + if (tPowUnverifyConditionsIdx < 3) { + // + if ( + iTPowState.powerUp > iTPowState.powerDown + || iTPowState.signal < MathMax(iTPowState.powerUp, iTPowState.powerDown) + ) { + tPowUnverifyConditions++; + } + + // + tPowUnverifyConditionsIdx++; + } + } + + // + isTPowVerified = + above20TPowers < 1 + // && ( + // ( + // xTPow0.powerUp > 20 + // || xTPow1.powerUp > 20 + // ) || ( + // (xTPow0.powerUp + xTPow1.powerUp) / 2 > (20 * 2) + // ) + // ) + // && xTPow0.signal < 20 + && tPowUnverifyConditions == 0 + ; + + // + isStateVerified = + // + // Start ... + true + ; + + // + result = + // + // Starter Condition ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } + + // + return result; +} +// +// END Functions ... +// + +// +// START Data Provider ... +// +XMarketState GetXMarketState( + const int bar_index +) { + // + XMarketState result = {}; + + // + double fast = GetMA( + bar_index, + xSwingLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double open = GetMA( + bar_index, + xSwingLength, + 0, + MODE_SMA, + PRICE_OPEN + ); + + // + double slow = GetMA( + bar_index, + xSwingLength * 2, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double oscillator = GetMA( + bar_index, + xSwingLength, + 0, + MODE_EMA, + PRICE_CLOSE + ); + + // + double oscillatorVerifier = GetMA( + bar_index, + xSwingLength, + 0, + MODE_EMA, + PRICE_WEIGHTED + ); + + // + int dailyCount = GetDailyCandleCount(); + double verifier = GetMA( + bar_index, + dailyCount, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double psar = iSAR( + _Symbol, + _Period, + xPSarStep, + xPSarMaximum, + bar_index + ); + + // + result.psar = psar; + result.fast = fast; + result.open = open; + result.slow = slow; + result.verifier = verifier; + result.oscillator = oscillator; + result.oscillatorVerifier = oscillatorVerifier; + + // + return result; +} +// +// END Data Provider ... +// diff --git a/Bkp/Used/14020502/Libraries/x-saherelm.xr.signal.lib.mq4 b/Bkp/Used/14020502/Libraries/x-saherelm.xr.signal.lib.mq4 new file mode 100644 index 0000000..2344d0c --- /dev/null +++ b/Bkp/Used/14020502/Libraries/x-saherelm.xr.signal.lib.mq4 @@ -0,0 +1,654 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 X Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Inputs ... +// +// +input string xRStarter = "- XR Signal Provider -"; // --> XR Signal Provider <-- + +// +input bool enableXRSignalling = false; // XR Signalling Enable + +// +input double xrR2R = 2; // XR Risk To Reward Ratio +input int xRMaximumCandlesPerTrade = 252; // XR Maximum Candles which a Trade can open + +// +input int xrOscillatorLength = 7; // XR Oscillator Length +input int xrFastLength = 20; // XR Fast Length +input int xrSlowLength = 50; // XR Slow Length +input int xrRangeMarketLength = 50; // XR Range Detector Length + +// +input int xrSwingLength = 7; // XR Swing Length +// +// END Inputs ... +// + +// +// START Global Requirement Functions ... +// +// +// XR Market State ... +struct XRMarketState { + // + double fast; + double slow; + + // + double prevFast; + double prevSlow; + + // + double oscillator; + double prevOscillator; + + // + double verifier; +}; + +// +// XR Based Signal Conditions ... +struct XRSignalConditions { + // + datetime startTime; + datetime signalTime; + datetime entryTime; + + // + double value; + XRState state; +}; + +// +static XRSignalConditions xrLongConds; +static bool xrCloseLongTrades = false; +static bool xrWaitForLongSignals = true; + +// +static double xrMaximumDrawDown = 0; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckXRSignalHandler( + const int bar_index +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + + // + if (!enableXRSignalling) { + return; + } + + // + XOHCL candle = GetCandleModel(bar_index); + + // + XRMarketState state = GetXRMarketState( + bar_index + ); + + // + if (xrWaitForLongSignals) { + // + if ( + state.oscillator < state.fast + && state.oscillator < state.slow + && state.prevOscillator < state.prevFast + && state.prevOscillator < state.prevSlow + && candle.low < xrMaximumDrawDown + ) { + // + xrMaximumDrawDown = 0; + xrCloseLongTrades = true; + } + } else { + } +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXRLongSignalConditions( + const int bar_index +) { + // + if (!enableXRSignalling) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XOHCL candle = GetCandleModel(bar_index + 1); + + // + XRState xrState = GetXRange( + bar_index, + xrRangeMarketLength + ); + + // + double affectedValue = xrState.mid; + + // + XRMarketState state = GetXRMarketState( + bar_index + ); + + // + bool isCrossOver = + state.fast > state.slow + && !(state.prevFast > state.prevSlow) + ; + + // + bool isCrossUnder = + state.fast < state.slow + && !(state.prevFast < state.prevSlow) + ; + + // + if ( + isCrossUnder + && xrLongConds.startTime == 0 + ) { + // + xrLongConds.startTime = barTime; + return; + } + + // + if ( + isCrossOver + && xrLongConds.startTime > 0 + && xrLongConds.signalTime == 0 + ) { + // + xrLongConds.value = affectedValue; + xrLongConds.state = xrState; + + // + xrLongConds.signalTime = barTime; + xrLongConds.entryTime = barTime; + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXRSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if (!enableXRSignalling) { + return result; + } + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + if (requestLong) { + // + if ( + !ValidateXRLongConditions() + ) { + return result; + } + } else { + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double askPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double bidPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double entryPrice = requestLong ? + askPrice : + bidPrice; + + // + double exitPrice = requestLong ? + bidPrice : + askPrice; + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + // + GetMarketLowestLow( + bar_index, + xrSwingLength + ) + ; + + // + double hh = + // + GetMarketHighestHigh( + bar_index, + xrSwingLength + ) + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = requestLong ? + MathMin(openPrice, closePrice) - ll : + hh - MathMax(openPrice, closePrice); + double reward = risk * xrR2R; + + // + double sl = requestLong ? + 0 : + ll; + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward + ; + + // + xrMaximumDrawDown = + xrMaximumDrawDown == 0 ? + xrLongConds.state.mid : + xrMaximumDrawDown > xrLongConds.state.mid ? + xrMaximumDrawDown : + xrLongConds.state.mid; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XR_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XR_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXRLongConditions() { + // + if (!enableXRSignalling) { + return false; + } + + // + bool isConditionsFilled = + xrLongConds.startTime > 0 + && xrLongConds.signalTime > 0 + && xrLongConds.entryTime > 0 + // + && xrLongConds.value > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xrLongConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xrLongConds.signalTime + ); + + // + // Count Affected Value Touches ... + int cStartBarIndex = iBarShift( + _Symbol, + _Period, + xrLongConds.state.start + ); + + // + int cEndBarIndex = cStartBarIndex + xrLongConds.state.length; + + // + int highTouched = 0; + int valueTouched = 0; + for (int i = cStartBarIndex; i <= cStartBarIndex + cEndBarIndex; i++) { + // + XOHCL iCandle = GetCandleModel(i); + + // + if ( + iCandle.low < xrLongConds.value + && iCandle.high > xrLongConds.value + ) { + valueTouched++; + } + + // + if ( + iCandle.low < xrLongConds.state.hh + && iCandle.high > xrLongConds.state.hh + ) { + highTouched++; + } + } + + // + isBLFilled = + // + xrLongConds.signalTime > xrLongConds.startTime + && xrLongConds.entryTime >= xrLongConds.signalTime + // + && highTouched < 2 + && valueTouched > (cEndBarIndex - cStartBarIndex) / 6 + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xrWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXRLongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXRLongSignalConditions() { + // + xrLongConds.startTime = 0; + xrLongConds.signalTime = 0; + xrLongConds.entryTime = 0; + + // + xrLongConds.value = 0; + + // + XRState e = {}; + xrLongConds.state = e; +} + +// +// Check State for Long Signals ... +bool IsReadyForXRSignals( + const XSignal &signal +) { + // + bool result = false; + + // + if (!enableXRSignalling) { + return result; + } + + // + XRMarketState state = GetXRMarketState(0); + + // + double fSDif = MathAbs(state.fast - state.slow); + double fSDifP = MathAbs(state.prevFast - state.prevSlow); + + // + double emaSlope = GetSlope( + 1, + state.prevOscillator, + 2, + state.oscillator + ); + + // + XOHCL pCandle = GetCandleModel(1); + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + result = + // + // Starter ... + true + // + && state.oscillator > state.fast + && emaSlope > 0 + && signal.entry > state.verifier + // + && fSDif > fSDifP + // + && signal.entry < xrLongConds.state.hh + && signal.entry > xrLongConds.state.mid + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + result = + false + ; + } + + // + return result; +} +// +// END Functions ... +// + +// +// START Data Providers ... +// +// +XRMarketState GetXRMarketState( + const int bar_index +) { + // + XRMarketState result = {}; + + // + // Prepare Market Length ... + int xrVerifierMarketLength = GetDailyCandleCount(); + + // + // Calculate Fast and Prev Fast ... + // + // Fast ... + double fast = GetMA( + bar_index + 1, + xrFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + // Prev Fast ... + double prevFast = GetMA( + bar_index + 2, + xrFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + // Calculate Slow and Prev Slow ... + + // + // Slow ... + double slow = GetMA( + bar_index + 1, + xrSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + // Prev Slow ... + double prevSlow = GetMA( + bar_index + 2, + xrSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + // Calculate Oscillator and Prev Oscillator ... + + // + // Oscillator ... + double oscillator = GetMA( + bar_index, + xrOscillatorLength, + 0, + MODE_EMA, + PRICE_CLOSE + ); + + // + // Prev Oscillator ... + double prevOscillator = GetMA( + bar_index + 1, + xrOscillatorLength, + 0, + MODE_EMA, + PRICE_CLOSE + ); + + // + // Calculate Verifier ... + double verifier = GetMA( + bar_index, + xrVerifierMarketLength, + 0, + MODE_EMA, + PRICE_CLOSE + ); + + // + result.fast = fast; + result.slow = slow; + result.verifier = verifier; + result.prevFast = prevFast; + result.prevSlow = prevSlow; + result.oscillator = oscillator; + result.prevOscillator = prevOscillator; + + // + return result; +} +// +// END Data Providers ... +// \ No newline at end of file diff --git a/Bkp/Used/14020510/read-conditions.tpw.long.mq4 b/Bkp/Used/14020510/read-conditions.tpw.long.mq4 new file mode 100644 index 0000000..9ac8f51 --- /dev/null +++ b/Bkp/Used/14020510/read-conditions.tpw.long.mq4 @@ -0,0 +1,1074 @@ + // + // Get Price Verification for Long ... + isPriceVerified = + // + // Starter ... + true + // + && isHHVerified + && signal.entry < hh + && !isBigSharpOccured + && signal.entry < candle0.high + && MathAbs(signal.entry - hh) > 50 * _Point + ; + + // + isTPowVerified = + // + // Starter ... + true + // + && tPow.signal < MathMax(tPow.powerUp, tPow.powerDown) + ; + + // + isPSarVerified = + // + // Starter ... + true + // + && state0.psar < signal.entry + ; + + // + // bool isLastFastCrossSlowVerified = + // lastFastCrossOverSlowTime > 0 + // && lastFastCrossUnderSlowTime > 0 + // ? + // MathAbs(GetLastFastCrossOverSlowBarIndex() - GetLastFastCrossUnderSlowBarIndex()) > (xTPWSwingLength * 2) + // : + // false + // ; + + // + isStateVerified = + // + // Start ... + true + // + // && state0.fast > state1.fast + // && state1.fast > state2.fast + // + // && state0.rangeFast > state0.rangeSlow + // && state1.rangeFast > state1.rangeSlow + // // + // && state0.rangeWeight > state0.verifier + // && state1.rangeWeight > state1.verifier + // // + // && state0.verifier < state0.rangeSlow + // && state1.verifier < state1.rangeSlow + // + && MathAbs(state0.range - state0.rangeWeight) > 50 * _Point + // + && MathAbs(state0.verifier - state0.rangeWeight) > 50 * _Point + // + // && ( + // lastRangeCrossOverRangeWeightTime > 0 + // && lastRangeCrossUnderRangeWeightTime > 0 + // ? + // // + // MathMin( + // GetLastRangeCrossOverRangeWeightBarIndex(), + // GetLastRangeCrossUnderRangeWeightBarIndex() + // ) - signalBarIndex > xTPWSwingLength + // : + // // + // false + // ) + // + // && ( + // state0.range < state0.verifier + // ? + // // + // false + // : + // // + // ( + // state0.rangeWeight > state0.range + // ? + // // + // MathAbs(state0.rangeWeight - state0.range) <= MathAbs(state0.range - state0.verifier) + // : + // // + // MathAbs(state0.rangeWeight - state0.range) <= MathAbs(state0.range - state0.verifier) + // ) + // ) + // + // // && isLastFastCrossSlowVerified + // && !( + // ll < llState.verifier + // && hh > state0.verifier + // ) + ; + + +// // +// datetime lastPriceOverVerifierTime; +// datetime lastFastCrossOverSlowTime; +// datetime lastPriceUnderVerifierTime; +// datetime lastPriceTouchVerifierTime; +// datetime lastFastCrossUnderSlowTime; +// datetime lastRangeCrossOverVerifierTime; +// datetime lastRangeCrossUnderVerifierTime; +// datetime lastRangeCrossOverRangeWeightTime; +// datetime lastRangeCrossUnderRangeWeightTime; +// datetime lastRangeWeightCrossOverVerifierTime; +// datetime lastRangeWeightCrossUnderVerifierTime; + +// // +// datetime lastTPowAboveMaxVerifierTime; + +// // +// // Find Crosses between fast and slow ... + +// // +// bool isFastCrossOverSlow = +// state1.fast > state1.slow +// && !(state2.fast > state2.slow) +// ; +// if (isFastCrossOverSlow) { +// lastFastCrossOverSlowTime = barTime; +// } + +// // +// bool isFastCrossUnderSlow = +// state1.fast < state1.slow +// && !(state2.fast < state2.slow) +// ; +// if (isFastCrossUnderSlow) { +// lastFastCrossUnderSlowTime = barTime; +// } + +// // +// // Find Range and Verifier Cross ... + +// // +// bool isRangeCrossOverVerifier = +// state1.range > state1.verifier +// && !(state2.range > state2.verifier) +// ; +// if (isRangeCrossOverVerifier) { +// lastRangeCrossOverVerifierTime = barTime; +// } + +// // +// bool isRangeCrossUnderVerifier = +// state1.range < state1.verifier +// && !(state2.range < state2.verifier) +// ; +// if (isRangeCrossUnderVerifier) { +// lastRangeCrossUnderVerifierTime = barTime; +// } + +// // +// // Find Crosses between range and rangeWeight ... + +// // +// bool isRangeCrossOverRangeWeight = +// state1.range > state1.rangeWeight +// && !(state2.range > state2.rangeWeight) +// ; +// if (isRangeCrossOverRangeWeight) { +// lastRangeCrossOverRangeWeightTime = barTime; +// } + +// // +// bool isRangeCrossUnderRangeWeight = +// state1.range < state1.rangeWeight +// && !(state2.range < state2.rangeWeight) +// ; +// if (isRangeCrossUnderRangeWeight) { +// lastRangeCrossUnderRangeWeightTime = barTime; +// } + +// // +// // Find RangeWeight and Verifier Cross ... + +// // +// bool isRangeWehigthCrossOverVerifier = +// state1.rangeWeight > state1.verifier +// && !(state2.rangeWeight > state2.verifier) +// ; +// if (isRangeWehigthCrossOverVerifier) { +// lastRangeWeightCrossOverVerifierTime = barTime; +// } + +// // +// bool isRangeWeightCrossUnderVerifier = +// state1.rangeWeight < state1.verifier +// && !(state2.rangeWeight < state2.verifier) +// ; +// if (isRangeWeightCrossUnderVerifier) { +// lastRangeWeightCrossUnderVerifierTime = barTime; +// } + +// // +// // Find Price Crosses by Verifier ... + +// // +// bool isPriceOverVerifier = +// candle1.low > state1.verifier +// && !(candle2.low > state1.verifier) +// ; +// if (isPriceOverVerifier) { +// lastPriceOverVerifierTime = barTime; +// } + +// // +// bool isPriceUnderVerifier = +// candle1.high < state1.verifier +// && !(candle2.high < state1.verifier) +// ; +// if (isPriceUnderVerifier) { +// lastPriceUnderVerifierTime = barTime; +// } + +// // +// bool isPriceTouchVerifier = +// isPriceOverVerifier +// || isPriceUnderVerifier +// ; + +// // +// if (isPriceTouchVerifier) { +// lastPriceTouchVerifierTime = barTime; +// } + +// // +// bool isTPowUpperBelowMaxVerifier = MathMax(tPow1.powerUp, tPow1.powerDown) < tPowerMaxVerifier; +// bool isTPowUpperAboveMaxVerifier = MathMax(tPow1.powerUp, tPow1.powerDown) > tPowerMaxVerifier; +// if (isTPowUpperAboveMaxVerifier) { +// lastTPowAboveMaxVerifierTime = barTime; +// } + +// // +// int GetLastFastCrossOverSlowBarIndex() { +// // +// int result = -1; + +// // +// if (lastFastCrossOverSlowTime > 0) { +// // +// result = iBarShift( +// _Symbol, +// _Period, +// lastFastCrossOverSlowTime +// ); +// } + +// // +// return result; +// } + +// // +// int GetLastFastCrossUnderSlowBarIndex() { +// // +// int result = -1; + +// // +// if (lastFastCrossUnderSlowTime > 0) { +// // +// result = iBarShift( +// _Symbol, +// _Period, +// lastFastCrossUnderSlowTime +// ); +// } + +// // +// return result; +// } + +// // +// int GetLastRangeCrossOverVerifierBarIndex() { +// // +// int result = -1; + +// // +// if (lastRangeCrossOverVerifierTime > 0) { +// // +// result = iBarShift( +// _Symbol, +// _Period, +// lastRangeCrossOverVerifierTime +// ); +// } + +// // +// return result; +// } + +// // +// int GetLastRangeCrossUnderVerifierBarIndex() { +// // +// int result = -1; + +// // +// if (lastRangeCrossUnderVerifierTime > 0) { +// // +// result = iBarShift( +// _Symbol, +// _Period, +// lastRangeCrossUnderVerifierTime +// ); +// } + +// // +// return result; +// } + +// // +// int GetLastRangeCrossOverRangeWeightBarIndex() { +// // +// int result = -1; + +// // +// if (lastRangeCrossOverRangeWeightTime > 0) { +// // +// result = iBarShift( +// _Symbol, +// _Period, +// lastRangeCrossOverRangeWeightTime +// ); +// } + +// // +// return result; +// } + +// // +// int GetLastRangeCrossUnderRangeWeightBarIndex() { +// // +// int result = -1; + +// // +// if (lastRangeCrossUnderRangeWeightTime > 0) { +// // +// result = iBarShift( +// _Symbol, +// _Period, +// lastRangeCrossUnderRangeWeightTime +// ); +// } + +// // +// return result; +// } + +// // +// int GetLastRangeWeightCrossOverVerifierBarIndex() { +// // +// int result = -1; + +// // +// if (lastRangeWeightCrossOverVerifierTime > 0) { +// // +// result = iBarShift( +// _Symbol, +// _Period, +// lastRangeWeightCrossOverVerifierTime +// ); +// } + +// // +// return result; +// } + +// // +// int GetLastRangeWeightCrossUnderVerifierBarIndex() { +// // +// int result = -1; + +// // +// if (lastRangeWeightCrossUnderVerifierTime > 0) { +// // +// result = iBarShift( +// _Symbol, +// _Period, +// lastRangeWeightCrossUnderVerifierTime +// ); +// } + +// // +// return result; +// } + + + // // + // // Detect Sharp Changes ... + // double ll = GetMarketLowestLow( + // bar_index, + // xTPWSwingLength + // ); + // double sharpDetectionValue = + // xTPWSharpDetectionFactor * _Point; + // double isSharpDetectionOccured = + // MathAbs(candle0.low - ll) > sharpDetectionValue + // ; + + // // + // // Retrieve State Min and Max ... + // double stateMin0 = GetXTPWStateMin(state0); + // double stateMax0 = GetXTPWStateMax(state0); + // bool isStateDistanceValid = + // MathAbs(stateMax0 - stateMin0) < sharpDetectionValue; + + // // + // // Fast Slow Verification ... + // // + // double topBound = MathMax(state1.range, state1.rangeWeight); + // topBound = MathMax(topBound, state1.verifier); + + // // + // double bottomBound = MathMin(state1.range, state1.rangeWeight); + // bottomBound = MathMin(bottomBound, state1.verifier); + + // + // bool isFastSlowValid = + // ( + // state1.fast > topBound + // || state1.fast < bottomBound + // ) && ( + // state1.slow > topBound + // || state1.slow < bottomBound + // ); + + // + bool longCondition1 = + // + // Condition 1 ... + true + // + && tPow0.powerDown > tPow0.powerUp + && state0.range > state0.verifier + && state1.range > state1.verifier + && state1.range > state1.rangeWeight + && tPow0.powerDown > tPow1.powerDown + && tPow1.powerDown > tPowerMaxVerifier + && tPow2.powerDown < tPowerMaxVerifier + && state1.rangeWeight > state1.verifier + && !( + ( + candle1.high > state1.verifier + && candle1.low < state1.verifier + ) || ( + candle1.low > state1.verifier + ) + ) + ; + + // + bool longCondition2 = + // + // Condition 2 ... + true + // + && tPow0.powerUp > tPow0.powerDown + && tPow1.powerUp > tPow1.powerDown + && tPow2.powerUp > tPow2.powerDown + && tPow1.powerUp < tPowerVerifier + // + && state1.fast > state1.slow + && state1.range > state1.verifier + && state0.fast < state0.rangeWeight + && state1.fast < state1.rangeWeight + && state1.rangeWeight > state1.range + && MathAbs(state1.rangeWeight - state1.range) > + (MathAbs(state1.range - state1.verifier) / 2) + // + && candle0.low > state0.verifier + && candle1.low > state1.verifier + ; + + // + bool longCondition3 = + // + // Condition 3 ... + true + // + && isCrossOver + && state0.fast >= state2.fast + && state1.psar < candle1.low + && state1.verifier < state1.fast + // + && MathMax(tPow1.powerUp, tPow1.powerDown) < tPowerMaxVerifier + ; + + +// +// Get Minimum value of State ... +double GetXTPWStateMin( + const XTPWMarketState &state +) { + // + double result = 0; + + // + result = state.psar; + result = MathMin(result, state.fast); + result = MathMin(result, state.slow); + result = MathMin(result, state.range); + result = MathMin(result, state.verifier); + result = MathMin(result, state.rangeWeight); + + // + return result; +} + +// +// Get Maximum value of State ... +double GetXTPWStateMax( + const XTPWMarketState &state +) { + // + double result = 0; + + // + result = state.psar; + result = MathMax(result, state.fast); + result = MathMax(result, state.slow); + result = MathMax(result, state.range); + result = MathMax(result, state.verifier); + result = MathMax(result, state.rangeWeight); + + // + return result; +} + + +// +// + // + // Count range weight Crosses ... + if ( + // + // Range Weight Cross Over Verifier ... + ( + iState1.rangeWeight > iState1.verifier + && !(iState2.rangeWeight > iState2.verifier) + ) + || + // + // Range Weight Cross Under Verifier ... + ( + iState1.rangeWeight < iState1.verifier + && !(iState2.rangeWeight < iState2.verifier) + ) + || + // + // Range Weight Cross Over Range ... + ( + iState1.rangeWeight > iState1.range + && !(iState2.rangeWeight > iState2.range) + ) + || + // + // Range Weight Cross Under Range ... + ( + iState1.rangeWeight < iState1.range + && !(iState2.rangeWeight < iState2.range) + ) + ) { + rangeWeightCrosses++; + } + + // + // Count Price above range ... + if ( + iCandle.low > iState1.range + || ( + iCandle.low < iState1.range + && iCandle.high > iState1.range + ) + ) { + // + priceAboveRange++; + } + + // + // Count Price above verifier ... + if ( + iCandle.low > iState1.verifier + || ( + iCandle.low < iState1.verifier + && iCandle.high > iState1.verifier + ) + ) { + // + priceAboveVerifier++; + } + + // + // Count between Range and Verifier ... + double vUpper = MathMax(iState0.range, iState0.verifier); + double vDowner = MathMin(iState0.range, iState0.verifier); + if ( + !( + iState0.fast > vUpper + && iState0.slow > vUpper + ) + && + !( + iState0.fast < vDowner + && iState0.slow < vDowner + ) + ) { + fastAndSlowBetweenRangeAndVerifier++; + } + +// +// Short ... + // + if ( + !enableXTPWSignalling + || !xTPWWaitForShortSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Retrieve TPower State ... + XTPOWStatee tPow0 = GetXTPowState( + bar_index, + xTPWSwingLength + ); + XTPOWStatee tPow1 = GetXTPowState( + bar_index + 1, + xTPWSwingLength + ); + XTPOWStatee tPow2 = GetXTPowState( + bar_index + 2, + xTPWSwingLength + ); + + // + // Retrieve TPWMarket State ... + XTPWMarketState state0 = GetXTPWMarketState( + bar_index + ); + XTPWMarketState state1 = GetXTPWMarketState( + bar_index + 1 + ); + XTPWMarketState state2 = GetXTPWMarketState( + bar_index + 2 + ); + + // + // Retrieve Candles ... + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + + // + bool isTPowUp = tPow2.powerUp > tPow2.powerDown; + + // + double tPowUpper = MathMax(tPow2.powerUp, tPow2.powerDown); + + // + bool startCondition = false; + bool signalCondition = false; + + // + startCondition = + // + true + // + && tPow2.powerDown > tPowerVerifier + ; + + // + signalCondition = + // + true + // + && tPow1.powerDown > tPow2.powerDown + && tPow1.powerDown > tPowerMaxVerifier + ; + + // // + // bool isCrossOver = + // state1.fast > state1.slow + // && !(state2.fast > state2.slow) + // ; + + // // + // bool isCrossUnder = + // state0.fast < state0.slow + // && state1.fast < state1.slow + // && !(state2.fast < state2.slow) + // ; + + // + double tPowerMedian = tPowerMaxVerifier - tPowerVerifier / 2; + + // + bool signalCondition1 = + isCrossUnder + ; + + // + bool signalCondition2 = + // + tPow0.powerDown > tPow0.powerUp + // + && tPow1.powerDown > tPow1.powerUp + && tPow2.powerDown > tPow2.powerUp + // + && tPow0.powerDown > tPowerMedian + && tPow1.powerDown > tPowerMedian + && tPow2.powerDown > tPowerMedian + // + && tPow0.signal > tPow0.powerDown + ; + + // + if ( + ( + ( + startCondition + && signalCondition + ) || ( + signalCondition1 + || signalCondition2 + ) + ) + && xTPWShortConds.startTime == 0 + && xTPWShortConds.signalTime == 0 + ) { + // + xTPWShortConds.startTime = barTime; + xTPWShortConds.signalTime = barTime; + xTPWShortConds.entryTime = barTime; + + // + return; + } + + +// +// Short ... + // + isPSarVerified = + // + // Starter ... + true + // + && state0.psar > candle0.high + && state0.psar > signal.entry + ; + + // + // Get Price Verification for Short ... + isPriceVerified = + // + // Starter ... + true + // + && priceAboveRange < 1 + && priceAboveVerifier == 0 + ; + + // + // Find Minimum Value of HH BarIndex Market State rangeWeight and verifier ... + double hhValidationValue = MathMin( + hhState.rangeWeight, + hhState.verifier + ); + bool isHHValidForShortSignal = + hh < hhValidationValue + ; + + // + isTPowVerified = + // + // Starter ... + true + // + && isHHValidForShortSignal + // + && aboveTPowerMaxVerifier < 4 + ; + + // + isStateVerified = + // + // Start ... + true + // + && rangeWeightCrosses == 0 + // + && state0.slow > state0.fast + // + && state0.range < state0.verifier + // + && state0.rangeWeight > state0.range + && state0.rangeWeight < state0.verifier + ; + + // + result = + // + // Starter Condition ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + + // // + // int aboveTPowerVerifier = 0; + // int abovePowerUpTPowerVerifier = 0; + // int abovePowerDownTPowerVerifier = 0; + + // // + // int aboveTPowerMaxVerifier = 0; + // int abovePowerUpTPowerMaxVerifier = 0; + // int abovePowerDownTPowerMaxVerifier = 0; + + // // + // int belowTPowerVerifier = 0; + // int belowPowerUpTPowerVerifier = 0; + // int belowPowerDownTPowerVerifier = 0; + + // // + // int belowTPowerMaxVerifier = 0; + // int belowPowerUpTPowerMaxVerifier = 0; + // int belowPowerDownTPowerMaxVerifier = 0; + + // // + // double powerUpSum = 0; + // double powerDownSum = 0; + + // // + // int priceAboveRange = 0; + // int priceAboveVerifier = 0; + // int fastAndSlowBetweenRangeAndVerifier = 0; + + // // + // int rangeWeightCrosses = 0; + + // // + // for (int i = signalBarIndex; i < signalBarIndex + xTPWSwingLength; i++) { + // // + // XOHCL iCandle = GetCandleModel(i); + + // // + // XTPOWStatee iTPow = GetXTPowState( + // i, + // xTPWSwingLength + // ); + + // // + // double isTPowUp = iTPow.powerUp > iTPow.powerDown; + + // // + // double tPowUpper = MathMax(iTPow.powerUp, iTPow.powerDown); + + // // + // // Summarise ... + // powerUpSum += iTPow.powerUp; + // powerDownSum += iTPow.powerDown; + + // // + // XTPWMarketState iState0 = GetXTPWMarketState( + // i + // ); + // XTPWMarketState iState1 = GetXTPWMarketState( + // i + 1 + // ); + // XTPWMarketState iState2 = GetXTPWMarketState( + // i + 2 + // ); + + + // // + // // Count Above TPow Verifier ... + // if (tPowUpper > tPowerVerifier) { + // // + // aboveTPowerVerifier++; + + // // + // if (isTPowUp) { + // abovePowerUpTPowerVerifier++; + // } else { + // abovePowerDownTPowerVerifier++; + // } + // } else if (tPowUpper < tPowerVerifier) { + // // + // belowTPowerVerifier++; + + // // + // if (isTPowUp) { + // belowPowerUpTPowerVerifier++; + // } else { + // belowPowerDownTPowerVerifier++; + // } + // } + + // // + // // Count Above TPow Max Verifier ... + // if (tPowUpper > tPowerMaxVerifier) { + // // + // aboveTPowerMaxVerifier++; + + // // + // if (isTPowUp) { + // abovePowerUpTPowerMaxVerifier++; + // } else { + // abovePowerDownTPowerMaxVerifier++; + // } + // } else if (tPowUpper < tPowerMaxVerifier) { + // // + // belowTPowerMaxVerifier++; + + // // + // if (isTPowUp) { + // belowPowerUpTPowerMaxVerifier++; + // } else { + // belowPowerDownTPowerMaxVerifier++; + // } + // } + // } + + + + // // + // int doubleMarketLength = (xTPWSwingLength * 2); + // int verifierLength = GetDailyCandleCount(); + // int rangeLength = verifierLength / 2; + + // // + // // Find Highest High ... + + // // + // double rangeHH = GetMarketHighestHigh( + // signalBarIndex, + // rangeLength + // ); + + // // + // double verifierHH = GetMarketHighestHigh( + // signalBarIndex, + // verifierLength + // ); + + // // + // // Find HH Bar Index ... + // int hhBarIndex = iHighest( + // _Symbol, + // _Period, + // MODE_HIGH, + // xTPWSwingLength, + // signalBarIndex + // ); + + // // + // // Find HH ... + // double hh = iHigh( + // _Symbol, + // _Period, + // hhBarIndex + // ); + + // // + // // Retrieve Market State on HH Bar Index ... + // XTPWMarketState hhState = GetXTPWMarketState( + // hhBarIndex + // ); + + // // + // // Retrieve TPow State on HH Bar Index ... + // XTPOWStatee hhTPow = GetXTPowState( + // hhBarIndex, + // xTPWSwingLength + // ); + + // // + // // Find Lowest Low ... + + // // + // double rangeLL = GetMarketLowestLow( + // signalBarIndex, + // rangeLength + // ); + + // // + // double verifierLL = GetMarketLowestLow( + // signalBarIndex, + // verifierLength + // ); + + // // + // // Find LL Bar Index ... + // int llBarIndex = iLowest( + // _Symbol, + // _Period, + // MODE_LOW, + // xTPWSwingLength, + // signalBarIndex + // ); + + // // + // // Find LL ... + // double ll = iLow( + // _Symbol, + // _Period, + // llBarIndex + // ); + + // // + // // Retrieve Market State on LL Bar Index ... + // XTPWMarketState llState = GetXTPWMarketState(llBarIndex); + + // // + // // Retrieve TPow State on LL Bar Index ... + // XTPOWStatee llTPow = GetXTPowState( + // llBarIndex, + // xTPWSwingLength + // ); + + // // + // // Find Sharp Changes ... + // double diffChange = (hh - ll); + // double sharpDetectionValue = + // (xTPWSharpDetectionFactor * _Point); + // bool isBigSharpOccured = + // diffChange > sharpDetectionValue; + // ; + + // // + // bool isHHVerified = + // !( + // hh == rangeHH + // && rangeHH == verifierHH + // ) + // || + // ( + // hh > rangeHH + // || hh > verifierHH + // ); + + // // + // bool isLLVerified = + // !( + // ll == rangeLL + // && rangeLL == verifierLL + // ) + // || + // ( + // ll < rangeLL + // || ll < verifierLL + // ); diff --git a/Bkp/Used/14020512/Experts/x-saherelm.ea.mq4 b/Bkp/Used/14020512/Experts/x-saherelm.ea.mq4 new file mode 100644 index 0000000..e7b7141 --- /dev/null +++ b/Bkp/Used/14020512/Experts/x-saherelm.ea.mq4 @@ -0,0 +1,1004 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XST Strategy Expert Advisor +// --------------------------------------------- +// saherelm implementation of strategy expert advisor ... +// in this EA, we try to combine multiple tools, to ashive best +// results ... +// +// ShortName: XST +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +989121694056 +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XST Strategy Expert Advisor" +#property strict + +// +// START Inputs ... +// +// +// Signal Prefixe ... +input string signalPrefix = "XST_EA"; // Signal Prefix + +// +// Signal Draw Specifications ... +input string bullishSignalLabel = "X_BUY"; // Bullish Signal Label +input color bullishSignalColor = clrAqua; // Bullish Signal Color + +// +input string bearishSignalLabel = "X_SELL"; // Bearish Signal Label +input color bearishSignalColor = clrFuchsia; // Bearish Signal Color + +// +input color signalEntryColor = clrAquamarine; // Signal Entry Ptice Color +input color signalSLColor = clrRed; // Signal SL Color +input color signalTPColor = clrGreen; // Signal TP Color + +// +input int candleGapBetweenSignals = 7; // How many Candle waits to new Signal from last one + +// +// Trade ... +input bool allowTrade = true; // Allow Trade Based on given Signals +input bool allowLongTrades = false; // Allow Long Trades +input bool allowShortTrades = true; // Allow Short Trades + +// +// Alerts ... +input bool alertEvents = true; // Alert Events +input bool alertPositions = true; // Alert Positions +input bool longPositionAlerts = true; // Alert Long Positions +input bool shortPositionAlerts = true; // Alert Short Positions + +// +// Alert Types ... +input bool terminalAlert = false; // Terminal Alert +input bool pushAlert = false; // Push Notification Alerts + +// +// Balance and Finanical Specifications ... +input double lotsPerTradePercent = 0.00001; // Lots Per Trade Percent +input int maxOpenTrades = 4; // Maximum Open Trade +input double maxDrawdownPercentPerPTrade = 0.1; // Maximum DrawDown Per Trade +input double minBalancePercent = 0.5; // Minimum Balance for Trading +input double maxEquityPercent = 0.1; // Maximum Trade Equity + +// +// START Global Definitions: Variables, Properties and etc ... +// +int lastSignalledBar = 0; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.signal.lib.mq4" + +// +int maxMarketLength = 0; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Validate Inputs ... + bool inputsNotValiid = + // + // EA ... + maxOpenTrades <= 0 + || maxEquityPercent < 0 + || minBalancePercent < 0 + || lotsPerTradePercent < 0 + || maxDrawdownPercentPerPTrade < 0 + ; + + // + if (inputsNotValiid) { + return INIT_PARAMETERS_INCORRECT; + } + + // + totalSignals = 0; + totalLongSignals = 0; + totalShortSignals = 0; + + // + initialBalance = 0; + + // + // START Define Array Series ... + // + // + // END Define Array Series ... + // + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST"; + + // + ClearSignalConditions(); + + // + maxMarketLength = MathMax(0, GetDailyCandleCount()); + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { +} + +// +// Ticker Event Handler ... +void OnTick() { + // + isNewDay = IsNewDay(); + if (isNewDay) { + // + LogMessage( + StringConcatenate( + "New Day ..." + ) + ); + } + + // + // Process Signals to Open Positions ... + ProcessSignals(); + + // + // Checking State for Signal Handling ... + CheckState(); + + // + // Process Open Positions for Trailing Stop Loss or Close ... + ProcessOpenPositions(); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Check State for Signal Handling ... +void CheckState() { + // + // Here we Must to Check Market State for enable or disable + // Signal Handlers and also make dection to close all long/short + // trades ... +} + +// +// Calculate Signals and Process Based on Exists Signals ... +void ProcessSignals() { + // + XSignalRequest request = {}; + request.type = X_SIGNAL_NONE; + request.hasSignal = false; + + // + // Prevent Multiple Calculating on Same Bars ... + isNewBar = IsNewBar(); + if (isNewBar) { + countedBars++; + } + + // + if (countedBars < maxMarketLength) { + return; + } + + // + bool allowDoTrade = true; + + // + // Check Balance ... + if (initialBalance > 0) { + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double minimumBalanceForTrade = + balance > initialBalance + ? + minBalancePercent * balance + : + minBalancePercent * initialBalance; + + // + // Retrieve Account Equity ... + double equity = AccountInfoDouble(ACCOUNT_EQUITY); + double maxAllowedEquity = balance - (balance * maxEquityPercent); + + // + // Retrieve Free Marigin ... + double freeMargin = AccountFreeMargin(); + double maximumMariginRisk = balance - (balance * maxEquityPercent); + + // + if ( + // + // Do not Open Positions if equity not passed ... + equity < maxAllowedEquity || + // + // Do not Open Positions if free margin not passed ... + freeMargin <= maximumMariginRisk || + // + // Do not open positions if balance less than minimum ... + balance <= minimumBalanceForTrade + ) { + // + static bool tradingPauseAlerted; + + // + allowDoTrade = false; + + // + if (!tradingPauseAlerted) { + // + string message = StringConcatenate( + "Trading Pause => ", + "Balance: ", balance, + ", Equity: ", equity, + ", FreeMargin: ", freeMargin + ); + + // + LogMessage(message); + SendAlert(message); + + // + tradingPauseAlerted = true; + } + } + } + + // + // Retrieve Signal Exists ... + request = GenerateSignal(0); + + // + // Prevent doing anything else, if there is no signals ... + if ( + !allowDoTrade || + !request.hasSignal || + request.type == X_SIGNAL_NONE + ) { + return; + } + + // + bool hasLongSignal = request.type == X_SIGNAL_LONG; + + // + // Check last Signalled Bar with Counted Bars ... + // Prevent Multiple Signalling on Same Bar ... + bool isInLastSignalledBars = false; + for (int i=0; i < candleGapBetweenSignals; i++) { + // + isInLastSignalledBars = + isInLastSignalledBars + || lastSignalledBar == countedBars - i + ; + } + if (isInLastSignalledBars) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + return; + } + + // + // increase last signalled bar ... + lastSignalledBar = countedBars; + + // + // Calculate Can Trade or not ... + allowDoTrade = allowTrade + && ( + hasLongSignal ? + allowLongTrades : + allowShortTrades + ); + + // + // Chack Maximum Open Positions ... + int openTrades = CountOpenTrades(); + if (maxOpenTrades > 0) { + // + if (openTrades >= maxOpenTrades) { + // + allowDoTrade = false; + + // + if (!allowDoTrade) { + // + string message = StringConcatenate( + "Trading Pause => ", + "Max Open Trades (", + maxOpenTrades, + ") reached ..." + ); + + // + LogMessage(message); + SendAlert(message); + } + } + } + + // + // Check Trading is Enable or not ... + // nothing to do if trading is disabled ... + if (!allowDoTrade) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + string message = StringConcatenate( + "Trading Not Allowed ..." + ); + + // + LogMessage(message); + SendAlert(message); + return; + } + + // + // Retrieve Signal Lots Per Trade ... + double lPTradePercent = GetSignalLottage( + request.signal, + lotsPerTradePercent + ); + + // + bool isPositionOpened = TradeSignal( + request.signal, + lPTradePercent, + // + bullishSignalLabel, + bullishSignalColor, + bearishSignalLabel, + bearishSignalColor + ); + + // + totalSignals++; + if (hasLongSignal) { + // + totalLongSignals++; + ClearLongSignalConditions(); + } else { + // + totalShortSignals++; + ClearShortSignalConditions(); + } + + // + if (isPositionOpened) { + // + bool canAlert = + alertPositions + && ( + hasLongSignal ? + longPositionAlerts + : + shortPositionAlerts + ); + + // + if (canAlert) { + // + // Alert Message ... + string message = StringConcatenate( + "Trade on Signal ID: ", request.signal.id, + ", ProvidedBy: ", GetSignalProviderIdentifier(request.signal.provider), + ", Entry: ", request.signal.entry, + ", TP: ", request.signal.tp + ); + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } + } + } +} + +// +// Process All Open Positions ... +void ProcessOpenPositions() { + // + // XSignalling ... + if (enableXSignalling) { + // + // Close All XXX Provided Signals on it's Specific Condition ... + if (xCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XXX_PROVIDER); + + // + xCloseLongTrades = false; + } + + // + if (xCloseShortTrades) { + // + CloseAllProviderShortTrades(X_XTPW_PROVIDER); + + // + xCloseShortTrades = false; + } + + // + // Close Maximum DrawDown Passed Trades ... + + // + // Longs ... + bool hasClosedLongInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xLongMaxDrawdownPerTradePercent, + X_SIGNAL_LONG, + X_XXX_PROVIDER + ); + + // + // Shorts ... + bool hasClosedShortInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xShortMaxDrawdownPerTradePercent, + X_SIGNAL_SHORT, + X_XXX_PROVIDER + ); + + // + // Close All Long Time Trades based on Provider provided Length ... + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + xMaximumCandlesPerTrade, + X_XXX_PROVIDER + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedLongInDrawDownLongTrade + || hasClosedShortInDrawDownLongTrade + ) { + xFailedSignals++; + } + } + + // + // XR Signalling ... + if (enableXRSignalling) { + // + if (xRCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XR_PROVIDER); + + // + xRCloseLongTrades = false; + } + + // + if (xRCloseShortTrades) { + // + CloseAllProviderShortTrades(X_XR_PROVIDER); + + // + xRCloseShortTrades = false; + } + + // + // Close Maximum DrawDown Passed Trades ... + + // + // Longs ... + bool hasClosedLongInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xRLongMaxDrawdownPerTradePercent, + X_SIGNAL_LONG, + X_XR_PROVIDER + ); + + // + // Shorts ... + bool hasClosedShortInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xRShortMaxDrawdownPerTradePercent, + X_SIGNAL_SHORT, + X_XR_PROVIDER + ); + + // + // Close All Long Time Trades based on Provider provided Length ... + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + xRMaximumCandlesPerTrade, + X_XR_PROVIDER + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedLongInDrawDownLongTrade + || hasClosedShortInDrawDownLongTrade + ) { + xRFailedSignals++; + } + } + + // + // XTPW Signalling ... + if (enableXTPWSignalling) { + // + if (xTPWCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XTPW_PROVIDER); + + // + xTPWCloseLongTrades = false; + } + + // + if (xTPWCloseShortTrades) { + // + CloseAllProviderShortTrades(X_XTPW_PROVIDER); + + // + xTPWCloseShortTrades = false; + } + + // + // Close Maximum DrawDown Passed Trades ... + + // + // Longs ... + bool hasClosedLongInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xTPWLongMaxDrawdownPerTradePercent, + X_SIGNAL_LONG, + X_XTPW_PROVIDER + ); + + // + // Shorts ... + bool hasClosedShortInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xTPWShortMaxDrawdownPerTradePercent, + X_SIGNAL_SHORT, + X_XTPW_PROVIDER + ); + + // + // Close All Long Time Trades based on Provider provided Length ... + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + xTPWMaximumCandlesPerTrade, + X_XTPW_PROVIDER + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedLongInDrawDownLongTrade + || hasClosedShortInDrawDownLongTrade + ) { + xTPWFailedSignals++; + } + } + + // + // Close Maximum DrawDown Passed Trades ... + // this is the Maximum Controller ... + // + double maxOfXPercent = enableXSignalling ? + MathMax( + xLongMaxDrawdownPerTradePercent, + xShortMaxDrawdownPerTradePercent + ) : 0 + ; + + // + double maxOfXRPercent = enableXRSignalling ? + MathMax( + xRLongMaxDrawdownPerTradePercent, + xRShortMaxDrawdownPerTradePercent + ) : 0 + ; + + // + double maxOfXTPWPercent = enableXTPWSignalling ? + MathMax( + xTPWLongMaxDrawdownPerTradePercent, + xTPWShortMaxDrawdownPerTradePercent + ) : 0 + ; + + // + double maxDrawDownPercent = MathMax( + maxOfXPercent, + maxOfXRPercent + ); + maxDrawDownPercent = MathMax( + maxDrawDownPercent, + maxOfXTPWPercent + ); + maxDrawDownPercent = MathMax( + maxDrawDownPercent, + maxDrawdownPercentPerPTrade + ); + + // + // we Calculate Max DrawDown Percent Per Trade ... + // then try to Close based on them ... + bool hasClosedInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + maxDrawDownPercent + ); +} + +// +// Send Special Type of Alerts ... +void SendAlert(string message) { + // + if (!alertEvents) { + return; + } + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } +} +// +// END Functions ... +// + +// +// +// Calculate Signal ... +// in this function we calculate a signal exists in +// specific bar or not ... +XSignalRequest GenerateSignal( + const int bar_index // Bar Index ... +) { + // + // create temp result ... + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + bool hasSignal = false; + bool hasLongSignal = false; + bool hasShortSignal = false; + + // + XSignal signal = {}; + + // + // Define Template Signal Requests for Managing Multiple Signals ... + // + // X ... + XSignalRequest xLongSignalRequest = {}; + XSignalRequest xShortSignalRequest = {}; + // + // XR ... + XSignalRequest xrLongSignalRequest = {}; + XSignalRequest xrShortSignalRequest = {}; + // + // XTPW ... + XSignalRequest xTPWLongSignalRequest = {}; + XSignalRequest xTPWShortSignalRequest = {}; + + // + // START XR Signal Handler ... + // + // + if (enableXRSignalling) { + // + CheckXRSignalHandler( + bar_index + ); + + // + // Long Trades ... + if (allowTrade && allowLongTrades) { + // + if (xRWaitForLongSignals) { + // + CheckXRLongSignalConditions( + bar_index + ); + + // + xrLongSignalRequest = GenerateXRSignal( + X_SIGNAL_LONG, + signalPrefix, + bar_index + ); + + // + if (xrLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXRSignals( + xrLongSignalRequest.signal + ); + + // + if (isReady && xRWaitForLongSignals) { + // + hasLongSignal = true; + signal = xrLongSignalRequest.signal; + } else { + ClearXRLongSignalConditions(); + } + } + } else { + ClearXRLongSignalConditions(); + } + } + + // + // Short Trades ... + if (allowTrade && allowShortTrades) { + } + } + // + // END XR Signal Handler ... + // + + // + // START XTPW Signal Handler ... + // + if (enableXTPWSignalling) { + // + CheckXTPWSignalHandler( + bar_index + ); + + // + // Long Trades ... + if (allowTrade && allowLongTrades) { + // + if (xTPWWaitForLongSignals) { + // + CheckXTPWLongSignalConditions( + bar_index + ); + + // + xTPWLongSignalRequest = GenerateXTPWSignal( + X_SIGNAL_LONG, + signalPrefix, + bar_index + ); + + // + if (xTPWLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXTPWSignals( + xTPWLongSignalRequest.signal + ); + + // + if (isReady && xTPWWaitForLongSignals) { + // + hasLongSignal = true; + signal = xTPWLongSignalRequest.signal; + } else { + ClearXTPWLongSignalConditions(); + } + } + } else { + ClearXTPWLongSignalConditions(); + } + } + + // + // Short Trades ... + if (allowTrade && allowShortTrades) { + // + if (xTPWWaitForShortSignals) { + // + CheckXTPWShortSignalConditions( + bar_index + ); + + // + xTPWShortSignalRequest = GenerateXTPWSignal( + X_SIGNAL_SHORT, + signalPrefix, + bar_index + ); + + // + if (xTPWShortSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXTPWSignals( + xTPWShortSignalRequest.signal + ); + + // + if (isReady && xTPWWaitForShortSignals) { + // + hasShortSignal = true; + signal = xTPWShortSignalRequest.signal; + } else { + ClearXTPWShortSignalConditions(); + } + } + } else { + ClearXTPWShortSignalConditions(); + } + } + } + // + // END XTPW Signal Handler ... + // + + // + // START X Signal Handler ... + // + // + if (enableXSignalling) { + // + CheckXSignalHandler( + bar_index + ); + + // + // Long Trades ... + if (allowTrade && allowLongTrades) { + // + if (xWaitForLongSignals) { + // + CheckXLongSignalConditions( + bar_index + ); + + // + xLongSignalRequest = GenerateXSignal( + X_SIGNAL_LONG, + signalPrefix, + bar_index + ); + + // + if (xLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXSignals( + xLongSignalRequest.signal + ); + + // + if (isReady && xWaitForLongSignals) { + // + hasLongSignal = true; + signal = xLongSignalRequest.signal; + } else { + ClearXLongSignalConditions(); + } + } + } else { + ClearXLongSignalConditions(); + } + } + + // + // Short Trades ... + if (allowTrade && allowShortTrades) { + // + if (xWaitForShortSignals) { + // + CheckXShortSignalConditions( + bar_index + ); + + // + xShortSignalRequest = GenerateXSignal( + X_SIGNAL_SHORT, + signalPrefix, + bar_index + ); + + // + if (xShortSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXSignals( + xShortSignalRequest.signal + ); + + // + if (isReady && xWaitForShortSignals) { + // + hasShortSignal = true; + signal = xShortSignalRequest.signal; + } else { + ClearXShortSignalConditions(); + } + } + } else { + ClearXShortSignalConditions(); + } + } + } + // + // END XR Signal Handler ... + // + + // + hasSignal = hasLongSignal || hasShortSignal; + + // + if (!hasSignal) { + // + signal.type = X_SIGNAL_NONE; + result.type = X_SIGNAL_NONE; + } + + // + // Normalize TP, SL and Entry Price ... + signal.tp = NormalizeDouble(signal.tp, _Digits); + signal.sl = NormalizeDouble(signal.sl, _Digits); + signal.entry = NormalizeDouble(signal.entry, _Digits); + + // + result.signal = signal; + result.type = signal.type; + result.hasSignal = hasSignal; + result.provider = signal.provider; + + // + // Return Result ... + return result; +} diff --git a/Bkp/Used/14020512/Indicators/x-saherelm.ma.mq4 b/Bkp/Used/14020512/Indicators/x-saherelm.ma.mq4 new file mode 100644 index 0000000..e3a5737 --- /dev/null +++ b/Bkp/Used/14020512/Indicators/x-saherelm.ma.mq4 @@ -0,0 +1,173 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MA Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 MA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Fast MA ... +input int maLength = 20; // MA Length +input int maShift = 0; // MA Shift +input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method +input ENUM_APPLIED_PRICE maAppliedPrice = PRICE_CLOSE; // MA Applied Price + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 1 + +// +#property indicator_plots 1 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Fast Ma Buffer ... +#property indicator_label1 "Ma" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrYellow +#property indicator_style1 STYLE_DOT +#property indicator_width1 2 + +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define maBufferIndex 0 + +double maBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (maLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + // + // Ma ... + SetIndexBuffer(maBufferIndex, maBuffer); + SetIndexDrawBegin(maBufferIndex, maLength + 1); + // + // End Set Index Buffers ... + // + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, maLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Ma ... + CalculateMa(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateMa( + const int &bar_index +) { + // + // Calculating Fast Ma ... + double ma = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + maAppliedPrice, + bar_index + ); + + // + maBuffer[bar_index] = ma; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020512/Indicators/x-saherelm.xrange.mq4 b/Bkp/Used/14020512/Indicators/x-saherelm.xrange.mq4 new file mode 100644 index 0000000..1359f57 --- /dev/null +++ b/Bkp/Used/14020512/Indicators/x-saherelm.xrange.mq4 @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XRange Indicator +// --------------------------------------------- +// saherelm implementation of above 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 XRange Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 14; +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 3 + +// +#property indicator_plots 3 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Highest High Buffer ... +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +// Lowest Low Buffer ... +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +// Middle Buffer ... +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_DASH +#property indicator_width3 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +// +#define highestHighBufferIndex 0 +#define lowestLowBufferIndex 1 +#define middleBufferIndex 2 + +// +double highestHighBuffer[]; +double lowestLowBuffer[]; +double middleBuffer[]; + +// +datetime startTime; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if ( + marketLength <= 0 + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + string hhLbl = StringConcatenate( + "XR HH(", marketLength, ")" + ); + SetIndexBuffer(highestHighBufferIndex, highestHighBuffer); + SetIndexLabel(highestHighBufferIndex, hhLbl); + + // + string llLbl = StringConcatenate( + "XR LL(", marketLength, ")" + ); + SetIndexBuffer(lowestLowBufferIndex, lowestLowBuffer); + SetIndexLabel(lowestLowBufferIndex, llLbl); + + // + string midLbl = StringConcatenate( + "XR Mid(", marketLength, ")" + ); + SetIndexBuffer(middleBufferIndex, middleBuffer); + SetIndexLabel(middleBufferIndex, midLbl); + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculations ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculations ... +void CalculateBuffers( + const int &bar_index +) { + // + // Retrieve Bar Time ... + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + if (startTime == 0) { + // + startTime = barTime; + SetIndicatorBuffersNone(bar_index); + return; + } + + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + startTime + ); + + // + int startDistance = startBarIndex - bar_index; + if (startDistance < marketLength) { + // + SetIndicatorBuffersNone(bar_index); + return; + } + + // + // Highest High ... + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLength, + bar_index + ); + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + highestHighBuffer[bar_index] = hh; + + // + // Lowest Low ... + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLength, + bar_index + ); + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + lowestLowBuffer[bar_index] = ll; + + // + // Middle Buffer ... + double mid = (hh + ll) / 2; + middleBuffer[bar_index] = mid; + + // + // Reset Start Time ... + startTime = 0; +} + +// +void SetIndicatorBuffersNone( + const int bar_index +) { + // + int lastBarIndex = bar_index + 1; + + // + double lastHighestHigh; + double lastLowestLow; + + // + // Highest High ... + if (ArraySize(highestHighBuffer) > lastBarIndex) { + lastHighestHigh = highestHighBuffer[lastBarIndex]; + } else { + lastHighestHigh = 0; + } + + // + // Lowest Low ... + if (ArraySize(lowestLowBuffer) > lastBarIndex) { + lastLowestLow = lowestLowBuffer[lastBarIndex]; + } else { + lastLowestLow = 0; + } + + // + highestHighBuffer[bar_index] = lastHighestHigh; + lowestLowBuffer[bar_index] = lastLowestLow; + + // + double mid = (lastHighestHigh + lastLowestLow) / 2; + middleBuffer[bar_index] = mid; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020512/Indicators/x-saherelm.xtpow.mq4 b/Bkp/Used/14020512/Indicators/x-saherelm.xtpow.mq4 new file mode 100644 index 0000000..46ff59e --- /dev/null +++ b/Bkp/Used/14020512/Indicators/x-saherelm.xtpow.mq4 @@ -0,0 +1,275 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center Trend Power Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 MA Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 7; // Market Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_separate_window + +// +#property indicator_plots 3 +#property indicator_buffers 3 +#property indicator_minimum 0 +#property indicator_maximum 100 + +// +#property indicator_levelcolor clrGray +#property indicator_levelstyle STYLE_DOT + +// +// Start Define Indicator Buffer Styles ... +// +#property indicator_type1 DRAW_HISTOGRAM +#property indicator_color1 clrLime +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +#property indicator_type2 DRAW_HISTOGRAM +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define powerUpBufferIndex 0 +#define powerDownBufferIndex 1 +#define signalBufferIndex 2 + +double powerUpBuffer[]; +double powerDownBuffer[]; +double signalBuffer[]; + +// +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (marketLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + SetLevelValue(0, 0.0); + IndicatorSetString(INDICATOR_LEVELTEXT,0,""); + + // + SetLevelValue(1, 20.0); + IndicatorSetString(INDICATOR_LEVELTEXT,1,""); + + // + SetLevelValue(2, 50); + IndicatorSetString(INDICATOR_LEVELTEXT,2,""); + + // + SetLevelValue(3, 100); + IndicatorSetString(INDICATOR_LEVELTEXT,3,""); + + // + string pUpLbl = StringConcatenate( + "P Up (", marketLength, ")" + ); + SetIndexLabel(powerUpBufferIndex, pUpLbl); + SetIndexBuffer(powerUpBufferIndex, powerUpBuffer); + SetIndexDrawBegin(powerUpBufferIndex, marketLength + 1); + + // + string pDownLbl = StringConcatenate( + "P Down (", marketLength, ")" + ); + SetIndexLabel(powerDownBufferIndex, pDownLbl); + SetIndexBuffer(powerDownBufferIndex, powerDownBuffer); + SetIndexDrawBegin(powerDownBufferIndex, marketLength + 1); + + // + string pSignalLbl = StringConcatenate( + "P Signal (", marketLength, ")" + ); + SetIndexLabel(signalBufferIndex, pSignalLbl); + SetIndexBuffer(signalBufferIndex, signalBuffer); + SetIndexDrawBegin(signalBufferIndex, marketLength + 1); + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "X_TPW_OSC"; + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Buffers ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateBuffers( + const int &bar_index +) { + // + double powerUp = 0; + double powerDown = 0; + + // + int dailyCount = GetDailyCandleCount(); + double dailyHH = GetMarketHighestHigh( + bar_index, + dailyCount + ); + double dailyLL = GetMarketLowestLow( + bar_index, + dailyCount + ); + double dailyDiff = dailyHH - dailyLL; + double rate = dailyDiff / 100; + + // + for (int i = bar_index; i < bar_index + marketLength; i++) { + // + XOHCL c = GetCandleModel(i); + + // + double cRange = + MathAbs(c.open - c.close) + // MathAbs(c.high - c.low) + ; + bool isBullish = c.open < c.close; + + // + if (isBullish) { + powerUp += cRange; + } else { + powerDown += cRange; + } + } + + // + powerUp = powerUp / rate; + powerDown = powerDown / rate; + + // + int doubleMarketLength = (marketLength * 2); + double ema = GetMA( + bar_index, + doubleMarketLength, + 0, + MODE_EMA, + PRICE_WEIGHTED + ); + + // + double emaRate = GetMarketHighestHigh(bar_index, doubleMarketLength) - GetMarketLowestLow(bar_index, doubleMarketLength) / 100; + + // + double signal = (ema / 100) * rate; + double signalAddition = MathMin(powerUp, powerDown); + + // + powerUpBuffer[bar_index] = powerUp; + powerDownBuffer[bar_index] = powerDown; + signalBuffer[bar_index] = signal + signalAddition; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020512/Libraries/x-saherelm.draw.lib.mq4 b/Bkp/Used/14020512/Libraries/x-saherelm.draw.lib.mq4 new file mode 100644 index 0000000..776cde4 --- /dev/null +++ b/Bkp/Used/14020512/Libraries/x-saherelm.draw.lib.mq4 @@ -0,0 +1,2010 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Draw Highest High ... +bool DrawHighestHigh( + const int bar_index, + const int marketLen, + const string tag, + const int drawUntilBarIndex = 0, + const long chartID = 0, + const int subWindow = 0, + const color clr = clrAqua, + const ENUM_LINE_STYLE style = STYLE_DOT, + const int width = 1, + const bool back = false, + const bool selection = false, + const bool hidden = false, + const long zOrder = 0 +) { + // + bool result = false; + + // + // Calculate Highest High ... + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + datetime hhTime = iTime( + _Symbol, + _Period, + hhIdx + ); + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + datetime drawUntilTime = + drawUntilBarIndex != bar_index ? + iTime( + _Symbol, + _Period, + drawUntilBarIndex + ) : + barTime + ; + + // + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + int rnd = rand(); + + // + // Define Label ... + string lbl = StringConcatenate( + tag, + "_HH(", marketLen ,")_", + hh, + "_", rnd + ); + + // + result = ObjectDelete( + chartID, + lbl + ); + + // + // Draw a Trend Line ... + result = DrawTrendLine( + chartID, + lbl, + subWindow, + hhTime, + hh, + drawUntilTime, + hh, + clr, + style, + width, + back, + selection, + hidden, + zOrder + ); + + // + return result; +} + +// +// Draw Lowest Low ... +bool DrawLowestLow( + const int bar_index, + const int marketLen, + const string tag, + const int drawUntilBarIndex = 0, + const long chartID = 0, + const int subWindow = 0, + const color clr = clrFuchsia, + const ENUM_LINE_STYLE style = STYLE_DOT, + const int width = 1, + const bool back = false, + const bool selection = false, + const bool hidden = false, + const long zOrder = 0 +) { + // + bool result = false; + + // + // Calculate Highest High ... + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + datetime llTime = iTime( + _Symbol, + _Period, + llIdx + ); + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + datetime drawUntilTime = + drawUntilBarIndex != bar_index ? + iTime( + _Symbol, + _Period, + drawUntilBarIndex + ) : + barTime + ; + + // + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + int rnd = rand(); + + // + // Define Label ... + string lbl = StringConcatenate( + tag, + "_LL(", marketLen ,")_", + ll, + "_", rnd + ); + + // + result = ObjectDelete( + chartID, + lbl + ); + + // + // Draw a Trend Line ... + result = DrawTrendLine( + chartID, + lbl, + subWindow, + llTime, + ll, + drawUntilTime, + ll, + clr, + style, + width, + back, + selection, + hidden, + zOrder + ); + + // + return result; +} + +// +// Draw Market Middle ... +bool DrawMarketMiddle( + const int bar_index, + const int marketLen, + const string tag, + const int drawUntilBarIndex = 0, + const long chartID = 0, + const int subWindow = 0, + const color clr = clrYellow, + const ENUM_LINE_STYLE style = STYLE_DOT, + const int width = 1, + const bool back = false, + const bool selection = false, + const bool hidden = false, + const long zOrder = 0 +) { + // + bool result = false; + + // + // Calculate Highest High ... + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + datetime llTime = iTime( + _Symbol, + _Period, + llIdx + ); + + // + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + // Calculate Highest High ... + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + datetime hhTime = iTime( + _Symbol, + _Period, + hhIdx + ); + + // + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + double middle = ll + ((hh - ll) / 2); + datetime middleTime = hhIdx < llIdx + ? hhTime + : llTime + ; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + datetime drawUntilTime = + drawUntilBarIndex != bar_index ? + iTime( + _Symbol, + _Period, + drawUntilBarIndex + ) : + barTime + ; + + // + int rnd = rand(); + + // + // Define Label ... + string lbl = StringConcatenate( + tag, + "_MID(", marketLen ,")_", + middle, + "_", rnd + ); + + // + result = ObjectDelete( + chartID, + lbl + ); + + // + // Draw a Trend Line ... + result = DrawTrendLine( + chartID, + lbl, + subWindow, + middleTime, + middle, + drawUntilTime, + middle, + clr, + style, + width, + back, + selection, + hidden, + zOrder + ); + + // + return result; +} + +// +// Start Arrow Functions ... +// +// +// Draw an Arrow Object on Chart ... +bool DrawArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // arrow name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const uchar arrowCode = OBJ_ARROW_UP, // arrow code + const ENUM_ARROW_ANCHOR anchor = ANCHOR_BOTTOM, // anchor point position + const color clr = clrAqua, // arrow color + const ENUM_LINE_STYLE style = STYLE_SOLID, // border line style + const int width = 3, // arrow size + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // Order Object ... +) { + // + // set anchor point coordinates if they are not set ... + ChangeArrowEmptyPoint(time, price); + + // + // reset the error value ... + ResetLastError(); + + // + // create an arrow ... + if(!ObjectCreate(chartID, name, OBJ_ARROW, subWindow, time, price)) { + // + string message = StringConcatenate(__FUNCTION__, + ": failed to create an arrow! Error code = ", + GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the arrow code ... + ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, arrowCode); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set the arrow color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set the border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set the arrow's size ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the arrow by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is false by default, if you want making it possible to highlight and move the object + // change it to true ... + ObjectSetInteger(chartID,name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point of Arrow ... +bool MoveArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if(!time) { + time = TimeCurrent(); + } + + // + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete an arrow ... +bool DeleteArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow" // arrow name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete an arrow ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete an arrow! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the arrow code ... +bool ArrowCodeChange( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + const uchar code = 252 // arrow code +) { + // + // reset the error value ... + ResetLastError(); + + // + // change the arrow code ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, code)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the arrow code! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change anchor type ... +bool ArrowAnchorChange( + const long chartID = 0, // chart's ID + const string name="Arrow", // object name + const ENUM_ARROW_ANCHOR anchor = ANCHOR_TOP // anchor type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change anchor type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change anchor type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeArrowEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } +} +// +// End Arrow Functions ... +// + +// +// Start Horizontal Line Functions ... +// +// +// Create, Draw the horizontal line ... +bool DrawHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + const int subWindow = 0, // subwindow index + double price = 0, // line price + const color clr = clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the price is not set, set it at the current Bid price level ... + if(!price) { + price=SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // create a horizontal line ... + if(!ObjectCreate(chartID, name, OBJ_HLINE, subWindow, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move horizontal line ... +bool MoveHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + double price = 0 // line price +) { + // + // if the line price is not set, move it to the current Bid price level ... + if(!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move a horizontal line ... + if(!ObjectMove(chartID, name, 0, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete a horizontal line ... +bool DeleteHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a horizontal line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End Horizontal Line Functions ... +// + +// +// Start Vertical Line Functions ... +// +// +// Create the vertical line ... +bool DrawVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + const int sub_window = 0, // subwindow index + datetime time = 0, // line time + const color clr=clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the line time is not set, draw it via the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value + ResetLastError(); + + // + // create a vertical line ... + if (!ObjectCreate(chartID, name, OBJ_VLINE, sub_window, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return true; +} + +// +// Move the vertical line ... +bool MoveVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + datetime time = 0 // line time +) { + // + // if line time is not set, move the line to the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the vertical line ... + if(!ObjectMove(chartID, name, 0, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the vertical line ... +bool DeleteVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the vertical line ... + if (!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // successful execution ... + return true; +} +// +// End Vertical Line Functions ... +// + +// +// Start RectangleLabel Functions ... +// +// +// Create Rectangle Label Object ... +bool DrawRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int subWindow = 0, // subwindow index + const int x = 0, // X coordinate + const int y = 0, // Y coordinate + const int width = 50, // width + const int height = 18, // height + const color back_clr = C'236,233,216', // background color + const ENUM_BORDER_TYPE border = BORDER_SUNKEN, // border type + const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring + const color clr = clrRed, // flat border color (Flat) + const ENUM_LINE_STYLE style = STYLE_SOLID, // flat border style + const int lineWidth = 1, // flat border width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // reset the error value ... + ResetLastError(); + + // + //--- create a rectangle label + if(!ObjectCreate(chartID, name, OBJ_RECTANGLE_LABEL, subWindow, 0, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set label coordinates ... + ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x); + ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y); + + // + // set label size ... + ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width); + ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height); + + // + // set background color ... + ObjectSetInteger(chartID, name, OBJPROP_BGCOLOR, back_clr); + + // + // set border type ... + ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border); + + // + // set the chart's corner, relative to which point coordinates are defined ... + ObjectSetInteger(chartID, name, OBJPROP_CORNER, corner); + + // + // set flat border color (in Flat mode) ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set flat border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set flat border width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, lineWidth); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the label by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move Rectangle Label .. +bool MoveRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int x = 0, // X coordinate + const int y=0 // Y coordinate +) { + // + // reset the error value ... + ResetLastError(); + + // + // move the rectangle label ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move X coordinate of the label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move Y coordinate of the label! Error code = ",GetLastError() + ); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the rectangle label ... +bool DeleteRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel" // label name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the label ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change Rectangle Label Size ... +bool ChangeSizeRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int width = 50, // label width + const int height = 18 // label height +) { + // + // reset the error value ... + ResetLastError(); + + // + // change label size ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's width! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's height! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change rectangle label border type ... +bool RectLabelChangeBorderType( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const ENUM_BORDER_TYPE border = BORDER_SUNKEN // border type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change border type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the border type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End RectangleLabel Functions ... +// + +// +// Start TrendLine Funcions ... +// +// Create a trend line by the given coordinates ... +bool DrawTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrYellow, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool rayRight = false, // line's continuation to the right + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeTrendLineEmptyPoints( + time1, + price1, + time2, + price2 + ); + + // + // reset the error value ... + ResetLastError(); + + // + // create a trend line by the given coordinates ... + if(!ObjectCreate(chartID, name, OBJ_TREND, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the line's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move trend line anchor point ... | +bool ChangeTrendLinePoint( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int pointindex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move trend line's anchor point ... + if(!ObjectMove(chartID, name, pointindex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// The function deletes the trend line from the chart ... +bool DeleteTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a trend line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of trend line's anchor points and set default ... +// values for empty ones ... +void ChangeTrendLineEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the first point's time is not set, it will be on the current bar ... + if (!time1) { + time1 = TimeCurrent(); + } + + // + // if the first point's price is not set, it will have Bid value ... + if (!price1) { + price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // if the second point's time is not set, it is located 9 bars left from the second one ... + if (!time2) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(), Period(), time1, 10, temp); + + // + // set the second point 9 bars left from the first one ... + time2 = temp[0]; + } + + // + // if the second point's price is not set, it is equal to the first point's one ... + if (!price2) { + price2 = price1; + } +} +// +// End TrendLine Functions ... +// + +// +// Start Text Functions ... +// +// Create and Draw a Text Object ... +bool DrawText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const string text = "Text", // the text itself + const string font = "Arial", // font + const int fontSize = 10, // font size + const color clr = clrRed, // color + const double angle = 0.0, // text slope + const ENUM_ANCHOR_POINT anchor = ANCHOR_CENTER, // anchor type + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor point coordinates if they are not set ... + ChangeTextEmptyPoint(time,price); + + // + // reset the error value ... + ResetLastError(); + + // + //--- create Text object + if(!ObjectCreate(chartID, name, OBJ_TEXT, subWindow, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the text ... + ObjectSetString(chartID, name , OBJPROP_TEXT, text); + + // + // set text font ... + ObjectSetString(chartID, name, OBJPROP_FONT, font); + + // + // set font size ... + ObjectSetInteger(chartID, name, OBJPROP_FONTSIZE, fontSize); + + // + // set the slope angle of the text ... + ObjectSetDouble(chartID, name, OBJPROP_ANGLE, angle); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the object by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID ,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point ... +bool MoveText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + //--- if point position is not set, move it to the current bar having Bid price + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point .. + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the object text ... +bool ChangeText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const string text = "Text" // text +) { + // + // reset the error value ... + ResetLastError(); + + // + // change object text ... + if(!ObjectSetString(chartID, name, OBJPROP_TEXT, text)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the text! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Text object ... +bool DeleteText( + const long chartID = 0, // chart's ID + const string name = "Text" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeTextEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + } +// +// End Text Functions ... +// + +// +// Start Fibonacchi Functions ... +// +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawFibonacci( + const long chartID = 0, // chart's ID + const string name="Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrRed, // object color + const ENUM_LINE_STYLE style = STYLE_SOLID, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawCustomFibonacci( + // + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + // + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrAqua, // object color + const ENUM_LINE_STYLE style = STYLE_DOT, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // Change Levels Of Fibonacci ... + bool result = FibonacciLevelsSet( + levels, + values, + colors, + styles, + widths, + descriptions, + chartID, + name + ); + + // + // successful execution ... + return result; +} + +// +// Set number of levels and their parameters ... +bool FibonacciLevelsSet( + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // check array sizes ... + if( + levels!=ArraySize(colors) || + levels!=ArraySize(styles) || + levels!=ArraySize(widths) || + levels!=ArraySize(widths) + ) { + // + string message = StringConcatenate( + __FUNCTION__, + ": array length does not correspond to the number of levels, error!" + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the number of levels ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELS, levels); + + // + // set the properties of levels in the loop ... + for(int i = 0; i < levels; i++) { + // + // level value ... + ObjectSetDouble(chartID, name, OBJPROP_LEVELVALUE, i, values[i]); + + // + // level color ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELCOLOR, i, colors[i]); + + // + // level style ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELSTYLE, i, styles[i]); + + // + // level width ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELWIDTH, i, widths[i]); + + // + // level description ... + // ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, DoubleToString(100 * values[i], 1)); + ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, descriptions[i]); + } + + // + // successful execution ... + return(true); +} + +// +// Move Fibonacci Retracement anchor point ... +bool FibonacciPointChange( + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int pointIndex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, pointIndex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Fibonacci Retracement ... +bool DeleteFibonachi( + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Fibonacci Retracement\"! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of Fibonacci Retracement anchor points and set +// default values for empty ones ... +void ChangeFibonacciEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the second point's time is not set, it will be on the current bar ... + if (!time2) { + time2 = TimeCurrent(); + } + + // + // if the second point's price is not set, it will have Bid value ... + if (!price2) { + price2 = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // if the first point's time is not set, it is located 9 bars left from the second one ... + if (!time1) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(),Period(),time2,10,temp); + + // + // set the first point 9 bars left from the second one ... + time1 = temp[0]; + } + + // + // if the first point's price is not set, move it 200 points below the second one ... + if (!price1) { + price1 = price2 - 200 * SymbolInfoDouble(_Symbol, SYMBOL_POINT); + } +} +// +// End Fibonacci Functions ... +// + + +// +// Start General Functions ... +// +// +// Remove all Drawn Objects ... +void RemoveDraws(const string &tag) { + // + for(int iObj=ObjectsTotal()-1; iObj >= 0; iObj--) { + // + string on = ObjectName(iObj); + if (StringFind(on, tag) == 0) { + ObjectDelete(on); + } + } +} +// +// End General Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020512/Libraries/x-saherelm.indicator.lib.mq4 b/Bkp/Used/14020512/Libraries/x-saherelm.indicator.lib.mq4 new file mode 100644 index 0000000..4605408 --- /dev/null +++ b/Bkp/Used/14020512/Libraries/x-saherelm.indicator.lib.mq4 @@ -0,0 +1,375 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Indicator Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// Reading specified Buffer From ADX Indicator ... +double ReadXMABuffer( + const int bar_index, + const int buffer_index, + // + const int marketLen, + // + const double stp, + const double mxm, + // + const int shortCycleMult, + const int mediumCycleMult, + const int longCycleMult +) { + // + string xmaIndicatorName = "x-saherelm.x.xma"; + + // + double result = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // Inputs ... + marketLen, + stp, + mxm, + shortCycleMult, + mediumCycleMult, + longCycleMult, + MODE_SMA, + // + buffer_index, + bar_index + ); + + // + return result; +} + +// +// Reading specified Buffer from XHL Indicator ... +double ReadXHLBuffer( + const int bar_index, + const int buffer_index, + // + const int marketLen, + // + const int shortCycleMult, + const int mediumCycleMult, + const int longCycleMult +) { + // + string xhlIndicatorName = "x-saherelm.x.hl"; + + // + double result = iCustom( + _Symbol, + _Period, + xhlIndicatorName, + // + // Inputs ... + marketLen, + shortCycleMult, + mediumCycleMult, + longCycleMult, + MODE_SMA, + // + buffer_index, + bar_index + ); + + // + return result; +} + +// +// Reading ADX Values ... +double ReadADX( + const int bar_index, + const int marketLen, + const int mult +) { + // + double result; + + // + int period = marketLen * mult; + + // + result = iADX( + _Symbol, + _Period, + period, + PRICE_CLOSE, + MODE_MAIN, + bar_index + ); + + // + return result; +} + +// +// Calculate XRange from Market ... +static XRState lastXRState; +XRState GetXRange( + const int bar_index, + const int rangeMarketLength +) { + // + XRState result = {}; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + int marketBarIndex = bar_index + rangeMarketLength; + + // + // Highest High ... + // + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketBarIndex, + bar_index + ); + + // + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + // Lowest Low ... + // + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketBarIndex, + bar_index + ); + + // + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + if (lastXRState.start == 0) { + // + lastXRState.start = barTime; + lastXRState.length = rangeMarketLength; + + // + lastXRState.hh = hh; + lastXRState.ll = ll; + + // + // Middle ... + double mid = (hh + ll) / 2; + lastXRState.mid = mid; + } else { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + lastXRState.start + ); + + // + if (startBarIndex - bar_index >= rangeMarketLength) { + // + lastXRState.start = barTime; + lastXRState.length = rangeMarketLength; + + // + lastXRState.hh = hh; + lastXRState.ll = ll; + + // + // Middle ... + double mid = (hh + ll) / 2; + lastXRState.mid = mid; + } + } + + // + result = lastXRState; + + // + return result; +} + +// +// Reading XTPowState from Indicatoe ... +XTPOWState GetXTPowState( + const int bar_index, + const int marketLen +) { + // + XTPOWState result = {}; + + // + // + double powerUp = 0; + double powerDown = 0; + double signal = 0; + + // + string indicatorName = "x-saherelm.xtpow"; + + // + int pUpIndex = 0; + int pDownIndex = 1; + int signalIndex = 2; + + // + powerUp = iCustom( + _Symbol, + _Period, + indicatorName, + // + marketLen, + // + pUpIndex, + bar_index + ); + + // + powerDown = iCustom( + _Symbol, + _Period, + indicatorName, + // + marketLen, + // + pDownIndex, + bar_index + ); + + // + signal = iCustom( + _Symbol, + _Period, + indicatorName, + // + marketLen, + // + signalIndex, + bar_index + ); + + // + result.signal = signal; + result.powerUp = powerUp; + result.powerDown = powerDown; + + // + return result; +} + +// +// Reading XRState From Indicator ... +XRState ReadXRange( + const int bar_index, + const int marketLen +) { + // + XRState result = {}; + + // + // Define Buffer Indexes ... + int hhBufferIndex = 0; + int llBufferIndex = 1; + int midBufferIndex = 2; + + // + string indicatorName = "x-saherelm.xrange"; + + // + // Read Values From XRange Indicator ... + + // + double hh = iCustom( + _Symbol, + _Period, + indicatorName, + // + // Inputs ... + marketLen, + // + hhBufferIndex, // Buffer Index ... + bar_index + ); + + // + double ll = iCustom( + _Symbol, + _Period, + indicatorName, + // + // Inputs ... + marketLen, + // + llBufferIndex, // Buffer Index ... + bar_index + ); + + // + double mid = iCustom( + _Symbol, + _Period, + indicatorName, + // + // Inputs ... + marketLen, + // + midBufferIndex, // Buffer Index ... + bar_index + ); + + // + // Filling Result ... + result.hh = hh; + result.ll = ll; + result.mid = mid; + + // + return result; +} +// +// END Indicator Reading Data ... +// diff --git a/Bkp/Used/14020512/Libraries/x-saherelm.lib.mq4 b/Bkp/Used/14020512/Libraries/x-saherelm.lib.mq4 new file mode 100644 index 0000000..cc0e23e --- /dev/null +++ b/Bkp/Used/14020512/Libraries/x-saherelm.lib.mq4 @@ -0,0 +1,1662 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +static datetime lastBarTime; + +// +struct XOHCL { + double high; + double open; + double close; + double low; +}; + +// +struct XRange { + // + datetime time; + + // + double highestHigh; + double lowestLow; + + // + int levels; + int marketLength; + + // + double rate; +}; + +// +struct XPrice { + // + double askPrice; + double bidPrice; + double priceGap; + + // + double longEntry; + double longExit; + + // + double shortEntry; + double shortExit; +}; + +// +// START Functions ... +// + +// +// Determines current working is New Bar or not ... +bool IsNewBar() { + // + // Reading Last Bar Date ... + datetime curbar = (datetime)SeriesInfoInteger( + _Symbol, + _Period, + SERIES_LASTBAR_DATE + ); + + // + if(lastBarTime != curbar) { + // + lastBarTime = curbar; + return true; + } + + // + return false; +} + +// +// Determines we are in new Day or not ... +bool IsNewDay() { + // + bool result = false; + + // + // Reading Last Bar Date ... + datetime curbar = (datetime)SeriesInfoInteger( + _Symbol, + _Period, + SERIES_LASTBAR_DATE + ); + + // + if (lastBarTime == 0) { + lastBarTime = curbar; + } + + // + if (curbar == lastBarTime) { + return result; + } + + // + // Retrieve Day and Month and Year for Last Bar Time ... + int lastBarDay = TimeDay(lastBarTime); + int lastBarMonth = TimeMonth(lastBarTime); + int lastBarYear = TimeYear(lastBarTime); + + // + // Retrieve Day and Month and Year for Current Bar Time ... + int curBarDay = TimeDay(curbar); + int curBarMonth = TimeMonth(curbar); + int curBarYear = TimeYear(curbar); + + // + result = curBarDay > lastBarDay + || curBarMonth > lastBarMonth + || curBarYear > lastBarYear; + + // + return result; +} + +// +// Retrieve Number of Candles in a Day ... +int GetDailyCandleCount() { + // + int seconds = PeriodSeconds(_Period); + + // + int daySeconds = 24 * 60 * 60; + + // + int result = daySeconds / seconds; + + // + return result; +} + +// +// XRange Detector ... +XRange GetMarketRange( + const int bar_index, + const int marketLen, + const int levels +) { + // + XRange result = {}; + + // + result.levels = levels; + result.marketLength = marketLen; + + // + datetime time = iTime( + _Symbol, + _Period, + bar_index + ); + result.time = time; + + // + double highestHigh = GetMarketHighestHigh( + bar_index, + marketLen + ); + result.highestHigh = highestHigh; + + // + double lowestLow = GetMarketLowestLow( + bar_index, + marketLen + ); + result.lowestLow = lowestLow; + + // + double diff = highestHigh - lowestLow; + double rate = diff / levels; + + // + result.rate = rate; + + // + return result; +} + +// +// Retrieve RMA on Specific Candle ... +double GetRMA( + int bar_index, + int length +) { + // + double shortSMA = iMA(_Symbol, _Period, length, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double mediumSMA = iMA(_Symbol, _Period, length * 2, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double longSMA = iMA(_Symbol, _Period, length * 3, 0, MODE_SMA, PRICE_CLOSE, bar_index); + + // + double result = longSMA - mediumSMA + shortSMA; + + // + return result; +} + +// +// Retrieve Moving Average ... +double GetMA( + const int bar_index, + const int maLength, + const int maShift, + const ENUM_MA_METHOD maMethod, + const ENUM_APPLIED_PRICE appliedPrice +) { + // + double result = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + appliedPrice, + bar_index + ); + + // + return result; +} + +// +// Calculate Fib Level ... +double GetFibonacciLevel( + double upPrice, + double downPrice, + double level, + int direction +) { + // + double ling = upPrice - downPrice; + double pLevel = (ling / 100) * (level * 100); + + // + double result = direction > 0 ? + upPrice - pLevel : + downPrice + pLevel; + result = NormalizeDouble(result, _Digits); + + // + return result; +} + +// +// Retrieve True Range ... +double GetTR( + const int bar_index +) { + // + double result = 0; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double prevClose = iClose( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double highLowDif = high - low; + double hpCDif = MathAbs(high - prevClose); + double lpCDiff = MathAbs(low - prevClose); + + // + result = MathMax(highLowDif, hpCDif); + result = MathMax(result, lpCDiff); + + // + return result; +} + +// +// Calculate True Range Simple Moving Average ... +double GetMarketTRSMA( + const int bar_index, + const int marketLen +) { + // + double result = 0; + + // + // Create Barket Length Trs ... + double trs[]; + ArrayResize( + trs, + marketLen + ); + int index = 0; + double trSum = 0; + for (int i = bar_index; i < bar_index + marketLen; i++) { + // + double tr = GetTR(i); + trs[index] = tr; + + // + trSum += tr; + + // + index++; + } + + // + result = trSum / marketLen; + + // + return result; +} + +// +// Retrieve Commodity Channel ... +double GetMarketCCI( + const int bar_index, + const int marketLen, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE +) { + // + double result = 0; + + // + result = iCCI( + _Symbol, + _Period, + marketLen, + appliedPrice, + bar_index + ); + + // + return result; +} + +// +// this function check crossing up two Buffers ... +bool IsCrossedOver( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] > arr2[index1]) && !(arr1[index2] > arr2[index2]); + + // + return result; +} + +// +// this function check crossing down two Buffers ... +bool IsCrossedUnder( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] < arr2[index1]) && !(arr1[index2] < arr2[index2]); + + // + return result; +} + +// +// Convert points to Actual Point ... +double PointsToDouble(int points) { + // + double result = points * _Point; + return result; +} + +// +// Converts Pips to Points ... +int PipsToPoints(int pips) { + // + int result = pips * ((_Digits == 3 || _Digits == 5) ? 10 : 1); + return result; +} + +// +// Converts Pips to Double ... +double PipsToDouble(int pips) { + // + double result = PointsToDouble(PipsToPoints(pips)); + return result; +} + +// +// Converts Double Value to Pips ... +int PriceToPips(double value) { + // + if (value <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + int result = (int)(value / pipValue); + + // + return result; +} + +// +// Converts Pips to Double ... +double PipsToPrice(int pips) { + // + if (pips <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + double result = pipValue * pips; + + // + return result; +} + +// +// Generate ATR StopLoss Value ... +double CalculateATRSL( + int period, + double multiplier +) { + // + if (period <= 0 || multiplier <= 0) { + return 0; + } + + // + double atrValue = iATR( + _Symbol, + _Period, + period, + 0 + ); + + // + double result = atrValue * multiplier; + + // + return result; +} + +// +// Detect Candle Type ... +// Bullish => means close > open ... +bool IsBullishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBullishCandle( + open, + close + ); + + // + return result; +} + +bool IsBullishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open < close; + + // + return result; +} + +// +// Detect Candle Type ... +// Bearish => means close < open ... +bool IsBearishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBearishCandle( + open, + close + ); + + // + return result; +} + +bool IsBearishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open > close; + + // + return result; +} + +// +// Retrieve a Candle Info ... +XOHCL GetCandleModel( + const int bar_index +) { + // + XOHCL result = {}; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + result.high = high; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + result.open = open; + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + result.close = close; + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + result.low = low; + + // + return result; +} + +// +// Retrieve Market Current Prices for Signals ... +XPrice GetPrice() { + // + XPrice result = {}; + + // + RefreshRates(); + + // + double askPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double bidPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(bidPrice - askPrice); + + // + result.askPrice = askPrice; + result.bidPrice = bidPrice; + result.priceGap = priceGap; + + // + result.longEntry = askPrice; + result.longExit = bidPrice; + + // + result.shortEntry = bidPrice; + result.shortExit = askPrice; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBullishDetected( + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double shpDetectMultipliers // Sharp Detect Multiplier +) { + // + bool result = false; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double minValue = 0; + double maxValue = 0; + int positionedLength = bar_index + marketLen; + + // + for (int i = bar_index; i < positionedLength; i++) { + // + double cHigh = iHigh( + _Symbol, + _Period, + i + ); + + // + double cLow = iLow( + _Symbol, + _Period, + i + ); + + // + minValue += MathMin(cLow, cHigh); + maxValue += MathMax(cLow, cHigh); + } + + // + double minAvg = minValue / positionedLength; + double maxAvg = maxValue / positionedLength; + + // + double shpValue = shpDetectMultipliers * _Point; + + // + result = (low - minAvg) > shpValue; + + // + int index = bar_index; + while ( + index < positionedLength + || !result + ) { + // + low = iLow( + _Symbol, + _Period, + index + ); + + // + result = result + || (low - minAvg) > shpValue; + + // + index++; + }; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBearishDetected( + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double shpDetectMultipliers // Sharp Detect Multiplier +) { + // + bool result = false; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double minValue = 0; + double maxValue = 0; + int positionedLength = bar_index + marketLen; + + // + for (int i = bar_index; i < positionedLength; i++) { + // + double cHigh = iHigh( + _Symbol, + _Period, + i + ); + + // + double cLow = iLow( + _Symbol, + _Period, + i + ); + + // + minValue += MathMin(cLow, cHigh); + maxValue += MathMax(cLow, cHigh); + } + + // + double minAvg = minValue / positionedLength; + double maxAvg = maxValue / positionedLength; + + // + double shpValue = shpDetectMultipliers * _Point; + + // + result = (high - maxAvg) > shpValue; + + // + int index = bar_index; + while ( + index < positionedLength + || !result + ) { + // + high = iHigh( + _Symbol, + _Period, + index + ); + + // + result = result + || (high - maxAvg) > shpValue; + + // + index++; + }; + + // + return result; +} + +// +// Retrieve Highest High Value based on Given Market ... +double GetMarketHighestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Low Value based on Given Market ... +double GetMarketHighestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Open Value based on Given Market ... +double GetMarketHighestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Close Value based on Given Market ... +double GetMarketHighestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Low Value based on Given Market ... +double GetMarketLowestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest High Value based on Given Market ... +double GetMarketLowestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Open Value based on Given Market ... +double GetMarketLowestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Close Value based on Given Market ... +double GetMarketLowestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// less than given price ... +double GetLowLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// great than given price ... +double GetLowGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// less than given price ... +double GetHighLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// great than given price ... +double GetHighGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// less than given price ... +double GetCloseLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// great than given price ... +double GetCloseGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Get Slope of a Line by it's two Point ... +double GetSlope( + double x1, + double y1, + double x2, + double y2 +) { + // + double result = (y2 - y1)/MathAbs(x2 - x1); + return result; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/14020512/Libraries/x-saherelm.log.lib.mq4 b/Bkp/Used/14020512/Libraries/x-saherelm.log.lib.mq4 new file mode 100644 index 0000000..066b3f7 --- /dev/null +++ b/Bkp/Used/14020512/Libraries/x-saherelm.log.lib.mq4 @@ -0,0 +1,91 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Log Tag ... +static string logTag = ""; + +// +// Enable or Disable Logging ... +static bool enableLogging = false; + +// +// Start Log Messages ... +// + +// +// Logging a Message, specified for this EA ... +// using provided LogTag ... +void LogMessage(string message) { + // + if (!enableLogging) { + return; + } + + // + Print(logTag, " > ", message); +} + +// +// this used for logging series ... +void LogSeries( + double &series[], // which series to Log ... + int length = 0, // number of items to Log, 0 means all ... + int skip = 0 // number of items which skip before logging ... +) { + // + string msg = ""; + + // + int seriesSize = ArraySize(series); + if ( + skip < 0 + || length < 0 + || seriesSize == 0 + || skip > seriesSize + || skip + length > seriesSize + ) { + return; + } + + // + length = length == 0 ? + seriesSize : + length; + int start = skip > 1 ? + skip - 1 : + skip == 1 ? + 1 : + 0; + + // + // Loop through series items ... + for (int i = start; i < start + length; i++) { + // + msg += StringConcatenate( + "i[", i, "]: ", series[i], ", " + ); + } + + // + LogMessage(msg); +} +// +// End Log Messages ... +// + diff --git a/Bkp/Used/14020512/Libraries/x-saherelm.models.lib.mq4 b/Bkp/Used/14020512/Libraries/x-saherelm.models.lib.mq4 new file mode 100644 index 0000000..1ade462 --- /dev/null +++ b/Bkp/Used/14020512/Libraries/x-saherelm.models.lib.mq4 @@ -0,0 +1,138 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Models Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// START STATIC Variables ... +// +// +static int totalSignals = 0; +static int totalLongSignals = 0; +static int totalShortSignals = 0; + +// +static double initialBalance = 0; + +// +static int countedBars = 0; +static bool isNewBar = false; +static bool isNewDay = false; +// +// END STATIC Variables ... +// + +// +// Start Models ... +// +// +// Signal Providers ... +enum ENUM_X_SIGNAL_PROVIDER { + X_UNKNOWN_PROVIDER, + X_XXX_PROVIDER, + X_XR_PROVIDER, + X_XTPW_PROVIDER +}; + +// +// these are different signal types ... +enum ENUM_X_SIGNAL_TYPE { + X_SIGNAL_NONE, + X_SIGNAL_LONG, + X_SIGNAL_SHORT, +}; + +// +// we Model each signals as this type ... +struct XSignal { + // + // Signal Symbol ... + string symbol; + + // + // Signal Type ... + ENUM_X_SIGNAL_TYPE type; + + // + // Signal ID ... + int id; + + // + // Signal Ticket Number, when Opening Trade ... + int ticket; + + // + // Signal Provider ... + ENUM_X_SIGNAL_PROVIDER provider; + + // + // Target Point ... + double tp; + + // + // Stop Loss ... + double sl; + + // + // Signal Entry Price ... + double entry; + + // + // Signalling Time ... + datetime time; + + // + // Signal Comments ... + string comment; + + // + // Signal TAG ... + string tag; +}; + +// +// this is Signal Request Response model ... +struct XSignalRequest { + bool hasSignal; + XSignal signal; + ENUM_X_SIGNAL_TYPE type; + ENUM_X_SIGNAL_PROVIDER provider; +}; + +// +struct XRState { + // + datetime start; + int length; + + // + double hh; + double ll; + double mid; +}; + +// +struct XTPOWState { + // + double powerUp; + double powerDown; + + // + double signal; +}; +// +// End Models ... +// diff --git a/Bkp/Used/14020512/Libraries/x-saherelm.signal.lib.mq4 b/Bkp/Used/14020512/Libraries/x-saherelm.signal.lib.mq4 new file mode 100644 index 0000000..c85d593 --- /dev/null +++ b/Bkp/Used/14020512/Libraries/x-saherelm.signal.lib.mq4 @@ -0,0 +1,1755 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Signal Draw Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +#include "../Libraries/x-saherelm.x.signal.lib.mq4" +#include "../Libraries/x-saherelm.xr.signal.lib.mq4" +#include "../Libraries/x-saherelm.xtpw.signal.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// END Global Requirement Functions ... +// + +// +// START Signal Related Functions ... +// +// +// Retrieve Signal Bar Index ... +int GetSignalBarIndex(XSignal &signal) { + // + // Temp Result ... + int result = -1; + + // + // Retriev Signal Bar Index ... + result = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + return result; +} + +// +string GetSignalProviderIdentifier( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + string result = ""; + + // + switch (provider) { + // + case X_XXX_PROVIDER: + result = "XXX"; + break; + + // + case X_XR_PROVIDER: + result = "XR"; + break; + + // + case X_XTPW_PROVIDER: + result = "XTPW"; + break; + + // + default: + result = ""; + break; + } + + // + return result; +} + +// +ENUM_X_SIGNAL_PROVIDER GetSignalProvider(string identifier) { + // + ENUM_X_SIGNAL_PROVIDER result = X_UNKNOWN_PROVIDER; + + // + if ( + StringFind( + identifier, + GetSignalProviderIdentifier(X_XXX_PROVIDER) + ) > -1 + ) { + result = X_XXX_PROVIDER; + } else if ( + StringFind( + identifier, + GetSignalProviderIdentifier(X_XR_PROVIDER) + ) > -1 + ) { + result = X_XR_PROVIDER; + } else if ( + StringFind( + identifier, + GetSignalProviderIdentifier(X_XTPW_PROVIDER) + ) > -1 + ) { + result = X_XTPW_PROVIDER; + } + + // + return result; +} + +// +// Retrieve Signal Lots Per Trade ... +double GetSignalLottage( + const XSignal &signal, + const double defLotsPerTrade +) { + // + double result = defLotsPerTrade; + + // + bool isLong = signal.type == X_SIGNAL_LONG; + + // + switch (signal.provider) { + // + case X_XR_PROVIDER: + // + result = isLong ? + xRLongLotsPerTradePercent : + xRShortLotsPerTradePercent + ; + break; + + // + case X_XXX_PROVIDER: + // + result = isLong ? + xLongLotsPerTradePercent : + xShortLotsPerTradePercent + ; + break; + + // + case X_XTPW_PROVIDER: + // + result = isLong ? + xTPWLongLotsPerTradePercent : + xTPWShortLotsPerTradePercent + ; + break; + } + + // + return result; +} + +// +// Draw Specific Range On Chart ... +void DrawRange( + const XRange &range, + const long chartID = 0, + const int subWindowID = 0, + const string tag = "", + const color clr = clrYellow +) { + // + // Loop through Levels Count ... + for (int i = 0; i <= range.levels; i++) { + // + datetime time1 = iTime( + _Symbol, + _Period, + 1 + ); + + // + datetime time2 = iTime( + _Symbol, + _Period, + 0 + ); + + // + double price = range.lowestLow + (i * range.rate); + + // + string lbl = StringConcatenate( + tag, + "_XRL_", + price + ); + + // + DrawTrendLine( + chartID, + lbl, + subWindowID, + time1, + price, + time2, + price, + clr, + STYLE_DOT + ); + } +} + +// +// Draw Signal Shapes on Chart ... +bool DrawSignal( + const XSignal &signal, + long chartID = 0, + int subWindowID = 0, + const double positionThresholdFactor = 10, + string longSignalLabel = "X-Long", + color longSignalColor = clrAqua, + string shortSignalLabel = "X-Short", + color shortSignalColor = clrFuchsia +) { + // + // Generate isLongSignal Var ... + bool isLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Signal Bar Index ... + int bar_index = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // START Draw Signal Arrow ... + // + // + // Arrow Shape Name ... + string arrowName = StringConcatenate(signal.tag, "_Arrow_", signal.id); + + // + // Arrow Price ... + double arrowPrice = 0; + if (isLongSignal) { + // + arrowPrice = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice - (positionThresholdFactor * _Point); + } else { + // + arrowPrice = iHigh( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice + (positionThresholdFactor * _Point); + } + + // + // Arrow Code ... + uchar arrowCode = isLongSignal ? SYMBOL_ARROWUP : SYMBOL_ARROWDOWN; + + // + // Arrow Anchor Point ... + ENUM_ARROW_ANCHOR arrowAnchorPoint = isLongSignal ? ANCHOR_BOTTOM : ANCHOR_TOP; + + // + // Arrow Color ... + color arrowColor = isLongSignal ? longSignalColor : shortSignalColor; + + // + // Draw Signal Arrow Shape ... + bool result = DrawArrow( + chartID, + arrowName, + subWindowID, + signal.time, + arrowPrice, + arrowCode, + arrowAnchorPoint, + arrowColor + ); + // + // END Draw Signal Arrow ... + // + + // + // START Draw Signal SL/TP ... + // + string slLineName = StringConcatenate(signal.tag, "_SL_", signal.id); + string tpLineName = StringConcatenate(signal.tag, "_TP_", signal.id); + string entryLineName = StringConcatenate(signal.tag, "_ENTRY_", signal.id); + + // + color slColor = shortSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color tpColor = longSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color entryColor = clrGreen; + + // + datetime time1 = iTime( + _Symbol, + _Period, + bar_index + 1 + ); + + // + // Draw Enrty Price ... + result = DrawTrendLine( + chartID, + entryLineName, + subWindowID, + time1, + signal.entry, + signal.time, + signal.entry, + entryColor, + STYLE_SOLID, + 2 + ); + + // + // Draw Signal SL ... + if (signal.sl > 0) { + // + result = DrawTrendLine( + chartID, + slLineName, + subWindowID, + time1, + signal.sl, + signal.time, + signal.sl, + slColor, + STYLE_SOLID, + 2 + ); + } + + // + // Draw Signal TP ... + if (signal.tp > 0) { + // + result = DrawTrendLine( + chartID, + tpLineName, + subWindowID, + time1, + signal.tp, + signal.time, + signal.tp, + tpColor, + STYLE_SOLID, + 2 + ); + } + // + // END Draw Signal SL/TP ... + // + + // + // Start Draw Signal Label ... + // + // + string labelName = StringConcatenate(signal.tag, "_Label_", signal.id); + + // + double labelPrice = isLongSignal ? arrowPrice - (positionThresholdFactor * _Point) : arrowPrice + (positionThresholdFactor * _Point); + + // + string labelText = isLongSignal ? longSignalLabel : shortSignalLabel; + labelText = StringConcatenate( + labelText, + "_", + GetSignalProviderIdentifier(signal.provider) + ); + + // + result = DrawText( + chartID, + labelName, + subWindowID, + signal.time, + labelPrice, + labelText, + "Arial", + 8, + arrowColor, + 0, + ANCHOR_CENTER + ); + // + // End Draw Signal Label ... + // + + // + return result; +} + +// +// Trade on Specific Signal ... +bool TradeSignal( + XSignal &signal, + // + double volumePercent, + // + // Long ... + const string longSignalLabel, + const color longSignalColor, + // + // Short ... + const string shortSignalLabel, + const color shortSignalColor +) { + // + // Temp Result ... + bool result = false; + + // + if (initialBalance == 0) { + initialBalance = AccountInfoDouble(ACCOUNT_BALANCE); + } + + // + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + int openPositions = CountOpenTrades(); + double volume = (volumePercent * initialBalance); + + // + if ( + signal.type != X_SIGNAL_LONG && + signal.type != X_SIGNAL_SHORT + ) { + return result; + } + + // + bool hasLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Check TP and Entry Price ... + if ( + ( + hasLongSignal + && signal.entry > signal.tp + ) || + ( + !hasLongSignal + && signal.entry < signal.tp + ) + ) { + return result; + } + + // + // Order Operation ... + int operation = hasLongSignal ? + OP_BUY : + OP_SELL; + + // + // Detect Trade Color ... + color clr = hasLongSignal ? + longSignalColor : + shortSignalColor; + + // + // Generate Signal Comment ... + string label = hasLongSignal ? + longSignalLabel : + shortSignalLabel; + + // + // Generate Signal Comment ... + string comment = StringConcatenate( + signal.tag, + "_", signal.id, + "_", GetSignalProviderIdentifier(signal.provider), + "_", label + ); + + // + // Placing Order ... + int orderTicket = OrderSend( + _Symbol, + operation, + volume, + signal.entry, + 3, + signal.sl, + signal.tp, + comment, + signal.id, + 0, + clr + ); + + // + // Draw Signal Shape if Order Opened Successfully ... + if (orderTicket >= 0) { + // + signal.ticket = orderTicket; + + // + // Here i must to Draw Signal Shapes ... + bool isDrawn = DrawSignal( + signal, + 0, + 0, + 50, + longSignalLabel, // Long Signal Label ... + longSignalColor, + shortSignalLabel, // Short Signal Label ... + shortSignalColor + ); + + // + LogMessage( + StringConcatenate( + "Order [", orderTicket ,"]: Provided by: ", GetSignalProviderIdentifier(signal.provider) + ) + ); + + // + // TODO: here we have to check if there are another + // open positions which their entry price is bigger + // than current signal entry price, for long trades and + // their tp is high than current tp, ... + // close in profit trades or modify orders tp to current ... + // // + // if (CountOpenTrades() > 0) { + // // + // // Here we have to + // ModifyOpenTradesBasedOnCurrentTrade(signal); + // } + + // + result = true; + } + + // + return result; +} +// +// END Signal Related Functions ... +// + +// +// START Orders Functions ... +// +// +// Convert To XSignal Model ... +XSignal OrderToSignal() { + // + // Temp Result ... + XSignal result = {}; + result.type = X_SIGNAL_NONE; + + // + // Here we can get some usefull info based on selected order ... + double swap = OrderSwap(); + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + int magicNumber = OrderMagicNumber(); + double takeProfit = OrderTakeProfit(); + string comment = OrderComment(); + + // + ENUM_X_SIGNAL_PROVIDER provider = GetSignalProvider(comment); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // Conver Position to Signal ... + result.sl = stopLoss; + result.tp = takeProfit; + result.time = openTime; + result.symbol = _Symbol; + result.id = magicNumber; + result.comment = comment; + result.entry = openPrice; + result.provider = provider; + result.type = isLongOrder ? X_SIGNAL_LONG : X_SIGNAL_SHORT; + + // + return result; +} + +// +// START Count Orders ... +// +// +// Count Open Positions ... +int CountOpenTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if (OrderSymbol() == _Symbol) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Long Positions ... +int CountOpenLongTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_BUY + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Short Positions ... +int CountOpenShortTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_SELL + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} +// +// END Count Orders ... +// + +// +// START Close Orders ... +// +// +// Close All Open Trades ... +bool CloseAllTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + + // + return result; +} + +// +bool CloseAllProviderTrades( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal(); + + // + if (signal.provider == provider) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +bool CloseAllProviderLongTrades( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal(); + + // + if ( + signal.provider == provider + && signal.type == X_SIGNAL_LONG + ) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +bool CloseAllProviderShortTrades( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal(); + + // + if ( + signal.provider == provider + && signal.type == X_SIGNAL_SHORT + ) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Long Trades ... +bool CloseAllLongTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Long Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Short Trades ... +bool CloseAllShortTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (!isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Short Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In Profit Trades ... +bool CloseAllInProfitTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit > 0 + && profit > 50 * _Point + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InProfit Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In DrawDown Trades ... +bool CloseAllInDrawDownTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if (profit < 0) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close Biggest In DrawDown Trades ... +bool CloseBiggestDrawDownTrade() { + // + // Loop through all Positions ... + bool result = false; + double drawDown = 0; + + // + // Find Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) > drawDown + ) { + drawDown = profit; + } + } + } + } + + // + // Close Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) >= drawDown + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Max InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Long Time Trades ... +bool CloseAllLongTimeTrades( + const int passedCandles, + const ENUM_X_SIGNAL_PROVIDER provider = X_UNKNOWN_PROVIDER +) { + // + bool result = false; + + // + if (passedCandles <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + string comment = OrderComment(); + + // + ENUM_X_SIGNAL_PROVIDER orderProvider = GetSignalProvider(comment); + bool isProviderVerified = + provider == X_UNKNOWN_PROVIDER ? + true : + orderProvider != X_UNKNOWN_PROVIDER + && orderProvider == provider + ; + + // + if ( + profit < 0 + && isProviderVerified + && openBarIndex - currentBarIndex >= passedCandles + // || ( + // profit > 0.5 + // && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 3) + // ) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Long Time issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + // else if ( + // openTrades > 0 + // && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 2) + // ) { + // result = CloseAllInProfitTrades() + // && CloseBiggestDrawDownTrade(); + // } + } + } + } + + // + return result; +} + +// +// Close all trades which passed Maximum Drawdown ... +bool CloseAllMaximumDrawDownPassedTrades( + const double maxDrDownPercentPerPTrade, + const ENUM_X_SIGNAL_TYPE type = X_SIGNAL_NONE, + const ENUM_X_SIGNAL_PROVIDER provider = X_UNKNOWN_PROVIDER +) { + // + if ( + initialBalance <= 0 + || maxDrDownPercentPerPTrade <= 0 + ) { + return false; + } + + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double maxAllowedDrawDown = -1 * (initialBalance * maxDrDownPercentPerPTrade); + + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + string comment = OrderComment(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + bool isTypeVerified = + type == X_SIGNAL_NONE ? + true : + ( isLongOrder + && type == X_SIGNAL_LONG + ) || ( + !isLongOrder + && type == X_SIGNAL_SHORT + ) + ; + + // + ENUM_X_SIGNAL_PROVIDER orderProvider = GetSignalProvider(comment); + bool isProviderVerified = + provider == X_UNKNOWN_PROVIDER ? + true : + orderProvider != X_UNKNOWN_PROVIDER + && orderProvider == provider + ; + + // + if ( + profit < 0 + && isTypeVerified + && isProviderVerified + && MathAbs(profit) >= MathAbs(maxAllowedDrawDown) + ) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Maximum DarwDown issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Trades Which Opens before Specified Length ... +bool CloseAllTradesWhichOpenInPastMarketLength( + const int marketLen +) { + // + bool result = false; + + // + if (marketLen <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + + // + if (openBarIndex <= currentBarIndex + marketLen) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Market Reverse issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } else if (openTrades > 0) { + // + // Close all InProfit Trdes and Biggest InDrawDown Trades ... + // result = CloseAllInProfitTrades(); + // && CloseBiggestDrawDownTrade(); + } + } + } + } + + // + return result; +} +// +// END Close Orders ... +// + +// +// START Modify Orders ... +// +// +void ModifyAllPriceLesserOpenTrades( + const XSignal &signal +) { + // + // Loop through all Open Trades ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + double takeProfit = OrderTakeProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // When new Signal Comming with price less than + // currently open trade and tp less than currently + // open trade, this means a market change happens ... + // here we can Close InProfit Trades or Modify Trades TP ... + if ( + ( + openPrice < signal.entry + || MathAbs(openPrice - signal.entry) < 300 * _Point + ) + && takeProfit > signal.tp + ) { + bool result = OrderModify( + ticket, + openPrice, + signal.sl, + signal.tp, + clrYellow + ); + } + } + } + } +} + +// +void ModifyOpenTradesBasedOnCurrentTrade( + const XSignal &signal +) { + // + ModifyAllPriceLesserOpenTrades(signal); +} +// +// END Modify Orders ... +// +// +// END Orders Functions ... +// + +// +// START Signal Conditions ... +// +// +// Clear Signal Conditions ... +void ClearSignalConditions() { + // + ClearLongSignalConditions(); + ClearShortSignalConditions(); +} + +// +// Clear all Conditions Waiter for Long Signals ... +void ClearLongSignalConditions() { + // + ClearXLongSignalConditions(); + ClearXRLongSignalConditions(); + ClearXTPWLongSignalConditions(); +} + +// +// Clear all Conditions Waiter for Short Signals ... +void ClearShortSignalConditions() { + // + ClearXShortSignalConditions(); + ClearXTPWShortSignalConditions(); +} +// +// END Signal Conditions ... +// diff --git a/Bkp/Used/14020512/Libraries/x-saherelm.x.signal.lib.mq4 b/Bkp/Used/14020512/Libraries/x-saherelm.x.signal.lib.mq4 new file mode 100644 index 0000000..84a2e13 --- /dev/null +++ b/Bkp/Used/14020512/Libraries/x-saherelm.x.signal.lib.mq4 @@ -0,0 +1,1063 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 X Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Inputs ... +// +// +input string xStarter = "- X Signal Provider -"; // ---> X Signal Provider <--- + +// +input bool enableXSignalling = true; // X Signalling Enable + +// +input bool enableXLong = true; // X Signalling Enable Long +input bool enableXShort = true; // X Signalling Enable Short + +// +input double xShortR2R = 3; // X Short Risk To Reward Ratio +input double xShortLotsPerTradePercent = 0.00001; // X Lots Percent per Short Trades +input double xShortMaxDrawdownPerTradePercent = 0.02; // X Max Allowed DrawDown Percent per Short Trade + +// +input double xLongR2R = 3; // X Long Risk To Reward Ratio +input double xLongLotsPerTradePercent = 0.00001; // X Lots Percent per Short Trades +input double xLongMaxDrawdownPerTradePercent = 0.02; // X Max Allowed DrawDown Percent per Long Trade + +// +input double xSharpDetectorFactor = 700; // X Sharp Detection Factor + +// +input int xMaximumCandlesPerTrade = 206; // X Maximum Candles which a Trade can open + +// +input int xOscillatorLength = 7; // X Oscillator Length + +// +input double xPSarStep = 0.02; // X Parabolic Sar Step +input double xPSarMaximum = 0.2; // X Parabolic Sar Maximum + +// +input int xRangeMarketLength = 5; // X Range Detector Length + +// +input int xSwingLength = 7; // X Signal Swing Length +// +// END Inputs ... +// + +// +// START Global Requirement Functions ... +// +// +// X Based Signal Conditions ... +struct XSignalConditions { + datetime startTime; + datetime signalTime; + datetime entryTime; +}; + +// +struct XMarketState { + double psar; + double fast; + double slow; + double open; + double verifier; + double oscillator; + double oscillatorVerifier; +}; + +// +static XSignalConditions xLongConds; +static bool xCloseLongTrades = false; +static bool xWaitForLongSignals = true; + +// +static XSignalConditions xShortConds; +static bool xCloseShortTrades = false; +static bool xWaitForShortSignals = true; + +// +// Count Number of Closed Maximum DrawDown Trades ... +static int xFailedSignals = 0; + +// +datetime lastVerifierTouched; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckXSignalHandler( + const int bar_index +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + // + if ( + !enableXSignalling + || !(enableXLong || enableXShort) + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XOHCL candle = GetCandleModel(bar_index); + XOHCL pCandle = GetCandleModel(bar_index + 1); + XTPOWState tPowState = GetXTPowState( + bar_index + 1, + xSwingLength + ); + + // + XMarketState state = GetXMarketState( + bar_index + 1 + ); + + // + // Check Verifier Last Touched ... + bool isVerifierTouched = pCandle.high > state.verifier + && pCandle.low < state.verifier; + + // + // Disable Signals if a signal Failed ... + if (xFailedSignals) { + // + // TODO: Complete this ... + } + + // + // Enable Or Disable Signalling ... + if (isVerifierTouched) { + // + lastVerifierTouched = barTime; + + // + if (xWaitForLongSignals) { + xWaitForLongSignals = false; + } + + // + if (xWaitForShortSignals) { + xWaitForShortSignals = false; + } + } else { + // + int lastVerifierTouchedBarIndex = iBarShift( + _Symbol, + _Period, + lastVerifierTouched + ); + + // + int distance = MathAbs(lastVerifierTouchedBarIndex - bar_index); + + // + if ( + !xWaitForLongSignals + && distance > (xSwingLength * 2) + ) { + xWaitForLongSignals = true; + } + + // + if ( + !xWaitForShortSignals + && ( + distance > (xSwingLength * 2) + || ( + tPowState.powerDown > tPowState.powerUp + && tPowState.powerDown < 49 + ) + ) + ) { + xWaitForShortSignals = true; + } + } + + // + // Close All Long Open Trades ... + if ( + tPowState.powerDown > 55 + && tPowState.powerDown > tPowState.powerUp + ) { + // xCloseLongTrades = true; + } +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXLongSignalConditions( + const int bar_index +) { + // + if ( + !enableXLong + || !enableXSignalling + || !xWaitForLongSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + bool isCrossOver = false; + bool isCrossUnder = false; + + // + XMarketState cState = GetXMarketState(1); + XMarketState pState = GetXMarketState(2); + + // + isCrossUnder = + cState.fast < cState.slow + && !(pState.fast < pState.slow) + ; + + // + isCrossOver = + cState.fast > cState.slow + && !(pState.fast > pState.slow) + ; + + // + if ( + isCrossUnder + && xLongConds.startTime == 0 + ) { + // + xLongConds.startTime = barTime; + return; + } + + // + if ( + isCrossOver + && xLongConds.startTime > 0 + && xLongConds.signalTime == 0 + ) { + // + xLongConds.signalTime = barTime; + xLongConds.entryTime = barTime; + return; + } +} + +// +// Check and Fill Short Signal Conditions ... +void CheckXShortSignalConditions( + const int bar_index +) { + // + if ( + !enableXShort + || !enableXSignalling + || !xWaitForShortSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + bool isCrossOver = false; + bool isCrossUnder = false; + + // + XMarketState cState = GetXMarketState(1); + XMarketState pState = GetXMarketState(2); + + // + isCrossUnder = + cState.fast < cState.slow + && !(pState.fast < pState.slow) + ; + + // + isCrossOver = + cState.fast > cState.slow + && !(pState.fast > pState.slow) + ; + + // + if ( + isCrossOver + && xShortConds.startTime == 0 + ) { + // + xShortConds.startTime = barTime; + return; + } + + // + if ( + isCrossUnder + && xShortConds.startTime > 0 + && xShortConds.signalTime == 0 + ) { + // + xShortConds.signalTime = barTime; + xShortConds.entryTime = barTime; + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if ( + !enableXSignalling + || !(enableXLong || enableXShort) + ) { + return result; + } + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + if (requestLong) { + // + if ( + !ValidateXLongConditions() + ) { + return result; + } + } else { + // + if ( + !ValidateXShortConditions() + ) { + return result; + } + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double askPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double bidPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double entryPrice = requestLong ? + askPrice : + bidPrice; + + // + double exitPrice = requestLong ? + bidPrice : + askPrice; + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + // + GetMarketLowestLow( + bar_index, + xSwingLength + ) + ; + + // + double hh = + // + GetMarketHighestHigh( + bar_index, + xSwingLength + ) + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = requestLong ? + MathMin(openPrice, closePrice) - ll : + hh - MathMax(openPrice, closePrice) + ; + + // + double reward = + requestLong ? + risk * xLongR2R : + risk * xShortR2R + ; + + // + double sl = requestLong ? + 0 : + 0; + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward + ; + + // + XRState range = GetXRange( + bar_index, + xRangeMarketLength + ); + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XXX_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XXX_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXLongConditions() { + // + if ( + !enableXLong + || !enableXSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xLongConds.startTime > 0 + && xLongConds.signalTime > 0 + && xLongConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.signalTime + ); + + // + int entryBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.entryTime + ); + + // + isBLFilled = + // + xLongConds.signalTime > xLongConds.startTime + && xLongConds.entryTime >= xLongConds.signalTime + // && MathAbs(signalBarIndex - startBarIndex) >= 1 + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXLongSignalConditions(); + } + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXShortConditions() { + // + if ( + !enableXShort + || !enableXSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xShortConds.startTime > 0 + && xShortConds.signalTime > 0 + && xShortConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.signalTime + ); + + // + int entryBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.entryTime + ); + + // + isBLFilled = + // + xShortConds.signalTime > xShortConds.startTime + && xShortConds.entryTime >= xShortConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xWaitForShortSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXShortSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXLongSignalConditions() { + // + xLongConds.startTime = 0; + xLongConds.entryTime = 0; + xLongConds.signalTime = 0; +} + +// +// Clear Short Signal Conditions for New One ... +void ClearXShortSignalConditions() { + // + xShortConds.startTime = 0; + xShortConds.entryTime = 0; + xShortConds.signalTime = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForXSignals( + const XSignal &signal +) { + // + bool result = false; + + // + if ( + !enableXSignalling + || !(enableXLong || enableXShort) + ) { + return result; + } + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // XOHCL candle = GetCandleModel(0); + XOHCL candle = GetCandleModel(signalBarIndex); + XOHCL pCandle = GetCandleModel(signalBarIndex + 1); + + // + // Retrieve Range ... + XRState range = GetXRange( + signalBarIndex, + xRangeMarketLength + ); + + // + // Retrive XMarket States ... + XMarketState xState0 = GetXMarketState(signalBarIndex); + XMarketState xState1 = GetXMarketState(signalBarIndex + 1); + XMarketState xState2 = GetXMarketState(signalBarIndex + 2); + XMarketState xStateLast = GetXMarketState(signalBarIndex + xSwingLength); + + // + // Retrieve Trend Powers ... + XTPOWState xTPow0 = GetXTPowState( + signalBarIndex, + xSwingLength + ); + XTPOWState xTPow1 = GetXTPowState( + signalBarIndex + 1, + xSwingLength + ); + + // + double hh = GetMarketHighestHigh( + signalBarIndex, + xSwingLength + ); + double ll = GetMarketLowestLow( + signalBarIndex, + xSwingLength + ); + double diffChange = (hh - ll); + bool isBigSharpOccured = + diffChange > (xSharpDetectorFactor * _Point) + ; + + // + bool isPSarVerified = false; + bool isTPowVerified = false; + bool isStateVerified = false; + bool isPriceVerified = false; + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + // Get Price Verification for Long ... + isPriceVerified = + // + // Starter ... + true + // + && !isBigSharpOccured + // + && signal.entry < hh + // + // && signal.entry < range.hh + // && signal.entry > range.mid + // // + // && candle.high > xState0.verifier + // && signal.entry > xState0.verifier + // + // && pCandle.low != ll + && pCandle.high != hh + ; + + // + int above20TPowers = 0; + double signalSlope = 0; + int tPowUnverifyConditions = 0; + int tPowUnverifyConditionsIdx = 0; + for (int i = signalBarIndex; i < signalBarIndex + xSwingLength; i++) { + // + XTPOWState iTPowState = GetXTPowState( + i, + xSwingLength + ); + + // + // Calculate Signal Slope ... + if (i == signalBarIndex) { + // + signalSlope = iTPowState.signal; + } else if (i == signalBarIndex + 1) { + // + signalSlope = GetSlope( + 1, + iTPowState.signal, + 2, + signalSlope + ); + } + + // + if ( + iTPowState.powerUp > iTPowState.powerDown + && MathMax(iTPowState.powerUp, iTPowState.powerDown) > 20 + ) { + above20TPowers++; + } + + // + if (tPowUnverifyConditionsIdx < 3) { + // + if ( + iTPowState.powerUp < iTPowState.powerDown + || iTPowState.signal > MathMax(iTPowState.powerUp, iTPowState.powerDown) + ) { + tPowUnverifyConditions++; + } + + // + tPowUnverifyConditionsIdx++; + } + } + + // + isTPowVerified = + above20TPowers > 1 + && tPowUnverifyConditions == 0 + ; + + // + isPSarVerified = + xState0.psar < signal.entry + && xState0.psar < candle.low; + + // + isStateVerified = + // + // Start ... + true + // + // && xState0.open < xState0.slow + ; + + // + result = + // + // Starter ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + isPSarVerified = + xState0.psar > signal.entry + && xState0.psar > candle.high + ; + + // + // Get Price Verification for Short ... + isPriceVerified = + // + // Starter ... + true + // + && !isBigSharpOccured + // + && signal.entry > ll + && pCandle.low != ll + ; + + // + int above20TPowers = 0; + double signalSlope = 0; + int tPowUnverifyConditions = 0; + int tPowUnverifyConditionsIdx = 0; + for (int i = signalBarIndex; i < signalBarIndex + xSwingLength; i++) { + // + XTPOWState iTPowState = GetXTPowState( + i, + xSwingLength + ); + + // + // Calculate Signal Slope ... + if (i == signalBarIndex) { + // + signalSlope = iTPowState.signal; + } else if (i == signalBarIndex + 1) { + // + signalSlope = GetSlope( + 1, + iTPowState.signal, + 2, + signalSlope + ); + } + + // + if ( + iTPowState.powerUp > iTPowState.powerDown + && MathMax(iTPowState.powerUp, iTPowState.powerDown) > 20 + ) { + above20TPowers++; + } + + // + if (tPowUnverifyConditionsIdx < 3) { + // + if ( + iTPowState.powerUp > iTPowState.powerDown + || iTPowState.signal < MathMax(iTPowState.powerUp, iTPowState.powerDown) + ) { + tPowUnverifyConditions++; + } + + // + tPowUnverifyConditionsIdx++; + } + } + + // + isTPowVerified = + above20TPowers < 1 + && tPowUnverifyConditions == 0 + && MathAbs(xTPow0.powerUp - xTPow0.powerDown) > 50 * _Point + ; + + // + isStateVerified = + // + // Start ... + true + // + // && (xStateLast.verifier - xState0.verifier) >= 0 + // + && xState0.verifier > signal.entry + // + && MathAbs(signal.entry - xState0.verifier) < (xSharpDetectorFactor * _Point) + ; + + // + result = + // + // Starter Condition ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } + + // + return result; +} +// +// END Functions ... +// + +// +// START Data Provider ... +// +XMarketState GetXMarketState( + const int bar_index +) { + // + XMarketState result = {}; + + // + double fast = GetMA( + bar_index, + xSwingLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double open = GetMA( + bar_index, + xSwingLength, + 0, + MODE_SMA, + PRICE_OPEN + ); + + // + double slow = GetMA( + bar_index, + xSwingLength * 2, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double oscillator = GetMA( + bar_index, + xSwingLength, + 0, + MODE_EMA, + PRICE_CLOSE + ); + + // + double oscillatorVerifier = GetMA( + bar_index, + xSwingLength, + 0, + MODE_EMA, + PRICE_WEIGHTED + ); + + // + int dailyCount = GetDailyCandleCount(); + double verifier = GetMA( + bar_index, + dailyCount, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double psar = iSAR( + _Symbol, + _Period, + xPSarStep, + xPSarMaximum, + bar_index + ); + + // + result.psar = psar; + result.fast = fast; + result.open = open; + result.slow = slow; + result.verifier = verifier; + result.oscillator = oscillator; + result.oscillatorVerifier = oscillatorVerifier; + + // + return result; +} +// +// END Data Provider ... +// diff --git a/Bkp/Used/14020512/Libraries/x-saherelm.xr.signal.lib.mq4 b/Bkp/Used/14020512/Libraries/x-saherelm.xr.signal.lib.mq4 new file mode 100644 index 0000000..a74e094 --- /dev/null +++ b/Bkp/Used/14020512/Libraries/x-saherelm.xr.signal.lib.mq4 @@ -0,0 +1,695 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 X Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Inputs ... +// +// +input string xRStarter = "- XR Signal Provider -"; // --> XR Signal Provider <-- + +// +input bool enableXRSignalling = false; // XR Signalling Enable + +// +input bool enableXRLong = true; // XR Signalling Enable Long +input bool enableXRShort = true; // XR Signalling Enable Short + +// +input double xRShortR2R = 2; // XR Short Risk To Reward Ratio +input double xRShortLotsPerTradePercent = 0.00001; // XR Lots Percent per Short Trades +input double xRShortMaxDrawdownPerTradePercent = 0.01; // XR Max Allowed DrawDown Percent per Short Trade + +// +input double xRLongR2R = 2; // XR Long Risk To Reward Ratio +input double xRLongLotsPerTradePercent = 0.00001; // XR Lots Percent per Short Trades +input double xRLongMaxDrawdownPerTradePercent = 0.01; // XR Max Allowed DrawDown Percent per Long Trade + +// +input int xRMaximumCandlesPerTrade = 252; // XR Maximum Candles which a Trade can open + +// +input int xROscillatorLength = 7; // XR Oscillator Length +input int xRFastLength = 20; // XR Fast Length +input int xRSlowLength = 50; // XR Slow Length +input int xRRangeMarketLength = 50; // XR Range Detector Length + +// +input int xRSwingLength = 7; // XR Swing Length +// +// END Inputs ... +// + +// +// START Global Requirement Functions ... +// +// +// XR Market State ... +struct XRMarketState { + // + double fast; + double slow; + + // + double prevFast; + double prevSlow; + + // + double oscillator; + double prevOscillator; + + // + double verifier; +}; + +// +// XR Based Signal Conditions ... +struct XRSignalConditions { + // + datetime startTime; + datetime signalTime; + datetime entryTime; + + // + double value; + XRState state; +}; + +// +static XRSignalConditions xRLongConds; +static bool xRCloseLongTrades = false; +static bool xRWaitForLongSignals = true; + +// +static XRSignalConditions xRShortConds; +static bool xRCloseShortTrades = false; +static bool xRWaitForShortSignals = true; + +// +// Count Number of Closed Maximum DrawDown Trades ... +static int xRFailedSignals = 0; + +// +double xRMaximumDrawDown = 0; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckXRSignalHandler( + const int bar_index +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + + // + if ( + !enableXRSignalling + || !(enableXRLong || enableXRShort) + ) { + return; + } + + // + XOHCL candle = GetCandleModel(bar_index); + + // + XRMarketState state = GetXRMarketState( + bar_index + ); + + // + if (xRWaitForLongSignals) { + // + if ( + state.oscillator < state.fast + && state.oscillator < state.slow + && state.prevOscillator < state.prevFast + && state.prevOscillator < state.prevSlow + && candle.low < xRMaximumDrawDown + ) { + // + xRMaximumDrawDown = 0; + xRCloseLongTrades = true; + } + } else { + } +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXRLongSignalConditions( + const int bar_index +) { + // + if ( + !enableXRLong + || !enableXRSignalling + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XOHCL candle = GetCandleModel(bar_index + 1); + + // + XRState xrState = GetXRange( + bar_index, + xRRangeMarketLength + ); + + // + double affectedValue = xrState.mid; + + // + XRMarketState state = GetXRMarketState( + bar_index + ); + + // + bool isCrossOver = + state.fast > state.slow + && !(state.prevFast > state.prevSlow) + ; + + // + bool isCrossUnder = + state.fast < state.slow + && !(state.prevFast < state.prevSlow) + ; + + // + if ( + isCrossUnder + && xRLongConds.startTime == 0 + ) { + // + xRLongConds.startTime = barTime; + return; + } + + // + if ( + isCrossOver + && xRLongConds.startTime > 0 + && xRLongConds.signalTime == 0 + ) { + // + xRLongConds.value = affectedValue; + xRLongConds.state = xrState; + + // + xRLongConds.signalTime = barTime; + xRLongConds.entryTime = barTime; + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXRSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if ( + !enableXRSignalling + || !(enableXRLong || enableXRShort) + ) { + return result; + } + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + if (requestLong) { + // + if ( + !ValidateXRLongConditions() + ) { + return result; + } + } else { + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double askPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double bidPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double entryPrice = requestLong ? + askPrice : + bidPrice; + + // + double exitPrice = requestLong ? + bidPrice : + askPrice; + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + // + GetMarketLowestLow( + bar_index, + xRSwingLength + ) + ; + + // + double hh = + // + GetMarketHighestHigh( + bar_index, + xRSwingLength + ) + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = requestLong ? + MathMin(openPrice, closePrice) - ll : + hh - MathMax(openPrice, closePrice); + double reward = + requestLong ? + risk * xRLongR2R : + risk * xRShortR2R + ; + + // + double sl = requestLong ? + 0 : + ll; + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward + ; + + // + xRMaximumDrawDown = + xRMaximumDrawDown == 0 ? + xRLongConds.state.mid : + xRMaximumDrawDown > xRLongConds.state.mid ? + xRMaximumDrawDown : + xRLongConds.state.mid; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XR_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XR_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXRLongConditions() { + // + if ( + !enableXRLong + || !enableXRSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xRLongConds.startTime > 0 + && xRLongConds.signalTime > 0 + && xRLongConds.entryTime > 0 + // + && xRLongConds.value > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xRLongConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xRLongConds.signalTime + ); + + // + // Count Affected Value Touches ... + int cStartBarIndex = iBarShift( + _Symbol, + _Period, + xRLongConds.state.start + ); + + // + int cEndBarIndex = cStartBarIndex + xRLongConds.state.length; + + // + int highTouched = 0; + int valueTouched = 0; + for (int i = cStartBarIndex; i <= cStartBarIndex + cEndBarIndex; i++) { + // + XOHCL iCandle = GetCandleModel(i); + + // + if ( + iCandle.low < xRLongConds.value + && iCandle.high > xRLongConds.value + ) { + valueTouched++; + } + + // + if ( + iCandle.low < xRLongConds.state.hh + && iCandle.high > xRLongConds.state.hh + ) { + highTouched++; + } + } + + // + isBLFilled = + // + xRLongConds.signalTime > xRLongConds.startTime + && xRLongConds.entryTime >= xRLongConds.signalTime + // + && highTouched < 2 + && valueTouched > (cEndBarIndex - cStartBarIndex) / 6 + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xRWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXRLongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXRLongSignalConditions() { + // + xRLongConds.startTime = 0; + xRLongConds.signalTime = 0; + xRLongConds.entryTime = 0; + + // + xRLongConds.value = 0; + + // + XRState e = {}; + xRLongConds.state = e; +} + +// +// Check State for Long Signals ... +bool IsReadyForXRSignals( + const XSignal &signal +) { + // + bool result = false; + + // + if ( + !enableXRSignalling + || !(enableXRLong || enableXRShort) + ) { + return result; + } + + // + XRMarketState state = GetXRMarketState(0); + + // + double fSDif = MathAbs(state.fast - state.slow); + double fSDifP = MathAbs(state.prevFast - state.prevSlow); + + // + double emaSlope = GetSlope( + 1, + state.prevOscillator, + 2, + state.oscillator + ); + + // + XOHCL pCandle = GetCandleModel(1); + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + result = + // + // Starter ... + true + // + && state.oscillator > state.fast + && emaSlope > 0 + && signal.entry > state.verifier + // + && fSDif > fSDifP + // + && signal.entry < xRLongConds.state.hh + && signal.entry > xRLongConds.state.mid + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + result = + false + ; + } + + // + return result; +} +// +// END Functions ... +// + +// +// START Data Providers ... +// +// +XRMarketState GetXRMarketState( + const int bar_index +) { + // + XRMarketState result = {}; + + // + // Prepare Market Length ... + int xrVerifierMarketLength = GetDailyCandleCount(); + + // + // Calculate Fast and Prev Fast ... + // + // Fast ... + double fast = GetMA( + bar_index + 1, + xRFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + // Prev Fast ... + double prevFast = GetMA( + bar_index + 2, + xRFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + // Calculate Slow and Prev Slow ... + + // + // Slow ... + double slow = GetMA( + bar_index + 1, + xRSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + // Prev Slow ... + double prevSlow = GetMA( + bar_index + 2, + xRSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + // Calculate Oscillator and Prev Oscillator ... + + // + // Oscillator ... + double oscillator = GetMA( + bar_index, + xROscillatorLength, + 0, + MODE_EMA, + PRICE_CLOSE + ); + + // + // Prev Oscillator ... + double prevOscillator = GetMA( + bar_index + 1, + xROscillatorLength, + 0, + MODE_EMA, + PRICE_CLOSE + ); + + // + // Calculate Verifier ... + double verifier = GetMA( + bar_index, + xrVerifierMarketLength, + 0, + MODE_EMA, + PRICE_CLOSE + ); + + // + result.fast = fast; + result.slow = slow; + result.verifier = verifier; + result.prevFast = prevFast; + result.prevSlow = prevSlow; + result.oscillator = oscillator; + result.prevOscillator = prevOscillator; + + // + return result; +} +// +// END Data Providers ... +// \ No newline at end of file diff --git a/Bkp/Used/14020512/Libraries/x-saherelm.xtpw.signal.lib.mq4 b/Bkp/Used/14020512/Libraries/x-saherelm.xtpw.signal.lib.mq4 new file mode 100644 index 0000000..ff71849 --- /dev/null +++ b/Bkp/Used/14020512/Libraries/x-saherelm.xtpw.signal.lib.mq4 @@ -0,0 +1,1332 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 XTPW Signal Global Library +// --------------------------------------------------- +// XSaherElm EA Signal Provider based on +// XTPow Indicator... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Inputs ... +// +// +input string xTPWStarter = "- XTPW Signal Provider -"; // ---> XTPW Signal Provider <--- + +// +input bool enableXTPWSignalling = false; // XTPW Signalling Enable + +// +input bool enableXTPWLong = true; // XTPW Signalling Enable Long +input bool enableXTPWShort = true; // XTPW Signalling Enable Short + +// +input double xTPWShortR2R = 2; // XTPW Short Risk To Reward Ratio +input double xTPWShortLotsPerTradePercent = 0.00001; // XTPW Lots Percent per Short Trades +input double xTPWShortMaxDrawdownPerTradePercent = 0.015; // XTPW Max Allowed DrawDown Percent per Short Trade + +// +input double xTPWLongR2R = 2; // XTPW Long Risk To Reward Ratio +input double xTPWLongLotsPerTradePercent = 0.00001; // XTPW Lots Percent per Short Trades +input double xTPWLongMaxDrawdownPerTradePercent = 0.015; // XTPW Max Allowed DrawDown Percent per Long Trade + +// +input int xTPWMaximumCandlesPerTrade = 206; // XTPW Maximum Candles which a Trade can open + +// +input double xTPWPSarStep = 0.02; // XTPW Parabolic Sar Step +input double xTPWPSarMaximum = 0.2; // XTPW Parabolic Sar Maximum + +// +input int xTPWSwingLength = 7; // XTPW Signal Swing Length +// +// END Inputs ... +// + +// +input double xTPWSharpDetectionFactor = 650; // XTPW Sharp Detection Factor + +// +// START Global Requirement Functions ... +// +// +// XTPW Based Signal Conditions ... +struct XTPWSignalConditions { + datetime startTime; + datetime signalTime; + datetime entryTime; +}; + +// +struct XTPWMarketState { + // + double psar; + + // + double scFast; + double scSlow; + double scWeight; + + // + double mcFast; + double mcSlow; + double mcWeight; + + // + double lcFast; + double lcSlow; + double lcWeight; +}; + +// +struct XLHS { + // + double scHH; + double scLL; + + // + double mcHH; + double mcLL; + + // + double lcHH; + double lcLL; +}; + +// +static XTPWSignalConditions xTPWLongConds; +static bool xTPWCloseLongTrades = false; +static bool xTPWWaitForLongSignals = true; + +// +static XTPWSignalConditions xTPWShortConds; +static bool xTPWCloseShortTrades = false; +static bool xTPWWaitForShortSignals = true; + +// +// Count Number of Closed Maximum DrawDown Trades ... +static int xTPWFailedSignals = 0; + +// +double tPowerVerifier = 20; +double tPowerMaxVerifier = 55; + +// +int scFastLength = 0; +int scSlowLength = 0; + +// +int mcFastLength = 0; +int mcSlowLength = 0; + +// +int lcFastLength = 0; +int lcSlowLength = 0; + +// +datetime lastTurnOffLongTradesTime; +datetime lastTurnOffShortTradesTime; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckXTPWSignalHandler( + const int bar_index +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + + // + if ( + !enableXTPWSignalling + || !(enableXTPWLong || enableXTPWShort) + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 1); + + // + XTPOWState tPow0 = GetXTPowState( + bar_index, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xTPWSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xTPWSwingLength + ); + + // + XTPWMarketState state0 = GetXTPWMarketState( + bar_index + ); + XTPWMarketState state1 = GetXTPWMarketState( + bar_index + 1 + ); + XTPWMarketState state2 = GetXTPWMarketState( + bar_index + 2 + ); + + // // + // // Disable Long Conditions ... + // if ( + // xTPWWaitForLongSignals + // && + // ( + // isRangeCrossOverRangeWeight + // || + // isRangeCrossUnderRangeWeight + // || + // isTPowUpperAboveMaxVerifier + // ) + // ) { + // // + // xTPWWaitForLongSignals = false; + // lastTurnOffLongTradesTime = barTime; + // } + + // // + // // Enable Long Conditions ... + // if ( + // !xTPWWaitForLongSignals + // && lastTurnOffLongTradesTime > 0 + // && ( + // // isFastCrossOverSlow + // // || + // // isFastCrossUnderSlow + // isRangeCrossOverRangeWeight + // || + // isRangeCrossUnderRangeWeight + // || + // isTPowUpperBelowMaxVerifier + // ) + // ) { + // // + // // Find Last Turn Off Bar Index ... + // int lastTurnOffLongTradesBarIndex = iBarShift( + // _Symbol, + // _Period, + // lastTurnOffLongTradesTime + // ); + + // // + // // the Distance must be bigger than market length ... + // if (MathAbs(lastTurnOffLongTradesBarIndex - bar_index) > xTPWSwingLength) { + // // + // xTPWWaitForLongSignals = true; + // lastTurnOffLongTradesTime = 0; + // } + // } +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXTPWLongSignalConditions( + const int bar_index +) { + // + if ( + !enableXTPWLong + || !enableXTPWSignalling + || !xTPWWaitForLongSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Retrieve TPow States ... + XTPOWState tPow0 = GetXTPowState( + bar_index, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xTPWSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xTPWSwingLength + ); + + // + // Retrieve TPowMarket State ... + XTPWMarketState state0 = GetXTPWMarketState( + bar_index + ); + XTPWMarketState state1 = GetXTPWMarketState( + bar_index + 1 + ); + XTPWMarketState state2 = GetXTPWMarketState( + bar_index + 2 + ); + + // + // Retrieve XPrice Model ... + XPrice prices = GetPrice(); + + // + // Retrieve Candles ... + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + + // + XLHS lhs = GetXTPWLHS(bar_index); + + // + bool isHHSame = + lhs.scHH == lhs.mcHH + && lhs.mcHH == lhs.lcHH + ; + + // + bool isLLSame = + lhs.scLL == lhs.mcLL + && lhs.mcLL == lhs.lcLL + ; + + // + bool startCondition = false; + bool signalCondition = false; + bool entryCondition = false; + + // + bool longCondition1 = + // + true + // + && !isHHSame + // + && !( + lhs.scLL == lhs.mcLL + ) + // + && !( + lhs.scHH == lhs.mcHH + ) + // + && !( + prices.longEntry + && candle0.high < state0.scFast + && candle0.high < state0.scSlow + && candle0.high < state0.mcFast + && candle0.high < state0.mcSlow + && candle0.high < state0.lcFast + && candle0.high < state0.lcSlow + ) + // + && tPow0.powerDown > tPowerMaxVerifier + && tPow1.powerDown > tPowerMaxVerifier + && tPow0.powerDown < MathMax(tPow1.powerUp, tPow1.powerDown) + && MathMax(tPow1.powerUp, tPow1.powerDown) > tPowerMaxVerifier + ; + + // + // Start Conditions ... + startCondition = ( + longCondition1 + ) + ; + + // + if ( + startCondition + && xTPWLongConds.startTime == 0 + && xTPWLongConds.signalTime == 0 + && xTPWLongConds.entryTime == 0 + ) { + // + xTPWLongConds.startTime = barTime; + xTPWLongConds.signalTime = barTime; + xTPWLongConds.entryTime = barTime; + + // + return; + } +} + +// +// Check and Fill Short Signal Conditions ... +void CheckXTPWShortSignalConditions( + const int bar_index +) { + // + if ( + !enableXTPWShort + || !enableXTPWSignalling + || !xTPWWaitForShortSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Retrieve TPower State ... + XTPOWState tPow0 = GetXTPowState( + bar_index, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xTPWSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xTPWSwingLength + ); + + // + // Retrieve TPWMarket State ... + XTPWMarketState state0 = GetXTPWMarketState( + bar_index + ); + XTPWMarketState state1 = GetXTPWMarketState( + bar_index + 1 + ); + XTPWMarketState state2 = GetXTPWMarketState( + bar_index + 2 + ); + + // + // Retrieve Candles ... + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + + // + XPrice prices = GetPrice(); + XLHS lhs = GetXTPWLHS(bar_index); + + // + double sharpDetectionValue = + xTPWSharpDetectionFactor * _Point; + + // + bool isHHSame = + lhs.scHH == lhs.mcHH + && lhs.mcHH == lhs.lcHH + ; + + // + bool isLLSame = + lhs.scLL == lhs.mcLL + && lhs.mcLL == lhs.lcLL + ; + + // + bool startCondition = false; + bool signalCondition = false; + bool entryCondition = false; + + // + bool shortCondition1 = + // + true + // + && tPow1.powerDown > tPowerMaxVerifier + && tPow2.powerDown < tPowerMaxVerifier + ; + + // + startCondition = ( + shortCondition1 + ) + ; + + // + if ( + startCondition + && xTPWShortConds.startTime == 0 + && xTPWShortConds.signalTime == 0 + && xTPWShortConds.entryTime == 0 + ) { + // + xTPWShortConds.startTime = barTime; + xTPWShortConds.signalTime = barTime; + xTPWShortConds.entryTime = barTime; + + // + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXTPWSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if ( + !enableXTPWSignalling + || !(enableXTPWLong || enableXTPWShort) + ) { + return result; + } + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + // Check Condition Validations ... + if (requestLong) { + // + // Check Long Condtion is Valid, if Long Requested ... + if ( + !ValidateXTPWLongConditions() + ) { + return result; + } + } else { + // + // Check Short Condtion is Valid, if Short Requested ... + if ( + !ValidateXTPWShortConditions() + ) { + return result; + } + } + + // + double ll = + // + GetMarketLowestLow( + bar_index, + xTPWSwingLength + ) + ; + + // + double hh = + // + GetMarketHighestHigh( + bar_index, + xTPWSwingLength + ) + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + // Price Calculations ... + XPrice prices = GetPrice(); + + // + // Read State ... + XTPWMarketState state0 = GetXTPWMarketState(bar_index); + + // + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + XOHCL candle3 = GetCandleModel(bar_index + 2); + + // + double risk = requestLong ? + // + MathMin(openPrice, closePrice) - ll : + hh - MathMax(openPrice, closePrice) + ; + + // + double longR2R = xTPWLongR2R; + double shortR2R = xTPWShortR2R; + + // + double sharpDetectorValue = xTPWSharpDetectionFactor * _Point; + + // + if ( + risk > 0 + && requestLong + ) { + return result; + } + + // + // Define Entry Price ... + double entryPrice = requestLong + ? + prices.longEntry + : + prices.shortEntry + ; + + // + // Fix TP Detects for Short Signals ... + if (!requestLong) { + risk = 0; + } + + // + double reward = requestLong ? + risk * longR2R : + risk * shortR2R + ; + + // + if (risk == 0) { + // + // Calculate Reward ... + reward = requestLong + ? + MathAbs(hh - entryPrice) + : + MathAbs(hh - entryPrice) + ; + + // + // Detect Sharp Change Occured or not ... + bool isSharpOccured = reward > sharpDetectorValue + || MathAbs(reward - sharpDetectorValue) < (50 * _Point); + + // + // Change Rewards on Special Conditions ... + if ( + ( + requestLong + && isSharpOccured + && ( + state0.lcFast < state0.lcSlow + || ( + state0.mcFast > state0.mcSlow + && state0.mcWeight < state0.mcSlow + ) + ) + ) + ) { + reward = reward / 2; + } + + // + if (reward < 50 * _Point) { + reward = (50 * _Point) + prices.priceGap; + } + + // // + // if (!requestLong) { + // reward = reward * shortR2R; + // } + } + + // + double sl = requestLong ? + 0 : + 0; + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward + ; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XTPW_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XTPW_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXTPWLongConditions() { + // + if ( + !enableXTPWLong + || !enableXTPWSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xTPWLongConds.startTime > 0 + && xTPWLongConds.signalTime > 0 + && xTPWLongConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // // + // int startBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWLongConds.startTime + // ); + + // // + // int signalBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWLongConds.signalTime + // ); + + // // + // int entryBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWLongConds.entryTime + // ); + + // // + // int startSignalDiff = (signalBarIndex - startBarIndex); + // int entrySignalDiff = (entryBarIndex - signalBarIndex); + // int maxDiff = MathMax(startSignalDiff, entrySignalDiff); + + // + isBLFilled = + // + // Starter ... + true + // + && xTPWLongConds.signalTime >= xTPWLongConds.startTime + && xTPWLongConds.entryTime >= xTPWLongConds.signalTime + // + // && maxDiff < (xTPWSwingLength * 2) + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xTPWWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXTPWLongSignalConditions(); + } + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXTPWShortConditions() { + // + if ( + !enableXTPWShort + || !enableXTPWSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xTPWShortConds.startTime > 0 + && xTPWShortConds.signalTime > 0 + && xTPWShortConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // // + // int startBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWShortConds.startTime + // ); + + // // + // int signalBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWShortConds.signalTime + // ); + + // // + // int entryBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWShortConds.entryTime + // ); + + // + isBLFilled = + // + // Starter ... + true + // + && xTPWShortConds.signalTime >= xTPWShortConds.startTime + && xTPWShortConds.entryTime >= xTPWShortConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xTPWWaitForShortSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXTPWShortSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXTPWLongSignalConditions() { + // + xTPWLongConds.startTime = 0; + xTPWLongConds.entryTime = 0; + xTPWLongConds.signalTime = 0; +} + +// +// Clear Short Signal Conditions for New One ... +void ClearXTPWShortSignalConditions() { + // + xTPWShortConds.startTime = 0; + xTPWShortConds.entryTime = 0; + xTPWShortConds.signalTime = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForXTPWSignals( + const XSignal &signal +) { + // + bool result = false; + + // + if ( + !enableXTPWSignalling + || !(enableXTPWLong || enableXTPWShort) + ) { + return result; + } + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // XOHCL candle = GetCandleModel(0); + XOHCL candle0 = GetCandleModel(signalBarIndex); + XOHCL candle1 = GetCandleModel(signalBarIndex + 1); + + // + // Retrieve TPow State ... + XTPOWState tPow0 = GetXTPowState( + signalBarIndex, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + signalBarIndex + 1, + xTPWSwingLength + ); + + // + // Retrive XMarket States ... + XTPWMarketState state0 = GetXTPWMarketState(signalBarIndex); + XTPWMarketState state1 = GetXTPWMarketState(signalBarIndex + 1); + XTPWMarketState state2 = GetXTPWMarketState(signalBarIndex + 2); + + // + bool isPSarVerified = false; + bool isTPowVerified = false; + bool isStateVerified = false; + bool isPriceVerified = false; + + // + // Calculate Sharp Detection Value ... + double sharpDetectionValue = + xTPWSharpDetectionFactor * _Point; + + // + // Find State0 Min ... + double state0Min = MathMin(state0.scFast, state0.scSlow); + state0Min = MathMin(state0Min, state0.mcFast); + state0Min = MathMin(state0Min, state0.mcSlow); + state0Min = MathMin(state0Min, state0.lcFast); + state0Min = MathMin(state0Min, state0.lcSlow); + + // + // Find State0 Min ... + double state0Max = MathMax(state0.scFast, state0.scSlow); + state0Max = MathMax(state0Max, state0.mcFast); + state0Max = MathMax(state0Max, state0.mcSlow); + state0Max = MathMax(state0Max, state0.lcFast); + state0Max = MathMax(state0Max, state0.lcSlow); + + // + // Find Distance Between State0 Min and Max ... + double state0MinMaxDistance = MathAbs(state0Max - state0Min); + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + // Get Price Verification for Long ... + isPriceVerified = + // + // Starter ... + true + // + ; + + // + isTPowVerified = + // + // Starter ... + true + // + && tPow0.powerDown > tPowerMaxVerifier + && tPow1.powerDown > tPowerMaxVerifier + && tPow0.powerDown < MathMax(tPow1.powerUp, tPow1.powerDown) + && MathMax(tPow1.powerUp, tPow1.powerDown) > tPowerMaxVerifier + ; + + // + isPSarVerified = + // + // Starter ... + true + // + ; + + // + isStateVerified = + // + // Start ... + true + // + && state0.mcFast > state0.mcSlow + && state1.mcFast > state1.mcSlow + // + && !( + state0.lcFast > state0.mcSlow + && state0.lcFast < state0.mcFast + ) + // + && MathAbs(state1.mcFast - state1.mcSlow) > (50 * _Point) + ; + + // + result = + // + // Starter ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + isPSarVerified = + // + // Starter ... + true + ; + + // + // Get Price Verification for Short ... + isPriceVerified = + // + // Starter ... + true + ; + + // + isTPowVerified = + // + // Starter ... + true + // + && tPow0.signal > MathMax(tPow0.powerUp, tPow0.powerDown) + ; + + // + isStateVerified = + // + // Start ... + true + // + && ( + // + state0.scFast < state0.scSlow + && state0.mcFast < state0.mcSlow + && state0.lcFast < state0.lcSlow + ? + signal.entry > state0.scFast + : + // + // Find Minimum and Maximum Distance of State ... + state0MinMaxDistance > sharpDetectionValue + ? + signal.entry > state0Min + : + true + ) + // + && MathAbs(state0.mcFast - state0.mcSlow) > 50 * _Point + ; + + // + result = + // + // Starter Condition ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } + + // + return result; +} +// +// END Functions ... +// + +// +// START Data Provider ... +// +// +// Retrieve Market State ... +XTPWMarketState GetXTPWMarketState( + const int bar_index +) { + // + XTPWMarketState result = {}; + + // + int dayCount = GetDailyCandleCount(); + int halfDayCount = (int)(dayCount / 2); + + // + if (scFastLength == 0) { + scFastLength = xTPWSwingLength; + } + + // + if (scSlowLength == 0) { + scSlowLength = xTPWSwingLength * 2; + } + + // + if (mcFastLength == 0) { + mcFastLength = halfDayCount; + } + + // + if (mcSlowLength == 0) { + mcSlowLength = dayCount; + } + + // + if (lcFastLength == 0) { + lcFastLength = halfDayCount * 3; + } + + // + if (lcSlowLength == 0) { + lcSlowLength = dayCount * 3; + } + + // + double scFast = GetMA( + bar_index, + scFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double scSlow = GetMA( + bar_index, + scSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double scWeight = GetMA( + bar_index, + scSlowLength, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double mcFast = GetMA( + bar_index, + mcFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double mcSlow = GetMA( + bar_index, + mcSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double mcWeight = GetMA( + bar_index, + mcSlowLength, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double lcFast = GetMA( + bar_index, + lcFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double lcSlow = GetMA( + bar_index, + lcSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double lcWeight = GetMA( + bar_index, + lcSlowLength, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double psar = iSAR( + _Symbol, + _Period, + xTPWPSarStep, + xTPWPSarMaximum, + bar_index + ); + + // + result.psar = psar; + result.scFast = scFast; + result.scSlow = scSlow; + result.mcFast = mcFast; + result.mcSlow = mcSlow; + result.lcFast = lcFast; + result.lcSlow = lcSlow; + result.scWeight = scWeight; + result.mcWeight = mcWeight; + result.lcWeight = lcWeight; + + // + return result; +} + +// +// Retrieve Highest Highs and Lowest Lows in Cycles ... +XLHS GetXTPWLHS( + const int bar_index +) { + // + XLHS result = {}; + + // + // Retrieve LL and HH (s) ... + + // + // SC HH ... + double scHH = GetMarketHighestHigh( + bar_index, + scFastLength + ); + + // + // SC LL ... + double scLL = GetMarketHighestHigh( + bar_index, + scFastLength + ); + + // + // MC HH ... + double mcHH = GetMarketHighestHigh( + bar_index, + mcFastLength + ); + + // + // MC LL ... + double mcLL = GetMarketHighestHigh( + bar_index, + mcFastLength + ); + + // + // LC HH ... + double lcHH = GetMarketHighestHigh( + bar_index, + lcFastLength + ); + + // + // LC LL ... + double lcLL = GetMarketHighestHigh( + bar_index, + lcFastLength + ); + + // + result.scHH = scHH; + result.scLL = scLL; + result.mcHH = mcHH; + result.mcLL = mcLL; + result.lcHH = lcHH; + result.lcLL = lcLL; + + // + return result; +} +// +// END Data Provider ... +// diff --git a/Bkp/Used/14020512/x-saherelm.xr.signal.lib.mq4 b/Bkp/Used/14020512/x-saherelm.xr.signal.lib.mq4 new file mode 100644 index 0000000..a74e094 --- /dev/null +++ b/Bkp/Used/14020512/x-saherelm.xr.signal.lib.mq4 @@ -0,0 +1,695 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 X Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Inputs ... +// +// +input string xRStarter = "- XR Signal Provider -"; // --> XR Signal Provider <-- + +// +input bool enableXRSignalling = false; // XR Signalling Enable + +// +input bool enableXRLong = true; // XR Signalling Enable Long +input bool enableXRShort = true; // XR Signalling Enable Short + +// +input double xRShortR2R = 2; // XR Short Risk To Reward Ratio +input double xRShortLotsPerTradePercent = 0.00001; // XR Lots Percent per Short Trades +input double xRShortMaxDrawdownPerTradePercent = 0.01; // XR Max Allowed DrawDown Percent per Short Trade + +// +input double xRLongR2R = 2; // XR Long Risk To Reward Ratio +input double xRLongLotsPerTradePercent = 0.00001; // XR Lots Percent per Short Trades +input double xRLongMaxDrawdownPerTradePercent = 0.01; // XR Max Allowed DrawDown Percent per Long Trade + +// +input int xRMaximumCandlesPerTrade = 252; // XR Maximum Candles which a Trade can open + +// +input int xROscillatorLength = 7; // XR Oscillator Length +input int xRFastLength = 20; // XR Fast Length +input int xRSlowLength = 50; // XR Slow Length +input int xRRangeMarketLength = 50; // XR Range Detector Length + +// +input int xRSwingLength = 7; // XR Swing Length +// +// END Inputs ... +// + +// +// START Global Requirement Functions ... +// +// +// XR Market State ... +struct XRMarketState { + // + double fast; + double slow; + + // + double prevFast; + double prevSlow; + + // + double oscillator; + double prevOscillator; + + // + double verifier; +}; + +// +// XR Based Signal Conditions ... +struct XRSignalConditions { + // + datetime startTime; + datetime signalTime; + datetime entryTime; + + // + double value; + XRState state; +}; + +// +static XRSignalConditions xRLongConds; +static bool xRCloseLongTrades = false; +static bool xRWaitForLongSignals = true; + +// +static XRSignalConditions xRShortConds; +static bool xRCloseShortTrades = false; +static bool xRWaitForShortSignals = true; + +// +// Count Number of Closed Maximum DrawDown Trades ... +static int xRFailedSignals = 0; + +// +double xRMaximumDrawDown = 0; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckXRSignalHandler( + const int bar_index +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + + // + if ( + !enableXRSignalling + || !(enableXRLong || enableXRShort) + ) { + return; + } + + // + XOHCL candle = GetCandleModel(bar_index); + + // + XRMarketState state = GetXRMarketState( + bar_index + ); + + // + if (xRWaitForLongSignals) { + // + if ( + state.oscillator < state.fast + && state.oscillator < state.slow + && state.prevOscillator < state.prevFast + && state.prevOscillator < state.prevSlow + && candle.low < xRMaximumDrawDown + ) { + // + xRMaximumDrawDown = 0; + xRCloseLongTrades = true; + } + } else { + } +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXRLongSignalConditions( + const int bar_index +) { + // + if ( + !enableXRLong + || !enableXRSignalling + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XOHCL candle = GetCandleModel(bar_index + 1); + + // + XRState xrState = GetXRange( + bar_index, + xRRangeMarketLength + ); + + // + double affectedValue = xrState.mid; + + // + XRMarketState state = GetXRMarketState( + bar_index + ); + + // + bool isCrossOver = + state.fast > state.slow + && !(state.prevFast > state.prevSlow) + ; + + // + bool isCrossUnder = + state.fast < state.slow + && !(state.prevFast < state.prevSlow) + ; + + // + if ( + isCrossUnder + && xRLongConds.startTime == 0 + ) { + // + xRLongConds.startTime = barTime; + return; + } + + // + if ( + isCrossOver + && xRLongConds.startTime > 0 + && xRLongConds.signalTime == 0 + ) { + // + xRLongConds.value = affectedValue; + xRLongConds.state = xrState; + + // + xRLongConds.signalTime = barTime; + xRLongConds.entryTime = barTime; + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXRSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if ( + !enableXRSignalling + || !(enableXRLong || enableXRShort) + ) { + return result; + } + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + if (requestLong) { + // + if ( + !ValidateXRLongConditions() + ) { + return result; + } + } else { + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double askPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double bidPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double entryPrice = requestLong ? + askPrice : + bidPrice; + + // + double exitPrice = requestLong ? + bidPrice : + askPrice; + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + // + GetMarketLowestLow( + bar_index, + xRSwingLength + ) + ; + + // + double hh = + // + GetMarketHighestHigh( + bar_index, + xRSwingLength + ) + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = requestLong ? + MathMin(openPrice, closePrice) - ll : + hh - MathMax(openPrice, closePrice); + double reward = + requestLong ? + risk * xRLongR2R : + risk * xRShortR2R + ; + + // + double sl = requestLong ? + 0 : + ll; + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward + ; + + // + xRMaximumDrawDown = + xRMaximumDrawDown == 0 ? + xRLongConds.state.mid : + xRMaximumDrawDown > xRLongConds.state.mid ? + xRMaximumDrawDown : + xRLongConds.state.mid; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XR_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XR_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXRLongConditions() { + // + if ( + !enableXRLong + || !enableXRSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xRLongConds.startTime > 0 + && xRLongConds.signalTime > 0 + && xRLongConds.entryTime > 0 + // + && xRLongConds.value > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xRLongConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xRLongConds.signalTime + ); + + // + // Count Affected Value Touches ... + int cStartBarIndex = iBarShift( + _Symbol, + _Period, + xRLongConds.state.start + ); + + // + int cEndBarIndex = cStartBarIndex + xRLongConds.state.length; + + // + int highTouched = 0; + int valueTouched = 0; + for (int i = cStartBarIndex; i <= cStartBarIndex + cEndBarIndex; i++) { + // + XOHCL iCandle = GetCandleModel(i); + + // + if ( + iCandle.low < xRLongConds.value + && iCandle.high > xRLongConds.value + ) { + valueTouched++; + } + + // + if ( + iCandle.low < xRLongConds.state.hh + && iCandle.high > xRLongConds.state.hh + ) { + highTouched++; + } + } + + // + isBLFilled = + // + xRLongConds.signalTime > xRLongConds.startTime + && xRLongConds.entryTime >= xRLongConds.signalTime + // + && highTouched < 2 + && valueTouched > (cEndBarIndex - cStartBarIndex) / 6 + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xRWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXRLongSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXRLongSignalConditions() { + // + xRLongConds.startTime = 0; + xRLongConds.signalTime = 0; + xRLongConds.entryTime = 0; + + // + xRLongConds.value = 0; + + // + XRState e = {}; + xRLongConds.state = e; +} + +// +// Check State for Long Signals ... +bool IsReadyForXRSignals( + const XSignal &signal +) { + // + bool result = false; + + // + if ( + !enableXRSignalling + || !(enableXRLong || enableXRShort) + ) { + return result; + } + + // + XRMarketState state = GetXRMarketState(0); + + // + double fSDif = MathAbs(state.fast - state.slow); + double fSDifP = MathAbs(state.prevFast - state.prevSlow); + + // + double emaSlope = GetSlope( + 1, + state.prevOscillator, + 2, + state.oscillator + ); + + // + XOHCL pCandle = GetCandleModel(1); + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + result = + // + // Starter ... + true + // + && state.oscillator > state.fast + && emaSlope > 0 + && signal.entry > state.verifier + // + && fSDif > fSDifP + // + && signal.entry < xRLongConds.state.hh + && signal.entry > xRLongConds.state.mid + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + result = + false + ; + } + + // + return result; +} +// +// END Functions ... +// + +// +// START Data Providers ... +// +// +XRMarketState GetXRMarketState( + const int bar_index +) { + // + XRMarketState result = {}; + + // + // Prepare Market Length ... + int xrVerifierMarketLength = GetDailyCandleCount(); + + // + // Calculate Fast and Prev Fast ... + // + // Fast ... + double fast = GetMA( + bar_index + 1, + xRFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + // Prev Fast ... + double prevFast = GetMA( + bar_index + 2, + xRFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + // Calculate Slow and Prev Slow ... + + // + // Slow ... + double slow = GetMA( + bar_index + 1, + xRSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + // Prev Slow ... + double prevSlow = GetMA( + bar_index + 2, + xRSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + // Calculate Oscillator and Prev Oscillator ... + + // + // Oscillator ... + double oscillator = GetMA( + bar_index, + xROscillatorLength, + 0, + MODE_EMA, + PRICE_CLOSE + ); + + // + // Prev Oscillator ... + double prevOscillator = GetMA( + bar_index + 1, + xROscillatorLength, + 0, + MODE_EMA, + PRICE_CLOSE + ); + + // + // Calculate Verifier ... + double verifier = GetMA( + bar_index, + xrVerifierMarketLength, + 0, + MODE_EMA, + PRICE_CLOSE + ); + + // + result.fast = fast; + result.slow = slow; + result.verifier = verifier; + result.prevFast = prevFast; + result.prevSlow = prevSlow; + result.oscillator = oscillator; + result.prevOscillator = prevOscillator; + + // + return result; +} +// +// END Data Providers ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020410/Experts/x-saherelm.osc.ea.mq4 b/Bkp/Used/OSC EA 14020410/Experts/x-saherelm.osc.ea.mq4 new file mode 100644 index 0000000..409a38d --- /dev/null +++ b/Bkp/Used/OSC EA 14020410/Experts/x-saherelm.osc.ea.mq4 @@ -0,0 +1,884 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XST_OSC Strategy Expert Advisor +// --------------------------------------------- +// saherelm implementation of strategy expert advisor ... +// +// ShortName: XST_OSC +// +// 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 XST_OSC Strategy Expert Advisor" +#property strict + +// +// START Inputs ... +// +// +// Signal Prefixe ... +input string signalPrefix = "XST_OSC"; // Signal Prefix + +// +// Signal Draw Specifications ... +input string bullishSignalLabel = "X_BUY"; // Bullish Signal Label +input color bullishSignalColor = clrAqua; // Bullish Signal Color + +// +input string bearishSignalLabel = "X_SELL"; // Bearish Signal Label +input color bearishSignalColor = clrFuchsia; // Bearish Signal Color + +// +input color signalEntryColor = clrAquamarine; // Signal Entry Ptice Color +input color signalSLColor = clrRed; // Signal SL Color +input color signalTPColor = clrGreen; // Signal TP Color + +// +// Trade ... +input bool allowTrade = true; // Allow Trade Based on given Signals +input bool allowLongTrades = true; // Allow Long Trades +input bool allowShortTrades = false; // Allow Short Trades + +// +// Market Specification Inpouts ... +input int marketLength = 7; // Market Length +input double riskToRewardRatio = 2; // Risk to Reward Ratio + +// +// Alerts ... +input bool alertEvents = true; // Alert Events +input bool alertPositions = true; // Alert Positions +input bool longPositionAlerts = true; // Alert Long Positions +input bool shortPositionAlerts = true; // Alert Short Positions + +// +// Alert Types ... +input bool terminalAlert = false; // Terminal Alert +input bool pushAlert = false; // Push Notification Alerts + +// +// Balance and Finanical Specifications ... +input double lotsPerTradePercent = 0.00001; // Lots Per Trade Percent +input int maxOpenTrades = 4; // Maximum Open Trade +input double maxDrawdownPercentPerPTrade = 0.1; // Maximum DrawDown Per Trade +input double minBalancePercent = 0.5; // Minimum Balance for Trading +input double maxEquityPercent = 0.1; // Maximum Trade Equity +input int closeAllOpenTradesAfterCandle = 480; // Close All Open Trades After Passed Candles + +// +// OSC Inputs ... +// +// FastOSC ... +// Short Cycle (Fast OSC) ... +input int fastOSCLength = 10; // FastOSC Length +input double fastOSCMultiplier = 1.0; // FastOSC Multiplier + +// +// SlowOSC ... +// Medium Cycle (Slow OSC) ... +input int slowOSCLength = 30; // SlowOSC Length +input double slowOSCMultiplier = 3.0; // SlowOSC Multiplier + +// +// Power OSC ... +input double minPowerOSC = 0.055; // Minimum Signal Power + +// +// Variance OSC ... +input double minVarianceOSC = 0; // Minimum Var Power + +// +// ZIGZAG Inputs ... +input int zDeviation = 5; // ZigZag Deviation +input int zBackStep = 3; // ZigZag Back Step + +// +// XMA Inputs ... +// +input int shortCycleFastMultiplier = 1; // Short Cycle Fast Multiplier +input int shortCycleSlowMultiplier = 4; // Short Cycle Slow Multiplier +input int mediumCycleFastMultiplier = 7; // Medium Cycle Fast Multiplier +input int mediumCycleSlowMultiplier = 14; // Medium Cycle Slow Multiplier +input int longCycleFastMultiplier = 70; // Long Cycle Fast Multiplier +input int longCycleSlowMultiplier = 140; // Long Cycle Slow Multiplier +// +// Show/Hide Inputs ... +input bool showShortCycle = false; // Show Short Cycle +input bool showShortCycleCrossLines = false; // Show Short Cycle Vertical Lines +input bool showMediumCycle = false; // Show Medium Cycle +input bool showMediumCycleCrossLines = false; // Show Medium Cycle Vertical Lines +input bool showLongCycle = false; // Show Long Cycle +input bool showLongCycleCrossLines = false; // Show Long Cycle Vertical Lines +// +// Color Inputs ... +input color shortCycleFastColor = clrGreen; // Short Cycle Fast Color ... +input color shortCycleSlowColor = clrRed; // Short Cycle Slow Color ... +input color mediumCycleFastColor = clrAqua; // Medium Cycle Fast Color ... +input color mediumCycleSlowColor = clrFuchsia; // Medium Cycle Slow Color ... +input color longCycleFastColor = clrGoldenrod; // Medium Cycle Fast Color ... +input color longCycleSlowColor = clrBrown; // Medium Cycle Slow Color ... +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +int lastSignalledBar = 0; + +// +bool waitForLongSignals = true; +bool closeLongTrades = false; + +// +bool waitForShortSignals = true; +bool closeShortTrades = false; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.osc.signal.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Validate Inputs ... + bool inputsNotValiid = + // + // MARKET ... + marketLength < 0 + || riskToRewardRatio < 0 + // + // EA ... + || lotsPerTradePercent < 0 + || maxOpenTrades <= 0 + || maxDrawdownPercentPerPTrade < 0 + || minBalancePercent < 0 + || maxEquityPercent < 0 + || marketLength < 0 + // + // OSC ... + || fastOSCLength < 0 + || fastOSCMultiplier < 0 + || slowOSCLength < 0 + || slowOSCMultiplier < 0 + || minPowerOSC < 0 + || minVarianceOSC < 0 + || slowOSCLength <= fastOSCLength + // + // ZIGZAG ... + || zDeviation < 0 + || zBackStep < 0 + || zBackStep >= marketLength + // + // XMA ... + // + // Validate Short Cycle ... + || shortCycleFastMultiplier <= 0 + || shortCycleSlowMultiplier <= 0 + || shortCycleFastMultiplier >= shortCycleSlowMultiplier + // + // Validate Medium Cycle ... + || mediumCycleFastMultiplier <= 0 + || mediumCycleSlowMultiplier <= 0 + || mediumCycleFastMultiplier >= mediumCycleSlowMultiplier + // + // Validate Long Cycle ... + || longCycleFastMultiplier <= 0 + || longCycleSlowMultiplier <= 0 + || longCycleFastMultiplier >= longCycleSlowMultiplier + // + // Validate Series of Multipliers ... + || shortCycleFastMultiplier >= mediumCycleFastMultiplier + || mediumCycleFastMultiplier >= longCycleFastMultiplier + ; + + if (inputsNotValiid) { + return INIT_PARAMETERS_INCORRECT; + } + + // + totalSignals = 0; + totalLongSignals = 0; + totalShortSignals = 0; + + // + initialBalance = 0; + + // + // START Define Array Series ... + // + // + // END Define Array Series ... + // + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST_OSC"; + + // // + // // Set Event Timer on One Seccond ... + // bool isEventSet = EventSetTimer(1); + // if (!isEventSet) { + // LogMessage("Error: " + GetLastError()); + // return INIT_FAILED; + // } + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + // Killing Event Timer ... + EventKillTimer(); +} + +// +// Ticker Event Handler ... +void OnTick() { + // + // Checking State for Signal Handling ... + CheckState(); + + // + // Process Signals to Open Positions ... + ProcessSignals(); + + // + // Process Open Positions for Trailing Stop Loss or Close ... + ProcessOpenPositions(); +} + +// +// Timer Event Handler ... +void OnTimer() { + // + CheckState(); + + // + ProcessOpenPositions(); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Check State for Signal Handling ... +void CheckState() { + // + // Here we Must to Check Market State in Big Picture ... + + // + int maShift = 0; + int fastMaLength = 10; + int slowMaLength = 50; + ENUM_MA_METHOD maMethod = MODE_SMA; + ENUM_APPLIED_PRICE maAppliedPrice = PRICE_CLOSE; + + // + double fastMa = iMA( + _Symbol, + _Period, + fastMaLength, + maShift, + maMethod, + maAppliedPrice, + 0 // Bar Index ... + ); + double fastMaPrev = iMA( + _Symbol, + _Period, + fastMaLength, + maShift, + maMethod, + maAppliedPrice, + 1 // Bar Index ... + ); + double fastMaPrevPrev = iMA( + _Symbol, + _Period, + fastMaLength, + maShift, + maMethod, + maAppliedPrice, + 2 // Bar Index ... + ); + + // + double slowMa = iMA( + _Symbol, + _Period, + slowMaLength, + maShift, + maMethod, + maAppliedPrice, + 0 // Bar Index ... + ); + double slowMaPrev = iMA( + _Symbol, + _Period, + slowMaLength, + maShift, + maMethod, + maAppliedPrice, + 1 // Bar Index ... + ); + double slowMaPrevPrev = iMA( + _Symbol, + _Period, + slowMaLength, + maShift, + maMethod, + maAppliedPrice, + 2 // Bar Index ... + ); + + // + bool isFastMACrossOverSlowMa = fastMa > slowMa + && !(fastMaPrev > slowMaPrev) + && !(fastMaPrevPrev > slowMaPrevPrev); + + // + bool isFastMACrossUnderSlowMa = fastMa < slowMa + && !(fastMaPrev < slowMaPrev) + && !(fastMaPrevPrev < slowMaPrevPrev); + + // + bool isSCFastCrossUnderSlow = xmaState.scFast < xmaState.scSlow + && !(xmaState.scFastPrev < xmaState.scSlowPrev); + + // + bool isMCFastCrossUnderSlow = xmaState.mcFast < xmaState.mcSlow + && !(xmaState.mcFastPrev < xmaState.mcSlowPrev); + + // + bool isLCFastCrossUnderSlow = xmaState.lcFast < xmaState.lcSlow + && !(xmaState.lcFastPrev < xmaState.lcSlowPrev); + + // + bool isSharpBullishHappens = IsSharpBullishHappens( + 0, // Bar Index ... + marketLength // Market Length ... + ); + + // + bool isSharpBearishHappens = IsSharpBullishHappens( + 0, // Bar Index ... + marketLength // Market Length ... + ); + + // + // TODO: Determines Where and How close Long Trades on Trend Reversal Points ... + closeLongTrades = + false + // ( + // isSCFastCrossUnderSlow + // && isMCFastCrossUnderSlow + // ) + // || + // ( + // isSCFastCrossUnderSlow + // && isLCFastCrossUnderSlow + // ) + // || + // ( + // isMCFastCrossUnderSlow + // && isLCFastCrossUnderSlow + // ) + // || + // IsSharpBearishHappens( + // 0, + // marketLength + // ) + ; + + // + waitForLongSignals = + true; + // waitForLongSignals + // ? + // true + // && !isSharpBullishHappens + // // && !adxState.trendPower > 50 + // // && adxState.trendPower < 20 + // : + // ( + // ( + // xmaState.lcFast > xmaState.lcSlow + // && !(xmaState.lcFastPrev > xmaState.lcSlowPrev) + // ) + // || + // ( + // xmaState.mcFast > xmaState.mcSlow + // && !(xmaState.mcFastPrev > xmaState.mcSlowPrev) + // ) + // || + // isSharpBearishHappens + // ) + // ; +} + +// +// Calculate Signals and Process Based on Exists Signals ... +void ProcessSignals() { + // + XSignalRequest request = {}; + request.type = X_NONE; + request.hasSignal = false; + + // + // Prevent Multiple Calculating on Same Bars ... + isNewBar = IsNewBar(); + if (isNewBar) { + // + countedBars++; + + // // + // LogMessage( + // StringConcatenate( + // "Check Signals, Bars: ", + // countedBars + // ) + // ); + + // + // Retrieve Signal Exists ... + // request = CalculateSignal( + // // + // // Bar Index ... + // 0, + // // + // // Market Specification Inpouts ... + // marketLength, // Market Length ... + // // + // // Risk To Reward Ratio ... + // riskToRewardRatio, + // // + // // XMA Inputs ... + // shortCycleFastMultiplier, // Short Cycle Fast Multiplier ... + // shortCycleSlowMultiplier, // Short Cycle Slow Multiplier ... + // mediumCycleFastMultiplier, // Medium Cycle Fast Multiplier ... + // mediumCycleSlowMultiplier, // Medium Cycle Slow Multiplier ... + // longCycleFastMultiplier, // Long Cycle Fast Multiplier ... + // longCycleSlowMultiplier, // Long Cycle Slow Multiplier ... + // // + // // Show/Hide Inputs ... + // showShortCycle, + // showShortCycleCrossLines, + // showMediumCycle, + // showMediumCycleCrossLines, + // showLongCycle, + // showLongCycleCrossLines, + // // + // // Color Inputs ... + // shortCycleFastColor, + // shortCycleSlowColor, + // mediumCycleFastColor, + // mediumCycleSlowColor, + // longCycleFastColor, + // longCycleSlowColor, + // // + // // OSC ... + // fastOSCLength, // FastOSC Length ... + // fastOSCMultiplier, // FastOSC Multiplier ... + // slowOSCLength, // SlowOSC Length ... + // slowOSCMultiplier, // SlowOSC Multiplier ... + // minPowerOSC, // Minimum Signal Power ... + // minVarianceOSC, // Minimum Var Power ... + // // + // // ZIGZAG Inputs ... + // zDeviation, // ZigZag Deviation ... + // zBackStep // ZigZag Back Step ... + // ); + } + + // + bool allowDoTrade = true; + + // + // Check Balance ... + if (initialBalance > 0) { + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double minimumBalanceForTrade = + balance > initialBalance + ? + minBalancePercent * balance + : + minBalancePercent * initialBalance; + + // + // Retrieve Account Equity ... + double equity = AccountInfoDouble(ACCOUNT_EQUITY); + double maxAllowedEquity = balance - (balance * maxEquityPercent); + + // + // Retrieve Free Marigin ... + double freeMargin = AccountFreeMargin(); + double maximumMariginRisk = balance - (balance * maxEquityPercent); + + // + if ( + // + // Do not Open Positions if equity not passed ... + equity < maxAllowedEquity || + // + // Do not Open Positions if free margin not passed ... + freeMargin <= maximumMariginRisk || + // + // Do not open positions if balance less than minimum ... + balance <= minimumBalanceForTrade + ) { + // + allowDoTrade = false; + + // // + // string message = StringConcatenate( + // "Trading Pause => ", + // "Balance: ", balance, + // ", Equity: ", equity, + // ", FreeMargin: ", freeMargin + // ); + + // // + // LogMessage(message); + // SendAlert(message); + + // + // Close In Profit Trades ... + // then Recheck Signal ... + // bool hasInProfitTradeClosed = CloseAllInProfitTrades(); + // if (hasInProfitTradeClosed) { + // ProcessSignals(); + // } + } + } + + // + // Retrieve Signal Exists ... + request = CalculateSignal( + // + // Bar Index ... + 0, + // + // Market Specification Inpouts ... + marketLength, // Market Length ... + // + // Risk To Reward Ratio ... + riskToRewardRatio, + // + // XMA Inputs ... + shortCycleFastMultiplier, // Short Cycle Fast Multiplier ... + shortCycleSlowMultiplier, // Short Cycle Slow Multiplier ... + mediumCycleFastMultiplier, // Medium Cycle Fast Multiplier ... + mediumCycleSlowMultiplier, // Medium Cycle Slow Multiplier ... + longCycleFastMultiplier, // Long Cycle Fast Multiplier ... + longCycleSlowMultiplier, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showShortCycle, + showShortCycleCrossLines, + showMediumCycle, + showMediumCycleCrossLines, + showLongCycle, + showLongCycleCrossLines, + // + // Color Inputs ... + shortCycleFastColor, + shortCycleSlowColor, + mediumCycleFastColor, + mediumCycleSlowColor, + longCycleFastColor, + longCycleSlowColor, + // + // OSC ... + fastOSCLength, // FastOSC Length ... + fastOSCMultiplier, // FastOSC Multiplier ... + slowOSCLength, // SlowOSC Length ... + slowOSCMultiplier, // SlowOSC Multiplier ... + minPowerOSC, // Minimum Signal Power ... + minVarianceOSC, // Minimum Var Power ... + // + // ZIGZAG Inputs ... + zDeviation, // ZigZag Deviation ... + zBackStep // ZigZag Back Step ... + ); + + // + // Prevent doing anything else, if there is no signals ... + if ( + !allowDoTrade || + !request.hasSignal || + request.type == X_NONE + ) { + return; + } + + // + bool hasLongSignal = request.type == X_LONG; + + // + // Check For Bot State ... + if ( + (hasLongSignal && !waitForLongSignals) + || (!hasLongSignal && !waitForShortSignals) + ) { + return; + } + + // + // Check last Signalled Bar with Counted Bars ... + // Prevent Multiple Signalling on Same Bar ... + if (lastSignalledBar == countedBars) { + // + totalSignals--; + if (hasLongSignal) { + totalLongSignals--; + } else { + totalShortSignals--; + } + return; + } + + // + // Prevent Signals if openTrades on last Market ... + // this means for each trades at least we have to wait market length passed from last signal ... + // if (lastSignalledBar + (marketLength) > countedBars) { + // return; + // } + + // + // increase last signalled bar ... + lastSignalledBar = countedBars; + + // + // Calculate Can Trade or not ... + allowDoTrade = allowTrade + && ( + hasLongSignal ? + allowLongTrades : + allowShortTrades + ); + + // + // Chack Maximum Open Positions ... + int openTrades = CountOpenTrades(); + if (maxOpenTrades > 0) { + // + if (openTrades >= maxOpenTrades) { + // + allowDoTrade = false; + + // + string message = StringConcatenate( + "Trading Pause => ", + "Max Open Trades (", + maxOpenTrades, + ") reached ..." + ); + + // + LogMessage(message); + SendAlert(message); + } + } + + // + // Check Trading is Enable or not ... + // nothing to do if trading is disabled ... + if (!allowDoTrade) { + // // + // string message = StringConcatenate( + // "Trading Not Allowed ..." + // ); + + // // + // LogMessage(message); + // SendAlert(message); + return; + } + + // + bool isPositionOpened = TradeSignal( + request.signal, + signalPrefix, + lotsPerTradePercent, + bullishSignalLabel, + bullishSignalColor, + bearishSignalLabel, + bearishSignalColor + ); + + // + if (isPositionOpened) { + // + bool canAlert = + alertPositions + && ( + hasLongSignal ? + longPositionAlerts + : + shortPositionAlerts + ); + + // + if (canAlert) { + // + // Alert Message ... + string message = StringConcatenate( + "Trade on Signal ID: ", request.signal.id, + ", Entry: ", request.signal.entryPrice, + ", TP: ", request.signal.tp + ); + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } + } + } +} + +// +// Process All Open Positions ... +void ProcessOpenPositions() { + // + // TODO: + // - Order 5 Long Time; + // - Order 8 Long Time; + // - Order 13 Long Time; + // - lcTrendDown; + // - mcTrendUp; + // - scTrendDown; + // - marketMiddleage < mcSlow; + // - longEntryPrice > lcSlow; + // - scTrendPowerUp; + // - Order 14 All Long Trades; + // - lcMarket TrendUp; + // - mcMarket TrendUp; + // - + // - Order 16 Long Time; + // - Ordrr 17 Long Time; + // - Ordrr 22 Long Time; + // - Ordrr 26 Long Time; + // - Ordrr 32 All Long Trades; + // - Ordrr 40 Long Time; + // - Ordrr 41 Long Time; + // - Ordrr 52 Long Time; + // - Ordrr 66 Long Time; + // - Ordrr 73 Long Time; + // - Ordrr 74 All Long Trades; + // - Ordrr 78 Long Time; + // - Ordrr 78 Long Time; + // - Ordrr 87 All Long Trades; + // - Ordrr 95 Long Time; + // - Ordrr 97 Long Time; + // - Ordrr 106 Long Time; + // - Ordrr 107 All Long Trades; + // - Ordrr 109 Long Time; + // - Ordrr 111 Long Time; + + // + if (closeLongTrades) { + // + closeLongTrades = false; + + // + bool isAllLongTradesClosed = CloseAllLongTrades(); + if (isAllLongTradesClosed) { + waitForLongSignals = false; + } + } + + // + if (closeShortTrades) { + // + closeShortTrades = false; + + // + bool isAllShortTradesClosed = CloseAllShortTrades(); + if (isAllShortTradesClosed) { + waitForShortSignals = false; + } + } + + // + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + closeAllOpenTradesAfterCandle + ); + + // + // Close Maximum DrawDown Passed Trades ... + bool hasClosedInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + maxDrawdownPercentPerPTrade + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedInDrawDownLongTrade + ) { + // + waitForLongSignals = false; + waitForShortSignals = false; + } +} + +// +// Send Special Type of Alerts ... +void SendAlert(string message) { + // // + // if (!alertEvents) { + // return; + // } + + // // + // // Terminal Alert ... + // if (terminalAlert) { + // Alert(message); + // } + + // // + // // Push Alert ... + // if (pushAlert) { + // SendNotification(message); + // } +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.adx.mq4 b/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.adx.mq4 new file mode 100644 index 0000000..3271a4e --- /dev/null +++ b/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.adx.mq4 @@ -0,0 +1,220 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center ADX Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm ADX Oscillator" +#property strict + +// +// START Inputs ... +// +input int length = 7; // Averaging Length +input ENUM_APPLIED_PRICE appliedPrice = PRICE_WEIGHTED; // Averaging Applied Price +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_separate_window + +// +#property indicator_minimum 0 +#property indicator_maximum 100 + +// +#property indicator_buffers 3 + +// +#property indicator_level1 0.0 +#property indicator_level2 50.0 +#property indicator_level3 70.0 +#property indicator_level4 100.0 +#property indicator_levelcolor clrSilver +#property indicator_levelstyle STYLE_DOT + +// +// ADX ... +#property indicator_width1 1 +#property indicator_color1 clrLightBlue +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_SOLID + +// +// Positive Direction ... +#property indicator_width2 1 +#property indicator_color2 clrLime +#property indicator_type2 DRAW_LINE +#property indicator_style2 STYLE_DOT + +// +// Negative Direction ... +#property indicator_width3 1 +#property indicator_color3 clrRed +#property indicator_type3 DRAW_LINE +#property indicator_style3 STYLE_DOT + +// +// Declare Buffers ... +#define adxBufferIndex 0 +#define positiveBufferIndex 1 +#define negativeBufferIndex 2 + +double adxBuffer[]; +double positiveBuffer[]; +double negativeBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (length < 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + IndicatorBuffers(3); + + // + SetIndexBuffer(positiveBufferIndex, positiveBuffer); + SetIndexLabel(positiveBufferIndex, "DI+"); + + // + SetIndexBuffer(negativeBufferIndex, negativeBuffer); + SetIndexLabel(negativeBufferIndex, "DI-"); + + // + SetIndexBuffer(adxBufferIndex, adxBuffer); + SetIndexLabel(adxBufferIndex, "ADX"); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, length); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Long TP ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index +) { + // + // Calculate Buffers ... + + // + // Retrieves the current ADX value ... + double adx = iADX( + _Symbol, + _Period, + length, + appliedPrice, + MODE_MAIN, + bar_index + ); + adxBuffer[bar_index] = adx; + + // + // Retrieves the current DI+ value ... + double plusDi = iADX( + _Symbol, + _Period, + length, + appliedPrice, + MODE_PLUSDI, + bar_index + ); + positiveBuffer[bar_index] = plusDi; + + // + // Retrieves the current DI- value ... + double minusDi = iADX( + _Symbol, + _Period, + length, + appliedPrice, + MODE_MINUSDI, + bar_index + ); + negativeBuffer[bar_index] = minusDi; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.ma.mq4 b/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.ma.mq4 new file mode 100644 index 0000000..e3a5737 --- /dev/null +++ b/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.ma.mq4 @@ -0,0 +1,173 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MA Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 MA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Fast MA ... +input int maLength = 20; // MA Length +input int maShift = 0; // MA Shift +input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method +input ENUM_APPLIED_PRICE maAppliedPrice = PRICE_CLOSE; // MA Applied Price + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 1 + +// +#property indicator_plots 1 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Fast Ma Buffer ... +#property indicator_label1 "Ma" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrYellow +#property indicator_style1 STYLE_DOT +#property indicator_width1 2 + +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define maBufferIndex 0 + +double maBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (maLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + // + // Ma ... + SetIndexBuffer(maBufferIndex, maBuffer); + SetIndexDrawBegin(maBufferIndex, maLength + 1); + // + // End Set Index Buffers ... + // + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, maLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Ma ... + CalculateMa(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateMa( + const int &bar_index +) { + // + // Calculating Fast Ma ... + double ma = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + maAppliedPrice, + bar_index + ); + + // + maBuffer[bar_index] = ma; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.momentum.mq4 b/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.momentum.mq4 new file mode 100644 index 0000000..ea6e419 --- /dev/null +++ b/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.momentum.mq4 @@ -0,0 +1,160 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center Momentum Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm Momentum Oscillator" +#property strict + +// +// START Inputs ... +// +input int length = 7; // Market Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_separate_window + +// +#property indicator_buffers 1 + +// +#property indicator_level1 0.0 +#property indicator_level2 100.0 +#property indicator_levelcolor clrSilver +#property indicator_levelstyle STYLE_DOT + +// +// MOMENTUM ... +#property indicator_width1 1 +#property indicator_color1 clrLightBlue +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_SOLID + +// +// Declare Buffers ... +#define momentumBufferIndex 0 + +double momentumBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (length < 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + IndicatorBuffers(1); + + // + SetIndexBuffer(momentumBufferIndex, momentumBuffer); + SetIndexLabel(momentumBufferIndex, "Momentum"); + SetIndexDrawBegin(momentumBufferIndex, length); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, length); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Long TP ... + CalculateBuffers( + i, + close + ); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index, + const double &close[] +) { + // + // Calculate Buffers ... + double momentum = close[bar_index] * 100 / close[bar_index + length]; + + // + momentumBuffer[bar_index] = momentum; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.osc.mq4 b/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.osc.mq4 new file mode 100644 index 0000000..220bd33 --- /dev/null +++ b/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.osc.mq4 @@ -0,0 +1,330 @@ +///////////////////////////////////////////////////////////////// +// +// SaherElm IT Center OSC Indicator +// ------------------------------------------------------------- +// this indicator provides OSC ... +// +// 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 OSC Indicator" +#property strict + +// +// START Inputs ... +// +// +// FastOSC ... +// Short Cycle (Fast OSC) ... +input int fastOSCLength = 10; // FastOSC Length +input double fastOSCMultiplier = 1.0; // FastOSC Multiplier + +// +// SlowOSC ... +// Medium Cycle (Slow OSC) ... +input int slowOSCLength = 30; // SlowOSC Length +input double slowOSCMultiplier = 3.0; // SlowOSC Multiplier +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +#property indicator_separate_window + +// +// we have 2 buffer in this indicator ... +#property indicator_buffers 5 + +// +// also we have 2 line for draw on this indicator ... +#property indicator_plots 5 + +// +// Fast OSC ... +#property indicator_width1 1 +#property indicator_color1 clrAqua +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_SOLID + +// +// Slow OSC ... +#property indicator_width2 1 +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrFuchsia +#property indicator_style2 STYLE_SOLID + +// +// Power OSC ... +#property indicator_width3 1 +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_DASHDOTDOT + +// +// Var OSC ... +#property indicator_width4 1 +#property indicator_type4 DRAW_HISTOGRAM +#property indicator_color4 clrBlueViolet +#property indicator_style4 STYLE_SOLID + +// +// Tan Fast/Slow OSC ... +#property indicator_width5 0 +#property indicator_type5 DRAW_NONE +#property indicator_color5 clrNONE +#property indicator_style5 STYLE_SOLID + +// +//#property indicator_minimum 0 +//#property indicator_maximum 1 + +// +// set color of horizontal levels ... +#property indicator_levelcolor clrGray + +// +// set style of horizontal levels ... +#property indicator_levelstyle STYLE_DOT + +// +// Declare Buffers ... +#define fastOSCBufferIndex 0 +#define slowOSCBufferIndex 1 +#define powerOSCBufferIndex 2 +#define varOSCBufferIndex 3 +#define fastSlowOSCAngleBufferIndex 4 + +// +double fastOSCBuffer[]; +double slowOSCBuffer[]; +double fastSlowOSCAngleBuffer[]; +double powerOSCBuffer[]; +double varOSCBuffer[]; + +// +// Used Indicators List ... +string rmaIndicatorName = "x-saherelm.rma"; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + fastOSCLength < 0 || + slowOSCLength < 0 || + slowOSCLength <= fastOSCLength + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XS_OSC"; + + // + // set descriptions of horizontal levels ... + SetLevelValue(0, 0.0); + IndicatorSetString(INDICATOR_LEVELTEXT,0,""); + + // + // set descriptions of horizontal levels ... + SetLevelValue(1, 0.5); + IndicatorSetString(INDICATOR_LEVELTEXT,1,""); + + // + // set descriptions of horizontal levels ... + SetLevelValue(2, 1); + IndicatorSetString(INDICATOR_LEVELTEXT,2,""); + + // + // Fast OSC Buffer ... + SetIndexBuffer(fastOSCBufferIndex, fastOSCBuffer); + SetIndexLabel(fastOSCBufferIndex, "Fast OSC"); + SetIndexDrawBegin(fastOSCBufferIndex, fastOSCLength - 1); + + // + // Slow OSC Buffer ... + SetIndexBuffer(slowOSCBufferIndex, slowOSCBuffer); + SetIndexLabel(slowOSCBufferIndex, "Slow OSC"); + SetIndexDrawBegin(slowOSCBufferIndex, slowOSCLength - 1); + + // + // Power OSC Buffer ... + SetIndexBuffer(powerOSCBufferIndex, powerOSCBuffer); + SetIndexLabel(powerOSCBufferIndex, "Power OSC"); + + // + // Var OSC Buffer ... + SetIndexBuffer(varOSCBufferIndex, varOSCBuffer); + SetIndexLabel(varOSCBufferIndex, "Var OSC"); + + // + // Tan Fast/Slow OSC Buffer ... + SetIndexBuffer(fastSlowOSCAngleBufferIndex, fastSlowOSCAngleBuffer); + SetIndexLabel(fastSlowOSCAngleBufferIndex, "F/L OSC Angle"); + + // + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(fastOSCLength, slowOSCLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + CalculateOscillators(close, i); + } + + // + return rates_total; +} + +// +// De Initialization ... +void OnDeinit(const int reason) { +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +void CalculateOscillators( + const double &close[], + const int &bar_index +) { + // + // FastOSC ... + // Short Cycle Calculations ... + int scl = fastOSCLength / 2; + int scl2 = scl / 2; + double maScl = iCustom(_Symbol, _Period, rmaIndicatorName, scl, 0, bar_index); + double scmAtr = iATR(_Symbol, _Period, scl, bar_index); + double scmOff = fastOSCMultiplier * scmAtr; + double maScl2 = iCustom(_Symbol, _Period, rmaIndicatorName, scl2, 0, bar_index); + double sctParam = maScl2 != 0 ? maScl2 : close[bar_index + 1]; + double sct = sctParam + scmOff; + double scb = sctParam - scmOff; + + // + // SlowOSC ... + // Medium Cycle Calculations ... + int mcl = slowOSCLength / 2; + int mcl2 = mcl / 2; + double maMcl = iCustom(_Symbol, _Period, rmaIndicatorName, mcl, 0, bar_index); + double mcmAtr = iATR(_Symbol, _Period, mcl, bar_index); + double mcmOff = slowOSCMultiplier * mcmAtr; + double maMcl2 = iCustom(_Symbol, _Period, rmaIndicatorName, mcl2, 0, bar_index); + double mctParam = maMcl2 != 0 ? maMcl2 : close[bar_index + 1]; + double mct = mctParam + mcmOff; + double mcb = mctParam - mcmOff; + + // + double scMM = (sct + scb) / 2; + + // + double fastOCS = (close[bar_index] - mcb) / (mct - mcb); + fastOSCBuffer[bar_index] = fastOCS; + + // + double slowOCS = (scMM - mcb) / (mct - mcb); + slowOSCBuffer[bar_index] = slowOCS; + + // + // Signal Power ... + // Difference Variant between FastOSC and Slow OSC ... + double powerOSC = fastOCS - slowOCS; + powerOSCBuffer[bar_index] = powerOSC; + + // + // Var OSC ... + double varOSC = fastOCS - 0.5; + varOSCBuffer[bar_index] = varOSC; + + // + // Calculate Tan Fast/Slow OSC ... + double fastOSCSlope = fastOSCBuffer[bar_index] - fastOSCBuffer[bar_index + 1]; + double slowOSCSlope = slowOSCBuffer[bar_index] - slowOSCBuffer[bar_index + 1]; + double tanFastSlowOSC = MathAbs( + (fastOSCSlope - slowOSCSlope) / (1 + (fastOSCSlope * slowOSCSlope)) + ); + + // + // here we pass Tan of angle ... + // fastSlowOSCAngleBuffer[bar_index] = tanFastSlowOSC; + + // + // here we pass degree of angle ... + fastSlowOSCAngleBuffer[bar_index] = MathArctan(tanFastSlowOSC); +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.rma.mq4 b/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.rma.mq4 new file mode 100644 index 0000000..0fc70fd --- /dev/null +++ b/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.rma.mq4 @@ -0,0 +1,141 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center RMA Indicator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm RMA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Set the RMA Length ... +input int RMALength = 10; // Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// we have 2 buffer in this indicator ... +#property indicator_buffers 1 + +// +// also we have 1 line for draw on this indicator ... +#property indicator_plots 1 + +// +// here we declare plot SlowOCS to system ... +#property indicator_label1 "RMA" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrFuchsia +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +// +// Declare Buffers ... +#define RMABufferIndex 0 + +// +double RMABuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + SetIndexBuffer(RMABufferIndex, RMABuffer); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + int maxLength = MathMax(0, RMALength); + + // + // wait to pass bars until we have rights ... + if (rates_total <= maxLength) { + // + // return not calculated ... + return 0; + } + + // + // find loop count for bars manipulation ... + int count = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // Print("Count: ", count, ", Bars: ", Bars); + + // + // this is the main loop of calculations, for each bar index ... + for (int i = count - 1; i >= 0; i--) { + // + // Start Calculation with Formula 1 ... + // + double shortSMA = iMA(_Symbol, _Period, RMALength, 0, MODE_SMA, PRICE_CLOSE, i); + double mediumSMA = iMA(_Symbol, _Period, RMALength * 2, 0, MODE_SMA, PRICE_CLOSE, i); + double longSMA = iMA(_Symbol, _Period, RMALength * 3, 0, MODE_SMA, PRICE_CLOSE, i); + + // + double rma1 = longSMA - mediumSMA + shortSMA; + rma1 = NormalizeDouble(rma1, _Digits); + // + // End Calculation with Formula 1 ... + // + + // + RMABuffer[i] = rma1; + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.rsi.mq4 b/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.rsi.mq4 new file mode 100644 index 0000000..448f732 --- /dev/null +++ b/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.rsi.mq4 @@ -0,0 +1,234 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center RSI Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm RSI Oscillator" +#property strict + +// +// START Inputs ... +// +input int rsiPeriod=14; // RSI Period +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_separate_window + +// +#property indicator_minimum 0 +#property indicator_maximum 100 + +// +#property indicator_buffers 1 +#property indicator_color1 DodgerBlue + +// +#property indicator_level1 30.0 +#property indicator_level2 50.0 +#property indicator_level3 70.0 +#property indicator_levelcolor clrSilver +#property indicator_levelstyle STYLE_DOT + +// +// Declare Buffers ... +#define rsiBufferIndex 0 +#define positiveBufferIndex 1 +#define negativeBufferIndex 2 + +double rsiBuffer[]; +double positiveBuffer[]; +double negativeBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + string short_name; + + // + IndicatorBuffers(3); + + // + SetIndexBuffer(positiveBufferIndex, positiveBuffer); + SetIndexBuffer(negativeBufferIndex, negativeBuffer); + + // + SetIndexStyle(rsiBufferIndex, DRAW_LINE); + SetIndexBuffer(rsiBufferIndex, rsiBuffer); + + // + // name for DataWindow and indicator subwindow label + short_name="RSI("+string(rsiPeriod)+")"; + IndicatorShortName(short_name); + SetIndexLabel(rsiBufferIndex, short_name); + + // + // check for input + if (rsiPeriod < 2) { + // + Print("Incorrect value for input variable InpRSIPeriod = ", rsiPeriod); + + // + // Failed Initialization ... + return INIT_PARAMETERS_INCORRECT; + } + + // + // set where to start draw ... + SetIndexDrawBegin(0, rsiPeriod); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + int i,pos; + double diff; + + // + // Prevent from run calculations if there is no fulfilled conditions ... + if (Bars <= rsiPeriod || rsiPeriod < 2) { + // + // return nothing calculated result ... + return 0; + } + + // + // counting from 0 to rates_total, this is most important ... + ArraySetAsSeries(rsiBuffer, false); + ArraySetAsSeries(positiveBuffer, false); + ArraySetAsSeries(negativeBuffer, false); + + // + ArraySetAsSeries(close, false); + + // + // preliminary calculations ... + pos = prev_calculated - 1; + if (pos <= rsiPeriod) { + // + // first RSIPeriod values of the indicator are not calculated + rsiBuffer[0] = 0.0; + positiveBuffer[0] = 0.0; + negativeBuffer[0] = 0.0; + + // + double sump=0.0; + double sumn=0.0; + for (i = 1; i <= rsiPeriod; i++) { + // + rsiBuffer[i]=0.0; + positiveBuffer[i]=0.0; + negativeBuffer[i]=0.0; + + // + diff = close[i] - close[i - 1]; + if(diff > 0) { + sump += diff; + } else { + sumn -= diff; + } + } + + // + // calculate first visible value ... + positiveBuffer[rsiPeriod] = sump / rsiPeriod; + negativeBuffer[rsiPeriod] = sumn / rsiPeriod; + if (negativeBuffer[rsiPeriod] != 0.0) { + // + rsiBuffer[rsiPeriod] = 100.0 - ( + 100.0 / ( + 1.0 + positiveBuffer[rsiPeriod] / negativeBuffer[rsiPeriod] + ) + ); + } else { + // + if (positiveBuffer[rsiPeriod] != 0.0) { + rsiBuffer[rsiPeriod] = 100.0; + } else { + rsiBuffer[rsiPeriod] = 50.0; + } + } + + // + // prepare the position value for main calculation ... + pos = rsiPeriod + 1; + } + + // + // the main loop of calculations ... + for (i = pos; i < rates_total && !IsStopped(); i++) { + // + diff = close[i] - close[i-1]; + + // + positiveBuffer[i] = (positiveBuffer[i-1] * (rsiPeriod - 1) + (diff > 0.0 ? diff : 0.0)) / rsiPeriod; + negativeBuffer[i] = (negativeBuffer[i-1] * (rsiPeriod - 1) + (diff < 0.0 ? -diff : 0.0)) / rsiPeriod; + + // + if (negativeBuffer[i] != 0.0) { + rsiBuffer[i] = 100.0 - 100.0 / (1 + positiveBuffer[i] / negativeBuffer[i]); + } else { + // + if (positiveBuffer[i] != 0.0) { + rsiBuffer[i] = 100.0; + } else { + rsiBuffer[i] = 50.0; + } + } + } + + // + return(rates_total); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.xma.mq4 b/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.xma.mq4 new file mode 100644 index 0000000..20206ac --- /dev/null +++ b/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.xma.mq4 @@ -0,0 +1,643 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XMA Indicator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XMA Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 7; // Market Length +input int shortCycleFastMultiplier = 1; // Short Cycle Fast Multiplier +input int shortCycleSlowMultiplier = 4; // Short Cycle Slow Multiplier +input int mediumCycleFastMultiplier = 7; // Medium Cycle Fast Multiplier +input int mediumCycleSlowMultiplier = 14; // Medium Cycle Slow Multiplier +input int longCycleFastMultiplier = 70; // Long Cycle Fast Multiplier +input int longCycleSlowMultiplier = 140; // Long Cycle Slow Multiplier +// +// Show Inputs ... +input bool showShortCycle = true; // Show Short Cycle +input bool showShortCycleCrossLines = true; // Show Short Cycle Vertical Lines +input bool showMediumCycle = true; // Show Medium Cycle +input bool showMediumCycleCrossLines = true; // Show Medium Cycle Vertical Lines +input bool showLongCycle = true; // Show Long Cycle +input bool showLongCycleCrossLines = true; // Show Long Cycle Vertical Lines +// +// Color Inputs ... +input color shortCycleFastColor = clrGreen; // Short Cycle Fast Color ... +input color shortCycleSlowColor = clrRed; // Short Cycle Slow Color ... +input color mediumCycleFastColor = clrAqua; // Medium Cycle Fast Color ... +input color mediumCycleSlowColor = clrFuchsia; // Medium Cycle Slow Color ... +input color longCycleFastColor = clrGoldenrod; // Medium Cycle Fast Color ... +input color longCycleSlowColor = clrBrown; // Medium Cycle Slow Color ... +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// define indicator buffers ... +#property indicator_buffers 7 +#property indicator_plots 7 + +// +// Middle ... +#property indicator_label7 "Mid" +#property indicator_type7 DRAW_LINE +#property indicator_color7 clrBisque +#property indicator_style7 STYLE_DASHDOTDOT +#property indicator_width7 1 + +// +// Declare Buffers ... +#define scFastBufferIndex 0 +#define scSlowBufferIndex 1 +#define mcFastBufferIndex 2 +#define mcSlowBufferIndex 3 +#define lcFastBufferIndex 4 +#define lcSlowBufferIndex 5 +#define midBufferIndex 6 + +// +double scFastBuffer[]; +double scSlowBuffer[]; +double mcFastBuffer[]; +double mcSlowBuffer[]; +double lcFastBuffer[]; +double lcSlowBuffer[]; +double midBuffer[]; + +// +int shortCycleFastLength; +int shortCycleSlowLength; +int mediumCycleFastLength; +int mediumCycleSlowLength; +int longCycleFastLength; +int longCycleSlowLength; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + // + // Validate Market Length ... + marketLength <= 0 + // + // Validate Short Cycle ... + || shortCycleFastMultiplier <= 0 + || shortCycleSlowMultiplier <= 0 + || shortCycleFastMultiplier >= shortCycleSlowMultiplier + // + // Validate Medium Cycle ... + || mediumCycleFastMultiplier <= 0 + || mediumCycleSlowMultiplier <= 0 + || mediumCycleFastMultiplier >= mediumCycleSlowMultiplier + // + // Validate Long Cycle ... + || longCycleFastMultiplier <= 0 + || longCycleSlowMultiplier <= 0 + || longCycleFastMultiplier >= longCycleSlowMultiplier + // + // Validate Series of Multipliers ... + || shortCycleFastMultiplier >= mediumCycleFastMultiplier + || mediumCycleFastMultiplier >= longCycleFastMultiplier + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST_XMA"; + + // + // Calculate Cycle Length based on given Multipliers ... + shortCycleFastLength = marketLength * shortCycleFastMultiplier; + shortCycleSlowLength = marketLength * shortCycleSlowMultiplier; + mediumCycleFastLength = marketLength * mediumCycleFastMultiplier; + mediumCycleSlowLength = marketLength * mediumCycleSlowMultiplier; + longCycleFastLength = marketLength * longCycleFastMultiplier; + longCycleSlowLength = marketLength * longCycleSlowMultiplier; + + // + // Short Cycle Fast ... + SetIndexLabel(scFastBufferIndex, "SCFast"); + SetIndexBuffer(scFastBufferIndex, scFastBuffer); + SetIndexDrawBegin(scFastBufferIndex, shortCycleFastLength); + SetIndexStyle( + scFastBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showShortCycle ? + shortCycleFastColor : + clrNONE + ); + + // + // Short Cycle Slow ... + SetIndexLabel(scSlowBufferIndex, "SCSLow"); + SetIndexBuffer(scSlowBufferIndex, scSlowBuffer); + SetIndexDrawBegin(scSlowBufferIndex, shortCycleSlowLength); + SetIndexStyle( + scSlowBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showShortCycle ? + shortCycleSlowColor : + clrNONE + ); + + // + // Medium Cycle Fast ... + SetIndexLabel(mcFastBufferIndex, "MCFast"); + SetIndexBuffer(mcFastBufferIndex, mcFastBuffer); + SetIndexDrawBegin(mcFastBufferIndex, mediumCycleFastLength); + SetIndexStyle( + mcFastBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showMediumCycle ? + mediumCycleFastColor : + clrNONE + ); + + // + // Medium Cycle Slow ... + SetIndexLabel(mcSlowBufferIndex, "MCSlow"); + SetIndexBuffer(mcSlowBufferIndex, mcSlowBuffer); + SetIndexDrawBegin(mcSlowBufferIndex, mediumCycleSlowLength); + SetIndexStyle( + mcSlowBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showMediumCycle ? + mediumCycleSlowColor : + clrNONE + ); + + // + // Long Cycle Fast ... + SetIndexLabel(lcFastBufferIndex, "LCFast"); + SetIndexBuffer(lcFastBufferIndex, lcFastBuffer); + SetIndexDrawBegin(lcFastBufferIndex, longCycleFastLength); + SetIndexStyle( + lcFastBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showLongCycle ? + longCycleFastColor : + clrNONE + ); + + // + // Long Cycle Slow ... + SetIndexLabel(lcSlowBufferIndex, "LCSlow"); + SetIndexBuffer(lcSlowBufferIndex, lcSlowBuffer); + SetIndexDrawBegin(lcSlowBufferIndex, longCycleSlowLength); + SetIndexStyle( + lcSlowBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showLongCycle ? + longCycleSlowColor : + clrNONE + ); + + // + // Market Middleage ... + SetIndexBuffer(midBufferIndex, midBuffer); + SetIndexDrawBegin(midBufferIndex, marketLength); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + RemoveDraws(logTag); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(marketLength, longCycleSlowLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Short Cycle ... + CalculateShortCycle(i); + + // + // Calculate Medium Cycle ... + CalculateMediumCycle(i); + + // + // Calculate Long Cycle ... + CalculateLongCycle(i); + + // + // Calculate Market Middleage ... + CalculateMarketMiddleage(i); + + // + // Calculate Cross Points ... + CalculateCrossPoints(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculate Short Cycle ... +void CalculateShortCycle( + const int bar_index +) { + // + // Fast ... + double shortCycleFast = iMA( + _Symbol, + _Period, + shortCycleFastLength, + 0, + MODE_SMA, + PRICE_WEIGHTED, + bar_index + ); + scFastBuffer[bar_index] = shortCycleFast; + + // + // Slow ... + double shortCycleSlow = iMA( + _Symbol, + _Period, + shortCycleSlowLength, + 0, + MODE_SMA, + PRICE_WEIGHTED, + bar_index + ); + scSlowBuffer[bar_index] = shortCycleSlow; +} + +// +// Calculate Medium Cycle ... +void CalculateMediumCycle( + const int bar_index +) { + // + // Fast ... + double mediumCycleFast = iMA( + _Symbol, + _Period, + mediumCycleFastLength, + 0, + MODE_SMA, + PRICE_MEDIAN, + bar_index + ); + mcFastBuffer[bar_index] = mediumCycleFast; + + // + // Slow ... + double mediumCycleSlow = iMA( + _Symbol, + _Period, + mediumCycleSlowLength, + 0, + MODE_SMA, + PRICE_MEDIAN, + bar_index + ); + mcSlowBuffer[bar_index] = mediumCycleSlow; +} + +// +// Calculate Long Cycle ... +void CalculateLongCycle( + const int bar_index +) { + // + // Fast ... + double longCycleFast = iMA( + _Symbol, + _Period, + longCycleFastLength, + 0, + MODE_SMA, + PRICE_CLOSE, + bar_index + ); + lcFastBuffer[bar_index] = longCycleFast; + + // + // Slow ... + double longCycleSlow = iMA( + _Symbol, + _Period, + longCycleSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE, + bar_index + ); + lcSlowBuffer[bar_index] = longCycleSlow; +} + +// +// Calculate Market Middleage ... +void CalculateMarketMiddleage( + const int bar_index +) { + // + // Mid ... + double marketMiddleage = iMA( + _Symbol, + _Period, + (int)(marketLength * 1.5), + 0, + MODE_EMA, + PRICE_MEDIAN, + bar_index + ); + midBuffer[bar_index] = marketMiddleage; +} + +// +// Calculate Cross Points and Draw Section Line on theme ... +void CalculateCrossPoints( + const int bar_index +) { + // + // START Draw Cross Lines ... + // + // + // Short Cycle ... + bool isSCFastCrossOverSlow = scFastBuffer[bar_index] > scSlowBuffer[bar_index] + && !(scFastBuffer[bar_index + 1] > scSlowBuffer[bar_index + 1]); + + // + bool isSCFastCrossUnderSlow = scFastBuffer[bar_index] < scSlowBuffer[bar_index] + && !(scFastBuffer[bar_index + 1] < scSlowBuffer[bar_index + 1]); + + // + // Medium Cycle ... + bool isMCFastCrossOverSlow = mcFastBuffer[bar_index] > mcSlowBuffer[bar_index] + && !(mcFastBuffer[bar_index + 1] > mcSlowBuffer[bar_index + 1]); + + // + bool isMCFastCrossUnderSlow = mcFastBuffer[bar_index] < mcSlowBuffer[bar_index] + && !(mcFastBuffer[bar_index + 1] < mcSlowBuffer[bar_index + 1]); + + // + // Long Cycle ... + bool isLCFastCrossOverSlow = lcFastBuffer[bar_index] > lcSlowBuffer[bar_index] + && !(lcFastBuffer[bar_index + 1] > lcSlowBuffer[bar_index + 1]); + + // + bool isLCFastCrossUnderSlow = lcFastBuffer[bar_index] < lcSlowBuffer[bar_index] + && !(lcFastBuffer[bar_index + 1] < lcSlowBuffer[bar_index + 1]); + + // + // START Drawing CrossPoints ... + // + // + datetime currentTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + if (showShortCycleCrossLines) { + // + // Draw Line ... + if (isSCFastCrossOverSlow) { + // + string lbl = StringConcatenate( + logTag, + "_SC_F_OV_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showShortCycleCrossLines ? + shortCycleFastColor : + clrNONE + ); + } + + // + // Draw Line ... + if (isSCFastCrossUnderSlow) { + // + string lbl = StringConcatenate( + logTag, + "_SC_F_UN_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showShortCycleCrossLines ? + shortCycleSlowColor : + clrNONE + ); + } + } + + // + if (showMediumCycleCrossLines) { + // + // Draw Line ... + if (isMCFastCrossOverSlow) { + // + string lbl = StringConcatenate( + logTag, + "_MC_F_OV_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showMediumCycleCrossLines ? + mediumCycleFastColor : + clrNONE + ); + } + + // + // Draw Line ... + if (isMCFastCrossUnderSlow) { + // + string lbl = StringConcatenate( + logTag, + "_MC_F_UN_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showMediumCycleCrossLines ? + mediumCycleSlowColor : + clrNONE + ); + } + } + + // + if (showLongCycleCrossLines) { + // + // Draw Line ... + if (isLCFastCrossOverSlow) { + // + string lbl = StringConcatenate( + logTag, + "_LC_F_OV_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showLongCycleCrossLines ? + longCycleFastColor : + clrNONE + ); + } + + // + // Draw Line ... + if (isLCFastCrossUnderSlow) { + // + string lbl = StringConcatenate( + logTag, + "_LC_F_UN_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showLongCycleCrossLines ? + longCycleSlowColor : + clrNONE + ); + } + } + // + // END Drawing CrossPoints ... + // +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.zigzag.mq4 b/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.zigzag.mq4 new file mode 100644 index 0000000..fbb073c --- /dev/null +++ b/Bkp/Used/OSC EA 14020410/Indicators/x-saherelm.zigzag.mq4 @@ -0,0 +1,476 @@ +///////////////////////////////////////////////////////////////// +// +// SaherElm IT Center ZigZag Indicator +// ------------------------------------------------------------- +// this indicator provides signals for Main strategy ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +//////////////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm ZigZag Indicator" +#property strict + +// +// START Inputs ... +// +input int depth = 12; // Depth +input int deviation = 5; // Deviation +input int backStep = 3; // BackStep +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// here we specify logging enabled or not ... +bool enableLogging = true; + +// +// this is a Tag which attached to our Logger ... +string logTag = "XS_ZG"; + +// +#property indicator_chart_window + +// +#property indicator_buffers 1 + +// +#property indicator_width1 1 +#property indicator_color1 clrAqua +// #property indicator_type1 DRAW_SECTION +// #property indicator_style1 STYLE_SOLID + +// // +// #property indicator_width2 1 +// #property indicator_color2 clrNONE +// #property indicator_type2 DRAW_NONE +// #property indicator_style2 STYLE_SOLID + +// // +// #property indicator_width3 1 +// #property indicator_color3 clrNONE +// #property indicator_type3 DRAW_NONE +// #property indicator_style3 STYLE_SOLID + +// +// Buffers ... +// +#define zigzagBufferIndex 0 +#define highBufferIndex 1 +#define lowBufferIndex 2 +// #define ziggyBufferIndex 3 + +// +double zigzagBuffer[]; +double highBuffer[]; +double lowBuffer[]; +// double ziggyBuffer[]; + +// +// recounting's depth of extremums ... +int level=3; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + depth <= 0 || + backStep < 0 || + deviation < 0 || + backStep >= depth + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Set Index Buffers of ZigZag ... + IndicatorBuffers(3); + + // + // ZigZag Buffer ... + SetIndexBuffer(zigzagBufferIndex, zigzagBuffer); + SetIndexStyle(zigzagBufferIndex, DRAW_SECTION); + SetIndexLabel(zigzagBufferIndex, "ZigZag"); + + // + // High Buffer ... + SetIndexBuffer(highBufferIndex, highBuffer); + SetIndexLabel(highBufferIndex, ""); + + // + // Low Buffer ... + SetIndexBuffer(lowBufferIndex, lowBuffer); + SetIndexLabel(lowBufferIndex, ""); + + // + // Ziggy Buffer ... + // SetIndexBuffer(ziggyBufferIndex, ziggyBuffer); + // SetIndexLabel(ziggyBufferIndex, ""); + + // + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + int maxLength = MathMax(depth, backStep); + + int i; + int counterZ; + int back; + int pos; + + // + int lastlowpos = 0; + int lasthighpos = 0; + int whatlookfor = 0; + + // + double extremum; + + // + double curlow = 0.0; + double curhigh = 0.0; + double lasthigh = 0.0; + double lastlow = 0.0; + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // first calculations ... + if (prev_calculated == 0) { + limit = InitializeBuffers(); + } else { + // + // find first extremum in the depth ExtLevel or 100 last bars ... + i = counterZ = 0; + while(counterZ < level && i < 100) { + // + if(zigzagBuffer[i] != 0.0) { + counterZ++; + } + + // + i++; + } + + // + // no extremum found - recounting all from begin ... + if(counterZ == 0) { + limit = InitializeBuffers(); + } else { + // + // set start position to found extremum position ... + limit = i-1; + + // + //--- what kind of extremum? + if(lowBuffer[i] != 0.0) { + // + // low extremum ... + curlow = lowBuffer[i]; + + // + // will look for the next high extremum ... + whatlookfor=1; + } else { + // + // high extremum ... + curhigh = highBuffer[i]; + + // + // will look for the next low extremum ... + whatlookfor=-1; + } + + // + // clear the rest data ... + for(i = limit - 1; i >= 0; i--) { + // + lowBuffer[i]=0.0; + highBuffer[i]=0.0; + zigzagBuffer[i]=0.0; + } + } + } + + // + // Main Calculation Loop ... + for (i = limit; i >= 0; i--) { + // + // find lowest low in depth of bars ... + extremum = low[ + iLowest( + _Symbol, + _Period, + MODE_LOW, + depth, + i + ) + ]; + + // + // this lowest has been found previously ... + if (extremum == lastlow) { + extremum = 0.0; + } else { + // + // new last low ... + lastlow=extremum; + + // + // discard extremum if current low is too high ... + if(low[i] - extremum > deviation * _Point) { + extremum=0.0; + } else { + // + // clear previous extremums in backstep bars ... + for(back = 1; back <= backStep; back++) { + // + pos = i + back; + + // + if(lowBuffer[pos] != 0 && lowBuffer[pos] > extremum) { + lowBuffer[pos] = 0.0; + } + } + } + } + + // + // found extremum is current low ... + if (low[i] == extremum) { + lowBuffer[i] = extremum; + } else { + lowBuffer[i] = 0.0; + } + + // + // find highest high in depth of bars ... + extremum = high[ + iHighest( + _Symbol, + _Period, + MODE_HIGH, + depth, + i + ) + ]; + + // + // this highest has been found previously ... + if (extremum == lasthigh) { + extremum = 0.0; + } else { + // + // new last high ... + lasthigh=extremum; + + // + // discard extremum if current high is too low ... + if (extremum - high[i] > deviation * Point) { + extremum = 0.0; + } else { + // + // clear previous extremums in backstep bars ... + for(back = 1; back <= backStep; back++) { + // + pos = i + back; + + // + if (highBuffer[pos] != 0 && highBuffer[pos] < extremum) { + highBuffer[pos] = 0.0; + } + } + } + } + + // + // found extremum is current high ... + if (high[i] == extremum) { + highBuffer[i] = extremum; + } else { + highBuffer[i] = 0.0; + } + } + + // + // final cutting ... + if( whatlookfor == 0) { + // + lastlow = 0.0; + lasthigh = 0.0; + } else { + // + lastlow = curlow; + lasthigh = curhigh; + } + + // + for(i = limit; i >= 0; i--) { + switch(whatlookfor) { + // + // look for peak or lawn ... + case 0: + // + if (lastlow == 0.0 && lasthigh == 0.0) { + if(highBuffer[i]!=0.0) { + // + lasthigh = High[i]; + lasthighpos = i; + whatlookfor = -1; + + // + zigzagBuffer[i] = lasthigh; + } + + // + if(lowBuffer[i] != 0.0) { + // + lastlow = Low[i]; + lastlowpos = i; + whatlookfor = 1; + + // + zigzagBuffer[i] = lastlow; + } + } + break; + + // + // look for peak ... + case 1: + // + if ( + lowBuffer[i] != 0.0 && + lowBuffer[i] < lastlow && + highBuffer[i] == 0.0 + ) { + // + zigzagBuffer[lastlowpos] = 0.0; + lastlowpos = i; + lastlow = lowBuffer[i]; + zigzagBuffer[i] = lastlow; + } + + // + if(highBuffer[i] != 0.0 && lowBuffer[i] == 0.0) { + // + lasthigh = highBuffer[i]; + lasthighpos = i; + zigzagBuffer[i] = lasthigh; + + // + whatlookfor=-1; + } + break; + + // + // look for lawn ... + case -1: + // + if( + highBuffer[i] != 0.0 && + highBuffer[i] > lasthigh && + lowBuffer[i] == 0.0 + ) { + // + zigzagBuffer[lasthighpos] = 0.0; + lasthighpos = i; + lasthigh = highBuffer[i]; + zigzagBuffer[i] = lasthigh; + } + + // + if( + lowBuffer[i] !=0.0 && + highBuffer[i] == 0.0 + ) { + // + lastlow = lowBuffer[i]; + lastlowpos = i; + zigzagBuffer[i] = lastlow; + whatlookfor=1; + } + break; + } + } + + // + // Done ... + return rates_total; +} + +// +// De Initialization ... +void OnDeinit(const int reason) { + // + // RemoveDraws(signalPrefix); + ChartRedraw(0); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +int InitializeBuffers() { + // + ArrayInitialize(lowBuffer,0.0); + ArrayInitialize(highBuffer, 0.0); + ArrayInitialize(zigzagBuffer, 0.0); + + // + //--- first counting position + return(Bars - depth); +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020410/Libraries/x-saherelm.draw.lib.mq4 b/Bkp/Used/OSC EA 14020410/Libraries/x-saherelm.draw.lib.mq4 new file mode 100644 index 0000000..08fefa7 --- /dev/null +++ b/Bkp/Used/OSC EA 14020410/Libraries/x-saherelm.draw.lib.mq4 @@ -0,0 +1,1670 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Start Arrow Functions ... +// +// +// Draw an Arrow Object on Chart ... +bool DrawArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // arrow name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const uchar arrowCode = OBJ_ARROW_UP, // arrow code + const ENUM_ARROW_ANCHOR anchor = ANCHOR_BOTTOM, // anchor point position + const color clr = clrAqua, // arrow color + const ENUM_LINE_STYLE style = STYLE_SOLID, // border line style + const int width = 3, // arrow size + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // Order Object ... +) { + // + // set anchor point coordinates if they are not set ... + ChangeArrowEmptyPoint(time, price); + + // + // reset the error value ... + ResetLastError(); + + // + // create an arrow ... + if(!ObjectCreate(chartID, name, OBJ_ARROW, subWindow, time, price)) { + // + string message = StringConcatenate(__FUNCTION__, + ": failed to create an arrow! Error code = ", + GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the arrow code ... + ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, arrowCode); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set the arrow color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set the border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set the arrow's size ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the arrow by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is false by default, if you want making it possible to highlight and move the object + // change it to true ... + ObjectSetInteger(chartID,name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point of Arrow ... +bool MoveArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if(!time) { + time = TimeCurrent(); + } + + // + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete an arrow ... +bool DeleteArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow" // arrow name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete an arrow ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete an arrow! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the arrow code ... +bool ArrowCodeChange( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + const uchar code = 252 // arrow code +) { + // + // reset the error value ... + ResetLastError(); + + // + // change the arrow code ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, code)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the arrow code! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change anchor type ... +bool ArrowAnchorChange( + const long chartID = 0, // chart's ID + const string name="Arrow", // object name + const ENUM_ARROW_ANCHOR anchor = ANCHOR_TOP // anchor type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change anchor type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change anchor type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeArrowEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } +} +// +// End Arrow Functions ... +// + +// +// Start Horizontal Line Functions ... +// +// +// Create, Draw the horizontal line ... +bool DrawHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + const int subWindow = 0, // subwindow index + double price = 0, // line price + const color clr = clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the price is not set, set it at the current Bid price level ... + if(!price) { + price=SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // create a horizontal line ... + if(!ObjectCreate(chartID, name, OBJ_HLINE, subWindow, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move horizontal line ... +bool MoveHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + double price = 0 // line price +) { + // + // if the line price is not set, move it to the current Bid price level ... + if(!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move a horizontal line ... + if(!ObjectMove(chartID, name, 0, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete a horizontal line ... +bool DeleteHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a horizontal line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End Horizontal Line Functions ... +// + +// +// Start Vertical Line Functions ... +// +// +// Create the vertical line ... +bool DrawVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + const int sub_window = 0, // subwindow index + datetime time = 0, // line time + const color clr=clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the line time is not set, draw it via the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value + ResetLastError(); + + // + // create a vertical line ... + if (!ObjectCreate(chartID, name, OBJ_VLINE, sub_window, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return true; +} + +// +// Move the vertical line ... +bool MoveVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + datetime time = 0 // line time +) { + // + // if line time is not set, move the line to the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the vertical line ... + if(!ObjectMove(chartID, name, 0, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the vertical line ... +bool DeleteVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the vertical line ... + if (!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // successful execution ... + return true; +} +// +// End Vertical Line Functions ... +// + +// +// Start RectangleLabel Functions ... +// +// +// Create Rectangle Label Object ... +bool DrawRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int subWindow = 0, // subwindow index + const int x = 0, // X coordinate + const int y = 0, // Y coordinate + const int width = 50, // width + const int height = 18, // height + const color back_clr = C'236,233,216', // background color + const ENUM_BORDER_TYPE border = BORDER_SUNKEN, // border type + const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring + const color clr = clrRed, // flat border color (Flat) + const ENUM_LINE_STYLE style = STYLE_SOLID, // flat border style + const int lineWidth = 1, // flat border width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // reset the error value ... + ResetLastError(); + + // + //--- create a rectangle label + if(!ObjectCreate(chartID, name, OBJ_RECTANGLE_LABEL, subWindow, 0, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set label coordinates ... + ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x); + ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y); + + // + // set label size ... + ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width); + ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height); + + // + // set background color ... + ObjectSetInteger(chartID, name, OBJPROP_BGCOLOR, back_clr); + + // + // set border type ... + ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border); + + // + // set the chart's corner, relative to which point coordinates are defined ... + ObjectSetInteger(chartID, name, OBJPROP_CORNER, corner); + + // + // set flat border color (in Flat mode) ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set flat border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set flat border width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, lineWidth); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the label by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move Rectangle Label .. +bool MoveRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int x = 0, // X coordinate + const int y=0 // Y coordinate +) { + // + // reset the error value ... + ResetLastError(); + + // + // move the rectangle label ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move X coordinate of the label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move Y coordinate of the label! Error code = ",GetLastError() + ); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the rectangle label ... +bool DeleteRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel" // label name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the label ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change Rectangle Label Size ... +bool ChangeSizeRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int width = 50, // label width + const int height = 18 // label height +) { + // + // reset the error value ... + ResetLastError(); + + // + // change label size ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's width! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's height! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change rectangle label border type ... +bool RectLabelChangeBorderType( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const ENUM_BORDER_TYPE border = BORDER_SUNKEN // border type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change border type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the border type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End RectangleLabel Functions ... +// + +// +// Start TrendLine Funcions ... +// +// Create a trend line by the given coordinates ... +bool DrawTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrYellow, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool rayRight = false, // line's continuation to the right + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeTrendLineEmptyPoints( + time1, + price1, + time2, + price2 + ); + + // + // reset the error value ... + ResetLastError(); + + // + // create a trend line by the given coordinates ... + if(!ObjectCreate(chartID, name, OBJ_TREND, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the line's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move trend line anchor point ... | +bool ChangeTrendLinePoint( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int pointindex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move trend line's anchor point ... + if(!ObjectMove(chartID, name, pointindex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// The function deletes the trend line from the chart ... +bool DeleteTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a trend line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of trend line's anchor points and set default ... +// values for empty ones ... +void ChangeTrendLineEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the first point's time is not set, it will be on the current bar ... + if (!time1) { + time1 = TimeCurrent(); + } + + // + // if the first point's price is not set, it will have Bid value ... + if (!price1) { + price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // if the second point's time is not set, it is located 9 bars left from the second one ... + if (!time2) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(), Period(), time1, 10, temp); + + // + // set the second point 9 bars left from the first one ... + time2 = temp[0]; + } + + // + // if the second point's price is not set, it is equal to the first point's one ... + if (!price2) { + price2 = price1; + } +} +// +// End TrendLine Functions ... +// + +// +// Start Text Functions ... +// +// Create and Draw a Text Object ... +bool DrawText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const string text = "Text", // the text itself + const string font = "Arial", // font + const int fontSize = 10, // font size + const color clr = clrRed, // color + const double angle = 0.0, // text slope + const ENUM_ANCHOR_POINT anchor = ANCHOR_CENTER, // anchor type + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor point coordinates if they are not set ... + ChangeTextEmptyPoint(time,price); + + // + // reset the error value ... + ResetLastError(); + + // + //--- create Text object + if(!ObjectCreate(chartID, name, OBJ_TEXT, subWindow, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the text ... + ObjectSetString(chartID, name , OBJPROP_TEXT, text); + + // + // set text font ... + ObjectSetString(chartID, name, OBJPROP_FONT, font); + + // + // set font size ... + ObjectSetInteger(chartID, name, OBJPROP_FONTSIZE, fontSize); + + // + // set the slope angle of the text ... + ObjectSetDouble(chartID, name, OBJPROP_ANGLE, angle); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the object by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID ,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point ... +bool MoveText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + //--- if point position is not set, move it to the current bar having Bid price + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point .. + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the object text ... +bool ChangeText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const string text = "Text" // text +) { + // + // reset the error value ... + ResetLastError(); + + // + // change object text ... + if(!ObjectSetString(chartID, name, OBJPROP_TEXT, text)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the text! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Text object ... +bool DeleteText( + const long chartID = 0, // chart's ID + const string name = "Text" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeTextEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + } +// +// End Text Functions ... +// + +// +// Start Fibonacchi Functions ... +// +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawFibonacci( + const long chartID = 0, // chart's ID + const string name="Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrRed, // object color + const ENUM_LINE_STYLE style = STYLE_SOLID, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawCustomFibonacci( + // + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + // + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrAqua, // object color + const ENUM_LINE_STYLE style = STYLE_DOT, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // Change Levels Of Fibonacci ... + bool result = FibonacciLevelsSet( + levels, + values, + colors, + styles, + widths, + descriptions, + chartID, + name + ); + + // + // successful execution ... + return result; +} + +// +// Set number of levels and their parameters ... +bool FibonacciLevelsSet( + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // check array sizes ... + if( + levels!=ArraySize(colors) || + levels!=ArraySize(styles) || + levels!=ArraySize(widths) || + levels!=ArraySize(widths) + ) { + // + string message = StringConcatenate( + __FUNCTION__, + ": array length does not correspond to the number of levels, error!" + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the number of levels ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELS, levels); + + // + // set the properties of levels in the loop ... + for(int i = 0; i < levels; i++) { + // + // level value ... + ObjectSetDouble(chartID, name, OBJPROP_LEVELVALUE, i, values[i]); + + // + // level color ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELCOLOR, i, colors[i]); + + // + // level style ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELSTYLE, i, styles[i]); + + // + // level width ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELWIDTH, i, widths[i]); + + // + // level description ... + // ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, DoubleToString(100 * values[i], 1)); + ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, descriptions[i]); + } + + // + // successful execution ... + return(true); +} + +// +// Move Fibonacci Retracement anchor point ... +bool FibonacciPointChange( + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int pointIndex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, pointIndex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Fibonacci Retracement ... +bool DeleteFibonachi( + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Fibonacci Retracement\"! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of Fibonacci Retracement anchor points and set +// default values for empty ones ... +void ChangeFibonacciEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the second point's time is not set, it will be on the current bar ... + if (!time2) { + time2 = TimeCurrent(); + } + + // + // if the second point's price is not set, it will have Bid value ... + if (!price2) { + price2 = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // if the first point's time is not set, it is located 9 bars left from the second one ... + if (!time1) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(),Period(),time2,10,temp); + + // + // set the first point 9 bars left from the second one ... + time1 = temp[0]; + } + + // + // if the first point's price is not set, move it 200 points below the second one ... + if (!price1) { + price1 = price2 - 200 * SymbolInfoDouble(_Symbol, SYMBOL_POINT); + } +} +// +// End Fibonacci Functions ... +// + + +// +// Start General Functions ... +// +// +// Remove all Drawn Objects ... +void RemoveDraws(const string &tag) { + // + for(int iObj=ObjectsTotal()-1; iObj >= 0; iObj--) { + // + string on = ObjectName(iObj); + if (StringFind(on, tag) == 0) { + ObjectDelete(on); + } + } +} +// +// End General Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020410/Libraries/x-saherelm.lib.mq4 b/Bkp/Used/OSC EA 14020410/Libraries/x-saherelm.lib.mq4 new file mode 100644 index 0000000..c1ccd2a --- /dev/null +++ b/Bkp/Used/OSC EA 14020410/Libraries/x-saherelm.lib.mq4 @@ -0,0 +1,1129 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +// START Functions ... +// + +// +// Determines current working is New Bar or not ... +bool IsNewBar() { + // + static datetime lastbar; + datetime curbar = (datetime)SeriesInfoInteger(_Symbol, _Period, SERIES_LASTBAR_DATE); + + // + if(lastbar != curbar) { + // + lastbar = curbar; + return true; + } + + // + return false; +} + +// +// Retrieve RMA on Specific Candle ... +double GetRMA( + int bar_index, + int length +) { + // + double shortSMA = iMA(_Symbol, _Period, length, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double mediumSMA = iMA(_Symbol, _Period, length * 2, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double longSMA = iMA(_Symbol, _Period, length * 3, 0, MODE_SMA, PRICE_CLOSE, bar_index); + + // + double result = longSMA - mediumSMA + shortSMA; + + // + return result; +} + +// +// this function check crossing up two Buffers ... +bool IsCrossedOver( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] > arr2[index1]) && !(arr1[index2] > arr2[index2]); + + // + return result; +} + +// +// this function check crossing down two Buffers ... +bool IsCrossedUnder( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] < arr2[index1]) && !(arr1[index2] < arr2[index2]); + + // + return result; +} + +// +// Convert points to Actual Point ... +double PointsToDouble(int points) { + // + double result = points * _Point; + return result; +} + +// +// Converts Pips to Points ... +int PipsToPoints(int pips) { + // + int result = pips * ((_Digits == 3 || _Digits == 5) ? 10 : 1); + return result; +} + +// +// Converts Pips to Double ... +double PipsToDouble(int pips) { + // + double result = PointsToDouble(PipsToPoints(pips)); + return result; +} + +// +// Converts Double Value to Pips ... +int PriceToPips(double value) { + // + if (value <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + int result = (int)(value / pipValue); + + // + return result; +} + +// +// Converts Pips to Double ... +double PipsToPrice(int pips) { + // + if (pips <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + double result = pipValue * pips; + + // + return result; +} + +// +// Generate ATR StopLoss Value ... +double CalculateATRSL( + int period, + double multiplier +) { + // + if (period <= 0 || multiplier <= 0) { + return 0; + } + + // + double atrValue = iATR( + _Symbol, + _Period, + period, + 0 + ); + + // + double result = atrValue * multiplier; + + // + return result; +} + +// +// Detect Candle Type ... +// Bullish => means close > open ... +bool IsBullishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBullishCandle( + open, + close + ); + + // + return result; +} + +bool IsBullishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open < close; + + // + return result; +} + +// +// Detect Candle Type ... +// Bearish => means close < open ... +bool IsBearishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBearishCandle( + open, + close + ); + + // + return result; +} + +bool IsBearishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open > close; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBullishHappens( + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + bool result = false; + + // + double lowestHighInMarket = GetMarketLowestHigh( + bar_index + 1, + marketLen + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + 1 + ); + + // + result = high > lowestHighInMarket + && PriceToPips(high - lowestHighInMarket) >= 4 + ; + + // + return result; +} + +// +// Detect Market Has Sharp Bearish or not ... +bool IsSharpBearishHappens( + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + bool result = false; + + // + double highestLowInMarket = GetMarketHighestLow( + bar_index + 1, + marketLen + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + result = low < highestLowInMarket + && PriceToPips(highestLowInMarket - low) >= 4 + ; + + // + return result; +} + +// +// Retrieve Highest High Value based on Given Market ... +double GetMarketHighestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Low Value based on Given Market ... +double GetMarketHighestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Open Value based on Given Market ... +double GetMarketHighestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Low Value based on Given Market ... +double GetMarketLowestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest High Value based on Given Market ... +double GetMarketLowestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Open Value based on Given Market ... +double GetMarketLowestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Close Value based on Given Market ... +double GetMarketLowestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// less than given price ... +double GetLowLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// great than given price ... +double GetLowGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// less than given price ... +double GetHighLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// great than given price ... +double GetHighGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// less than given price ... +double GetCloseLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// great than given price ... +double GetCloseGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +struct XMinMax { + double min; + double max; +}; + +// +// Find Min and Max Value of specific Buffer ... +XMinMax GetBufferMinMax(const double &buffer[]) { + // + XMinMax result = {}; + + // + int bufferSize = ArraySize(buffer); + if (bufferSize < 1) { + return result; + } + + // + double min = buffer[0]; + double max = buffer[0]; + + // + for (int i = 1; i < bufferSize; i++) { + // + if (buffer[i] < min) { + min = buffer[i]; + } else if (buffer[i] > max) { + max = buffer[i]; + } + } + + // + result.min = min; + result.max = max; + + // + return result; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020410/Libraries/x-saherelm.log.lib.mq4 b/Bkp/Used/OSC EA 14020410/Libraries/x-saherelm.log.lib.mq4 new file mode 100644 index 0000000..0a1e0e2 --- /dev/null +++ b/Bkp/Used/OSC EA 14020410/Libraries/x-saherelm.log.lib.mq4 @@ -0,0 +1,91 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Log Tag ... +static string logTag = ""; + +// +// Enable or Disable Logging ... +static bool enableLogging = false; + +// +// Start Log Messages ... +// + +// +// Logging a Message, specified for this EA ... +// using provided LogTag ... +void LogMessage(string message) { + // + if (!enableLogging) { + return; + } + + // + Print(logTag, " > ", message); +} + +// +// this used for logging series ... +void LogSeries( + double &series[], // which series to Log ... + int length = 0, // number of items to Log, 0 means all ... + int skip = 0 // number of items which skip before logging ... +) { + // + string msg = ""; + + // + int seriesSize = ArraySize(series); + if ( + skip < 0 + || length < 0 + || seriesSize == 0 + || skip > seriesSize + || skip + length > seriesSize + ) { + return; + } + + // + length = length = 0 ? + seriesSize : + length; + int start = skip > 1 ? + skip - 1 : + skip == 1 ? + 1 : + 0; + + // + // Loop through series items ... + for (int i = start; i < start + length; i++) { + // + msg += StringConcatenate( + "i[", i, "]: ", series[i], ", " + ); + } + + // + LogMessage(msg); +} +// +// End Log Messages ... +// + diff --git a/Bkp/Used/OSC EA 14020410/Libraries/x-saherelm.osc.models.lib.mq4 b/Bkp/Used/OSC EA 14020410/Libraries/x-saherelm.osc.models.lib.mq4 new file mode 100644 index 0000000..dbf8bd9 --- /dev/null +++ b/Bkp/Used/OSC EA 14020410/Libraries/x-saherelm.osc.models.lib.mq4 @@ -0,0 +1,217 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Models Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Start Models ... +// + +// +// Used Indicators List ... +const string xmaIndicatorName = "x-saherelm.xma"; +const string adxIndicatorName = "x-saherelm.adx"; +const string oscIndicatorName = "x-saherelm.osc"; +const string zigZagIndicatorName = "x-saherelm.zigzag"; + +// +// Direction ... +enum X_DIRECTION { + X_UP, + X_DOWN +}; + +// +// these are different signal types ... +enum X_SIGNAL_TYPE { + X_NONE, + X_LONG, + X_SHORT, +}; + +// +// we Model each signals as this type ... +struct XSignal { + int id; + X_SIGNAL_TYPE type; + double tp; + double sl; + string symbol; + datetime time; + double entryPrice; +}; + +// +// this is Signal Request Response model ... +struct XSignalRequest { + bool hasSignal; + X_SIGNAL_TYPE type; + XSignal signal; +}; + +// +// we model OSC Return Data ... +struct XOSCState { + // + double fastOSC; + double fastOSCPrev; + + // + double slowOSC; + double slowOSCPrev; + + // + double powerOSC; + double powerOSCPrev; + + // + double varOSC; + double varOSCPrev; + + // + double tanFSOSC; + + // + bool isOSCCrossOver; + bool isOSCCrossUnder; +}; + +// +// Define a Model to Represent Snapshot of XMA Indicator ... +struct XMAState { + // + // Short Cycle ... + // + // FAST ... + double scFast; + double scFastPrev; + + // + // SLOW ... + double scSlow; + double scSlowPrev; + + // + bool isSCTrendUp; + + // + // Medium Cycle ... + // + // FAST ... + double mcFast; + double mcFastPrev; + + // + // SLOW ... + double mcSlow; + double mcSlowPrev; + + // + // Long Cycle ... + // + // FAST ... + double lcFast; + double lcFastPrev; + + // + // SLOW ... + double lcSlow; + double lcSlowPrev; + + // + // MIDDLEAGE ... + double marketMiddleage; + double marketMiddleagePrev; +}; + +// +struct XMAOverView { + // + bool isSCTrendUp; + bool isSCTrendDown; + + // + bool isMCTrendUp; + bool isMCTrendDown; + + // + bool isLCTrendUp; + bool isLCTrendDown; +}; + +// +// Represent ADX State ... +struct XADXState { + // + double trendPower; + double trendPowerPrev; + + // + double upDirection; + double upDirectionPrev; + + // + double downDirection; + double downDirectionPrev; + + // + bool isUpTrend; + bool isDownTrend; +}; + +// +// ZigZag State ... +struct XZigZagState { + // + double zigZag; + datetime zigZagTime; + + // + double zigZagPrev; + datetime zigZagPrevTime; + + // + double zigZagPrevPrev; + datetime zigZagPrevPrevTime; + + // + double low; + int lowBarIndex; + datetime lowTime; + + // + double high; + int highBarIndex; + datetime highTime; + + // + double delta; + + // + bool isWaitForTrendUp; + bool isWaitForTrendDown; +}; + +// +// Parse Use full Info about ZigZag State ... +struct XZigZagOverView { + // + bool isTrendUp; + bool isTrendDown; +}; +// +// End Models ... +// diff --git a/Bkp/Used/OSC EA 14020410/Libraries/x-saherelm.osc.signal.lib.mq4 b/Bkp/Used/OSC EA 14020410/Libraries/x-saherelm.osc.signal.lib.mq4 new file mode 100644 index 0000000..e10bbf2 --- /dev/null +++ b/Bkp/Used/OSC EA 14020410/Libraries/x-saherelm.osc.signal.lib.mq4 @@ -0,0 +1,3195 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Signal Draw Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.osc.models.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +static int totalSignals = 0; +static int totalLongSignals = 0; +static int totalShortSignals = 0; + +// +static double initialBalance = 0; + +// +static int countedBars = 0; +static bool isNewBar = false; + +// +static XMAState xmaState; +static XOSCState oscState; +static XADXState adxState; +static XMAOverView xmaOverview; +static XZigZagState zigZagState; +static XZigZagOverView zigZagOverView; + +// +static double zigZagValues[]; +static datetime zigZagTimes[]; + +// +static double highs[]; +static datetime highTimes[]; + +// +static double lows[]; +static datetime lowTimes[]; + +// +static double scTrendPowerMax; +static double scTrendPowerMin; +static double scTrendPowers[]; +static datetime scTrendPowerTimes[]; + +// +static double mcTrendPowerMax; +static double mcTrendPowerMin; +static double mcTrendPowers[]; +static datetime mcTrendPowerTimes[]; + +// +static double lcTrendPowerMax; +static double lcTrendPowerMin; +static double lcTrendPowers[]; + +// +// Retrieve ZigZag State ... +XZigZagState GetZigZagState( + const int bar_index, + int zDpt = 7, + int zDev = 5, + int zBkStp = 3 +) { + // + XZigZagState result = {}; + + // + // Free Arrays ... + ArrayFree(zigZagTimes); + ArrayFree(zigZagValues); + + // + int counter = bar_index; + int numberOfZigZagValues = zDpt; + + // + // START Retrieve ZigZag ... + // + // + int lastNonZeroIndex = 0; + while (lastNonZeroIndex < numberOfZigZagValues - 1) { + // + // Retrieve ZigZag Value ... + double zigZagValue = iCustom( + _Symbol, + _Period, + zigZagIndicatorName, + zDpt, // Depth ... + zDev, // Deviation ... + zBkStp, // BackStep ... + 0, // Buffer Index ... + counter // Bar Index ... + ); + + // + if (zigZagValue != 0.0) { + // + // Retrieve Non Zero ZigZag Time ... + datetime zigZagTime = iTime( + _Symbol, + _Period, + counter + ); + + // + ArrayResize( + zigZagTimes, + ArraySize(zigZagTimes) + 1 + ); + ArrayResize( + zigZagValues, + ArraySize(zigZagValues) + 1 + ); + zigZagValues[lastNonZeroIndex] = zigZagValue; + zigZagTimes[lastNonZeroIndex] = zigZagTime; + + // + // Increase Index Value ... + lastNonZeroIndex++; + } + + // + // Increase Bar Index ... + counter++; + } + + // + double lastValue = zigZagValues[0]; + datetime lastValueTime = zigZagTimes[0]; + + // + double lastPrevValue = zigZagValues[1]; + datetime lastPrevValueTime = zigZagTimes[1]; + + // + double lastPrevPrevValue = zigZagValues[2]; + datetime lastPrevPrevValueTime = zigZagTimes[2]; + // + // END Retrieve ZigZag ... + // + + // + result.zigZag = lastValue; + result.zigZagTime = lastValueTime; + + // + result.zigZagPrev = lastPrevValue; + result.zigZagPrevTime = lastPrevValueTime; + + // + result.zigZagPrevPrev = lastPrevPrevValue; + result.zigZagPrevPrevTime = lastPrevPrevValueTime; + + // + double delta = lastPrevPrevValue - lastPrevValue; + result.delta = delta; + + // + bool isWaitForTrendUp = delta > 0; + result.isWaitForTrendUp = !isWaitForTrendUp; + + // + bool isWaitForTrendDown = delta < 0; + result.isWaitForTrendDown = !isWaitForTrendDown; + + // + double low = isWaitForTrendUp ? + lastPrevValue : + lastPrevPrevValue; + datetime lowTime = isWaitForTrendUp ? + lastPrevValueTime : + lastPrevPrevValueTime; + int lowBarIndex = iBarShift( + _Symbol, + _Period, + lowTime + ); + // + result.low = low; + result.lowTime = lowTime; + result.lowBarIndex = lowBarIndex; + + // + double high = isWaitForTrendUp ? + lastPrevPrevValue : + lastPrevValue; + datetime highTime = isWaitForTrendUp ? + lastPrevPrevValueTime : + lastPrevValueTime; + int highBarIndex = iBarShift( + _Symbol, + _Period, + highTime + ); + + // + result.high = high; + result.highTime = highTime; + result.highBarIndex = highBarIndex; + + // + return result; +} + +// +// Retrieve ZigZag Overview ... +XZigZagOverView GetZigZagOverView() { + // + XZigZagOverView result = {}; + + // + // Free Arrays ... + ArrayFree(highs); + ArrayFree(lows); + ArrayFree(lowTimes); + ArrayFree(highTimes); + + // + // Validate Arrays ... + int valuesBufferSize = ArraySize(zigZagValues); + if ( + valuesBufferSize <= 1 + || valuesBufferSize != ArraySize(zigZagTimes) + ) { + return result; + } + + // + // Calculate First high, low ... + bool isFirstItemLow = zigZagValues[0] < zigZagValues[1]; + + // + int pos = 0; + int index = 0; + while (index <= valuesBufferSize - 1) { + // + ArrayResize( + lows, + ArraySize(lows) + 1 + ); + lows[pos] = isFirstItemLow + ? zigZagValues[index] + : zigZagValues[index + 1]; + + // + ArrayResize( + lowTimes, + ArraySize(lowTimes) + 1 + ); + lowTimes[pos] = isFirstItemLow + ? zigZagTimes[index] + : zigZagTimes[index + 1]; + + // + ArrayResize( + highs, + ArraySize(highs) + 1 + ); + highs[pos] = isFirstItemLow + ? zigZagValues[index + 1] + : zigZagValues[index]; + + // + ArrayResize( + highTimes, + ArraySize(highTimes) + 1 + ); + highTimes[pos] = isFirstItemLow + ? zigZagTimes[index + 1] + : zigZagTimes[index]; + + // + pos++; + + // + index += 2; + } + + // + // Now we have going to calculate Trends Based on highs and lows ... + // these calculations done using Highs and Lows Buffer ... + // + double lastLow = 0; + double lastHigh = 0; + bool isTrendUp = true; + bool isTrendDown = true; + double smoothValue = (5 * _Point); + + // + int highBufferSize = ArraySize(highs); + if (highBufferSize > 2) { + // + for (int i = 0; i <= highBufferSize - 1; i++) { + // + lastHigh = i + 1 <= highBufferSize - 1 + ? + highs[i + 1] + : + 0 + ; + + // + isTrendUp = isTrendUp + && ( + highs[i] >= lastHigh + || MathAbs(highs[i] - lastHigh) <= smoothValue + ); + } + } else { + // + isTrendUp = false; + } + result.isTrendUp = isTrendUp; + + // + int lowsBufferSize = ArraySize(lows); + if (lowsBufferSize > 2) { + // + for (int i = 0; i <= lowsBufferSize - 1; i++) { + // + lastLow = i + 1 <= lowsBufferSize - 1 + ? + lows[i + 1] + : + 0 + ; + + // + isTrendDown = isTrendDown + && ( + lows[i] <= lastLow + || MathAbs(lows[i] - lastLow) <= smoothValue + ); + } + } else { + // + isTrendDown = false; + } + result.isTrendDown = isTrendDown; + + // + return result; +} + +// +// Retrieve State ... +XOSCState GetOSCState( + const int bar_index, + const int foLen, + const double foMul, + const int slLen, + const double slMul +) { + // + // Define Trend Direction Related Values ... + // + XOSCState result = {}; + + // + // START Extract Data from Oscillator ... + // + // + // Fast OSC ... + double fastOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 0, // Fast OSC Buffer Index ... + bar_index + ); + result.fastOSC = fastOSC; + + // + // Prev FastOSC ... + double fastOSCPrev = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 0, // Fast OSC Buffer Index ... + bar_index + 1 + ); + result.fastOSCPrev = fastOSCPrev; + + // + // Slow OSC ... + double slowOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 1, // Slow OSC Buffer Index ... + bar_index + ); + result.slowOSC = slowOSC; + + // + // Prev Slow OSC ... + double slowOSCPrev = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 1, // Slow OSC Buffer Index ... + bar_index + 1 + ); + result.slowOSCPrev = slowOSCPrev; + + // + // Power OSC ... + double powerOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 2, // Power OSC Buffer Index ... + bar_index + ); + result.powerOSC = powerOSC; + + // + double powerOSCPrev = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 2, // Power OSC Buffer Index ... + bar_index + 1 + ); + result.powerOSCPrev = powerOSCPrev; + + // + // Var OSC ... + double varOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 3, // Var OSC Buffer Index ... + bar_index + ); + result.varOSC = varOSC; + + // + double varOSCPrev = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 3, // Var OSC Buffer Index ... + bar_index + 1 + ); + result.varOSCPrev = varOSCPrev; + + // + // Tan FS OSC ... + double tanFSOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 4, // Tan F/S OSC Buffer Index ... + bar_index + ); + result.tanFSOSC = tanFSOSC; + // + // END Extract Data from Oscillator ... + // + + // + // Calculations ... + // + bool isOSCCrossOver = fastOSC > slowOSC && + !(fastOSCPrev > slowOSCPrev); + result.isOSCCrossOver = isOSCCrossOver; + + // + bool isOSCCrossUnder = fastOSC < slowOSC && + !(fastOSCPrev < slowOSCPrev); + result.isOSCCrossUnder = isOSCCrossUnder; + + // + return result; +} + +// +// Check Market Ranging or not based on OSC ... +bool IsOSCMarketRanging( + // + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double rangingThreshold, // Detect Ranging based On Power OSC ... + // + // OSC Specifications ... + const int foLen, // Fast OSC Length ... + const double foMul, // Fast OSC Multiplier ... + const int slLen, // Slow OSC Length ... + const double slMul // Slow OSC Multiplier ... +) { + // + bool result = false; + + // + // Detect Buffer Size ... + const int bufferSize = marketLen + bar_index; + double powerOSCBuffer[]; + ArraySetAsSeries( + powerOSCBuffer, + true + ); + ArrayResize( + powerOSCBuffer, + bufferSize + ); + + // + // Loop through Market for Extract PowerOSC from OSC Indicator ... + for (int i = bufferSize - 1; i >= 0; i--) { + // + // Retrieve OSC State at Specific Bar Index ... + XOSCState state = GetOSCState( + i, + foLen, + foMul, + slLen, + slMul + ); + + // + powerOSCBuffer[i] = state.powerOSC; + } + + // + // now we have to extract min and max value of Splitted Buffer ... + XMinMax minMax = GetBufferMinMax(powerOSCBuffer); + + // + // now Check Min and Max Direction and Compare them with Ranging Value ... + result = MathAbs(minMax.min) > rangingThreshold + || MathAbs(minMax.max) > rangingThreshold; + + // + return result; +} + +// +// Retrieve and Calculate XMA State ... +XMAState GetXMAState( + // + // Market Specification Inpouts ... + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + // XMA Inputs ... + const int scFastMul, // Short Cycle Fast Multiplier ... + const int scSlowMul, // Short Cycle Slow Multiplier ... + const int mcFastMul, // Medium Cycle Fast Multiplier ... + const int mcSlowMul, // Medium Cycle Slow Multiplier ... + const int lcFastMul, // Long Cycle Fast Multiplier ... + const int lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + const bool showSC, // Show Short Cycle + const bool showSCCrossLines, // Show Short Cycle Vertical Lines + const bool showMC, // Show Medium Cycle + const bool showMCCrossLines, // Show Medium Cycle Vertical Lines + const bool showLC, // Show Long Cycle + const bool showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + const color sxFastColor, // Short Cycle Fast Color ... + const color scSlowColor, // Short Cycle Slow Color ... + const color mcFastColor, // Medium Cycle Fast Color ... + const color mcSlowColor, // Medium Cycle Slow Color ... + const color lcFastColor, // Medium Cycle Fast Color ... + const color lcSlowColor // Medium Cycle Slow Color ... +) { + // + // Temp Result ... + XMAState result = {}; + + // + // START Reading Buffers ... + // + // + // Define BufferIndexes ... + int scFastBufIndex = 0; + int scSlowBufIndex = 1; + int mcFastBufIndex = 2; + int mcSlowBufIndex = 3; + int lcFastBufIndex = 4; + int lcSlowBufIndex = 5; + int midBufIndex = 6; + + // + // START Short Cycle ... + // + // + // Short Cycle Fast ... + double scFast = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + scFastBufIndex, // Buffer Index ... + bar_index + ); + result.scFast = scFast; + + // + // Short Cycle Previous Fast ... + double scFastPrev = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + scFastBufIndex, // Buffer Index ... + bar_index + 1 + ); + result.scFastPrev = scFastPrev; + + // + // Short Cycle Slow ... + double scSlow = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + scSlowBufIndex, // Buffer Index ... + bar_index + ); + result.scSlow = scSlow; + + // + // Short Cycle Previous Slow ... + double scSlowPrev = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + scSlowBufIndex, // Buffer Index ... + bar_index + 1 + ); + result.scSlowPrev = scSlowPrev; + // + // END Short Cycle ... + // + + // + // START Medium Cycle ... + // + // + // Medium Cycle Fast ... + double mcFast = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + mcFastBufIndex, // Buffer Index ... + bar_index + ); + result.mcFast = mcFast; + + // + // Medium Cycle Previous Fast ... + double mcFastPrev = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + mcFastBufIndex, // Buffer Index ... + bar_index + 1 + ); + result.mcFastPrev = mcFastPrev; + + // + // Medium Cycle Slow ... + double mcSlow = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + mcSlowBufIndex, // Buffer Index ... + bar_index + ); + result.mcSlow = mcSlow; + + // + // Medium Cycle Previous Slow ... + double mcSlowPrev = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + mcSlowBufIndex, // Buffer Index ... + bar_index + 1 + ); + result.mcSlowPrev = mcSlowPrev; + // + // END Medium Cycle ... + // + + // + // START Long Cycle ... + // + // + // Long Cycle Fast ... + double lcFast = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + lcFastBufIndex, // Buffer Index ... + bar_index + ); + result.lcFast = lcFast; + + // + // Long Cycle Previous Fast ... + double lcFastPrev = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + lcFastBufIndex, // Buffer Index ... + bar_index + 1 + ); + result.lcFastPrev = lcFastPrev; + + // + // Long Cycle Slow ... + double lcSlow = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + lcSlowBufIndex, // Buffer Index ... + bar_index + ); + result.lcSlow = lcSlow; + + // + // Long Cycle Previous Slow ... + double lcSlowPrev = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + lcSlowBufIndex, // Buffer Index ... + bar_index + 1 + ); + result.lcSlowPrev = lcSlowPrev; + // + // END Long Cycle ... + // + + // + // START Makret Middleage ... + // + // + // Market Middleage ... + double marketMiddleage = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + midBufIndex, // Buffer Index ... + bar_index + ); + result.marketMiddleage = marketMiddleage; + + // + // Previous Market Middleage ... + double marketMiddleagePrev = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + midBufIndex, // Buffer Index ... + bar_index + 1 + ); + result.marketMiddleagePrev = marketMiddleagePrev; + // + // END Makret Middleage ... + // + // + // END Reading Buffers ... + // + + // + return result; +} + +XMAOverView GetXMAOverView( + // + // Market Specification Inpouts ... + const int bar_index, // Bar Index ... + const int marketLen, // Market Length + // + // XMA Inputs ... + const int scFastMul, // Short Cycle Fast Multiplier ... + const int scSlowMul, // Short Cycle Slow Multiplier ... + const int mcFastMul, // Medium Cycle Fast Multiplier ... + const int mcSlowMul, // Medium Cycle Slow Multiplier ... + const int lcFastMul, // Long Cycle Fast Multiplier ... + const int lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + const bool showSC, // Show Short Cycle + const bool showSCCrossLines, // Show Short Cycle Vertical Lines + const bool showMC, // Show Medium Cycle + const bool showMCCrossLines, // Show Medium Cycle Vertical Lines + const bool showLC, // Show Long Cycle + const bool showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + const color sxFastColor, // Short Cycle Fast Color ... + const color scSlowColor, // Short Cycle Slow Color ... + const color mcFastColor, // Medium Cycle Fast Color ... + const color mcSlowColor, // Medium Cycle Slow Color ... + const color lcFastColor, // Medium Cycle Fast Color ... + const color lcSlowColor // Medium Cycle Slow Color ... +) { + // + XMAOverView result = {}; + + // + // Clear Arrays ... + ArrayFree(scTrendPowers); + ArrayFree(scTrendPowerTimes); + + // + ArrayFree(mcTrendPowers); + ArrayFree(mcTrendPowerTimes); + + // + ArrayFree(lcTrendPowers); + + // + scTrendPowerMin = 0; + scTrendPowerMax = 0; + + // + mcTrendPowerMin = 0; + mcTrendPowerMax = 0; + + // + lcTrendPowerMin = 0; + lcTrendPowerMax = 0; + + // + bool isSCFastCrossOverSlow = false; + bool isSCFastCrossUnderSlow = false; + + // + bool isMCFastCrossOverSlow = false; + bool isMCFastCrossUnderSlow = false; + + // + // Create a Loop for retrieveing info ... + int index = bar_index; + while ( + !(isSCFastCrossOverSlow + && isSCFastCrossUnderSlow + && isMCFastCrossOverSlow + && isMCFastCrossUnderSlow + ) + ) { + // + // Retrieve State of XMA ... + XMAState state = GetXMAState( + // + // Bar Index ... + index, // Bar Index ... + // + // Market Length ... + marketLen, // Market Length ... + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor // Medium Cycle Slow Color ... + ); + + // + // Filling Arrays ... + datetime time = iTime( + _Symbol, + _Period, + index + ); + + // + // START Short Cycle ... + // + // + int scTrendPowerSize = ArraySize(scTrendPowers); + if (bar_index > 0 && scTrendPowerSize == 0) { + // + int delta = bar_index; + ArrayResize( + scTrendPowers, + delta + ); + ArrayResize( + scTrendPowerTimes, + delta + ); + + // + // Fill Array by Zero ... + for (int i=0; i < bar_index; i++) { + scTrendPowers[i] = 0; + scTrendPowerTimes[i] = 0; + } + } else { + // + ArrayResize( + scTrendPowers, + scTrendPowerSize + 1 + ); + ArrayResize( + scTrendPowerTimes, + scTrendPowerSize + 1 + ); + } + + // + double scTPower = MathAbs(state.scFast - state.scSlow); + scTrendPowers[index] = scTPower; + scTrendPowerTimes[index] = time; + + // + // Calculate Min and Max ... + scTrendPowerMin = + scTrendPowerMin == 0 + || scTPower < scTrendPowerMin + ? + scTPower + : + scTrendPowerMin; + scTrendPowerMax = + scTPower > scTrendPowerMax ? + scTPower : + scTrendPowerMax; + + // + // Check Cross Over ... + if (!isSCFastCrossOverSlow) { + // + isSCFastCrossOverSlow = + state.scFast > state.scSlow + && !(state.scFastPrev > state.scSlowPrev); + } + + // + // Check Cross Under ... + if (!isSCFastCrossUnderSlow) { + // + isSCFastCrossUnderSlow = + state.scFast < state.scSlow + && !(state.scFastPrev < state.scSlowPrev); + } + // + // END Short Cycle ... + // + + // + // START Medium Cycle ... + // + // + int mcTrendPowerSize = ArraySize(mcTrendPowers); + if (bar_index > 0 && mcTrendPowerSize == 0) { + // + int delta = bar_index; + ArrayResize( + mcTrendPowers, + delta + ); + ArrayResize( + mcTrendPowerTimes, + delta + ); + + // + // Fill Array by Zero ... + for (int i=0; i < bar_index; i++) { + mcTrendPowers[i] = 0; + mcTrendPowerTimes[i] = 0; + } + } else { + // + ArrayResize( + mcTrendPowers, + mcTrendPowerSize + 1 + ); + ArrayResize( + mcTrendPowerTimes, + mcTrendPowerSize + 1 + ); + } + + // + double mcTPower = MathAbs(state.mcFast - state.mcSlow); + mcTrendPowers[index] = mcTPower; + mcTrendPowerTimes[index] = time; + + // + // Calculate Min and Max ... + mcTrendPowerMin = + mcTrendPowerMin == 0 + || mcTPower < mcTrendPowerMin + ? + mcTPower + : + mcTrendPowerMin; + mcTrendPowerMax = + mcTPower > mcTrendPowerMax ? + mcTPower : + mcTrendPowerMax; + + // + // Check Cross Over ... + if (!isMCFastCrossOverSlow) { + // + isMCFastCrossOverSlow = + state.mcFast > state.mcSlow + && !(state.mcFastPrev > state.mcSlowPrev); + } + + // + // Check Cross Under ... + if (!isMCFastCrossUnderSlow) { + // + isMCFastCrossUnderSlow = + state.mcFast < state.mcSlow + && !(state.mcFastPrev < state.mcSlowPrev); + } + // + // END Medium Cycle ... + // + + // + // START Long Cycle ... + // + // + int lcTrendPowerSize = ArraySize(lcTrendPowers); + if (bar_index > 0 && lcTrendPowerSize == 0) { + // + int delta = bar_index; + ArrayResize( + lcTrendPowers, + delta + ); + + // + // Fill Array by Zero ... + for (int i=0; i < bar_index; i++) { + lcTrendPowers[i] = 0; + } + } else { + // + ArrayResize( + lcTrendPowers, + lcTrendPowerSize + 1 + ); + } + + // + double lcTPower = MathAbs(state.lcFast - state.lcSlow); + lcTrendPowers[index] = lcTPower; + + // + // Calculate Min and Max ... + lcTrendPowerMin = + lcTrendPowerMin == 0 + || lcTPower < lcTrendPowerMin + ? + lcTPower + : + lcTrendPowerMin; + lcTrendPowerMax = + lcTPower > lcTrendPowerMax ? + lcTPower : + lcTrendPowerMax; + // + // END Long Cycle ... + // + + // + // Fill Calculations ... + + + // + index++; + } + + // + return result; +} + +// +// Retrieve XADX State ... +XADXState GetADXState( + // + const int bar_index, // Bar Index ... + // + const int marketLen // Market Length ... +) { + // + // Temp Result ... + XADXState result = {}; + + // + // Define Buffer Index ... + int adxBufferIndex = 0; + int positiveBufferIndex = 1; + int negativeBufferIndex = 2; + + // + ENUM_APPLIED_PRICE appliedPrice = PRICE_WEIGHTED; + + // + // START Recieve Buffers ... + // + // + // TRENDPOWER ... + double trendPower = iCustom( + // + // Global Data ... + _Symbol, + _Period, + // + // Indicator Name ... + adxIndicatorName, + // + // Indicator Inputs ... + marketLen, // Averaging Period ... + appliedPrice, // Averaging Applied Price ... + // + // Buffer Index + adxBufferIndex, // ADX Trend Power Buffer Index ... + // + // Shift or Bar Index ... + bar_index + ); + result.trendPower = trendPower; + + // + // TRENDPOWER Prev ... + double trendPowerPrev = iCustom( + // + // Global Data ... + _Symbol, + _Period, + // + // Indicator Name ... + adxIndicatorName, + // + // Indicator Inputs ... + marketLen, // Averaging Period ... + appliedPrice, // Averaging Applied Price ... + // + // Buffer Index + adxBufferIndex, // ADX Trend Power Buffer Index ... + // + // Shift or Bar Index ... + bar_index + 1 + ); + result.trendPowerPrev = trendPowerPrev; + + // + // UP Dir ... + double upDirection = iCustom( + // + // Global Data ... + _Symbol, + _Period, + // + // Indicator Name ... + adxIndicatorName, + // + // Indicator Inputs ... + marketLen, // Averaging Period ... + appliedPrice, // Averaging Applied Price ... + // + // Buffer Index + positiveBufferIndex, // Up Direction Buffer Index ... + // + // Shift or Bar Index ... + bar_index + ); + result.upDirection = upDirection; + + // + // UP Dir Prev ... + double upDirectionPrev = iCustom( + // + // Global Data ... + _Symbol, + _Period, + // + // Indicator Name ... + adxIndicatorName, + // + // Indicator Inputs ... + marketLen, // Averaging Period ... + appliedPrice, // Averaging Applied Price ... + // + // Buffer Index + positiveBufferIndex, // Up Direction Buffer Index ... + // + // Shift or Bar Index ... + bar_index + 1 + ); + result.upDirectionPrev = upDirectionPrev; + + // + // DOWN Dir ... + double downDirection = iCustom( + // + // Global Data ... + _Symbol, + _Period, + // + // Indicator Name ... + adxIndicatorName, + // + // Indicator Inputs ... + marketLen, // Averaging Period ... + appliedPrice, // Averaging Applied Price ... + // + // Buffer Index + negativeBufferIndex, // Down Direction Buffer Index ... + // + // Shift or Bar Index ... + bar_index + ); + result.downDirection = downDirection; + + // + // DOWN Dir Prev ... + double downDirectionPrev = iCustom( + // + // Global Data ... + _Symbol, + _Period, + // + // Indicator Name ... + adxIndicatorName, + // + // Indicator Inputs ... + marketLen, // Averaging Period ... + appliedPrice, // Averaging Applied Price ... + // + // Buffer Index + negativeBufferIndex, // Down Direction Buffer Index ... + // + // Shift or Bar Index ... + bar_index + 1 + ); + result.downDirectionPrev = downDirectionPrev; + // + // END Recieve Buffers ... + // + + // + // Calculations ... + + // + bool isUpTrend = upDirection > downDirection + && upDirectionPrev > downDirectionPrev; + result.isUpTrend = isUpTrend; + + // + bool isDownTrend = upDirection < downDirection + && upDirectionPrev < downDirectionPrev; + result.isDownTrend = isDownTrend; + + // + return result; +} + +// +// Calculate Fib Level ... +double GetFibonacciLevel( + double upPrice, + double downPrice, + double level, + X_DIRECTION direction +) { + // + double ling = upPrice - downPrice; + double pLevel = (ling / 100) * (level * 100); + + // + double result = direction == X_UP ? + upPrice - pLevel : + downPrice + pLevel; + result = NormalizeDouble(result, _Digits); + + // + return result; +} +// +// END Global Requirement Functions ... +// + +// +// START Signal Related Functions ... +// +// +// Calculate Signal ... +// in this function we calculate a signal exists in +// specific bar or not ... +XSignalRequest CalculateSignal( + // + const int bar_index, // Bar Index ... + // + // MARKET Specifications ... + const int marketLen, // Market Length ... + const double r2r, // Risk To Reward Ratio ... + // + // XMA Inputs ... + // + const int scFastMul, // Short Cycle Fast Multiplier ... + const int scSlowMul, // Short Cycle Slow Multiplier ... + const int mcFastMul, // Medium Cycle Fast Multiplier ... + const int mcSlowMul, // Medium Cycle Slow Multiplier ... + const int lcFastMul, // Long Cycle Fast Multiplier ... + const int lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + const bool showSC, // Show Short Cycle + const bool showSCCrossLines, // Show Short Cycle Vertical Lines + const bool showMC, // Show Medium Cycle + const bool showMCCrossLines, // Show Medium Cycle Vertical Lines + const bool showLC, // Show Long Cycle + const bool showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + const color sxFastColor, // Short Cycle Fast Color ... + const color scSlowColor, // Short Cycle Slow Color ... + const color mcFastColor, // Medium Cycle Fast Color ... + const color mcSlowColor, // Medium Cycle Slow Color ... + const color lcFastColor, // Medium Cycle Fast Color ... + const color lcSlowColor, // Medium Cycle Slow Color ... + // + // OSC Inputs ... + const int fastOSCLen, // FastOSC Length ... + const double fastOSCMul, // FastOSC Multiplier ... + const int slowOSCLen, // SlowOSC Length ... + const double slowOSCMul, // SlowOSC Multiplier ... + const double minPowOSC, // Minimum Signal Power ... + const double minVarOSC, // Minimum Var Power ... + // + // ZIGZAG Inputs ... + const int zDev, // ZigZag Deviation ... + const int zBkStep // ZigZag Back Step ... +) { + // + // create temp result ... + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_NONE; + + // + XSignal signal = {}; + + // + // Retrieve ZigZag State ... + + // + // START Capturing Signal ... + // + // + // START Retrieve Statets ... + // + // Reading Oscillator State ... + oscState = GetOSCState( + bar_index, + fastOSCLen, + fastOSCMul, + slowOSCLen, + slowOSCMul + ); + + // + // Retrieve ZigZag State ... + zigZagState = GetZigZagState( + bar_index, + marketLen, + zDev, + zBkStep + ); + + // + zigZagOverView = GetZigZagOverView(); + + // + // Retrieve Market Trend ... + xmaState = GetXMAState( + // + // Bar Index ... + bar_index, // Bar Index ... + // + // Market Length ... + marketLen, // Market Length ... + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor // Medium Cycle Slow Color ... + ); + + // + xmaOverview = GetXMAOverView( + // + // Bar Index ... + bar_index, // Bar Index ... + // + // Market Length ... + marketLen, // Market Length ... + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor // Medium Cycle Slow Color ... + ); + + // + // Retrieve ADX State ... + adxState = GetADXState( + // + bar_index, // Bar Index ... + // + marketLen // Market Length ... + ); + // + // END Retrieve Statets ... + // + + // + // START States Calculations ... + // + // + // START PRICE Calculations ... + // + RefreshRates(); + + // + double candleLow = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double candleHigh = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + // LONG Prices ... + double longEntryPrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK); + double longClosePrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); + double longPriceGap = longClosePrice - longEntryPrice; + + // + // SHORT Prices ... + double shortEntryPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); + double shortClosePrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK); + double shortPriceGap = shortEntryPrice - shortClosePrice; + // + // END PRICE Calculations ... + // + + // + // START LONG Signals ... + // + bool hasLongSignal = false; + + // + // XMA Based Signals ... + hasLongSignal = + // + // XMA ... + // + // SC Fast Cross Over Market Middleage ... + xmaState.scFast > xmaState.marketMiddleage + && !(xmaState.scFastPrev > xmaState.marketMiddleage) + // + // when Short Cycle is Trending Up ... + && xmaState.scFast > xmaState.scSlow + && xmaState.scFastPrev > xmaState.scSlowPrev + // + // When Medium Cycle is Trending Up ... + && xmaState.mcFast > xmaState.mcSlow + && xmaState.mcFastPrev > xmaState.mcSlowPrev + // + // and Medium Cycle TrendPower is Going Up ... + && MathAbs(xmaState.mcFast - xmaState.mcSlow) > + MathAbs(xmaState.mcFastPrev - xmaState.mcSlowPrev) + // + // When Long Cycle is Trending Up ... + && xmaState.lcFast > xmaState.lcSlow + && xmaState.lcFastPrev > xmaState.lcSlowPrev + // + // and Long Cycle TrendPower is Going Up ... + && MathAbs(xmaState.lcFast - xmaState.lcSlow) > + MathAbs(xmaState.lcFastPrev - xmaState.lcSlowPrev) + // + // Short Cycle Slow bigger thhan Medium Cycle Fast ... + && xmaState.scSlow > xmaState.mcFast + // + // OSC ... + // Check OSC Fast and Slow is Less than 0.5 ... + && oscState.fastOSC < 0.5 + && oscState.slowOSC < 0.5 + && oscState.fastOSCPrev < 0.5 + && oscState.slowOSCPrev < 0.5 + && oscState.fastOSC > oscState.fastOSCPrev + // + // Check OSC Minimum Signal Power ... + // this Helps for Detect Market exits from Ranging ... + && minPowOSC > 0 + ? + // + // Check Conditions only if value provided ... + oscState.powerOSCPrev < 0 + && MathAbs(oscState.powerOSCPrev) > minPowOSC + : + // + // ... other wise, ignore ... + true + // + // Check Previous Candle Signal Power must be Lower than + // Current Signal Power and the Direction Must be Up Trend ... + && oscState.powerOSCPrev < oscState.powerOSC + // + // Also we Have to Check Market not ranging ... + && !IsOSCMarketRanging( + bar_index + 1, + marketLen, + minPowOSC, + fastOSCLen, + fastOSCMul, + slowOSCLen, + slowOSCMul + ) + // + // ZIGZAG ... + && zigZagState.isWaitForTrendDown + && !zigZagState.isWaitForTrendUp + // + // XADX ... + // TODO: add XADX Base Conditions for Long Trades ... + // When ADX Trend Power bigger than 20 and less than 50 ... + && !adxState.trendPower < 23 + && !adxState.trendPowerPrev < 23 + // + // Check Trend Direction for Signals ... + && adxState.upDirection > adxState.downDirection + && adxState.upDirectionPrev > adxState.downDirectionPrev + // && adxState.trendPower < 50 + // && adxState.trendPower > adxState.trendPowerPrev + // + // PRICE Checking ... + // price must be less than Candle High at openning time ... + && longEntryPrice <= candleHigh + // + // also Candle High and Low must be above than lc Fast & lc Slow ... + && longEntryPrice > xmaState.lcFast + && longEntryPrice > xmaState.lcSlow + && ( + !IsSharpBullishHappens( + bar_index, + marketLen * 2 + ) + || IsSharpBearishHappens( + bar_index, + marketLen * 2 + ) + ) + ; + // + // END LONG Signals ... + // + + // + // START SHORT Signals ... + // + bool hasShortSignal = false; + + // + // Recieve Signals Based on XOSC ... + // hasShortSignal = + // oscState.hasShortSignal + // ; + // + // END SHORT Signals ... + // + + // + // Check Signal Exists regardless of Long or Short ... + bool hasSignal = hasLongSignal || hasShortSignal; + + // + // Prevent from Going forward if there is not a Signal ... + if (!hasSignal) { + // + result.signal = signal; + return result; + } + + // + totalSignals++; + + // + // Define Price Related Variables ... + // + double price = 0; + double priceGap; + double sl = 0; + double risk; + double reward; + double tp = 0; + double r2rRatio = r2r; + + // + datetime time = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Fill Signal Related Variables ... + if (hasLongSignal) { + // + totalLongSignals++; + + // + price = longEntryPrice; + priceGap = longPriceGap; + + // // + // // Setting Up SL Based on Prev Candle ... + // sl = prevCandleLow; + + // + // Setting Up SL Based on Last Market Lowest ... + sl = GetMarketLowestLow( + bar_index, + marketLen + ); + + // // + // // Setting Up SL Based on Prev Candle Less Low Price ... + // sl = GetLowLessCandlePrice( + // bar_index, + // price + // ); + + // + // Check if ZigZag shows TrendUp increase r2rRatio ... + if ( + ( + xmaState.marketMiddleage < highs[0] + && xmaState.marketMiddleage > candleLow + ) + || ( + zigZagOverView.isTrendUp + && !zigZagOverView.isTrendDown + ) + ) { + // + r2rRatio = r2r + (r2r * 0.6); + } + + // + risk = price - sl; + reward = risk * r2rRatio; + tp = price + reward; + + // + // Check TP Based On ZigZag High .. + if ( + tp > zigZagState.high + && !zigZagOverView.isTrendUp + ) { + tp = zigZagState.high - (5 * _Point); + } + + // + // Check TP based on Spread ... + if (tp < price + priceGap) { + tp = tp + priceGap; + } + } else if (hasShortSignal) { + // + totalShortSignals++; + + // + price = shortEntryPrice; + priceGap = shortPriceGap; + + // // + // // Setting Up SL Based On Prev Candle ... + // sl = prevCandleHigh; + + // // + // // Setting Up SL Based on Last Market Highest ... + // sl = GetMarketHighestHigh( + // bar_index, + // marketLen + // ); + + // + // Setting Up SL Based on Prev Candle Great High Price ... + sl = GetHighGreatCandlePrice( + bar_index, + price + ); + + // + risk = sl - price; + reward = risk * r2r; + tp = price - reward; + } + + // + // Normalize Prices ... + price = NormalizeDouble(price, _Digits); + sl = NormalizeDouble(sl, _Digits); + tp = NormalizeDouble(tp, _Digits); + + // + // Generate Signal Structure ... + signal.type = hasLongSignal ? + X_LONG : + X_SHORT; + signal.tp = tp; + signal.sl = 0; // sl; + signal.time = time; + signal.symbol = _Symbol; + signal.entryPrice = price; + signal.id = totalLongSignals; + // + // END Capturing Signal ... + // + + // + // Fill Result ... + result.hasSignal = hasSignal; + result.signal = signal; + result.type = signal.type; + + // + return result; +} + +// +// START Signal Verification Functions ... +// +// +// END Signal Verification Functions ... +// + +// +// START Market State Functions ... +// +// +// END Market State Functions ... +// + +// +// Retrieve Signal Bar Index ... +int GetSignalBarIndex(XSignal &signal) { + // + // Temp Result ... + int result = -1; + + // + // Retriev Signal Bar Index ... + result = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + return result; +} + +// +// Generate a Unique ID for Signal ... +string GenerateSignalTAG( + const XSignal &signal, + const string tag, + const string longSignalLabel, + const string shortSignalLabel +) { + // + // Generate Propper Label for Signal ... + string label = signal.type == X_LONG ? longSignalLabel : signal.type == X_SHORT ? shortSignalLabel : "UN_KNOWN"; + + // + // Generate Unique String Identifier for Signal ... + string result = tag + + "_[ID:" + IntegerToString(signal.id) + "]" + + "_[" + label + "]" + + "_[" + signal.symbol + "]" + + "_[Time:" + TimeToStr(signal.time) + "]" + + "_[TP:" + DoubleToString(signal.tp) + "]" + + "_[SL:" + DoubleToString(signal.sl) + "]"; + + // + return result; +} + +// +// Draw Signal Shapes on Chart ... +bool DrawSignal( + const XSignal &signal, + long chartID = 0, + int subWindowID = 0, + const double positionThresholdFactor = 10, + string signalTag = "X-Signal", + string longSignalLabel = "X-Long", + color longSignalColor = clrAqua, + string shortSignalLabel = "X-Short", + color shortSignalColor = clrFuchsia +) { + // + // Generate isLongSignal Var ... + bool isLongSignal = signal.type == X_LONG; + + // + // Signal Bar Index ... + int bar_index = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // START Draw Signal Arrow ... + // + // + // Arrow Shape Name ... + string arrowName = StringConcatenate(signalTag, "_Arrow_", signal.id); + + // + // Arrow Price ... + double arrowPrice = 0; + if (isLongSignal) { + // + arrowPrice = iLow( + _Symbol, + _Period, + bar_index + ); + + // + arrowPrice = arrowPrice - (positionThresholdFactor * _Point); + } else { + // + arrowPrice = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + arrowPrice = arrowPrice + (positionThresholdFactor * _Point); + } + + // + // Arrow Code ... + uchar arrowCode = isLongSignal ? SYMBOL_ARROWUP : SYMBOL_ARROWDOWN; + + // + // Arrow Anchor Point ... + ENUM_ARROW_ANCHOR arrowAnchorPoint = isLongSignal ? ANCHOR_BOTTOM : ANCHOR_TOP; + + // + // Arrow Color ... + color arrowColor = isLongSignal ? longSignalColor : shortSignalColor; + + // + // Draw Signal Arrow Shape ... + bool result = DrawArrow( + chartID, + arrowName, + subWindowID, + signal.time, + arrowPrice, + arrowCode, + arrowAnchorPoint, + arrowColor, + STYLE_SOLID, + 3, + false, + false, + false, + 0 + ); + // + // END Draw Signal Arrow ... + // + + // + // START Draw Signal SL/TP ... + // + string slLineName = StringConcatenate(signalTag, "_SL_", signal.id); + string tpLineName = StringConcatenate(signalTag, "_TP_", signal.id); + string entryLineName = StringConcatenate(signalTag, "_ENTRY_", signal.id); + + // + color slColor = shortSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color tpColor = longSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color entryColor = clrGreen; + + // + datetime time1 = iTime( + _Symbol, + _Period, + bar_index + 1 + ); + + // + // Draw Enrty Price ... + result = DrawTrendLine( + chartID, + entryLineName, + subWindowID, + time1, + signal.entryPrice, + signal.time, + signal.entryPrice, + entryColor, + STYLE_SOLID, + 2 + ); + + // + // Draw Signal SL ... + if (signal.sl > 0) { + // + result = DrawTrendLine( + chartID, + slLineName, + subWindowID, + time1, + signal.sl, + signal.time, + signal.sl, + slColor, + STYLE_SOLID, + 2 + ); + } + + // + // Draw Signal TP ... + if (signal.tp > 0) { + // + result = DrawTrendLine( + chartID, + tpLineName, + subWindowID, + time1, + signal.tp, + signal.time, + signal.tp, + tpColor, + STYLE_SOLID, + 2 + ); + } + // + // END Draw Signal SL/TP ... + // + + // + // Start Draw Signal Label ... + // + // + string labelName = StringConcatenate(signalTag, "_Label_", signal.id); + + // + double labelPrice = isLongSignal ? arrowPrice - (positionThresholdFactor * _Point) : arrowPrice + (positionThresholdFactor * _Point); + + // + string labelText = isLongSignal ? longSignalLabel : shortSignalLabel; + + // + result = DrawText( + chartID, + labelName, + subWindowID, + signal.time, + labelPrice, + labelText, + "Arial", + 10, + arrowColor, + 0, + ANCHOR_CENTER + ); + // + // End Draw Signal Label ... + // + + // + return result; +} + +// +// Trade on Specific Signal ... +bool TradeSignal( + XSignal &signal, + // + string prefix, + // + double volumePercent, + // + // Long ... + const string longSignalLabel, + const color longSignalColor, + // + // Short ... + const string shortSignalLabel, + const color shortSignalColor +) { + // + // Temp Result ... + bool result = false; + + // + if (initialBalance == 0) { + initialBalance = AccountInfoDouble(ACCOUNT_BALANCE); + } + + // + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + int openPositions = CountOpenTrades(); + double volume = (volumePercent * initialBalance); + + // + if ( + signal.type != X_LONG && + signal.type != X_SHORT + ) { + return result; + } + + // + bool hasLongSignal = signal.type == X_LONG; + + // + // Check TP and Entry Price ... + if ( + ( + hasLongSignal + && signal.entryPrice > signal.tp + ) || + ( + !hasLongSignal + && signal.entryPrice < signal.tp + ) + ) { + return result; + } + + // + // Order Operation ... + int operation = hasLongSignal ? + OP_BUY : + OP_SELL; + + // + // Detect Trade Color ... + color clr = hasLongSignal ? + longSignalColor : + shortSignalColor; + + // + // Generate Signal Comment ... + string label = hasLongSignal ? + longSignalLabel : + shortSignalLabel; + + // + // Generate Signal Comment ... + string comment = StringConcatenate( + prefix, + "_", signal.id, "_", + label + ); + + // + // Placing Order ... + int orderTicket = OrderSend( + _Symbol, + operation, + volume, + signal.entryPrice, + 3, + signal.sl, + signal.tp, + comment, + signal.id, + 0, + clr + ); + + // + // Draw Signal Shape if Order Opened Successfully ... + if (orderTicket >= 0) { + // + // Here i must to Draw Signal Shapes ... + DrawSignal( + signal, + 0, + 0, + 50, + prefix, // Signal Tag ... + longSignalLabel, // Long Signal Label ... + longSignalColor, + shortSignalLabel, // Short Signal Label ... + shortSignalColor + ); + + // + result = true; + } + + // + return result; +} +// +// END Signal Related Functions ... +// + +// +// START Orders Functions ... +// +// +// Convert To XSignal Model ... +XSignal OrderToSignal() { + // + // Temp Result ... + XSignal result = {}; + result.type = X_NONE; + + // + // Here we can get some usefull info based on selected order ... + double swap = OrderSwap(); + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + int magicNumber = OrderMagicNumber(); + double takeProfit = OrderTakeProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // Conver Position to Signal ... + result.sl = stopLoss; + result.tp = takeProfit; + result.time = openTime; + result.symbol = _Symbol; + result.id = magicNumber; + result.entryPrice = openPrice; + result.type = isLongOrder ? X_LONG : X_SHORT; + + // + return result; +} + +// +// START Count Orders ... +// +// +// Count Open Positions ... +int CountOpenTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if (OrderSymbol() == _Symbol) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Long Positions ... +int CountOpenLongTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_BUY + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Short Positions ... +int CountOpenShortTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_SELL + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} +// +// END Count Orders ... +// + +// +// START Close Orders ... +// +// +// Close All Open Trades ... +bool CloseAllTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + + // + return result; +} + +// +// Close All Open Long Trades ... +bool CloseAllLongTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Long Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Short Trades ... +bool CloseAllShortTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (!isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Short Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In Profit Trades ... +bool CloseAllInProfitTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if (profit > 0) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InProfit Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Long Time Trades ... +bool CloseAllLongTimeTrades( + const int passedCandles +) { + // + bool result = false; + + // + if (passedCandles <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + + // + if ( + openBarIndex - currentBarIndex >= passedCandles + || ( + profit > 0.5 + && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 3) + ) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Long Time issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close all trades which passed Maximum Drawdown ... +bool CloseAllMaximumDrawDownPassedTrades( + const double maxDrDownPercentPerPTrade +) { + // + if ( + initialBalance <= 0 + || maxDrDownPercentPerPTrade <= 0 + ) { + return false; + } + + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double maxAllowedDrawDown = -1 * (initialBalance * maxDrDownPercentPerPTrade); + + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + if ( + profit < 0 + && MathAbs(profit) >= MathAbs(maxAllowedDrawDown) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Maximum DarwDown issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} +// +// END Close Orders ... +// +// +// END Orders Functions ... +// diff --git a/Bkp/Used/OSC EA 14020414/Experts/x-saherelm.osc.ea.mq4 b/Bkp/Used/OSC EA 14020414/Experts/x-saherelm.osc.ea.mq4 new file mode 100644 index 0000000..36d1e89 --- /dev/null +++ b/Bkp/Used/OSC EA 14020414/Experts/x-saherelm.osc.ea.mq4 @@ -0,0 +1,695 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XST_OSC Strategy Expert Advisor +// --------------------------------------------- +// saherelm implementation of strategy expert advisor ... +// +// ShortName: XST_OSC +// +// 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 XST_OSC Strategy Expert Advisor" +#property strict + +// +// START Inputs ... +// +// +// Signal Prefixe ... +input string signalPrefix = "XST_OSC"; // Signal Prefix + +// +// Signal Draw Specifications ... +input string bullishSignalLabel = "X_BUY"; // Bullish Signal Label +input color bullishSignalColor = clrAqua; // Bullish Signal Color + +// +input string bearishSignalLabel = "X_SELL"; // Bearish Signal Label +input color bearishSignalColor = clrFuchsia; // Bearish Signal Color + +// +input color signalEntryColor = clrAquamarine; // Signal Entry Ptice Color +input color signalSLColor = clrRed; // Signal SL Color +input color signalTPColor = clrGreen; // Signal TP Color + +// +// Trade ... +input bool allowTrade = true; // Allow Trade Based on given Signals +input bool allowLongTrades = true; // Allow Long Trades +input bool allowShortTrades = false; // Allow Short Trades + +// +// Market Specification Inpouts ... +input int marketLength = 7; // Market Length +input double riskToRewardRatio = 1.5; // Risk to Reward Ratio + +// +// Alerts ... +input bool alertEvents = true; // Alert Events +input bool alertPositions = true; // Alert Positions +input bool longPositionAlerts = true; // Alert Long Positions +input bool shortPositionAlerts = true; // Alert Short Positions + +// +// Alert Types ... +input bool terminalAlert = false; // Terminal Alert +input bool pushAlert = false; // Push Notification Alerts + +// +// Balance and Finanical Specifications ... +input double lotsPerTradePercent = 0.00001; // Lots Per Trade Percent +input int maxOpenTrades = 4; // Maximum Open Trade +input double maxDrawdownPercentPerPTrade = 0.05; // Maximum DrawDown Per Trade +input double minBalancePercent = 0.5; // Minimum Balance for Trading +input double maxEquityPercent = 0.1; // Maximum Trade Equity +input int closeAllOpenTradesAfterCandle = 480; // Close All Open Trades After Passed Candles +input bool closeAllInProfitOpenTradesWhenMaxOpenTradesReached = true; // Close All In Profit Open Trades When Max Open Trades Reached and New Signal Income + +// +// OSC Inputs ... +// +// FastOSC ... +// Short Cycle (Fast OSC) ... +input int fastOSCLength = 10; // FastOSC Length +input double fastOSCMultiplier = 1.0; // FastOSC Multiplier + +// +// SlowOSC ... +// Medium Cycle (Slow OSC) ... +input int slowOSCLength = 30; // SlowOSC Length +input double slowOSCMultiplier = 3.0; // SlowOSC Multiplier + +// +// Power OSC ... +input double minPowerOSC = 0.04; // Minimum Signal Power + +// +// Variance OSC ... +input double minVarianceOSC = 0; // Minimum Var Power + +// +// ZIGZAG Inputs ... +input int zDeviation = 5; // ZigZag Deviation +input int zBackStep = 3; // ZigZag Back Step + +// +// XMA Inputs ... +// +input double step = 0.02; // SAR Step +input double maximum = 0.2; // SAR Maximum +input int shortCycleFastMultiplier = 1; // Short Cycle Fast Multiplier +input int shortCycleSlowMultiplier = 4; // Short Cycle Slow Multiplier +input int mediumCycleFastMultiplier = 7; // Medium Cycle Fast Multiplier +input int mediumCycleSlowMultiplier = 14; // Medium Cycle Slow Multiplier +input int longCycleFastMultiplier = 70; // Long Cycle Fast Multiplier +input int longCycleSlowMultiplier = 140; // Long Cycle Slow Multiplier +// +// Show/Hide Inputs ... +input bool showPSar = true; // Show Parabolic Sar +input bool showShortCycle = false; // Show Short Cycle +input bool showShortCycleCrossLines = false; // Show Short Cycle Vertical Lines +input bool showMediumCycle = true; // Show Medium Cycle +input bool showMediumCycleCrossLines = false; // Show Medium Cycle Vertical Lines +input bool showLongCycle = false; // Show Long Cycle +input bool showLongCycleCrossLines = false; // Show Long Cycle Vertical Lines +// +// Color Inputs ... +input color pSarColor = clrCornflowerBlue; // Parabolic Sar Color +input color shortCycleFastColor = clrGreen; // Short Cycle Fast Color ... +input color shortCycleSlowColor = clrRed; // Short Cycle Slow Color ... +input color mediumCycleFastColor = clrAqua; // Medium Cycle Fast Color ... +input color mediumCycleSlowColor = clrFuchsia; // Medium Cycle Slow Color ... +input color longCycleFastColor = clrGoldenrod; // Medium Cycle Fast Color ... +input color longCycleSlowColor = clrBrown; // Medium Cycle Slow Color ... +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +int lastSignalledBar = 0; + +// +bool waitForLongSignals = true; +bool closeLongTrades = false; + +// +bool waitForShortSignals = true; +bool closeShortTrades = false; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.osc.signal.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Validate Inputs ... + bool inputsNotValiid = + // + // MARKET ... + marketLength < 0 + || riskToRewardRatio < 0 + // + // EA ... + || lotsPerTradePercent < 0 + || maxOpenTrades <= 0 + || maxDrawdownPercentPerPTrade < 0 + || minBalancePercent < 0 + || maxEquityPercent < 0 + || marketLength < 0 + // + // OSC ... + || fastOSCLength < 0 + || fastOSCMultiplier < 0 + || slowOSCLength < 0 + || slowOSCMultiplier < 0 + || minPowerOSC < 0 + || minVarianceOSC < 0 + || slowOSCLength <= fastOSCLength + // + // ZIGZAG ... + || zDeviation < 0 + || zBackStep < 0 + || zBackStep >= marketLength + // + // XMA ... + // + // Validate Short Cycle ... + || shortCycleFastMultiplier <= 0 + || shortCycleSlowMultiplier <= 0 + || shortCycleFastMultiplier >= shortCycleSlowMultiplier + // + // Validate Medium Cycle ... + || mediumCycleFastMultiplier <= 0 + || mediumCycleSlowMultiplier <= 0 + || mediumCycleFastMultiplier >= mediumCycleSlowMultiplier + // + // Validate Long Cycle ... + || longCycleFastMultiplier <= 0 + || longCycleSlowMultiplier <= 0 + || longCycleFastMultiplier >= longCycleSlowMultiplier + // + // Validate Series of Multipliers ... + || shortCycleFastMultiplier >= mediumCycleFastMultiplier + || mediumCycleFastMultiplier >= longCycleFastMultiplier + ; + + if (inputsNotValiid) { + return INIT_PARAMETERS_INCORRECT; + } + + // + totalSignals = 0; + totalLongSignals = 0; + totalShortSignals = 0; + + // + initialBalance = 0; + + // + // START Define Array Series ... + // + // + // END Define Array Series ... + // + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST_OSC"; + + // // + // // Set Event Timer on One Seccond ... + // bool isEventSet = EventSetTimer(1); + // if (!isEventSet) { + // LogMessage("Error: " + GetLastError()); + // return INIT_FAILED; + // } + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + // Killing Event Timer ... + EventKillTimer(); +} + +// +// Ticker Event Handler ... +void OnTick() { + // + // Checking State for Signal Handling ... + CheckState(); + + // + // Process Signals to Open Positions ... + ProcessSignals(); + + // + // Process Open Positions for Trailing Stop Loss or Close ... + ProcessOpenPositions(); +} + +// +// Timer Event Handler ... +void OnTimer() { + // + CheckState(); + + // + ProcessOpenPositions(); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Check State for Signal Handling ... +void CheckState() { + // + // Here we Must to Check Market State in Big Picture ... + + // + // Prevent from Checking, if there is no states available ... + if (ArraySize(xmaStates) == 0) { + return; + } + + // + // TODO: Determines Where and How close Long Trades on Trend Reversal Points ... + closeLongTrades = + false + // + // Check When Parabolic SAR Reverse Direction Happens ... + // || ( + // isParabolicCrossOverMarketMiddle + // && !isMCTrendUp + // ) + ; + + // + waitForLongSignals = + true + // waitForLongSignals + // ? + // // + // // Usually Conditions ... + // // Chanege to False ... + // isMCTrendUp + // && isSCTrendUp + // : + // // + // // Reverse Come Back Conditions ... + // // Change to True ... + // isMCFastCrossOverSlow + // || isSCFastCrossUnderSlow + ; +} + +// +// Calculate Signals and Process Based on Exists Signals ... +void ProcessSignals() { + // + XSignalRequest request = {}; + request.type = X_NONE; + request.hasSignal = false; + + // + // Prevent Multiple Calculating on Same Bars ... + isNewBar = IsNewBar(); + if (isNewBar) { + // + countedBars++; + } + + // + bool allowDoTrade = true; + + // + // Check Balance ... + if (initialBalance > 0) { + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double minimumBalanceForTrade = + balance > initialBalance + ? + minBalancePercent * balance + : + minBalancePercent * initialBalance; + + // + // Retrieve Account Equity ... + double equity = AccountInfoDouble(ACCOUNT_EQUITY); + double maxAllowedEquity = balance - (balance * maxEquityPercent); + + // + // Retrieve Free Marigin ... + double freeMargin = AccountFreeMargin(); + double maximumMariginRisk = balance - (balance * maxEquityPercent); + + // + if ( + // + // Do not Open Positions if equity not passed ... + equity < maxAllowedEquity || + // + // Do not Open Positions if free margin not passed ... + freeMargin <= maximumMariginRisk || + // + // Do not open positions if balance less than minimum ... + balance <= minimumBalanceForTrade + ) { + // + allowDoTrade = false; + + // // + // string message = StringConcatenate( + // "Trading Pause => ", + // "Balance: ", balance, + // ", Equity: ", equity, + // ", FreeMargin: ", freeMargin + // ); + + // // + // LogMessage(message); + // SendAlert(message); + } + } + + // + // Retrieve Signal Exists ... + request = CalculateSignal( + // + // Bar Index ... + 0, + // + // Market Specification Inpouts ... + marketLength, // Market Length ... + closeAllOpenTradesAfterCandle, // Reverse Lookup in Market ... + riskToRewardRatio, // Risk To Reward Ratio ... + step, // PSAR Step ... + maximum, // PSAR Maximum ... + // + // XMA Inputs ... + shortCycleFastMultiplier, // Short Cycle Fast Multiplier ... + shortCycleSlowMultiplier, // Short Cycle Slow Multiplier ... + mediumCycleFastMultiplier, // Medium Cycle Fast Multiplier ... + mediumCycleSlowMultiplier, // Medium Cycle Slow Multiplier ... + longCycleFastMultiplier, // Long Cycle Fast Multiplier ... + longCycleSlowMultiplier, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showPSar, + showShortCycle, + showShortCycleCrossLines, + showMediumCycle, + showMediumCycleCrossLines, + showLongCycle, + showLongCycleCrossLines, + // + // Color Inputs ... + pSarColor, + shortCycleFastColor, + shortCycleSlowColor, + mediumCycleFastColor, + mediumCycleSlowColor, + longCycleFastColor, + longCycleSlowColor, + // + // OSC ... + fastOSCLength, // FastOSC Length ... + fastOSCMultiplier, // FastOSC Multiplier ... + slowOSCLength, // SlowOSC Length ... + slowOSCMultiplier, // SlowOSC Multiplier ... + minPowerOSC, // Minimum Signal Power ... + minVarianceOSC, // Minimum Var Power ... + // + // ZIGZAG Inputs ... + zDeviation, // ZigZag Deviation ... + zBackStep // ZigZag Back Step ... + ); + + // + // Prevent doing anything else, if there is no signals ... + if ( + !allowDoTrade || + !request.hasSignal || + request.type == X_NONE + ) { + return; + } + + // + bool hasLongSignal = request.type == X_LONG; + + // + // Check For Bot State ... + if ( + (hasLongSignal && !waitForLongSignals) + || (!hasLongSignal && !waitForShortSignals) + ) { + return; + } + + // + // Check last Signalled Bar with Counted Bars ... + // Prevent Multiple Signalling on Same Bar ... + bool isInLastSignalledBars = false; + for (int i=0; i < marketLength; i++) { + // + isInLastSignalledBars = + isInLastSignalledBars + || lastSignalledBar == countedBars - i + ; + } + if (isInLastSignalledBars) { + // + totalSignals--; + if (hasLongSignal) { + totalLongSignals--; + } else { + totalShortSignals--; + } + return; + } + + // + // increase last signalled bar ... + lastSignalledBar = countedBars; + + // + // Calculate Can Trade or not ... + allowDoTrade = allowTrade + && ( + hasLongSignal ? + allowLongTrades : + allowShortTrades + ); + + // + // Chack Maximum Open Positions ... + int openTrades = CountOpenTrades(); + if (maxOpenTrades > 0) { + // + if (openTrades >= maxOpenTrades) { + // + allowDoTrade = false; + + // + if (closeAllInProfitOpenTradesWhenMaxOpenTradesReached) { + // + // Close All In Profit Trades ... + bool hasClosedInProfitTrade = CloseAllInProfitTrades(); + if (hasClosedInProfitTrade) { + // + openTrades = CountOpenTrades(); + + // + allowDoTrade = !(openTrades >= maxOpenTrades); + } + } + + // + if (!allowDoTrade) { + // + string message = StringConcatenate( + "Trading Pause => ", + "Max Open Trades (", + maxOpenTrades, + ") reached ..." + ); + + // + LogMessage(message); + SendAlert(message); + } + } + } + + // + // Check Trading is Enable or not ... + // nothing to do if trading is disabled ... + if (!allowDoTrade) { + // // + // string message = StringConcatenate( + // "Trading Not Allowed ..." + // ); + + // // + // LogMessage(message); + // SendAlert(message); + return; + } + + // + bool isPositionOpened = TradeSignal( + request.signal, + signalPrefix, + lotsPerTradePercent, + bullishSignalLabel, + bullishSignalColor, + bearishSignalLabel, + bearishSignalColor + ); + + // + if (isPositionOpened) { + // + bool canAlert = + alertPositions + && ( + hasLongSignal ? + longPositionAlerts + : + shortPositionAlerts + ); + + // + if (canAlert) { + // + // Alert Message ... + string message = StringConcatenate( + "Trade on Signal ID: ", request.signal.id, + ", Entry: ", request.signal.entryPrice, + ", TP: ", request.signal.tp + ); + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } + } + } +} + +// +// Process All Open Positions ... +void ProcessOpenPositions() { + // + if (closeLongTrades) { + // + closeLongTrades = false; + + // + bool isAllLongTradesClosed = CloseAllLongTrades(); + if (isAllLongTradesClosed) { + waitForLongSignals = false; + } + } + + // + if (closeShortTrades) { + // + closeShortTrades = false; + + // + bool isAllShortTradesClosed = CloseAllShortTrades(); + if (isAllShortTradesClosed) { + waitForShortSignals = false; + } + } + + // + // bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + // closeAllOpenTradesAfterCandle + // ); + + // // + // // Close Maximum DrawDown Passed Trades ... + // bool hasClosedInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + // maxDrawdownPercentPerPTrade + // ); + + // // + // if ( + // hasClosedLongTimeTrade + // || hasClosedInDrawDownLongTrade + // ) { + // // + // waitForLongSignals = false; + // waitForShortSignals = false; + // } +} + +// +// Send Special Type of Alerts ... +void SendAlert(string message) { + // + if (!alertEvents) { + return; + } + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020414/Indicators/ParabolicSar.mq4 b/Bkp/Used/OSC EA 14020414/Indicators/ParabolicSar.mq4 new file mode 100644 index 0000000..261808a --- /dev/null +++ b/Bkp/Used/OSC EA 14020414/Indicators/ParabolicSar.mq4 @@ -0,0 +1,333 @@ +//------------------------------------------------------------------ +#property copyright "www.forex-station.com" +#property link "www.forex-station.com" +//------------------------------------------------------------------ +#property indicator_chart_window +#property indicator_buffers 4 +#property indicator_color1 clrLimeGreen +#property indicator_color2 clrOrange +#property indicator_color3 clrLimeGreen +#property indicator_color4 clrOrange +#property indicator_width3 3 +#property indicator_width4 3 +#property strict + +// +// +// +// +// + +extern ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; // Time frame to use +extern double AccStep = 0.02; // Accumulation step +extern double AccLimit = 0.2; // Accumulation limit +extern ENUM_APPLIED_PRICE PriceHigh = PRICE_CLOSE; // Psar high price +extern ENUM_APPLIED_PRICE PriceLow = PRICE_CLOSE; // Psar low price +extern int PriceSmoothing = 0; // Psar smoothing +extern ENUM_MA_METHOD PriceSmoothingMethod = MODE_SMA; // Psar ma smoothing method +extern bool alertsOn = true; // Alerts on? +extern bool alertsOnCurrent = false; // Alerts on current open bar? +extern bool alertsMessage = true; // Alerts message? +extern bool alertsSound = false; // Alerts sound? +extern bool alertsEmail = false; // Alerts email? +extern bool alertsNotify = false; // Alerts notification by phone? +extern bool DrawAsDots = true; // Draw as dots or solid line +extern int Shift = 0; // Shift + +double sarUp[]; +double sarDn[]; +double saraUp[]; +double saraDn[]; +int timeFrame; +string indicatorFileName; +bool returnBars; + +//------------------------------------------------------------------ +// +//------------------------------------------------------------------ +// +// +// +// +// + +int init() +{ + int type = DRAW_LINE; if (DrawAsDots) type = DRAW_ARROW; + SetIndexBuffer(0,sarUp); SetIndexStyle(0,type); SetIndexArrow(0,159); + SetIndexBuffer(1,sarDn); SetIndexStyle(1,type); SetIndexArrow(1,159); + SetIndexBuffer(2,saraUp); SetIndexStyle(2,DRAW_ARROW); SetIndexArrow(2,159); + SetIndexBuffer(3,saraDn); SetIndexStyle(3,DRAW_ARROW); SetIndexArrow(3,159); + + // + // + // + // + // + + indicatorFileName = WindowExpertName(); + returnBars = (TimeFrame==-99); + TimeFrame = MathMax(TimeFrame,_Period); + PriceSmoothing = MathMax(PriceSmoothing,1); + for (int i=0; i<4; i++) SetIndexShift(i,Shift*timeFrame/Period()); + + // + // + // + // + // + + return(0); +} +int deinit() { return(0); } + +//------------------------------------------------------------------ +// +//------------------------------------------------------------------ +// +// +// +// +// + +int start() +{ + int i,counted_bars=IndicatorCounted(); + if(counted_bars < 0) return(-1); + if(counted_bars>0) counted_bars--; + int limit = MathMin(Bars-counted_bars,Bars-1); + if (returnBars) { sarUp[0] = limit+1; return(0); } + + // + // + // + // + // + + if (TimeFrame == Period()) + { + for(i = limit; i >= 0; i--) + { + double sarClose; + double sarOpen; + double sarPosition; + double sarChange; + double pHigh = iMA(NULL,0,PriceSmoothing,0,PriceSmoothingMethod,PriceHigh,i); + double pLow = iMA(NULL,0,PriceSmoothing,0,PriceSmoothingMethod,PriceLow ,i); + iParabolic(fmax(pHigh,pLow),fmin(pHigh,pLow),AccStep,AccLimit,sarClose,sarOpen,sarPosition,sarChange,i); + sarUp[i] = EMPTY_VALUE; + sarDn[i] = EMPTY_VALUE; + saraUp[i] = EMPTY_VALUE; + saraDn[i] = EMPTY_VALUE; + if (sarPosition==1) + sarUp[i] = sarClose; + else sarDn[i] = sarClose; + if (sarChange!=0) + if (sarChange==1) + saraUp[i] = sarClose; + else saraDn[i] = sarClose; + } + manageAlerts(); + return(0); + } + + // + // + // + // + // + + limit = (int)fmax(limit,fmin(Bars-1,iCustom(NULL,TimeFrame,indicatorFileName,-99,0,0)*TimeFrame/Period())); + for(i=limit; i>=0; i--) + { + int y = iBarShift(NULL,TimeFrame,Time[i]); + int x = iBarShift(NULL,TimeFrame,Time[i+1]); + sarUp[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,AccStep,AccLimit,PriceHigh,PriceLow,PriceSmoothing,PriceSmoothingMethod,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,0,0,y); + sarDn[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,AccStep,AccLimit,PriceHigh,PriceLow,PriceSmoothing,PriceSmoothingMethod,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,0,1,y); + saraUp[i] = EMPTY_VALUE; + saraDn[i] = EMPTY_VALUE; + if (x!=y) + { + saraUp[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,AccStep,AccLimit,PriceHigh,PriceLow,PriceSmoothing,PriceSmoothingMethod,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,0,2,y); + saraDn[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,AccStep,AccLimit,PriceHigh,PriceLow,PriceSmoothing,PriceSmoothingMethod,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,0,3,y); + } + } + return(0); + +} + +//------------------------------------------------------------------ +// +//------------------------------------------------------------------ +// +// +// +// +// + +double work[][7]; +#define _high 0 +#define _low 1 +#define _ohigh 2 +#define _olow 3 +#define _open 4 +#define _position 5 +#define _af 6 + + +void iParabolic(double high, double low, double step, double limit, double& pClose, double& pOpen, double& pPosition, double& pChange, int i) +{ + if (ArrayRange(work,0)!=Bars) ArrayResize(work,Bars); i = Bars-i-1; + + // + // + // + // + // + + pChange = 0; + work[i][_ohigh] = high; + work[i][_olow] = low; + if (i<1) + { + work[i][_high] = high; + work[i][_low] = low; + work[i][_open] = high; + work[i][_position] = -1; + return; + } + work[i][_open] = work[i-1][_open]; + work[i][_af] = work[i-1][_af]; + work[i][_position] = work[i-1][_position]; + work[i][_high] = fmax(work[i-1][_high],high); + work[i][_low] = fmin(work[i-1][_low] ,low ); + + // + // + // + // + // + + if (work[i][_position] == 1) + if (low<=work[i][_open]) + { + work[i][_position] = -1; + pChange = -1; + pClose = work[i][_high]; + work[i][_high] = high; + work[i][_low] = low; + work[i][_af] = step; + work[i][_open] = pClose + work[i][_af]*(work[i][_low]-pClose); + if (work[i][_open]work[i-1][_high] && work[i][_af]work[i ][_olow]) work[i][_open] = work[i ][_olow]; + if (work[i][_open]>work[i-1][_olow]) work[i][_open] = work[i-1][_olow]; + } + else + if (high>=work[i][_open]) + { + work[i][_position] = 1; + pChange = 1; + pClose = work[i][_low]; + work[i][_low] = low; + work[i][_high] = high; + work[i][_af] = step; + work[i][_open] = pClose + work[i][_af]*(work[i][_high]-pClose); + if (work[i][_open]>work[i ][_olow]) work[i][_open] = work[i ][_olow]; + if (work[i][_open]>work[i-1][_olow]) work[i][_open] = work[i-1][_olow]; + } + else + { + pClose = work[i][_open]; + if (work[i][_low]=0; i--) + if (tf==iTfTable[i]) return(sTfTable[i]); + return(""); +} \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.adx.mq4 b/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.adx.mq4 new file mode 100644 index 0000000..3271a4e --- /dev/null +++ b/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.adx.mq4 @@ -0,0 +1,220 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center ADX Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm ADX Oscillator" +#property strict + +// +// START Inputs ... +// +input int length = 7; // Averaging Length +input ENUM_APPLIED_PRICE appliedPrice = PRICE_WEIGHTED; // Averaging Applied Price +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_separate_window + +// +#property indicator_minimum 0 +#property indicator_maximum 100 + +// +#property indicator_buffers 3 + +// +#property indicator_level1 0.0 +#property indicator_level2 50.0 +#property indicator_level3 70.0 +#property indicator_level4 100.0 +#property indicator_levelcolor clrSilver +#property indicator_levelstyle STYLE_DOT + +// +// ADX ... +#property indicator_width1 1 +#property indicator_color1 clrLightBlue +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_SOLID + +// +// Positive Direction ... +#property indicator_width2 1 +#property indicator_color2 clrLime +#property indicator_type2 DRAW_LINE +#property indicator_style2 STYLE_DOT + +// +// Negative Direction ... +#property indicator_width3 1 +#property indicator_color3 clrRed +#property indicator_type3 DRAW_LINE +#property indicator_style3 STYLE_DOT + +// +// Declare Buffers ... +#define adxBufferIndex 0 +#define positiveBufferIndex 1 +#define negativeBufferIndex 2 + +double adxBuffer[]; +double positiveBuffer[]; +double negativeBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (length < 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + IndicatorBuffers(3); + + // + SetIndexBuffer(positiveBufferIndex, positiveBuffer); + SetIndexLabel(positiveBufferIndex, "DI+"); + + // + SetIndexBuffer(negativeBufferIndex, negativeBuffer); + SetIndexLabel(negativeBufferIndex, "DI-"); + + // + SetIndexBuffer(adxBufferIndex, adxBuffer); + SetIndexLabel(adxBufferIndex, "ADX"); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, length); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Long TP ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index +) { + // + // Calculate Buffers ... + + // + // Retrieves the current ADX value ... + double adx = iADX( + _Symbol, + _Period, + length, + appliedPrice, + MODE_MAIN, + bar_index + ); + adxBuffer[bar_index] = adx; + + // + // Retrieves the current DI+ value ... + double plusDi = iADX( + _Symbol, + _Period, + length, + appliedPrice, + MODE_PLUSDI, + bar_index + ); + positiveBuffer[bar_index] = plusDi; + + // + // Retrieves the current DI- value ... + double minusDi = iADX( + _Symbol, + _Period, + length, + appliedPrice, + MODE_MINUSDI, + bar_index + ); + negativeBuffer[bar_index] = minusDi; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.ma.mq4 b/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.ma.mq4 new file mode 100644 index 0000000..e3a5737 --- /dev/null +++ b/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.ma.mq4 @@ -0,0 +1,173 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MA Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 MA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Fast MA ... +input int maLength = 20; // MA Length +input int maShift = 0; // MA Shift +input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method +input ENUM_APPLIED_PRICE maAppliedPrice = PRICE_CLOSE; // MA Applied Price + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 1 + +// +#property indicator_plots 1 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Fast Ma Buffer ... +#property indicator_label1 "Ma" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrYellow +#property indicator_style1 STYLE_DOT +#property indicator_width1 2 + +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define maBufferIndex 0 + +double maBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (maLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + // + // Ma ... + SetIndexBuffer(maBufferIndex, maBuffer); + SetIndexDrawBegin(maBufferIndex, maLength + 1); + // + // End Set Index Buffers ... + // + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, maLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Ma ... + CalculateMa(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateMa( + const int &bar_index +) { + // + // Calculating Fast Ma ... + double ma = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + maAppliedPrice, + bar_index + ); + + // + maBuffer[bar_index] = ma; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.momentum.mq4 b/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.momentum.mq4 new file mode 100644 index 0000000..ea6e419 --- /dev/null +++ b/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.momentum.mq4 @@ -0,0 +1,160 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center Momentum Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm Momentum Oscillator" +#property strict + +// +// START Inputs ... +// +input int length = 7; // Market Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_separate_window + +// +#property indicator_buffers 1 + +// +#property indicator_level1 0.0 +#property indicator_level2 100.0 +#property indicator_levelcolor clrSilver +#property indicator_levelstyle STYLE_DOT + +// +// MOMENTUM ... +#property indicator_width1 1 +#property indicator_color1 clrLightBlue +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_SOLID + +// +// Declare Buffers ... +#define momentumBufferIndex 0 + +double momentumBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (length < 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + IndicatorBuffers(1); + + // + SetIndexBuffer(momentumBufferIndex, momentumBuffer); + SetIndexLabel(momentumBufferIndex, "Momentum"); + SetIndexDrawBegin(momentumBufferIndex, length); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, length); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Long TP ... + CalculateBuffers( + i, + close + ); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index, + const double &close[] +) { + // + // Calculate Buffers ... + double momentum = close[bar_index] * 100 / close[bar_index + length]; + + // + momentumBuffer[bar_index] = momentum; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.osc.mq4 b/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.osc.mq4 new file mode 100644 index 0000000..220bd33 --- /dev/null +++ b/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.osc.mq4 @@ -0,0 +1,330 @@ +///////////////////////////////////////////////////////////////// +// +// SaherElm IT Center OSC Indicator +// ------------------------------------------------------------- +// this indicator provides OSC ... +// +// 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 OSC Indicator" +#property strict + +// +// START Inputs ... +// +// +// FastOSC ... +// Short Cycle (Fast OSC) ... +input int fastOSCLength = 10; // FastOSC Length +input double fastOSCMultiplier = 1.0; // FastOSC Multiplier + +// +// SlowOSC ... +// Medium Cycle (Slow OSC) ... +input int slowOSCLength = 30; // SlowOSC Length +input double slowOSCMultiplier = 3.0; // SlowOSC Multiplier +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +#property indicator_separate_window + +// +// we have 2 buffer in this indicator ... +#property indicator_buffers 5 + +// +// also we have 2 line for draw on this indicator ... +#property indicator_plots 5 + +// +// Fast OSC ... +#property indicator_width1 1 +#property indicator_color1 clrAqua +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_SOLID + +// +// Slow OSC ... +#property indicator_width2 1 +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrFuchsia +#property indicator_style2 STYLE_SOLID + +// +// Power OSC ... +#property indicator_width3 1 +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_DASHDOTDOT + +// +// Var OSC ... +#property indicator_width4 1 +#property indicator_type4 DRAW_HISTOGRAM +#property indicator_color4 clrBlueViolet +#property indicator_style4 STYLE_SOLID + +// +// Tan Fast/Slow OSC ... +#property indicator_width5 0 +#property indicator_type5 DRAW_NONE +#property indicator_color5 clrNONE +#property indicator_style5 STYLE_SOLID + +// +//#property indicator_minimum 0 +//#property indicator_maximum 1 + +// +// set color of horizontal levels ... +#property indicator_levelcolor clrGray + +// +// set style of horizontal levels ... +#property indicator_levelstyle STYLE_DOT + +// +// Declare Buffers ... +#define fastOSCBufferIndex 0 +#define slowOSCBufferIndex 1 +#define powerOSCBufferIndex 2 +#define varOSCBufferIndex 3 +#define fastSlowOSCAngleBufferIndex 4 + +// +double fastOSCBuffer[]; +double slowOSCBuffer[]; +double fastSlowOSCAngleBuffer[]; +double powerOSCBuffer[]; +double varOSCBuffer[]; + +// +// Used Indicators List ... +string rmaIndicatorName = "x-saherelm.rma"; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + fastOSCLength < 0 || + slowOSCLength < 0 || + slowOSCLength <= fastOSCLength + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XS_OSC"; + + // + // set descriptions of horizontal levels ... + SetLevelValue(0, 0.0); + IndicatorSetString(INDICATOR_LEVELTEXT,0,""); + + // + // set descriptions of horizontal levels ... + SetLevelValue(1, 0.5); + IndicatorSetString(INDICATOR_LEVELTEXT,1,""); + + // + // set descriptions of horizontal levels ... + SetLevelValue(2, 1); + IndicatorSetString(INDICATOR_LEVELTEXT,2,""); + + // + // Fast OSC Buffer ... + SetIndexBuffer(fastOSCBufferIndex, fastOSCBuffer); + SetIndexLabel(fastOSCBufferIndex, "Fast OSC"); + SetIndexDrawBegin(fastOSCBufferIndex, fastOSCLength - 1); + + // + // Slow OSC Buffer ... + SetIndexBuffer(slowOSCBufferIndex, slowOSCBuffer); + SetIndexLabel(slowOSCBufferIndex, "Slow OSC"); + SetIndexDrawBegin(slowOSCBufferIndex, slowOSCLength - 1); + + // + // Power OSC Buffer ... + SetIndexBuffer(powerOSCBufferIndex, powerOSCBuffer); + SetIndexLabel(powerOSCBufferIndex, "Power OSC"); + + // + // Var OSC Buffer ... + SetIndexBuffer(varOSCBufferIndex, varOSCBuffer); + SetIndexLabel(varOSCBufferIndex, "Var OSC"); + + // + // Tan Fast/Slow OSC Buffer ... + SetIndexBuffer(fastSlowOSCAngleBufferIndex, fastSlowOSCAngleBuffer); + SetIndexLabel(fastSlowOSCAngleBufferIndex, "F/L OSC Angle"); + + // + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(fastOSCLength, slowOSCLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + CalculateOscillators(close, i); + } + + // + return rates_total; +} + +// +// De Initialization ... +void OnDeinit(const int reason) { +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +void CalculateOscillators( + const double &close[], + const int &bar_index +) { + // + // FastOSC ... + // Short Cycle Calculations ... + int scl = fastOSCLength / 2; + int scl2 = scl / 2; + double maScl = iCustom(_Symbol, _Period, rmaIndicatorName, scl, 0, bar_index); + double scmAtr = iATR(_Symbol, _Period, scl, bar_index); + double scmOff = fastOSCMultiplier * scmAtr; + double maScl2 = iCustom(_Symbol, _Period, rmaIndicatorName, scl2, 0, bar_index); + double sctParam = maScl2 != 0 ? maScl2 : close[bar_index + 1]; + double sct = sctParam + scmOff; + double scb = sctParam - scmOff; + + // + // SlowOSC ... + // Medium Cycle Calculations ... + int mcl = slowOSCLength / 2; + int mcl2 = mcl / 2; + double maMcl = iCustom(_Symbol, _Period, rmaIndicatorName, mcl, 0, bar_index); + double mcmAtr = iATR(_Symbol, _Period, mcl, bar_index); + double mcmOff = slowOSCMultiplier * mcmAtr; + double maMcl2 = iCustom(_Symbol, _Period, rmaIndicatorName, mcl2, 0, bar_index); + double mctParam = maMcl2 != 0 ? maMcl2 : close[bar_index + 1]; + double mct = mctParam + mcmOff; + double mcb = mctParam - mcmOff; + + // + double scMM = (sct + scb) / 2; + + // + double fastOCS = (close[bar_index] - mcb) / (mct - mcb); + fastOSCBuffer[bar_index] = fastOCS; + + // + double slowOCS = (scMM - mcb) / (mct - mcb); + slowOSCBuffer[bar_index] = slowOCS; + + // + // Signal Power ... + // Difference Variant between FastOSC and Slow OSC ... + double powerOSC = fastOCS - slowOCS; + powerOSCBuffer[bar_index] = powerOSC; + + // + // Var OSC ... + double varOSC = fastOCS - 0.5; + varOSCBuffer[bar_index] = varOSC; + + // + // Calculate Tan Fast/Slow OSC ... + double fastOSCSlope = fastOSCBuffer[bar_index] - fastOSCBuffer[bar_index + 1]; + double slowOSCSlope = slowOSCBuffer[bar_index] - slowOSCBuffer[bar_index + 1]; + double tanFastSlowOSC = MathAbs( + (fastOSCSlope - slowOSCSlope) / (1 + (fastOSCSlope * slowOSCSlope)) + ); + + // + // here we pass Tan of angle ... + // fastSlowOSCAngleBuffer[bar_index] = tanFastSlowOSC; + + // + // here we pass degree of angle ... + fastSlowOSCAngleBuffer[bar_index] = MathArctan(tanFastSlowOSC); +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.psar.mq4 b/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.psar.mq4 new file mode 100644 index 0000000..a263cdb --- /dev/null +++ b/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.psar.mq4 @@ -0,0 +1,215 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center PSAR Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm PSAR Oscillator" +#property strict + +// +// START Inputs ... +// +input int shift = 0; // Shift +input double step = 0.02; // Step +input double maximum = 0.2; // Maximum +input bool drawAsDots = false; // Draw As Dots +// +input int priceSmoothing = 0; // Price Smoothing +input ENUM_APPLIED_PRICE priceLow = PRICE_CLOSE; // Psar low price +input ENUM_APPLIED_PRICE priceHigh = PRICE_OPEN; // Psar high price +input ENUM_MA_METHOD priceSmoothingMethod = MODE_SMA; // Price Smoothing Method +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 3 + +// +#property indicator_color1 clrLimeGreen +#property indicator_width1 1 +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_DOT + +// +#property indicator_color2 clrAqua +#property indicator_width2 1 +#property indicator_type2 DRAW_LINE +#property indicator_style2 STYLE_DOT + +// +#property indicator_color3 clrFuchsia +#property indicator_width3 1 +#property indicator_type3 DRAW_LINE +#property indicator_style3 STYLE_DOT + +// +// +// Declare Buffers ... +// +#define sarBufferIndex 0 +#define upBufferIndex 1 +#define downBufferIndex 2 + +// +double sarBuffer[]; +double upBuffer[]; +double downBuffer[]; + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + SetIndexBuffer(sarBufferIndex, sarBuffer); + SetIndexLabel(sarBufferIndex, "SAR"); + + // + SetIndexBuffer(upBufferIndex, upBuffer); + SetIndexLabel(upBufferIndex, "Up"); + + // + SetIndexBuffer(downBufferIndex, downBuffer); + SetIndexLabel(downBufferIndex, "Down"); + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XS_PSAR"; + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + // int maxLength = MathMax(0, length); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < 0) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Long TP ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index +) { + // + // Calculate isarValue ... + double sarValue = iSAR( + NULL, + _Period, + step, + maximum, + bar_index + ); + + // + double pHigh = iMA( + NULL, + _Period, + priceSmoothing, + 0, + priceSmoothingMethod, + priceHigh, + bar_index + ); + + // + double pLow = iMA( + _Symbol, + _Period, + priceSmoothing, + 0, + priceSmoothingMethod, + priceLow, + bar_index + ); + + // + upBuffer[bar_index] = pHigh; + sarBuffer[bar_index] = sarValue; + downBuffer[bar_index] = pLow; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.rma.mq4 b/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.rma.mq4 new file mode 100644 index 0000000..0fc70fd --- /dev/null +++ b/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.rma.mq4 @@ -0,0 +1,141 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center RMA Indicator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm RMA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Set the RMA Length ... +input int RMALength = 10; // Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// we have 2 buffer in this indicator ... +#property indicator_buffers 1 + +// +// also we have 1 line for draw on this indicator ... +#property indicator_plots 1 + +// +// here we declare plot SlowOCS to system ... +#property indicator_label1 "RMA" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrFuchsia +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +// +// Declare Buffers ... +#define RMABufferIndex 0 + +// +double RMABuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + SetIndexBuffer(RMABufferIndex, RMABuffer); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + int maxLength = MathMax(0, RMALength); + + // + // wait to pass bars until we have rights ... + if (rates_total <= maxLength) { + // + // return not calculated ... + return 0; + } + + // + // find loop count for bars manipulation ... + int count = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // Print("Count: ", count, ", Bars: ", Bars); + + // + // this is the main loop of calculations, for each bar index ... + for (int i = count - 1; i >= 0; i--) { + // + // Start Calculation with Formula 1 ... + // + double shortSMA = iMA(_Symbol, _Period, RMALength, 0, MODE_SMA, PRICE_CLOSE, i); + double mediumSMA = iMA(_Symbol, _Period, RMALength * 2, 0, MODE_SMA, PRICE_CLOSE, i); + double longSMA = iMA(_Symbol, _Period, RMALength * 3, 0, MODE_SMA, PRICE_CLOSE, i); + + // + double rma1 = longSMA - mediumSMA + shortSMA; + rma1 = NormalizeDouble(rma1, _Digits); + // + // End Calculation with Formula 1 ... + // + + // + RMABuffer[i] = rma1; + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.rsi.mq4 b/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.rsi.mq4 new file mode 100644 index 0000000..448f732 --- /dev/null +++ b/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.rsi.mq4 @@ -0,0 +1,234 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center RSI Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm RSI Oscillator" +#property strict + +// +// START Inputs ... +// +input int rsiPeriod=14; // RSI Period +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_separate_window + +// +#property indicator_minimum 0 +#property indicator_maximum 100 + +// +#property indicator_buffers 1 +#property indicator_color1 DodgerBlue + +// +#property indicator_level1 30.0 +#property indicator_level2 50.0 +#property indicator_level3 70.0 +#property indicator_levelcolor clrSilver +#property indicator_levelstyle STYLE_DOT + +// +// Declare Buffers ... +#define rsiBufferIndex 0 +#define positiveBufferIndex 1 +#define negativeBufferIndex 2 + +double rsiBuffer[]; +double positiveBuffer[]; +double negativeBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + string short_name; + + // + IndicatorBuffers(3); + + // + SetIndexBuffer(positiveBufferIndex, positiveBuffer); + SetIndexBuffer(negativeBufferIndex, negativeBuffer); + + // + SetIndexStyle(rsiBufferIndex, DRAW_LINE); + SetIndexBuffer(rsiBufferIndex, rsiBuffer); + + // + // name for DataWindow and indicator subwindow label + short_name="RSI("+string(rsiPeriod)+")"; + IndicatorShortName(short_name); + SetIndexLabel(rsiBufferIndex, short_name); + + // + // check for input + if (rsiPeriod < 2) { + // + Print("Incorrect value for input variable InpRSIPeriod = ", rsiPeriod); + + // + // Failed Initialization ... + return INIT_PARAMETERS_INCORRECT; + } + + // + // set where to start draw ... + SetIndexDrawBegin(0, rsiPeriod); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + int i,pos; + double diff; + + // + // Prevent from run calculations if there is no fulfilled conditions ... + if (Bars <= rsiPeriod || rsiPeriod < 2) { + // + // return nothing calculated result ... + return 0; + } + + // + // counting from 0 to rates_total, this is most important ... + ArraySetAsSeries(rsiBuffer, false); + ArraySetAsSeries(positiveBuffer, false); + ArraySetAsSeries(negativeBuffer, false); + + // + ArraySetAsSeries(close, false); + + // + // preliminary calculations ... + pos = prev_calculated - 1; + if (pos <= rsiPeriod) { + // + // first RSIPeriod values of the indicator are not calculated + rsiBuffer[0] = 0.0; + positiveBuffer[0] = 0.0; + negativeBuffer[0] = 0.0; + + // + double sump=0.0; + double sumn=0.0; + for (i = 1; i <= rsiPeriod; i++) { + // + rsiBuffer[i]=0.0; + positiveBuffer[i]=0.0; + negativeBuffer[i]=0.0; + + // + diff = close[i] - close[i - 1]; + if(diff > 0) { + sump += diff; + } else { + sumn -= diff; + } + } + + // + // calculate first visible value ... + positiveBuffer[rsiPeriod] = sump / rsiPeriod; + negativeBuffer[rsiPeriod] = sumn / rsiPeriod; + if (negativeBuffer[rsiPeriod] != 0.0) { + // + rsiBuffer[rsiPeriod] = 100.0 - ( + 100.0 / ( + 1.0 + positiveBuffer[rsiPeriod] / negativeBuffer[rsiPeriod] + ) + ); + } else { + // + if (positiveBuffer[rsiPeriod] != 0.0) { + rsiBuffer[rsiPeriod] = 100.0; + } else { + rsiBuffer[rsiPeriod] = 50.0; + } + } + + // + // prepare the position value for main calculation ... + pos = rsiPeriod + 1; + } + + // + // the main loop of calculations ... + for (i = pos; i < rates_total && !IsStopped(); i++) { + // + diff = close[i] - close[i-1]; + + // + positiveBuffer[i] = (positiveBuffer[i-1] * (rsiPeriod - 1) + (diff > 0.0 ? diff : 0.0)) / rsiPeriod; + negativeBuffer[i] = (negativeBuffer[i-1] * (rsiPeriod - 1) + (diff < 0.0 ? -diff : 0.0)) / rsiPeriod; + + // + if (negativeBuffer[i] != 0.0) { + rsiBuffer[i] = 100.0 - 100.0 / (1 + positiveBuffer[i] / negativeBuffer[i]); + } else { + // + if (positiveBuffer[i] != 0.0) { + rsiBuffer[i] = 100.0; + } else { + rsiBuffer[i] = 50.0; + } + } + } + + // + return(rates_total); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.xma.mq4 b/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.xma.mq4 new file mode 100644 index 0000000..3512a17 --- /dev/null +++ b/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.xma.mq4 @@ -0,0 +1,688 @@ + /////////////////////////////////////////////////////// +// +// SaherElm IT Center XMA Indicator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XMA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Market Specifications ... +input int marketLength = 7; // Market Length +input double step = 0.02; // SAR Step +input double maximum = 0.2; // SAR Maximum +// +// Cycle Definitions ... +input int shortCycleFastMultiplier = 1; // Short Cycle Fast Multiplier +input int shortCycleSlowMultiplier = 4; // Short Cycle Slow Multiplier +input int mediumCycleFastMultiplier = 7; // Medium Cycle Fast Multiplier +input int mediumCycleSlowMultiplier = 14; // Medium Cycle Slow Multiplier +input int longCycleFastMultiplier = 70; // Long Cycle Fast Multiplier +input int longCycleSlowMultiplier = 140; // Long Cycle Slow Multiplier +// +// Show Inputs ... +input bool showPSar = true; // Show Parabolic Sar +input bool showShortCycle = true; // Show Short Cycle +input bool showShortCycleCrossLines = true; // Show Short Cycle Vertical Lines +input bool showMediumCycle = true; // Show Medium Cycle +input bool showMediumCycleCrossLines = true; // Show Medium Cycle Vertical Lines +input bool showLongCycle = true; // Show Long Cycle +input bool showLongCycleCrossLines = true; // Show Long Cycle Vertical Lines +// +// Color Inputs ... +input color pSarColor = clrCornflowerBlue; // Parabolic Sar Color +input color shortCycleFastColor = clrGreen; // Short Cycle Fast Color +input color shortCycleSlowColor = clrRed; // Short Cycle Slow Color +input color mediumCycleFastColor = clrAqua; // Medium Cycle Fast Color +input color mediumCycleSlowColor = clrFuchsia; // Medium Cycle Slow Color +input color longCycleFastColor = clrGoldenrod; // Medium Cycle Fast Color +input color longCycleSlowColor = clrBrown; // Medium Cycle Slow Color +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// define indicator buffers ... +#property indicator_buffers 8 +#property indicator_plots 8 + +// +// Middle ... +#property indicator_label7 "Mid" +#property indicator_type7 DRAW_LINE +#property indicator_color7 clrBisque +#property indicator_style7 STYLE_DASHDOTDOT +#property indicator_width7 1 + +// +// Declare Buffers ... +#define scFastBufferIndex 0 +#define scSlowBufferIndex 1 +#define mcFastBufferIndex 2 +#define mcSlowBufferIndex 3 +#define lcFastBufferIndex 4 +#define lcSlowBufferIndex 5 +#define midBufferIndex 6 +#define pSarBufferIndex 7 + +// +double scFastBuffer[]; +double scSlowBuffer[]; +double mcFastBuffer[]; +double mcSlowBuffer[]; +double lcFastBuffer[]; +double lcSlowBuffer[]; +double midBuffer[]; +double pSarBuffer[]; + +// +int shortCycleFastLength; +int shortCycleSlowLength; +int mediumCycleFastLength; +int mediumCycleSlowLength; +int longCycleFastLength; +int longCycleSlowLength; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + // + // Validate Market Length ... + marketLength <= 0 + // + // Validate Short Cycle ... + || shortCycleFastMultiplier <= 0 + || shortCycleSlowMultiplier <= 0 + || shortCycleFastMultiplier >= shortCycleSlowMultiplier + // + // Validate Medium Cycle ... + || mediumCycleFastMultiplier <= 0 + || mediumCycleSlowMultiplier <= 0 + || mediumCycleFastMultiplier >= mediumCycleSlowMultiplier + // + // Validate Long Cycle ... + || longCycleFastMultiplier <= 0 + || longCycleSlowMultiplier <= 0 + || longCycleFastMultiplier >= longCycleSlowMultiplier + // + // Validate Series of Multipliers ... + || shortCycleFastMultiplier >= mediumCycleFastMultiplier + || mediumCycleFastMultiplier >= longCycleFastMultiplier + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST_XMA"; + + // + // Calculate Cycle Length based on given Multipliers ... + shortCycleFastLength = marketLength * shortCycleFastMultiplier; + shortCycleSlowLength = marketLength * shortCycleSlowMultiplier; + mediumCycleFastLength = marketLength * mediumCycleFastMultiplier; + mediumCycleSlowLength = marketLength * mediumCycleSlowMultiplier; + longCycleFastLength = marketLength * longCycleFastMultiplier; + longCycleSlowLength = marketLength * longCycleSlowMultiplier; + + // + // Short Cycle Fast ... + SetIndexLabel(scFastBufferIndex, "SCFast"); + SetIndexBuffer(scFastBufferIndex, scFastBuffer); + SetIndexDrawBegin(scFastBufferIndex, shortCycleFastLength); + SetIndexStyle( + scFastBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showShortCycle ? + shortCycleFastColor : + clrNONE + ); + + // + // Short Cycle Slow ... + SetIndexLabel(scSlowBufferIndex, "SCSLow"); + SetIndexBuffer(scSlowBufferIndex, scSlowBuffer); + SetIndexDrawBegin(scSlowBufferIndex, shortCycleSlowLength); + SetIndexStyle( + scSlowBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showShortCycle ? + shortCycleSlowColor : + clrNONE + ); + + // + // Medium Cycle Fast ... + SetIndexLabel(mcFastBufferIndex, "MCFast"); + SetIndexBuffer(mcFastBufferIndex, mcFastBuffer); + SetIndexDrawBegin(mcFastBufferIndex, mediumCycleFastLength); + SetIndexStyle( + mcFastBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showMediumCycle ? + mediumCycleFastColor : + clrNONE + ); + + // + // Medium Cycle Slow ... + SetIndexLabel(mcSlowBufferIndex, "MCSlow"); + SetIndexBuffer(mcSlowBufferIndex, mcSlowBuffer); + SetIndexDrawBegin(mcSlowBufferIndex, mediumCycleSlowLength); + SetIndexStyle( + mcSlowBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showMediumCycle ? + mediumCycleSlowColor : + clrNONE + ); + + // + // Long Cycle Fast ... + SetIndexLabel(lcFastBufferIndex, "LCFast"); + SetIndexBuffer(lcFastBufferIndex, lcFastBuffer); + SetIndexDrawBegin(lcFastBufferIndex, longCycleFastLength); + SetIndexStyle( + lcFastBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showLongCycle ? + longCycleFastColor : + clrNONE + ); + + // + // Long Cycle Slow ... + SetIndexLabel(lcSlowBufferIndex, "LCSlow"); + SetIndexBuffer(lcSlowBufferIndex, lcSlowBuffer); + SetIndexDrawBegin(lcSlowBufferIndex, longCycleSlowLength); + SetIndexStyle( + lcSlowBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showLongCycle ? + longCycleSlowColor : + clrNONE + ); + + // + // Market Middleage ... + SetIndexBuffer(midBufferIndex, midBuffer); + SetIndexDrawBegin(midBufferIndex, marketLength); + SetIndexLabel(midBufferIndex, "Market Mid"); + + // + // Parabolic Sar ... + SetIndexBuffer(pSarBufferIndex, pSarBuffer); + SetIndexLabel(pSarBufferIndex, "P Sar"); + SetIndexStyle( + pSarBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showPSar ? + pSarColor : + clrNONE + ); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + RemoveDraws(logTag); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(marketLength, longCycleSlowLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Short Cycle ... + CalculateShortCycle(i); + + // + // Calculate Medium Cycle ... + CalculateMediumCycle(i); + + // + // Calculate Long Cycle ... + CalculateLongCycle(i); + + // + // Calculate Market Middleage ... + CalculateMarketMiddleage(i); + + // + // Calculate Cross Points ... + CalculateCrossPoints(i); + + // + // Calculate Parabolic Sar ... + CalculateParabolicSar(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculate Short Cycle ... +void CalculateShortCycle( + const int bar_index +) { + // + // Fast ... + double shortCycleFast = iMA( + _Symbol, + _Period, + shortCycleFastLength, + 0, + MODE_SMA, + PRICE_WEIGHTED, + bar_index + ); + scFastBuffer[bar_index] = shortCycleFast; + + // + // Slow ... + double shortCycleSlow = iMA( + _Symbol, + _Period, + shortCycleSlowLength, + 0, + MODE_SMA, + PRICE_WEIGHTED, + bar_index + ); + scSlowBuffer[bar_index] = shortCycleSlow; +} + +// +// Calculate Medium Cycle ... +void CalculateMediumCycle( + const int bar_index +) { + // + // Fast ... + double mediumCycleFast = iMA( + _Symbol, + _Period, + mediumCycleFastLength, + 0, + MODE_SMA, + PRICE_MEDIAN, + bar_index + ); + mcFastBuffer[bar_index] = mediumCycleFast; + + // + // Slow ... + double mediumCycleSlow = iMA( + _Symbol, + _Period, + mediumCycleSlowLength, + 0, + MODE_SMA, + PRICE_MEDIAN, + bar_index + ); + mcSlowBuffer[bar_index] = mediumCycleSlow; +} + +// +// Calculate Long Cycle ... +void CalculateLongCycle( + const int bar_index +) { + // + // Fast ... + double longCycleFast = iMA( + _Symbol, + _Period, + longCycleFastLength, + 0, + MODE_SMA, + PRICE_CLOSE, + bar_index + ); + lcFastBuffer[bar_index] = longCycleFast; + + // + // Slow ... + double longCycleSlow = iMA( + _Symbol, + _Period, + longCycleSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE, + bar_index + ); + lcSlowBuffer[bar_index] = longCycleSlow; +} + +// +// Calculate Market Middleage ... +void CalculateMarketMiddleage( + const int bar_index +) { + // + // Mid ... + double marketMiddleage = iMA( + _Symbol, + _Period, + (int)(marketLength * 1.5), + 0, + MODE_EMA, + PRICE_MEDIAN, + bar_index + ); + midBuffer[bar_index] = marketMiddleage; +} + +// +// Calculate Cross Points and Draw Section Line on theme ... +void CalculateCrossPoints( + const int bar_index +) { + // + // START Draw Cross Lines ... + // + // + // Short Cycle ... + bool isSCFastCrossOverSlow = scFastBuffer[bar_index] > scSlowBuffer[bar_index] + && !(scFastBuffer[bar_index + 1] > scSlowBuffer[bar_index + 1]); + + // + bool isSCFastCrossUnderSlow = scFastBuffer[bar_index] < scSlowBuffer[bar_index] + && !(scFastBuffer[bar_index + 1] < scSlowBuffer[bar_index + 1]); + + // + // Medium Cycle ... + bool isMCFastCrossOverSlow = mcFastBuffer[bar_index] > mcSlowBuffer[bar_index] + && !(mcFastBuffer[bar_index + 1] > mcSlowBuffer[bar_index + 1]); + + // + bool isMCFastCrossUnderSlow = mcFastBuffer[bar_index] < mcSlowBuffer[bar_index] + && !(mcFastBuffer[bar_index + 1] < mcSlowBuffer[bar_index + 1]); + + // + // Long Cycle ... + bool isLCFastCrossOverSlow = lcFastBuffer[bar_index] > lcSlowBuffer[bar_index] + && !(lcFastBuffer[bar_index + 1] > lcSlowBuffer[bar_index + 1]); + + // + bool isLCFastCrossUnderSlow = lcFastBuffer[bar_index] < lcSlowBuffer[bar_index] + && !(lcFastBuffer[bar_index + 1] < lcSlowBuffer[bar_index + 1]); + + // + // START Drawing CrossPoints ... + // + // + datetime currentTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + if (showShortCycleCrossLines) { + // + // Draw Line ... + if (isSCFastCrossOverSlow) { + // + string lbl = StringConcatenate( + logTag, + "_SC_F_OV_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showShortCycleCrossLines ? + shortCycleFastColor : + clrNONE + ); + } + + // + // Draw Line ... + if (isSCFastCrossUnderSlow) { + // + string lbl = StringConcatenate( + logTag, + "_SC_F_UN_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showShortCycleCrossLines ? + shortCycleSlowColor : + clrNONE + ); + } + } + + // + if (showMediumCycleCrossLines) { + // + // Draw Line ... + if (isMCFastCrossOverSlow) { + // + string lbl = StringConcatenate( + logTag, + "_MC_F_OV_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showMediumCycleCrossLines ? + mediumCycleFastColor : + clrNONE + ); + } + + // + // Draw Line ... + if (isMCFastCrossUnderSlow) { + // + string lbl = StringConcatenate( + logTag, + "_MC_F_UN_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showMediumCycleCrossLines ? + mediumCycleSlowColor : + clrNONE + ); + } + } + + // + if (showLongCycleCrossLines) { + // + // Draw Line ... + if (isLCFastCrossOverSlow) { + // + string lbl = StringConcatenate( + logTag, + "_LC_F_OV_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showLongCycleCrossLines ? + longCycleFastColor : + clrNONE + ); + } + + // + // Draw Line ... + if (isLCFastCrossUnderSlow) { + // + string lbl = StringConcatenate( + logTag, + "_LC_F_UN_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showLongCycleCrossLines ? + longCycleSlowColor : + clrNONE + ); + } + } + // + // END Drawing CrossPoints ... + // +} + +void CalculateParabolicSar( + const int bar_index +) { + // + double sarValue = iSAR( + NULL, + _Period, + step, + maximum, + bar_index + ); + + // + pSarBuffer[bar_index] = sarValue; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.zigzag.mq4 b/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.zigzag.mq4 new file mode 100644 index 0000000..fbb073c --- /dev/null +++ b/Bkp/Used/OSC EA 14020414/Indicators/x-saherelm.zigzag.mq4 @@ -0,0 +1,476 @@ +///////////////////////////////////////////////////////////////// +// +// SaherElm IT Center ZigZag Indicator +// ------------------------------------------------------------- +// this indicator provides signals for Main strategy ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +//////////////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm ZigZag Indicator" +#property strict + +// +// START Inputs ... +// +input int depth = 12; // Depth +input int deviation = 5; // Deviation +input int backStep = 3; // BackStep +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// here we specify logging enabled or not ... +bool enableLogging = true; + +// +// this is a Tag which attached to our Logger ... +string logTag = "XS_ZG"; + +// +#property indicator_chart_window + +// +#property indicator_buffers 1 + +// +#property indicator_width1 1 +#property indicator_color1 clrAqua +// #property indicator_type1 DRAW_SECTION +// #property indicator_style1 STYLE_SOLID + +// // +// #property indicator_width2 1 +// #property indicator_color2 clrNONE +// #property indicator_type2 DRAW_NONE +// #property indicator_style2 STYLE_SOLID + +// // +// #property indicator_width3 1 +// #property indicator_color3 clrNONE +// #property indicator_type3 DRAW_NONE +// #property indicator_style3 STYLE_SOLID + +// +// Buffers ... +// +#define zigzagBufferIndex 0 +#define highBufferIndex 1 +#define lowBufferIndex 2 +// #define ziggyBufferIndex 3 + +// +double zigzagBuffer[]; +double highBuffer[]; +double lowBuffer[]; +// double ziggyBuffer[]; + +// +// recounting's depth of extremums ... +int level=3; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + depth <= 0 || + backStep < 0 || + deviation < 0 || + backStep >= depth + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Set Index Buffers of ZigZag ... + IndicatorBuffers(3); + + // + // ZigZag Buffer ... + SetIndexBuffer(zigzagBufferIndex, zigzagBuffer); + SetIndexStyle(zigzagBufferIndex, DRAW_SECTION); + SetIndexLabel(zigzagBufferIndex, "ZigZag"); + + // + // High Buffer ... + SetIndexBuffer(highBufferIndex, highBuffer); + SetIndexLabel(highBufferIndex, ""); + + // + // Low Buffer ... + SetIndexBuffer(lowBufferIndex, lowBuffer); + SetIndexLabel(lowBufferIndex, ""); + + // + // Ziggy Buffer ... + // SetIndexBuffer(ziggyBufferIndex, ziggyBuffer); + // SetIndexLabel(ziggyBufferIndex, ""); + + // + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + int maxLength = MathMax(depth, backStep); + + int i; + int counterZ; + int back; + int pos; + + // + int lastlowpos = 0; + int lasthighpos = 0; + int whatlookfor = 0; + + // + double extremum; + + // + double curlow = 0.0; + double curhigh = 0.0; + double lasthigh = 0.0; + double lastlow = 0.0; + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // first calculations ... + if (prev_calculated == 0) { + limit = InitializeBuffers(); + } else { + // + // find first extremum in the depth ExtLevel or 100 last bars ... + i = counterZ = 0; + while(counterZ < level && i < 100) { + // + if(zigzagBuffer[i] != 0.0) { + counterZ++; + } + + // + i++; + } + + // + // no extremum found - recounting all from begin ... + if(counterZ == 0) { + limit = InitializeBuffers(); + } else { + // + // set start position to found extremum position ... + limit = i-1; + + // + //--- what kind of extremum? + if(lowBuffer[i] != 0.0) { + // + // low extremum ... + curlow = lowBuffer[i]; + + // + // will look for the next high extremum ... + whatlookfor=1; + } else { + // + // high extremum ... + curhigh = highBuffer[i]; + + // + // will look for the next low extremum ... + whatlookfor=-1; + } + + // + // clear the rest data ... + for(i = limit - 1; i >= 0; i--) { + // + lowBuffer[i]=0.0; + highBuffer[i]=0.0; + zigzagBuffer[i]=0.0; + } + } + } + + // + // Main Calculation Loop ... + for (i = limit; i >= 0; i--) { + // + // find lowest low in depth of bars ... + extremum = low[ + iLowest( + _Symbol, + _Period, + MODE_LOW, + depth, + i + ) + ]; + + // + // this lowest has been found previously ... + if (extremum == lastlow) { + extremum = 0.0; + } else { + // + // new last low ... + lastlow=extremum; + + // + // discard extremum if current low is too high ... + if(low[i] - extremum > deviation * _Point) { + extremum=0.0; + } else { + // + // clear previous extremums in backstep bars ... + for(back = 1; back <= backStep; back++) { + // + pos = i + back; + + // + if(lowBuffer[pos] != 0 && lowBuffer[pos] > extremum) { + lowBuffer[pos] = 0.0; + } + } + } + } + + // + // found extremum is current low ... + if (low[i] == extremum) { + lowBuffer[i] = extremum; + } else { + lowBuffer[i] = 0.0; + } + + // + // find highest high in depth of bars ... + extremum = high[ + iHighest( + _Symbol, + _Period, + MODE_HIGH, + depth, + i + ) + ]; + + // + // this highest has been found previously ... + if (extremum == lasthigh) { + extremum = 0.0; + } else { + // + // new last high ... + lasthigh=extremum; + + // + // discard extremum if current high is too low ... + if (extremum - high[i] > deviation * Point) { + extremum = 0.0; + } else { + // + // clear previous extremums in backstep bars ... + for(back = 1; back <= backStep; back++) { + // + pos = i + back; + + // + if (highBuffer[pos] != 0 && highBuffer[pos] < extremum) { + highBuffer[pos] = 0.0; + } + } + } + } + + // + // found extremum is current high ... + if (high[i] == extremum) { + highBuffer[i] = extremum; + } else { + highBuffer[i] = 0.0; + } + } + + // + // final cutting ... + if( whatlookfor == 0) { + // + lastlow = 0.0; + lasthigh = 0.0; + } else { + // + lastlow = curlow; + lasthigh = curhigh; + } + + // + for(i = limit; i >= 0; i--) { + switch(whatlookfor) { + // + // look for peak or lawn ... + case 0: + // + if (lastlow == 0.0 && lasthigh == 0.0) { + if(highBuffer[i]!=0.0) { + // + lasthigh = High[i]; + lasthighpos = i; + whatlookfor = -1; + + // + zigzagBuffer[i] = lasthigh; + } + + // + if(lowBuffer[i] != 0.0) { + // + lastlow = Low[i]; + lastlowpos = i; + whatlookfor = 1; + + // + zigzagBuffer[i] = lastlow; + } + } + break; + + // + // look for peak ... + case 1: + // + if ( + lowBuffer[i] != 0.0 && + lowBuffer[i] < lastlow && + highBuffer[i] == 0.0 + ) { + // + zigzagBuffer[lastlowpos] = 0.0; + lastlowpos = i; + lastlow = lowBuffer[i]; + zigzagBuffer[i] = lastlow; + } + + // + if(highBuffer[i] != 0.0 && lowBuffer[i] == 0.0) { + // + lasthigh = highBuffer[i]; + lasthighpos = i; + zigzagBuffer[i] = lasthigh; + + // + whatlookfor=-1; + } + break; + + // + // look for lawn ... + case -1: + // + if( + highBuffer[i] != 0.0 && + highBuffer[i] > lasthigh && + lowBuffer[i] == 0.0 + ) { + // + zigzagBuffer[lasthighpos] = 0.0; + lasthighpos = i; + lasthigh = highBuffer[i]; + zigzagBuffer[i] = lasthigh; + } + + // + if( + lowBuffer[i] !=0.0 && + highBuffer[i] == 0.0 + ) { + // + lastlow = lowBuffer[i]; + lastlowpos = i; + zigzagBuffer[i] = lastlow; + whatlookfor=1; + } + break; + } + } + + // + // Done ... + return rates_total; +} + +// +// De Initialization ... +void OnDeinit(const int reason) { + // + // RemoveDraws(signalPrefix); + ChartRedraw(0); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +int InitializeBuffers() { + // + ArrayInitialize(lowBuffer,0.0); + ArrayInitialize(highBuffer, 0.0); + ArrayInitialize(zigzagBuffer, 0.0); + + // + //--- first counting position + return(Bars - depth); +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020414/Libraries/x-saherelm.draw.lib.mq4 b/Bkp/Used/OSC EA 14020414/Libraries/x-saherelm.draw.lib.mq4 new file mode 100644 index 0000000..08fefa7 --- /dev/null +++ b/Bkp/Used/OSC EA 14020414/Libraries/x-saherelm.draw.lib.mq4 @@ -0,0 +1,1670 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Start Arrow Functions ... +// +// +// Draw an Arrow Object on Chart ... +bool DrawArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // arrow name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const uchar arrowCode = OBJ_ARROW_UP, // arrow code + const ENUM_ARROW_ANCHOR anchor = ANCHOR_BOTTOM, // anchor point position + const color clr = clrAqua, // arrow color + const ENUM_LINE_STYLE style = STYLE_SOLID, // border line style + const int width = 3, // arrow size + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // Order Object ... +) { + // + // set anchor point coordinates if they are not set ... + ChangeArrowEmptyPoint(time, price); + + // + // reset the error value ... + ResetLastError(); + + // + // create an arrow ... + if(!ObjectCreate(chartID, name, OBJ_ARROW, subWindow, time, price)) { + // + string message = StringConcatenate(__FUNCTION__, + ": failed to create an arrow! Error code = ", + GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the arrow code ... + ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, arrowCode); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set the arrow color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set the border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set the arrow's size ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the arrow by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is false by default, if you want making it possible to highlight and move the object + // change it to true ... + ObjectSetInteger(chartID,name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point of Arrow ... +bool MoveArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if(!time) { + time = TimeCurrent(); + } + + // + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete an arrow ... +bool DeleteArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow" // arrow name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete an arrow ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete an arrow! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the arrow code ... +bool ArrowCodeChange( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + const uchar code = 252 // arrow code +) { + // + // reset the error value ... + ResetLastError(); + + // + // change the arrow code ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, code)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the arrow code! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change anchor type ... +bool ArrowAnchorChange( + const long chartID = 0, // chart's ID + const string name="Arrow", // object name + const ENUM_ARROW_ANCHOR anchor = ANCHOR_TOP // anchor type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change anchor type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change anchor type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeArrowEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } +} +// +// End Arrow Functions ... +// + +// +// Start Horizontal Line Functions ... +// +// +// Create, Draw the horizontal line ... +bool DrawHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + const int subWindow = 0, // subwindow index + double price = 0, // line price + const color clr = clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the price is not set, set it at the current Bid price level ... + if(!price) { + price=SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // create a horizontal line ... + if(!ObjectCreate(chartID, name, OBJ_HLINE, subWindow, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move horizontal line ... +bool MoveHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + double price = 0 // line price +) { + // + // if the line price is not set, move it to the current Bid price level ... + if(!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move a horizontal line ... + if(!ObjectMove(chartID, name, 0, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete a horizontal line ... +bool DeleteHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a horizontal line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End Horizontal Line Functions ... +// + +// +// Start Vertical Line Functions ... +// +// +// Create the vertical line ... +bool DrawVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + const int sub_window = 0, // subwindow index + datetime time = 0, // line time + const color clr=clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the line time is not set, draw it via the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value + ResetLastError(); + + // + // create a vertical line ... + if (!ObjectCreate(chartID, name, OBJ_VLINE, sub_window, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return true; +} + +// +// Move the vertical line ... +bool MoveVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + datetime time = 0 // line time +) { + // + // if line time is not set, move the line to the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the vertical line ... + if(!ObjectMove(chartID, name, 0, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the vertical line ... +bool DeleteVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the vertical line ... + if (!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // successful execution ... + return true; +} +// +// End Vertical Line Functions ... +// + +// +// Start RectangleLabel Functions ... +// +// +// Create Rectangle Label Object ... +bool DrawRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int subWindow = 0, // subwindow index + const int x = 0, // X coordinate + const int y = 0, // Y coordinate + const int width = 50, // width + const int height = 18, // height + const color back_clr = C'236,233,216', // background color + const ENUM_BORDER_TYPE border = BORDER_SUNKEN, // border type + const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring + const color clr = clrRed, // flat border color (Flat) + const ENUM_LINE_STYLE style = STYLE_SOLID, // flat border style + const int lineWidth = 1, // flat border width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // reset the error value ... + ResetLastError(); + + // + //--- create a rectangle label + if(!ObjectCreate(chartID, name, OBJ_RECTANGLE_LABEL, subWindow, 0, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set label coordinates ... + ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x); + ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y); + + // + // set label size ... + ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width); + ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height); + + // + // set background color ... + ObjectSetInteger(chartID, name, OBJPROP_BGCOLOR, back_clr); + + // + // set border type ... + ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border); + + // + // set the chart's corner, relative to which point coordinates are defined ... + ObjectSetInteger(chartID, name, OBJPROP_CORNER, corner); + + // + // set flat border color (in Flat mode) ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set flat border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set flat border width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, lineWidth); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the label by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move Rectangle Label .. +bool MoveRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int x = 0, // X coordinate + const int y=0 // Y coordinate +) { + // + // reset the error value ... + ResetLastError(); + + // + // move the rectangle label ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move X coordinate of the label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move Y coordinate of the label! Error code = ",GetLastError() + ); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the rectangle label ... +bool DeleteRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel" // label name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the label ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change Rectangle Label Size ... +bool ChangeSizeRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int width = 50, // label width + const int height = 18 // label height +) { + // + // reset the error value ... + ResetLastError(); + + // + // change label size ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's width! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's height! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change rectangle label border type ... +bool RectLabelChangeBorderType( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const ENUM_BORDER_TYPE border = BORDER_SUNKEN // border type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change border type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the border type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End RectangleLabel Functions ... +// + +// +// Start TrendLine Funcions ... +// +// Create a trend line by the given coordinates ... +bool DrawTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrYellow, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool rayRight = false, // line's continuation to the right + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeTrendLineEmptyPoints( + time1, + price1, + time2, + price2 + ); + + // + // reset the error value ... + ResetLastError(); + + // + // create a trend line by the given coordinates ... + if(!ObjectCreate(chartID, name, OBJ_TREND, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the line's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move trend line anchor point ... | +bool ChangeTrendLinePoint( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int pointindex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move trend line's anchor point ... + if(!ObjectMove(chartID, name, pointindex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// The function deletes the trend line from the chart ... +bool DeleteTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a trend line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of trend line's anchor points and set default ... +// values for empty ones ... +void ChangeTrendLineEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the first point's time is not set, it will be on the current bar ... + if (!time1) { + time1 = TimeCurrent(); + } + + // + // if the first point's price is not set, it will have Bid value ... + if (!price1) { + price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // if the second point's time is not set, it is located 9 bars left from the second one ... + if (!time2) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(), Period(), time1, 10, temp); + + // + // set the second point 9 bars left from the first one ... + time2 = temp[0]; + } + + // + // if the second point's price is not set, it is equal to the first point's one ... + if (!price2) { + price2 = price1; + } +} +// +// End TrendLine Functions ... +// + +// +// Start Text Functions ... +// +// Create and Draw a Text Object ... +bool DrawText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const string text = "Text", // the text itself + const string font = "Arial", // font + const int fontSize = 10, // font size + const color clr = clrRed, // color + const double angle = 0.0, // text slope + const ENUM_ANCHOR_POINT anchor = ANCHOR_CENTER, // anchor type + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor point coordinates if they are not set ... + ChangeTextEmptyPoint(time,price); + + // + // reset the error value ... + ResetLastError(); + + // + //--- create Text object + if(!ObjectCreate(chartID, name, OBJ_TEXT, subWindow, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the text ... + ObjectSetString(chartID, name , OBJPROP_TEXT, text); + + // + // set text font ... + ObjectSetString(chartID, name, OBJPROP_FONT, font); + + // + // set font size ... + ObjectSetInteger(chartID, name, OBJPROP_FONTSIZE, fontSize); + + // + // set the slope angle of the text ... + ObjectSetDouble(chartID, name, OBJPROP_ANGLE, angle); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the object by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID ,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point ... +bool MoveText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + //--- if point position is not set, move it to the current bar having Bid price + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point .. + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the object text ... +bool ChangeText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const string text = "Text" // text +) { + // + // reset the error value ... + ResetLastError(); + + // + // change object text ... + if(!ObjectSetString(chartID, name, OBJPROP_TEXT, text)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the text! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Text object ... +bool DeleteText( + const long chartID = 0, // chart's ID + const string name = "Text" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeTextEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + } +// +// End Text Functions ... +// + +// +// Start Fibonacchi Functions ... +// +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawFibonacci( + const long chartID = 0, // chart's ID + const string name="Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrRed, // object color + const ENUM_LINE_STYLE style = STYLE_SOLID, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawCustomFibonacci( + // + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + // + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrAqua, // object color + const ENUM_LINE_STYLE style = STYLE_DOT, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // Change Levels Of Fibonacci ... + bool result = FibonacciLevelsSet( + levels, + values, + colors, + styles, + widths, + descriptions, + chartID, + name + ); + + // + // successful execution ... + return result; +} + +// +// Set number of levels and their parameters ... +bool FibonacciLevelsSet( + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // check array sizes ... + if( + levels!=ArraySize(colors) || + levels!=ArraySize(styles) || + levels!=ArraySize(widths) || + levels!=ArraySize(widths) + ) { + // + string message = StringConcatenate( + __FUNCTION__, + ": array length does not correspond to the number of levels, error!" + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the number of levels ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELS, levels); + + // + // set the properties of levels in the loop ... + for(int i = 0; i < levels; i++) { + // + // level value ... + ObjectSetDouble(chartID, name, OBJPROP_LEVELVALUE, i, values[i]); + + // + // level color ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELCOLOR, i, colors[i]); + + // + // level style ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELSTYLE, i, styles[i]); + + // + // level width ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELWIDTH, i, widths[i]); + + // + // level description ... + // ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, DoubleToString(100 * values[i], 1)); + ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, descriptions[i]); + } + + // + // successful execution ... + return(true); +} + +// +// Move Fibonacci Retracement anchor point ... +bool FibonacciPointChange( + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int pointIndex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, pointIndex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Fibonacci Retracement ... +bool DeleteFibonachi( + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Fibonacci Retracement\"! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of Fibonacci Retracement anchor points and set +// default values for empty ones ... +void ChangeFibonacciEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the second point's time is not set, it will be on the current bar ... + if (!time2) { + time2 = TimeCurrent(); + } + + // + // if the second point's price is not set, it will have Bid value ... + if (!price2) { + price2 = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // if the first point's time is not set, it is located 9 bars left from the second one ... + if (!time1) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(),Period(),time2,10,temp); + + // + // set the first point 9 bars left from the second one ... + time1 = temp[0]; + } + + // + // if the first point's price is not set, move it 200 points below the second one ... + if (!price1) { + price1 = price2 - 200 * SymbolInfoDouble(_Symbol, SYMBOL_POINT); + } +} +// +// End Fibonacci Functions ... +// + + +// +// Start General Functions ... +// +// +// Remove all Drawn Objects ... +void RemoveDraws(const string &tag) { + // + for(int iObj=ObjectsTotal()-1; iObj >= 0; iObj--) { + // + string on = ObjectName(iObj); + if (StringFind(on, tag) == 0) { + ObjectDelete(on); + } + } +} +// +// End General Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020414/Libraries/x-saherelm.lib.mq4 b/Bkp/Used/OSC EA 14020414/Libraries/x-saherelm.lib.mq4 new file mode 100644 index 0000000..c1ccd2a --- /dev/null +++ b/Bkp/Used/OSC EA 14020414/Libraries/x-saherelm.lib.mq4 @@ -0,0 +1,1129 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +// START Functions ... +// + +// +// Determines current working is New Bar or not ... +bool IsNewBar() { + // + static datetime lastbar; + datetime curbar = (datetime)SeriesInfoInteger(_Symbol, _Period, SERIES_LASTBAR_DATE); + + // + if(lastbar != curbar) { + // + lastbar = curbar; + return true; + } + + // + return false; +} + +// +// Retrieve RMA on Specific Candle ... +double GetRMA( + int bar_index, + int length +) { + // + double shortSMA = iMA(_Symbol, _Period, length, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double mediumSMA = iMA(_Symbol, _Period, length * 2, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double longSMA = iMA(_Symbol, _Period, length * 3, 0, MODE_SMA, PRICE_CLOSE, bar_index); + + // + double result = longSMA - mediumSMA + shortSMA; + + // + return result; +} + +// +// this function check crossing up two Buffers ... +bool IsCrossedOver( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] > arr2[index1]) && !(arr1[index2] > arr2[index2]); + + // + return result; +} + +// +// this function check crossing down two Buffers ... +bool IsCrossedUnder( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] < arr2[index1]) && !(arr1[index2] < arr2[index2]); + + // + return result; +} + +// +// Convert points to Actual Point ... +double PointsToDouble(int points) { + // + double result = points * _Point; + return result; +} + +// +// Converts Pips to Points ... +int PipsToPoints(int pips) { + // + int result = pips * ((_Digits == 3 || _Digits == 5) ? 10 : 1); + return result; +} + +// +// Converts Pips to Double ... +double PipsToDouble(int pips) { + // + double result = PointsToDouble(PipsToPoints(pips)); + return result; +} + +// +// Converts Double Value to Pips ... +int PriceToPips(double value) { + // + if (value <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + int result = (int)(value / pipValue); + + // + return result; +} + +// +// Converts Pips to Double ... +double PipsToPrice(int pips) { + // + if (pips <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + double result = pipValue * pips; + + // + return result; +} + +// +// Generate ATR StopLoss Value ... +double CalculateATRSL( + int period, + double multiplier +) { + // + if (period <= 0 || multiplier <= 0) { + return 0; + } + + // + double atrValue = iATR( + _Symbol, + _Period, + period, + 0 + ); + + // + double result = atrValue * multiplier; + + // + return result; +} + +// +// Detect Candle Type ... +// Bullish => means close > open ... +bool IsBullishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBullishCandle( + open, + close + ); + + // + return result; +} + +bool IsBullishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open < close; + + // + return result; +} + +// +// Detect Candle Type ... +// Bearish => means close < open ... +bool IsBearishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBearishCandle( + open, + close + ); + + // + return result; +} + +bool IsBearishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open > close; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBullishHappens( + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + bool result = false; + + // + double lowestHighInMarket = GetMarketLowestHigh( + bar_index + 1, + marketLen + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + 1 + ); + + // + result = high > lowestHighInMarket + && PriceToPips(high - lowestHighInMarket) >= 4 + ; + + // + return result; +} + +// +// Detect Market Has Sharp Bearish or not ... +bool IsSharpBearishHappens( + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + bool result = false; + + // + double highestLowInMarket = GetMarketHighestLow( + bar_index + 1, + marketLen + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + result = low < highestLowInMarket + && PriceToPips(highestLowInMarket - low) >= 4 + ; + + // + return result; +} + +// +// Retrieve Highest High Value based on Given Market ... +double GetMarketHighestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Low Value based on Given Market ... +double GetMarketHighestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Open Value based on Given Market ... +double GetMarketHighestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Low Value based on Given Market ... +double GetMarketLowestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest High Value based on Given Market ... +double GetMarketLowestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Open Value based on Given Market ... +double GetMarketLowestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Close Value based on Given Market ... +double GetMarketLowestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// less than given price ... +double GetLowLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// great than given price ... +double GetLowGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// less than given price ... +double GetHighLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// great than given price ... +double GetHighGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// less than given price ... +double GetCloseLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// great than given price ... +double GetCloseGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +struct XMinMax { + double min; + double max; +}; + +// +// Find Min and Max Value of specific Buffer ... +XMinMax GetBufferMinMax(const double &buffer[]) { + // + XMinMax result = {}; + + // + int bufferSize = ArraySize(buffer); + if (bufferSize < 1) { + return result; + } + + // + double min = buffer[0]; + double max = buffer[0]; + + // + for (int i = 1; i < bufferSize; i++) { + // + if (buffer[i] < min) { + min = buffer[i]; + } else if (buffer[i] > max) { + max = buffer[i]; + } + } + + // + result.min = min; + result.max = max; + + // + return result; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA 14020414/Libraries/x-saherelm.log.lib.mq4 b/Bkp/Used/OSC EA 14020414/Libraries/x-saherelm.log.lib.mq4 new file mode 100644 index 0000000..066b3f7 --- /dev/null +++ b/Bkp/Used/OSC EA 14020414/Libraries/x-saherelm.log.lib.mq4 @@ -0,0 +1,91 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Log Tag ... +static string logTag = ""; + +// +// Enable or Disable Logging ... +static bool enableLogging = false; + +// +// Start Log Messages ... +// + +// +// Logging a Message, specified for this EA ... +// using provided LogTag ... +void LogMessage(string message) { + // + if (!enableLogging) { + return; + } + + // + Print(logTag, " > ", message); +} + +// +// this used for logging series ... +void LogSeries( + double &series[], // which series to Log ... + int length = 0, // number of items to Log, 0 means all ... + int skip = 0 // number of items which skip before logging ... +) { + // + string msg = ""; + + // + int seriesSize = ArraySize(series); + if ( + skip < 0 + || length < 0 + || seriesSize == 0 + || skip > seriesSize + || skip + length > seriesSize + ) { + return; + } + + // + length = length == 0 ? + seriesSize : + length; + int start = skip > 1 ? + skip - 1 : + skip == 1 ? + 1 : + 0; + + // + // Loop through series items ... + for (int i = start; i < start + length; i++) { + // + msg += StringConcatenate( + "i[", i, "]: ", series[i], ", " + ); + } + + // + LogMessage(msg); +} +// +// End Log Messages ... +// + diff --git a/Bkp/Used/OSC EA 14020414/Libraries/x-saherelm.osc.models.lib.mq4 b/Bkp/Used/OSC EA 14020414/Libraries/x-saherelm.osc.models.lib.mq4 new file mode 100644 index 0000000..7165179 --- /dev/null +++ b/Bkp/Used/OSC EA 14020414/Libraries/x-saherelm.osc.models.lib.mq4 @@ -0,0 +1,127 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Models Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Start Models ... +// +// +// Used Indicators List ... +const string xmaIndicatorName = "x-saherelm.xma"; +const string adxIndicatorName = "x-saherelm.adx"; +const string oscIndicatorName = "x-saherelm.osc"; +const string zigZagIndicatorName = "x-saherelm.zigzag"; + +// +// Direction ... +enum X_DIRECTION { + X_UP, + X_DOWN +}; + +// +// these are different signal types ... +enum X_SIGNAL_TYPE { + X_NONE, + X_LONG, + X_SHORT, +}; + +// +// we Model each signals as this type ... +struct XSignal { + int id; + X_SIGNAL_TYPE type; + double tp; + double sl; + string symbol; + datetime time; + double entryPrice; +}; + +// +// this is Signal Request Response model ... +struct XSignalRequest { + bool hasSignal; + X_SIGNAL_TYPE type; + XSignal signal; +}; + +// +// we model OSC Return Data ... +struct XOSCState { + // + double fastOSC; + double slowOSC; + + // + double powerOSC; + + // + double varOSC; + + // + double tanFSOSC; +}; + +// +// Define a Model to Represent Snapshot of XMA Indicator ... +struct XMAState { + // + // Short Cycle ... + // + // FAST ... + double scFast; + + // + // SLOW ... + double scSlow; + + // + bool isSCTrendUp; + + // + // Medium Cycle ... + // + // FAST ... + double mcFast; + + // + // SLOW ... + double mcSlow; + + // + // Long Cycle ... + // + // FAST ... + double lcFast; + + // + // SLOW ... + double lcSlow; + + // + // MIDDLEAGE ... + double marketMiddleage; + + // + // PARABOLIC-SAR ... + double parabolicSAR; +}; +// +// End Models ... +// diff --git a/Bkp/Used/OSC EA 14020414/Libraries/x-saherelm.osc.signal.lib.mq4 b/Bkp/Used/OSC EA 14020414/Libraries/x-saherelm.osc.signal.lib.mq4 new file mode 100644 index 0000000..34248bb --- /dev/null +++ b/Bkp/Used/OSC EA 14020414/Libraries/x-saherelm.osc.signal.lib.mq4 @@ -0,0 +1,3124 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Signal Draw Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.osc.models.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +static int totalSignals = 0; +static int totalLongSignals = 0; +static int totalShortSignals = 0; + +// +static double initialBalance = 0; + +// +static int countedBars = 0; +static bool isNewBar = false; + +// +static bool isSharpBullishHappens; +static bool isSharpBearishHappens; + +// +static XOSCState oscStates[]; + +// +static bool isOSCFastCrossOverSlow; +static datetime oscFastCrossOverSlowTime; +static datetime lastOSCFastCrossOverSlowTime; + +// +static bool isOSCFastCrossUnderSlow; +static datetime oscFastCrossUnderSlowTime; +static datetime lastOSCFastCrossUnderSlowTime; + +// +static bool isOSCTrendUp; +static double minOSCPower; +static double maxOSCPower; +static bool isOSCTrendDown; +static bool isOSCPowerTrendUp; +static bool isOSCMarketRanging; +static bool isOSCPowerTrendDown; + +// +static XMAState xmaStates[]; + +// +static bool isSCFastCrossOverSlow; +static datetime scFastCrossOverSlowTime; +static datetime lastSCFastCrossOverSlowTime; +static bool isSCFastCrossOverSlowValid; + +// +static bool isSCFastCrossUnderSlow; +static datetime scFastCrossUnderSlowTime; +static datetime lastSCFastCrossUnderSlowTime; +static bool isSCFastCrossUnderSlowValid; + +// +static bool isSCTrendUp; +static bool isSCTrendDown; + +// +static bool isMCFastCrossOverSlow; +static datetime mcFastCrossOverSlowTime; +static datetime lastMCFastCrossOverSlowTime; +static bool isMCFastCrossOverSlowValid; + +// +static bool isMCTrendUp; +static bool isMCTrendDown; + +// +static double mcTrendPowers[]; +static double marketMiddles[]; + +// +static bool isMCFastCrossUnderSlow; +static datetime mcFastCrossUnderSlowTime; +static datetime lastMCFastCrossUnderSlowTime; +static bool isMCFastCrossUnderSlowValid; + +// +static bool isMarketMiddleCrossOverMCFast; +static datetime marketMiddleCrossOverMCFastTime; +static datetime lastMarketMiddleCrossOverMCFastTime; +static bool isMarketMiddleCrossOverMCFastValid; + +// +static bool isMarketMiddleCrossOverMCSlow; +static datetime marketMiddleCrossOverMCSlowTime; +static datetime lastMarketMiddleCrossOverMCSlowTime; +static bool isMarketMiddleCrossOverMCSlowValid; + +// +static bool isMarketMiddleCrossUnderMCFast; +static datetime marketMiddleCrossUnderMCFastTime; +static datetime lastMarketMiddleCrossUnderMCFastTime; +static bool isMarketMiddleCrossUnderMCFastValid; + +// +static bool isMarketMiddleCrossUnderMCSlow; +static datetime marketMiddleCrossUnderMCSlowTime; +static datetime lastMarketMiddleCrossUnderMCSlowTime; +static bool isMarketMiddleCrossUnderMCSlowValid; + +// +static bool isParabolicCrossOverMarketMiddle; +static datetime parabolicCrossOverMarketMiddleTime; +static datetime lastParabolicCrossOverMarketMiddleTime; +static bool isParabolicCrossOverMarketMiddleValid; + +// +static bool isParabolicCrossUnderMarketMiddle; +static datetime parabolicCrossUnderMarketMiddleTime; +static datetime lastParabolicCrossUnderMarketMiddleTime; +static bool isParabolicCrossUnderMarketMiddleValid; + +// +static bool isParabolicTrendUp; +static bool isParabolicTrendDown; + +// +static bool isLCFastCrossOverSlow; +static datetime lcFastCrossOverSlowTime; +static datetime lastLCFastCrossOverSlowTime; + +// +static bool isLCFastCrossUnderSlow; +static datetime lcFastCrossUnderSlowTime; +static datetime lastLCFastCrossUnderSlowTime; + +// +static bool isMarketMiddleageTrendUp; +static bool isMarketMiddleageTrendDown; + +// +// Retrieve State ... +XOSCState GetOSCState( + const int bar_index, + const int foLen, + const double foMul, + const int slLen, + const double slMul +) { + // + // Define Trend Direction Related Values ... + // + XOSCState result = {}; + + // + // START Extract Data from Oscillator ... + // + // + // Fast OSC ... + double fastOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 0, // Fast OSC Buffer Index ... + bar_index + ); + result.fastOSC = fastOSC; + + // + // Slow OSC ... + double slowOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 1, // Slow OSC Buffer Index ... + bar_index + ); + result.slowOSC = slowOSC; + + // + // Power OSC ... + double powerOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 2, // Power OSC Buffer Index ... + bar_index + ); + result.powerOSC = powerOSC; + + // + // Var OSC ... + double varOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 3, // Var OSC Buffer Index ... + bar_index + ); + result.varOSC = varOSC; + + // + // Tan FS OSC ... + double tanFSOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 4, // Tan F/S OSC Buffer Index ... + bar_index + ); + result.tanFSOSC = tanFSOSC; + // + // END Extract Data from Oscillator ... + // + + // + return result; +} + +// +// Check Market Ranging or not based on OSC ... +bool IsOSCMarketRanging( + // + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double rangingThreshold, // Detect Ranging based On Power OSC ... + // + // OSC Specifications ... + const int foLen, // Fast OSC Length ... + const double foMul, // Fast OSC Multiplier ... + const int slLen, // Slow OSC Length ... + const double slMul // Slow OSC Multiplier ... +) { + // + bool result = false; + + // + // Detect Buffer Size ... + const int bufferSize = marketLen + bar_index; + double powerOSCBuffer[]; + ArraySetAsSeries( + powerOSCBuffer, + true + ); + ArrayResize( + powerOSCBuffer, + bufferSize + ); + + // + // Loop through Market for Extract PowerOSC from OSC Indicator ... + for (int i = bufferSize - 1; i >= 0; i--) { + // + // Retrieve OSC State at Specific Bar Index ... + XOSCState state = GetOSCState( + i, + foLen, + foMul, + slLen, + slMul + ); + + // + powerOSCBuffer[i] = state.powerOSC; + } + + // + // now we have to extract min and max value of Splitted Buffer ... + XMinMax minMax = GetBufferMinMax(powerOSCBuffer); + + // + // now Check Min and Max Direction and Compare them with Ranging Value ... + result = MathAbs(minMax.min) > rangingThreshold + || MathAbs(minMax.max) > rangingThreshold; + + // + return result; +} + +// +// Retrieve and Calculate XMA State ... +XMAState GetXMAState( + // + // Market Specification Inpouts ... + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + const double stp, // SAR Step ... + const double maxm, // SAR Maximum ... + // + // XMA Inputs ... + const int scFastMul, // Short Cycle Fast Multiplier ... + const int scSlowMul, // Short Cycle Slow Multiplier ... + const int mcFastMul, // Medium Cycle Fast Multiplier ... + const int mcSlowMul, // Medium Cycle Slow Multiplier ... + const int lcFastMul, // Long Cycle Fast Multiplier ... + const int lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + const bool showPSr, // Show Parabolic Sar + const bool showSC, // Show Short Cycle + const bool showSCCrossLines, // Show Short Cycle Vertical Lines + const bool showMC, // Show Medium Cycle + const bool showMCCrossLines, // Show Medium Cycle Vertical Lines + const bool showLC, // Show Long Cycle + const bool showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + const color pSrColor, // Parabolic Sar Color + const color scFastColor, // Short Cycle Fast Color ... + const color scSlowColor, // Short Cycle Slow Color ... + const color mcFastColor, // Medium Cycle Fast Color ... + const color mcSlowColor, // Medium Cycle Slow Color ... + const color lcFastColor, // Medium Cycle Fast Color ... + const color lcSlowColor // Medium Cycle Slow Color ... +) { + // + // Temp Result ... + XMAState result = {}; + + // + // START Reading Buffers ... + // + // + // Define BufferIndexes ... + int scFastBufIndex = 0; + int scSlowBufIndex = 1; + int mcFastBufIndex = 2; + int mcSlowBufIndex = 3; + int lcFastBufIndex = 4; + int lcSlowBufIndex = 5; + int midBufIndex = 6; + int pSarBufIndex = 7; + + // + // START Short Cycle ... + // + // + // Short Cycle Fast ... + double scFast = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + stp, // PSAR Step ... + maxm, // PSAR Maximum ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showPSr, // Show Parabolic SAR ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + pSrColor, // Parabolic Sar Color ... + scFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + scFastBufIndex, // Buffer Index ... + bar_index + ); + result.scFast = scFast; + + // + // Short Cycle Slow ... + double scSlow = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + stp, // PSAR Step ... + maxm, // PSAR Maximum ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showPSr, // Show Parabolic SAR ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + pSrColor, // Parabolic Sar Color ... + scFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + scSlowBufIndex, // Buffer Index ... + bar_index + ); + result.scSlow = scSlow; + // + // END Short Cycle ... + // + + // + // START Medium Cycle ... + // + // + // Medium Cycle Fast ... + double mcFast = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + stp, // PSAR Step ... + maxm, // PSAR Maximum ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showPSr, // Show Parabolic SAR ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + pSrColor, // Parabolic Sar Color ... + scFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + mcFastBufIndex, // Buffer Index ... + bar_index + ); + result.mcFast = mcFast; + + // + // Medium Cycle Slow ... + double mcSlow = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + stp, // PSAR Step ... + maxm, // PSAR Maximum ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showPSr, // Show Parabolic SAR ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + pSrColor, // Parabolic Sar Color ... + scFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + mcSlowBufIndex, // Buffer Index ... + bar_index + ); + result.mcSlow = mcSlow; + // + // END Medium Cycle ... + // + + // + // START Long Cycle ... + // + // + // Long Cycle Fast ... + double lcFast = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + stp, // PSAR Step ... + maxm, // PSAR Maximum ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showPSr, // Show Parabolic SAR ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + pSrColor, // Parabolic Sar Color ... + scFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + lcFastBufIndex, // Buffer Index ... + bar_index + ); + result.lcFast = lcFast; + + // + // Long Cycle Slow ... + double lcSlow = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + stp, // PSAR Step ... + maxm, // PSAR Maximum ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showPSr, // Show Parabolic SAR ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + pSrColor, // Parabolic Sar Color ... + scFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + lcSlowBufIndex, // Buffer Index ... + bar_index + ); + result.lcSlow = lcSlow; + // + // END Long Cycle ... + // + + // + // START Makret Middleage ... + // + // + // Market Middleage ... + double marketMiddleage = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + stp, // PSAR Step ... + maxm, // PSAR Maximum ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showPSr, // Show Parabolic SAR ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + pSrColor, // Parabolic Sar Color ... + scFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + midBufIndex, // Buffer Index ... + bar_index + ); + result.marketMiddleage = marketMiddleage; + // + // END Makret Middleage ... + // + + // + // START Parabolic SAR ... + // + // + // Parabolic ... + double parabolicSAR = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + stp, // PSAR Step ... + maxm, // PSAR Maximum ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showPSr, // Show Parabolic SAR ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + pSrColor, // Parabolic Sar Color ... + scFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + pSarBufIndex, // Buffer Index ... + bar_index + ); + result.parabolicSAR = parabolicSAR; + // + // END Makret Middleage ... + // + // + // END Reading Buffers ... + // + + // + return result; +} + +// +// Calculate Fib Level ... +double GetFibonacciLevel( + double upPrice, + double downPrice, + double level, + X_DIRECTION direction +) { + // + double ling = upPrice - downPrice; + double pLevel = (ling / 100) * (level * 100); + + // + double result = direction == X_UP ? + upPrice - pLevel : + downPrice + pLevel; + result = NormalizeDouble(result, _Digits); + + // + return result; +} +// +// END Global Requirement Functions ... +// + +// +// START Signal Related Functions ... +// +// +// Calculate Signal ... +// in this function we calculate a signal exists in +// specific bar or not ... +XSignalRequest CalculateSignal( + // + const int bar_index, // Bar Index ... + // + // MARKET Specifications ... + const int marketLen, // Market Length ... + const int reverseLookupInMarket,//Revrse Lookup In Marketfor TP, SL, ... + const double r2r, // Risk To Reward Ratio ... + // + // TODO: here we can add different Signalling Strategies + // usages variables to handle On/Off them in where we want ... + // + // XMA Inputs ... + // + const double stp, // SAR Step ... + const double maxm, // SAR Maximum ... + const int scFastMul, // Short Cycle Fast Multiplier ... + const int scSlowMul, // Short Cycle Slow Multiplier ... + const int mcFastMul, // Medium Cycle Fast Multiplier ... + const int mcSlowMul, // Medium Cycle Slow Multiplier ... + const int lcFastMul, // Long Cycle Fast Multiplier ... + const int lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + const bool showPSr, // Show Parabolic Sar + const bool showSC, // Show Short Cycle + const bool showSCCrossLines, // Show Short Cycle Vertical Lines + const bool showMC, // Show Medium Cycle + const bool showMCCrossLines, // Show Medium Cycle Vertical Lines + const bool showLC, // Show Long Cycle + const bool showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + const color pSrColor, // Parabolic Sar Color ... + const color scFastColor, // Short Cycle Fast Color ... + const color scSlowColor, // Short Cycle Slow Color ... + const color mcFastColor, // Medium Cycle Fast Color ... + const color mcSlowColor, // Medium Cycle Slow Color ... + const color lcFastColor, // Medium Cycle Fast Color ... + const color lcSlowColor, // Medium Cycle Slow Color ... + // + // OSC Inputs ... + const int fastOSCLen, // FastOSC Length ... + const double fastOSCMul, // FastOSC Multiplier ... + const int slowOSCLen, // SlowOSC Length ... + const double slowOSCMul, // SlowOSC Multiplier ... + const double minPowOSC, // Minimum Signal Power ... + const double minVarOSC, // Minimum Var Power ... + // + // ZIGZAG Inputs ... + const int zDev, // ZigZag Deviation ... + const int zBkStep // ZigZag Back Step ... +) { + // + // create temp result ... + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_NONE; + + // + XSignal signal = {}; + + // + XOSCState emptyOscState = {}; + ArrayFree(oscStates); + ArrayResize( + oscStates, + marketLen + ); + for (int i = 0; i < marketLen; i++) { + oscStates[i] = emptyOscState; + } + + // + XMAState emptyXmaState = {}; + ArrayFree(xmaStates); + ArrayResize( + xmaStates, + marketLen + ); + for (int i = 0; i < marketLen; i++) { + xmaStates[i] = emptyXmaState; + } + + // + // Retrieve Bar Index Time ... + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + 1 + ); + + // + minOSCPower = 0; + maxOSCPower = 0; + + // + // START Retrieve Statets ... + // + // + // Loop through Market Length ... + int index = 0; + for (int i = bar_index; i < bar_index + marketLen; i++) { + // + // Retrieve Index OSC State ... + XOSCState oscState = GetOSCState( + index, // Bar Index ... + fastOSCLen, + fastOSCMul, + slowOSCLen, + slowOSCMul + ); + + // + // Retrieve XMA State ... + XMAState xmaState = GetXMAState( + index, // Bar Index ... + marketLen, // Market Length ... + stp, // SAR Step ... + maxm, // SAR Maximum ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + showPSr, // Show Parabolic Sar + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + pSrColor, // Parabolic Sar Color + scFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor // Medium Cycle Slow Color ... + ); + + // + // Set Retrieved Index States ... + oscStates[index] = oscState; + xmaStates[index] = xmaState; + + // + index++; + } + // + // END Retrieve Statets ... + // + + // + // START States Calculations ... + // + + // + // START OSC Calculations ... + // + // + // Check OSC Fast Cross Over Slow ... + isOSCFastCrossOverSlow = + oscStates[1].fastOSC > oscStates[1].fastOSC + && !(oscStates[2].fastOSC >= oscStates[2].fastOSC) + && !(oscStates[3].fastOSC >= oscStates[3].fastOSC) + ; + + // + // Setting Date Time ... + if (isOSCFastCrossOverSlow) { + // + lastOSCFastCrossOverSlowTime = oscFastCrossOverSlowTime; + oscFastCrossOverSlowTime = barTime; + } + + // + // Check OSC Fast Cross Under Slow ... + isOSCFastCrossUnderSlow = + oscStates[1].fastOSC < oscStates[1].fastOSC + && !(oscStates[2].fastOSC <= oscStates[2].fastOSC) + && !(oscStates[3].fastOSC <= oscStates[3].fastOSC) + ; + + // + // Setting Date Time ... + if (isOSCFastCrossUnderSlow) { + // + lastOSCFastCrossUnderSlowTime = oscFastCrossUnderSlowTime; + oscFastCrossUnderSlowTime = barTime; + } + + // + // Check OSC Trending Up ... + isOSCTrendUp = + oscStates[1].fastOSC > oscStates[2].fastOSC + && oscStates[1].fastOSC > oscStates[3].fastOSC + && ( + oscStates[1].fastOSC > oscStates[3].fastOSC + || oscStates[1].fastOSC > oscStates[4].fastOSC + ); + + // + // Check OSC Trending Down ... + isOSCTrendDown = + oscStates[1].fastOSC < oscStates[2].fastOSC + && oscStates[1].fastOSC < oscStates[3].fastOSC + && ( + oscStates[1].fastOSC < oscStates[3].fastOSC + || oscStates[1].fastOSC < oscStates[4].fastOSC + ); + + // + isOSCPowerTrendUp = + oscStates[1].powerOSC > oscStates[2].powerOSC + && oscStates[1].powerOSC > oscStates[3].powerOSC; + + // + isOSCPowerTrendDown = + oscStates[1].powerOSC < oscStates[2].powerOSC + && oscStates[1].powerOSC < oscStates[3].powerOSC; + + // + for (int i = 0; i < marketLen; i++) { + // + minOSCPower = + minOSCPower == 0 + || oscStates[i].powerOSC < minOSCPower + ? + oscStates[i].powerOSC + : + minOSCPower + ; + + // + maxOSCPower = + maxOSCPower == 0 + || oscStates[i].powerOSC > maxOSCPower + ? + oscStates[i].powerOSC + : + maxOSCPower + ; + } + + // + // now Check Min and Max Direction and Compare them with Ranging Value ... + isOSCMarketRanging = + MathAbs(minOSCPower) <= minPowOSC + || MathAbs(maxOSCPower) <= minOSCPower; + // + // END OSC Calculations ... + // + + // + // START XMA Calculations ... + // + // + // Check SC Fast Cross Over Slow ... + isSCFastCrossOverSlow = + xmaStates[1].scFast > xmaStates[1].scSlow + && !(xmaStates[2].scFast >= xmaStates[2].scSlow); + + // + // Setting Date Time ... + if (isSCFastCrossOverSlow) { + // + lastSCFastCrossOverSlowTime = scFastCrossOverSlowTime; + scFastCrossOverSlowTime = barTime; + } + int scFastCrossOverSlowBarIndex = iBarShift( + _Symbol, + _Period, + scFastCrossOverSlowTime, + false + ); + int lastSCFastCrossOverSlowTimeBarIndex = iBarShift( + _Symbol, + _Period, + lastSCFastCrossOverSlowTime, + false + ); + isSCFastCrossOverSlowValid = + lastSCFastCrossOverSlowTimeBarIndex - scFastCrossOverSlowBarIndex > (scFastMul * marketLen); + + // + // Check SC Fast Cross Under Slow ... + isSCFastCrossUnderSlow = + xmaStates[1].scFast < xmaStates[1].scSlow + && !(xmaStates[2].scFast <= xmaStates[2].scSlow); + + // + // Setting Date Time ... + if (isSCFastCrossUnderSlow) { + // + lastSCFastCrossUnderSlowTime = scFastCrossUnderSlowTime; + scFastCrossUnderSlowTime = barTime; + } + int scFastCrossUnderSlowBarIndex = iBarShift( + _Symbol, + _Period, + scFastCrossUnderSlowTime, + false + ); + int lastSCFastCrossUnderSlowBarIndex = iBarShift( + _Symbol, + _Period, + lastSCFastCrossUnderSlowTime, + false + ); + isSCFastCrossUnderSlowValid = + lastSCFastCrossUnderSlowBarIndex - scFastCrossUnderSlowBarIndex > (scFastMul * marketLen); + + // + isSCTrendUp = + xmaStates[1].scFast > xmaStates[1].scSlow + && xmaStates[2].scFast > xmaStates[2].scSlow + && xmaStates[3].scFast > xmaStates[3].scSlow; + + // + isSCTrendDown = + xmaStates[1].scFast < xmaStates[1].scSlow + && xmaStates[2].scFast < xmaStates[2].scSlow + && xmaStates[3].scFast < xmaStates[3].scSlow; + + // + // Check MC Fast Cross Over Slow ... + isMCFastCrossOverSlow = + xmaStates[1].mcFast > xmaStates[1].mcSlow + && !(xmaStates[2].mcFast >= xmaStates[2].mcSlow); + + // + // Setting Date Time ... + if (isMCFastCrossOverSlow) { + // + lastMCFastCrossOverSlowTime = mcFastCrossOverSlowTime; + mcFastCrossOverSlowTime = barTime; + } + int mcFastCrossOverSlowBarIndex = iBarShift( + _Symbol, + _Period, + mcFastCrossOverSlowTime, + false + ); + int lastMCFastCrossOverSlowBarIndex = iBarShift( + _Symbol, + _Period, + lastMCFastCrossOverSlowTime, + false + ); + isMCFastCrossOverSlowValid = + lastMCFastCrossOverSlowBarIndex - mcFastCrossOverSlowBarIndex > (mcFastMul * marketLen); + + // + // Check MC Fast Cross Under Slow ... + isMCFastCrossUnderSlow = + xmaStates[1].mcFast < xmaStates[1].mcSlow + && !(xmaStates[2].mcFast <= xmaStates[2].mcSlow); + + // + // Setting Date Time ... + if (isMCFastCrossUnderSlow) { + // + lastMCFastCrossUnderSlowTime = mcFastCrossUnderSlowTime; + mcFastCrossUnderSlowTime = barTime; + } + int mcFastCrossUnderSlowBarIndex = iBarShift( + _Symbol, + _Period, + mcFastCrossUnderSlowTime, + false + ); + int lastMCFastCrossUnderSlowBarIndex = iBarShift( + _Symbol, + _Period, + lastMCFastCrossUnderSlowTime, + false + ); + isMCFastCrossUnderSlowValid = + lastMCFastCrossUnderSlowBarIndex - mcFastCrossUnderSlowBarIndex > (mcFastMul * marketLen); + + // + // Reset Arrays if Cross Over Happens ... + if ( + isMCFastCrossOverSlow + // || isMCFastCrossUnderSlow + ) { + // + ArrayFree(mcTrendPowers); + ArrayFree(marketMiddles); + } + + // + double tempMCTrendPowers[]; + if ( + isNewBar + || ArraySize(mcTrendPowers) == 0 + ) { + // + ArrayResize( + tempMCTrendPowers, + ArraySize(mcTrendPowers) + ); + ArrayCopy( + tempMCTrendPowers, + mcTrendPowers, + 0, + 0 + ); + + // + ArrayResize( + mcTrendPowers, + ArraySize(mcTrendPowers) + 1 + ); + } + + // + double tempMarketMiddles[]; + if ( + isNewBar + || ArraySize(marketMiddles) == 0 + ) { + // + ArrayResize( + tempMarketMiddles, + ArraySize(marketMiddles) + ); + ArrayCopy( + tempMarketMiddles, + marketMiddles, + 0, + 0 + ); + + // + ArrayResize( + marketMiddles, + ArraySize(marketMiddles) + 1 + ); + } + + // + double mcPow = MathAbs( + xmaStates[1].mcFast - xmaStates[1].mcSlow + ); + mcTrendPowers[bar_index] = mcPow; + ArrayCopy( + mcTrendPowers, + tempMCTrendPowers, + bar_index + 1, + bar_index + ); + ArrayFree(tempMCTrendPowers); + + // + double marketMiddleage = xmaStates[0].marketMiddleage; + marketMiddles[bar_index] = marketMiddleage; + ArrayCopy( + marketMiddles, + tempMarketMiddles, + bar_index + 1, + bar_index + ); + ArrayFree(tempMCTrendPowers); + + // + XMinMax mcTrendMinMax = GetBufferMinMax(mcTrendPowers); + XMinMax marketMiddlesMinMax = GetBufferMinMax(marketMiddles); + + // + isMCTrendUp = + xmaStates[1].mcFast > xmaStates[1].mcSlow + && xmaStates[2].mcFast > xmaStates[2].mcSlow + && xmaStates[3].mcFast > xmaStates[3].mcSlow; + + // + isMCTrendDown = + xmaStates[1].mcFast < xmaStates[1].mcSlow + && xmaStates[2].mcFast < xmaStates[2].mcSlow + && xmaStates[3].mcFast < xmaStates[3].mcSlow; + + // + // Market Middleage Length ... + int marketMiddleageLength = (int)(marketLen * 1.5); + + // + // Check Market Middleage Cross Over MC Fast ... + isMarketMiddleCrossOverMCFast = + xmaStates[1].marketMiddleage > xmaStates[1].mcFast + && !(xmaStates[2].marketMiddleage >= xmaStates[2].mcFast) + && !(xmaStates[3].marketMiddleage >= xmaStates[3].mcFast) + ; + + // + // Setting Date Time ... + if (isMarketMiddleCrossOverMCFast) { + // + lastMarketMiddleCrossOverMCFastTime = marketMiddleCrossOverMCFastTime; + marketMiddleCrossOverMCFastTime = barTime; + } + int marketMiddleCrossOverMCFastBarIndex = iBarShift( + _Symbol, + _Period, + marketMiddleCrossOverMCFastTime, + false + ); + int lastMarketMiddleCrossOverMCFastBarIndex = iBarShift( + _Symbol, + _Period, + lastMarketMiddleCrossOverMCFastTime, + false + ); + isMarketMiddleCrossOverMCFastValid = + lastMarketMiddleCrossOverMCFastBarIndex - marketMiddleCrossOverMCFastBarIndex > (marketMiddleageLength); + + // + // Check Market Middleage Cross Over MC Slow ... + isMarketMiddleCrossOverMCSlow = + xmaStates[1].marketMiddleage > xmaStates[1].mcSlow + && !(xmaStates[2].marketMiddleage >= xmaStates[2].mcSlow) + && !(xmaStates[3].marketMiddleage >= xmaStates[3].mcSlow) + ; + + // + // Setting Date Time ... + if (isMarketMiddleCrossOverMCSlow) { + // + lastMarketMiddleCrossOverMCSlowTime = marketMiddleCrossOverMCSlowTime; + marketMiddleCrossOverMCSlowTime = barTime; + } + int marketMiddleCrossOverMCSlowBarIndex = iBarShift( + _Symbol, + _Period, + marketMiddleCrossOverMCSlowTime, + false + ); + int lastMarketMiddleCrossOverMCSlowBarIndex = iBarShift( + _Symbol, + _Period, + lastMarketMiddleCrossOverMCSlowTime, + false + ); + isMarketMiddleCrossOverMCSlowValid = + lastMarketMiddleCrossOverMCSlowBarIndex - marketMiddleCrossOverMCSlowBarIndex > (marketMiddleageLength); + + // + // Check Market Middleage Cross Under MC Fast ... + isMarketMiddleCrossUnderMCFast = + xmaStates[1].marketMiddleage < xmaStates[1].mcFast + && !(xmaStates[2].marketMiddleage <= xmaStates[2].mcFast) + && !(xmaStates[3].marketMiddleage <= xmaStates[3].mcFast) + ; + + // + // Setting Date Time ... + if (isMarketMiddleCrossUnderMCFast) { + // + lastMarketMiddleCrossUnderMCFastTime = marketMiddleCrossUnderMCFastTime; + marketMiddleCrossUnderMCFastTime = barTime; + } + int marketMiddleCrossUnderMCFastBarIndex = iBarShift( + _Symbol, + _Period, + marketMiddleCrossUnderMCFastTime, + false + ); + int lastMarketMiddleCrossUnderMCFastBarIndex = iBarShift( + _Symbol, + _Period, + lastMarketMiddleCrossUnderMCFastTime, + false + ); + isMarketMiddleCrossUnderMCFastValid = + lastMarketMiddleCrossUnderMCFastBarIndex - marketMiddleCrossUnderMCFastBarIndex > (marketMiddleageLength); + + // + // Check Market Middleage Cross Under MC Slow ... + isMarketMiddleCrossUnderMCSlow = + xmaStates[1].marketMiddleage < xmaStates[1].mcSlow + && !(xmaStates[2].marketMiddleage <= xmaStates[2].mcSlow) + && !(xmaStates[3].marketMiddleage <= xmaStates[3].mcSlow) + ; + + // + // Setting Date Time ... + if (isMarketMiddleCrossUnderMCSlow) { + // + lastMarketMiddleCrossUnderMCSlowTime = marketMiddleCrossUnderMCSlowTime; + marketMiddleCrossUnderMCSlowTime = barTime; + } + int marketMiddleCrossUnderMCSlowBarIndex = iBarShift( + _Symbol, + _Period, + marketMiddleCrossUnderMCSlowTime, + false + ); + int lastMarketMiddleCrossUnderMCSlowBarIndex = iBarShift( + _Symbol, + _Period, + lastMarketMiddleCrossUnderMCSlowTime, + false + ); + isMarketMiddleCrossUnderMCSlowValid = + lastMarketMiddleCrossUnderMCSlowBarIndex - marketMiddleCrossUnderMCSlowBarIndex > (marketMiddleageLength); + + // + isParabolicCrossOverMarketMiddle = + xmaStates[1].parabolicSAR > xmaStates[1].marketMiddleage + && !(xmaStates[2].parabolicSAR >= xmaStates[2].marketMiddleage); + + // + if (isParabolicCrossOverMarketMiddle) { + // + lastParabolicCrossOverMarketMiddleTime = parabolicCrossOverMarketMiddleTime; + parabolicCrossOverMarketMiddleTime = barTime; + } + + // + // Find Distance between two Parabolic Cross ... + int parabolicCrossOverMarketMiddleBarIndex = iBarShift( + _Symbol, + _Period, + parabolicCrossOverMarketMiddleTime, + false + ); + int lastParabolicCrossOverMarketMiddleBarIndex = iBarShift( + _Symbol, + _Period, + lastParabolicCrossOverMarketMiddleTime, + false + ); + isParabolicCrossOverMarketMiddleValid = + lastParabolicCrossOverMarketMiddleBarIndex - parabolicCrossOverMarketMiddleBarIndex > marketLen; + + // + isParabolicCrossUnderMarketMiddle = + xmaStates[1].parabolicSAR < xmaStates[1].marketMiddleage + && !(xmaStates[2].parabolicSAR <= xmaStates[2].marketMiddleage); + + // + if (isParabolicCrossUnderMarketMiddle) { + // + lastParabolicCrossUnderMarketMiddleTime = parabolicCrossUnderMarketMiddleTime; + parabolicCrossUnderMarketMiddleTime = barTime; + } + + // + // Find Distance between two Parabolic Cross ... + int parabolicCrossUnderMarketMiddleBarIndex = iBarShift( + _Symbol, + _Period, + parabolicCrossUnderMarketMiddleTime, + false + ); + int lastParabolicCrossUnderMarketMiddleBarIndex = iBarShift( + _Symbol, + _Period, + lastParabolicCrossUnderMarketMiddleTime, + false + ); + isParabolicCrossUnderMarketMiddleValid = + lastParabolicCrossUnderMarketMiddleTime - parabolicCrossUnderMarketMiddleTime > marketLen; + + // + isParabolicTrendUp = + xmaStates[1].parabolicSAR > xmaStates[1].marketMiddleage + && xmaStates[2].parabolicSAR > xmaStates[2].marketMiddleage; + + // + isParabolicTrendDown = + xmaStates[1].parabolicSAR < xmaStates[1].marketMiddleage + && xmaStates[2].parabolicSAR < xmaStates[2].marketMiddleage; + + // + // Check LC Fast Cross Over Slow ... + isLCFastCrossOverSlow = + xmaStates[1].lcFast > xmaStates[1].lcSlow + && !(xmaStates[2].lcFast >= xmaStates[2].lcSlow); + + // + // Setting Date Time ... + if (isLCFastCrossOverSlow) { + // + lastLCFastCrossOverSlowTime = lcFastCrossOverSlowTime; + lcFastCrossOverSlowTime = barTime; + } + + // + // Check LC Fast Cross Under Slow ... + isLCFastCrossUnderSlow = + xmaStates[1].lcFast < xmaStates[1].lcSlow + && !(xmaStates[2].lcFast <= xmaStates[2].lcSlow); + + // + // Setting Date Time ... + if (isLCFastCrossUnderSlow) { + // + lastLCFastCrossUnderSlowTime = lcFastCrossUnderSlowTime; + lcFastCrossUnderSlowTime = barTime; + } + + // + // Check Market Middleage Trends Up ... + isMarketMiddleageTrendUp = + xmaStates[0].marketMiddleage > xmaStates[1].marketMiddleage + && xmaStates[0].marketMiddleage > xmaStates[2].marketMiddleage + && xmaStates[0].marketMiddleage > xmaStates[3].marketMiddleage + && xmaStates[1].marketMiddleage > xmaStates[2].marketMiddleage + && xmaStates[1].marketMiddleage > xmaStates[3].marketMiddleage + && xmaStates[2].marketMiddleage > xmaStates[3].marketMiddleage; + + // + // Check Market Middleage Trends Down ... + isMarketMiddleageTrendDown = + xmaStates[0].marketMiddleage < xmaStates[1].marketMiddleage + && xmaStates[0].marketMiddleage < xmaStates[2].marketMiddleage + && xmaStates[0].marketMiddleage < xmaStates[3].marketMiddleage + && xmaStates[1].marketMiddleage < xmaStates[2].marketMiddleage + && xmaStates[1].marketMiddleage < xmaStates[3].marketMiddleage + && xmaStates[2].marketMiddleage < xmaStates[3].marketMiddleage; + // + // END XMA Calculations ... + // + + // + // START PRICE Calculations ... + // + RefreshRates(); + + // + // double candleOpen = iOpen( + // _Symbol, + // _Period, + // bar_index + // ); + + // + double marketLow[]; + double marketOpen[]; + double marketHigh[]; + double marketClose[]; + ArrayResize( + marketLow, + marketLen + ); + ArrayResize( + marketOpen, + marketLen + ); + ArrayResize( + marketHigh, + marketLen + ); + ArrayResize( + marketClose, + marketLen + ); + for (int i = bar_index; i < marketLen + bar_index - 1; i++) { + // + marketLow[i] = iLow( + _Symbol, + _Period, + i + ); + + // + marketOpen[i] = iOpen( + _Symbol, + _Period, + i + ); + + // + marketHigh[i] = iHigh( + _Symbol, + _Period, + i + ); + + // + marketClose[i] = iClose( + _Symbol, + _Period, + i + ); + } + + // + // Retrieve Market Price Actions Min/Max ... + XMinMax marketLowMinMax = GetBufferMinMax(marketLow); + XMinMax marketHighMinMax = GetBufferMinMax(marketHigh); + XMinMax marketOpenMinMax = GetBufferMinMax(marketOpen); + XMinMax marketCloseMinMax = GetBufferMinMax(marketClose); + + // + isSharpBullishHappens = IsSharpBullishHappens( + bar_index, + marketLen + ); + + // + isSharpBearishHappens = IsSharpBearishHappens( + bar_index, + marketLen + ); + + // + // LONG Prices ... + double longEntryPrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK); + double longClosePrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); + double longPriceGap = longClosePrice - longEntryPrice; + + // + // SHORT Prices ... + double shortEntryPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); + double shortClosePrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK); + double shortPriceGap = shortEntryPrice - shortClosePrice; + // + // END PRICE Calculations ... + // + + // + // START Capturing Signal ... + // + + // + // START LONG Signals ... + // + // + // OSC ... + bool oscHasLongSignal = + // + // Check Power OSC Cross Over 0 ... + oscStates[1].powerOSC > 0 + && oscStates[2].powerOSC < 0 + && MathAbs(oscStates[1].powerOSC) > minPowOSC + && MathAbs(oscStates[2].powerOSC) > minPowOSC + // + // Check MC Market Trending Up ... + && xmaStates[1].mcFast > xmaStates[1].mcSlow + // + // Check Parabolic below market miidleage ... + && xmaStates[1].parabolicSAR < xmaStates[1].marketMiddleage + && xmaStates[2].parabolicSAR < xmaStates[2].marketMiddleage + // + // Check Parabolic Value bigger than MC Slow ... + && xmaStates[1].parabolicSAR > xmaStates[1].mcSlow + // + // Check Distance between two Parabolic Cross Under + // Market Middleage or current barIndex and current Cross is Valid or not ... + && ( + isParabolicCrossUnderMarketMiddleValid + || parabolicCrossUnderMarketMiddleBarIndex - bar_index > marketLen + ) + // + // Check Market Middleage not Max ... + && xmaStates[1].marketMiddleage < marketMiddlesMinMax.max + // + // Check Entry Price Lower than Market Highest High ... + && longEntryPrice < marketHighMinMax.max + && MathAbs(longEntryPrice - marketHighMinMax.max) > (5 * _Point) + // + // We Have to prevent signaling when a Bullish Sharp occured ... + && !isSharpBullishHappens; + + // + bool hasLongSignal = + // + // OSC Signals ... + oscHasLongSignal + ; + // + // END LONG Signals ... + // + + // + // START SHORT Signals ... + // + bool hasShortSignal = false; + // + // END SHORT Signals ... + // + + // + // Check Signal Exists regardless of Long or Short ... + bool hasSignal = hasLongSignal || hasShortSignal; + + // + // Prevent from Going forward if there is not a Signal ... + if (!hasSignal) { + // + result.signal = signal; + return result; + } + + // + totalSignals++; + + // + // Define Price Related Variables ... + // + double price = 0; + double priceGap; + double sl = 0; + double risk; + double reward; + double tp = 0; + double r2rRatio = r2r; + + // + datetime time = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Fill Signal Related Variables ... + if (hasLongSignal) { + // + totalLongSignals++; + + // + price = longEntryPrice; + priceGap = longPriceGap; + + // // + // // Setting Up SL Based on Prev Candle ... + // sl = prevCandleLow; + + // + // Setting Up SL Based on Last Market Lowest ... + sl = GetMarketLowestLow( + bar_index, + marketLen + ); + + // // + // // Setting Up SL Based on Prev Candle Less Low Price ... + // sl = GetLowLessCandlePrice( + // bar_index, + // price + // ); + + // + // if (isSharpBearishHappens) { + // sl = marketLow[1]; + // } + + // + risk = price - sl; + + // // + // // here we calculate risk based on candle open ... + risk = marketOpen[0] - sl; + + // + reward = risk * r2rRatio; + tp = price + reward; + + // + // Check TP Touches before add in Market length + // based on Passed Candles ... + double passCandleReverseHighestHigh = GetMarketHighestHigh(0, reverseLookupInMarket); + if (tp > passCandleReverseHighestHigh) { + tp = passCandleReverseHighestHigh + (5 * _Point); + } + + // + // if (oscHasLongSignal) { + // tp = price + PipsToPrice(1); + // } + + // + // Check TP based on Spread ... + if (tp < price + priceGap) { + tp = tp + priceGap; + } + } else if (hasShortSignal) { + // + totalShortSignals++; + + // + price = shortEntryPrice; + priceGap = shortPriceGap; + + // // + // // Setting Up SL Based On Prev Candle ... + // sl = prevCandleHigh; + + // // + // // Setting Up SL Based on Last Market Highest ... + // sl = GetMarketHighestHigh( + // bar_index, + // marketLen + // ); + + // + // Setting Up SL Based on Prev Candle Great High Price ... + // sl = GetHighGreatCandlePrice( + // bar_index, + // price + // ); + + // + // Settup SL based On Parabolic SAR ... + //sl = xmaStates[0].parabolicSAR; + + // + risk = sl - price; + reward = risk * r2r; + tp = price - reward; + } + + // + // Normalize Prices ... + price = NormalizeDouble(price, _Digits); + sl = NormalizeDouble(sl, _Digits); + tp = NormalizeDouble(tp, _Digits); + + // + // Generate Signal Structure ... + signal.type = hasLongSignal ? + X_LONG : + X_SHORT; + signal.tp = tp; + signal.sl = 0; // sl; + signal.time = time; + signal.symbol = _Symbol; + signal.entryPrice = price; + signal.id = totalLongSignals; + // + // END Capturing Signal ... + // + + // + // Fill Result ... + result.hasSignal = hasSignal; + result.signal = signal; + result.type = signal.type; + + // + // Return Result ... + return result; +} + +// +// START Signal Verification Functions ... +// +// +// END Signal Verification Functions ... +// + +// +// START Market State Functions ... +// +// +// END Market State Functions ... +// + +// +// Retrieve Signal Bar Index ... +int GetSignalBarIndex(XSignal &signal) { + // + // Temp Result ... + int result = -1; + + // + // Retriev Signal Bar Index ... + result = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + return result; +} + +// +// Generate a Unique ID for Signal ... +string GenerateSignalTAG( + const XSignal &signal, + const string tag, + const string longSignalLabel, + const string shortSignalLabel +) { + // + // Generate Propper Label for Signal ... + string label = signal.type == X_LONG ? longSignalLabel : signal.type == X_SHORT ? shortSignalLabel : "UN_KNOWN"; + + // + // Generate Unique String Identifier for Signal ... + string result = tag + + "_[ID:" + IntegerToString(signal.id) + "]" + + "_[" + label + "]" + + "_[" + signal.symbol + "]" + + "_[Time:" + TimeToStr(signal.time) + "]" + + "_[TP:" + DoubleToString(signal.tp) + "]" + + "_[SL:" + DoubleToString(signal.sl) + "]"; + + // + return result; +} + +// +// Draw Signal Shapes on Chart ... +bool DrawSignal( + const XSignal &signal, + long chartID = 0, + int subWindowID = 0, + const double positionThresholdFactor = 10, + string signalTag = "X-Signal", + string longSignalLabel = "X-Long", + color longSignalColor = clrAqua, + string shortSignalLabel = "X-Short", + color shortSignalColor = clrFuchsia +) { + // + // Generate isLongSignal Var ... + bool isLongSignal = signal.type == X_LONG; + + // + // Signal Bar Index ... + int bar_index = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // START Draw Signal Arrow ... + // + // + // Arrow Shape Name ... + string arrowName = StringConcatenate(signalTag, "_Arrow_", signal.id); + + // + // Arrow Price ... + double arrowPrice = 0; + if (isLongSignal) { + // + arrowPrice = iLow( + _Symbol, + _Period, + bar_index + ); + + // + arrowPrice = arrowPrice - (positionThresholdFactor * _Point); + } else { + // + arrowPrice = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + arrowPrice = arrowPrice + (positionThresholdFactor * _Point); + } + + // + // Arrow Code ... + uchar arrowCode = isLongSignal ? SYMBOL_ARROWUP : SYMBOL_ARROWDOWN; + + // + // Arrow Anchor Point ... + ENUM_ARROW_ANCHOR arrowAnchorPoint = isLongSignal ? ANCHOR_BOTTOM : ANCHOR_TOP; + + // + // Arrow Color ... + color arrowColor = isLongSignal ? longSignalColor : shortSignalColor; + + // + // Draw Signal Arrow Shape ... + bool result = DrawArrow( + chartID, + arrowName, + subWindowID, + signal.time, + arrowPrice, + arrowCode, + arrowAnchorPoint, + arrowColor, + STYLE_SOLID, + 3, + false, + false, + false, + 0 + ); + // + // END Draw Signal Arrow ... + // + + // + // START Draw Signal SL/TP ... + // + string slLineName = StringConcatenate(signalTag, "_SL_", signal.id); + string tpLineName = StringConcatenate(signalTag, "_TP_", signal.id); + string entryLineName = StringConcatenate(signalTag, "_ENTRY_", signal.id); + + // + color slColor = shortSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color tpColor = longSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color entryColor = clrGreen; + + // + datetime time1 = iTime( + _Symbol, + _Period, + bar_index + 1 + ); + + // + // Draw Enrty Price ... + result = DrawTrendLine( + chartID, + entryLineName, + subWindowID, + time1, + signal.entryPrice, + signal.time, + signal.entryPrice, + entryColor, + STYLE_SOLID, + 2 + ); + + // + // Draw Signal SL ... + if (signal.sl > 0) { + // + result = DrawTrendLine( + chartID, + slLineName, + subWindowID, + time1, + signal.sl, + signal.time, + signal.sl, + slColor, + STYLE_SOLID, + 2 + ); + } + + // + // Draw Signal TP ... + if (signal.tp > 0) { + // + result = DrawTrendLine( + chartID, + tpLineName, + subWindowID, + time1, + signal.tp, + signal.time, + signal.tp, + tpColor, + STYLE_SOLID, + 2 + ); + } + // + // END Draw Signal SL/TP ... + // + + // + // Start Draw Signal Label ... + // + // + string labelName = StringConcatenate(signalTag, "_Label_", signal.id); + + // + double labelPrice = isLongSignal ? arrowPrice - (positionThresholdFactor * _Point) : arrowPrice + (positionThresholdFactor * _Point); + + // + string labelText = isLongSignal ? longSignalLabel : shortSignalLabel; + + // + result = DrawText( + chartID, + labelName, + subWindowID, + signal.time, + labelPrice, + labelText, + "Arial", + 10, + arrowColor, + 0, + ANCHOR_CENTER + ); + // + // End Draw Signal Label ... + // + + // + return result; +} + +// +// Trade on Specific Signal ... +bool TradeSignal( + XSignal &signal, + // + string prefix, + // + double volumePercent, + // + // Long ... + const string longSignalLabel, + const color longSignalColor, + // + // Short ... + const string shortSignalLabel, + const color shortSignalColor +) { + // + // Temp Result ... + bool result = false; + + // + if (initialBalance == 0) { + initialBalance = AccountInfoDouble(ACCOUNT_BALANCE); + } + + // + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + int openPositions = CountOpenTrades(); + double volume = (volumePercent * initialBalance); + + // + if ( + signal.type != X_LONG && + signal.type != X_SHORT + ) { + return result; + } + + // + bool hasLongSignal = signal.type == X_LONG; + + // + // Check TP and Entry Price ... + if ( + ( + hasLongSignal + && signal.entryPrice > signal.tp + ) || + ( + !hasLongSignal + && signal.entryPrice < signal.tp + ) + ) { + return result; + } + + // + // Order Operation ... + int operation = hasLongSignal ? + OP_BUY : + OP_SELL; + + // + // Detect Trade Color ... + color clr = hasLongSignal ? + longSignalColor : + shortSignalColor; + + // + // Generate Signal Comment ... + string label = hasLongSignal ? + longSignalLabel : + shortSignalLabel; + + // + // Generate Signal Comment ... + string comment = StringConcatenate( + prefix, + "_", signal.id, "_", + label + ); + + // + // Placing Order ... + int orderTicket = OrderSend( + _Symbol, + operation, + volume, + signal.entryPrice, + 3, + signal.sl, + signal.tp, + comment, + signal.id, + 0, + clr + ); + + // + // Draw Signal Shape if Order Opened Successfully ... + if (orderTicket >= 0) { + // + // Here i must to Draw Signal Shapes ... + DrawSignal( + signal, + 0, + 0, + 50, + prefix, // Signal Tag ... + longSignalLabel, // Long Signal Label ... + longSignalColor, + shortSignalLabel, // Short Signal Label ... + shortSignalColor + ); + + // + // TODO: here we have to check if there are another + // open positions which their entry price is bigger + // than current signal entry price, for long trades and + // their tp is high than current tp, ... + // close in profit trades or modify orders tp to current ... + // + if (CountOpenTrades() > 0) { + // + // Here we have to + // ModifyOpenTradesBasedOnCurrentTrade(signal); + } + + // + result = true; + } + + // + return result; +} +// +// END Signal Related Functions ... +// + +// +// START Orders Functions ... +// +// +// Convert To XSignal Model ... +XSignal OrderToSignal() { + // + // Temp Result ... + XSignal result = {}; + result.type = X_NONE; + + // + // Here we can get some usefull info based on selected order ... + double swap = OrderSwap(); + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + int magicNumber = OrderMagicNumber(); + double takeProfit = OrderTakeProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // Conver Position to Signal ... + result.sl = stopLoss; + result.tp = takeProfit; + result.time = openTime; + result.symbol = _Symbol; + result.id = magicNumber; + result.entryPrice = openPrice; + result.type = isLongOrder ? X_LONG : X_SHORT; + + // + return result; +} + +// +// START Count Orders ... +// +// +// Count Open Positions ... +int CountOpenTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if (OrderSymbol() == _Symbol) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Long Positions ... +int CountOpenLongTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_BUY + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Short Positions ... +int CountOpenShortTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_SELL + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} +// +// END Count Orders ... +// + +// +// START Close Orders ... +// +// +// Close All Open Trades ... +bool CloseAllTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + + // + return result; +} + +// +// Close All Open Long Trades ... +bool CloseAllLongTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Long Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Short Trades ... +bool CloseAllShortTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (!isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Short Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In Profit Trades ... +bool CloseAllInProfitTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if (profit > 0) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InProfit Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In DrawDown Trades ... +bool CloseAllInDrawDownTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if (profit < 0) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close Biggest In DrawDown Trades ... +bool CloseBiggestDrawDownTrade() { + // + // Loop through all Positions ... + bool result = false; + double drawDown = 0; + + // + // Find Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) > drawDown + ) { + drawDown = profit; + } + } + } + } + + // + // Close Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) >= drawDown + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Max InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Long Time Trades ... +bool CloseAllLongTimeTrades( + const int passedCandles +) { + // + bool result = false; + + // + if (passedCandles <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + + // + if ( + openBarIndex - currentBarIndex >= passedCandles + || ( + profit > 0.5 + && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 3) + ) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Long Time issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } else if ( + openTrades > 0 + && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 2) + ) { + result = CloseAllInProfitTrades() + && CloseBiggestDrawDownTrade(); + } + } + } + } + + // + return result; +} + +// +// Close all trades which passed Maximum Drawdown ... +bool CloseAllMaximumDrawDownPassedTrades( + const double maxDrDownPercentPerPTrade +) { + // + if ( + initialBalance <= 0 + || maxDrDownPercentPerPTrade <= 0 + ) { + return false; + } + + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double maxAllowedDrawDown = -1 * (initialBalance * maxDrDownPercentPerPTrade); + + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + if ( + profit < 0 + && MathAbs(profit) >= MathAbs(maxAllowedDrawDown) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Maximum DarwDown issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Trades Which Opens before Specified Length ... +bool CloseAllTradesWhichOpenInPastMarketLength( + const int marketLen +) { + // + bool result = false; + + // + if (marketLen <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + + // + if (openBarIndex <= currentBarIndex + marketLen) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Market Reverse issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } else if (openTrades > 0) { + // + // Close all InProfit Trdes and Biggest InDrawDown Trades ... + result = CloseAllInProfitTrades() + && CloseBiggestDrawDownTrade(); + } + } + } + } + + // + return result; +} +// +// END Close Orders ... +// + +// +// START Modify Orders ... +// +// +void ModifyAllPriceLesserOpenTrades( + const XSignal &signal +) { + // + // Loop through all Open Trades ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + double takeProfit = OrderTakeProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // When new Signal Comming with price less than + // currently open trade and tp less than currently + // open trade, this means a market change happens ... + // here we can Close InProfit Trades or Modify Trades TP ... + if ( + openPrice < signal.entryPrice + && takeProfit > signal.tp + ) { + bool result = OrderModify( + ticket, + openPrice, + signal.sl, + signal.tp, + clrYellow + ); + } + } + } + } +} + +// +void ModifyOpenTradesBasedOnCurrentTrade( + const XSignal &signal +) { + // + ModifyAllPriceLesserOpenTrades(signal); +} +// +// END Modify Orders ... +// +// +// END Orders Functions ... +// diff --git a/Bkp/Used/OSC EA/Experts/x-saherelm.osc.ea.mq4 b/Bkp/Used/OSC EA/Experts/x-saherelm.osc.ea.mq4 new file mode 100644 index 0000000..5e1f2ed --- /dev/null +++ b/Bkp/Used/OSC EA/Experts/x-saherelm.osc.ea.mq4 @@ -0,0 +1,784 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XST_OSC Strategy Expert Advisor +// --------------------------------------------- +// saherelm implementation of strategy expert advisor ... +// +// ShortName: XST_OSC +// +// 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 XST_OSC Strategy Expert Advisor" +#property strict + +// +// START Inputs ... +// +// +// Signal Prefixe ... +input string signalPrefix = "XST_OSC"; // Signal Prefix + +// +// Signal Draw Specifications ... +input string bullishSignalLabel = "X_BUY"; // Bullish Signal Label +input color bullishSignalColor = clrAqua; // Bullish Signal Color + +// +input string bearishSignalLabel = "X_SELL"; // Bearish Signal Label +input color bearishSignalColor = clrFuchsia; // Bearish Signal Color + +// +input color signalEntryColor = clrAquamarine; // Signal Entry Ptice Color +input color signalSLColor = clrRed; // Signal SL Color +input color signalTPColor = clrGreen; // Signal TP Color + +// +// Trade ... +input bool allowTrade = true; // Allow Trade Based on given Signals +input bool allowLongTrades = true; // Allow Long Trades +input bool allowShortTrades = false; // Allow Short Trades + +// +// Market Specification Inpouts ... +input int marketLength = 7; // Market Length +input double riskToRewardRatio = 2; // Risk to Reward Ratio + +// +// Alerts ... +input bool alertEvents = true; // Alert Events +input bool alertPositions = true; // Alert Positions +input bool longPositionAlerts = true; // Alert Long Positions +input bool shortPositionAlerts = true; // Alert Short Positions + +// +// Alert Types ... +input bool terminalAlert = false; // Terminal Alert +input bool pushAlert = false; // Push Notification Alerts + +// +// Balance and Finanical Specifications ... +input double lotsPerTradePercent = 0.00001; // Lots Per Trade Percent +input int maxOpenTrades = 4; // Maximum Open Trade +input double maxDrawdownPercentPerPTrade = 0.1; // Maximum DrawDown Per Trade +input double minBalancePercent = 0.5; // Minimum Balance for Trading +input double maxEquityPercent = 0.1; // Maximum Trade Equity +input int closeAllOpenTradesAfterCandle = 864; // Close All Open Trades After Passed Candles + +// +// OSC Inputs ... +// +// FastOSC ... +// Short Cycle (Fast OSC) ... +input int fastOSCLength = 7; // FastOSC Length +input double fastOSCMultiplier = 1.0; // FastOSC Multiplier + +// +// SlowOSC ... +// Medium Cycle (Slow OSC) ... +input int slowOSCLength = 14; // SlowOSC Length +input double slowOSCMultiplier = 3.0; // SlowOSC Multiplier + +// +// Power OSC ... +input double minPowerOSC = 0.055; // Minimum Signal Power + +// +// Variance OSC ... +input double minVarianceOSC = 0; // Minimum Var Power + +// +// ZIGZAG Inputs ... +input int zDeviation = 5; // ZigZag Deviation +input int zBackStep = 3; // ZigZag Back Step + +// +// XMA Inputs ... +// +input int shortCycleFastMultiplier = 1; // Short Cycle Fast Multiplier +input int shortCycleSlowMultiplier = 4; // Short Cycle Slow Multiplier +input int mediumCycleFastMultiplier = 7; // Medium Cycle Fast Multiplier +input int mediumCycleSlowMultiplier = 14; // Medium Cycle Slow Multiplier +input int longCycleFastMultiplier = 70; // Long Cycle Fast Multiplier +input int longCycleSlowMultiplier = 140; // Long Cycle Slow Multiplier +// +// Show/Hide Inputs ... +input bool showShortCycle = false; // Show Short Cycle +input bool showShortCycleCrossLines = false; // Show Short Cycle Vertical Lines +input bool showMediumCycle = false; // Show Medium Cycle +input bool showMediumCycleCrossLines = false; // Show Medium Cycle Vertical Lines +input bool showLongCycle = false; // Show Long Cycle +input bool showLongCycleCrossLines = false; // Show Long Cycle Vertical Lines +// +// Color Inputs ... +input color shortCycleFastColor = clrGreen; // Short Cycle Fast Color ... +input color shortCycleSlowColor = clrRed; // Short Cycle Slow Color ... +input color mediumCycleFastColor = clrAqua; // Medium Cycle Fast Color ... +input color mediumCycleSlowColor = clrFuchsia; // Medium Cycle Slow Color ... +input color longCycleFastColor = clrGoldenrod; // Medium Cycle Fast Color ... +input color longCycleSlowColor = clrBrown; // Medium Cycle Slow Color ... +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +int lastSignalledBar = 0; + +// +bool waitForLongSignals = true; +bool closeLongTrades = false; + +// +bool waitForShortSignals = true; +bool closeShortTrades = false; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.osc.signal.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Validate Inputs ... + bool inputsNotValiid = + // + // MARKET ... + marketLength < 0 + || riskToRewardRatio < 0 + // + // EA ... + || lotsPerTradePercent < 0 + || maxOpenTrades <= 0 + || maxDrawdownPercentPerPTrade < 0 + || minBalancePercent < 0 + || maxEquityPercent < 0 + || marketLength < 0 + // + // OSC ... + || fastOSCLength < 0 + || fastOSCMultiplier < 0 + || slowOSCLength < 0 + || slowOSCMultiplier < 0 + || minPowerOSC < 0 + || minVarianceOSC < 0 + || slowOSCLength <= fastOSCLength + // + // ZIGZAG ... + || zDeviation < 0 + || zBackStep < 0 + || zBackStep >= marketLength + // + // XMA ... + // + // Validate Short Cycle ... + || shortCycleFastMultiplier <= 0 + || shortCycleSlowMultiplier <= 0 + || shortCycleFastMultiplier >= shortCycleSlowMultiplier + // + // Validate Medium Cycle ... + || mediumCycleFastMultiplier <= 0 + || mediumCycleSlowMultiplier <= 0 + || mediumCycleFastMultiplier >= mediumCycleSlowMultiplier + // + // Validate Long Cycle ... + || longCycleFastMultiplier <= 0 + || longCycleSlowMultiplier <= 0 + || longCycleFastMultiplier >= longCycleSlowMultiplier + // + // Validate Series of Multipliers ... + || shortCycleFastMultiplier >= mediumCycleFastMultiplier + || mediumCycleFastMultiplier >= longCycleFastMultiplier + ; + + if (inputsNotValiid) { + return INIT_PARAMETERS_INCORRECT; + } + + // + totalSignals = 0; + totalLongSignals = 0; + totalShortSignals = 0; + + // + initialBalance = 0; + + // + // START Define Array Series ... + // + // + // END Define Array Series ... + // + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST_OSC"; + + // // + // // Set Event Timer on One Seccond ... + // bool isEventSet = EventSetTimer(1); + // if (!isEventSet) { + // LogMessage("Error: " + GetLastError()); + // return INIT_FAILED; + // } + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + // Killing Event Timer ... + EventKillTimer(); +} + +// +// Ticker Event Handler ... +void OnTick() { + // + // Checking State for Signal Handling ... + CheckState(); + + // + // Process Signals to Open Positions ... + ProcessSignals(); + + // + // Process Open Positions for Trailing Stop Loss or Close ... + ProcessOpenPositions(); +} + +// +// Timer Event Handler ... +void OnTimer() { + // + CheckState(); + + // + ProcessOpenPositions(); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Check State for Signal Handling ... +void CheckState() { + // + // Here we Must to Check Market State in Big Picture ... + + // + bool isSCFastCrossUnderSlow = xmaState.scFast < xmaState.scSlow + && !(xmaState.scFastPrev < xmaState.scSlowPrev); + + // + bool isMCFastCrossUnderSlow = xmaState.mcFast < xmaState.mcSlow + && !(xmaState.mcFastPrev < xmaState.mcSlowPrev); + + // + bool isLCFastCrossUnderSlow = xmaState.lcFast < xmaState.lcSlow + && !(xmaState.lcFastPrev < xmaState.lcSlowPrev); + + // + closeLongTrades = + ( + isSCFastCrossUnderSlow + && isMCFastCrossUnderSlow + ) + || + ( + isSCFastCrossUnderSlow + && isLCFastCrossUnderSlow + ) + || + ( + isMCFastCrossUnderSlow + && isLCFastCrossUnderSlow + ) + ; + + // + waitForLongSignals = + waitForLongSignals + ? + true + : + ( + ( + xmaState.lcFast > xmaState.lcSlow + && !(xmaState.lcFastPrev > xmaState.lcSlowPrev) + ) + || + ( + xmaState.mcFast > xmaState.mcSlow + && !(xmaState.mcFastPrev > xmaState.mcSlowPrev) + ) + ) + ; +} + +// +// Calculate Signals and Process Based on Exists Signals ... +void ProcessSignals() { + // + XSignalRequest request = {}; + request.type = X_NONE; + request.hasSignal = false; + + // + // Prevent Multiple Calculating on Same Bars ... + isNewBar = IsNewBar(); + if (isNewBar) { + // + countedBars++; + + // // + // LogMessage( + // StringConcatenate( + // "Check Signals, Bars: ", + // countedBars + // ) + // ); + + // + // Retrieve Signal Exists ... + // request = CalculateSignal( + // // + // // Bar Index ... + // 0, + // // + // // Market Specification Inpouts ... + // marketLength, // Market Length ... + // // + // // Risk To Reward Ratio ... + // riskToRewardRatio, + // // + // // XMA Inputs ... + // shortCycleFastMultiplier, // Short Cycle Fast Multiplier ... + // shortCycleSlowMultiplier, // Short Cycle Slow Multiplier ... + // mediumCycleFastMultiplier, // Medium Cycle Fast Multiplier ... + // mediumCycleSlowMultiplier, // Medium Cycle Slow Multiplier ... + // longCycleFastMultiplier, // Long Cycle Fast Multiplier ... + // longCycleSlowMultiplier, // Long Cycle Slow Multiplier ... + // // + // // Show/Hide Inputs ... + // showShortCycle, + // showShortCycleCrossLines, + // showMediumCycle, + // showMediumCycleCrossLines, + // showLongCycle, + // showLongCycleCrossLines, + // // + // // Color Inputs ... + // shortCycleFastColor, + // shortCycleSlowColor, + // mediumCycleFastColor, + // mediumCycleSlowColor, + // longCycleFastColor, + // longCycleSlowColor, + // // + // // OSC ... + // fastOSCLength, // FastOSC Length ... + // fastOSCMultiplier, // FastOSC Multiplier ... + // slowOSCLength, // SlowOSC Length ... + // slowOSCMultiplier, // SlowOSC Multiplier ... + // minPowerOSC, // Minimum Signal Power ... + // minVarianceOSC, // Minimum Var Power ... + // // + // // ZIGZAG Inputs ... + // zDeviation, // ZigZag Deviation ... + // zBackStep // ZigZag Back Step ... + // ); + } + + // + bool allowDoTrade = true; + + // + // Check Balance ... + if (initialBalance > 0) { + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double minimumBalanceForTrade = + balance > initialBalance + ? + minBalancePercent * balance + : + minBalancePercent * initialBalance; + + // + // Retrieve Account Equity ... + double equity = AccountInfoDouble(ACCOUNT_EQUITY); + double maxAllowedEquity = balance - (balance * maxEquityPercent); + + // + // Retrieve Free Marigin ... + double freeMargin = AccountFreeMargin(); + double maximumMariginRisk = balance - (balance * maxEquityPercent); + + // + if ( + // + // Do not Open Positions if equity not passed ... + equity < maxAllowedEquity || + // + // Do not Open Positions if free margin not passed ... + freeMargin <= maximumMariginRisk || + // + // Do not open positions if balance less than minimum ... + balance <= minimumBalanceForTrade + ) { + // + allowDoTrade = false; + + // // + // string message = StringConcatenate( + // "Trading Pause => ", + // "Balance: ", balance, + // ", Equity: ", equity, + // ", FreeMargin: ", freeMargin + // ); + + // // + // LogMessage(message); + // SendAlert(message); + + // + // Close In Profit Trades ... + // then Recheck Signal ... + // bool hasInProfitTradeClosed = CloseAllInProfitTrades(); + // if (hasInProfitTradeClosed) { + // ProcessSignals(); + // } + } + } + + // + // Retrieve Signal Exists ... + request = CalculateSignal( + // + // Bar Index ... + 0, + // + // Market Specification Inpouts ... + marketLength, // Market Length ... + // + // Risk To Reward Ratio ... + riskToRewardRatio, + // + // XMA Inputs ... + shortCycleFastMultiplier, // Short Cycle Fast Multiplier ... + shortCycleSlowMultiplier, // Short Cycle Slow Multiplier ... + mediumCycleFastMultiplier, // Medium Cycle Fast Multiplier ... + mediumCycleSlowMultiplier, // Medium Cycle Slow Multiplier ... + longCycleFastMultiplier, // Long Cycle Fast Multiplier ... + longCycleSlowMultiplier, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showShortCycle, + showShortCycleCrossLines, + showMediumCycle, + showMediumCycleCrossLines, + showLongCycle, + showLongCycleCrossLines, + // + // Color Inputs ... + shortCycleFastColor, + shortCycleSlowColor, + mediumCycleFastColor, + mediumCycleSlowColor, + longCycleFastColor, + longCycleSlowColor, + // + // OSC ... + fastOSCLength, // FastOSC Length ... + fastOSCMultiplier, // FastOSC Multiplier ... + slowOSCLength, // SlowOSC Length ... + slowOSCMultiplier, // SlowOSC Multiplier ... + minPowerOSC, // Minimum Signal Power ... + minVarianceOSC, // Minimum Var Power ... + // + // ZIGZAG Inputs ... + zDeviation, // ZigZag Deviation ... + zBackStep // ZigZag Back Step ... + ); + + // + // Prevent doing anything else, if there is no signals ... + if ( + !allowDoTrade || + !request.hasSignal || + request.type == X_NONE + ) { + return; + } + + // + bool hasLongSignal = request.type == X_LONG; + + // + // Check For Bot State ... + if ( + (hasLongSignal && !waitForLongSignals) + || (!hasLongSignal && !waitForShortSignals) + ) { + return; + } + + // + // Check last Signalled Bar with Counted Bars ... + // Prevent Multiple Signalling on Same Bar ... + if (lastSignalledBar == countedBars) { + // + totalSignals--; + if (hasLongSignal) { + totalLongSignals--; + } else { + totalShortSignals--; + } + return; + } + + // + // Prevent Signals if openTrades on last Market ... + // this means for each trades at least we have to wait market length passed from last signal ... + // if (lastSignalledBar + (marketLength) > countedBars) { + // return; + // } + + // + // increase last signalled bar ... + lastSignalledBar = countedBars; + + // + // Calculate Can Trade or not ... + allowDoTrade = allowTrade + && ( + hasLongSignal ? + allowLongTrades : + allowShortTrades + ); + + // + // Chack Maximum Open Positions ... + int openTrades = CountOpenTrades(); + if (maxOpenTrades > 0) { + // + if (openTrades >= maxOpenTrades) { + // + allowDoTrade = false; + + // + string message = StringConcatenate( + "Trading Pause => ", + "Max Open Trades (", + maxOpenTrades, + ") reached ..." + ); + + // + LogMessage(message); + SendAlert(message); + } + } + + // + // Check Trading is Enable or not ... + // nothing to do if trading is disabled ... + if (!allowDoTrade) { + // // + // string message = StringConcatenate( + // "Trading Not Allowed ..." + // ); + + // // + // LogMessage(message); + // SendAlert(message); + return; + } + + // + bool isPositionOpened = TradeSignal( + request.signal, + signalPrefix, + lotsPerTradePercent, + bullishSignalLabel, + bullishSignalColor, + bearishSignalLabel, + bearishSignalColor + ); + + // + if (isPositionOpened) { + // + bool canAlert = + alertPositions + && ( + hasLongSignal ? + longPositionAlerts + : + shortPositionAlerts + ); + + // + if (canAlert) { + // + // Alert Message ... + string message = StringConcatenate( + "Trade on Signal ID: ", request.signal.id, + ", Entry: ", request.signal.entryPrice, + ", TP: ", request.signal.tp + ); + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } + } + } +} + +// +// Process All Open Positions ... +void ProcessOpenPositions() { + // + // TODO: + // - Order 5 Long Time; + // - Order 8 Long Time; + // - Order 13 Long Time; + // - lcTrendDown; + // - mcTrendUp; + // - scTrendDown; + // - marketMiddleage < mcSlow; + // - longEntryPrice > lcSlow; + // - scTrendPowerUp; + // - Order 14 All Long Trades; + // - lcMarket TrendUp; + // - mcMarket TrendUp; + // - + // - Order 16 Long Time; + // - Ordrr 17 Long Time; + // - Ordrr 22 Long Time; + // - Ordrr 26 Long Time; + // - Ordrr 32 All Long Trades; + // - Ordrr 40 Long Time; + // - Ordrr 41 Long Time; + // - Ordrr 52 Long Time; + // - Ordrr 66 Long Time; + // - Ordrr 73 Long Time; + // - Ordrr 74 All Long Trades; + // - Ordrr 78 Long Time; + // - Ordrr 78 Long Time; + // - Ordrr 87 All Long Trades; + // - Ordrr 95 Long Time; + // - Ordrr 97 Long Time; + // - Ordrr 106 Long Time; + // - Ordrr 107 All Long Trades; + // - Ordrr 109 Long Time; + // - Ordrr 111 Long Time; + + // + if (closeLongTrades) { + // + closeLongTrades = false; + + // + bool isAllLongTradesClosed = CloseAllLongTrades(); + if (isAllLongTradesClosed) { + waitForLongSignals = false; + } + } + + // + if (closeShortTrades) { + // + closeShortTrades = false; + + // + bool isAllShortTradesClosed = CloseAllShortTrades(); + if (isAllShortTradesClosed) { + waitForShortSignals = false; + } + } + + // + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + closeAllOpenTradesAfterCandle + ); + + // + // Close Maximum DrawDown Passed Trades ... + bool hasClosedInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + maxDrawdownPercentPerPTrade + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedInDrawDownLongTrade + ) { + // + waitForLongSignals = false; + waitForShortSignals = false; + } +} + +// +// Send Special Type of Alerts ... +void SendAlert(string message) { + // // + // if (!alertEvents) { + // return; + // } + + // // + // // Terminal Alert ... + // if (terminalAlert) { + // Alert(message); + // } + + // // + // // Push Alert ... + // if (pushAlert) { + // SendNotification(message); + // } +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA/Indicators/x-saherelm.adx.mq4 b/Bkp/Used/OSC EA/Indicators/x-saherelm.adx.mq4 new file mode 100644 index 0000000..3271a4e --- /dev/null +++ b/Bkp/Used/OSC EA/Indicators/x-saherelm.adx.mq4 @@ -0,0 +1,220 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center ADX Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm ADX Oscillator" +#property strict + +// +// START Inputs ... +// +input int length = 7; // Averaging Length +input ENUM_APPLIED_PRICE appliedPrice = PRICE_WEIGHTED; // Averaging Applied Price +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_separate_window + +// +#property indicator_minimum 0 +#property indicator_maximum 100 + +// +#property indicator_buffers 3 + +// +#property indicator_level1 0.0 +#property indicator_level2 50.0 +#property indicator_level3 70.0 +#property indicator_level4 100.0 +#property indicator_levelcolor clrSilver +#property indicator_levelstyle STYLE_DOT + +// +// ADX ... +#property indicator_width1 1 +#property indicator_color1 clrLightBlue +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_SOLID + +// +// Positive Direction ... +#property indicator_width2 1 +#property indicator_color2 clrLime +#property indicator_type2 DRAW_LINE +#property indicator_style2 STYLE_DOT + +// +// Negative Direction ... +#property indicator_width3 1 +#property indicator_color3 clrRed +#property indicator_type3 DRAW_LINE +#property indicator_style3 STYLE_DOT + +// +// Declare Buffers ... +#define adxBufferIndex 0 +#define positiveBufferIndex 1 +#define negativeBufferIndex 2 + +double adxBuffer[]; +double positiveBuffer[]; +double negativeBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (length < 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + IndicatorBuffers(3); + + // + SetIndexBuffer(positiveBufferIndex, positiveBuffer); + SetIndexLabel(positiveBufferIndex, "DI+"); + + // + SetIndexBuffer(negativeBufferIndex, negativeBuffer); + SetIndexLabel(negativeBufferIndex, "DI-"); + + // + SetIndexBuffer(adxBufferIndex, adxBuffer); + SetIndexLabel(adxBufferIndex, "ADX"); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, length); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Long TP ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index +) { + // + // Calculate Buffers ... + + // + // Retrieves the current ADX value ... + double adx = iADX( + _Symbol, + _Period, + length, + appliedPrice, + MODE_MAIN, + bar_index + ); + adxBuffer[bar_index] = adx; + + // + // Retrieves the current DI+ value ... + double plusDi = iADX( + _Symbol, + _Period, + length, + appliedPrice, + MODE_PLUSDI, + bar_index + ); + positiveBuffer[bar_index] = plusDi; + + // + // Retrieves the current DI- value ... + double minusDi = iADX( + _Symbol, + _Period, + length, + appliedPrice, + MODE_MINUSDI, + bar_index + ); + negativeBuffer[bar_index] = minusDi; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA/Indicators/x-saherelm.ma.mq4 b/Bkp/Used/OSC EA/Indicators/x-saherelm.ma.mq4 new file mode 100644 index 0000000..e3a5737 --- /dev/null +++ b/Bkp/Used/OSC EA/Indicators/x-saherelm.ma.mq4 @@ -0,0 +1,173 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MA Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 MA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Fast MA ... +input int maLength = 20; // MA Length +input int maShift = 0; // MA Shift +input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method +input ENUM_APPLIED_PRICE maAppliedPrice = PRICE_CLOSE; // MA Applied Price + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 1 + +// +#property indicator_plots 1 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Fast Ma Buffer ... +#property indicator_label1 "Ma" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrYellow +#property indicator_style1 STYLE_DOT +#property indicator_width1 2 + +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define maBufferIndex 0 + +double maBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (maLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + // + // Ma ... + SetIndexBuffer(maBufferIndex, maBuffer); + SetIndexDrawBegin(maBufferIndex, maLength + 1); + // + // End Set Index Buffers ... + // + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, maLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Ma ... + CalculateMa(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateMa( + const int &bar_index +) { + // + // Calculating Fast Ma ... + double ma = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + maAppliedPrice, + bar_index + ); + + // + maBuffer[bar_index] = ma; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA/Indicators/x-saherelm.momentum.mq4 b/Bkp/Used/OSC EA/Indicators/x-saherelm.momentum.mq4 new file mode 100644 index 0000000..ea6e419 --- /dev/null +++ b/Bkp/Used/OSC EA/Indicators/x-saherelm.momentum.mq4 @@ -0,0 +1,160 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center Momentum Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm Momentum Oscillator" +#property strict + +// +// START Inputs ... +// +input int length = 7; // Market Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_separate_window + +// +#property indicator_buffers 1 + +// +#property indicator_level1 0.0 +#property indicator_level2 100.0 +#property indicator_levelcolor clrSilver +#property indicator_levelstyle STYLE_DOT + +// +// MOMENTUM ... +#property indicator_width1 1 +#property indicator_color1 clrLightBlue +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_SOLID + +// +// Declare Buffers ... +#define momentumBufferIndex 0 + +double momentumBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if (length < 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + IndicatorBuffers(1); + + // + SetIndexBuffer(momentumBufferIndex, momentumBuffer); + SetIndexLabel(momentumBufferIndex, "Momentum"); + SetIndexDrawBegin(momentumBufferIndex, length); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, length); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Long TP ... + CalculateBuffers( + i, + close + ); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +void CalculateBuffers( + const int bar_index, + const double &close[] +) { + // + // Calculate Buffers ... + double momentum = close[bar_index] * 100 / close[bar_index + length]; + + // + momentumBuffer[bar_index] = momentum; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA/Indicators/x-saherelm.osc.mq4 b/Bkp/Used/OSC EA/Indicators/x-saherelm.osc.mq4 new file mode 100644 index 0000000..220bd33 --- /dev/null +++ b/Bkp/Used/OSC EA/Indicators/x-saherelm.osc.mq4 @@ -0,0 +1,330 @@ +///////////////////////////////////////////////////////////////// +// +// SaherElm IT Center OSC Indicator +// ------------------------------------------------------------- +// this indicator provides OSC ... +// +// 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 OSC Indicator" +#property strict + +// +// START Inputs ... +// +// +// FastOSC ... +// Short Cycle (Fast OSC) ... +input int fastOSCLength = 10; // FastOSC Length +input double fastOSCMultiplier = 1.0; // FastOSC Multiplier + +// +// SlowOSC ... +// Medium Cycle (Slow OSC) ... +input int slowOSCLength = 30; // SlowOSC Length +input double slowOSCMultiplier = 3.0; // SlowOSC Multiplier +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +#property indicator_separate_window + +// +// we have 2 buffer in this indicator ... +#property indicator_buffers 5 + +// +// also we have 2 line for draw on this indicator ... +#property indicator_plots 5 + +// +// Fast OSC ... +#property indicator_width1 1 +#property indicator_color1 clrAqua +#property indicator_type1 DRAW_LINE +#property indicator_style1 STYLE_SOLID + +// +// Slow OSC ... +#property indicator_width2 1 +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrFuchsia +#property indicator_style2 STYLE_SOLID + +// +// Power OSC ... +#property indicator_width3 1 +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_DASHDOTDOT + +// +// Var OSC ... +#property indicator_width4 1 +#property indicator_type4 DRAW_HISTOGRAM +#property indicator_color4 clrBlueViolet +#property indicator_style4 STYLE_SOLID + +// +// Tan Fast/Slow OSC ... +#property indicator_width5 0 +#property indicator_type5 DRAW_NONE +#property indicator_color5 clrNONE +#property indicator_style5 STYLE_SOLID + +// +//#property indicator_minimum 0 +//#property indicator_maximum 1 + +// +// set color of horizontal levels ... +#property indicator_levelcolor clrGray + +// +// set style of horizontal levels ... +#property indicator_levelstyle STYLE_DOT + +// +// Declare Buffers ... +#define fastOSCBufferIndex 0 +#define slowOSCBufferIndex 1 +#define powerOSCBufferIndex 2 +#define varOSCBufferIndex 3 +#define fastSlowOSCAngleBufferIndex 4 + +// +double fastOSCBuffer[]; +double slowOSCBuffer[]; +double fastSlowOSCAngleBuffer[]; +double powerOSCBuffer[]; +double varOSCBuffer[]; + +// +// Used Indicators List ... +string rmaIndicatorName = "x-saherelm.rma"; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + fastOSCLength < 0 || + slowOSCLength < 0 || + slowOSCLength <= fastOSCLength + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XS_OSC"; + + // + // set descriptions of horizontal levels ... + SetLevelValue(0, 0.0); + IndicatorSetString(INDICATOR_LEVELTEXT,0,""); + + // + // set descriptions of horizontal levels ... + SetLevelValue(1, 0.5); + IndicatorSetString(INDICATOR_LEVELTEXT,1,""); + + // + // set descriptions of horizontal levels ... + SetLevelValue(2, 1); + IndicatorSetString(INDICATOR_LEVELTEXT,2,""); + + // + // Fast OSC Buffer ... + SetIndexBuffer(fastOSCBufferIndex, fastOSCBuffer); + SetIndexLabel(fastOSCBufferIndex, "Fast OSC"); + SetIndexDrawBegin(fastOSCBufferIndex, fastOSCLength - 1); + + // + // Slow OSC Buffer ... + SetIndexBuffer(slowOSCBufferIndex, slowOSCBuffer); + SetIndexLabel(slowOSCBufferIndex, "Slow OSC"); + SetIndexDrawBegin(slowOSCBufferIndex, slowOSCLength - 1); + + // + // Power OSC Buffer ... + SetIndexBuffer(powerOSCBufferIndex, powerOSCBuffer); + SetIndexLabel(powerOSCBufferIndex, "Power OSC"); + + // + // Var OSC Buffer ... + SetIndexBuffer(varOSCBufferIndex, varOSCBuffer); + SetIndexLabel(varOSCBufferIndex, "Var OSC"); + + // + // Tan Fast/Slow OSC Buffer ... + SetIndexBuffer(fastSlowOSCAngleBufferIndex, fastSlowOSCAngleBuffer); + SetIndexLabel(fastSlowOSCAngleBufferIndex, "F/L OSC Angle"); + + // + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(fastOSCLength, slowOSCLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + CalculateOscillators(close, i); + } + + // + return rates_total; +} + +// +// De Initialization ... +void OnDeinit(const int reason) { +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +void CalculateOscillators( + const double &close[], + const int &bar_index +) { + // + // FastOSC ... + // Short Cycle Calculations ... + int scl = fastOSCLength / 2; + int scl2 = scl / 2; + double maScl = iCustom(_Symbol, _Period, rmaIndicatorName, scl, 0, bar_index); + double scmAtr = iATR(_Symbol, _Period, scl, bar_index); + double scmOff = fastOSCMultiplier * scmAtr; + double maScl2 = iCustom(_Symbol, _Period, rmaIndicatorName, scl2, 0, bar_index); + double sctParam = maScl2 != 0 ? maScl2 : close[bar_index + 1]; + double sct = sctParam + scmOff; + double scb = sctParam - scmOff; + + // + // SlowOSC ... + // Medium Cycle Calculations ... + int mcl = slowOSCLength / 2; + int mcl2 = mcl / 2; + double maMcl = iCustom(_Symbol, _Period, rmaIndicatorName, mcl, 0, bar_index); + double mcmAtr = iATR(_Symbol, _Period, mcl, bar_index); + double mcmOff = slowOSCMultiplier * mcmAtr; + double maMcl2 = iCustom(_Symbol, _Period, rmaIndicatorName, mcl2, 0, bar_index); + double mctParam = maMcl2 != 0 ? maMcl2 : close[bar_index + 1]; + double mct = mctParam + mcmOff; + double mcb = mctParam - mcmOff; + + // + double scMM = (sct + scb) / 2; + + // + double fastOCS = (close[bar_index] - mcb) / (mct - mcb); + fastOSCBuffer[bar_index] = fastOCS; + + // + double slowOCS = (scMM - mcb) / (mct - mcb); + slowOSCBuffer[bar_index] = slowOCS; + + // + // Signal Power ... + // Difference Variant between FastOSC and Slow OSC ... + double powerOSC = fastOCS - slowOCS; + powerOSCBuffer[bar_index] = powerOSC; + + // + // Var OSC ... + double varOSC = fastOCS - 0.5; + varOSCBuffer[bar_index] = varOSC; + + // + // Calculate Tan Fast/Slow OSC ... + double fastOSCSlope = fastOSCBuffer[bar_index] - fastOSCBuffer[bar_index + 1]; + double slowOSCSlope = slowOSCBuffer[bar_index] - slowOSCBuffer[bar_index + 1]; + double tanFastSlowOSC = MathAbs( + (fastOSCSlope - slowOSCSlope) / (1 + (fastOSCSlope * slowOSCSlope)) + ); + + // + // here we pass Tan of angle ... + // fastSlowOSCAngleBuffer[bar_index] = tanFastSlowOSC; + + // + // here we pass degree of angle ... + fastSlowOSCAngleBuffer[bar_index] = MathArctan(tanFastSlowOSC); +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA/Indicators/x-saherelm.rma.mq4 b/Bkp/Used/OSC EA/Indicators/x-saherelm.rma.mq4 new file mode 100644 index 0000000..0fc70fd --- /dev/null +++ b/Bkp/Used/OSC EA/Indicators/x-saherelm.rma.mq4 @@ -0,0 +1,141 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center RMA Indicator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm RMA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Set the RMA Length ... +input int RMALength = 10; // Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// we have 2 buffer in this indicator ... +#property indicator_buffers 1 + +// +// also we have 1 line for draw on this indicator ... +#property indicator_plots 1 + +// +// here we declare plot SlowOCS to system ... +#property indicator_label1 "RMA" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrFuchsia +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +// +// Declare Buffers ... +#define RMABufferIndex 0 + +// +double RMABuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + SetIndexBuffer(RMABufferIndex, RMABuffer); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + int maxLength = MathMax(0, RMALength); + + // + // wait to pass bars until we have rights ... + if (rates_total <= maxLength) { + // + // return not calculated ... + return 0; + } + + // + // find loop count for bars manipulation ... + int count = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // Print("Count: ", count, ", Bars: ", Bars); + + // + // this is the main loop of calculations, for each bar index ... + for (int i = count - 1; i >= 0; i--) { + // + // Start Calculation with Formula 1 ... + // + double shortSMA = iMA(_Symbol, _Period, RMALength, 0, MODE_SMA, PRICE_CLOSE, i); + double mediumSMA = iMA(_Symbol, _Period, RMALength * 2, 0, MODE_SMA, PRICE_CLOSE, i); + double longSMA = iMA(_Symbol, _Period, RMALength * 3, 0, MODE_SMA, PRICE_CLOSE, i); + + // + double rma1 = longSMA - mediumSMA + shortSMA; + rma1 = NormalizeDouble(rma1, _Digits); + // + // End Calculation with Formula 1 ... + // + + // + RMABuffer[i] = rma1; + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA/Indicators/x-saherelm.rsi.mq4 b/Bkp/Used/OSC EA/Indicators/x-saherelm.rsi.mq4 new file mode 100644 index 0000000..448f732 --- /dev/null +++ b/Bkp/Used/OSC EA/Indicators/x-saherelm.rsi.mq4 @@ -0,0 +1,234 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center RSI Oscillator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm RSI Oscillator" +#property strict + +// +// START Inputs ... +// +input int rsiPeriod=14; // RSI Period +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +#property indicator_separate_window + +// +#property indicator_minimum 0 +#property indicator_maximum 100 + +// +#property indicator_buffers 1 +#property indicator_color1 DodgerBlue + +// +#property indicator_level1 30.0 +#property indicator_level2 50.0 +#property indicator_level3 70.0 +#property indicator_levelcolor clrSilver +#property indicator_levelstyle STYLE_DOT + +// +// Declare Buffers ... +#define rsiBufferIndex 0 +#define positiveBufferIndex 1 +#define negativeBufferIndex 2 + +double rsiBuffer[]; +double positiveBuffer[]; +double negativeBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + string short_name; + + // + IndicatorBuffers(3); + + // + SetIndexBuffer(positiveBufferIndex, positiveBuffer); + SetIndexBuffer(negativeBufferIndex, negativeBuffer); + + // + SetIndexStyle(rsiBufferIndex, DRAW_LINE); + SetIndexBuffer(rsiBufferIndex, rsiBuffer); + + // + // name for DataWindow and indicator subwindow label + short_name="RSI("+string(rsiPeriod)+")"; + IndicatorShortName(short_name); + SetIndexLabel(rsiBufferIndex, short_name); + + // + // check for input + if (rsiPeriod < 2) { + // + Print("Incorrect value for input variable InpRSIPeriod = ", rsiPeriod); + + // + // Failed Initialization ... + return INIT_PARAMETERS_INCORRECT; + } + + // + // set where to start draw ... + SetIndexDrawBegin(0, rsiPeriod); + + // + // initialization done ... + return INIT_SUCCEEDED; +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + int i,pos; + double diff; + + // + // Prevent from run calculations if there is no fulfilled conditions ... + if (Bars <= rsiPeriod || rsiPeriod < 2) { + // + // return nothing calculated result ... + return 0; + } + + // + // counting from 0 to rates_total, this is most important ... + ArraySetAsSeries(rsiBuffer, false); + ArraySetAsSeries(positiveBuffer, false); + ArraySetAsSeries(negativeBuffer, false); + + // + ArraySetAsSeries(close, false); + + // + // preliminary calculations ... + pos = prev_calculated - 1; + if (pos <= rsiPeriod) { + // + // first RSIPeriod values of the indicator are not calculated + rsiBuffer[0] = 0.0; + positiveBuffer[0] = 0.0; + negativeBuffer[0] = 0.0; + + // + double sump=0.0; + double sumn=0.0; + for (i = 1; i <= rsiPeriod; i++) { + // + rsiBuffer[i]=0.0; + positiveBuffer[i]=0.0; + negativeBuffer[i]=0.0; + + // + diff = close[i] - close[i - 1]; + if(diff > 0) { + sump += diff; + } else { + sumn -= diff; + } + } + + // + // calculate first visible value ... + positiveBuffer[rsiPeriod] = sump / rsiPeriod; + negativeBuffer[rsiPeriod] = sumn / rsiPeriod; + if (negativeBuffer[rsiPeriod] != 0.0) { + // + rsiBuffer[rsiPeriod] = 100.0 - ( + 100.0 / ( + 1.0 + positiveBuffer[rsiPeriod] / negativeBuffer[rsiPeriod] + ) + ); + } else { + // + if (positiveBuffer[rsiPeriod] != 0.0) { + rsiBuffer[rsiPeriod] = 100.0; + } else { + rsiBuffer[rsiPeriod] = 50.0; + } + } + + // + // prepare the position value for main calculation ... + pos = rsiPeriod + 1; + } + + // + // the main loop of calculations ... + for (i = pos; i < rates_total && !IsStopped(); i++) { + // + diff = close[i] - close[i-1]; + + // + positiveBuffer[i] = (positiveBuffer[i-1] * (rsiPeriod - 1) + (diff > 0.0 ? diff : 0.0)) / rsiPeriod; + negativeBuffer[i] = (negativeBuffer[i-1] * (rsiPeriod - 1) + (diff < 0.0 ? -diff : 0.0)) / rsiPeriod; + + // + if (negativeBuffer[i] != 0.0) { + rsiBuffer[i] = 100.0 - 100.0 / (1 + positiveBuffer[i] / negativeBuffer[i]); + } else { + // + if (positiveBuffer[i] != 0.0) { + rsiBuffer[i] = 100.0; + } else { + rsiBuffer[i] = 50.0; + } + } + } + + // + return(rates_total); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA/Indicators/x-saherelm.xma.mq4 b/Bkp/Used/OSC EA/Indicators/x-saherelm.xma.mq4 new file mode 100644 index 0000000..20206ac --- /dev/null +++ b/Bkp/Used/OSC EA/Indicators/x-saherelm.xma.mq4 @@ -0,0 +1,643 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XMA Indicator +// --------------------------------------------- +// saherelm implementation of above oscillator ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XMA Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 7; // Market Length +input int shortCycleFastMultiplier = 1; // Short Cycle Fast Multiplier +input int shortCycleSlowMultiplier = 4; // Short Cycle Slow Multiplier +input int mediumCycleFastMultiplier = 7; // Medium Cycle Fast Multiplier +input int mediumCycleSlowMultiplier = 14; // Medium Cycle Slow Multiplier +input int longCycleFastMultiplier = 70; // Long Cycle Fast Multiplier +input int longCycleSlowMultiplier = 140; // Long Cycle Slow Multiplier +// +// Show Inputs ... +input bool showShortCycle = true; // Show Short Cycle +input bool showShortCycleCrossLines = true; // Show Short Cycle Vertical Lines +input bool showMediumCycle = true; // Show Medium Cycle +input bool showMediumCycleCrossLines = true; // Show Medium Cycle Vertical Lines +input bool showLongCycle = true; // Show Long Cycle +input bool showLongCycleCrossLines = true; // Show Long Cycle Vertical Lines +// +// Color Inputs ... +input color shortCycleFastColor = clrGreen; // Short Cycle Fast Color ... +input color shortCycleSlowColor = clrRed; // Short Cycle Slow Color ... +input color mediumCycleFastColor = clrAqua; // Medium Cycle Fast Color ... +input color mediumCycleSlowColor = clrFuchsia; // Medium Cycle Slow Color ... +input color longCycleFastColor = clrGoldenrod; // Medium Cycle Fast Color ... +input color longCycleSlowColor = clrBrown; // Medium Cycle Slow Color ... +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +// define indicator buffers ... +#property indicator_buffers 7 +#property indicator_plots 7 + +// +// Middle ... +#property indicator_label7 "Mid" +#property indicator_type7 DRAW_LINE +#property indicator_color7 clrBisque +#property indicator_style7 STYLE_DASHDOTDOT +#property indicator_width7 1 + +// +// Declare Buffers ... +#define scFastBufferIndex 0 +#define scSlowBufferIndex 1 +#define mcFastBufferIndex 2 +#define mcSlowBufferIndex 3 +#define lcFastBufferIndex 4 +#define lcSlowBufferIndex 5 +#define midBufferIndex 6 + +// +double scFastBuffer[]; +double scSlowBuffer[]; +double mcFastBuffer[]; +double mcSlowBuffer[]; +double lcFastBuffer[]; +double lcSlowBuffer[]; +double midBuffer[]; + +// +int shortCycleFastLength; +int shortCycleSlowLength; +int mediumCycleFastLength; +int mediumCycleSlowLength; +int longCycleFastLength; +int longCycleSlowLength; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + // + // Validate Market Length ... + marketLength <= 0 + // + // Validate Short Cycle ... + || shortCycleFastMultiplier <= 0 + || shortCycleSlowMultiplier <= 0 + || shortCycleFastMultiplier >= shortCycleSlowMultiplier + // + // Validate Medium Cycle ... + || mediumCycleFastMultiplier <= 0 + || mediumCycleSlowMultiplier <= 0 + || mediumCycleFastMultiplier >= mediumCycleSlowMultiplier + // + // Validate Long Cycle ... + || longCycleFastMultiplier <= 0 + || longCycleSlowMultiplier <= 0 + || longCycleFastMultiplier >= longCycleSlowMultiplier + // + // Validate Series of Multipliers ... + || shortCycleFastMultiplier >= mediumCycleFastMultiplier + || mediumCycleFastMultiplier >= longCycleFastMultiplier + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST_XMA"; + + // + // Calculate Cycle Length based on given Multipliers ... + shortCycleFastLength = marketLength * shortCycleFastMultiplier; + shortCycleSlowLength = marketLength * shortCycleSlowMultiplier; + mediumCycleFastLength = marketLength * mediumCycleFastMultiplier; + mediumCycleSlowLength = marketLength * mediumCycleSlowMultiplier; + longCycleFastLength = marketLength * longCycleFastMultiplier; + longCycleSlowLength = marketLength * longCycleSlowMultiplier; + + // + // Short Cycle Fast ... + SetIndexLabel(scFastBufferIndex, "SCFast"); + SetIndexBuffer(scFastBufferIndex, scFastBuffer); + SetIndexDrawBegin(scFastBufferIndex, shortCycleFastLength); + SetIndexStyle( + scFastBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showShortCycle ? + shortCycleFastColor : + clrNONE + ); + + // + // Short Cycle Slow ... + SetIndexLabel(scSlowBufferIndex, "SCSLow"); + SetIndexBuffer(scSlowBufferIndex, scSlowBuffer); + SetIndexDrawBegin(scSlowBufferIndex, shortCycleSlowLength); + SetIndexStyle( + scSlowBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showShortCycle ? + shortCycleSlowColor : + clrNONE + ); + + // + // Medium Cycle Fast ... + SetIndexLabel(mcFastBufferIndex, "MCFast"); + SetIndexBuffer(mcFastBufferIndex, mcFastBuffer); + SetIndexDrawBegin(mcFastBufferIndex, mediumCycleFastLength); + SetIndexStyle( + mcFastBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showMediumCycle ? + mediumCycleFastColor : + clrNONE + ); + + // + // Medium Cycle Slow ... + SetIndexLabel(mcSlowBufferIndex, "MCSlow"); + SetIndexBuffer(mcSlowBufferIndex, mcSlowBuffer); + SetIndexDrawBegin(mcSlowBufferIndex, mediumCycleSlowLength); + SetIndexStyle( + mcSlowBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showMediumCycle ? + mediumCycleSlowColor : + clrNONE + ); + + // + // Long Cycle Fast ... + SetIndexLabel(lcFastBufferIndex, "LCFast"); + SetIndexBuffer(lcFastBufferIndex, lcFastBuffer); + SetIndexDrawBegin(lcFastBufferIndex, longCycleFastLength); + SetIndexStyle( + lcFastBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showLongCycle ? + longCycleFastColor : + clrNONE + ); + + // + // Long Cycle Slow ... + SetIndexLabel(lcSlowBufferIndex, "LCSlow"); + SetIndexBuffer(lcSlowBufferIndex, lcSlowBuffer); + SetIndexDrawBegin(lcSlowBufferIndex, longCycleSlowLength); + SetIndexStyle( + lcSlowBufferIndex, + DRAW_LINE, + STYLE_DOT, + 1, + showLongCycle ? + longCycleSlowColor : + clrNONE + ); + + // + // Market Middleage ... + SetIndexBuffer(midBufferIndex, midBuffer); + SetIndexDrawBegin(midBufferIndex, marketLength); + + // + // initialization done ... + return(INIT_SUCCEEDED); +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + RemoveDraws(logTag); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(marketLength, longCycleSlowLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Short Cycle ... + CalculateShortCycle(i); + + // + // Calculate Medium Cycle ... + CalculateMediumCycle(i); + + // + // Calculate Long Cycle ... + CalculateLongCycle(i); + + // + // Calculate Market Middleage ... + CalculateMarketMiddleage(i); + + // + // Calculate Cross Points ... + CalculateCrossPoints(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculate Short Cycle ... +void CalculateShortCycle( + const int bar_index +) { + // + // Fast ... + double shortCycleFast = iMA( + _Symbol, + _Period, + shortCycleFastLength, + 0, + MODE_SMA, + PRICE_WEIGHTED, + bar_index + ); + scFastBuffer[bar_index] = shortCycleFast; + + // + // Slow ... + double shortCycleSlow = iMA( + _Symbol, + _Period, + shortCycleSlowLength, + 0, + MODE_SMA, + PRICE_WEIGHTED, + bar_index + ); + scSlowBuffer[bar_index] = shortCycleSlow; +} + +// +// Calculate Medium Cycle ... +void CalculateMediumCycle( + const int bar_index +) { + // + // Fast ... + double mediumCycleFast = iMA( + _Symbol, + _Period, + mediumCycleFastLength, + 0, + MODE_SMA, + PRICE_MEDIAN, + bar_index + ); + mcFastBuffer[bar_index] = mediumCycleFast; + + // + // Slow ... + double mediumCycleSlow = iMA( + _Symbol, + _Period, + mediumCycleSlowLength, + 0, + MODE_SMA, + PRICE_MEDIAN, + bar_index + ); + mcSlowBuffer[bar_index] = mediumCycleSlow; +} + +// +// Calculate Long Cycle ... +void CalculateLongCycle( + const int bar_index +) { + // + // Fast ... + double longCycleFast = iMA( + _Symbol, + _Period, + longCycleFastLength, + 0, + MODE_SMA, + PRICE_CLOSE, + bar_index + ); + lcFastBuffer[bar_index] = longCycleFast; + + // + // Slow ... + double longCycleSlow = iMA( + _Symbol, + _Period, + longCycleSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE, + bar_index + ); + lcSlowBuffer[bar_index] = longCycleSlow; +} + +// +// Calculate Market Middleage ... +void CalculateMarketMiddleage( + const int bar_index +) { + // + // Mid ... + double marketMiddleage = iMA( + _Symbol, + _Period, + (int)(marketLength * 1.5), + 0, + MODE_EMA, + PRICE_MEDIAN, + bar_index + ); + midBuffer[bar_index] = marketMiddleage; +} + +// +// Calculate Cross Points and Draw Section Line on theme ... +void CalculateCrossPoints( + const int bar_index +) { + // + // START Draw Cross Lines ... + // + // + // Short Cycle ... + bool isSCFastCrossOverSlow = scFastBuffer[bar_index] > scSlowBuffer[bar_index] + && !(scFastBuffer[bar_index + 1] > scSlowBuffer[bar_index + 1]); + + // + bool isSCFastCrossUnderSlow = scFastBuffer[bar_index] < scSlowBuffer[bar_index] + && !(scFastBuffer[bar_index + 1] < scSlowBuffer[bar_index + 1]); + + // + // Medium Cycle ... + bool isMCFastCrossOverSlow = mcFastBuffer[bar_index] > mcSlowBuffer[bar_index] + && !(mcFastBuffer[bar_index + 1] > mcSlowBuffer[bar_index + 1]); + + // + bool isMCFastCrossUnderSlow = mcFastBuffer[bar_index] < mcSlowBuffer[bar_index] + && !(mcFastBuffer[bar_index + 1] < mcSlowBuffer[bar_index + 1]); + + // + // Long Cycle ... + bool isLCFastCrossOverSlow = lcFastBuffer[bar_index] > lcSlowBuffer[bar_index] + && !(lcFastBuffer[bar_index + 1] > lcSlowBuffer[bar_index + 1]); + + // + bool isLCFastCrossUnderSlow = lcFastBuffer[bar_index] < lcSlowBuffer[bar_index] + && !(lcFastBuffer[bar_index + 1] < lcSlowBuffer[bar_index + 1]); + + // + // START Drawing CrossPoints ... + // + // + datetime currentTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + if (showShortCycleCrossLines) { + // + // Draw Line ... + if (isSCFastCrossOverSlow) { + // + string lbl = StringConcatenate( + logTag, + "_SC_F_OV_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showShortCycleCrossLines ? + shortCycleFastColor : + clrNONE + ); + } + + // + // Draw Line ... + if (isSCFastCrossUnderSlow) { + // + string lbl = StringConcatenate( + logTag, + "_SC_F_UN_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showShortCycleCrossLines ? + shortCycleSlowColor : + clrNONE + ); + } + } + + // + if (showMediumCycleCrossLines) { + // + // Draw Line ... + if (isMCFastCrossOverSlow) { + // + string lbl = StringConcatenate( + logTag, + "_MC_F_OV_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showMediumCycleCrossLines ? + mediumCycleFastColor : + clrNONE + ); + } + + // + // Draw Line ... + if (isMCFastCrossUnderSlow) { + // + string lbl = StringConcatenate( + logTag, + "_MC_F_UN_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showMediumCycleCrossLines ? + mediumCycleSlowColor : + clrNONE + ); + } + } + + // + if (showLongCycleCrossLines) { + // + // Draw Line ... + if (isLCFastCrossOverSlow) { + // + string lbl = StringConcatenate( + logTag, + "_LC_F_OV_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showLongCycleCrossLines ? + longCycleFastColor : + clrNONE + ); + } + + // + // Draw Line ... + if (isLCFastCrossUnderSlow) { + // + string lbl = StringConcatenate( + logTag, + "_LC_F_UN_S_", + currentTime + ); + + // + DrawVerticalLine( + 0, + lbl, + 0, + currentTime, + showLongCycleCrossLines ? + longCycleSlowColor : + clrNONE + ); + } + } + // + // END Drawing CrossPoints ... + // +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA/Indicators/x-saherelm.zigzag.mq4 b/Bkp/Used/OSC EA/Indicators/x-saherelm.zigzag.mq4 new file mode 100644 index 0000000..fbb073c --- /dev/null +++ b/Bkp/Used/OSC EA/Indicators/x-saherelm.zigzag.mq4 @@ -0,0 +1,476 @@ +///////////////////////////////////////////////////////////////// +// +// SaherElm IT Center ZigZag Indicator +// ------------------------------------------------------------- +// this indicator provides signals for Main strategy ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +//////////////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm ZigZag Indicator" +#property strict + +// +// START Inputs ... +// +input int depth = 12; // Depth +input int deviation = 5; // Deviation +input int backStep = 3; // BackStep +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// here we specify logging enabled or not ... +bool enableLogging = true; + +// +// this is a Tag which attached to our Logger ... +string logTag = "XS_ZG"; + +// +#property indicator_chart_window + +// +#property indicator_buffers 1 + +// +#property indicator_width1 1 +#property indicator_color1 clrAqua +// #property indicator_type1 DRAW_SECTION +// #property indicator_style1 STYLE_SOLID + +// // +// #property indicator_width2 1 +// #property indicator_color2 clrNONE +// #property indicator_type2 DRAW_NONE +// #property indicator_style2 STYLE_SOLID + +// // +// #property indicator_width3 1 +// #property indicator_color3 clrNONE +// #property indicator_type3 DRAW_NONE +// #property indicator_style3 STYLE_SOLID + +// +// Buffers ... +// +#define zigzagBufferIndex 0 +#define highBufferIndex 1 +#define lowBufferIndex 2 +// #define ziggyBufferIndex 3 + +// +double zigzagBuffer[]; +double highBuffer[]; +double lowBuffer[]; +// double ziggyBuffer[]; + +// +// recounting's depth of extremums ... +int level=3; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + + // + // Validating Input Parameters ... + if ( + depth <= 0 || + backStep < 0 || + deviation < 0 || + backStep >= depth + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Set Index Buffers of ZigZag ... + IndicatorBuffers(3); + + // + // ZigZag Buffer ... + SetIndexBuffer(zigzagBufferIndex, zigzagBuffer); + SetIndexStyle(zigzagBufferIndex, DRAW_SECTION); + SetIndexLabel(zigzagBufferIndex, "ZigZag"); + + // + // High Buffer ... + SetIndexBuffer(highBufferIndex, highBuffer); + SetIndexLabel(highBufferIndex, ""); + + // + // Low Buffer ... + SetIndexBuffer(lowBufferIndex, lowBuffer); + SetIndexLabel(lowBufferIndex, ""); + + // + // Ziggy Buffer ... + // SetIndexBuffer(ziggyBufferIndex, ziggyBuffer); + // SetIndexLabel(ziggyBufferIndex, ""); + + // + return(INIT_SUCCEEDED); +} + +// +// Do Calculation ... +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + int maxLength = MathMax(depth, backStep); + + int i; + int counterZ; + int back; + int pos; + + // + int lastlowpos = 0; + int lasthighpos = 0; + int whatlookfor = 0; + + // + double extremum; + + // + double curlow = 0.0; + double curhigh = 0.0; + double lasthigh = 0.0; + double lastlow = 0.0; + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // first calculations ... + if (prev_calculated == 0) { + limit = InitializeBuffers(); + } else { + // + // find first extremum in the depth ExtLevel or 100 last bars ... + i = counterZ = 0; + while(counterZ < level && i < 100) { + // + if(zigzagBuffer[i] != 0.0) { + counterZ++; + } + + // + i++; + } + + // + // no extremum found - recounting all from begin ... + if(counterZ == 0) { + limit = InitializeBuffers(); + } else { + // + // set start position to found extremum position ... + limit = i-1; + + // + //--- what kind of extremum? + if(lowBuffer[i] != 0.0) { + // + // low extremum ... + curlow = lowBuffer[i]; + + // + // will look for the next high extremum ... + whatlookfor=1; + } else { + // + // high extremum ... + curhigh = highBuffer[i]; + + // + // will look for the next low extremum ... + whatlookfor=-1; + } + + // + // clear the rest data ... + for(i = limit - 1; i >= 0; i--) { + // + lowBuffer[i]=0.0; + highBuffer[i]=0.0; + zigzagBuffer[i]=0.0; + } + } + } + + // + // Main Calculation Loop ... + for (i = limit; i >= 0; i--) { + // + // find lowest low in depth of bars ... + extremum = low[ + iLowest( + _Symbol, + _Period, + MODE_LOW, + depth, + i + ) + ]; + + // + // this lowest has been found previously ... + if (extremum == lastlow) { + extremum = 0.0; + } else { + // + // new last low ... + lastlow=extremum; + + // + // discard extremum if current low is too high ... + if(low[i] - extremum > deviation * _Point) { + extremum=0.0; + } else { + // + // clear previous extremums in backstep bars ... + for(back = 1; back <= backStep; back++) { + // + pos = i + back; + + // + if(lowBuffer[pos] != 0 && lowBuffer[pos] > extremum) { + lowBuffer[pos] = 0.0; + } + } + } + } + + // + // found extremum is current low ... + if (low[i] == extremum) { + lowBuffer[i] = extremum; + } else { + lowBuffer[i] = 0.0; + } + + // + // find highest high in depth of bars ... + extremum = high[ + iHighest( + _Symbol, + _Period, + MODE_HIGH, + depth, + i + ) + ]; + + // + // this highest has been found previously ... + if (extremum == lasthigh) { + extremum = 0.0; + } else { + // + // new last high ... + lasthigh=extremum; + + // + // discard extremum if current high is too low ... + if (extremum - high[i] > deviation * Point) { + extremum = 0.0; + } else { + // + // clear previous extremums in backstep bars ... + for(back = 1; back <= backStep; back++) { + // + pos = i + back; + + // + if (highBuffer[pos] != 0 && highBuffer[pos] < extremum) { + highBuffer[pos] = 0.0; + } + } + } + } + + // + // found extremum is current high ... + if (high[i] == extremum) { + highBuffer[i] = extremum; + } else { + highBuffer[i] = 0.0; + } + } + + // + // final cutting ... + if( whatlookfor == 0) { + // + lastlow = 0.0; + lasthigh = 0.0; + } else { + // + lastlow = curlow; + lasthigh = curhigh; + } + + // + for(i = limit; i >= 0; i--) { + switch(whatlookfor) { + // + // look for peak or lawn ... + case 0: + // + if (lastlow == 0.0 && lasthigh == 0.0) { + if(highBuffer[i]!=0.0) { + // + lasthigh = High[i]; + lasthighpos = i; + whatlookfor = -1; + + // + zigzagBuffer[i] = lasthigh; + } + + // + if(lowBuffer[i] != 0.0) { + // + lastlow = Low[i]; + lastlowpos = i; + whatlookfor = 1; + + // + zigzagBuffer[i] = lastlow; + } + } + break; + + // + // look for peak ... + case 1: + // + if ( + lowBuffer[i] != 0.0 && + lowBuffer[i] < lastlow && + highBuffer[i] == 0.0 + ) { + // + zigzagBuffer[lastlowpos] = 0.0; + lastlowpos = i; + lastlow = lowBuffer[i]; + zigzagBuffer[i] = lastlow; + } + + // + if(highBuffer[i] != 0.0 && lowBuffer[i] == 0.0) { + // + lasthigh = highBuffer[i]; + lasthighpos = i; + zigzagBuffer[i] = lasthigh; + + // + whatlookfor=-1; + } + break; + + // + // look for lawn ... + case -1: + // + if( + highBuffer[i] != 0.0 && + highBuffer[i] > lasthigh && + lowBuffer[i] == 0.0 + ) { + // + zigzagBuffer[lasthighpos] = 0.0; + lasthighpos = i; + lasthigh = highBuffer[i]; + zigzagBuffer[i] = lasthigh; + } + + // + if( + lowBuffer[i] !=0.0 && + highBuffer[i] == 0.0 + ) { + // + lastlow = lowBuffer[i]; + lastlowpos = i; + zigzagBuffer[i] = lastlow; + whatlookfor=1; + } + break; + } + } + + // + // Done ... + return rates_total; +} + +// +// De Initialization ... +void OnDeinit(const int reason) { + // + // RemoveDraws(signalPrefix); + ChartRedraw(0); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +int InitializeBuffers() { + // + ArrayInitialize(lowBuffer,0.0); + ArrayInitialize(highBuffer, 0.0); + ArrayInitialize(zigzagBuffer, 0.0); + + // + //--- first counting position + return(Bars - depth); +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA/Libraries/x-saherelm.draw.lib.mq4 b/Bkp/Used/OSC EA/Libraries/x-saherelm.draw.lib.mq4 new file mode 100644 index 0000000..08fefa7 --- /dev/null +++ b/Bkp/Used/OSC EA/Libraries/x-saherelm.draw.lib.mq4 @@ -0,0 +1,1670 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Start Arrow Functions ... +// +// +// Draw an Arrow Object on Chart ... +bool DrawArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // arrow name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const uchar arrowCode = OBJ_ARROW_UP, // arrow code + const ENUM_ARROW_ANCHOR anchor = ANCHOR_BOTTOM, // anchor point position + const color clr = clrAqua, // arrow color + const ENUM_LINE_STYLE style = STYLE_SOLID, // border line style + const int width = 3, // arrow size + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // Order Object ... +) { + // + // set anchor point coordinates if they are not set ... + ChangeArrowEmptyPoint(time, price); + + // + // reset the error value ... + ResetLastError(); + + // + // create an arrow ... + if(!ObjectCreate(chartID, name, OBJ_ARROW, subWindow, time, price)) { + // + string message = StringConcatenate(__FUNCTION__, + ": failed to create an arrow! Error code = ", + GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the arrow code ... + ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, arrowCode); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set the arrow color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set the border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set the arrow's size ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the arrow by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is false by default, if you want making it possible to highlight and move the object + // change it to true ... + ObjectSetInteger(chartID,name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point of Arrow ... +bool MoveArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if(!time) { + time = TimeCurrent(); + } + + // + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete an arrow ... +bool DeleteArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow" // arrow name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete an arrow ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete an arrow! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the arrow code ... +bool ArrowCodeChange( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + const uchar code = 252 // arrow code +) { + // + // reset the error value ... + ResetLastError(); + + // + // change the arrow code ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, code)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the arrow code! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change anchor type ... +bool ArrowAnchorChange( + const long chartID = 0, // chart's ID + const string name="Arrow", // object name + const ENUM_ARROW_ANCHOR anchor = ANCHOR_TOP // anchor type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change anchor type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change anchor type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeArrowEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } +} +// +// End Arrow Functions ... +// + +// +// Start Horizontal Line Functions ... +// +// +// Create, Draw the horizontal line ... +bool DrawHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + const int subWindow = 0, // subwindow index + double price = 0, // line price + const color clr = clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the price is not set, set it at the current Bid price level ... + if(!price) { + price=SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // create a horizontal line ... + if(!ObjectCreate(chartID, name, OBJ_HLINE, subWindow, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move horizontal line ... +bool MoveHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + double price = 0 // line price +) { + // + // if the line price is not set, move it to the current Bid price level ... + if(!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move a horizontal line ... + if(!ObjectMove(chartID, name, 0, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete a horizontal line ... +bool DeleteHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a horizontal line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End Horizontal Line Functions ... +// + +// +// Start Vertical Line Functions ... +// +// +// Create the vertical line ... +bool DrawVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + const int sub_window = 0, // subwindow index + datetime time = 0, // line time + const color clr=clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the line time is not set, draw it via the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value + ResetLastError(); + + // + // create a vertical line ... + if (!ObjectCreate(chartID, name, OBJ_VLINE, sub_window, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return true; +} + +// +// Move the vertical line ... +bool MoveVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + datetime time = 0 // line time +) { + // + // if line time is not set, move the line to the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the vertical line ... + if(!ObjectMove(chartID, name, 0, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the vertical line ... +bool DeleteVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the vertical line ... + if (!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // successful execution ... + return true; +} +// +// End Vertical Line Functions ... +// + +// +// Start RectangleLabel Functions ... +// +// +// Create Rectangle Label Object ... +bool DrawRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int subWindow = 0, // subwindow index + const int x = 0, // X coordinate + const int y = 0, // Y coordinate + const int width = 50, // width + const int height = 18, // height + const color back_clr = C'236,233,216', // background color + const ENUM_BORDER_TYPE border = BORDER_SUNKEN, // border type + const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring + const color clr = clrRed, // flat border color (Flat) + const ENUM_LINE_STYLE style = STYLE_SOLID, // flat border style + const int lineWidth = 1, // flat border width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // reset the error value ... + ResetLastError(); + + // + //--- create a rectangle label + if(!ObjectCreate(chartID, name, OBJ_RECTANGLE_LABEL, subWindow, 0, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set label coordinates ... + ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x); + ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y); + + // + // set label size ... + ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width); + ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height); + + // + // set background color ... + ObjectSetInteger(chartID, name, OBJPROP_BGCOLOR, back_clr); + + // + // set border type ... + ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border); + + // + // set the chart's corner, relative to which point coordinates are defined ... + ObjectSetInteger(chartID, name, OBJPROP_CORNER, corner); + + // + // set flat border color (in Flat mode) ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set flat border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set flat border width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, lineWidth); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the label by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move Rectangle Label .. +bool MoveRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int x = 0, // X coordinate + const int y=0 // Y coordinate +) { + // + // reset the error value ... + ResetLastError(); + + // + // move the rectangle label ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move X coordinate of the label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move Y coordinate of the label! Error code = ",GetLastError() + ); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the rectangle label ... +bool DeleteRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel" // label name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the label ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change Rectangle Label Size ... +bool ChangeSizeRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int width = 50, // label width + const int height = 18 // label height +) { + // + // reset the error value ... + ResetLastError(); + + // + // change label size ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's width! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's height! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change rectangle label border type ... +bool RectLabelChangeBorderType( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const ENUM_BORDER_TYPE border = BORDER_SUNKEN // border type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change border type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the border type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End RectangleLabel Functions ... +// + +// +// Start TrendLine Funcions ... +// +// Create a trend line by the given coordinates ... +bool DrawTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrYellow, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool rayRight = false, // line's continuation to the right + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeTrendLineEmptyPoints( + time1, + price1, + time2, + price2 + ); + + // + // reset the error value ... + ResetLastError(); + + // + // create a trend line by the given coordinates ... + if(!ObjectCreate(chartID, name, OBJ_TREND, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the line's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move trend line anchor point ... | +bool ChangeTrendLinePoint( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int pointindex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move trend line's anchor point ... + if(!ObjectMove(chartID, name, pointindex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// The function deletes the trend line from the chart ... +bool DeleteTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a trend line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of trend line's anchor points and set default ... +// values for empty ones ... +void ChangeTrendLineEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the first point's time is not set, it will be on the current bar ... + if (!time1) { + time1 = TimeCurrent(); + } + + // + // if the first point's price is not set, it will have Bid value ... + if (!price1) { + price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // if the second point's time is not set, it is located 9 bars left from the second one ... + if (!time2) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(), Period(), time1, 10, temp); + + // + // set the second point 9 bars left from the first one ... + time2 = temp[0]; + } + + // + // if the second point's price is not set, it is equal to the first point's one ... + if (!price2) { + price2 = price1; + } +} +// +// End TrendLine Functions ... +// + +// +// Start Text Functions ... +// +// Create and Draw a Text Object ... +bool DrawText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const string text = "Text", // the text itself + const string font = "Arial", // font + const int fontSize = 10, // font size + const color clr = clrRed, // color + const double angle = 0.0, // text slope + const ENUM_ANCHOR_POINT anchor = ANCHOR_CENTER, // anchor type + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor point coordinates if they are not set ... + ChangeTextEmptyPoint(time,price); + + // + // reset the error value ... + ResetLastError(); + + // + //--- create Text object + if(!ObjectCreate(chartID, name, OBJ_TEXT, subWindow, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the text ... + ObjectSetString(chartID, name , OBJPROP_TEXT, text); + + // + // set text font ... + ObjectSetString(chartID, name, OBJPROP_FONT, font); + + // + // set font size ... + ObjectSetInteger(chartID, name, OBJPROP_FONTSIZE, fontSize); + + // + // set the slope angle of the text ... + ObjectSetDouble(chartID, name, OBJPROP_ANGLE, angle); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the object by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID ,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point ... +bool MoveText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + //--- if point position is not set, move it to the current bar having Bid price + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point .. + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the object text ... +bool ChangeText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const string text = "Text" // text +) { + // + // reset the error value ... + ResetLastError(); + + // + // change object text ... + if(!ObjectSetString(chartID, name, OBJPROP_TEXT, text)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the text! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Text object ... +bool DeleteText( + const long chartID = 0, // chart's ID + const string name = "Text" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeTextEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + } +// +// End Text Functions ... +// + +// +// Start Fibonacchi Functions ... +// +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawFibonacci( + const long chartID = 0, // chart's ID + const string name="Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrRed, // object color + const ENUM_LINE_STYLE style = STYLE_SOLID, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawCustomFibonacci( + // + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + // + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrAqua, // object color + const ENUM_LINE_STYLE style = STYLE_DOT, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // Change Levels Of Fibonacci ... + bool result = FibonacciLevelsSet( + levels, + values, + colors, + styles, + widths, + descriptions, + chartID, + name + ); + + // + // successful execution ... + return result; +} + +// +// Set number of levels and their parameters ... +bool FibonacciLevelsSet( + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // check array sizes ... + if( + levels!=ArraySize(colors) || + levels!=ArraySize(styles) || + levels!=ArraySize(widths) || + levels!=ArraySize(widths) + ) { + // + string message = StringConcatenate( + __FUNCTION__, + ": array length does not correspond to the number of levels, error!" + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the number of levels ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELS, levels); + + // + // set the properties of levels in the loop ... + for(int i = 0; i < levels; i++) { + // + // level value ... + ObjectSetDouble(chartID, name, OBJPROP_LEVELVALUE, i, values[i]); + + // + // level color ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELCOLOR, i, colors[i]); + + // + // level style ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELSTYLE, i, styles[i]); + + // + // level width ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELWIDTH, i, widths[i]); + + // + // level description ... + // ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, DoubleToString(100 * values[i], 1)); + ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, descriptions[i]); + } + + // + // successful execution ... + return(true); +} + +// +// Move Fibonacci Retracement anchor point ... +bool FibonacciPointChange( + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int pointIndex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, pointIndex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Fibonacci Retracement ... +bool DeleteFibonachi( + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Fibonacci Retracement\"! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of Fibonacci Retracement anchor points and set +// default values for empty ones ... +void ChangeFibonacciEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the second point's time is not set, it will be on the current bar ... + if (!time2) { + time2 = TimeCurrent(); + } + + // + // if the second point's price is not set, it will have Bid value ... + if (!price2) { + price2 = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // if the first point's time is not set, it is located 9 bars left from the second one ... + if (!time1) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(),Period(),time2,10,temp); + + // + // set the first point 9 bars left from the second one ... + time1 = temp[0]; + } + + // + // if the first point's price is not set, move it 200 points below the second one ... + if (!price1) { + price1 = price2 - 200 * SymbolInfoDouble(_Symbol, SYMBOL_POINT); + } +} +// +// End Fibonacci Functions ... +// + + +// +// Start General Functions ... +// +// +// Remove all Drawn Objects ... +void RemoveDraws(const string &tag) { + // + for(int iObj=ObjectsTotal()-1; iObj >= 0; iObj--) { + // + string on = ObjectName(iObj); + if (StringFind(on, tag) == 0) { + ObjectDelete(on); + } + } +} +// +// End General Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA/Libraries/x-saherelm.lib.mq4 b/Bkp/Used/OSC EA/Libraries/x-saherelm.lib.mq4 new file mode 100644 index 0000000..ed1bbc6 --- /dev/null +++ b/Bkp/Used/OSC EA/Libraries/x-saherelm.lib.mq4 @@ -0,0 +1,968 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +// START Functions ... +// + +// +// Determines current working is New Bar or not ... +bool IsNewBar() { + // + static datetime lastbar; + datetime curbar = (datetime)SeriesInfoInteger(_Symbol, _Period, SERIES_LASTBAR_DATE); + + // + if(lastbar != curbar) { + // + lastbar = curbar; + return true; + } + + // + return false; +} + +// +// Retrieve RMA on Specific Candle ... +double GetRMA( + int bar_index, + int length +) { + // + double shortSMA = iMA(_Symbol, _Period, length, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double mediumSMA = iMA(_Symbol, _Period, length * 2, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double longSMA = iMA(_Symbol, _Period, length * 3, 0, MODE_SMA, PRICE_CLOSE, bar_index); + + // + double result = longSMA - mediumSMA + shortSMA; + + // + return result; +} + +// +// this function check crossing up two Buffers ... +bool IsCrossedOver( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] > arr2[index1]) && !(arr1[index2] > arr2[index2]); + + // + return result; +} + +// +// this function check crossing down two Buffers ... +bool IsCrossedUnder( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] < arr2[index1]) && !(arr1[index2] < arr2[index2]); + + // + return result; +} + +// +// Convert points to Actual Point ... +double PointsToDouble(int points) { + // + double result = points * _Point; + return result; +} + +// +// Converts Pips to Points ... +int PipsToPoints(int pips) { + // + int result = pips * ((_Digits == 3 || _Digits == 5) ? 10 : 1); + return result; +} + +// +// Converts Pips to Double ... +double PipsToDouble(int pips) { + // + double result = PointsToDouble(PipsToPoints(pips)); + return result; +} + +// +// Converts Double Value to Pips ... +int PriceToPips(double value) { + // + if (value <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + int result = (int)(value / pipValue); + + // + return result; +} + +// +// Converts Pips to Double ... +double PipsToPrice(int pips) { + // + if (pips <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + double result = pipValue * pips; + + // + return result; +} + +// +// Generate ATR StopLoss Value ... +double CalculateATRSL( + int period, + double multiplier +) { + // + if (period <= 0 || multiplier <= 0) { + return 0; + } + + // + double atrValue = iATR( + _Symbol, + _Period, + period, + 0 + ); + + // + double result = atrValue * multiplier; + + // + return result; +} + +// +// Detect Candle Type ... +// Bullish => means close > open ... +bool isBullishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = isBullishCandle( + open, + close + ); + + // + return result; +} + +bool isBullishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open < close; + + // + return result; +} + +// +// Detect Candle Type ... +// Bearish => means close < open ... +bool isBearishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = isBearishCandle( + open, + close + ); + + // + return result; +} + +bool isBearishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open > close; + + // + return result; +} + +// +// Retrieve Highest High Value based on Given Market ... +double GetMarketHighestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest High Value based on Given Market ... +double GetMarketLowestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest High Value based on Given Market ... +double GetMarketHighestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest High Value based on Given Market ... +double GetMarketLowestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// less than given price ... +double GetLowLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// great than given price ... +double GetLowGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// less than given price ... +double GetHighLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// great than given price ... +double GetHighGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// less than given price ... +double GetCloseLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// great than given price ... +double GetCloseGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +struct XMinMax { + double min; + double max; +}; + +// +// Find Min and Max Value of specific Buffer ... +XMinMax GetBufferMinMax(const double &buffer[]) { + // + XMinMax result = {}; + + // + int bufferSize = ArraySize(buffer); + if (bufferSize < 1) { + return result; + } + + // + double min = buffer[0]; + double max = buffer[0]; + + // + for (int i = 1; i < bufferSize; i++) { + // + if (buffer[i] < min) { + min = buffer[i]; + } else if (buffer[i] > max) { + max = buffer[i]; + } + } + + // + result.min = min; + result.max = max; + + // + return result; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/Used/OSC EA/Libraries/x-saherelm.log.lib.mq4 b/Bkp/Used/OSC EA/Libraries/x-saherelm.log.lib.mq4 new file mode 100644 index 0000000..eb5ea36 --- /dev/null +++ b/Bkp/Used/OSC EA/Libraries/x-saherelm.log.lib.mq4 @@ -0,0 +1,47 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Log Tag ... +static string logTag = ""; + +// +// Enable or Disable Logging ... +static bool enableLogging = false; + +// +// Start Log Messages ... +// + +// +// Logging a Message, specified for this EA ... +// using provided LogTag ... +void LogMessage(string message) { + // + if (!enableLogging) { + return; + } + + // + Print(logTag, " > ", message); +} + +// +// End Log Messages ... +// + diff --git a/Bkp/Used/OSC EA/Libraries/x-saherelm.osc.models.lib.mq4 b/Bkp/Used/OSC EA/Libraries/x-saherelm.osc.models.lib.mq4 new file mode 100644 index 0000000..a22cf6d --- /dev/null +++ b/Bkp/Used/OSC EA/Libraries/x-saherelm.osc.models.lib.mq4 @@ -0,0 +1,194 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Models Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Start Models ... +// + +// +// Used Indicators List ... +const string xmaIndicatorName = "x-saherelm.xma"; +const string adxIndicatorName = "x-saherelm.adx"; +const string oscIndicatorName = "x-saherelm.osc"; +const string zigZagIndicatorName = "x-saherelm.zigzag"; + +// +// Direction ... +enum X_DIRECTION { + X_UP, + X_DOWN +}; + +// +// these are different signal types ... +enum X_SIGNAL_TYPE { + X_NONE, + X_LONG, + X_SHORT, +}; + +// +// we Model each signals as this type ... +struct XSignal { + int id; + X_SIGNAL_TYPE type; + double tp; + double sl; + string symbol; + datetime time; + double entryPrice; +}; + +// +// this is Signal Request Response model ... +struct XSignalRequest { + bool hasSignal; + X_SIGNAL_TYPE type; + XSignal signal; +}; + +// +// we model OSC Return Data ... +struct XOSCState { + // + double fastOSC; + double fastOSCPrev; + + // + double slowOSC; + double slowOSCPrev; + + // + double powerOSC; + double powerOSCPrev; + + // + double varOSC; + double varOSCPrev; + + // + double tanFSOSC; + + // + bool isOSCCrossOver; + bool isOSCCrossUnder; +}; + +// +// Define a Model to Represent Snapshot of XMA Indicator ... +struct XMAState { + // + // Short Cycle ... + // + // FAST ... + double scFast; + double scFastPrev; + + // + // SLOW ... + double scSlow; + double scSlowPrev; + + // + bool isSCTrendUp; + + // + // Medium Cycle ... + // + // FAST ... + double mcFast; + double mcFastPrev; + + // + // SLOW ... + double mcSlow; + double mcSlowPrev; + + // + // Long Cycle ... + // + // FAST ... + double lcFast; + double lcFastPrev; + + // + // SLOW ... + double lcSlow; + double lcSlowPrev; + + // + // MIDDLEAGE ... + double marketMiddleage; + double marketMiddleagePrev; +}; + +// +// Represent ADX State ... +struct XADXState { + // + double trendPower; + double trendPowerPrev; + + // + double upDirection; + double upDirectionPrev; + + // + double downDirection; + double downDirectionPrev; + + // + bool isUpTrend; + bool isDownTrend; +}; + +// +// ZigZag State ... +struct XZigZagState { + // + double zigZag; + datetime zigZagTime; + + // + double zigZagPrev; + datetime zigZagPrevTime; + + // + double low; + int lowBarIndex; + datetime lowTime; + + // + double high; + int highBarIndex; + datetime highTime; + + // + double delta; + + // + bool isWaitForTrendUp; + bool isWaitForTrendDown; + + // + bool isLowIsLastLow; + bool isHighIsLastHigh; +}; +// +// End Models ... +// diff --git a/Bkp/Used/OSC EA/Libraries/x-saherelm.osc.signal.lib.mq4 b/Bkp/Used/OSC EA/Libraries/x-saherelm.osc.signal.lib.mq4 new file mode 100644 index 0000000..94e8959 --- /dev/null +++ b/Bkp/Used/OSC EA/Libraries/x-saherelm.osc.signal.lib.mq4 @@ -0,0 +1,2641 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Signal Draw Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.osc.models.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +static int totalSignals = 0; +static int totalLongSignals = 0; +static int totalShortSignals = 0; + +// +static double initialBalance = 0; + +// +static int countedBars = 0; +static bool isNewBar = false; + +// +static XMAState xmaState; +static XOSCState oscState; +static XADXState adxState; +static XZigZagState zigZagState; + +// +// Retrieve ZigZag State ... +XZigZagState GetZigZagState( + const int bar_index, + int zDpt = 7, + int zDev = 5, + int zBkStp = 3 +) { + // + XZigZagState result = {}; + + // + int counter = bar_index; + + // + double lastValue = 0.0; + datetime lastValueTime = 0; + + // + double lastPrevValue = 0.0; + datetime lastPrevValueTime = 0; + + // + // START Retrieve ZigZag ... + // + while ( + lastValue == 0.0 || + lastPrevValue == 0.0 + ) { + // + // ZigZag ... + double zigZag = iCustom( + _Symbol, + _Period, + zigZagIndicatorName, + zDpt, // Depth ... + zDev, // Deviation ... + zBkStp, // BackStep ... + 0, // Buffer Index ... + counter + ); + + // + if (zigZag != 0.0) { + // + if (lastValue == 0.0) { + // + lastValue = zigZag; + lastValueTime = iTime( + _Symbol, + _Period, + counter + ); + } else if (lastPrevValue == 0.0) { + // + lastPrevValue = zigZag; + lastPrevValueTime = iTime( + _Symbol, + _Period, + counter + ); + } + } + + // + counter++; + } + // + // END Retrieve ZigZag ... + // + + // + result.zigZag = lastValue; + result.zigZagTime = lastValueTime; + + // + result.zigZagPrev = lastPrevValue; + result.zigZagPrevTime = lastPrevValueTime; + + // + double delta = lastPrevValue - lastValue; + result.delta = delta; + + // + bool isWaitForTrendUp = delta > 0; + result.isWaitForTrendUp = isWaitForTrendUp; + + // + bool isWaitForTrendDown = delta < 0; + result.isWaitForTrendDown = isWaitForTrendDown; + + // + double low = isWaitForTrendUp ? + lastValue : + lastPrevValue; + datetime lowTime = isWaitForTrendUp ? + lastValueTime : + lastPrevValueTime; + int lowBarIndex = iBarShift( + _Symbol, + _Period, + lowTime + ); + // + result.low = low; + result.lowTime = lowTime; + result.lowBarIndex = lowBarIndex; + + // + double high = isWaitForTrendUp ? + lastPrevValue : + lastValue; + datetime highTime = isWaitForTrendUp ? + lastPrevValueTime : + lastValueTime; + int highBarIndex = iBarShift( + _Symbol, + _Period, + highTime + ); + + // + result.high = high; + result.highTime = highTime; + result.highBarIndex = highBarIndex; + + // + // Check Signals Occured exactly after high or low ... + bool isLowIsLastLow = false; + bool isHighIsLastHigh = false; + for (int i = zBkStp - 1; i <= 0; i--) { + // + double lLow = iLow( + _Symbol, + _Period, + i + ); + + // + isLowIsLastLow = isLowIsLastLow + || lLow == low + || MathAbs(lLow - low) < 0.05; + + // + double lHigh = iHigh( + _Symbol, + _Period, + i + ); + + // + isHighIsLastHigh = high + || lHigh == high + || MathAbs(lHigh - high) < 0.05; + } + + // + result.isLowIsLastLow = isLowIsLastLow; + result.isHighIsLastHigh = isHighIsLastHigh; + + // + return result; +} + +// +// Retrieve State ... +XOSCState GetOSCState( + const int bar_index, + const int foLen, + const double foMul, + const int slLen, + const double slMul +) { + // + // Define Trend Direction Related Values ... + // + XOSCState result = {}; + + // + // START Extract Data from Oscillator ... + // + // + // Fast OSC ... + double fastOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 0, // Fast OSC Buffer Index ... + bar_index + ); + result.fastOSC = fastOSC; + + // + // Prev FastOSC ... + double fastOSCPrev = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 0, // Fast OSC Buffer Index ... + bar_index + 1 + ); + result.fastOSCPrev = fastOSCPrev; + + // + // Slow OSC ... + double slowOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 1, // Slow OSC Buffer Index ... + bar_index + ); + result.slowOSC = slowOSC; + + // + // Prev Slow OSC ... + double slowOSCPrev = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 1, // Slow OSC Buffer Index ... + bar_index + 1 + ); + result.slowOSCPrev = slowOSCPrev; + + // + // Power OSC ... + double powerOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 2, // Power OSC Buffer Index ... + bar_index + ); + result.powerOSC = powerOSC; + + // + double powerOSCPrev = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 2, // Power OSC Buffer Index ... + bar_index + 1 + ); + result.powerOSCPrev = powerOSCPrev; + + // + // Var OSC ... + double varOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 3, // Var OSC Buffer Index ... + bar_index + ); + result.varOSC = varOSC; + + // + double varOSCPrev = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 3, // Var OSC Buffer Index ... + bar_index + 1 + ); + result.varOSCPrev = varOSCPrev; + + // + // Tan FS OSC ... + double tanFSOSC = iCustom( + _Symbol, + _Period, + oscIndicatorName, + foLen, + foMul, + slLen, + slMul, + 4, // Tan F/S OSC Buffer Index ... + bar_index + ); + result.tanFSOSC = tanFSOSC; + // + // END Extract Data from Oscillator ... + // + + // + // Calculations ... + // + bool isOSCCrossOver = fastOSC > slowOSC && + !(fastOSCPrev > slowOSCPrev); + result.isOSCCrossOver = isOSCCrossOver; + + // + bool isOSCCrossUnder = fastOSC < slowOSC && + !(fastOSCPrev < slowOSCPrev); + result.isOSCCrossUnder = isOSCCrossUnder; + + // + return result; +} + +// +// Check Market Ranging or not based on OSC ... +bool IsOSCMarketRanging( + // + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double rangingThreshold, // Detect Ranging based On Power OSC ... + // + // OSC Specifications ... + const int foLen, // Fast OSC Length ... + const double foMul, // Fast OSC Multiplier ... + const int slLen, // Slow OSC Length ... + const double slMul // Slow OSC Multiplier ... +) { + // + bool result = false; + + // + // Detect Buffer Size ... + const int bufferSize = marketLen + bar_index; + double powerOSCBuffer[]; + ArraySetAsSeries( + powerOSCBuffer, + true + ); + ArrayResize( + powerOSCBuffer, + bufferSize + ); + + // + // Loop through Market for Extract PowerOSC from OSC Indicator ... + for (int i = bufferSize - 1; i >= 0; i--) { + // + // Retrieve OSC State at Specific Bar Index ... + XOSCState state = GetOSCState( + i, + foLen, + foMul, + slLen, + slMul + ); + + // + powerOSCBuffer[i] = state.powerOSC; + } + + // + // now we have to extract min and max value of Splitted Buffer ... + XMinMax minMax = GetBufferMinMax(powerOSCBuffer); + + // + // now Check Min and Max Direction and Compare them with Ranging Value ... + result = MathAbs(minMax.min) > rangingThreshold + || MathAbs(minMax.max) > rangingThreshold; + + // + return result; +} + +// +// Retrieve and Calculate XMA State ... +XMAState GetXMAState( + const int bar_index, // Bar Index ... + // + // Market Length ... + const int marketLen, // Market Length ... + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + const int scFastMul, // Short Cycle Fast Multiplier ... + const int scSlowMul, // Short Cycle Slow Multiplier ... + const int mcFastMul, // Medium Cycle Fast Multiplier ... + const int mcSlowMul, // Medium Cycle Slow Multiplier ... + const int lcFastMul, // Long Cycle Fast Multiplier ... + const int lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + const bool showSC, // Show Short Cycle + const bool showSCCrossLines, // Show Short Cycle Vertical Lines + const bool showMC, // Show Medium Cycle + const bool showMCCrossLines, // Show Medium Cycle Vertical Lines + const bool showLC, // Show Long Cycle + const bool showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + const color sxFastColor, // Short Cycle Fast Color ... + const color scSlowColor, // Short Cycle Slow Color ... + const color mcFastColor, // Medium Cycle Fast Color ... + const color mcSlowColor, // Medium Cycle Slow Color ... + const color lcFastColor, // Medium Cycle Fast Color ... + const color lcSlowColor // Medium Cycle Slow Color ... +) { + // + // Temp Result ... + XMAState result = {}; + + // + // START Reading Buffers ... + // + // + // Define BufferIndexes ... + int scFastBufIndex = 0; + int scSlowBufIndex = 1; + int mcFastBufIndex = 2; + int mcSlowBufIndex = 3; + int lcFastBufIndex = 4; + int lcSlowBufIndex = 5; + int midBufIndex = 6; + + // + // START Short Cycle ... + // + // + // Short Cycle Fast ... + double scFast = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + scFastBufIndex, // Buffer Index ... + bar_index + ); + result.scFast = scFast; + + // + // Short Cycle Previous Fast ... + double scFastPrev = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + scFastBufIndex, // Buffer Index ... + bar_index + 1 + ); + result.scFastPrev = scFastPrev; + + // + // Short Cycle Slow ... + double scSlow = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + scSlowBufIndex, // Buffer Index ... + bar_index + ); + result.scSlow = scSlow; + + // + // Short Cycle Previous Slow ... + double scSlowPrev = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + scSlowBufIndex, // Buffer Index ... + bar_index + 1 + ); + result.scSlowPrev = scSlowPrev; + // + // END Short Cycle ... + // + + // + // START Medium Cycle ... + // + // + // Medium Cycle Fast ... + double mcFast = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + mcFastBufIndex, // Buffer Index ... + bar_index + ); + result.mcFast = mcFast; + + // + // Medium Cycle Previous Fast ... + double mcFastPrev = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + mcFastBufIndex, // Buffer Index ... + bar_index + 1 + ); + result.mcFastPrev = mcFastPrev; + + // + // Medium Cycle Slow ... + double mcSlow = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + mcSlowBufIndex, // Buffer Index ... + bar_index + ); + result.mcSlow = mcSlow; + + // + // Medium Cycle Previous Slow ... + double mcSlowPrev = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + mcSlowBufIndex, // Buffer Index ... + bar_index + 1 + ); + result.mcSlowPrev = mcSlowPrev; + // + // END Medium Cycle ... + // + + // + // START Long Cycle ... + // + // + // Long Cycle Fast ... + double lcFast = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + lcFastBufIndex, // Buffer Index ... + bar_index + ); + result.lcFast = lcFast; + + // + // Long Cycle Previous Fast ... + double lcFastPrev = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + lcFastBufIndex, // Buffer Index ... + bar_index + 1 + ); + result.lcFastPrev = lcFastPrev; + + // + // Long Cycle Slow ... + double lcSlow = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + lcSlowBufIndex, // Buffer Index ... + bar_index + ); + result.lcSlow = lcSlow; + + // + // Long Cycle Previous Slow ... + double lcSlowPrev = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + lcSlowBufIndex, // Buffer Index ... + bar_index + 1 + ); + result.lcSlowPrev = lcSlowPrev; + // + // END Long Cycle ... + // + + // + // START Makret Middleage ... + // + // + // Market Middleage ... + double marketMiddleage = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + midBufIndex, // Buffer Index ... + bar_index + ); + result.marketMiddleage = marketMiddleage; + + // + // Previous Market Middleage ... + double marketMiddleagePrev = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + marketLen, // Market Length ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor, // Medium Cycle Slow Color ... + // + midBufIndex, // Buffer Index ... + bar_index + 1 + ); + result.marketMiddleagePrev = marketMiddleagePrev; + // + // END Makret Middleage ... + // + // + // END Reading Buffers ... + // + + // + return result; +} + +// +// Retrieve XADX State ... +XADXState GetADXState( + // + const int bar_index, // Bar Index ... + // + const int marketLen // Market Length ... +) { + // + // Temp Result ... + XADXState result = {}; + + // + // Define Buffer Index ... + int adxBufferIndex = 0; + int positiveBufferIndex = 1; + int negativeBufferIndex = 2; + + // + ENUM_APPLIED_PRICE appliedPrice = PRICE_WEIGHTED; + + // + // START Recieve Buffers ... + // + // + // TRENDPOWER ... + double trendPower = iCustom( + // + // Global Data ... + _Symbol, + _Period, + // + // Indicator Name ... + adxIndicatorName, + // + // Indicator Inputs ... + marketLen, // Averaging Period ... + appliedPrice, // Averaging Applied Price ... + // + // Buffer Index + adxBufferIndex, // ADX Trend Power Buffer Index ... + // + // Shift or Bar Index ... + bar_index + ); + result.trendPower = trendPower; + + // + // TRENDPOWER Prev ... + double trendPowerPrev = iCustom( + // + // Global Data ... + _Symbol, + _Period, + // + // Indicator Name ... + adxIndicatorName, + // + // Indicator Inputs ... + marketLen, // Averaging Period ... + appliedPrice, // Averaging Applied Price ... + // + // Buffer Index + adxBufferIndex, // ADX Trend Power Buffer Index ... + // + // Shift or Bar Index ... + bar_index + 1 + ); + result.trendPowerPrev = trendPowerPrev; + + // + // UP Dir ... + double upDirection = iCustom( + // + // Global Data ... + _Symbol, + _Period, + // + // Indicator Name ... + adxIndicatorName, + // + // Indicator Inputs ... + marketLen, // Averaging Period ... + appliedPrice, // Averaging Applied Price ... + // + // Buffer Index + positiveBufferIndex, // Up Direction Buffer Index ... + // + // Shift or Bar Index ... + bar_index + ); + result.upDirection = upDirection; + + // + // UP Dir Prev ... + double upDirectionPrev = iCustom( + // + // Global Data ... + _Symbol, + _Period, + // + // Indicator Name ... + adxIndicatorName, + // + // Indicator Inputs ... + marketLen, // Averaging Period ... + appliedPrice, // Averaging Applied Price ... + // + // Buffer Index + positiveBufferIndex, // Up Direction Buffer Index ... + // + // Shift or Bar Index ... + bar_index + 1 + ); + result.upDirectionPrev = upDirectionPrev; + + // + // DOWN Dir ... + double downDirection = iCustom( + // + // Global Data ... + _Symbol, + _Period, + // + // Indicator Name ... + adxIndicatorName, + // + // Indicator Inputs ... + marketLen, // Averaging Period ... + appliedPrice, // Averaging Applied Price ... + // + // Buffer Index + negativeBufferIndex, // Down Direction Buffer Index ... + // + // Shift or Bar Index ... + bar_index + ); + result.downDirection = downDirection; + + // + // DOWN Dir Prev ... + double downDirectionPrev = iCustom( + // + // Global Data ... + _Symbol, + _Period, + // + // Indicator Name ... + adxIndicatorName, + // + // Indicator Inputs ... + marketLen, // Averaging Period ... + appliedPrice, // Averaging Applied Price ... + // + // Buffer Index + negativeBufferIndex, // Down Direction Buffer Index ... + // + // Shift or Bar Index ... + bar_index + 1 + ); + result.downDirectionPrev = downDirectionPrev; + // + // END Recieve Buffers ... + // + + // + // Calculations ... + + // + bool isUpTrend = upDirection > downDirection + && upDirectionPrev > downDirectionPrev; + result.isUpTrend = isUpTrend; + + // + bool isDownTrend = upDirection < downDirection + && upDirectionPrev < downDirectionPrev; + result.isDownTrend = isDownTrend; + + // + return result; +} + +// +// Calculate Fib Level ... +double GetFibonacciLevel( + double upPrice, + double downPrice, + double level, + X_DIRECTION direction +) { + // + double ling = upPrice - downPrice; + double pLevel = (ling / 100) * (level * 100); + + // + double result = direction == X_UP ? + upPrice - pLevel : + downPrice + pLevel; + result = NormalizeDouble(result, _Digits); + + // + return result; +} +// +// END Global Requirement Functions ... +// + +// +// START Signal Related Functions ... +// +// +// Calculate Signal ... +// in this function we calculate a signal exists in +// specific bar or not ... +XSignalRequest CalculateSignal( + // + const int bar_index, // Bar Index ... + // + // MARKET Specifications ... + const int marketLen, // Market Length ... + const double r2r, // Risk To Reward Ratio ... + // + // XMA Inputs ... + // + const int scFastMul, // Short Cycle Fast Multiplier ... + const int scSlowMul, // Short Cycle Slow Multiplier ... + const int mcFastMul, // Medium Cycle Fast Multiplier ... + const int mcSlowMul, // Medium Cycle Slow Multiplier ... + const int lcFastMul, // Long Cycle Fast Multiplier ... + const int lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + const bool showSC, // Show Short Cycle + const bool showSCCrossLines, // Show Short Cycle Vertical Lines + const bool showMC, // Show Medium Cycle + const bool showMCCrossLines, // Show Medium Cycle Vertical Lines + const bool showLC, // Show Long Cycle + const bool showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + const color sxFastColor, // Short Cycle Fast Color ... + const color scSlowColor, // Short Cycle Slow Color ... + const color mcFastColor, // Medium Cycle Fast Color ... + const color mcSlowColor, // Medium Cycle Slow Color ... + const color lcFastColor, // Medium Cycle Fast Color ... + const color lcSlowColor, // Medium Cycle Slow Color ... + // + // OSC Inputs ... + const int fastOSCLen, // FastOSC Length ... + const double fastOSCMul, // FastOSC Multiplier ... + const int slowOSCLen, // SlowOSC Length ... + const double slowOSCMul, // SlowOSC Multiplier ... + const double minPowOSC, // Minimum Signal Power ... + const double minVarOSC, // Minimum Var Power ... + // + // ZIGZAG Inputs ... + const int zDev, // ZigZag Deviation ... + const int zBkStep // ZigZag Back Step ... +) { + // + // create temp result ... + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_NONE; + + // + XSignal signal = {}; + + // + // Retrieve ZigZag State ... + + // + // START Capturing Signal ... + // + // + // START Retrieve Statets ... + // + // Reading Oscillator State ... + oscState = GetOSCState( + bar_index, + fastOSCLen, + fastOSCMul, + slowOSCLen, + slowOSCMul + ); + + // + // Retrieve ZigZag State ... + zigZagState = GetZigZagState( + bar_index, + marketLen, + zDev, + zBkStep + ); + + // + // Retrieve Market Trend ... + xmaState = GetXMAState( + // + // Bar Index ... + bar_index, // Bar Index ... + // + // Market Length ... + marketLen, // Market Length ... + // + // XMA Inputs ... + // + // Market Specification Inpouts ... + scFastMul, // Short Cycle Fast Multiplier ... + scSlowMul, // Short Cycle Slow Multiplier ... + mcFastMul, // Medium Cycle Fast Multiplier ... + mcSlowMul, // Medium Cycle Slow Multiplier ... + lcFastMul, // Long Cycle Fast Multiplier ... + lcSlowMul, // Long Cycle Slow Multiplier ... + // + // Show/Hide Inputs ... + showSC, // Show Short Cycle + showSCCrossLines, // Show Short Cycle Vertical Lines + showMC, // Show Medium Cycle + showMCCrossLines, // Show Medium Cycle Vertical Lines + showLC, // Show Long Cycle + showLCCrossLines, // Show Long Cycle Vertical Lines + // + // Color Inputs ... + sxFastColor, // Short Cycle Fast Color ... + scSlowColor, // Short Cycle Slow Color ... + mcFastColor, // Medium Cycle Fast Color ... + mcSlowColor, // Medium Cycle Slow Color ... + lcFastColor, // Medium Cycle Fast Color ... + lcSlowColor // Medium Cycle Slow Color ... + ); + + // + // Retrieve ADX State ... + adxState = GetADXState( + // + bar_index, // Bar Index ... + // + marketLen // Market Length ... + ); + // + // END Retrieve Statets ... + // + + // + // START States Calculations ... + // + // + // START PRICE Calculations ... + // + RefreshRates(); + + // + double candleLow = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double candleHigh = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + // LONG Prices ... + double longEntryPrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK); + double longClosePrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); + double longPriceGap = longClosePrice - longEntryPrice; + + // + // SHORT Prices ... + double shortEntryPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); + double shortClosePrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK); + double shortPriceGap = shortEntryPrice - shortClosePrice; + // + // END PRICE Calculations ... + // + + // + // START LONG Signals ... + // + bool hasLongSignal = false; + + // + // XMA Based Signals ... + bool xmaHasLongSignal = + // + // XMA ... + // + // SC Fast Cross Over Market Middleage ... + xmaState.scFast > xmaState.marketMiddleage + && !(xmaState.scFastPrev > xmaState.marketMiddleage) + // + // when Short Cycle is Trending Up ... + && xmaState.scFast > xmaState.scSlow + && xmaState.scFastPrev > xmaState.scSlowPrev + // + // When Medium Cycle is Trending Up ... + && xmaState.mcFast > xmaState.mcSlow + && xmaState.mcFastPrev > xmaState.mcSlowPrev + // + // and Medium Cycle TrendPower is Going Up ... + && MathAbs(xmaState.mcFast - xmaState.mcSlow) > + MathAbs(xmaState.mcFastPrev - xmaState.mcSlowPrev) + // + // When Long Cycle is Trending Up ... + && xmaState.lcFast > xmaState.lcSlow + && xmaState.lcFastPrev > xmaState.lcSlowPrev + // + // and Long Cycle TrendPower is Going Up ... + && MathAbs(xmaState.lcFast - xmaState.lcSlow) > + MathAbs(xmaState.lcFastPrev - xmaState.lcSlowPrev) + // + // Short Cycle Slow bigger thhan Medium Cycle Fast ... + && xmaState.scSlow > xmaState.mcFast + // + // OSC ... + // Check OSC Fast and Slow is Less than 0.5 ... + && oscState.fastOSC < 0.5 + && oscState.slowOSC < 0.5 + // + // Check OSC Minimum Signal Power ... + // this Helps for Detect Market exits from Ranging ... + && minPowOSC > 0 + ? + // + // Check Conditions only if value provided ... + oscState.powerOSCPrev < 0 + && MathAbs(oscState.powerOSCPrev) > minPowOSC + : + // + // ... other wise, ignore ... + true + // + // Check Previous Candle Signal Power must be Lower than + // Current Signal Power and the Direction Must be Up Trend ... + && oscState.powerOSCPrev < oscState.powerOSC + // + // Also we Have to Check Market not ranging ... + && !IsOSCMarketRanging( + bar_index + 1, + marketLen, + minPowOSC, + fastOSCLen, + fastOSCMul, + slowOSCLen, + slowOSCMul + ) + // + // XADX ... + // TODO: add XADX Base Conditions for Long Trades ... + // + // PRICE Checking ... + // price must be less than Candle High at openning time ... + && longEntryPrice <= candleHigh + // + // also Candle High and Low must be above than lc Fast & lc Slow ... + && longEntryPrice > xmaState.lcFast + && longEntryPrice > xmaState.lcSlow + ; + + // + // Has Some Good Points ... + // double oscTreshold = 0.5; + bool oscHasLongSignal = + false + // // + // // OSC ... + // oscState.isOSCCrossOver + // // + // // XMA ... + // // + // // + // // PRICE ... + // && longEntryPrice <= candleHigh + ; + + // + hasLongSignal = + xmaHasLongSignal || oscHasLongSignal; + // + // END LONG Signals ... + // + + // + // START SHORT Signals ... + // + bool hasShortSignal = false; + + // + // Recieve Signals Based on XOSC ... + // hasShortSignal = + // oscState.hasShortSignal + // ; + // + // END SHORT Signals ... + // + + // + // Check Signal Exists regardless of Long or Short ... + bool hasSignal = hasLongSignal || hasShortSignal; + + // + // Prevent from Going forward if there is not a Signal ... + if (!hasSignal) { + // + result.signal = signal; + return result; + } + + // + totalSignals++; + + // + // Define Price Related Variables ... + // + double price = 0; + double priceGap; + double sl = 0; + double risk; + double reward; + double tp = 0; + + // + datetime time = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Fill Signal Related Variables ... + if (hasLongSignal) { + // + totalLongSignals++; + + // + price = longEntryPrice; + priceGap = longPriceGap; + + // // + // // Setting Up SL Based on Prev Candle ... + // sl = prevCandleLow; + + // + // Setting Up SL Based on Last Market Lowest ... + sl = GetMarketLowestLow( + bar_index, + marketLen + ); + + // // + // // Setting Up SL Based on Prev Candle Less Low Price ... + // sl = GetLowLessCandlePrice( + // bar_index, + // price + // ); + + // + risk = price - sl; + reward = risk * r2r; + tp = price + reward; + + // + // Check TP for prevent from 5 Pips ... + // double pipsPrice = PipsToPrice(2); + // if (tp > price + pipsPrice) { + // tp = price + pipsPrice; + // } + + // + // Check TP based on Spread ... + if (tp < price + priceGap) { + tp = tp + priceGap; + } + } else if (hasShortSignal) { + // + totalShortSignals++; + + // + price = shortEntryPrice; + priceGap = shortPriceGap; + + // // + // // Setting Up SL Based On Prev Candle ... + // sl = prevCandleHigh; + + // // + // // Setting Up SL Based on Last Market Highest ... + // sl = GetMarketHighestHigh( + // bar_index, + // marketLen + // ); + + // + // Setting Up SL Based on Prev Candle Great High Price ... + sl = GetHighGreatCandlePrice( + bar_index, + price + ); + + // + risk = sl - price; + reward = risk * r2r; + tp = price - reward; + } + + // + // Normalize Prices ... + price = NormalizeDouble(price, _Digits); + sl = NormalizeDouble(sl, _Digits); + tp = NormalizeDouble(tp, _Digits); + + // + // Generate Signal Structure ... + signal.type = hasLongSignal ? + X_LONG : + X_SHORT; + signal.tp = tp; + signal.sl = 0; // sl; + signal.time = time; + signal.symbol = _Symbol; + signal.entryPrice = price; + signal.id = totalLongSignals; + // + // END Capturing Signal ... + // + + // + // Fill Result ... + result.hasSignal = hasSignal; + result.signal = signal; + result.type = signal.type; + + // + return result; +} + +// +// START Signal Verification Functions ... +// +// +// END Signal Verification Functions ... +// + +// +// START Market State Functions ... +// +// +// END Market State Functions ... +// + +// +// Retrieve Signal Bar Index ... +int GetSignalBarIndex(XSignal &signal) { + // + // Temp Result ... + int result = -1; + + // + // Retriev Signal Bar Index ... + result = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + return result; +} + +// +// Generate a Unique ID for Signal ... +string GenerateSignalTAG( + const XSignal &signal, + const string tag, + const string longSignalLabel, + const string shortSignalLabel +) { + // + // Generate Propper Label for Signal ... + string label = signal.type == X_LONG ? longSignalLabel : signal.type == X_SHORT ? shortSignalLabel : "UN_KNOWN"; + + // + // Generate Unique String Identifier for Signal ... + string result = tag + + "_[ID:" + IntegerToString(signal.id) + "]" + + "_[" + label + "]" + + "_[" + signal.symbol + "]" + + "_[Time:" + TimeToStr(signal.time) + "]" + + "_[TP:" + DoubleToString(signal.tp) + "]" + + "_[SL:" + DoubleToString(signal.sl) + "]"; + + // + return result; +} + +// +// Draw Signal Shapes on Chart ... +bool DrawSignal( + const XSignal &signal, + long chartID = 0, + int subWindowID = 0, + const double positionThresholdFactor = 10, + string signalTag = "X-Signal", + string longSignalLabel = "X-Long", + color longSignalColor = clrAqua, + string shortSignalLabel = "X-Short", + color shortSignalColor = clrFuchsia +) { + // + // Generate isLongSignal Var ... + bool isLongSignal = signal.type == X_LONG; + + // + // Signal Bar Index ... + int bar_index = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // START Draw Signal Arrow ... + // + // + // Arrow Shape Name ... + string arrowName = StringConcatenate(signalTag, "_Arrow_", signal.id); + + // + // Arrow Price ... + double arrowPrice = 0; + if (isLongSignal) { + // + arrowPrice = iLow( + _Symbol, + _Period, + bar_index + ); + + // + arrowPrice = arrowPrice - (positionThresholdFactor * _Point); + } else { + // + arrowPrice = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + arrowPrice = arrowPrice + (positionThresholdFactor * _Point); + } + + // + // Arrow Code ... + uchar arrowCode = isLongSignal ? SYMBOL_ARROWUP : SYMBOL_ARROWDOWN; + + // + // Arrow Anchor Point ... + ENUM_ARROW_ANCHOR arrowAnchorPoint = isLongSignal ? ANCHOR_BOTTOM : ANCHOR_TOP; + + // + // Arrow Color ... + color arrowColor = isLongSignal ? longSignalColor : shortSignalColor; + + // + // Draw Signal Arrow Shape ... + bool result = DrawArrow( + chartID, + arrowName, + subWindowID, + signal.time, + arrowPrice, + arrowCode, + arrowAnchorPoint, + arrowColor, + STYLE_SOLID, + 3, + false, + false, + false, + 0 + ); + // + // END Draw Signal Arrow ... + // + + // + // START Draw Signal SL/TP ... + // + string slLineName = StringConcatenate(signalTag, "_SL_", signal.id); + string tpLineName = StringConcatenate(signalTag, "_TP_", signal.id); + string entryLineName = StringConcatenate(signalTag, "_ENTRY_", signal.id); + + // + color slColor = shortSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color tpColor = longSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color entryColor = clrGreen; + + // + datetime time1 = iTime( + _Symbol, + _Period, + bar_index + 1 + ); + + // + // Draw Enrty Price ... + result = DrawTrendLine( + chartID, + entryLineName, + subWindowID, + time1, + signal.entryPrice, + signal.time, + signal.entryPrice, + entryColor, + STYLE_SOLID, + 2 + ); + + // + // Draw Signal SL ... + if (signal.sl > 0) { + // + result = DrawTrendLine( + chartID, + slLineName, + subWindowID, + time1, + signal.sl, + signal.time, + signal.sl, + slColor, + STYLE_SOLID, + 2 + ); + } + + // + // Draw Signal TP ... + if (signal.tp > 0) { + // + result = DrawTrendLine( + chartID, + tpLineName, + subWindowID, + time1, + signal.tp, + signal.time, + signal.tp, + tpColor, + STYLE_SOLID, + 2 + ); + } + // + // END Draw Signal SL/TP ... + // + + // + // Start Draw Signal Label ... + // + // + string labelName = StringConcatenate(signalTag, "_Label_", signal.id); + + // + double labelPrice = isLongSignal ? arrowPrice - (positionThresholdFactor * _Point) : arrowPrice + (positionThresholdFactor * _Point); + + // + string labelText = isLongSignal ? longSignalLabel : shortSignalLabel; + + // + result = DrawText( + chartID, + labelName, + subWindowID, + signal.time, + labelPrice, + labelText, + "Arial", + 10, + arrowColor, + 0, + ANCHOR_CENTER + ); + // + // End Draw Signal Label ... + // + + // + return result; +} + +// +// Trade on Specific Signal ... +bool TradeSignal( + XSignal &signal, + // + string prefix, + // + double volumePercent, + // + // Long ... + const string longSignalLabel, + const color longSignalColor, + // + // Short ... + const string shortSignalLabel, + const color shortSignalColor +) { + // + // Temp Result ... + bool result = false; + + // + if (initialBalance == 0) { + initialBalance = AccountInfoDouble(ACCOUNT_BALANCE); + } + + // + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + int openPositions = CountOpenTrades(); + double volume = (volumePercent * initialBalance); + + // + if ( + signal.type != X_LONG && + signal.type != X_SHORT + ) { + return result; + } + + // + bool hasLongSignal = signal.type == X_LONG; + + // + // Check TP and Entry Price ... + if ( + ( + hasLongSignal + && signal.entryPrice > signal.tp + ) || + ( + !hasLongSignal + && signal.entryPrice < signal.tp + ) + ) { + return result; + } + + // + // Order Operation ... + int operation = hasLongSignal ? + OP_BUY : + OP_SELL; + + // + // Detect Trade Color ... + color clr = hasLongSignal ? + longSignalColor : + shortSignalColor; + + // + // Generate Signal Comment ... + string label = hasLongSignal ? + longSignalLabel : + shortSignalLabel; + + // + // Generate Signal Comment ... + string comment = StringConcatenate( + prefix, + "_", signal.id, "_", + label + ); + + // + // Placing Order ... + int orderTicket = OrderSend( + _Symbol, + operation, + volume, + signal.entryPrice, + 3, + signal.sl, + signal.tp, + comment, + signal.id, + 0, + clr + ); + + // + // Draw Signal Shape if Order Opened Successfully ... + if (orderTicket >= 0) { + // + // Here i must to Draw Signal Shapes ... + DrawSignal( + signal, + 0, + 0, + 50, + prefix, // Signal Tag ... + longSignalLabel, // Long Signal Label ... + longSignalColor, + shortSignalLabel, // Short Signal Label ... + shortSignalColor + ); + + // + result = true; + } + + // + return result; +} +// +// END Signal Related Functions ... +// + +// +// START Orders Functions ... +// +// +// Convert To XSignal Model ... +XSignal OrderToSignal() { + // + // Temp Result ... + XSignal result = {}; + result.type = X_NONE; + + // + // Here we can get some usefull info based on selected order ... + double swap = OrderSwap(); + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + int magicNumber = OrderMagicNumber(); + double takeProfit = OrderTakeProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // Conver Position to Signal ... + result.sl = stopLoss; + result.tp = takeProfit; + result.time = openTime; + result.symbol = _Symbol; + result.id = magicNumber; + result.entryPrice = openPrice; + result.type = isLongOrder ? X_LONG : X_SHORT; + + // + return result; +} + +// +// START Count Orders ... +// +// +// Count Open Positions ... +int CountOpenTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if (OrderSymbol() == _Symbol) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Long Positions ... +int CountOpenLongTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_BUY + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Short Positions ... +int CountOpenShortTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_SELL + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} +// +// END Count Orders ... +// + +// +// START Close Orders ... +// +// +// Close All Open Trades ... +bool CloseAllTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + + // + return result; +} + +// +// Close All Open Long Trades ... +bool CloseAllLongTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Long Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Short Trades ... +bool CloseAllShortTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (!isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Short Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In Profit Trades ... +bool CloseAllInProfitTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if (profit > 0) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InProfit Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Long Time Trades ... +bool CloseAllLongTimeTrades( + const int passedCandles +) { + // + bool result = false; + + // + if (passedCandles <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + + // + if (openBarIndex - currentBarIndex >= passedCandles) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Long Time issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close all trades which passed Maximum Drawdown ... +bool CloseAllMaximumDrawDownPassedTrades( + const double maxDrDownPercentPerPTrade +) { + // + if ( + initialBalance <= 0 + || maxDrDownPercentPerPTrade <= 0 + ) { + return false; + } + + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double maxAllowedDrawDown = -1 * (initialBalance * maxDrDownPercentPerPTrade); + + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + if ( + profit < 0 + && MathAbs(profit) >= MathAbs(maxAllowedDrawDown) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Maximum DarwDown issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} +// +// END Close Orders ... +// +// +// END Orders Functions ... +// diff --git a/Bkp/Used/Parabolic SAR EA/parabolic.sar.ea.mq4 b/Bkp/Used/Parabolic SAR EA/parabolic.sar.ea.mq4 new file mode 100644 index 0000000..d83efa2 --- /dev/null +++ b/Bkp/Used/Parabolic SAR EA/parabolic.sar.ea.mq4 @@ -0,0 +1,117 @@ +void OnTick() +{ + + string signal = ""; + double Sar = iSAR(_Symbol, _Period, 0.02, 0.2, 0); + + if (Sar < Low[1] && Open[1] < Close[1]) + { + signal = "buy"; + } + + if (Sar > High[1] && Open[1] > Close[1]) + { + signal = "sell"; + } + + if (signal == "buy" && OrdersTotal() == 0) + + OrderSend(_Symbol, OP_BUY, 0.01, Ask, 3, 20, 100, NULL, 0, 0, Green); + + if (signal == "sell" && OrdersTotal() == 0) + + OrderSend(_Symbol, OP_SELL, 0.01, Bid, 3, 20, 100, NULL, 0, 0, Red); + + Comment("The Signal is :", signal); + + if (Open[1] > Close[1] && OrdersTotal() > 0) + + CloseBuyPosition(); + + if (Open[1] < Close[1] && OrdersTotal() > 0) + + CloseSellPosition(); +} + + +void OnTick() +{ + /* string signal = ""; + double Sar = iSAR( _Symbol, _Period, 0.02, 0.2, 0 ); + + if ( Sar < Low[1] && Open[1] < Close[1] ) signal = "buy"; + if ( Sar > High[1] && Open[1] > Close[1] ) signal = "sell"; + + if ( signal == "buy" && OrdersTotal() == 0 ) OrderSend( _Symbol, OP_BUY, 0.01, Ask, 3, 20, 100, NULL, 0, 0, Green ); + if ( signal == "sell" && OrdersTotal() == 0 ) OrderSend( _Symbol, OP_SELL, 0.01, Bid, 3, 20, 100, NULL, 0, 0, Red ); + + Comment( "The Signal is :", signal ); + + if ( Open[1] > Close[1] && OrdersTotal() > 0 ) CloseBuyPosition(); + if ( Open[1] < Close[1] && OrdersTotal() > 0 ) CloseSellPosition(); + */ + + static int count_of_NOPs = 0; + if ( OrdersTotal() == 0 ) + { if ( Open[1] < Close[1] + && Low[1] > iSAR( _Symbol, _Period, 0.02, 0.2, 0 ) + ) { + int rc = OrderSend( _Symbol, OP_BUY, 0.01, Ask, 3, 20, 100, NULL, 0, 0, Green ); + Print( StringFormat( "HAVING NO ORDERS ACTIVE... DID TRY OrderSend( OP_BUY ) -> RESULTING RetCode ( tkt# ) == %d [yield GetLastError() == %d]", + rc, + GetLastError() + ) + ); + count_of_NOPs = 0; //------------------------------ .RESET + return; //------------------------------------------^ J.I.T./RET + } + if ( Open[1] > Close[1] + && High[1] < iSAR( _Symbol, _Period, 0.02, 0.2, 0 ) + ) { + int rc = OrderSend( _Symbol, OP_SELL, 0.01, Bid, 3, 20, 100, NULL, 0, 0, Red ); + Print( StringFormat( "HAVING NO ORDERS ACTIVE... DID TRY OrderSend( OP_SELL ) -> RESULTING RetCode ( tkt# ) == %d [yield GetLastError() == %d]", + rc, + GetLastError() + ) + ); + if ( ) + count_of_NOPs = 0; //------------------------------ .RESET + return; //------------------------------------------^ J.I.T./RET + } + + /* OTHERWISE: */ + Print( StringFormat( "HAVING NO ORDERS ACTIVE... DID NOP... (for %d time)", + ++count_of_NOPs + ) + ); + // */ + } + else + { if ( Open[1] > Close[1] ) { Print( StringFormat( "HAVING %d ORDERS ACTIVE... WILL TRY CloseBuyPosition()...", + OrdersTotal() + ) + ); + CloseBuyPosition(); + count_of_NOPs = 0; //---------- .RESET + return; //----------------------^ J.I.T./RET + } + if ( Open[1] < Close[1] ) { Print( StringFormat( "HAVING %d ORDERS ACTIVE... WILL TRY CloseSellPosition()...", + OrdersTotal() + ) + ); + CloseSellPosition(); + count_of_NOPs = 0; //---------- .RESET + return; //----------------------^ J.I.T./RET + } + + /* OTHERWISE: */ + Print( StringFormat( "HAVING %d ORDERS ACTIVE... DID NOP... (for %d time)", + OrdersTotal(), + ++count_of_NOPs + ) + ); + // */ + } + + + \ No newline at end of file diff --git a/Bkp/Used/x-saherelm.xTEMP.signal.lib.mq4 b/Bkp/Used/x-saherelm.xTEMP.signal.lib.mq4 new file mode 100644 index 0000000..96cbb5b --- /dev/null +++ b/Bkp/Used/x-saherelm.xTEMP.signal.lib.mq4 @@ -0,0 +1,720 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 XTPW Signal Global Library +// --------------------------------------------------- +// XSaherElm EA Signal Provider based on +// XTPow Indicator... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Inputs ... +// +// +input string xTPWStarter = "- XTPW Signal Provider -"; // ---> XTPW Signal Provider <--- + +// +input bool enableXTPWSignalling = true; // XTPW Signalling Enable + +// +input double xTPWR2R = 2.5; // XTPW Risk To Reward Ratio +input int xTPWMaximumCandlesPerTrade = 206; // XTPW Maximum Candles which a Trade can open + +// +input double xTPWPSarStep = 0.02; // XTPW Parabolic Sar Step +input double xTPWPSarMaximum = 0.2; // XTPW Parabolic Sar Maximum + +// +input int xTPWSwingLength = 7; // XTPW Signal Swing Length +// +// END Inputs ... +// + +// +// START Global Requirement Functions ... +// +// +// XTPW Based Signal Conditions ... +struct XTPWSignalConditions { + datetime startTime; + datetime signalTime; + datetime entryTime; +}; + +// +struct XTPWMarketState { + double psar; + double fast; + double slow; + double verifier; +}; + +// +static XTPWSignalConditions xTPWLongConds; +static bool xTPWCloseLongTrades = false; +static bool xTPWWaitForLongSignals = true; + +// +static XTPWSignalConditions xTPWShortConds; +static bool xTPWCloseShortTrades = false; +static bool xTPWWaitForShortSignals = true; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckXTPWSignalHandler( + const int bar_index +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + + // + if (!enableXTPWSignalling) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XOHCL candle = GetCandleModel(bar_index); + XOHCL pCandle = GetCandleModel(bar_index + 1); +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXTPWLongSignalConditions( + const int bar_index +) { + // + if ( + !enableXTPWSignalling + || !xTPWWaitForLongSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + bool startCondition = false; + bool signalCondition = false; + + // + if ( + startCondition + && xTPWLongConds.startTime == 0 + ) { + // + xTPWLongConds.startTime = barTime; + return; + } + + // + if ( + signalCondition + && xTPWLongConds.startTime > 0 + && xTPWLongConds.signalTime == 0 + ) { + // + xTPWLongConds.signalTime = barTime; + xTPWLongConds.entryTime = barTime; + return; + } +} + +// +// Check and Fill Short Signal Conditions ... +void CheckXShortSignalConditions( + const int bar_index +) { + // + if ( + !enableXTPWSignalling + || !xTPWWaitForShortSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + bool startCondition = false; + bool signalCondition = false; + + // + if ( + startCondition + && xTPWShortConds.startTime == 0 + ) { + // + xTPWShortConds.startTime = barTime; + return; + } + + // + if ( + signalCondition + && xTPWShortConds.startTime > 0 + && xTPWShortConds.signalTime == 0 + ) { + // + xTPWShortConds.signalTime = barTime; + xTPWShortConds.entryTime = barTime; + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXTPWSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if (!enableXTPWSignalling) { + return result; + } + + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + if (requestLong) { + // + if ( + !ValidateXTPWLongConditions() + ) { + return result; + } + } else { + // + if ( + !ValidateXTPWShortConditions() + ) { + return result; + } + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double askPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double bidPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double entryPrice = requestLong ? + askPrice : + bidPrice; + + // + double exitPrice = requestLong ? + bidPrice : + askPrice; + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + // + GetMarketLowestLow( + bar_index, + xTPWSwingLength + ) + ; + + // + double hh = + // + GetMarketHighestHigh( + bar_index, + xTPWSwingLength + ) + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = requestLong ? + MathMin(openPrice, closePrice) - ll : + hh - MathMax(openPrice, closePrice); + + // + double reward = risk * xTPWR2R; + + // + double sl = requestLong ? + 0 : + 0; + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward + ; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XXX_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XXX_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXTPWLongConditions() { + // + if (!enableXTPWSignalling) { + return false; + } + + // + bool isConditionsFilled = + xTPWLongConds.startTime > 0 + && xTPWLongConds.signalTime > 0 + && xTPWLongConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xTPWLongConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xTPWLongConds.signalTime + ); + + // + int entryBarIndex = iBarShift( + _Symbol, + _Period, + xTPWLongConds.entryTime + ); + + // + isBLFilled = + // + xTPWLongConds.signalTime > xTPWLongConds.startTime + && xTPWLongConds.entryTime >= xTPWLongConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xTPWWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXTPWLongSignalConditions(); + } + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXTPWShortConditions() { + // + if (!enableXTPWSignalling) { + return false; + } + + // + bool isConditionsFilled = + xTPWShortConds.startTime > 0 + && xTPWShortConds.signalTime > 0 + && xTPWShortConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xTPWShortConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xTPWShortConds.signalTime + ); + + // + int entryBarIndex = iBarShift( + _Symbol, + _Period, + xTPWShortConds.entryTime + ); + + // + isBLFilled = + // + xTPWShortConds.signalTime > xTPWShortConds.startTime + && xTPWShortConds.entryTime >= xTPWShortConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xTPWWaitForShortSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXTPWShortSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXTPWLongSignalConditions() { + // + xTPWLongConds.startTime = 0; + xTPWLongConds.entryTime = 0; + xTPWLongConds.signalTime = 0; +} + +// +// Clear Short Signal Conditions for New One ... +void ClearXTPWShortSignalConditions() { + // + xTPWShortConds.startTime = 0; + xTPWShortConds.entryTime = 0; + xTPWShortConds.signalTime = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForXTPWSignals( + const XSignal &signal +) { + // + bool result = false; + + // + if (!enableXTPWSignalling) { + return result; + } + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // XOHCL candle = GetCandleModel(0); + XOHCL candle = GetCandleModel(signalBarIndex); + XOHCL pCandle = GetCandleModel(signalBarIndex + 1); + + // + // Retrive XMarket States ... + + // + double hh = GetMarketHighestHigh( + signalBarIndex, + xTPWSwingLength + ); + double ll = GetMarketLowestLow( + signalBarIndex, + xTPWSwingLength + ); + double diffChange = (hh - ll); + bool isBigSharpOccured = + diffChange > (600 * _Point) + ; + + // + bool isPSarVerified = false; + bool isTPowVerified = false; + bool isStateVerified = false; + bool isPriceVerified = false; + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + // Get Price Verification for Long ... + isPriceVerified = + // + // Starter ... + true + ; + + // + isTPowVerified = + // + // Starter ... + true + ; + + // + isPSarVerified = + // + // Starter ... + true + ; + + // + isStateVerified = + // + // Start ... + true + ; + + // + result = + // + // Starter ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + isPSarVerified = + // + // Starter ... + true + ; + + // + // Get Price Verification for Short ... + isPriceVerified = + // + // Starter ... + true + ; + + // + isTPowVerified = + // + // Starter ... + true + ; + + // + isStateVerified = + // + // Start ... + true + ; + + // + result = + // + // Starter Condition ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } + + // + return result; +} +// +// END Functions ... +// + +// +// START Data Provider ... +// +XTPWMarketState GetXMTPWarketState( + const int bar_index +) { + // + XTPWMarketState result = {}; + + // + double fast = GetMA( + bar_index, + xTPWSwingLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double slow = GetMA( + bar_index, + xTPWSwingLength * 2, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + int dailyCount = GetDailyCandleCount(); + double verifier = GetMA( + bar_index, + dailyCount, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double psar = iSAR( + _Symbol, + _Period, + xTPWPSarStep, + xTPWPSarMaximum, + bar_index + ); + + // + result.psar = psar; + result.fast = fast; + result.slow = slow; + result.verifier = verifier; + + // + return result; +} +// +// END Data Provider ... +// diff --git a/Bkp/XAUUSD-15M/Experts/x-saherelm.ea.mq4 b/Bkp/XAUUSD-15M/Experts/x-saherelm.ea.mq4 new file mode 100644 index 0000000..d8a63ca --- /dev/null +++ b/Bkp/XAUUSD-15M/Experts/x-saherelm.ea.mq4 @@ -0,0 +1,1038 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XST Strategy Expert Advisor +// --------------------------------------------- +// saherelm implementation of strategy expert advisor ... +// in this EA, we try to combine multiple tools, to ashive best +// results ... +// +// ShortName: XST +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +989121694056 +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XST Strategy Expert Advisor" +#property strict + +// +// START Inputs ... +// +// +// Signal Prefixe ... +input string signalPrefix = "XST_EA"; // Signal Prefix + +// +// Signal Draw Specifications ... +input string bullishSignalLabel = "X_BUY"; // Bullish Signal Label +input color bullishSignalColor = clrAqua; // Bullish Signal Color + +// +input string bearishSignalLabel = "X_SELL"; // Bearish Signal Label +input color bearishSignalColor = clrFuchsia; // Bearish Signal Color + +// +input color signalEntryColor = clrAquamarine; // Signal Entry Ptice Color +input color signalSLColor = clrRed; // Signal SL Color +input color signalTPColor = clrGreen; // Signal TP Color + +// +input int candleGapBetweenSignals = 7; // How many Candle waits to new Signal from last one + +// +// Trade ... +input bool allowTrade = true; // Allow Trade Based on given Signals +input bool allowLongTrades = true; // Allow Long Trades +input bool allowShortTrades = true; // Allow Short Trades + +// +// Alerts ... +input bool alertEvents = true; // Alert Events +input bool alertPositions = true; // Alert Positions +input bool longPositionAlerts = true; // Alert Long Positions +input bool shortPositionAlerts = true; // Alert Short Positions + +// +// Alert Types ... +input bool terminalAlert = false; // Terminal Alert +input bool pushAlert = false; // Push Notification Alerts + +// +// Balance and Finanical Specifications ... +input double lotsPerTradePercent = 0.00001; // Lots Per Trade Percent +input int maxOpenTrades = 4; // Maximum Open Trade +input double maxDrawdownPercentPerPTrade = 0.1; // Maximum DrawDown Per Trade +input double minBalancePercent = 0.5; // Minimum Balance for Trading +input double maxEquityPercent = 0.1; // Maximum Trade Equity + +// +// START Global Definitions: Variables, Properties and etc ... +// +int lastSignalledBar = 0; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.signal.lib.mq4" + +// +int maxMarketLength = 0; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Validate Inputs ... + bool inputsNotValiid = + // + // EA ... + maxOpenTrades <= 0 + || maxEquityPercent < 0 + || minBalancePercent < 0 + || lotsPerTradePercent < 0 + || maxDrawdownPercentPerPTrade < 0 + ; + + // + if (inputsNotValiid) { + return INIT_PARAMETERS_INCORRECT; + } + + // + totalSignals = 0; + totalLongSignals = 0; + totalShortSignals = 0; + + // + initialBalance = 0; + + // + // START Define Array Series ... + // + // + // END Define Array Series ... + // + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST"; + + // + ClearSignalConditions(); + + // + maxMarketLength = MathMax(0, GetDailyCandleCount()); + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { +} + +// +// Ticker Event Handler ... +void OnTick() { + // + isNewDay = IsNewDay(); + if (isNewDay) { + // + LogMessage( + StringConcatenate( + "New Day ..." + ) + ); + } + + // + // Process Signals to Open Positions ... + ProcessSignals(); + + // + // Checking State for Signal Handling ... + CheckState(); + + // + // Process Open Positions for Trailing Stop Loss or Close ... + ProcessOpenPositions(); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Check State for Signal Handling ... +void CheckState() { + // + // Here we Must to Check Market State for enable or disable + // Signal Handlers and also make dection to close all long/short + // trades ... +} + +// +// Calculate Signals and Process Based on Exists Signals ... +void ProcessSignals() { + // + XSignalRequest request = {}; + request.type = X_SIGNAL_NONE; + request.hasSignal = false; + + // + // Prevent Multiple Calculating on Same Bars ... + isNewBar = IsNewBar(); + if (isNewBar) { + countedBars++; + } + + // + if (countedBars < maxMarketLength) { + return; + } + + // + bool allowDoTrade = true; + + // + // Check Balance ... + if (initialBalance > 0) { + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double minimumBalanceForTrade = + balance > initialBalance + ? + minBalancePercent * balance + : + minBalancePercent * initialBalance; + + // + // Retrieve Account Equity ... + double equity = AccountInfoDouble(ACCOUNT_EQUITY); + double maxAllowedEquity = balance - (balance * maxEquityPercent); + + // + // Retrieve Free Marigin ... + double freeMargin = AccountFreeMargin(); + double maximumMariginRisk = balance - (balance * maxEquityPercent); + + // + if ( + // + // Do not Open Positions if equity not passed ... + equity < maxAllowedEquity || + // + // Do not Open Positions if free margin not passed ... + freeMargin <= maximumMariginRisk || + // + // Do not open positions if balance less than minimum ... + balance <= minimumBalanceForTrade + ) { + // + static bool tradingPauseAlerted; + + // + allowDoTrade = false; + + // + if (!tradingPauseAlerted) { + // + string message = StringConcatenate( + "Trading Pause => ", + "Balance: ", balance, + ", Equity: ", equity, + ", FreeMargin: ", freeMargin + ); + + // + LogMessage(message); + SendAlert(message); + + // + tradingPauseAlerted = true; + } + } + } + + // + // Retrieve Signal Exists ... + request = GenerateSignal(0); + + // + // Prevent doing anything else, if there is no signals ... + if ( + !allowDoTrade || + !request.hasSignal || + request.type == X_SIGNAL_NONE + ) { + return; + } + + // + bool hasLongSignal = request.type == X_SIGNAL_LONG; + + // + // Check last Signalled Bar with Counted Bars ... + // Prevent Multiple Signalling on Same Bar ... + bool isInLastSignalledBars = false; + for (int i=0; i < candleGapBetweenSignals; i++) { + // + isInLastSignalledBars = + isInLastSignalledBars + || lastSignalledBar == countedBars - i + ; + } + if (isInLastSignalledBars) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + return; + } + + // + // increase last signalled bar ... + lastSignalledBar = countedBars; + + // + // Calculate Can Trade or not ... + allowDoTrade = allowTrade + && ( + hasLongSignal ? + allowLongTrades : + allowShortTrades + ); + + // + // Chack Maximum Open Positions ... + int openTrades = CountOpenTrades(); + if (maxOpenTrades > 0) { + // + if (openTrades >= maxOpenTrades) { + // + allowDoTrade = false; + + // + if (!allowDoTrade) { + // + string message = StringConcatenate( + "Trading Pause => ", + "Max Open Trades (", + maxOpenTrades, + ") reached ..." + ); + + // + LogMessage(message); + SendAlert(message); + } + } + } + + // + // Check Trading is Enable or not ... + // nothing to do if trading is disabled ... + if (!allowDoTrade) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + string message = StringConcatenate( + "Trading Not Allowed ..." + ); + + // + LogMessage(message); + SendAlert(message); + return; + } + + // + // Retrieve Signal Lots Per Trade ... + double lPTradePercent = GetSignalLottage( + request.signal, + lotsPerTradePercent + ); + + // + bool isPositionOpened = TradeSignal( + request.signal, + lPTradePercent, + // + bullishSignalLabel, + bullishSignalColor, + bearishSignalLabel, + bearishSignalColor + ); + + // + totalSignals++; + if (hasLongSignal) { + // + totalLongSignals++; + ClearLongSignalConditions(); + } else { + // + totalShortSignals++; + ClearShortSignalConditions(); + } + + // + if (isPositionOpened) { + // + bool canAlert = + alertPositions + && ( + hasLongSignal ? + longPositionAlerts + : + shortPositionAlerts + ); + + // + if (canAlert) { + // + // Alert Message ... + string message = StringConcatenate( + "Trade on Signal ID: ", request.signal.id, + ", ProvidedBy: ", GetSignalProviderIdentifier(request.signal.provider), + ", Entry: ", request.signal.entry, + ", TP: ", request.signal.tp + ); + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } + } + } +} + +// +// Process All Open Positions ... +void ProcessOpenPositions() { + // + // XSignalling ... + if (enableXSignalling) { + // + // Close All XXX Provided Signals on it's Specific Condition ... + if (xCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XXX_PROVIDER); + + // + xCloseLongTrades = false; + } + + // + if (xCloseShortTrades) { + // + CloseAllProviderShortTrades(X_XTPW_PROVIDER); + + // + xCloseShortTrades = false; + } + + // + // Close Maximum DrawDown Passed Trades ... + + // + // Longs ... + bool hasClosedLongInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xLongMaxDrawdownPerTradePercent, + X_SIGNAL_LONG, + X_XXX_PROVIDER + ); + + // + // Shorts ... + bool hasClosedShortInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xShortMaxDrawdownPerTradePercent, + X_SIGNAL_SHORT, + X_XXX_PROVIDER + ); + + // + // Close All Long Time Trades based on Provider provided Length ... + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + xMaximumCandlesPerTrade, + X_XXX_PROVIDER + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedLongInDrawDownLongTrade + || hasClosedShortInDrawDownLongTrade + ) { + xFailedSignals++; + } + } + + // + // XR Signalling ... + if (enableXRSignalling) { + // + if (xRCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XR_PROVIDER); + + // + xRCloseLongTrades = false; + } + + // + if (xRCloseShortTrades) { + // + CloseAllProviderShortTrades(X_XR_PROVIDER); + + // + xRCloseShortTrades = false; + } + + // + // Close Maximum DrawDown Passed Trades ... + + // + // Longs ... + bool hasClosedLongInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xRLongMaxDrawdownPerTradePercent, + X_SIGNAL_LONG, + X_XR_PROVIDER + ); + + // + // Shorts ... + bool hasClosedShortInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xRShortMaxDrawdownPerTradePercent, + X_SIGNAL_SHORT, + X_XR_PROVIDER + ); + + // + // Close All Long Time Trades based on Provider provided Length ... + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + xRMaximumCandlesPerTrade, + X_XR_PROVIDER + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedLongInDrawDownLongTrade + || hasClosedShortInDrawDownLongTrade + ) { + xRFailedSignals++; + } + } + + // + // XTPW Signalling ... + if (enableXTPWSignalling) { + // + if (xTPWCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XTPW_PROVIDER); + + // + xTPWCloseLongTrades = false; + } + + // + if (xTPWCloseShortTrades) { + // + CloseAllProviderShortTrades(X_XTPW_PROVIDER); + + // + xTPWCloseShortTrades = false; + } + + // + // Close Maximum DrawDown Passed Trades ... + + // + // Longs ... + bool hasClosedLongInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xTPWLongMaxDrawdownPerTradePercent, + X_SIGNAL_LONG, + X_XTPW_PROVIDER + ); + + // + // Shorts ... + bool hasClosedShortInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xTPWShortMaxDrawdownPerTradePercent, + X_SIGNAL_SHORT, + X_XTPW_PROVIDER + ); + + // + // Close All Long Time Trades based on Provider provided Length ... + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + xTPWMaximumCandlesPerTrade, + X_XTPW_PROVIDER + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedLongInDrawDownLongTrade + || hasClosedShortInDrawDownLongTrade + ) { + xTPWFailedSignals++; + } + } + + // + // Close Maximum DrawDown Passed Trades ... + // this is the Maximum Controller ... + // + double maxOfXPercent = enableXSignalling ? + MathMax( + xLongMaxDrawdownPerTradePercent, + xShortMaxDrawdownPerTradePercent + ) : 0 + ; + + // + double maxOfXRPercent = enableXRSignalling ? + MathMax( + xRLongMaxDrawdownPerTradePercent, + xRShortMaxDrawdownPerTradePercent + ) : 0 + ; + + // + double maxOfXTPWPercent = enableXTPWSignalling ? + MathMax( + xTPWLongMaxDrawdownPerTradePercent, + xTPWShortMaxDrawdownPerTradePercent + ) : 0 + ; + + // + double maxDrawDownPercent = MathMax( + maxOfXPercent, + maxOfXRPercent + ); + maxDrawDownPercent = MathMax( + maxDrawDownPercent, + maxOfXTPWPercent + ); + maxDrawDownPercent = MathMax( + maxDrawDownPercent, + maxDrawdownPercentPerPTrade + ); + + // + // we Calculate Max DrawDown Percent Per Trade ... + // then try to Close based on them ... + bool hasClosedInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + maxDrawDownPercent + ); +} + +// +// Send Special Type of Alerts ... +void SendAlert(string message) { + // + if (!alertEvents) { + return; + } + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } +} +// +// END Functions ... +// + +// +// +// Calculate Signal ... +// in this function we calculate a signal exists in +// specific bar or not ... +XSignalRequest GenerateSignal( + const int bar_index // Bar Index ... +) { + // + // create temp result ... + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + bool hasSignal = false; + bool hasLongSignal = false; + bool hasShortSignal = false; + + // + XSignal signal = {}; + + // + // Define Template Signal Requests for Managing Multiple Signals ... + // + // X ... + XSignalRequest xLongSignalRequest = {}; + XSignalRequest xShortSignalRequest = {}; + // + // XR ... + XSignalRequest xrLongSignalRequest = {}; + XSignalRequest xrShortSignalRequest = {}; + // + // XTPW ... + XSignalRequest xTPWLongSignalRequest = {}; + XSignalRequest xTPWShortSignalRequest = {}; + + // + // START XR Signal Handler ... + // + // + if (enableXRSignalling) { + // + CheckXRSignalHandler( + bar_index + ); + + // + // Long Trades ... + if (allowTrade && allowLongTrades) { + // + if (xRWaitForLongSignals) { + // + CheckXRLongSignalConditions( + bar_index + ); + + // + xrLongSignalRequest = GenerateXRSignal( + X_SIGNAL_LONG, + signalPrefix, + bar_index + ); + + // + if (xrLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXRSignals( + xrLongSignalRequest.signal + ); + + // + if (isReady && xRWaitForLongSignals) { + // + hasLongSignal = true; + signal = xrLongSignalRequest.signal; + } else { + ClearXRLongSignalConditions(); + } + } + } else { + ClearXRLongSignalConditions(); + } + } + + // + // Short Trades ... + if (allowTrade && allowShortTrades) { + // + if (xRWaitForShortSignals) { + // + CheckXRShortSignalConditions( + bar_index + ); + + // + xrShortSignalRequest = GenerateXRSignal( + X_SIGNAL_SHORT, + signalPrefix, + bar_index + ); + + // + if (xrShortSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXRSignals( + xrShortSignalRequest.signal + ); + + // + if (isReady && xRWaitForShortSignals) { + // + hasShortSignal = true; + signal = xrShortSignalRequest.signal; + } else { + ClearXRShortSignalConditions(); + } + } + } else { + ClearXRShortSignalConditions(); + } + } + } + // + // END XR Signal Handler ... + // + + // + // START XTPW Signal Handler ... + // + if (enableXTPWSignalling) { + // + CheckXTPWSignalHandler( + bar_index + ); + + // + // Long Trades ... + if (allowTrade && allowLongTrades) { + // + if (xTPWWaitForLongSignals) { + // + CheckXTPWLongSignalConditions( + bar_index + ); + + // + xTPWLongSignalRequest = GenerateXTPWSignal( + X_SIGNAL_LONG, + signalPrefix, + bar_index + ); + + // + if (xTPWLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXTPWSignals( + xTPWLongSignalRequest.signal + ); + + // + if (isReady && xTPWWaitForLongSignals) { + // + hasLongSignal = true; + signal = xTPWLongSignalRequest.signal; + } else { + ClearXTPWLongSignalConditions(); + } + } + } else { + ClearXTPWLongSignalConditions(); + } + } + + // + // Short Trades ... + if (allowTrade && allowShortTrades) { + // + if (xTPWWaitForShortSignals) { + // + CheckXTPWShortSignalConditions( + bar_index + ); + + // + xTPWShortSignalRequest = GenerateXTPWSignal( + X_SIGNAL_SHORT, + signalPrefix, + bar_index + ); + + // + if (xTPWShortSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXTPWSignals( + xTPWShortSignalRequest.signal + ); + + // + if (isReady && xTPWWaitForShortSignals) { + // + hasShortSignal = true; + signal = xTPWShortSignalRequest.signal; + } else { + ClearXTPWShortSignalConditions(); + } + } + } else { + ClearXTPWShortSignalConditions(); + } + } + } + // + // END XTPW Signal Handler ... + // + + // + // START X Signal Handler ... + // + // + if (enableXSignalling) { + // + CheckXSignalHandler( + bar_index + ); + + // + // Long Trades ... + if (allowTrade && allowLongTrades) { + // + if (xWaitForLongSignals) { + // + CheckXLongSignalConditions( + bar_index + ); + + // + xLongSignalRequest = GenerateXSignal( + X_SIGNAL_LONG, + signalPrefix, + bar_index + ); + + // + if (xLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXSignals( + xLongSignalRequest.signal + ); + + // + if (isReady && xWaitForLongSignals) { + // + hasLongSignal = true; + signal = xLongSignalRequest.signal; + } else { + ClearXLongSignalConditions(); + } + } + } else { + ClearXLongSignalConditions(); + } + } + + // + // Short Trades ... + if (allowTrade && allowShortTrades) { + // + if (xWaitForShortSignals) { + // + CheckXShortSignalConditions( + bar_index + ); + + // + xShortSignalRequest = GenerateXSignal( + X_SIGNAL_SHORT, + signalPrefix, + bar_index + ); + + // + if (xShortSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXSignals( + xShortSignalRequest.signal + ); + + // + if (isReady && xWaitForShortSignals) { + // + hasShortSignal = true; + signal = xShortSignalRequest.signal; + } else { + ClearXShortSignalConditions(); + } + } + } else { + ClearXShortSignalConditions(); + } + } + } + // + // END XR Signal Handler ... + // + + // + hasSignal = hasLongSignal || hasShortSignal; + + // + if (!hasSignal) { + // + signal.type = X_SIGNAL_NONE; + result.type = X_SIGNAL_NONE; + } + + // + // Normalize TP, SL and Entry Price ... + signal.tp = NormalizeDouble(signal.tp, _Digits); + signal.sl = NormalizeDouble(signal.sl, _Digits); + signal.entry = NormalizeDouble(signal.entry, _Digits); + + // + result.signal = signal; + result.type = signal.type; + result.hasSignal = hasSignal; + result.provider = signal.provider; + + // + // Return Result ... + return result; +} diff --git a/Bkp/XAUUSD-15M/Indicators/x-saherelm.ma.mq4 b/Bkp/XAUUSD-15M/Indicators/x-saherelm.ma.mq4 new file mode 100644 index 0000000..e3a5737 --- /dev/null +++ b/Bkp/XAUUSD-15M/Indicators/x-saherelm.ma.mq4 @@ -0,0 +1,173 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MA Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 MA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Fast MA ... +input int maLength = 20; // MA Length +input int maShift = 0; // MA Shift +input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method +input ENUM_APPLIED_PRICE maAppliedPrice = PRICE_CLOSE; // MA Applied Price + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 1 + +// +#property indicator_plots 1 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Fast Ma Buffer ... +#property indicator_label1 "Ma" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrYellow +#property indicator_style1 STYLE_DOT +#property indicator_width1 2 + +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define maBufferIndex 0 + +double maBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (maLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + // + // Ma ... + SetIndexBuffer(maBufferIndex, maBuffer); + SetIndexDrawBegin(maBufferIndex, maLength + 1); + // + // End Set Index Buffers ... + // + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, maLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Ma ... + CalculateMa(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateMa( + const int &bar_index +) { + // + // Calculating Fast Ma ... + double ma = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + maAppliedPrice, + bar_index + ); + + // + maBuffer[bar_index] = ma; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/XAUUSD-15M/Indicators/x-saherelm.xrange.mq4 b/Bkp/XAUUSD-15M/Indicators/x-saherelm.xrange.mq4 new file mode 100644 index 0000000..1359f57 --- /dev/null +++ b/Bkp/XAUUSD-15M/Indicators/x-saherelm.xrange.mq4 @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XRange Indicator +// --------------------------------------------- +// saherelm implementation of above 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 XRange Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 14; +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 3 + +// +#property indicator_plots 3 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Highest High Buffer ... +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +// Lowest Low Buffer ... +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +// Middle Buffer ... +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_DASH +#property indicator_width3 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +// +#define highestHighBufferIndex 0 +#define lowestLowBufferIndex 1 +#define middleBufferIndex 2 + +// +double highestHighBuffer[]; +double lowestLowBuffer[]; +double middleBuffer[]; + +// +datetime startTime; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if ( + marketLength <= 0 + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + string hhLbl = StringConcatenate( + "XR HH(", marketLength, ")" + ); + SetIndexBuffer(highestHighBufferIndex, highestHighBuffer); + SetIndexLabel(highestHighBufferIndex, hhLbl); + + // + string llLbl = StringConcatenate( + "XR LL(", marketLength, ")" + ); + SetIndexBuffer(lowestLowBufferIndex, lowestLowBuffer); + SetIndexLabel(lowestLowBufferIndex, llLbl); + + // + string midLbl = StringConcatenate( + "XR Mid(", marketLength, ")" + ); + SetIndexBuffer(middleBufferIndex, middleBuffer); + SetIndexLabel(middleBufferIndex, midLbl); + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculations ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculations ... +void CalculateBuffers( + const int &bar_index +) { + // + // Retrieve Bar Time ... + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + if (startTime == 0) { + // + startTime = barTime; + SetIndicatorBuffersNone(bar_index); + return; + } + + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + startTime + ); + + // + int startDistance = startBarIndex - bar_index; + if (startDistance < marketLength) { + // + SetIndicatorBuffersNone(bar_index); + return; + } + + // + // Highest High ... + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLength, + bar_index + ); + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + highestHighBuffer[bar_index] = hh; + + // + // Lowest Low ... + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLength, + bar_index + ); + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + lowestLowBuffer[bar_index] = ll; + + // + // Middle Buffer ... + double mid = (hh + ll) / 2; + middleBuffer[bar_index] = mid; + + // + // Reset Start Time ... + startTime = 0; +} + +// +void SetIndicatorBuffersNone( + const int bar_index +) { + // + int lastBarIndex = bar_index + 1; + + // + double lastHighestHigh; + double lastLowestLow; + + // + // Highest High ... + if (ArraySize(highestHighBuffer) > lastBarIndex) { + lastHighestHigh = highestHighBuffer[lastBarIndex]; + } else { + lastHighestHigh = 0; + } + + // + // Lowest Low ... + if (ArraySize(lowestLowBuffer) > lastBarIndex) { + lastLowestLow = lowestLowBuffer[lastBarIndex]; + } else { + lastLowestLow = 0; + } + + // + highestHighBuffer[bar_index] = lastHighestHigh; + lowestLowBuffer[bar_index] = lastLowestLow; + + // + double mid = (lastHighestHigh + lastLowestLow) / 2; + middleBuffer[bar_index] = mid; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/XAUUSD-15M/Indicators/x-saherelm.xtpow.mq4 b/Bkp/XAUUSD-15M/Indicators/x-saherelm.xtpow.mq4 new file mode 100644 index 0000000..46ff59e --- /dev/null +++ b/Bkp/XAUUSD-15M/Indicators/x-saherelm.xtpow.mq4 @@ -0,0 +1,275 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center Trend Power Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 MA Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 7; // Market Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_separate_window + +// +#property indicator_plots 3 +#property indicator_buffers 3 +#property indicator_minimum 0 +#property indicator_maximum 100 + +// +#property indicator_levelcolor clrGray +#property indicator_levelstyle STYLE_DOT + +// +// Start Define Indicator Buffer Styles ... +// +#property indicator_type1 DRAW_HISTOGRAM +#property indicator_color1 clrLime +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +#property indicator_type2 DRAW_HISTOGRAM +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define powerUpBufferIndex 0 +#define powerDownBufferIndex 1 +#define signalBufferIndex 2 + +double powerUpBuffer[]; +double powerDownBuffer[]; +double signalBuffer[]; + +// +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (marketLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + SetLevelValue(0, 0.0); + IndicatorSetString(INDICATOR_LEVELTEXT,0,""); + + // + SetLevelValue(1, 20.0); + IndicatorSetString(INDICATOR_LEVELTEXT,1,""); + + // + SetLevelValue(2, 50); + IndicatorSetString(INDICATOR_LEVELTEXT,2,""); + + // + SetLevelValue(3, 100); + IndicatorSetString(INDICATOR_LEVELTEXT,3,""); + + // + string pUpLbl = StringConcatenate( + "P Up (", marketLength, ")" + ); + SetIndexLabel(powerUpBufferIndex, pUpLbl); + SetIndexBuffer(powerUpBufferIndex, powerUpBuffer); + SetIndexDrawBegin(powerUpBufferIndex, marketLength + 1); + + // + string pDownLbl = StringConcatenate( + "P Down (", marketLength, ")" + ); + SetIndexLabel(powerDownBufferIndex, pDownLbl); + SetIndexBuffer(powerDownBufferIndex, powerDownBuffer); + SetIndexDrawBegin(powerDownBufferIndex, marketLength + 1); + + // + string pSignalLbl = StringConcatenate( + "P Signal (", marketLength, ")" + ); + SetIndexLabel(signalBufferIndex, pSignalLbl); + SetIndexBuffer(signalBufferIndex, signalBuffer); + SetIndexDrawBegin(signalBufferIndex, marketLength + 1); + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "X_TPW_OSC"; + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Buffers ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateBuffers( + const int &bar_index +) { + // + double powerUp = 0; + double powerDown = 0; + + // + int dailyCount = GetDailyCandleCount(); + double dailyHH = GetMarketHighestHigh( + bar_index, + dailyCount + ); + double dailyLL = GetMarketLowestLow( + bar_index, + dailyCount + ); + double dailyDiff = dailyHH - dailyLL; + double rate = dailyDiff / 100; + + // + for (int i = bar_index; i < bar_index + marketLength; i++) { + // + XOHCL c = GetCandleModel(i); + + // + double cRange = + MathAbs(c.open - c.close) + // MathAbs(c.high - c.low) + ; + bool isBullish = c.open < c.close; + + // + if (isBullish) { + powerUp += cRange; + } else { + powerDown += cRange; + } + } + + // + powerUp = powerUp / rate; + powerDown = powerDown / rate; + + // + int doubleMarketLength = (marketLength * 2); + double ema = GetMA( + bar_index, + doubleMarketLength, + 0, + MODE_EMA, + PRICE_WEIGHTED + ); + + // + double emaRate = GetMarketHighestHigh(bar_index, doubleMarketLength) - GetMarketLowestLow(bar_index, doubleMarketLength) / 100; + + // + double signal = (ema / 100) * rate; + double signalAddition = MathMin(powerUp, powerDown); + + // + powerUpBuffer[bar_index] = powerUp; + powerDownBuffer[bar_index] = powerDown; + signalBuffer[bar_index] = signal + signalAddition; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/XAUUSD-15M/Libraries/x-saherelm.draw.lib.mq4 b/Bkp/XAUUSD-15M/Libraries/x-saherelm.draw.lib.mq4 new file mode 100644 index 0000000..776cde4 --- /dev/null +++ b/Bkp/XAUUSD-15M/Libraries/x-saherelm.draw.lib.mq4 @@ -0,0 +1,2010 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Draw Highest High ... +bool DrawHighestHigh( + const int bar_index, + const int marketLen, + const string tag, + const int drawUntilBarIndex = 0, + const long chartID = 0, + const int subWindow = 0, + const color clr = clrAqua, + const ENUM_LINE_STYLE style = STYLE_DOT, + const int width = 1, + const bool back = false, + const bool selection = false, + const bool hidden = false, + const long zOrder = 0 +) { + // + bool result = false; + + // + // Calculate Highest High ... + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + datetime hhTime = iTime( + _Symbol, + _Period, + hhIdx + ); + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + datetime drawUntilTime = + drawUntilBarIndex != bar_index ? + iTime( + _Symbol, + _Period, + drawUntilBarIndex + ) : + barTime + ; + + // + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + int rnd = rand(); + + // + // Define Label ... + string lbl = StringConcatenate( + tag, + "_HH(", marketLen ,")_", + hh, + "_", rnd + ); + + // + result = ObjectDelete( + chartID, + lbl + ); + + // + // Draw a Trend Line ... + result = DrawTrendLine( + chartID, + lbl, + subWindow, + hhTime, + hh, + drawUntilTime, + hh, + clr, + style, + width, + back, + selection, + hidden, + zOrder + ); + + // + return result; +} + +// +// Draw Lowest Low ... +bool DrawLowestLow( + const int bar_index, + const int marketLen, + const string tag, + const int drawUntilBarIndex = 0, + const long chartID = 0, + const int subWindow = 0, + const color clr = clrFuchsia, + const ENUM_LINE_STYLE style = STYLE_DOT, + const int width = 1, + const bool back = false, + const bool selection = false, + const bool hidden = false, + const long zOrder = 0 +) { + // + bool result = false; + + // + // Calculate Highest High ... + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + datetime llTime = iTime( + _Symbol, + _Period, + llIdx + ); + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + datetime drawUntilTime = + drawUntilBarIndex != bar_index ? + iTime( + _Symbol, + _Period, + drawUntilBarIndex + ) : + barTime + ; + + // + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + int rnd = rand(); + + // + // Define Label ... + string lbl = StringConcatenate( + tag, + "_LL(", marketLen ,")_", + ll, + "_", rnd + ); + + // + result = ObjectDelete( + chartID, + lbl + ); + + // + // Draw a Trend Line ... + result = DrawTrendLine( + chartID, + lbl, + subWindow, + llTime, + ll, + drawUntilTime, + ll, + clr, + style, + width, + back, + selection, + hidden, + zOrder + ); + + // + return result; +} + +// +// Draw Market Middle ... +bool DrawMarketMiddle( + const int bar_index, + const int marketLen, + const string tag, + const int drawUntilBarIndex = 0, + const long chartID = 0, + const int subWindow = 0, + const color clr = clrYellow, + const ENUM_LINE_STYLE style = STYLE_DOT, + const int width = 1, + const bool back = false, + const bool selection = false, + const bool hidden = false, + const long zOrder = 0 +) { + // + bool result = false; + + // + // Calculate Highest High ... + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + datetime llTime = iTime( + _Symbol, + _Period, + llIdx + ); + + // + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + // Calculate Highest High ... + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + datetime hhTime = iTime( + _Symbol, + _Period, + hhIdx + ); + + // + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + double middle = ll + ((hh - ll) / 2); + datetime middleTime = hhIdx < llIdx + ? hhTime + : llTime + ; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + datetime drawUntilTime = + drawUntilBarIndex != bar_index ? + iTime( + _Symbol, + _Period, + drawUntilBarIndex + ) : + barTime + ; + + // + int rnd = rand(); + + // + // Define Label ... + string lbl = StringConcatenate( + tag, + "_MID(", marketLen ,")_", + middle, + "_", rnd + ); + + // + result = ObjectDelete( + chartID, + lbl + ); + + // + // Draw a Trend Line ... + result = DrawTrendLine( + chartID, + lbl, + subWindow, + middleTime, + middle, + drawUntilTime, + middle, + clr, + style, + width, + back, + selection, + hidden, + zOrder + ); + + // + return result; +} + +// +// Start Arrow Functions ... +// +// +// Draw an Arrow Object on Chart ... +bool DrawArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // arrow name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const uchar arrowCode = OBJ_ARROW_UP, // arrow code + const ENUM_ARROW_ANCHOR anchor = ANCHOR_BOTTOM, // anchor point position + const color clr = clrAqua, // arrow color + const ENUM_LINE_STYLE style = STYLE_SOLID, // border line style + const int width = 3, // arrow size + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // Order Object ... +) { + // + // set anchor point coordinates if they are not set ... + ChangeArrowEmptyPoint(time, price); + + // + // reset the error value ... + ResetLastError(); + + // + // create an arrow ... + if(!ObjectCreate(chartID, name, OBJ_ARROW, subWindow, time, price)) { + // + string message = StringConcatenate(__FUNCTION__, + ": failed to create an arrow! Error code = ", + GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the arrow code ... + ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, arrowCode); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set the arrow color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set the border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set the arrow's size ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the arrow by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is false by default, if you want making it possible to highlight and move the object + // change it to true ... + ObjectSetInteger(chartID,name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point of Arrow ... +bool MoveArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if(!time) { + time = TimeCurrent(); + } + + // + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete an arrow ... +bool DeleteArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow" // arrow name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete an arrow ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete an arrow! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the arrow code ... +bool ArrowCodeChange( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + const uchar code = 252 // arrow code +) { + // + // reset the error value ... + ResetLastError(); + + // + // change the arrow code ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, code)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the arrow code! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change anchor type ... +bool ArrowAnchorChange( + const long chartID = 0, // chart's ID + const string name="Arrow", // object name + const ENUM_ARROW_ANCHOR anchor = ANCHOR_TOP // anchor type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change anchor type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change anchor type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeArrowEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } +} +// +// End Arrow Functions ... +// + +// +// Start Horizontal Line Functions ... +// +// +// Create, Draw the horizontal line ... +bool DrawHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + const int subWindow = 0, // subwindow index + double price = 0, // line price + const color clr = clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the price is not set, set it at the current Bid price level ... + if(!price) { + price=SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // create a horizontal line ... + if(!ObjectCreate(chartID, name, OBJ_HLINE, subWindow, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move horizontal line ... +bool MoveHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + double price = 0 // line price +) { + // + // if the line price is not set, move it to the current Bid price level ... + if(!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move a horizontal line ... + if(!ObjectMove(chartID, name, 0, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete a horizontal line ... +bool DeleteHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a horizontal line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End Horizontal Line Functions ... +// + +// +// Start Vertical Line Functions ... +// +// +// Create the vertical line ... +bool DrawVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + const int sub_window = 0, // subwindow index + datetime time = 0, // line time + const color clr=clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the line time is not set, draw it via the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value + ResetLastError(); + + // + // create a vertical line ... + if (!ObjectCreate(chartID, name, OBJ_VLINE, sub_window, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return true; +} + +// +// Move the vertical line ... +bool MoveVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + datetime time = 0 // line time +) { + // + // if line time is not set, move the line to the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the vertical line ... + if(!ObjectMove(chartID, name, 0, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the vertical line ... +bool DeleteVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the vertical line ... + if (!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // successful execution ... + return true; +} +// +// End Vertical Line Functions ... +// + +// +// Start RectangleLabel Functions ... +// +// +// Create Rectangle Label Object ... +bool DrawRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int subWindow = 0, // subwindow index + const int x = 0, // X coordinate + const int y = 0, // Y coordinate + const int width = 50, // width + const int height = 18, // height + const color back_clr = C'236,233,216', // background color + const ENUM_BORDER_TYPE border = BORDER_SUNKEN, // border type + const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring + const color clr = clrRed, // flat border color (Flat) + const ENUM_LINE_STYLE style = STYLE_SOLID, // flat border style + const int lineWidth = 1, // flat border width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // reset the error value ... + ResetLastError(); + + // + //--- create a rectangle label + if(!ObjectCreate(chartID, name, OBJ_RECTANGLE_LABEL, subWindow, 0, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set label coordinates ... + ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x); + ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y); + + // + // set label size ... + ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width); + ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height); + + // + // set background color ... + ObjectSetInteger(chartID, name, OBJPROP_BGCOLOR, back_clr); + + // + // set border type ... + ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border); + + // + // set the chart's corner, relative to which point coordinates are defined ... + ObjectSetInteger(chartID, name, OBJPROP_CORNER, corner); + + // + // set flat border color (in Flat mode) ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set flat border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set flat border width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, lineWidth); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the label by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move Rectangle Label .. +bool MoveRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int x = 0, // X coordinate + const int y=0 // Y coordinate +) { + // + // reset the error value ... + ResetLastError(); + + // + // move the rectangle label ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move X coordinate of the label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move Y coordinate of the label! Error code = ",GetLastError() + ); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the rectangle label ... +bool DeleteRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel" // label name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the label ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change Rectangle Label Size ... +bool ChangeSizeRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int width = 50, // label width + const int height = 18 // label height +) { + // + // reset the error value ... + ResetLastError(); + + // + // change label size ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's width! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's height! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change rectangle label border type ... +bool RectLabelChangeBorderType( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const ENUM_BORDER_TYPE border = BORDER_SUNKEN // border type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change border type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the border type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End RectangleLabel Functions ... +// + +// +// Start TrendLine Funcions ... +// +// Create a trend line by the given coordinates ... +bool DrawTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrYellow, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool rayRight = false, // line's continuation to the right + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeTrendLineEmptyPoints( + time1, + price1, + time2, + price2 + ); + + // + // reset the error value ... + ResetLastError(); + + // + // create a trend line by the given coordinates ... + if(!ObjectCreate(chartID, name, OBJ_TREND, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the line's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move trend line anchor point ... | +bool ChangeTrendLinePoint( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int pointindex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move trend line's anchor point ... + if(!ObjectMove(chartID, name, pointindex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// The function deletes the trend line from the chart ... +bool DeleteTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a trend line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of trend line's anchor points and set default ... +// values for empty ones ... +void ChangeTrendLineEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the first point's time is not set, it will be on the current bar ... + if (!time1) { + time1 = TimeCurrent(); + } + + // + // if the first point's price is not set, it will have Bid value ... + if (!price1) { + price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // if the second point's time is not set, it is located 9 bars left from the second one ... + if (!time2) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(), Period(), time1, 10, temp); + + // + // set the second point 9 bars left from the first one ... + time2 = temp[0]; + } + + // + // if the second point's price is not set, it is equal to the first point's one ... + if (!price2) { + price2 = price1; + } +} +// +// End TrendLine Functions ... +// + +// +// Start Text Functions ... +// +// Create and Draw a Text Object ... +bool DrawText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const string text = "Text", // the text itself + const string font = "Arial", // font + const int fontSize = 10, // font size + const color clr = clrRed, // color + const double angle = 0.0, // text slope + const ENUM_ANCHOR_POINT anchor = ANCHOR_CENTER, // anchor type + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor point coordinates if they are not set ... + ChangeTextEmptyPoint(time,price); + + // + // reset the error value ... + ResetLastError(); + + // + //--- create Text object + if(!ObjectCreate(chartID, name, OBJ_TEXT, subWindow, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the text ... + ObjectSetString(chartID, name , OBJPROP_TEXT, text); + + // + // set text font ... + ObjectSetString(chartID, name, OBJPROP_FONT, font); + + // + // set font size ... + ObjectSetInteger(chartID, name, OBJPROP_FONTSIZE, fontSize); + + // + // set the slope angle of the text ... + ObjectSetDouble(chartID, name, OBJPROP_ANGLE, angle); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the object by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID ,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point ... +bool MoveText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + //--- if point position is not set, move it to the current bar having Bid price + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point .. + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the object text ... +bool ChangeText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const string text = "Text" // text +) { + // + // reset the error value ... + ResetLastError(); + + // + // change object text ... + if(!ObjectSetString(chartID, name, OBJPROP_TEXT, text)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the text! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Text object ... +bool DeleteText( + const long chartID = 0, // chart's ID + const string name = "Text" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeTextEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + } +// +// End Text Functions ... +// + +// +// Start Fibonacchi Functions ... +// +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawFibonacci( + const long chartID = 0, // chart's ID + const string name="Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrRed, // object color + const ENUM_LINE_STYLE style = STYLE_SOLID, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawCustomFibonacci( + // + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + // + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrAqua, // object color + const ENUM_LINE_STYLE style = STYLE_DOT, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // Change Levels Of Fibonacci ... + bool result = FibonacciLevelsSet( + levels, + values, + colors, + styles, + widths, + descriptions, + chartID, + name + ); + + // + // successful execution ... + return result; +} + +// +// Set number of levels and their parameters ... +bool FibonacciLevelsSet( + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // check array sizes ... + if( + levels!=ArraySize(colors) || + levels!=ArraySize(styles) || + levels!=ArraySize(widths) || + levels!=ArraySize(widths) + ) { + // + string message = StringConcatenate( + __FUNCTION__, + ": array length does not correspond to the number of levels, error!" + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the number of levels ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELS, levels); + + // + // set the properties of levels in the loop ... + for(int i = 0; i < levels; i++) { + // + // level value ... + ObjectSetDouble(chartID, name, OBJPROP_LEVELVALUE, i, values[i]); + + // + // level color ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELCOLOR, i, colors[i]); + + // + // level style ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELSTYLE, i, styles[i]); + + // + // level width ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELWIDTH, i, widths[i]); + + // + // level description ... + // ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, DoubleToString(100 * values[i], 1)); + ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, descriptions[i]); + } + + // + // successful execution ... + return(true); +} + +// +// Move Fibonacci Retracement anchor point ... +bool FibonacciPointChange( + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int pointIndex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, pointIndex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Fibonacci Retracement ... +bool DeleteFibonachi( + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Fibonacci Retracement\"! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of Fibonacci Retracement anchor points and set +// default values for empty ones ... +void ChangeFibonacciEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the second point's time is not set, it will be on the current bar ... + if (!time2) { + time2 = TimeCurrent(); + } + + // + // if the second point's price is not set, it will have Bid value ... + if (!price2) { + price2 = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // if the first point's time is not set, it is located 9 bars left from the second one ... + if (!time1) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(),Period(),time2,10,temp); + + // + // set the first point 9 bars left from the second one ... + time1 = temp[0]; + } + + // + // if the first point's price is not set, move it 200 points below the second one ... + if (!price1) { + price1 = price2 - 200 * SymbolInfoDouble(_Symbol, SYMBOL_POINT); + } +} +// +// End Fibonacci Functions ... +// + + +// +// Start General Functions ... +// +// +// Remove all Drawn Objects ... +void RemoveDraws(const string &tag) { + // + for(int iObj=ObjectsTotal()-1; iObj >= 0; iObj--) { + // + string on = ObjectName(iObj); + if (StringFind(on, tag) == 0) { + ObjectDelete(on); + } + } +} +// +// End General Functions ... +// \ No newline at end of file diff --git a/Bkp/XAUUSD-15M/Libraries/x-saherelm.indicator.lib.mq4 b/Bkp/XAUUSD-15M/Libraries/x-saherelm.indicator.lib.mq4 new file mode 100644 index 0000000..0e4b162 --- /dev/null +++ b/Bkp/XAUUSD-15M/Libraries/x-saherelm.indicator.lib.mq4 @@ -0,0 +1,450 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Indicator Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// Reading specified Buffer From ADX Indicator ... +double ReadXMABuffer( + const int bar_index, + const int buffer_index, + // + const int marketLen, + // + const double stp, + const double mxm, + // + const int shortCycleMult, + const int mediumCycleMult, + const int longCycleMult +) { + // + string xmaIndicatorName = "x-saherelm.x.xma"; + + // + double result = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // Inputs ... + marketLen, + stp, + mxm, + shortCycleMult, + mediumCycleMult, + longCycleMult, + MODE_SMA, + // + buffer_index, + bar_index + ); + + // + return result; +} + +// +// Reading specified Buffer from XHL Indicator ... +double ReadXHLBuffer( + const int bar_index, + const int buffer_index, + // + const int marketLen, + // + const int shortCycleMult, + const int mediumCycleMult, + const int longCycleMult +) { + // + string xhlIndicatorName = "x-saherelm.x.hl"; + + // + double result = iCustom( + _Symbol, + _Period, + xhlIndicatorName, + // + // Inputs ... + marketLen, + shortCycleMult, + mediumCycleMult, + longCycleMult, + MODE_SMA, + // + buffer_index, + bar_index + ); + + // + return result; +} + +// +// Reading ADX Values ... +double ReadADX( + const int bar_index, + const int marketLen, + const int mult +) { + // + double result; + + // + int period = marketLen * mult; + + // + result = iADX( + _Symbol, + _Period, + period, + PRICE_CLOSE, + MODE_MAIN, + bar_index + ); + + // + return result; +} + +// +// Reading Pivot States ... +XPvtState GetPVTState( + const int bar_index, + const int marketLen +) { + // + XPvtState result = {}; + + // + double hh = GetMarketHighestHigh( + bar_index, + marketLen + ); + + // + double ho = GetMarketHighestOpen( + bar_index, + marketLen + ); + + // + double hc = GetMarketHighestClose( + bar_index, + marketLen + ); + + // + double hl = GetMarketHighestLow( + bar_index, + marketLen + ); + + // + double ll = GetMarketLowestLow( + bar_index, + marketLen + ); + + // + double lo = GetMarketLowestOpen( + bar_index, + marketLen + ); + + // + double lc = GetMarketLowestClose( + bar_index, + marketLen + ); + + // + double lh = GetMarketLowestHigh( + bar_index, + marketLen + ); + + // + // Filling Result ... + // + result.hh = hh; + result.ho = ho; + result.hc = hc; + result.hl = hl; + + // + result.ll = ll; + result.lo = lo; + result.lc = lc; + result.lh = lh; + + // + return result; +} + +// +// Calculate XRange from Market ... +static XRState lastXRState; +XRState GetXRange( + const int bar_index, + const int rangeMarketLength +) { + // + XRState result = {}; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + int marketBarIndex = bar_index + rangeMarketLength; + + // + // Highest High ... + // + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketBarIndex, + bar_index + ); + + // + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + // Lowest Low ... + // + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketBarIndex, + bar_index + ); + + // + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + if (lastXRState.start == 0) { + // + lastXRState.start = barTime; + lastXRState.length = rangeMarketLength; + + // + lastXRState.hh = hh; + lastXRState.ll = ll; + + // + // Middle ... + double mid = (hh + ll) / 2; + lastXRState.mid = mid; + } else { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + lastXRState.start + ); + + // + if (startBarIndex - bar_index >= rangeMarketLength) { + // + lastXRState.start = barTime; + lastXRState.length = rangeMarketLength; + + // + lastXRState.hh = hh; + lastXRState.ll = ll; + + // + // Middle ... + double mid = (hh + ll) / 2; + lastXRState.mid = mid; + } + } + + // + result = lastXRState; + + // + return result; +} + +// +// Reading XTPowState from Indicatoe ... +XTPOWState GetXTPowState( + const int bar_index, + const int marketLen +) { + // + XTPOWState result = {}; + + // + // + double powerUp = 0; + double powerDown = 0; + double signal = 0; + + // + string indicatorName = "x-saherelm.xtpow"; + + // + int pUpIndex = 0; + int pDownIndex = 1; + int signalIndex = 2; + + // + powerUp = iCustom( + _Symbol, + _Period, + indicatorName, + // + marketLen, + // + pUpIndex, + bar_index + ); + + // + powerDown = iCustom( + _Symbol, + _Period, + indicatorName, + // + marketLen, + // + pDownIndex, + bar_index + ); + + // + signal = iCustom( + _Symbol, + _Period, + indicatorName, + // + marketLen, + // + signalIndex, + bar_index + ); + + // + result.signal = signal; + result.powerUp = powerUp; + result.powerDown = powerDown; + + // + return result; +} + +// +// Reading XRState From Indicator ... +XRState ReadXRange( + const int bar_index, + const int marketLen +) { + // + XRState result = {}; + + // + // Define Buffer Indexes ... + int hhBufferIndex = 0; + int llBufferIndex = 1; + int midBufferIndex = 2; + + // + string indicatorName = "x-saherelm.xrange"; + + // + // Read Values From XRange Indicator ... + + // + double hh = iCustom( + _Symbol, + _Period, + indicatorName, + // + // Inputs ... + marketLen, + // + hhBufferIndex, // Buffer Index ... + bar_index + ); + + // + double ll = iCustom( + _Symbol, + _Period, + indicatorName, + // + // Inputs ... + marketLen, + // + llBufferIndex, // Buffer Index ... + bar_index + ); + + // + double mid = iCustom( + _Symbol, + _Period, + indicatorName, + // + // Inputs ... + marketLen, + // + midBufferIndex, // Buffer Index ... + bar_index + ); + + // + // Filling Result ... + result.hh = hh; + result.ll = ll; + result.mid = mid; + + // + return result; +} +// +// END Indicator Reading Data ... +// diff --git a/Bkp/XAUUSD-15M/Libraries/x-saherelm.lib.mq4 b/Bkp/XAUUSD-15M/Libraries/x-saherelm.lib.mq4 new file mode 100644 index 0000000..cc0e23e --- /dev/null +++ b/Bkp/XAUUSD-15M/Libraries/x-saherelm.lib.mq4 @@ -0,0 +1,1662 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +static datetime lastBarTime; + +// +struct XOHCL { + double high; + double open; + double close; + double low; +}; + +// +struct XRange { + // + datetime time; + + // + double highestHigh; + double lowestLow; + + // + int levels; + int marketLength; + + // + double rate; +}; + +// +struct XPrice { + // + double askPrice; + double bidPrice; + double priceGap; + + // + double longEntry; + double longExit; + + // + double shortEntry; + double shortExit; +}; + +// +// START Functions ... +// + +// +// Determines current working is New Bar or not ... +bool IsNewBar() { + // + // Reading Last Bar Date ... + datetime curbar = (datetime)SeriesInfoInteger( + _Symbol, + _Period, + SERIES_LASTBAR_DATE + ); + + // + if(lastBarTime != curbar) { + // + lastBarTime = curbar; + return true; + } + + // + return false; +} + +// +// Determines we are in new Day or not ... +bool IsNewDay() { + // + bool result = false; + + // + // Reading Last Bar Date ... + datetime curbar = (datetime)SeriesInfoInteger( + _Symbol, + _Period, + SERIES_LASTBAR_DATE + ); + + // + if (lastBarTime == 0) { + lastBarTime = curbar; + } + + // + if (curbar == lastBarTime) { + return result; + } + + // + // Retrieve Day and Month and Year for Last Bar Time ... + int lastBarDay = TimeDay(lastBarTime); + int lastBarMonth = TimeMonth(lastBarTime); + int lastBarYear = TimeYear(lastBarTime); + + // + // Retrieve Day and Month and Year for Current Bar Time ... + int curBarDay = TimeDay(curbar); + int curBarMonth = TimeMonth(curbar); + int curBarYear = TimeYear(curbar); + + // + result = curBarDay > lastBarDay + || curBarMonth > lastBarMonth + || curBarYear > lastBarYear; + + // + return result; +} + +// +// Retrieve Number of Candles in a Day ... +int GetDailyCandleCount() { + // + int seconds = PeriodSeconds(_Period); + + // + int daySeconds = 24 * 60 * 60; + + // + int result = daySeconds / seconds; + + // + return result; +} + +// +// XRange Detector ... +XRange GetMarketRange( + const int bar_index, + const int marketLen, + const int levels +) { + // + XRange result = {}; + + // + result.levels = levels; + result.marketLength = marketLen; + + // + datetime time = iTime( + _Symbol, + _Period, + bar_index + ); + result.time = time; + + // + double highestHigh = GetMarketHighestHigh( + bar_index, + marketLen + ); + result.highestHigh = highestHigh; + + // + double lowestLow = GetMarketLowestLow( + bar_index, + marketLen + ); + result.lowestLow = lowestLow; + + // + double diff = highestHigh - lowestLow; + double rate = diff / levels; + + // + result.rate = rate; + + // + return result; +} + +// +// Retrieve RMA on Specific Candle ... +double GetRMA( + int bar_index, + int length +) { + // + double shortSMA = iMA(_Symbol, _Period, length, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double mediumSMA = iMA(_Symbol, _Period, length * 2, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double longSMA = iMA(_Symbol, _Period, length * 3, 0, MODE_SMA, PRICE_CLOSE, bar_index); + + // + double result = longSMA - mediumSMA + shortSMA; + + // + return result; +} + +// +// Retrieve Moving Average ... +double GetMA( + const int bar_index, + const int maLength, + const int maShift, + const ENUM_MA_METHOD maMethod, + const ENUM_APPLIED_PRICE appliedPrice +) { + // + double result = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + appliedPrice, + bar_index + ); + + // + return result; +} + +// +// Calculate Fib Level ... +double GetFibonacciLevel( + double upPrice, + double downPrice, + double level, + int direction +) { + // + double ling = upPrice - downPrice; + double pLevel = (ling / 100) * (level * 100); + + // + double result = direction > 0 ? + upPrice - pLevel : + downPrice + pLevel; + result = NormalizeDouble(result, _Digits); + + // + return result; +} + +// +// Retrieve True Range ... +double GetTR( + const int bar_index +) { + // + double result = 0; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double prevClose = iClose( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double highLowDif = high - low; + double hpCDif = MathAbs(high - prevClose); + double lpCDiff = MathAbs(low - prevClose); + + // + result = MathMax(highLowDif, hpCDif); + result = MathMax(result, lpCDiff); + + // + return result; +} + +// +// Calculate True Range Simple Moving Average ... +double GetMarketTRSMA( + const int bar_index, + const int marketLen +) { + // + double result = 0; + + // + // Create Barket Length Trs ... + double trs[]; + ArrayResize( + trs, + marketLen + ); + int index = 0; + double trSum = 0; + for (int i = bar_index; i < bar_index + marketLen; i++) { + // + double tr = GetTR(i); + trs[index] = tr; + + // + trSum += tr; + + // + index++; + } + + // + result = trSum / marketLen; + + // + return result; +} + +// +// Retrieve Commodity Channel ... +double GetMarketCCI( + const int bar_index, + const int marketLen, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE +) { + // + double result = 0; + + // + result = iCCI( + _Symbol, + _Period, + marketLen, + appliedPrice, + bar_index + ); + + // + return result; +} + +// +// this function check crossing up two Buffers ... +bool IsCrossedOver( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] > arr2[index1]) && !(arr1[index2] > arr2[index2]); + + // + return result; +} + +// +// this function check crossing down two Buffers ... +bool IsCrossedUnder( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] < arr2[index1]) && !(arr1[index2] < arr2[index2]); + + // + return result; +} + +// +// Convert points to Actual Point ... +double PointsToDouble(int points) { + // + double result = points * _Point; + return result; +} + +// +// Converts Pips to Points ... +int PipsToPoints(int pips) { + // + int result = pips * ((_Digits == 3 || _Digits == 5) ? 10 : 1); + return result; +} + +// +// Converts Pips to Double ... +double PipsToDouble(int pips) { + // + double result = PointsToDouble(PipsToPoints(pips)); + return result; +} + +// +// Converts Double Value to Pips ... +int PriceToPips(double value) { + // + if (value <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + int result = (int)(value / pipValue); + + // + return result; +} + +// +// Converts Pips to Double ... +double PipsToPrice(int pips) { + // + if (pips <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + double result = pipValue * pips; + + // + return result; +} + +// +// Generate ATR StopLoss Value ... +double CalculateATRSL( + int period, + double multiplier +) { + // + if (period <= 0 || multiplier <= 0) { + return 0; + } + + // + double atrValue = iATR( + _Symbol, + _Period, + period, + 0 + ); + + // + double result = atrValue * multiplier; + + // + return result; +} + +// +// Detect Candle Type ... +// Bullish => means close > open ... +bool IsBullishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBullishCandle( + open, + close + ); + + // + return result; +} + +bool IsBullishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open < close; + + // + return result; +} + +// +// Detect Candle Type ... +// Bearish => means close < open ... +bool IsBearishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBearishCandle( + open, + close + ); + + // + return result; +} + +bool IsBearishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open > close; + + // + return result; +} + +// +// Retrieve a Candle Info ... +XOHCL GetCandleModel( + const int bar_index +) { + // + XOHCL result = {}; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + result.high = high; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + result.open = open; + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + result.close = close; + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + result.low = low; + + // + return result; +} + +// +// Retrieve Market Current Prices for Signals ... +XPrice GetPrice() { + // + XPrice result = {}; + + // + RefreshRates(); + + // + double askPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double bidPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(bidPrice - askPrice); + + // + result.askPrice = askPrice; + result.bidPrice = bidPrice; + result.priceGap = priceGap; + + // + result.longEntry = askPrice; + result.longExit = bidPrice; + + // + result.shortEntry = bidPrice; + result.shortExit = askPrice; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBullishDetected( + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double shpDetectMultipliers // Sharp Detect Multiplier +) { + // + bool result = false; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double minValue = 0; + double maxValue = 0; + int positionedLength = bar_index + marketLen; + + // + for (int i = bar_index; i < positionedLength; i++) { + // + double cHigh = iHigh( + _Symbol, + _Period, + i + ); + + // + double cLow = iLow( + _Symbol, + _Period, + i + ); + + // + minValue += MathMin(cLow, cHigh); + maxValue += MathMax(cLow, cHigh); + } + + // + double minAvg = minValue / positionedLength; + double maxAvg = maxValue / positionedLength; + + // + double shpValue = shpDetectMultipliers * _Point; + + // + result = (low - minAvg) > shpValue; + + // + int index = bar_index; + while ( + index < positionedLength + || !result + ) { + // + low = iLow( + _Symbol, + _Period, + index + ); + + // + result = result + || (low - minAvg) > shpValue; + + // + index++; + }; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBearishDetected( + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double shpDetectMultipliers // Sharp Detect Multiplier +) { + // + bool result = false; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double minValue = 0; + double maxValue = 0; + int positionedLength = bar_index + marketLen; + + // + for (int i = bar_index; i < positionedLength; i++) { + // + double cHigh = iHigh( + _Symbol, + _Period, + i + ); + + // + double cLow = iLow( + _Symbol, + _Period, + i + ); + + // + minValue += MathMin(cLow, cHigh); + maxValue += MathMax(cLow, cHigh); + } + + // + double minAvg = minValue / positionedLength; + double maxAvg = maxValue / positionedLength; + + // + double shpValue = shpDetectMultipliers * _Point; + + // + result = (high - maxAvg) > shpValue; + + // + int index = bar_index; + while ( + index < positionedLength + || !result + ) { + // + high = iHigh( + _Symbol, + _Period, + index + ); + + // + result = result + || (high - maxAvg) > shpValue; + + // + index++; + }; + + // + return result; +} + +// +// Retrieve Highest High Value based on Given Market ... +double GetMarketHighestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Low Value based on Given Market ... +double GetMarketHighestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Open Value based on Given Market ... +double GetMarketHighestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Close Value based on Given Market ... +double GetMarketHighestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Low Value based on Given Market ... +double GetMarketLowestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest High Value based on Given Market ... +double GetMarketLowestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Open Value based on Given Market ... +double GetMarketLowestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Close Value based on Given Market ... +double GetMarketLowestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// less than given price ... +double GetLowLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// great than given price ... +double GetLowGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// less than given price ... +double GetHighLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// great than given price ... +double GetHighGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// less than given price ... +double GetCloseLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// great than given price ... +double GetCloseGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Get Slope of a Line by it's two Point ... +double GetSlope( + double x1, + double y1, + double x2, + double y2 +) { + // + double result = (y2 - y1)/MathAbs(x2 - x1); + return result; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Bkp/XAUUSD-15M/Libraries/x-saherelm.log.lib.mq4 b/Bkp/XAUUSD-15M/Libraries/x-saherelm.log.lib.mq4 new file mode 100644 index 0000000..066b3f7 --- /dev/null +++ b/Bkp/XAUUSD-15M/Libraries/x-saherelm.log.lib.mq4 @@ -0,0 +1,91 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Log Tag ... +static string logTag = ""; + +// +// Enable or Disable Logging ... +static bool enableLogging = false; + +// +// Start Log Messages ... +// + +// +// Logging a Message, specified for this EA ... +// using provided LogTag ... +void LogMessage(string message) { + // + if (!enableLogging) { + return; + } + + // + Print(logTag, " > ", message); +} + +// +// this used for logging series ... +void LogSeries( + double &series[], // which series to Log ... + int length = 0, // number of items to Log, 0 means all ... + int skip = 0 // number of items which skip before logging ... +) { + // + string msg = ""; + + // + int seriesSize = ArraySize(series); + if ( + skip < 0 + || length < 0 + || seriesSize == 0 + || skip > seriesSize + || skip + length > seriesSize + ) { + return; + } + + // + length = length == 0 ? + seriesSize : + length; + int start = skip > 1 ? + skip - 1 : + skip == 1 ? + 1 : + 0; + + // + // Loop through series items ... + for (int i = start; i < start + length; i++) { + // + msg += StringConcatenate( + "i[", i, "]: ", series[i], ", " + ); + } + + // + LogMessage(msg); +} +// +// End Log Messages ... +// + diff --git a/Bkp/XAUUSD-15M/Libraries/x-saherelm.models.lib.mq4 b/Bkp/XAUUSD-15M/Libraries/x-saherelm.models.lib.mq4 new file mode 100644 index 0000000..fa9903f --- /dev/null +++ b/Bkp/XAUUSD-15M/Libraries/x-saherelm.models.lib.mq4 @@ -0,0 +1,154 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Models Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// START STATIC Variables ... +// +// +static int totalSignals = 0; +static int totalLongSignals = 0; +static int totalShortSignals = 0; + +// +static double initialBalance = 0; + +// +static int countedBars = 0; +static bool isNewBar = false; +static bool isNewDay = false; +// +// END STATIC Variables ... +// + +// +// Start Models ... +// +// +// Signal Providers ... +enum ENUM_X_SIGNAL_PROVIDER { + X_UNKNOWN_PROVIDER, + X_XXX_PROVIDER, + X_XR_PROVIDER, + X_XTPW_PROVIDER +}; + +// +// these are different signal types ... +enum ENUM_X_SIGNAL_TYPE { + X_SIGNAL_NONE, + X_SIGNAL_LONG, + X_SIGNAL_SHORT, +}; + +// +// Model Market Highs and Lows ... +struct XPvtState { + // + double hh; + double ho; + double hc; + double hl; + + // + double ll; + double lo; + double lc; + double lh; +}; + +// +// we Model each signals as this type ... +struct XSignal { + // + // Signal Symbol ... + string symbol; + + // + // Signal Type ... + ENUM_X_SIGNAL_TYPE type; + + // + // Signal ID ... + int id; + + // + // Signal Ticket Number, when Opening Trade ... + int ticket; + + // + // Signal Provider ... + ENUM_X_SIGNAL_PROVIDER provider; + + // + // Target Point ... + double tp; + + // + // Stop Loss ... + double sl; + + // + // Signal Entry Price ... + double entry; + + // + // Signalling Time ... + datetime time; + + // + // Signal Comments ... + string comment; + + // + // Signal TAG ... + string tag; +}; + +// +// this is Signal Request Response model ... +struct XSignalRequest { + bool hasSignal; + XSignal signal; + ENUM_X_SIGNAL_TYPE type; + ENUM_X_SIGNAL_PROVIDER provider; +}; + +// +struct XRState { + // + datetime start; + int length; + + // + double hh; + double ll; + double mid; +}; + +// +struct XTPOWState { + // + double powerUp; + double powerDown; + + // + double signal; +}; +// +// End Models ... +// diff --git a/Bkp/XAUUSD-15M/Libraries/x-saherelm.signal.lib.mq4 b/Bkp/XAUUSD-15M/Libraries/x-saherelm.signal.lib.mq4 new file mode 100644 index 0000000..097ce74 --- /dev/null +++ b/Bkp/XAUUSD-15M/Libraries/x-saherelm.signal.lib.mq4 @@ -0,0 +1,1756 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Signal Draw Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +#include "../Libraries/x-saherelm.x.signal.lib.mq4" +#include "../Libraries/x-saherelm.xr.signal.lib.mq4" +#include "../Libraries/x-saherelm.xtpw.signal.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// END Global Requirement Functions ... +// + +// +// START Signal Related Functions ... +// +// +// Retrieve Signal Bar Index ... +int GetSignalBarIndex(XSignal &signal) { + // + // Temp Result ... + int result = -1; + + // + // Retriev Signal Bar Index ... + result = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + return result; +} + +// +string GetSignalProviderIdentifier( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + string result = ""; + + // + switch (provider) { + // + case X_XXX_PROVIDER: + result = "XXX"; + break; + + // + case X_XR_PROVIDER: + result = "XR"; + break; + + // + case X_XTPW_PROVIDER: + result = "XTPW"; + break; + + // + default: + result = ""; + break; + } + + // + return result; +} + +// +ENUM_X_SIGNAL_PROVIDER GetSignalProvider(string identifier) { + // + ENUM_X_SIGNAL_PROVIDER result = X_UNKNOWN_PROVIDER; + + // + if ( + StringFind( + identifier, + GetSignalProviderIdentifier(X_XXX_PROVIDER) + ) > -1 + ) { + result = X_XXX_PROVIDER; + } else if ( + StringFind( + identifier, + GetSignalProviderIdentifier(X_XR_PROVIDER) + ) > -1 + ) { + result = X_XR_PROVIDER; + } else if ( + StringFind( + identifier, + GetSignalProviderIdentifier(X_XTPW_PROVIDER) + ) > -1 + ) { + result = X_XTPW_PROVIDER; + } + + // + return result; +} + +// +// Retrieve Signal Lots Per Trade ... +double GetSignalLottage( + const XSignal &signal, + const double defLotsPerTrade +) { + // + double result = defLotsPerTrade; + + // + bool isLong = signal.type == X_SIGNAL_LONG; + + // + switch (signal.provider) { + // + case X_XR_PROVIDER: + // + result = isLong ? + xRLongLotsPerTradePercent : + xRShortLotsPerTradePercent + ; + break; + + // + case X_XXX_PROVIDER: + // + result = isLong ? + xLongLotsPerTradePercent : + xShortLotsPerTradePercent + ; + break; + + // + case X_XTPW_PROVIDER: + // + result = isLong ? + xTPWLongLotsPerTradePercent : + xTPWShortLotsPerTradePercent + ; + break; + } + + // + return result; +} + +// +// Draw Specific Range On Chart ... +void DrawRange( + const XRange &range, + const long chartID = 0, + const int subWindowID = 0, + const string tag = "", + const color clr = clrYellow +) { + // + // Loop through Levels Count ... + for (int i = 0; i <= range.levels; i++) { + // + datetime time1 = iTime( + _Symbol, + _Period, + 1 + ); + + // + datetime time2 = iTime( + _Symbol, + _Period, + 0 + ); + + // + double price = range.lowestLow + (i * range.rate); + + // + string lbl = StringConcatenate( + tag, + "_XRL_", + price + ); + + // + DrawTrendLine( + chartID, + lbl, + subWindowID, + time1, + price, + time2, + price, + clr, + STYLE_DOT + ); + } +} + +// +// Draw Signal Shapes on Chart ... +bool DrawSignal( + const XSignal &signal, + long chartID = 0, + int subWindowID = 0, + const double positionThresholdFactor = 10, + string longSignalLabel = "X-Long", + color longSignalColor = clrAqua, + string shortSignalLabel = "X-Short", + color shortSignalColor = clrFuchsia +) { + // + // Generate isLongSignal Var ... + bool isLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Signal Bar Index ... + int bar_index = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // START Draw Signal Arrow ... + // + // + // Arrow Shape Name ... + string arrowName = StringConcatenate(signal.tag, "_Arrow_", signal.id); + + // + // Arrow Price ... + double arrowPrice = 0; + if (isLongSignal) { + // + arrowPrice = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice - (positionThresholdFactor * _Point); + } else { + // + arrowPrice = iHigh( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice + (positionThresholdFactor * _Point); + } + + // + // Arrow Code ... + uchar arrowCode = isLongSignal ? SYMBOL_ARROWUP : SYMBOL_ARROWDOWN; + + // + // Arrow Anchor Point ... + ENUM_ARROW_ANCHOR arrowAnchorPoint = isLongSignal ? ANCHOR_BOTTOM : ANCHOR_TOP; + + // + // Arrow Color ... + color arrowColor = isLongSignal ? longSignalColor : shortSignalColor; + + // + // Draw Signal Arrow Shape ... + bool result = DrawArrow( + chartID, + arrowName, + subWindowID, + signal.time, + arrowPrice, + arrowCode, + arrowAnchorPoint, + arrowColor + ); + // + // END Draw Signal Arrow ... + // + + // + // START Draw Signal SL/TP ... + // + string slLineName = StringConcatenate(signal.tag, "_SL_", signal.id); + string tpLineName = StringConcatenate(signal.tag, "_TP_", signal.id); + string entryLineName = StringConcatenate(signal.tag, "_ENTRY_", signal.id); + + // + color slColor = shortSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color tpColor = longSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color entryColor = clrGreen; + + // + datetime time1 = iTime( + _Symbol, + _Period, + bar_index + 1 + ); + + // + // Draw Enrty Price ... + result = DrawTrendLine( + chartID, + entryLineName, + subWindowID, + time1, + signal.entry, + signal.time, + signal.entry, + entryColor, + STYLE_SOLID, + 2 + ); + + // + // Draw Signal SL ... + if (signal.sl > 0) { + // + result = DrawTrendLine( + chartID, + slLineName, + subWindowID, + time1, + signal.sl, + signal.time, + signal.sl, + slColor, + STYLE_SOLID, + 2 + ); + } + + // + // Draw Signal TP ... + if (signal.tp > 0) { + // + result = DrawTrendLine( + chartID, + tpLineName, + subWindowID, + time1, + signal.tp, + signal.time, + signal.tp, + tpColor, + STYLE_SOLID, + 2 + ); + } + // + // END Draw Signal SL/TP ... + // + + // + // Start Draw Signal Label ... + // + // + string labelName = StringConcatenate(signal.tag, "_Label_", signal.id); + + // + double labelPrice = isLongSignal ? arrowPrice - (positionThresholdFactor * _Point) : arrowPrice + (positionThresholdFactor * _Point); + + // + string labelText = isLongSignal ? longSignalLabel : shortSignalLabel; + labelText = StringConcatenate( + labelText, + "_", + GetSignalProviderIdentifier(signal.provider) + ); + + // + result = DrawText( + chartID, + labelName, + subWindowID, + signal.time, + labelPrice, + labelText, + "Arial", + 8, + arrowColor, + 0, + ANCHOR_CENTER + ); + // + // End Draw Signal Label ... + // + + // + return result; +} + +// +// Trade on Specific Signal ... +bool TradeSignal( + XSignal &signal, + // + double volumePercent, + // + // Long ... + const string longSignalLabel, + const color longSignalColor, + // + // Short ... + const string shortSignalLabel, + const color shortSignalColor +) { + // + // Temp Result ... + bool result = false; + + // + if (initialBalance == 0) { + initialBalance = AccountInfoDouble(ACCOUNT_BALANCE); + } + + // + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + int openPositions = CountOpenTrades(); + double volume = (volumePercent * initialBalance); + + // + if ( + signal.type != X_SIGNAL_LONG && + signal.type != X_SIGNAL_SHORT + ) { + return result; + } + + // + bool hasLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Check TP and Entry Price ... + if ( + ( + hasLongSignal + && signal.entry > signal.tp + ) || + ( + !hasLongSignal + && signal.entry < signal.tp + ) + ) { + return result; + } + + // + // Order Operation ... + int operation = hasLongSignal ? + OP_BUY : + OP_SELL; + + // + // Detect Trade Color ... + color clr = hasLongSignal ? + longSignalColor : + shortSignalColor; + + // + // Generate Signal Comment ... + string label = hasLongSignal ? + longSignalLabel : + shortSignalLabel; + + // + // Generate Signal Comment ... + string comment = StringConcatenate( + signal.tag, + "_", signal.id, + "_", GetSignalProviderIdentifier(signal.provider), + "_", label + ); + + // + // Placing Order ... + int orderTicket = OrderSend( + _Symbol, + operation, + volume, + signal.entry, + 3, + signal.sl, + signal.tp, + comment, + signal.id, + 0, + clr + ); + + // + // Draw Signal Shape if Order Opened Successfully ... + if (orderTicket >= 0) { + // + signal.ticket = orderTicket; + + // + // Here i must to Draw Signal Shapes ... + bool isDrawn = DrawSignal( + signal, + 0, + 0, + 50, + longSignalLabel, // Long Signal Label ... + longSignalColor, + shortSignalLabel, // Short Signal Label ... + shortSignalColor + ); + + // + LogMessage( + StringConcatenate( + "Order [", orderTicket ,"]: Provided by: ", GetSignalProviderIdentifier(signal.provider) + ) + ); + + // + // TODO: here we have to check if there are another + // open positions which their entry price is bigger + // than current signal entry price, for long trades and + // their tp is high than current tp, ... + // close in profit trades or modify orders tp to current ... + // // + // if (CountOpenTrades() > 0) { + // // + // // Here we have to + // ModifyOpenTradesBasedOnCurrentTrade(signal); + // } + + // + result = true; + } + + // + return result; +} +// +// END Signal Related Functions ... +// + +// +// START Orders Functions ... +// +// +// Convert To XSignal Model ... +XSignal OrderToSignal() { + // + // Temp Result ... + XSignal result = {}; + result.type = X_SIGNAL_NONE; + + // + // Here we can get some usefull info based on selected order ... + double swap = OrderSwap(); + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + int magicNumber = OrderMagicNumber(); + double takeProfit = OrderTakeProfit(); + string comment = OrderComment(); + + // + ENUM_X_SIGNAL_PROVIDER provider = GetSignalProvider(comment); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // Conver Position to Signal ... + result.sl = stopLoss; + result.tp = takeProfit; + result.time = openTime; + result.symbol = _Symbol; + result.id = magicNumber; + result.comment = comment; + result.entry = openPrice; + result.provider = provider; + result.type = isLongOrder ? X_SIGNAL_LONG : X_SIGNAL_SHORT; + + // + return result; +} + +// +// START Count Orders ... +// +// +// Count Open Positions ... +int CountOpenTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if (OrderSymbol() == _Symbol) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Long Positions ... +int CountOpenLongTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_BUY + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Short Positions ... +int CountOpenShortTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_SELL + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} +// +// END Count Orders ... +// + +// +// START Close Orders ... +// +// +// Close All Open Trades ... +bool CloseAllTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + + // + return result; +} + +// +bool CloseAllProviderTrades( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal(); + + // + if (signal.provider == provider) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +bool CloseAllProviderLongTrades( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal(); + + // + if ( + signal.provider == provider + && signal.type == X_SIGNAL_LONG + ) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +bool CloseAllProviderShortTrades( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal(); + + // + if ( + signal.provider == provider + && signal.type == X_SIGNAL_SHORT + ) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Long Trades ... +bool CloseAllLongTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Long Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Short Trades ... +bool CloseAllShortTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (!isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Short Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In Profit Trades ... +bool CloseAllInProfitTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit > 0 + && profit > 50 * _Point + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InProfit Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In DrawDown Trades ... +bool CloseAllInDrawDownTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if (profit < 0) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close Biggest In DrawDown Trades ... +bool CloseBiggestDrawDownTrade() { + // + // Loop through all Positions ... + bool result = false; + double drawDown = 0; + + // + // Find Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) > drawDown + ) { + drawDown = profit; + } + } + } + } + + // + // Close Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) >= drawDown + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Max InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Long Time Trades ... +bool CloseAllLongTimeTrades( + const int passedCandles, + const ENUM_X_SIGNAL_PROVIDER provider = X_UNKNOWN_PROVIDER +) { + // + bool result = false; + + // + if (passedCandles <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + string comment = OrderComment(); + + // + ENUM_X_SIGNAL_PROVIDER orderProvider = GetSignalProvider(comment); + bool isProviderVerified = + provider == X_UNKNOWN_PROVIDER ? + true : + orderProvider != X_UNKNOWN_PROVIDER + && orderProvider == provider + ; + + // + if ( + profit < 0 + && isProviderVerified + && openBarIndex - currentBarIndex >= passedCandles + // || ( + // profit > 0.5 + // && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 3) + // ) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Long Time issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + // else if ( + // openTrades > 0 + // && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 2) + // ) { + // result = CloseAllInProfitTrades() + // && CloseBiggestDrawDownTrade(); + // } + } + } + } + + // + return result; +} + +// +// Close all trades which passed Maximum Drawdown ... +bool CloseAllMaximumDrawDownPassedTrades( + const double maxDrDownPercentPerPTrade, + const ENUM_X_SIGNAL_TYPE type = X_SIGNAL_NONE, + const ENUM_X_SIGNAL_PROVIDER provider = X_UNKNOWN_PROVIDER +) { + // + if ( + initialBalance <= 0 + || maxDrDownPercentPerPTrade <= 0 + ) { + return false; + } + + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double maxAllowedDrawDown = -1 * (initialBalance * maxDrDownPercentPerPTrade); + + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + string comment = OrderComment(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + bool isTypeVerified = + type == X_SIGNAL_NONE ? + true : + ( isLongOrder + && type == X_SIGNAL_LONG + ) || ( + !isLongOrder + && type == X_SIGNAL_SHORT + ) + ; + + // + ENUM_X_SIGNAL_PROVIDER orderProvider = GetSignalProvider(comment); + bool isProviderVerified = + provider == X_UNKNOWN_PROVIDER ? + true : + orderProvider != X_UNKNOWN_PROVIDER + && orderProvider == provider + ; + + // + if ( + profit < 0 + && isTypeVerified + && isProviderVerified + && MathAbs(profit) >= MathAbs(maxAllowedDrawDown) + ) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Maximum DarwDown issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Trades Which Opens before Specified Length ... +bool CloseAllTradesWhichOpenInPastMarketLength( + const int marketLen +) { + // + bool result = false; + + // + if (marketLen <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + + // + if (openBarIndex <= currentBarIndex + marketLen) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Market Reverse issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } else if (openTrades > 0) { + // + // Close all InProfit Trdes and Biggest InDrawDown Trades ... + // result = CloseAllInProfitTrades(); + // && CloseBiggestDrawDownTrade(); + } + } + } + } + + // + return result; +} +// +// END Close Orders ... +// + +// +// START Modify Orders ... +// +// +void ModifyAllPriceLesserOpenTrades( + const XSignal &signal +) { + // + // Loop through all Open Trades ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + double takeProfit = OrderTakeProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // When new Signal Comming with price less than + // currently open trade and tp less than currently + // open trade, this means a market change happens ... + // here we can Close InProfit Trades or Modify Trades TP ... + if ( + ( + openPrice < signal.entry + || MathAbs(openPrice - signal.entry) < 300 * _Point + ) + && takeProfit > signal.tp + ) { + bool result = OrderModify( + ticket, + openPrice, + signal.sl, + signal.tp, + clrYellow + ); + } + } + } + } +} + +// +void ModifyOpenTradesBasedOnCurrentTrade( + const XSignal &signal +) { + // + ModifyAllPriceLesserOpenTrades(signal); +} +// +// END Modify Orders ... +// +// +// END Orders Functions ... +// + +// +// START Signal Conditions ... +// +// +// Clear Signal Conditions ... +void ClearSignalConditions() { + // + ClearLongSignalConditions(); + ClearShortSignalConditions(); +} + +// +// Clear all Conditions Waiter for Long Signals ... +void ClearLongSignalConditions() { + // + ClearXLongSignalConditions(); + ClearXRLongSignalConditions(); + ClearXTPWLongSignalConditions(); +} + +// +// Clear all Conditions Waiter for Short Signals ... +void ClearShortSignalConditions() { + // + ClearXShortSignalConditions(); + ClearXRShortSignalConditions(); + ClearXTPWShortSignalConditions(); +} +// +// END Signal Conditions ... +// diff --git a/Bkp/XAUUSD-15M/Libraries/x-saherelm.x.signal.lib.mq4 b/Bkp/XAUUSD-15M/Libraries/x-saherelm.x.signal.lib.mq4 new file mode 100644 index 0000000..834ddb1 --- /dev/null +++ b/Bkp/XAUUSD-15M/Libraries/x-saherelm.x.signal.lib.mq4 @@ -0,0 +1,1063 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 X Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Inputs ... +// +// +input string xStarter = "- X Signal Provider -"; // ---> X Signal Provider <--- + +// +input bool enableXSignalling = true; // X Signalling Enable + +// +input bool enableXLong = true; // X Signalling Enable Long +input bool enableXShort = true; // X Signalling Enable Short + +// +input double xShortR2R = 3; // X Short Risk To Reward Ratio +input double xShortLotsPerTradePercent = 0.0002; // X Lots Percent per Short Trades +input double xShortMaxDrawdownPerTradePercent = 0.4; // X Max Allowed DrawDown Percent per Short Trade + +// +input double xLongR2R = 3; // X Long Risk To Reward Ratio +input double xLongLotsPerTradePercent = 0.0002; // X Lots Percent per Short Trades +input double xLongMaxDrawdownPerTradePercent = 0.4; // X Max Allowed DrawDown Percent per Long Trade + +// +input double xSharpDetectorFactor = 700; // X Sharp Detection Factor + +// +input int xMaximumCandlesPerTrade = 206; // X Maximum Candles which a Trade can open + +// +input int xOscillatorLength = 7; // X Oscillator Length + +// +input double xPSarStep = 0.02; // X Parabolic Sar Step +input double xPSarMaximum = 0.2; // X Parabolic Sar Maximum + +// +input int xRangeMarketLength = 5; // X Range Detector Length + +// +input int xSwingLength = 7; // X Signal Swing Length +// +// END Inputs ... +// + +// +// START Global Requirement Functions ... +// +// +// X Based Signal Conditions ... +struct XSignalConditions { + datetime startTime; + datetime signalTime; + datetime entryTime; +}; + +// +struct XMarketState { + double psar; + double fast; + double slow; + double open; + double verifier; + double oscillator; + double oscillatorVerifier; +}; + +// +static XSignalConditions xLongConds; +static bool xCloseLongTrades = false; +static bool xWaitForLongSignals = true; + +// +static XSignalConditions xShortConds; +static bool xCloseShortTrades = false; +static bool xWaitForShortSignals = true; + +// +// Count Number of Closed Maximum DrawDown Trades ... +static int xFailedSignals = 0; + +// +datetime lastVerifierTouched; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckXSignalHandler( + const int bar_index +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + // + if ( + !enableXSignalling + || !(enableXLong || enableXShort) + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XOHCL candle = GetCandleModel(bar_index); + XOHCL pCandle = GetCandleModel(bar_index + 1); + XTPOWState tPowState = GetXTPowState( + bar_index + 1, + xSwingLength + ); + + // + XMarketState state = GetXMarketState( + bar_index + 1 + ); + + // + // Check Verifier Last Touched ... + bool isVerifierTouched = pCandle.high > state.verifier + && pCandle.low < state.verifier; + + // + // Disable Signals if a signal Failed ... + if (xFailedSignals) { + // + // TODO: Complete this ... + } + + // + // Enable Or Disable Signalling ... + if (isVerifierTouched) { + // + lastVerifierTouched = barTime; + + // + if (xWaitForLongSignals) { + xWaitForLongSignals = false; + } + + // + if (xWaitForShortSignals) { + xWaitForShortSignals = false; + } + } else { + // + int lastVerifierTouchedBarIndex = iBarShift( + _Symbol, + _Period, + lastVerifierTouched + ); + + // + int distance = MathAbs(lastVerifierTouchedBarIndex - bar_index); + + // + if ( + !xWaitForLongSignals + && distance > (xSwingLength * 2) + ) { + xWaitForLongSignals = true; + } + + // + if ( + !xWaitForShortSignals + && ( + distance > (xSwingLength * 2) + || ( + tPowState.powerDown > tPowState.powerUp + && tPowState.powerDown < 49 + ) + ) + ) { + xWaitForShortSignals = true; + } + } + + // + // Close All Long Open Trades ... + if ( + tPowState.powerDown > 55 + && tPowState.powerDown > tPowState.powerUp + ) { + // xCloseLongTrades = true; + } +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXLongSignalConditions( + const int bar_index +) { + // + if ( + !enableXLong + || !enableXSignalling + || !xWaitForLongSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + bool isCrossOver = false; + bool isCrossUnder = false; + + // + XMarketState cState = GetXMarketState(1); + XMarketState pState = GetXMarketState(2); + + // + isCrossUnder = + cState.fast < cState.slow + && !(pState.fast < pState.slow) + ; + + // + isCrossOver = + cState.fast > cState.slow + && !(pState.fast > pState.slow) + ; + + // + if ( + isCrossUnder + && xLongConds.startTime == 0 + ) { + // + xLongConds.startTime = barTime; + return; + } + + // + if ( + isCrossOver + && xLongConds.startTime > 0 + && xLongConds.signalTime == 0 + ) { + // + xLongConds.signalTime = barTime; + xLongConds.entryTime = barTime; + return; + } +} + +// +// Check and Fill Short Signal Conditions ... +void CheckXShortSignalConditions( + const int bar_index +) { + // + if ( + !enableXShort + || !enableXSignalling + || !xWaitForShortSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + bool isCrossOver = false; + bool isCrossUnder = false; + + // + XMarketState cState = GetXMarketState(1); + XMarketState pState = GetXMarketState(2); + + // + isCrossUnder = + cState.fast < cState.slow + && !(pState.fast < pState.slow) + ; + + // + isCrossOver = + cState.fast > cState.slow + && !(pState.fast > pState.slow) + ; + + // + if ( + isCrossOver + && xShortConds.startTime == 0 + ) { + // + xShortConds.startTime = barTime; + return; + } + + // + if ( + isCrossUnder + && xShortConds.startTime > 0 + && xShortConds.signalTime == 0 + ) { + // + xShortConds.signalTime = barTime; + xShortConds.entryTime = barTime; + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if ( + !enableXSignalling + || !(enableXLong || enableXShort) + ) { + return result; + } + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + if (requestLong) { + // + if ( + !ValidateXLongConditions() + ) { + return result; + } + } else { + // + if ( + !ValidateXShortConditions() + ) { + return result; + } + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double askPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double bidPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double entryPrice = requestLong ? + askPrice : + bidPrice; + + // + double exitPrice = requestLong ? + bidPrice : + askPrice; + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + // + GetMarketLowestLow( + bar_index, + xSwingLength + ) + ; + + // + double hh = + // + GetMarketHighestHigh( + bar_index, + xSwingLength + ) + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = requestLong ? + MathMin(openPrice, closePrice) - ll : + hh - MathMax(openPrice, closePrice) + ; + + // + double reward = + requestLong ? + risk * xLongR2R : + risk * xShortR2R + ; + + // + double sl = requestLong ? + 0 : + 0; + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward + ; + + // + XRState range = GetXRange( + bar_index, + xRangeMarketLength + ); + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XXX_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XXX_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXLongConditions() { + // + if ( + !enableXLong + || !enableXSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xLongConds.startTime > 0 + && xLongConds.signalTime > 0 + && xLongConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.signalTime + ); + + // + int entryBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.entryTime + ); + + // + isBLFilled = + // + xLongConds.signalTime > xLongConds.startTime + && xLongConds.entryTime >= xLongConds.signalTime + // && MathAbs(signalBarIndex - startBarIndex) >= 1 + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXLongSignalConditions(); + } + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXShortConditions() { + // + if ( + !enableXShort + || !enableXSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xShortConds.startTime > 0 + && xShortConds.signalTime > 0 + && xShortConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.signalTime + ); + + // + int entryBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.entryTime + ); + + // + isBLFilled = + // + xShortConds.signalTime > xShortConds.startTime + && xShortConds.entryTime >= xShortConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xWaitForShortSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXShortSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXLongSignalConditions() { + // + xLongConds.startTime = 0; + xLongConds.entryTime = 0; + xLongConds.signalTime = 0; +} + +// +// Clear Short Signal Conditions for New One ... +void ClearXShortSignalConditions() { + // + xShortConds.startTime = 0; + xShortConds.entryTime = 0; + xShortConds.signalTime = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForXSignals( + const XSignal &signal +) { + // + bool result = false; + + // + if ( + !enableXSignalling + || !(enableXLong || enableXShort) + ) { + return result; + } + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // XOHCL candle = GetCandleModel(0); + XOHCL candle = GetCandleModel(signalBarIndex); + XOHCL pCandle = GetCandleModel(signalBarIndex + 1); + + // + // Retrieve Range ... + XRState range = GetXRange( + signalBarIndex, + xRangeMarketLength + ); + + // + // Retrive XMarket States ... + XMarketState xState0 = GetXMarketState(signalBarIndex); + XMarketState xState1 = GetXMarketState(signalBarIndex + 1); + XMarketState xState2 = GetXMarketState(signalBarIndex + 2); + XMarketState xStateLast = GetXMarketState(signalBarIndex + xSwingLength); + + // + // Retrieve Trend Powers ... + XTPOWState xTPow0 = GetXTPowState( + signalBarIndex, + xSwingLength + ); + XTPOWState xTPow1 = GetXTPowState( + signalBarIndex + 1, + xSwingLength + ); + + // + double hh = GetMarketHighestHigh( + signalBarIndex, + xSwingLength + ); + double ll = GetMarketLowestLow( + signalBarIndex, + xSwingLength + ); + double diffChange = (hh - ll); + bool isBigSharpOccured = + diffChange > (xSharpDetectorFactor * _Point) + ; + + // + bool isPSarVerified = false; + bool isTPowVerified = false; + bool isStateVerified = false; + bool isPriceVerified = false; + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + // Get Price Verification for Long ... + isPriceVerified = + // + // Starter ... + true + // + && !isBigSharpOccured + // + && signal.entry < hh + // + // && signal.entry < range.hh + // && signal.entry > range.mid + // // + // && candle.high > xState0.verifier + // && signal.entry > xState0.verifier + // + // && pCandle.low != ll + && pCandle.high != hh + ; + + // + int above20TPowers = 0; + double signalSlope = 0; + int tPowUnverifyConditions = 0; + int tPowUnverifyConditionsIdx = 0; + for (int i = signalBarIndex; i < signalBarIndex + xSwingLength; i++) { + // + XTPOWState iTPowState = GetXTPowState( + i, + xSwingLength + ); + + // + // Calculate Signal Slope ... + if (i == signalBarIndex) { + // + signalSlope = iTPowState.signal; + } else if (i == signalBarIndex + 1) { + // + signalSlope = GetSlope( + 1, + iTPowState.signal, + 2, + signalSlope + ); + } + + // + if ( + iTPowState.powerUp > iTPowState.powerDown + && MathMax(iTPowState.powerUp, iTPowState.powerDown) > 20 + ) { + above20TPowers++; + } + + // + if (tPowUnverifyConditionsIdx < 3) { + // + if ( + iTPowState.powerUp < iTPowState.powerDown + || iTPowState.signal > MathMax(iTPowState.powerUp, iTPowState.powerDown) + ) { + tPowUnverifyConditions++; + } + + // + tPowUnverifyConditionsIdx++; + } + } + + // + isTPowVerified = + above20TPowers > 1 + && tPowUnverifyConditions == 0 + ; + + // + isPSarVerified = + xState0.psar < signal.entry + && xState0.psar < candle.low; + + // + isStateVerified = + // + // Start ... + true + // + // && xState0.open < xState0.slow + ; + + // + result = + // + // Starter ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + isPSarVerified = + xState0.psar > signal.entry + && xState0.psar > candle.high + ; + + // + // Get Price Verification for Short ... + isPriceVerified = + // + // Starter ... + true + // + && !isBigSharpOccured + // + && signal.entry > ll + && pCandle.low != ll + ; + + // + int above20TPowers = 0; + double signalSlope = 0; + int tPowUnverifyConditions = 0; + int tPowUnverifyConditionsIdx = 0; + for (int i = signalBarIndex; i < signalBarIndex + xSwingLength; i++) { + // + XTPOWState iTPowState = GetXTPowState( + i, + xSwingLength + ); + + // + // Calculate Signal Slope ... + if (i == signalBarIndex) { + // + signalSlope = iTPowState.signal; + } else if (i == signalBarIndex + 1) { + // + signalSlope = GetSlope( + 1, + iTPowState.signal, + 2, + signalSlope + ); + } + + // + if ( + iTPowState.powerUp > iTPowState.powerDown + && MathMax(iTPowState.powerUp, iTPowState.powerDown) > 20 + ) { + above20TPowers++; + } + + // + if (tPowUnverifyConditionsIdx < 3) { + // + if ( + iTPowState.powerUp > iTPowState.powerDown + || iTPowState.signal < MathMax(iTPowState.powerUp, iTPowState.powerDown) + ) { + tPowUnverifyConditions++; + } + + // + tPowUnverifyConditionsIdx++; + } + } + + // + isTPowVerified = + above20TPowers < 1 + && tPowUnverifyConditions == 0 + && MathAbs(xTPow0.powerUp - xTPow0.powerDown) > 50 * _Point + ; + + // + isStateVerified = + // + // Start ... + true + // + // && (xStateLast.verifier - xState0.verifier) >= 0 + // + && xState0.verifier > signal.entry + // + && MathAbs(signal.entry - xState0.verifier) < (xSharpDetectorFactor * _Point) + ; + + // + result = + // + // Starter Condition ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } + + // + return result; +} +// +// END Functions ... +// + +// +// START Data Provider ... +// +XMarketState GetXMarketState( + const int bar_index +) { + // + XMarketState result = {}; + + // + double fast = GetMA( + bar_index, + xSwingLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double open = GetMA( + bar_index, + xSwingLength, + 0, + MODE_SMA, + PRICE_OPEN + ); + + // + double slow = GetMA( + bar_index, + xSwingLength * 2, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double oscillator = GetMA( + bar_index, + xSwingLength, + 0, + MODE_EMA, + PRICE_CLOSE + ); + + // + double oscillatorVerifier = GetMA( + bar_index, + xSwingLength, + 0, + MODE_EMA, + PRICE_WEIGHTED + ); + + // + int dailyCount = GetDailyCandleCount(); + double verifier = GetMA( + bar_index, + dailyCount, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double psar = iSAR( + _Symbol, + _Period, + xPSarStep, + xPSarMaximum, + bar_index + ); + + // + result.psar = psar; + result.fast = fast; + result.open = open; + result.slow = slow; + result.verifier = verifier; + result.oscillator = oscillator; + result.oscillatorVerifier = oscillatorVerifier; + + // + return result; +} +// +// END Data Provider ... +// diff --git a/Bkp/XAUUSD-15M/Libraries/x-saherelm.xr.signal.lib.mq4 b/Bkp/XAUUSD-15M/Libraries/x-saherelm.xr.signal.lib.mq4 new file mode 100644 index 0000000..d4ae238 --- /dev/null +++ b/Bkp/XAUUSD-15M/Libraries/x-saherelm.xr.signal.lib.mq4 @@ -0,0 +1,1142 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 X Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Inputs ... +// +// +input string xRStarter = "- XR Signal Provider -"; // --> XR Signal Provider <-- + +// +input bool enableXRSignalling = true; // XR Signalling Enable + +// +input bool enableXRLong = true; // XR Signalling Enable Long +input bool enableXRShort = true; // XR Signalling Enable Short + +// +input double xRShortR2R = 1.5; // XR Short Risk To Reward Ratio +input double xRShortLotsPerTradePercent = 0.0002; // XR Lots Percent per Short Trades +input double xRShortMaxDrawdownPerTradePercent = 0.15; // XR Max Allowed DrawDown Percent per Short Trade + +// +input double xRLongR2R = 1.5; // XR Long Risk To Reward Ratio +input double xRLongLotsPerTradePercent = 0.0002; // XR Lots Percent per Short Trades +input double xRLongMaxDrawdownPerTradePercent = 0.15; // XR Max Allowed DrawDown Percent per Long Trade + +// +input int xRMaximumCandlesPerTrade = 96; // XR Maximum Candles which a Trade can open + +// +input int xRSwingLength = 48; // XR Swing Length +// +// END Inputs ... +// + +// +input double xRSharpDetectionFactor = 1350; // XR Sharp Detection Factor + +// +// START Global Requirement Functions ... +// +// +// XR Market State ... +struct XRMarketState { + // + double fast; + double slow; + double open; + + // + double range; + double rangeFast; + double rangeSlow; + double rangeOpen; + + // + double verifier; +}; + +// +// XR Based Signal Conditions ... +struct XRSignalConditions { + datetime startTime; + datetime signalTime; + datetime entryTime; +}; + +// +static XRSignalConditions xRLongConds; +static bool xRCloseLongTrades = false; +static bool xRWaitForLongSignals = true; + +// +static XRSignalConditions xRShortConds; +static bool xRCloseShortTrades = false; +static bool xRWaitForShortSignals = true; + +// +// Count Number of Closed Maximum DrawDown Trades ... +static int xRFailedSignals = 0; + +// +double xRMaximumDrawDown = 0; + +// +int fastLength = 0; +int slowLength = 0; + +// +int verifierLength = 0; + +// +int rangeFastLength = 0; +int rangeSlowLength = 0; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckXRSignalHandler( + const int bar_index +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + + // + if ( + !enableXRSignalling + || !(enableXRLong || enableXRShort) + ) { + return; + } +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXRLongSignalConditions( + const int bar_index +) { + // + if ( + !enableXRLong + || !enableXRSignalling + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Read Prices ... + XPrice prices = GetPrice(); + + // + // Read XPVTState ... + XPvtState pvt0 = GetPVTState( + bar_index, + xRSwingLength + ); + + // + // Double Length Pivots ... + XPvtState dblPvt0 = GetPVTState( + bar_index, + (xRSwingLength * 2) + ); + + // + // Reading Required Candles ... + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + XOHCL candle3 = GetCandleModel(bar_index + 3); + + // + // Reding Required XRMarketStates ... + XRMarketState state0 = GetXRMarketState(bar_index); + XRMarketState state1 = GetXRMarketState(bar_index + 1); + XRMarketState state2 = GetXRMarketState(bar_index + 2); + XRMarketState state3 = GetXRMarketState(bar_index + 3); + + // + // Reading required XRangeStates ... + XRState range0 = ReadXRange( + bar_index + xRSwingLength, + xRSwingLength + ); + XRState range1 = ReadXRange( + bar_index + xRSwingLength + 1, + xRSwingLength + ); + XRState range2 = ReadXRange( + bar_index + xRSwingLength + 2, + xRSwingLength + ); + + // + XRState cRange0 = ReadXRange( + bar_index, + xRSwingLength + ); + + // + // Validate Farest Range Values ... + if ( + range2.hh == 0 + || + range2.ll == 0 + || + range2.mid == 0 + ) { + return; + } + + // + // Reading Required XTPowStates ... + XTPOWState tPow0 = GetXTPowState( + bar_index, + xRSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xRSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xRSwingLength + ); + + // + // if state verifier below range middle + // this means market is bullish ... + // + // if state verifier above range middle + // this means market is bearish ... + // + + // + bool isMarketBullish = + state0.verifier < range0.mid + && state1.verifier < range1.mid; + bool isMarketBearish = + state0.verifier > range0.mid + && state1.verifier > range1.mid; + bool isMarketGoingBullish = + state0.verifier > range0.mid + && !(state1.verifier > range1.mid); + bool isMarketGoingBearish = + state0.verifier < range0.mid + && !(state1.verifier < range1.mid); + + // + // Check Highest High Conditions ... + bool isHHVerified = + !( + pvt0.hh == dblPvt0.hh + ) + ; + + // + int sharpDetectionLength = 7; + double sharpDetectionValue = xRSharpDetectionFactor * _Point; + + // + int sharpHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + sharpDetectionLength, + bar_index + ); + double sharpHH = iHigh( + _Symbol, + _Period, + sharpHHIdx + ); + + // + int sharpLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + sharpDetectionLength, + bar_index + ); + double sharpLL = iLow( + _Symbol, + _Period, + sharpLLIdx + ); + + // + double sharpDiff = sharpHH - sharpLL; + bool isSharpOccered = + sharpDiff > sharpDetectionValue; + + // + XRMarketState lastState = GetXRMarketState( + bar_index + sharpDetectionLength + ); + + // + double stateFSDiff = (state0.fast - state0.slow) - (lastState.fast - lastState.slow); + + // + // Start Calculating Long Conditions ... + bool longCondition1 = + // + // Starter ... + true + // + && isMarketBullish + // + && + ( + candle2.high < range2.mid + || ( + candle2.high > range2.mid + && candle2.low < range2.mid + ) + ) + && candle1.low > range1.mid + ; + + // + if ( + // + ( + longCondition1 + ) + // + && xRLongConds.startTime == 0 + && xRLongConds.entryTime == 0 + && xRLongConds.signalTime == 0 + ) { + // + xRLongConds.startTime = barTime; + xRLongConds.entryTime = barTime; + xRLongConds.signalTime = barTime; + + // + return; + } +} + +// +// Check and Fill Short Signal Conditions ... +void CheckXRShortSignalConditions( + const int bar_index +) { + // + if ( + !enableXRShort + || !enableXRSignalling + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Read Prices ... + XPrice prices = GetPrice(); + + // + // Read XPVTState ... + XPvtState pvt0 = GetPVTState( + bar_index, + xRSwingLength + ); + + // + // Double Length Pivots ... + XPvtState dblPvt0 = GetPVTState( + bar_index, + (xRSwingLength * 2) + ); + + // + // Reading Required Candles ... + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + XOHCL candle3 = GetCandleModel(bar_index + 3); + + // + // Reding Required XRMarketStates ... + XRMarketState state0 = GetXRMarketState(bar_index); + XRMarketState state1 = GetXRMarketState(bar_index + 1); + XRMarketState state2 = GetXRMarketState(bar_index + 2); + XRMarketState state3 = GetXRMarketState(bar_index + 3); + + // + // Reading required XRangeStates ... + XRState range0 = ReadXRange( + bar_index + xRSwingLength, + xRSwingLength + ); + XRState range1 = ReadXRange( + bar_index + xRSwingLength + 1, + xRSwingLength + ); + XRState range2 = ReadXRange( + bar_index + xRSwingLength + 2, + xRSwingLength + ); + + // + XRState cRange0 = ReadXRange( + bar_index, + xRSwingLength + ); + + // + // Validate Farest Range Values ... + if ( + range2.hh == 0 + || + range2.ll == 0 + || + range2.mid == 0 + ) { + return; + } + + // + // Reading Required XTPowStates ... + XTPOWState tPow0 = GetXTPowState( + bar_index, + xRSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xRSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xRSwingLength + ); + + // + // if state verifier below range middle + // this means market is bullish ... + // + // if state verifier above range middle + // this means market is bearish ... + // + + // + bool isMarketBullish = + state0.verifier < range0.mid + && state1.verifier < range1.mid; + bool isMarketBearish = + state0.verifier > range0.mid + && state1.verifier > range1.mid; + bool isMarketGoingBullish = + state0.verifier > range0.mid + && !(state1.verifier > range1.mid); + bool isMarketGoingBearish = + state0.verifier < range0.mid + && !(state1.verifier < range1.mid); + + // + // Check Highest High Conditions ... + bool isHHVerified = + !( + pvt0.hh == dblPvt0.hh + ) + ; + + // + int sharpDetectionLength = 7; + double sharpDetectionValue = xRSharpDetectionFactor * _Point; + + // + int sharpHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + sharpDetectionLength, + bar_index + ); + double sharpHH = iHigh( + _Symbol, + _Period, + sharpHHIdx + ); + + // + int sharpLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + sharpDetectionLength, + bar_index + ); + double sharpLL = iLow( + _Symbol, + _Period, + sharpLLIdx + ); + + // + double sharpDiff = sharpHH - sharpLL; + bool isSharpOccered = + sharpDiff > sharpDetectionValue; + + // + XRMarketState lastState = GetXRMarketState( + bar_index + sharpDetectionLength + ); + + // + double stateFSDiff = (state0.fast - state0.slow) - (lastState.fast - lastState.slow); + + // + // Start Calculating Long Conditions ... + bool shortCondition1 = + // + // Starter ... + true + // + && isMarketBearish + // + && + ( + candle2.low > range2.mid + || ( + candle2.high > range2.mid + && candle2.low < range2.mid + ) + ) + && candle1.high < range1.mid + ; + + // + if ( + // + ( + shortCondition1 + ) + // + && xRShortConds.startTime == 0 + && xRShortConds.entryTime == 0 + && xRShortConds.signalTime == 0 + ) { + // + xRShortConds.startTime = barTime; + xRShortConds.entryTime = barTime; + xRShortConds.signalTime = barTime; + + // + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXRSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if ( + !enableXRSignalling + || !(enableXRLong || enableXRShort) + ) { + return result; + } + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + if (requestLong) { + // + if ( + !ValidateXRLongConditions() + ) { + return result; + } + } else { + // + if ( + !ValidateXRShortConditions() + ) { + return result; + } + } + + // + // Price Calculations ... + XPvtState pvts = GetPVTState( + bar_index, + xRSwingLength + ); + XPrice prices = GetPrice(); + + // + double entryPrice = requestLong ? + prices.longEntry : + prices.shortEntry + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = requestLong ? + MathMin(openPrice, closePrice) - pvts.ll : + pvts.hh - MathMax(openPrice, closePrice); + if (risk <= 0) { + // + risk = requestLong ? + MathAbs(pvts.hh - entryPrice) : + MathAbs(pvts.ll - entryPrice) + ; + } + + // + double reward = + requestLong ? + risk * xRLongR2R : + risk * xRShortR2R + ; + + // + double sl = requestLong ? + 0 : + 0; + + // + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward + ; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XR_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XR_PROVIDER; + + // + return result; +} + +// +// Validate Long Signal Conditions ... +bool ValidateXRLongConditions() { + // + if ( + !enableXRLong + || !enableXRSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xRLongConds.startTime > 0 + && xRLongConds.signalTime > 0 + && xRLongConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + isBLFilled = + // + xRLongConds.signalTime >= xRLongConds.startTime + && xRLongConds.entryTime >= xRLongConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xRWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXRLongSignalConditions(); + } + + // + return result; +} + +// +// Validate Short Signal Conditions ... +bool ValidateXRShortConditions() { + // + if ( + !enableXRShort + || !enableXRSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xRShortConds.startTime > 0 + && xRShortConds.signalTime > 0 + && xRShortConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + isBLFilled = + // + xRShortConds.signalTime >= xRShortConds.startTime + && xRShortConds.entryTime >= xRShortConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xRWaitForShortSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXRShortSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXRLongSignalConditions() { + // + xRLongConds.startTime = 0; + xRLongConds.signalTime = 0; + xRLongConds.entryTime = 0; +} + +// +// Clear Short Signal Conditions for New One ... +void ClearXRShortSignalConditions() { + // + xRShortConds.startTime = 0; + xRShortConds.signalTime = 0; + xRShortConds.entryTime = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForXRSignals( + const XSignal &signal +) { + // + bool result = false; + + // + if ( + !enableXRSignalling + || !(enableXRLong || enableXRShort) + ) { + return result; + } + + // + // Find Signal Bar Index ... + int signalBarIndex = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // Read Prices ... + XPrice prices = GetPrice(); + + // + // Read XPVTState ... + XPvtState pvt0 = GetPVTState( + signalBarIndex, + xRSwingLength + ); + + // + // Reading Required Candles ... + XOHCL candle0 = GetCandleModel(signalBarIndex); + XOHCL candle1 = GetCandleModel(signalBarIndex + 1); + XOHCL candle2 = GetCandleModel(signalBarIndex + 2); + XOHCL candle3 = GetCandleModel(signalBarIndex + 3); + + // + // Reding Required XRMarketStates ... + XRMarketState state0 = GetXRMarketState(signalBarIndex); + XRMarketState state1 = GetXRMarketState(signalBarIndex + 1); + XRMarketState state2 = GetXRMarketState(signalBarIndex + 2); + XRMarketState state3 = GetXRMarketState(signalBarIndex + 3); + + // + // Reading required XRangeStates ... + XRState range0 = ReadXRange( + signalBarIndex + xRSwingLength, + xRSwingLength + ); + XRState range1 = ReadXRange( + signalBarIndex + xRSwingLength + 1, + xRSwingLength + ); + XRState range2 = ReadXRange( + signalBarIndex + xRSwingLength + 2, + xRSwingLength + ); + + // + // Reading Required XTPowStates ... + XTPOWState tPow0 = GetXTPowState( + signalBarIndex, + xRSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + signalBarIndex + 1, + xRSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + signalBarIndex + 2, + xRSwingLength + ); + + // + double hhllDiff = MathAbs(pvt0.hh - pvt0.ll); + double sharpDetectionValue = xRSharpDetectionFactor * _Point; + bool isSharpOccured = hhllDiff > sharpDetectionValue; + + // + // Calculate State Min Max Diff ... + // + double state0Min = MathMin(state0.fast, state0.slow); + state0Min = MathMin(state0Min, state0.open); + state0Min = MathMin(state0Min, state0.rangeFast); + state0Min = MathMin(state0Min, state0.rangeSlow); + state0Min = MathMin(state0Min, state0.rangeOpen); + state0Min = MathMin(state0Min, state0.verifier); + + // + double state0Max = MathMax(state0.fast, state0.slow); + state0Max = MathMax(state0Max, state0.open); + state0Max = MathMax(state0Max, state0.rangeFast); + state0Max = MathMax(state0Max, state0.rangeSlow); + state0Max = MathMax(state0Max, state0.rangeOpen); + state0Max = MathMax(state0Max, state0.verifier); + + // + double state0MinMaxDiff = (state0Max - state0Min); + + // + bool isTPowValid = false; + bool isStateValid = false; + bool isRangeValid = false; + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + // Retrieve TPow Verifications ... + isTPowValid = + // + // Starter ... + true + ; + + // + // Retrieve XMarket Verifications ... + isStateValid = + // + // Starter ... + true + // + // && !(state0MinMaxDiff > sharpDetectionValue) + ; + + // + // Retrieve XRange Verifications ... + isRangeValid = + // + // Starter ... + true + ; + + // + result = + // + // Starter ... + true + // + && isTPowValid + && isStateValid + && isRangeValid + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + // Retrieve TPow Verifications ... + isTPowValid = + // + // Starter ... + true + ; + + // + // Retrieve XMarket Verifications ... + isStateValid = + // + // Starter ... + true + ; + + // + // Retrieve XRange Verifications ... + isRangeValid = + // + // Starter ... + true + ; + + // + result = + // + // Starter ... + true + // + && isTPowValid + && isStateValid + && isRangeValid + ; + } + + // + return result; +} +// +// END Functions ... +// + +// +// START Data Providers ... +// +// +XRMarketState GetXRMarketState( + const int bar_index +) { + // + XRMarketState result = {}; + + // + // Calculate Market Lengths ... + + // + if (fastLength == 0) { + fastLength = xRSwingLength; + } + + // + if (slowLength == 0) { + slowLength = xRSwingLength * 2; + } + + // + if (verifierLength == 0) { + verifierLength = (GetDailyCandleCount() * 2); + } + + // + if (rangeFastLength == 0) { + rangeFastLength = (int)(verifierLength / 2); + } + + // + if (rangeSlowLength == 0) { + rangeSlowLength = verifierLength; + } + + // + // Reading Values ... + + // + double fast = GetMA( + bar_index, + fastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double slow = GetMA( + bar_index, + slowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double open = GetMA( + bar_index, + fastLength, + 0, + MODE_SMA, + PRICE_OPEN + ); + + // + double rangeFast = GetMA( + bar_index, + rangeFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double rangeSlow = GetMA( + bar_index, + rangeSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double rangeOpen = GetMA( + bar_index, + rangeFastLength, + 0, + MODE_SMA, + PRICE_OPEN + ); + + // + double verifier = GetMA( + bar_index, + verifierLength, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + // Filling Result ... + result.fast = fast; + result.slow = slow; + result.open = open; + result.verifier = verifier; + result.rangeFast = rangeFast; + result.rangeSlow = rangeSlow; + result.rangeOpen = rangeOpen; + + // + return result; +} +// +// END Data Providers ... +// \ No newline at end of file diff --git a/Bkp/XAUUSD-15M/Libraries/x-saherelm.xtpw.signal.lib.mq4 b/Bkp/XAUUSD-15M/Libraries/x-saherelm.xtpw.signal.lib.mq4 new file mode 100644 index 0000000..4bf02ce --- /dev/null +++ b/Bkp/XAUUSD-15M/Libraries/x-saherelm.xtpw.signal.lib.mq4 @@ -0,0 +1,1332 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 XTPW Signal Global Library +// --------------------------------------------------- +// XSaherElm EA Signal Provider based on +// XTPow Indicator... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Inputs ... +// +// +input string xTPWStarter = "- XTPW Signal Provider -"; // ---> XTPW Signal Provider <--- + +// +input bool enableXTPWSignalling = true; // XTPW Signalling Enable + +// +input bool enableXTPWLong = true; // XTPW Signalling Enable Long +input bool enableXTPWShort = true; // XTPW Signalling Enable Short + +// +input double xTPWShortR2R = 2; // XTPW Short Risk To Reward Ratio +input double xTPWShortLotsPerTradePercent = 0.0002; // XTPW Lots Percent per Short Trades +input double xTPWShortMaxDrawdownPerTradePercent = 0.3; // XTPW Max Allowed DrawDown Percent per Short Trade + +// +input double xTPWLongR2R = 2; // XTPW Long Risk To Reward Ratio +input double xTPWLongLotsPerTradePercent = 0.0002; // XTPW Lots Percent per Short Trades +input double xTPWLongMaxDrawdownPerTradePercent = 0.3; // XTPW Max Allowed DrawDown Percent per Long Trade + +// +input int xTPWMaximumCandlesPerTrade = 206; // XTPW Maximum Candles which a Trade can open + +// +input double xTPWPSarStep = 0.02; // XTPW Parabolic Sar Step +input double xTPWPSarMaximum = 0.2; // XTPW Parabolic Sar Maximum + +// +input int xTPWSwingLength = 7; // XTPW Signal Swing Length +// +// END Inputs ... +// + +// +input double xTPWSharpDetectionFactor = 650; // XTPW Sharp Detection Factor + +// +// START Global Requirement Functions ... +// +// +// XTPW Based Signal Conditions ... +struct XTPWSignalConditions { + datetime startTime; + datetime signalTime; + datetime entryTime; +}; + +// +struct XTPWMarketState { + // + double psar; + + // + double scFast; + double scSlow; + double scWeight; + + // + double mcFast; + double mcSlow; + double mcWeight; + + // + double lcFast; + double lcSlow; + double lcWeight; +}; + +// +struct XLHS { + // + double scHH; + double scLL; + + // + double mcHH; + double mcLL; + + // + double lcHH; + double lcLL; +}; + +// +static XTPWSignalConditions xTPWLongConds; +static bool xTPWCloseLongTrades = false; +static bool xTPWWaitForLongSignals = true; + +// +static XTPWSignalConditions xTPWShortConds; +static bool xTPWCloseShortTrades = false; +static bool xTPWWaitForShortSignals = true; + +// +// Count Number of Closed Maximum DrawDown Trades ... +static int xTPWFailedSignals = 0; + +// +double tPowerVerifier = 20; +double tPowerMaxVerifier = 55; + +// +int scFastLength = 0; +int scSlowLength = 0; + +// +int mcFastLength = 0; +int mcSlowLength = 0; + +// +int lcFastLength = 0; +int lcSlowLength = 0; + +// +datetime lastTurnOffLongTradesTime; +datetime lastTurnOffShortTradesTime; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckXTPWSignalHandler( + const int bar_index +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + + // + if ( + !enableXTPWSignalling + || !(enableXTPWLong || enableXTPWShort) + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 1); + + // + XTPOWState tPow0 = GetXTPowState( + bar_index, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xTPWSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xTPWSwingLength + ); + + // + XTPWMarketState state0 = GetXTPWMarketState( + bar_index + ); + XTPWMarketState state1 = GetXTPWMarketState( + bar_index + 1 + ); + XTPWMarketState state2 = GetXTPWMarketState( + bar_index + 2 + ); + + // // + // // Disable Long Conditions ... + // if ( + // xTPWWaitForLongSignals + // && + // ( + // isRangeCrossOverRangeWeight + // || + // isRangeCrossUnderRangeWeight + // || + // isTPowUpperAboveMaxVerifier + // ) + // ) { + // // + // xTPWWaitForLongSignals = false; + // lastTurnOffLongTradesTime = barTime; + // } + + // // + // // Enable Long Conditions ... + // if ( + // !xTPWWaitForLongSignals + // && lastTurnOffLongTradesTime > 0 + // && ( + // // isFastCrossOverSlow + // // || + // // isFastCrossUnderSlow + // isRangeCrossOverRangeWeight + // || + // isRangeCrossUnderRangeWeight + // || + // isTPowUpperBelowMaxVerifier + // ) + // ) { + // // + // // Find Last Turn Off Bar Index ... + // int lastTurnOffLongTradesBarIndex = iBarShift( + // _Symbol, + // _Period, + // lastTurnOffLongTradesTime + // ); + + // // + // // the Distance must be bigger than market length ... + // if (MathAbs(lastTurnOffLongTradesBarIndex - bar_index) > xTPWSwingLength) { + // // + // xTPWWaitForLongSignals = true; + // lastTurnOffLongTradesTime = 0; + // } + // } +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXTPWLongSignalConditions( + const int bar_index +) { + // + if ( + !enableXTPWLong + || !enableXTPWSignalling + || !xTPWWaitForLongSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Retrieve TPow States ... + XTPOWState tPow0 = GetXTPowState( + bar_index, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xTPWSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xTPWSwingLength + ); + + // + // Retrieve TPowMarket State ... + XTPWMarketState state0 = GetXTPWMarketState( + bar_index + ); + XTPWMarketState state1 = GetXTPWMarketState( + bar_index + 1 + ); + XTPWMarketState state2 = GetXTPWMarketState( + bar_index + 2 + ); + + // + // Retrieve XPrice Model ... + XPrice prices = GetPrice(); + + // + // Retrieve Candles ... + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + + // + XLHS lhs = GetXTPWLHS(bar_index); + + // + bool isHHSame = + lhs.scHH == lhs.mcHH + && lhs.mcHH == lhs.lcHH + ; + + // + bool isLLSame = + lhs.scLL == lhs.mcLL + && lhs.mcLL == lhs.lcLL + ; + + // + bool startCondition = false; + bool signalCondition = false; + bool entryCondition = false; + + // + bool longCondition1 = + // + true + // + && !isHHSame + // + && !( + lhs.scLL == lhs.mcLL + ) + // + && !( + lhs.scHH == lhs.mcHH + ) + // + && !( + prices.longEntry + && candle0.high < state0.scFast + && candle0.high < state0.scSlow + && candle0.high < state0.mcFast + && candle0.high < state0.mcSlow + && candle0.high < state0.lcFast + && candle0.high < state0.lcSlow + ) + // + && tPow0.powerDown > tPowerMaxVerifier + && tPow1.powerDown > tPowerMaxVerifier + && tPow0.powerDown < MathMax(tPow1.powerUp, tPow1.powerDown) + && MathMax(tPow1.powerUp, tPow1.powerDown) > tPowerMaxVerifier + ; + + // + // Start Conditions ... + startCondition = ( + longCondition1 + ) + ; + + // + if ( + startCondition + && xTPWLongConds.startTime == 0 + && xTPWLongConds.signalTime == 0 + && xTPWLongConds.entryTime == 0 + ) { + // + xTPWLongConds.startTime = barTime; + xTPWLongConds.signalTime = barTime; + xTPWLongConds.entryTime = barTime; + + // + return; + } +} + +// +// Check and Fill Short Signal Conditions ... +void CheckXTPWShortSignalConditions( + const int bar_index +) { + // + if ( + !enableXTPWShort + || !enableXTPWSignalling + || !xTPWWaitForShortSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Retrieve TPower State ... + XTPOWState tPow0 = GetXTPowState( + bar_index, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xTPWSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xTPWSwingLength + ); + + // + // Retrieve TPWMarket State ... + XTPWMarketState state0 = GetXTPWMarketState( + bar_index + ); + XTPWMarketState state1 = GetXTPWMarketState( + bar_index + 1 + ); + XTPWMarketState state2 = GetXTPWMarketState( + bar_index + 2 + ); + + // + // Retrieve Candles ... + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + + // + XPrice prices = GetPrice(); + XLHS lhs = GetXTPWLHS(bar_index); + + // + double sharpDetectionValue = + xTPWSharpDetectionFactor * _Point; + + // + bool isHHSame = + lhs.scHH == lhs.mcHH + && lhs.mcHH == lhs.lcHH + ; + + // + bool isLLSame = + lhs.scLL == lhs.mcLL + && lhs.mcLL == lhs.lcLL + ; + + // + bool startCondition = false; + bool signalCondition = false; + bool entryCondition = false; + + // + bool shortCondition1 = + // + true + // + && tPow1.powerDown > tPowerMaxVerifier + && tPow2.powerDown < tPowerMaxVerifier + ; + + // + startCondition = ( + shortCondition1 + ) + ; + + // + if ( + startCondition + && xTPWShortConds.startTime == 0 + && xTPWShortConds.signalTime == 0 + && xTPWShortConds.entryTime == 0 + ) { + // + xTPWShortConds.startTime = barTime; + xTPWShortConds.signalTime = barTime; + xTPWShortConds.entryTime = barTime; + + // + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXTPWSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if ( + !enableXTPWSignalling + || !(enableXTPWLong || enableXTPWShort) + ) { + return result; + } + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + // Check Condition Validations ... + if (requestLong) { + // + // Check Long Condtion is Valid, if Long Requested ... + if ( + !ValidateXTPWLongConditions() + ) { + return result; + } + } else { + // + // Check Short Condtion is Valid, if Short Requested ... + if ( + !ValidateXTPWShortConditions() + ) { + return result; + } + } + + // + double ll = + // + GetMarketLowestLow( + bar_index, + xTPWSwingLength + ) + ; + + // + double hh = + // + GetMarketHighestHigh( + bar_index, + xTPWSwingLength + ) + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + // Price Calculations ... + XPrice prices = GetPrice(); + + // + // Read State ... + XTPWMarketState state0 = GetXTPWMarketState(bar_index); + + // + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + XOHCL candle3 = GetCandleModel(bar_index + 2); + + // + double risk = requestLong ? + // + MathMin(openPrice, closePrice) - ll : + hh - MathMax(openPrice, closePrice) + ; + + // + double longR2R = xTPWLongR2R; + double shortR2R = xTPWShortR2R; + + // + double sharpDetectorValue = xTPWSharpDetectionFactor * _Point; + + // + if ( + risk > 0 + && requestLong + ) { + return result; + } + + // + // Define Entry Price ... + double entryPrice = requestLong + ? + prices.longEntry + : + prices.shortEntry + ; + + // + // Fix TP Detects for Short Signals ... + if (!requestLong) { + risk = 0; + } + + // + double reward = requestLong ? + risk * longR2R : + risk * shortR2R + ; + + // + if (risk == 0) { + // + // Calculate Reward ... + reward = requestLong + ? + MathAbs(hh - entryPrice) + : + MathAbs(hh - entryPrice) + ; + + // + // Detect Sharp Change Occured or not ... + bool isSharpOccured = reward > sharpDetectorValue + || MathAbs(reward - sharpDetectorValue) < (50 * _Point); + + // + // Change Rewards on Special Conditions ... + if ( + ( + requestLong + && isSharpOccured + && ( + state0.lcFast < state0.lcSlow + || ( + state0.mcFast > state0.mcSlow + && state0.mcWeight < state0.mcSlow + ) + ) + ) + ) { + reward = reward / 2; + } + + // + if (reward < 50 * _Point) { + reward = (50 * _Point) + prices.priceGap; + } + + // // + // if (!requestLong) { + // reward = reward * shortR2R; + // } + } + + // + double sl = requestLong ? + 0 : + 0; + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward + ; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XTPW_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XTPW_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXTPWLongConditions() { + // + if ( + !enableXTPWLong + || !enableXTPWSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xTPWLongConds.startTime > 0 + && xTPWLongConds.signalTime > 0 + && xTPWLongConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // // + // int startBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWLongConds.startTime + // ); + + // // + // int signalBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWLongConds.signalTime + // ); + + // // + // int entryBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWLongConds.entryTime + // ); + + // // + // int startSignalDiff = (signalBarIndex - startBarIndex); + // int entrySignalDiff = (entryBarIndex - signalBarIndex); + // int maxDiff = MathMax(startSignalDiff, entrySignalDiff); + + // + isBLFilled = + // + // Starter ... + true + // + && xTPWLongConds.signalTime >= xTPWLongConds.startTime + && xTPWLongConds.entryTime >= xTPWLongConds.signalTime + // + // && maxDiff < (xTPWSwingLength * 2) + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xTPWWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXTPWLongSignalConditions(); + } + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXTPWShortConditions() { + // + if ( + !enableXTPWShort + || !enableXTPWSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xTPWShortConds.startTime > 0 + && xTPWShortConds.signalTime > 0 + && xTPWShortConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // // + // int startBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWShortConds.startTime + // ); + + // // + // int signalBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWShortConds.signalTime + // ); + + // // + // int entryBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWShortConds.entryTime + // ); + + // + isBLFilled = + // + // Starter ... + true + // + && xTPWShortConds.signalTime >= xTPWShortConds.startTime + && xTPWShortConds.entryTime >= xTPWShortConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xTPWWaitForShortSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXTPWShortSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXTPWLongSignalConditions() { + // + xTPWLongConds.startTime = 0; + xTPWLongConds.entryTime = 0; + xTPWLongConds.signalTime = 0; +} + +// +// Clear Short Signal Conditions for New One ... +void ClearXTPWShortSignalConditions() { + // + xTPWShortConds.startTime = 0; + xTPWShortConds.entryTime = 0; + xTPWShortConds.signalTime = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForXTPWSignals( + const XSignal &signal +) { + // + bool result = false; + + // + if ( + !enableXTPWSignalling + || !(enableXTPWLong || enableXTPWShort) + ) { + return result; + } + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // XOHCL candle = GetCandleModel(0); + XOHCL candle0 = GetCandleModel(signalBarIndex); + XOHCL candle1 = GetCandleModel(signalBarIndex + 1); + + // + // Retrieve TPow State ... + XTPOWState tPow0 = GetXTPowState( + signalBarIndex, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + signalBarIndex + 1, + xTPWSwingLength + ); + + // + // Retrive XMarket States ... + XTPWMarketState state0 = GetXTPWMarketState(signalBarIndex); + XTPWMarketState state1 = GetXTPWMarketState(signalBarIndex + 1); + XTPWMarketState state2 = GetXTPWMarketState(signalBarIndex + 2); + + // + bool isPSarVerified = false; + bool isTPowVerified = false; + bool isStateVerified = false; + bool isPriceVerified = false; + + // + // Calculate Sharp Detection Value ... + double sharpDetectionValue = + xTPWSharpDetectionFactor * _Point; + + // + // Find State0 Min ... + double state0Min = MathMin(state0.scFast, state0.scSlow); + state0Min = MathMin(state0Min, state0.mcFast); + state0Min = MathMin(state0Min, state0.mcSlow); + state0Min = MathMin(state0Min, state0.lcFast); + state0Min = MathMin(state0Min, state0.lcSlow); + + // + // Find State0 Min ... + double state0Max = MathMax(state0.scFast, state0.scSlow); + state0Max = MathMax(state0Max, state0.mcFast); + state0Max = MathMax(state0Max, state0.mcSlow); + state0Max = MathMax(state0Max, state0.lcFast); + state0Max = MathMax(state0Max, state0.lcSlow); + + // + // Find Distance Between State0 Min and Max ... + double state0MinMaxDistance = MathAbs(state0Max - state0Min); + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + // Get Price Verification for Long ... + isPriceVerified = + // + // Starter ... + true + // + ; + + // + isTPowVerified = + // + // Starter ... + true + // + && tPow0.powerDown > tPowerMaxVerifier + && tPow1.powerDown > tPowerMaxVerifier + && tPow0.powerDown < MathMax(tPow1.powerUp, tPow1.powerDown) + && MathMax(tPow1.powerUp, tPow1.powerDown) > tPowerMaxVerifier + ; + + // + isPSarVerified = + // + // Starter ... + true + // + ; + + // + isStateVerified = + // + // Start ... + true + // + && state0.mcFast > state0.mcSlow + && state1.mcFast > state1.mcSlow + // + && !( + state0.lcFast > state0.mcSlow + && state0.lcFast < state0.mcFast + ) + // + && MathAbs(state1.mcFast - state1.mcSlow) > (50 * _Point) + ; + + // + result = + // + // Starter ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + isPSarVerified = + // + // Starter ... + true + ; + + // + // Get Price Verification for Short ... + isPriceVerified = + // + // Starter ... + true + ; + + // + isTPowVerified = + // + // Starter ... + true + // + && tPow0.signal > MathMax(tPow0.powerUp, tPow0.powerDown) + ; + + // + isStateVerified = + // + // Start ... + true + // + && ( + // + state0.scFast < state0.scSlow + && state0.mcFast < state0.mcSlow + && state0.lcFast < state0.lcSlow + ? + signal.entry > state0.scFast + : + // + // Find Minimum and Maximum Distance of State ... + state0MinMaxDistance > sharpDetectionValue + ? + signal.entry > state0Min + : + true + ) + // + && MathAbs(state0.mcFast - state0.mcSlow) > 50 * _Point + ; + + // + result = + // + // Starter Condition ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } + + // + return result; +} +// +// END Functions ... +// + +// +// START Data Provider ... +// +// +// Retrieve Market State ... +XTPWMarketState GetXTPWMarketState( + const int bar_index +) { + // + XTPWMarketState result = {}; + + // + int dayCount = GetDailyCandleCount(); + int halfDayCount = (int)(dayCount / 2); + + // + if (scFastLength == 0) { + scFastLength = xTPWSwingLength; + } + + // + if (scSlowLength == 0) { + scSlowLength = xTPWSwingLength * 2; + } + + // + if (mcFastLength == 0) { + mcFastLength = halfDayCount; + } + + // + if (mcSlowLength == 0) { + mcSlowLength = dayCount; + } + + // + if (lcFastLength == 0) { + lcFastLength = halfDayCount * 3; + } + + // + if (lcSlowLength == 0) { + lcSlowLength = dayCount * 3; + } + + // + double scFast = GetMA( + bar_index, + scFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double scSlow = GetMA( + bar_index, + scSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double scWeight = GetMA( + bar_index, + scSlowLength, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double mcFast = GetMA( + bar_index, + mcFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double mcSlow = GetMA( + bar_index, + mcSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double mcWeight = GetMA( + bar_index, + mcSlowLength, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double lcFast = GetMA( + bar_index, + lcFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double lcSlow = GetMA( + bar_index, + lcSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double lcWeight = GetMA( + bar_index, + lcSlowLength, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double psar = iSAR( + _Symbol, + _Period, + xTPWPSarStep, + xTPWPSarMaximum, + bar_index + ); + + // + result.psar = psar; + result.scFast = scFast; + result.scSlow = scSlow; + result.mcFast = mcFast; + result.mcSlow = mcSlow; + result.lcFast = lcFast; + result.lcSlow = lcSlow; + result.scWeight = scWeight; + result.mcWeight = mcWeight; + result.lcWeight = lcWeight; + + // + return result; +} + +// +// Retrieve Highest Highs and Lowest Lows in Cycles ... +XLHS GetXTPWLHS( + const int bar_index +) { + // + XLHS result = {}; + + // + // Retrieve LL and HH (s) ... + + // + // SC HH ... + double scHH = GetMarketHighestHigh( + bar_index, + scFastLength + ); + + // + // SC LL ... + double scLL = GetMarketHighestHigh( + bar_index, + scFastLength + ); + + // + // MC HH ... + double mcHH = GetMarketHighestHigh( + bar_index, + mcFastLength + ); + + // + // MC LL ... + double mcLL = GetMarketHighestHigh( + bar_index, + mcFastLength + ); + + // + // LC HH ... + double lcHH = GetMarketHighestHigh( + bar_index, + lcFastLength + ); + + // + // LC LL ... + double lcLL = GetMarketHighestHigh( + bar_index, + lcFastLength + ); + + // + result.scHH = scHH; + result.scLL = scLL; + result.mcHH = mcHH; + result.mcLL = mcLL; + result.lcHH = lcHH; + result.lcLL = lcLL; + + // + return result; +} +// +// END Data Provider ... +// diff --git a/Docs/Reports/14020412/OSC XMA 15Min Long/Only OSC/StrategyTester_1.gif b/Docs/Reports/14020412/OSC XMA 15Min Long/Only OSC/StrategyTester_1.gif new file mode 100644 index 0000000..64e458f Binary files /dev/null and b/Docs/Reports/14020412/OSC XMA 15Min Long/Only OSC/StrategyTester_1.gif differ diff --git a/Docs/Reports/14020412/OSC XMA 15Min Long/Only OSC/StrategyTester_1.htm b/Docs/Reports/14020412/OSC XMA 15Min Long/Only OSC/StrategyTester_1.htm new file mode 100644 index 0000000..9cf344a --- /dev/null +++ b/Docs/Reports/14020412/OSC XMA 15Min Long/Only OSC/StrategyTester_1.htm @@ -0,0 +1,762 @@ + + + + Strategy Tester: x-saherelm.osc.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.osc.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2023.01.03 01:00 - 2023.06.28 23:45 (2023.01.01 - 2023.06.29)
ModelEvery tick (the most precise method based on all available least timeframes)
Bars in test12551Ticks modelled15360882Modelling qualityn/a
Mismatched charts errors1395
Initial deposit1000.00SpreadCurrent (50)
Total net profit223.50Gross profit1480.53Gross loss-1257.03
Profit factor1.18Expected payoff0.63
Absolute drawdown66.94Maximal drawdown434.20 (31.15%)Relative drawdown31.15% (434.20)
Total trades353Short positions (won %)0 (0.00%)Long positions (won %)353 (89.80%)
Profit trades (% of total)317 (89.80%)Loss trades (% of total)36 (10.20%)
Largestprofit trade33.12loss trade-82.64
Averageprofit trade4.67loss trade-34.92
Maximumconsecutive wins (profit in money)80 (449.04)consecutive losses (loss in money)5 (-149.41)
Maximalconsecutive profit (count of wins)449.04 (80)consecutive loss (count of losses)-225.40 (4)
Averageconsecutive wins26consecutive losses3
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12023.01.03 01:15buy10.011827.450.001843.83
22023.01.03 04:15buy20.011829.930.001835.55
32023.01.03 04:40t/p20.011835.550.001835.555.621005.62
42023.01.03 08:18t/p10.011843.830.001843.8316.381022.00
52023.01.03 11:30buy30.011841.650.001855.25
62023.01.03 12:00buy40.011839.080.001847.54
72023.01.03 14:30buy50.011835.760.001845.00
82023.01.03 16:33t/p50.011845.000.001845.009.241031.24
92023.01.03 16:40t/p40.011847.540.001847.548.461039.70
102023.01.03 18:45buy60.011831.470.001838.67
112023.01.03 19:43t/p60.011838.670.001838.677.201046.90
122023.01.04 02:45buy70.011838.470.001842.41
132023.01.04 03:42t/p70.011842.410.001842.413.941050.84
142023.01.04 09:32t/p30.011855.250.001855.2513.601064.44
152023.01.04 15:30buy80.011859.480.001872.26
162023.01.04 17:43buy90.011858.070.001872.79
172023.01.04 18:15buy100.011859.520.001879.82
182023.01.04 22:13buy110.011852.910.001863.57
192023.01.04 23:00close110.011855.120.001863.572.211066.65
202023.01.04 23:00buy120.011855.620.001866.04
212023.01.05 04:48close120.011855.910.001866.040.291066.94
222023.01.05 04:48buy130.011856.410.001859.81
232023.01.06 17:07t/p130.011859.810.001859.813.401070.34
242023.01.09 03:38t/p80.011872.260.001872.2612.781083.12
252023.01.09 03:42t/p90.011872.790.001872.7914.721097.84
262023.01.09 09:17t/p100.011879.820.001879.8220.301118.14
272023.01.09 14:08buy140.011873.920.001879.06
282023.01.09 16:00buy150.011878.500.001889.38
292023.01.09 16:03t/p140.011879.060.001879.065.141123.28
302023.01.09 18:45buy160.011876.880.001885.72
312023.01.09 20:30buy170.011873.710.001882.41
322023.01.09 21:08buy180.011873.080.001877.60
332023.01.09 21:45close180.011873.900.001877.600.821124.10
342023.01.09 21:45close170.011873.900.001882.410.191124.29
352023.01.09 21:45buy190.011874.400.001882.66
362023.01.09 23:42buy200.011871.550.001875.43
372023.01.10 03:30close200.011873.400.001875.431.851126.14
382023.01.10 03:30buy210.011873.900.001885.50
392023.01.10 19:45close210.011875.230.001885.501.331127.47
402023.01.10 19:45close190.011875.230.001882.660.831128.30
412023.01.10 19:45buy220.011875.730.001884.15
422023.01.10 20:48buy230.011875.450.001880.99
432023.01.10 23:00close230.011877.930.001880.992.481130.78
442023.01.10 23:00close220.011877.930.001884.152.201132.98
452023.01.10 23:00close160.011877.930.001885.721.051134.03
462023.01.10 23:00buy240.011878.430.001883.37
472023.01.10 23:30buy250.011877.800.001880.92
482023.01.11 02:00buy260.011877.490.001878.97
492023.01.11 07:11t/p260.011878.970.001878.971.481135.51
502023.01.11 07:33t/p250.011880.920.001880.923.121138.63
512023.01.11 07:37t/p240.011883.370.001883.374.941143.57
522023.01.11 15:45buy270.011880.230.001888.51
532023.01.11 18:46buy280.011873.780.001885.52
542023.01.12 01:15buy290.011877.590.001880.31
552023.01.12 03:57t/p290.011880.310.001880.312.721146.29
562023.01.12 13:13t/p280.011885.520.001885.5211.741158.03
572023.01.12 14:22t/p270.011888.510.001888.518.281166.31
582023.01.12 14:23t/p150.011889.380.001889.3810.881177.19
592023.01.12 15:45buy300.011892.180.001925.30
602023.01.12 18:00buy310.011889.130.001907.11
612023.01.13 08:30buy320.011895.510.001901.27
622023.01.13 09:45buy330.011897.320.001903.56
632023.01.13 10:08t/p320.011901.270.001901.275.761182.95
642023.01.13 10:12t/p330.011903.560.001903.566.241189.19
652023.01.13 10:42t/p310.011907.110.001907.1117.981207.17
662023.01.13 15:41buy340.011899.570.001908.39
672023.01.13 16:47t/p340.011908.390.001908.398.821215.99
682023.01.16 04:31t/p300.011925.300.001925.3033.121249.11
692023.01.16 15:55buy350.011914.440.001919.66
702023.01.16 16:30buy360.011914.600.001920.40
712023.01.16 20:00buy370.011914.160.001916.24
722023.01.17 01:05t/p370.011916.240.001916.242.081251.19
732023.01.17 04:15buy380.011915.870.001921.35
742023.01.17 09:45buy390.011910.040.001915.68
752023.01.17 10:45close390.011910.310.001915.680.271251.46
762023.01.17 10:45buy400.011910.810.001917.41
772023.01.17 15:30close400.011911.980.001917.411.171252.63
782023.01.17 15:30buy410.011912.480.001922.68
792023.01.17 18:30close410.011912.600.001922.680.121252.75
802023.01.17 18:30buy420.011913.100.001920.64
812023.01.18 15:30t/p350.011919.660.001919.665.221257.97
822023.01.18 15:30t/p360.011920.400.001920.405.801263.77
832023.01.18 15:30t/p420.011920.640.001920.647.541271.31
842023.01.18 15:31t/p380.011921.350.001921.355.481276.79
852023.01.18 23:30buy430.011904.630.001908.69
862023.01.19 01:06buy440.011904.440.001906.46
872023.01.19 01:51t/p440.011906.460.001906.462.021278.81
882023.01.19 02:33t/p430.011908.690.001908.694.061282.87
892023.01.19 04:30buy450.011903.550.001908.11
902023.01.19 05:07t/p450.011908.110.001908.114.561287.43
912023.01.19 13:00buy460.011909.940.001915.62
922023.01.19 13:30buy470.011909.670.001914.81
932023.01.19 14:08buy480.011909.630.001912.57
942023.01.19 14:45buy490.011910.690.001918.15
952023.01.19 15:30close490.011911.860.001918.151.171288.60
962023.01.19 15:30close480.011911.860.001912.572.231290.83
972023.01.19 15:30close470.011911.860.001914.812.191293.02
982023.01.19 15:30close460.011911.860.001915.621.921294.94
992023.01.19 15:30buy500.011912.360.001922.84
1002023.01.19 17:36t/p500.011922.840.001922.8410.481305.42
1012023.01.20 07:45buy510.011927.080.001934.26
1022023.01.20 10:06t/p510.011934.260.001934.267.181312.60
1032023.01.20 11:30buy520.011931.900.001942.00
1042023.01.20 12:15buy530.011929.300.001934.20
1052023.01.20 13:00buy540.011930.340.001935.18
1062023.01.20 15:03buy550.011929.550.001933.49
1072023.01.23 03:50t/p550.011933.490.001933.493.941316.54
1082023.01.23 04:12t/p530.011934.200.001934.204.901321.44
1092023.01.23 04:18t/p540.011935.180.001935.184.841326.28
1102023.01.23 10:37buy560.011923.900.001930.20
1112023.01.23 15:15buy570.011926.780.001933.48
1122023.01.23 17:31buy580.011918.590.001931.51
1132023.01.23 22:38t/p560.011930.200.001930.206.301332.58
1142023.01.23 22:45t/p580.011931.510.001931.5112.921345.50
1152023.01.24 03:36t/p570.011933.480.001933.486.701352.20
1162023.01.24 10:03t/p520.011942.000.001942.0010.101362.30
1172023.01.24 17:27buy590.011930.540.001952.36
1182023.01.25 01:45buy600.011937.100.001937.96
1192023.01.25 02:03t/p600.011937.960.001937.960.861363.16
1202023.01.25 03:00buy610.011937.140.001940.86
1212023.01.25 08:32buy620.011930.890.001938.43
1222023.01.25 10:27buy630.011931.860.001939.26
1232023.01.25 10:45close620.011931.070.001938.430.181363.34
1242023.01.25 10:45close590.011931.070.001952.360.531363.87
1252023.01.25 10:45buy640.011931.570.001939.29
1262023.01.25 14:38buy650.011926.590.001930.55
1272023.01.25 16:42t/p650.011930.550.001930.553.961367.83
1282023.01.25 19:32t/p630.011939.260.001939.267.401375.23
1292023.01.25 19:32t/p640.011939.290.001939.297.721382.95
1302023.01.25 20:21t/p610.011940.860.001940.863.721386.67
1312023.01.26 03:45buy660.011945.510.001950.81
1322023.01.26 04:15buy670.011946.010.001952.31
1332023.01.26 08:00buy680.011947.760.001952.28
1342023.01.26 10:30buy690.011943.920.001955.06
1352023.02.01 22:02close690.011944.430.001955.060.511387.18
1362023.02.01 22:08close660.011946.020.001950.810.511387.69
1372023.02.01 22:08close670.011946.520.001952.310.511388.20
1382023.02.01 22:31close680.011948.270.001952.280.511388.71
1392023.02.02 13:30buy700.011955.460.001962.46
1402023.02.02 14:16buy710.011955.350.001961.87
1412023.02.03 11:15buy720.011913.840.001919.96
1422023.02.09 18:30close700.011872.820.001962.46-82.641306.07
1432023.02.09 19:15close710.011873.210.001961.87-82.141223.93
1442023.02.10 03:00buy730.011863.180.001869.10
1452023.02.10 04:00buy740.011862.590.001868.75
1462023.02.10 04:45buy750.011863.040.001870.28
1472023.02.10 10:06t/p740.011868.750.001868.756.161230.09
1482023.02.10 10:06t/p730.011869.100.001869.105.921236.01
1492023.02.10 10:08t/p750.011870.280.001870.287.241243.25
1502023.02.10 12:30buy760.011864.280.001871.36
1512023.02.10 13:30buy770.011862.320.001865.36
1522023.02.10 14:43buy780.011865.240.001872.48
1532023.02.10 15:47t/p770.011865.360.001865.363.041246.29
1542023.02.10 16:00buy790.011867.310.001877.81
1552023.02.10 16:15close720.011866.390.001919.96-47.451198.84
1562023.02.10 17:15buy800.011865.270.001877.09
1572023.02.17 17:30close760.011833.960.001871.36-30.321168.52
1582023.02.17 19:30close780.011841.780.001872.48-23.461145.06
1592023.02.17 21:00close790.011841.980.001877.81-25.331119.73
1602023.02.17 22:15close800.011842.420.001877.09-22.851096.88
1612023.02.20 03:03buy810.011839.590.001842.75
1622023.02.20 04:06buy820.011840.900.001846.68
1632023.02.20 04:33t/p810.011842.750.001842.753.161100.04
1642023.02.20 05:45buy830.011842.690.001845.15
1652023.02.20 07:45buy840.011843.690.001848.09
1662023.02.20 08:06t/p830.011845.150.001845.152.461102.50
1672023.02.20 08:30buy850.011843.960.001848.90
1682023.02.20 09:15buy860.011845.180.001849.18
1692023.02.20 10:02t/p820.011846.680.001846.685.781108.28
1702023.02.20 11:00buy870.011844.500.001849.72
1712023.02.20 12:00close840.011843.730.001848.090.041108.32
1722023.02.20 12:00buy880.011844.230.001849.89
1732023.02.20 13:15close850.011844.160.001848.900.201108.52
1742023.02.20 13:15buy890.011844.660.001847.74
1752023.02.20 15:30close890.011845.880.001847.741.221109.74
1762023.02.20 15:30close880.011845.880.001849.891.651111.39
1772023.02.20 15:30close870.011845.880.001849.721.381112.77
1782023.02.20 15:30close860.011845.880.001849.180.701113.47
1792023.02.20 15:30buy900.011846.380.001853.38
1802023.02.20 16:00buy910.011846.710.001854.37
1812023.02.20 18:45buy920.011843.700.001845.84
1822023.02.21 01:15buy930.011842.570.001845.95
1832023.02.21 04:30close930.011842.610.001845.950.041113.51
1842023.02.21 04:30buy940.011843.110.001848.65
1852023.02.27 23:00close900.011816.990.001853.38-29.391084.12
1862023.02.27 23:30close910.011816.780.001854.37-29.931054.19
1872023.02.28 03:15close920.011816.580.001845.84-27.121027.07
1882023.02.28 09:30close940.011811.970.001848.65-31.14995.93
1892023.02.28 11:00buy950.011811.070.001823.15
1902023.02.28 13:45buy960.011810.890.001816.49
1912023.02.28 15:30buy970.011809.700.001812.60
1922023.02.28 15:52t/p970.011812.600.001812.602.90998.83
1932023.02.28 16:45t/p960.011816.490.001816.495.601004.43
1942023.02.28 17:02t/p950.011823.150.001823.1512.081016.51
1952023.03.01 16:00buy980.011837.490.001844.13
1962023.03.01 16:30buy990.011839.010.001848.69
1972023.03.01 16:57t/p980.011844.130.001844.136.641023.15
1982023.03.01 17:30buy1000.011838.590.001848.29
1992023.03.02 04:30buy1010.011836.160.001845.80
2002023.03.02 05:00buy1020.011834.900.001841.80
2012023.03.02 16:45close1020.011835.000.001841.800.101023.25
2022023.03.02 16:45buy1030.011835.500.001845.76
2032023.03.02 23:17close1030.011835.890.001845.760.391023.64
2042023.03.02 23:17buy1040.011836.390.001838.65
2052023.03.03 01:15close1040.011836.520.001838.650.131023.77
2062023.03.03 01:15close1010.011836.520.001845.800.361024.13
2072023.03.03 01:15buy1050.011837.020.001839.76
2082023.03.03 02:03t/p1050.011839.760.001839.762.741026.87
2092023.03.03 13:16t/p1000.011848.290.001848.299.701036.57
2102023.03.03 13:17t/p990.011848.690.001848.699.681046.25
2112023.03.03 18:00buy1060.011845.090.001856.21
2122023.03.06 06:13t/p1060.011856.210.001856.2111.121057.37
2132023.03.06 12:30buy1070.011852.960.001857.04
2142023.03.07 03:30buy1080.011846.530.001850.83
2152023.03.07 09:26t/p1080.011850.830.001850.834.301061.67
2162023.03.08 02:01buy1090.011814.410.001816.13
2172023.03.08 03:32buy1100.011813.370.001814.89
2182023.03.08 06:17buy1110.011811.370.001813.33
2192023.03.08 08:53t/p1110.011813.330.001813.331.961063.63
2202023.03.08 08:53buy1120.011813.830.001818.23
2212023.03.08 09:41t/p1100.011814.890.001814.891.521065.15
2222023.03.08 10:30buy1130.011814.330.001816.53
2232023.03.08 13:15close1130.011815.580.001816.531.251066.40
2242023.03.08 13:15close1120.011815.580.001818.231.751068.15
2252023.03.08 13:15close1090.011815.580.001816.131.171069.32
2262023.03.08 13:15buy1140.011816.080.001823.00
2272023.03.08 14:16buy1150.011815.450.001819.45
2282023.03.08 15:00buy1160.011815.410.001818.91
2292023.03.08 16:32close1160.011816.500.001818.911.091070.41
2302023.03.08 16:32close1150.011816.500.001819.451.051071.46
2312023.03.08 16:32close1140.011816.500.001823.000.421071.88
2322023.03.08 16:32buy1170.011817.000.001819.60
2332023.03.08 16:48t/p1170.011819.600.001819.602.601074.48
2342023.03.08 19:45buy1180.011818.290.001823.63
2352023.03.08 21:15buy1190.011816.200.001821.34
2362023.03.09 01:15buy1200.011815.680.001820.58
2372023.03.09 15:32t/p1200.011820.580.001820.584.901079.38
2382023.03.09 15:33t/p1190.011821.340.001821.345.141084.52
2392023.03.09 15:43t/p1180.011823.630.001823.635.341089.86
2402023.03.09 19:15buy1210.011828.400.001833.62
2412023.03.09 20:43t/p1210.011833.620.001833.625.221095.08
2422023.03.09 23:15buy1220.011831.560.001836.08
2432023.03.09 23:45buy1230.011831.330.001835.39
2442023.03.10 04:15buy1240.011832.700.001837.24
2452023.03.10 10:02t/p1230.011835.390.001835.394.061099.14
2462023.03.10 10:02t/p1220.011836.080.001836.084.521103.66
2472023.03.10 12:15buy1250.011833.580.001838.30
2482023.03.10 13:15buy1260.011835.020.001842.60
2492023.03.10 14:00close1250.011834.790.001838.301.211104.87
2502023.03.10 14:00close1240.011834.790.001837.242.091106.96
2512023.03.10 14:00buy1270.011835.290.001840.79
2522023.03.10 15:32t/p1270.011840.790.001840.795.501112.46
2532023.03.10 15:43t/p1260.011842.600.001842.607.581120.04
2542023.03.10 15:45buy1280.011844.210.001868.45
2552023.03.10 16:35close1070.011853.470.001857.040.511120.55
2562023.03.10 19:15buy1290.011859.600.001869.92
2572023.03.10 22:53t/p1280.011868.450.001868.4524.241144.79
2582023.03.10 23:01t/p1290.011869.920.001869.9210.321155.11
2592023.03.13 04:15buy1300.011876.090.001883.31
2602023.03.13 04:30t/p1300.011883.310.001883.317.221162.33
2612023.03.13 08:15buy1310.011882.210.001891.87
2622023.03.13 10:15buy1320.011878.890.001892.99
2632023.03.13 11:37t/p1310.011891.870.001891.879.661171.99
2642023.03.13 11:40t/p1320.011892.990.001892.9914.101186.09
2652023.03.13 13:30buy1330.011888.130.001902.01
2662023.03.13 14:53t/p1330.011902.010.001902.0113.881199.97
2672023.03.13 19:00buy1340.011909.440.001921.90
2682023.03.14 05:20buy1350.011907.130.001911.61
2692023.03.14 08:16t/p1350.011911.610.001911.614.481204.45
2702023.03.14 16:07buy1360.011905.350.001919.23
2712023.03.14 16:45buy1370.011905.430.001924.89
2722023.03.14 18:45buy1380.011906.720.001915.12
2732023.03.15 13:32t/p1380.011915.120.001915.128.401212.85
2742023.03.15 14:01t/p1360.011919.230.001919.2313.881226.73
2752023.03.15 14:03t/p1340.011921.900.001921.9012.461239.19
2762023.03.15 14:13t/p1370.011924.890.001924.8919.461258.65
2772023.03.15 16:00buy1390.011926.410.001943.85
2782023.03.15 16:45buy1400.011922.870.001933.23
2792023.03.15 17:30buy1410.011926.280.001943.20
2802023.03.15 18:00buy1420.011927.410.001943.71
2812023.03.15 18:23t/p1400.011933.230.001933.2310.361269.01
2822023.03.15 21:12buy1430.011919.750.001933.45
2832023.03.16 11:45close1430.011920.120.001933.450.371269.38
2842023.03.16 11:45buy1440.011920.620.001928.32
2852023.03.16 14:08t/p1440.011928.320.001928.327.701277.08
2862023.03.16 16:15buy1450.011928.890.001939.59
2872023.03.16 16:45close1450.011931.480.001939.592.591279.67
2882023.03.16 16:45close1420.011931.480.001943.714.071283.74
2892023.03.16 16:45close1410.011931.480.001943.205.201288.94
2902023.03.16 16:45close1390.011931.480.001943.855.071294.01
2912023.03.16 16:45buy1460.011931.980.001948.86
2922023.03.16 20:47buy1470.011920.920.001929.86
2932023.03.16 22:30buy1480.011919.600.001921.78
2942023.03.17 00:05buy1490.011920.130.001922.77
2952023.03.17 00:30close1490.011920.170.001922.770.041294.05
2962023.03.17 00:30close1480.011920.170.001921.780.571294.62
2972023.03.17 00:30buy1500.011920.670.001924.39
2982023.03.17 01:00buy1510.011920.330.001922.93
2992023.03.17 03:30close1510.011921.630.001922.931.301295.92
3002023.03.17 03:30close1500.011921.630.001924.390.961296.88
3012023.03.17 03:30close1470.011921.630.001929.860.711297.59
3022023.03.17 03:30buy1520.011922.130.001929.29
3032023.03.17 05:27t/p1520.011929.290.001929.297.161304.75
3042023.03.17 15:12t/p1460.011948.860.001948.8616.881321.63
3052023.03.17 18:45buy1530.011960.110.001969.11
3062023.03.17 19:31t/p1530.011969.110.001969.119.001330.63
3072023.03.17 22:30buy1540.011980.400.001993.04
3082023.03.20 02:02buy1550.011978.210.001982.81
3092023.03.20 07:52t/p1550.011982.810.001982.814.601335.23
3102023.03.20 08:03t/p1540.011993.040.001993.0412.641347.87
3112023.03.21 00:15buy1560.011979.290.001983.23
3122023.03.21 02:15buy1570.011979.540.001985.16
3132023.03.21 02:47buy1580.011978.860.001984.78
3142023.03.21 04:53t/p1560.011983.230.001983.233.941351.81
3152023.03.21 05:32t/p1580.011984.780.001984.785.921357.73
3162023.03.21 15:30buy1590.011965.280.001977.62
3172023.03.22 01:00buy1600.011941.500.001944.64
3182023.03.22 02:45buy1610.011943.740.001946.06
3192023.03.22 03:02t/p1600.011944.640.001944.643.141360.87
3202023.03.22 03:13t/p1610.011946.060.001946.062.321363.19
3212023.03.22 03:45buy1620.011945.010.001949.71
3222023.03.22 05:31buy1630.011941.140.001945.66
3232023.03.22 10:15close1630.011943.300.001945.662.161365.35
3242023.03.22 10:15buy1640.011943.800.001962.26
3252023.03.22 16:48t/p1620.011949.710.001949.714.701370.05
3262023.03.22 20:03t/p1640.011962.260.001962.2618.461388.51
3272023.03.22 20:50t/p1590.011977.620.001977.6212.341400.85
3282023.03.23 01:15buy1650.011966.940.001971.16
3292023.03.23 02:03t/p1650.011971.160.001971.164.221405.07
3302023.03.23 10:15buy1660.011978.440.001984.82
3312023.03.23 12:00buy1670.011978.390.001985.17
3322023.03.23 12:30buy1680.011979.800.001988.88
3332023.03.23 14:15close1670.011978.410.001985.170.021405.09
3342023.03.23 14:15buy1690.011978.910.001985.01
3352023.03.23 15:30close1660.011978.450.001984.820.011405.10
3362023.03.23 15:30buy1700.011978.950.002003.17
3372023.03.23 17:22t/p1690.011985.010.001985.016.101411.20
3382023.03.23 17:22t/p1570.011985.160.001985.165.621416.82
3392023.03.23 18:16t/p1680.011988.880.001988.889.081425.90
3402023.03.23 21:15buy1710.011996.500.002012.82
3412023.03.23 22:00buy1720.011998.160.002017.82
3422023.03.24 02:30buy1730.011994.000.002001.48
3432023.03.24 03:00close1700.011993.560.002003.1714.611440.51
3442023.03.24 03:00buy1740.011994.060.002002.12
3452023.03.24 14:00close1740.011995.620.002002.121.561442.07
3462023.03.24 14:00close1730.011995.620.002001.481.621443.69
3472023.03.24 14:00buy1750.011996.120.002006.46
3482023.03.24 14:30buy1760.011997.220.002009.76
3492023.03.24 16:45close1750.011996.950.002006.460.831444.52
3502023.03.24 16:45close1710.011996.950.002012.820.451444.97
3512023.03.24 16:45buy1770.011997.450.002019.99
3522023.03.24 17:15buy1780.011993.810.002008.41
3532023.03.31 05:00close1720.011982.100.002017.82-16.061428.91
3542023.03.31 12:01buy1790.011976.870.001980.91
3552023.03.31 14:07t/p1790.011980.910.001980.914.041432.95
3562023.03.31 15:45buy1800.011982.210.001993.71
3572023.03.31 20:30close1760.011968.440.002009.76-28.781404.17
3582023.03.31 21:45buy1810.011971.180.001979.18
3592023.03.31 22:45close1770.011969.930.002019.99-27.521376.65
3602023.03.31 23:15close1780.011968.940.002008.41-24.871351.78
3612023.04.03 09:34buy1820.011955.270.001962.69
3622023.04.03 10:15buy1830.011958.850.001974.33
3632023.04.03 11:02t/p1820.011962.690.001962.697.421359.20
3642023.04.03 14:17t/p1830.011974.330.001974.3315.481374.68
3652023.04.03 15:03t/p1810.011979.180.001979.188.001382.68
3662023.04.03 17:15buy1840.011983.360.002004.70
3672023.04.03 21:30buy1850.011985.250.001991.47
3682023.04.03 22:16buy1860.011985.360.001989.58
3692023.04.03 22:45close1860.011985.520.001989.580.161382.84
3702023.04.03 22:45close1850.011985.520.001991.470.271383.11
3712023.04.03 22:45close1840.011985.520.002004.702.161385.27
3722023.04.03 22:45close1800.011985.520.001993.713.311388.58
3732023.04.03 22:45buy1870.011986.020.001993.18
3742023.04.04 01:15buy1880.011985.530.001988.81
3752023.04.04 02:06buy1890.011984.590.001985.05
3762023.04.04 02:38t/p1890.011985.050.001985.050.461389.04
3772023.04.04 03:30buy1900.011984.950.001987.71
3782023.04.04 08:18buy1910.011980.650.001984.97
3792023.04.04 11:00close1910.011982.000.001984.971.351390.39
3802023.04.04 11:00buy1920.011982.500.001992.90
3812023.04.04 13:30close1920.011983.790.001992.901.291391.68
3822023.04.04 13:30buy1930.011984.290.001991.91
3832023.04.04 16:25t/p1900.011987.710.001987.712.761394.44
3842023.04.04 16:32t/p1880.011988.810.001988.813.281397.72
3852023.04.04 16:44t/p1930.011991.910.001991.917.621405.34
3862023.04.04 17:00t/p1870.011993.180.001993.187.161412.50
3872023.04.05 18:45buy1940.012021.120.002042.96
3882023.04.05 21:15buy1950.012022.000.002027.24
3892023.04.05 22:30buy1960.012022.220.002024.76
3902023.04.06 01:45buy1970.012020.650.002023.91
3912023.04.12 15:31close1970.012021.180.002023.910.531413.03
3922023.04.12 15:32close1940.012021.640.002042.960.521413.55
3932023.04.12 15:32close1950.012022.510.002027.240.511414.06
3942023.04.12 15:33close1960.012022.730.002024.760.511414.57
3952023.04.12 18:00buy1980.012007.810.002019.03
3962023.04.12 19:15buy1990.012008.540.002014.38
3972023.04.12 21:08t/p1990.012014.380.002014.385.841420.41
3982023.04.13 03:01t/p1980.012019.030.002019.0311.221431.63
3992023.04.13 05:15buy2000.012019.460.002026.04
4002023.04.13 07:15buy2010.012019.060.002025.18
4012023.04.13 09:15buy2020.012018.670.002024.85
4022023.04.13 10:38t/p2020.012024.850.002024.856.181437.81
4032023.04.13 10:40t/p2010.012025.180.002025.186.121443.93
4042023.04.13 11:05t/p2000.012026.040.002026.046.581450.51
4052023.04.13 18:45buy2030.012042.040.002058.26
4062023.04.13 23:00buy2040.012040.760.002048.48
4072023.04.14 03:00buy2050.012040.040.002042.08
4082023.04.14 03:30buy2060.012040.250.002043.07
4092023.04.14 03:42t/p2050.012042.080.002042.082.041452.55
4102023.04.14 03:45t/p2060.012043.070.002043.072.821455.37
4112023.04.14 04:15buy2070.012042.350.002049.37
4122023.04.14 09:00buy2080.012043.110.002049.23
4132023.04.14 09:31close2070.012042.930.002049.370.581455.95
4142023.04.14 09:31close2040.012042.930.002048.482.171458.12
4152023.04.14 09:31close2030.012042.930.002058.260.891459.01
4162023.04.14 09:31buy2090.012043.430.002050.21
4172023.04.14 12:36buy2100.012036.710.002044.67
4182023.04.14 15:30buy2110.012036.920.002045.88
4192023.04.21 14:00close2080.011987.900.002049.23-55.211403.80
4202023.04.21 14:30close2090.011985.170.002050.21-58.261345.54
4212023.04.21 15:32buy2120.011990.420.002004.28
4222023.04.21 17:30close2100.011982.080.002044.67-54.631290.91
4232023.04.21 20:30close2110.011979.620.002045.88-57.301233.61
4242023.04.24 09:00buy2130.011979.680.001983.98
4252023.04.24 10:30buy2140.011982.870.001992.63
4262023.04.24 11:00buy2150.011983.000.001993.02
4272023.04.24 11:54t/p2130.011983.980.001983.984.301237.91
4282023.04.24 17:45buy2160.011986.500.002010.66
4292023.04.25 01:05t/p2140.011992.630.001992.639.761247.67
4302023.04.25 01:08t/p2150.011993.020.001993.0210.021257.69
4312023.04.25 08:15buy2170.011994.120.002000.20
4322023.04.25 08:49buy2180.011994.410.001998.25
4332023.04.25 12:15close2160.011989.730.002010.663.231260.92
4342023.04.25 12:15buy2190.011990.230.001995.91
4352023.04.25 20:26t/p2190.011995.910.001995.915.681266.60
4362023.04.25 20:53t/p2180.011998.250.001998.253.841270.44
4372023.04.25 21:03t/p2170.012000.200.002000.206.081276.52
4382023.04.25 23:00buy2200.011999.540.002009.26
4392023.04.26 01:15buy2210.011997.970.002001.67
4402023.04.26 03:10t/p2210.012001.670.002001.673.701280.22
4412023.04.26 05:00buy2220.011999.190.002005.57
4422023.04.26 05:30buy2230.011998.620.002003.86
4432023.04.26 07:49close2120.011995.770.002004.285.351285.57
4442023.04.26 07:49buy2240.011996.270.002000.57
4452023.04.26 09:22close2240.011996.910.002000.570.641286.21
4462023.04.26 09:22buy2250.011997.410.002000.93
4472023.04.26 10:30close2250.011998.040.002000.930.631286.84
4482023.04.26 10:30buy2260.011998.540.002006.24
4492023.04.26 13:00close2260.011998.660.002006.240.121286.96
4502023.04.26 13:00close2230.011998.660.002003.860.041287.00
4512023.04.26 13:00buy2270.011999.160.002004.66
4522023.04.26 16:00buy2280.011998.260.002011.28
4532023.04.26 16:22t/p2270.012004.660.002004.665.501292.50
4542023.04.26 16:24t/p2220.012005.570.002005.576.381298.88
4552023.04.26 21:56buy2290.011991.040.001996.34
4562023.04.27 05:16t/p2290.011996.340.001996.345.301304.18
4572023.04.27 17:07buy2300.011985.500.002001.28
4582023.04.27 20:00buy2310.011984.770.001991.37
4592023.04.28 17:38t/p2310.011991.370.001991.376.601310.78
4602023.05.01 07:13buy2320.011984.280.001989.62
4612023.05.01 14:42t/p2320.011989.620.001989.625.341316.12
4622023.05.01 15:32close2200.012000.050.002009.260.511316.63
4632023.05.01 15:35t/p2300.012001.280.002001.2815.781332.41
4642023.05.01 23:30buy2330.011981.190.001984.01
4652023.05.02 02:30buy2340.011983.000.001986.00
4662023.05.02 03:15buy2350.011983.330.001987.81
4672023.05.02 03:45close2340.011983.040.001986.000.041332.45
4682023.05.02 03:45close2330.011983.040.001984.011.851334.30
4692023.05.02 03:45buy2360.011983.540.001988.44
4702023.05.02 04:15buy2370.011983.510.001988.35
4712023.05.02 10:00close2370.011984.430.001988.350.921335.22
4722023.05.02 10:00close2360.011984.430.001988.440.891336.11
4732023.05.02 10:00close2350.011984.430.001987.811.101337.21
4742023.05.02 10:00buy2380.011984.930.001989.69
4752023.05.02 11:45buy2390.011981.760.001987.72
4762023.05.02 12:15buy2400.011983.150.001991.89
4772023.05.02 12:45close2400.011984.610.001991.891.461338.67
4782023.05.02 12:45close2390.011984.610.001987.722.851341.52
4792023.05.02 12:45buy2410.011985.110.001997.77
4802023.05.02 14:06t/p2380.011989.690.001989.694.761346.28
4812023.05.02 17:13t/p2410.011997.770.001997.7712.661358.94
4822023.05.02 17:14close2280.011998.790.002011.280.531359.47
4832023.05.02 21:30buy2420.012015.390.002023.23
4842023.05.02 22:00buy2430.012014.620.002020.92
4852023.05.02 23:30buy2440.012016.680.002020.60
4862023.05.03 01:30buy2450.012016.300.002017.22
4872023.05.03 03:00close2430.012015.710.002020.921.091360.56
4882023.05.03 03:00close2420.012015.710.002023.230.321360.88
4892023.05.03 03:00buy2460.012016.210.002016.93
4902023.05.03 03:30buy2470.012016.420.002020.30
4912023.05.03 04:15t/p2460.012016.930.002016.930.721361.60
4922023.05.03 04:16t/p2450.012017.220.002017.220.921362.52
4932023.05.03 05:00buy2480.012017.100.002019.44
4942023.05.03 06:15buy2490.012018.180.002020.84
4952023.05.03 07:00close2490.012018.300.002020.840.121362.64
4962023.05.03 07:00close2480.012018.300.002019.441.201363.84
4972023.05.03 07:00close2470.012018.300.002020.301.881365.72
4982023.05.03 07:00close2440.012018.300.002020.601.621367.34
4992023.05.03 07:00buy2500.012018.800.002021.78
5002023.05.03 07:48buy2510.012017.570.002018.01
5012023.05.03 09:30buy2520.012016.540.002020.22
5022023.05.03 09:50t/p2510.012018.010.002018.010.441367.78
5032023.05.03 10:00buy2530.012018.330.002025.59
5042023.05.03 11:30buy2540.012016.320.002023.16
5052023.05.03 13:36close2540.012016.340.002023.160.021367.80
5062023.05.03 13:36buy2550.012016.840.002018.54
5072023.05.03 16:29t/p2550.012018.540.002018.541.701369.50
5082023.05.03 17:45buy2560.012019.060.002032.86
5092023.05.03 17:52t/p2520.012020.220.002020.223.681373.18
5102023.05.03 18:02t/p2500.012021.780.002021.782.981376.16
5112023.05.03 18:22t/p2530.012025.590.002025.597.261383.42
5122023.05.03 21:02t/p2560.012032.860.002032.8613.801397.22
5132023.05.03 21:15buy2570.012025.830.002038.07
5142023.05.03 22:30buy2580.012025.950.002043.35
5152023.05.03 23:50t/p2570.012038.070.002038.0712.241409.46
5162023.05.04 01:05t/p2580.012043.350.002043.3517.401426.86
5172023.05.04 16:45buy2590.012041.070.002058.53
5182023.05.04 17:44t/p2590.012058.530.002058.5317.461444.32
5192023.05.04 18:36buy2600.012050.470.002060.89
5202023.05.04 19:15buy2610.012054.070.002074.83
5212023.05.04 19:45buy2620.012051.680.002067.66
5222023.05.04 20:45buy2630.012048.670.002056.47
5232023.05.04 22:15close2630.012049.070.002056.470.401444.72
5242023.05.04 22:15buy2640.012049.570.002057.37
5252023.05.04 23:15close2640.012050.140.002057.370.571445.29
5262023.05.04 23:15buy2650.012050.640.002056.98
5272023.05.11 23:30close2600.012013.690.002060.89-36.781408.51
5282023.05.12 01:15close2610.012015.960.002074.83-38.111370.40
5292023.05.12 01:45close2620.012015.350.002067.66-36.331334.07
5302023.05.12 05:15close2650.012011.920.002056.98-38.721295.35
5312023.05.12 10:15buy2660.012010.210.002018.67
5322023.05.12 13:45buy2670.012006.810.002018.07
5332023.05.12 16:05t/p2670.012018.070.002018.0711.261306.61
5342023.05.12 16:06t/p2660.012018.670.002018.678.461315.07
5352023.05.12 19:15buy2680.012010.470.002014.07
5362023.05.12 20:01t/p2680.012014.070.002014.073.601318.67
5372023.05.15 15:30buy2690.012015.350.002021.61
5382023.05.15 16:58t/p2690.012021.610.002021.616.261324.93
5392023.05.15 18:45buy2700.012018.550.002028.39
5402023.05.16 10:52buy2710.012009.630.002019.29
5412023.05.16 13:15buy2720.012010.410.002012.89
5422023.05.16 15:30buy2730.012007.380.002014.36
5432023.05.16 15:43t/p2720.012012.890.002012.892.481327.41
5442023.05.16 15:45t/p2730.012014.360.002014.366.981334.39
5452023.05.17 01:30buy2740.011989.890.001993.11
5462023.05.17 03:00buy2750.011990.150.001991.79
5472023.05.17 03:20t/p2750.011991.790.001991.791.641336.03
5482023.05.17 05:00buy2760.011992.950.001998.57
5492023.05.17 06:00close2740.011992.550.001993.112.661338.69
5502023.05.17 06:00buy2770.011993.050.001997.67
5512023.05.22 23:45close2700.011971.650.002028.39-46.901291.79
5522023.05.23 15:45close2710.011959.200.002019.29-50.431241.36
5532023.05.23 18:45buy2780.011967.250.001972.51
5542023.05.23 19:15buy2790.011968.770.001977.05
5552023.05.23 19:38t/p2780.011972.510.001972.515.261246.62
5562023.05.23 21:26t/p2790.011977.050.001977.058.281254.90
5572023.05.24 10:00close2760.011971.540.001998.57-21.411233.49
5582023.05.24 10:45buy2800.011976.440.001987.36
5592023.05.24 11:00close2770.011973.800.001997.67-19.251214.24
5602023.05.25 01:15buy2810.011959.230.001962.01
5612023.05.25 01:46buy2820.011959.860.001963.14
5622023.05.25 04:00buy2830.011959.650.001963.07
5632023.05.25 11:23t/p2810.011962.010.001962.012.781217.02
5642023.05.25 11:25t/p2830.011963.070.001963.073.421220.44
5652023.05.25 11:25t/p2820.011963.140.001963.143.281223.72
5662023.05.25 17:05buy2840.011949.160.001963.92
5672023.05.26 01:05buy2850.011941.660.001946.72
5682023.05.26 04:00buy2860.011941.280.001949.74
5692023.05.26 04:58t/p2850.011946.720.001946.725.061228.78
5702023.05.26 08:35t/p2860.011949.740.001949.748.461237.24
5712023.05.26 16:45buy2870.011950.430.001962.17
5722023.05.26 17:15buy2880.011950.730.001962.89
5732023.05.30 17:15close2880.011955.910.001962.895.181242.42
5742023.05.30 17:15close2870.011955.910.001962.175.481247.90
5752023.05.30 17:15close2840.011955.910.001963.926.751254.65
5762023.05.30 17:15buy2890.011956.410.001966.61
5772023.05.31 06:00buy2900.011956.510.001961.59
5782023.05.31 08:30buy2910.011959.570.001962.43
5792023.05.31 08:43t/p2900.011961.590.001961.595.081259.73
5802023.05.31 08:50t/p2910.011962.430.001962.432.861262.59
5812023.05.31 11:15buy2920.011958.320.001963.14
5822023.05.31 12:21buy2930.011958.020.001960.36
5832023.05.31 13:00close2930.011958.480.001960.360.461263.05
5842023.05.31 13:00close2920.011958.480.001963.140.161263.21
5852023.05.31 13:00close2890.011958.480.001966.612.071265.28
5862023.05.31 13:00buy2940.011958.980.001966.46
5872023.05.31 14:15buy2950.011958.590.001964.21
5882023.05.31 16:13t/p2950.011964.210.001964.215.621270.90
5892023.05.31 16:42t/p2940.011966.460.001966.467.481278.38
5902023.05.31 17:30buy2960.011966.450.001977.69
5912023.05.31 18:15close2800.011971.120.001987.36-5.321273.06
5922023.05.31 20:45buy2970.011968.340.001978.22
5932023.05.31 21:15buy2980.011967.370.001975.31
5942023.06.01 01:10buy2990.011963.980.001965.92
5952023.06.01 01:46t/p2990.011965.920.001965.921.941275.00
5962023.06.01 03:15buy3000.011966.760.001968.70
5972023.06.01 16:00t/p3000.011968.700.001968.701.941276.94
5982023.06.01 16:30buy3010.011968.550.001987.73
5992023.06.01 17:00t/p2980.011975.310.001975.317.941284.88
6002023.06.01 18:07t/p2960.011977.690.001977.6911.241296.12
6012023.06.01 18:07t/p2970.011978.220.001978.229.881306.00
6022023.06.01 21:00buy3020.011978.390.001982.23
6032023.06.01 21:45buy3030.011977.680.001980.10
6042023.06.01 22:17buy3040.011977.500.001980.26
6052023.06.02 02:49close3010.011976.650.001987.738.101314.10
6062023.06.02 02:49buy3050.011977.150.001978.69
6072023.06.02 05:07t/p3050.011978.690.001978.691.541315.64
6082023.06.02 05:50t/p3030.011980.100.001980.102.421318.06
6092023.06.02 05:51t/p3040.011980.260.001980.262.761320.82
6102023.06.02 06:19t/p3020.011982.230.001982.233.841324.66
6112023.06.05 01:25buy3060.011950.340.001955.26
6122023.06.05 04:45buy3070.011947.480.001949.50
6132023.06.05 06:45buy3080.011947.430.001953.67
6142023.06.05 08:44buy3090.011946.000.001948.80
6152023.06.05 17:00t/p3090.011948.800.001948.802.801327.46
6162023.06.05 17:00t/p3070.011949.500.001949.502.021329.48
6172023.06.05 17:00t/p3080.011953.670.001953.676.241335.72
6182023.06.05 17:01t/p3060.011955.260.001955.264.921340.64
6192023.06.06 17:19buy3100.011961.380.001971.82
6202023.06.06 18:00buy3110.011960.390.001971.81
6212023.06.06 18:31buy3120.011961.070.001968.45
6222023.06.07 11:15buy3130.011959.370.001967.71
6232023.06.07 16:45close3130.011961.830.001967.712.461343.10
6242023.06.07 16:45close3120.011961.830.001968.450.761343.86
6252023.06.07 16:45close3110.011961.830.001971.811.441345.30
6262023.06.07 16:45close3100.011961.830.001971.820.451345.75
6272023.06.07 16:45buy3140.011962.330.001972.03
6282023.06.08 21:46buy3150.011964.760.001969.40
6292023.06.09 01:45buy3160.011966.260.001968.02
6302023.06.09 02:45buy3170.011966.170.001967.65
6312023.06.09 04:15close3140.011964.510.001972.032.181347.93
6322023.06.09 04:15buy3180.011965.010.001967.73
6332023.06.09 09:30close3150.011964.800.001969.400.041347.97
6342023.06.09 09:30buy3190.011965.300.001970.00
6352023.06.09 15:30t/p3170.011967.650.001967.651.481349.45
6362023.06.09 15:30t/p3180.011967.730.001967.732.721352.17
6372023.06.09 15:30t/p3160.011968.020.001968.021.761353.93
6382023.06.09 15:31t/p3190.011970.000.001970.004.701358.63
6392023.06.09 15:45buy3200.011965.820.001969.38
6402023.06.09 17:00buy3210.011962.410.001972.33
6412023.06.12 18:09buy3220.011955.880.001965.98
6422023.06.13 01:45buy3230.011958.430.001961.19
6432023.06.13 04:15close3230.011958.780.001961.190.351358.98
6442023.06.13 04:15close3220.011958.780.001965.982.901361.88
6452023.06.13 04:15buy3240.011959.280.001962.20
6462023.06.13 05:45buy3250.011958.670.001963.47
6472023.06.13 09:21t/p3240.011962.200.001962.202.921364.80
6482023.06.13 10:08t/p3250.011963.470.001963.474.801369.60
6492023.06.13 15:30t/p3200.011969.380.001969.383.561373.16
6502023.06.13 22:52buy3260.011943.360.001948.06
6512023.06.14 01:07buy3270.011944.400.001949.38
6522023.06.14 01:45buy3280.011945.350.001951.23
6532023.06.14 03:00close3260.011943.800.001948.060.441373.60
6542023.06.14 03:00buy3290.011944.300.001947.88
6552023.06.14 05:00close3290.011946.700.001947.882.401376.00
6562023.06.14 05:00close3280.011946.700.001951.231.351377.35
6572023.06.14 05:00close3270.011946.700.001949.382.301379.65
6582023.06.14 05:00buy3300.011947.200.001953.00
6592023.06.14 06:00buy3310.011947.830.001951.31
6602023.06.14 06:30buy3320.011948.020.001951.02
6612023.06.14 07:30close3320.011948.390.001951.020.371380.02
6622023.06.14 07:30close3310.011948.390.001951.310.561380.58
6632023.06.14 07:30close3300.011948.390.001953.001.191381.77
6642023.06.14 07:30buy3330.011948.890.001952.37
6652023.06.14 08:15buy3340.011949.350.001951.81
6662023.06.14 08:45buy3350.011947.950.001950.85
6672023.06.14 10:30close3350.011948.850.001950.850.901382.67
6682023.06.14 10:30buy3360.011949.350.001957.03
6692023.06.14 12:26t/p3340.011951.810.001951.812.461385.13
6702023.06.14 12:34t/p3330.011952.370.001952.373.481388.61
6712023.06.14 15:15buy3370.011948.480.001953.24
6722023.06.14 15:36t/p3370.011953.240.001953.244.761393.37
6732023.06.14 15:43t/p3360.011957.030.001957.037.681401.05
6742023.06.15 08:30buy3380.011935.850.001945.35
6752023.06.15 10:37buy3390.011934.230.001943.29
6762023.06.15 11:15buy3400.011934.480.001944.94
6772023.06.15 12:30close3390.011934.350.001943.290.121401.17
6782023.06.15 12:30buy3410.011934.850.001942.43
6792023.06.15 13:46close3400.011934.710.001944.940.231401.40
6802023.06.15 13:46buy3420.011935.210.001939.41
6812023.06.15 16:25t/p3420.011939.410.001939.414.201405.60
6822023.06.15 16:27t/p3410.011942.430.001942.437.581413.18
6832023.06.15 16:43t/p3380.011945.350.001945.359.501422.68
6842023.06.16 09:33close3210.011962.920.001972.330.511423.19
6852023.06.16 16:45buy3430.011962.910.001975.15
6862023.06.16 17:56buy3440.011960.330.001970.55
6872023.06.16 18:30buy3450.011960.650.001973.45
6882023.06.16 20:25buy3460.011958.100.001965.60
6892023.06.26 01:15close3430.011923.680.001975.15-39.231383.96
6902023.06.26 02:15close3440.011924.300.001970.55-36.031347.93
6912023.06.26 03:00close3450.011925.150.001973.45-35.501312.43
6922023.06.26 04:45close3460.011927.640.001965.60-30.461281.97
6932023.06.26 18:17buy3470.011926.410.001935.09
6942023.06.27 03:30buy3480.011923.740.001928.92
6952023.06.27 04:00buy3490.011922.960.001926.58
6962023.06.27 04:42t/p3490.011926.580.001926.583.621285.59
6972023.06.27 04:49t/p3480.011928.920.001928.925.181290.77
6982023.06.27 10:00buy3500.011927.720.001934.24
6992023.06.27 15:01buy3510.011924.180.001931.16
7002023.06.28 01:15buy3520.011915.060.001918.66
7012023.06.28 04:00close3520.011915.950.001918.660.891291.66
7022023.06.28 04:00buy3530.011916.450.001918.91
7032023.06.28 23:54close at stop3530.011906.650.001918.91-9.801281.86
7042023.06.28 23:54close at stop3510.011906.650.001931.16-17.531264.33
7052023.06.28 23:54close at stop3500.011906.650.001934.24-21.071243.26
7062023.06.28 23:54close at stop3470.011906.650.001935.09-19.761223.50
+
diff --git a/Docs/Reports/14020412/OSC XMA 15Min Long/Only XMA/StrategyTester_1.gif b/Docs/Reports/14020412/OSC XMA 15Min Long/Only XMA/StrategyTester_1.gif new file mode 100644 index 0000000..005d140 Binary files /dev/null and b/Docs/Reports/14020412/OSC XMA 15Min Long/Only XMA/StrategyTester_1.gif differ diff --git a/Docs/Reports/14020412/OSC XMA 15Min Long/Only XMA/StrategyTester_1.htm b/Docs/Reports/14020412/OSC XMA 15Min Long/Only XMA/StrategyTester_1.htm new file mode 100644 index 0000000..78dc9e1 --- /dev/null +++ b/Docs/Reports/14020412/OSC XMA 15Min Long/Only XMA/StrategyTester_1.htm @@ -0,0 +1,222 @@ + + + + Strategy Tester: x-saherelm.osc.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.osc.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2023.01.03 01:00 - 2023.06.28 23:45 (2023.01.01 - 2023.06.29)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_OSC"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=480; fastOSCLength=10; fastOSCMultiplier=1; slowOSCLength=30; slowOSCMultiplier=3; minPowerOSC=0.055; minVarianceOSC=0; zDeviation=5; zBackStep=3; shortCycleFastMultiplier=1; shortCycleSlowMultiplier=4; mediumCycleFastMultiplier=7; mediumCycleSlowMultiplier=14; longCycleFastMultiplier=70; longCycleSlowMultiplier=140; showShortCycle=false; +showShortCycleCrossLines=false; +showMediumCycle=false; +showMediumCycleCrossLines=false; +showLongCycle=false; +showLongCycleCrossLines=false; +shortCycleFastColor=Green; shortCycleSlowColor=Red; mediumCycleFastColor=Aqua; mediumCycleSlowColor=Magenta; longCycleFastColor=Goldenrod; longCycleSlowColor=Brown;
Bars in test12551Ticks modelled15360882Modelling qualityn/a
Mismatched charts errors1395
Initial deposit1000.00SpreadCurrent (57)
Total net profit58.78Gross profit582.17Gross loss-523.39
Profit factor1.11Expected payoff0.78
Absolute drawdown10.15Maximal drawdown322.36 (23.55%)Relative drawdown23.55% (322.36)
Total trades75Short positions (won %)0 (0.00%)Long positions (won %)75 (80.00%)
Profit trades (% of total)60 (80.00%)Loss trades (% of total)15 (20.00%)
Largestprofit trade32.50loss trade-83.16
Averageprofit trade9.70loss trade-34.89
Maximumconsecutive wins (profit in money)23 (247.24)consecutive losses (loss in money)5 (-152.61)
Maximalconsecutive profit (count of wins)247.24 (23)consecutive loss (count of losses)-224.33 (4)
Averageconsecutive wins12consecutive losses3
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12023.01.06 10:45buy10.011838.920.001843.76
22023.01.06 13:30buy20.011840.110.001852.61
32023.01.06 15:41t/p10.011843.760.001843.764.841004.84
42023.01.06 17:02t/p20.011852.610.001852.6112.501017.34
52023.01.10 10:45buy30.011874.470.001882.55
62023.01.11 07:36t/p30.011882.550.001882.558.081025.42
72023.01.12 04:00buy40.011880.930.001888.89
82023.01.12 14:23t/p40.011888.890.001888.897.961033.38
92023.01.17 16:30buy50.011915.960.001934.12
102023.01.17 17:00buy60.011913.860.001920.64
112023.01.18 10:30buy70.011912.320.001931.62
122023.01.18 10:45buy80.011912.000.001927.60
132023.01.18 15:30t/p60.011920.640.001920.646.781040.16
142023.01.19 06:45buy90.011909.950.001916.75
152023.01.19 16:21t/p90.011916.750.001916.756.801046.96
162023.01.19 21:26t/p80.011927.600.001927.6015.601062.56
172023.01.19 22:07t/p70.011931.620.001931.6219.301081.86
182023.01.19 22:13t/p50.011934.120.001934.1218.161100.02
192023.01.23 02:45buy100.011930.950.001942.63
202023.01.23 21:30buy110.011928.100.001937.10
212023.01.24 08:31t/p110.011937.100.001937.109.001109.02
222023.01.25 18:57buy120.011937.690.001955.77
232023.01.25 21:57t/p100.011942.630.001942.6311.681120.70
242023.01.27 14:15buy130.011932.410.001941.85
252023.01.27 18:45buy140.011931.740.001962.44
262023.01.31 17:15buy150.011922.500.001941.44
272023.02.01 21:43close120.011938.200.001955.770.511121.21
282023.02.01 21:52t/p150.011941.440.001941.4418.941140.15
292023.02.01 21:52t/p130.011941.850.001941.859.441149.59
302023.02.02 06:45close140.011953.230.001962.4421.491171.08
312023.02.07 04:45buy160.011874.080.001882.44
322023.02.07 19:48t/p160.011882.440.001882.448.361179.44
332023.02.08 02:07buy170.011874.940.001882.96
342023.02.08 09:56t/p170.011882.960.001882.968.021187.46
352023.02.09 05:00buy180.011879.500.001891.10
362023.02.10 16:30buy190.011867.550.001879.53
372023.02.10 16:46buy200.011865.500.001873.38
382023.02.10 17:18buy210.011866.930.001883.07
392023.02.16 10:00close180.011841.080.001891.10-38.421149.04
402023.02.17 21:30close190.011842.050.001879.53-25.501123.54
412023.02.17 21:45close200.011841.760.001873.38-23.741099.80
422023.02.17 22:15close210.011842.420.001883.07-24.511075.29
432023.02.22 04:18buy220.011836.810.001840.77
442023.02.22 10:05t/p220.011840.770.001840.773.961079.25
452023.02.24 04:30buy230.011826.890.001832.79
462023.02.24 05:15buy240.011827.540.001834.30
472023.02.24 08:15buy250.011825.790.001829.71
482023.02.24 08:30buy260.011825.830.001829.83
492023.02.28 19:25t/p250.011829.710.001829.713.921083.17
502023.02.28 19:25t/p260.011829.830.001829.834.001087.17
512023.03.01 08:15t/p230.011832.790.001832.795.901093.07
522023.03.01 08:32t/p240.011834.300.001834.306.761099.83
532023.03.02 17:33buy270.011839.300.001854.26
542023.03.02 17:45buy280.011836.180.001842.78
552023.03.02 20:52buy290.011835.880.001843.44
562023.03.03 08:42t/p280.011842.780.001842.786.601106.43
572023.03.03 08:48t/p290.011843.440.001843.447.561113.99
582023.03.03 22:04t/p270.011854.260.001854.2614.961128.95
592023.03.08 17:00buy300.011820.920.001838.76
602023.03.09 10:45buy310.011819.070.001832.05
612023.03.09 17:02t/p310.011832.050.001832.0512.981141.93
622023.03.10 15:31t/p300.011838.760.001838.7617.841159.77
632023.03.14 20:30buy320.011909.590.001918.35
642023.03.14 20:45buy330.011908.470.001914.99
652023.03.15 13:30buy340.011912.290.001944.79
662023.03.15 13:32t/p330.011914.990.001914.996.521166.29
672023.03.15 13:33t/p320.011918.350.001918.358.761175.05
682023.03.17 14:33t/p340.011944.790.001944.7932.501207.55
692023.03.21 04:55buy350.011984.480.001995.38
702023.03.22 16:45buy360.011945.310.001959.07
712023.03.22 20:02t/p360.011959.070.001959.0713.761221.31
722023.03.23 19:34t/p350.011995.380.001995.3810.901232.21
732023.03.28 08:45buy370.011960.000.001967.16
742023.03.28 15:38t/p370.011967.160.001967.167.161239.37
752023.03.30 09:30buy380.011967.110.001981.19
762023.03.30 19:33t/p380.011981.190.001981.1914.081253.45
772023.04.03 14:00buy390.011972.870.001992.83
782023.04.04 15:15buy400.011984.560.001997.18
792023.04.04 16:46t/p390.011992.830.001992.8319.961273.41
802023.04.04 17:00t/p400.011997.180.001997.1812.621286.03
812023.04.06 14:15buy410.012020.250.002025.97
822023.04.11 05:30buy420.011996.090.002011.05
832023.04.12 04:37t/p420.012011.050.002011.0514.961300.99
842023.04.12 15:35t/p410.012025.970.002025.975.721306.71
852023.04.17 15:00buy430.012009.490.002019.07
862023.04.18 10:29buy440.012002.540.002011.86
872023.04.19 22:00buy450.011996.680.002003.18
882023.04.20 13:29t/p450.012003.180.002003.186.501313.21
892023.04.20 17:08t/p440.012011.860.002011.869.321322.53
902023.04.24 12:15buy460.011985.670.001995.83
912023.04.24 20:00close430.011986.450.002019.07-23.041299.49
922023.04.25 02:42t/p460.011995.830.001995.8310.161309.65
932023.04.25 20:30buy470.011994.280.002006.76
942023.04.26 16:26t/p470.012006.760.002006.7612.481322.13
952023.04.27 06:00buy480.011999.130.002015.61
962023.04.28 17:45buy490.011988.940.002003.12
972023.05.01 14:15buy500.011987.350.001996.19
982023.05.01 15:24t/p500.011996.190.001996.198.841330.97
992023.05.01 15:36t/p490.012003.120.002003.1214.181345.15
1002023.05.02 13:45buy510.011988.110.002003.63
1012023.05.02 17:15close480.011999.650.002015.610.521345.67
1022023.05.02 17:28t/p510.012003.630.002003.6315.521361.19
1032023.05.08 11:45buy520.012022.380.002027.64
1042023.05.08 18:29t/p520.012027.640.002027.645.261366.45
1052023.05.10 15:45buy530.012046.500.002090.02
1062023.05.11 03:15buy540.012032.950.002038.13
1072023.05.11 14:32buy550.012038.380.002062.76
1082023.05.11 14:33t/p540.012038.130.002038.135.181371.63
1092023.05.12 16:47buy560.012020.820.002054.00
1102023.05.12 20:02buy570.012014.980.002028.60
1112023.05.17 20:45close530.011981.850.002090.02-64.651306.98
1122023.05.18 19:30close550.011955.220.002062.76-83.161223.82
1132023.05.19 21:45close560.011979.300.002054.00-41.521182.30
1142023.05.22 02:00close570.011979.980.002028.60-35.001147.30
1152023.05.23 17:30buy580.011969.700.001991.80
1162023.05.23 17:45buy590.011967.930.001978.41
1172023.05.24 07:30t/p590.011978.410.001978.4110.481157.78
1182023.05.26 09:45buy600.011951.870.001962.05
1192023.05.29 15:00buy610.011946.780.001952.32
1202023.05.29 15:15buy620.011945.930.001949.77
1212023.05.30 12:55t/p620.011949.770.001949.773.841161.62
1222023.05.30 12:59t/p610.011952.320.001952.325.541167.16
1232023.05.30 15:20t/p600.011962.050.001962.0510.181177.34
1242023.05.31 02:00close580.011958.460.001991.80-11.241166.10
1252023.06.01 14:30buy630.011967.510.001983.01
1262023.06.02 06:21t/p630.011983.010.001983.0115.501181.60
1272023.06.05 17:30buy640.011959.060.001992.22
1282023.06.07 17:00buy650.011970.110.001996.37
1292023.06.07 17:15buy660.011964.900.001980.74
1302023.06.08 15:38buy670.011957.110.001981.87
1312023.06.09 05:30close640.011963.620.001992.224.561186.16
1322023.06.12 11:30buy680.011964.510.001976.49
1332023.06.13 13:55close660.011965.420.001980.740.521186.68
1342023.06.13 15:30close650.011970.760.001996.370.651187.33
1352023.06.14 12:31buy690.011952.480.001961.02
1362023.06.14 15:36buy700.011952.840.001967.32
1372023.06.14 15:44close670.011957.620.001981.870.511187.84
1382023.06.15 17:15buy710.011956.020.002008.72
1392023.06.16 04:46t/p690.011961.020.001961.028.541196.38
1402023.06.16 13:53close680.011965.040.001976.490.531196.91
1412023.06.16 15:15t/p700.011967.320.001967.3214.481211.39
1422023.06.20 10:45buy720.011955.420.001968.94
1432023.06.21 21:45buy730.011937.390.001945.49
1442023.06.21 22:00buy740.011936.290.001941.61
1452023.06.23 01:45close710.011913.380.002008.72-42.641168.75
1462023.06.27 05:45buy750.011928.250.001937.95
1472023.06.27 15:45close720.011927.430.001968.94-27.991140.76
1482023.06.28 23:54close at stop750.011906.650.001937.95-21.601119.16
1492023.06.28 23:54close at stop740.011906.650.001941.61-29.641089.52
1502023.06.28 23:54close at stop730.011906.650.001945.49-30.741058.78
+
diff --git a/Docs/Reports/14020427/StrategyTester 1.gif b/Docs/Reports/14020427/StrategyTester 1.gif new file mode 100644 index 0000000..1f3c0ce Binary files /dev/null and b/Docs/Reports/14020427/StrategyTester 1.gif differ diff --git a/Docs/Reports/14020427/StrategyTester 1.htm b/Docs/Reports/14020427/StrategyTester 1.htm new file mode 100644 index 0000000..3057841 --- /dev/null +++ b/Docs/Reports/14020427/StrategyTester 1.htm @@ -0,0 +1,77 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.01.29 23:45 (2020.01.01 - 2021.02.01)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=408; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +step=0.01; maximum=0.1; shortCycleMultiplier=2; mediumCycleMultiplier=6; longCycleMultiplier=36;
Bars in test4192Ticks modelled3544155Modelling quality24.42%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (51)
Total net profit54.27Gross profit54.27Gross loss-0.00
Profit factorExpected payoff10.85
Absolute drawdown29.71Maximal drawdown53.15 (5.19%)Relative drawdown5.19% (53.15)
Total trades5Short positions (won %)0 (0.00%)Long positions (won %)5 (100.00%)
Profit trades (% of total)5 (100.00%)Loss trades (% of total)0 (0.00%)
Largestprofit trade20.17loss trade-0.00
Averageprofit trade10.85loss trade-0.00
Maximumconsecutive wins (profit in money)5 (54.27)consecutive losses (loss in money)0 (-0.00)
Maximalconsecutive profit (count of wins)54.27 (5)consecutive loss (count of losses)-0.00 (0)
Averageconsecutive wins5consecutive losses0
+Graph
+ + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.02 08:30buy10.011814.560.001828.18
22020.12.02 12:22t/p10.011828.180.001828.1813.621013.62
32020.12.04 14:15buy20.011842.710.001850.47
42020.12.04 16:15buy30.011843.510.001864.07
52020.12.07 16:49t/p20.011850.470.001850.477.371020.99
62020.12.07 17:46t/p30.011864.070.001864.0720.171041.17
72020.12.18 01:00buy40.011884.910.001888.23
82020.12.18 14:09t/p40.011888.230.001888.233.321044.49
92021.01.05 05:45buy50.011942.150.001951.93
102021.01.05 16:16t/p50.011951.930.001951.939.781054.27
+
diff --git a/Docs/Reports/14020427/StrategyTester 2.gif b/Docs/Reports/14020427/StrategyTester 2.gif new file mode 100644 index 0000000..e902f9a Binary files /dev/null and b/Docs/Reports/14020427/StrategyTester 2.gif differ diff --git a/Docs/Reports/14020427/StrategyTester 2.htm b/Docs/Reports/14020427/StrategyTester 2.htm new file mode 100644 index 0000000..5f7287e --- /dev/null +++ b/Docs/Reports/14020427/StrategyTester 2.htm @@ -0,0 +1,81 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.02.26 23:45 (2020.01.01 - 2021.03.01)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=408; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +step=0.01; maximum=0.1; shortCycleMultiplier=2; mediumCycleMultiplier=6; longCycleMultiplier=36;
Bars in test6016Ticks modelled6166924Modelling quality24.60%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (50)
Total net profit35.23Gross profit66.77Gross loss-31.54
Profit factor2.12Expected payoff5.03
Absolute drawdown29.69Maximal drawdown53.15 (5.19%)Relative drawdown5.19% (53.15)
Total trades7Short positions (won %)0 (0.00%)Long positions (won %)7 (85.71%)
Profit trades (% of total)6 (85.71%)Loss trades (% of total)1 (14.29%)
Largestprofit trade20.17loss trade-31.54
Averageprofit trade11.13loss trade-31.54
Maximumconsecutive wins (profit in money)6 (66.77)consecutive losses (loss in money)1 (-31.54)
Maximalconsecutive profit (count of wins)66.77 (6)consecutive loss (count of losses)-31.54 (1)
Averageconsecutive wins6consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.02 08:30buy10.011814.550.001828.17
22020.12.02 12:22t/p10.011828.170.001828.1713.621013.62
32020.12.04 14:15buy20.011842.700.001850.46
42020.12.04 16:15buy30.011843.500.001864.06
52020.12.07 16:49t/p20.011850.460.001850.467.371020.99
62020.12.07 17:46t/p30.011864.060.001864.0620.171041.17
72020.12.18 01:00buy40.011884.900.001888.22
82020.12.18 14:09t/p40.011888.220.001888.223.321044.49
92021.01.05 05:45buy50.011942.140.001951.92
102021.01.05 16:16t/p50.011951.920.001951.929.781054.27
112021.02.09 03:15buy60.011835.680.001848.18
122021.02.09 11:54t/p60.011848.180.001848.1812.501066.77
132021.02.10 15:15buy70.011844.620.001857.72
142021.02.12 10:19close70.011814.620.001857.72-31.541035.23
+
diff --git a/Docs/Reports/14020427/StrategyTester 3.gif b/Docs/Reports/14020427/StrategyTester 3.gif new file mode 100644 index 0000000..7728f57 Binary files /dev/null and b/Docs/Reports/14020427/StrategyTester 3.gif differ diff --git a/Docs/Reports/14020427/StrategyTester 3.htm b/Docs/Reports/14020427/StrategyTester 3.htm new file mode 100644 index 0000000..0ebb51f --- /dev/null +++ b/Docs/Reports/14020427/StrategyTester 3.htm @@ -0,0 +1,81 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.02.26 23:45 (2020.01.01 - 2021.03.01)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=408; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +step=0.01; maximum=0.1; shortCycleMultiplier=2; mediumCycleMultiplier=6; longCycleMultiplier=36;
Bars in test6016Ticks modelled6166924Modelling quality24.60%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (51)
Total net profit56.23Gross profit56.23Gross loss-0.00
Profit factorExpected payoff8.03
Absolute drawdown36.52Maximal drawdown53.15 (5.23%)Relative drawdown5.23% (53.15)
Total trades7Short positions (won %)0 (0.00%)Long positions (won %)7 (100.00%)
Profit trades (% of total)7 (100.00%)Loss trades (% of total)0 (0.00%)
Largestprofit trade12.50loss trade-0.00
Averageprofit trade8.03loss trade-0.00
Maximumconsecutive wins (profit in money)7 (56.23)consecutive losses (loss in money)0 (-0.00)
Maximalconsecutive profit (count of wins)56.23 (7)consecutive loss (count of losses)-0.00 (0)
Averageconsecutive wins7consecutive losses0
+Graph
+ + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.02 08:30buy10.011814.560.001821.37
22020.12.02 10:36t/p10.011821.370.001821.376.811006.81
32020.12.04 14:15buy20.011842.710.001850.47
42020.12.04 16:15buy30.011843.510.001853.79
52020.12.07 16:49t/p20.011850.470.001850.477.371014.18
62020.12.07 16:52t/p30.011853.790.001853.799.891024.08
72020.12.18 01:00buy40.011884.910.001888.23
82020.12.18 14:09t/p40.011888.230.001888.233.321027.40
92021.01.05 05:45buy50.011942.150.001951.93
102021.01.05 16:16t/p50.011951.930.001951.939.781037.18
112021.02.09 03:15buy60.011835.690.001848.19
122021.02.09 11:54t/p60.011848.190.001848.1912.501049.68
132021.02.10 15:15buy70.011844.630.001851.18
142021.02.10 15:37t/p70.011851.180.001851.186.551056.23
+
diff --git a/Docs/Reports/14020427/StrategyTester 4.gif b/Docs/Reports/14020427/StrategyTester 4.gif new file mode 100644 index 0000000..190c6f7 Binary files /dev/null and b/Docs/Reports/14020427/StrategyTester 4.gif differ diff --git a/Docs/Reports/14020427/StrategyTester 4.htm b/Docs/Reports/14020427/StrategyTester 4.htm new file mode 100644 index 0000000..3f65e6f --- /dev/null +++ b/Docs/Reports/14020427/StrategyTester 4.htm @@ -0,0 +1,87 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.03.31 23:45 (2020.01.01 - 2021.04.01)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=408; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +step=0.01; maximum=0.1; shortCycleMultiplier=2; mediumCycleMultiplier=6; longCycleMultiplier=36;
Bars in test8132Ticks modelled9612073Modelling quality24.70%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (50)
Total net profit80.25Gross profit80.25Gross loss-0.00
Profit factorExpected payoff8.03
Absolute drawdown36.50Maximal drawdown53.15 (5.23%)Relative drawdown5.23% (53.15)
Total trades10Short positions (won %)0 (0.00%)Long positions (won %)10 (100.00%)
Profit trades (% of total)10 (100.00%)Loss trades (% of total)0 (0.00%)
Largestprofit trade12.50loss trade-0.00
Averageprofit trade8.03loss trade-0.00
Maximumconsecutive wins (profit in money)10 (80.25)consecutive losses (loss in money)0 (-0.00)
Maximalconsecutive profit (count of wins)80.25 (10)consecutive loss (count of losses)-0.00 (0)
Averageconsecutive wins10consecutive losses0
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.02 08:30buy10.011814.550.001821.36
22020.12.02 10:36t/p10.011821.360.001821.366.811006.81
32020.12.04 14:15buy20.011842.700.001850.46
42020.12.04 16:15buy30.011843.500.001853.78
52020.12.07 16:49t/p20.011850.460.001850.467.371014.18
62020.12.07 16:52t/p30.011853.780.001853.789.891024.08
72020.12.18 01:00buy40.011884.900.001888.22
82020.12.18 14:09t/p40.011888.220.001888.223.321027.40
92021.01.05 05:45buy50.011942.140.001951.92
102021.01.05 16:16t/p50.011951.920.001951.929.781037.18
112021.02.09 03:15buy60.011835.680.001848.18
122021.02.09 11:54t/p60.011848.180.001848.1812.501049.68
132021.02.10 15:15buy70.011844.620.001851.17
142021.02.10 15:37t/p70.011851.170.001851.176.551056.23
152021.03.10 03:15buy80.011718.560.001729.52
162021.03.10 15:15buy90.011714.680.001724.00
172021.03.10 20:33t/p90.011724.000.001724.009.321065.55
182021.03.11 04:07t/p80.011729.520.001729.529.801075.35
192021.03.16 12:30buy100.011733.030.001737.93
202021.03.16 16:22t/p100.011737.930.001737.934.901080.25
+
diff --git a/Docs/Reports/14020427/StrategyTester 5.gif b/Docs/Reports/14020427/StrategyTester 5.gif new file mode 100644 index 0000000..a43105a Binary files /dev/null and b/Docs/Reports/14020427/StrategyTester 5.gif differ diff --git a/Docs/Reports/14020427/StrategyTester 5.htm b/Docs/Reports/14020427/StrategyTester 5.htm new file mode 100644 index 0000000..9ed9171 --- /dev/null +++ b/Docs/Reports/14020427/StrategyTester 5.htm @@ -0,0 +1,99 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.04.30 23:45 (2020.01.01 - 2021.05.01)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=408; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +step=0.01; maximum=0.1; shortCycleMultiplier=2; mediumCycleMultiplier=6; longCycleMultiplier=36;
Bars in test10063Ticks modelled11947707Modelling quality24.76%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (51)
Total net profit76.08Gross profit106.85Gross loss-30.77
Profit factor3.47Expected payoff4.76
Absolute drawdown36.52Maximal drawdown59.05 (5.44%)Relative drawdown5.44% (59.05)
Total trades16Short positions (won %)0 (0.00%)Long positions (won %)16 (93.75%)
Profit trades (% of total)15 (93.75%)Loss trades (% of total)1 (6.25%)
Largestprofit trade12.50loss trade-30.77
Averageprofit trade7.12loss trade-30.77
Maximumconsecutive wins (profit in money)12 (85.99)consecutive losses (loss in money)1 (-30.77)
Maximalconsecutive profit (count of wins)85.99 (12)consecutive loss (count of losses)-30.77 (1)
Averageconsecutive wins8consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.02 08:30buy10.011814.560.001821.37
22020.12.02 10:36t/p10.011821.370.001821.376.811006.81
32020.12.04 14:15buy20.011842.710.001850.47
42020.12.04 16:15buy30.011843.510.001853.79
52020.12.07 16:49t/p20.011850.470.001850.477.371014.18
62020.12.07 16:52t/p30.011853.790.001853.799.891024.08
72020.12.18 01:00buy40.011884.910.001888.23
82020.12.18 14:09t/p40.011888.230.001888.233.321027.40
92021.01.05 05:45buy50.011942.150.001951.93
102021.01.05 16:16t/p50.011951.930.001951.939.781037.18
112021.02.09 03:15buy60.011835.690.001848.19
122021.02.09 11:54t/p60.011848.190.001848.1912.501049.68
132021.02.10 15:15buy70.011844.630.001851.18
142021.02.10 15:37t/p70.011851.180.001851.186.551056.23
152021.03.10 03:15buy80.011718.570.001729.53
162021.03.10 15:15buy90.011714.690.001724.01
172021.03.10 20:33t/p90.011724.010.001724.019.321065.55
182021.03.11 04:07t/p80.011729.530.001729.539.801075.35
192021.03.16 12:30buy100.011733.040.001737.94
202021.03.16 16:22t/p100.011737.940.001737.944.901080.25
212021.04.06 13:30buy110.011732.050.001734.85
222021.04.06 14:24t/p110.011734.850.001734.852.801083.05
232021.04.08 03:00buy120.011737.150.001740.09
242021.04.08 08:01t/p120.011740.090.001740.092.941085.99
252021.04.09 04:30buy130.011756.920.001760.31
262021.04.13 08:37close130.011726.920.001760.31-30.771055.22
272021.04.14 09:15buy140.011746.430.001751.74
282021.04.14 15:39buy150.011746.670.001755.93
292021.04.15 15:19t/p140.011751.740.001751.744.151059.38
302021.04.15 16:54t/p150.011755.930.001755.938.101067.48
312021.04.21 14:15buy160.011782.360.001790.96
322021.04.21 16:49t/p160.011790.960.001790.968.601076.08
+
diff --git a/Docs/Reports/14020427/StrategyTester 6.gif b/Docs/Reports/14020427/StrategyTester 6.gif new file mode 100644 index 0000000..c3ebb99 Binary files /dev/null and b/Docs/Reports/14020427/StrategyTester 6.gif differ diff --git a/Docs/Reports/14020427/StrategyTester 6.htm b/Docs/Reports/14020427/StrategyTester 6.htm new file mode 100644 index 0000000..70fb1e0 --- /dev/null +++ b/Docs/Reports/14020427/StrategyTester 6.htm @@ -0,0 +1,127 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.09.30 23:45 (2020.01.01 - 2021.10.01)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=408; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +step=0.01; maximum=0.1; shortCycleMultiplier=2; mediumCycleMultiplier=6; longCycleMultiplier=36;
Bars in test20043Ticks modelled22474457Modelling quality24.88%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (60)
Total net profit87.01Gross profit151.26Gross loss-64.25
Profit factor2.35Expected payoff2.90
Absolute drawdown36.70Maximal drawdown85.54 (7.74%)Relative drawdown7.74% (85.54)
Total trades30Short positions (won %)0 (0.00%)Long positions (won %)30 (83.33%)
Profit trades (% of total)25 (83.33%)Loss trades (% of total)5 (16.67%)
Largestprofit trade12.50loss trade-30.77
Averageprofit trade6.05loss trade-12.85
Maximumconsecutive wins (profit in money)12 (85.99)consecutive losses (loss in money)3 (-32.06)
Maximalconsecutive profit (count of wins)85.99 (12)consecutive loss (count of losses)-32.06 (3)
Averageconsecutive wins6consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.02 08:30buy10.011814.650.001821.46
22020.12.02 10:36t/p10.011821.460.001821.466.811006.81
32020.12.04 14:15buy20.011842.800.001850.56
42020.12.04 16:15buy30.011843.600.001853.88
52020.12.07 16:49t/p20.011850.560.001850.567.371014.18
62020.12.07 16:52t/p30.011853.880.001853.889.891024.08
72020.12.18 01:00buy40.011885.000.001888.32
82020.12.18 14:09t/p40.011888.320.001888.323.321027.40
92021.01.05 05:45buy50.011942.240.001952.02
102021.01.05 16:16t/p50.011952.020.001952.029.781037.18
112021.02.09 03:15buy60.011835.780.001848.28
122021.02.09 11:54t/p60.011848.280.001848.2812.501049.68
132021.02.10 15:15buy70.011844.720.001851.27
142021.02.10 15:37t/p70.011851.270.001851.276.551056.23
152021.03.10 03:15buy80.011718.660.001729.62
162021.03.10 15:15buy90.011714.780.001724.10
172021.03.10 21:06t/p90.011724.100.001724.109.321065.55
182021.03.11 04:07t/p80.011729.620.001729.629.801075.35
192021.03.16 12:30buy100.011733.130.001738.03
202021.03.16 16:24t/p100.011738.030.001738.034.901080.25
212021.04.06 13:30buy110.011732.140.001734.94
222021.04.06 14:24t/p110.011734.940.001734.942.801083.05
232021.04.08 03:00buy120.011737.240.001740.18
242021.04.08 08:03t/p120.011740.180.001740.182.941085.99
252021.04.09 04:30buy130.011757.010.001760.40
262021.04.13 08:36close130.011727.010.001760.40-30.771055.22
272021.04.14 09:15buy140.011746.520.001751.83
282021.04.14 15:39buy150.011746.760.001756.02
292021.04.15 15:19t/p140.011751.830.001751.834.151059.38
302021.04.15 16:54t/p150.011756.020.001756.028.101067.48
312021.04.21 14:15buy160.011782.450.001791.05
322021.04.21 16:49t/p160.011791.050.001791.058.601076.08
332021.05.10 23:15buy170.011837.760.001843.26
342021.05.11 11:45buy180.011837.410.001846.05
352021.05.12 16:04t/p170.011843.260.001843.264.731080.81
362021.05.14 15:16close180.011837.920.001846.05-1.421079.40
372021.05.19 06:45buy190.011869.240.001874.28
382021.05.19 16:00t/p190.011874.280.001874.285.041084.44
392021.07.02 20:45buy200.011785.590.001792.91
402021.07.05 11:06t/p200.011792.910.001792.916.931091.37
412021.07.06 01:06buy210.011791.770.001794.39
422021.07.06 04:45t/p210.011794.390.001794.392.621093.99
432021.07.12 03:30buy220.011809.370.001816.23
442021.07.13 15:39t/p220.011816.230.001816.236.471100.47
452021.07.15 08:45buy230.011828.770.001834.57
462021.07.19 15:06close230.011798.770.001834.57-30.771069.70
472021.07.30 04:30buy240.011829.950.001835.53
482021.07.30 10:15buy250.011830.190.001836.63
492021.08.04 16:09close240.011830.460.001835.53-0.651069.05
502021.08.04 16:22close250.011830.700.001836.63-0.651068.41
512021.08.12 07:30buy260.011752.610.001758.59
522021.08.13 09:24t/p260.011758.590.001758.595.591074.00
532021.08.17 08:15buy270.011787.930.001791.97
542021.08.17 08:52t/p270.011791.970.001791.974.041078.04
552021.09.15 06:45buy280.011804.030.001806.41
562021.09.15 09:15buy290.011803.620.001806.36
572021.09.15 15:24t/p290.011806.360.001806.362.741080.78
582021.09.15 15:24t/p280.011806.410.001806.412.381083.16
592021.09.22 04:45buy300.011776.600.001780.45
602021.09.22 21:07t/p300.011780.450.001780.453.851087.01
+
diff --git a/Docs/Reports/14020427/Whole StrategyTester 1.gif b/Docs/Reports/14020427/Whole StrategyTester 1.gif new file mode 100644 index 0000000..db66459 Binary files /dev/null and b/Docs/Reports/14020427/Whole StrategyTester 1.gif differ diff --git a/Docs/Reports/14020427/Whole StrategyTester 1.htm b/Docs/Reports/14020427/Whole StrategyTester 1.htm new file mode 100644 index 0000000..5e808a8 --- /dev/null +++ b/Docs/Reports/14020427/Whole StrategyTester 1.htm @@ -0,0 +1,321 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.06.29 23:45 (2020.01.01 - 2023.06.30)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=408; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +step=0.01; maximum=0.1; shortCycleMultiplier=2; mediumCycleMultiplier=6; longCycleMultiplier=36;
Bars in test61247Ticks modelled69753529Modelling quality40.22%
Mismatched charts errors33
Initial deposit1000.00SpreadCurrent (50)
Total net profit278.17Gross profit741.15Gross loss-462.98
Profit factor1.60Expected payoff2.19
Absolute drawdown36.51Maximal drawdown158.60 (12.94%)Relative drawdown12.94% (158.60)
Total trades127Short positions (won %)0 (0.00%)Long positions (won %)127 (83.46%)
Profit trades (% of total)106 (83.46%)Loss trades (% of total)21 (16.54%)
Largestprofit trade42.29loss trade-31.57
Averageprofit trade6.99loss trade-22.05
Maximumconsecutive wins (profit in money)19 (161.16)consecutive losses (loss in money)4 (-122.74)
Maximalconsecutive profit (count of wins)161.16 (19)consecutive loss (count of losses)-122.74 (4)
Averageconsecutive wins8consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.02 08:30buy10.011814.550.001821.36
22020.12.02 10:36t/p10.011821.360.001821.366.811006.81
32020.12.04 14:15buy20.011842.700.001850.46
42020.12.04 16:15buy30.011843.500.001853.78
52020.12.07 16:49t/p20.011850.460.001850.467.371014.18
62020.12.07 16:52t/p30.011853.780.001853.789.891024.07
72020.12.18 01:00buy40.011884.900.001888.22
82020.12.18 14:09t/p40.011888.220.001888.223.321027.39
92021.01.05 05:45buy50.011942.140.001951.92
102021.01.05 16:16t/p50.011951.920.001951.929.781037.17
112021.02.09 03:15buy60.011835.680.001848.18
122021.02.09 11:54t/p60.011848.180.001848.1812.501049.67
132021.02.10 15:15buy70.011844.620.001851.17
142021.02.10 15:37t/p70.011851.170.001851.176.551056.22
152021.03.10 03:15buy80.011718.560.001729.52
162021.03.10 15:15buy90.011714.680.001724.00
172021.03.10 20:33t/p90.011724.000.001724.009.321065.54
182021.03.11 04:07t/p80.011729.520.001729.529.791075.33
192021.03.16 12:30buy100.011733.030.001737.93
202021.03.16 16:22t/p100.011737.930.001737.934.901080.23
212021.04.06 13:30buy110.011732.040.001734.84
222021.04.06 14:24t/p110.011734.840.001734.842.801083.03
232021.04.08 03:00buy120.011737.140.001740.08
242021.04.08 08:01t/p120.011740.080.001740.082.941085.97
252021.04.09 04:30buy130.011756.910.001760.30
262021.04.13 08:37close130.011726.910.001760.30-30.781055.19
272021.04.14 09:15buy140.011746.420.001751.73
282021.04.14 15:39buy150.011746.660.001755.92
292021.04.15 15:19t/p140.011751.730.001751.734.141059.33
302021.04.15 16:54t/p150.011755.920.001755.928.091067.42
312021.04.21 14:15buy160.011782.350.001790.95
322021.04.21 16:49t/p160.011790.950.001790.958.601076.02
332021.05.10 23:15buy170.011837.660.001843.16
342021.05.11 11:45buy180.011837.310.001845.95
352021.05.12 16:04t/p170.011843.160.001843.164.721080.74
362021.05.14 15:15close180.011837.820.001845.95-1.441079.30
372021.05.19 06:45buy190.011869.140.001874.18
382021.05.19 16:00t/p190.011874.180.001874.185.041084.34
392021.07.02 20:45buy200.011785.490.001792.81
402021.07.05 10:54t/p200.011792.810.001792.816.931091.27
412021.07.06 01:06buy210.011791.670.001794.29
422021.07.06 04:45t/p210.011794.290.001794.292.621093.89
432021.07.12 03:30buy220.011809.270.001816.13
442021.07.13 15:39t/p220.011816.130.001816.136.471100.36
452021.07.15 08:45buy230.011828.670.001834.47
462021.07.19 15:06close230.011798.670.001834.47-30.781069.58
472021.07.30 04:30buy240.011829.850.001835.43
482021.07.30 10:15buy250.011830.090.001836.53
492021.08.04 16:09close240.011830.360.001835.43-0.661068.92
502021.08.04 16:09close250.011830.600.001836.53-0.661068.26
512021.08.12 07:30buy260.011752.510.001758.49
522021.08.13 09:24t/p260.011758.490.001758.495.591073.85
532021.08.17 08:15buy270.011787.830.001791.87
542021.08.17 08:52t/p270.011791.870.001791.874.041077.89
552021.09.15 06:45buy280.011803.930.001806.31
562021.09.15 09:15buy290.011803.520.001806.26
572021.09.15 15:24t/p290.011806.260.001806.262.741080.63
582021.09.15 15:24t/p280.011806.310.001806.312.381083.01
592021.09.22 04:45buy300.011776.500.001780.35
602021.09.22 21:07t/p300.011780.350.001780.353.851086.86
612021.10.01 10:00buy310.011756.070.001765.61
622021.10.04 09:00buy320.011761.720.001765.52
632021.10.04 17:39t/p320.011765.520.001765.523.801090.66
642021.10.04 17:39t/p310.011765.610.001765.619.151099.81
652021.10.13 04:00buy330.011761.780.001765.06
662021.10.13 10:39t/p330.011765.060.001765.063.281103.09
672021.10.21 04:00buy340.011784.190.001789.47
682021.10.22 09:31t/p340.011789.470.001789.474.891107.98
692021.10.25 01:15buy350.011793.840.001796.90
702021.10.25 03:54t/p350.011796.900.001796.903.061111.04
712021.11.05 15:15buy360.011795.930.001806.49
722021.11.05 17:22t/p360.011806.490.001806.4910.561121.60
732021.11.08 12:15buy370.011818.030.001823.33
742021.11.08 15:24t/p370.011823.330.001823.335.301126.90
752021.11.18 09:49buy380.011867.450.001875.47
762021.11.22 12:39close380.011837.450.001875.47-30.781096.12
772021.12.07 08:00buy390.011781.310.001785.35
782021.12.07 18:24t/p390.011785.350.001785.354.041100.16
792021.12.14 03:00buy400.011788.160.001793.66
802021.12.14 08:15buy410.011788.420.001793.70
812021.12.15 21:00close410.011758.410.001793.70-30.401069.76
822021.12.15 21:00close400.011758.150.001793.66-30.401039.36
832021.12.23 15:30buy420.011808.430.001813.23
842021.12.27 17:54t/p420.011813.230.001813.234.021043.38
852021.12.28 06:45buy430.011810.840.001813.84
862021.12.28 08:36t/p430.011813.840.001813.843.001046.38
872022.01.11 15:30buy440.011808.430.001814.37
882022.01.11 18:22t/p440.011814.370.001814.375.941052.32
892022.01.12 07:34buy450.011820.520.001824.18
902022.01.12 15:39t/p450.011824.180.001824.183.661055.98
912022.01.13 05:22buy460.011825.520.001827.44
922022.01.13 07:37t/p460.011827.440.001827.441.921057.90
932022.01.26 04:00buy470.011848.220.001850.96
942022.01.26 21:54close470.011818.220.001850.96-30.001027.90
952022.02.01 18:30buy480.011806.970.001815.85
962022.02.04 06:37close480.011807.480.001815.85-1.441026.46
972022.02.09 03:45buy490.011826.740.001829.48
982022.02.09 14:30buy500.011827.470.001828.75
992022.02.09 15:02t/p500.011828.750.001828.751.281027.74
1002022.02.09 15:04t/p490.011829.480.001829.482.741030.48
1012022.02.18 15:00buy510.011894.270.001904.75
1022022.02.21 01:24t/p510.011904.750.001904.7510.091040.57
1032022.03.02 08:45buy520.011937.680.001948.62
1042022.03.04 02:39t/p520.011948.620.001948.629.381049.95
1052022.03.04 11:15buy530.011941.660.001956.40
1062022.03.04 16:37t/p530.011956.400.001956.4014.741064.69
1072022.03.07 17:45buy540.011989.420.002032.10
1082022.03.08 06:45buy550.011989.920.001999.74
1092022.03.08 08:25t/p550.011999.740.001999.749.821074.51
1102022.03.08 16:49t/p540.012032.100.002032.1042.291116.80
1112022.03.24 08:15buy560.011942.900.001947.97
1122022.03.24 13:31t/p560.011947.970.001947.975.071121.87
1132022.03.25 03:00buy570.011963.080.001972.98
1142022.03.28 08:54close570.011933.080.001972.98-30.391091.49
1152022.04.08 03:00buy580.011933.340.001938.28
1162022.04.08 15:09t/p580.011938.280.001938.284.941096.43
1172022.04.11 08:45buy590.011944.970.001949.67
1182022.04.11 11:19t/p590.011949.670.001949.674.701101.13
1192022.04.12 14:15buy600.011956.680.001966.46
1202022.04.12 15:39t/p600.011966.460.001966.469.781110.91
1212022.04.13 04:49buy610.011968.170.001977.53
1222022.04.13 12:39t/p610.011977.530.001977.539.361120.27
1232022.04.14 02:00buy620.011978.670.001982.69
1242022.04.14 05:00buy630.011980.050.001986.23
1252022.04.14 10:45buy640.011977.510.001984.20
1262022.04.18 02:37t/p620.011982.690.001982.693.241123.51
1272022.04.18 02:46t/p640.011984.200.001984.205.911129.42
1282022.04.18 02:49t/p630.011986.230.001986.235.401134.82
1292022.05.05 13:30buy650.011898.250.001907.69
1302022.05.05 15:49t/p650.011907.690.001907.699.441144.26
1312022.05.20 18:15buy660.011844.180.001855.68
1322022.05.23 08:08t/p660.011855.680.001855.6811.111155.37
1332022.05.24 06:30buy670.011854.920.001865.38
1342022.05.24 16:47t/p670.011865.380.001865.3810.461165.83
1352022.05.30 16:30buy680.011860.850.001873.75
1362022.06.01 08:17close680.011830.850.001873.75-30.781135.05
1372022.06.09 02:15buy690.011854.330.001859.11
1382022.06.10 17:56t/p690.011859.110.001859.114.391139.44
1392022.06.17 08:15buy700.011847.380.001852.76
1402022.06.17 15:53t/p700.011852.760.001852.765.381144.82
1412022.07.22 09:00buy710.011716.260.001721.96
1422022.07.22 12:27t/p710.011721.960.001721.965.701150.52
1432022.07.25 01:15buy720.011726.480.001733.02
1442022.07.25 12:25t/p720.011733.020.001733.026.541157.06
1452022.08.01 05:15buy730.011764.130.001769.45
1462022.08.01 09:45buy740.011764.250.001769.84
1472022.08.01 12:38t/p730.011769.450.001769.455.321162.38
1482022.08.01 12:42t/p740.011769.840.001769.845.591167.97
1492022.08.01 21:00buy750.011769.400.001770.06
1502022.08.01 22:13t/p750.011770.060.001770.060.661168.63
1512022.08.02 12:15buy760.011773.830.001780.03
1522022.08.02 15:15t/p760.011780.030.001780.036.201174.83
1532022.08.05 07:45buy770.011792.040.001793.26
1542022.08.09 13:13close770.011792.550.001793.26-0.271174.56
1552022.08.24 17:00buy780.011746.270.001752.35
1562022.08.24 17:53t/p780.011752.350.001752.356.081180.64
1572022.09.05 20:00buy790.011712.390.001716.49
1582022.09.06 03:22t/p790.011716.490.001716.493.711184.35
1592022.09.08 07:15buy800.011716.950.001722.63
1602022.09.08 13:37t/p800.011722.630.001722.635.681190.03
1612022.09.30 16:45buy810.011669.210.001683.07
1622022.10.03 17:22t/p810.011683.070.001683.0713.471203.50
1632022.10.04 06:45buy820.011700.470.001710.19
1642022.10.04 10:18t/p820.011710.190.001710.199.721213.22
1652022.10.24 07:45buy830.011658.440.001667.68
1662022.10.26 03:00buy840.011653.220.001656.72
1672022.10.26 06:27t/p840.011656.720.001656.723.501216.72
1682022.10.26 10:08t/p830.011667.680.001667.688.461225.18
1692022.10.26 18:15buy850.011672.150.001688.25
1702022.10.27 08:45buy860.011669.870.001682.99
1712022.10.27 11:16buy870.011665.590.001671.30
1722022.10.28 15:30close850.011642.140.001688.25-31.571193.61
1732022.10.28 18:16close860.011639.870.001682.99-30.391163.22
1742022.10.31 10:33close870.011635.590.001671.30-30.781132.44
1752022.11.02 20:15buy880.011664.550.001700.75
1762022.11.02 22:53close880.011634.550.001700.75-30.001102.44
1772022.11.07 05:32buy890.011673.440.001678.96
1782022.11.07 11:23t/p890.011678.960.001678.965.521107.96
1792022.11.10 13:00buy900.011708.650.001717.29
1802022.11.10 15:31t/p900.011717.290.001717.298.641116.60
1812022.11.11 06:45buy910.011752.150.001756.21
1822022.11.11 07:27t/p910.011756.210.001756.214.061120.66
1832022.11.14 05:15buy920.011765.290.001773.39
1842022.11.14 09:45buy930.011762.510.001767.31
1852022.11.14 16:40t/p930.011767.310.001767.314.801125.46
1862022.11.14 17:12t/p920.011773.390.001773.398.101133.56
1872022.11.25 13:15buy940.011753.960.001758.35
1882022.11.28 10:41t/p940.011758.350.001758.354.001137.56
1892022.12.08 13:45buy950.011784.860.001789.50
1902022.12.08 15:23t/p950.011789.500.001789.504.641142.20
1912022.12.09 13:00buy960.011794.910.001806.33
1922022.12.13 15:33t/p960.011806.330.001806.3310.641152.84
1932022.12.14 03:01buy970.011811.600.001816.36
1942022.12.15 10:13close970.011781.590.001816.36-31.181121.66
1952022.12.22 02:15buy980.011816.230.001821.17
1962022.12.22 20:22close980.011786.230.001821.17-30.001091.66
1972022.12.30 03:00buy990.011816.600.001821.40
1982022.12.30 09:01t/p990.011821.400.001821.404.801096.46
1992023.01.05 09:30buy1000.011854.480.001861.84
2002023.01.06 17:21t/p1000.011861.840.001861.846.971103.43
2012023.01.09 14:15buy1010.011875.480.001880.19
2022023.01.09 16:48t/p1010.011880.190.001880.194.711108.14
2032023.01.10 21:15buy1020.011876.190.001884.01
2042023.01.11 06:00buy1030.011878.060.001884.46
2052023.01.11 07:38t/p1020.011884.010.001884.017.431115.57
2062023.01.11 10:47t/p1030.011884.460.001884.466.401121.97
2072023.01.13 10:00buy1040.011899.980.001909.62
2082023.01.13 16:50t/p1040.011909.620.001909.629.641131.61
2092023.01.20 17:30buy1050.011930.400.001939.82
2102023.01.24 08:53t/p1050.011939.820.001939.828.641140.25
2112023.02.01 06:15buy1060.011928.390.001935.43
2122023.02.01 21:42t/p1060.011935.430.001935.437.041147.29
2132023.02.20 04:30buy1070.011842.620.001851.18
2142023.02.22 14:31close1070.011843.130.001851.18-0.271147.02
2152023.03.01 04:00buy1080.011829.430.001841.49
2162023.03.01 15:01t/p1080.011841.490.001841.4912.061159.08
2172023.03.13 11:00buy1090.011885.840.001910.24
2182023.03.13 16:46t/p1090.011910.240.001910.2424.401183.48
2192023.03.14 08:15buy1100.011911.270.001920.74
2202023.03.14 14:15buy1110.011907.600.001919.24
2212023.03.14 19:00buy1120.011909.010.001921.99
2222023.03.15 14:01t/p1110.011919.240.001919.2411.251194.73
2232023.03.15 14:02t/p1100.011920.740.001920.749.081203.81
2242023.03.15 14:03t/p1120.011921.990.001921.9912.591216.40
2252023.03.16 01:15buy1130.011921.480.001928.68
2262023.03.16 14:20t/p1130.011928.680.001928.687.201223.60
2272023.03.16 21:15buy1140.011920.000.001929.92
2282023.03.17 06:53t/p1140.011929.920.001929.929.531233.13
2292023.03.20 06:15buy1150.011974.860.001978.82
2302023.03.20 07:46t/p1150.011978.820.001978.823.961237.09
2312023.03.24 05:58buy1160.011993.650.001997.21
2322023.03.24 12:08t/p1160.011997.210.001997.213.561240.65
2332023.03.31 14:00buy1170.011979.710.001984.51
2342023.03.31 15:33t/p1170.011984.510.001984.514.801245.45
2352023.04.12 15:45buy1180.012022.510.002038.50
2362023.04.13 15:45t/p1180.012038.500.002038.5014.821260.27
2372023.04.26 09:45buy1190.011998.820.002007.08
2382023.04.26 16:26t/p1190.012007.080.002007.088.261268.53
2392023.05.03 11:40buy1200.012016.570.002019.99
2402023.05.03 14:00buy1210.012016.860.002019.56
2412023.05.03 16:30buy1220.012018.960.002029.50
2422023.05.03 16:35t/p1210.012019.560.002019.562.701271.23
2432023.05.03 17:52t/p1200.012019.990.002019.993.421274.65
2442023.05.03 21:00t/p1220.012029.500.002029.5010.541285.19
2452023.05.31 08:00buy1230.011960.380.001966.70
2462023.05.31 13:45buy1240.011958.810.001965.97
2472023.05.31 16:42t/p1240.011965.970.001965.977.161292.35
2482023.05.31 16:42t/p1230.011966.700.001966.706.321298.67
2492023.06.01 02:15buy1250.011966.140.001972.32
2502023.06.01 16:34t/p1250.011972.320.001972.326.181304.85
2512023.06.02 05:00buy1260.011977.670.001981.00
2522023.06.02 06:06t/p1260.011981.000.001981.003.331308.18
2532023.06.02 12:45buy1270.011980.960.001991.34
2542023.06.02 21:02close1270.011950.950.001991.34-30.011278.17
+
diff --git a/Docs/Reports/14020427/Whole StrategyTester 2 - 1 Max Trade.gif b/Docs/Reports/14020427/Whole StrategyTester 2 - 1 Max Trade.gif new file mode 100644 index 0000000..47a7b83 Binary files /dev/null and b/Docs/Reports/14020427/Whole StrategyTester 2 - 1 Max Trade.gif differ diff --git a/Docs/Reports/14020427/Whole StrategyTester 2 - 1 Max Trade.htm b/Docs/Reports/14020427/Whole StrategyTester 2 - 1 Max Trade.htm new file mode 100644 index 0000000..fa1f1fb --- /dev/null +++ b/Docs/Reports/14020427/Whole StrategyTester 2 - 1 Max Trade.htm @@ -0,0 +1,273 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.06.29 23:45 (2020.01.01 - 2023.06.30)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=1; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=408; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +step=0.01; maximum=0.1; shortCycleMultiplier=2; mediumCycleMultiplier=6; longCycleMultiplier=36;
Bars in test61247Ticks modelled69753529Modelling quality40.22%
Mismatched charts errors33
Initial deposit1000.00SpreadCurrent (57)
Total net profit247.67Gross profit616.97Gross loss-369.31
Profit factor1.67Expected payoff2.40
Absolute drawdown14.52Maximal drawdown102.26 (8.60%)Relative drawdown8.60% (102.26)
Total trades103Short positions (won %)0 (0.00%)Long positions (won %)103 (84.47%)
Profit trades (% of total)87 (84.47%)Loss trades (% of total)16 (15.53%)
Largestprofit trade42.29loss trade-31.58
Averageprofit trade7.09loss trade-23.08
Maximumconsecutive wins (profit in money)14 (116.92)consecutive losses (loss in money)2 (-61.58)
Maximalconsecutive profit (count of wins)116.92 (14)consecutive loss (count of losses)-61.58 (2)
Averageconsecutive wins7consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.02 08:30buy10.011814.620.001821.43
22020.12.02 10:36t/p10.011821.430.001821.436.811006.81
32020.12.04 14:15buy20.011842.770.001850.53
42020.12.07 16:49t/p20.011850.530.001850.537.371014.18
52020.12.18 01:00buy30.011884.970.001888.29
62020.12.18 14:09t/p30.011888.290.001888.293.321017.50
72021.01.05 05:45buy40.011942.210.001951.99
82021.01.05 16:16t/p40.011951.990.001951.999.781027.28
92021.02.09 03:15buy50.011835.750.001848.25
102021.02.09 11:54t/p50.011848.250.001848.2512.501039.78
112021.02.10 15:15buy60.011844.690.001851.24
122021.02.10 15:37t/p60.011851.240.001851.246.551046.33
132021.03.10 03:15buy70.011718.630.001729.59
142021.03.11 04:07t/p70.011729.590.001729.599.791056.12
152021.03.16 12:30buy80.011733.100.001738.00
162021.03.16 16:22t/p80.011738.000.001738.004.901061.02
172021.04.06 13:30buy90.011732.110.001734.91
182021.04.06 14:24t/p90.011734.910.001734.912.801063.82
192021.04.08 03:00buy100.011737.210.001740.15
202021.04.08 08:01t/p100.011740.150.001740.152.941066.76
212021.04.09 04:30buy110.011756.980.001760.37
222021.04.13 08:37close110.011726.980.001760.37-30.781035.98
232021.04.14 09:15buy120.011746.490.001751.80
242021.04.15 15:19t/p120.011751.800.001751.804.141040.12
252021.04.21 14:15buy130.011782.420.001791.02
262021.04.21 16:49t/p130.011791.020.001791.028.601048.72
272021.05.10 23:15buy140.011837.730.001843.23
282021.05.12 16:04t/p140.011843.230.001843.234.721053.44
292021.05.19 06:45buy150.011869.210.001874.25
302021.05.19 16:00t/p150.011874.250.001874.255.041058.48
312021.07.02 20:45buy160.011785.560.001792.88
322021.07.05 11:06t/p160.011792.880.001792.886.931065.41
332021.07.06 01:06buy170.011791.740.001794.36
342021.07.06 04:45t/p170.011794.360.001794.362.621068.03
352021.07.12 03:30buy180.011809.340.001816.20
362021.07.13 15:39t/p180.011816.200.001816.206.471074.50
372021.07.15 08:45buy190.011828.740.001834.54
382021.07.19 15:06close190.011798.740.001834.54-30.781043.72
392021.07.30 04:30buy200.011829.920.001835.50
402021.08.04 16:09close200.011830.430.001835.50-0.661043.06
412021.08.12 07:30buy210.011752.580.001758.56
422021.08.13 09:24t/p210.011758.560.001758.565.591048.65
432021.08.17 08:15buy220.011787.900.001791.94
442021.08.17 08:52t/p220.011791.940.001791.944.041052.69
452021.09.15 06:45buy230.011804.000.001806.38
462021.09.15 15:24t/p230.011806.380.001806.382.381055.07
472021.09.22 04:45buy240.011776.570.001780.42
482021.09.22 21:07t/p240.011780.420.001780.423.851058.92
492021.10.01 10:00buy250.011756.140.001765.68
502021.10.04 17:39t/p250.011765.680.001765.689.151068.07
512021.10.13 04:00buy260.011761.850.001765.13
522021.10.13 10:39t/p260.011765.130.001765.133.281071.35
532021.10.21 04:00buy270.011784.260.001789.54
542021.10.22 09:31t/p270.011789.540.001789.544.891076.24
552021.10.25 01:15buy280.011793.910.001796.97
562021.10.25 03:54t/p280.011796.970.001796.973.061079.30
572021.11.05 15:15buy290.011796.000.001806.56
582021.11.05 17:22t/p290.011806.560.001806.5610.561089.86
592021.11.08 12:15buy300.011818.100.001823.40
602021.11.08 15:24t/p300.011823.400.001823.405.301095.16
612021.11.18 09:49buy310.011867.520.001875.54
622021.11.22 12:39close310.011837.520.001875.54-30.781064.38
632021.12.07 08:00buy320.011781.380.001785.42
642021.12.07 18:24t/p320.011785.420.001785.424.041068.42
652021.12.14 03:00buy330.011788.230.001793.73
662021.12.15 21:00close330.011758.230.001793.73-30.391038.03
672021.12.23 15:30buy340.011808.500.001813.30
682021.12.28 07:54t/p340.011813.300.001813.303.631041.66
692022.01.11 15:30buy350.011808.500.001814.44
702022.01.11 18:22t/p350.011814.440.001814.445.941047.60
712022.01.12 07:34buy360.011820.590.001824.25
722022.01.12 15:39t/p360.011824.250.001824.253.661051.26
732022.01.13 05:22buy370.011825.590.001827.51
742022.01.13 07:39t/p370.011827.510.001827.511.921053.18
752022.01.26 04:00buy380.011848.290.001851.03
762022.01.26 21:54close380.011818.290.001851.03-30.001023.18
772022.02.01 18:30buy390.011807.040.001815.92
782022.02.04 06:39close390.011807.550.001815.92-1.441021.74
792022.02.09 03:45buy400.011826.810.001829.55
802022.02.09 15:04t/p400.011829.550.001829.552.741024.48
812022.02.18 15:00buy410.011894.340.001904.82
822022.02.21 01:24t/p410.011904.820.001904.8210.091034.57
832022.03.02 08:45buy420.011937.750.001948.69
842022.03.04 02:39t/p420.011948.690.001948.699.381043.95
852022.03.04 11:15buy430.011941.730.001956.47
862022.03.04 16:37t/p430.011956.470.001956.4714.741058.69
872022.03.07 17:45buy440.011989.490.002032.17
882022.03.08 16:49t/p440.012032.170.002032.1742.291100.98
892022.03.24 08:15buy450.011942.970.001948.04
902022.03.24 13:31t/p450.011948.040.001948.045.071106.05
912022.03.25 03:00buy460.011963.150.001973.05
922022.03.28 08:54close460.011933.150.001973.05-30.391075.66
932022.04.08 03:00buy470.011933.410.001938.35
942022.04.08 15:09t/p470.011938.350.001938.354.941080.60
952022.04.11 08:45buy480.011945.040.001949.74
962022.04.11 11:19t/p480.011949.740.001949.744.701085.30
972022.04.12 14:15buy490.011956.750.001966.53
982022.04.12 15:39t/p490.011966.530.001966.539.781095.08
992022.04.13 04:49buy500.011968.240.001977.60
1002022.04.13 12:39t/p500.011977.600.001977.609.361104.44
1012022.04.14 02:00buy510.011978.740.001982.76
1022022.04.18 02:37t/p510.011982.760.001982.763.241107.68
1032022.05.05 13:30buy520.011898.320.001907.76
1042022.05.05 15:49t/p520.011907.760.001907.769.441117.12
1052022.05.20 18:15buy530.011844.250.001855.75
1062022.05.23 08:08t/p530.011855.750.001855.7511.111128.23
1072022.05.24 06:30buy540.011854.990.001865.45
1082022.05.24 16:47t/p540.011865.450.001865.4510.461138.69
1092022.05.30 16:30buy550.011860.920.001873.82
1102022.06.01 08:16close550.011830.910.001873.82-30.791107.90
1112022.06.09 02:15buy560.011854.400.001859.18
1122022.06.10 17:56t/p560.011859.180.001859.184.391112.29
1132022.06.17 08:15buy570.011847.450.001852.83
1142022.06.17 15:53t/p570.011852.830.001852.835.381117.67
1152022.07.22 09:00buy580.011716.330.001722.03
1162022.07.22 12:28t/p580.011722.030.001722.035.701123.37
1172022.07.25 01:15buy590.011726.550.001733.09
1182022.07.25 12:25t/p590.011733.090.001733.096.541129.91
1192022.08.01 05:15buy600.011764.200.001769.52
1202022.08.01 12:41t/p600.011769.520.001769.525.321135.23
1212022.08.01 21:00buy610.011769.470.001770.13
1222022.08.01 22:13t/p610.011770.130.001770.130.661135.89
1232022.08.02 12:15buy620.011773.900.001780.10
1242022.08.02 15:15t/p620.011780.100.001780.106.201142.09
1252022.08.05 07:45buy630.011792.110.001793.33
1262022.08.09 13:13close630.011792.630.001793.33-0.261141.83
1272022.08.24 17:00buy640.011746.340.001752.42
1282022.08.24 17:53t/p640.011752.420.001752.426.081147.91
1292022.09.05 20:00buy650.011712.460.001716.56
1302022.09.06 03:22t/p650.011716.560.001716.563.711151.62
1312022.09.08 07:15buy660.011717.020.001722.70
1322022.09.08 13:37t/p660.011722.700.001722.705.681157.30
1332022.09.30 16:45buy670.011669.280.001683.14
1342022.10.03 17:22t/p670.011683.140.001683.1413.471170.77
1352022.10.04 06:45buy680.011700.540.001710.26
1362022.10.04 10:18t/p680.011710.260.001710.269.721180.49
1372022.10.24 07:45buy690.011658.510.001667.75
1382022.10.26 10:28t/p690.011667.750.001667.758.461188.96
1392022.10.26 18:15buy700.011672.220.001688.32
1402022.10.28 15:30close700.011642.200.001688.32-31.581157.38
1412022.11.02 20:15buy710.011664.620.001700.82
1422022.11.02 22:53close710.011634.620.001700.82-30.001127.38
1432022.11.07 05:32buy720.011673.510.001679.03
1442022.11.07 11:26t/p720.011679.030.001679.035.521132.90
1452022.11.10 13:00buy730.011708.720.001717.36
1462022.11.10 15:31t/p730.011717.360.001717.368.641141.54
1472022.11.11 06:45buy740.011752.220.001756.28
1482022.11.11 07:27t/p740.011756.280.001756.284.061145.60
1492022.11.14 05:15buy750.011765.360.001773.46
1502022.11.14 17:12t/p750.011773.460.001773.468.101153.70
1512022.11.25 13:15buy760.011754.030.001758.42
1522022.11.28 10:41t/p760.011758.420.001758.424.001157.70
1532022.12.08 13:45buy770.011784.930.001789.57
1542022.12.08 15:33t/p770.011789.570.001789.574.641162.34
1552022.12.09 13:00buy780.011794.980.001806.40
1562022.12.13 15:33t/p780.011806.400.001806.4010.641172.98
1572022.12.14 03:01buy790.011811.670.001816.43
1582022.12.15 10:13close790.011781.650.001816.43-31.191141.79
1592022.12.22 02:15buy800.011816.300.001821.24
1602022.12.22 20:22close800.011786.290.001821.24-30.011111.78
1612022.12.30 03:00buy810.011816.670.001821.47
1622022.12.30 09:01t/p810.011821.470.001821.474.801116.58
1632023.01.05 09:30buy820.011854.550.001861.91
1642023.01.06 17:32t/p820.011861.910.001861.916.971123.55
1652023.01.09 14:15buy830.011875.550.001880.26
1662023.01.09 16:48t/p830.011880.260.001880.264.711128.26
1672023.01.10 21:15buy840.011876.260.001884.08
1682023.01.11 07:38t/p840.011884.080.001884.087.431135.69
1692023.01.13 10:00buy850.011900.050.001909.69
1702023.01.13 16:50t/p850.011909.690.001909.699.641145.33
1712023.01.20 17:30buy860.011930.470.001939.89
1722023.01.24 09:02t/p860.011939.890.001939.898.641153.97
1732023.02.01 06:15buy870.011928.460.001935.50
1742023.02.01 21:42t/p870.011935.500.001935.507.041161.01
1752023.02.20 04:30buy880.011842.690.001851.25
1762023.02.22 14:31close880.011843.210.001851.25-0.261160.75
1772023.03.01 04:00buy890.011829.500.001841.56
1782023.03.01 16:38t/p890.011841.560.001841.5612.061172.81
1792023.03.13 11:00buy900.011885.910.001910.31
1802023.03.13 16:46t/p900.011910.310.001910.3124.401197.21
1812023.03.14 08:15buy910.011911.340.001920.81
1822023.03.15 14:02t/p910.011920.810.001920.819.081206.29
1832023.03.16 01:15buy920.011921.550.001928.75
1842023.03.16 14:21t/p920.011928.750.001928.757.201213.49
1852023.03.16 21:15buy930.011920.070.001929.99
1862023.03.17 06:54t/p930.011929.990.001929.999.531223.02
1872023.03.20 06:15buy940.011974.930.001978.89
1882023.03.20 07:46t/p940.011978.890.001978.893.961226.98
1892023.03.24 05:58buy950.011993.720.001997.28
1902023.03.24 12:08t/p950.011997.280.001997.283.561230.54
1912023.03.31 14:00buy960.011979.780.001984.58
1922023.03.31 15:33t/p960.011984.580.001984.584.801235.34
1932023.04.12 15:45buy970.012022.580.002038.57
1942023.04.13 15:46t/p970.012038.570.002038.5714.821250.16
1952023.04.26 09:45buy980.011998.890.002007.15
1962023.04.26 16:26t/p980.012007.150.002007.158.261258.42
1972023.05.03 11:40buy990.012016.640.002020.06
1982023.05.03 17:52t/p990.012020.060.002020.063.421261.84
1992023.05.31 08:00buy1000.011960.450.001966.77
2002023.05.31 16:42t/p1000.011966.770.001966.776.321268.16
2012023.06.01 02:15buy1010.011966.210.001972.39
2022023.06.01 16:35t/p1010.011972.390.001972.396.181274.34
2032023.06.02 05:00buy1020.011977.740.001981.07
2042023.06.02 06:06t/p1020.011981.070.001981.073.331277.67
2052023.06.02 12:45buy1030.011981.030.001991.41
2062023.06.02 21:01close1030.011951.030.001991.41-30.001247.67
+
diff --git a/Docs/Reports/14020427/Whole StrategyTester 3.gif b/Docs/Reports/14020427/Whole StrategyTester 3.gif new file mode 100644 index 0000000..83d01e7 Binary files /dev/null and b/Docs/Reports/14020427/Whole StrategyTester 3.gif differ diff --git a/Docs/Reports/14020427/Whole StrategyTester 3.htm b/Docs/Reports/14020427/Whole StrategyTester 3.htm new file mode 100644 index 0000000..11f1abf --- /dev/null +++ b/Docs/Reports/14020427/Whole StrategyTester 3.htm @@ -0,0 +1,321 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.06.29 23:45 (2020.01.01 - 2023.06.30)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=252; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +step=0.01; maximum=0.1; shortCycleMultiplier=2; mediumCycleMultiplier=6; longCycleMultiplier=36;
Bars in test61247Ticks modelled69753529Modelling quality40.22%
Mismatched charts errors33
Initial deposit1000.00SpreadCurrent (60)
Total net profit235.24Gross profit679.38Gross loss-444.14
Profit factor1.53Expected payoff1.85
Absolute drawdown40.51Maximal drawdown135.42 (12.37%)Relative drawdown12.37% (135.42)
Total trades127Short positions (won %)0 (0.00%)Long positions (won %)127 (81.89%)
Profit trades (% of total)104 (81.89%)Loss trades (% of total)23 (18.11%)
Largestprofit trade42.24loss trade-31.31
Averageprofit trade6.53loss trade-19.31
Maximumconsecutive wins (profit in money)21 (167.96)consecutive losses (loss in money)3 (-73.90)
Maximalconsecutive profit (count of wins)167.96 (21)consecutive loss (count of losses)-73.90 (3)
Averageconsecutive wins7consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.02 08:30buy10.011814.650.001821.46
22020.12.02 10:36t/p10.011821.460.001821.466.811006.81
32020.12.04 14:15buy20.011842.800.001850.56
42020.12.04 16:15buy30.011843.600.001853.88
52020.12.07 16:49t/p20.011850.560.001850.567.321014.13
62020.12.07 16:52t/p30.011853.880.001853.889.841023.98
72020.12.18 01:00buy40.011885.000.001888.32
82020.12.18 14:09t/p40.011888.320.001888.323.321027.30
92021.01.05 05:45buy50.011942.240.001952.02
102021.01.05 16:16t/p50.011952.020.001952.029.781037.08
112021.02.09 03:15buy60.011835.780.001848.28
122021.02.09 11:54t/p60.011848.280.001848.2812.501049.58
132021.02.10 15:15buy70.011844.720.001851.27
142021.02.10 15:37t/p70.011851.270.001851.276.551056.13
152021.03.10 03:15buy80.011718.660.001729.62
162021.03.10 15:15buy90.011714.780.001724.10
172021.03.10 21:06t/p90.011724.100.001724.109.321065.45
182021.03.11 04:07t/p80.011729.620.001729.629.651075.10
192021.03.16 12:30buy100.011733.130.001738.03
202021.03.16 16:24t/p100.011738.030.001738.034.901080.00
212021.04.06 13:30buy110.011732.140.001734.94
222021.04.06 14:24t/p110.011734.940.001734.942.801082.80
232021.04.08 03:00buy120.011737.240.001740.18
242021.04.08 08:03t/p120.011740.180.001740.182.941085.74
252021.04.09 04:30buy130.011757.010.001760.40
262021.04.13 08:36close130.011727.010.001760.40-30.871054.87
272021.04.14 09:15buy140.011746.520.001751.83
282021.04.14 15:39buy150.011746.760.001756.02
292021.04.15 15:19t/p140.011751.830.001751.834.001058.88
302021.04.15 16:54t/p150.011756.020.001756.027.951066.83
312021.04.21 14:15buy160.011782.450.001791.05
322021.04.21 16:49t/p160.011791.050.001791.058.601075.43
332021.05.10 23:15buy170.011837.760.001843.26
342021.05.11 11:45buy180.011837.410.001846.05
352021.05.12 15:51close180.011837.920.001846.050.071075.50
362021.05.12 15:52close170.011838.270.001843.26-0.361075.14
372021.05.19 06:45buy190.011869.240.001874.28
382021.05.19 16:00t/p190.011874.280.001874.285.041080.18
392021.07.02 20:45buy200.011785.590.001792.91
402021.07.05 11:06t/p200.011792.910.001792.916.881087.07
412021.07.06 01:06buy210.011791.770.001794.39
422021.07.06 04:45t/p210.011794.390.001794.392.621089.69
432021.07.12 03:30buy220.011809.370.001816.23
442021.07.13 15:04close220.011809.880.001816.230.071089.76
452021.07.15 08:45buy230.011828.770.001834.57
462021.07.19 15:06close230.011798.770.001834.57-30.871058.89
472021.07.30 04:30buy240.011829.950.001835.53
482021.07.30 10:15buy250.011830.190.001836.63
492021.08.03 21:30close240.011810.040.001835.53-20.781038.11
502021.08.04 04:15close250.011809.250.001836.63-22.251015.86
512021.08.12 07:30buy260.011752.610.001758.59
522021.08.13 09:24t/p260.011758.590.001758.595.541021.41
532021.08.17 08:15buy270.011787.930.001791.97
542021.08.17 08:52t/p270.011791.970.001791.974.041025.45
552021.09.15 06:45buy280.011804.030.001806.41
562021.09.15 09:15buy290.011803.620.001806.36
572021.09.15 15:24t/p290.011806.360.001806.362.741028.19
582021.09.15 15:24t/p280.011806.410.001806.412.381030.57
592021.09.22 04:45buy300.011776.600.001780.45
602021.09.22 21:07t/p300.011780.450.001780.453.851034.42
612021.10.01 10:00buy310.011756.170.001765.71
622021.10.04 09:00buy320.011761.820.001765.62
632021.10.04 17:39t/p320.011765.620.001765.623.801038.22
642021.10.04 17:39t/p310.011765.710.001765.719.101047.32
652021.10.13 04:00buy330.011761.880.001765.16
662021.10.13 10:39t/p330.011765.160.001765.163.281050.60
672021.10.21 04:00buy340.011784.290.001789.57
682021.10.22 09:31t/p340.011789.570.001789.574.841055.45
692021.10.25 01:15buy350.011793.940.001797.00
702021.10.25 03:54t/p350.011797.000.001797.003.061058.51
712021.11.05 15:15buy360.011796.030.001806.59
722021.11.05 17:22t/p360.011806.590.001806.5910.561069.07
732021.11.08 12:15buy370.011818.130.001823.43
742021.11.08 15:24t/p370.011823.430.001823.435.301074.37
752021.11.18 09:49buy380.011867.550.001875.57
762021.11.22 12:39close380.011837.550.001875.57-30.871043.50
772021.12.07 08:00buy390.011781.410.001785.45
782021.12.07 18:24t/p390.011785.450.001785.454.041047.54
792021.12.14 03:00buy400.011788.260.001793.76
802021.12.14 08:15buy410.011788.520.001793.80
812021.12.15 21:00close410.011758.510.001793.80-30.451017.09
822021.12.15 21:00close400.011758.250.001793.76-30.45986.65
832021.12.23 15:30buy420.011808.530.001813.33
842021.12.28 01:00close420.011811.350.001813.331.51988.16
852021.12.28 06:45buy430.011810.940.001813.94
862021.12.28 08:36t/p430.011813.940.001813.943.00991.16
872022.01.11 15:30buy440.011808.530.001814.47
882022.01.11 18:22t/p440.011814.470.001814.475.94997.10
892022.01.12 07:34buy450.011820.620.001824.28
902022.01.12 15:39t/p450.011824.280.001824.283.661000.76
912022.01.13 05:22buy460.011825.620.001827.54
922022.01.13 07:39t/p460.011827.540.001827.541.921002.68
932022.01.26 04:00buy470.011848.320.001851.06
942022.01.26 21:54close470.011818.320.001851.06-30.00972.68
952022.02.01 18:30buy480.011807.070.001815.95
962022.02.03 04:00close480.011808.370.001815.95-0.44972.24
972022.02.09 03:45buy490.011826.840.001829.58
982022.02.09 14:30buy500.011827.570.001828.85
992022.02.09 15:04t/p500.011828.850.001828.851.28973.52
1002022.02.09 15:04t/p490.011829.580.001829.582.74976.26
1012022.02.18 15:00buy510.011894.370.001904.85
1022022.02.21 01:24t/p510.011904.850.001904.8510.04986.30
1032022.03.02 08:45buy520.011937.780.001948.72
1042022.03.03 22:19close520.011938.290.001948.72-0.80985.51
1052022.03.04 11:15buy530.011941.760.001956.50
1062022.03.04 16:37t/p530.011956.500.001956.5014.741000.25
1072022.03.07 17:45buy540.011989.520.002032.20
1082022.03.08 06:45buy550.011990.020.001999.84
1092022.03.08 08:30t/p550.011999.840.001999.849.821010.07
1102022.03.08 16:49t/p540.012032.200.002032.2042.241052.31
1112022.03.24 08:15buy560.011943.000.001948.07
1122022.03.24 13:31t/p560.011948.070.001948.075.071057.38
1132022.03.25 03:00buy570.011963.180.001973.08
1142022.03.28 08:54close570.011933.170.001973.08-30.451026.94
1152022.04.08 03:00buy580.011933.440.001938.38
1162022.04.08 15:09t/p580.011938.380.001938.384.941031.88
1172022.04.11 08:45buy590.011945.070.001949.77
1182022.04.11 11:19t/p590.011949.770.001949.774.701036.58
1192022.04.12 14:15buy600.011956.780.001966.56
1202022.04.12 15:39t/p600.011966.560.001966.569.781046.36
1212022.04.13 04:49buy610.011968.270.001977.63
1222022.04.13 12:39t/p610.011977.630.001977.639.361055.72
1232022.04.14 02:00buy620.011978.770.001982.79
1242022.04.14 05:00buy630.011980.150.001986.33
1252022.04.14 10:45buy640.011977.610.001984.30
1262022.04.18 02:37t/p620.011982.790.001982.793.151058.87
1272022.04.18 02:46t/p640.011984.300.001984.305.821064.69
1282022.04.18 02:49t/p630.011986.330.001986.335.311069.99
1292022.05.05 13:30buy650.011898.350.001907.79
1302022.05.05 15:49t/p650.011907.790.001907.799.441079.43
1312022.05.20 18:15buy660.011844.280.001855.78
1322022.05.23 08:08t/p660.011855.780.001855.7811.061090.50
1332022.05.24 06:30buy670.011855.020.001865.48
1342022.05.24 16:47t/p670.011865.480.001865.4810.461100.96
1352022.05.30 16:30buy680.011860.950.001873.85
1362022.06.01 08:16close680.011830.950.001873.85-30.871070.09
1372022.06.09 02:15buy690.011854.430.001859.21
1382022.06.10 17:51close690.011854.940.001859.210.071070.16
1392022.06.17 08:15buy700.011847.480.001852.86
1402022.06.22 04:45close700.011828.420.001852.86-20.371049.80
1412022.07.22 09:00buy710.011716.360.001722.06
1422022.07.22 12:28t/p710.011722.060.001722.065.701055.50
1432022.07.25 01:15buy720.011726.580.001733.12
1442022.07.25 12:25t/p720.011733.120.001733.126.541062.04
1452022.08.01 05:15buy730.011764.230.001769.55
1462022.08.01 09:45buy740.011764.350.001769.94
1472022.08.01 12:41t/p730.011769.550.001769.555.321067.36
1482022.08.01 12:42t/p740.011769.940.001769.945.591072.95
1492022.08.01 21:00buy750.011769.500.001770.16
1502022.08.01 22:13t/p750.011770.160.001770.160.661073.61
1512022.08.02 12:15buy760.011773.930.001780.13
1522022.08.02 15:15t/p760.011780.130.001780.136.201079.81
1532022.08.05 07:45buy770.011792.140.001793.36
1542022.08.09 11:25close770.011792.660.001793.36-0.351079.46
1552022.08.24 17:00buy780.011746.370.001752.45
1562022.08.24 17:53t/p780.011752.450.001752.456.081085.54
1572022.09.05 20:00buy790.011712.490.001716.59
1582022.09.06 03:22t/p790.011716.590.001716.593.661089.20
1592022.09.08 07:15buy800.011717.050.001722.73
1602022.09.08 13:37t/p800.011722.730.001722.735.681094.88
1612022.09.30 16:45buy810.011669.310.001683.17
1622022.10.03 17:22t/p810.011683.170.001683.1713.421108.31
1632022.10.04 06:45buy820.011700.570.001710.29
1642022.10.04 10:18t/p820.011710.290.001710.299.721118.03
1652022.10.24 07:45buy830.011658.540.001667.78
1662022.10.25 16:48close830.011659.050.001667.780.071118.10
1672022.10.26 03:00buy840.011653.320.001656.82
1682022.10.26 06:27t/p840.011656.820.001656.823.501121.60
1692022.10.26 18:15buy850.011672.250.001688.35
1702022.10.27 08:45buy860.011669.970.001683.09
1712022.10.27 11:16buy870.011665.690.001671.40
1722022.10.28 04:58close870.011666.210.001671.400.081121.68
1732022.10.28 04:58close860.011666.210.001683.09-4.201117.49
1742022.10.28 04:58close850.011666.210.001688.35-7.781109.71
1752022.11.02 20:15buy880.011664.650.001682.75
1762022.11.02 22:53close880.011634.640.001682.75-30.011079.70
1772022.11.07 05:32buy890.011673.540.001679.06
1782022.11.07 11:26t/p890.011679.060.001679.065.521085.22
1792022.11.10 13:00buy900.011708.750.001717.39
1802022.11.10 15:31t/p900.011717.390.001717.398.641093.86
1812022.11.11 06:45buy910.011752.250.001756.31
1822022.11.11 07:27t/p910.011756.310.001756.314.061097.92
1832022.11.14 05:15buy920.011765.390.001773.49
1842022.11.14 09:45buy930.011762.610.001767.41
1852022.11.14 16:40t/p930.011767.410.001767.414.801102.72
1862022.11.14 17:12t/p920.011773.490.001773.498.101110.82
1872022.11.25 13:15buy940.011754.060.001758.45
1882022.11.28 10:41t/p940.011758.450.001758.453.951114.77
1892022.12.08 13:45buy950.011784.960.001789.60
1902022.12.08 15:33t/p950.011789.600.001789.604.641119.41
1912022.12.09 13:00buy960.011795.010.001806.43
1922022.12.13 15:31close960.011795.560.001806.43-0.321119.09
1932022.12.14 03:01buy970.011811.700.001816.46
1942022.12.15 10:13close970.011781.700.001816.46-31.311087.78
1952022.12.22 02:15buy980.011816.330.001821.27
1962022.12.22 20:22close980.011786.320.001821.27-30.011057.77
1972022.12.30 03:00buy990.011816.700.001821.50
1982022.12.30 09:01t/p990.011821.500.001821.504.801062.57
1992023.01.05 09:30buy1000.011854.580.001861.94
2002023.01.06 17:42t/p1000.011861.940.001861.946.921069.50
2012023.01.09 14:15buy1010.011875.580.001880.29
2022023.01.09 16:48t/p1010.011880.290.001880.294.711074.21
2032023.01.10 21:15buy1020.011876.290.001884.11
2042023.01.11 06:00buy1030.011878.160.001884.56
2052023.01.11 07:38t/p1020.011884.110.001884.117.381081.59
2062023.01.11 10:48t/p1030.011884.560.001884.566.401087.99
2072023.01.13 10:00buy1040.011900.080.001909.72
2082023.01.13 16:50t/p1040.011909.720.001909.729.641097.63
2092023.01.20 17:30buy1050.011930.500.001939.92
2102023.01.24 03:00close1050.011931.020.001939.92-0.351097.28
2112023.02.01 06:15buy1060.011928.490.001935.53
2122023.02.01 21:42t/p1060.011935.530.001935.537.041104.32
2132023.02.20 04:30buy1070.011842.720.001851.28
2142023.02.21 16:35close1070.011843.230.001851.280.071104.40
2152023.03.01 04:00buy1080.011829.530.001841.59
2162023.03.01 16:38t/p1080.011841.590.001841.5912.061116.46
2172023.03.13 11:00buy1090.011885.940.001910.34
2182023.03.13 16:46t/p1090.011910.340.001910.3424.401140.86
2192023.03.14 08:15buy1100.011911.370.001920.84
2202023.03.14 14:15buy1110.011907.700.001919.34
2212023.03.14 19:00buy1120.011909.110.001922.09
2222023.03.15 14:01t/p1110.011919.340.001919.3411.201152.06
2232023.03.15 14:02t/p1100.011920.840.001920.849.031161.10
2242023.03.15 14:03t/p1120.011922.090.001922.0912.541173.64
2252023.03.16 01:15buy1130.011921.580.001928.78
2262023.03.16 14:21t/p1130.011928.780.001928.787.201180.84
2272023.03.16 21:15buy1140.011920.100.001930.02
2282023.03.17 06:54t/p1140.011930.020.001930.029.481190.33
2292023.03.20 06:15buy1150.011974.960.001978.92
2302023.03.20 07:46t/p1150.011978.920.001978.923.961194.29
2312023.03.24 05:58buy1160.011993.750.001997.31
2322023.03.24 12:08t/p1160.011997.310.001997.313.561197.85
2332023.03.31 14:00buy1170.011979.810.001984.61
2342023.03.31 15:33t/p1170.011984.610.001984.614.801202.65
2352023.04.12 15:45buy1180.012022.610.002038.60
2362023.04.13 15:46t/p1180.012038.600.002038.6014.681217.33
2372023.04.26 09:45buy1190.011998.920.002007.18
2382023.04.26 16:26t/p1190.012007.180.002007.188.261225.59
2392023.05.03 11:40buy1200.012016.670.002020.09
2402023.05.03 14:00buy1210.012016.960.002019.66
2412023.05.03 16:30buy1220.012019.060.002029.60
2422023.05.03 16:35t/p1210.012019.660.002019.662.701228.29
2432023.05.03 17:52t/p1200.012020.090.002020.093.421231.71
2442023.05.03 21:00t/p1220.012029.600.002029.6010.541242.25
2452023.05.31 08:00buy1230.011960.480.001966.80
2462023.05.31 13:45buy1240.011958.910.001966.07
2472023.05.31 16:42t/p1240.011966.070.001966.077.161249.41
2482023.05.31 16:42t/p1230.011966.800.001966.806.321255.73
2492023.06.01 02:15buy1250.011966.240.001972.42
2502023.06.01 16:35t/p1250.011972.420.001972.426.181261.91
2512023.06.02 05:00buy1260.011977.770.001981.10
2522023.06.02 06:06t/p1260.011981.100.001981.103.331265.24
2532023.06.02 12:45buy1270.011981.060.001991.44
2542023.06.02 20:51close1270.011951.060.001991.44-30.001235.24
+
diff --git a/Docs/Reports/14020427/Whole StrategyTester.gif b/Docs/Reports/14020427/Whole StrategyTester.gif new file mode 100644 index 0000000..84c508e Binary files /dev/null and b/Docs/Reports/14020427/Whole StrategyTester.gif differ diff --git a/Docs/Reports/14020427/Whole StrategyTester.htm b/Docs/Reports/14020427/Whole StrategyTester.htm new file mode 100644 index 0000000..31e957c --- /dev/null +++ b/Docs/Reports/14020427/Whole StrategyTester.htm @@ -0,0 +1,333 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.07.19 23:45 (2020.01.01 - 2023.07.20)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=408; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +step=0.01; maximum=0.1; shortCycleMultiplier=2; mediumCycleMultiplier=6; longCycleMultiplier=36;
Bars in test62525Ticks modelled71468432Modelling qualityn/a
Mismatched charts errors753
Initial deposit1000.00SpreadCurrent (60)
Total net profit225.21Gross profit749.40Gross loss-524.19
Profit factor1.43Expected payoff1.69
Absolute drawdown36.70Maximal drawdown158.55 (13.22%)Relative drawdown13.22% (158.55)
Total trades133Short positions (won %)0 (0.00%)Long positions (won %)133 (81.95%)
Profit trades (% of total)109 (81.95%)Loss trades (% of total)24 (18.05%)
Largestprofit trade42.29loss trade-32.32
Averageprofit trade6.88loss trade-21.84
Maximumconsecutive wins (profit in money)19 (161.19)consecutive losses (loss in money)4 (-122.72)
Maximalconsecutive profit (count of wins)161.19 (19)consecutive loss (count of losses)-122.72 (4)
Averageconsecutive wins8consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.02 08:30buy10.011814.650.001821.46
22020.12.02 10:36t/p10.011821.460.001821.466.811006.81
32020.12.04 14:15buy20.011842.800.001850.56
42020.12.04 16:15buy30.011843.600.001853.88
52020.12.07 16:49t/p20.011850.560.001850.567.371014.18
62020.12.07 16:52t/p30.011853.880.001853.889.891024.08
72020.12.18 01:00buy40.011885.000.001888.32
82020.12.18 14:09t/p40.011888.320.001888.323.321027.40
92021.01.05 05:45buy50.011942.240.001952.02
102021.01.05 16:16t/p50.011952.020.001952.029.781037.18
112021.02.09 03:15buy60.011835.780.001848.28
122021.02.09 11:54t/p60.011848.280.001848.2812.501049.68
132021.02.10 15:15buy70.011844.720.001851.27
142021.02.10 15:37t/p70.011851.270.001851.276.551056.23
152021.03.10 03:15buy80.011718.660.001729.62
162021.03.10 15:15buy90.011714.780.001724.10
172021.03.10 21:06t/p90.011724.100.001724.109.321065.55
182021.03.11 04:07t/p80.011729.620.001729.629.801075.35
192021.03.16 12:30buy100.011733.130.001738.03
202021.03.16 16:24t/p100.011738.030.001738.034.901080.25
212021.04.06 13:30buy110.011732.140.001734.94
222021.04.06 14:24t/p110.011734.940.001734.942.801083.05
232021.04.08 03:00buy120.011737.240.001740.18
242021.04.08 08:03t/p120.011740.180.001740.182.941085.99
252021.04.09 04:30buy130.011757.010.001760.40
262021.04.13 08:36close130.011727.010.001760.40-30.771055.22
272021.04.14 09:15buy140.011746.520.001751.83
282021.04.14 15:39buy150.011746.760.001756.02
292021.04.15 15:19t/p140.011751.830.001751.834.151059.38
302021.04.15 16:54t/p150.011756.020.001756.028.101067.48
312021.04.21 14:15buy160.011782.450.001791.05
322021.04.21 16:49t/p160.011791.050.001791.058.601076.08
332021.05.10 23:15buy170.011837.760.001843.26
342021.05.11 11:45buy180.011837.410.001846.05
352021.05.12 16:04t/p170.011843.260.001843.264.731080.81
362021.05.14 15:16close180.011837.920.001846.05-1.421079.40
372021.05.19 06:45buy190.011869.240.001874.28
382021.05.19 16:00t/p190.011874.280.001874.285.041084.44
392021.07.02 20:45buy200.011785.590.001792.91
402021.07.05 11:06t/p200.011792.910.001792.916.931091.37
412021.07.06 01:06buy210.011791.770.001794.39
422021.07.06 04:45t/p210.011794.390.001794.392.621093.99
432021.07.12 03:30buy220.011809.370.001816.23
442021.07.13 15:39t/p220.011816.230.001816.236.471100.47
452021.07.15 08:45buy230.011828.770.001834.57
462021.07.19 15:06close230.011798.770.001834.57-30.771069.70
472021.07.30 04:30buy240.011829.950.001835.53
482021.07.30 10:15buy250.011830.190.001836.63
492021.08.04 16:09close240.011830.460.001835.53-0.651069.05
502021.08.04 16:22close250.011830.700.001836.63-0.651068.41
512021.08.12 07:30buy260.011752.610.001758.59
522021.08.13 09:24t/p260.011758.590.001758.595.591074.00
532021.08.17 08:15buy270.011787.930.001791.97
542021.08.17 08:52t/p270.011791.970.001791.974.041078.04
552021.09.15 06:45buy280.011804.030.001806.41
562021.09.15 09:15buy290.011803.620.001806.36
572021.09.15 15:24t/p290.011806.360.001806.362.741080.78
582021.09.15 15:24t/p280.011806.410.001806.412.381083.16
592021.09.22 04:45buy300.011776.600.001780.45
602021.09.22 21:07t/p300.011780.450.001780.453.851087.01
612021.10.01 10:00buy310.011756.170.001765.71
622021.10.04 09:00buy320.011761.820.001765.62
632021.10.04 17:39t/p320.011765.620.001765.623.801090.81
642021.10.04 17:39t/p310.011765.710.001765.719.151099.97
652021.10.13 04:00buy330.011761.880.001765.16
662021.10.13 10:39t/p330.011765.160.001765.163.281103.25
672021.10.21 04:00buy340.011784.290.001789.57
682021.10.22 09:31t/p340.011789.570.001789.574.891108.14
692021.10.25 01:15buy350.011793.940.001797.00
702021.10.25 03:54t/p350.011797.000.001797.003.061111.20
712021.11.05 15:15buy360.011796.030.001806.59
722021.11.05 17:22t/p360.011806.590.001806.5910.561121.76
732021.11.08 12:15buy370.011818.130.001823.43
742021.11.08 15:24t/p370.011823.430.001823.435.301127.06
752021.11.18 09:49buy380.011867.550.001875.57
762021.11.22 12:39close380.011837.550.001875.57-30.771096.29
772021.12.07 08:00buy390.011781.410.001785.45
782021.12.07 18:24t/p390.011785.450.001785.454.041100.33
792021.12.14 03:00buy400.011788.260.001793.76
802021.12.14 08:15buy410.011788.520.001793.80
812021.12.15 21:00close410.011758.510.001793.80-30.401069.94
822021.12.15 21:00close400.011758.250.001793.76-30.401039.54
832021.12.23 15:30buy420.011808.530.001813.33
842021.12.28 06:45buy430.011810.940.001813.94
852021.12.28 07:54t/p420.011813.330.001813.333.641043.19
862021.12.28 08:36t/p430.011813.940.001813.943.001046.19
872022.01.11 15:30buy440.011808.530.001814.47
882022.01.11 18:22t/p440.011814.470.001814.475.941052.13
892022.01.12 07:34buy450.011820.620.001824.28
902022.01.12 15:39t/p450.011824.280.001824.283.661055.79
912022.01.13 05:22buy460.011825.620.001827.54
922022.01.13 07:39t/p460.011827.540.001827.541.921057.71
932022.01.26 04:00buy470.011848.320.001851.06
942022.01.26 21:54close470.011818.320.001851.06-30.001027.71
952022.02.01 18:30buy480.011807.070.001815.95
962022.02.04 17:30close480.011807.580.001815.95-1.421026.29
972022.02.09 03:45buy490.011826.840.001829.58
982022.02.09 14:30buy500.011827.570.001828.85
992022.02.09 15:04t/p500.011828.850.001828.851.281027.57
1002022.02.09 15:04t/p490.011829.580.001829.582.741030.31
1012022.02.18 15:00buy510.011894.370.001904.85
1022022.02.21 01:24t/p510.011904.850.001904.8510.091040.41
1032022.03.02 08:45buy520.011937.780.001948.72
1042022.03.04 02:39t/p520.011948.720.001948.729.401049.81
1052022.03.04 11:15buy530.011941.760.001956.50
1062022.03.04 16:37t/p530.011956.500.001956.5014.741064.55
1072022.03.07 17:45buy540.011989.520.002032.20
1082022.03.08 06:45buy550.011990.020.001999.84
1092022.03.08 08:30t/p550.011999.840.001999.849.821074.37
1102022.03.08 16:49t/p540.012032.200.002032.2042.291116.66
1112022.03.24 08:15buy560.011943.000.001948.07
1122022.03.24 13:31t/p560.011948.070.001948.075.071121.73
1132022.03.25 03:00buy570.011963.180.001973.08
1142022.03.28 08:54close570.011933.170.001973.08-30.401091.33
1152022.04.08 03:00buy580.011933.440.001938.38
1162022.04.08 15:09t/p580.011938.380.001938.384.941096.27
1172022.04.11 08:45buy590.011945.070.001949.77
1182022.04.11 11:19t/p590.011949.770.001949.774.701100.97
1192022.04.12 14:15buy600.011956.780.001966.56
1202022.04.12 15:39t/p600.011966.560.001966.569.781110.75
1212022.04.13 04:49buy610.011968.270.001977.63
1222022.04.13 12:39t/p610.011977.630.001977.639.361120.11
1232022.04.14 02:00buy620.011978.770.001982.79
1242022.04.14 05:00buy630.011980.150.001986.33
1252022.04.14 10:45buy640.011977.610.001984.30
1262022.04.18 02:37t/p620.011982.790.001982.793.251123.36
1272022.04.18 02:46t/p640.011984.300.001984.305.921129.28
1282022.04.18 02:49t/p630.011986.330.001986.335.411134.69
1292022.05.05 13:30buy650.011898.350.001907.79
1302022.05.05 15:49t/p650.011907.790.001907.799.441144.13
1312022.05.20 18:15buy660.011844.280.001855.78
1322022.05.23 08:08t/p660.011855.780.001855.7811.111155.25
1332022.05.24 06:30buy670.011855.020.001865.48
1342022.05.24 16:47t/p670.011865.480.001865.4810.461165.71
1352022.05.30 16:30buy680.011860.950.001873.85
1362022.06.01 08:16close680.011830.950.001873.85-30.771134.94
1372022.06.09 02:15buy690.011854.430.001859.21
1382022.06.10 17:56t/p690.011859.210.001859.214.391139.33
1392022.06.17 08:15buy700.011847.480.001852.86
1402022.06.23 20:45close700.011828.540.001852.86-21.251118.08
1412022.07.22 09:00buy710.011716.360.001722.06
1422022.07.22 12:28t/p710.011722.060.001722.065.701123.78
1432022.07.25 01:15buy720.011726.580.001733.12
1442022.07.25 12:25t/p720.011733.120.001733.126.541130.32
1452022.08.01 05:15buy730.011764.230.001769.55
1462022.08.01 09:45buy740.011764.350.001769.94
1472022.08.01 12:41t/p730.011769.550.001769.555.321135.64
1482022.08.01 12:42t/p740.011769.940.001769.945.591141.23
1492022.08.01 21:00buy750.011769.500.001770.16
1502022.08.01 22:13t/p750.011770.160.001770.160.661141.89
1512022.08.02 12:15buy760.011773.930.001780.13
1522022.08.02 15:15t/p760.011780.130.001780.136.201148.09
1532022.08.05 07:45buy770.011792.140.001793.36
1542022.08.09 13:42t/p770.011793.360.001793.360.451148.54
1552022.08.24 17:00buy780.011746.370.001752.45
1562022.08.24 17:53t/p780.011752.450.001752.456.081154.62
1572022.09.05 20:00buy790.011712.490.001716.59
1582022.09.06 03:22t/p790.011716.590.001716.593.711158.34
1592022.09.08 07:15buy800.011717.050.001722.73
1602022.09.08 13:37t/p800.011722.730.001722.735.681164.02
1612022.09.30 16:45buy810.011669.310.001683.17
1622022.10.03 17:22t/p810.011683.170.001683.1713.471177.49
1632022.10.04 06:45buy820.011700.570.001710.29
1642022.10.04 10:18t/p820.011710.290.001710.299.721187.21
1652022.10.24 07:45buy830.011658.540.001667.78
1662022.10.26 03:00buy840.011653.320.001656.82
1672022.10.26 06:27t/p840.011656.820.001656.823.501190.71
1682022.10.26 10:28t/p830.011667.780.001667.788.471199.18
1692022.10.26 18:15buy850.011672.250.001688.35
1702022.10.27 08:45buy860.011669.970.001683.09
1712022.10.27 11:16buy870.011665.690.001671.40
1722022.10.28 15:30close850.011642.250.001688.35-31.541167.64
1732022.10.28 18:16close860.011639.970.001683.09-30.391137.26
1742022.10.31 10:33close870.011635.680.001671.40-30.781106.48
1752022.11.02 20:15buy880.011664.650.001700.85
1762022.11.02 22:53close880.011634.640.001700.85-30.011076.47
1772022.11.07 05:32buy890.011673.540.001679.06
1782022.11.07 11:26t/p890.011679.060.001679.065.521081.99
1792022.11.10 13:00buy900.011708.750.001717.39
1802022.11.10 15:31t/p900.011717.390.001717.398.641090.63
1812022.11.11 06:45buy910.011752.250.001756.31
1822022.11.11 07:27t/p910.011756.310.001756.314.061094.69
1832022.11.14 05:15buy920.011765.390.001773.49
1842022.11.14 09:45buy930.011762.610.001767.41
1852022.11.14 16:40t/p930.011767.410.001767.414.801099.49
1862022.11.14 17:12t/p920.011773.490.001773.498.101107.59
1872022.11.25 13:15buy940.011754.060.001758.45
1882022.11.28 10:41t/p940.011758.450.001758.454.001111.59
1892022.12.08 13:45buy950.011784.960.001789.60
1902022.12.08 15:33t/p950.011789.600.001789.604.641116.23
1912022.12.09 13:00buy960.011795.010.001806.43
1922022.12.13 15:33t/p960.011806.430.001806.4310.651126.88
1932022.12.14 03:01buy970.011811.700.001816.46
1942022.12.15 10:13close970.011781.700.001816.46-31.161095.73
1952022.12.22 02:15buy980.011816.330.001821.27
1962022.12.22 20:22close980.011786.320.001821.27-30.011065.72
1972022.12.30 03:00buy990.011816.700.001821.50
1982022.12.30 09:01t/p990.011821.500.001821.504.801070.52
1992023.01.05 09:30buy1000.011854.580.001861.94
2002023.01.06 17:42t/p1000.011861.940.001861.946.971077.49
2012023.01.09 14:15buy1010.011875.580.001880.29
2022023.01.09 16:48t/p1010.011880.290.001880.294.711082.20
2032023.01.10 21:15buy1020.011876.290.001884.11
2042023.01.11 06:00buy1030.011878.160.001884.56
2052023.01.11 07:38t/p1020.011884.110.001884.117.431089.64
2062023.01.11 10:48t/p1030.011884.560.001884.566.401096.04
2072023.01.13 10:00buy1040.011900.080.001909.72
2082023.01.13 16:50t/p1040.011909.720.001909.729.641105.68
2092023.01.20 17:30buy1050.011930.500.001939.92
2102023.01.24 09:02t/p1050.011939.920.001939.928.651114.33
2112023.02.01 06:15buy1060.011928.490.001935.53
2122023.02.01 21:42t/p1060.011935.530.001935.537.041121.37
2132023.02.20 04:30buy1070.011842.720.001851.28
2142023.02.24 15:33close1070.011812.710.001851.28-32.321089.05
2152023.03.01 04:00buy1080.011829.530.001841.59
2162023.03.01 16:38t/p1080.011841.590.001841.5912.061101.11
2172023.03.13 11:00buy1090.011885.940.001910.34
2182023.03.13 16:46t/p1090.011910.340.001910.3424.401125.51
2192023.03.14 08:15buy1100.011911.370.001920.84
2202023.03.14 14:15buy1110.011907.700.001919.34
2212023.03.14 19:00buy1120.011909.110.001922.09
2222023.03.15 14:01t/p1110.011919.340.001919.3411.251136.76
2232023.03.15 14:02t/p1100.011920.840.001920.849.081145.85
2242023.03.15 14:03t/p1120.011922.090.001922.0912.591158.44
2252023.03.16 01:15buy1130.011921.580.001928.78
2262023.03.16 14:21t/p1130.011928.780.001928.787.201165.64
2272023.03.16 21:15buy1140.011920.100.001930.02
2282023.03.17 06:54t/p1140.011930.020.001930.029.531175.17
2292023.03.20 06:15buy1150.011974.960.001978.92
2302023.03.20 07:46t/p1150.011978.920.001978.923.961179.13
2312023.03.24 05:58buy1160.011993.750.001997.31
2322023.03.24 12:08t/p1160.011997.310.001997.313.561182.69
2332023.03.31 14:00buy1170.011979.810.001984.61
2342023.03.31 15:33t/p1170.011984.610.001984.614.801187.49
2352023.04.12 15:45buy1180.012022.610.002038.60
2362023.04.13 15:46t/p1180.012038.600.002038.6014.831202.33
2372023.04.26 09:45buy1190.011998.920.002007.18
2382023.04.26 16:26t/p1190.012007.180.002007.188.261210.59
2392023.05.03 11:40buy1200.012016.670.002020.09
2402023.05.03 14:00buy1210.012016.960.002019.66
2412023.05.03 16:30buy1220.012019.060.002029.60
2422023.05.03 16:35t/p1210.012019.660.002019.662.701213.29
2432023.05.03 17:52t/p1200.012020.090.002020.093.421216.71
2442023.05.03 21:00t/p1220.012029.600.002029.6010.541227.25
2452023.05.31 08:00buy1230.011960.480.001966.80
2462023.05.31 13:45buy1240.011958.910.001966.07
2472023.05.31 16:42t/p1240.011966.070.001966.077.161234.41
2482023.05.31 16:42t/p1230.011966.800.001966.806.321240.73
2492023.06.01 02:15buy1250.011966.240.001972.42
2502023.06.01 16:35t/p1250.011972.420.001972.426.181246.91
2512023.06.02 05:00buy1260.011977.770.001981.10
2522023.06.02 06:06t/p1260.011981.100.001981.103.331250.24
2532023.06.02 12:45buy1270.011981.060.001991.44
2542023.06.02 20:51close1270.011951.060.001991.44-30.001220.24
2552023.07.03 07:00buy1280.011918.700.001922.42
2562023.07.03 16:16t/p1280.011922.420.001922.423.721223.96
2572023.07.11 19:45buy1290.011932.790.001935.57
2582023.07.12 03:35t/p1290.011935.570.001935.572.391226.35
2592023.07.13 16:15buy1300.011961.140.001969.50
2602023.07.18 14:16t/p1300.011969.500.001969.507.201233.56
2612023.07.19 10:15buy1310.011980.120.001986.85
2622023.07.19 15:30buy1320.011978.550.001984.68
2632023.07.19 20:08buy1330.011979.090.001989.95
2642023.07.19 23:54close at stop1330.011976.470.001989.95-2.621230.94
2652023.07.19 23:54close at stop1320.011976.470.001984.68-2.081228.86
2662023.07.19 23:54close at stop1310.011976.470.001986.85-3.651225.21
+
diff --git a/Docs/Reports/14020427/XR Strategy Test 1.gif b/Docs/Reports/14020427/XR Strategy Test 1.gif new file mode 100644 index 0000000..d3f1e22 Binary files /dev/null and b/Docs/Reports/14020427/XR Strategy Test 1.gif differ diff --git a/Docs/Reports/14020427/XR Strategy Test 1.htm b/Docs/Reports/14020427/XR Strategy Test 1.htm new file mode 100644 index 0000000..98bc578 --- /dev/null +++ b/Docs/Reports/14020427/XR Strategy Test 1.htm @@ -0,0 +1,138 @@ + + + + Strategy Tester: x-saherelm.xr.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.xr.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.06.29 23:45 (2020.01.01 - 2023.06.30)
ModelEvery tick (the most precise method based on all available least timeframes)
Bars in test61247Ticks modelled69753529Modelling quality40.22%
Mismatched charts errors33
Initial deposit1000.00SpreadCurrent (60)
Total net profit2337.40Gross profit2533.14Gross loss-195.74
Profit factor12.94Expected payoff57.01
Absolute drawdown600.00Maximal drawdown1787.50 (55.97%)Relative drawdown69.29% (1556.27)
Total trades41Short positions (won %)0 (0.00%)Long positions (won %)41 (95.12%)
Profit trades (% of total)39 (95.12%)Loss trades (% of total)2 (4.88%)
Largestprofit trade75.00loss trade-107.85
Averageprofit trade64.95loss trade-97.87
Maximumconsecutive wins (profit in money)17 (1231.46)consecutive losses (loss in money)1 (-107.85)
Maximalconsecutive profit (count of wins)1231.46 (17)consecutive loss (count of losses)-107.85 (1)
Averageconsecutive wins13consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.02 15:15buy10.501824.660.001826.16
22020.12.02 17:39t/p10.501826.160.001826.1675.001075.00
32021.01.11 04:00buy20.501829.260.001830.76
42021.01.11 04:31t/p20.501830.760.001830.7675.001150.00
52021.02.12 14:00buy30.501819.170.001820.67
62021.02.12 17:46t/p30.501820.670.001820.6775.001225.00
72021.02.15 10:30buy40.501819.510.001821.01
82021.02.15 13:39t/p40.501821.010.001821.0175.001300.00
92021.02.15 18:15buy50.501819.540.001821.04
102021.02.16 02:24t/p50.501821.040.001821.0453.231353.23
112021.05.07 06:15buy60.501819.850.001821.35
122021.05.07 06:24t/p60.501821.350.001821.3575.001428.23
132021.05.07 10:30buy70.501820.000.001821.50
142021.05.07 11:34t/p70.501821.500.001821.5075.001503.23
152021.05.07 16:00buy80.501839.160.001840.66
162021.05.07 16:03t/p80.501840.660.001840.6675.001578.23
172021.05.13 04:30buy90.501822.150.001823.65
182021.05.13 17:51t/p90.501823.650.001823.6575.001653.23
192021.06.17 02:45buy100.501820.030.001821.53
202021.06.17 04:54t/p100.501821.530.001821.5375.001728.23
212021.07.14 15:30buy110.501824.340.001825.84
222021.07.14 15:34t/p110.501825.840.001825.8475.001803.23
232021.07.16 15:45buy120.501823.910.001825.41
242021.07.16 16:39t/p120.501825.410.001825.4175.001878.23
252021.07.29 10:15buy130.501819.440.001820.94
262021.07.29 11:39t/p130.501820.940.001820.9475.001953.23
272021.08.27 22:30buy140.501818.730.001820.23
282021.08.30 03:37t/p140.501820.230.001820.2353.232006.46
292021.08.30 03:45buy150.501820.450.001821.95
302021.08.30 04:06t/p150.501821.950.001821.9575.002081.46
312021.09.03 16:00buy160.501823.920.001825.42
322021.09.03 16:09t/p160.501825.420.001825.4275.002156.46
332021.11.08 15:45buy170.501819.340.001820.84
342021.11.08 15:54t/p170.501820.840.001820.8475.002231.46
352021.12.28 15:45buy180.501819.710.001821.21
362021.12.31 11:09close180.501819.730.001821.21-107.852123.61
372022.01.05 15:15buy190.501820.490.001821.99
382022.01.05 15:24t/p190.501821.990.001821.9975.002198.61
392022.01.12 16:00buy200.501821.690.001823.19
402022.01.12 16:37t/p200.501823.190.001823.1975.002273.61
412022.01.18 18:00buy210.501820.250.001821.75
422022.01.19 15:21t/p210.501821.750.001821.7553.232326.84
432022.01.19 15:21buy220.501822.350.001823.85
442022.01.19 15:24t/p220.501823.850.001823.8575.002401.84
452022.02.08 10:45buy230.501820.380.001821.88
462022.02.08 15:39t/p230.501821.880.001821.8875.002476.84
472022.05.13 02:15buy240.501820.070.001821.57
482022.05.13 02:47t/p240.501821.570.001821.5775.002551.84
492022.05.13 14:15buy250.501818.840.001820.34
502022.05.16 21:56t/p250.501820.340.001820.3453.232605.07
512022.05.18 13:00buy260.501819.810.001821.31
522022.05.18 18:41t/p260.501821.310.001821.3175.002680.07
532022.05.18 19:00buy270.501823.970.001825.47
542022.05.19 12:08t/p270.501825.470.001825.479.692689.76
552022.06.14 16:15buy280.501820.010.001821.51
562022.06.15 09:37t/p280.501821.510.001821.5153.232742.99
572022.06.15 09:37buy290.501822.110.001823.61
582022.06.15 10:42t/p290.501823.610.001823.6175.002817.99
592022.06.16 15:15buy300.501823.900.001825.40
602022.06.16 15:31t/p300.501825.400.001825.4075.002892.99
612022.06.24 16:30buy310.501826.410.001827.91
622022.06.24 17:09t/p310.501827.910.001827.9175.002967.99
632022.06.29 19:15buy320.501818.970.001820.47
642022.06.30 03:49t/p320.501820.470.001820.479.692977.68
652022.12.13 17:00buy330.501822.380.001823.88
662022.12.13 17:00t/p330.501823.880.001823.8875.003052.68
672022.12.21 15:45buy340.501819.140.001820.64
682022.12.21 17:08t/p340.501820.640.001820.6475.003127.68
692022.12.22 05:15buy350.501818.900.001820.40
702022.12.27 17:26t/p350.501820.400.001820.409.693137.37
712022.12.27 17:45buy360.501827.790.001829.29
722023.01.03 01:05close360.501829.080.001829.29-87.893049.48
732023.01.03 01:05buy370.501829.670.001831.17
742023.01.03 02:12t/p370.501831.170.001831.1775.003124.48
752023.02.23 16:00buy380.501825.940.001827.44
762023.02.23 16:17t/p380.501827.440.001827.4475.003199.48
772023.02.27 20:15buy390.501819.340.001820.84
782023.02.28 17:00t/p390.501820.840.001820.8453.233252.71
792023.03.07 18:45buy400.501819.710.001821.21
802023.03.07 19:13t/p400.501821.210.001821.2175.003327.71
812023.03.08 17:45buy410.501820.430.001821.93
822023.03.09 15:33t/p410.501821.930.001821.939.693337.40
+
diff --git a/Docs/Reports/14020427/XR Strategy Test 2.gif b/Docs/Reports/14020427/XR Strategy Test 2.gif new file mode 100644 index 0000000..bbc1222 Binary files /dev/null and b/Docs/Reports/14020427/XR Strategy Test 2.gif differ diff --git a/Docs/Reports/14020427/XR Strategy Test 2.htm b/Docs/Reports/14020427/XR Strategy Test 2.htm new file mode 100644 index 0000000..1997074 --- /dev/null +++ b/Docs/Reports/14020427/XR Strategy Test 2.htm @@ -0,0 +1,241 @@ + + + + Strategy Tester: x-saherelm.xr.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.xr.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.06.29 23:45 (2020.01.01 - 2023.06.30)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=35; swingLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=2; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=96; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +
Bars in test61247Ticks modelled69753529Modelling quality40.22%
Mismatched charts errors33
Initial deposit1000.00SpreadCurrent (60)
Total net profit-22.73Gross profit140.12Gross loss-162.85
Profit factor0.86Expected payoff-0.26
Absolute drawdown35.59Maximal drawdown110.15 (10.25%)Relative drawdown10.25% (110.15)
Total trades87Short positions (won %)0 (0.00%)Long positions (won %)87 (88.51%)
Profit trades (% of total)77 (88.51%)Loss trades (% of total)10 (11.49%)
Largestprofit trade9.07loss trade-31.31
Averageprofit trade1.82loss trade-16.29
Maximumconsecutive wins (profit in money)33 (47.60)consecutive losses (loss in money)3 (-67.46)
Maximalconsecutive profit (count of wins)60.79 (24)consecutive loss (count of losses)-67.46 (3)
Averageconsecutive wins10consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
1652022.07.20 16:45buy830.011710.780.001713.22
1662022.07.21 14:37close830.011680.780.001713.22-31.31967.80
1472022.05.10 14:45buy740.011863.420.001865.19
1482022.05.11 02:53close740.011833.400.001865.19-30.461038.94
792021.10.14 15:45buy400.011799.210.001800.37
802021.10.15 15:52close400.011769.200.001800.37-30.451021.80
1612022.07.05 02:15buy810.011810.010.001813.25
1622022.07.05 17:03close810.011779.990.001813.25-30.021005.24
492021.06.09 06:15buy250.011896.400.001903.47
502021.06.10 07:15close250.011886.580.001903.47-11.131049.67
1532022.06.14 10:00buy770.011830.310.001843.30
1542022.06.15 11:00close770.011820.620.001843.30-10.131031.93
512021.06.15 16:00buy260.011866.010.001868.96
522021.06.16 17:00close260.011858.760.001868.96-7.691041.98
1632022.07.12 13:00buy820.011735.390.001743.99
1642022.07.13 14:00close820.011729.690.001743.99-6.14999.10
732021.10.07 14:15buy370.011764.680.001764.87
762021.10.08 13:54close370.011760.360.001764.87-4.761052.17
672021.09.01 19:00buy340.011815.860.001816.89
682021.09.02 12:39close340.011816.370.001816.89-0.801054.22
692021.09.02 14:45buy350.011815.870.001815.87
702021.09.02 14:54t/p350.011815.870.001815.870.001054.22
1092021.12.22 17:15buy550.011792.860.001792.86
1102021.12.22 17:24t/p550.011792.860.001792.860.001044.70
392021.05.11 12:45buy200.011838.500.001838.54
402021.05.11 13:04t/p200.011838.540.001838.540.041052.35
1412022.03.10 12:15buy710.011995.580.001995.62
1422022.03.10 12:15t/p710.011995.620.001995.620.041066.30
192021.03.22 18:00buy100.011738.750.001742.92
202021.03.23 08:33close100.011739.260.001742.920.071036.18
352021.04.30 14:30buy180.011772.700.001773.44
362021.05.03 05:22close180.011773.210.001773.440.071049.31
592021.07.02 21:15buy300.011791.110.001794.84
602021.07.05 10:37close300.011791.620.001794.840.071051.48
772021.10.11 18:15buy390.011758.580.001760.18
782021.10.12 08:04close390.011759.090.001760.180.071052.24
912021.11.11 19:00buy460.011862.510.001865.78
922021.11.12 17:21close460.011863.020.001865.780.071032.55
1052021.12.10 06:30buy530.011779.380.001779.47
1062021.12.10 15:37t/p530.011779.470.001779.470.091043.66
1292022.02.04 09:00buy650.011807.450.001807.70
1302022.02.04 09:05t/p650.011807.700.001807.700.251057.24
1552022.06.17 15:45buy780.011850.980.001851.29
1562022.06.17 15:46t/p780.011851.290.001851.290.311032.24
972021.11.26 05:00buy490.011794.490.001794.82
982021.11.26 05:04t/p490.011794.820.001794.820.331039.16
332021.04.27 17:00buy170.011783.470.001783.89
342021.04.27 17:09t/p170.011783.890.001783.890.421049.24
132021.02.15 02:45buy70.011822.670.001830.54
142021.02.15 14:46close70.011823.180.001830.540.511023.20
412021.05.19 03:00buy210.011870.540.001874.85
422021.05.19 15:54close210.011871.050.001874.850.511052.86
532021.06.30 05:15buy270.011764.210.001765.55
542021.06.30 17:49close270.011764.720.001765.550.511042.49
742021.10.08 09:30buy380.011759.850.001762.96
752021.10.08 13:54close380.011760.360.001762.960.511056.92
1452022.04.26 06:15buy730.011905.400.001911.36
1462022.04.26 23:23close730.011905.910.001911.360.511069.40
1572022.06.21 05:00buy790.011841.920.001843.00
1582022.06.21 17:39close790.011842.430.001843.000.511032.75
1132021.12.27 07:15buy570.011810.970.001811.49
1142021.12.27 17:19t/p570.011811.490.001811.490.521045.84
1212022.01.07 16:30buy610.011792.620.001793.14
1222022.01.07 16:43t/p610.011793.140.001793.140.521051.06
1112021.12.23 10:15buy560.011807.640.001808.26
1122021.12.23 15:30t/p560.011808.260.001808.260.621045.32
1152022.01.04 11:45buy580.011806.180.001806.85
1162022.01.04 12:24t/p580.011806.850.001806.850.671046.51
252021.04.15 08:30buy130.011741.610.001742.31
262021.04.15 08:45t/p130.011742.310.001742.310.701041.75
892021.11.05 06:30buy450.011795.050.001795.76
902021.11.05 07:04t/p450.011795.760.001795.760.711032.48
1492022.05.12 03:30buy750.011855.500.001856.26
1502022.05.12 03:38t/p750.011856.260.001856.260.761039.70
872021.10.28 05:00buy440.011798.040.001798.85
882021.10.28 05:09t/p440.011798.850.001798.850.811031.77
1172022.01.05 04:00buy590.011815.740.001816.60
1182022.01.05 08:22t/p590.011816.600.001816.600.861047.37
1272022.01.31 01:30buy640.011790.370.001797.78
1282022.01.31 13:30close640.011791.330.001797.780.961056.99
1072021.12.13 10:15buy540.011787.030.001788.07
1082021.12.13 13:39t/p540.011788.070.001788.071.041044.70
1352022.02.11 14:45buy680.011830.390.001831.47
1362022.02.11 15:04t/p680.011831.470.001831.471.081061.35
112021.02.05 07:15buy60.011796.630.001797.72
122021.02.05 07:36t/p60.011797.720.001797.721.091022.69
1032021.12.07 17:45buy520.011783.270.001784.36
1042021.12.07 18:22t/p520.011784.360.001784.361.091043.57
1012021.12.03 18:30buy510.011777.270.001778.37
1022021.12.03 18:51t/p510.011778.370.001778.371.101042.48
632021.08.18 09:00buy320.011791.060.001792.18
642021.08.18 09:09t/p320.011792.180.001792.181.121053.80
1712022.08.23 11:00buy860.011738.700.001739.84
1722022.08.23 11:13t/p860.011739.840.001739.841.14975.10
1252022.01.25 08:30buy630.011842.670.001843.84
1262022.01.25 16:49t/p630.011843.840.001843.841.171056.03
612021.08.03 20:15buy310.011811.680.001813.32
622021.08.04 05:22t/p310.011813.320.001813.321.201052.68
652021.08.26 17:45buy330.011790.620.001791.84
662021.08.26 17:54t/p330.011791.840.001791.841.221055.02
1332022.02.09 12:15buy670.011827.680.001829.06
1342022.02.09 15:04t/p670.011829.060.001829.061.381060.27
832021.10.25 11:00buy420.011799.510.001800.90
842021.10.25 11:15t/p420.011800.900.001800.901.391025.44
92021.02.01 08:15buy50.011863.750.001875.61
102021.02.01 20:15close50.011865.280.001875.611.531021.60
472021.06.07 16:30buy240.011890.190.001891.73
482021.06.07 17:24t/p240.011891.730.001891.731.541060.79
1312022.02.07 11:00buy660.011813.460.001815.11
1322022.02.07 15:09t/p660.011815.110.001815.111.651058.89
272021.04.16 11:45buy140.011765.210.001767.00
282021.04.16 12:09t/p140.011767.000.001767.001.791043.54
1372022.02.18 23:00buy690.011897.400.001899.76
1382022.02.21 01:00t/p690.011899.760.001899.761.921063.28
212021.03.24 21:15buy110.011734.950.001738.29
222021.03.25 05:15t/p110.011738.290.001738.292.031038.21
452021.05.25 12:00buy230.011883.100.001885.26
462021.05.25 16:52t/p230.011885.260.001885.262.161059.25
1732022.08.24 21:00buy870.011749.940.001753.42
1742022.08.25 03:50t/p870.011753.420.001753.422.17977.27
712021.09.08 13:45buy360.011798.650.001800.84
722021.09.08 15:09t/p360.011800.840.001800.842.191056.41
992021.11.30 16:00buy500.011796.060.001798.28
1002021.11.30 16:49t/p500.011798.280.001798.282.221041.38
812021.10.19 16:00buy410.011782.030.001784.28
822021.10.19 16:01t/p410.011784.280.001784.282.251024.05
1512022.06.07 10:30buy760.011846.180.001848.53
1522022.06.07 12:20t/p760.011848.530.001848.532.351042.05
952021.11.16 03:30buy480.011865.160.001867.64
962021.11.16 04:37t/p480.011867.640.001867.642.481038.83
1592022.06.24 20:30buy800.011828.550.001831.50
1602022.06.27 01:00t/p800.011831.500.001831.502.511035.26
1432022.03.21 13:30buy720.011926.050.001928.64
1442022.03.21 15:52t/p720.011928.640.001928.642.591068.89
312021.04.26 21:45buy160.011780.270.001783.33
322021.04.27 04:01t/p160.011783.330.001783.332.621048.82
292021.04.19 09:45buy150.011780.760.001783.41
302021.04.19 10:39t/p150.011783.410.001783.412.651046.19
1672022.07.25 10:30buy840.011728.350.001731.02
1682022.07.25 12:18t/p840.011731.020.001731.022.67970.47
12020.12.03 16:15buy10.011840.090.001843.27
22020.12.04 04:52t/p10.011843.270.001843.272.741002.74
232021.03.31 12:15buy120.011685.800.001688.64
242021.03.31 13:39t/p120.011688.640.001688.642.841041.05
1392022.03.03 12:15buy700.011931.410.001934.39
1402022.03.03 12:30t/p700.011934.390.001934.392.981066.26
552021.07.01 16:45buy280.011779.550.001782.54
562021.07.01 17:03t/p280.011782.540.001782.542.991045.48
372021.05.10 09:00buy190.011839.010.001842.01
382021.05.10 15:09t/p190.011842.010.001842.013.001052.31
1192022.01.07 05:15buy600.011792.220.001795.39
1202022.01.07 15:39t/p600.011795.390.001795.393.171050.54
1692022.08.08 05:30buy850.011775.410.001778.90
1702022.08.08 10:48t/p850.011778.900.001778.903.49973.96
932021.11.15 13:15buy470.011863.840.001867.64
942021.11.15 15:09t/p470.011867.640.001867.643.801036.35
1232022.01.19 11:30buy620.011816.070.001819.87
1242022.01.19 15:17t/p620.011819.870.001819.873.801054.86
172021.03.16 15:30buy90.011733.170.001737.00
182021.03.16 16:21t/p90.011737.000.001737.003.831036.10
52020.12.08 04:00buy30.011864.270.001868.35
62020.12.08 04:54t/p30.011868.350.001868.354.081015.21
432021.05.21 12:30buy220.011877.800.001882.03
442021.05.21 15:19t/p220.011882.030.001882.034.231057.09
72020.12.31 13:45buy40.011894.880.001899.74
82020.12.31 17:31t/p40.011899.740.001899.744.861020.07
852021.10.27 18:00buy430.011792.490.001798.01
862021.10.27 21:27t/p430.011798.010.001798.015.521030.96
572021.07.02 03:30buy290.011776.660.001782.58
582021.07.02 11:22t/p290.011782.580.001782.585.921051.40
32020.12.07 07:15buy20.011839.630.001848.02
42020.12.07 16:49t/p20.011848.020.001848.028.391011.13
152021.03.02 12:30buy80.011727.470.001736.54
162021.03.02 19:36t/p80.011736.540.001736.549.071032.27
+
diff --git a/Docs/Reports/14020427/test 1.gif b/Docs/Reports/14020427/test 1.gif new file mode 100644 index 0000000..39e88dd Binary files /dev/null and b/Docs/Reports/14020427/test 1.gif differ diff --git a/Docs/Reports/14020427/test 1.htm b/Docs/Reports/14020427/test 1.htm new file mode 100644 index 0000000..afc9bc5 --- /dev/null +++ b/Docs/Reports/14020427/test 1.htm @@ -0,0 +1,299 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.06.29 23:45 (2020.01.01 - 2023.06.30)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=408; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +step=0.01; maximum=0.1; shortCycleMultiplier=2; mediumCycleMultiplier=6; longCycleMultiplier=36;
Bars in test61247Ticks modelled69753529Modelling quality40.22%
Mismatched charts errors33
Initial deposit1000.00SpreadCurrent (50)
Total net profit-1.93Gross profit395.60Gross loss-397.53
Profit factor1.00Expected payoff-0.02
Absolute drawdown93.42Maximal drawdown137.71 (13.19%)Relative drawdown13.19% (137.71)
Total trades116Short positions (won %)0 (0.00%)Long positions (won %)116 (36.21%)
Profit trades (% of total)42 (36.21%)Loss trades (% of total)74 (63.79%)
Largestprofit trade24.00loss trade-15.43
Averageprofit trade9.42loss trade-5.37
Maximumconsecutive wins (profit in money)4 (59.73)consecutive losses (loss in money)9 (-44.59)
Maximalconsecutive profit (count of wins)59.73 (4)consecutive loss (count of losses)-60.13 (8)
Averageconsecutive wins2consecutive losses3
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.01 02:45buy10.011779.481775.151786.48
22020.12.01 06:24t/p10.011786.481775.151786.487.001007.00
32020.12.02 01:30buy20.011812.601812.081813.44
42020.12.02 01:31s/l20.011812.081812.081813.44-0.521006.48
52020.12.02 08:30buy30.011814.551806.131821.36
62020.12.02 10:36t/p30.011821.361806.131821.366.811013.29
72020.12.02 17:45buy40.011825.371811.451847.89
82020.12.03 04:45buy50.011829.931825.741836.71
92020.12.03 05:39t/p50.011836.711825.741836.716.781020.07
102020.12.03 14:00buy60.011842.771833.331858.05
112020.12.03 16:49s/l60.011833.331833.331858.05-9.441010.63
122020.12.03 20:15buy70.011839.001828.731855.62
132020.12.04 04:47buy80.011841.651838.241847.17
142020.12.04 08:00s/l80.011838.241838.241847.17-3.411007.22
152020.12.04 09:00buy90.011843.921836.891849.61
162020.12.04 14:15buy100.011842.701837.901850.46
172020.12.04 15:39s/l100.011837.901837.901850.46-4.801002.42
182020.12.04 15:39s/l90.011836.891836.891849.61-7.03995.39
192020.12.04 16:15buy110.011843.501830.791853.78
202020.12.04 16:18t/p40.011847.891811.451847.8920.781016.17
212020.12.04 17:54s/l110.011830.791830.791853.78-12.711003.46
222020.12.04 21:00buy120.011835.851833.561839.55
232020.12.07 01:23s/l120.011833.561833.561839.55-2.731000.73
242020.12.07 10:34s/l70.011828.731828.731855.62-11.14989.59
252020.12.07 14:15buy130.011832.091826.761840.71
262020.12.07 16:24t/p130.011840.711826.761840.718.62998.21
272020.12.07 23:45buy140.011864.891857.241877.27
282020.12.08 04:15buy150.011866.521860.091876.92
292020.12.08 13:08s/l150.011860.091860.091876.92-6.43991.78
302020.12.08 15:00buy160.011866.011859.711876.21
312020.12.09 02:30buy170.011870.041869.251871.32
322020.12.09 02:31s/l170.011869.251869.251871.32-0.79990.99
332020.12.09 05:39s/l160.011859.711859.711876.21-6.74984.26
342020.12.09 06:07s/l140.011857.241857.241877.27-8.52975.74
352020.12.09 09:45buy180.011861.181857.811866.64
362020.12.09 12:22s/l180.011857.811857.811866.64-3.37972.37
372020.12.09 13:30buy190.011860.241855.381868.10
382020.12.09 13:37s/l190.011855.381855.381868.10-4.86967.51
392020.12.09 15:45buy200.011861.661853.511874.84
402020.12.09 16:24s/l200.011853.511853.511874.84-8.15959.36
412020.12.09 23:45buy210.011839.361831.441852.18
422020.12.10 11:06s/l210.011831.441831.441852.18-9.23950.13
432020.12.10 14:30buy220.011837.621831.881846.90
442020.12.10 16:03t/p220.011846.901831.881846.909.28959.41
452020.12.11 03:30buy230.011838.871835.731843.95
462020.12.11 05:13s/l230.011835.731835.731843.95-3.14956.27
472020.12.11 06:15buy240.011837.261834.581841.60
482020.12.11 07:54s/l240.011834.581834.581841.60-2.68953.59
492020.12.11 08:45buy250.011836.931833.061843.19
502020.12.11 09:45s/l250.011833.061833.061843.19-3.87949.72
512020.12.11 11:30buy260.011836.171830.691845.03
522020.12.11 13:01s/l260.011830.691830.691845.03-5.48944.24
532020.12.11 14:00buy270.011833.331822.081851.53
542020.12.11 15:45buy280.011838.181829.271852.60
552020.12.14 04:45buy290.011837.461833.951843.14
562020.12.14 07:24s/l290.011833.951833.951843.14-3.51940.73
572020.12.14 10:24s/l280.011829.271829.271852.60-9.35931.38
582020.12.14 12:24s/l270.011822.081822.081851.53-11.69919.70
592020.12.14 16:00buy300.011833.081820.001854.24
602020.12.14 20:45buy310.011828.351825.321833.25
612020.12.14 21:54s/l310.011825.321825.321833.25-3.03916.67
622020.12.15 01:15buy320.011829.221827.371832.22
632020.12.15 01:39s/l320.011827.371827.371832.22-1.85914.82
642020.12.15 04:00buy330.011829.931824.801838.23
652020.12.15 07:37t/p330.011838.231824.801838.238.30923.12
662020.12.15 15:37t/p300.011854.241820.001854.2420.72943.84
672020.12.16 04:30buy340.011854.801850.781861.30
682020.12.16 10:45buy350.011860.661851.831874.94
692020.12.16 10:51t/p340.011861.301850.781861.306.50950.34
702020.12.16 15:22s/l350.011851.831851.831874.94-8.83941.51
712020.12.16 19:00buy360.011854.871851.871859.73
722020.12.16 19:25s/l360.011851.871851.871859.73-3.00938.51
732020.12.16 22:00buy370.011861.681841.081878.35
742020.12.17 05:15buy380.011864.961861.721870.20
752020.12.17 07:54t/p380.011870.201861.721870.205.24943.75
762020.12.17 10:24t/p370.011878.351841.081878.3515.36959.12
772020.12.18 01:00buy390.011884.901882.851888.22
782020.12.18 02:39s/l390.011882.851882.851888.22-2.05957.07
792020.12.18 06:15buy400.011883.041878.541890.32
802020.12.18 10:09s/l400.011878.541878.541890.32-4.50952.57
812020.12.18 13:45buy410.011880.781877.751885.68
822020.12.18 14:06t/p410.011885.681877.751885.684.90957.47
832020.12.18 20:00buy420.011884.341881.781888.48
842020.12.18 20:51s/l420.011881.781881.781888.48-2.56954.91
852020.12.21 01:30buy430.011884.501879.311892.90
862020.12.21 03:09t/p430.011892.901879.311892.908.40963.31
872020.12.21 15:45buy440.011883.161868.171907.42
882020.12.21 18:45buy450.011880.781873.551892.48
892020.12.22 01:15buy460.011881.401873.811893.68
902020.12.22 03:30buy470.011881.191874.821891.49
912020.12.22 07:45s/l470.011874.821874.821891.49-6.37956.94
922020.12.22 08:09s/l460.011873.811873.811893.68-7.59949.35
932020.12.22 08:09s/l450.011873.551873.551892.48-7.67941.68
942020.12.22 08:54s/l440.011868.171868.171907.42-15.43926.26
952020.12.22 12:15buy480.011874.671868.761884.23
962020.12.22 17:49s/l480.011868.761868.761884.23-5.91920.35
972020.12.22 21:33buy490.011864.301859.941871.36
982020.12.22 22:39s/l490.011859.941859.941871.36-4.36915.99
992020.12.23 03:00buy500.011864.321861.211869.36
1002020.12.23 09:04buy510.011866.311863.131871.45
1012020.12.23 10:54t/p500.011869.361861.211869.365.04921.03
1022020.12.23 11:09t/p510.011871.451863.131871.455.14926.17
1032020.12.23 15:45buy520.011869.151856.731889.25
1042020.12.24 02:00buy530.011873.011870.881876.45
1052020.12.24 03:24t/p530.011876.451870.881876.453.44929.61
1062020.12.24 08:45buy540.011876.601874.811879.50
1072020.12.24 10:19t/p540.011879.501874.811879.502.90932.51
1082020.12.24 16:00buy550.011874.511872.621877.57
1092020.12.24 16:09s/l550.011872.621872.621877.57-1.89930.62
1102020.12.28 03:00t/p520.011889.251856.731889.2517.92948.54
1112020.12.28 12:00buy560.011885.701880.681893.82
1122020.12.28 12:24s/l560.011880.681880.681893.82-5.02943.52
1132020.12.28 15:45buy570.011885.821872.031908.14
1142020.12.28 23:45s/l570.011872.031872.031908.14-13.79929.73
1152020.12.29 02:04buy580.011877.891871.171888.77
1162020.12.29 10:00buy590.011879.951874.881888.15
1172020.12.29 12:39s/l590.011874.881874.881888.15-5.07924.66
1182020.12.29 16:00buy600.011880.191873.451891.09
1192020.12.29 17:09s/l600.011873.451873.451891.09-6.74917.92
1202020.12.29 17:45buy610.011878.721870.361892.24
1212020.12.30 01:15buy620.011878.371877.131880.37
1222020.12.30 01:34s/l620.011877.131877.131880.37-1.24916.68
1232020.12.30 13:30buy630.011880.591877.181886.11
1242020.12.30 13:54s/l630.011877.181877.181886.11-3.41913.27
1252020.12.30 19:54t/p580.011888.771871.171888.7710.44923.71
1262020.12.30 22:51t/p610.011892.241870.361892.2413.08936.80
1272020.12.31 09:30buy640.011889.801885.361896.98
1282020.12.31 15:22t/p640.011896.981885.361896.987.18943.98
1292020.12.31 15:30buy650.011897.531892.301905.99
1302020.12.31 16:54s/l650.011892.301892.301905.99-5.23938.75
1312021.01.04 01:45buy660.011914.531884.871938.53
1322021.01.04 15:31t/p660.011938.531884.871938.5324.00962.75
1332021.01.04 20:15buy670.011942.881930.611962.74
1342021.01.05 05:45buy680.011942.141936.101951.92
1352021.01.05 16:16t/p680.011951.921936.101951.929.78972.53
1362021.01.05 18:45buy690.011949.061939.151965.10
1372021.01.06 01:22buy700.011951.581947.551958.10
1382021.01.06 03:24s/l700.011947.551947.551958.10-4.03968.50
1392021.01.06 08:30buy710.011944.911943.011947.99
1402021.01.06 09:09t/p710.011947.991943.011947.993.08971.58
1412021.01.06 14:36s/l690.011939.151939.151965.10-10.35961.23
1422021.01.06 14:39s/l670.011930.611930.611962.74-13.14948.09
1432021.01.06 21:30buy720.011914.031904.591929.31
1442021.01.07 07:30buy730.011918.341916.611921.14
1452021.01.07 07:30s/l730.011916.611916.611921.14-1.73946.36
1462021.01.07 15:30buy740.011918.691913.921926.41
1472021.01.07 15:46s/l740.011913.921913.921926.41-4.77941.59
1482021.01.07 20:15buy750.011914.051908.311923.33
1492021.01.08 06:37s/l750.011908.311908.311923.33-6.18935.42
1502021.01.08 09:54s/l720.011904.591904.591929.31-11.18924.24
1512021.01.08 13:45buy760.011894.341889.171902.70
1522021.01.08 14:34s/l760.011889.171889.171902.70-5.17919.07
1532021.01.08 23:00buy770.011848.061840.881859.68
1542021.01.11 03:00s/l770.011840.881840.881859.68-7.62911.45
1552021.01.11 07:00buy780.011834.441825.711848.56
1562021.01.11 08:33t/p780.011848.561825.711848.5614.12925.57
1572021.01.11 18:00buy790.011849.261830.631879.40
1582021.01.12 04:30buy800.011848.811839.871863.27
1592021.01.12 12:09t/p800.011863.271839.871863.2714.46940.03
1602021.01.12 20:15buy810.011844.121836.421856.58
1612021.01.12 21:31t/p810.011856.581836.421856.5812.46952.49
1622021.01.13 08:15buy820.011860.211856.961865.47
1632021.01.13 10:04s/l820.011856.961856.961865.47-3.25949.24
1642021.01.13 14:45buy830.011855.181851.341861.40
1652021.01.13 15:09s/l830.011851.341851.341861.40-3.84945.40
1662021.01.13 20:00buy840.011856.151852.421862.19
1672021.01.13 22:18s/l840.011852.421852.421862.19-3.73941.67
1682021.01.14 03:07close790.011849.771830.631879.40-1.67940.00
1692021.01.14 08:00buy850.011844.821837.821856.14
1702021.01.14 09:37s/l850.011837.821837.821856.14-7.00933.00
1712021.01.14 14:04buy860.011844.011837.041855.29
1722021.01.14 19:53t/p860.011855.291837.041855.2911.28944.28
1732021.01.14 23:04buy870.011848.091843.571855.41
1742021.01.15 02:15buy880.011848.991844.971855.49
1752021.01.15 10:45buy890.011852.821848.581859.68
1762021.01.15 11:39t/p870.011855.411843.571855.416.88951.17
1772021.01.15 11:39t/p880.011855.491844.971855.496.50957.67
1782021.01.15 13:52s/l890.011848.581848.581859.68-4.24953.43
1792021.01.15 21:45buy900.011829.491826.991833.53
1802021.01.15 22:07s/l900.011826.991826.991833.53-2.50950.93
1812021.01.18 04:45buy910.011829.611817.481849.23
1822021.01.18 13:15buy920.011837.471828.661851.73
1832021.01.18 15:00buy930.011835.971828.531848.01
1842021.01.19 08:30buy940.011839.951835.701846.83
1852021.01.19 14:55s/l940.011835.701835.701846.83-4.25946.68
1862021.01.19 18:15buy950.011842.161831.741859.02
1872021.01.20 04:08t/p930.011848.011828.531848.0111.17957.85
1882021.01.20 04:49t/p910.011849.231817.481849.2318.75976.60
1892021.01.20 08:06t/p920.011851.731828.661851.7313.39989.99
1902021.01.20 16:22t/p950.011859.021831.741859.0216.421006.41
1912021.01.20 16:30buy960.011860.281826.301887.77
1922021.01.21 05:00buy970.011872.001867.191879.78
1932021.01.21 09:39s/l970.011867.191867.191879.78-4.811001.60
1942021.01.21 13:00buy980.011870.471866.771876.45
1952021.01.21 14:54s/l980.011866.771866.771876.45-3.70997.90
1962021.01.21 19:39buy990.011864.711863.381866.87
1972021.01.21 20:52t/p990.011866.871863.381866.872.161000.06
1982021.01.22 11:15buy1000.011863.031858.371870.57
1992021.01.22 11:52s/l1000.011858.371858.371870.57-4.66995.40
2002021.01.22 17:00buy1010.011850.661834.621863.64
2012021.01.22 21:30close1010.011856.441834.621863.645.781001.18
2022021.01.22 21:30close960.011856.441826.301887.77-5.58995.60
2032021.01.25 02:45buy1020.011860.211854.601869.29
2042021.01.25 03:24s/l1020.011854.601854.601869.29-5.61989.99
2052021.01.25 07:15buy1030.011855.681853.281859.56
2062021.01.25 07:37s/l1030.011853.281853.281859.56-2.40987.59
2072021.01.25 11:21buy1040.011853.481851.441856.78
2082021.01.25 12:34t/p1040.011856.781851.441856.783.30990.89
2092021.01.25 20:30buy1050.011856.711854.551860.21
2102021.01.25 21:24s/l1050.011854.551854.551860.21-2.16988.73
2112021.01.26 01:30buy1060.011857.191854.101862.19
2122021.01.26 02:07s/l1060.011854.101854.101862.19-3.09985.64
2132021.01.26 13:19buy1070.011851.601848.211857.08
2142021.01.26 15:24t/p1070.011857.081848.211857.085.48991.12
2152021.01.26 22:45buy1080.011853.271849.031860.13
2162021.01.27 01:16s/l1080.011849.031849.031860.13-4.68986.44
2172021.01.27 02:00buy1090.011851.631848.691856.39
2182021.01.27 02:47s/l1090.011848.691848.691856.39-2.94983.50
2192021.01.27 07:15buy1100.011847.881845.011852.52
2202021.01.27 10:01t/p1100.011852.521845.011852.524.64988.14
2212021.01.27 17:15buy1110.011843.871828.841856.03
2222021.01.28 06:45buy1120.011838.361836.231841.80
2232021.01.28 07:53s/l1120.011836.231836.231841.80-2.13986.01
2242021.01.28 08:45buy1130.011838.361834.801844.12
2252021.01.28 09:09s/l1130.011834.801834.801844.12-3.56982.45
2262021.01.28 15:52t/p1110.011856.031828.841856.0310.85993.31
2272021.01.28 22:45buy1140.011843.301840.821847.32
2282021.01.28 23:01s/l1140.011840.821840.821847.32-2.48990.83
2292021.01.29 03:37buy1150.011843.901840.011850.20
2302021.01.29 06:15buy1160.011841.821841.241842.76
2312021.01.29 06:52t/p1160.011842.761841.241842.760.94991.77
2322021.01.29 08:54t/p1150.011850.201840.011850.206.30998.07
+
diff --git a/Docs/Reports/EURUSD-15M/StrategyTester 1.gif b/Docs/Reports/EURUSD-15M/StrategyTester 1.gif new file mode 100644 index 0000000..08325b4 Binary files /dev/null and b/Docs/Reports/EURUSD-15M/StrategyTester 1.gif differ diff --git a/Docs/Reports/EURUSD-15M/StrategyTester 1.htm b/Docs/Reports/EURUSD-15M/StrategyTester 1.htm new file mode 100644 index 0000000..50fbf12 --- /dev/null +++ b/Docs/Reports/EURUSD-15M/StrategyTester 1.htm @@ -0,0 +1,199 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolEURUSD (Euro vs US Dollar)
Period15 Minutes (M15) 2022.03.09 01:45 - 2023.09.14 23:45 (2020.01.01 - 2023.09.15)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.04; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.04; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +enableXRLong=true; +enableXRShort=true; +xRShortR2R=1.5; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.015; xRLongR2R=1.5; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.015; xRMaximumCandlesPerTrade=96; xRSwingLength=48; xRSharpDetectionFactor=1350; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.03; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.03; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test37897Ticks modelled33978857Modelling quality50.97%
Mismatched charts errors4
Initial deposit1000.00SpreadCurrent (17)
Total net profit-76.97Gross profit125.93Gross loss-202.90
Profit factor0.62Expected payoff-1.24
Absolute drawdown108.07Maximal drawdown109.59 (10.94%)Relative drawdown10.94% (109.59)
Total trades62Short positions (won %)0 (0.00%)Long positions (won %)62 (53.23%)
Profit trades (% of total)33 (53.23%)Loss trades (% of total)29 (46.77%)
Largestprofit trade17.33loss trade-19.07
Averageprofit trade3.82loss trade-7.00
Maximumconsecutive wins (profit in money)5 (19.17)consecutive losses (loss in money)4 (-16.84)
Maximalconsecutive profit (count of wins)19.17 (5)consecutive loss (count of losses)-34.75 (3)
Averageconsecutive wins2consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12022.04.01 12:15buy10.011.105380.000001.10670
22022.04.01 19:45buy20.011.104500.000001.10804
32022.04.01 22:15buy30.011.104290.000001.10522
42022.04.04 03:48t/p30.011.105220.000001.105220.851000.85
52022.04.05 15:45close10.011.096450.000001.10670-9.10991.75
62022.04.05 23:15close20.011.090350.000001.10804-14.32977.43
72022.04.14 05:30buy40.011.090530.000001.09689
82022.04.18 09:00close40.011.079360.000001.09689-11.34966.09
92022.04.18 13:15buy50.011.079540.000001.08104
102022.04.18 14:52t/p50.011.081040.000001.081041.50967.59
112022.04.19 02:00buy60.011.078180.000001.07989
122022.04.19 08:00buy70.011.077310.000001.07872
132022.04.19 09:48t/p70.011.078720.000001.078721.41969.00
142022.04.19 10:54t/p60.011.079890.000001.079891.71970.71
152022.04.27 05:30buy80.011.064820.000001.06824
162022.04.27 13:45buy90.011.061520.000001.06701
172022.04.29 09:00close80.011.053600.000001.06824-11.56959.16
182022.04.29 17:15close90.011.053140.000001.06701-8.72950.44
192022.05.11 06:00buy100.011.053550.000001.05622
202022.05.11 11:09t/p100.011.056220.000001.056222.67953.11
212022.05.23 17:45buy110.011.066850.000001.07384
222022.05.24 17:00t/p110.011.073840.000001.073846.91960.02
232022.05.30 12:45buy120.011.076530.000001.08367
242022.05.30 17:30buy130.011.077150.000001.08318
252022.05.31 17:45buy140.011.071720.000001.07979
262022.06.01 16:15close120.011.072900.000001.08367-3.80956.22
272022.06.01 21:00close130.011.065050.000001.08318-12.27943.95
282022.06.03 15:37close140.011.071710.000001.07979-0.43943.52
292022.06.07 10:30buy150.011.068980.000001.07600
302022.06.09 14:54close150.011.068970.000001.07600-0.35943.18
312022.06.13 19:45buy160.011.044400.000001.04998
322022.06.15 11:39t/p160.011.049980.000001.049985.41948.59
332022.06.20 12:45buy170.011.053650.000001.06073
342022.06.21 17:00buy180.011.055960.000001.05986
352022.06.22 16:33close170.011.053640.000001.06073-0.18948.41
362022.06.22 17:52t/p180.011.059860.000001.059863.82952.23
372022.06.29 11:30buy190.011.051610.000001.05923
382022.07.01 15:00close190.011.043520.000001.05923-8.43943.80
392022.07.11 18:30buy200.011.008320.000001.01438
402022.07.12 13:30buy210.011.001420.000001.00553
412022.07.12 14:19t/p210.011.005530.000001.005534.11947.91
422022.07.13 22:00close200.011.006220.000001.01438-2.27945.64
432022.07.19 18:00buy220.011.024640.000001.02971
442022.07.20 10:45buy230.011.024060.000001.02736
452022.07.21 15:39t/p230.011.027360.000001.027363.05948.69
462022.07.21 21:30close220.011.019380.000001.02971-5.60943.10
472022.08.01 10:30buy240.011.022900.000001.02728
482022.08.01 17:54t/p240.011.027280.000001.027284.38947.48
492022.08.19 16:45buy250.011.005790.000001.00861
502022.08.19 21:30buy260.011.004280.000001.00665
512022.08.23 11:30buy270.010.993030.000001.00182
522022.08.23 20:15close250.010.997290.000001.00861-8.67938.81
532022.08.24 01:00close260.010.996830.000001.00665-7.70931.11
542022.08.25 09:24t/p270.011.001820.000001.001828.45939.56
552022.09.05 10:30buy280.010.991250.000001.00139
562022.09.06 09:00buy290.010.996040.000001.00048
572022.09.07 14:00close280.010.989650.000001.00139-1.77937.79
582022.09.07 22:49t/p290.011.000480.000001.000484.36942.15
592022.09.23 16:30buy300.010.976900.000000.98317
602022.09.26 02:15buy310.010.969430.000000.97699
612022.09.27 20:00close300.010.958000.000000.98317-19.07923.08
622022.09.28 05:45close310.010.955280.000000.97699-14.32908.76
632022.09.29 17:00buy320.010.974260.000000.99184
642022.10.04 15:24t/p320.010.991840.000000.9918417.33926.09
652022.10.07 18:30buy330.010.978850.000000.99184
662022.10.11 22:00close330.010.970810.000000.99184-8.21917.88
672022.10.26 17:45buy340.011.003080.000001.01061
682022.10.28 13:15buy350.010.995700.000001.00035
692022.10.28 21:15close340.010.994430.000001.01061-8.99908.90
702022.11.01 16:45close350.010.988270.000001.00035-7.60901.30
712022.11.10 06:15buy360.011.002840.000001.00782
722022.11.10 15:32t/p360.011.007820.000001.007824.98906.28
732022.12.07 10:45buy370.011.045810.000001.05004
742022.12.07 12:43t/p370.011.050040.000001.050044.23910.51
752023.01.04 16:30buy380.011.061310.000001.06650
762023.01.09 02:02t/p380.011.066500.000001.066504.77915.28
772023.01.31 13:00buy390.011.082370.000001.08312
782023.01.31 13:36t/p390.011.083120.000001.083120.75916.03
792023.03.01 19:15buy400.011.067590.000001.07227
802023.03.02 22:00buy410.011.059120.000001.06311
812023.03.03 21:52t/p410.011.063110.000001.063113.91919.94
822023.03.03 23:15close400.011.063330.000001.07227-4.60915.34
832023.03.06 03:00buy420.011.062830.000001.06409
842023.03.06 04:38t/p420.011.064090.000001.064091.26916.60
852023.03.10 10:00buy430.011.059580.000001.06366
862023.03.10 15:42t/p430.011.063660.000001.063664.08920.68
872023.03.22 17:45buy440.011.078900.000001.08190
882023.03.22 20:02t/p440.011.081900.000001.081903.00923.68
892023.03.28 14:00buy450.011.082360.000001.08587
902023.03.28 19:00buy460.011.084380.000001.09212
912023.03.29 12:57t/p450.011.085870.000001.085873.43927.11
922023.03.30 16:25t/p460.011.092120.000001.092127.40934.51
932023.05.03 17:30buy470.011.104660.000001.10976
942023.05.03 21:30buy480.011.106380.000001.11271
952023.05.05 21:30close470.011.101830.000001.10976-3.17931.35
962023.05.08 01:45close480.011.101430.000001.11271-5.37925.98
972023.05.09 18:15buy490.011.095750.000001.09674
982023.05.09 21:21t/p490.011.096740.000001.096740.99926.97
992023.05.25 21:30buy500.011.072660.000001.07692
1002023.05.29 19:30buy510.011.071320.000001.07252
1012023.05.30 01:45close500.011.070920.000001.07692-1.99924.98
1022023.05.30 04:36t/p510.011.072520.000001.072521.12926.09
1032023.06.13 16:15buy520.011.080210.000001.08543
1042023.06.14 17:53t/p520.011.085430.000001.085435.14931.23
1052023.06.19 19:00buy530.011.092290.000001.09376
1062023.06.20 10:32t/p530.011.093760.000001.093761.39932.61
1072023.07.14 12:00buy540.011.123230.000001.13100
1082023.07.18 16:09close540.011.123220.000001.13100-0.18932.44
1092023.07.24 00:15buy550.011.112680.000001.11394
1102023.07.24 09:52t/p550.011.113940.000001.113941.26933.70
1112023.08.03 09:45buy560.011.093050.000001.09503
1122023.08.03 12:45buy570.011.092700.000001.09681
1132023.08.03 15:39t/p560.011.095030.000001.095031.98935.68
1142023.08.04 15:37t/p570.011.096810.000001.096814.03939.70
1152023.08.22 10:00buy580.011.091880.000001.09584
1162023.08.24 14:00close580.011.085400.000001.09584-6.82932.89
1172023.09.05 20:00buy590.011.073060.000001.07921
1182023.09.07 18:45buy600.011.070740.000001.07473
1192023.09.08 00:15close590.011.069590.000001.07921-3.89929.00
1202023.09.11 13:45buy610.011.073270.000001.07573
1212023.09.11 17:09t/p600.011.074730.000001.074733.82932.82
1222023.09.11 17:24t/p610.011.075730.000001.075732.46935.28
1232023.09.13 03:45buy620.011.076230.000001.07896
1242023.09.14 23:54close at stop620.011.064230.000001.07896-12.25923.03
+
diff --git a/Docs/Reports/Screenshot 2023-08-03 202922.png b/Docs/Reports/Screenshot 2023-08-03 202922.png new file mode 100644 index 0000000..98f6bb0 Binary files /dev/null and b/Docs/Reports/Screenshot 2023-08-03 202922.png differ diff --git a/Docs/Reports/Screenshot 2023-08-08 174923.png b/Docs/Reports/Screenshot 2023-08-08 174923.png new file mode 100644 index 0000000..6795066 Binary files /dev/null and b/Docs/Reports/Screenshot 2023-08-08 174923.png differ diff --git a/Docs/Reports/StrategyTester X (XR and XXX and XTPW) - 0.2 - Full.gif b/Docs/Reports/StrategyTester X (XR and XXX and XTPW) - 0.2 - Full.gif new file mode 100644 index 0000000..dcdca94 Binary files /dev/null and b/Docs/Reports/StrategyTester X (XR and XXX and XTPW) - 0.2 - Full.gif differ diff --git a/Docs/Reports/StrategyTester X (XR and XXX and XTPW) - 0.2 - Full.htm b/Docs/Reports/StrategyTester X (XR and XXX and XTPW) - 0.2 - Full.htm new file mode 100644 index 0000000..342d0e7 --- /dev/null +++ b/Docs/Reports/StrategyTester X (XR and XXX and XTPW) - 0.2 - Full.htm @@ -0,0 +1,445 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.08 12:30 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.0002; xShortMaxDrawdownPerTradePercent=0.4; xLongR2R=3; xLongLotsPerTradePercent=0.0002; xLongMaxDrawdownPerTradePercent=0.4; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=true; +xRShortR2R=1.5; xRShortLotsPerTradePercent=0.0002; xRShortMaxDrawdownPerTradePercent=0.15; xRLongR2R=1.5; xRLongLotsPerTradePercent=0.0002; xRLongMaxDrawdownPerTradePercent=0.15; xRMaximumCandlesPerTrade=96; xRSwingLength=48; xRSharpDetectionFactor=1350; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.0002; xTPWShortMaxDrawdownPerTradePercent=0.3; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.0002; xTPWLongMaxDrawdownPerTradePercent=0.3; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63768Ticks modelled73089409Modelling qualityn/a
Mismatched charts errors905
Initial deposit1000.00SpreadCurrent (51)
Total net profit11549.05Gross profit21988.17Gross loss-10439.12
Profit factor2.11Expected payoff62.43
Absolute drawdown79.00Maximal drawdown2410.03 (23.15%)Relative drawdown52.81% (1054.29)
Total trades185Short positions (won %)105 (59.05%)Long positions (won %)80 (58.75%)
Profit trades (% of total)109 (58.92%)Loss trades (% of total)76 (41.08%)
Largestprofit trade929.92loss trade-408.85
Averageprofit trade201.73loss trade-137.36
Maximumconsecutive wins (profit in money)15 (3323.80)consecutive losses (loss in money)8 (-643.55)
Maximalconsecutive profit (count of wins)4023.21 (12)consecutive loss (count of losses)-1081.46 (7)
Averageconsecutive wins4consecutive losses3
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 06:45sell10.201807.850.001797.08
22020.11.27 15:09t/p10.201797.080.001797.08215.401215.40
32020.11.27 15:09sell20.201796.570.001788.89
42020.11.27 15:36t/p20.201788.890.001788.89153.601369.00
52020.12.01 19:30buy30.201812.580.001853.94
62020.12.02 10:39buy40.201824.820.001839.43
72020.12.02 14:45close40.201817.320.001839.43-150.001219.00
82020.12.04 09:30buy50.201842.380.001854.80
92020.12.07 10:38close50.201822.380.001854.80-408.85810.15
102020.12.07 16:52t/p30.201853.940.001853.94774.121584.28
112021.01.06 02:00buy60.201950.710.001958.51
122021.01.06 12:00t/p60.201958.510.001958.51156.001740.28
132021.01.29 16:54sell70.201865.800.001855.99
142021.01.29 17:39t/p70.201855.990.001855.99196.201936.48
152021.02.04 16:00sell80.201808.190.001779.92
162021.02.05 17:24close80.201808.200.001779.923.921940.40
172021.02.05 19:15buy90.201814.780.001846.22
182021.02.08 14:49buy100.201824.180.001843.47
192021.02.09 09:54t/p100.201843.470.001843.47376.952317.35
202021.02.09 11:24t/p90.201846.220.001846.22611.112928.46
212021.02.09 17:45sell110.201841.990.001838.33
222021.02.09 18:09t/p110.201838.330.001838.3373.203001.66
232021.02.10 17:00sell120.201841.300.001827.41
242021.02.11 19:09t/p120.201827.410.001827.41290.173291.83
252021.02.16 15:15sell130.201811.040.001788.17
262021.02.16 17:09sell140.201804.040.001801.47
272021.02.16 18:49t/p140.201801.470.001801.4751.403343.23
282021.02.16 18:49sell150.201800.960.001767.09
292021.02.17 01:09t/p130.201788.170.001788.17461.523804.75
302021.02.19 02:39t/p150.201767.090.001767.09698.014502.76
312021.02.19 05:15buy160.201769.850.001786.38
322021.02.19 16:09t/p160.201786.380.001786.38330.604833.36
332021.02.23 04:00buy170.201813.570.001842.72
342021.02.23 05:45buy180.201813.260.001827.74
352021.02.23 11:24close170.201806.070.001842.72-150.004683.36
362021.02.23 11:24close180.201805.760.001827.74-150.004533.36
372021.02.23 11:24buy190.201806.260.001820.62
382021.02.23 16:37close190.201798.760.001820.62-150.004383.36
392021.03.03 16:51sell200.201712.530.001708.07
402021.03.03 17:36t/p200.201708.070.001708.0789.204472.56
412021.03.11 16:48buy210.201719.840.001727.97
422021.03.11 20:09t/p210.201727.970.001727.97162.604635.16
432021.03.17 13:48buy220.201728.280.001737.00
442021.03.17 20:06t/p220.201737.000.001737.00174.404809.56
452021.04.08 14:00buy230.201746.240.001756.38
462021.04.08 16:39t/p230.201756.380.001756.38202.805012.36
472021.04.19 15:15buy240.201775.840.001781.87
482021.04.21 04:30buy250.201779.820.001788.61
492021.04.21 04:39t/p240.201781.870.001781.87102.915115.27
502021.04.21 16:39t/p250.201788.610.001788.61175.805291.07
512021.04.27 18:24buy260.201778.360.001784.35
522021.04.28 12:24close260.201763.360.001784.35-308.854982.22
532021.05.04 23:15sell270.201779.150.001777.35
542021.05.05 03:24t/p270.201777.350.001777.3540.125022.34
552021.05.06 18:00buy280.201815.870.001857.41
562021.05.10 17:45sell290.201839.580.001833.85
572021.05.11 03:39t/p290.201833.850.001833.85118.725141.07
582021.05.12 23:21close280.201815.850.001857.41-35.785105.28
592021.05.13 13:15sell300.201810.390.001791.73
602021.05.13 15:07close300.201817.890.001791.73-150.004955.28
612021.05.19 22:00buy310.201863.400.001881.95
622021.05.20 19:49t/p310.201881.950.001881.95344.465299.74
632021.06.17 10:30sell320.201809.210.001762.92
642021.06.18 08:45sell330.201784.490.001777.35
652021.06.18 15:52t/p330.201777.350.001777.35142.805442.54
662021.06.18 22:54t/p320.201762.920.001762.92929.926372.47
672021.07.01 05:00buy340.201771.700.001788.95
682021.07.02 15:39t/p340.201788.950.001788.95336.156708.62
692021.07.06 19:07buy350.201794.020.001807.68
702021.07.07 13:24t/p350.201807.680.001807.68264.356972.97
712021.07.08 14:00buy360.201817.710.001849.35
722021.07.08 16:39close360.201810.210.001849.35-150.006822.97
732021.07.08 18:04buy370.201801.870.001814.59
742021.07.13 15:30buy380.201813.520.001824.52
752021.07.13 15:30close380.201806.020.001824.52-150.006672.97
762021.07.13 15:39t/p370.201814.590.001814.59227.866900.84
772021.07.13 17:21sell390.201811.750.001808.46
782021.07.13 20:34t/p390.201808.460.001808.4665.806966.64
792021.07.14 06:30buy400.201813.380.001826.10
802021.07.14 08:30buy410.201813.760.001827.05
812021.07.14 11:30buy420.201814.800.001828.95
822021.07.14 15:04buy430.201821.020.001839.02
832021.07.14 15:09t/p400.201826.100.001826.10254.407221.04
842021.07.14 15:37t/p410.201827.050.001827.05265.807486.84
852021.07.14 15:39t/p420.201828.950.001828.95283.007769.84
862021.07.15 17:09close430.201821.010.001839.02-26.747743.10
872021.07.16 22:30sell440.201810.350.001786.20
882021.07.19 09:15sell450.201806.190.001789.75
892021.07.19 16:09close450.201813.690.001789.75-150.007593.10
902021.07.19 18:15sell460.201807.210.001794.99
912021.07.19 23:30close440.201811.980.001786.20-28.487564.62
922021.07.19 23:30sell470.201811.480.001805.66
932021.07.20 04:04close460.201814.710.001794.99-145.887418.74
942021.07.20 04:04sell480.201814.210.001812.49
952021.07.20 05:07close470.201818.980.001805.66-145.887272.86
962021.07.20 11:09t/p480.201812.490.001812.4934.407307.26
972021.07.20 18:15sell490.201810.140.001788.26
982021.07.20 20:30sell500.201810.840.001790.01
992021.07.21 10:30sell510.201808.770.001801.56
1002021.07.21 14:03t/p510.201801.560.001801.56144.207451.46
1012021.07.23 10:54close490.201810.150.001788.2620.417471.87
1022021.07.23 14:34t/p500.201790.010.001790.01437.217909.08
1032021.07.29 04:30buy520.201816.130.001850.99
1042021.07.30 19:52close520.201816.120.001850.99-9.057900.04
1052021.07.30 21:45sell530.201810.450.001779.33
1062021.08.02 04:45sell540.201809.440.001783.03
1072021.08.02 06:30sell550.201811.180.001792.46
1082021.08.02 19:24close540.201816.940.001783.03-150.007750.04
1092021.08.02 19:39close530.201817.950.001779.33-145.887604.16
1102021.08.02 19:39sell560.201817.450.001799.74
1112021.08.02 19:54close550.201818.680.001792.46-150.007454.16
1122021.08.03 04:30sell570.201809.740.001795.34
1132021.08.03 06:15sell580.201810.010.001796.02
1142021.08.04 05:30close570.201813.380.001795.34-68.687385.48
1152021.08.04 05:30sell590.201812.880.001810.08
1162021.08.04 07:15close580.201812.750.001796.02-50.687334.80
1172021.08.04 14:36close560.201817.460.001799.748.047342.85
1182021.08.04 15:07close590.201820.380.001810.08-150.007192.85
1192021.08.04 18:30sell600.201806.630.001769.34
1202021.08.04 21:45sell610.201810.860.001779.92
1212021.08.05 08:54sell620.201808.740.001803.00
1222021.08.05 10:52close600.201814.130.001769.34-137.637055.21
1232021.08.05 11:37sell630.201809.130.001802.26
1242021.08.05 16:39sell640.201802.930.001795.96
1252021.08.05 16:39t/p620.201803.000.001803.00114.807170.01
1262021.08.05 16:39t/p630.201802.260.001802.26137.407307.41
1272021.08.06 10:18t/p640.201795.960.001795.96143.527450.94
1282021.08.06 15:39t/p610.201779.920.001779.92635.298086.22
1292021.08.17 17:15buy650.201782.620.001787.73
1302021.08.18 04:09t/p650.201787.730.001787.7393.358179.58
1312021.08.20 17:39sell660.201781.750.001777.75
1322021.08.23 02:18t/p660.201777.750.001777.7584.128263.70
1332021.08.26 13:45buy670.201787.170.001795.30
1342021.08.26 18:04t/p670.201795.300.001795.30162.608426.30
1352021.08.27 19:15buy680.201814.880.001860.66
1362021.08.30 20:15close680.201810.010.001860.66-106.258320.05
1372021.08.31 04:30buy690.201813.980.001822.79
1382021.08.31 14:15buy700.201814.230.001820.43
1392021.08.31 16:06close700.201806.730.001820.43-150.008170.05
1402021.08.31 16:06close690.201806.480.001822.79-150.008020.05
1412021.08.31 20:00buy710.201814.290.001832.64
1422021.09.01 04:30buy720.201812.910.001829.19
1432021.09.01 11:23sell730.201811.910.001804.44
1442021.09.01 15:52close730.201819.410.001804.44-150.007870.05
1452021.09.01 18:19sell740.201812.290.001800.92
1462021.09.01 21:00close710.201812.490.001832.64-44.857825.21
1472021.09.02 06:04close720.201812.900.001829.19-26.747798.47
1482021.09.02 07:30sell750.201811.430.001804.14
1492021.09.02 17:30sell760.201807.760.001793.92
1502021.09.03 04:06close740.201812.300.001800.9216.297814.76
1512021.09.03 04:37sell770.201810.730.001806.97
1522021.09.03 08:30close750.201811.800.001804.14-3.287811.48
1532021.09.03 14:07close760.201815.260.001793.92-145.887665.60
1542021.09.03 14:07sell780.201814.760.001805.79
1552021.09.03 15:34close770.201818.240.001806.97-150.207515.40
1562021.09.03 15:36close780.201822.260.001805.79-150.007365.40
1572021.09.07 13:15sell790.201810.900.001786.66
1582021.09.07 16:15sell800.201810.490.001785.77
1592021.09.08 16:54t/p790.201786.660.001786.66488.927854.32
1602021.09.08 16:54t/p800.201785.770.001785.77498.528352.85
1612021.10.21 09:45buy810.201786.670.001797.59
1622021.10.22 15:22t/p810.201797.590.001797.59209.558562.40
1632021.10.27 18:09sell820.201793.560.001789.11
1642021.10.28 16:30close820.201808.560.001789.11-287.638274.77
1652021.11.03 04:00sell830.201783.060.001779.26
1662021.11.03 08:15t/p830.201779.260.001779.2676.008350.77
1672021.11.05 18:45buy840.201814.330.001857.76
1682021.11.10 16:24t/p840.201857.760.001857.76842.069192.83
1692021.11.22 19:45sell850.201810.200.001755.21
1702021.11.23 04:15sell860.201807.780.001757.35
1712021.11.26 09:54close860.201807.790.001757.3520.419213.24
1722021.11.26 12:03close850.201810.210.001755.2124.539237.77
1732021.11.30 17:48sell870.201794.770.001781.02
1742021.11.30 18:04t/p870.201781.020.001781.02275.009512.77
1752021.12.13 16:49sell880.201785.140.001782.99
1762021.12.14 10:24t/p880.201782.990.001782.9947.129559.89
1772021.12.15 04:45sell890.201771.980.001768.80
1782021.12.15 07:39t/p890.201768.800.001768.8063.609623.49
1792021.12.15 16:54sell900.201769.740.001766.01
1802021.12.15 17:39t/p900.201766.010.001766.0174.609698.09
1812021.12.20 17:01sell910.201793.800.001789.41
1822021.12.20 22:09t/p910.201789.410.001789.4187.809785.89
1832021.12.21 16:52buy920.201793.730.001796.76
1842021.12.22 18:04t/p920.201796.760.001796.7651.759837.65
1852021.12.27 18:00buy930.201812.980.001827.61
1862021.12.28 08:00buy940.201813.200.001822.49
1872021.12.28 17:00buy950.201814.150.001821.35
1882021.12.28 19:00close930.201810.530.001827.61-57.859779.80
1892021.12.28 19:00buy960.201811.050.001813.05
1902021.12.28 20:51close950.201806.650.001821.35-150.009629.80
1912021.12.28 20:54close940.201805.700.001822.49-150.009479.80
1922021.12.29 10:07close960.201803.550.001813.05-158.859320.95
1932021.12.30 19:00buy970.201813.820.001839.85
1942022.01.03 15:09close970.201813.810.001839.85-17.899303.06
1952022.01.03 16:00sell980.201806.970.001776.15
1962022.01.04 17:00close980.201811.720.001776.15-90.889212.18
1972022.01.04 17:45buy990.201817.010.001844.22
1982022.01.04 19:30buy1000.201814.590.001838.17
1992022.01.05 21:09close990.201817.000.001844.22-9.059203.14
2002022.01.05 21:09close1000.201814.580.001838.17-9.059194.09
2012022.01.05 22:30sell1010.201810.000.001780.84
2022022.01.11 08:16close1010.201810.010.001780.8424.539218.62
2032022.01.11 18:30buy1020.201815.670.001836.03
2042022.01.13 17:51close1020.201815.660.001836.03-35.589183.04
2052022.01.18 12:00sell1030.201810.270.001791.81
2062022.01.18 15:30sell1040.201806.890.001783.36
2072022.01.18 15:34close1040.201814.390.001783.36-150.009033.04
2082022.01.18 15:37close1030.201817.770.001791.81-150.008883.04
2092022.01.18 18:19sell1050.201813.030.001806.19
2102022.01.19 05:15sell1060.201810.740.001797.05
2112022.01.19 07:00sell1070.201811.540.001805.36
2122022.01.19 12:34close1060.201818.240.001797.05-150.008733.04
2132022.01.19 12:37close1070.201819.040.001805.36-150.008583.04
2142022.01.19 12:37sell1080.201818.540.001805.81
2152022.01.19 16:37close1080.201826.040.001805.81-150.008433.04
2162022.01.19 16:52close1050.201828.030.001806.19-295.888137.16
2172022.01.27 09:00sell1090.201810.600.001776.66
2182022.01.27 13:15sell1100.201810.700.001793.86
2192022.01.27 18:24t/p1100.201793.860.001793.86336.808473.96
2202022.02.02 17:24close1090.201810.610.001776.6616.298490.25
2212022.02.04 12:30buy1110.201814.020.001827.67
2222022.02.04 15:30buy1120.201813.290.001824.06
2232022.02.04 15:36close1110.201806.520.001827.67-150.008340.25
2242022.02.04 15:36close1120.201805.780.001824.06-150.208190.05
2252022.02.07 02:45buy1130.201812.800.001843.33
2262022.02.07 11:00buy1140.201813.370.001822.93
2272022.02.07 14:00buy1150.201813.930.001821.18
2282022.02.07 18:37buy1160.201818.370.001830.55
2292022.02.07 21:06t/p1150.201821.180.001821.18145.008335.05
2302022.02.07 21:37t/p1140.201822.930.001822.93191.208526.25
2312022.02.09 11:30buy1170.201827.790.001831.60
2322022.02.09 15:07t/p1160.201830.550.001830.55225.918752.16
2332022.02.09 15:09t/p1170.201831.600.001831.6076.208828.36
2342022.02.11 20:34t/p1130.201843.330.001843.33557.529385.88
2352022.02.15 11:19buy1180.201856.870.001866.96
2362022.02.16 19:19t/p1180.201866.960.001866.96192.959578.84
2372022.02.18 17:33sell1190.201895.770.001893.21
2382022.02.18 17:37t/p1190.201893.210.001893.2151.209630.04
2392022.03.02 18:16sell1200.201921.470.001907.56
2402022.03.03 13:34close1200.201936.480.001907.56-287.839342.20
2412022.03.14 08:45sell1210.201975.330.001973.05
2422022.03.14 09:54t/p1210.201973.050.001973.0545.609387.80
2432022.04.22 19:22sell1220.201936.790.001932.93
2442022.04.22 20:28t/p1220.201932.930.001932.9377.209465.00
2452022.04.26 16:08sell1230.201905.800.001905.21
2462022.04.26 16:57t/p1230.201905.210.001905.2111.809476.80
2472022.05.13 16:15sell1240.201802.800.001764.16
2482022.05.13 17:01close1240.201810.300.001764.16-150.009326.80
2492022.05.13 19:00sell1250.201808.990.001779.64
2502022.05.16 02:00sell1260.201810.840.001796.49
2512022.05.16 03:58close1250.201816.490.001779.64-145.889180.92
2522022.05.16 06:45sell1270.201809.830.001798.46
2532022.05.16 10:42t/p1270.201798.460.001798.46227.409408.32
2542022.05.16 10:43t/p1260.201796.490.001796.49287.009695.32
2552022.05.18 06:30sell1280.201808.180.001785.79
2562022.05.18 10:00sell1290.201809.610.001794.63
2572022.05.18 10:28close1280.201815.680.001785.79-150.009545.32
2582022.05.18 11:12close1290.201817.110.001794.63-150.009395.32
2592022.05.18 15:15sell1300.201808.580.001791.15
2602022.05.18 16:43close1300.201816.090.001791.15-150.209245.12
2612022.06.10 16:01sell1310.201839.900.001834.17
2622022.06.10 16:18t/p1310.201834.170.001834.17114.609359.72
2632022.06.14 19:00sell1320.201810.290.001778.72
2642022.06.14 21:30sell1330.201810.070.001778.17
2652022.06.15 04:38close1330.201817.570.001778.17-145.889213.85
2662022.06.15 05:20close1320.201817.790.001778.72-145.889067.97
2672022.06.24 05:00sell1340.201823.760.001819.89
2682022.06.24 16:00t/p1340.201819.890.001819.8977.409145.37
2692022.06.30 13:45sell1350.201810.240.001792.95
2702022.06.30 15:37close1350.201817.750.001792.95-150.208995.17
2712022.06.30 18:00sell1360.201808.930.001784.98
2722022.06.30 20:00sell1370.201809.760.001787.05
2732022.07.01 14:39t/p1370.201787.050.001787.05458.329453.49
2742022.07.01 15:24t/p1360.201784.980.001784.98483.129936.61
2752022.07.20 16:52sell1380.201708.520.001702.79
2762022.07.20 19:48t/p1380.201702.790.001702.79114.6010051.21
2772022.08.01 01:30buy1390.201764.460.001772.38
2782022.08.01 12:57t/p1390.201772.380.001772.38158.4010209.61
2792022.08.02 18:02sell1400.201776.930.001767.92
2802022.08.02 21:02t/p1400.201767.920.001767.92180.2010389.81
2812022.08.22 14:15buy1410.201735.800.001742.64
2822022.08.23 11:42t/p1410.201742.640.001742.64127.9510517.77
2832022.09.05 04:45buy1420.201711.690.001722.31
2842022.09.06 03:46t/p1420.201722.310.001722.31203.5510721.32
2852022.09.30 20:35buy1430.201663.070.001667.31
2862022.10.03 04:30t/p1430.201667.310.001667.3175.9510797.27
2872022.11.02 21:03sell1440.201647.760.001626.40
2882022.11.03 10:26t/p1440.201626.400.001626.40439.5711236.84
2892022.11.15 04:45buy1450.201771.800.001782.63
2902022.11.15 09:47t/p1450.201782.630.001782.63216.6011453.44
2912022.11.21 20:30buy1460.201738.320.001753.50
2922022.11.21 23:45buy1470.201738.430.001742.36
2932022.11.22 03:06t/p1470.201742.360.001742.3669.7511523.19
2942022.11.24 02:26t/p1460.201753.500.001753.50259.3711782.56
2952022.11.30 10:00buy1480.201755.420.001761.93
2962022.11.30 11:36t/p1480.201761.930.001761.93130.2011912.76
2972022.11.30 17:18buy1490.201751.830.001763.12
2982022.11.30 21:20t/p1490.201763.120.001763.12225.8012138.56
2992022.12.09 17:23buy1500.201791.170.001800.19
3002022.12.09 18:20t/p1500.201800.190.001800.19180.4012318.96
3012022.12.13 16:30buy1510.201818.890.001875.11
3022022.12.13 17:47close1510.201811.390.001875.11-150.0012168.96
3032022.12.13 18:45buy1520.201813.270.001859.04
3042022.12.13 19:25close1520.201805.770.001859.04-150.0012018.96
3052022.12.20 17:15buy1530.201820.840.001871.26
3062022.12.21 06:43close1530.201813.340.001871.26-158.8511860.12
3072022.12.21 09:30buy1540.201815.350.001820.14
3082022.12.21 14:00buy1550.201814.060.001816.91
3092022.12.21 15:13t/p1550.201816.910.001816.9157.0011917.12
3102022.12.21 17:07t/p1540.201820.140.001820.1495.8012012.92
3112022.12.22 16:15sell1560.201807.890.001789.40
3122022.12.22 20:02t/p1560.201789.400.001789.40369.8012382.72
3132022.12.27 17:30buy1570.201821.700.001850.34
3142022.12.27 19:56close1570.201814.190.001850.34-150.2012232.52
3152022.12.27 20:15buy1580.201814.990.001833.56
3162022.12.28 03:30buy1590.201814.650.001832.71
3172022.12.28 09:03close1580.201807.490.001833.56-158.8512073.67
3182022.12.28 10:08close1590.201807.130.001832.71-150.4011923.27
3192022.12.29 17:00buy1600.201814.310.001828.76
3202022.12.29 18:45buy1610.201814.680.001829.68
3212022.12.30 18:38close1600.201814.300.001828.76-9.0511914.23
3222023.01.03 01:07t/p1610.201829.680.001829.68273.4612187.69
3232023.01.11 17:38buy1620.201870.920.001874.91
3242023.01.11 19:21t/p1620.201874.910.001874.9179.8012267.49
3252023.01.12 17:10sell1630.201884.680.001867.96
3262023.01.12 21:05close1630.201899.680.001867.96-300.0011967.49
3272023.01.20 09:00buy1640.201926.850.001936.66
3282023.01.20 10:08t/p1640.201936.660.001936.66196.2012163.69
3292023.02.07 16:32sell1650.201869.860.001868.93
3302023.02.07 16:45t/p1650.201868.930.001868.9318.6012182.29
3312023.02.09 17:00sell1660.201879.160.001868.22
3322023.02.09 18:03t/p1660.201868.220.001868.22218.8012401.09
3332023.02.24 18:15sell1670.201809.460.001784.47
3342023.02.24 20:00sell1680.201809.720.001785.12
3352023.02.24 23:15sell1690.201811.200.001791.97
3362023.02.27 05:30sell1700.201810.190.001802.03
3372023.02.27 16:00close1670.201816.960.001784.47-145.8812255.21
3382023.02.27 16:22close1680.201817.220.001785.12-145.8812109.33
3392023.02.27 16:22sell1710.201816.720.001801.36
3402023.02.27 16:23close1700.201817.690.001802.03-150.0011959.33
3412023.02.27 16:57close1690.201818.700.001791.97-145.8811813.45
3422023.02.28 10:00sell1720.201810.360.001797.04
3432023.02.28 12:00sell1730.201810.170.001796.57
3442023.02.28 16:46close1730.201817.670.001796.57-150.0011663.45
3452023.02.28 16:47close1720.201817.860.001797.04-150.0011513.45
3462023.02.28 17:03close1710.201824.220.001801.36-145.8811367.58
3472023.03.01 04:30buy1740.201829.010.001845.24
3482023.03.02 20:35sell1750.201835.870.001834.86
3492023.03.02 20:43t/p1750.201834.860.001834.8620.2011387.78
3502023.03.03 10:41t/p1740.201845.240.001845.24289.2211676.99
3512023.03.08 05:15sell1760.201809.930.001774.74
3522023.03.08 16:32close1760.201817.430.001774.74-150.0011526.99
3532023.04.25 09:30buy1770.201995.350.002008.13
3542023.04.26 16:27t/p1770.202008.130.002008.13246.7511773.75
3552023.04.26 19:17buy1780.201988.980.001995.09
3562023.04.27 05:12t/p1780.201995.090.001995.0995.6611869.41
3572023.05.15 17:34sell1790.202016.660.002011.32
3582023.05.16 09:04t/p1790.202011.320.002011.32110.9211980.33
3592023.05.26 17:09sell1800.201951.200.001949.72
3602023.05.26 17:19t/p1800.201949.720.001949.7229.6012009.93
3612023.06.07 17:32sell1810.201958.950.001947.93
3622023.06.07 18:50t/p1810.201947.930.001947.93220.4012230.33
3632023.07.04 17:45buy1820.201928.500.001932.73
3642023.07.05 16:17t/p1820.201932.730.001932.7375.7512306.08
3652023.07.13 18:04sell1830.201959.610.001957.54
3662023.07.13 18:51t/p1830.201957.540.001957.5441.4012347.48
3672023.07.19 18:12sell1840.201974.940.001970.18
3682023.07.20 17:35t/p1840.201970.180.001970.18107.5712455.05
3692023.07.25 15:30sell1850.201958.580.001953.88
3702023.07.25 17:00t/p1850.201953.880.001953.8894.0012549.05
+
diff --git a/Docs/Reports/StrategyTester X (XXX and XTPW) Full - 0.2.gif b/Docs/Reports/StrategyTester X (XXX and XTPW) Full - 0.2.gif new file mode 100644 index 0000000..6b9c0a9 Binary files /dev/null and b/Docs/Reports/StrategyTester X (XXX and XTPW) Full - 0.2.gif differ diff --git a/Docs/Reports/StrategyTester X (XXX and XTPW) Full - 0.2.htm b/Docs/Reports/StrategyTester X (XXX and XTPW) Full - 0.2.htm new file mode 100644 index 0000000..0f86f87 --- /dev/null +++ b/Docs/Reports/StrategyTester X (XXX and XTPW) Full - 0.2.htm @@ -0,0 +1,223 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.01 23:45 (2020.01.01 - 2023.08.02)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.0002; xShortMaxDrawdownPerTradePercent=0.4; xLongR2R=3; xLongLotsPerTradePercent=0.0002; xLongMaxDrawdownPerTradePercent=0.4; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +enableXRLong=true; +enableXRShort=true; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.0002; xTPWShortMaxDrawdownPerTradePercent=0.3; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.0002; xTPWLongMaxDrawdownPerTradePercent=0.3; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63353Ticks modelled72601176Modelling qualityn/a
Mismatched charts errors808
Initial deposit1000.00SpreadCurrent (50)
Total net profit7795.40Gross profit9684.44Gross loss-1889.04
Profit factor5.13Expected payoff105.34
Absolute drawdown601.05Maximal drawdown714.05 (64.16%)Relative drawdown64.16% (714.05)
Total trades74Short positions (won %)39 (89.74%)Long positions (won %)35 (94.29%)
Profit trades (% of total)68 (91.89%)Loss trades (% of total)6 (8.11%)
Largestprofit trade439.57loss trade-409.05
Averageprofit trade142.42loss trade-314.84
Maximumconsecutive wins (profit in money)19 (2789.35)consecutive losses (loss in money)1 (-409.05)
Maximalconsecutive profit (count of wins)2789.35 (19)consecutive loss (count of losses)-409.05 (1)
Averageconsecutive wins11consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 09:30buy10.201842.370.001854.79
22020.12.07 10:38close10.201822.360.001854.79-409.05590.95
32021.01.06 02:00buy20.201950.700.001958.50
42021.01.06 12:00t/p20.201958.500.001958.50156.00746.95
52021.01.29 16:54sell30.201865.800.001855.99
62021.01.29 17:39t/p30.201855.990.001855.99196.20943.15
72021.02.09 17:45sell40.201841.990.001838.33
82021.02.09 18:09t/p40.201838.330.001838.3373.201016.35
92021.02.10 17:00sell50.201841.300.001827.41
102021.02.11 19:09t/p50.201827.410.001827.41290.171306.52
112021.02.16 17:09sell60.201804.040.001801.47
122021.02.16 18:49t/p60.201801.470.001801.4751.401357.92
132021.02.19 05:15buy70.201769.840.001786.37
142021.02.19 16:09t/p70.201786.370.001786.37330.601688.52
152021.03.03 16:51sell80.201712.530.001708.07
162021.03.03 17:36t/p80.201708.070.001708.0789.201777.72
172021.03.11 16:48buy90.201719.830.001727.97
182021.03.11 20:09t/p90.201727.970.001727.97162.801940.52
192021.03.17 13:48buy100.201728.270.001737.00
202021.03.17 20:06t/p100.201737.000.001737.00174.602115.12
212021.04.08 14:00buy110.201746.230.001756.37
222021.04.08 16:39t/p110.201756.370.001756.37202.802317.92
232021.04.19 15:15buy120.201775.830.001781.86
242021.04.21 04:39t/p120.201781.860.001781.86102.912420.83
252021.04.27 18:24buy130.201778.350.001784.35
262021.04.28 12:24close130.201763.350.001784.35-308.852111.98
272021.05.04 23:15sell140.201779.150.001777.35
282021.05.05 03:24t/p140.201777.350.001777.3540.122152.10
292021.05.10 17:45sell150.201839.580.001833.85
302021.05.11 03:39t/p150.201833.850.001833.85118.722270.83
312021.05.19 22:00buy160.201863.390.001881.95
322021.05.20 19:49t/p160.201881.950.001881.95344.662615.49
332021.06.18 08:45sell170.201784.490.001777.35
342021.06.18 15:52t/p170.201777.350.001777.35142.802758.29
352021.07.01 05:00buy180.201771.690.001788.94
362021.07.02 15:39t/p180.201788.940.001788.94336.153094.44
372021.07.06 19:07buy190.201794.010.001807.68
382021.07.07 13:24t/p190.201807.680.001807.68264.553359.00
392021.07.08 18:04buy200.201801.860.001814.59
402021.07.13 15:39t/p200.201814.590.001814.59228.063587.06
412021.07.13 17:21sell210.201811.750.001808.46
422021.07.13 20:34t/p210.201808.460.001808.4665.803652.86
432021.07.14 12:00buy220.201814.410.001822.33
442021.07.14 15:06t/p220.201822.330.001822.33158.403811.26
452021.08.17 17:15buy230.201782.610.001787.72
462021.08.18 04:09t/p230.201787.720.001787.7293.353904.61
472021.08.20 17:39sell240.201781.750.001777.75
482021.08.23 02:18t/p240.201777.750.001777.7584.123988.73
492021.08.26 13:45buy250.201787.160.001795.29
502021.08.26 18:04t/p250.201795.290.001795.29162.604151.33
512021.08.31 15:30sell260.201811.860.001809.11
522021.08.31 16:04t/p260.201809.110.001809.1155.004206.33
532021.10.21 09:45buy270.201786.660.001797.58
542021.10.22 15:22t/p270.201797.580.001797.58209.554415.89
552021.10.27 18:09sell280.201793.560.001789.11
562021.10.28 16:30close280.201808.560.001789.11-287.634128.25
572021.11.03 04:00sell290.201783.060.001779.26
582021.11.03 08:15t/p290.201779.260.001779.2676.004204.25
592021.11.30 17:48sell300.201794.770.001781.02
602021.11.30 18:04t/p300.201781.020.001781.02275.004479.25
612021.12.13 16:49sell310.201785.140.001782.99
622021.12.14 10:24t/p310.201782.990.001782.9947.124526.38
632021.12.15 04:45sell320.201771.980.001768.80
642021.12.15 07:39t/p320.201768.800.001768.8063.604589.98
652021.12.15 16:54sell330.201769.740.001766.01
662021.12.15 17:39t/p330.201766.010.001766.0174.604664.58
672021.12.20 17:01sell340.201793.800.001789.41
682021.12.20 22:09t/p340.201789.410.001789.4187.804752.38
692021.12.21 16:52buy350.201793.720.001796.76
702021.12.22 18:04t/p350.201796.760.001796.7651.954804.33
712022.01.18 18:19sell360.201813.030.001806.19
722022.01.19 16:52close360.201828.030.001806.19-295.884508.45
732022.02.09 11:30buy370.201827.780.001831.59
742022.02.09 15:09t/p370.201831.590.001831.5976.204584.65
752022.02.15 11:19buy380.201856.860.001866.95
762022.02.16 19:19t/p380.201866.950.001866.95192.954777.61
772022.02.18 17:33sell390.201895.770.001893.21
782022.02.18 17:37t/p390.201893.210.001893.2151.204828.81
792022.03.02 18:16sell400.201921.470.001907.56
802022.03.03 13:34close400.201936.470.001907.56-287.634541.17
812022.03.14 08:45sell410.201975.330.001973.05
822022.03.14 09:54t/p410.201973.050.001973.0545.604586.77
832022.04.22 19:22sell420.201936.790.001932.93
842022.04.22 20:28t/p420.201932.930.001932.9377.204663.97
852022.04.26 16:08sell430.201905.800.001905.21
862022.04.26 16:57t/p430.201905.210.001905.2111.804675.77
872022.06.10 16:01sell440.201839.900.001834.17
882022.06.10 16:18t/p440.201834.170.001834.17114.604790.37
892022.06.24 05:00sell450.201823.760.001819.89
902022.06.24 16:00t/p450.201819.890.001819.8977.404867.77
912022.07.20 16:52sell460.201708.520.001702.79
922022.07.20 19:48t/p460.201702.790.001702.79114.604982.37
932022.08.01 01:30buy470.201764.450.001772.37
942022.08.01 12:57t/p470.201772.370.001772.37158.405140.77
952022.08.02 18:02sell480.201776.930.001767.92
962022.08.02 21:02t/p480.201767.920.001767.92180.205320.97
972022.08.22 14:15buy490.201735.790.001742.63
982022.08.23 11:42t/p490.201742.630.001742.63127.955448.93
992022.09.05 04:45buy500.201711.680.001722.30
1002022.09.06 03:46t/p500.201722.300.001722.30203.555652.48
1012022.09.30 20:35buy510.201663.060.001667.30
1022022.10.03 04:30t/p510.201667.300.001667.3075.955728.43
1032022.11.02 21:03sell520.201647.760.001626.40
1042022.11.03 10:26t/p520.201626.400.001626.40439.576168.00
1052022.11.15 04:45buy530.201771.790.001782.62
1062022.11.15 09:47t/p530.201782.620.001782.62216.606384.60
1072022.11.21 20:30buy540.201738.310.001753.49
1082022.11.21 23:45buy550.201738.420.001742.35
1092022.11.22 03:06t/p550.201742.350.001742.3569.756454.35
1102022.11.24 02:26t/p540.201753.490.001753.49259.376713.72
1112022.11.30 10:00buy560.201755.410.001761.92
1122022.11.30 11:36t/p560.201761.920.001761.92130.206843.92
1132022.11.30 17:18buy570.201751.820.001763.12
1142022.11.30 21:20t/p570.201763.120.001763.12226.007069.92
1152022.12.09 17:23buy580.201791.160.001800.19
1162022.12.09 18:20t/p580.201800.190.001800.19180.607250.52
1172023.01.11 17:38buy590.201870.910.001874.91
1182023.01.11 19:21t/p590.201874.910.001874.9180.007330.52
1192023.01.12 17:10sell600.201884.680.001867.96
1202023.01.12 21:05close600.201899.680.001867.96-300.007030.52
1212023.01.20 09:00buy610.201926.840.001936.65
1222023.01.20 10:08t/p610.201936.650.001936.65196.207226.72
1232023.02.07 16:32sell620.201869.860.001868.93
1242023.02.07 16:45t/p620.201868.930.001868.9318.607245.32
1252023.02.09 17:00sell630.201879.160.001868.22
1262023.02.09 18:03t/p630.201868.220.001868.22218.807464.12
1272023.03.01 04:30buy640.201829.000.001845.23
1282023.03.02 20:35sell650.201835.870.001834.87
1292023.03.02 20:43t/p650.201834.870.001834.8720.007484.12
1302023.03.03 10:41t/p640.201845.230.001845.23289.227773.34
1312023.04.25 09:30buy660.201995.340.002008.12
1322023.04.26 16:27t/p660.202008.120.002008.12246.758020.09
1332023.04.26 19:17buy670.201988.970.001995.08
1342023.04.27 05:12t/p670.201995.080.001995.0895.668115.76
1352023.05.15 17:34sell680.202016.660.002011.32
1362023.05.16 09:04t/p680.202011.320.002011.32110.928226.68
1372023.05.26 17:09sell690.201951.200.001949.72
1382023.05.26 17:19t/p690.201949.720.001949.7229.608256.28
1392023.06.07 17:32sell700.201958.950.001947.93
1402023.06.07 18:50t/p700.201947.930.001947.93220.408476.68
1412023.07.04 17:45buy710.201928.490.001932.72
1422023.07.05 16:17t/p710.201932.720.001932.7275.758552.43
1432023.07.13 18:04sell720.201959.610.001957.54
1442023.07.13 18:51t/p720.201957.540.001957.5441.408593.83
1452023.07.19 18:12sell730.201974.940.001970.18
1462023.07.20 17:35t/p730.201970.180.001970.18107.578701.40
1472023.07.25 15:30sell740.201958.580.001953.88
1482023.07.25 17:00t/p740.201953.880.001953.8894.008795.40
+
diff --git a/Docs/Reports/StrategyTester X (XXX and XTPW) Full.gif b/Docs/Reports/StrategyTester X (XXX and XTPW) Full.gif new file mode 100644 index 0000000..b8382b5 Binary files /dev/null and b/Docs/Reports/StrategyTester X (XXX and XTPW) Full.gif differ diff --git a/Docs/Reports/StrategyTester X (XXX and XTPW) Full.htm b/Docs/Reports/StrategyTester X (XXX and XTPW) Full.htm new file mode 100644 index 0000000..c78b557 --- /dev/null +++ b/Docs/Reports/StrategyTester X (XXX and XTPW) Full.htm @@ -0,0 +1,227 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.01 23:45 (2020.01.01 - 2023.08.02)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +enableXRLong=true; +enableXRShort=true; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63353Ticks modelled72601176Modelling qualityn/a
Mismatched charts errors808
Initial deposit1000.00SpreadCurrent (51)
Total net profit410.10Gross profit504.55Gross loss-94.45
Profit factor5.34Expected payoff5.40
Absolute drawdown18.44Maximal drawdown26.23 (2.16%)Relative drawdown2.39% (24.08)
Total trades76Short positions (won %)40 (90.00%)Long positions (won %)36 (94.44%)
Profit trades (% of total)70 (92.11%)Loss trades (% of total)6 (7.89%)
Largestprofit trade21.98loss trade-20.44
Averageprofit trade7.21loss trade-15.74
Maximumconsecutive wins (profit in money)19 (139.44)consecutive losses (loss in money)1 (-20.44)
Maximalconsecutive profit (count of wins)139.44 (19)consecutive loss (count of losses)-20.44 (1)
Averageconsecutive wins10consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 09:30buy10.011842.380.001854.80
22020.12.04 17:39sell20.011836.610.001825.20
32020.12.07 10:37t/p20.011825.200.001825.2011.621011.62
42020.12.07 10:38close10.011822.380.001854.80-20.44991.17
52021.01.06 02:00buy30.011950.710.001958.51
62021.01.06 12:00t/p30.011958.510.001958.517.80998.97
72021.01.29 16:54sell40.011865.800.001855.99
82021.01.29 17:39t/p40.011855.990.001855.999.811008.78
92021.02.09 17:45sell50.011841.990.001838.33
102021.02.09 18:09t/p50.011838.330.001838.333.661012.44
112021.02.10 17:00sell60.011841.300.001827.41
122021.02.11 19:09t/p60.011827.410.001827.4114.511026.95
132021.02.16 17:09sell70.011804.040.001801.47
142021.02.16 18:49t/p70.011801.470.001801.472.571029.52
152021.02.19 05:15buy80.011769.850.001786.38
162021.02.19 16:09t/p80.011786.380.001786.3816.531046.05
172021.03.03 16:51sell90.011712.530.001708.07
182021.03.03 17:36t/p90.011708.070.001708.074.461050.51
192021.03.11 16:48buy100.011719.840.001727.97
202021.03.11 20:09t/p100.011727.970.001727.978.131058.64
212021.03.17 13:48buy110.011728.280.001737.00
222021.03.17 20:06t/p110.011737.000.001737.008.721067.36
232021.04.08 14:00buy120.011746.240.001756.38
242021.04.08 16:39t/p120.011756.380.001756.3810.141077.50
252021.04.19 15:15buy130.011775.840.001781.87
262021.04.21 04:30buy140.011779.820.001788.61
272021.04.21 04:39t/p130.011781.870.001781.875.151082.65
282021.04.21 16:39t/p140.011788.610.001788.618.791091.44
292021.04.27 18:24buy150.011778.360.001784.35
302021.04.28 12:24close150.011763.360.001784.35-15.441076.00
312021.05.04 23:15sell160.011779.150.001777.35
322021.05.05 03:24t/p160.011777.350.001777.352.011078.00
332021.05.10 17:45sell170.011839.580.001833.85
342021.05.11 03:39t/p170.011833.850.001833.855.941083.94
352021.05.19 22:00buy180.011863.400.001881.95
362021.05.20 19:49t/p180.011881.950.001881.9517.221101.16
372021.06.18 08:45sell190.011784.490.001777.35
382021.06.18 15:52t/p190.011777.350.001777.357.141108.30
392021.07.01 05:00buy200.011771.700.001788.95
402021.07.02 15:39t/p200.011788.950.001788.9516.811125.11
412021.07.06 19:07buy210.011794.020.001807.68
422021.07.07 13:24t/p210.011807.680.001807.6813.221138.33
432021.07.08 18:04buy220.011801.870.001814.59
442021.07.13 15:39t/p220.011814.590.001814.5911.391149.72
452021.07.13 17:21sell230.011811.750.001808.46
462021.07.13 20:34t/p230.011808.460.001808.463.291153.01
472021.07.14 12:00buy240.011814.420.001822.34
482021.07.14 15:06t/p240.011822.340.001822.347.921160.93
492021.08.17 17:15buy250.011782.620.001787.73
502021.08.18 04:09t/p250.011787.730.001787.734.671165.60
512021.08.20 17:39sell260.011781.750.001777.75
522021.08.23 02:18t/p260.011777.750.001777.754.211169.80
532021.08.26 13:45buy270.011787.170.001795.30
542021.08.26 18:04t/p270.011795.300.001795.308.131177.93
552021.08.31 15:30sell280.011811.860.001809.11
562021.08.31 16:04t/p280.011809.110.001809.112.751180.68
572021.10.21 09:45buy290.011786.670.001797.59
582021.10.22 15:22t/p290.011797.590.001797.5910.481191.16
592021.10.27 18:09sell300.011793.560.001789.11
602021.10.28 16:30close300.011808.560.001789.11-14.381176.78
612021.11.03 04:00sell310.011783.060.001779.26
622021.11.03 08:15t/p310.011779.260.001779.263.801180.58
632021.11.30 17:48sell320.011794.770.001781.02
642021.11.30 18:04t/p320.011781.020.001781.0213.751194.33
652021.12.13 16:49sell330.011785.140.001782.99
662021.12.14 10:24t/p330.011782.990.001782.992.361196.68
672021.12.15 04:45sell340.011771.980.001768.80
682021.12.15 07:39t/p340.011768.800.001768.803.181199.86
692021.12.15 16:54sell350.011769.740.001766.01
702021.12.15 17:39t/p350.011766.010.001766.013.731203.59
712021.12.20 17:01sell360.011793.800.001789.41
722021.12.20 22:09t/p360.011789.410.001789.414.391207.98
732021.12.21 16:52buy370.011793.730.001796.76
742021.12.22 18:04t/p370.011796.760.001796.762.591210.57
752022.01.18 18:19sell380.011813.030.001806.19
762022.01.19 16:52close380.011828.030.001806.19-14.791195.78
772022.02.09 11:30buy390.011827.790.001831.60
782022.02.09 15:09t/p390.011831.600.001831.603.811199.59
792022.02.15 11:19buy400.011856.870.001866.96
802022.02.16 19:19t/p400.011866.960.001866.969.651209.24
812022.02.18 17:33sell410.011895.770.001893.21
822022.02.18 17:37t/p410.011893.210.001893.212.561211.80
832022.03.02 18:16sell420.011921.470.001907.56
842022.03.03 13:34close420.011936.480.001907.56-14.391197.40
852022.03.14 08:45sell430.011975.330.001973.05
862022.03.14 09:54t/p430.011973.050.001973.052.281199.68
872022.04.22 19:22sell440.011936.790.001932.93
882022.04.22 20:28t/p440.011932.930.001932.933.861203.54
892022.04.26 16:08sell450.011905.800.001905.21
902022.04.26 16:57t/p450.011905.210.001905.210.591204.13
912022.06.10 16:01sell460.011839.900.001834.17
922022.06.10 16:18t/p460.011834.170.001834.175.731209.86
932022.06.24 05:00sell470.011823.760.001819.89
942022.06.24 16:00t/p470.011819.890.001819.893.871213.73
952022.07.20 16:52sell480.011708.520.001702.79
962022.07.20 19:48t/p480.011702.790.001702.795.731219.46
972022.08.01 01:30buy490.011764.460.001772.38
982022.08.01 12:57t/p490.011772.380.001772.387.921227.38
992022.08.02 18:02sell500.011776.930.001767.92
1002022.08.02 21:02t/p500.011767.920.001767.929.011236.39
1012022.08.22 14:15buy510.011735.800.001742.64
1022022.08.23 11:42t/p510.011742.640.001742.646.401242.79
1032022.09.05 04:45buy520.011711.690.001722.31
1042022.09.06 03:46t/p520.011722.310.001722.3110.181252.97
1052022.09.30 20:35buy530.011663.070.001667.31
1062022.10.03 04:30t/p530.011667.310.001667.313.801256.77
1072022.11.02 21:03sell540.011647.760.001626.40
1082022.11.03 10:26t/p540.011626.400.001626.4021.981278.75
1092022.11.15 04:45buy550.011771.800.001782.63
1102022.11.15 09:47t/p550.011782.630.001782.6310.831289.58
1112022.11.21 20:30buy560.011738.320.001753.50
1122022.11.21 23:45buy570.011738.430.001742.36
1132022.11.22 03:06t/p570.011742.360.001742.363.491293.06
1142022.11.24 02:26t/p560.011753.500.001753.5012.971306.03
1152022.11.30 10:00buy580.011755.420.001761.93
1162022.11.30 11:36t/p580.011761.930.001761.936.511312.54
1172022.11.30 17:18buy590.011751.830.001763.12
1182022.11.30 21:20t/p590.011763.120.001763.1211.291323.83
1192022.12.09 17:23buy600.011791.170.001800.19
1202022.12.09 18:20t/p600.011800.190.001800.199.021332.85
1212023.01.11 17:38buy610.011870.920.001874.91
1222023.01.11 19:21t/p610.011874.910.001874.913.991336.84
1232023.01.12 17:10sell620.011884.680.001867.96
1242023.01.12 21:05close620.011899.680.001867.96-15.001321.84
1252023.01.20 09:00buy630.011926.850.001936.66
1262023.01.20 10:08t/p630.011936.660.001936.669.811331.65
1272023.02.07 16:32sell640.011869.860.001868.93
1282023.02.07 16:45t/p640.011868.930.001868.930.931332.58
1292023.02.09 17:00sell650.011879.160.001868.22
1302023.02.09 18:03t/p650.011868.220.001868.2210.941343.52
1312023.03.01 04:30buy660.011829.010.001845.24
1322023.03.02 20:35sell670.011835.870.001834.86
1332023.03.02 20:43t/p670.011834.860.001834.861.011344.53
1342023.03.03 10:41t/p660.011845.240.001845.2414.461358.99
1352023.04.25 09:30buy680.011995.350.002008.13
1362023.04.26 16:27t/p680.012008.130.002008.1312.341371.33
1372023.04.26 19:17buy690.011988.980.001995.09
1382023.04.27 05:12t/p690.011995.090.001995.094.781376.11
1392023.05.15 17:34sell700.012016.660.002011.32
1402023.05.16 09:04t/p700.012011.320.002011.325.551381.66
1412023.05.26 17:09sell710.011951.200.001949.72
1422023.05.26 17:19t/p710.011949.720.001949.721.481383.14
1432023.06.07 17:32sell720.011958.950.001947.93
1442023.06.07 18:50t/p720.011947.930.001947.9311.021394.16
1452023.07.04 17:45buy730.011928.500.001932.73
1462023.07.05 16:17t/p730.011932.730.001932.733.791397.95
1472023.07.13 18:04sell740.011959.610.001957.54
1482023.07.13 18:51t/p740.011957.540.001957.542.071400.02
1492023.07.19 18:12sell750.011974.940.001970.18
1502023.07.20 17:35t/p750.011970.180.001970.185.381405.40
1512023.07.25 15:30sell760.011958.580.001953.88
1522023.07.25 17:00t/p760.011953.880.001953.884.701410.10
+
diff --git a/Docs/Reports/Tests/X/StrategyTester - lots 0.00001 - maxd 0.015 - r2r 3 - 1.gif b/Docs/Reports/Tests/X/StrategyTester - lots 0.00001 - maxd 0.015 - r2r 3 - 1.gif new file mode 100644 index 0000000..868fd3f Binary files /dev/null and b/Docs/Reports/Tests/X/StrategyTester - lots 0.00001 - maxd 0.015 - r2r 3 - 1.gif differ diff --git a/Docs/Reports/Tests/X/StrategyTester - lots 0.00001 - maxd 0.015 - r2r 3 - 1.htm b/Docs/Reports/Tests/X/StrategyTester - lots 0.00001 - maxd 0.015 - r2r 3 - 1.htm new file mode 100644 index 0000000..55cca55 --- /dev/null +++ b/Docs/Reports/Tests/X/StrategyTester - lots 0.00001 - maxd 0.015 - r2r 3 - 1.htm @@ -0,0 +1,159 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.07.27 23:45 (2020.01.01 - 2023.07.28)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.015; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.015; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.01; xTPWLongR2R=1.5; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.01; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=700;
Bars in test63077Ticks modelled72224447Modelling qualityn/a
Mismatched charts errors798
Initial deposit1000.00SpreadCurrent (58)
Total net profit191.89Gross profit281.98Gross loss-90.09
Profit factor3.13Expected payoff4.26
Absolute drawdown21.51Maximal drawdown42.93 (3.48%)Relative drawdown3.48% (42.93)
Total trades45Short positions (won %)24 (83.33%)Long positions (won %)21 (90.48%)
Profit trades (% of total)39 (86.67%)Loss trades (% of total)6 (13.33%)
Largestprofit trade16.82loss trade-15.43
Averageprofit trade7.23loss trade-15.02
Maximumconsecutive wins (profit in money)17 (134.54)consecutive losses (loss in money)2 (-30.00)
Maximalconsecutive profit (count of wins)134.54 (17)consecutive loss (count of losses)-30.00 (2)
Averageconsecutive wins10consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 09:30buy10.011842.450.001854.87
22020.12.07 10:34close10.011827.450.001854.87-15.43984.57
32020.12.18 02:30sell20.011884.040.001880.44
42020.12.18 03:21t/p20.011880.440.001880.443.60988.17
52021.01.06 02:00buy30.011950.780.001958.58
62021.01.06 12:00t/p30.011958.580.001958.587.80995.97
72021.02.19 05:15buy40.011769.920.001786.45
82021.02.19 16:09t/p40.011786.450.001786.4516.531012.50
92021.04.08 14:00buy50.011746.310.001756.45
102021.04.08 16:39t/p50.011756.450.001756.4510.141022.64
112021.04.21 04:30buy60.011779.890.001788.68
122021.04.21 16:39t/p60.011788.680.001788.688.791031.43
132021.05.04 23:15sell70.011779.150.001777.35
142021.05.05 03:24t/p70.011777.350.001777.352.001033.43
152021.06.03 23:15sell80.011870.990.001864.93
162021.06.04 03:45sell90.011869.320.001861.64
172021.06.04 04:49t/p80.011864.930.001864.936.261039.69
182021.06.04 04:52t/p90.011861.640.001861.647.681047.37
192021.06.17 08:00sell100.011821.330.001813.95
202021.06.17 09:09t/p100.011813.950.001813.957.381054.75
212021.06.18 08:45sell110.011784.490.001777.35
222021.06.18 15:52t/p110.011777.350.001777.357.141061.89
232021.07.01 05:00buy120.011771.770.001789.02
242021.07.02 15:39t/p120.011789.020.001789.0216.821078.71
252021.07.14 12:00buy130.011814.490.001822.41
262021.07.14 15:07t/p130.011822.410.001822.417.921086.63
272021.08.26 13:45buy140.011787.240.001795.37
282021.08.26 18:04t/p140.011795.370.001795.378.131094.76
292021.10.21 09:45buy150.011786.740.001797.66
302021.10.22 15:22t/p150.011797.660.001797.6610.491105.24
312021.11.23 05:30sell160.011808.910.001802.04
322021.11.23 10:52t/p160.011802.040.001802.046.871112.11
332021.12.15 04:45sell170.011771.980.001768.80
342021.12.15 07:39t/p170.011768.800.001768.803.181115.29
352022.02.09 11:30buy180.011827.860.001831.67
362022.02.09 15:09t/p180.011831.670.001831.673.811119.10
372022.02.14 13:30sell190.011855.860.001850.34
382022.02.14 17:39close190.011870.860.001850.34-15.001104.10
392022.03.14 08:45sell200.011975.330.001973.05
402022.03.14 10:01t/p200.011973.050.001973.052.281106.38
412022.03.16 05:15sell210.011919.680.001909.45
422022.03.16 16:19t/p210.011909.450.001909.4510.231116.61
432022.05.17 11:30sell220.011827.110.001818.29
442022.05.17 21:12t/p220.011818.290.001818.298.821125.43
452022.06.24 05:00sell230.011823.760.001819.89
462022.06.24 16:00t/p230.011819.890.001819.893.871129.30
472022.07.06 01:05sell240.011766.830.001763.38
482022.07.06 13:07t/p240.011763.380.001763.383.451132.75
492022.07.07 01:45sell250.011738.940.001733.96
502022.07.07 05:30sell260.011739.930.001733.36
512022.07.08 10:45t/p250.011733.960.001733.965.181137.93
522022.07.08 15:31t/p260.011733.360.001733.366.771144.70
532022.08.01 01:30buy270.011764.530.001772.45
542022.08.01 12:57t/p270.011772.450.001772.457.921152.62
552022.08.08 22:30sell280.011787.280.001781.64
562022.08.10 15:32close280.011802.280.001781.64-14.601138.02
572022.08.22 14:15buy290.011735.870.001742.71
582022.08.23 11:42t/p290.011742.710.001742.716.411144.43
592022.09.05 04:45buy300.011711.760.001722.38
602022.09.06 03:47t/p300.011722.380.001722.3810.191154.62
612022.10.10 23:00sell310.011668.780.001662.90
622022.10.11 05:13t/p310.011662.900.001662.906.081160.70
632022.11.15 04:45buy320.011771.870.001782.70
642022.11.15 09:47t/p320.011782.700.001782.7010.831171.53
652022.11.15 15:00sell330.011775.140.001768.81
662022.11.15 16:48t/p330.011768.810.001768.816.331177.86
672022.11.21 20:30buy340.011738.390.001753.57
682022.11.21 23:45buy350.011738.500.001742.43
692022.11.22 03:07t/p350.011742.430.001742.433.501181.36
702022.11.24 02:26t/p340.011753.570.001753.5713.021194.38
712022.11.30 10:00buy360.011755.490.001762.00
722022.11.30 12:00t/p360.011762.000.001762.006.511200.89
732023.01.20 09:00buy370.011926.920.001936.73
742023.01.20 10:08t/p370.011936.730.001936.739.811210.70
752023.02.03 05:45sell380.011916.370.001914.03
762023.02.03 09:32t/p380.011914.030.001914.032.341213.04
772023.03.01 04:30buy390.011829.080.001845.31
782023.03.03 10:42t/p390.011845.310.001845.3114.501227.54
792023.03.21 07:45sell400.011981.970.001978.01
802023.03.21 08:23t/p400.011978.010.001978.013.961231.50
812023.03.31 07:15sell410.011981.510.001979.86
822023.03.31 08:08t/p410.011979.860.001979.861.651233.15
832023.04.25 09:30buy420.011995.420.002008.20
842023.04.25 14:02close420.011980.420.002008.20-15.001218.15
852023.05.08 01:45sell430.012014.730.002005.97
862023.05.08 18:42close430.012029.730.002005.97-15.001203.15
872023.07.04 17:45buy440.011928.570.001932.80
882023.07.05 16:17t/p440.011932.800.001932.803.801206.95
892023.07.07 04:30sell450.011911.150.001907.91
902023.07.07 15:30close450.011926.210.001907.91-15.061191.89
+
diff --git a/Docs/Reports/Tests/X/StrategyTester - lots 0.00001 - maxd 0.015 - r2r 3.gif b/Docs/Reports/Tests/X/StrategyTester - lots 0.00001 - maxd 0.015 - r2r 3.gif new file mode 100644 index 0000000..1cc0637 Binary files /dev/null and b/Docs/Reports/Tests/X/StrategyTester - lots 0.00001 - maxd 0.015 - r2r 3.gif differ diff --git a/Docs/Reports/Tests/X/StrategyTester - lots 0.00001 - maxd 0.015 - r2r 3.htm b/Docs/Reports/Tests/X/StrategyTester - lots 0.00001 - maxd 0.015 - r2r 3.htm new file mode 100644 index 0000000..6477e82 --- /dev/null +++ b/Docs/Reports/Tests/X/StrategyTester - lots 0.00001 - maxd 0.015 - r2r 3.htm @@ -0,0 +1,173 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.07.27 23:45 (2020.01.01 - 2023.07.28)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.015; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.015; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +xTPWShortR2R=1.5; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.01; xTPWLongR2R=1.5; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.01; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=700;
Bars in test63077Ticks modelled72224447Modelling qualityn/a
Mismatched charts errors798
Initial deposit1000.00SpreadCurrent (59)
Total net profit176.26Gross profit265.68Gross loss-89.42
Profit factor2.97Expected payoff3.39
Absolute drawdown6.09Maximal drawdown47.44 (3.88%)Relative drawdown3.88% (47.44)
Total trades52Short positions (won %)37 (83.78%)Long positions (won %)15 (100.00%)
Profit trades (% of total)46 (88.46%)Loss trades (% of total)6 (11.54%)
Largestprofit trade10.83loss trade-15.01
Averageprofit trade5.78loss trade-14.90
Maximumconsecutive wins (profit in money)18 (96.73)consecutive losses (loss in money)2 (-29.81)
Maximalconsecutive profit (count of wins)96.73 (18)consecutive loss (count of losses)-29.81 (2)
Averageconsecutive wins9consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.18 02:30sell10.011884.040.001880.44
22020.12.18 03:21t/p10.011880.440.001880.443.601003.60
32021.01.06 02:00buy20.011950.790.001958.59
42021.01.06 12:00t/p20.011958.590.001958.597.801011.40
52021.01.21 02:45sell30.011869.150.001861.32
62021.01.21 15:54t/p30.011861.320.001861.327.831019.23
72021.03.09 22:15sell40.011716.740.001708.85
82021.03.10 13:30t/p40.011708.850.001708.858.091027.32
92021.04.01 03:45sell50.011706.320.001698.49
102021.04.01 16:01close50.011721.320.001698.49-15.001012.32
112021.04.08 14:00buy60.011746.320.001756.46
122021.04.08 16:39t/p60.011756.460.001756.4610.141022.46
132021.04.15 21:15sell70.011767.210.001764.03
142021.04.15 23:24t/p70.011764.030.001764.033.181025.64
152021.04.21 04:30buy80.011779.900.001788.69
162021.04.21 16:39t/p80.011788.690.001788.698.791034.43
172021.05.04 23:15sell90.011779.150.001777.35
182021.05.05 03:24t/p90.011777.350.001777.352.001036.43
192021.05.07 13:45sell100.011820.100.001817.55
202021.05.07 15:33t/p100.011817.550.001817.552.551038.98
212021.06.03 23:15sell110.011870.990.001864.93
222021.06.04 03:45sell120.011869.320.001861.64
232021.06.04 04:49t/p110.011864.930.001864.936.261045.24
242021.06.04 04:52t/p120.011861.640.001861.647.681052.92
252021.06.17 08:00sell130.011821.330.001813.95
262021.06.17 09:09t/p130.011813.950.001813.957.381060.30
272021.06.18 08:45sell140.011784.490.001777.35
282021.06.18 15:52t/p140.011777.350.001777.357.141067.44
292021.07.14 12:00buy150.011814.500.001822.42
302021.07.14 15:07t/p150.011822.420.001822.427.921075.36
312021.08.26 13:45buy160.011787.250.001795.38
322021.08.26 18:04t/p160.011795.380.001795.388.131083.49
332021.10.21 09:45buy170.011786.750.001797.67
342021.10.22 15:22t/p170.011797.670.001797.6710.491093.98
352021.11.23 05:30sell180.011808.910.001802.04
362021.11.23 10:52t/p180.011802.040.001802.046.871100.85
372021.12.15 04:45sell190.011771.980.001768.80
382021.12.15 07:39t/p190.011768.800.001768.803.181104.03
392022.02.09 11:30buy200.011827.870.001831.68
402022.02.09 15:09t/p200.011831.680.001831.683.811107.84
412022.02.14 13:30sell210.011855.860.001850.34
422022.02.14 17:39close210.011870.860.001850.34-15.001092.84
432022.03.14 08:45sell220.011975.330.001973.05
442022.03.14 10:01t/p220.011973.050.001973.052.281095.12
452022.03.16 05:15sell230.011919.680.001909.45
462022.03.16 16:19t/p230.011909.450.001909.4510.231105.35
472022.05.17 05:00sell240.011826.120.001823.51
482022.05.17 06:33t/p240.011823.510.001823.512.611107.96
492022.06.24 05:00sell250.011823.760.001819.89
502022.06.24 16:00t/p250.011819.890.001819.893.871111.83
512022.07.06 01:05sell260.011766.830.001763.38
522022.07.06 13:07t/p260.011763.380.001763.383.451115.28
532022.07.07 01:45sell270.011738.940.001733.96
542022.07.07 05:30sell280.011739.930.001733.36
552022.07.08 10:45t/p270.011733.960.001733.965.181120.46
562022.07.08 15:31t/p280.011733.360.001733.366.771127.23
572022.08.01 01:30buy290.011764.540.001772.46
582022.08.01 12:57t/p290.011772.460.001772.467.921135.15
592022.08.08 22:30sell300.011787.280.001781.64
602022.08.10 15:32close300.011802.290.001781.64-14.611120.54
612022.08.22 14:15buy310.011735.880.001742.72
622022.08.23 11:42t/p310.011742.720.001742.726.411126.95
632022.09.05 04:45buy320.011711.770.001722.39
642022.09.06 03:47t/p320.011722.390.001722.3910.191137.13
652022.10.10 23:00sell330.011668.780.001662.90
662022.10.11 05:13t/p330.011662.900.001662.906.081143.21
672022.11.09 07:30sell340.011708.410.001705.89
682022.11.09 12:07t/p340.011705.890.001705.892.521145.73
692022.11.15 04:45buy350.011771.880.001782.71
702022.11.15 09:47t/p350.011782.710.001782.7110.831156.56
712022.11.15 15:00sell360.011775.140.001768.81
722022.11.15 16:48t/p360.011768.810.001768.816.331162.89
732022.11.21 23:45buy370.011738.510.001742.44
742022.11.22 03:07t/p370.011742.440.001742.443.501166.39
752022.11.30 10:00buy380.011755.500.001762.01
762022.11.30 12:00t/p380.011762.010.001762.016.511172.90
772023.01.09 07:30sell390.011876.700.001873.64
782023.01.09 11:03t/p390.011873.640.001873.643.061175.96
792023.01.20 09:00buy400.011926.930.001936.74
802023.01.20 10:08t/p400.011936.740.001936.749.811185.77
812023.02.02 09:00sell410.011951.910.001945.34
822023.02.02 15:58t/p410.011945.340.001945.346.571192.34
832023.02.03 05:45sell420.011916.370.001914.03
842023.02.03 09:32t/p420.011914.030.001914.032.341194.68
852023.03.21 07:45sell430.011981.970.001978.01
862023.03.21 08:23t/p430.011978.010.001978.013.961198.64
872023.03.31 07:15sell440.011981.510.001979.86
882023.03.31 08:08t/p440.011979.860.001979.861.651200.29
892023.04.04 02:00sell450.011983.600.001978.41
902023.04.04 04:59t/p450.011978.410.001978.415.191205.48
912023.04.05 01:45sell460.012020.810.002019.10
922023.04.05 04:15sell470.012020.920.002015.55
932023.04.05 17:32t/p460.012019.100.002019.101.711207.19
942023.04.05 17:33t/p470.012015.550.002015.555.371212.56
952023.04.14 07:30sell480.012044.780.002040.07
962023.04.14 08:51t/p480.012040.070.002040.074.711217.27
972023.05.02 21:45sell490.012014.740.002008.50
982023.05.03 21:00close490.012029.740.002008.50-14.801202.47
992023.05.08 01:45sell500.012014.730.002005.97
1002023.05.08 18:42close500.012029.740.002005.97-15.011187.46
1012023.07.04 17:45buy510.011928.580.001932.81
1022023.07.05 16:17t/p510.011932.810.001932.813.801191.26
1032023.07.07 04:30sell520.011911.150.001907.91
1042023.07.07 15:30close520.011926.150.001907.91-15.001176.26
+
diff --git a/Docs/Reports/Tests/X/StrategyTester - lots 0.00001 - maxd 0.015.gif b/Docs/Reports/Tests/X/StrategyTester - lots 0.00001 - maxd 0.015.gif new file mode 100644 index 0000000..fc19c9b Binary files /dev/null and b/Docs/Reports/Tests/X/StrategyTester - lots 0.00001 - maxd 0.015.gif differ diff --git a/Docs/Reports/Tests/X/StrategyTester - lots 0.00001 - maxd 0.015.htm b/Docs/Reports/Tests/X/StrategyTester - lots 0.00001 - maxd 0.015.htm new file mode 100644 index 0000000..f91c583 --- /dev/null +++ b/Docs/Reports/Tests/X/StrategyTester - lots 0.00001 - maxd 0.015.htm @@ -0,0 +1,173 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.07.27 23:45 (2020.01.01 - 2023.07.28)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +xShortR2R=2.5; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.015; xLongR2R=2.5; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.015; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +xTPWShortR2R=1.5; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.01; xTPWLongR2R=1.5; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.01; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=700;
Bars in test63077Ticks modelled72224447Modelling qualityn/a
Mismatched charts errors798
Initial deposit1000.00SpreadCurrent (57)
Total net profit151.92Gross profit226.60Gross loss-74.68
Profit factor3.03Expected payoff2.92
Absolute drawdown6.67Maximal drawdown26.96 (2.29%)Relative drawdown2.41% (26.81)
Total trades52Short positions (won %)37 (86.49%)Long positions (won %)15 (100.00%)
Profit trades (% of total)47 (90.38%)Loss trades (% of total)5 (9.62%)
Largestprofit trade9.03loss trade-15.05
Averageprofit trade4.82loss trade-14.94
Maximumconsecutive wins (profit in money)19 (85.81)consecutive losses (loss in money)1 (-15.05)
Maximalconsecutive profit (count of wins)85.81 (19)consecutive loss (count of losses)-15.05 (1)
Averageconsecutive wins9consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.18 02:30sell10.011884.040.001881.04
22020.12.18 03:17t/p10.011881.040.001881.043.001003.00
32021.01.06 02:00buy20.011950.770.001957.27
42021.01.06 11:54t/p20.011957.270.001957.276.501009.50
52021.01.21 02:45sell30.011869.150.001862.63
62021.01.21 15:54t/p30.011862.630.001862.636.521016.02
72021.03.09 22:15sell40.011716.740.001710.17
82021.03.10 08:09t/p40.011710.170.001710.176.771022.79
92021.04.01 03:45sell50.011706.320.001699.80
102021.04.01 16:01close50.011721.320.001699.80-15.001007.79
112021.04.08 14:00buy60.011746.300.001754.75
122021.04.08 16:36t/p60.011754.750.001754.758.451016.24
132021.04.15 21:15sell70.011767.210.001764.56
142021.04.15 22:39t/p70.011764.560.001764.562.651018.89
152021.04.21 04:30buy80.011779.880.001787.21
162021.04.21 09:51t/p80.011787.210.001787.217.331026.22
172021.05.04 23:15sell90.011779.150.001777.65
182021.05.05 03:10t/p90.011777.650.001777.651.701027.92
192021.05.07 13:45sell100.011820.100.001817.98
202021.05.07 15:07t/p100.011817.980.001817.982.121030.04
212021.06.03 23:15sell110.011870.990.001865.94
222021.06.04 03:45sell120.011869.320.001862.92
232021.06.04 04:49t/p110.011865.940.001865.945.251035.29
242021.06.04 04:52t/p120.011862.920.001862.926.401041.69
252021.06.17 08:00sell130.011821.330.001815.18
262021.06.17 09:07t/p130.011815.180.001815.186.151047.84
272021.06.18 08:45sell140.011784.490.001778.54
282021.06.18 15:24t/p140.011778.540.001778.545.951053.79
292021.07.14 12:00buy150.011814.480.001821.08
302021.07.14 15:06t/p150.011821.080.001821.086.601060.39
312021.08.26 13:45buy160.011787.230.001794.01
322021.08.26 17:31t/p160.011794.010.001794.016.781067.17
332021.10.21 09:45buy170.011786.730.001795.83
342021.10.22 15:19t/p170.011795.830.001795.838.671075.84
352021.11.23 05:30sell180.011808.910.001803.19
362021.11.23 10:49t/p180.011803.190.001803.195.721081.56
372021.12.15 04:45sell190.011771.980.001769.33
382021.12.15 07:24t/p190.011769.330.001769.332.651084.21
392022.02.09 11:30buy200.011827.850.001831.03
402022.02.09 15:07t/p200.011831.030.001831.033.181087.39
412022.02.14 13:30sell210.011855.860.001851.26
422022.02.14 17:39close210.011870.860.001851.26-15.001072.39
432022.03.14 08:45sell220.011975.330.001973.43
442022.03.14 09:24t/p220.011973.430.001973.431.901074.29
452022.03.16 05:15sell230.011919.680.001911.16
462022.03.16 16:09t/p230.011911.160.001911.168.521082.81
472022.05.17 05:00sell240.011826.120.001823.95
482022.05.17 06:08t/p240.011823.950.001823.952.171084.98
492022.06.24 05:00sell250.011823.760.001820.54
502022.06.24 16:00t/p250.011820.540.001820.543.221088.20
512022.07.06 01:05sell260.011766.830.001763.96
522022.07.06 08:38t/p260.011763.960.001763.962.871091.07
532022.07.07 01:45sell270.011738.940.001734.79
542022.07.07 05:30sell280.011739.930.001734.46
552022.07.08 10:43t/p270.011734.790.001734.794.351095.42
562022.07.08 10:43t/p280.011734.460.001734.465.671101.09
572022.08.01 01:30buy290.011764.520.001771.12
582022.08.01 12:53t/p290.011771.120.001771.126.601107.69
592022.08.08 22:30sell300.011787.280.001782.58
602022.08.10 15:32close300.011802.300.001782.58-14.621093.07
612022.08.22 14:15buy310.011735.860.001741.56
622022.08.23 11:20t/p310.011741.560.001741.565.271098.34
632022.09.05 04:45buy320.011711.750.001720.60
642022.09.06 03:32t/p320.011720.600.001720.608.421106.75
652022.10.10 23:00sell330.011668.780.001663.88
662022.10.11 05:13t/p330.011663.880.001663.885.101111.85
672022.11.09 07:30sell340.011708.410.001706.31
682022.11.09 12:07t/p340.011706.310.001706.312.101113.95
692022.11.15 04:45buy350.011771.860.001780.89
702022.11.15 09:46t/p350.011780.890.001780.899.031122.98
712022.11.15 15:00sell360.011775.140.001769.87
722022.11.15 16:48t/p360.011769.870.001769.875.271128.25
732022.11.21 23:45buy370.011738.490.001741.77
742022.11.22 03:03t/p370.011741.770.001741.772.851131.10
752022.11.30 10:00buy380.011755.480.001760.91
762022.11.30 11:08t/p380.011760.910.001760.915.431136.53
772023.01.09 07:30sell390.011876.700.001874.15
782023.01.09 09:51t/p390.011874.150.001874.152.551139.08
792023.01.20 09:00buy400.011926.910.001935.09
802023.01.20 10:07t/p400.011935.090.001935.098.181147.26
812023.02.02 09:00sell410.011951.910.001946.44
822023.02.02 15:52t/p410.011946.440.001946.445.471152.73
832023.02.03 05:45sell420.011916.370.001914.42
842023.02.03 06:23t/p420.011914.420.001914.421.951154.68
852023.03.21 07:45sell430.011981.970.001978.67
862023.03.21 08:22t/p430.011978.670.001978.673.301157.98
872023.03.31 07:15sell440.011981.510.001980.14
882023.03.31 08:08t/p440.011980.140.001980.141.371159.35
892023.04.04 02:00sell450.011983.600.001979.28
902023.04.04 04:54t/p450.011979.280.001979.284.321163.67
912023.04.05 01:45sell460.012020.810.002019.39
922023.04.05 04:15sell470.012020.920.002016.45
932023.04.05 17:11t/p460.012019.390.002019.391.421165.09
942023.04.05 17:32t/p470.012016.450.002016.454.471169.56
952023.04.14 07:30sell480.012044.780.002040.86
962023.04.14 08:38t/p480.012040.860.002040.863.921173.48
972023.05.02 21:45sell490.012014.740.002009.54
982023.05.03 15:15t/p490.012009.540.002009.545.401178.88
992023.05.08 01:45sell500.012014.730.002007.43
1002023.05.08 19:15close500.012029.740.002007.43-15.011163.87
1012023.07.04 17:45buy510.011928.560.001932.09
1022023.07.05 16:17t/p510.011932.090.001932.093.101166.97
1032023.07.07 04:30sell520.011911.150.001908.45
1042023.07.07 15:30close520.011926.200.001908.45-15.051151.92
+
diff --git a/Docs/Reports/Tests/X/StrategyTester 1.gif b/Docs/Reports/Tests/X/StrategyTester 1.gif new file mode 100644 index 0000000..9f4c0da Binary files /dev/null and b/Docs/Reports/Tests/X/StrategyTester 1.gif differ diff --git a/Docs/Reports/Tests/X/StrategyTester 1.htm b/Docs/Reports/Tests/X/StrategyTester 1.htm new file mode 100644 index 0000000..9f8cc67 --- /dev/null +++ b/Docs/Reports/Tests/X/StrategyTester 1.htm @@ -0,0 +1,98 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.07.27 23:45 (2020.01.01 - 2023.07.28)
ModelEvery tick (the most precise method based on all available least timeframes)
Bars in test63077Ticks modelled72224447Modelling qualityn/a
Mismatched charts errors798
Initial deposit1000.00SpreadCurrent (60)
Total net profit201.25Gross profit201.25Gross loss-0.00
Profit factorExpected payoff9.58
Absolute drawdown21.07Maximal drawdown26.62 (2.65%)Relative drawdown2.65% (26.62)
Total trades21Short positions (won %)0 (0.00%)Long positions (won %)21 (100.00%)
Profit trades (% of total)21 (100.00%)Loss trades (% of total)0 (0.00%)
Largestprofit trade16.82loss trade-0.00
Averageprofit trade9.58loss trade-0.00
Maximumconsecutive wins (profit in money)21 (201.25)consecutive losses (loss in money)0 (-0.00)
Maximalconsecutive profit (count of wins)201.25 (21)consecutive loss (count of losses)-0.00 (0)
Averageconsecutive wins21consecutive losses0
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 09:30buy10.011842.470.001854.89
22020.12.07 16:54t/p10.011854.890.001854.8911.991011.99
32021.01.06 02:00buy20.011950.800.001958.60
42021.01.06 12:00t/p20.011958.600.001958.607.801019.79
52021.02.19 05:15buy30.011769.940.001786.47
62021.02.19 16:09t/p30.011786.470.001786.4716.531036.32
72021.04.08 14:00buy40.011746.330.001756.47
82021.04.08 16:39t/p40.011756.470.001756.4710.141046.46
92021.04.21 04:30buy50.011779.910.001788.70
102021.04.21 16:39t/p50.011788.700.001788.708.791055.25
112021.07.01 05:00buy60.011771.790.001789.04
122021.07.02 15:39t/p60.011789.040.001789.0416.821072.07
132021.07.14 12:00buy70.011814.510.001822.43
142021.07.14 15:07t/p70.011822.430.001822.437.921079.99
152021.08.26 13:45buy80.011787.260.001795.39
162021.08.26 18:04t/p80.011795.390.001795.398.131088.12
172021.10.21 09:45buy90.011786.760.001797.68
182021.10.22 15:22t/p90.011797.680.001797.6810.491098.60
192022.02.09 11:30buy100.011827.880.001831.69
202022.02.09 15:09t/p100.011831.690.001831.693.811102.41
212022.08.01 01:30buy110.011764.550.001772.47
222022.08.01 12:57t/p110.011772.470.001772.477.921110.33
232022.08.22 14:15buy120.011735.890.001742.73
242022.08.23 11:42t/p120.011742.730.001742.736.411116.74
252022.09.05 04:45buy130.011711.780.001722.40
262022.09.06 03:47t/p130.011722.400.001722.4010.191126.93
272022.11.15 04:45buy140.011771.890.001782.72
282022.11.15 09:47t/p140.011782.720.001782.7210.831137.76
292022.11.21 20:30buy150.011738.410.001753.59
302022.11.21 23:45buy160.011738.520.001742.45
312022.11.22 03:07t/p160.011742.450.001742.453.501141.26
322022.11.24 02:26t/p150.011753.590.001753.5913.021154.28
332022.11.30 10:00buy170.011755.510.001762.02
342022.11.30 12:00t/p170.011762.020.001762.026.511160.79
352023.01.20 09:00buy180.011926.940.001936.75
362023.01.20 10:08t/p180.011936.750.001936.759.811170.60
372023.03.01 04:30buy190.011829.100.001845.33
382023.03.03 10:42t/p190.011845.330.001845.3314.501185.10
392023.04.25 09:30buy200.011995.440.002008.22
402023.04.26 16:28t/p200.012008.220.002008.2212.351197.45
412023.07.04 17:45buy210.011928.590.001932.82
422023.07.05 16:17t/p210.011932.820.001932.823.801201.25
+
diff --git a/Docs/Reports/Tests/X/StrategyTester 2.gif b/Docs/Reports/Tests/X/StrategyTester 2.gif new file mode 100644 index 0000000..93e3b74 Binary files /dev/null and b/Docs/Reports/Tests/X/StrategyTester 2.gif differ diff --git a/Docs/Reports/Tests/X/StrategyTester 2.htm b/Docs/Reports/Tests/X/StrategyTester 2.htm new file mode 100644 index 0000000..62ee295 --- /dev/null +++ b/Docs/Reports/Tests/X/StrategyTester 2.htm @@ -0,0 +1,84 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.06.28 23:45 (2020.01.01 - 2023.06.29)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=2; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.0003; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.4; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +xR2R=2.5; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xrR2R=2; xRMaximumCandlesPerTrade=252; xrOscillatorLength=7; xrFastLength=20; xrSlowLength=50; xrRangeMarketLength=50; xrSwingLength=7;
Bars in test61155Ticks modelled69617088Modelling quality40.15%
Mismatched charts errors30
Initial deposit1000.00SpreadCurrent (59)
Total net profit1812.58Gross profit1812.58Gross loss-0.00
Profit factorExpected payoff226.57
Absolute drawdown290.70Maximal drawdown420.90 (37.24%)Relative drawdown37.24% (420.90)
Total trades8Short positions (won %)0 (0.00%)Long positions (won %)8 (100.00%)
Profit trades (% of total)8 (100.00%)Loss trades (% of total)0 (0.00%)
Largestprofit trade270.90loss trade-0.00
Averageprofit trade226.57loss trade-0.00
Maximumconsecutive wins (profit in money)8 (1812.58)consecutive losses (loss in money)0 (-0.00)
Maximalconsecutive profit (count of wins)1812.58 (8)consecutive loss (count of losses)-0.00 (0)
Averageconsecutive wins8consecutive losses0
+Graph
+ + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12021.01.06 02:00buy10.301950.790.001957.29
22021.01.06 11:54t/p10.301957.290.001957.29195.001195.00
32021.04.08 14:00buy20.301746.320.001754.77
42021.04.08 16:36t/p20.301754.770.001754.77253.501448.50
52021.04.21 04:30buy30.301779.900.001787.23
62021.04.21 09:52t/p30.301787.230.001787.23219.901668.40
72021.07.14 12:00buy40.301814.500.001821.10
82021.07.14 15:06t/p40.301821.100.001821.10198.001866.40
92021.10.21 09:45buy50.301786.750.001795.85
102021.10.22 15:19t/p50.301795.850.001795.85259.942126.34
112022.09.05 04:45buy60.301711.770.001720.62
122022.09.06 03:32t/p60.301720.620.001720.62252.442378.78
132022.11.15 04:45buy70.301771.880.001780.91
142022.11.15 09:46t/p70.301780.910.001780.91270.902649.68
152022.11.30 10:00buy80.301755.500.001760.93
162022.11.30 11:08t/p80.301760.930.001760.93162.902812.58
+
diff --git a/Docs/Reports/Tests/X/StrategyTester 3 - Short.gif b/Docs/Reports/Tests/X/StrategyTester 3 - Short.gif new file mode 100644 index 0000000..e7e420b Binary files /dev/null and b/Docs/Reports/Tests/X/StrategyTester 3 - Short.gif differ diff --git a/Docs/Reports/Tests/X/StrategyTester 3 - Short.htm b/Docs/Reports/Tests/X/StrategyTester 3 - Short.htm new file mode 100644 index 0000000..3d0b7dc --- /dev/null +++ b/Docs/Reports/Tests/X/StrategyTester 3 - Short.htm @@ -0,0 +1,130 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.06.28 23:45 (2020.01.01 - 2023.06.29)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=2; allowTrade=true; +allowLongTrades=false; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +xR2R=2.5; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xrR2R=2; xRMaximumCandlesPerTrade=252; xrOscillatorLength=7; xrFastLength=20; xrSlowLength=50; xrRangeMarketLength=50; xrSwingLength=7;
Bars in test61155Ticks modelled69617088Modelling quality40.15%
Mismatched charts errors30
Initial deposit1000.00SpreadCurrent (50)
Total net profit74.65Gross profit120.83Gross loss-46.18
Profit factor2.62Expected payoff2.41
Absolute drawdown14.66Maximal drawdown31.19 (3.07%)Relative drawdown3.07% (31.19)
Total trades31Short positions (won %)31 (90.32%)Long positions (won %)0 (0.00%)
Profit trades (% of total)28 (90.32%)Loss trades (% of total)3 (9.68%)
Largestprofit trade8.52loss trade-29.37
Averageprofit trade4.32loss trade-15.39
Maximumconsecutive wins (profit in money)14 (65.09)consecutive losses (loss in money)1 (-29.37)
Maximalconsecutive profit (count of wins)65.09 (14)consecutive loss (count of losses)-29.37 (1)
Averageconsecutive wins9consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.18 02:30sell10.011884.040.001881.04
22020.12.18 03:09t/p10.011881.040.001881.043.001003.00
32021.01.21 02:45sell20.011869.150.001862.63
42021.01.21 15:54t/p20.011862.630.001862.636.521009.52
52021.03.09 22:15sell30.011716.740.001710.17
62021.03.10 08:09t/p30.011710.170.001710.176.781016.30
72021.04.01 03:45sell40.011706.320.001699.80
82021.04.06 07:54close40.011736.320.001699.80-29.37986.93
92021.04.15 21:15sell50.011767.210.001764.56
102021.04.15 22:39t/p50.011764.560.001764.562.65989.58
112021.06.03 23:15sell60.011870.990.001865.94
122021.06.04 03:45sell70.011869.320.001862.92
132021.06.04 04:49t/p60.011865.940.001865.945.26994.84
142021.06.04 04:52t/p70.011862.920.001862.926.401001.24
152021.06.17 08:00sell80.011821.330.001815.18
162021.06.17 09:07t/p80.011815.180.001815.186.151007.39
172021.06.18 08:45sell90.011784.490.001778.54
182021.06.18 15:24t/p90.011778.540.001778.545.951013.34
192021.11.23 05:30sell100.011808.910.001803.19
202021.11.23 09:03t/p100.011803.190.001803.195.721019.06
212021.12.15 04:45sell110.011771.980.001769.33
222021.12.15 07:24t/p110.011769.330.001769.332.651021.71
232022.02.14 13:30sell120.011855.860.001851.26
242022.02.15 13:54t/p120.011851.260.001851.264.811026.52
252022.03.14 08:45sell130.011975.330.001973.43
262022.03.14 09:24t/p130.011973.430.001973.431.901028.42
272022.03.16 05:15sell140.011919.680.001911.16
282022.03.16 16:09t/p140.011911.160.001911.168.521036.94
292022.05.17 05:00sell150.011826.120.001823.95
302022.05.17 06:08t/p150.011823.950.001823.952.171039.11
312022.07.06 01:05sell160.011766.830.001763.96
322022.07.06 08:38t/p160.011763.960.001763.962.871041.98
332022.07.07 01:45sell170.011738.940.001734.79
342022.07.07 05:30sell180.011739.930.001734.46
352022.07.08 10:43t/p170.011734.790.001734.794.361046.34
362022.07.08 10:43t/p180.011734.460.001734.465.681052.02
372022.08.08 22:30sell190.011787.280.001782.58
382022.08.11 05:00close190.011788.480.001782.58-0.151051.87
392022.10.10 23:00sell200.011668.780.001663.88
402022.10.11 05:13t/p200.011663.880.001663.885.111056.98
412022.11.09 07:30sell210.011708.410.001706.31
422022.11.09 12:07t/p210.011706.310.001706.312.101059.08
432022.11.15 15:00sell220.011775.140.001769.87
442022.11.15 16:48t/p220.011769.870.001769.875.271064.35
452023.01.09 07:30sell230.011876.700.001874.15
462023.01.09 09:50t/p230.011874.150.001874.152.551066.90
472023.02.02 09:00sell240.011951.910.001946.44
482023.02.02 15:52t/p240.011946.440.001946.445.471072.37
492023.02.03 05:45sell250.011916.370.001914.42
502023.02.03 06:23t/p250.011914.420.001914.421.951074.32
512023.03.31 07:15sell260.011981.510.001980.14
522023.03.31 08:07t/p260.011980.140.001980.141.371075.69
532023.04.04 02:00sell270.011983.600.001979.28
542023.04.04 04:50t/p270.011979.280.001979.284.321080.01
552023.04.05 01:45sell280.012020.810.002019.39
562023.04.05 04:15sell290.012020.920.002016.45
572023.04.05 17:11t/p280.012019.390.002019.391.421081.43
582023.04.05 17:32t/p290.012016.450.002016.454.471085.90
592023.05.02 21:45sell300.012014.740.002009.54
602023.05.03 15:15t/p300.012009.540.002009.545.411091.31
612023.05.08 01:45sell310.012014.730.002007.43
622023.05.10 07:15close310.012031.810.002007.43-16.661074.65
+
diff --git a/Docs/Reports/Tests/X/StrategyTester 4 - Short Long 0.3 0.4.gif b/Docs/Reports/Tests/X/StrategyTester 4 - Short Long 0.3 0.4.gif new file mode 100644 index 0000000..0cd8541 Binary files /dev/null and b/Docs/Reports/Tests/X/StrategyTester 4 - Short Long 0.3 0.4.gif differ diff --git a/Docs/Reports/Tests/X/StrategyTester 4 - Short Long 0.3 0.4.htm b/Docs/Reports/Tests/X/StrategyTester 4 - Short Long 0.3 0.4.htm new file mode 100644 index 0000000..cc169a5 --- /dev/null +++ b/Docs/Reports/Tests/X/StrategyTester 4 - Short Long 0.3 0.4.htm @@ -0,0 +1,162 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.06.28 23:45 (2020.01.01 - 2023.06.29)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=2; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.0003; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.4; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +xR2R=2.5; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xrR2R=2; xRMaximumCandlesPerTrade=252; xrOscillatorLength=7; xrFastLength=20; xrSlowLength=50; xrRangeMarketLength=50; xrSwingLength=7;
Bars in test61155Ticks modelled69617088Modelling quality40.15%
Mismatched charts errors30
Initial deposit1000.00SpreadCurrent (56)
Total net profit4615.79Gross profit6210.29Gross loss-1594.49
Profit factor3.89Expected payoff98.21
Absolute drawdown199.80Maximal drawdown759.90 (18.60%)Relative drawdown34.47% (420.90)
Total trades47Short positions (won %)33 (87.88%)Long positions (won %)14 (100.00%)
Profit trades (% of total)43 (91.49%)Loss trades (% of total)4 (8.51%)
Largestprofit trade270.90loss trade-400.20
Averageprofit trade144.43loss trade-398.62
Maximumconsecutive wins (profit in money)18 (2440.63)consecutive losses (loss in money)1 (-400.20)
Maximalconsecutive profit (count of wins)2440.63 (18)consecutive loss (count of losses)-400.20 (1)
Averageconsecutive wins11consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.18 02:30sell10.301884.040.001881.04
22020.12.18 03:10t/p10.301881.040.001881.0490.001090.00
32021.01.06 02:00buy20.301950.760.001957.26
42021.01.06 11:54t/p20.301957.260.001957.26195.001285.00
52021.01.21 02:45sell30.301869.150.001862.63
62021.01.21 15:54t/p30.301862.630.001862.63195.601480.60
72021.03.09 22:15sell40.301716.740.001710.17
82021.03.10 08:09t/p40.301710.170.001710.17203.411684.01
92021.04.01 03:45sell50.301706.320.001699.80
102021.04.01 10:24close50.301719.660.001699.80-400.201283.81
112021.04.08 14:00buy60.301746.290.001754.74
122021.04.08 16:36t/p60.301754.740.001754.74253.501537.31
132021.04.15 21:15sell70.301767.210.001764.56
142021.04.15 22:39t/p70.301764.560.001764.5679.501616.81
152021.04.21 04:30buy80.301779.870.001787.20
162021.04.21 09:51t/p80.301787.200.001787.20219.901836.71
172021.05.04 23:15sell90.301779.150.001777.65
182021.05.05 03:09t/p90.301777.650.001777.6551.311888.01
192021.05.07 13:45sell100.301820.100.001817.98
202021.05.07 15:07t/p100.301817.980.001817.9863.601951.61
212021.06.03 23:15sell110.301870.990.001865.94
222021.06.04 04:49t/p110.301865.940.001865.94157.812109.42
232021.06.17 08:00sell120.301821.330.001815.18
242021.06.17 09:07t/p120.301815.180.001815.18184.502293.92
252021.06.18 08:45sell130.301784.490.001778.54
262021.06.18 15:24t/p130.301778.540.001778.54178.502472.42
272021.07.14 12:00buy140.301814.470.001821.07
282021.07.14 15:05t/p140.301821.070.001821.07198.002670.42
292021.08.26 13:45buy150.301787.220.001794.00
302021.08.26 17:31t/p150.301794.000.001794.00203.402873.82
312021.10.21 09:45buy160.301786.720.001795.82
322021.10.22 15:19t/p160.301795.820.001795.82259.943133.76
332021.11.23 05:30sell170.301808.910.001803.19
342021.11.23 10:49t/p170.301803.190.001803.19171.603305.36
352021.12.15 04:45sell180.301771.980.001769.33
362021.12.15 07:24t/p180.301769.330.001769.3379.503384.86
372022.02.09 11:30buy190.301827.840.001831.02
382022.02.09 15:07t/p190.301831.020.001831.0295.403480.26
392022.02.14 13:30sell200.301855.860.001851.26
402022.02.14 17:18close200.301869.200.001851.26-400.203080.06
412022.03.14 08:45sell210.301975.330.001973.43
422022.03.14 09:24t/p210.301973.430.001973.4357.003137.06
432022.03.16 05:15sell220.301919.680.001911.16
442022.03.16 16:09t/p220.301911.160.001911.16255.603392.66
452022.05.17 05:00sell230.301826.120.001823.95
462022.05.17 06:08t/p230.301823.950.001823.9565.103457.76
472022.06.24 05:00sell240.301823.760.001820.54
482022.06.24 16:00t/p240.301820.540.001820.5496.603554.36
492022.07.06 01:05sell250.301766.830.001763.96
502022.07.06 08:38t/p250.301763.960.001763.9686.103640.46
512022.07.07 01:45sell260.301738.940.001734.79
522022.07.08 10:43t/p260.301734.790.001734.79130.813771.26
532022.08.01 01:30buy270.301764.510.001771.11
542022.08.01 12:53t/p270.301771.110.001771.11198.003969.26
552022.08.08 22:30sell280.301787.280.001782.58
562022.08.09 16:33close280.301800.620.001782.58-393.893575.37
572022.08.22 14:15buy290.301735.850.001741.55
582022.08.23 11:20t/p290.301741.550.001741.55157.943733.31
592022.09.05 04:45buy300.301711.740.001720.59
602022.09.06 03:32t/p300.301720.590.001720.59252.443985.74
612022.10.10 23:00sell310.301668.780.001663.88
622022.10.11 05:13t/p310.301663.880.001663.88153.314139.05
632022.11.09 07:30sell320.301708.410.001706.31
642022.11.09 12:07t/p320.301706.310.001706.3163.004202.05
652022.11.15 04:45buy330.301771.850.001780.88
662022.11.15 09:46t/p330.301780.880.001780.88270.904472.95
672022.11.15 15:00sell340.301775.140.001769.87
682022.11.15 16:48t/p340.301769.870.001769.87158.104631.05
692022.11.21 23:45buy350.301738.480.001741.76
702022.11.22 03:03t/p350.301741.760.001741.7685.344716.39
712022.11.30 10:00buy360.301755.470.001760.90
722022.11.30 11:08t/p360.301760.900.001760.90162.904879.29
732023.01.09 07:30sell370.301876.700.001874.15
742023.01.09 09:51t/p370.301874.150.001874.1576.504955.79
752023.01.20 09:00buy380.301926.900.001935.08
762023.01.20 10:07t/p380.301935.080.001935.08245.405201.19
772023.02.02 09:00sell390.301951.910.001946.44
782023.02.02 15:52t/p390.301946.440.001946.44164.105365.29
792023.02.03 05:45sell400.301916.370.001914.42
802023.02.03 06:23t/p400.301914.420.001914.4258.505423.79
812023.03.21 07:45sell410.301981.970.001978.67
822023.03.21 08:22t/p410.301978.670.001978.6799.005522.79
832023.03.31 07:15sell420.301981.510.001980.14
842023.03.31 08:08t/p420.301980.140.001980.1441.105563.89
852023.04.04 02:00sell430.301983.600.001979.28
862023.04.04 04:54t/p430.301979.280.001979.28129.605693.49
872023.04.05 01:45sell440.302020.810.002019.39
882023.04.05 17:11t/p440.302019.390.002019.3942.605736.09
892023.04.14 07:30sell450.302044.780.002040.86
902023.04.14 08:38t/p450.302040.860.002040.86117.605853.69
912023.05.02 21:45sell460.302014.740.002009.54
922023.05.03 15:15t/p460.302009.540.002009.54162.316015.99
932023.05.08 01:45sell470.302014.730.002007.43
942023.05.08 18:29close470.302028.070.002007.43-400.205615.79
+
diff --git a/Docs/Reports/Tests/X/StrategyTester Short 1.gif b/Docs/Reports/Tests/X/StrategyTester Short 1.gif new file mode 100644 index 0000000..5b29ecb Binary files /dev/null and b/Docs/Reports/Tests/X/StrategyTester Short 1.gif differ diff --git a/Docs/Reports/Tests/X/StrategyTester Short 1.htm b/Docs/Reports/Tests/X/StrategyTester Short 1.htm new file mode 100644 index 0000000..a12b30b --- /dev/null +++ b/Docs/Reports/Tests/X/StrategyTester Short 1.htm @@ -0,0 +1,95 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.01 23:45 (2020.01.01 - 2023.08.02)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=false; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63353Ticks modelled72601176Modelling qualityn/a
Mismatched charts errors808
Initial deposit1000.00SpreadCurrent (60)
Total net profit-16.50Gross profit42.85Gross loss-59.35
Profit factor0.72Expected payoff-1.27
Absolute drawdown20.26Maximal drawdown40.23 (3.94%)Relative drawdown3.94% (40.23)
Total trades13Short positions (won %)13 (76.92%)Long positions (won %)0 (0.00%)
Profit trades (% of total)10 (76.92%)Loss trades (% of total)3 (23.08%)
Largestprofit trade8.82loss trade-20.00
Averageprofit trade4.28loss trade-19.78
Maximumconsecutive wins (profit in money)4 (15.94)consecutive losses (loss in money)1 (-20.00)
Maximalconsecutive profit (count of wins)15.94 (4)consecutive loss (count of losses)-20.00 (1)
Averageconsecutive wins3consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.18 02:30sell10.011884.040.001880.44
22020.12.18 03:21t/p10.011880.440.001880.443.601003.60
32021.05.04 23:15sell20.011779.150.001777.35
42021.05.05 03:24t/p20.011777.350.001777.352.021005.62
52021.06.18 08:45sell30.011784.490.001777.35
62021.06.18 15:52t/p30.011777.350.001777.357.141012.76
72021.12.15 04:45sell40.011771.980.001768.80
82021.12.15 07:39t/p40.011768.800.001768.803.181015.94
92022.02.14 13:30sell50.011855.860.001850.34
102022.02.15 04:39close50.011875.860.001850.34-19.78996.16
112022.03.14 08:45sell60.011975.330.001973.05
122022.03.14 10:01t/p60.011973.050.001973.052.28998.44
132022.05.17 11:30sell70.011827.110.001818.29
142022.05.17 21:12t/p70.011818.290.001818.298.821007.26
152022.06.24 05:00sell80.011823.760.001819.89
162022.06.24 16:00t/p80.011819.890.001819.893.871011.13
172022.08.08 22:30sell90.011787.280.001781.64
182022.08.10 15:33close90.011807.290.001781.64-19.57991.56
192022.11.15 15:00sell100.011775.140.001768.81
202022.11.15 16:48t/p100.011768.810.001768.816.33997.89
212023.03.21 07:45sell110.011981.970.001978.01
222023.03.21 08:23t/p110.011978.010.001978.013.961001.85
232023.03.31 07:15sell120.011981.510.001979.86
242023.03.31 08:08t/p120.011979.860.001979.861.651003.50
252023.07.07 04:30sell130.011911.150.001907.91
262023.07.07 17:37close130.011931.150.001907.91-20.00983.50
+
diff --git a/Docs/Reports/Tests/XR/StrategyTester 1.gif b/Docs/Reports/Tests/XR/StrategyTester 1.gif new file mode 100644 index 0000000..bf203ae Binary files /dev/null and b/Docs/Reports/Tests/XR/StrategyTester 1.gif differ diff --git a/Docs/Reports/Tests/XR/StrategyTester 1.htm b/Docs/Reports/Tests/XR/StrategyTester 1.htm new file mode 100644 index 0000000..c94c15d --- /dev/null +++ b/Docs/Reports/Tests/XR/StrategyTester 1.htm @@ -0,0 +1,183 @@ + + + + Strategy Tester: x-saherelm.xr.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.xr.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.07.21 23:45 (2020.01.01 - 2023.07.22)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=50; swingLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.03; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=252; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +
Bars in test62709Ticks modelled71719330Modelling qualityn/a
Mismatched charts errors777
Initial deposit1000.00SpreadCurrent (60)
Total net profit64.36Gross profit198.76Gross loss-134.40
Profit factor1.48Expected payoff1.11
Absolute drawdown9.15Maximal drawdown38.61 (3.57%)Relative drawdown3.57% (38.61)
Total trades58Short positions (won %)0 (0.00%)Long positions (won %)58 (58.62%)
Profit trades (% of total)34 (58.62%)Loss trades (% of total)24 (41.38%)
Largestprofit trade14.58loss trade-15.38
Averageprofit trade5.85loss trade-5.60
Maximumconsecutive wins (profit in money)4 (23.01)consecutive losses (loss in money)3 (-26.09)
Maximalconsecutive profit (count of wins)23.01 (4)consecutive loss (count of losses)-26.09 (3)
Averageconsecutive wins2consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.03 23:30buy10.011841.440.001845.90
22020.12.04 15:31t/p10.011845.900.001845.904.021004.02
32020.12.08 18:30buy20.011870.350.001886.13
42020.12.09 05:19close20.011864.070.001886.13-6.72997.31
52020.12.30 03:45buy30.011883.290.001893.75
62020.12.30 10:00close30.011878.490.001893.75-4.80992.51
72020.12.30 18:00buy40.011885.860.001895.62
82020.12.31 02:15t/p40.011895.620.001895.628.451000.96
92021.01.05 11:30buy50.011944.710.001954.49
102021.01.06 03:09t/p50.011954.490.001954.499.341010.31
112021.04.05 17:30buy60.011729.420.001742.62
122021.04.05 22:00close60.011725.680.001742.62-3.741006.57
132021.04.19 06:15buy70.011778.720.001785.24
142021.04.19 07:15close70.011776.750.001785.24-1.971004.60
152021.04.26 21:00buy80.011780.010.001781.77
162021.04.26 23:39t/p80.011781.770.001781.771.761006.36
172021.05.18 23:45buy90.011870.210.001872.99
182021.05.19 05:00close90.011867.630.001872.99-3.021003.34
192021.05.20 08:15buy100.011876.090.001877.07
202021.05.20 08:30t/p100.011877.070.001877.070.981004.32
212021.05.21 11:30buy110.011876.530.001882.65
222021.05.21 15:21t/p110.011882.650.001882.656.121010.44
232021.05.24 19:15buy120.011884.010.001887.27
242021.05.25 01:15close120.011880.910.001887.27-3.541006.91
252021.05.25 10:45buy130.011884.160.001898.74
262021.05.25 21:06t/p130.011898.740.001898.7414.581021.49
272021.06.28 20:30buy140.011780.510.001785.35
282021.06.28 21:15close140.011778.020.001785.35-2.491019.00
292021.07.06 04:15buy150.011792.940.001796.10
302021.07.06 04:53t/p150.011796.100.001796.103.161022.16
312021.07.09 17:45buy160.011806.390.001814.91
322021.07.12 07:16close160.011801.870.001814.91-4.961017.20
332021.07.12 19:30buy170.011805.330.001808.45
342021.07.13 04:34t/p170.011808.450.001808.452.681019.89
352021.08.12 23:00buy180.011753.790.001757.21
362021.08.13 09:09t/p180.011757.210.001757.212.981022.87
372021.09.01 22:30buy190.011815.330.001820.69
382021.09.02 02:45close190.011813.220.001820.69-3.421019.45
392021.09.03 05:15buy200.011813.490.001819.35
402021.09.03 15:34t/p200.011819.350.001819.355.861025.31
412021.09.29 06:00buy210.011740.530.001751.43
422021.09.29 16:24close210.011736.210.001751.43-4.321020.99
432021.11.16 04:45buy220.011867.860.001877.40
442021.11.16 09:45close220.011863.300.001877.40-4.561016.43
452021.12.07 04:30buy230.011781.010.001785.23
462021.12.07 05:45close230.011778.500.001785.23-2.511013.92
472021.12.07 20:30buy240.011784.430.001788.51
482021.12.08 04:07t/p240.011788.510.001788.513.641017.57
492021.12.28 08:15buy250.011813.150.001819.37
502021.12.28 15:37t/p250.011819.370.001819.376.221023.79
512022.01.10 21:30buy260.011801.220.001805.98
522022.01.11 04:24t/p260.011805.980.001805.984.321028.11
532022.01.19 11:15buy270.011816.130.001824.95
542022.01.19 15:54t/p270.011824.950.001824.958.821036.93
552022.01.24 23:15buy280.011843.380.001853.74
562022.01.25 11:04close280.011838.270.001853.74-5.551031.39
572022.01.31 11:30buy290.011791.280.001798.92
582022.01.31 16:39t/p290.011798.920.001798.927.641039.03
592022.02.16 09:30buy300.011856.110.001860.85
602022.02.16 15:00close300.011852.740.001860.85-3.371035.66
612022.03.03 22:15buy310.011937.410.001946.73
622022.03.04 02:36t/p310.011946.730.001946.738.881044.54
632022.03.04 13:00buy320.011947.630.001961.75
642022.03.04 18:09t/p320.011961.750.001961.7514.121058.66
652022.03.11 21:30buy330.011986.950.001999.25
662022.03.14 00:45close330.011972.860.001999.25-14.531044.14
672022.03.24 13:30buy340.011946.500.001957.42
682022.03.24 14:03t/p340.011957.420.001957.4210.921055.06
692022.04.05 16:15buy350.011935.270.001956.63
702022.04.05 18:45close350.011925.680.001956.63-9.591045.47
712022.04.13 08:30buy360.011969.860.001973.40
722022.04.13 11:19t/p360.011973.400.001973.403.541049.01
732022.05.20 09:45buy370.011848.340.001859.62
742022.05.20 16:30close370.011840.610.001859.62-7.731041.28
752022.05.23 01:15buy380.011845.310.001848.55
762022.05.23 02:07t/p380.011848.550.001848.553.241044.52
772022.06.08 15:15buy390.011851.320.001858.82
782022.06.08 18:07t/p390.011858.820.001858.827.501052.02
792022.07.05 02:15buy400.011810.010.001814.79
802022.07.05 10:30close400.011806.730.001814.79-3.281048.74
812022.10.26 07:45buy410.011656.860.001658.96
822022.10.26 08:41t/p410.011658.960.001658.962.101050.84
832022.10.27 08:45buy420.011669.970.001683.09
842022.10.27 09:45close420.011661.850.001683.09-8.121042.72
852022.11.02 04:00buy430.011650.460.001653.36
862022.11.02 10:00t/p430.011653.360.001653.362.901045.62
872022.11.14 17:45buy440.011770.180.001784.24
882022.11.15 08:45close440.011769.440.001784.24-1.181044.44
892022.11.30 05:45buy450.011754.150.001759.19
902022.11.30 10:57t/p450.011759.190.001759.195.041049.48
912023.01.11 06:30buy460.011877.620.001882.84
922023.01.11 07:37t/p460.011882.840.001882.845.221054.70
932023.02.09 05:00buy470.011879.530.001889.99
942023.02.09 16:01t/p470.011889.990.001889.9910.461065.16
952023.02.16 21:30buy480.011843.520.001847.54
962023.02.17 01:15close480.011835.010.001847.54-8.951056.22
972023.02.22 05:15buy490.011837.180.001840.68
982023.02.22 10:03t/p490.011840.680.001840.683.501059.72
992023.03.28 17:00buy500.011963.690.001968.77
1002023.03.28 17:57t/p500.011968.770.001968.775.081064.80
1012023.03.30 10:45buy510.011969.560.001976.42
1022023.03.30 19:01t/p510.011976.420.001976.426.861071.66
1032023.04.26 13:30buy520.012000.140.002005.44
1042023.04.26 16:24t/p520.012005.440.002005.445.301076.96
1052023.04.27 06:00buy530.011999.160.002014.50
1062023.04.27 15:45close530.011983.780.002014.50-15.381061.58
1072023.05.15 19:45buy540.012020.300.002031.78
1082023.05.15 22:00close540.012014.590.002031.78-5.711055.87
1092023.06.09 17:30buy550.011967.630.001988.83
1102023.06.09 18:30close550.011962.630.001988.83-5.001050.87
1112023.06.13 03:15buy560.011961.000.001966.36
1122023.06.13 15:30t/p560.011966.360.001966.365.361056.23
1132023.07.12 03:45buy570.011936.100.001941.76
1142023.07.12 15:30t/p570.011941.760.001941.765.661061.89
1152023.07.19 23:00buy580.011978.780.001982.56
1162023.07.20 04:30t/p580.011982.560.001982.562.471064.36
+
diff --git a/Docs/Reports/Tests/XR/StrategyTester 2.gif b/Docs/Reports/Tests/XR/StrategyTester 2.gif new file mode 100644 index 0000000..e8b04be Binary files /dev/null and b/Docs/Reports/Tests/XR/StrategyTester 2.gif differ diff --git a/Docs/Reports/Tests/XR/StrategyTester 2.htm b/Docs/Reports/Tests/XR/StrategyTester 2.htm new file mode 100644 index 0000000..e26147c --- /dev/null +++ b/Docs/Reports/Tests/XR/StrategyTester 2.htm @@ -0,0 +1,172 @@ + + + + Strategy Tester: x-saherelm.xr.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.xr.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.07.21 23:45 (2020.01.01 - 2023.07.22)
ModelEvery tick (the most precise method based on all available least timeframes)
Bars in test62709Ticks modelled71719330Modelling qualityn/a
Mismatched charts errors777
Initial deposit1000.00SpreadCurrent (60)
Total net profit1287.21Gross profit3975.20Gross loss-2687.99
Profit factor1.48Expected payoff22.19
Absolute drawdown183.02Maximal drawdown772.20 (29.49%)Relative drawdown29.49% (772.20)
Total trades58Short positions (won %)0 (0.00%)Long positions (won %)58 (58.62%)
Profit trades (% of total)34 (58.62%)Loss trades (% of total)24 (41.38%)
Largestprofit trade291.60loss trade-307.60
Averageprofit trade116.92loss trade-112.00
Maximumconsecutive wins (profit in money)4 (460.18)consecutive losses (loss in money)3 (-521.80)
Maximalconsecutive profit (count of wins)460.18 (4)consecutive loss (count of losses)-521.80 (3)
Averageconsecutive wins2consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.03 23:30buy10.201841.440.001845.90
22020.12.04 15:31t/p10.201845.900.001845.9080.491080.49
32020.12.08 18:30buy20.201870.350.001886.13
42020.12.09 05:19close20.201864.070.001886.13-134.31946.18
52020.12.30 03:45buy30.201883.290.001893.75
62020.12.30 10:00close30.201878.490.001893.75-96.00850.18
72020.12.30 18:00buy40.201885.860.001895.62
82020.12.31 02:15t/p40.201895.620.001895.62169.081019.26
92021.01.05 11:30buy50.201944.710.001954.49
102021.01.06 03:09t/p50.201954.490.001954.49186.891206.15
112021.04.05 17:30buy60.201729.420.001742.62
122021.04.05 22:00close60.201725.680.001742.62-74.801131.35
132021.04.19 06:15buy70.201778.720.001785.24
142021.04.19 07:15close70.201776.750.001785.24-39.401091.95
152021.04.26 21:00buy80.201780.010.001781.77
162021.04.26 23:39t/p80.201781.770.001781.7735.201127.15
172021.05.18 23:45buy90.201870.210.001872.99
182021.05.19 05:00close90.201867.630.001872.99-60.311066.84
192021.05.20 08:15buy100.201876.090.001877.07
202021.05.20 08:30t/p100.201877.070.001877.0719.601086.44
212021.05.21 11:30buy110.201876.530.001882.65
222021.05.21 15:21t/p110.201882.650.001882.65122.401208.84
232021.05.24 19:15buy120.201884.010.001887.27
242021.05.25 01:15close120.201880.910.001887.27-70.711138.14
252021.05.25 10:45buy130.201884.160.001898.74
262021.05.25 21:06t/p130.201898.740.001898.74291.601429.74
272021.06.28 20:30buy140.201780.510.001785.35
282021.06.28 21:15close140.201778.020.001785.35-49.801379.94
292021.07.06 04:15buy150.201792.940.001796.10
302021.07.06 04:53t/p150.201796.100.001796.1063.201443.14
312021.07.09 17:45buy160.201806.390.001814.91
322021.07.12 07:16close160.201801.870.001814.91-99.111344.03
332021.07.12 19:30buy170.201805.330.001808.45
342021.07.13 04:34t/p170.201808.450.001808.4553.691397.72
352021.08.12 23:00buy180.201753.790.001757.21
362021.08.13 09:09t/p180.201757.210.001757.2159.691457.41
372021.09.01 22:30buy190.201815.330.001820.69
382021.09.02 02:45close190.201813.220.001820.69-68.321389.09
392021.09.03 05:15buy200.201813.490.001819.35
402021.09.03 15:34t/p200.201819.350.001819.35117.201506.29
412021.09.29 06:00buy210.201740.530.001751.43
422021.09.29 16:24close210.201736.210.001751.43-86.401419.89
432021.11.16 04:45buy220.201867.860.001877.40
442021.11.16 09:45close220.201863.300.001877.40-91.201328.69
452021.12.07 04:30buy230.201781.010.001785.23
462021.12.07 05:45close230.201778.500.001785.23-50.201278.49
472021.12.07 20:30buy240.201784.430.001788.51
482021.12.08 04:07t/p240.201788.510.001788.5172.891351.38
492021.12.28 08:15buy250.201813.150.001819.37
502021.12.28 15:37t/p250.201819.370.001819.37124.401475.78
512022.01.10 21:30buy260.201801.220.001805.98
522022.01.11 04:24t/p260.201805.980.001805.9886.491562.27
532022.01.19 11:15buy270.201816.130.001824.95
542022.01.19 15:54t/p270.201824.950.001824.95176.401738.67
552022.01.24 23:15buy280.201843.380.001853.74
562022.01.25 11:04close280.201838.270.001853.74-110.911627.76
572022.01.31 11:30buy290.201791.280.001798.92
582022.01.31 16:39t/p290.201798.920.001798.92152.801780.56
592022.02.16 09:30buy300.201856.110.001860.85
602022.02.16 15:00close300.201852.740.001860.85-67.401713.16
612022.03.03 22:15buy310.201937.410.001946.73
622022.03.04 02:36t/p310.201946.730.001946.73177.691890.86
632022.03.04 13:00buy320.201947.630.001961.75
642022.03.04 18:09t/p320.201961.750.001961.75282.402173.26
652022.03.11 21:30buy330.201986.950.001999.25
662022.03.14 00:45close330.201972.860.001999.25-290.511882.75
672022.03.24 13:30buy340.201946.500.001957.42
682022.03.24 14:03t/p340.201957.420.001957.42218.402101.15
692022.04.05 16:15buy350.201935.270.001956.63
702022.04.05 18:45close350.201925.680.001956.63-191.801909.35
712022.04.13 08:30buy360.201969.860.001973.40
722022.04.13 11:19t/p360.201973.400.001973.4070.801980.15
732022.05.20 09:45buy370.201848.340.001859.62
742022.05.20 16:30close370.201840.610.001859.62-154.601825.55
752022.05.23 01:15buy380.201845.310.001848.55
762022.05.23 02:07t/p380.201848.550.001848.5564.801890.35
772022.06.08 15:15buy390.201851.320.001858.82
782022.06.08 18:07t/p390.201858.820.001858.82150.002040.35
792022.07.05 02:15buy400.201810.010.001814.79
802022.07.05 10:30close400.201806.730.001814.79-65.601974.75
812022.10.26 07:45buy410.201656.860.001658.96
822022.10.26 08:41t/p410.201658.960.001658.9642.002016.75
832022.10.27 08:45buy420.201669.970.001683.09
842022.10.27 09:45close420.201661.850.001683.09-162.401854.35
852022.11.02 04:00buy430.201650.460.001653.36
862022.11.02 10:00t/p430.201653.360.001653.3658.001912.35
872022.11.14 17:45buy440.201770.180.001784.24
882022.11.15 08:45close440.201769.440.001784.24-23.511888.84
892022.11.30 05:45buy450.201754.150.001759.19
902022.11.30 10:57t/p450.201759.190.001759.19100.801989.64
912023.01.11 06:30buy460.201877.620.001882.84
922023.01.11 07:37t/p460.201882.840.001882.84104.402094.04
932023.02.09 05:00buy470.201879.530.001889.99
942023.02.09 16:01t/p470.201889.990.001889.99209.202303.24
952023.02.16 21:30buy480.201843.520.001847.54
962023.02.17 01:15close480.201835.010.001847.54-178.912124.33
972023.02.22 05:15buy490.201837.180.001840.68
982023.02.22 10:03t/p490.201840.680.001840.6870.002194.33
992023.03.28 17:00buy500.201963.690.001968.77
1002023.03.28 17:57t/p500.201968.770.001968.77101.602295.93
1012023.03.30 10:45buy510.201969.560.001976.42
1022023.03.30 19:01t/p510.201976.420.001976.42137.202433.13
1032023.04.26 13:30buy520.202000.140.002005.44
1042023.04.26 16:24t/p520.202005.440.002005.44106.002539.13
1052023.04.27 06:00buy530.201999.160.002014.50
1062023.04.27 15:45close530.201983.780.002014.50-307.602231.53
1072023.05.15 19:45buy540.202020.300.002031.78
1082023.05.15 22:00close540.202014.590.002031.78-114.202117.33
1092023.06.09 17:30buy550.201967.630.001988.83
1102023.06.09 18:30close550.201962.630.001988.83-100.002017.33
1112023.06.13 03:15buy560.201961.000.001966.36
1122023.06.13 15:30t/p560.201966.360.001966.36107.202124.53
1132023.07.12 03:45buy570.201936.100.001941.76
1142023.07.12 15:30t/p570.201941.760.001941.76113.202237.73
1152023.07.19 23:00buy580.201978.780.001982.56
1162023.07.20 04:30t/p580.201982.560.001982.5649.482287.21
+
diff --git a/Docs/Reports/Tests/XR/StrategyTester 3.gif b/Docs/Reports/Tests/XR/StrategyTester 3.gif new file mode 100644 index 0000000..b615ee3 Binary files /dev/null and b/Docs/Reports/Tests/XR/StrategyTester 3.gif differ diff --git a/Docs/Reports/Tests/XR/StrategyTester 3.htm b/Docs/Reports/Tests/XR/StrategyTester 3.htm new file mode 100644 index 0000000..d2417ad --- /dev/null +++ b/Docs/Reports/Tests/XR/StrategyTester 3.htm @@ -0,0 +1,183 @@ + + + + Strategy Tester: x-saherelm.xr.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.xr.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.07.21 23:45 (2020.01.01 - 2023.07.22)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=50; swingLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.0003; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=252; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +
Bars in test62709Ticks modelled71719330Modelling qualityn/a
Mismatched charts errors777
Initial deposit1000.00SpreadCurrent (60)
Total net profit1930.81Gross profit5962.79Gross loss-4031.98
Profit factor1.48Expected payoff33.29
Absolute drawdown274.52Maximal drawdown1158.30 (33.79%)Relative drawdown39.80% (479.56)
Total trades58Short positions (won %)0 (0.00%)Long positions (won %)58 (58.62%)
Profit trades (% of total)34 (58.62%)Loss trades (% of total)24 (41.38%)
Largestprofit trade437.40loss trade-461.40
Averageprofit trade175.38loss trade-168.00
Maximumconsecutive wins (profit in money)4 (690.28)consecutive losses (loss in money)3 (-782.70)
Maximalconsecutive profit (count of wins)690.28 (4)consecutive loss (count of losses)-782.70 (3)
Averageconsecutive wins2consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.03 23:30buy10.301841.440.001845.90
22020.12.04 15:31t/p10.301845.900.001845.90120.741120.74
32020.12.08 18:30buy20.301870.350.001886.13
42020.12.09 05:19close20.301864.070.001886.13-201.46919.28
52020.12.30 03:45buy30.301883.290.001893.75
62020.12.30 10:00close30.301878.490.001893.75-144.00775.28
72020.12.30 18:00buy40.301885.860.001895.62
82020.12.31 02:15t/p40.301895.620.001895.62253.611028.89
92021.01.05 11:30buy50.301944.710.001954.49
102021.01.06 03:09t/p50.301954.490.001954.49280.341309.23
112021.04.05 17:30buy60.301729.420.001742.62
122021.04.05 22:00close60.301725.680.001742.62-112.201197.03
132021.04.19 06:15buy70.301778.720.001785.24
142021.04.19 07:15close70.301776.750.001785.24-59.101137.93
152021.04.26 21:00buy80.301780.010.001781.77
162021.04.26 23:39t/p80.301781.770.001781.7752.801190.73
172021.05.18 23:45buy90.301870.210.001872.99
182021.05.19 05:00close90.301867.630.001872.99-90.461100.27
192021.05.20 08:15buy100.301876.090.001877.07
202021.05.20 08:30t/p100.301877.070.001877.0729.401129.67
212021.05.21 11:30buy110.301876.530.001882.65
222021.05.21 15:21t/p110.301882.650.001882.65183.601313.27
232021.05.24 19:15buy120.301884.010.001887.27
242021.05.25 01:15close120.301880.910.001887.27-106.061207.20
252021.05.25 10:45buy130.301884.160.001898.74
262021.05.25 21:06t/p130.301898.740.001898.74437.401644.60
272021.06.28 20:30buy140.301780.510.001785.35
282021.06.28 21:15close140.301778.020.001785.35-74.701569.90
292021.07.06 04:15buy150.301792.940.001796.10
302021.07.06 04:53t/p150.301796.100.001796.1094.801664.70
312021.07.09 17:45buy160.301806.390.001814.91
322021.07.12 07:16close160.301801.870.001814.91-148.661516.04
332021.07.12 19:30buy170.301805.330.001808.45
342021.07.13 04:34t/p170.301808.450.001808.4580.541596.58
352021.08.12 23:00buy180.301753.790.001757.21
362021.08.13 09:09t/p180.301757.210.001757.2189.541686.12
372021.09.01 22:30buy190.301815.330.001820.69
382021.09.02 02:45close190.301813.220.001820.69-102.491583.63
392021.09.03 05:15buy200.301813.490.001819.35
402021.09.03 15:34t/p200.301819.350.001819.35175.801759.43
412021.09.29 06:00buy210.301740.530.001751.43
422021.09.29 16:24close210.301736.210.001751.43-129.601629.83
432021.11.16 04:45buy220.301867.860.001877.40
442021.11.16 09:45close220.301863.300.001877.40-136.801493.03
452021.12.07 04:30buy230.301781.010.001785.23
462021.12.07 05:45close230.301778.500.001785.23-75.301417.73
472021.12.07 20:30buy240.301784.430.001788.51
482021.12.08 04:07t/p240.301788.510.001788.51109.341527.07
492021.12.28 08:15buy250.301813.150.001819.37
502021.12.28 15:37t/p250.301819.370.001819.37186.601713.67
512022.01.10 21:30buy260.301801.220.001805.98
522022.01.11 04:24t/p260.301805.980.001805.98129.741843.41
532022.01.19 11:15buy270.301816.130.001824.95
542022.01.19 15:54t/p270.301824.950.001824.95264.602108.01
552022.01.24 23:15buy280.301843.380.001853.74
562022.01.25 11:04close280.301838.270.001853.74-166.361941.65
572022.01.31 11:30buy290.301791.280.001798.92
582022.01.31 16:39t/p290.301798.920.001798.92229.202170.85
592022.02.16 09:30buy300.301856.110.001860.85
602022.02.16 15:00close300.301852.740.001860.85-101.102069.75
612022.03.03 22:15buy310.301937.410.001946.73
622022.03.04 02:36t/p310.301946.730.001946.73266.542336.28
632022.03.04 13:00buy320.301947.630.001961.75
642022.03.04 18:09t/p320.301961.750.001961.75423.602759.88
652022.03.11 21:30buy330.301986.950.001999.25
662022.03.14 00:45close330.301972.860.001999.25-435.762324.12
672022.03.24 13:30buy340.301946.500.001957.42
682022.03.24 14:03t/p340.301957.420.001957.42327.602651.72
692022.04.05 16:15buy350.301935.270.001956.63
702022.04.05 18:45close350.301925.680.001956.63-287.702364.02
712022.04.13 08:30buy360.301969.860.001973.40
722022.04.13 11:19t/p360.301973.400.001973.40106.202470.22
732022.05.20 09:45buy370.301848.340.001859.62
742022.05.20 16:30close370.301840.610.001859.62-231.902238.32
752022.05.23 01:15buy380.301845.310.001848.55
762022.05.23 02:07t/p380.301848.550.001848.5597.202335.52
772022.06.08 15:15buy390.301851.320.001858.82
782022.06.08 18:07t/p390.301858.820.001858.82225.002560.52
792022.07.05 02:15buy400.301810.010.001814.79
802022.07.05 10:30close400.301806.730.001814.79-98.402462.12
812022.10.26 07:45buy410.301656.860.001658.96
822022.10.26 08:41t/p410.301658.960.001658.9663.002525.12
832022.10.27 08:45buy420.301669.970.001683.09
842022.10.27 09:45close420.301661.850.001683.09-243.602281.52
852022.11.02 04:00buy430.301650.460.001653.36
862022.11.02 10:00t/p430.301653.360.001653.3687.002368.52
872022.11.14 17:45buy440.301770.180.001784.24
882022.11.15 08:45close440.301769.440.001784.24-35.262333.26
892022.11.30 05:45buy450.301754.150.001759.19
902022.11.30 10:57t/p450.301759.190.001759.19151.202484.46
912023.01.11 06:30buy460.301877.620.001882.84
922023.01.11 07:37t/p460.301882.840.001882.84156.602641.06
932023.02.09 05:00buy470.301879.530.001889.99
942023.02.09 16:01t/p470.301889.990.001889.99313.802954.86
952023.02.16 21:30buy480.301843.520.001847.54
962023.02.17 01:15close480.301835.010.001847.54-268.362686.50
972023.02.22 05:15buy490.301837.180.001840.68
982023.02.22 10:03t/p490.301840.680.001840.68105.002791.50
992023.03.28 17:00buy500.301963.690.001968.77
1002023.03.28 17:57t/p500.301968.770.001968.77152.402943.90
1012023.03.30 10:45buy510.301969.560.001976.42
1022023.03.30 19:01t/p510.301976.420.001976.42205.803149.70
1032023.04.26 13:30buy520.302000.140.002005.44
1042023.04.26 16:24t/p520.302005.440.002005.44159.003308.70
1052023.04.27 06:00buy530.301999.160.002014.50
1062023.04.27 15:45close530.301983.780.002014.50-461.402847.30
1072023.05.15 19:45buy540.302020.300.002031.78
1082023.05.15 22:00close540.302014.590.002031.78-171.302676.00
1092023.06.09 17:30buy550.301967.630.001988.83
1102023.06.09 18:30close550.301962.630.001988.83-150.002526.00
1112023.06.13 03:15buy560.301961.000.001966.36
1122023.06.13 15:30t/p560.301966.360.001966.36160.802686.80
1132023.07.12 03:45buy570.301936.100.001941.76
1142023.07.12 15:30t/p570.301941.760.001941.76169.802856.60
1152023.07.19 23:00buy580.301978.780.001982.56
1162023.07.20 04:30t/p580.301982.560.001982.5674.212930.81
+
diff --git a/Docs/Reports/Tests/XR/StrategyTester 4.gif b/Docs/Reports/Tests/XR/StrategyTester 4.gif new file mode 100644 index 0000000..2f235e8 Binary files /dev/null and b/Docs/Reports/Tests/XR/StrategyTester 4.gif differ diff --git a/Docs/Reports/Tests/XR/StrategyTester 4.htm b/Docs/Reports/Tests/XR/StrategyTester 4.htm new file mode 100644 index 0000000..6e17ef6 --- /dev/null +++ b/Docs/Reports/Tests/XR/StrategyTester 4.htm @@ -0,0 +1,183 @@ + + + + Strategy Tester: x-saherelm.xr.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.xr.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.07.21 23:45 (2020.01.01 - 2023.07.22)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +marketLength=50; swingLength=7; riskToRewardRatio=2; alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.0003; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.3; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=252; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +
Bars in test62709Ticks modelled71719330Modelling qualityn/a
Mismatched charts errors777
Initial deposit1000.00SpreadCurrent (60)
Total net profit2201.41Gross profit5962.79Gross loss-3761.38
Profit factor1.59Expected payoff37.96
Absolute drawdown274.52Maximal drawdown997.50 (28.19%)Relative drawdown39.80% (479.56)
Total trades58Short positions (won %)0 (0.00%)Long positions (won %)58 (58.62%)
Profit trades (% of total)34 (58.62%)Loss trades (% of total)24 (41.38%)
Largestprofit trade437.40loss trade-313.66
Averageprofit trade175.38loss trade-156.72
Maximumconsecutive wins (profit in money)4 (690.28)consecutive losses (loss in money)3 (-621.90)
Maximalconsecutive profit (count of wins)690.28 (4)consecutive loss (count of losses)-621.90 (3)
Averageconsecutive wins2consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.03 23:30buy10.301841.440.001845.90
22020.12.04 15:31t/p10.301845.900.001845.90120.741120.74
32020.12.08 18:30buy20.301870.350.001886.13
42020.12.09 05:19close20.301864.070.001886.13-201.46919.28
52020.12.30 03:45buy30.301883.290.001893.75
62020.12.30 10:00close30.301878.490.001893.75-144.00775.28
72020.12.30 18:00buy40.301885.860.001895.62
82020.12.31 02:15t/p40.301895.620.001895.62253.611028.89
92021.01.05 11:30buy50.301944.710.001954.49
102021.01.06 03:09t/p50.301954.490.001954.49280.341309.23
112021.04.05 17:30buy60.301729.420.001742.62
122021.04.05 22:00close60.301725.680.001742.62-112.201197.03
132021.04.19 06:15buy70.301778.720.001785.24
142021.04.19 07:15close70.301776.750.001785.24-59.101137.93
152021.04.26 21:00buy80.301780.010.001781.77
162021.04.26 23:39t/p80.301781.770.001781.7752.801190.73
172021.05.18 23:45buy90.301870.210.001872.99
182021.05.19 05:00close90.301867.630.001872.99-90.461100.27
192021.05.20 08:15buy100.301876.090.001877.07
202021.05.20 08:30t/p100.301877.070.001877.0729.401129.67
212021.05.21 11:30buy110.301876.530.001882.65
222021.05.21 15:21t/p110.301882.650.001882.65183.601313.27
232021.05.24 19:15buy120.301884.010.001887.27
242021.05.25 01:15close120.301880.910.001887.27-106.061207.20
252021.05.25 10:45buy130.301884.160.001898.74
262021.05.25 21:06t/p130.301898.740.001898.74437.401644.60
272021.06.28 20:30buy140.301780.510.001785.35
282021.06.28 21:15close140.301778.020.001785.35-74.701569.90
292021.07.06 04:15buy150.301792.940.001796.10
302021.07.06 04:53t/p150.301796.100.001796.1094.801664.70
312021.07.09 17:45buy160.301806.390.001814.91
322021.07.12 07:16close160.301801.870.001814.91-148.661516.04
332021.07.12 19:30buy170.301805.330.001808.45
342021.07.13 04:34t/p170.301808.450.001808.4580.541596.58
352021.08.12 23:00buy180.301753.790.001757.21
362021.08.13 09:09t/p180.301757.210.001757.2189.541686.12
372021.09.01 22:30buy190.301815.330.001820.69
382021.09.02 02:45close190.301813.220.001820.69-102.491583.63
392021.09.03 05:15buy200.301813.490.001819.35
402021.09.03 15:34t/p200.301819.350.001819.35175.801759.43
412021.09.29 06:00buy210.301740.530.001751.43
422021.09.29 16:24close210.301736.210.001751.43-129.601629.83
432021.11.16 04:45buy220.301867.860.001877.40
442021.11.16 09:45close220.301863.300.001877.40-136.801493.03
452021.12.07 04:30buy230.301781.010.001785.23
462021.12.07 05:45close230.301778.500.001785.23-75.301417.73
472021.12.07 20:30buy240.301784.430.001788.51
482021.12.08 04:07t/p240.301788.510.001788.51109.341527.07
492021.12.28 08:15buy250.301813.150.001819.37
502021.12.28 15:37t/p250.301819.370.001819.37186.601713.67
512022.01.10 21:30buy260.301801.220.001805.98
522022.01.11 04:24t/p260.301805.980.001805.98129.741843.41
532022.01.19 11:15buy270.301816.130.001824.95
542022.01.19 15:54t/p270.301824.950.001824.95264.602108.01
552022.01.24 23:15buy280.301843.380.001853.74
562022.01.25 11:04close280.301838.270.001853.74-166.361941.65
572022.01.31 11:30buy290.301791.280.001798.92
582022.01.31 16:39t/p290.301798.920.001798.92229.202170.85
592022.02.16 09:30buy300.301856.110.001860.85
602022.02.16 15:00close300.301852.740.001860.85-101.102069.75
612022.03.03 22:15buy310.301937.410.001946.73
622022.03.04 02:36t/p310.301946.730.001946.73266.542336.28
632022.03.04 13:00buy320.301947.630.001961.75
642022.03.04 18:09t/p320.301961.750.001961.75423.602759.88
652022.03.11 21:30buy330.301986.950.001999.25
662022.03.14 00:22close330.301976.930.001999.25-313.662446.22
672022.03.24 13:30buy340.301946.500.001957.42
682022.03.24 14:03t/p340.301957.420.001957.42327.602773.82
692022.04.05 16:15buy350.301935.270.001956.63
702022.04.05 18:24close350.301925.270.001956.63-300.002473.82
712022.04.13 08:30buy360.301969.860.001973.40
722022.04.13 11:19t/p360.301973.400.001973.40106.202580.02
732022.05.20 09:45buy370.301848.340.001859.62
742022.05.20 16:30close370.301840.610.001859.62-231.902348.12
752022.05.23 01:15buy380.301845.310.001848.55
762022.05.23 02:07t/p380.301848.550.001848.5597.202445.32
772022.06.08 15:15buy390.301851.320.001858.82
782022.06.08 18:07t/p390.301858.820.001858.82225.002670.32
792022.07.05 02:15buy400.301810.010.001814.79
802022.07.05 10:30close400.301806.730.001814.79-98.402571.92
812022.10.26 07:45buy410.301656.860.001658.96
822022.10.26 08:41t/p410.301658.960.001658.9663.002634.92
832022.10.27 08:45buy420.301669.970.001683.09
842022.10.27 09:45close420.301661.850.001683.09-243.602391.32
852022.11.02 04:00buy430.301650.460.001653.36
862022.11.02 10:00t/p430.301653.360.001653.3687.002478.32
872022.11.14 17:45buy440.301770.180.001784.24
882022.11.15 08:45close440.301769.440.001784.24-35.262443.06
892022.11.30 05:45buy450.301754.150.001759.19
902022.11.30 10:57t/p450.301759.190.001759.19151.202594.26
912023.01.11 06:30buy460.301877.620.001882.84
922023.01.11 07:37t/p460.301882.840.001882.84156.602750.86
932023.02.09 05:00buy470.301879.530.001889.99
942023.02.09 16:01t/p470.301889.990.001889.99313.803064.66
952023.02.16 21:30buy480.301843.520.001847.54
962023.02.17 01:15close480.301835.010.001847.54-268.362796.30
972023.02.22 05:15buy490.301837.180.001840.68
982023.02.22 10:03t/p490.301840.680.001840.68105.002901.30
992023.03.28 17:00buy500.301963.690.001968.77
1002023.03.28 17:57t/p500.301968.770.001968.77152.403053.70
1012023.03.30 10:45buy510.301969.560.001976.42
1022023.03.30 19:01t/p510.301976.420.001976.42205.803259.50
1032023.04.26 13:30buy520.302000.140.002005.44
1042023.04.26 16:24t/p520.302005.440.002005.44159.003418.50
1052023.04.27 06:00buy530.301999.160.002014.50
1062023.04.27 15:35close530.301989.140.002014.50-300.603117.90
1072023.05.15 19:45buy540.302020.300.002031.78
1082023.05.15 22:00close540.302014.590.002031.78-171.302946.60
1092023.06.09 17:30buy550.301967.630.001988.83
1102023.06.09 18:30close550.301962.630.001988.83-150.002796.60
1112023.06.13 03:15buy560.301961.000.001966.36
1122023.06.13 15:30t/p560.301966.360.001966.36160.802957.40
1132023.07.12 03:45buy570.301936.100.001941.76
1142023.07.12 15:30t/p570.301941.760.001941.76169.803127.20
1152023.07.19 23:00buy580.301978.780.001982.56
1162023.07.20 04:30t/p580.301982.560.001982.5674.213201.41
+
diff --git a/Docs/Reports/Tests/XR/StrategyTester 5.gif b/Docs/Reports/Tests/XR/StrategyTester 5.gif new file mode 100644 index 0000000..905a6a2 Binary files /dev/null and b/Docs/Reports/Tests/XR/StrategyTester 5.gif differ diff --git a/Docs/Reports/Tests/XR/StrategyTester 5.htm b/Docs/Reports/Tests/XR/StrategyTester 5.htm new file mode 100644 index 0000000..1f7f2fa --- /dev/null +++ b/Docs/Reports/Tests/XR/StrategyTester 5.htm @@ -0,0 +1,213 @@ + + + + Strategy Tester: x-saherelm.xr.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.xr.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.07.21 23:45 (2020.01.01 - 2023.07.22)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.0003; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.3; minBalancePercent=0.5; maxEquityPercent=0.1; closeAllOpenTradesAfterCandle=252; closeAllInProfitOpenTradesWhenMaxOpenTradesReached=false; +xrR2R=2; xrMarketLength=7; xrMarketRangeMult=7; xrFastMult=3; xrSlowMult=7; xrSwingLength=7;
Bars in test62709Ticks modelled71719330Modelling qualityn/a
Mismatched charts errors777
Initial deposit1000.00SpreadCurrent (60)
Total net profit2656.05Gross profit8026.93Gross loss-5370.88
Profit factor1.49Expected payoff36.38
Absolute drawdown169.22Maximal drawdown954.90 (24.18%)Relative drawdown31.06% (374.26)
Total trades73Short positions (won %)0 (0.00%)Long positions (won %)73 (56.16%)
Profit trades (% of total)41 (56.16%)Loss trades (% of total)32 (43.84%)
Largestprofit trade528.00loss trade-313.66
Averageprofit trade195.78loss trade-167.84
Maximumconsecutive wins (profit in money)4 (991.20)consecutive losses (loss in money)3 (-208.69)
Maximalconsecutive profit (count of wins)991.20 (4)consecutive loss (count of losses)-493.50 (2)
Averageconsecutive wins2consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.03 23:30buy10.301841.440.001845.90
22020.12.04 15:31t/p10.301845.900.001845.90120.741120.74
32020.12.08 18:30buy20.301870.350.001886.13
42020.12.09 03:19close20.301867.580.001886.13-96.161024.58
52020.12.30 03:45buy30.301883.290.001893.75
62020.12.30 10:00close30.301878.490.001893.75-144.00880.58
72020.12.30 18:00buy40.301885.860.001895.62
82020.12.31 02:15t/p40.301895.620.001895.62253.611134.19
92020.12.31 13:45buy50.301894.880.001901.64
102021.01.04 01:00t/p50.301901.640.001901.64176.681310.87
112021.01.05 11:30buy60.301944.710.001954.49
122021.01.06 03:09t/p60.301954.490.001954.49280.341591.20
132021.04.05 17:30buy70.301729.420.001742.62
142021.04.05 22:00close70.301725.680.001742.62-112.201479.00
152021.04.26 21:00buy80.301780.010.001781.77
162021.04.26 23:39t/p80.301781.770.001781.7752.801531.80
172021.05.11 09:00buy90.301837.410.001840.21
182021.05.11 09:51close90.301834.840.001840.21-77.101454.70
192021.05.18 23:45buy100.301870.210.001872.99
202021.05.19 05:00close100.301867.630.001872.99-90.461364.24
212021.05.20 08:15buy110.301876.090.001877.07
222021.05.20 08:30t/p110.301877.070.001877.0729.401393.64
232021.05.21 11:30buy120.301876.530.001882.65
242021.05.21 15:21t/p120.301882.650.001882.65183.601577.24
252021.05.24 19:15buy130.301884.010.001887.27
262021.05.25 01:15close130.301880.910.001887.27-106.061471.18
272021.05.25 10:45buy140.301884.160.001898.74
282021.05.25 21:06t/p140.301898.740.001898.74437.401908.58
292021.06.28 20:30buy150.301780.510.001785.35
302021.06.28 21:15close150.301778.020.001785.35-74.701833.88
312021.07.02 02:00buy160.301776.630.001777.79
322021.07.02 03:39t/p160.301777.790.001777.7934.801868.68
332021.07.06 04:15buy170.301792.940.001796.10
342021.07.06 04:53t/p170.301796.100.001796.1094.801963.48
352021.07.09 17:45buy180.301806.390.001814.91
362021.07.12 07:16close180.301801.870.001814.91-148.661814.82
372021.07.13 17:45buy190.301811.870.001825.27
382021.07.13 21:07close190.301806.200.001825.27-170.101644.72
392021.08.11 05:30buy200.301732.250.001747.61
402021.08.11 18:06t/p200.301747.610.001747.61460.802105.52
412021.08.12 23:00buy210.301753.790.001757.21
422021.08.13 09:09t/p210.301757.210.001757.2189.542195.06
432021.08.18 04:30buy220.301789.150.001796.39
442021.08.18 12:30close220.301787.880.001796.39-38.102156.96
452021.09.01 22:30buy230.301815.330.001820.69
462021.09.02 02:45close230.301813.220.001820.69-102.492054.47
472021.09.02 03:15buy240.301815.430.001819.79
482021.09.02 05:30close240.301813.160.001819.79-68.101986.37
492021.09.03 05:15buy250.301813.490.001819.35
502021.09.03 15:34t/p250.301819.350.001819.35175.802162.17
512021.09.27 03:45buy260.301753.930.001763.97
522021.09.27 12:49close260.301749.120.001763.97-144.302017.87
532021.10.22 02:15buy270.301786.030.001793.21
542021.10.22 09:54t/p270.301793.210.001793.21215.402233.27
552021.11.16 04:45buy280.301867.860.001877.40
562021.11.16 09:45close280.301863.300.001877.40-136.802096.47
572021.12.07 04:30buy290.301781.010.001785.23
582021.12.07 05:45close290.301778.500.001785.23-75.302021.17
592021.12.07 20:30buy300.301784.430.001788.51
602021.12.08 04:07t/p300.301788.510.001788.51109.342130.51
612021.12.28 08:15buy310.301813.150.001819.37
622021.12.28 15:37t/p310.301819.370.001819.37186.602317.11
632022.01.10 21:30buy320.301801.220.001805.98
642022.01.11 04:24t/p320.301805.980.001805.98129.742446.85
652022.01.19 11:15buy330.301816.130.001824.95
662022.01.19 15:54t/p330.301824.950.001824.95264.602711.45
672022.01.24 23:15buy340.301843.380.001853.74
682022.01.25 12:36close340.301836.700.001853.74-213.462497.98
692022.01.31 11:30buy350.301791.280.001798.92
702022.01.31 16:39t/p350.301798.920.001798.92229.202727.18
712022.02.16 09:30buy360.301856.110.001860.85
722022.02.16 15:00close360.301852.740.001860.85-101.102626.08
732022.02.28 16:15buy370.301914.460.001926.88
742022.02.28 18:09close370.301904.460.001926.88-300.002326.08
752022.03.03 22:15buy380.301937.410.001946.73
762022.03.04 02:36t/p380.301946.730.001946.73266.542592.62
772022.03.04 13:00buy390.301947.630.001961.75
782022.03.04 18:09t/p390.301961.750.001961.75423.603016.22
792022.03.11 21:30buy400.301986.950.001999.25
802022.03.14 00:22close400.301976.930.001999.25-313.662702.56
812022.03.21 06:45buy410.301928.320.001933.60
822022.03.21 14:30close410.301923.730.001933.60-137.702564.86
832022.03.24 13:30buy420.301946.500.001957.42
842022.03.24 14:03t/p420.301957.420.001957.42327.602892.46
852022.04.05 16:15buy430.301935.270.001956.63
862022.04.05 18:24close430.301925.270.001956.63-300.002592.46
872022.04.13 08:30buy440.301969.860.001973.40
882022.04.13 11:19t/p440.301973.400.001973.40106.202698.66
892022.05.04 11:30buy450.301869.680.001876.04
902022.05.04 17:15close450.301863.310.001876.04-191.102507.56
912022.05.20 09:45buy460.301848.340.001859.62
922022.05.20 16:31close460.301840.590.001859.62-232.502275.06
932022.05.23 01:15buy470.301845.310.001848.55
942022.05.23 02:07t/p470.301848.550.001848.5597.202372.26
952022.05.30 06:45buy480.301859.800.001862.94
962022.05.30 08:42t/p480.301862.940.001862.9494.202466.46
972022.06.08 15:15buy490.301851.320.001858.82
982022.06.08 18:07t/p490.301858.820.001858.82225.002691.46
992022.07.05 02:15buy500.301810.010.001814.79
1002022.07.05 10:30close500.301806.730.001814.79-98.402593.06
1012022.09.09 04:30buy510.301715.930.001727.53
1022022.09.09 10:22t/p510.301727.530.001727.53348.002941.06
1032022.10.27 08:45buy520.301669.970.001683.09
1042022.10.27 09:45close520.301661.850.001683.09-243.602697.46
1052022.11.02 04:00buy530.301650.460.001653.36
1062022.11.02 10:00t/p530.301653.360.001653.3687.002784.46
1072022.11.16 12:15buy540.301783.620.001796.96
1082022.11.16 16:37close540.301773.620.001796.96-300.002484.46
1092022.11.30 05:45buy550.301754.150.001759.19
1102022.11.30 10:57t/p550.301759.190.001759.19151.202635.66
1112022.12.08 15:15buy560.301787.360.001794.56
1122022.12.08 17:28t/p560.301794.560.001794.56216.002851.66
1132022.12.21 16:45buy570.301818.300.001822.80
1142022.12.21 17:37t/p570.301822.800.001822.80135.002986.66
1152023.01.09 18:45buy580.301876.980.001885.82
1162023.01.10 02:26close580.301868.360.001885.82-271.662715.00
1172023.01.11 06:30buy590.301877.620.001882.84
1182023.01.11 07:37t/p590.301882.840.001882.84156.602871.60
1192023.02.09 05:00buy600.301879.530.001889.99
1202023.02.09 16:01t/p600.301889.990.001889.99313.803185.40
1212023.02.16 21:30buy610.301843.520.001847.54
1222023.02.17 01:15close610.301835.010.001847.54-268.362917.04
1232023.02.22 05:15buy620.301837.180.001840.68
1242023.02.22 10:03t/p620.301840.680.001840.68105.003022.04
1252023.03.17 04:45buy630.301929.140.001946.74
1262023.03.17 15:02t/p630.301946.740.001946.74528.003550.04
1272023.03.28 17:00buy640.301963.690.001968.77
1282023.03.28 17:57t/p640.301968.770.001968.77152.403702.44
1292023.03.30 10:45buy650.301969.560.001976.42
1302023.03.30 19:01t/p650.301976.420.001976.42205.803908.24
1312023.04.26 13:30buy660.302000.140.002005.44
1322023.04.26 15:30close660.301993.710.002005.44-192.903715.34
1332023.04.27 06:00buy670.301999.160.002014.50
1342023.04.27 15:35close670.301989.140.002014.50-300.603414.74
1352023.05.09 08:15buy680.302027.060.002032.32
1362023.05.09 14:30t/p680.302032.320.002032.32157.803572.54
1372023.05.15 19:45buy690.302020.300.002031.78
1382023.05.15 22:00close690.302014.590.002031.78-171.303401.24
1392023.06.09 17:30buy700.301967.630.001988.83
1402023.06.09 18:30close700.301962.630.001988.83-150.003251.24
1412023.06.13 03:15buy710.301961.000.001966.36
1422023.06.13 15:30t/p710.301966.360.001966.36160.803412.04
1432023.07.12 03:45buy720.301936.100.001941.76
1442023.07.12 15:30t/p720.301941.760.001941.76169.803581.84
1452023.07.19 23:00buy730.301978.780.001982.56
1462023.07.20 04:30t/p730.301982.560.001982.5674.213656.05
+
diff --git a/Docs/Reports/Tests/XTPW/Full/StrategyTester 1.gif b/Docs/Reports/Tests/XTPW/Full/StrategyTester 1.gif new file mode 100644 index 0000000..dabf25d Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Full/StrategyTester 1.gif differ diff --git a/Docs/Reports/Tests/XTPW/Full/StrategyTester 1.htm b/Docs/Reports/Tests/XTPW/Full/StrategyTester 1.htm new file mode 100644 index 0000000..e6ae90d --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Full/StrategyTester 1.htm @@ -0,0 +1,169 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.01 23:45 (2020.01.01 - 2023.08.02)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63353Ticks modelled72601176Modelling qualityn/a
Mismatched charts errors808
Initial deposit1000.00SpreadCurrent (57)
Total net profit209.11Gross profit297.85Gross loss-88.73
Profit factor3.36Expected payoff4.18
Absolute drawdown5.97Maximal drawdown30.04 (2.64%)Relative drawdown2.64% (30.04)
Total trades50Short positions (won %)35 (85.71%)Long positions (won %)15 (93.33%)
Profit trades (% of total)44 (88.00%)Loss trades (% of total)6 (12.00%)
Largestprofit trade22.02loss trade-15.49
Averageprofit trade6.77loss trade-14.79
Maximumconsecutive wins (profit in money)10 (74.81)consecutive losses (loss in money)1 (-15.49)
Maximalconsecutive profit (count of wins)74.81 (10)consecutive loss (count of losses)-15.49 (1)
Averageconsecutive wins6consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 17:39sell10.011836.610.001825.20
22020.12.07 10:37t/p10.011825.200.001825.2011.631011.63
32021.01.29 16:54sell20.011865.800.001855.99
42021.01.29 19:22t/p20.011855.990.001855.999.811021.44
52021.02.09 17:45sell30.011841.990.001838.33
62021.02.09 18:09t/p30.011838.330.001838.333.661025.10
72021.02.10 17:00sell40.011841.300.001827.41
82021.02.11 19:09t/p40.011827.410.001827.4114.551039.65
92021.02.16 17:09sell50.011804.040.001801.47
102021.02.16 18:49t/p50.011801.470.001801.472.571042.22
112021.03.03 16:51sell60.011712.530.001708.07
122021.03.03 17:36t/p60.011708.070.001708.074.461046.68
132021.03.11 16:48buy70.011719.900.001728.00
142021.03.11 20:09t/p70.011728.000.001728.008.101054.78
152021.03.17 13:48buy80.011728.340.001737.00
162021.03.17 20:06t/p80.011737.000.001737.008.661063.44
172021.04.19 15:15buy90.011775.900.001781.90
182021.04.21 04:39t/p90.011781.900.001781.905.031068.46
192021.04.27 18:24buy100.011778.420.001784.35
202021.04.28 12:24close100.011763.420.001784.35-15.491052.98
212021.05.10 17:45sell110.011839.580.001833.85
222021.05.11 03:39t/p110.011833.850.001833.855.951058.93
232021.05.19 22:00buy120.011863.460.001881.95
242021.05.20 19:49t/p120.011881.950.001881.9517.031075.96
252021.07.06 19:07buy130.011794.080.001807.68
262021.07.07 13:24t/p130.011807.680.001807.6813.111089.07
272021.07.08 18:04buy140.011801.930.001814.59
282021.07.13 15:39t/p140.011814.590.001814.5911.201100.27
292021.07.13 17:21sell150.011811.750.001808.46
302021.07.13 20:37t/p150.011808.460.001808.463.291103.56
312021.08.17 17:15buy160.011782.680.001787.76
322021.08.18 04:09t/p160.011787.760.001787.764.591108.16
332021.08.20 17:39sell170.011781.750.001777.75
342021.08.23 03:16t/p170.011777.750.001777.754.221112.38
352021.08.31 15:30sell180.011811.860.001809.11
362021.08.31 16:04t/p180.011809.110.001809.112.751115.13
372021.10.27 18:09sell190.011793.560.001789.11
382021.10.28 16:30close190.011808.560.001789.11-14.341100.78
392021.11.03 04:00sell200.011783.060.001779.26
402021.11.03 08:15t/p200.011779.260.001779.263.801104.58
412021.11.30 17:48sell210.011794.770.001781.02
422021.11.30 18:04t/p210.011781.020.001781.0213.751118.33
432021.12.13 16:49sell220.011785.140.001782.99
442021.12.14 10:24t/p220.011782.990.001782.992.371120.70
452021.12.15 16:54sell230.011769.740.001766.01
462021.12.15 17:39t/p230.011766.010.001766.013.731124.43
472021.12.20 17:01sell240.011793.800.001789.41
482021.12.20 22:09t/p240.011789.410.001789.414.391128.82
492021.12.21 16:52buy250.011793.790.001799.79
502021.12.22 20:09t/p250.011799.790.001799.795.511134.34
512022.01.18 18:19sell260.011813.030.001806.19
522022.01.19 16:51close260.011828.030.001806.19-14.781119.55
532022.02.15 11:19buy270.011856.930.001866.99
542022.02.16 19:19t/p270.011866.990.001866.999.571129.13
552022.02.18 17:33sell280.011895.770.001893.21
562022.02.18 17:37t/p280.011893.210.001893.212.561131.69
572022.03.02 18:16sell290.011921.470.001907.56
582022.03.03 13:34close290.011936.470.001907.56-14.341117.35
592022.04.22 19:22sell300.011936.790.001932.93
602022.04.22 20:28t/p300.011932.930.001932.933.861121.21
612022.04.26 16:08sell310.011905.800.001905.21
622022.04.26 16:57t/p310.011905.210.001905.210.591121.80
632022.06.10 16:01sell320.011839.900.001834.17
642022.06.10 16:18t/p320.011834.170.001834.175.731127.53
652022.07.20 16:52sell330.011708.520.001702.79
662022.07.20 19:48t/p330.011702.790.001702.795.731133.26
672022.08.02 18:02sell340.011776.930.001767.92
682022.08.02 21:02t/p340.011767.920.001767.929.011142.27
692022.09.30 20:35buy350.011663.130.001667.34
702022.10.03 04:30t/p350.011667.340.001667.343.721145.99
712022.11.02 21:03sell360.011647.760.001626.40
722022.11.03 10:26t/p360.011626.400.001626.4022.021168.01
732022.11.30 17:18buy370.011751.890.001763.12
742022.11.30 21:20t/p370.011763.120.001763.1211.231179.24
752022.12.09 17:23buy380.011791.230.001800.19
762022.12.09 18:20t/p380.011800.190.001800.198.961188.20
772023.01.11 17:38buy390.011870.980.001874.94
782023.01.11 19:21t/p390.011874.940.001874.943.961192.16
792023.01.12 17:10sell400.011884.680.001867.96
802023.01.12 21:03close400.011899.680.001867.96-15.001177.16
812023.02.07 16:32sell410.011869.860.001868.93
822023.02.07 16:45t/p410.011868.930.001868.930.931178.09
832023.02.09 17:00sell420.011879.160.001868.22
842023.02.09 18:03t/p420.011868.220.001868.2210.941189.03
852023.03.02 20:35sell430.011835.870.001834.80
862023.03.03 21:27close430.011850.870.001834.80-14.781174.25
872023.04.26 19:17buy440.011989.040.001995.12
882023.04.27 05:13t/p440.011995.120.001995.124.621178.87
892023.05.15 17:34sell450.012016.660.002011.32
902023.05.16 09:04t/p450.012011.320.002011.325.561184.43
912023.05.26 17:09sell460.011951.200.001949.72
922023.05.26 17:19t/p460.011949.720.001949.721.481185.91
932023.06.07 17:32sell470.011958.950.001947.93
942023.06.07 18:51t/p470.011947.930.001947.9311.021196.93
952023.07.13 18:04sell480.011959.610.001957.54
962023.07.13 18:51t/p480.011957.540.001957.542.071199.00
972023.07.19 18:12sell490.011974.940.001970.18
982023.07.20 17:35t/p490.011970.180.001970.185.421204.41
992023.07.25 15:30sell500.011958.580.001953.88
1002023.07.25 17:00t/p500.011953.880.001953.884.701209.11
+
diff --git a/Docs/Reports/Tests/XTPW/In Test/StrategyTester 1.gif b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 1.gif new file mode 100644 index 0000000..46ab045 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 1.gif differ diff --git a/Docs/Reports/Tests/XTPW/In Test/StrategyTester 1.htm b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 1.htm new file mode 100644 index 0000000..e268a6f --- /dev/null +++ b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 1.htm @@ -0,0 +1,75 @@ + + + + Strategy Tester: + + + + + + + +
+
Strategy Tester Report
+
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
Symbol
Period 1970.01.01 00:00 - 1970.01.01 00:00
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=6; allowTrade=true; +allowLongTrades=false; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.0001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.15; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xR2R=2.5; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xrR2R=2; xRMaximumCandlesPerTrade=252; xrOscillatorLength=7; xrFastLength=20; xrSlowLength=50; xrRangeMarketLength=50; xrSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWR2R=1.5; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=700;
- 1970.01.01 00:00
+Graph
+ + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12021.01.08 11:00sell10.101888.710.001857.17
22021.01.08 16:49sell20.101868.640.001837.14
32021.01.08 17:09t/p10.101857.170.001857.17315.401315.40
42021.01.08 20:21t/p20.101837.140.001837.14315.001630.40
52022.01.18 10:30sell30.101814.210.001808.80
62022.01.18 15:09t/p30.101808.800.001808.8054.101684.50
+
diff --git a/Docs/Reports/Tests/XTPW/In Test/StrategyTester 2.gif b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 2.gif new file mode 100644 index 0000000..6bb225d Binary files /dev/null and b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 2.gif differ diff --git a/Docs/Reports/Tests/XTPW/In Test/StrategyTester 2.htm b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 2.htm new file mode 100644 index 0000000..5246318 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 2.htm @@ -0,0 +1,357 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.06.28 23:45 (2020.01.01 - 2023.06.29)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=6; allowTrade=true; +allowLongTrades=false; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.0001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.15; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xR2R=2.5; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xrR2R=2; xRMaximumCandlesPerTrade=252; xrOscillatorLength=7; xrFastLength=20; xrSlowLength=50; xrRangeMarketLength=50; xrSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWR2R=1.5; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=700;
Bars in test61155Ticks modelled69617088Modelling quality40.15%
Mismatched charts errors30
Initial deposit1000.00SpreadCurrent (50)
Total net profit2713.39Gross profit7938.41Gross loss-5225.02
Profit factor1.52Expected payoff18.84
Absolute drawdown53.20Maximal drawdown1492.43 (28.67%)Relative drawdown28.67% (1492.43)
Total trades144Short positions (won %)144 (75.00%)Long positions (won %)0 (0.00%)
Profit trades (% of total)108 (75.00%)Loss trades (% of total)36 (25.00%)
Largestprofit trade355.53loss trade-150.20
Averageprofit trade73.50loss trade-145.14
Maximumconsecutive wins (profit in money)16 (692.04)consecutive losses (loss in money)4 (-598.28)
Maximalconsecutive profit (count of wins)1621.17 (8)consecutive loss (count of losses)-598.28 (4)
Averageconsecutive wins4consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 15:15sell10.101793.480.001772.09
22020.11.30 02:30sell20.101783.130.001773.23
32020.11.30 04:51t/p20.101773.230.001773.2399.001099.00
42020.11.30 04:51t/p10.101772.090.001772.09215.811314.82
52021.01.08 11:00sell30.101888.710.001857.17
62021.01.08 15:15sell40.101882.460.001865.86
72021.01.08 16:45sell50.101871.560.001840.06
82021.01.08 16:51t/p40.101865.860.001865.86166.001480.82
92021.01.08 17:09t/p30.101857.170.001857.17315.401796.22
102021.01.08 18:15sell60.101854.120.001827.81
112021.01.08 19:33t/p50.101840.060.001840.06315.002111.22
122021.01.11 02:30sell70.101842.650.001823.57
132021.01.11 03:21t/p60.101827.810.001827.81265.022376.23
142021.01.11 03:24t/p70.101823.570.001823.57190.802567.03
152021.01.27 17:06sell80.101841.520.001836.68
162021.01.28 03:24t/p80.101836.680.001836.6854.142621.18
172021.01.28 08:15sell90.101835.080.001828.99
182021.01.28 15:45close90.101850.080.001828.99-150.002471.18
192021.02.02 13:45sell100.101845.320.001834.90
202021.02.02 15:22t/p100.101834.900.001834.90104.202575.38
212021.02.02 20:45sell110.101835.300.001831.00
222021.02.03 17:39t/p110.101831.000.001831.0044.912620.29
232021.02.04 03:15sell120.101832.970.001830.68
242021.02.04 03:45t/p120.101830.680.001830.6822.902643.19
252021.02.04 11:30sell130.101815.010.001798.05
262021.02.04 16:09t/p130.101798.050.001798.05169.602812.79
272021.02.12 03:00sell140.101823.920.001818.13
282021.02.12 09:54t/p140.101818.130.001818.1357.902870.69
292021.02.16 19:45sell150.101797.010.001776.58
302021.02.17 15:39t/p150.101776.580.001776.58206.223076.91
312021.02.17 21:15sell160.101774.560.001766.84
322021.02.18 15:09close160.101789.560.001766.84-144.252932.65
332021.02.19 02:15sell170.101770.450.001760.93
342021.02.19 16:06close170.101785.450.001760.93-150.002782.65
352021.02.24 21:30sell180.101798.290.001796.22
362021.02.25 04:52t/p180.101796.220.001796.2226.452809.10
372021.02.25 14:00sell190.101786.660.001774.05
382021.02.25 17:24t/p190.101774.050.001774.05126.102935.20
392021.02.25 22:15sell200.101771.510.001759.80
402021.02.26 07:39t/p200.101759.800.001759.80119.023054.21
412021.03.05 02:00sell210.101693.980.001684.40
422021.03.08 01:19close210.101708.980.001684.40-148.092906.12
432021.03.24 00:15sell220.101727.230.001725.33
442021.03.24 03:09t/p220.101725.330.001725.3319.002925.12
452021.03.29 17:30sell230.101707.730.001680.13
462021.03.30 15:39t/p230.101680.130.001680.13277.923203.04
472021.04.09 16:15sell240.101732.680.001711.65
482021.04.13 16:39close240.101747.680.001711.65-146.173056.87
492021.04.28 08:30sell250.101769.950.001767.06
502021.04.28 10:09t/p250.101767.060.001767.0628.903085.77
512021.05.04 23:15sell260.101779.150.001778.25
522021.05.05 01:09t/p260.101778.250.001778.2510.913096.68
532021.05.12 22:15sell270.101820.200.001814.22
542021.05.12 23:24t/p270.101814.220.001814.2259.803156.49
552021.06.03 17:00sell280.101867.560.001836.48
562021.06.03 23:15sell290.101870.990.001867.96
572021.06.04 04:46t/p290.101867.960.001867.9632.223188.70
582021.06.04 15:39close280.101882.560.001836.48-148.093040.62
592021.06.10 07:30sell300.101885.380.001881.69
602021.06.10 10:24t/p300.101881.690.001881.6936.903077.52
612021.06.10 14:15sell310.101878.470.001873.43
622021.06.10 15:01t/p310.101873.430.001873.4350.403127.92
632021.06.14 01:58sell320.101874.070.001872.72
642021.06.14 03:07t/p320.101872.720.001872.7213.503141.42
652021.06.14 09:45sell330.101860.600.001852.50
662021.06.14 15:07t/p330.101852.500.001852.5081.003222.42
672021.06.28 15:00sell340.101774.390.001767.54
682021.06.29 14:15t/p340.101767.540.001767.5470.423292.83
692021.06.29 14:30sell350.101766.840.001758.70
702021.06.29 15:39t/p350.101758.700.001758.7081.403374.23
712021.07.27 02:30sell360.101797.120.001795.91
722021.07.27 04:52t/p360.101795.910.001795.9112.103386.33
732021.08.02 02:45sell370.101812.650.001810.25
742021.08.02 04:37t/p370.101810.250.001810.2524.003410.33
752021.08.05 21:45sell380.101803.280.001798.02
762021.08.06 01:30sell390.101804.200.001803.39
772021.08.06 03:04t/p390.101803.390.001803.398.103418.43
782021.08.06 10:15t/p380.101798.020.001798.0254.523472.95
792021.08.06 23:15sell400.101760.350.001754.70
802021.08.09 01:24t/p400.101754.700.001754.7058.413531.36
812021.08.25 10:30sell410.101792.620.001785.48
822021.08.25 17:24t/p410.101785.480.001785.4871.403602.76
832021.09.07 17:15sell420.101800.260.001778.41
842021.09.10 08:34close420.101800.280.001778.419.383612.14
852021.09.17 20:45sell430.101750.470.001744.77
862021.09.20 05:24t/p430.101744.770.001744.7758.913671.05
872021.09.23 22:45sell440.101748.240.001742.87
882021.09.23 23:21t/p440.101742.870.001742.8753.703724.75
892021.10.15 19:30sell450.101768.100.001757.75
902021.10.15 22:30sell460.101768.170.001767.38
912021.10.15 23:24t/p460.101767.380.001767.387.903732.65
922021.10.19 10:48close450.101783.100.001757.75-146.173586.48
932021.10.26 17:00sell470.101789.760.001773.22
942021.10.28 15:21close470.101804.760.001773.22-142.343444.14
952021.11.03 04:00sell480.101783.060.001777.36
962021.11.03 07:30sell490.101781.540.001779.14
972021.11.03 08:16t/p490.101779.140.001779.1424.003468.14
982021.11.03 14:39t/p480.101777.360.001777.3657.003525.14
992021.11.19 01:45sell500.101858.430.001855.42
1002021.11.19 10:24t/p500.101855.420.001855.4230.103555.24
1012021.11.19 19:45sell510.101843.510.001819.38
1022021.11.22 16:24t/p510.101819.380.001819.38243.223798.45
1032021.11.22 17:30sell520.101814.950.001779.78
1042021.11.24 16:09t/p520.101779.780.001779.78355.534153.98
1052021.12.02 10:00sell530.101775.250.001769.99
1062021.12.02 10:24t/p530.101769.990.001769.9952.604206.59
1072021.12.09 15:00sell540.101776.180.001766.13
1082021.12.13 14:49close540.101791.180.001766.13-146.174060.41
1092021.12.20 17:00sell550.101791.570.001781.64
1102021.12.20 20:30sell560.101793.970.001791.36
1112021.12.20 21:52t/p560.101791.360.001791.3626.104086.51
1122021.12.22 22:30close550.101804.160.001781.64-122.073964.44
1132022.01.06 15:00sell570.101791.640.001778.65
1142022.01.10 20:30close570.101800.000.001778.65-79.773884.67
1152022.01.18 10:30sell580.101814.210.001808.80
1162022.01.18 15:09t/p580.101808.800.001808.8054.103938.77
1172022.01.27 03:54sell590.101815.180.001809.30
1182022.01.27 13:37t/p590.101809.300.001809.3058.803997.57
1192022.01.28 17:00sell600.101786.250.001779.25
1202022.02.01 07:19close600.101801.260.001779.25-146.273851.30
1212022.02.23 07:15sell610.101896.100.001890.40
1222022.02.23 10:45sell620.101894.500.001889.54
1232022.02.23 11:39t/p610.101890.400.001890.4057.003908.30
1242022.02.23 19:04close620.101909.500.001889.54-150.003758.30
1252022.03.14 16:15sell630.101954.460.001935.80
1262022.03.14 20:45sell640.101953.900.001942.16
1272022.03.15 03:23t/p640.101942.160.001942.16119.323877.62
1282022.03.15 07:04t/p630.101935.800.001935.80188.514066.13
1292022.03.15 12:15sell650.101929.500.001921.27
1302022.03.15 13:00t/p650.101921.270.001921.2782.304148.43
1312022.04.06 02:51sell660.101920.800.001917.88
1322022.04.06 04:01t/p660.101917.880.001917.8829.204177.63
1332022.04.21 18:15sell670.101944.300.001940.78
1342022.04.21 18:33t/p670.101940.780.001940.7835.204212.83
1352022.04.22 19:15sell680.101936.670.001930.70
1362022.04.22 21:30sell690.101933.750.001929.55
1372022.04.25 01:37t/p680.101930.700.001930.7061.624274.45
1382022.04.25 03:18t/p690.101929.550.001929.5543.914318.36
1392022.04.25 13:15sell700.101915.100.001909.24
1402022.04.25 13:58t/p700.101909.240.001909.2458.604376.96
1412022.05.09 18:00sell710.101860.370.001848.81
1422022.05.10 17:47t/p710.101848.810.001848.81117.524494.48
1432022.05.10 22:30sell720.101841.470.001833.64
1442022.05.11 02:53t/p720.101833.640.001833.6480.224574.69
1452022.05.13 01:30sell730.101819.570.001813.17
1462022.05.13 01:33t/p730.101813.170.001813.1764.004638.69
1472022.05.31 18:30sell740.101840.860.001825.53
1482022.05.31 22:00sell750.101840.650.001832.73
1492022.06.01 07:48t/p750.101832.730.001832.7381.124719.81
1502022.06.02 13:21close740.101855.880.001825.53-142.544577.27
1512022.06.06 18:15sell760.101843.240.001831.57
1522022.06.08 18:06close760.101858.240.001831.57-146.174431.10
1532022.06.13 21:31sell770.101826.480.001820.66
1542022.06.13 22:18t/p770.101820.660.001820.6658.204489.30
1552022.06.22 02:30sell780.101830.550.001827.37
1562022.06.22 03:39t/p780.101827.370.001827.3731.804521.10
1572022.06.22 08:00sell790.101825.550.001818.68
1582022.06.22 14:09close790.101840.560.001818.68-150.104371.00
1592022.06.24 05:00sell800.101823.760.001821.83
1602022.06.24 09:48t/p800.101821.830.001821.8319.304390.30
1612022.06.29 02:00sell810.101819.490.001817.69
1622022.06.29 09:37t/p810.101817.690.001817.6918.004408.30
1632022.07.06 01:05sell820.101766.830.001765.11
1642022.07.06 08:37t/p820.101765.110.001765.1117.204425.50
1652022.07.06 18:15sell830.101737.520.001697.74
1662022.07.07 01:45sell840.101738.940.001736.45
1672022.07.07 21:30sell850.101740.140.001736.17
1682022.07.08 10:39t/p840.101736.450.001736.4526.814452.31
1692022.07.08 10:39t/p850.101736.170.001736.1741.624493.93
1702022.07.08 17:47close830.101752.520.001697.74-142.344351.59
1712022.07.13 03:15sell860.101724.330.001721.62
1722022.07.13 15:31t/p860.101721.620.001721.6227.104378.69
1732022.07.26 22:00sell870.101716.990.001713.68
1742022.07.27 16:55t/p870.101713.680.001713.6835.024413.70
1752022.08.15 18:00sell880.101778.820.001774.55
1762022.08.16 11:13t/p880.101774.550.001774.5544.624458.32
1772022.08.17 17:45sell890.101766.350.001755.96
1782022.08.17 23:45sell900.101762.750.001756.66
1792022.08.18 20:03t/p900.101756.660.001756.6666.644524.96
1802022.08.18 20:13t/p890.101755.960.001755.96109.654634.61
1812022.08.19 01:30sell910.101757.740.001755.12
1822022.08.19 03:38t/p910.101755.120.001755.1226.204660.81
1832022.08.19 21:30sell920.101748.960.001747.36
1842022.08.19 21:57t/p920.101747.360.001747.3616.004676.81
1852022.08.22 03:00sell930.101745.490.001741.80
1862022.08.22 10:02t/p930.101741.800.001741.8036.904713.71
1872022.08.22 15:00sell940.101733.070.001728.18
1882022.08.22 15:46t/p940.101728.180.001728.1848.904762.61
1892022.08.26 23:15sell950.101737.430.001736.52
1902022.08.29 01:05t/p950.101736.520.001736.5211.024773.62
1912022.08.29 02:15sell960.101735.270.001730.05
1922022.08.29 04:18t/p960.101730.050.001730.0552.204825.82
1932022.08.29 10:45sell970.101720.470.001712.78
1942022.08.29 15:51close970.101735.470.001712.78-150.004675.82
1952022.08.31 16:30sell980.101711.710.001705.47
1962022.09.01 04:13t/p980.101705.470.001705.4768.144743.97
1972022.09.01 08:00sell990.101702.760.001697.87
1982022.09.01 15:42t/p990.101697.870.001697.8748.904792.87
1992022.09.13 19:15sell1000.101703.670.001698.42
2002022.09.14 04:21t/p1000.101698.420.001698.4254.414847.28
2012022.09.15 04:00sell1010.101695.360.001691.36
2022022.09.15 06:02t/p1010.101691.360.001691.3640.004887.28
2032022.09.15 14:15sell1020.101684.980.001675.74
2042022.09.15 17:50t/p1020.101675.740.001675.7492.404979.68
2052022.09.15 22:15sell1030.101662.930.001656.57
2062022.09.16 02:15sell1040.101662.860.001660.10
2072022.09.16 09:33t/p1040.101660.100.001660.1027.605007.28
2082022.09.16 10:52t/p1030.101656.570.001656.5765.525072.80
2092022.09.22 09:45sell1050.101658.320.001650.51
2102022.09.22 11:17close1050.101673.330.001650.51-150.104922.70
2112022.09.23 18:00sell1060.101643.300.001628.59
2122022.09.23 21:15sell1070.101643.750.001637.05
2132022.09.26 03:55t/p1070.101637.050.001637.0568.924991.61
2142022.09.26 03:58t/p1060.101628.590.001628.59149.015140.63
2152022.09.26 23:45sell1080.101621.840.001612.14
2162022.09.27 09:23close1080.101636.840.001612.14-148.094992.54
2172022.09.28 03:15sell1090.101629.530.001628.51
2182022.09.28 03:32t/p1090.101628.510.001628.5110.205002.74
2192022.10.19 18:45sell1100.101631.310.001621.95
2202022.10.21 06:43t/p1100.101621.950.001621.95101.265104.00
2212022.10.28 15:47sell1110.101644.000.001634.01
2222022.10.31 15:30t/p1110.101634.010.001634.01101.825205.82
2232022.11.01 02:15sell1120.101631.870.001629.43
2242022.11.01 08:57close1120.101646.880.001629.43-150.105055.72
2252022.11.03 16:00sell1130.101619.240.001612.94
2262022.11.04 03:58close1130.101634.250.001612.94-148.194907.53
2272022.11.21 03:30sell1140.101745.070.001733.52
2282022.11.21 18:53t/p1140.101733.520.001733.52115.505023.03
2292022.12.15 10:15sell1150.101782.220.001761.51
2302022.12.15 15:30sell1160.101774.400.001766.02
2312022.12.16 16:53close1160.101789.400.001766.02-148.094874.95
2322022.12.19 05:11close1150.101797.220.001761.51-146.174728.78
2332023.01.05 22:45sell1170.101833.790.001831.47
2342023.01.06 15:42close1170.101848.790.001831.47-148.094580.69
2352023.01.17 09:00sell1180.101906.990.001899.81
2362023.01.17 12:00sell1190.101906.380.001899.56
2372023.01.18 05:40t/p1180.101899.810.001899.8173.724654.41
2382023.01.18 05:41t/p1190.101899.560.001899.5670.124724.52
2392023.02.10 05:00sell1200.101859.730.001853.61
2402023.02.10 07:12t/p1200.101853.610.001853.6161.204785.72
2412023.02.13 23:00sell1210.101854.060.001853.76
2422023.02.13 23:33t/p1210.101853.760.001853.763.004788.72
2432023.02.23 03:00sell1220.101824.280.001821.66
2442023.02.23 15:33t/p1220.101821.660.001821.6626.204814.92
2452023.02.24 14:15sell1230.101817.100.001808.45
2462023.02.24 20:15sell1240.101809.770.001804.12
2472023.02.27 05:40t/p1230.101808.450.001808.4588.424903.34
2482023.02.28 17:03close1240.101824.770.001804.12-146.174757.17
2492023.04.03 05:45sell1250.101956.480.001944.75
2502023.04.03 13:43close1250.101971.490.001944.75-150.104607.07
2512023.04.17 01:15sell1260.102002.520.001996.13
2522023.04.17 04:11t/p1260.101996.130.001996.1363.904670.97
2532023.04.18 01:30sell1270.101993.970.001990.58
2542023.04.18 17:09close1270.102008.990.001990.58-150.204520.77
2552023.04.21 15:15sell1280.101983.310.001971.73
2562023.04.21 16:39close1280.101998.310.001971.73-150.004370.77
2572023.04.28 15:30sell1290.101980.640.001974.58
2582023.05.01 09:15sell1300.101981.460.001976.42
2592023.05.01 15:23close1290.101995.640.001974.58-148.094222.68
2602023.05.01 15:23close1300.101996.460.001976.42-150.004072.68
2612023.05.17 16:00sell1310.101984.710.001979.03
2622023.05.17 16:56t/p1310.101979.030.001979.0356.804129.48
2632023.05.18 15:00sell1320.101973.960.001967.99
2642023.05.18 15:33t/p1320.101967.990.001967.9959.704189.18
2652023.05.18 16:30sell1330.101959.750.001936.53
2662023.05.18 23:15sell1340.101957.230.001956.86
2672023.05.19 04:22t/p1340.101956.860.001956.865.624194.80
2682023.05.19 18:17close1330.101974.770.001936.53-148.284046.51
2692023.05.23 09:00sell1350.101960.850.001955.81
2702023.05.23 10:28t/p1350.101955.810.001955.8150.404096.91
2712023.05.23 13:45sell1360.101955.890.001949.59
2722023.05.23 16:47close1360.101970.910.001949.59-150.203946.71
2732023.05.25 04:00sell1370.101959.150.001958.01
2742023.05.25 04:08t/p1370.101958.010.001958.0111.403958.11
2752023.06.05 03:30sell1380.101947.180.001943.28
2762023.06.05 08:18t/p1380.101943.280.001943.2839.003997.11
2772023.06.07 22:30sell1390.101941.790.001937.49
2782023.06.08 15:38close1390.101956.790.001937.49-144.253852.86
2792023.06.15 08:15sell1400.101931.360.001924.67
2802023.06.15 10:30sell1410.101933.280.001926.98
2812023.06.15 15:28t/p1410.101926.980.001926.9863.003915.86
2822023.06.15 16:43close1400.101946.380.001924.67-150.203765.66
2832023.06.20 23:15sell1420.101935.890.001932.07
2842023.06.21 09:05t/p1420.101932.070.001932.0740.123805.77
2852023.06.22 15:15sell1430.101925.870.001920.29
2862023.06.22 16:09t/p1430.101920.290.001920.2955.803861.57
2872023.06.22 17:30sell1440.101916.120.001899.52
2882023.06.23 16:06close1440.101931.130.001899.52-148.193713.39
+
diff --git a/Docs/Reports/Tests/XTPW/In Test/StrategyTester 3.gif b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 3.gif new file mode 100644 index 0000000..69684cd Binary files /dev/null and b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 3.gif differ diff --git a/Docs/Reports/Tests/XTPW/In Test/StrategyTester 3.htm b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 3.htm new file mode 100644 index 0000000..5d27c1f --- /dev/null +++ b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 3.htm @@ -0,0 +1,359 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.06.28 23:45 (2020.01.01 - 2023.06.29)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=6; allowTrade=true; +allowLongTrades=false; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.0001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xR2R=2.5; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xrR2R=2; xRMaximumCandlesPerTrade=252; xrOscillatorLength=7; xrFastLength=20; xrSlowLength=50; xrRangeMarketLength=50; xrSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWR2R=1.5; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=700;
Bars in test61155Ticks modelled69617088Modelling quality40.15%
Mismatched charts errors30
Initial deposit1000.00SpreadCurrent (50)
Total net profit3492.92Gross profit7525.28Gross loss-4032.36
Profit factor1.87Expected payoff24.09
Absolute drawdown53.20Maximal drawdown1011.44 (18.56%)Relative drawdown21.55% (321.80)
Total trades145Short positions (won %)145 (71.72%)Long positions (won %)0 (0.00%)
Profit trades (% of total)104 (71.72%)Loss trades (% of total)41 (28.28%)
Largestprofit trade355.53loss trade-100.10
Averageprofit trade72.36loss trade-98.35
Maximumconsecutive wins (profit in money)16 (692.04)consecutive losses (loss in money)4 (-400.20)
Maximalconsecutive profit (count of wins)1140.36 (5)consecutive loss (count of losses)-400.20 (4)
Averageconsecutive wins4consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 15:15sell10.101793.480.001772.09
22020.11.30 02:30sell20.101783.130.001773.23
32020.11.30 04:51t/p20.101773.230.001773.2399.001099.00
42020.11.30 04:51t/p10.101772.090.001772.09215.811314.82
52021.01.08 11:00sell30.101888.710.001857.17
62021.01.08 15:15sell40.101882.460.001865.86
72021.01.08 16:01close40.101892.460.001865.86-100.001214.82
82021.01.08 16:45sell50.101871.560.001840.06
92021.01.08 17:09t/p30.101857.170.001857.17315.401530.22
102021.01.08 18:15sell60.101854.120.001827.81
112021.01.08 19:33t/p50.101840.060.001840.06315.001845.22
122021.01.11 02:30sell70.101842.650.001823.57
132021.01.11 03:21t/p60.101827.810.001827.81265.022110.23
142021.01.11 03:24t/p70.101823.570.001823.57190.802301.03
152021.01.27 17:06sell80.101841.520.001836.68
162021.01.28 03:24t/p80.101836.680.001836.6854.142355.18
172021.01.28 08:15sell90.101835.080.001828.99
182021.01.28 15:39close90.101845.080.001828.99-100.002255.18
192021.02.02 13:45sell100.101845.320.001834.90
202021.02.02 15:22t/p100.101834.900.001834.90104.202359.38
212021.02.02 20:45sell110.101835.300.001831.00
222021.02.03 17:39t/p110.101831.000.001831.0044.912404.29
232021.02.04 03:15sell120.101832.970.001830.68
242021.02.04 03:45t/p120.101830.680.001830.6822.902427.19
252021.02.04 11:30sell130.101815.010.001798.05
262021.02.04 16:09t/p130.101798.050.001798.05169.602596.79
272021.02.12 03:00sell140.101823.920.001818.13
282021.02.12 09:54t/p140.101818.130.001818.1357.902654.69
292021.02.16 19:45sell150.101797.010.001776.58
302021.02.17 15:39t/p150.101776.580.001776.58206.222860.91
312021.02.17 21:15sell160.101774.560.001766.84
322021.02.18 05:06close160.101784.560.001766.84-94.252766.65
332021.02.19 02:15sell170.101770.450.001760.93
342021.02.19 15:52close170.101780.460.001760.93-100.102666.55
352021.02.24 21:30sell180.101798.290.001796.22
362021.02.25 04:52t/p180.101796.220.001796.2226.452693.00
372021.02.25 14:00sell190.101786.660.001774.05
382021.02.25 17:24t/p190.101774.050.001774.05126.102819.10
392021.02.25 22:15sell200.101771.510.001759.80
402021.02.26 07:39t/p200.101759.800.001759.80119.022938.11
412021.03.05 02:00sell210.101693.980.001684.40
422021.03.05 16:21close210.101703.980.001684.40-100.002838.11
432021.03.24 00:15sell220.101727.230.001725.33
442021.03.24 03:09t/p220.101725.330.001725.3319.002857.11
452021.03.29 17:30sell230.101707.730.001680.13
462021.03.30 15:39t/p230.101680.130.001680.13277.923135.03
472021.04.09 16:15sell240.101732.680.001711.65
482021.04.09 17:22close240.101742.680.001711.65-100.003035.03
492021.04.28 08:30sell250.101769.950.001767.06
502021.04.28 10:09t/p250.101767.060.001767.0628.903063.93
512021.05.04 23:15sell260.101779.150.001778.25
522021.05.05 01:09t/p260.101778.250.001778.2510.913074.84
532021.05.12 22:15sell270.101820.200.001814.22
542021.05.12 23:24t/p270.101814.220.001814.2259.803134.64
552021.06.03 17:00sell280.101867.560.001836.48
562021.06.03 23:15sell290.101870.990.001867.96
572021.06.04 04:46t/p290.101867.960.001867.9632.223166.86
582021.06.04 15:36close280.101877.560.001836.48-98.083068.77
592021.06.10 07:30sell300.101885.380.001881.69
602021.06.10 10:24t/p300.101881.690.001881.6936.903105.67
612021.06.10 14:15sell310.101878.470.001873.43
622021.06.10 15:01t/p310.101873.430.001873.4350.403156.07
632021.06.14 01:58sell320.101874.070.001872.72
642021.06.14 03:07t/p320.101872.720.001872.7213.503169.57
652021.06.14 09:45sell330.101860.600.001852.50
662021.06.14 15:07t/p330.101852.500.001852.5081.003250.57
672021.06.28 15:00sell340.101774.390.001767.54
682021.06.29 14:15t/p340.101767.540.001767.5470.423320.99
692021.06.29 14:30sell350.101766.840.001758.70
702021.06.29 15:39t/p350.101758.700.001758.7081.403402.39
712021.07.27 02:30sell360.101797.120.001795.91
722021.07.27 04:52t/p360.101795.910.001795.9112.103414.49
732021.08.02 02:45sell370.101812.650.001810.25
742021.08.02 04:37t/p370.101810.250.001810.2524.003438.49
752021.08.05 21:45sell380.101803.280.001798.02
762021.08.06 01:30sell390.101804.200.001803.39
772021.08.06 03:04t/p390.101803.390.001803.398.103446.59
782021.08.06 10:15t/p380.101798.020.001798.0254.523501.10
792021.08.06 23:15sell400.101760.350.001754.70
802021.08.09 01:24t/p400.101754.700.001754.7058.413559.52
812021.08.25 10:30sell410.101792.620.001785.48
822021.08.25 17:24t/p410.101785.480.001785.4871.403630.92
832021.09.07 17:15sell420.101800.260.001778.41
842021.09.10 08:34close420.101800.280.001778.419.383640.29
852021.09.17 20:45sell430.101750.470.001744.77
862021.09.20 05:24t/p430.101744.770.001744.7758.913699.21
872021.09.23 22:45sell440.101748.240.001742.87
882021.09.23 23:21t/p440.101742.870.001742.8753.703752.91
892021.10.15 19:30sell450.101768.100.001757.75
902021.10.15 22:30sell460.101768.170.001767.38
912021.10.15 23:24t/p460.101767.380.001767.387.903760.81
922021.10.19 09:03close450.101778.100.001757.75-96.173664.64
932021.10.26 17:00sell470.101789.760.001773.22
942021.10.28 05:09close470.101799.760.001773.22-92.343572.30
952021.11.03 04:00sell480.101783.060.001777.36
962021.11.03 07:30sell490.101781.540.001779.14
972021.11.03 08:16t/p490.101779.140.001779.1424.003596.30
982021.11.03 14:39t/p480.101777.360.001777.3657.003653.30
992021.11.19 01:45sell500.101858.430.001855.42
1002021.11.19 10:24t/p500.101855.420.001855.4230.103683.39
1012021.11.19 19:45sell510.101843.510.001819.38
1022021.11.22 16:24t/p510.101819.380.001819.38243.223926.61
1032021.11.22 17:30sell520.101814.950.001779.78
1042021.11.24 16:09t/p520.101779.780.001779.78355.534282.14
1052021.12.02 10:00sell530.101775.250.001769.99
1062021.12.02 10:24t/p530.101769.990.001769.9952.604334.74
1072021.12.09 15:00sell540.101776.180.001766.13
1082021.12.10 16:04close540.101786.180.001766.13-98.084236.66
1092021.12.20 17:00sell550.101791.570.001781.64
1102021.12.20 20:30sell560.101793.970.001791.36
1112021.12.20 21:52t/p560.101791.360.001791.3626.104262.76
1122021.12.22 20:24close550.101801.570.001781.64-96.174166.59
1132022.01.06 15:00sell570.101791.640.001778.65
1142022.01.10 13:22close570.101801.640.001778.65-96.174070.42
1152022.01.18 10:30sell580.101814.210.001808.80
1162022.01.18 15:09t/p580.101808.800.001808.8054.104124.52
1172022.01.27 03:54sell590.101815.180.001809.30
1182022.01.27 13:37t/p590.101809.300.001809.3058.804183.32
1192022.01.28 17:00sell600.101786.250.001779.25
1202022.01.31 15:52close600.101796.250.001779.25-98.084085.23
1212022.02.23 07:15sell610.101896.100.001890.40
1222022.02.23 10:45sell620.101894.500.001889.54
1232022.02.23 11:39t/p610.101890.400.001890.4057.004142.23
1242022.02.23 15:24close620.101904.500.001889.54-100.004042.23
1252022.03.14 16:15sell630.101954.460.001935.80
1262022.03.14 20:45sell640.101953.900.001942.16
1272022.03.15 03:23t/p640.101942.160.001942.16119.324161.55
1282022.03.15 07:04t/p630.101935.800.001935.80188.514350.06
1292022.03.15 12:15sell650.101929.500.001921.27
1302022.03.15 13:00t/p650.101921.270.001921.2782.304432.36
1312022.04.06 02:51sell660.101920.800.001917.88
1322022.04.06 04:01t/p660.101917.880.001917.8829.204461.56
1332022.04.21 18:15sell670.101944.300.001940.78
1342022.04.21 18:33t/p670.101940.780.001940.7835.204496.76
1352022.04.22 19:15sell680.101936.670.001930.70
1362022.04.22 21:30sell690.101933.750.001929.55
1372022.04.25 01:37t/p680.101930.700.001930.7061.624558.38
1382022.04.25 03:18t/p690.101929.550.001929.5543.914602.29
1392022.04.25 13:15sell700.101915.100.001909.24
1402022.04.25 13:58t/p700.101909.240.001909.2458.604660.89
1412022.05.09 18:00sell710.101860.370.001848.81
1422022.05.10 17:47t/p710.101848.810.001848.81117.524778.41
1432022.05.10 22:30sell720.101841.470.001833.64
1442022.05.11 02:53t/p720.101833.640.001833.6480.224858.62
1452022.05.13 01:30sell730.101819.570.001813.17
1462022.05.13 01:33t/p730.101813.170.001813.1764.004922.62
1472022.05.31 18:30sell740.101840.860.001825.53
1482022.05.31 22:00sell750.101840.650.001832.73
1492022.06.01 07:48t/p750.101832.730.001832.7381.125003.74
1502022.06.02 09:23close740.101850.860.001825.53-92.344911.40
1512022.06.06 18:15sell760.101843.240.001831.57
1522022.06.07 16:53close760.101853.250.001831.57-98.184813.21
1532022.06.13 21:31sell770.101826.480.001820.66
1542022.06.13 22:18t/p770.101820.660.001820.6658.204871.41
1552022.06.22 02:30sell780.101830.550.001827.37
1562022.06.22 03:39t/p780.101827.370.001827.3731.804903.21
1572022.06.22 08:00sell790.101825.550.001818.68
1582022.06.22 14:04close790.101835.560.001818.68-100.104803.11
1592022.06.24 05:00sell800.101823.760.001821.83
1602022.06.24 09:48t/p800.101821.830.001821.8319.304822.41
1612022.06.29 02:00sell810.101819.490.001817.69
1622022.06.29 09:37t/p810.101817.690.001817.6918.004840.41
1632022.07.06 01:05sell820.101766.830.001765.11
1642022.07.06 08:37t/p820.101765.110.001765.1117.204857.61
1652022.07.06 18:15sell830.101737.520.001697.74
1662022.07.07 01:45sell840.101738.940.001736.45
1672022.07.07 08:37close830.101747.530.001697.74-94.354763.26
1682022.07.07 16:51close840.101748.940.001736.45-100.004663.26
1692022.07.07 21:30sell850.101740.140.001736.17
1702022.07.08 02:02sell860.101738.950.001737.03
1712022.07.08 10:39t/p860.101737.030.001737.0319.204682.46
1722022.07.08 10:39t/p850.101736.170.001736.1741.624724.07
1732022.07.13 03:15sell870.101724.330.001721.62
1742022.07.13 15:31t/p870.101721.620.001721.6227.104751.17
1752022.07.26 22:00sell880.101716.990.001713.68
1762022.07.27 16:55t/p880.101713.680.001713.6835.024786.19
1772022.08.15 18:00sell890.101778.820.001774.55
1782022.08.16 11:13t/p890.101774.550.001774.5544.624830.80
1792022.08.17 17:45sell900.101766.350.001755.96
1802022.08.17 23:45sell910.101762.750.001756.66
1812022.08.18 20:03t/p910.101756.660.001756.6666.644897.45
1822022.08.18 20:13t/p900.101755.960.001755.96109.655007.09
1832022.08.19 01:30sell920.101757.740.001755.12
1842022.08.19 03:38t/p920.101755.120.001755.1226.205033.29
1852022.08.19 21:30sell930.101748.960.001747.36
1862022.08.19 21:57t/p930.101747.360.001747.3616.005049.29
1872022.08.22 03:00sell940.101745.490.001741.80
1882022.08.22 10:02t/p940.101741.800.001741.8036.905086.19
1892022.08.22 15:00sell950.101733.070.001728.18
1902022.08.22 15:46t/p950.101728.180.001728.1848.905135.09
1912022.08.26 23:15sell960.101737.430.001736.52
1922022.08.29 01:05t/p960.101736.520.001736.5211.025146.11
1932022.08.29 02:15sell970.101735.270.001730.05
1942022.08.29 04:18t/p970.101730.050.001730.0552.205198.31
1952022.08.29 10:45sell980.101720.470.001712.78
1962022.08.29 15:22close980.101730.480.001712.78-100.105098.21
1972022.08.31 16:30sell990.101711.710.001705.47
1982022.08.31 17:28close990.101721.710.001705.47-100.004998.21
1992022.09.01 08:00sell1000.101702.760.001697.87
2002022.09.01 15:42t/p1000.101697.870.001697.8748.905047.11
2012022.09.13 19:15sell1010.101703.670.001698.42
2022022.09.14 04:21t/p1010.101698.420.001698.4254.415101.52
2032022.09.15 04:00sell1020.101695.360.001691.36
2042022.09.15 06:02t/p1020.101691.360.001691.3640.005141.52
2052022.09.15 14:15sell1030.101684.980.001675.74
2062022.09.15 17:50t/p1030.101675.740.001675.7492.405233.92
2072022.09.15 22:15sell1040.101662.930.001656.57
2082022.09.16 02:15sell1050.101662.860.001660.10
2092022.09.16 09:33t/p1050.101660.100.001660.1027.605261.52
2102022.09.16 10:52t/p1040.101656.570.001656.5765.525327.04
2112022.09.22 09:45sell1060.101658.320.001650.51
2122022.09.22 11:15close1060.101668.320.001650.51-100.005227.04
2132022.09.23 18:00sell1070.101643.300.001628.59
2142022.09.23 21:15sell1080.101643.750.001637.05
2152022.09.26 03:55t/p1080.101637.050.001637.0568.925295.95
2162022.09.26 03:58t/p1070.101628.590.001628.59149.015444.97
2172022.09.26 23:45sell1090.101621.840.001612.14
2182022.09.27 04:02close1090.101631.840.001612.14-98.085346.88
2192022.09.28 03:15sell1100.101629.530.001628.51
2202022.09.28 03:32t/p1100.101628.510.001628.5110.205357.08
2212022.10.19 18:45sell1110.101631.310.001621.95
2222022.10.20 17:21close1110.101641.310.001621.95-94.255262.83
2232022.10.28 15:47sell1120.101644.000.001634.01
2242022.10.31 15:30t/p1120.101634.010.001634.01101.825364.64
2252022.11.01 02:15sell1130.101631.870.001629.43
2262022.11.01 07:48close1130.101641.870.001629.43-100.005264.64
2272022.11.03 16:00sell1140.101619.240.001612.94
2282022.11.03 16:51close1140.101629.240.001612.94-100.005164.64
2292022.11.21 03:30sell1150.101745.070.001733.52
2302022.11.21 18:53t/p1150.101733.520.001733.52115.505280.14
2312022.12.15 10:15sell1160.101782.220.001761.51
2322022.12.15 15:30sell1170.101774.400.001766.02
2332022.12.15 16:22close1170.101784.400.001766.02-100.005180.14
2342022.12.16 16:57close1160.101792.230.001761.51-98.185081.95
2352023.01.05 22:45sell1180.101833.790.001831.47
2362023.01.06 15:33close1180.101843.800.001831.47-98.184983.77
2372023.01.17 09:00sell1190.101906.990.001899.81
2382023.01.17 12:00sell1200.101906.380.001899.56
2392023.01.17 16:12close1200.101916.380.001899.56-100.004883.77
2402023.01.18 05:40t/p1190.101899.810.001899.8173.724957.48
2412023.02.10 05:00sell1210.101859.730.001853.61
2422023.02.10 07:12t/p1210.101853.610.001853.6161.205018.68
2432023.02.13 23:00sell1220.101854.060.001853.76
2442023.02.13 23:33t/p1220.101853.760.001853.763.005021.68
2452023.02.23 03:00sell1230.101824.280.001821.66
2462023.02.23 15:33t/p1230.101821.660.001821.6626.205047.88
2472023.02.24 14:15sell1240.101817.100.001808.45
2482023.02.24 20:15sell1250.101809.770.001804.12
2492023.02.27 05:40t/p1240.101808.450.001808.4588.425136.30
2502023.02.27 17:03close1250.101819.770.001804.12-98.085038.21
2512023.04.03 05:45sell1260.101956.480.001944.75
2522023.04.03 11:53close1260.101966.490.001944.75-100.104938.11
2532023.04.17 01:15sell1270.102002.520.001996.13
2542023.04.17 04:11t/p1270.101996.130.001996.1363.905002.01
2552023.04.18 01:30sell1280.101993.970.001990.58
2562023.04.18 10:36close1280.102003.980.001990.58-100.104901.91
2572023.04.21 15:15sell1290.101983.310.001971.73
2582023.04.21 16:18close1290.101993.320.001971.73-100.104801.81
2592023.04.28 15:30sell1300.101980.640.001974.58
2602023.04.28 17:38close1300.101990.640.001974.58-100.004701.81
2612023.05.01 09:15sell1310.101981.460.001976.42
2622023.05.01 15:14close1310.101991.460.001976.42-100.004601.81
2632023.05.17 16:00sell1320.101984.710.001979.03
2642023.05.17 16:56t/p1320.101979.030.001979.0356.804658.61
2652023.05.18 15:00sell1330.101973.960.001967.99
2662023.05.18 15:33t/p1330.101967.990.001967.9959.704718.31
2672023.05.18 16:30sell1340.101959.750.001936.53
2682023.05.18 23:15sell1350.101957.230.001956.86
2692023.05.19 04:22t/p1350.101956.860.001956.865.624723.93
2702023.05.19 18:15close1340.101969.760.001936.53-98.184625.74
2712023.05.23 09:00sell1360.101960.850.001955.81
2722023.05.23 10:28t/p1360.101955.810.001955.8150.404676.14
2732023.05.23 13:45sell1370.101955.890.001949.59
2742023.05.23 16:17close1370.101965.900.001949.59-100.104576.04
2752023.05.25 04:00sell1380.101959.150.001958.01
2762023.05.25 04:08t/p1380.101958.010.001958.0111.404587.44
2772023.06.05 03:30sell1390.101947.180.001943.28
2782023.06.05 08:18t/p1390.101943.280.001943.2839.004626.44
2792023.06.07 22:30sell1400.101941.790.001937.49
2802023.06.08 15:30close1400.101951.790.001937.49-94.254532.19
2812023.06.15 08:15sell1410.101931.360.001924.67
2822023.06.15 10:30sell1420.101933.280.001926.98
2832023.06.15 15:28t/p1420.101926.980.001926.9863.004595.19
2842023.06.15 16:26close1410.101941.370.001924.67-100.104495.09
2852023.06.20 23:15sell1430.101935.890.001932.07
2862023.06.21 09:05t/p1430.101932.070.001932.0740.124535.20
2872023.06.22 15:15sell1440.101925.870.001920.29
2882023.06.22 16:09t/p1440.101920.290.001920.2955.804591.00
2892023.06.22 17:30sell1450.101916.120.001899.52
2902023.06.23 15:47close1450.101926.120.001899.52-98.084492.92
+
diff --git a/Docs/Reports/Tests/XTPW/In Test/StrategyTester 4.gif b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 4.gif new file mode 100644 index 0000000..74f9b49 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 4.gif differ diff --git a/Docs/Reports/Tests/XTPW/In Test/StrategyTester 4.htm b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 4.htm new file mode 100644 index 0000000..a11115b --- /dev/null +++ b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 4.htm @@ -0,0 +1,111 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.04.29 23:45 (2020.01.01 - 2021.04.30)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=6; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.01; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xR2R=2.5; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xrR2R=2; xRMaximumCandlesPerTrade=252; xrOscillatorLength=7; xrFastLength=20; xrSlowLength=50; xrRangeMarketLength=50; xrSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWR2R=1.5; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=700;
Bars in test9971Ticks modelled11845786Modelling quality24.76%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (56)
Total net profit8.71Gross profit110.01Gross loss-101.30
Profit factor1.09Expected payoff0.41
Absolute drawdown21.07Maximal drawdown82.19 (7.75%)Relative drawdown7.75% (82.19)
Total trades21Short positions (won %)0 (0.00%)Long positions (won %)21 (52.38%)
Profit trades (% of total)11 (52.38%)Loss trades (% of total)10 (47.62%)
Largestprofit trade14.87loss trade-11.30
Averageprofit trade10.00loss trade-10.13
Maximumconsecutive wins (profit in money)5 (56.63)consecutive losses (loss in money)7 (-71.30)
Maximalconsecutive profit (count of wins)56.63 (5)consecutive loss (count of losses)-71.30 (7)
Averageconsecutive wins3consecutive losses3
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 16:16buy10.011847.830.001863.25
22020.12.04 17:09close10.011837.830.001863.25-10.00990.00
32020.12.08 10:33buy20.011867.410.001873.98
42020.12.08 16:39t/p20.011873.980.001873.986.57996.57
52020.12.16 10:45buy30.011860.720.001871.43
62020.12.16 15:22close30.011850.720.001871.43-10.00986.57
72020.12.16 21:49buy40.011857.510.001873.44
82020.12.17 09:39t/p40.011873.440.001873.4414.631001.20
92020.12.24 16:52buy50.011876.490.001883.23
102020.12.28 01:00t/p50.011883.230.001883.235.881007.08
112021.01.08 16:00buy60.011891.260.001912.92
122021.01.08 16:36close60.011881.260.001912.92-10.00997.08
132021.01.11 16:45buy70.011839.580.001854.88
142021.01.12 07:36t/p70.011854.880.001854.8814.871011.95
152021.01.12 20:15buy80.011844.180.001853.53
162021.01.12 21:24t/p80.011853.530.001853.539.351021.30
172021.01.14 10:00buy90.011842.170.001850.63
182021.01.14 16:30t/p90.011850.630.001850.638.461029.76
192021.02.05 15:45buy100.011803.570.001818.12
202021.02.08 01:09t/p100.011818.120.001818.1214.121043.88
212021.02.10 15:15buy110.011844.680.001854.51
222021.02.10 15:39t/p110.011854.510.001854.519.831053.71
232021.02.16 17:15buy120.011806.790.001832.11
242021.02.16 18:54close120.011796.790.001832.11-10.001043.71
252021.02.24 12:45buy130.011808.580.001816.34
262021.02.24 15:39close130.011798.580.001816.34-10.001033.71
272021.02.25 16:45buy140.011786.940.001799.20
282021.02.25 17:07close140.011776.940.001799.20-10.001023.71
292021.02.26 12:45buy150.011767.160.001774.12
302021.02.26 16:37close150.011757.160.001774.12-10.001013.71
312021.03.03 18:04buy160.011718.110.001739.20
322021.03.04 01:33close160.011708.110.001739.20-11.301002.41
332021.03.04 12:00buy170.011715.570.001729.07
342021.03.04 19:24close170.011705.570.001729.07-10.00992.41
352021.03.11 15:00buy180.011736.230.001744.48
362021.03.11 16:22close180.011726.230.001744.48-10.00982.41
372021.03.31 15:45buy190.011689.230.001699.06
382021.03.31 17:18t/p190.011699.060.001699.069.83992.24
392021.04.13 14:15buy200.011730.150.001737.89
402021.04.13 15:39t/p200.011737.890.001737.897.74999.98
412021.04.15 15:15buy210.011750.780.001759.51
422021.04.15 17:06t/p210.011759.510.001759.518.731008.71
+
diff --git a/Docs/Reports/Tests/XTPW/In Test/StrategyTester 5.gif b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 5.gif new file mode 100644 index 0000000..d83c688 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 5.gif differ diff --git a/Docs/Reports/Tests/XTPW/In Test/StrategyTester 5.htm b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 5.htm new file mode 100644 index 0000000..f8de3e0 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 5.htm @@ -0,0 +1,443 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.04.29 23:45 (2020.01.01 - 2021.04.30)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=6; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.01; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xR2R=2.5; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xrR2R=2; xRMaximumCandlesPerTrade=252; xrOscillatorLength=7; xrFastLength=20; xrSlowLength=50; xrRangeMarketLength=50; xrSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWR2R=1.5; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=700;
Bars in test9971Ticks modelled11845786Modelling quality24.76%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (51)
Total net profit-306.00Gross profit601.23Gross loss-907.24
Profit factor0.66Expected payoff-1.64
Absolute drawdown321.14Maximal drawdown390.59 (36.52%)Relative drawdown36.52% (390.59)
Total trades187Short positions (won %)0 (0.00%)Long positions (won %)187 (51.87%)
Profit trades (% of total)97 (51.87%)Loss trades (% of total)90 (48.13%)
Largestprofit trade30.74loss trade-11.76
Averageprofit trade6.20loss trade-10.08
Maximumconsecutive wins (profit in money)12 (96.08)consecutive losses (loss in money)12 (-123.06)
Maximalconsecutive profit (count of wins)96.08 (12)consecutive loss (count of losses)-123.06 (12)
Averageconsecutive wins3consecutive losses3
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 02:09buy10.011810.440.001811.73
22020.11.27 02:25t/p10.011811.730.001811.731.291001.29
32020.11.27 03:30buy20.011811.060.001814.56
42020.11.27 10:00buy30.011810.750.001815.55
52020.11.27 15:06close20.011801.060.001814.56-10.00991.29
62020.11.27 15:06close30.011800.750.001815.55-10.00981.29
72020.11.27 18:45buy40.011786.120.001794.93
82020.11.30 04:46close40.011776.120.001794.93-10.43970.86
92020.11.30 09:06buy50.011776.090.001788.74
102020.11.30 12:54close50.011766.070.001788.74-10.02960.84
112020.11.30 16:30buy60.011777.020.001791.89
122020.11.30 18:31buy70.011780.130.001793.69
132020.12.01 03:09buy80.011780.300.001784.10
142020.12.01 04:30buy90.011781.750.001787.41
152020.12.01 05:21t/p80.011784.100.001784.103.80964.64
162020.12.01 06:00buy100.011784.870.001790.09
172020.12.01 07:54t/p90.011787.410.001787.415.66970.30
182020.12.01 07:54buy110.011788.060.001791.06
192020.12.01 09:51t/p100.011790.090.001790.095.22975.52
202020.12.01 09:54t/p110.011791.060.001791.063.00978.52
212020.12.01 10:06t/p60.011791.890.001791.8914.44992.96
222020.12.01 10:09t/p70.011793.690.001793.6913.131006.08
232020.12.01 10:51buy120.011793.660.001801.97
242020.12.01 12:24buy130.011798.150.001804.09
252020.12.01 13:01t/p120.011801.970.001801.978.311014.39
262020.12.01 13:04t/p130.011804.090.001804.095.941020.33
272020.12.01 13:45buy140.011805.830.001821.94
282020.12.01 15:52buy150.011811.350.001818.34
292020.12.01 20:07buy160.011815.240.001821.95
302020.12.02 08:54buy170.011813.760.001821.83
312020.12.02 10:34t/p150.011818.340.001818.346.561026.89
322020.12.02 10:37t/p170.011821.830.001821.838.071034.96
332020.12.02 10:37t/p140.011821.940.001821.9415.681050.64
342020.12.02 10:37t/p160.011821.950.001821.956.281056.92
352020.12.02 12:00buy180.011825.320.001837.29
362020.12.02 13:30buy190.011829.210.001836.56
372020.12.02 14:45close190.011819.210.001836.56-10.001046.92
382020.12.02 15:52close180.011815.320.001837.29-10.001036.92
392020.12.02 18:00buy200.011826.780.001845.77
402020.12.02 21:39buy210.011830.220.001835.23
412020.12.03 01:37buy220.011831.390.001833.90
422020.12.03 05:22t/p220.011833.900.001833.902.511039.43
432020.12.03 05:24t/p210.011835.230.001835.233.711043.14
442020.12.03 05:30buy230.011835.100.001847.61
452020.12.03 10:00buy240.011842.740.001860.47
462020.12.03 14:00buy250.011842.780.001854.24
472020.12.03 16:49close250.011832.780.001854.24-10.001033.14
482020.12.03 16:49close240.011832.740.001860.47-10.001023.14
492020.12.03 18:09close230.011825.090.001847.61-10.011013.13
502020.12.03 20:15buy260.011839.010.001851.48
512020.12.03 21:54buy270.011840.490.001847.41
522020.12.04 05:15buy280.011843.550.001851.40
532020.12.04 15:31t/p200.011845.770.001845.7717.261030.40
542020.12.04 15:33t/p270.011847.410.001847.416.491036.89
552020.12.04 15:39close280.011833.540.001851.40-10.011026.88
562020.12.04 16:45buy290.011846.380.001866.11
572020.12.04 17:21close290.011836.380.001866.11-10.001016.88
582020.12.04 17:54close260.011829.010.001851.48-10.431006.44
592020.12.04 21:24buy300.011837.090.001839.27
602020.12.07 01:03buy310.011838.260.001840.35
612020.12.07 03:30buy320.011837.430.001841.09
622020.12.07 05:03t/p300.011839.270.001839.271.751008.19
632020.12.07 06:15buy330.011839.640.001844.52
642020.12.07 07:24t/p310.011840.350.001840.352.091010.28
652020.12.07 07:49t/p320.011841.090.001841.093.661013.94
662020.12.07 07:51buy340.011841.920.001848.45
672020.12.07 10:30close340.011831.920.001848.45-10.001003.94
682020.12.07 10:31close330.011829.630.001844.52-10.01993.93
692020.12.07 15:30buy350.011835.000.001843.33
702020.12.07 16:36t/p350.011843.330.001843.338.331002.26
712020.12.07 18:30buy360.011866.190.001879.98
722020.12.08 15:30buy370.011865.640.001871.60
732020.12.08 15:46t/p370.011871.600.001871.605.961008.22
742020.12.08 17:00buy380.011870.460.001879.15
752020.12.08 19:52buy390.011873.330.001882.39
762020.12.09 05:22close390.011863.330.001882.39-10.43997.79
772020.12.09 05:39close380.011860.450.001879.15-10.44987.35
782020.12.09 06:07close360.011856.190.001879.98-10.86976.49
792020.12.09 08:30buy400.011863.150.001870.85
802020.12.09 11:00buy410.011864.960.001874.88
812020.12.09 13:39close410.011854.950.001874.88-10.01966.48
822020.12.09 13:39close400.011853.150.001870.85-10.00956.48
832020.12.09 15:45buy420.011861.950.001871.84
842020.12.09 16:30close420.011851.950.001871.84-10.00946.48
852020.12.09 23:24buy430.011839.400.001850.02
862020.12.10 11:09close430.011829.390.001850.02-11.31935.17
872020.12.10 15:34buy440.011841.850.001850.34
882020.12.10 17:00buy450.011848.090.001862.46
892020.12.10 17:39close450.011838.090.001862.46-10.00925.17
902020.12.10 18:16close440.011831.840.001850.34-10.01915.16
912020.12.11 02:08buy460.011839.630.001842.11
922020.12.11 03:37buy470.011839.750.001843.56
932020.12.11 12:15buy480.011837.330.001845.70
942020.12.11 13:04close470.011829.750.001843.56-10.00905.16
952020.12.11 13:04close460.011829.630.001842.11-10.00895.16
962020.12.11 13:21close480.011827.330.001845.70-10.00885.16
972020.12.11 15:30buy490.011836.350.001844.41
982020.12.11 17:00buy500.011841.550.001851.09
992020.12.11 17:09t/p490.011844.410.001844.418.06893.22
1002020.12.11 18:30buy510.011844.760.001852.85
1012020.12.14 03:09close510.011834.760.001852.85-10.43882.79
1022020.12.14 10:19close500.011831.540.001851.09-10.44872.35
1032020.12.14 16:00buy520.011833.090.001848.96
1042020.12.14 18:39close520.011823.090.001848.96-10.00862.35
1052020.12.15 04:15buy530.011831.990.001841.29
1062020.12.15 07:34buy540.011837.510.001839.57
1072020.12.15 07:45t/p540.011839.570.001839.572.06864.41
1082020.12.15 09:00buy550.011840.410.001847.70
1092020.12.15 09:07t/p530.011841.290.001841.299.30873.71
1102020.12.15 10:30buy560.011843.850.001849.61
1112020.12.15 12:09buy570.011847.580.001851.23
1122020.12.15 14:24t/p550.011847.700.001847.707.29881.00
1132020.12.15 15:08t/p560.011849.610.001849.615.76886.76
1142020.12.15 15:15buy580.011849.690.001860.15
1152020.12.15 15:31t/p570.011851.230.001851.233.65890.41
1162020.12.15 21:09buy590.011853.210.001858.03
1172020.12.16 04:37buy600.011857.600.001862.48
1182020.12.16 04:46t/p590.011858.030.001858.034.39894.80
1192020.12.16 10:39t/p580.011860.150.001860.1510.03904.82
1202020.12.16 11:00buy610.011862.080.001874.91
1212020.12.16 11:19t/p600.011862.480.001862.484.88909.70
1222020.12.16 12:37buy620.011863.200.001864.96
1232020.12.16 13:15t/p620.011864.960.001864.961.76911.46
1242020.12.16 15:22close610.011852.080.001874.91-10.00901.46
1252020.12.16 23:30buy630.011863.700.001868.61
1262020.12.17 03:30buy640.011866.400.001871.70
1272020.12.17 06:39buy650.011868.410.001873.65
1282020.12.17 07:51t/p630.011868.610.001868.613.61905.08
1292020.12.17 08:03buy660.011870.640.001875.74
1302020.12.17 09:09t/p640.011871.700.001871.705.30910.38
1312020.12.17 09:36buy670.011872.780.001877.58
1322020.12.17 09:39t/p650.011873.650.001873.655.24915.62
1332020.12.17 10:19t/p660.011875.740.001875.745.10920.72
1342020.12.17 10:22t/p670.011877.580.001877.584.80925.52
1352020.12.17 11:00buy680.011879.030.001891.30
1362020.12.17 14:34buy690.011879.450.001884.46
1372020.12.17 15:37t/p690.011884.460.001884.465.01930.53
1382020.12.17 16:00buy700.011888.140.001908.05
1392020.12.17 16:36t/p680.011891.300.001891.3012.27942.80
1402020.12.17 17:53buy710.011893.460.001899.78
1412020.12.17 19:18close710.011883.460.001899.78-10.00932.80
1422020.12.18 06:54buy720.011885.460.001887.97
1432020.12.18 10:09close700.011878.140.001908.05-10.43922.37
1442020.12.18 14:09t/p720.011887.970.001887.972.51924.88
1452020.12.18 14:15buy730.011887.860.001902.08
1462020.12.18 16:54close730.011877.860.001902.08-10.00914.88
1472020.12.21 01:15buy740.011884.030.001891.23
1482020.12.21 03:06t/p740.011891.230.001891.237.20922.08
1492020.12.21 07:00buy750.011900.140.001909.13
1502020.12.21 08:30buy760.011906.870.001918.32
1512020.12.21 08:54close760.011896.870.001918.32-10.00912.08
1522020.12.21 11:49close750.011890.130.001909.13-10.01902.07
1532020.12.21 15:00buy770.011879.950.001891.61
1542020.12.21 16:45buy780.011881.210.001895.00
1552020.12.22 08:51close780.011871.210.001895.00-10.43891.64
1562020.12.22 08:52close770.011869.940.001891.61-10.44881.19
1572020.12.22 13:00buy790.011873.050.001877.78
1582020.12.22 14:39buy800.011875.310.001882.09
1592020.12.22 15:24t/p790.011877.780.001877.784.73885.92
1602020.12.22 16:00buy810.011879.160.001890.80
1612020.12.22 17:49close810.011869.160.001890.80-10.00875.92
1622020.12.22 17:52close800.011865.300.001882.09-10.01865.91
1632020.12.23 02:54buy820.011864.010.001866.14
1642020.12.23 03:09t/p820.011866.140.001866.142.13868.04
1652020.12.23 10:22buy830.011868.900.001874.32
1662020.12.23 14:07close830.011858.890.001874.32-10.01858.03
1672020.12.23 16:15buy840.011868.730.001880.43
1682020.12.24 03:09buy850.011876.100.001879.48
1692020.12.24 04:30buy860.011879.130.001888.64
1702020.12.24 04:39t/p850.011879.480.001879.483.38861.41
1712020.12.24 10:09buy870.011879.050.001880.81
1722020.12.24 11:30buy880.011878.210.001881.48
1732020.12.24 20:15t/p840.011880.430.001880.4310.40871.82
1742020.12.24 20:15t/p870.011880.810.001880.811.76873.58
1752020.12.24 20:15t/p880.011881.480.001881.483.27876.85
1762020.12.28 01:39t/p860.011888.640.001888.648.65885.50
1772020.12.28 03:01buy890.011890.380.001892.75
1782020.12.28 03:04t/p890.011892.750.001892.752.37887.87
1792020.12.28 04:30buy900.011897.560.001912.50
1802020.12.28 07:39close900.011887.560.001912.50-10.00877.87
1812020.12.28 15:45buy910.011885.830.001902.57
1822020.12.28 17:15buy920.011893.820.001906.57
1832020.12.28 17:51close920.011883.810.001906.57-10.01867.86
1842020.12.28 19:37close910.011875.820.001902.57-10.01857.85
1852020.12.29 03:04buy930.011880.640.001886.52
1862020.12.29 06:01buy940.011880.880.001887.50
1872020.12.29 10:03buy950.011881.740.001887.89
1882020.12.29 11:31buy960.011880.610.001886.03
1892020.12.29 17:09close950.011871.730.001887.89-10.01847.84
1902020.12.29 18:39t/p960.011886.030.001886.035.42853.26
1912020.12.29 19:15buy970.011880.650.001884.22
1922020.12.30 03:06buy980.011881.250.001885.50
1932020.12.30 05:07t/p970.011884.220.001884.223.14856.39
1942020.12.30 06:06buy990.011885.320.001888.11
1952020.12.30 06:09t/p980.011885.500.001885.504.25860.64
1962020.12.30 13:30buy1000.011880.600.001884.74
1972020.12.30 16:03t/p1000.011884.740.001884.744.14864.78
1982020.12.30 16:54t/p930.011886.520.001886.525.45870.23
1992020.12.30 16:54t/p940.011887.500.001887.506.19876.42
2002020.12.30 17:15buy1010.011886.150.001896.14
2012020.12.30 19:00buy1020.011887.170.001892.09
2022020.12.30 19:37t/p990.011888.110.001888.112.79879.21
2032020.12.30 20:30buy1030.011889.690.001896.32
2042020.12.30 22:23buy1040.011892.230.001894.83
2052020.12.30 22:50t/p1020.011892.090.001892.094.92884.13
2062020.12.30 23:45buy1050.011894.150.001898.10
2072020.12.31 01:16t/p1040.011894.830.001894.831.30885.44
2082020.12.31 03:04t/p1010.011896.140.001896.148.69894.13
2092020.12.31 03:04t/p1030.011896.320.001896.325.33899.46
2102020.12.31 03:06buy1060.011897.490.001901.03
2112020.12.31 03:07t/p1050.011898.100.001898.102.65902.12
2122020.12.31 05:15close1060.011887.490.001901.03-10.00892.12
2132020.12.31 09:45buy1070.011893.890.001905.40
2142020.12.31 11:18buy1080.011894.830.001900.25
2152020.12.31 15:37buy1090.011897.920.001904.27
2162020.12.31 17:30buy1100.011899.440.001908.56
2172021.01.04 01:00t/p1070.011905.400.001905.4010.65902.77
2182021.01.04 01:00t/p1080.011900.250.001900.254.56907.32
2192021.01.04 01:00t/p1090.011904.270.001904.275.49912.81
2202021.01.04 01:00t/p1100.011908.560.001908.568.26921.07
2212021.01.04 01:34buy1110.011912.570.001943.31
2222021.01.04 03:00buy1120.011913.800.001919.76
2232021.01.04 04:30buy1130.011918.770.001928.16
2242021.01.04 04:49t/p1120.011919.760.001919.765.96927.03
2252021.01.04 10:09t/p1130.011928.160.001928.169.39936.42
2262021.01.04 10:22buy1140.011932.800.001940.78
2272021.01.04 15:37t/p1140.011940.780.001940.787.98944.40
2282021.01.04 15:38buy1150.011942.350.001953.36
2292021.01.04 16:48t/p1110.011943.310.001943.3130.74975.14
2302021.01.04 17:15close1150.011932.340.001953.36-10.01965.13
2312021.01.05 05:30buy1160.011942.070.001949.68
2322021.01.05 09:30buy1170.011943.880.001953.78
2332021.01.05 11:06buy1180.011943.810.001948.31
2342021.01.05 12:37buy1190.011945.890.001950.75
2352021.01.05 13:21t/p1180.011948.310.001948.314.50969.63
2362021.01.05 13:54t/p1160.011949.680.001949.687.61977.24
2372021.01.05 14:00buy1200.011950.270.001958.99
2382021.01.05 15:45t/p1190.011950.750.001950.754.86982.10
2392021.01.05 16:07buy1210.011950.450.001956.36
2402021.01.05 17:07close1210.011940.450.001956.36-10.00972.10
2412021.01.05 17:07close1200.011940.270.001958.99-10.00962.10
2422021.01.05 19:15buy1220.011950.140.001960.64
2432021.01.05 21:00buy1230.011951.580.001955.86
2442021.01.06 02:24buy1240.011951.770.001953.78
2452021.01.06 03:07t/p1170.011953.780.001953.789.47971.56
2462021.01.06 03:07t/p1240.011953.780.001953.782.01973.57
2472021.01.06 06:09close1230.011941.580.001955.86-10.43963.14
2482021.01.06 08:18buy1250.011946.670.001952.46
2492021.01.06 09:45buy1260.011947.850.001954.12
2502021.01.06 10:37t/p1250.011952.460.001952.465.79968.93
2512021.01.06 10:39t/p1260.011954.120.001954.126.27975.20
2522021.01.06 11:30buy1270.011955.760.001969.71
2532021.01.06 13:57close1270.011945.760.001969.71-10.00965.20
2542021.01.06 14:34close1220.011940.130.001960.64-10.44954.76
2552021.01.06 21:37buy1280.011918.110.001929.57
2562021.01.06 23:07buy1290.011920.670.001927.90
2572021.01.07 12:30close1290.011910.670.001927.90-11.30943.47
2582021.01.07 16:39close1280.011908.110.001929.57-11.30932.17
2592021.01.07 18:45buy1300.011914.660.001919.58
2602021.01.07 21:15buy1310.011916.460.001925.07
2612021.01.08 06:39close1310.011906.450.001925.07-10.44921.73
2622021.01.08 09:54close1300.011904.650.001919.58-10.44911.29
2632021.01.11 17:45buy1320.011848.660.001877.66
2642021.01.12 05:00buy1330.011847.670.001855.01
2652021.01.12 06:54buy1340.011851.050.001852.27
2662021.01.12 07:31t/p1340.011852.270.001852.271.22912.51
2672021.01.12 07:37t/p1330.011855.010.001855.017.34919.85
2682021.01.12 08:15buy1350.011856.450.001867.30
2692021.01.12 10:03buy1360.011862.090.001867.25
2702021.01.12 12:30buy1370.011862.060.001871.99
2712021.01.12 15:22close1360.011852.090.001867.25-10.00909.85
2722021.01.12 15:22close1370.011852.050.001871.99-10.01899.84
2732021.01.12 15:37close1350.011846.450.001867.30-10.00889.84
2742021.01.12 16:09close1320.011838.650.001877.66-10.44879.40
2752021.01.12 21:15buy1380.011851.380.001871.21
2762021.01.12 22:47buy1390.011855.090.001861.96
2772021.01.13 02:04buy1400.011859.130.001866.59
2782021.01.13 03:37buy1410.011861.500.001869.38
2792021.01.13 03:40t/p1390.011861.960.001861.966.44885.83
2802021.01.13 09:30buy1420.011861.860.001865.97
2812021.01.13 11:09close1420.011851.850.001865.97-10.01875.82
2822021.01.13 11:09close1410.011851.500.001869.38-10.00865.82
2832021.01.13 11:18close1400.011849.130.001866.59-10.00855.82
2842021.01.13 15:45buy1430.011859.330.001873.43
2852021.01.13 17:15buy1440.011859.450.001869.29
2862021.01.13 22:51close1440.011849.440.001869.29-10.01845.81
2872021.01.13 22:51close1430.011849.320.001873.43-10.01835.80
2882021.01.14 03:19buy1450.011851.230.001860.34
2892021.01.14 04:24close1380.011841.350.001871.21-11.76824.05
2902021.01.14 04:24close1450.011841.220.001860.34-10.01814.04
2912021.01.14 07:39buy1460.011845.190.001850.52
2922021.01.14 14:48buy1470.011843.950.001850.72
2932021.01.14 16:15buy1480.011845.240.001856.30
2942021.01.14 16:30t/p1460.011850.520.001850.525.33819.37
2952021.01.14 16:30t/p1470.011850.720.001850.726.77826.14
2962021.01.14 17:45buy1490.011847.070.001855.23
2972021.01.14 19:53t/p1490.011855.230.001855.238.16834.30
2982021.01.14 20:00buy1500.011855.620.001870.47
2992021.01.14 20:00t/p1480.011856.300.001856.3011.06845.36
3002021.01.14 21:49close1500.011845.610.001870.47-10.01835.35
3012021.01.15 02:30buy1510.011852.620.001862.93
3022021.01.15 10:34buy1520.011852.500.001857.29
3032021.01.15 12:00buy1530.011855.490.001862.71
3042021.01.15 14:09close1530.011845.490.001862.71-10.00825.35
3052021.01.15 15:39close1510.011842.610.001862.93-10.01815.34
3062021.01.15 15:39close1520.011842.490.001857.29-10.01805.33
3072021.01.18 04:37buy1540.011830.630.001842.45
3082021.01.18 07:39buy1550.011837.550.001842.26
3092021.01.18 09:00buy1560.011838.530.001850.92
3102021.01.18 18:31buy1570.011839.430.001847.74
3112021.01.19 03:21t/p1550.011842.260.001842.264.28809.61
3122021.01.19 03:21t/p1540.011842.450.001842.4511.39820.99
3132021.01.19 03:24buy1580.011843.480.001851.55
3142021.01.19 09:00buy1590.011841.010.001847.75
3152021.01.19 15:09close1580.011833.480.001851.55-10.00810.99
3162021.01.19 18:45buy1600.011841.640.001853.49
3172021.01.20 04:07t/p1570.011847.740.001847.747.45818.44
3182021.01.20 04:07t/p1590.011847.750.001847.756.31824.75
3192021.01.20 05:00buy1610.011850.140.001858.36
3202021.01.20 07:08buy1620.011850.760.001853.40
3212021.01.20 07:54t/p1560.011850.920.001850.9211.53836.28
3222021.01.20 08:30buy1630.011852.720.001859.19
3232021.01.20 08:39t/p1620.011853.400.001853.402.64838.92
3242021.01.20 08:39t/p1600.011853.490.001853.4911.42850.33
3252021.01.20 10:00buy1640.011856.230.001862.46
3262021.01.20 14:51close1640.011846.220.001862.46-10.01840.32
3272021.01.20 14:54close1630.011842.720.001859.19-10.00830.32
3282021.01.20 15:04close1610.011840.140.001858.36-10.00820.32
3292021.01.20 18:15buy1650.011865.840.001883.45
3302021.01.21 21:00buy1660.011867.890.001874.70
3312021.01.21 22:30buy1670.011868.830.001870.89
3322021.01.21 22:46t/p1670.011870.890.001870.892.06822.38
3332021.01.22 07:30buy1680.011863.720.001865.70
3342021.01.22 08:24close1660.011857.890.001874.70-10.43811.95
3352021.01.22 11:15buy1690.011863.040.001868.70
3362021.01.22 12:24close1650.011855.840.001883.45-11.73800.23
3372021.01.22 12:34close1680.011853.720.001865.70-10.00790.23
3382021.01.22 12:36close1690.011853.040.001868.70-10.00780.23
3392021.01.22 17:15buy1700.011852.810.001874.17
3402021.01.25 03:03buy1710.011859.980.001864.39
3412021.01.25 08:30close1710.011849.970.001864.39-10.01770.22
3422021.01.25 11:39buy1720.011856.770.001863.43
3432021.01.25 13:00buy1730.011863.240.001876.28
3442021.01.25 13:04t/p1720.011863.430.001863.436.66776.88
3452021.01.25 15:22buy1740.011867.180.001874.10
3462021.01.25 16:54close1740.011857.170.001874.10-10.01766.87
3472021.01.25 17:07close1730.011853.240.001876.28-10.00756.87
3482021.01.25 20:00buy1750.011858.520.001868.84
3492021.01.26 04:15buy1760.011858.730.001866.25
3502021.01.26 12:54close1760.011848.730.001866.25-10.00746.87
3512021.01.26 12:54close1750.011848.520.001868.84-10.43736.43
3522021.01.26 14:45buy1770.011855.890.001863.35
3532021.01.26 16:15buy1780.011857.300.001864.43
3542021.01.26 22:45close1700.011852.770.001874.17-0.90735.53
3552021.01.27 03:06close1780.011847.300.001864.43-10.43725.10
3562021.01.27 03:09close1770.011845.890.001863.35-10.43714.67
3572021.01.27 07:45buy1790.011850.070.001856.27
3582021.01.27 10:00buy1800.011851.400.001856.16
3592021.01.27 13:37close1800.011841.400.001856.16-10.00704.67
3602021.01.27 13:39close1790.011840.070.001856.27-10.00694.67
3612021.01.27 16:30buy1810.011844.550.001854.17
3622021.01.27 16:39close1810.011834.550.001854.17-10.00684.67
3632021.01.28 11:00buy1820.011838.690.001845.07
3642021.01.28 12:30buy1830.011842.100.001847.64
3652021.01.28 15:39t/p1820.011845.070.001845.076.38691.05
3662021.01.28 15:45t/p1830.011847.640.001847.645.54696.59
3672021.01.28 17:45buy1840.011862.050.001875.73
3682021.01.28 18:49close1840.011852.050.001875.73-10.00686.59
3692021.01.28 22:39buy1850.011843.700.001846.09
3702021.01.29 07:54t/p1850.011846.090.001846.091.96688.55
3712021.01.29 08:51buy1860.011849.110.001852.43
3722021.01.29 11:09t/p1860.011852.430.001852.433.32691.87
3732021.01.29 11:15buy1870.011852.640.001867.58
3742021.01.29 12:43close at stop1870.011854.770.001867.582.13694.00
+
diff --git a/Docs/Reports/Tests/XTPW/In Test/StrategyTester 6.gif b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 6.gif new file mode 100644 index 0000000..da959bc Binary files /dev/null and b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 6.gif differ diff --git a/Docs/Reports/Tests/XTPW/In Test/StrategyTester 6.htm b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 6.htm new file mode 100644 index 0000000..fc35a3d --- /dev/null +++ b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 6.htm @@ -0,0 +1,81 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.04.29 23:45 (2020.01.01 - 2021.04.30)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=6; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.01; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xR2R=2.5; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xrR2R=2; xRMaximumCandlesPerTrade=252; xrOscillatorLength=7; xrFastLength=20; xrSlowLength=50; xrRangeMarketLength=50; xrSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWR2R=1.5; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=700;
Bars in test9971Ticks modelled11845786Modelling quality24.76%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (51)
Total net profit-2.82Gross profit17.18Gross loss-20.00
Profit factor0.86Expected payoff-0.47
Absolute drawdown23.71Maximal drawdown25.89 (2.58%)Relative drawdown2.58% (25.89)
Total trades6Short positions (won %)0 (0.00%)Long positions (won %)6 (66.67%)
Profit trades (% of total)4 (66.67%)Loss trades (% of total)2 (33.33%)
Largestprofit trade7.50loss trade-10.00
Averageprofit trade4.29loss trade-10.00
Maximumconsecutive wins (profit in money)3 (15.00)consecutive losses (loss in money)2 (-20.00)
Maximalconsecutive profit (count of wins)15.00 (3)consecutive loss (count of losses)-20.00 (2)
Averageconsecutive wins2consecutive losses2
+Graph
+ + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12021.02.03 02:15buy10.011837.980.001840.16
22021.02.03 02:39t/p10.011840.160.001840.162.181002.18
32021.02.12 08:00buy20.011824.340.001827.91
42021.02.12 10:19close20.011814.340.001827.91-10.00992.18
52021.02.12 12:45buy30.011821.410.001829.72
62021.02.12 15:30close30.011811.410.001829.72-10.00982.18
72021.03.09 01:30buy40.011685.840.001693.34
82021.03.09 08:45t/p40.011693.340.001693.347.50989.68
92021.03.31 02:45buy50.011685.480.001689.02
102021.03.31 08:45buy60.011681.540.001685.50
112021.03.31 09:34t/p60.011685.500.001685.503.96993.64
122021.03.31 15:39t/p50.011689.020.001689.023.54997.18
+
diff --git a/Docs/Reports/Tests/XTPW/In Test/StrategyTester 7.gif b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 7.gif new file mode 100644 index 0000000..99369a1 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 7.gif differ diff --git a/Docs/Reports/Tests/XTPW/In Test/StrategyTester 7.htm b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 7.htm new file mode 100644 index 0000000..abd9d0f --- /dev/null +++ b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 7.htm @@ -0,0 +1,81 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.04.29 23:45 (2020.01.01 - 2021.04.30)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=6; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.015; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xR2R=2.5; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xrR2R=2; xRMaximumCandlesPerTrade=252; xrOscillatorLength=7; xrFastLength=20; xrSlowLength=50; xrRangeMarketLength=50; xrSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWR2R=1.5; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=700;
Bars in test9971Ticks modelled11845786Modelling quality24.76%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (51)
Total net profit29.06Gross profit29.06Gross loss-0.00
Profit factorExpected payoff4.84
Absolute drawdown22.81Maximal drawdown24.99 (2.49%)Relative drawdown2.49% (24.99)
Total trades6Short positions (won %)0 (0.00%)Long positions (won %)6 (100.00%)
Profit trades (% of total)6 (100.00%)Loss trades (% of total)0 (0.00%)
Largestprofit trade8.31loss trade-0.00
Averageprofit trade4.84loss trade-0.00
Maximumconsecutive wins (profit in money)6 (29.06)consecutive losses (loss in money)0 (-0.00)
Maximalconsecutive profit (count of wins)29.06 (6)consecutive loss (count of losses)-0.00 (0)
Averageconsecutive wins6consecutive losses0
+Graph
+ + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12021.02.03 02:15buy10.011837.980.001840.16
22021.02.03 02:39t/p10.011840.160.001840.162.181002.18
32021.02.12 08:00buy20.011824.340.001827.91
42021.02.12 12:45buy30.011821.410.001829.72
52021.02.12 17:54t/p20.011827.910.001827.913.571005.75
62021.02.12 17:54t/p30.011829.720.001829.728.311014.06
72021.03.09 01:30buy40.011685.840.001693.34
82021.03.09 08:45t/p40.011693.340.001693.347.501021.56
92021.03.31 02:45buy50.011685.480.001689.02
102021.03.31 08:45buy60.011681.540.001685.50
112021.03.31 09:34t/p60.011685.500.001685.503.961025.52
122021.03.31 15:39t/p50.011689.020.001689.023.541029.06
+
diff --git a/Docs/Reports/Tests/XTPW/In Test/StrategyTester 8.gif b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 8.gif new file mode 100644 index 0000000..33bc5a2 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 8.gif differ diff --git a/Docs/Reports/Tests/XTPW/In Test/StrategyTester 8.htm b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 8.htm new file mode 100644 index 0000000..16be30e --- /dev/null +++ b/Docs/Reports/Tests/XTPW/In Test/StrategyTester 8.htm @@ -0,0 +1,70 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2021.08.02 01:00 - 2021.10.29 23:45 (2021.08.01 - 2021.10.31)
ModelEvery tick (the most precise method based on all available least timeframes)
Bars in test6965Ticks modelled5220361Modelling quality25.00%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (58)
Total net profit-11.75Gross profit18.25Gross loss-30.00
Profit factor0.61Expected payoff-1.68
Absolute drawdown14.47Maximal drawdown30.83 (3.03%)Relative drawdown3.03% (30.83)
Total trades7Short positions (won %)0 (0.00%)Long positions (won %)7 (71.43%)
Profit trades (% of total)5 (71.43%)Loss trades (% of total)2 (28.57%)
Largestprofit trade8.78loss trade-15.00
Averageprofit trade3.65loss trade-15.00
Maximumconsecutive wins (profit in money)3 (13.04)consecutive losses (loss in money)1 (-15.00)
Maximalconsecutive profit (count of wins)13.04 (3)consecutive loss (count of losses)-15.00 (1)
Averageconsecutive wins2consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12021.08.09 08:30buy10.011743.630.001752.41
22021.08.09 10:48t/p10.011752.410.001752.418.781008.78
32021.08.12 20:45buy20.011751.600.001753.99
42021.08.13 04:22t/p20.011753.990.001753.991.961010.74
52021.08.18 02:00buy30.011786.860.001789.16
62021.08.18 04:33t/p30.011789.160.001789.162.301013.04
72021.09.08 04:04buy40.011798.630.001803.76
82021.09.08 16:54close40.011783.630.001803.76-15.00998.04
92021.09.13 05:45buy50.011789.150.001792.95
102021.09.13 08:54t/p50.011792.950.001792.953.801001.84
112021.09.16 03:15buy60.011795.080.001796.87
122021.09.16 12:51close60.011780.080.001796.87-15.00986.84
132021.09.27 02:15buy70.011749.620.001751.03
142021.09.27 03:13t/p70.011751.030.001751.031.41988.25
+
diff --git a/Docs/Reports/Tests/XTPW/In Test/StrategyTester.gif b/Docs/Reports/Tests/XTPW/In Test/StrategyTester.gif new file mode 100644 index 0000000..bf95b4f Binary files /dev/null and b/Docs/Reports/Tests/XTPW/In Test/StrategyTester.gif differ diff --git a/Docs/Reports/Tests/XTPW/In Test/StrategyTester.htm b/Docs/Reports/Tests/XTPW/In Test/StrategyTester.htm new file mode 100644 index 0000000..89eff88 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/In Test/StrategyTester.htm @@ -0,0 +1,81 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.12.30 23:45 (2020.01.01 - 2021.12.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=6; allowTrade=true; +allowLongTrades=false; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.0001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.15; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xR2R=2.5; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xrR2R=2; xRMaximumCandlesPerTrade=252; xrOscillatorLength=7; xrFastLength=20; xrSlowLength=50; xrRangeMarketLength=50; xrSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWR2R=1.5; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=700;
Bars in test25902Ticks modelled27850269Modelling quality24.91%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (60)
Total net profit687.00Gross profit952.41Gross loss-265.41
Profit factor3.59Expected payoff114.50
Absolute drawdown61.80Maximal drawdown283.01 (14.41%)Relative drawdown14.64% (163.90)
Total trades6Short positions (won %)6 (66.67%)Long positions (won %)0 (0.00%)
Profit trades (% of total)4 (66.67%)Loss trades (% of total)2 (33.33%)
Largestprofit trade315.40loss trade-142.34
Averageprofit trade238.10loss trade-132.71
Maximumconsecutive wins (profit in money)3 (895.41)consecutive losses (loss in money)1 (-142.34)
Maximalconsecutive profit (count of wins)895.41 (3)consecutive loss (count of losses)-142.34 (1)
Averageconsecutive wins2consecutive losses1
+Graph
+ + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12021.01.08 11:00sell10.101888.710.001857.17
22021.01.08 16:45sell20.101871.560.001840.06
32021.01.08 17:09t/p10.101857.170.001857.17315.401315.40
42021.01.08 18:15sell30.101854.120.001827.81
52021.01.08 19:33t/p20.101840.060.001840.06315.001630.40
62021.01.11 03:21t/p30.101827.810.001827.81265.021895.42
72021.10.26 17:00sell40.101789.760.001773.22
82021.10.28 15:21close40.101804.760.001773.22-142.341753.08
92021.11.03 04:00sell50.101783.060.001777.36
102021.11.03 14:39t/p50.101777.360.001777.3657.001810.08
112021.12.20 17:00sell60.101791.570.001781.64
122021.12.22 22:30close60.101804.260.001781.64-123.071687.01
+
diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 1.gif b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 1.gif new file mode 100644 index 0000000..d4767e5 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 1.gif differ diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 1.htm b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 1.htm new file mode 100644 index 0000000..cb9b5b7 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 1.htm @@ -0,0 +1,103 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2021.01.04 01:00 - 2021.01.29 23:45 (2021.01.01 - 2021.01.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=1.5; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test2825Ticks modelled1863423Modelling quality25.00%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (51)
Total net profit37.17Gross profit45.89Gross loss-8.72
Profit factor5.26Expected payoff2.19
Absolute drawdown1.08Maximal drawdown14.81 (1.42%)Relative drawdown1.42% (14.81)
Total trades17Short positions (won %)0 (0.00%)Long positions (won %)17 (94.12%)
Profit trades (% of total)16 (94.12%)Loss trades (% of total)1 (5.88%)
Largestprofit trade3.02loss trade-8.72
Averageprofit trade2.87loss trade-8.72
Maximumconsecutive wins (profit in money)16 (45.89)consecutive losses (loss in money)1 (-8.72)
Maximalconsecutive profit (count of wins)45.89 (16)consecutive loss (count of losses)-8.72 (1)
Averageconsecutive wins16consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12021.01.05 17:08buy10.011939.900.001942.92
22021.01.05 17:19t/p10.011942.920.001942.923.021003.02
32021.01.05 22:24buy20.011949.670.001952.69
42021.01.06 01:31t/p20.011952.690.001952.692.531005.55
52021.01.06 04:54buy30.011944.020.001947.04
62021.01.06 05:15t/p30.011947.040.001947.043.021008.57
72021.01.12 15:39buy40.011844.020.001847.04
82021.01.12 16:31t/p40.011847.040.001847.043.021011.59
92021.01.12 18:46buy50.011841.920.001844.94
102021.01.12 20:34t/p50.011844.940.001844.943.021014.61
112021.01.15 15:54buy60.011839.140.001842.16
122021.01.15 16:09t/p60.011842.160.001842.163.021017.63
132021.01.19 14:54buy70.011836.230.001839.25
142021.01.19 15:52t/p70.011839.250.001839.253.021020.65
152021.01.19 16:54buy80.011835.490.001838.51
162021.01.19 17:03t/p80.011838.510.001838.513.021023.67
172021.01.19 20:48buy90.011840.410.001843.43
182021.01.20 02:54t/p90.011843.430.001843.432.531026.21
192021.01.20 14:54buy100.011842.620.001845.64
202021.01.20 15:39t/p100.011845.640.001845.643.021029.23
212021.01.20 19:24buy110.011863.200.001866.22
222021.01.20 20:21t/p110.011866.220.001866.223.021032.25
232021.01.25 17:09buy120.011851.970.001854.99
242021.01.25 17:24t/p120.011854.990.001854.993.021035.27
252021.01.25 21:22buy130.011855.430.001858.45
262021.01.26 03:54t/p130.011858.450.001858.452.531037.80
272021.01.28 19:06buy140.011845.620.001848.64
282021.01.28 23:01buy150.011841.300.001844.32
292021.01.29 01:39t/p150.011844.320.001844.322.531040.33
302021.01.29 08:51t/p140.011848.640.001848.642.531042.87
312021.01.29 16:39buy160.011855.920.001858.94
322021.01.29 16:49t/p160.011858.940.001858.943.021045.89
332021.01.29 19:22buy170.011856.150.001859.17
342021.01.29 23:58close at stop170.011847.430.001859.17-8.721037.17
+
diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 10.gif b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 10.gif new file mode 100644 index 0000000..15854a6 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 10.gif differ diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 10.htm b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 10.htm new file mode 100644 index 0000000..5ea0cb3 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 10.htm @@ -0,0 +1,95 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2023.01.03 01:00 - 2023.08.02 04:45 (2023.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test14765Ticks modelled18359176Modelling qualityn/a
Mismatched charts errors804
Initial deposit1000.00SpreadCurrent (50)
Total net profit-49.87Gross profit45.06Gross loss-94.92
Profit factor0.47Expected payoff-3.84
Absolute drawdown49.87Maximal drawdown53.43 (5.32%)Relative drawdown5.32% (53.43)
Total trades13Short positions (won %)0 (0.00%)Long positions (won %)13 (53.85%)
Profit trades (% of total)7 (53.85%)Loss trades (% of total)6 (46.15%)
Largestprofit trade16.17loss trade-16.48
Averageprofit trade6.44loss trade-15.82
Maximumconsecutive wins (profit in money)2 (18.97)consecutive losses (loss in money)1 (-16.48)
Maximalconsecutive profit (count of wins)18.97 (2)consecutive loss (count of losses)-16.48 (1)
Averageconsecutive wins1consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12023.01.11 01:24buy10.011876.960.001878.14
22023.01.11 03:01t/p10.011878.140.001878.141.181001.18
32023.01.11 12:42buy20.011883.450.001886.42
42023.01.11 17:38buy30.011870.910.001878.90
52023.01.11 18:06close20.011868.450.001886.42-15.00986.18
62023.01.12 03:48t/p30.011878.900.001878.906.53992.71
72023.02.02 18:35buy40.011917.590.001927.38
82023.02.03 15:32close40.011902.570.001927.38-15.51977.20
92023.02.16 13:52buy50.011836.270.001839.07
102023.02.16 14:52t/p50.011839.070.001839.072.80980.00
112023.03.16 17:38buy60.011915.520.001932.18
122023.03.17 07:33t/p60.011932.180.001932.1816.17996.18
132023.04.05 20:20buy70.012019.930.002023.78
142023.04.06 16:44close70.012004.920.002023.78-16.47979.71
152023.04.26 19:17buy80.011988.970.002001.19
162023.04.27 08:13t/p80.012001.190.002001.1910.76990.47
172023.05.24 17:20buy90.011967.200.001972.30
182023.05.25 15:34close90.011952.180.001972.30-16.48973.99
192023.05.26 17:32buy100.011946.400.001951.61
202023.05.30 12:59t/p100.011951.610.001951.614.24978.23
212023.06.16 19:16buy110.011955.520.001961.50
222023.06.20 16:17close110.011940.520.001961.50-15.97962.26
232023.07.13 18:51buy120.011957.820.001961.68
242023.07.14 04:38t/p120.011961.680.001961.683.37965.63
252023.07.20 17:09buy130.011972.690.001979.97
262023.07.21 18:04close130.011957.680.001979.97-15.50950.13
+
diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 11.gif b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 11.gif new file mode 100644 index 0000000..39eeab5 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 11.gif differ diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 11.htm b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 11.htm new file mode 100644 index 0000000..9ba9c5a --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 11.htm @@ -0,0 +1,75 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2023.01.03 01:00 - 2023.08.02 05:00 (2023.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test14766Ticks modelled18360505Modelling qualityn/a
Mismatched charts errors804
Initial deposit1000.00SpreadCurrent (56)
Total net profit23.29Gross profit23.29Gross loss-0.00
Profit factorExpected payoff7.76
Absolute drawdown4.03Maximal drawdown6.73 (0.67%)Relative drawdown0.67% (6.73)
Total trades3Short positions (won %)0 (0.00%)Long positions (won %)3 (100.00%)
Profit trades (% of total)3 (100.00%)Loss trades (% of total)0 (0.00%)
Largestprofit trade10.70loss trade-0.00
Averageprofit trade7.76loss trade-0.00
Maximumconsecutive wins (profit in money)3 (23.29)consecutive losses (loss in money)0 (-0.00)
Maximalconsecutive profit (count of wins)23.29 (3)consecutive loss (count of losses)-0.00 (0)
Averageconsecutive wins3consecutive losses0
+Graph
+ + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12023.01.11 17:38buy10.011870.970.001878.90
22023.01.12 03:48t/p10.011878.900.001878.906.471006.47
32023.04.26 19:17buy20.011989.030.002001.19
42023.04.27 08:13t/p20.012001.190.002001.1910.701017.17
52023.07.13 19:00buy30.011955.080.001961.68
62023.07.14 04:38t/p30.011961.680.001961.686.111023.29
+
diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 12.gif b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 12.gif new file mode 100644 index 0000000..ed24571 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 12.gif differ diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 12.htm b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 12.htm new file mode 100644 index 0000000..c1ca429 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 12.htm @@ -0,0 +1,103 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.02 05:15 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63371Ticks modelled72617929Modelling qualityn/a
Mismatched charts errors809
Initial deposit1000.00SpreadCurrent (56)
Total net profit118.15Gross profit149.13Gross loss-30.97
Profit factor4.81Expected payoff6.95
Absolute drawdown19.83Maximal drawdown28.11 (2.79%)Relative drawdown2.79% (28.11)
Total trades17Short positions (won %)0 (0.00%)Long positions (won %)17 (88.24%)
Profit trades (% of total)15 (88.24%)Loss trades (% of total)2 (11.76%)
Largestprofit trade18.17loss trade-15.49
Averageprofit trade9.94loss trade-15.49
Maximumconsecutive wins (profit in money)13 (129.43)consecutive losses (loss in money)1 (-15.49)
Maximalconsecutive profit (count of wins)129.43 (13)consecutive loss (count of losses)-15.49 (1)
Averageconsecutive wins8consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12021.03.11 16:48buy10.011719.890.001736.10
22021.03.12 11:09close10.011704.890.001736.10-15.49984.51
32021.03.17 13:48buy20.011728.330.001737.00
42021.03.17 20:06t/p20.011737.000.001737.008.67993.18
52021.04.19 15:15buy30.011775.890.001787.89
62021.04.21 09:54t/p30.011787.890.001787.8911.031004.21
72021.04.27 18:24buy40.011778.410.001784.35
82021.04.28 12:24close40.011763.410.001784.35-15.49988.72
92021.05.19 22:00buy50.011863.450.001881.95
102021.05.20 19:49t/p50.011881.950.001881.9517.041005.77
112021.07.06 19:07buy60.011794.070.001807.68
122021.07.07 13:24t/p60.011807.680.001807.6813.121018.89
132021.07.08 18:04buy70.011801.920.001814.59
142021.07.13 15:39t/p70.011814.590.001814.5911.211030.10
152021.08.17 17:15buy80.011782.670.001792.83
162021.08.18 09:37t/p80.011792.830.001792.839.671039.77
172021.12.21 16:52buy90.011793.780.001799.79
182021.12.22 20:09t/p90.011799.790.001799.795.521045.30
192022.02.15 11:19buy100.011856.920.001877.04
202022.02.17 10:16t/p100.011877.040.001877.0418.171063.47
212022.04.26 17:36buy110.011901.330.001904.58
222022.04.26 17:38t/p110.011904.580.001904.583.251066.72
232022.09.30 20:35buy120.011663.120.001671.54
242022.10.03 16:16t/p120.011671.540.001671.547.931074.66
252022.11.30 17:18buy130.011751.880.001763.12
262022.11.30 21:20t/p130.011763.120.001763.1211.241085.90
272022.12.09 17:23buy140.011791.220.001800.19
282022.12.09 18:20t/p140.011800.190.001800.198.971094.87
292023.01.11 17:38buy150.011870.970.001878.90
302023.01.12 03:48t/p150.011878.900.001878.906.471101.34
312023.04.26 19:17buy160.011989.030.002001.19
322023.04.27 08:13t/p160.012001.190.002001.1910.701112.04
332023.07.13 19:00buy170.011955.080.001961.68
342023.07.14 04:38t/p170.011961.680.001961.686.111118.15
+
diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 13.gif b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 13.gif new file mode 100644 index 0000000..36be70d Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 13.gif differ diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 13.htm b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 13.htm new file mode 100644 index 0000000..bb47461 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 13.htm @@ -0,0 +1,103 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.02 06:00 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63374Ticks modelled72620713Modelling qualityn/a
Mismatched charts errors809
Initial deposit1000.00SpreadCurrent (57)
Total net profit91.72Gross profit107.20Gross loss-15.49
Profit factor6.92Expected payoff5.40
Absolute drawdown0.80Maximal drawdown21.17 (2.03%)Relative drawdown2.03% (21.17)
Total trades17Short positions (won %)0 (0.00%)Long positions (won %)17 (94.12%)
Profit trades (% of total)16 (94.12%)Loss trades (% of total)1 (5.88%)
Largestprofit trade17.03loss trade-15.49
Averageprofit trade6.70loss trade-15.49
Maximumconsecutive wins (profit in money)13 (89.63)consecutive losses (loss in money)1 (-15.49)
Maximalconsecutive profit (count of wins)89.63 (13)consecutive loss (count of losses)-15.49 (1)
Averageconsecutive wins8consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12021.03.11 16:48buy10.011719.900.001725.30
22021.03.11 17:07t/p10.011725.300.001725.305.401005.40
32021.03.17 13:48buy20.011728.340.001737.00
42021.03.17 20:06t/p20.011737.000.001737.008.661014.06
52021.04.19 15:15buy30.011775.900.001779.90
62021.04.20 19:24t/p30.011779.900.001779.903.511017.57
72021.04.27 18:24buy40.011778.420.001784.35
82021.04.28 12:24close40.011763.420.001784.35-15.491002.09
92021.05.19 22:00buy50.011863.460.001881.95
102021.05.20 19:49t/p50.011881.950.001881.9517.031019.12
112021.07.06 19:07buy60.011794.080.001807.68
122021.07.07 13:24t/p60.011807.680.001807.6813.111032.23
132021.07.08 18:04buy70.011801.930.001814.59
142021.07.13 15:39t/p70.011814.590.001814.5911.201043.43
152021.08.17 17:15buy80.011782.680.001786.06
162021.08.17 17:24t/p80.011786.060.001786.063.381046.81
172021.12.21 16:52buy90.011793.790.001799.79
182021.12.22 20:09t/p90.011799.790.001799.795.511052.33
192022.02.15 11:19buy100.011856.930.001863.63
202022.02.16 16:39t/p100.011863.630.001863.636.211058.54
212022.04.26 17:36buy110.011901.340.001904.58
222022.04.26 17:38t/p110.011904.580.001904.583.241061.78
232022.09.30 20:35buy120.011663.130.001665.93
242022.10.03 04:23t/p120.011665.930.001665.932.311064.09
252022.11.30 17:18buy130.011751.890.001763.12
262022.11.30 21:20t/p130.011763.120.001763.1211.231075.32
272022.12.09 17:23buy140.011791.230.001800.19
282022.12.09 18:20t/p140.011800.190.001800.198.961084.28
292023.01.11 17:38buy150.011870.980.001873.62
302023.01.11 18:51t/p150.011873.620.001873.622.641086.92
312023.04.26 19:17buy160.011989.040.001993.09
322023.04.27 04:34t/p160.011993.090.001993.092.591089.52
332023.07.13 19:00buy170.011955.090.001957.29
342023.07.13 19:18t/p170.011957.290.001957.292.201091.72
+
diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 2.gif b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 2.gif new file mode 100644 index 0000000..8c6dcb1 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 2.gif differ diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 2.htm b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 2.htm new file mode 100644 index 0000000..0aa2565 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 2.htm @@ -0,0 +1,127 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.05.28 23:45 (2020.01.01 - 2021.05.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test11903Ticks modelled14454965Modelling quality24.80%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (60)
Total net profit75.28Gross profit155.15Gross loss-79.87
Profit factor1.94Expected payoff2.60
Absolute drawdown5.66Maximal drawdown65.01 (6.09%)Relative drawdown6.09% (65.01)
Total trades29Short positions (won %)0 (0.00%)Long positions (won %)29 (79.31%)
Profit trades (% of total)23 (79.31%)Loss trades (% of total)6 (20.69%)
Largestprofit trade18.30loss trade-16.46
Averageprofit trade6.75loss trade-13.31
Maximumconsecutive wins (profit in money)8 (53.93)consecutive losses (loss in money)2 (-31.46)
Maximalconsecutive profit (count of wins)53.93 (8)consecutive loss (count of losses)-31.46 (2)
Averageconsecutive wins5consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 01:49buy10.011840.610.001841.60
22020.12.04 02:34t/p10.011841.600.001841.600.991000.99
32020.12.16 17:07buy20.011851.160.001858.69
42020.12.16 21:52t/p20.011858.690.001858.697.531008.52
52020.12.21 15:09buy30.011872.270.001884.07
62020.12.21 15:48t/p30.011884.070.001884.0711.801020.32
72021.01.05 22:24buy40.011949.760.001952.93
82021.01.06 01:33t/p40.011952.930.001952.932.681023.00
92021.01.12 18:46buy50.011842.010.001846.47
102021.01.12 20:34t/p50.011846.470.001846.474.461027.46
112021.01.20 15:15buy60.011834.780.001851.35
122021.01.20 16:06t/p60.011851.350.001851.3516.571044.03
132021.01.20 19:24buy70.011863.290.001870.20
142021.01.20 22:37t/p70.011870.200.001870.206.911050.94
152021.01.25 18:18buy80.011847.720.001864.22
162021.01.25 21:22buy90.011855.520.001858.99
172021.01.26 04:07t/p90.011858.990.001858.992.981053.93
182021.01.27 16:39close80.011832.720.001864.22-15.971037.95
192021.01.28 19:30buy100.011840.840.001859.63
202021.01.28 23:01buy110.011841.390.001844.75
212021.01.29 02:09t/p110.011844.750.001844.752.871040.83
222021.01.29 12:54t/p100.011859.630.001859.6318.301059.13
232021.02.10 17:22buy120.011841.230.001854.70
242021.02.10 22:09buy130.011842.100.001846.21
252021.02.11 15:15t/p130.011846.210.001846.212.651061.78
262021.02.11 19:09close120.011826.230.001854.70-16.461045.32
272021.02.16 14:39buy140.011815.670.001823.53
282021.02.16 15:37close140.011800.670.001823.53-15.001030.32
292021.02.18 17:04buy150.011773.580.001787.03
302021.02.18 20:09buy160.011774.390.001777.95
312021.02.19 15:51t/p160.011777.950.001777.953.071033.40
322021.02.19 16:09t/p150.011787.030.001787.0312.961046.36
332021.03.11 16:48buy170.011719.930.001736.10
342021.03.11 19:54buy180.011722.490.001725.88
352021.03.11 20:06t/p180.011725.880.001725.883.391049.75
362021.03.12 11:09close170.011704.930.001736.10-15.491034.27
372021.03.16 13:54buy190.011731.560.001735.44
382021.03.16 14:18t/p190.011735.440.001735.443.881038.15
392021.03.17 13:48buy200.011728.370.001737.00
402021.03.17 15:39buy210.011728.670.001731.81
412021.03.17 16:22t/p210.011731.810.001731.813.141041.29
422021.03.17 20:06t/p200.011737.000.001737.008.631049.92
432021.04.19 15:15buy220.011775.930.001787.89
442021.04.19 19:22buy230.011771.820.001776.60
452021.04.20 17:09t/p230.011776.600.001776.604.291054.21
462021.04.20 20:54buy240.011777.940.001780.24
472021.04.21 04:09t/p240.011780.240.001780.241.811056.02
482021.04.21 09:54t/p220.011787.890.001787.8910.991067.01
492021.04.23 17:37buy250.011772.400.001795.78
502021.04.27 18:22buy260.011779.470.001784.35
512021.04.28 03:09close250.011772.390.001795.78-1.471065.54
522021.04.28 12:24close260.011764.470.001784.35-15.491050.06
532021.05.19 22:00buy270.011863.490.001881.95
542021.05.20 01:22buy280.011869.360.001871.54
552021.05.20 03:54t/p280.011871.540.001871.542.181052.24
562021.05.20 19:49t/p270.011881.950.001881.9517.001069.24
572021.05.21 19:18buy290.011870.800.001876.84
582021.05.21 20:37t/p290.011876.840.001876.846.041075.28
+
diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 3.gif b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 3.gif new file mode 100644 index 0000000..7f6d483 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 3.gif differ diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 3.htm b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 3.htm new file mode 100644 index 0000000..3739303 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 3.htm @@ -0,0 +1,102 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.06.29 23:45 (2020.01.01 - 2021.06.30)
ModelEvery tick (the most precise method based on all available least timeframes)
Bars in test13911Ticks modelled17143577Modelling quality24.83%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (60)
Total net profit42.27Gross profit120.67Gross loss-78.40
Profit factor1.54Expected payoff1.84
Absolute drawdown5.66Maximal drawdown39.57 (3.73%)Relative drawdown3.73% (39.57)
Total trades23Short positions (won %)0 (0.00%)Long positions (won %)23 (78.26%)
Profit trades (% of total)18 (78.26%)Loss trades (% of total)5 (21.74%)
Largestprofit trade17.97loss trade-16.46
Averageprofit trade6.70loss trade-15.68
Maximumconsecutive wins (profit in money)8 (55.00)consecutive losses (loss in money)2 (-30.97)
Maximalconsecutive profit (count of wins)55.00 (8)consecutive loss (count of losses)-30.97 (2)
Averageconsecutive wins5consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 01:49buy10.011840.610.001841.60
22020.12.04 02:34t/p10.011841.600.001841.600.991000.99
32020.12.16 17:07buy20.011851.160.001858.69
42020.12.16 21:52t/p20.011858.690.001858.697.531008.52
52020.12.21 15:09buy30.011872.270.001884.07
62020.12.21 15:48t/p30.011884.070.001884.0711.801020.32
72021.01.05 22:24buy40.011949.760.001952.93
82021.01.06 01:33t/p40.011952.930.001952.932.681023.00
92021.01.12 18:46buy50.011842.010.001846.47
102021.01.12 20:34t/p50.011846.470.001846.474.461027.46
112021.01.20 19:24buy60.011863.290.001870.20
122021.01.20 22:37t/p60.011870.200.001870.206.911034.37
132021.01.28 20:00buy70.011838.060.001856.52
142021.01.29 12:49t/p70.011856.520.001856.5217.971052.35
152021.02.10 17:22buy80.011841.230.001854.70
162021.02.10 22:09buy90.011842.100.001846.21
172021.02.11 15:15t/p90.011846.210.001846.212.651055.00
182021.02.11 19:09close80.011826.230.001854.70-16.461038.54
192021.03.11 16:48buy100.011719.930.001736.10
202021.03.11 19:54buy110.011722.490.001725.88
212021.03.11 20:06t/p110.011725.880.001725.883.391041.93
222021.03.12 11:09close100.011704.930.001736.10-15.491026.44
232021.03.16 13:54buy120.011731.560.001735.44
242021.03.16 14:18t/p120.011735.440.001735.443.881030.32
252021.03.17 13:48buy130.011728.370.001737.00
262021.03.17 15:39buy140.011728.670.001731.81
272021.03.17 16:22t/p140.011731.810.001731.813.141033.46
282021.03.17 20:06t/p130.011737.000.001737.008.631042.09
292021.04.19 15:15buy150.011775.930.001787.89
302021.04.19 19:22buy160.011771.820.001776.60
312021.04.20 17:09t/p160.011776.600.001776.604.291046.39
322021.04.21 09:54t/p150.011787.890.001787.8910.991057.37
332021.04.27 18:22buy170.011779.470.001784.35
342021.04.28 12:24close170.011764.470.001784.35-15.491041.89
352021.05.19 22:00buy180.011863.490.001881.95
362021.05.20 01:22buy190.011869.360.001871.54
372021.05.20 03:54t/p190.011871.540.001871.542.181044.07
382021.05.20 19:49t/p180.011881.950.001881.9517.001061.07
392021.05.21 19:18buy200.011870.800.001876.84
402021.05.21 20:37t/p200.011876.840.001876.846.041067.11
412021.06.01 11:34buy210.011908.020.001915.21
422021.06.01 13:39buy220.011905.620.001911.75
432021.06.01 16:18t/p220.011911.750.001911.756.131073.24
442021.06.01 17:54close210.011893.020.001915.21-15.001058.24
452021.06.25 18:51buy230.011779.840.001787.90
462021.06.29 14:22close230.011764.840.001787.90-15.971042.27
+
diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 4.gif b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 4.gif new file mode 100644 index 0000000..579675f Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 4.gif differ diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 4.htm b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 4.htm new file mode 100644 index 0000000..6b6ee72 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 4.htm @@ -0,0 +1,102 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.06.29 23:45 (2020.01.01 - 2021.06.30)
ModelEvery tick (the most precise method based on all available least timeframes)
Bars in test13911Ticks modelled17143577Modelling quality24.83%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (50)
Total net profit44.06Gross profit122.47Gross loss-78.41
Profit factor1.56Expected payoff1.92
Absolute drawdown5.46Maximal drawdown39.07 (3.68%)Relative drawdown3.68% (39.07)
Total trades23Short positions (won %)0 (0.00%)Long positions (won %)23 (78.26%)
Profit trades (% of total)18 (78.26%)Loss trades (% of total)5 (21.74%)
Largestprofit trade18.07loss trade-16.46
Averageprofit trade6.80loss trade-15.68
Maximumconsecutive wins (profit in money)8 (55.80)consecutive losses (loss in money)2 (-30.97)
Maximalconsecutive profit (count of wins)55.80 (8)consecutive loss (count of losses)-30.97 (2)
Averageconsecutive wins5consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 01:49buy10.011840.510.001841.60
22020.12.04 02:34t/p10.011841.600.001841.601.091001.09
32020.12.16 17:07buy20.011851.060.001858.69
42020.12.16 21:52t/p20.011858.690.001858.697.631008.72
52020.12.21 15:09buy30.011872.170.001884.07
62020.12.21 15:48t/p30.011884.070.001884.0711.901020.62
72021.01.05 22:24buy40.011949.660.001952.93
82021.01.06 01:33t/p40.011952.930.001952.932.781023.40
92021.01.12 18:46buy50.011841.910.001846.47
102021.01.12 20:34t/p50.011846.470.001846.474.561027.96
112021.01.20 19:24buy60.011863.190.001870.20
122021.01.20 22:37t/p60.011870.200.001870.207.011034.97
132021.01.28 20:00buy70.011837.960.001856.52
142021.01.29 12:49t/p70.011856.520.001856.5218.071053.05
152021.02.10 17:22buy80.011841.130.001854.70
162021.02.10 22:09buy90.011842.000.001846.21
172021.02.11 15:15t/p90.011846.210.001846.212.751055.80
182021.02.11 19:09close80.011826.130.001854.70-16.461039.34
192021.03.11 16:48buy100.011719.830.001736.10
202021.03.11 19:54buy110.011722.390.001725.88
212021.03.11 20:06t/p110.011725.880.001725.883.491042.83
222021.03.12 11:09close100.011704.830.001736.10-15.491027.34
232021.03.16 13:54buy120.011731.460.001735.44
242021.03.16 14:18t/p120.011735.440.001735.443.981031.32
252021.03.17 13:48buy130.011728.270.001737.00
262021.03.17 15:39buy140.011728.570.001731.81
272021.03.17 16:22t/p140.011731.810.001731.813.241034.56
282021.03.17 20:06t/p130.011737.000.001737.008.731043.29
292021.04.19 15:15buy150.011775.830.001787.89
302021.04.19 19:22buy160.011771.720.001776.60
312021.04.20 17:09t/p160.011776.600.001776.604.391047.69
322021.04.21 09:54t/p150.011787.890.001787.8911.091058.77
332021.04.27 18:22buy170.011779.370.001784.35
342021.04.28 12:24close170.011764.360.001784.35-15.501043.28
352021.05.19 22:00buy180.011863.390.001881.95
362021.05.20 01:22buy190.011869.260.001871.54
372021.05.20 03:54t/p190.011871.540.001871.542.281045.56
382021.05.20 19:49t/p180.011881.950.001881.9517.101062.66
392021.05.21 19:18buy200.011870.700.001876.84
402021.05.21 20:37t/p200.011876.840.001876.846.141068.80
412021.06.01 11:34buy210.011907.920.001915.21
422021.06.01 13:39buy220.011905.520.001911.75
432021.06.01 16:18t/p220.011911.750.001911.756.231075.03
442021.06.01 17:54close210.011892.920.001915.21-15.001060.03
452021.06.25 18:51buy230.011779.740.001787.90
462021.06.29 14:22close230.011764.740.001787.90-15.971044.06
+
diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 5.gif b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 5.gif new file mode 100644 index 0000000..096ccb0 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 5.gif differ diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 5.htm b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 5.htm new file mode 100644 index 0000000..28e84c9 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 5.htm @@ -0,0 +1,115 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.06.29 23:45 (2020.01.01 - 2021.06.30)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test13911Ticks modelled17143577Modelling quality24.83%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (60)
Total net profit48.62Gross profit111.05Gross loss-62.43
Profit factor1.78Expected payoff2.11
Absolute drawdown5.66Maximal drawdown39.57 (3.78%)Relative drawdown3.78% (39.57)
Total trades23Short positions (won %)0 (0.00%)Long positions (won %)23 (82.61%)
Profit trades (% of total)19 (82.61%)Loss trades (% of total)4 (17.39%)
Largestprofit trade17.00loss trade-16.46
Averageprofit trade5.84loss trade-15.61
Maximumconsecutive wins (profit in money)8 (43.17)consecutive losses (loss in money)1 (-16.46)
Maximalconsecutive profit (count of wins)43.17 (8)consecutive loss (count of losses)-16.46 (1)
Averageconsecutive wins4consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 01:49buy10.011840.610.001841.60
22020.12.04 02:34t/p10.011841.600.001841.600.991000.99
32020.12.16 17:07buy20.011851.160.001858.69
42020.12.16 21:52t/p20.011858.690.001858.697.531008.52
52020.12.21 15:09buy30.011872.270.001884.07
62020.12.21 15:48t/p30.011884.070.001884.0711.801020.32
72021.01.05 22:24buy40.011949.760.001952.93
82021.01.06 01:33t/p40.011952.930.001952.932.681023.00
92021.01.12 18:46buy50.011842.010.001846.47
102021.01.12 20:34t/p50.011846.470.001846.474.461027.46
112021.01.20 19:24buy60.011863.290.001870.20
122021.01.20 22:37t/p60.011870.200.001870.206.911034.37
132021.01.28 20:00buy70.011838.060.001844.21
142021.01.28 21:24t/p70.011844.210.001844.216.151040.52
152021.02.10 17:22buy80.011841.230.001854.70
162021.02.10 22:09buy90.011842.100.001846.21
172021.02.11 15:15t/p90.011846.210.001846.212.651043.17
182021.02.11 19:09close80.011826.230.001854.70-16.461026.72
192021.03.11 16:48buy100.011719.930.001736.10
202021.03.11 19:54buy110.011722.490.001725.88
212021.03.11 20:06t/p110.011725.880.001725.883.391030.11
222021.03.12 11:09close100.011704.930.001736.10-15.491014.62
232021.03.16 13:54buy120.011731.560.001735.44
242021.03.16 14:18t/p120.011735.440.001735.443.881018.50
252021.03.17 13:48buy130.011728.370.001737.00
262021.03.17 15:39buy140.011728.670.001731.81
272021.03.17 16:22t/p140.011731.810.001731.813.141021.64
282021.03.17 20:06t/p130.011737.000.001737.008.631030.27
292021.04.19 15:15buy150.011775.930.001787.89
302021.04.19 19:22buy160.011771.820.001776.60
312021.04.20 17:09t/p160.011776.600.001776.604.291034.56
322021.04.21 09:54t/p150.011787.890.001787.8910.991045.55
332021.04.27 18:22buy170.011779.470.001784.35
342021.04.28 12:24close170.011764.470.001784.35-15.491030.06
352021.05.19 22:00buy180.011863.490.001881.95
362021.05.20 01:22buy190.011869.360.001871.54
372021.05.20 03:54t/p190.011871.540.001871.542.181032.24
382021.05.20 19:49t/p180.011881.950.001881.9517.001049.25
392021.05.21 19:18buy200.011870.800.001876.84
402021.05.21 20:37t/p200.011876.840.001876.846.041055.29
412021.06.01 11:34buy210.011908.020.001915.21
422021.06.01 13:39buy220.011905.620.001911.75
432021.06.01 16:18t/p220.011911.750.001911.756.131061.42
442021.06.01 17:54close210.011893.020.001915.21-15.001046.42
452021.06.25 18:51buy230.011779.840.001782.53
462021.06.28 01:52t/p230.011782.530.001782.532.201048.62
+
diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 6.gif b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 6.gif new file mode 100644 index 0000000..0e22ca4 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 6.gif differ diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 6.htm b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 6.htm new file mode 100644 index 0000000..d9e7a6e --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 6.htm @@ -0,0 +1,109 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.06.29 23:45 (2020.01.01 - 2021.06.30)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test13911Ticks modelled17143577Modelling quality24.83%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (60)
Total net profit56.72Gross profit102.70Gross loss-45.97
Profit factor2.23Expected payoff2.84
Absolute drawdown5.66Maximal drawdown30.08 (2.87%)Relative drawdown2.87% (30.08)
Total trades20Short positions (won %)0 (0.00%)Long positions (won %)20 (85.00%)
Profit trades (% of total)17 (85.00%)Loss trades (% of total)3 (15.00%)
Largestprofit trade17.00loss trade-15.49
Averageprofit trade6.04loss trade-15.32
Maximumconsecutive wins (profit in money)8 (40.41)consecutive losses (loss in money)1 (-15.49)
Maximalconsecutive profit (count of wins)40.41 (8)consecutive loss (count of losses)-15.49 (1)
Averageconsecutive wins6consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 01:49buy10.011840.610.001841.60
22020.12.04 02:34t/p10.011841.600.001841.600.991000.99
32020.12.16 17:07buy20.011851.160.001858.69
42020.12.16 21:52t/p20.011858.690.001858.697.531008.52
52020.12.21 15:09buy30.011872.270.001884.07
62020.12.21 15:48t/p30.011884.070.001884.0711.801020.32
72021.01.05 22:24buy40.011949.760.001952.93
82021.01.06 01:33t/p40.011952.930.001952.932.681023.00
92021.01.12 18:46buy50.011842.010.001846.47
102021.01.12 20:34t/p50.011846.470.001846.474.461027.46
112021.01.20 19:24buy60.011863.290.001870.20
122021.01.20 22:37t/p60.011870.200.001870.206.911034.37
132021.02.10 22:09buy70.011842.100.001846.21
142021.02.11 15:15t/p70.011846.210.001846.212.651037.02
152021.03.11 16:48buy80.011719.930.001736.10
162021.03.11 19:54buy90.011722.490.001725.88
172021.03.11 20:06t/p90.011725.880.001725.883.391040.41
182021.03.12 11:09close80.011704.930.001736.10-15.491024.93
192021.03.16 13:54buy100.011731.560.001735.44
202021.03.16 14:18t/p100.011735.440.001735.443.881028.81
212021.03.17 13:48buy110.011728.370.001737.00
222021.03.17 15:39buy120.011728.670.001731.81
232021.03.17 16:22t/p120.011731.810.001731.813.141031.95
242021.03.17 20:06t/p110.011737.000.001737.008.631040.58
252021.04.19 15:15buy130.011775.930.001787.89
262021.04.19 19:22buy140.011771.820.001776.60
272021.04.20 17:09t/p140.011776.600.001776.604.291044.87
282021.04.21 09:54t/p130.011787.890.001787.8910.991055.86
292021.04.27 18:22buy150.011779.470.001784.35
302021.04.28 12:24close150.011764.470.001784.35-15.491040.37
312021.05.19 22:00buy160.011863.490.001881.95
322021.05.20 01:22buy170.011869.360.001871.54
332021.05.20 03:54t/p170.011871.540.001871.542.181042.55
342021.05.20 19:49t/p160.011881.950.001881.9517.001059.55
352021.05.21 19:18buy180.011870.800.001876.84
362021.05.21 20:37t/p180.011876.840.001876.846.041065.59
372021.06.01 11:34buy190.011908.020.001915.21
382021.06.01 13:39buy200.011905.620.001911.75
392021.06.01 16:18t/p200.011911.750.001911.756.131071.72
402021.06.01 17:54close190.011893.020.001915.21-15.001056.72
+
diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 7.gif b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 7.gif new file mode 100644 index 0000000..f23e029 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 7.gif differ diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 7.htm b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 7.htm new file mode 100644 index 0000000..0958fdd --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 7.htm @@ -0,0 +1,143 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.12.30 23:45 (2020.01.01 - 2021.12.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test25902Ticks modelled27850269Modelling quality24.91%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (50)
Total net profit126.08Gross profit187.55Gross loss-61.47
Profit factor3.05Expected payoff3.41
Absolute drawdown5.46Maximal drawdown29.68 (2.83%)Relative drawdown2.83% (29.68)
Total trades37Short positions (won %)0 (0.00%)Long positions (won %)37 (89.19%)
Profit trades (% of total)33 (89.19%)Loss trades (% of total)4 (10.81%)
Largestprofit trade17.10loss trade-15.50
Averageprofit trade5.68loss trade-15.37
Maximumconsecutive wins (profit in money)16 (83.15)consecutive losses (loss in money)1 (-15.50)
Maximalconsecutive profit (count of wins)83.15 (16)consecutive loss (count of losses)-15.50 (1)
Averageconsecutive wins8consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 01:49buy10.011840.510.001841.60
22020.12.04 02:34t/p10.011841.600.001841.601.091001.09
32020.12.16 17:07buy20.011851.060.001858.69
42020.12.16 21:52t/p20.011858.690.001858.697.631008.72
52020.12.21 15:09buy30.011872.170.001884.07
62020.12.21 15:48t/p30.011884.070.001884.0711.901020.62
72021.01.05 22:24buy40.011949.660.001952.93
82021.01.06 01:33t/p40.011952.930.001952.932.781023.40
92021.01.12 18:46buy50.011841.910.001846.47
102021.01.12 20:34t/p50.011846.470.001846.474.561027.96
112021.01.20 19:24buy60.011863.190.001870.20
122021.01.20 22:37t/p60.011870.200.001870.207.011034.97
132021.02.10 22:09buy70.011842.000.001846.21
142021.02.11 15:15t/p70.011846.210.001846.212.751037.72
152021.03.11 16:48buy80.011719.830.001736.10
162021.03.11 19:54buy90.011722.390.001725.88
172021.03.11 20:06t/p90.011725.880.001725.883.491041.21
182021.03.12 11:09close80.011704.830.001736.10-15.491025.73
192021.03.16 13:54buy100.011731.460.001735.44
202021.03.16 14:18t/p100.011735.440.001735.443.981029.71
212021.03.17 13:48buy110.011728.270.001737.00
222021.03.17 15:39buy120.011728.570.001731.81
232021.03.17 16:22t/p120.011731.810.001731.813.241032.95
242021.03.17 20:06t/p110.011737.000.001737.008.731041.68
252021.04.19 15:15buy130.011775.830.001787.89
262021.04.19 19:22buy140.011771.720.001776.60
272021.04.20 17:09t/p140.011776.600.001776.604.391046.07
282021.04.21 09:54t/p130.011787.890.001787.8911.091057.16
292021.04.27 18:22buy150.011779.370.001784.35
302021.04.28 12:24close150.011764.360.001784.35-15.501041.66
312021.05.19 22:00buy160.011863.390.001881.95
322021.05.20 01:22buy170.011869.260.001871.54
332021.05.20 03:54t/p170.011871.540.001871.542.281043.94
342021.05.20 19:49t/p160.011881.950.001881.9517.101061.04
352021.05.21 19:18buy180.011870.700.001876.84
362021.05.21 20:37t/p180.011876.840.001876.846.141067.18
372021.06.01 11:34buy190.011907.920.001915.21
382021.06.01 13:39buy200.011905.520.001911.75
392021.06.01 16:18t/p200.011911.750.001911.756.231073.41
402021.06.01 17:54close190.011892.920.001915.21-15.001058.41
412021.07.06 19:07buy210.011794.010.001807.68
422021.07.07 13:24t/p210.011807.680.001807.6813.181071.60
432021.07.08 18:04buy220.011801.860.001814.59
442021.07.13 15:39t/p220.011814.590.001814.5911.271082.87
452021.07.15 15:54buy230.011823.580.001828.43
462021.07.15 20:37t/p230.011828.430.001828.434.851087.72
472021.07.20 21:03buy240.011809.650.001811.85
482021.07.21 09:09t/p240.011811.850.001811.851.711089.43
492021.07.27 21:54buy250.011800.120.001801.88
502021.07.28 04:21t/p250.011801.880.001801.881.271090.71
512021.08.17 17:15buy260.011782.610.001792.83
522021.08.18 09:37t/p260.011792.830.001792.839.731100.44
532021.09.09 16:52buy270.011791.470.001794.24
542021.09.09 20:00t/p270.011794.240.001794.242.771103.21
552021.09.13 19:09buy280.011794.270.001797.46
562021.09.14 15:54t/p280.011797.460.001797.462.701105.91
572021.09.17 16:54buy290.011749.140.001753.88
582021.09.17 17:07t/p290.011753.880.001753.884.741110.65
592021.10.12 18:37buy300.011762.070.001764.41
602021.10.13 10:37t/p300.011764.410.001764.411.851112.51
612021.10.21 14:54buy310.011778.060.001787.33
622021.10.21 17:00buy320.011779.850.001785.79
632021.10.22 02:39t/p320.011785.790.001785.795.451117.96
642021.10.22 06:19t/p310.011787.330.001787.338.781126.75
652021.10.22 23:38buy330.011792.440.001794.37
662021.10.25 03:00t/p330.011794.370.001794.371.441128.19
672021.11.10 01:34buy340.011831.630.001832.49
682021.11.10 15:34t/p340.011832.490.001832.490.861129.05
692021.11.16 18:24buy350.011856.850.001864.27
702021.11.17 14:54t/p350.011864.270.001864.276.931135.98
712021.12.21 16:52buy360.011793.720.001799.79
722021.12.22 20:09t/p360.011799.790.001799.795.581141.57
732021.12.28 18:04buy370.011811.250.001815.71
742021.12.29 12:39close370.011796.250.001815.71-15.491126.08
+
diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 8.gif b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 8.gif new file mode 100644 index 0000000..dd48ba4 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 8.gif differ diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 8.htm b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 8.htm new file mode 100644 index 0000000..b123cfd --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 8.htm @@ -0,0 +1,175 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2022.12.30 20:45 (2020.01.01 - 2022.12.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test49605Ticks modelled54257661Modelling quality33.32%
Mismatched charts errors5
Initial deposit1000.00SpreadCurrent (50)
Total net profit157.15Gross profit267.02Gross loss-109.87
Profit factor2.43Expected payoff2.97
Absolute drawdown5.46Maximal drawdown56.48 (4.94%)Relative drawdown4.94% (56.48)
Total trades53Short positions (won %)0 (0.00%)Long positions (won %)53 (86.79%)
Profit trades (% of total)46 (86.79%)Loss trades (% of total)7 (13.21%)
Largestprofit trade18.22loss trade-16.46
Averageprofit trade5.80loss trade-15.70
Maximumconsecutive wins (profit in money)16 (83.15)consecutive losses (loss in money)2 (-31.95)
Maximalconsecutive profit (count of wins)83.15 (16)consecutive loss (count of losses)-31.95 (2)
Averageconsecutive wins7consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 01:49buy10.011840.510.001841.60
22020.12.04 02:34t/p10.011841.600.001841.601.091001.09
32020.12.16 17:07buy20.011851.060.001858.69
42020.12.16 21:52t/p20.011858.690.001858.697.631008.72
52020.12.21 15:09buy30.011872.170.001884.07
62020.12.21 15:48t/p30.011884.070.001884.0711.901020.62
72021.01.05 22:24buy40.011949.660.001952.93
82021.01.06 01:33t/p40.011952.930.001952.932.781023.40
92021.01.12 18:46buy50.011841.910.001846.47
102021.01.12 20:34t/p50.011846.470.001846.474.561027.96
112021.01.20 19:24buy60.011863.190.001870.20
122021.01.20 22:37t/p60.011870.200.001870.207.011034.97
132021.02.10 22:09buy70.011842.000.001846.21
142021.02.11 15:15t/p70.011846.210.001846.212.751037.72
152021.03.11 16:48buy80.011719.830.001736.10
162021.03.11 19:54buy90.011722.390.001725.88
172021.03.11 20:06t/p90.011725.880.001725.883.491041.21
182021.03.12 11:09close80.011704.830.001736.10-15.491025.73
192021.03.16 13:54buy100.011731.460.001735.44
202021.03.16 14:18t/p100.011735.440.001735.443.981029.71
212021.03.17 13:48buy110.011728.270.001737.00
222021.03.17 15:39buy120.011728.570.001731.81
232021.03.17 16:22t/p120.011731.810.001731.813.241032.95
242021.03.17 20:06t/p110.011737.000.001737.008.731041.68
252021.04.19 15:15buy130.011775.830.001787.89
262021.04.19 19:22buy140.011771.720.001776.60
272021.04.20 17:09t/p140.011776.600.001776.604.391046.07
282021.04.21 09:54t/p130.011787.890.001787.8911.091057.16
292021.04.27 18:22buy150.011779.370.001784.35
302021.04.28 12:24close150.011764.360.001784.35-15.501041.66
312021.05.19 22:00buy160.011863.390.001881.95
322021.05.20 01:22buy170.011869.260.001871.54
332021.05.20 03:54t/p170.011871.540.001871.542.281043.94
342021.05.20 19:49t/p160.011881.950.001881.9517.101061.04
352021.05.21 19:18buy180.011870.700.001876.84
362021.05.21 20:37t/p180.011876.840.001876.846.141067.18
372021.06.01 11:34buy190.011907.920.001915.21
382021.06.01 13:39buy200.011905.520.001911.75
392021.06.01 16:18t/p200.011911.750.001911.756.231073.41
402021.06.01 17:54close190.011892.920.001915.21-15.001058.41
412021.07.06 19:07buy210.011794.010.001807.68
422021.07.07 13:24t/p210.011807.680.001807.6813.181071.60
432021.07.08 18:04buy220.011801.860.001814.59
442021.07.13 15:39t/p220.011814.590.001814.5911.271082.87
452021.07.15 15:54buy230.011823.580.001828.43
462021.07.15 20:37t/p230.011828.430.001828.434.851087.72
472021.07.20 21:03buy240.011809.650.001811.85
482021.07.21 09:09t/p240.011811.850.001811.851.711089.43
492021.07.27 21:54buy250.011800.120.001801.88
502021.07.28 04:21t/p250.011801.880.001801.881.271090.71
512021.08.17 17:15buy260.011782.610.001792.83
522021.08.18 09:37t/p260.011792.830.001792.839.731100.44
532021.09.09 16:52buy270.011791.470.001794.24
542021.09.09 20:00t/p270.011794.240.001794.242.771103.21
552021.09.13 19:09buy280.011794.270.001797.46
562021.09.14 15:54t/p280.011797.460.001797.462.701105.91
572021.09.17 16:54buy290.011749.140.001753.88
582021.09.17 17:07t/p290.011753.880.001753.884.741110.65
592021.10.12 18:37buy300.011762.070.001764.41
602021.10.13 10:37t/p300.011764.410.001764.411.851112.51
612021.10.21 14:54buy310.011778.060.001787.33
622021.10.21 17:00buy320.011779.850.001785.79
632021.10.22 02:39t/p320.011785.790.001785.795.451117.96
642021.10.22 06:19t/p310.011787.330.001787.338.781126.75
652021.10.22 23:38buy330.011792.440.001794.37
662021.10.25 03:00t/p330.011794.370.001794.371.441128.19
672021.11.10 01:34buy340.011831.630.001832.49
682021.11.10 15:34t/p340.011832.490.001832.490.861129.05
692021.11.16 18:24buy350.011856.850.001864.27
702021.11.17 14:54t/p350.011864.270.001864.276.931135.98
712021.12.21 16:52buy360.011793.720.001799.79
722021.12.22 20:09t/p360.011799.790.001799.795.581141.57
732021.12.28 18:04buy370.011811.250.001815.71
742021.12.29 12:39close370.011796.250.001815.71-15.491126.08
752022.01.05 21:39buy380.011814.810.001818.13
762022.01.06 08:54close380.011799.810.001818.13-16.461109.62
772022.02.15 11:09buy390.011857.700.001877.87
782022.02.15 13:37buy400.011854.470.001857.60
792022.02.16 11:49t/p400.011857.600.001857.602.641112.26
802022.02.17 10:17t/p390.011877.870.001877.8718.221130.49
812022.02.22 12:24buy410.011896.110.001904.28
822022.02.22 15:30t/p410.011904.280.001904.288.171138.66
832022.04.26 17:36buy420.011901.270.001904.54
842022.04.26 17:38t/p420.011904.540.001904.543.271141.93
852022.05.23 09:02buy430.011854.300.001857.99
862022.05.23 11:08t/p430.011857.990.001857.993.691145.62
872022.05.27 18:03buy440.011853.000.001855.43
882022.05.30 04:37t/p440.011855.430.001855.431.941147.56
892022.07.27 16:43buy450.011715.740.001718.17
902022.07.27 18:17t/p450.011718.170.001718.172.431149.99
912022.09.14 19:18buy460.011702.510.001706.58
922022.09.15 07:56close460.011687.510.001706.58-16.461133.53
932022.09.30 20:35buy470.011663.060.001671.54
942022.10.03 16:16t/p470.011671.540.001671.547.991141.53
952022.11.30 17:18buy480.011751.820.001763.12
962022.11.30 20:08buy490.011751.520.001754.09
972022.11.30 20:33t/p490.011754.090.001754.092.571144.10
982022.11.30 21:20t/p480.011763.120.001763.1211.301155.40
992022.12.09 17:23buy500.011791.160.001800.19
1002022.12.09 18:20t/p500.011800.190.001800.199.031164.43
1012022.12.09 20:01buy510.011798.720.001805.93
1022022.12.12 17:37close510.011783.720.001805.93-15.491148.94
1032022.12.16 16:17buy520.011783.190.001787.72
1042022.12.16 16:48t/p520.011787.720.001787.724.531153.47
1052022.12.22 11:30buy530.011815.760.001819.44
1062022.12.22 15:20t/p530.011819.440.001819.443.681157.15
+
diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 9.gif b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 9.gif new file mode 100644 index 0000000..bf30e2f Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 9.gif differ diff --git a/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 9.htm b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 9.htm new file mode 100644 index 0000000..2f98b76 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Long/StrategyTester Long 9.htm @@ -0,0 +1,205 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.02 03:45 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63365Ticks modelled72611240Modelling qualityn/a
Mismatched charts errors808
Initial deposit1000.00SpreadCurrent (51)
Total net profit113.62Gross profit318.41Gross loss-204.79
Profit factor1.55Expected payoff1.67
Absolute drawdown5.48Maximal drawdown56.49 (4.95%)Relative drawdown4.95% (56.49)
Total trades68Short positions (won %)0 (0.00%)Long positions (won %)68 (80.88%)
Profit trades (% of total)55 (80.88%)Loss trades (% of total)13 (19.12%)
Largestprofit trade18.21loss trade-16.48
Averageprofit trade5.79loss trade-15.75
Maximumconsecutive wins (profit in money)16 (83.02)consecutive losses (loss in money)2 (-31.95)
Maximalconsecutive profit (count of wins)83.02 (16)consecutive loss (count of losses)-31.95 (2)
Averageconsecutive wins5consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 01:49buy10.011840.520.001841.60
22020.12.04 02:34t/p10.011841.600.001841.601.081001.08
32020.12.16 17:07buy20.011851.070.001858.69
42020.12.16 21:52t/p20.011858.690.001858.697.621008.70
52020.12.21 15:09buy30.011872.180.001884.07
62020.12.21 15:48t/p30.011884.070.001884.0711.891020.59
72021.01.05 22:24buy40.011949.670.001952.93
82021.01.06 01:33t/p40.011952.930.001952.932.771023.36
92021.01.12 18:46buy50.011841.920.001846.47
102021.01.12 20:34t/p50.011846.470.001846.474.551027.91
112021.01.20 19:24buy60.011863.200.001870.20
122021.01.20 22:37t/p60.011870.200.001870.207.001034.91
132021.02.10 22:09buy70.011842.010.001846.21
142021.02.11 15:15t/p70.011846.210.001846.212.741037.65
152021.03.11 16:48buy80.011719.840.001736.10
162021.03.11 19:54buy90.011722.400.001725.88
172021.03.11 20:06t/p90.011725.880.001725.883.481041.13
182021.03.12 11:09close80.011704.840.001736.10-15.491025.65
192021.03.16 13:54buy100.011731.470.001735.44
202021.03.16 14:18t/p100.011735.440.001735.443.971029.62
212021.03.17 13:48buy110.011728.280.001737.00
222021.03.17 15:39buy120.011728.580.001731.81
232021.03.17 16:22t/p120.011731.810.001731.813.231032.85
242021.03.17 20:06t/p110.011737.000.001737.008.721041.57
252021.04.19 15:15buy130.011775.840.001787.89
262021.04.19 19:22buy140.011771.730.001776.60
272021.04.20 17:09t/p140.011776.600.001776.604.381045.95
282021.04.21 09:54t/p130.011787.890.001787.8911.081057.03
292021.04.27 18:22buy150.011779.380.001784.35
302021.04.28 12:24close150.011764.380.001784.35-15.491041.54
312021.05.19 22:00buy160.011863.400.001881.95
322021.05.20 01:22buy170.011869.270.001871.54
332021.05.20 03:54t/p170.011871.540.001871.542.271043.81
342021.05.20 19:49t/p160.011881.950.001881.9517.091060.90
352021.05.21 19:18buy180.011870.710.001876.84
362021.05.21 20:37t/p180.011876.840.001876.846.131067.03
372021.06.01 11:34buy190.011907.930.001915.21
382021.06.01 13:39buy200.011905.530.001911.75
392021.06.01 16:18t/p200.011911.750.001911.756.221073.25
402021.06.01 17:54close190.011892.930.001915.21-15.001058.25
412021.07.06 19:07buy210.011794.020.001807.68
422021.07.07 13:24t/p210.011807.680.001807.6813.171071.43
432021.07.08 18:04buy220.011801.870.001814.59
442021.07.13 15:39t/p220.011814.590.001814.5911.261082.69
452021.07.15 15:54buy230.011823.590.001828.43
462021.07.15 20:37t/p230.011828.430.001828.434.841087.53
472021.07.20 21:03buy240.011809.660.001811.85
482021.07.21 09:09t/p240.011811.850.001811.851.701089.23
492021.07.27 21:54buy250.011800.130.001801.88
502021.07.28 04:21t/p250.011801.880.001801.881.261090.50
512021.08.17 17:15buy260.011782.620.001792.83
522021.08.18 09:37t/p260.011792.830.001792.839.721100.22
532021.09.09 16:52buy270.011791.480.001794.25
542021.09.09 20:00t/p270.011794.250.001794.252.771102.99
552021.09.13 19:09buy280.011794.280.001797.46
562021.09.14 15:54t/p280.011797.460.001797.462.691105.68
572021.09.17 16:54buy290.011749.150.001753.89
582021.09.17 17:07t/p290.011753.890.001753.894.741110.42
592021.10.12 18:37buy300.011762.080.001764.42
602021.10.13 10:37t/p300.011764.420.001764.421.851112.28
612021.10.21 14:54buy310.011778.070.001787.33
622021.10.21 17:00buy320.011779.860.001785.79
632021.10.22 02:39t/p320.011785.790.001785.795.441117.72
642021.10.22 06:19t/p310.011787.330.001787.338.771126.50
652021.10.22 23:38buy330.011792.450.001794.37
662021.10.25 03:00t/p330.011794.370.001794.371.431127.93
672021.11.10 01:34buy340.011831.640.001832.49
682021.11.10 15:34t/p340.011832.490.001832.490.851128.78
692021.11.16 18:24buy350.011856.860.001864.27
702021.11.17 14:54t/p350.011864.270.001864.276.921135.70
712021.12.21 16:52buy360.011793.730.001799.79
722021.12.22 20:09t/p360.011799.790.001799.795.571141.28
732021.12.28 18:04buy370.011811.260.001815.71
742021.12.29 12:39close370.011796.260.001815.71-15.491125.79
752022.01.05 21:39buy380.011814.820.001818.14
762022.01.06 08:54close380.011799.820.001818.14-16.461109.33
772022.02.15 11:09buy390.011857.710.001877.87
782022.02.15 13:37buy400.011854.480.001857.60
792022.02.16 11:49t/p400.011857.600.001857.602.631111.96
802022.02.17 10:17t/p390.011877.870.001877.8718.211130.18
812022.02.22 12:24buy410.011896.120.001904.28
822022.02.22 15:30t/p410.011904.280.001904.288.161138.34
832022.04.26 17:36buy420.011901.280.001904.54
842022.04.26 17:38t/p420.011904.540.001904.543.261141.60
852022.05.23 09:02buy430.011854.310.001857.99
862022.05.23 11:08t/p430.011857.990.001857.993.681145.28
872022.05.27 18:03buy440.011853.010.001855.44
882022.05.30 04:37t/p440.011855.440.001855.441.941147.22
892022.07.27 16:43buy450.011715.750.001718.18
902022.07.27 18:17t/p450.011718.180.001718.182.431149.65
912022.09.14 19:18buy460.011702.520.001706.58
922022.09.15 07:56close460.011687.510.001706.58-16.471133.18
932022.09.30 20:35buy470.011663.070.001671.54
942022.10.03 16:16t/p470.011671.540.001671.547.981141.17
952022.11.30 17:18buy480.011751.830.001763.12
962022.11.30 20:08buy490.011751.530.001754.09
972022.11.30 20:33t/p490.011754.090.001754.092.561143.73
982022.11.30 21:20t/p480.011763.120.001763.1211.291155.02
992022.12.09 17:23buy500.011791.170.001800.19
1002022.12.09 18:20t/p500.011800.190.001800.199.021164.04
1012022.12.09 20:01buy510.011798.730.001805.93
1022022.12.12 17:37close510.011783.730.001805.93-15.491148.55
1032022.12.16 16:17buy520.011783.200.001787.72
1042022.12.16 16:48t/p520.011787.720.001787.724.521153.07
1052022.12.22 11:30buy530.011815.770.001819.44
1062022.12.22 15:20t/p530.011819.440.001819.443.671156.74
1072023.01.03 03:27buy540.011827.900.001832.34
1082023.01.03 04:36t/p540.011832.340.001832.344.441161.18
1092023.01.03 21:27buy550.011837.150.001840.00
1102023.01.04 03:22t/p550.011840.000.001840.002.361163.55
1112023.01.11 01:24buy560.011876.970.001878.14
1122023.01.11 03:01t/p560.011878.140.001878.141.171164.72
1132023.01.11 12:42buy570.011883.460.001886.42
1142023.01.11 17:38buy580.011870.920.001878.90
1152023.01.11 18:06close570.011868.460.001886.42-15.001149.72
1162023.01.12 03:48t/p580.011878.900.001878.906.521156.24
1172023.02.02 18:35buy590.011917.600.001927.38
1182023.02.03 15:32close590.011902.570.001927.38-15.521140.72
1192023.02.16 13:52buy600.011836.280.001839.07
1202023.02.16 14:52t/p600.011839.070.001839.072.791143.51
1212023.03.16 17:38buy610.011915.530.001932.18
1222023.03.17 07:33t/p610.011932.180.001932.1816.161159.67
1232023.04.05 20:20buy620.012019.940.002023.78
1242023.04.06 16:44close620.012004.920.002023.78-16.481143.20
1252023.04.26 19:17buy630.011988.980.002001.19
1262023.04.27 08:13t/p630.012001.190.002001.1910.751153.95
1272023.05.24 17:20buy640.011967.210.001972.30
1282023.05.25 15:34close640.011952.210.001972.30-16.461137.49
1292023.05.26 17:32buy650.011946.410.001951.61
1302023.05.30 12:59t/p650.011951.610.001951.614.231141.71
1312023.06.16 19:16buy660.011955.530.001961.50
1322023.06.20 16:17close660.011940.530.001961.50-15.971125.74
1332023.07.13 18:51buy670.011957.830.001961.68
1342023.07.14 04:38t/p670.011961.680.001961.683.361129.11
1352023.07.20 17:09buy680.011972.700.001979.97
1362023.07.21 18:04close680.011957.700.001979.97-15.491113.62
+
diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 1.gif b/Docs/Reports/Tests/XTPW/Short/StrategyTester 1.gif new file mode 100644 index 0000000..c8bcbff Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Short/StrategyTester 1.gif differ diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 1.htm b/Docs/Reports/Tests/XTPW/Short/StrategyTester 1.htm new file mode 100644 index 0000000..72eae31 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Short/StrategyTester 1.htm @@ -0,0 +1,131 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.01.29 23:45 (2020.01.01 - 2021.01.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=false; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test4192Ticks modelled3544155Modelling quality24.42%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (50)
Total net profit2.71Gross profit201.38Gross loss-198.66
Profit factor1.01Expected payoff0.09
Absolute drawdown73.05Maximal drawdown109.12 (10.53%)Relative drawdown10.53% (109.12)
Total trades31Short positions (won %)31 (58.06%)Long positions (won %)0 (0.00%)
Profit trades (% of total)18 (58.06%)Loss trades (% of total)13 (41.94%)
Largestprofit trade42.22loss trade-20.63
Averageprofit trade11.19loss trade-15.28
Maximumconsecutive wins (profit in money)4 (21.10)consecutive losses (loss in money)2 (-35.42)
Maximalconsecutive profit (count of wins)79.26 (3)consecutive loss (count of losses)-35.42 (2)
Averageconsecutive wins2consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 15:15sell10.011793.480.001764.96
22020.11.30 04:54t/p10.011764.960.001764.9628.741028.74
32020.12.03 18:15sell20.011827.220.001807.22
42020.12.03 20:09sell30.011838.700.001833.83
52020.12.03 22:57close20.011842.220.001807.22-15.001013.74
62020.12.04 15:39t/p30.011833.830.001833.835.091018.83
72020.12.04 17:30sell40.011833.610.001805.03
82020.12.07 16:49close40.011848.610.001805.03-14.781004.05
92020.12.07 17:00sell50.011856.490.001855.05
102020.12.08 06:09close50.011871.490.001855.05-14.78989.27
112020.12.09 06:15sell60.011856.300.001836.32
122020.12.09 17:04sell70.011838.100.001789.48
132020.12.09 20:19t/p60.011836.320.001836.3219.981009.25
142020.12.10 18:36sell80.011836.090.001811.23
152020.12.11 22:30close70.011838.870.001789.480.111009.35
162020.12.15 06:54close80.011836.110.001811.230.641009.99
172020.12.16 15:30sell90.011854.090.001838.15
182020.12.16 22:00sell100.011861.180.001860.80
192020.12.16 22:09t/p100.011860.800.001860.800.381010.37
202020.12.17 07:03close90.011869.090.001838.15-14.34996.03
212020.12.21 02:45sell110.011889.000.001888.86
222020.12.21 03:03t/p110.011888.860.001888.860.14996.17
232020.12.21 12:15sell120.011868.580.001808.82
242020.12.21 14:09close120.011883.580.001808.82-15.00981.17
252020.12.22 18:00sell130.011861.400.001824.52
262020.12.23 16:49sell140.011875.360.001874.48
272020.12.23 16:49close130.011876.400.001824.52-14.78966.39
282020.12.23 17:07t/p140.011874.480.001874.480.88967.27
292020.12.30 17:01sell150.011887.550.001883.27
302021.01.04 01:00close150.011909.280.001883.27-20.63946.63
312021.01.05 18:03sell160.011942.890.001930.15
322021.01.06 10:45sell170.011954.750.001949.49
332021.01.06 11:54close160.011957.890.001930.15-14.78931.85
342021.01.06 13:53t/p170.011949.490.001949.495.26937.11
352021.01.06 14:00sell180.011944.910.001919.37
362021.01.06 17:36t/p180.011919.370.001919.3725.54962.65
372021.01.06 18:45sell190.011903.040.001847.52
382021.01.06 21:37close190.011918.040.001847.52-15.00947.65
392021.01.08 11:15sell200.011890.620.001854.26
402021.01.08 16:49sell210.011868.640.001826.64
412021.01.08 17:22t/p200.011854.260.001854.2636.36984.01
422021.01.11 03:21t/p210.011826.640.001826.6442.221026.23
432021.01.12 16:30sell220.011845.260.001814.58
442021.01.12 21:30sell230.011853.270.001852.59
452021.01.12 22:03t/p230.011852.590.001852.590.681026.91
462021.01.13 02:09close220.011860.260.001814.58-14.781012.13
472021.01.15 17:21sell240.011833.450.001814.53
482021.01.18 01:52t/p240.011814.530.001814.5319.141031.27
492021.01.20 15:15sell250.011834.880.001801.94
502021.01.20 16:02close250.011849.880.001801.94-15.001016.27
512021.01.20 17:00sell260.011855.310.001836.73
522021.01.20 17:48close260.011870.310.001836.73-15.001001.27
532021.01.25 18:15sell270.011847.450.001813.91
542021.01.27 17:30sell280.011846.730.001846.25
552021.01.27 17:37t/p280.011846.250.001846.250.481001.75
562021.01.28 15:45close270.011847.460.001813.911.091002.83
572021.01.28 16:15sell290.011859.180.001857.74
582021.01.28 16:24t/p290.011857.740.001857.741.441004.27
592021.01.28 19:30sell300.011840.890.001804.65
602021.01.29 12:39close300.011855.890.001804.65-14.78989.49
612021.01.29 17:09sell310.011861.150.001839.67
622021.01.29 23:58close at stop310.011847.930.001839.6713.221002.71
+
diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 10.gif b/Docs/Reports/Tests/XTPW/Short/StrategyTester 10.gif new file mode 100644 index 0000000..541a446 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Short/StrategyTester 10.gif differ diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 10.htm b/Docs/Reports/Tests/XTPW/Short/StrategyTester 10.htm new file mode 100644 index 0000000..79caca1 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Short/StrategyTester 10.htm @@ -0,0 +1,115 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.03.30 23:45 (2020.01.01 - 2021.03.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=false; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test8040Ticks modelled9476561Modelling quality24.70%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (50)
Total net profit63.78Gross profit168.72Gross loss-104.94
Profit factor1.61Expected payoff2.77
Absolute drawdown5.32Maximal drawdown61.21 (5.61%)Relative drawdown5.61% (61.21)
Total trades23Short positions (won %)23 (65.22%)Long positions (won %)0 (0.00%)
Profit trades (% of total)15 (65.22%)Loss trades (% of total)8 (34.78%)
Largestprofit trade23.92loss trade-15.00
Averageprofit trade11.25loss trade-13.12
Maximumconsecutive wins (profit in money)7 (58.67)consecutive losses (loss in money)4 (-46.03)
Maximalconsecutive profit (count of wins)58.67 (7)consecutive loss (count of losses)-46.03 (4)
Averageconsecutive wins3consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 15:15sell10.011793.480.001779.22
22020.11.27 15:52t/p10.011779.220.001779.2214.261014.26
32020.12.09 12:30sell20.011857.620.001849.31
42020.12.09 16:51t/p20.011849.310.001849.318.311022.57
52020.12.09 17:00sell30.011839.670.001815.36
62020.12.10 18:15sell40.011834.130.001818.44
72020.12.11 22:54close30.011839.680.001815.360.871023.44
82020.12.15 05:07close40.011834.140.001818.440.651024.08
92020.12.22 17:45sell50.011871.710.001862.42
102020.12.22 17:54t/p50.011862.420.001862.429.291033.37
112021.01.06 14:00sell60.011944.910.001932.14
122021.01.06 14:39t/p60.011932.140.001932.1412.771046.14
132021.01.06 15:45sell70.011935.140.001922.61
142021.01.06 17:24t/p70.011922.610.001922.6112.531058.67
152021.01.06 18:45sell80.011903.040.001874.79
162021.01.06 21:37close80.011918.040.001874.79-15.001043.67
172021.01.08 11:00sell90.011888.710.001867.68
182021.01.08 16:49sell100.011868.640.001844.72
192021.01.08 16:49t/p90.011867.680.001867.6821.031064.70
202021.01.08 19:24t/p100.011844.720.001844.7223.921088.62
212021.02.04 16:45sell110.011788.260.001757.14
222021.02.05 10:06close110.011803.260.001757.14-14.781073.84
232021.02.11 19:30sell120.011824.700.001810.16
242021.02.16 06:00close120.011826.610.001810.16-1.251072.59
252021.02.16 16:15sell130.011795.370.001773.85
262021.02.16 17:22close130.011810.370.001773.85-15.001057.59
272021.02.19 03:15sell140.011761.430.001747.66
282021.02.19 08:09close140.011776.430.001747.66-15.001042.59
292021.02.24 16:15sell150.011793.620.001778.74
302021.02.25 16:09t/p150.011778.740.001778.7415.541058.13
312021.02.26 17:07sell160.011740.570.001714.20
322021.03.01 08:24close160.011755.570.001714.20-14.781043.35
332021.03.04 20:31sell170.011702.790.001687.76
342021.03.05 03:09t/p170.011687.760.001687.7615.251058.60
352021.03.22 08:46sell180.011732.420.001723.47
362021.03.23 15:15sell190.011734.540.001728.17
372021.03.23 15:54t/p190.011728.170.001728.176.371064.97
382021.03.23 17:15sell200.011726.720.001719.77
392021.03.24 14:24close180.011732.430.001723.470.431065.39
402021.03.25 14:45sell210.011725.190.001717.21
412021.03.25 15:24close210.011740.190.001717.21-15.001050.39
422021.03.25 15:34close200.011741.720.001719.77-14.121036.27
432021.03.25 17:39sell220.011730.910.001720.87
442021.03.29 16:34t/p220.011720.870.001720.8710.481046.75
452021.03.29 16:45sell230.011711.000.001694.19
462021.03.30 13:54t/p230.011694.190.001694.1917.031063.78
+
diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 11.gif b/Docs/Reports/Tests/XTPW/Short/StrategyTester 11.gif new file mode 100644 index 0000000..d4616d9 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Short/StrategyTester 11.gif differ diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 11.htm b/Docs/Reports/Tests/XTPW/Short/StrategyTester 11.htm new file mode 100644 index 0000000..d7c91d1 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Short/StrategyTester 11.htm @@ -0,0 +1,91 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.03.30 23:45 (2020.01.01 - 2021.03.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=false; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test8040Ticks modelled9476561Modelling quality24.70%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (50)
Total net profit29.92Gross profit73.60Gross loss-43.69
Profit factor1.68Expected payoff2.72
Absolute drawdown6.86Maximal drawdown51.61 (4.84%)Relative drawdown4.84% (51.61)
Total trades11Short positions (won %)11 (72.73%)Long positions (won %)0 (0.00%)
Profit trades (% of total)8 (72.73%)Loss trades (% of total)3 (27.27%)
Largestprofit trade13.43loss trade-15.00
Averageprofit trade9.20loss trade-14.56
Maximumconsecutive wins (profit in money)5 (56.33)consecutive losses (loss in money)2 (-29.12)
Maximalconsecutive profit (count of wins)56.33 (5)consecutive loss (count of losses)-29.12 (2)
Averageconsecutive wins3consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.09 12:30sell10.011857.620.001849.31
22020.12.09 16:51t/p10.011849.310.001849.318.311008.31
32020.12.10 18:24sell20.011836.830.001823.84
42020.12.14 12:22t/p20.011823.840.001823.8413.431021.74
52020.12.22 17:45sell30.011871.710.001862.42
62020.12.22 17:54t/p30.011862.420.001862.429.291031.03
72021.01.06 14:00sell40.011944.910.001932.14
82021.01.06 14:39t/p40.011932.140.001932.1412.771043.80
92021.01.06 15:45sell50.011935.140.001922.61
102021.01.06 17:24t/p50.011922.610.001922.6112.531056.33
112021.03.04 21:09sell60.011696.260.001683.27
122021.03.08 01:21close60.011711.260.001683.27-14.561041.77
132021.03.22 08:46sell70.011732.420.001723.47
142021.03.23 15:15sell80.011734.540.001728.17
152021.03.23 15:54t/p80.011728.170.001728.176.371048.14
162021.03.23 17:15sell90.011726.720.001719.77
172021.03.24 14:24close70.011732.430.001723.470.431048.56
182021.03.25 14:45sell100.011725.190.001717.21
192021.03.25 15:24close100.011740.190.001717.21-15.001033.56
202021.03.25 15:34close90.011741.720.001719.77-14.121019.44
212021.03.25 17:39sell110.011730.910.001720.87
222021.03.29 16:34t/p110.011720.870.001720.8710.481029.92
+
diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 12.gif b/Docs/Reports/Tests/XTPW/Short/StrategyTester 12.gif new file mode 100644 index 0000000..7e93c6d Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Short/StrategyTester 12.gif differ diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 12.htm b/Docs/Reports/Tests/XTPW/Short/StrategyTester 12.htm new file mode 100644 index 0000000..057368e --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Short/StrategyTester 12.htm @@ -0,0 +1,81 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.03.30 23:45 (2020.01.01 - 2021.03.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=false; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test8040Ticks modelled9476561Modelling quality24.70%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (50)
Total net profit35.17Gross profit50.17Gross loss-15.00
Profit factor3.34Expected payoff5.86
Absolute drawdown6.86Maximal drawdown23.76 (2.33%)Relative drawdown2.33% (23.76)
Total trades6Short positions (won %)6 (83.33%)Long positions (won %)0 (0.00%)
Profit trades (% of total)5 (83.33%)Loss trades (% of total)1 (16.67%)
Largestprofit trade13.43loss trade-15.00
Averageprofit trade10.03loss trade-15.00
Maximumconsecutive wins (profit in money)5 (50.17)consecutive losses (loss in money)1 (-15.00)
Maximalconsecutive profit (count of wins)50.17 (5)consecutive loss (count of losses)-15.00 (1)
Averageconsecutive wins5consecutive losses1
+Graph
+ + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.09 12:30sell10.011857.620.001849.31
22020.12.09 16:51t/p10.011849.310.001849.318.311008.31
32020.12.10 18:24sell20.011836.830.001823.84
42020.12.14 12:22t/p20.011823.840.001823.8413.431021.74
52020.12.22 17:45sell30.011871.710.001862.42
62020.12.22 17:54t/p30.011862.420.001862.429.291031.03
72021.01.06 14:00sell40.011944.910.001932.14
82021.01.06 14:39t/p40.011932.140.001932.1412.771043.80
92021.03.23 15:15sell50.011734.540.001728.17
102021.03.23 15:54t/p50.011728.170.001728.176.371050.17
112021.03.25 14:45sell60.011725.190.001717.21
122021.03.25 15:24close60.011740.190.001717.21-15.001035.17
+
diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 13.gif b/Docs/Reports/Tests/XTPW/Short/StrategyTester 13.gif new file mode 100644 index 0000000..8e75c52 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Short/StrategyTester 13.gif differ diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 13.htm b/Docs/Reports/Tests/XTPW/Short/StrategyTester 13.htm new file mode 100644 index 0000000..b78cc40 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Short/StrategyTester 13.htm @@ -0,0 +1,139 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.01 23:45 (2020.01.01 - 2023.08.02)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=false; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63353Ticks modelled72601176Modelling qualityn/a
Mismatched charts errors808
Initial deposit1000.00SpreadCurrent (59)
Total net profit109.29Gross profit182.54Gross loss-73.25
Profit factor2.49Expected payoff3.12
Absolute drawdown5.99Maximal drawdown31.30 (2.90%)Relative drawdown2.90% (31.30)
Total trades35Short positions (won %)35 (85.71%)Long positions (won %)0 (0.00%)
Profit trades (% of total)30 (85.71%)Loss trades (% of total)5 (14.29%)
Largestprofit trade22.02loss trade-15.00
Averageprofit trade6.08loss trade-14.65
Maximumconsecutive wins (profit in money)10 (62.88)consecutive losses (loss in money)1 (-15.00)
Maximalconsecutive profit (count of wins)62.88 (10)consecutive loss (count of losses)-15.00 (1)
Averageconsecutive wins5consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 17:39sell10.011836.610.001825.20
22020.12.07 10:37t/p10.011825.200.001825.2011.631011.63
32021.01.29 16:54sell20.011865.800.001855.99
42021.01.29 19:22t/p20.011855.990.001855.999.811021.44
52021.02.09 17:45sell30.011841.990.001838.33
62021.02.09 18:09t/p30.011838.330.001838.333.661025.10
72021.02.10 17:00sell40.011841.300.001827.41
82021.02.11 19:09t/p40.011827.410.001827.4114.551039.65
92021.02.16 17:09sell50.011804.040.001801.47
102021.02.16 18:49t/p50.011801.470.001801.472.571042.22
112021.03.03 16:51sell60.011712.530.001708.07
122021.03.03 17:36t/p60.011708.070.001708.074.461046.68
132021.05.10 17:45sell70.011839.580.001833.85
142021.05.11 03:39t/p70.011833.850.001833.855.951052.63
152021.07.13 17:21sell80.011811.750.001808.46
162021.07.13 20:37t/p80.011808.460.001808.463.291055.92
172021.08.20 17:39sell90.011781.750.001777.75
182021.08.23 03:16t/p90.011777.750.001777.754.221060.13
192021.08.31 15:30sell100.011811.860.001809.11
202021.08.31 16:04t/p100.011809.110.001809.112.751062.88
212021.10.27 18:09sell110.011793.560.001789.11
222021.10.28 16:30close110.011808.560.001789.11-14.341048.54
232021.11.03 04:00sell120.011783.060.001779.26
242021.11.03 08:16t/p120.011779.260.001779.263.801052.34
252021.11.30 17:48sell130.011794.770.001781.02
262021.11.30 18:04t/p130.011781.020.001781.0213.751066.09
272021.12.13 16:49sell140.011785.140.001782.99
282021.12.14 10:24t/p140.011782.990.001782.992.371068.46
292021.12.15 16:54sell150.011769.740.001766.01
302021.12.15 17:39t/p150.011766.010.001766.013.731072.19
312021.12.20 17:01sell160.011793.800.001789.41
322021.12.20 22:09t/p160.011789.410.001789.414.391076.58
332022.01.18 18:19sell170.011813.030.001806.19
342022.01.19 16:51close170.011828.030.001806.19-14.781061.80
352022.02.18 17:33sell180.011895.770.001893.21
362022.02.18 17:37t/p180.011893.210.001893.212.561064.36
372022.03.02 18:16sell190.011921.470.001907.56
382022.03.03 13:34close190.011936.470.001907.56-14.341050.02
392022.04.22 19:22sell200.011936.790.001932.93
402022.04.22 20:28t/p200.011932.930.001932.933.861053.88
412022.04.26 16:08sell210.011905.800.001905.21
422022.04.26 16:57t/p210.011905.210.001905.210.591054.47
432022.06.10 16:01sell220.011839.900.001834.17
442022.06.10 16:18t/p220.011834.170.001834.175.731060.20
452022.07.20 16:52sell230.011708.520.001702.79
462022.07.20 19:48t/p230.011702.790.001702.795.731065.93
472022.08.02 18:02sell240.011776.930.001767.92
482022.08.02 21:02t/p240.011767.920.001767.929.011074.94
492022.11.02 21:03sell250.011647.760.001626.40
502022.11.03 10:26t/p250.011626.400.001626.4022.021096.95
512023.01.12 17:10sell260.011884.680.001867.96
522023.01.12 21:03close260.011899.680.001867.96-15.001081.95
532023.02.07 16:32sell270.011869.860.001868.93
542023.02.07 16:45t/p270.011868.930.001868.930.931082.88
552023.02.09 17:00sell280.011879.160.001868.22
562023.02.09 18:03t/p280.011868.220.001868.2210.941093.82
572023.03.02 20:35sell290.011835.870.001834.78
582023.03.03 21:27close290.011850.870.001834.78-14.781079.04
592023.05.15 17:34sell300.012016.660.002011.32
602023.05.16 09:05t/p300.012011.320.002011.325.561084.60
612023.05.26 17:09sell310.011951.200.001949.72
622023.05.26 17:19t/p310.011949.720.001949.721.481086.08
632023.06.07 17:32sell320.011958.950.001947.93
642023.06.07 18:51t/p320.011947.930.001947.9311.021097.10
652023.07.13 18:04sell330.011959.610.001957.54
662023.07.13 18:51t/p330.011957.540.001957.542.071099.17
672023.07.19 18:12sell340.011974.940.001970.18
682023.07.20 17:35t/p340.011970.180.001970.185.421104.59
692023.07.25 15:30sell350.011958.580.001953.88
702023.07.25 17:00t/p350.011953.880.001953.884.701109.29
+
diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 2.gif b/Docs/Reports/Tests/XTPW/Short/StrategyTester 2.gif new file mode 100644 index 0000000..078a8d6 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Short/StrategyTester 2.gif differ diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 2.htm b/Docs/Reports/Tests/XTPW/Short/StrategyTester 2.htm new file mode 100644 index 0000000..0abf346 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Short/StrategyTester 2.htm @@ -0,0 +1,129 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.01.29 23:45 (2020.01.01 - 2021.01.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=false; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test4192Ticks modelled3544155Modelling quality24.42%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (50)
Total net profit-10.54Gross profit123.62Gross loss-134.15
Profit factor0.92Expected payoff-0.35
Absolute drawdown33.64Maximal drawdown56.13 (5.49%)Relative drawdown5.49% (56.13)
Total trades30Short positions (won %)30 (70.00%)Long positions (won %)0 (0.00%)
Profit trades (% of total)21 (70.00%)Loss trades (% of total)9 (30.00%)
Largestprofit trade20.64loss trade-15.02
Averageprofit trade5.89loss trade-14.91
Maximumconsecutive wins (profit in money)6 (22.03)consecutive losses (loss in money)2 (-30.01)
Maximalconsecutive profit (count of wins)31.16 (2)consecutive loss (count of losses)-30.01 (2)
Averageconsecutive wins3consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 15:49sell10.011781.870.001768.94
22020.11.30 04:54t/p10.011768.940.001768.9413.151013.15
32020.12.03 19:45sell20.011837.710.001837.54
42020.12.03 19:52t/p20.011837.540.001837.540.171013.32
52020.12.04 18:03sell30.011830.530.001822.23
62020.12.07 16:39close30.011845.530.001822.23-14.78998.54
72020.12.07 17:00sell40.011857.900.001857.90
82020.12.08 16:36close40.011872.900.001857.90-14.78983.76
92020.12.09 12:33sell50.011857.610.001853.45
102020.12.09 13:39t/p50.011853.450.001853.454.16987.92
112020.12.09 17:00sell60.011839.660.001827.50
122020.12.09 20:54t/p60.011827.500.001827.5012.161000.08
132020.12.10 18:15sell70.011834.110.001826.26
142020.12.11 13:24t/p70.011826.260.001826.268.071008.15
152020.12.16 15:30sell80.011852.750.001848.10
162020.12.16 21:19t/p80.011848.100.001848.104.651012.80
172020.12.16 22:00sell90.011861.530.001861.53
182020.12.16 22:09t/p90.011861.530.001861.530.001012.80
192020.12.21 03:01sell100.011888.990.001888.58
202020.12.21 08:07close100.011904.000.001888.58-15.01997.79
212020.12.21 12:15sell110.011868.410.001853.39
222020.12.21 14:09close110.011883.410.001853.39-15.00982.79
232020.12.22 17:45sell120.011871.700.001867.05
242020.12.22 17:52t/p120.011867.050.001867.054.65987.44
252020.12.23 16:52sell130.011877.210.001877.21
262020.12.23 16:58t/p130.011877.210.001877.210.00987.44
272020.12.29 18:45sell140.011882.910.001879.65
282020.12.29 19:21t/p140.011879.650.001879.653.26990.70
292021.01.05 18:45sell150.011948.570.001947.82
302021.01.06 03:24t/p150.011947.820.001947.820.97991.67
312021.01.06 14:03sell160.011943.910.001937.03
322021.01.06 14:37t/p160.011937.030.001937.036.88998.55
332021.01.06 15:51sell170.011935.120.001928.85
342021.01.06 16:39t/p170.011928.850.001928.856.271004.82
352021.01.06 18:48sell180.011902.080.001887.48
362021.01.06 21:36close180.011917.080.001887.48-15.00989.82
372021.01.08 11:03sell190.011888.700.001878.18
382021.01.08 15:39t/p190.011878.180.001878.1810.521000.34
392021.01.08 17:24sell200.011851.280.001830.64
402021.01.08 20:24t/p200.011830.640.001830.6420.641020.98
412021.01.12 16:15sell210.011839.410.001828.66
422021.01.12 21:30sell220.011853.470.001853.33
432021.01.12 21:30close210.011854.430.001828.66-15.021005.96
442021.01.12 21:39t/p220.011853.330.001853.330.141006.10
452021.01.15 17:04sell230.011839.110.001833.48
462021.01.15 17:09t/p230.011833.480.001833.485.631011.73
472021.01.19 15:15sell240.011835.380.001830.73
482021.01.20 04:54close240.011850.380.001830.73-14.78996.94
492021.01.20 15:48sell250.011845.500.001839.65
502021.01.20 16:22close250.011860.500.001839.65-15.00981.94
512021.01.25 18:04sell260.011851.850.001844.90
522021.01.27 03:54t/p260.011844.900.001844.907.39989.33
532021.01.27 17:15sell270.011843.380.001839.89
542021.01.27 22:39t/p270.011839.890.001839.893.49992.82
552021.01.28 16:00sell280.011856.950.001855.88
562021.01.28 16:54t/p280.011855.880.001855.881.07993.89
572021.01.28 19:19sell290.011842.140.001832.37
582021.01.29 12:49close290.011857.140.001832.37-14.78979.11
592021.01.29 16:45sell300.011854.900.001844.55
602021.01.29 22:52t/p300.011844.550.001844.5510.35989.46
+
diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 3.gif b/Docs/Reports/Tests/XTPW/Short/StrategyTester 3.gif new file mode 100644 index 0000000..27f550b Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Short/StrategyTester 3.gif differ diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 3.htm b/Docs/Reports/Tests/XTPW/Short/StrategyTester 3.htm new file mode 100644 index 0000000..8b56762 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Short/StrategyTester 3.htm @@ -0,0 +1,141 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.01.29 23:45 (2020.01.01 - 2021.01.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=false; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test4192Ticks modelled3544155Modelling quality24.42%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (59)
Total net profit27.33Gross profit250.32Gross loss-223.00
Profit factor1.12Expected payoff0.76
Absolute drawdown63.41Maximal drawdown110.43 (10.55%)Relative drawdown10.55% (110.43)
Total trades36Short positions (won %)36 (58.33%)Long positions (won %)0 (0.00%)
Profit trades (% of total)21 (58.33%)Loss trades (% of total)15 (41.67%)
Largestprofit trade42.22loss trade-15.61
Averageprofit trade11.92loss trade-14.87
Maximumconsecutive wins (profit in money)5 (38.49)consecutive losses (loss in money)3 (-44.78)
Maximalconsecutive profit (count of wins)84.28 (2)consecutive loss (count of losses)-44.78 (3)
Averageconsecutive wins2consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 15:15sell10.011793.480.001764.96
22020.11.30 04:54t/p10.011764.960.001764.9628.741028.74
32020.12.03 18:15sell20.011827.220.001807.22
42020.12.03 20:09sell30.011838.700.001838.70
52020.12.03 20:19t/p30.011838.700.001838.700.001028.74
62020.12.03 22:57close20.011842.220.001807.22-15.001013.74
72020.12.04 17:30sell40.011833.610.001805.03
82020.12.07 16:49close40.011848.620.001805.03-14.79998.95
92020.12.07 17:00sell50.011856.490.001855.05
102020.12.08 06:07close50.011871.490.001855.05-14.78984.17
112020.12.09 06:15sell60.011856.300.001836.32
122020.12.09 12:30sell70.011857.620.001841.00
132020.12.09 16:58t/p70.011841.000.001841.0016.621000.79
142020.12.09 17:00sell80.011839.670.001791.05
152020.12.09 20:19t/p60.011836.320.001836.3219.981020.77
162020.12.10 18:15sell90.011834.130.001802.75
172020.12.11 22:33close80.011839.680.001791.050.871021.63
182020.12.15 05:06close90.011834.140.001802.750.651022.28
192020.12.16 15:30sell100.011854.090.001838.15
202020.12.16 22:00sell110.011861.180.001860.80
212020.12.16 22:18t/p110.011860.800.001860.800.381022.66
222020.12.17 07:03close100.011869.090.001838.15-14.341008.32
232020.12.21 02:45sell120.011889.000.001888.86
242020.12.21 04:30sell130.011896.270.001890.35
252020.12.21 08:07close120.011904.000.001888.86-15.00993.32
262020.12.21 11:49t/p130.011890.350.001890.355.92999.24
272020.12.21 12:15sell140.011868.580.001808.82
282020.12.21 14:09close140.011883.580.001808.82-15.00984.24
292020.12.22 17:45sell150.011871.710.001853.13
302020.12.23 16:49sell160.011875.360.001874.48
312020.12.23 17:07t/p160.011874.480.001874.480.88985.12
322020.12.28 01:00close150.011888.630.001853.13-15.61969.51
332020.12.29 18:45sell170.011882.910.001876.39
342020.12.30 17:01sell180.011887.550.001887.55
352020.12.30 17:05t/p180.011887.550.001887.550.00969.51
362020.12.31 03:06close170.011897.910.001876.39-14.12955.39
372021.01.05 18:03sell190.011942.890.001930.15
382021.01.06 10:45sell200.011954.750.001954.75
392021.01.06 10:52t/p200.011954.750.001954.750.00955.39
402021.01.06 11:54close190.011957.890.001930.15-14.78940.61
412021.01.06 14:00sell210.011944.910.001919.37
422021.01.06 15:45sell220.011935.140.001910.08
432021.01.06 17:37t/p210.011919.370.001919.3725.54966.15
442021.01.06 17:49t/p220.011910.080.001910.0825.06991.21
452021.01.06 18:45sell230.011903.040.001847.52
462021.01.06 21:37close230.011918.040.001847.52-15.00976.21
472021.01.08 11:00sell240.011888.710.001846.65
482021.01.08 16:49sell250.011868.640.001826.64
492021.01.08 19:22t/p240.011846.650.001846.6542.061018.27
502021.01.11 03:21t/p250.011826.640.001826.6442.221060.49
512021.01.12 16:15sell260.011839.420.001796.42
522021.01.12 21:30sell270.011853.270.001852.59
532021.01.12 21:30close260.011854.430.001796.42-15.011045.48
542021.01.13 11:09t/p270.011852.590.001852.590.901046.38
552021.01.15 17:00sell280.011839.120.001816.62
562021.01.18 01:51t/p280.011816.620.001816.6222.721069.10
572021.01.19 15:15sell290.011835.390.001816.79
582021.01.20 04:52close290.011850.390.001816.79-14.781054.31
592021.01.20 15:15sell300.011834.880.001801.94
602021.01.20 15:54close300.011849.880.001801.94-15.001039.31
612021.01.20 17:00sell310.011855.310.001836.73
622021.01.20 17:46close310.011870.310.001836.73-15.001024.31
632021.01.25 18:00sell320.011851.860.001824.06
642021.01.27 17:15sell330.011843.370.001836.37
652021.01.28 03:24t/p330.011836.370.001836.377.661031.97
662021.01.28 15:46close320.011851.870.001824.061.091033.06
672021.01.28 16:00sell340.011856.940.001854.78
682021.01.28 16:54t/p340.011854.780.001854.782.161035.22
692021.01.28 19:15sell350.011842.150.001803.07
702021.01.29 12:49close350.011857.150.001803.07-14.781020.44
712021.01.29 16:45sell360.011854.910.001813.51
722021.01.29 23:58close at stop360.011848.020.001813.516.891027.33
+
diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 4.gif b/Docs/Reports/Tests/XTPW/Short/StrategyTester 4.gif new file mode 100644 index 0000000..c325728 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Short/StrategyTester 4.gif differ diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 4.htm b/Docs/Reports/Tests/XTPW/Short/StrategyTester 4.htm new file mode 100644 index 0000000..dd2646e --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Short/StrategyTester 4.htm @@ -0,0 +1,115 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.01.29 23:45 (2020.01.01 - 2021.01.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=false; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test4192Ticks modelled3544155Modelling quality24.42%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (51)
Total net profit68.47Gross profit232.50Gross loss-164.02
Profit factor1.42Expected payoff2.98
Absolute drawdown26.54Maximal drawdown88.50 (8.33%)Relative drawdown8.33% (88.50)
Total trades23Short positions (won %)23 (52.17%)Long positions (won %)0 (0.00%)
Profit trades (% of total)12 (52.17%)Loss trades (% of total)11 (47.83%)
Largestprofit trade42.22loss trade-15.53
Averageprofit trade19.37loss trade-14.91
Maximumconsecutive wins (profit in money)4 (38.10)consecutive losses (loss in money)4 (-59.65)
Maximalconsecutive profit (count of wins)84.28 (2)consecutive loss (count of losses)-59.65 (4)
Averageconsecutive wins2consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 15:15sell10.011793.480.001764.96
22020.11.30 04:54t/p10.011764.960.001764.9628.741028.74
32020.12.03 18:15sell20.011827.220.001807.22
42020.12.03 22:57close20.011842.220.001807.22-15.001013.74
52020.12.04 17:30sell30.011833.610.001805.03
62020.12.07 16:49close30.011848.620.001805.03-14.79998.95
72020.12.09 06:15sell40.011856.300.001836.32
82020.12.09 12:30sell50.011857.620.001841.00
92020.12.09 16:58t/p50.011841.000.001841.0016.621015.57
102020.12.09 17:00sell60.011839.670.001791.05
112020.12.09 20:19t/p40.011836.320.001836.3219.981035.55
122020.12.10 18:15sell70.011834.130.001802.75
132020.12.11 22:54close60.011839.690.001791.050.861036.40
142020.12.15 05:06close70.011834.140.001802.750.651037.05
152020.12.16 15:30sell80.011854.090.001838.15
162020.12.17 07:03close80.011869.090.001838.15-14.341022.71
172020.12.21 12:15sell90.011868.580.001808.82
182020.12.21 14:09close90.011883.580.001808.82-15.001007.71
192020.12.22 17:45sell100.011871.710.001853.13
202020.12.28 01:00close100.011888.550.001853.13-15.53992.18
212021.01.05 18:03sell110.011942.890.001930.15
222021.01.06 11:54close110.011957.890.001930.15-14.78977.40
232021.01.06 14:00sell120.011944.910.001919.37
242021.01.06 15:45sell130.011935.140.001910.08
252021.01.06 17:36t/p120.011919.370.001919.3725.541002.94
262021.01.06 17:49t/p130.011910.080.001910.0825.061028.00
272021.01.06 18:45sell140.011903.040.001847.52
282021.01.06 21:37close140.011918.040.001847.52-15.001013.00
292021.01.08 11:00sell150.011888.710.001846.65
302021.01.08 16:49sell160.011868.640.001826.64
312021.01.08 19:22t/p150.011846.650.001846.6542.061055.06
322021.01.11 03:21t/p160.011826.640.001826.6442.221097.28
332021.01.12 16:15sell170.011839.420.001796.42
342021.01.12 21:30close170.011854.440.001796.42-15.021082.26
352021.01.15 17:00sell180.011839.120.001816.62
362021.01.18 01:51t/p180.011816.620.001816.6222.721104.98
372021.01.19 15:15sell190.011835.390.001816.79
382021.01.20 04:54close190.011850.390.001816.79-14.781090.20
392021.01.20 15:15sell200.011834.880.001801.94
402021.01.20 16:02close200.011849.880.001801.94-15.001075.20
412021.01.25 18:00sell210.011851.860.001824.06
422021.01.28 15:46close210.011851.870.001824.061.091076.29
432021.01.28 19:15sell220.011842.150.001803.07
442021.01.29 12:49close220.011857.150.001803.07-14.781061.50
452021.01.29 16:45sell230.011854.910.001813.51
462021.01.29 23:58close at stop230.011847.940.001813.516.971068.47
+
diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 5.gif b/Docs/Reports/Tests/XTPW/Short/StrategyTester 5.gif new file mode 100644 index 0000000..b163183 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Short/StrategyTester 5.gif differ diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 5.htm b/Docs/Reports/Tests/XTPW/Short/StrategyTester 5.htm new file mode 100644 index 0000000..b899130 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Short/StrategyTester 5.htm @@ -0,0 +1,105 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.01.29 23:45 (2020.01.01 - 2021.01.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=false; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test4192Ticks modelled3544155Modelling quality24.42%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (51)
Total net profit42.18Gross profit131.55Gross loss-89.37
Profit factor1.47Expected payoff2.34
Absolute drawdown13.15Maximal drawdown48.26 (4.51%)Relative drawdown4.55% (47.52)
Total trades18Short positions (won %)18 (66.67%)Long positions (won %)0 (0.00%)
Profit trades (% of total)12 (66.67%)Loss trades (% of total)6 (33.33%)
Largestprofit trade23.92loss trade-15.02
Averageprofit trade10.96loss trade-14.90
Maximumconsecutive wins (profit in money)4 (65.18)consecutive losses (loss in money)2 (-29.78)
Maximalconsecutive profit (count of wins)65.18 (4)consecutive loss (count of losses)-29.78 (2)
Averageconsecutive wins2consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 15:18sell10.011792.300.001776.86
22020.11.27 15:54t/p10.011776.860.001776.8615.441015.44
32020.12.04 18:15sell20.011833.750.001821.09
42020.12.07 16:49close20.011848.760.001821.09-14.791000.65
52020.12.09 06:30sell30.011857.560.001849.00
62020.12.09 12:30sell40.011857.620.001849.31
72020.12.09 16:51t/p40.011849.310.001849.318.311008.96
82020.12.09 16:53t/p30.011849.000.001849.008.561017.52
92020.12.09 17:00sell50.011839.670.001815.36
102020.12.10 18:15sell60.011834.130.001818.44
112020.12.11 22:54close50.011839.690.001815.360.861018.38
122020.12.15 05:06close60.011834.140.001818.440.651019.02
132020.12.21 13:00sell70.011870.400.001843.42
142020.12.21 16:37close70.011885.400.001843.42-15.001004.02
152020.12.22 17:45sell80.011871.710.001862.42
162020.12.22 17:54t/p80.011862.420.001862.429.291013.31
172021.01.06 14:30sell90.011946.740.001935.80
182021.01.06 14:37t/p90.011935.800.001935.8010.941024.25
192021.01.08 11:00sell100.011888.710.001867.68
202021.01.08 16:49sell110.011868.640.001844.72
212021.01.08 16:49t/p100.011867.680.001867.6821.031045.28
222021.01.08 19:24t/p110.011844.720.001844.7223.921069.20
232021.01.12 16:15sell120.011839.420.001817.92
242021.01.12 21:30close120.011854.440.001817.92-15.021054.18
252021.01.15 17:00sell130.011839.120.001827.87
262021.01.15 17:54t/p130.011827.870.001827.8711.251065.43
272021.01.19 15:15sell140.011835.390.001826.09
282021.01.20 04:54close140.011850.390.001826.09-14.781050.65
292021.01.20 15:18sell150.011832.930.001814.51
302021.01.20 15:51close150.011847.930.001814.51-15.001035.65
312021.01.25 18:00sell160.011851.860.001837.96
322021.01.27 14:18t/p160.011837.960.001837.9614.341049.99
332021.01.28 19:15sell170.011842.150.001822.61
342021.01.29 12:49close170.011857.150.001822.61-14.781035.21
352021.01.29 16:45sell180.011854.910.001834.21
362021.01.29 23:58close at stop180.011847.940.001834.216.971042.18
+
diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 6.gif b/Docs/Reports/Tests/XTPW/Short/StrategyTester 6.gif new file mode 100644 index 0000000..90ff806 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Short/StrategyTester 6.gif differ diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 6.htm b/Docs/Reports/Tests/XTPW/Short/StrategyTester 6.htm new file mode 100644 index 0000000..17a4a78 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Short/StrategyTester 6.htm @@ -0,0 +1,105 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.01.29 23:45 (2020.01.01 - 2021.01.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=false; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test4192Ticks modelled3544155Modelling quality24.42%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (56)
Total net profit53.14Gross profit127.71Gross loss-74.57
Profit factor1.71Expected payoff2.95
Absolute drawdown6.56Maximal drawdown48.25 (4.46%)Relative drawdown4.46% (48.25)
Total trades18Short positions (won %)18 (72.22%)Long positions (won %)0 (0.00%)
Profit trades (% of total)13 (72.22%)Loss trades (% of total)5 (27.78%)
Largestprofit trade23.92loss trade-15.01
Averageprofit trade9.82loss trade-14.91
Maximumconsecutive wins (profit in money)6 (35.50)consecutive losses (loss in money)2 (-29.78)
Maximalconsecutive profit (count of wins)59.71 (4)consecutive loss (count of losses)-29.78 (2)
Averageconsecutive wins3consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 15:18sell10.011792.300.001784.58
22020.11.27 15:39t/p10.011784.580.001784.587.721007.72
32020.12.04 18:15sell20.011833.750.001827.42
42020.12.07 10:34t/p20.011827.420.001827.426.551014.27
52020.12.09 06:30sell30.011857.560.001853.28
62020.12.09 12:30sell40.011857.620.001853.47
72020.12.09 13:39t/p40.011853.470.001853.474.151018.42
82020.12.09 13:39t/p30.011853.280.001853.284.281022.70
92020.12.09 17:00sell50.011839.670.001827.52
102020.12.09 20:54t/p50.011827.520.001827.5212.151034.85
112020.12.10 18:15sell60.011834.130.001818.44
122020.12.15 05:06close60.011834.140.001818.440.651035.50
132020.12.21 13:00sell70.011870.400.001856.91
142020.12.21 16:37close70.011885.400.001856.91-15.001020.50
152020.12.22 17:45sell80.011871.710.001862.42
162020.12.22 17:54t/p80.011862.420.001862.429.291029.79
172021.01.06 14:30sell90.011946.740.001941.27
182021.01.06 14:34t/p90.011941.270.001941.275.471035.26
192021.01.08 11:00sell100.011888.710.001867.68
202021.01.08 16:49sell110.011868.640.001844.72
212021.01.08 16:49t/p100.011867.680.001867.6821.031056.29
222021.01.08 19:24t/p110.011844.720.001844.7223.921080.21
232021.01.12 16:15sell120.011839.420.001817.92
242021.01.12 21:30close120.011854.430.001817.92-15.011065.20
252021.01.15 17:00sell130.011839.120.001827.87
262021.01.15 17:54t/p130.011827.870.001827.8711.251076.45
272021.01.19 15:15sell140.011835.390.001826.09
282021.01.20 04:54close140.011850.390.001826.09-14.781061.67
292021.01.20 15:18sell150.011832.930.001823.72
302021.01.20 15:51close150.011847.930.001823.72-15.001046.67
312021.01.25 18:00sell160.011851.860.001837.96
322021.01.27 14:18t/p160.011837.960.001837.9614.341061.00
332021.01.28 19:15sell170.011842.150.001822.61
342021.01.29 12:49close170.011857.150.001822.61-14.781046.22
352021.01.29 16:45sell180.011854.910.001834.21
362021.01.29 23:58close at stop180.011847.990.001834.216.921053.14
+
diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 7.gif b/Docs/Reports/Tests/XTPW/Short/StrategyTester 7.gif new file mode 100644 index 0000000..9b794f2 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Short/StrategyTester 7.gif differ diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 7.htm b/Docs/Reports/Tests/XTPW/Short/StrategyTester 7.htm new file mode 100644 index 0000000..68db091 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Short/StrategyTester 7.htm @@ -0,0 +1,178 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.01.29 23:45 (2020.01.01 - 2021.01.31)
ModelEvery tick (the most precise method based on all available least timeframes)
Bars in test4192Ticks modelled3544155Modelling quality24.42%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (51)
Total net profit-63.19Gross profit205.91Gross loss-269.09
Profit factor0.77Expected payoff-1.04
Absolute drawdown82.91Maximal drawdown126.05 (12.08%)Relative drawdown12.08% (126.05)
Total trades61Short positions (won %)61 (70.49%)Long positions (won %)0 (0.00%)
Profit trades (% of total)43 (70.49%)Loss trades (% of total)18 (29.51%)
Largestprofit trade22.19loss trade-16.92
Averageprofit trade4.79loss trade-14.95
Maximumconsecutive wins (profit in money)11 (39.60)consecutive losses (loss in money)2 (-31.70)
Maximalconsecutive profit (count of wins)39.60 (11)consecutive loss (count of losses)-31.70 (2)
Averageconsecutive wins3consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 15:07sell10.011798.240.001793.49
22020.11.27 15:09t/p10.011793.490.001793.494.751004.75
32020.12.02 15:54sell20.011813.390.001807.04
42020.12.02 18:09close20.011828.390.001807.04-15.00989.75
52020.12.03 18:00sell30.011830.890.001825.88
62020.12.03 18:09t/p30.011825.880.001825.885.01994.76
72020.12.03 19:45sell40.011837.700.001836.69
82020.12.03 20:39t/p40.011836.690.001836.691.01995.77
92020.12.04 17:22sell50.011835.380.001829.06
102020.12.07 10:31sell60.011829.930.001824.08
112020.12.07 10:34t/p50.011829.060.001829.066.541002.31
122020.12.07 10:37t/p60.011824.080.001824.085.851008.16
132020.12.07 16:47sell70.011847.400.001846.39
142020.12.07 16:48t/p70.011846.390.001846.391.011009.17
152020.12.09 06:00sell80.011859.770.001856.01
162020.12.09 06:08t/p80.011856.010.001856.013.761012.93
172020.12.09 12:22sell90.011857.780.001853.71
182020.12.09 13:39t/p90.011853.710.001853.714.071017.00
192020.12.09 16:57sell100.011844.600.001834.91
202020.12.09 20:22t/p100.011834.910.001834.919.691026.69
212020.12.10 17:54sell110.011834.420.001819.02
222020.12.11 17:24sell120.011847.280.001846.27
232020.12.11 17:36t/p120.011846.270.001846.271.011027.70
242020.12.14 16:39sell130.011837.050.001836.04
252020.12.14 16:51t/p130.011836.040.001836.041.011028.71
262020.12.14 18:24sell140.011824.420.001810.92
272020.12.15 05:07close110.011834.440.001819.020.641029.35
282020.12.15 07:39close140.011839.420.001810.92-14.781014.57
292020.12.16 15:18sell150.011855.030.001850.84
302020.12.16 15:22t/p150.011850.840.001850.844.191018.76
312020.12.16 21:19sell160.011847.450.001842.45
322020.12.16 22:00close160.011862.460.001842.45-15.011003.75
332020.12.16 23:00sell170.011864.080.001862.76
342020.12.16 23:09t/p170.011862.760.001862.761.321005.07
352020.12.18 15:09sell180.011887.500.001886.55
362020.12.18 15:13t/p180.011886.550.001886.550.951006.02
372020.12.18 16:54sell190.011880.190.001875.59
382020.12.21 02:37sell200.011887.620.001886.61
392020.12.21 03:17close190.011895.190.001875.59-14.78991.23
402020.12.21 04:15sell210.011897.420.001895.61
412020.12.21 04:39t/p210.011895.610.001895.611.81993.04
422020.12.21 07:09close200.011902.620.001886.61-15.00978.04
432020.12.21 09:54sell220.011893.310.001886.69
442020.12.21 11:52t/p220.011886.690.001886.696.62984.66
452020.12.21 11:54sell230.011883.880.001876.38
462020.12.21 12:04t/p230.011876.380.001876.387.50992.16
472020.12.22 17:10sell240.011870.060.001858.82
482020.12.22 19:00sell250.011864.350.001855.66
492020.12.23 14:07t/p240.011858.820.001858.8211.461003.62
502020.12.23 16:37sell260.011872.700.001871.69
512020.12.23 17:15t/p260.011871.690.001871.691.011004.63
522020.12.24 04:34close250.011879.350.001855.66-14.12990.51
532020.12.24 17:09sell270.011878.820.001877.81
542020.12.24 17:13t/p270.011877.810.001877.811.01991.52
552020.12.28 08:30sell280.011879.920.001872.11
562020.12.28 13:52t/p280.011872.110.001872.117.81999.33
572020.12.28 16:37sell290.011893.330.001892.32
582020.12.28 16:45t/p290.011892.320.001892.321.011000.34
592020.12.29 18:31sell300.011882.760.001881.75
602020.12.29 18:54t/p300.011881.750.001881.751.011001.35
612020.12.30 16:39sell310.011883.520.001881.96
622020.12.30 16:46t/p310.011881.960.001881.961.561002.91
632020.12.31 20:09sell320.011891.930.001888.50
642021.01.04 01:00close320.011909.290.001888.50-16.92985.99
652021.01.05 17:08sell330.011939.390.001932.88
662021.01.05 18:45sell340.011948.560.001947.80
672021.01.06 03:07close330.011954.390.001932.88-14.78971.21
682021.01.06 03:24t/p340.011947.800.001947.800.98972.19
692021.01.06 04:54sell350.011943.510.001938.80
702021.01.06 10:34sell360.011951.660.001950.65
712021.01.06 12:00close350.011958.510.001938.80-15.00957.19
722021.01.06 13:24t/p360.011950.650.001950.651.01958.20
732021.01.06 13:57sell370.011947.410.001941.85
742021.01.06 14:34t/p370.011941.850.001941.855.56963.76
752021.01.06 15:30sell380.011938.070.001932.94
762021.01.06 15:54t/p380.011932.940.001932.945.13968.89
772021.01.06 17:49sell390.011908.520.001893.81
782021.01.06 22:09close390.011923.520.001893.81-15.00953.89
792021.01.08 10:04sell400.011889.270.001867.08
802021.01.08 16:37sell410.011878.540.001864.52
812021.01.08 16:51t/p400.011867.080.001867.0822.19976.08
822021.01.08 16:52t/p410.011864.520.001864.5214.02990.10
832021.01.12 15:39sell420.011843.510.001825.66
842021.01.12 21:24sell430.011852.850.001851.84
852021.01.13 01:57close420.011858.510.001825.66-14.78975.32
862021.01.13 11:09t/p430.011851.840.001851.841.23976.54
872021.01.13 16:52sell440.011857.800.001854.60
882021.01.13 19:37t/p440.011854.600.001854.603.20979.74
892021.01.13 22:54sell450.011847.410.001843.32
902021.01.14 04:22t/p450.011843.320.001843.324.75984.49
912021.01.14 04:34sell460.011835.720.001827.58
922021.01.14 16:24close460.011850.730.001827.58-15.01969.48
932021.01.15 15:54sell470.011838.630.001826.89
942021.01.15 17:54sell480.011827.340.001809.39
952021.01.15 17:54t/p470.011826.890.001826.8911.74981.22
962021.01.19 03:19close480.011842.340.001809.39-14.56966.66
972021.01.19 10:23sell490.011844.640.001843.63
982021.01.19 10:30t/p490.011843.630.001843.631.01967.67
992021.01.19 14:54sell500.011835.720.001826.35
1002021.01.19 16:38sell510.011835.920.001828.68
1012021.01.20 04:54close500.011850.720.001826.35-14.78952.89
1022021.01.20 06:39close510.011850.920.001828.68-14.78938.11
1032021.01.20 14:54sell520.011842.110.001836.51
1042021.01.20 15:09t/p520.011836.510.001836.515.60943.71
1052021.01.20 16:30sell530.011859.780.001858.64
1062021.01.20 16:52t/p530.011858.640.001858.641.14944.85
1072021.01.21 17:00sell540.011863.620.001860.50
1082021.01.22 05:03t/p540.011860.500.001860.503.34948.19
1092021.01.22 12:39sell550.011850.140.001843.33
1102021.01.22 14:39t/p550.011843.330.001843.336.81955.00
1112021.01.25 17:09sell560.011851.460.001835.42
1122021.01.27 16:39t/p560.011835.420.001835.4216.48971.48
1132021.01.27 16:45sell570.011832.260.001819.77
1142021.01.27 17:09close570.011847.260.001819.77-15.00956.48
1152021.01.27 18:30sell580.011847.820.001845.17
1162021.01.27 19:00t/p580.011845.170.001845.172.65959.13
1172021.01.28 15:45sell590.011848.570.001847.56
1182021.01.28 16:39close590.011863.570.001847.56-15.00944.13
1192021.01.28 19:06sell600.011845.110.001826.67
1202021.01.29 12:54close600.011860.110.001826.67-14.78929.34
1212021.01.29 16:39sell610.011855.410.001835.21
1222021.01.29 23:58close at stop610.011847.940.001835.217.47936.81
+
diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 8.gif b/Docs/Reports/Tests/XTPW/Short/StrategyTester 8.gif new file mode 100644 index 0000000..223d1b5 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Short/StrategyTester 8.gif differ diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 8.htm b/Docs/Reports/Tests/XTPW/Short/StrategyTester 8.htm new file mode 100644 index 0000000..718bee0 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Short/StrategyTester 8.htm @@ -0,0 +1,101 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.01.29 23:45 (2020.01.01 - 2021.01.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=false; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test4192Ticks modelled3544155Modelling quality24.42%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (50)
Total net profit13.00Gross profit116.69Gross loss-103.69
Profit factor1.13Expected payoff0.81
Absolute drawdown38.21Maximal drawdown52.31 (5.16%)Relative drawdown5.16% (52.31)
Total trades16Short positions (won %)16 (56.25%)Long positions (won %)0 (0.00%)
Profit trades (% of total)9 (56.25%)Loss trades (% of total)7 (43.75%)
Largestprofit trade22.76loss trade-15.00
Averageprofit trade12.97loss trade-14.81
Maximumconsecutive wins (profit in money)3 (44.73)consecutive losses (loss in money)2 (-29.78)
Maximalconsecutive profit (count of wins)44.73 (3)consecutive loss (count of losses)-29.78 (2)
Averageconsecutive wins2consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 16:00sell10.011778.500.001749.26
22020.12.01 10:07close10.011793.500.001749.26-14.56985.44
32020.12.04 18:15sell20.011833.750.001821.09
42020.12.07 16:49close20.011848.750.001821.09-14.78970.66
52020.12.09 06:30sell30.011857.560.001849.00
62020.12.09 16:53t/p30.011849.000.001849.008.56979.22
72020.12.09 17:15sell40.011842.320.001820.66
82020.12.10 18:36sell50.011836.090.001823.11
92020.12.14 12:22t/p50.011823.110.001823.1113.42992.64
102020.12.14 12:24t/p40.011820.660.001820.6622.761015.39
112020.12.21 12:30sell60.011869.360.001840.26
122020.12.21 14:09close60.011884.360.001840.26-15.001000.39
132020.12.22 18:00sell70.011861.400.001842.96
142020.12.23 16:49close70.011876.400.001842.96-14.78985.61
152021.01.06 14:15sell80.011946.240.001934.80
162021.01.06 14:37t/p80.011934.800.001934.8011.44997.05
172021.01.06 16:00sell90.011932.780.001918.05
182021.01.06 17:37t/p90.011918.050.001918.0514.731011.78
192021.01.08 11:15sell100.011890.620.001872.44
202021.01.08 16:39t/p100.011872.440.001872.4418.181029.96
212021.01.12 16:30sell110.011845.260.001829.92
222021.01.13 02:09close110.011860.260.001829.92-14.781015.18
232021.01.15 17:21sell120.011833.450.001821.61
242021.01.18 01:34t/p120.011821.610.001821.6112.061027.24
252021.01.20 15:30sell130.011840.960.001830.57
262021.01.20 16:15close130.011855.960.001830.57-15.001012.24
272021.01.25 18:15sell140.011847.450.001830.68
282021.01.28 15:45close140.011847.460.001830.681.091013.32
292021.01.28 19:30sell150.011840.890.001822.15
302021.01.29 12:39close150.011855.890.001822.15-14.78998.54
312021.01.29 17:09sell160.011861.150.001846.69
322021.01.29 22:46t/p160.011846.690.001846.6914.461013.00
+
diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 9.gif b/Docs/Reports/Tests/XTPW/Short/StrategyTester 9.gif new file mode 100644 index 0000000..4ae2014 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Short/StrategyTester 9.gif differ diff --git a/Docs/Reports/Tests/XTPW/Short/StrategyTester 9.htm b/Docs/Reports/Tests/XTPW/Short/StrategyTester 9.htm new file mode 100644 index 0000000..e9e19dd --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Short/StrategyTester 9.htm @@ -0,0 +1,89 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.01.29 23:45 (2020.01.01 - 2021.01.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=false; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test4192Ticks modelled3544155Modelling quality24.42%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (50)
Total net profit88.62Gross profit103.62Gross loss-15.00
Profit factor6.91Expected payoff8.86
Absolute drawdown5.32Maximal drawdown47.52 (4.53%)Relative drawdown4.53% (47.52)
Total trades10Short positions (won %)10 (90.00%)Long positions (won %)0 (0.00%)
Profit trades (% of total)9 (90.00%)Loss trades (% of total)1 (10.00%)
Largestprofit trade23.92loss trade-15.00
Averageprofit trade11.51loss trade-15.00
Maximumconsecutive wins (profit in money)7 (58.67)consecutive losses (loss in money)1 (-15.00)
Maximalconsecutive profit (count of wins)58.67 (7)consecutive loss (count of losses)-15.00 (1)
Averageconsecutive wins5consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 15:15sell10.011793.480.001779.22
22020.11.27 15:52t/p10.011779.220.001779.2214.261014.26
32020.12.09 12:30sell20.011857.620.001849.31
42020.12.09 16:51t/p20.011849.310.001849.318.311022.57
52020.12.09 17:00sell30.011839.670.001815.36
62020.12.10 18:15sell40.011834.130.001818.44
72020.12.11 22:54close30.011839.680.001815.360.871023.44
82020.12.15 05:07close40.011834.140.001818.440.651024.08
92020.12.22 17:45sell50.011871.710.001862.42
102020.12.22 17:54t/p50.011862.420.001862.429.291033.37
112021.01.06 14:00sell60.011944.910.001932.14
122021.01.06 14:39t/p60.011932.140.001932.1412.771046.14
132021.01.06 15:45sell70.011935.140.001922.61
142021.01.06 17:24t/p70.011922.610.001922.6112.531058.67
152021.01.06 18:45sell80.011903.040.001874.79
162021.01.06 21:37close80.011918.040.001874.79-15.001043.67
172021.01.08 11:00sell90.011888.710.001867.68
182021.01.08 16:49sell100.011868.640.001844.72
192021.01.08 16:49t/p90.011867.680.001867.6821.031064.70
202021.01.08 19:24t/p100.011844.720.001844.7223.921088.62
+
diff --git a/Docs/Reports/Tests/XTPW/Test/StrategyTester 1.gif b/Docs/Reports/Tests/XTPW/Test/StrategyTester 1.gif new file mode 100644 index 0000000..4f2b76c Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Test/StrategyTester 1.gif differ diff --git a/Docs/Reports/Tests/XTPW/Test/StrategyTester 1.htm b/Docs/Reports/Tests/XTPW/Test/StrategyTester 1.htm new file mode 100644 index 0000000..c82edeb --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Test/StrategyTester 1.htm @@ -0,0 +1,79 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.03.30 23:45 (2020.01.01 - 2021.03.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.01; xTPWLongR2R=1.5; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.01; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=700;
Bars in test8040Ticks modelled9476561Modelling quality24.70%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (60)
Total net profit31.63Gross profit41.63Gross loss-10.00
Profit factor4.16Expected payoff6.33
Absolute drawdown4.91Maximal drawdown23.30 (2.25%)Relative drawdown2.25% (23.30)
Total trades5Short positions (won %)0 (0.00%)Long positions (won %)5 (80.00%)
Profit trades (% of total)4 (80.00%)Loss trades (% of total)1 (20.00%)
Largestprofit trade14.45loss trade-10.00
Averageprofit trade10.41loss trade-10.00
Maximumconsecutive wins (profit in money)3 (27.18)consecutive losses (loss in money)1 (-10.00)
Maximalconsecutive profit (count of wins)27.18 (3)consecutive loss (count of losses)-10.00 (1)
Averageconsecutive wins2consecutive losses1
+Graph
+ + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.30 17:15buy10.011775.150.001787.08
22020.12.01 07:52t/p10.011787.080.001787.0811.501011.50
32021.01.28 11:30buy20.011840.810.001849.71
42021.01.28 15:45t/p20.011849.710.001849.718.901020.40
52021.02.19 08:45buy30.011773.050.001779.83
62021.02.19 15:52t/p30.011779.830.001779.836.781027.18
72021.03.04 13:39buy40.011715.670.001723.65
82021.03.04 19:24close40.011705.670.001723.65-10.001017.18
92021.03.05 16:45buy50.011697.630.001712.51
102021.03.08 01:24t/p50.011712.510.001712.5114.451031.63
+
diff --git a/Docs/Reports/Tests/XTPW/Test/StrategyTester 2.gif b/Docs/Reports/Tests/XTPW/Test/StrategyTester 2.gif new file mode 100644 index 0000000..944dde4 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Test/StrategyTester 2.gif differ diff --git a/Docs/Reports/Tests/XTPW/Test/StrategyTester 2.htm b/Docs/Reports/Tests/XTPW/Test/StrategyTester 2.htm new file mode 100644 index 0000000..224a643 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Test/StrategyTester 2.htm @@ -0,0 +1,171 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.12.30 23:45 (2020.01.01 - 2021.12.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2.5; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=700;
Bars in test25902Ticks modelled27850269Modelling quality24.91%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (60)
Total net profit38.61Gross profit135.52Gross loss-96.91
Profit factor1.40Expected payoff0.77
Absolute drawdown2.76Maximal drawdown50.54 (4.72%)Relative drawdown4.72% (50.54)
Total trades50Short positions (won %)0 (0.00%)Long positions (won %)50 (84.00%)
Profit trades (% of total)42 (84.00%)Loss trades (% of total)8 (16.00%)
Largestprofit trade11.16loss trade-15.86
Averageprofit trade3.23loss trade-12.11
Maximumconsecutive wins (profit in money)12 (31.55)consecutive losses (loss in money)2 (-30.43)
Maximalconsecutive profit (count of wins)40.62 (10)consecutive loss (count of losses)-30.43 (2)
Averageconsecutive wins8consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.03 18:15buy10.011827.820.001837.00
22020.12.03 19:34t/p10.011837.000.001837.009.181009.18
32020.12.04 17:30buy20.011834.330.001835.11
42020.12.04 17:37t/p20.011835.110.001835.110.781009.96
52020.12.09 06:15buy30.011856.900.001859.10
62020.12.09 06:34t/p30.011859.100.001859.102.201012.16
72020.12.16 15:30buy40.011854.690.001867.14
82020.12.17 03:33t/p40.011867.140.001867.1411.161023.32
92020.12.21 12:15buy50.011869.180.001903.76
102020.12.28 13:54close50.011869.160.001903.76-3.031020.29
112021.01.05 18:00buy60.011943.950.001955.28
122021.01.06 10:45t/p60.011955.280.001955.2810.901031.19
132021.01.06 14:00buy70.011945.510.001945.51
142021.01.06 14:04t/p70.011945.510.001945.510.001031.19
152021.01.12 16:15buy80.011840.020.001846.92
162021.01.12 16:30t/p80.011846.920.001846.926.901038.09
172021.01.19 15:15buy90.011835.990.001842.12
182021.01.19 16:22t/p90.011842.120.001842.126.131044.22
192021.01.20 15:15buy100.011835.480.001837.23
202021.01.20 15:21t/p100.011837.230.001837.231.751045.97
212021.01.25 18:00buy110.011852.460.001857.99
222021.01.25 19:24t/p110.011857.990.001857.995.531051.50
232021.01.28 19:15buy120.011842.750.001846.40
242021.01.29 08:47t/p120.011846.400.001846.403.221054.72
252021.01.29 16:45buy130.011855.510.001859.31
262021.01.29 16:51t/p130.011859.310.001859.313.801058.52
272021.02.09 17:49buy140.011842.440.001867.07
282021.02.10 17:00buy150.011841.900.001843.58
292021.02.10 17:00modify140.011842.440.001843.58
302021.02.10 17:07t/p140.011843.580.001843.580.711059.23
312021.02.10 17:07t/p150.011843.580.001843.581.681060.91
322021.02.11 18:15buy160.011837.220.001838.17
332021.02.11 21:30close160.011822.220.001838.17-15.001045.91
342021.02.16 14:00buy170.011816.630.001819.03
352021.02.16 15:34close170.011801.630.001819.03-15.001030.91
362021.03.11 16:45buy180.011720.540.001722.07
372021.03.11 16:51t/p180.011722.070.001722.071.531032.44
382021.03.16 09:30buy190.011728.010.001731.34
392021.03.16 10:21t/p190.011731.340.001731.343.331035.77
402021.03.16 17:45buy200.011729.860.001734.16
412021.03.17 03:52t/p200.011734.160.001734.163.871039.64
422021.03.17 13:30buy210.011728.460.001728.61
432021.03.17 13:36t/p210.011728.610.001728.610.151039.79
442021.03.18 10:45buy220.011736.310.001737.31
452021.03.18 11:03t/p220.011737.310.001737.311.001040.79
462021.03.22 08:15buy230.011733.250.001736.73
472021.03.22 13:09t/p230.011736.730.001736.733.481044.27
482021.03.23 15:15buy240.011735.140.001735.59
492021.03.24 12:04t/p240.011735.590.001735.590.021044.29
502021.03.25 09:15buy250.011731.860.001733.64
512021.03.25 09:39t/p250.011733.640.001733.641.781046.07
522021.03.25 17:30buy260.011735.590.001740.57
532021.03.29 16:34close260.011720.590.001740.57-15.861030.21
542021.04.07 15:00buy270.011735.100.001737.30
552021.04.07 15:52t/p270.011737.300.001737.302.201032.41
562021.04.14 16:45buy280.011739.080.001750.71
572021.04.15 15:15t/p280.011750.710.001750.7110.341042.75
582021.04.19 15:15buy290.011776.640.001778.42
592021.04.19 15:24t/p290.011778.420.001778.421.781044.53
602021.04.23 17:00buy300.011782.070.001783.50
612021.04.27 04:03t/p300.011783.500.001783.500.571045.10
622021.04.27 16:45buy310.011779.880.001783.78
632021.04.27 16:54t/p310.011783.780.001783.783.901049.00
642021.04.27 19:00buy320.011778.510.001779.64
652021.04.27 20:09t/p320.011779.640.001779.641.131050.13
662021.05.04 18:15buy330.011778.060.001781.11
672021.05.04 18:22t/p330.011781.110.001781.113.051053.18
682021.05.10 17:45buy340.011840.180.001847.26
692021.05.11 16:00buy350.011827.100.001829.00
702021.05.11 16:01t/p350.011829.000.001829.001.901055.08
712021.05.11 16:09close340.011825.180.001847.26-15.431039.65
722021.05.19 11:00buy360.011868.350.001873.35
732021.05.19 14:24close360.011853.350.001873.35-15.001024.65
742021.05.19 22:00buy370.011863.650.001863.98
752021.05.19 22:04t/p370.011863.980.001863.980.331024.98
762021.05.21 17:15buy380.011875.850.001876.93
772021.05.21 17:24t/p380.011876.930.001876.931.081026.06
782021.06.01 11:30buy390.011908.720.001910.47
792021.06.01 11:52t/p390.011910.470.001910.471.751027.81
802021.06.01 13:45buy400.011905.320.001906.00
812021.06.01 13:52t/p400.011906.000.001906.000.681028.49
822021.06.01 17:15buy410.011900.360.001907.09
832021.06.02 16:37t/p410.011907.090.001907.096.301034.79
842021.06.08 17:00buy420.011888.330.001898.56
852021.06.09 16:39t/p420.011898.560.001898.569.801044.59
862021.06.22 15:30buy430.011777.260.001778.06
872021.06.22 16:07t/p430.011778.060.001778.060.801045.39
882021.06.24 19:15buy440.011777.940.001781.97
892021.06.25 10:24t/p440.011781.970.001781.973.601048.99
902021.06.25 18:15buy450.011781.340.001785.09
912021.06.28 08:54t/p450.011785.090.001785.093.321052.31
922021.07.01 18:15buy460.011770.830.001770.98
932021.07.01 18:15t/p460.011770.980.001770.980.151052.46
942021.07.06 19:00buy470.011796.960.001799.01
952021.07.07 04:19t/p470.011799.010.001799.011.621054.08
962021.07.08 17:15buy480.011807.030.001809.58
972021.07.09 18:18t/p480.011809.580.001809.582.121056.20
982021.07.13 17:15buy490.011809.560.001835.86
992021.07.15 14:30buy500.011826.370.001834.87
1002021.07.15 14:30modify490.011809.560.001834.87
1012021.07.16 18:09close500.011811.370.001834.87-15.431040.77
1022021.07.16 18:33close490.011809.550.001834.87-2.161038.61
+
diff --git a/Docs/Reports/Tests/XTPW/Test/StrategyTester 3.gif b/Docs/Reports/Tests/XTPW/Test/StrategyTester 3.gif new file mode 100644 index 0000000..fd7fa10 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Test/StrategyTester 3.gif differ diff --git a/Docs/Reports/Tests/XTPW/Test/StrategyTester 3.htm b/Docs/Reports/Tests/XTPW/Test/StrategyTester 3.htm new file mode 100644 index 0000000..451522c --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Test/StrategyTester 3.htm @@ -0,0 +1,189 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.12.30 23:45 (2020.01.01 - 2021.12.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2.5; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=700;
Bars in test25902Ticks modelled27850269Modelling quality24.91%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (60)
Total net profit-34.86Gross profit155.05Gross loss-189.91
Profit factor0.82Expected payoff-0.59
Absolute drawdown49.36Maximal drawdown143.17 (13.09%)Relative drawdown13.09% (143.17)
Total trades59Short positions (won %)0 (0.00%)Long positions (won %)59 (76.27%)
Profit trades (% of total)45 (76.27%)Loss trades (% of total)14 (23.73%)
Largestprofit trade11.97loss trade-16.29
Averageprofit trade3.45loss trade-13.56
Maximumconsecutive wins (profit in money)13 (33.75)consecutive losses (loss in money)6 (-79.74)
Maximalconsecutive profit (count of wins)33.75 (13)consecutive loss (count of losses)-79.74 (6)
Averageconsecutive wins5consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 18:03buy10.011831.130.001835.18
22020.12.04 19:30t/p10.011835.180.001835.184.051004.05
32020.12.16 15:30buy20.011853.350.001862.45
42020.12.16 22:00t/p20.011862.450.001862.459.101013.15
52020.12.21 12:15buy30.011869.010.001903.16
62020.12.28 13:55close30.011869.000.001903.16-3.021010.13
72021.01.06 14:03buy40.011944.510.001947.51
82021.01.06 14:09t/p40.011947.510.001947.513.001013.13
92021.01.12 16:15buy50.011840.010.001846.89
102021.01.12 16:30t/p50.011846.890.001846.896.881020.01
112021.01.19 15:15buy60.011835.980.001842.08
122021.01.19 16:22t/p60.011842.080.001842.086.101026.11
132021.01.25 18:04buy70.011852.450.001857.95
142021.01.25 19:24t/p70.011857.950.001857.955.501031.61
152021.01.28 19:19buy80.011842.740.001846.37
162021.01.29 08:47t/p80.011846.370.001846.373.201034.81
172021.01.29 16:45buy90.011855.500.001859.28
182021.01.29 16:51t/p90.011859.280.001859.283.781038.59
192021.02.10 17:36buy100.011840.200.001846.28
202021.02.11 15:15t/p100.011846.280.001846.284.791043.38
212021.02.16 14:00buy110.011816.620.001819.00
222021.02.16 15:34close110.011801.620.001819.00-15.001028.38
232021.03.16 09:30buy120.011728.000.001731.30
242021.03.16 10:21t/p120.011731.300.001731.303.301031.68
252021.03.16 17:49buy130.011729.090.001731.47
262021.03.16 19:06t/p130.011731.470.001731.472.381034.06
272021.03.17 13:33buy140.011728.450.001728.58
282021.03.17 13:36t/p140.011728.580.001728.580.131034.19
292021.03.18 10:45buy150.011736.300.001737.28
302021.03.18 11:03t/p150.011737.280.001737.280.981035.17
312021.03.22 08:17buy160.011733.240.001736.69
322021.03.22 13:09t/p160.011736.690.001736.693.451038.62
332021.03.23 15:19buy170.011735.130.001735.56
342021.03.24 12:04t/p170.011735.560.001735.560.001038.62
352021.04.14 16:49buy180.011739.070.001750.67
362021.04.15 15:15t/p180.011750.670.001750.6710.311048.93
372021.04.23 17:02buy190.011782.060.001783.46
382021.04.27 04:03t/p190.011783.460.001783.460.541049.47
392021.04.27 17:45buy200.011780.200.001784.90
402021.04.28 12:22close200.011765.200.001784.90-15.431034.04
412021.05.04 18:15buy210.011778.050.001781.08
422021.05.04 18:22t/p210.011781.080.001781.083.031037.07
432021.05.10 17:54buy220.011837.430.001837.63
442021.05.10 17:58t/p220.011837.630.001837.630.201037.27
452021.05.11 16:09buy230.011826.520.001826.97
462021.05.11 16:51t/p230.011826.970.001826.970.451037.72
472021.05.19 11:54buy240.011860.370.001863.37
482021.05.19 12:00t/p240.011863.370.001863.373.001040.72
492021.05.19 22:01buy250.011862.940.001865.94
502021.05.19 22:09t/p250.011865.940.001865.943.001043.72
512021.05.21 17:15buy260.011875.840.001876.89
522021.05.21 17:24t/p260.011876.890.001876.891.051044.77
532021.06.01 11:34buy270.011908.050.001908.13
542021.06.01 11:46t/p270.011908.130.001908.130.081044.85
552021.06.01 17:15buy280.011899.990.001905.79
562021.06.02 15:24t/p280.011905.790.001905.795.371050.22
572021.06.08 17:00buy290.011888.320.001898.52
582021.06.09 16:39t/p290.011898.520.001898.529.771059.99
592021.06.22 15:34buy300.011777.240.001777.99
602021.06.22 16:07t/p300.011777.990.001777.990.751060.74
612021.06.25 18:15buy310.011780.790.001783.17
622021.06.28 08:24t/p310.011783.170.001783.171.951062.69
632021.07.01 18:24buy320.011769.570.001772.57
642021.07.01 20:04t/p320.011772.570.001772.573.001065.69
652021.07.08 17:17buy330.011807.020.001809.55
662021.07.09 18:18t/p330.011809.550.001809.552.101067.79
672021.07.13 17:18buy340.011809.550.001835.83
682021.07.15 14:36buy350.011825.530.001831.93
692021.07.15 14:36modify340.011809.550.001831.93
702021.07.16 18:09close350.011810.530.001831.93-15.431052.36
712021.07.16 18:33close340.011809.540.001831.93-2.161050.20
722021.07.20 17:45buy360.011812.450.001814.60
732021.07.21 15:16close360.011797.450.001814.60-15.431034.77
742021.07.30 15:49buy370.011825.470.001828.47
752021.07.30 21:39close370.011810.470.001828.47-15.001019.77
762021.08.04 17:15buy380.011818.020.001819.52
772021.08.05 16:39close380.011803.020.001819.52-16.291003.48
782021.08.24 16:45buy390.011804.750.001811.50
792021.08.25 16:37close390.011789.750.001811.50-15.43988.05
802021.09.01 17:15buy400.011812.740.001818.32
812021.09.02 16:15buy410.011811.890.001816.77
822021.09.02 16:15modify400.011812.740.001816.77
832021.09.03 15:16t/p400.011816.770.001816.772.31990.36
842021.09.03 15:16t/p410.011816.770.001816.774.45994.81
852021.09.07 06:45buy420.011823.350.001823.70
862021.09.07 14:18close420.011808.350.001823.70-15.00979.81
872021.09.09 16:49buy430.011794.470.001801.72
882021.09.10 08:37t/p430.011801.720.001801.726.82986.63
892021.09.15 17:04buy440.011797.210.001802.84
902021.09.16 12:37close440.011782.210.001802.84-16.29970.34
912021.09.22 21:51buy450.011770.120.001773.30
922021.09.22 22:24t/p450.011773.300.001773.303.18973.52
932021.10.07 15:45buy460.011755.480.001757.76
942021.10.07 16:52t/p460.011757.760.001757.762.28975.80
952021.10.08 17:30buy470.011762.890.001766.27
962021.10.12 15:45buy480.011754.960.001756.36
972021.10.12 15:51t/p480.011756.360.001756.361.40977.20
982021.10.12 16:54t/p470.011766.270.001766.272.52979.72
992021.10.22 18:46buy490.011788.300.001800.70
1002021.10.25 07:54t/p490.011800.700.001800.7011.97991.69
1012021.11.02 15:04buy500.011791.520.001798.77
1022021.11.03 14:39close500.011776.520.001798.77-15.43976.26
1032021.11.09 17:15buy510.011822.800.001828.00
1042021.11.09 18:51t/p510.011828.000.001828.005.20981.46
1052021.11.16 16:04buy520.011867.230.001870.78
1062021.11.16 19:54close520.011852.230.001870.78-15.00966.46
1072021.11.18 15:30buy530.011856.970.001860.87
1082021.11.18 15:36t/p530.011860.870.001860.873.90970.36
1092021.11.30 17:49buy540.011792.680.001795.41
1102021.11.30 18:07close540.011777.680.001795.41-15.00955.36
1112021.12.07 11:15buy550.011779.030.001780.51
1122021.12.07 11:51t/p550.011780.510.001780.511.48956.84
1132021.12.07 15:31buy560.011778.340.001781.34
1142021.12.07 16:39t/p560.011781.340.001781.343.00959.84
1152021.12.21 16:54buy570.011793.670.001796.67
1162021.12.22 18:04t/p570.011796.670.001796.672.57962.41
1172021.12.28 16:15buy580.011811.410.001813.51
1182021.12.28 16:24t/p580.011813.510.001813.512.10964.51
1192021.12.28 18:48buy590.011810.050.001810.68
1202021.12.28 18:54t/p590.011810.680.001810.680.63965.14
+
diff --git a/Docs/Reports/Tests/XTPW/Test/StrategyTester 4.gif b/Docs/Reports/Tests/XTPW/Test/StrategyTester 4.gif new file mode 100644 index 0000000..be29d04 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Test/StrategyTester 4.gif differ diff --git a/Docs/Reports/Tests/XTPW/Test/StrategyTester 4.htm b/Docs/Reports/Tests/XTPW/Test/StrategyTester 4.htm new file mode 100644 index 0000000..224ef7b --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Test/StrategyTester 4.htm @@ -0,0 +1,85 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.12.30 23:45 (2020.01.01 - 2021.12.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=4; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.01; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=700;
Bars in test25902Ticks modelled27850269Modelling quality24.91%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (60)
Total net profit26.49Gross profit36.50Gross loss-10.01
Profit factor3.65Expected payoff3.31
Absolute drawdown5.52Maximal drawdown13.71 (1.33%)Relative drawdown1.33% (13.71)
Total trades8Short positions (won %)0 (0.00%)Long positions (won %)8 (87.50%)
Profit trades (% of total)7 (87.50%)Loss trades (% of total)1 (12.50%)
Largestprofit trade8.37loss trade-10.01
Averageprofit trade5.21loss trade-10.01
Maximumconsecutive wins (profit in money)5 (30.62)consecutive losses (loss in money)1 (-10.01)
Maximalconsecutive profit (count of wins)30.62 (5)consecutive loss (count of losses)-10.01 (1)
Averageconsecutive wins4consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12021.01.25 18:04buy10.011852.450.001861.25
22021.01.26 06:09t/p10.011861.250.001861.258.371008.37
32021.01.28 20:00buy20.011837.880.001842.68
42021.01.28 21:09t/p20.011842.680.001842.684.801013.17
52021.03.16 09:30buy30.011728.000.001733.28
62021.03.16 12:39t/p30.011733.280.001733.285.281018.45
72021.05.19 22:01buy40.011862.940.001867.74
82021.05.19 22:21t/p40.011867.740.001867.744.801023.25
92021.09.02 16:15buy50.011811.890.001819.69
102021.09.03 15:34t/p50.011819.690.001819.697.371030.62
112021.09.07 07:37buy60.011822.290.001827.09
122021.09.07 12:24close60.011812.280.001827.09-10.011020.61
132021.10.07 15:45buy70.011755.480.001759.12
142021.10.07 16:54t/p70.011759.120.001759.123.641024.25
152021.10.12 15:45buy80.011754.960.001757.20
162021.10.12 15:52t/p80.011757.200.001757.202.241026.49
+
diff --git a/Docs/Reports/Tests/XTPW/Test/StrategyTester Long 1.gif b/Docs/Reports/Tests/XTPW/Test/StrategyTester Long 1.gif new file mode 100644 index 0000000..dd6e3b1 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Test/StrategyTester Long 1.gif differ diff --git a/Docs/Reports/Tests/XTPW/Test/StrategyTester Long 1.htm b/Docs/Reports/Tests/XTPW/Test/StrategyTester Long 1.htm new file mode 100644 index 0000000..8c16093 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Test/StrategyTester Long 1.htm @@ -0,0 +1,123 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.07.28 23:45 (2020.01.01 - 2023.07.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=1.5; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.02; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63169Ticks modelled72369290Modelling qualityn/a
Mismatched charts errors799
Initial deposit1000.00SpreadCurrent (50)
Total net profit55.56Gross profit117.99Gross loss-62.43
Profit factor1.89Expected payoff2.06
Absolute drawdown7.49Maximal drawdown42.26 (3.85%)Relative drawdown3.85% (42.26)
Total trades27Short positions (won %)0 (0.00%)Long positions (won %)27 (88.89%)
Profit trades (% of total)24 (88.89%)Loss trades (% of total)3 (11.11%)
Largestprofit trade7.44loss trade-21.46
Averageprofit trade4.92loss trade-20.81
Maximumconsecutive wins (profit in money)19 (96.37)consecutive losses (loss in money)1 (-21.46)
Maximalconsecutive profit (count of wins)96.37 (19)consecutive loss (count of losses)-21.46 (1)
Averageconsecutive wins8consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.02 03:43buy10.011814.730.001816.98
22020.12.02 09:28buy20.011812.810.001816.41
32020.12.02 09:54t/p20.011816.410.001816.413.601003.60
42020.12.02 10:22t/p10.011816.980.001816.982.251005.85
52020.12.02 21:54buy30.011829.880.001834.47
62020.12.02 23:54buy40.011831.020.001835.49
72020.12.03 05:22t/p30.011834.470.001834.473.131008.98
82020.12.03 05:24t/p40.011835.490.001835.493.011011.99
92020.12.03 20:34buy50.011837.840.001845.25
102020.12.03 22:21buy60.011840.200.001847.03
112020.12.04 15:31t/p50.011845.250.001845.256.921018.92
122020.12.04 15:33t/p60.011847.030.001847.036.341025.26
132020.12.08 15:04buy70.011865.620.001872.69
142020.12.08 16:36t/p70.011872.690.001872.697.071032.33
152020.12.15 20:52buy80.011853.000.001859.90
162020.12.15 23:39buy90.011853.970.001858.55
172020.12.16 10:37t/p90.011858.550.001858.554.091036.42
182020.12.16 10:39t/p80.011859.900.001859.906.411042.84
192020.12.16 18:58buy100.011854.870.001858.31
202020.12.16 20:54buy110.011856.270.001862.21
212020.12.16 21:51t/p100.011858.310.001858.313.441046.28
222020.12.16 22:00t/p110.011862.210.001862.215.941052.22
232020.12.17 23:54buy120.011886.280.001890.84
242020.12.18 06:09buy130.011882.700.001887.65
252020.12.18 07:49buy140.011885.490.001890.91
262020.12.18 14:09t/p130.011887.650.001887.654.951057.17
272020.12.21 01:34buy150.011884.420.001890.60
282020.12.21 03:04t/p150.011890.600.001890.606.181063.35
292020.12.21 03:04t/p120.011890.840.001890.843.591066.93
302020.12.21 03:04t/p140.011890.910.001890.914.931071.87
312020.12.31 11:00buy160.011893.630.001899.86
322020.12.31 17:33t/p160.011899.860.001899.866.231078.10
332021.01.05 09:45buy170.011942.050.001948.40
342021.01.05 13:22t/p170.011948.400.001948.406.351084.45
352021.01.06 09:19buy180.011948.700.001956.14
362021.01.06 10:48t/p180.011956.140.001956.147.441091.89
372021.01.19 19:19buy190.011841.460.001846.43
382021.01.20 03:09t/p190.011846.430.001846.434.481096.37
392021.02.01 20:17buy200.011865.270.001872.37
402021.02.02 09:24close200.011845.270.001872.37-20.491075.89
412021.02.08 07:28buy210.011814.800.001818.93
422021.02.08 09:18buy220.011815.830.001819.84
432021.02.08 12:30buy230.011813.220.001819.22
442021.02.08 13:34t/p210.011818.930.001818.934.131080.02
452021.02.08 13:34t/p230.011819.220.001819.226.001086.02
462021.02.08 13:34t/p220.011819.840.001819.844.011090.03
472021.02.08 22:24buy240.011834.090.001839.16
482021.02.09 04:22t/p240.011839.160.001839.164.581094.61
492021.02.10 21:09buy250.011843.000.001847.37
502021.02.11 19:48close250.011823.000.001847.37-21.461073.15
512021.02.19 23:06buy260.011781.950.001785.33
522021.02.22 01:00t/p260.011785.330.001785.332.891076.04
532021.02.23 14:49buy270.011810.900.001816.96
542021.02.24 15:54close270.011790.900.001816.96-20.491055.56
+
diff --git a/Docs/Reports/Tests/XTPW/Test/StrategyTester Long 2.gif b/Docs/Reports/Tests/XTPW/Test/StrategyTester Long 2.gif new file mode 100644 index 0000000..ed26036 Binary files /dev/null and b/Docs/Reports/Tests/XTPW/Test/StrategyTester Long 2.gif differ diff --git a/Docs/Reports/Tests/XTPW/Test/StrategyTester Long 2.htm b/Docs/Reports/Tests/XTPW/Test/StrategyTester Long 2.htm new file mode 100644 index 0000000..6fe15e1 --- /dev/null +++ b/Docs/Reports/Tests/XTPW/Test/StrategyTester Long 2.htm @@ -0,0 +1,115 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2021.01.04 01:00 - 2021.01.29 23:45 (2021.01.01 - 2021.01.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=1.5; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test2825Ticks modelled1863423Modelling quality25.00%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (51)
Total net profit-75.83Gross profit45.67Gross loss-121.50
Profit factor0.38Expected payoff-3.30
Absolute drawdown88.29Maximal drawdown108.86 (10.67%)Relative drawdown10.67% (108.86)
Total trades23Short positions (won %)0 (0.00%)Long positions (won %)23 (65.22%)
Profit trades (% of total)15 (65.22%)Loss trades (% of total)8 (34.78%)
Largestprofit trade7.23loss trade-15.49
Averageprofit trade3.04loss trade-15.19
Maximumconsecutive wins (profit in money)6 (14.22)consecutive losses (loss in money)4 (-60.04)
Maximalconsecutive profit (count of wins)18.71 (5)consecutive loss (count of losses)-60.04 (4)
Averageconsecutive wins4consecutive losses3
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12021.01.05 07:00buy10.011939.430.001943.05
22021.01.05 09:24t/p10.011943.050.001943.053.621003.62
32021.01.05 09:45buy20.011942.050.001948.38
42021.01.05 13:22t/p20.011948.380.001948.386.331009.95
52021.01.05 20:15buy30.011951.130.001955.81
62021.01.06 09:13buy40.011947.600.001950.59
72021.01.06 10:32t/p40.011950.590.001950.592.991012.94
82021.01.06 10:46t/p30.011955.810.001955.814.191017.13
92021.01.13 02:13buy50.011859.350.001866.81
102021.01.13 09:34buy60.011861.920.001866.03
112021.01.13 13:04buy70.011856.150.001857.73
122021.01.13 15:39t/p70.011857.730.001857.731.581018.71
132021.01.13 22:54close60.011846.920.001866.03-15.001003.71
142021.01.13 23:54close50.011844.310.001866.81-15.04988.67
152021.01.15 10:43buy80.011852.810.001857.60
162021.01.15 12:43buy90.011855.730.001860.13
172021.01.15 15:49close90.011840.730.001860.13-15.00973.67
182021.01.15 15:54close80.011837.810.001857.60-15.00958.67
192021.01.19 08:58buy100.011840.930.001844.11
202021.01.19 10:22t/p100.011844.110.001844.113.18961.85
212021.01.19 12:19buy110.011843.360.001844.22
222021.01.19 12:37t/p110.011844.220.001844.220.86962.71
232021.01.19 19:43buy120.011842.910.001845.28
242021.01.19 21:19buy130.011841.190.001841.76
252021.01.20 01:34buy140.011841.110.001844.43
262021.01.20 02:09t/p130.011841.760.001841.760.08962.80
272021.01.20 03:04t/p140.011844.430.001844.433.32966.12
282021.01.20 03:06t/p120.011845.280.001845.281.88968.00
292021.01.21 20:39buy150.011865.910.001870.80
302021.01.21 22:46t/p150.011870.800.001870.804.89972.89
312021.01.21 22:49buy160.011870.850.001873.85
322021.01.22 12:24close160.011855.850.001873.85-15.49957.40
332021.01.25 03:21buy170.011857.390.001859.96
342021.01.25 12:49t/p170.011859.960.001859.962.57959.97
352021.01.25 14:55buy180.011861.750.001863.16
362021.01.25 15:06t/p180.011863.160.001863.161.41961.38
372021.01.26 03:58buy190.011858.070.001862.11
382021.01.26 06:38buy200.011858.070.001859.60
392021.01.26 14:52buy210.011855.730.001862.95
402021.01.26 15:39t/p200.011859.600.001859.601.53962.91
412021.01.27 10:04buy220.011852.410.001857.17
422021.01.27 13:09close190.011843.070.001862.11-15.49947.43
432021.01.27 13:39close210.011840.730.001862.95-15.49931.94
442021.01.27 14:18close220.011837.410.001857.17-15.00916.94
452021.01.28 12:22buy230.011842.720.001849.95
462021.01.28 15:46t/p230.011849.950.001849.957.23924.17
+
diff --git a/Docs/Reports/X/Full/StrategyTester 1 Full.gif b/Docs/Reports/X/Full/StrategyTester 1 Full.gif new file mode 100644 index 0000000..1345f14 Binary files /dev/null and b/Docs/Reports/X/Full/StrategyTester 1 Full.gif differ diff --git a/Docs/Reports/X/Full/StrategyTester 1 Full.htm b/Docs/Reports/X/Full/StrategyTester 1 Full.htm new file mode 100644 index 0000000..34808a4 --- /dev/null +++ b/Docs/Reports/X/Full/StrategyTester 1 Full.htm @@ -0,0 +1,127 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.01 23:45 (2020.01.01 - 2023.08.02)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +enableXRLong=true; +enableXRShort=true; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63353Ticks modelled72601176Modelling qualityn/a
Mismatched charts errors808
Initial deposit1000.00SpreadCurrent (50)
Total net profit187.12Gross profit207.57Gross loss-20.45
Profit factor10.15Expected payoff7.20
Absolute drawdown30.05Maximal drawdown35.70 (3.55%)Relative drawdown3.55% (35.70)
Total trades26Short positions (won %)5 (100.00%)Long positions (won %)21 (95.24%)
Profit trades (% of total)25 (96.15%)Loss trades (% of total)1 (3.85%)
Largestprofit trade16.81loss trade-20.45
Averageprofit trade8.30loss trade-20.45
Maximumconsecutive wins (profit in money)25 (207.57)consecutive losses (loss in money)1 (-20.45)
Maximalconsecutive profit (count of wins)207.57 (25)consecutive loss (count of losses)-20.45 (1)
Averageconsecutive wins25consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 09:30buy10.011842.370.001854.79
22020.12.07 10:38close10.011822.360.001854.79-20.45979.55
32021.01.06 02:00buy20.011950.700.001958.50
42021.01.06 12:00t/p20.011958.500.001958.507.80987.35
52021.02.19 05:15buy30.011769.840.001786.37
62021.02.19 16:09t/p30.011786.370.001786.3716.531003.88
72021.04.08 14:00buy40.011746.230.001756.37
82021.04.08 16:39t/p40.011756.370.001756.3710.141014.02
92021.04.21 04:30buy50.011779.810.001788.60
102021.04.21 16:39t/p50.011788.600.001788.608.791022.81
112021.05.04 23:15sell60.011779.150.001777.35
122021.05.05 03:24t/p60.011777.350.001777.352.011024.81
132021.06.18 08:45sell70.011784.490.001777.35
142021.06.18 15:52t/p70.011777.350.001777.357.141031.95
152021.07.01 05:00buy80.011771.690.001788.94
162021.07.02 15:39t/p80.011788.940.001788.9416.811048.76
172021.07.14 12:00buy90.011814.410.001822.33
182021.07.14 15:06t/p90.011822.330.001822.337.921056.68
192021.08.26 13:45buy100.011787.160.001795.29
202021.08.26 18:04t/p100.011795.290.001795.298.131064.81
212021.10.21 09:45buy110.011786.660.001797.58
222021.10.22 15:22t/p110.011797.580.001797.5810.481075.29
232021.12.15 04:45sell120.011771.980.001768.80
242021.12.15 07:39t/p120.011768.800.001768.803.181078.47
252022.02.09 11:30buy130.011827.780.001831.59
262022.02.09 15:09t/p130.011831.590.001831.593.811082.28
272022.03.14 08:45sell140.011975.330.001973.05
282022.03.14 09:54t/p140.011973.050.001973.052.281084.56
292022.06.24 05:00sell150.011823.760.001819.89
302022.06.24 16:00t/p150.011819.890.001819.893.871088.43
312022.08.01 01:30buy160.011764.450.001772.37
322022.08.01 12:57t/p160.011772.370.001772.377.921096.35
332022.08.22 14:15buy170.011735.790.001742.63
342022.08.23 11:42t/p170.011742.630.001742.636.401102.75
352022.09.05 04:45buy180.011711.680.001722.30
362022.09.06 03:46t/p180.011722.300.001722.3010.181112.92
372022.11.15 04:45buy190.011771.790.001782.62
382022.11.15 09:47t/p190.011782.620.001782.6210.831123.75
392022.11.21 20:30buy200.011738.310.001753.49
402022.11.21 23:45buy210.011738.420.001742.35
412022.11.22 03:06t/p210.011742.350.001742.353.491127.24
422022.11.24 02:26t/p200.011753.490.001753.4912.971140.21
432022.11.30 10:00buy220.011755.410.001761.92
442022.11.30 11:36t/p220.011761.920.001761.926.511146.72
452023.01.20 09:00buy230.011926.840.001936.65
462023.01.20 10:08t/p230.011936.650.001936.659.811156.53
472023.03.01 04:30buy240.011829.000.001845.23
482023.03.03 10:41t/p240.011845.230.001845.2314.461170.99
492023.04.25 09:30buy250.011995.340.002008.12
502023.04.26 16:27t/p250.012008.120.002008.1212.341183.33
512023.07.04 17:45buy260.011928.490.001932.72
522023.07.05 16:17t/p260.011932.720.001932.723.791187.12
+
diff --git a/Docs/Reports/X/Long/StrategyTester.gif b/Docs/Reports/X/Long/StrategyTester.gif new file mode 100644 index 0000000..bb981a8 Binary files /dev/null and b/Docs/Reports/X/Long/StrategyTester.gif differ diff --git a/Docs/Reports/X/Long/StrategyTester.htm b/Docs/Reports/X/Long/StrategyTester.htm new file mode 100644 index 0000000..692fc34 --- /dev/null +++ b/Docs/Reports/X/Long/StrategyTester.htm @@ -0,0 +1,111 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.01 23:45 (2020.01.01 - 2023.08.02)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63353Ticks modelled72601176Modelling qualityn/a
Mismatched charts errors808
Initial deposit1000.00SpreadCurrent (60)
Total net profit167.90Gross profit188.39Gross loss-20.49
Profit factor9.20Expected payoff8.00
Absolute drawdown30.19Maximal drawdown35.74 (3.55%)Relative drawdown3.55% (35.74)
Total trades21Short positions (won %)0 (0.00%)Long positions (won %)21 (95.24%)
Profit trades (% of total)20 (95.24%)Loss trades (% of total)1 (4.76%)
Largestprofit trade16.76loss trade-20.49
Averageprofit trade9.42loss trade-20.49
Maximumconsecutive wins (profit in money)20 (188.39)consecutive losses (loss in money)1 (-20.49)
Maximalconsecutive profit (count of wins)188.39 (20)consecutive loss (count of losses)-20.49 (1)
Averageconsecutive wins20consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 09:30buy10.011842.470.001854.89
22020.12.07 10:38close10.011822.470.001854.89-20.49979.51
32021.01.06 02:00buy20.011950.800.001958.60
42021.01.06 12:00t/p20.011958.600.001958.607.80987.31
52021.02.19 05:15buy30.011769.940.001786.47
62021.02.19 16:09t/p30.011786.470.001786.4716.531003.84
72021.04.08 14:00buy40.011746.330.001756.47
82021.04.08 16:39t/p40.011756.470.001756.4710.141013.98
92021.04.21 04:30buy50.011779.910.001788.70
102021.04.21 16:39t/p50.011788.700.001788.708.791022.77
112021.07.01 05:00buy60.011771.790.001789.04
122021.07.02 15:39t/p60.011789.040.001789.0416.761039.54
132021.07.14 12:00buy70.011814.510.001822.43
142021.07.14 15:07t/p70.011822.430.001822.437.921047.46
152021.08.26 13:45buy80.011787.260.001795.39
162021.08.26 18:04t/p80.011795.390.001795.398.131055.59
172021.10.21 09:45buy90.011786.760.001797.68
182021.10.22 15:22t/p90.011797.680.001797.6810.431066.02
192022.02.09 11:30buy100.011827.880.001831.69
202022.02.09 15:09t/p100.011831.690.001831.693.811069.83
212022.08.01 01:30buy110.011764.550.001772.47
222022.08.01 12:57t/p110.011772.470.001772.477.921077.75
232022.08.22 14:15buy120.011735.890.001742.73
242022.08.23 11:42t/p120.011742.730.001742.736.351084.10
252022.09.05 04:45buy130.011711.780.001722.40
262022.09.06 03:47t/p130.011722.400.001722.4010.131094.24
272022.11.15 04:45buy140.011771.890.001782.72
282022.11.15 09:47t/p140.011782.720.001782.7210.831105.07
292022.11.21 20:30buy150.011738.410.001753.59
302022.11.21 23:45buy160.011738.520.001742.45
312022.11.22 03:07t/p160.011742.450.001742.453.441108.51
322022.11.24 02:26t/p150.011753.590.001753.5912.751121.26
332022.11.30 10:00buy170.011755.510.001762.02
342022.11.30 12:00t/p170.011762.020.001762.026.511127.77
352023.01.20 09:00buy180.011926.940.001936.75
362023.01.20 10:08t/p180.011936.750.001936.759.811137.58
372023.03.01 04:30buy190.011829.100.001845.33
382023.03.03 10:42t/p190.011845.330.001845.3314.281151.87
392023.04.25 09:30buy200.011995.440.002008.22
402023.04.26 16:28t/p200.012008.220.002008.2212.291164.16
412023.07.04 17:45buy210.011928.590.001932.82
422023.07.05 16:17t/p210.011932.820.001932.823.741167.90
+
diff --git a/Docs/Reports/X/Short/StrategyTester Short 1.gif b/Docs/Reports/X/Short/StrategyTester Short 1.gif new file mode 100644 index 0000000..40a5192 Binary files /dev/null and b/Docs/Reports/X/Short/StrategyTester Short 1.gif differ diff --git a/Docs/Reports/X/Short/StrategyTester Short 1.htm b/Docs/Reports/X/Short/StrategyTester Short 1.htm new file mode 100644 index 0000000..a4e0cd2 --- /dev/null +++ b/Docs/Reports/X/Short/StrategyTester Short 1.htm @@ -0,0 +1,95 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.01 23:45 (2020.01.01 - 2023.08.02)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=false; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +xShortR2R=2; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63353Ticks modelled72601176Modelling qualityn/a
Mismatched charts errors808
Initial deposit1000.00SpreadCurrent (50)
Total net profit16.30Gross profit36.30Gross loss-20.00
Profit factor1.81Expected payoff1.25
Absolute drawdown9.13Maximal drawdown21.03 (2.03%)Relative drawdown2.03% (21.03)
Total trades13Short positions (won %)13 (92.31%)Long positions (won %)0 (0.00%)
Profit trades (% of total)12 (92.31%)Loss trades (% of total)1 (7.69%)
Largestprofit trade5.88loss trade-20.00
Averageprofit trade3.02loss trade-20.00
Maximumconsecutive wins (profit in money)12 (36.30)consecutive losses (loss in money)1 (-20.00)
Maximalconsecutive profit (count of wins)36.30 (12)consecutive loss (count of losses)-20.00 (1)
Averageconsecutive wins12consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.18 02:30sell10.011884.040.001881.64
22020.12.18 03:09t/p10.011881.640.001881.642.401002.40
32021.05.04 23:15sell20.011779.150.001777.95
42021.05.05 01:39t/p20.011777.950.001777.951.421003.82
52021.06.18 08:45sell30.011784.490.001779.73
62021.06.18 15:24t/p30.011779.730.001779.734.761008.58
72021.12.15 04:45sell40.011771.980.001769.86
82021.12.15 07:22t/p40.011769.860.001769.862.121010.70
92022.02.14 13:30sell50.011855.860.001852.18
102022.02.14 14:46t/p50.011852.180.001852.183.681014.38
112022.03.14 08:45sell60.011975.330.001973.81
122022.03.14 09:24t/p60.011973.810.001973.811.521015.90
132022.05.17 11:30sell70.011827.110.001821.23
142022.05.17 17:07t/p70.011821.230.001821.235.881021.78
152022.06.24 05:00sell80.011823.760.001821.18
162022.06.24 16:00t/p80.011821.180.001821.182.581024.36
172022.08.08 22:30sell90.011787.280.001783.52
182022.08.09 05:13t/p90.011783.520.001783.523.981028.34
192022.11.15 15:00sell100.011775.140.001770.92
202022.11.15 16:38t/p100.011770.920.001770.924.221032.56
212023.03.21 07:45sell110.011981.970.001979.33
222023.03.21 08:17t/p110.011979.330.001979.332.641035.20
232023.03.31 07:15sell120.011981.510.001980.41
242023.03.31 08:07t/p120.011980.410.001980.411.101036.30
252023.07.07 04:30sell130.011911.150.001908.99
262023.07.07 17:37close130.011931.150.001908.99-20.001016.30
+
diff --git a/Docs/Reports/X/Short/StrategyTester Short 2.gif b/Docs/Reports/X/Short/StrategyTester Short 2.gif new file mode 100644 index 0000000..65134d7 Binary files /dev/null and b/Docs/Reports/X/Short/StrategyTester Short 2.gif differ diff --git a/Docs/Reports/X/Short/StrategyTester Short 2.htm b/Docs/Reports/X/Short/StrategyTester Short 2.htm new file mode 100644 index 0000000..6dae19e --- /dev/null +++ b/Docs/Reports/X/Short/StrategyTester Short 2.htm @@ -0,0 +1,85 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.01 23:45 (2020.01.01 - 2023.08.02)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=false; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=true; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +enableXRLong=true; +enableXRShort=true; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63353Ticks modelled72601176Modelling qualityn/a
Mismatched charts errors808
Initial deposit1000.00SpreadCurrent (50)
Total net profit18.48Gross profit18.48Gross loss-0.00
Profit factorExpected payoff3.70
Absolute drawdown10.94Maximal drawdown14.46 (1.44%)Relative drawdown1.44% (14.46)
Total trades5Short positions (won %)5 (100.00%)Long positions (won %)0 (0.00%)
Profit trades (% of total)5 (100.00%)Loss trades (% of total)0 (0.00%)
Largestprofit trade7.14loss trade-0.00
Averageprofit trade3.70loss trade-0.00
Maximumconsecutive wins (profit in money)5 (18.48)consecutive losses (loss in money)0 (-0.00)
Maximalconsecutive profit (count of wins)18.48 (5)consecutive loss (count of losses)-0.00 (0)
Averageconsecutive wins5consecutive losses0
+Graph
+ + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12021.05.04 23:15sell10.011779.150.001777.35
22021.05.05 03:24t/p10.011777.350.001777.352.011002.01
32021.06.18 08:45sell20.011784.490.001777.35
42021.06.18 15:52t/p20.011777.350.001777.357.141009.15
52021.12.15 04:45sell30.011771.980.001768.80
62021.12.15 07:39t/p30.011768.800.001768.803.181012.33
72022.03.14 08:45sell40.011975.330.001973.05
82022.03.14 09:54t/p40.011973.050.001973.052.281014.61
92022.06.24 05:00sell50.011823.760.001819.89
102022.06.24 16:00t/p50.011819.890.001819.893.871018.48
+
diff --git a/Docs/Reports/XR/Long/StrategyTester 1.gif b/Docs/Reports/XR/Long/StrategyTester 1.gif new file mode 100644 index 0000000..e16f6e5 Binary files /dev/null and b/Docs/Reports/XR/Long/StrategyTester 1.gif differ diff --git a/Docs/Reports/XR/Long/StrategyTester 1.htm b/Docs/Reports/XR/Long/StrategyTester 1.htm new file mode 100644 index 0000000..1c5b449 --- /dev/null +++ b/Docs/Reports/XR/Long/StrategyTester 1.htm @@ -0,0 +1,217 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.01 23:45 (2020.01.01 - 2023.08.02)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=true; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63353Ticks modelled72601176Modelling qualityn/a
Mismatched charts errors808
Initial deposit1000.00SpreadCurrent (51)
Total net profit95.44Gross profit261.37Gross loss-165.93
Profit factor1.58Expected payoff1.34
Absolute drawdown5.38Maximal drawdown31.55 (2.87%)Relative drawdown2.87% (31.55)
Total trades71Short positions (won %)0 (0.00%)Long positions (won %)71 (57.75%)
Profit trades (% of total)41 (57.75%)Loss trades (% of total)30 (42.25%)
Largestprofit trade17.60loss trade-10.50
Averageprofit trade6.37loss trade-5.53
Maximumconsecutive wins (profit in money)4 (33.04)consecutive losses (loss in money)3 (-6.71)
Maximalconsecutive profit (count of wins)33.04 (4)consecutive loss (count of losses)-16.35 (2)
Averageconsecutive wins2consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.03 23:30buy10.011841.350.001845.81
22020.12.04 15:31t/p10.011845.810.001845.814.021004.02
32020.12.08 18:30buy20.011870.260.001886.04
42020.12.09 03:19close20.011867.580.001886.04-3.121000.90
52020.12.30 03:45buy30.011883.200.001893.66
62020.12.30 10:00close30.011878.490.001893.66-4.71996.19
72020.12.30 18:00buy40.011885.770.001895.53
82020.12.31 02:15t/p40.011895.530.001895.538.431004.62
92020.12.31 13:45buy50.011894.790.001901.55
102021.01.04 01:00t/p50.011901.550.001901.555.881010.49
112021.01.05 11:30buy60.011944.620.001954.40
122021.01.06 03:09t/p60.011954.400.001954.409.341019.83
132021.04.05 17:30buy70.011729.330.001742.53
142021.04.05 22:00close70.011725.680.001742.53-3.651016.18
152021.04.26 21:00buy80.011779.920.001781.68
162021.04.26 23:39t/p80.011781.680.001781.681.761017.94
172021.05.11 09:00buy90.011837.320.001840.12
182021.05.11 09:51close90.011834.840.001840.12-2.481015.46
192021.05.18 23:45buy100.011870.120.001872.90
202021.05.19 05:00close100.011867.630.001872.90-2.931012.53
212021.05.20 08:15buy110.011876.000.001876.98
222021.05.20 08:30t/p110.011876.980.001876.980.981013.51
232021.05.21 11:30buy120.011876.440.001882.56
242021.05.21 15:21t/p120.011882.560.001882.566.121019.63
252021.05.24 19:15buy130.011883.920.001887.18
262021.05.25 01:15close130.011880.910.001887.18-3.451016.18
272021.05.25 10:45buy140.011884.070.001898.65
282021.05.25 21:06t/p140.011898.650.001898.6514.581030.76
292021.06.28 20:30buy150.011780.420.001785.26
302021.06.28 21:15close150.011778.020.001785.26-2.401028.36
312021.07.02 02:00buy160.011776.540.001777.70
322021.07.02 03:39t/p160.011777.700.001777.701.161029.52
332021.07.06 04:15buy170.011792.850.001796.01
342021.07.06 04:53t/p170.011796.010.001796.013.161032.68
352021.07.09 17:45buy180.011806.300.001814.82
362021.07.12 07:16close180.011801.870.001814.82-4.871027.80
372021.07.13 17:45buy190.011811.780.001825.18
382021.07.13 21:07close190.011806.200.001825.18-5.581022.22
392021.08.11 05:30buy200.011732.160.001747.52
402021.08.11 18:06t/p200.011747.520.001747.5215.361037.58
412021.08.12 23:00buy210.011753.700.001757.12
422021.08.13 09:09t/p210.011757.120.001757.122.981040.56
432021.08.18 04:30buy220.011789.060.001796.30
442021.08.18 12:30close220.011787.880.001796.30-1.181039.38
452021.09.01 22:30buy230.011815.240.001820.60
462021.09.02 02:45close230.011813.220.001820.60-3.351036.04
472021.09.02 03:15buy240.011815.340.001819.70
482021.09.02 05:30close240.011813.160.001819.70-2.181033.86
492021.09.03 05:15buy250.011813.400.001819.26
502021.09.03 15:34t/p250.011819.260.001819.265.861039.72
512021.09.27 03:45buy260.011753.840.001763.88
522021.09.27 12:49close260.011749.120.001763.88-4.721035.00
532021.10.22 02:15buy270.011785.940.001793.12
542021.10.22 09:52t/p270.011793.120.001793.127.181042.18
552021.11.16 04:45buy280.011867.770.001877.31
562021.11.16 09:45close280.011863.300.001877.31-4.471037.71
572021.12.07 04:30buy290.011780.920.001785.14
582021.12.07 05:45close290.011778.500.001785.14-2.421035.29
592021.12.07 20:30buy300.011784.340.001788.42
602021.12.08 04:07t/p300.011788.420.001788.423.641038.92
612021.12.28 08:15buy310.011813.060.001819.28
622021.12.28 15:36t/p310.011819.280.001819.286.221045.14
632022.01.10 21:30buy320.011801.130.001805.89
642022.01.11 04:24t/p320.011805.890.001805.894.321049.46
652022.01.19 11:15buy330.011816.040.001824.86
662022.01.19 15:33t/p330.011824.860.001824.868.821058.28
672022.01.24 23:15buy340.011843.290.001853.65
682022.01.25 12:36close340.011836.700.001853.65-7.031051.25
692022.01.31 11:30buy350.011791.190.001798.83
702022.01.31 16:39t/p350.011798.830.001798.837.641058.89
712022.02.16 09:30buy360.011856.020.001860.76
722022.02.16 15:00close360.011852.740.001860.76-3.281055.61
732022.02.28 16:15buy370.011914.370.001926.79
742022.02.28 18:09close370.011904.370.001926.79-10.001045.61
752022.03.03 22:15buy380.011937.320.001946.64
762022.03.04 02:36t/p380.011946.640.001946.648.881054.49
772022.03.04 13:00buy390.011947.540.001961.66
782022.03.04 18:09t/p390.011961.660.001961.6614.121068.61
792022.03.11 21:30buy400.011986.860.001999.16
802022.03.14 00:22close400.011976.800.001999.16-10.501058.10
812022.03.24 13:30buy410.011946.410.001957.33
822022.03.24 14:03t/p410.011957.330.001957.3310.921069.02
832022.04.05 16:15buy420.011935.180.001956.54
842022.04.05 18:24close420.011925.180.001956.54-10.001059.02
852022.04.13 08:30buy430.011969.770.001973.31
862022.04.13 08:48t/p430.011973.310.001973.313.541062.56
872022.05.20 09:45buy440.011848.250.001859.53
882022.05.20 16:31close440.011840.590.001859.53-7.661054.90
892022.05.23 01:15buy450.011845.220.001848.46
902022.05.23 02:07t/p450.011848.460.001848.463.241058.14
912022.05.30 06:45buy460.011859.710.001862.85
922022.05.30 08:42t/p460.011862.850.001862.853.141061.28
932022.06.08 15:15buy470.011851.230.001858.73
942022.06.08 18:07t/p470.011858.730.001858.737.501068.78
952022.07.05 02:15buy480.011809.920.001814.70
962022.07.05 10:30close480.011806.730.001814.70-3.191065.59
972022.10.27 08:45buy490.011669.880.001683.00
982022.10.27 09:45close490.011661.850.001683.00-8.031057.56
992022.11.02 04:00buy500.011650.370.001653.27
1002022.11.02 10:00t/p500.011653.270.001653.272.901060.46
1012022.11.16 12:15buy510.011783.530.001796.87
1022022.11.16 16:43close510.011773.530.001796.87-10.001050.46
1032022.11.30 05:45buy520.011754.060.001759.10
1042022.11.30 10:53t/p520.011759.100.001759.105.041055.50
1052022.12.08 15:15buy530.011787.270.001794.47
1062022.12.08 17:28t/p530.011794.470.001794.477.201062.70
1072022.12.21 16:45buy540.011818.210.001822.71
1082022.12.21 17:36t/p540.011822.710.001822.714.501067.20
1092023.01.09 18:45buy550.011876.890.001885.73
1102023.01.10 02:26close550.011868.360.001885.73-8.971058.23
1112023.01.11 06:30buy560.011877.530.001882.75
1122023.01.11 07:37t/p560.011882.750.001882.755.221063.45
1132023.02.09 05:00buy570.011879.440.001889.90
1142023.02.09 16:00t/p570.011889.900.001889.9010.461073.91
1152023.02.16 21:30buy580.011843.430.001847.45
1162023.02.17 01:15close580.011835.010.001847.45-8.861065.05
1172023.02.22 05:15buy590.011837.090.001840.59
1182023.02.22 10:03t/p590.011840.590.001840.593.501068.55
1192023.03.17 04:45buy600.011929.050.001946.65
1202023.03.17 15:02t/p600.011946.650.001946.6517.601086.15
1212023.03.28 17:00buy610.011963.600.001968.68
1222023.03.28 17:57t/p610.011968.680.001968.685.081091.23
1232023.03.30 10:45buy620.011969.470.001976.33
1242023.03.30 19:01t/p620.011976.330.001976.336.861098.09
1252023.04.26 13:30buy630.012000.050.002005.35
1262023.04.26 15:30close630.011993.710.002005.35-6.341091.75
1272023.04.27 06:00buy640.011999.070.002014.41
1282023.04.27 15:35close640.011989.060.002014.41-10.011081.74
1292023.05.09 08:15buy650.012026.970.002032.23
1302023.05.09 14:30t/p650.012032.230.002032.235.261087.00
1312023.05.15 19:45buy660.012020.210.002031.69
1322023.05.15 22:00close660.012014.590.002031.69-5.621081.38
1332023.06.09 17:30buy670.011967.540.001988.74
1342023.06.09 18:30close670.011962.630.001988.74-4.911076.47
1352023.06.13 03:15buy680.011960.910.001966.27
1362023.06.13 15:30t/p680.011966.270.001966.275.361081.83
1372023.07.12 03:45buy690.011936.010.001941.67
1382023.07.12 15:30t/p690.011941.670.001941.675.661087.49
1392023.07.19 23:00buy700.011978.690.001982.47
1402023.07.20 04:30t/p700.011982.470.001982.472.451089.94
1412023.07.31 15:00buy710.011959.430.001964.93
1422023.07.31 15:31t/p710.011964.930.001964.935.501095.44
+
diff --git a/Docs/Reports/XR/Long/StrategyTester 10.gif b/Docs/Reports/XR/Long/StrategyTester 10.gif new file mode 100644 index 0000000..605ff8a Binary files /dev/null and b/Docs/Reports/XR/Long/StrategyTester 10.gif differ diff --git a/Docs/Reports/XR/Long/StrategyTester 10.htm b/Docs/Reports/XR/Long/StrategyTester 10.htm new file mode 100644 index 0000000..4dcf5fd --- /dev/null +++ b/Docs/Reports/XR/Long/StrategyTester 10.htm @@ -0,0 +1,89 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.04 23:45 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=false; +xRShortR2R=1.5; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.015; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xRSwingLength=48; xRSharpDetectionFactor=1350; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63629Ticks modelled72967510Modelling qualityn/a
Mismatched charts errors826
Initial deposit1000.00SpreadCurrent (60)
Total net profit100.29Gross profit131.18Gross loss-30.88
Profit factor4.25Expected payoff14.33
Absolute drawdown5.87Maximal drawdown29.76 (2.81%)Relative drawdown2.81% (29.76)
Total trades7Short positions (won %)0 (0.00%)Long positions (won %)7 (57.14%)
Profit trades (% of total)4 (57.14%)Loss trades (% of total)3 (42.86%)
Largestprofit trade53.90loss trade-10.88
Averageprofit trade32.79loss trade-10.29
Maximumconsecutive wins (profit in money)2 (24.79)consecutive losses (loss in money)2 (-20.88)
Maximalconsecutive profit (count of wins)53.90 (1)consecutive loss (count of losses)-20.88 (2)
Averageconsecutive wins1consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.01 19:30buy10.011812.670.001867.81
22020.12.07 18:09t/p10.011867.810.001867.8152.491052.49
32021.02.23 04:07buy20.011813.000.001850.54
42021.02.23 16:34close20.011803.000.001850.54-10.001042.49
52021.07.29 04:30buy30.011816.220.001862.70
62021.08.02 15:16close30.011806.220.001862.70-10.881031.60
72021.11.05 18:45buy40.011814.410.001872.29
82021.11.16 10:54t/p40.011872.290.001872.2953.901085.50
92022.02.04 15:30buy50.011813.380.001827.74
102022.02.04 15:37close50.011803.380.001827.74-10.001075.50
112022.02.07 11:01buy60.011813.370.001825.93
122022.02.07 16:19buy70.011815.990.001829.55
132022.02.08 17:22t/p60.011825.930.001825.9312.121087.62
142022.02.09 15:04t/p70.011829.550.001829.5512.681100.29
+
diff --git a/Docs/Reports/XR/Long/StrategyTester 11.gif b/Docs/Reports/XR/Long/StrategyTester 11.gif new file mode 100644 index 0000000..bd320fc Binary files /dev/null and b/Docs/Reports/XR/Long/StrategyTester 11.gif differ diff --git a/Docs/Reports/XR/Long/StrategyTester 11.htm b/Docs/Reports/XR/Long/StrategyTester 11.htm new file mode 100644 index 0000000..12a09e2 --- /dev/null +++ b/Docs/Reports/XR/Long/StrategyTester 11.htm @@ -0,0 +1,167 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.07 23:45 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=false; +xRShortR2R=1.5; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=1.5; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xRSwingLength=48; xRSharpDetectionFactor=1350; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63721Ticks modelled73052669Modelling qualityn/a
Mismatched charts errors959
Initial deposit1000.00SpreadCurrent (60)
Total net profit66.06Gross profit313.93Gross loss-247.87
Profit factor1.27Expected payoff1.44
Absolute drawdown11.93Maximal drawdown111.45 (9.77%)Relative drawdown9.77% (111.45)
Total trades46Short positions (won %)0 (0.00%)Long positions (won %)46 (43.48%)
Profit trades (% of total)20 (43.48%)Loss trades (% of total)26 (56.52%)
Largestprofit trade42.10loss trade-11.77
Averageprofit trade15.70loss trade-9.53
Maximumconsecutive wins (profit in money)4 (58.47)consecutive losses (loss in money)9 (-88.41)
Maximalconsecutive profit (count of wins)61.47 (3)consecutive loss (count of losses)-88.41 (9)
Averageconsecutive wins3consecutive losses4
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.01 19:30buy10.011812.670.001854.03
22020.12.02 02:30buy20.011813.300.001827.99
32020.12.02 08:45buy30.011813.220.001821.29
42020.12.02 10:36t/p30.011821.290.001821.298.071008.07
52020.12.02 12:22t/p20.011827.990.001827.9914.691022.76
62020.12.07 16:54t/p10.011854.030.001854.0338.711061.47
72021.02.05 19:15buy40.011814.870.001846.31
82021.02.08 01:15buy50.011817.920.001853.94
92021.02.08 07:30buy60.011815.770.001825.97
102021.02.08 10:54close50.011807.920.001853.94-10.001051.47
112021.02.08 11:45buy70.011813.190.001820.66
122021.02.08 13:36t/p70.011820.660.001820.667.471058.94
132021.02.08 14:53t/p60.011825.970.001825.9710.201069.14
142021.02.09 11:24t/p40.011846.310.001846.3130.561099.69
152021.02.23 04:00buy80.011813.660.001842.81
162021.02.23 05:45buy90.011813.350.001827.83
172021.02.23 12:03close80.011803.660.001842.81-10.001089.69
182021.02.23 16:34close90.011803.350.001827.83-10.001079.69
192021.05.06 18:00buy100.011815.960.001857.50
202021.05.12 23:21close100.011815.950.001857.50-1.781077.91
212021.07.08 14:00buy110.011817.800.001849.44
222021.07.08 16:54close110.011807.800.001849.44-10.001067.91
232021.07.13 15:30buy120.011813.610.001824.61
242021.07.13 15:33close120.011803.610.001824.61-10.001057.91
252021.07.13 18:15buy130.011812.880.001833.64
262021.07.14 06:30buy140.011813.470.001826.19
272021.07.14 08:30buy150.011813.850.001827.14
282021.07.14 10:45buy160.011813.970.001827.44
292021.07.14 15:09t/p140.011826.190.001826.1912.721070.63
302021.07.14 15:37t/p150.011827.140.001827.1413.291083.92
312021.07.14 15:37t/p160.011827.440.001827.4413.471097.39
322021.07.15 10:09t/p130.011833.640.001833.6418.991116.38
332021.07.29 04:30buy170.011816.220.001851.08
342021.08.02 15:16close170.011806.220.001851.08-10.881105.50
352021.08.27 19:15buy180.011814.970.001860.75
362021.08.31 04:30buy190.011814.070.001822.88
372021.08.31 14:15buy200.011814.320.001820.52
382021.08.31 16:07close180.011804.970.001860.75-10.881094.61
392021.08.31 16:09close200.011804.320.001820.52-10.001084.61
402021.08.31 16:09close190.011804.070.001822.88-10.001074.61
412021.08.31 20:00buy210.011814.380.001832.73
422021.09.01 04:30buy220.011813.000.001829.28
432021.09.03 14:00close210.011813.360.001832.73-3.231071.38
442021.09.03 17:37t/p220.011829.280.001829.2814.511085.89
452021.11.05 18:45buy230.011814.420.001857.85
462021.11.10 16:24t/p230.011857.850.001857.8542.101128.00
472021.12.27 18:00buy240.011813.070.001827.70
482021.12.28 08:00buy250.011813.290.001822.58
492021.12.28 17:00buy260.011814.240.001821.44
502021.12.29 02:08close260.011804.240.001821.44-10.441117.55
512021.12.29 10:07close250.011803.290.001822.58-10.441107.11
522021.12.29 10:09close240.011803.070.001827.70-10.881096.23
532021.12.30 19:00buy270.011813.910.001839.94
542022.01.03 16:54close270.011803.910.001839.94-10.881085.34
552022.01.04 17:45buy280.011817.100.001844.31
562022.01.04 19:30buy290.011814.680.001838.26
572022.01.06 03:09close280.011807.100.001844.31-11.771073.57
582022.01.06 07:37close290.011804.680.001838.26-11.771061.80
592022.01.11 18:30buy300.011815.760.001836.12
602022.01.14 19:18close300.011815.750.001836.12-2.221059.58
612022.02.04 12:30buy310.011814.110.001827.76
622022.02.04 15:30buy320.011813.380.001824.15
632022.02.04 15:37close310.011804.110.001827.76-10.001049.58
642022.02.04 15:37close320.011803.380.001824.15-10.001039.58
652022.02.07 02:45buy330.011812.890.001843.42
662022.02.07 11:00buy340.011813.460.001823.02
672022.02.07 14:00buy350.011814.020.001821.27
682022.02.07 16:15buy360.011816.190.001826.66
692022.02.07 21:07t/p350.011821.270.001821.277.251046.83
702022.02.07 21:39t/p340.011823.020.001823.029.561056.39
712022.02.08 17:24t/p360.011826.660.001826.6610.031066.42
722022.02.11 20:34t/p330.011843.420.001843.4227.881094.30
732022.12.13 16:30buy370.011818.980.001875.20
742022.12.13 17:50close370.011808.980.001875.20-10.001084.30
752022.12.13 18:45buy380.011813.360.001859.13
762022.12.14 21:01close380.011803.350.001859.13-10.451073.84
772022.12.20 17:15buy390.011820.930.001871.35
782022.12.21 09:30buy400.011815.440.001820.23
792022.12.21 14:00buy410.011814.150.001817.00
802022.12.21 15:13t/p410.011817.000.001817.002.851076.69
812022.12.21 17:08t/p400.011820.230.001820.234.791081.48
822022.12.22 15:38close390.011810.930.001871.35-11.771069.72
832022.12.27 17:30buy420.011821.790.001850.43
842022.12.27 19:58close420.011811.790.001850.43-10.001059.72
852022.12.27 20:15buy430.011815.080.001833.65
862022.12.28 03:30buy440.011814.740.001832.80
872022.12.28 10:15close430.011805.080.001833.65-10.441049.27
882022.12.28 10:15close440.011804.730.001832.80-10.011039.26
892022.12.29 17:00buy450.011814.400.001828.85
902022.12.29 18:45buy460.011814.770.001829.77
912023.01.03 01:05t/p450.011828.850.001828.8513.121052.39
922023.01.03 01:07t/p460.011829.770.001829.7713.671066.06
+
diff --git a/Docs/Reports/XR/Long/StrategyTester 2.gif b/Docs/Reports/XR/Long/StrategyTester 2.gif new file mode 100644 index 0000000..4ec49d5 Binary files /dev/null and b/Docs/Reports/XR/Long/StrategyTester 2.gif differ diff --git a/Docs/Reports/XR/Long/StrategyTester 2.htm b/Docs/Reports/XR/Long/StrategyTester 2.htm new file mode 100644 index 0000000..c9d8a08 --- /dev/null +++ b/Docs/Reports/XR/Long/StrategyTester 2.htm @@ -0,0 +1,91 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.01.29 23:45 (2020.01.01 - 2021.01.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xRSwingLength=11; xRSharpDetectionFactor=650; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test4192Ticks modelled3544155Modelling quality24.42%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (51)
Total net profit59.63Gross profit79.64Gross loss-20.01
Profit factor3.98Expected payoff7.45
Absolute drawdown24.68Maximal drawdown42.62 (4.07%)Relative drawdown4.07% (42.62)
Total trades8Short positions (won %)0 (0.00%)Long positions (won %)8 (75.00%)
Profit trades (% of total)6 (75.00%)Loss trades (% of total)2 (25.00%)
Largestprofit trade19.99loss trade-10.01
Averageprofit trade13.27loss trade-10.00
Maximumconsecutive wins (profit in money)3 (49.04)consecutive losses (loss in money)1 (-10.01)
Maximalconsecutive profit (count of wins)49.04 (3)consecutive loss (count of losses)-10.01 (1)
Averageconsecutive wins3consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 02:45buy10.011813.240.001823.26
22020.11.27 07:31close10.011803.230.001823.26-10.01989.99
32020.12.01 16:15buy20.011814.300.001836.06
42020.12.01 19:15buy30.011813.970.001831.39
52020.12.02 01:00buy40.011812.820.001812.82
62020.12.02 02:09t/p40.011812.820.001812.820.00989.99
72020.12.02 08:30buy50.011814.560.001828.18
82020.12.02 10:45buy60.011824.380.001851.10
92020.12.02 12:22t/p50.011828.180.001828.1813.621003.61
102020.12.02 12:39t/p30.011831.390.001831.3916.981020.59
112020.12.02 15:54close60.011814.380.001851.10-10.001010.59
122020.12.02 16:15buy70.011819.680.001832.70
132020.12.03 05:19t/p70.011832.700.001832.7011.691022.28
142020.12.03 05:37t/p20.011836.060.001836.0619.991042.27
152021.01.18 02:45buy80.011819.330.001836.69
162021.01.18 07:37t/p80.011836.690.001836.6917.361059.63
+
diff --git a/Docs/Reports/XR/Long/StrategyTester 3.gif b/Docs/Reports/XR/Long/StrategyTester 3.gif new file mode 100644 index 0000000..da54e45 Binary files /dev/null and b/Docs/Reports/XR/Long/StrategyTester 3.gif differ diff --git a/Docs/Reports/XR/Long/StrategyTester 3.htm b/Docs/Reports/XR/Long/StrategyTester 3.htm new file mode 100644 index 0000000..868efaf --- /dev/null +++ b/Docs/Reports/XR/Long/StrategyTester 3.htm @@ -0,0 +1,87 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.01.29 23:45 (2020.01.01 - 2021.01.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xRSwingLength=11; xRSharpDetectionFactor=650; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test4192Ticks modelled3544155Modelling quality24.42%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (51)
Total net profit57.80Gross profit67.80Gross loss-10.00
Profit factor6.78Expected payoff9.63
Absolute drawdown20.25Maximal drawdown42.62 (4.01%)Relative drawdown4.01% (42.62)
Total trades6Short positions (won %)0 (0.00%)Long positions (won %)6 (83.33%)
Profit trades (% of total)5 (83.33%)Loss trades (% of total)1 (16.67%)
Largestprofit trade19.99loss trade-10.00
Averageprofit trade13.56loss trade-10.00
Maximumconsecutive wins (profit in money)3 (36.12)consecutive losses (loss in money)1 (-10.00)
Maximalconsecutive profit (count of wins)36.12 (3)consecutive loss (count of losses)-10.00 (1)
Averageconsecutive wins3consecutive losses1
+Graph
+ + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.01 16:15buy10.011814.300.001836.06
22020.12.01 19:15buy20.011813.970.001831.39
32020.12.02 01:00buy30.011812.820.001818.34
42020.12.02 08:30buy40.011814.560.001828.18
52020.12.02 10:34t/p30.011818.340.001818.345.521005.52
62020.12.02 10:45buy50.011824.380.001851.10
72020.12.02 12:22t/p40.011828.180.001828.1813.621019.14
82020.12.02 12:39t/p20.011831.390.001831.3916.981036.12
92020.12.02 15:54close50.011814.380.001851.10-10.001026.12
102020.12.02 16:15buy60.011819.680.001832.70
112020.12.03 05:19t/p60.011832.700.001832.7011.691037.81
122020.12.03 05:37t/p10.011836.060.001836.0619.991057.80
+
diff --git a/Docs/Reports/XR/Long/StrategyTester 4.gif b/Docs/Reports/XR/Long/StrategyTester 4.gif new file mode 100644 index 0000000..5d8f0b3 Binary files /dev/null and b/Docs/Reports/XR/Long/StrategyTester 4.gif differ diff --git a/Docs/Reports/XR/Long/StrategyTester 4.htm b/Docs/Reports/XR/Long/StrategyTester 4.htm new file mode 100644 index 0000000..0d2ba8e --- /dev/null +++ b/Docs/Reports/XR/Long/StrategyTester 4.htm @@ -0,0 +1,85 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.01.29 23:45 (2020.01.01 - 2021.01.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.015; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.015; xRMaximumCandlesPerTrade=252; xRSwingLength=11; xRSharpDetectionFactor=650; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test4192Ticks modelled3544155Modelling quality24.42%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (51)
Total net profit67.80Gross profit67.80Gross loss-0.00
Profit factorExpected payoff13.56
Absolute drawdown20.25Maximal drawdown26.20 (2.60%)Relative drawdown2.60% (26.20)
Total trades5Short positions (won %)0 (0.00%)Long positions (won %)5 (100.00%)
Profit trades (% of total)5 (100.00%)Loss trades (% of total)0 (0.00%)
Largestprofit trade19.99loss trade-0.00
Averageprofit trade13.56loss trade-0.00
Maximumconsecutive wins (profit in money)5 (67.80)consecutive losses (loss in money)0 (-0.00)
Maximalconsecutive profit (count of wins)67.80 (5)consecutive loss (count of losses)-0.00 (0)
Averageconsecutive wins5consecutive losses0
+Graph
+ + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.01 16:15buy10.011814.300.001836.06
22020.12.01 19:15buy20.011813.970.001831.39
32020.12.02 01:00buy30.011812.820.001818.34
42020.12.02 08:30buy40.011814.560.001828.18
52020.12.02 10:34t/p30.011818.340.001818.345.521005.52
62020.12.02 12:22t/p40.011828.180.001828.1813.621019.14
72020.12.02 12:39t/p20.011831.390.001831.3916.981036.12
82020.12.02 16:15buy50.011819.680.001832.70
92020.12.03 05:19t/p50.011832.700.001832.7011.691047.81
102020.12.03 05:37t/p10.011836.060.001836.0619.991067.80
+
diff --git a/Docs/Reports/XR/Long/StrategyTester 5.gif b/Docs/Reports/XR/Long/StrategyTester 5.gif new file mode 100644 index 0000000..f2053e2 Binary files /dev/null and b/Docs/Reports/XR/Long/StrategyTester 5.gif differ diff --git a/Docs/Reports/XR/Long/StrategyTester 5.htm b/Docs/Reports/XR/Long/StrategyTester 5.htm new file mode 100644 index 0000000..42889ef --- /dev/null +++ b/Docs/Reports/XR/Long/StrategyTester 5.htm @@ -0,0 +1,103 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2021.03.30 23:45 (2020.01.01 - 2021.03.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.015; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.015; xRMaximumCandlesPerTrade=252; xRSwingLength=11; xRSharpDetectionFactor=650; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test8040Ticks modelled9476561Modelling quality24.70%
Mismatched charts errors0
Initial deposit1000.00SpreadCurrent (50)
Total net profit63.48Gross profit123.48Gross loss-60.00
Profit factor2.06Expected payoff4.53
Absolute drawdown20.22Maximal drawdown67.32 (5.95%)Relative drawdown5.95% (67.32)
Total trades14Short positions (won %)0 (0.00%)Long positions (won %)14 (71.43%)
Profit trades (% of total)10 (71.43%)Loss trades (% of total)4 (28.57%)
Largestprofit trade19.99loss trade-15.00
Averageprofit trade12.35loss trade-15.00
Maximumconsecutive wins (profit in money)10 (123.48)consecutive losses (loss in money)4 (-60.00)
Maximalconsecutive profit (count of wins)123.48 (10)consecutive loss (count of losses)-60.00 (4)
Averageconsecutive wins10consecutive losses4
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.01 16:15buy10.011814.290.001836.05
22020.12.01 19:15buy20.011813.960.001831.38
32020.12.02 01:00buy30.011812.810.001818.35
42020.12.02 08:30buy40.011814.550.001828.17
52020.12.02 10:34t/p30.011818.350.001818.355.541005.54
62020.12.02 12:22t/p40.011828.170.001828.1713.621019.16
72020.12.02 12:39t/p20.011831.380.001831.3816.981036.14
82020.12.02 16:15buy50.011819.670.001832.69
92020.12.03 05:19t/p50.011832.690.001832.6911.691047.83
102020.12.03 05:37t/p10.011836.050.001836.0519.991067.82
112021.02.05 22:30buy60.011812.580.001817.60
122021.02.08 01:07t/p60.011817.600.001817.604.581072.40
132021.02.08 01:15buy70.011817.820.001833.66
142021.02.08 05:15buy80.011811.700.001817.36
152021.02.08 09:21buy90.011816.730.001827.67
162021.02.08 09:30t/p80.011817.360.001817.365.661078.06
172021.02.08 13:22buy100.011817.990.001836.63
182021.02.08 15:37t/p90.011827.670.001827.6710.941089.00
192021.02.08 16:09t/p70.011833.660.001833.6615.841104.84
202021.02.08 17:24t/p100.011836.630.001836.6318.641123.48
212021.02.23 02:00buy110.011810.780.001816.74
222021.02.23 04:00buy120.011813.560.001827.54
232021.02.23 08:00buy130.011813.000.001818.80
242021.02.23 16:38close120.011798.560.001827.54-15.001108.48
252021.02.23 16:38close130.011798.000.001818.80-15.001093.48
262021.02.23 16:48close110.011795.780.001816.74-15.001078.48
272021.02.24 04:19buy140.011811.640.001823.28
282021.02.24 15:47close140.011796.640.001823.28-15.001063.48
+
diff --git a/Docs/Reports/XR/Long/StrategyTester 6.gif b/Docs/Reports/XR/Long/StrategyTester 6.gif new file mode 100644 index 0000000..ca3bdd7 Binary files /dev/null and b/Docs/Reports/XR/Long/StrategyTester 6.gif differ diff --git a/Docs/Reports/XR/Long/StrategyTester 6.htm b/Docs/Reports/XR/Long/StrategyTester 6.htm new file mode 100644 index 0000000..e7f7192 --- /dev/null +++ b/Docs/Reports/XR/Long/StrategyTester 6.htm @@ -0,0 +1,89 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2022.01.03 01:00 - 2023.08.04 23:45 (2022.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=false; +xRShortR2R=1.5; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.015; xRLongR2R=1.5; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.015; xRMaximumCandlesPerTrade=252; xRSwingLength=7; xRSharpDetectionFactor=650; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test38648Ticks modelled45067506Modelling qualityn/a
Mismatched charts errors826
Initial deposit1000.00SpreadCurrent (60)
Total net profit30.68Gross profit30.68Gross loss-0.00
Profit factorExpected payoff4.38
Absolute drawdown1.72Maximal drawdown11.16 (1.10%)Relative drawdown1.10% (11.16)
Total trades7Short positions (won %)0 (0.00%)Long positions (won %)7 (100.00%)
Profit trades (% of total)7 (100.00%)Loss trades (% of total)0 (0.00%)
Largestprofit trade14.90loss trade-0.00
Averageprofit trade4.38loss trade-0.00
Maximumconsecutive wins (profit in money)7 (30.68)consecutive losses (loss in money)0 (-0.00)
Maximalconsecutive profit (count of wins)30.68 (7)consecutive loss (count of losses)-0.00 (0)
Averageconsecutive wins7consecutive losses0
+Graph
+ + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12022.01.11 02:39buy10.011803.570.001808.31
22022.01.11 07:54t/p10.011808.310.001808.314.741004.74
32022.01.11 16:48buy20.011803.580.001805.67
42022.01.11 16:52t/p20.011805.670.001805.672.091006.83
52022.02.01 10:19buy30.011803.580.001806.07
62022.02.01 11:09t/p30.011806.070.001806.072.491009.32
72022.02.01 16:03buy40.011803.580.001805.05
82022.02.01 16:09t/p40.011805.050.001805.051.471010.79
92022.02.02 14:02buy50.011803.480.001805.27
102022.02.02 15:21t/p50.011805.270.001805.271.791012.58
112022.12.20 11:15buy60.011803.390.001818.29
122022.12.20 17:10t/p60.011818.290.001818.2914.901027.48
132022.12.27 02:30buy70.011802.870.001806.07
142022.12.27 04:45t/p70.011806.070.001806.073.201030.68
+
diff --git a/Docs/Reports/XR/Long/StrategyTester 7.gif b/Docs/Reports/XR/Long/StrategyTester 7.gif new file mode 100644 index 0000000..9e04b0a Binary files /dev/null and b/Docs/Reports/XR/Long/StrategyTester 7.gif differ diff --git a/Docs/Reports/XR/Long/StrategyTester 7.htm b/Docs/Reports/XR/Long/StrategyTester 7.htm new file mode 100644 index 0000000..e5b9cca --- /dev/null +++ b/Docs/Reports/XR/Long/StrategyTester 7.htm @@ -0,0 +1,143 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.04 23:45 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=false; +xRShortR2R=1.5; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.015; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xRSwingLength=48; xRSharpDetectionFactor=650; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63629Ticks modelled72967510Modelling qualityn/a
Mismatched charts errors826
Initial deposit1000.00SpreadCurrent (60)
Total net profit125.81Gross profit290.45Gross loss-164.65
Profit factor1.76Expected payoff3.70
Absolute drawdown11.93Maximal drawdown74.32 (6.57%)Relative drawdown6.57% (74.32)
Total trades34Short positions (won %)0 (0.00%)Long positions (won %)34 (44.12%)
Profit trades (% of total)15 (44.12%)Loss trades (% of total)19 (55.88%)
Largestprofit trade53.92loss trade-11.77
Averageprofit trade19.36loss trade-8.67
Maximumconsecutive wins (profit in money)6 (82.82)consecutive losses (loss in money)6 (-46.65)
Maximalconsecutive profit (count of wins)105.06 (5)consecutive loss (count of losses)-46.65 (6)
Averageconsecutive wins4consecutive losses5
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.01 19:30buy10.011812.670.001867.81
22020.12.02 02:30buy20.011813.300.001832.88
32020.12.02 08:45buy30.011813.220.001823.98
42020.12.02 10:39t/p30.011823.980.001823.9810.761010.76
52020.12.03 05:19t/p20.011832.880.001832.8818.251029.01
62020.12.07 18:09t/p10.011867.810.001867.8152.491081.50
72021.02.08 07:30buy40.011816.010.001829.61
82021.02.08 11:45buy50.011813.190.001823.15
92021.02.08 14:46t/p50.011823.150.001823.159.961091.46
102021.02.08 15:49t/p40.011829.610.001829.6113.601105.06
112021.02.23 04:00buy60.011813.660.001852.52
122021.02.23 05:45buy70.011813.350.001832.65
132021.02.23 12:03close60.011803.660.001852.52-10.001095.06
142021.02.23 16:34close70.011803.350.001832.65-10.001085.06
152021.05.06 18:00buy80.011815.960.001871.34
162021.05.12 23:21close80.011815.950.001871.34-1.781083.28
172021.07.08 14:00buy90.011817.800.001859.98
182021.07.08 16:54close90.011807.800.001859.98-10.001073.28
192021.07.13 15:30buy100.011813.610.001828.27
202021.07.13 15:33close100.011803.610.001828.27-10.001063.28
212021.07.13 18:15buy110.011812.880.001840.56
222021.07.14 06:30buy120.011813.470.001830.43
232021.07.14 08:33buy130.011814.130.001831.85
242021.07.14 10:45buy140.011813.970.001831.93
252021.07.15 09:06t/p120.011830.430.001830.4315.631078.91
262021.07.15 09:09t/p130.011831.850.001831.8516.391095.31
272021.07.15 09:09t/p140.011831.930.001831.9316.631111.94
282021.07.16 17:52close110.011812.870.001840.56-2.221109.72
292021.07.29 04:30buy150.011816.220.001862.70
302021.08.02 15:16close150.011806.220.001862.70-10.881098.83
312021.08.27 19:15buy160.011814.970.001876.01
322021.08.31 04:30buy170.011814.070.001825.81
332021.08.31 14:15buy180.011814.320.001822.58
342021.08.31 16:07close160.011804.970.001876.01-10.881087.95
352021.08.31 16:09close180.011804.320.001822.58-10.001077.95
362021.08.31 16:09close170.011804.070.001825.81-10.001067.95
372021.09.01 06:00buy190.011814.440.001834.00
382021.09.07 11:09close190.011814.430.001834.00-2.661065.28
392021.11.05 18:45buy200.011814.420.001872.32
402021.11.16 10:54t/p200.011872.320.001872.3253.921119.20
412021.12.27 18:00buy210.011813.070.001832.57
422021.12.28 08:00buy220.011813.290.001825.67
432021.12.28 17:00buy230.011814.240.001823.84
442021.12.29 02:08close230.011804.240.001823.84-10.441108.76
452021.12.29 10:07close220.011803.290.001825.67-10.441098.32
462021.12.29 10:09close210.011803.070.001832.57-10.881087.43
472022.01.11 18:30buy240.011815.760.001842.90
482022.01.14 19:18close240.011815.750.001842.90-2.221085.21
492022.02.04 15:30buy250.011813.380.001827.74
502022.02.04 15:37close250.011803.380.001827.74-10.001075.21
512022.02.07 02:49buy260.011813.160.001853.86
522022.02.07 11:00buy270.011813.460.001826.20
532022.02.07 14:00buy280.011814.020.001823.68
542022.02.07 16:15buy290.011816.190.001830.15
552022.02.08 15:54t/p280.011823.680.001823.689.221084.43
562022.02.08 17:22t/p270.011826.200.001826.2012.301096.73
572022.02.09 15:06t/p290.011830.150.001830.1513.081109.80
582022.02.11 20:49t/p260.011853.860.001853.8638.051147.85
592022.12.20 17:22buy300.011818.080.001879.60
602022.12.21 09:31buy310.011815.890.001822.27
612022.12.21 14:00buy320.011814.150.001817.95
622022.12.21 15:20t/p320.011817.950.001817.953.801151.65
632022.12.21 17:36t/p310.011822.270.001822.276.381158.03
642022.12.22 15:53close300.011808.080.001879.60-11.771146.26
652022.12.27 20:15buy330.011815.080.001839.84
662022.12.28 03:30buy340.011814.740.001838.82
672022.12.28 10:15close330.011805.080.001839.84-10.441135.82
682022.12.28 10:15close340.011804.730.001838.82-10.011125.81
+
diff --git a/Docs/Reports/XR/Long/StrategyTester 8.gif b/Docs/Reports/XR/Long/StrategyTester 8.gif new file mode 100644 index 0000000..de9b6fb Binary files /dev/null and b/Docs/Reports/XR/Long/StrategyTester 8.gif differ diff --git a/Docs/Reports/XR/Long/StrategyTester 8.htm b/Docs/Reports/XR/Long/StrategyTester 8.htm new file mode 100644 index 0000000..1daf914 --- /dev/null +++ b/Docs/Reports/XR/Long/StrategyTester 8.htm @@ -0,0 +1,97 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.04 23:45 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=false; +xRShortR2R=1.5; xRShortLotsPerTradePercent=0.0001; xRShortMaxDrawdownPerTradePercent=0.15; xRLongR2R=2; xRLongLotsPerTradePercent=0.0001; xRLongMaxDrawdownPerTradePercent=0.1; xRMaximumCandlesPerTrade=252; xRSwingLength=48; xRSharpDetectionFactor=1350; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63629Ticks modelled72967510Modelling qualityn/a
Mismatched charts errors826
Initial deposit1000.00SpreadCurrent (60)
Total net profit1586.83Gross profit2026.73Gross loss-439.91
Profit factor4.61Expected payoff144.26
Absolute drawdown96.42Maximal drawdown616.71 (32.38%)Relative drawdown32.38% (616.71)
Total trades11Short positions (won %)0 (0.00%)Long positions (won %)11 (54.55%)
Profit trades (% of total)6 (54.55%)Loss trades (% of total)5 (45.45%)
Largestprofit trade538.99loss trade-108.85
Averageprofit trade337.79loss trade-87.98
Maximumconsecutive wins (profit in money)2 (1072.41)consecutive losses (loss in money)3 (-317.69)
Maximalconsecutive profit (count of wins)1072.41 (2)consecutive loss (count of losses)-317.69 (3)
Averageconsecutive wins2consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.01 19:30buy10.101812.670.001867.81
22020.12.02 10:36buy20.101821.850.001841.33
32020.12.03 09:52t/p20.101841.330.001841.33181.531181.53
42020.12.07 18:09t/p10.101867.810.001867.81524.861706.39
52021.02.23 04:07buy30.101813.000.001850.54
62021.02.23 16:34close30.101803.000.001850.54-100.001606.39
72021.07.29 04:30buy40.101816.220.001862.70
82021.07.29 09:52buy50.101818.920.001868.58
92021.08.02 04:39close50.101808.920.001868.58-108.851497.55
102021.08.02 15:16close40.101806.220.001862.70-108.851388.70
112021.11.05 18:45buy60.101814.410.001872.29
122021.11.08 03:07buy70.101819.710.001876.59
132021.11.16 10:54t/p60.101872.290.001872.29538.991927.69
142021.11.16 15:18t/p70.101876.590.001876.59533.422461.11
152022.02.04 15:30buy80.101813.380.001827.74
162022.02.04 15:37close80.101803.380.001827.74-100.002361.11
172022.02.07 11:01buy90.101813.370.001825.93
182022.02.07 16:19buy100.101815.990.001829.55
192022.02.07 20:25buy110.101821.630.001843.73
202022.02.08 17:22t/p90.101825.930.001825.93121.182482.29
212022.02.09 15:04t/p100.101829.550.001829.55126.752609.04
222022.02.10 15:33close110.101821.620.001843.73-22.222586.83
+
diff --git a/Docs/Reports/XR/Long/StrategyTester 9.gif b/Docs/Reports/XR/Long/StrategyTester 9.gif new file mode 100644 index 0000000..13f7a09 Binary files /dev/null and b/Docs/Reports/XR/Long/StrategyTester 9.gif differ diff --git a/Docs/Reports/XR/Long/StrategyTester 9.htm b/Docs/Reports/XR/Long/StrategyTester 9.htm new file mode 100644 index 0000000..eb87f44 --- /dev/null +++ b/Docs/Reports/XR/Long/StrategyTester 9.htm @@ -0,0 +1,123 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.04 23:45 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=false; +xRShortR2R=1.5; xRShortLotsPerTradePercent=0.0001; xRShortMaxDrawdownPerTradePercent=0.15; xRLongR2R=2; xRLongLotsPerTradePercent=0.0001; xRLongMaxDrawdownPerTradePercent=0.1; xRMaximumCandlesPerTrade=252; xRSwingLength=48; xRSharpDetectionFactor=1350; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63629Ticks modelled72967510Modelling qualityn/a
Mismatched charts errors826
Initial deposit1000.00SpreadCurrent (60)
Total net profit868.35Gross profit2155.53Gross loss-1287.18
Profit factor1.67Expected payoff36.18
Absolute drawdown96.42Maximal drawdown851.58 (44.06%)Relative drawdown44.06% (851.58)
Total trades24Short positions (won %)0 (0.00%)Long positions (won %)24 (37.50%)
Profit trades (% of total)9 (37.50%)Loss trades (% of total)15 (62.50%)
Largestprofit trade539.19loss trade-117.69
Averageprofit trade239.50loss trade-85.81
Maximumconsecutive wins (profit in money)3 (842.39)consecutive losses (loss in money)5 (-489.58)
Maximalconsecutive profit (count of wins)842.39 (3)consecutive loss (count of losses)-489.58 (5)
Averageconsecutive wins2consecutive losses4
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.01 19:30buy10.101812.670.001867.81
22020.12.02 10:36buy20.101821.850.001841.33
32020.12.03 09:52t/p20.101841.330.001841.33181.531181.53
42020.12.07 18:09t/p10.101867.810.001867.81524.861706.39
52021.02.08 07:30buy30.101815.770.001829.37
62021.02.08 15:49t/p30.101829.370.001829.37136.001842.39
72021.02.23 04:00buy40.101813.660.001852.52
82021.02.23 08:07buy50.101813.980.001826.90
92021.02.23 11:54close50.101803.980.001826.90-100.001742.39
102021.02.23 12:03close40.101803.660.001852.52-100.001642.39
112021.05.06 18:04buy60.101815.740.001870.68
122021.05.12 23:21close60.101815.730.001870.68-17.791624.60
132021.07.13 15:30buy70.101813.610.001828.27
142021.07.13 15:33close70.101803.610.001828.27-100.001524.60
152021.07.14 10:45buy80.101813.970.001831.93
162021.07.14 13:37buy90.101817.470.001838.05
172021.07.15 09:09t/p80.101831.930.001831.93166.331690.93
182021.07.19 07:30close90.101813.820.001838.05-58.621632.32
192021.07.29 04:30buy100.101816.220.001862.70
202021.07.29 09:51buy110.101818.660.001868.32
212021.08.02 04:39close110.101808.660.001868.32-108.851523.47
222021.08.02 15:16close100.101806.220.001862.70-108.851414.62
232021.08.27 19:21buy120.101814.650.001875.05
242021.08.27 22:54buy130.101819.260.001887.44
252021.08.30 18:39close130.101809.260.001887.44-104.421310.20
262021.08.31 16:09close120.101804.650.001875.05-108.851201.36
272021.11.05 18:45buy140.101814.420.001872.32
282021.11.08 07:54buy150.101821.600.001845.16
292021.11.10 15:39t/p150.101845.160.001845.16226.751428.11
302021.11.16 10:54t/p140.101872.320.001872.32539.191967.30
312022.01.11 18:43buy160.101816.350.001843.49
322022.01.14 19:15close160.101816.340.001843.49-22.221945.09
332022.02.04 15:30buy170.101813.380.001827.74
342022.02.04 15:37close170.101803.380.001827.74-100.001845.09
352022.02.07 11:00buy180.101813.460.001826.20
362022.02.07 14:00buy190.101814.020.001823.68
372022.02.07 21:36buy200.101823.260.001848.06
382022.02.08 15:54t/p190.101823.680.001823.6892.181937.26
392022.02.08 17:22t/p180.101826.200.001826.20122.982060.24
402022.02.10 15:31close200.101823.250.001848.06-22.222038.03
412022.12.20 17:22buy210.101818.080.001879.60
422022.12.21 10:00buy220.101816.930.001825.99
432022.12.22 15:53close210.101808.080.001879.60-117.691920.33
442022.12.22 15:58close220.101806.930.001825.99-113.271807.07
452022.12.27 20:15buy230.101815.080.001839.84
462022.12.28 10:15close230.101805.080.001839.84-104.421702.64
472022.12.28 10:15buy240.101805.660.001824.00
482022.12.30 16:07t/p240.101824.000.001824.00165.711868.35
+
diff --git a/Docs/Reports/XR/Short/StrategyTester 1.gif b/Docs/Reports/XR/Short/StrategyTester 1.gif new file mode 100644 index 0000000..848a4a0 Binary files /dev/null and b/Docs/Reports/XR/Short/StrategyTester 1.gif differ diff --git a/Docs/Reports/XR/Short/StrategyTester 1.htm b/Docs/Reports/XR/Short/StrategyTester 1.htm new file mode 100644 index 0000000..e95644f --- /dev/null +++ b/Docs/Reports/XR/Short/StrategyTester 1.htm @@ -0,0 +1,283 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.04 23:45 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=false; +enableXRShort=true; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xRSwingLength=48; xRSharpDetectionFactor=1350; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63629Ticks modelled72967534Modelling qualityn/a
Mismatched charts errors826
Initial deposit1000.00SpreadCurrent (51)
Total net profit138.50Gross profit694.79Gross loss-556.29
Profit factor1.25Expected payoff1.33
Absolute drawdown75.42Maximal drawdown148.46 (13.84%)Relative drawdown13.84% (148.46)
Total trades104Short positions (won %)104 (44.23%)Long positions (won %)0 (0.00%)
Profit trades (% of total)46 (44.23%)Loss trades (% of total)58 (55.77%)
Largestprofit trade50.75loss trade-11.05
Averageprofit trade15.10loss trade-9.59
Maximumconsecutive wins (profit in money)10 (194.09)consecutive losses (loss in money)11 (-108.64)
Maximalconsecutive profit (count of wins)194.09 (10)consecutive loss (count of losses)-108.64 (11)
Averageconsecutive wins4consecutive losses5
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 06:45sell10.011807.850.001793.49
22020.11.27 12:30sell20.011808.700.001798.70
32020.11.27 15:07t/p20.011798.700.001798.7010.001010.00
42020.11.27 15:09t/p10.011793.490.001793.4914.361024.36
52020.12.01 17:30sell30.011806.320.001788.90
62020.12.01 20:15close30.011816.330.001788.90-10.011014.35
72020.12.02 05:15sell40.011809.570.001794.49
82020.12.02 10:34close40.011819.570.001794.49-10.001004.35
92021.02.04 16:00sell50.011808.190.001770.49
102021.02.05 21:00sell60.011810.160.001800.30
112021.02.05 23:00sell70.011810.890.001802.49
122021.02.08 01:09close50.011818.190.001770.49-9.59994.76
132021.02.08 04:45sell80.011810.250.001793.39
142021.02.08 11:00sell90.011809.020.001789.70
152021.02.08 13:31close90.011819.020.001789.70-10.00984.76
162021.02.08 13:34close60.011820.170.001800.30-9.80974.96
172021.02.08 13:34close80.011820.250.001793.39-10.00964.96
182021.02.08 13:36close70.011820.890.001802.49-9.79955.16
192021.02.16 15:15sell100.011811.040.001780.54
202021.02.16 18:30sell110.011803.470.001759.29
212021.02.17 15:24t/p100.011780.540.001780.5430.71985.87
222021.02.22 16:37close110.011803.480.001759.291.23987.10
232021.02.22 19:30sell120.011809.990.001805.03
242021.02.23 09:45sell130.011809.820.001797.80
252021.02.23 11:54t/p120.011805.030.001805.035.17992.26
262021.02.23 14:45sell140.011810.320.001799.30
272021.02.23 16:37t/p140.011799.300.001799.3011.021003.28
282021.02.23 16:45t/p130.011797.800.001797.8012.021015.30
292021.02.24 05:00sell150.011810.060.001802.60
302021.02.24 15:21t/p150.011802.600.001802.607.461022.76
312021.05.13 13:15sell160.011810.390.001785.51
322021.05.13 15:39close160.011820.390.001785.51-10.001012.76
332021.06.17 10:30sell170.011809.210.001747.49
342021.07.06 10:54close170.011809.220.001747.493.491016.26
352021.07.06 16:15sell180.011806.750.001790.71
362021.07.06 19:24t/p180.011790.710.001790.7116.041032.30
372021.07.08 17:00sell190.011808.270.001788.55
382021.07.09 21:45sell200.011811.020.001808.80
392021.07.09 22:54t/p200.011808.800.001808.802.221034.52
402021.07.13 06:15sell210.011811.020.001808.06
412021.07.13 08:37t/p210.011808.060.001808.062.961037.48
422021.07.13 10:15sell220.011811.280.001808.84
432021.07.13 11:00close190.011810.250.001788.55-1.361036.12
442021.07.13 11:06t/p220.011808.840.001808.842.441038.56
452021.07.13 16:15sell230.011809.710.001795.17
462021.07.13 20:15sell240.011808.830.001792.53
472021.07.14 15:04close240.011818.830.001792.53-9.791028.76
482021.07.14 15:04close230.011819.710.001795.17-9.791018.97
492021.07.16 22:30sell250.011810.350.001778.15
502021.07.19 09:15sell260.011806.190.001784.27
512021.07.19 18:15sell270.011807.210.001790.91
522021.07.19 23:30sell280.011811.470.001803.69
532021.07.20 04:09close260.011816.190.001784.27-9.791009.17
542021.07.20 04:31close270.011817.210.001790.91-9.79999.38
552021.07.20 15:36close250.011820.350.001778.15-9.59989.79
562021.07.20 15:37close280.011821.470.001803.69-9.79980.00
572021.07.20 18:15sell290.011810.140.001780.96
582021.07.20 20:30sell300.011810.840.001783.06
592021.07.21 10:30sell310.011808.770.001799.15
602021.07.21 15:09t/p310.011799.150.001799.159.62989.62
612021.07.26 10:22close290.011810.150.001780.961.23990.84
622021.07.26 10:24close300.011810.850.001783.061.23992.07
632021.07.30 21:45sell320.011810.450.001768.95
642021.08.02 04:45sell330.011809.440.001774.22
652021.08.02 06:30sell340.011811.380.001786.42
662021.08.02 09:15sell350.011810.310.001797.51
672021.08.02 20:09close330.011819.440.001774.22-10.00982.07
682021.08.03 04:30sell360.011809.740.001790.54
692021.08.04 15:06close360.011819.740.001790.54-9.79972.28
702021.08.04 15:07close350.011820.310.001797.51-9.59962.69
712021.08.04 15:07close320.011820.450.001768.95-9.38953.31
722021.08.04 15:09close340.011821.380.001786.42-9.59943.72
732021.08.04 18:30sell370.011806.630.001756.91
742021.08.04 21:45sell380.011810.860.001769.60
752021.08.05 01:00sell390.011811.890.001772.69
762021.08.05 03:15sell400.011810.920.001769.78
772021.08.06 16:07t/p390.011772.690.001772.6939.41983.13
782021.08.06 16:39t/p400.011769.780.001769.7841.351024.47
792021.08.06 16:39t/p380.011769.600.001769.6042.081066.56
802021.08.09 01:22t/p370.011756.910.001756.9150.751117.31
812021.08.30 18:30sell410.011811.210.001797.55
822021.08.31 16:15sell420.011803.320.001771.96
832021.08.31 16:37close420.011813.320.001771.96-10.001107.31
842021.08.31 18:15sell430.011805.950.001779.85
852021.08.31 20:09close430.011815.950.001779.85-10.001097.31
862021.09.01 11:15sell440.011809.570.001794.93
872021.09.01 15:52close440.011819.570.001794.93-10.001087.31
882021.09.01 18:15sell450.011810.930.001793.05
892021.09.02 07:30sell460.011811.430.001801.71
902021.09.02 12:30close410.011815.680.001797.55-3.441083.87
912021.09.02 17:30sell470.011807.760.001789.30
922021.09.03 04:45sell480.011811.190.001806.13
932021.09.03 15:18close470.011817.760.001789.30-9.791074.07
942021.09.03 15:34close450.011820.930.001793.05-9.181064.90
952021.09.03 15:34close480.011821.190.001806.13-10.001054.90
962021.09.03 15:34close460.011821.430.001801.71-9.791045.10
972021.09.07 13:15sell490.011810.900.001778.58
982021.09.07 16:15sell500.011810.490.001777.53
992021.09.16 12:54t/p490.011778.580.001778.5834.591079.69
1002021.09.16 13:00t/p500.011777.530.001777.5335.231114.92
1012021.10.22 18:30sell510.011800.480.001774.18
1022021.10.28 05:24close510.011800.490.001774.181.231116.14
1032021.11.22 19:45sell520.011810.200.001736.88
1042021.11.23 04:15sell530.011807.780.001740.54
1052021.11.26 09:54close530.011807.790.001740.541.021117.17
1062021.11.26 12:03close520.011810.210.001736.881.231118.39
1072021.11.26 14:30sell540.011809.150.001796.79
1082021.11.26 16:54t/p540.011796.790.001796.7912.361130.75
1092021.12.17 16:00sell550.011806.620.001791.74
1102021.12.20 21:49t/p550.011791.740.001791.7415.091145.84
1112021.12.27 19:15sell560.011809.010.001800.49
1122021.12.27 23:30sell570.011811.240.001807.18
1132021.12.28 02:30sell580.011811.150.001806.91
1142021.12.28 15:24close560.011819.010.001800.49-9.791136.04
1152021.12.28 18:15sell590.011809.840.001789.48
1162021.12.28 20:00sell600.011810.260.001790.74
1172021.12.28 20:51t/p570.011807.180.001807.184.271140.31
1182021.12.28 20:51t/p580.011806.910.001806.914.241144.55
1192021.12.29 15:09t/p600.011790.740.001790.7419.731164.28
1202021.12.31 09:07close590.011819.840.001789.48-8.971155.31
1212022.01.03 16:00sell610.011806.970.001765.87
1222022.01.04 17:39close610.011816.970.001765.87-9.791145.51
1232022.01.05 22:30sell620.011810.000.001771.12
1242022.01.11 08:16close620.011810.010.001771.121.231146.74
1252022.01.18 12:00sell630.011810.270.001785.65
1262022.01.18 15:30sell640.011806.890.001775.51
1272022.01.18 15:37close640.011816.890.001775.51-10.001136.74
1282022.01.18 16:04close630.011820.270.001785.65-10.001126.74
1292022.01.19 05:15sell650.011810.740.001792.48
1302022.01.19 07:00sell660.011811.540.001803.30
1312022.01.19 15:19close650.011820.740.001792.48-10.001116.74
1322022.01.19 15:19close660.011821.540.001803.30-10.001106.74
1332022.01.27 09:00sell670.011810.600.001765.34
1342022.01.27 13:15sell680.011810.700.001788.24
1352022.01.28 12:52t/p680.011788.240.001788.2422.671129.41
1362022.02.02 17:24close670.011810.610.001765.340.811130.22
1372022.02.04 13:45sell690.011810.330.001802.37
1382022.02.04 15:39t/p690.011802.370.001802.377.961138.18
1392022.02.04 16:00sell700.011795.320.001756.60
1402022.02.04 16:39close700.011805.320.001756.60-10.001128.18
1412022.02.07 03:45sell710.011809.750.001799.03
1422022.02.07 10:30sell720.011811.100.001803.08
1432022.02.07 12:30sell730.011811.530.001804.37
1442022.02.07 19:37close710.011819.750.001799.03-10.001118.18
1452022.02.07 20:22close720.011821.100.001803.08-10.001108.18
1462022.02.07 20:24close730.011821.530.001804.37-10.001098.18
1472022.05.13 16:15sell740.011802.800.001751.28
1482022.05.13 17:02close740.011812.800.001751.28-10.001088.18
1492022.05.13 19:00sell750.011808.990.001769.85
1502022.05.16 02:00sell760.011810.840.001791.70
1512022.05.16 06:45sell770.011809.830.001794.67
1522022.05.16 10:43t/p770.011794.670.001794.6715.161103.34
1532022.05.16 10:51t/p760.011791.700.001791.7019.141122.48
1542022.05.16 21:55close750.011819.020.001769.85-9.821112.66
1552022.05.18 06:30sell780.011808.180.001778.32
1562022.05.18 10:00sell790.011809.610.001789.63
1572022.05.18 12:33close780.011818.190.001778.32-10.011102.65
1582022.05.18 12:37close790.011819.610.001789.63-10.001092.65
1592022.05.18 15:15sell800.011808.580.001785.34
1602022.05.18 18:32close800.011818.580.001785.34-10.001082.65
1612022.06.14 19:00sell810.011810.290.001768.19
1622022.06.14 21:30sell820.011810.070.001767.53
1632022.06.15 09:22close820.011820.070.001767.53-9.791072.85
1642022.06.15 09:28close810.011820.290.001768.19-9.791063.06
1652022.06.30 13:45sell830.011810.240.001787.18
1662022.06.30 15:39close830.011820.240.001787.18-10.001053.06
1672022.06.30 18:00sell840.011808.930.001776.99
1682022.06.30 20:00sell850.011809.760.001779.48
1692022.07.04 05:45sell860.011809.120.001799.24
1702022.07.04 07:45sell870.011811.720.001807.04
1712022.07.04 11:39t/p870.011807.040.001807.044.681057.74
1722022.07.05 05:30sell880.011810.210.001806.77
1732022.07.05 10:24t/p880.011806.770.001806.773.441061.18
1742022.07.05 14:18t/p860.011799.240.001799.2410.091071.26
1752022.07.05 17:03t/p850.011779.480.001779.4830.901102.16
1762022.07.05 17:05t/p840.011776.990.001776.9932.561134.72
1772022.12.13 19:45sell890.011809.040.001778.50
1782022.12.13 21:30sell900.011809.730.001780.57
1792022.12.14 04:00sell910.011810.570.001783.09
1802022.12.14 06:15sell920.011809.880.001798.28
1812022.12.14 21:02t/p920.011798.280.001798.2811.601146.32
1822022.12.14 22:45sell930.011808.630.001797.87
1832022.12.15 03:53t/p930.011797.870.001797.8711.381157.70
1842022.12.15 10:12t/p910.011783.090.001783.0928.101185.80
1852022.12.15 10:20t/p900.011780.570.001780.5729.981215.78
1862022.12.15 10:31t/p890.011778.500.001778.5031.361247.15
1872022.12.22 16:15sell940.011807.890.001783.23
1882022.12.27 17:20close940.011817.890.001783.23-9.381237.76
1892022.12.28 02:30sell950.011810.310.001764.09
1902022.12.28 04:30sell960.011810.330.001764.15
1912022.12.28 08:00sell970.011810.300.001787.62
1922022.12.29 20:25close970.011820.300.001787.62-9.381228.38
1932022.12.29 20:25close950.011820.310.001764.09-9.381219.00
1942022.12.29 20:25close960.011820.330.001764.15-9.381209.62
1952023.02.24 18:15sell980.011809.460.001776.14
1962023.02.24 20:00sell990.011809.720.001776.92
1972023.02.24 23:15sell1000.011811.200.001785.56
1982023.02.27 05:30sell1010.011810.190.001799.31
1992023.02.27 17:03close980.011819.460.001776.14-9.791199.83
2002023.02.27 17:03close990.011819.720.001776.92-9.791190.03
2012023.02.27 17:18close1010.011820.190.001799.31-10.001180.03
2022023.02.28 10:00sell1020.011810.360.001792.60
2032023.02.28 12:00sell1030.011810.170.001792.03
2042023.02.28 17:00close1030.011821.220.001792.03-11.051168.98
2052023.02.28 17:00close1020.011821.220.001792.60-10.861158.12
2062023.02.28 17:00close1000.011821.220.001785.56-9.611148.51
2072023.03.08 05:15sell1040.011809.930.001763.01
2082023.03.08 16:48close1040.011819.940.001763.01-10.011138.50
+
diff --git a/Docs/Reports/XR/Short/StrategyTester 2.gif b/Docs/Reports/XR/Short/StrategyTester 2.gif new file mode 100644 index 0000000..fa9c0ff Binary files /dev/null and b/Docs/Reports/XR/Short/StrategyTester 2.gif differ diff --git a/Docs/Reports/XR/Short/StrategyTester 2.htm b/Docs/Reports/XR/Short/StrategyTester 2.htm new file mode 100644 index 0000000..4268d4a --- /dev/null +++ b/Docs/Reports/XR/Short/StrategyTester 2.htm @@ -0,0 +1,97 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.07 01:15 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=false; +enableXRShort=true; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xRSwingLength=48; xRSharpDetectionFactor=1350; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63631Ticks modelled72968765Modelling qualityn/a
Mismatched charts errors826
Initial deposit1000.00SpreadCurrent (60)
Total net profit43.39Gross profit91.75Gross loss-48.35
Profit factor1.90Expected payoff3.94
Absolute drawdown1.08Maximal drawdown32.09 (3.09%)Relative drawdown3.09% (32.09)
Total trades11Short positions (won %)11 (54.55%)Long positions (won %)0 (0.00%)
Profit trades (% of total)6 (54.55%)Loss trades (% of total)5 (45.45%)
Largestprofit trade40.11loss trade-10.00
Averageprofit trade15.29loss trade-9.67
Maximumconsecutive wins (profit in money)3 (33.04)consecutive losses (loss in money)2 (-19.59)
Maximalconsecutive profit (count of wins)49.09 (2)consecutive loss (count of losses)-19.59 (2)
Averageconsecutive wins2consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 12:34sell10.011808.470.001798.47
22020.11.27 15:09t/p10.011798.470.001798.4710.001010.00
32021.02.23 09:54sell20.011808.360.001796.34
42021.02.23 14:54sell30.011809.080.001798.06
52021.02.23 16:45t/p30.011798.060.001798.0611.021021.02
62021.02.23 16:48t/p20.011796.340.001796.3412.021033.04
72021.07.13 16:15sell40.011808.460.001793.92
82021.07.13 20:16sell50.011808.250.001791.95
92021.07.14 15:01close50.011818.250.001791.95-9.791023.25
102021.07.14 15:02close40.011818.460.001793.92-9.791013.45
112021.07.21 10:34sell60.011808.650.001799.03
122021.07.21 15:09t/p60.011799.030.001799.039.621023.07
132021.08.03 04:39sell70.011811.070.001794.53
142021.08.04 15:09close70.011821.070.001794.53-9.791013.28
152021.08.05 01:39sell80.011811.540.001771.64
162021.08.05 15:30sell90.011809.510.001800.53
172021.08.05 16:45t/p90.011800.530.001800.538.981022.26
182021.08.06 16:08t/p80.011771.640.001771.6440.111062.36
192021.10.22 18:39sell100.011786.660.001760.36
202021.10.22 19:39close100.011796.660.001760.36-10.001052.36
212021.12.28 18:19sell110.011809.950.001789.81
222021.12.31 09:09close110.011819.950.001789.81-8.971043.39
+
diff --git a/Docs/Reports/XR/Short/StrategyTester 3.gif b/Docs/Reports/XR/Short/StrategyTester 3.gif new file mode 100644 index 0000000..32e8d5e Binary files /dev/null and b/Docs/Reports/XR/Short/StrategyTester 3.gif differ diff --git a/Docs/Reports/XR/Short/StrategyTester 3.htm b/Docs/Reports/XR/Short/StrategyTester 3.htm new file mode 100644 index 0000000..6203c5b --- /dev/null +++ b/Docs/Reports/XR/Short/StrategyTester 3.htm @@ -0,0 +1,95 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.07 01:45 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=false; +enableXRShort=true; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xRSwingLength=48; xRSharpDetectionFactor=1350; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63633Ticks modelled72969323Modelling qualityn/a
Mismatched charts errors826
Initial deposit1000.00SpreadCurrent (60)
Total net profit44.66Gross profit83.01Gross loss-38.35
Profit factor2.16Expected payoff4.47
Absolute drawdown12.08Maximal drawdown40.24 (3.91%)Relative drawdown3.91% (40.24)
Total trades10Short positions (won %)10 (60.00%)Long positions (won %)0 (0.00%)
Profit trades (% of total)6 (60.00%)Loss trades (% of total)4 (40.00%)
Largestprofit trade40.11loss trade-9.79
Averageprofit trade13.84loss trade-9.59
Maximumconsecutive wins (profit in money)3 (21.88)consecutive losses (loss in money)3 (-29.38)
Maximalconsecutive profit (count of wins)40.11 (1)consecutive loss (count of losses)-29.38 (3)
Averageconsecutive wins2consecutive losses2
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 12:34sell10.011808.470.001798.47
22020.11.27 15:09t/p10.011798.470.001798.4710.001010.00
32021.02.23 14:54sell20.011809.080.001798.06
42021.02.23 16:45t/p20.011798.060.001798.0611.021021.02
52021.07.13 16:15sell30.011808.460.001793.92
62021.07.13 20:16sell40.011808.250.001791.95
72021.07.14 15:01close40.011818.250.001791.95-9.791011.23
82021.07.14 15:02close30.011818.460.001793.92-9.791001.43
92021.08.03 04:39sell50.011811.070.001794.53
102021.08.04 15:09close50.011821.070.001794.53-9.79991.64
112021.08.05 01:39sell60.011811.540.001771.64
122021.08.06 16:08t/p60.011771.640.001771.6440.111031.74
132021.12.28 18:19sell70.011809.950.001789.81
142021.12.31 09:09close70.011819.950.001789.81-8.971022.77
152022.12.14 19:11sell80.011808.980.001804.16
162022.12.14 21:01t/p80.011804.160.001804.164.821027.59
172022.12.14 22:47sell90.011808.170.001797.41
182022.12.15 04:13t/p90.011797.410.001797.4111.381038.97
192023.02.27 14:00sell100.011811.310.001805.83
202023.02.28 10:18t/p100.011805.830.001805.835.691044.66
+
diff --git a/Docs/Reports/XR/Short/StrategyTester 4.gif b/Docs/Reports/XR/Short/StrategyTester 4.gif new file mode 100644 index 0000000..e109724 Binary files /dev/null and b/Docs/Reports/XR/Short/StrategyTester 4.gif differ diff --git a/Docs/Reports/XR/Short/StrategyTester 4.htm b/Docs/Reports/XR/Short/StrategyTester 4.htm new file mode 100644 index 0000000..2382333 --- /dev/null +++ b/Docs/Reports/XR/Short/StrategyTester 4.htm @@ -0,0 +1,174 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.07 17:45 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
Bars in test63697Ticks modelled73031931Modelling qualityn/a
Mismatched charts errors826
Initial deposit1000.00SpreadCurrent (51)
Total net profit64.59Gross profit429.97Gross loss-365.38
Profit factor1.18Expected payoff1.09
Absolute drawdown64.19Maximal drawdown151.17 (13.91%)Relative drawdown13.91% (151.17)
Total trades59Short positions (won %)59 (37.29%)Long positions (won %)0 (0.00%)
Profit trades (% of total)22 (37.29%)Loss trades (% of total)37 (62.71%)
Largestprofit trade50.75loss trade-11.05
Averageprofit trade19.54loss trade-9.88
Maximumconsecutive wins (profit in money)4 (173.59)consecutive losses (loss in money)8 (-80.50)
Maximalconsecutive profit (count of wins)173.59 (4)consecutive loss (count of losses)-80.50 (8)
Averageconsecutive wins2consecutive losses4
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 06:45sell10.011807.850.001793.49
22020.11.27 15:09t/p10.011793.490.001793.4914.361014.36
32021.02.04 16:00sell20.011808.190.001770.49
42021.02.08 01:09close20.011818.190.001770.49-9.591004.77
52021.02.16 15:15sell30.011811.040.001780.54
62021.02.16 18:30sell40.011803.470.001759.29
72021.02.17 15:24t/p30.011780.540.001780.5430.711035.48
82021.02.22 16:37close40.011803.480.001759.291.231036.70
92021.05.13 13:15sell50.011810.390.001785.51
102021.05.13 15:39close50.011820.390.001785.51-10.001026.70
112021.06.17 10:30sell60.011809.210.001747.49
122021.07.06 10:54close60.011809.220.001747.493.491030.20
132021.07.16 22:30sell70.011810.350.001778.15
142021.07.19 09:15sell80.011806.190.001784.27
152021.07.19 18:15sell90.011807.210.001790.91
162021.07.19 23:30sell100.011811.470.001803.69
172021.07.20 04:09close80.011816.190.001784.27-9.791020.40
182021.07.20 04:31close90.011817.210.001790.91-9.791010.61
192021.07.20 15:36close70.011820.350.001778.15-9.591001.02
202021.07.20 15:37close100.011821.470.001803.69-9.79991.23
212021.07.20 18:15sell110.011810.140.001780.96
222021.07.20 20:30sell120.011810.840.001783.06
232021.07.21 10:30sell130.011808.770.001799.15
242021.07.21 15:09t/p130.011799.150.001799.159.621000.85
252021.07.26 10:22close110.011810.150.001780.961.231002.08
262021.07.26 10:24close120.011810.850.001783.061.231003.30
272021.07.30 21:45sell140.011810.450.001768.95
282021.08.02 04:45sell150.011809.440.001774.22
292021.08.02 06:30sell160.011811.380.001786.42
302021.08.02 09:15sell170.011810.310.001797.51
312021.08.02 20:09close150.011819.440.001774.22-10.00993.30
322021.08.03 04:30sell180.011809.740.001790.54
332021.08.04 15:06close180.011819.740.001790.54-9.79983.51
342021.08.04 15:07close170.011820.310.001797.51-9.59973.92
352021.08.04 15:07close140.011820.450.001768.95-9.38964.54
362021.08.04 15:09close160.011821.380.001786.42-9.59954.95
372021.08.04 18:30sell190.011806.630.001756.91
382021.08.04 21:45sell200.011810.860.001769.60
392021.08.05 01:00sell210.011811.890.001772.69
402021.08.05 03:15sell220.011810.920.001769.78
412021.08.06 16:07t/p210.011772.690.001772.6939.41994.36
422021.08.06 16:39t/p220.011769.780.001769.7841.351035.70
432021.08.06 16:39t/p200.011769.600.001769.6042.081077.79
442021.08.09 01:22t/p190.011756.910.001756.9150.751128.54
452021.09.01 11:15sell230.011809.570.001794.93
462021.09.01 15:52close230.011819.570.001794.93-10.001118.54
472021.09.01 18:15sell240.011810.930.001793.05
482021.09.02 07:30sell250.011811.430.001801.71
492021.09.02 17:30sell260.011807.760.001789.30
502021.09.03 04:45sell270.011811.190.001806.13
512021.09.03 15:18close260.011817.760.001789.30-9.791108.74
522021.09.03 15:34close240.011820.930.001793.05-9.181099.57
532021.09.03 15:34close270.011821.190.001806.13-10.001089.57
542021.09.03 15:34close250.011821.430.001801.71-9.791079.77
552021.09.07 13:15sell280.011810.900.001778.58
562021.09.07 16:15sell290.011810.490.001777.53
572021.09.16 12:54t/p280.011778.580.001778.5834.591114.36
582021.09.16 13:00t/p290.011777.530.001777.5335.231149.59
592021.11.22 19:45sell300.011810.200.001736.88
602021.11.23 04:15sell310.011807.780.001740.54
612021.11.26 09:54close310.011807.790.001740.541.021150.61
622021.11.26 12:03close300.011810.210.001736.881.231151.84
632022.01.03 16:00sell320.011806.970.001765.87
642022.01.04 17:39close320.011816.970.001765.87-9.791142.04
652022.01.05 22:30sell330.011810.000.001771.12
662022.01.11 08:16close330.011810.010.001771.121.231143.27
672022.01.18 12:00sell340.011810.270.001785.65
682022.01.18 15:30sell350.011806.890.001775.51
692022.01.18 15:37close350.011816.890.001775.51-10.001133.27
702022.01.18 16:04close340.011820.270.001785.65-10.001123.27
712022.01.19 05:15sell360.011810.740.001792.48
722022.01.19 07:00sell370.011811.540.001803.30
732022.01.19 15:19close360.011820.740.001792.48-10.001113.27
742022.01.19 15:19close370.011821.540.001803.30-10.001103.27
752022.01.27 09:00sell380.011810.600.001765.34
762022.01.27 13:15sell390.011810.700.001788.24
772022.01.28 12:52t/p390.011788.240.001788.2422.671125.93
782022.02.02 17:24close380.011810.610.001765.340.811126.75
792022.05.13 16:15sell400.011802.800.001751.28
802022.05.13 17:02close400.011812.800.001751.28-10.001116.75
812022.05.13 19:00sell410.011808.990.001769.85
822022.05.16 02:00sell420.011810.840.001791.70
832022.05.16 06:45sell430.011809.830.001794.67
842022.05.16 10:43t/p430.011794.670.001794.6715.161131.91
852022.05.16 10:51t/p420.011791.700.001791.7019.141151.05
862022.05.16 21:55close410.011819.020.001769.85-9.821141.23
872022.05.18 06:30sell440.011808.180.001778.32
882022.05.18 10:00sell450.011809.610.001789.63
892022.05.18 12:33close440.011818.190.001778.32-10.011131.22
902022.05.18 12:37close450.011819.610.001789.63-10.001121.22
912022.05.18 15:15sell460.011808.580.001785.34
922022.05.18 18:32close460.011818.580.001785.34-10.001111.22
932022.06.14 19:00sell470.011810.290.001768.19
942022.06.14 21:30sell480.011810.070.001767.53
952022.06.15 09:22close480.011820.070.001767.53-9.791101.42
962022.06.15 09:28close470.011820.290.001768.19-9.791091.63
972022.06.30 13:45sell490.011810.240.001787.18
982022.06.30 15:39close490.011820.240.001787.18-10.001081.63
992022.06.30 18:00sell500.011808.930.001776.99
1002022.06.30 20:00sell510.011809.760.001779.48
1012022.07.05 17:03t/p510.011779.480.001779.4830.901112.53
1022022.07.05 17:05t/p500.011776.990.001776.9932.561145.08
1032022.12.22 16:15sell520.011807.890.001783.23
1042022.12.27 17:20close520.011817.890.001783.23-9.381135.70
1052023.02.24 18:15sell530.011809.460.001776.14
1062023.02.24 20:00sell540.011809.720.001776.92
1072023.02.24 23:15sell550.011811.200.001785.56
1082023.02.27 05:30sell560.011810.190.001799.31
1092023.02.27 17:03close530.011819.460.001776.14-9.791125.91
1102023.02.27 17:03close540.011819.720.001776.92-9.791116.11
1112023.02.27 17:18close560.011820.190.001799.31-10.001106.11
1122023.02.28 10:00sell570.011810.360.001792.60
1132023.02.28 12:00sell580.011810.170.001792.03
1142023.02.28 17:00close580.011821.220.001792.03-11.051095.06
1152023.02.28 17:00close570.011821.220.001792.60-10.861084.20
1162023.02.28 17:00close550.011821.220.001785.56-9.611074.60
1172023.03.08 05:15sell590.011809.930.001763.01
1182023.03.08 16:48close590.011819.940.001763.01-10.011064.59
+
diff --git a/Docs/Reports/XR/StrategyTester 1 - Full.gif b/Docs/Reports/XR/StrategyTester 1 - Full.gif new file mode 100644 index 0000000..b08e5bc Binary files /dev/null and b/Docs/Reports/XR/StrategyTester 1 - Full.gif differ diff --git a/Docs/Reports/XR/StrategyTester 1 - Full.htm b/Docs/Reports/XR/StrategyTester 1 - Full.htm new file mode 100644 index 0000000..67b4780 --- /dev/null +++ b/Docs/Reports/XR/StrategyTester 1 - Full.htm @@ -0,0 +1,297 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.08 10:00 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=true; +xRShortR2R=1.5; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.008; xRLongR2R=1.5; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.008; xRMaximumCandlesPerTrade=96; xRSwingLength=48; xRSharpDetectionFactor=1350; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63758Ticks modelled73078285Modelling qualityn/a
Mismatched charts errors901
Initial deposit1000.00SpreadCurrent (57)
Total net profit210.35Gross profit662.75Gross loss-452.40
Profit factor1.46Expected payoff1.90
Absolute drawdown4.01Maximal drawdown124.53 (9.39%)Relative drawdown9.39% (124.53)
Total trades111Short positions (won %)65 (38.46%)Long positions (won %)46 (34.78%)
Profit trades (% of total)41 (36.94%)Loss trades (% of total)70 (63.06%)
Largestprofit trade46.50loss trade-8.45
Averageprofit trade16.16loss trade-6.46
Maximumconsecutive wins (profit in money)5 (72.43)consecutive losses (loss in money)10 (-52.73)
Maximalconsecutive profit (count of wins)99.30 (4)consecutive loss (count of losses)-55.38 (7)
Averageconsecutive wins3consecutive losses5
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 06:45sell10.011807.850.001797.08
22020.11.27 15:09t/p10.011797.080.001797.0810.771010.77
32020.12.01 19:30buy20.011812.640.001854.00
42020.12.02 02:30buy30.011813.270.001827.96
52020.12.02 08:45buy40.011813.190.001821.26
62020.12.02 10:36t/p40.011821.260.001821.268.071018.84
72020.12.02 12:22t/p30.011827.960.001827.9614.691033.53
82020.12.07 16:52t/p20.011854.000.001854.0038.711072.24
92021.02.04 16:00sell50.011808.190.001779.92
102021.02.05 17:24close50.011808.200.001779.920.201072.43
112021.02.05 19:15buy60.011814.840.001846.28
122021.02.08 01:15buy70.011817.890.001853.91
132021.02.08 04:24close70.011809.890.001853.91-8.001064.43
142021.02.08 07:30buy80.011815.740.001825.94
152021.02.08 10:54close80.011807.740.001825.94-8.001056.43
162021.02.08 11:45buy90.011813.160.001820.63
172021.02.08 13:36t/p90.011820.630.001820.637.471063.90
182021.02.09 11:24t/p60.011846.280.001846.2830.561094.46
192021.02.16 15:15sell100.011811.040.001788.17
202021.02.16 18:30sell110.011803.470.001770.34
212021.02.17 01:09t/p100.011788.170.001788.1723.081117.53
222021.02.17 18:09t/p110.011770.340.001770.3433.341150.87
232021.02.23 04:00buy120.011813.630.001842.78
242021.02.23 05:45buy130.011813.320.001827.80
252021.02.23 11:24close120.011805.630.001842.78-8.001142.87
262021.02.23 11:24close130.011805.320.001827.80-8.001134.87
272021.05.06 18:00buy140.011815.930.001857.47
282021.05.12 23:21close140.011815.910.001857.47-1.791133.08
292021.05.13 13:15sell150.011810.390.001791.73
302021.05.13 15:36close150.011818.390.001791.73-8.001125.08
312021.06.17 10:30sell160.011809.210.001762.92
322021.06.18 22:54t/p160.011762.920.001762.9246.501171.58
332021.07.08 14:00buy170.011817.770.001849.41
342021.07.08 16:39close170.011809.770.001849.41-8.001163.58
352021.07.13 15:30buy180.011813.580.001824.58
362021.07.13 15:31close180.011805.570.001824.58-8.011155.57
372021.07.13 18:15buy190.011812.850.001833.61
382021.07.14 03:09close190.011804.840.001833.61-8.451147.11
392021.07.14 06:30buy200.011813.440.001826.16
402021.07.14 08:30buy210.011813.820.001827.11
412021.07.14 10:45buy220.011813.940.001827.41
422021.07.14 15:09t/p200.011826.160.001826.1612.721159.83
432021.07.14 15:37t/p210.011827.110.001827.1113.291173.12
442021.07.14 15:37t/p220.011827.410.001827.4113.471186.59
452021.07.16 22:30sell230.011810.350.001786.20
462021.07.19 09:15sell240.011806.190.001789.75
472021.07.19 16:18close240.011814.190.001789.75-8.001178.59
482021.07.19 18:15sell250.011807.210.001794.99
492021.07.19 23:30sell260.011811.470.001805.64
502021.07.19 23:30close230.011812.040.001786.20-1.481177.11
512021.07.20 03:00sell270.011811.350.001805.34
522021.07.20 04:06close250.011815.210.001794.99-7.791169.32
532021.07.20 05:08close270.011819.350.001805.34-8.001161.32
542021.07.20 05:18close260.011819.470.001805.64-7.791153.52
552021.07.20 18:15sell280.011810.140.001788.26
562021.07.20 20:30sell290.011810.840.001790.01
572021.07.21 10:30sell300.011808.770.001801.56
582021.07.21 14:03t/p300.011801.560.001801.567.211160.73
592021.07.23 10:54close280.011810.150.001788.261.021161.75
602021.07.23 14:34t/p290.011790.010.001790.0121.861183.61
612021.07.29 04:30buy310.011816.190.001851.05
622021.07.30 19:51close310.011816.180.001851.05-0.451183.16
632021.07.30 21:45sell320.011810.450.001779.33
642021.08.02 04:45sell330.011809.440.001783.03
652021.08.02 06:30sell340.011811.380.001792.66
662021.08.02 09:15sell350.011810.310.001800.71
672021.08.02 19:36close330.011817.440.001783.03-8.001175.16
682021.08.02 19:39close350.011818.310.001800.71-8.001167.16
692021.08.02 19:52close320.011818.450.001779.33-7.791159.37
702021.08.02 20:07close340.011819.380.001792.66-8.001151.37
712021.08.03 04:30sell360.011809.740.001795.34
722021.08.03 06:15sell370.011810.010.001796.02
732021.08.03 08:15sell380.011810.150.001796.37
742021.08.03 12:00sell390.011810.640.001805.50
752021.08.04 05:30close360.011813.440.001795.34-3.491147.87
762021.08.04 07:15close370.011812.810.001796.02-2.591145.28
772021.08.04 09:15close380.011813.010.001796.37-2.651142.63
782021.08.04 13:00close390.011815.210.001805.50-4.361138.26
792021.08.04 18:30sell400.011806.630.001769.34
802021.08.04 21:45sell410.011810.860.001779.92
812021.08.05 01:00sell420.011811.890.001782.49
822021.08.05 03:15sell430.011810.920.001780.07
832021.08.05 10:54close400.011814.630.001769.34-7.381130.88
842021.08.05 11:30sell440.011809.830.001802.96
852021.08.05 16:39t/p440.011802.960.001802.966.871137.75
862021.08.06 15:39t/p420.011782.490.001782.4929.611167.36
872021.08.06 15:39t/p430.011780.070.001780.0731.061198.41
882021.08.06 15:39t/p410.011779.920.001779.9231.761230.18
892021.08.27 19:15buy450.011814.940.001860.72
902021.08.30 20:15close450.011810.010.001860.72-5.371224.80
912021.08.31 04:30buy460.011814.040.001822.85
922021.08.31 14:15buy470.011814.290.001820.49
932021.08.31 16:06close470.011806.290.001820.49-8.001216.80
942021.08.31 16:06close460.011806.040.001822.85-8.001208.80
952021.08.31 20:00buy480.011814.350.001832.70
962021.09.01 04:30buy490.011812.970.001829.25
972021.09.01 11:15sell500.011809.570.001798.59
982021.09.01 15:39close500.011817.570.001798.59-8.001200.80
992021.09.01 18:15sell510.011810.930.001797.52
1002021.09.01 21:00close480.011812.490.001832.70-2.301198.50
1012021.09.02 06:04close490.011812.960.001829.25-1.341197.17
1022021.09.02 07:30sell520.011811.430.001804.14
1032021.09.02 17:30sell530.011807.760.001793.92
1042021.09.02 21:07close510.011810.940.001797.520.611197.77
1052021.09.03 04:45sell540.011811.190.001807.40
1062021.09.03 07:45sell550.011811.510.001806.85
1072021.09.03 08:30close520.011811.860.001804.14-0.221197.55
1082021.09.03 15:06close530.011815.760.001793.92-7.791189.76
1092021.09.03 15:34close540.011819.190.001807.40-8.001181.76
1102021.09.03 15:34close550.011819.510.001806.85-8.001173.76
1112021.09.07 13:15sell560.011810.900.001786.66
1122021.09.07 16:15sell570.011810.490.001785.77
1132021.09.08 16:54t/p560.011786.660.001786.6624.451198.20
1142021.09.08 16:54t/p570.011785.770.001785.7724.931223.13
1152021.11.05 18:45buy580.011814.390.001857.82
1162021.11.10 16:24t/p580.011857.820.001857.8242.101265.23
1172021.11.22 19:45sell590.011810.200.001755.21
1182021.11.23 04:15sell600.011807.780.001757.35
1192021.11.26 09:54close600.011807.790.001757.351.021266.25
1202021.11.26 11:55close590.011810.210.001755.211.231267.48
1212021.12.27 18:00buy610.011813.040.001827.67
1222021.12.28 08:00buy620.011813.260.001822.55
1232021.12.28 17:00buy630.011814.210.001821.41
1242021.12.28 19:00close610.011810.530.001827.67-2.951264.53
1252021.12.28 20:52close630.011806.210.001821.41-8.001256.53
1262021.12.28 20:54close620.011805.250.001822.55-8.011248.52
1272021.12.30 19:00buy640.011813.880.001839.91
1282022.01.03 15:09close640.011813.860.001839.91-0.901247.61
1292022.01.03 16:00sell650.011806.970.001776.15
1302022.01.04 17:00close650.011811.780.001776.15-4.601243.01
1312022.01.04 17:45buy660.011817.070.001844.28
1322022.01.04 19:30buy670.011814.650.001838.23
1332022.01.05 21:09close660.011817.050.001844.28-0.461242.55
1342022.01.05 21:09close670.011814.640.001838.23-0.451242.09
1352022.01.05 22:30sell680.011810.000.001780.84
1362022.01.11 08:09close680.011810.010.001780.841.231243.32
1372022.01.11 18:30buy690.011815.730.001836.09
1382022.01.13 17:51close690.011815.720.001836.09-1.781241.54
1392022.01.18 12:00sell700.011810.270.001791.81
1402022.01.18 15:30sell710.011806.890.001783.36
1412022.01.18 15:34close710.011814.890.001783.36-8.001233.54
1422022.01.18 15:37close700.011818.270.001791.81-8.001225.54
1432022.01.19 05:15sell720.011810.740.001797.05
1442022.01.19 07:00sell730.011811.540.001805.36
1452022.01.19 12:35close720.011818.740.001797.05-8.001217.54
1462022.01.19 12:39close730.011819.540.001805.36-8.001209.54
1472022.01.27 09:00sell740.011810.600.001776.66
1482022.01.27 13:15sell750.011810.700.001793.86
1492022.01.27 18:24t/p750.011793.860.001793.8616.841226.38
1502022.02.02 17:24close740.011810.610.001776.660.811227.19
1512022.02.04 12:30buy760.011814.080.001827.73
1522022.02.04 15:30buy770.011813.350.001824.12
1532022.02.04 15:36close760.011806.080.001827.73-8.001219.19
1542022.02.04 15:36close770.011805.350.001824.12-8.001211.19
1552022.02.07 02:45buy780.011812.860.001843.39
1562022.02.07 11:00buy790.011813.430.001822.99
1572022.02.07 14:00buy800.011813.990.001821.24
1582022.02.07 16:15buy810.011816.160.001826.63
1592022.02.07 21:06t/p800.011821.240.001821.247.251218.44
1602022.02.07 21:39t/p790.011822.990.001822.999.561228.00
1612022.02.08 17:24t/p810.011826.630.001826.6310.031238.03
1622022.02.11 20:34t/p780.011843.390.001843.3927.881265.91
1632022.05.13 16:15sell820.011802.800.001764.16
1642022.05.13 17:01close820.011810.800.001764.16-8.001257.91
1652022.05.13 19:00sell830.011808.990.001779.64
1662022.05.16 02:00sell840.011810.840.001796.49
1672022.05.16 04:08close830.011817.000.001779.64-7.801250.10
1682022.05.16 06:45sell850.011809.830.001798.46
1692022.05.16 10:42t/p850.011798.460.001798.4611.371261.47
1702022.05.16 10:43t/p840.011796.490.001796.4914.351275.82
1712022.05.18 06:30sell860.011808.180.001785.79
1722022.05.18 10:00sell870.011809.610.001794.63
1732022.05.18 10:31close860.011816.190.001785.79-8.011267.81
1742022.05.18 12:32close870.011817.620.001794.63-8.011259.80
1752022.05.18 15:15sell880.011808.580.001791.15
1762022.05.18 18:08close880.011816.580.001791.15-8.001251.80
1772022.06.14 19:00sell890.011810.290.001778.72
1782022.06.14 21:30sell900.011810.070.001778.17
1792022.06.15 05:31close900.011818.070.001778.17-7.791244.01
1802022.06.15 05:31close890.011818.290.001778.72-7.791236.22
1812022.06.30 13:45sell910.011810.240.001792.95
1822022.06.30 15:37close910.011818.240.001792.95-8.001228.22
1832022.06.30 18:00sell920.011808.930.001784.98
1842022.06.30 20:00sell930.011809.760.001787.05
1852022.07.01 14:39t/p930.011787.050.001787.0522.921251.13
1862022.07.01 15:25t/p920.011784.980.001784.9824.161275.29
1872022.12.13 16:30buy940.011818.950.001875.17
1882022.12.13 17:48close940.011810.950.001875.17-8.001267.29
1892022.12.13 18:45buy950.011813.330.001859.10
1902022.12.13 19:25close950.011805.330.001859.10-8.001259.29
1912022.12.20 17:15buy960.011820.900.001871.32
1922022.12.21 07:23close960.011812.900.001871.32-8.441250.85
1932022.12.21 09:30buy970.011815.410.001820.20
1942022.12.21 14:00buy980.011814.120.001816.97
1952022.12.21 15:13t/p980.011816.970.001816.972.851253.70
1962022.12.21 17:07t/p970.011820.200.001820.204.791258.49
1972022.12.22 16:15sell990.011807.890.001789.40
1982022.12.22 20:02t/p990.011789.400.001789.4018.491276.98
1992022.12.27 17:30buy1000.011821.760.001850.40
2002022.12.27 19:56close1000.011813.760.001850.40-8.001268.98
2012022.12.27 20:15buy1010.011815.050.001833.62
2022022.12.28 03:30buy1020.011814.710.001832.77
2032022.12.28 10:08close1010.011807.040.001833.62-8.451260.52
2042022.12.28 10:08close1020.011806.710.001832.77-8.001252.52
2052022.12.29 17:00buy1030.011814.370.001828.82
2062022.12.29 18:45buy1040.011814.740.001829.74
2072022.12.30 18:38close1030.011814.350.001828.82-0.461252.06
2082023.01.03 01:07t/p1040.011829.740.001829.7413.671265.74
2092023.02.24 18:15sell1050.011809.460.001784.47
2102023.02.24 20:00sell1060.011809.720.001785.12
2112023.02.24 23:15sell1070.011811.200.001791.97
2122023.02.27 05:30sell1080.011810.190.001802.03
2132023.02.27 16:23close1050.011817.460.001784.47-7.791257.94
2142023.02.27 16:23close1060.011817.720.001785.12-7.791250.15
2152023.02.27 16:55close1080.011818.190.001802.03-8.001242.15
2162023.02.27 16:57close1070.011819.200.001791.97-7.791234.35
2172023.02.28 10:00sell1090.011810.360.001797.04
2182023.02.28 12:00sell1100.011810.170.001796.57
2192023.02.28 16:47close1100.011818.170.001796.57-8.001226.35
2202023.02.28 16:47close1090.011818.360.001797.04-8.001218.35
2212023.03.08 05:15sell1110.011809.930.001774.74
2222023.03.08 16:32close1110.011817.930.001774.74-8.001210.35
+
diff --git a/Docs/Reports/XR/StrategyTester 2 - 0.2 - Full.gif b/Docs/Reports/XR/StrategyTester 2 - 0.2 - Full.gif new file mode 100644 index 0000000..0ce41b5 Binary files /dev/null and b/Docs/Reports/XR/StrategyTester 2 - 0.2 - Full.gif differ diff --git a/Docs/Reports/XR/StrategyTester 2 - 0.2 - Full.htm b/Docs/Reports/XR/StrategyTester 2 - 0.2 - Full.htm new file mode 100644 index 0000000..73d7435 --- /dev/null +++ b/Docs/Reports/XR/StrategyTester 2 - 0.2 - Full.htm @@ -0,0 +1,301 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.08 11:00 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +enableXLong=true; +enableXShort=true; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=true; +enableXRLong=true; +enableXRShort=true; +xRShortR2R=1.5; xRShortLotsPerTradePercent=0.0002; xRShortMaxDrawdownPerTradePercent=0.15; xRLongR2R=1.5; xRLongLotsPerTradePercent=0.0002; xRLongMaxDrawdownPerTradePercent=0.15; xRMaximumCandlesPerTrade=96; xRSwingLength=48; xRSharpDetectionFactor=1350; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=false; +enableXTPWLong=true; +enableXTPWShort=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63762Ticks modelled73083601Modelling qualityn/a
Mismatched charts errors902
Initial deposit1000.00SpreadCurrent (50)
Total net profit3076.78Gross profit11645.54Gross loss-8568.76
Profit factor1.36Expected payoff27.23
Absolute drawdown78.80Maximal drawdown2946.14 (44.93%)Relative drawdown44.93% (2946.14)
Total trades113Short positions (won %)66 (46.97%)Long positions (won %)47 (25.53%)
Profit trades (% of total)43 (38.05%)Loss trades (% of total)70 (61.95%)
Largestprofit trade929.92loss trade-159.05
Averageprofit trade270.83loss trade-122.41
Maximumconsecutive wins (profit in money)6 (2894.35)consecutive losses (loss in money)9 (-793.75)
Maximalconsecutive profit (count of wins)2894.35 (6)consecutive loss (count of losses)-1042.16 (7)
Averageconsecutive wins2consecutive losses4
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.11.27 06:45sell10.201807.850.001797.08
22020.11.27 15:09t/p10.201797.080.001797.08215.401215.40
32020.11.27 15:09sell20.201796.570.001788.89
42020.11.27 15:36t/p20.201788.890.001788.89153.601369.00
52020.12.01 19:30buy30.201812.570.001853.93
62020.12.02 10:39buy40.201824.800.001839.41
72020.12.02 14:45close40.201817.290.001839.41-150.201218.80
82020.12.07 16:52t/p30.201853.930.001853.93774.121992.92
92021.02.04 16:00sell50.201808.190.001779.92
102021.02.05 17:24close50.201808.200.001779.923.921996.85
112021.02.05 19:15buy60.201814.770.001846.21
122021.02.08 14:48buy70.201823.880.001843.17
132021.02.09 09:54t/p70.201843.170.001843.17376.952373.80
142021.02.09 11:24t/p60.201846.210.001846.21611.112984.91
152021.02.16 15:15sell80.201811.040.001788.17
162021.02.16 18:30sell90.201803.470.001770.34
172021.02.17 01:09t/p80.201788.170.001788.17461.523446.43
182021.02.17 18:09t/p90.201770.340.001770.34666.724113.15
192021.02.23 04:00buy100.201813.560.001842.71
202021.02.23 05:45buy110.201813.250.001827.73
212021.02.23 11:24close100.201806.060.001842.71-150.003963.15
222021.02.23 11:24close110.201805.750.001827.73-150.003813.15
232021.02.23 11:24buy120.201806.240.001820.63
242021.02.23 16:38close120.201798.740.001820.63-150.003663.15
252021.05.06 18:00buy130.201815.860.001857.40
262021.05.12 23:21close130.201815.850.001857.40-35.583627.57
272021.05.13 13:15sell140.201810.390.001791.73
282021.05.13 15:08close140.201817.890.001791.73-150.003477.57
292021.05.13 15:08sell150.201817.380.001809.21
302021.05.13 17:52close150.201824.880.001809.21-150.003327.57
312021.06.17 10:30sell160.201809.210.001762.92
322021.06.18 22:54t/p160.201762.920.001762.92929.924257.49
332021.07.08 14:00buy170.201817.700.001849.34
342021.07.08 16:39close170.201810.200.001849.34-150.004107.49
352021.07.13 15:30buy180.201813.510.001824.51
362021.07.13 15:30close180.201806.000.001824.51-150.203957.29
372021.07.13 18:15buy190.201812.780.001833.54
382021.07.13 21:09close190.201805.280.001833.54-150.003807.29
392021.07.14 06:30buy200.201813.370.001826.09
402021.07.14 08:30buy210.201813.750.001827.04
412021.07.14 15:06buy220.201822.680.001840.68
422021.07.14 15:09t/p200.201826.090.001826.09254.404061.69
432021.07.14 15:37t/p210.201827.040.001827.04265.804327.49
442021.07.15 16:00close220.201822.670.001840.68-26.744300.75
452021.07.16 22:30sell230.201810.350.001786.20
462021.07.19 09:15sell240.201806.190.001789.75
472021.07.19 14:54sell250.201800.540.001777.82
482021.07.19 15:52close250.201808.040.001777.82-150.004150.75
492021.07.19 16:09close240.201813.690.001789.75-150.004000.75
502021.07.19 18:15sell260.201807.210.001794.99
512021.07.19 23:30close230.201811.970.001786.20-28.283972.47
522021.07.20 04:04close260.201814.710.001794.99-145.883826.60
532021.07.20 04:04sell270.201814.220.001812.51
542021.07.20 11:09t/p270.201812.510.001812.5134.203860.80
552021.07.20 18:15sell280.201810.140.001788.26
562021.07.20 20:30sell290.201810.840.001790.01
572021.07.21 13:54sell300.201801.740.001784.64
582021.07.22 15:36close300.201801.750.001784.6412.173872.96
592021.07.23 10:54close280.201810.150.001788.2620.413893.37
602021.07.23 14:34t/p290.201790.010.001790.01437.214330.58
612021.07.29 04:30buy310.201816.120.001850.98
622021.07.30 19:52close310.201816.110.001850.98-9.054321.54
632021.07.30 21:45sell320.201810.450.001779.33
642021.08.02 04:45sell330.201809.440.001783.03
652021.08.02 19:24close330.201816.940.001783.03-150.004171.54
662021.08.02 19:39close320.201817.950.001779.33-145.884025.66
672021.08.02 19:39sell340.201817.460.001799.73
682021.08.03 04:30sell350.201809.740.001795.34
692021.08.04 05:30close350.201813.370.001795.34-68.483957.18
702021.08.04 05:30sell360.201812.880.001810.08
712021.08.04 14:36close340.201817.470.001799.738.043965.22
722021.08.04 15:07close360.201820.380.001810.08-150.003815.22
732021.08.04 18:30sell370.201806.630.001769.34
742021.08.05 10:52close370.201814.130.001769.34-137.633677.59
752021.08.05 10:52sell380.201813.640.001805.63
762021.08.05 15:30sell390.201810.170.001803.44
772021.08.05 16:37t/p380.201805.630.001805.63160.203837.79
782021.08.05 16:39t/p390.201803.440.001803.44134.603972.39
792021.08.27 19:15buy400.201814.870.001860.65
802021.08.30 20:15close400.201810.010.001860.65-106.053866.34
812021.08.31 04:30buy410.201813.970.001822.78
822021.08.31 14:15buy420.201814.220.001820.42
832021.08.31 16:06close420.201806.720.001820.42-150.003716.34
842021.08.31 16:06close410.201806.470.001822.78-150.003566.34
852021.08.31 16:06buy430.201806.960.001825.02
862021.08.31 20:00buy440.201814.280.001832.63
872021.09.01 21:00close440.201812.490.001832.63-44.653521.70
882021.09.01 21:00sell450.201812.480.001801.41
892021.09.02 07:30sell460.201811.430.001804.14
902021.09.02 17:09close430.201806.950.001825.02-35.583486.11
912021.09.03 04:07close450.201812.490.001801.4116.293502.40
922021.09.03 04:39sell470.201810.530.001806.77
932021.09.03 08:30close460.201811.790.001804.14-3.083499.32
942021.09.03 15:34close470.201818.030.001806.77-150.003349.32
952021.09.03 15:34sell480.201817.540.001806.17
962021.09.03 15:37close480.201825.040.001806.17-150.003199.32
972021.09.07 13:15sell490.201810.900.001786.66
982021.09.07 17:01sell500.201808.280.001782.29
992021.09.08 16:54t/p490.201786.660.001786.66488.923688.25
1002021.09.14 15:30t/p500.201782.290.001782.29548.654236.90
1012021.11.05 18:45buy510.201814.320.001857.75
1022021.11.10 16:24t/p510.201857.750.001857.75842.065078.96
1032021.11.22 19:45sell520.201810.200.001755.21
1042021.11.23 04:15sell530.201807.780.001757.35
1052021.11.23 08:48sell540.201803.200.001790.24
1062021.11.23 15:07t/p540.201790.240.001790.24259.205338.16
1072021.11.26 09:54close530.201807.790.001757.3520.415358.57
1082021.11.26 12:03close520.201810.210.001755.2124.535383.10
1092021.12.27 18:00buy550.201812.970.001827.60
1102021.12.28 08:00buy560.201813.190.001822.48
1112021.12.28 13:01buy570.201818.480.001832.73
1122021.12.28 16:09close570.201810.980.001832.73-150.005233.10
1132021.12.28 19:00close550.201810.530.001827.60-57.655175.46
1142021.12.28 19:00buy580.201811.040.001813.04
1152021.12.28 20:54close560.201805.680.001822.48-150.205025.26
1162021.12.29 10:07close580.201803.540.001813.04-158.854866.41
1172021.12.30 19:00buy590.201813.810.001839.84
1182022.01.03 15:09close590.201813.790.001839.84-18.094848.32
1192022.01.03 16:00sell600.201806.970.001776.15
1202022.01.04 17:00close600.201811.710.001776.15-90.684757.64
1212022.01.04 17:45buy610.201817.000.001844.21
1222022.01.04 19:30buy620.201814.580.001838.16
1232022.01.05 15:30buy630.201823.000.001835.98
1242022.01.05 21:09close610.201816.980.001844.21-9.254748.40
1252022.01.05 21:09close630.201815.500.001835.98-150.004598.40
1262022.01.05 21:09close620.201814.570.001838.16-9.054589.35
1272022.01.05 22:30sell640.201810.000.001780.84
1282022.01.11 08:16close640.201810.010.001780.8424.534613.88
1292022.01.11 18:30buy650.201815.660.001836.02
1302022.01.13 17:51close650.201815.650.001836.02-35.584578.30
1312022.01.18 12:00sell660.201810.270.001791.81
1322022.01.18 15:30sell670.201806.890.001783.36
1332022.01.18 15:34close670.201814.390.001783.36-150.004428.30
1342022.01.18 15:37close660.201817.770.001791.81-150.004278.30
1352022.01.19 05:15sell680.201810.740.001797.05
1362022.01.19 07:00sell690.201811.540.001805.36
1372022.01.19 12:34close680.201818.240.001797.05-150.004128.30
1382022.01.19 12:37close690.201819.040.001805.36-150.003978.30
1392022.01.19 12:37sell700.201818.550.001805.80
1402022.01.19 16:37close700.201826.050.001805.80-150.003828.30
1412022.01.27 09:00sell710.201810.600.001776.66
1422022.01.27 13:15sell720.201810.700.001793.86
1432022.01.27 15:49sell730.201801.610.001779.70
1442022.01.27 16:39close730.201809.110.001779.70-150.003678.30
1452022.01.27 18:24t/p720.201793.860.001793.86336.804015.10
1462022.02.02 17:24close710.201810.610.001776.6616.294031.39
1472022.02.04 12:30buy740.201814.010.001827.66
1482022.02.04 15:30buy750.201813.280.001824.05
1492022.02.04 15:36close740.201806.510.001827.66-150.003881.39
1502022.02.04 15:36close750.201805.780.001824.05-150.003731.39
1512022.02.07 02:45buy760.201812.790.001843.32
1522022.02.07 11:00buy770.201813.360.001822.92
1532022.02.07 21:24buy780.201822.380.001840.10
1542022.02.07 21:37t/p770.201822.920.001822.92191.203922.59
1552022.02.10 15:33close780.201822.370.001840.10-44.433878.16
1562022.02.11 20:34t/p760.201843.320.001843.32557.524435.68
1572022.05.13 16:15sell790.201802.800.001764.16
1582022.05.13 17:01close790.201810.310.001764.16-150.204285.48
1592022.05.13 19:00sell800.201808.990.001779.64
1602022.05.16 02:00sell810.201810.840.001796.49
1612022.05.16 03:58close800.201816.500.001779.64-146.084139.40
1622022.05.16 05:01sell820.201812.910.001807.12
1632022.05.16 08:05t/p820.201807.120.001807.12115.804255.20
1642022.05.16 08:05sell830.201806.620.001791.70
1652022.05.16 10:43t/p810.201796.490.001796.49287.004542.20
1662022.05.16 10:51t/p830.201791.700.001791.70298.404840.60
1672022.05.18 06:30sell840.201808.180.001785.79
1682022.05.18 10:00sell850.201809.610.001794.63
1692022.05.18 10:28close840.201815.680.001785.79-150.004690.60
1702022.05.18 11:12close850.201817.120.001794.63-150.204540.40
1712022.05.18 15:15sell860.201808.580.001791.15
1722022.05.18 16:43close860.201816.080.001791.15-150.004390.40
1732022.06.14 19:00sell870.201810.290.001778.72
1742022.06.14 21:30sell880.201810.070.001778.17
1752022.06.15 04:38close880.201817.580.001778.17-146.084244.32
1762022.06.15 05:20close870.201817.790.001778.72-145.884098.45
1772022.06.15 05:20sell890.201817.300.001812.70
1782022.06.15 12:40close890.201824.800.001812.70-150.003948.45
1792022.06.30 13:45sell900.201810.240.001792.95
1802022.06.30 15:37close900.201817.740.001792.95-150.003798.45
1812022.06.30 18:00sell910.201808.930.001784.98
1822022.06.30 20:06sell920.201809.330.001786.62
1832022.07.01 08:31sell930.201800.240.001786.49
1842022.07.01 14:39t/p920.201786.620.001786.62458.324256.77
1852022.07.01 14:39t/p930.201786.490.001786.49275.004531.77
1862022.07.01 15:24t/p910.201784.980.001784.98483.125014.89
1872022.12.13 16:30buy940.201818.880.001875.10
1882022.12.13 17:47close940.201811.380.001875.10-150.004864.89
1892022.12.13 18:45buy950.201813.260.001859.03
1902022.12.13 19:25close950.201805.760.001859.03-150.004714.89
1912022.12.20 17:15buy960.201820.830.001871.25
1922022.12.21 06:43close960.201813.330.001871.25-158.854556.04
1932022.12.21 09:30buy970.201815.340.001820.13
1942022.12.21 14:00buy980.201814.050.001816.90
1952022.12.21 15:13t/p980.201816.900.001816.9057.004613.04
1962022.12.21 17:07t/p970.201820.130.001820.1395.804708.84
1972022.12.22 16:15sell990.201807.890.001789.40
1982022.12.22 20:02t/p990.201789.400.001789.40369.805078.64
1992022.12.27 17:30buy1000.201821.690.001850.33
2002022.12.27 19:56close1000.201814.190.001850.33-150.004928.64
2012022.12.27 20:15buy1010.201814.980.001833.55
2022022.12.28 03:30buy1020.201814.640.001832.70
2032022.12.28 09:03close1010.201807.470.001833.55-159.054769.60
2042022.12.28 09:16buy1030.201809.440.001810.49
2052022.12.28 10:00t/p1030.201810.490.001810.4921.004790.60
2062022.12.28 10:08close1020.201807.130.001832.70-150.204640.40
2072022.12.29 17:00buy1040.201814.300.001828.75
2082022.12.29 18:45buy1050.201814.670.001829.67
2092022.12.30 09:01buy1060.201821.980.001831.55
2102022.12.30 12:31close1060.201814.470.001831.55-150.204490.20
2112022.12.30 18:38close1040.201814.280.001828.75-9.254480.95
2122023.01.03 01:07t/p1050.201829.670.001829.67273.464754.41
2132023.02.24 18:15sell1070.201809.460.001784.47
2142023.02.24 20:00sell1080.201809.720.001785.12
2152023.02.27 16:00close1070.201816.960.001784.47-145.884608.54
2162023.02.27 16:08sell1090.201814.370.001811.82
2172023.02.27 16:22close1080.201817.220.001785.12-145.884462.66
2182023.02.28 09:22t/p1090.201811.820.001811.8255.124517.78
2192023.02.28 10:00sell1100.201810.360.001797.04
2202023.02.28 12:00sell1110.201810.170.001796.57
2212023.02.28 16:46close1110.201817.670.001796.57-150.004367.78
2222023.02.28 16:47close1100.201817.860.001797.04-150.004217.78
2232023.02.28 16:47sell1120.201817.370.001816.92
2242023.02.28 16:51t/p1120.201816.920.001816.929.004226.78
2252023.03.08 05:15sell1130.201809.930.001774.74
2262023.03.08 16:32close1130.201817.430.001774.74-150.004076.78
+
diff --git a/Docs/Reports/XTPW/Full/StrategyTester 1.gif b/Docs/Reports/XTPW/Full/StrategyTester 1.gif new file mode 100644 index 0000000..dabf25d Binary files /dev/null and b/Docs/Reports/XTPW/Full/StrategyTester 1.gif differ diff --git a/Docs/Reports/XTPW/Full/StrategyTester 1.htm b/Docs/Reports/XTPW/Full/StrategyTester 1.htm new file mode 100644 index 0000000..e6ae90d --- /dev/null +++ b/Docs/Reports/XTPW/Full/StrategyTester 1.htm @@ -0,0 +1,169 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.01 23:45 (2020.01.01 - 2023.08.02)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63353Ticks modelled72601176Modelling qualityn/a
Mismatched charts errors808
Initial deposit1000.00SpreadCurrent (57)
Total net profit209.11Gross profit297.85Gross loss-88.73
Profit factor3.36Expected payoff4.18
Absolute drawdown5.97Maximal drawdown30.04 (2.64%)Relative drawdown2.64% (30.04)
Total trades50Short positions (won %)35 (85.71%)Long positions (won %)15 (93.33%)
Profit trades (% of total)44 (88.00%)Loss trades (% of total)6 (12.00%)
Largestprofit trade22.02loss trade-15.49
Averageprofit trade6.77loss trade-14.79
Maximumconsecutive wins (profit in money)10 (74.81)consecutive losses (loss in money)1 (-15.49)
Maximalconsecutive profit (count of wins)74.81 (10)consecutive loss (count of losses)-15.49 (1)
Averageconsecutive wins6consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 17:39sell10.011836.610.001825.20
22020.12.07 10:37t/p10.011825.200.001825.2011.631011.63
32021.01.29 16:54sell20.011865.800.001855.99
42021.01.29 19:22t/p20.011855.990.001855.999.811021.44
52021.02.09 17:45sell30.011841.990.001838.33
62021.02.09 18:09t/p30.011838.330.001838.333.661025.10
72021.02.10 17:00sell40.011841.300.001827.41
82021.02.11 19:09t/p40.011827.410.001827.4114.551039.65
92021.02.16 17:09sell50.011804.040.001801.47
102021.02.16 18:49t/p50.011801.470.001801.472.571042.22
112021.03.03 16:51sell60.011712.530.001708.07
122021.03.03 17:36t/p60.011708.070.001708.074.461046.68
132021.03.11 16:48buy70.011719.900.001728.00
142021.03.11 20:09t/p70.011728.000.001728.008.101054.78
152021.03.17 13:48buy80.011728.340.001737.00
162021.03.17 20:06t/p80.011737.000.001737.008.661063.44
172021.04.19 15:15buy90.011775.900.001781.90
182021.04.21 04:39t/p90.011781.900.001781.905.031068.46
192021.04.27 18:24buy100.011778.420.001784.35
202021.04.28 12:24close100.011763.420.001784.35-15.491052.98
212021.05.10 17:45sell110.011839.580.001833.85
222021.05.11 03:39t/p110.011833.850.001833.855.951058.93
232021.05.19 22:00buy120.011863.460.001881.95
242021.05.20 19:49t/p120.011881.950.001881.9517.031075.96
252021.07.06 19:07buy130.011794.080.001807.68
262021.07.07 13:24t/p130.011807.680.001807.6813.111089.07
272021.07.08 18:04buy140.011801.930.001814.59
282021.07.13 15:39t/p140.011814.590.001814.5911.201100.27
292021.07.13 17:21sell150.011811.750.001808.46
302021.07.13 20:37t/p150.011808.460.001808.463.291103.56
312021.08.17 17:15buy160.011782.680.001787.76
322021.08.18 04:09t/p160.011787.760.001787.764.591108.16
332021.08.20 17:39sell170.011781.750.001777.75
342021.08.23 03:16t/p170.011777.750.001777.754.221112.38
352021.08.31 15:30sell180.011811.860.001809.11
362021.08.31 16:04t/p180.011809.110.001809.112.751115.13
372021.10.27 18:09sell190.011793.560.001789.11
382021.10.28 16:30close190.011808.560.001789.11-14.341100.78
392021.11.03 04:00sell200.011783.060.001779.26
402021.11.03 08:15t/p200.011779.260.001779.263.801104.58
412021.11.30 17:48sell210.011794.770.001781.02
422021.11.30 18:04t/p210.011781.020.001781.0213.751118.33
432021.12.13 16:49sell220.011785.140.001782.99
442021.12.14 10:24t/p220.011782.990.001782.992.371120.70
452021.12.15 16:54sell230.011769.740.001766.01
462021.12.15 17:39t/p230.011766.010.001766.013.731124.43
472021.12.20 17:01sell240.011793.800.001789.41
482021.12.20 22:09t/p240.011789.410.001789.414.391128.82
492021.12.21 16:52buy250.011793.790.001799.79
502021.12.22 20:09t/p250.011799.790.001799.795.511134.34
512022.01.18 18:19sell260.011813.030.001806.19
522022.01.19 16:51close260.011828.030.001806.19-14.781119.55
532022.02.15 11:19buy270.011856.930.001866.99
542022.02.16 19:19t/p270.011866.990.001866.999.571129.13
552022.02.18 17:33sell280.011895.770.001893.21
562022.02.18 17:37t/p280.011893.210.001893.212.561131.69
572022.03.02 18:16sell290.011921.470.001907.56
582022.03.03 13:34close290.011936.470.001907.56-14.341117.35
592022.04.22 19:22sell300.011936.790.001932.93
602022.04.22 20:28t/p300.011932.930.001932.933.861121.21
612022.04.26 16:08sell310.011905.800.001905.21
622022.04.26 16:57t/p310.011905.210.001905.210.591121.80
632022.06.10 16:01sell320.011839.900.001834.17
642022.06.10 16:18t/p320.011834.170.001834.175.731127.53
652022.07.20 16:52sell330.011708.520.001702.79
662022.07.20 19:48t/p330.011702.790.001702.795.731133.26
672022.08.02 18:02sell340.011776.930.001767.92
682022.08.02 21:02t/p340.011767.920.001767.929.011142.27
692022.09.30 20:35buy350.011663.130.001667.34
702022.10.03 04:30t/p350.011667.340.001667.343.721145.99
712022.11.02 21:03sell360.011647.760.001626.40
722022.11.03 10:26t/p360.011626.400.001626.4022.021168.01
732022.11.30 17:18buy370.011751.890.001763.12
742022.11.30 21:20t/p370.011763.120.001763.1211.231179.24
752022.12.09 17:23buy380.011791.230.001800.19
762022.12.09 18:20t/p380.011800.190.001800.198.961188.20
772023.01.11 17:38buy390.011870.980.001874.94
782023.01.11 19:21t/p390.011874.940.001874.943.961192.16
792023.01.12 17:10sell400.011884.680.001867.96
802023.01.12 21:03close400.011899.680.001867.96-15.001177.16
812023.02.07 16:32sell410.011869.860.001868.93
822023.02.07 16:45t/p410.011868.930.001868.930.931178.09
832023.02.09 17:00sell420.011879.160.001868.22
842023.02.09 18:03t/p420.011868.220.001868.2210.941189.03
852023.03.02 20:35sell430.011835.870.001834.80
862023.03.03 21:27close430.011850.870.001834.80-14.781174.25
872023.04.26 19:17buy440.011989.040.001995.12
882023.04.27 05:13t/p440.011995.120.001995.124.621178.87
892023.05.15 17:34sell450.012016.660.002011.32
902023.05.16 09:04t/p450.012011.320.002011.325.561184.43
912023.05.26 17:09sell460.011951.200.001949.72
922023.05.26 17:19t/p460.011949.720.001949.721.481185.91
932023.06.07 17:32sell470.011958.950.001947.93
942023.06.07 18:51t/p470.011947.930.001947.9311.021196.93
952023.07.13 18:04sell480.011959.610.001957.54
962023.07.13 18:51t/p480.011957.540.001957.542.071199.00
972023.07.19 18:12sell490.011974.940.001970.18
982023.07.20 17:35t/p490.011970.180.001970.185.421204.41
992023.07.25 15:30sell500.011958.580.001953.88
1002023.07.25 17:00t/p500.011953.880.001953.884.701209.11
+
diff --git a/Docs/Reports/XTPW/Long/StrategyTester Long 13.gif b/Docs/Reports/XTPW/Long/StrategyTester Long 13.gif new file mode 100644 index 0000000..36be70d Binary files /dev/null and b/Docs/Reports/XTPW/Long/StrategyTester Long 13.gif differ diff --git a/Docs/Reports/XTPW/Long/StrategyTester Long 13.htm b/Docs/Reports/XTPW/Long/StrategyTester Long 13.htm new file mode 100644 index 0000000..bb47461 --- /dev/null +++ b/Docs/Reports/XTPW/Long/StrategyTester Long 13.htm @@ -0,0 +1,103 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.02 06:00 (2020.01.01 - 2023.08.31)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=true; +allowShortTrades=false; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63374Ticks modelled72620713Modelling qualityn/a
Mismatched charts errors809
Initial deposit1000.00SpreadCurrent (57)
Total net profit91.72Gross profit107.20Gross loss-15.49
Profit factor6.92Expected payoff5.40
Absolute drawdown0.80Maximal drawdown21.17 (2.03%)Relative drawdown2.03% (21.17)
Total trades17Short positions (won %)0 (0.00%)Long positions (won %)17 (94.12%)
Profit trades (% of total)16 (94.12%)Loss trades (% of total)1 (5.88%)
Largestprofit trade17.03loss trade-15.49
Averageprofit trade6.70loss trade-15.49
Maximumconsecutive wins (profit in money)13 (89.63)consecutive losses (loss in money)1 (-15.49)
Maximalconsecutive profit (count of wins)89.63 (13)consecutive loss (count of losses)-15.49 (1)
Averageconsecutive wins8consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12021.03.11 16:48buy10.011719.900.001725.30
22021.03.11 17:07t/p10.011725.300.001725.305.401005.40
32021.03.17 13:48buy20.011728.340.001737.00
42021.03.17 20:06t/p20.011737.000.001737.008.661014.06
52021.04.19 15:15buy30.011775.900.001779.90
62021.04.20 19:24t/p30.011779.900.001779.903.511017.57
72021.04.27 18:24buy40.011778.420.001784.35
82021.04.28 12:24close40.011763.420.001784.35-15.491002.09
92021.05.19 22:00buy50.011863.460.001881.95
102021.05.20 19:49t/p50.011881.950.001881.9517.031019.12
112021.07.06 19:07buy60.011794.080.001807.68
122021.07.07 13:24t/p60.011807.680.001807.6813.111032.23
132021.07.08 18:04buy70.011801.930.001814.59
142021.07.13 15:39t/p70.011814.590.001814.5911.201043.43
152021.08.17 17:15buy80.011782.680.001786.06
162021.08.17 17:24t/p80.011786.060.001786.063.381046.81
172021.12.21 16:52buy90.011793.790.001799.79
182021.12.22 20:09t/p90.011799.790.001799.795.511052.33
192022.02.15 11:19buy100.011856.930.001863.63
202022.02.16 16:39t/p100.011863.630.001863.636.211058.54
212022.04.26 17:36buy110.011901.340.001904.58
222022.04.26 17:38t/p110.011904.580.001904.583.241061.78
232022.09.30 20:35buy120.011663.130.001665.93
242022.10.03 04:23t/p120.011665.930.001665.932.311064.09
252022.11.30 17:18buy130.011751.890.001763.12
262022.11.30 21:20t/p130.011763.120.001763.1211.231075.32
272022.12.09 17:23buy140.011791.230.001800.19
282022.12.09 18:20t/p140.011800.190.001800.198.961084.28
292023.01.11 17:38buy150.011870.980.001873.62
302023.01.11 18:51t/p150.011873.620.001873.622.641086.92
312023.04.26 19:17buy160.011989.040.001993.09
322023.04.27 04:34t/p160.011993.090.001993.092.591089.52
332023.07.13 19:00buy170.011955.090.001957.29
342023.07.13 19:18t/p170.011957.290.001957.292.201091.72
+
diff --git a/Docs/Reports/XTPW/Short/StrategyTester 13.gif b/Docs/Reports/XTPW/Short/StrategyTester 13.gif new file mode 100644 index 0000000..8e75c52 Binary files /dev/null and b/Docs/Reports/XTPW/Short/StrategyTester 13.gif differ diff --git a/Docs/Reports/XTPW/Short/StrategyTester 13.htm b/Docs/Reports/XTPW/Short/StrategyTester 13.htm new file mode 100644 index 0000000..b78cc40 --- /dev/null +++ b/Docs/Reports/XTPW/Short/StrategyTester 13.htm @@ -0,0 +1,139 @@ + + + + Strategy Tester: x-saherelm.ea + + + + + + + +
+
Strategy Tester Report
+
x-saherelm.ea
+
Alpari-Demo (Build 1382)

+ + + + + + + + + + + + + + + + + + + + + + +
SymbolXAUUSD (Gold (Spot))
Period15 Minutes (M15) 2020.11.25 18:30 - 2023.08.01 23:45 (2020.01.01 - 2023.08.02)
ModelEvery tick (the most precise method based on all available least timeframes)
ParameterssignalPrefix="XST_EA"; bullishSignalLabel="X_BUY"; bullishSignalColor=Aqua; bearishSignalLabel="X_SELL"; bearishSignalColor=Magenta; signalEntryColor=Aquamarine; signalSLColor=Red; signalTPColor=Green; candleGapBetweenSignals=7; allowTrade=true; +allowLongTrades=false; +allowShortTrades=true; +alertEvents=true; +alertPositions=true; +longPositionAlerts=true; +shortPositionAlerts=true; +terminalAlert=false; +pushAlert=false; +lotsPerTradePercent=0.00001; maxOpenTrades=4; maxDrawdownPercentPerPTrade=0.1; minBalancePercent=0.5; maxEquityPercent=0.1; xStarter="- X Signal Provider -"; enableXSignalling=false; +xShortR2R=3; xShortLotsPerTradePercent=0.00001; xShortMaxDrawdownPerTradePercent=0.02; xLongR2R=3; xLongLotsPerTradePercent=0.00001; xLongMaxDrawdownPerTradePercent=0.02; xSharpDetectorFactor=700; xMaximumCandlesPerTrade=206; xOscillatorLength=7; xPSarStep=0.02; xPSarMaximum=0.2; xRangeMarketLength=5; xSwingLength=7; xRStarter="- XR Signal Provider -"; enableXRSignalling=false; +xRShortR2R=2; xRShortLotsPerTradePercent=0.00001; xRShortMaxDrawdownPerTradePercent=0.01; xRLongR2R=2; xRLongLotsPerTradePercent=0.00001; xRLongMaxDrawdownPerTradePercent=0.01; xRMaximumCandlesPerTrade=252; xROscillatorLength=7; xRFastLength=20; xRSlowLength=50; xRRangeMarketLength=50; xRSwingLength=7; xTPWStarter="- XTPW Signal Provider -"; enableXTPWSignalling=true; +xTPWShortR2R=2; xTPWShortLotsPerTradePercent=0.00001; xTPWShortMaxDrawdownPerTradePercent=0.015; xTPWLongR2R=2; xTPWLongLotsPerTradePercent=0.00001; xTPWLongMaxDrawdownPerTradePercent=0.015; xTPWMaximumCandlesPerTrade=206; xTPWPSarStep=0.02; xTPWPSarMaximum=0.2; xTPWSwingLength=7; xTPWSharpDetectionFactor=650;
Bars in test63353Ticks modelled72601176Modelling qualityn/a
Mismatched charts errors808
Initial deposit1000.00SpreadCurrent (59)
Total net profit109.29Gross profit182.54Gross loss-73.25
Profit factor2.49Expected payoff3.12
Absolute drawdown5.99Maximal drawdown31.30 (2.90%)Relative drawdown2.90% (31.30)
Total trades35Short positions (won %)35 (85.71%)Long positions (won %)0 (0.00%)
Profit trades (% of total)30 (85.71%)Loss trades (% of total)5 (14.29%)
Largestprofit trade22.02loss trade-15.00
Averageprofit trade6.08loss trade-14.65
Maximumconsecutive wins (profit in money)10 (62.88)consecutive losses (loss in money)1 (-15.00)
Maximalconsecutive profit (count of wins)62.88 (10)consecutive loss (count of losses)-15.00 (1)
Averageconsecutive wins5consecutive losses1
+Graph
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#TimeTypeOrderSizePriceS / LT / PProfitBalance
12020.12.04 17:39sell10.011836.610.001825.20
22020.12.07 10:37t/p10.011825.200.001825.2011.631011.63
32021.01.29 16:54sell20.011865.800.001855.99
42021.01.29 19:22t/p20.011855.990.001855.999.811021.44
52021.02.09 17:45sell30.011841.990.001838.33
62021.02.09 18:09t/p30.011838.330.001838.333.661025.10
72021.02.10 17:00sell40.011841.300.001827.41
82021.02.11 19:09t/p40.011827.410.001827.4114.551039.65
92021.02.16 17:09sell50.011804.040.001801.47
102021.02.16 18:49t/p50.011801.470.001801.472.571042.22
112021.03.03 16:51sell60.011712.530.001708.07
122021.03.03 17:36t/p60.011708.070.001708.074.461046.68
132021.05.10 17:45sell70.011839.580.001833.85
142021.05.11 03:39t/p70.011833.850.001833.855.951052.63
152021.07.13 17:21sell80.011811.750.001808.46
162021.07.13 20:37t/p80.011808.460.001808.463.291055.92
172021.08.20 17:39sell90.011781.750.001777.75
182021.08.23 03:16t/p90.011777.750.001777.754.221060.13
192021.08.31 15:30sell100.011811.860.001809.11
202021.08.31 16:04t/p100.011809.110.001809.112.751062.88
212021.10.27 18:09sell110.011793.560.001789.11
222021.10.28 16:30close110.011808.560.001789.11-14.341048.54
232021.11.03 04:00sell120.011783.060.001779.26
242021.11.03 08:16t/p120.011779.260.001779.263.801052.34
252021.11.30 17:48sell130.011794.770.001781.02
262021.11.30 18:04t/p130.011781.020.001781.0213.751066.09
272021.12.13 16:49sell140.011785.140.001782.99
282021.12.14 10:24t/p140.011782.990.001782.992.371068.46
292021.12.15 16:54sell150.011769.740.001766.01
302021.12.15 17:39t/p150.011766.010.001766.013.731072.19
312021.12.20 17:01sell160.011793.800.001789.41
322021.12.20 22:09t/p160.011789.410.001789.414.391076.58
332022.01.18 18:19sell170.011813.030.001806.19
342022.01.19 16:51close170.011828.030.001806.19-14.781061.80
352022.02.18 17:33sell180.011895.770.001893.21
362022.02.18 17:37t/p180.011893.210.001893.212.561064.36
372022.03.02 18:16sell190.011921.470.001907.56
382022.03.03 13:34close190.011936.470.001907.56-14.341050.02
392022.04.22 19:22sell200.011936.790.001932.93
402022.04.22 20:28t/p200.011932.930.001932.933.861053.88
412022.04.26 16:08sell210.011905.800.001905.21
422022.04.26 16:57t/p210.011905.210.001905.210.591054.47
432022.06.10 16:01sell220.011839.900.001834.17
442022.06.10 16:18t/p220.011834.170.001834.175.731060.20
452022.07.20 16:52sell230.011708.520.001702.79
462022.07.20 19:48t/p230.011702.790.001702.795.731065.93
472022.08.02 18:02sell240.011776.930.001767.92
482022.08.02 21:02t/p240.011767.920.001767.929.011074.94
492022.11.02 21:03sell250.011647.760.001626.40
502022.11.03 10:26t/p250.011626.400.001626.4022.021096.95
512023.01.12 17:10sell260.011884.680.001867.96
522023.01.12 21:03close260.011899.680.001867.96-15.001081.95
532023.02.07 16:32sell270.011869.860.001868.93
542023.02.07 16:45t/p270.011868.930.001868.930.931082.88
552023.02.09 17:00sell280.011879.160.001868.22
562023.02.09 18:03t/p280.011868.220.001868.2210.941093.82
572023.03.02 20:35sell290.011835.870.001834.78
582023.03.03 21:27close290.011850.870.001834.78-14.781079.04
592023.05.15 17:34sell300.012016.660.002011.32
602023.05.16 09:05t/p300.012011.320.002011.325.561084.60
612023.05.26 17:09sell310.011951.200.001949.72
622023.05.26 17:19t/p310.011949.720.001949.721.481086.08
632023.06.07 17:32sell320.011958.950.001947.93
642023.06.07 18:51t/p320.011947.930.001947.9311.021097.10
652023.07.13 18:04sell330.011959.610.001957.54
662023.07.13 18:51t/p330.011957.540.001957.542.071099.17
672023.07.19 18:12sell340.011974.940.001970.18
682023.07.20 17:35t/p340.011970.180.001970.185.421104.59
692023.07.25 15:30sell350.011958.580.001953.88
702023.07.25 17:00t/p350.011953.880.001953.884.701109.29
+
diff --git a/Docs/Signalling Conditions.md b/Docs/Signalling Conditions.md new file mode 100644 index 0000000..ac8aec4 --- /dev/null +++ b/Docs/Signalling Conditions.md @@ -0,0 +1,501 @@ +# OSC Signalling Conditions + +there are some Verifications For signals. +here i described them. + +## Long + +- OSC +- When Market Middleage Cross Over MC Fast +- When MCFast Under MC Slow +- When MakretMiddleage + +```mql4 + // // + // // XMA Based Signals ... + // hasLongSignal = + // // + // // XMA ... + // // + // // SC Fast Cross Over Market Middleage ... + // xmaState.scFast > xmaState.marketMiddleage + // && !(xmaState.scFastPrev > xmaState.marketMiddleage) + // // + // // when Short Cycle is Trending Up ... + // && xmaState.scFast > xmaState.scSlow + // && xmaState.scFastPrev > xmaState.scSlowPrev + // // + // // When Medium Cycle is Trending Up ... + // && xmaState.mcFast > xmaState.mcSlow + // && xmaState.mcFastPrev > xmaState.mcSlowPrev + // // + // // and Medium Cycle TrendPower is Going Up ... + // && MathAbs(xmaState.mcFast - xmaState.mcSlow) > + // MathAbs(xmaState.mcFastPrev - xmaState.mcSlowPrev) + // // + // // When Long Cycle is Trending Up ... + // && xmaState.lcFast > xmaState.lcSlow + // && xmaState.lcFastPrev > xmaState.lcSlowPrev + // // + // // and Long Cycle TrendPower is Going Up ... + // && MathAbs(xmaState.lcFast - xmaState.lcSlow) > + // MathAbs(xmaState.lcFastPrev - xmaState.lcSlowPrev) + // // + // // Short Cycle Slow bigger thhan Medium Cycle Fast ... + // && xmaState.scSlow > xmaState.mcFast + // // + // // OSC ... + // // Check OSC Fast and Slow is Less than 0.5 ... + // && oscState.fastOSC < 0.5 + // && oscState.slowOSC < 0.5 + // && oscState.fastOSCPrev < 0.5 + // && oscState.slowOSCPrev < 0.5 + // && oscState.fastOSC > oscState.fastOSCPrev + // // + // // Check OSC Minimum Signal Power ... + // // this Helps for Detect Market exits from Ranging ... + // && minPowOSC > 0 + // ? + // // + // // Check Conditions only if value provided ... + // oscState.powerOSCPrev < 0 + // && MathAbs(oscState.powerOSCPrev) > minPowOSC + // : + // // + // // ... other wise, ignore ... + // true + // // + // // Check Previous Candle Signal Power must be Lower than + // // Current Signal Power and the Direction Must be Up Trend ... + // && oscState.powerOSCPrev < oscState.powerOSC + // // + // // Also we Have to Check Market not ranging ... + // && !IsOSCMarketRanging( + // bar_index + 1, + // marketLen, + // minPowOSC, + // fastOSCLen, + // fastOSCMul, + // slowOSCLen, + // slowOSCMul + // ) + // // + // // ZIGZAG ... + // && zigZagState.isWaitForTrendDown + // && !zigZagState.isWaitForTrendUp + // // + // // XADX ... + // // TODO: add XADX Base Conditions for Long Trades ... + // // When ADX Trend Power bigger than 20 and less than 50 ... + // && !adxState.trendPower < 23 + // && !adxState.trendPowerPrev < 23 + // // + // // Check Trend Direction for Signals ... + // && adxState.upDirection > adxState.downDirection + // && adxState.upDirectionPrev > adxState.downDirectionPrev + // // && adxState.trendPower < 50 + // // && adxState.trendPower > adxState.trendPowerPrev + // // + // // PRICE Checking ... + // // price must be less than Candle High at openning time ... + // && longEntryPrice <= candleHigh + // // + // // also Candle High and Low must be above than lc Fast & lc Slow ... + // && longEntryPrice > xmaState.lcFast + // && longEntryPrice > xmaState.lcSlow + // && ( + // !IsSharpBullishHappens( + // bar_index, + // marketLen * 2 + // ) + // || IsSharpBearishHappens( + // bar_index, + // marketLen * 2 + // ) + // ) + // ; + + // + // Check for Long Trades if some Sharp Bullish Happens, + // Decrease sl size for fixing tps ... + // if (isSharpBullishHappens) { + // sl = sl / 1.5; + // } + + // + // TODO: Remove this ... + // if (xmaStates[0].marketMiddleage > xmaStates[1].marketMiddleage) { + // r2rRatio = r2rRatio * 2; + // } + + // + hasLongSignal = + // + // Global ... + true + // + && ( + // + // XMA ... + ( + // + true + // + // Check Medium Cycle is in TrendDown ... + && xmaStates[0].mcSlow > xmaStates[0].mcFast + && xmaStates[1].mcSlow > xmaStates[1].mcFast + && xmaStates[2].mcSlow > xmaStates[2].mcFast + // + // Check Market Middleage Cross Over MC Slow ... + // && isMarketMiddleCrossOverMCSlow + // && xmaStates[0].marketMiddleage >= (5 * _Point); + && xmaStates[0].marketMiddleage > xmaStates[0].mcSlow + && !(xmaStates[1].marketMiddleage >= xmaStates[1].mcSlow) + // + // IMPORTANT: by passing this condition i can Increase r2r ration ... + // && xmaStates[0].marketMiddleage > xmaStates[1].marketMiddleage + && MathAbs(xmaStates[0].marketMiddleage - xmaStates[1].marketMiddleage) > _Point + ) + // || + // + // OSC ... + // ( + // // + // true + // // + // // Check osc fast cross over slow ... + // && oscStates[1].fastOSC > oscStates[1].slowOSC + // && !(oscStates[2].fastOSC >= oscStates[2].slowOSC) + // // + // // Check OSC Fast bigger than 0.5 ... + // && oscStates[1].fastOSC > 0.5 + // && ( + // xmaStates[1].mcFast > xmaStates[1].mcSlow + // ? + // // + // xmaStates[1].marketMiddleage > xmaStates[1].mcSlow + // // + // && xmaStates[1].marketMiddleage > xmaStates[2].marketMiddleage + // && xmaStates[1].marketMiddleage > xmaStates[3].marketMiddleage + // && xmaStates[2].marketMiddleage > xmaStates[3].marketMiddleage + // : + // true + // ) + // ) + ) + ; +``` + +```mql4 + // + // TODO: Determines Where and How close Long Trades on Trend Reversal Points ... + closeLongTrades = + false + // + // This is One Conditions ... + // ( + // // + // xmaStates[0].marketMiddleage < xmaStates[0].mcFast + // && ( + // xmaStates[0].marketMiddleage < xmaStates[0].mcSlow + // || xmaStates[1].marketMiddleage < xmaStates[1].mcSlow + // || xmaStates[2].marketMiddleage < xmaStates[2].mcSlow + // ) + // // + // && xmaStates[0].mcFast > xmaStates[0].mcSlow + // // + // && xmaStates[0].marketMiddleage < xmaStates[1].marketMiddleage + // && xmaStates[1].marketMiddleage < xmaStates[2].marketMiddleage + // ) + ; + + // + waitForLongSignals = + true; + // waitForLongSignals + // ? + // // + // true + // // + // // Closing Options ... + // // + // // Trades Doesnt Closed ... + // && !closeLongTrades + // // + // // PRICE ... + // // + // // Bullish Sharp doesnt occured ... + // && !isSharpBullishHappens + // // + // // XMA ... + // // + // && xmaStates[0].marketMiddleage < xmaStates[0].mcFast + // && !( + // // + // // On MC Trend Up ... + // xmaStates[0].mcFast > xmaStates[0].mcSlow + // ? + // // + // // Market Middleage doesnt Trending Down ... + // xmaStates[0].marketMiddleage - xmaStates[0].mcFast > xmaStates[1].marketMiddleage - xmaStates[1].mcFast + // && xmaStates[0].marketMiddleage - xmaStates[0].mcFast > xmaStates[2].marketMiddleage - xmaStates[2].mcFast + // && xmaStates[0].marketMiddleage - xmaStates[0].mcFast > xmaStates[3].marketMiddleage - xmaStates[3].mcFast + // && xmaStates[1].marketMiddleage - xmaStates[1].mcFast > xmaStates[3].marketMiddleage - xmaStates[3].mcFast + // : + // true + // ) + // : + // // + // true + // && ( + // // + // // PRICE ... + // // isSharpBearishHappens + // // + // // XMA ... + // isMCFastCrossUnderSlow + // || isMarketMiddleCrossUnderMCSlow + // ) + ; +``` + +```mql4 + // + bool xmaHasLongSignal = + // + // Global ... + true + // + // XMA ... + // + // Check Medium Cycle is in TrendDown ... + // && xmaStates[0].mcSlow > xmaStates[0].mcFast + // && xmaStates[1].mcSlow > xmaStates[1].mcFast + // && xmaStates[2].mcSlow > xmaStates[2].mcFast + // + // Check Market Middleage Cross Over MC Slow ... + && isMarketMiddleageTrendUp + // + // Check distance between Medium Cycle Market + && isMarketMiddleCrossOverMCSlow + // && xmaStates[0].marketMiddleage > xmaStates[0].mcSlow + // && MathAbs(xmaStates[1].marketMiddleage - xmaStates[2].mcSlow) > _Point + // + // IMPORTANT: by passing this condition i can Increase r2r ration ... + // && xmaStates[0].marketMiddleage > xmaStates[1].marketMiddleage + && MathAbs(xmaStates[1].marketMiddleage - xmaStates[2].marketMiddleage) > _Point + // + // OSC ... + && oscStates[1].fastOSC > 0.5 + && !isOSCPowerTrendDown + && oscStates[1].powerOSC > 0 + // + // PRICE ... + && !isSharpBullishHappens + && longEntryPrice < marketHigh[0] + && marketHigh[0] > marketHigh[1] + && marketHigh[0] > marketHigh[2] + ; + + // + bool oscHasLongSignal = + // + false + // + // OSC ... + // + // Check osc is Trending Up ... + // isOSCTrendUp + // + // Check osc fast cross over slow ... + // isOSCFastCrossOverSlow + // + // Check OSC Market not Ranging ... + // && !isOSCMarketRanging + // + // Check OSC Fast bigger than 0.5 ... + // && oscStates[1].fastOSC > 0.5 + // && oscStates[1].slowOSC > 0.5 + // + // PRICE ... + // && !isSharpBullishHappens + // && longEntryPrice < marketHigh[0] + // && marketHigh[0] > marketHigh[1] + // && marketHigh[0] > marketHigh[2] + ; + + // + bool hasLongSignal = + xmaHasLongSignal + || + oscHasLongSignal + ; +``` + +```mql4 + // + bool hasLongSignal = + // + // Global ... + true + // + && + // XMA ... + // + // Check Parabolic Sar Cross Under Market Middleage + // Or Trending Down ... + isParabolicCrossUnderMarketMiddle + && + // + // Check PSar Value is Bigger Than Market Middleage ... + xmaStates[1].parabolicSAR < xmaStates[1].marketMiddleage + && + // + // Check Parabolic Revrse Change bigger than Prev Cancle Close ... + xmaStates[1].parabolicSAR < MathMin(marketOpen[1], marketClose[1]) + && + // + // Now We Have Separate our Conditions based on + // Market Trends ... + // + // Medium Cycle Market Trends Up ... + isMCTrendUp + ? + ( + // + // Market Middle must be in Trending Up ... + isMarketMiddleageTrendUp + && + // + // Market Middle Must be less than Maximum in Cycle ... + xmaStates[1].marketMiddleage < marketMiddlesMinMax.max + && + // + // Market Middleage must be above of MC Fast ... + xmaStates[1].marketMiddleage > xmaStates[1].mcFast + && + // + // Check Distance between SC Fast and Market Middle ... + MathAbs(xmaStates[1].scFast - xmaStates[1].scSlow) > (3 * _Point) + // + // Minimum Signal Power of OSC ... + // MathAbs(oscStates[1].powerOSC > minPowOSC) + ) + : + // + // Medium Cycle Market Trends Down ... + false + // () + ; +``` + +```mql4 + // + // Based On MC Market Trend Up ... + // + // Based On MC Market Down Trend ... + // isMCTrendDown + // || isMCFastCrossUnderSlow + // ? + // ( + // + // Find SC Fast Cross Over SC Slow, which happens betweentwo of SC Fast Under SC Slow ... + // isSCFastCrossOverSlow + + // // + // // Find the Moment which Market Middleage Cross Over MC Fast ... + // isMarketMiddleCrossOverMCFast + // // + // // Check Parabolix SAR for Long Trades ... + // && xmaStates[0].parabolicSAR < xmaStates[0].marketMiddleage + // && xmaStates[1].parabolicSAR < xmaStates[1].marketMiddleage + // // + // // Check Market Middle and Parabolic SAR Distance ... + // && MathAbs(xmaStates[1].marketMiddleage - xmaStates[1].parabolicSAR) >= 1 + // // + // // Check Distance between MCSlow and MCFast bigger than MarketMiddle and Parabolic SAR ... + // && MathAbs(xmaStates[1].mcFast - xmaStates[1].mcSlow) > MathAbs(xmaStates[1].marketMiddleage - xmaStates[1].parabolicSAR) + // ) + // : + // // + // // Based On MC Market Up Trend ... + // false +``` + +```mql4 + // + oscHasLongSignal = + // + oscStates[0].fastOSC > oscStates[0].slowOSC + && ( + ( + oscStates[0].fastOSC > 0.5 + && oscStates[0].fastOSC < 0.75 + ) + || oscStates[0].fastOSC <= 0.5 + ) + && ( + oscStates[0].powerOSC > 0 + || oscStates[1].powerOSC > 0 + ) + // + && xmaStates[0].scFast > xmaStates[0].marketMiddleage + && MathAbs(xmaStates[0].scFast - xmaStates[0].marketMiddleage) > (20 * _Point) + // + && xmaStates[1].scFast > xmaStates[1].marketMiddleage + && MathAbs(xmaStates[1].scFast - xmaStates[1].marketMiddleage) > (20 * _Point) + // + && xmaStates[2].scFast > xmaStates[2].marketMiddleage + // + && xmaStates[0].mcFast > xmaStates[0].mcSlow + && MathAbs(xmaStates[0].mcFast - xmaStates[0].mcSlow) > (50 * _Point) + // + && xmaStates[0].mcFast < xmaStates[0].scFast + && xmaStates[0].mcFast < xmaStates[0].parabolicSAR + // + && xmaStates[0].parabolicSAR < xmaStates[0].marketMiddleage + && xmaStates[1].parabolicSAR < xmaStates[1].marketMiddleage + // + && !isSharpBullishHappens + // + && longEntryPrice > xmktStates[0].highestLow + && longEntryPrice > xmaStates[0].marketMiddleage + // + && xmktStates[0].highestLow > xmaStates[0].scFast + && xmktStates[0].lowestHigh < xmaStates[0].scFast + && xmktStates[0].lowestHigh < xmaStates[0].marketMiddleage + ; +``` + +```mql4 +``` + +```mql4 +``` + +```mql4 +``` + +```mql4 +``` + +```mql4 +``` + +```mql4 +``` + +```mql4 +``` + +```mql4 +``` + +```mql4 +``` + +```mql4 +``` + +```mql4 +``` diff --git a/Docs/x-saherelm.ea.x.full.set b/Docs/x-saherelm.ea.x.full.set new file mode 100644 index 0000000..31d34d3 --- /dev/null +++ b/Docs/x-saherelm.ea.x.full.set @@ -0,0 +1,276 @@ +signalPrefix=XST_EA +bullishSignalLabel=X_BUY +bullishSignalColor=16776960 +bearishSignalLabel=X_SELL +bearishSignalColor=16711935 +signalEntryColor=13959039 +signalSLColor=255 +signalTPColor=32768 +candleGapBetweenSignals=7 +candleGapBetweenSignals,F=0 +candleGapBetweenSignals,1=6 +candleGapBetweenSignals,2=0 +candleGapBetweenSignals,3=0 +allowTrade=1 +allowTrade,F=0 +allowTrade,1=0 +allowTrade,2=1 +allowTrade,3=1 +allowLongTrades=1 +allowLongTrades,F=0 +allowLongTrades,1=0 +allowLongTrades,2=1 +allowLongTrades,3=1 +allowShortTrades=1 +allowShortTrades,F=0 +allowShortTrades,1=0 +allowShortTrades,2=1 +allowShortTrades,3=1 +alertEvents=1 +alertEvents,F=0 +alertEvents,1=0 +alertEvents,2=1 +alertEvents,3=1 +alertPositions=1 +alertPositions,F=0 +alertPositions,1=0 +alertPositions,2=1 +alertPositions,3=1 +longPositionAlerts=1 +longPositionAlerts,F=0 +longPositionAlerts,1=0 +longPositionAlerts,2=1 +longPositionAlerts,3=1 +shortPositionAlerts=1 +shortPositionAlerts,F=0 +shortPositionAlerts,1=0 +shortPositionAlerts,2=1 +shortPositionAlerts,3=1 +terminalAlert=0 +terminalAlert,F=0 +terminalAlert,1=0 +terminalAlert,2=1 +terminalAlert,3=1 +pushAlert=0 +pushAlert,F=0 +pushAlert,1=0 +pushAlert,2=1 +pushAlert,3=1 +lotsPerTradePercent=0.00001000 +lotsPerTradePercent,F=0 +lotsPerTradePercent,1=0.00030000 +lotsPerTradePercent,2=0.00000000 +lotsPerTradePercent,3=0.00000000 +maxOpenTrades=4 +maxOpenTrades,F=0 +maxOpenTrades,1=4 +maxOpenTrades,2=0 +maxOpenTrades,3=0 +maxDrawdownPercentPerPTrade=0.01500000 +maxDrawdownPercentPerPTrade,F=0 +maxDrawdownPercentPerPTrade,1=0.30000000 +maxDrawdownPercentPerPTrade,2=0.00000000 +maxDrawdownPercentPerPTrade,3=0.00000000 +minBalancePercent=0.50000000 +minBalancePercent,F=0 +minBalancePercent,1=0.50000000 +minBalancePercent,2=0.00000000 +minBalancePercent,3=0.00000000 +maxEquityPercent=0.10000000 +maxEquityPercent,F=0 +maxEquityPercent,1=0.10000000 +maxEquityPercent,2=0.00000000 +maxEquityPercent,3=0.00000000 +xStarter=- X Signal Provider - +enableXSignalling=1 +enableXSignalling,F=0 +enableXSignalling,1=0 +enableXSignalling,2=1 +enableXSignalling,3=1 +xShortR2R=2.50000000 +xShortR2R,F=0 +xShortR2R,1=2.50000000 +xShortR2R,2=0.00000000 +xShortR2R,3=0.00000000 +xShortLotsPerTradePercent=0.00002000 +xShortLotsPerTradePercent,F=0 +xShortLotsPerTradePercent,1=0.00002000 +xShortLotsPerTradePercent,2=0.00000000 +xShortLotsPerTradePercent,3=0.00000000 +xShortMaxDrawdownPerTradePercent=0.04000000 +xShortMaxDrawdownPerTradePercent,F=0 +xShortMaxDrawdownPerTradePercent,1=0.02000000 +xShortMaxDrawdownPerTradePercent,2=0.00000000 +xShortMaxDrawdownPerTradePercent,3=0.00000000 +xLongR2R=2.50000000 +xLongR2R,F=0 +xLongR2R,1=2.50000000 +xLongR2R,2=0.00000000 +xLongR2R,3=0.00000000 +xLongLotsPerTradePercent=0.00002000 +xLongLotsPerTradePercent,F=0 +xLongLotsPerTradePercent,1=0.00002000 +xLongLotsPerTradePercent,2=0.00000000 +xLongLotsPerTradePercent,3=0.00000000 +xLongMaxDrawdownPerTradePercent=0.04000000 +xLongMaxDrawdownPerTradePercent,F=0 +xLongMaxDrawdownPerTradePercent,1=0.02000000 +xLongMaxDrawdownPerTradePercent,2=0.00000000 +xLongMaxDrawdownPerTradePercent,3=0.00000000 +xMaximumCandlesPerTrade=206 +xMaximumCandlesPerTrade,F=0 +xMaximumCandlesPerTrade,1=504 +xMaximumCandlesPerTrade,2=0 +xMaximumCandlesPerTrade,3=0 +xOscillatorLength=7 +xOscillatorLength,F=0 +xOscillatorLength,1=7 +xOscillatorLength,2=0 +xOscillatorLength,3=0 +xPSarStep=0.02000000 +xPSarStep,F=0 +xPSarStep,1=0.02000000 +xPSarStep,2=0.00000000 +xPSarStep,3=0.00000000 +xPSarMaximum=0.20000000 +xPSarMaximum,F=0 +xPSarMaximum,1=0.20000000 +xPSarMaximum,2=0.00000000 +xPSarMaximum,3=0.00000000 +xRangeMarketLength=5 +xRangeMarketLength,F=0 +xRangeMarketLength,1=35 +xRangeMarketLength,2=0 +xRangeMarketLength,3=0 +xSwingLength=7 +xSwingLength,F=0 +xSwingLength,1=7 +xSwingLength,2=0 +xSwingLength,3=0 +xRStarter=- XR Signal Provider - +enableXRSignalling=0 +enableXRSignalling,F=0 +enableXRSignalling,1=0 +enableXRSignalling,2=1 +enableXRSignalling,3=1 +xRShortR2R=2.00000000 +xRShortR2R,F=0 +xRShortR2R,1=2.00000000 +xRShortR2R,2=0.00000000 +xRShortR2R,3=0.00000000 +xRShortLotsPerTradePercent=0.00001000 +xRShortLotsPerTradePercent,F=0 +xRShortLotsPerTradePercent,1=0.00001000 +xRShortLotsPerTradePercent,2=0.00000000 +xRShortLotsPerTradePercent,3=0.00000000 +xRShortMaxDrawdownPerTradePercent=0.01000000 +xRShortMaxDrawdownPerTradePercent,F=0 +xRShortMaxDrawdownPerTradePercent,1=0.01000000 +xRShortMaxDrawdownPerTradePercent,2=0.00000000 +xRShortMaxDrawdownPerTradePercent,3=0.00000000 +xRLongR2R=2.00000000 +xRLongR2R,F=0 +xRLongR2R,1=2.00000000 +xRLongR2R,2=0.00000000 +xRLongR2R,3=0.00000000 +xRLongLotsPerTradePercent=0.00001000 +xRLongLotsPerTradePercent,F=0 +xRLongLotsPerTradePercent,1=0.00001000 +xRLongLotsPerTradePercent,2=0.00000000 +xRLongLotsPerTradePercent,3=0.00000000 +xRLongMaxDrawdownPerTradePercent=0.01000000 +xRLongMaxDrawdownPerTradePercent,F=0 +xRLongMaxDrawdownPerTradePercent,1=0.01000000 +xRLongMaxDrawdownPerTradePercent,2=0.00000000 +xRLongMaxDrawdownPerTradePercent,3=0.00000000 +xRMaximumCandlesPerTrade=252 +xRMaximumCandlesPerTrade,F=0 +xRMaximumCandlesPerTrade,1=252 +xRMaximumCandlesPerTrade,2=0 +xRMaximumCandlesPerTrade,3=0 +xROscillatorLength=7 +xROscillatorLength,F=0 +xROscillatorLength,1=7 +xROscillatorLength,2=0 +xROscillatorLength,3=0 +xRFastLength=20 +xRFastLength,F=0 +xRFastLength,1=20 +xRFastLength,2=0 +xRFastLength,3=0 +xRSlowLength=50 +xRSlowLength,F=0 +xRSlowLength,1=50 +xRSlowLength,2=0 +xRSlowLength,3=0 +xRRangeMarketLength=50 +xRRangeMarketLength,F=0 +xRRangeMarketLength,1=50 +xRRangeMarketLength,2=0 +xRRangeMarketLength,3=0 +xRSwingLength=7 +xRSwingLength,F=0 +xRSwingLength,1=7 +xRSwingLength,2=0 +xRSwingLength,3=0 +xTPWStarter=- XTPW Signal Provider - +enableXTPWSignalling=0 +enableXTPWSignalling,F=0 +enableXTPWSignalling,1=0 +enableXTPWSignalling,2=1 +enableXTPWSignalling,3=1 +xTPWShortR2R=1.50000000 +xTPWShortR2R,F=0 +xTPWShortR2R,1=1.50000000 +xTPWShortR2R,2=0.00000000 +xTPWShortR2R,3=0.00000000 +xTPWShortLotsPerTradePercent=0.00001000 +xTPWShortLotsPerTradePercent,F=0 +xTPWShortLotsPerTradePercent,1=0.00001000 +xTPWShortLotsPerTradePercent,2=0.00000000 +xTPWShortLotsPerTradePercent,3=0.00000000 +xTPWShortMaxDrawdownPerTradePercent=0.01000000 +xTPWShortMaxDrawdownPerTradePercent,F=0 +xTPWShortMaxDrawdownPerTradePercent,1=0.01000000 +xTPWShortMaxDrawdownPerTradePercent,2=0.00000000 +xTPWShortMaxDrawdownPerTradePercent,3=0.00000000 +xTPWLongR2R=1.50000000 +xTPWLongR2R,F=0 +xTPWLongR2R,1=1.50000000 +xTPWLongR2R,2=0.00000000 +xTPWLongR2R,3=0.00000000 +xTPWLongLotsPerTradePercent=0.00001000 +xTPWLongLotsPerTradePercent,F=0 +xTPWLongLotsPerTradePercent,1=0.00001000 +xTPWLongLotsPerTradePercent,2=0.00000000 +xTPWLongLotsPerTradePercent,3=0.00000000 +xTPWLongMaxDrawdownPerTradePercent=0.01000000 +xTPWLongMaxDrawdownPerTradePercent,F=0 +xTPWLongMaxDrawdownPerTradePercent,1=0.01000000 +xTPWLongMaxDrawdownPerTradePercent,2=0.00000000 +xTPWLongMaxDrawdownPerTradePercent,3=0.00000000 +xTPWMaximumCandlesPerTrade=206 +xTPWMaximumCandlesPerTrade,F=0 +xTPWMaximumCandlesPerTrade,1=206 +xTPWMaximumCandlesPerTrade,2=0 +xTPWMaximumCandlesPerTrade,3=0 +xTPWPSarStep=0.02000000 +xTPWPSarStep,F=0 +xTPWPSarStep,1=0.02000000 +xTPWPSarStep,2=0.00000000 +xTPWPSarStep,3=0.00000000 +xTPWPSarMaximum=0.20000000 +xTPWPSarMaximum,F=0 +xTPWPSarMaximum,1=0.20000000 +xTPWPSarMaximum,2=0.00000000 +xTPWPSarMaximum,3=0.00000000 +xTPWSwingLength=7 +xTPWSwingLength,F=0 +xTPWSwingLength,1=7 +xTPWSwingLength,2=0 +xTPWSwingLength,3=0 +xTPWSharpDetectionFactor=700.00000000 +xTPWSharpDetectionFactor,F=0 +xTPWSharpDetectionFactor,1=700.00000000 +xTPWSharpDetectionFactor,2=0.00000000 +xTPWSharpDetectionFactor,3=0.00000000 diff --git a/Experts/x-saherelm.ea.mq4 b/Experts/x-saherelm.ea.mq4 new file mode 100644 index 0000000..7af93af --- /dev/null +++ b/Experts/x-saherelm.ea.mq4 @@ -0,0 +1,1116 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XST Strategy Expert Advisor +// --------------------------------------------- +// saherelm implementation of strategy expert advisor ... +// in this EA, we try to combine multiple tools, to ashive best +// results ... +// +// ShortName: XST +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +989121694056 +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XST Strategy Expert Advisor" +#property strict + +// +// START Inputs ... +// +// +// Signal Prefixe ... +input string signalPrefix = "XST_EA"; // Signal Prefix + +// +// Signal Draw Specifications ... +input string bullishSignalLabel = "X_BUY"; // Bullish Signal Label +input color bullishSignalColor = clrAqua; // Bullish Signal Color + +// +input string bearishSignalLabel = "X_SELL"; // Bearish Signal Label +input color bearishSignalColor = clrFuchsia; // Bearish Signal Color + +// +input color signalEntryColor = clrAquamarine; // Signal Entry Ptice Color +input color signalSLColor = clrRed; // Signal SL Color +input color signalTPColor = clrGreen; // Signal TP Color + +// +input int candleGapBetweenSignals = 7; // How many Candle waits to new Signal from last one + +// +// Trade ... +input bool allowTrade = true; // Allow Trade Based on given Signals +input bool allowLongTrades = true; // Allow Long Trades +input bool allowShortTrades = true; // Allow Short Trades + +// +// Balance and Finanical Specifications ... +input double lotsPerTradePercent = 0.00001; // Lots Per Trade Percent +input int maxOpenTrades = 4; // Maximum Open Trade +input double maxDrawdownPercentPerPTrade = 0.1; // Maximum DrawDown Per Trade +input double minBalancePercent = 0.5; // Minimum Balance for Trading +input double maxEquityPercent = 0.1; // Maximum Trade Equity + +// +// START Global Definitions: Variables, Properties and etc ... +// +int lastSignalledBar = 0; + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// TODO: Complete this ... +// Include Dialog Handler ... +// #include "../Libraries/x-saherelm.dialog.mq4" + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.signal.lib.mq4" + +// +// Add Logging Inputs ... +// +input string xAlertingLabel = "- Alerts -"; // --> Alerts <-- + +// +// Alerts ... + +// +// Alert Bot Events ... +input bool logEvents = true; // Log Events +input bool alertEvents = true; // Alert Events + +// +// Alert Types ... +input bool terminalAlert = false; // Terminal Alert +input bool pushAlert = false; // Push Notification Alerts + +// +// Positions ... +input bool alertPositions = true; // Alert Positions +input bool longPositionAlerts = true; // Alert Long Positions +input bool shortPositionAlerts = true; // Alert Short Positions + +// +input bool enableNewDayAlert = true; // New Day Alert +input bool enableNewHourAlert = true; // New Hour Alert + +// +int maxMarketLength = 0; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Validate Inputs ... + bool inputsNotValiid = + // + // EA ... + maxOpenTrades <= 0 + || maxEquityPercent < 0 + || minBalancePercent < 0 + || lotsPerTradePercent < 0 + || maxDrawdownPercentPerPTrade < 0 + ; + + // + if (inputsNotValiid) { + return INIT_PARAMETERS_INCORRECT; + } + + // + totalSignals = 0; + totalLongSignals = 0; + totalShortSignals = 0; + + // + initialBalance = 0; + + // + // START Define Array Series ... + // + // + // END Define Array Series ... + // + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "XST"; + + // + ClearSignalConditions(); + + // + maxMarketLength = MathMax(0, GetDailyCandleCount()); + + // + // TODO: Complete this ... + // try to Create App Window ... + // CreateDialog(logTag); + + // + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) { + // + // TODO: Complete this ... + // Destroy Dialog ... + // DestroyDialog(reason); +} + +// +// Handling Chart Events ... +void OnChartEvent( + const int id, // event ID + const long& lparam, // event parameter of the long type + const double& dparam, // event parameter of the double type + const string& sparam // event parameter of the string type +) { + // + // TODO: Complete this ... + // DialogChartEvent( + // id, + // lparam, + // dparam, + // sparam + // ); +} + +// +// Ticker Event Handler ... +void OnTick() { + // + isNewDay = IsNewDay(); + if ( + isNewDay + && enableNewDayAlert + ) { + // + SendAlert( + StringConcatenate( + "New Day ..." + ) + ); + } + + // + isNewHour = IsNewHour(); + if ( + isNewHour + && enableNewHourAlert + ) { + // + SendAlert( + StringConcatenate( + "New Hour ..." + ) + ); + } + + // + // Process Signals to Open Positions ... + ProcessSignals(); + + // + // Checking State for Signal Handling ... + CheckState(); + + // + // Process Open Positions for Trailing Stop Loss or Close ... + ProcessOpenPositions(); +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Check State for Signal Handling ... +void CheckState() { + // + // Here we Must to Check Market State for enable or disable + // Signal Handlers and also make dection to close all long/short + // trades ... +} + +// +// Calculate Signals and Process Based on Exists Signals ... +void ProcessSignals() { + // + XSignalRequest request = {}; + request.type = X_SIGNAL_NONE; + request.hasSignal = false; + + // + // Prevent Multiple Calculating on Same Bars ... + isNewBar = IsNewBar(); + if (isNewBar) { + countedBars++; + } + + // + if (countedBars < maxMarketLength) { + return; + } + + // + bool allowDoTrade = true; + + // + // Check Balance ... + if (initialBalance > 0) { + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double minimumBalanceForTrade = + balance > initialBalance + ? + minBalancePercent * balance + : + minBalancePercent * initialBalance; + + // + // Retrieve Account Equity ... + double equity = AccountInfoDouble(ACCOUNT_EQUITY); + double maxAllowedEquity = balance - (balance * maxEquityPercent); + + // + // Retrieve Free Marigin ... + double freeMargin = AccountFreeMargin(); + double maximumMariginRisk = balance - (balance * maxEquityPercent); + + // + if ( + // + // Do not Open Positions if equity not passed ... + equity < maxAllowedEquity || + // + // Do not Open Positions if free margin not passed ... + freeMargin <= maximumMariginRisk || + // + // Do not open positions if balance less than minimum ... + balance <= minimumBalanceForTrade + ) { + // + static bool tradingPauseAlerted; + + // + allowDoTrade = false; + + // + if (!tradingPauseAlerted) { + // + string message = StringConcatenate( + "Trading Pause => ", + "Balance: ", balance, + ", Equity: ", equity, + ", FreeMargin: ", freeMargin + ); + + // + LogMessage(message); + SendAlert(message); + + // + tradingPauseAlerted = true; + } + } + } + + // + // Retrieve Signal Exists ... + request = GenerateSignal(0); + + // + // Prevent doing anything else, if there is no signals ... + if ( + !allowDoTrade || + !request.hasSignal || + request.type == X_SIGNAL_NONE + ) { + return; + } + + // + bool hasLongSignal = request.type == X_SIGNAL_LONG; + + // + // Check last Signalled Bar with Counted Bars ... + // Prevent Multiple Signalling on Same Bar ... + bool isInLastSignalledBars = false; + for (int i=0; i < candleGapBetweenSignals; i++) { + // + isInLastSignalledBars = + isInLastSignalledBars + || lastSignalledBar == countedBars - i + ; + } + if (isInLastSignalledBars) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + return; + } + + // + // increase last signalled bar ... + lastSignalledBar = countedBars; + + // + // Calculate Can Trade or not ... + allowDoTrade = allowTrade + && ( + hasLongSignal ? + allowLongTrades : + allowShortTrades + ); + + // + // Chack Maximum Open Positions ... + int openTrades = CountOpenTrades(); + if (maxOpenTrades > 0) { + // + if (openTrades >= maxOpenTrades) { + // + allowDoTrade = false; + + // + if (!allowDoTrade) { + // + string message = StringConcatenate( + "Trading Pause => ", + "Max Open Trades (", + maxOpenTrades, + ") reached ..." + ); + + // + LogMessage(message); + SendAlert(message); + } + } + } + + // + // Check Trading is Enable or not ... + // nothing to do if trading is disabled ... + if (!allowDoTrade) { + // + // Clear Signal Conditions ... + if (hasLongSignal) { + ClearLongSignalConditions(); + } else { + ClearShortSignalConditions(); + } + + // + string message = StringConcatenate( + "Trading Not Allowed ..." + ); + + // + LogMessage(message); + SendAlert(message); + return; + } + + // + // Retrieve Signal Lots Per Trade ... + double lPTradePercent = GetSignalLottage( + request.signal, + lotsPerTradePercent + ); + + // + bool isPositionOpened = TradeSignal( + request.signal, + lPTradePercent, + // + bullishSignalLabel, + bullishSignalColor, + bearishSignalLabel, + bearishSignalColor + ); + + // + totalSignals++; + if (hasLongSignal) { + // + totalLongSignals++; + ClearLongSignalConditions(); + } else { + // + totalShortSignals++; + ClearShortSignalConditions(); + } + + // + if (isPositionOpened) { + // + bool canAlert = + alertPositions + && ( + hasLongSignal ? + longPositionAlerts + : + shortPositionAlerts + ); + + // + if (canAlert) { + // + // Alert Message ... + string message = StringConcatenate( + "Trade on Signal ID: ", request.signal.id, + ", ProvidedBy: ", GetSignalProviderIdentifier(request.signal.provider), + ", Entry: ", request.signal.entry, + ", TP: ", request.signal.tp + ); + + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } + } + } +} + +// +// Process All Open Positions ... +void ProcessOpenPositions() { + // + // XSignalling ... + if (enableXSignalling) { + // + // Close All XXX Provided Signals on it's Specific Condition ... + if (xCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XXX_PROVIDER); + + // + xCloseLongTrades = false; + } + + // + if (xCloseShortTrades) { + // + CloseAllProviderShortTrades(X_XTPW_PROVIDER); + + // + xCloseShortTrades = false; + } + + // + // Close Maximum DrawDown Passed Trades ... + + // + // Longs ... + bool hasClosedLongInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xLongMaxDrawdownPerTradePercent, + X_SIGNAL_LONG, + X_XXX_PROVIDER + ); + + // + // Shorts ... + bool hasClosedShortInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xShortMaxDrawdownPerTradePercent, + X_SIGNAL_SHORT, + X_XXX_PROVIDER + ); + + // + // Close All Long Time Trades based on Provider provided Length ... + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + xMaximumCandlesPerTrade, + X_XXX_PROVIDER + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedLongInDrawDownLongTrade + || hasClosedShortInDrawDownLongTrade + ) { + xFailedSignals++; + } + } + + // + // XR Signalling ... + if (enableXRSignalling) { + // + if (xRCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XR_PROVIDER); + + // + xRCloseLongTrades = false; + } + + // + if (xRCloseShortTrades) { + // + CloseAllProviderShortTrades(X_XR_PROVIDER); + + // + xRCloseShortTrades = false; + } + + // + // Close Maximum DrawDown Passed Trades ... + + // + // Longs ... + bool hasClosedLongInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xRLongMaxDrawdownPerTradePercent, + X_SIGNAL_LONG, + X_XR_PROVIDER + ); + + // + // Shorts ... + bool hasClosedShortInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xRShortMaxDrawdownPerTradePercent, + X_SIGNAL_SHORT, + X_XR_PROVIDER + ); + + // + // Close All Long Time Trades based on Provider provided Length ... + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + xRMaximumCandlesPerTrade, + X_XR_PROVIDER + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedLongInDrawDownLongTrade + || hasClosedShortInDrawDownLongTrade + ) { + xRFailedSignals++; + } + } + + // + // XTPW Signalling ... + if (enableXTPWSignalling) { + // + if (xTPWCloseLongTrades) { + // + CloseAllProviderLongTrades(X_XTPW_PROVIDER); + + // + xTPWCloseLongTrades = false; + } + + // + if (xTPWCloseShortTrades) { + // + CloseAllProviderShortTrades(X_XTPW_PROVIDER); + + // + xTPWCloseShortTrades = false; + } + + // + // Close Maximum DrawDown Passed Trades ... + + // + // Longs ... + bool hasClosedLongInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xTPWLongMaxDrawdownPerTradePercent, + X_SIGNAL_LONG, + X_XTPW_PROVIDER + ); + + // + // Shorts ... + bool hasClosedShortInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + xTPWShortMaxDrawdownPerTradePercent, + X_SIGNAL_SHORT, + X_XTPW_PROVIDER + ); + + // + // Close All Long Time Trades based on Provider provided Length ... + bool hasClosedLongTimeTrade = CloseAllLongTimeTrades( + xTPWMaximumCandlesPerTrade, + X_XTPW_PROVIDER + ); + + // + if ( + hasClosedLongTimeTrade + || hasClosedLongInDrawDownLongTrade + || hasClosedShortInDrawDownLongTrade + ) { + xTPWFailedSignals++; + } + } + + // + // Close Maximum DrawDown Passed Trades ... + // this is the Maximum Controller ... + // + double maxOfXPercent = enableXSignalling ? + MathMax( + xLongMaxDrawdownPerTradePercent, + xShortMaxDrawdownPerTradePercent + ) : 0 + ; + + // + double maxOfXRPercent = enableXRSignalling ? + MathMax( + xRLongMaxDrawdownPerTradePercent, + xRShortMaxDrawdownPerTradePercent + ) : 0 + ; + + // + double maxOfXTPWPercent = enableXTPWSignalling ? + MathMax( + xTPWLongMaxDrawdownPerTradePercent, + xTPWShortMaxDrawdownPerTradePercent + ) : 0 + ; + + // + double maxDrawDownPercent = MathMax( + maxOfXPercent, + maxOfXRPercent + ); + maxDrawDownPercent = MathMax( + maxDrawDownPercent, + maxOfXTPWPercent + ); + maxDrawDownPercent = MathMax( + maxDrawDownPercent, + maxDrawdownPercentPerPTrade + ); + + // + // we Calculate Max DrawDown Percent Per Trade ... + // then try to Close based on them ... + bool hasClosedInDrawDownLongTrade = CloseAllMaximumDrawDownPassedTrades( + maxDrawDownPercent + ); +} + +// +// Send Special Type of Alerts ... +void SendAlert(string message) { + // + if ( + !logEvents + && !alertEvents + ) { + return; + } + + // + // Log Handling ... + if (logEvents) { + LogMessage(message); + } + + // + // Alert Handling ... + if (alertEvents) { + // + // Terminal Alert ... + if (terminalAlert) { + Alert(message); + } + + // + // Push Alert ... + if (pushAlert) { + SendNotification(message); + } + } +} +// +// END Functions ... +// + +// +// +// Calculate Signal ... +// in this function we calculate a signal exists in +// specific bar or not ... +XSignalRequest GenerateSignal( + const int bar_index // Bar Index ... +) { + // + // create temp result ... + XSignalRequest result = {}; + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + bool hasSignal = false; + bool hasLongSignal = false; + bool hasShortSignal = false; + + // + XSignal signal = {}; + + // + // Define Template Signal Requests for Managing Multiple Signals ... + // + // X ... + XSignalRequest xLongSignalRequest = {}; + XSignalRequest xShortSignalRequest = {}; + // + // XR ... + XSignalRequest xrLongSignalRequest = {}; + XSignalRequest xrShortSignalRequest = {}; + // + // XTPW ... + XSignalRequest xTPWLongSignalRequest = {}; + XSignalRequest xTPWShortSignalRequest = {}; + + // + // START XR Signal Handler ... + // + // + if (enableXRSignalling) { + // + CheckXRSignalHandler( + bar_index + ); + + // + // Long Trades ... + if (allowTrade && allowLongTrades) { + // + if (xRWaitForLongSignals) { + // + CheckXRLongSignalConditions( + bar_index + ); + + // + xrLongSignalRequest = GenerateXRSignal( + X_SIGNAL_LONG, + signalPrefix, + bar_index + ); + + // + if (xrLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXRSignals( + xrLongSignalRequest.signal + ); + + // + if (isReady && xRWaitForLongSignals) { + // + hasLongSignal = true; + signal = xrLongSignalRequest.signal; + } else { + ClearXRLongSignalConditions(); + } + } + } else { + ClearXRLongSignalConditions(); + } + } + + // + // Short Trades ... + if (allowTrade && allowShortTrades) { + // + if (xRWaitForShortSignals) { + // + CheckXRShortSignalConditions( + bar_index + ); + + // + xrShortSignalRequest = GenerateXRSignal( + X_SIGNAL_SHORT, + signalPrefix, + bar_index + ); + + // + if (xrShortSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXRSignals( + xrShortSignalRequest.signal + ); + + // + if (isReady && xRWaitForShortSignals) { + // + hasShortSignal = true; + signal = xrShortSignalRequest.signal; + } else { + ClearXRShortSignalConditions(); + } + } + } else { + ClearXRShortSignalConditions(); + } + } + } + // + // END XR Signal Handler ... + // + + // + // START XTPW Signal Handler ... + // + if (enableXTPWSignalling) { + // + CheckXTPWSignalHandler( + bar_index + ); + + // + // Long Trades ... + if (allowTrade && allowLongTrades) { + // + if (xTPWWaitForLongSignals) { + // + CheckXTPWLongSignalConditions( + bar_index + ); + + // + xTPWLongSignalRequest = GenerateXTPWSignal( + X_SIGNAL_LONG, + signalPrefix, + bar_index + ); + + // + if (xTPWLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXTPWSignals( + xTPWLongSignalRequest.signal + ); + + // + if (isReady && xTPWWaitForLongSignals) { + // + hasLongSignal = true; + signal = xTPWLongSignalRequest.signal; + } else { + ClearXTPWLongSignalConditions(); + } + } + } else { + ClearXTPWLongSignalConditions(); + } + } + + // + // Short Trades ... + if (allowTrade && allowShortTrades) { + // + if (xTPWWaitForShortSignals) { + // + CheckXTPWShortSignalConditions( + bar_index + ); + + // + xTPWShortSignalRequest = GenerateXTPWSignal( + X_SIGNAL_SHORT, + signalPrefix, + bar_index + ); + + // + if (xTPWShortSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXTPWSignals( + xTPWShortSignalRequest.signal + ); + + // + if (isReady && xTPWWaitForShortSignals) { + // + hasShortSignal = true; + signal = xTPWShortSignalRequest.signal; + } else { + ClearXTPWShortSignalConditions(); + } + } + } else { + ClearXTPWShortSignalConditions(); + } + } + } + // + // END XTPW Signal Handler ... + // + + // + // START X Signal Handler ... + // + // + if (enableXSignalling) { + // + CheckXSignalHandler( + bar_index + ); + + // + // Long Trades ... + if (allowTrade && allowLongTrades) { + // + if (xWaitForLongSignals) { + // + CheckXLongSignalConditions( + bar_index + ); + + // + xLongSignalRequest = GenerateXSignal( + X_SIGNAL_LONG, + signalPrefix, + bar_index + ); + + // + if (xLongSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXSignals( + xLongSignalRequest.signal + ); + + // + if (isReady && xWaitForLongSignals) { + // + hasLongSignal = true; + signal = xLongSignalRequest.signal; + } else { + ClearXLongSignalConditions(); + } + } + } else { + ClearXLongSignalConditions(); + } + } + + // + // Short Trades ... + if (allowTrade && allowShortTrades) { + // + if (xWaitForShortSignals) { + // + CheckXShortSignalConditions( + bar_index + ); + + // + xShortSignalRequest = GenerateXSignal( + X_SIGNAL_SHORT, + signalPrefix, + bar_index + ); + + // + if (xShortSignalRequest.hasSignal) { + // + // Here we can Check and Filter Signals Based On State ... + bool isReady = IsReadyForXSignals( + xShortSignalRequest.signal + ); + + // + if (isReady && xWaitForShortSignals) { + // + hasShortSignal = true; + signal = xShortSignalRequest.signal; + } else { + ClearXShortSignalConditions(); + } + } + } else { + ClearXShortSignalConditions(); + } + } + } + // + // END XR Signal Handler ... + // + + // + hasSignal = hasLongSignal || hasShortSignal; + + // + if (!hasSignal) { + // + signal.type = X_SIGNAL_NONE; + result.type = X_SIGNAL_NONE; + } + + // + // Normalize TP, SL and Entry Price ... + signal.tp = NormalizeDouble(signal.tp, _Digits); + signal.sl = NormalizeDouble(signal.sl, _Digits); + signal.entry = NormalizeDouble(signal.entry, _Digits); + + // + result.signal = signal; + result.type = signal.type; + result.hasSignal = hasSignal; + result.provider = signal.provider; + + // + // Return Result ... + return result; +} diff --git a/Indicators/x-saherelm.ma.mq4 b/Indicators/x-saherelm.ma.mq4 new file mode 100644 index 0000000..e3a5737 --- /dev/null +++ b/Indicators/x-saherelm.ma.mq4 @@ -0,0 +1,173 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MA Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 MA Indicator" +#property strict + +// +// START Inputs ... +// +// +// Fast MA ... +input int maLength = 20; // MA Length +input int maShift = 0; // MA Shift +input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method +input ENUM_APPLIED_PRICE maAppliedPrice = PRICE_CLOSE; // MA Applied Price + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 1 + +// +#property indicator_plots 1 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Fast Ma Buffer ... +#property indicator_label1 "Ma" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrYellow +#property indicator_style1 STYLE_DOT +#property indicator_width1 2 + +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define maBufferIndex 0 + +double maBuffer[]; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (maLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Start Set Index Buffers ... + // + // + // Ma ... + SetIndexBuffer(maBufferIndex, maBuffer); + SetIndexDrawBegin(maBufferIndex, maLength + 1); + // + // End Set Index Buffers ... + // + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, maLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Ma ... + CalculateMa(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateMa( + const int &bar_index +) { + // + // Calculating Fast Ma ... + double ma = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + maAppliedPrice, + bar_index + ); + + // + maBuffer[bar_index] = ma; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Indicators/x-saherelm.xrange.mq4 b/Indicators/x-saherelm.xrange.mq4 new file mode 100644 index 0000000..1359f57 --- /dev/null +++ b/Indicators/x-saherelm.xrange.mq4 @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XRange Indicator +// --------------------------------------------- +// saherelm implementation of above 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 XRange Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 14; +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_chart_window + +// +#property indicator_buffers 3 + +// +#property indicator_plots 3 + +// +// Start Define Indicator Buffer Styles ... +// +// +// Highest High Buffer ... +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +// Lowest Low Buffer ... +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +// Middle Buffer ... +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_DASH +#property indicator_width3 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +// +#define highestHighBufferIndex 0 +#define lowestLowBufferIndex 1 +#define middleBufferIndex 2 + +// +double highestHighBuffer[]; +double lowestLowBuffer[]; +double middleBuffer[]; + +// +datetime startTime; +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if ( + marketLength <= 0 + ) { + return INIT_PARAMETERS_INCORRECT; + } + + // + string hhLbl = StringConcatenate( + "XR HH(", marketLength, ")" + ); + SetIndexBuffer(highestHighBufferIndex, highestHighBuffer); + SetIndexLabel(highestHighBufferIndex, hhLbl); + + // + string llLbl = StringConcatenate( + "XR LL(", marketLength, ")" + ); + SetIndexBuffer(lowestLowBufferIndex, lowestLowBuffer); + SetIndexLabel(lowestLowBufferIndex, llLbl); + + // + string midLbl = StringConcatenate( + "XR Mid(", marketLength, ")" + ); + SetIndexBuffer(middleBufferIndex, middleBuffer); + SetIndexLabel(middleBufferIndex, midLbl); + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculations ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculations ... +void CalculateBuffers( + const int &bar_index +) { + // + // Retrieve Bar Time ... + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + if (startTime == 0) { + // + startTime = barTime; + SetIndicatorBuffersNone(bar_index); + return; + } + + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + startTime + ); + + // + int startDistance = startBarIndex - bar_index; + if (startDistance < marketLength) { + // + SetIndicatorBuffersNone(bar_index); + return; + } + + // + // Highest High ... + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLength, + bar_index + ); + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + highestHighBuffer[bar_index] = hh; + + // + // Lowest Low ... + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLength, + bar_index + ); + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + lowestLowBuffer[bar_index] = ll; + + // + // Middle Buffer ... + double mid = (hh + ll) / 2; + middleBuffer[bar_index] = mid; + + // + // Reset Start Time ... + startTime = 0; +} + +// +void SetIndicatorBuffersNone( + const int bar_index +) { + // + int lastBarIndex = bar_index + 1; + + // + double lastHighestHigh; + double lastLowestLow; + + // + // Highest High ... + if (ArraySize(highestHighBuffer) > lastBarIndex) { + lastHighestHigh = highestHighBuffer[lastBarIndex]; + } else { + lastHighestHigh = 0; + } + + // + // Lowest Low ... + if (ArraySize(lowestLowBuffer) > lastBarIndex) { + lastLowestLow = lowestLowBuffer[lastBarIndex]; + } else { + lastLowestLow = 0; + } + + // + highestHighBuffer[bar_index] = lastHighestHigh; + lowestLowBuffer[bar_index] = lastLowestLow; + + // + double mid = (lastHighestHigh + lastLowestLow) / 2; + middleBuffer[bar_index] = mid; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Indicators/x-saherelm.xtpow.mq4 b/Indicators/x-saherelm.xtpow.mq4 new file mode 100644 index 0000000..46ff59e --- /dev/null +++ b/Indicators/x-saherelm.xtpow.mq4 @@ -0,0 +1,275 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center Trend Power Indicator +// --------------------------------------------- +// saherelm implementation of above indicator ... +// this indicator uses two ma line: +// - fast ma; +// - slow ma; +// +// 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 MA Indicator" +#property strict + +// +// START Inputs ... +// +input int marketLength = 7; // Market Length +// +// END Inputs ... +// + +// +// START Global Definitions: Variables, Properties and etc ... +// +#property indicator_separate_window + +// +#property indicator_plots 3 +#property indicator_buffers 3 +#property indicator_minimum 0 +#property indicator_maximum 100 + +// +#property indicator_levelcolor clrGray +#property indicator_levelstyle STYLE_DOT + +// +// Start Define Indicator Buffer Styles ... +// +#property indicator_type1 DRAW_HISTOGRAM +#property indicator_color1 clrLime +#property indicator_style1 STYLE_DOT +#property indicator_width1 1 + +// +#property indicator_type2 DRAW_HISTOGRAM +#property indicator_color2 clrRed +#property indicator_style2 STYLE_DOT +#property indicator_width2 1 + +// +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrYellow +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 +// +// End Define Indicator Buffer Styles ... +// + +// +// Buffers ... +#define powerUpBufferIndex 0 +#define powerDownBufferIndex 1 +#define signalBufferIndex 2 + +double powerUpBuffer[]; +double powerDownBuffer[]; +double signalBuffer[]; + +// +#include "../Libraries/x-saherelm.lib.mq4" +// +// END Global Definitions: Variables, Properties and etc ... +// + +// +// Start Event Handlers ... +// +// +// Initialization ... +int OnInit() { + // + // Initialize what we want ... + if (marketLength <= 0) { + return INIT_PARAMETERS_INCORRECT; + } + + // + SetLevelValue(0, 0.0); + IndicatorSetString(INDICATOR_LEVELTEXT,0,""); + + // + SetLevelValue(1, 20.0); + IndicatorSetString(INDICATOR_LEVELTEXT,1,""); + + // + SetLevelValue(2, 50); + IndicatorSetString(INDICATOR_LEVELTEXT,2,""); + + // + SetLevelValue(3, 100); + IndicatorSetString(INDICATOR_LEVELTEXT,3,""); + + // + string pUpLbl = StringConcatenate( + "P Up (", marketLength, ")" + ); + SetIndexLabel(powerUpBufferIndex, pUpLbl); + SetIndexBuffer(powerUpBufferIndex, powerUpBuffer); + SetIndexDrawBegin(powerUpBufferIndex, marketLength + 1); + + // + string pDownLbl = StringConcatenate( + "P Down (", marketLength, ")" + ); + SetIndexLabel(powerDownBufferIndex, pDownLbl); + SetIndexBuffer(powerDownBufferIndex, powerDownBuffer); + SetIndexDrawBegin(powerDownBufferIndex, marketLength + 1); + + // + string pSignalLbl = StringConcatenate( + "P Signal (", marketLength, ")" + ); + SetIndexLabel(signalBufferIndex, pSignalLbl); + SetIndexBuffer(signalBufferIndex, signalBuffer); + SetIndexDrawBegin(signalBufferIndex, marketLength + 1); + + // + // here we specify logging enabled or not ... + enableLogging = true; + + // + // this is a Tag which attached to our Logger ... + logTag = "X_TPW_OSC"; + + // + return INIT_SUCCEEDED; +} + +// +// Calculating what we want ... +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] +) { + // + // this counts Available Bars ... + int limit; + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + int maxLength = MathMax(0, marketLength); + + // + // input variable, we return 0 means nothing passed ... + if (rates_total < maxLength) { + return 0; + } + + // + // found which candles calculated before ... + limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; + + // + // this is the main loop of calculations, for each bar index ... + for (int i = limit - 1; i >= 0; i--) { + // + // Start Calculation here ... + // i is bar_index ... + + // + // Calculate Buffers ... + CalculateBuffers(i); + } + + // + return rates_total; +} +// +// END Event Handlers ... +// + +// +// START Functions ... +// +// +// Calculating Ma ... +void CalculateBuffers( + const int &bar_index +) { + // + double powerUp = 0; + double powerDown = 0; + + // + int dailyCount = GetDailyCandleCount(); + double dailyHH = GetMarketHighestHigh( + bar_index, + dailyCount + ); + double dailyLL = GetMarketLowestLow( + bar_index, + dailyCount + ); + double dailyDiff = dailyHH - dailyLL; + double rate = dailyDiff / 100; + + // + for (int i = bar_index; i < bar_index + marketLength; i++) { + // + XOHCL c = GetCandleModel(i); + + // + double cRange = + MathAbs(c.open - c.close) + // MathAbs(c.high - c.low) + ; + bool isBullish = c.open < c.close; + + // + if (isBullish) { + powerUp += cRange; + } else { + powerDown += cRange; + } + } + + // + powerUp = powerUp / rate; + powerDown = powerDown / rate; + + // + int doubleMarketLength = (marketLength * 2); + double ema = GetMA( + bar_index, + doubleMarketLength, + 0, + MODE_EMA, + PRICE_WEIGHTED + ); + + // + double emaRate = GetMarketHighestHigh(bar_index, doubleMarketLength) - GetMarketLowestLow(bar_index, doubleMarketLength) / 100; + + // + double signal = (ema / 100) * rate; + double signalAddition = MathMin(powerUp, powerDown); + + // + powerUpBuffer[bar_index] = powerUp; + powerDownBuffer[bar_index] = powerDown; + signalBuffer[bar_index] = signal + signalAddition; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Libraries/x-saherelm.dialog.mq4 b/Libraries/x-saherelm.dialog.mq4 new file mode 100644 index 0000000..c00318e --- /dev/null +++ b/Libraries/x-saherelm.dialog.mq4 @@ -0,0 +1,110 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Dialog Library +// --------------------------------------------- +// saherelm useful tools and definitions +// for handling dialogs ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes Logger library ... +// #include "../Libraries/x-saherelm.lib.mq4" +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +#include + +// +CAppDialog AppWindow; + +// +// Prefix for Created Dialogs ... +string windowPrefix = "XWinD"; + +// +// Generate a random number for dialogs ... +int GenerateWindowNumber() { + // + int result = MathRand() + 1; + + // + return result; +} + +// +// Generate a Window Prefix ID ... +string GenerateWindowID() { + // + string result = windowPrefix; + + // + // Generate INT ID ... + int idNum = GenerateWindowNumber(); + + // + result += "_" + StringConcatenate(idNum); + + // + return result; +} + +// +bool CreateDialog( + const string title = "" +) { + // + // string windowID = GenerateWindowID(); + + // + // Try to Create Window ... + bool result = AppWindow.Create( + 0, + title, + 0, + 20, + 20, + 360, + 324 + ); + + // + if (result) { + AppWindow.Run(); + } + + // + return result; +} + +// +void DestroyDialog(const int reason) { + AppWindow.Destroy(reason); +} + +// +// Apply Chart Event on Created Window ... +void DialogChartEvent( + const int id, // event ID + const long& lparam, // event parameter of the long type + const double& dparam, // event parameter of the double type + const string& sparam // event parameter of the string type +) { + // + AppWindow.ChartEvent( + id, + lparam, + dparam, + sparam + ); +} \ No newline at end of file diff --git a/Libraries/x-saherelm.draw.lib.mq4 b/Libraries/x-saherelm.draw.lib.mq4 new file mode 100644 index 0000000..776cde4 --- /dev/null +++ b/Libraries/x-saherelm.draw.lib.mq4 @@ -0,0 +1,2010 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes our shared library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Draw Highest High ... +bool DrawHighestHigh( + const int bar_index, + const int marketLen, + const string tag, + const int drawUntilBarIndex = 0, + const long chartID = 0, + const int subWindow = 0, + const color clr = clrAqua, + const ENUM_LINE_STYLE style = STYLE_DOT, + const int width = 1, + const bool back = false, + const bool selection = false, + const bool hidden = false, + const long zOrder = 0 +) { + // + bool result = false; + + // + // Calculate Highest High ... + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + datetime hhTime = iTime( + _Symbol, + _Period, + hhIdx + ); + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + datetime drawUntilTime = + drawUntilBarIndex != bar_index ? + iTime( + _Symbol, + _Period, + drawUntilBarIndex + ) : + barTime + ; + + // + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + int rnd = rand(); + + // + // Define Label ... + string lbl = StringConcatenate( + tag, + "_HH(", marketLen ,")_", + hh, + "_", rnd + ); + + // + result = ObjectDelete( + chartID, + lbl + ); + + // + // Draw a Trend Line ... + result = DrawTrendLine( + chartID, + lbl, + subWindow, + hhTime, + hh, + drawUntilTime, + hh, + clr, + style, + width, + back, + selection, + hidden, + zOrder + ); + + // + return result; +} + +// +// Draw Lowest Low ... +bool DrawLowestLow( + const int bar_index, + const int marketLen, + const string tag, + const int drawUntilBarIndex = 0, + const long chartID = 0, + const int subWindow = 0, + const color clr = clrFuchsia, + const ENUM_LINE_STYLE style = STYLE_DOT, + const int width = 1, + const bool back = false, + const bool selection = false, + const bool hidden = false, + const long zOrder = 0 +) { + // + bool result = false; + + // + // Calculate Highest High ... + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + datetime llTime = iTime( + _Symbol, + _Period, + llIdx + ); + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + datetime drawUntilTime = + drawUntilBarIndex != bar_index ? + iTime( + _Symbol, + _Period, + drawUntilBarIndex + ) : + barTime + ; + + // + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + int rnd = rand(); + + // + // Define Label ... + string lbl = StringConcatenate( + tag, + "_LL(", marketLen ,")_", + ll, + "_", rnd + ); + + // + result = ObjectDelete( + chartID, + lbl + ); + + // + // Draw a Trend Line ... + result = DrawTrendLine( + chartID, + lbl, + subWindow, + llTime, + ll, + drawUntilTime, + ll, + clr, + style, + width, + back, + selection, + hidden, + zOrder + ); + + // + return result; +} + +// +// Draw Market Middle ... +bool DrawMarketMiddle( + const int bar_index, + const int marketLen, + const string tag, + const int drawUntilBarIndex = 0, + const long chartID = 0, + const int subWindow = 0, + const color clr = clrYellow, + const ENUM_LINE_STYLE style = STYLE_DOT, + const int width = 1, + const bool back = false, + const bool selection = false, + const bool hidden = false, + const long zOrder = 0 +) { + // + bool result = false; + + // + // Calculate Highest High ... + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + datetime llTime = iTime( + _Symbol, + _Period, + llIdx + ); + + // + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + // Calculate Highest High ... + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + datetime hhTime = iTime( + _Symbol, + _Period, + hhIdx + ); + + // + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + double middle = ll + ((hh - ll) / 2); + datetime middleTime = hhIdx < llIdx + ? hhTime + : llTime + ; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + datetime drawUntilTime = + drawUntilBarIndex != bar_index ? + iTime( + _Symbol, + _Period, + drawUntilBarIndex + ) : + barTime + ; + + // + int rnd = rand(); + + // + // Define Label ... + string lbl = StringConcatenate( + tag, + "_MID(", marketLen ,")_", + middle, + "_", rnd + ); + + // + result = ObjectDelete( + chartID, + lbl + ); + + // + // Draw a Trend Line ... + result = DrawTrendLine( + chartID, + lbl, + subWindow, + middleTime, + middle, + drawUntilTime, + middle, + clr, + style, + width, + back, + selection, + hidden, + zOrder + ); + + // + return result; +} + +// +// Start Arrow Functions ... +// +// +// Draw an Arrow Object on Chart ... +bool DrawArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // arrow name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const uchar arrowCode = OBJ_ARROW_UP, // arrow code + const ENUM_ARROW_ANCHOR anchor = ANCHOR_BOTTOM, // anchor point position + const color clr = clrAqua, // arrow color + const ENUM_LINE_STYLE style = STYLE_SOLID, // border line style + const int width = 3, // arrow size + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // Order Object ... +) { + // + // set anchor point coordinates if they are not set ... + ChangeArrowEmptyPoint(time, price); + + // + // reset the error value ... + ResetLastError(); + + // + // create an arrow ... + if(!ObjectCreate(chartID, name, OBJ_ARROW, subWindow, time, price)) { + // + string message = StringConcatenate(__FUNCTION__, + ": failed to create an arrow! Error code = ", + GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the arrow code ... + ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, arrowCode); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set the arrow color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set the border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set the arrow's size ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the arrow by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is false by default, if you want making it possible to highlight and move the object + // change it to true ... + ObjectSetInteger(chartID,name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point of Arrow ... +bool MoveArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if(!time) { + time = TimeCurrent(); + } + + // + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete an arrow ... +bool DeleteArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow" // arrow name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete an arrow ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete an arrow! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the arrow code ... +bool ArrowCodeChange( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + const uchar code = 252 // arrow code +) { + // + // reset the error value ... + ResetLastError(); + + // + // change the arrow code ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, code)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the arrow code! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change anchor type ... +bool ArrowAnchorChange( + const long chartID = 0, // chart's ID + const string name="Arrow", // object name + const ENUM_ARROW_ANCHOR anchor = ANCHOR_TOP // anchor type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change anchor type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change anchor type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeArrowEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } +} +// +// End Arrow Functions ... +// + +// +// Start Horizontal Line Functions ... +// +// +// Create, Draw the horizontal line ... +bool DrawHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + const int subWindow = 0, // subwindow index + double price = 0, // line price + const color clr = clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the price is not set, set it at the current Bid price level ... + if(!price) { + price=SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // create a horizontal line ... + if(!ObjectCreate(chartID, name, OBJ_HLINE, subWindow, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move horizontal line ... +bool MoveHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + double price = 0 // line price +) { + // + // if the line price is not set, move it to the current Bid price level ... + if(!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move a horizontal line ... + if(!ObjectMove(chartID, name, 0, 0, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete a horizontal line ... +bool DeleteHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a horizontal line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a horizontal line! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End Horizontal Line Functions ... +// + +// +// Start Vertical Line Functions ... +// +// +// Create the vertical line ... +bool DrawVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + const int sub_window = 0, // subwindow index + datetime time = 0, // line time + const color clr=clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // if the line time is not set, draw it via the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value + ResetLastError(); + + // + // create a vertical line ... + if (!ObjectCreate(chartID, name, OBJ_VLINE, sub_window, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return true; +} + +// +// Move the vertical line ... +bool MoveVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + datetime time = 0 // line time +) { + // + // if line time is not set, move the line to the last bar ... + if (!time) { + time = TimeCurrent(); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the vertical line ... + if(!ObjectMove(chartID, name, 0, time, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the vertical line ... +bool DeleteVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the vertical line ... + if (!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete the vertical line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return false; + } + + // + // successful execution ... + return true; +} +// +// End Vertical Line Functions ... +// + +// +// Start RectangleLabel Functions ... +// +// +// Create Rectangle Label Object ... +bool DrawRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int subWindow = 0, // subwindow index + const int x = 0, // X coordinate + const int y = 0, // Y coordinate + const int width = 50, // width + const int height = 18, // height + const color back_clr = C'236,233,216', // background color + const ENUM_BORDER_TYPE border = BORDER_SUNKEN, // border type + const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring + const color clr = clrRed, // flat border color (Flat) + const ENUM_LINE_STYLE style = STYLE_SOLID, // flat border style + const int lineWidth = 1, // flat border width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // reset the error value ... + ResetLastError(); + + // + //--- create a rectangle label + if(!ObjectCreate(chartID, name, OBJ_RECTANGLE_LABEL, subWindow, 0, 0)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set label coordinates ... + ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x); + ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y); + + // + // set label size ... + ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width); + ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height); + + // + // set background color ... + ObjectSetInteger(chartID, name, OBJPROP_BGCOLOR, back_clr); + + // + // set border type ... + ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border); + + // + // set the chart's corner, relative to which point coordinates are defined ... + ObjectSetInteger(chartID, name, OBJPROP_CORNER, corner); + + // + // set flat border color (in Flat mode) ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set flat border line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set flat border width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, lineWidth); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the label by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move Rectangle Label .. +bool MoveRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int x = 0, // X coordinate + const int y=0 // Y coordinate +) { + // + // reset the error value ... + ResetLastError(); + + // + // move the rectangle label ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move X coordinate of the label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move Y coordinate of the label! Error code = ",GetLastError() + ); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete the rectangle label ... +bool DeleteRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel" // label name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the label ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a rectangle label! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change Rectangle Label Size ... +bool ChangeSizeRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int width = 50, // label width + const int height = 18 // label height +) { + // + // reset the error value ... + ResetLastError(); + + // + // change label size ... + if(!ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's width! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + if(!ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the label's height! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change rectangle label border type ... +bool RectLabelChangeBorderType( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const ENUM_BORDER_TYPE border = BORDER_SUNKEN // border type +) { + // + // reset the error value ... + ResetLastError(); + + // + // change border type ... + if(!ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the border type! Error code = ",GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} +// +// End RectangleLabel Functions ... +// + +// +// Start TrendLine Funcions ... +// +// Create a trend line by the given coordinates ... +bool DrawTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrYellow, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool rayRight = false, // line's continuation to the right + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeTrendLineEmptyPoints( + time1, + price1, + time2, + price2 + ); + + // + // reset the error value ... + ResetLastError(); + + // + // create a trend line by the given coordinates ... + if(!ObjectCreate(chartID, name, OBJ_TREND, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set line color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the line's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move trend line anchor point ... | +bool ChangeTrendLinePoint( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int pointindex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(Symbol(),SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move trend line's anchor point ... + if(!ObjectMove(chartID, name, pointindex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// The function deletes the trend line from the chart ... +bool DeleteTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine" // line name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete a trend line ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete a trend line! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of trend line's anchor points and set default ... +// values for empty ones ... +void ChangeTrendLineEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the first point's time is not set, it will be on the current bar ... + if (!time1) { + time1 = TimeCurrent(); + } + + // + // if the first point's price is not set, it will have Bid value ... + if (!price1) { + price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // if the second point's time is not set, it is located 9 bars left from the second one ... + if (!time2) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(), Period(), time1, 10, temp); + + // + // set the second point 9 bars left from the first one ... + time2 = temp[0]; + } + + // + // if the second point's price is not set, it is equal to the first point's one ... + if (!price2) { + price2 = price1; + } +} +// +// End TrendLine Functions ... +// + +// +// Start Text Functions ... +// +// Create and Draw a Text Object ... +bool DrawText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const string text = "Text", // the text itself + const string font = "Arial", // font + const int fontSize = 10, // font size + const color clr = clrRed, // color + const double angle = 0.0, // text slope + const ENUM_ANCHOR_POINT anchor = ANCHOR_CENTER, // anchor type + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor point coordinates if they are not set ... + ChangeTextEmptyPoint(time,price); + + // + // reset the error value ... + ResetLastError(); + + // + //--- create Text object + if(!ObjectCreate(chartID, name, OBJ_TEXT, subWindow, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the text ... + ObjectSetString(chartID, name , OBJPROP_TEXT, text); + + // + // set text font ... + ObjectSetString(chartID, name, OBJPROP_FONT, font); + + // + // set font size ... + ObjectSetInteger(chartID, name, OBJPROP_FONTSIZE, fontSize); + + // + // set the slope angle of the text ... + ObjectSetDouble(chartID, name, OBJPROP_ANGLE, angle); + + // + // set anchor type ... + ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of moving the object by mouse ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID ,name, OBJPROP_SELECTED, selection); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Move the anchor point ... +bool MoveText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + //--- if point position is not set, move it to the current bar having Bid price + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point .. + if(!ObjectMove(chartID, name, 0, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Change the object text ... +bool ChangeText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const string text = "Text" // text +) { + // + // reset the error value ... + ResetLastError(); + + // + // change object text ... + if(!ObjectSetString(chartID, name, OBJPROP_TEXT, text)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to change the text! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Text object ... +bool DeleteText( + const long chartID = 0, // chart's ID + const string name = "Text" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Text\" object! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution + return(true); +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeTextEmptyPoint( + datetime &time, + double &price +) { + // + // if the point's time is not set, it will be on the current bar ... + if(!time) { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if(!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + } +// +// End Text Functions ... +// + +// +// Start Fibonacchi Functions ... +// +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawFibonacci( + const long chartID = 0, // chart's ID + const string name="Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrRed, // object color + const ENUM_LINE_STYLE style = STYLE_SOLID, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return(true); +} + +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawCustomFibonacci( + // + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + // + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrAqua, // object color + const ENUM_LINE_STYLE style = STYLE_DOT, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) { + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // reset the error value ... + ResetLastError(); + + // + // Create Fibonacci Retracement by the given coordinates ... + if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to create \"Fibonacci Retracement\"! Error code = " , GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable (true) or disable (false) the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // enable (true) or disable (false) the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, name, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // Change Levels Of Fibonacci ... + bool result = FibonacciLevelsSet( + levels, + values, + colors, + styles, + widths, + descriptions, + chartID, + name + ); + + // + // successful execution ... + return result; +} + +// +// Set number of levels and their parameters ... +bool FibonacciLevelsSet( + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // check array sizes ... + if( + levels!=ArraySize(colors) || + levels!=ArraySize(styles) || + levels!=ArraySize(widths) || + levels!=ArraySize(widths) + ) { + // + string message = StringConcatenate( + __FUNCTION__, + ": array length does not correspond to the number of levels, error!" + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // set the number of levels ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELS, levels); + + // + // set the properties of levels in the loop ... + for(int i = 0; i < levels; i++) { + // + // level value ... + ObjectSetDouble(chartID, name, OBJPROP_LEVELVALUE, i, values[i]); + + // + // level color ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELCOLOR, i, colors[i]); + + // + // level style ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELSTYLE, i, styles[i]); + + // + // level width ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELWIDTH, i, widths[i]); + + // + // level description ... + // ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, DoubleToString(100 * values[i], 1)); + ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, descriptions[i]); + } + + // + // successful execution ... + return(true); +} + +// +// Move Fibonacci Retracement anchor point ... +bool FibonacciPointChange( + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int pointIndex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) { + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { + time = TimeCurrent(); + } + + // + if (!price) { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // reset the error value ... + ResetLastError(); + + // + // move the anchor point ... + if(!ObjectMove(chartID, name, pointIndex, time, price)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to move the anchor point! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Delete Fibonacci Retracement ... +bool DeleteFibonachi( + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) { + // + // reset the error value ... + ResetLastError(); + + // + // delete the object ... + if(!ObjectDelete(chartID, name)) { + // + string message = StringConcatenate( + __FUNCTION__, + ": failed to delete \"Fibonacci Retracement\"! Error code = ", GetLastError() + ); + + // + LogMessage(message); + + // + return(false); + } + + // + // successful execution ... + return(true); +} + +// +// Check the values of Fibonacci Retracement anchor points and set +// default values for empty ones ... +void ChangeFibonacciEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 +) { + // + // if the second point's time is not set, it will be on the current bar ... + if (!time2) { + time2 = TimeCurrent(); + } + + // + // if the second point's price is not set, it will have Bid value ... + if (!price2) { + price2 = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // if the first point's time is not set, it is located 9 bars left from the second one ... + if (!time1) { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(),Period(),time2,10,temp); + + // + // set the first point 9 bars left from the second one ... + time1 = temp[0]; + } + + // + // if the first point's price is not set, move it 200 points below the second one ... + if (!price1) { + price1 = price2 - 200 * SymbolInfoDouble(_Symbol, SYMBOL_POINT); + } +} +// +// End Fibonacci Functions ... +// + + +// +// Start General Functions ... +// +// +// Remove all Drawn Objects ... +void RemoveDraws(const string &tag) { + // + for(int iObj=ObjectsTotal()-1; iObj >= 0; iObj--) { + // + string on = ObjectName(iObj); + if (StringFind(on, tag) == 0) { + ObjectDelete(on); + } + } +} +// +// End General Functions ... +// \ No newline at end of file diff --git a/Libraries/x-saherelm.indicator.lib.mq4 b/Libraries/x-saherelm.indicator.lib.mq4 new file mode 100644 index 0000000..0e4b162 --- /dev/null +++ b/Libraries/x-saherelm.indicator.lib.mq4 @@ -0,0 +1,450 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Indicator Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// Reading specified Buffer From ADX Indicator ... +double ReadXMABuffer( + const int bar_index, + const int buffer_index, + // + const int marketLen, + // + const double stp, + const double mxm, + // + const int shortCycleMult, + const int mediumCycleMult, + const int longCycleMult +) { + // + string xmaIndicatorName = "x-saherelm.x.xma"; + + // + double result = iCustom( + _Symbol, + _Period, + xmaIndicatorName, + // + // Inputs ... + marketLen, + stp, + mxm, + shortCycleMult, + mediumCycleMult, + longCycleMult, + MODE_SMA, + // + buffer_index, + bar_index + ); + + // + return result; +} + +// +// Reading specified Buffer from XHL Indicator ... +double ReadXHLBuffer( + const int bar_index, + const int buffer_index, + // + const int marketLen, + // + const int shortCycleMult, + const int mediumCycleMult, + const int longCycleMult +) { + // + string xhlIndicatorName = "x-saherelm.x.hl"; + + // + double result = iCustom( + _Symbol, + _Period, + xhlIndicatorName, + // + // Inputs ... + marketLen, + shortCycleMult, + mediumCycleMult, + longCycleMult, + MODE_SMA, + // + buffer_index, + bar_index + ); + + // + return result; +} + +// +// Reading ADX Values ... +double ReadADX( + const int bar_index, + const int marketLen, + const int mult +) { + // + double result; + + // + int period = marketLen * mult; + + // + result = iADX( + _Symbol, + _Period, + period, + PRICE_CLOSE, + MODE_MAIN, + bar_index + ); + + // + return result; +} + +// +// Reading Pivot States ... +XPvtState GetPVTState( + const int bar_index, + const int marketLen +) { + // + XPvtState result = {}; + + // + double hh = GetMarketHighestHigh( + bar_index, + marketLen + ); + + // + double ho = GetMarketHighestOpen( + bar_index, + marketLen + ); + + // + double hc = GetMarketHighestClose( + bar_index, + marketLen + ); + + // + double hl = GetMarketHighestLow( + bar_index, + marketLen + ); + + // + double ll = GetMarketLowestLow( + bar_index, + marketLen + ); + + // + double lo = GetMarketLowestOpen( + bar_index, + marketLen + ); + + // + double lc = GetMarketLowestClose( + bar_index, + marketLen + ); + + // + double lh = GetMarketLowestHigh( + bar_index, + marketLen + ); + + // + // Filling Result ... + // + result.hh = hh; + result.ho = ho; + result.hc = hc; + result.hl = hl; + + // + result.ll = ll; + result.lo = lo; + result.lc = lc; + result.lh = lh; + + // + return result; +} + +// +// Calculate XRange from Market ... +static XRState lastXRState; +XRState GetXRange( + const int bar_index, + const int rangeMarketLength +) { + // + XRState result = {}; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + int marketBarIndex = bar_index + rangeMarketLength; + + // + // Highest High ... + // + int hhIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketBarIndex, + bar_index + ); + + // + double hh = iHigh( + _Symbol, + _Period, + hhIdx + ); + + // + // Lowest Low ... + // + int llIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketBarIndex, + bar_index + ); + + // + double ll = iLow( + _Symbol, + _Period, + llIdx + ); + + // + if (lastXRState.start == 0) { + // + lastXRState.start = barTime; + lastXRState.length = rangeMarketLength; + + // + lastXRState.hh = hh; + lastXRState.ll = ll; + + // + // Middle ... + double mid = (hh + ll) / 2; + lastXRState.mid = mid; + } else { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + lastXRState.start + ); + + // + if (startBarIndex - bar_index >= rangeMarketLength) { + // + lastXRState.start = barTime; + lastXRState.length = rangeMarketLength; + + // + lastXRState.hh = hh; + lastXRState.ll = ll; + + // + // Middle ... + double mid = (hh + ll) / 2; + lastXRState.mid = mid; + } + } + + // + result = lastXRState; + + // + return result; +} + +// +// Reading XTPowState from Indicatoe ... +XTPOWState GetXTPowState( + const int bar_index, + const int marketLen +) { + // + XTPOWState result = {}; + + // + // + double powerUp = 0; + double powerDown = 0; + double signal = 0; + + // + string indicatorName = "x-saherelm.xtpow"; + + // + int pUpIndex = 0; + int pDownIndex = 1; + int signalIndex = 2; + + // + powerUp = iCustom( + _Symbol, + _Period, + indicatorName, + // + marketLen, + // + pUpIndex, + bar_index + ); + + // + powerDown = iCustom( + _Symbol, + _Period, + indicatorName, + // + marketLen, + // + pDownIndex, + bar_index + ); + + // + signal = iCustom( + _Symbol, + _Period, + indicatorName, + // + marketLen, + // + signalIndex, + bar_index + ); + + // + result.signal = signal; + result.powerUp = powerUp; + result.powerDown = powerDown; + + // + return result; +} + +// +// Reading XRState From Indicator ... +XRState ReadXRange( + const int bar_index, + const int marketLen +) { + // + XRState result = {}; + + // + // Define Buffer Indexes ... + int hhBufferIndex = 0; + int llBufferIndex = 1; + int midBufferIndex = 2; + + // + string indicatorName = "x-saherelm.xrange"; + + // + // Read Values From XRange Indicator ... + + // + double hh = iCustom( + _Symbol, + _Period, + indicatorName, + // + // Inputs ... + marketLen, + // + hhBufferIndex, // Buffer Index ... + bar_index + ); + + // + double ll = iCustom( + _Symbol, + _Period, + indicatorName, + // + // Inputs ... + marketLen, + // + llBufferIndex, // Buffer Index ... + bar_index + ); + + // + double mid = iCustom( + _Symbol, + _Period, + indicatorName, + // + // Inputs ... + marketLen, + // + midBufferIndex, // Buffer Index ... + bar_index + ); + + // + // Filling Result ... + result.hh = hh; + result.ll = ll; + result.mid = mid; + + // + return result; +} +// +// END Indicator Reading Data ... +// diff --git a/Libraries/x-saherelm.lib.mq4 b/Libraries/x-saherelm.lib.mq4 new file mode 100644 index 0000000..9cbc3d6 --- /dev/null +++ b/Libraries/x-saherelm.lib.mq4 @@ -0,0 +1,1695 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes Logger library ... +#include "../Libraries/x-saherelm.log.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +static datetime lastBarTime; + +// +struct XOHCL { + double high; + double open; + double close; + double low; +}; + +// +struct XRange { + // + datetime time; + + // + double highestHigh; + double lowestLow; + + // + int levels; + int marketLength; + + // + double rate; +}; + +// +struct XPrice { + // + double askPrice; + double bidPrice; + double priceGap; + + // + double longEntry; + double longExit; + + // + double shortEntry; + double shortExit; +}; + +// +// START Functions ... +// + +// +// Determines current working is New Bar or not ... +bool IsNewBar() { + // + // Reading Last Bar Date ... + datetime curbar = (datetime)SeriesInfoInteger( + _Symbol, + _Period, + SERIES_LASTBAR_DATE + ); + + // + if(lastBarTime != curbar) { + // + lastBarTime = curbar; + return true; + } + + // + return false; +} + +// +// Determines we are in new Day or not ... +bool IsNewDay() { + // + bool result = false; + + // + // Reading Last Bar Date ... + datetime curbar = (datetime)SeriesInfoInteger( + _Symbol, + _Period, + SERIES_LASTBAR_DATE + ); + + // + if (lastBarTime == 0) { + lastBarTime = curbar; + } + + // + if (curbar == lastBarTime) { + return result; + } + + // + // Retrieve Day and Month and Year for Last Bar Time ... + int lastBarDay = TimeDay(lastBarTime); + int lastBarMonth = TimeMonth(lastBarTime); + int lastBarYear = TimeYear(lastBarTime); + + // + // Retrieve Day and Month and Year for Current Bar Time ... + int curBarDay = TimeDay(curbar); + int curBarMonth = TimeMonth(curbar); + int curBarYear = TimeYear(curbar); + + // + result = curBarDay > lastBarDay + || curBarMonth > lastBarMonth + || curBarYear > lastBarYear; + + // + return result; +} + +// +// Determines we are in new Hour or not ... +bool IsNewHour() { + // + // Save Last Hour value ... + static int lastHour = 0; + + // + bool isInNewDay = IsNewDay(); + if (isInNewDay) { + // + // Reset Last Hour if it's in New Day ... + lastHour = 0; + } + + // + // Retrieve Current Hour value ... + int currentHour = Hour(); + + // + // Check values ... + bool result = currentHour > lastHour; + if (result) { + // + // Update Last Hour value ... + lastHour = currentHour; + } + + // + // returns result ... + return result; +} + +// +// Retrieve Number of Candles in a Day ... +int GetDailyCandleCount() { + // + int seconds = PeriodSeconds(_Period); + + // + int daySeconds = 24 * 60 * 60; + + // + int result = daySeconds / seconds; + + // + return result; +} + +// +// XRange Detector ... +XRange GetMarketRange( + const int bar_index, + const int marketLen, + const int levels +) { + // + XRange result = {}; + + // + result.levels = levels; + result.marketLength = marketLen; + + // + datetime time = iTime( + _Symbol, + _Period, + bar_index + ); + result.time = time; + + // + double highestHigh = GetMarketHighestHigh( + bar_index, + marketLen + ); + result.highestHigh = highestHigh; + + // + double lowestLow = GetMarketLowestLow( + bar_index, + marketLen + ); + result.lowestLow = lowestLow; + + // + double diff = highestHigh - lowestLow; + double rate = diff / levels; + + // + result.rate = rate; + + // + return result; +} + +// +// Retrieve RMA on Specific Candle ... +double GetRMA( + int bar_index, + int length +) { + // + double shortSMA = iMA(_Symbol, _Period, length, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double mediumSMA = iMA(_Symbol, _Period, length * 2, 0, MODE_SMA, PRICE_CLOSE, bar_index); + double longSMA = iMA(_Symbol, _Period, length * 3, 0, MODE_SMA, PRICE_CLOSE, bar_index); + + // + double result = longSMA - mediumSMA + shortSMA; + + // + return result; +} + +// +// Retrieve Moving Average ... +double GetMA( + const int bar_index, + const int maLength, + const int maShift, + const ENUM_MA_METHOD maMethod, + const ENUM_APPLIED_PRICE appliedPrice +) { + // + double result = iMA( + _Symbol, + _Period, + maLength, + maShift, + maMethod, + appliedPrice, + bar_index + ); + + // + return result; +} + +// +// Calculate Fib Level ... +double GetFibonacciLevel( + double upPrice, + double downPrice, + double level, + int direction +) { + // + double ling = upPrice - downPrice; + double pLevel = (ling / 100) * (level * 100); + + // + double result = direction > 0 ? + upPrice - pLevel : + downPrice + pLevel; + result = NormalizeDouble(result, _Digits); + + // + return result; +} + +// +// Retrieve True Range ... +double GetTR( + const int bar_index +) { + // + double result = 0; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double prevClose = iClose( + _Symbol, + _Period, + bar_index + 1 + ); + + // + double highLowDif = high - low; + double hpCDif = MathAbs(high - prevClose); + double lpCDiff = MathAbs(low - prevClose); + + // + result = MathMax(highLowDif, hpCDif); + result = MathMax(result, lpCDiff); + + // + return result; +} + +// +// Calculate True Range Simple Moving Average ... +double GetMarketTRSMA( + const int bar_index, + const int marketLen +) { + // + double result = 0; + + // + // Create Barket Length Trs ... + double trs[]; + ArrayResize( + trs, + marketLen + ); + int index = 0; + double trSum = 0; + for (int i = bar_index; i < bar_index + marketLen; i++) { + // + double tr = GetTR(i); + trs[index] = tr; + + // + trSum += tr; + + // + index++; + } + + // + result = trSum / marketLen; + + // + return result; +} + +// +// Retrieve Commodity Channel ... +double GetMarketCCI( + const int bar_index, + const int marketLen, + const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE +) { + // + double result = 0; + + // + result = iCCI( + _Symbol, + _Period, + marketLen, + appliedPrice, + bar_index + ); + + // + return result; +} + +// +// this function check crossing up two Buffers ... +bool IsCrossedOver( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] > arr2[index1]) && !(arr1[index2] > arr2[index2]); + + // + return result; +} + +// +// this function check crossing down two Buffers ... +bool IsCrossedUnder( + double &arr1[], + double &arr2[], + int index1, + int index2 = -1 +) { + // + // Normalize Index 2 Value ... + if (index2 < 0) { + index2 = index1 + 1; + } + + // + bool result = (arr1[index1] < arr2[index1]) && !(arr1[index2] < arr2[index2]); + + // + return result; +} + +// +// Convert points to Actual Point ... +double PointsToDouble(int points) { + // + double result = points * _Point; + return result; +} + +// +// Converts Pips to Points ... +int PipsToPoints(int pips) { + // + int result = pips * ((_Digits == 3 || _Digits == 5) ? 10 : 1); + return result; +} + +// +// Converts Pips to Double ... +double PipsToDouble(int pips) { + // + double result = PointsToDouble(PipsToPoints(pips)); + return result; +} + +// +// Converts Double Value to Pips ... +int PriceToPips(double value) { + // + if (value <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + int result = (int)(value / pipValue); + + // + return result; +} + +// +// Converts Pips to Double ... +double PipsToPrice(int pips) { + // + if (pips <= 0) { + return 0; + } + + // + double pipValue = _Point * MathPow(10, _Digits); + double result = pipValue * pips; + + // + return result; +} + +// +// Generate ATR StopLoss Value ... +double CalculateATRSL( + int period, + double multiplier +) { + // + if (period <= 0 || multiplier <= 0) { + return 0; + } + + // + double atrValue = iATR( + _Symbol, + _Period, + period, + 0 + ); + + // + double result = atrValue * multiplier; + + // + return result; +} + +// +// Detect Candle Type ... +// Bullish => means close > open ... +bool IsBullishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBullishCandle( + open, + close + ); + + // + return result; +} + +bool IsBullishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open < close; + + // + return result; +} + +// +// Detect Candle Type ... +// Bearish => means close < open ... +bool IsBearishCandle( + const int bar_index +) { + // + // Temp Result ... + bool result = false; + + // + if (bar_index < 0) { + return result; + } + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + result = IsBearishCandle( + open, + close + ); + + // + return result; +} + +bool IsBearishCandle( + const double open, + const double close +) { + // + // Temp Result ... + bool result = false; + + // + result = open > close; + + // + return result; +} + +// +// Retrieve a Candle Info ... +XOHCL GetCandleModel( + const int bar_index +) { + // + XOHCL result = {}; + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + result.high = high; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + result.open = open; + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + result.close = close; + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + result.low = low; + + // + return result; +} + +// +// Retrieve Market Current Prices for Signals ... +XPrice GetPrice() { + // + XPrice result = {}; + + // + RefreshRates(); + + // + double askPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double bidPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double priceGap = MathAbs(bidPrice - askPrice); + + // + result.askPrice = askPrice; + result.bidPrice = bidPrice; + result.priceGap = priceGap; + + // + result.longEntry = askPrice; + result.longExit = bidPrice; + + // + result.shortEntry = bidPrice; + result.shortExit = askPrice; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBullishDetected( + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double shpDetectMultipliers // Sharp Detect Multiplier +) { + // + bool result = false; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double minValue = 0; + double maxValue = 0; + int positionedLength = bar_index + marketLen; + + // + for (int i = bar_index; i < positionedLength; i++) { + // + double cHigh = iHigh( + _Symbol, + _Period, + i + ); + + // + double cLow = iLow( + _Symbol, + _Period, + i + ); + + // + minValue += MathMin(cLow, cHigh); + maxValue += MathMax(cLow, cHigh); + } + + // + double minAvg = minValue / positionedLength; + double maxAvg = maxValue / positionedLength; + + // + double shpValue = shpDetectMultipliers * _Point; + + // + result = (low - minAvg) > shpValue; + + // + int index = bar_index; + while ( + index < positionedLength + || !result + ) { + // + low = iLow( + _Symbol, + _Period, + index + ); + + // + result = result + || (low - minAvg) > shpValue; + + // + index++; + }; + + // + return result; +} + +// +// Detect Market Has Sharp Bullish or not ... +bool IsSharpBearishDetected( + const int bar_index, // Bar Index ... + const int marketLen, // Market Length ... + // + const double shpDetectMultipliers // Sharp Detect Multiplier +) { + // + bool result = false; + + // + double open = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double close = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double high = iHigh( + _Symbol, + _Period, + bar_index + ); + + // + double low = iLow( + _Symbol, + _Period, + bar_index + ); + + // + double minValue = 0; + double maxValue = 0; + int positionedLength = bar_index + marketLen; + + // + for (int i = bar_index; i < positionedLength; i++) { + // + double cHigh = iHigh( + _Symbol, + _Period, + i + ); + + // + double cLow = iLow( + _Symbol, + _Period, + i + ); + + // + minValue += MathMin(cLow, cHigh); + maxValue += MathMax(cLow, cHigh); + } + + // + double minAvg = minValue / positionedLength; + double maxAvg = maxValue / positionedLength; + + // + double shpValue = shpDetectMultipliers * _Point; + + // + result = (high - maxAvg) > shpValue; + + // + int index = bar_index; + while ( + index < positionedLength + || !result + ) { + // + high = iHigh( + _Symbol, + _Period, + index + ); + + // + result = result + || (high - maxAvg) > shpValue; + + // + index++; + }; + + // + return result; +} + +// +// Retrieve Highest High Value based on Given Market ... +double GetMarketHighestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Low Value based on Given Market ... +double GetMarketHighestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Open Value based on Given Market ... +double GetMarketHighestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Highest Close Value based on Given Market ... +double GetMarketHighestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iHighest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Low Value based on Given Market ... +double GetMarketLowestLow( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_LOW, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iLow( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest High Value based on Given Market ... +double GetMarketLowestHigh( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_HIGH, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iHigh( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Open Value based on Given Market ... +double GetMarketLowestOpen( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_OPEN, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iOpen( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Retrieve Lowest Close Value based on Given Market ... +double GetMarketLowestClose( + // + const int bar_index, // Bar Index ... + const int marketLen // Market Length ... +) { + // + // Empty Result ... + double result = 0.0; + + // + // Retrieve Desired Bar Index ... + int foundedBarIndex = iLowest( + _Symbol, + _Period, + MODE_CLOSE, + marketLen, + bar_index + ); + + // + // Retrieve Price ... + result = iClose( + _Symbol, + _Period, + foundedBarIndex + ); + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// less than given price ... +double GetLowLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Low Price is +// great than given price ... +double GetLowGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iLow( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetLowGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iLow( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// less than given price ... +double GetHighLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's High Price is +// great than given price ... +double GetHighGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iHigh( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetHighGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iHigh( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Open Price is +// less than given price ... +double GetOpenGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iOpen( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetOpenGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iOpen( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// less than given price ... +double GetCloseLessCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result >= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseLessCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP >= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Find last Candle which it's Close Price is +// great than given price ... +double GetCloseGreatCandlePrice( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int index = bar_index + 1; + double result = iClose( + _Symbol, + _Period, + index + ); + + // + while (result <= price) { + // + index++; + + // + result = iLow( + _Symbol, + _Period, + index + ); + } + + // + return result; +} +int GetCloseGreatCandleIndex( + // + const int bar_index, // Bar Index ... + const double price // Position Open Price ... +) { + // + int result = bar_index + 1; + double cP = iClose( + _Symbol, + _Period, + result + ); + + // + while (cP <= price) { + // + result++; + + // + cP = iLow( + _Symbol, + _Period, + result + ); + } + + // + return result; +} + +// +// Get Slope of a Line by it's two Point ... +double GetSlope( + double x1, + double y1, + double x2, + double y2 +) { + // + double result = (y2 - y1)/MathAbs(x2 - x1); + return result; +} +// +// END Functions ... +// \ No newline at end of file diff --git a/Libraries/x-saherelm.log.lib.mq4 b/Libraries/x-saherelm.log.lib.mq4 new file mode 100644 index 0000000..066b3f7 --- /dev/null +++ b/Libraries/x-saherelm.log.lib.mq4 @@ -0,0 +1,91 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Draw Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Log Tag ... +static string logTag = ""; + +// +// Enable or Disable Logging ... +static bool enableLogging = false; + +// +// Start Log Messages ... +// + +// +// Logging a Message, specified for this EA ... +// using provided LogTag ... +void LogMessage(string message) { + // + if (!enableLogging) { + return; + } + + // + Print(logTag, " > ", message); +} + +// +// this used for logging series ... +void LogSeries( + double &series[], // which series to Log ... + int length = 0, // number of items to Log, 0 means all ... + int skip = 0 // number of items which skip before logging ... +) { + // + string msg = ""; + + // + int seriesSize = ArraySize(series); + if ( + skip < 0 + || length < 0 + || seriesSize == 0 + || skip > seriesSize + || skip + length > seriesSize + ) { + return; + } + + // + length = length == 0 ? + seriesSize : + length; + int start = skip > 1 ? + skip - 1 : + skip == 1 ? + 1 : + 0; + + // + // Loop through series items ... + for (int i = start; i < start + length; i++) { + // + msg += StringConcatenate( + "i[", i, "]: ", series[i], ", " + ); + } + + // + LogMessage(msg); +} +// +// End Log Messages ... +// + diff --git a/Libraries/x-saherelm.models.lib.mq4 b/Libraries/x-saherelm.models.lib.mq4 new file mode 100644 index 0000000..6899040 --- /dev/null +++ b/Libraries/x-saherelm.models.lib.mq4 @@ -0,0 +1,155 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Models Global Library +// --------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// START STATIC Variables ... +// +// +static int totalSignals = 0; +static int totalLongSignals = 0; +static int totalShortSignals = 0; + +// +static double initialBalance = 0; + +// +static int countedBars = 0; +static bool isNewBar = false; +static bool isNewDay = false; +static bool isNewHour = false; +// +// END STATIC Variables ... +// + +// +// Start Models ... +// +// +// Signal Providers ... +enum ENUM_X_SIGNAL_PROVIDER { + X_UNKNOWN_PROVIDER, + X_XXX_PROVIDER, + X_XR_PROVIDER, + X_XTPW_PROVIDER +}; + +// +// these are different signal types ... +enum ENUM_X_SIGNAL_TYPE { + X_SIGNAL_NONE, + X_SIGNAL_LONG, + X_SIGNAL_SHORT, +}; + +// +// Model Market Highs and Lows ... +struct XPvtState { + // + double hh; + double ho; + double hc; + double hl; + + // + double ll; + double lo; + double lc; + double lh; +}; + +// +// we Model each signals as this type ... +struct XSignal { + // + // Signal Symbol ... + string symbol; + + // + // Signal Type ... + ENUM_X_SIGNAL_TYPE type; + + // + // Signal ID ... + int id; + + // + // Signal Ticket Number, when Opening Trade ... + int ticket; + + // + // Signal Provider ... + ENUM_X_SIGNAL_PROVIDER provider; + + // + // Target Point ... + double tp; + + // + // Stop Loss ... + double sl; + + // + // Signal Entry Price ... + double entry; + + // + // Signalling Time ... + datetime time; + + // + // Signal Comments ... + string comment; + + // + // Signal TAG ... + string tag; +}; + +// +// this is Signal Request Response model ... +struct XSignalRequest { + bool hasSignal; + XSignal signal; + ENUM_X_SIGNAL_TYPE type; + ENUM_X_SIGNAL_PROVIDER provider; +}; + +// +struct XRState { + // + datetime start; + int length; + + // + double hh; + double ll; + double mid; +}; + +// +struct XTPOWState { + // + double powerUp; + double powerDown; + + // + double signal; +}; +// +// End Models ... +// diff --git a/Libraries/x-saherelm.signal.lib.mq4 b/Libraries/x-saherelm.signal.lib.mq4 new file mode 100644 index 0000000..097ce74 --- /dev/null +++ b/Libraries/x-saherelm.signal.lib.mq4 @@ -0,0 +1,1756 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 Signal Draw Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// Includes Drawing library ... +#include "../Libraries/x-saherelm.draw.lib.mq4" + +// +#include "../Libraries/x-saherelm.x.signal.lib.mq4" +#include "../Libraries/x-saherelm.xr.signal.lib.mq4" +#include "../Libraries/x-saherelm.xtpw.signal.lib.mq4" + +// +// START Global Requirement Functions ... +// +// +// END Global Requirement Functions ... +// + +// +// START Signal Related Functions ... +// +// +// Retrieve Signal Bar Index ... +int GetSignalBarIndex(XSignal &signal) { + // + // Temp Result ... + int result = -1; + + // + // Retriev Signal Bar Index ... + result = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + return result; +} + +// +string GetSignalProviderIdentifier( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + string result = ""; + + // + switch (provider) { + // + case X_XXX_PROVIDER: + result = "XXX"; + break; + + // + case X_XR_PROVIDER: + result = "XR"; + break; + + // + case X_XTPW_PROVIDER: + result = "XTPW"; + break; + + // + default: + result = ""; + break; + } + + // + return result; +} + +// +ENUM_X_SIGNAL_PROVIDER GetSignalProvider(string identifier) { + // + ENUM_X_SIGNAL_PROVIDER result = X_UNKNOWN_PROVIDER; + + // + if ( + StringFind( + identifier, + GetSignalProviderIdentifier(X_XXX_PROVIDER) + ) > -1 + ) { + result = X_XXX_PROVIDER; + } else if ( + StringFind( + identifier, + GetSignalProviderIdentifier(X_XR_PROVIDER) + ) > -1 + ) { + result = X_XR_PROVIDER; + } else if ( + StringFind( + identifier, + GetSignalProviderIdentifier(X_XTPW_PROVIDER) + ) > -1 + ) { + result = X_XTPW_PROVIDER; + } + + // + return result; +} + +// +// Retrieve Signal Lots Per Trade ... +double GetSignalLottage( + const XSignal &signal, + const double defLotsPerTrade +) { + // + double result = defLotsPerTrade; + + // + bool isLong = signal.type == X_SIGNAL_LONG; + + // + switch (signal.provider) { + // + case X_XR_PROVIDER: + // + result = isLong ? + xRLongLotsPerTradePercent : + xRShortLotsPerTradePercent + ; + break; + + // + case X_XXX_PROVIDER: + // + result = isLong ? + xLongLotsPerTradePercent : + xShortLotsPerTradePercent + ; + break; + + // + case X_XTPW_PROVIDER: + // + result = isLong ? + xTPWLongLotsPerTradePercent : + xTPWShortLotsPerTradePercent + ; + break; + } + + // + return result; +} + +// +// Draw Specific Range On Chart ... +void DrawRange( + const XRange &range, + const long chartID = 0, + const int subWindowID = 0, + const string tag = "", + const color clr = clrYellow +) { + // + // Loop through Levels Count ... + for (int i = 0; i <= range.levels; i++) { + // + datetime time1 = iTime( + _Symbol, + _Period, + 1 + ); + + // + datetime time2 = iTime( + _Symbol, + _Period, + 0 + ); + + // + double price = range.lowestLow + (i * range.rate); + + // + string lbl = StringConcatenate( + tag, + "_XRL_", + price + ); + + // + DrawTrendLine( + chartID, + lbl, + subWindowID, + time1, + price, + time2, + price, + clr, + STYLE_DOT + ); + } +} + +// +// Draw Signal Shapes on Chart ... +bool DrawSignal( + const XSignal &signal, + long chartID = 0, + int subWindowID = 0, + const double positionThresholdFactor = 10, + string longSignalLabel = "X-Long", + color longSignalColor = clrAqua, + string shortSignalLabel = "X-Short", + color shortSignalColor = clrFuchsia +) { + // + // Generate isLongSignal Var ... + bool isLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Signal Bar Index ... + int bar_index = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // START Draw Signal Arrow ... + // + // + // Arrow Shape Name ... + string arrowName = StringConcatenate(signal.tag, "_Arrow_", signal.id); + + // + // Arrow Price ... + double arrowPrice = 0; + if (isLongSignal) { + // + arrowPrice = iLow( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice - (positionThresholdFactor * _Point); + } else { + // + arrowPrice = iHigh( + _Symbol, + _Period, + bar_index + 1 + ); + + // + arrowPrice = arrowPrice + (positionThresholdFactor * _Point); + } + + // + // Arrow Code ... + uchar arrowCode = isLongSignal ? SYMBOL_ARROWUP : SYMBOL_ARROWDOWN; + + // + // Arrow Anchor Point ... + ENUM_ARROW_ANCHOR arrowAnchorPoint = isLongSignal ? ANCHOR_BOTTOM : ANCHOR_TOP; + + // + // Arrow Color ... + color arrowColor = isLongSignal ? longSignalColor : shortSignalColor; + + // + // Draw Signal Arrow Shape ... + bool result = DrawArrow( + chartID, + arrowName, + subWindowID, + signal.time, + arrowPrice, + arrowCode, + arrowAnchorPoint, + arrowColor + ); + // + // END Draw Signal Arrow ... + // + + // + // START Draw Signal SL/TP ... + // + string slLineName = StringConcatenate(signal.tag, "_SL_", signal.id); + string tpLineName = StringConcatenate(signal.tag, "_TP_", signal.id); + string entryLineName = StringConcatenate(signal.tag, "_ENTRY_", signal.id); + + // + color slColor = shortSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color tpColor = longSignalColor; // isLongSignal ? shortSignalColor : longSignalColor; + color entryColor = clrGreen; + + // + datetime time1 = iTime( + _Symbol, + _Period, + bar_index + 1 + ); + + // + // Draw Enrty Price ... + result = DrawTrendLine( + chartID, + entryLineName, + subWindowID, + time1, + signal.entry, + signal.time, + signal.entry, + entryColor, + STYLE_SOLID, + 2 + ); + + // + // Draw Signal SL ... + if (signal.sl > 0) { + // + result = DrawTrendLine( + chartID, + slLineName, + subWindowID, + time1, + signal.sl, + signal.time, + signal.sl, + slColor, + STYLE_SOLID, + 2 + ); + } + + // + // Draw Signal TP ... + if (signal.tp > 0) { + // + result = DrawTrendLine( + chartID, + tpLineName, + subWindowID, + time1, + signal.tp, + signal.time, + signal.tp, + tpColor, + STYLE_SOLID, + 2 + ); + } + // + // END Draw Signal SL/TP ... + // + + // + // Start Draw Signal Label ... + // + // + string labelName = StringConcatenate(signal.tag, "_Label_", signal.id); + + // + double labelPrice = isLongSignal ? arrowPrice - (positionThresholdFactor * _Point) : arrowPrice + (positionThresholdFactor * _Point); + + // + string labelText = isLongSignal ? longSignalLabel : shortSignalLabel; + labelText = StringConcatenate( + labelText, + "_", + GetSignalProviderIdentifier(signal.provider) + ); + + // + result = DrawText( + chartID, + labelName, + subWindowID, + signal.time, + labelPrice, + labelText, + "Arial", + 8, + arrowColor, + 0, + ANCHOR_CENTER + ); + // + // End Draw Signal Label ... + // + + // + return result; +} + +// +// Trade on Specific Signal ... +bool TradeSignal( + XSignal &signal, + // + double volumePercent, + // + // Long ... + const string longSignalLabel, + const color longSignalColor, + // + // Short ... + const string shortSignalLabel, + const color shortSignalColor +) { + // + // Temp Result ... + bool result = false; + + // + if (initialBalance == 0) { + initialBalance = AccountInfoDouble(ACCOUNT_BALANCE); + } + + // + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + int openPositions = CountOpenTrades(); + double volume = (volumePercent * initialBalance); + + // + if ( + signal.type != X_SIGNAL_LONG && + signal.type != X_SIGNAL_SHORT + ) { + return result; + } + + // + bool hasLongSignal = signal.type == X_SIGNAL_LONG; + + // + // Check TP and Entry Price ... + if ( + ( + hasLongSignal + && signal.entry > signal.tp + ) || + ( + !hasLongSignal + && signal.entry < signal.tp + ) + ) { + return result; + } + + // + // Order Operation ... + int operation = hasLongSignal ? + OP_BUY : + OP_SELL; + + // + // Detect Trade Color ... + color clr = hasLongSignal ? + longSignalColor : + shortSignalColor; + + // + // Generate Signal Comment ... + string label = hasLongSignal ? + longSignalLabel : + shortSignalLabel; + + // + // Generate Signal Comment ... + string comment = StringConcatenate( + signal.tag, + "_", signal.id, + "_", GetSignalProviderIdentifier(signal.provider), + "_", label + ); + + // + // Placing Order ... + int orderTicket = OrderSend( + _Symbol, + operation, + volume, + signal.entry, + 3, + signal.sl, + signal.tp, + comment, + signal.id, + 0, + clr + ); + + // + // Draw Signal Shape if Order Opened Successfully ... + if (orderTicket >= 0) { + // + signal.ticket = orderTicket; + + // + // Here i must to Draw Signal Shapes ... + bool isDrawn = DrawSignal( + signal, + 0, + 0, + 50, + longSignalLabel, // Long Signal Label ... + longSignalColor, + shortSignalLabel, // Short Signal Label ... + shortSignalColor + ); + + // + LogMessage( + StringConcatenate( + "Order [", orderTicket ,"]: Provided by: ", GetSignalProviderIdentifier(signal.provider) + ) + ); + + // + // TODO: here we have to check if there are another + // open positions which their entry price is bigger + // than current signal entry price, for long trades and + // their tp is high than current tp, ... + // close in profit trades or modify orders tp to current ... + // // + // if (CountOpenTrades() > 0) { + // // + // // Here we have to + // ModifyOpenTradesBasedOnCurrentTrade(signal); + // } + + // + result = true; + } + + // + return result; +} +// +// END Signal Related Functions ... +// + +// +// START Orders Functions ... +// +// +// Convert To XSignal Model ... +XSignal OrderToSignal() { + // + // Temp Result ... + XSignal result = {}; + result.type = X_SIGNAL_NONE; + + // + // Here we can get some usefull info based on selected order ... + double swap = OrderSwap(); + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + int magicNumber = OrderMagicNumber(); + double takeProfit = OrderTakeProfit(); + string comment = OrderComment(); + + // + ENUM_X_SIGNAL_PROVIDER provider = GetSignalProvider(comment); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // Conver Position to Signal ... + result.sl = stopLoss; + result.tp = takeProfit; + result.time = openTime; + result.symbol = _Symbol; + result.id = magicNumber; + result.comment = comment; + result.entry = openPrice; + result.provider = provider; + result.type = isLongOrder ? X_SIGNAL_LONG : X_SIGNAL_SHORT; + + // + return result; +} + +// +// START Count Orders ... +// +// +// Count Open Positions ... +int CountOpenTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if (OrderSymbol() == _Symbol) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Long Positions ... +int CountOpenLongTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_BUY + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} + +// +// Count Open Short Positions ... +int CountOpenShortTrades() { + // + int result = 0; + + // + // Loop through Orders ... + for (int i = 0; i < OrdersTotal(); i++) { + // + // Select indexed Order ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order ... + if ( + OrderSymbol() == _Symbol + && OrderType() == OP_SELL + ) { + result++; + } + } + } + + // + // Return Result ... + return result; +} +// +// END Count Orders ... +// + +// +// START Close Orders ... +// +// +// Close All Open Trades ... +bool CloseAllTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + + // + return result; +} + +// +bool CloseAllProviderTrades( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal(); + + // + if (signal.provider == provider) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +bool CloseAllProviderLongTrades( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal(); + + // + if ( + signal.provider == provider + && signal.type == X_SIGNAL_LONG + ) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +bool CloseAllProviderShortTrades( + ENUM_X_SIGNAL_PROVIDER provider +) { + // + bool result = false; + + // + // Loop through Signals ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + XSignal signal = OrderToSignal(); + + // + if ( + signal.provider == provider + && signal.type == X_SIGNAL_SHORT + ) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Provider Long Trades Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Long Trades ... +bool CloseAllLongTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Long Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Open Short Trades ... +bool CloseAllShortTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + if (!isLongOrder) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of All Short Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In Profit Trades ... +bool CloseAllInProfitTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit > 0 + && profit > 50 * _Point + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InProfit Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All In DrawDown Trades ... +bool CloseAllInDrawDownTrades() { + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if (profit < 0) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close Biggest In DrawDown Trades ... +bool CloseBiggestDrawDownTrade() { + // + // Loop through all Positions ... + bool result = false; + double drawDown = 0; + + // + // Find Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) > drawDown + ) { + drawDown = profit; + } + } + } + } + + // + // Close Biggest In DrawDown ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + if ( + profit < 0 + && MathAbs(profit) >= drawDown + ) { + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Max InDrawDown Trade Closing issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Long Time Trades ... +bool CloseAllLongTimeTrades( + const int passedCandles, + const ENUM_X_SIGNAL_PROVIDER provider = X_UNKNOWN_PROVIDER +) { + // + bool result = false; + + // + if (passedCandles <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + string comment = OrderComment(); + + // + ENUM_X_SIGNAL_PROVIDER orderProvider = GetSignalProvider(comment); + bool isProviderVerified = + provider == X_UNKNOWN_PROVIDER ? + true : + orderProvider != X_UNKNOWN_PROVIDER + && orderProvider == provider + ; + + // + if ( + profit < 0 + && isProviderVerified + && openBarIndex - currentBarIndex >= passedCandles + // || ( + // profit > 0.5 + // && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 3) + // ) + ) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Long Time issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + // else if ( + // openTrades > 0 + // && openBarIndex - currentBarIndex >= passedCandles - (passedCandles / 2) + // ) { + // result = CloseAllInProfitTrades() + // && CloseBiggestDrawDownTrade(); + // } + } + } + } + + // + return result; +} + +// +// Close all trades which passed Maximum Drawdown ... +bool CloseAllMaximumDrawDownPassedTrades( + const double maxDrDownPercentPerPTrade, + const ENUM_X_SIGNAL_TYPE type = X_SIGNAL_NONE, + const ENUM_X_SIGNAL_PROVIDER provider = X_UNKNOWN_PROVIDER +) { + // + if ( + initialBalance <= 0 + || maxDrDownPercentPerPTrade <= 0 + ) { + return false; + } + + // + // Retrieve Account Balance ... + double balance = AccountInfoDouble(ACCOUNT_BALANCE); + double maxAllowedDrawDown = -1 * (initialBalance * maxDrDownPercentPerPTrade); + + // + // Loop through all Positions ... + bool result = false; + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + string comment = OrderComment(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + bool isTypeVerified = + type == X_SIGNAL_NONE ? + true : + ( isLongOrder + && type == X_SIGNAL_LONG + ) || ( + !isLongOrder + && type == X_SIGNAL_SHORT + ) + ; + + // + ENUM_X_SIGNAL_PROVIDER orderProvider = GetSignalProvider(comment); + bool isProviderVerified = + provider == X_UNKNOWN_PROVIDER ? + true : + orderProvider != X_UNKNOWN_PROVIDER + && orderProvider == provider + ; + + // + if ( + profit < 0 + && isTypeVerified + && isProviderVerified + && MathAbs(profit) >= MathAbs(maxAllowedDrawDown) + ) { + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Maximum DarwDown issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } + } + } + } + + // + return result; +} + +// +// Close All Trades Which Opens before Specified Length ... +bool CloseAllTradesWhichOpenInPastMarketLength( + const int marketLen +) { + // + bool result = false; + + // + if (marketLen <= 0) { + return result; + } + + // + int currentBarIndex = iBarShift( + _Symbol, + _Period, + TimeCurrent() + ); + + // + int openTrades = CountOpenTrades(); + + // + // Loop through all Positions ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + datetime openTime = OrderOpenTime(); + int openBarIndex = iBarShift( + _Symbol, + _Period, + openTime + ); + + // + if (openBarIndex <= currentBarIndex + marketLen) { + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // Since because of equity ... + // we have to ckose allpositions ... + bool isOrderClosed = OrderClose( + ticket, + lots, + closePrice, + clrYellow + ); + + // + if (isOrderClosed) { + // + LogMessage( + StringConcatenate( + "Order [", ticket, "] Closed because of Market Reverse issue ..." + ) + ); + } + + // + result = + result + || isOrderClosed; + } else if (openTrades > 0) { + // + // Close all InProfit Trdes and Biggest InDrawDown Trades ... + // result = CloseAllInProfitTrades(); + // && CloseBiggestDrawDownTrade(); + } + } + } + } + + // + return result; +} +// +// END Close Orders ... +// + +// +// START Modify Orders ... +// +// +void ModifyAllPriceLesserOpenTrades( + const XSignal &signal +) { + // + // Loop through all Open Trades ... + for (int i = OrdersTotal(); i >= 0; i--) { + // + // Check Order Selected or not ... + if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { + // + // Check Order Symbol is same as Current Symbol ... + if (OrderSymbol() == _Symbol) { + // + double lots = OrderLots(); + int ticket = OrderTicket(); + double profit = OrderProfit(); + double stopLoss = OrderStopLoss(); + double openPrice = OrderOpenPrice(); + datetime openTime = OrderOpenTime(); + double takeProfit = OrderTakeProfit(); + + // + // find order type ... + bool isLongOrder = OrderType() == OP_BUY; + + // + // find close price ... + double closePrice = isLongOrder ? + SymbolInfoDouble(_Symbol, SYMBOL_BID) : + SymbolInfoDouble(_Symbol, SYMBOL_ASK); + + // + // When new Signal Comming with price less than + // currently open trade and tp less than currently + // open trade, this means a market change happens ... + // here we can Close InProfit Trades or Modify Trades TP ... + if ( + ( + openPrice < signal.entry + || MathAbs(openPrice - signal.entry) < 300 * _Point + ) + && takeProfit > signal.tp + ) { + bool result = OrderModify( + ticket, + openPrice, + signal.sl, + signal.tp, + clrYellow + ); + } + } + } + } +} + +// +void ModifyOpenTradesBasedOnCurrentTrade( + const XSignal &signal +) { + // + ModifyAllPriceLesserOpenTrades(signal); +} +// +// END Modify Orders ... +// +// +// END Orders Functions ... +// + +// +// START Signal Conditions ... +// +// +// Clear Signal Conditions ... +void ClearSignalConditions() { + // + ClearLongSignalConditions(); + ClearShortSignalConditions(); +} + +// +// Clear all Conditions Waiter for Long Signals ... +void ClearLongSignalConditions() { + // + ClearXLongSignalConditions(); + ClearXRLongSignalConditions(); + ClearXTPWLongSignalConditions(); +} + +// +// Clear all Conditions Waiter for Short Signals ... +void ClearShortSignalConditions() { + // + ClearXShortSignalConditions(); + ClearXRShortSignalConditions(); + ClearXTPWShortSignalConditions(); +} +// +// END Signal Conditions ... +// diff --git a/Libraries/x-saherelm.x.signal.lib.mq4 b/Libraries/x-saherelm.x.signal.lib.mq4 new file mode 100644 index 0000000..834ddb1 --- /dev/null +++ b/Libraries/x-saherelm.x.signal.lib.mq4 @@ -0,0 +1,1063 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 X Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Inputs ... +// +// +input string xStarter = "- X Signal Provider -"; // ---> X Signal Provider <--- + +// +input bool enableXSignalling = true; // X Signalling Enable + +// +input bool enableXLong = true; // X Signalling Enable Long +input bool enableXShort = true; // X Signalling Enable Short + +// +input double xShortR2R = 3; // X Short Risk To Reward Ratio +input double xShortLotsPerTradePercent = 0.0002; // X Lots Percent per Short Trades +input double xShortMaxDrawdownPerTradePercent = 0.4; // X Max Allowed DrawDown Percent per Short Trade + +// +input double xLongR2R = 3; // X Long Risk To Reward Ratio +input double xLongLotsPerTradePercent = 0.0002; // X Lots Percent per Short Trades +input double xLongMaxDrawdownPerTradePercent = 0.4; // X Max Allowed DrawDown Percent per Long Trade + +// +input double xSharpDetectorFactor = 700; // X Sharp Detection Factor + +// +input int xMaximumCandlesPerTrade = 206; // X Maximum Candles which a Trade can open + +// +input int xOscillatorLength = 7; // X Oscillator Length + +// +input double xPSarStep = 0.02; // X Parabolic Sar Step +input double xPSarMaximum = 0.2; // X Parabolic Sar Maximum + +// +input int xRangeMarketLength = 5; // X Range Detector Length + +// +input int xSwingLength = 7; // X Signal Swing Length +// +// END Inputs ... +// + +// +// START Global Requirement Functions ... +// +// +// X Based Signal Conditions ... +struct XSignalConditions { + datetime startTime; + datetime signalTime; + datetime entryTime; +}; + +// +struct XMarketState { + double psar; + double fast; + double slow; + double open; + double verifier; + double oscillator; + double oscillatorVerifier; +}; + +// +static XSignalConditions xLongConds; +static bool xCloseLongTrades = false; +static bool xWaitForLongSignals = true; + +// +static XSignalConditions xShortConds; +static bool xCloseShortTrades = false; +static bool xWaitForShortSignals = true; + +// +// Count Number of Closed Maximum DrawDown Trades ... +static int xFailedSignals = 0; + +// +datetime lastVerifierTouched; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckXSignalHandler( + const int bar_index +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + // + if ( + !enableXSignalling + || !(enableXLong || enableXShort) + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XOHCL candle = GetCandleModel(bar_index); + XOHCL pCandle = GetCandleModel(bar_index + 1); + XTPOWState tPowState = GetXTPowState( + bar_index + 1, + xSwingLength + ); + + // + XMarketState state = GetXMarketState( + bar_index + 1 + ); + + // + // Check Verifier Last Touched ... + bool isVerifierTouched = pCandle.high > state.verifier + && pCandle.low < state.verifier; + + // + // Disable Signals if a signal Failed ... + if (xFailedSignals) { + // + // TODO: Complete this ... + } + + // + // Enable Or Disable Signalling ... + if (isVerifierTouched) { + // + lastVerifierTouched = barTime; + + // + if (xWaitForLongSignals) { + xWaitForLongSignals = false; + } + + // + if (xWaitForShortSignals) { + xWaitForShortSignals = false; + } + } else { + // + int lastVerifierTouchedBarIndex = iBarShift( + _Symbol, + _Period, + lastVerifierTouched + ); + + // + int distance = MathAbs(lastVerifierTouchedBarIndex - bar_index); + + // + if ( + !xWaitForLongSignals + && distance > (xSwingLength * 2) + ) { + xWaitForLongSignals = true; + } + + // + if ( + !xWaitForShortSignals + && ( + distance > (xSwingLength * 2) + || ( + tPowState.powerDown > tPowState.powerUp + && tPowState.powerDown < 49 + ) + ) + ) { + xWaitForShortSignals = true; + } + } + + // + // Close All Long Open Trades ... + if ( + tPowState.powerDown > 55 + && tPowState.powerDown > tPowState.powerUp + ) { + // xCloseLongTrades = true; + } +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXLongSignalConditions( + const int bar_index +) { + // + if ( + !enableXLong + || !enableXSignalling + || !xWaitForLongSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + bool isCrossOver = false; + bool isCrossUnder = false; + + // + XMarketState cState = GetXMarketState(1); + XMarketState pState = GetXMarketState(2); + + // + isCrossUnder = + cState.fast < cState.slow + && !(pState.fast < pState.slow) + ; + + // + isCrossOver = + cState.fast > cState.slow + && !(pState.fast > pState.slow) + ; + + // + if ( + isCrossUnder + && xLongConds.startTime == 0 + ) { + // + xLongConds.startTime = barTime; + return; + } + + // + if ( + isCrossOver + && xLongConds.startTime > 0 + && xLongConds.signalTime == 0 + ) { + // + xLongConds.signalTime = barTime; + xLongConds.entryTime = barTime; + return; + } +} + +// +// Check and Fill Short Signal Conditions ... +void CheckXShortSignalConditions( + const int bar_index +) { + // + if ( + !enableXShort + || !enableXSignalling + || !xWaitForShortSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + bool isCrossOver = false; + bool isCrossUnder = false; + + // + XMarketState cState = GetXMarketState(1); + XMarketState pState = GetXMarketState(2); + + // + isCrossUnder = + cState.fast < cState.slow + && !(pState.fast < pState.slow) + ; + + // + isCrossOver = + cState.fast > cState.slow + && !(pState.fast > pState.slow) + ; + + // + if ( + isCrossOver + && xShortConds.startTime == 0 + ) { + // + xShortConds.startTime = barTime; + return; + } + + // + if ( + isCrossUnder + && xShortConds.startTime > 0 + && xShortConds.signalTime == 0 + ) { + // + xShortConds.signalTime = barTime; + xShortConds.entryTime = barTime; + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if ( + !enableXSignalling + || !(enableXLong || enableXShort) + ) { + return result; + } + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + if (requestLong) { + // + if ( + !ValidateXLongConditions() + ) { + return result; + } + } else { + // + if ( + !ValidateXShortConditions() + ) { + return result; + } + } + + // + // Price Calculations ... + // + RefreshRates(); + + // + double askPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_ASK + ); + + // + double bidPrice = SymbolInfoDouble( + _Symbol, + SYMBOL_BID + ); + + // + double entryPrice = requestLong ? + askPrice : + bidPrice; + + // + double exitPrice = requestLong ? + bidPrice : + askPrice; + + // + double priceGap = MathAbs(entryPrice - exitPrice); + + // + double ll = + // + GetMarketLowestLow( + bar_index, + xSwingLength + ) + ; + + // + double hh = + // + GetMarketHighestHigh( + bar_index, + xSwingLength + ) + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = requestLong ? + MathMin(openPrice, closePrice) - ll : + hh - MathMax(openPrice, closePrice) + ; + + // + double reward = + requestLong ? + risk * xLongR2R : + risk * xShortR2R + ; + + // + double sl = requestLong ? + 0 : + 0; + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward + ; + + // + XRState range = GetXRange( + bar_index, + xRangeMarketLength + ); + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XXX_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XXX_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXLongConditions() { + // + if ( + !enableXLong + || !enableXSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xLongConds.startTime > 0 + && xLongConds.signalTime > 0 + && xLongConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.signalTime + ); + + // + int entryBarIndex = iBarShift( + _Symbol, + _Period, + xLongConds.entryTime + ); + + // + isBLFilled = + // + xLongConds.signalTime > xLongConds.startTime + && xLongConds.entryTime >= xLongConds.signalTime + // && MathAbs(signalBarIndex - startBarIndex) >= 1 + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXLongSignalConditions(); + } + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXShortConditions() { + // + if ( + !enableXShort + || !enableXSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xShortConds.startTime > 0 + && xShortConds.signalTime > 0 + && xShortConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + int startBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.startTime + ); + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.signalTime + ); + + // + int entryBarIndex = iBarShift( + _Symbol, + _Period, + xShortConds.entryTime + ); + + // + isBLFilled = + // + xShortConds.signalTime > xShortConds.startTime + && xShortConds.entryTime >= xShortConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xWaitForShortSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXShortSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXLongSignalConditions() { + // + xLongConds.startTime = 0; + xLongConds.entryTime = 0; + xLongConds.signalTime = 0; +} + +// +// Clear Short Signal Conditions for New One ... +void ClearXShortSignalConditions() { + // + xShortConds.startTime = 0; + xShortConds.entryTime = 0; + xShortConds.signalTime = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForXSignals( + const XSignal &signal +) { + // + bool result = false; + + // + if ( + !enableXSignalling + || !(enableXLong || enableXShort) + ) { + return result; + } + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // XOHCL candle = GetCandleModel(0); + XOHCL candle = GetCandleModel(signalBarIndex); + XOHCL pCandle = GetCandleModel(signalBarIndex + 1); + + // + // Retrieve Range ... + XRState range = GetXRange( + signalBarIndex, + xRangeMarketLength + ); + + // + // Retrive XMarket States ... + XMarketState xState0 = GetXMarketState(signalBarIndex); + XMarketState xState1 = GetXMarketState(signalBarIndex + 1); + XMarketState xState2 = GetXMarketState(signalBarIndex + 2); + XMarketState xStateLast = GetXMarketState(signalBarIndex + xSwingLength); + + // + // Retrieve Trend Powers ... + XTPOWState xTPow0 = GetXTPowState( + signalBarIndex, + xSwingLength + ); + XTPOWState xTPow1 = GetXTPowState( + signalBarIndex + 1, + xSwingLength + ); + + // + double hh = GetMarketHighestHigh( + signalBarIndex, + xSwingLength + ); + double ll = GetMarketLowestLow( + signalBarIndex, + xSwingLength + ); + double diffChange = (hh - ll); + bool isBigSharpOccured = + diffChange > (xSharpDetectorFactor * _Point) + ; + + // + bool isPSarVerified = false; + bool isTPowVerified = false; + bool isStateVerified = false; + bool isPriceVerified = false; + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + // Get Price Verification for Long ... + isPriceVerified = + // + // Starter ... + true + // + && !isBigSharpOccured + // + && signal.entry < hh + // + // && signal.entry < range.hh + // && signal.entry > range.mid + // // + // && candle.high > xState0.verifier + // && signal.entry > xState0.verifier + // + // && pCandle.low != ll + && pCandle.high != hh + ; + + // + int above20TPowers = 0; + double signalSlope = 0; + int tPowUnverifyConditions = 0; + int tPowUnverifyConditionsIdx = 0; + for (int i = signalBarIndex; i < signalBarIndex + xSwingLength; i++) { + // + XTPOWState iTPowState = GetXTPowState( + i, + xSwingLength + ); + + // + // Calculate Signal Slope ... + if (i == signalBarIndex) { + // + signalSlope = iTPowState.signal; + } else if (i == signalBarIndex + 1) { + // + signalSlope = GetSlope( + 1, + iTPowState.signal, + 2, + signalSlope + ); + } + + // + if ( + iTPowState.powerUp > iTPowState.powerDown + && MathMax(iTPowState.powerUp, iTPowState.powerDown) > 20 + ) { + above20TPowers++; + } + + // + if (tPowUnverifyConditionsIdx < 3) { + // + if ( + iTPowState.powerUp < iTPowState.powerDown + || iTPowState.signal > MathMax(iTPowState.powerUp, iTPowState.powerDown) + ) { + tPowUnverifyConditions++; + } + + // + tPowUnverifyConditionsIdx++; + } + } + + // + isTPowVerified = + above20TPowers > 1 + && tPowUnverifyConditions == 0 + ; + + // + isPSarVerified = + xState0.psar < signal.entry + && xState0.psar < candle.low; + + // + isStateVerified = + // + // Start ... + true + // + // && xState0.open < xState0.slow + ; + + // + result = + // + // Starter ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + isPSarVerified = + xState0.psar > signal.entry + && xState0.psar > candle.high + ; + + // + // Get Price Verification for Short ... + isPriceVerified = + // + // Starter ... + true + // + && !isBigSharpOccured + // + && signal.entry > ll + && pCandle.low != ll + ; + + // + int above20TPowers = 0; + double signalSlope = 0; + int tPowUnverifyConditions = 0; + int tPowUnverifyConditionsIdx = 0; + for (int i = signalBarIndex; i < signalBarIndex + xSwingLength; i++) { + // + XTPOWState iTPowState = GetXTPowState( + i, + xSwingLength + ); + + // + // Calculate Signal Slope ... + if (i == signalBarIndex) { + // + signalSlope = iTPowState.signal; + } else if (i == signalBarIndex + 1) { + // + signalSlope = GetSlope( + 1, + iTPowState.signal, + 2, + signalSlope + ); + } + + // + if ( + iTPowState.powerUp > iTPowState.powerDown + && MathMax(iTPowState.powerUp, iTPowState.powerDown) > 20 + ) { + above20TPowers++; + } + + // + if (tPowUnverifyConditionsIdx < 3) { + // + if ( + iTPowState.powerUp > iTPowState.powerDown + || iTPowState.signal < MathMax(iTPowState.powerUp, iTPowState.powerDown) + ) { + tPowUnverifyConditions++; + } + + // + tPowUnverifyConditionsIdx++; + } + } + + // + isTPowVerified = + above20TPowers < 1 + && tPowUnverifyConditions == 0 + && MathAbs(xTPow0.powerUp - xTPow0.powerDown) > 50 * _Point + ; + + // + isStateVerified = + // + // Start ... + true + // + // && (xStateLast.verifier - xState0.verifier) >= 0 + // + && xState0.verifier > signal.entry + // + && MathAbs(signal.entry - xState0.verifier) < (xSharpDetectorFactor * _Point) + ; + + // + result = + // + // Starter Condition ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } + + // + return result; +} +// +// END Functions ... +// + +// +// START Data Provider ... +// +XMarketState GetXMarketState( + const int bar_index +) { + // + XMarketState result = {}; + + // + double fast = GetMA( + bar_index, + xSwingLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double open = GetMA( + bar_index, + xSwingLength, + 0, + MODE_SMA, + PRICE_OPEN + ); + + // + double slow = GetMA( + bar_index, + xSwingLength * 2, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double oscillator = GetMA( + bar_index, + xSwingLength, + 0, + MODE_EMA, + PRICE_CLOSE + ); + + // + double oscillatorVerifier = GetMA( + bar_index, + xSwingLength, + 0, + MODE_EMA, + PRICE_WEIGHTED + ); + + // + int dailyCount = GetDailyCandleCount(); + double verifier = GetMA( + bar_index, + dailyCount, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double psar = iSAR( + _Symbol, + _Period, + xPSarStep, + xPSarMaximum, + bar_index + ); + + // + result.psar = psar; + result.fast = fast; + result.open = open; + result.slow = slow; + result.verifier = verifier; + result.oscillator = oscillator; + result.oscillatorVerifier = oscillatorVerifier; + + // + return result; +} +// +// END Data Provider ... +// diff --git a/Libraries/x-saherelm.xr.signal.lib.mq4 b/Libraries/x-saherelm.xr.signal.lib.mq4 new file mode 100644 index 0000000..53785cf --- /dev/null +++ b/Libraries/x-saherelm.xr.signal.lib.mq4 @@ -0,0 +1,1142 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 X Signal Global Library +// --------------------------------------------------- +// saherelm useful tools and definitions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Inputs ... +// +// +input string xRStarter = "- XR Signal Provider -"; // --> XR Signal Provider <-- + +// +input bool enableXRSignalling = false; // XR Signalling Enable + +// +input bool enableXRLong = true; // XR Signalling Enable Long +input bool enableXRShort = true; // XR Signalling Enable Short + +// +input double xRShortR2R = 1.5; // XR Short Risk To Reward Ratio +input double xRShortLotsPerTradePercent = 0.0002; // XR Lots Percent per Short Trades +input double xRShortMaxDrawdownPerTradePercent = 0.15; // XR Max Allowed DrawDown Percent per Short Trade + +// +input double xRLongR2R = 1.5; // XR Long Risk To Reward Ratio +input double xRLongLotsPerTradePercent = 0.0002; // XR Lots Percent per Short Trades +input double xRLongMaxDrawdownPerTradePercent = 0.15; // XR Max Allowed DrawDown Percent per Long Trade + +// +input int xRMaximumCandlesPerTrade = 96; // XR Maximum Candles which a Trade can open + +// +input int xRSwingLength = 48; // XR Swing Length +// +// END Inputs ... +// + +// +input double xRSharpDetectionFactor = 1350; // XR Sharp Detection Factor + +// +// START Global Requirement Functions ... +// +// +// XR Market State ... +struct XRMarketState { + // + double fast; + double slow; + double open; + + // + double range; + double rangeFast; + double rangeSlow; + double rangeOpen; + + // + double verifier; +}; + +// +// XR Based Signal Conditions ... +struct XRSignalConditions { + datetime startTime; + datetime signalTime; + datetime entryTime; +}; + +// +static XRSignalConditions xRLongConds; +static bool xRCloseLongTrades = false; +static bool xRWaitForLongSignals = true; + +// +static XRSignalConditions xRShortConds; +static bool xRCloseShortTrades = false; +static bool xRWaitForShortSignals = true; + +// +// Count Number of Closed Maximum DrawDown Trades ... +static int xRFailedSignals = 0; + +// +double xRMaximumDrawDown = 0; + +// +int fastLength = 0; +int slowLength = 0; + +// +int verifierLength = 0; + +// +int rangeFastLength = 0; +int rangeSlowLength = 0; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckXRSignalHandler( + const int bar_index +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + + // + if ( + !enableXRSignalling + || !(enableXRLong || enableXRShort) + ) { + return; + } +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXRLongSignalConditions( + const int bar_index +) { + // + if ( + !enableXRLong + || !enableXRSignalling + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Read Prices ... + XPrice prices = GetPrice(); + + // + // Read XPVTState ... + XPvtState pvt0 = GetPVTState( + bar_index, + xRSwingLength + ); + + // + // Double Length Pivots ... + XPvtState dblPvt0 = GetPVTState( + bar_index, + (xRSwingLength * 2) + ); + + // + // Reading Required Candles ... + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + XOHCL candle3 = GetCandleModel(bar_index + 3); + + // + // Reding Required XRMarketStates ... + XRMarketState state0 = GetXRMarketState(bar_index); + XRMarketState state1 = GetXRMarketState(bar_index + 1); + XRMarketState state2 = GetXRMarketState(bar_index + 2); + XRMarketState state3 = GetXRMarketState(bar_index + 3); + + // + // Reading required XRangeStates ... + XRState range0 = ReadXRange( + bar_index + xRSwingLength, + xRSwingLength + ); + XRState range1 = ReadXRange( + bar_index + xRSwingLength + 1, + xRSwingLength + ); + XRState range2 = ReadXRange( + bar_index + xRSwingLength + 2, + xRSwingLength + ); + + // + XRState cRange0 = ReadXRange( + bar_index, + xRSwingLength + ); + + // + // Validate Farest Range Values ... + if ( + range2.hh == 0 + || + range2.ll == 0 + || + range2.mid == 0 + ) { + return; + } + + // + // Reading Required XTPowStates ... + XTPOWState tPow0 = GetXTPowState( + bar_index, + xRSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xRSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xRSwingLength + ); + + // + // if state verifier below range middle + // this means market is bullish ... + // + // if state verifier above range middle + // this means market is bearish ... + // + + // + bool isMarketBullish = + state0.verifier < range0.mid + && state1.verifier < range1.mid; + bool isMarketBearish = + state0.verifier > range0.mid + && state1.verifier > range1.mid; + bool isMarketGoingBullish = + state0.verifier > range0.mid + && !(state1.verifier > range1.mid); + bool isMarketGoingBearish = + state0.verifier < range0.mid + && !(state1.verifier < range1.mid); + + // + // Check Highest High Conditions ... + bool isHHVerified = + !( + pvt0.hh == dblPvt0.hh + ) + ; + + // + int sharpDetectionLength = 7; + double sharpDetectionValue = xRSharpDetectionFactor * _Point; + + // + int sharpHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + sharpDetectionLength, + bar_index + ); + double sharpHH = iHigh( + _Symbol, + _Period, + sharpHHIdx + ); + + // + int sharpLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + sharpDetectionLength, + bar_index + ); + double sharpLL = iLow( + _Symbol, + _Period, + sharpLLIdx + ); + + // + double sharpDiff = sharpHH - sharpLL; + bool isSharpOccered = + sharpDiff > sharpDetectionValue; + + // + XRMarketState lastState = GetXRMarketState( + bar_index + sharpDetectionLength + ); + + // + double stateFSDiff = (state0.fast - state0.slow) - (lastState.fast - lastState.slow); + + // + // Start Calculating Long Conditions ... + bool longCondition1 = + // + // Starter ... + true + // + && isMarketBullish + // + && + ( + candle2.high < range2.mid + || ( + candle2.high > range2.mid + && candle2.low < range2.mid + ) + ) + && candle1.low > range1.mid + ; + + // + if ( + // + ( + longCondition1 + ) + // + && xRLongConds.startTime == 0 + && xRLongConds.entryTime == 0 + && xRLongConds.signalTime == 0 + ) { + // + xRLongConds.startTime = barTime; + xRLongConds.entryTime = barTime; + xRLongConds.signalTime = barTime; + + // + return; + } +} + +// +// Check and Fill Short Signal Conditions ... +void CheckXRShortSignalConditions( + const int bar_index +) { + // + if ( + !enableXRShort + || !enableXRSignalling + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Read Prices ... + XPrice prices = GetPrice(); + + // + // Read XPVTState ... + XPvtState pvt0 = GetPVTState( + bar_index, + xRSwingLength + ); + + // + // Double Length Pivots ... + XPvtState dblPvt0 = GetPVTState( + bar_index, + (xRSwingLength * 2) + ); + + // + // Reading Required Candles ... + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + XOHCL candle3 = GetCandleModel(bar_index + 3); + + // + // Reding Required XRMarketStates ... + XRMarketState state0 = GetXRMarketState(bar_index); + XRMarketState state1 = GetXRMarketState(bar_index + 1); + XRMarketState state2 = GetXRMarketState(bar_index + 2); + XRMarketState state3 = GetXRMarketState(bar_index + 3); + + // + // Reading required XRangeStates ... + XRState range0 = ReadXRange( + bar_index + xRSwingLength, + xRSwingLength + ); + XRState range1 = ReadXRange( + bar_index + xRSwingLength + 1, + xRSwingLength + ); + XRState range2 = ReadXRange( + bar_index + xRSwingLength + 2, + xRSwingLength + ); + + // + XRState cRange0 = ReadXRange( + bar_index, + xRSwingLength + ); + + // + // Validate Farest Range Values ... + if ( + range2.hh == 0 + || + range2.ll == 0 + || + range2.mid == 0 + ) { + return; + } + + // + // Reading Required XTPowStates ... + XTPOWState tPow0 = GetXTPowState( + bar_index, + xRSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xRSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xRSwingLength + ); + + // + // if state verifier below range middle + // this means market is bullish ... + // + // if state verifier above range middle + // this means market is bearish ... + // + + // + bool isMarketBullish = + state0.verifier < range0.mid + && state1.verifier < range1.mid; + bool isMarketBearish = + state0.verifier > range0.mid + && state1.verifier > range1.mid; + bool isMarketGoingBullish = + state0.verifier > range0.mid + && !(state1.verifier > range1.mid); + bool isMarketGoingBearish = + state0.verifier < range0.mid + && !(state1.verifier < range1.mid); + + // + // Check Highest High Conditions ... + bool isHHVerified = + !( + pvt0.hh == dblPvt0.hh + ) + ; + + // + int sharpDetectionLength = 7; + double sharpDetectionValue = xRSharpDetectionFactor * _Point; + + // + int sharpHHIdx = iHighest( + _Symbol, + _Period, + MODE_HIGH, + sharpDetectionLength, + bar_index + ); + double sharpHH = iHigh( + _Symbol, + _Period, + sharpHHIdx + ); + + // + int sharpLLIdx = iLowest( + _Symbol, + _Period, + MODE_LOW, + sharpDetectionLength, + bar_index + ); + double sharpLL = iLow( + _Symbol, + _Period, + sharpLLIdx + ); + + // + double sharpDiff = sharpHH - sharpLL; + bool isSharpOccered = + sharpDiff > sharpDetectionValue; + + // + XRMarketState lastState = GetXRMarketState( + bar_index + sharpDetectionLength + ); + + // + double stateFSDiff = (state0.fast - state0.slow) - (lastState.fast - lastState.slow); + + // + // Start Calculating Long Conditions ... + bool shortCondition1 = + // + // Starter ... + true + // + && isMarketBearish + // + && + ( + candle2.low > range2.mid + || ( + candle2.high > range2.mid + && candle2.low < range2.mid + ) + ) + && candle1.high < range1.mid + ; + + // + if ( + // + ( + shortCondition1 + ) + // + && xRShortConds.startTime == 0 + && xRShortConds.entryTime == 0 + && xRShortConds.signalTime == 0 + ) { + // + xRShortConds.startTime = barTime; + xRShortConds.entryTime = barTime; + xRShortConds.signalTime = barTime; + + // + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXRSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if ( + !enableXRSignalling + || !(enableXRLong || enableXRShort) + ) { + return result; + } + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + if (requestLong) { + // + if ( + !ValidateXRLongConditions() + ) { + return result; + } + } else { + // + if ( + !ValidateXRShortConditions() + ) { + return result; + } + } + + // + // Price Calculations ... + XPvtState pvts = GetPVTState( + bar_index, + xRSwingLength + ); + XPrice prices = GetPrice(); + + // + double entryPrice = requestLong ? + prices.longEntry : + prices.shortEntry + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + double risk = requestLong ? + MathMin(openPrice, closePrice) - pvts.ll : + pvts.hh - MathMax(openPrice, closePrice); + if (risk <= 0) { + // + risk = requestLong ? + MathAbs(pvts.hh - entryPrice) : + MathAbs(pvts.ll - entryPrice) + ; + } + + // + double reward = + requestLong ? + risk * xRLongR2R : + risk * xRShortR2R + ; + + // + double sl = requestLong ? + 0 : + 0; + + // + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward + ; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XR_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XR_PROVIDER; + + // + return result; +} + +// +// Validate Long Signal Conditions ... +bool ValidateXRLongConditions() { + // + if ( + !enableXRLong + || !enableXRSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xRLongConds.startTime > 0 + && xRLongConds.signalTime > 0 + && xRLongConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + isBLFilled = + // + xRLongConds.signalTime >= xRLongConds.startTime + && xRLongConds.entryTime >= xRLongConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xRWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXRLongSignalConditions(); + } + + // + return result; +} + +// +// Validate Short Signal Conditions ... +bool ValidateXRShortConditions() { + // + if ( + !enableXRShort + || !enableXRSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xRShortConds.startTime > 0 + && xRShortConds.signalTime > 0 + && xRShortConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // + isBLFilled = + // + xRShortConds.signalTime >= xRShortConds.startTime + && xRShortConds.entryTime >= xRShortConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xRWaitForShortSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXRShortSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXRLongSignalConditions() { + // + xRLongConds.startTime = 0; + xRLongConds.signalTime = 0; + xRLongConds.entryTime = 0; +} + +// +// Clear Short Signal Conditions for New One ... +void ClearXRShortSignalConditions() { + // + xRShortConds.startTime = 0; + xRShortConds.signalTime = 0; + xRShortConds.entryTime = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForXRSignals( + const XSignal &signal +) { + // + bool result = false; + + // + if ( + !enableXRSignalling + || !(enableXRLong || enableXRShort) + ) { + return result; + } + + // + // Find Signal Bar Index ... + int signalBarIndex = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // Read Prices ... + XPrice prices = GetPrice(); + + // + // Read XPVTState ... + XPvtState pvt0 = GetPVTState( + signalBarIndex, + xRSwingLength + ); + + // + // Reading Required Candles ... + XOHCL candle0 = GetCandleModel(signalBarIndex); + XOHCL candle1 = GetCandleModel(signalBarIndex + 1); + XOHCL candle2 = GetCandleModel(signalBarIndex + 2); + XOHCL candle3 = GetCandleModel(signalBarIndex + 3); + + // + // Reding Required XRMarketStates ... + XRMarketState state0 = GetXRMarketState(signalBarIndex); + XRMarketState state1 = GetXRMarketState(signalBarIndex + 1); + XRMarketState state2 = GetXRMarketState(signalBarIndex + 2); + XRMarketState state3 = GetXRMarketState(signalBarIndex + 3); + + // + // Reading required XRangeStates ... + XRState range0 = ReadXRange( + signalBarIndex + xRSwingLength, + xRSwingLength + ); + XRState range1 = ReadXRange( + signalBarIndex + xRSwingLength + 1, + xRSwingLength + ); + XRState range2 = ReadXRange( + signalBarIndex + xRSwingLength + 2, + xRSwingLength + ); + + // + // Reading Required XTPowStates ... + XTPOWState tPow0 = GetXTPowState( + signalBarIndex, + xRSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + signalBarIndex + 1, + xRSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + signalBarIndex + 2, + xRSwingLength + ); + + // + double hhllDiff = MathAbs(pvt0.hh - pvt0.ll); + double sharpDetectionValue = xRSharpDetectionFactor * _Point; + bool isSharpOccured = hhllDiff > sharpDetectionValue; + + // + // Calculate State Min Max Diff ... + // + double state0Min = MathMin(state0.fast, state0.slow); + state0Min = MathMin(state0Min, state0.open); + state0Min = MathMin(state0Min, state0.rangeFast); + state0Min = MathMin(state0Min, state0.rangeSlow); + state0Min = MathMin(state0Min, state0.rangeOpen); + state0Min = MathMin(state0Min, state0.verifier); + + // + double state0Max = MathMax(state0.fast, state0.slow); + state0Max = MathMax(state0Max, state0.open); + state0Max = MathMax(state0Max, state0.rangeFast); + state0Max = MathMax(state0Max, state0.rangeSlow); + state0Max = MathMax(state0Max, state0.rangeOpen); + state0Max = MathMax(state0Max, state0.verifier); + + // + double state0MinMaxDiff = (state0Max - state0Min); + + // + bool isTPowValid = false; + bool isStateValid = false; + bool isRangeValid = false; + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + // Retrieve TPow Verifications ... + isTPowValid = + // + // Starter ... + true + ; + + // + // Retrieve XMarket Verifications ... + isStateValid = + // + // Starter ... + true + // + // && !(state0MinMaxDiff > sharpDetectionValue) + ; + + // + // Retrieve XRange Verifications ... + isRangeValid = + // + // Starter ... + true + ; + + // + result = + // + // Starter ... + true + // + && isTPowValid + && isStateValid + && isRangeValid + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + // Retrieve TPow Verifications ... + isTPowValid = + // + // Starter ... + true + ; + + // + // Retrieve XMarket Verifications ... + isStateValid = + // + // Starter ... + true + ; + + // + // Retrieve XRange Verifications ... + isRangeValid = + // + // Starter ... + true + ; + + // + result = + // + // Starter ... + true + // + && isTPowValid + && isStateValid + && isRangeValid + ; + } + + // + return result; +} +// +// END Functions ... +// + +// +// START Data Providers ... +// +// +XRMarketState GetXRMarketState( + const int bar_index +) { + // + XRMarketState result = {}; + + // + // Calculate Market Lengths ... + + // + if (fastLength == 0) { + fastLength = xRSwingLength; + } + + // + if (slowLength == 0) { + slowLength = xRSwingLength * 2; + } + + // + if (verifierLength == 0) { + verifierLength = (GetDailyCandleCount() * 2); + } + + // + if (rangeFastLength == 0) { + rangeFastLength = (int)(verifierLength / 2); + } + + // + if (rangeSlowLength == 0) { + rangeSlowLength = verifierLength; + } + + // + // Reading Values ... + + // + double fast = GetMA( + bar_index, + fastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double slow = GetMA( + bar_index, + slowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double open = GetMA( + bar_index, + fastLength, + 0, + MODE_SMA, + PRICE_OPEN + ); + + // + double rangeFast = GetMA( + bar_index, + rangeFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double rangeSlow = GetMA( + bar_index, + rangeSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double rangeOpen = GetMA( + bar_index, + rangeFastLength, + 0, + MODE_SMA, + PRICE_OPEN + ); + + // + double verifier = GetMA( + bar_index, + verifierLength, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + // Filling Result ... + result.fast = fast; + result.slow = slow; + result.open = open; + result.verifier = verifier; + result.rangeFast = rangeFast; + result.rangeSlow = rangeSlow; + result.rangeOpen = rangeOpen; + + // + return result; +} +// +// END Data Providers ... +// \ No newline at end of file diff --git a/Libraries/x-saherelm.xtpw.signal.lib.mq4 b/Libraries/x-saherelm.xtpw.signal.lib.mq4 new file mode 100644 index 0000000..4bf02ce --- /dev/null +++ b/Libraries/x-saherelm.xtpw.signal.lib.mq4 @@ -0,0 +1,1332 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL4 XTPW Signal Global Library +// --------------------------------------------------- +// XSaherElm EA Signal Provider based on +// XTPow Indicator... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Includes library ... +#include "../Libraries/x-saherelm.lib.mq4" + +// +// Includes Indicator library ... +#include "../Libraries/x-saherelm.indicator.lib.mq4" + +// +// Includes Models library ... +#include "../Libraries/x-saherelm.models.lib.mq4" + +// +// START Inputs ... +// +// +input string xTPWStarter = "- XTPW Signal Provider -"; // ---> XTPW Signal Provider <--- + +// +input bool enableXTPWSignalling = true; // XTPW Signalling Enable + +// +input bool enableXTPWLong = true; // XTPW Signalling Enable Long +input bool enableXTPWShort = true; // XTPW Signalling Enable Short + +// +input double xTPWShortR2R = 2; // XTPW Short Risk To Reward Ratio +input double xTPWShortLotsPerTradePercent = 0.0002; // XTPW Lots Percent per Short Trades +input double xTPWShortMaxDrawdownPerTradePercent = 0.3; // XTPW Max Allowed DrawDown Percent per Short Trade + +// +input double xTPWLongR2R = 2; // XTPW Long Risk To Reward Ratio +input double xTPWLongLotsPerTradePercent = 0.0002; // XTPW Lots Percent per Short Trades +input double xTPWLongMaxDrawdownPerTradePercent = 0.3; // XTPW Max Allowed DrawDown Percent per Long Trade + +// +input int xTPWMaximumCandlesPerTrade = 206; // XTPW Maximum Candles which a Trade can open + +// +input double xTPWPSarStep = 0.02; // XTPW Parabolic Sar Step +input double xTPWPSarMaximum = 0.2; // XTPW Parabolic Sar Maximum + +// +input int xTPWSwingLength = 7; // XTPW Signal Swing Length +// +// END Inputs ... +// + +// +input double xTPWSharpDetectionFactor = 650; // XTPW Sharp Detection Factor + +// +// START Global Requirement Functions ... +// +// +// XTPW Based Signal Conditions ... +struct XTPWSignalConditions { + datetime startTime; + datetime signalTime; + datetime entryTime; +}; + +// +struct XTPWMarketState { + // + double psar; + + // + double scFast; + double scSlow; + double scWeight; + + // + double mcFast; + double mcSlow; + double mcWeight; + + // + double lcFast; + double lcSlow; + double lcWeight; +}; + +// +struct XLHS { + // + double scHH; + double scLL; + + // + double mcHH; + double mcLL; + + // + double lcHH; + double lcLL; +}; + +// +static XTPWSignalConditions xTPWLongConds; +static bool xTPWCloseLongTrades = false; +static bool xTPWWaitForLongSignals = true; + +// +static XTPWSignalConditions xTPWShortConds; +static bool xTPWCloseShortTrades = false; +static bool xTPWWaitForShortSignals = true; + +// +// Count Number of Closed Maximum DrawDown Trades ... +static int xTPWFailedSignals = 0; + +// +double tPowerVerifier = 20; +double tPowerMaxVerifier = 55; + +// +int scFastLength = 0; +int scSlowLength = 0; + +// +int mcFastLength = 0; +int mcSlowLength = 0; + +// +int lcFastLength = 0; +int lcSlowLength = 0; + +// +datetime lastTurnOffLongTradesTime; +datetime lastTurnOffShortTradesTime; +// +// END Global Requirement Functions ... +// + +// +// START Functions ... +// +// +// Check and Fill Long and Short Signal Handlers ... +void CheckXTPWSignalHandler( + const int bar_index +) { + // + // Check Market For Enable/Disable Signal Handlers ... + // Checking Market for Long Signals ... + + // + if ( + !enableXTPWSignalling + || !(enableXTPWLong || enableXTPWShort) + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 1); + + // + XTPOWState tPow0 = GetXTPowState( + bar_index, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xTPWSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xTPWSwingLength + ); + + // + XTPWMarketState state0 = GetXTPWMarketState( + bar_index + ); + XTPWMarketState state1 = GetXTPWMarketState( + bar_index + 1 + ); + XTPWMarketState state2 = GetXTPWMarketState( + bar_index + 2 + ); + + // // + // // Disable Long Conditions ... + // if ( + // xTPWWaitForLongSignals + // && + // ( + // isRangeCrossOverRangeWeight + // || + // isRangeCrossUnderRangeWeight + // || + // isTPowUpperAboveMaxVerifier + // ) + // ) { + // // + // xTPWWaitForLongSignals = false; + // lastTurnOffLongTradesTime = barTime; + // } + + // // + // // Enable Long Conditions ... + // if ( + // !xTPWWaitForLongSignals + // && lastTurnOffLongTradesTime > 0 + // && ( + // // isFastCrossOverSlow + // // || + // // isFastCrossUnderSlow + // isRangeCrossOverRangeWeight + // || + // isRangeCrossUnderRangeWeight + // || + // isTPowUpperBelowMaxVerifier + // ) + // ) { + // // + // // Find Last Turn Off Bar Index ... + // int lastTurnOffLongTradesBarIndex = iBarShift( + // _Symbol, + // _Period, + // lastTurnOffLongTradesTime + // ); + + // // + // // the Distance must be bigger than market length ... + // if (MathAbs(lastTurnOffLongTradesBarIndex - bar_index) > xTPWSwingLength) { + // // + // xTPWWaitForLongSignals = true; + // lastTurnOffLongTradesTime = 0; + // } + // } +} + +// +// Check and Fill Long Signal Conditions ... +void CheckXTPWLongSignalConditions( + const int bar_index +) { + // + if ( + !enableXTPWLong + || !enableXTPWSignalling + || !xTPWWaitForLongSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Retrieve TPow States ... + XTPOWState tPow0 = GetXTPowState( + bar_index, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xTPWSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xTPWSwingLength + ); + + // + // Retrieve TPowMarket State ... + XTPWMarketState state0 = GetXTPWMarketState( + bar_index + ); + XTPWMarketState state1 = GetXTPWMarketState( + bar_index + 1 + ); + XTPWMarketState state2 = GetXTPWMarketState( + bar_index + 2 + ); + + // + // Retrieve XPrice Model ... + XPrice prices = GetPrice(); + + // + // Retrieve Candles ... + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + + // + XLHS lhs = GetXTPWLHS(bar_index); + + // + bool isHHSame = + lhs.scHH == lhs.mcHH + && lhs.mcHH == lhs.lcHH + ; + + // + bool isLLSame = + lhs.scLL == lhs.mcLL + && lhs.mcLL == lhs.lcLL + ; + + // + bool startCondition = false; + bool signalCondition = false; + bool entryCondition = false; + + // + bool longCondition1 = + // + true + // + && !isHHSame + // + && !( + lhs.scLL == lhs.mcLL + ) + // + && !( + lhs.scHH == lhs.mcHH + ) + // + && !( + prices.longEntry + && candle0.high < state0.scFast + && candle0.high < state0.scSlow + && candle0.high < state0.mcFast + && candle0.high < state0.mcSlow + && candle0.high < state0.lcFast + && candle0.high < state0.lcSlow + ) + // + && tPow0.powerDown > tPowerMaxVerifier + && tPow1.powerDown > tPowerMaxVerifier + && tPow0.powerDown < MathMax(tPow1.powerUp, tPow1.powerDown) + && MathMax(tPow1.powerUp, tPow1.powerDown) > tPowerMaxVerifier + ; + + // + // Start Conditions ... + startCondition = ( + longCondition1 + ) + ; + + // + if ( + startCondition + && xTPWLongConds.startTime == 0 + && xTPWLongConds.signalTime == 0 + && xTPWLongConds.entryTime == 0 + ) { + // + xTPWLongConds.startTime = barTime; + xTPWLongConds.signalTime = barTime; + xTPWLongConds.entryTime = barTime; + + // + return; + } +} + +// +// Check and Fill Short Signal Conditions ... +void CheckXTPWShortSignalConditions( + const int bar_index +) { + // + if ( + !enableXTPWShort + || !enableXTPWSignalling + || !xTPWWaitForShortSignals + ) { + return; + } + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + // Retrieve TPower State ... + XTPOWState tPow0 = GetXTPowState( + bar_index, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + bar_index + 1, + xTPWSwingLength + ); + XTPOWState tPow2 = GetXTPowState( + bar_index + 2, + xTPWSwingLength + ); + + // + // Retrieve TPWMarket State ... + XTPWMarketState state0 = GetXTPWMarketState( + bar_index + ); + XTPWMarketState state1 = GetXTPWMarketState( + bar_index + 1 + ); + XTPWMarketState state2 = GetXTPWMarketState( + bar_index + 2 + ); + + // + // Retrieve Candles ... + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + + // + XPrice prices = GetPrice(); + XLHS lhs = GetXTPWLHS(bar_index); + + // + double sharpDetectionValue = + xTPWSharpDetectionFactor * _Point; + + // + bool isHHSame = + lhs.scHH == lhs.mcHH + && lhs.mcHH == lhs.lcHH + ; + + // + bool isLLSame = + lhs.scLL == lhs.mcLL + && lhs.mcLL == lhs.lcLL + ; + + // + bool startCondition = false; + bool signalCondition = false; + bool entryCondition = false; + + // + bool shortCondition1 = + // + true + // + && tPow1.powerDown > tPowerMaxVerifier + && tPow2.powerDown < tPowerMaxVerifier + ; + + // + startCondition = ( + shortCondition1 + ) + ; + + // + if ( + startCondition + && xTPWShortConds.startTime == 0 + && xTPWShortConds.signalTime == 0 + && xTPWShortConds.entryTime == 0 + ) { + // + xTPWShortConds.startTime = barTime; + xTPWShortConds.signalTime = barTime; + xTPWShortConds.entryTime = barTime; + + // + return; + } +} + +// +// Convert Long Signal Conditions to XSignal ... +XSignalRequest GenerateXTPWSignal( + const ENUM_X_SIGNAL_TYPE type, // Signal Type ... + const string signalTag , // Signal Tag ... + const int bar_index +) { + // + XSignalRequest result = {}; + + // + result.hasSignal = false; + result.type = X_SIGNAL_NONE; + result.provider = X_UNKNOWN_PROVIDER; + + // + if ( + !enableXTPWSignalling + || !(enableXTPWLong || enableXTPWShort) + ) { + return result; + } + + // + bool requestLong = type == X_SIGNAL_LONG; + + // + // Check Condition Validations ... + if (requestLong) { + // + // Check Long Condtion is Valid, if Long Requested ... + if ( + !ValidateXTPWLongConditions() + ) { + return result; + } + } else { + // + // Check Short Condtion is Valid, if Short Requested ... + if ( + !ValidateXTPWShortConditions() + ) { + return result; + } + } + + // + double ll = + // + GetMarketLowestLow( + bar_index, + xTPWSwingLength + ) + ; + + // + double hh = + // + GetMarketHighestHigh( + bar_index, + xTPWSwingLength + ) + ; + + // + double openPrice = iOpen( + _Symbol, + _Period, + bar_index + ); + + // + double closePrice = iClose( + _Symbol, + _Period, + bar_index + ); + + // + // Price Calculations ... + XPrice prices = GetPrice(); + + // + // Read State ... + XTPWMarketState state0 = GetXTPWMarketState(bar_index); + + // + XOHCL candle0 = GetCandleModel(bar_index); + XOHCL candle1 = GetCandleModel(bar_index + 1); + XOHCL candle2 = GetCandleModel(bar_index + 2); + XOHCL candle3 = GetCandleModel(bar_index + 2); + + // + double risk = requestLong ? + // + MathMin(openPrice, closePrice) - ll : + hh - MathMax(openPrice, closePrice) + ; + + // + double longR2R = xTPWLongR2R; + double shortR2R = xTPWShortR2R; + + // + double sharpDetectorValue = xTPWSharpDetectionFactor * _Point; + + // + if ( + risk > 0 + && requestLong + ) { + return result; + } + + // + // Define Entry Price ... + double entryPrice = requestLong + ? + prices.longEntry + : + prices.shortEntry + ; + + // + // Fix TP Detects for Short Signals ... + if (!requestLong) { + risk = 0; + } + + // + double reward = requestLong ? + risk * longR2R : + risk * shortR2R + ; + + // + if (risk == 0) { + // + // Calculate Reward ... + reward = requestLong + ? + MathAbs(hh - entryPrice) + : + MathAbs(hh - entryPrice) + ; + + // + // Detect Sharp Change Occured or not ... + bool isSharpOccured = reward > sharpDetectorValue + || MathAbs(reward - sharpDetectorValue) < (50 * _Point); + + // + // Change Rewards on Special Conditions ... + if ( + ( + requestLong + && isSharpOccured + && ( + state0.lcFast < state0.lcSlow + || ( + state0.mcFast > state0.mcSlow + && state0.mcWeight < state0.mcSlow + ) + ) + ) + ) { + reward = reward / 2; + } + + // + if (reward < 50 * _Point) { + reward = (50 * _Point) + prices.priceGap; + } + + // // + // if (!requestLong) { + // reward = reward * shortR2R; + // } + } + + // + double sl = requestLong ? + 0 : + 0; + double tp = requestLong ? + entryPrice + reward : + entryPrice - reward + ; + + // + datetime barTime = iTime( + _Symbol, + _Period, + bar_index + ); + + // + result.signal.tp = tp; + result.signal.sl = sl; + result.signal.type = type; + result.signal.time = barTime; + result.signal.tag = signalTag; + result.signal.symbol = _Symbol; + result.signal.entry = entryPrice; + result.signal.id = totalSignals + 1; + result.signal.provider = X_XTPW_PROVIDER; + + // + result.hasSignal = true; + result.type = type; + result.provider = X_XTPW_PROVIDER; + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXTPWLongConditions() { + // + if ( + !enableXTPWLong + || !enableXTPWSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xTPWLongConds.startTime > 0 + && xTPWLongConds.signalTime > 0 + && xTPWLongConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // // + // int startBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWLongConds.startTime + // ); + + // // + // int signalBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWLongConds.signalTime + // ); + + // // + // int entryBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWLongConds.entryTime + // ); + + // // + // int startSignalDiff = (signalBarIndex - startBarIndex); + // int entrySignalDiff = (entryBarIndex - signalBarIndex); + // int maxDiff = MathMax(startSignalDiff, entrySignalDiff); + + // + isBLFilled = + // + // Starter ... + true + // + && xTPWLongConds.signalTime >= xTPWLongConds.startTime + && xTPWLongConds.entryTime >= xTPWLongConds.signalTime + // + // && maxDiff < (xTPWSwingLength * 2) + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xTPWWaitForLongSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXTPWLongSignalConditions(); + } + + // + return result; +} + +// +// Validate Signal Conditions ... +bool ValidateXTPWShortConditions() { + // + if ( + !enableXTPWShort + || !enableXTPWSignalling + ) { + return false; + } + + // + bool isConditionsFilled = + xTPWShortConds.startTime > 0 + && xTPWShortConds.signalTime > 0 + && xTPWShortConds.entryTime > 0 + ; + + // + bool isBLFilled = false; + if (isConditionsFilled) { + // // + // int startBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWShortConds.startTime + // ); + + // // + // int signalBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWShortConds.signalTime + // ); + + // // + // int entryBarIndex = iBarShift( + // _Symbol, + // _Period, + // xTPWShortConds.entryTime + // ); + + // + isBLFilled = + // + // Starter ... + true + // + && xTPWShortConds.signalTime >= xTPWShortConds.startTime + && xTPWShortConds.entryTime >= xTPWShortConds.signalTime + ; + } + + // + bool result = + isBLFilled + && isConditionsFilled + && xTPWWaitForShortSignals + ; + + // + // Since maybe Conditions Filled but + // Slope is Negative, for Handling Next Signals and + // Prevent from infinity loop, here we Clear Signal Conditions ... + if ( + !result + && isConditionsFilled + ) { + ClearXTPWShortSignalConditions(); + } + + // + return result; +} + +// +// Clear Long Signal Conditions for New One ... +void ClearXTPWLongSignalConditions() { + // + xTPWLongConds.startTime = 0; + xTPWLongConds.entryTime = 0; + xTPWLongConds.signalTime = 0; +} + +// +// Clear Short Signal Conditions for New One ... +void ClearXTPWShortSignalConditions() { + // + xTPWShortConds.startTime = 0; + xTPWShortConds.entryTime = 0; + xTPWShortConds.signalTime = 0; +} + +// +// Check State for Long Signals ... +bool IsReadyForXTPWSignals( + const XSignal &signal +) { + // + bool result = false; + + // + if ( + !enableXTPWSignalling + || !(enableXTPWLong || enableXTPWShort) + ) { + return result; + } + + // + int signalBarIndex = iBarShift( + _Symbol, + _Period, + signal.time + ); + + // + // XOHCL candle = GetCandleModel(0); + XOHCL candle0 = GetCandleModel(signalBarIndex); + XOHCL candle1 = GetCandleModel(signalBarIndex + 1); + + // + // Retrieve TPow State ... + XTPOWState tPow0 = GetXTPowState( + signalBarIndex, + xTPWSwingLength + ); + XTPOWState tPow1 = GetXTPowState( + signalBarIndex + 1, + xTPWSwingLength + ); + + // + // Retrive XMarket States ... + XTPWMarketState state0 = GetXTPWMarketState(signalBarIndex); + XTPWMarketState state1 = GetXTPWMarketState(signalBarIndex + 1); + XTPWMarketState state2 = GetXTPWMarketState(signalBarIndex + 2); + + // + bool isPSarVerified = false; + bool isTPowVerified = false; + bool isStateVerified = false; + bool isPriceVerified = false; + + // + // Calculate Sharp Detection Value ... + double sharpDetectionValue = + xTPWSharpDetectionFactor * _Point; + + // + // Find State0 Min ... + double state0Min = MathMin(state0.scFast, state0.scSlow); + state0Min = MathMin(state0Min, state0.mcFast); + state0Min = MathMin(state0Min, state0.mcSlow); + state0Min = MathMin(state0Min, state0.lcFast); + state0Min = MathMin(state0Min, state0.lcSlow); + + // + // Find State0 Min ... + double state0Max = MathMax(state0.scFast, state0.scSlow); + state0Max = MathMax(state0Max, state0.mcFast); + state0Max = MathMax(state0Max, state0.mcSlow); + state0Max = MathMax(state0Max, state0.lcFast); + state0Max = MathMax(state0Max, state0.lcSlow); + + // + // Find Distance Between State0 Min and Max ... + double state0MinMaxDistance = MathAbs(state0Max - state0Min); + + // + // Verify Long Signals ... + if (signal.type == X_SIGNAL_LONG) { + // + // Get Price Verification for Long ... + isPriceVerified = + // + // Starter ... + true + // + ; + + // + isTPowVerified = + // + // Starter ... + true + // + && tPow0.powerDown > tPowerMaxVerifier + && tPow1.powerDown > tPowerMaxVerifier + && tPow0.powerDown < MathMax(tPow1.powerUp, tPow1.powerDown) + && MathMax(tPow1.powerUp, tPow1.powerDown) > tPowerMaxVerifier + ; + + // + isPSarVerified = + // + // Starter ... + true + // + ; + + // + isStateVerified = + // + // Start ... + true + // + && state0.mcFast > state0.mcSlow + && state1.mcFast > state1.mcSlow + // + && !( + state0.lcFast > state0.mcSlow + && state0.lcFast < state0.mcFast + ) + // + && MathAbs(state1.mcFast - state1.mcSlow) > (50 * _Point) + ; + + // + result = + // + // Starter ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } else + // + // Verify Short Signals ... + if (signal.type == X_SIGNAL_SHORT) { + // + isPSarVerified = + // + // Starter ... + true + ; + + // + // Get Price Verification for Short ... + isPriceVerified = + // + // Starter ... + true + ; + + // + isTPowVerified = + // + // Starter ... + true + // + && tPow0.signal > MathMax(tPow0.powerUp, tPow0.powerDown) + ; + + // + isStateVerified = + // + // Start ... + true + // + && ( + // + state0.scFast < state0.scSlow + && state0.mcFast < state0.mcSlow + && state0.lcFast < state0.lcSlow + ? + signal.entry > state0.scFast + : + // + // Find Minimum and Maximum Distance of State ... + state0MinMaxDistance > sharpDetectionValue + ? + signal.entry > state0Min + : + true + ) + // + && MathAbs(state0.mcFast - state0.mcSlow) > 50 * _Point + ; + + // + result = + // + // Starter Condition ... + true + // + && isPSarVerified + // + && isTPowVerified + // + && isStateVerified + // + && isPriceVerified + ; + } + + // + return result; +} +// +// END Functions ... +// + +// +// START Data Provider ... +// +// +// Retrieve Market State ... +XTPWMarketState GetXTPWMarketState( + const int bar_index +) { + // + XTPWMarketState result = {}; + + // + int dayCount = GetDailyCandleCount(); + int halfDayCount = (int)(dayCount / 2); + + // + if (scFastLength == 0) { + scFastLength = xTPWSwingLength; + } + + // + if (scSlowLength == 0) { + scSlowLength = xTPWSwingLength * 2; + } + + // + if (mcFastLength == 0) { + mcFastLength = halfDayCount; + } + + // + if (mcSlowLength == 0) { + mcSlowLength = dayCount; + } + + // + if (lcFastLength == 0) { + lcFastLength = halfDayCount * 3; + } + + // + if (lcSlowLength == 0) { + lcSlowLength = dayCount * 3; + } + + // + double scFast = GetMA( + bar_index, + scFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double scSlow = GetMA( + bar_index, + scSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double scWeight = GetMA( + bar_index, + scSlowLength, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double mcFast = GetMA( + bar_index, + mcFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double mcSlow = GetMA( + bar_index, + mcSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double mcWeight = GetMA( + bar_index, + mcSlowLength, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double lcFast = GetMA( + bar_index, + lcFastLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double lcSlow = GetMA( + bar_index, + lcSlowLength, + 0, + MODE_SMA, + PRICE_CLOSE + ); + + // + double lcWeight = GetMA( + bar_index, + lcSlowLength, + 0, + MODE_EMA, + PRICE_MEDIAN + ); + + // + double psar = iSAR( + _Symbol, + _Period, + xTPWPSarStep, + xTPWPSarMaximum, + bar_index + ); + + // + result.psar = psar; + result.scFast = scFast; + result.scSlow = scSlow; + result.mcFast = mcFast; + result.mcSlow = mcSlow; + result.lcFast = lcFast; + result.lcSlow = lcSlow; + result.scWeight = scWeight; + result.mcWeight = mcWeight; + result.lcWeight = lcWeight; + + // + return result; +} + +// +// Retrieve Highest Highs and Lowest Lows in Cycles ... +XLHS GetXTPWLHS( + const int bar_index +) { + // + XLHS result = {}; + + // + // Retrieve LL and HH (s) ... + + // + // SC HH ... + double scHH = GetMarketHighestHigh( + bar_index, + scFastLength + ); + + // + // SC LL ... + double scLL = GetMarketHighestHigh( + bar_index, + scFastLength + ); + + // + // MC HH ... + double mcHH = GetMarketHighestHigh( + bar_index, + mcFastLength + ); + + // + // MC LL ... + double mcLL = GetMarketHighestHigh( + bar_index, + mcFastLength + ); + + // + // LC HH ... + double lcHH = GetMarketHighestHigh( + bar_index, + lcFastLength + ); + + // + // LC LL ... + double lcLL = GetMarketHighestHigh( + bar_index, + lcFastLength + ); + + // + result.scHH = scHH; + result.scLL = scLL; + result.mcHH = mcHH; + result.mcLL = mcLL; + result.lcHH = lcHH; + result.lcLL = lcLL; + + // + return result; +} +// +// END Data Provider ... +// diff --git a/MQL4.code-workspace b/MQL4.code-workspace new file mode 100644 index 0000000..11a5ef6 --- /dev/null +++ b/MQL4.code-workspace @@ -0,0 +1,12 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": { + "C_Cpp.default.includePath": [ + "c:\\Users\\hadi_\\AppData\\Roaming\\MetaQuotes\\Terminal\\50CA3DFB510CC5A8F28B48D1BF2A5702\\MQL4\\Include\\Include" + ] + } +} \ No newline at end of file diff --git a/Node/x-arg.parser.js b/Node/x-arg.parser.js new file mode 100644 index 0000000..bbac10c --- /dev/null +++ b/Node/x-arg.parser.js @@ -0,0 +1,91 @@ +/** + * XArgs Parser Module ... + * a module for parsing args in node js cli apps ... + * + * Maintainer + * + * Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) + */ + +// +//#region Variable/Constants ... +const ARGUMENT_SEPARATION_REGEX = /([^=\s]+)[=\ ]?\s*(.*)/; +//#endregion + +// +//#region Actions ... +function parseArgs(argv) { + // + // Removing node/bin and called script name + argv = argv.slice(2); + + // + const result = {}; + let argName; + let argValue; + + // + if ( + argv === null + || argv === undefined + || argv.length === 0 + ) { + return result; + } + + // + const argString = argv.join(" "); + let matches = argString + .match(ARGUMENT_SEPARATION_REGEX); + matches.splice(0, 1); + matches = matches + .filter(m => m !== undefined && m !== ""); + + // + matches.forEach(arg => { + // + // Separate argument for a key/value return + arg = arg.match(ARGUMENT_SEPARATION_REGEX); + arg.splice(0, 1); + + // + // Retrieve the argument name + argName = arg[0]; + + // + // Remove "--" or "-" + if (argName.indexOf('-') === 0) { + // + argName = argName + .slice( + argName + .slice(0, 2) + .lastIndexOf('-') + 1 + ); + } + + // + // Parse argument value or set it to `true` if empty + argValue = + arg[1] !== '' + ? parseFloat(arg[1]) + .toString() === arg[1] + ? +arg[1] + : arg[1] + : true; + + // + result[argName] = argValue; + }); + + // + return result; +} +//#endregion + +// +//#region Exports ... +module.exports = { + parseArgs +}; +//#endregion \ No newline at end of file diff --git a/Node/x-color.tools.js b/Node/x-color.tools.js new file mode 100644 index 0000000..c3ac5f9 --- /dev/null +++ b/Node/x-color.tools.js @@ -0,0 +1,506 @@ +/** + * XColor Tools Module ... + * a module for handle colorify text contents in node js ... + * + * Maintainer + * + * Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) + */ + +// +//#region Module Imports ... +const XValueTools = require("./x-value.tools"); +//#endregion + +// +//#region Constants ... +/** + * these are available style which can applied to an string ... + */ +const AVAILABLE_STYLES = { + // + Bold: "\x1b[1m", + Dim: "\x1b[2m", + Underlined: "\x1b[4m", + Blink: "\x1b[5m", + ReverseFandB: "\x1b[7m", + Hidden: "\x1b[8m", + // + // Commonly used for reset all Styles ... + Reset: "\x1b[0m" +}; + +/** + * these are available foreground colors which can applied to an string ... + */ +const AVAILABLE_FOREGROUND_COLORS = { + Default: "\x1b[39m", + Black: "\x1b[30m", + Red: "\x1b[31m", + Green: "\x1b[32m", + Yellow: "\x1b[33m", + Blue: "\x1b[34m", + Magenta: "\x1b[35m", + Cyan: "\x1b[36m", + LightGray: "\x1b[37m", + DarkGray: "\x1b[90m", + LightRed: "\x1b[91m", + LightGreen: "\x1b[92m", + LightYellow: "\x1b[93m", + LightBlue: "\x1b[94m", + LightMagenta: "\x1b[95m", + LightCyan: "\x1b[96m", + White: "\x1b[97m", +}; + +/** + * these are available background colors which can applied to an string ... + */ +const AVAILABLE_BACKGROUND_COLORS = { + Default: "\x1b[49m", + Black: "\x1b[40m", + Red: "\x1b[41m", + Green: "\x1b[42m", + Yellow: "\x1b[43m", + Blue: "\x1b[44m", + Magenta: "\x1b[45m", + Cyan: "\x1b[46m", + LightGray: "\x1b[47m", + DarkGray: "\x1b[100m", + LightRed: "\x1b[101m", + LightGreen: "\x1b[102m", + LightYellow: "\x1b[103m", + LightBlue: "\x1b[104m", + LightMagenta: "\x1b[105m", + LightCyan: "\x1b[106m", + White: "\x1b[107m", +}; + +/** + * these are available style names, which exports from module and + * users can use them ... + */ +const STYLE_NAMES = { + Bold: "Bold", + Dim: "Dim", + Underlined: "Underlined", + Blink: "Blink", + ReverseFandB: "ReverseFandB", + Hidden: "Hidden", + Reset: "Reset", +}; + +/** + * these are available color names, which exports from module and + * users can use them ... + */ +const COLOR_NAMES = { + Default: "Default", + Black: "Black", + Red: "Red", + Green: "Green", + Yellow: "Yellow", + Blue: "Blue", + Magenta: "Magenta", + Cyan: "Cyan", + LightGray: "LightGray", + DarkGray: "DarkGray", + LightRed: "LightRed", + LightGreen: "LightGreen", + LightYellow: "LightYellow", + LightBlue: "LightBlue", + LightMagenta: "LightMagenta", + LightCyan: "LightCyan", + White: "White", +}; +//#endregion + +// +//#region Actions ... +/** + * apply specified style and color on a content ... + * + * @param {string} content specified content for styling ... + * @param {string} color specific color name for using to styling ... + * @param {string} style soecufic style name to use ... + * @param {boolean} toForeground apply specified color as foreground ... + * @param {boolean} toBackground apply specified color as background ... + * @returns {string} styled content ... + */ +function apply( + content, + color, + style, + toForeground = true, + toBackground = false +) { + // + let result = content; + + // + // Validate Arg ... + if (!XValueTools.isValidArg(content)) { + return result; + } + + // + // Detect and Validate Style and Apply it ... + let eStyle = AVAILABLE_STYLES[style]; + if (XValueTools.isValidArg(eStyle)) { + result = `${eStyle}${result}${AVAILABLE_STYLES.Reset}`; + } + + // + // Detect and Validate Foreground Color and Apply it ... + let eFColor = AVAILABLE_FOREGROUND_COLORS[color]; + if ( + !!toForeground + && XValueTools.isValidArg(eFColor) + ) { + result = `${eFColor}${result}${AVAILABLE_STYLES.Reset}`; + } + + // + // Detect and Validate Background Color and Apply it ... + let eBColor = AVAILABLE_BACKGROUND_COLORS[color]; + if ( + !!toBackground + && XValueTools.isValidArg(eBColor) + ) { + result = `${eBColor}${result}${AVAILABLE_STYLES.Reset}`; + } + +} + +/** + * apply specific style on a content ... + * + * @param {string} content specific content which going to styled ... + * @param {string} style a member of STYLE_NAMES which specified that which style going to applied to content ... + * @returns {string} styled content ... + */ +function applyStyle(content, style) { + // + // Validate Arg ... + if (!XValueTools.isValidArg(content)) { + return content; + } + + // + let eStyle = AVAILABLE_STYLES[style]; + if (eStyle === undefined) { + return content; + } + + // + return `${eStyle}${content}${AVAILABLE_STYLES.Reset}`; +} + +/** + * apply specific foreground color on a content ... + * + * @param {string} content specific content which going to colorified ... + * @param {string} color a member of COLOR_NAMES which specified that which color going to applied to content ... + * @returns {string} colorified content ... + */ +function applyForegroundColor(content, color) { + // + // Validate Arg ... + if (!XValueTools.isValidArg(content)) { + return content; + } + + // + let eColor = AVAILABLE_FOREGROUND_COLORS[color]; + if (eColor === undefined) { + return content; + } + + // + return `${eColor}${content}${AVAILABLE_STYLES.Reset}`; +} + +/** + * apply specific background color on a content ... + * + * @param {string} content specific content which going to colorified ... + * @param {string} color a member of COLOR_NAMES which specified that which color going to applied to content ... + * @returns {string} colorified content ... + */ +function applyBackgroundColor(content, color) { + // + // Validate Arg ... + if (!XValueTools.isValidArg(content)) { + return content; + } + + // + let eColor = AVAILABLE_BACKGROUND_COLORS[color]; + if (eColor === undefined) { + return content; + } + + // + return `${eColor}${content}${AVAILABLE_STYLES.Reset}`; +} + +/** + * generate style and color applier expression ... + * + * @param {string} color specific color name for using to styling ... + * @param {string} style soecufic style name to use ... + * @param {boolean} reset close applier string by reset styles ... + * @param {boolean} toForeground apply specified color as foreground ... + * @param {boolean} toBackground apply specified color as background ... + * @returns {string} style and color applier string ... + */ +function getApplier( + style = "", + color = "", + reset = false, + toForeground = true, + toBackground = false +) { + // + let result = ""; + + // + // Detect and Validate Style and Apply it ... + let eStyle = AVAILABLE_STYLES[style]; + if (XValueTools.isValidArg(eStyle)) { + result = `${eStyle}`; + } + + // + // Detect and Validate Foreground Color and Apply it ... + let eFColor = AVAILABLE_FOREGROUND_COLORS[color]; + if ( + !!toForeground + && XValueTools.isValidArg(eFColor) + ) { + result = `${eFColor}`; + } + + // + // Detect and Validate Background Color and Apply it ... + let eBColor = AVAILABLE_BACKGROUND_COLORS[color]; + if ( + !!toBackground + && XValueTools.isValidArg(eBColor) + ) { + result = `${eBColor}`; + } + + // + if ( + !!reset && + result.length > 0 + ) { + result = `${result}${AVAILABLE_STYLES.Reset}`; + } + + // + return result; +} + +/** + * generate style applier expression ... + * + * @param {string} style soecufic style name to use ... + * @param {boolean} reset close applier string by reset styles ... + * @returns {string} style applier string ... + */ +function getStyleApplier( + style = "", + reset = false +) { + // + let result = ""; + + // + // Detect and Validate Style and Apply it ... + let eStyle = AVAILABLE_STYLES[style]; + if (XValueTools.isValidArg(eStyle)) { + result = `${eStyle}`; + } + + // + if ( + !!reset && + result.length > 0 + ) { + result = `${result}${AVAILABLE_STYLES.Reset}`; + } + + // + return result; +} + +/** + * generate color applier expression ... + * + * @param {string} color specific color name for using to styling ... + * @param {boolean} reset close applier string by reset styles ... + * @param {boolean} toForeground apply specified color as foreground ... + * @param {boolean} toBackground apply specified color as background ... + * @returns {string} color applier string ... + */ +function getColorApplier( + color = "", + reset = false, + toForeground = true, + toBackground = false +) { + // + let result = ""; + + // + // Detect and Validate Foreground Color and Apply it ... + let eFColor = AVAILABLE_FOREGROUND_COLORS[color]; + if ( + !!toForeground + && XValueTools.isValidArg(eFColor) + ) { + result = `${eFColor}`; + } + + // + // Detect and Validate Background Color and Apply it ... + let eBColor = AVAILABLE_BACKGROUND_COLORS[color]; + if ( + !!toBackground + && XValueTools.isValidArg(eBColor) + ) { + result = `${eBColor}`; + } + + // + if ( + !!reset && + result.length > 0 + ) { + result = `${result}${AVAILABLE_STYLES.Reset}`; + } + + // + return result; +} + +/** + * colorified specific content ... + * + * @param {string} content specified content for styling ... + * @param {string} color specific color name for using to styling ... + * @param {boolean} toForeground apply specified color as foreground ... + * @param {boolean} toBackground apply specified color as background ... + * @returns {string} + */ +function colorifyContent( + content = "", + color = "", + toForeground = true, + toBackground = false +) { + // + let result = content; + + // + if (!XValueTools.isValidArg(content)) { + return result; + } + + // + // Finde Colors ... + + // + // Detect and Validate Foreground Color and Apply it ... + let eFColor = AVAILABLE_FOREGROUND_COLORS[color]; + if ( + !!toForeground + && XValueTools.isValidArg(eFColor) + ) { + result = `${eFColor}${result}`; + } + + // + // Detect and Validate Background Color and Apply it ... + let eBColor = AVAILABLE_BACKGROUND_COLORS[color]; + if ( + !!toBackground + && XValueTools.isValidArg(eBColor) + ) { + result = `${eBColor}${result}`; + } + + // + if ( + result.length > 0 + && ( + XValueTools.isValidArg(eFColor) || + XValueTools.isValidArg(eBColor) + ) + ) { + result = `${result}${AVAILABLE_STYLES.Reset}`; + } + + // + return result; +} + +/** + * apply style on specific content ... + * + * @param {string} content specified content for styling ... + * @param {string} style soecufic style name to use ... + * @returns {string} + */ +function stylifiyContent( + content = "", + style = "", +) { + // + let result = content; + + // + if (!XValueTools.isValidArg(content)) { + return result; + } + + // + // Detect and Validate Style and Apply it ... + let eStyle = AVAILABLE_STYLES[style]; + if (XValueTools.isValidArg(eStyle)) { + result = `${eStyle}${result}`; + } + + // + if ( + result.length > 0 + && XValueTools.isValidArg(eStyle) + ) { + result = `${result}${AVAILABLE_STYLES.Reset}`; + } + + // + return result; +} +//#endregion + +// +//#region Module Exports ... +module.exports = { + // + STYLE_NAMES, + COLOR_NAMES, + // + apply, + applyStyle, + getApplier, + getColorApplier, + getStyleApplier, + colorifyContent, + stylifiyContent, + applyForegroundColor, + applyBackgroundColor, +} +//#endregion \ No newline at end of file diff --git a/Node/x-file.tools.js b/Node/x-file.tools.js new file mode 100644 index 0000000..505849e --- /dev/null +++ b/Node/x-file.tools.js @@ -0,0 +1,909 @@ +/** + * XFile Tools Module ... + * a module for handle all file/folder manipulating task in node js ... + * + * Maintainer + * + * Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) + */ + +// +//#region Module Imports ... +const fs = require('fs'); +const os = require('os'); +const Path = require('path'); +const http = require('http'); +const https = require('https'); +const XValueTools = require('./x-value.tools'); +//#endregion + +// +//#region Constants ... +/** + * current os path separators ... + */ +const PathSeparator = Path.sep; + +/** + * current directory ... + */ +const CurrentDir = __dirname; + + +/** + * Commonly used Names ... + */ +const NAMES = { + Documents: "Documents", +}; +//#endregion + +// +//#region Actions ... +// +//#region Global ... +/** + * retrieve a path status ... + * + * @param {string} path a path value to check ... + * @returns an stat object ... + */ +function getStatus(path = '') { + // + if (!XValueTools.isValidArg(path)) { + return undefined; + } + + // + return fs.statSync(path); +} +//#endregion + +// +//#region Path Providers +/** + * retrieve user's Home path ... + * + * @returns {string} a path ... + */ +function getOSHomePath() { + return os.homedir(); +} + +/** + * retrieve os Documents path ... + * + * @returns {string} a path ... + */ +function getOSDocumentsPath() { + // + const homePath = getOSHomePath(); + const result = joinPath(homePath, NAMES.Documents); + + // + return result; +} +//#endregion + +// +//#region Path ... +/** + * retrieve the base name of specific address path ... + * + * @param {string} path address of file or folder ... + * @returns string ... + */ +function basename(path = '') { + // + if (!XValueTools.isValidArg(path)) { + return ''; + } + + // + const result = Path.basename(path); + return result; +} + +/** + * join several path segments together ... + * + * @param {...string} path path params ... + * @returns a joined paths ... + */ +function joinPath(...path) { + return Path.join(...path); +} + +/** + * resolve a relative path to absolute ... + * + * @param {string[]} path a path value to check ... + * @returns {string} + */ +function resolvePath(...path) { + return Path.resolve(...path); +} +//#endregion + +// +//#region File ... +/** + * determines a path destination is a file or not ... + * + * @param {string} path a path value to check ... + * @returns a boolean value ... + */ +function isFileExists(path = '') { + // + if (!XValueTools.isValidArg(path)) { + return false; + } + + // + try { + const stat = getStatus(path); + if (!stat) { + return false; + } + + // + return stat.isFile(); + } catch { + return false; + } +} + +/** + * remove a file ... + * + * @param {string} path a file path ... + * @returns {Promise} action done or not ... + */ +function removeFile(path = '') { + return new Promise((resolve) => { + // + if (!isFileExists(path)) { + resolve(false); + } + + // + fs.unlink(path, (err) => { + // + if (err) { + resolve(false); + return; + } + + // + resolve(true); + }); + }); +} + +/** + * copy a file to destination path ... + * + * @param {string} source source file path ... + * @param {string} dest dest folder path ... + * @returns {Promise} action done or not ... + */ +function copyFile( + source = '', + dest = '' +) { + return new Promise((resolve) => { + // + if ( + !isFileExists(source) || + !isDirectoryExists(dest) + ) { + resolve(false); + return; + } + + // + const destFilePath = Path.join(dest, Path.basename(source)); + fs.copyFile(source, destFilePath, (err) => { + // + if (err) { + resolve(false); + return; + } + + // + resolve(true); + }); + }); +} + +/** + * reading specified file content ... + * + * @param {string} path a file path ... + * @returns {Promise} file content ... + */ +function readFile(path = '') { + return new Promise((resolve) => { + // + if (!isFileExists(path)) { + resolve(''); + return; + } + + // + fs.readFile(path, 'utf8', (err, content) => { + // + if (err) { + resolve(undefined); + return; + } + + // + resolve(content); + }); + }); +} + +/** + * write content to a file ... + * + * @param {string} path a file path ... + * @param {string} content the content which going to write to the file ... + * @param {bool} overwrite determines file overwrite if exists ... + * @returns {Promise} action done or not ... + */ +function writeFile( + path = '', + content = '', + overwrite = true +) { + return new Promise((resolve) => { + // + if (isFileExists(path) && !overwrite) { + // + resolve(false); + return; + } + + // + // Normalize Content ... + content = XValueTools.isValidArg(content) ? + content : + ''; + + // + fs.writeFile(path, content, (err) => { + // + if (err) { + // + resolve(false); + return; + } + + // + resolve(true); + }); + }); +} + +/** + * create a file ... + * + * @param {string} path file path ... + * @param {string} fileName file name ... + * @returns {Promise} action done or not ... + */ +function createFile( + path = '', + fileName = '' +) { + return new Promise((resolve) => { + // + const filePath = Path.join(path, fileName); + if ( + isFileExists(filePath) || + !XValueTools.isValidArg(path) || + !XValueTools.isValidArg(fileName) + ) { + // + resolve(false); + return; + } + + // + fs.writeFile(filePath, '', (err) => { + // + if (err) { + // + resolve(false); + return; + } + + // + resolve(true); + }); + }); +} + +/** + * remove a file name extension ... + * + * @param {string} name + * @returns {string} name without extension ... + */ +function removeFileExtension(name = '') { + return name.substring(0, name.lastIndexOf('.')) || name; +} + +/** + * retrieve a file extension ... + * + * @param {string} path a path which locate a file ... + * @returns {string} + */ +function getFileExtension(path = '') { + // + let result = ""; + + // + // Validate Arg ... + if ( + !XValueTools.isValidArg(path) + || !isFileExists(path) + ) { + return result; + } + + // + // Retrieve just file name ... + const fileName = basename(path); + result = fileName.replace( + removeFileExtension(fileName), + "" + ); + + // + return result; +} + +/** + * retrieve all files list recursively from specific path ... + * + * @param {string} path a source folder path ... + * @param {string[]} extensions which file extensions need to be listed, live empty for all files ... + * @returns {Promise} + */ +async function getRecursiveFilesList( + path = "", + extensions = [] +) { + // + let result = []; + + // + // Validate Args ... + if ( + !XValueTools.isValidArg(path) + || !isDirectoryExists(path) + ) { + return result; + } + + // + const contents = await getDirectoryContents(path); + for (const item of contents) { + // + const itemPath = joinPath( + path, + item + ); + + // + const isItemFile = isFileExists(itemPath); + if (isItemFile) { + // + const itemFileExtension = getFileExtension(itemPath); + const isFileInSupportedExtensions = + extensions === undefined || extensions.length === 0 + ? true + : extensions.includes(itemFileExtension) + ; + if (isFileInSupportedExtensions) { + result.push(itemPath); + } + } else if (isDirectoryExists(itemPath)) { + // + const itemPathFiles = await getRecursiveFilesList(itemPath, extensions); + result.push(...itemPathFiles); + } + } + + // + return result; +} +//#endregion + +// +//#region Directory ... +/** + * create a directory ... + * + * @param {string} path destination path including dir name ... + * @param {boolean} recursive create directories recursively ... + * @returns action done or not ... + */ +function createDirectory( + path = '', + recursive = true +) { + // + let result = false; + + // + if ( + isDirectoryExists(path) || + !XValueTools.isValidArg(path) + ) { + return false; + } + + // + try { + // + fs.mkdirSync(path, { recursive: recursive }); + result = true; + return result; + } catch { + return false; + } +} + +/** + * remove a directory ... + * + * @param {string} path destination path including dir name ... + * @param {boolean} recursive removes directories recursively ... + * @returns {Promise} action done or not ... + */ +function removeDirectory( + path = '', + recursive = false +) { + return new Promise((resolve) => { + // + if (!isDirectoryExists(path)) { + resolve(false); + return; + } + + // + fs.rm(path, { + recursive + }, (err) => { + // + if (err) { + resolve(false); + return; + } + + // + resolve(true); + }); + }); +} + +/** + * determines a path destination is a directory or not ... + * + * @param {string} path a folder path ... + * @returns represent destnation path is Directory or not ... + */ +function isDirectoryExists(path = '') { + // + if (!XValueTools.isValidArg(path)) { + return false; + } + + // + try { + // + const isExists = fs.existsSync(path); + if (!isExists) { + return false; + } + + // + const stat = getStatus(path); + if (!stat) { + return false; + } + + // + const result = stat.isDirectory(); + return result; + } catch { + return false; + } +} + +/** + * retrieve a directory content ... + * + * @param {string} path a folder path ... + * @returns {Promise} a collection of folder files ... + */ +function getDirectoryContents(path = '') { + return new Promise((resolve) => { + // + if (!isDirectoryExists(path)) { + resolve([]); + return; + } + + // + fs.readdir(path, (err, content) => { + // + if (err) { + resolve([]); + return; + } + + // + resolve(content); + }); + }); +} + +/** + * retrieve a directory files ... + * + * @param {string} path a folder path ... + * @returns {Promise} a collection of folder files ... + */ +function getDirectoryFiles( + path = '', + containsHiddenFiles = false +) { + return new Promise((resolve) => { + // + if (!isDirectoryExists(path)) { + resolve([]); + return; + } + + // + fs.readdir(path, (err, content) => { + // + if (err) { + resolve([]); + return; + } + + // + if (!containsHiddenFiles) { + content = content.filter(c => !c.startsWith('.')); + } + + // + const result = []; + content + .forEach(c => { + // + const cPath = Path.join(path, c); + if (isFileExists(cPath)) { + result.push(c); + } + }); + + // + resolve(result); + }); + }); +} + +/** + * retrieve a directory folders ... + * + * @param {string} path a folder path ... + * @returns {Promise} a collection of folder names ... + */ +function getDirectoryFolders(path = '') { + return new Promise((resolve) => { + // + if (!isDirectoryExists(path)) { + resolve([]); + return; + } + + // + fs.readdir(path, (err, content) => { + // + if (err) { + resolve([]); + return; + } + + // + const result = []; + content.forEach(c => { + // + const cPath = Path.join(path, c); + if (isDirectoryExists(cPath)) { + result.push(c); + } + }); + + // + resolve(result); + }); + }); +} + +/** + * copy a folder with all of it's content to dest ... + * + * @param {string} source source folder path ... + * @param {string} dest dest folder path ... + * @returns {Promise} action done or not ... + */ +async function copyFolder( + source = '', + dest = '' +) { + // + if ( + !isDirectoryExists(source) || + !XValueTools.isValidArg(dest) || + !XValueTools.isValidArg(source) + ) { + return false; + } + + // + const folderName = Path.basename(source); + const destPath = Path.join(dest, folderName); + + // + // Create Dest Path folder if not exists ... + if (!isDirectoryExists(destPath)) { + // + let result = createDirectory(destPath, true); + if (!result) { + return false; + } + } + + // + // Files ... + const files = await getDirectoryFiles(source); + if (files && files.constructor === Array && files.length > 0) { + // + const filesPromises = files.map(file => copyFile(Path.join(source, file), destPath)); + const filesResult = (await Promise.all(filesPromises)).every(r => !!r); + if (!filesResult) { + return false; + } + } + + // + // Folders ... + const folders = await getDirectoryFolders(source); + if (folders && folders.constructor === Array && folders.length > 0) { + // + const folderPromises = folders.map(folder => copyFolder(Path.join(source, folder), destPath)); + const filesResult = (await Promise.all(folderPromises)).every(r => !!r); + if (!filesResult) { + return false; + } + } + + // + return true; +} + +/** + * copy a folder's content recursively to dest path ... + * + * @param {string} source source folder path ... + * @param {string} dest dest folder path ... + * @returns {Promise} action done or not ... + */ +async function copyFolderContent( + source = '', + dest = '' +) { + // + if ( + !isDirectoryExists(source) || + !isDirectoryExists(dest) || + !XValueTools.isValidArg(dest) || + !XValueTools.isValidArg(source) + ) { + return false; + } + + // + // + // Files ... + const files = await getDirectoryFiles(source); + if (files && files.constructor === Array && files.length > 0) { + // + const filesPromises = files.map(file => copyFile(joinPath(source, file), dest)); + const filesResult = (await Promise.all(filesPromises)).every(r => !!r); + if (!filesResult) { + return false; + } + } + + // + // Folders ... + const folders = await getDirectoryFolders(source); + if (folders && folders.constructor === Array && folders.length > 0) { + // + const folderPromises = folders.map(folder => copyFolder(joinPath(source, folder), dest)); + const filesResult = (await Promise.all(folderPromises)).every(r => !!r); + if (!filesResult) { + return false; + } + } + + // + return true; +} +//#endregion + +// +//#region Downloader ... +/** + * download a file from specific url and store it ... + * + * @param {string} filepath the file name and path which required to put download file on it ... + * @param {string} url the web url for downloading ... + */ +function download(filepath, url) { + // + // Validate Args ... + if ( + !XValueTools.isValidArg(url) + || !XValueTools.isValidURL(url) + || !XValueTools.isValidArg(filepath) + ) { + return; + } + + // + var file = fs.createWriteStream(filepath); + + // + if (url.startsWith('https:')) { + https.get(url, function (response) { + response.pipe(file); + }); + } else if (url.startsWith('http:')) { + http.get(url, function (response) { + response.pipe(file); + }); + } +} +//#endregion + +// +//#region JSON ... +/** + * read and parse a JSON content from a file ... + * + * @param {string} path source file path ... + * @returns {any} + */ +function readJSON(path = "") { + // + // Validate Args ... + if (!isFileExists(path)) { + return undefined; + } + + // + let result = undefined; + try { + result = require(path); + } catch { + result = undefined; + } + + // + return result; +} + +/** + * write a JSON Object content into a file ... + * + * @param {string} path dest file path ... + * @param {any} content an object which required to write to file ... + * @returns {Promise} + */ +async function writeJSON( + path = "", + content = undefined +) { + // + let result = false; + + // + // Validate Args ... + if (!XValueTools.isValidArg(path)) { + return result; + } + + // + // Normallize Content ... + if (content === undefined) { + content = {}; + } + + // + const contentString = XValueTools.beautifyJSON(content); + + // + result = await writeFile( + path, + contentString, + true + ); + + // + return result; +} +//#endregion +//#endregion + +// +//#region Module Exports ... +module.exports = { + // + CurrentDir, + PathSeparator, + + // + getStatus, + + // + getOSHomePath, + getOSDocumentsPath, + + // + basename, + joinPath, + resolvePath, + + // + download, + + // + readJSON, + writeJSON, + + // + copyFile, + readFile, + writeFile, + createFile, + removeFile, + isFileExists, + getFileExtension, + removeFileExtension, + getRecursiveFilesList, + + // + copyFolder, + createDirectory, + removeDirectory, + createDirectory, + removeDirectory, + isDirectoryExists, + isDirectoryExists, + copyFolderContent, + getDirectoryFiles, + getDirectoryFolders, + getDirectoryContents, +}; +//#endregion \ No newline at end of file diff --git a/Node/x-logger.tools.js b/Node/x-logger.tools.js new file mode 100644 index 0000000..ed6ccf8 --- /dev/null +++ b/Node/x-logger.tools.js @@ -0,0 +1,362 @@ + +/** + * XLogger Tools Module ... + * a module which used to handle all Loggings related actions in node js ... + * + * Maintainer + * + * Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) + */ + +// +//#region Imports ... +const XColorTools = require("./x-color.tools"); +const XValueTools = require("./x-value.tools"); +//#endregion + +// +//#region Variables/Constants ... +let baseLogTag = 'xFrameworkCLI'; +let enableLogging = true; + +/** + * Log Tags ... + */ +const XLogTag = { + Debug: 'debug', + Info: 'info', + Warn: 'warn', + Error: 'error' +}; +//#endregion + +// +//#region Actions ... +/** + * retrieve an instance of XLogMessage ... + * + * @param {string} tag tag of logging ... + * @param {string} message content of log message ... + * @param {array of any} args args of content which required to logging ... + * @param {number} timestamp logging time ... + * + * @returns an instance of log message object ... + */ +function XLogMessage( + tag, + message, + args, + timestamp +) { + // + if (!tag) { + throw 'Tag not provided ...'; + } + + // + if (!message) { + throw 'Message not provided ...'; + } + + // + if (!args) { + args = []; + } + + // + if (!timestamp) { + timestamp = new Date().getTime(); + } + + // + return { + tag, + message, + args, + timestamp, + }; +} + +/** + * log data ... + * + * @param {XLogMessage} message + */ +function log(message) { + // + if (!message || !message.tag || !message.message || !enableLogging) { + return; + } + + // + message.timestamp = new Date().getTime(); + + // + switch (message.tag) { + // + case XLogTag.Debug: + logDebug(message); + break; + // + case XLogTag.Info: + logInfo(message); + break; + // + case XLogTag.Warn: + logWarn(message); + break; + // + case XLogTag.Error: + logError(message); + break; + + // + default: + break; + } +} + +/** + * Log Debug ... + * + * @param {XLogMessage} message + */ +function logDebug(message) { + // + if (!message || !message.message || !enableLogging || message.tag !== XLogTag.Debug) { + return; + } + + // + message.timestamp = new Date().getTime(); + + // + const cBaseLogTag = XColorTools.colorifyContent( + baseLogTag, + XColorTools.COLOR_NAMES.LightGray + ); + + // + const cTag = XColorTools.colorifyContent( + message.tag, + XColorTools.COLOR_NAMES.Default + ); + + // + const cMessage = XColorTools.colorifyContent( + message.message, + XColorTools.COLOR_NAMES.LightGray + ); + + // + console.debug(`${cBaseLogTag}:${cTag} => ${cMessage}`, ...message.args); +} + +/** + * Log Info ... + * + * @param {XLogMessage} message + */ +function logInfo(message) { + // + if (!message || !message.message || !enableLogging || message.tag !== XLogTag.Info) { + return; + } + + // + message.timestamp = new Date().getTime(); + + // + const cBaseLogTag = XColorTools.colorifyContent( + baseLogTag, + XColorTools.COLOR_NAMES.LightGray + ); + + // + const cTag = XColorTools.colorifyContent( + message.tag, + XColorTools.COLOR_NAMES.Default + ); + + // + const cMessage = XColorTools.colorifyContent( + message.message, + XColorTools.COLOR_NAMES.Blue + ); + + // + console.info(`${cBaseLogTag}:${cTag} => ${cMessage}`, ...message.args); +} + +/** + * Log Warn ... + * + * @param {XLogMessage} message + */ +function logWarn(message) { + // + if (!message || !message.message || !enableLogging || message.tag !== XLogTag.Warn) { + return; + } + + // + message.timestamp = new Date().getTime(); + + // + const cBaseLogTag = XColorTools.colorifyContent( + baseLogTag, + XColorTools.COLOR_NAMES.LightGray + ); + + // + const cTag = XColorTools.colorifyContent( + message.tag, + XColorTools.COLOR_NAMES.Default + ); + + // + const cMessage = XColorTools.colorifyContent( + message.message, + XColorTools.COLOR_NAMES.Yellow + ); + + // + console.warn(`${cBaseLogTag}:${cTag} => ${cMessage}`, ...message.args); +} + +/** + * Log Error ... + * + * @param {XLogMessage} message + */ +function logError(message) { + // + if (!message || !message.message || !enableLogging || message.tag !== XLogTag.Error) { + return; + } + + // + message.timestamp = new Date().getTime(); + + // + const cBaseLogTag = XColorTools.colorifyContent( + baseLogTag, + XColorTools.COLOR_NAMES.LightGray + ); + + // + const cTag = XColorTools.colorifyContent( + message.tag, + XColorTools.COLOR_NAMES.Default + ); + + // + const cMessage = XColorTools.colorifyContent( + message.message, + XColorTools.COLOR_NAMES.Red + ); + + // + console.error(`${cBaseLogTag}:${cTag} => ${cMessage}`, ...message.args); +} + +/** + * issue simple debug log ... + * + * @param {string} message log message ... + */ +function simpleDebugLog(message = "") { + // + const msgObject = XLogMessage( + XLogTag.Debug, + message + ); + + // + logDebug(msgObject); +} + +/** + * issue simple info log ... + * + * @param {string} message log message ... + */ +function simpleInfoLog(message = "") { + // + const msgObject = XLogMessage( + XLogTag.Info, + message + ); + + // + logInfo(msgObject); +} + +/** + * issue simple warn log ... + * + * @param {string} message log message ... + */ +function simpleWarnLog(message = "") { + // + const msgObject = XLogMessage( + XLogTag.Warn, + message + ); + + // + logWarn(msgObject); +} + +/** + * issue simple error log ... + * + * @param {string} message log message ... + */ +function simpleErrorLog(message = "") { + // + const msgObject = XLogMessage( + XLogTag.Error, + message + ); + + // + logError(msgObject); +} +//#endregion + +// +//#region Module Eports ... +module.exports = { + // + enableLogging: () => { + enableLogging = true; + }, + disableLogging: () => { + enableLogging = false; + }, + isLoggingEnable: () => { + return enableLogging; + }, + changeBaseLogTag: (value => { + // + if (XValueTools.isValidArg(value)) { + baseLogTag = value; + } + }), + // + XLogTag: XLogTag, + // + XLogMessage: XLogMessage, + log: log, + logDebug: logDebug, + logInfo: logInfo, + logWarn: logWarn, + logError: logError, + // + simpleDebugLog, + simpleInfoLog, + simpleWarnLog, + simpleErrorLog, +} +//#endregion \ No newline at end of file diff --git a/Node/x-type-detector.tools.js b/Node/x-type-detector.tools.js new file mode 100644 index 0000000..86ed3d8 --- /dev/null +++ b/Node/x-type-detector.tools.js @@ -0,0 +1,268 @@ +/** + * DataType Tools Module ... + * a module for manipulate and detect supported data types in node js ... + * + * Maintainer + * + * Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) + */ + +// +//#region Constants ... +/** + * all supported data types ... + */ +const DataTypes = { + Null: 'null', + Date: 'date', + Array: 'array', + Object: 'object', + String: 'string', + Number: 'number', + Unknown: 'unknown', + Boolean: 'boolean', + Function: 'function', + Undefined: 'undefined', +}; +//#endregion + +// +//#region Actions ... +/** + * detect type of a content ... + * + * @param {any} value the content which going to check ... + * @returns + */ +function getType(value) { + // + const type = typeof value; + + // + let result = DataTypes.Unknown; + let dateIdentifier = '[object Date]'; + let constructor = value && value.constructor ? + value.constructor.toString() : + ''; + + // + switch (type) { + // + case 'undefined': + result = DataTypes.Undefined; + break; + + // + case 'boolean': + result = DataTypes.Boolean; + break; + + // + case 'string': + result = DataTypes.String; + break; + + // + case 'number': + result = DataTypes.Number; + break; + + // + case 'function': + result = DataTypes.Function; + break; + + // + case 'object': + // + // Null ... + if (value === null) { + result = DataTypes.Null; + } else + // + // Array ... + if (Array.isArray(value)) { + result = DataTypes.Array; + } else + // + // Data ... + if ( + value instanceof Date || + isFunction(value.getMonth) || + constructor.includes(dateIdentifier) || + Object.prototype.toString.call(value) === dateIdentifier + ) { + result = DataTypes.Date; + } else + // + // Object ... + { + result = DataTypes.Object; + } + break; + + // + default: + result = DataTypes.Unknown; + break; + } + + // + return result; +} + +/** + * retrieve an object constructor ... + * + * @param {any} value the content which going to check ... + * @returns + */ +function getConstructor(value) { + // + const result = value && value.constructor ? + value.constructor.toString() : + ''; + + // + return result; +} + +/** + * retrieve an object prototype ... + * + * @param {any} value the content which going to check ... + * @returns + */ +function getPrototype(value) { + // + const result = value ? + Object.prototype.toString.call(value) : + ''; + + // + return result; +} + +/** + * check an object is null or not ... + * + * @param {any} value the content which going to check ... + * @returns + */ +function isNull(value) { + return getType(value) === DataTypes.Null; +} + +/** + * check an object is undefined or not ... + * + * @param {any} value the content which going to check ... + * @returns + */ +function isUndefined(value) { + return getType(value) === DataTypes.Undefined; +} + +/** + * check an object is null or undefined or not ... + * + * @param {any} value the content which going to check ... + * @returns + */ +function isNullOrUndefined(value) { + return isNull(value) || isUndefined(value); +} + +/** + * check an object is a date or not ... + * + * @param {any} value the content which going to check ... + * @returns + */ +function isDate(value) { + return getType(value) === DataTypes.Date; +} + +/** + * check an object is number or not ... + * + * @param {any} value the content which going to check ... + * @returns + */ +function isNumber(value) { + return getType(value) === DataTypes.Number; +} + +/** + * check an object is string or not ... + * + * @param {any} value the content which going to check ... + * @returns + */ +function isString(value) { + return getType(value) === DataTypes.String; +} + +/** + * check an object is boolean or not ... + * + * @param {any} value the content which going to check ... + * @returns + */ +function isBoolean(value) { + return getType(value) === DataTypes.Boolean; +} + +/** + * check an object is an Array or not ... + * + * @param {any} value the content which going to check ... + * @returns + */ +function isArray(value) { + return getType(value) === DataTypes.Array; +} + +/** + * check an object is and Object or not ... + * + * @param {any} value the content which going to check ... + * @returns + */ +function isObject(value) { + return getType(value) === DataTypes.Object; +} + +/** + * check an object is a Function or not ... + * + * @param {any} value the content which going to check ... + * @returns + */ +function isFunction(value) { + return getType(value) === DataTypes.Function; +} +//#endregion + +// +//#region Module Exports ... +module.exports = { + // + DataTypes, + + // + getType, + getConstructor, + getPrototype, + isNull, + isUndefined, + isNullOrUndefined, + isDate, + isNumber, + isString, + isBoolean, + isArray, + isObject, + isFunction, +} +//#endregion \ No newline at end of file diff --git a/Node/x-value.tools.js b/Node/x-value.tools.js new file mode 100644 index 0000000..81cfcc4 --- /dev/null +++ b/Node/x-value.tools.js @@ -0,0 +1,1528 @@ +/** + * Value Tools Module ... + * a module for Validate args and values ... + * + * Maintainer + * + * Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) + */ + +// +//#region Imports ... +const XTypeTools = require('./x-type-detector.tools'); +//#endregion + +// +//#region Actions ... +/** +* validate a value as an argument ... +* +* @param {string} value the value which going to validate ... +* @returns +*/ +function isValidArg(value) { + // + let result = false; + + // + result = value && + value.length > 0; + + // + return result; +} + +/** + * validate a collection of valuea as an arguments ... + * + * @param {string|string[]} values the value collection which going to checked ... + * @returns + */ +function isValidArgs(values) { + // + // Normalize Values ... + const normalValues = toNormalArray(values); + if (!hasChildArray(normalValues)) { + return false; + } + + // + let result = normalValues.every(nv => isValidArg(nv)); + return result; +} + +/** + * converts content to an array object ... + * + * @param {string|string[]} content the content which required to normalized ... + * @returns {string[]} array object ... + */ +function toNormalArray(content = '') { + // + // Validate Args ... + if (!isValidArg(content)) { + return []; + } + + // + const result = Array.isArray(content) ? + [...content] : + content.includes(',') && + content !== ',' ? + [...content.split(',')] : + [content]; + + // + return result; +} + +/** + * determines value is array and has atleast one child ... + * + * @param {any} value the value which going to checked ... + * @returns {boolean} result of checking ... + */ +function hasChildArray(value) { + // + let result = false; + result = value && + Array.isArray(value) && + value.length > 0; + + // + return result; +} + +/** + * check an string is ends with specified symbol ... + * + * @param {string} symbol specified search symbol ... + * @param {string} value specified search content ... + * @param {boolean} ignoreCase specified search case sensitive or not ... + * @returns + */ +function endsWidth( + symbol = '', + value = '', + ignoreCase = true +) { + // + if (!isValidArg(value)) { + return false; + } + + // + if (!isValidArg(symbol)) { + return true; + } + + // + // TODO: uncomment it if necessary ... + // symbol = symbol.trim(); + + // + let result = false; + const subtractedContent = value.substring(value.length - symbol.length); + result = !!ignoreCase ? + subtractedContent + .toLowerCase() === symbol + .toLowerCase() : + subtractedContent === symbol; + + // + return result; +} + +/** + * surround specified content by provided symbol ... + * + * @param {string} symbol surround string ... + * @param {string} content used content to surrounded by symbol ... + * @returns surrounded content ... + */ +function surroundBy( + symbol = '', + content = '' +) { + // + // Validate Args ... + if (!isValidArg(content)) { + content = ''; + } + + // + if (!isValidArg(symbol)) { + symbol = ''; + } + + // + if (isSurrounded(symbol, content)) { + return content; + } + + // + const result = `${symbol}${content}${symbol}`; + return result; +} + +/** + * convert a parsed sign to clear string ... + * + * @param {string} value a parsed content ... + * @returns clear parsed signs ... + */ +function toStringExpression(value) { + // + let result = ''; + result = value; + + // + if ( + !value || + !isValidArg(value) || + !isSurroundedString(value) + ) { + return result; + } + + // + const startSymbol = value.charAt(0); + const endSymbol = value.charAt(value.length - 1); + + // + if (startSymbol !== endSymbol) { + return result; + } + + // + if ( + startSymbol === "\"" || + startSymbol === "\'" + ) { + result = clearSurround(startSymbol, value); + } + + // + return result; +} + + + +/** + * find and cleare proposed candidates from specified content ... + * + * @param {string|string[]} candidates the proposed string(s) whic going to cleared from content ... + * @param {string} content the destination content which used to find and replace candidates on it ... + * @returns cleared content ... + */ +function clearContent( + candidates, + content +) { + // + // Validate Args ... + if ( + !candidates || + !isValidArg(content) + ) { + return ''; + } + + // + // Normalize candidates ... + const normalCandidates = toNormalArray(candidates) + .filter(c => isValidArg(c)); + if (!hasChildArray(normalCandidates)) { + return content; + } + + // + // define regexp for content ... + const regExpExpression = normalCandidates.join('|'); + const regExp = new RegExp( + regExpExpression, + 'gi' + ); + + // + let result = ''; + result = content.replace(regExp, ''); + + // + return result; +} + +/** + * clear surrounded symbol from content ... + * + * @param {string} symbol specified search symbol ... + * @param {string} content specified content to clear ... + * @returns + */ +function clearSurround( + symbol = '', + content = '' +) { + // + // Validate Args ... + if ( + !isValidArg(content) || + (isValidArg(symbol) && + symbol.length >= content.length - 1) + ) { + return ''; + } + + // + // Validate Surround ... + if (!isSurrounded(symbol, content)) { + return content; + } + + // + if (!isValidArg(symbol)) { + return content; + } + + // + let result = content.substring(symbol.length, content.length - symbol.length); + return result; +} + +/** + * clear object sign ... + * + * @param {string} content + * @returns cleared content ... + */ +function clearObjectSurround(content = '') { + // + // Validate Args ... + if ( + !isValidArg(content) || + !isSurroundedObject(content) + ) { + return content; + } + + // + const endIndex = content.length - ( + endsWidth('}', content) ? + 1 : + endsWidth('},', content) || + endsWidth('};', content) || + endsWidth('}\n', content) ? + 2 : + 0 + ); + + // + const result = content.substring(1, endIndex); + return result; +} + +/** + * clear array sign ... + * + * @param {string} content + * @returns cleared content ... + */ +function clearArraySurround(content = '') { + // + // Validate Args ... + if ( + !isValidArg(content) || + !isSurroundedArray(content) + ) { + return content; + } + + // + const endIndex = content.length - ( + endsWidth(']', content) ? + 1 : + endsWidth('],', content) || + endsWidth('];', content) || + endsWidth(']\n', content) ? + 2 : + 0 + ); + + // + const result = content.substring(1, endIndex); + return result; +} + +/** + * slice a content to individual parts ... + * + * @param {number|number[]} indexes which indexes used to slice ... + * @param {strng} content the content which going to sliced ... + * @returns sliced parts of content ... + */ +function sliceContent(indexes, content) { + // + // Validate Args ... + if ( + !isValidArg(indexes) || + !isValidArg(content) + ) { + return []; + } + + // + // Normalize indexes ... + const normalIndexes = toNormalArray(indexes) + .filter(index => index > -1 && index < content.length); + if (!hasChildArray(normalIndexes)) { + return []; + } + + // + let result = ['']; + result.pop(); + + // + let lastIndex = 0; + for (const index of normalIndexes) { + // + const part = content.substring(lastIndex, index); + if (isValidArg(part)) { + result.push(part.trim()); + } + + // + lastIndex = index + 1; + } + + // + // check remained parts ... + if (lastIndex < content.length) { + // + const part = content.substring(lastIndex); + if (isValidArg(part)) { + result.push(part.trim()); + } + } + + // + return result; +} + + + +/** + * check an string is starts and ends with specified symbol ... + * + * @param {string} symbol specified search symbol ... + * @param {string} content specified search content ... + * @param {boolean} ignoreCase specified search case sensitive or not ... + * @returns + */ +function isSurrounded( + symbol = '', + content = '', + ignoreCase = true +) { + // + // Validate Args ... + if (!isValidArg(content)) { + return false; + } + + // + if (!isValidArg(symbol)) { + return true; + } + + // + symbol = symbol.trim(); + + // + let result = false; + result = (!!ignoreCase ? + content + .toLowerCase() + .startsWith(symbol.toLowerCase()) : + content.startsWith(symbol) + ) && + endsWidth(symbol, content, ignoreCase); + + // + return result; +} + +/** + * determines a content is an string surrounded value or not ... + * + * @param {string} content a content which going to check ... + * @returns + */ +function isSurroundedString(content = '') { + // + // Validate Args ... + if (!isValidArg(content)) { + return false; + } + + // + let result = false; + result = ( + content.startsWith('\'') && + ( + endsWidth('\'', content) || + endsWidth('\',', content) || + endsWidth('\';', content) || + endsWidth('\'\n', content) + ) || + content.startsWith('\"') && + ( + endsWidth('\"', content) || + endsWidth('\",', content) || + endsWidth('\";', content) || + endsWidth('\"\n', content) + ) || + content.startsWith('`') && + ( + endsWidth('\`', content) || + endsWidth('\`,', content) || + endsWidth('\`;', content) || + endsWidth('\`\n', content) + ) + ); + return result; +} + +/** + * check a content is an array content or not ... + * + * @param {string} content + * @returns + */ +function isSurroundedArray(content = '') { + // + // Validate Args ... + if (!isValidArg(content)) { + return false; + } + + // + let result = false; + result = content.startsWith('[') && + ( + endsWidth(']', content) || + endsWidth('],', content) || + endsWidth('];', content) || + endsWidth(']\n', content) + ); + return result; +} + +/** + * check a content is an object content or not ... + * + * @param {string} content + * @returns + */ +function isSurroundedObject(content = '') { + // + // Validate Args ... + if (!isValidArg(content)) { + return false; + } + + // + let result = false; + result = content.startsWith('{') && + ( + endsWidth('}', content) || + endsWidth('},', content) || + endsWidth('};', content) || + endsWidth('}\n', content) + ); + return result; +} + +/** + * check an index model is contains inside anothers or not ... + * + * @param {{ start: number, end: number}} source the source index model to check ... + * @param {...{ start: number, end: number}} dest the collection of index models which going to check ... + * @returns + */ +function isIndexInside(source, ...dest) { + // + let result = false; + + // + // Validate Args ... + if (!source || !dest) { + return result; + } + + // + // Check idx is standard ... + if ( + !source || + !source.end || + !source.start || + source.start > source.end + ) { + return false; + } + + // + // Check types of destinations ... + for (let index of dest) { + // + // Check idx is standard ... + if ( + !index || + !index.end || + !index.start || + index.start > index.end + ) { + return false; + } + } + + // + if (dest.includes(source)) { + dest = dest.filter(d => d !== source); + } + + // + const insideContentIndex = dest.find(dIndex => { + // + const result = source.start >= dIndex.start && + source.start <= dIndex.end && + source.end >= dIndex.start && + source.end <= dIndex.end; + return result; + }); + + // + result = insideContentIndex; + return result; +} + +/** + * check a number exists in + * @param {number} idx the number which going to check ... + * @param {{ start: number, end: number}} index the index model + * @returns + */ +function isInsideIndex(idx = -1, index) { + // + let result = false; + + // + // Validate Args ... + if ( + !index || + !index.hasOwnProperty('end') || + !index.hasOwnProperty('start') + ) { + return result; + } + + // + result = idx > index.start && idx < index.end; + return result; +} + +/** + * determines an object is key/value and type ... + * + * @param {any} content the object which we are going to check ... + * @returns + */ +function isKeyValueType(content) { + // + const result = content && + content.hasOwnProperty('key') && + content.hasOwnProperty('type') && + content.hasOwnProperty('value'); + + // + return result; +} + + + +/** + * find all indexes of token(s) in content ... + * + * @param {string|string[]} tokens the tokens which require to search ... + * @param {string} content the content which using to search ... + * @returns {number[]} all occured indexes ... + */ +function findAllIndexes( + tokens, + content +) { + // + // Validate Args ... + if ( + !isValidArg(tokens) || + !isValidArg(content) + ) { + return []; + } + + // + // normalize tokens ... + const normalTokens = toNormalArray(tokens); + if (!hasChildArray(normalTokens)) { + return []; + } + + // + // Parse contents ... + let match; + const result = []; + const regExp = new RegExp( + normalTokens.join('|'), + 'g' + ); + while ((match = regExp.exec(content)) !== null) { + result.push(match.index); + } + if (!hasChildArray(result)) { + return []; + } + + // + return result; +} + +/** + * find nearest symbol in a content from specified index ... + * + * @param {string|string[]} candidates specifies which symbols to find ... + * @param {string} content te content for seasrch ... + * @param {number} startFromIndex the index of start position ... + * @returns + */ +function findNearest( + candidates, + content = '', + startFromIndex = 0 +) { + // + // Validate Args ... + if ( + !isValidArg(content) || + !isValidArg(candidates) || + !isValidArg(content.trim()) + ) { + return ''; + } + + // + // Normalize Content ... + content = content.trim(); + + // + // Normalize Starts From ... + startFromIndex = startFromIndex < 0 || startFromIndex > content.length - 1 ? 0 : startFromIndex; + + // + // Normalize Symbols ... + const normalCandidates = toNormalArray(candidates); + if (!hasChildArray(normalCandidates)) { + return ''; + } + + // + let nearestIndex = findNearestIndex( + normalCandidates, + content, + startFromIndex + ); + if (nearestIndex < 0) { + return ''; + } + + // + let result = content.substring( + nearestIndex, + nearestIndex + Math.max(...normalCandidates.map(nc => nc.length)) + ).trim(); + return result; +} + +/** + * search candidates in content and find nearest one and return it ... + * + * @param {string|string[]} candidates which candidates required to check ... + * @param {string} content the content which required to search candidates ... + * @param {number} startFromIndex the proposed index to start searching content from on ... + * @returns + */ +function findNearestIndex( + candidates = [''], + content = '', + startFromIndex = 0, + ignoreClosedItems = false +) { + // + // Validate Args ... + if ( + !isValidArg(content) || + !isValidArg(candidates) + ) { + return -1; + } + + // + // Mormalize startFromIndex value ... + startFromIndex = startFromIndex < 0 ? + 0 : + startFromIndex > content.length - 1 ? + content.length - 1 : + startFromIndex; + + // + // Normalize candidates ... + let normalCandidates = toNormalArray(candidates); + + // + if (!!ignoreClosedItems) { + normalCandidates = normalCandidates + .map(c => content.indexOf( + c, + startFromIndex + ) + ).map(c => +c) + .filter(c => +c > -1); + } else { + normalCandidates = findAllIndexesOutOfCloseds(normalCandidates, content) + .filter(c => c >= startFromIndex); + } + if (!hasChildArray(normalCandidates)) { + return -1; + } + + // + let result = -1; + result = Math.min(...normalCandidates); + + // + return result; +} + +/** + * find close index of specific sign in destination content ... + * + * @param {string} openSymbol open of area sign ... + * @param {string} closeSymbol close of area sign ... + * @param {string} content the destination content for parsing ... + * @param {number} startsFrom an start index of content for start parsing ... + * @returns + */ +function findCloseIndex( + openSymbol = '', + closeSymbol = '', + content = '', + startsFrom = -1 +) { + // + // Validate Args ... + if ( + startsFrom < 0 || + !isValidArg(content) || + !isValidArg(openSymbol) || + !isValidArg(closeSymbol) || + openSymbol === closeSymbol || + !content.includes(openSymbol) || + !content.includes(closeSymbol) || + startsFrom > content.length - 1 + ) { + return -1; + } + + // + let result = -1; + + // + let index = startsFrom; + const openSignStack = []; + while (index < content.length) { + // + const openCandidate = content.substring(index, index + openSymbol.length); + const closeCandidate = content.substring(index, index + closeSymbol.length); + + // + if (openCandidate === openSymbol) { + openSignStack.push(index); + } else if (closeCandidate === closeSymbol) { + // + if (openSignStack.length > 0) { + openSignStack.pop(); + } + + // + if (openSignStack.length === 0) { + result = index; + break; + } + } + + // + index++; + } + + // + return result; +} + +/** + * find closed contents of specific sign in destination content ... + * + * @param {string} openSymbol open of area sign ... + * @param {string} closeSymbol close of area sign ... + * @param {string} content the destination content for parsing ... + * @param {number} startsFrom an start index of content for start parsing ... + * @returns + */ +function findClosedContent( + openSymbol = '', + closeSymbol = '', + content = '', + startsFrom = 0, +) { + // + let result = [{ + start: -1, + end: -1, + content: '' + }]; + result.pop(); + + // + // Validate Args ... + if ( + !isValidArg(content) || + !isValidArg(openSymbol) || + !isValidArg(closeSymbol) || + !content.includes(openSymbol) || + !content.includes(closeSymbol) || + openSymbol.length >= content.length || + closeSymbol.length >= content.length + ) { + return result; + } + + // + // Normalize Start From ... + startsFrom = startsFrom < 0 || startsFrom >= content.length ? 0 : startsFrom; + + // + let canContinue = true; + while (!!canContinue) { + // + let openSymbolIndex = content.indexOf(openSymbol, startsFrom); + if (openSymbolIndex < 0) { + // + canContinue = false; + continue; + } + + // + let closeSymbolIndex = findCloseIndex( + openSymbol, + closeSymbol, + content, + openSymbolIndex + ); + if (closeSymbolIndex < 0) { + // + canContinue = false; + continue; + } + if (content.charAt(closeSymbolIndex) !== closeSymbol) { + closeSymbolIndex++; + } + + // + // Prevent ${} string interpolations ... + if ( + openSymbol === '{' && + openSymbolIndex - 1 >= 0 + ) { + // + const prevChar = content.charAt(openSymbolIndex - 1); + if (prevChar === '$') { + continue; + } + } + + // + const item = content + .substring(openSymbolIndex, closeSymbolIndex + 1) + .trim(); + startsFrom = closeSymbolIndex + 1; + result.push({ + start: openSymbolIndex, + end: closeSymbolIndex, + content: item + }); + } + + // + if (!hasChildArray(result)) { + return result; + } + + // + return result; +} + +/** + * extract a collection of closed contents exists in a content ... + * + * @param symbols a collection of open and close contents ... + * @param {string} content a content for searching inside it ... + * @returns a collection of closed content ... + */ +function findClosedContents( + symbols = [ + { + openSymbol: '', + closeSymbol: '' + } + ], + content = '' +) { + // + let result = [{ + start: -1, + end: -1, + content: '' + }]; + result.pop(); + + // + if ( + !isValidArg(content) || + !hasChildArray(symbols) + ) { + return []; + } + + // + symbols.forEach(symbol => { + // + const closedContent = findClosedContent( + symbol.openSymbol, + symbol.closeSymbol, + content + ); + + // + if (hasChildArray(closedContent)) { + result.push( + ...closedContent + ); + } + }); + + // + return result; +} + +/** + * find all string content closed items ... + * + * @param {string} content a content which going to search ... + * @returns a collection of index descriptors ... + */ +function findClosedStrings(content = '') { + // + // Validate Args ... + if (!isValidArg(content)) { + return []; + } + + // + // there are 3 types of strings ... + // ' " and ` + + // + const token1 = '\''; + const token1Stack = [0]; + token1Stack.pop(); + + // + const token2 = '"'; + const token2Stack = [0]; + token2Stack.pop(); + + // + const token3 = '`'; + const token3Stack = [0]; + token3Stack.pop(); + + // + const result = [ + { + start: -1, + end: -1, + content: '' + } + ]; + result.pop(); + + // + for (let i = 0; i < content.length; i++) { + // + const currentChart = content.charAt(i); + + // + //#region Token 1 ... + if (currentChart === token1) { + // + if (!hasChildArray(token1Stack)) { + token1Stack.push(i); + } else { + // + const start = token1Stack.pop(); + const end = i + 1; + const pContent = content.substring(start, end); + result.push({ + start, + end, + content: pContent + }); + } + } + //#endregion + + // + //#region Token 2 ... + if (currentChart === token2) { + // + if (!hasChildArray(token2Stack)) { + token2Stack.push(i); + } else { + // + const start = token2Stack.pop(); + const end = i + 1; + const pContent = content.substring(start, end); + result.push({ + start, + end, + content: pContent + }); + } + } + //#endregion + + // + //#region Token 3 ... + if (currentChart === token3) { + // + if (!hasChildArray(token3Stack)) { + token3Stack.push(i); + } else { + // + const start = token3Stack.pop(); + const end = i + 1; + const pContent = content.substring(start, end); + result.push({ + start, + end, + content: pContent + }); + } + } + //#endregion + } + + // + return result; +} + +/** + * find container indexes from within indexes ... + * + * @param {...{start: number, end: number}} index the collection of indexes to find beiggers inside ... + * @returns + */ +function findContainerIndexes(...index) { + // + let result = [ + { + start: -1, + end: -1, + content: '' + } + ]; + result.pop(); + + // + let concatedIndexes = []; + for (let idx of index) { + // + // Index Childs ... + for (let iix of idx) { + // + // Check idx is standard ... + if ( + !iix || + !iix.end || + !iix.start || + iix.start > iix.end + ) { + continue; + } + + // + // Check index inside another index ... + concatedIndexes.push(iix); + } + } + + // + if (!hasChildArray(concatedIndexes)) { + return result; + } + + // + for (let ccIdx of concatedIndexes) { + // + const isInside = isIndexInside(ccIdx, ...concatedIndexes); + if (isInside) { + continue; + } + + // + if (hasChildArray(result)) { + // + const isInsideResult = isIndexInside(ccIdx, ...result); + if (isInsideResult) { + continue; + } + } + + // + result.push(ccIdx); + } + + // + return result; +} + +/** + * find all tokens indexes inside a content which they are not inside closed items ... + * + * @param {string|string[]} tokens the tokens which require to search ... + * @param {string} content the content which using to search ... + * @returns + */ +function findAllIndexesOutOfCloseds1( + tokens, + content, +) { + // + // Validate Args ... + if (!isValidArg(content)) { + return []; + } + + // + // Extract token Indexes ... + const tokensIndexes = findAllIndexes(tokens, content); + if (!hasChildArray(tokensIndexes)) { + return []; + } + + // + // Extract Closed Objects Indexes ... + const closedArrays = findClosedContent('[', ']', content); + const closedObjects = findClosedContent('{', '}', content); + const closedStrings = findClosedStrings(content); + if ( + !hasChildArray(closedObjects) && + !hasChildArray(closedArrays) && + !hasChildArray(closedStrings) + ) { + return tokensIndexes; + } + + // + // find bigger sloded ... + let containerClosedItems = findContainerIndexes( + closedArrays, + closedObjects, + closedStrings + ).filter(i => !isSurroundedString(i.content)); + + // + let result = [-1]; + result.pop(); + + // + for (let tIdx of tokensIndexes) { + // + let canAdd = true; + for (let ccIndex of containerClosedItems) { + // + canAdd = isInsideIndex(tIdx, ccIndex); + if (canAdd) { + break; + } + } + + // + if (!canAdd) { + result.push(tIdx); + } + } + + // + return result; +} + +/** + * find all tokens indexes inside a content which they are not inside closed items ... + * + * @param {string|string[]} tokens the tokens which require to search ... + * @param {string} content the content which using to search ... + * @returns + */ +function findAllIndexesOutOfCloseds( + tokens, + content, +) { + // + // Define Result ... + let result = [-1]; + result.pop(); + + // + // Validate Args ... + if (!isValidArg(content)) { + return []; + } + + // + // Normalize Tokens ... + const normalizeTokens = toNormalArray(tokens); + if (!hasChildArray(normalizeTokens)) { + return result; + } + + // + // Extract Closed Objects Indexes ... + let openSymbols = [ + '{', + '[', + '\'', + '"', + '`' + ]; + let closeSymbols = [ + '}', + ']', + '\'', + '"', + '`' + ]; + let openStack = []; + let lastOpenSymbol = ''; + let lastClosedIndex = -1; + for (let i = 0; i < content.length; i++) { + // + const prevChar = content.charAt(i - 1) || ''; + const char = content.charAt(i); + const nextChar = content.charAt(i + 1) || ''; + + // + const isToken = normalizeTokens.includes(char); + const isOpenSymbol = openSymbols.includes(char); + const isCloseSymbol = closeSymbols.includes(char); + + // + if (isOpenSymbol && lastOpenSymbol !== char) { + openStack.push(i); + lastOpenSymbol = char === '\'' || char === '"' || char === '`' ? char : lastOpenSymbol; + } else if (isCloseSymbol) { + // + lastOpenSymbol = char === '\'' || char === '"' || char === '`' ? '' : lastOpenSymbol; + let lastPop = openStack.pop(); + if (openStack.length === 0) { + lastClosedIndex = lastPop; + } + } else if (isToken) { + if ( + i > lastClosedIndex && + openStack.length === 0 + ) { + result.push(i); + } + } + } + + // + return result; +} +//#endregion + +// +//#region Validator Actions ... +/** + * check specified value is Valid URL Address or not ... + * + * @param {string} value specified string which required to check + * @returns {boolean} + */ +function isValidURL(value = "") { + // + if (!isValidArg(value)) { + return false; + } + + const pattern = new RegExp( + '^([a-zA-Z]+:\\/\\/)?' + // protocol + '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name + '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR IP (v4) address + '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path + '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string + '(\\#[-a-z\\d_]*)?$', // fragment locator + 'i' + ); + + // + const result = pattern.test(value); + return result; +} + +/** + * check specified value is Valid URL Address or not ... + * + * @param {string} value specified string which required to check + */ +function isValidEmail(value = "") { + // + if (!isValidArg(value)) { + return false; + } + + // + const pattern = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/gim; + + // + const result = pattern.test(value); + return result; +} +//#endregion + +// +//#region Normallizers ... +/** + * normallize an string ... + * + * @param {string} value specified value ... + * @returns {string} + */ +function toNormalString(value = "") { + // + if (!XTypeTools.isString(value)) { + value = ""; + } + + // + const result = value + .trim() + .toLowerCase(); + + // + return result; +} +//#endregion + +// +//#region Beautifiers ... +/** + * converts an object to string based on json and beautify result ... + * + * @param {any} object + * @returns {string} + */ +function beautifyJSON(object = undefined) { + // + // TODO: Complete this ... + let result = ""; + + // + // validate object ... + if (object === undefined) { + return result; + } + + // + // Convert result ... + result = JSON.stringify( + object, + null, + 4 + ); + + // + return result; +} +//#endregion + +// +//#region Module Exports ... +module.exports = { + // + endsWidth, + surroundBy, + isValidArg, + isValidArgs, + toNormalArray, + hasChildArray, + toStringExpression, + + // + sliceContent, + clearContent, + clearSurround, + clearArraySurround, + clearObjectSurround, + + // + isSurrounded, + isIndexInside, + isInsideIndex, + isKeyValueType, + isSurroundedArray, + isSurroundedString, + isSurroundedObject, + + // + findNearest, + findAllIndexes, + findCloseIndex, + findNearestIndex, + findClosedContent, + findClosedStrings, + findClosedContents, + findAllIndexesOutOfCloseds, + + // + // Validator Actions ... + isValidURL, + isValidEmail, + + // + // Normallizers ... + toNormalString, + + // + beautifyJSON, +} +//#endregion \ No newline at end of file diff --git a/Publishes/.gitkeep b/Publishes/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md new file mode 100644 index 0000000..22078bc --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# MQL4 + +this is a workspace which contains MetaTrader4 Data Folder Contents to Directly develop MQL4 using VSCode and test them. + +## Maintainer + +Hadi Khazaee asl + +[https://www.saherelm.ir](https://www.saherelm.ir) + +[hadi_khazaee_asl@yahoo.com](mailto:hadi_khazaee_asl@yahoo.com) diff --git a/Temp/result.md b/Temp/result.md new file mode 100644 index 0000000..e2430d1 --- /dev/null +++ b/Temp/result.md @@ -0,0 +1,307 @@ +# Report On OSC + +1- + + +2- + + +3- + + +4- + + +5- + + +6- + + +7- + + +8- + + +9- + + +10- + + +11- + + +12- + + +13- + + +14- + + +15- + + +16- + + +17- + + +18- + + +19- + + +20- + + +21- + + +22- + + +23- + + +24- + + +25- + + +26- + + +27- + + +28- + + +29- + + +30- + + +31- + + +32- + + +33- + + +34- + + +35- + + +36- + + +37- + + +38- + + +39- + + +40- + + +41- + + +42- + + +43- + + +44- + + +45- + + +46- + + +47- + + +48- + + +49- + + +50- + + +51- + + +52- + + +53- + + +54- + + +55- + + +56- + + +57- + + +58- + + +59- + + +60- + + +61- + + +62- + + +63- + + +64- + + +65- + + +66- + + +67- + + +68- + + +69- + + +70- + + +71- + + +72- + + +73- + + +74- + + +75- + + +76- + + +77- + + +78- + + +79- + + +80- + + +81- + + +82- + + +83- + + +84- + + +85- + + +86- + + +87- + + +88- + + +89- + + +90- + + +91- + + +92- + + +93- + + +94- + + +95- + + +96- + + +97- + + +98- + + +99- + + +100- + + +101- + + +102- + diff --git a/Templates/x-saherelm.ea..xtpw.btc.tpl b/Templates/x-saherelm.ea..xtpw.btc.tpl new file mode 100644 index 0000000..d890a98 --- /dev/null +++ b/Templates/x-saherelm.ea..xtpw.btc.tpl @@ -0,0 +1,90 @@ + +id=133391534035912727 +comment=x-saherelm.ea testing with candleGapBetweenSignals=7; allowTrade=1; allowLongTrades=1; allowShortTrades=1; alertEvents=1; alertPositions=1; longPositionAlerts=1; shortPositionAlerts=1; terminalAlert=0; pushAlert=0; lotsPerTradePercent=0.00001; maxOpenTrad +symbol=BTCUSD +period=15 +leftpos=846 +digits=2 +scale=32 +graph=1 +fore=0 +grid=0 +volume=0 +scroll=0 +shift=0 +ohlc=1 +one_click=0 +one_click_btn=1 +askline=0 +days=0 +descriptions=0 +shift_size=20 +fixed_pos=0 +window_left=52 +window_top=52 +window_right=1352 +window_bottom=477 +window_type=3 +background_color=0 +foreground_color=16777215 +barup_color=65280 +bardown_color=255 +bullcandle_color=65280 +bearcandle_color=255 +chartline_color=65280 +volumes_color=3329330 +grid_color=10061943 +askline_color=255 +stops_color=255 + + +height=100 +fixed_height=0 + +name=main + + + + +height=50 +fixed_height=0 + +name=Custom Indicator + +name=x-saherelm.xtpow +flags=259 +window_num=-1 + +marketLength=7 + + +shift_0=0 +draw_0=2 +color_0=65280 +style_0=2 +weight_0=1 +shift_1=0 +draw_1=2 +color_1=255 +style_1=2 +weight_1=1 +shift_2=0 +draw_2=0 +color_2=65535 +style_2=2 +weight_2=1 +min=0.00000000 +max=100.00000000 +levels_color=8421504 +levels_style=2 +levels_weight=-1 +level_0=0.00000000 +level_1=20.00000000 +level_2=50.00000000 +level_3=100.00000000 +period_flags=0 +show_data=1 + + + + diff --git a/Templates/x-saherelm.ea.15m.tpl b/Templates/x-saherelm.ea.15m.tpl new file mode 100644 index 0000000..23db707 --- /dev/null +++ b/Templates/x-saherelm.ea.15m.tpl @@ -0,0 +1,208 @@ + +id=133391534035912728 +comment=x-saherelm.ea testing with candleGapBetweenSignals=7; allowTrade=1; allowLongTrades=1; allowShortTrades=1; alertEvents=1; alertPositions=1; longPositionAlerts=1; shortPositionAlerts=1; terminalAlert=0; pushAlert=0; lotsPerTradePercent=0.00001; maxOpenTrad +symbol=BTCUSD +period=15 +leftpos=354 +digits=2 +scale=32 +graph=1 +fore=0 +grid=0 +volume=0 +scroll=0 +shift=0 +ohlc=1 +one_click=0 +one_click_btn=1 +askline=0 +days=0 +descriptions=0 +shift_size=20 +fixed_pos=0 +window_left=26 +window_top=26 +window_right=1356 +window_bottom=460 +window_type=3 +background_color=0 +foreground_color=16777215 +barup_color=65280 +bardown_color=255 +bullcandle_color=65280 +bearcandle_color=255 +chartline_color=65280 +volumes_color=3329330 +grid_color=10061943 +askline_color=255 +stops_color=255 + + +height=100 +fixed_height=0 + +name=main + + +name=Parabolic SAR +step=0.0200 +end=0.2000 +color=65280 +style=0 +weight=1 +period_flags=0 +show_data=1 + + +name=Moving Average +period=288 +shift=0 +method=1 +apply=4 +color=7059389 +style=4 +weight=1 +period_flags=0 +show_data=1 + + +name=Moving Average +period=288 +shift=0 +method=0 +apply=0 +color=3937500 +style=4 +weight=1 +period_flags=0 +show_data=1 + + +name=Moving Average +period=144 +shift=0 +method=0 +apply=0 +color=36095 +style=4 +weight=1 +period_flags=0 +show_data=1 + + +name=Moving Average +period=96 +shift=0 +method=1 +apply=4 +color=13434880 +style=3 +weight=1 +period_flags=0 +show_data=1 + + +name=Moving Average +period=96 +shift=0 +method=0 +apply=0 +color=16711935 +style=3 +weight=1 +period_flags=0 +show_data=1 + + +name=Moving Average +period=48 +shift=0 +method=0 +apply=0 +color=16776960 +style=3 +weight=1 +period_flags=0 +show_data=1 + + +name=Moving Average +period=14 +shift=0 +method=1 +apply=4 +color=8388736 +style=2 +weight=1 +period_flags=0 +show_data=1 + + +name=Moving Average +period=14 +shift=0 +method=0 +apply=0 +color=255 +style=2 +weight=1 +period_flags=0 +show_data=1 + + +name=Moving Average +period=7 +shift=0 +method=0 +apply=0 +color=32768 +style=2 +weight=1 +period_flags=0 +show_data=1 + + + + +height=50 +fixed_height=0 + +name=Custom Indicator + +name=x-saherelm.xtpow +flags=259 +window_num=-1 + +marketLength=7 + + +shift_0=0 +draw_0=2 +color_0=65280 +style_0=2 +weight_0=1 +shift_1=0 +draw_1=2 +color_1=255 +style_1=2 +weight_1=1 +shift_2=0 +draw_2=0 +color_2=65535 +style_2=2 +weight_2=1 +min=0.00000000 +max=100.00000000 +levels_color=8421504 +levels_style=2 +levels_weight=-1 +level_0=0.00000000 +level_1=20.00000000 +level_2=50.00000000 +level_3=100.00000000 +period_flags=0 +show_data=1 + + + + diff --git a/publish.js b/publish.js new file mode 100644 index 0000000..70aff7e --- /dev/null +++ b/publish.js @@ -0,0 +1,253 @@ +/** + * Publish XEa ... + * a node js based application for publishing x-ea Expert ... + * + * Maintainer + * + * Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) + */ + +// +//#region Imports ... +const XFileTools = require("./Node/x-file.tools"); +const XArgsParser = require("./Node/x-arg.parser"); +const XValueTools = require("./Node/x-value.tools"); +const XLoggerTools = require("./Node/x-logger.tools"); +//#endregion + +// +//#region Constants / Variables ... +const MESSAGES = { + // + // Errors ... + InvalidArgs: "invalid arg ...", + ActionFailed: "action failed ...", + DuplicateName: "duplicate name ...", + // + // Messages ... + CheckNameValue: "checking pack name value ...", + CheckPackExists: "checking given pack name exists or not ...", + CreatePackFolder: "creating publish destination folder ...", + StartPacking: "start packing ...", + Succeed: "packing successfully finished ...", +}; +//#endregion + +// +//#region Actions ... +//#endregion + +// +//#region Startup ... +const args = process.argv; +const packName = process.argv[2]; +const packFolderPath = XFileTools.joinPath(__dirname, "Publishes"); + +// +// Startup function ... +async function startup() { + // + // Check pack name contains value ... + XLoggerTools.simpleInfoLog(MESSAGES.CheckNameValue); + if (!XValueTools.isValidArg(packName)) { + // + XLoggerTools.simpleErrorLog(MESSAGES.InvalidArgs); + exit(); + } + + // + // Check Pack Path Exists ... + if (!XFileTools.isDirectoryExists(packFolderPath)) { + // + // Create Pack Folder ... + const isCreated = XFileTools.createDirectory(packFolderPath); + if (!isCreated) { + // + XLoggerTools.simpleErrorLog(MESSAGES.ActionFailed); + exit(); + } + } + + // + // Prepare Pack Dest Folder Path ... + const packPath = XFileTools.joinPath(packFolderPath, packName); + + // + // Check Existance ... + XLoggerTools.simpleInfoLog(MESSAGES.CheckPackExists); + if (XFileTools.isDirectoryExists(packPath)) { + // + XLoggerTools.simpleErrorLog(MESSAGES.DuplicateName); + exit(); + } + + // + // Create Dest Pack Path Folder ... + XLoggerTools.simpleInfoLog(MESSAGES.CreatePackFolder); + let isCreated = XFileTools.createDirectory(packPath); + if (!isCreated) { + // + XLoggerTools.simpleErrorLog(MESSAGES.ActionFailed); + exit(); + } + + // + // Generate a List of Files ... + // + // Ex4 Files ... + let ex4FilesList = await XFileTools.getRecursiveFilesList( + __dirname, + [".ex4"] + ); + + // + // MQ4 Files ... + let mq4FilesList = await XFileTools.getRecursiveFilesList( + __dirname, + [".mq4"] + ); + + // + // Filter BKP files ... + // + // From Ex4 ... + ex4FilesList = ex4FilesList.filter(f => + !f.toLowerCase().includes("bkp") + && f.toLowerCase().includes("x-saherelm.") + ); + + // + // From MQ4 ... + mq4FilesList = mq4FilesList.filter(f => + !f.toLowerCase().includes("bkp") + && f.toLowerCase().includes("x-saherelm.") + ); + + // + // Create required Dest Folders on Pack Dest ... + XLoggerTools.simpleInfoLog(MESSAGES.StartPacking); + + // + const packEx4Folder = XFileTools.joinPath(packPath, "Ex4"); + isCreated = XFileTools.createDirectory(packEx4Folder); + if (!isCreated) { + // + XLoggerTools.simpleErrorLog(MESSAGES.ActionFailed()); + exit(); + } + + // + const packMQ4Folder = XFileTools.joinPath(packPath, "MQ4"); + isCreated = XFileTools.createDirectory(packMQ4Folder); + if (!isCreated) { + // + XLoggerTools.simpleErrorLog(MESSAGES.ActionFailed()); + exit(); + } + + // + const packReportsFolder = XFileTools.joinPath(packPath, "Reports"); + isCreated = XFileTools.createDirectory(packReportsFolder); + if (!isCreated) { + // + XLoggerTools.simpleErrorLog(MESSAGES.ActionFailed()); + exit(); + } + + // + // Transfer Files ... + for(let idx = 0; idx < ex4FilesList.length; idx++) { + // + const ex4 = ex4FilesList[idx]; + const mq4 = mq4FilesList[idx]; + + // + // Clear Current Dir and File Name to found Path ... + const clearEx4FilePath = ex4.replace(__dirname, ""); + const clearMQ4FilePath = mq4.replace(__dirname, ""); + + // + const ex4FileName = XFileTools.basename(clearEx4FilePath); + const mq4FileName = XFileTools.basename(clearMQ4FilePath); + + // + let ex4FilePath = clearEx4FilePath.replace(ex4FileName, ""); + if (ex4FilePath.startsWith(XFileTools.PathSeparator)) { + ex4FilePath = ex4FilePath.substring(1); + } + if (ex4FilePath.endsWith(XFileTools.PathSeparator)) { + ex4FilePath = ex4FilePath.substring(0, ex4FilePath.length - 1); + } + ex4FilePath = XFileTools.joinPath(packEx4Folder, ex4FilePath); + if (!XFileTools.isDirectoryExists(ex4FilePath)) { + // + isCreated = XFileTools.createDirectory(ex4FilePath); + if (!isCreated) { + // + XLoggerTools.simpleErrorLog(MESSAGES.ActionFailed); + exit(); + } + } + let isTransfered = await XFileTools.copyFile(ex4, ex4FilePath); + if (!isTransfered) { + // + XLoggerTools.simpleErrorLog(MESSAGES.ActionFailed); + exit(); + } + + // + let mq4FilePath = clearMQ4FilePath.replace(mq4FileName, ""); + if (mq4FilePath.startsWith(XFileTools.PathSeparator)) { + mq4FilePath = mq4FilePath.substring(1); + } + if (mq4FilePath.endsWith(XFileTools.PathSeparator)) { + mq4FilePath = mq4FilePath.substring(0, mq4FilePath.length - 1); + } + mq4FilePath = XFileTools.joinPath(packMQ4Folder, mq4FilePath); + if (!XFileTools.isDirectoryExists(mq4FilePath)) { + // + isCreated = XFileTools.createDirectory(mq4FilePath); + if (!isCreated) { + // + XLoggerTools.simpleErrorLog(MESSAGES.ActionFailed); + exit(); + } + } + isTransfered = await XFileTools.copyFile(mq4, mq4FilePath); + if (!isTransfered) { + // + XLoggerTools.simpleErrorLog(MESSAGES.ActionFailed); + exit(); + } + } + + // + // Adding Pack Time ... + const packVersionFile = XFileTools.joinPath(packPath, "Version.txt"); + const packVersionContent = `packed at: ${new Date()}`; + isCreated = await XFileTools.writeFile( + packVersionFile, + packVersionContent + ); + if (!isCreated) { + // + XLoggerTools.simpleErrorLog(MESSAGES.ActionFailed); + exit(); + } + + // + // Succeed the Action ... + XLoggerTools.simpleInfoLog(MESSAGES.Succeed); + exit(); +} + +/** + * exit from app ... + */ +function exit() { + process.exit(); +} +// +// Startup Application ... +startup(); +//#endregion \ No newline at end of file