Gamestudio Links
Zorro Links
Newest Posts
Chat Room for Zorro Programmers
by danatrader. 07/02/20 18:35
Locating unfreed memory
by Dooley. 07/02/20 14:39
A9
by Aku_Aku. 07/02/20 12:43
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 07/02/20 11:11
Help with code
by danatrader. 07/02/20 04:22
Grid Trading - dynamic
by danatrader. 07/01/20 17:15
Fuzzy Range
by AndrewAMD. 07/01/20 16:57
new macro: break_assets
by AndrewAMD. 07/01/20 01:01
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
8 registered members (3run, Zheka, deus777, kvm, Quad, Ayumi, alibaba, 20BN), 422 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
carolthesecond, Roger399, vrindger, XRaf, pchen90
18472 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Optimize non asset/algo specific #478577
11/11/19 08:07
11/11/19 08:07
Joined: Jul 2019
Posts: 41
Köln
S
StefanCGN Offline OP
Newbie
StefanCGN  Offline OP
Newbie
S

Joined: Jul 2019
Posts: 41
Köln
Hi, I am trying to use optimize for parameters independently from assets / algos. The manual says that I have to enumerate assets in a for loop and call optimize outside loop. All my tries do not work... Individual optimization is done. WHY?

function run()

{



set(PARAMETERS+FACTORS);

AssetList = "AssetsOandaEUR100extended.csv";

BarPeriod = 60; // 1 hour bars

LookBack = 1800;

NumYears = 10;

NumWFOCycles = 10;

Hedge = 2;

Weekend = 2;

StartWeek = 10400; // start Monday 4 am

EndWeek = 51900; // end Friday 7 pm

if(Train) {

Detrend = PRICES;

NumSampleCycles = 4; }



int i;

for(i=0; Assets[i]; i++)

{ asset(Assets[i]); }

asset("EUR/USD");

algo("MOMENT_FX");



var Threshold = optimize(1,0.25,3,0.25);

int r = optimize(20,1,20,2);

Last edited by StefanCGN; 11/11/19 11:04.
Re: Optimize non asset/algo specific [Re: StefanCGN] #478581
11/11/19 11:51
11/11/19 11:51
Joined: Jul 2000
Posts: 27,249
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,249
Frankfurt
That's no individual optimization. In fact it's no optimization at all.

For getting help with coding, please post the same script that you had a problem with, and please use code formatting so that it is readable.

Re: Optimize non asset/algo specific [Re: StefanCGN] #478582
11/11/19 12:11
11/11/19 12:11
Joined: Jul 2019
Posts: 41
Köln
S
StefanCGN Offline OP
Newbie
StefanCGN  Offline OP
Newbie
S

Joined: Jul 2019
Posts: 41
Köln
In fact it is an adaption of your currency strength skript. If I start to train this, it is still going through all assets to optimize:

Code
 
int TrailingStop(var range )

{

  if(TradeIsLong and TradeIsOpen and TradeProfit > 0)

    TradeStopLimit = max(TradeStopLimit,LL(range));

  else if(TradeIsShort and TradeIsOpen and TradeProfit > 0)      

           TradeStopLimit = min(TradeStopLimit,HH(range));

return 0;

}

 

function run()

{

 

          set(PARAMETERS+FACTORS); 

          AssetList = "AssetsOandaEUR100extended.csv";

          BarPeriod = 60;        // 1 hour bars

          LookBack = 1800;    

          NumYears = 10;

          NumWFOCycles = 10;

          Hedge = 2;

          Weekend = 2;

          StartWeek = 10400; // start Monday 4 am

          EndWeek = 51900; // end Friday 7 pm

          if(Train) {

          Detrend = PRICES;

          NumSampleCycles = 4; }

         

 

          Capital = slider(1,4000,0,7000,"Capital","initial captial");

         

          Margin = 0.5 * OptimalF * Capital;

         

         

          int i=0;

 

          for(i=0; Assets[i]; i++)

          {asset(Assets[i]);

          i++;}

         

          var Threshold = optimize(1,0.25,3,0.25);

          int r = optimize(20,1,20,2);

         

 

  

          ccyReset();

  string Name;

  while(Name = (loop(Assets)))

  {

    if(assetType(Name) != FOREX)

      continue; // Currency pairs only

    asset(Name);

    vars Prices = series(priceClose());

    ccySet(ROC(Prices,1)); // store price change as strength

  }

 

  

  

// get currency pairs with highest and lowest strength difference

          string Best = ccyMax(), Worst = ccyMin();

   asset(Best);

   vars Prices_b = series(priceClose());

          vars roc_b = series(ROC(Prices_b,1));

          vars zscore_b = series(zscore(roc_b[0],1800));

          asset(Worst);

          vars Prices_w = series(priceClose());

          vars roc_w = series(ROC(Prices_w,1));

          vars zscore_w = series(zscore(roc_w[0],1800));

 

                   

          static char OldBest[8], OldWorst[8]; // static for keeping contents between runs

  if(*OldBest && !strstr(Best,OldBest)) { // new strongest asset?

    asset(OldBest);

    exitLong();

    if(zscore_b[0] > Threshold) {

      asset(Best);

                    Stop = 2*ATR(20);

      enterLong(TrailingStop,r);

    }

  }

  if(*OldWorst && !strstr(Worst,OldWorst)) { // new weakest asset?

    asset(OldWorst);

    exitShort();

    if(zscore_w[0] < -Threshold) {

      asset(Worst);

                    Stop = 2*ATR(20);

      enterShort(TrailingStop,r);

    }

  }

 

// store previous strongest and weakest asset names 

  strcpy(OldBest,Best);

  strcpy(OldWorst,Worst);


}


Last edited by StefanCGN; 11/11/19 14:15.
Re: Optimize non asset/algo specific [Re: StefanCGN] #478583
11/11/19 14:11
11/11/19 14:11
Joined: Feb 2017
Posts: 1,012
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,012
Chicago
First of all, you should write [/code] instead of [code/] at the end of your code block.

Second, if your intent was to optimize each individual asset, you are certainly not doing that. You must put your optimize() call inside of your asset loop(). To be explicitly clear, your while loop must be using the loop() call, and the optimize() call must be in that same exact while loop.

Re: Optimize non asset/algo specific [Re: AndrewAMD] #478584
11/11/19 14:15
11/11/19 14:15
Joined: Jul 2019
Posts: 41
Köln
S
StefanCGN Offline OP
Newbie
StefanCGN  Offline OP
Newbie
S

Joined: Jul 2019
Posts: 41
Köln
Thanks, but I want explicitly the opposite: Parameters should be in depended from algo/asset. That's why I placed the calls outside.... But the optimizer still goes through the components....

Re: Optimize non asset/algo specific [Re: StefanCGN] #478585
11/11/19 14:51
11/11/19 14:51
Joined: Feb 2017
Posts: 1,012
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,012
Chicago
Then don't use loop().

Instead of while(loop()), use for(listed_assets){asset(Asset); /* etc */}. But keep your optimize() calls outside of the for loop.

Re: Optimize non asset/algo specific [Re: AndrewAMD] #478586
11/11/19 15:32
11/11/19 15:32
Joined: Jul 2019
Posts: 41
Köln
S
StefanCGN Offline OP
Newbie
StefanCGN  Offline OP
Newbie
S

Joined: Jul 2019
Posts: 41
Köln
Thanks a lot. That helped!!! :-)


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1