plz help in profit booking code

#1
My strategy is simple. Buy in 5 mins chart when 5 ema crosses 20 ema. Sell at 15 point profit or negative cross over or at market close. Plz help
 

casoni

Well-Known Member
#2
hello.
have set target = 15 POINTS [ adjustable from parameter window ]
this will sell at target achieved or stop loss [ i.e ema(c,20) ] hits ,
vice- versa for short

e1=EMA(C,5);
e2=EMA(C,20);
Plot(C,"Close",3,64);
Plot(e1,"",6,1);
Plot(e2,"",4,1);

b1=Cross(e1,e2);
s1=Cross(e2,e1);
Buysetup=Flip(b1,s1);
Shortsetup=Flip(s1,b1);
trend=IIf(BarsSince(Buysetup)>BarsSince(Shortsetup),1,0);
L2=e2;
H2=e2;
s5d=TrendSL=IIf(trend==1,L2,H2);
t1=Param("Set Target points",15,5,100,1);
BOS=IIf(e1>e2,1,-1);
Price=ValueWhen(IIf(Bos==1,b1,s1),C);
T1=IIf(BOS==1,(Price+t1),(Price-t1));
buyBars=BarsSince(Cross(e1,e2));
sellBars=BarsSince(Cross(e2,e1));
DisPds=LastValue(IIf(Bos==1,buybars,sellbars))+1;
BackPds=0;
T1A=ValueWhen(DisPds,Ref(Ref(T1,-BackPds),BackPds));
Plot(T1A,"Target",IIf(Bos==1,5,4),24);

Buy = B1 ;
Short= S1 ;
Sell=Shortsetup OR Cross(t1a,C);
Cover=Buysetup OR Cross(C,t1a);

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short,Cover);
Cover=ExRem(Cover,Short);


PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorGreen, 0,Low,-15);
PlotShapes(IIf(Sell, shapeHollowDownArrow, shapeNone),colorOrange, 0,High,-25);
PlotShapes(IIf(Cover, shapeHollowUpArrow, shapeNone),colorLime, 0,Low,-25);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorRed, 0,High,-15);

side = 3;//
dist = Param("text up-dn",0.1,0,2,0.1);
for( i = 1; i < BarCount; i++ )
{
if(i+side== BarCount) PlotText( "T.Stop " + e2[ i ], i+5, e2[ i ]-dist, colorLime );
}

thank you
 
#3
thanks a lot for the help...but i doubt if u have covered closing position at market closing as i cannot see the same anywhere in the code.. i have heard that it uses timenum() function but dont know how to use it
 

casoni

Well-Known Member
#4
thanks a lot for the help...but i doubt if u have covered closing position at market closing as i cannot see the same anywhere in the code.. i have heard that it uses timenum() function but dont know how to use it

you didn,t mention .you want to close all position when market closes.
..
will add that code .
.any thing else you want to add ?
 

casoni

Well-Known Member
#5
delete
Buy=.....
short=,,
sell=...
cover=....
and use this

EndDay = ParamTime( "No trade after ", "15:00:00" );
EndDay2 = ParamTime( "close position ", "15:15:00" );
tn = TimeNum();
dn = DateNum();
Exit = Ref( tn < EndDay2, -1 ) AND ( tn >= EndDay2 OR dn < Ref( dn, 1 ) );
Buy = B1 AND Tn<EndDay;
Short= S1 AND Tn<EndDay;
Sell=Shortsetup OR Cross(t1a,C) OR exit;
Cover=Buysetup OR Cross(C,t1a) OR exit;

**
oops sorry .. you had mentioned you want to close position at mkt end..
 
Last edited:

casoni

Well-Known Member
#7
thanks ... now just to ask u .. if i want to change buy sell conditions i have to change b1 and s1 only right ??

Buy = B1 ;
short =s1 ;

and

sell = Cross(e2,e1);
 
#8
dear brother.. now the question is if i want to know how many targets achieved and how many stoplosses triggered in the past ..?? how to do know the same ??
 

Similar threads