Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 20:05
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
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
0 registered members (), 1,438 guests, and 5 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
Page 2 of 2 1 2
Re: RINA 3D optimization charts [Re: ] #435494
01/08/14 13:54
01/08/14 13:54
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
The for() loop won't work here because it would be exeuted for any strategy run.

Instead:

int StepsFast = 10, StepsSlow = 40;
NumTotalCycles = StepsSlow * StepsFast;

and then:

Fast = 10 + (TotalCycle % StepsFast);
Slow = 20 + (TotalCycle / StepsFast);

at least that's the basic idea.

Re: RINA 3D optimization charts [Re: ] #435503
01/08/14 15:31
01/08/14 15:31
Joined: Jun 2013
Posts: 41
Ohio, USA
P
Pork Offline
Newbie
Pork  Offline
Newbie
P

Joined: Jun 2013
Posts: 41
Ohio, USA
Hi Liftoff,

I see a problem with this
for(Slow; Slow<=MaxSlow;++Slow){
for(Fast; Fast<=MaxFast;++Fast){
vars Price = series(priceClose()),
Fast = series(SMA(Price,Fast)),
Slow = series(SMA(Price,Slow));
the variable Slow is in the for loop and then also in the series.
Same problem with Fast. Two of them need to be renamed.
P

Re: RINA 3D optimization charts [Re: jcl] #435505
01/08/14 15:39
01/08/14 15:39
Joined: Dec 2013
Posts: 11
J
Jeff_Raven Offline
Newbie
Jeff_Raven  Offline
Newbie
J

Joined: Dec 2013
Posts: 11
liftoff, you're using Slow and Fast as variable names for 3 different things:
1. int Fast for the starting point of your loop
2. as the control variable for the for loop
3. as the name of a series that contains doubles

Looking through the code, it seems like you expect to get 30 lines of output. When I run your code, I get 10 with odd values.

The sprintf statement doesn't look right (could be because I don't know what %i is as a format. I can't find it in the manual).

Just as a shell, without the trading portion, try this:
Code:
function run()
{
  StartDate = 2003;
  EndDate   = 2008;
  BarPeriod = 30;
  LookBack  = 60;          // changed from 30 Maximum period is 60
  asset("GBP/USD");

  int  MinSlow = 20;       // renamed
  int  MinFast = 1;        // renamed
  int  MaxSlow = 60;
  int  MaxFast = 10;
  int  ThisFast, ThisSlow; // while loop control variables

  // no trade costs...
  Spread    = 0;
  Slippage  = 0;
  RollLong  = RollShort = 0;
  char line[100];

  ThisSlow  = MinSlow;                                    // initialize while control variable

  while ( ThisSlow <= MaxSlow )                           // changed for to while
  {
    ThisFast = MinFast;                                   // initialize while control variable
 
    while ( ThisFast <= MaxFast )                         // changed for to while 
    {
      vars       Price = series(priceClose() ),
                 Fast  = series(SMA(Price, ThisFast) ),   // replace SMA parameter with current loop control variable value
                 Slow  = series(SMA(Price, ThisSlow) );   // replace SMA parameter with current loop control variable value

      static var BuyLimit, SellLimit, BuyStop, SellStop;

      // insert trade logic here

      if ( is(EXITRUN) )
      {
        sprintf(line,
                "\n%6d, %6d, %6.2f, %6.2f",
                ThisSlow, ThisFast, WinTotal, LossTotal); // reformatted the output string and changed output variables to curreent loop control variable values
        file_append("NetProfit.csv", line);
      }

      ThisFast = ThisFast + MinFast;                      // increment while control variable
    } // while ( ThisFast <= MaxFast )

    ThisSlow = ThisSlow  + MinSlow;                       // increment while control variable
  } // while ( ThisSlow <= MaxSlow )

} /* run */



My changes are indicated in comments.
The output is:

Code:
20,      1,   0.00,   0.00
    20,      2,   0.00,   0.00
    20,      3,   0.00,   0.00
    20,      4,   0.00,   0.00
    20,      5,   0.00,   0.00
    20,      6,   0.00,   0.00
    20,      7,   0.00,   0.00
    20,      8,   0.00,   0.00
    20,      9,   0.00,   0.00
    20,     10,   0.00,   0.00
    40,      1,   0.00,   0.00
    40,      2,   0.00,   0.00
    40,      3,   0.00,   0.00
    40,      4,   0.00,   0.00
    40,      5,   0.00,   0.00
    40,      6,   0.00,   0.00
    40,      7,   0.00,   0.00
    40,      8,   0.00,   0.00
    40,      9,   0.00,   0.00
    40,     10,   0.00,   0.00
    60,      1,   0.00,   0.00
    60,      2,   0.00,   0.00
    60,      3,   0.00,   0.00
    60,      4,   0.00,   0.00
    60,      5,   0.00,   0.00
    60,      6,   0.00,   0.00
    60,      7,   0.00,   0.00
    60,      8,   0.00,   0.00
    60,      9,   0.00,   0.00
    60,     10,   0.00,   0.00



which looks more like what you're expecting.

hth.

(Pork types faster than I do! laugh )

Last edited by Jeff_Raven; 01/08/14 15:40. Reason: ETA
Re: RINA 3D optimization charts [Re: jcl] #435510
01/08/14 16:22
01/08/14 16:22
Joined: Dec 2013
Posts: 11
J
Jeff_Raven Offline
Newbie
Jeff_Raven  Offline
Newbie
J

Joined: Dec 2013
Posts: 11
Originally Posted By: jcl
The for() loop won't work here because it would be exeuted for any strategy run.


jcl, what did you mean my this? I don't understand.
Although, when I tried a for loop in my code, above, it didn't compile, but it does with the while loop.

Re: RINA 3D optimization charts [Re: Jeff_Raven] #435511
01/08/14 16:27
01/08/14 16:27

L
liftoff
Unregistered
liftoff
Unregistered
L



I tried running this code and I ended up with the too many trades error. I believe the loop was happening every bar, but we are trying to achieve a loop after every complete cycle. So after every bar, the run function will run a number of times per the loop we created. Its either that or something along those lines. Here is the code I run with.
Code:
function run()
{
	
	StartDate = 2003;
	EndDate = 2008;
	BarPeriod = 30;
	LookBack = 60; // Lookback period changed from default 30 to 60 to cater for largest slow period
	asset("GBP/USD");
		
	 int  MinSlow = 20;       // Minimum Slow Period
  	 int  MinFast = 1;        // Minumum Fast Period
  	 int  MaxSlow = 60;		  // Maximum Slow Period
  	 int  MaxFast = 10;		  // Maximum Fast Period
  	 int  ThisFast, ThisSlow; // while loop control variables
  	 int  SlowInc = 1;		  // Slow Period Incremental Value
  	 int  FastInc = 1;		  // Fast Incremental Value

  // no trade costs...
  	Spread    = 0;
  	Slippage  = 0;
  	RollLong  = RollShort = 0;
  	char line[100];	
	
	ThisSlow  = MinSlow;                                    // initialize while control variable

 	 while ( ThisSlow <= MaxSlow )                           // changed for to while
  	{
    ThisFast = MinFast;                                   // initialize while control variable
 
    while ( ThisFast <= MaxFast )                         // changed for to while 
    {
      vars       Price = series(priceClose() ),
                 Fast  = series(SMA(Price, ThisFast) ),   // replace SMA parameter with current loop control variable value
                 Slow  = series(SMA(Price, ThisSlow) );   // replace SMA parameter with current loop control variable value

      static var BuyLimit, SellLimit, BuyStop, SellStop;
      
					
				if(crossOver(Fast,Slow)) {
					BuyStop = priceHigh() + 1*PIP;
					BuyLimit = priceHigh() + 5*PIP;
				}
				if(crossUnder(Fast,Slow)) {
					SellStop = priceLow() - 1*PIP;
					SellLimit = priceLow() - 5*PIP;
				}
					
				if(!NumOpenLong && Fast[0] > Slow[0] && Price[0] < BuyLimit)
					enterLong(1,BuyStop);
				if(!NumOpenShort && Fast[0] < Slow[0] && Price[0] > SellLimit)
					enterShort(1,SellStop);
			
			if ( is(EXITRUN) )
      {
        sprintf(line,
                "\n%6d, %6d, %6.2f, %6.2f",
                ThisSlow, ThisFast, WinTotal, LossTotal); // line sent to csv file
        file_append("NetProfit.csv", line);
      }	
      ThisFast = ThisFast + FastInc;                      // increment while control variable
   } // while ( ThisFast <= MaxFast )

    ThisSlow = ThisSlow  + SlowInc;                       // increment while control variable
  } // while ( ThisSlow <= MaxSlow )		
}


I think that is what jcl meant

Re: RINA 3D optimization charts [Re: ] #435521
01/08/14 17:34
01/08/14 17:34

L
liftoff
Unregistered
liftoff
Unregistered
L



Using jcl's hint I made changes and tried this... It came out ok and produced the csv file needed to do the 3D hunky punky in excel.
Code:
function run()
{
	StartDate = 2003;
	EndDate = 2008;
	BarPeriod = 30;
	LookBack = 60; // Lookback period changed from default 30 to 60 to cater for largest slow period
	asset("GBP/USD");
		
	   int StepsFast = 10, StepsSlow = 40; // The number of steps the moving MA will make
		NumTotalCycles = StepsSlow * StepsFast; // Number of times to run the system

  // no trade costs...
  	Spread    = 0;
  	Slippage  = 0;
  	RollLong  = RollShort = 0;
  	
  	int Fast, Slow;	
	Fast = 1 + (TotalCycle % StepsFast); // Should return 1 to 10 each 40 times
   Slow = 20 + (TotalCycle / StepsFast);	// Should increase 20 by 0.1 10 times per 1-10 cycle of Fast increase
	
   
      vars       Price = series(priceClose() ),
                 FastMA  = series(SMA(Price, Fast) ),   // replace SMA parameter with current loop control variable value
                 SlowMA  = series(SMA(Price, Slow) );   // replace SMA parameter with current loop control variable value

      static var BuyLimit, SellLimit, BuyStop, SellStop;
      
					
				if(crossOver(FastMA,SlowMA)) {
					BuyStop = priceHigh() + 1*PIP;
					BuyLimit = priceHigh() + 5*PIP;
				}
				if(crossUnder(FastMA,SlowMA)) {
					SellStop = priceLow() - 1*PIP;
					SellLimit = priceLow() - 5*PIP;
				}
					
				if(!NumOpenLong && FastMA[0] > SlowMA[0] && Price[0] < BuyLimit)
					enterLong(1,BuyStop);
				if(!NumOpenShort && FastMA[0] < SlowMA[0] && Price[0] > SellLimit)
					enterShort(1,SellStop);
			
			if (is(EXITRUN)){
				char line[100];
       		 sprintf(line,
                "\n%6d, %6d, %6.2f, %6.2f",
                Slow, Fast, WinTotal, LossTotal); // line sent to csv file
        			file_append("Data\\NetProfit.csv", line);
      		}	
}


And the csv content.
Code:
20	2	6584.75	5973.65
20	3	6238.38	5823.69
20	4	6078.61	5523.38
20	5	5893.27	5462.33
20	6	5801.79	5237.07
20	7	5733.03	5113.88
20	8	5686.43	5116.28
20	9	5747.87	5051.76
20	10	5608.7	5084.1
21	1	7129.45	6575.14
21	2	6498.38	5974.29


Progress. I like how the community came together to help me out on this one. Thanks a lot guys.

Page 2 of 2 1 2

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1