Code for partial close with percentage
Forums › ProRealTime English forum › ProOrder support › Code for partial close with percentage
- This topic has 61 replies, 7 voices, and was last updated 4 years ago by
nonetheless.
-
-
12/11/2020 at 7:37 AM #15331212/11/2020 at 7:53 AM #153313
There you go (not tested):
123456ONCE PerCent = 0.50 //0.50 = close half positionsIF MyLongExitConditions AND LongOnMarket THENSELL (abs(CountOfPosition) * PerCent) AT MarketELSIF MyLongExitConditions AND ShortOnMarket THENEXITSHORT (abs(CountOfPosition) * PerCent) AT MarketENDIF1 user thanked author for this post.
12/11/2020 at 9:03 AM #15332612/11/2020 at 6:46 PM #153428There you go (not tested):
123456ONCE PerCent = 0.50 //0.50 = close half positionsIF MyLongExitConditions AND LongOnMarket THENSELL (abs(CountOfPosition) * PerCent) AT MarketELSIF MyLongExitConditions AND ShortOnMarket THENEXITSHORT (abs(CountOfPosition) * PerCent) AT MarketENDIFThis is already available with PRT 11? Because on PRT 10 it wasn’t possible partial closed.
Thanks
12/11/2020 at 8:07 PM #153432Yes, it is available with v11.
12/19/2020 at 9:13 AM #15438412/19/2020 at 10:58 AM #154392There you go (not tested):
1234567891011ONCE PerCent = 0.002 //0.2% = positions to closeONCE FallPerCent = 0.005 //0.5% = price dropONCE MinLotSize = 0.5 //0.5 lots minimumExitQuantity = abs(CountOfPosition) * PerCentRemainQuantity = max(MinLotSize,abs(CountOfPosition) - ExitQuantity)CloseQuantity = abs(CountOfPosition) - RemainQuantityIF close <= (PositionPrice * (1 - FallPerCent)) AND LongOnMarket THENSELL CloseQuantity Contracts AT MarketELSIF close >= (PositionPrice * (1 + FallPerCent)) AND ShortOnMarket THENEXITSHORT CloseQuantity Contracts AT MarketENDIFI added a check to make sure the quantity left open is not < to the Minimum Lot Size required (that you can set at line 3, after checking with the broker).
My code in the previous post was missing the word Contracts.
12/19/2020 at 1:53 PM #15441912/19/2020 at 2:47 PM #154425You may either write lines 5-6 manually or try to replace them with:
12RemainQty = max(MinLotSize,abs(CountOfPosition) - ExitQuantity)CloseQuantity = abs(CountOfPosition) - RemainQtyUsing a different name.
12/19/2020 at 3:04 PM #15442712/19/2020 at 6:41 PM #15444612/19/2020 at 7:17 PM #154451There you go:
1234567891011ONCE PerCent = 0.5 //50% = positions to closeONCE Pips = 20 * PipSizeONCE MinLotSize = 0.5 //0.5 lots minimumExitQuantity = abs(CountOfPosition) * PerCentRemainQty = max(MinLotSize,abs(CountOfPosition) - ExitQuantity)CloseQuantity = abs(CountOfPosition) - RemainQtyIF close >= (PositionPrice + Pips) AND LongOnMarket THENSELL CloseQuantity Contracts AT MarketELSIF close <= (PositionPrice - Pips) AND ShortOnMarket THENEXITSHORT CloseQuantity Contracts AT MarketENDIF12/19/2020 at 7:30 PM #15445512/19/2020 at 7:40 PM #15445712/20/2020 at 10:09 AM #154538You may either write lines 5-6 manually or try to replace them with:
12RemainQty = max(MinLotSize,abs(CountOfPosition) – ExitQuantity)CloseQuantity = abs(CountOfPosition) – RemainQtyUsing a different name.
I’m probably pretty stupid.
Is there an opportunity to explain in a simpler way how I do with “RemainQty”.
Gets error no matter what I do!
-
AuthorPosts
Find exclusive trading pro-tools on