Announcement

Collapse
No announcement yet.

Getting day of the week in a var?!?!

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

  • Getting day of the week in a var?!?!

    Hi, I'd like to grab the current day of the week for the current candle. I used the code below and it grabbed the current date from my PC's clock. I'm doing this so I can cut my positon in 1/2 on fridays and mondays. Thanks!

    daynow = new Date(); //dont work

    if (
    daynow.getDay() == 5
    ) onAction3()


    thanks always
    Geoff

  • #2
    Hi Geoff,

    Check the Time folder in my Fileshare (the link is below). There are efs's there that show how to accomplish this. The efs entitled myDayTest.efs shows how to grab this information efficiently.

    Further, I believe the Time Functions 08 14 2006.efs provides some additional clarification by performing a good side by side comparison of the differences between PC clock time and the bar time functionality.

    I hope this helps.

    Comment


    • #3
      YES. **LL YES.. HECK YES I MEAN

      Yes the 'basic' script is now complete thanks to your help! You will be awarded a prize. M&Ms ok ?? Im sure someone will find a flaw in this but hey its all good. I still need to put in some menu parameters and install some sort of stop/target system. Here it is in entirety for the heck of it or if anyone wants it.

      PHP Code:
      /* Geoff Notes
      ===============

      This script accomplishes the following:
                  
                 (NA=NOT CODED YET)
         # THIS FILE WAS TESTED ON THE DOW MINI / YM
         # DOESNT ALLOW TRADES IN DEAD ZONE 12-1415
         # FRIDAYS IT CUTS THE LOT SIZE DOWN BY 1/3RD
         # NO SLEEPING WITH POSITIONS CLOSES OUT POSITIONS EOD
         # 900-1600 TRADES ONLY -- THIS SHOULD BE ACCOMPLISHED BY YOUR ESIGNAL TIME TEMPLATE OR OWN DICIPLINE
         # CLOSES OUT TRADE STILL BEING HELD IN TO DEADZONE

         
      CURRENTLY WORKING ON: STOPS -- MUST MAKE SOME MANUAL LOOPS DUE TO BUG


         
      */


      // Var code for current genericstrategy (EMA Crossover) - Remove if your changing strategies

      var vEMA8 = new MAStudy(640"Close"MAStudy.EXPONENTIAL); // Equiv to 8/21 on 8minute time frame
      var vEMA21 = new MAStudy(1680"Close"MAStudy.EXPONENTIAL);

      // END    

          
      function preMain() {
      //Code_PreMain_setPriceBarColor
      setColorPriceBars(true);
      //Code_PreMain_setPriceBarColor
         /**
          *  This function is called only once, before any of the bars are loaded.
          *  Place any study or EFS configuration commands here.
          */
          
      setPriceStudy(true);
          
      setStudyTitle("Base Strategy BETA 1.2");
          
      setCursorLabelName("fast"0);
          
      setCursorLabelName("slow"1);
          
      setDefaultBarStyle(PS_SOLID0);
          
      setDefaultBarStyle(PS_SOLID1);
          
      setDefaultBarFgColor(Color.brown0);
          
      setDefaultBarFgColor(Color.white1);
          
      setDefaultBarThickness(10);
          
      setDefaultBarThickness(11);
          
      setPlotType(PLOTTYPE_LINE0);
          
      setPlotType(PLOTTYPE_LINE1);

          
      AllowTrading true
        
      //  size=0;
          
      size Strategy.getDefaultLotSize(); // Variable only passes to main from BT front end
          
      symb = new String(getSymbol() );
          
      EntryPrice=0;
          
      vLastAlert = -1;
         
      //  var size = Strategy.getDefaultLotSize() // testing only i think its broke
              
      //  Below are variables passed from the edit studies configure menu. 

          
      gStop = new FunctionParameter("gStop"FunctionParameter.NUMBER);
          
      gStop.setDefault(20); 
          
      gStop.setName("Hard Stop");

          
      gParam2 = new FunctionParameter("gParam2"FunctionParameter.NUMBER);
          
      gParam2.setDefault100 ); 
          
      gParam2.setName("Parameter 2");

          
      gParam3 = new FunctionParameter("gParam3"FunctionParameter.NUMBER);
          
      gParam3.setDefault100 ); 
          
      gParam3.setName("Parameter 3");

      }

      function 
      main(gStopgParam2gParam3) {
         
      /**
          *  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.
          */

      if (symb !="YM #F") {
      drawTextPixel(1050"THIS STUDY IS INTENDED FOR USE ON THE DOW MINI YM #F SYMBOL ONLY!"Color.RGB(0,0,255), Color.RGB(165,165,165), Text.ONTOPnull10"TagName");
      debugPrintln("THIS STUDY IS INTENDED FOR USE ON THE DOW MINI YM #F SYMBOL ONLY! " symb " rejected!");
      return;
       }

      // GET TIME AND SET TRADING TO OK
          
      var Time = (hour(0)*100)+minute(0);
          
      daynow = new Date(getValue("time",0));
          
      AllowTrading true;
      // 


      // EXIT TRADES AT BEGINNING OF DZ
         
      if(Time == 1200 && Strategy.isInTrade() && Strategy.isShort() ) {
         
      AllowTrading false;
         
      Strategy.doCover"DZ Exit Short"Strategy.CLOSEStrategy.THISBARStrategy.ALL ); }
         else if (
      Time == 1200 && Strategy.isInTrade() && Strategy.isLong() ) {
         
      AllowTrading false;
         
      Strategy.doSell"DZ Exit Long"Strategy.CLOSEStrategy.THISBARStrategy.ALL); }
      // END DZ EXIT CODE


      // EXIT TRADES AT EOD 
         
      if(day(0) != day(1) && Strategy.isInTrade() && Strategy.isShort() ) {
         
      Strategy.doCover"EOD Exit Short"Strategy.CLOSEStrategy.THISBARStrategy.ALL ); 
         
      AllowTrading false;
         
      vLastAlert = -1
       
      }
         else if (
      day(0) != day(1) && Strategy.isInTrade() && Strategy.isLong() ) {
         
      Strategy.doSell"EOD Exit Long"Strategy.CLOSEStrategy.THISBARStrategy.ALL);
         
      AllowTrading false;
         
      vLastAlert = -

      // END EOD EXIT CODE


      // DEADZONE TEST -- IF FOUND THEN DISALLOW TRADES
              
      if (
                  
      Time >= 1200 &&
                  
      Time 1415
              
      onAction1()
      //}}END DZ TEST
            
       //{{CHECK DAY OF WEEK -- IF MONDAY UP SHARES, IF FRIDAY LOWER SHARES OR NOT ALLOW TRADING
               
      if (
                  
      daynow.getDay() == )  {
                  
      size Math.round(Strategy.getDefaultLotSize() / 3);
                  
      // AllowTrading=false 
                  
      }
              else if (
                  
      daynow.getDay() == ) {
                  
      size Math.round(Strategy.getDefaultLotSize() * 2); }
                  
              else if ( 
      daynow.getDay() != 5) {
                  
      size Strategy.getDefaultLotSize(); }
              
      //}}END FRIDAY/MONDAY CHECK
              
              
      //{{ 8 / 21 EMA CROSSOVER STRATEGY CODE -------REPLACE THIS WITH SOMETHING GOOD N PLENTY
               
      if (
                  
      vEMA8.getValue(MAStudy.MA) < vEMA21.getValue(MAStudy.MA) &&
                  
      getBarState()== BARSTATE_NEWBAR &&   // SUPPOSED TO LESSON FALSE SIGNALS ON TICK REPLY
                  
      AllowTrading == true 
              
      onAction4()
              
               else if (
                  
      vEMA8.getValue(MAStudy.MA) > vEMA21.getValue(MAStudy.MA) &&
                  
      getBarState()== BARSTATE_NEWBAR && // SUPPOSED TO LESSON FALSE SIGNALS ON TICK REPLY
                  
      AllowTrading == true 
              
      onAction5()
              
        
          
      //{{Return Values for MAS for graphic plotting on chart
              
      return new Array(
                  
      vEMA8.getValue(MAStudy.MA),
                  
      vEMA21.getValue(MAStudy.MA)
              );
          
      //}}END ARRARY RETURN
          
      //}}END STRATEGY CODE ----------------------------------------------


      }



      //{{ACTIONS CALLED FROM MAIN

          //{{DONT ALLOW TRADING!
          
      function onAction1() {
              
      AllowTrading false;
              
      vLastAlert 1;       
          }
          
      //}}END Action_1
          
             
          //{{Action_4 - SHORT ENTRY
          
      function onAction4() {
              
      setBarBgColor(Color.red);
              
      //       if (Strategy.isShort() == false) // I dont recall why i commented this out but script is working
             
      if (vLastAlert != )   
             {
             
      Strategy.doShort("Short Entry"Strategy.CLOSEStrategy.THISBARsize0); 
             
      EntryPrice close(0);
             }
             
      vLastAlert 4;    
          }
          
      //}}END Action_4
          
          //{{Action_5 - LONG ENTRY
          
      function onAction5() {
              
      setBarBgColor(Color.blue);
              
      //       if (Strategy.isLong() == false)  // I dont recall why i commented this out but script is working
               
      if (vLastAlert != 
              { 
              
      Strategy.doLong("Long Entry"Strategy.CLOSEStrategy.THISBARsize0);
              
      EntryPrice close(0); 
              
      vLastAlert 5; }
         }
          
      //}}END Action_5
          
          
      //}}END ALL Actions

      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).
          */

      Comment


      • #4
        Originally posted by glay
        Yes the 'basic' script is now complete thanks to your help! You will be awarded a prize. M&Ms ok ??
        You are welcome, but I will pass on the prize. Hope this works out for you.

        Comment

        Working...
        X