瀏覽代碼

图表指标文字信息

jieyu 4 年之前
父節點
當前提交
52a6a14ade

+ 53 - 0
RMA/app/src/main/java/cn/muchinfo/rma/view/base/chart/ChartDataAdapter.kt

@@ -145,7 +145,60 @@ class ChartDataAdapter {
             }
         }
         return stickList
+    }
+
+    fun historyDataToStickList(history: List<HistoryDatas>, ohldate: ArrayList<ChartData>){
+        val stickList = arrayListOf<StickEntity>()
+        if(history.isNotEmpty()){
+            var dClose = 0.0
+            var dEMA12 = 0.0
+            var dEMA26 = 0.0
+            var dDIF = 0.0
+            var dDEA = 0.0
+            var dMACD = 0.0
+            ohldate.clear()
+            ohldate.addAll(historyDataToChartData(history))
+            ohldate.forEachIndexed { index, historyDatas ->
+                val chartData = historyDatas as ChartData
+                dClose = chartData.getClose()
+                if (index == 0) {
+                    dEMA12 = dClose
+                    dEMA26 = dClose
+                    dDIF = 0.0
+                    dDEA = 0.0
+                    dMACD = 0.0
+                } else {
+                    val lastChartData = ohldate[index - 1] as ChartData
+                    dEMA12 = MTPChartControl.getEMA12(lastChartData.getEMA12(), dClose)
+                    dEMA26 = MTPChartControl.getEMA26(lastChartData.getEMA26(), dClose)
+                    dDIF = MTPChartControl.getDIF(dEMA12, dEMA26)
+                    dDEA = MTPChartControl.getDEA(lastChartData.getDEA(), dDIF)
+                    dMACD = MTPChartControl.getMACD(dDIF, dDEA)
+                }
 
+                chartData.setEMA12(dEMA12)
+                chartData.setEMA26(dEMA26)
+                chartData.setDIF(dDIF)
+                chartData.setDEA(dDEA)
+                chartData.setMACD(dMACD)
+
+                if (index < stickList.size) {
+                    if (dMACD > 0) {
+                        stickList.get(index).setHigh(dMACD)
+                        stickList.get(index).setLow(0.0)
+                    } else {
+                        stickList.get(index).setHigh(0.0)
+                        stickList.get(index).setLow(dMACD)
+                    }
+                } else {
+                    if (dMACD > 0) {
+                        stickList.add(StickEntity(dMACD, 0.0, 2014))
+                    } else {
+                        stickList.add(StickEntity(0.0, dMACD, 2014))
+                    }
+                }
+            }
+        }
     }
 
 

+ 23 - 0
RMA/app/src/main/java/cn/muchinfo/rma/view/base/chart/old/timeCharts/KChartView.java

@@ -18,8 +18,10 @@ import com.desfate.chart.MACandleStickChart;
 import com.desfate.chart.MTPTabHost;
 import com.desfate.chart.MTPTabHostListener;
 import com.desfate.chart.MinusStickChart;
+import com.desfate.chart.data.ChartData;
 import com.desfate.chart.data.ChartDataContainer;
 import com.desfate.chart.entity.LineEntity;
+import com.desfate.chart.entity.OHLCEntity;
 import com.desfate.chart.event.ITouchEventResponse;
 
 import java.util.ArrayList;
@@ -183,6 +185,7 @@ public class KChartView extends FrameLayout {
         LineEntity MA15 = candle_chart.getLineData().get(2);
         if (MA5.getLineData() == null || MA10.getLineData() == null || MA15.getLineData() == null) {
             setStickChart();
+            showSum(minusStickChart, 0);
             return;
         }
         double ma5Val = MA5.getLineData().get(MA5.getLineData().size() - 1);
@@ -192,6 +195,7 @@ public class KChartView extends FrameLayout {
         candle_chart.setDecimalNum(new ChartDataAdapter().getGoodsInfoMarket(goodsCode).getGoodsInfo().getDecimalplace());
         candle_chart.invalidate();
         setStickChart();
+        showSum(minusStickChart, 0);
     }
 
 
@@ -255,6 +259,25 @@ public class KChartView extends FrameLayout {
     private void showSum(MinusStickChart minusStickChart, int index) {
         try {
             String textString = tab.getCurrentValue();
+            if (getString(R.string.mtp_rsi).equals(textString)) {
+                StickChartTools.showRSISum(context, minusStickChart, new ChartDataAdapter().historyDataToOHLDate(history), info_text, index);
+            } else if (getString(R.string.mtp_macd).equals(textString)) {
+                ArrayList<ChartData> ohldate = new ArrayList<>();
+                new ChartDataAdapter().historyDataToStickList(history, ohldate);
+                StickChartTools.showMACDSum(context, ohldate, info_text, index);
+            } else if (getString(R.string.mtp_psy).equals(textString)) {
+                StickChartTools.showPSYSum(context, minusStickChart, new ChartDataAdapter().historyDataToOHLDate(history), info_text, index);
+            } else if (getString(R.string.mtp_cci).equals(textString)) {
+                StickChartTools.showCCISum(context, minusStickChart, new ChartDataAdapter().historyDataToOHLDate(history), info_text, index);
+            } else if (getString(R.string.mtp_dma).equals(textString)) {
+                StickChartTools.showDMASum(context, minusStickChart, new ChartDataAdapter().historyDataToOHLDate(history), info_text, index);
+            } else if (getString(R.string.mtp_kdj).equals(textString)) {
+                StickChartTools.showKDJSum(context, minusStickChart, new ChartDataAdapter().historyDataToOHLDate(history), info_text, index);
+            } else if (getString(R.string.mtp_bias).equals(textString)) {
+                StickChartTools.showBIASSum(context, minusStickChart, new ChartDataAdapter().historyDataToOHLDate(history), info_text, index);
+            } else if (getString(R.string.tas_total).equals(textString)) {
+                StickChartTools.showTotalSum(context, minusStickChart, new ChartDataAdapter().historyDataToOHLDate(history), info_text, index);
+            }
         } catch (Exception e) {
             e.printStackTrace();
         }

+ 221 - 0
RMA/app/src/main/java/cn/muchinfo/rma/view/base/chart/old/timeCharts/StickChartTools.java

@@ -1,6 +1,9 @@
 package cn.muchinfo.rma.view.base.chart.old.timeCharts;
 
 import android.content.Context;
+import android.graphics.Color;
+import android.text.Html;
+import android.widget.TextView;
 
 import com.desfate.chart.MinusStickChart;
 import com.desfate.chart.data.BidChartTotalDatas;
@@ -15,7 +18,9 @@ import com.desfate.chart.entity.LineEntity;
 import com.desfate.chart.entity.OHLCEntity;
 import com.desfate.chart.entity.StickEntity;
 import com.desfate.chart.ui.old.OTC.controls.TargetControl;
+import com.desfate.chart.util.MathUtil;
 
+import java.text.NumberFormat;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -495,4 +500,220 @@ public class StickChartTools {
         minusstickchart.setDecimalNum(2);
         minusstickchart.postInvalidate();
     }
+
+    /***********************文本显示*********************************/
+
+
+    /**
+     * @param minusStickChart
+     * @param index
+     */
+    public static void showTotalSum(Context context, MinusStickChart minusStickChart, List<OHLCEntity> mOHLCList, TextView textView, int index) {
+        if (mOHLCList.size() == 0) {
+            textView.setText("");
+            return;
+        }
+        String bias = "<font color='%s'> VOL5:%s </font><font color='%s'> VOL10:%s </font><font color='%s'> VOLNUM:%s </font>";
+        String htmlString = "";
+        String total5 = "";
+        String total10 = "";
+        String totalNum = "";
+        try {
+            index = index == 0 ? minusStickChart.getNewLineData().get(0).getLineData().size() - 1 : index;
+            total5 = MathUtil.roundNum(minusStickChart.getNewLineData().get(0).getLineData().get(index), 2);
+            total10 = MathUtil.roundNum(minusStickChart.getNewLineData().get(1).getLineData().get(index), 2);
+            totalNum = "" + (int) minusStickChart.getNewStickData().get(index).getHigh();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        htmlString = String.format(bias, context.getResources().getColor(com.desfate.chart.R.color.mtp_chart_k_total5), total5,
+                context.getResources().getColor(com.desfate.chart.R.color.mtp_chart_k_total10), total10, Color.RED, totalNum);
+        textView.setText(Html.fromHtml(htmlString));
+    }
+
+    /**
+     * BIAS6 BIAS12 BIAS24
+     *
+     * @param minusStickChart
+     * @param index
+     */
+    public static void showBIASSum(Context context, MinusStickChart minusStickChart, List<OHLCEntity> mOHLCList, TextView textView, int index) {
+        if (mOHLCList.size() == 0) {
+            textView.setText("");
+            return;
+        }
+        String bias = "<font color='%s'> BIAS6:%s </font><font color='%s'> BIAS12:%s </font><font color='%s'> BIAS24:%s</font>";
+        String htmlString = "";
+        String bias6String = "0.0";
+        String bias12String = "0.0";
+        String bias24String = "0.0";
+        try {
+            index = index == 0 ? minusStickChart.getNewLineData().get(0).getLineData().size() - 1 : index;
+            bias6String = MathUtil.roundNum(minusStickChart.getNewLineData().get(0).getLineData().get(index), 2);
+            bias12String = MathUtil.roundNum(minusStickChart.getNewLineData().get(1).getLineData().get(index), 2);
+            bias24String = MathUtil.roundNum(minusStickChart.getNewLineData().get(2).getLineData().get(index), 2);
+        } catch (Exception e) {
+        }
+        htmlString = String.format(bias, context.getResources().getColor(com.desfate.chart.R.color.mtp_chart_k_bias_6), bias6String,
+                    context.getResources().getColor(com.desfate.chart.R.color.mtp_chart_k_bias_12), bias12String, context.getResources().getColor(com.desfate.chart.R.color.mtp_chart_k_bias_24), bias24String);
+        textView.setText(Html.fromHtml(htmlString));
+    }
+
+    public static void showKDJSum(Context context, MinusStickChart minusStickChart, List<OHLCEntity> mOHLCList, TextView textView, int index) {
+        if (mOHLCList.size() == 0) {
+            textView.setText("");
+            return;
+        }
+        String bias = "<font color='%s'> K:%s </font><font color='%s'> D:%s </font><font color='%s'> J:%s </font>";
+        String htmlString = "";
+        String kString = "0.0";
+        String dString = "0.0";
+        String jString = "0.0";
+        try {
+            index = index == 0 ? minusStickChart.getNewLineData().get(0).getLineData().size() - 1 : index;
+            kString = MathUtil.roundNum(minusStickChart.getNewLineData().get(0).getLineData().get(index), 2);
+            dString = MathUtil.roundNum(minusStickChart.getNewLineData().get(1).getLineData().get(index), 2);
+            jString = MathUtil.roundNum(minusStickChart.getNewLineData().get(2).getLineData().get(index), 2);
+        } catch (Exception e) {
+        }
+
+        htmlString = String.format(bias, context.getResources().getColor(com.desfate.chart.R.color.mtp_chart_k_kdj_k), kString,
+                    context.getResources().getColor(com.desfate.chart.R.color.mtp_chart_k_kdj_j), dString, context.getResources().getColor(com.desfate.chart.R.color.mtp_chart_k_kdj_j), jString);
+
+        textView.setText(Html.fromHtml(htmlString));
+    }
+
+    /**
+     * DMA AMA
+     *
+     * @param minusStickChart
+     * @param index
+     */
+    public static void showDMASum(Context context, MinusStickChart minusStickChart, List<OHLCEntity> mOHLCList, TextView textView, int index) {
+        if (mOHLCList.size() == 0) {
+            textView.setText("");
+            return;
+        }
+        String dma = "<font color='%s'> DMA:%s </font><font color='%s'> AMA:%s</font>";
+        String htmlString = "";
+        String dmaString = "0.0";
+        String amaString = "0.0";
+        try {
+            index = index == 0 ? minusStickChart.getNewLineData().get(0).getLineData().size() - 1 : index;
+            dmaString = MathUtil.roundNum(minusStickChart.getNewLineData().get(0).getLineData().get(index), 2);
+            amaString = MathUtil.roundNum(minusStickChart.getNewLineData().get(1).getLineData().get(index), 2);
+        } catch (Exception e) {
+        }
+
+
+        htmlString = String.format(dma, context.getResources().getColor(com.desfate.chart.R.color.mtp_chart_k_dma), dmaString,
+                context.getResources().getColor(com.desfate.chart.R.color.mtp_chart_k_dma_ama), amaString);
+
+        textView.setText(Html.fromHtml(htmlString));
+    }
+
+    public static void showCCISum(Context context, MinusStickChart minusStickChart, List<OHLCEntity> mOHLCList, TextView textView, int index) {
+        if (mOHLCList.size() == 0) {
+            textView.setText("");
+            return;
+        }
+        String cci = "<font color='%s'> CCI:%s </font>";
+        String htmlString = "";
+        String cciValue = "0.0";
+        try {
+            index = index == 0 ? minusStickChart.getNewLineData().get(0).getLineData().size() - 1 : index;
+            cciValue = MathUtil.roundNum(minusStickChart.getNewLineData().get(0).getLineData().get(index), 2);
+        } catch (Exception e) {
+        }
+        htmlString = String.format(cci, context.getResources().getColor(com.desfate.chart.R.color.mtp_chart_k_cci), cciValue);
+        textView.setText(Html.fromHtml(htmlString));
+    }
+
+    /**
+     * 显示RSI对应的sum
+     */
+    public static void showRSISum(Context context, MinusStickChart minusStickChart, List<OHLCEntity> mOHLCList, TextView textView, int index) {
+        if (mOHLCList.size() == 0) {
+            textView.setText("");
+            return;
+        }
+        String rsi = "<font color='%s'> RSI6:%s </font><font color='%s'> RSI12:%s </font><font color='%s'> RSI24:%s </font>";
+        String strHtml = "";
+        try {
+            index = index == 0 ? minusStickChart.getNewLineData().get(0).getLineData().size() - 1 : index;
+            String value6 = MathUtil.roundNum(minusStickChart.getNewLineData().get(0).getLineData().get(index), 2);
+            String value12 = MathUtil.roundNum(minusStickChart.getNewLineData().get(1).getLineData().get(index), 2);
+            String value24 = MathUtil.roundNum(minusStickChart.getNewLineData().get(2).getLineData().get(index), 2);
+            strHtml = String.format(rsi,
+                    context.getResources().getColor(com.desfate.chart.R.color.mtp_chart_k_rsi6), value6,
+                    context.getResources().getColor(com.desfate.chart.R.color.mtp_chart_k_rsi12), value12,
+                    context.getResources().getColor(com.desfate.chart.R.color.mtp_chart_k_rsi24), value24);
+        } catch (Exception e) {
+            strHtml = "RSI:0.0";
+        }
+        textView.setText(Html.fromHtml(strHtml));
+    }
+
+    /**
+     * 显示MACD对应的sum
+     */
+    public static void showMACDSum(Context context , List<ChartData> mOHLCList, TextView textView, int index) {
+        if (mOHLCList.size() == 0) {
+            textView.setText("");
+            return;
+        }
+        try {
+            setMinusStickText(context, textView,  mOHLCList.get(index == 0 ? mOHLCList.size() - 1 : index));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    private static void setMinusStickText(Context context, TextView minusStickTV, ChartData data) {
+        NumberFormat nf = NumberFormat.getInstance();
+        nf.setGroupingUsed(false);
+        nf.setMaximumFractionDigits(2);
+        nf.setMinimumFractionDigits(2);
+        String macd = nf.format(data.getMACD());
+        String strMACDColor = "#FF0000";
+        if (data.getMACD() < 0) {
+            strMACDColor = "#009900";
+        }
+        String dif = nf.format(data.getDIF());
+        String dea = nf.format(data.getDEA());
+        String source = "<font color='%s'>MACD:%s </font>";
+        source += "<font color='" + context.getResources().getColor(com.desfate.chart.R.color.mtp_chart_k_macd_dif) + "'>DIF:%s </font>";
+        source += "<font color='" + context.getResources().getColor(com.desfate.chart.R.color.mtp_chart_k_macd_dea) + "'>DEA:%s</font>";
+
+        String strHtml = String.format(source, strMACDColor, macd, dif, dea);
+        minusStickTV.setText(Html.fromHtml(strHtml));
+    }
+
+    /**
+     * PSY PSYMA
+     *
+     * @param minusStickChart
+     * @param index
+     */
+    public static void showPSYSum(Context context, MinusStickChart minusStickChart, List<OHLCEntity> mOHLCList, TextView textView, int index) {
+        if (mOHLCList.size() == 0) {
+            textView.setText("");
+            return;
+        }
+        String psy = "<font color='%s'> PSY:%s </font><font color='%s'> PSYMA:%s </font>";
+        String strHtml = "";
+        String psyValue = "0.0";
+        String psyMAValue = "0.0";
+        try {
+            index = index == 0 ? minusStickChart.getNewLineData().get(0).getLineData().size() - 1 : index;
+            psyValue = MathUtil.roundNum(minusStickChart.getNewLineData().get(0).getLineData().get(index), 2);
+            psyMAValue = MathUtil.roundNum(minusStickChart.getNewLineData().get(1).getLineData().get(index), 2);
+        } catch (Exception e) {
+        }
+
+        strHtml = String.format(psy, context.getResources().getColor(com.desfate.chart.R.color.mtp_chart_k_psy), psyValue,
+                context.getResources().getColor(com.desfate.chart.R.color.mtp_chart_k_psy_ma), psyMAValue);
+
+        textView.setText(Html.fromHtml(strHtml));
+    }
 }

+ 4 - 0
RMA/chart/src/main/java/com/desfate/chart/GridChart.java

@@ -995,6 +995,10 @@ public class GridChart extends BaseChart implements OnGestureListener, OnScaleGe
         int action = event.getAction();
         if (isEnableCrossOnTouch()) {
             switch (action) {
+                case MotionEvent.ACTION_DOWN:{
+                    float postX = getClickPostX();
+                }
+                break;
                 case MotionEvent.ACTION_UP: {
                     displayCrossXOnTouch = displayCrossYOnTouch = true;
                     if (this.getClickPostX() > 0 || this.getClickPostY() > 0) {