Coding help - page 198

 
cain82:
Thanks for reply!

But how can I get an angle lines of MA on the general chart like in this indi hystogramm code?

//---- indicator settings

#property indicator_separate_window

#property indicator_buffers 3

#property indicator_color1 LimeGreen

#property indicator_color2 FireBrick

#property indicator_color3 Yellow

#property indicator_width1 2

#property indicator_width2 2

#property indicator_width3 2

//---- indicator parameters

extern int TimeFrame = 60;

extern int MAMode = 0;

extern int MAPeriod = 50;

extern int Price = 4;

extern double AngleTreshold = 0.25;

extern int StartMAShift = 2;

extern int EndMAShift = 0;

extern int MaxBars = 500;

string TF1;

//---- indicator buffers

double UpBuffer[];

double DownBuffer[];

double ZeroBuffer[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

//---- 2 additional buffers are used for counting.

IndicatorBuffers(3);

//---- drawing settings

SetIndexStyle(0,DRAW_HISTOGRAM);

SetIndexStyle(1,DRAW_HISTOGRAM);

SetIndexStyle(2,DRAW_HISTOGRAM);

IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2 );

//---- 3 indicator buffers mapping

if(!SetIndexBuffer(0,UpBuffer) &&

!SetIndexBuffer(1,DownBuffer) &&

!SetIndexBuffer(2,ZeroBuffer))

Print("cannot set indicator buffers!");

SetIndexLabel(0,"");

SetIndexLabel(1,"");

SetIndexLabel(2,"");

switch(TimeFrame)

{

case 1: TF1="M1"; break;

case 5: TF1="M5"; break;

case 15: TF1="M15"; break;

case 30: TF1="M30"; break;

case 60: TF1="H1"; break;

case 240: TF1="H4"; break;

case 1440: TF1="D1"; break;

case 10080: TF1="W1"; break;

case 43200: TF1="MN1"; break;

default: {TimeFrame = Period(); init(); return(0);}

}

IndicatorShortName("MAAngle MTF * "+TF1+" *");

//---- initialization done

return(0);

}

//+------------------------------------------------------------------+

//| The angle for EMA |

//+------------------------------------------------------------------+

int start()

{

double fEndMA, fStartMA;

double fAngle, mFactor, dFactor;

int nLimit, i;

int nCountedBars;

double angle;

int ShiftDif;

string Sym;

if (MAMode >= 4) MAMode = 0;

if(EndMAShift >= StartMAShift)

{

Print("Error: EndMAShift >= StartMAShift");

StartMAShift = 6;

EndMAShift = 0;

}

nCountedBars = IndicatorCounted();

dFactor = 2*3.14159/180.0;

mFactor = 10000.0;

Sym = StringSubstr(Symbol(),3,3);

if (Sym == "JPY") mFactor = 100.0;

ShiftDif = StartMAShift-EndMAShift;

mFactor /= ShiftDif;

//---- check for possible errors

if(nCountedBars<0) return(-1);

//---- last counted bar will be recounted

if(nCountedBars>0) nCountedBars--;

nLimit=Bars-nCountedBars;

nLimit=MathMax(nLimit,TimeFrame/Period());

nLimit=MathMin(nLimit,MaxBars );

//---- main loop

for(i=0; i<nLimit; i++)

{

int y = iBarShift(NULL,TimeFrame,Time);

if (TimeFrame<Period()) TimeFrame=Period();

fEndMA=iMA(NULL,TimeFrame,MAPeriod,0,MAMode,Price,y+EndMAShift);

fStartMA=iMA(NULL,TimeFrame,MAPeriod,0,MAMode,Price,y+StartMAShift);

// 10000.0 : Multiply by 10000 so that the fAngle is not too small

// for the indicator Window.

fAngle = mFactor * (fEndMA - fStartMA)/2.0;

//fAngle = MathArctan(fAngle)/dFactor;

DownBuffer = 0.0;

UpBuffer = 0.0;

ZeroBuffer = 0.0;

if(fAngle > AngleTreshold)

UpBuffer = fAngle;

else if (fAngle < -AngleTreshold)

DownBuffer = fAngle;

else ZeroBuffer = fAngle;

}

return(0);

}

