Board logo

标题: [eSIGNAL] StiffnessIndicator指标[eSIGNAL] [打印本页]

作者: 龙听    时间: 2018-11-27 16:49     标题: StiffnessIndicator指标[eSIGNAL]

For this month’s Traders’ Tip, we’ve provided the StiffnessIndicator.efs study based on the article by Markos Katsanos in this issue, “The Stiffness Indicator.” This study attempts to determine if markets are in a strong price trend.

The study contains formula parameters that may be configured through the edit chart window (right-click on the chart and select “edit chart”). A sample chart is shown in Figure 2.

[attach]5571[/attach]
作者: 龙听    时间: 2018-11-27 16:50

  1. /*********************************
  2. Provided By:  
  3. eSignal (Copyright c eSignal), a division of Interactive Data
  4. Corporation. 2016. All rights reserved. This sample eSignal
  5. Formula Script (EFS) is for educational purposes only and may be
  6. modified and saved under a new file name.  eSignal is not responsible
  7. for the functionality once modified.  eSignal reserves the right
  8. to modify and overwrite this EFS file with each new release.

  9. Description:        
  10.     The Stiffness Indicator by Markos Katsanos
  11.    

  12. Version:            1.00  9/14/2018

  13. Formula Parameters:                     Default:
  14. Period                                  60
  15. MA DAYS                                 100
  16. STIFFNESS CRITICAl                      90

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

  20. **********************************/

  21. var fpArray = new Array();

  22. function preMain(){
  23.     setPriceStudy(false);
  24.     setStudyTitle("Stiffness Indicator");
  25.     setCursorLabelName("STIFFNESS");
  26.     setPlotType(PLOTTYPE_HISTOGRAM);
  27.    
  28.     var x = 0;
  29.     fpArray[x] = new FunctionParameter("Period", FunctionParameter.NUMBER);
  30.         with(fpArray[x++]){
  31.         setName("STIFFNESS PERIOD");
  32.         setLowerLimit(1);
  33.         setDefault(60);
  34.         
  35.     }

  36.     fpArray[x] = new FunctionParameter("MAB", FunctionParameter.NUMBER);
  37.         with(fpArray[x++]){
  38.         setName("MA DAYS");
  39.         setLowerLimit(1);
  40.         setDefault(100);
  41.       
  42.     }
  43.     fpArray[x] = new FunctionParameter("STIFFCRIT", FunctionParameter.NUMBER);
  44.         with(fpArray[x++]){
  45.         setName("STIFFNESS CRITICAl");
  46.         setLowerLimit(1);
  47.         setDefault(90);
  48.         
  49.     }
  50. }

  51. var bInit = false;
  52. var bVersion = null;
  53. var xClose = null;
  54. var xMA2 = null;
  55. var nEntryPrice = null;
  56. var xLow = null;
  57. var xHigh = null;
  58. var vStopPrice = null;
  59. var bIsLong = null;
  60. var xCloseSPY = null;
  61. var xEMA = null;
  62. var xStiffness = null;
  63. var bWasLong = false;


  64. function main(Period, MAB, STIFFCRIT){
  65.     if (bVersion == null) bVersion = verify();
  66.     if (bVersion == false) return;
  67.         
  68.     if (getBarState() == BARSTATE_ALLBARS){
  69.         bInit = false;
  70.         bIsLong = false;
  71.     }

  72.     if (getCurrentBarCount() < Period) return;
  73.    
  74.     if (!bInit){
  75.         
  76.         xCloseSPY = close("SPY");
  77.         xClose = close();
  78.         xHigh = high();
  79.         xLow = low();
  80.         bIsLong = false;
  81.         bWasLong = false;
  82.             
  83.         xMA2 = efsInternal("Calc_MA2", xClose, MAB);
  84.         xEMA = efsInternal("Calc_Ema", xCloseSPY, MAB);
  85.         xStiffness = efsInternal("Calc_Stif", xClose, Period, xMA2);
  86.         
  87.         addBand(STIFFCRIT, PS_DASH, 1, Color.grey, 2);
  88.         
  89.         bInit = true;
  90.     }

  91.    
  92.     if (getBarState() == BARSTATE_NEWBAR && xStiffness.getValue(-1) != null)  {   
  93.          if ((xStiffness.getValue(0)<= STIFFCRIT) && bIsLong){      
  94.             
  95.             if (xStiffness.getValue(-1) > STIFFCRIT){
  96.                 drawTextRelative(0, TopRow1, "\u00EA", Color.red, null, Text.PRESET|Text.CENTER, "Wingdings", 10, "Exit"+rawtime(0));
  97.                 bIsLong = false;                    
  98.             }
  99.             else {
  100.                 removeText("Long"+rawtime(0));
  101.                 removeText("Text"+rawtime(0));
  102.             }
  103.             bIsLong = false;
  104.         }
  105.    
  106.         if (xEMA.getValue(0) >= xEMA.getValue(-2) && !bIsLong && (xStiffness.getValue(-1) < STIFFCRIT)){                  
  107.             
  108.             if ((xStiffness.getValue(1) > STIFFCRIT)){
  109.                  
  110.                 drawTextRelative(0, TopRow1, "\u00E9", Color.green, null, Text.PRESET|Text.CENTER, "Wingdings", 10, "Long"+rawtime(0));
  111.                 bIsLong = true;
  112.                 bWasLong = true;
  113.             }      
  114.             else {
  115.                 removeText("Exit"+rawtime(0));
  116.                 removeText("TextExit"+rawtime(0));
  117.                 if (bWasLong)
  118.                     bIsLong = true;
  119.                     
  120.             }
  121.         }
  122.     }
  123.     return (xStiffness.getValue(0))
  124. }

  125. var P = null;

  126. function Calc_Stif (xClose, Period, xMA2){
  127.     if (xClose.getValue(-Period) == null || xMA2.getValue(-Period) == null) return;
  128.    
  129.     P = 0;
  130.     for (var i = 0; i < Period; i++) {
  131.         
  132.         if (xClose.getValue(-i) > xMA2.getValue(-i)) P++;
  133.     }
  134.     return (P * 100 / Period);
  135. }

  136. function Calc_MA2(xClose, MAB){   
  137.     if (xClose.getValue(-MAB) == null) return;
  138.     return (sma(MAB) - 0.2 * stdDev(MAB));
  139. }

  140. function Calc_Ema(xCloseSPY, MAB){
  141.     if (xCloseSPY.getValue(-MAB) == null) return;
  142.     return ema(MAB, sym("SPY," + getInterval()));
  143. }

  144. function verify(){
  145.     var b = false;
  146.     if (getBuildNumber() < 3756){
  147.         
  148.         drawTextAbsolute(5, 35, "This study requires version 10.6 or later.",
  149.             Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
  150.             null, 13, "error");
  151.         drawTextAbsolute(5, 20, "Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp",
  152.             Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
  153.             null, 13, "upgrade");
  154.         return b;
  155.     }
  156.     else
  157.         b = true;
  158.    
  159.     return b;
  160. }
复制代码

微信截图_20181127164344.png

图片附件: 微信截图_20181127164344.png (2018-11-27 16:45, 70.73 KB) / 下载次数 78
http://www.qhlt.cn/attachment.php?aid=5571&k=b95e23b2c8f2f2c9f5c51d47db8686d9&t=1714553161&sid=B30442






欢迎光临 龙听期货论坛 (http://www.qhlt.cn/) Powered by Discuz! 7.2