거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Telegram에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
Experts

Close Orders By Target or Cut Loss - MetaTrader 4용 expert

조회수:
11280
평가:
(28)
게시됨:
2021.03.31 11:02
업데이트됨:
2021.04.01 06:39
이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동
We use this EA as a trading tool.

There are 3 inputs required, as follows:

  1. Profit Target
  2. Cut Loss
  3. Magic Number
extern    double         inTargetProfitMoney     = 10;       //Target Profit ($)
extern    double         inCutLossMoney          = 0.0;      //Cut Loss ($)
extern    int            inMagicNumber           = 0;        //Magic Number


When this EA is executed, it will first call the OnInit () function. Where we will verify the input and variable initialization

int OnInit()
  {
//---
   if(inTargetProfitMoney <= 0)
     {
      Alert("Invalid input");
      return(INIT_PARAMETERS_INCORRECT);
     }

   inCutLossMoney = MathAbs(inCutLossMoney) * -1;

//---
   return(INIT_SUCCEEDED);
  }


And every time the price movement (tick) will call the OnTick () function

void OnTick()
  {
//---

   double   tFloating = 0.0;
   int tOrder  = OrdersTotal();
   for(int i=tOrder-1; i>=0; i--)
     {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
         if(OrderMagicNumber() == inMagicNumber)
           {
            tFloating   += OrderProfit()+OrderCommission() + OrderSwap();
           }
        }
     }

   if(tFloating >= inTargetProfitMoney || (tFloating <= inCutLossMoney && inCutLossMoney < 0))
     {
      fCloseAllOrders();
     }

  }

In the OnTick function, it will continue to calculate the total profit or loss. Then will close all orders that can be fulfilled the target or maximum loss limit

void fCloseAllOrders()
  {
   double   priceClose = 0.0;
   int tOrders = OrdersTotal();
   for(int i=tOrders-1; i>=0; i--)
     {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
         if(OrderMagicNumber() == inMagicNumber && (OrderType() == OP_BUY || OrderType() == OP_SELL))
           {
            priceClose  = (OrderType()==OP_BUY)?MarketInfo(OrderSymbol(), MODE_BID):MarketInfo(OrderSymbol(), MODE_ASK);
            if(!OrderClose(OrderTicket(), OrderLots(), priceClose, slippage, clrGold))
              {
               Print("WARNING: Close Failed");
              }
           }
        }
     }
  }


for more detailed information and sharing of mql4 code education, please join our telegram t.me/codeMQL




Trailing Stop with MagicNumber Trailing Stop with MagicNumber

Add on tool to support our trading by shifting stoploss (SL) to the profit area

2 MA Crossing 2 MA Crossing

For the purpose of learning to create an EA, I will share how to make an EA that uses 2 cross moving average indicators as a trading position entry signal.

Auto Scheduler Auto Scheduler

It's a auto scheduler.

Daily Target, Max Daily Losses with MagicNumber Daily Target, Max Daily Losses with MagicNumber

With the aim of educating you how to make trading tools that are simple and can be used immediately.