if (Positions[0].GetProfitLoss(Close[0], PerformanceUnit.Currency) + Positions[1].GetProfitLoss(Close[0], PerformanceUnit.Currency) > 0.00 ) { ExitLong("",""); ExitLong(1,"",""); }
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
combined P&L, multi instrument strategy
Collapse
X
-
combined P&L, multi instrument strategy
Hi,
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.
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.BertrandNinjaTrader Customer Service
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..
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..
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
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
-
Originally posted by calhawk01 View PostStill doesnt work i feel like pulling my hair out... below is the entire strat
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 addedCode:if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired ) return;
NT support can you please advise?
Comment
-
Originally posted by calhawk01 View Posti addedCode: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:
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'Code: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 isCode:ExitLong(PrimaryQuantity,"PrimaryCombined","PrimaryBuy"); ExitLong(1,HedgeQuantity,"HedgeCombined", "HedgeBuy");
Code:Positions[1].GetProfitLoss(GetCurrentBid(1), PerformanceUnit.Currency)
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by GussJ, 03-04-2020, 03:11 PM
|
11 responses
3,229 views
0 likes
|
Last Post Today, 08:07 PM | ||
Started by andrewtrades, Today, 04:57 PM
|
1 response
14 views
0 likes
|
Last Post Today, 05:02 PM | ||
Started by chbruno, Today, 04:10 PM
|
0 responses
7 views
0 likes
|
Last Post
by chbruno
Today, 04:10 PM
|
||
Started by josh18955, 03-25-2023, 11:16 AM
|
6 responses
441 views
0 likes
|
Last Post
by Delerium
Today, 03:42 PM
|
||
Started by FAQtrader, Today, 03:35 PM
|
0 responses
12 views
0 likes
|
Last Post
by FAQtrader
Today, 03:35 PM
|
Comment