Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

if i am in a "long" position and a short signal is activated

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

    if i am in a "long" position and a short signal is activated

    is it possible for exit the long and enter the short simultaneously?

    Like

    ExitLong();
    EnterShort():


    Or is there another way which I can achieve this?

    #2
    Just do the EnterShort() then Kaywai, it would reverse automatically for you.

    Comment


      #3
      i won't need to exitlong() ?

      Comment


        #4
        Correct, if you're long and call EnterShort() it would do the reverse.

        Comment


          #5
          Thank you Bertrand!

          Comment


            #6
            Stopped out and don't know why! Please help!

            Hi Bertrand,

            I've been trying to debug this issue I am now experiencing. From the attached chart (I've circled it and the relevant date is 3/7/2011 at 11pm), the code correctly closes the long position and initiates a short position. The problem is it gets stopped out immediately!

            From the trace which I have attached, there is a short stop at 1.4055 and a long stop at 1.3956 but no stop loss at 1.4003!

            Would you mind taking a look to see what happened?

            Another question I have pertains to whipsaws where I am stopped out on the same bar. Is there any way I can avoid that?

            Regards

            Kay Wai
            Attached Files

            Comment


              #7
              Hi Kay, are you resetting the stoploss then when you're flat to same default value?

              Comment


                #8
                Originally posted by kaywai View Post
                ... Another question I have pertains to whipsaws where I am stopped out on the same bar. Is there any way I can avoid that?

                Regards

                Kay Wai
                Try looking at this that I wrote a while back.

                Comment


                  #9
                  Hi Bertrand,

                  Not sure what you mean...I don't know why the stop is being placed at the same price as the entry as the value of the stop is either 0 or a calculated value which for the short trade in question is at 1.4055. The long stop (1.3956) was resetted after the short entry and short stop was placed. They are all part of the same block of code.

                  Hi Koganam,

                  Thanks for that! Will probably have to sit down and study that code of yours closely.

                  Regards

                  Kay Wai

                  Comment


                    #10
                    Kay, if you don't reset the stop to a default offset when flat, it could be still holding a prior value - please check into this sample here where the reset is done if you're in a flat strategy position :

                    Comment


                      #11
                      Thanks Bertrand. I will take a look at your suggestion. Kay Wai

                      Comment


                        #12
                        Hi Bertrand,

                        I just went thru the code SamplePriceModification you suggested.

                        In a scenario where for example you close a long position and enter a short position by just using EnterShort(); , how are you able to reset the stop loss if you set the stop loss at the point of entry?

                        Alternatively, if I am in a long position and I would like to enter a short position, would the code below as a block work better?

                        ExitLong();
                        LongStopLoss = 0;
                        SetStopLoss(CalculationMode.Price, LongStopLoss);
                        EnterShort();
                        ShortStopLoss = xxx;
                        SetStopLoss(CalculationMode.Price, ShortStopLoss);

                        Regards

                        Kay Wai

                        Comment


                          #13
                          Hi Kay, the reset if flat is done with this snippet in the sample :

                          // Resets the stop loss to the original value when all positions are closed
                          if (Position.MarketPosition == MarketPosition.Flat)
                          {
                          SetStopLoss(CalculationMode.Ticks, stoplossticks);
                          }

                          Comment


                            #14
                            Hi Bertrand,

                            The reason why I ask this is because I use a price stoploss which is calculated just prior to the entry...I do not have a constant range from the entry price.

                            My double, LongStopLoss, defaults to zero should a position be exited but the problem now, it seems, there is no reset...which I guess would involve further investigation.

                            Regards
                            Kay Wai

                            Comment


                              #15
                              Kay, we would recommend to do the reset as outlined in the sample.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              648 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              369 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              108 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              572 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              574 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X