Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 950

 
Can you please tell me how to close a trade? How to close a trade after n (number e.g. 5) candles after its opening? The opening time of the trade is not known in advance.
 
kokos4:
Please advise who can. How to close a position after n (number eg 5) candles after its opening? You don't know the opening time beforehand.

Count n candles in seconds, add to the opening time and compare with the current time. As soon as the current time is greater - an order to close.


////где-то в цикле перебора ордеров:
////
timer = OrderOpenTime()+PeriodSeconds()*n;

if(TimeCurrent()>timer) close(OrderTicket());
////////////////


 
kokos4:
Please advise who can. How to close the deal after n (number eg 5) candles after its opening? In advance the time of opening of the position is unknown.

The number of candles that have passed since the order was opened (remember to highlight it beforehand):

iBarShift (_Symbol, _Period, OrderOpenTime());

Further it is easier as "a piece of cake". ;)

 

Colleagues, my NormalizeDouble function doesn't work (I can't explain it otherwise). It outputs 16 digits, although I wrote 5 in the second parameter. Please tell me what's wrong in the code:

double i = 0.123456789112345;
void OnStart()
  {
         NormalizeDouble(i, 5);  
         Alert (i);
  }
 
JoinDoe: Colleagues, my NormalizeDouble function is not working (I can't explain it otherwise).
double i = 0.123456789112345;
void OnStart()
  {
         Alert (NormalizeDouble (i, 5));
  }
 
TarasBY:
Thank you! And now it's showing 0.12346
 
JoinDoe:
Thank you! And now it's 0.12346.
Correct, rounded down to the nearest one!
 
How would you make it so that there is no rounding?
 
JoinDoe:
How would you do that without rounding?

Then it will not be normalised and may cause an error! Why aren't you happy with a more accurate normalised price?

If you need it for some reason, you can multiply the original number by 100000, turning it into an integer, and then multiply it by _Point or 0.00001:

double i = 0.123456789112345;
void OnStart()
  {
         Alert (NormalizeDouble (i*100000, 0)*_Point);
  }
 
borilunad:

Then it will not be normalised and may cause an error! Why are you not happy with a more accurate normalised price?

I don't know, it looked like an error :)) But if it's more accurate, then of course it's better to use this, the more accurate price. Thanks, you've helped!