Strategy trade metrics displayed in chart label


Category:
0
0

Aloha Pete,

First thank you. I have learned a great deal about scripting from you. I’m trying to figure out a way to implement labels for past performance of the floatingpl()  and addorder() functions. I have done extensive backtesting for some of my strategies but would like to see a snapshot of how my strategy is performing recently. For example, if i pull up a 30 day 1 min chart of SPY, I could quickly see a few stats in labels based off the previous addorder executions like accuracy%, max loser, max winner, etc. This way it could give me a quick view of how my strategy is performing in the current market conditions in a particular stock. In which case could lead me to size up, size down, no trade, etc.

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on December 24, 2018 12:45 am
172 views
0
Private answer

I had to update your question title so that other visitors will understand your request more clearly. This also helps others who are searching for a similar solution. “P/L script” was far too vague.

Since the context of your question is in regards to Strategies, I moved it out of the Chart Studies topic and into the Strategy Guide topic.

Most of what you requested is simply not possible in Thinkorswim. You must do this through exporting the data to a spreadsheet and performing your analysis there. The P/L graph and associated function are not scriptable. All you get is the P/L displayed on the lower price graph, and that only works when you check the box to turn that on or off.

A bit more detail. The strategy engine in Thinkorswim posts theoretical buys and sells on the chart based on your rules (algorithm). Once those orders are plotted on the chart there is literally no way to write any script which can read them.

Solution. Move to another platform. For Thinkorswim, there may be a method (depending on the complexity of your particular strategy) to write a Chart Study that replicates the exact same theoretical orders on a chart as the Strategy. Once you achieve this very advanced code you may then be able to add more lines of code to compute the trade metrics you seek. But in the end, you will have a chart study and NOT a chart strategy.

It is a topic that comes up occasionally during my work and it just makes my head hurt to think about it. I would just move to another platform where tools are already provided for this.

Marked as spam
Posted by (Questions: 37, Answers: 4084)
Answered on December 24, 2018 8:23 am
0

Thank you Pete very much. I apologize I’m not too good at navigating through forums. I was also having another issue i can’t seem to resolve. I’m running a macd with an aggregation of 5mins on a 1min chart and my addorder will trigger 5 consective signals on the macdcrossover until the aggregation period is over and confirmed. I tried comparing the value and avg of 5 bars ago and many other ideas with no luck. My goal is to get one signal once the macd cross has confirmed on the 5 min timeframe.

( at January 2, 2019 6:36 pm)
0

MTF Strategies are far beyond the scope of what we cover for no charge in the Q&A forum. Since you seem to have a good grasp of writing your own, I suggest you examine the code we provide with the following video: https://www.hahn-tech.com/thinkorswim-strategy-guide-mtf/

Be sure to watch the entire video carefully. When using MTF in a strategy there are some major pitfalls you will want to avoid.

( at January 2, 2019 6:52 pm)