Determine next trade long or short if previous trade exited due to stop loss
Forums › ProRealTime English forum › ProOrder support › Determine next trade long or short if previous trade exited due to stop loss
- This topic has 8 replies, 3 voices, and was last updated 6 years ago by
sulimaster.
-
-
10/26/2019 at 9:25 PM #111297
Hi
My trading strategy alternates between long and short trades i.e. long closes and short opens at the same time and vice versa. If a long trade is closed early due to a stop loss being triggered, I want the next trade to be a short trade (and vice versa if a short trade is closed early due to a stop loss being triggered).
Please, how do I code to check whether the previous trade was long or short and whether it was exited due to a stop loss being triggered?
Something like:
1234567IF [previous trade was long] AND [previous trade exited due to stop loss being triggered] THENa = 1ENDIFIF [previous trade was short] AND [previous trade exited due to stop loss being triggered] THENb = 1ENDIFI can then use the above a and b as conditions to enter the next trade but I do not know how to code the bits in the square brackets. Please help
Thanks
Sachin
10/27/2019 at 9:55 AM #111314I already used this snippet to identify what was the last order type and if it was in gain, so it could be adapted to make the opposite:
12345678910111213//------------------//check profitif strategyprofit<>strategyprofit[1] thenif positionperf(1)>0 thenif close<tradeprice(2) thengain=-1 //was sellelsif close>tradeprice(2) thengain=1 //was buyendifelsegain=0endifendif1 user thanked author for this post.
10/27/2019 at 10:16 AM #111315Added as Log 181 here …
10/29/2019 at 5:57 PM #111565Thanks Nicolas
Is the below code valid and would it give me result of a = 1 if the previous trade was long and b =1 if the previous trade was short?
1234567IF LONGONMARKET(TRADEINDEX(2)) = 1 THENa = 1ENDIFIF SHORTONMARKET(TRADEINDEX(2)) = 1 THENb = 1ENDIF10/29/2019 at 11:49 PM #111595Hi Nicolas
Thinking about it further, BARINDEX starts ascending from left to right and ONMARKET starts ascending from right to left. So is the below code correct instead of my reply earlier to give a result of a = 1 if the previous trade was long and b = 1 if the previous trade was short?
1234567IF LONGONMARKET(BARINDEX - TRADEINDEX(2)) = 1 THENa = 1ENDIFIF SHORTONMARKET(BARINDEX - TRADEINDEX(2)) = 1 THENb = 1ENDIFThanks
Sachin
10/30/2019 at 1:41 PM #111662Why don’t you GRAPH Longonmarket and GRAPH a then you will see what the code gives you on the BT results?
If you don’t know what GRAPH involves just say?
1 user thanked author for this post.
10/30/2019 at 2:09 PM #111670That could work but offset must be in brackets and not parenthesis !
1 user thanked author for this post.
11/07/2019 at 4:01 PM #112353Thanks Nicolas
Yes, I should check when to use [] or ()
11/07/2019 at 4:02 PM #112354Thanks GraHal
I was aware of RETURN but completely missed GRAPH. I’ll have a look and come back if I need assistance. Thanks again
-
AuthorPosts
Find exclusive trading pro-tools on