Announcement

Collapse
No announcement yet.

Last Traded Price.

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

  • Last Traded Price.

    Hi people,

    I have developed a model which i am using in backtesting, however when i have to opetion to go long, I only have thre chioce to go long on trhe close of the bar or on the market of the bar.

    Problem being I eith overstate my profits or under state them,

    What I want to do is enter a trade based upon the last traded price.

    Can someone tell me how to do this please?

  • #2
    HarryBedi
    You can use Strategy.STOP or Strategy.LIMIT and enter the trade at a specific price. That price would be defined for example by an average or other price based indicator.
    When using this option you will however need to ensure that the defined price has actually been breached by the bar that generates the trade (see example below) else you may have unrealistic results
    For more information and examples you may want to read through the Guide to Developing eSignal Strategies which is in the EFS KnowledgeBase
    Alex

    PHP Code:
    if(!Strategy.isLong()&&high(0)>Price){//if High > Price
        
    if(open(0)<=Price){//if in the bar that triggers the trade Open <= Price
            
    Strategy.doLong("Long",Strategy.STOP,Strategy.THISBAR,Strategy.DEFAULT,Price);//go Long at Price
        
    }else{//otherwise
            
    Strategy.doLong("Long",Strategy.MARKET,Strategy.THISBAR);//go Long at Open
        
    }

    Comment


    • #3
      Hi Alex,

      Thanks for getting back to me.

      The problem is not that I am concerned about the price in the market.

      What I want to occur is this:

      Each time my crierias are met in a given bar for example 240 mins I would like the chart to send me an alert that criterias have been met. and that we are now entering a long position or conversely a short position.

      Unless I am being really dumb, how do I tell the chart to do that with a limit order or stop order using the wizard?

      Many thanks for all your help.

      Harry

      Comment


      • #4
        Harry
        If you are looking to trigger alerts in real time then you would simply set up the required conditions in the Formula Wizard and execute the type of alert you want.
        You should not be using the strategy object for that purpose as it is intended only for back testing
        Alex

        Comment


        • #5
          Hi Alex,

          Thanks for getting back to me. I am sorry but I didnt make myself clear. What I meant to Alerting me would be that once the conditions were met in the price bar then, I would expect to add a condition in the set price bar color object.

          But before that for back testing purposes, I need to have the back tester tell me how profitable the strategy is. I think what you posted to me before was the kind of stuff I was after, just I am not sure if I need to set up new expressions in the Wizard or include them in the existing conditions.

          Many thanks for all your help.

          Rgds,
          Harry

          Comment


          • #6
            Harry
            I am not sure I understand what you mean with "once the conditions were met in the price bar then, I would expect to add a condition in the set price bar color object."
            As to the example I provided in my earler reply you should be able to include that into your existing conditions. However, without knowing how these are set up I can't offer any specific guidance
            Alex

            Comment


            • #7
              Last Traded price?

              Hi Alex,

              Thanks for your patience.

              I copy and pasting the EFS wizard script for you. Just to reiterate what I am interested in once the conditions are met while the bar is trading not once the bar has closed, so that I can trade from the last traded price as opposed to waiting for the bar to close and i have missed part of a profitable trade.

              Many thanks for your help,
              Harry

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


              //{{EFSWizard_Declarations
              var vADXDM = new ADXDMStudy(14);
              var 
              vMACD12_26 = new MACDStudy(12269"OHLC/4"false);
              var 
              vParSAR = new ParabolicStudy(0.020.020.2);
              var 
              vRSI10 = new RSIStudy(10"Close");
              var 
              vLastAlert = -1;
              //}}EFSWizard_Declarations


              function preMain() {
              //{{EFSWizard_Code_PreMain_setPriceBarColor
              setColorPriceBars(true);
              //}}EFSWizard_Code_PreMain_setPriceBarColor
                 /**
                  *  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("test");
              //}}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 (
                          
              Strategy.isLong() == false &&
                          
              close() > high(-1) &&
                          
              close() > high(-2) &&
                          
              close() > high(-3) &&
                          
              vADXDM.getValue(ADXDMStudy.PDI) > vADXDM.getValue(ADXDMStudy.NDI) &&
                          
              vADXDM.getValue(ADXDMStudy.ADX, -1) > 20 &&
                          
              vADXDM.getValue(ADXDMStudy.ADX, -2) > 20 &&
                          
              vADXDM.getValue(ADXDMStudy.ADX, -3) > 20 &&
                          
              vMACD12_26.getValue(MACDStudy.HIST) > &&
                          
              vRSI10.getValue(RSIStudy.RSI) > 30 &&
                          
              vParSAR.getValue(ParabolicStudy.STOP) <= low(0)
                      ) 
              onAction1()
                  
              //}}EFSWizard_Expression_1
                  
                  //{{EFSWizard_Expression_2
                      
              else if (
                          
              Strategy.isShort() == false &&
                          
              close() > low(-1) &&
                          
              close() > low(-2) &&
                          
              close() > low(-3) &&
                          
              vADXDM.getValue(ADXDMStudy.PDI) < vADXDM.getValue(ADXDMStudy.NDI) &&
                          
              vADXDM.getValue(ADXDMStudy.ADX, -1) > 20 &&
                          
              vADXDM.getValue(ADXDMStudy.ADX, -2) > 20 &&
                          
              vADXDM.getValue(ADXDMStudy.ADX, -3) > 20 &&
                          
              vMACD12_26.getValue(MACDStudy.HIST) < &&
                          
              vRSI10.getValue(RSIStudy.RSI) < 70 &&
                          
              vParSAR.getValue(ParabolicStudy.STOP) >= high(0) &&
                          
              Strategy.isShort() < 
                      ) 
              onAction2()
                  
              //}}EFSWizard_Expression_2
                  
                  //{{EFSWizard_Expression_3
                      
              else if (
                          
              Strategy.isLong() == true &&
                          
              vRSI10.getValue(RSIStudy.RSI) >= 70 &&
                          
              Strategy.isInTrade() == true
                      
              onAction3()
                  
              //}}EFSWizard_Expression_3
                  
                  //{{EFSWizard_Expression_4
                      
              else if (
                          
              Strategy.isLong() == true &&
                          
              vRSI10.getValue(RSIStudy.RSI) < 30 &&
                          
              Strategy.isInTrade() == true
                      
              onAction4()
                  
              //}}EFSWizard_Expression_4
                  
                  //{{EFSWizard_Expression_5
                      
              else if (
                          
              Strategy.isShort() == true &&
                          
              vRSI10.getValue(RSIStudy.RSI) > 70 &&
                          
              Strategy.isInTrade() == true
                      
              onAction5()
                  
              //}}EFSWizard_Expression_5
                  
                  //{{EFSWizard_Expression_6
                      
              else if (
                          
              Strategy.isShort() == true &&
                          
              vRSI10.getValue(RSIStudy.RSI) < 30 &&
                          
              Strategy.isInTrade() == true
                      
              onAction6()
                  
              //}}EFSWizard_Expression_6
                  
                  //{{EFSWizard_Expression_7
                      
              else if (
                          
              Strategy.isLong() < high()>Price
                      
              onAction7();
                  
              //}}EFSWizard_Expression_7
                  
              //}}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() {
                      
              setPriceBarColor(Color.RGB(0,255,0));
                      
              drawShapeRelative(0low(), Shape.UPARROW""Color.RGB(155,0,0), Shape.BOTTOM);
                      
              Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Bullet.wav");
                      if (
              vLastAlert != 1Strategy.doLong("LONG"Strategy.MARKETStrategy.THISBARStrategy.DEFAULT, 0);
                      
              vLastAlert 1;
                  }
                  
              //}}EFSWizard_Action_1
                  
                  //{{EFSWizard_Action_2
                  
              function onAction2() {
                      
              setPriceBarColor(Color.RGB(255,0,0));
                      
              drawShapeRelative(0low(), Shape.DOWNARROW""Color.RGB(255,0,0), Shape.TOP);
                      
              Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Train.wav");
                      if (
              vLastAlert != 2Strategy.doShort(""Strategy.MARKETStrategy.NEXTBARStrategy.DEFAULT, 0);
                      
              vLastAlert 2;
                  }
                  
              //}}EFSWizard_Action_2
                  
                  //{{EFSWizard_Action_3
                  
              function onAction3() {
                      
              setPriceBarColor(Color.RGB(255,255,0));
                      
              Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Applause.wav");
                      
              drawShapeRelative(0low(), Shape.CIRCLE""Color.RGB(166,202,240), Shape.LEFT);
                      if (
              vLastAlert != 3Strategy.doSell(""Strategy.CLOSEStrategy.THISBARStrategy.DEFAULT, 0);
                      
              vLastAlert 3;
                  }
                  
              //}}EFSWizard_Action_3
                  
                  //{{EFSWizard_Action_4
                  
              function onAction4() {
                      
              setPriceBarColor(Color.RGB(128,0,128));
                      
              Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Punch.wav");
                      
              drawShapeRelative(0low(), Shape.SQUARE""Color.RGB(155,0,0), Shape.LEFT);
                      if (
              vLastAlert != 4Strategy.doSell(""Strategy.CLOSEStrategy.THISBARStrategy.DEFAULT, 0);
                      
              vLastAlert 4;
                  }
                  
              //}}EFSWizard_Action_4
                  
                  //{{EFSWizard_Action_5
                  
              function onAction5() {
                      
              setPriceBarColor(Color.RGB(155,0,0));
                      
              Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Punch.wav");
                      
              drawShapeRelative(0low(), Shape.SQUARE""Color.RGB(155,0,0), Shape.LEFT);
                      if (
              vLastAlert != 5Strategy.doCover(""Strategy.CLOSEStrategy.THISBARStrategy.DEFAULT, 0);
                      
              vLastAlert 5;
                  }
                  
              //}}EFSWizard_Action_5
                  
                  //{{EFSWizard_Action_6
                  
              function onAction6() {
                      
              setPriceBarColor(Color.RGB(166,202,240));
                      
              Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Applause.wav");
                      
              drawShapeRelative(0low(), Shape.CIRCLE""Color.RGB(166,202,240), Shape.LEFT);
                      if (
              vLastAlert != 6Strategy.doCover(""Strategy.CLOSEStrategy.THISBARStrategy.DEFAULT, 0);
                      
              vLastAlert 6;
                  }
                  
              //}}EFSWizard_Action_6
                  
                  //{{EFSWizard_Action_7
                  
              function onAction7() {
                      
              setPriceBarColor(Color.RGB(0,255,0));
                      
              drawShapeRelative(0low(), Shape.UPARROW""Color.RGB(0,255,0), Shape.BOTTOM);
                      
              Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Bullet.wav");
                      if (
              vLastAlert != 7Strategy.doLong("Long"Strategy.CLOSEStrategy.THISBARStrategy.DEFAULT, Price);
                      
              vLastAlert 7;
                  }
                  
              //}}EFSWizard_Action_7
                  
              //}}EFSWizard_Actions 

              Comment


              • #8
                Re: Last Traded price?

                Alex,

                One more thing, I tried entering the script u provided at the bottom in to the wizard, however I have a problem as I have not declared what Price is.

                How do I declare a variable in the wizard? Or in this case I need to declare model as price. Once the criterias of the model are met ie true, then they become "Price" then I need to say that if the Price is true and it triggers in the bar, then enter the trade "do.Long" otherwise wait until the close and then wait for the signal.

                Thanks
                HArry

                Comment


                • #9
                  Harry
                  In back testing an efs executes only once per bar and has no way of telling at what specific price within a bar a trade would be triggered under real time conditions
                  The choices available to you are MARKET which is the same as Open and CLOSE which is the Close. In back testing these two prices will provide results that are the closest to the ones you would be get when running the same strategy in real time and basing all your signals on the close of a bar.
                  Having said that you can try to simulate real time conditions by using an intrabar price. In that case you would use STOP or LIMIT as the entry and you would need a price based indicator (such as a moving average) to allow you to define the entry price.
                  A reasonable approximation could be obtained with a 1 period moving average of HLC/3 which can be easily set up in the Formula Wizard and then used throughout the strategy as the entry price. Using a 1 period average also allows you not to check if prices breached the average because by definition it is always contained within the bar. The solution I am suggesting should closely simulate an intrabar entry and provide you with the kind of analysis you are trying to accomplish
                  Alex

                  Comment


                  • #10
                    Harry
                    With regards to the efs you posted I would completely remove Set7 as it contains several errors.
                    As to adding a moving average to use as the entry price (as explained in my prior reply) you can see an example of what I mean in the enclosed image. Notice that I have added a 1 period MA study of the HLC3 and that I have changed Strategy.CLOSE to Strategy.STOP and use the value of the MA as the STOP price
                    Alex

                    Comment


                    • #11
                      Thanks Alex,

                      Thats done the job.

                      However one more question.

                      Going back to your earlier post that the EFS wizard only calculates on the close of the bar. You also provided me with a script which basically worked on the principle if the price was met and the criterias fulfilled the an alert or in this case a long or short position would be take.

                      How do I going forward incorporate a signal based upon the events happening in live time - how should I alter the code?

                      Many thanks for your help - almost at the winning post!

                      Regards
                      Harry

                      Comment


                      • #12
                        Harry
                        FYI I did not say that an efs created with the Formula Wizard calculates only on the close of a bar. What I said was that in backtesting an efs executes only once per bar.
                        As to converting your formula for real time use you would need to rewrite the study replacing all the strategy objects with user defined global variables that you will use to track your long/short state. To do this you will need to use the EFS Editor as the Formula Wizard does not have the provision to create user defined variables.
                        If you are uncomfortable writing this yourself I would suggest that you enlist the help of one of the EFS Consultants
                        Alex

                        Comment


                        • #13
                          Thanks for clearing up my ignorange.

                          All the best
                          HArry

                          Comment

                          Working...
                          X