0 registered members (),
1,382
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
OP
Newbie
|
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 ! 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
OP
Newbie
|
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.
// 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
OP
Newbie
|
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.
// 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... Sq
|
|
|
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
SFF
Member
|
Member
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.
|
|
|
|