|
Cocos Wave Strategy
#417895
02/19/13 11:41
02/19/13 11:41
|
Joined: Nov 2012
Posts: 209
SFF
OP
Member
|
OP
Member
Joined: Nov 2012
Posts: 209
|
Hi, I just made this code but it is not working correctly. Where is wrong? The strategy is based on this. http://www.forexisbiz.com/showthread.php/1530-Lets-try-this-cocos-wave
var GSMOOTH(var price_,vars arr,var alfa){
var ret = pow(alfa,4)*price_ + 4*(1-alfa)*arr[0+1] - 6*pow(1-alfa,2)*arr[0+2] + 4*pow(1-alfa,3)*arr[0+3] - pow(1-alfa,4)*arr[0+4];
return (ret);
}
var getAlfa(var p){
var pis = 3.1415926535;
var w = 2*pis/p;
var beta = (1 - cos(w))/(pow(1.414,2.0/3) - 1);
var alfa = -beta + sqrt(beta*beta + 2*beta);
return (alfa);
}
function run(){
set(TICKS);
int Fast=13;
int Slow=26;
int Signal=3;
vars Fastalfa=series(getAlfa(Fast));
vars Slowalfa=series(getAlfa(Slow));
vars Signalalfa=series(getAlfa(Signal));
vars Close=series(priceClose());
vars ma = series();
ma = series(GSMOOTH(Close[0],ma,Slowalfa[0]));
vars maf = series();
maf=series(GSMOOTH(Close[0],maf,Fastalfa[0]));
vars mains=series(ma[0]-maf[0]);
vars signal = series();
signal=series(GSMOOTH(mains[0],signal,Signalalfa[0]));
vars tmp=series(mains[0]-signal[0]);
int MA_Period=80;
var Deviation=0.1;
int sMA, upper, down;
vars sMA = series(SMA(series(priceClose(20)),MA_Period));
var upper = sMA[0] * (1+Deviation/100);
var down = sMA[0] * (1-Deviation/100);
vars Close = series(priceClose());
TakeProfit = 25*PIP;
if(crossOver(Close,upper)) {
Stop = down - 10*PIP;
enterLong();
}
if(crossUnder(Close,down)) {
Stop = upper + 10*PIP;
enterShort();
}
}
Last edited by SFF; 02/20/13 10:33.
|
|
|
Re: Cocos Wave Strategy
[Re: jcl]
#417974
02/19/13 23:23
02/19/13 23:23
|
Joined: Nov 2012
Posts: 209
SFF
OP
Member
|
OP
Member
Joined: Nov 2012
Posts: 209
|
It is just simple as the image. We enter a trade when closeprice cross over/under a shifted envelope with a filter GMACD. Exit is TP 25 pips and SL is when closeprice +/- 10 pips a under or upper band. I have the other exit too, it is dynamical exit, when a buy condition happens short closes and reverse.
I hope this helps.
Last edited by SFF; 02/19/13 23:32.
|
|
|
Re: Cocos Wave Strategy
[Re: jcl]
#418002
02/20/13 09:45
02/20/13 09:45
|
Joined: Nov 2012
Posts: 209
SFF
OP
Member
|
OP
Member
Joined: Nov 2012
Posts: 209
|
I misunderstand about GMACD, it is a bar not a line, so when it is up it only enters long break out signal.
This is a SL code but I think it is not working correctly from LOGFILE. if(priceClose == upper + 10*PIP) exitShort(); if(priceClose == down - 10*PIP) exitLong();
I expect this code is identical to crossUnder. "priceClose(1) > down && priceClose(0) < down"
Last edited by SFF; 02/20/13 09:48.
|
|
|
Re: Cocos Wave Strategy
[Re: jcl]
#418006
02/20/13 10:04
02/20/13 10:04
|
Joined: Nov 2012
Posts: 209
SFF
OP
Member
|
OP
Member
Joined: Nov 2012
Posts: 209
|
Great, Thank you. I will try this new code and I will let you know if I have more problems.
The correct code was updated above.
Last edited by SFF; 02/20/13 10:34.
|
|
|
Re: Cocos Wave Strategy
[Re: SFF]
#418007
02/20/13 10:22
02/20/13 10:22
|
Joined: Nov 2012
Posts: 209
SFF
OP
Member
|
OP
Member
Joined: Nov 2012
Posts: 209
|
Here is a code without GMACD. By viewing a trade log It is correct. But a short trade should have been on 12/05/06 but not on the daily TF. Could you check log and chart and explain why.
function run(){
set(LOGFILE);
int MA_Period=80;
var Deviation=0.1;
int sMA, upper, down;
vars sMA = series(SMA(series(priceClose(20)),MA_Period));
var upper = sMA[0] * (1+Deviation/100);
var down = sMA[0] * (1-Deviation/100);
vars Close = series(priceClose());
TakeProfit = 25*PIP;
if(crossOver(Close,upper)) {
Stop = down - 10*PIP;
enterLong();
}
if(crossUnder(Close,down)) {
Stop = upper + 10*PIP;
enterShort();
}
}
|
|
|
|