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

[amibroker] Re: How to "Enter Long" at Open on Next Day



PureBytes Links

Trading Reference Links

Mike - Okay, got it. I missed the obvious. Thanks for helping me learn
programming. Also, your code worked fine. Thanks.

--- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@xxx> wrote:
>
> Wally,
> 
> The "..." simply meant "write your own sell code here!". It is not 
> part of the AmiBroker syntax. Taking your original example, the 
> actual code becomes:
> 
> SetTradeDelays(1, 1, 1, 1);
> 
> MA20 = MA(Close, 20);
> MA80 = MA(Close, 80);
> MA150 = MA(Close, 150);
> 
> Buy = (Close > MA20) && (MA20 > MA80) && (MA20 > MA150);
> BuyPrice = Open;
> 
> Sell = (Close < MA20) && (MA20 < MA80) && (MA20 < MA150);
> SellPrice = Open;
> 
> Note that the above example answers your follow up question to 
> Tomasz. Yes, you can write code to override the AA window settings; 
> Use SetTradeDelays.
> 
> For an explanation of any of the functions used, refer to the Help 
> menu in AmiBroker, or on-line at:
> http://www.amibroker.com/guide/afl/afl_index.php?m=1
> 
> Keep in mind that you will still need to add money management logic 
> to the code and/or in your preferences settings (e.g. max positions, 
> position size, margin usage, long only vs. short only vs. long and 
> short, etc).
> 
> Mike
> 
> > > > Cond1 = Ref(Close,-1); BuyPrice = Open;
> > > > Cond2 = Close > MA( Close, 20 );
> > > > Cond3 = MA(  Close , 20 ) > MA(  Close , 80 ); 
> > > > Cond4 = MA(  Close , 20 ) > MA(  Close , 150 ); 
> > > > Buy = Cond1 AND Cond2 AND Cond3 AND Cond4; 
> > > > 
> > > > Cond4 = Ref(Close,-1); SellPrice = Open;
> > > > Cond5 = Close < MA( Close, 20 );
> > > > Cond6 = MA(  Close , 20 ) < MA(  Close , 80 ); 
> > > > Cond7 = MA(  Close , 20 ) < MA(  Close , 150 );
> > > > Sell = Cond4 AND Cond5 AND Cond6 AND Cond7;
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "electricwally77" <soundmaker@> 
> wrote:
> >
> > Mike, Thank you for helping. I received a syntax error on Line 8 of
> > your code (Sell = ...). I tried placing a semi-colen (;) at the end
> > but to no avail. I'm not sure how to correct this. 
> > 
> > Your code below.......
> > 
> > 
> > SetTradeDelays(1, 1, 1, 1);
> > 
> > MA20 = MA(Close, 20);
> > MA80 = MA(Close, 80);
> > MA150 = MA(Close, 150);
> > 
> > Buy = (Close > MA20) && (MA20 > MA80) && (MA20 > MA150);
> > BuyPrice = Open;
> > 
> > Sell = ...
> > SellPrice = Open;
> > 
> > 
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@> wrote:
> > >
> > > You should be able to code your script as though everything were 
> going 
> > > to happen on the same day as the signal, then just use 
> SetTradeDelays 
> > > to defer it 'till the next day.
> > > 
> > > Try something like this (untested):
> > > 
> > > SetTradeDelays(1, 1, 1, 1);
> > > 
> > > MA20 = MA(Close, 20);
> > > MA80 = MA(Close, 80);
> > > MA150 = MA(Close, 150);
> > > 
> > > Buy = (Close > MA20) && (MA20 > MA80) && (MA20 > MA150);
> > > BuyPrice = Open;
> > > 
> > > Sell = ...
> > > SellPrice = Open;
> > > 
> > > P.S. For better performance, only calculate the MA's once.
> > > 
> > > Mike
> > > 
> > > 
> > > --- In amibroker@xxxxxxxxxxxxxxx, "electricwally77" <soundmaker@> 
> > > wrote:
> > > >
> > > > I appreciate any code help if possible.
> > > > 
> > > > I've been at my code for hours and can't figure out what I did 
> > > wrong.
> > > > 
> > > > I'm trying to tell my system to Enter Long on the Next Trading 
> Day 
> > > (at
> > > > the open price) only if the "Buy" rules are True the trading 
> day 
> > > before.
> > > > 
> > > > Likewise, I'm trying to tell my system to Exit Long on the Next
> > > > Trading Day (at the open price) only if the "Sell" rules are 
> True 
> > > the
> > > > trading day before.
> > > > 
> > > > In other words, If my system tells me to buy or sell on a 
> particular
> > > > day, I only want to execute the trade at the open on the next 
> > > trading
> > > > day (not the same day the system identifies a trade).
> > > > 
> > > > Here is my code below:
> > > > 
> > > > Cond1 = Ref(Close,-1); BuyPrice = Open;
> > > > Cond2 = Close > MA( Close, 20 );
> > > > Cond3 = MA(  Close , 20 ) > MA(  Close , 80 ); 
> > > > Cond4 = MA(  Close , 20 ) > MA(  Close , 150 ); 
> > > > Buy = Cond1 AND Cond2 AND Cond3 AND Cond4; 
> > > > 
> > > > Cond4 = Ref(Close,-1); SellPrice = Open;
> > > > Cond5 = Close < MA( Close, 20 );
> > > > Cond6 = MA(  Close , 20 ) < MA(  Close , 80 ); 
> > > > Cond7 = MA(  Close , 20 ) < MA(  Close , 150 );
> > > > Sell = Cond4 AND Cond5 AND Cond6 AND Cond7;
> > > > 
> > > > Thanks you members.
> > > >
> > >
> >
>



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

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

*********************
TO GET TECHNICAL 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/