Matrix code not working for large db

The below code works perfectly for db containg 1 min data upto 10 days but failing when run for db containing 1 min data for 2 months.


profitTargetHitDistance_1= IIf( VarGet( "profitTarget1iHitConditionHasBeenTrueInThisSetup" ), ValueWhen( VarGet( "profitTarget1iHitOnThisBar" ), VarGet( "profitTarget1iHitDistanceFromPatternFoundi" ) ), 10000 ) ;
    profitTargetHitDistance_2= IIf( VarGet( "profitTarget2iHitConditionHasBeenTrueInThisSetup" ), ValueWhen( VarGet( "profitTarget2iHitOnThisBar" ), VarGet( "profitTarget2iHitDistanceFromPatternFoundi" ) ), 10000 ) ;
    profitTargetHitDistance_3= IIf( VarGet( "profitTarget3iHitConditionHasBeenTrueInThisSetup" ), ValueWhen( VarGet( "profitTarget3iHitOnThisBar" ), VarGet( "profitTarget3iHitDistanceFromPatternFoundi" ) ), 10000 ) ;
    profitTargetHitDistance_4= IIf( minRetracementWave5XConditionHasBeenTrueInThisSetupWithOpenPosition,
    ValueWhen( minRetracementWave5XConditionMetOnThisBarWithOpenPosition, minRetracementWave5XConditionMetWithOpenPositionDistanceFromPatternFoundi ), 10000 ) ;


    profitTargetHitSequenceMatrix = Matrix( 4, 2, 0 );    
    //profitTargetHitSequenceMatrix = MxFromString( "{ { 1, " + VarGet( "profitTargetHitDistance_1" ) + "}, { 2, " + VarGet( "profitTargetHitDistance_2" ) + "}, { 3, " + VarGet( "profitTargetHitDistance_3" ) + "}, { 4, " + VarGet( "profitTargetHitDistance_4" ) + "}}" );
    //profitTargetHitSequenceMatrixSorted = MxSortRows( profitTargetHitSequenceMatrix, true, 1 ) ;
    for (i=0;i<BarCount;i++){
    profitTargetHitSequenceMatrix[0][0]=1;profitTargetHitSequenceMatrix[0][1]=profitTargetHitDistance_1[i];
    profitTargetHitSequenceMatrix[1][0]=2;profitTargetHitSequenceMatrix[1][1]=profitTargetHitDistance_2[i];
    profitTargetHitSequenceMatrix[2][0]=3;profitTargetHitSequenceMatrix[2][1]=profitTargetHitDistance_3[i];
    profitTargetHitSequenceMatrix[3][0]=4;profitTargetHitSequenceMatrix[3][1]=profitTargetHitDistance_4[i];
    }
   
    profitTargetHitSequenceMatrixSorted = MxSortRows( profitTargetHitSequenceMatrix, true, 1 ) ;
profitTargetHitSequenceMatrixSortedString="{{"+profitTargetHitSequenceMatrixSorted[0][0] + ", "+ profitTargetHitSequenceMatrixSorted[0][1]+"}, "
+"{"+profitTargetHitSequenceMatrixSorted[1][0] + ", "+ profitTargetHitSequenceMatrixSorted[1][1]+"}, "
+"{"+profitTargetHitSequenceMatrixSorted[2][0] + ", "+ profitTargetHitSequenceMatrixSorted[2][1]+"}, "
+"{"+profitTargetHitSequenceMatrixSorted[3][0] + ", "+ profitTargetHitSequenceMatrixSorted[3][1]+"}}";
StaticVarSetText( Name() + chartid + "profitTargetHitSequenceMatrixSortedString", profitTargetHitSequenceMatrixSortedString );
StaticVarSet( Name() + chartid + "profitTargetHitDistance_1", profitTargetHitDistance_1 );

WHAT does "failing" mean???


That one is non sense. You do not need loop over entire BarCount if you just store single value per row.

Simply use LastValue function:

profitTargetHitSequenceMatrix = Matrix( 4, 2, 0 );

profitTargetHitSequenceMatrix[0][0] = 1;
profitTargetHitSequenceMatrix[0][1] = LastValue(profitTargetHitDistance_1);
profitTargetHitSequenceMatrix[1][0] = 2;
profitTargetHitSequenceMatrix[1][1] = LastValue(profitTargetHitDistance_2);
profitTargetHitSequenceMatrix[2][0] = 3;
profitTargetHitSequenceMatrix[2][1] = LastValue(profitTargetHitDistance_3);
profitTargetHitSequenceMatrix[3][0] = 4;
profitTargetHitSequenceMatrix[3][1] = LastValue(profitTargetHitDistance_4);

