Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Mutiple Position exit question
Collapse
X
-
Mutiple Position exit question
If I am using a strategy that opens 2 different positions, 1 in the eur/usd and 1 in the gbp/usd using BarsInProgress, and I get to a profit of 5 pips, what is the easiest way to simply exit the positions (prior to the close of the bar)???Tags: None
-
Bertrand,
I don't want to have a profit target of 5 pips for each one....what I want to do is, let's say that EUR is up 17 and GBP/USD is down 12, or if GBP/USD is up 44 and EUR/USD is down 39, or if EUR/USD is up 6 and GBP is down 1, etc., there is an overall profit of 5. Does that make sense? In other words, if my strategy opens up both positions using BarsArray, I want to exit the positions when there is an overall profit a 5. How can I achieve this? I tried if (Postion.AvgPrice * TickSize == 5), then close the positions, but it doesn't close them????
Comment
-
Bertrand.... Please be more specific! I just want to figure out how to program if I have a total profit of 5 with my 2 positions ...... close out. I tried what you said and have had no luck. Can you please be more specific? Help me out with the "double" thing please......
Comment
-
Here it is Bertrand..... I just want to exit when the profit is 5 pips, not neccessarily at the end of the bar......
protected override void Initialize()
{
Add("$GBPUSD", PeriodType.Minute, 1);
TraceOrders = true;
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
{
if (Historical)
return;
}
// Checks if OnBarUpdate() is called from an update on EUR/USD minute Bars
if (BarsInProgress == 0)
{
EnterLong(DefaultQuantity, "EUR/USD Long");
}
// Checks if OnBarUpdate() is called from an update on GBP/USD minute Bars
if (BarsInProgress == 1)
{
EnterShort(DefaultQuantity, "GBP/USD Short");
}
// Positions[0] is the position of the EUR/USD and Positions[1] is that of the GBP/USD
myPnl = Positions[0].GetProfitLoss(Closes[0][0], PerformanceUnit.Points) + Positions[1].GetProfitLoss(Closes[1][0], PerformanceUnit.Points);
if (myPnl == 5)
{
ExitLong();
ExitShort();
}
Comment
-
Josh.....
If I compile this as is, it says "The name 'myPnl' does not exist in the current context
If I add:
public double myPnl
{
get { return myPnl; }
set { myPnl = Math.Max(1, value); }
}
to the #region Properties, it compiles fine, but when I try to load it to a chart, Ninjatrader crashes! Does that make sense?
Comment
-
Here is what my #region Properties looks like:
#region Properties
[Description("")]
[Category("Parameters")]
public int MyInput0
{
get { return myInput0; }
set { myInput0 = Math.Max(1, value); }
}
public double myPnl
{
get { return myPnl; }
set { myPnl = Math.Max(1, value); }
}
#endregion
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
669 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
378 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
111 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
575 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
581 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment