Experts: New Martin

 

New Martin:

The New Martin Expert Advisor opens two opposite positions upon start. OnTradeTransaction handling. When Take Profit triggers, it opens a position (one position) in the same direction. The intersection of two MA indicators is a signal to open a position of a larger lot.

New Martin crossing

Author: Vladimir Karputov

 

Version 1.105: Introduced separate functions OpenBuy and OpenSell

//+------------------------------------------------------------------+
//| Opening BUY position by symbol|
//+------------------------------------------------------------------+
bool OpenBuy(const double lot)
  {
   bool res=false;

   double price=m_symbol.Ask();
   double tp=m_symbol.NormalizePrice(m_symbol.Bid()+InpTP*m_adjusted_point);
   if(m_trade.Buy(lot,m_symbol.Name(),price,0.0,tp))
      if(m_trade.ResultDeal()>0)
         res=true;

   return(res);
  }
//+------------------------------------------------------------------+
//| Opening a SELL position by symbol|
//+------------------------------------------------------------------+
bool OpenSell(const double lot)
  {
   bool res=false;

   double price=m_symbol.Bid();
   double tp=m_symbol.NormalizePrice(m_symbol.Ask()-InpTP*m_adjusted_point);
   if(m_trade.Sell(lot,m_symbol.Name(),price,0.0,tp))
      if(m_trade.ResultDeal()>0)
         res=true;

   return(res);
  }

Now the code is more readable.

 

As always the problem is what to do with unprofitable positions that are hanging? Here is an example of version 1.105:

1.105

and version 1.105 with one small change: in OnTradeTransaction (when a TakeProfit position close is detected) we search for the most unprofitable position and close this most unprofitable position:

1.105 with one small change: In OnTradeTransaction

Let me remind you that the single tests are conducted exclusively in the"Every Tick Based on Real Tick" mode.

Both variants started at 10000. Which variant to choose - I think it depends on your specific goals.

 
there is an option to close all positions when at least one of them receives a trip
 
trader781:
there is an option to close all positions when at least one of them receives a tp

In this case it can be like this:

the first start - two multidirectional positions, one of them gets TakeProfit and we close all of them (i.e. we close the remaining position - the unprofitable one). As a result, we take profit on TakeProfit and at the same time a loss on the second position.

That doesn't sound very good.

 
Vladimir Karputov:

In this case it can be like this:

first start - two multidirectional positions, one gets TakeProfit and we close all of them (that is, we close the remaining one - the unprofitable one). As a result, we take profit on TakeProfit and at the same time a loss on the second position.

That's not very good.

I have one of these, but there martin should be 2 minimum + successful entry.

the main problem is finding an entry where the sum of successful entries should more than half the sum of unsuccessful ones.

8 knees from 0.01 is enough if it is not a cross.

theory

1) 2 orders of 0.01 each are opened in different directions on the signal

2) if the price passes the required distance to the profit, then a refill with a take, the number of refills, the step of the knee and take - you can play with this for a long time.

 

I decided to leave the second option (... with one small change: in OnTradeTransaction (when closing a position by TakeProfit is detected) we search for the most unprofitable position and close this most unprofitable position ...):

Forum on trading, automated trading systems and testing trading strategies

Expert Advisors: New Martin

Vladimir Karputov, 2017.01.22 19:00

As always the problem - what to do with unprofitable positions that are hanging? Here is an example of version 1.105:

1.105

and version 1.105 with one small change: in OnTradeTransaction (when TakeProfit position closing is detected) we search for the most unprofitable position and close this most unprofitable position:

1.105 with one small change: In OnTradeTransaction

Let me remind you that the single tests are conducted exclusively in the"Every Tick Based on Real Tick" mode.

Both variants started at 10000. Which variant to choose - I think it depends on your specific goals.


now version 1.106

 
The New Martin advisor code is launched as a free New Martin demo signal.
 

Version 1.007 - protection against terminal restart:

//---
   if(!RefreshRates())
      return;

   if(m_first)
     {
      //--- protection against terminal restart:
      int total=0;
      for(int i=PositionsTotal()-1;i>=0;i--) // returns the number of open positions
         if(m_position.SelectByIndex(i))     // selects the position by index for further access to its properties
            if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==m_magic)
               total++;
      //--- if there are already positions opened by this Expert Advisor on the trading account -
      //--- so we initialise the variables in such a way that it seems to have already been the first time.
      if(total>0)
        {
         bln_buy=true;
         bln_sell=true;
         m_first=false;
         return;
        }


      if(OpenBuy(InpLot))
         bln_buy=true;
      if(OpenSell(InpLot))
         bln_sell=true;
      m_first=false;
     }
//---


Now if the terminal has been restarted or the EA has been recompiled and the EA has already opened positions on the given trading account, there will be no "first run" situation.

 

Version 1.108 Now at crossover and at TakeProfit if there is a profitable position, it is also closed.

Compare 1.108 (top charts) with the previous version 1.107:

New Martin GBPUSD 107 vs 108

и

New Martin EURUSD 107 vs 108.png

Version 1.108 has a smaller total profit, but also the drawdowns in difficult periods are twice as small compared to version 1.107.

 
Master, can you make it work for MQ4?