Announcement

Collapse
No announcement yet.

Help to improve this formula

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

  • Help to improve this formula

    Hi, friends,
    Please, I need help to modifie this formula, because times in times I need to reload it.
    Is there some way to have no need to reload it?
    PHP Code:
    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("Break2NX"); 
        
    setColorPriceBars(true);
        
    setDefaultPriceBarColor(Color.yellow);

    }

    function 
    main() {
        var 
    vHL high() - low();
        var 
    vVar vHL 0.35;
        var 
    vAddVar vVar 0.50;

        if(
    close() > high(-1) && !Strategy.isLong()){
            
    Strategy.doLong("Long"Strategy.MARKETStrategy.NEXTBAR);
            
    drawShapeRelative(0low() - vVarShape.UPARROW""Color.bluenull"buyShp" getValue("time"));
            
        }
        if(
    close() < low(-1) && !Strategy.isShort()){
            
    Strategy.doShort("Short"Strategy.MARKETStrategy.NEXTBAR);
            
    drawShapeRelative(0high() + vVarShape.DOWNARROW""Color.yellownull"sellShp" getValue("time"));
            
        }

        if(
    Strategy.isLong())
                   
    setPriceBarColor(Color.navy);
        if(
    Strategy.isShort())
                
    setPriceBarColor(Color.red);
                
        return;

    Last edited by Barros; 04-05-2006, 01:25 PM.

  • #2
    try adding this to your premain function

    setComputeOnClose(true);

    Comment


    • #3
      Thanks

      Hi Biswar,
      Very good your solution.
      Thank you very much.
      Be lucky.

      Comment


      • #4
        Another Improve

        Please, can someone help to set sound alerts when the buy or sell signs happen?

        Comment


        • #5
          Barros
          Add Alert.playSound("ding.wav"); (using any wav file of your choice) inside each condition after the drawShapeRelative(...) commands.
          For more information on the alert functions see this article in the EFS KnowledgeBase
          Alex

          Comment


          • #6
            Thanks

            Hi Alexis,
            Thank you. It is working very well.

            Comment


            • #7
              Barros
              My pleasure
              Alex

              Comment


              • #8
                Another Formula needs improvements

                Hi Friends,
                Please, this formula needs improvements from whom has better know how than me, to separate the circles from the highs and lows and make it work better:

                //{{EFSWizard_Description
                //
                // This formula was generated by the Alert Wizard
                //
                //}}EFSWizard_Description


                //{{EFSWizard_Declarations
                var vDonchian = new DonchianStudy(10, -4);
                var vLastAlert = -1;
                //}}EFSWizard_Declarations


                function preMain() {
                /**
                * This function is called only once, before any of the bars are loaded.
                * Place any study or EFS configuration commands here.
                */
                //{{EFSWizard_PreMain
                setPriceStudy(true);
                setStudyTitle("ADonTouch");
                //}}EFSWizard_PreMain

                }

                function main() {
                /**
                * The main() function is called once per bar on all previous bars, once per
                * each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
                * in your preMain(), it is also called on every tick.
                */

                //{{EFSWizard_Expressions
                //{{EFSWizard_Expression_1
                if (
                high() == vDonchian.getValue(DonchianStudy.UPPER)
                ) onAction1()
                //}}EFSWizard_Expression_1

                //{{EFSWizard_Expression_2
                else if (
                low() == vDonchian.getValue(DonchianStudy.LOWER)
                ) onAction2();
                //}}EFSWizard_Expression_2

                //}}EFSWizard_Expressions


                //{{EFSWizard_Return
                return null;
                //}}EFSWizard_Return

                }

                function postMain() {
                /**
                * The postMain() function is called only once, when the EFS is no longer used for
                * the current symbol (ie, symbol change, chart closing, or application shutdown).
                */
                }

                //{{EFSWizard_Actions
                //{{EFSWizard_Action_1
                function onAction1() {
                if (vLastAlert != 1) drawShapeRelative(0, high(), Shape.CIRCLE, "", Color.RGB(255,0,0), Shape.TOP);
                if (vLastAlert != 1) Alert.playSound("D:\\Arquivos de programas\\eSignal\\Sounds\\doorbell.wav");
                vLastAlert = 1;
                }
                //}}EFSWizard_Action_1

                //{{EFSWizard_Action_2
                function onAction2() {
                if (vLastAlert != 2) drawShapeRelative(0, low(), Shape.CIRCLE, "", Color.RGB(0,0,255), Shape.BOTTOM);
                if (vLastAlert != 2) Alert.playSound("D:\\Arquivos de programas\\eSignal\\Sounds\\Ding.wav");
                vLastAlert = 2;
                }
                //}}EFSWizard_Action_2

                //}}EFSWizard_Actions
                Last edited by Barros; 04-08-2006, 05:08 AM.

                Comment


                • #9
                  Hi Barros

                  you can add or subtract a value from the high or low


                  ie
                  drawShapeRelative(0, high()+2, Shape.CIRCLE, "", Color.RGB(255,0,0), Shape.TOP);

                  this will plot the circle 2 points or ticks above the high, you will need to change the value depending on the market you are trading,
                  for instance on the russell i would use .2 and on the dow i would use 2

                  hope this makes sense

                  Comment


                  • #10
                    Some circles do not appears

                    Hi Biswar and all,
                    The solution to separate the circles from the highs and lows is working well.
                    There are some circles that were to appear but are not, do you have some suggestion?

                    Comment


                    • #11
                      Barros
                      As far as I can see the formula is drawing all the appropriate circles on historical data. To see this replace in the main function
                      return null;
                      with
                      return new Array (vDonchian.getValue(DonchianStudy.UPPER), vDonchian.getValue(DonchianStudy.LOWER));
                      Note that as it is written now this formula will only work (albeit incorrectly) on historical data and not in real time. This is because you are applying a negative offset when you declare the Donchian Channel but your conditions are looking at the current bar - for which there are no values - instead of 4 bars back. This means that on historical bars your efs is forward looking (ie it "knows" what will happen in the future).
                      In order for this efs to work in real time and provide the correct signals on historical data you need to change your conditions to
                      if (
                      high(-4) == vDonchian.getValue(DonchianStudy.UPPER,-4)
                      ) onAction1()

                      and
                      else if (
                      low(-4) == vDonchian.getValue(DonchianStudy.LOWER,-4)
                      ) onAction2();

                      Once you do this you will see the circles appear on the appropriate bars just like they would actually be if you were running the efs in real time (see the image enclosed below)
                      Alex

                      Comment


                      • #12
                        Very good observation

                        Hi Alex, once more, thanks for the perfect responce.
                        I would like to make the circles appear even when the high be -1 point below the Donchian or the low be +1 above the Donchian. Could you give me the solution, please?

                        Comment


                        • #13
                          Barros
                          The conditions would need to be changed as follows.
                          At this point you should have enough examples and information to be able to modify the script to your requirements
                          Alex

                          PHP Code:
                          if(high(-4) >= (vDonchian.getValue(DonchianStudy.UPPER,-4) - 1) && high(-4) <= vDonchian.getValue(DonchianStudy.UPPER,-4))
                          //etc
                          if(low(-4) <= (vDonchian.getValue(DonchianStudy.LOWER,-4) + 1) && low(-4) >= vDonchian.getValue(DonchianStudy.LOWER,-4))
                          //etc 

                          Comment


                          • #14
                            Thanks

                            Hi Alex,
                            Thank you very much!

                            Comment

                            Working...
                            X