direct statistical trading a "clearly" defined approach by NTW31

Discussion in 'Strategy Building' started by nukethewhales31, Dec 31, 2008.

  1. I developed a program to trade and backtest a very similar method, but it trades stocks / etfs. It can backtest up to 8 years of 1 minute data and I was very surprised by the results.

    That being said, in The Logical Trader, Mark Fisher said that the SPYders were very hard to trade and this method doesn't work very well on any 'market based' etf. This is because they tend to back-and-fill as Fisher calls it and this is due to so many different influences on these etfs.

    The 'sector based' etfs are much better.

    I can send you a pdf with any symbol backtested for 8 years using 1 minute bars, just pm me. Tell me your rules and I will send you the pdf, with the stats, rules, graph of pnl, and the pnl reported on a monthly basis. I am currently working on statistically grading the systems, but that's just not completed just yet.
     
    #521     Jan 31, 2011
  2. Use on TickData to calculate Hourly bars. The script will do all the calculations incl removing the outlyers on both sides and will plot the LSD and SLD as lines.

    Have fun

    inputs: n(20),
    accuracy(70),
    reward(.63);

    variables: ii(0),
    ii2(0),
    minofmax(999999),
    succestrades(0),
    failuretrades(0),
    mdrr(0),
    remove_sd(0),
    remove_ld(0),
    trigger(0),
    counter(0),
    result(0),
    sesscounter(0),
    sessopen(0),
    sesshigh(0),
    sesslow(0),
    ihigh(0),
    ilow(0),
    lsd(0),
    sld(0);

    array: raw[50,50](0),
    sd[](0),
    ld[](999999),
    dummysd[](0),
    dummyld[](999999);

    if currentbar = 1 then begin
    condition1 = array_setmaxindex(sd,n);
    condition2 = array_setmaxindex(ld,n);
    condition3 = array_setmaxindex(dummysd,n);
    condition4 = array_setmaxindex(dummyld,n);
    end;

    if floor(time*.01) <> floor(time[1]*.01) then begin

    sesscounter = sesscounter + 1;

    raw[1,50] = maxlist( maxlist( ihigh-sessopen, sessopen-ilow ), ( minmove / pricescale ) );
    value1 = sort2darray(raw,1,50,1);

    sessopen = c;
    sesshigh = c;
    sesslow = c;
    ihigh = c;
    ilow = c;

    if sesscounter > n+1 then begin

    minofmax = 999999;
    for ii = 1 to n begin
    if raw[ii,1] < minofmax then minofmax = raw[ii,1];
    end;

    for ii = 1 to n begin
    counter = 0;
    repeat
    counter = counter + 1;
    ld[ii] = raw[ii,counter];
    sd[ii] = raw[ii,counter+1];
    until
    sd[ii] < minofmax;
    end;

    for ii = 1 to n begin
    dummysd[ii] = sd[ii];
    dummyld[ii] = ld[ii];
    end;

    succestrades = iff( accuracy < 100, round( (n*accuracy)*.01, 0 ), n );
    failuretrades = (n-succestrades);

    value1 = sortarray(sd,n,1);
    value2 = sortarray(ld,n,-1);

    result = -999999;
    if failuretrades >= 1 then begin

    for ii = 0 to failuretrades begin
    remove_sd = ii + 1;
    remove_ld = failuretrades - remove_sd + 2;
    if ld[remove_ld] - sd[remove_sd] > result then begin
    result = ld[remove_ld] - sd[remove_sd];
    lsd = sd[remove_sd];
    sld = ld[remove_ld];
    end;
    end;

    for ii = 1 to n begin
    if dummysd[ii] > lsd or dummyld[ii] < sld then begin
    dummysd[ii] = 0;
    dummyld[ii] = 999999;
    end;
    end;

    end;

    lsd = highestarray(dummysd,n) + ( minmove / pricescale );
    sld = lowestarray(dummyld,n);

    mdrr = iff(sld-lsd > 0 and lsd <> 0, (sld-lsd)/lsd, 0);

    end;

    if sesscounter > 1 then
    for ii = 50 downto 2 begin
    for ii2 = 1 to 50 begin
    raw[ii,ii2] = raw[ii-1,ii2];
    end;
    end;

    for ii = 1 to 50 begin
    raw[1,ii] = 0;
    end;

    end;

    if c > sesshigh then sesshigh = c;
    if c < sesslow then sesslow = c;
    if c > ihigh then ihigh = c;
    if c < ilow then ilow = c;

    if c >= sessopen and c[1] < sessopen then begin
    if sessopen-sesslow > raw[1,50] then begin
    for ii = 1 to 50 begin
    if raw[1,ii] = sessopen-sesslow then trigger = 1;
    end;
    if trigger = 0 then begin
    raw[1,50] = sessopen-sesslow;
    value1 = sort2darray(raw,1,50,1);
    end;
    end;
    sesslow = sessopen;
    trigger = 0;
    end;

    if c <= sessopen and c[1] > sessopen then begin
    if sesshigh-sessopen > raw[1,50] then begin
    for ii = 1 to 50 begin
    if raw[1,ii] = sesshigh-sessopen then trigger = 1;
    end;
    if trigger = 0 then begin
    raw[1,50] = sesshigh-sessopen;
    value1 = sort2darray(raw,1,50,1);
    end;
    end;
    sesshigh = sessopen;
    trigger = 0;
    end;

    if sesscounter > n+1 then begin
    plot1(lsd,"lsd");
    plot2(sld,"sld");
    end;
     
    #522     Feb 10, 2011
  3. Hey flyingdutchmen, what language is that?
     
    #523     Feb 10, 2011
  4. Good1

    Good1

    //+------------------------------------------------------------------+
    //|
    //|
    //|
    //+------------------------------------------------------------------+

    extern int Eliminations=4;
    datetime barTime; // global variable

    //+------------------------------------------------------------------+
    //| expert initialization function |
    //+------------------------------------------------------------------+
    int init()
    //----
    {
    //----
    int handle;
    int i,j,k;

    double HOArray[22];
    double OLArray[22];
    datetime orderOpen=OrderOpenTime();
    string p,q,l,s,t;
    double Long[22];
    double Short[22];
    double MinValLongArray;
    int minValueidx;
    int maxValueidx;
    double EnterLong;
    double EnterShort;
    double TPLong;
    double TPShort;

    handle=FileOpen("dump.txt", FILE_CSV|FILE_WRITE);


    if(handle<1) //a little error handling on the handle
    {
    Print("File my_data.dat not found, the last error is ", GetLastError());
    return(false);
    }


    for(i=1;i<=21;i++)
    {

    HOArray=High-Open;
    OLArray=Open-Low;

    if(HOArray>OLArray)
    {
    Long=HOArray;
    Short=OLArray;
    }
    if(HOArray<OLArray)
    {
    Long=OLArray;
    Short=HOArray;
    }


    p = DoubleToStr(HOArray,5);
    q = DoubleToStr(OLArray,5);
    l = DoubleToStr(Long[i],5);
    s = DoubleToStr(Short[i],5);
    //t = CharToStr(i,2)
    FileWrite(handle, p, q, l, s,i);
    }
    minValueidx = ArrayMinimum(Long,WHOLE_ARRAY,1);
    MinValLongArray = Long[minValueidx];
    FileWrite(handle, MinValLongArray);

    int y;
    for(y=1;y<=21;y++)
    {
    if(Short[y]>MinValLongArray)
    {
    Long[y]=Short[y];
    Short[y]=0;
    }
    l = DoubleToStr(Long[y],5);
    s = DoubleToStr(Short[y],5);
    FileWrite(handle,l,s,y);
    }
    int x;

    for(x=1;x<=Eliminations;x++)
    {
    minValueidx = ArrayMinimum(Long,WHOLE_ARRAY,1);
    maxValueidx = ArrayMaximum(Short,WHOLE_ARRAY,1);
    FileWrite(handle,Long[minValueidx],Short[maxValueidx]);
    if(x==Eliminations)
    break;
    Long[minValueidx] = 1000;
    Short[maxValueidx] = 0;

    }
    //FileWrite(handle,Long[minValueidx],Short[maxValueidx]);
    EnterLong=Open[0]+Short[maxValueidx];
    TPLong=Open[0]+Long[minValueidx];
    EnterShort=Open[0]-Short[maxValueidx];
    TPShort=Open[0]-Long[minValueidx];

    FileWrite(handle,"Open ","EntLong","TPLong","EntShort","TPShort");
    FileWrite(handle,DoubleToStr(Open[0],5),EnterLong,TPLong,EnterShort,TPShort);
    FileWrite(handle,Minute());

    FileClose(handle);
    //Print("Done with handle#: ", handle);

    //----
    return(0);
    }
    //+------------------------------------------------------------------+
    //| expert deinitialization function |
    //+------------------------------------------------------------------+
    int deinit()
    {
    //----

    //----
    return(0);
    }
    //+------------------------------------------------------------------+
    //| expert start function |
    //+------------------------------------------------------------------+
    int start()

    {
    int handle;
    //----
    //if(Minute()==1)
    if( barTime < Time[0] ){
    barTime = Time[0];
    handle=FileOpen("minLog.txt", FILE_CSV|FILE_WRITE);

    if(handle<1) //a little error handling on the handle
    {
    Print("File my_data.dat not found, the last error is ", GetLastError());
    return(false);
    }

    OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Bid-150*Point,Bid+150*Point);
    FileClose(handle);
    }
    //----
    return(0);
    }
    //+------------------------------------------------------------------+[/i][/i]
     
    #524     Feb 10, 2011
  5. Good1

    Good1

    Thanks, i've included (above) the MT4 code i used to test. This is the code that produced the chart i posted previously. I'll see if i can port your version to MT4.
     
    #525     Feb 10, 2011
  6. Humpy

    Humpy

    Couldn't do it in Metastock I suppose ?????
     
    #526     Feb 11, 2011
  7. @SteveGee
    EL, for tradestation, multicharts or any other EL compatible software

    @Good1
    it seems to me that your script calculates bar values ? that would be less then perfect. you will need to go down to the tick and save each value when price crosses above the first openingtick of the hour or below it. this sometimes could happen up to 20-30 times within a hour. Each distance will need to be stored, then the 2 highest values of that bar can be used as LD and SD but you realy need to store all these individual values in an array to be able to calculate the LSD and SLD at a later point because some of these values can turn out to be longer then high-open or open-low. just using high-open and open-low will give you unrealistic values
     
    #527     Feb 11, 2011
  8. Just checking to see if the OP is around?
     
    #528     Feb 25, 2011
  9. Figured I'd use my first post on this board to chime in here and thank NUKE for starting this great thread exactly two years and two months ago. Great stuff and very civil discourse with only a few rude interruptions from the immature yahoos of the world. Just spent the last few days reading the whole thread (time permitting).


    Important Questions First!

    Nuke, could you enlighten a us a bit about your moniker? I did see the Nuking Whale vid you posted toward the beginning of the thread but no color on what prompted you to create this character. Did you have a half-sister with Greenpeace or some other impactful event in your youthood?


    By reading the entire thread most all my initial questions were answered, but scJohn posted a good queston on page 80 asking about throwing away outliers. How did you treat multiple same value outliers?

    Also, did you ever setup that Website you'd mentioned toward the end?

    And a bit OT-
    babe714 linked us to the thread Emintrader started two years ago. Has he ever been heard from again?
     
    #529     Mar 2, 2011
  10. I have done some preliminary testing using the bar formation set at 80%. This was done on a 4 hour chart. All the testing was done by hand. The script pointed out the trades, and only ONE trade taken per bar. This was also using the 20 EMA for bias.

    As you can see it's a rather rocky equity curve. Each trade taken was with a normalized risk of $50.00. The R:R was usually pretty low as well. There where anywhere from 3-6 trades per day. See the picture below.

    This is working on my charts to point out the trades. I want to try to work on this using the tic data as ntw mentioned, and Good1 was speaking of in his diagram.

    I'll post more on my thoughts on that in a bit, as I think there are quite a few holes in my logic on that front.
     
    #530     Mar 6, 2011