본문 바로가기

개발

[javascript] 빗썸 비트코인 최근 100일 가격 가중치 구하기

비트코인 최근 100일 가격 가중치 구하기 

현재 가격이 0에 가까울수록 높은 가격대에 속합니다.

오늘 가격의 100일간 가중치를 통해 상승장 하락장을 구분할 수 있습니다.

 

현재 가중치 50% 이상을 기준으로 7일 이전 가중치가 50%보다 낮고 현재 가중치가 7일전 가중치보다 낮다면 현재 상승 추세에 진입했다고 판단할 수 있습니다.

현재 소스 에서는 1일봉을 기준으로 하였지만 4시간봉 15분봉 1분봉 등 다양한 타임프레임을 이용하여 돌파 매매에 지표로 쓰기 좋습니다.

<!DOCTYPE html>
<html>
<head>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script>
    $(document).ready(function() {
      $.ajax({
        url: "https://api.bithumb.com/public/candlestick/btc",
        data: {
          'count': 100
        },
        success: function(data) {
          const prices = data.data.map(d => d[4]).reverse();
          const maxPrice = Math.max(...prices);
          const minPrice = Math.min(...prices);
          const currentPrice = prices[0];
          const threeDaysAgoPrice = prices[6];

          let currentWeight = 0;
          let threeDaysAgoWeight = 0;
          if (currentPrice >= maxPrice) {
            currentWeight = 100;
          } else if (currentPrice <= minPrice) {
            currentWeight = 0;
          } else {
            currentWeight = (currentPrice - minPrice) / (maxPrice - minPrice) * 100;
          }

          if (threeDaysAgoPrice >= maxPrice) {
            threeDaysAgoWeight = 100;
          } else if (threeDaysAgoPrice <= minPrice) {
            threeDaysAgoWeight = 0;
          } else {
            threeDaysAgoWeight = (threeDaysAgoPrice - minPrice) / (maxPrice - minPrice) * 100;
          }

		  $('#current_price').text(currentPrice);
          $('#current_weight').text(currentWeight.toFixed(2) + '%');
          $('#three_days_ago_weight').text(threeDaysAgoWeight.toFixed(2) + '%');
        }
      });
    });
  </script>
</head>
<body>
  <div>
    현재 가격: <span id="current_price"></span>원
  </div>
  <div>
    현재 가중치: <span id="current_weight"></span>

  </div>
  <div>
    7일 전 종가 가중치: <span id="three_days_ago_weight"></span>
  </div>
</body>
</html>

 

실시간 실제 결과

여러 방면으로 활용해 보세요. 현재 글을 업로드 하는 시간 기준으로는 가중치가 0에 가까울때입니다. 기분이 좋네요 ㅎㅎ 100일중 거의 최고 가격을 유지 중 입니다

현재 가격:
현재 가중치:
7일 전 종가 가중치:

 

감사합니다. 도움이 되셧다면 공감 눌러 주세요!

반응형