one fit size strategy
Forums › ProRealTime English forum › ProOrder support › one fit size strategy
- This topic has 9 replies, 5 voices, and was last updated 1 year ago by ZeroCafeine.
-
-
03/29/2023 at 9:18 PM #212461
Hi everyone,
The name of the strategy is obviously ironic and conceptually wrong.
Anyway, I practiced writing this strategy, but it doesn’t work because I have two error messages on lines 4 and 7. I would ask you to help me fix the code and make any changes you think are necessary if you believe it can be improved.
Specifically, the strategy follows the market trend when the 50-period EMA is above the 100-period EMA, the ADX is above 20, the RSI is above 50, the MACD is above zero, the Stochastic is above 20, and the price is above the 20-period Bollinger moving average. In this case, a long position is opened with a market order, while the stop loss is set at twice the 14-period ATR below the market price and the profit target is set at three times the 14-period ATR above the market price.
When the market is choppy, the strategy adopts a more cautious trading strategy. When the price crosses the Bollinger range, a long or short position is opened . In this case, the stop loss is set at twice the 14-period ATR above or below the market price and the profit target is set at three times the 14-period ATR above or below the market price.
At least , I believe that what I have written outlines these rules. Sorry, but I am learning while having fun.
Edo
123456789101112131415161718192021222324252627282930313233// Define ParametersDEFPARAM CumulateOrders = FalseDEFPARAM PreloadBars = 500DEFPARAM OrderCancelDelay = 1// Define IndicatorsIndicator1 = EMA[50](close)Indicator2 = EMA[100](close)Indicator3 = ADX[14](14)Indicator4 = RSI[14](close)Indicator5 = Bollinger[20](close)Indicator6 = MACD[12,26,9](close)Indicator7 = Stochastic[14,3,3](close)Indicator8 = ATR[14](close)// Trend Following StrategyIf Indicator1 > Indicator2 and Indicator3 > 20 and Indicator4 > 50 and Indicator6 > 0 and Indicator7 > 20 and close > Indicator5.Middle thenBUY 1 CONTRACT AT MARKETSET STOP LOSS 2 * Indicator8 BELOW MARKETSET TARGET PROFIT 3 * Indicator8 ABOVE MARKET// Choppy Market StrategyElseIf Indicator5.Upper > Indicator5.Lower and Indicator6 < 0 and Indicator7 < 80 thenIf close crosses above Indicator5.Upper ThenBUY 1 CONTRACT AT MARKETSET STOP LOSS 2 * Indicator8 BELOW MARKETSET TARGET PROFIT 3 * Indicator8 ABOVE MARKETElseIf close crosses below Indicator5.Lower ThenSELL SHORT 1 CONTRACT AT MARKETSET STOP LOSS 2 * Indicator8 ABOVE MARKETSET TARGET PROFIT 3 * Indicator8 BELOW MARKETEndIfEndIf03/30/2023 at 4:30 AM #212472Hi Edo,
OrderCancelDelay is not a “system parameter” (I have no idea how to call these, set with DefParam), hence an error message on that one.
Then probably some message on line 7 because line 4 has to be corrected first.What you intended with line 4 ? … no idea. 🙂 What was the idea about this line ?
The name of the title is perfect. Now get it working !
hahaPeter
03/30/2023 at 5:58 AM #212474Hi Peter,
eheh you’re right: the name of the strategy is perfect!…but , I say, the strategy itself… not exactly the same!
Anyhow, in line 4 the value of “1” in this case should mean that the order will be cancelled after one bar, so if the order is not filled immediately, it will be cancelled in the next bar. As per your suggestion, I deleted line 4 but error in line 7 remains..
ciao
Edo
03/30/2023 at 6:17 AM #212475Ah, I only now see it myself … EMA is not an existing function. Look here on how to do it : https://www.prorealcode.com/documentation/average/
in line 4 the value of “1” in this case should mean that the order will be cancelled after one bar
If that is what you want, then let your code start with Sell At Market. Or better :
123If OnMarket thenSell at Market // For a Long position.Endif1 user thanked author for this post.
03/30/2023 at 4:22 PM #212565OrderCancelDelay, Ema, Bollinger and ATR are not valid supported keywords.
OrderCancelDelay does not exist.
EMA must be replaced with Exponentialaverage[periods](source) or Average[periods,1](source).
Bollinger needs to be either BollingerUP[periods](source) or BollingerDown[periods](source).
ATR should be replaced with AverageTrueRange[periods](source).
1 user thanked author for this post.
03/31/2023 at 4:09 PM #212618Hello everyone,
I was finally able to finish my first code. I tested it on BTCUSD and I’m attaching a screenshot.
Thank you in advance to those who want to try to improve it, if it’s worth it, by sharing here any enhancements.
Edo
12345678910111213141516171819202122232425262728293031// Define ParametersDEFPARAM CumulateOrders = FalseDEFPARAM PreloadBars = 500// Define IndicatorsIndicator1 = Exponentialaverage[100](close)Indicator2 = Exponentialaverage[150](close)[100]Indicator3 = ADXR[14]Indicator4 = RSI[14](close)Indicator5 = BollingerUp[20](close)Indicator6 = BollingerDown[20](close)Indicator7 = BollingerBandWidth[20](close)Indicator8 = MACD[12,26,9](close)Indicator9 = Stochasticd[14,3,5](close)Indicator10 = AverageTrueRange[14](close)// Trend Following StrategyIf Indicator1 > Indicator2 and Indicator3 > 20 and Indicator4 > 50 and Indicator8 > 0 and Indicator9 > 20 and close > Indicator7 thenBUY 100 CONTRACT AT MARKETSET STOP TRAILING 30 * Indicator10// Choppy Market StrategyELSIF Indicator5 > Indicator6 and Indicator8 < 0 and Indicator9 < 80 thenIf close CROSSES OVER Indicator5 ThenBUY 100 CONTRACT AT MARKETSET STOP TRAILING 30 * Indicator10ELSIF close CROSSES UNDER Indicator6 ThenSELLSHORT 50 CONTRACT AT MARKETSET STOP TRAILING 30 * Indicator10ENDIFENDIF04/01/2023 at 12:18 AM #212634Congratulations ! Very well done.
Keep in mind that backtesting is an art in itself. For example, being Long on Bitcoin over that period of time does not lose easily. Hence, try the same over the past one year and it could be more difficult.
Still, well done because you applied your theories and they worked out. Looks easy but is not easy at all.1 user thanked author for this post.
04/07/2023 at 3:59 PM #21302004/07/2023 at 5:05 PM #21302104/12/2023 at 12:38 PM #213179Keep in mind that backtesting is an art in itself. For example, being Long on Bitcoin over that period of time does not lose easily. Hence, try the same over the past one year and it could be more difficult.
yes backtest is an Art, You can take almost any strategy and you will see that it will always be positive at some point, and that will be comforting to you and because of that you may do a lot of stupid things, You always have to look and look hard and understand what’s going on,
A little theory that might help you and it’s very simple, if for example your strategy is a Long strategy, then once you think your strategy is good you can try to backtest it on some periods in the past where you can see visually that the trend is down, if your Long strategy ends up with zero gains in a downtrend then I think you might have a winning strategy,
Be careful not to optimize your strategy lot for the bear market in question otherwise it is cheating
about your line :
1DEFPARAM OrderCancelDelay = 1If your goal is to buy only after the condition candle (Candle 1) then this is already the case with the ProRealTime code your order will be cancelled at the next candle (Candle 3) if it is not filled at the previous candle (Candle 2)
-
AuthorPosts
Find exclusive trading pro-tools on