Files
MQL4Data/Bkp/UnUsed/Indicators/x-saherelm.psar.mq4
T
2024-01-25 04:05:58 +03:30

215 lines
4.5 KiB
Plaintext

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