I have this RibbonsPlotter indicator from TS forum:
TS.com/Discussions/Topic.aspx?Topic_ID=89978&SearchTerm=RibbonsPlotter%20&txtExactMatch=&Page=1
I never had any problem using it with TS. But with Multicharts, it has this Error of Floating-point invalid operation.
Can someone please help? Thanks.
Code: Select all
{
Indicator: _RibbonsPlotter
Description: This Indictor plots various types of ribbons (multiple bands of deviation functions)
around a centerline reference function.
Provided By: Mark J. Krisburg (MarkSanDiego)
Updated: 02/18/07 original version
09/14/08 fixed offset
01/03/09 lower band function formula error correction
01/04/09 future projections added (FutureOffset = 1 or 2)
04/30/09 clean up and tighten code
05/29/09 add display of input parameters on chart
07/08/09 _BarsDisplayed function modified to minimize increase in MaxBarsBack
cause by back referencing to print chart labels after LastBarOnChart
reached.
07/10/09 WVAP added as to centerline functions
**************************************************************************************
{ Reference Function (Center line) May be: }
0-Zero axis
1-AMA (Arithmetic Average)
2-EMA (Exponential Moving Average
3-LR (Linear Regression)
4-Adaptive Moving Avg (Kaufman - KAMA)
5-T3 Triple Exponential Moving Average
6-JMA Juric Moving Average or
7-WVAP
8-Fixed Value
{ Deviation Function (Band or Ribbons) may be: }
1-Standard Deviation (Bollinger Bands)
2-Standard Error
3-ATR (Average True Range - Keltner Bands)
4 JMA True Range (ATR using Jurik Moving Avg)
5-Pct (Percentage)
6-Points
**************************************************************************************
}
[LegacyColorValue = true];
Inputs:
Price(low),
Smooth(0),
UpperBandsRef(TypicalPrice),
LowerBandsRef(TypicalPrice),
Offset(0),
RefID(3),
AMALength(15), { arithmetic moving average length }
EMALength(15), { exponential moving average length }
LRLength(15), { linear regression function length }
LRTgtBar(0), { linear regression function target bar }
KAMA_EffRatioLen(7), { Kaufman adaptive moving average parameters }
KAMA_FastLength(2), { Kaufman adaptive moving average parameters }
KAMA_SlowLength(25), { Kaufman adaptive moving average parameters }
T3Length(20),
JMALength(20),
JMAPhase(0),
VWAP("No Param RefID = 7"),
RefValue(0),
DevID(1), { deviation function identifier }
StdDevLength(15), { standard deviation length }
StdErrLength(15), { standard error length }
ATRLength(14), { average true range length }
JATRLength(14), { percentage }
Percent(1),
Pts(1),
NBands(3), { maximum 8 }
StartMult(1),
Increment(1),
AddMinus(0),
RoundToTradable(False),
PlotWidth(0),
ShowCenterLine(true),
DisplayParameters(true), { display chart parameters }
CLParamColor(yellow), { center line parameters display color }
DevParamColor(cyan), { deviation parameters display color }
CLVertPct(8), { vertical position in chart range percent for center line parameter display }
DevVertPct(3), { vertical position in chart range percent for deviation parameter display }
CLHorizPct(50), { horizontal position in percent for center line parameter display
[leftmost = zero %, rightmost = 100%] }
DevHorizPct(50); { horizontal position in percent for deviation parameter display
[leftmost = zero %, rightmost = 100%] }
Arrays:
UpperBand[9](0),
LowerBand[9](0),
RefParam[4](0), { reference function (center line) parameters }
DevParam[4](0); { deviation function (bands or ribbons) parameters }
Variables:
UpperCL(0),
LowerCL(0),
{ chart display parameters }
intrabarpersist string Text1("Center Line: "),
intrabarpersist string Text2(" Deviation: "),
intrabarpersist TextVertPct1(CLVertPct),
intrabarpersist TextVertPct2(DevVertPct),
intrabarpersist TextHorizPct1(CLHorizPct),
intrabarpersist TextHorizPct2(DevHorizPct),
intrabarpersist TextVert1(0),
intrabarpersist TextVert2(0),
intrabarpersist int TextOffset1(0),
intrabarpersist int TextOffset2(0),
intrabarpersist DisplayHigh(0),
intrabarpersist DisplayLow(0),
intrabarpersist DisplayRange(0),
intrabarpersist BarsDisplayed(0),
intrabarpersist TextID1(0),
intrabarpersist TextID2(0),
intrabarpersist RangePctAtOffset(0),
intrabarpersist TextLength1(0),
intrabarpersist TextLength2(0),
intrabarpersist TextMaxLength(0);
{ pack reference and deviation function parameters into arrays }
Once begin
{ initialize display parameters text strings }
{ Reference function parameters }
RefParam[0] = RefID;
switch RefID begin
Case 0:
RefParam[1] = 0;
Text1 = Text1 & "Zero axis";
Case 1:
RefParam[1] = AMALength;
Text1 = Text1 & "AMA " & NumToStr(AMALength, 0);
Case 2:
RefParam[1] = EMALength;
Text1 = Text1 & "EMA " & NumToStr(EMALength, 1);
Case 3:
RefParam[1] = LRLength;
RefParam[2] = LRTgtBar;
Text1 = Text1 & "LinReg " & NumToStr(LRLength, 0)
& " Offset " & NumToStr(Offset,0) & " TgtBar " & NumToStr(LRTgtBar, 0);
Case 4:
RefParam[1] = KAMA_EffRatioLen;
RefParam[2] = KAMA_FastLength;
RefParam[3] = KAMA_SlowLength;
Text1 = Text1 & "KAMA " & NumToStr(KAMA_EffRatioLen, 1)
& ", " & NumToStr(KAMA_FastLength, 1) & ", " & NumToStr(KAMA_SlowLength, 1);
Case 5:
RefParam[1] = T3Length;
Text1 = Text1 & "T3 " & NumToStr(T3Length, 0);
Case 6:
RefParam[1] = JMALength;
RefParam[2] = JMAPhase;
Text1 = Text1 & "JMA " & NumToStr(JMALength, 0) & " Phase " & NumToStr(JMAPhase, 0);
Case 7:
Text1 = Text1 & "VWAP";
Case 8:
RefParam[1] = RefValue;
Text1 = Text1 & "Value = " & NumToStr(RefValue, 1);
end;
{ Deviation function parameters }
DevParam[0] = DevID;
switch DevID begin
Case 1:
DevParam[1] = StdDevLength;
Text2 = Text2 & "Std Dev " & NumToStr(StdDevLength, 0);
Case 2:
DevParam[1] = StdErrLength;
Text2 = Text2 & "Std Err " & NumToStr(StdErrLength, 0);
Case 3:
DevParam[1] = ATRLength;
Text2 = Text2 & "ATR " & NumToStr(ATRLength, 0);
Case 4:
DevParam[1] = JATRLength;
Text2 = Text2 & "JURIC ATR " & NumToStr(JATRLength, 0);
Case 5:
DevParam[1] = Percent;
Text2 = Text2 & "Percent " & NumToStr(Percent, 1);
Case 6:
DevParam[1] = Pts;
Text2 = Text2 & "Points " & NumToStr(Pts, 2);
end;
TextID1 = Text_New(0, 0, 0, Text1);
TextID2 = Text_New(0, 0, 0, Text2);
value1 = Text_SetColor(TextID1, CLParamColor);
value2 = Text_SetColor(TextID2, DevParamColor);
TextLength1 = StrLen(Text1);
TextLength2 = StrLen(Text2);
TextMaxLength = MaxList(TextLength1, TextLength2);
end;
Value1 = _RibbonsCalc(UpperBandsRef[Offset], LowerBandsRef[Offset], RefParam, DevParam,
NBands, StartMult, Increment, AddMinus, RoundToTradable, UpperBand, LowerBand);
{ PLOTTING }
If NBands >= 1 Then Begin
Plot8(UpperBand[1],"Hi-1", default, default, PlotWidth);
Plot10(LowerBand[1],"Lo-1", default, default, PlotWidth);
If NBands >=2 Then Begin
Plot7(UpperBand[2],"Hi-2", default, default, PlotWidth);
Plot11(LowerBand[2],"Lo-2", default, default, PlotWidth);
If NBands >=3 Then Begin
Plot6(UpperBand[3],"Hi-3", default, default, PlotWidth);
Plot12(LowerBand[3],"Lo-3", default, default, PlotWidth);
If NBands >= 4 Then Begin
Plot5(UpperBand[4],"Hi-4", default, default, PlotWidth);
Plot13(LowerBand[4],"Lo-4", default, default, PlotWidth);
If NBands >= 5 Then Begin
Plot4(UpperBand[5],"Hi-5", default, default, PlotWidth);
Plot14(LowerBand[5],"Lo-5", default, default, PlotWidth);
If NBands >=6 Then Begin
Plot3(UpperBand[6], "Hi-6", default, default, PlotWidth);
Plot15(LowerBand[6],"Lo-6", default, default, PlotWidth);
If NBands >=7 Then Begin
Plot2(UpperBand[7],"Hi-7", default, default, PlotWidth);
Plot16(LowerBand[7],"Lo-7", default, default, PlotWidth);
If NBands >=8 Then Begin
Plot1(UpperBand[8],"Hi-8", default, default, PlotWidth);
Plot17(LowerBand[8],"Lo-8", default, default, PlotWidth);
End;
End;
End;
End;
End;
End;
End;
End;
if ShowCenterLine then begin
Plot9(UpperBand[0] + AddMinus,"URef", default, default, PlotWidth);
If LowerBand[0] <> UpperBand[0] Then Plot18(LowerBand[0] + AddMinus,"LRef", default, default, PlotWidth);
end;
if Smooth > 0 then Plot21(Average(Price, Smooth), "Smooth Price");
//if Smooth > 0 then Plot21(JRC.JMA.2k(Price, Smooth,0), "Smooth Price");
{ chart label section }
{ adding this section causes ribbon plotter to delay plotting for first 200 bars }
{ may wish to comment out this section if using ribbon plotter for strategy testing }
{ since almost 200 more bars of data will be available to analyze }
BarsDisplayed = _BarsDisplayed;
if _LastBarOnChart then begin
if DisplayParameters then begin
switch RefID begin
case 0, 7:
value1 = _DisplayRangeAll( DisplayHigh, DisplayLow, DisplayRange );
default:
DisplayHigh = Highest(MaxList(UpperBand[NBands], High), BarsDisplayed);
DisplayLow = Lowest(MinList(LowerBand[NBands], Low), BarsDisplayed);
DisplayRange = DisplayHigh - DisplayLow;
end;
TextOffset1 = BarsDisplayed * (1 - TextHorizPct1 / 100) + TextMaxLength/2;
TextOffset2 = BarsDisplayed * (1 - TextHorizPct2 / 100) + TextMaxLength/2;
{ determine range percent of price at middle of text string }
RangePctAtOffset = (Close[(TextOffset1 + TextOffset2 - TextMaxLength)/2] - DisplayLow) / DisplayRange;
if RangePctAtOffset > 0.50 then begin
TextVert1 = DisplayLow + DisplayRange * TextVertPct1 / 100;
TextVert2 = DisplayLow + DisplayRange * TextVertPct2 / 100;
end else begin
TextVert1 = DisplayHigh - DisplayRange * TextVertPct2 / 100;
TextVert2 = DisplayHigh - DisplayRange * TextVertPct1 / 100;
end;
value3 = Text_SetLocation(TextID1, Date[TextOffset1], Time[TextOffset1], TextVert1);
value4 = Text_SetLocation(TextID2, Date[TextOffset2], Time[TextOffset2], TextVert2);
end;
end;
{}
// debug:
//print(_DateTimeSymbol,TextID1,TextID2,TextOffset1,TextOffset2,DisplayLow,DisplayHigh,DisplayRange,TextVert1,TextVert2);
Code: Select all
{
Function: _RibbonsCalc
Purpose: This function calculates a series of bands (ribbons) displaced from a
user specified centerline function.
The band values are loaded into arrays UpperBand and LowerBand.
The zero index item (ex. UpperBand[0]) represents the center line value.
Author: MarkSanDiego
Updated: 09/08/08 original version derived from _RibbonsPlotter indicator
01/30/09 prevent Standard Deviation function FXParam from being < 1
05/29/09 clean up and stream line code
CenterLine: May be:
0 - Zero axis
1 - AMA (Arithmetic Average)
2 - EMA (Exponential Moving Average
3 - LR (Linear Regression)
4 - Adaptive Moving Avg (Kaufman - KAMA)
5 - T3 Triple Exponential Moving Average
6 - JMA Juric Moving Average or
7 - Fixed Value
Band Function: May be:
1 - Standard Deviation (Bollinger Bands),
2 - Standard Error (Anderson Bands )
3 - Average True Range - ATR (Keltner Bands)
4 - Jurik Average True Range (ATR using Jurik Moving Avg)
5 - Percentage
6 - Points
}
{
Usage:
Inputs:
Price(low),
Smooth(0),
UpperBandsRef(TypicalPrice),
LowerBandsRef(TypicalPrice),
RefID(3),
AMALength(15), { arithmetic moving average length }
EMALength(15), { exponential moving average length }
LRLength(15), { linear regression function length }
LRTgtBar(0), { linear regression function target bar }
KAMA_EffRatioLen(7), { Kaufman adaptive moving average parameters }
KAMA_FastLength(2), { Kaufman adaptive moving average parameters }
KAMA_SlowLength(25), { Kaufman adaptive moving average parameters }
T3Length(20),
JMALength(20),
JMAPhase(0),
RefValue(0),
DevID(5), { deviation function identifier }
StdDevLength(15), { standard deviation length }
StdErrLength(15), { standard error length }
ATRLength(14), { average true range length }
JATRLength(14), { percentage }
Percent(1),
Pts(1),
NBands(2), { maximum 8 }
StartMult(1),
Increment(1),
AddMinus(0),
RoundToTradable(False),
PlotWidth(0),
ShowCenterLine(true);
Arrays:
UpperBand[9](0), { array containing band values. UpperBand[0] is the center line value }
LowerBand[9](0), { array containing band values. UpperBand[0] is the center line value }
RefParam[4](0), { reference function (center line) parameters }
DevParam[4](0); { deviation function (bands or ribbons) parameters }
Variables:
UpperCL(0),
LowerCL(0);
Value1 = _RibbonsCalc(UpperBandsRef, LowerBandsRef, RefParam, DevParam,
NBands, StartMult, Increment, AddMinus, RoundToTradable, UpperBand, LowerBand);
}
Inputs:
UpperBandsRef(NumericSeries),
LowerBandsRef(NumericSeries),
RefParam[xx](NumericArrayRef),
DevParam[yy](NumericArrayRef),
NBands(NumericSimple),
StartMult(NumericSimple),
Increment(NumericSimple),
AddMinus(NumericSimple),
RoundToTradable(TrueFalseSimple),
{ Arrays: }
UpperBand[tt](NumericArrayRef),
LowerBand[uu](NumericArrayRef);
Variables:
intrabarpersist RefID(0), { reference function ID }
R1(0), { reference function parameters }
R2(0),
R3(0),
R4(0),
DevID(0), { deviation function ID }
D1(0), { deviation function paramaters }
D1b(0), { special handling required for standard dev and standard error functions }
D2(0),
D3(0),
D4(0),
n(0),
StartBar(0),
intrabarpersist UpperFX(0),
intrabarpersist LowerFX(0),
intrabarpersist UpperCL(0),
intrabarpersist LowerCL(0);
{ unpack static reference and deviation function parameters }
once begin
RefID = RefParam[0];
R1 = RefParam[1];
R2 = RefParam[2];
R3 = RefParam[3];
R4 = RefParam[4];
DevID = DevParam[0];
D1 = DevParam[1];
D1b = MaxList(2, D1); { special handling required for standard dev and standard error functions }
D2 = DevParam[2];
D3 = DevParam[3];
D4 = DevParam[4];
end;
{ ESTABLISH CENTERLINE }
switch RefID begin
Case 0:
UpperCL = 0;
case 1:
UpperCL = AverageFC(UpperBandsRef, R1);
case 2:
UpperCL = XAverage(UpperBandsRef, R1);
case 3:
UpperCL = LinearRegValueFC(UpperBandsRef, R1, R2);
case 4:
UpperCL = AdaptiveMovAvg(UpperBandsRef, R1, R2, R3);
case 5:
UpperCL = T3Average.Series(UpperBandsRef, R1);
{ {disable if Juric moving average not installed }
case 6:
UpperCL = JRC.JMA.2k(UpperBandsRef, R1, R2);}
case 7:
UpperCL = R1;
end;
if LowerBandsRef = UpperBandsRef then begin
LowerCL = UpperCL;
end else begin
switch RefID begin
Case 0:
LowerCL = 0;
case 1:
LowerCL = AverageFC(LowerBandsRef, R1);
case 2:
LowerCL = XAverage(LowerBandsRef, R1);
case 3:
LowerCL = LinearRegValueFC(LowerBandsRef, R1, R2);
case 4:
LowerCL = AdaptiveMovAvg(LowerBandsRef, R1, R2, R3);
case 5:
LowerCL = T3Average.Series(LowerBandsRef, R1);
{ {disable if Juric moving average not installed }
case 6:
LowerCL = JRC.JMA.2k(LowerBandsRef, R1, R2); }
case 7:
LowerCL = R1;
end;
end;
{ ESTABLISH FUNCTION }
switch DevID begin
case 1:
UpperFX = _StdDev(UpperBandsRef, D1b);
Case 2:
UpperFX = _StdError(UpperBandsRef, D1b);
case 3:
UpperFX = _AvgTrueRange(D1);
{{ disable if Jurik moving average not installed }
case 4:
UpperFX = _JMATrueRange(D1);}
case 5:
UpperFX = UpperBandsRef * D1 / 100;
case 6:
UpperFx = D1;
end;
if LowerBandsRef = UpperBandsRef then begin
LowerfX = UpperFx;
end else begin
switch DevID begin
case 1:
LowerFX = _StdDev(LowerBandsRef, D1b);
Case 2:
LowerFX = _StdError(LowerBandsRef, D1b);
case 3:
LowerFx = UpperFx;
case 4:
LowerFx = UpperFx;
case 5:
LowerFX = LowerBandsRef * D1 / 100;
case 6:
LowerFx = D1;
end;
end;
{ ROUND OFF to tradeable value }
if RoundToTradable then begin
for n = 0 to NBands begin
UpperBand[n] = Round2Fraction(UpperCL + UpperFx*(StartMult+(n-1)*Increment) + AddMinus);
LowerBand[n] = Round2Fraction(LowerCL - LowerFx*(StartMult+(n-1)*Increment) + AddMinus);
end;
{ no rounding off }
end else begin
for n = 0 to NBands begin
UpperBand[n] = UpperCL + UpperFx*(StartMult+(n-1)*Increment) + AddMinus;
LowerBand[n] = LowerCL - LowerFx*(StartMult+(n-1)*Increment) + AddMinus;
end;
End;
_RibbonsCalc = 0;