Timed Exiting when in the Red
Forums › ProRealTime English forum › ProOrder support › Timed Exiting when in the Red
- This topic has 5 replies, 3 voices, and was last updated 9 months ago by Brad.
-
-
03/11/2024 at 10:43 AM #229597
Good day all
Can someone please let me know if I have coded this correctly?
- Exit on a Friday if an open trade shows a value of -30 points or less at 21h20 UTC.
- Exit any open trade with a value of -80 points or less from bar 15 or more.
Regards
Brad
Exit trades in the red12345678910111213141516171819FloatingPoints = ((Close - POSITIONPRICE) * POINTVALUE) / POINTSIZEFridayPoints = -30NumberOfBars = 15CutTheTradePoints = -80//Exit Friday evening trades at 21h20 UCT if current points are less than -30IF (DayOfWeek = 5 AND Time >= 212000) AND (FloatingPoints < FridayPoints) THENCloseFridayTrade = 1ELSECloseFridayTrade = 0ENDIF//Exit the trade if after 15 bars the current points are less than -80IF (BARINDEX - TRADEINDEX(1) >= NumberOfBars) AND (FloatingPoints < CutTheTradePoints) THENCuttingMyLosses = 1ELSECuttingMyLosses = 0ENDIF03/12/2024 at 6:43 AM #22962903/12/2024 at 9:19 AM #229632Hi Brad,
JS is right that it is not easy to see whether a real trading system will work out. However, in advance I think I can say this :
123456//Exit the trade if after 15 bars the current points are less than -80IF (BARINDEX - TRADEINDEX(1) >= NumberOfBars) AND (FloatingPoints < CutTheTradePoints) THENCuttingMyLosses = 1ELSECuttingMyLosses = 0ENDIFThis may initially not exit when you would have a Pending Stop for this. Thus, at an initial bar which complies to above, the exit may not happen because the price is not met (again, when you’d use a Pending Stop), while at a next bar the condition may not be true any more because the loss is less than 80 again (e.g. 79). And because the construction of your code, CuttingMyLosses will be 0 again and no exit will happen.
This might be what you want.
If that is not what you want, you must introduce something like CuttingMyLossesSet. For example :
1234567891011121314//Exit the trade if after 15 bars the current points are less than -80// Don't forget the logic to reset CuttingMyLossesSet at the beginning of a new trade.If Not CuttingMyLossesSet thenIF (BARINDEX - TRADEINDEX(1) >= NumberOfBars) AND (FloatingPoints < CutTheTradePoints) THENCuttingMyLosses = 1CuttingMyLossesSet = 1ELSECuttingMyLosses = 0ENDIFEndifThis may look overdone too some, but I know how decently you are trying to master (PRT) coding.
Peter
1 user thanked author for this post.
03/13/2024 at 8:54 PM #229722Thanks, JS and Peter, for your feedback.
Looking at the code you supplied, Peter, does the logic remain the same if I write the code like this?
Resetting to 01234567891011//Exit the trade if after 15 bars the current points are less than -80IF NOT LongOnMarket THENCuttingMyLosses = 0ENDIFIF (BARINDEX - TRADEINDEX(1) >= NumberOfBars) AND (FloatingPoints < CutTheTradePoints) THENCuttingMyLosses = 1ELSECuttingMyLosses = 0ENDIFAm I understanding your coding correctly?
(You are correct; I’m definitely trying to master/understand code logic to improve my coding).
Regards
Brad
03/14/2024 at 1:03 AM #229737To me the introduction of lines 3,4,5 looks more decent than without it. But I would have the same remarks as in my previous post. Please remember, those remarks are only valid when you’d use Pending Stops. Compare with this :
123456IF (BARINDEX - TRADEINDEX(1) >= NumberOfBars) AND (FloatingPoints < CutTheTradePoints) THENCuttingMyLosses = 1Sell at MarketELSECuttingMyLosses = 0ENDIFNow all is fine, and/but your CuttingMyLosses variable would do nothing. So that variable urges (in my mind) for something like
123If CuttingMyLosses then// Pending Stop logic hereEndifAnd my previous post would be valid because the order may not be filled and your code will be called again with the position still there.
What remains is that it is difficult to brainstorm without seeing the full code.
But I am confident you got the gist already. 🙂1 user thanked author for this post.
03/15/2024 at 11:24 AM #229829 -
AuthorPosts
Find exclusive trading pro-tools on