Help with limiting strategy to one trade per day
Forums › ProRealTime English forum › ProOrder support › Help with limiting strategy to one trade per day
- This topic has 10 replies, 4 voices, and was last updated 3 years ago by Finning.
-
-
07/17/2020 at 3:17 AM #139465
Morning,
I’m very new to PRT coding (though not the markets in general) and have been trying to work on a 15-minute trend reversal strategy for the US 500.
I’ve pulled several examples of very useful code (mostly from Nicolas) but tonight I’ve become stuck trying to limit the system to just taking one trade per day. I’ve found multiple examples of how to fix the problem in the forums but when I try to institute each and every one of these (which are all similar), the strategy still occasionally takes 2 trades per day when I backtest (via IG) over the past 6 months and I can’t work out what I’m doing wrong.
Any help would be much appreciated.
Here is the code I’ve cobbled together so far (in the attachments).
Mark
* Accidentally uploaded the first pic twice – apologies as it didn’t seem to work initially
07/17/2020 at 7:26 AM #139473There you go:
12345678910Once TradeON = 1If IntraDayBarIndex = 0 thenTradeON = 1EndifIf OnMarket or StrategyProfit <> StrategyProfit[1] ThenTradeON = 0EndifIf MyConditions and TradeON and Not OnMarket ThenBUY/SELLSHORT.......Endifuse TradeON as an additional condition to enter a trade.
1 user thanked author for this post.
07/17/2020 at 9:11 AM #13948307/17/2020 at 9:21 AM #139484Hi Roberto,
I’ve just integrated that nice piece of code you sent me this am but frustratingly the order list indicates the strategy is still occasionally taking 2 trades in the same day (12 June, 1st July and 8th July). See attached pics with updated code.
Any idea how to get around this?
Mark
07/17/2020 at 11:03 AM #139493Please paste the code using the “Insert PRT code” button, not pics of it, otherwise I cannot use it.
Thank you 🙂
07/17/2020 at 11:06 AM #139496Moreover, use “@” only when there are so many users posting and you absolutely need to reference one of them. In this case it’s just the two of us. Because everytime you put that sign in front of a username, that user will receive an email.
Thank you 🙂
07/17/2020 at 5:04 PM #139516Hi Roberto,
Thanks for letting me know how things work and apologies for using ‘@’ . I hadn’t even realised there was an ‘insert PRT code’ button!
As requested, please find the code attached.
Any ideas how to ensure the strategy only takes 1 trade/day?
Many thanks
Mark
Reversal strategy for US 500123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263//US 500//15-min TFDEFPARAM CumulateOrders=false//UK(London) timeDefParam FlatBefore = 100000DefParam FlatAfter = 230000IF Time >= 100000 AND Time <= 170000 OR Time >= 180000 AND Time <= 203000 THENTradetime = 1elseTradetime = 0endifOnce TradeON = 1If IntraDayBarIndex = 0 thenTradeON = 1EndifIf OnMarket or StrategyProfit <> StrategyProfit[1] ThenTradeON = 0EndifPositionSize = 50CorrectVol = high-low[1]>5 AND high-low[2]>5 and high-low[3]>5 //volatility of preceding 3 candles is sufficient for trade to occursto = stochastic[8,3]c1 = close[1]<open[1] and close>openc2 = close>open[1] AND close >= (high-low)*0.60 + lowc3 = lowest[3](low)<lowest[50](low)[1] or lowest[3](low)<lowest[50](low)[2] or lowest[3](low)<lowest[50](low)[3]c4 = summation[3](sto<20)>0c5 = close[1]>open[1] and close<openc6 = close<open[1] AND close <= (high-low)*0.40 + lowc7 = highest[3](high)>highest[50](high)[1] or highest[3](high)>highest[50](high)[2] or highest[3](high)>highest[50](high)[3]c8 = summation[3](sto>80)>0buyCondition = c1 and c2 and c3 and c4sellCondition = c5 and c6 and c7 and c8// BUY orderIF NOT OnMarket AND CorrectVol AND buyCondition AND Tradetime and TradeON THENBUY PositionSize CONTRACTS AT MARKETSET STOP LOSS abs(close - (lowest[3](low) - 1 * pipsize))set target $profit 600ENDIF// SELL orderIF NOT OnMarket AND CorrectVol AND sellCondition AND Tradetime and TradeON thenSELLSHORT PositionSize CONTRACTS AT MARKETSET STOP LOSS abs(close - (highest[3](high) + 1 * pipsize))set target $profit 600ENDIFIf LongonMarket and (high-low[1]) <3 AND (high-low[2]) < 3 THEN //if volatility very low intra-day then exit positionssell positionSize contracts at marketEndifIf ShortOnMarket AND (high-low[1]) <3 AND (high-low[2]) < 3 THENbuy positionSize contracts at marketEndif07/17/2020 at 6:19 PM #139518It’s because at line 62 you are using BUY to exit a Short trade. No, you’ll have to replace it with EXITSHORT.
To recap:
- BUY opens a Long trade
- SELL exits a Long trade
- SELLSHORT opens a Short trade
- EXITSHORT exits a Short trade
using BUY at line 62 implies a Stop & Reverse, since the Short trade is first closed and new Long one is subsequently opened.
1 user thanked author for this post.
07/17/2020 at 6:26 PM #13951909/08/2020 at 11:38 AM #14359609/09/2020 at 10:36 AM #143705Have a look how this code is used
1OTD = Barindex - TradeIndex(1) > IntradayBarIndex // limits the (opening) trades till 1 per day (OTD One Trade per Day)1234if time >= StartE And time <= StartL and OTD then //and not onmarket thenIF conditionsmet thenbuy N shares AT MARKETendifTaken from this strategy here:
https://www.prorealcode.com/prorealtime-trading-strategies/optimization-ma-cross-machine-learning/
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on