Initial Commit ...
This commit is contained in:
@@ -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 ...
|
||||
//
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
//
|
||||
@@ -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 ][_ohigh]) work[i][_open] = work[i ][_ohigh];
|
||||
if (work[i][_open]<work[i-1][_ohigh]) work[i][_open] = work[i-1][_ohigh];
|
||||
}
|
||||
else
|
||||
{
|
||||
pClose = work[i][_open];
|
||||
if (work[i][_high]>work[i-1][_high] && work[i][_af]<limit) work[i][_af] = fmin(work[i][_af]+step,limit);
|
||||
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
|
||||
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]<work[i-1][_low] && work[i][_af]<limit) work[i][_af] = fmin(work[i][_af]+step,limit);
|
||||
work[i][_open] = pClose + work[i][_af]*(work[i][_low]-pClose);
|
||||
if (work[i][_open]<work[i ][_ohigh]) work[i][_open] = work[i ][_ohigh];
|
||||
if (work[i][_open]<work[i-1][_ohigh]) work[i][_open] = work[i-1][_ohigh];
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
pOpen = work[i][_open];
|
||||
pPosition = work[i][_position];
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
//
|
||||
//-------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
void manageAlerts()
|
||||
{
|
||||
if (alertsOn)
|
||||
{
|
||||
int whichBar = 1; if (alertsOnCurrent) whichBar = 0;
|
||||
if (saraUp[whichBar] != EMPTY_VALUE || saraDn[whichBar] != EMPTY_VALUE)
|
||||
{
|
||||
if (saraUp[whichBar] != EMPTY_VALUE) doAlert(whichBar,"up");
|
||||
if (saraDn[whichBar] != EMPTY_VALUE) doAlert(whichBar,"down");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
void doAlert(int forBar, string doWhat)
|
||||
{
|
||||
static string previousAlert="nothing";
|
||||
static datetime previousTime;
|
||||
string message;
|
||||
|
||||
if (previousAlert != doWhat || previousTime != Time[forBar]) {
|
||||
previousAlert = doWhat;
|
||||
previousTime = Time[forBar];
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
message = StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," ",timeFrameToString(_Period)+" Parabolic sar trend changed to ",doWhat);
|
||||
if (alertsMessage) Alert(message);
|
||||
if (alertsEmail) SendMail(StringConcatenate(Symbol(),"parabolic sar"),message);
|
||||
if (alertsNotify) SendNotification(message);
|
||||
if (alertsSound) PlaySound("alert2.wav");
|
||||
}
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------
|
||||
//|
|
||||
//+-------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
|
||||
int iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};
|
||||
|
||||
string timeFrameToString(int tf)
|
||||
{
|
||||
for (int i=ArraySize(iTfTable)-1; i>=0; i--)
|
||||
if (tf==iTfTable[i]) return(sTfTable[i]);
|
||||
return("");
|
||||
}
|
||||
@@ -0,0 +1,359 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| PanelDialog.mqh |
|
||||
//| Copyright 2009-2015, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#include <Controls\Dialog.mqh>
|
||||
#include <Controls\Button.mqh>
|
||||
#include <Controls\Edit.mqh>
|
||||
#include <Controls\ListView.mqh>
|
||||
#include <Controls\ComboBox.mqh>
|
||||
#include <Controls\SpinEdit.mqh>
|
||||
#include <Controls\RadioGroup.mqh>
|
||||
#include <Controls\CheckGroup.mqh>
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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<<i))
|
||||
return(false);
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Create the "CheckGroup" element |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::CreateCheckGroup(void)
|
||||
{
|
||||
int sx=(ClientAreaWidth()-(INDENT_LEFT+INDENT_RIGHT+BUTTON_WIDTH))/3-CONTROLS_GAP_X;
|
||||
//--- coordinates
|
||||
int x1=INDENT_LEFT+sx+CONTROLS_GAP_X;
|
||||
int y1=INDENT_TOP+EDIT_HEIGHT+CONTROLS_GAP_Y;
|
||||
int x2=x1+sx;
|
||||
int y2=ClientAreaHeight()-INDENT_BOTTOM;
|
||||
//--- create
|
||||
if(!m_check_group.Create(m_chart_id,m_name+"CheckGroup",m_subwin,x1,y1,x2,y2))
|
||||
return(false);
|
||||
if(!Add(m_check_group))
|
||||
return(false);
|
||||
m_check_group.Alignment(WND_ALIGN_HEIGHT,0,y1,0,INDENT_BOTTOM);
|
||||
//--- fill out with strings
|
||||
for(int i=0;i<4;i++)
|
||||
if(!m_check_group.AddItem("Item "+IntegerToString(i),1<<i))
|
||||
return(false);
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Create the "ListView" element |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::CreateListView(void)
|
||||
{
|
||||
int sx=(ClientAreaWidth()-(INDENT_LEFT+INDENT_RIGHT+BUTTON_WIDTH))/3-CONTROLS_GAP_X;
|
||||
//--- coordinates
|
||||
int x1=ClientAreaWidth()-(sx+INDENT_RIGHT+BUTTON_WIDTH+CONTROLS_GAP_X);
|
||||
int y1=INDENT_TOP+EDIT_HEIGHT+CONTROLS_GAP_Y;
|
||||
int x2=x1+sx;
|
||||
int y2=ClientAreaHeight()-INDENT_BOTTOM;
|
||||
//--- create
|
||||
if(!m_list_view.Create(m_chart_id,m_name+"ListView",m_subwin,x1,y1,x2,y2))
|
||||
return(false);
|
||||
if(!Add(m_list_view))
|
||||
return(false);
|
||||
m_list_view.Alignment(WND_ALIGN_HEIGHT,0,y1,0,INDENT_BOTTOM);
|
||||
//--- fill out with strings
|
||||
for(int i=0;i<16;i++)
|
||||
if(!m_list_view.ItemAdd("Item "+IntegerToString(i)))
|
||||
return(false);
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Handler of resizing |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::OnResize(void)
|
||||
{
|
||||
//--- call method of parent class
|
||||
if(!CAppDialog::OnResize()) return(false);
|
||||
//--- coordinates
|
||||
int x=ClientAreaLeft()+INDENT_LEFT;
|
||||
int y=m_radio_group.Top();
|
||||
int sx=(ClientAreaWidth()-(INDENT_LEFT+INDENT_RIGHT+BUTTON_WIDTH))/3-CONTROLS_GAP_X;
|
||||
//--- move and resize the "RadioGroup" element
|
||||
m_radio_group.Move(x,y);
|
||||
m_radio_group.Width(sx);
|
||||
//--- move and resize the "CheckGroup" element
|
||||
x=ClientAreaLeft()+INDENT_LEFT+sx+CONTROLS_GAP_X;
|
||||
m_check_group.Move(x,y);
|
||||
m_check_group.Width(sx);
|
||||
//--- move and resize the "ListView" element
|
||||
x=ClientAreaLeft()+ClientAreaWidth()-(sx+INDENT_RIGHT+BUTTON_WIDTH+CONTROLS_GAP_X);
|
||||
m_list_view.Move(x,y);
|
||||
m_list_view.Width(sx);
|
||||
//--- succeed
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Event handler |
|
||||
//+------------------------------------------------------------------+
|
||||
void CPanelDialog::OnClickButton1(void)
|
||||
{
|
||||
m_edit.Text(__FUNCTION__);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Event handler |
|
||||
//+------------------------------------------------------------------+
|
||||
void CPanelDialog::OnClickButton2(void)
|
||||
{
|
||||
m_edit.Text(__FUNCTION__);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Event handler |
|
||||
//+------------------------------------------------------------------+
|
||||
void CPanelDialog::OnClickButton3(void)
|
||||
{
|
||||
if(m_button3.Pressed())
|
||||
m_edit.Text(__FUNCTION__+"On");
|
||||
else
|
||||
m_edit.Text(__FUNCTION__+"Off");
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Event handler |
|
||||
//+------------------------------------------------------------------+
|
||||
void CPanelDialog::OnChangeListView(void)
|
||||
{
|
||||
m_edit.Text(__FUNCTION__+" \""+m_list_view.Select()+"\"");
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Event handler |
|
||||
//+------------------------------------------------------------------+
|
||||
void CPanelDialog::OnChangeRadioGroup(void)
|
||||
{
|
||||
m_edit.Text(__FUNCTION__+" : Value="+IntegerToString(m_radio_group.Value()));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Event handler |
|
||||
//+------------------------------------------------------------------+
|
||||
void CPanelDialog::OnChangeCheckGroup(void)
|
||||
{
|
||||
m_edit.Text(__FUNCTION__+" : Value="+IntegerToString(m_check_group.Value()));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Rest events handler |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CPanelDialog::OnDefault(const int id,const long &lparam,const double &dparam,const string &sparam)
|
||||
{
|
||||
//--- restore buttons' states after mouse move'n'click
|
||||
if(id==CHARTEVENT_CLICK)
|
||||
m_radio_group.RedrawButtonStates();
|
||||
//--- let's handle event by parent
|
||||
return(false);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,65 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| SimplePanel.mq4 |
|
||||
//| Copyright 2009-2014, MetaQuotes Software Corp. |
|
||||
//| http://www.mql4.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2009-2014, MetaQuotes Software Corp."
|
||||
#property link "http://www.mql4.com"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 0
|
||||
#property indicator_minimum 0.0
|
||||
#property indicator_maximum 0.0
|
||||
#include "PanelDialog.mqh"
|
||||
//+------------------------------------------------------------------+
|
||||
//| Global Variables |
|
||||
//+------------------------------------------------------------------+
|
||||
CPanelDialog ExtDialog;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit(void)
|
||||
{
|
||||
//--- create application dialog
|
||||
if(!ExtDialog.Create(0,"Simple Panel",0,50,50,390,200))
|
||||
return(INIT_FAILED);
|
||||
//--- run application
|
||||
if(!ExtDialog.Run())
|
||||
return(INIT_FAILED);
|
||||
//--- ok
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator deinitialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//--- destroy application dialog
|
||||
ExtDialog.Destroy(reason);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const int begin,
|
||||
const double &price[])
|
||||
{
|
||||
//---
|
||||
// do nothing
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| ChartEvent function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnChartEvent(const int id,
|
||||
const long &lparam,
|
||||
const double &dparam,
|
||||
const string &sparam)
|
||||
{
|
||||
ExtDialog.ChartEvent(id,lparam,dparam,sparam);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -0,0 +1,147 @@
|
||||
/////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center OSC EA Panel ...
|
||||
// -------------------------------------------------------------
|
||||
// this is an Oscillator for Panel Providing on OSC EA ...
|
||||
//
|
||||
// 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 ...
|
||||
//
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
// Includes our shared library ...
|
||||
#include "../Libraries/x-saherelm.lib.mq4"
|
||||
|
||||
//
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 0
|
||||
#property indicator_minimum 0.0
|
||||
#property indicator_maximum 0.0
|
||||
#include "../Include/PanelDialog.mqh"
|
||||
|
||||
//
|
||||
// Define a Dialog Instance ...
|
||||
// CPanelDialog dialog;
|
||||
|
||||
//
|
||||
// here we specify logging enabled or not ...
|
||||
bool enableLogging = true;
|
||||
|
||||
//
|
||||
// this is a Tag which attached to our Logger ...
|
||||
string logTag = "XS_OSC_PANEL";
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
|
||||
//
|
||||
// Validating Input Parameters ...
|
||||
// if (
|
||||
// ) {
|
||||
// return INIT_PARAMETERS_INCORRECT;
|
||||
// }
|
||||
|
||||
//
|
||||
// Set Buffers ...
|
||||
|
||||
//
|
||||
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 = 0; // 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 ...
|
||||
|
||||
//
|
||||
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 ...
|
||||
//
|
||||
@@ -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 ...
|
||||
//
|
||||
@@ -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 ...
|
||||
//
|
||||
@@ -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 ...
|
||||
//
|
||||
@@ -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 ...
|
||||
//
|
||||
@@ -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 ...
|
||||
//
|
||||
@@ -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 ...
|
||||
//
|
||||
@@ -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 ...
|
||||
//
|
||||
@@ -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 ...
|
||||
//
|
||||
@@ -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 ...
|
||||
//
|
||||
@@ -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 ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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 ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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 ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user