PDA

View Full Version : Looking for mechanism to scale down size based on performance


scriabinop23
05-15-2007, 10:03 PM
I am looking for, on a daily basis, a mechanism within a strategy to realize a certain type of trade is failing, and scale down entry size or even abstain from entry until a new session commences.

ie... a long strategy is failing because markets are selling off aggressively, and every dip buy fails. As the strategy fails perhaps twice or three times in a row, make subsequent entries have less size.

Any way to do this?

I see this is a cumprofit variable that I could use, but that won't be very effective if I had one home run in the beginning of the day, and three smaller failures after.

Basically, I'd like to build damage control into the strategy.

[ie lets say my strategy is countertrending, and the day is overall a trending day...]


Also: I've noticed the BarsSinceEntry() and BarsSinceExit() values do not work on the basis of a less than qualifier ie if the running strategy has not yet initiated a position, since by default Barssinceexit = -1 and barssinceentry could equal 0:

if (BarsSinceEntry())
EnterLong();

My thoughts are I could use the BarsSinceExit or Entry statement as a way to exclude reattempting a failed trade within a certain timeframe. The problem is that if I put this qualifer in front of my main logic, I will never trigger an order, since by default they are less than 1 or 0 already. (i figure 10-20 3 min bars could be enough to exclude too soon re-entry).

Any way to make these variables have defaults of above 100 if the strategy had never been invoked?

NinjaTrader_Ray
05-16-2007, 07:19 AM
No this would not be possible. What you could do is skip through the performance object and review actual trades. I apologize in advance, this section is no where near complete in documentation.

http://www.ninjatrader-support.com/HelpGuideV6/Overview44.html

Likely this is not of any help right now but I will provide some sample code in the next few weeks in this area.

scriabinop23
05-16-2007, 07:26 AM
is (Performance.AllTrades.Performance.MaxConsecLoser) /etc... (and all the other performance #s) indicative of all trades since the strategy started running in the control center (upon hitting start) its session, or complete history in the DB? or just the day's performance?


Also, any ideas on the BarsSinceEntry() fields? am i stuck and correct in my observation?

NinjaTrader_Ray
05-16-2007, 07:56 AM
Its all trades since the strategy started running including historical and real-time trades.

Regarding the BarssinceEntry(), I don't fully comprehend what you want to do there.

scriabinop23
05-16-2007, 08:01 AM
Its all trades since the strategy started running including historical and real-time trades.

Regarding the BarssinceEntry(), I don't fully comprehend what you want to do there.


meaning if i started running the strategy on 5/10-5/11, then stopped it and restarted the program and reran at 5/15-5/16, it would show me data all the way from 5/10?

On barssinceentry the goal is to say

if barrsinceentry < 10 Do not re enter any new trades. I want to put this qualifier before all of my trade triggers.

BUT if the strategy is newly commenced, the variable defaults to a value lower than 10 already (since it hasn't entered yet) [like 0], it won't work.

NinjaTrader_Ray
05-16-2007, 09:25 AM
Thanks for clarification.

When you run a strategy, it will show you trade history against the amount of historical data you have on your chart. So if your chart has 5 days of data, it will show virtual historical strategy history against those 5 days. Had you run the strategy in real-time during this five day period and stopped it, the real-time history is NOT included as part of the virtual historical calculation when running the strategy again.

On the second issue, why not do something like this.


if (BarsSinceEntry() > 10 && BarsSinceEntry() != -1)
// Take the trade

scriabinop23
05-16-2007, 11:41 AM
Thanks for clarification.
On the second issue, why not do something like this.


if (BarsSinceEntry() > 10 && BarsSinceEntry() != -1)
// Take the trade


actually i need an or statement..

if (BarsSinceExit() > 10 or BarsSinceExit() = -1)


whats the or statement for or? :) thanks (instead of &&)

scriabinop23
05-16-2007, 12:01 PM
actually i need an or statement..

if (BarsSinceExit() > 10 or BarsSinceExit() = -1)


whats the or statement for or? :) thanks (instead of &&)


Found it.. || looks like it.
but both that and | result in Operator '|' cannot be applied to operands of type 'bool' and 'int' Strategy\LongHNG.cs ...

alternative operator?

NinjaTrader_Ray
05-16-2007, 12:26 PM
Please take a look here - http://www.ninjatrader-support.com/HelpGuideV6/BasicSyntax.html

scriabinop23
05-16-2007, 12:40 PM
Please take a look here - http://www.ninjatrader-support.com/HelpGuideV6/BasicSyntax.html


Now I can't make sense of why || doesn't work.
statement is as follows:

If BarsSinceExit() > 3 || BarsSinceExit() = -1
{...

My intention: if one of the above is true then execute.
Says can't apply to bool or int operands.

NinjaTrader_Ray
05-16-2007, 12:46 PM
Should be


if (BarsSinceExit() > 3 || BarsSinceExit() == -1)
// Do something

scriabinop23
05-16-2007, 01:04 PM
Should be


if (BarsSinceExit() > 3 || BarsSinceExit() == -1)
// Do something



thanks a lot!!