持っているポジションの含み益を取得して一定の利益がでたら決済するようにしたいです。エラーの原因が分かりません。修正を教えてください。

 
//+------------------------------------------------------------------+
//|                                                      testea1.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

#include <Trade\Trade.mqh>
#include <Object.mqh>
#include <Trade\PositionInfo.mqh>
//必要なパラメータ
input double Volume=0.1;//ロット数
input int SL=200;//ストップロス
input int TP=200;//テイクプロフィット
input int stealthPoint = 25;
input int MAPeriod = 20;//移動平均期間
input int Deviation=50;//スリッページ
input int Magic=1234;//マジックナンバー

//直近の注文状況をチェックするグローバル変数
bool BuyPosition, SellPosition;
bool PositionCheck(double price, double distance)
  {
   for(int i = 0; i < PositionsTotal(); i++)
     {
      PositionSelect(i);
      double posPrice = PositionGetDouble(POSITION_PRICE_OPEN);
      if(MathAbs(posPrice - price) < distance)
        {
         return true;
        }
     }
   return false;
  }

//| Expert initialization function                                   |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
// ポジションの含み益を取得する
double profit = PositionsTotal() > 0 ? PositionGetDouble(POSITION_PROFIT) : 0.0;

// 決済する含み益の閾値を設定する
double profitThreshold = 100.0;

// 含み益が閾値に達したら決済する
if (profit >= profitThreshold) {
    // すべてのオーダーをクローズする
    int totalOrders = OrdersTotal();
    for (int i = totalOrders - 1; i >= 0; i--) {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
            if (OrderSymbol() == Symbol()) {
                OrderClose(OrderTicket(), OrderLots(), SymbolInfoDouble(Symbol(), SYMBOL_BID), 3);
            }
        }
    }
}
'SELECT_BY_POS' - undeclared identifier testea1.mq5 64 28
'MODE_TRADES' - undeclared identifier testea1.mq5 64 43
'OrderSelect' - wrong parameters count testea1.mq5 64 13
   built-in: bool OrderSelect(ulong) testea1.mq5 64 13
'OrderSymbol' - undeclared identifier testea1.mq5 65 17
')' - expression expected testea1.mq5 65 29
implicit conversion from 'number' to 'string' testea1.mq5 65 17
'OrderClose' - undeclared identifier testea1.mq5 66 17
'OrderTicket' - undeclared identifier testea1.mq5 66 28
')' - expression expected testea1.mq5 66 40
',' - unexpected token testea1.mq5 66 41
'OrderTicket' - some operator expected testea1.mq5 66 28
')' - expression expected testea1.mq5 66 53
',' - unexpected token testea1.mq5 66 54
',' - unexpected token testea1.mq5 66 94
')' - unexpected token testea1.mq5 66 97
expression has no effect testea1.mq5 66 96
implicit conversion from 'number' to 'string' testea1.mq5 28 22
Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
  • 2023.02.19
  • www.mql5.com
MQL5: язык торговых стратегий для MetaTrader 5, позволяет писать собственные торговые роботы, технические индикаторы, скрипты и библиотеки функций
理由: