MQL4 Workshop - page 2

 
Petr Nosek:
OK this is your opinion and mine is different. My opinion is if you have a really profitable (automatic) system (even you don't have to have capital) you are able to get enough money from people who look for opportunity where they can invest. I agree you need some free money for earning enough but $50,000 isn't too much. But it is a little bit off-topic. I think we can agree to each other that if we have a really profitable system we have some possibilities to capitalize on it.

Seems a language issue, you are saying the same as me. By selling I don't necessarily mean as an EA, could be a signal, a PAMM account or whatever. In all cases, you sell your system.

My point was in opposition to the widespread opinion you can become rich starting with 100$.

 
Alain Verleyen:

Seems a language issue, you are saying the same as me. By selling I don't necessarily mean as an EA, could be a signal, a PAMM account or whatever. In all cases, you sell your system.

My point was in opposition to the widespread opinion you can become rich starting with 100$.

I was getting out of it that Wa7eedXMZ said he bought some EAs and ended up with empty accounts. Then I assumed we talk about selling EAs. And I still believe that selling EA is usually a scam. Providing signals, PAMM and so on that is another thing and sometime it makes sense.
 
Wa7eedXMZ:

So before it gets out of the topic and be too late, lets get started.

The system that I am going to start up with is a one of the most popular and most famous trading system in the history of the automated trading. (I guess!)


Martingale


So now it is your turn, feel free to suggest anything, use this system, modify it, backtesting it, do what ever you might think with it, it is mine as it is yours.

Any thoughts or Ideas are very welcomed. Thanks in advance for your hard work and contribution.

It isn't a good start with Martingale in my opinion. By using Martingale you probably empty your account as well. I'm sorry but I don't want to participate on building another Martingale system (I'm sure there are lots of similar systems in the code base or in the market). But I can suggest you some general  improvements in your code.

  1. Stop using obsolete functions like start(),init() and so on. You should use OnTick(), OnInit()...
  2. Start using #property strict
  3. You could get in trouble with your "PIPs" calculation.
  4. You could get in trouble with your lots adjusting. See my code below.
  5. You could get in trouble with your price adjusting. See my code below.

There are other possibilities for improving but I think it's enough for start.

Lots adjusting:

bool NormalizeVolume(const double volume,double& volumeNormalized,string symbol=NULL)
  {
   if(symbol==NULL || symbol=="") symbol=_Symbol;
   double volumeStep=SymbolInfoDouble(symbol,SYMBOL_VOLUME_STEP);
   double volumeMin=SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN);
   double volumeMax=SymbolInfoDouble(symbol,SYMBOL_VOLUME_MAX);
   volumeNormalized=int(volume/volumeStep)*volumeStep;
   volumeNormalized=volumeNormalized<volumeMin?0.0:(volumeNormalized>volumeMax?volumeMax:volumeNormalized);
   return(volumeNormalized>DBL_EPSILON);
  }


Price adjusting:

double NormalizePrice(const double price,string symbol=NULL)
  {
   if(price<0.0) return(0.0);
   if(symbol==NULL || symbol=="") symbol=_Symbol;
   double tickSize=SymbolInfoDouble(symbol,SYMBOL_TRADE_TICK_SIZE);
   return(round(price/tickSize)*tickSize);
  }
 
Petr Nosek:

It isn't a good start with Martingale in my opinion. By using Martingale you probably empty your account as well. I'm sorry but I don't want to participate on building another Martingale system (I'm sure there are lots of similar systems in the code base or in the market).

I agree, starting with Martingale system is not a good start, the system can easily trapped into a side trend and few trades later wipes out all of your money instantly.

I have another system, give me a chance to explain it.

Edit:

So this system works the same way as following:

Cool_err


Except it uses a trailing stop instead of stop limits.


Code Break Down:


1. Global Variables:

//////////////////////////////////////////////////////////////////////////////////////////
////                                                                                  ////
////                                 Global Variables                                 ////
////                                                                                  ////
//////////////////////////////////////////////////////////////////////////////////////////
extern int MagicNumber=10001;

