Announcement

Collapse
No announcement yet.

HELP: How to code scaling out?

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

  • HELP: How to code scaling out?

    Hi all,

    Would any kind soul help me out?

    I'm trying to code the following for ES:

    1. For discussion sake, we will use 10MA & 20MA crossovers.
    2. When 10MA < 20MA, SHORT. When 10MA > 20MA, LONG.
    3. Profit Target = 3pt, Stop Loss = 2pt.

    4. If StopLoss breached, then close ALL.
    5. When Profit Target reached, scale out HALF the size. Let the other half ride until MA cross again or stopped out.

    I'm able to code up to the StopLoss and Profit Taking part, but really loss on how to code the scale-out part.

    Can anyone please help me?

  • #2
    Scaling out....

    Scaling out is not a problem. You would simply enter your trade with X number of contacts/shares (say 5 or 10).

    You enter your trade by forcing a number of contracts to trade.

    Then you would simply issue multiple EXIT trades for this single entry trade.

    The easiest way I have attempted to do this is to setup the following variables...

    var DefaultEntryContracts = 10;
    var Exit1Contracts = 3;
    var Exit2Contracts = 4;
    var Exit3Contracts = 3;

    This way, you can setup the execution of the trades accordingly..

    Additionally, you will probably need to setup an "ExitStage" variable that will report the stage of your scaled exits..

    var ExitStage = 0;

    When you enter your trade, you would reset this variable to 0 (zero).

    Then, as you place your exit strategies (1,2,3) you would increment this variable...

    ExitStage += 1;

    This way, you can test for your exit conditions and the current "Stage" of your exit variable....

    if ( (exitcondition1) && (ExitStage == 0) ) {
    do.Sell(...);
    ExitStage += 1;
    }

    if ( (exitcondition2) && (ExitStage == 1) ) {
    do.Sell(...);
    ExitStage += 1;
    }

    if ( (exitcondition3) && (ExitStage == 2) ) {
    do.Sell(...);
    ExitStage += 1;
    // at this point - the trade in completed.
    }

    Hope this helps..

    B
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Thanks Doji3333!

      But when I do a backtest, what do I put in the "Default Lot Size" box?

      Comment


      • #4
        You don't....

        When coding a scaled Exit system, you don't use the DEFAULT LOT SIZE for the back-tester....

        You have to force the LOT SIZE with the doBuy, doSell, doCover and doShort.

        Here is an example of the parameters for the entry/exit functions...

        All the parameters are identical for each entry/exit function..

        Strategy.doLong (Description, Fill Type, Fill Bar, LotSize, StopOrLimit)


        Example...

        Strategy.doLong ("Entry Order", Strategy.MARKET, Strategy.NEXTBAR, 50);

        - this code enters a long trade with 50 contracts/shares.

        Strategy.doSell ("First Exit Order", Strategy.MARKET, Strategy.NEXTBAR, 10);

        Strategy.doSell ("Second Exit Order", Strategy.MARKET, Strategy.NEXTBAR, 10);

        -- these exit calls are exiting with 10 contracts each...

        Hope this helps..

        Brad
        Brad Matheny
        eSignal Solution Provider since 2000

        Comment

        Working...
        X