Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (TedMar, AndrewAMD), 1,043 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
For fun: why did Zorro not trade in some places? #427049
08/01/13 13:54
08/01/13 13:54
Joined: Jul 2013
Posts: 522
D
dusktrader Offline OP
User
dusktrader  Offline OP
User
D

Joined: Jul 2013
Posts: 522
I'm playing with some new features I got from the updated Workshop 5 tutorial (which will presumably appear in an upcoming Zorro version)...

Listed below are the small modifications I made to Workshop5_3 to play with this. But what I'm interested in at the moment is the result chart... look at these 2 charts. One implements the new function which limits max trades to 1. The other has no limits.

Look specifically at the timeframe of 2009. I would like to know why Zorro takes trades when there is no limit, but when trades are limited via the function it does not. Seems like it should at least take 1 trade during this period.

I'm just trying to understand the "why" about this. Thanks in advance if you can shed any light...

Code:
// Workshop 5: Counter trend trading, optimized ////////////////

function reverseShort(int MaxTrades)
{
// update the stops and profit targets of open trades
  if(Stop > 0) 
    exitShort(0,priceClose()+Stop);
  if(TakeProfit > 0) 
    exitShort(0,(priceClose()+TakeProfit));
 
// if MaxTrades is not reached, open a new trade
  if(NumOpenShort < MaxTrades)
    enterShort();
// otherwise, close all opposite trades
  else if(!mode(HEDGING))
    exitLong();
  return 0;
}

function reverseLong(int MaxTrades)
{
// update the stops and profit targets of open trades
  if(Stop > 0) 
    exitLong(0,priceClose()-Stop);
  if(TakeProfit > 0) 
    exitLong(0,-(priceClose()+TakeProfit));
 
// if MaxTrades is not reached, open a new trade
  if(NumOpenLong < MaxTrades)
    enterLong();
// otherwise, close all opposite trades
  else if(!mode(HEDGING))
    exitShort();
  return 0;
}

function run()
{
	set(PARAMETERS+NFA);  // generate and use optimized parameters
	BarPeriod = 240;	// 4 hour bars
	LookBack = 500;
	StartDate = 2002;
	NumWFOCycles = 5; // activate WFO

	if(ReTrain) {
		UpdateDays = -1;	// update price data from the server 
		SelectWFO = -1;	// select the last cycle for re-optimization
	}
	
// calculate the buy/sell signal
	vars Price = series(price());
	vars DomPeriod = series(DominantPeriod(Price,30));
	var LowPeriod = LowPass(DomPeriod,500);
	vars HP = series(HighPass(Price,LowPeriod*optimize(1,0.5,2)));
	vars Signal = series(Fisher(HP,500));
	var Threshold = optimize(1,0.5,2,0.1);

// buy and sell
	Stop = optimize(4,2,8) * ATR(100);
	Trail = 4*ATR(100);
	if(crossUnder(Signal,-Threshold))
		reverseLong(1); //max 1 trade, update stops
		//enterLong();
	else if(crossOver(Signal,Threshold))
		reverseShort(1); //max 1 trade, update stops
		//enterShort();

	PlotWidth = 800;
	PlotHeight1 = 300;
}


Attached Files
EURUSD_max1trade.png (19 downloads)
EURUSD_nolimit.png (18 downloads)
Re: For fun: why did Zorro not trade in some places? [Re: dusktrader] #427059
08/01/13 14:51
08/01/13 14:51
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
It does not omit trades with my workshop 5 script. But I believe your reverseShort function has a mistake, here is mine:

Code:
TRADE* reverseShort(int MaxTrades)
{
	if(Stop > 0) 
		exitShort(0,priceClose()+Stop); 
	if(TakeProfit > 0) 
		exitShort(0,-(priceClose()-TakeProfit));
	if(NumOpenShort < MaxTrades)
		return enterShort();
	else if(!mode(HEDGING))
		exitLong();
	return 0;
}


Re: For fun: why did Zorro not trade in some places? [Re: jcl] #427060
08/01/13 15:07
08/01/13 15:07
Joined: May 2013
Posts: 245
S
swingtraderkk Offline
Member
swingtraderkk  Offline
Member
S

Joined: May 2013
Posts: 245
Jcl,

Apolgies,

I'm not a C programmer, can you explain what TRADE* does please?

Re: For fun: why did Zorro not trade in some places? [Re: swingtraderkk] #427097
08/02/13 06:27
08/02/13 06:27
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
It is a pointer to the trade struct, or 0 when the trade could not be opened.

Pointers and structs are not explained in the tutorial because you won't need them in simple strategies. They are used in more complex scripts or strategies. You can find at the end of workshop 3 some links to C courses where pointers and structs are explained.

Re: For fun: why did Zorro not trade in some places? [Re: jcl] #427099
08/02/13 08:15
08/02/13 08:15
Joined: May 2013
Posts: 245
S
swingtraderkk Offline
Member
swingtraderkk  Offline
Member
S

Joined: May 2013
Posts: 245
OK,

So I think I now understand pointers and what a struct is.

The syntax is still confusing me:

Are you telling the function reverseShort() that when passed an integer called max trades it is to execute whats inside the {} and then return a pointer to a trade struct?

Why is this necessary or superior to simply declaring the function with function?

Re: For fun: why did Zorro not trade in some places? [Re: swingtraderkk] #427100
08/02/13 08:26
08/02/13 08:26
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
In the example above it's not necessary.

In the general case, it's useful for finding if the trade was opened or not, or for storing the trade pointer for other purposes such as maintaining a trade statistics list or something similar.

Re: For fun: why did Zorro not trade in some places? [Re: jcl] #427109
08/02/13 10:17
08/02/13 10:17
Joined: Jul 2013
Posts: 522
D
dusktrader Offline OP
User
dusktrader  Offline OP
User
D

Joined: Jul 2013
Posts: 522
Hi jcl, my reverseShort function did have an error, thanks for finding that!

But I'm still getting the same result, even when I copy/paste your exact code from above. (ie, the missing trades section mentioned above)

However please note I have changed:
Code:
TRADE* reverseShort(int MaxTrades)


to simply
Code:
function reverseShort(int MaxTrades)



I am running v1.12.1. The TRADE* notation doesn't seem to work as written in this version?

Re: For fun: why did Zorro not trade in some places? [Re: dusktrader] #427129
08/02/13 15:26
08/02/13 15:26
Joined: Jul 2013
Posts: 522
D
dusktrader Offline OP
User
dusktrader  Offline OP
User
D

Joined: Jul 2013
Posts: 522
Aha! I think I figured this out. The reason that the chart trades look different when changing the strategy from using enterLong() to reverseLong() is because I've been re-training it between those changes.

When re-training, apparently it gets different parameters that cause it to actually trade differently.

This light-bulb went off in my head when I accidentally forgot to re-train after flipping the strategy. I just clicked Test and then Result... and doing this (ie, using same parameter set) shows trading throughout (or not) consistently during that 2009 period.

Now I feel accomplished LOL. I can say the week hasn't been a waste for my ongoing Zorro knowledge...


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1