Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop distance #1391

Merged
merged 2 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/components/charts/CandleChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ import {
TooltipComponent,
VisualMapComponent,
VisualMapPiecewiseComponent,
// MarkAreaComponent,
MarkLineComponent,
// MarkPointComponent,
} from 'echarts/components';
import { use } from 'echarts/core';
import { CanvasRenderer } from 'echarts/renderers';
Expand All @@ -54,6 +57,9 @@ use([
TooltipComponent,
VisualMapComponent,
VisualMapPiecewiseComponent,
// MarkAreaComponent,
MarkLineComponent,
// MarkPointComponent,

CandlestickChart,
BarChart,
Expand Down
37 changes: 37 additions & 0 deletions src/shared/charts/tradeChartData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ export function generateTradeSeries(
): ScatterSeriesOption {
const { tradeData } = getTradeEntries(dataset, trades);

const openTrades = trades.filter((t) => t.is_open);

const tradesSeries: ScatterSeriesOption = {
name: nameTrades,
type: 'scatter',
Expand Down Expand Up @@ -158,6 +160,41 @@ export function generateTradeSeries(
symbolSize: 13,
data: tradeData,
};
// Show distance to stoploss
if (openTrades.length > 0) {
// Ensure to import and "use" whatever feature in candleChart! (MarkLine, MarkArea, ...)
// Offset to avoid having the line at the very end of the chart
const offset = dataset.timeframe_ms * 10;

tradesSeries.markLine = {
symbol: 'none',
itemStyle: {
color: '#ff0000AA',
},
label: {
show: true,
position: 'middle',
},
lineStyle: {
type: 'solid',
},
data: openTrades.map((t) => {
return [
{
name: 'Stoploss',
yAxis: t.stop_loss_abs,
xAxis:
dataset.data_stop_ts - offset > t.open_timestamp
? t.open_timestamp
: dataset.data_stop_ts - offset,
},
{
yAxis: t.stop_loss_abs,
xAxis: t.close_timestamp ?? dataset.data_stop_ts,
},
];
}),
};
}
return tradesSeries;
}
Loading