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

Re: Declare variable for future use: Looking for workaround



PureBytes Links

Trading Reference Links

Hi mike,
did you test the code i posted earlier. and is this similar to what 
you asked.

john. 
--- In amibroker@xxxx, "mik954" <mik-u@xxxx> wrote:
> Tomasz,
> 
> I've seen this code. It works. Thanks. The only problem with this 
code 
> is that again it's theorecal profit, not real one. Real Buy signal:
> 
> Buy = Buy AND TheoreticalProfit < 0;
> 
> will be different than Buy signal used to calculate profit.
> 
> Anyway, thanks again,
> Mike
> 
> --- In amibroker@xxxx, "Tomasz Janeczko" <amibroker@xxxx> wrote:
> > Mike,
> > 
> > I already posted this but you maybe overlooked this, so once 
again:
> > the code for your problem is:
> > 
> > Buy = ... entry rule...
> > Sell = .... exit rule...
> > 
> > TheoreticalProfit = ValueWhen( Sell, SellPrice ) - ValueWhen( 
Buy, 
> BuyPrice, 2 ) 
> > 
> > Buy = Buy AND TheoreticalProfit < 0;
> > 
> > Another solution is to use VBScript as explained in AmiBroker 
> User's guide: AmiBroker Formula Language:
> > AFL Scripting Host. In VBScript you can loop as you wish.
> > 
> > There is no workaround needed at all.
> > 
> > Best regards,
> > Tomasz Janeczko
> > amibroker.com
> > ----- Original Message ----- 
> > From: "mik954" <mik-u@xxxx>
> > To: <amibroker@xxxx>
> > Sent: Tuesday, April 23, 2002 11:17 PM
> > Subject: [amibroker] Re: Declare variable for future use: Looking 
> for workaround
> > 
> > 
> > > No, I don't think it's chicken/egg problem.
> > > 
> > > Initially it's a very simple task: I need PREVIOUS values of 
> Buy/Sell 
> > > to calculate CURRENT tradeProfit, then I need PREVIOUS value of 
> > > tradeProfit to calculate current value of Buy. It seemed so 
easy!
> > > 
> > > But it turned out that AFL doesn't allow it. So I am looking 
for 
> > > workaround :(
> > > 
> > > Thanks,
> > > Mike
> > > 
> > > --- In amibroker@xxxx, "bluesinvestor" <investor@xxxx> wrote:
> > > > This is kind of the chicken and the egg problem isn't it?
> > > > 
> > > > You will never get a BUY if tradeProfit is never initialized 
> (thus 
> > > it will
> > > > never be LESS THAN zero).
> > > > 
> > > > Or am I missing something?
> > > > 
> > > > -----Original Message-----
> > > > From: mik954 [mailto:mik-u@x...]
> > > > Sent: Tuesday, April 23, 2002 11:30 AM
> > > > To: amibroker@xxxx
> > > > Subject: [amibroker] Re: Declare variable for future use: 
> Left/Right
> > > > side of the formula
> > > > 
> > > > 
> > > > Hi, Mike,
> > > > 
> > > > Thank you for the idea. Here is my usage:
> > > > 
> > > > // var tradeProfit; // declare variable for future use
> > > > Buy = longEntry and ValueWhen(Sell, tradeProfit) < 0;
> > > > Sell = LongExit;
> > > > tradeProfit = ValueWhen(Sell, SellPrice) - ValueWhen(Buy, 
> BuyPrice);
> > > > 
> > > > May be you idea about setting to Close will work. When I 
tried 
> to
> > > > initialize tradeProfit array with 0, it didn't return correct 
> value
> > > > in ValueWhen() function: allways 0.
> > > > 
> > > > Thanks,
> > > > Mike
> > > > 
> > > > 
> > > > --- In amibroker@xxxx, Mike Pham <mmqp@xxxx> wrote:
> > > > > without much knowing of your usages; I would think
> > > > > you could always create a dummy array and use it on
> > > > > the right side of the formula.
> > > > >
> > > > > dummy = Close; // this is to create the dummy array
> > > > > and initialize them with close datas.
> > > > >
> > > > > ABformula = dummy;
> > > > >
> > > > > regards.
> > > > > --- mik954 <mik-u@xxxx> wrote:
> > > > > > Tomasz,
> > > > > >
> > > > > > Thank you for the links describing AFL arrays.
> > > > > >
> > > > > > But I still don't know how I can benefit from
> > > > > > AMA/AMA2 functions to
> > > > > > fix my problem.
> > > > > >
> > > > > > The problem is how to obtain a value from an array
> > > > > > using ValueWhen()
> > > > > > function (on the right side of the formula) before
> > > > > > setting/defining
> > > > > > this array on the left side of the formala.
> > > > > >
> > > > > > In Excel I don't need to declare any rows/columns:
> > > > > > they are all
> > > > > > predefined. Therefore I can use any new row/column
> > > > > > on the left and
> > > > > > right side of the formula at any time.
> > > > > >
> > > > > > As I understand in AFL I CANNOT use an array on the
> > > > > > right side of the
> > > > > > formula before using it on the left side.. That's my
> > > > > > PROBLEM.
> > > > > >
> > > > > > A simle fix would be using some kind of declaration
> > > > > > (var for example,
> > > > > > like in VB/JS Script) to allow using of array on the
> > > > > > right side of
> > > > > > the formula.
> > > > > >
> > > > > > Thanks,
> > > > > > Mike
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > --- In amibroker@xxxx, "Tomasz Janeczko"
> > > > > > <amibroker@xxxx> wrote:
> > > > > > > Mike,
> > > > > > >
> > > > > > > There are numerous possibilities to reference
> > > > > > previous value of the
> > > > > > indicator or any array.
> > > > > > > Please check out
> > > > > > http://www.amibroker.net/boards/viewtopic.php?t=81
> > > > > > for the details.
> > > > > > >
> > > > > > > Best regards,
> > > > > > > Tomasz Janeczko
> > > > > > > amibroker.com
> > > > > > > ----- Original Message -----
> > > > > > > From: "mik954" <mik-u@xxxx>
> > > > > > > To: <amibroker@xxxx>
> > > > > > > Sent: Tuesday, April 23, 2002 2:15 AM
> > > > > > > Subject: [amibroker] Re: Declare variable for
> > > > > > future use: No way in
> > > > > > AFL?
> > > > > > >
> > > > > > >
> > > > > > > > Tomasz,
> > > > > > > >
> > > > > > > > You mean that I cannot use REF() function to get
> > > > > > a previous
> > > > > > element
> > > > > > > > of an ARRAY mentioned later in the code?
> > > > > > > >
> > > > > > > > So in AFL there is no way to use a previous
> > > > > > value of a variable
> > > > > > to
> > > > > > > > define its new value? What a disappointment. Is
> > > > > > there any
> > > > > > workaround?
> > > > > > > >
> > > > > > > > Thanks,
> > > > > > > > Mike
> > > > > > > >
> > > > > > > >
> > > > > > > > --- In amibroker@xxxx, "Tomasz Janeczko"
> > > > > > <amibroker@xxxx> wrote:
> > > > > > > > > Mike,
> > > > > > > > >
> > > > > > > > > No, AFL operates on entire arrays and it uses
> > > > > > only single-pass
> > > > > > to
> > > > > > > > process all bars.
> > > > > > > > > So if you assign a value later in your code it
> > > > > > will have no
> > > > > > effect
> > > > > > > > on any lines that appeared
> > > > > > > > > before.
> > > > > > > > >
> > > > > > > > > Best regards,
> > > > > > > > > Tomasz Janeczko
> > > > > > > > > amibroker.com
> > > > > > > > > ----- Original Message -----
> > > > > > > > > From: "mik954" <mik-u@xxxx>
> > > > > > > > > To: <amibroker@xxxx>
> > > > > > > > > Sent: Monday, April 22, 2002 6:13 PM
> > > > > > > > > Subject: [amibroker] Declare variable for
> > > > > > future use (was TJ:
> > > > > > > > Actual trade profit vs. Theoretical)
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > > Hi, all!
> > > > > > > > > >
> > > > > > > > > > Well, so far no any response on my initial
> > > > > > post (even on
> > > > > > direct e-
> > > > > > > > > > mail to support@xxxx). It's weird. Maybe my
> > > > > > question wasn't
> > > > > > > > > > clear, or Tomasz was too busy.
> > > > > > > > > >
> > > > > > > > > > OK, let me ask in a different way. Is there
> > > > > > any way in AFL to
> > > > > > > > declare
> > > > > > > > > > variable/array and use its previos value
> > > > > > before setting
> > > > > > current
> > > > > > > > one?
> > > > > > > > > >
> > > > > > > > > > I mean:
> > > > > > > > > >
> > > > > > > > > > // var tradeProfit; // declare variable for
> > > > > > future use
> > > > > > > > > >
> > > > > > > > > > Buy = longEntry and ValueWhen(Sell,
> > > > > > tradeProfit) < 0;
> > > > > > > > > > Sell = LongExit;
> > > > > > > > > >
> > > > > > > > > > tradeProfit = ValueWhen(Sell, SellPrice) -
> > > > > > ValueWhen(Buy,
> > > > > > > > BuyPrice);
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Any suggestions are welcome.
> > > > > > > > > >
> > > > > > > > > > Thanks,
> > > > > > > > > > Mike
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Your use of Yahoo! Groups is subject to
> > > > > > http://docs.yahoo.com/info/terms/
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > > __________________________________________________
> > > > > Do You Yahoo!?
> > > > > Yahoo! Games - play chess, backgammon, pool and more
> > > > > http://games.yahoo.com/
> > > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > Your use of Yahoo! Groups is subject to 
> > > http://docs.yahoo.com/info/terms/
> > > 
> > > 
> > > 
> > > 
> > > 
> > > Your use of Yahoo! Groups is subject to 
> http://docs.yahoo.com/info/terms/ 
> > > 
> > > 
> > >