Guest User

Untitled

a guest
Jan 18th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. <?php
  2. $prev1 = array(
  3. "ema99" => "0.0010309",
  4. "ema200" => "0.00010166",
  5. "price" => "0.00010670",
  6. "ema9" => "0.00010688",
  7. "ema20" => "0.00010616",
  8. "ema26" => "0.00010576",
  9. "ema50" => "0.00010448",
  10. );
  11.  
  12. print_r(getColorRanges($prev1));
  13.  
  14.  
  15. function getColorRanges($prev1){
  16. $prev = array();
  17. $i = 0; // iterator to assign associative array
  18. $ref; // used to as index of price
  19. $temp; // to assign prev value to compare indexes if difference is -1 so it is in the order
  20. $t = true; // previously i gave it true as a considering sequence is in the order if once it is broken there is no chance of it is coming true and i false it
  21. $true = ['0' => 0 , '9' => 1, '20' => 2, '26' => 3, '50' => 4, '99' => 5, '200' => 6];
  22.  
  23. foreach ($prev1 as $key => $value) {
  24. if($key == "price"){
  25. $prev[0] = $i;
  26. }
  27. else {
  28. $prev[substr($key,3,strlen($key)-3)] = $i;
  29. }
  30. $i++;
  31. }
  32.  
  33. $ref = $prev[0];
  34. $i = 0;
  35.  
  36. foreach ($prev as $key => $value) {
  37. if($prev[$key] < $ref){
  38. $prev1['ema'.$key] = 'red';
  39. }
  40. else if($prev[$key] == $ref){
  41. if ((($prev[0] > $prev[99] || $prev[0] > $prev[200]) && $ref <= 2) || $ref == 0) {
  42. $prev1['price'] = 'blue';
  43. }
  44. else if($ref == 6){
  45. $prev1['price'] = 'red';
  46. }
  47. else{
  48. $prev1['price'] = 'green';
  49. }
  50. }
  51. else {
  52. if(($true[$temp] - $true[$key] == -1) && $t){
  53. $prev1['ema'.$key] = 'blue';
  54. }else{
  55. $t = false;
  56. $prev1['ema'.$key] = 'green';
  57. }
  58. }
  59. $temp = $key;
  60. }
  61. return $prev1;
  62. }
Add Comment
Please, Sign In to add comment