首页 > 解决方案 > 如何修复关闭 [1] 和关闭 [2]

问题描述

我的 EA 交易有问题,现在我将向您展示带有交易屏幕截图的代码(这种情况经常发生)记住

void OnTimer()
{
  //---
  if (currBars != Bars){
    calculate_price_levels();
    //debug_levels();
  
    check_nearest_levels();
  
    if (is_session()){
      if (Close[2] < Nearest_Up_Level && Close[1] >= Nearest_Up_Level && isAvailableOrder()){ 
        //Print("BUY entry, Nearest_Up_Level:",Nearest_Up_Level, ",Close[2]:",Close[2], ",Close[1]:",Close[1]);
    
        double lot = _get_lot_size (Stop_Loss);
        OpenTrade(Symbol(), OP_BUY, lot);
      }

      if (Close[2] > Nearest_Down_Level && Close[1] <= Nearest_Down_Level && isAvailableOrder()){
        //Print("SELL entry, Nearest_Down_Level:",Nearest_Down_Level, ",Close[2]:",Close[2], ",Close[1]:",Close[1]);

        double lot = _get_lot_size (Stop_Loss);
        OpenTrade(Symbol(), OP_SELL, lot);
      }
    }

    currBars = Bars;
  }

  if (Trailing_Stop > 0) trail_sl();
  // if (BE > 0) check_be();

  int trades_number = _get_number_of_trades();
  if (trades_number < Trades_Number_0) check_last_trade_result();

  Trades_Number_0 = trades_number;
}

void check_nearest_levels(){
  int size = ArraySize(Price_Levels);

  for (int i = 0; i < size; i++){
    if (Close[2] > Price_Levels[i] && Close[2] < Price_Levels[i + 1]){
      Nearest_Down_Level = Price_Levels[i];
      Nearest_Up_Level = Price_Levels[i + 1];

      BUY_TP_Price = 0;
      if (size > i + 2) BUY_TP_Price = Price_Levels[i + 2];
      else BUY_TP_Price = Nearest_Up_Level + StepPips * Point * mp;

      Next_BUY_TP_Price = 0;
      if (size > i + 3) Next_BUY_TP_Price = Price_Levels[i + 3];
      else Next_BUY_TP_Price = BUY_TP_Price + StepPips * Point * mp;

      SELL_TP_Price = 0;
      if (i >= 1) SELL_TP_Price = Price_Levels[i - 1];
      else SELL_TP_Price = Nearest_Down_Level - StepPips * Point * mp;

      Next_SELL_TP_Price = 0;
      if (i >= 2) Next_SELL_TP_Price = Price_Levels[i - 2];
      else Next_SELL_TP_Price = SELL_TP_Price - StepPips * Point * mp;

      break;
    }
  }
}

图 1

我想做的事的例子
https://i.stack.imgur.com/ec1ji.png

标签: mql4metatrader4

解决方案


推荐阅读