You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Swing Index: The Swing Index calculates a value based on four factors: opening price, closing price, high price, and low price. It ranges from -100 to +100, with higher values indicating stronger price swings.
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- indicator parameters
extern int sw_length = 14;
//---- indicator buffers
double SwingBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Indicator buffer
SetIndexBuffer(0, SwingBuffer);
SetIndexStyle(0, DRAW_LINE);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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 = rates_total - sw_length;
for (int i = sw_length; i >= 0; i--)
{
double R = MathAbs(high[i] - close[i - 1]);
double S = MathAbs(low[i] - close[i - 1]);
double ER = MathMax(high[i] - low[i], MathMax(MathAbs(high[i] - close[i - 1]), MathAbs(low[i] - close[i - 1])));
double K = MathMax(R, S);
double SI = 50 * ((close[i] - close[i - 1]) + 0.5 * (close[i] - open[i]) + 0.25 * (close[i - 1] - open[i - 1])) / ER * K / sw_length;
SwingBuffer[i] = SI;
}
return(rates_total);
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Beta Was this translation helpful? Give feedback.
All reactions