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

Setting an ExitLongStop

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

    Setting an ExitLongStop

    I have the following setup where I have certain condition that if met I enter a long position and also create a longstop variable at the previous low.

    Then outside of the condition I try to set the ExitLongStop as the Max of LongStop at the time of the fill (which doesn't change) and a moving average (which continues to change each OnBarUpdate).

    It does not seem to be picking up the LongStop variable I have created.
    Do I need to place this somewhere else in the code

    protectedoverridevoid OnBarUpdate()
    {

    // Condition set 1
    If ........

    {

    LongStop = Low[
    1];
    EnterLong(DefaultQuantity,
    "");
    }

    Stop = Math.Max(SMA(Low,
    8)[1],LongStop );
    ExitLongStop(Stop);
    }

    #2
    fiddy, would suggest printing the variables at both points and continued bars to see what exact outcome you get with this approach. If you have the Stop variable outside the entry condition it would continue to update on each bar. Would also suggest to check the entry does not evaluate to true again on continuous bars, so LongStop actually is getting reset to the Low all the time...
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks for the suggestion
      I get the following msg
      **NT** A Sell stop order placed at '13/02/2013 5:00:00 AM' has been ignored since the stop price is greater than or equal to close price of the current bar. This is an invalid order and subsequent orders may also be ignored. Please fix your strategy.

      However When the initial Entry Order is placed the market is above the stop price, it is only during that bar that it goes below what would have been the stop level.

      Is there a way to get both orders placed simulataneously in the code so that I don't get this error.

      Comment


        #4
        fiddy, the order would only be expected to be sent if you have position then registered (otherwise it would be just ignored).

        To send the order on the fill of the entry without waiting for the position update you could submit from the more advanced OnExecution() method for example.

        BertrandNinjaTrader Customer Service

        Comment


          #5
          Would the correct results show in backtesting mode if you use this method or will it only work in a live trading environment

          Comment


            #6
            That would generally work in live and backtesting mode. However before taking any strategy live I would suggest a few runs in our Market Replay environment.
            BertrandNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by junkone, Today, 11:37 AM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by frankthearm, Yesterday, 09:08 AM
            11 responses
            41 views
            0 likes
            Last Post frankthearm  
            Started by quantismo, 04-17-2024, 05:13 PM
            5 responses
            35 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by proptrade13, Today, 11:06 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by love2code2trade, 04-17-2024, 01:45 PM
            4 responses
            35 views
            0 likes
            Last Post love2code2trade  
            Working...
            X