//Count the % of trades closed in the same candle
// Pepsmile
// 7 june 2018
DEFPARAM CUMULATEORDERS = false
// simple buy/short strategy
MM1 = ExponentialAverage[20](close)
// Long
IF MM1 crosses over MM1[1] THEN
BUY 1 LOT AT MARKET
ENDIF
// Short
IF MM1 crosses under MM1[1] THEN
SELLSHORT 1 LOT AT MARKET
ENDIF
////// closed SL & TP to find easily right cases
set stop ploss 5
set target pprofit 5
///////////////////
// Snippet
if longonmarket[2]=0 and longonmarket[1]>0 and longonmarket=0 then
Long1=Long1+1
elsif shortonmarket[2]=0 and shortonmarket[1]>0 and shortonmarket=0 then
Short1=Short1+1
endif
// Graph variables
// Long1 = count #longs open/close in the same candle
// Short1 = count #longs open/close in the same candle
//graph Long1 as "Long1"
//graph -Short1 as "Short1"
//
if (onmarket and barindex=tradeindex) or(barindex=tradeindex and barindex=tradeindex(2)) then
TotalT=TotalT+1
endif
// due to the lag of 1 bar calculation for Long1 & Short1, results have to been considered 1 bar after close, best to see final result
graph 100*(Long1+Short1)/TotalT