i posted code using the REMAP function. Code that uses REMAP function - #9 by empottasch but I could not add some code to that thread. So this thread is just an update.
Here I post an update using the REMAP function and I added the MapCreate function. What it does: it compares the data within the yellow box (fig 1) with the data prior to that yellow box (fig 2) and finds patterns that are most similar to the one in the yellow box (using least squares fitting).
This code is different from the previous code because I used 1) the MapCreate function. 2) I defined the functions to be fitted differently. Since if you for instance fit the Close price and the EMA( C, 150 ) what you really want to know is how the close price relates to EMA( C, 150 ). Fitting EMA( C, 150 ) just on itself has little meaning. It is the relation to the close price that is meaningful. As you can see in figure 2 the patterns that fit best are similar with respect to EMA( C, 150 ), since that is what has been used for this particular fit.
So by default the code is in "continues mode" which means it calculates at every refresh. Personally I use it in 1Min charts but have it calculate only once per minute. Plus you can control the number of bars to use in the calculation.
But this code posted here is the basic code and needs EOD date else it will be too slow. Or you have to put it in Trigger Mode (see param window).
Anyways here is the base code
//RequestTimedRefresh( 0.1 );
SetBarsRequired( sbrAll, sbrAll );
SetChartBkColor( colorBlack );
SetChartOptions( 0, chartShowDates );
per = Param( "Pattern Number of Bars", 20, 1, 250, 1 );
npred = Param( "Number of Bars to Predict", 20, 1, 150, 1 );
nfits = Param( "Number of Fits", 3, 1, 50, 1 );
calculationMode = ParamList( "Calculation Mode", "Continuous Mode|Trigger Mode", 0 ); // continuous gets real time updates
calculationTrigger = ParamTrigger( "Calculation Trigger", "Press Here" ); // works when calculation mode is in Trigger Mode
displayType = ParamList( "Display Type", "Show Average Fit Plus Forcasts|Show Average Fit Standard Deviation Cone", 1 );
normalizationmode = ParamList( "Normalization mode", "Percentage|0 to 1", 1 );
showbarnumbering = ParamToggle( "Show Bar Numbering", "Not Show|Show", 1 );
showPatternText = ParamToggle( "Show Pattern Text", "Not Show|Show", 1 );
patternlock = ParamList( "Pattern Lock", "Lock Off|Lock On", 0 );
ft = ParamList( "Font Type", "Tahoma|Arial Black|Verdana|Courier New|Times New Roman|Open Sans|Segoe UI|DejaVu Sans", 1 );
sz = Param( "Font Size", 10, 8, 50, 1 );
clearAll = ParamTrigger( "Clear All Static variables", "Clear All Static variables" );
sintest = ParamToggle( "SINUS FUNCTION TEST", "Not Show|Show", 0 ); // test an artificial data function
// initialisations
bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );
distance = 0;
distancecounter = 0;
hper = lper = Null;
bestFitsStorageArray = 0;
idx0 = ss = shift = 0;
yymin = Status( "axisminy" );
yymax = Status( "axismaxy" );
topcone = botcone = 0;
////////////////////////////////////////////////////
// For testing purposes
pi = 3.14159265359;
function sinfunc( wavelength, phase )
{
sinusFunctionArray = 2 * sin( 2 * pi * Cum( 1 ) / wavelength + phase )
+ 1 * sin( 2 * pi * Cum( 1 ) / ( trunc( wavelength / 2 ) ) + phase / 2 )
+ 0.5 * sin( 2 * pi * Cum( 1 ) / ( trunc( wavelength / 4 ) ) + phase / 4 )
+ 1 * sin( 2 * pi * Cum( 1 ) / ( trunc( wavelength * 50 ) ) + phase / 8 );
//+ 2 * Random( 1 );
//+ 0.75 * mtRandomA( seed = 1 );
return sinusFunctionArray;
}
if( sintest )
{
O = H = L = C = sinfunc( 30, pi );
Plot( C, "", colorWhite, styleLine, Null, Null, 0, 0, 1 );
}
////////////////////////////////////////////////////
/////////////////// DEFINE the Functions here /////////////////
totpat = 9; // total number of patterns
pf1 = ParamToggle( "Function f1: Close", "Off|On", 1 );
pf2 = ParamToggle( "Function f2: EMA(Close,20) against Close", "Off|On", 0 );
pf3 = ParamToggle( "Function f3: EMA(Close,150) against Close", "Off|On", 0 );
pf4 = ParamToggle( "Function f4: RSI(14)", "Off|On", 0 );
pf5 = ParamToggle( "Function f5: BBandTop(15,2) against Close", "Off|On", 0 );
pf6 = ParamToggle( "Function f6: BBandBot(15,2) against Close", "Off|On", 0 );
pf7 = ParamToggle( "Function f7: High against Close", "Off|On", 0 );
pf8 = ParamToggle( "Function f8: Low against Close", "Off|On", 0 );
pf9 = ParamToggle( "Function f9: Open against Close", "Off|On", 0 );
// note: when chosing to display for instance function 2 the pf2 needs to also be set to ON.
displayFunction = ParamList( "Forecasted Function ID", "1,2,3,4,5,6,7,8,9", 0 );
// function 1, Close price
nn = 1;
pp = MapCreate();
pp["OnOff"] = pf1;
pp["Text"] = "[C], \n";
pp["Variable"] = C;
pp["High"] = HHV( pp["Variable"], per );
pp["Low"] = LLV( pp["Variable"], per );
pp["Startpoint"] = per * 2;
VarSet( "patf" + nn, pp );
// function 2, C-EMA(20)
nn = 2;
pp = MapCreate();
pp["OnOff"] = pf2;
pp["Text"] = "[EMA(20) against C], \n";
pp["Variable"] = EMA( C, 20 );
pp["High"] = Max( HHV( C, per ), HHV( pp["Variable"], per ) ); // normalisation box include the Close price
pp["Low"] = Min( LLV( C, per ), LLV( pp["Variable"], per ) );
pp["Startpoint"] = per * 2 + 20;
VarSet( "patf" + nn, pp );
// function 3, C-EMA(150)
nn = 3;
pp = MapCreate();
pp["OnOff"] = pf3;
pp["Text"] = "[EMA(150) against C], \n";
pp["Variable"] = EMA( C, 150 );
pp["High"] = Max( HHV( C, per ), HHV( pp["Variable"], per ) ); // normalisation box include the Close price
pp["Low"] = Min( LLV( C, per ), LLV( pp["Variable"], per ) );
pp["Startpoint"] = per * 2 + 150;
VarSet( "patf" + nn, pp );
// function 4, RSI(14)
nn = 4;
pp = MapCreate();
pp["OnOff"] = pf4;
pp["Text"] = "[RSI(14)], \n";
pp["Variable"] = RSI( 14 );
pp["High"] = HHV( pp["Variable"], per );
pp["Low"] = LLV( pp["Variable"], per );
pp["Startpoint"] = per * 2 + 14;
VarSet( "patf" + nn, pp );
// function 5, BBandTop(15,2)
nn = 5;
pp = MapCreate();
pp["OnOff"] = pf5;
pp["Text"] = "[BBandTop(15,2) against C], \n";
pp["Variable"] = BBandTop( C, 15, 2 );
pp["High"] = Max( HHV( C, per ), HHV( pp["Variable"], per ) ); // normalisation box include the Close price
pp["Low"] = Min( LLV( C, per ), LLV( pp["Variable"], per ) );
pp["Startpoint"] = per * 2 + 15;
VarSet( "patf" + nn, pp );
// function 6, BBandBot(15,2)
nn = 6;
pp = MapCreate();
pp["OnOff"] = pf6;
pp["Text"] = "[BBandBot(15,2) against C], \n";
pp["Variable"] = BBandBot( C, 15, 2 );
pp["High"] = Max( HHV( C, per ), HHV( pp["Variable"], per ) ); // normalisation box include the Close price
pp["Low"] = Min( LLV( C, per ), LLV( pp["Variable"], per ) );
pp["Startpoint"] = per * 2 + 15;
VarSet( "patf" + nn, pp );
// function 7, High against Close
nn = 7;
pp = MapCreate();
pp["OnOff"] = pf7;
pp["Text"] = "[H against C], \n";
pp["Variable"] = High;
pp["High"] = Max( HHV( C, per ), HHV( pp["Variable"], per ) ); // normalisation box include the Close price
pp["Low"] = Min( LLV( C, per ), LLV( pp["Variable"], per ) );
pp["Startpoint"] = per * 2;
VarSet( "patf" + nn, pp );
// function 8, Low against Close
nn = 8;
pp = MapCreate();
pp["OnOff"] = pf8;
pp["Text"] = "[L against C], \n";
pp["Variable"] = Low;
pp["High"] = Max( HHV( C, per ), HHV( pp["Variable"], per ) ); // normalisation box include the Close price
pp["Low"] = Min( LLV( C, per ), LLV( pp["Variable"], per ) );
pp["Startpoint"] = per * 2;
VarSet( "patf" + nn, pp );
// function 9, Open against Close
nn = 9;
pp = MapCreate();
pp["OnOff"] = pf9;
pp["Text"] = "[O against C], \n";
pp["Variable"] = Open;
pp["High"] = Max( HHV( C, per ), HHV( pp["Variable"], per ) ); // normalisation box include the Close price
pp["Low"] = Min( LLV( C, per ), LLV( pp["Variable"], per ) );
pp["Startpoint"] = per * 2;
VarSet( "patf" + nn, pp );
//////////////////////////////////
function SayOnce( text )
{
if( StaticVarGetText( "lastsaidtext" ) != text )
{
Say( text );
StaticVarSetText( "lastsaidtext", text );
}
}
// lock pattern in place
if( patternlock == "Lock Off" )
{
idx0 = Nz( SelectedValue( BarIndex() ) );
StaticVarSet( "idx0", idx0 );
SayOnce( "Lock Off" );
clrlock = colorRed;
}
if( patternlock == "Lock On" )
{
idx0 = Nz( StaticVarGet( "idx0" ) );
SayOnce( "Lock On" );
clrlock = colorBrightGreen;
}
if( clearAll )
{
SayOnce( "Clear All Static Variables" );
StaticVarRemove( "*" );
}
function patternDefinition()
{
distance = 0;
cnt = 0;
for( npat = 1; npat <= totpat; npat++ )
{
map_pat = VarGet( "patf" + npat );
if( map_pat["OnOff"] )
{
cnt = cnt + 1;
StaticVarSetText( "patternText", StaticVarGetText( "patternText" ) + map_pat["Text"] );
ff = map_pat["Variable"];
hper = map_pat["High"];
lper = map_pat["Low"];
pat = 0;
for( z = 0; z < per; z++ )
{
x = idx0 - per + z + 1;
if( normalizationmode == "0 to 1" )
{
pat[z] = Remap( ff[x], lper[idx0], hper[idx0], 0, 1 );
}
if( normalizationmode == "Percentage" )
{
pat[z] = Remap( ff[x], lper[idx0], hper[idx0], 0, SafeDivide( hper[idx0] - lper[idx0], lper[idx0] ) * 100 );
}
if( showbarnumbering )
PlotTextSetFont( "" + z, ft, sz, x, yymin, colorBlack, colorWhite, 0 );
}
cpat = 0;
for( i = map_pat["Startpoint"]; i < idx0 - per; i++ )
{
dis = 0;
for( z = 0; z < per; z++ )
{
x = i - per + z + 1;
if( normalizationmode == "0 to 1" )
{
cpat[z] = Remap( ff[x], lper[i], hper[i], 0, 1 );
}
if( normalizationmode == "Percentage" )
{
cpat[z] = Remap( ff[x], lper[i], hper[i], 0, SafeDivide( hper[i] - lper[i], lper[i] ) * 100 );
}
// avoid parts with bad data
if( lper[x] == hper[x] )
{
dis = 1e12;
}
else
{
dis = sqrt( ( cpat[z] - pat[z] ) ^ 2 ) + dis;
}
}
distance[i] = distance[i] + SafeDivide( dis, per ); // average distance per bar
distancecounter[i] = distancecounter[i] + 1;
}
StaticVarSet( "distance", distance );
StaticVarSet( "distancecounter", distancecounter );
}
}
if( cnt == 0 )
{
StaticVarSet( "distance", 0 );
}
}
if( calculationMode == "Continuous Mode" )
{
StaticVarSetText( "patternText", "" );
patternDefinition();
}
if( calculationMode == "Trigger Mode" )
{
if( calculationTrigger )
{
Say( "Calculate Fit" );
StaticVarSetText( "patternText", "" );
patternDefinition();
Say( "Finished" );
}
}
// handle the distances of the fits
distance = Nz( StaticVarGet( "distance" ) );
distancecounter = Nz( StaticVarGet( "distancecounter" ) );
distance = SafeDivide( distance, distancecounter );
distance = IIf( distance == 0, 1e12, distance ); // distance initially needs to be set to 0, so remove zeros after fitting
sdistance = Sort( distance, 0, -1, False ); // return sorted value
sdistancei = Sort( distance, 0, -1, True ); // return the index corresponding to the sorted value
if( displayFunction == "1" )
{
// function to forcast
map_pat = VarGet( "patf" + displayFunction );
ff_disp = map_pat["Variable"];
hper = map_pat["High"];
lper = map_pat["Low"];
displayFunctionText = map_pat["Text"];
Plot( ff_disp, "", colorWhite, styleCandle, Null, Null, 0, 0, 1 );
}
if( displayFunction == "2" )
{
// function to forcast
map_pat = VarGet( "patf" + displayFunction );
ff_disp = map_pat["Variable"];
hper = map_pat["High"];
lper = map_pat["Low"];
displayFunctionText = map_pat["Text"];
Plot( ff_disp, "", colorWhite, styleDashed, Null, Null, 0, 0, 2 );
}
if( displayFunction == "3" )
{
// function to forcast
map_pat = VarGet( "patf" + displayFunction );
ff_disp = map_pat["Variable"];
hper = map_pat["High"];
lper = map_pat["Low"];
displayFunctionText = map_pat["Text"];
Plot( ff_disp, "", colorWhite, styleDashed, Null, Null, 0, 0, 2 );
}
if( displayFunction == "4" )
{
// function to forcast
map_pat = VarGet( "patf" + displayFunction );
ff_disp = map_pat["Variable"];
hper = map_pat["High"];
lper = map_pat["Low"];
displayFunctionText = map_pat["Text"];
Plot( ff_disp, "", colorWhite, styleDashed, Null, Null, 0, 0, 2 );
}
if( displayFunction == "5" )
{
// function to forcast
map_pat = VarGet( "patf" + displayFunction );
ff_disp = map_pat["Variable"];
hper = map_pat["High"];
lper = map_pat["Low"];
displayFunctionText = map_pat["Text"];
Plot( ff_disp, "", colorWhite, styleDashed, Null, Null, 0, 0, 2 );
}
if( displayFunction == "6" )
{
// function to forcast
map_pat = VarGet( "patf" + displayFunction );
ff_disp = map_pat["Variable"];
hper = map_pat["High"];
lper = map_pat["Low"];
displayFunctionText = map_pat["Text"];
Plot( ff_disp, "", colorWhite, styleDashed, Null, Null, 0, 0, 2 );
}
if( displayFunction == "7" )
{
// function to forcast
map_pat = VarGet( "patf" + displayFunction );
ff_disp = map_pat["Variable"];
hper = map_pat["High"];
lper = map_pat["Low"];
displayFunctionText = map_pat["Text"];
Plot( ff_disp, "", colorWhite, styleDashed, Null, Null, 0, 0, 2 );
}
if( displayFunction == "8" )
{
// function to forcast
map_pat = VarGet( "patf" + displayFunction );
ff_disp = map_pat["Variable"];
hper = map_pat["High"];
lper = map_pat["Low"];
displayFunctionText = map_pat["Text"];
Plot( ff_disp, "", colorWhite, styleDashed, Null, Null, 0, 0, 2 );
}
if( displayFunction == "9" )
{
// function to forcast
map_pat = VarGet( "patf" + displayFunction );
ff_disp = map_pat["Variable"];
hper = map_pat["High"];
lper = map_pat["Low"];
displayFunctionText = map_pat["Text"];
Plot( ff_disp, "", colorWhite, styleDashed, Null, Null, 0, 0, 2 );
}
if( pf2 )
{
map_pat = VarGet( "patf2" );
Plot( map_pat["Variable"], "", colorGold, styleDashed | styleNoRescale, Null, Null, 0, 0, 1 );
}
if( pf3 )
{
map_pat = VarGet( "patf3" );
Plot( map_pat["Variable"], "", colorAqua, styleDashed | styleNoRescale, Null, Null, 0, 0, 1 );
}
if( pf5 )
{
map_pat = VarGet( "patf5" );
Plot( map_pat["Variable"], "", colorOrange, styleDashed | styleNoRescale, Null, Null, 0, 0, 1 );
}
if( pf6 )
{
map_pat = VarGet( "patf6" );
Plot( map_pat["Variable"], "", colorViolet, styleDashed | styleNoRescale, Null, Null, 0, 0, 1 );
}
// function helps to avoid selecting 2 patterns within a distance of "per" bars
function testValidity( aa, disi, per, i0 )
{
val = 1;
for( i = 0; i < 50; i++ )
{
// first element, no storage elements yet
if( aa[i] == 0 AND i == 0 )
{
val = 1;
break;
}
else
// distance to new best fit disi less than per then ignore disi
if( abs( aa[i] - disi ) < per )
{
val = 0;
break;
}
else
if( i0 - disi < npred )
{
val = 0;
break;
}
else
if( disi <= per )
{
val = 0;
break;
}
}
return val;
}
cnt = 0;
for( i = 0; i < BarCount; i++ )
{
fitdummyY = 0;
forcastdummyY = 0;
// avoid selecting 2 patterns within a distance of per bars, use testValidity
if( testValidity( bestFitsStorageArray, sdistancei[i], ( per + npred ), idx0 ) )
{
bestFitsStorageArray[cnt] = idx = sdistancei[i];
//_TRACE( "idx: " + idx0 );
shift = npred - Min( BarCount - 1 - idx0, npred );
// fit
for( j = 0; j < per; j++ )
{
x = Max( 0, idx0 + j - per + 1 );
x1 = Max( 0, idx + j - per + 1 );
y = Remap( ff_disp[x1], lper[idx], hper[idx], lper[idx0], hper[idx0] );
fitdummyY[x] = y;
}
StaticVarSet( "fit" + cnt, fitdummyY );
// forecast
for( j = per; j < per + npred; j++ )
{
x = Min( BarCount - 1, idx0 + j - per + 1 - shift );
x1 = Min( BarCount - 1, idx + j - per + 1 );
y = Remap( ff_disp[x1], lper[idx], hper[idx], lper[idx0], hper[idx0] );
forcastdummyY[x] = y;
}
StaticVarSet( "forcast" + cnt, forcastdummyY );
cnt = cnt + 1;
}
if( cnt > nfits )
{
StaticVarSet( "bestFitsStorageArray", bestFitsStorageArray );
break;
}
}
if( displayType == "Show Average Fit Plus Forcasts" )
{
totfit = 0;
totforcast = 0;
for( i = 0; i < nfits; i++ )
{
ff = StaticVarGet( "fit" + i );
Plot( IIf( ff, ff, Null ), "", colorAqua, styleDashed | styleNoRescale | styleNoLabel, Null, Null, 0, 0, 1 );
totfit = totfit + StaticVarGet( "fit" + i );
ff = StaticVarGet( "forcast" + i );
Plot( IIf( ff, ff, Null ), "", colorViolet, styleDashed | styleNoRescale | styleNoLabel, Null, Null, shift, 0, 1 );
totforcast = totforcast + StaticVarGet( "forcast" + i );
PlotTextSetFont( "" + ( i + 1 ), ft, sz, idx0 + 1 + npred, ff[idx0 + npred - shift], colorBlack, colorWhite, 0 );
}
// average fit
totfit = totfit / nfits;
Plot( IIf( totfit, totfit, Null ), "", colorAqua, styleDots | styleNoRescale | styleNoLabel, Null, Null, 0, 1, 3 );
// average forcast
totforcast = totforcast / nfits;
Plot( IIf( totforcast, totforcast, Null ), "", colorViolet, styleDots | styleNoRescale | styleNoLabel, Null, Null, shift, 1, 3 );
}
if( displayType == "Show Average Fit Standard Deviation Cone" )
{
totfit = 0;
totforcast = 0;
for( i = 0; i < nfits; i++ )
{
ff = StaticVarGet( "fit" + i );
totfit = totfit + StaticVarGet( "fit" + i );
ff = StaticVarGet( "forcast" + i );
totforcast = totforcast + StaticVarGet( "forcast" + i );
}
// average fit
totfit = totfit / nfits;
Plot( IIf( totfit, totfit, Null ), "", colorYellow, styleDots | styleNoRescale | styleNoLabel, Null, Null, 0, 1, 2 );
// average forcast
totforcast = totforcast / nfits;
Plot( IIf( totforcast, totforcast, Null ), "", colorViolet, styleDots | styleNoRescale | styleNoLabel, Null, Null, shift, 1, 3 );
// error cone forecast
topcone = botcone = Null;
for( i = 0; i < npred; i++ )
{
ss = 0;
x = idx0 + 1 + i;
shift = npred - Min( BarCount - 1 - idx0, npred );
for( j = 0; j < nfits; j++ )
{
ff = StaticVarGet( "forcast" + j );
ss = ( ff[x - shift] - totforcast[x - shift] ) ^ 2 + ss;
}
topcone[x - shift] = totforcast[x - shift] + sqrt( SafeDivide( ss, nfits ) );
botcone[x - shift] = totforcast[x - shift] - sqrt( SafeDivide( ss, nfits ) );
}
topcone = IIf( 0, Null, topcone );
botcone = IIf( 0, Null, botcone );
PlotOHLC( topcone, topcone, botcone, botcone, "", ColorRGB( 0, 0, 60 ), styleCloud | styleNoLabel | styleNoRescale, Null, Null, shift, -10, 1 );
Plot( topcone, "", colorblue, styleLine | styleNoLabel | styleNoRescale, Null, Null, shift, -10, 3 );
Plot( botcone, "", colorblue, styleLine | styleNoLabel | styleNoRescale, Null, Null, shift, -10, 3 );
// error cone data fits
topcone = botcone = Null;
for( i = 0; i < per; i++ )
{
ss = 0;
x = Max( 0, idx0 - per + i + 1 );
shift = 0;
for( j = 0; j < nfits; j++ )
{
ff = StaticVarGet( "fit" + j );
ss = ( ff[x - shift] - totfit[x - shift] ) ^ 2 + ss;
}
topcone[x - shift] = totfit[x - shift] + sqrt( SafeDivide( ss, nfits ) );
botcone[x - shift] = totfit[x - shift] - sqrt( SafeDivide( ss, nfits ) );
}
topcone = IIf( 0, Null, topcone );
botcone = IIf( 0, Null, botcone );
PlotOHLC( topcone, topcone, botcone, botcone, "", ColorRGB( 0, 0, 60 ), styleCloud | styleNoLabel | styleNoRescale, Null, Null, shift, -10, 1 );
Plot( topcone, "", colorblue, styleLine | styleNoLabel | styleNoRescale, Null, Null, shift, -10, 3 );
Plot( botcone, "", colorblue, styleLine | styleNoLabel | styleNoRescale, Null, Null, shift, -10, 3 );
}
// draw box around pattern that needs to be fitted
pat = IIf( idx0 == BarIndex(), 1, 0 );
Plot( pat, "", colorYellow, styleDashed | styleHistogram | styleOwnScale | styleNoLabel, 0, 1, 0, -3, 1 );
GfxSetZOrder( -2 );
GfxSetCoordsMode( 1 );
GfxSelectSolidBrush( ColorRGB( 50, 50, 10 ) );
GfxSelectPen( ColorYellow, 3, 0 );
if( !IsEmpty( hper[idx0] ) AND !IsEmpty( lper[idx0] ) )
GfxPolyline( idx0, hper[idx0], idx0, lper[idx0], idx0 - per + 1, lper[idx0], idx0 - per + 1, hper[idx0], idx0, hper[idx0] );
if( showPatternText )
PlotTextSetFont( "" + StaticVarGetText( "patternText" ), ft, sz, idx0 + 2, hper[idx0], colorBlack, colorWhite, 0 );
// show boxes around the best fits
GfxSelectPen( colorAqua, 3, 0 );
for( i = 0; i < nfits; i++ )
{
idx0 = bestFitsStorageArray[i];
idx_fit = 0;
if( !IsEmpty( hper[idx0] ) AND !IsEmpty( lper[idx0] ) )
{
GfxPolyline( idx0, hper[idx0], idx0, lper[idx0], idx0 - per + 1, lper[idx0], idx0 - per + 1, hper[idx0], idx0, hper[idx0] );
PlotTextSetFont( "" + ( i + 1 ) + " best", ft, sz, idx0, hper[idx0], colorBlack, colorWhite, 0 );
pat = IIf( idx0 == BarIndex(), 1, 0 );
Plot( pat, "", colorAqua, styleDashed | styleHistogram | styleOwnScale | styleNoLabel, 0, 1, 0, -3, 1 );
for( j = 0; j < per; j++ )
{
x = Max( 0, idx0 - per + j + 1 );
idx_fit[x] = ff_disp[x];
}
Plot( IIf( idx_fit, idx_fit, Null ), "", colorAqua, styleDots | styleNoRescale | styleNoLabel, Null, Null, 0, 1, 2 );
}
}
Title = EncodeColor( colorAqua ) + "Number of Fits: " + nfits + " | "
+ EncodeColor( colorYellow ) + " Pattern Size: " + per + " | "
+ EncodeColor( colorBrightGreen ) + " Number of bars forcasted: " + npred + " | "
+ EncodeColor( colorOrange ) + " Normalization Mode: " + normalizationmode + " | "
+ EncodeColor( clrlock ) + " Pattern Lock: " + patternlock + " | \n"
+ EncodeColor( colorLightBlue ) + "Forcasted Function: " + displayFunctionText + ""
+ EncodeColor( colorPink ) + "Fitted Functions: \n" + StaticVarGetText( "patternText" );