Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ExitLong or Short Not Working

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

    ExitLong or Short Not Working

    For some reason my exit long action doesn't seem to be working. Here is the code:

    Code:
                // Long Exit
                if (Position.MarketPosition == MarketPosition.Long
    				&& Close[0] < WSTideBand10Env(2.5, 14, 1, 11, 3, 3).UpperEnv[0])
                {
                    Variable0 = WSTideBand10Env(2.5, 14, 1, 11, 3, 3).UpperEnv[0];
    				ExitLongLimit(Variable0, "WSTB_LL", "WSTB_L");
                }
    
                // Short Exit
                if (Position.MarketPosition == MarketPosition.Short
    				&& Close[0] > WSTideBand10Env(2.5, 14, 1, 11, 3, 3).LowerEnv[0])
                {
                    Variable1 = WSTideBand10Env(2.5, 14, 1, 11, 3, 3).LowerEnv[0];
    				ExitLongLimit(Variable1, "WSTB_SL", "WSTB_S");
                }
    WSTideBand is a custom indicator with averages and sdev bands. I am trying to execute a limit exit at one of the band values. I tried just putting the indicator value in the price field and that didn't work, then I tried setting a variable to the band value and putting the variable in the price field for the limit exit. Neither approach works. I'm getting no exits with the proper exit label so as near as I can tell it just doesn't work. Is there some other format I should be using?
    Thanks
    DaveN

    #2
    Originally posted by daven View Post
    For some reason my exit long action doesn't seem to be working. Here is the code:

    Code:
                // Long Exit
                if (Position.MarketPosition == MarketPosition.Long
                    && Close[0] < WSTideBand10Env(2.5, 14, 1, 11, 3, 3).UpperEnv[0])
                {
                    Variable0 = WSTideBand10Env(2.5, 14, 1, 11, 3, 3).UpperEnv[0];
                    ExitLongLimit(Variable0, "WSTB_LL", "WSTB_L");
                }
     
                // Short Exit
                if (Position.MarketPosition == MarketPosition.Short
                    && Close[0] > WSTideBand10Env(2.5, 14, 1, 11, 3, 3).LowerEnv[0])
                {
                    Variable1 = WSTideBand10Env(2.5, 14, 1, 11, 3, 3).LowerEnv[0];
                    ExitLongLimit(Variable1, "WSTB_SL", "WSTB_S");
                }
    WSTideBand is a custom indicator with averages and sdev bands. I am trying to execute a limit exit at one of the band values. I tried just putting the indicator value in the price field and that didn't work, then I tried setting a variable to the band value and putting the variable in the price field for the limit exit. Neither approach works. I'm getting no exits with the proper exit label so as near as I can tell it just doesn't work. Is there some other format I should be using?
    Thanks
    DaveN
    Open an identical chart, and enable chart trader. That should show you at what prices your code is placing the orders if at all.

    Comment


      #3
      Hello DaveN,

      Thank you for your post.

      Do you see any errors in the Log tab of the NinjaTrader Control Center? If so please detail in your response.

      As koganam mentioned earlier; have you opened up a Chart Trader on another chart for the same instrument and account that your strategy is running on? Do you see the orders placed on the chart with the Chart Trader enabled?

      I recommend enabling TraceOrders on your strategy so you can track the orders in your Output window (Tools > Output Window).
      For information on TraceOrders please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=3627

      I look forward to your response.

      Comment


        #4
        I set up the second chart with chart trader enabled. This has been very helpful in allowing me to see how the strategy behaves in real-time (at least replay real time). Thanks for the suggestion. One other question: I seem to recall a sample strategy that allows a strategy to reach into an active ATM and modify the stop for that ATM. I am now using a strategy which calls an ATM and uses that to control the entry. That seems to be working pretty well but I also have a set of conditions that when they occur, means I should exit a long if long or a short if short, despite the fact that an ATM is currently managing the trade. Is there some sample code that would show me how to reach into an active ATM and change either the stop or profit or both, or, alternatively close the ATM and return control to the strategy?
        Thanks
        DaveN

        Comment


          #5
          Hello DaveN,

          Thank you for your response.

          You can find a sample by going to the NinjaTrader Control Center > Tools > Edit NinjaScript > Strategy > SampleAtmStrategy > OK.

          To close the open position and the ATM Strategy you can use AtmStrategyClose(): http://www.ninjatrader.com/support/h...ategyclose.htm

          For information on the ATM Strategy Methods that you can use please visit the following link: http://www.ninjatrader.com/support/h...gy_methods.htm

          Please let me know if I may be of further assistance.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by alifarahani, Today, 09:40 AM
          6 responses
          31 views
          0 likes
          Last Post alifarahani  
          Started by Waxavi, Today, 02:10 AM
          1 response
          17 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by Kaledus, Today, 01:29 PM
          5 responses
          13 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by Waxavi, Today, 02:00 AM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by gentlebenthebear, Today, 01:30 AM
          3 responses
          17 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X