help me with my code

 
hello all ,, can u help me to modify my code ?... i wanna build strategy like this  https://telegra.ph/file/fbdc32ed144011a1c8c0a.jpg  with Fxgen and the model is like this  https://telegra.ph/file/10ac5ab589d8a46a05554.jpg



as u can see the model is not simple ... if the order reach Buyorder5 and condition buyorder5 is -20pips the ea not open trade again because the model just for 5 order .. if u wanna make ea reach 100 order averaging u must build 100 model too... this is not simple because too much code .. so i wanna make averaging reach unlimited order with single model like this https://telegra.ph/file/0eb47e0610cdfff05c95a.jpg .. i did it but the lot not multiply like this https://telegra.ph/file/ea39fa08345a5f6cc8dce.jpg



im trying too add some code multiple and magicnumber like this  https://telegra.ph/file/43896c11fde95bcdd47b9.jpg and this https://telegra.ph/file/d4d4dae33532228952c96.jpg but is not working .. pelase help me to modify my mql4..

//-------------------------------------------------------------
//  Etasoft Inc. Forex EA and Script Generator version 7.x   EA
//-------------------------------------------------------------
// Keywords: MT4, Forex EA builder, create EA, expert advisor developer

#property copyright "Copyright © 2014-2019, Etasoft Inc. Forex EA Generator v7.x"
#property link      "http://www.forexgenerator.com/"

#include <stdlib.mqh>
#include <WinUser32.mqh>

// exported variables
extern double BuyLots4 = 0.01;
extern int BuyStoploss4 = 0;
extern int BuyTakeprofit4 = 0;
extern int Gap6 = -5;

extern double Multiply = 2;
double lastOrderLotSize = 0.0*Multiply;
//extern double BuyLots10 = lastOrderLotSize*Multiply;
extern int BuyStoploss10 = 0;
extern int BuyTakeprofit10 = 0;
int lastOrderMagicNumber = 0;

// local variables
double PipValue=1;    // this variable is here to support 5-digit brokers
bool Terminated = false;
string LF = "\n";  // use this in custom or utility blocks where you need line feeds
int NDigits = 4;   // used mostly for NormalizeDouble in Flex type blocks
int ObjCount = 0;  // count of all objects created on the chart, allows creation of objects with unique names
int current = 0;   // current bar index, used by Cross Up, Cross Down and many other blocks
int varylots[101]; // used by Buy Order Varying, Sell Order Varying and similar



int init()
{
    NDigits = Digits;
    
    if (false) ObjectsDeleteAll();      // clear the chart
    
    
    Comment("");    // clear the chart
    return (0);
}

// Expert start
int start()
{
    if (Bars < 10)
    {
        Comment("Not enough bars");
        return (0);
    }
    if (Terminated == true)
    {
        Comment("EA Terminated.");
        return (0);
    }
    
    OnEveryTick1();
    return (0);
}

void OnEveryTick1()
{
    PipValue = 1;
    if (NDigits == 3 || NDigits == 5) PipValue = 10;
   
    IfNoOrderExist12();
    IfGap6();
    int totalOrders = OrdersTotal();
    for (int i = totalOrders - 1; i >= 0; i--)
    {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
            lastOrderMagicNumber = OrderMagicNumber();
            break;
        }
    }
    int TotalOrder = OrdersTotal();
    for (int u = TotalOrder - 1; u >= 0; u--)
    {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
            lastOrderLotSize = OrderLots();
            break;
        }
    }
    
}

void IfNoOrderExist12()
{
    bool exists = false;
    for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
        if (OrderSymbol() == Symbol())
        {
            exists = true;
        }
    }
    else
    {
        Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
    }
    
    if (exists == false)
    {
        BuyOrder4();
        
    }
}

void BuyOrder4()
{
    Print("BuyOrder4()");
    double SL = Bid + BuyStoploss4*PipValue*Point;
    if (BuyStoploss4 == 0) SL = 0;
    double TP = Bid - BuyTakeprofit4*PipValue*Point;
    if (BuyTakeprofit4 == 0) TP = 0;
    int ticket = -1;
    if (true)
    ticket = OrderSend(Symbol(), OP_BUY, BuyLots4, Bid, 4, 0, 0, "My Expert", 1, 0, Red);
    else
    ticket = OrderSend(Symbol(), OP_BUY, BuyLots4, Bid, 4, SL, TP, "My Expert", 1, 0, Red);
    if (ticket > -1)
    {
        if (true)
        {
            bool sel = OrderSelect(ticket, SELECT_BY_TICKET);
            bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Red);
            if (ret == false)
            Print("OrderModify() error - ", ErrorDescription(GetLastError()));
        }
            
    }
    else
    {
        Print("OrderSend() error - ", ErrorDescription(GetLastError()));
    }
}

void IfGap6()
{
    Print("Magic number terakhir : "+lastOrderMagicNumber);
    Print("ifgap6");
    for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
        if (OrderSymbol() == Symbol() && OrderMagicNumber() == lastOrderMagicNumber)
        {
            if ((Gap6 < 0 && ((OrderType() == OP_BUY && Ask - OrderOpenPrice() < Gap6*PipValue*Point) ||
            (OrderType() == OP_SELL && OrderOpenPrice() - Bid < Gap6*PipValue*Point))) ||
            ((Gap6 > 0 && ((OrderType() == OP_BUY && Ask - OrderOpenPrice() > Gap6*PipValue*Point) ||
            (OrderType() == OP_SELL && OrderOpenPrice() - Bid > Gap6*PipValue*Point)))))
            {
                IfOrderDoesNotExist9();
                
            }
        }
    }
    else
    Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
    
}

