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

Trailing Stop with MagicNumber - MetaTrader 4용 expert

조회수:
9968
평가:
(26)
게시됨:
2021.03.30 13:17
이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동


Trailing stop really supports our trading by shifting the stop loss to the profit area so that we can always automatically secure our trades.

We will start the code by specifying the input trailing stop parameters

input    bool     isTrailingStop = true;  //Trailing Stop
input    int      trailingStart  = 15;    //Trailing Start (pips)
input    int      trailingStep   = 5;     //Trailing Step (pips)

input    int      MagicNumber = 0;        //Magic Number


Global Variable

//Variabel Global
double   myPoint    = 0.0;


When we run this EA, the OnInit () function will be executed for the first time and in this function we will validate and initialize the input variables.

int OnInit()
  {
  
   if (isTrailingStop && trailingStart <= 0){
      Alert ("Parameters incorrect");
      return(INIT_PARAMETERS_INCORRECT);
   }
   
   myPoint     = GetPipPoint(Symbol());
   
   return(INIT_SUCCEEDED);
  }


Every time a price movement (tick) occurs on the chart where this EA is paired, the OnTick () function will be executed. Inside the OnTick () function will call the setTrailingStop () function

void OnTick()
  {
//---
   setTrailingStop(MagicNumber);
   
  }


Function setTrailingStop()

void setTrailingStop(int magicNumber=0){
   if (isTrailingStop==false) return;
   
   int      tOrder = 0;
   string   pair = "";
   double   sl = 0.0, tp = 0.0;
   
   pair = Symbol();
   
   tOrder = OrdersTotal();
   for (int i=tOrder-1; i>=0; i--){
      bool hrsSelect = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if (OrderMagicNumber() == magicNumber && StringFind(OrderSymbol(), pair, 0) == 0 ){
         if (OrderType() == OP_BUY){
            if ( (Bid - (trailingStart * myPoint)) >= OrderOpenPrice()
                  && (Bid - ((trailingStart+trailingStep) * myPoint) >= OrderStopLoss() )
                )
            {
               sl = NormalizeDouble(Bid - (trailingStart * myPoint), Digits());
               if (!OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0, clrBlue)){
                  Print ("#", OrderTicket(), " gagal update sl");
               }
            }
         }
         
         if (OrderType() == OP_SELL){
            if ( (Ask + (trailingStart * myPoint)) <= OrderOpenPrice()
                  && ( (Ask + ((trailingStart+trailingStep) * myPoint) <= OrderStopLoss() ) || OrderStopLoss() == 0.0)
               )
            {
               sl = NormalizeDouble(Ask + (trailingStart * myPoint), Digits() );
               if (!OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0, clrBlue)){
                  Print ("#", OrderTicket(), " gagal update sl");
               }
            }
         }
      } //end if magicNumber
   }//end for
}


other standard functions required is GetPipPoint() 

// Fungsi GetPipPoint
double GetPipPoint(string pair)
{
   double point= 0.0;
   int digits = (int) MarketInfo(pair, MODE_DIGITS);
   if(digits == 2 || digits== 3) point= 0.01;
   else if(digits== 4 || digits== 5) point= 0.0001;
   return(point);
}


If you have any questions, please leave them in the comments or you can also join our group sharing (in Indonesian) t.me/codeMQL


We also provide the SignalForex App

You can support us by downloading and continue to use the SignalForex App to support your trading more profitably

https://play.google.com/store/apps/details?id=com.autobotfx.signalforex



    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.

    EA - The Simple Trading Panel - MT4 EA - The Simple Trading Panel - MT4

    The simple trading panel is a trading tool that is very interesting because it will allow you to predefine your StopLoss and your TakeProfit in term of pips.

    Close Orders By Target or Cut Loss Close Orders By Target or Cut Loss

    This EA is used as a trading tool to help us close all orders with a specific target in the form of money or cut loss. We can filter orders by magic number.

    Auto Scheduler Auto Scheduler

    It's a auto scheduler.