Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Unintened Position Reversals
Collapse
X
-
Unintened Position Reversals
If i am in a Long and teh entry signal for a Short happens i do not want to exit my Long. I only want to exit my long when one of my conditional long exits happen. Right now a Short will exit me and then create a new short entry. is there a way to prevent that from happening?Tags: None
-
Unintended Position Reversal
I have this programmed thru the Ninja GUI. how do i ensure that the position is flat before the program enters trade. This is not a case of turning it on teh first time - this happens when it is running and enterting subsequent trades.
Comment
-
I have a similar situation as hifreq posted in #1 except I want to take the short trade and stay in the long. I cannot use Position.MarketPosition == MarketProsition.Flat (as Josh suggested in #2) to enter the short because I want to be in both positions. Is there a way to satisfy both positions?
Comment
-
CaptainAmericaXX,
You cannot be long and short at the same time with the Managed approach of strategy programming. If you want to do this you will have to use the Unmanaged approach outlined here: http://www.ninjatrader.com/support/h...er_methods.htmJosh P.NinjaTrader Customer Service
Comment
-
Thank you for the reply. I've now entered the realm of the Unmanaged Approach. I'm doing something wrong because I get no trades and nothing in the Output window. The Output window does say that the strategy is enabled, but I get no other strings. Also none of my previous Managed strategies will run now. Anyone have any suggestions as to why this is so?
Here is a simple code I wrote to see if I was understanding the unmanaged approach:
private IOrder BullQuickI = null;
private IOrder BullRunnerI = null;
private IOrder BearQuickI = null;
private IOrder BearRunnerI = null;
protected override void Initialize()
{
Unmanaged = true;
CalculateOnBarClose = true;
}
protected override void OnBarUpdate()
{
// Bull Moves set 1
if (CrossBelow(MACD(12, 26, 9).Avg, MACD(12, 26, 9), 1)
&& BullQuickI == null
&& BullRunnerI == null)
{
BullQuickI = SubmitOrder(0, OrderAction.Buy, OrderType.Market, 1, 0, 0, "", "BullQuickI");
BullRunnerI = SubmitOrder(0, OrderAction.Buy, OrderType.Market, 1, 0, 0, "", "BullRunnerI");
}
//Conditions to Exit BullQuickI
if (Close[0] > Position.AvgPrice
&& m_inBullQuickMove
&& Falling(RMI(10, 3)) == true)
{
BullQuickI = SubmitOrder(0, OrderAction.BuyToCover, OrderType.Market, 1, 0, 0, "", "BullQuickI");
m_inBullQuickMove = false;
Print(Time[0] + " Exit Bull Quick Exit I ");
}
//Conditions to Exit BullRunnerI
if (m_inBullRunner && Close[0] < VMAZones (9, 2, 18).Lower[0]
&& BullRunnerExitOK
&& TrendStrengthA(VC.NinjaScript.Utility.MovingAverag eType.VWMA, 200, 20, 10).TrendStrength[0] < 60
&& Falling(RMI(10, 3)) == true)
{
BullRunnerI = SubmitOrder(0, OrderAction.BuyToCover, OrderType.Market, 1, 0, 0, "", "BullRunnerI");
m_inBullRunner = false;
BullRunnerExitOK = false;
Print(Time[0] + " BullRunnerExitOK = false");
}
//Breakeven for BullRunnerI
if(m_inBullRunner && !m_inBullQuickMove
&& Close[0] < Position.AvgPrice)
{
BullRunnerI = SubmitOrder(0, OrderAction.BuyToCover, OrderType.Market, 1, 0, 0, "", "BullRunnerI");
m_inBullRunner = false;
BullRunnerExitOK = false;
Print(Time[0] + " BullRunnerExitOK = false");
}
// Bear Moves
if (CrossAbove(MACD(12, 26, 9).Avg, MACD(12, 26, 9), 1)
&& BearQuickI == null
&& BearRunnerI == null)
{
BearQuickI = SubmitOrder(0, OrderAction.Sell, OrderType.Market, 1, 0, 0, "", "BearQuickI");
BearRunnerI = SubmitOrder(0, OrderAction.Sell, OrderType.Market, 1, 0, 0, "", "BearRunnerI");
}
//Conditions to Exit BearQuickI
//Condition 1: Simple Rising RMI
if (Close[0] < Position.AvgPrice
&& m_inBearQuickMove
&& Rising(RMI(10, 3)) == true)
{
BearQuickI = SubmitOrder(0, OrderAction.SellShort, OrderType.Market, 1, 0, 0, "", "BearQuickI");
m_inBearQuickMove = false;
Print(Time[0] + " Exit Bear Quick MoveI (rising RMI)");
}
//Conditions to Exit BearRunnerI
if (m_inBearRunner && Close[0] > VMAZones (9, 2, 18).Upper[0]
&& BearRunnerExitOK
&& TrendStrengthA(VC.NinjaScript.Utility.MovingAverag eType.VWMA, 200, 20, 10).TrendStrength[0] > -60
&& Rising(RMI(10, 3)) == true)
{
BearRunnerI = SubmitOrder(0, OrderAction.SellShort, OrderType.Market, 1, 0, 0, "", "BearRunnerI");
m_inBearRunner = false;
BearRunnerExitOK = false;
Print(Time[0] + " BearRunnerExitOK = false");
}
//Breakeven for BearRunnerI
if(m_inBearRunner && !m_inBearQuickMove
&& Close[0] > Position.AvgPrice)
{
BearRunnerI = SubmitOrder(0, OrderAction.SellShort, OrderType.Market, 1, 0, 0, "", "BearRunnerI");
m_inBearRunner = false;
BearRunnerExitOK = false;
Print(Time[0] + " BearRunnerExitOK = false");
}
}
Comment
-
Ok, just tried that and yes I get a message on every updated bar, but nothing else. And no errors in the log.
Comment
-
Hello,
Ok if no other prints then this means that your entry conditions are not getting filled.
As I see you have Prints by your SubmitOrders. However if we dont even get these it means that the condition is not running.
Therefor we would need to look into your entry order condition is where the problem is. Start pulling items out until you see the Print statement for one of your SubmitOrders fires.
I look forward to assisting you further.BrettNinjaTrader Product Management
Comment
-
For the purpose of this trial (just figuring out how to use the Unmanaged Approach) I picked a simple MACD cross for the entry conditions. Can't get any simpler than that. So I can't take anything out. Also NONE of my other managed strategies will take trades now. I can get the Print() to print things such as a MACD cross, but no trades will fire and the Print() will not work in conjunction with a trade.
Comment
-
Hello,
Alright lets backup here. As I need a full pictures of whats going on to assist here.
So now you are able to get output and you are getting the prints next to your entry conditions?
Is this a different script then what you posted below as the script below is more then simple MA cross.
Can you post your simple MA crossover code (Full Code) so I can run it on my side.
I look forward to assisting you further.BrettNinjaTrader Product Management
Comment
-
Thanks for your help Brett. Yes I'm getting script from the Print() on the first line of the OnBarUpdate. No I'm not getting any script from the entry conditions. Please disregard what I said about my other strategies not running that wasn't accurate. The entire code for the strategy in question is in post #7. Thanks again for taking a look at it.
Comment
-
Alright thanks for clarification.
The script below needs to be further simplified before I can run it on my side. Please create a copy called simplified version and then remove out exit conditions. Remove out extra checks to submit the entries. Make it as basic as possible. Then re post the simplified version of the code that tried to submit a simply entry order and fails to do so then I will run and find the issue for you.
I look forward to assisting you further.BrettNinjaTrader Product Management
Comment
-
Ok here is the simplified code. I tested it out and it takes 1 trade now, but without specific exit conditions the short cancels the long instead of both trades continuing until a BuyToCover or SellShort. Also once that 1st trade fires no other trades are called. Obviously there is something here I don't understand. Thanks for your help.
#region IOrder Entries
private IOrder BullQuickI = null;
private IOrder BullRunnerI = null;
private IOrder BearQuickI = null;
private IOrder BearRunnerI = null;
#endregion
protected override void Initialize()
{
Unmanaged = true;
CalculateOnBarClose = true;
}
protected override void OnBarUpdate()
{
if (CrossBelow(MACD(12, 26, 9).Avg, MACD(12, 26, 9), 1)
&& BullQuickI == null
&& BullRunnerI == null)
{
BullQuickI = SubmitOrder(0, OrderAction.Buy, OrderType.Market, 1, 0, 0, "", "BullQuickI");
BullRunnerI = SubmitOrder(0, OrderAction.Buy, OrderType.Market, 1, 0, 0, "", "BullRunnerI");
Print(Time[0] + " Bull");
}
// Bear Moves
if (CrossAbove(MACD(12, 26, 9).Avg, MACD(12, 26, 9), 1)
&& BearQuickI == null
&& BearRunnerI == null)
{
BearQuickI = SubmitOrder(0, OrderAction.Sell, OrderType.Market, 1, 0, 0, "", "BearQuickI");
BearRunnerI = SubmitOrder(0, OrderAction.Sell, OrderType.Market, 1, 0, 0, "", "BearRunnerI");
Print(Time[0] + " Bear");
}
}
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
595 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
343 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 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
556 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
554 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment