Greening up on multiple positions with a target profit
This trigger example is about hedging, trading out, or greening up / distributing loss as we call it in MarketFeeder Pro. It is very easy to green up a single selection based on its target profit, because this function is built into the program. But operating multiple bets and selections may require some effort.
So in this example we'll place random initial bets, both back and lay, on various selections, and then we'll close all positions once the overall P/L target is reached. It could be both profit or loss target, which we will specify in the constants.
As an additional tuner, we'll set the triggers to either close all positions regardless of the outcome just before the off, or carry on into the in-play.
In the constants you can set:
profit_target : Profit target for closing all positions, in currency units;
loss_target : Loss target for closing all positions, in currency units
max_bet_num : Number of initial bets (if you choose to place them);
go_inplay : 1 - to go in-play, and 0 - close before the off;
secs_before_off : How many seconds before the off to close all if go_inplay = 0.
This is how the market looks after the first random bets were placed, with max_bet_num = 5:
The type of bet and selection to bet on is chosen based on the selection's ID on BetFair. You can safely turn off the two triggers that make them, "initial random back bets" and "initial random lay bets" if you intend to open the trades manually or using your own triggers.
This is how the market will look after all five bets are closed, with profit_target = 1.0.
You can notice that most selections were greened up (Nokhada, Soldier In Action, Rosamaria and Southern Seas), while Flyboy traded out with a great loss of 64% which was compensated by the other bets.
The trigger that calculates the overall P/L after each market refresh and checks it against the constants is called "calculating overall P/L". All it does is add up the potential P/Ls of each selection, which can be expressed through this formula:
Individual potential P/L = IF(back_payout > lay_payout, (back_payout - lay_payout)/lay_price - back_matched, lay_matched - (lay_payout - back_payout)/back_price)
These triggers will work equally well with all types of win markets. The horse race was chosen as an example just because of its high liquidity.
If you decide to edit the triggers, make sure they stay in the same relative order as they are, as it is crucial for their correct work.