[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Re: Matching User Input Date Parameters



PureBytes Links

Trading Reference Links

Mike,

Thank you.  I can't say that I completely understand it yet, but I will be walking through the code until I do.

Coming from a C programming background, I am still trying to wrap my head around the AmiBroker way of using Array processing. 

Thanks again, and I will let you know how it goes into the Flexible Parameters system.

Blair

Mike wrote:

Hi,

I've modified your grouping code to give a 100 times speedup over
4000 bars.

I simplified the logic to do everything as array manipulations rather
than within a loop. Only the plotting of text was left in a loop.

I suspect that your biggest problem was the repeated assignment of an
entire array to a single array element at each bar in the loop.

e.g.
LP1[k] = iif( varget( "L" + i ) >= 1, 1, 0 );

IIF performs a calculation of the entire array, which you were
evalutating at every bar.

As always, hand check everything before accepting it as valid.

Mike

// Paramaters Organized by Grouping

// Date Parameters - in Numeric form (DateNum values)
// Level Parameters (0-9)
// Text Parameters for On Screen Comments
// Symbol Parameters 0-4 (0 - None, 1 - Triangle, 2 -
D1 = Param( "D01", 1081010, 1000101, 1101231, 1 );
L1 = Param( "L01", 2, 0, 9, 1 );
T1 = ParamStr( "T01", "Text 01" );
S1 = Param( "S01", 2, 0, 4, 1 );
D2 = Param( "D02", 1081003, 1000101, 1101231, 1 );
L2 = Param( "L02", 8, 0, 9, 1 );
T2 = ParamStr( "T02", "Text 02" );
S2 = Param( "S02", 4, 0, 4, 1 );
D3 = Param( "D03", 1080926, 1000101, 1101231, 1 );
L3 = Param( "L03", 3, 0, 9, 1 );
T3 = ParamStr( "T03", "Text 03" );
S3 = Param( "S03", 3, 0, 4, 1 );
D4 = Param( "D04", 1081017, 1000101, 1101231, 1 );
L4 = Param( "L04", 1, 0, 9, 1 );
T4 = ParamStr( "T04", "Text 04" );
S4 = Param( "S04", 4, 0, 4, 1 );
D5 = Param( "D05", 1081024, 1000101, 1101231, 1 );
L5 = Param( "L05", 7, 0, 9, 1 );
T5 = ParamStr( "T05", "Text 05" );
S5 = Param( "S05", 1, 0, 4, 1 );
D6 = Param( "D06", 1081031, 1000101, 1101231, 1 );
L6 = Param( "L06", 2, 0, 9, 1 );
T6 = ParamStr( "T06", "Text 06" );
S6 = Param( "S06", 1, 0, 4, 1 );
D7 = Param( "D07", 1081107, 1000101, 1101231, 1 );
L7 = Param( "L07", 5, 0, 9, 1 );
T7 = ParamStr( "T07", "Text 07" );
S7 = Param( "S07", 3, 0, 4, 1 );
D8 = Param( "D08", 1080919, 1000101, 1101231, 1 );
L8 = Param( "L08", 6, 0, 9, 1 );
T8 = ParamStr( "T08", "Text 08" );
S8 = Param( "S08", 2, 0, 4, 1 );
D9 = Param( "D09", 0, 0, 1101231, 1 );
L9 = Param( "L09", 0, 0, 9, 1 );
T9 = ParamStr( "T09", "" );
S9 = Param( "S09", 0, 0, 4, 1 );
D10 = Param( "D10", 0, 0, 1101231, 1 );
L10 = Param( "L10", 0, 0, 9, 1 );
T10 = ParamStr( "T10", "" );
S10 = Param( "S10", 0, 0, 4, 1 );

// Set up the Color Arrays
color1 = colortan;
color2 = colordarkyellow;
color3 = colorpink;
color4 = colorturquoise;
color5 = colorgreen;
color6 = coloryellow;
color7 = colorred;
color8 = colorblue;
color9 = colorgrey50;

// Set up the Shapes Arrays
shape0 = shapedowntriangle;
shape1 = shapeuptriangle;
shape2 = shapecircle;
shape3 = shapesquare;
shape4 = shapestar;

// Set Both DateNum vs BarIndex
dn = DateNum();
bi = BarIndex();

// Initialize the Plot control array
plotcontrol = 0;

// Initialize the Level Plot control Arrays
LP1 = LP2 = LP3 = LP4 = LP5 = LP6 = LP7 = LP8 = LP9 = 0;

// Initialze the Plot Shape control array
pshape = shapeNone;

// Initialize cause of plot
cause = 0;

for (i = 1; i <= 10; i++) {
D = VarGet("D" + i);
S = VarGet("S" + i);
L = VarGet("L" + i);

trigger = (D == dn);
cause = IIF(trigger, i, cause);
plotcontrol = IIF(trigger, 1, plotcontrol);
pshape = IIF(trigger, VarGet("shape" + S), pshape);

for (j = 1; j <= 9; j++) {
LP = VarGet("LP" + j);
VarSet("LP" + j, IIF(trigger, L >= j, LP));
}
}

// For Reference - Plot the Zero and One Level
Plot(0, "Zero", colorred, styleline + stylenolabel + stylenotitle);
Plot(1, "One", colorred, styleline + stylenolabel + stylenotitle);

// Plot the text
for (i = 0; i < BarCount; i++) {
if (cause[i]) {
PlotText(" " + VarGetText("T" + cause[i]), i, VarGet("L" + cause
[i]) * 0.11, VarGet("color" + VarGet("L" + cause[i])));
}
}

// Now handle plotting the stack of shapes
for (i = 1; i <= 9; i++) {
Plotshapes(plotcontrol * VarGet("LP" + i) * pshape, VarGet("color"
+ i), 0, 0, (i - 1) * 15);
}

--- In amibroker@xxxxxxxxxps.com, Snoopy <snoopy.pa30@...> wrote:
>
> AmiBroker Group,
>
> I am attaching Test code so you can run it and see what I am trying
to
> do. My analysis involves Manually determining these dates and
levels.
> No way yet to have AFL calculate them for me.
>
> DatesTest01.afl has the parameters Grouped by type (Date, Level,
Text,
> Symbol)
> DatesTest02.afl has the Parameters Grouped by input (one block for
each
> input set)
>
> I have put in valid daily values so you will see some results. You
will
> have to Manually adjust the size of this chart pane to have the
Text
> Align with the Top Symbol.
>
> Mike - Thanks for your response. I liked the idea of inputting the
> dates in DateNum format that you showed in your response. I used
it
> here in the tests.
>
> As I expect my analysis to involve anywhere from 10-50 points, you
can
> (hopefully) see the potential problems.
>
> I am using Dennis Brown's Flexible Parameters to handle the
Parameter
> screen for user input, but hope that someone on the list here can
> suggest a more efficient / better method to do what I have shown.
When
> I want to scale it up to the 50-100 points, I am afraid the
processing
> time will make it impractical.
>
> Any and all suggestions appreciated.
>
> Thanks in advance...
>
>
>
>
>
>
>
> /*
> Simple Test of Matching Dates 02
>
> Parameters Organized by Grouping
>
> Quick Summary of System
> User inputs the Date, Level, and Comment for a Level event
> A level (1-9) event sets all levels below it
> i.e. If on Date 3 you have a Level 6 event, then
> you need to show Levels 1-6 (symbols) for
that date
>
> Desired Results:
> A STACK (Level #) of Colored symbols with the Text
>
> Issues:
> 1. How to Process
> 2. How to Scale up to 20-50-100 Dates
> 3. When Scaling up - Managing the Parameters Screen
> 4. In this example - the order/grouping of the parameters
> 5. Combining PlotShapes (Pixel based Placement) and PlotText
($ based Placement)
>
> Resolutions:
> 1. Ask the Group
> 2. Ask the Group
> 3. Using the Flexible Parameters from Dennis Brown
> 4. Using the Flexible Parameters in live system to Group
Parameters and build Sub Menus
> 5. Plot indicator in seperate chart pane and manually size
scale in 0-1 range
>
> */
> // Paramaters Organized by Grouping
>
> // Date Parameters - in Numeric form (DateNum values)
> // Level Parameters (0-9)
> // Text Parameters for On Screen Comments
> // Symbol Parameters 0-4 (0 - None, 1 - Triangle, 2 -
> D1 = Param("D01", 1081010, 1000101, 1101231, 1);
> L1 = Param("L01", 2, 0, 9, 1);
> T1 = ParamStr("T01", "Text 01");
> S1 = Param("S01", 2, 0, 4, 1);
> D2 = Param("D02", 1081003, 1000101, 1101231, 1);
> L2 = Param("L02", 8, 0, 9, 1);
> T2 = ParamStr("T02", "Text 02");
> S2 = Param("S02", 4, 0, 4, 1);
> D3 = Param("D03", 1080926, 1000101, 1101231, 1);
> L3 = Param("L03", 3, 0, 9, 1);
> T3 = ParamStr("T03", "Text 03");
> S3 = Param("S03", 3, 0, 4, 1);
> D4 = Param("D04", 1081017, 1000101, 1101231, 1);
> L4 = Param("L04", 1, 0, 9, 1);
> T4 = ParamStr("T04", "Text 04");
> S4 = Param("S04", 4, 0, 4, 1);
> D5 = Param("D05", 1081024, 1000101, 1101231, 1);
> L5 = Param("L05", 7, 0, 9, 1);
> T5 = ParamStr("T05", "Text 05");
> S5 = Param("S05", 1, 0, 4, 1);
> D6 = Param("D06", 1081031, 1000101, 1101231, 1);
> L6 = Param("L06", 2, 0, 9, 1);
> T6 = ParamStr("T06", "Text 06");
> S6 = Param("S06", 1, 0, 4, 1);
> D7 = Param("D07", 1081107, 1000101, 1101231, 1);
> L7 = Param("L07", 5, 0, 9, 1);
> T7 = ParamStr("T07", "Text 07");
> S7 = Param("S07", 3, 0, 4, 1);
> D8 = Param("D08", 1080919, 1000101, 1101231, 1);
> L8 = Param("L08", 6, 0, 9, 1);
> T8 = ParamStr("T08", "Text 08");
> S8 = Param("S08", 2, 0, 4, 1);
> D9 = Param("D09", 0, 0, 1101231, 1);
> L9 = Param("L09", 0, 0, 9, 1);
> T9 = ParamStr("T09", "");
> S9 = Param("S09", 0, 0, 4, 1);
> D10 = Param("D10", 0, 0, 1101231, 1);
> L10 = Param("L10", 0, 0, 9, 1);
> T10 = ParamStr("T10", "");
> S10 = Param("S10", 0, 0, 4, 1);
>
> // Set up the Color Arrays
> color0 = colorwhite; // I Am using a Black background
> color1 = colortan;
> color2 = colordarkyellow;
> color3 = colorpink;
> color4 = colorturquoise;
> color5 = colorgreen;
> color6 = coloryellow;
> color7 = colorred;
> color8 = colorblue;
> color9 = colorgrey50;
>
>
> // Set up the Shapes Arrays
> shape0 = shapedowntriangle;
> shape1 = shapeuptriangle;
> shape2 = shapecircle;
> shape3 = shapesquare;
> shape4 = shapestar;
>
> // Set Both DateNum vs BarIndex
> dn = DateNum();
> bi = BarIndex();
>
> // Due to the STACK of PlotShapes Required - How do I Process
this...??
>
> // Initialize the Plot control array
> plotcontrol = 0;
>
> // Initialize the Level Plot control Arrays
> LP0 = LP1 = LP2 = LP3 = LP4 = LP5 = LP6 = LP7 = LP8 = LP9 = LP10 =
0;
>
> // Initialze the Plot Shape control array
> pshape = shapenone;
>
> // loop through all bars to see if it matches a date and then set
the control arrays
> for(k=1; k<BarCount; k++)
> {
> i=0; // set the starting value for the do loop
> do
> {
> i++; // Increment the looping variable
> pshape[k] = VarGet("shape" + VarGet("S"+i));
>
> if(dn[k] == VarGet("D"+i))
> {
> plotcontrol[k] = 1;
>
> // Set the shape to Plot
> // Do I need to get this plottext statement moved? How?
> // plottext( text, x, y -
in Dollars (Y Scale), color, bkcolor);
> PlotText(" " + VarGetText("T"+i), k,
(VarGet("L"+i)-1)*0.11, VarGet("color"+VarGet("L"+i)));
> // now set the Level Plot array values
> /* Method 1 - appears to not work
> for (m=1; m<11; m++)
> {
> VarSet("LP" + m + "[" + k + "]", iif
(VarGet("L"+i)>=1,1,0));
> }
> */
> /* Method 2 - BFI - Brut Force and Ignorance
> */
> LP1[k] = iif(varget("L"+i)>=1,1,0);
> LP2[k] = iif(varget("L"+i)>=2,1,0);
> LP3[k] = iif(varget("L"+i)>=3,1,0);
> LP4[k] = iif(varget("L"+i)>=4,1,0);
> LP5[k] = iif(varget("L"+i)>=5,1,0);
> LP6[k] = iif(varget("L"+i)>=6,1,0);
> LP7[k] = iif(varget("L"+i)>=7,1,0);
> LP8[k] = iif(varget("L"+i)>=8,1,0);
> LP9[k] = iif(varget("L"+i)>=9,1,0);
>
> break; // to break out of the DO LOOP (I
Hope)
> // Assumption that Actual
Date only entered Once!!
>
> }
> } while( i<11);
> }
>
> // For Reference - Plot the Zero and One Level
> //plot(Array, name, color, style, min, max, xshift);
> Plot(0,"Zero", colorred, styleline+stylenolabel+stylenotitle);
> Plot(1,"One", colorred, styleline+stylenolabel+stylenotitle);
>
>
> // Now handle plotting the stack of shapes
> for(i=1; i<11; i++)
> {
> // plotshapes(
shape, color, layer,
yposition, offset);
> Plotshapes(plotcontrol*VarGet("LP" + i)*pshape, VarGet
("color"+i), 0, 0, (i-1)*15);
> }
>
> /*
> Simple Test of Matching Dates
>
> Parameters Organized by Type
>
> Quick Summary of System
> User inputs the Date, Level, and Comment for a Level event
> A level (1-9) event sets all levels below it
> i.e. If on Date 3 you have a Level 6 event, then
> you need to show Levels 1-6 (symbols) for
that date
>
> Desired Results:
> A STACK (Level #) of Colored symbols with the Text
>
> Issues:
> 1. How to Process
> 2. How to Scale up to 20-50-100 Dates
> 3. When Scaling up - Managing the Parameters Screen
> 4. In this example - the order/grouping of the parameters
> 5. Combining PlotShapes (Pixel based Placement) and PlotText
($ based Placement)
>
> Resolutions:
> 1. Ask the Group
> 2. Ask the Group
> 3. Using the Flexible Parameters from Dennis Brown
> 4. Using the Flexible Parameters in live system to Group
Parameters and build Sub Menus
> 5. Plot indicator in seperate chart pane and manually size
scale in 0-1 range
>
> */
>
> // Date Paramaters - in Numeric form (DateNum values)
> D1 = Param("D01", 1081010, 1000101, 1101231, 1);
> D2 = Param("D02", 1081003, 1000101, 1101231, 1);
> D3 = Param("D03", 1080926, 1000101, 1101231, 1);
> D4 = Param("D04", 1081017, 1000101, 1101231, 1);
> D5 = Param("D05", 1081024, 1000101, 1101231, 1);
> D6 = Param("D06", 1081031, 1000101, 1101231, 1);
> D7 = Param("D07", 1081107, 1000101, 1101231, 1);
> D8 = Param("D08", 1080919, 1000101, 1101231, 1);
> D9 = Param("D09", 0, 0, 1101231, 1);
> D10 = Param("D10", 0, 0, 1101231, 1);
>
> // Level Parameters
> L1 = Param("L01", 2, 0, 9, 1);
> L2 = Param("L02", 8, 0, 9, 1);
> L3 = Param("L03", 3, 0, 9, 1);
> L4 = Param("L04", 1, 0, 9, 1);
> L5 = Param("L05", 7, 0, 9, 1);
> L6 = Param("L06", 2, 0, 9, 1);
> L7 = Param("L07", 5, 0, 9, 1);
> L8 = Param("L08", 6, 0, 9, 1);
> L9 = Param("L09", 0, 0, 9, 1);
> L10 = Param("L10", 0, 0, 9, 1);
>
> // Text Parameters for On Screen Comments
> T1 = ParamStr("T01", "Text 01");
> T2 = ParamStr("T02", "Text 02");
> T3 = ParamStr("T03", "Text 03");
> T4 = ParamStr("T04", "Text 04");
> T5 = ParamStr("T05", "Text 05");
> T6 = ParamStr("T06", "Text 06");
> T7 = ParamStr("T07", "Text 07");
> T8 = ParamStr("T08", "Text 08");
> T9 = ParamStr("T09", "");
> T10 = ParamStr("T10", "");
>
> // Symbol Parameters
> S1 = Param("S01", 2, 0, 4, 1);
> S2 = Param("S02", 4, 0, 4, 1);
> S3 = Param("S03", 3, 0, 4, 1);
> S4 = Param("S04", 4, 0, 4, 1);
> S5 = Param("S05", 1, 0, 4, 1);
> S6 = Param("S06", 1, 0, 4, 1);
> S7 = Param("S07", 3, 0, 4, 1);
> S8 = Param("S08", 2, 0, 4, 1);
> S9 = Param("S09", 0, 0, 4, 1);
> S10 = Param("S10", 0, 0, 4, 1);
>
> // Set up the Color Arrays
> color0 = colorwhite; // I Am using a Black background
> color1 = colortan;
> color2 = colordarkyellow;
> color3 = colorpink;
> color4 = colorturquoise;
> color5 = colorgreen;
> color6 = coloryellow;
> color7 = colorred;
> color8 = colorblue;
> color9 = colorgrey50;
>
> // Set up the Shapes Arrays
> shape0 = shapedowntriangle;
> shape1 = shapeuptriangle;
> shape2 = shapecircle;
> shape3 = shapesquare;
> shape4 = shapestar;
>
> // Set Both DateNum vs BarIndex
> dn = DateNum();
> bi = BarIndex();
>
> // Due to the STACK of PlotShapes Required - How do I Process
this...??
>
> // Initialize the Plot control array
> plotcontrol = 0;
>
> // Initialize the Level Plot control Arrays
> LP0 = LP1 = LP2 = LP3 = LP4 = LP5 = LP6 = LP7 = LP8 = LP9 = LP10 =
0;
>
> // Initialze the Plot Shape control array
> pshape = shapenone;
>
> // loop through all bars to see if it matches a date and then set
the control arrays
> for(k=1; k<BarCount; k++)
> {
> i=0; // set the starting value for the do loop
> do
> {
> i++; // Increment the looping variable
> pshape[k] = VarGet("shape" + VarGet("S"+i));
>
> if(dn[k] == VarGet("D"+i))
> {
> plotcontrol[k] = 1;
>
> // Set the shape to Plot
> // Do I need to get this plottext statement moved? How?
> // plottext( text, x, y -
in Dollars (Y Scale), color, bkcolor);
> PlotText(" " + VarGetText("T"+i), k,
(VarGet("L"+i)-1)*0.11, VarGet("color"+VarGet("L"+i)));
> // now set the Level Plot array values
> /* Method 1 - appears to not work
> for (m=1; m<11; m++)
> {
> VarSet("LP" + m + "[" + k + "]", iif
(VarGet("L"+i)>=1,1,0));
> }
> */
> /* Method 2 - BFI - Brut Force and Ignorance
> */
> LP1[k] = iif(varget("L"+i)>=1,1,0);
> LP2[k] = iif(varget("L"+i)>=2,1,0);
> LP3[k] = iif(varget("L"+i)>=3,1,0);
> LP4[k] = iif(varget("L"+i)>=4,1,0);
> LP5[k] = iif(varget("L"+i)>=5,1,0);
> LP6[k] = iif(varget("L"+i)>=6,1,0);
> LP7[k] = iif(varget("L"+i)>=7,1,0);
> LP8[k] = iif(varget("L"+i)>=8,1,0);
> LP9[k] = iif(varget("L"+i)>=9,1,0);
>
> break; // to break out of the DO LOOP (I
Hope)
> // Assumption that Actual
Date only entered Once!!
>
> }
> } while( i<11);
> }
>
> // For Reference - Plot the Zero and One Level
> //plot(Array, name, color, style, min, max, xshift);
> Plot(0,"Zero", colorred, styleline+stylenolabel+stylenotitle);
> Plot(1,"One", colorred, styleline+stylenolabel+stylenotitle);
>
>
> // Now handle plotting the stack of shapes
> for(i=1; i<11; i++)
> {
> // plotshapes(
shape, color, layer,
yposition, offset);
> Plotshapes(plotcontrol*VarGet("LP" + i)*pshape, VarGet
("color"+i), 0, 0, (i-1)*15);
>


--
Snoopy
"Still trying to shoot down that Red Baron"
__._,_.___

**** IMPORTANT ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

*********************
TO GET TECHNICAL SUPPORT from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
*********************

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html

*********************************




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___