Adding the lower line now will not change the functioning of the calculation. First I need the code to be working correctly and than I can add the lower line condition.
Adding the lower line now will not change the functioning of the calculation. First I need the code to be working correctly and than I can add the lower line condition.
Adding the Lower Line will change the "idea" of how it operates , regardless of whether or not the code is correct . The idea with the lower line is closer to what you are trying to accomplish so i would do that first .
//+------------------------------------------------------------------+//| Envelopes.mq4 |//| Copyright 2016, MetaQuotes Software Corp. |//| https://www.mql5.com |//+------------------------------------------------------------------+#property copyright"Copyright 2016, MetaQuotes Software Corp."#property link"https://www.mql5.com"#property version"1.00"#property strict#property indicator_chart_window#property indicator_buffers4#property indicator_plots4//--- plot OriginalUpper#property indicator_label1"OriginalUpper"#property indicator_type1DRAW_LINE#property indicator_color1clrWhite#property indicator_style1STYLE_SOLID#property indicator_width11//--- plot OriginalLower#property indicator_label2"OriginalLower"#property indicator_type2DRAW_LINE#property indicator_color2clrWhite#property indicator_style2STYLE_SOLID#property indicator_width21//--- plot SeekUpper#property indicator_label3"SeekUpper"#property indicator_type3DRAW_LINE#property indicator_color3clrDodgerBlue#property indicator_style3STYLE_SOLID#property indicator_width31//--- plot SeekLower#property indicator_label4"SeekLower"#property indicator_type4DRAW_LINE#property indicator_color4clrCrimson#property indicator_style4STYLE_SOLID#property indicator_width41inputENUM_MA_METHOD MA_Method=MODE_SMA;
inputENUM_APPLIED_PRICE Applied_Price=PRICE_CLOSE;
inputint MA_Period=20;
enum ds_use
{
ds_use_valid=0,//Only if found
ds_use_last=1,//Last loop value
ds_use_closest=2//Closest possible - if not found
};
input ds_use use_last_value=ds_use_valid;
//--- indicator buffersdouble OriginalUpperBuffer[];//M15double OriginalLowerBuffer[];//M15double SeekUpperBuffer[];
double SeekLowerBuffer[];
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit()
{
//--- indicator buffers mappingSetIndexBuffer(0,OriginalUpperBuffer);
SetIndexBuffer(1,OriginalLowerBuffer);
SetIndexBuffer(2,SeekUpperBuffer);
SetIndexBuffer(3,SeekLowerBuffer);
//---return(INIT_SUCCEEDED);
}
double previous_dev_step=-1;
//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[])
{
//---int begin=rates_total-prev_calculated;
if(begin>100) begin=begin-10;
//--- the main loop of calculationsfor(int i=begin; i>=0 && !IsStopped(); i--)
{
double DevStep=0.125;
double CDevStep=0.125;//closest dev stepdouble minimum=0;
double Deviation=0;
double M15UppEnv = iEnvelopes(NULL, PERIOD_M15,63,1,0,PRICE_CLOSE,0.063,MODE_UPPER,i+1); // prijs van de M15-upper envelope deviatie 0,063 bar 0double M15LowEnv = iEnvelopes(NULL, PERIOD_M15,63,1,0,PRICE_CLOSE,0.063,MODE_LOWER,i+1); // prijs van de M15-lower envelope deviatie 0,063 bar 0//seek int seek_step=125;
for(int seek=125;seek<=3000;seek+=seek_step)
{
DevStep=seek;
DevStep=DevStep/1000;
double env_up=iEnvelopes(NULL,PERIOD_M5,108,1,0,PRICE_CLOSE,DevStep,MODE_UPPER,i+1);
double env_dw=iEnvelopes(NULL,PERIOD_M5,108,1,0,PRICE_CLOSE,DevStep,MODE_LOWER,i+1);
if(env_up>M15LowEnv&&env_up<M15UppEnv&&env_dw>M15LowEnv&&env_dw<M15UppEnv)
{
Deviation = DevStep;
break;
}
//closest calcsdouble dist_up=env_up-M15UppEnv;
dist_up=MathAbs(dist_up);
double dist_dw=env_dw-M15LowEnv;
dist_dw=MathAbs(dist_dw);
double dist=dist_up+dist_dw;
if(seek==125)
{
minimum=dist;
CDevStep=DevStep;
}
if(seek>125)
{
if(dist<minimum)
{
minimum=dist;
CDevStep=DevStep;
}
}
//closest calcs end here
Deviation=DevStep;
if(seek==3000&&use_last_value==ds_use_valid) Deviation=previous_dev_step;
if(seek==3000&&use_last_value==ds_use_closest) Deviation=CDevStep;
}
//seek ends here
OriginalUpperBuffer[i]=M15UppEnv;
OriginalLowerBuffer[i]=M15LowEnv;
//if value is valid if(Deviation!=-1)
{
double ma=iMA(NULL,0,MA_Period,0,MA_Method,Applied_Price,i+1);
SeekUpperBuffer[i]=(1+Deviation/100)*ma;
SeekLowerBuffer[i]=(1-Deviation/100)*ma;
}
previous_dev_step=Deviation;
//if value is valid ends here
}
//--- //--- return value of prev_calculated for next callreturn(rates_total);
}
//+------------------------------------------------------------------+//| Timer function |//+------------------------------------------------------------------+voidOnTimer()
{
//---
}
//+------------------------------------------------------------------+//| ChartEvent function |//+------------------------------------------------------------------+voidOnChartEvent(constint id,
constlong &lparam,
constdouble &dparam,
conststring &sparam)
{
//---
}
//+------------------------------------------------------------------+
The code you send can draws two lines of period 63, but not the lines of the 1008 period, and its the last one that is required. As the code is now, it will never work though because the logic in Line 102 excludes every possibility.
The upper envelope and the lower envelope of a slow period (1008) can never be between the fast period envelopes at the same time.
It is like I explained before, just one of the two slow envelopes either the upper or the lower will be between the fast envelopes at any given time. That is why I road that once the code for the upper slow envelope is working, the code for the lower slow envelope is easily added.
Yes, that is the idea, but although the code seems right, it does not execute right
Great , might i ask about the 1008 to 63 ? why this pair ?
Great = We are indeed checking the upper line only , add another clause in the if statement for the lower line.
These are just the MA settings I use.
Adding the lower line now will not change the functioning of the calculation. First I need the code to be working correctly and than I can add the lower line condition.
These are just the MA settings I use.
Adding the lower line now will not change the functioning of the calculation. First I need the code to be working correctly and than I can add the lower line condition.
The idea with the lower line is closer to what you are trying to accomplish so i would do that first .
Hi Lorentzos,
Thanks for the work your putting into my request.
The code you send can draws two lines of period 63, but not the lines of the 1008 period, and its the last one that is required. As the code is now, it will never work though because the logic in Line 102 excludes every possibility.
The upper envelope and the lower envelope of a slow period (1008) can never be between the fast period envelopes at the same time.
It is like I explained before, just one of the two slow envelopes either the upper or the lower will be between the fast envelopes at any given time. That is why I road that once the code for the upper slow envelope is working, the code for the lower slow envelope is easily added.
Hi Lorentzos,
I made some changes to your code, and guess what,..... it is working.
Thanks a lot for the help you gave me.
I wish you a very nice evening and prosperous trading.
Robert
Hi Lorentzos,
I made some changes to your code, and guess what,..... it is working.
Thanks a lot for the help you gave me.
I wish you a very nice evening and prosperous trading.
Robert
No problem . Enjoy :)