MQL4 Workshop

To add comments, please log in or register
Wa7eedXMZ
37
Wa7eedXMZ  

Hello there, I am new to this forum and I am wondering if any of you would help me make it possible for this topic to become free for all, not profitable, collaborative, and educational. The thing is I got hooked with the automated trading around a year ago, and yes I bought some of them and ended up with empty accounts, so I asked my self "why won't I make my own?" and "What it takes to make my own any way?", so I started searching Google for answers and found the MQL4 and knew it can be used to make an automated trading Expert Advisers. Luckily I had just a little experience with the CPP Programming Language, so I did not have any problem with learning the basics of programming with the MQL4.

What I want?

  • Any one who wants to learn and wants to help with the MQL4 Projects.
  • Any one who believe the Money Making Systems should not be sold for what so ever(if it makes money, then why you sell it?).
  • Any one who believe that every one deserve a second chance and there is more than enough for everyone.

What we will do in this topic?

I have been working on MQL4 and so far I developed 4 Expert Advisers, and yes I can share it with you so you may learn something from them or maybe you will suggest some sort of an improvement on any of them, or you may help me to improve them, they all will be open source, free for all, with no extra charge, that if you liked them anyway!. So we will work together on a potentially profitable strategies and develop them to make money for me and you and every body out there.

So..

With the permission of this forum moderators, can I proceed with this workshop?

And to the other members who are interested in this idea, will you be with me in this and what do you think of it?


Petr Nosek
3025
Petr Nosek  
Wa7eedXMZ:
 

What I want?

  • Any one who wants to learn and wants to help with the MQL4 Projects.
  • Any one who believe the Money Making Systems should not be sold for what so ever(if it makes money, then why you sell it?).
  • Any one who believe that every one deserve a second chance and there is more than enough for everyone.

  • I always want to learn but there is a problem because I don't know who (and what) will teach me. But I could consider whether I want to help with this project.
  • I agree that somebody who created a profitable system don't need to sell it.
  • This is more a philosophical topic than an MQL topic.
Wa7eedXMZ:
 

What we will do in this topic?

So we will work together on a potentially profitable strategies and develop them to make money for me and you and every body out there.

