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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        648 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        574 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X