if (Positions[0].GetProfitLoss(Close[0], PerformanceUnit.Currency) + Positions[1].GetProfitLoss(Close[0], PerformanceUnit.Currency) > 0.00 )
{
ExitLong("","");
ExitLong(1,"","");
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
combined P&L, multi instrument strategy
Collapse
X
-
combined P&L, multi instrument strategy
Hi,
the above should be calculating the combined unrealized P&L of the two instruments in the strategy. Correct? It seems to be not doing that. it doesn't exit the positions. neither of the positions are exited.Code:Tags: None
-
Originally posted by NinjaTrader_Bertrand View Postcalhawk01, in which BarsInProgress do you call that portion? You pass in Close[0] as reference price for both instruments in, that's likely where it breaks. I would first add in a print to see exactly when it triggers and what you calculate value wise.
i tried adding both barsinprogress. still doesnt work. please help!Code:if (BarsInProgress == 0 && BarsInProgress ==1 && Positions[1].MarketPosition == MarketPosition.Long && Positions[0].MarketPosition == MarketPosition.Long && Positions[0].GetProfitLoss(Close[0], PerformanceUnit.Currency) + Positions[1].GetProfitLoss(Close[0], PerformanceUnit.Currency) > 0.00) { ExitLong("PrimaryBuy","PrimarySell"); ExitLong(1,"HedgeBuy","HedgeSell"); }
Comment
-
I would not execute from both, as you would need to have the situtation then where both actually are called for the same timestamp, primary should be fine.
Also would pass in then Closes[1] for the second call to calculate the pnl based on the secondary instruments close price and not the primary as in your call.
Comment
-
Originally posted by NinjaTrader_Bertrand View PostI would not execute from both, as you would need to have the situtation then where both actually are called for the same timestamp, primary should be fine.
Also would pass in then Closes[1] for the second call to calculate the pnl based on the secondary instruments close price and not the primary as in your call.
I'm having a hard time following your reply.
And i tried changing the secondary "close" to close[1].. the second hard position still did not exit. only the primary did.
can you please give me an example? ive been working on the for past 24 hours
would really appreciate your help..
Did not work..Code:if (BarsInProgress == 0 && BarsInProgress ==1 && Positions[1].MarketPosition == MarketPosition.Long && Positions[0].MarketPosition == MarketPosition.Long && Positions[0].GetProfitLoss(Close[0], PerformanceUnit.Currency) + Positions[1].GetProfitLoss(Close[1], PerformanceUnit.Currency) > 0.00) { ExitLong("PrimaryBuy","PrimarySell"); ExitLong(1,"HedgeBuy","HedgeSell"); }
Comment
-
Originally posted by calhawk01 View PostI'm having a hard time following your reply.
And i tried changing the secondary "close" to close[1].. the second hard position still did not exit. only the primary did.
can you please give me an example? ive been working on the for past 24 hours
would really appreciate your help..
Did not work..Code:if (BarsInProgress == 0 && BarsInProgress ==1 && Positions[1].MarketPosition == MarketPosition.Long && Positions[0].MarketPosition == MarketPosition.Long && Positions[0].GetProfitLoss(Close[0], PerformanceUnit.Currency) + Positions[1].GetProfitLoss(Close[1], PerformanceUnit.Currency) > 0.00) { ExitLong("PrimaryBuy","PrimarySell"); ExitLong(1,"HedgeBuy","HedgeSell"); }- "BarsInProgress == 0 && BarsInProgress ==1" is an impossible condition, and means that your filter will always be identically false.
- Close based on BarsArray[1] is Closes[1], not Close[1].
You can try this:
Code:if (BarsInProgress == 0 && Positions[1].MarketPosition == MarketPosition.Long && Positions[0].MarketPosition == MarketPosition.Long && Positions[0].GetProfitLoss(Close[0], PerformanceUnit.Currency) + Positions[1].GetProfitLoss([B][COLOR=Red]Closes[1][0][/COLOR][/B], PerformanceUnit.Currency) > 0.00)
Comment
-
Originally posted by koganam View Post- "BarsInProgress == 0 && BarsInProgress ==1" is an impossible condition, and means that your filter will always be identically false.
- Close based on BarsArray[1] is Closes[1], not Close[1].
You can try this:
Code:if (BarsInProgress == 0 && Positions[1].MarketPosition == MarketPosition.Long && Positions[0].MarketPosition == MarketPosition.Long && Positions[0].GetProfitLoss(Close[0], PerformanceUnit.Currency) + Positions[1].GetProfitLoss([B][COLOR=Red]Closes[1][0][/COLOR][/B], PerformanceUnit.Currency) > 0.00)
Still doesnt work
i feel like pulling my hair out... below is the entire strat
i've tried moving the bolded at the end and at the beginning..Code:protected override void OnBarUpdate() { [B] if (BarsInProgress == 0 && Positions[1].MarketPosition == MarketPosition.Long && Positions[0].MarketPosition == MarketPosition.Long && Positions[0].GetProfitLoss(Close[0], PerformanceUnit.Currency) + Positions[1].GetProfitLoss(Closes[1][0], PerformanceUnit.Currency) > 0.00) { ExitLong("",""); ExitLong(1,"",""); }[/B] if (Positions[0].MarketPosition == MarketPosition.Flat && Positions[1].MarketPosition == MarketPosition.Flat && Close[0] > 0) { EnterLong(0,PrimaryQuantity, "PrimaryBuy"); } if (Positions[1].MarketPosition == MarketPosition.Flat && Close[0] < (Positions[0].AvgPrice-hedge)) { EnterLong(1,HedgeQuantity, "HedgeBuy"); } }
Comment
-
Is that the entirety of your OBU handler? If so, you are missing a CurrentBars check to be sure that you have valid data. There should be an entry in your log about the error. Look up "CurrentBars" in the NT Help.Originally posted by calhawk01 View PostStill doesnt work
i feel like pulling my hair out... below is the entire strat
i've tried moving the bolded at the end and at the beginning..Code:protected override void OnBarUpdate() { [B] if (BarsInProgress == 0 && Positions[1].MarketPosition == MarketPosition.Long && Positions[0].MarketPosition == MarketPosition.Long && Positions[0].GetProfitLoss(Close[0], PerformanceUnit.Currency) + Positions[1].GetProfitLoss(Closes[1][0], PerformanceUnit.Currency) > 0.00) { ExitLong("",""); ExitLong(1,"",""); }[/B] if (Positions[0].MarketPosition == MarketPosition.Flat && Positions[1].MarketPosition == MarketPosition.Flat && Close[0] > 0) { EnterLong(0,PrimaryQuantity, "PrimaryBuy"); } if (Positions[1].MarketPosition == MarketPosition.Flat && Close[0] < (Positions[0].AvgPrice-hedge)) { EnterLong(1,HedgeQuantity, "HedgeBuy"); } }
ref: http://www.ninjatrader.com/support/h...urrentbars.htm
Comment
-
Originally posted by koganam View PostIs that the entirety of your OBU handler? If so, you are missing a CurrentBars check to be sure that you have valid data. There should be an entry in your log about the error. Look up "CurrentBars" in the NT Help.
ref: http://www.ninjatrader.com/support/h...urrentbars.htm
i addedbut it did not make any difference. it's still not executing the exit order for the secondary data series! it enters the trade but doesnt want to exit it.Code:if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired ) return;
NT support can you please advise?
Comment
-
Originally posted by calhawk01 View Posti addedbut it did not make any difference. it's still not executing the exit order for the secondary data series! it enters the trade but doesnt want to exit it.Code:if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired ) return;
NT support can you please advise?
the only thing that does work is ''flatten all position'' feature. but that shuts the strategy down. any way to keep the strategy going?
Comment
-
Output:
But the signalname does match...5/2/2014 10:00:00 AM Ignored PlaceOrder() method at 5/2/2014 10:00:00 AM: Action=Sell OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='HedgeSell' FromEntrySignal='HedgeBuy' Reason='SignalName does not have a matching FromEntrySignal to exit'is my entryCode:if (Positions[1].MarketPosition == MarketPosition.Flat && Close[0] < (Positions[0].AvgPrice-hedge)) { EnterLong(1,HedgeQuantity, "HedgeBuy"); }
Comment
-
finally got it working.. the issue was the Exit command
the correct one isquestion:Code:ExitLong(PrimaryQuantity,"PrimaryCombined","PrimaryBuy"); ExitLong(1,HedgeQuantity,"HedgeCombined", "HedgeBuy");
gives the unrealized P&L based on current bid on secondary instrument. correct?Code:Positions[1].GetProfitLoss(GetCurrentBid(1), PerformanceUnit.Currency)
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
562 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
325 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
547 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
547 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment