DEFPARAM CumulateOrders = true
once ordersize=1
// Conditions
MA1 = Average [2]
MA2 = Average [13]
MA3 = Average [11]
MA4 = Average [4]
c1 = Ma1>MA2
c122 = Ma3>MA4
t1 = time >= 090000
t2 = time = 180000
d1 = dayofweek = 2
d2 = dayofweek = 4
if strategyprofit<=20000 then
a=1
endif
if strategyprofit>20000 and strategyprofit<=40000 then
a=2
endif
if strategyprofit>50000 then
a=3
endif
if strategyprofit<=20000 then
if ordersize>16 then
ordersize=16
endif
endif
if strategyprofit>20000 and strategyprofit<=50000 then
if ordersize>32 then
ordersize=32
endif
endif
if strategyprofit>50000 then
if ordersize>64 then
ordersize=64
endif
endif
// buy
indicator13 = MACD[12,26,9](close)
c13 = (indicator13 < 30)
indicator11 = ExponentialAverage[20](close)
c11 = (close >= indicator11)
indicator1 = MACDline[12,26,9](close)
indicator2 = ExponentialAverage[12](indicator1)
c12 = (indicator1 > indicator2)
//sell
indicator1111 = ExponentialAverage[20](close)
c1111 = (close <= indicator1111)
indicator111 = MACDline[12,26,9](close)
indicator2111 = ExponentialAverage[9](indicator111)
c1211 = (indicator111 < indicator2111)
if not onmarket then
If d1 And t1 and c1 and c11 and c12 and c13 THEN
IF PositionPerf(1) < 0 THEN
OrderSize = OrderSize*2
if ordersize<1 then
ordersize=1
ENDIF
ELSIF PositionPerf(1) > 0 THEN
OrderSize = a
if ordersize<1 then
ordersize=1
ENDIF
endif
buy ordersize Contract At Market
Endif
If d1 And t1 and c122 and c1111 and c1211 THEN
IF PositionPerf(1) < 0 THEN
OrderSize = OrderSize*2
if ordersize<1 then
ordersize=1
ENDIF
ELSIF PositionPerf(1) > 0 THEN
OrderSize = a
if ordersize<1 then
ordersize=1
ENDIF
endif
sellshort ordersize Contract At Market
Endif
endif
If d2 and t2 then
exitshort at market
endif
Set Stop Ploss 50 // from Trade
Set Target PProfit 60 // 50 <<<<<<<<<<<<<<
A way to know, within the zero bars, to really know which ones need the tick per tick is optimizing a variable. In the summary list, set how many times you need to tick by tick. Since all the zero bars do not have to be undefined, you may simply touch the take or the stop. In this robot, it would only take 4 ticks per tick
Results attached. It’s good but I don’t think it’s any better than our best ones so far. Draw is 27% and there are too many “dips”. Plus max loss and consecutive losses are not as good. We could use this as a “second stage” system after the lower risk one maybe. What variables have you optimised ?
Also, sorry, I couldn’t quite understand your comment about the zero bars, could you explain a bit further, thanks
The truth that this last year has been very good for this strategy, this week and during the weekend will try to optimize sales operations, but if it is not productive, it is best to limit to buying operations. As far as the ceilings, as I can show you an example
This is an example of zero bar that would not need tick by tick. In the list of backtest would appear like duration or bars, but would not be an indefinite result. Do not touch take and stop within the same bar. When performing the optimization of variables, it appears that this robot, in 4 years and a half, would only need 4 times to tick by tick. Only 4 times in this period, the price touches take and stop in the same bar.
DEFPARAM CumulateOrders = true
once ordersize=1
// Conditions
MA1 = Average [2]
MA2 = Average [13]
MA3 = Average [11]
MA4 = Average [4]
c1 = Ma1>MA2
c122 = Ma3>MA4
t1 = time >= 090000
t2 = time = 180000
d1 = dayofweek = 2
d2 = dayofweek = 4
capital=strategyprofit+3000
a=capital/3000
if a<1 then
a=1
endif
if a>10 then
a=10
endif
// buy
indicator13 = MACD[12,26,9](close)
c13 = (indicator13 < 30)
indicator11 = ExponentialAverage[20](close)
c11 = (close >= indicator11)
indicator1 = MACDline[12,26,9](close)
indicator2 = ExponentialAverage[12](indicator1)
c12 = (indicator1 > indicator2)
//sell
indicator1111 = ExponentialAverage[20](close)
c1111 = (close <= indicator1111)
indicator111 = MACDline[12,26,9](close)
indicator2111 = ExponentialAverage[9](indicator111)
c1211 = (indicator111 < indicator2111)
if not onmarket then
If d1 And t1 and c1 and c11 and c12 and c13 THEN
IF PositionPerf(1) < 0 THEN
OrderSize = OrderSize+a
if ordersize<1 then
ordersize=1
ENDIF
ELSIF PositionPerf(1) > 0 THEN
OrderSize = a
if ordersize<1 then
ordersize=1
ENDIF
endif
buy ordersize Contract At Market
Endif
If d1 And t1 and c122 and c1111 and c1211 THEN
IF PositionPerf(1) < 0 THEN
OrderSize = OrderSize+a
if ordersize<1 then
ordersize=1
ENDIF
ELSIF PositionPerf(1) > 0 THEN
OrderSize = a
if ordersize<1 then
ordersize=1
ENDIF
endif
sellshort ordersize Contract At Market
Endif
endif
If d2 and t2 then
exitshort at market
endif
Set Stop Ploss 50 // from Trade
Set Target PProfit 50 // from Trade
DEFPARAM CumulateOrders = true
once ordersize=1
// Conditions
MA1 = Average [2]
MA2 = Average [13]
MA3 = Average [11]
MA4 = Average [4]
c1 = Ma1>MA2
c122 = Ma3>MA4
t1 = time >= 090000
t2 = time = 180000
d1 = dayofweek = 2
d2 = dayofweek = 4
capital=strategyprofit+3000
a=capital/3000
if a<1 then
a=1
endif
if a>10 then
a=10
endif
// buy
indicator13 = MACD[12,26,9](close)
c13 = (indicator13 < 30)
indicator11 = ExponentialAverage[20](close)
c11 = (close >= indicator11)
indicator1 = MACDline[12,26,9](close)
indicator2 = ExponentialAverage[12](indicator1)
c12 = (indicator1 > indicator2)
//sell
indicator1111 = ExponentialAverage[20](close)
c1111 = (close <= indicator1111)
indicator111 = MACDline[12,26,9](close)
indicator2111 = ExponentialAverage[9](indicator111)
c1211 = (indicator111 < indicator2111)
if not onmarket then
If d1 And t1 and c1 and c11 and c12 and c13 THEN
IF PositionPerf(1) < 0 THEN
OrderSize = OrderSize+1
if ordersize<1 then
ordersize=1
ENDIF
ELSIF PositionPerf(1) > 0 THEN
OrderSize = a
if ordersize<1 then
ordersize=1
ENDIF
endif
buy ordersize Contract At Market
Endif
If d1 And t1 and c122 and c1111 and c1211 THEN
IF PositionPerf(1) < 0 THEN
OrderSize = OrderSize+1
if ordersize<1 then
ordersize=1
ENDIF
ELSIF PositionPerf(1) > 0 THEN
OrderSize = a
if ordersize<1 then
ordersize=1
ENDIF
endif
sellshort ordersize Contract At Market
Endif
endif
If d2 and t2 then
exitshort at market
endif
Set Stop Ploss 50 // from Trade
Set Target PProfit 50 // from Trade
MA1 to MA4 moving average periods are over optimized IMO. If you want to filter trend without optimization over the past data, you should try to use adaptive periods moving average, there are plenty of them in the code library. I don’t say it will be better, but you should give it a try! Remember that “the best is the enemy of the good” 🙂
Hi all. Question in relation to this and any other strategy which uses
DEFPARAM CumulateOrders = true
Is it possible to limit the number of “cycles” orders can be accumulated in a 24hr period? I’m thinking about minimising the risk of allowing orders to continuously accumulate, for example in the instance of a natural disaster or terrorist attack. It would be especially useful on strategies which are left to run overnight.
Can anyone help with the coding?
Thanks
Hi jonjon, you can put false, nothing happens, practically does not change
Hi Raul. I already have fuses in my strategies. What I’m interested in is additionally limiting the amount of trades in a day whilst still being able to accumulate orders. For example, if a strategy on average returns 3 trades a day, ideally I would want to limit number of trades in 1 day to let’s say 10 trades. If it was to trade 10 times in a day (or more) it could be due to a macro event or worse and I would want to not trade. If you have wide stops (which occasionally I do) it is possible to accumulate orders without getting stopped out or the fuse(s) being triggered and then potentially getting a big loss at the end of the trading period when all positions are closed.
An alternative could be to have a fuse which works out your loss midway during a trade(s) instead of when the position(s) is closed. It can then stop the strategy if the daily loss is greater than x no matter how many trades are open. Is this possible? I’ve only seen fuses which calculate once a trade is closed.
Results as below (system 7) – I have include the system 3 performance for overall comparison and also adjusted a version of System 3 incorporating your code for the short side (System 3 Long + short). Overall the draw of 7 is acceptable at 15% but the profit curve is not ideal as I think it’s too steep to be realistic. Adding the short code to system 3 produces better long terms results but the draw of 50% is too big.
Looking at the stats, it seems like the short side is not as profitable, maybe it might be worth seeing if different sl/tp levels for shorts produces better results. Also I agree with Nicolas above, we do want to be careful not to overoptimise the variables.
On the CAC system, the results so far this week for live vs backtest match up. Only 1 trade to compare (as system only trades on Tuesdays) but a good start with no differences.
Thank you very much manel. I think the best is still system 3. but I still fear the martingale, although this limited. A serious loss would be great. I have a couple more robots on the dax, taken from this same page that you would like to try 200000 bars. If you took the steps would you do the screenshots? Thank you!