PureBytes Links
Trading Reference Links
|
Hi Ed, all,
Eventually i was able to remove all excessive signals with the "flip" function.
Cond1 = flip("some trigger",buy);
Cond2 = flip("some trigger",short);
buy = ..... AND Cond2;
short = ... AND Cond1;
It was very simple in the end, but i allready thaught it would be :-)
Thanks anyhow for youre help.
--- In amibroker@xxxxxxxxxxxxxxx, "chaoss45" <chaoss45@xxx> wrote:
>
> Ed that's great! thanks a lot.
>
> I have to take some time to figure this out, but am sure i will be able to.
> I'll let you know how this will work out for me.
>
> regards.
>
>
> --- In amibroker@xxxxxxxxxxxxxxx, "Edward Pottasch" <empottasch@> wrote:
> >
> > file attachment doesn't seem to work at the moment.
> >
> > here is the code:
> >
> >
> > procedure buySellShortCover_proc(Buy,BuyPrice,Sell,SellPrice,Short,ShortPrice,Cover,CoverPrice,timearr,endtime)
> > {
> >
> > global BuyAdjusted;
> > global BuyPriceAdjusted;
> > global ShortAdjusted;
> > global ShortPriceAdjusted;
> > global SellAdjusted;
> > global SellPriceAdjusted;
> > global CoverAdjusted;
> > global CoverPriceAdjusted;
> >
> >
> > BuyAdjusted = 0;
> > BuyPriceAdjusted = 0;
> > ShortAdjusted = 0;
> > ShortPriceAdjusted = 0;
> > SellAdjusted = 0;
> > SellPriceAdjusted = 0;
> > CoverAdjusted = 0;
> > CoverPriceAdjusted = 0;
> >
> > delay = 1;
> > slip = 0.0;
> >
> > for( i = 1; i < BarCount; i++ )
> > {
> >
> > if (Buy[ i ])
> > {
> >
> > // inside a long trade:
> >
> > BuyAdjusted[ i ] = 1;
> > BuyPriceAdjusted[ i ] = O[ i ] + slip;
> >
> > for (j = i + delay; j < BarCount; j++)
> > {
> >
> > // exit at end of day
> > if (timearr[ j ] >= endtime)
> > {
> >
> > SellAdjusted[ j ] = 1;
> > SellPriceAdjusted[ j ] = O[ j ] - slip;
> > i = j;
> > break;
> >
> > }
> > // exit at sell / short signal
> > else if (Sell[ j ])
> > {
> >
> > SellAdjusted[ j ] = 1;
> > SellPriceAdjusted[ j ] = O[ j ] - slip;
> > i = j - 1;
> > break;
> >
> > }
> > // to avoid problems at the end of the array
> > else if (j == BarCount - 1)
> > {
> >
> > i = BarCount;
> >
> > }
> > }
> > }
> > else if (Short[ i ])
> > {
> >
> > // inside a short trade:
> >
> > ShortAdjusted[ i ] = 1;
> > ShortPriceAdjusted[ i ] = O[ i ] + slip;
> >
> > for (j = i + delay; j < BarCount; j++)
> > {
> >
> > // exit at end of day
> > if (timearr[ j ] >= endtime)
> > {
> >
> > CoverAdjusted[ j ] = 1;
> > CoverPriceAdjusted[ j ] = O[ j ] + slip;
> > i = j;
> > break;
> >
> > }
> > // exit at cover / buy signal
> > else if (Cover[ j ])
> > {
> >
> > CoverAdjusted[ j ] = 1;
> > CoverPriceAdjusted[ j ] = O[ j ] + slip;
> > i = j - 1;
> > break;
> >
> > }
> > // to avoid problems at the end of the array
> > else if (j == BarCount - 1)
> > {
> >
> > i = BarCount;
> >
> > }
> > }
> > }
> > }
> >
> > }
> >
> >
> > SetBarsRequired(10000,10000);
> > SetTradeDelays(0,0,0,0);
> > SetOption("CommissionMode", 3);
> > SetOption("FuturesMode",True);
> > NumContracts = 1;
> > PositionSize = NumContracts * MarginDeposit;
> > SetOption("MaxOpenPositions", 6);
> > SetOption("CommissionAmount", 2.4);
> >
> > starttime = 093000; // true exchange opening time
> > endtime = 160000; // true exchange closing time
> > per = 15;
> >
> > timecond = TimeNum() >= starttime AND TimeNum() <= endtime;
> >
> > Buy = (C > Ref(HHV(H,per),-1)) * timecond;
> > Buy = Ref(Buy,-1); BuyPrice = O;
> > Short = (C < Ref(LLV(L,per),-1)) * timecond;
> > Short = Ref(Short,-1); ShortPrice = O;
> > Sell = Short; SellPrice = ShortPrice;
> > Cover = Buy; CoverPrice = BuyPrice;
> >
> > buySellShortCover_proc(Buy,BuyPrice,Sell,SellPrice,Short,ShortPrice,Cover,CoverPrice,TimeNum(),endtime);
> >
> > Buy = BuyAdjusted;
> > BuyPrice = BuyPriceAdjusted;
> > Short = ShortAdjusted;
> > ShortPrice = ShortPriceAdjusted;
> > Sell = SellAdjusted;
> > SellPrice = SellPriceAdjusted;
> > Cover = CoverAdjusted;
> > CoverPrice = CoverPriceAdjusted;
> >
> > GraphXSpace = 5;
> > SetChartOptions(0, chartShowDates);
> > Plot(C,"\nLast",colorWhite,64);
> >
> > Plot(Ref(HHV(H,per),-1),"\nhhv",colorGreen,styleDashed);
> > Plot(Ref(LLV(L,per),-1),"\nllv",colorRed,styleDashed);
> >
> > PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorGreen,0,L,-15);
> > PlotShapes(IIf(Buy,shapeHollowUpArrow,shapeNone),colorWhite,0,L,-15);
> > PlotShapes(IIf(Buy,shapeHollowSmallCircle,shapeNone),colorWhite,0,BuyPrice,0);
> >
> > PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,-15);
> > PlotShapes(IIf(Sell,shapeHollowDownArrow,shapeNone),colorWhite,0,H,-15);
> > PlotShapes(IIf(Sell,shapeHollowSmallCircle,shapeNone),colorWhite,0,SellPrice,0);
> >
> > PlotShapes(IIf(Short,shapeDownTriangle,shapeNone),colorYellow,0,H,IIf(Short AND Sell,-30,-15));
> > PlotShapes(IIf(Short,shapeHollowDownTriangle,shapeNone),colorWhite,0,H,IIf(Short AND Sell,-30,-15));
> > PlotShapes(IIf(Short,shapeHollowCircle,shapeNone),colorWhite,0,ShortPrice,0);
> >
> > PlotShapes(IIf(Cover,shapeUpTriangle,shapeNone),colorLightBlue,0,L,IIf(Cover AND Buy,-30,-15));
> > PlotShapes(IIf(Cover,shapeHollowUpTriangle,shapeNone),colorWhite,0,L,IIf(Cover AND Buy,-30,-15));
> > PlotShapes(IIf(Cover,shapeHollowCircle,shapeNone),colorWhite,0,CoverPrice,0);
> >
> > Plot(timecond, "", colorDarkGrey, styleArea|styleOwnScale,0,1);
> >
> >
> >
> >
> > ----- Original Message -----
> > From: Edward Pottasch
> > To: amibroker@xxxxxxxxxxxxxxx
> > Sent: Wednesday, August 05, 2009 12:32 PM
> > Subject: Re: [amibroker] Re: remove all excessive signals [1 Attachment]
> >
> >
> > [Attachment(s) from Edward Pottasch included below]
> >
> >
> >
> > hi,
> >
> > I added an example where I use some constraints of my own. The buy and short constraint contain multiple signals. Have a look if you can figure it out. It is worth while to figure out how this works because you can add stops or any type of exit you like in these loops.
> >
> > rgds, Ed
> >
> >
> >
> >
> >
> > ----- Original Message -----
> > From: chaoss45
> > To: amibroker@xxxxxxxxxxxxxxx
> > Sent: Wednesday, August 05, 2009 11:51 AM
> > Subject: [amibroker] Re: remove all excessive signals
> >
> >
> >
> > Hi Ed, ok, thank you very much.
> >
> > I don't have the exact code here right now, but i can try to sum up a short version from memory.
> > I don't know the exact applystop rules i used.
> > And also don't know the Dhigh and the Dlow rules right now, but they describe a high and a low taken from a couple hours in the morning (Dutch).
> > I hope you can show me the loop with this data, or else i will post the code later this evening.
> >
> > ****************************************
> > timeopen = 070000;
> > timeclose = 180000;
> > tod = TimeNum();
> > inRange = tod >= timeopen AND tod <= timeclose;
> >
> > Dhigh = ....;
> > DLow = ....;
> >
> > Buy = inRange AND Cross(High,Dhigh);
> >
> > Sell = 0;
> > applystop(...);
> >
> > Short = inRange AND Cross(ShortStop,Dlow);
> >
> > Cover = 0;
> > applystop(...);
> >
> > Buy = ExRem(Buy,tod==180000);
> > Sell = ExRem(Sell,tod==180000);
> > **********************************************
> >
> > regards
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, "Edward Pottasch" <empottasch@> wrote:
> > >
> > > simplest way to do this is using loops. If you post your problem (buy, sell, short and cover array constraints) I can show you how,
> > >
> > > rgds, Ed
> > >
> > >
> > >
> > >
> > >
> > > ----- Original Message -----
> > > From: chaoss45
> > > To: amibroker@xxxxxxxxxxxxxxx
> > > Sent: Wednesday, August 05, 2009 10:28 AM
> > > Subject: [amibroker] Re: remove all excessive signals
> > >
> > >
> > > Hi Mike, thanks.
> > >
> > > I am talking about one symbol, just take the first signal that appears and remove all others.
> > > Further i made a mistake in my previous postings, i said "Sell" but it should be "Short".
> > > So for a recap: I want to take the first signal that appears (Buy or Short) and remove all other signals for that symbol for that day.
> > > Right now i'm working with Exrem and got all excessive Buys and Shorts removed, but that still leaves me with 1 Buy and 1 Short signal a day.
> > >
> > > How can i remove this last excessive Buy or Short signal?
> > >
> > > Your idea should work, but i'm not a great coder so i hope there is a simpler way to do this.
> > >
> > > --- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@> wrote:
> > > >
> > > > Sorry,
> > > >
> > > > I think that I misread your question. Though, the answer is laregely the same; you could use custom backtester.
> > > >
> > > > Iterate through the signals at each bar. If an open position already exists for the symbol, reset the position size to zero for the new signal if the date of the bar is the same as the entry date of the open position.
> > > >
> > > > Any attempt to use arrays outside of the custom backtester using such approaches as flip, exrem, etc. do not take into account that some signals simply will not get filled due to portfolio limitations. Thus, custom backtester is the only reliable way of knowing if a position was *actually* taken.
> > > >
> > > > Mike
> > > >
> > > > --- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@> wrote:
> > > > >
> > > > > One sure fire way to do it would be to write custom backtester code that iterated through the trade signals at each bar and simply reset the position size to 0 for all remaining signals.
> > > > >
> > > > > Regardless of how you accomplish your task, if you are trading more than a single symbol you are at risk of getting highly biased results. How do you determine which signal occured first? If you get 3 Buys from 3 symbols on the same bar, which one do you take? Whatever logic you use to make that determination will bias your results. You would likely be best to select from the 3 at random.
> > > > >
> > > > > Mike
> > > > >
> > > > > --- In amibroker@xxxxxxxxxxxxxxx, "chaoss45" <chaoss45@> wrote:
> > > > > >
> > > > > >
> > > > > > Hello all,
> > > > > >
> > > > > > I'm trying to write code for a breakout system.
> > > > > > Right now i have my system working (demo) but i'm having trouble to
> > > > > > remove all excessive signals.
> > > > > > I want to take the first Buy or Sell signal of the day, and all other
> > > > > > signals for the day removed.
> > > > > > For example: if the first signal is a buy signal, all other buy and sell
> > > > > > signals should be removed (or ignored) but i cannot do it.
> > > > > > I tried Exrem and that is working fine only for removing the other buy
> > > > > > or sell signals, but not for removing all the other buy and sell
> > > > > > signals.
> > > > > > I think it is something simple, but for some reason i do not see it.
> > > > > > Could somebody help me with the code?
> > > > > >
> > > > >
> > > >
> > >
> >
>
------------------------------------
**** 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/
|