Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Additional order generated for 'always in' strategy

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

    Additional order generated for 'always in' strategy

    Hello,
    I have this strategy that looks for specific conditions around VWAP.
    It is designed to always have a position during the session.

    For example, if the price reaches a specific distance above VWAP, it will go long.
    If, after a while, the price reaches a specific distance below VWAP, it will close the long position and go short.
    if it does not reach the 'below VWAP' value, it will just exit the position at the end of the session.

    The strategy also includes logic around a 'no trade period' during which no new trade can occur (only close of a existing position, if needed).
    So because of this, it is important to sometime just close a position and not initiate the opposing trade (because it occurs in the -no trade period-)

    The strategy is using EnterLong(), ExitLong(), EnterShort(), ExitShort, along with some tests on Position.MarketPosition.

    For now, the quantity is always 1 and specific signal names are provided.

    The problem is that once a position is initiated, if the conditions exists to create a reverse position, the resulting new position ends up with a quantity of 2.
    Example:
    1) Long initiated via a EnterLong(), with a quantity of 1 (the Control Center's Execution tab shows this as an 'Entry' and the position shows '1 L' ... all good)
    2) At some point, a condition exists to reverse so :
    2.1) an ExitLong() is done (Execution tab shows this as an 'Exit' and the position show '0 L' which is good)
    2.2) if this does not occur in the -no trade period-, an EnterShort() is done

    Looking in the Control Center's Execution tab, I can clearly see that an action with a signal name 'Close Position' is done, just after the ExitLong
    This particular action appears 'system generated' as the strategy does not use a signal name labeled 'Close Position'.
    The entry type on the execution tab for this line shows 'Entry' and the Position shows '1 S'

    After that, the Execution tab shows a line for the EnterShort, with another 'Entry' and the Position is now at '2 S'

    It should be noted that this only occurs when that strategy is running 'live' (on the SIM101 account)
    When run under the strategy analyzer, there is no problem and the execution display in the Analyzer does not have any entry with the name 'Close position'

    There is clearly something I am missing with the expected results using simple EnterLong(), ExitLong(), EnterShort(), ExitShort.

    I would like to know :
    a) where does the 'Close position' action comes from ?
    b) why is there a different behaviour between 'live' and 'analyzer' for this ?
    c) some proposed options to correct the issue (may use ExitLongStopMarket instead)
    d) if an example of an 'always in' strategy exists, please share a link (I could not find one).


    Thank you in advance for your help.

    Cheers.








    #2
    Hello lacharp,

    You need to make sure you are not calling any Exit methods in addition to the opposite entry. If you have both long and short entries that will cause a reversal if you are in a position and call the opposite entry method, no exit is needed. If you are also exiting that will duplicate the exit causing an extra position.

    Comment


      #3
      Hello Jesse,
      Thanks for the very quick reply.
      If I understand correctly, it is suggested to not do any Exit but just go with EnterLong and EnterShort.

      Could you please provide guidance on how to " sometime just close a position and not initiate the opposing trade (because it occurs in the -no trade period-) " ?

      Would also appreciate some feedback on item 3) ... live vs analyzer behaviour

      Thanks again for your help.

      Comment


        #4
        Hello lacharp,

        You would need to make sure those conditions don't happen at the same time. If you need to just exit, make sure your entry condition does not become true within the same event to prevent the double exit. If you need to reverse you'll need to make sure your exit does not happen and only the opposite entry is being called. This will heavily depend on the conditions you are using to trigger exits and entries.

        Backtesting can cause differences in how the strategy executes so testing in realtime will be the best source to know how the script actually works when running it.

        Comment


          #5
          Hello Jesse,
          Just to report that I have been able to correct the logic to achieve desired result!
          Your second feedback was particularly helpful.
          Thanks you for help, very much appreciated.
          This can be considered closed.
          Cheers.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          71 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          143 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          76 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          47 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          51 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X