NexusFi: Find Your Edge


Home Menu

 





Flatten all trades NT8 help


Discussion in NinjaTrader

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




 
Search this Thread
  #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?
Iran and Israel Stand Down: What $9M in Peace Contracts …
Prediction Markets & Event Contracts
April CPI Preview: +3.7% YoY Expected at 8:30 AM ET -- C …
Traders Hideout
Irans Dual Probability: Guns Quiet at 99.95% While Forma …
Prediction Markets & Event Contracts
Warsh Opens Today, Hormuz June 19 -- WTI Below $80, Fran …
Prediction Markets & Event Contracts
Would a node-based workflow for automated trading be useful?
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
10 thanks
Darmok and Jalad at Tanagra
3 thanks
Big Mike in Ecuador
1 thanks
30 Sessions
1 thanks




Last Updated on May 1, 2017


© 2026 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 - Downloads - Top
no new posts