[description = This BUY/SELL strategy ENTERS on a NEW HIGH (5 period default, user selectable) and also 3 on 12 EMA. EXIT is when there is a confirmed close below 1.3 (user selectable) x ATR. This complete indicator displays the following information: Entry and exits - UP & DOWN arrows Exit arrow is accompanied by a tick if this trade is profitable, or a cross if a loss, plus the percentage gain or loss for that trade Right pointing arrow at last bar if we in a continuing trade Orange line is rising stop (1.3 x ATR) - can be adjusted EXIT needs two closes below the rising stop, with the second lower than the first Summary line gives : Brief description of strategy P - Profit - componded over the selected period - default period is from 1 Jan 2013 - user selectable WR - Win Ratio - percentage of wins from total trade MDD - Maximum Draw Down % CDD - Current Draw Down % PPA - Profit Per Annum % (Profit / num years) TIM - Time In Market % SCORE - WR * PPA | WR * WR * PPA | WR * WR * PPA / TIM ADVICE - BUY, SELL, HOLD, STAY OUT determined by strategy. NOTE - The display of all these fields can lead to clutter - if desired you can turn any or all components off by selecting the indicator, click STYLES (which displays a list of the fields) & then selecting those required or not.; author=Bleakley, Des;target=price;] printposn := input("Print Position ", 9, 1, 20); lookback := input(" Lookback Period ", 5, 1, 100); startdate := inputdate("Start Analysis From ",date(2013,1,1) ); red_atrnum := input("Exit ATR factor ", 1.3, 0.1, 10); red_ATR := C-red_atrnum*ATR(21); earlybar := barnumber < 30 OR startdate > now; lastbar := barnumber=lastvalue(barnumber); printpositionH:= HHV(HIGH,50)*(printposn/10+1)*1.2; printpositionL := LLV(LOW,50)*(printposn/10)*0.8; firstbalance := 100; strategy := "("+printposn+") NH ("+lookback+") & 312 - EXIT ATR ("+red_atrnum+")"; [color=orange]; { **** ENTRY CONDITIONS **** } highpoint := HHV( CLOSE, lookback ); entercondition := (CLOSE >= highpoint) AND (ma(C,3,E) > ma(C,12,E)) ; {[name=ec;linestyle=marker;marker=type2];entercondition;} ts := if( earlybar, -CLOSE, if( close < prev AND hist(close,1) < prev AND close0 AND entercondition, max( red_ATR, prev), { IN and enter condition } if( prev<0 AND entercondition, red_ATR, { NOT INMKT & enter condition } if( prev>0 ,max(red_ATR,prev), prev))))); { No enter or exit } exitcondition := close < hist(ts,1) AND hist(close,1) < hist(ts,1) AND close0; { **** Count number of bars in and out of market **** } thisbardate := now(); prevbardate := hist( now(),1); daysdiff := datediff(prevbardate, thisbardate); period := if ( daysdiff <7, "DAILY", if ( daysdiff <30, "WEEKLY", if ( daysdiff < 93, "MONTHLY", if ( daysdiff<365, "QUARTERLY","YEARLY")))); TOTALINMKT := if (earlybar, 0, if (INMKT, prev+1, prev)); TOTALOUTMKT := if (earlybar, 0, if ( NOT INMKT, prev+1, prev)); TOTALNUMBARS := TOTALINMKT + TOTALOUTMKT; INMKTRATIO := TOTALINMKT / TOTALNUMBARS; period_factor :=if (period="DAILY", 260, if( period="WEEKLY", 52, if( period="MONTHLY", 12, if( period = "QUARTERLY", 4, 1)))); total_years := TOTALNUMBARS / period_factor; { **** CALCULATE DRAW DOWN **** } highthistrade := if(NOT INMKT, CLOSE ,highestsince(1,buysignal, CLOSE)); thistradeDDpc := ((highthistrade-CLOSE)/highthistrade)*100; maxDDpcthistrade := highestsince(1,buysignal,thistradeDDpc); maxDDpc_all_time := highest ( maxDDpcthistrade ); RCDD := if ( INMKT,round(thistradeDDpc, 2),if ( sellsignal,round(((hist(highthistrade,1)-CLOSE)/hist(highthistrade,1))*100, 2), 0) ); { **** CALCULATE PROFIT **** } lastbuyprice := if(buysignal, if(lastbar, CLOSE, future(OPEN,1)), prev); tomorrowopen := if(lastbar, CLOSE, future (OPEN, 1)); {enterprice := if ( buysignal, future(OPEN,1), prev); } profit := tomorrowopen - lastbuyprice; profitpc := (profit/lastbuyprice)*100; win := profit > 0; loss := profit <= 0; balance := if(earlybar, firstbalance, if(sellsignal or (lastbar AND hist(INMKT,1)), prev*(1+profitpc/100), prev)); final_profit := balance-firstbalance; PPA := final_profit/total_years; { **** CALCULATE NUMBER OF WINS AND LOSSES **** } numwins := if(earlybar,0,if(((lastbar AND INMKT) OR sellsignal) AND win, prev+1, prev)); numlosses := if(earlybar, 0,if((lastbar OR sellsignal) AND loss, prev+1, prev)); total_trades := numwins+numlosses; winratio := if ( total_trades = 0, 0 , (numwins/total_trades)*100 ); RPPAscore := round (winratio*PPA/100); RPPAscore2 := round((winratio*winratio * PPA)/10000); RAPPA := round ( (winratio*winratio*PPA)/(INMKTRATIO*10000)); { **** DECIDE ON RECOMMENDATION ***** } bars_buy_ago := if (entercondition AND NOT hist(INMKT,1), 0, barssince(buysignal)); ss_buy := if(bars_buy_ago = 0 AND INMKT," BUY NOW &", if(bars_buy_ago<6 AND INMKT, " BUY "+bars_buy_ago+" &","")); ss_sell := if( exitcondition AND hist(INMKT,1), " SELL &",""); ss_wait := if( NOT INMKT OR sellsignal, " STAY OUT", ""); ss_hold := if (( INMKT{ exitcondition}) OR (hist(INMKT,1) AND CLOSE >=abs(hist(ts,1))), " HOLD", ""); ss_watch := if( hist(INMKT,1) AND CLOSE