|
本帖最後由 joshsmi 於 15-2-2 00:44 編輯
Guys, what's all that easy language junk gotta do with AB?
MA calculation using loop compared to built-in MA
- function cMA( array, maperiod ) {
- // set null values at the beginning of the array
- for ( i = 0; i < maPeriod - 1 && i < BarCount; i++ )
- myMa[i] = Null;
- // calculate the average for each bar
- for ( i = maPeriod - 1; i < BarCount; i++ ) {
- // clear temporary result
- tempSum = 0;
- // inner loop to sum bar data
- for ( j = 0; j < maPeriod; j++ )
- tempSum += array[i - j];
- // save calculated value to result array element
- myMa[i] = tempSum / maPeriod;
- }
- // returning result
- return myMa;
- }
- P = ParamField( "Price field", -1 );
- Periods = Param( "Periods", 15, 2, 1000, 1, 10 );
- Plot( cMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
- Plot( MA( P, Periods ), "Built-in MA", ColorRed, styleLine );
複製代碼
|
|