Ok, its time to move forward.

Quote:

// Build 0004

// #define ASSETLOOP "USD/CHF", "EUR/USD", "GBP/USD", "USD/CAD", "AUD/USD", "USD/JPY", "XAU/USD", "XAG/USD", "NAS100", "SPX500", "GER30", "US30", "UK100" //FOREX SET
#define ASSETLOOP "EUR/USD", "GBP/USD", "USD/CAD", "AUD/USD", "USD/JPY", "XAU/USD", "XAG/USD" // No Stock
//#define ASSETLOOP "USD/CHF", "EUR/USD","USD/JPY","XAU/USD","SPX500"//MIN FOREX SET
//#define ASSETLOOP "EUR/USD" //test asset

//---- Global VAR ----
int myCapital = 0;
var myMargin = 0;
var comp = 0;
//--------------------

function setSlider()
{
myCapital = slider(1,2500,0,25000,"Capital"," Initial Capital"); //used for compounding calculation
myMargin = slider(2,50,0,500,"Margin"," Initial Margin"); // fixed or initial Margin
comp= slider(3,0,0,1,"Comp.", "0=Fixed Margin 1=Compound Margin");
}

function checkEquity()
{
// equity curve trading: switch to phantom mode when the equity
// curve goes down and is below its own lowpass filtered value

if(Train) { Lots = 1; return; } // no phantom trades in training mode
vars EquityCurve = series(ProfitClosed+ProfitOpen);
vars EquityLP = series(LowPass(EquityCurve,10));
if(EquityLP[0] < LowPass(EquityLP,100) && falling(EquityLP))
Lots = -1; // drawdown -> phantom trading
else
Lots = 1; // profitable -> normal trading
}

function enterFSLong()
{
if(comp == 1 && !is(TRAINMODE)) {
Margin = OptimalFLong * myMargin * sqrt(1 + max(0,(WinLong-LossLong)/myCapital));
enterLong();
} else {
Margin=myMargin;
enterLong();
}
}

function enterFSShort()
{
if(comp == 1 && !is(TRAINMODE)) {
Margin = OptimalFShort * myMargin * sqrt(1 + max(0,(WinShort-LossShort)/myCapital));
enterLong();
} else {
Margin=myMargin;
enterLong();
}
}

function CLSTR()
{
TimeFrame=24;

Stop = 2*ATR(14);
Trail = Stop;
TrailLock = 10;

checkEquity();

var dayL = optimize(40,10,80);
var dayS = optimize(40,10,80);

if (priceHigh() >= HH(dayL)) enterFSLong();
if (priceLow() <= LL(dayS)) enterFSShort();
}

function CNTR()
{
TimeFrame = 4;
Stop = optimize(4,2,8) * ATR(100);
Trail = 4*ATR(100);

vars Price = series(price());
vars Filtered = series(BandPass(Price,optimize(30,20,40),0.5));
vars Signal = series(Fisher(Filtered,500));
var Threshold = optimize(1,0.5,1.5,0.1);

checkEquity();

if(crossUnder(Signal,-Threshold)) enterFSLong();
else if(crossOver(Signal,Threshold)) enterFSShort();
}

function TRND()
{
TimeFrame = 1;
Stop = optimize(4,2,8) * ATR(100);
Trail = 0;

vars Price = series(price());
vars Trend = series(LowPass(Price,optimize(500,300,800)));

checkEquity();

if(valley(Trend)) enterFSLong();
else if(peak(Trend)) enterFSShort();
}

function run()
{
set(PARAMETERS+FACTORS); // generate and use optimized parameters and factors

BarPeriod = 60; // 1 hour bars
LookBack = 2500; // needed for Fisher()
NumWFOCycles = 6; // activate WFO

StartDate = 2009;
EndDate = 2014;
Hedge=5;

if(ReTrain) {
UpdateDays = -1; // update price data from the server
SelectWFO = -1; // select the last cycle for re-optimization
reset(FACTORS); // don't generate factors when re-training
}
NumWFOCycles = 6; // activate WFO

setSlider();

// portfolio loop
while(asset(loop(ASSETLOOP)))
while(algo(loop("TRND","CNTR","CLSTR")))
{
if(Algo == "TRND")
TRND();

if(Algo == "CNTR")
CNTR();

if(Algo == "CLSTR")
CLSTR();
}

PlotWidth = 700;
PlotHeight1 = 400;
//ColorUp = ColorDn = ColorWin = ColorLoss = 0; // don't plot candles and trades
//set(TESTNOW+PLOTNOW);
}


mainly no change in the trading strategy, re-arranged the run function, some service functions amd prepared the slider in order to be execute in demo with the possibility to change some money Management parameters. I have added anothe assets set because my broker does not have the same feed as the Zorro's.

Strategies, Broker (Assets/minimal lot size/commission structure) are the nexy open question. I have to study...

Last edited by MatPed; 03/09/15 14:00.