This is something I have been playing about with for a while, focussing initially on just the trebles - working on the basis that if I can get that working the rest should fall into place.
The bit I have been stuck on for a while is what to do when you have multiple lines hitting the same selection.
I have tried for example coming up with a trigger containing system number for each bet
So for example for four horses a, b, c and d we end up four trebles (lets assume for now that the races are in chronological order - it gets more complicated when not, but the principle is the same)
Treble 1: a,b,c
Treble 2: a,b,d
Treble 3: a,c,d
Treble 4: b,c,d
So I can create trigger treble 1, 2, 3 and 4 and you can refer back to outcome of previous triggered event, but this does still leave working out the outcome from the profit of the races and how it relates to the next bet in the sequence. I have this running and it will work fine for a single treble, but its gets problematic when combining with other trebles that have combinations of the same selections
So if horse A wins you can divide the profit by 3 and add it to the stake for the next bets in trebles 2, 3 and 4.
But if horse A loses and horse B wins, then you don't want to be dividing the profit from Horse B as it just goes onto the one treble 4 selection C. If horse A and B win, then again you don't want to divide the profit by three, but need to related it back to the three lines in progress.
In the doubles in the L15 this gets more complicated as there are more of them, and its possible that you can have some bets on a horse that are the first leg of a double, and others that are the second leg, and if it wins you want to be leaving the profit from the winning second leg, but rolling on the profit from the winning first legs.
This is the crux at present.... I am trying to think through an efficient approach that can address this fundamental issue, as I am not sure yet I have adopted the correct starting point.
Obviously you have all the other fun and games that can still mix things up for you. Overlaps in race finishes to the next race start, some meetings being delayed by over 30mins etc