Announcement

Collapse
No announcement yet.

Reinvesting profits

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Reinvesting profits

    Hi all,

    I have a strategy that I am backtesting to work on futures markets, but have come across a stumbling block:

    I would like the strategy to re-invest the profits in itself... so, when it comes to the next trade, the strategy goes long/short the Account balance divided by the margin per contract (rounded down to the nearest whole number).

    For example, I start off with $10,000 and trade one lot... when the balance gets to $20,000 I want to trade 2 lots etc...

    An added complication is that I am totally useless at programming - I'm pretty much restricted to what I can to in the formula wizard.

    Any tips?

    Many thanks

    NBD

  • #2
    Sure, I've done this in the past and can assist you.

    All you really need to do is establish some working requirements and simple math to calculate how you want to "reinvest".

    First, you have to start with a capital pool. Second, you have to determine a minimum amount, or cut-off amount, if the capital pool drops below a certain amount. Next, you have to determine how you want to allocate the funds from the capital pool to your trading. You also need to understand the margin requirements for trading whatever you are testing.

    I would suggest starting with the basics, then expanding from there. For example.

    PHP Code:
    var CapitalPool 100000;
    var 
    MinTradingAmount 1;
    var 
    ShutOffMin 25000;
    var 
    ContractMargin 3000;
    var 
    MaxTradingAmountFromCP 0.33;  //33% 
    Now, to calculate how many you are allowed to trade, you would just a function like this...

    PHP Code:

    function fCalcTradingAmount() {
      var 
    MContracts 0;  //  Set the default to ZERO CONTRACTS
       //  Then we'll let the following code calc the proper amount to trade

      
    var AllowedTradingCapital CapitalPool MaxTradingAmountFromCP;

      if (
    AllowedTradingCapital ShutOffMin) {
        
    //  Now, determine how many we are allowed to trade based on margin.
         
    MContracts Math.floor(AllowedTradingCapital ContractMargin);
        if (
    MContracts 0) {  //  more than zero contracts
           // allowed to trade calculated amount
           
    return MContracts;
        } else {
           if ((
    AllowedTradingCapital ContractMargin) > ShutOffMin) {
             
    // allowed to trade minimum amount
              
    return MinTradingAmount;
           } else {
             
    // not allowed to trade, return ZERO
              
    return 0;
           }
        }
      } else {
         
    // not allowed to trade, return ZERO
         
    return 0;
      }

    Additionally, you'll need to track the ENTRY and EXIT price for all trades and continue to include DEBITS and CREDITS to your running total for the CapitalPool. In other words, you have to create a mini-accounting system in your code to handle all of this.

    You can even create a LOOKUP feature for different symbols using the FILE functions. But this might be too complicated for you right now. Start with the basics and expand from there.

    Hope this helps??
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Wow, thanks very much Brad!

      I will have to go away and digest your post, and figure out how I integrate this into the code from the formula wizard, but in the meantime, thanks again!

      Comment

      Working...
      X