[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

spreading and optimization



PureBytes Links

Trading Reference Links

dear fellow list members,

I enjoy spread trading, unfortunately Tradestation doesn't support spread reporting. If I trade a spread I would have to manually compile the total profit/loss. Not only that, but the problem arises when you want to optimize something: You would have to do it manually, an almost impossible task.

I made a function that compiled the profit/loss, which could be charted. 
The function is as follows (I think it calculates it correctly)

{function name: spreadprofit
calculates the profit of a spread strategy
a simple expression used here as an example
by frode l aschim 2001}

inputs: length(numeric),std(numeric);
vars: div1(0),div2(0),posi(0),totpro(0);
div1=(close)/(close of data2);
div2=summation(div1,LENGTH);
if div2 crosses below 1+std then posi=-1;
if div2 crosses above 1-std then posi=1;
if posi[1]=-1 and posi[2] <>-1 then totpro=totpro+(open-close);
if posi[1]=-1 and posi[2] =-1 then totpro=totpro+(close[1]-close);
if posi[1]=-1 and posi[2] <>-1 then totpro=totpro+(close of data2-open of data2);
if posi[1]=-1 and posi[2] =-1 then totpro=totpro+(close of data2-close[1] of data2);
if posi[1]=1 and posi[2] <>1 then totpro=totpro+(close-open);
if posi[1]=1 and posi[2] =1 then totpro=totpro+(close-close[1]);
if posi[1]=1 and posi[2] <>1 then totpro=totpro+(open of data2-close of data2);
if posi[1]=1 and posi[2] =1 then totpro=totpro+(close[1] of data2-close of data2);
spreadprofit=totpro;
{end of code}

I think gives me the correct spreadprofit(has to be changed slightly depending on MOC or MOO orders)
the problem is as follows:
if I want to optimize the inputs, I thought of making the following indicator:
{made to write all the profit/loss of the differnt into a file for review
by frode l aschim}
inputs: length(5), std (5);
vars: tell(0),tell2(0), prof(0);
prof=0;
IF LASTBARONCHART=TRUE THEN BEGIN
 FOR TELL=1 TO LENGTH BEGIN
 FOR TELL2=1 TO STD BEGIN
 
  prof=SPREADPROFIT(TELL,TELL2);
fileappend("c:\append2.txt", numtostr(prof,5)); fileappend("C:\append2.txt"," ");fileappend("c:\append2.txt",numtostr(tell,0)+numtostr(tell2,0));fileappend("C:\append2.txt"," ");
 END;
 END;
end;
{end of code}

However, this doesnt seem to work. If I put values instead of the tell&tell2 for-loops, it writes the correct profit. However when I loop it - the correct profit is not shown, it seems like the looping makes some of the function values change or something. It does not print the different profit/loss of the spreadprofit.

Any ideas? What am I doing wrong?

BRGDS

Frode