
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello All, please I am trying to use the OnTradeTransaction function to manage my positions such that I want to replace a buy position that closes due to take profit with a buy limit order and replace a buy position that closes due to stop loss with a buy stop order. Also vice-versa for sell positions. Please take note that the program I am working on places hedged trades.
I know I definitely have my entire logic coded wrongly as seen in my code below so please help me correct the code because the code does not function as expected. For instance when a buy position is opened first followed by a sell trade, I now have 2 trades running and if the buy position hits stop loss, I am supposed to have the program place a new buy stop order using the price, sl, and tp of the closed buy position but this is not so as my code below only detects the last opened position which is a sell position and tries to use its price, sl, and tp parameters to place a buy stop which is totally wrong.
Apparently, I don't know how to select the last closed buy position from the total deals and then pass the trade.BuyStop function to it. Please help me correct this in the code below. T
Thank you