Files
xMQL4/xIndicators/x-saherelm.sl.mq4
T
2024-01-25 04:03:36 +03:30

154 lines
3.7 KiB
Plaintext

///////////////////////////////////////////////////////
//
// 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 ...
//