I’ve been trying to use the graph instruction to display number of trades as in the statistic of a backtest. But when accumulating orders it not straight forward with a counter.
was looking at this problem myself, and have come up with the following code. In a cumulating trades setting, it counts number of total trades, and number of long/number of short.
A word of caution though – it slips up on same bar entry/exits – it won’t count a trade if it opens and closes on the same bar, or if a trade netts off to no position in the same bar – an example picture is attached. This same bar close count problem might be overcome with an additional condition?
Graph tradenum, longcount and shortcount to see results.
You could do something like this to record mid candle trades. It does not allow for spread so you might want to factor that in in some way when comparing to the high and low of a candle.
This is the long only version. Not tested and written during first cup of coffee of the day!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
iflonglimitorderonandlow<xthen
longcount=longcount+1
endif
longlimitorderon=0
iflongstoporderonandhigh>xthen
longcount=longcount+1
endif
longstoporderon=0
//
//Your conditions and calculation of x price in here
To help us continually offer you the best experience on ProRealCode, we use cookies. By clicking on "Continue" you are agreeing to our use of them. You can also check our "privacy policy" page for more information.Continue