Announcement

Collapse
No announcement yet.

Multiple positions - scaling in

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

  • Multiple positions - scaling in

    Just started learning efs and created my first system complete with buy/sell/short/cover signals. A lot of help came from the Guide to Creating EFS Strategies.

    What I'd like to do at this point is learn how to scale in additional positions after an initial signal is generated. For instance, I receive a buy signal and execute a first leg. If it goes against me $.50, I add a second leg, and so on up to five legs or some variable. Once a sell condition hits, I'd unload all legs. Vice-versa on the shorts.

    In the EFS Guide, I read the section on local and global variables, as well as the sample code for profit targets and stops, but I'm not sure if they would apply in my case. I also scanned the boards, but didn't see any threads on this subject. Nothing in the EFS example library either. I assume this is something that can't be programmed with the formula wizard.

    Can someone point me to some threads or post an example efs file or two that does this? I'm pretty good at figuring things out as long as I have an example to look at. Otherwise I tend to make things more complicated than they need to be.

    Thanks in advance,
    Derek

  • #2
    scaling...

    Derek,

    There are control variables that you should use...

    Strategy.isLong()
    Strategy.isShort()
    Strategy.isInTrade()

    your main entry trades should use the Strategy.isInTrade() function to test (if it is a New Entry) - like....

    if ((!Strategy.isInTrade()) && (New Buy Trigger)) {
    .. new buy signal
    }
    if ((!Strategy.isInTrade()) && (New Sell Trigger)) {
    .. new sell signal
    }

    Now, your scaling trades are a bit different. Let's assume you are in a LONG trade and want to scale when the price is 0.50 against you... You need a control variable to allow this to happen only once.

    var ScaleLevel = -1;
    var nEntryPrice = 0; // records the trade entry price
    var Scale1Level = 0.50;

    // NEW trade signals
    if ((!Strategy.isInTrade()) && (New Buy Trigger)) {
    .. new buy signal
    ScaleLevel = 0;
    nEntryPrice = close();
    }
    if ((!Strategy.isInTrade()) && (New Sell Trigger)) {
    .. new sell signal
    ScaleLevel = 0;
    nEntryPrice = close();
    }


    // Scale Trade Signals - Level 1
    if ((Strategy.isLong()) && (close <= (nEntryPrice-Scale1Level)) && (ScaleLevel == 0)) {
    .. Add Scale buy signal
    ScaleLevel += 1;
    }
    if ((Strategy.isShort()) && (close >= (nEntryPrice+Scale1Level)) && (ScaleLevel == 0)) {
    .. new sell signal
    ScaleLevel += 1;
    }

    Notice the way I'm using the control variable (incrementing it with each stage of the scale trading system. This way, I can create as many scale levels as I want.

    Let me know if this helps... (BTW, Thanks for the compliment on the "guide").

    B
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Brad, I wanted to thank you for your help. Sorry I haven't responded sooner. As soon as I get a chance I'm going to experiment with what you've written.

      Also, your guide is great, especially for beginners like me.

      Comment


      • #4
        EFS Guide

        Can you please tell me wher to find the EFS programming guide, I have no programming knowledge at all and want to get started so any advice very much appreciated
        Thanks

        Comment


        • #5
          minx
          All EFS related documentation is available in the EFS Help Center & Library
          You may also want to download the EFS Help files (in HTML or Windows Help formats) courtesy of Chris Kryza which are available here
          Alex

          Comment


          • #6
            Stuck

            Brad, I gave it the college try but got stuck on the suggestions. Either I'm just not getting any additional signals at all or I'm getting signals every time a buy signal is generated (ignoring the $.50 criteria.)

            I'm sure it'd be best if I just posted the efs at this point, but I'm really trying to get it down on my own without you pros having to help me cheat.

            I think what's going on are conflicting variables. Since I used the Formula Wizard originally, I have four different expressions and four different actions for Short, Long, Cover, and Sell, respectively.

            Currently, the process is as follows:

            var vLastAlert = -1;
            var ScaleLevel = -1;
            var nEntryPrice = 0; // records the trade entry price
            var Scale1Level = 0.50;

            function main
            if Short Signal=onAction1
            else if Long Signal=onAction2
            else if Cover Short Signal=onAction3
            else if Sell Long Signal=onAction 4

            function postmain
            function onAction1() if vLastAlert != 1 execute short; vLastAlert = 1
            function onAction2() if vLastAlert != 2 execute long; vLastAlert = 2
            function onAction3() if vLastAlert != 3 execute cover; vLastAlert = 3
            function onAction4() if vLastAlert != 4 execute sell; vLastAlert = 4

            I tried adding your conditions so that an additional short signal would jump to onAction1 and an additional long would jump to onAction2, but I guess that won't work due to the vLastAlert variable. If I eliminate the variable, it'll execute on every signal, though.

            I tried adding your conditions so that an additional short and long signal would jump to onAction5 and onAction6 and execute additional legs. Couldn't get it to work regardless of whether I put them above or below the other four expressions.

            I guess I'm just trying to get straight the proper order conceptually. If I know the proper order of execution I'm sure I can figure out the rest.

            Hope I wasn't too confusing.

            Derek

            P.S. It seems like both vLastAlert and ScaleLevel are there to do the same thing, but I'm not making the connection on whether I should eliminate one or the other.

            Comment


            • #7
              Post your code

              If you want, post your code and I will help..

              The only other advice I can offer it "code order"...

              You might try putting your "additional trading code" above your main ENTRY code (in your EFS). This way, the "additional entry" code will not be triggered on the same bar as your main ENTRY code.

              Brad
              Brad Matheny
              eSignal Solution Provider since 2000

              Comment


              • #8
                Brad, woke up at 2:30am with an epiphany and figured out how to get it to work. Was dragging in the market today, but it was worth it. Thanks for being here to help out.

                Derek

                Comment

                Working...
                X