/// <summary> /// MACDを計算する /// 定められたSecondsValue周期で呼び出される /// </summary> public override void Calculate() { oldHistogram = currentHistogram; // 12分足EMA double temp1 = NonApiUtility.CalcEma(ShortEmaLength, baseList, NonApiUtility.Last(List[0])); List[0].Add(temp1); // 26分足EMA double temp2 = NonApiUtility.CalcEma(LongEmaLength, baseList, NonApiUtility.Last(List[1])); List[1].Add(temp2); // MACD double macd = temp1 - temp2; List[2].Add(macd); // MACDシグナル // 9分 double signal = NonApiUtility.CalcEma(SignalLength, List[2], NonApiUtility.Last(List[3])); List[3].Add(signal); // ヒストグラム currentHistogram = macd - signal; List[4].Add(currentHistogram); }
/// <summary> /// チャネルを更新する /// 定められたSecondsValue周期で呼び出される /// </summary> public override void Calculate() { // 最大値・最小値の更新 if (tempMax > 0) { MaxList.Add(tempMax); MinList.Add(tempMin); tempMax = -1; tempMin = -1; } else { MaxList.Add(NonApiUtility.Last(baseList)); MinList.Add(NonApiUtility.Last(baseList)); } // 要素数を超えたらカットする if (baseList.Count > Length) { baseList.RemoveAt(0); } if (MaxList.Count > Length) { MaxList.RemoveAt(0); } if (MinList.Count > Length) { MinList.RemoveAt(0); } }
/// <summary> /// 解離計算する /// </summary> public override void Calculate() { var last1 = NonApiUtility.Last(baseList1, 0); var last2 = NonApiUtility.Last(RefExchange[(int)RefId].BaseHistory.BaseList, 0); // 差 var subtract = last1 - last2; List[0].Add(subtract); // 乖離率 var subPoint = subtract / last2 * 100.0; List[1].Add(subPoint); // 差の移動平均線 double average = NonApiUtility.CalcSma(List[0], Length); if (average <= 0) { average = CurrentPrice; } List[2].Add(average); // 差のシグマ計算 Sigma = NonApiUtility.CalcSigma(Length, List[0], average) * Magnification; List[3].Add(Sigma); // 1シグマ上 List[4].Add(average + Sigma); // 1シグマ下 List[5].Add(average - Sigma); }
/// <summary> /// 指数平均移動線(EMA)を計算する /// 定められたSecondsValue周期で呼び出される /// </summary> public override void Calculate() { // 履歴に追加 List[0].Add(NonApiUtility.CalcEma(Length, baseList, NonApiUtility.Last(List[0]))); }
/// <summary> /// 毎秒実行される /// </summary> public override async void Update() { try { var currentPrice = NonApiUtility.Last(BaseHistory.BaseList); //interval.Update(); //if (!interval.IsCounting) //{ if (positionManager.GetIsBreaking(currentPrice)) { // ブレイク検出、急いで成行注文 if (positionManager.NextTurn == OrderSide.BUY) { // 売る Console.WriteLine($"売:{currentPrice}"); positionManager.Sell(); //interval.InitCount(); positionManager.BuyOrderPrice = BaseChannel.CurrentMax; Console.WriteLine($"次の買トリガー:{currentPrice} -> {positionManager.BuyOrderPrice}"); } if (positionManager.NextTurn == OrderSide.SELL) { // 買う Console.WriteLine($"買:{currentPrice}"); positionManager.Buy(); //interval.InitCount(); positionManager.SellOrderPrice = BaseChannel.CurrentMin; Console.WriteLine($"次の売トリガー:{positionManager.SellOrderPrice} <- {currentPrice}"); } } //} if (orderCounter.Update()) { if (await Client.CheckServerStatus()) { if (BaseChannel.ReadyCount <= 0) { positionManager.BuyOrderPrice = BaseChannel.CurrentMax; positionManager.SellOrderPrice = BaseChannel.CurrentMin; // 次の注文設定 switch (positionManager.NextTurn) { case OrderSide.BUYSELL: // 初回のみ Console.WriteLine($"初回トリガー:{positionManager.SellOrderPrice} <- {currentPrice} -> {positionManager.BuyOrderPrice}"); break; case OrderSide.BUY: Console.WriteLine($"買トリガー:{currentPrice} -> {positionManager.BuyOrderPrice}"); break; case OrderSide.SELL: Console.WriteLine($"売トリガー:{positionManager.SellOrderPrice} <- {currentPrice}"); break; } } else { Console.WriteLine($"準備中:{BaseChannel.ReadyCount}"); } } } } catch (Exception ex) { Error(ex); } }
/// <summary> /// 毎秒実行される /// </summary> public override async void Update() { try { // 現在価格 var currentPrice = NonApiUtility.Last(BaseHistory.BaseList); if (orderCounter.Update()) { if (ParentOrders != null) { // トレンド判定 OrderSide trend = OrderSide.BUYSELL; string message = ""; Console.WriteLine($"S{BaseSmaShort.CurrentValue} L{BaseSmaLong.CurrentValue}"); if (BaseSmaShort.CurrentValue > BaseSmaLong.CurrentValue) { trend = OrderSide.BUY; message = "上げ買い"; } else if (BaseSmaShort.CurrentValue < BaseSmaLong.CurrentValue) { trend = OrderSide.SELL; message = "下げ売り"; } if (SfdMode) { if (trend == OrderSide.BUY && BaseSfd.IsSfdModeHigh) { message = $"SFD{BaseSfd.CurrentValue}なので買い中止"; trend = OrderSide.BUYSELL; } else if (trend == OrderSide.SELL && BaseSfd.IsSfdModeLow) { message = $"SFD{BaseSfd.CurrentValue}なので売り中止"; trend = OrderSide.BUYSELL; } } // 注文管理更新 tpm.Update(ParentOrders, trend); if (await Client.CheckServerStatus()) { // 値幅を決定 var orderHeight = CalcOrderHeight(); if (trend == OrderSide.BUY) { // 上げトレンド Console.WriteLine(message); tpm.Buy(currentPrice, orderHeight, OrderAmount); } else if (trend == OrderSide.SELL) { // 下げトレンド Console.WriteLine(message); tpm.Sell(currentPrice, orderHeight, OrderAmount); } } } else { Console.WriteLine("注文情報取得失敗のため、トラリピの更新をしません"); } } } catch (Exception ex) { Error(ex); } }