How To Make Max BUY Order and Max SELL Order. if want Open Position in One Pair, 1st Signal is Open BUY and next Signal Open SELL in One Pair. thanks

 
//+------------------------------------------------------------------+
//| This MQL is generated by Expert Advisor Builder                  |
//|                http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/ |
//|                                                                  |
//|  In no event will author be liable for any damages whatsoever.   |
//|                      Use at your own risk.                       |
//|                                                                  |
//+------------------- DO NOT REMOVE THIS HEADER --------------------+

#define SIGNAL_NONE 0
#define SIGNAL_BUY   1
#define SIGNAL_SELL  2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4

#property copyright "SusiloFX"
#property link      "http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/"

extern int MagicNumber = 1410;
extern bool SignalMail = False;
extern bool EachTickMode = False;
extern int Slippage = 7;
extern bool UseStopLoss = False;
extern int StopLoss = 30;
extern bool UseTakeProfit = True;
extern int TakeProfit = 11;
extern bool UseTrailingStop = False;
extern int TrailingStop = 30;

int BarCount;
int Current;
bool TickCheck = False;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init() {
   BarCount = Bars;

   if (EachTickMode) Current = 0; else Current = 1;

   return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit() {
   return(0);
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start() {
   int Order = SIGNAL_NONE;
   int BTotal, STotal, Ticket;
   double StopLossLevel, TakeProfitLevel;


   if (EachTickMode && Bars != BarCount) TickCheck = False;
   BTotal = OrdersTotal();
   STotal = OrdersTotal();
   Order = SIGNAL_NONE;

   //+------------------------------------------------------------------+
   //| Variable Begin                                                   |
   //+------------------------------------------------------------------+







double Lots = MathFloor(AccountFreeMargin()*1/1000/MarketInfo(Symbol(),MODE_MARGINREQUIRED)/MarketInfo(Symbol(),MODE_LOTSTEP))*MarketInfo(Symbol(),MODE_LOTSTEP);
double sLots = 1.0;

if (OrdersHistoryTotal()>0){
OrderSelect(OrdersHistoryTotal()-1, OP_BUY, MODE_HISTORY);
if (OrderCloseTime() + 1410 > TimeCurrent()){
return(0);
}
}

if (OrdersHistoryTotal()>0){
OrderSelect(OrdersHistoryTotal()-1, OP_SELL, MODE_HISTORY);
if (OrderCloseTime() + 1410 > TimeCurrent()){
return(0);
}
}
   
   //+------------------------------------------------------------------+
   //| Variable End                                                     |
   //+------------------------------------------------------------------+

   //Check position
   bool IsTrade = False;
    
   for (int b = 0; b < BTotal; b ++) {
      OrderSelect(b, SELECT_BY_POS, MODE_TRADES);
      if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
         IsTrade = True;
         if(OrderType() == OP_BUY) {


         }
      }
   }

   //+------------------------------------------------------------------+
   //| Signal Begin(Entry)                                              |
   //+------------------------------------------------------------------+

   if ((BBK || BBE || BBH)) Order = SIGNAL_BUY;

   //+------------------------------------------------------------------+
   //| Signal End                                                       |
   //+------------------------------------------------------------------+

   //Buy
   if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
     if(IsTrade) {
         if(OrderType() == OP_SELL && OrderSymbol() == Symbol()) {
         }}

     if(!IsTrade) {
         //Check free margin
         if (AccountFreeMargin() < (1000 * Lots)) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
         }

         if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;

         Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "SusiloFX", MagicNumber, 0, DodgerBlue);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
                                Print("BUY order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
                        } else {
                                Print("Error opening BUY order : ", GetLastError());
                        }
         }
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         return(0);
      }
   }



   for (int s = 0; s < STotal; s ++) {
      OrderSelect(s, SELECT_BY_POS, MODE_TRADES);
      if(OrderType() <= OP_BUY && OrderSymbol() == Symbol()) {
         IsTrade = True;
         if(OrderType() == OP_SELL) {


         }
      }
 }

   //+------------------------------------------------------------------+
   //| Signal Begin(Entry)                                              |
   //+------------------------------------------------------------------+

   if ((SBK || SBE || SBH)) Order = SIGNAL_SELL;

   //+------------------------------------------------------------------+
   //| Signal End                                                       |
   //+------------------------------------------------------------------+

   //Sell
   if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
     if(IsTrade) {
         if(OrderType() == OP_BUY && OrderSymbol() == Symbol()) {
         }}
         
      if(!IsTrade) {
         //Check free margin
         if (AccountFreeMargin() < (1000 * Lots)) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
         }

         if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;

         Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "SusiloFX", MagicNumber, 0, DeepPink);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
                                Print("SELL order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
                        } else {
                                Print("Error opening SELL order : ", GetLastError());
                        }
         }
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         return(0);
      }
   }

   if (!EachTickMode) BarCount = Bars;

   return(0);
}

