Hey guys,
I am working on a extended version of the portfolio workshop script. My plan is to make this script more flexible – so it is able to trade different algos on different assets.
So far i used 4 dummy algos (Stategy1, …) which were are supposed to be traded in 2 groups.

Algo1&Algo2@Asset1
Algo3&Algo4@Asset2

I tried a very pathetic version:

Code:
// First Asset loop
  while(asset(loop("EUR/USD")))
  while(algo(loop("S1","S2")))
  {
    Margin = 0.5 * OptimalF * Capital;
    if(Algo == "S1") 
      trade_S1();
    else if(Algo == "S2") 
      trade_S2();
  }
// Second Asset loop
  while(asset(loop("EUR/JPY")))
  while(algo(loop("S3","S4")))
  {
    Margin = 0.5 * OptimalF * Capital;
    if(Algo == "S3") 
      trade_S3();
    else if(Algo == "S4") 
      trade_S4();
  }
}


and ofc it doenst work.

"Too many loops(max 2)!"

so i guess i need more "nested" version...

i hope someone has any idea how to get his done.

thx a lot in advance

(P.S. i know, i could potentially use multiple instances of zorro with each one "simple" portfolio - but my api does not allow more than one log-in)


First part of the script
Code:
// Strategy 1 - dummy from workshop
function trade_S1()
{
  TimeFrame = 4;
  vars Price = series(price());
  vars Filtered = series(BandPass(Price,optimize(30,25,35),0.5));
  vars Signal = series(Fisher(Filtered,500));
  var Threshold = optimize(1,0.5,2,0.1);
  Stop = optimize(4,2,10) * ATR(100);
  Trail = 4*ATR(100);
  if(crossUnder(Signal,-Threshold))
    enterLong();
  else if(crossOver(Signal,Threshold))
    enterShort();
}
// Strategy 2 - dummy from workshop
function trade_S2()
{
  TimeFrame = 1;
  vars Price = series(price());
  vars Trend = series(LowPass(Price,optimize(500,300,700)));
    Stop = optimize(4,2,10) * ATR(100);
  Trail = 0;
  vars MMI_Raw = series(MMI(Price,300));
  vars MMI_Smooth = series(LowPass(MMI_Raw,500));
    if(falling(MMI_Smooth)) 
  {
    if(valley(Trend))
      enterLong();
    else if(peak(Trend))
      enterShort();
  }
}
// Strategy 3 - dummy from workshop
function trade_S3()
{
  TimeFrame = 4;
  vars Price = series(price());
  vars Filtered = series(BandPass(Price,optimize(30,25,35),0.5));
  vars Signal = series(Fisher(Filtered,500));
  var Threshold = optimize(1,0.5,2,0.1);

  Stop = optimize(4,2,10) * ATR(100);
  Trail = 4*ATR(100);

  if(crossUnder(Signal,-Threshold))
    enterLong();
  else if(crossOver(Signal,Threshold))
    enterShort();
	}
// Strategy 4 - dummy from workshop
function trade_S4()
{
  TimeFrame = 1;
  vars Price = series(price());
  vars Trend = series(LowPass(Price,optimize(500,300,700)));
  
  Stop = optimize(4,2,10) * ATR(100);
  Trail = 0;

  vars MMI_Raw = series(MMI(Price,300));
  vars MMI_Smooth = series(LowPass(MMI_Raw,500));
  
  if(falling(MMI_Smooth)) 
  {
    if(valley(Trend))
      enterLong();
    else if(peak(Trend))
      enterShort();
  }
	}
// Function run every new bar
function run()
{
  set(PARAMETERS+FACTORS+LOGFILE);
  BarPeriod = 60; 
  LookBack = 2000;
  StartDate = 2005;
  NumWFOCycles = 10;  
  Capital = 10000;	
// Retraining
  if(ReTrain) {
    UpdateDays = -1;  
    SelectWFO = -1;	
    reset(FACTORS); 
  }


Attached Files
flexport.c (1 downloads)