Editing my EA. 6 new conditions

MQL4 Indicadores Asesores Expertos

Trabajo finalizado

Plazo de ejecución 16 días
Comentario del Cliente
Super!!!! Did great job , will definitely use again , very knowledgeable and patient ,..☺️👍👍👍👍👍👍

Tarea técnica

Good day,
I would like to edit my EA. Add new conditions and edit existing ones.

In the appendix you will find Word where all the new 6 conditions for trading are described. And EA alone.

It is very important that it is clear at the outset after reading the code how EA works and that you are able to fully understand the functionality of EA and then add and edit new conditions.

_

If alert window with phrase “nesprávná hodnota arg-point” shows up, you have to maximise the window and copy paste the value from this row to the EA set_up.

 

New conditions – it should be possible to turn on and turn off each point:

 

1.     Max orders on “Target profit”

Maximal number of consecutive profitable positions (positions closed on Target profit).

In set_up we enter number x, meaning “Max orders on Target profit”. When x positions are closed on Target profit, EA doesn´t open new positions that day (till 0:00) or according to time set up in trading session.

2.     Trading session 2 - Another time block (from 9-11 / 17-19)

One is already in EA and I would like to have another one, so EA could trade in more time zones.

3.     Information panel column on the left

-       ID Magic Number

-        Total profit - Information on the total profit from the chart. I can trade one underlying asset in multiple charts, each chart has its own magic number. It is therefore not the sum of all profits on the underlying asset, but on one chart, ie on one magic number. In currency of trading account. This is not reseted.

-        Total profit in % = 100*(Total profit / Balance). This is not reseted.

-        Consecutive TP – TP is Target profit. Number of positions closed on Target Profit (consecutive), ie number of consecutive Target Profit for one magic number. This number is reseted once we reach Stop Loss.

-        Max consecutive TP – the max number of consecutive target profits. This is not reseted, number can be only higher.

Example:

Max consecutive TP“ the higest number of consecutive Target profits.
Example: I get 2 consecutive TP, then I get Stop loss (in this moment „
Max consecutive TP“ is 2). Then I get 7 consecutive TP, then I get Stop loss (in this moment „Max consecutive TP“ is 7). Then I get 4 consecutive TP, then I get Stop loss (in this moment „Max consecutive TP“ is still 7).

-        Max TP on MN – how many times we reached Target profit (this number is not reseted). When we reach TP, “Max TP on MN” increases by 1.

-        Total drawdown - Information on the total dwawdown from the chart. In currency of trading account. This is not reseted.

-        Total drawdown in % - 100*(Total drawdown / Balance). This is not reseted.

-        Consecutive SL – SL is Stop loss. Number of positions closed on Stop loss (consecutive), ie number of consecutive Stop loss for one magic number. This number is reseted once we reach Target profit.

-        Max consecutive SL – the max number of consecutive Stop loss. This is not reseted, number can be only higher.

Example:

Max consecutive SL“ the higest number of consecutive Stop losses.
Example: I get 2 consecutive SL, then I get Target profit (in this moment „
Max consecutive SL“ is 2). Then I get 7 consecutive SL, then I get Target profit (in this moment „Max consecutive SL“ is 7). Then I get 4 consecutive SL, then I get Target profit (in this moment „Max consecutive SL“ is still 7).

-        Max SL on MN - how many times we reached Stop loss (this number is not reseted). When we reach SL, “Max SL on MN” increases by 1.

-        Market conditions (Spread, Swap)

-       Trading plan

o   Max Consecutive Loss Allowed (information from set_up)

o   TP and SL (information from set_up)

o   Max future drawdown

§  Here you can see calculation of Max future drawdown:

Equation: SL/TP=”coefficient”  

SL2=SL*”coefficient”

SL3=SL2*”coefficient”

SL4=SL3*”coefficient”

Sum of these SLs (according to “Max Consecutive Loss Allowed”)=Max future drawdown in pips. We need to recalculate this to currency of trading account and show in graph.

o   Max future drawdown in % =100*(Max future drawdown/Balance)

 

The displayed text must be displayed in its entirety in the graph in all resolutions - or I can choose the text size in the set up.

 

 

4.     Breakeven – shown in graph

Breakeven” is shown as line in the graph, line colour is adjustable.

Following step, when the price is already 10% from TP of recovery position, Stop Loss is set up to 0,1% minus (so in case of execution of this little minus EA would open recovery position again and not position according to basic set up due to swaps and commissions).

When market price is 5% from Target Profit, “Breakeven” moves to new value (BE=sum of previous loss + commissions + swap).

You can find equations also in excel “rovnice_Equations”

Example:
So we can for use 100/2 = 50

Total loss 1500

So if profit=1550

BE=1500

Another example

If total loss = 100(a bit higher with swap and commission)

BE step=100/2 = 50

If profit = 100+50 = 150

BE= 150

Tp=200

Another one

Total loss 300

Total profit 400

400-300 = 100

So

100/2 = 50

If profit = 350

BE = 300

 

5.     Shifting the sum of consecutive candles for the next corrected position. (Shift of sum of consecutive candles for next recovery position)

In set_up, we use following condition:

"Numbers of Candles to check" (already in code).

New condition “MAX next of candles to check” (turned on / off) increases number of consecutive candles by 1, when position is opened immediately after closure of loss positions.

Example: “Number of candles to check” is set up to 1. When I get Stop Loss, new position is opened automatically after 2 candles. Now when I get Stop Loss, new position is opened after 3 candles and so on.

Of course, we need one new condition “MAX next candles to check” (we enter number in here) – this number defines max number of consecutive candles (when number of consecutive candles+1 is reached, no new position is opened).  

(More info in code – “Number of Candles to check”)

 

Example: In set_up:

Number of Candles to check: 1

MAX next of candles to check: 3

Max Consecutive Loss Allowed: 3

-        First position is opened after one candle – this position is closed on Stop Loss. When we get first Stop Loss, we need 2 consecutive candles so new position is opened. In case this second position is also closed on Stop Loss, we need now 3 consecutive candles so new position is opened. This position is the last one (when it is closed again on Stop Loss), because we set up sum of max. consecutive Stop Losses.

 

If “Max Consecutive Loss Allowed” is 5 and “Max next of candle to check” is 3:

-        EA opens new position after 3 consecutive candles.

 

 

 

 

When I get Target Profit, EA starts open positions again from the beginning according to set_up.

 

BUT: My position is closed on Stop Loss and it seems that conditions for opening new position in the same direction will be met (it means new position needs to have the same direction as the last one closed position, not opposite direction!), new position is opened immediately (according to set_up “Number of Candles to check” and others) and doesn´t wait for another candle according to “MAX next of candles to check”. It should be possible to turn on / off this condition.

 

Start new start:

-        This is a new condition – in case we reach condition “Max Consecutive Loss Allowed”, EA starts trading from the beginning according to set_up.

-        Max Consecutive Loss Allowed” – it is maximum of positions closed on Stop Loss. When we meet this condition, we have to edit Magic number manually, so EA can start trading again according to set_up.

-        Start new start” should replace this manual edit – if “Start new start” is active and we reach “Max Consecutive Loss Allowed”, Magic number is edited automatically and EA starts trading again from the beginning according to set_up.

 

 

 

It is important so we don´t loose anything in the code, everything should work as it worked till now. New conditions are in addition to the existing ones. Example: they should cooperate with time blocks for trading, it should be possible to use indicators etc.  


Sample code:


//--- New Candle Filter
   bool IsNewBar=Time[0]>Candle_Time;


    // ============================== Entries ==============================

    if (AllowTrading && IsNewBar && Count(0)+Count(1)==0 && (UseTF==false || IsGoodTime(TradeStartTime,TradeEndTime)))
      {
       int CustomIndicatorDirection = -1;
       
       if (CustomeIndicatorName != "")
       {
         double value = iCustom(Symbol(), Period(), CustomeIndicatorName, CustomIndicatorBuffer, 1);
         
         if (value < CustomIndicatorMiddleLevel)
            CustomIndicatorDirection = OP_SELL;
         else
            CustomIndicatorDirection = OP_BUY;
       }
       
       if(Bull_Count()>=CandleCount)
         {
          if (CustomeIndicatorName == "" || CustomIndicatorDirection == OP_BUY)
            if (NewOrderAllowed())
               sendMarketOrder(TRADEDIR_LONG);
            
          Candle_Time=Time[0];
         }
       else if(Bear_Count()>=CandleCount)
        {
         if (CustomeIndicatorName == "" || CustomIndicatorDirection == OP_SELL)
            if (NewOrderAllowed())
               sendMarketOrder(TRADEDIR_SHORT);
            
         Candle_Time=Time[0];
        }
      }

}

//+------------------------------------------------------------------+
//| Open Orders Counting Function                                    |
//+------------------------------------------------------------------+
int Count(int Type)
  {
   int count=0;
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      bool Select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(Select && OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber && OrderType()==Type)
         count++;
     }
   return (count);
  }
//+------------------------------------------------------------------+
//| Previous Bullish Candles Counting Function                       |
//+------------------------------------------------------------------+
int Bull_Count()
  {
   int count=0;
   for(int i=1; i<Bars; i++)
     {
      if(Close[i]>Open[i]) count++;
      if(Close[i]<Open[i]) break;
     }
   return (count);
  }
//+------------------------------------------------------------------+
//| Previous Bearish Candles Counting Function                       |
//+------------------------------------------------------------------+
int Bear_Count()
  {
   int count=0;
   for(int i=1; i<Bars; i++)
     {
      if(Close[i]<Open[i]) count++;
      if(Close[i]>Open[i]) break;
     }
   return (count);
  }
//+------------------------------------------------------------------+
//| Time Filter Function                                             |
//+------------------------------------------------------------------+
bool IsGoodTime(string StartTime,string EndTime)
  {
   bool goodtime=false;
   datetime tradestarttime=StringToTime(StartTime);
   datetime tradeendtime=StringToTime(EndTime);
   
   if(tradeendtime>tradestarttime) goodtime=(TimeCurrent()>=tradestarttime && TimeCurrent()<tradeendtime);
   else if(tradestarttime>tradeendtime && tradeendtime<=TimeCurrent() && tradestarttime>TimeCurrent()) goodtime=false;
   else goodtime=true;

   return(goodtime);
  }
// ====================================================================
// Helper methods
// ====================================================================

bool existsOpenPosition(int &out_ticket) {
    out_ticket = -1;
    
    for (int i = OrdersTotal() - 1; i >= 0; i--) {
        if (selectOurOrder(i, SELECT_BY_POS, MODE_TRADES) &&
                    isBuyOrSell(OrderType())) {
            out_ticket = OrderTicket();
            return true;
        }
    }
    return false;
}

bool isLossSequence(int &out_cnt, double &out_pl, double &out_avgCommissionPerLot) {
    out_cnt = 0;
    out_pl = out_avgCommissionPerLot = 0.0;
    
    CArrayInt openTimes;
    CArrayDouble profits, swaps, commissions, lots;
    collectLossSequence(OrdersTotal(), MODE_TRADES, openTimes, profits, swaps, commissions, lots);
    collectLossSequence(OrdersHistoryTotal(), MODE_HISTORY, openTimes, profits, swaps, commissions, lots);
    if (profits.Total() > 0) {
        out_cnt = profits.Total();
        double sumLots = 0.0;
        for (int i = 0; i < openTimes.Total(); i++) {
            out_pl += profits[i] + swaps[i] + commissions[i];
            sumLots = lots[i];
        }
        out_avgCommissionPerLot = out_pl / sumLots;
        return true;
    }
    return false;
}

bool insertNewestFirst(CArrayInt &openTimes, const datetime openTime,
                       CArrayDouble &pls, const double pl,
                       int &out_insertPos) {
    out_insertPos = -1;

    // keeping just a single positive P/L in the array and that one at the end (if there is any positive P/L)
    // ... keeping the openTime and P/L entries order by the openTime    
    for (out_insertPos = 0; out_insertPos < openTimes.Total(); out_insertPos++) {
        // checking inserting to the front of the current stored openTime
        if (openTime > openTimes[out_insertPos]) {
            openTimes.Insert((int)openTime, out_insertPos);
            pls.Insert(pl, out_insertPos);
            return true;
        }
        // potentially replacing the current element if the time is identical and the P/L is positive and higher
        if (openTime == openTimes[out_insertPos] && pl > 0.0 && pl > pls[out_insertPos]) {
            openTimes.Insert((int)openTime, out_insertPos);
            pls.Insert(pl, out_insertPos);
            return true;
        }
        // not inserting anything if we are at a stored positive P/L (... and the given openTime is at-or-after the stored openTime)
        if (pls[out_insertPos] > 0.0) {
            out_insertPos = -1;
            return false;
        }
    }
    // reaching this point means that we didn't find any stopper so inserting to the end
    openTimes.Add((int)openTime);
    pls.Add(pl);
    return true;
}

void collectLossSequence(const int orderCount, const int orderPool,
                         CArrayInt &openTimes, CArrayDouble &profits, CArrayDouble &swaps,
                         CArrayDouble &commissions, CArrayDouble &lots) {
    datetime openTime;
    double profit, swap, commission, pl;
    int insertIndex;
    bool added;
    CArrayDouble pls;
    for (int i = orderCount; i >= 0; i--) {
        if (selectOurOrder(i, SELECT_BY_POS, orderPool) &&
                    isBuyOrSell(OrderType())) {
            // we want to keep the last element as profit (or loss if no later profits where encountered)
            openTime = OrderOpenTime();
            profit = OrderProfit();
            swap = OrderSwap();
            commission = OrderCommission();
            pl = profit + swap + commission;
            added = insertNewestFirst(openTimes, openTime, pls, pl, insertIndex);
            if (added) {
                if (insertIndex >= profits.Total()) {  // adding the elements to the end
                    profits.Add(profit);
                    swaps.Add(swap);
                    commissions.Add(commission);
                    lots.Add(OrderLots());
                } else {
                    profits.Insert(profit, insertIndex);
                    swaps.Insert(swap, insertIndex);
                    commissions.Insert(commission, insertIndex);
                    lots.Insert(OrderLots(), insertIndex);
                }
                if (pl > 0.0) {
                    for (int di = openTimes.Total(); di > insertIndex; di--) {
                        openTimes.Delete(di);
                        pls.Delete(di);
                        profits.Delete(di);
                        swaps.Delete(di);
                        commissions.Delete(di);
                        lots.Delete(di);
                    }
                }
            }
        }
    }
}

Archivos adjuntos:

Han respondido

1
Desarrollador 1
Evaluación
(10)
Proyectos
9
11%
Arbitraje
5
0% / 60%
Caducado
1
11%
Libre
Solicitudes similares
Zzz 30+ USD
// กำหนดค่าตัวแปรพื้นฐาน input double lotSize = 0.1; // ขนาดล็อตที่ต้องการ input int takeProfit = 50; // ระยะ Take Profit (จุด) input int stopLoss = 50; // ระยะ Stop Loss (จุด) input int magicNumber = 123456; // หมายเลข Magic Number input int smaPeriod = 14; // ช่วงเวลา Simple Moving Average (SMA) // เวลาที่ออเดอร์ล่าสุดถูกเปิด datetime lastOrderTime = 0; // ฟังก์ชั่นหลักของ EA void OnTick() { //
Mobile robot 50 - 100 USD
I want a profitable scalping EA robot for mt5 and mobile phones (licence key should be provided).the video link attached below indicates how the EA robot should operate it.it analyses the market before taking trades and it trades candle to candle .also coding samples are provided on the video .it should be applicable to all timeframes.it should trade indices(Nas100,US30,S&p500,GER30,)
I use the translator I hope to make myself understood. I'm looking for a cyclical indicator. mt5. I attach videos to understand how it works. to be inserted at any point of the graph. It is possible to change the color and thickness of the line
This EA must have the following functions together: BE: place BE when the price reach a certain gain in PIPS and you can choose the offset too, so, for example it activates after 10 pips with 1 pip of offset so you can have profit with BE too Auto SL and TP Can manage the trades made by phone when MT5 is open in the PC or VPS Trailing stop (step by step): I can decide at what number of pips the trailing stop get
This is a strategy based on crossing two trend indicators on the second timeframe (1s, for example). We work not only with the market but with the limit orders as well (robot must "read" an order book). Read the whole instruction please for more details. Speak Russian, English
Martingale EA for MT5 30 - 100 USD
Criteria: Only one trade at a time. Cannot open another trade if one is running Trade on EURUSD only, once job is completed I will be happy to schedule more for other pairs You choose entry strategy and criteria win rate must be above 50% in long term backtest of EURUSD Every trade has got TP and SL Trades to last about a day, few trades a week, at least 10 pips gain per trade, so that it can be launched on normal
I have a indicator, mql file. The signals are seen below on a EURNZD H1 chart. Very important to get accurate entries. The signal to trade is the first tic after the the indicator signal paints. I've tried to demonstrate that below. Other than that the EA will have a lot size escalation, an on-screen pip counter, a button to stop taking new trades, SL/TP, and magic number. I would like the indicator to be within the
I would like to create an EA based on the Shved Supply and Demand indicator. you can find the Shved Supply and Demand v1.7 indicator in the following link https://www.mql5.com/en/code/29395 NB: Checks the trading robot must pass before publication in the Market ( https://www.mql5.com/en/articles/2555 ) MQ5 file to be provided
Im looking for an coder to code an EA: Trade management 1. opening trades according to the indicator 2. trades settings to choose from like: open all trades according to the signal open only trade 1,2,3 or 4 % per trade ( example 50/30/20 of the lot settings, with 4 trades it would be for example 50/30/10/10) 3. SL/Trailing settings: Move SL to entry after hitting TP1/TP2 or TP3 moving SL by % keep the original SL
Hi I'm looking to have 2 of my pinescript strategies converted to MQL5 and was wondering if you could first give me a quote for the more simple strategy and then for both the simple and complex strategy together. The simple strategy is a MACD crossover type thing that uses a special EMA script that filters out some ranging price action and also fractal candles for the stop loss. The second strategy is market

Información sobre el proyecto

Presupuesto
30 - 90 USD
IVA (21%): 6.3 - 18.9 USD
Total: 36.3 - 108.9 USD
Para el ejecutor
27 - 81 USD
Plazo límite de ejecución
de 1 a 4 día(s)