Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,244 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Collection of Useful General-Purpose functions #410654
11/06/12 18:25
11/06/12 18:25
Joined: Oct 2012
Posts: 16
Aix en Provence, France
Squalou Offline OP
Newbie
Squalou  Offline OP
Newbie

Joined: Oct 2012
Posts: 16
Aix en Provence, France
Hi all,

I am starting this thread to build together some kind of "useful general-purpose functions" repository.

The idea is to post in this thread all kinds of functions that you found useful to yourself, and could be also helpful to others.

Having a centralized area collecting these functions would greatly help newcomers to Zorro in writing their own strategies with even less time than it is already ! cool

Hopefully this thread could even become a new SECTION in the forum, i'm sure it will attract a lot of programmers.

Perhaps we can think of some way to put some of these functions in a true Zorro source code library file, as it is the case with indicators.c for instance.

My first contribution comes right next...

Sq

Re: Collection of Useful General-Purpose functions [Re: Squalou] #410655
11/06/12 18:31
11/06/12 18:31
Joined: Oct 2012
Posts: 16
Aix en Provence, France
Squalou Offline OP
Newbie
Squalou  Offline OP
Newbie

Joined: Oct 2012
Posts: 16
Aix en Provence, France
So, here is my first contribution.

a function to plot the Equity and Balance curves below your Zorro result charts.

Code:
// plotting Equity & Balance curves on your Zorro result charts.

// add this forward declaration on top of your script:
function plot_balance_equity();

// next comes your script:

//---------------------------------------
function run()
//---------------------------------------
{
	// set this to automatically produce the result chart at the end of a [Test]
	set(PLOTNOW);

	// your strategy code goes here, for instance:

	while(asset(loop("EUR/USD"/*,"AUD/USD","GBP/USD","GER30","NAS100","SPX500","UK100","UKOil","US30","USD/CAD","USD/CHF","USD/JPY","USDOLLAR","USOil","XAG/USD","XAU/USD"*/)))
	{

		// ... your trading decisions here ...

		//---------------------------------------
		// now plot the Balance & Equity curves
		plot_balance_equity();
		//---------------------------------------
		
	} // asset(loop(...))
	
	
	// set the size of the resulting chart PNG file
	PlotWidth   = 2000;
	PlotHeight1 = 500;
}

// here is the actual function:

//---------------------------------------
function plot_balance_equity()
//---------------------------------------
{
	var *EquityCurve = series(WinTotal - LossTotal + WinValTotal - LossValTotal);
	plot("Balance",Balance,NEW,BLUE);
	plot("Equity",*EquityCurve,0,GREEN);
}

//end


Re: Collection of Useful General-Purpose functions [Re: Squalou] #410656
11/06/12 18:44
11/06/12 18:44
Joined: Oct 2012
Posts: 16
Aix en Provence, France
Squalou Offline OP
Newbie
Squalou  Offline OP
Newbie

Joined: Oct 2012
Posts: 16
Aix en Provence, France
Here is an example a very simple strategy script to illustrate the use of this function.

Code:
// plotting Equity & Balance curves on your Zorro result charts.

function plot_balance_equity(); // forward declaration of the new function

//---------------------------------------
function run()
//---------------------------------------
{
	set(PLOTNOW); // set this to automatically produce the result chart at the end of a [Test]

// your strategy code goes here, for instance:

	while(asset(loop("EUR/USD"/*,"AUD/USD","GBP/USD","GER30","NAS100","SPX500","UK100","UKOil","US30","USD/CAD","USD/CHF","USD/JPY","USDOLLAR","USOil","XAG/USD","XAU/USD"*/)))
	{

		// ... your trading decisions come here ...
		var *ClosePrice = series(priceClose());
		var *distfromMA = series(*ClosePrice-EMA(ClosePrice,100));
		if (distfromMA[0] > 0) enterLong();  // enter Long above MA (& close all Shorts)
		if (distfromMA[0] < 0) enterShort(); // enter Short below MA (& close all Longs)
		
		//---------------------------------------
		// now plot the Balance & Equity curves
		plot_balance_equity();
		//---------------------------------------
		
	} // asset(loop(...))
	
	
	// set the size of the resulting chart PNG file
	PlotWidth   = 2000;
	PlotHeight1 = 500;
}

//---------------------------------------
function plot_balance_equity()
//---------------------------------------
{
	var *EquityCurve = series(WinTotal - LossTotal + WinValTotal - LossValTotal);
	plot("Balance",Balance,NEW,BLUE);
	plot("Equity",*EquityCurve,0,GREEN);
}

//end




Sorry, i haven't found yet how to attach a file to a post...
(i cannot find the "File Manager" link on the "new post" page... HELP!)

I would have also loved posting a resulting chart to actually show how this looks like...
blush

Sq

Re: Collection of Useful General-Purpose functions [Re: Squalou] #410660
11/06/12 19:52
11/06/12 19:52
Joined: Oct 2012
Posts: 22
G
Guiom Offline
Newbie
Guiom  Offline
Newbie
G

Joined: Oct 2012
Posts: 22
Great function here, thanks.

In the forum FAQ is shows that to "In order to add an image to your message or your signature, you must have the image already available on a web server and reachable by a URL"

Guiom

Re: Collection of Useful General-Purpose functions [Re: Guiom] #413316
12/12/12 01:26
12/12/12 01:26
Joined: Nov 2012
Posts: 209
S
SFF Offline
Member
SFF  Offline
Member
S

Joined: Nov 2012
Posts: 209
I am looking for a generic anti-martingale money management function.
It is a simple and basic money management.

Last edited by SFF; 12/12/12 01:26.
Re: Collection of Useful General-Purpose functions [Re: SFF] #414178
12/24/12 19:11
12/24/12 19:11
Joined: Dec 2012
Posts: 14
P
Pipinator Offline
Newbie
Pipinator  Offline
Newbie
P

Joined: Dec 2012
Posts: 14
Thanks Squalu! Good idea for the thread.

Pip


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