Pivot Function with Arrays--Funny Behavior

Questions about MultiCharts and user contributed studies.
kelnihat
Posts: 7
Joined: 11 Sep 2014
Has thanked: 1 time

Pivot Function with Arrays--Funny Behavior

Postby kelnihat » 24 Oct 2014

If the admins think that this should not be a new topic but a continuation of the "Pivot Function" topic, please move it there.

Below is some code I am testing, and that will hopefully become the cornerstone of something interesting :), but I am hitting a glitch I cannot understand. Will be grateful for suggestions.

Code: Select all

vars: counter(0), distance (.03),
lookbacklength(52),
HP(1), LP(-1), RS(2), LS(2),
chartbn(0),bar_offset (0),
oPivotPrice(0),oPivotBar(0);

Arrays: HighsArray[4](0),
HighsArrayBar[4](0),
HighDiffArray[3](0);

ClearPrintLog;

chartbn = MaxBarsBack + CurrentBar;

if chartbn > (lookbacklength + 2) then
For counter = 4 downto 1
begin
//Checks for the (5 - counter)th Pivot
Value50 = Pivot(high,lookbacklength,LS,RS, (5 - counter),HP, oPivotPrice,oPivotBar);
//Stores the high value of the (5 - counter)th Pivot in the (counter)th position of
//the array--so the most recent Pivot high value is stored in the highest array position
HighsArray[counter] = oPivotPrice;
//stores the "bars-back" value of the pivot to another array using the same logic
HighsArrayBar[counter] = oPivotBar;
end;

print("********");
print("HighsArray[4]:"," ", HighsArray[4]);
print("HighsArray[3]:"," ", HighsArray[3]);
print("HighsArray[2]:"," ", HighsArray[2]);
print("HighsArray[1]:"," ", HighsArray[1]);

print("offset value: ", HighsArrayBar[4]," >> HIGH at Bar[offset value]: ", High[HighsArrayBar[4]]);
print("offset value: ", HighsArrayBar[3]," >> HIGH at Bar[offset value]: ", High[HighsArrayBar[3]]);
print("offset value: ", HighsArrayBar[2]," >> HIGH at Bar[offset value]: ", High[HighsArrayBar[2]]);
print("offset value: ", HighsArrayBar[1]);
At this stage, the code is compiled properly and the output of the print statements is this
HighsArray[4]: 104.93
HighsArray[3]: 104.90
HighsArray[2]: 104.88
HighsArray[1]: 104.76
offset value: 8.00 >> HIGH at Bar[offset value]: 104.93
offset value: 13.00 >> HIGH at Bar[offset value]: 104.90
offset value: 19.00 >> HIGH at Bar[offset value]: 104.88
offset value: 35.00
:

Please notice the last line of the code, and the last line of the print statement...

Now, if I change the last line of the code by adding to it so that the last line structurally looks exactly like the previous three:

Code: Select all

print("offset value: ", HighsArrayBar[1]," >> HIGH at Bar[offset value]: ", High[HighsArrayBar[1]]);
the code still compiles but the output changes as follows:
HighsArray[4]: 102.45
HighsArray[3]: 102.43
HighsArray[2]: 102.41
HighsArray[1]: -1.00
offset value: 14.00 >> HIGH at Bar[offset value]: 102.45
offset value: 19.00 >> HIGH at Bar[offset value]: 102.43
offset value: 31.00 >> HIGH at Bar[offset value]: 102.41
and the attached error message is generated ("trying to address future data", etc.].

The error message makes sense if the value of HighsArray[1] is in fact -1.00; but it is not until MC changes it during "runtime" (or whatever inserting a study in a chart should be called--don't know since I am not a professional programmer).

Anyhow, I hope you can see why I am feeling like Ramses (or one of his generals, given that he delegated authority) watching the Red Sea part--you add a little bit of innocuous code and lo and behold, all your pivot values change. :)

Thanks and regards.
Attachments
Error Message.PNG
(5.89 KiB) Downloaded 249 times

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Pivot Function with Arrays--Funny Behavior

Postby Henry MultiСharts » 27 Oct 2014

kelnihat, please let us know if updating to MultiCharts 9.0 did not fix this issue.


Return to “MultiCharts”