2 registered members (7th_zorro, dr_panther),
1,193
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
MACD + Flat Market Detector
#418084
02/20/13 22:34
02/20/13 22:34
|
Joined: Nov 2012
Posts: 209
SFF
OP
Member
|
OP
Member
Joined: Nov 2012
Posts: 209
|
I tried to convert this free indicator and my current code is below. Zorro says that "Error in 'line 22: 'FextMapBuffer6' undeclared identifier". Why this happen? Thanks in advance. The original indicator. http://www.pointzero-trading.com/FreeMetatraderDownloads/view/5
function run(){
int FastEMA = 9;
int SlowEMA = 26;
int AvPeriod = 400;
var Gamma = 0.75;
vars med = series(MedPrice());
vars median = series(MACD(med,FastEMA,SlowEMA,4));
vars FextMapBuffer6 = series(median[0] - median[1]);
vars FextMapBuffer5 = series(abs(FextMapBuffer6[0]));
var flat = EMA(FextMapBuffer5,AvPeriod);
vars FextMapBuffer3 = series((flat * Gamma));
vars FextMapBuffer4 = series(0 - (flat * Gamma));
}
if(FextMapBuffer6 > FextMapBuffer3)
exitShort();
enterLong();
if(FextMapBuffer6 < FextMapBuffer4)
exitLong();
enterShort();
}
|
|
|
Re: MACD + Flat Market Detector
[Re: SFF]
#418092
02/21/13 06:55
02/21/13 06:55
|
Joined: Sep 2012
Posts: 99
TankWolf
Junior Member
|
Junior Member
Joined: Sep 2012
Posts: 99
|
Actually all it was from what I can tell is some wrong brackets in your code. function run(){ LookBack = 500; int FastEMA = 9; int SlowEMA = 26; int AvPeriod = 400; var Gamma = 0.75;
vars med = series(MedPrice());
vars median = series(MACD(med,FastEMA,SlowEMA,4)); vars FextMapBuffer6 = series(median[0] - median[1]); vars FextMapBuffer5 = series(abs(FextMapBuffer6[0]));
var flat = EMA(FextMapBuffer5,AvPeriod); vars FextMapBuffer3 = series((flat * Gamma)); vars FextMapBuffer4 = series(0 - (flat * Gamma));
if(FextMapBuffer6 > FextMapBuffer3) { exitShort(); enterLong(); } if(FextMapBuffer6 < FextMapBuffer4) { exitLong(); enterShort(); } }
Updated code above. Though I do have one question for jcl, when we compare series for our entry codes do we use the pointers (FextMapBuffer) to the series or the last variable in our series in this case (FextMapBuffer6[0])?
|
|
|
Re: MACD + Flat Market Detector
[Re: SFF]
#418097
02/21/13 08:16
02/21/13 08:16
|
Joined: Sep 2012
Posts: 99
TankWolf
Junior Member
|
Junior Member
Joined: Sep 2012
Posts: 99
|
Well in the interests of the community I had a go at creating the indicator & it looks right but you should all test it probably before relying on it & by all means please make changes where you see necessary. function run(){ set(PLOTPRICE+PLOTNOW); BarPeriod = 15; LookBack = 500; StartDate = 20120201; NumDays = 1; int FastEMA = 9; int SlowEMA = 26; int AvPeriod = 400; var Gamma = 0.75;
vars med = series(MedPrice());
vars median = series(MACD(med,FastEMA,SlowEMA,4)); vars FextMapBuffer6 = series(median[0] - median[1]); vars FextMapBuffer5 = series(abs(FextMapBuffer6[0])); vars FextMapBuffer1 = series(0); vars FextMapBuffer2 = series(0);
var flat = EMA(FextMapBuffer5,AvPeriod); vars FextMapBuffer3 = series((flat * Gamma)); vars FextMapBuffer4 = series(0 - (flat * Gamma));
int NewWindow = 0; plot("NewWindow",NewWindow,NEW,BLACK); if(FextMapBuffer6[0] < FextMapBuffer6[1]) { FextMapBuffer2[0] = FextMapBuffer6[0]; FextMapBuffer1[0] = 0; plot("FextMapBuffer2",FextMapBuffer2[0],BARS,RED); } else if(FextMapBuffer6[0] > FextMapBuffer6[1]) { FextMapBuffer1[0] = FextMapBuffer6[0]; FextMapBuffer2[0] = 0; plot("FextMapBuffer1",FextMapBuffer1[0],BARS,BLUE); } plot("FextMapBuffer3",FextMapBuffer3[0],0,BLACK); plot("FextMapBuffer4",FextMapBuffer4[0],0,BLACK); }
Enjoy.
Last edited by TankWolf; 02/21/13 08:21. Reason: Edited Code
|
|
|
Re: MACD + Flat Market Detector
[Re: TankWolf]
#418099
02/21/13 08:39
02/21/13 08:39
|
Joined: Nov 2012
Posts: 209
SFF
OP
Member
|
OP
Member
Joined: Nov 2012
Posts: 209
|
Good script.Thanks.
I check a plot again with your script and it looks that by comparing in Zorro and MT4 chart they are not same.
Please compare MT4 daily chart for EUR/USD with Zorro plot on 2012/09. You know what I mean.
Last edited by SFF; 02/21/13 08:41.
|
|
|
Re: MACD + Flat Market Detector
[Re: TankWolf]
#418101
02/21/13 08:45
02/21/13 08:45
|
Joined: Sep 2012
Posts: 99
TankWolf
Junior Member
|
Junior Member
Joined: Sep 2012
Posts: 99
|
Lol I just read the description again... Description
This is the standard MACD indicator drawing two flat lines instead of a signal line. It allows you to detect and trade flat/range-bound markets. It is nothing fancy and was only created to run some test, but it might be useful to you.
By the sounds of this its just MACD with these flat lines drawn Ive reattached code to show the difference please note Ive just got all the bars red on normal MACD not sure how you change them with the built in indicator to show blue for accelerating. function run(){ set(PLOTPRICE+PLOTNOW); BarPeriod = 15; LookBack = 500; StartDate = 20120201; NumDays = 1; int FastEMA = 9; int SlowEMA = 26; int AvPeriod = 400; var Gamma = 0.75;
vars med = series(MedPrice());
vars median = series(MACD(med,FastEMA,SlowEMA,4)); vars MACDHistory = series(rMACDHist); vars FextMapBuffer6 = series(median[0] - median[1]); vars FextMapBuffer5 = series(abs(FextMapBuffer6[0])); vars FextMapBuffer1 = series(0); vars FextMapBuffer2 = series(0);
var flat = EMA(FextMapBuffer5,AvPeriod); vars FextMapBuffer3 = series((flat * Gamma)); vars FextMapBuffer4 = series(0 - (flat * Gamma));
int NewWindow2 = 0; plot("NewWindow2",NewWindow2,NEW,BLACK); plot("MACD",MACDHistory[0],BARS,RED); plot("FextMapBuffer3",FextMapBuffer3[0],0,BLACK); plot("FextMapBuffer4",FextMapBuffer4[0],0,BLACK);
int NewWindow = 0; plot("NewWindow",NewWindow,NEW,BLACK); if(FextMapBuffer6[0] < FextMapBuffer6[1]) { FextMapBuffer2[0] = FextMapBuffer6[0]; FextMapBuffer1[0] = 0; plot("FextMapBuffer2",FextMapBuffer2[0],BARS,RED); } else if(FextMapBuffer6[0] > FextMapBuffer6[1]) { FextMapBuffer1[0] = FextMapBuffer6[0]; FextMapBuffer2[0] = 0; plot("FextMapBuffer1",FextMapBuffer1[0],BARS,BLUE); } plot("FextMapBuffer3",FextMapBuffer3[0],0,BLACK); plot("FextMapBuffer4",FextMapBuffer4[0],0,BLACK); }
|
|
|
Re: MACD + Flat Market Detector
[Re: SFF]
#418110
02/21/13 10:23
02/21/13 10:23
|
Joined: Sep 2012
Posts: 99
TankWolf
Junior Member
|
Junior Member
Joined: Sep 2012
Posts: 99
|
Been playing some more there was still some errors Ive got it close but it still doesnt look exact though I think that may be because of the way the daily bars are grouped for FXCM and Zorro differently. function run(){ set(PLOTPRICE+PLOTNOW); BarPeriod = 1440; LookBack = 500; StartDate = 20120901; NumDays = 100; int FastEMA = 9; int SlowEMA = 26; int AvPeriod = 400; var Gamma = 0.75;
vars FextMapBuffer1 = series(0); vars FextMapBuffer2 = series(0);
//Median vars Price = series(price()); vars MedianPrice = series(SMA(Price,500));
vars median = series(MACD(MedianPrice,FastEMA,SlowEMA,4)); vars median1 = series(MACD(MedianPrice+1,FastEMA,SlowEMA,4));
//Difference vars FextMapBuffer6 = series(median[0] - median1[0]);
//Save current absoulte value vars FextMapBuffer5 = series(abs(FextMapBuffer6[0]));
//Flat lines vars flat = series(EMA(FextMapBuffer5,AvPeriod)); vars FextMapBuffer3 = series((flat[0] * Gamma)); vars FextMapBuffer4 = series(0 - (flat[0] * Gamma));
int NewWindow = 0; plot("NewWindow",NewWindow,NEW,BLACK);
//Deceleration if(FextMapBuffer6[0] < FextMapBuffer6[1]) { FextMapBuffer2[0] = FextMapBuffer6[0]; FextMapBuffer1[0] = 0; plot("FextMapBuffer2",FextMapBuffer2[0],BARS,RED); } //Acceleration else if(FextMapBuffer6[0] > FextMapBuffer6[1]) { FextMapBuffer1[0] = FextMapBuffer6[0]; FextMapBuffer2[0] = 0; plot("FextMapBuffer1",FextMapBuffer1[0],BARS,BLUE); } plot("FextMapBuffer3",FextMapBuffer3[0],0,BLACK); plot("FextMapBuffer4",FextMapBuffer4[0],0,BLACK); }
|
|
|
|