Change a variable/flag after a LWL streak possible?
Forums › ProRealTime English forum › ProOrder support › Change a variable/flag after a LWL streak possible?
- This topic has 9 replies, 3 voices, and was last updated 4 years ago by
GraHal.
-
-
08/08/2021 at 3:51 PM #174934
Hi.
Is there possible to change or set a variable/flag after the last three trades where LWL (loss win loss) or something similar? The problem for me is when it comes to more than the last two trades. Coding statements checking the last two trades works fine.
Example code (not complete):
Code example12345678910111213141516171819202122232425262728293031323334353637if BARINDEX = 0 thenLWLtrigger = 0 // After loss win loss (LWL) this variable changes to 1contractscore = 0 // When below 0 a contract is added, more losses subtract more from score and wins adds back scoreendifif not onmarket thenmystrategyprofit = strategyprofit// Example with LL that works, the problem is three trades in a row, etc. LWLif mystrategyprofit <> mystrategyprofit[1] thenprofithistory = mystrategyprofitprofithistory2 = mystrategyprofit[1]profhistest = profithistory < profithistory[1] and profithistory2 < profithistory2[1]// Even this worked I think: profithistory < profithistory[1] and profithistory[1] < profithistory[2]endif// More losses would subtract more from contractscore in other if statementsif LWLtrigger = 0 and profhistest thencontractscore = contractscore - 1LWLtrigger = 1endif// How to do the same concept but with three consecutive trades WLW?endif// Buy example, of course there would be complete code to set the LWLtrigger to 0 again after a win (or more wins if there where more losses using contractscore).if not onmarket and LWLtrigger = 0 and otherparameters thenbuy 1 contract at marketendifif not onmarket and LWLtrigger = 1 and otherparameters thenbuy 2 contract at marketendifSincerely,
Daniel.08/08/2021 at 5:10 PM #174944You can keep track of the outcome of trades with this code:
12345678910Once Gained = 0Once Lost = 0If StrategyProfit > StrategyProfit[1] thenGained = 1Lost = 0ElsIf StrategyProfit < StrategyProfit[1] thenGained = 0Lost = 1EndifLWL = Lost and Gained[1] and Lost[2]1 user thanked author for this post.
08/08/2021 at 9:16 PM #17495208/09/2021 at 6:32 PM #174979Hi again.
I thought we would work normal hours this week but it’s still “summer hours”, so I got some extra time. 🙂
I’ve tried your code but it seems to have the same problem. PRT still can only keep track of the last two trades.
The test code with graph.12345678910111213141516Once Gained = 0Once Lost = 0If StrategyProfit > StrategyProfit[1] thenGained = 1Lost = 0ElsIf StrategyProfit < StrategyProfit[1] thenGained = 0Lost = 1EndifLWL = Lost and Gained[1] and Lost[2]LW = Gained and Lost[1]graph LWL as "LWL"graph LW coloured(0,0,255) as "LW"/Daniel
08/10/2021 at 10:27 AM #174996You wanted to detectc LWL, or any other sequence of your choice, to pause a strategy.
“The problem for me is when it comes to more than the last two trades“, what does that mean? what’s the problem there?
08/10/2021 at 5:54 PM #175041Yes I wanted to detect LWL but the code doesn’t do that (as you saw in the image I added in my previous reply). I painted in where there where LWL and the graph didn’t get triggered (otherwise it would get the true value 1 opposed to 0 in the picture in those positions). The image shows successful graph of LW I used as an example which works fine on the last two trades. But the platform (PRT) don’t seem to be able to check earlier than the last two trades when it comes to wins and losses. So to be clear, I want the graph to be triggered by LWL, then I know it works.
Thanks again,
Daniel.08/10/2021 at 10:54 PM #175070Yes, I got it. The glitch was that that wirth [1] the code is not accessing the previous result, bu the previous candle (the same for [2]).
This one should do:
123456789101112131415161718192021222324252627282930313233ONCE MyProfit1 = 0ONCE MyProfit2 = 0ONCE MyProfit3 = 0ONCE LWL = 0IF LWL THENMyProfit1 = 0ENDIFIf StrategyProfit > StrategyProfit[1] thenMyProfit1 = MyProfit2MyProfit2 = MyProfit3MyProfit3 = 1ElsIf StrategyProfit < StrategyProfit[1] thenMyProfit1 = MyProfit2MyProfit2 = MyProfit3MyProfit3 = -1EndifLWL = (MyProfit1 = -1) AND (MyProfit2 = 1) AND (MyProfit3 = -1)IF close crosses over average[20] and Not LongOnMarket thenbuy at marketelsif close crosses under average[20] and Not ShortOnMarket thensellshort at marketendifset stop ploss 100set target pprofit 300graph LWL coloured(255,0,0,255)graph MyProfit1graph MyProfit2graph MyProfit31 user thanked author for this post.
08/11/2021 at 6:41 PM #17511708/14/2021 at 7:09 PM #17535608/18/2021 at 7:58 PM #175643Link to Roberto code above added as Log 299 here
2 users thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on