How can I find the average opening price for the last two positions?
-
How can I find the average opening price for the last two positions?
If there are five positions .
i used BUCKET FOR TRADES but it is give me average to all opening price buy or sell - i need average opening price for te last /newest two only -
@khalids222 Well, you will need two variables for sure. One for each trade. Do you need both of them be closed? No open trade is necessary for the calculation?
-
@l-andorrà yes i need to close . You can explain
-
@khalids222 This is more difficult than I expected. Satoring the last one is very easy but finding the second one is much harder. I guess a loop is required that stops at the second one, but I can't see how to do it right now.
-
@l-andorrà thank you very much
-
@khalids222 I think this link will show you how to achieve what you would like:link text
I haven't tested but I hope this helps. -
or a loop of last 2 trades, sum the 2 prices and divide by 2
would be a quick solution, that works
-
@bk7 Then show as a solution.
-
@jstap @bk7
First of all, I would like to thank you for your efforts and response, and I want to share part of the project with you to understand what is required more clearly. this linkhttps://fxdreema.com/shared/HKa3gDAtd
Every time the price goes back ten pips down, a buy position will be opened.
And when the price goes up ten points, the last two deals will be closed, their sum is positive
In this case, every time the price goes down 10 pips, how do I close the last trade and the one before it? In the event that the ten points variable moves? I need to know the average of the last two trades to close them together -
@khalids222 Hello, I have had a look at your project I have taken a picture of a few changed bits, although I haven't tested I think should work.
I have put the reset variable under on trade, as long as result is used before a new trade is closed it will work fine, as a general rule keeping pink blocks separate seems to work better.

I have moved the other blocks as they don't need to be in between pink, I removed the pink check profit because the pips away is already doing this.

Let me know how this works.
-
@jstap said in How can I find the average opening price for the last two positions?:
Hello, I have had a look at your project I have taken a picture of a few changed bits, although I haven't tested I think should work.
I have put the reset variable under on trade, as long as result is used before a new trade is closed it will work fine, as a general rule keeping pink blocks separate seems to work better.I appreciate your reply, thanks a lot but it didn't work
Didn't close the last two deals only the last
-
@khalids222 Change the pink close for blue, everything should then work.
-
@jstap
In this case, all deals will be closed, not just the last two &This is not required

-
@khalids222 In this case this is where things start to get complicated. In most blocks you can set a group number, if for example you set a trade as 1 you can then set the close block to only close group 1. There may be another way of doing this but I don't know it.
-
@jstap Overall, thank you very much, I will try
-
@khalids222 hello my dear friend, can you please share your project link. I am trying to understand
-
@ladydolares ohhhh sorry i see it now

-
@khalids222 So while sleeping the correct answer came to me, as you'll see in this picture just change the number of trades to check from1 to 2 and put the pink block back. Hope this helps.

-
@jstap consistently opened buy trade in test

-
@ladydolares If you post your link in a new question, can send directly to me if you want and ill have a look.