[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

Donna,

 

Okay, now that I understand your code better…

 

The problem with the display not changing the "status" and always printing "stay" is that Amibroker does not have ARRAYS for STRINGS. In other words you cannot say:

 

wi = IIf(cond1,"stay","exit"); //This will get a syntax error.

 

The reason you don't get an error is you are using a loop and assigning a single value to wi, which is just fine. However, each bar of your loop continually reassigns the value of wi ending up with the last day (today) being the value that always prints since it can hold only a single text string.

 

THE FIX: I took out your loop and used ARRAY code (much faster anyway). Instead of setting wi = "some text", I set wi to a flag of 1, 2 or 0. Then in then I load "text" into a variable I arbitrarily named myresult using WriteIf(wi == 1,"DiffO", WriteIf(wi == 2,"DiffC", "Stay"). This changes everyday as you wish.

--

Terry

 

 

//Full code follows:

 

SetChartOptions(1,chartShowDates);

 

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;

 

wi = IIf(SBAvg > FBavg AND CalcO >= -0.11 AND CalcO <= 0.11, 1, IIf(SBAvg > FBAvg AND CalcC >= -0.11 AND CalcC <= 0.11, 2, 0));

 

Plot(SBAvg > FBAvg AND (CalcO >= -0.11 AND CalcO <= 0.11),"CalcO True",colorBlack,styleDots|styleOwnScale,0,1);

Plot(SBAvg > FBAvg AND (CalcC >= -0.11 AND CalcC <= 0.11),"CalcC True",colorWhite,styleDots|styleOwnScale,-0.1,1.1);

 

myresult = "\n" + WriteIf(wi == 1, "DiffO" + WriteVal(CalcO,1.2), WriteIf(wi == 2, "DiffC" + WriteVal(CalcC,1.2), "Stay"));

 

_N(Title = Name() + " (" + StrLeft(FullName(), 10) + ") -- " + Date()

 + "\n O: " + WriteVal(O,1.2)

 + "\n H: " + WriteVal(H,1.2)

 + "\n L: " + WriteVal(L,1.2)

 + "\n C: " + WriteVal(C,1.2)

 + "\n Fast = " + WriteVal(FBAvg,1.2) + EncodeColor(colorRed ) + myresult);

 

-----Original Message-----
From:
amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf Of dmarval
Sent:
Friday, November 18, 2005 09:18
To:
amibroker@xxxxxxxxxxxxxxx
Su
bject: [amibroker] Re: Problem with for,if, else statement

 

Good Morning Terry,

I hope this works without the (>>. I don't know why they show. I dislike when they appear. They are annoying. I just cut and paste the messages. When I sent my first reply there were so many. So if I posting incorrectly, tell me the right way. I am always willing to learn.

Again, thank you for helping me with this. I have so many different ways to try to get the values to show in the title when I click on the various different bars. Being new to this and attempting to get Amibroker to do what I want is so hard and frustrating. I know your formual works It does give me the name and values, in the title, for the last trading day. And yes, the values change as you scroll through, which seem to me to means that the code does work. I just can't figure out for the life of me, why when I click on individual days the title will not reflect the value. I agree with you that the days are not many. That is why I posted the symbol WMT. Stupid as this may sound -- I found the values in the title by scrolling through, yet when I click on the actual day, it doesn't show me the value. My code is posted below:

 

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);

Plot(Close, "Close", colorBlack, styleBar);

//Calculations//

CalcO = O - FBAvg;

CalcC = C - FBAvg;

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

{

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

{

wi = " DiffO: " + WriteVal(CalcO[i],1.2) ;

}

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

{

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

}

else

{

wi = "stay";

}

}

 

_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);

fdfsfs


--- In amibroker@xxxxxxxxxxxxxxx, "Terry" <MagicTH@xxxx> wrote:

Good morning Donna,

 

Could you please paste your entire code and send it again. The code below is incomplete (and has extraneous >> in it which I removed, but there is still missing code). I will then run some tests for you.

 

If you prefer, you can send the AFL file directly to MagicTH [at] comcast.net

--

Terry

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

 

Sorry, typo error.

WMT --August 24,2005  Open: 46.35 ,   FBAvg: 46.38 gives value DiffO:  -.03

WMT --September 9,2005  Open: 45.65 ,   FBAvg: 45.58 gives value DiffO:  +.07

Donna

--- In amibroker@xxxxxxxxxxxxxxx, "dmarval" <dmarval@xxxx> wrote:

Terry,

You are right!! I'm sorry. I should have paid more attention. It does make it easier to read the code this way. I put the code as stated and got  syntax error, so I put 2 brackets and it works.

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

{>>

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

   {>>

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

   }>>

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

   {>>

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

   }>>

   else>>

  {>>

      wi = "   stay  ";

>> 

>_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);

>

Yes, I would like and appreciate it if you could help me  see the values on the chart area for a given bar. I have clicked on the bars but the title will not show value of the day I clicked. ie:

WMT --August 24,2005  Open: 46.35 ,   FBAvg: 46.38 gives value DiffO:  +.07

instead the value in the title says stay.

Thank you.

Sincerely,

Donna


--- In amibroker@xxxxxxxxxxxxxxx, "Terry" <MagicTH@xxxx> wrote:

Donna,

You said: "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."

I gave you the answer already. I also said try this first and I'd help more, but if you aren't going to listen then I'm not going to help. I make mistakes too so my answers are not always perfect, but in this case I double checked after Bob's comment and re-explained. This answer is in this email below and re-copied here:

 

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

 

It makes more sense for reading code to reverse the terms (the plus and minus values and < > ) like this:

 

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

 

 

Simply scrolling through a window changes nothing except the values reported in the Y axis on the right side of the graph. If you want to see values (on the chart or in the Interpretation window) for a given bar, you must click on the bar.

 

 

As to Diff not changing, I see you have the same logic error inside the loop as shown above. Apply the same fix that as above to stop getting the same answers regardless of the data values.

 

 

There is more code I have not evaluated yet. If the above is changed and still does not solve your problem, write back.




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