Announcement

Collapse
No announcement yet.

reload efs from within code

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

  • #16
    Thanks Steve,

    Will be trying this out later on today. Have chores to do first.

    Paul Murray.

    Comment


    • #17
      Have not implemented this solution yet, but have another question - seeing you mentioned date functions.

      How can I test if a bar is from today's data, so thet I can build a running total of Profit/Loss just for trade signals today, when an efs is loaded up or maybe an option selected.

      Paul.

      Comment


      • #18
        Steve,

        Just noticed you posted the efs, have downloaded it and will give it a go.

        Thanks.

        Paul.

        Comment


        • #19
          Another thing I wouuld like to do is close all trades (or not open new ones) in the last 10 minutes of trading, some very poor overnight paper trades are ruining my strategy.

          Paul.

          Comment


          • #20
            Currently checking for today with

            PHP Code:
             if (getBarState() == BARSTATE_NEWBAR && getDay(0)==day(0)) 
            To only process trades for today, but this does not work, I amgetting results for all data in time template.

            Paul.

            Comment


            • #21
              Paul,

              I never heard if the reloadEFS() efs ever worked on your end, please let me know.

              Regarding the issue regarding checking for the current day, this should work for you, it is a fully functional efs that can be run for demonstration purposes. Just extract the appropriate sections for your efs.

              A copy will also be available in my fileshare.

              PHP Code:
              // Add this section as global, outside mmain
              var todayBar;
              var 
              today;
              var 
              chartDay;
              var 
              clockDay;
              var 
              myDayTest;
              function 
              Check_Time(){
               
              today = new Date();
               
              todayBar = new Date(getValue("time",0)); // alternately getValue("time",0);
               
              chartDay today.getDate(); // alternately day(0)
               
              clockDay todayBar.getDate();
               
              myDayTest = (chartDay == clockDay);
              }
               
              var 
              bInit false
              function 
              preMain(){
               
              setStudyTitle("MyDayTest");
               
              setShowCursorLabel(false);
              }

              function 
              main(){
               
               if(!
              bInit){
                
              Check_Time();
                
              bInit true;
               }
               
               
              //checks once every new bar
               
              if (getBarState() == BARSTATE_NEWBAR ){
                
              // checked once per hour
                
              if(hour(0)!=hour(-1)){  // by sticking this in here, it decreases number of times the Date object it is called
                 
              Check_Time();
                }
                
              // then to check if the day is the current one
                
              if(myDayTest){
                 
              debugPrintln("37: myDayTest = "+myDayTest+" clockDay = "+clockDay+" chartDay = "+chartDay);
                }
                else{
                 
              debugPrintln("39: myDayTest = "+myDayTest+" clockDay = "+clockDay+" chartDay = "+chartDay);
                }
               } 
              //end barcheck
               

              Comment


              • #22
                Hi Steve,

                thanks for the reply,

                actually I have been concentrating on the date check routine, just twigged the date routine this afternoon, I like your idea of checking the hour to avoid calling time routine too often.

                Am working on a routine to close trades out before end of trading day (especially useful for FTSE at it can gap after US markets have done their thing).

                Have not implemented reloadefs as it is not something to test during trading day (if it locks up eSignal), but it is integral to my current system - so I will get round to it. I am very grateful for the efforts you made to help me.

                It is difficult trying to fit in all this development, trade and leave time for my family (oh and get some sleep).

                But would we have it any other way.

                Paul Murray.

                Comment


                • #23
                  I am interested to know how others have got on with this thread utilising the reloadEFS() call. I have my code working as I wanted in 'ComputeOnClose(true)' mode and I wanted to move it up a gear into current bar calculations. I am finding the odd miscalculation such that if I 'reload' the script, it recalculates the values correctly. Which leads me back to this thread - I am trying to achieve exactly the same principle of reloading the EFS script every time a new NEW_BAR forms.

                  I have tried following the scripts below, but without any success - the section of code that would indicate that my 'reload' could fire, never gets triggered.

                  Anyone else manage to resolve this?

                  Comment


                  • #24
                    I got this to work using Alex's example (sorry, no link).

                    Code:
                    	if (reload) {
                    		if(vLastCount == null) 
                    			vLastCount = getNumBars(); 
                    		if(vLastCount != getNumBars()) { 
                    			vLastCount = getNumBars(); 
                    			reloadEFS(); 
                    			return; 
                    		}
                    	}
                    where reload is a flag indicating whether you want to do reloading, in general. vLastCount is an efs-level var initially set to null. The real question for me, is, why do I need to use this at all. It seems it is required in my efs. I could post it, but it is proprietary. Maybe I change some things.

                    Comment


                    • #25
                      Maybe something like this, will illustrate:

                      PHP Code:
                      function preMain()
                      {
                          
                      setStudyTitle("Test"); 
                          
                      setPriceStudy(true);
                          
                      setDefaultBarFgColor(Color.RGB(00114), 0);
                          
                      setPlotTypePLOTTYPE_INSTANTCOLORLINE);
                      }

                      var 
                      Value1_1 0.0;
                      var 
                      close0close1;
                      var 
                      vLastCount null;
                      var 
                      reload false;
                      var 
                      init true;
                          
                      function 
                      main(periodfactor1factor2thicknessshiftvol)
                      {
                          if (
                      period == null)
                              
                      period 3;
                          if (
                      factor1 == null)
                              
                      factor1 2;
                          if (
                      factor2 == null)
                              
                      factor2 2;
                          if (
                      thickness == null)
                              
                      thickness 4;
                          if (
                      shift == null)
                              
                      shift 0.998;

                          
                      // reload
                          /*if (reload) {
                              if(vLastCount == null) 
                                  vLastCount = getNumBars(); 
                              if(vLastCount != getNumBars()) { 
                                  vLastCount = getNumBars(); 
                                  reloadEFS(); 
                                  return; 
                              }
                          }*/
                          
                          
                      if (init) {      
                              
                      setDefaultBarThickness(thickness0);
                              var 
                      sym = new String(getSymbol());
                              
                      /*if (sym.indexOf(" - ") || sym.indexOf(" + ") || 
                                  sym.indexOf(" * ") || sym.indexOf(" / "))*/
                                  //reload = true;
                              
                      init false;
                          }

                          
                      close0 close(), close1 close(-1);

                          if (
                      vol) {
                              var 
                      volume0 volume();
                              
                      // do something with volume
                          
                      }

                          
                      //var Price = "Close";
                          //if (sPrice != null) Price = sPrice;
                          
                      var vPrice close0;
                          
                      //(open+high+low90+close())/4
                          
                      var MARK 0.8;
                          if (
                      period != nullMARK period;
                          var 
                      Value2 factor1 MARK-1;
                          var 
                      mark 0.0;
                          if ((
                      Value2) != 0mark factor2 Value2;
                          var 
                      Value1 = -* (mark vPrice Value1_1);
                          var 
                      factor3 Value1 vPrice;
                          if (
                      Value1 Value1_1)//( nPlot>nPlot_1 ) 
                              
                      setBarFgColor(Color.RGB(01920), 0);
                          else if (
                      Value1 Value1_1)//( nPlot<nPlot_1 ) 
                              
                      setBarFgColor(Color.RGB(25500), 0);
                          else 
                      setBarFgColor(Color.RGB(767676), 0);
                          if (
                      getBarState() == BARSTATE_NEWBARValue1_1 Value1;

                          return (
                      Value1 factor3) *shift;

                      Comment


                      • #26
                        Hi Atlas,



                        I may have misunderstood the problem and haven't dug too deeply into the old posts associated with this thread.

                        But it sounded like the origional problem was that a manual reload had to be done to get the same results in tick replay/ or realtime as when processing historical bars?


                        If that's the case then that can usually be resolved by not using barindex 0 for evaluating indicator values, as index 0 is changes with each trade and is therefore not stable to use for signal evaluation. Using -2 and -1 barindexes usually resolves the problerm and manual reaload's (or realoadEFS() functions) would therefore not be necessary.

                        Glen
                        Glen Demarco
                        [email protected]

                        Comment


                        • #27
                          I don't think I'm using a barIndex anywhere.

                          Comment


                          • #28
                            atlas
                            To fix your code so that it works correctly in real time without the need to reload the script using ReloadEFS() you first need to declare the variable Value1 as a global variable (ie outside of main) and not as a local variable (as you do that remember to remove the var from where you declare it locally).
                            Then you need to move the line
                            if(getBarState() == BARSTATE_NEWBAR) Value1_1 = Value1;
                            to a line prior to where you calculate the value of Value1.
                            Once you make these changes the script should work correctly
                            For an explanation of why this is required see this post in reply to a similar issue.
                            Alex

                            Comment


                            • #29
                              Originally posted by atlas
                              I don't think I'm using a barIndex anywhere.
                              Hi Atlas,

                              What I was referring to was the first numeric parameter passed to most of the builtin data series functions such as: close(0), open(-1), high(-2), etc., is referrred to as the Barindex parameter.

                              When a null value is passed to those fuinctions as in: close(), the default numeric value passed is 0.

                              Not sure if the solution was a barindex issue or related to the solution Alex found but thought this was something you may want to know.

                              Glen
                              Glen Demarco
                              [email protected]

                              Comment


                              • #30
                                Ok, thanks everyone. I think I have some kind of dyslexia when it comes to ordering things, in code. Works good.

                                Comment

                                Working...
                                X