step moving average mt5 coding
step moving average mt5 coding
//| CustomMA.mq5 |
//| Copyright 2023, Your Name |
//| https://www.yourwebsite.com |
//+------------------------------------------------------------------+
#property copyright "Your Name"
#property link "https://www.yourwebsite.com"
#property version "1.00"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Blue
#property indicator_color2 Green
#property indicator_color3 Red
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
SetIndexBuffer(0, LineBuffer);
SetIndexBuffer(1, UpBuffer);
SetIndexBuffer(2, DnBuffer);
ArraySetAsSeries(LineBuffer, true);
ArraySetAsSeries(UpBuffer, true);
ArraySetAsSeries(DnBuffer, true);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const double &price[],
const long &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const double &spread[])
{
int limit = rates_total - prev_calculated;
if (ColorMode == 0)
LineBuffer[shift] = StepMA;
if (ColorMode == 1)
{
if (close[shift] > StepMA)
UpBuffer[shift] = StepMA;
else
DnBuffer[shift] = StepMA;
}
else if (ColorMode == 2)
{
if (close[shift] > StepMA)
{
UpBuffer[shift] = StepMA;
DnBuffer[shift] = EMPTY_VALUE; // Clear the down buffer
}
else
{
DnBuffer[shift] = StepMA;
UpBuffer[shift] = EMPTY_VALUE; // Clear the up buffer
}
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
//| Function to calculate step size |
//+------------------------------------------------------------------+
int StepSizeCalc(int Length, double Kv, double StepSize, int shift)
{
// Your logic to calculate step size based on Length, Kv, and StepSize
// This is a placeholder; implement your calculation here
return StepSize; // Example return
}
//+------------------------------------------------------------------+
//| Function to calculate step moving average |
//+------------------------------------------------------------------+
double StepMACalc(const double &high[], const double &low[], int Step, int shift)
{
// Your logic to calculate the moving average based on high and low prices
// This is a placeholder; implement your calculation here
return (high[shift] + low[shift]) / 2; // Example return
}