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

[amibroker] Re: Static var help



PureBytes Links

Trading Reference Links

mike, 

what you are saying makes alot of sense. Can you do the same with sigscale out and showing arrows. Meaning to show a trade arrow when a sigscaleout takes place ( part of the trade is exited). Either by using turn trade arrows on, or by using the addtocomposite?? 

thanks
zeek 
-

-- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@xxx> wrote:
>
> 
> The problem with what you are trying to do is that it is entirely
> dependent upon the date range.
> 
> For example; In one date range the Buy might occur first meaning that
> any subsequent Short would have to be ignored until the Sell. Whereas
> using a different date range a Short might occur first meaning that any
> subsequent Buy would have to be ignored until the Cover.
> 
> The other problem is that it ignores portfolio limitations. Presumably
> you are doing this because you want to see actual positions. Charting
> alone can not do this for you (technically you could, but it would be a
> mamoth amount of code and excruciatingly slow).
> 
> So, if you just want to see an accurate chart (as opposed to trying to
> use the logic for signal generation), then the most reliable thing to do
> would be to remove the PlotSymbols code from your AFL entirely, then run
> a backtest (showing list of trades), then right click on the list of
> trades and select the "Show arrows for actual trades" menu item. This
> will show the *actual* trade arrows for you, including all portfolio
> limitations such as max number of positions, lack of capital, etc. Every
> time you run the backtest you would have to regenerate the trade arrows
> this way. You may have to alter your chart parameters to allow showing
> chart arrows.
> 
> Alternatively, you can include the same arrow generation code directly
> in your AFL via composite symbols and just run the backtest to update
> the composite. The trade arrows will automatically update on the chart
> without any need to generate from the trade list. See the code below for
> an example.
> 
> In the example I'm using smaller offsets and blue/orange instead of
> green/red for my shapes so as to allow you to still use the trade list
> to apply actual trades and confirm that the results are identical.
> 
> The trade logic is dummy logic that just shorts on every bar index that
> is evenly divisible by 2 and covers on every bar index that is evenly
> divisible by 5. Equally simple, the buy logic buys the 1st day of the
> week and sells the 5th day of the week. This logic will cause overlaps
> with each other thereby demonstrating the removal of unwanted arrows.
> You can use the "Show arrows for all raw signals" menu from the trade
> list to see where signals have been ignored.
> 
> Note that the code below will produce a composite symbol, of the form
> ~symbol for each symbol for which a trade is taken by the backtester
> e.g. ~AA if a long or short position was taken for symbol AA, etc. As
> with all composites, the composites will show up in Group 253 in your
> Symbols tree. You may delete them from there when no longer wanted. I
> would not recommend running this code against a large watchlist since it
> could result in many many composites.
> 
> bars = BarIndex();
> Short = bars % 2 == 0;
> Cover = bars % 5 == 0;
> 
> days = DayOfWeek();
> Buy = days == 1;
> Sell = days == 5;
> 
> SetCustomBacktestProc("");
> 
> if (Status("action") == ActionPortfolio) {
>     bo = GetBacktesterObject();
>     bo.BackTest();
> 
>     dates = DateTime();
> 
>     for (trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade()) {
>        SetForeign(trade.Symbol);
>        bars = BarIndex();
>        entryBar = LastValue(ValueWhen(trade.EntryDateTime == dates,
> bars));
>        exitBar = LastValue(ValueWhen(trade.ExitDateTime == dates, bars));
>        temp = 0;
> 
>        if (trade.IsLong) {
>           temp[entryBar] = 1;
>           temp[exitBar] = 2;
>        } else {
>           temp[entryBar] = 4;
>           temp[exitBar] = 8;
>        }
> 
>        AddToComposite(temp, "~" + trade.Symbol, "X", atcFlagDefaults |
> atcFlagEnableInPortfolio);
>        RestorePriceArrays();
>     }
> }
> 
> _SECTION_BEGIN("Price1");
> SetChartOptions(0,chartShowArrows|chartShowDates);
> _N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g,
> Lo %g, Close %g BarIndex %g {{VALUES}}", O, H, L, C, BarIndex() ));
> Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle |
> ParamStyle("Style") | GetPriceStyle() );
> _SECTION_END();
> 
> trades = Foreign("~" + Name(), "X");
> 
> PlotShapes(((trades & 1) == 1) * shapeUpArrow, colorBlue, 0, Low, -5);  
> // Buy arrows
> PlotShapes(((trades & 2) == 2) * shapeDownArrow, colorOrange, 0, High,
> -5);   // Sell arrows
> PlotShapes(((trades & 4) == 4) * shapeHollowDownArrow, colorOrange, 0,
> High, -15);   // Short arrows
> PlotShapes(((trades & 8) == 8) * shapeHollowUpArrow, colorBlue, 0, Low,
> -15);   // Cover arrows
> 
> 
> Mike
> 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "gregg55554" <zeeking57@> wrote:
> >
> > I am using staticvars to tell the buy or sell not to put a 1 in the
> buy if a short trade is currently in process. It is messing up all my
> charting arrows. there are short arrows while still in the middle of
> long trades.
> >
> > The shorton , longon vaiables i want to use will tell the buy/short
> not to put a 1 in the buy/short array. BUt by definition they get set
> after after the buy and short array are initiliazed in the code. so the
> buy code will always look at the initialized value at 0, before it reads
> the the variables.So I thought to use static variable but I am messing
> up the code and not sure why. Then I thought to use the flip function
> but that is also not working bc it gets set after the buy and sell code.
> it is like a catch 22.
> >
> > For example:
> >
> > shorton=0;
> > longon=0;
> >
> > Buy= (H>highsignal)AND Shorton==0 ;
> > BuyPrice = Max(O,Highsignal+.05);
> > Short = (Signallow>L) AND Longon==0;
> > ShortPrice = Min(Open,Signallow-.05);
> > Shorton = Flip( Short, Cover );
> > Longon = Flip( Buy, Sell );
> >
> > This is not working.
> > --- In amibroker@xxxxxxxxxxxxxxx, "Mike" sfclimbers@ wrote:
> > >
> > > Zeek,
> > >
> > > My first question would be: Why are you using static variables?
> AmiBroker will not allow you to enter a Buy if you are already Short,
> unless you override that behavior. So, I don't see a need for any of
> what you are trying to do.
> > >
> > > Have you changed the default backtester mode? Or, perhaps you have
> selected the checkbox "Reverse entry signal forces exit" in the AA
> Settings. Leave the backtester mode at its default and unselect the
> "Reverse ..." checkbox from the settings window. Then, just write your
> vanilla Buy/Sell and Short/Cover code without any concern for what the
> other is doing. AmiBroker will sort it out based on which signals occur
> first.
> > >
> > > As an example, run a backtest on the following; Once with the
> "Reverse ..." checkbox selected and again with it unselected:
> > >
> > > WeekDay = DayOfWeek();
> > > Short = WeekDay == 1;
> > > Cover = 0;
> > > Buy = WeekDay == 3;
> > > Sell = 0;
> > >
> > > Notice that in one case you get both buys and shorts. In the other
> you get only a single signal (whichever occurred first).
> > >
> > > As for what is being done "wrong". It's not so much wrong as
> pointless. Making a call to StaticVarGet without storing the resulting
> value has no purpose (that I'm aware of), yet your code is doing that
> twice.
> > >
> > > Also, given that the value being stored is just the value of readily
> available arrays, I don't see why you need to store anything at all. Why
> not just use Flip() as in my previous post, or BarsSince(), or Ref()?
> > >
> > > Finally, if you are using the same AFL over multiple symbols, a
> short position in one symbol will affect the logic of the remaining
> symbols since you are not discriminating between statics among the
> different symbols (i.e. you are using a single static variable rather
> than one per symbol).
> > >
> > > Based on what I've read so far in your previous posts, I'm guessing
> that unselecting the "Reverse ..." checkbox will solve all your
> problems.
> > >
> > > Mike
> > >
> > > --- In amibroker@xxxxxxxxxxxxxxx, "gregg55554" <zeeking57@> wrote:
> > > >
> > > > thanks Mike for your reply,
> > > >
> > > > a) can you tell me what is wrong with the code, so I don't make
> the same mistake again in the future. I tried to replicate code I had
> seen for staticvars.
> > > >
> > > > b) In terms of what I am trying to do. I am trying to write a
> staticvar that detects when there is a short trade. and then set it in
> my buy condition not to have a buy if "onshort" == 1. so when staticvar
> "onshort" equals 1 then no buys will occur.
> > > > I would use the exrem function but as I understand it, it is not
> very good in the backtester?? So Marcin suggested I use a staticvar.
> > > >
> > > > Can you help please
> > > > zeek
> > > >
> > > >
> > > > --- In amibroker@xxxxxxxxxxxxxxx, zeek ing <zeeking57@> wrote:
> > > > >
> > > > > I think I am having a little problem with my static var code. I
> expected to
> > > > > see in an exploration with the variable "onshort" a value of 1
> when a short
> > > > > trade is on. Instead all I see is zeros in the exploration. I am
> not sure
> > > > > why. there are two parts to the code. If anyone can tell me what
> is wrong
> > > > > with this code it would be appreciated. thanks
> > > > >
> > > > > ///part a--
> > > > > StaticVarGet("onshort");
> > > > >
> > > > >
> > > > >
> > > > > if( IsNull( StaticVarGet("onshort"))) StaticVarSet("onshort",0);
> > > > >
> > > > > Onshort= StaticVarGet("onshort");
> > > > >
> > > > >
> > > > >
> > > > > //part b---
> > > > >
> > > > > if (LastValue(Short))
> > > > >
> > > > >
> > > > >
> > > > > {StaticVarSet("onshort",1);}
> > > > >
> > > > > if (LastValue(Cover))
> > > > >
> > > > >
> > > > >
> > > > > {StaticVarSet("onshort",0);}
> > > > >
> > > > >
> > > > >
> > > > > StaticVarGet("onshort");
> > > > >
> > > >
> > >
> >
>




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

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

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

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

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

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/