[description=DJB - ENTRY & EXIT ARROWS with profit calculations KISS strategy; author = Bleakley, Des ; target=PRICE; ] strategy := "NEW HIGH - Entry Filter (S) - Exit 7on12"; NBARSBACK := 52; { Set period for new high } totalbars := lastvalue( barnumber); lastbar := barnumber = totalbars; firstdate := firstvalue(now()); lastdate := lastvalue( now()); totaldaysactive := datediff(firstdate, lastdate) - NBARSBACK; numyears := totaldaysactive / 365; printposition := CLOSE*0.87; [color=red;] { **** ENTRY CONDITIONS **** } newhigh := if (barnumber<=NBARSBACK, FALSE, CLOSE >= highest(CLOSE,NBARSBACK) ); enterconditionA := LoadSymbol("XAO", Close) >= ma(LoadSymbol("XAO", Close ),12,E); { Entry condition A - Is market in up trend ? } enterconditionB := newhigh; { Entry condition B - Is this bar a NBARS HIGH? } enterconditionC := ma(C,7,E) > ma(C,12,E) AND ma(C,11,E) > ma(C,12,E); { Entry condition C - is 7 & 11 > 12 EMA? } entercondition := enterconditionA AND enterconditionB AND enterconditionC; { Select entry conditions } { **** EXIT CONDITIONS **** } exitcondition := cross( ma(C,12,E) , ma(C,7,E)); { ***** According to our entry and exit conditions, are we in or out of the market? ***** } INMKT := if ( entercondition, TRUE, if ( exitcondition, FALSE, prev )); { **** Look at status of INMKT to see if we have triggered a buy or sell condition *** } buysignal := INMKT AND NOT hist(INMKT,1); sellsignal := NOT INMKT AND hist(INMKT,1); { **** PRINT ENTER & EXIT ARROWS **** } [Name = "ENTER"; Linestyle = marker; color=red;marker = type13]; buysignal; [Name = "EXIT"; Linestyle = marker;color=red; marker=type14]; sellsignal; { **** Mark exit bar to indicate a 7 on 12 exit **** } [name="x7";linestyle=marker;color=red;marker = type7]; sellsignal; { *********** PRINT Buy & Sell prices = next OPEN ************* } [name=" ";linestyle=text;textalign=below,centre;fontstyle=bold;fontsize=6;]; if ( buysignal,"Buy: "+round(future(OPEN,1),2), undefined); printposition*0.55; [name=" ";linestyle=text;textalign=below,centre;fontstyle=bold;fontsize=6;]; if ( sellsignal,"Sell: "+round(future(OPEN,1),2), undefined); printposition*0.55; { **** Remember Date of latest buysignal **** } lastbuydate := if ( buysignal, now(), prev ); { **** Remember Enter Price (tomorrow's OPEN) on buy signal for later profit/loss calculation **** } ENTERPRICE := if ( buysignal, future(OPEN,1), prev); { **** Count number of bars in and out of market **** } INMKTCOUNT := if (INMKT,+1, 0); OUTMKTCOUNT := if (NOT INMKT, +1, 0); TOTALINMKT := sum(INMKTCOUNT); TOTALOUTMKT := sum(OUTMKTCOUNT); INMKTRATIO := TOTALINMKT / totalbars; { **** Note highest Close in this trade **** } THIShightodate := if (buysignal, CLOSE, if ( sellsignal, 0, if ( (CLOSE > prev AND INMKT) , CLOSE, prev))); { **** Calculate Draw Down for his trade **** } DDtoday := if ( sellsignal, hist(THIShightodate,1)-CLOSE, THIShightodate -CLOSE); DDtodaypercent := if(sellsignal, ( DDtoday / hist(THIShightodate,1)) *100, (DDtoday / THIShightodate)*100); DispDDpc := if(INMKT,DDtodaypercent , if(sellsignal,DDtodaypercent,0)); MAXDDpercent := highest( DDtodaypercent ); { ************ PRINT Notional Profit Per Trade *************** } lastbuyprice := hist( ENTERPRICE, 1); tomorrowopen := future (OPEN, 1); profit := tomorrowopen - lastbuyprice; profitpercentage := (profit / lastbuyprice) * 100; win := profitpercentage > 0; loss := profitpercentage <= 0; tradeprofitorlosspercent := if (sellsignal, profitpercentage, 0 ); thisiswin := if (sellsignal AND win, +1,0); thisisloss := if (sellsignal AND loss, +1,0); numwins := sum(thisiswin); numlosses := sum(thisisloss); totalnumtrades := numwins + numlosses; winratio := if ( totalnumtrades = 0, 0 , (numwins/totalnumtrades)*100 ); thiswinvalue := if (thisiswin, profitpercentage,0); thislossvalue := if (thisisloss, profitpercentage,0); totalwinpercent := sum(thiswinvalue); totallosspercent := sum(thislossvalue); currtradedays := datediff( lastbuydate, NOW() ); profitpcpa := if( currtradedays=0,0, (profitpercentage / currtradedays) * 365); Rprofitpercentage := round( profitpercentage, 2); Rprofitpcpa := round( profitpcpa, 2 ); [name="PSell";linestyle=text;textalign=below,centre;fontstyle=bold;fontsize=6;]; if ( sellsignal and win,"Profit : "+round(profit,2)+"("+Rprofitpercentage+"%) in "+currtradedays+" days ("+Rprofitpcpa+"%PA)", undefined); printposition*0.53; [name="LSell";linestyle=text;textalign=below,centre;fontstyle=bold;fontsize=6;]; if ( sellsignal and loss,"Loss : "+round(profit,2)+"("+Rprofitpercentage+"%) in "+currtradedays+" days ("+Rprofitpcpa+"%PA)", undefined); printposition*0.53; { ****** PRINT Summary Stats ********* } totalnettprofit := sum(tradeprofitorlosspercent); returnperyear := totalnettprofit / numyears; averagewin := if ( numwins>0, totalwinpercent/numwins, 0); averageloss := if ( numlosses>0, totallosspercent/numlosses, 0); profitratio := if ( averageloss=0, 1, averagewin / -averageloss ); perannum := returnperyear / INMKTRATIO; INorOUT := if(INMKT,"IN","OUT"); lastprofit := if ( (buysignal AND lastbar), 0, if( INMKT, (CLOSE/hist(ENTERPRICE,1)-1) * 100, 0)); lasttradepc := if ( currtradedays = 0, 0, (lastprofit / currtradedays) * 365 ); { **** Round for printing **** } Rlatestprofit := round( lastprofit, 2); Raveragewin := round( averagewin, 2); Raverageloss := round( averageloss, 2); Rprofitratio := round( profitratio, 2); Rtotaldaysactive := round( totaldaysactive ); Rnumyears := round(numyears,1); Rreturnperyear := round( returnperyear, 2 ); RINMKTRATIO := round(INMKTRATIO*100); Rmaxddpercent := round(MAXDDpercent, 2); Rwinratio := round ( winratio ); Rtotalnettprofit := round ( totalnettprofit, 2); Rperannum := round( perannum, 1); Rlasttradepc := round(lasttradepc); Rppt :=round(totalnettprofit/totalnumtrades,2); [name="SUMMARY";linestyle=text;textalign=below,centre;fontstyle=bold;fontsize=9;]; if ( lastbar,strategy+" - Curr "+INorOUT+" @ "+Rlatestprofit+"% ("+Rlasttradepc+"% PA) - MAX DD = "+Rmaxddpercent+"%", undefined); printposition*0.92; if ( lastbar,"Profit : "+Rtotalnettprofit+"% W/L : "+numwins+"/"+numlosses+" WR : "+Rwinratio+"% IN : "+RINMKTRATIO+"% of "+Rnumyears+" years - ("+Rtotaldaysactive+"D) - ROC : "+round(ROC(C,126,%))+"%", undefined); printposition*0.88; if ( lastbar ,"Avg W ("+Raveragewin+"%) = "+Rprofitratio+" times Avg L ("+Raverageloss+"%) PA1: "+Rreturnperyear+" PA2: "+Rperannum+"% PPT: "+Rppt+"%", undefined); printposition*0.84;