NexusFi: Find Your Edge


Home Menu

 





Manual entry, automated exit (Ninja Trader or other)?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one peaceland with 7 posts (0 thanks)
    2. looks_two MWinfrey with 6 posts (11 thanks)
    3. looks_3 monpere with 5 posts (12 thanks)
    4. looks_4 Xav1029 with 5 posts (6 thanks)
      Best Posters
    1. looks_one monpere with 2.4 thanks per post
    2. looks_two MWinfrey with 1.8 thanks per post
    3. looks_3 Xav1029 with 1.2 thanks per post
    4. looks_4 bnichols with 0.7 thanks per post
    1. trending_up 17,079 views
    2. thumb_up 35 thanks given
    3. group 13 followers
    1. forum 35 posts
    2. attach_file 2 attachments




 
Search this Thread

Manual entry, automated exit (Ninja Trader or other)?

  #21 (permalink)
 
bnichols's Avatar
 bnichols 
Dartmouth NS
 
Experience: Intermediate
Platform: MC, MC.Net, NT, TWS
Broker: IB / IQFeed / Kids
Trading: Forex, stocks
Posts: 637 since Feb 2010
Thanks Given: 64
Thanks Received: 460

Perhaps checking when no positions open. I believe a workaround may be

if(Position.MarketPosition == MarketPosition.Long)
[...]
which allows NT to handle the indices in any case.

Visit my NexusFi Trade Journal Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Futures True Range Report
The Elite Circle
Are there any eval firms that allow you to sink to your …
Traders Hideout
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
36 thanks
NexusFi site changelog and issues/problem reporting
22 thanks
The Program
20 thanks
GFIs1 1 DAX trade per day journal
19 thanks
  #22 (permalink)
 
monpere's Avatar
 monpere 
Bala, PA, USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus, IB
Trading: SPY, Oil, Euro
Posts: 1,854 since Jul 2010
Thanks Given: 300
Thanks Received: 3,371


MWinfrey View Post
Ok...for me this is uncharted territory. I have the buttons working and attempting to add the code that will manage the trade. However, I'm having issues.

 
Code
if (NinjaTrader.Cbi.Globals.Accounts[0].Positions[0].MarketPosition == MarketPosition.Long)
... do something
However, I get an error saying "You are accessing an index with a value that is invalid since its out of range." Which doesn't surprise me. However, how do I set Accounts[0] and Positions[0] to something meaningful so I don't get that error? I had to swallow a bit of pride just to ask this question because I should be able to figure this out without asking. But, not getting anywhere.

Thanks,
Mike

I use this to check for open positions in Account[0] because I am generally connected to only one account, but if you generally are connected to multiple accounts, you would have to loop through the NinjaTrader.Cbi.Globals.Accounts[x] array as well.

 
Code
	//### Open Positions
if ( NinjaTrader.Cbi.Globals.Accounts.Count > 0 && NinjaTrader.Cbi.Globals.Accounts[0].Positions.Count > 0 ) {
	for (int i=0; i < NinjaTrader.Cbi.Globals.Accounts[0].Positions.Count; i++ ) {
		if ( NinjaTrader.Cbi.Globals.Accounts[0].Positions[i].Instrument.FullName == Instrument.FullName ) {
			Print(NinjaTrader.Cbi.Globals.Accounts[0].Name +" Position " +(i+1) +". "
			+NinjaTrader.Cbi.Globals.Accounts[0].Positions[i].Instrument.FullName +" "
			+NinjaTrader.Cbi.Globals.Accounts[0].Positions[i].MarketPosition +" "
			+NinjaTrader.Cbi.Globals.Accounts[0].Positions[i].Quantity +" "
			+"@"+NinjaTrader.Cbi.Globals.Accounts[0].Positions[i].AvgPrice+" "
			);
		}
	}
}

Reply With Quote
Thanked by:
  #23 (permalink)
 
MWinfrey's Avatar
 MWinfrey 
Lubbock TX
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Stage 5 Trading
Trading: CL
Posts: 1,878 since Jul 2009
Thanks Given: 1,450
Thanks Received: 3,335



monpere View Post
I use this to check for open positions in Account[0] because I am generally connected to only one account, but if you generally are connected to multiple accounts, you would have to loop through the NinjaTrader.Cbi.Globals.Accounts[x] array as well.

Thank you @monpere...that got me off top dead center.

Reply With Quote
  #24 (permalink)
peaceland
Lomita, CA/USA
 
Posts: 8 since Sep 2012
Thanks Given: 0
Thanks Received: 0


monpere View Post
There are all sorts of issues with MB Trading if your want to do anything innovative. Their systems and infrastructure are just antiquated. They have to shutdown after market everyday for maintenance, their responses to order executions and modifications are slow, they have regular unscheduled outages, the market will go through your orders by several ticks and you will not get fills. The only redeeming things I found were are that you can trade micro lots, and they pay you when you provide liquidity with limit orders. That's been my experience with them.

You can do most the things you want with various other brokers. I personally use Interactive Brokers and Mirus Futures to reliably do some of these things.

Don't have enough capital to open an IB account. What other FX brokers are reliable that I can work with? I looked for quite a while and MB seemed the best one for the $2k I have to start with.

