Editing my EA. 6 new conditions

MQL4 Indikatoren Experten

Auftrag beendet

Ausführungszeit 16 Tage
Bewertung des Kunden
Super!!!! Did great job , will definitely use again , very knowledgeable and patient ,..☺️👍👍👍👍👍👍

Spezifikation

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);
                    }
                }
            }
        }
    }
}

Dateien:

Bewerbungen

1
Entwickler 1
Bewertung
(10)
Projekte
9
11%
Schlichtung
5
0% / 60%
Frist nicht eingehalten
1
11%
Frei
Ähnliche Aufträge
Hi, I have an indicator from my friend, I want to copy it to my own MT5 can you do that for me. Here is the link
I'm looking for someone to help me create an arbitrage trading robot that can trade on any decentralized exchange and forex market. I already have some source code to a strategy but would like to enhance it to make it profitable and automated
I installed the E.A. into the Experts folder in MT4. When I double click on it nothing happens. When I right click and "attach to chart" nothing happens. The E.A. is not grayed out, it simply will not attach. Any help would be greatly Appreciated
I have an EA and want to add few new logic to fetch profit taking factors and other values from an external master data and use it in existing EA
Hello Every one, Good day, I want from someone professional to create an EA is working on Mt5, This EA is working by depend on some indicators, and all those indicators must be working on MACD window, not on the chart, for more details please read my attached pdf file carefully. Many Thanks
I'm looking for an expert MQL5 developer that can create an EA that's based on my price action trading strategy with no indicators. The EA must analyze trades based on my price action rules, enter trades based on my price action rules, manage trades based on my price action rules and exit trades based on my price action rules
hi hi there i have an strategy on tradingview and i want to automate it like metatrader EA so i want the strategy to open and close trade automaticlly on tradingview
We are looking for an experienced Expert Advisor Developer who can build a customized MT5 Expert Advisor for us. The Expert Advisor would use two built-in indicators as entry/exit signals and our own risk management strategy with customizable inputs. The goal is to create a reliable and efficient trading tool that can automate our trading process on the MT5 platform. Skills required: - Strong understanding of
I need stochastic div (hidden &regular ea) that should perform task in all tf's ..divergence is a repaint stly so i want to use it with candlestick flips .. so bet for it
Hello, I have an indicator from a friend and I'd like to replicate it on my own TradingView or MT5 platform. Could you assist me with that?. Here is the link

Projektdetails

Budget
30 - 90 USD
MwSt (21%): 6.3 - 18.9 USD
Insgesamt: 36.3 - 108.9 USD
Für die Entwickler
27 - 81 USD
Ausführungsfristen
von 1 bis 4 Tag(e)