Implementing own calculation into Moving Average period 1 to have plot series of data in chart (the indicator goes back in time with calculations)
arsa2018: Is there any professional who may help me with implementing a simple moving average (period 1) on the calculation
- learn
to code it, or pay (Freelance) someone to code it.
We're not going to code it for you.
We are willing to help you when you post your attempt (using SRC) and the nature of your problem. - AverageUpperRange = AverageUpperRange + MathAbs(iOpen(Symbol(),PERIOD_D1,cnt)-iClose(Symbol(),PERIOD_D1,cnt));Why is the upperRange the body candle, and the lowerRange includes the body on a up candle but not a down candle?
AverageLowerRange = AverageLowerRange + MathAbs(iClose(Symbol(),PERIOD_D1,cnt)-iLow(Symbol(),PERIOD_D1,cnt));
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hey folks,
I am currently sitting on a code which has my own calculation. I succeeded to code the calculation into MQL4 for the current period. However, I want to look back in time and see the indicator go as well (kind of a loop) also for evaluation of the indicator based on history. I had the idea to implement a simple moving average with period 1 on the calculation with a calculation loop. But then the calculation has to be adjusted to work in a loop as well.
Is there any professional who may help me with implementing a simple moving average (period 1) on the calculation (will be 4 simple moving averages for each outcome) (see below).
Here is the code:
#property indicator_buffers 2
#property indicator_color1 White
#property indicator_color2 Red
#property indicator_level1 0
//---- input parameters
extern int DaysToLookBack = 21;
extern int SetATRTimeframe = 60;
extern int ATRValue = 23;
extern double ATRMultiplier = 3.9812;
extern color LineColor = Black;
extern int LineWidth = 1;
extern int LineStyle = STYLE_DOT;
int ShowComment = TRUE;
extern string LineNameUpper = "uBBE";
extern string LineNameLower = "lBBE";
extern string LineExtensionUpper = "uDistribution";
extern string LineExtensionLower = "lDistribution";
int init() {
IndicatorShortName("BBE Indicator ("+DaysToLookBack+")");
return(0);
}
int deinit() {
if (ShowComment) Comment("");
ObjectDelete(LineNameUpper);
ObjectDelete(LineNameLower);
ObjectDelete(LineExtensionUpper);
ObjectDelete(LineExtensionLower);
ObjectDelete("ObjName33");
ObjectDelete("ObjName213");
ObjectDelete("ObjName33Distri");
ObjectDelete("ObjName213Distri");
return(0);
}
int start() {
int LookBack = iBarShift(Symbol(),0,iTime(Symbol(),PERIOD_D1,DaysToLookBack),false);
int limit = MathMin(Bars,LookBack+1);
{
double AverageUpperRange=0.0,AverageLowerRange=0.0;
for (int cnt=DaysToLookBack; cnt>=1; cnt--) {
AverageUpperRange = AverageUpperRange + MathAbs(iOpen(Symbol(),PERIOD_D1,cnt)-iClose(Symbol(),PERIOD_D1,cnt));
AverageLowerRange = AverageLowerRange + MathAbs(iClose(Symbol(),PERIOD_D1,cnt)-iLow(Symbol(),PERIOD_D1,cnt));
}
AverageUpperRange/=DaysToLookBack;
AverageLowerRange/=DaysToLookBack;
AverageUpperRange = iOpen(Symbol(),PERIOD_D1,0)+AverageUpperRange;
AverageLowerRange = iOpen(Symbol(),PERIOD_D1,0)-AverageLowerRange;
if (ShowComment) Comment("BBE "+"\n"" © Arsa2018");
if (ObjectFind(LineNameUpper)<0) DrawLine(LineNameUpper,AverageUpperRange);
else ObjectMove(LineNameUpper,0,TimeCurrent(),AverageUpperRange);
if (ObjectFind(LineNameLower)<0) DrawLine(LineNameLower,AverageLowerRange);
else ObjectMove(LineNameLower,0,TimeCurrent(),AverageLowerRange);
ObjectCreate("ObjName33", OBJ_TEXT, 0, TimeCurrent(),DoubleToStr(AverageUpperRange,Digits));
ObjectSetText("ObjName33"," o BBE: "+DoubleToStr(AverageUpperRange,Digits),10, "Verdana", DarkGray);
ObjectSet("ObjName33", OBJPROP_CORNER, 0);
ObjectSetInteger(0,"ObjName33",OBJPROP_ANCHOR,ANCHOR_LEFT);
ObjectCreate("ObjName213", OBJ_TEXT, 0, TimeCurrent(),DoubleToStr(AverageLowerRange,Digits));
ObjectSetText("ObjName213"," u BBE: "+DoubleToStr(AverageLowerRange,Digits),10, "Verdana", DarkGray);
ObjectSet("ObjName213", OBJPROP_CORNER, 0);
ObjectSetInteger(0,"ObjName213",OBJPROP_ANCHOR,ANCHOR_LEFT);
double AverageUpperExtension=0.0,AverageLowerExtension=0.0;
AverageUpperExtension = AverageUpperRange + iATR(NULL,SetATRTimeframe,ATRValue,0)*ATRMultiplier ;
AverageLowerExtension = AverageLowerRange - iATR(NULL,SetATRTimeframe,ATRValue,0)*ATRMultiplier ;
if (ObjectFind(LineExtensionUpper)<0) DrawLine(LineExtensionUpper,AverageUpperExtension);
else ObjectMove(LineExtensionUpper,0,TimeCurrent(),AverageUpperExtension);
if (ObjectFind(LineExtensionLower)<0) DrawLine(LineExtensionLower,AverageLowerExtension);
else ObjectMove(LineExtensionLower,0,TimeCurrent(),AverageLowerExtension);
ObjectCreate("ObjName33Distri", OBJ_TEXT, 0, TimeCurrent(),DoubleToStr(AverageUpperExtension,Digits));
ObjectSetText("ObjName33Distri"," uDistribution: "+DoubleToStr(AverageUpperExtension,Digits),10, "Verdana", DarkGray);
ObjectSet("ObjName33Distri", OBJPROP_CORNER, 0);
ObjectSetInteger(0,"ObjName33Distri",OBJPROP_ANCHOR,ANCHOR_LEFT);
ObjectCreate("ObjName213Distri", OBJ_TEXT, 0, TimeCurrent(),DoubleToStr(AverageLowerExtension,Digits));
ObjectSetText("ObjName213Distri"," lDistribution: "+DoubleToStr(AverageLowerExtension,Digits),10, "Verdana", DarkGray);
ObjectSet("ObjName213Distri", OBJPROP_CORNER, 0);
ObjectSetInteger(0,"ObjName213Distri",OBJPROP_ANCHOR,ANCHOR_LEFT);
return(0);
}
void DrawLine(string LineName,double price1) {
ObjectCreate(LineName,OBJ_TREND,0,TimeCurrent(),price1,Time[40],price1);
ObjectSet(LineName,OBJPROP_COLOR,LineColor);
ObjectSet(LineName,OBJPROP_WIDTH,LineWidth);
ObjectSet(LineName,OBJPROP_STYLE,LineStyle);
ObjectSet(LineName,OBJPROP_RAY_RIGHT, false);
}
I would be more than grateful if there is anyone who could help me out. Thanks in regard.
Best greetings,
Aron