I am running a piece of code with 1 minute and 4 minute periodicity. By periodicity i mean Analysis Settings-->Periodicity. The values that I run for these 2 runs are different whereas I expect them to be same. Below is the copy-paste runnable code. Here is the price data file that needs to be used.
_TRACE( "!CLEAR!" );
_SECTION_BEGIN( "Price" );
SetChartOptions( 0, chartShowArrows | chartShowDates | chartWrapTitle );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}} ", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
PlotOHLC( O, H, L, C, "Close", colorRed, styleBar , Null, Null, 0, 1, 1 );
_SECTION_END();
FwdSearchDistance = 14;
_Trace( "BarScore for FwdSearchDistance=" + FwdSearchDistance );
minSearchDistanceForBarScore = 2;
constScoreTypeLL = 1;
constScoreTypeHH = 2;
maxSearchDistanceForBarScore=50;
function calculateBarScore()
{
if( Status( "actionex" ) != actionExAAParameters && Status( "actionex" ) != actionPortfolio )
{
startTime = Now( 5 );
thisTimeframeinseconds = Interval();
thisTimeframeinMinutes = thisTimeframeinseconds / 60;
distCounterStartValue = minSearchDistanceForBarScore;
InterveaningBarCounter = 0;
for( distanceCounter = distCounterStartValue; distanceCounter <= maxSearchDistanceForBarScore; distanceCounter++ )
{
intersectionReachedHH = 0;
intersectionReachedLL = 0;
sourceBarHigh = H;
destBarHigh = Ref( H, distanceCounter );
sourceBarLow = L;
destBarLow = Ref( L, distanceCounter );
aHH = ( destBarHigh - sourceBarHigh ) / distanceCounter;
aLL = ( destBarLow - sourceBarLow ) / distanceCounter;
distanceIdentifier = distanceCounter; //Max(0, distanceCounter - minSearchDistanceForBarScore);
distanceIsMoreThanBarCount = BarIndex() + distanceCounter > ( BarCount - 1 );
for( InterveaningBarCounter = 1; InterveaningBarCounter < distanceCounter; InterveaningBarCounter++ )
{
lineHHAtInterveaningBar = aHH * InterveaningBarCounter + sourceBarHigh; //value of line_HH at bar (i+k)
lineLLAtInterveaningBar = aLL * InterveaningBarCounter + sourceBarLow; //value of line_LL at bar (i+k)
intersectionReachedHH = intersectionReachedHH || lineHHAtInterveaningBar <= Ref( H, InterveaningBarCounter );
intersectionReachedLL = intersectionReachedLL || lineLLAtInterveaningBar >= Ref( L, InterveaningBarCounter );
VarSet( "bsHH_" + distanceIdentifier, IIf( !distanceIsMoreThanBarCount && !intersectionReachedHH && lineHHAtInterveaningBar > Ref( H, InterveaningBarCounter ),
InterveaningBarCounter, IIf( distanceIdentifier == 0, 0, Nz( Varget( "bsHH_" + ( distanceIdentifier - 1 ) ) ) ) ) );
VarSet( "bsLL_" + distanceIdentifier, IIf( !distanceIsMoreThanBarCount && !intersectionReachedLL && lineLLAtInterveaningBar < Ref( L, InterveaningBarCounter ),
InterveaningBarCounter, IIf( distanceIdentifier == 0, 0, Nz( Varget( "bsLL_" + ( distanceIdentifier - 1 ) ) ) ) ) );
}
currenIntervalInSeconds = Interval(); //_TRACE("currenIntervalInSeconds="+currenIntervalInSeconds);
StaticVarSet( Name() + "_interval_" + currenIntervalInSeconds + "_bsHH_" + distanceIdentifier, VarGet( "bsHH_" + distanceIdentifier ), 0, cmAlways );
StaticVarSet( Name() + "_interval_" + currenIntervalInSeconds + "_bsLL_" + distanceIdentifier, VarGet( "bsLL_" + distanceIdentifier ), 0, cmAlways );
}
endTime = Now( 5 );
runTime = round( DateTimeDiff( endTime, startTime ) ) ;
}// end if
}//end of function
function getBarScore( arrayFwdSearchDistance, barScoreType )
{
retval = Null;
currenIntervalInSeconds = Interval();
for( searchDistanceCounter = minSearchDistanceForBarScore; searchDistanceCounter <= maxSearchDistanceForBarScore; searchDistanceCounter++ )
{
distanceIdentifier = searchDistanceCounter;
retval = IIf( arrayFwdSearchDistance == searchDistanceCounter, iif( barScoreType == constScoreTypeHH, StaticVarGet( Name() + "_interval_" + currenIntervalInSeconds + "_bsHH_" + distanceIdentifier ), StaticVarGet( Name() + "_interval_" + currenIntervalInSeconds + "_bsLL_" + distanceIdentifier ) ), retval );
}
return retval;
}
PatternTimeFrame=in1Minute * 13;
TimeFrameSet(PatternTimeFrame);
calculateBarScore();
bsHH = getBarScore( maxSearchDistanceForBarScore, constScoreTypeHH );
//bsLL = getBarScore( maxSearchDistanceForBarScore, constScoreTypeLL );
TimeFrameRestore();
bsHH=TimeFrameExpand(bsHH, PatternTimeFrame);
//bsLL=TimeFrameExpand(bsLL, PatternTimeFrame);
atr1 = ATR( 1 );
for( i = 1; i < BarCount; i++ )
{
PlotTextSetFont( "" + bsHH[i], "windings", 7, i , H[i] + atr1[i] / 3 , colorYellow, -100 );//
//PlotTextSetFont( "" + bsLL[i], "windings", 7, i , L[i] - atr1[i] / 3 , colorYellow, -100 );//
}
_TRACE( "bsHH=" + bsHH );
_TRACE( "barindex()=" + barindex() );
Filter=1;
AddColumn(bsHH, "bsHH");
//AddColumn(bsLL, "bsLL");
See the Exploration screenshot below. First one is for periodicity 1 minute and the next one is for periodicity 4 minutes.