multiple strategies within one trading system
Forums › ProRealTime English forum › ProOrder support › multiple strategies within one trading system
- This topic has 18 replies, 6 voices, and was last updated 3 years ago by robertogozzi.
-
-
07/18/2017 at 12:09 AM #40921
Hi,
I’m trying to have a few strategies, triggered based on different conditions, within one trading system. Is it possible in PRT? And if yes, would anyone please give me a simple example and give advice on what mistakes to avoid and how to write it structurally correct?
Thanks,
Thomas
07/20/2017 at 6:35 PM #41185123456789101112131415161718192021// Conditions to enter long positionsIF NOT LongOnMarket ThenIf Condition1 THENBUY n CONTRACTS AT MARKETa = 1ENDIFIf Condition2 THENBUY n CONTRACTS AT MARKETa = 2ENDIFENDIF// Conditions to exit long positionsIF LongOnMarket THENIF a = 1 AND ConditionToExit1 THENSELL AT MARKETENDIFIF a = 2 AND ConditionToExit2 THENSELL AT MARKETENDIFENDIFSorry I wasn’t more specific before, I’m new to PRT. I just wondered whether you can run the code on various strategies within (condition1 and condition2) and have specific exit conditions linked with those strategies (ConditionToExit1 and ConditionToExit2) – but they will be triggered only to those assigned strategies (a = 1 or a = 2). It looks doable to me, but I wonder if there is any restriction.
07/20/2017 at 8:01 PM #41189Sounds good, so to keep the discussion simple, … You had Trade Entry on Condition A and Exit on Condition 1 (for example) but elsewhere in the same coded ‘Auto-Trading System’ you might use a different Condition for Exit … let’s call it Exit Condition 2 for example?
Have I misunderstood your question?
Generally the term Strategy / Strat / Bot / Algo is used to describe a coded ‘Auto-Trading System’ which runs on, for example, the DAX. You could of course run the same Strat on the EUR/USD, but likely your variables (the [20] in Average[20] ) may need to be optimised for the DAX different from the EUR/USD.
Cheers
GraHal1 user thanked author for this post.
07/21/2017 at 10:43 AM #41272I posted a template for multiple strategies in a single TS, click https://www.prorealcode.com/topic/allow-only-one-strategy-to-execute-a-trade/#post-34686
Roberto
07/21/2017 at 10:51 AM #4127407/21/2017 at 11:53 AM #41277Try using this link: https://www.prorealcode.com/topic/allow-only-one-strategy-to-execute-a-trade/
(instead of https://www.prorealcode.com/topic/allow-only-one-strategy-to-execute-a-trade/#post-34686), then go to post #34686, just before Nicolas’ reply.
07/21/2017 at 12:00 PM #41278They seem not to work at the moment.
Here is a copy of my post.
You can assembly all of your strategies into a bigger file.
“DEFPARAM CumulateOrders = false” will do the hard job!
Of course you may need to name variables in different ways, say, a1s1 or cond1s1 for the first strategy, then a2s1/cond2s1….. a1s2/cond1s2 for the second strategy etc….
You may name a variable StrategyID = 0 when NOT ONMARKET, then set it to any number you want each buy/sell is executed so you know which strategy was triggered.
Example:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748DEFPARAM CumulateOrders = False //Only 1 trade at a timeIF NOT OnMarket THEN //Make sure you reset this variable to ZERO when not tradingStrategyID = 0ENDIF//-----------------------------------------------------------------------------------------------------------------IF (StrategyID = 0) OR (StrategyID = 1) THEN //Strategy 1s1.... = ........ENDIF//-----------------------------------------------------------------------------------------------------------------IF (StrategyID = 0) OR (StrategyID = 2) THEN //Strategy 2s2Avg = Average[20](close)s2Rsi = Rsi[14]...//************************************************************************// LONG//************************************************************************IF close CROSSES OVER s2Avg THENStrategyID = 2SET TARGET PPROFIT 20SET STOP PLOSS 10BUY nLots CONTRACT AT MARKETENDIF//************************************************************************// SHORT//************************************************************************IF close CROSSES UNDER s2Avg THENStrategyID = 2SET TARGET PPROFIT 20SET STOP PLOSS 10SELLSHORT nLots CONTRACT AT MARKETENDIF....ENDIF//-----------------------------------------------------------------------------------------------------------------IF (StrategyID = 0) OR (StrategyID = 3) THEN //Strategy 3s3.... = .........ENDIF07/22/2017 at 8:52 AM #4135203/17/2020 at 6:07 PM #12236903/17/2020 at 7:16 PM #122374In my example above I used TP & SL several times with the same values but they can be different.
You can also use TIMEFRAME multiple times, as needed.
You cannot use more than 5 different TF’s + default one.
TIMEFRAME(1 hour,default) and TIMEFRAME(1 hour,updateonclose) count as one, not two!
02/06/2021 at 4:45 PM #160520Hi,
Sorry for resurfacing an old thread, but I was having a similar conundrum. Is there a way of adding strategy specific exit rules, rather than just TP or SL? I tried doing so, but my sell rules seem to be mixing in the actual trading process. For example, this code exits trades that strategy 2 initiated based on strategy 1 exit parameters.
Here’s my code:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859DEFPARAM CumulateOrders = false // Cumulating positions deactivated//dynamic position sizingINITIALCAPITAL = 10000c = (INITIALCAPITAL/close)if c < 0.2 thenc = 0.2endif// Conditions to enter long positionsIF NOT onmarket thenStrategyID = 0ENDIF//trend following strategyIF (StrategyID = 0) OR (StrategyID = 1) THENindicator1 = SAR[0.14,0.01,0.3]c1 = (close > indicator1)indicator2 = RSI[14](close)c2 = (indicator2 < 80)c3 = (close >= open)indicator3 = AroonUp[10]c4 = (indicator3 > 15)indicator4 = CALL "ATR"[14,2]c5 = (close > indicator4)IF c1 AND c2 AND c3 AND c4 AND c5 THENStrategyID = 1BUY c PERPOINT AT MARKETset stop $loss 420ENDIFindicator5 = SAR[0.14,0.01,0.3]c6 = (indicator5 > close)indicator6 = RSI[14](close)c7 = (indicator6 > 80)IF c6 OR c7 THENSELL AT MARKETENDIFENDIF//mean reversion strategyIF (StrategyID = 0) OR (StrategyID = 2) THENindicator4 = CALL "ATR"[14,2]c8 = (close < indicator4)indicator7 = RSI[14](close)c9 = (indicator7 < 30)IF c8 and c9 THENStrategyID = 2BUY c PERPOINT AT MARKETENDIFc10= (indicator7 > 50)IF c10 THENSELL AT MARKETENDIFENDIFgraph StrategyIDTo illustrate my point, I’ve attached a screenshot of my strategy working. Strategy 2 -Separated is the code I used for strategy 2, but separated from the code I posted above. As you can see, Strategy 2 took the same trade as my initial code and held it until the exit criteria were met, whereas my original code immediately closes this trade because it meets strategy 1 exit rules.
02/06/2021 at 5:33 PM #160525The code you posted CANNOT close one strategy because of conditions from the other one.
The two strategies are clearly separated with a different ID and, as long as IF…ENDIF works, they cannot mix.
The above code user RSI[14], while on your pic I can spot RSI[13], this can be a cause.
I cannot test it because I don’t have the ATR indicator you are calling. Post it or post a link where I can find it.
02/06/2021 at 5:45 PM #160527Sure, the ATR that I am using is this indicator: https://www.prorealcode.com/prorealtime-indicators/another-atr-trailing-stop/
The RSI that is on the chart is purely used for visualisation purposes and isn’t reflective of the strategy that I am using.
Maybe my IF statements are wrongly worded? I ask because as soon as strategy 2 kicks in, the code I posted closes the position. See my screenshot:
02/08/2021 at 12:18 PM #160666Thenumber of parameters for the indicator is three:
1CALL "ATR"[14,2,1]why did you use only two of them?
What instrument is the one traded in your last pic?
02/09/2021 at 10:55 AM #160777Dear robertogozzi,
Thank you for your reply. I’m attaching some extra info.
First, the code to “Strategy 2 – separated”. As you can see its the same as strategy 2 in the first code I posted, so the ATR settings are exactly the same.
1234567891011121314151617181920DEFPARAM CumulateOrders = false // Cumulating positions deactivatedINITIALCAPITAL = 10000c = (INITIALCAPITAL/close)if c < 0.2 thenc = 0.2endifindicator4 = CALL "ATR"[14,2]c8 = (close < indicator4)indicator7 = RSI[14](close)c9 = (indicator7 < 30)IF c8 and c9 THENStrategyID = 2BUY c PERPOINT AT MARKETENDIFc10= (indicator7 > 50)IF c10 THENSELL AT MARKETENDIFSecond, I have uploaded an expanded screenshot showing the instrument, along with the “graph StrategyID” function from the first code I posted.
I believe that the issue rests with how I have worded my IF statements- could you please test?
-
AuthorPosts
Find exclusive trading pro-tools on