PureBytes Links
Trading Reference Links
|
Hi Thomas,
I am new to amibroker and not the worlds greatest programmer,but your code may be a solution to the logic I was after..
I wanted to test a very simple system..The entry could be anything,and i would initially want a 8% max stop and 20% profit target.But I want the profit target on 50% of my position.If the high>profittarget,i would like to move my stoploss up to break even or have a trailing stop on the open position.Unfortunately,i was advised i need looping statements which is way beyond me....I think the IIf statement may work..
Buy=myrule;
BuyPrice = ValueWhen(Ref(Buy,-1),Open);
StopLoss = 0.92*BuyPrice;
ProfitTarget = 1.20*BuyPrice;
Sell = Cross(High,ProfitTarget) OR Cross(StopLoss, Low);
SellPrice = IIf(High>ProfitTarget, ProfitTarget, StopLoss);
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell,Buy);
here is where i need some help.I understand your code.Is there a way to use the IIF and state if the position size=50%,move max loss stop to buyprice?? Or IIF close>profitarget,stoploss=buyprice??This would save me from loops!!!
Thanks,
Allan
----- Original Message -----
From: "Thomas Z." <tzg@xxxxxxxxxxxxxxxx>
Date: Friday, July 7, 2006 1:36 pm
Subject: RE: [amibroker] Re: How do I keep the buyprice while multiple buy signals happen
> Hi Andre,
>
> i have not checked out my code below detailed but it should point
> you to the
> right direction. Just a quick modification.
> i would also better use the build-in applystop function instead
> manuallystop and profit target.
>
> Buy = Cross (MACD(12, 26), Signal(12, 26,9));
> BuyPrice = ValueWhen(Ref(Buy,-1),Open);
>
> StopLoss = 0.9*BuyPrice;
> ProfitTarget = 1.03*BuyPrice;
>
> Sell = Cross(High,ProfitTarget) OR Cross(StopLoss, Low);
> SellPrice = IIf(High>ProfitTarget, ProfitTarget, StopLoss);
>
> Buy = ExRem(Buy, Sell);
> Sell = ExRem(Sell,Buy);
>
>
> Best regards
>
> Thomas
> www.tradingbasis.com <http://www.tradingbasis.com/>
>
>
>
> _____
>
> From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx]
> On Behalf
> Of Andre
> Sent: Friday, July 07, 2006 5:24 PM
> To: amibroker@xxxxxxxxxxxxxxx
> Subject: [amibroker] Re: How do I keep the buyprice while multiple buy
> signals happen
>
>
>
> Thanks Thomas,
> I knew about exrem. Thanks to you I realized one new thing: the
> recursive nature of the sales signal (which is based on the buy
> signal) means that I have to do Exrem several times. I have re-
> approached my problem and this code apparently seems to do the
> trick
> I wanted ("buy at MACD crossing, sell at 3% profit or 10% loss"),
> but, my gosh it's ugly (3 Exrems)! And I am not sure if logicaly
> this is enough. I proved empirically to myself (try stock AXP),
> that
> 2 exrems is not enough. Is there a more elegant way to do this?:
>
> -----------------------------------
>
> Buy = Cross (MACD(12, 26), Signal(12, 26,9));
> BP = IIf(Buy, Ref(BuyPrice,1), 0);
>
> //Actual BuyPrice [BP] is the Open of the following day
>
> Sell = Cross(High,1.03*ValueWhen(Buy, BP)) OR Cross(0.9*ValueWhen
> (Buy , BP), Low);
>
> // NOTE THAT AT THIS POINT I GET FALSE SELL SIGNALS BECAUSE I HAVE
> FALSE BUY SIGNALS
>
> Buy = ExRem(Buy, Sell);
>
> // THIS GETS RID OF FIRST WAVE OF FALSE SELLS
> // THEN WE RE-CALCULATE ALL BUYS AND SELLS:
>
> BP = IIf(Buy, Ref(BuyPrice,1), 0);
> //BuyPrice is the Open of the following day
>
> Sell = Cross(High,1.03*ValueWhen(Buy, BP)) OR Cross(0.9*ValueWhen
> (Buy , BP), Low);
>
> Buy = ExRem(Buy, Sell);
>
> // THIS IS NOT ENOUGH. IF THERE HAD BEEN 2 FALSE BUYS BEFORE,
> SELLS
> ARE STILL OFF.
>
> BP = IIf(Buy, Ref(BuyPrice,1), 0);
> Sell = Cross(High,1.03*ValueWhen(Buy, BP)) OR Cross(0.9*ValueWhen
> (Buy , BP), Low);
>
> Buy = ExRem(Buy, Sell);
>
> // I AM NOT SURE IF I HEREWITH COVERED IT ALL, OR I NEED TO
> CONTINUE
> THIS EXREM GYMNASTICS. IN PRACTICAL TESTS THIS SEEMS TO GIVE ME
> THE
> CORRECT +3% and -10% Trades.
>
> SellPrice = IIf(High>1.03*ValueWhen(Buy, BP), 1.03*ValueWhen(Buy,
> BP), 0.9*ValueWhen(Buy, BP));
>
> --- In amibroker@xxxxxxxxx <mailto:amibroker%40yahoogroups.com>
> ps.com,"Thomas Z." <tzg@xxx> wrote:
> >
> > Hi Andre,
> >
> > i think the easiest way would simply be to use the exrem
> function.
> It would
> > assure that you only get a new buy after a sell.
> >
> > SYNTAX exrem( ARRAY1, ARRAY2 )
> > RETURNS ARRAY
> > FUNCTION removes excessive signals:
> > returns 1 on the first occurence of "true" signal in Array1
> > then returns 0 until Array2 is true even if there are "true"
> signals in
> > Array1
> > EXAMPLE buy = ExRem( buy, sell );
> > sell = ExRem( sell, buy );
> >
> > Best regards
> >
> > Thomas
> > www.tradingbasis.com <http://www.tradingb
> <http://www.tradingbasis.com/>asis.com/>
> >
> >
> >
> > _____
> >
> > From: amibroker@xxxxxxxxx <mailto:amibroker%40yahoogroups.com>
> ps.com[mailto:amibroker@xxxxxxxxx
> <mailto:amibroker%40yahoogroups.com> ps.com]
> On Behalf
> > Of Andre
> > Sent: Friday, July 07, 2006 9:14 AM
> > To: amibroker@xxxxxxxxx <mailto:amibroker%40yahoogroups.com> ps.com
> > Subject: [amibroker] How do I keep the buyprice while multiple
> buy
> signals
> > happen
> >
> >
> >
> > Hello,
> >
> > This should be the simplest thing and I am simply running in
> circles
> > with AFL not being able to give me what I want.
> > Here's what I want in simple terms:
> >
> > . Buy on MACD crossing (buy at Open the following day).
> > . Sell at 3% profit or at 10% loss.
> >
> > Period. That's all.
> >
> > The problem I am having is in "keeping" the purchase price at
> hand.
> > Yes, I know about "ValueWhen" function, but I can't get it to
> work
> > because I can easily have multiple buy signals before the sell
> > occurs and a new Buy gives me a new BuyPrice that throws off all
> my
> > profit and loss targets.
> > Please advise. Thanks,
> >
> > Andre Perman
> >
>
>
>
>
>
|