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

RE: [amibroker] Re: Problem with for,if, else statement



PureBytes Links

Trading Reference Links

So you want, as Steve correctly stated,

if (SBAvg[i]>FBavg[i] AND ( CalcO[i]<= 0.11 AND CalcO[i]>= -0.11 ) ).

I can’t propose a solution that will show the current values of CalcC and CalcO  because a Bela Fleck  performance beckons, but doesn’t your loop necessarily yield their final values?

Bob

 

 

-----Original Message-----
From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx]On Behalf Of dmarval
Sent: Thursday, November 17, 2005 6:48 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] Re: Problem with for,if, else statement

 

Bob

If you mean that the FBAvg is acting as my zero line, then you are correct.

You wrote:

     "( CalcO[i]<= 0.11 OR CalcO[i]>= -0.11 ) restrains CalcO[i] to the band centered on zero.">>

if (SBAvg[i]>FBavg[i] AND CalcO[i]<= 0.11 OR CalcO[i]>= -0.11)// The price of 0.11 is the cap above the FBAvg OR -0.11 is the cap below the FBAvg.

I only want to search within these ranges. I don't want to find values that are over 0.11 cents or under the -0.11. Just either or condition within the +0.11 and -0.11 range.

In my earlier post  I said that if I scroll through the window, different values will appear in the title (but only showing value of the last trading day shown in the window) . But that is incorrect. Eventhough the values in the title are displaying different amounts when you scroll through the window, it does not match the last trading day within the display window.

The only value that shows correct in the title is the current end of the trading day. All other date periods in the title show false results when scrolling through window. And if clicked in various areas of the window ( your window display must be showing last trading period --today), the amount in the "Diff" title will not change. I am so stumped!

Sincerely,

Donna

 

If I click in the middle of the window --the value of that day will not show. I am at a loss


--- In amibroker@xxxxxxxxxxxxxxx, "Bob Jagow" <bjagow@xxxx> wrote:

I failed to read beyond the 1st line, Steve.

You're right, of course!!!

And it may well be that Donna wants to exclude [as per your 2nd choice] the band centered on zero

Bob

-----Original Message-----
From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx]On Behalf Of Terry
Sent: Thursday, November 17, 2005 4:08 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: RE: [amibroker] Problem with for,if, else statement

The problem is with this part:


( CalcO[i]<= 0.11 OR CalcO[i]>= -0.11 )

ANY number is ALWAYS less than +.11 OR greater than -.11, right?

1,000,000 is > -0.11

-1,000,000 is < +0.11

Pick a number, always TRUE.

This is why I suggested changing this part. In fact, I don't know what is wanted except I'm pretty sure ALWAYS TRUE is NOT the desired result.

I see the choices as:

( CalcO[i] <= 0.11 AND CalcO[i] >= -0.11 ) //Number is BETWEEN -0.11 and +0.11

or

( CalcO[i] >= 0.11 OR  CalcO[i] <= -0.11 ) //Number is either below -0.11 OR above +0.11

--

Terry

-----Original Message-----
From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf Of Bob Jagow
Sent: Thursday, November 17, 2005 16:23
To: amibroker@xxxxxxxxxxxxxxx
Subject: RE: [amibroker] Problem with for,if, else statement

Terry.,

Re the logic, he clearly wants

if (SBAvg[i]>FBavg[i] AND ( CalcO[i]<= 0.11 OR CalcO[i]>= -0.11 ) ).

[The added parens are needed because AND has a higher precedence than OR].

if (SBAvg[i]>FBavg[i] AND (CalcO[i]<= 0.11 OR CalcO[i]>= -0.11)         == true,

but if (SBAvg[i]>FBavg[i] AND CalcO[i]<= 0.11 AND CalcO[i]>= -0.11)     == false

Didn't check the looping logic because it should be doable with the original arrays IMO.

Regards,

Bob

-----Original Message-----
From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx]On Behalf Of Terry
Sent: Thursday, November 17, 2005 12:44 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: RE: [amibroker] Problem with for,if, else statement

One step at a time (saves me time!)

Please first fix this statement as ANY values always give TRUE the way it is. Note red text.

Change this:

if (SBAvg[i]>FBavg[i] AND CalcO[i]<= 0.11 OR CalcO[i]>= -0.11)

To this:

if (SBAvg[i]>FBavg[i] AND CalcO[i]<= 0.11 AND CalcO[i]>= -0.11)

With or without that fix, I get different answers for each day I click on.

If that doesn't fix it, write back

Also, please "wrap" your Title statement in _N(Title = …); to keep the garbage out of the Interpretation window.

_N(Title = Name() + " (" + StrLeft(FullName(), 10) + ") --  " + Date() +"   O: "+ WriteVal(O,1.2 )+ "   H: " + WriteVal(H,1.2) + "   L: " + WriteVal(L,1.2) + "     C: " + C + "         Fast = " + WriteVal(FBAvg,1.2)+ EncodeColor( colorPaleTurquoise )+ wi);

PS: It's okay, IMHO, to write. I do this frequently as required.

If (cond1) {do stuff}

Else if (cond2) {do other stuff}

Else {do third stuff}

--

Terry

-----Original Message-----
From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf Of dmarval
Sent: Thursday, November 17, 2005 13:26
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] Problem with for,if, else statement

Can someone please help me figure out what's wrong with

my "for,if,else...." code. I am new at attempting to code. My

problem is that my formula only calculates the value difference for

the last trading day, and if I click on any other previous trading

days, my title value still states value of the last trading day.

What I would like this code to do, is calculate the different values

for each individual current and previous trading days and to have

the values reflected in my title.

FastPeriods =5;

SlowPeriods = 20;

FBAvg = Sum( Volume * Close, FastPeriods ) / Sum( Volume,

FastPeriods);

SBAvg = Sum( Volume * Close,  SlowPeriods ) / Sum( Volume,

SlowPeriods);

Plot(FBAvg,"Fast ",colorAqua,styleLine);

Plot(SBAvg,"Slow ",colorDarkBlue,styleLine+styleThick);

//Calculations//

CalcO = O - FBAvg;

CalcC = C - FBAvg;

for( i = 0; i < BarCount; i++ )

{

   if (SBAvg[i]>FBavg[i] AND CalcO[i]<= 0.11 OR CalcO[i]>= -0.11)

   {

      wi = "    DiffO:    " + WriteVal(O[i] - FBAvg[i],1.2);

   }

   else if(SBAvg[i]>FBAvg[i] AND CalcC[i]<= 0.11 OR CalcC[i]>= -0.11)

   {

      wi = "    DiffC:   " + WriteVal(CalcC[i],1.2);

   }

   else

  {

      wi = "------";

  }

}

Title = Name() + " (" + StrLeft(FullName(), 10) +

      ") --  " + Date() +"   O: "+  WriteVal(O,1.2 )+ "   H: " +

WriteVal(H,1.2) + "   L: " + WriteVal(L,1.2) + "     C: " + C

+ "         Fast = " + WriteVal(FBAvg,1.2)+ EncodeColor(

colorPaleTurquoise )+

  wi;

------------------------ Yahoo! Groups Sponsor --------------------~-->

Try Online Currency Trading with GFT. Free 50K Demo. Trade

24 Hours. Commission-Free.

http://us.click.yahoo.com/RvFikB/9M2KAA/U1CZAA/GHeqlB/TM

--------------------------------------------------------------------~->

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

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




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 other support material please check also:
http://www.amibroker.com/support.html





YAHOO! GROUPS LINKS