//+------------------------------------------------------------------+
//| 第三指标.mq4 |
//| Copyright 2022, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots 4
//--- plot Lab1
#property indicator_label1 "Lab1"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrDarkGreen
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- plot Lab2
#property indicator_label2 "Lab2"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrRed
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//--- plot Lab3
#property indicator_label3 "Lab3"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrBlack
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
//--- plot Lab4
#property indicator_label4 "Lab4"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrBlack
#property indicator_style4 STYLE_SOLID
#property indicator_width4 1
//--- indicator buffers
double Lab1Buffer[];
double Lab2Buffer[];
double Lab3Buffer[];
double Lab4Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,Lab1Buffer);
SetIndexBuffer(1,Lab2Buffer);
SetIndexBuffer(2,Lab3Buffer);
SetIndexBuffer(3,Lab4Buffer);
//---
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 - prev_calculated;
if(limit == 0) limit++;
for(int i = 0; i < limit; i++) {
Lab1Buffer[i] = iIchimoku(NULL,0,9,1,52,MODE_SENKOUSPANA,i);
Lab2Buffer[i] =iIchimoku(NULL,0,9,1,52,MODE_SENKOUSPANB,i);
}
for(int i = 0; i < limit; i++) {
if(Lab1Buffer[i] >= Lab2Buffer[i] && Lab1Buffer[i+1]<Lab2Buffer[i+1]) {
Lab3Buffer[i] =Lab2Buffer[i];
}
else if(Lab1Buffer[i]<=Lab2Buffer[i] && Lab1Buffer[i+1]>Lab2Buffer[i+1]) {
Lab3Buffer[i] = Lab2Buffer[i];
Lab4Buffer[i]=Lab3Buffer[i];
}
}
return(rates_total);
}
|