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

[amibroker] Re: Apply trailing stop after 18:00



PureBytes Links

Trading Reference Links

Can no one guide me with this script? Please advice!

--- In amibroker@xxxxxxxxxxxxxxx, "iliagold1" <iliagold1@xxx> wrote:
>
> Hello,
> 
> It did not work, let me try to explain what we are actually trying 
> to do.
> 
> We would like to optimize a formula on 30 days of the crude oil 
> future and we would like to trade only between 14:00 and 18:00. 
The 
> problem we encountered is that if a trade is not sold before 
18:00, 
> it will stay overnight until next day. That is not what we want 
> because it is far too risky! Therefore, when a trade is still open 
> after 18:00, it should have a have a trailing-stop applied to it, 
> with a maximum loss of 20 cents.
> 
> Exmaple of a trailing-stop:
> 
> At 17:44 the system buy's one contract at $68.00, at 18:00 it is 
> still not sold and the price is at $67.70, at 18:01 a trailing-
stop 
> is applied with 20 cents max. loss (max loss is if price goes to 
> goes to $67.50).
> The price goes to 68.10, and the contract is still not sold, but 
the 
> trailing stop is moved from $67.50 to $67.90. Then the price falls 
> to 67.90 and the stop order is executed and the contract is sold 
> (with a loss of 10 cents)
> 
> I hope this is clear that somebody can help me code this stop. I 
> have asked the support of AmiBroker but they did not reply in a 
few 
> days and we are kind of in a hurry.
> 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, Graham <kavemanperth@> wrote:
> >
> > you cannot use applystop like this
> > try this, it might work
> > 
> > Sell = Cross( Signal( fa, sa, sig ), MACD( fa, sa ) )
> >  or cross( valuewhen( timecondition2, C-0.1 ), L );
> > 
> > -- 
> > Cheers
> > Graham
> > AB-Write >< Professional AFL Writing Service
> > Yes, I write AFL code to your requirements
> > http://www.aflwriting.com
> > 
> > 
> > On 09/05/07, iliagold1 <iliagold1@> wrote:
> > > Hello all,
> > >
> > > I would like to add a trailing stop after the last order of 
the 
> day
> > > of 10 cents, how would I put that in the formula?
> > >
> > > I tried something like this but it does not work, please help.
> > >
> > > tn2 = TimeNum();
> > > timecondition2 = tn2 >= 180001;
> > >
> > > if( LastValue( Buy AND timecondition2 ) )
> > >
> > > {
> > > ApplyStop( 2, 2, 1, 100, False, 1 );
> > > }
> > >
> > >
> > > ----------
> > >
> > > Bellow is the full formula:
> > >
> > > /* variable = optimize( "Description", default, min, max, 
step ) 
> */
> > > fa = Optimize( "MACD Fast", 661, 1, 1000, 10 );
> > > sa = Optimize("MACD Slow", 221, 1, 400, 10 );
> > > sig = Optimize( "Signal average", 171, 1, 200, 10 );
> > >
> > > tn = TimeNum();
> > > timecondition = tn >= 140000 AND tn < 180000;
> > >
> > > tn2 = TimeNum();
> > > timecondition2 = tn2 >= 180001;
> > >
> > > Buy = Cross( MACD( fa, sa ) , Signal( fa, sa, sig ) );
> > > Sell = Cross( Signal( fa, sa, sig ), MACD( fa, sa ) );
> > >
> > > Short = Sell;
> > > Cover = Buy;
> > >
> > > Buy = Buy AND timecondition;
> > > Short = Short AND timecondition;
> > > //Sell = Sell OR NOT timecondition;
> > > //Cover = Cover OR NOT timecondition;
> > >
> > > if( LastValue( Buy AND timecondition2 ) )
> > >
> > > {
> > > ApplyStop( 2, 2, 1, 100, False, 1 );
> > > }
> > >
> > > PositionSize = MarginDeposit = 1;
> >
>




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