Announcement

Collapse
No announcement yet.

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...

    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.

        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.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            602 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            347 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            103 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            560 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            559 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X