First: Thanks for your help on this... much appreciated.
Here is my code that I am trying to get to work. I just need to get the concepts in my head and I maybe self sufficient.
I am trying to set a flag and capture the bar number, if the BUY comes on, and we don't have a new bar, then ignore it. I want to plot the arrow AT the price (the close at that instant) the buy came on. And leave it on. It is complaining about my variable BuyFlag... "you cannot use array here, please use [] to access array elements." Will my arrow be pointing to the price the instant the indicator came on ?
This is how I am thinking, but it may not be the right way, please feel free to change the whole method.
Also, if I alter the signal and save the file, will that change be reapplied to the entire range of bars - will execution start from bar 0 to latest ? Or do I have to manually loop through all the bars and calculate the indicator again. This is the concepts part I need in my head.
Thanks.
_SECTION_BEGIN("Test Indicator");
SetBarsRequired(10000, 10000);
#pragma nocache
#include_once <PYMF Utility Functions.afl>
// get the pararmeters
TShortLen = Param( "T3 Short Len", 3, 3, 50, 1 ); // for T3
TMedLen = Param( "T5 Med Len", 5, 3, 50, 1 ); // for T5
TLongLen = Param( "T8 Long Len", 8, 3, 50, 1 ); // for T8
TTrendLen = Param( "T21 Trend Len", 13, 3, 50, 1 ); // for T21
TilsonFactor = Param( "Tilson Factor", .618, .0001, 1, .0001 ); // for Tilson T3 factor
TilsonSeparation = Param( "T3-5 Separation", .120, 3, 50, .0001 ); // for T3 and T5 differnce
CCIShortLen = Param( "CCI Short Len", 3, 3, 50, 1 ); // for CCI Pivots
CCIMedLen = Param( "CCI Med Len", 14, 3, 50, 1 ); // for CCI Pivots
CCILongLen = Param( "CCI Long Len", 50, 3, 200, 1 ); // for CCI Pivots
CCIHighLimit = Param( "CCI High Limit", 80, 0, 300, 1 ); // for CCI sells
CCILowLimit = Param( "CCI Low Limit", -80, 0, -300, -1 ); // for CCI buys
EMALen = Param( "EMA Len", 34, 3, 200, 1 ); // EMA average length
EMASeparation = Param( "EMA Separation", .1, 3, 200, 0001 ); // EMA separation
OutputFilePathOnly = ParamStr( "Output File path", "C:\\TEMP\\AMI\\"); // Output file path
TraceProgram = ParamToggle( "DebugProgram", "No|Yes", default=1 ); // do we want to turn on debugging
// this is how I thought I should initialize my variables - this give an error
//boolean BuyFlag = False;
// get the current bar, so we know when we get a new bar for the signals
BarNumber = BarIndex();
CurrentBar = EndValue( BarNumber );
if ( BeginValue( BarIndex() == 0) ) // first bar, reset all the flags
{
CurrentBar = -1;
LastBar = 0;
_TRACE ( "First Bar");
}
if (LastBar == CurrentBar )
{
_TRACE ( TraceProgram, "Same Bar: BarIndex=" + CurrentBar );
} else {
_TRACE ( "New Bar BarIndex=" + CurrentBar );
// ok, new bar, reset the flags for new signals
CheckBuy = True;
CheckSell = True;
CheckShort = True;
CheckCover = True;
}
// only set these on once per bar, if they come on, the they stay on
// just dummy signals for now until we get the flags sorted out.
BuyFlag = Cross( Close, EMA(Close,9) );
if (BuyFlag == False AND CheckBuy == True )
{
_TRACE ( "New BUY at bar: " + CurrentBar );
Buy = True;
CheckBuy = False;
PlotShapes( Buy*shapeUpArrow, colorWhite ,0,Graph0,-35 );
}
SellFlag = Cross( EMA(Close,9), Close );
if (SellFlag == True AND CheckSell == True )
{
_TRACE ( "New SELL at bar: " + CurrentBar );
Sell = True;
CheckSell = False;
PlotShapes( Sell*shapeSmallDownTriangle, colorWhite,0,Graph0,-55 );
}
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
ShortFlag = Cross( EMA(Close,9), Close );
if (ShortFlag == True AND CheckShort == True )
{
_TRACE ( "New SHORT at bar: " + CurrentBar );
Short = True;
CheckShort = False;
PlotShapes( Short*shapeDownArrow, colorBrightGreen, 0,Graph0, -35 );
}
CoverFlag = Cross( Close, EMA(Close,9) );
if (CoverFlag == True AND CheckCover == True )
{
_TRACE ( "New Cover at bar: " + CurrentBar );
Cover = True;
CheckCover = False;
PlotShapes( Cover*shapeSmallUpTriangle, colorBrightGreen ,0,Graph0,-55 );
}
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);
// last thing we do is to save the current bar so we don't do this again
LastBar = EndValue( BarNumber );
_SECTION_END();
-----amibroker@xxxxxxxxxxxxxxx wrote: -----
To: <amibroker@xxxxxxxxxxxxxxx>
From: "cstrader" <cstrader232@xxxxxxxxxxxx>
Sent by: amibroker@xxxxxxxxxxxxxxx
Date: 01/23/2006 11:11PM
Subject: Re: [amibroker] Bar concepts and formula execution help
Try putting this line as the first line of your code:
Setbarsrequired(10000, 10000);
This might help with your problem of not all of the bars being shown in the
_trace.
The problem of signals coming and going within a bar is not real clear to
me. You have to remember that, unless you are looping, AFL works with
arrays. I think TS does not and it may take you a while to get used to them
(in the end you'll be happy you did). Array actions that occur on later
bars can indeed change things on earlier bars.
I think you might need to post some of your code.
----- Original Message -----
From: "clarusinnovation" <mfishburn@xxxxxxxxxxxxxxxxxxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Monday, January 23, 2006 10:59 PM
Subject: [amibroker] Bar concepts and formula execution help
> Hi,
>
> I am struggling with the concepts of bars. I am a Tradestation convert
> to Ami. In Tradestation when I applied a new indicator, or system, the
> code would execute from Bar 0 to the latest bar (say 1500). Each bar
> would be like a new bar until bar 1500 is reached. How does this work
> in Ami.
>
> When I apply an indicator in Ami, things get plotted, but I don't get
> how the bar index is being used. I have put up DebugView and have
> tried to _TRACE with print outs, but it doesn't start from bar 0 to
> the latest bar....
>
> I need to understand that concept.
>
> I need to have a buy come on once in a bar. sometimes my conditions go
> on or off in the bar and the arrow shows up and then disappears. I
> can't have that if I have transmitted the order and it got filled. So,
> if buy comes on, I want to leave it on until I get a new bar and then
> it is a new ball game.
>
> I know you can help me with the indicator, but please help me think
> and figure out how this thing works.
>
> Thanks a lot.
>
> Mark
>
>
>
>
>
>
>
> Please note that this group is for discussion between users only.
>
> To get support from AmiBroker please send an e-mail directly to
> SUPPORT {at} amibroker.com
>
> For other support material please check also:
> http://www.amibroker.com/support.html
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>