# Martingale money management for forex 0

Posted on 12, March 2014

in Category SID

### Description for Martingale SID 124

Martingale money management for forex

A basic Martingale money managment for forex:

Description from:

http://en.wikipedia.org/wiki/Martingale_(betting_system)

A martingale is any of a class of betting strategies that originated from and were popular in 18th century The simplest of these strategies was designed for a game in which the gambler wins his stake if a coin comes up heads and loses it if the coin comes up tails. The strategy had the gambler double his bet after every loss, so that the first win would recover all previous losses plus win a profit equal to the original stake. The martingale strategy has been applied to roulette as well, as the probability of hitting either red or black is close to 50%. The logic for this Position Sizing Strategy:

PositionSize:

```my \$lastTrade = TradeHistory(1);

\$currentUnits = \$units if(\$currentUnits==0);

if(\$profit<0){
\$currentUnits = \$currentUnits*2;
}else{
\$currentUnits = \$units;
}
}

return RoundToUnitSize(ForexUnitsAvailable(\$currentUnits));```

```if (ShortPosition) {
#If we have a short position, close it.
}
else {
#we have no position, or we are long.
my \$num=PositionSize();
}```

```my \$stop=shift;
#Stop trading if we do not have a stop price
die 'No stop price for BuyStop' unless \$stop;

if (ShortPosition) {
#If we have a short position, close it.
}
else {
#we have no position, or we are long.
my \$num=PositionSize();
}
```

```my \$limit=shift;
#Stop trading if we do not have a limit price
die 'No limit price for BuyLimit' unless \$limit;

if (ShortPosition) {
#If we have a short position, close it.
}
else {
#we have no position, or we are long.
my \$num=PositionSize();
}
```

```my (\$stop,\$limit)=@_;
#Stop trading if we do not have a stop and limit price
die 'No limit price for BuyStopLimit' unless \$limit;
die 'No stop price for BuyStopLimit' unless \$stop;

if (ShortPosition) {
#If we have a short position, close it.
}
else {
#we have no position, or we are long.
my \$num=PositionSize();
}```

SellMarket event logic:

```if (LongPosition) {
#If we have a long position, close it.
PlaceSellOpen('Martingale_Close_Long');
}
else {
#If we have no position or we are short, place the order
my \$num=PositionSize();
PlaceSellOpen('Martingale_Open_Short',\$num) if \$num;
}
```

SellStop event logic:

```my \$stop=shift;
#Stop trading if we do not have a stop price
die 'No stop price for SellStop' unless \$stop;

if (LongPosition) {
#If we have a long position, close it.
PlaceSellStop('Martingale_Close_Long',0,\$stop);
}
else {
#If we have no position or we are short, place the order
my \$num=PositionSize();
PlaceSellStop('Martingale_Open_Sell_Stop',\$num,\$stop) if \$num;
}```

SellLimit event logic:

```my \$limit=shift;
#Stop trading if we do not have a limit price
die 'No limit price for SellLimit' unless \$limit;

if (LongPosition) {
#If we have a long position, close it.
PlaceSellLimit('Martingale_Close_Long',0,\$limit);
}
else {
#If we have no position or we are short, place the order
my \$num=PositionSize();
PlaceSellLimit('Martingale_Open_Sell_Limit',\$num,\$limit) if \$num;
}```

SellStopLimit event logic:

```my (\$stop,\$limit)=@_;
#Stop trading if we do not have a stop and limit price
die 'No limit price for SellStopLimit' unless \$limit;
die 'No stop price for SellStopLimit' unless \$stop;

if (LongPosition) {
#If we have a long position, close it.
PlaceSellStopLimit('Martingale_Close_Long',0,\$stop,\$limit);
}
else {
#If we have no position or we are short, place the order
my \$num=PositionSize();
PlaceSellStopLimit('Martingale_Open_Short',\$num,\$stop,\$limit) if \$num;
}```