- limit = Bars - counted_bars;You are mixing apples and oranges
for(int i=limit; i>=0; i--){
:
mainL1= iMACD(Symbol(),PERIOD_H1,Fast,Slow,Signal,PRICE_CLOSE,MODE_MAIN,i); Don't double post.
- limit = Bars - counted_bars;You are mixing apples and oranges
for(int i=limit; i>=0; i--){
:
mainL1= iMACD(Symbol(),PERIOD_H1,Fast,Slow,Signal,PRICE_CLOSE,MODE_MAIN,i); Don't double post.
Double topic removed.
I 've just try to 2loop, but still have problem with the value of "Bars".
Bars -> is the no. candle of M15 chart.
I find the iBars or iBarsShift but, i still can't find the right way.
:(
I 've just try to 2loop, but still have problem with the value of "Bars".
Bars -> is the no. candle of M15 chart.
I find the iBars or iBarsShift but, i still can't find the right way.
:(
Dear all,
I try to make the custom indicator about the cutting of MACD main & signal.
Rule is (with the upTrend):
1. With M15 the MACD main line cut up the signal line -> sign1.
2. Sign1 = true -> with H1, check the MACD on the up or down trend (uptrend when mainH1 cut up signalH1 & oppsite). -> sign2.
3. Sign2 = true -> insert an UParrow on the MACD line.
Now, I'm stick on the mud with access the value data of the H1. So, could you please show me the way to access the value data of MACD H1 ???
Thank you so much.
T.Son
My code:
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Lime
#property indicator_color3 LimeGreen
#property indicator_color4 Red
//---- input parameters
extern int Fast=12;
extern int Slow=26;
extern int Signal=9;
extern double tol=0.1;
//---- buffers
double MACDLineBuffer[];
double SignalLineBuffer[];
double SignalDown[];
double SignalUp[];
double macd1, macd2, sign1, sign2, mainL1, signL1, mainL2, signL2;
bool upTrend, downTrend;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorShortName("MACD ("+Fast+","+Slow+","+Signal+")");
//Main line
SetIndexStyle (0,DRAW_LINE);
SetIndexBuffer (0,MACDLineBuffer);
SetIndexDrawBegin (0,Slow);
SetIndexLabel (0,"MACD");
//Signal line
SetIndexStyle (1,DRAW_LINE,STYLE_DOT);
SetIndexBuffer (1,SignalLineBuffer);
SetIndexDrawBegin (1,Slow+Signal);
SetIndexLabel (1,"Signal");
//Arrow down
SetIndexStyle (2,DRAW_ARROW,0,1);
SetIndexArrow (2, 242);
SetIndexBuffer (2, SignalDown);
SetIndexDrawBegin (2,Slow+Signal);
SetIndexLabel (2,"SignalDOWN");
//Arrow up
SetIndexStyle (3,DRAW_ARROW,0,1);
SetIndexArrow (3,241);
SetIndexBuffer (3, SignalUp);
SetIndexDrawBegin (3,Slow+Signal);
SetIndexLabel (3,"SignalUP");
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars = IndicatorCounted();
if (counted_bars<0) return(-1);
if (counted_bars>0) counted_bars--;
limit = Bars - counted_bars;
for(int i=limit; i>=0; i--)
{
//Set MACD & Sign line
MACDLineBuffer[i]= iMACD(Symbol(),0,Fast,Slow,Signal,PRICE_CLOSE,0,i);
SignalLineBuffer[i]= iMACD(Symbol(),0,Fast,Slow,Signal,PRICE_CLOSE,1,i);
//Set macd & sign value at this timeflame
macd1= iMACD(Symbol(),0,Fast,Slow,Signal,PRICE_CLOSE,0,i);
sign1= iMACD(Symbol(),0,Fast,Slow,Signal,PRICE_CLOSE,MODE_SIGNAL,i);
macd2= iMACD(Symbol(),0,Fast,Slow,Signal,PRICE_CLOSE,0,i+1);
sign2= iMACD(Symbol(),0,Fast,Slow,Signal,PRICE_CLOSE,1,i+1);
//Set macd & sign value at larger timeflame
switch (Period())
{
case 15: //M15 -> check MACD & Sign value at H1
mainL1= iMACD(Symbol(),PERIOD_H1,Fast,Slow,Signal,PRICE_CLOSE,MODE_MAIN,i);
signL1= iMACD(Symbol(),PERIOD_H1,Fast,Slow,Signal,PRICE_CLOSE,MODE_SIGNAL,i);
mainL2= iMACD(Symbol(),PERIOD_H1,Fast,Slow,Signal,PRICE_CLOSE,MODE_MAIN,i+1);
signL2= iMACD(Symbol(),PERIOD_H1,Fast,Slow,Signal,PRICE_CLOSE,MODE_SIGNAL,i+1);
break;
case 60: //H1 -> check MACD & Sign value at H4
mainL1= iMACD(Symbol(),PERIOD_H4,Fast,Slow,Signal,PRICE_CLOSE,MODE_MAIN,i);
signL1= iMACD(Symbol(),PERIOD_H4,Fast,Slow,Signal,PRICE_CLOSE,MODE_SIGNAL,i);
mainL2= iMACD(Symbol(),PERIOD_H4,Fast,Slow,Signal,PRICE_CLOSE,MODE_MAIN,i+1);
signL2= iMACD(Symbol(),PERIOD_H4,Fast,Slow,Signal,PRICE_CLOSE,MODE_SIGNAL,i+1);
break;
case 240: //H4 -> check MACD & Sign value at D1
mainL1= iMACD(Symbol(),PERIOD_D1,Fast,Slow,Signal,PRICE_CLOSE,MODE_MAIN,i);
signL1= iMACD(Symbol(),PERIOD_D1,Fast,Slow,Signal,PRICE_CLOSE,MODE_SIGNAL,i);
mainL2= iMACD(Symbol(),PERIOD_D1,Fast,Slow,Signal,PRICE_CLOSE,MODE_MAIN,i+1);
signL2= iMACD(Symbol(),PERIOD_D1,Fast,Slow,Signal,PRICE_CLOSE,MODE_SIGNAL,i+1);
break;
default: //Defaults is use this timeflame
mainL1= iMACD(Symbol(),0,Fast,Slow,Signal,PRICE_CLOSE,MODE_MAIN,i);
signL1= iMACD(Symbol(),0,Fast,Slow,Signal,PRICE_CLOSE,MODE_SIGNAL,i);
mainL2= iMACD(Symbol(),0,Fast,Slow,Signal,PRICE_CLOSE,MODE_MAIN,i+1);
signL2= iMACD(Symbol(),0,Fast,Slow,Signal,PRICE_CLOSE,MODE_SIGNAL,i+1);
break;
}
if(mainL1 >signL1 && mainL2 <signL2)
{
upTrend =true;
downTrend =false;
}
if(mainL1 >signL1 && mainL2 <signL2)
{
upTrend =false;
downTrend =true;
}
//Insert UP ARROW
if(upTrend && macd1 >=sign1 && macd2 <sign2)
SignalUp[i]= MACDLineBuffer[i] -tol*MACDLineBuffer[i];
//Insert DOWN ARROW
if (downTrend && macd1 <=sign1 && macd2 >sign2)
SignalDown[i]= MACDLineBuffer[i] +tol*MACDLineBuffer[i];
}
//----
return(0);
}
//+------------------------------------------------------------------+
iTime(Symbol(),H1,i);
mrsunftu: I find the iBars or iBarsShift but, i still can't find the right way.
|
|
|
Tks you so much, & sorry cause I think, you underline to rematch for me the reson.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear all,
I try to make the custom indicator about the cutting of MACD main & signal.
Rule is (with the upTrend):
1. With M15 the MACD main line cut up the signal line -> sign1.
2. Sign1 = true -> with H1, check the MACD on the up or down trend (uptrend when mainH1 cut up signalH1 & oppsite). -> sign2.
3. Sign2 = true -> insert an UParrow on the MACD line.
Now, I'm stick on the mud with access the value data of the H1. So, could you please show me the way to access the value data of MACD H1 ???
Thank you so much.
T.Son
My code:
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Lime
#property indicator_color3 LimeGreen
#property indicator_color4 Red
//---- input parameters
extern int Fast=12;
extern int Slow=26;
extern int Signal=9;
extern double tol=0.1;
//---- buffers
double MACDLineBuffer[];
double SignalLineBuffer[];
double SignalDown[];
double SignalUp[];
double macd1, macd2, sign1, sign2, mainL1, signL1, mainL2, signL2;
bool upTrend, downTrend;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorShortName("MACD ("+Fast+","+Slow+","+Signal+")");
//Main line
SetIndexStyle (0,DRAW_LINE);
SetIndexBuffer (0,MACDLineBuffer);
SetIndexDrawBegin (0,Slow);
SetIndexLabel (0,"MACD");
//Signal line
SetIndexStyle (1,DRAW_LINE,STYLE_DOT);
SetIndexBuffer (1,SignalLineBuffer);
SetIndexDrawBegin (1,Slow+Signal);
SetIndexLabel (1,"Signal");
//Arrow down
SetIndexStyle (2,DRAW_ARROW,0,1);
SetIndexArrow (2, 242);
SetIndexBuffer (2, SignalDown);
SetIndexDrawBegin (2,Slow+Signal);
SetIndexLabel (2,"SignalDOWN");
//Arrow up
SetIndexStyle (3,DRAW_ARROW,0,1);
SetIndexArrow (3,241);
SetIndexBuffer (3, SignalUp);
SetIndexDrawBegin (3,Slow+Signal);
SetIndexLabel (3,"SignalUP");
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars = IndicatorCounted();
if (counted_bars<0) return(-1);
if (counted_bars>0) counted_bars--;
limit = Bars - counted_bars;
for(int i=limit; i>=0; i--)
{
//Set MACD & Sign line
MACDLineBuffer[i]= iMACD(Symbol(),0,Fast,Slow,Signal,PRICE_CLOSE,0,i);
SignalLineBuffer[i]= iMACD(Symbol(),0,Fast,Slow,Signal,PRICE_CLOSE,1,i);
//Set macd & sign value at this timeflame
macd1= iMACD(Symbol(),0,Fast,Slow,Signal,PRICE_CLOSE,0,i);
sign1= iMACD(Symbol(),0,Fast,Slow,Signal,PRICE_CLOSE,MODE_SIGNAL,i);
macd2= iMACD(Symbol(),0,Fast,Slow,Signal,PRICE_CLOSE,0,i+1);
sign2= iMACD(Symbol(),0,Fast,Slow,Signal,PRICE_CLOSE,1,i+1);
//Set macd & sign value at larger timeflame
switch (Period())
{
case 15: //M15 -> check MACD & Sign value at H1
mainL1= iMACD(Symbol(),PERIOD_H1,Fast,Slow,Signal,PRICE_CLOSE,MODE_MAIN,i);
signL1= iMACD(Symbol(),PERIOD_H1,Fast,Slow,Signal,PRICE_CLOSE,MODE_SIGNAL,i);
mainL2= iMACD(Symbol(),PERIOD_H1,Fast,Slow,Signal,PRICE_CLOSE,MODE_MAIN,i+1);
signL2= iMACD(Symbol(),PERIOD_H1,Fast,Slow,Signal,PRICE_CLOSE,MODE_SIGNAL,i+1);
break;
case 60: //H1 -> check MACD & Sign value at H4
mainL1= iMACD(Symbol(),PERIOD_H4,Fast,Slow,Signal,PRICE_CLOSE,MODE_MAIN,i);
signL1= iMACD(Symbol(),PERIOD_H4,Fast,Slow,Signal,PRICE_CLOSE,MODE_SIGNAL,i);
mainL2= iMACD(Symbol(),PERIOD_H4,Fast,Slow,Signal,PRICE_CLOSE,MODE_MAIN,i+1);
signL2= iMACD(Symbol(),PERIOD_H4,Fast,Slow,Signal,PRICE_CLOSE,MODE_SIGNAL,i+1);
break;
case 240: //H4 -> check MACD & Sign value at D1
mainL1= iMACD(Symbol(),PERIOD_D1,Fast,Slow,Signal,PRICE_CLOSE,MODE_MAIN,i);
signL1= iMACD(Symbol(),PERIOD_D1,Fast,Slow,Signal,PRICE_CLOSE,MODE_SIGNAL,i);
mainL2= iMACD(Symbol(),PERIOD_D1,Fast,Slow,Signal,PRICE_CLOSE,MODE_MAIN,i+1);
signL2= iMACD(Symbol(),PERIOD_D1,Fast,Slow,Signal,PRICE_CLOSE,MODE_SIGNAL,i+1);
break;
default: //Defaults is use this timeflame
mainL1= iMACD(Symbol(),0,Fast,Slow,Signal,PRICE_CLOSE,MODE_MAIN,i);
signL1= iMACD(Symbol(),0,Fast,Slow,Signal,PRICE_CLOSE,MODE_SIGNAL,i);
mainL2= iMACD(Symbol(),0,Fast,Slow,Signal,PRICE_CLOSE,MODE_MAIN,i+1);
signL2= iMACD(Symbol(),0,Fast,Slow,Signal,PRICE_CLOSE,MODE_SIGNAL,i+1);
break;
}
if(mainL1 >signL1 && mainL2 <signL2)
{
upTrend =true;
downTrend =false;
}
if(mainL1 >signL1 && mainL2 <signL2)
{
upTrend =false;
downTrend =true;
}
//Insert UP ARROW
if(upTrend && macd1 >=sign1 && macd2 <sign2)
SignalUp[i]= MACDLineBuffer[i] -tol*MACDLineBuffer[i];
//Insert DOWN ARROW
if (downTrend && macd1 <=sign1 && macd2 >sign2)
SignalDown[i]= MACDLineBuffer[i] +tol*MACDLineBuffer[i];
}
//----
return(0);
}
//+------------------------------------------------------------------+