Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

setting a stoploss with Unmanaged Approach

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

    #16
    I've only used this formula for futures, so I can confirm for futures it works great.
    The formula as provided assumes 1 contract.

    I'm not familiar enough with forex. I mean, I have never traded currency pairs at all, so I have no idea with regards to forex what 'PointValue' means in that world.

    I've never used NinjaTrader for stocks either, so I'm not exactly sure what 'PointValue' means for stocks. However, I suspect for all stocks the PointValue would be the same, that is, I assume it would be PointValue=$1.

    To modify the formula to take into account number of contracts, just work through some examples, use CL or TF where each tick is $10 and the math is easy,

    1 contract long CL at $60 with $400 max loss means 40 tick stop loss.
    2 contracts long CL at $60 with $400 max loss means 20 tick stop loss.

    Thus,
    StopPrice = Position.AvgPrice - (MaxLossCurrency/PointValue)/Quantity

    Using our running example of entry price = $60, to maintain a 40 tick stop loss on 2 long CL contracts, you'd have to set your max loss to $800,
    StopPrice => 60 - (800/1000)/2 => 60 - .80/2 => 60 - .40 => 59.60

    It's just simple math, but working it out with pencil & paper can help.

    Btw, if you always think in terms of ticks for a stop loss, you can (for most purposes) ignore quantity. That is, assume 40 tick stop loss is your "room to roam" for CL ... and you think in those terms. Your "room to roam" thinking is not impacted by number of contracts, you always enter '40' in for stop loss and you do the math IN YOUR HEAD if you have Quantity > 1. (Or have your strategy print to the output window that 40 ticks * quantity = max loss in dollars, so you can see the $400 vs $800 max risk.)

    Consider the markedly different approach if your "room to roam" thinking was done in dollars rather than ticks. If $400 is your max loss (aka your "room to roam") then you enter 400 into your strategy but enter 800 for 2 contracts, 1200 for 3 contracts -- so the math is no longer in your head but is surfaced immediately ... ok, but wait do you enter 400 and the let your strategy multiply it by Quantity automatically for you? Or do you have to enter 800, or 1200? Whatever, you'll have to decide.

    My point is: this idea of stop loss as "room to roam" is better expressed as a tick thing, not a dollars thing.

    I'm just saying that if you're doing too much of your thinking in dollars (rather than ticks) certain things can get a bit more complicated as you increase quantity. It's not a big deal, but I'm just saying, there are times when thinking in ticks is easier than thinking in dollars. In my opinion, figuring a StopPrice is one of those times (esp when Quantity > 1).

    Comment


      #17
      sorry to say Patrick and bltdavid but this is not a universal formula :
      StopPrice = Position.AvgPrice - stoploss in dollars/(Instrument.MasterInstrument.PointValue)

      for example:
      buy 1 eur.usd for 1.24
      stoploss in dollars = 500
      using formula from above: StopPrice=1.24-500/100000=1.2395
      This is ofcourse nog right. Since the loss is only .005 instead of 500.

      Using the formula i provided earlier will give the right Stopprice:
      StopPrice=((Position.Quantity*Position.AvgPrice)-Stoploss in dollars)/Position.Quantity
      StopPrice=((1*1.24)-500)/1= -498.76

      1*(1.24 - -498.76)=500

      ofcourse this example shows an impossible scenario to have a -498.76 eur.usd exchange rate.
      but it shows a correct formula..

      please your response, is it possible to have a universal formula for all instruments?

      or do you have to calculate it different for each instrument in the strategy like:

      protected override void OnStartUp()
      {
      if (instrument == currency) ... Currency formula
      if (instrument== futures)... Futures formula
      etc.

      }

      Comment


        #18
        bltDavid just read your response after writing mine

        I understand that thinking in ticks is more clear, but a fixed stoploss in dollars has its value too.

        Looks like every instrument needs a different formula

        do you agree Patrick?

        Comment


          #19
          If you buy 1 eur.usd at 1.2400, and it drops to 1.2395, have you lost $500?

          (I ask this in complete ignorance as I don't understand forex.)

          Comment


            #20
            no , i was using the futures formula you provided to show that by using that formula to calculate the stoprice of 1.2395 is not correct and you loose only 0.005

            the other formula gives the right stoploss of $500 with an (impossible) eur.usd stopprice of -498.76 for 1 unit
            i used the radical 1 unit example with $500 stoploss only to show the impact of using the future formula for the forex market.

            Comment


              #21
              Hello yeshe,

              Thank you for your response.

              From what I gather if we subtract the TickSize multiplied by the currency value divided by the value per tick times quantity of the position from the average entry price we should have the correct value:
              Code:
              Position.AvgPrice - TickSize*(400/((Instrument.MasterInstrument.PointValue*TickSize)*Position.Quantity))

              Comment


                #22
                thank you Patrick

                I tested it for currency and a little bit on futures.
                The Formula you provided seems to work for futures but not for currency

                so correct formula for currency :

                StopPrice=((Position.Quantity*Position.AvgPrice)-Stoploss in dollars)/Position.Quantity


                formula for futures:

                StopPrice=Position.AvgPrice - TickSize*(Stoploss in dollars/((Instrument.MasterInstrument.PointValue*TickSize) *Position.Quantity))

                or
                StopPrice = Position.AvgPrice - (MaxLossCurrency/MasterInstrument.PointValue)/Position.Quantity

                do you both agree?

                it seems that a uniform formula cannot be found, too bad

                how to incorporate this into a mutli instrument strategy
                something like

                if (instrument = currency) StopPrice=....[currency formula]...
                if(instrument = futures) StopPrice=....[futures formula]....

                what is the code for this?

                regards

                Comment


                  #23
                  Your code is very close.

                  I think you're asking about InstrumentType ... try looking at this ...

                  Comment


                    #24
                    For futures, looks good to me (for forex, I'll defer to you).

                    Realize that this formula is for LONG positions.

                    LONG:
                    StopPrice = Position.AvgPrice - (MaxLossCurrency/PointValue)/Position.Quantity

                    SHORT:
                    StopPrice = Position.AvgPrice + (MaxLossCurrency/PointValue)/Position.Quantity

                    Btw, a nice tip to help code typing & reading, try using this property,

                    Code:
                    private double PointValue
                    {
                        get { return this.Instrument.MasterInstrument.PointValue; }
                    }
                    You could use the same idea for the InstrumentType as well ...

                    Regards

                    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
                    573 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X