Announcement

Collapse
No announcement yet.

Averaging System with multiple entry's and exit's

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

  • #46
    PHP Code:
    function main(OvernightLogic,UserTime,StartTime,EndTime,LineLen,Stop,Lv1,Lv2,Lv3,Lv4,CloseAllTime,TodayOnly,plotPrice,PriceOffset,TrdSz1,TrdSz2,TrdSz3,TrdSz4,MaxClip)  
    {  
        var 
    xOpen  LineTag null;  
        if(
    TodayOnlyLineTag 105;  
        else 
    LineTag gID();  
        if(
    isMonthly() || isWeekly() || isDaily()) return;
        
        var  
    barDate getValue("time");
        var 
    dayOfWeek barDate.getDay();
        if (
    dayOfWeek == 0) return;
        
          if((
    hour(0)*100)+minute(0)>=UserTime && bInit == false
        {  
            
            
    nPrice open(0); 
        
            
    drawLineRelative0nPrice+Lv1LineLennPrice+Lv1PS_DOT1Color.maroon"Up"+LineTag );  
            
    drawLineRelative0nPrice+Lv2LineLennPrice+Lv2PS_DOT1Color.green"Up1"+LineTag );  
            
    drawLineRelative0nPrice+Lv3LineLennPrice+Lv3PS_DOT1Color.red"Up2"+LineTag );  
            
    drawLineRelative0nPrice+Lv4LineLennPrice+Lv4PS_DOT2Color.red"Up3"+LineTag );  
            
    drawLineRelative0nPrice-Lv1LineLennPrice-Lv1PS_DOT1Color.maroon"Dwn1"+LineTag );  
            
    drawLineRelative0nPrice-Lv2LineLennPrice-Lv2PS_DOT1Color.green"Dwn2"+LineTag );  
            
    drawLineRelative0nPrice-Lv3LineLennPrice-Lv3PS_DOT1Color.red"Dwn3"+LineTag );  
            
    drawLineRelative0nPrice-Lv4LineLennPrice-Lv4PS_DOT2Color.red"Dwn4"+LineTag );  
            
    drawLineRelative0nPriceLineLennPricePS_SOLID1Color.blue"OpenMid"+LineTag );   
              
            
    bInit true;
        }
        
       
        if(
    plotPrice.indexOf("Open")!=-1drawTextRelative(PriceOffsetnPricenPrice+0Color.bluenullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_A");  
        if(
    plotPrice.indexOf("Res1")!=-1drawTextRelative(PriceOffsetnPrice+Lv1nPrice+Lv1Color.maroonnullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_H");  
        if(
    plotPrice.indexOf("Res2")!=-1drawTextRelative(PriceOffsetnPrice+Lv2nPrice+Lv2Color.greennullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_K");  
        if(
    plotPrice.indexOf("Res3")!=-1drawTextRelative(PriceOffsetnPrice+Lv3nPrice+Lv3Color.rednullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_L");  
        if(
    plotPrice.indexOf("Res4")!=-1drawTextRelative(PriceOffsetnPrice+Lv4nPrice+Lv4Color.rednullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_M");  
        if(
    plotPrice.indexOf("Sup1")!=-1drawTextRelative(PriceOffsetnPrice-Lv1nPrice-Lv1Color.maroonnullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_N");  
        if(
    plotPrice.indexOf("Sup2")!=-1drawTextRelative(PriceOffsetnPrice-Lv2nPrice-Lv2Color.greennullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_O");  
        if(
    plotPrice.indexOf("Sup3")!=-1drawTextRelative(PriceOffsetnPrice-Lv3nPrice-Lv3Color.rednullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_P");  
        if(
    plotPrice.indexOf("Sup4")!=-1drawTextRelative(PriceOffsetnPrice-Lv4nPrice-Lv4Color.rednullText.BOLD Text.LEFT Text.VCENTERnull10"TimeP_Q");  

        
        if (
    getCurrentBarIndex() == 0) return
        
        var 
    nPosSize Strategy.getPositionSize();
       
        if(
    EndTime CloseAllTime) return; 
        

    // Daily Variable Reset and follow on if overnight
     
        
    if (day(0)!= day(-1)) {
            
            if (
    Strategy.isInTrade()) {
            
                
    bYLong1 bLong1;  
                
    bYLong2 bLong2;  
                
    bYLong3 bLong3;  
                
    bYLong4 bLong4;  
                
    bYShort1 bShort1;  
                
    bYShort2 bShort2;  
                
    bYShort3 bShort3;  
                
    bYShort4 bShort4;
                
    nYPrice nPrice;

            }
        
            
    bLong1 false;  
            
    bLong2 false;  
            
    bLong3 false;  
            
    bLong4 false;  
            
    bShort1 false;  
            
    bShort2 false;  
            
    bShort3 false;  
            
    bShort4 false
       
            
    bExitFlag false;
            
    bInit false;
             
        }

        if((
    hour(0)*100)+minute(0)< StartTime)  return;
        
        
    //Overnight exit logic
         
    if(OvernightLogic){
         
            if (
    Strategy.isShort() == true)
            
    //if (bYShort1 == true || bYShort2 == true || bYShort3 == true || bYShort4 == true)    
                
    {  
                  
                    if (
    bYShort1 == true && bYShort2 == false && bYShort3 == false && bYShort4 == false)  
                    {  
                      
                        if (
    low(0)< nYPrice
                        {  
                            
    nOExitPrice nYPrice;  
                            
    Strategy.doCover("Overnight Exit S1 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnOExitPrice);  
                            
    drawShape(Shape.CIRCLEBelowBar2Color.green);
                            
    bYShort1 false;  bYShort2 falsebYShort3 falsebYShort4 false
                        }  
                    } 
                    if (
    bYShort1 == true && bYShort2 == true && bYShort3 == false && bYShort4 == false)  
                    {  
                              
                        if (
    low(0)< nYPrice+Lv1)  
                        {  
                            
    nOExitPrice nYPrice+Lv1;  
                            
    Strategy.doCover("Overnight Exit S2 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnOExitPrice);  
                            
    drawShape(Shape.CIRCLEBelowBar2Color.green); 
                            
    bYShort1 false;  bYShort2 falsebYShort3 falsebYShort4 false
                        }  
                    } 
                    if (
    bYShort1 == true && bYShort2 == true && bYShort3 == true && bYShort4 == false)  
                    {  
                            
                        if (
    low(0)< nYPrice+Lv2)  
                        {  
                            
    nOExitPrice nYPrice+Lv2;  
                            
    Strategy.doCover("Overnight Exit S3 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnOExitPrice);  
                            
    drawShape(Shape.CIRCLEBelowBar2Color.green); 
                            
    bYShort1 false;  bYShort2 falsebYShort3 falsebYShort4 false;  
                        }  
                    } 
                    if (
    bYShort1 == true && bYShort2 == true && bYShort3 == true && bYShort4 == true)  
                    {  
                            
                        if (
    low(0)< nYPrice+Lv3)  
                        {  
                            
    nOExitPrice nYPrice+Lv3;  
                            
    Strategy.doCover("Overnight Exit S4 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnOExitPrice);  
                            
    drawShape(Shape.CIRCLEBelowBar2Color.green);  
                            
    bYShort1 false;  bYShort2 falsebYShort3 falsebYShort4 false;  
                        }  
                    }  
                }  else if (
    Strategy.isLong() == true)
                    
    //else if (bYLong1 == true || bYLong2 == true || bYLong3 == true || bYLong4 == true)
                
    {  
                        
                    if (
    bYLong1 == true && bYLong2 == false && bYLong3 == false && bYLong4 == false)  
                    {  
                              
                        if (
    high(0)> nYPrice)  
                        {  
                            
    nOExitPrice nYPrice;  
                            
    Strategy.doSell("Overnight Exit L1 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnOExitPrice);  
                            
    drawShape(Shape.CIRCLEAboveBar2Color.green); 
                            
    bYLong1 falsebYLong2 falsebYLong3 falsebYLong4 false
                        }  
                    } 
                    if (
    bYLong1 == true && bYLong2 == true && bYLong3 == false && bYLong4 == false)  
                    {  
                            
                        if (
    high(0)> nYPrice-Lv1)  
                        {  
                            
    nOExitPrice nYPrice-Lv1;  
                            
    Strategy.doSell("Overnight Exit L2 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnOExitPrice);  
                            
    drawShape(Shape.CIRCLEAboveBar2Color.green); 
                            
    bYLong1 falsebYLong2 falsebYLong3 falsebYLong4 false;  
                        }  
                    }  
                    if (
    bYLong1 == true && bYLong2 == true && bYLong3 == true && bYLong4 == false)  
                    {  
                            
                        if (
    high(0)> nYPrice-Lv2)  
                        {  
                            
    nOExitPrice nYPrice-Lv2;  
                            
    Strategy.doSell("Overnight Exit L3 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnOExitPrice);  
                            
    drawShape(Shape.CIRCLEAboveBar2Color.green); 
                            
    bYLong1 falsebYLong2 falsebYLong3 falsebYLong4 false;
                        }  
                    } 
                    if (
    bYLong1 == true && bYLong2 == true && bYLong3 == true && bYLong4 == true)  
                    {  
                            
                        if (
    high(0)> nYPrice-Lv3)  
                        {  
                            
    nOExitPrice nYPrice-Lv3;  
                            
    Strategy.doSell("Overnight Exit L4 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnOExitPrice);  
                            
    drawShape(Shape.CIRCLEAboveBar2Color.green); 
                            
    bYLong1 falsebYLong2 falsebYLong3 falsebYLong4 false
                        }  
                   }  
                
            }

    Last edited by ferret; 10-28-2013, 09:52 AM.

    Comment


    • #47
      PHP Code:

      //STRATEGY 
          
          
      if((hour(0)*100)+minute(0)> EndTime) return;

      //Exit Signals  
          
      if (Strategy.isInTrade() == true)  
          {  
            
              if (
      Strategy.isShort() == true)  
              {  
                    
                  if (
      bShort1 == true && bShort2 == false && bShort3 == false && bShort4 == false)  
                  {  
                        
                      if (
      low(0)< nPrice)  
                      {  
                          
      nExitPrice nPrice;  
                          
      Strategy.doCover("Cover Short1 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);  
                          
      drawShape(Shape.DIAMONDBelowBar2Color.green);
                          
      bShort1 false
                          
      bYShort1 false;  bYShort2 falsebYShort3 falsebYShort4 false;
                          
      bYLong1 falsebYLong2 falsebYLong3 falsebYLong4 false
                      }  
                  } 
                  if (
      bShort1 == true && bShort2 == true && bShort3 == false && bShort4 == false)  
                  {  
                        
                      if (
      low(0)< nPrice+Lv1)  
                      {  
                          
      nExitPrice nPrice+Lv1;  
                          
      Strategy.doCover("Cover Short2 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);  
                          
      drawShape(Shape.DIAMONDBelowBar2Color.green); 
                          
      bShort2 false
                          
      bYShort1 false;  bYShort2 falsebYShort3 falsebYShort4 false;
                          
      bYLong1 falsebYLong2 falsebYLong3 falsebYLong4 false;  
                      }  
                  } 
                  if (
      bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == false)  
                  {  
                        
                      if (
      low(0)< nPrice+Lv2)  
                      {  
                          
      nExitPrice nPrice+Lv2;  
                          
      Strategy.doCover("Cover Short3 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);  
                          
      drawShape(Shape.DIAMONDBelowBar2Color.green); 
                          
      bShort3 false
                          
      bYShort1 false;  bYShort2 falsebYShort3 falsebYShort4 false;
                          
      bYLong1 falsebYLong2 falsebYLong3 falsebYLong4 false;  
                      }  
                  } 
                  if (
      bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == true)  
                  {  
                        
                      if (
      low(0)< nPrice+Lv3)  
                      {  
                          
      nExitPrice nPrice+Lv3;  
                          
      Strategy.doCover("Cover Short4 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);  
                          
      drawShape(Shape.DIAMONDBelowBar2Color.green);  
                          
      bShort4 false
                          
      bYShort1 false;  bYShort2 falsebYShort3 falsebYShort4 false;
                          
      bYLong1 falsebYLong2 falsebYLong3 falsebYLong4 false
                      }  
                  }  
              }  else if (
      Strategy.isLong() == true)  
              {  
                    
                  if (
      bLong1 == true && bLong2 == false && bLong3 == false && bLong4 == false)  
                  {  
                        
                      if (
      high(0)> nPrice)  
                      {  
                          
      nExitPrice nPrice;  
                          
      Strategy.doSell("Sell Long1 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);  
                          
      drawShape(Shape.DIAMONDAboveBar2Color.green); 
                          
      bLong1 false;  
                          
      bYShort1 false;  bYShort2 falsebYShort3 falsebYShort4 false;
                          
      bYLong1 falsebYLong2 falsebYLong3 falsebYLong4 false
                      }  
                  } 
                  if (
      bLong1 == true && bLong2 == true && bLong3 == false && bLong4 == false)  
                  {  
                        
                      if (
      high(0)> nPrice-Lv1)  
                      {  
                          
      nExitPrice nPrice-Lv1;  
                          
      Strategy.doSell("Sell Long2 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);  
                          
      drawShape(Shape.DIAMONDAboveBar2Color.green); 
                          
      bLong2 false
                          
      bYShort1 false;  bYShort2 falsebYShort3 falsebYShort4 false;
                          
      bYLong1 falsebYLong2 falsebYLong3 falsebYLong4 false
                      }  
                  } 
                  if (
      bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == false)  
                  {  
                        
                      if (
      high(0)> nPrice-Lv2)  
                      {  
                          
      nExitPrice nPrice-Lv2;  
                          
      Strategy.doSell("Sell Long3 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);  
                          
      drawShape(Shape.DIAMONDAboveBar2Color.green); 
                          
      bLong3 false
                          
      bYShort1 false;  bYShort2 falsebYShort3 falsebYShort4 false;
                          
      bYLong1 falsebYLong2 falsebYLong3 falsebYLong4 false
                      }  
                  } 
                  if (
      bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == true)  
                  {  
                        
                      if (
      high(0)> nPrice-Lv3)  
                      {  
                          
      nExitPrice nPrice-Lv3;  
                          
      Strategy.doSell("Sell Long4 Signal"Strategy.LIMITStrategy.THISBARStrategy.ALLnExitPrice);  
                          
      drawShape(Shape.DIAMONDAboveBar2Color.green); 
                          
      bLong4 false
                          
      bYShort1 false;  bYShort2 falsebYShort3 falsebYShort4 false;
                          
      bYLong1 falsebYLong2 falsebYLong3 falsebYLong4 false
                      }  
                  }  
              }  
          } 


      // Entry Short Signals  

          
      if (nPosSize > -MaxClip && bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false)  
          {  
              if (
      high(0)> nPrice+Lv1)  
              {  
                  
      nEntryPrice nPrice+Lv1;  
                  
      Strategy.doShort("Entry Short1 Signal"Strategy.LIMITStrategy.THISBARTrdSz1nEntryPrice);  
                  
      drawShape(Shape.DOWNARROWAboveBar2Color.red);  
                  
      bShort1 true;
                  
      bYShort1 false;  bYShort2 falsebYShort3 falsebYShort4 false;
                  
      bYLong1 falsebYLong2 falsebYLong3 falsebYLong4 false;   
              } 
          } 
          if (
      nPosSize > -MaxClip && bShort1 == true && bShort2 == false && bShort3 == false && bShort4 == false)  
          {  
              if (
      high(0)> nPrice+Lv2)  
              {  
                  
      nEntryPrice nPrice+Lv2;  
                  
      Strategy.doShort("Entry Short2 Signal"Strategy.LIMITStrategy.THISBARTrdSz2nEntryPrice);  
                  
      drawShape(Shape.DOWNARROWAboveBar2Color.red);  
                  
      bShort2 true;  
              }  
          } 
          if (
      nPosSize > -MaxClip && bShort1 == true && bShort2 == true && bShort3 == false && bShort4 == false)  
          {  
              if (
      high(0)> nPrice+Lv3)  
              {  
                  
      nEntryPrice nPrice+Lv3;  
                  
      Strategy.doShort("Entry Short3 Signal"Strategy.LIMITStrategy.THISBARTrdSz3nEntryPrice);  
                  
      drawShape(Shape.DOWNARROWAboveBar2Color.red);  
                  
      bShort3 true;  
              }  
          } 
          if (
      nPosSize > -MaxClip && bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == false)  
          {  
              if (
      high(0)> nPrice+Lv4)  
              {  
                  
      nEntryPrice nPrice+Lv4;  
                  
      Strategy.doShort("Entry Short4 Signal"Strategy.LIMITStrategy.THISBARTrdSz4nEntryPrice);  
                  
      drawShape(Shape.DOWNARROWAboveBar2Color.red);  
                  
      bShort4 true;     
              }  
          } 
          
      //Entry Long Signals  
           
          
      if (nPosSize MaxClip && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false)  
          {  
              if (
      low(0)< nPrice-Lv1)  
              {  
                  
      nEntryPrice nPrice-Lv1;  
                  
      Strategy.doLong("Entry Long1 Signal"Strategy.LIMITStrategy.THISBARTrdSz1nEntryPrice);  
                  
      drawShape(Shape.UPARROWBelowBar2Color.blue);  
                  
      bLong1 true;
                  
      bYShort1 false;  bYShort2 falsebYShort3 falsebYShort4 false;
                  
      bYLong1 falsebYLong2 falsebYLong3 falsebYLong4 false;   
              }  
          } 
          if (
      nPosSize MaxClip && bLong1 == true && bLong2 == false && bLong3 == false && bLong4 == false)  
          {  
              if (
      low(0)< nPrice-Lv2)  
              {  
                  
      nEntryPrice nPrice-Lv2;  
                  
      Strategy.doLong("Entry Long2 Signal"Strategy.LIMITStrategy.THISBARTrdSz2nEntryPrice);  
                  
      drawShape(Shape.UPARROWBelowBar2Color.blue);  
                  
      bLong2 true;  
              }  
          } 
          if (
      nPosSize MaxClip && bLong1 == true && bLong2 == true && bLong3 == false && bLong4 == false)  
          {  
              if (
      low(0)< nPrice-Lv3)  
              {  
                  
      nEntryPrice nPrice-Lv3;  
                  
      Strategy.doLong("Entry Long3 Signal"Strategy.LIMITStrategy.THISBARTrdSz3nEntryPrice);  
                  
      drawShape(Shape.UPARROWBelowBar2Color.blue);  
                  
      bLong3 true;  
              }  
          } 
          if (
      nPosSize MaxClip && bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == false)  
          {  
              if (
      low(0)< nPrice-Lv4)  
              {  
                  
      nEntryPrice nPrice-Lv4;  
                  
      Strategy.doLong("Entry Long4 Signal"Strategy.LIMITStrategy.THISBARTrdSz4nEntryPrice);  
                  
      drawShape(Shape.UPARROWBelowBar2Color.blue);  
                  
      bLong4 true;  
              }  
          } 
      }   
          

                
        
      var 
      grID 0;  
      function 
      gID()  
      {  
          
      grID ++;  
          return( 
      grID );  

      Last edited by ferret; 10-28-2013, 09:53 AM.

      Comment


      • #48
        If you run the script tonight on the same chart as I did (ES Z3, 30 day dynamic time template and 5 min interval) you should see what I did.

        I isolated each conditional within the if(OvernightLogic){} block until the backtest error was generated, then I modified the limit price in the Strategy.doSell function and found that the limit price in the Strategy.doSell causes a backtest report error if it is equal or less than the high of the bar that triggered the conditional.

        See attached script with my comments. Ferret20131028.efs

        The problem is that I don't know why it does that and it may well be a bug in the backtest report so consider reporting it.

        Wayne

        Comment


        • #49
          Yep thanks Wayne, all understood!

          Ive ended up changing the "nOExitPrice" variable to "= low(0) - 0.01;" for the isShort exits and "nOExitPrice = high(0) + 0.01;" for the long position exits. Obviously this isnt ideal as the prices recorded will give a better price than what is available in reality, but it is a compromise Im happy to live with, and at least it is getting the backtest reports to show!

          Interestingly, I first tried to set the variable to "nOExitPrice = high(0) + 0.01;" for the short position exit and vice versa, which would give a pessimistic back test result, but this still didn't solve the back test error.

          Thanks again!!

          Daniel

          Comment


          • #50
            Unfortunately, on further inspection, this has only solved half of the issue. The back test report now shows, but the exit trades under the "Overnight Logic" do not appear in the back test report even though they appear on the charts! I have also forwarded the thread to the development team to see if they can shed any light on the issue.

            Thanks again

            Comment


            • #51
              Turns out its an issue with eSignal v.11. The back test report works fine in 10.6 even with the original exit prices in the overnight logic.

              Daniel

              Comment


              • #52
                Hi Wayne,

                Sorry I have what I think is a pretty simple question for you, but I cant seem to get my head around it!

                I have tried to add a Start Date and an End Date into the code, so that I can run the back test between a user specified date range. I have added a StartDate and an EndDate function parameter to the preMain so that I can edit the date range easily during the back testing. My idea was to then add a line similar to the "if((hour(0)*100)+minute(0)< StartTime) return;" line and use "if(day(0) + month(0) + year(0) < StartDate) return;" instead. I quickly realised this wouldn't work as it is not just a simple addition of the corresponding parts. Ive looked at some other posts on here, and tried using the getDate() function, and also tried creating day/month variables using the getDay/getMonth functions etc but with no success. I cant seem to get my head around how I would format the user specified date in the function parameter and then use a formula in the code to isolate the date range in between these two user specified dates.

                Thanks in advance

                Daniel

                Comment


                • #53
                  Hi,

                  There are several ways. One is:
                  PHP Code:
                  debugClear();
                  function 
                  preMain() {
                      
                  setPriceStudy(true);
                      var 
                  aFPArray = new Array();
                      var 
                  0;
                      
                  aFPArray[x] = new FunctionParameter("StartDate"FunctionParameter.NUMBER);
                      
                  with(aFPArray[x++]) {
                          
                  setName("Start Date (yyyymmdd)");
                         
                  setDefault(20130909);
                      }
                      
                  aFPArray[x] = new FunctionParameter("EndDate"FunctionParameter.NUMBER);
                      
                  with(aFPArray[x++]) {
                          
                  setName("End Date (yyyymmdd)");
                          
                  setDefault(20131106);
                      }
                  }
                  function 
                  main(StartDate,EndDate){
                      var 
                  bar_YYYYMMDD_Date = ((year(0)*100)+month(0))*100+day(0);
                      
                  //if(StartDate == bar_YYYYMMDD_Date) debugPrintln("18: "+bar_YYYYMMDD_Date);
                      //if(EndDate == bar_YYYYMMDD_Date) debugPrintln("19: "+bar_YYYYMMDD_Date);
                      
                  if(bar_YYYYMMDD_Date>=StartDate && EndDate >= bar_YYYYMMDD_Date){
                          
                  setBarBgColor(Color.RGB(230,255,207));
                      }

                  Or using your example:

                  PHP Code:
                  debugClear();
                  function 
                  preMain() {
                      
                  setPriceStudy(true);
                      var 
                  aFPArray = new Array();
                      var 
                  0;
                      
                  aFPArray[x] = new FunctionParameter("StartDate"FunctionParameter.NUMBER);
                      
                  with(aFPArray[x++]) {
                          
                  setName("Start Date (yyyymmdd)");
                         
                  setDefault(20130909);
                      }
                      
                  aFPArray[x] = new FunctionParameter("EndDate"FunctionParameter.NUMBER);
                      
                  with(aFPArray[x++]) {
                          
                  setName("End Date (yyyymmdd)");
                          
                  setDefault(20131106);
                      }
                  }
                  function 
                  main(StartDate,EndDate){
                      var 
                  bar_YYYYMMDD_Date = ((year(0)*100)+month(0))*100+day(0);
                      if(
                  StartDate>bar_YYYYMMDD_Date || bar_YYYYMMDD_Date>EndDate) return;
                      
                  setBarBgColor(Color.RGB(230,255,207));


                  Test for the best placement of this return statement, likely right after "function main()" also account for when/if your are in a trade when the "EndDate" arrives.

                  Wayne
                  Last edited by waynecd; 11-07-2013, 01:31 PM.

                  Comment


                  • #54
                    Hi Wayne,

                    Now that the code is all pretty much finished, I would like to be able to apply it to all of my desired markets. With this in mind, I would like to be able to edit the symbols referred to in the code in the "Edit chart" function, rather than having to edit the script itself. Is it possible to use a variable within the "sym" function? I have tried to create a functionParam (named "Market1") which would be a string (for example "ES Z3") and then reference this in the sym function ie: var X = close(-1,sym("Market1,D"));

                    This doesnt seem to work as it is, and I can seem to find any suggestions on the forum. Is there another way to do this?

                    Thanks again!

                    Daniel

                    Comment


                    • #55
                      Hi,

                      var X = close(-1,sym("Market1,D"));
                      The above code places the Market1 variable inside quotes making it a string so the efs engine does not evaluate the variable as a variable.
                      The correct syntax for that would be
                      PHP Code:
                      var close(-1,sym(Market1+",D")); 
                      Here is a simple template:
                      PHP Code:
                      function preMain(){
                          var 
                      aFPArray = new Array();
                          var 
                      0;
                          
                      aFPArray[x] = new FunctionParameter("Symbol"FunctionParameter.STRING);
                          
                      with(aFPArray[x++]) {
                              
                      setName("Symbol");
                              
                      setDefault();//Don't use quotes when entering the symbol
                          
                      }
                          
                      aFPArray[x] = new FunctionParameter("Interval"FunctionParameter.STRING);
                          
                      with(aFPArray[x++]) {
                              
                      setName("Interval");
                              
                      setDefault();//Don't use quotes when entering the interval
                          
                      }
                      }
                      var 
                      bInit false;
                      var 
                      study1;
                      function 
                      main(Symbol,Interval){
                          if (!
                      bInit){
                              var 
                      vSymbol;//declare this variable as global (instead of here as local) if it will be used outside of the bInit block or main
                              
                      if (Symbol == nullSymbol getSymbol();
                              if (
                      Interval == nullInterval getInterval();
                              
                      vSymbol Symbol "," Interval;
                              
                      study1=sma(10,sym(vSymbol));
                              
                      bInit true;
                          }
                          return 
                      study1.getValue(0);

                      Wayne
                      Last edited by waynecd; 11-13-2013, 12:52 PM.

                      Comment

                      Working...
                      X