Problem While....Loop

Questions about MultiCharts and user contributed studies.
Kam
Posts: 13
Joined: 22 May 2013
Has thanked: 8 times

Problem While....Loop

Postby Kam » 01 Jun 2013

Hi,

I am new here and hope that someone could help

I have a problem with the function of " While ....Loop".

I ran my indicator with "While...Loop" with different date range set.

Date Range 1 = From 2005 May 15 to 2013 June 02

First Result data Point = 2008 Mar 11

Date Range 2 = From 2000 May 15 to 2013 June 02

First Result data Point = 2006 Sept 29

I believe that there is some error in my coding because some data has been skipped in the analysis. How Shall I check it ??

Kam

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Problem While....Loop

Postby TJ » 02 Jun 2013

Post your code and let the community debug it for you.



How to post codes
viewtopic.php?f=16&t=11713

Kam
Posts: 13
Joined: 22 May 2013
Has thanked: 8 times

Re: Problem While....Loop

Postby Kam » 02 Jun 2013

HI .....

Hope Someone could help me out .... thks

Vars: Counter(1), NEW(0), MyAVG(0);

MyAvg = Average(Close,3);
Counter = 1 ;
IF High > High[1] then

WHILE low < MyAvg[Counter]
BEGIN
NEW = lOW[Counter];
Counter = Counter +1 ;
PLot5(NEW, "XXX",RED);
END;

Kam
Posts: 13
Joined: 22 May 2013
Has thanked: 8 times

Re: Problem While....Loop

Postby Kam » 02 Jun 2013

Please find below coding for your reference, It is not doing what I wanted because some data has skipped in the analysis

Vars: Counter(1), NEW(0), MyAVG(0);

MyAvg = Average(Close,3);
Counter = 1 ;
IF High > High[1] then

WHILE low < MyAvg[Counter]
BEGIN
NEW = lOW[Counter];
Counter = Counter +1 ;
plot6(MyAvg ,"3");
PLot5(nEW, "XXX",RED);
END;

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Problem While....Loop

Postby TJ » 02 Jun 2013

this might be helpful:
All About Loops
viewtopic.php?f=16&t=7351

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Problem While....Loop

Postby TJ » 02 Jun 2013

HI .....

Hope Someone could help me out .... thks

Vars: Counter(1), NEW(0), MyAVG(0);

MyAvg = Average(Close,3);
Counter = 1 ;
IF High > High[1] then

WHILE low < MyAvg[Counter]
BEGIN
NEW = lOW[Counter];
Counter = Counter +1 ;
PLot5(NEW, "XXX",RED);
END;
Can't help you just by looking at the codes.
Please explain what are you trying to achieve?
Maybe include a mock up chart (with arrows and notes) to demonstrate your vision?

Kam
Posts: 13
Joined: 22 May 2013
Has thanked: 8 times

Re: Problem While....Loop

Postby Kam » 02 Jun 2013

HI TJ.

The code is compiled. However, there is one thing that I don't quite understand. My data started from 2003 Dec 15 to 2013 June 02, the first plot was shown 2006 Aug 22. When I used the "Print" function; the first plot was show on 2003 Dec 29. This was totally confusing me. Those plot should point at the same date. I am new in the multichart. What I have been doing was playing around with each function.

What I am trying to achieve is to count how many backward point of moving average is greater than the current low when today high is greater than yesterday's high. The result is LOW[counter].


Kam

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Problem While....Loop

Postby TJ » 02 Jun 2013

HI TJ.
The code is compiled. However, there is one thing that I don't quite understand. My data started from 2003 Dec 15 to 2013 June 02, the first plot was shown 2006 Aug 22. When I used the "Print" function; the first plot was show on 2003 Dec 29. This was totally confusing me. Those plot should point at the same date. I am new in the multichart. What I have been doing was playing around with each function.
What I am trying to achieve is to count how many backward point of moving average is greater than the current low when today high is greater than yesterday's high. The result is LOW[counter].
Kam
You have not posted the code with the "print", so I can't comment on your bug.

My suggestions:
You should add more plot statements to your code, so that you can track the changes of your variables in the indicator.

