x Emanuele..poi domani spiego meglio i difetti che ha
//_________________________Openmese_______________settembre 2018______________//
Var: fflat,lg,sh,contalg,contash,contaflat; // monitoraggio situazione flat / long / short
Var: Pr_Ingr(0), Max_Gain(0), Max_Gain_perc(0), actual(0); ///_____Actual=Gain
var: meseprec18,meseprec9,cambiatogiorno,contagiornoinessere,prova;
var: prox01,prox02;
Var: idlastop,contagain;
Var: contaoplong,contaopshort,meseprec66,optotal;
Var: rangeminimi,rangemassimi,percentualemese;
Var: formulaprimariaup,formulaprimariadown,codiceup,codiceup1,dayafter,tp1up,tp1down;
Var: formulaprimariaup1,formulaprimariadown1,codiceup2,codiceup3,tp1up1,tp1down1;
Var: contatp1up,contatp1down,meseprec,meseprec8,meseprec51;
Var: indzona1,indzona2,indzona3,indzona4;
rangeminimi=(((openm-lowm)/openm)*100);
rangemassimi=(((highm-openm)/openm)*100);
percentualemese=rangeminimi+rangemassimi;
/////////////////////////////////////////////////////////////////////////////////////////////
formulaPrimariaup=openm+(openm/100)*20;
formulaPrimariadown=openm-(openm/100)*20;
codiceup=op(formulaprimariaup,openm,sub);
codiceup1=op(codiceup,22,divis);
formulaPrimariaup1=openm+(openm/100)*10;
formulaPrimariadown1=openm-(openm/100)*10;
codiceup2=op(formulaprimariaup1,openm,sub);
codiceup3=op(codiceup2,22,divis);
if getday<>dayafter and IsFirstBarDay then tp1up=tp1up+codiceup1;endif;
if getday<>dayafter and IsFirstBarDay then tp1down=tp1down-codiceup1;endif;
if getmonth<>meseprec then tp1up=openm;endif;
if getmonth<>meseprec then tp1down=openm;endif;
/////////////////////////////////////////////////////////////////////////////////////////////////////
if getday<>dayafter and IsFirstBarDay then tp1up1=tp1up1+codiceup3;endif;
if getday<>dayafter and IsFirstBarDay then tp1down1=tp1down1-codiceup3;endif;
dayafter=getday;
if getmonth<>meseprec then tp1up1=openm;endif;
if getmonth<>meseprec then tp1down1=openm;endif;
meseprec=getmonth;
if c>tp1up1 then contatp1up=contatp1up+1;endif;
if c<tp1down1 then contatp1down=contatp1down+1;endif;
if getmonth<>meseprec8 then contatp1up=0;endif;
if getmonth<>meseprec8 then contatp1down=0;endif;
meseprec8=getmonth;
plotchart(tp1up, 0 , green, solid, 2);
plotchart(tp1up1, 0 , green, solid, 1);
plotchart(tp1down, 0 , red, solid, 2);
plotchart(tp1down1, 0 , red, solid, 1);
//////////////////////___CONTA_Situazione___///////////////////////////////////////////////
if positiondir=0 then fflat=1;endif; if positiondir<>0 then fflat=0;contaflat=0;endif; if fflat=1 and fflat[1]=1 then contaflat=(contaflat[1]+1);endif;
if positiondir=1 then lg=1;endif; if positiondir<>1 then lg=0;contalg=0;endif; if lg=1 and lg[1]=1 then contalg=(contalg[1]+1);endif;
if positiondir=-1 then sh=1;endif; if positiondir<>-1 then sh=0;contash=0;endif; if sh=1 and sh[1]=1 then contash=(contash[1]+1);endif;
//////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// ACTUAL /////////////////////////////////////////////////////
if Positionvalue<>0 then Pr_Ingr = positionValue;
if Positiondir=1 then if (C>Max_Gain) or (Max_Gain=0) then Max_Gain = C;
Max_Gain_perc = ((Max_Gain-Pr_ingr)*100)/Pr_Ingr;endif;
Actual = ((C-Pr_ingr)*100)/Pr_Ingr;
else
if (C<Max_Gain) or (Max_Gain=0) then Max_Gain = C;
Max_Gain_perc = ((Pr_ingr-Max_Gain)*100)/Pr_Ingr;endif;
Actual = ((Pr_ingr-C)*100)/Pr_Ingr;endif;
else Pr_ingr = 0;Max_Gain = 0; Actual = 0;endif;
/////////////////////////////////////////////////////////////////////////////
cambiatogiorno = GetValues(days, 1, prova, prova, prova, prova);
if getmonth<>meseprec18 then contagiornoinessere=0;endif;
if cambiatogiorno then contagiornoinessere=contagiornoinessere+1;endif;
meseprec18=getmonth;
prox01=addperc(openm,2);
prox02=addperc(openm,-2);
PlotChart(openM,0, gray, solid, 1);
PlotChart(prox01,0, aqua, dot, 1);
PlotChart(prox02,0, red, dot, 1);
DrawText(1,0 ,D ,openm , "OpenMese=",openm , red, 11, 1+3,Alright);
DrawText(2,0 ,D ,prox01 , "2 % sup.=",prox01 , aqua, 9, 1+3,Alright);
DrawText(3,0 ,D ,prox02 , "2 % inf.=",prox02 , aqua, 9, 1+3,Alright);
////////////////////////////////////////////////////////////////////////////////////////////////
if positiondir=1 and contalg=1 then contaoplong=contaoplong+1;endif;
if positiondir=-1 and contash=1 then contaopshort=contaopshort+1;endif;
if getmonth<>meseprec66 then contaoplong=0;endif;
if getmonth<>meseprec66 then contaopshort=0;endif;
meseprec66=getmonth;
optotal=contaoplong+contaopshort;
///////////////////////// Stop Loss //////////////////////////////////////////////////////////////////////////////
InstallStopLoss(INPERC, 3.00, "Stop");
plotchartNoZero(getstoploss, 0, red, solid, 2);
DrawText(4,0 , D,getstoploss , "sl",getstoploss , red, 15, 1+4,Alright);
////////////////////// Enter & Exit Long ///////////////////////////////////////////////////////////////////////////
if c>prox01 and contagiornoinessere<19 and contaflat>1 and contagain<3 then enterlong(nextbar,atopen);endif;
if positiondir=1 and contagiornoinessere>18 then exitlong(nextbar,atopen);endif;
if positiondir=1 and getmonth<>meseprec51 then exitlong(nextbar,atopen);endif;
if positiondir=1 and actual>4.0 and contaoplong<>1 then exitlong(nextbar,atopen);endif;
///////////////////// Enter & Exit Short //////////////////////////////////////////////////////////////////////////
if c<prox02 and contagiornoinessere<19 and contaflat>1 and contagain<3 then entershort(nextbar,atopen);endif;
if positiondir=-1 and contagiornoinessere>18 then exitshort(nextbar,atopen);endif;
if positiondir=-1 and getmonth<>meseprec51 then exitshort(nextbar,atopen);endif;
if positiondir=-1 and actual>4.0 and contaopshort<>1 then exitshort(nextbar,atopen);endif;
if positiondir=1 and Max_Gain_perc<3 and contalg>102 then ModifyStopLoss(INPERC,1.50);endif;
if positiondir=-1 and Max_Gain_perc<3 and contash>102 then ModifyStopLoss(INPERC,1.50);endif;
//////////////////////////////// Gain Mensile /////////////////////////////////////////////////////////////////////
meseprec51=getmonth;
if getMonth <> meseprec9 then
contagain = 0;
endif;
if IdLastOpClosed > idlastop then
contagain = contagain + LastTradeClosedPerc;
endif;
idlastop = IdLastOpClosed;
meseprec9=getmonth;
//////////////////////////// Plottaggi Vari ////////////////////////////////////////////////////////////////////////
indzona1=Createviewport(200, 0, true);
PlotChart(actual,indzona1,aqua,solid,2);
PlotChart(Max_Gain_perc,indzona1,red,solid,2);
indzona2=Createviewport(200, 0, true);
PlotChart(contagain,indzona2,green,solid,2);
indzona3=Createviewport(200, 0, true);
PlotChart(contaoplong,indzona3,green,solid,2);
PlotChart(contaopshort,indzona3,red,solid,2);
PlotChart(optotal,indzona3,aqua,solid,3);
Indzona4=CreateViewport(100, 0, true);
plotchart(contagiornoinessere, indzona4,red, solid, 1 );
DrawText(5,indzona4 ,D ,contagiornoinessere , "giorni borsistici=",contagiornoinessere , red, 10, 2+2,Alleft);