best way to create a stop loss

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ToroV
    Junior Member
    • Apr 2017
    • 9

    #1

    best way to create a stop loss

    Hi guys, as many of you I'm working on my own software to create and optimize my strategies.
    I'm wondering for a good stop loss/cashout method: for example if I place a back bet (size 100£, price 3) on runner ABC, I risk 100£ and have a profit of 200£ in case ABC wins.

    But if ABC goes in the opposite direction I'd like to reduce my loss, so I place a limit order on ABC: lay 50£ at 6, so I will have a loss of 50£ in both cases.

    This is the theory... but in the real world market goes fast, so if I place a lay bet at 6, the bet could not be matched, and my stop loss is not a stop loss anymore.

    Which is the best way for getting a real checkout?

    Thank you guys
  • jabe
    Senior Member
    • Dec 2014
    • 705

    #2
    You can't place a lay bet at price = 6.0 and wait for it to be matched at 6.0 if the price when the bet was made was already lower than 6.0. It'll be matched as soon as there are lower prices available.

    If you're going to do a stop loss, you are going to have to assume that you will lose a little money on the bet. I think you need your stop loss (a lay bet in your scenario) to have the same - or similar - stake as your original back bet.

    When you place a back bet, if there is money available at higher odds than your order specifies, it will match with the highest odds available, if there are any. Similarly, if you make a lay bet, it will match with the lowest odds available, if there are any.

    So, for your stop loss, you need to monitor the odds (every 200ms, which is how often they change) and, as soon as there is a match a little higher (how much higher is up to you, but after a back bet of 3.0, you want to be looking at 3.2 or similar), you place a lay bet for the same stake (or very similar), but for notably higher odds (perhaps even 1000, to make certain of getting matched). That way, if the odds suddenly leapt from 3.0 to 3.6, you'll get a match at 3.6. It doesn't matter exactly where the match is, you're out and only lose a little. That's a stop loss.

    You will also make a lay bet at lower than 3.0 to take profit if the price drops below 3.0 as you hope. The thing to watch for here is that your lay bet at 2.5, say will need a stake to reflect how much of the original back bet was matched, just in case it isn't all matched.


    Back to the numbers in your example. What happens is this:
    1. Assuming the back bet is matched, you have £100 at 3.0, so a £200 win or £100 loss. If you place a lay bet of £50 at 6.0, it will get matched if the price is below 6.0. Suppose the price is 3.5. This gives you a loss of £125 or a gain of £50, so your position is that you either win £75 or lose £50. That's not really a stop loss.

    If your lay bet is for £90, you either lose £215 or win £90, leaving you either down £15 or down £10. If the lay matched at 3.2, you'd be up £2 or down £10. If your stake was £100 and you matched at 3.2, you'd be down £20 or nothing.


    When your first (back) bet is placed, the current price might move around a little before your bet is completely matched, so the margin before you apply your stop loss bet wants to be tight, but not too tight.


    Last thoughts: there is now a fill-or-kill option on a bet. This means you can place a bet and if it is not fulfilled immediately, it will be considered void. This means you don't have to wait to see how it is being matched; you are immediately told.

    Finally, be aware that if your bets are being made in-play, they will be subject to a delay. I believe 5 seconds is the usual delay for football. Prices could move a long way in that time. Before events start, there is no delay.


    Someone may be along with more on this soon...

    Comment

    • ToroV
      Junior Member
      • Apr 2017
      • 9

      #3
      Hi Jabe,
      I knew that betfair matches bets at the best price, so my idea is to monitor back prices until it reaches a trigger value (in my example 5.50)...
      so if the back price reaches 5.5 then place a lay bet at 6, accepting the loss.

      In my code I saw that it works well but, if market moves fast, the prices can go higher than 6 in less than 2 seconds (the delay in horse races), so my order remains unmatched at 6, and the market is already at 7.

      If I'm not wrong you suggest two ways:
      option 1: when the current back price is at 5.5 (example), place a lay bet at 6 and wait if it matches. If price goes higher than 6, cancel the unmatched amount (with the cancelOrders call) and place a new order at higher price with a new calculated size

      option 2: when the current back price is at 5.5, place a lay bet at 6 with the fill_or_kill attribute, if it doesn't match place a new lay bet (with fill_or_kill) at higher price and so on

      If I understand it well the option 2 is faster to develop, but with the fill_or_kill attribute my lay orders can never match.

      The option 1 is a little bit trickier but I have more possibilities to get a match; am I right?


      Maybe the stop loss algorithm of the various betangel, fairbot, ... is similar to what described in option 1

      what do you think?

      Comment

      • jabe
        Senior Member
        • Dec 2014
        • 705

        #4
        What you describe mostly fits with my thoughts.

        I'm still uncertain about the change in price at which you are thinking of triggering your stop loss. If it means you lose 50% or more of your stake, that'd concern me, but then the fact you mention a 2-second delay means you'll be doing this during the race, and so a rapid rise in the price suggests the horse has little chance of winning.

        If you are worried that your stop loss bet might not be matched, you could make the price = 100 or 1000. That way, it would match with the best it could get. It might match with the 5.5 or with 6 or 7, but it should find something lower to match with. On the other hand, if your bets are made while the race being run, there is a chance that the price could get as far as 100 or 1000, or there might be nothing left to match with if the horse has dropped back. Difficult. Test with stakes far below £100!

        I'm not sure if there's anything else I can suggest. Good luck!

        Comment

        • Lopiner
          Junior Member
          • Feb 2009
          • 117

          #5
          Originally posted by jabe View Post
          What you describe mostly fits with my thoughts.

          I'm still uncertain about the change in price at which you are thinking of triggering your stop loss. If it means you lose 50% or more of your stake, that'd concern me, but then the fact you mention a 2-second delay means you'll be doing this during the race, and so a rapid rise in the price suggests the horse has little chance of winning.

          If you are worried that your stop loss bet might not be matched, you could make the price = 100 or 1000. That way, it would match with the best it could get. It might match with the 5.5 or with 6 or 7, but it should find something lower to match with. On the other hand, if your bets are made while the race being run, there is a chance that the price could get as far as 100 or 1000, or there might be nothing left to match with if the horse has dropped back. Difficult. Test with stakes far below £100!

          I'm not sure if there's anything else I can suggest. Good luck!
          Just a detail, if you are stop lossing a back bet, this is, placing a lay bet, you always have to adjust the stake to the odd so it doesn't exceed your upside. If the original bet is a back for 100£ at odds of 3.0 and you want to fire a stop loss lay at 1000 odds you should stake around 0.20£. If you fire a 50£ bet at odds of 1000, even if the market is trading at around 6.00 or 7.00, you have to have 50K in your account and you always risk of being matched at 1000.
          There is a "Bet to Payout or Profit/Liability" option, check this out http://docs.developer.betfair.com/do...ofit/Liability

          If the first bet is a lay, then you can have that strategy of firing a back bet at odds of 1.01 with the amount of the opening lay bet and be happy with the price you get matched.

          In illiquid or very fast moving markets like sports betting at betfair this is always a problem. Most people do what its described above, they have a trigger price and a price to place the bet. Using the case above, when the best to lay price reaches for example 5.5 (the trigger price) you place a bet at 6.0. If the bet is unmatched then you chase the stop (the "Bet to Payout or Profit/Liability" solves part of this problem if you are willing to take whatever price there is).

          This can be done with more sophisticated thinking, like analyzing the market depth and take different actions depending if the market is thin or full of money. You can also trigger you stop loss bet and leave it there if it's unmatched hoping for a price reversal.
          Last edited by Lopiner; 03-05-2017, 03:05 PM.
          fooledbyabet.com

          Comment

          • jabe
            Senior Member
            • Dec 2014
            • 705

            #6
            Yes, good point. I was thinking more of making sure the bet was taken, but hadn't really adjusted to in-play betting on horse racing.

            Comment

            • ToroV
              Junior Member
              • Apr 2017
              • 9

              #7
              Thank you for your help guys... now it's all clear

              Comment

              • ToroV
                Junior Member
                • Apr 2017
                • 9

                #8
                Hi guys, with your help I'd like to make another step forward.

                In the example above a placed a back bet, a trigger at specific price, and a lay bet to cashout.

                I see that the cashout function of betfair is more complex than this, because it works also on markets in which there are mutiple bets matched.

                So lets make anoter example: I back 100£ on the 1st favourite runner at 5, and lay 100£ on the 2nd favourite at 6; so if the 1st wins I gain 500£, otherwise if the 2nd wins I loose 600£.

                During the race I see the betfair cashout button, but I'd like to know HOW betfair calculates bets to place in this case, not only one bet, but multiple bets on the market

                I searched around the internet but I found only the formula for one bets... maybe the overhall cashout is the sum of single cashouts?

                Comment

                Working...
                X