PDA

View Full Version : How to tell the strategy if the trade was a win or loss?


m3power222
07-07-2009, 07:53 AM
The strategy takes up to 2 trades a day because if the 1st trade is a loser I want it to take a 2nd trade. If the 1st trade is a winner I do not want it to take the 2nd trade so I watch it trade and after the targets have been filled stop the strategy.

I know I can use a bool flag to set it to true/false based on certain criteria.

So how can I tell if the trade is a winner? My definition of a winner is either a target being filled or one of the stop strategies being activated. There are 2 targets so 2 stop strategies. Once a particular price is hit stop strat 1 will auto break even and stop strat 2 will auto trail.

Either I need to know when a target is filled or stop is moved to set the bool flag. What is the best way to do that?

BigDog008
07-07-2009, 08:08 AM
seeing if targets or stops filled can be done via IOrder and just managing your orders through that...

NinjaTrader_Austin
07-07-2009, 08:09 AM
Hi m3power, I have a couple of reference samples that I think can help you out.

Here is a sample for using trade performance statistics for money management (http://www.ninjatrader-support2.com/vb/showthread.php?t=4084).
Next is the reference page for TradeCollection (http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?TradeCollectionClass).
Lastly, this is the Trade Class (http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?TradeClass)--useful for getting individual trade information.

Let us know if you have any more questions.

m3power222
07-07-2009, 11:06 AM
I'm trying to integrate it with the sampleatmstrat:

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{

// At the start of a new session
if (Bars.FirstBarOfSession)
{
// Store the strategy's prior cumulated realized profit and number of trades
priorTradesCumProfit = Performance.AllTrades.TradesPerformance.Currency.C umProfit;

/* NOTE: Using .AllTrades will include both historical virtual trades as well as real-time trades.
If you want to only count profits from real-time trades please use .RealtimeTrades. */
}

/* Prevents further trading if the current session's realized profit exceeds $1*/
if (Performance.AllTrades.TradesPerformance.Currency. CumProfit - priorTradesCumProfit >= 1)
{
// Returns out of the OnBarUpdate() method. This prevents any further evaluation of trade logic in the OnBarUpdate() method.
return;
}

// Make sure this strategy does not execute against historical data
if (Historical)
return;

Not sure if having 2 places where it says return; will be an issue? I did a market replay and it still took a second trade.

NinjaTrader_Austin
07-07-2009, 11:26 AM
M3power, if you're trying to use performance metrics with an ATM strategy, take a look at the ATM profit/loss (http://www.ninjatrader-support.com/HelpGuideV6/AsmStrategyRealizedProfitLoss.html) reference page. Here is another link for if you're interested in unrealized ATM profit/loss (http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?AsmStrategyUnrealizedProfitLoss).

m3power222
07-07-2009, 11:34 AM
M3power, if you're trying to use performance metrics with an ATM strategy, take a look at the ATM profit/loss (http://www.ninjatrader-support.com/HelpGuideV6/AsmStrategyRealizedProfitLoss.html) reference page. Here is another link for if you're interested in unrealized ATM profit/loss (http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?AsmStrategyUnrealizedProfitLoss).

Would it be easier just to find out if a target is filled or stop moved?

NinjaTrader_Austin
07-07-2009, 12:28 PM
Would it be easier just to find out if a target is filled or stop moved?
It is certainly a possiblity that what you're suggesting here is easier. Reference for getting ATM stop and target orders (http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?GetAtmStrategyStopTargetOrderStatus ).

m3power222
07-09-2009, 02:06 AM
I ended up using this and it appears to work:

// Prevents a second trade if first trade was profitable
if (GetAtmStrategyRealizedProfitLoss(atmStrategyId) > 0)
{
entrylong = false;
entryshort = false;

The question I have is every new day does GetAtmStrategyRealizedProfitLoss look at the current day?

If not then it won't take the next days trade if it includes the previous days win.

NinjaTrader_Bertrand
07-09-2009, 05:24 AM
m3power222, I believe this is a daytrading strategy without overnight positions, so it should only reflect the current day in this case.

m3power222
07-09-2009, 07:34 AM
m3power222, I believe this is a daytrading strategy without overnight positions, so it should only reflect the current day in this case.

Is there anyone that can verify this as my goal is to leave the strategy on 24x7.

There is no way to test on market replays as ver 6.5 can't string the mutiple replay days together.

NinjaTrader_Austin
07-09-2009, 07:41 AM
M3, GetAtmStrategyRealizedProfitLoss only returns the profit/loss for that particular strategy ID, and each strategy ID holds only one trade. The concept of current day/previous day doesn't really apply.

m3power222
07-09-2009, 07:49 AM
Thank you guys.