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

RE: [amibroker] cannot buy on open



PureBytes Links

Trading Reference Links









<span lang=EN-AU
>Yuki, the one thing I have found with producing
formula is that you need to step back and say in minute detail what it is that
you want. Computers are reasonably bulletproof as is Amibroker. BUT, you must
be precise in the methods and logic with which you write the formula. There are
no shortcuts to writing code and you must be precise.

<span lang=EN-AU
>You want to have a buy and a sell every day. So why
not set your trade settings to buy at open and sell at close, with zero trade
delays

<span lang=EN-AU
>Buyprice = Open;

<span lang=EN-AU
>SellPrice = Close;

<span lang=EN-AU
>SetTradeDelays(0,0,0,0);

<span lang=EN-AU
> 

<span lang=EN-AU
>Next you want to trade this every day. So why not make
this your condition for the trade signals. How can we say to trade every day?
The expression BarIndex() gives a number for every day, or Datenum() can do the
same. I will use BarIndex()

<span lang=EN-AU
>Buy = BarIndex()>=0;

<span lang=EN-AU
>Sell = BarIndex()>=0;

<span lang=EN-AU
> 

<span lang=EN-AU
>The whole code would look like this

<font size=2 color=blue
face="Courier New">SetTradeDelays<font size=2 color=black
face="Courier New">(<span
lang=EN-AU >0<font
size=2 color=black face="Courier New">,<font size=2
color=fuchsia face="Courier New">0<font size=2
color=black face="Courier New">,<font size=2
color=fuchsia face="Courier New">0<font size=2
color=black face="Courier New">,<font size=2
color=fuchsia face="Courier New">0<font size=2
color=black face="Courier New">);

<font size=2 color=red
face="Courier New">BuyPrice<span
lang=EN-AU >=<font
size=2 color=red face="Courier New">Open<font size=2
color=black face="Courier New">;

<font size=2 color=red
face="Courier New">SellPrice<span
lang=EN-AU >=<font
size=2 color=red face="Courier New">Close<font size=2
color=black face="Courier New">;

<font size=2 color=red
face="Courier New">Buy<span
lang=EN-AU > = <font
size=2 color=blue face="Courier New">BarIndex<font size=2
color=black face="Courier New">()>=<font size=2
color=fuchsia face="Courier New">0<font size=2
color=black face="Courier New">;

<span
lang=EN-AU >Sell<font size=2
color=black> = <font
size=2 color=blue>BarIndex<font
size=2 color=black>()>=<font
size=2 color=fuchsia>0<font
size=2 color=black>;

<span lang=EN-AU
> 

<span lang=EN-AU
> 

<span lang=EN-AU
> 

<span lang=EN-AU
>Cheers,

<span lang=EN-AU
 >Graham

<span lang=EN-AU
> 

<span lang=EN-AU
> 

-----Original Message-----
From: Yuki Taga [mailto:yukitaga@xxxxxxxxxxxxx] 
Sent: Sunday, 23 February 2003 10:55 AM
To: Graham
Subject: Re: [amibroker] cannot buy on open

<span lang=EN-AU
> 

<span lang=EN-AU
>Hi Graham,

<span lang=EN-AU
> 

<span lang=EN-AU
>Forget that condition, Graham.  I want a buy
condition that is met on

<span lang=EN-AU
>every open, and a sell condition that is met on every
close.  Can you

<span lang=EN-AU
>do it?  If you can, maybe I can tweak it from
there.  I cannot do it.

<span lang=EN-AU
> 

<span lang=EN-AU
>Yuki

<span lang=EN-AU
> 

<span lang=EN-AU
>Sunday, February 23, 2003, 10:47:39 AM, you wrote:

<span lang=EN-AU
> 

<span lang=EN-AU
>G> Yuki

<span lang=EN-AU
>G> Buy requires a condition to be met and results
in a binary 1 or 0. A "1"

<span lang=EN-AU
>G> gives the signal for the buy to be activated.

<span lang=EN-AU
>G> Same with the Sell

