Did buying cover my short? or something else?

 

Hi,

I noticed something odd the other day and was wondering if anyone could tell me what happened...

I have a script that I run to enter orders for me - it calculates entry, stop, target, and position size based on risking 1% of my account. I was already in a short position (about 0.7 units) that was in profit but I wanted to go long, so i ran the 'long' script that entered the long order for me. Price came to my entry point and two unexpected things happened:

- my short position was closed automatically. For some reason I thought that all positions were managed separately, so by going long i would have 2 open positions (i was planning on closing the short manually)
and
- I was long 0.14 units, instead of the ~0.7 - 1 units I would have expected. So I'd like to know why this happened and what I should do to make sure it doesn't happen again? I see 2 possible reasons:

1 - The call to AccountBalance() i use to calculate 1% of my account only returns the available balance... So since I was already in a short then I had less balance available, so the 1% risk was much smaller than it should have been.
or
2 - The long closed my short and I was long the difference between my long and short positions. In this case I need to change my script to consider any open positions when calculating the size.

So has anyone seen this before, and know whether 1 or 2 is what happened? Any help much appreciated.

Thanks

David.

 
Maybe it's a "no-hedging" or FIFO thing . . . are you USA based ? we don't have to worry about such things over here (UK).
 
davidc123:

1 - The call to AccountBalance() i use to calculate what 1% of my account only returns the available balance... So since I was already in a short then I had less balance available, so the 1% risk was much smaller than it should have been.
or
2 - The long closed my short and I was long the difference between my long short positions. In this case I need to change my script to consider any open positions when calculating the size.

So has anyone seen this before, and know whether 1 or 2 is what happened? Any help much appreciated.

if you have a US based broker - then #2 is correct - hedging (being long and short at the same time) is not allowed in the US and all trades are open and closed using FIFO (first in first out), so in effect when you placed the long order the short was closed(offset) by the amount of your long order.

 
RaptorUK:
Maybe it's a "no-hedging" or FIFO thing . . . are you USA based ? we don't have to worry about such things over here (UK).

nah i'm uk too, switched to a uk account at oanda to avoid that rule. this might be a question for oanda but not sure they'd have a clue about mql
 

Доброго времени суток уважаемые форумчане!

Меня зовут Герман, мне 23 года, я являюсь трейдером компании "Инстафорекс"

Помогите в поиске нужного скрипта! Скрипт нужен для сетки отложенных ордеров.

Reason: