Number of Trades Counter


Category:
0
0

Hi Pete, Begginer with Thinkcript here. I’m wondering if I am missing something. It seems like there should be a simple Thinkscript function that returns the number of trades executed by given strategy?

I’m looking to build quick graphic feedback on effectiveness of strategy by plotting (FloatingPL ) / (Total # of trades executed by strategy), providing average $-per-position feedback for given perameters, for given strategy. 

I’ve been struggling to impliment a counter based on changes in FPL(), but

1) It occurs to me that there must be a simpler way and

2) Platform does NOT LIKE Incrementing with IF/THEN  statements and FPL[1] +1. (Plot dissapears, only likes to count if FPL[1] is in an “else” branch, ect.)

Beating my head against the wall with this for several days now. I really appreciate your help. 

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on November 29, 2019 9:04 am
337 views
0
Hi Pete, I was actually able to get the code to spit out a "Accumulated Number of Trades" just now with the following code. From here I should be able to get $ per position, ect. without the hassle of using the strategy reports. declare lower; def FPL = FPL(); plot FPLLine = FPL(); plot ZeroLine = 0; plot FPLbump = FPL == FPL[1]; def tradecounter = if FPL == 0 then 0 #on first data sets otherwise indeterminate initial value of tradecounter to 1 else if FPL == FPL[1] # always executed after initial setting of tradecounter then tradecounter[1] #"flat" current condition - No Change else if FPL[1] != FPL[2] #"rough" current condition - Possible Change then tradecounter[1] #...and "rough" past condition - No Change else tradecounter[1] + 1 ; #...and "flat" plast condition - Incriment one plot tradecounterline = tradecounter;
( at November 29, 2019 12:18 pm)
0
Sorry, but it does not reliably count the number of trades. I just tested this on a Ichimoku strategy published in one of our videos. The trade report produced by Thinkorswim shows 10 total trades. While your code shows 13 total trades.
( at November 30, 2019 9:43 am)
0
Private answer

You did not include a section of fully functional code. So I really have nothing to offer you.

However I did do a search for the term FloatingPL and found the following posts on this topic:

https://www.hahn-tech.com/ans/strategy-trade-metrics-displayed-in-chart-label/

https://www.hahn-tech.com/ans/the-floatingpl-script/

Did you already search the forum for a solution before posting? If so, did you run across these posts and feel they did not explain why you are not having success?

Edit: Out of curiosity I decided to experiment with the FPL() function to see if it could be used to count the number of trades displayed by a chart strategy on Thinkorswim. Below is the code I used for testing. The end result shows that there is no bullet proof way to use the FPL() function to count trades. Because this function does not return a true/false condition. But rather it returns the actual P/L produced by the strategy orders.

First, be sure to read up on the details for the FPL() function:

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/FPL.html

Here is the code I used for my test:

declare lower;
def data1 = FPL();
def data2 = FPL()[1];
plot test2 = data1[1] == data2[1] and data1 <> data2;

I'm really not sure why anyone would try to do this using a custom chart study. The preferred method is to export the trade report into a spreadsheet. From the spreadsheet, you can build formulas to compute any sort of trade metrics you require. So much easier than writing code.

Marked as spam
Posted by (Questions: 37, Answers: 4084)
Answered on November 29, 2019 10:27 am
0
Really, really appreciate your prompt response. I spend a couple of hours trying to get your answer here to apply: https://www.hahn-tech.com/ans/how-does-one-use-a-counter-variable-in-thinkscript/ My really big question was if there was a low-hanging \\”packaged\\” function, I was missing. Apparently there isn\\’t so thanks for clarifying that. Your comment form does not seem to be playing nicely with code so I will post my code in solution form.
( at November 29, 2019 11:29 am)
0
I edited my answer to include some details uncovered while testing for a possible solution.
( at November 29, 2019 12:16 pm)