Initial Commit ...
This commit is contained in:
@@ -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 ...
|
||||
//
|
||||
Reference in New Issue
Block a user