Help with Dodgy MA cross, pullback EA - freelance disaster.

 
Hi guys, let me say first up, I am absolutely not a programmers butthole. 

Right, now that’s clear, recently I put a job on the freelance page for a EA to be created that observes 2 moving averages cross, then waits for a pull back. 

The pull back is defined with a minimum and maximum figure in pips, once the price comes back up (or down to) equal what the price was at the MA cross, it then waits a definable amount of pips and opens a position. 

Well that’s how it is meant to work anyway. 

The guy who programmed it was hard to work with, and I don’t really think he understood how to do it to be honest. 
Anyway, not here to bag him out, I just need a hand sorting it out. 

A great friend of mine sorted out a few issues in the code, but he does not write mql4 code. Hence I need your help!


The issue is, that you can see the setup as clear as day on a chart during a visual mode backtest, but the ea doesn’t open a trade. 

It will however open totally random (so it appears) trades which don’t follow the rules at all. 

Thanks in advance to all that offer their skills, may the trading deity bless you with low draw downs and many pips


//+------------------------------------------------------------------+



#property version   "1.01"
#property strict

int tiketbuy ;
int tiketsell;



//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+



//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

enum isBool
{
   t, // YES
   f  // NO
};

 
enum isBoolll
{
  ttt, // ON
  fff  // OFF
};

enum isBBool
{
  tt, // YES
  ff  // NO
};

enum isBBooool
{
  tttt, // Auto trading
  ffff  // Manual trading
};

extern int magicnum=1; //Magic number (should be unique for each chart)
int maxallowablespread=250000;  //Maximum spread
extern isBool usetemplate=t;// Use template
extern isBBooool actionmode=tttt; // Select action
extern isBool sendnotifmeta=t; // Alert on chart
extern isBool sendnotifmetaphone=f; // Push notification to MT4 App
extern string    mv = "========>> Moving average configuration <<========";
extern    ENUM_MA_METHOD modema=MODE_SMA; //Select mode
extern ENUM_TIMEFRAMES timema=PERIOD_CURRENT;//Moving average timeframe
extern int   slowperiod =100; // Slow moving (big)
extern int   fastperiod =50;  // Fast moving average (small
extern string    pb = "========>> Pull back depth <<========";
extern int minpullbackdepth=10; // Minimum pullback depth(pips)
extern int maxpullbackdepth=40; // Maximum pullback depth(pips)
extern int extramin=5; // Minimum extra pips
extern int maxnumcandlepullback=300; // Maximum candles to wait 
extern string  fxts = "========>>  Take profit and stop loss <<========";
extern int tpfix=50;  //Take profit
extern int slfix=50;  //Stop loss
extern int BreakEven=20; // break even
extern string  aul = "========>> Lot Management <<========";
input double lots=.01;  //Fixed lot
input isBBool   smartlotmode= ff;// Use Auto lot
input double risknumber=1;      //Risk percent(%)
extern string  pm = "========>> Position Management <<========";
extern isBool trailing= f; //Trailing stop loss
extern double trailingpoint= 20; //Trailing stop in pips
extern string btm = "========>>  Set expert time(based on broker time) <<========";
isBoolll backtestmode = ttt; //  ON only for backtest(for live trade should be OFF)
extern string bTradeStartTime = "00:01"; //Trade start time 
extern string bTradeStopTime = "23:59"; //Trade stop time 
string  tme = "========>> Set expert time (based on GMT, market opening time) <<========";
string TradeStartTime = "00:01"; //Trade start time
string TradeStopTime = "23:59"; //Trade stop time

int perbuy=0;
int persell=0;

string miantimeframess="";
int swichbuy=0;
int swichsell=0;

//+-----------------------------------------------------------------------------------------------------------+

//|                                                                                                           |

//+-----------------------------------------------------------------------------------------------------------+

int OnInit()
{
  if(usetemplate==t)
  {
    ChartSetInteger(0,CHART_SHOW_GRID,true);
    ChartSetInteger(0,CHART_SHOW_GRID,true);
    ChartSetInteger(0,CHART_SHOW_PERIOD_SEP,false);
    ChartSetInteger(0,CHART_SHOW_BID_LINE,true);
    ChartSetInteger(0,CHART_SHOW_ASK_LINE,false);
    ChartSetInteger(0,CHART_COLOR_BACKGROUND,clrBlack);
    ChartSetInteger(0,CHART_COLOR_FOREGROUND,clrWhite);
    ChartSetInteger(0,CHART_COLOR_CHART_UP,clrLimeGreen);
    ChartSetInteger(0,CHART_COLOR_CHART_DOWN,clrLimeGreen);
    ChartSetInteger(0,CHART_COLOR_CANDLE_BULL,clrBlack);
    ChartSetInteger(0,CHART_COLOR_CANDLE_BEAR,clrWhite);
    ChartSetInteger(0,CHART_MODE,CHART_CANDLES);
  }

  if(timema==PERIOD_M1 || (timema==PERIOD_CURRENT && Period()==1))
  {
    miantimeframess="M1";
  }

  if(timema==PERIOD_M5 || (timema==PERIOD_CURRENT && Period()==5))
  {
    miantimeframess="M5";
  }

  if(timema==PERIOD_M15 || (timema==PERIOD_CURRENT && Period()==15))
  {
    miantimeframess="M15";
  }

  if(timema==PERIOD_M30 || (timema==PERIOD_CURRENT && Period()==30))
  {
    miantimeframess="M30";
  }

  if(timema==PERIOD_H1 || (timema==PERIOD_CURRENT && Period()==60))
  {
    miantimeframess="H1";
  }

  if(timema==PERIOD_H4 || (timema==PERIOD_CURRENT && Period()==240))
  {
    miantimeframess="H4";
  }
  if(timema==PERIOD_D1 || (timema==PERIOD_CURRENT && Period()==1440))
  {
    miantimeframess="D1";
  }
  if(timema==PERIOD_W1|| (timema==PERIOD_CURRENT && Period()==10080))
  {
    miantimeframess="W1";
  }
  if(timema==PERIOD_MN1 || (timema==PERIOD_CURRENT && Period()==43200))
  {
    miantimeframess="MN1";
  }
  swichbuy=0;
  swichsell=0;

  return(INIT_SUCCEEDED);
}

void OnTick()
{  
   /*
  if((((accountmode==true &&(AccountNumber() == accountnumberone || AccountNumber()==accountnumbertwo || AccountNumber()==accountnumberthree

    || AccountNumber()==accountnumberfour|| AccountNumber()==accountnumberfive|| AccountNumber()==accountnumbersix))|| accountmode==false)

    && TimeCurrent() <= expire))
    */
  if (true)
  {
    //####################################################### ORDER SEND PART  ######################3################################
    if(hourfilter()==TRUE  && (numberofcurrencynamebuy() ==0 ||numberofcurrencynamesell() ==0 )  && 
      NormalizeDouble(Ask-Bid, 5)<=maxallowablespread*Point*50 && permissionorderonecandle()==true  && numhistoryonecandle()==0 )
    {
      if(signal() == "Buy" && numberofcurrencyname() == 0 && swichbuy == 0)
      {
        swichbuy=1;
        if(sendnotifmeta == t)
        {
          string a= ChartSymbol();
          Alert("buy signal ",a  + "\n" +  "TIME FRAME = "+  miantimeframess);
          PlaySound("alert.wav");
        } 
                        
        if(sendnotifmetaphone == t)
        {                 
          string msg=("SIGNAL = buy signal"  );
          string msgg=("SYMBOL = "+  Symbol()   );
          string msggg=("TIME FRAME = "+  miantimeframess   );
          SendNotification (msg+"\n"+msgg+"\n"+msggg);   
        }

        double  tpbuy = Ask + (tpfix)*10*Point;
        double   slbuy = Ask - (slfix)*10*Point;
        if(tpfix == 0)
        {
          tpbuy = 0;
        }
        if(slfix==0)
        {
          slbuy=0;
        }
        if(actionmode == tttt)
        {
          tiketbuy = OrderSend(Symbol(), OP_BUY,smartlot(),Ask,5,slbuy,tpbuy, "moving pull back",magicnum,0, clrGold);
        }   
      }

      if( signal()=="Sell" && numberofcurrencyname() ==0 && swichsell==0) 
      {
        swichsell=1;
        if(sendnotifmeta == t)
        {
          string a= ChartSymbol()  ;
          Alert("sell signal ",a  + "\n" +  "TIME FRAME = "+  miantimeframess);
          PlaySound("alert.wav");
        }                 
        if(sendnotifmetaphone == t)
        {                 
           string msg=("SIGNAL = sell signal"  );
           string msgg=("SYMBOL = "+  Symbol()   );
           string msggg=("TIME FRAME = "+  miantimeframess   );
           SendNotification (msg+"\n"+msgg+"\n"+msggg);   
        }
        double tpsell = Bid - (tpfix)*10*Point;
        double   slsell = Bid + (slfix)*10*Point;
        if(tpfix==0)
        {
          tpsell=0;
        }
        if(slfix==0)
        {
          slsell=0;
        }
        if(actionmode==tttt)
        {         
            tiketsell = OrderSend(Symbol(), OP_SELL,smartlot(),Bid, 5,slsell,tpsell,"moving pull back",magicnum,0, clrRed);
        }
      }
    }
    //---------------------------------  trailing function------------------------------
    if(trailing == t)
    {
      if(numberofcurrencyname()!= 0)
      {
        for(int  i = OrdersTotal()-1 ; i >=0 ; i--)
        {
          if(OrderSelect(i, SELECT_BY_POS)==true && OrderMagicNumber()==magicnum && (OrderType()==OP_BUY || OrderType()==OP_SELL) && OrderStopLoss()!=NULL )
          {
            int order=OrderTicket();
            double stop =StringToDouble(StringSubstr(OrderComment(),StringLen(OrderComment())/2,StringLen(OrderComment()) ));  
            double open=OrderOpenPrice();
            if(OrderSelect(order,SELECT_BY_TICKET)  && OrderType()==OP_BUY  && Bid -  OrderOpenPrice()>trailingpoint*10*Point &&
              Bid - OrderStopLoss()>trailingpoint*10*Point && OrderStopLoss() < Bid-(trailingpoint*10*Point)  )
            {
              int trailingbuy= OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(trailingpoint*10*Point),OrderTakeProfit(),0,clrBlue);
            }
            if(OrderSelect(order,SELECT_BY_TICKET)&&  OrderType()==OP_SELL &&   OrderOpenPrice() -Ask >trailingpoint*10*Point &&
              OrderStopLoss() - Ask >trailingpoint*10*Point && OrderStopLoss() > Ask + (trailingpoint*10*Point)  )
            {                                
              int trailingsell= OrderModify(OrderTicket(),OrderOpenPrice(),Ask + (trailingpoint*10*Point)  ,OrderTakeProfit(),0,clrRed);
            }              
          }
        }
      }
    }
  }
}