That one is unnecessary also.
Just use MxToString.

profitTargetHitSequenceMatrixSortedString = MxToString(profitTargetHitSequenceMatrixSorted); 

Your loop version stores last value to matrix also!
So it's pointless to use loop.

"Great", you just interchange words without info. Reader is as wise as before!
I repeat:
WHAT does "failing" / "incorrect" mean???

My loop stores the ith value to the matrix not the last value.

It stores single value. Single value. Single value may be last value, selected value, last visible value etc.

Your loop is point less!

If you want to store selected value instead of last value then use selected value.

profitTargetHitSequenceMatrix = Matrix( 4, 2, 0 );

profitTargetHitSequenceMatrix[0][0] = 1;
profitTargetHitSequenceMatrix[0][1] = SelectedValue(profitTargetHitDistance_1);
profitTargetHitSequenceMatrix[1][0] = 2;
profitTargetHitSequenceMatrix[1][1] = SelectedValue(profitTargetHitDistance_2);
profitTargetHitSequenceMatrix[2][0] = 3;
profitTargetHitSequenceMatrix[2][1] = SelectedValue(profitTargetHitDistance_3);
profitTargetHitSequenceMatrix[3][0] = 4;
profitTargetHitSequenceMatrix[3][1] = SelectedValue(profitTargetHitDistance_4);

Besides please don't use SMS style. "ith" is unknown.

My aim is to store the value of the bar. Any bar. Every bar. How will lastValue work here? Dont i have to iterate through 0 to barcount-1?

Do you still don't get it?
You defined your matrix size yourself!
Do you understand what your line below means?

Again... it is your line not anyone else's line.

How will that one make it possible to store values from 0 to BarCount-1 if BarCount is e.g. 100000???
If you are not competent enough then why do you want to argue here about what is stored via your code?

If you want to store entire array then you still don't need loop.
There is MxSetBlock function.

Do you have reading difficulties?
If you do not want to store last value of entire array but some other element of array then use other function extracting element of array like SelectedValue, LastVisibleValue or ...

https://www.amibroker.com/guide/h_understandafl.html

Yes but 4 x 2 matrix will be created for every bar. Right?

No, output of profitTargetHitSequenceMatrixSorted will be of last bar of barcount range which may be last bar of entire array or last visible bar or last bar of analysis range.

please explain this one thing is matrix scalar or is it created for every bar?

Answer was already given in this thread.
Read again and slowly.

But that is not what i want. I want it be processed bar by bar not just for last bar. That is why i had used loop.

Your code will store the lastvalue profitTargetHitDistance_1 variable for every bar. .

Don't annoy the hell out of me.
You start to act like troll.

I did not wrote of just LastValue.
Read entire thread for heaven's sake!

i guess i made the mistake of believing that matrix is array (array of matrices). Each bar will have a matrix of its own i thought. I was wrong. And I stand corrected. I will now find some other way. Thankyou
Is there a thing like linkedList within a linkedList. Each link of the parent list has a child list within.
Thanks again.

Not recommended but apparently you look for something along these lines.

profitTargetHitDistance_1 = O;
profitTargetHitDistance_2 = H;
profitTargetHitDistance_3 = L;
profitTargetHitDistance_4 = C;

profitTargetHitSequenceMatrix = Matrix( 4, 2, 0 );

profitTargetHitSequenceMatrix[0][0] = 1;
profitTargetHitSequenceMatrix[1][0] = 2;
profitTargetHitSequenceMatrix[2][0] = 3;
profitTargetHitSequenceMatrix[3][0] = 4;

for( i = 0; i < BarCount; i++ )
{	
	profitTargetHitSequenceMatrix[0][1] = profitTargetHitDistance_1[i];	
	profitTargetHitSequenceMatrix[1][1] = profitTargetHitDistance_2[i];	
	profitTargetHitSequenceMatrix[2][1] = profitTargetHitDistance_3[i];	
	profitTargetHitSequenceMatrix[3][1] = profitTargetHitDistance_4[i];	

	VarSet("profitTargetHitSequenceMatrix"+i, profitTargetHitSequenceMatrix);
}

n = 10;//set n (bar index)
i = Min(n, BarCount-1);
mat = VarGet("profitTargetHitSequenceMatrix"+Max(0,i));
profitTargetHitSequenceMatrixSorted = MxSortRows(mat, true, 1 );

printf(MxToString(profitTargetHitSequenceMatrixSorted)); 

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.