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

[amibroker] Re: AFL coding



PureBytes Links

Trading Reference Links

Test done. You can pass values from one chart to another. You just 
have to hold you mouth just right to do it. Here are the three 
indicator charts I used to test this. Copy each into a separate 
indicator and place the StatidVarGet indicator at the bottom. If it 
is not at the bottom the previous value is seen in the staticvarget 
code. 

When you click on the bar you will see the values. If the CCI and 
Stoch are both going up or down an buy/sell arrow will be displayed. 
Also the value of the CCI or Sto up or down condition will be 
displayed by plot. I tried to plot the CCI in the staticvarget chart 
but it does not produce the line chart. 

The CCI value does come across but the ref statement does not work. 
Only the selected value or the last value come across. If you click 
on a bar you see the value. This is where AB arrays blow my mind. If 
I set the CCI array in the staticvarget code I don't understand why 
it does not persist from that point on.

Back test does not work as I mentioned. The data from the other 
charts are needed and are not available when using AA.

But a user could indeed use this approach for combining conditions 
from various charts into buy and sell signals an auto trading 
program.  

Barry

// *****************************
// CCI code
periods = Param( "Periods", 14, 2, 30, 1 );
fCCI	= CCI( periods );
Up	= fCCI > Ref(fCCI, -1);
Dn 	= fCCI < Ref(fCCI, -1);

Plot(fCCI, "CCI", colorRed);

bi = BarIndex();
ai = SelectedValue( bi ) - bi[ 0 ]; 

Pfx = "CCI";
StaticVarSet(Pfx + "UP", Up[ai]);
StaticVarSet(Pfx + "DN", Dn[ai]);
StaticVarSet(Pfx + "CCI", fCCI[ai]); // passes CCI value

