Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

trading & not trading

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

    trading & not trading

    Hi Ninjas

    I am trying to program under what circumstances I should not trade.
    The code below I have under the OnBarUpdate(). However, it doesn't seem to eliminate unwanted trades during the backtest. Please confirm if such code structure/syntax are right for my purpose:

    Code:
        
    
           if    
                (
                //conditions when NOT to trade
                )
                    {
                    [B]Position.MarketPosition = MarketPosition.Flat;[/B]  //Is this the correct syntax to use if I intend to stay out of the market?
                    }
                
    
           else if
                (
                //conditions when TO TRADE
                )
                   {
                    //I do this when I want to Trade
                    }
    Last edited by ionaz; 06-19-2013, 10:51 AM.

    #2
    Hello,

    Position,.MarketPostion only check if the strategy was flat, but does not prevent you from taking orders.

    If you to prevent the strategy from taking trades after a specific condition, you can simply ask the strategy to return; under that code block

    Code:
          if    
                (
                //conditions when NOT to trade
                )
                    {
                       return;
                    }
    MatthewNinjaTrader Product Management

    Comment


      #3
      Hi Matthew

      thanks for your post. This didn't help - I still have unwanted trades. BTW I realised that conditions when I don't want to trade didn't happen anyway, so with or without your proposed solution I get the same results. THANKS anyway, good to know this.

      So with regards to unwanted trades. I have an embedded calculator which calculates #of trades based on assount size and my risk tolerance. Works great except some oocasions when it buys 100 stocks for some reason. So in all unwanted trades it trades 100 stocks.

      Do you know what might be the reason?
      Do you know where can I change this 100 number?

      Comment


        #4
        I would not know the reason that your strategy is calculated to buy these stocks, but you should be able to trace the orders that occurred at this time to conditions in your script.

        The 100 number is the strategy quantity defaults if you have not specified a size in your order methods. You can change this when you start your strategy, you will find the "set order quantity" order property which can be changed to 'by default quantity" and then set the Default quantity you wish.
        MatthewNinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        67 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        150 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        162 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        99 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        286 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X