//+----------------------------------------------------------------------+

//|                             SIGNAL FUNCTION                          |

//+----------------------------------------------------------------------+

string  signal()
{
  if(movingbuysell(0) == "moving buy signal") 
  {
    return("Buy");
  }
  if(movingbuysell(0) == "moving sell signal")         
  {
    return("Sell");
  }
  return("NO SIGNAL");
}

//+------------------------------------- MOVING AVERAGE (BUY & SELL)-----------------------------+

string movingbuysell(int i)
{  

  double movingfast =  iMA(NULL,timema,fastperiod,0,modema,PRICE_CLOSE,i+1);
  double movingslow =  iMA(NULL,timema,slowperiod,0,modema,PRICE_CLOSE,i+1);
  int buysignal=0;
  int sellsignal=0;
  if(movingslow < movingfast)
  {
    swichsell=0;
    int num=i+1;
    while(iMA(NULL,timema,slowperiod,0,modema,PRICE_CLOSE,num) <= iMA(NULL,timema,fastperiod,0,modema,PRICE_CLOSE,num) && num < 1000)    
    {
      num=num+1;
    }
    num=num-2;
    if(iClose(NULL, timema , num) > iClose(NULL,timema, iLowest(NULL,timema,MODE_CLOSE,num,i+1) )  &&  
      (iClose(NULL, timema , num) - iClose(NULL,timema, iLowest(NULL,timema,MODE_CLOSE,num,i+1) )  )/(Point*10) >  minpullbackdepth  &&
      iClose(NULL, timema , num)< iClose(NULL, timema , i+1) && 
      (iClose(NULL, timema , i+1) - iClose(NULL, timema , num))/(Point*10) > extramin && num <  maxnumcandlepullback)
    {
      buysignal=1;
    }
  }
  if(movingslow > movingfast)
  {
    swichbuy=0;
    int num=i+1;
    while(iMA(NULL,timema,slowperiod,0,modema,PRICE_CLOSE,num) >= iMA(NULL,timema,fastperiod,0,modema,PRICE_CLOSE,num) && num < 1000)    
    {
      num=num+1;
    }
    num=num-2;
    if(iClose(NULL, timema , num) < iClose(NULL,timema, iHighest(NULL,timema,MODE_CLOSE,num,i+1) )  &&  
      (iClose(NULL,timema, iHighest(NULL,timema,MODE_CLOSE,num,i+1) ) -iClose(NULL, timema , num) )/(Point*10) >  minpullbackdepth  &&
      iClose(NULL, timema , num)> iClose(NULL, timema , i+1) && 
      (iClose(NULL, timema , num) - iClose(NULL, timema , i+1) )/(Point*10) > extramin && num <  maxnumcandlepullback)
    {
      sellsignal = 1;
    }
  }
  if(buysignal == 1)
  {
    return("moving buy signal");
  }

  if(sellsignal == 1)
  {
    return("moving sell signal");
  }
  return("no signal");
} 

//+------------------------------------------------------------------+
//|                         number of position with same currency    |
//+------------------------------------------------------------------+

int numberofcurrencyname()
{
  int numberr = 0;
  for(int  i = OrdersTotal()-1 ; i >=0 ; i--)
  {
    if(OrderSelect(i,SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber()==magicnum && (OrderType()==OP_BUY || OrderType()==OP_SELL))
    {
      numberr = numberr + 1;
    }
  }
  return(numberr);
}

int numberofcurrencynamebuy()
{
  int numberr = 0;
  for(int  i = OrdersTotal()-1 ; i >=0 ; i--)
  {
    if(OrderSelect(i,SELECT_BY_POS, MODE_TRADES) &&  OrderType()==OP_BUY  &&   OrderMagicNumber()==magicnum )
    {
      numberr=numberr+1;
    }
  }
  return(numberr);
}     

int numberofcurrencynamesell()
{
  int numberr = 0;
  for(int  i = OrdersTotal()-1 ; i >=0 ; i--)
  {
    if(OrderSelect(i,SELECT_BY_POS, MODE_TRADES) &&  OrderType()==OP_SELL && OrderMagicNumber()==magicnum)
    {
      numberr=numberr+1;
    }
  }
  return(numberr);
}  

//+------------------------------------------------------------------+
//|                     time day filter  function                    |
//+------------------------------------------------------------------+

bool hourfilter()
{
  int cdaystart = TimeDay(TimeGMT());
  int chourstart = TimeHour(StrToTime(TradeStartTime));
  int cminutestart = TimeMinute(StrToTime(TradeStartTime));
  int cdaystop = TimeDay(TimeGMT());
  int chourstop = TimeHour(StrToTime(TradeStopTime));
  int cminutestop = TimeMinute(StrToTime(TradeStopTime));
  int gday = TimeDay(TimeGMT());
  int ghour = TimeHour(TimeGMT());
  int gminute = TimeMinute(TimeGMT());

/*
  if(TimeDaylightSavings()==0)
  {
    dst=0;
  }

  if(TimeDaylightSavings()!=0)
  {
    dst=-1;
  }

  chourstart=chourstart+dst;
  chourstop=chourstop+dst;
  */

  if(backtestmode ==fff && gday>=cdaystart && ghour>=chourstart && (ghour>chourstart || (ghour==chourstart && gminute>=cminutestart)) && gday<=cdaystop && ghour <= chourstop && (ghour<chourstop || (ghour==chourstop && gminute<=cminutestop)))
  {
    return(true);
  }

  int bcdaystart = TimeDay(TimeCurrent());
  int bchourstart = TimeHour(StrToTime(bTradeStartTime));
  int bcminutestart = TimeMinute(StrToTime(bTradeStartTime));
  int bcdaystop = TimeDay(TimeCurrent());
  int bchourstop = TimeHour(StrToTime(bTradeStopTime));
  int bcminutestop = TimeMinute(StrToTime(bTradeStopTime));
  int bgday = TimeDay(TimeCurrent());
  int bghour = TimeHour(TimeCurrent());
  int bgminute = TimeMinute(TimeCurrent());
  if(backtestmode ==ttt && bgday>=bcdaystart && bghour>=bchourstart && (bghour>bchourstart || (bghour==bchourstart && bgminute>=bcminutestart)) && bgday<=bcdaystop && bghour <= bchourstop && (bghour<bchourstop || (bghour==bchourstop && bgminute<=bcminutestop)))
  {
    return(true);
  }
  else
  {
    return(false);
  }
}

//+-----------------------------------------------------+
//|                      smart lot                      |
//+-----------------------------------------------------+

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

double smartlot()
{
  double risknumbers=NormalizeDouble((1)*risknumber,2);
  double lot =lots;
  double g=100000;
  if(Bid>25)
  {
    g=1000;
  }

  if(smartlotmode  == tt &&  (slfix*g*Point*10*MarketInfo(Symbol(), MODE_TICKVALUE))!=0)
  {
    lot =NormalizeDouble(((AccountBalance()* risknumbers/100)/ (slfix*g*Point*10*MarketInfo(Symbol(), MODE_TICKVALUE))),2);
  }
  if(lot>=MarketInfo(Symbol(),MODE_MAXLOT))
  {
    lot=MarketInfo(Symbol(),MODE_MAXLOT);
  }
  if(lot==0)
  {
    lot=.01;
  }

  if(lot <MarketInfo(Symbol(),MODE_MINLOT))
  {
    lot = MarketInfo(Symbol(),MODE_MINLOT);
  }
  return(NormalizeDouble(lot, 2));
}

//+------------------------------------------------------------------+
//|             permission for new order one candle                  |
//+------------------------------------------------------------------+

bool permissionorderonecandle()
{
   bool buyp=true;
   for(int  i = 0 ; i<=OrdersTotal()-1  ; i++)
    {
      if(OrderSelect(i,SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber()==magicnum)
      {
        long torderbuy=OrderOpenTime();
        long tstartbuy=iTime(NULL,timema ,0);
        if((torderbuy < tstartbuy))
        {
          buyp=true;
        }
        else
        {
          buyp=false;
        }
      }
  }
  return(buyp);
}

//-----------------number of  history position in one candle--------------------------+

int numhistoryonecandle()
{
  int numhonecandle=0;
   for(int  i = 0 ; i<=OrdersHistoryTotal()-1  ; i++)
   {
      if(OrderSelect(i,SELECT_BY_POS, MODE_HISTORY) &&  OrderMagicNumber()==magicnum)
      {
         long ttorder=OrderOpenTime();
         long ttstart=iTime(NULL,timema ,0);
         if(ttorder>= ttstart)
         {
            numhonecandle=numhonecandle+1;
         }
      }
   }
   return(numhonecandle);

}

Moving Average - Trend Indicators - Technical Indicators - Price Charts, Technical and Fundamental Analysis - MetaTrader 5 Help
  • www.metatrader5.com
The Moving Average Technical Indicator shows the mean instrument price value for a certain period of time. When one calculates the moving average...
 
Aussie222615:
Hi guys, let me say first up, I am absolutely not a programmers butthole. 

Right, now that’s clear, recently I put a job on the freelance page for a EA to be created that observes 2 moving averages cross, then waits for a pull back. 

The pull back is defined with a minimum and maximum figure in pips, once the price comes back up (or down to) equal what the price was at the MA cross, it then waits a definable amount of pips and opens a position. 

Well that’s how it is meant to work anyway. 

The guy who programmed it was hard to work with, and I don’t really think he understood how to do it to be honest. 
Anyway, not here to bag him out, I just need a hand sorting it out. 

A great friend of mine sorted out a few issues in the code, but he does not write mql4 code. Hence I need your help!


The issue is, that you can see the setup as clear as day on a chart during a visual mode backtest, but the ea doesn’t open a trade. 

It will however open totally random (so it appears) trades which don’t follow the rules at all. 

Thanks in advance to all that offer their skills, may the trading deity bless you with low draw downs and many pips




You payed money for this? - I don't want to judge the worthiness of this work, as I don't know how much you spent. But just by glancing over the codes first lines, I personally would say the coder is somewhere between rookie and early junior dev state.

It would be nice, if you can post the code properly. Use Alt-S or the "Code-Button" to post code. It's horrible to read like it is now. - Don't repost, edit your current post and update the format, please.
 
Aussie222615: Hence I need your help!
  1. Why did you post your MT4 question in the MT5 General 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.

  2. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
              Forum rules and recommendations - General - MQL5 programming forum (2023)
              Messages Editor

  3. I agree with Dominik. Three enumerations describing a bool is ridiculous.

  4.         double  tpbuy = Ask + (tpfix)*10*Point;
            double   slbuy = Ask - (slfix)*10*Point;

    You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)

      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
      My GBPJPY shows average spread = 26 points, average maximum spread = 134.
      My EURCHF shows average spread = 18 points, average maximum spread = 106.
      (your broker will be similar).
                Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)

  5. Your code.
    Do not hard code constants.
    Code breaks on MT5.
      if(timema==PERIOD_M1 || (timema==PERIOD_CURRENT && Period()==1))
      {
        miantimeframess="M1";
      }
    
      if(timema==PERIOD_M5 || (timema==PERIOD_CURRENT && Period()==5))
      {
        miantimeframess="M5";
      }
    
      if(timema==PERIOD_M15 || (timema==PERIOD_CURRENT && Period()==15))
      {
        miantimeframess="M15";
      }
    
      if(timema==PERIOD_M30 || (timema==PERIOD_CURRENT && Period()==30))
      {
        miantimeframess="M30";
      }
    
      if(timema==PERIOD_H1 || (timema==PERIOD_CURRENT && Period()==60))
      {
        miantimeframess="H1";
      }
    
      if(timema==PERIOD_H4 || (timema==PERIOD_CURRENT && Period()==240))
      {
        miantimeframess="H4";
      }
      if(timema==PERIOD_D1 || (timema==PERIOD_CURRENT && Period()==1440))
      {
        miantimeframess="D1";
      }
      if(timema==PERIOD_W1|| (timema==PERIOD_CURRENT && Period()==10080))
      {
        miantimeframess="W1";
      }
      if(timema==PERIOD_MN1 || (timema==PERIOD_CURRENT && Period()==43200))
      {
        miantimeframess="MN1";
      }
    Simplified
    miantimeframess=as_string(timema);
    //////////////////////////////////////////
    string      as_string(ENUM_TIMEFRAMES aePeriod){
       if(aePeriod == PERIOD_CURRENT)   aePeriod = ENUM_TIMEFRAMES(_Period);
       string   period_xxx  = EnumToString(aePeriod);                 // PERIOD_XXX
       return StringSubstr(period_xxx, 7);                            // XXX
    }

 
Sorry, ill try again. I didnt know thats how it was done
 
Dominik Christian Egert #:
You payed money for this? - I don't want to judge the worthiness of this work, as I don't know how much you spent. But just by glancing over the codes first lines, I personally would say the coder is somewhere between rookie and early junior dev state.

It would be nice, if you can post the code properly. Use Alt-S or the "Code-Button" to post code. It's horrible to read like it is now. - Don't repost, edit your current post and update the format, please.

Yep, I unfortunately paid money for this. 

The guy was a complete rookie, no idea.


Thank you for your reply, any help I can get is appreciated. 

 
William Roeder #:
  1. Why did you post your MT4 question in the MT5 General 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.

  2. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
              Forum rules and recommendations - General - MQL5 programming forum (2023)
              Messages Editor

  3. I agree with Dominik. Three enumerations describing a bool is ridiculous.

  4. You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)

      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
      My GBPJPY shows average spread = 26 points, average maximum spread = 134.
      My EURCHF shows average spread = 18 points, average maximum spread = 106.
      (your broker will be similar).
                Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)

  5. Your code.
    Do not hard code constants.
    Code breaks on MT5.
    Simplified

Hey William, in response to your questions


1.1Why post in the MT5 are -  Im a bit special?


1.2 Sorry, as above, im special, I didnt know there was a way to post code, and didn't realise it'd drive people mental. Ive fixed it, obviously.


1.3 I don't know what a Bool is, im guessing some type of true of false logic, I dunno, not a programmer at all. Hence why I am here, to mooch off you good people. 


2.1   Don't you want the specified amount used in either direction? 

Yeah, I think that's what I want, I sort of grasp what you're saying, Im not sure what to change to fix it though. What you are saying about the SL/TP being closer and further, respectively, and why you wouldn't want that makes sense.

Would you steer me in the right direction on what to change there? Im terribly sorry, I am a complete noob as far as programming goes. I can trade, I've been in the game a little while now, everyday is a school day but.


2.2 I need to read that a few more times and get my head around it.


2.3 Im all across charts showing bid and ask prices, it'd be about the only thing Im all over.



With regards to the "simplified" code you posted, Im not sure what I should do with that? Im sure its blisteringly obvious to you, but am I to assume I shit can the bit of code (your code) and replace it with the simplified version?

I assume all that code he's come up with is superfluous and unnecessary?


Thanks a million for your comments so far, I really appreciate it.

Cheers