#include <string.h>
#include <stdlib.h>
int main(int argc, char** argv) {
double amount;
double target;
int winperc;
int changeperc = 10;
int whichcase;
int howmuch;
int volatil = 5;
int limvolatil = 4;
int count = 0;
double invest;
int inverti = 1;
if (argc < 3) {
printf("\nHow many operations do you need to loose all your money? This program demonstrates the secret Gold Rule of Trading (aka: why some good investors loose all their money): Every time you have a big loss you should decrease the investment to ricuperate the capital and every time you have a big win you should increase it. The people usually do the opposite!\n");
printf("\nforex [capital] [target capital] [winning percentage] [invert]\n\n");
printf("(winning percentage = how many times you win every 100; invert = 0 to follow the gold rule and 1 to not follow it)\n");
printf("\nexample. forex 50 100 60 1\n\n");
printf("What you will discover? You will discover every time you don't follow the Gold Rule (invert=1) you lose all your money and every time you follow it (invert=0) you reach your capital target\nGood look people!\n");
printf("\n__Cyber_traveller__\n\n");
exit(1);
}
inverti = atoi(argv[4]);
amount = atoi(argv[1]);
target = atoi(argv[2]);
winperc = atoi(argv[3]);
//changeperc = argv[4];
//volatil = argv[5];
srand ( time(NULL) );
invest = amount;
do {
count++;
whichcase = rand() % 100 + 1;
howmuch = rand() % volatil;
if (whichcase <= winperc)
{
if (inverti == 0) {
if (howmuch >= limvolatil) {
if (invest < (amount * 3))
invest = invest + ((invest / 100) * changeperc);
printf(" Grossa vincita\n");
}
} else {
if (howmuch >= limvolatil) {
if (invest > (amount /8))
invest = invest - ((invest / 100) * changeperc);
printf(" Grossa vincita\n");
}
}
amount = amount + ((invest/100) * howmuch);
}
else
{
if (inverti == 0) {
if (howmuch >= limvolatil) {
if (invest > (amount /8))
invest = invest - ((invest / 100) * changeperc);
printf(" Grossa perdita\n");
}
} else {
if (howmuch >= limvolatil) {
if (invest < (amount * 3))
invest = invest + ((invest / 100) * changeperc);
printf(" Grossa perdita\n");
}
}
amount = amount - ((invest/100) * howmuch);
}
printf("amount =<%f> - investment= <%f>\n", amount, invest);
} while ((amount > (double)1) && (amount < (double)target));
printf("----------------------\nOperations = <%i>\n", count);
return 0;
}