Skip to content

Commit

Permalink
Merge pull request #24 from CAFECA-IO/feature/rsi_index
Browse files Browse the repository at this point in the history
Feature/rsi index
  • Loading branch information
Luphia authored Apr 22, 2024
2 parents f77721d + 91a34c7 commit 27f905a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auto-trade",
"version": "0.0.1+5",
"version": "0.0.1+6",
"description": "",
"author": "",
"private": true,
Expand Down
29 changes: 19 additions & 10 deletions src/strategies/strategy/autoArima.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,44 @@
import * as ARIMA from 'arima';
import { rsi } from 'technicalindicators';

export function suggestion(data: {
currentPrice: number;
priceArray: number[];
spreadFee: number;
holdingStatus: string;
rsiValue: number; // add this as a new field
}) {
let suggestion = 'WAIT';
const arima = new ARIMA('auto');
arima.train(data.priceArray);
// const AbsspreadFee = Math.abs(data.spreadFee);
const arimaPredict = arima.predict(15);
const predict: number[] = arimaPredict[0];
// const predictProfit = AbsspreadFee * 2.8;
const currentPrice = data.currentPrice;
if (predict[predict.length - 1] > currentPrice) {
const rsiInput = {
period: 14, // Set the desired value for the period property
values: data.priceArray, // Pass the data.priceArray as the values property
};
const rsiValue = rsi(rsiInput);
const rsiAverage = average(rsiValue, 3); // calculate a moving average of the RSI
if (predict[predict.length - 1] > currentPrice && rsiAverage < 70) {
// buy signal with low RSI
suggestion = 'BUY';
}
if (predict[predict.length - 1] < currentPrice) {
} else if (predict[predict.length - 1] < currentPrice && rsiAverage > 30) {
// sell signal with high RSI
suggestion = 'SELL';
}
if (suggestion === 'WAIT') {
return suggestion;
}
if (data.holdingStatus === 'WAIT') {
if (data.holdingStatus === 'WAIT' || data.holdingStatus === suggestion) {
return suggestion;
} else {
return 'CLOSE'; // close the position when the suggestion changes
}
if (suggestion !== data.holdingStatus) {
return 'CLOSE';
}
return 'WAIT';
}

function average(arr: number[], n: number): number {
return arr.reduce((a, b) => a + b, 0) / n;
}

export function takeProfit(data: {
Expand Down

0 comments on commit 27f905a

Please sign in to comment.