void IfOrderDoesNotExist9()
{
    Print("IfOrderDoesNotExist9()");
    bool exists = false;
    for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
        if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == lastOrderMagicNumber+1)
        {
            exists = true;
        }
    }
    else
    {
        Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
    }
    
    if (exists == false)
    {
        BuyOrder10();
        
    }
}

void BuyOrder10()
{
    Print("sellorder10()");
    double SL = Bid + BuyStoploss10*PipValue*Point;
    if (BuyStoploss10 == 0) SL = 0;
    double TP = Bid - BuyTakeprofit10*PipValue*Point;
    if (BuyTakeprofit10 == 0) TP = 0;
    int ticket = -1;
    if (true)
    ticket = OrderSend(Symbol(), OP_BUY, lastOrderLotSize, Bid, 4, 0, 0, "My Expert", lastOrderMagicNumber+1, 0, Red);
    else
    ticket = OrderSend(Symbol(), OP_BUY, lastOrderLotSize, Bid, 4, SL, TP, "My Expert", lastOrderMagicNumber+1, 0, Red);
    if (ticket > -1)
    {
        if (true)
        {
            bool sel = OrderSelect(ticket, SELECT_BY_TICKET);
            bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Red);
            if (ret == false)
            Print("OrderModify() error - ", ErrorDescription(GetLastError()));
        }
            
    }
    else
    {
        Print("OrderSend() error - ", ErrorDescription(GetLastError()));
    }
}



int deinit()
{
    if (false) ObjectsDeleteAll();
    
    
    return (0);
}

 
  1. Ridwan Salahudin: can u help me to modify my code ?... i wanna … as u can see … if u wanna … u must … so i wanna … 

    "u" and "wanna" are not words. This is an international English forum; post in English on this part of the forums.
              Please don't write ur - it's "you are" or "your" - MQL4 programming forum (2014)

  2. Ridwan Salahudin: pelase help me to modify my mql4..

    Why did you post your MT4 question in the 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? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  3. Ridwan Salahudin: i wanna build strategy like this  https://telegra.ph/file/fbdc32ed144011a1c8c0a.jpg&nbsp
    Until you have enough posts to directly insert your images, please use the link button Use the link button(Control+K) See the difference?  https://telegra.ph/file/fbdc32ed144011a1c8c0a.jpg
              Messages Editor


  4. // Expert start
    int start()
    {

    You should stop using the old event handlers (init, start, deinit) and IndicatorCounted() and start using new event handlers (OnInit, OnTick/OnCalculate, OnDeinit).
              Event Handling Functions - MQL4 Reference
              How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 (2016)

  5. Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your difficulty.
              No free help (2017)

    Or pay someone. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum (2018)

    We're not going to code it for you (although it could happen if you are lucky or the issue is interesting).
              No free help (2017)

  6. // Keywords: MT4, Forex EA builder, create EA, expert advisor developer

    ChatGPT (the worst), “Bots Builder”, “EA builder”, “EA Builder Pro”, EATree, “Etasoft forex generator”, “Forex Strategy Builder”, ForexEAdvisor (aka. ForexEAdvisor STRATEGY BUILDER, and Online Forex Expert Advisor Generator), ForexRobotAcademy.com, forexsb, “FX EA Builder”, fxDreema, Forex Generator, FxPro, Molanis, Octa-FX Meta Editor, Strategy Builder FX, Strategy Quant, “Visual Trader Studio”, “MQL5 Wizard”, etc., are all the same. You will get something quick, but then you will spend a much longer time trying to get it right, than if you learned the language up front, and then just wrote it.

    Since you haven't learned MQL4/5, therefor there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into yours.

    We are willing to HELP you when you post your attempt (using Code button) and state the nature of your problem, but we are not going to debug your hundreds of lines of code. You are essentially going to be on your own.

    ChatGPT
    1. Even it says do not use it for coding.*
    2. Mixing MT4 and MT5 code together.
    3. Creating multiple OnCalculate/OnTick functions.
    4. OnCalculate returning a double.
    5. Filling buffers with zero in OnInit (they have no size yet). Setting buffer elements to zero but not setting Empty Value to correspond.
    6. Calling undefined functions.
    7. Sometimes, not using strict (MT4 code).
    8. Code that will not compile.
    9. Creating code outside of functions.*
    10. Creating incomplete code.*
    11. Initialization of Global variables with non-constants.*
    12. Assigning a MT5 handle to a double or missing the buffer and bar indexes in a MT4 call.*
    13. Useing MT4 Trade Functions without first selecting an order.*
    14. Uses NULL in OrderSend.*
    bot builder Creating two OnInit() functions.*
    EA builder
    1. Counting up while closing multiple orders.
    2. Not useing time in new bar detection.
    3. Not adjusting for 4/5 digit brokers, TP/SL and slippage.*
    4. Not checking return codes.
    EATree Uses objects on chart to save values — not persistent storage (files or GV+Flush.) No recovery (crash/power failure.)
    ForexEAdvisor
    1. Non-updateing global variables.
    2. Compilation errors.
    3. Not checking return codes.*
    4. Not reporting errors.
    FX EA Builder
    1. Not checking return codes.
    2. Loosing open tickets on terminal restart. No recovery (crash/power failure.)
    3. Not adjusting stops for the spread .*
    4. Using OrdersTotal directly.

Reason: