Extended Floating Profit & Loss - Backtesting data utility

R

RConner7

Member
@eddielee394 and all

question. Based on the metrics provided by this study addon... what would you guys consider a successful backtest strategy?

Also - What is the difference between WinRate and W/L %?

Thanks - loving this so far!
 
E

eddielee394

Member
Based on the metrics provided by this study addon... what would you guys consider a successful backtest strategy?
  • Easy to execute/manage in a real world environment
  • Doesn't incur significant drawdown risk per personal tolerance
  • Makes money ;)
What is the difference between WinRate and W/L %?
win rate is a ratio of winning trades to losing trades.
W/L is the percentage of wins relative to total number trades.
 
R

RConner7

Member
Thank you.

Would you consider this to be a successful strategy? 100 share trades. 2min chart.

 
M

MrAdelphi02

New member
@eddielee394 Absolutely brilliant study/strategy!

Just have a few questions:

1. Is the code able to be adapted so the Total Profit of a certain strategy can be added to a Watchlist (Just a dollar value)?

2. I am not able to add it on the end of a custom strategy. It only seems to work for me in two scenarios:
a. As a upper study (floating P&L hidden) when another study has been enabled
b. As a lower study (floating P&L enabled) when another study has been enabled
 
E

eddielee394

Member
. Is the code able to be adapted so the Total Profit of a certain strategy can be added to a Watchlist (Just a dollar value)?
Not likely (although I could be wrong). It depends on the strategy order functions and I don't believe those are accessible as watchlist fields. But maybe someone thats a bit more adept with TS might have more insight.

I am not able to add it on the end of a custom strategy.
Thats odd. I'd have to see how you're implementing it with your strategy. Displaying it as an upper study on it's own shouldn't display any results as it requires the order functions from a strategy to perform the p&l calculations. Unless I'm misunderstanding you. Regardless, post your implementation with your strategy and I'll take a look.
 
M

Mascapitalllctrader

New member
So the code allows you to see the Last entry price. how can i display what the last exit price is. Thanks
 
M

Max911

New member
Maybe there is an error in counting the number of trades, because it seems that the trades that end neutral (0.00) don't count. How can I fix that?
 
E

eddielee394

Member
Maybe there is an error in counting the number of trades, because it seems that the trades that end neutral (0.00) don't count. How can I fix that?
The variable that's passed to the increment function used to count the number of trades is entryFPLAll. Would have to add some logic in the condition that that would include "breakeven" trades.

So the code allows you to see the Last entry price. how can i display what the last exit price is. Thanks
TOS doesn't have a built in function to get a strategy exit. So the only way you would be able to do this is to create a variable based on your strategy's exit conditions and then get the resulting price. It's not included in this script because it would couple the script too tightly with the strategy (making it difficult to port over to other strategies since exit conditions will differ per strategy).
 
Last edited:
M

Max911

New member
The variable that's passed to the increment function used to count the number of trades is entryFPLAll. Would have to add some logic in the condition that that would include "breakeven" trades.

How can I add 'breakeven' trades counter in your code? It seems you count breakeven as winners (>=0)

def entryReturn = if isExitBar then exitBarPL - exitBarPL[1] else entryReturn[1];
def isWin = if isExitBar and entryReturn >= 0 then 1 else 0;
def isLoss = if isExitBar and entryReturn < 0 then 1 else 0;
def entryReturnWin = if isWin then entryReturn else entryReturnWin[1];
def entryReturnLoss = if isLoss then entryReturn else entryReturnLoss[1];
def entryFPLWins = if isWin then entryReturn else 0;
def entryFPLLosses = if isLoss then entryReturn else 0;
def entryFPLAll = if isLoss or isWin then entryReturn else 0;
 
E

eddielee394

Member
How can I add 'breakeven' trades counter in your code? It seems you count breakeven as winners (>=0)


Could probably just add a variable to count the break-even trades and include that in the entryFPLAll condition. Maybe something like this (untested):
Code:
def isBreakEven = if isExitBar and entryReturn == 0 then 1 else 0;
def isWin = if isExitBar and entryReturn > 0 then 1 else 0;
...//other variables

def entryFPLAll = if isLoss or isWin or isBreakEven then entryReturn else 0;
 
M

Max911

New member
Could probably just add a variable to count the break-even trades and include that in the entryFPLAll condition. Maybe something like this (untested):
Code:
def isBreakEven = if isExitBar and entryReturn == 0 then 1 else 0;
def isWin = if isExitBar and entryReturn > 0 then 1 else 0;
...//other variables

def entryFPLAll = if isLoss or isWin or isBreakEven then entryReturn else 0;
It doesn't work, maybe we need to fix 'entryreturn' variable, if it doesn't count zero increment...
 
M

Mascapitalllctrader

New member
The variable that's passed to the increment function used to count the number of trades is entryFPLAll. Would have to add some logic in the condition that that would include "breakeven" trades.


TOS doesn't have a built in function to get a strategy exit. So the only way you would be able to do this is to create a variable based on your strategy's exit conditions and then get the resulting price. It's not included in this script because it would couple the script too tightly with the strategy (making it difficult to port over to other strategies since exit conditions will differ per strategy).

@ eddielee39
The variable that's passed to the increment function used to count the number of trades is entryFPLAll. Would have to add some logic in the condition that that would include "breakeven" trades.


TOS doesn't have a built in function to get a strategy exit. So the only way you would be able to do this is to create a variable based on your strategy's exit conditions and then get the resulting price. It's not included in this script because it would couple the script too tightly with the strategy (making it difficult to port over to other strategies since exit conditions will differ per strategy).


Got ya but question is when i take this code

Addlabel (yes, text =“last exit: “ + ( entryreturn +entry price) hit apply and it shows the exit price for a second than the code continues to calculate which will add the profit to the entry price. This is over my head a total newbie when it comes to coding stuff been trading for 5 years and looking to send myself alerts when my strategy enters and exits a positions as i have not yet coded a trading not to do this for
Me automatically.

I am trading futures so when i do Entryreturn takes the tick and converts that into dollars how can i have the code keep it on ticks than i can find the last exit price
 
Last edited:
E

eddielee394

Member
It doesn't work
It's been a while since i looked at this code & was posting from my phone. Try this:

Code:
def isBreakEven = if isExitBar and entryReturn == 0 then 1 else 0;
def isWin = if isExitBar and entryReturn > 0 then 1 else 0;
...//other variables

def entryFPLAll = if isLoss or isWin or isBreakEven then entryReturn else 0;

#Counts
..//other variables
def breakEvenCount = incrementValue(isBreakEven);

#Label
AddLabel(yes,
                text = "BreakEven Count: " + breakEvenCount
                color = Color.WHITE
);


Edit: I did some brief testing on this and there's a divide by zero bug that will occur when using the above code in the case when there are 0 wins. I don't have time at the moment to push the appropriate fixes, but the workaround would be to update all the calculations that use the winCount variable (roughly line 264 -268) to handle if the winCount equals zero
 
Last edited:
E

eddielee394

Member
Got ya but question is when i take this code

Addlabel (yes, text =“last exit: “ + ( entryreturn +entry price) hit apply and it shows the exit price for a second than the code continues to calculate which will add the profit to the entry price.
That's because entryReturn calculates the net dollar return of a trade. So you're basically adding the P&L (in dollars) of a trade to the entry price of that same trade. If you want the actual price of the underlying instrument that you exited at, like i already mentioned the easiest way is probably to just get the price specific to the exit condition of your strategy. Then fire off an alert using that.
Alternatively, you probably could calculate it as a recursive variable using the built-in TickValue() function and a bit of math. Maybe something along the lines of this (untested):

Code:
def exitPrice = if isExitBar then entryPrice + entryReturn/TickValue() else exitPrice[1] ;

#Labels
...//other labels
AddLabel(yes,
         text = "LastExit: " + AsPrice(exitPrice)
         );
 
S

SparkyFlary

Member
The win/loss count and win/loss rates are not working for me. It also keeps saying 0 trades. What's wrong?
 
E

eddielee394

Member
The win/loss count and win/loss rates are not working for me. It also keeps saying 0 trades. What's wrong?
Without seeing exactly how you implemented it, a screenshot or any other specific details I can't say for sure what the issue is for you. Sorry.
 
M

Max911

New member
I did some brief testing on this and there's a divide by zero bug that will occur when using the above code in the case when there are 0 wins.
It doesn't work. I don't find the bug but I'm not sure if it's only about '0' breakevens, cuz total number of trades never matches actual number. If you don't get the total number that corresponds, all other statistics end up being wrong and unreliable.
 
E

eddielee394

Member
It doesn't work. I don't find the bug but I'm not sure if it's only about '0' breakevens, cuz total number of trades never matches actual number. If you don't get the total number that corresponds, all other statistics end up being wrong and unreliable.
Share a link to your strategy, along with the ticker and aggregation period you were using so I can try and reproduce the issue on my end.
 
M

Max911

New member
Edit: I did some brief testing on this and there's a divide by zero bug that will occur when using the above code in the case when there are 0 wins.
Hi, it's not about breakeven trades. I think I found the reason why the trades do not count well. Apparently the script ignores the trades that start on the next bar to the bar that marked the closing of a previous trade. How can I fix that?

 
Last edited:

Similar threads

Top