How to i get very first order entry price. I have code but it not work correct
How to i get very first order entry price. I have code but it not work correct
12 Aug 2022, 10:09
Please help me get very old or first opend position entry price. I use this code but it not get me correct value while use mulit order.
Positions.Where(x => x.TradeType == TradeType.Sell).OrderBy(x => x.EntryTime).First().EntryPrice;
Replies
MongolTrader
12 Aug 2022, 10:49
RE:
PanagiotisCharalampous said:
Hi MongolTrader,
Please explain why do you think it doesn't work.
Best Regards,
Panagiotis
I use this entry price for take profit of another position. But it not stable it moves i dont know why.
@MongolTrader
PanagiotisCharalampous
12 Aug 2022, 10:50
Hi MongolTrader,
It seems correct to me. So you need to provide more information.
Best Regards,
Panagiotis
Join us on Telegram and Facebook
@PanagiotisCharalampous
paolo.panicali
12 Aug 2022, 13:02
a possible reason
Hi Mongol, maybe this can help you, I just tell you what it seems to me and my personal opinion, not the Truth.
...that code recalls the EntryPrice of the oldest currently open position on any symbol.
A possible reason for the price not being "stable" can be that by the time you use that function the position is already closed so that you are picking the price of another position and maybe on another symbol ( the second oldest that now it is the oldest because the oldest had been closed so now it is in the History and not in Positions) , in that case you should call History instead of Positions and refer to the current symbol.
You may also want to specify the symbol name in order not to pick another symbol price, which also could be the cause.
For instance if you run a bot with this line of code on 3 symbols in three different instances or in the same instance, you will end up mixing up prices and will take the price of a symbol for another symbol.
Not only that, if the outcome of the line of code you show is null cause there are not open positions currently, you will get a null value or the bot will crash and forced to stop.
Bottom line, I personally always hard type or parametrize the symbol name to sort, find or close positions (otherwise I sort find or close positions of another instance or another bot, also remember to label correctly the positions you open, that is the easiest wat to pick an open trade) and if the price is unstable is most likely because the position you are trying to take the price had been closed or maybe you set a rolling time window which is excluding the first open position time.
Hope that help bye.
@paolo.panicali
MongolTrader
12 Aug 2022, 13:45
RE: a possible reason
paolo.panicali said:
Hi Mongol, maybe this can help you, I just tell you what it seems to me and my personal opinion, not the Truth.
...that code recalls the EntryPrice of the oldest currently open position on any symbol.
A possible reason for the price not being "stable" can be that by the time you use that function the position is already closed so that you are picking the price of another position and maybe on another symbol ( the second oldest that now it is the oldest because the oldest had been closed so now it is in the History and not in Positions) , in that case you should call History instead of Positions and refer to the current symbol.
You may also want to specify the symbol name in order not to pick another symbol price, which also could be the cause.
For instance if you run a bot with this line of code on 3 symbols in three different instances or in the same instance, you will end up mixing up prices and will take the price of a symbol for another symbol.
Not only that, if the outcome of the line of code you show is null cause there are not open positions currently, you will get a null value or the bot will crash and forced to stop.
Bottom line, I personally always hard type or parametrize the symbol name to sort, find or close positions (otherwise I sort find or close positions of another instance or another bot, also remember to label correctly the positions you open, that is the easiest wat to pick an open trade) and if the price is unstable is most likely because the position you are trying to take the price had been closed or maybe you set a rolling time window which is excluding the first open position time.
Hope that help bye.
Tank you very much. Very rich explanation for me. Best& Regards
@MongolTrader
paolo.panicali
12 Aug 2022, 14:24
i ve seen your new post...
apparently you are getting a null value and the bot crashes as expected, the trade you are trying to get the Entry Price must be into the History then... :-)
I replicated the thing here and I get right the same error when there are no trades open...if I use History I get the value...
bye
@paolo.panicali
paolo.panicali
12 Aug 2022, 14:37
Also, maybe you are going Async...
Also, probably you are placing Async trades and sometimes you have the new trade executed when the older is still open ( so that the entry price is in Positions...), and some other times the execution is delayed for any reason and the older is already closed...
So you wanna be specially careful if you are going async.
@paolo.panicali
PanagiotisCharalampous
12 Aug 2022, 10:32
Hi MongolTrader,
Please explain why do you think it doesn't work.
Best Regards,
Panagiotis
Join us on Telegram and Facebook
@PanagiotisCharalampous