[description = This indicator calculates and displays the TRADER'S RATE OF CHANGE - (TROC) in a separate panel. This is similar to the standard ROC but refines the ROC to better mirror what a trader would have been doing during the period this stock is held. It calculates the profit (or loss) for the trader using their trading strategy, and further adjusts this for the period held, to provide a (rough) annualised result. In this example, ENTRY is MA5UP twice & SROC UP twice & EXIT is BOT - Best Of Three - HappyFace, MA5DOWN once, SROC DOWN once. Default period of view is 110 bars (weeks normally) equating to 2 years. This indicator is designed to be run ONLY ON WEEKLY DATA; author=Bleakley, Des;target=new;] hist_bars := input("History bars ", 110, 10, 1000); MA5 := 5; MA_method := SIMPLE; close_HF := 6; TP_ATR_num := 3; emasmooth := 10; roc_bars := 52; max_bar_num := lastvalue(barnumber); history_bars := if(hist_bars>max_bar_num, max_bar_num, hist_bars); startbar := if(history_bars=0,65,max_bar_num - history_bars); earlybar := barnumber < 65 OR barnumber < startbar; lastbar := barnumber=lastvalue(barnumber); firstbalance := 100; [color=red]; { **** DETERMINE PERIOD OF CHART **** } daysdiff := datediff( hist( now(),1), now() ); period := if ( daysdiff <7, "DAILY", if ( daysdiff <30, "WEEKLY", if ( daysdiff < 93, "MONTHLY", if ( daysdiff<365, "QUARTERLY","YEARLY")))); period_factor :=if (period="DAILY", 260, if( period="WEEKLY", 52, if( period="MONTHLY", 12, if( period = "QUARTERLY", 4, 1)))); { **** Calculate raw & smoothed annual rise **** } boughtprice := hist(CLOSE, roc_bars); risetodate := CLOSE - boughtprice; risepc := (risetodate/boughtprice)*100; smoothpcS := ma( risepc, emasmooth, S); smoothpcE := ma( risepc, emasmooth, E); smoothpc_up_one := hist(smoothpcS,1) < smoothpcS; smoothpc_down_one := hist(smoothpcE,1) >= smoothpcE; smoothpc_up_two := hist(smoothpc_up_one,1) AND smoothpc_up_one; smoothpc_down_two := hist(smoothpc_down_one,1) AND smoothpc_down_one; { **** MA5 & HAPPY FACE NEARBY CALCULATIONS **** } roc_st := roc(CLOSE,14,PERCENT); bell := cross(roc_st,0); bell_nearby := barssince(bell) <6 AND roc_st >0; MA5_down_one := hist(ma(CLOSE,MA5,MA_method),1) >= ma(CLOSE,MA5,MA_method); MA5_down_two := hist(MA5_down_one,1) AND MA5_down_one; MA5_up_one := hist(ma(CLOSE,MA5,MA_method),1) < ma(CLOSE,MA5,MA_method); MA5_up_two :=hist(MA5_up_one,1) AND MA5_up_one; ATR_profit_line := (ma(CLOSE,13,SIMPLE) + TP_ATR_num*ATR(21)); happy_face := C >= ATR_profit_line; happy_face_nearby := barssince(happy_face)< close_HF; last_HF_value := valuewhen(1,happy_face,CLOSE); first_HF := happy_face AND NOT hist(happy_face_nearby,1); { **** DEFINE ENTER AND EXIT CONDITIONS **** } en_2 := MA5_up_two AND smoothpc_up_two ; en_3 := MA5_up_two AND smoothpc_up_one AND bell_nearby; ex_1 := MA5_down_one AND smoothpc_down_one ; ex_2 := happy_face_nearby AND MA5_down_one AND CLOSE= HHV(Close,close_HF); ex_3 := happy_face_nearby AND smoothpc_down_one AND CLOSE= HHV(Close,close_HF); exitcondition := NOT WHITE AND (ex_1 OR ex_2 or ex_3) ; entercondition := NOT exitcondition AND WHITE AND (en_2 OR en_3) AND NOT first_HF; { **** ARE WE IN OR OUT OF THE MARKET? **** } INMKT := if( earlybar, FALSE, if( prev AND exitcondition, FALSE, if( NOT prev AND entercondition, TRUE, prev))); { **** CHANGE FROM INMKT TO NOT INMKT DEFINES BUY/SELL SIGNALS - LONG SYSTEM **** } buysignal := NOT hist(INMKT,1) AND INMKT; sellsignal := hist(INMKT,1) AND NOT INMKT; { **** Count number of bars in and out of market **** } 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; total_years := TOTALNUMBARS / period_factor; { **** CALCULATE PROFIT FOR EACH TRADE AND SUM THEM **** } lastbuyprice := if(buysignal, if(lastbar, CLOSE, future(OPEN,1)), prev); tomorrowopen := if(lastbar, CLOSE, future (OPEN, 1)); profit := tomorrowopen - lastbuyprice; profitpc := (profit/lastbuyprice)*100; uplift_since_buy := if (INMKT OR sellsignal, (tomorrowopen/lastbuyprice),0); balance := if(earlybar, firstbalance, if( buysignal, prev, if( sellsignal, valuewhen(1, buysignal, prev)*uplift_since_buy, if( INMKT, valuewhen(1,buysignal, prev)*uplift_since_buy, prev)))); final_profit := balance-firstbalance; PPA := final_profit/total_years; { **** DISPLAY TROC VALUE AND DRAW TROC LINE FOR PERIOD SELECTED **** } raw_TROC := PPA/INMKTRATIO; TROC := round(raw_TROC,0); { **** DRAW RAW TROC LINE **** } [name=TROC RAW;linestyle=Step;color=red;width=2;dp=0;visible=false];+TROC;