After taking a position I'm tracking some values (max, high, low etc.) in an array. These values are used to determine the moment when the trailingstop must come in action.
After the position is closed. How do I clear the values in the array (I assume this is in memory somewhere). So it will only use values to fill the array during a specific position.
Any reserved word for this?
How to clear the values of an array?
Re: How to clear the values of an array?
From the help,
https://www.multicharts.com/trading-sof ... etMaxIndex
I have not read about a reserve word nor have I done this but I am thinking you could reduce the SetMaxIndex down to 1 or maybe even zero the reset it up to the size you want (two statements). The Wiki index is below on the command.Dynamic arrays (arrays with an unlimited number of elements) are one-dimensional, and are initialized at declaration as having only one element. Declared dynamic arrays can be resized using Array_SetMaxIndex.
https://www.multicharts.com/trading-sof ... etMaxIndex
-
- Posts: 401
- Joined: 19 Jan 2011
- Location: Netherlands
- Has thanked: 85 times
- Been thanked: 124 times
Re: How to clear the values of an array?
This way I managed to clear the values of an array:
With taking a position the dynamic array is set to add one index per the close of the bar of the chart timeframe.
Thanks for directing me in the right direction bowlesj3.
With taking a position the dynamic array is set to add one index per the close of the bar of the chart timeframe.
Code: Select all
Vars:
Setmaxindex(false),
PositionOpen(false),
Macd_count(0),
MACD_daily_diff_intraday(0),
Highest_macd(0);
Array:
Macd_diff_array[] (0); // to store the macd diff per bar, but you can use anything
If (MP <> 0) then begin
setmaxindex = true; // used to change the setmaxindex
PositionOpen = true; // used for only count when a position is open
end
Else begin
Setmaxindex = false;
PositionOpen = false;
end;
If (barstatus(1)=2) and positionOpen then begin
If close <> close[1] then begin
Macd_count = macd_count + 1;
end;
// expand the array by one
array_setmaxindex(Macd_diff_array, macd_count);
If Setmaxindex then begin
// post data to array
Macd_diff_array[macd_count] = MACD_daily_diff_intraday;
// calculate the highest macd diff value
Highest_macd = HighestArray(macd_diff_array, macd_count);
end;
end;
If Setmaxindex = false then begin
// decline the array to zero
array_setmaxindex(Macd_diff_array, 0);
end;
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: How to clear the values of an array?
Assigns zero value to elements of mas array with index from 1 to mas array size.array_setvalrange(mas, 1, array_getmaxindex(mas), 0);