x Michelangelo
questo ad esempio era stato fatto ad agosto 2012..sembrava promettente..tutto bello ripieno di indicatori(adx,vydia,repulse,regressione lineare,macd,mfi,piste cicliche..etc..) e patapum...
//___________________agosto 2012____________________//
Var: x(3.85),y(9); // 4...19 3.5....9 3.5 --> 3.85
Var: MEDIAA,MEDIAB,MEDIAC,OP3B,MEDIAflusso,expflusso;
Var: MEDIAlong,MEDIAshort,MACDlong,MACDlongSIGNAL,MACDshort,MACDshortSIGNAL;
Var: DD0a,PVa,NVa,OP1a,EX0a,EX1a,m20;
Var: STOCX,MSX;
Var: MYX,MYYX,OPYX,BBACX,HHX,MX,MMX,OAAX,M1X,MM1X,OAA1X;
Var: ATDXlong,ATDXshort;
Var: CONDIZIONIlong,CONDIZIONIshort,condizione1,condizione2, CondTempo;
var: media20,MioEXPSMOOTH11,pista,va3,ma,sommapositive,sommapositive2,sommanegative,sommanegative2,volpos,volneg,sommaok;
Var: expo9,cumpos,cumneg,totpos,totneg,cbpos1,cbneg1;
// var takeprofit
Var: ingresso1,uscita,prox2,prox4;
// adx
Var: ADXA,ADXB,ADXH,NDX40,PDX40;
Var: dayss;
// vydia
Var: cv2,cv3,cv5,cv5y,CC,CC11,CC22,CC3,KK,ZZ,K,alpha,alphaK,ZK,Vydia;
// repulse
Var: Periods(54),Periods1(29),Periods2(79); //54 29 84 84-->79
Var: LO,HI,LO1,HI1,cv7,cv8,cv9,cv100,openpreced,openpreced1,periodsIndietro,periodsIndietro1,Zona1, Zona2;
Var: AA,AA1,AA2,AA3,AA4,AA5,BB,BB1,BB2,BB3,BB4,BB5,CC1,CC2,Rep;
Var: AAB,AAB1,AAB2,AAB3,AAB4,AAB5,BBB,BBB1,BBB2,BBB3,BBB4,BBB5,CC1A,CC2A,Rep1;
Var: LO2,HI2,Rep2,openpreced2,periodsIndietro2,AAC,AAC1,AAC2,AAC3,AAC4,AAC5,BBC,BBC1,BBC2,BBC3,BBC4,BBC5;
Var: CC1B,CC2B,cond1,cond2;
// killer
Var: media,filtro_1,killer;
// media lungo
var: MEDIA500, EMEDIA500, ATTESA_LG, ATTESA_SH;
var: tipo_take,Tipo_Ingresso;
var: flat(1),prec_flat(1),evento;
Var: Percent_Gain, ValTP; // Variabili per il Take Profit
Var: Percent_Soglia,Percent_Take,ValMax,ValMin,CheckL,CheckS,Soglia,SogliaStop; // Variabili per il Trailing Profit
Var: PercentRisk,ValSL; // Variabili per lo Stop Loss
Var:dif,difp;
var: massimogiornoprima,minimogiornoprima,divino3,divino4,divino5,divino6;
var: divino1,divino2,prox6;
massimogiornoprima = eod.h[1];
minimogiornoprima =eod.l[1];
divino3= minimogiornoprima+(161.8*(massimogiornoprima-minimogiornoprima))/100;
divino1= minimogiornoprima+(117.39*(massimogiornoprima-minimogiornoprima))/100;
divino5= minimogiornoprima+ ((117.38*(massimogiornoprima-minimogiornoprima))/100)/4.8 ;//117,38
divino4= massimogiornoprima-(161.8*(massimogiornoprima-minimogiornoprima))/100;
divino2= massimogiornoprima-(117.39*(massimogiornoprima-minimogiornoprima))/100; ///117,39
divino6= massimogiornoprima- ((117.38*(massimogiornoprima-minimogiornoprima))/100)/4.8 ;
dif=(close[1]-open[2]);
difp=(dif/close[2]*100);
prox6=addperc(divino2,-2.2);
////////// MEDIA DI LUNGO ///////////////////
MEDIA500 = MOV(C,103,e); // 100 103
EMEDIA500 = MEDIA500 - MEDIA500[1];
if (EMEDIA500 > 0) then
ATTESA_LG = 50 + (EMEDIA500*50)/0.0224648;
ATTESA_SH = 50 - (EMEDIA500*50)/0.0224648;
else if (EMEDIA500<0) then
ATTESA_SH = 50+(EMEDIA500*50)/-0.0205002;
ATTESA_LG = 50-(EMEDIA500*50)/-0.0205002;
else if (EMEDIA500=0) then
ATTESA_SH = 50; //
ATTESA_LG = 50; //
endif;endif;endif;
//////////////////////////////////////////////////////
///// KILLER
killer=regrlin(c,54,r); // 54 ok
media=mov(killer,54,s); // 54 ok
filtro_1=expsmooth(killer,21); //20 21 ok
///////////////////////////////////////
/////////////////////// Vydia ///////////////////////////
cv2=constval(2);
cv3=constval(3);
cv5=constval(5);
cv5y=5*y;
CC=OP(cv2,Open,mul);
CC11=OP(cv3,Close,mul);
CC22=OP(CC,CC11,add);
CC3=OP(CC22,cv5,divis);
KK=stddev(CC3,y);
ZZ=stddev(CC3,cv5y);
K=KK/ZZ;
alpha=(2/(x+1)); // (2/(x+1) ok
alphak=(alpha*K);
ZK=(1-alphak);
Vydia=(CC3*alphak)+(Vydia[1]*ZK);
//////////////////////////////////////////////
cv7=constval(2);
cv8=constval(3);
cv9=constval(5);
cv100=constval(100);
LO=llv(L,Periods);
HI=hhv(H,Periods);
periodsIndietro=periods-1;
OpenPreced=mov(O,1,S,periodsindietro);
AA1=op(cv8,C,mul);
AA2=op(cv7,LO,mul);
AA3=op(AA1,AA2,sub);
AA4=op(AA3,OpenPreced,sub);
AA5=op(AA4,Close,divis);
AA=op(cv100,AA5,mul);
BB1=op(cv7,HI,mul);
BB2=op(OpenPreced,BB1,add);
BB3=op(cv8,C,mul);
BB4=op(BB2,BB3,sub);
BB5=op(BB4,C,divis);
BB=op(cv100,BB5,mul);
CC1=expsmooth(AA,5*Periods);
CC2=expsmooth(BB,5*Periods);
Rep=op(CC1,CC2,sub);
//REPULSE-1//
LO1=llv(L,Periods1);
HI1=hhv(H,Periods1);
periodsIndietro1=periods1-1;
OpenPreced1=mov(O,1,S,periodsindietro1);
AAB1=op(cv8,C,mul);
AAB2=op(cv7,LO1,mul);
AAB3=op(AAB1,AAB2,sub);
AAB4=op(AAB3,OpenPreced1,sub);
AAB5=op(AAB4,Close,divis);
AAB=op(cv100,AAB5,mul);
BBB1=op(cv7,HI1,mul);
BBB2=op(OpenPreced1,BBB1,add);
BBB3=op(cv8,C,mul);
BBB4=op(BBB2,BBB3,sub);
BBB5=op(BBB4,C,divis);
BBB=op(cv100,BBB5,mul);
CC1A=expsmooth(AAB,5*Periods1);
CC2A=expsmooth(BBB,5*Periods1);
Rep1=op(CC1A,CC2A,sub);
LO2=llv(L,Periods2);
HI2=hhv(H,Periods2);
periodsIndietro2=periods2-1;
OpenPreced2=mov(O,1,S,periodsindietro2);
AAC1=op(cv8,C,mul);
AAC2=op(cv7,LO2,mul);
AAC3=op(AAC1,AAC2,sub);
AAC4=op(AAC3,OpenPreced2,sub);
AAC5=op(AAC4,Close,divis);
AAC =op(cv100,AAC5,mul);
BBC1=op(cv7,HI2,mul);
BBC2=op(OpenPreced2,BBC1,add);
BBC3=op(cv8,C,mul);
BBC4=op(BBC2,BBC3,sub);
BBC5=op(BBC4,C,divis);
BBC=op(cv100,BBC5,mul);
CC1B=expsmooth(AAC,5*Periods2);
CC2B=expsmooth(BBC,5*Periods2);
Rep2=op(CC1B,CC2B,sub);
NDX40=DMNDX(C,18); /// 18
PDX40=DMPDX(C,18); /// 18
ma=hhv(h,5); // 5 ok
MEDIAlong =MOV(C,11,e); // 11 ok
MEDIAshort =MOV(C,20,e); // 20 ok
MEDIAA=MOV(C,58,s); // 74 55 58 ok ///
MEDIAB=MOV(C,27,s); // 25s 18 27
OP3B =OP(MEDIAB,MEDIAA,2); // ok
MEDIAC=MOV(OP3B,2,s); //2, e,s ok
MACDlong =MACD(C,9,48); // da 8 a 9
MACDlongSIGNAL=EXPSMOOTH(MACDlong,58); //da 55 a 58
MACDshort =MACD(C,4,48); // 4,48
MACDshortSIGNAL=EXPSMOOTH(MACDshort,62);// 62
ATDXlong =ATR(C,3); // 3
ADXA=DMADX(c,45);
ADXB=DMADX(c,68);// 58 67
ADXH=DMADX(C,40); //40
HHX=MFI (C,46,0); // ok
MX=MOV(HHX,14,s); // 14
MMX=MOV(HHX,21,s); // 21
OAAX=OP(MX,MMX,ADD);
M1X=MOV(OAAX,1,e);
MM1X =MOV(OAAX,2,e);
OAA1X=OP(M1X,MM1X,ADD);
mediaflusso= MOV(C,7,e); // ok
expflusso=EXPSMOOTH(mediaflusso,6); // ok
EX0a =WILDER(mediaflusso,5); // ok
EX1a =WILDER(EX0a,5); // ok
M20 =MOV(EX1a,18,e); // ok
PISTA=PISTACICLICA(M20,46); // ok
VA3 =VARIAZ(PISTA,V,PREC);
IF expflusso<expflusso[1] THEN
cumneg=cumneg+V;
volneg=V;
volpos=0;
cumpos=0;
else
cumpos=cumpos+V;
cumneg=0;
volpos=V;
volneg=0;
endif;
sommapositive=sum(volpos,100);
sommanegative= sum(volneg,100);
sommapositive2=(sum(sommapositive,34))/34; // da 34 34
sommanegative2= (sum(sommanegative,18))/18; //24 24
if cumneg=0 and cumneg[1]>=ATTESA_SH*8000 then // da 18000 8000 /////////
totneg=1;
endif;
if totneg=1 then
cbneg1=cbneg1+1;
endif;
if cbneg1>=ATTESA_SH*0.41 then // da 0.41 0.39?
condizione1=1 ;
else
condizione1=0;
endif;
if cumpos=0 and cumpos[1]>=ATTESA_LG*610000 then // da 620000
totpos=1;
endif;
if totpos=1 then
cbpos1=cbpos1+1;
endif;
if cbpos1>=ATTESA_LG*0.0018 then // 0.48
condizione2=1 ;
else
condizione2=0;
endif;
if sommanegative<ATTESA_LG*319000 and sommapositive>ATTESA_SH*207000 then //322000 319000 214000
sommaok=1;
else
sommaok=0;
endif;
if (DayOfWeek=wednesday and T>1620) or (DayOfWeek=friday and T>1620) then
dayss = 1;
else
dayss = 0;
endif;
prox2=addperc(uscita,1.3); ///// 2.4 2.3 ok ////////
prox4=addperc(uscita,2.1); //1.9,2.1
////////////////////////////// CONDIZIONI /////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
if PositionDir = 0 and evento = 0 then flat = 1;endif;
evento = 0;
////////////////// CODICE DEL TAKE PROFIT ///////////////////////
if (PositionDir = 1) then
ValTP = PositionValue + ((PositionValue * Percent_Gain)/100); //Take Profit per il LONG
if (H>ValTP) and (evento = 0) then
EXITLONG(nextBAR, ATCLOSE);
prec_flat = flat;
flat = 1;
endif;
endif;
if (PositionDir = -1) then
ValTP = PositionValue - ((PositionValue * Percent_Gain)/100); //Take Profit per lo SHORT
if (L<ValTP) and (evento = 0) then
EXITSHORT(nextBAR, ATCLOSE);
prec_flat = flat;
flat = 1;
endif;
endif;
{ /////////////////////////////////////////////////////// }
///////////// CODICE TRAILING PROFIT /////////////////////////
if (PositionDir = 0) then
ValMax = 0;
ValMin = 10000;
checkL = 0;
checkS = 0;
endif;
if (PositionDir = 1) and (evento = 0) then ////// Trailing Profit LONG ///////////
Soglia = PositionValue + ((PositionValue * Percent_Soglia)/100);
ValMin = 10000;
checkS = 0;
if (H > ValMax) then ValMax = H;endif;
SogliaStop = ValMax - ((ValMax * Percent_Take)/100);
if (checkL = 0) and (H > Soglia) then checkL = 1;endif;
if (checkL = 1) and (L < SogliaStop) then
ExitLong(nextBar, AtClose);
prec_flat = flat;
flat = 1;
endif;
endif;
if (PositionDir = -1) and (evento = 0) then ////// Trailing Profit SHORT ///////////
Soglia = PositionValue - ((PositionValue * Percent_soglia)/100);
valMax = 0;
checkL = 0;
if (L < ValMin) then ValMin = L;endif;
SogliaStop = ValMin + ((ValMin * Percent_Take)/100);
if (checkS = 0) and (L < Soglia) then checkS = 1;endif;
if (checkS = 1) and (H > SogliaStop) then
ExitShort(nextBAR, ATCLOSE);
prec_flat = flat;
flat = 1;
endif;
endif;
//////////////////////// codice dello STOP LOSS //////////////////////////////
if (PositionDir = 1) then ValSL = PositionValue - ((PositionValue * PercentRisk)/100);endif;
if (PositionDir = -1) then ValSL = PositionValue + ((PositionValue * PercentRisk)/100);endif;
if (PositionDir = 1) and (L<ValSL) and (evento = 0) then // STOP LOSS per il LONG
ExitLong(nextBAR, ATCLOSE);
prec_flat = flat;
flat = 1;
endif;
if (PositionDir = -1) and (H>ValSL) and (evento = 0) then // STOP LOSS per lo SHORT
ExitShort(nextBAR, ATCLOSE);
prec_flat = flat;
flat = 1;
endif;
///////////////////////// Ingresso x prox /////////////////////////
ingresso1=positionvalue;
if ingresso1=0 and ingresso1[1]<>0 then uscita=close;endif;
////////////////////////////////////////////////////////////
if (T >= 0920) and (T <= 1716)then //0920 1715
evento = 0;
cond1= OAA1X<OAA1X[1] and OP3B<MEDIAC AND MACDshort<MACDshortSIGNAL and sommapositive2<sommapositive2[1] and adxh<ATTESA_SH*0.35 // SH*0.35
and sommaok=0 AND MEDIAshort>C AND C<Vydia and condizione2=1 and barsince(va3<va3[1])>=4 and MACDshortSIGNAL>=-0.017; ////// MACDshortSIGNAL>=-0.022 0.0017 va3[1])>=4
cond2= OAA1X<OAA1X[1] and OP3B<MEDIAC AND C<Vydia AND MACDshort<MACDshortSIGNAL and sommaok=0 AND MEDIAshort>C
and barsince(va3<va3[1])>=5 and MACDshortSIGNAL >=-0.021 and NDX40-NDX40[1]>-1.3; /////// NDX40-NDX40[1]>-1.1 1.3
///////////////////////////// ENTERLONG ///////////////////////////////////////////////////
IF MACDlong>MACDlongSIGNAL {and difp<0.9} AND MEDIAlong<C and ADXA>ADXA[1] AND C>Vydia and condizione1=1 and ATDXlong>0.0143 and adxh>ATTESA_LG*0.1920
and rep1>rep1[1] and MACDlongSIGNAL<=0.045 THEN // MACDlongSIGNAL>=0.145
ENTERLONG (nextBAR,ATclose);
cbneg1=0;totpos=0;totneg=0;Tipo_Ingresso = 1; //////
if (flat<>0) then //////
prec_flat = flat;
flat = 0;
evento = 1;
endif;
endif;
if totneg=0 then
IF OAA1X>OAA1X[1] {and difp<0.2} and OP3B>MEDIAC and ADXA>ADXA[1] and adxh>ATTESA_LG*0.2850 //10,11 ****
and C>Vydia and rep1>rep1[1] AND ATDXlong>0.0143 and MACDlongSIGNAL<= 0.0665 THEN
ENTERLONG (nextBAR,ATclose);
cbneg1=0;totpos=0;totneg=0;Tipo_Ingresso = 2;
if (flat<>0) then
prec_flat = flat;
flat = 0;
evento = 1;
endif;
endif;ENDIF;
///////////////////////////// ENTERSHORT ///////////////////////////////////////////////////////
if cond1 and barsince(rep1<rep)>1 {and difp<0.9} and c<prox4 and rep1<rep1[1] and dayss=0 then //*****
ENTERSHORT(nextBAR,ATclose);
cbpos1=0;totpos=0;totneg=0;condizione2=0;Tipo_Ingresso = 3;
if (flat <> -1) then
prec_flat = flat;
flat = -1;
evento = 1;
endif;
ENDIF;
if totpos=0 then
IF cond2 and barsince(rep1<rep)>1 and difp<0.3 and c<prox4 and barsince(rep2>2.43)>1 and rep1<rep1[1] and dayss=0 THEN // da 3.0 a 2.99 e inserito rep1<rep1[1]
ENTERSHORT(nextBAR,ATclose);cbpos1=0;totpos=0;totneg=0;Tipo_Ingresso = 4;
if (flat <> -1) then ///****** 0.3
prec_flat = flat;
flat = -1;
evento = 1;
endif;
ENDIF;ENDIF;
////////////////////////// Rientro Long e Short /////////////////////////////////////////////////////////////////////
if positiondir=0 and adxb>adxb[1] {and (h[1]-l[1])>=40} and c>prox6 and barsince(rep1<3.10)>1 and rep1<rep1[1] and rep2<rep1 and dayss=0 then // rep1<0.80
entershort(nextbar,atclose);
Tipo_Ingresso = 5; //***
if (flat <> -1) then
prec_flat = flat;
flat = -1;
evento = 1;
endif;
endif;
if positiondir=1 and adxb>adxb[1] {and (h[1]-l[1])>=40}and c>prox6 and c<prox4 and barsince(rep1<3.10)>1 and rep1<rep1[1] and rep2<rep1 and cond2 {and dayss=0} then // rep1<0.80
entershort(nextbar,atclose);
Tipo_Ingresso = 5;
if (flat <> -1) then //**
prec_flat = flat;
flat = -1;
evento = 1;
endif;
endif;
if positiondir=-1 and barsince(c=ma)=2 {and (h[1]-l[1])>=40 }and condizione1=1 then
enterlong(nextbar,atclose);
cbneg1=0;condizione1=0;totneg=0;Tipo_Ingresso = 6;
if (flat <> 0) then
prec_flat = flat;
flat = 0;
evento = 1;
endif;
endif;
if positiondir=0 and MACDlong>MACDlongSIGNAL {and (h[1]-l[1])>=40} and ADXA>ADXA[1] AND C>Vydia and condizione1=1 and ATDXlong>0.0143
{and adxh>ATTESA_LG*0.1920 and rep1>rep1[1]} and MACDlongSIGNAL>=0.15 and MACDlongSIGNAL<=0.154 THEN // MACDlongSIGNAL>=0.15 and MACDlongSIGNAL<=0.152
ENTERLONG (nextBAR,ATclose);
cbneg1=0;totpos=0;totneg=0;Tipo_Ingresso = 7;
if (flat <> 0) then
prec_flat = flat;
flat = 0;
evento = 1;
endif;
endif;
if positiondir=0 and(cond1 or cond2) {and (h[1]-l[1])>=40}and c>prox6 and MACDshortSIGNAL <=-0.019 and dayss=0 then // MACDshortSIGNAL <=-0.019
ENTERSHORT(nextBAR,ATclose);
cbpos1=0;totpos=0;totneg=0;Tipo_Ingresso = 8;
if (flat <> -1) then
prec_flat = flat;
flat = -1;
evento = 1;
endif;
endif;
/////////////////////// CHIUSURA TEMPO TRADING ////////////////////////
endif;
////////////////////////////////// EXIT-LONG & SHORT //////////////////////////////////////////
if positiondir=-1 and o>media and killer>filtro_1 and barsince(killer>killer[1])>=4 and difp>0.75 and C>Vydia then ///////// 0.8
exitshort(nextbar,atclose);
cbneg1=0;totpos=0;totneg=0;Tipo_Ingresso = 9;
prec_flat = flat;
flat = 1;
evento = 1;
endif;
if positiondir=1 and cond2 and rep<-0.22 and C<Vydia then if killer<filtro_1 and barsince(rep1<rep1[1])>5 // rep<-0.22 ///////
then exitlong(nextbar,atclose);
cbpos1=0;totpos=0;totneg=0;
prec_flat = flat;
flat = 1;
evento = 1;
endif;
endif;
/////////////////////////////////// PROFIT & LOSS ///////////////////////////////////////////////////
//installstoploss(inperc,2.79);
Tipo_Take = 1;
if (positiondir = 1) then // TP, SL, Trailing INIZIALI per il LONG
Percent_Gain = 6.2; // TP INIZIALE
PercentRisk = 3.30; //3.4 // SL INIZIALE
Percent_Soglia = 2.49; //2.5 ///// Soglie del Trailing Profit ///
Percent_Take = 2.3; //2.3
else
Percent_Gain = 7.1; //7.1 // TP, SL, Trailing INIZIALI per lo SHORT
PercentRisk = 3.30; // 3.4
Percent_Soglia = 2.49; //2.5
Percent_Take = 2.3; //2.3
endif;
if (prec_flat = 1) and barsince(ndx40>pdx40)>2 then // traduzione di: if positiondir=0 and barsince(ndx40>pdx40)>2 then installtakeprofit
Tipo_Take = 2;
if positionlong then Percent_Gain = 4.35; //4.4
else Percent_Gain = 3.78; //3.8
endif;
endif;
if (prec_flat = 1) and barsince(ndx40<pdx40)>2 then // traduzione di: if positiondir=0 and barsince(ndx40<pdx40)>2 then installtakeprofit
Tipo_Take = 3;
if positionlong then Percent_Gain = 6.05; //6.05
else Percent_Gain = 1.55; //1.5 1.65 ///////////////////
endif;
endif;
if (positionDir <> -1) and barsince(rep<-0.10)>2 and rep1<rep1[1] then PercentRisk = 1.80;endif;
if (positionDir <> -1) and sommanegative>15200000 then PercentRisk = 2.64;endif; // 2.64 sommanegative>ATTESA_lg*421000 19.000
//////////////////////////////////////////////////////
Zona1=CreateViewport(350,true,true);
//Zona2=CreateViewport(250,true,true);
PlotChart(ingresso1,Zona1,red,solid,2);
PlotChart(uscita,Zona1,blue,solid,2);
//PlotChart(Rep2,Zona1,black,solid,2);
//PlotChart(Tipo_Ingresso,Zona1,black,solid,2);
//PlotChart(0,Zona1,blue,solid,1);
Plotchart(divino3,0,green,dot,2);
Plotchart(divino1,0,green,solid,1);
Plotchart(divino5,0,blue,solid,1);
Plotchart(divino4,0,red,dot,2);
Plotchart(divino2,0,red,solid,1);
Plotchart(divino6,0,fuchsia,solid,1);