I don't see curly braces to determine what goes into the for loop and if test
It would be extremely rare for 2 MAs to be exactly the same value on a bar so check for a cross
ie
if((mova1[i]>mova2[i] && mova1[i+1]<mova2[i+1]) || (mova1[i]<mova2[i] && mova1[i+1]>mova2[i+1]))
If you just want a single horizontal line on your chart, create it in init and move it in your main code. If this is the case, you would need to count down in your loop so that the line is at the most recent cross, not the very first cross on the chart
- Exactly. The == operand. - MQL4 forum
- Or perhaps
bool isUp = mova1[i] > mova2[i]; bool wasUp = mova1[i+1] > mova2[i+1]; bool isCross = isUp != wasUp; if(isCross)
Not easy to do that :
//+------------------------------------------------------------------+
//| Maimaj.mq4 |
//| GGG Macon France |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 SpringGreen
#property indicator_color2 Red
#property indicator_color3 Lime
#property indicator_color4 Magenta
extern bool cross_on_ema_on_close = false;
extern int C= 55;
extern int L=100;
double CC[];
double LL[];
double hausse[];
double baisse[];
double cross_up, cross_down;
//+ ------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit() {
SetIndexBuffer(0,CC); SetIndexStyle(0,DRAW_LINE,0,2);
SetIndexBuffer (1,LL); SetIndexStyle(1,DRAW_LINE,0,2);
SetIndexBuffer(2,hausse); SetIndexStyle(2,DRAW_LINE,0,4);
SetIndexBuffer (3,baisse); SetIndexStyle(3,DRAW_LINE,0,4);
SetIndexEmptyValue(2,0.0);
SetIndexEmptyValue(3,0.0);
//---
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() {
int i,limit;
int countedbars= IndicatorCounted();
if (countedbars<0) return -1;
if(countedbars>0) countedbars--;
limit=Bars-countedbars;
for(i=0; i<limit; i++) CC[i]= iMA(NULL,0,C,0,1,0,i);
for(i=0; i<limit; i++) LL[i]= iMA(NULL,0,L,0,1,0,i);
//====================================================
i= Bars - 500;
if( countedbars > 500 ) i = Bars - countedbars -1;
while( i >= 0 )
{
if( CC[i+1]>=LL[i+1] && CC[i]<=LL[i] )
{
if( cross_on_ema_on_close ) cross_down = Close[i];
else cross_down = CC[i];
hausse[i+1]=0.0;
}
baisse[i] = cross_down ;
if( CC[i+1]<=LL[i+1] && CC[i]>=LL[i] )
{
if( cross_on_ema_on_close ) cross_up = Close[i];
else cross_up = CC[i];
baisse[i+1] = 0.0;
}
hausse[i] =cross_up;
if( CC[i] > LL[i] ) baisse [i] = 0.0;
if( CC[i] < LL[i] ) hausse[i] = 0.0;
//---
i--;
}
//--------
return(0);
}
//========================================================================
ffoorr:
Not easy to do that :
Monsieur ffoorr
One more and last favor, in the attached indicator please make the same lines as above when whatever two mas equal each other same like the above indicator. you can limit number of lines for each moving average via an external variable lets call it Linesnum .
thanks in advance
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
please i need your help because i have no coding background and want to code simple indicator.
i am trying to code an indicator that draws two emas(55,100)on the main chart and also draws horizontal line at the point when they equal each other (ema1=ema2).the horizontal line should start at that point till the end of the chart until a new point is generated.
the following code gives dozen of errors that is my miserable attempt.