I am creating a panel indicator which uses the "CheckGroup" class. My question is; in the "SimplePanel" indicator when the "OnChangeCheckGroup" function is called, how can i determine which of the boxes are checked using the value given by the check group value function? Any help is greatly appreciated.
Hi ErikTheRed,
There are plenty ways to solve that. Basically, we just keep subtracting the total value with the highest available value starting from the highest value down to the smallest value, if the result is bigger or equal than the smallest value, then we keep subtracting with the next available highest value until the result is less than the smallest value.
first example, using lot of ifs, which is annoying but perhaps self explanatory ...
string Item =""; int value = 14; if (value >= 8) {Item = " 3"; value -= 8;} if (value >= 4) {Item = Item+" 2"; value -= 4;} if (value >= 2) {Item = Item+" 1"; value -= 2;} if (value >= 1) {Item = Item+" 0"; value -= 1;} Alert ("Item is "+Item);
second example using for loop iteration ...
int value = 14; double power; int item [4] = {0, 0, 0, 0}; for (int pos = 3; pos >= 0; pos--) { power = MathPow (2,pos); if (value >= power) {item [pos] = 1; value -= power;} Alert ("item on "+IntegerToString (pos)+" is "+IntegerToString (item [pos])); }
I compiled all of those example but not check any further, like I didn't add break condition inside for loop and else if value is smaller than power ;).
Like I've said there are many ways to do that, so you may experiment with those examples.
:D
Hi ErikTheRed,
There are plenty ways to solve that. Basically, we just keep subtracting the total value with the highest available value starting from the highest value down to the smallest value, if the result is bigger or equal than the smallest value, then we keep subtracting with the next available highest value until the result is less than the smallest value.
first example, using lot of ifs, which is annoying but perhaps self explanatory ...
second example using for loop iteration ...
I compiled all of those example but not check any further, like I didn't add break condition inside for loop and else if value is smaller than power ;).
Like I've said there are many ways to do that, so you may experiment with those examples.
:D
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am creating a panel indicator which uses the "CheckGroup" class. My question is; in the "SimplePanel" indicator when the "OnChangeCheckGroup" function is called, how can i determine which of the boxes are checked using the value given by the check group value function? Any help is greatly appreciated.