NexusFi: Find Your Edge


Home Menu

 





Flatten all trades NT8 help


Discussion in NinjaTrader

Updated
    1. trending_up 1,934 views
    2. thumb_up 1 thanks given
    3. group 1 followers
    1. forum 1 posts
    2. attach_file 0 attachments




 
Search this Thread

Flatten all trades NT8 help

  #1 (permalink)
 ElBi 
North Bergen
 
Experience: Beginner
Platform: NinjaTrader
Trading: Cl, ZB
Posts: 4 since Feb 2017
Thanks Given: 2
Thanks Received: 1

Good afternoon all.

I looked around and am trying to set a strategy that oversees the account and closes out and disables all the strategies I have on my account when I reach a 1000 profit target or a 870 loss.

 
Code
NinjaTrader.Gui.SuperDom.SuperDom.FlattenEverything()
does not work on NT8.

Here is my code:

 
Code
myAccount = Account.All.FirstOrDefault(a => a.Name == "Sim101");

 
Code
if (myAccount.Get(AccountItem.UnrealizedProfitLoss, Currency.UsDollar) >= 1000 )
{
	 Account.FlattenEverything();
			
	Print("1000 hit PnL: " + myAccount.Get(AccountItem.UnrealizedProfitLoss, Currency.UsDollar) + " " + Times[0][0].TimeOfDay);
		
				
} 
			

			
			
if (myAccount.Get(AccountItem.UnrealizedProfitLoss, Currency.UsDollar) <= -870)
 {
	 Account.FlattenEverything(); 
				

	Print("-870 hit PnL: " + myAccount.Get(AccountItem.UnrealizedProfitLoss, Currency.UsDollar)+ " @ " + Times[0][0].TimeOfDay);
		   
		
} //END OF DD CLOSE CHECK!
			

if ((Times[0][0].DayOfWeek == DayOfWeek.Friday) && (Times[0][0].TimeOfDay >= new TimeSpan(16, 40, 0)))
{
	Account.FlattenEverything();
} //END OF FRIDAY EXIT A FEW MINS BEFORE CLOSE

As soon as I enable this, it disables all the strategies. Is there something I missed in the "If" statements?

Thank you!!

Solution:

Turnes out that if you use
 
Code
Times[0][0].
it goes thru all the bars on the chart and sure enough, there were two Friday 16:40 bars on the chart.

Correction:

Use
 
Code
DateTime.Now
and it will only check future bars.

Thanks for your time!! Hope someone will learn from my blunders!

Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
MC PL editor upgrade
MultiCharts
Trade idea based off three indicators.
Traders Hideout
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Quant vue
Trading Reviews and Vendors
 




Last Updated on May 1, 2017


© 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