//+------------------------------------------------------------------+
 
RaptorUK:

Please edit your post . . .  or have your code deleted.


Please use this to post code . . . it makes it easier to read.

Don't delete it yet ;)


That EachTickMode variable (?!?), did you build this using EA builder or something like that ?   

 
phi.nuts:

Don't delete it yet ;)


I'm not going to,  I always give at least 24 hours for the OP to respond to my polite request . . .  many do,  so thank you to them    :-)
 
RaptorUK:
I'm not going to,  I always give at least 24 hours for the OP to respond to my polite request . . .  many do,  so thank you to them    :-)

Al right, I leave it to you ;)


 It is EA Builder that was discussed before  https://www.mql5.com/en/forum/139865.

And you also a MT4 signal provider : SusifoFX (aka Novy Susilo) https://www.mql5.com/en/users/SusiloFX

 
i try include Max Buy Order and Max Sell Order, can you help me.. thanks
 
SusiloFX:
i try include Max Buy Order and Max Sell Order, can you help me.. thanks
Help you ?  or code it for you ?  what have you tried so far ?
 
RaptorUK:
Help you ?  or code it for you ?  what have you tried so far ?


i try to change All Max Order is two OP SELL and BUY with my analisis, but All OP is Four with three OP SELL and one OP BUY or three OP BUY and one OP SELL. maybe any error code with EA Builder, but i so tried to find it.

 
SusiloFX:

i try to change All Max Order is two OP SELL and BUY with my analisis, but All OP is Four with three OP SELL and one OP BUY or three OP BUY and one OP SELL. maybe any error code with EA Builder, but i so tried to find it.


OK,  what code did you change to what ?
 
   for (int s = 0; s < STotal; s ++) {
      OrderSelect(s, SELECT_BY_POS, MODE_TRADES);
      if(OrderType() <= OP_BUY && OrderSymbol() == Symbol()) {
         IsTrade = True;
         if(OrderType() == OP_SELL) {

STotal For Sell Max Order


   for (int b = 0; b < BTotal; b ++) {
      OrderSelect(b, SELECT_BY_POS, MODE_TRADES);
      if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
         IsTrade = True;
         if(OrderType() == OP_BUY) {


         }
      }
   }
BTotal For Buy Max Order
 
SusiloFX:

STotal For Sell Max Order


BTotal For Buy Max Order

This

if(OrderType() <= OP_SELL 

 

says . . .  if the order is a OP_BUY or OP_SELL,  i.e. Buy or Sell . . .  look at this:  https://docs.mql4.com/constants/trading

 

Did you also change something here? This is a very weird OrderSelect and probably does not what it is planned to do, but might have in influence on continuing the code or not:

if (OrdersHistoryTotal()>0){
OrderSelect(OrdersHistoryTotal()-1, OP_BUY, MODE_HISTORY);
if (OrderCloseTime() + 1410 > TimeCurrent()){
return(0);
}
}

if (OrdersHistoryTotal()>0){
OrderSelect(OrdersHistoryTotal()-1, OP_SELL, MODE_HISTORY);
if (OrderCloseTime() + 1410 > TimeCurrent()){
return(0);
}
}

Check OrderSelect().

 

Just wondering.. what is this good for:

     if(IsTrade) {
         if(OrderType() == OP_BUY && OrderSymbol() == Symbol()) {
         }}

Maybe you should click the link phi.nuts has posted.