Reply With Quote
  #25 (permalink)
peaceland
Lomita, CA/USA
 
Posts: 8 since Sep 2012
Thanks Given: 0
Thanks Received: 0

Since I am having so much trouble figuring out how to automate exits, what do you all think of Managed Forex Accounts? I know that you all prefer to do your own trading. I feel the same. But at this point, am not avail. to watch the account all night long...

What about doing something like this until I am able to resolve the issue?
Managed Forex Account | Forex Managed Accounts

Reply With Quote
  #26 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,399 since Jun 2009
Thanks Given: 33,173
Thanks Received: 101,538


peaceland View Post
Don't have enough capital to open an IB account. What other FX brokers are reliable that I can work with? I looked for quite a while and MB seemed the best one for the $2k I have to start with.

Please use the Brokers section of the forum for this question, not this thread which is for NinjaTrader "Manual entry, automated exit".

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #27 (permalink)
 
MWinfrey's Avatar
 MWinfrey 
Lubbock TX
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Stage 5 Trading
Trading: CL
Posts: 1,878 since Jul 2009
Thanks Given: 1,450
Thanks Received: 3,335


monpere View Post
 
Code
	//### Open Positions
if ( NinjaTrader.Cbi.Globals.Accounts.Count > 0 && NinjaTrader.Cbi.Globals.Accounts[0].Positions.Count > 0 ) {
	for (int i=0; i < NinjaTrader.Cbi.Globals.Accounts[0].Positions.Count; i++ ) {
		if ( NinjaTrader.Cbi.Globals.Accounts[0].Positions[i].Instrument.FullName == Instrument.FullName ) {
			Print(NinjaTrader.Cbi.Globals.Accounts[0].Name +" Position " +(i+1) +". "
			+NinjaTrader.Cbi.Globals.Accounts[0].Positions[i].Instrument.FullName +" "
			+NinjaTrader.Cbi.Globals.Accounts[0].Positions[i].MarketPosition +" "
			+NinjaTrader.Cbi.Globals.Accounts[0].Positions[i].Quantity +" "
			+"@"+NinjaTrader.Cbi.Globals.Accounts[0].Positions[i].AvgPrice+" "
			);
		}
	}
}

@monpere using the construct you provided is very helpful. I added a condition to exit a trade and then added Strategy.ExitLong() if the exit condition is met. Unfortunately, I get an error "Object reference not set to an instance of an object." I loop through the accounts and positions arrays to get the right ones but yet I get that error. Have I given enough for you to know what might be happening?

Reply With Quote
  #28 (permalink)
 Felix trader 
California - USA/Rio grande do sul-Brasil.
 
Experience: Intermediate
Platform: tradestation, ninja trader
Trading: Futuros
Posts: 88 since Apr 2011
Thanks Given: 851
Thanks Received: 23

Could you help me with this risk control? I have created an strategy with two targets for the Ninja Trader ATM DOM, both of them with 8ticks of inicial stop, then I put a trailing stop with frequency on ONE. But what Im looking for is that, when the trade goes bad, itch tick it goes back, the target also goes back one tick as the profit. Do you get it? An example: My stop is 8, and my target is also on 8, but if it goes bad, ich tick it goes, the stop will be 7, the target 7... Thats it, waiting for answers. Thank you!

Reply With Quote
  #29 (permalink)
 
monpere's Avatar
 monpere 
Bala, PA, USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus, IB
Trading: SPY, Oil, Euro
Posts: 1,854 since Jul 2010
Thanks Given: 300
Thanks Received: 3,371


Felix trader View Post
Could you help me with this risk control? I have created an strategy with two targets for the Ninja Trader ATM DOM, both of them with 8ticks of inicial stop, then I put a trailing stop with frequency on ONE. But what Im looking for is that, when the trade goes bad, itch tick it goes back, the target also goes back one tick as the profit. Do you get it? An example: My stop is 8, and my target is also on 8, but if it goes bad, ich tick it goes, the stop will be 7, the target 7... Thats it, waiting for answers. Thank you!

I don't do any trade management within the indicator, and I am not a fan of instantiating a strategy from within an indicator. All my trade management is done in a stand alone strategy started in the strategy tab.

Reply With Quote
Thanked by:
  #30 (permalink)
 
MWinfrey's Avatar
 MWinfrey 
Lubbock TX
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Stage 5 Trading
Trading: CL
Posts: 1,878 since Jul 2009
Thanks Given: 1,450
Thanks Received: 3,335


I wrote an indicator that is intended to automatically exit trades while still being able to use the ChartTrader to enter trades. So in other words, Manual Entry --- Automated Exit.

This code does not have buttons and runs just like any other indicator. It's very basic as you can tell by looking at the code. However, there is a problem that I need help with. The ExitShort or ExitLong causes an error "Object reference not set to an instance of an object."

I'm not sure what object reference it's referring to and have spent a lot of time trying to figure it out. So, I thought I'd present it here to see if anyone else can figure it out.

Once this problem is solved I can move on to making this indicator more functional...I hope.

Thanks,
Mike

Attached Files
Elite Membership required to download: ManageTrades.cs
Reply With Quote
Thanked by:




Last Updated on March 1, 2020


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts