Discussion of article "Developing a trading Expert Advisor from scratch"

 

New article Developing a trading Expert Advisor from scratch has been published:

In this article, we will discuss how to develop a trading robot with minimum programming. Of course, MetaTrader 5 provides a high level of control over trading positions. However, using only the manual ability to place orders can be quite difficult and risky for less experienced users.

The Expert Advisor presented in this article can be improved in various ways to work with sets of parameters, but this would require more code that will make it more independent from MetaTrader 5.

The great success of this EA is that it uses MetaTrader 5 itself to perform actions that are not in its code, and therefore it is extremely stable and reliable.


Author: Daniel Jose

 

Good morning,

Very good, I just don't understand one thing. When I place the order in WIN and WDO the EA opens 6 orders with the number of contracts I entered in "leverage". So even if I want to trade with 1 contract, I can't, it opens 6.

Is this a concept I've overlooked? I'm a beginner, so I'm starting from that premise.

Thank you very much for sharing.

 
As I understand it, you need knowledge of Algo Trading to work with this...
[Deleted]  
Very good!
 
joecafrois #:
As I understand it, you need knowledge of AlgoTrading to work with it...

You don't need knowledge of AlgoTrading ... but it needs to be enabled whenever you use an EA (Expert Advisor), otherwise the EA is limited in how it works.

 
Feresther number of contracts I entered in "leverage". So even if I want to trade with 1 contract, I can't, it opens 6.

Is this a concept I've overlooked? I'm a beginner, so I'm starting from that premise.

Thank you very much for sharing.

It could be that the system is sending more than one order when you click the mouse, the reasons could be different, but thanks for reporting it 😁👍, to solve this problem, you'll have to add an extra test when you click the mouse, the points to modify or add are marked in GREEN ... make sure you type it in the right way, otherwise the order may not be sent, or it may not be accepted by the server ... but adding this extra test should solve your problem. The logic is as follows: When the mouse is clicked, the STATIC variable will be set, and will only be reset to allow a new order to be sent when the mouse is no longer pressed.

inline void MoveTo(int X, int Y, uint Key)
{
        static double d_block = 0; 
        int w = 0;
        datetime dt;
        bool bEClick, bKeyBuy, bKeySell;
        double take = 0, stop = 0, price;
        bEClick  = (Key & 0x01) == 0x01;                //Left click
        bKeyBuy  = (Key & 0x04) == 0x04;                //SHIFT Pressed
        bKeySell = (Key & 0x08) == 0x08;                //CTRL Pressed
        ChartXYToTimePrice(Infos.Id, X, Y, w, dt, price);
        ObjectMove(Infos.Id, Infos.szHLinePrice, 0, 0, price = (bKeyBuy != bKeySell ? AdjustPrice(price) : 0));
        ObjectMove(Infos.Id, Infos.szHLineTake, 0, 0, take = price + (Infos.TakeProfit * (bKeyBuy ? 1 : -1)));
        ObjectMove(Infos.Id, Infos.szHLineStop, 0, 0, stop = price + (Infos.StopLoss * (bKeyBuy ? -1 : 1)));
        if ((bEClick) && (bKeyBuy != bKeySell) && (d_block == 0)) CreateOrderPendent(bKeyBuy, Infos.Volume, (d_block = price), take, stop, Infos.IsDayTrade); else d_block = 0;
        ObjectSetInteger(Infos.Id, Infos.szHLinePrice, OBJPROP_COLOR, (bKeyBuy != bKeySell ? Infos.cPrice : clrNONE));
        ObjectSetInteger(Infos.Id, Infos.szHLineTake, OBJPROP_COLOR, (take > 0 ? Infos.cTake : clrNONE));
        ObjectSetInteger(Infos.Id, Infos.szHLineStop, OBJPROP_COLOR, (stop > 0 ? Infos.cStop : clrNONE));
};
 
is there mq4 version
 
Good article, thank you.
 
Good afternoon, where do I set the number of points and number of lots for the mini-index?
 
C4rl1n #:
Good afternoon, where do I set the number of points and number of lots for the mini-index?

Actually, in this code the adjustment is automatic. You tell it the financier and the number of contracts to trade and the code makes the adjustment in terms of points... This information is given when you place the Expert Advisor on the chart. 😁👍

 
I see, it's because I want to develop my EA, but the number of lots and points don't match up