Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Automated trading

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Automated trading

    Good morning all,

    Live working strategy will open positions whenever conditions are met. How it’s possible in NT 8 to make strategy STOP working after opening and closing only one position, so I will put it back on manually after some time. Or just take a break for like 3 minutes and continue work normally after that?
    Thank you
    Michael

    #2
    Hello 2014Michael,

    Thank you for your post.

    It is in fact possible to stop the strategy from trading. Below is a basic example:
    Code:
    		private bool IsTrading = false;
    		protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				Name										= "ExampleStopStrategyAfterOneTrade";
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{
    			// Only trade on realtime data
    			// This means no historical trading (backtests) will occur
    			if (State <= State.Historical) return;
    			
    			// check if we have already submitted an entry and if that entry was filled
    			// You can include any exit conditions here
    			if (IsTrading && Position.MarketPosition == MarketPosition.Long)
    			{
    				ExitLong();
    				// We don't set IsTrading back to false here as we want the strategy to stop trading
    				// If you want the strategy to pick up trades later you can use a condition and then set the IsTrading bool to false
    			}
    			// If we are not in a trade and have not taken a trade then place an entry
    			if (!IsTrading)
    			{
    				EnterLong();
    				// Now we set the bool to true to indicate we have placed an entry
    				IsTrading = true;
    			}
    		}
    If you would like to take a look a time filter condition please visit the following links:
    Please let me know if you have any questions.

    Comment


      #3
      Thank you Patrick H. Let my see how it works.
      Sincerely,
      Michael

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Rapine Heihei, Today, 08:19 PM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by Rapine Heihei, Today, 08:25 PM
      0 responses
      5 views
      0 likes
      Last Post Rapine Heihei  
      Started by f.saeidi, Today, 08:01 PM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by Rapine Heihei, Today, 07:51 PM
      0 responses
      6 views
      0 likes
      Last Post Rapine Heihei  
      Started by frslvr, 04-11-2024, 07:26 AM
      5 responses
      98 views
      1 like
      Last Post caryc123  
      Working...
      X