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]);
: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]]);
and the attached error message is generated ("trying to address future data", etc.].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
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.