0 registered members (),
1,438
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: RINA 3D optimization charts
[Re: jcl]
#435505
01/08/14 15:39
01/08/14 15:39
|
Joined: Dec 2013
Posts: 11
Jeff_Raven
Newbie
|
Newbie
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:
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:
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! )
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
Jeff_Raven
Newbie
|
Newbie
Joined: Dec 2013
Posts: 11
|
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
|
liftoff
Unregistered
|
liftoff
Unregistered
|
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.
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
|
liftoff
Unregistered
|
liftoff
Unregistered
|
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.
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.
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.
|
|
|
|