int Slippage=3;
double MyPoint=Point;
double TheStopLoss=0;
double TheTakeProfit=0;
double lotSize=0.01;
double StopLoss=0;
double TakeProfit=0;
int Step=5;

2. Main Function:

///////////////////////////////////////////////////////////////////////////////////////////
////                                                                                   ////
////                                   Main Function                                   ////
////                                                                                   ////
///////////////////////////////////////////////////////////////////////////////////////////
int start()
{ 
  if(Digits==3 || Digits==5)
  MyPoint=Point*10;
  
  if(OrdersTotal()==0)
  {
    if(MathRand()%2==0)
    openBuy();
    else
    openSell();
  }
  if(OrdersTotal()==1)
  {
    modifySingleOrder();
    if(OrderSelect(OrdersTotal()-1, SELECT_BY_POS, MODE_TRADES))
    {
      if(OrderType()==OP_BUY)
      {
        if(Bid<=OrderOpenPrice()-Step*MyPoint)
        {
          openSell();
        }
      }
      if(OrderType()==OP_SELL)
      {
        if(Ask>=OrderOpenPrice()+Step*MyPoint)
        {
          openBuy();
        }
      }
    }
  }
  if(OrdersTotal()>1)
  {
    int BuyOrders=0;
    int SellOrders=0;
    for(int i=OrdersTotal()-1; i>=0; i--)
    {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
        if(OrderType()==OP_BUY)
        BuyOrders++;
        else
        SellOrders++;
      }
    }
    if(
        (BuyOrders==SellOrders)/*||
        (
          (HighGreenZone()<Step*MyPoint)&&
          (LowGreenZone()<Step*MyPoint)
        )*/
      )
    {
      cancellAllStopLevels();
      if(Ask>=maxOpenPrice()+Step*MyPoint)
      {
        openBuy();
      }
      if(Bid<=minOpenPrice()-Step*MyPoint)
      {
        openSell();
      }
    }
    if(BuyOrders!=SellOrders)
    {
      if(HighGreenZone()>=Step*MyPoint)
      {
        double HighLimit=maxOpenPrice()+((Step*MyPoint)*3);
        if(Bid>HighLimit && Ask>HighLimit)
        {
          stopAllAtHighGreenZone();
        }
      }
      if(LowGreenZone()>=Step*MyPoint)
      {
        double LowLimit=minOpenPrice()-((Step*MyPoint)*3);
        if(Bid<LowLimit && Ask<LowLimit)
        {
          stopAllAtLowGreenZone();
        }
      }
      if(
          (Ask>=maxOpenPrice()+Step*MyPoint)&&
          (HighGreenZone()<Step*MyPoint)
        )
      
      {
        openBuy();
      }
      if(
          (Bid<=minOpenPrice()-Step*MyPoint)&&
          (LowGreenZone()<Step*MyPoint)
        )
      {
        openSell();
      }
    }
  }
  return true;
}

3. Custom Functions:

//////////////////////////////////////////////////////////////////////////////////////////
////                                                                                  ////
////                                 Custom Functions                                 ////
////                                                                                  ////
//////////////////////////////////////////////////////////////////////////////////////////
double maxOpenPrice()
{
  double maxOPP;
  if(OrdersTotal()>0)
  {
    if(OrderSelect(OrdersTotal()-1, SELECT_BY_POS, MODE_TRADES))
    {
      maxOPP=OrderOpenPrice();
      for(int i=OrdersTotal()-1; i>=0; i--)
      {
        if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
          maxOPP=MathMax(maxOPP, OrderOpenPrice());
        }
      }
    }
  }
  return maxOPP;
}

//----------------------------------------------------------------------------------------------------------------------------------------
double minOpenPrice()
{
  double minOPP;
  if(OrdersTotal()>0)
  {
    if(OrderSelect(OrdersTotal()-1, SELECT_BY_POS, MODE_TRADES))
    {
      minOPP=OrderOpenPrice();
      for(int i=OrdersTotal()-1; i>=0; i--)
      {
        if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
          minOPP=MathMin(minOPP, OrderOpenPrice());
        }
      }
    }
  }
  return minOPP;
}

//----------------------------------------------------------------------------------------------------------------------------------------
double HighGreenZone()
{
  double Total=0;
  double Profit=0;
  for(int l=OrdersTotal()-1; l>=0; l--)
  {
    if(OrderSelect(l, SELECT_BY_POS, MODE_TRADES))
    {
      if(OrderType()==OP_BUY)
      {
        if(OrderSelect(l, SELECT_BY_POS, MODE_TRADES))
        {
          Profit=(OrderOpenPrice()-(maxOpenPrice()+Step*MyPoint))*-1;
        }
      }
    }
    if(OrderSelect(l, SELECT_BY_POS, MODE_TRADES))
    {
      if(OrderType()==OP_SELL)
      {
        if(OrderSelect(l, SELECT_BY_POS, MODE_TRADES))
        {
          Profit=OrderOpenPrice()-(maxOpenPrice()+Step*MyPoint);
        }
      }
    }
    Total=Total+Profit;
  }
  return Total;
}

//----------------------------------------------------------------------------------------------------------------------------------------
double LowGreenZone()
{
  double Total=0;
  double Profit=0;
  for(int l=OrdersTotal()-1; l>=0; l--)
  {
    if(OrderSelect(l, SELECT_BY_POS, MODE_TRADES))
    {
      if(OrderType()==OP_BUY)
      {
        if(OrderSelect(l, SELECT_BY_POS, MODE_TRADES))
        {
          Profit=(OrderOpenPrice()-(minOpenPrice()-Step*MyPoint))*-1;
        }
      }
    }
    if(OrderSelect(l, SELECT_BY_POS, MODE_TRADES))
    {
      if(OrderType()==OP_SELL)
      {
        if(OrderSelect(l, SELECT_BY_POS, MODE_TRADES))
        {
          Profit=OrderOpenPrice()-(minOpenPrice()-Step*MyPoint);
        }
      }
    }
    Total=Total+Profit;
  }
  return Total;
}

//----------------------------------------------------------------------------------------------------------------------------------------
int openSell()
{
  if(OrderSend(Symbol(),OP_SELL,lotSize,Bid,Slippage,0,0,"Cool_err",MagicNumber,0,Red))
  return true;
  return true;
}

//----------------------------------------------------------------------------------------------------------------------------------------
int openBuy()
{
  if(OrderSend(Symbol(),OP_BUY,lotSize,Ask,Slippage,0,0,"Cool_err",MagicNumber,0,Blue))
  return true;
  return true;
}

//----------------------------------------------------------------------------------------------------------------------------------------
int modifySingleOrder()
{
  if(OrdersTotal()==1)
  {
    if(OrderSelect(OrdersTotal()-1, SELECT_BY_POS, MODE_TRADES))
    {
      if(OrderTakeProfit()==0)
      {
        if(OrderSelect(OrdersTotal()-1, SELECT_BY_POS, MODE_TRADES))
        {
          if(OrderType()==OP_BUY)
          {
            if(OrderModify(OrderTicket() ,OrderOpenPrice(),NormalizeDouble(0,Digits),NormalizeDouble(maxOpenPrice()+Step*MyPoint,Digits),0,Green))
            return true;
            return true;
          }
        }
        if(OrderSelect(OrdersTotal()-1, SELECT_BY_POS, MODE_TRADES))
        {
          if(OrderType()==OP_SELL)
          {
            if(OrderModify(OrderTicket() ,OrderOpenPrice(),NormalizeDouble(0,Digits),NormalizeDouble(minOpenPrice()-Step*MyPoint,Digits),0,Green))
            return true;
          }
        }
      }
    }
  }
  return true;
}

//----------------------------------------------------------------------------------------------------------------------------------------
int cancellAllStopLevels()
{
  if(OrdersTotal()>1)
  {
    for(int i=OrdersTotal()-1; i>=0; i--)
    {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
        if(
            (OrderTakeProfit()!=0)||
            (OrderStopLoss()!=0)
          )
        {
          if(OrderModify(OrderTicket() ,OrderOpenPrice(),NormalizeDouble(0,Digits),NormalizeDouble(0,Digits),0,Green))
          return true;
        }
      }
    }
  }
  return true;
}

//----------------------------------------------------------------------------------------------------------------------------------------
int stopAllAtHighGreenZone()
{
  for(int i=0; i<OrdersTotal(); i++)
  {
    if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
      if(OrderType()==OP_BUY)
      {
        if(Bid-OrderOpenPrice()>Step*MyPoint)
        {
          if((OrderStopLoss()<Bid-Step*MyPoint) || (OrderStopLoss() == 0))
          {
            if(OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Step*MyPoint,0,0,Green))
            return true;
          }
        }
      }
    }
    if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
      if(OrderType()==OP_SELL)
      {
        if((Ask-OrderOpenPrice())>(Step*MyPoint))
        {
          if((OrderTakeProfit()<(Ask-Step*MyPoint)) || (OrderTakeProfit()==0))
          {
            if(OrderModify(OrderTicket(),OrderOpenPrice(),0,Ask-Step*MyPoint,0,Red))
            return true;
          }
        }
      }
    }
  }
  return true;
}

//----------------------------------------------------------------------------------------------------------------------------------------
int stopAllAtLowGreenZone()
{
  if(OrdersTotal()>1)
  {
    for(int i=0; i<OrdersTotal(); i++)
    {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
        if(OrderType()==OP_BUY)
        {
          if(OrderOpenPrice()-Bid>Step*MyPoint)
          {
            if((OrderTakeProfit()>Bid+Step*MyPoint)||(OrderTakeProfit()==0))
            {
              if(OrderModify(OrderTicket(),OrderOpenPrice(),0,Bid+Step*MyPoint,0,Green))
              return true;
            }
          }
        }
      }
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
        if(OrderType()==OP_SELL)
        {
          if(OrderOpenPrice()-Ask>Step*MyPoint)
          {
            if((OrderStopLoss()>(Ask+Step*MyPoint)) || (OrderStopLoss()==0))
            {
              if(OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Step*MyPoint,0,0,Red))
              return true;
            }
          }
        }
      }
    }
  }
  return true;
}

//----------------------------------------------------------------------------------------------------------------------------------------


Sorry for the bad coding, on mean while you can backtest it and tell me what do you think!

On my behalf, I think adding a martingale strategy on this EA could make it better.

Files:
Cool_err.mq4  11 kb
 

it has been a while since I started this topic and as I see nothing accomplished, on my behalf I was trying to achieve something and that what I came up with:

MartiMax

It based on Martingale strategy except it always close on profit. The side trend price movement has huge effect on blowing off all of your capital.

The code file as well with the EA file are on the attachments, backtest them and notify me please.

For any suggestions or modifications on the previously posted EAs or even if you have a strategy that you think it is going to work please let me now about it.

Thanks in advance.

Files:
MartiMax.ex4  33 kb
MartiMax.mq4  9 kb
 

The next EA is an attempt to improve the MartiMax EA, the improvement is all about including Hedging strategy into the same MartiMax strategy and that is what I came up with:

Hedging&Martingale

Adding Hedging Strategy into MartiMax strategy prevent the EA to stuck into a channel trading and opening an infinite number of orders until wipes out the account capital.

The code file as well with the EA file are on the attachments, backtest them and notify me please.

For any suggestions or modifications on the previously posted EAs or even if you have a strategy that you think it is going to work please let me now about it.

Thanks in advance.

 

The follow up EA is an improved version of Cool_err:

ExtremeHedge

The code file as well with the EA file are on the attachments, backtest them and notify me please.

For any suggestions or modifications on the previously posted EAs or even if you have a strategy that you think it is going to work please let me now about it.

Thanks in advance.

Files:
 

My recent attempts is this EA:

Grender

The code file as well with the EA file are on the attachments, backtest them and notify me please.

For any suggestions or modifications on the previously posted EAs or even if you have a strategy that you think it is going to work please let me now about it.

Thanks in advance.

Files:
Grender.ex4  30 kb
Grender.mq4  16 kb