# Data mine/ optimize for basic price action patterns

Is there a way to use the optimization feature or loop or some other way to data mine simple price action patterns?

For example, I would like to use just the O,H,L,C values from the last 3 or 4 days to find which is the most profitable price pattern.

In other software it might be written like below where numeric values can be optimized:

`````` Buy = O[1] > O[2] AND C[1] > H[2] AND H[1] < H[3];
``````

Something like below, but where you can cycle through all the different combinations:

``````O1 = Ref(O,-1);
O2 = Ref(O,-2);
O3 = Ref(O,-3);
H1 = Ref(H,-1);
H2 = Ref(H,-2);
H3 = Ref(H,-3);
L1 = Ref(L,-1);
L2 = Ref(L,-2);
L3 = Ref(L,-3);
C1 = Ref(C,-1);
C2 = Ref(C,-2);
C3 = Ref(C,-3);

Pattern1 = O1>O2 AND H1>H2 AND C1>C2;
Pattern2 = O1>O2 AND H1>H2 AND C1<C2;
Pattern3 = O1>O2 AND H1<H2 AND C1>C2;
//Pattern4 = ;

``````

I guess the problem is there are millions of possible combinations but thought Iâ€™d pose the question to see if anyone knows how to do it in AB. Hope I explained well enough.

Thanks

1 Like

Sure.

(Not sure if you get it.)

``````/// by fxshrat

start = 1; end = 3;
for( i = start ; i <= end; i++ ) {
VarSet( "O" + i, Ref( O, -i) );
VarSet( "H" + i, Ref( H, -i) );
VarSet( "L" + i, Ref( L, -i) );
VarSet( "C" + i, Ref( C, -i) );
}

Open1 = Optimize ( "Open1", 1, start, end, 1);
Open2 = Optimize ( "Open2", 1, start, end, 1);

High1 = Optimize ( "High1", 1, start, end, 1);
High2 = Optimize ( "High2", 1, start, end, 1);

Close1 = Optimize ( "Close1", 1, start, end, 1);
Close2 = Optimize ( "Close2", 1, start, end, 1);

// Currently three pattern set
PatternOpt = Optimize( "Pattern", 1, 1, 3, 1 );

VarO1 = VarGet( "O" + Open1 );
VarO2 = VarGet( "O" + Open2 );
VarH1 = VarGet( "H" + High1 );
VarH2 = VarGet( "H" + High2 );
VarC1 = VarGet( "C" + Close1 );
VarC2 = VarGet( "C" + Close2 );

Pattern1 = VarO1>VarO2 AND VarH1>VarH2 AND VarC1>VarC2;
Pattern2 = VarO1>VarO2 AND VarH1>VarH2 AND VarC1<VarC2;
Pattern3 = VarO1>VarO2 AND VarH1<VarH2 AND VarC1>VarC2;
//Pattern4 = ;

SetPositionSize( 100, spsShares );

if( Status( "actionex" ) == actionExOptimizeBacktest  ) { // if Optimization

Exclude = High1 == High2 || Open1 == Open2 || Close1 == Close2;

Buy = VarGet( "Pattern" + PatternOpt );

} else { // if normal backtest

// set VarGet names according to start/end settings above
Buy = VarGet( "O1" ) > VarGet( "O3" ) AND VarGet( "H3" ) > VarGet( "H1" ) AND VarGet( "C1" ) >  VarGet( "C2" );
}

Sell = 0;

bars = 5;
ApplyStop( stopTypeNBar, stopModeBars, bars, True );

// No short
Short = Cover = 0;
``````
19 Likes

Thanks, will try and work it through

@marwood There is a chapter in Howard Bandyâ€™s book â€śQuantitative Trading Systemsâ€ť that also has some AmiBroker ideas (and an afl) on Price Pattern analysis.

And on the old forum another idea from Aron P.,
https://groups.yahoo.com/neo/groups/amibroker/conversations/messages/191409

Good luck, and I would be interested to hear if you make some progress.

3 Likes

i know very little about Data Mining but after a little conversation with Aron I realized I was using similar techniques for like 15 years but didnâ€™t know it was called Data Mining.

To get started a bit again with the topic I made some code where you manually select a pattern (yellow in video) and then it looks for the 10 best fitting patterns (pink in video) within the same symbol (or data array). The idea now of course is to use the 10 best fitting patterns (in pink) to make an assumption whether the price will move up or down for the selected pattern, see little video

https://tinyurl.com/yan4cdls

to compare prices along the data array, I used normalization. I found this article helpful with that:

1 Like

video doesnâ€™t show. Wanted to remove post again but not possible. Moderator please remove that data mining post thanks