twoWavesLimits/twoWaves.mq5
super.admin 62a907ea44 convert
2025-05-30 16:34:23 +02:00

122 lines
4.2 KiB
MQL5

//+------------------------------------------------------------------+
//| twoWaves.mq5 |
//| Copyright 2018, Benjamin Pillet |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, Benjamin Pillet"
#property link ""
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots 4
//--- plot wave1high
#property indicator_label1 "wave1high"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrTomato
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- plot wave1low
#property indicator_label2 "wave1low"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrTomato
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//--- plot wave2high
#property indicator_label3 "wave2high"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrGold
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
//--- plot wave2low
#property indicator_label4 "wave2low"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrGold
#property indicator_style4 STYLE_SOLID
#property indicator_width4 1
//--- indicator buffers
double wave1highBuffer[];
double wave1lowBuffer[];
double wave2highBuffer[];
double wave2lowBuffer[];
//--- input parameters
input ENUM_TIMEFRAMES TF = PERIOD_CURRENT;
//--- global variables
int pos;
double w1High;
double w1Low;
double p_w2High;//potential wave two high
double w2High;
double p_w2Low;//potential wave two low
double w2Low;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,wave1highBuffer,INDICATOR_DATA);
SetIndexBuffer(1,wave1lowBuffer,INDICATOR_DATA);
SetIndexBuffer(2,wave2highBuffer,INDICATOR_DATA);
SetIndexBuffer(3,wave2lowBuffer,INDICATOR_DATA);
//---
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[])
{
//---
pos = prev_calculated -1;
if(pos < 3){
pos = 3;
}
for(int i=pos; i<rates_total; i++){
//wave one high
if(close[i-2] > open[i-2] && close[i-1] < open[i-1]){
p_w2Low = low[i-1]; //reset potential wave two low
if(high[i-2] > high[i-1]) w1High = high[i-2];
else w1High = high[i-1];
}
//wave one low
if(close[i-2] < open[i-2] && close[i-1] > open[i-1]){
p_w2High = high[i-1]; //reset potential wave two low
if(low[i-2] < low[i-1]) w1Low = low[i-2];
else w1Low = low[i-1];
}
//wave two high
if(high[i-1] > p_w2High) p_w2High = high[i-1];
if(close[i-1] < w1Low && close[i-2] > w1Low){
w2High = p_w2High;
}
//wave two low
if(low[i-1] < p_w2Low) p_w2Low = low[i-1];
if(close[i-1] > w1High && close[i-2] < w1High){
w2Low = p_w2Low;
}
//pass the values to the indicator buffers
wave1highBuffer[i] = w1High;
wave1lowBuffer[i] = w1Low;
wave2highBuffer[i] = w2High;
wave2lowBuffer[i] = w2Low;
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+