Announcement

Collapse
No announcement yet.

Sample Profit Target/Trailing Stop Code

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

  • #16
    Jason,

    I'm being such an idiot - and I bet readers of this post recognise what a silly request my last post was.

    What I'm really trying to say is, can you help write some code that will allow to trigger the formula (Sample_TargetStop.efs. )at a certain price at a particular time (preferably on an Intraday basis)?

    Cheers.

    Carlton

    Comment


    • #17
      Jason,

      Searching through the bullentins I found one of your formulas which provides price alert at certain level. This may be the answer to one of my requests below, however, the alert doesn't appear to work.

      Any thoughts?

      Cheers

      Carlton

      Comment


      • #18
        Its Official, I'm an idiot!

        First, I didn't include the formula for you to take a look at.

        Second, its not really what I'm looking for. As I mentioned, previously, I would appreciate any help you can give me to write some code that will activate the formula you provided below (Sample_TargetStop.efs.) Ideally, I would like the formula to be activated at a certain price or time, (or both if possible).

        While searching through the bullentins I found the formula your wrote a while back which set alerts at certain price levels and I was going to attempt to tweak it to help me achieve the above until you got in touch with me. However, that piece of code is doesn't appear to be working.

        /************************************************** ******************
        Copyright © eSignal, 2003
        Title: Alert at X
        Version: 1.0

        ================================================== ===================
        Fix History:


        ================================================== ===================
        Project Description:

        This formula will provide an alert at a given price level.

        ================================================== ===================
        Notes:
        Please note that the price level must be defined in the Edit Studies window
        before any alert is given. If multiple alerts are needed, please create
        another instance of the formula.

        Once the alert is hit, the formula must be reloaded to reset the alert.

        ************************************************** ********************/

        vInit = false;
        var PriceLevel = null;
        var vAlertTriggered = false;

        function preMain() {

        if (vInit == false) {
        setPriceStudy(true);
        setStudyTitle("Alert at X");
        setShowCursorLabel(false);

        var fp1 = new FunctionParameter("PriceLevel", FunctionParameter.NUMBER);

        var fp1a = new FunctionParameter("HiLo", FunctionParameter.STRING);
        fp1a.setName("Alert Type?");
        fp1a.addOption("At_Or_Above");
        fp1a.addOption("At_Or_Below");
        fp1a.setDefault("At_Or_Above"); //Edit this value to set a new default

        var fp2 = new FunctionParameter("Popup", FunctionParameter.BOOLEAN);
        fp2.setName("Pop-up Alert?");
        fp2.setDefault(true);

        var fp3 = new FunctionParameter("Sound", FunctionParameter.BOOLEAN);
        fp3.setName("Sound Alert?");
        fp3.setDefault(true);

        var fp4 = new FunctionParameter("Email", FunctionParameter.BOOLEAN);
        fp4.setName("Email Alert?");
        fp4.setDefault(false);

        vInit = true;
        } else if (vInit == true) setStudyTitle("Alert at " + PriceLevel);

        }

        function main(PriceLevel,HiLo,Popup,Sound,Email) {

        if (PriceLevel == null || vAlertTriggered) return;

        if (HiLo == "At_Or_Above") {
        if (close() >= PriceLevel) {
        if (Popup) Alert.addToList(getSymbol(), "ALERT: " + getSymbol() + " >= " + PriceLevel);
        if (Sound) Alert.playSound("ding.wav");
        if (Email) Alert.email(getSymbol(), "ALERT: " + getSymbol() + " >= " + PriceLevel);
        vAlertTriggered = true;
        }
        } else if (HiLo == "At_Or_Below") {
        if (close() <= PriceLevel) {
        if (Popup) Alert.addToList(getSymbol(), "ALERT: " + getSymbol() + " <= " + PriceLevel);
        if (Sound) Alert.playSound("ding.wav");
        if (Email) Alert.email(getSymbol(), "ALERT: " + getSymbol() + " <= " + PriceLevel);
        vAlertTriggered = true;
        }
        }

        return;
        }


        I don't think anybody other than you will help me as they won't be bothered to read all that I have said - which I perfectly understand.

        Cheers

        Carlton

        Comment


        • #19
          var ProfitTarget1 = 5.0;

          is the line that sets the profit target, I am pretty sure about this.

          If you want to take the profit at the click of a button, use drawTextRelative and have the buttion directed toward a section of code that closes the position, if one is open.

          drawTextAbsolute(0, 0, "ClosePosition@URL=EFS:closeAll", Color.red, Color.white, Text.FRAME|Text.BOLD , "Courier", 12, 999);

          draws some text at a price level and driects the program to function closeAll();

          the code you need in closeAll is

          Strategy.doCover("Short PT1 Exit", Strategy.STOP, Strategy.THISBAR,
          Strategy.getDefaultLotSize(), (nTradeEntryPrice - ProfitTarget1));

          or the corresponding code to exit a long.

          Do you always talk to your self like this? I do, so I know the feeling.

          Comment


          • #20
            if( getValue("hour")*100+getValue("minute") >= 945 && close()>1000000)
            debugPrintln("Time to retire");

            will let you know when it is after 945 am and you can retire, ie take a nap, not stop working

            Comment


            • #21
              Thanks David,

              I'm going to check it out.


              Cheers

              Carlton

              Comment


              • #22
                Hello David,

                I cut and pasted the formula you posted below but I couldn't get it to work. I should point out that I have very little programming experience and I'm quite sure I doing something rather silly. Therefore, would you be kind enough to detail what I would need to do to get this piece of code to work.

                Cheers mate.

                Carlton

                Comment


                • #23
                  I include the code that missed some parenthesis.

                  I am also trying to integrate that code (found from a document called ''Guide to developing eSignal Indicators'', do a search for it) with a simple but working IB buysell script.

                  Does the following: '' if (/*Buy Condition*/) '' the point where I include the test for the Buy?

                  Thank you for helping.

                  Cheers,

                  Andrei


                  /*----------------------------------------------------------------
                  // Identify new trade signals…
                  ----------------------------------------------------------------- */

                  if (Strategy.isInTrade() == false) {
                  if (/*Buy Condition*/) {
                  nNewTrade = 1; // New Trade Trigger
                  nsignal = 1; // Buy Signal – Trade Type
                  }
                  Attached Files

                  Comment


                  • #24
                    My pleasure Andrei


                    Carlton

                    Comment


                    • #25
                      Hello Carlton,

                      Here's the other example formula for the Sample Profit Target code in the Guide to Developing Strategies I promised you. This formula will also be added to the guide when we get it updated. It's basically the same formula as Sample_TargetStop.efs without the trailing stop logic. Enjoy.

                      Sample_ProfitTargets.efs
                      Jason K.
                      Project Manager
                      eSignal - an Interactive Data company

                      EFS KnowledgeBase
                      JavaScript for EFS Video Series
                      EFS Beginner Tutorial Series
                      EFS Glossary
                      Custom EFS Development Policy

                      New User Orientation

                      Comment


                      • #26
                        Jason,

                        Once again thanks ever-so-much mate.

                        I hope I'm in a position to help you out sometime.

                        Cheers

                        Carlton

                        Comment


                        • #27
                          Thank you for your help.

                          I have a couple of questions:

                          I understand that the efs is logically executed line by line from top to bottom,. Does that mean that my IBbroker buy should be placed BEFORE the alert for faster execution or does it matter little (see code below)?

                          Is there a way to submit a bid (or offer) rather than the IBbroker MARKET through the getMostRecentBid() function?

                          Thanks!

                          Andrei

                          /*----------------------------------------------------------------
                          // Identify new trade signals
                          ----------------------------------------------------------------- */
                          if (Strategy.isInTrade() == false) {
                          //if (/*Buy Condition*/)) {
                          if (vMA1_1 < vMA2_1 && vMA1 > vMA2) { //ADDED
                          nNewTrade = 1; // New Trade Trigger
                          nsignal = 1; // Buy Signal - Trade Type
                          vAlert = true;
                          AlertCntr += 1;
                          drawShapeRelative(0, vSignal, Shape.UPARROW, null, Color.yellow, Image.TOP | Image.ONTOP, "Alert" + AlertCntr);
                          drawShapeRelative(0, low() - vVar, Shape.UPARROW, "", Color.lime, null, "buyShp" + getValue("time"));
                          drawTextRelative(-1, low() - (vVar + vAddVar), "Buy MA 10e-20s", Color.black, Color.lime, Text.BOLD | Text.ONTOP, null, null, "buyTxt" + getValue("time"));
                          //
                          // buy 1 contract, limit @ market price
                          //
                          trade.Buy(getSymbol(), 1, IBBroker.MARKET);

                          Comment


                          • #28
                            Re: Reply to post 'Sample Profit Target/Trailing Stop Code'

                            My thought is that the efs updates every tick - and finishes before the next
                            tick arrives - so isn't that fast enuf?

                            A few lines earlier in the code isn't going to materially faster.

                            ----- Original Message -----
                            From: <[email protected]>
                            To: <[email protected]>
                            Sent: Tuesday, November 25, 2003 9:35 PM
                            Subject: Reply to post 'Sample Profit Target/Trailing Stop Code'


                            > Hello dloomis,
                            >
                            > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                            >

                            Comment


                            • #29
                              Carlton, look what I found behind the bush...

                              Do you think we could all try to understand the logic of it?

                              Cheers

                              Andrei
                              Attached Files

                              Comment


                              • #30
                                Andrei,

                                You give me more credit than I'm worth. I'm truly a novice. However, I am interested as to what your formula sets out to achieve.

                                Cheers

                                Carlton

                                Comment

                                Working...
                                X