#property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Black IndicatorShortName("Balanced"); extern int BalancedPeriod=20; double NewLine[]; int init() { SetIndexStyle(0,DRAW_LINE,2); SetIndexBuffer(0,NewLine); SetIndexDrawBegin(0,Bars-BalancedPeriod); return(0); } double Ind1; double Ind2; int start() { int counted_bars=IndicatorCounted(); for(int pos=Bars-counted_bars-1;pos>=0;pos--){ Ind1 = iCustom(NULL, 0, "Ind1", 2, pos); Ind2 = iCustom(NULL, 0, "Ind2", 2, pos); NewLine[pos] =(Ind1 + Ind2)/2; } return(0); }
try this code.
when coding Indicators you have to calculate the values for all the bars. if you want to see a drawn line in the history. for this you have to use a array.
That's great, worked a treat. Thanks!

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
Hi,
I'm slowly learning about coding MQL4, and while I'm getting to grips with modifying existing code I am still quite a bit off the mark on writing my own indicators from scratch.
To help learn, I'm trying to write a custom indicator ("Balanced") which draws a line using data from 2 other custom indicators ("Ind1" and "Ind2"). The drawn line data will be (Line 2 of Ind1 + Line 2 of Ind2) / 2
So far I have the following code, which doesn't throw up any errors but it doesn't actually draw anything. I know it is far from perfect, but it is all good practice for learning so any hints would be very much appreciated!
Many thanks