//+------------------------------------------------------------------+

That indicator is calculating something similar to the slope (not the angle, since the angle can never be calculated exactly on the time series chart neither an exact slope since the is trying to use some different math than the one needed for a slope) for each and every bar of the ma. If you want to invert it (I am just guessing what exactly do you want) you are going to get that starting ma as a result (so you are going to get a moving average on chart).

If you wish to extend the slope of the last bar, then you can use something similar to this indicator https://www.mql5.com/en/forum/173235/page36 that extends the moving average using the slope of the last bar

 
mladen:
That indicator is calculating something similar to the slope (not the angle, since the angle can never be calculated exactly on the time series chart neither an exact slope since the is trying to use some different math than the one needed for a slope) for each and every bar of the ma. If you want to invert it (I am just guessing what exactly do you want) you are going to get that starting ma as a result (so you are going to get a moving average on chart). If you wish to extend the slope of the last bar, then you can use something similar to this indicator https://www.mql5.com/en/forum/173235/page36 that extends the moving average using the slope of the last bar

Thank you mladen! It`s very similar to what I want

Do you have the same with MTF mode?

 

mladen..

i need your help to modify this indicator https://www.mql5.com/en/forum/general

 

Mladen,

Calculate BBands using data from a moving average.

As an example to apply to non-standard MT4 stockings.

As an example for one of the types of moving average of AllAverages.

Is a BBands that uses real data from average.

No BBands SMA, with a different type moving average.

 
Antonsan:
Mladen,

Calculate BBands using data from a moving average.

As an example to apply to non-standard MT4 stockings.

As an example for one of the types of moving average of AllAverages.

Is a BBands that uses real data from average.

No BBands SMA, with a different type moving average.

Antonsan

You can calculate Bollinger bands on any value if you use iStdDevOnArry() function.

Fill an array with the values you wish to use (values of any average for example) calculate its deviation using iStdDevOnArray() and calculate a middle line for Bollinger bands using iMaOnArray() (using the same array that iStrDevOnArry() uses) and then the bands are simple : middle line + deviation*multiplier for upper, and middle line - deviation*multiplier for lower band

 

Antonsan

Here is a very somple sample code that you can use as a template to build bollinger bands of any value. All you have to do is to replace iRsi() call in this line :

for(i=limit; i >= 0; i--) value = iRSI(NULL,0,RsiLength,RsiPrice,i);

with the desired function or a iCustom() call to any custom indicator and it will calculate Bollinger bands for that value

Files:
 
mladen:
person77 One more options added : AllowCloseEqualOpen. so you can control it with that option now

Great work mlanden! Thanks again.

 

Good indicator for EA

Hello,

This indicator has 5 line.(pivot+R1+R2+S1+S2)

I want make an ea that base this lines. Unfortunately these line haven't buffer.I need someone allocate a buffer to each line.

Please help

Best Regards;

Bamik

Files:
 
bamik:
Hello,

This indicator has 5 line.(pivot+R1+R2+S1+S2)

I want make an ea that base this lines. Unfortunately these line haven't buffer.I need someone allocate a buffer to each line.

Please help

Best Regards;

Bamik

barnik

Did you check this thread : https://www.mql5.com/en/forum/172894

There is a lot of pivot indicators using buffers at that thread

 
mladen:
barnik

Did you check this thread : https://www.mql5.com/en/forum/172894

There is a lot of pivot indicators using buffers at that thread

Thanks deer mladen for your help,

I download and tested most of these indicators.Only " AutoPivotIndicator_ver5" indicator was just like "TARGETS-LINES".

Unfortunately, this indicator also does not use the buffer and uses the object.

Would you mind please change my simple indicator.(allocate a buffer to each line).it's a little indicator.

Thanks

Reason: