Have the lenght of a candle to insert TP.

 

Hi guys,

so i want to obtain the lenght of a candle to have my TP.

I did that but no effect:

double   O= iOpen(Symbol(), Period_M15, 1),
         C=  iClose(Symbol(),Period_M15, 1);

double   tp= MathAbs(C - O)/Point*25/100;

Like you see, i want 25% of the candle lenght. It will be my TP.

I thank you by advance for your helps, which were always nice.

 
Kane59:

Hi guys,

so i want to obtain the lenght of a candle to have my TP.

I did that but no effect:

Like you see, i want 25% of the candle lenght. It will be my TP.

I thank you by advance for your helps, which were always nice.

TP is a price not an offset . . .  the tp figure you have calculated might be something like 0.000375 for GBPUSD,  you can't set your TP at that price.  For a Buy try adding your tp figure to Ask + Spread 

If you are doing that already then you may have a type casting issue . . .  25/100 as ints is equal to 0 ,  instead use 25.0/100.0
 
RaptorUK:
TP is a price not an offset . . .  the tp figure you have calculated might be something like 0.000375 for GBPUSD,  you can't set your TP at that price.  For a Buy try adding your tp figure to Ask + Spread 

If you are doing that already then you may have a type casting issue . . .  25/100 as ints is equal to 0 ,  instead use 25.0/100.0

You're right about bad price for TP (i receive error message: Takeprofit values error for Ordersend...)


I use TP like this:

ticket = OrderSend(Symbol(),OP_BUYSTOP,0.01,O,300,0,O+tp,NULL,0,0,CLR_NONE);
 
Kane59:

You're right about bad price for TP (i receive error message: Takeprofit values error for Ordersend...)


I use TP like this:

If you used a more descriptive name for your variable called  O  I wouldn't have to ask what it was  . . .  what is the Error number that you get ?
 
RaptorUK:
If you used a more descriptive name for your variable called  O  I wouldn't have to ask what it was  . . .  what is the Error number that you get ?


"O" is the open price of the last candle in period M15.  I have not a error number, when this part of the EA is running, in "expert", i can read:


"Invalid Take Profit for the OrderSend Function"

 
Kane59:

"O" is the open price of the last candle in period M15.  I have not a error number, when this part of the EA is running, in "expert", i can read:


"Invalid Take Profit for the OrderSend Function"

Can you modify your code to print the error number to the log . . .

 What are Function return values ? How do I use them ?

 

I read:

Invalid Take Profit for OrderSend Function

Error 4107

i know what is it, but just want the open price of the last candle.

So i define:

Open = iOpen(Symbol(), Period_M5, 1);

 

Ok it worked when it wants..........

But at now, the last candle value / 25% = 1.4 pips. But Ea didi this:

Open price (1.30....) + TP(14.0000)= 15.30 to be closed !

What the hell? Just want the value of difference between cloàse and open price, have 25% of this value and apply to a TP...

 
Kane59:

Ok it worked when it wants..........

But at now, the last candle value / 25% = 1.4 pips. But Ea didi this:

Open price (1.30....) + TP(14.0000)= 15.30 to be closed !

What the hell? Just want the value of difference between cloàse and open price, have 25% of this value and apply to a TP...

Why don't you simply do this . . .

double   tp = NormalizeDouble(MathAbs(C - O) * (25.0 / 100.0), Digits);

 See:  https://www.mql5.com/en/forum/140682  &  https://www.mql5.com/en/forum/139584/page3#635899

 

You're right, it is working.

But i had change a part cause value was very Huge:

double   tp = NormalizeDouble(MathAbs(C - O) * (25.0 / 100.0), Digits);

TO

double tp = NormalizeDouble(MathAbs(CloseA - OpenA) / Point * (25.0/1000000), Digits);

Without this big divide, value gave me a very huge TP:

Open Price = 1.30......

TP= 37,30....

Imagine the crazy value of the Euro dollar ! With this change it's perfect !

Thanks again for today. Every time, You, and WHRoeder are very Helpfull !

 
Kane59:

You're right, it is working.

But i had change a part cause value was very Huge:

Without this big divide, value gave me a very huge TP:

Open Price = 1.30......

TP= 37,30....

Imagine the crazy value of the Euro dollar ! With this change it's perfect !

Thanks again for today. Every time, You, and WHRoeder are very Helpfull !

No,  you are doing something wrong,  take any candle at random and do the maths . . .  for example,  EURUSD H1  Open = 1.30861    Close = 1.30641

My code  NormalizeDouble(MathAbs(C - O) * (25.0 / 100.0), Digits)   would be  1.30641 - 1.30861 = -0.0022   MathAbs() of that = 0.0022   multiply that by (25.0/100.0)  = 0.00055  

 

Remove the Point and the "big divide"  and as you can see the code will work . . . .