The FloatingPL Script


Category:
1
0

I’m using that feature “FloatingPL” on the thinkorswim platform,
Which is nothing more than a Floating Profit/Loss histogram, Generated from a custom strategy Which through the function “AddOrder” indicates the points of buying and selling

#
# TD Ameritrade IP Company, Inc. (c) 2012
#
declare lower;

plot FPL = FPL();
plot ZeroLine = 0;

FPL.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
FPL.DefineColor(“Positive and Up”, Color.GREEN);
FPL.DefineColor(“Positive and Down”, Color.DARK_GREEN);
FPL.DefineColor(“Negative and Down”, Color.RED);
FPL.DefineColor(“Negative and Up”, Color.DARK_RED);
FPL.AssignValueColor(if FPL >= 0 then if FPL > FPL[1] then FPL.Color(“Positive and Up”) else FPL.Color(“Positive and Down”) else if FPL < FPL[1] then FPL.Color(“Negative and Down”) else FPL.Color(“Negative and Up”));
ZeroLine.SetDefaultColor(Color.GRAY);

And then I had this idea of plotting another histogram similar to the “FloatingPL” but based on some risk parameters, That will help in decision-making during the day
 
so i Would add a study to create another histogram but with some minor modifications in the “FloatingPL” script
So would be possible for us to have this Default script used in the calculation of the “FloatingPL” ?

I mean, it probably will not be anything too complicated because the calculation involved in the process is quite simple                        FPL = (current price) – (entry price)

Anyways, just throwing this topic in the air, case anyone have knowledge in this area that could share with us

and Thank you Pete for continuing to supply this community with plenty of thinkorswim information

Attachments:
Marked as spam
Posted by (Questions: 7, Answers: 13)
Asked on May 16, 2017 9:05 am
3885 views
0
Private answer

As of the time of this post there is nothing in the Thinkscript language reference that makes this possible. The nearest element they give us is a function called EntryPrice().

Details here: http://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Others/EntryPrice.html

A quick test reveals that this function is only valid when used within a strategy and not within a study. Create a study with these two lines of code:

declare lower;
plot data = EntryPrice();

Even if there is a strategy present on the chart the output of this remains N/A for it’s entire span. So it cannot be used to create custom P/L graph. In order to do anything meaningful at all they would need correct for this. They meaning the Thinkorswim developers. They would also need to create several other functions to read other elements from the active strategy in the chart and enable it to be plotted in a lower subgraph. In this article I detailed some of these challenges: https://www.hahn-tech.com/thinkorswim-strategies-complex-stop-management/

The only other alternative is to abandon the entire concept of using a strategy to plot theoretical buy and sell orders. In it’s place you would write your own framework to mimic the work done by the strategy engine. It is only within this framework that you could control all the elements needed to keep track of each theoretical entry/exit/price/trade size. And from that, you could create whatever sort of P/L calculations you want.

This is a BIG project. One that would cost a lot of money. Given there are other platforms out there that can already handle this I’m not sure it’s worth the expense.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on May 16, 2017 9:55 am
0
Private answer

It’s not true that entry price cannot be used to customize your PnL; I spent an entire weekend actually creating my own, most of the time, if not all, was focused on figuring this out. The reason I wanted to make my own is because using PnL to determine which stocks preforms well with a certain strategy is almost in terms of dollar value.What matters is your total percentage returns on the strategy. For instance, if I made $5 or 50% on $10, and $5 on $1MM or essentially zero, the charts data would read the same.

How to get around this: within your strategy, set you chart to price type Last, go to the last line of code and do something like: “plot FPL= (entryprice()-close)/close”. You can customize as you wish but that is the general idea.

Marked as spam
Posted by (Questions: 0, Answers: 2)
Answered on May 22, 2017 3:53 pm
0

Glad you got something working. I tried your suggestion but it did not plot anything for me. All I got was N/A. I think what you are actually getting is close/close. The EntryPrice() is being counted as a zero and the rest of the equation is being processed. Try doing the same with only EntryPrice() as your data element.

( at May 22, 2017 5:53 pm)
0
Here is a EMA strategy with the entry price over close plot included in the study def. You can easily step back and calc to see that it is correctly calculating this. True, there is N/A in the upper left values panel, but the chart can be read to see the level. Note, it might be easier to set the chart to bar too. input price = close; input fastLength = 20; input slowLength = 50; input averageType = AverageType.EXPONENTIAL; input type = pricetype.LAST; plot FastMA = MovingAverage(averageType, price, fastLength); plot SlowMA = MovingAverage(averageType, price, slowLength); FastMA.SetDefaultColor(GetColor(1)); SlowMA.SetDefaultColor(GetColor(2)); AddOrder(OrderType.BUY_AUTO, FastMA crosses above SlowMA, tickColor = GetColor(1), arrowColor = GetColor(1), name = \”MovAvgTwoLinesStratLE\”); AddOrder(OrderType.SELL_AUTO, FastMA crosses below SlowMA, tickColor = GetColor(2), arrowColor = GetColor(2), name = \”MovAvgTwoLinesStratSE\”); plot EntryPrice = entryprice()/close; EntryPrice.SetDefaultColor(color = Color.GREEN);
( at May 24, 2017 7:30 am)
0

Awesome, this one works. Now what to do with it? You can’t get it off the chart into an Excel spreadsheet. Which is where something like this can actually be used for analysis. Why not just export the Strategy report to Excel and perform all your analysis there? Not picking, just curious.

( at May 24, 2017 11:06 am)
0
Private answer

Here is the answer I had, from the team of ThinkScript

Unfortunately, the base code for FloatingPL is hard-coded into the platform and the code is not available.  The FloatingPL study uses the FPL() function, which is what is hard-coded and not written in thinkScript.  For more information about FPL, please see this link:  http://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Others/FPL.html

Best Regards,

Trade Desk/thinkScript

Marked as spam
Posted by (Questions: 7, Answers: 13)
Answered on May 23, 2017 12:31 pm
0

Basically we are going to need a comparison algorithm
Which will compare the floating price of the stock with your point of entry on the trade (in which the conditions to buy or short were respected)

( at May 23, 2017 12:35 pm)
0

Move to another platform. The advanced techniques you are trying to employ are simply not supported on Thinkorswim. OR, work within the limitations that are present and accept the fact there are many elements you simply cannot measure.

( at May 23, 2017 2:42 pm)