The7 strategy

Posted By: jcl

The7 strategy - 09/30/12 16:04

I just found this simple strategy on another forum, posted by someone with the name "The7". With some small modifications it was quite successful in a WFO test and gets > 7000 pips annual profit:

Code:
function run()
{
  set(TESTNOW|PLOTNOW|PARAMETERS);
  NumWFOCycles = 8;
  BarPeriod = 1440;

  while(asset(loop("EUR/USD","AUD/USD","USD/CAD"))) 
  {
     var Period = optimize(5,3,15);
     var EMA5H = LowPass(series(priceHigh()),3*Period);
     var EMA5L = LowPass(series(priceLow()),3*Period);

     Stop = (HH(2) - LL(2)) * optimize(1,0.5,5);

    if(priceOpen() > EMA5H && priceClose() < EMA5H && priceLow() > EMA5L)
      enterShort();
    else if(priceOpen() < EMA5L && priceClose() > EMA5L && priceHigh() < EMA5H)
      enterLong();
  }
}



The performance is quite remarkable for such a simple system. Here's the equity curve on a microlot account:


Posted By: TankWolf

Re: The7 strategy - 10/01/12 04:21

I copied your code and run the script just to give it a test, but my equity curve and results look nothing like yours.
Posted By: jcl

Re: The7 strategy - 10/01/12 09:38

Yes, the reason is the parameter bug mentioned on the website. Workshops 5_3 and 6 won't work either, for the same reason - I wonder why people not already have complained about that. The bug only affected 0.99.4, no earlier or later versions. Zorro 1.01 is planned for release tomorrow.
Posted By: Anonymous

Re: The7 strategy - 10/01/12 15:00

I hope Zorro 1.01 will come with forex only versions of Z1 and Z2 so we can test them properly on micro-accounts
Posted By: TankWolf

Re: The7 strategy - 10/04/12 10:47

Originally Posted By: "Code"

function run()
{
set(TESTNOW|PLOTNOW|PARAMETERS);
NumWFOCycles = 8;
BarPeriod = 1440;

while(asset(loop("EUR/USD","AUD/USD","USD/CHF")))
{
var Period = optimize(5,3,15);
var EMA5H = LowPass(series(priceHigh()),3*Period);
var EMA5L = LowPass(series(priceLow()),3*Period);

Stop = (HH(2) - LL(2)) * optimize(1,0.5,5);

if(priceOpen() > EMA5H && priceClose() < EMA5H && priceLow() > EMA5L)
enterShort();
else if(priceOpen() < EMA5L && priceClose() > EMA5L && priceHigh() < EMA5H)
enterLong();
}
}


Originally Posted By: "Result"

Annual return 471%
Profit factor 2.69 (PRR 2.08)
Sharpe ratio 1.53
Kelly criterion 0.51
OptimalF .082
Ulcer index 7%
Prediction error 44%


Change USD/CAD to USD/CHF and the results get even better. jcl I was wondering if we could do another example of setting up the optimal margin and lots on this because I seem to be having alot of trouble getting it to work because in this example we are only using one strategy instead of multiple as like in Workshop 6_2.