<span lang=EN-AU
>G> So you would need a condition to be met :

<span lang=EN-AU
>G> Buy = Cross(C,EMA(C,20);

<span lang=EN-AU
>G> Sell = Cross(EMA(C,10),C);

<span lang=EN-AU
>G> BuyPrice = Open;

<span lang=EN-AU
>G> SellPrice = Close;

<span lang=EN-AU
>G> Now you need to apply the settings to buy at
open, and sell at close.

<span lang=EN-AU
>G> Then have your trade delays set to what you
require, Buy delay 0 day,

<span lang=EN-AU
>G> and sell at 0 days. You can do this with the
command

<span lang=EN-AU
>G> SetTradeDelays(0,0,0,0);

<span lang=EN-AU
> 

<span lang=EN-AU
>G> Check if these are the correct spellings in the
AB help pages. Hope this

<span lang=EN-AU
>G> works, I have not tested it but will if you have
problems with it, or

<span lang=EN-AU
>G> maybe someone else will have  abetter
response.

<span lang=EN-AU
> 

<span lang=EN-AU
>G> Oh, by the way, do not consider your questions
sill or basic because

<span lang=EN-AU
>G> often they make me stop and think about things
and how I can improve my

<span lang=EN-AU
>G> coding.

<span lang=EN-AU
> 

<span lang=EN-AU
>G> Cheers,

<span lang=EN-AU
>G> Graham

<span lang=EN-AU
> 

<span lang=EN-AU
> 

<span lang=EN-AU
>G> -----Original Message-----

<span lang=EN-AU
>G> From: Yuki Taga [mailto:yukitaga@xxxxxxxxxxxxx] 

<span lang=EN-AU
>G> Sent: Sunday, 23 February 2003 9:18 AM

<span lang=EN-AU
>G> To: amibroker@xxxxxxxxxxxxxxx

<span lang=EN-AU
>G> Subject: [amibroker] cannot buy on open

<span lang=EN-AU
> 

<span lang=EN-AU
>G> Sometimes the apparently simplest things are
not, in AB.

<span lang=EN-AU
> 

<span lang=EN-AU
>G> I cannot seem to make it buy on the open and
sell on the close the

<span lang=EN-AU
>G> same day, no matter what formula I enter. 
Everything is done on the

<span lang=EN-AU
>G> close.  This is regardless of what I have
in 'settings', and

<span lang=EN-AU
>G> regardless of what I write in code to control
those settings.

<span lang=EN-AU
> 

<span lang=EN-AU
>G> Even a brain-dead:

<span lang=EN-AU
> 

<span lang=EN-AU
>G> Buy = Open; //nothing more, we'd buy every open
and sell every close

<span lang=EN-AU
> 

<span lang=EN-AU
>G> Sell = Close;

<span lang=EN-AU
> 

<span lang=EN-AU
>G> SetTradeDelays(0,0,0,0);

<span lang=EN-AU
> 

<span lang=EN-AU
>G> BuyPrice = Open;

<span lang=EN-AU
> 

<span lang=EN-AU
>G> SellPrice = Close;

<span lang=EN-AU
> 

<span lang=EN-AU
>G> results in all buys and sells taking place on
the close, at the same

<span lang=EN-AU
>G> price, of course. Can someone explain why I
cannot control this?

<span lang=EN-AU
> 

<span lang=EN-AU
>G> Yuki ^_^

<span lang=EN-AU
> 

<span lang=EN-AU
> 

<span lang=EN-AU
>Post AmiQuote-related messages ONLY to:
amiquote@xxxxxxxxxxxxxxx 

<span lang=EN-AU
>(Web page: http://groups.yahoo.com/group/amiquote/messages/)

<span lang=EN-AU
> 

<span lang=EN-AU
>Check group FAQ at:
http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

<span lang=EN-AU
> 

<span lang=EN-AU
>Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/ 

<span lang=EN-AU
> 










Yahoo! Groups Sponsor


  ADVERTISEMENT









Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html



Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.