Great idea but... I'm afraid that there aren't sufficiently experienced people here who want to participate to this project. In other words there are lots of beginners on this forum but too few good coders and traders (they usually don't need to work with newbies together).


I'll watch your topic and we'll see. If it start to be interesting I'll join you.

kypa
1079
kypa  

Sounds like Wa7eed wants to build Communism. :D

The idea is not really new though, in fact it's already implemented in the site. It's called Code Base.

https://www.mql5.com/en/code

MQL5 Code Base
MQL5 Code Base
  • www.mql5.com
This version of WSO (Widner Support Oscillator) and WRO (Widner Resistance Oscillator) shows channel on chart instead of displaying oscillator values in a separate window. The Hurst exponent is referred to as the "index of dependence" or "index of long-range dependence". It quantifies the relative tendency of a time series either to regress...
Wa7eedXMZ
37
Wa7eedXMZ  
kypa:

Sounds like Wa7eed wants to build Communism. :D

The idea is not really new though, in fact it's already implemented in the site. It's called Code Base.

https://www.mql5.com/en/code

I did not claim to be a professional programmer, I am still learning and I think it would be so much fun and interesting to learn with others as will, until I feel I can do something better maybe I will go to the Code Base, but for now the Code Base seems to be a waste of my time because I do not know much and I dont think I will do much as will.

About "Communism" I dont know what it suppose to mean, but it seems interesting.

Thank you @kypa for paying attention, and for your replay.

Wa7eedXMZ
37
Wa7eedXMZ  
Petr Nosek:
  • I always want to learn but there is a problem because I don't know who (and what) will teach me. But I could consider whether I want to help with this project.
  • I agree that somebody who created a profitable system don't need to sell it.
  • This is more a philosophical topic than an MQL topic.

Great idea but... I'm afraid that there aren't sufficiently experienced people here who want to participate to this project. In other words there are lots of beginners on this forum but too few good coders and traders (they usually don't need to work with newbies together).


I'll watch your topic and we'll see. If it start to be interesting I'll join you.

Thank you @Petr Nosek for your replay and you are very welcome when ever you like.

I will start small very soon and see what is gonna happen.

see yah!

William Roeder
20214
William Roeder  
Wa7eedXMZ: with learning the basics of programming with the MQL4.
Why did you post your MT4 post in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
          General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon.
Alain Verleyen
38685
Alain Verleyen  
Petr Nosek:

  • I agree that somebody who created a profitable system don't need to sell it.

Really ?

When I will have a profitable system in some years, I will sell it. I will need to sell it. Why ? Because I don't have a capital. I can build it, I can test it on a cent account for example, investing 1000 USD but I will not be able to really profit from it without a real capital. To be able to really profit and live from it you need a capital of minimum 50,000 USD.

Wa7eedXMZ
37
Wa7eedXMZ  
whroeder1:
Why did you post your MT4 post in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
          General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon.
Thank you for your replay and I apologize for my mistake.
Petr Nosek
3025
Petr Nosek  
Alain Verleyen:

Really ?

When I will have a profitable system in some years, I will sell it. I will need to sell it. Why ? Because I don't have a capital. I can build it, I can test it on a cent account for example, investing 1000 USD but I will not be able to really profit from it without a real capital. To be able to really profit and live from it you need a capital of minimum 50,000 USD.

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.
Wa7eedXMZ
37
Wa7eedXMZ  
Alain Verleyen:

Really ?

When I will have a profitable system in some years, I will sell it. I will need to sell it. Why ? Because I don't have a capital. I can build it, I can test it on a cent account for example, investing 1000 USD but I will not be able to really profit from it without a real capital. To be able to really profit and live from it you need a capital of minimum 50,000 USD.

Hi @Alain Verleyen, sorry for posting this thread in this section.

About selling the profitable systems, it is hard to know whether or not this system or that system will be profitable in the future or not, and I bought around three systems before with a hope that it can make some profit but it did not, what I mean is there is a scammers who make money by selling their systems and they dose not even use it at all because they know it dose not work. So how can I trust them after what they did to me?

As you can see, there is two types of people in here:

  1. The one who has a real profitable system in this industry but has no capital investment to start trading, and they only have the right to sell their product.
  2. The one who has a crappy system and know it wont work and he has no place in the Forex industry but he is their to scam people and steal them, and this is the worst kind ever who should be in prison in no time and unfortunately they are not because...(I DON'T KNOW)

I think you @Alain Verleyen do hate the second type as much as I do and you should actually because they take a potential customers from you.

Wa7eedXMZ
37
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


The file is in the Attachments, you can use it on a demo account if you wish or a real account (UNDER YOUR OWN RISK!!!), modify it, suggest a modification or contribute with me to improve it.


About this EA:

It uses a simple Martingale strategy where the next order lot size is as twice as much as the previously closed order. On a fresh accounts were no orders been closed before it open a random position. It opens the next orders on the same type of the previous order if the previous order is won and it opens the next order of an opposite type if the previously closed order is loss. It multiplies the next order lot only if the previous order been closed was a loss.


installation:

I assume you all know how to install it on your platform, so if you have any troubles with that search google or just reply on this thread.


Settings:

MagicNumber: You know what it is, so leave it as it is or change it as you wish.

TakeProfit: You also know what it is, I recommend a value of 10 for Spread purposes.

StopLoss: And you also know what it is, I recommend a value of 10 also for Spread purposes.

LotsMultiplier: I recommend it to be 2, and it is used if you want the next lot size to be as twice or as three times of the previous one, so change as you wish.

minLotSize: This defines the minimum risk lot size for every position you entered, change it as you wish.



Code Breakdown:

Now in depth with the source code of this EA, I will divide it into three categories as following:

1. Global Variables:

//////////////////////////////////////////////////////////////////////////////////////////
////                                                                                  ////
////                                 Global Variables                                 ////
////                                                                                  ////
//////////////////////////////////////////////////////////////////////////////////////////
extern int MagicNumber=10001;
extern int TakeProfit=10;
extern int StopLoss=10;
extern int LotsMultiplier=2;
extern double minLotSize=0.01;

int Slippage=3;
double MyPoint=Point;

2. Main Function:

///////////////////////////////////////////////////////////////////////////////////////////
////                                                                                   ////
////                                   Main Function                                   ////
////                                                                                   ////
///////////////////////////////////////////////////////////////////////////////////////////
int start()
{
  if(Digits==3 || Digits==5)
  MyPoint=Point*10;
  
//On Fresh Account, Random Start
  if(
      (OrdersHistoryTotal()==0)&&
      (OrdersTotal()==0)
    )
    {
      if(MathRand()%2==0)
      openBuy();
      else
      openSell();
    }

// Following Orders
  if(
      (OrdersHistoryTotal()>0)&&
      (OrdersTotal()==0)
    )
    {
      if(
          (OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS, MODE_HISTORY))&&
          (OrderProfit()>0)
        )
      {
        if(
            (OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS, MODE_HISTORY))&&
            (OrderType() == OP_BUY)
          )
        {
          openBuy();
        }
        else
          openSell();
      }
      if(
          (OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS, MODE_HISTORY))&&
          (OrderProfit()<0)
        )
      {
        if(
            (OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS, MODE_HISTORY))&&
            (OrderType() == OP_BUY)
          )
        {
          openSell();
        }
        else
          openBuy();
      }
    }
  
  return true;
}

