Graph number of trades

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #24775 quote
    Elsborgtrading
    Participant
    Veteran

    Hi coders

    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.

    Does anyone have an idea on how to graph this?

    cheers Kasper

    Screenshot_192.jpg Screenshot_192.jpg
    #24977 quote
    Nicolas
    Keymaster
    Master

    An idea would be to fetch through all tradeindex within a loop to count them all.

    #96797 quote
    Finning
    Participant
    Veteran

    Hi all,

    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.

    If tradenum = 0 and not onmarket then
    tradenum = 0
    endif
    
    If abs(countofposition-countofposition[1]) and tradenum=0 then 
    tradenum = 1
    if shortonmarket then 
    shortcount = 1
    else
    if longonmarket then
    longcount = 1 
    endif
    endif
    endif
    
    if longonmarket[1] and shortonmarket then
    tradenum = tradenum[1]+1
    shortcount = shortcount[1]+1
    endif
    
    if shortonmarket[1] and longonmarket then
    tradenum = tradenum[1]+1
    longcount = longcount[1]+1
    endif
    
    if longonmarket[1] and longonmarket then
    tradenum = tradenum[1]
    longcount = longcount[1]
    endif
    
    if shortonmarket[1] and shortonmarket then
    tradenum = tradenum[1]
    shortcount = shortcount[1]
    endif
    
    If onmarket[1] and not onmarket then
    tradenum = tradenum[1]
    longcount = longcount[1]
    shortcount = shortcount[1]
    endif
    
    If not onmarket[1] and longonmarket then
    tradenum = tradenum[1]+1
    longcount = longcount[1]+1
    endif
    
    If not onmarket[1] and shortonmarket then
    tradenum = tradenum[1]+1
    shortcount = shortcount[1]+1
    endif

     

    Regards,

    Finning

    Capture-1.jpg Capture-1.jpg
    #96804 quote
    Vonasi
    Moderator
    Master

    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!

    if longlimitorderon and low < x then
    longcount = longcount + 1
    endif
    
    longlimitorderon = 0
    
    if longstoporderon and high > x then
    longcount = longcount + 1
    endif
    
    longstoporderon = 0
    
    //
    //Your conditions and calculation of x price in here
    //
    
    //Limit order
    if (your long entry conditions at a LOWER price) then
    buy 1 contract at x limit
    longlimitorderon = 1
    endif
    
    //Stop order
    if (your long entry conditions at a HIGHER price) then
    buy 1 contract at x stop
    longstoporderon = 1
    endif
    
    //Market order
    if (your long entry conditions at MARKET price) then
    buy 1 contract at market
    longcount = longcount + 1
    endif
    
    graph longcount
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Graph number of trades


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 3 replies,
has 4 voices, and was last updated by Vonasi
6 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/11/2017
Status: Active
Attachments: 2 files
Logo Logo
Loading...