Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to properly call ExitShort/ExitLong

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

    How to properly call ExitShort/ExitLong

    I am having an odd issue where I am calling ExitShort/ExitLong, but the position stays open.

    So here's the code to enter:
    EnterShort(Convert.ToInt32(DefaultQuantity), MyOrderName);
    or
    EnterLong(Convert.ToInt32(DefaultQuantity), MyOrderName);

    To Exit:
    ExitShort(MyOrderName);
    or
    ExitLong(MyOrderName);

    I have verified that the MyOrderName is the same for both Enter and Exit.
    So the Entry Signal exit should work, but not seem to work.

    Any thoughts?

    #2
    Hello ATMtrader0001,

    Please try using Trace Orders to see if the orders are being ignored for some reason, you can view the output window when you run the script and it will let you know if any problems are happening due to the logic you are using.

    Comment


      #3
      Reason='This was an exit order but no position exists to exit'

      Here are the relevant lines:
      1/16/2024 10:14:00 AM Strategy 'StrategyLong/-1': Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='L-Qty-1 Close: 2.969-SL:2.959' Mode=Ticks Value=10 IsSimulatedStop=False IsMarketIfTouched=False
      1/16/2024 10:14:00 AM Strategy 'StrategyLong/-1': Entered internal SubmitOrderManaged() method at 1/16/2024 10:14:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='L-Qty-1 Close: 2.969-SL:2.959' FromEntrySignal=''
      1/16/2024 10:24:00 AM Strategy 'StrategyLong/-1': Entered internal SubmitOrderManaged() method at 1/16/2024 10:24:00 AM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal='L-Qty-1 Close: 2.969-SL:2.959'
      1/16/2024 10:24:00 AM Strategy 'StrategyLong/-1': Ignored SubmitOrderManaged() method at 1/16/2024 10:24:00 AM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal='L-Qty-1 Close: 2.969-SL:2.959' Reason='This was an exit order but no position exists to exit'

      ​So you can see that it entered into a trade called 'L-Qty-1 Close: 2.969-SL:2.959' at 10:14 and then at 10:24 it tried to exit that trade but got the error.

      I get conflicting information. In the Executions tab I see a Long for the same Instrument, but at the Price on 2.952 at 10:12 and it stays in that
      trade until 12:40 PM when it hist the Stop Loss, but it shold have exited prior to that time,

      Can you exolain why I get that error? I used the same name.

      I am confused by this.

      Comment


        #4
        ATMtrader0001 I do not think this will solve your issues but I would switch "MyOrderName" to "MyOrderLong'' and "MyOrderShort" for each respective area just so they are different. You would then need to make sure you do not miss any areas where your code would need to use this. This is something I always like to have separated. It helps too if you ever export trade results for other purposes.

        Also, could there have been an issue with the entry conditions you have for the system? Have you had this system working on the live market before?

        Comment


          #5
          durdcash Thanks for the tip. I realized after I posted the above that it had hit the Stop Loss and closed the order which is why it did not exist when I
          called the Exit.. I do not use the same strategy to trade in both directions at the same time. I have had better results trading in only one direction.

          As all code it is a work in progress.

          Comment


            #6
            ATMtrader0001 I would personally recommend building it into one code for the strategy. Then work on building in bool values for long trades only, short trades only, referencing being InTrade, etc. for the specific conditions. I have found it helps to make sure you don't have unexpected issues at times and easier for reviewing trading stats after a market replay imo.

            Comment


              #7
              durdcash Yes I do use bools to track direction of trade and they are set by the strategy (a variable in the region section).
              Thank you for pointing it out.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Today, 05:17 AM
              0 responses
              44 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              124 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              65 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              42 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              46 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X