3. Costume Functions:

//////////////////////////////////////////////////////////////////////////////////////////
////                                                                                  ////
////                                 Custom Functions                                 ////
////                                                                                  ////
//////////////////////////////////////////////////////////////////////////////////////////
double GetLots()
{
  double min_lot = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN);
  double max_lot = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX);
  double lotSize=min_lot;
  
  if(
      (OrdersHistoryTotal()==0)
      ||
      (
        (OrdersHistoryTotal()>0)&&
        (OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS, MODE_HISTORY))&&
        (OrderProfit()>0)
      )
    )
    {
      lotSize= NormalizeDouble((AccountBalance()/baseRisk()), 2);
      if(lotSize < min_lot)
        lotSize = min_lot;
      if(lotSize > max_lot)
        lotSize = max_lot;
    }
  
  if(
      (OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS, MODE_HISTORY))&&
      (OrderProfit()<0)
    )
    {
      lotSize= NormalizeDouble((OrderLots()*LotsMultiplier), 2);
      if(lotSize < min_lot)
      {
        lotSize = min_lot;
      }
      if(lotSize > max_lot)
      {
        lotSize = max_lot;
      }
    }  
  return lotSize;
}
//---------------------------------------------------------------------------------------------------------------------
int baseRisk()
{ 
  return AccountBalance()/minLotSize;
}
//---------------------------------------------------------------------------------------------------------------------

int openSell()
{
  if(OrderSend(Symbol(),OP_SELL,GetLots(),Bid,Slippage,0,0,"Martingale",MagicNumber,0,Red))
  {
    double TheTakeProfit=Bid-TakeProfit*MyPoint;
    double TheStopLoss=Bid+StopLoss*MyPoint;
    if(OrderSelect(OrdersTotal()-1,SELECT_BY_POS, MODE_TRADES))
    {
      if(OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green))
      return true;
    }
  }
  return true;
}
//---------------------------------------------------------------------------------------------------------------------

int openBuy()
{
  if(OrderSend(Symbol(),OP_BUY,GetLots(),Ask,Slippage,0,0,"Martingale",MagicNumber,0,Blue))
  {
    double TheTakeProfit=Ask+TakeProfit*MyPoint;
    double TheStopLoss=Ask-StopLoss*MyPoint;
    if(OrderSelect(OrdersTotal()-1, SELECT_BY_POS, MODE_TRADES))
    {
      if(OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green))
      return true;
    }
  }
  return true;
}

Suggested Modifications:

  1. There is a chance when this system lose control and can not place stop limits for opened positions, there should be a separated function that can check if the opened order has stop limits and if not then stop limits has to be placed.
  2. The EA will fail to open larger lot sizes more than the maximum lot size allowed on the current account, we need to figure out a way to check whether the naxt order lot size is more than the maximum lot size allowed for any position and if true then the next lot size will be seberated into multible orders where the total lot size of all of them equal to the needed lot size volume.
  3. This EA can fall easily into huge gabs over the week ends, so there should be a way to permits that from happening.

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.

Files:
12
To add comments, please log in or register