Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 10
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Of course, I understand that the problem is caused by recalculation on the zero bar, but I cannot decide how to solve it.
Now 03 is glitchy.
This is the place:
y=Neg;
Pos=positive;
Neg=negative;
Store data in simple variables - this will only work the first time the indicator is calculated. Then, on the zero bar, the variable that should contain data from the previous bar will contain data from the current bar, but on the previous tick.
Now 03 is glitchy.
This is the place:
y=Neg;
Pos=positive;
Neg=negative;
Store data in simple variables - this will only work the first time the indicator is calculated. Then, on the zero bar, the variable, which should have data from the previous bar, will have data from the current bar, but on the previous tick.
Of course, I got it, I wonder how to solve the problem without graphical buffer - to save resources - memory?
Meditate on this indicator. It has a lot of static variables:
static int cDir=0;
static int pDir=0;
They are made instead of buffers.
When IndicatorCounted()=0 LastTime should be zeroed (the others are not necessary, but desirable).
Then at the beginning of the loop, move the values:
{
LastTime=Time[i];
pDir=cDir;
}
else
{
cDir=pDir;
}
Variables starting with "c" are the current value and with "p" the previous value.
string MyFileName="History_Of_Trades.csv";
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//нннннннннннннннннннннннннннннннннннннннннннннннннннннннннннннннннннн
//создаем файл и записываем в него заглавную строку
//нннннннннннннннннннннннннннннннннннннннннннннннннннннннннннннннннннн
int file_handle=FileOpen(MyFileName, FILE_WRITE, " ");
string mytext="Магик;Номер ордера;Время открытия;Время закрытия;Объем;Символ;Цена открытия;Цена закрытия;Своп;Прибыль";
FileWrite(file_handle, mytext);
FileClose(file_handle);
//нннннннннннннннннннннннннннннннннннннннннннннннннннннннннннннннннннн
//записываем в файл данные по закрытым позициям
//нннннннннннннннннннннннннннннннннннннннннннннннннннннннннннннннннннн
for (int n=1; n<=OrdersTotal(); n++) {
if (OrderSelect(n-1,SELECT_BY_POS,MODE_HISTORY)) {
if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
mytext=OrderMagicNumber()+";"
+OrderTicket()+";"
+TimeToString(OrderOpenTime(),TIME_DATE|TIME_MINUTES)+";"
+TimeToString(OrderCloseTime(),TIME_DATE|TIME_MINUTES)+";"
+DoubleToString(OrderLots(),2)+";"
+Symbol()+";"
+DoubleToString(OrderOpenPrice(),Digits)+";"
+DoubleToString(OrderClosePrice(),Digits)+";"
+DoubleToString(OrderSwap(),2)+";"
+DoubleToString(OrderProfit(),2);
file_handle=FileOpen(MyFileName, FILE_READ|FILE_WRITE, " ");
FileSeek(file_handle, 0, SEEK_END);
FileWrite(file_handle, mytext);
FileClose(file_handle);
}}}}
Hello. Please help me with the code. I'm trying to write a script that writes the available trading history into a file. But something seems to be wrong in the code, because as a result of the script execution there are only two lines in the file: the title line (see in the code) and the data of the oldest deal from the history. I don't understand what's wrong. I have not managed to analyze it myself, so I may ask for some help.
Dmitry has written a good article.
There's just the script I need, but it still doesn't work for me, it has mql5 and I have mql4, the compiler generates a lot of errors, apparently it knows many unfamiliar words for it :(
Hello. I need tosend to api.binaryteam.ru from the indicator after the alert. What lines should be added to the indicator.mq4 file to send a line like http://api.binaryteam.ru/?request=signal&key=12345472300af900f431234561234567&formname=risefall&type_account=demo&symbol=frxUSDCHF&duration=5m&amount=3&bet=CALL&source=metatrader to api.binaryteam.ru after the alert.
There is an example of sending to http://binaryteam.ru/addons/#api http://binaryteam.ru/files/mt4example_1.zip via WebRequest .When adding the following lines to the indicator.mq4 file
extern double bet=1;
extern int expiration=1;
extern string key = "12345472300af900f431234561234567" ;
extern string type_account = "demo";
extern bool Flag = false;
extern string bettype;
.....
int start() {
....
условие покупки {
.....
Alert("алерт индюка - BUY!!!");
bettype = "CALL";
Print("направление ставки: ",bettype);
Flag = true;
Print(BinaryTeam());
}
условие продажи {
.....
Alert(""алерт индюка - SELL!!!");
bettype = "PUT";
Print("направление ставки: ",bettype);
Flag = true;
Print(BinaryTeam());
}
}
bool BinaryTeam()
{
char post[],result[];
int res;
string headers;
//--- для работы с сервером необходимо добавить URL
//--- в список разрешенных URL (Главное меню->Сервис->Настройки, вкладка "Советники"):
string formname = "risefall";
string symbol = "frx" + Symbol();
string duration = IntegerToString(expiration) + "m";
string amount = DoubleToString(bet);
if(Flag==false)
{
Print("не задано направление торговли");
return(false);
}
//--- пример: http://api.binaryteam.ru/?request=signal&key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&formname=risefall&type_account=demo&symbol=frxUSDCHF&duration=5m&amount=3&bet=CALL&source=metatrader
//--- собираем строку для отправки
string send = "?request=signal" +
"&source=metatrader" +
"&type_account=" + type_account +
"&bet=" + bettype +
"&formname=" + formname +
"&date_start=now" +
"&symbol=" + symbol +
"&duration=" + duration +
"&barrier=0" +
"&amount=" + amount +
"&key=" + key;
Print(send);
ResetLastError();
int timeout=5000;
res = WebRequest("GET",url+send,NULL,NULL,timeout,post,0,result,headers);
if(res==-1)
{
Print("Ошибка в WebRequest. Код ошибки =",GetLastError());
MessageBox("Необходимо добавить адрес '"+url+"' в список разрешенных URL во вкладке 'Советники'","Ошибка",MB_ICONINFORMATION);
}
else
{
Print(CharArrayToString(result));
return(true);
}
Print("Непредвиденная ситуация");
return(false);
}
writes 2016.11.16 13:50:01.783 Error in WebRequest.error code=4060
How to pass a request without WebRequest function? are there any other functions similar to WebRequest? to be able to add to the indicator.mq4 file
What exactly is the script. Let's have a look at it.
In the appendix to that article, it is called sHistoryExport.mq5. My compiler does not accept functions whose names begin with "HistoryDeal..." and identifiers beginning with "DEAL_...". Here is the code:
#property link "https://www.mql5.com"
#property version "1.00"
#property script_show_inputs
input bool UseDateFrom = false; // Указывать дату начала
input datetime DateFrom=0; // Дата начала
input bool UseDateTo=false; // Указывать дату окончания
input datetime DateTo=0; // Дата окончания
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart(){
datetime from,to;
if(UseDateFrom){
from=DateFrom;
}
else{
from=0;
}
if(UseDateTo){
to=DateTo;
}
else{
to=TimeCurrent();
}
if(!HistorySelect(from,to)){
Alert("Ошибка выделение истории");
return;
}
string FileName="history.csv";
int h=FileOpen(FileName,FILE_WRITE|FILE_ANSI|FILE_CSV,";");
if(h==INVALID_HANDLE){
Alert("Ошибка открытия файла");
return;
}
// первая строка, что бы знать, где что находится
FileWrite(h,"Time","Deal","Order","Symbol","Type","Direction","Volume","Price","Comission","Swap","Profit","Comment");
// по всем сделкам
for(int i=0;i<HistoryDealsTotal();i++){
ulong ticket=HistoryDealGetTicket(i);
if(ticket!=0){
long type=HistoryDealGetInteger(ticket,DEAL_TYPE);
if(type==DEAL_TYPE_BUY || type==DEAL_TYPE_SELL){
long entry=HistoryDealGetInteger(ticket,DEAL_ENTRY);
FileWrite(h,(datetime)HistoryDealGetInteger(ticket,DEAL_TIME),
ticket,
HistoryDealGetInteger(ticket,DEAL_ORDER),
HistoryDealGetString(ticket,DEAL_SYMBOL),
(type==DEAL_TYPE_BUY?"buy":"sell"),
(entry==DEAL_ENTRY_IN?"in":(entry==DEAL_ENTRY_OUT?"out":"in/out")),
DoubleToString(HistoryDealGetDouble(ticket,DEAL_VOLUME),2),
HistoryDealGetDouble(ticket,DEAL_PRICE),
DoubleToString(HistoryDealGetDouble(ticket,DEAL_COMMISSION),2),
DoubleToString(HistoryDealGetDouble(ticket,DEAL_SWAP),2),
DoubleToString(HistoryDealGetDouble(ticket,DEAL_PROFIT),2),
HistoryDealGetString(ticket,DEAL_COMMENT)
);
}
}
else{
Alert("Ошибка выделения сделки, повторите попытку");
FileClose(h);
return;
}
}
FileClose(h);
Alert("Сохранение выполнено, см. файл "+FileName);
}
//+------------------------------------------------------------------+