Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Save backtest results

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

    #31
    Thanks Patrick,

    Could I still get some help? I am quite new in NT ATM programming.
    How would you program this rule: after a long tentry the next one must be short, and vice versa?

    Thanks.

    Comment


      #32
      Hello Borsz,

      Thank you for your post.

      The condition would need to know the previous position and then determine if a new position would take place. We would need an initial order placement though, and then we can set this new variable to long or short for the previous position:
      Code:
              #region Variables		
              private string prevPosition = "";
              #endregion
      
              
              protected override void Initialize()
              {
                 	
              }
      		
      		protected override void OnBarUpdate()
      		{	
      			// Ensure we are flat to avoid reversals caused by the prevPosition string.
      			if(Position.MarketPosition == MarketPosition.Flat)
      			{
      				// Place initial trade.
      				if(prevPosition == null) // prevPosition will initially be null.
      				{
      					// Calculate long or short trade.
      				}
      				
      				// Place trade based on previous position.
      				if(prevPosition == "long")
      				{
      					// Go short.
      				}
      				if(prevPosition == "short")
      				{
      					// Go long.
      				}
      			}
      		}
      	
      		protected override void OnPositionUpdate(IPosition position)
      		{
      			// Calculate previous position.
      			if(Position.MarketPosition == MarketPosition.Long)
      				prevPosition = "long";
      			else if(Position.MarketPosition == MarketPosition.Short)
      				prevPosition = "short";
      		}
      For information on the OnPositionUpdate() method please visit the following link: http://www.ninjatrader.com/support/h...tionupdate.htm

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      72 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      39 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      63 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      63 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      53 views
      0 likes
      Last Post CarlTrading  
      Working...
      X