MQL4 Learning - page 41

 

I want to shorter the price

Hi Guys,

finally I've configured my email account on MT4, and I've done an indicator that says me the order opened. But I have still a problem....when I receive the price at which I bought or sold I receive this long value:

Price: 1.96830000

Is there a way to shorter it to 1.9683?I've used in the code the BID price.

Thanks.

Regards,

Mauro

 

string YourNewPrice = DoubleToStr(Bid,Digits);

mauro269:
Hi Guys,

finally I've configured my email account on MT4, and I've done an indicator that says me the order opened. But I have still a problem....when I receive the price at which I bought or sold I receive this long value:

Price: 1.96830000

Is there a way to shorter it to 1.9683?I've used in the code the BID price.

Thanks.

Regards,

Mauro
 

Hi my friend, thanks for your reply.

I put it after:

int start()

{

Is it correct?

However I have a problem because at the string

"StopLoss: " + (YourNewPrice - SL*Point) + "pips \n\n"

It says that there's a problem at the "-" sign between YourNewPrice and SL:

'-' - both operands are to be numeric

Thanks for your help!

 

for the calculation you use Bid again.

a "double" has always those trailing zero's

...DoubleToStr(Bid - (SL*Point),Digits)...

mauro269:
Hi my friend, thanks for your reply.

I put it after:

int start()

{

Is it correct?

However I have a problem because at the string

"StopLoss: " + (YourNewPrice - SL*Point) + "pips \n\n"

It says that there's a problem at the "-" sign between YourNewPrice and SL:

'-' - both operands are to be numeric

Thanks for your help!
 
IN10TION:
for the calculation you use Bid again.

a "double" has always those trailing zero's

...DoubleToStr(Bid - (SL*Point),Digits)...

Thanks a lot, Now it works perfect!!!

Regards

 

Yes, that should solve the problem, although I would think that if you're that far behind the market you probably don't want to be opening that trade anyway (just my .0002).

The error will be invalid price, which I think is #138 if I recall correctly.

 

calling consecutive losses?

I can't figure out how to call the current count of consecutive losses (or wins) that exited through SL (or TP) on a system that maintains many open/pending orders.

Is there a function for this? (like the variable on the default MACD EA) or will I have to keep an array with the closetime of each order and recalculate it each time?

 

Can you not just check the order history. If the closing price is the same as SL then it was a loss. If it's the same as the TP then it's a win.

Did I miss something?

Lux

 

My apologies, maybe i don't understand the order history calls...

I guess that means you could search the order history by time closed to find the most recent order closed, check if it was TP/SL, and search again?

I was just hoping there was a function that the MACD EA used instead of searching 200k orders (by the end of a 5 year backtest) for the most recent closed orders.

Is there a way to find the most recently closed orders perhaps?

 

Sure. Use TimeDayOfYear(TimeCurrent()) then keep subtracting 1 till you hit an order.

Lux

Reason: