MQL4 question How open multiple orders in EA - mql4

I still don't know how code to open multiple orders in EA.
I saw some EA open orders multiple times example buy order open first time and next buy order will open after direction is correct.
How can code it.
Thanks you.

Q : How open multiple orders in EA?
for example this way:
#define NotSetHERE 0.
int retCode = OrderSend( _Symbol, // string symbol, // symbol
OP_BUY, // int cmd, // operation
1.0, // double volume, // volume
Ask, // double price, // price
10, // int slippage, // slippage
NotSetHERE, // double stoploss, // stop loss
NotSetHERE, // double takeprofit, // take profit
"DEMO1", // string comment = NULL, // comment
-1, // int magic = 0, // magic number
0, // datetime expiration = 0, // P/O expiration
clrRed // color arrow_color = clrNONE // color
);
...
...
int retCod2 = OrderSend( "XAGUSD", // string symbol, // symbol
OP_BUY, // int cmd, // operation
2.0, // double volume, // volume
Ask, // double price, // price
10, // int slippage, // slippage
NotSetHERE, // double stoploss, // stop loss
NotSetHERE, // double takeprofit, // take profit
"DEMO2", // string comment = NULL, // comment
-2, // int magic = 0, // magic number
0, // datetime expiration = 0, // P/O expiration
clrWhite // color arrow_color = clrNONE // color
);
...
...
int retCod3 = OrderSend( "EURCHF", // string symbol, // symbol
OP_BUY, // int cmd, // operation
3.0, // double volume, // volume
Ask, // double price, // price
10, // int slippage, // slippage
NotSetHERE, // double stoploss, // stop loss
NotSetHERE, // double takeprofit, // take profit
"DEMO3", // string comment = NULL, // comment
-3, // int magic = 0, // magic number
0, // datetime expiration = 0, // P/O expiration
clrGreen // color arrow_color = clrNONE // color
);

Related

How to fix Error 130 on MT4 Expert Advisor Short trades?

I am trying to get this code to trade short. It trades long but give MT4 Error 130 invalid stop loss and is not going short. What do I change so this code goes short?
Code:
string symbol = "EURUSD"; // symbol
double volume = .01; // volume
int slippage = 0; // slippage
double pricelong = Ask; // price
string cmdlong = "OP_BUYLIMIT"; // operation
double stoplosslong = Ask - .0005; // stop loss
double takeprofitlong = Bid + .0005; // take profit
string commentlong="Long"; // comment
color arrow_color_long=Green; // color
double priceshort = Bid; // price
string cmdshort = "OP_SELLLIMIT"; // operation
double stoplossshort = 25; // stop loss
double takeprofitshort = 50; // take profit
string commentshort="Short"; // comment
color arrow_color_short=Red; // color
int magic=0; // magic number
datetime expiration=0; // pending order expiration
orderresults = OrderSend(symbol, cmdshort , volume, priceshort, slippage, stoplossshort, takeprofitshort, commentshort, magic, expiration, arrow_color_short);

MQL4 EA ignoring some arrows

I have created a simple EA in mql4 that execute trades based on the appearing of some BUY and SELL arrows. However the EA ignores some of the arrows. I need help.
I want the EA to trade based on all arrows that appears. Any help is much appreciated. Thank you.
The codes below.
void OnTick()
{
int total_orders = OrdersTotal();
int buy_ticket = 0;
int sell_ticket = 0;
// Reading Indicator buffer
double super_buy_arrow = iCustom(NULL,0,"super-arrow-indicator",0,0);
double super_sell_arrow = iCustom(NULL,0,"super-arrow-indicator",1,0);
// Buy or Sell if Arrow appears
if(total_orders == 0)
{
if( super_buy_arrow != EMPTY_VALUE )
{
buy_ticket = OrderSend(Symbol(), OP_BUY, FixedLot, Ask, Slippage, Ask-150*_Point, Ask+250*_Point,NULL, Magic, 0, Green);
}
if( super_sell_arrow != EMPTY_VALUE )
{
sell_ticket = OrderSend(Symbol(), OP_SELL, FixedLot, Bid, Slippage, Bid+150*_Point, Bid-250*_Point,NULL, Magic, 0, Red);
}
}
}
}

How to convert send order from mql4 to mql5

Below is the method I'm using to place an order after three minutes if it doesn't go through. I've converted the larger part of it from mql4 to mql5. It's just the commented part that I'm not sure how I'll change to mql5 since in mql5 send orders return bool's and not int's. I would be glad if I could get help with fixing this remaining part.
void MakeOrders()
{
static datetime lastTime = 0;
datetime currTime = iTime(Symbol(),PERIOD_M3,0);
if (currTime>lastTime)
{
for (int i=ObjectsTotal(0, 0, -1)-1; i>=0; i--)
{
string name = ObjectName(0, i, 0, -1);
if (ObjectGetString(0, name, OBJPROP_NAME, 0)==OBJ_RECTANGLE && ObjectGetString(0,name,OBJPROP_TEXT)=="")
{
double entryPrice=ObjectGetDouble(0,name,OBJPROP_PRICE,1)-3*_Point;
double stopLoss=ObjectGetDouble(0,name,OBJPROP_PRICE,2);
double slDist=fabs(entryPrice-stopLoss);
double dTakeProfit=entryPrice-2*slDist;
MqlTradeRequest request={0};
MqlTradeResult result={0};
//--- parameters of request
request.action =TRADE_ACTION_DEAL; // type of trade operation
request.symbol =Symbol(); // symbol
request.volume =lotSize; // volume of 0.1 lot
request.type =ORDER_TYPE_BUY_LIMIT; // order type
request.price = entryPrice; // price for opening
//request.deviation=5; // allowed deviation from the price
request.magic =magicnumber; // MagicNumber of the order
request.tp = dTakeProfit;
request.sl = stopLoss;
//--- send the request
if(!OrderSend(request,result))
PrintFormat("OrderSend error %d",GetLastError());
/*
int ticketSell = OrderSend(Symbol(),OP_SELLLIMIT,lotSize, entryPrice,0,stopLoss,dTakeProfit,"SellOrder",magicnumber,0,Red);
if (ticketSell>0)
{
ObjectSetText(name,string(ticketSell));
i = ObjectsTotal()-1; // rather than continuing the 'for' loop, we must restart because arrows (ie new objects) were created.
}
*/
}
}
lastTime = currTime;
}
}
if(result.retcode==10009 || result.order>0)
ObjectSetText(name,string(result.order));

Receive parameters from an URL

I'm getting URL input from the server as follows:
http://10.0.0.70/distance=150/angle=60
Now how can I get the distance and angle parameters from this URL and store it into a another variable?
I have to use this in the Arduino programming language.
This should work
char str[] = "http://10.0.0.70/distance=150/angle=60";
char * pch;
char *ptr;
long ret;
pch = strchr(str,'='); // find '='
ret = strtoul(pch, &ptr, 10); // take the number after it (here ret = 150)
pch = strchr(pch+1,'='); // find the next '='
ret = strtoul(pch, &ptr, 10); // take the number after it (here ret = 60)

C++ - Removing invalid characters when a user paste in a grid

Here's my situation. I have an issue where I need to filter invalid characters that a user may paste from word or excel documents.
Here is what I'm doing.
First I'm trying to convert any unicode characters to ascii
extern "C" COMMON_STRING_FUNCTIONS long ConvertUnicodeToAscii(wchar_t * pwcUnicodeString, char* &pszAsciiString)
{
int nBufLen = WideCharToMultiByte(CP_ACP, 0, pwcUnicodeString, -1, NULL, 0, NULL, NULL)+1;
pszAsciiString = new char[nBufLen];
WideCharToMultiByte(CP_ACP, 0, pwcUnicodeString, -1, pszAsciiString, nBufLen, NULL, NULL);
return nBufLen;
}
Next I'm filtering out any character that does not have a value between 31 and 127
String __fastcall TMainForm::filterInput(String l_sConversion)
{
// Used to store every character that was stripped out.
String filterChars = "";
// Not Used. We never received the whitelist
String l_SWhiteList = "";
// Our String without the invalid characters.
AnsiString l_stempString;
// convert the string into an array of chars
wchar_t* outputChars = l_sConversion.w_str();
char * pszOutputString = NULL;
//convert any unicode characters to ASCII
ConvertUnicodeToAscii(outputChars, pszOutputString);
l_stempString = (AnsiString)pszOutputString;
//We're going backwards since we are removing characters which changes the length and position.
for (int i = l_stempString.Length(); i > 0; i--)
{
char l_sCurrentChar = l_stempString[i];
//If we don't have a valid character, filter it out of the string.
if (((unsigned int)l_sCurrentChar < 31) ||((unsigned int)l_sCurrentChar > 127))
{
String l_sSecondHalf = "";
String l_sFirstHalf = "";
l_sSecondHalf = l_stempString.SubString(i + 1, l_stempString.Length() - i);
l_sFirstHalf = l_stempString.SubString(0, i - 1);
l_stempString = l_sFirstHalf + l_sSecondHalf;
filterChars += "\'" + ((String)(unsigned int)(l_sCurrentChar)) + "\' ";
}
}
if (filterChars.Length() > 0)
{
LogInformation(__LINE__, __FUNC__, Utilities::LOG_CATEGORY_GENERAL, "The Following ASCII Values were filtered from the string: " + filterChars);
}
// Delete the char* to avoid memory leaks.
delete [] pszOutputString;
return l_stempString;
}
Now this seems to work except, when you try to copy and past bullets from a word document.
o Bullet1:
 subbullet1.
You will get something like this
oBullet1?subbullet1.
My filter function is called on an onchange event.
The bullets are replaced with the value o and a question mark.
What am I doing wrong, and is there a better way of trying to do this.
I'm using c++ builder XE5 so please no Visual C++ solutions.
When you perform the conversion to ASCII (which is not actually converting to ASCII, btw), Unicode characters that are not supported by the target codepage are lost - either dropped, replaced with ?, or replaced with a close approximation - so they are not available to your scanning loop. You should not do the conversion at all, scan the source Unicode data as-is instead.
Try something more like this:
#include <System.Character.hpp>
String __fastcall TMainForm::filterInput(String l_sConversion)
{
// Used to store every character sequence that was stripped out.
String filterChars;
// Not Used. We never received the whitelist
String l_SWhiteList;
// Our String without the invalid sequences.
String l_stempString;
int numChars;
for (int i = 1; i <= l_sConversion.Length(); i += numChars)
{
UCS4Char ch = TCharacter::ConvertToUtf32(l_sConversion, i, numChars);
String seq = l_sConversion.SubString(i, numChars);
//If we don't have a valid codepoint, filter it out of the string.
if ((ch <= 31) || (ch >= 127))
filterChars += (_D("\'") + seq + _D("\' "));
else
l_stempString += seq;
}
if (!filterChars.IsEmpty())
{
LogInformation(__LINE__, __FUNC__, Utilities::LOG_CATEGORY_GENERAL, _D("The Following Values were filtered from the string: ") + filterChars);
}
return l_stempString;
}

Resources