我计算了时间段的简单移动平均线和平滑移动平均线。但如果鳄鱼计算了SMMA(MEDEAN PRICE,期间,班次),我如何为平滑移动平均线添加移位?
HTML代码
<div class="form-inline">
<div class="">
<h5> Jaws </h5>
<div class="form-group modal_vin cls-setng-menu">
<p> Period </p>
<input type="text" class="form-control modal_vin txtbox1" id="jaws_period" name="jaws_period" value="13">
</div>
<div class="form-group modal_vin cls-setng-menu">
<p> Shift </p>
<input type="text" class="form-control modal_vin txtbox1" id="jaws_shift" name="jaws_shift" value="8">
</div>
<div class="form-group modal_vin">
<p> Color </p>
<a class="btn btn-danger btn-select vin-chn-bns" style="background-color: #e74c3c !important" id="jaws_a_color">
<input type="hidden" class="btn-select-input" id="" name="" value="" />
<span class="btn-select-value" style="background-color: #e74c3c !important;padding: 0px !important" id="jaws_color"></span><span class='btn-select-arrow glyphicon glyphicon-chevron-down'></span>
<ul class="dropdown-vin-color" style="position:absolute;top:134%">
<li class="selected" style="background-color: rgb(241, 196, 15) ! important;padding:15px;" onclick="change_jaws_color('f1c40f')"></li>
<li style="background-color: rgb(230, 126, 34) ! important;padding:15px;" onclick="change_jaws_color('e67e22')"></li>
<li style="background-color: rgb(231, 76, 60) ! important;padding:15px;" onclick="change_jaws_color('e74c3c')"></li>
<li style="background-color: rgb(211, 84, 0) ! important;padding:15px;" onclick="change_jaws_color('d35400')"></li>
<li style="background-color: rgb(41, 128, 185) ! important;padding:15px;" onclick="change_jaws_color('2980b9')"></li>
<li style="background-color: rgb(155, 89, 182) ! important;padding:15px;" onclick="change_jaws_color('9b59b6')"></li>
</ul>
</a>
</div>
<div class="form-group modal_vin">
<p> Width </p>
<a class="btn btn-danger btn-select vin-chn-bns">
<input type="hidden" class="btn-select-input" id="" name="" value="" />
<span class="btn-select-value" id="jaws_width">1px</span> <span class='btn-select-arrow glyphicon glyphicon-chevron-down'></span>
<ul class="dropdown-vin-color" style="position:absolute;top:134%">
<li class="selected">1px</li>
<li>2px</li>
<li>3px</li>
<li>4px</li>
<li>5px</li>
</ul>
</a>
</div>
</div>
<div class="">
<h5> Teeth </h5>
<div class="form-group modal_vin cls-setng-menu">
<p> Period </p>
<input type="text" class="form-control modal_vin txtbox1" id="teeth_period" name="teeth_period" value="8">
</div>
<div class="form-group modal_vin cls-setng-menu">
<p> Shift </p>
<input type="text" class="form-control modal_vin txtbox1" id="teeth_shift" name="teeth_shift" value="5">
</div>
<div class="form-group modal_vin">
<p> Color </p>
<a class="btn btn-danger btn-select vin-chn-bns" style="background-color: #2980b9 !important" id="teeth_a_color">
<input type="hidden" class="btn-select-input" id="" name="" value="" />
<span class="btn-select-value" style="background-color: #2980b9 !important;padding: 0px !important" id="teeth_color"></span><span class='btn-select-arrow glyphicon glyphicon-chevron-down'></span>
<ul class="dropdown-vin-color" style="position:absolute;top:134%">
<li class="selected" style="background-color: rgb(241, 196, 15) ! important;padding:15px;" onclick="change_teeth_color('f1c40f')"></li>
<li style="background-color: rgb(230, 126, 34) ! important;padding:15px;" onclick="change_teeth_color('e67e22')"></li>
<li style="background-color: rgb(231, 76, 60) ! important;padding:15px;" onclick="change_teeth_color('e74c3c')"></li>
<li style="background-color: rgb(211, 84, 0) ! important;padding:15px;" onclick="change_teeth_color('d35400')"></li>
<li style="background-color: rgb(41, 128, 185) ! important;padding:15px;" onclick="change_teeth_color('2980b9')"></li>
<li style="background-color: rgb(155, 89, 182) ! important;padding:15px;" onclick="change_teeth_color('9b59b6')"></li>
</ul>
</a>
</div>
<div class="form-group modal_vin">
<p> Width </p>
<a class="btn btn-danger btn-select vin-chn-bns">
<input type="hidden" class="btn-select-input" id="" name="" value="" />
<span class="btn-select-value" id="teeth_width">1px</span> <span class='btn-select-arrow glyphicon glyphicon-chevron-down'></span>
<ul class="dropdown-vin-color" style="position:absolute;top:134%">
<li class="selected">1px</li>
<li>2px</li>
<li>3px</li>
<li>4px</li>
<li>5px</li>
</ul>
</a>
</div>
</div>
<div class="">
<h5> Lips </h5>
<div class="form-group modal_vin cls-setng-menu">
<p> Period </p>
<input type="text" class="form-control modal_vin txtbox1" id="lips_period" name="lips_period" value="5">
</div>
<div class="form-group modal_vin cls-setng-menu">
<p> Shift </p>
<input type="text" class="form-control modal_vin txtbox1" id="lips_shift" name="lips_shift" value="3">
</div>
<div class="form-group modal_vin">
<p> Color </p>
<a class="btn btn-danger btn-select vin-chn-bns" style="background-color: #9b59b6 !important" id="lips_a_color">
<input type="hidden" class="btn-select-input" id="" name="" value="" />
<span class="btn-select-value" style="background-color: #9b59b6 !important;padding: 0px !important" id="lips_color"></span><span class='btn-select-arrow glyphicon glyphicon-chevron-down'></span>
<ul class="dropdown-vin-color" style="position:absolute;top:134%">
<li class="selected" style="background-color: rgb(241, 196, 15) ! important;padding:15px;" onclick="change_lips_color('f1c40f')"></li>
<li style="background-color: rgb(230, 126, 34) ! important;padding:15px;" onclick="change_lips_color('e67e22')"></li>
<li style="background-color: rgb(231, 76, 60) ! important;padding:15px;" onclick="change_lips_color('e74c3c')"></li>
<li style="background-color: rgb(211, 84, 0) ! important;padding:15px;" onclick="change_lips_color('d35400')"></li>
<li style="background-color: rgb(41, 128, 185) ! important;padding:15px;" onclick="change_lips_color('2980b9')"></li>
<li style="background-color: rgb(155, 89, 182) ! important;padding:15px;" onclick="change_lips_color('9b59b6')"></li>
</ul>
</a>
</div>
<div class="form-group modal_vin">
<p> Width </p>
<a class="btn btn-danger btn-select vin-chn-bns">
<input type="hidden" class="btn-select-input" id="" name="" value="" />
<span class="btn-select-value" id="lips_width">1px</span> <span class='btn-select-arrow glyphicon glyphicon-chevron-down'></span>
<ul class="dropdown-vin-color" style="position:absolute;top:134%">
<li class="selected">1px</li>
<li>2px</li>
<li>3px</li>
<li>4px</li>
<li>5px</li>
</ul>
</a>
</div>
</div>
<div class="vin_footer text-center">
<button onclick="alligator()" data-dismiss="modal" aria-hidden="true" class="btn btn_footer" type="submit">Apply</button>
<button ng-click="onReset()" class="btn btn-gray btn2_footer">Reset</button>
<button ng-click="onCancel()" class="btn btn-gray btn2_footer">Cancel</button>
</div>
现在我已经尝试了仅使用周期而不使用移位值的平滑移动平均线。
Javascript代码
var chart = $("#tv_chart_container").highcharts();
var series = chart.series[0];
var jaws_data = [];
var sumForAverage = 0;
var EMA_previous_day = 0;
var SMMA = 0;
var price = 0;
var high,low;
var PREVSUM;
var jaws_mul = (2 / (jaws_period + 1) );
var teeth_mul = (2 / (teeth_period + 1) );
var lips_mul = (2 / (lips_mul + 1) );
var i;
for(i=0;i<series.data.length;i++) {
sumForAverage += series.data[i].y;
if(i<period) {
jaws_data.push(null);
}
else {
sumForAverage -= series.data[i-period].y;
if(SMMA == 0)
{
SMMA = sumForAverage/period;
}
else
{
high = chart.yAxis[0].dataMax;
low = chart.yAxis[0].dataMin;
price = (high + low)/2;
PREVSUM = SMMA *period;
SMMA = (PREVSUM-SMMA+price)/period;
}
jaws_data.push([series.data[i].x, SMMA]);
}
}
chart.addSeries({
name: 'Jaws',
linkedTo: 'primary',
showInLegend: true,
type: 'trendline',
algorithm: 'SMA',
periods: jaws_period,
lineWidth:jaws_width,
lineColor:jaws_color,
data:jaws_data
});
我想知道如何使用移位值来平滑移动平均线?