Try not to use the WHILE loop. It is a more advanced form of loop; you can debug easier if you use IF-THEN-ELSE;

Good luck.

eg. of plots to track variables.

Code: Select all

Vars: Counter(1), NEW(0), MyAVG(0);

MyAvg = Average(Close,3);
plot10(myavg, "MyAvg");

Counter = 1 ;

IF High > High[1] then
begin
plot20(h, "h>h1");

WHILE low < MyAvg[Counter]
BEGIN
plot7(counter, "counter");
NEW = lOW[Counter];

Counter = Counter +1 ;
plot6(MyAvg ,"3");
PLot5(nEW, "XXX",RED);
end;
END;

Kam
Posts: 13
Joined: 22 May 2013
Has thanked: 8 times

Re: Problem While....Loop

Postby Kam » 02 Jun 2013

HI TJ,


Many Thks.

I used your code but the result was the same. The first plot was shown on Aug 2006 but the data was start as of Dec 2003.

Please find below is my print function.

Print(" Symbol ", Symbol, " Date ", Date:7:0, "MyAvg" , MyAvg, "HIGH", HIGH ,"nEW ",nEW );


kam

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Problem While....Loop

Postby TJ » 02 Jun 2013

HI TJ,
Many Thks.
I used your code but the result was the same. The first plot was shown on Aug 2006 but the data was start as of Dec 2003.
Please find below is my print function.
Print(" Symbol ", Symbol, " Date ", Date:7:0, "MyAvg" , MyAvg, "HIGH", HIGH ,"nEW ",nEW );
kam
Of course the result is the same, that was only an example to show you how to add plots to trace your variables. Your logic is at fault, that is why you are not getting the result you want. You will need to draw a chart with arrows and notes to illustrate what you want before you can develop a logic to plot the right dot on the right chart.

ps. your PRINT snippet in isolation is of no use for debugging.

Kam
Posts: 13
Joined: 22 May 2013
Has thanked: 8 times

Re: Problem While....Loop

Postby Kam » 02 Jun 2013

HI TJ..

THks

I am sure my coding is correct because all dots was at the correct place I expected.
The only thing I have been confused that is the first dot placement.
It should be occurred at somewhere earlier than Aug 2006 because My data was started as of Dec 2003.

Anyway , thks a lot

Kam

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Problem While....Loop

Postby arjfca » 08 Jun 2013

HI TJ..

THks

I am sure my coding is correct because all dots was at the correct place I expected.
The only thing I have been confused that is the first dot placement.
It should be occurred at somewhere earlier than Aug 2006 because My data was started as of Dec 2003.

Anyway , thks a lot

Kam
Kam, is your problem resolved? I had a similar problem when I started with MC.

If not, you may check your indicator properties, ....Max numbers bars of reference

If autodetect, then your code will start running at the first bar that is valid for your code witch should be related to your average value. Meaning, if your average is on 10 bars, your code will be started after the 10' bars because it need to do is computation on at least 10 bars

If the selection is on user specified and the value = 50 then your code will start after the 50' bars on the chart

Martin

Kam
Posts: 13
Joined: 22 May 2013
Has thanked: 8 times

Re: Problem While....Loop

Postby Kam » 09 Jun 2013

HI Martin,

Thank for your email.

I did change it to manual input from auto-detection.

My problem has not resolved.

I guess the fundamental question is associated to the logic of multicharts. It seems to me that multicharts ( version 8.5) cannot deal with something is changing. As advised by the support, I upgrade to version 8.7 beta 2, the result has been improved but the first dot was roughly 3.5 years different from the result which was coded in VBA.
KAm

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Problem While....Loop

Postby arjfca » 10 Jun 2013

HI Martin,

Thank for your email.

I did change it to manual input from auto-detection.

My problem has not resolved.

I guess the fundamental question is associated to the logic of multicharts. It seems to me that multicharts ( version 8.5) cannot deal with something is changing. As advised by the support, I upgrade to version 8.7 beta 2, the result has been improved but the first dot was roughly 3.5 years different from the result which was coded in VBA.
KAm
OK then maybe you could have a chat session with MC support
Good luck
Martin


Return to “MultiCharts”