if(ParamToggle("Show arrows", "No|Yes", 1))
{
PlotShapes(Up * shapeUpArrow, colorGreen);
PlotShapes(Dn * shapeDownArrow, colorRed);

// *****************************
// Stoch %K code
pStoch 	= Param("Stoch period", 10, 1, 30, 1 );
pKavg	= Param("%K avg", 3, 1, 20, 1 );
fStoch	= StochK(pStoch, pKavg);
Up	= fStoch > Ref(fStoch, -1);
DN	= fStoch < Ref(fStoch, -1);

bi = BarIndex();
ai = SelectedValue( bi ) - bi[ 0 ]; 

Pfx = "StoK";
StaticVarSet(Pfx + "UP", Up[ai]);
StaticVarSet(Pfx + "DN", Dn[ai]);

Plot(fStoch, _DEFAULT_NAME(), colorRed);

PlotShapes(Up * shapeUpArrow, colorGreen);
PlotShapes(Dn * shapeDownArrow, colorRed);

// *****************************
// staticvarget code

bi = BarIndex();
ai = SelectedValue( bi ) - bi[ 0 ]; 

PfxCCI	= "myCCI";
PfxStoK	= "Stok";
 
CCIup[ai] = StaticVarGet(PfxCCI + "UP");
CCIdn[ai] = -1 * StaticVarGet(PfxCCI + "DN");
fCCI[ai] = -1 * StaticVarGet(PfxCCI + "CCI");

StoUp[ai] = StaticVarGet(PfxStoK+ "UP");
StoDn[ai] = -1 * StaticVarGet(PfxStoK+ "DN");
Buy  = Cover = CCIup AND stoup;
Sell = Short = CCIdn AND stodn;
PlotShapes(Buy * shapeUpArrow, colorGreen);
PlotShapes(Sell * shapeDownArrow, colorRed);
Plot(CCIup, "CCI state", colorGreen);
Plot(CCIdn, "CCI state", colorRed);
Plot(stoup, "CCI state", colorBlue);
Plot(stodn, "CCI state", colorBlack);
Plot(fCCI, "CCI value", colorGreen);
Plot(Ref(fCCI, -1), "Prev CCI value", colorGreen);


--- In amibroker@xxxxxxxxxxxxxxx, "Barry Scarborough" <razzbarry@xxx> 
wrote:
>
> Sorry for the confusion. 
> 
> I wish static vars could contain arrays too. Ain't so.
> 
> What I was saying is that if you have an indicator that calculates 
a 
> CCI then you may be able to get the current value using a static. 
If 
> the program that uses the staticvarget you could add this to an 
> array. I am assuming you are using live data and pass the data 
every 
> scan. This will not work for back test or anything like that. I 
will 
> try this later and see if it is true. If so then I will post how I 
> did it.
> 
> If I understood the original post, where the user wanted to use 
> multiple charts and then combine the output of each indicator chart 
> into a buy signal in the auto trading program. To do this the 
signal 
> could be generated in an indicator and the buy condition could be 
> passed in a static. That could be ANDed in the Buy = whatever in 
the 
> trading program. But to preserve this condition in the auto trading 
> program it would have to be assigned to an array if the user wanted 
> to plot the CCI results. 
> 
> This is no problem at all if you use includes. I explained, or I 
> tried to explain, how to use includes to accomplish this. I 
wouldn't 
> touch a DLL with a stick. 
> 
> Barry
> 
> --- In amibroker@xxxxxxxxxxxxxxx, Dennis Brown <see3d@> wrote:
> >
> > Barry,
> > 
> > I am having a tough time following this.
> > Are you saying that a single static variable can hold an array?
> > I only wish it were true.
> > You can do it with static variables, but you have to have a 
> separate  
> > variable for each element in the array.
> > 
> > AddToComposite() or disk files are the only way I know to pass 
an  
> > array between AFL charts/panes, and it can be very slow.
> > It is faster to recalculate.
> > 
> > I guess one could write a DLL that could save them like a static  
> > variable.
> > This has been discussed at length in the past.
> > 
> > BR,
> > Dennis
> > 
> > On Dec 3, 2008, at 1:54 AM, Barry Scarborough wrote:
> > 
> > >
> > > I forgot to say how to use the static var. In the using program 
> you
> > > set the static var to a local variable.
> > >
> > > Before you can do that you need to create Pfx in this module.
> > > Pfx = "CCI";
> > > Then set a local var
> > > fCCI = StaticVarGet(Pfx + "CCI");
> > > And now you have the value from the other indicator in your 
local
> > > program.
> > >
> > > If you are going to do much of this create an include with 
> constants
> > > in it and include that before all other includes and in every
> > > indicator where it will be used. Hey, now you are doing object
> > > oriented coding in AFL, neat huh. Well kinda but not really but 
> this
> > > will save you loads of time when building other systems.
> > >
> > > As I mentioned before I think includes are the way to go but
> > > programming is an art form and everyone has their own style. 
What
> > > works for you is the right way to go. But as much as you can 
look 
> far
> > > ahead.
> > >
> > > Cheers,
> > > Barry
> > >
> > > --- In amibroker@xxxxxxxxxxxxxxx, "Barry Scarborough" 
<razzbarry@>
> > > wrote:
> > >>
> > >> That is a nice idea.
> > >>
> > >> Make sure the static variables are unique, don't collide. It 
> would
> > > be
> > >> safest to use a prefix for each indicator you create. An 
example
> > > for
> > >> a CCI indicator would be
> > >> Pfx = "CCI";
> > >> fCCI = do your CCI calc here
> > >> StaticVarSet(Pfx + "CCI", fCCI);
> > >> This static var is visible to all other programs running on the
> > >> visible chart.
> > >>
> > >> Also I think that AB scans the charts from top to bottom so 
make
> > > sure
> > >> the auto trading code is at the bottom so the data delivered 
to 
> it
> > > is
> > >> fresh and not from the last scan. You can trace this and see 
what
> > >> happens.
> > >>
> > >> But, I think you are going to run into problems when you try to
> > > back
> > >> test or optimize since AA only sees the formula you are back
> > > testing.
> > >> It will not see the other charts on a worksheet.
> > >>
> > >> Another thing you can do is create an include file for each of 
> the
> > >> indicators you want to use. Include them in the auto trading
> > > program
> > >> and also in the indicators you use in the other charts but 
don't
> > > plot
> > >> them in the auto trading program. Put the parameters in the
> > > indicator
> > >> file not your auto trading file. Set the default parameter in 
the
> > >> include and all charts will stay in sync. If you add arrows at 
> the
> > >> buy points in each indicator you will see when they are
> > > contributing
> > >> to the trade condition.
> > >>
> > >> This is an example I use in my AT program:
> > >>
> > >> // cci include
> > >>
> > >> pCCI			= Param("CCI period", pCCI, 1, 20, 1);
> 	
> > >> pCCI			= Optimize("CCI period", pCCI, 1, 20, 
> 2);
> > >>
> > >> fCCI			= CCI(pCCI);
> > >> CCIlo			= fCCI < -100;
> > >> CCIhi			= fCCI > 100;
> > >> CCIup			= fCCI > Ref(fCCI, -1);
> > >> CCIdn			= fCCI < Ref(fCCI, -1);
> > >>
> > >> if(PlotTrue)
> > >>   Plot(fCCI,	"\nCCI(" + NumToStr(pCCI, 1.0) + ")", 
> colorGreen,
> > >> styleOwnScale);
> > >>
> > >> Note that I have the default parameter set to the var name 
pCCI.
> > > When
> > >> I include it I set the value before the #include line. You 
don't
> > > have
> > >> to do this but it is one way to use the same include formula in
> > > many
> > >> programs but override the parameter in the using program(s). 
Then
> > > you
> > >> can set PlotTrue = True; before the #include to tell the 
> indicator
> > >> whether to plot it or not. If would be false in your AT 
program 
> and
> > >> true in your indicator.
> > >>
> > >> Barry
> > >>
> > >> --- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@> wrote:
> > >>>
> > >>> You could try using StaticVarSet in your main pane. Then, 
refer
> > > to
> > >> the
> > >>> values using StaticVarGet in the sub panes. You might have to 
> use
> > >> the
> > >>> View | Refresh All menu item to get the other panes to update
> > > after
> > >>> making any changes in the main pane, else activate each one in
> > > turn
> > >> to
> > >>> have them update automatically upon activation.
> > >>>
> > >>> Mike
> > >>>
> > >>> --- In amibroker@xxxxxxxxxxxxxxx, "brianw468" <wild21@> wrote:
> > >>>>
> > >>>> Can anyone help with the following, please:-
> > >>>> 1. I am developing an AFL to generate buy and sell signals by
> > >> combining
> > >>>> different indicators with variable parameters (to be
> > > optimised).
> > >> I
> > >>>> would like to generate a plot with price and one indicator in
> > > the
> > >> top
> > >>>> pane, and the other indicators in separate panes below this, 
to
> > >> reduce
> > >>>> clutter in the plots.
> > >>>> I know I could simply set up separate panes with the
> > > appropriate
> > >>>> indicators - BUT then the parameters would not be tied to 
those
> > >> used in
> > >>>> the main pane. Changing parameter values and ensuring
> > > consistency
> > >>>> across the panes would then become a chore.
> > >>>> 2. I had thought that the SECTION commands might help here, 
but
> > >> that
> > >>>> doesn't seem to be the case. In fact, on checking the
> > >> documentation I
> > >>>> can't find when it is either necessary or desirable to use
> > > these
> > >>>> commands. Does anyone know?
> > >>>> TIA
> > >>>>
> > >>>> Brian
> > >>>>
> > >>>
> > >>
> > >
> > >
> > >
> > > ------------------------------------
> > >
> > > **** 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
> > >
> > > *********************************
> > > Yahoo! Groups Links
> > >
> > >
> > >
> >
>



------------------------------------

**** 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

*********************************
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/