anti-martingale (ninjatrader)

Dear all,

Does anyone have a sample of a martingale or anti-martingale strategy programmed for ninjatrader ?

Thank you in advance.

Chris:confused:
 
Quote from Chris128:

Dear all,

Does anyone have a sample of a martingale or anti-martingale strategy programmed for ninjatrader ?

Thank you in advance.

Chris:confused:

Martingale is just doubling the bet whenever one loses, correct? Below is pseudo-code (not C++/C#/Ninjascript):

bet_size = 1;
while (bet_size) {
result = make_trade(bet_size);
(result == loss) ? bet_size *= 2 : bet_size = 0;
}


Anti-martingale is doubling the bet after every win, correct?
Below is pseudo-code:

bet_size = 1;
while (bet_size) {
result = make_trade(bet_size);
(result == win) ? bet_size *= 2 : bet_size = 0;
}
 
Quote from blah12345678:

Martingale is just doubling the bet whenever one loses, correct? Below is pseudo-code (not C++/C#/Ninjascript):

bet_size = 1;
while (bet_size) {
result = make_trade(bet_size);
(result == loss) ? bet_size *= 2 : bet_size = 0;
}


Anti-martingale is doubling the bet after every win, correct?
Below is pseudo-code:

bet_size = 1;
while (bet_size) {
result = make_trade(bet_size);
(result == win) ? bet_size *= 2 : bet_size = 0;
}

So in both cases (win or lose) this pseudo code will double the size of the bet (trade) only once, right?

Edit: Ok I know what you mean now.
 
Quote from xelite777:

So in both cases (win or lose) this pseudo code will double the size of the bet (trade) only once, right?

The pseudo-code is just an example. It will have to be tweaked to fit into his overall logic. It won't work otherwise.

In the previous example, the sample code runs in a loop. In the martingale, it exits the loop when result == win. In the anti-martingale, when result == loss. Both reset bet_size to 1.

The system will need to check the results of the last trade to see if it's a loser(winner). If it is, then it needs to determine how many losers(winners) in a row the system had. Then figure out the new bet size.

A more enhanced pseudo-code example:

last_trade_result (bet_system) {

if (bet_system == "martingale") {
status_check = "loss";
} else if (bet_system == "anti-martingale") {
status_check = "win";
}

streak = 0;
counter = -1;

while (counter < 0) {
status = closed_trades[counter];
if (status == status_check) {
streak++;
counter--;
} else {
counter = 0;
}
}
return streak;
}

system_streak = last_trade_result("martingale");
/* system_streak = last_trade_result("anti_martingale"); */

/* I'll leave it to OP to figure out the initial bet size and how to maintain variable persistence between runs */
bet_size = get_original_bet_size();

/* if system_streak is < 0, something's wrong */
bet_size *= power(2, system_streak);
 
An anti-martingale position size would halve your position after a loss, not set it to 0, so the change is

(result == win) ? bet_size *= 2 : bet_size /= 2;
 
Back
Top