Announcement

Collapse
No announcement yet.

2012 June: Trading High Yield Bonds Using ETFs by Brooke Gardner.

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 2012 June: Trading High Yield Bonds Using ETFs by Brooke Gardner.

    File Name: PriceMA.efs

    Description:
    Trading High Yield Bonds Using ETFs by Brooke Gardner.

    Formula Parameters:

    PriceMA.efs
    Price Source: Close
    MA Period: 8
    MA Type: Simple

    Notes:
    The related article is copyrighted material. If you are not a subscriber
    of Stocks & Commodities, please visit www.traders.com .

    Download File:
    PriceMA.efs

    PriceMA.efs


    EFS Code:

    PHP Code:
    /*********************************  
    Provided By:
          Interactive Data Corporation (Copyright © 2012)
          All rights reserved. This sample eSignal Formula Script (EFS)
          is for educational purposes only. Interactive Data Corporation
          reserves the right to modify and overwrite this EFS file with
          each new release.  
           
    Description:
          Trading High Yield Bonds Using ETFs by Brooke Gardner.

    Version:            1.0  5/04/2012    

    Formula Parameters:                     Default:
          Price Source                             Close
          MA Period                                 8
          MA Type                                   Simple         
      
    Notes:
          The related article is copyrighted material. If you are not
          a subscriber of Stocks & Commodities, please visit [url]www.traders.com.[/url]

    **********************************/    

    var fpArray = new Array();    

    function 
    preMain()  
    {
          
    setPriceStudy(true);
          
    setCursorLabelName("MA"0);
          var 
    x=0;    
          
    fpArray[x] = new FunctionParameter("priceSource"FunctionParameter.STRING);
          
    with(fpArray[x++])
          {
                  
    setName("Price Source");
                  
    addOption("Open");
                  
    addOption("Close");
                  
    addOption("Low");
                  
    addOption("High");
                  
    addOption("HL/2");
                  
    addOption("HLC/3");
                  
    addOption("OHLC/4");
                  
    setDefault("Close");
          }   
          
    fpArray[x] = new FunctionParameter("maPeriod"FunctionParameter.NUMBER);
          
    with(fpArray[x++])
          {
                  
    setName("MA Period");
                  
    setLowerLimit(1);
                  
    setDefault(8);
          }      
          
    fpArray[x] = new FunctionParameter("maType"FunctionParameter.STRING);
          
    with(fpArray[x++])
          {
                  
    setName("MA Type");
                  
    addOption("Simple");
                  
    addOption("Exponential");
                  
    addOption("Weighted");
                  
    addOption("Volume Weighted");
                  
    setDefault("Simple");
          }     
    }    

    var 
    bInit false;  
    var 
    bVersion null;     
    var 
    xSource null;  
    var 
    xMA null;    
    var 
    0;    

    function 
    main(priceSourcemaPeriodmaType)  
    {
          if (
    bVersion == nullbVersion verify();
          if (
    bVersion == false) return;
          
    // Back Testing formulas are not for real time analysis.
          // Therefore, prevent processing and exit at bar 0.
          
    if (getCurrentBarIndex() == 0) return;
          if (!
    bInit)
          {
                  switch (
    priceSource)
                  {
                         case 
    'Open':
                             
    xSource open();
                             break;
                         case 
    'Close':
                             
    xSource close();
                             break;
                         case 
    'High':
                             
    xSource high();
                             break;
                         case 
    'Low':
                             
    xSource low();
                             break;
                         case 
    'HL/2':
                             
    xSource hl2();
                             break;
                         case 
    'HLC/3':
                             
    xSource hlc3();
                             break;
                         case 
    'OHLC/4'
                             
    xSource ohlc4();
                             break;
                         default : 
    xSource close();
                  }
                  switch (
    maType)
                  {
                         case 
    "Simple" :
                             
    xMA sma(maPeriodxSource);
                             break;
                         case 
    "Exponential" :
                             
    xMA ema(maPeriodxSource);
                             break;
                         case 
    "Weighted" :
                             
    xMA wma(maPeriodxSource);
                             break;
                         case 
    "Volume Weighted" :
                             
    xMA vwma(maPeriodxSource);
                             break;
                         default : 
    xMA sma(maPeriodxSource);
                  }
                  
    bInit true;
          }
          var 
    nPrice xSource.getValue(0);
          var 
    vMA xMA.getValue(0);

          
    // Exit Strategy
          
    if (Strategy.isInTrade())
          {
               if (
    Strategy.isLong() && nPrice vMA)
              {
                  
    Strategy.doSell("Long Exit Signal"Strategy.CLOSEStrategy.THISBAR);
              }
               else if (
    Strategy.isShort() && nPrice vMA)
              {
                  
    Strategy.doCover("Short Exit Signal"Strategy.CLOSEStrategy.THISBAR);
              }
          }

          
    // Entry Strategy
          
    if (!Strategy.isInTrade())
          {
               if (
    nPrice vMA)
              {
                  
    Strategy.doLong("Long signal"Strategy.CLOSEStrategy.THISBAR);
                  
    drawShape(Shape.UPARROWAboveBar1Color.limei++);
              }
              else if (
    nPrice vMA)
              {
                  
    Strategy.doShort("Short signal"Strategy.CLOSEStrategy.THISBAR);
                  
    drawShape(Shape.DOWNARROWBelowBar1Color.redi++);
              }
          }

          return 
    xMA.getValue(0);  
    }    

    // verify version  
    function verify() {
          var 
    false;
          if (
    getBuildNumber() < 779) {
              
    drawTextAbsolute(535"This study requires version 8.0 or later.",
                   
    Color.whiteColor.blueText.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
                   
    null13"error");
              
    drawTextAbsolute(520"Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp",
                   
    Color.whiteColor.blueText.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
                   
    null13"upgrade");
              return 
    b;
          } else {
              
    true;
          }
          return 
    b;  

    Last edited by eSignal; 05-14-2012, 07:15 AM.
Working...
X