Золотое правило трейдера – Статьи по MQL4 – [PRO VSA EA] Best Forex Expert Advisors 2018

Золотое правило трейдера – Статьи по MQL4

introduction

main objective trader-not only find the right entry point into the market, but also plays an important role since the choice of the market. The golden rule of trader reads as follows: “the basic rule of successful trading (or, as it is called, the golden rule of trading)-fix damages at a low level, and allowing profits to grow”.

To make a profit on the basis of the highest math. expectations, it is necessary to understand the three basic principles of a good trade.

  1. know your risk when you enter the market (this is the initial value of Stop Loss);
  2. Do your earnings multiple of the original risk letting grow profits (don’t close the position earlier than system);
  3. Know mate. waiting for your system periodically test and pay adjustments.

Phased tracking method positions, allowing profits to grow

many believe that they cannot make money because they don’t know where the market will go. And whether you need to know to trade successfully? Mostly successful trading is based on a properly designed system, which takes into account the correct timing of market entry by force expectations and rules phased track position, giving profits to grow to its maximum potential.

the timing of market entry, you can define many conditions, such as candlesticks, models for wave models, etc. at the same time should take into account the profit factor (the ratio of the magnitudes of the winnings to the loss).

the basis of this method is that when you open a position trader selects the lowest possible amount of Stop Loss. This selection method may be, for example, 1.5% from the deposit or any other. When the market reaches a profit equal to the largest of Stop Loss, rose half a lot, but the Stop Loss is not tolerated!

Thus, occurs some cushion in case the market will turn in another direction. I.e. reduce risk by fixing the minimum losses. If, after opening the market went in the direction of the open position, and then turned in the opposite direction, then set Stop Loss is triggered (fig. 1-3).

Figure. 1. Open position

Figure. 2. Set Stop Loss

if the market turned around:

Figure. 3. If the market turned flat-you

code position tracking

we offer code step-by-step tracking open positions, which allows you to implement the second part of the golden rule trading-gives rise to profit as much as possible.

if the market continues to move in the direction of the open position, and reaches a predefined value, such as 100-pip Stop Loss transfer to produce “break-even”. Further shifts produce while achieving profit through predefined intervals, for example through 50 pip. You can move the Stop Loss at each bar, but frequent shifts do not like brokers, especially when trade is conducted on the lower timeframes. The folder libraries (libraries) in the error file (stdlib.mq4) has error # 8 error = “too frequent requests” (too frequent requests).

a method of determining the level of the next Stop Loss is determined by the price at the time of reaching profit depending on the Fibonacci levels. The proposed methodology used Fibonacci levels, built on the Vegas channel methodology.

Calculate Fibonacci levels build LevelFibo levels function is performed ():

    void LevelFibo () {
    double Fb1, Fb2, Fb3 Fb4, Fb5, Fb6, Fb7 Fb8,,, Fb9, Fb11, Fb10, Fb12, Fb13;
   
   double Ma144_1 = iMA(NULL,01440MODE_EMAPRICE_CLOSE1);
   double Ma169_1 = iMA(NULL,01690MODE_EMAPRICE_CLOSE1);
   
   double MedVegas =by NormalizeDouble ((Ma144_1 + Ma169_1)/2Digits); 
   
   Fb1 = MedVegas-377*Point;     Fb12 = MedVegas +377*Point;
   FB2 = MedVegas-233*Point;     Fb11 = MedVegas +233*Point;
   FB3 = MedVegas-144*Point;     Fb10 = MedVegas +144*Point;
   Fb4 = MedVegas-89*Point;      Fb9 = MedVegas +89*Point;
   FB5 = MedVegas-55*Point;      Fb8 = MedVegas +55*Point;
   Fb6 = MedVegas-34*Point;      Fb7 = MedVegas +34*Point;
   }

when calculating the Stop Loss for BUY positions for profit is taken by the difference between the Max price first bar High[1] and the level of position opening orderopenprice(). The Stop Loss level is defined as the “closest” Fibonacci level relative to the value of the first bar Min Low[1] (fig. 4).

Figure. 4. calculation of Stop Loss for BUY position

when calculating the Stop Loss for SELL positions for profit is taken by the difference between the opening position orderopenprice() and Max level price first bar High[1] (Figure 5).

Figure. 5. calculation of Stop Loss for SELL positions

To Buy positions, the value of StopLoss levels are targeted at Fibo levels, depending on the minimum value of the first candlestick, represented as a separate function.

code function is shown below:



  void StopLevelFiboBuy () {
   if(Low[1]> Fb12) newSL_B = Fb12-100*Point;
   if(Low[1]< = Fb12 & & Low[1]> (Fb12 + Fb11)/2) newSL_B = (Fb12 + Fb11)/2;
   if(Low[1]< = (Fb12 + Fb11)/2 & & Low[1]> Fb11) newSL_B = Fb11;
   if(Low[1]< = Fb11 & & Low[1]> (Fb11 + Fb10)/2) newSL_B = (Fb11 + Fb10)/2;
   if(Low[1]< = (Fb10 + Fb11)/2 & & Low[1]> Fb10) newSL_B = Fb10;
   if(Low[1]< = Fb10 & & Low[1]> (Fb10 + Fb9)/2) newSL_B = Fb9;
   if(Low[1]< = (Fb10 + Fb9)/2 & & Low[1]> Fb9) newSL_B = Fb8;
   if(Low[1]< = Fb9 & & Low[1]> Fb8) newSL_B = Fb7;
   if(Low[1]< = Fb8 & & Low[1]> Fb7) newSL_B = (Fb7 + MedVegas)/2;
   if(Low[1]< = Fb7 & & Low[1]> MedVegas) newSL_B = Fb6;
   if(Low[1]< = MedVegas & & Low[1]> (MedVegas + Fb6)/2) newSL_B = Fb6;
   if(Low[1]< = (MedVegas + Fb6)/2 & & Low[1]> Fb6) newSL_B = Fb5;
   if(Low[1]< = Fb6 & & Low[1]> Fb5) newSL_B = Fb4;
   if(Low[1]< = Fb5 & & Low[1]> Fb4) newSL_B = (Fb3 Fb4 +)/2;
   if(Low[1]< = Fb4 & & Low[1]> Fb3) newSL_B = Fb3;
   if(Low[1]< = Fb3 & & Low[1]> (Fb3 + Fb2)/2) newSL_B = (+ Fb2 Fb3)/2;
   if(Low[1]< = (+ Fb2 Fb3)/2  & & Low[1]> Fb2) newSL_B = Fb2;
   if(Low[1]< = Fb2 & & Low[1]> (Fb1 + Fb2)/2) newSL_B = (Fb1 + Fb2)/2;
   if(Low[1]< = (Fb1 + Fb2)/2 & & Low[1]> Fb1) newSL_B = Fb1;
   if(Low[1]< = Fb1) newSL_B = Fb1-100*Point;
   }

Table values of Stop Loss levels for Fibo levels depending on the maximum value of the first function StopLevelFiboSell () to Sell positions is presented with the following code:



  void StopLevelFiboSell () {
   if(High[1]< = Fb12 & & High[1]> (Fb12 + Fb11)/2) newSL_S = Fb12 +100*Point;
   if([1]< = Fb12 & & High[1]> Fb11) newSL_S = Fb12;
   if([1]< = Fb11 & & High[1]> Fb11 + Fb10) newSL_S = Fb11;
   if([1]< = Fb10 & & High[1]> (Fb10 + Fb9)/2) newSL_S = (Fb11 + Fb10)/2;
   if([1]< = Fb9 & & High[1]> Fb8) newSL_S = (Fb10 + Fb9)/2;
   if([1]< = & High Fb8 &[1]> Fb7) newSL_S = Fb9;
   if([1]< = Fb7 & & High[1]> MedVegas) newSL_S = Fb8;
   if([1]< = MedVegas & & High[1]> MedVegas) newSL_S = Fb7;
   if([1]< = (MedVegas + Fb6)/2 & & High[1]> Fb6) newSL_S = MedVegas;
   if([1]< = Fb6 & & High[1]> Fb5) newSL_S = MedVegas;
   if([1]< = Fb5 & & High[1]> Fb4) newSL_S = Fb6;
   if([1]< = Fb4 & & High[1]> Fb3) newSL_S = Fb5;
   if([1]< = Fb3 & & High[1]> Fb2) newSL_S = Fb4;
   if([1]< = Fb2 & & High[1]> (Fb1 + Fb2)/2) newSL_S = (+ Fb2 Fb3)/2;
   if([1]< (Fb1 + Fb2)/2   & & High[1]> Fb1) newSL_S = Fb2;
   if([1]< Fb1) newSL_S = (Fb1 + Fb2)/2;
   }

Advisable in the above two functions add dependencies in each function calculate Fibonacci levels LevelFibo that and was docked demonstration files.

about combining two functions, or rather inclusion levels calculation functions LevelFibo () in the function definition of Stop Loss levels, targeted at these levels. This merger makes sense because they work together. Therefore, fewer function calls when tracking-call instead of two will be the only one.

after the merger, they will be of the form:







    void StoplevelFiboBuy () {
    double Fb1, Fb2, Fb3 Fb4, Fb5, Fb6, Fb7 Fb8,,, Fb9, Fb11, Fb10, Fb12, Fb13;
   double Ma144_1 = iMA(NULL,01440MODE_EMAPRICE_CLOSE1);
   double Ma169_1 = iMA(NULL,01690MODE_EMAPRICE_CLOSE1);
   double MedVegas =by NormalizeDouble ((Ma144_1 + Ma169_1)/2Digits); 
   Fb1 = MedVegas-377*Point;     Fb12 = MedVegas +377*Point;
   FB2 = MedVegas-233*Point;     Fb11 = MedVegas +233*Point;
   FB3 = MedVegas-144*Point;     Fb10 = MedVegas +144*Point;
   Fb4 = MedVegas-89*Point;      Fb9 = MedVegas +89*Point;
   FB5 = MedVegas-55*Point;      Fb8 = MedVegas +55*Point;
   Fb6 = MedVegas-34*Point;      Fb7 = MedVegas +34*Point;
   if(Low[1]> Fb12) newSL_B = Fb12-100*Point;
   if(Low[1]< = Fb12 & & Low[1]> (Fb12 + Fb11)/2) newSL_B = (Fb12 + Fb11)/2;
   if(Low[1]< = (Fb12 + Fb11)/2 & & Low[1]> Fb11) newSL_B = Fb11;
   if(Low[1]< = Fb11 & & Low[1]> (Fb11 + Fb10)/2) newSL_B = (Fb11 + Fb10)/2;
   if(Low[1]< = (Fb10 + Fb11)/2 & & Low[1]> Fb10) newSL_B = Fb10;
   if(Low[1]< = Fb10 & & Low[1]> (Fb10 + Fb9)/2) newSL_B = Fb9;
   if(Low[1]< = (Fb10 + Fb9)/2 & & Low[1]> Fb9) newSL_B = Fb8;
   if(Low[1]< = Fb9 & & Low[1]> Fb8) newSL_B = Fb7;
   if(Low[1]< = Fb8 & & Low[1]> Fb7) newSL_B = (Fb7 + MedVegas)/2;
   if(Low[1]< = Fb7 & & Low[1]> MedVegas) newSL_B = Fb6;
   if(Low[1]< = MedVegas & & Low[1]> (MedVegas + Fb6)/2) newSL_B = Fb6;
   if(Low[1]< = (MedVegas + Fb6)/2 & & Low[1]> Fb6) newSL_B = Fb5;
   if(Low[1]< = Fb6 & & Low[1]> Fb5) newSL_B = Fb4;
   if(Low[1]< = Fb5 & & Low[1]> Fb4) newSL_B = (Fb3 Fb4 +)/2;
   if(Low[1]< = Fb4 & & Low[1]> Fb3) newSL_B = Fb3;
   if(Low[1]< = Fb3 & & Low[1]> (Fb3 + Fb2)/2) newSL_B = (+ Fb2 Fb3)/2;
   if(Low[1]< = (+ Fb2 Fb3)/2  & & Low[1]> Fb2) newSL_B = Fb2;
   if(Low[1]< = Fb2 & & Low[1]> (Fb1 + Fb2)/2) newSL_B = (Fb1 + Fb2)/2;
   if(Low[1]< = (Fb1 + Fb2)/2 & & Low[1]> Fb1) newSL_B = Fb1;
   if(Low[1]< = Fb1) newSL_B = Fb1-100*Point;
   }

Main team tracking code positions presented in the form of a fragment of the expert advisor with the succession of actions perform the above functions depending on the current values of the price bars. After selecting the corresponding public order happens step-by-step tracking.

the following is a small piece of tracking code:


for(int i =OrdersTotal ()-1; i > =0; i-) {
   if(!OrderSelect (i, SELECT_BY_POS, MODE_TRADES)) {Print("order selection error ="GetLastError());}
   if(OrderSymbol() ==Symbol()) {
      if(OrderType() == OP_BUY) {
         if(OrderMag icNumber() == Magic) {
            
            if((High[1]-OrderOpenPrice ()) > = SL_B *Point  & & OrderLots() ==0.2) Close_B_lot ();
            
            if((High[1]-OrderOpenPrice ())/Point> =100  & & OrderLots() ==0.1  & &

OrderStopLoss< OrderOpenPrice()) {
               Print("1-move StopLoss");
               if (!OrderModify(OrderTicketOrderOpenPrice ()OrderOpenPrice () +2*PointOrderTakeProfit()0Aqua)) {
                  Print(' in Modif. Ord. # "OrderTicket" # Error "GetLastError ());
                 }
               return;
              }
            
            if((High[1]-OrderOpenPrice ()) > =120*Point  & & OrderOpenPrice() > Ma144_1-144*Point) {StoplevelFiboBuy ();
               newSL_B = newSL_B +21*Point;
               if((Bid-newSL_B)/Point< StopLevel) newSL_B = Bid-StopLevel *Point;
               if(newSL_B >OrderStopLoss() & & (Bid-newSL_B)/Point> StopLevel) {
                  Print("2-nd StopLoss transfer");
                  Modyf_B_lot ();
                 }}
            
            if((High[1]-OrderOpenPrice ()) > =200*Point & & (High[1]-OrderOpenPrice ()) =< 250*Point) {StoplevelFiboBuy ();
               if((Bid-newSL_B)/Point< StopLevel) newSL_B = Bid-StopLevel *Point;
               if(newSL_B >OrderStopLoss() & & (Bid-newSL_B)/Point> StopLevel) {
                  Print(3-rd level wrapping order # "OrderTicket());
                  Modyf_B_lot ();
                 }}
            
            if((High[1]-OrderOpenPrice ()) > =250*Point  & & OrderOpenPrice() > Ma144_1-144*Point) {StoplevelFiboBuy ();
               newSL_B = newSL_B +10*Point;
               if((Bid-newSL_B)/Point< StopLevel) newSL_B = Bid-StopLevel *Point;
               if(newSL_B >OrderStopLoss() & & (Bid-newSL_B)/Point> StopLevel) {
                  Print(4 porting to a new level of order # "OrderTicket());
                  Modyf_B_lot ();
                 }}
            
            if((High[1]-OrderOpenPrice ()) > =300*Point & & (High[1]-OrderOpenPrice ()) =< 350*Point) {StoplevelFiboBuy ();
               newSL_B = newSL_B +20*Point;
               if((Bid-newSL_B)/Point< StopLevel) newSL_B = Bid-StopLevel *Point;
               if(newSL_B >OrderStopLoss() & & (Bid-newSL_B)/Point> StopLevel) {
                  Print("5-th transfer at the level of order #"OrderTicket());
                  Modyf_B_lot ();
                 }
              }
            
            ...
           }
        }}}

in the attached version of the demonstration sequence Adviser phased tracking consists of 8 stages.

screenshot below reflects the stages of work tracing the position of Advisor Demo Buy. The position is open in connection with arisen signal that formed a bearish absorption model of “three candles” are also among the sequestered candles have a candle “inverted hammer, which increases the value of a signal for opening a long position at.

Figure. 6. example escorts Buy position

to see Fibo lines, like a light screenshot, you should use the “Vegas”. It can be found on the website of MQL4: https://www.mql5.com/ru/code/7148

the same screenshot with the “dark” of the monitor screen and a little stretched:

Figure. 7. A screenshot of the monitor screen (demo version to Buy)

Figure. 8. example escorts Sell position

to view the monitor work demonstration is to install temporary advisers test settings as shown in the following figure. 9-10:

Figure. 9. parameters of the expert advisor Demo_traill_Buy.mql

Figure. 10. parameters of the expert advisor Demo_traill_Sell.mql

Note: article files attached files demonstration advisers like mini-robots to track positions when buying and selling. Here positions are opened by double lot. However, when Stop Loss moved to the break-even point, there is confidence in the future price movement in the right direction, and you can add another position.

Conclusion

a short conclusion is that the results presented here for tracking orders show that the method of movement orders, Stop Loss, target the dynamic levels Fibo gives satisfactory results. The described method can be recommended for practical use in trading.

function defining dynamic levels Fibo:

  • LevelFiboKgd.mq4
  • StopLevelFiboBuy.mq4
  • StopLevelFiboSell.mq4
  • demo files:
  • Demo_trail_Buy_v1.mq4-Demo file to Buy
  • Demo_ trail_Sell_v1.mq4-Demo file to Sell

Leave a comment