前几天研究了这个虽说有时候直接肉眼就能看出来,但是在附图显示看着更加直接,用谷歌mini写的
//+------------------------------------------------------------------+
//| MA_Slope.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026"
#property link ""
#property version "1.00"
#property strict
#property indicator_separate_window
#property indicator_level1 0.0
#property indicator_buffers 2
#property indicator_color1 clrGreen
#property indicator_color2 clrRed
#property indicator_width1 3
#property indicator_width2 3
input int MAPeriod = 20;
input ENUM_MA_METHOD MAMethod = MODE_SMA;
input ENUM_APPLIED_PRICE MAPrice = PRICE_CLOSE;
double ExtBufferUp[];
double ExtBufferDn[];
int OnInit()
{
SetIndexBuffer(0, ExtBufferUp);
SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID, 3, clrGreen);
SetIndexBuffer(1, ExtBufferDn);
SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 3, clrRed);
IndicatorShortName("MA(" + IntegerToString(MAPeriod) + ") Slope");
return(INIT_SUCCEEDED);
}
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[])
{
if(rates_total <= MAPeriod + 5) return(0);
int limit = rates_total - prev_calculated;
if(prev_calculated > 0) limit++;
if(limit > rates_total - 2) limit = rates_total - 2;
double myPoint = Point;
if(myPoint == 0) myPoint = 0.00001;
for(int i = limit; i >= 0; i--)
{
if(i < 0 || i >= rates_total - 1) continue;
double maCurrent = iMA(NULL, 0, MAPeriod, 0, MAMethod, MAPrice, i);
double maPrevious = iMA(NULL, 0, MAPeriod, 0, MAMethod, MAPrice, i + 1);
double slopeInPoints = (maCurrent - maPrevious) / myPoint;
if(MathAbs(slopeInPoints) < 0.1) slopeInPoints = 0.0;
if(slopeInPoints >= 0)
{
ExtBufferUp[i] = slopeInPoints;
ExtBufferDn[i] = 0.0;
}
else
{
ExtBufferUp[i] = 0.0;
ExtBufferDn[i] = slopeInPoints;
}
}
return(rates_total);
}
用法复制到笔记本然后另存后缀为.mq4 放到MQL4\Indicators就行了
感谢分享 试试