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

Re: Declare variable for future use: What about JavaScript?



PureBytes Links

Trading Reference Links

Tomasz,

I was wrong. You are not "absolutely" right saying: "in ANY language 
you should not use a variable without initializing it first."

Not in ANY language. I forgot about scripting languages like 
JavaScript :)

Mike

--- In amibroker@xxxx, "mik954" <mik-u@xxxx> wrote:
> Tomasz,
> 
> Sorry to bother you with this stupid question. You are absolutly 
> right that "in ANY language you should not use a variable without 
> initializing it first." But in AFL we deal with not scalar 
variables, 
> but ARRAYS. So when I want to initialize array, in fact I want to 
> initialize a "pointer" to array, not ALL ACTUAL VALUES of array. 
> Right?
> 
> Here is my idea in English: 
> 
> Buy signal will be accepted only if previous ACTUAL trade in the 
same 
> direction was a loss.
> 
> Here is the code which doesn't work:
> 
> Buy = 0;
> Sell = 0;
> tradeProfit = 0;
> 
> Buy = longEntry and ValueWhen(Sell, tradeProfit) < 0);
> Sell = LongExit;
> tradeProfit = ValueWhen(Sell, SellPrice) - ValueWhen(Buy, 
BuyPrice);
> 
> The problem is that ValueWhen(Sell, tradeProfit) always returns 0. 
> May be because "initialization" of tradeProfit resets all previous 
> values to 0.
> 
> I guest something like this might work:
> 
> var Sell;
> var tradeProfit;
> 
> Buy = longEntry and ValueWhen(Sell, tradeProfit) < 0);
> Sell = LongExit;
> tradeProfit = ValueWhen(Sell, SellPrice) - ValueWhen(Buy, 
BuyPrice);
> 
> 
> Thanks,
> Mike
> 
> 
> 
> --- In amibroker@xxxx, "Tomasz Janeczko" <amibroker@xxxx> wrote:
> > Mike,
> > 
> > In fact in ANY language you should not use a variable without 
> initializing it first.
> > But as to the problem - it would be better if you explain in 
plain 
> english
> > what do you want to achieve, then it will be possible to write 
the 
> code.
> > 
> > Best regards,
> > Tomasz Janeczko
> > amibroker.com
> > ----- Original Message ----- 
> > From: "mik954" <mik-u@xxxx>
> > To: <amibroker@xxxx>
> > Sent: Tuesday, April 23, 2002 3:50 PM
> > Subject: [amibroker] Re: Declare variable for future use: 
> Left/Right side of the formula
> > 
> > 
> > > 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/ 
> > > > > 
> > > > > 
> > > > >
> > > 
> > > 
> > > 
> > > 
> > > 
> > > Your use of Yahoo! Groups is subject to 
> http://docs.yahoo.com/info/terms/ 
> > > 
> > > 
> > >