Index futures automation

Discussion in 'Journals' started by hilmy83, Jul 3, 2022.

Can a fully automated trading strategy work in the long run?

  1. YES!

    56 vote(s)
    66.7%
  2. Hell naw.

    15 vote(s)
    17.9%
  3. I don't know, I got my own trading to worry about.

    13 vote(s)
    15.5%
  1. hilmy83

    hilmy83

    Well just as I thought, I started following the algo right at the peak. This could be a long drawdown or a short one. Considering it's just about 30% dd so far, could be another 20-30% downside.

    But I'm just going to stick to it and ride the the downfall or ride up. The backtests gotta be worth something

    upload_2023-1-27_10-37-38.png


    Red circle is where I traded the algo live. Just my luck

    upload_2023-1-27_10-38-51.png
     
    #201     Jan 27, 2023
    beginner66 and NoahA like this.
  2. hilmy83

    hilmy83

    Still working through the drawdown earlier. Topped off the accoutn to 10k jsut so i can have enough margin to handle the reverses.

    So I have a b/e sequence function thats programmed into this algo. But one thing I found out about programming a stop and reverse with b/e function into futures is that, you have to deal with partial fills situation that can throw off your b/e target calculation.

    Breakeven targets need to read the closed losses history and so if you have partial fills, your algo will mistakenly target incorrect b/e level if it sets the target as soon as order is triggered.

    Example:

    upload_2023-2-4_14-8-46.png

    If each of those fill represent loss, then it's required that the algo waits a few ms to set the target until all reverse lots are accounted for, to make sure the losses history are read correctly, and b/e target is determined accurately.

    I had close call on 2/2 where my b/e function as it's programmed but did not wait until the complete lots are filled and set the b/e target short. Luckily i was at my desk watching it to manually trade it.

    Things you learn that you never thought of when running the algo is crazy...
     
    #202     Feb 4, 2023
  3. hilmy83

    hilmy83

    I don't think I can mentally take a DD this big from this strategy. I thought 50% is the worst I could experience, but backtesting it during fall/winter months show bigger dd. I still make more money this method, but It's just way too risky

    upload_2023-2-6_10-44-30.png
     
    #203     Feb 6, 2023
  4. hilmy83

    hilmy83

    If I go back to my scalping method, it's an all out approach. Meaning all in for minimal profit or b/e or the day.

    Just based on backtests, I would have about 97-98% profitable days.

    Even though I haven't seen catastrophic losses in the backtests (yes zero loss), I used the close calls as the potential loss %. I probably get about 4-5 of those in a given year, which translates to 2% (5/250 days).

    I know that my loss is 80% of the account (AMP's margin call level).

    Since any given day, my loss is basically a one hit shot, I can calculate my risk of ruin in a given day:



    upload_2023-2-6_11-21-36.png

    " u" in this case is 1 since it's all out loss for the day if it doesnt' go into profit or b/e

    ((1-.96)/(1+.96))^1

    = about 2-3% risk of ruin to lose 80% of my account
     
    #204     Feb 6, 2023
  5. hilmy83

    hilmy83

    upload_2023-2-6_11-34-46.png
    upload_2023-2-6_11-35-36.png
    upload_2023-2-6_11-36-30.png

    On a 10k account it would retur about 60% based on 1 contract without compounding.

    Maybe this is the approach I should take.

    There's no way to eliminate risk of ruin completely. Even with a pre determined stop, you can reach pretty steep drawdown on a string of losing consecutive hits.
     
    #205     Feb 6, 2023
  6. hilmy83

    hilmy83

    Simple fix was adding the sleep function (1 sec) before it calculates and sets the target, so that it waits for all the lots to be executed properly. This worked in backtest, just have to make sure it works in live. Will continue to monitor live and ready to jump in if it doesn't work!

    Code:
     if(           PP[0]== +1&&TSLM[0]==0) // Target is absent
           {if(TBLM[0]>=1)REMO(BLM[0][0]);
            Sleep(1000);SPOS();if(PP[0]== +1)
            {if(BF==0&&TREN==YES)
             {TCKV[0]=SymbolInfoDouble(TCKR[0],SYMBOL_TRADE_TICK_VALUE);
            //TRPP=         (CMMS-CHPR(ID[0]))/(TCKV[0]*LT[0]) ;
              TRPP=MathCeil((CMMS-CHPR(ID[0]))/(TCKV[0]*LT[0]));
                   //TRG=NRDT(OP[0]  + TCKS[0]*(TRPP+0.5)+RNG*TRML,DIGT[0]);
                     TRG=NRDT(OP[0]  + TCKS[0]* TRPP     +RNG*TRML,DIGT[0]);
              ocom="Trg"+FIN0(PT-1,2)+"_"+DoubleToString(LT[0],2);
             }
           //else     TRG=NRDT(OP[0]+POIN[0]*(BEPP+0.5),DIGT[0]);
             else
             if(BF==1)            // !!! obliged
             {TCKV[0]=SymbolInfoDouble(TCKR[0],SYMBOL_TRADE_TICK_VALUE);
            //BEPP=         (CMMS-CHPR(ID[0]))/(TCKV[0]*LT[0]) ;
              BEPP=MathCeil((CMMS-CHPR(ID[0]))/(TCKV[0]*LT[0]));
                   //TRG=NRDT(OP[0]  + TCKS[0]*(BEPP+0.5)         ,DIGT[0]);
                     TRG=NRDT(OP[0]  + TCKS[0]* BEPP              ,DIGT[0]);
              ocom="BE_"+FIN0(PT-1,2)+"_"+DoubleToString(LT[0],2);
             }
             if(BF==1||TREN==YES) // !!! obliged
             {s=SSLM(MAGIC,LT[0],TRG,0,0,ocom);
             }
            }
           }else
         //if(           PP[0]== -1&&TBLM[0]==0) // Target is absent
         //if(TREN==YES&&PP[0]== -1&&TBLM[0]==0) // Target is absent
           if(           PP[0]== -1&&TBLM[0]==0) // Target is absent
           {if(TSLM[0]>=1)REMO(SLM[0][0]);
            Sleep(1000);SPOS();if(PP[0]== -1)
            {if(BF==0&&TREN==YES)
             {TCKV[0]=SymbolInfoDouble(TCKR[0],SYMBOL_TRADE_TICK_VALUE);
            //TRPP=         (CMMS-CHPR(ID[0]))/(TCKV[0]*LT[0]) ;
              TRPP=MathCeil((CMMS-CHPR(ID[0]))/(TCKV[0]*LT[0]));
                   //TRG=NRDT(OP[0]  - TCKS[0]*(TRPP+0.5)-RNG*TRML,DIGT[0]);
                     TRG=NRDT(OP[0]  - TCKS[0]* TRPP     -RNG*TRML,DIGT[0]);
              ocom="Trg"+FIN0(PT-1,2)+"_"+DoubleToString(LT[0],2);
             }
           //else     TRG=NRDT(OP[0]-POIN[0]*(BEPP+0.5),DIGT[0]);
             else
             if(BF==1)            // !!! obliged
             {TCKV[0]=SymbolInfoDouble(TCKR[0],SYMBOL_TRADE_TICK_VALUE);
            //BEPP=         (CMMS-CHPR(ID[0]))/(TCKV[0]*LT[0]) ;
              BEPP=MathCeil((CMMS-CHPR(ID[0]))/(TCKV[0]*LT[0]));
                   //TRG=NRDT(OP[0]  - TCKS[0]*(BEPP+0.5)         ,DIGT[0]);
                     TRG=NRDT(OP[0]  - TCKS[0]* BEPP              ,DIGT[0]);
              ocom="BE_"+FIN0(PT-1,2)+"_"+DoubleToString(LT[0],2);
             }
             if(BF==1||TREN==YES) // !!! obliged
             {b=SBLM(MAGIC,LT[0],TRG,0,0,ocom);
             }
            }
     
    Last edited: Feb 9, 2023
    #206     Feb 9, 2023
    MarkBrown likes this.
  7. rb7

    rb7

    Not sure if you are using Mkt or Lmt orders.
    In both cases, you cannot be sure that all fills will be received within 1 sec, or within a fix number of second.
    You need to keep track of the total volume filled until it gets to your total order volume.
     
    #207     Feb 9, 2023
  8. hilmy83

    hilmy83

    Well on the reverse it would be market stop orders. But what you're saying is correct, I can only assume the orders are filled within 1 sec. Which means calculating to make sure the full pre determined lot to fully execute would be better approach.
     
    #208     Feb 9, 2023
  9. hilmy83

    hilmy83

    Created variables reverse lots. Basically algo will now compare net position (after reverse AR) status with calculated reverse lot (CRLT) before setting target.

    Code:
     double   CMMS,CMMR,TRLT,CRLT,ARLT;
    void     CLRV()                                             // CLEAR FIELDS FOR NEXT PROC
    {        PT  =0;                 GlobalVariableSet(VPROC,PT  );
           //SINC=0;                 GlobalVariableSet(VSINC,SINC);
             BF  =0;                 GlobalVariableSet(VBEFL,BF  );
             DR  =0;                 GlobalVariableSet(VDRDW,DR  );
             TRLT=0.0;               GlobalVariableSet(VLOTS,TRLT);
             ARLT=0.0;               GlobalVariableSet(VLTAR,ARLT);
             CMMS=0.0;               GlobalVariableSet(VCMMS,CMMS);
             TIMS+=86400;            GlobalVariableSet(VTIMS,TIMS);
             TIMF+=86400;            GlobalVariableSet(VTIMF,TIMF);
    
    
    I think this is it. The final version *fingers crossed!
    Just need one of those ranging reverse days and partial fills in live to see it work properly.
     
    #209     Feb 15, 2023
  10. hilmy83

    hilmy83

    I want to create a side by side % performance between my algo (gross and net after comm) against the benchmarks SPX/NDX

    This journal is pretty much done as far as algo development is concerned. Now I'll let run till it dies..

    upload_2023-2-21_15-35-12.png

    After about 20 or so data points we'll plot the graphs.

    upload_2023-2-21_15-29-41.png

    Let's see if my passive algo can outdo the index in the long run. If it can, I consider this endeavor a success and ready to move the hell on to other things.
     
    #210     Feb 21, 2023
    Nobert likes this.