NexusFi: Find Your Edge


Home Menu

 





Ninjatrader simple code to exit all L and S positions at a particular time.


Discussion in NinjaTrader

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




 
Search this Thread

Ninjatrader simple code to exit all L and S positions at a particular time.

  #1 (permalink)
 birdoggg 
Charlotte, NC/USA
 
Experience: Advanced
Platform: NT, TOS
Broker: Mirus/ZF, AMP/CQG, TOS, MBT
Trading: Futures, Stocks, Bonds, Forex
Posts: 37 since May 2011
Thanks Given: 56
Thanks Received: 9

Hey folks,

RE: Ninjatrader Strategy time to exit all L and S positions (not using the NT system Flatten but code to put into the Strategy)...here is a snapshot..

In a Strategy I will like for it to exit any open positions in that Strategy only at a particular time during the day while keeping the Strategy running. I already have the time frames to actually take trades set, but just need it to exit all positions at a particular time and then let the next trade happen per the time frames I set. I already have used your thread on timefilters so thanks for that...however, it does not seem to address exiting all positions at x time.

I don't want to flatten all positions totally with other trades I may be in with other Strategies or manual trades within the Options>Data>Misc. Flatten all in NT...it should be in each Strategy that is deployed.

What I have it doing per the timefilters thread is:

Take any trades that may develop per the Strategy beginning on Sunday after 190000 (7pm est) to 115900 (midnight 11:59 pm est), then on Monday-Friday 000100 (one min passed midnight) til 153000 (3:30 pm est) and it then takes a break from taking trades til 190000 (7pm est) Monday-Friday and so on. So, there is a gap between 153000 (3:30 pm est) and 190000 (7 pm est) daily Mon-Friday that I do not want the strategy to actually taking any trades or in any trades either.

There is 29 +/- min (between 153000 3:30 pm est - 155900 4 pm est) where I tell it to stop actually entering any new trades after that time but it has 29 +/- extra min. for any establish trade positions to finish developing before it needs to exit all long and short positions for that particular Strategy until after 190000 (7 pm est) later that day.

Can you send me over some code that I can plug into the Strategy that tells it to exit all long and short positions (if any) for this Strategy at 155900 3:59 pm est?

and

Where would I put the code (beginning, middle, or end)? If you could take a basic simple strategy code and highlight the code you would have me put in to exit all positions in the Strategy at >= 155900 (3:59 pm est) and <= 185900 (6:59 pm est) that would be absolutely wonderful. I have some ideas, but can not get the code just right yet on exiting all long and short positions in the Strategy between those particular time frames.

P.S. By the way, I can not use the Flatten function in NT (Options>Data>Misc) because I need the Strategy to stay on at all times daily for the week without restarting it, don't want for it to Flatten any other separate Strategies I may have going, and lastly don't want it to Flatten any manual trades I may be in at the time (among other reasons). Therefore, that is why I need it to be put into each individual Strategy independent of NT).

Thanks everyone...



Greg

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
REcommedations for programming help
Sierra Chart
What broker to use for trading palladium futures
Commodities
MC PL editor upgrade
MultiCharts
Cheap historycal L1 data for stocks
Stocks and ETFs
 
  #2 (permalink)
 
MrYou's Avatar
 MrYou 
NC, USA
 
Experience: None
Platform: None Yet
Trading: Guitar
Posts: 403 since Jun 2011
Thanks Given: 618
Thanks Received: 196

This switch(Position.MarketPosition) block is pretty much at the core of all my strategies. Also switch is faster than if statements, but its only useful for certain variables.

 
Code
switch (Position.MarketPosition)
{
     case MarketPosition.Flat:
          if (...)
               EnterLong();
          else if (...)
               EnterShort();
          break;

     case MarketPosition.Long:
          if (ToTime(Time[0]) >= ToTime(15, 59, 0) && ToTime(Time[0]) <= ToTime(18, 59, 00))
               ExitLong();
          break;

     case MarketPosition.Short:
          if (ToTime(Time[0]) >= ToTime(15, 59, 0) && ToTime(Time[0]) <= ToTime(18, 59, 00))
               ExitShort();
          break;
}

Reply With Quote
Thanked by:
  #3 (permalink)
 birdoggg 
Charlotte, NC/USA
 
Experience: Advanced
Platform: NT, TOS
Broker: Mirus/ZF, AMP/CQG, TOS, MBT
Trading: Futures, Stocks, Bonds, Forex
Posts: 37 since May 2011
Thanks Given: 56
Thanks Received: 9


MrYou...

Thanks a lot! I will be checking this out (I want to have triple redundancy).


Started this thread Reply With Quote




Last Updated on October 16, 2012


© 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