One last thing is it possible to set the lots so they increase depending on account size. Say for an random example you want to risk 3% of your current balance on every new trade which sets 30 pip stops. Starting with say 1,000 capital I would normally work out ((Capital/100*Risk%)/Stop) = $ per contract
((1000/100*3)/30 = $1.00 per contract = 0.1 lot. OR

Posted By: jcl

Re: The7 strategy - 10/04/12 12:33

Set FACTORS also, and use the "Margin" variable (not "Lots") for adjusting the trade volume. This is an example of adjusting Margin to the account size:

Code:
//Margin for enterLong()
if(Train)
  Lots = 1;
else if(OptimalFLong > 0) {
  Lots = 1;
  Margin = clamp(Balance * OptimalFLong * 0.1, 5, 1000);
} else 
  Lots = 0;

...

// Margin for enterShort() 
if(Train)
  Lots = 1;
else if(OptimalFShort > 0) {
  Lots = 1;
  Margin = clamp(Balance * OptimalFShort * 0.1, 5, 1000);
} else 
  Lots = 0;



Play with the factor 0.1. The higher it is, the higher is both the profit and the drawdown. Be aware that the annual return percentage always goes down when you reinvest profits, because the drawdowns are higher.
Posted By: jcl

Re: The7 strategy - 10/05/12 06:30

If you want to experiment with this strategy, here's another suggestion:

You see that the strategy uses unfiltered prices of a candle for comparison. This is called "Price Action Trading" and is the usual beginners' method for quickly losing money. Unfiltered prices are mostly random and can normally not be used for a trading system.

Yet this works here, and this hints to a seasonal effect. Try to run the system with different BarOffset values. With no BarOffset, Zorro starts daily bars at GMT midnight, so with BarOffset you can determine the minute into the day when the candle opens. If it's a seasonal effect, the system will only work within a certain BarOffset range that should be different for every currency. F.i. AUD/USD is mostly traded in the Sydney season and USD/CAD mostly in the New York season.

By using individual bar offsets per currency you can most likely get even more profit out of the system. Keep in mind to set BarOffset first before calling asset().
Posted By: sabgto

Re: The7 strategy - 10/07/12 21:17

If my time frame is daily, does HH(2) return the highest price in the last 2 days? Thanks for you reply.
Posted By: jcl

Re: The7 strategy - 10/08/12 07:23

Yes. Here's the description of the traditional indicators:

http://zorro-trader.com/manual/en/ta.htm
Posted By: deweymcg

Re: The7 strategy - 11/04/12 19:25

Do you have an mql equivalent for the lowPass filter? Thanks
Posted By: maudur

Re: The7 strategy - 11/05/12 23:17

Originally Posted By: jcl
If you want to experiment with this strategy, here's another suggestion:

...
Try to run the system with different BarOffset values. With no BarOffset, Zorro starts daily bars at GMT midnight, so with BarOffset you can determine the minute into the day when the candle opens. If it's a seasonal effect, the system will only work within a certain BarOffset range that should be different for every currency. F.i. AUD/USD is mostly traded in the Sydney season and USD/CAD mostly in the New York season.

By using individual bar offsets per currency you can most likely get even more profit out of the system. Keep in mind to set BarOffset first before calling asset().


JCL,

In the code you have:

while(asset(loop("EUR/USD","AUD/USD","USD/CHF")))

How do you set BarOffset before calling asset in it loop? Inside the while body you already called asset.

Thanks.
Posted By: hughbriss

Re: The7 strategy - 11/05/12 23:22

Just put...

BarOffset = whatever;
while(asset(loop("EUR/USD", etc)))
Posted By: maudur

Re: The7 strategy - 11/05/12 23:29

Originally Posted By: hughbriss
Just put...

BarOffset = whatever;
while(asset(loop("EUR/USD", etc)))


Thank you Hugh, but my question is:

I understand the Loop executes the body of the while for each pair, so to put the statement before the while, not setup BarOffset for each pair. What I need is to place a Baroffset different for each pair as suggested by JCL.

Thanks.
Posted By: hughbriss

Re: The7 strategy - 11/06/12 05:46

Sorry, I misunderstood. That is a tricky one.
Posted By: jcl

Re: The7 strategy - 11/06/12 12:50

You have then not only different assets, but also different bar offsets. So you can not just set the asset directly in the while parameter, but must store the instrument string f.i. in another string, and use it to set Baroffset and call asset() inside the loop:

Code:
string myAsset;
while(myAsset = loop("EUR/USD","AUD/USD","USD/CHF"))
{
  if(myAsset == "EUR/USD") BarOffset = 123;
  if(myAsset == "AUD/USD") BarOffset = 456;
  ...
  asset(myAsset);



I haven't tried this myself, but theoretically it should work this way. Mind the '=' and '=='.
Posted By: PriNova

Re: The7 strategy - 11/20/12 19:35

I have another question which makes me crazy about the logic how Zorro handles BarOffsets with Pricedata. Here is an example code and a picture to compare.

this is only an experiment to understand the logic. i took the The7 Strategy Signals.

So the Strategie says for a Short Position. Check if OPEN of the last Candle (priceOpen(1)) is above than EMA_High(1) AND the CLOSE of the last candle (priceClose(1)) is below EMA_High(1) AND the CLOSE of the last candle (priceClose(1)) is above EMA_Low(1).

So here is the code and compare the TimeOffset in the two codes:

Code:
function run()
{
	StartDate = 2012;
	BarPeriod = 60;
	var* priceH = series(priceHigh());
	var* priceL = series(priceLow());
	var *EMAHigh = series(EMA(priceH,5));
	var *EMALow = series(EMA(priceL, 5));
	
	
	//Short 0
	if(priceOpen(1) > EMAHigh[0]
	and priceClose(1) < EMAHigh[1]
	and priceClose(1) > EMALow[1])
	{
		enterShort();
	}
        PlotBars  =150;
	plot("EMAH", EMAHigh[0], 0, BLUE);
	plot("EMAL", EMALow[0], 0, BLUE);
}



And here is the resulting picture. Interesting to see, that the orders are 1 Candle too late.




But if i change the code-logic, which makes me trouble in my head, to this:

Code:
function run()
{
	StartDate = 2012;
	BarPeriod = 60;
	var* priceH = series(priceHigh());
	var* priceL = series(priceLow());
	var *EMAHigh = series(EMA(priceH,5));
	var *EMALow = series(EMA(priceL, 5));
	
	
	//Short 0
	if(priceOpen(0) > EMAHigh[0]
	and priceClose(0) < EMAHigh[0]
	and priceClose(0) > EMALow[0])
	{
		enterShort();
	}
	PlotBars  =150;
	plot("EMAH", EMAHigh[0], 0, BLUE);
	plot("EMAL", EMALow[0], 0, BLUE);
}



Then the results are like in this picture:



And the Orders are exactly at the candle, where they shoudl be.
I don't understand this logic, cause like in the first code, this is how MT4 handles the logic naturally:

MT4:
1. If new candle opens
2. check conditions on last candle, for example MT4-Code: High[1]
3. execute Order on actuall candle with the next tick

Zorro:
1. exactly at close of actual candle
2. check conditions on this candle, which is like the recent last candle in MT4, Zorro: priceHigh(0)
3. execute order on new candle with first tick.

Overall, this is a turnaround in my head. I see problems with some logics, where a trade must be executed on the actual candle (!)befor it closes. for example the actual candle reaches a defined body-size, which implies it as an impulsive candle and i'd like to trade it immediatly instead waiting for candle close.
I read in the manual, that if Zorro is in TRADINGMODE, that the Orderexecution is TICK-based, but how could i calculate the Body from the recent Open to the actual Tick-Price?
This could not be possible, because priceOpen(0) gives me the Openprice of the already closed candle (Open(1) in MT4)

i hope that someone understand what i try to explain here.
Posted By: jcl

Re: The7 strategy - 11/20/12 23:45

All existing trade platforms follow the same simple logic. When a trade signal is generated from the current candle, the order is executed at the next tick, which is the Open of the next candle. You can obviously not execute a trade in the middle of the same candle that generated the trade signal, at least not without a time machine.

If you want to execute a trade in the middle of a candle, in your example by using an entry price limit, you must have generated the trade signal from the candle before. An entry condition can only delay your trade, but can not make it happen earlier.
Posted By: PriNova

Re: The7 strategy - 11/21/12 06:09

Originally Posted By: jcl
All existing trade platforms follow the same simple logic. When a trade signal is generated from the current candle, the order is executed at the next tick, which is the Open of the next candle. You can obviously not execute a trade in the middle of the same candle that generated the trade signal, at least not without a time machine.


this is partially not true and i will show it in a video i make now, because it has nothing to do with a time-machine.

if a trade signal is generated from the current candle, the orders is executed with the next tick, BUT it hasn't to be the open of the next candle. if i'm willing my order could be executed in the same current candle.

pictures are more than words.
Posted By: PriNova

Re: The7 strategy - 11/21/12 07:38

Here is the video now: i hope it is now clearer what i mean, that execution could happen in the current candle as many orders i like and that condition-checks are made in the recent candle indexed at 1.
this is why in my first code the order is executed 1 Candle too late.

[video:youtube]http://www.youtube.com/watch?v=N6Jg-vz5IYQ[/video]

Posted By: jcl

Re: The7 strategy - 11/21/12 08:18

Maybe there are some misunderstandings of the concepts of candles and bars.

- Candles are counted 0, 1, 2 and so on. 1 is not the recent candle as you seem to think, 0 is the recent candle. When candles consists of several bars, the 0 candle can be partial.

- The run function is executed at the end and not in the middle of a bar. A bar has no "middle". Only a candle can have a middle. If you want a run in the middle of a candle for some reason, just make the bar period shorter or the candle time frame longer so that a candle covers several bars.

This is however unusual for a strategy, so I'm not sure if that's what you really want. I have more the impression that you just mean an entry limit.

For details look in the manual on the following pages:

http://zorro-trader.com/manual/en/bar.htm
http://zorro-trader.com/manual/en/run.htm
http://zorro-trader.com/manual/en/barperiod.htm

I hope this helps; otherwise just let me know what you do not understand.

If you think you have to trade in the middle of a candle for some reason, and you don't know how to do that, I'll help. Just open a new thread, as this has nothing to do with the "7" system, and explain the system that you have in mind. There are often several ways to a certain solution.
Posted By: PriNova

Re: The7 strategy - 11/21/12 10:27

thank you for answering.

i think i misuse the word 'recent' which reflects the current candle.

And yes, i will open another thread. This could help a lot of other users to port code from MT4 to Zorro
Posted By: deweymcg

Re: The7 strategy - 11/25/12 18:38

Very odd--I just downloaded Zorro 1.03 and ran this again. The results were very different and nowhere near as good:

Walk-Forward Test TheSeven portfolio - performance report

Simulation period 05.04.2008-02.11.2012
Test period 24.04.2010-02.11.2012
WFO test cycles 7 x 112 bars (23 weeks)
Training cycles 8 x 634 bars (131 weeks)
Lookback time 80 bars (16 weeks)

Gross win/loss 1426$ / -1265$ (+2017p)
Average profit 64$/year, 5$/month, 0$/day
Max drawdown -217$ (MAE -438$)
Max down time 83 weeks from Nov 2010
Largest margin 67$
Trade volume 122446$ (48454$/year)
Transaction costs -28$ spr, -3$ slp, -24$ rol
Capital required $303

Number of trades 141 (55/year)
Percent winning 46%
Max win/loss 98$ / -56$
Avg trade profit 1$ 14.3p (+22$ / -17$)
Avg trade bars 25 (+27 / -23)
Max trade bars 187 (38 weeks)
Time in market 455%
Max open trades 14
Max loss streak 8 (uncorrelated 9)

Annual return 27%
Profit factor 1.13 (PRR 0.89)
Sharpe ratio 0.16
Kelly criterion 0.12
OptimalF .022
Ulcer index 66%
Prediction error 43%

Portfolio analysis OptF ProF Win/Loss Cycles

AUD/USD avg .017 0.65 18/31 \X\\/\X
EUR/USD avg .036 1.91 21/20 /XX/.XX
USD/CHF avg .010 1.12 26/25 X//\XXX

AUD/USD:L .017 1.18 11/13 \/\\/\/
AUD/USD:S .000 0.47 7/18 \\\./\\
EUR/USD:L .030 1.88 12/6 /\//.\/
EUR/USD:S .042 1.93 9/14 ./\/./\
USD/CHF:L .012 1.13 12/11 \//.//\
USD/CHF:S .009 1.12 14/14 ///\\\/
Posted By: jcl

Re: The7 strategy - 11/26/12 08:35

When a strategy performance strongly depends on the simulation period, the strategy is probably unstable and should not be traded with those parameters.

Test the 7 strategy with different WFO cycles and different DataSplit values. If the results are largely different, the strategy is not good - most likely some parameter is over-optimized.
© 2024 lite-C Forums