2
// multi account entry with static total risk across accounts
$numberofaccounts=3;
$acc1="TRPETERB";
$acc2="TRPETERB2";
$acc3="TRPETERB3";
$acc4="TRPETERB4";
// total risk of all positions combined across the accounts
$totalrisk=50;
// account percentages split make sure the total makes 100
$acc1perc=10;
$acc2perc=55;
$acc3perc=35;
// calculations of risk per account
$riskacc1=$totalrisk*$acc1perc/100;
$riskacc2=$totalrisk*$acc2perc/100;
$riskacc3=$totalrisk*$acc3perc/100;
$riskacc4=$totalrisk*$acc4perc/100;
// cancel all previous orders and set the stop loss from the montage (doubleckick on chart)
$Montage.CXL ALLSYMB;
$mystop=$Montage.Price;
// save the stop loss for later
setvar("STOP_"+$montage.symbol,$mystop);
// Rounding of stop
if($mystop<1)
{
$mystop=Round($mystop,4);
}
else
{
$mystop=Round($mystop,2);
}
// Determine long or short
if($mystop<$Montage.LAST)
{
$EntryPrice=Round($Montage.Ask,2);
$Offset=$mystop*0.98;
}
else
{
$EntryPrice=Round($Montage.Bid,2);
$Offset=$mystop*1.02;
}
// Rounding of Offset Price
if($Offset<1)
{
$Offset=Round($Offset,4);
}
else
{
$Offset=Round($Offset,2);
}
// Rounding of entry Price
if($EntryPrice<1)
{
$EntryPrice=Round($EntryPrice,4);
}
else
{
$EntryPrice=Round($EntryPrice,2);
}
// Calculate shares and fill in the montage with order data
$Pricetostop=ABS($EntryPrice-$mystop);
// start loop through accounts
$loop=1;
while ($loop<=$numberofaccounts)
{
$Amount=getvar("RISKACC"+$loop)/$Pricetostop;
$Montage.account=getvar("ACC"+$loop);
$Montage.share=$Amount;
$Montage.ROUTE="LIMIT";
$Montage.TIF="DAY+";
$Montage.Price=$EntryPrice;
// Use LimitP stop in 4:00 AM - 9:30 AM and 4:00 PM-8:00 PM
$STOPTYPE="LimitP";
if(getsecond()>34200)
{
if(getsecond()<57600)
{
// Standard stop type during normal hours. Change as route necessary
$STOPTYPE="MARKET";
}
}
// Finally, place the order
if($mystop<$Montage.LAST)
{
$Montage.Buy;
}
else
{
$Montage.Sell;
}
$loop=$loop+1;
// end of loop 1
}
// wait for the fill of orders before placing stop loss orders 1000 means 1 second 2000 is 2 seconds...
wait(1000);
// stop loss loop
$loop=1;
while ($loop<=$numberofaccounts)
{
$MONTAGE.ROUTE="STOP";
$MONTAGE.ACCOUNT=getvar("ACC"+$loop);
$MONTAGE.STOPTYPE=$STOPTYPE;
$MONTAGE.StopPrice=$mystop;
$MONTAGE.Price=$Offset;
$MONTAGE.Share=$montage.POS;
$MONTAGE.TIF="DAY+";
$MONTAGE.SEND=REVERSE;
$loop=$loop+1;
}

