Forex Factory (https://www.forexfactory.com/)
-   Platform Tech (https://www.forexfactory.com/forum/69-platform-tech)
-   -   Silly question for exp concerning math with double (https://www.forexfactory.com/thread/17398-silly-question-for-exp-concerning-math-with-double)

Ahil Feb 10, 2007 11:06am | Post# 1

Silly question for exp concerning math with double
 
How do I do simple math jobs with varaible type double

I want to do this

double i;

i = i*2;

question how do i do this simple math calculation???????

Ahil Feb 10, 2007 11:56am | Post# 2

is it allowed ??

i think i get an error there if I try to do i=i*2 with double type variable

????

smjones Feb 10, 2007 12:02pm | Post# 3

This is what I thought to do, but if it is a bitwise operation, it only will work with intiegers. If it is a normal operation, it will work with doubles. The manual is not clear on this, so you should try it.

I am reffering to i *= 2:

Ahil Feb 10, 2007 12:06pm | Post# 4

well i was experimenting and it works with doubles i mean i=i*2;

but maybe my problem is because this double is extern and it messes up somewhere when i try to change it later ??

Ahil Feb 10, 2007 12:13pm | Post# 5

To explain what I am trying to do

I have extern double i=0.1;

in start() I am redefining i like this

i=MyFunction(i);

MyFunction is something like this

double MyFunction(double a);
{
a *=2;
return(a);
}

what happens??????

smjones Feb 10, 2007 12:20pm | Post# 6

So are you saying this does not return a = a * 2 ?

It looks like it would to me...

if not, perhaps this
double MyFunction(double a);
{

double b = a;
a = b *2;
return(a);
}

Ahil Feb 10, 2007 12:40pm | Post# 7

well i tried it all but it doesn't work

what I am trying to do is to apply Martingale principle to Lots

My starting Lots are 0.1

and in order to check if my last trade was profitable I am calling functions

a=OrdersHistoryTotal()
OrderSelect(a, SELECT_BY_TICKET)
OrderProfit()

and then if OrderProfit was<0 then I try to change Lots=Lots*2;

but it messes up, I am a bit frustrated with such simple thing that goes wrong? aaaaaaaaa )

Ahil Feb 10, 2007 12:50pm | Post# 8

well to answer myself

I had to insert Lots=OrderLots();

after calling function OrderSelect because it messed up my variable Lots

why?? I dont know maybe because it was used as a part of OrderSend ????

dont know but everything works now


Thank to smjones for trying to help

smjones Feb 10, 2007 1:04pm | Post# 9

If possible, could you please post that part of your code that does your martingale? I would like to understand better what you were doing and that way I can learn more..

Thanks Scott

PabloPL Feb 10, 2007 10:02pm | Post# 10

Listen try this one - should be fine:

Inserted Code
extern double i=0.1;
double i1;
int init() {
   i1 = i;
}
int start() {
   i1=MyFunction(i1);
}
double MyFunction(double a) {
   a *=2;
   return(a);
}

Ahil Feb 11, 2007 6:28am | Post# 11

@smjones
well it works now here it is, variable rez is too much but I was trying everything

extern double Lots=0.1;
extern bool MrtnGale = false;


double Martingale(double Koliko)
{
double rez;

rez=Koliko;
Koliko=rez*2;

return(Koliko);
}


bool ZadnjiTradeProfit() // true if last trade profitable else is false
{
int Hist = 0;
double prof = 0;


Hist = OrdersHistoryTotal();


if(OrderSelect(Hist, SELECT_BY_TICKET)==true)
{
Lots=OrderLots(); // without this line Lots gets messes up
// dont know why
prof = OrderProfit();
if (prof>=0) return(true); else return(false);
}
else
{
Print("OrderSelect neuspjelo ",GetLastError());
return(true);
}
}


int start() //MAIN PROGRAMM
{
//----


// this is where I check if last trade was a winner or looser

if (MrtnGale==true) //check for extern if Martingale is ON
if (OrdersHistoryTotal()>0)
if (ZadnjiTradeProfit()==false) Lots=Martingale(Lots); else Lots=LotsPocetni;



p.s

thanks guys for help

smjones Feb 11, 2007 10:21am | Post# 12

Yes, I see what you are doing, I see you are using the temporay holding var, rez... I am not sure why the orderlots either. Maybe someone else knows why it is necessary. Thanks for posting it. It gave me some new insight, Scott

Ahil Feb 12, 2007 10:08am | Post# 13

Yes, I see what you are doing, I see you are using the temporay holding var, rez... I am not sure why the orderlots either. Maybe someone else knows why it is necessary. Thanks for posting it. It gave me some new insight, Scott
well it didnt work without Orderlots, why??? I am puzzled too


© Forex Factory