Initial Commit ...
This commit is contained in:
@@ -0,0 +1,532 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| x-saherelm.ea |
|
||||
//| Copyright 2023, SaherElm IT Center |
|
||||
//| https://www.saherelm.ir |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
input double riskToReward = 1.5; // Risk To Reward Ratio
|
||||
|
||||
//
|
||||
// Define Models ...
|
||||
//
|
||||
// Signal Providers ...
|
||||
enum ENUM_XSIGNAL_PROVIDER {
|
||||
X_UNKNOWN_PROVIDER = 0,
|
||||
X_CCI_PROVIDER = 1
|
||||
};
|
||||
|
||||
//
|
||||
// Signal Type ...
|
||||
enum ENUM_XSIGNAL_TYPE {
|
||||
X_NONE = 0,
|
||||
X_BUY = 1,
|
||||
X_SELL = 2
|
||||
};
|
||||
|
||||
//
|
||||
// Signal ...
|
||||
struct XSignal {
|
||||
//
|
||||
// Signal Type ...
|
||||
ENUM_XSIGNAL_TYPE type;
|
||||
|
||||
//
|
||||
// Signal ID ...
|
||||
int id;
|
||||
|
||||
//
|
||||
// Signal Ticket Number, when Opening Trade ...
|
||||
int ticket;
|
||||
|
||||
//
|
||||
// Signal Provider ...
|
||||
ENUM_XSIGNAL_PROVIDER provider;
|
||||
|
||||
//
|
||||
// Target Point ...
|
||||
double tp;
|
||||
|
||||
//
|
||||
// Stop Loss ...
|
||||
double sl;
|
||||
|
||||
//
|
||||
// Signal Entry Price ...
|
||||
double price;
|
||||
|
||||
//
|
||||
// Signalling Time ...
|
||||
datetime time;
|
||||
};
|
||||
|
||||
//
|
||||
// CCI Based Signal Conditions ...
|
||||
struct XCCILongSignalConditions {
|
||||
//
|
||||
datetime start;
|
||||
|
||||
//
|
||||
datetime crossOverMinusHundredTime;
|
||||
datetime crossUnderMinusHundredTime;
|
||||
|
||||
//
|
||||
double crossOverSlope;
|
||||
};
|
||||
|
||||
//
|
||||
bool isNewBar = false;
|
||||
|
||||
//
|
||||
int countedBars = 0;
|
||||
int totalSignals = 0;
|
||||
int lastSignalledBar = 0;
|
||||
|
||||
//
|
||||
XCCILongSignalConditions cciLongConds = {};
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert tick function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
isNewBar = IsNewBar();
|
||||
|
||||
//
|
||||
if (isNewBar) {
|
||||
//
|
||||
countedBars++;
|
||||
}
|
||||
|
||||
//
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
0
|
||||
);
|
||||
|
||||
//
|
||||
bool hasSignal = false;
|
||||
bool hasLongSignal = false;
|
||||
bool hasShortSignal = false;
|
||||
|
||||
//
|
||||
// Generate Signals Based On iCCI ...
|
||||
CheckCCILongSignalConditions(0);
|
||||
|
||||
//
|
||||
// Long Signal ...
|
||||
hasLongSignal =
|
||||
//
|
||||
// Check CCI Long Signal is Valid ...
|
||||
ValidateCCILongConditions();
|
||||
|
||||
//
|
||||
// Signal ...
|
||||
hasSignal = hasLongSignal || hasShortSignal;
|
||||
|
||||
//
|
||||
// Prevent Going Forward when there is no Signal ...
|
||||
if (!hasSignal) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
if (lastSignalledBar == countedBars) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
totalSignals++;
|
||||
lastSignalledBar = countedBars;
|
||||
|
||||
//
|
||||
// Get CCI Long Signal ...
|
||||
XSignal signal = {};
|
||||
|
||||
//
|
||||
if (hasLongSignal) {
|
||||
signal = GenerateCCILongSignal();
|
||||
}
|
||||
|
||||
//
|
||||
TradeOnSignal(signal);
|
||||
|
||||
//
|
||||
Print("CCI Long Signal ...");
|
||||
|
||||
//
|
||||
ClearCCILongSignalConditions();
|
||||
}
|
||||
|
||||
//
|
||||
// Trade Based On Signal ...
|
||||
void TradeOnSignal(
|
||||
XSignal &signal
|
||||
) {
|
||||
//
|
||||
if (signal.type == X_NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
bool isLongSignal = signal.type == X_BUY;
|
||||
|
||||
//
|
||||
// Order Operation ...
|
||||
int operation = isLongSignal ?
|
||||
OP_BUY :
|
||||
OP_SELL;
|
||||
|
||||
//
|
||||
// Detect Trade Color ...
|
||||
color clr = isLongSignal ?
|
||||
clrAqua :
|
||||
clrFuchsia;
|
||||
|
||||
//
|
||||
// Generate Signal Comment ...
|
||||
string label = isLongSignal ?
|
||||
"BUY" :
|
||||
"SELL";
|
||||
|
||||
//
|
||||
// Generate Signal Comment ...
|
||||
string comment = StringConcatenate(
|
||||
"XCCI",
|
||||
"_", signal.id,
|
||||
"_", label
|
||||
);
|
||||
|
||||
//
|
||||
// Placing Order ...
|
||||
int orderTicket = OrderSend(
|
||||
_Symbol,
|
||||
operation,
|
||||
0.01,
|
||||
signal.price,
|
||||
3,
|
||||
signal.sl,
|
||||
signal.tp,
|
||||
comment,
|
||||
signal.id,
|
||||
0,
|
||||
clr
|
||||
);
|
||||
|
||||
//
|
||||
// Draw Signal Shape if Order Opened Successfully ...
|
||||
if (orderTicket >= 0) {
|
||||
//
|
||||
signal.ticket = orderTicket;
|
||||
Print("Order: ", orderTicket, " ...");
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Convert CCI Long Signal Conditions to XSignal ...
|
||||
XSignal GenerateCCILongSignal() {
|
||||
//
|
||||
XSignal result = {};
|
||||
|
||||
//
|
||||
// Price Calculations ...
|
||||
//
|
||||
RefreshRates();
|
||||
|
||||
//
|
||||
double entryPrice = SymbolInfoDouble(
|
||||
_Symbol,
|
||||
SYMBOL_ASK
|
||||
);
|
||||
|
||||
//
|
||||
double exitPrice = SymbolInfoDouble(
|
||||
_Symbol,
|
||||
SYMBOL_BID
|
||||
);
|
||||
|
||||
//
|
||||
double priceGap = MathAbs(entryPrice - exitPrice);
|
||||
|
||||
//
|
||||
double ll = GetLowestLow();
|
||||
double hh = GetHighestHigh();
|
||||
double pSar = iSAR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
0.002,
|
||||
0.02,
|
||||
0
|
||||
);
|
||||
|
||||
//
|
||||
double sl = ll;
|
||||
|
||||
//
|
||||
double risk = entryPrice - ll;
|
||||
double reward = risk * riskToReward;
|
||||
|
||||
//
|
||||
double tp = entryPrice + reward;
|
||||
|
||||
//
|
||||
if (tp > hh) {
|
||||
tp = hh;
|
||||
}
|
||||
|
||||
//
|
||||
if (tp < entryPrice + priceGap) {
|
||||
tp = entryPrice + priceGap;
|
||||
}
|
||||
|
||||
//
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
0
|
||||
);
|
||||
|
||||
//
|
||||
result.tp = tp;
|
||||
result.sl = 0; // sl;
|
||||
result.type = X_BUY;
|
||||
result.id = totalSignals;
|
||||
result.price = entryPrice;
|
||||
result.provider = X_CCI_PROVIDER;
|
||||
result.time = barTime;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate CCI Signal Conditions ...
|
||||
bool ValidateCCILongConditions() {
|
||||
//
|
||||
bool result =
|
||||
cciLongConds.start != 0
|
||||
&& cciLongConds.crossUnderMinusHundredTime != 0
|
||||
&& cciLongConds.crossOverMinusHundredTime != 0
|
||||
&& cciLongConds.crossUnderMinusHundredTime >= cciLongConds.start
|
||||
&& cciLongConds.crossOverMinusHundredTime > cciLongConds.crossUnderMinusHundredTime
|
||||
&& cciLongConds.crossOverSlope > 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Clear CCI Long Signal Conditions for New One ...
|
||||
void ClearCCILongSignalConditions() {
|
||||
//
|
||||
cciLongConds.start = 0;
|
||||
cciLongConds.crossOverSlope = 0;
|
||||
cciLongConds.crossOverMinusHundredTime = 0;
|
||||
cciLongConds.crossUnderMinusHundredTime = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Check and Fill CC Signal Conditions ...
|
||||
void CheckCCILongSignalConditions(
|
||||
const int bar_index
|
||||
) {
|
||||
//
|
||||
// Retrieve Bar Time ...
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
// LONG:
|
||||
// wait for cci cross under -100
|
||||
// then wait for cross over -100
|
||||
// slope of crossing over ??? ...
|
||||
if (cciLongConds.start == 0) {
|
||||
cciLongConds.start = barTime;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Start Time ...
|
||||
if (cciLongConds.start == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Read current, prev, and prevPrev CCI ...
|
||||
double cci = GetCCI(bar_index);
|
||||
double cci1 = GetCCI(bar_index + 1);
|
||||
double cci2 = GetCCI(bar_index + 2);
|
||||
|
||||
//
|
||||
// Find Cross Under -100 ...
|
||||
bool isCrossUnderMinusHundred =
|
||||
cci < -100 && !(cci1 < -100);
|
||||
|
||||
//
|
||||
// Fill Conditions ...
|
||||
if (
|
||||
isCrossUnderMinusHundred
|
||||
&& cciLongConds.crossUnderMinusHundredTime == 0
|
||||
) {
|
||||
//
|
||||
cciLongConds.crossUnderMinusHundredTime = barTime;
|
||||
}
|
||||
|
||||
//
|
||||
// Prevent Going forward untill Cross Under Happens ...
|
||||
if (cciLongConds.crossUnderMinusHundredTime == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Find Cross Over -100 ...
|
||||
bool isCrossOverMinusHundred =
|
||||
cci > -100 && !(cci1 > -100);
|
||||
|
||||
//
|
||||
// Fill Conditions ...
|
||||
if (
|
||||
isCrossOverMinusHundred
|
||||
&& cciLongConds.crossOverMinusHundredTime == 0
|
||||
) {
|
||||
//
|
||||
cciLongConds.crossOverMinusHundredTime = barTime;
|
||||
}
|
||||
|
||||
//
|
||||
// Prevent from Going forward untill Cross Over Happens ...
|
||||
if (cciLongConds.crossOverMinusHundredTime == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Slope ...
|
||||
double x1 = 0;
|
||||
double y1 = cci1;
|
||||
double x2 = 1;
|
||||
double y2 = cci;
|
||||
|
||||
//
|
||||
// Calculat Line Slope ...
|
||||
double tSlope = GetSlope(
|
||||
x1, y1, x2, y2
|
||||
);
|
||||
|
||||
//
|
||||
cciLongConds.crossOverSlope = tSlope;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Retrieve CCI Value ...
|
||||
double GetCCI(
|
||||
const int bar_index,
|
||||
const int marketLength = 504,
|
||||
const ENUM_APPLIED_PRICE source = PRICE_TYPICAL
|
||||
) {
|
||||
//
|
||||
double result = iCCI(
|
||||
_Symbol,
|
||||
_Period,
|
||||
marketLength,
|
||||
source,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Determines current working is New Bar or not ...
|
||||
bool IsNewBar() {
|
||||
//
|
||||
static datetime lastbar;
|
||||
datetime curbar = (datetime)SeriesInfoInteger(_Symbol, _Period, SERIES_LASTBAR_DATE);
|
||||
|
||||
//
|
||||
if(lastbar != curbar) {
|
||||
//
|
||||
lastbar = curbar;
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Get Slope of a Line by it's two Point ...
|
||||
double GetSlope(
|
||||
double x1,
|
||||
double y1,
|
||||
double x2,
|
||||
double y2
|
||||
) {
|
||||
//
|
||||
double result = (y2 - y1)/(x2 - x1);
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Market Related Functions ...
|
||||
//
|
||||
double GetLowestLow() {
|
||||
//
|
||||
int index = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_LOW,
|
||||
14,
|
||||
0
|
||||
);
|
||||
|
||||
//
|
||||
double result = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double GetHighestHigh() {
|
||||
//
|
||||
int index = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_HIGH,
|
||||
14,
|
||||
0
|
||||
);
|
||||
|
||||
//
|
||||
double result = iHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,100 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL4 Models Global Library
|
||||
// ---------------------------------------------
|
||||
// saherelm useful tools and definitions ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Start Models ...
|
||||
//
|
||||
//
|
||||
// Used Indicators List ...
|
||||
const string xmaIndicatorName = "x-saherelm.xma";
|
||||
const string adxIndicatorName = "x-saherelm.adx";
|
||||
const string oscIndicatorName = "x-saherelm.osc";
|
||||
const string shpdIndicatorName = "x-saherelm.shpd";
|
||||
const string zigZagIndicatorName = "x-saherelm.zigzag";
|
||||
const string xmarketIndicatorName = "x-saherelm.xmarket";
|
||||
const string momentumIndicatorName = "x-saherelm.momentum";
|
||||
|
||||
//
|
||||
// Direction ...
|
||||
enum X_DIRECTION {
|
||||
X_UP,
|
||||
X_DOWN
|
||||
};
|
||||
|
||||
//
|
||||
// these are different signal types ...
|
||||
enum X_SIGNAL_TYPE {
|
||||
X_NONE,
|
||||
X_LONG,
|
||||
X_SHORT,
|
||||
};
|
||||
|
||||
//
|
||||
// we Model each signals as this type ...
|
||||
struct XSignal {
|
||||
int id;
|
||||
int ticket;
|
||||
X_SIGNAL_TYPE type;
|
||||
double tp;
|
||||
double sl;
|
||||
string symbol;
|
||||
datetime time;
|
||||
string comment;
|
||||
double entryPrice;
|
||||
};
|
||||
|
||||
//
|
||||
// this is Signal Request Response model ...
|
||||
struct XSignalRequest {
|
||||
bool hasSignal;
|
||||
X_SIGNAL_TYPE type;
|
||||
XSignal signal;
|
||||
};
|
||||
|
||||
//
|
||||
struct XMACycleState {
|
||||
double fast;
|
||||
double slow;
|
||||
};
|
||||
|
||||
//
|
||||
// Define a Model to Represent Snapshot of XMA Indicator ...
|
||||
struct XMAState {
|
||||
//
|
||||
// SC ...
|
||||
XMACycleState sc;
|
||||
|
||||
//
|
||||
// MC ...
|
||||
XMACycleState mc;
|
||||
|
||||
//
|
||||
// LC ...
|
||||
XMACycleState lc;
|
||||
|
||||
//
|
||||
// MIDDLEAGE ...
|
||||
double marketMiddleage;
|
||||
|
||||
//
|
||||
// PARABOLIC-SAR ...
|
||||
double parabolicSAR;
|
||||
};
|
||||
//
|
||||
// End Models ...
|
||||
//
|
||||
@@ -0,0 +1,330 @@
|
||||
/////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center OSC Indicator
|
||||
// -------------------------------------------------------------
|
||||
// this indicator provides OSC ...
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm OSC Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
// FastOSC ...
|
||||
// Short Cycle (Fast OSC) ...
|
||||
input int fastOSCLength = 10; // FastOSC Length
|
||||
input double fastOSCMultiplier = 1.0; // FastOSC Multiplier
|
||||
|
||||
//
|
||||
// SlowOSC ...
|
||||
// Medium Cycle (Slow OSC) ...
|
||||
input int slowOSCLength = 30; // SlowOSC Length
|
||||
input double slowOSCMultiplier = 3.0; // SlowOSC Multiplier
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
// Includes our shared library ...
|
||||
#include "../Libraries/x-saherelm.lib.mq4"
|
||||
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
// we have 2 buffer in this indicator ...
|
||||
#property indicator_buffers 5
|
||||
|
||||
//
|
||||
// also we have 2 line for draw on this indicator ...
|
||||
#property indicator_plots 5
|
||||
|
||||
//
|
||||
// Fast OSC ...
|
||||
#property indicator_width1 1
|
||||
#property indicator_color1 clrAqua
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
|
||||
//
|
||||
// Slow OSC ...
|
||||
#property indicator_width2 1
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrFuchsia
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
|
||||
//
|
||||
// Power OSC ...
|
||||
#property indicator_width3 1
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrYellow
|
||||
#property indicator_style3 STYLE_DASHDOTDOT
|
||||
|
||||
//
|
||||
// Var OSC ...
|
||||
#property indicator_width4 1
|
||||
#property indicator_type4 DRAW_HISTOGRAM
|
||||
#property indicator_color4 clrBlueViolet
|
||||
#property indicator_style4 STYLE_SOLID
|
||||
|
||||
//
|
||||
// Tan Fast/Slow OSC ...
|
||||
#property indicator_width5 0
|
||||
#property indicator_type5 DRAW_NONE
|
||||
#property indicator_color5 clrNONE
|
||||
#property indicator_style5 STYLE_SOLID
|
||||
|
||||
//
|
||||
//#property indicator_minimum 0
|
||||
//#property indicator_maximum 1
|
||||
|
||||
//
|
||||
// set color of horizontal levels ...
|
||||
#property indicator_levelcolor clrGray
|
||||
|
||||
//
|
||||
// set style of horizontal levels ...
|
||||
#property indicator_levelstyle STYLE_DOT
|
||||
|
||||
//
|
||||
// Declare Buffers ...
|
||||
#define fastOSCBufferIndex 0
|
||||
#define slowOSCBufferIndex 1
|
||||
#define powerOSCBufferIndex 2
|
||||
#define varOSCBufferIndex 3
|
||||
#define fastSlowOSCAngleBufferIndex 4
|
||||
|
||||
//
|
||||
double fastOSCBuffer[];
|
||||
double slowOSCBuffer[];
|
||||
double fastSlowOSCAngleBuffer[];
|
||||
double powerOSCBuffer[];
|
||||
double varOSCBuffer[];
|
||||
|
||||
//
|
||||
// Used Indicators List ...
|
||||
string rmaIndicatorName = "x-saherelm.rma";
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
|
||||
//
|
||||
// Validating Input Parameters ...
|
||||
if (
|
||||
fastOSCLength < 0 ||
|
||||
slowOSCLength < 0 ||
|
||||
slowOSCLength <= fastOSCLength
|
||||
) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// here we specify logging enabled or not ...
|
||||
enableLogging = true;
|
||||
|
||||
//
|
||||
// this is a Tag which attached to our Logger ...
|
||||
logTag = "XS_OSC";
|
||||
|
||||
//
|
||||
// set descriptions of horizontal levels ...
|
||||
SetLevelValue(0, 0.0);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT,0,"");
|
||||
|
||||
//
|
||||
// set descriptions of horizontal levels ...
|
||||
SetLevelValue(1, 0.5);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT,1,"");
|
||||
|
||||
//
|
||||
// set descriptions of horizontal levels ...
|
||||
SetLevelValue(2, 1);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT,2,"");
|
||||
|
||||
//
|
||||
// Fast OSC Buffer ...
|
||||
SetIndexBuffer(fastOSCBufferIndex, fastOSCBuffer);
|
||||
SetIndexLabel(fastOSCBufferIndex, "Fast OSC");
|
||||
SetIndexDrawBegin(fastOSCBufferIndex, fastOSCLength - 1);
|
||||
|
||||
//
|
||||
// Slow OSC Buffer ...
|
||||
SetIndexBuffer(slowOSCBufferIndex, slowOSCBuffer);
|
||||
SetIndexLabel(slowOSCBufferIndex, "Slow OSC");
|
||||
SetIndexDrawBegin(slowOSCBufferIndex, slowOSCLength - 1);
|
||||
|
||||
//
|
||||
// Power OSC Buffer ...
|
||||
SetIndexBuffer(powerOSCBufferIndex, powerOSCBuffer);
|
||||
SetIndexLabel(powerOSCBufferIndex, "Power OSC");
|
||||
|
||||
//
|
||||
// Var OSC Buffer ...
|
||||
SetIndexBuffer(varOSCBufferIndex, varOSCBuffer);
|
||||
SetIndexLabel(varOSCBufferIndex, "Var OSC");
|
||||
|
||||
//
|
||||
// Tan Fast/Slow OSC Buffer ...
|
||||
SetIndexBuffer(fastSlowOSCAngleBufferIndex, fastSlowOSCAngleBuffer);
|
||||
SetIndexLabel(fastSlowOSCAngleBufferIndex, "F/L OSC Angle");
|
||||
|
||||
//
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//
|
||||
// Do Calculation ...
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[]
|
||||
) {
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(fastOSCLength, slowOSCLength);
|
||||
|
||||
//
|
||||
// input variable, we return 0 means nothing passed ...
|
||||
if (rates_total < maxLength) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// found which candles calculated before ...
|
||||
limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1;
|
||||
|
||||
//
|
||||
// this is the main loop of calculations, for each bar index ...
|
||||
for (int i = limit - 1; i >= 0; i--) {
|
||||
//
|
||||
// Start Calculation here ...
|
||||
// i is bar_index ...
|
||||
|
||||
//
|
||||
CalculateOscillators(close, i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// De Initialization ...
|
||||
void OnDeinit(const int reason) {
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
void CalculateOscillators(
|
||||
const double &close[],
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
// FastOSC ...
|
||||
// Short Cycle Calculations ...
|
||||
int scl = fastOSCLength / 2;
|
||||
int scl2 = scl / 2;
|
||||
double maScl = iCustom(_Symbol, _Period, rmaIndicatorName, scl, 0, bar_index);
|
||||
double scmAtr = iATR(_Symbol, _Period, scl, bar_index);
|
||||
double scmOff = fastOSCMultiplier * scmAtr;
|
||||
double maScl2 = iCustom(_Symbol, _Period, rmaIndicatorName, scl2, 0, bar_index);
|
||||
double sctParam = maScl2 != 0 ? maScl2 : close[bar_index + 1];
|
||||
double sct = sctParam + scmOff;
|
||||
double scb = sctParam - scmOff;
|
||||
|
||||
//
|
||||
// SlowOSC ...
|
||||
// Medium Cycle Calculations ...
|
||||
int mcl = slowOSCLength / 2;
|
||||
int mcl2 = mcl / 2;
|
||||
double maMcl = iCustom(_Symbol, _Period, rmaIndicatorName, mcl, 0, bar_index);
|
||||
double mcmAtr = iATR(_Symbol, _Period, mcl, bar_index);
|
||||
double mcmOff = slowOSCMultiplier * mcmAtr;
|
||||
double maMcl2 = iCustom(_Symbol, _Period, rmaIndicatorName, mcl2, 0, bar_index);
|
||||
double mctParam = maMcl2 != 0 ? maMcl2 : close[bar_index + 1];
|
||||
double mct = mctParam + mcmOff;
|
||||
double mcb = mctParam - mcmOff;
|
||||
|
||||
//
|
||||
double scMM = (sct + scb) / 2;
|
||||
|
||||
//
|
||||
double fastOCS = (close[bar_index] - mcb) / (mct - mcb);
|
||||
fastOSCBuffer[bar_index] = fastOCS;
|
||||
|
||||
//
|
||||
double slowOCS = (scMM - mcb) / (mct - mcb);
|
||||
slowOSCBuffer[bar_index] = slowOCS;
|
||||
|
||||
//
|
||||
// Signal Power ...
|
||||
// Difference Variant between FastOSC and Slow OSC ...
|
||||
double powerOSC = fastOCS - slowOCS;
|
||||
powerOSCBuffer[bar_index] = powerOSC;
|
||||
|
||||
//
|
||||
// Var OSC ...
|
||||
double varOSC = fastOCS - 0.5;
|
||||
varOSCBuffer[bar_index] = varOSC;
|
||||
|
||||
//
|
||||
// Calculate Tan Fast/Slow OSC ...
|
||||
double fastOSCSlope = fastOSCBuffer[bar_index] - fastOSCBuffer[bar_index + 1];
|
||||
double slowOSCSlope = slowOSCBuffer[bar_index] - slowOSCBuffer[bar_index + 1];
|
||||
double tanFastSlowOSC = MathAbs(
|
||||
(fastOSCSlope - slowOSCSlope) / (1 + (fastOSCSlope * slowOSCSlope))
|
||||
);
|
||||
|
||||
//
|
||||
// here we pass Tan of angle ...
|
||||
// fastSlowOSCAngleBuffer[bar_index] = tanFastSlowOSC;
|
||||
|
||||
//
|
||||
// here we pass degree of angle ...
|
||||
fastSlowOSCAngleBuffer[bar_index] = MathArctan(tanFastSlowOSC);
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,412 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center X Indicator
|
||||
// ---------------------------------------------
|
||||
// saherelm implementation of above indicator ...
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
input int marketLength = 7; // Market Length
|
||||
|
||||
//
|
||||
input int shortCycleMultiplier = 2; // Market Short Cycle Multiplier
|
||||
input int mediumCycleMultiplier = 6; // Market Medium Cycle Multiplier
|
||||
input int longCycleMultiplier = 36; // Market Medium Cycle Multiplier
|
||||
|
||||
//
|
||||
input ENUM_MA_METHOD maMethod = MODE_SMA; // Ma Method
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 6
|
||||
|
||||
//
|
||||
#property indicator_plots 6
|
||||
|
||||
//
|
||||
// Start Define Indicator Buffer Styles ...
|
||||
//
|
||||
//
|
||||
// Short Cycle Highest High Buffer ...
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrGreen
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// Short Cycle Lowest Low Buffer ...
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Medium Cycle Highest High Buffer ...
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrAqua
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Medium Cycle Lowest Low Buffer ...
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrFuchsia
|
||||
#property indicator_style4 STYLE_DOT
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// Long Cycle Highest High Buffer ...
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 C'62,82,6'
|
||||
#property indicator_style5 STYLE_DOT
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
// Long Cycle Lowest Low Buffer ...
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 C'255,81,0'
|
||||
#property indicator_style6 STYLE_DOT
|
||||
#property indicator_width6 1
|
||||
//
|
||||
// End Define Indicator Buffer Styles ...
|
||||
//
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
//
|
||||
// HH Buffers ...
|
||||
#define scHHBufferIndex 0
|
||||
#define scLLBufferIndex 1
|
||||
#define mcHHBufferIndex 2
|
||||
#define mcLLBufferIndex 3
|
||||
#define lcHHBufferIndex 4
|
||||
#define lcLLBufferIndex 5
|
||||
|
||||
double scHHBuffer[];
|
||||
double scLLBuffer[];
|
||||
double mcHHBuffer[];
|
||||
double mcLLBuffer[];
|
||||
double lcHHBuffer[];
|
||||
double lcLLBuffer[];
|
||||
|
||||
//
|
||||
// Variables ...
|
||||
int shortCycleLength;
|
||||
int mediumCycleLength;
|
||||
int longCycleLength;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
if (
|
||||
marketLength <= 0 ||
|
||||
shortCycleMultiplier <= 0 ||
|
||||
mediumCycleMultiplier <= 0 ||
|
||||
shortCycleMultiplier > mediumCycleMultiplier
|
||||
) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Start Set Index Buffers ...
|
||||
//
|
||||
shortCycleLength = shortCycleMultiplier * marketLength;
|
||||
mediumCycleLength = mediumCycleMultiplier * marketLength;
|
||||
longCycleLength = longCycleMultiplier * marketLength;
|
||||
|
||||
//
|
||||
// Highest High and Lowest Low Buffers ...
|
||||
//
|
||||
// Short Cycle Highest High ...
|
||||
string scHHLbl = StringConcatenate(
|
||||
"SC HH(", shortCycleLength, ")"
|
||||
);
|
||||
SetIndexBuffer(scHHBufferIndex, scHHBuffer);
|
||||
SetIndexLabel(scHHBufferIndex, scHHLbl);
|
||||
|
||||
//
|
||||
// Short Cycle Lowest Low ...
|
||||
string scLLLbl = StringConcatenate(
|
||||
"SC LL(", shortCycleLength, ")"
|
||||
);
|
||||
SetIndexBuffer(scLLBufferIndex, scLLBuffer);
|
||||
SetIndexLabel(scLLBufferIndex, scLLLbl);
|
||||
|
||||
//
|
||||
// Medium Cycle Highest High ...
|
||||
string mcHHLbl = StringConcatenate(
|
||||
"MC HH(", mediumCycleLength, ")"
|
||||
);
|
||||
SetIndexBuffer(mcHHBufferIndex, mcHHBuffer);
|
||||
SetIndexLabel(mcHHBufferIndex, mcHHLbl);
|
||||
|
||||
//
|
||||
// Medium Cycle Lowest Low ...
|
||||
string mcLLLbl = StringConcatenate(
|
||||
"MC LL(", mediumCycleLength, ")"
|
||||
);
|
||||
SetIndexBuffer(mcLLBufferIndex, mcLLBuffer);
|
||||
SetIndexLabel(mcLLBufferIndex, mcLLLbl);
|
||||
|
||||
//
|
||||
// Long Cycle Highest High ...
|
||||
string lcHHLbl = StringConcatenate(
|
||||
"LC HH(", longCycleLength, ")"
|
||||
);
|
||||
SetIndexBuffer(lcHHBufferIndex, lcHHBuffer);
|
||||
SetIndexLabel(lcHHBufferIndex, lcHHLbl);
|
||||
|
||||
//
|
||||
// Long Cycle Lowest Low ...
|
||||
string lcLLLbl = StringConcatenate(
|
||||
"LC LL(", longCycleLength, ")"
|
||||
);
|
||||
SetIndexBuffer(lcLLBufferIndex, lcLLBuffer);
|
||||
SetIndexLabel(lcLLBufferIndex, lcLLLbl);
|
||||
//
|
||||
// End Set Index Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[]
|
||||
) {
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(0, marketLength);
|
||||
|
||||
//
|
||||
// input variable, we return 0 means nothing passed ...
|
||||
if (rates_total < maxLength) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// found which candles calculated before ...
|
||||
limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1;
|
||||
|
||||
//
|
||||
// this is the main loop of calculations, for each bar index ...
|
||||
for (int i = limit - 1; i >= 0; i--) {
|
||||
//
|
||||
// Start Calculation here ...
|
||||
// i is bar_index ...
|
||||
|
||||
//
|
||||
// Calculat Ma's ...
|
||||
//
|
||||
CalculateShortCycle(i);
|
||||
|
||||
//
|
||||
CalculateMediumCycle(i);
|
||||
|
||||
//
|
||||
CalculateLongCycle(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Calculating Short Cycle ...
|
||||
void CalculateShortCycle(
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
// Short Cycle Highest High ...
|
||||
//
|
||||
int scHHIdx = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_HIGH,
|
||||
shortCycleLength,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
double scHH = iHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
scHHIdx
|
||||
);
|
||||
|
||||
//
|
||||
scHHBuffer[bar_index] = scHH;
|
||||
|
||||
//
|
||||
// Short Cycle Lowest Low ...
|
||||
//
|
||||
int scLLIdx = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_LOW,
|
||||
shortCycleLength,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
double scLL = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
scLLIdx
|
||||
);
|
||||
|
||||
//
|
||||
scLLBuffer[bar_index] = scLL;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating Medium Cycle ...
|
||||
void CalculateMediumCycle(
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
// Medium Cycle Highest High ...
|
||||
//
|
||||
int mcHHIdx = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_HIGH,
|
||||
mediumCycleLength,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
double mcHH = iHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mcHHIdx
|
||||
);
|
||||
|
||||
//
|
||||
mcHHBuffer[bar_index] = mcHH;
|
||||
|
||||
//
|
||||
// Medium Cycle Lowest Low ...
|
||||
//
|
||||
int mcLLIdx = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_LOW,
|
||||
mediumCycleLength,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
double mcLL = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mcLLIdx
|
||||
);
|
||||
|
||||
//
|
||||
mcLLBuffer[bar_index] = mcLL;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating Long Cycle ...
|
||||
void CalculateLongCycle(
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
// Long Cycle Highest High ...
|
||||
//
|
||||
int lcHHIdx = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_HIGH,
|
||||
longCycleLength,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
double lcHH = iHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
lcHHIdx
|
||||
);
|
||||
|
||||
//
|
||||
lcHHBuffer[bar_index] = lcHH;
|
||||
|
||||
//
|
||||
// Long Cycle Lowest Low ...
|
||||
//
|
||||
int lcLLIdx = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_LOW,
|
||||
longCycleLength,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
double lcLL = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
lcLLIdx
|
||||
);
|
||||
|
||||
//
|
||||
lcLLBuffer[bar_index] = lcLL;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,265 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center Trend Power Indicator
|
||||
// ---------------------------------------------
|
||||
// saherelm implementation of above indicator ...
|
||||
// this indicator uses two ma line:
|
||||
// - fast ma;
|
||||
// - slow ma;
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm MA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int marketLength = 7; // Market Length
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_plots 3
|
||||
#property indicator_buffers 3
|
||||
#property indicator_minimum 0
|
||||
#property indicator_maximum 100
|
||||
|
||||
//
|
||||
#property indicator_levelcolor clrGray
|
||||
#property indicator_levelstyle STYLE_DOT
|
||||
|
||||
//
|
||||
// Start Define Indicator Buffer Styles ...
|
||||
//
|
||||
#property indicator_type1 DRAW_HISTOGRAM
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
#property indicator_type2 DRAW_HISTOGRAM
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrYellow
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
//
|
||||
// End Define Indicator Buffer Styles ...
|
||||
//
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
#define powerUpBufferIndex 0
|
||||
#define powerDownBufferIndex 1
|
||||
#define signalBufferIndex 2
|
||||
#define diBufferIndex 3
|
||||
|
||||
double powerUpBuffer[];
|
||||
double powerDownBuffer[];
|
||||
double signalBuffer[];
|
||||
double diBuffer[];
|
||||
|
||||
//
|
||||
#include "../Libraries/x-saherelm.lib.mq4"
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
if (marketLength <= 0) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
SetLevelValue(0, 0.0);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT,0,"");
|
||||
|
||||
//
|
||||
SetLevelValue(1, 50);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT,1,"");
|
||||
|
||||
//
|
||||
SetLevelValue(2, 100);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT,2,"");
|
||||
|
||||
//
|
||||
string pUpLbl = StringConcatenate(
|
||||
"P Up (", marketLength, ")"
|
||||
);
|
||||
SetIndexLabel(powerUpBufferIndex, pUpLbl);
|
||||
SetIndexBuffer(powerUpBufferIndex, powerUpBuffer);
|
||||
SetIndexDrawBegin(powerUpBufferIndex, marketLength + 1);
|
||||
|
||||
//
|
||||
string pDownLbl = StringConcatenate(
|
||||
"P Down (", marketLength, ")"
|
||||
);
|
||||
SetIndexLabel(powerDownBufferIndex, pDownLbl);
|
||||
SetIndexBuffer(powerDownBufferIndex, powerDownBuffer);
|
||||
SetIndexDrawBegin(powerDownBufferIndex, marketLength + 1);
|
||||
|
||||
//
|
||||
string pSignalLbl = StringConcatenate(
|
||||
"P Signal (", marketLength, ")"
|
||||
);
|
||||
SetIndexLabel(signalBufferIndex, pSignalLbl);
|
||||
SetIndexBuffer(signalBufferIndex, signalBuffer);
|
||||
SetIndexDrawBegin(signalBufferIndex, marketLength + 1);
|
||||
|
||||
//
|
||||
// here we specify logging enabled or not ...
|
||||
enableLogging = true;
|
||||
|
||||
//
|
||||
// this is a Tag which attached to our Logger ...
|
||||
logTag = "X_TPW_OSC";
|
||||
|
||||
//
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[]
|
||||
) {
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(0, marketLength);
|
||||
|
||||
//
|
||||
// input variable, we return 0 means nothing passed ...
|
||||
if (rates_total < maxLength) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// found which candles calculated before ...
|
||||
limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1;
|
||||
|
||||
//
|
||||
// this is the main loop of calculations, for each bar index ...
|
||||
for (int i = limit - 1; i >= 0; i--) {
|
||||
//
|
||||
// Start Calculation here ...
|
||||
// i is bar_index ...
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Calculating Ma ...
|
||||
void CalculateBuffers(
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
double powerUp = 0;
|
||||
double powerDown = 0;
|
||||
|
||||
//
|
||||
int dailyCount = GetDailyCandleCount();
|
||||
double dailyHH = GetMarketHighestHigh(
|
||||
bar_index,
|
||||
dailyCount
|
||||
);
|
||||
double dailyLL = GetMarketLowestLow(
|
||||
bar_index,
|
||||
dailyCount
|
||||
);
|
||||
double dailyDiff = dailyHH - dailyLL;
|
||||
double rate = dailyDiff / 100;
|
||||
|
||||
//
|
||||
for (int i = bar_index; i < bar_index + marketLength; i++) {
|
||||
//
|
||||
XOHCL c = GetCandleModel(i);
|
||||
|
||||
//
|
||||
double cRange =
|
||||
MathAbs(c.open - c.close)
|
||||
// MathAbs(c.high - c.low)
|
||||
;
|
||||
bool isBullish = c.open < c.close;
|
||||
|
||||
//
|
||||
if (isBullish) {
|
||||
powerUp += cRange;
|
||||
} else {
|
||||
powerDown += cRange;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
powerUp = powerUp / rate;
|
||||
powerDown = powerDown / rate;
|
||||
|
||||
//
|
||||
double ema = GetMA(
|
||||
bar_index,
|
||||
marketLength,
|
||||
0,
|
||||
MODE_EMA,
|
||||
PRICE_WEIGHTED
|
||||
);
|
||||
|
||||
//
|
||||
double signal = (ema / 100) * rate;
|
||||
double signalAddition = MathMin(powerUp, powerDown);
|
||||
|
||||
//
|
||||
powerUpBuffer[bar_index] = powerUp;
|
||||
powerDownBuffer[bar_index] = powerDown;
|
||||
signalBuffer[bar_index] = signal + signalAddition;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,291 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center Trend Power Indicator
|
||||
// ---------------------------------------------
|
||||
// saherelm implementation of above indicator ...
|
||||
// this indicator uses two ma line:
|
||||
// - fast ma;
|
||||
// - slow ma;
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm MA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int marketLength = 7; // Market Length
|
||||
input int shift = 0; // Shift
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_plots 3
|
||||
#property indicator_buffers 3
|
||||
// #property indicator_minimum 0
|
||||
// #property indicator_maximum 200
|
||||
|
||||
//
|
||||
#property indicator_levelcolor clrGray
|
||||
#property indicator_levelstyle STYLE_DOT
|
||||
|
||||
//
|
||||
// Start Define Indicator Buffer Styles ...
|
||||
//
|
||||
#property indicator_type1 DRAW_HISTOGRAM
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
#property indicator_type2 DRAW_HISTOGRAM
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrYellow
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// #property indicator_type4 DRAW_LINE
|
||||
// #property indicator_color4 clrAqua
|
||||
// #property indicator_style4 STYLE_DASHDOT
|
||||
// #property indicator_width4 1
|
||||
//
|
||||
// End Define Indicator Buffer Styles ...
|
||||
//
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
#define powerUpBufferIndex 0
|
||||
#define powerDownBufferIndex 1
|
||||
#define signalBufferIndex 2
|
||||
// #define diBufferIndex 3
|
||||
|
||||
double powerUpBuffer[];
|
||||
double powerDownBuffer[];
|
||||
double signalBuffer[];
|
||||
// double diBuffer[];
|
||||
|
||||
//
|
||||
#include "../Libraries/x-saherelm.lib.mq4"
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
if (marketLength <= 0) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
// //
|
||||
// SetLevelValue(0, 0.0);
|
||||
// IndicatorSetString(INDICATOR_LEVELTEXT,0,"");
|
||||
|
||||
// //
|
||||
// SetLevelValue(1, 50);
|
||||
// IndicatorSetString(INDICATOR_LEVELTEXT,1,"");
|
||||
|
||||
// //
|
||||
// SetLevelValue(2, 100);
|
||||
// IndicatorSetString(INDICATOR_LEVELTEXT,2,"");
|
||||
|
||||
//
|
||||
string pUpLbl = StringConcatenate(
|
||||
"P Up (", marketLength, ")"
|
||||
);
|
||||
SetIndexLabel(powerUpBufferIndex, pUpLbl);
|
||||
SetIndexBuffer(powerUpBufferIndex, powerUpBuffer);
|
||||
SetIndexDrawBegin(powerUpBufferIndex, marketLength + 1);
|
||||
|
||||
//
|
||||
string pDownLbl = StringConcatenate(
|
||||
"P Down (", marketLength, ")"
|
||||
);
|
||||
SetIndexLabel(powerDownBufferIndex, pDownLbl);
|
||||
SetIndexBuffer(powerDownBufferIndex, powerDownBuffer);
|
||||
SetIndexDrawBegin(powerDownBufferIndex, marketLength + 1);
|
||||
|
||||
//
|
||||
string pSignalLbl = StringConcatenate(
|
||||
"P Signal (", marketLength, ")"
|
||||
);
|
||||
SetIndexLabel(signalBufferIndex, pSignalLbl);
|
||||
SetIndexBuffer(signalBufferIndex, signalBuffer);
|
||||
SetIndexDrawBegin(signalBufferIndex, marketLength + 1);
|
||||
|
||||
// //
|
||||
// string pDiLbl = StringConcatenate(
|
||||
// "P DI (", marketLength, ")"
|
||||
// );
|
||||
// SetIndexLabel(diBufferIndex, pDiLbl);
|
||||
// SetIndexBuffer(diBufferIndex, diBuffer);
|
||||
// SetIndexDrawBegin(diBufferIndex, marketLength + 1);
|
||||
|
||||
//
|
||||
// here we specify logging enabled or not ...
|
||||
enableLogging = true;
|
||||
|
||||
//
|
||||
// this is a Tag which attached to our Logger ...
|
||||
logTag = "X_TPW_OSC";
|
||||
|
||||
//
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[]
|
||||
) {
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(0, marketLength);
|
||||
|
||||
//
|
||||
// input variable, we return 0 means nothing passed ...
|
||||
if (rates_total < maxLength) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// found which candles calculated before ...
|
||||
limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1;
|
||||
|
||||
//
|
||||
// this is the main loop of calculations, for each bar index ...
|
||||
for (int i = limit - 1; i >= 0; i--) {
|
||||
//
|
||||
// Start Calculation here ...
|
||||
// i is bar_index ...
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Calculating Ma ...
|
||||
void CalculateBuffers(
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
double powerUp = 0;
|
||||
double powerDown = 0;
|
||||
|
||||
//
|
||||
int dailyCount = GetDailyCandleCount();
|
||||
double dailyHH = GetMarketHighestHigh(
|
||||
bar_index,
|
||||
dailyCount
|
||||
);
|
||||
double dailyLL = GetMarketLowestLow(
|
||||
bar_index,
|
||||
dailyCount
|
||||
);
|
||||
double dailyDiff = dailyHH - dailyLL;
|
||||
double rate = dailyDiff / 100;
|
||||
|
||||
//
|
||||
for (int i = bar_index + shift; i < bar_index + marketLength + shift; i++) {
|
||||
//
|
||||
XOHCL c = GetCandleModel(i);
|
||||
|
||||
//
|
||||
double cRange =
|
||||
MathAbs(c.open - c.close)
|
||||
// MathAbs(c.high - c.low)
|
||||
;
|
||||
bool isBullish = c.open < c.close;
|
||||
|
||||
//
|
||||
if (isBullish) {
|
||||
powerUp += cRange;
|
||||
} else {
|
||||
powerDown += cRange;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
powerUp = powerUp / rate;
|
||||
powerDown = powerDown / rate;
|
||||
|
||||
|
||||
//
|
||||
double ema = GetMA(
|
||||
bar_index,
|
||||
(marketLength * 2),
|
||||
0,
|
||||
MODE_EMA,
|
||||
PRICE_WEIGHTED
|
||||
);
|
||||
|
||||
//
|
||||
powerUpBuffer[bar_index] = powerUp;
|
||||
|
||||
//
|
||||
powerDownBuffer[bar_index] = -1 * powerDown;
|
||||
|
||||
//
|
||||
double emaRate = MathAbs(powerUp - MathAbs(powerDown)) / 100;
|
||||
double signal = (ema / 100) * emaRate;
|
||||
|
||||
//
|
||||
bool isPowerUp = powerUp > MathAbs(powerDown);
|
||||
double signalAddition = isPowerUp ? (-1 * powerDown) : powerUp;
|
||||
signalBuffer[bar_index] = signal + signalAddition;
|
||||
//
|
||||
// double pDiff = powerUpBuffer[bar_index] - powerDownBuffer[bar_index];
|
||||
// double cDiValue = pDiff + signalBuffer[bar_index];
|
||||
// diBuffer[bar_index] = cDiValue;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,395 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center X Indicator
|
||||
// ---------------------------------------------
|
||||
// saherelm implementation of above indicator ...
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
input int marketLength = 7; // Market Length
|
||||
|
||||
//
|
||||
input double step = 0.02; // P SAR Step
|
||||
input double maximum = 0.2; // P SAR Maximum
|
||||
|
||||
//
|
||||
input int shortCycleMultiplier = 2; // Market Short Cycle Multiplier
|
||||
input int mediumCycleMultiplier = 6; // Market Medium Cycle Multiplier
|
||||
input int longCycleMultiplier = 36; // Market Medium Cycle Multiplier
|
||||
|
||||
//
|
||||
input ENUM_MA_METHOD maMethod = MODE_SMA; // Ma Method
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 7
|
||||
|
||||
//
|
||||
#property indicator_plots 7
|
||||
|
||||
//
|
||||
// Start Define Indicator Buffer Styles ...
|
||||
//
|
||||
//
|
||||
// Short Cycle Fast Buffer ...
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrGreen
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// Short Cycle Slow Buffer ...
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Medium Cycle Fast Buffer ...
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrAqua
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// Medium Cycle Slow Buffer ...
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrFuchsia
|
||||
#property indicator_style4 STYLE_DOT
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// Long Cycle Fast Buffer ...
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 C'62,82,6'
|
||||
#property indicator_style5 STYLE_DOT
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
// Long Cycle Slow Buffer ...
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 C'255,81,0'
|
||||
#property indicator_style6 STYLE_DOT
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
// Parabolic SAR ...
|
||||
#property indicator_type7 DRAW_LINE
|
||||
#property indicator_color7 C'0,174,255'
|
||||
#property indicator_style7 STYLE_DASHDOT
|
||||
#property indicator_width7 1
|
||||
//
|
||||
// End Define Indicator Buffer Styles ...
|
||||
//
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
//
|
||||
// Ma Buffers ...
|
||||
#define scFastBufferIndex 0
|
||||
#define scSlowBufferIndex 1
|
||||
#define mcFastBufferIndex 2
|
||||
#define mcSlowBufferIndex 3
|
||||
#define lcFastBufferIndex 4
|
||||
#define lcSlowBufferIndex 5
|
||||
#define psarBufferIndex 6
|
||||
|
||||
double scFastBuffer[];
|
||||
double scSlowBuffer[];
|
||||
double mcFastBuffer[];
|
||||
double mcSlowBuffer[];
|
||||
double lcFastBuffer[];
|
||||
double lcSlowBuffer[];
|
||||
double psarBuffer[];
|
||||
|
||||
//
|
||||
// Variables ...
|
||||
int shortCycleLength;
|
||||
int mediumCycleLength;
|
||||
int longCycleLength;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
if (
|
||||
marketLength <= 0 ||
|
||||
shortCycleMultiplier <= 0 ||
|
||||
mediumCycleMultiplier <= 0 ||
|
||||
shortCycleMultiplier > mediumCycleMultiplier
|
||||
) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Start Set Index Buffers ...
|
||||
//
|
||||
shortCycleLength = shortCycleMultiplier * marketLength;
|
||||
mediumCycleLength = mediumCycleMultiplier * marketLength;
|
||||
longCycleLength = longCycleMultiplier * marketLength;
|
||||
|
||||
//
|
||||
// Ma Buffers ...
|
||||
//
|
||||
// Short Cycle ...
|
||||
string scFLbl = StringConcatenate(
|
||||
"SC F(", shortCycleLength, ")"
|
||||
);
|
||||
SetIndexBuffer(scFastBufferIndex, scFastBuffer);
|
||||
SetIndexLabel(scFastBufferIndex, scFLbl);
|
||||
|
||||
//
|
||||
string scSLbl = StringConcatenate(
|
||||
"SC S(", shortCycleLength, ")"
|
||||
);
|
||||
SetIndexBuffer(scSlowBufferIndex, scSlowBuffer);
|
||||
SetIndexLabel(scSlowBufferIndex, scSLbl);
|
||||
|
||||
//
|
||||
// Medium Cycle ...
|
||||
string mcFLbl = StringConcatenate(
|
||||
"MC F(", mediumCycleLength, ")"
|
||||
);
|
||||
SetIndexBuffer(mcFastBufferIndex, mcFastBuffer);
|
||||
SetIndexLabel(mcFastBufferIndex, mcFLbl);
|
||||
|
||||
//
|
||||
string mcSLbl = StringConcatenate(
|
||||
"MC S(", mediumCycleLength, ")"
|
||||
);
|
||||
SetIndexBuffer(mcSlowBufferIndex, mcSlowBuffer);
|
||||
SetIndexLabel(mcSlowBufferIndex, mcSLbl);
|
||||
|
||||
//
|
||||
// Long Cycle ...
|
||||
string lcFLbl = StringConcatenate(
|
||||
"LC F(", longCycleLength, ")"
|
||||
);
|
||||
SetIndexBuffer(lcFastBufferIndex, lcFastBuffer);
|
||||
SetIndexLabel(lcFastBufferIndex, lcFLbl);
|
||||
|
||||
//
|
||||
string lcSLbl = StringConcatenate(
|
||||
"LC S(", longCycleLength, ")"
|
||||
);
|
||||
SetIndexBuffer(lcSlowBufferIndex, lcSlowBuffer);
|
||||
SetIndexLabel(lcSlowBufferIndex, lcSLbl);
|
||||
//
|
||||
// End Set Index Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Parabolic Sar ...
|
||||
SetIndexBuffer(psarBufferIndex, psarBuffer);
|
||||
SetIndexLabel(psarBufferIndex, "P Sar");
|
||||
|
||||
//
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[]
|
||||
) {
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(0, marketLength);
|
||||
|
||||
//
|
||||
// input variable, we return 0 means nothing passed ...
|
||||
if (rates_total < maxLength) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// found which candles calculated before ...
|
||||
limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1;
|
||||
|
||||
//
|
||||
// this is the main loop of calculations, for each bar index ...
|
||||
for (int i = limit - 1; i >= 0; i--) {
|
||||
//
|
||||
// Start Calculation here ...
|
||||
// i is bar_index ...
|
||||
|
||||
//
|
||||
// Calculat Ma's ...
|
||||
//
|
||||
CalculateShortCycle(i);
|
||||
|
||||
//
|
||||
CalculateMediumCycle(i);
|
||||
|
||||
//
|
||||
CalculateLongCycle(i);
|
||||
|
||||
//
|
||||
// Parabolic SAR ...
|
||||
CalculateParabolicSAR(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Calculating Short Cycle ...
|
||||
void CalculateShortCycle(
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
double scFast = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
shortCycleLength,
|
||||
0,
|
||||
maMethod,
|
||||
PRICE_OPEN,
|
||||
bar_index
|
||||
);
|
||||
scFastBuffer[bar_index] = scFast;
|
||||
|
||||
//
|
||||
double scSlow = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
shortCycleLength,
|
||||
0,
|
||||
maMethod,
|
||||
PRICE_CLOSE,
|
||||
bar_index
|
||||
);
|
||||
scSlowBuffer[bar_index] = scSlow;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating Medium Cycle ...
|
||||
void CalculateMediumCycle(
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
double mcFast = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mediumCycleLength,
|
||||
0,
|
||||
maMethod,
|
||||
PRICE_OPEN,
|
||||
bar_index
|
||||
);
|
||||
mcFastBuffer[bar_index] = mcFast;
|
||||
|
||||
//
|
||||
double mcSlow = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
mediumCycleLength,
|
||||
0,
|
||||
maMethod,
|
||||
PRICE_CLOSE,
|
||||
bar_index
|
||||
);
|
||||
mcSlowBuffer[bar_index] = mcSlow;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating Long Cycle ...
|
||||
void CalculateLongCycle(
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
double lcFast = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
longCycleLength,
|
||||
0,
|
||||
maMethod,
|
||||
PRICE_OPEN,
|
||||
bar_index
|
||||
);
|
||||
lcFastBuffer[bar_index] = lcFast;
|
||||
|
||||
//
|
||||
double lcSlow = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
longCycleLength,
|
||||
0,
|
||||
maMethod,
|
||||
PRICE_CLOSE,
|
||||
bar_index
|
||||
);
|
||||
lcSlowBuffer[bar_index] = lcSlow;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Parabolic SAR ...
|
||||
void CalculateParabolicSAR(
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
double pSar = iSAR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
step,
|
||||
maximum,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
psarBuffer[bar_index] = pSar;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Reference in New Issue
Block a user