borilunad: Good morning, Artyom! Yes, it's clear about magicians! But when something is not in a loop, but in if-else type conditions, it will be enough just to put first condition if(Symbol()==mySymbol)(without else, of course), previously presenting mySymbol=Symbol()?! So that all variables of all EAs are the same, but each on its own graph! I can't check it yet, I'm still writing, "making it out"! :)
If string mySymbol=Symbol();, then this variable will contain the value of the current symbol. Accordingly, for each EA, that trades on its own chart, the value of this variable will be equal to the value of symbol, on which the EA has been launched.
artmedia70: If string mySymbol=Symbol();, then this variable will hold the value of the current symbol. Accordingly, for each EA that trades on its own chart, the value of this variable will be equal to the value of the symbol, on which the EA has been launched.
Somehow, I did not think about the string! I am still struggling with errors in tested functions that work well in other EAs!Thank you very much!
//+------------------------------------------------------------------+//| cci on ma.mq4 |//| Copyright 2014, MetaQuotes Software Corp. |//| https://www.mql5.com |//+------------------------------------------------------------------+#property copyright"2005-2014, MetaQuotes Software Corp."#property link"https://www.mql4.com"#property strictinputdouble Lots =0.1;
inputint Expiration =5; //laikas minutemis//---- input parametersinputint cci_p = 89;
inputint ma = 13;
inputint NumberOfBarsToCalculate = 100;
inputstring comment=".csv or .txt";//коментарийinputstring FileType="csv";//тип файла datetime op_time=0,cl_time=0;
double op_price=0,cl_price=0;
int op_type=0;
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+voidOnTick(void)
{
int cnt,ticket,total;
//---if(Bars<cci_p+1)
{
Print("bars less than ",cci_p);
return;
}
//--- to simplify the coding and speed up access data are put into internal variablesdouble cci_dn=iCustom(NULL,0,"cci_ma",cci_p,ma,NumberOfBarsToCalculate,2,0);
double cci_up=iCustom(NULL,0,"cci_ma",cci_p,ma,NumberOfBarsToCalculate,3,0);
total=OrdersTotal();
if(total<1)
{
//--- check for long position (BUY) possibilityif(cci_up>0 && cci_up!=EMPTY_VALUE)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"cci sample",16384,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
op_time=TimeLocal();
op_price=Close[0];
op_type=1;
Print("BUY order opened : ",OrderOpenPrice());
Print("op_price : ",op_price, "op_time : ",op_time);
}
elsePrint("Error opening BUY order : ",GetLastError());
return;
}
//--- check for short position (SELL) possibilityif(cci_dn<0 && cci_dn!=EMPTY_VALUE)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"cci sample",16384,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
op_time=TimeLocal();
op_price=Close[0];
op_type=-1;
Print("BUY order opened : ",OrderOpenPrice());
Print("op_price : ",op_price, "op_time : ",op_time);
}
elsePrint("Error opening SELL order : ",GetLastError());
}
//--- exit from the "no opened orders" blockreturn;
}
//--- it is important to enter the market correctly, but it is more important to exit it correctly... for(cnt=0;cnt<total;cnt++)
{
if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
continue;
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
//--- long position is openedif(OrderType()==OP_BUY)
{
//--- should it be closed?if(TimeCurrent()>=op_time+Expiration*60)
{
//--- close order and exitif(!OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet))
cl_time=TimeCurrent();//op_time+Expiration*60;
cl_price=Close[0];
Print("OrderClose error ",GetLastError());
PrintToFile(op_price, cl_price, op_type, op_time, cl_time);
return;
}
}
else// go to short position
{
//--- should it be closed?if(TimeCurrent()>=op_time+Expiration*60)
{
//--- close order and exitif(!OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet))
cl_time=TimeCurrent();//op_time+Expiration*60;
cl_price=Close[0];
Print("OrderClose error ",GetLastError());
PrintToFile(op_price, cl_price, op_type, op_time, cl_time);
return;
}
}
}
}
//---
}
//+------------------------------------------------------------------+void PrintToFile(double opPrice=0,double clPrice=0,int opType=0, datetime opTime=0, datetime clTime=0)
{
string fileName=StringConcatenate(Symbol()," ",Period()," ","gi_EA_cci");
int handle;
handle=FileOpen(fileName+FileType, FILE_WRITE|FILE_READ,";");
if(handle!=INVALID_HANDLE)
{
PrintFormat("Файл %s открыт для записи",fileName);
PrintFormat("Путь к файлу: %s\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH));
//--- сначала запишем количество сигналовFileSeek(handle, 0, SEEK_END);
FileWrite(handle,
opPrice,
clPrice,
opType,
TimeToString(opTime,TIME_MINUTES|TIME_SECONDS),
TimeToString(clTime,TIME_MINUTES|TIME_SECONDS));
//--- закрываем файлFileClose(handle);
PrintFormat("Данные записаны, файл %s закрыт",fileName);
}
elsePrintFormat("Не удалось открыть файл %s, Код ошибки = %d",fileName,GetLastError());
}
beginner: Can you tell me how to define a withdrawal on the board?
For some "orders", OrderType() produces a value numerically equal to 6. These are the withdrawals and deposits.
After a successful OrderSelect() call (returned true), you can determine the size of the withdrawal/reload by the value returned from OrderProfit(), and by the sign of this value - whether it is a withdrawal or a deposit...
Also, some brokers charge a fee, imitating a withdrawal by the amount of the fee. You can try to distinguish the charging of commission from the withdrawal from the account by a comment obtained using OrderComment().
However, be careful: this is all undocumented and may stop working at any time.
Dear programmers! When optimizing an Expert Advisor, I personally, I think, like many other participants, try to find the maximum ratio of profit to maximum drawdown (ratio: profit/loss), which I think is the most important indicator. I do this procedure manually after completion of the tester's run. Is it possible to automate this process? Or, how does each of you determine this parameter? Thank you in advance.
yosuf: Dear programmers! When optimizing an Expert Advisor, I personally, I think, like many other participants, try to find the maximum ratio of profit to maximum drawdown (ratio: profit/loss), which I think is the most important indicator. I do this procedure manually after completion of the tester's run. Is it possible to automate this process? Or, how does each of you determine this parameter? Thank you in advance.
I do so
//+---------------------- OnTester() --------------------------------+doubleOnTester()
{
double Result = 0;
double Profit = TesterStatistics(STAT_PROFIT);
double Drowdown = TesterStatistics(STAT_EQUITY_DD);
if(Drowdown>0)
Result = Profit/Drowdown;
else Result = 0;
return(NormalizeDouble(Result,2));
}
//+------------------------------------------------------------------+
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Upload the history for the character being tested. The error is in the history data, not in iCustom()
Good morning, Artyom! Yes, it's clear about magicians! But when something is not in a loop, but in if-else type conditions, it will be enough just to put first condition if(Symbol()==mySymbol)(without else, of course), previously presenting mySymbol=Symbol()?! So that all variables of all EAs are the same, but each on its own graph! I can't check it yet, I'm still writing, "making it out"! :)
If string mySymbol=Symbol();, then this variable will hold the value of the current symbol. Accordingly, for each EA that trades on its own chart, the value of this variable will be equal to the value of the symbol, on which the EA has been launched.
Printing to a file. I am learning to print on this file.
Why does it print zeros in cl_time ?
Can you tell me how to define a withdrawal on the board?
For some "orders", OrderType() produces a value numerically equal to 6. These are the withdrawals and deposits.
After a successful OrderSelect() call (returned true), you can determine the size of the withdrawal/reload by the value returned from OrderProfit(), and by the sign of this value - whether it is a withdrawal or a deposit...
Also, some brokers charge a fee, imitating a withdrawal by the amount of the fee. You can try to distinguish the charging of commission from the withdrawal from the account by a comment obtained using OrderComment().
However, be careful: this is all undocumented and may stop working at any time.
Dear programmers! When optimizing an Expert Advisor, I personally, I think, like many other participants, try to find the maximum ratio of profit to maximum drawdown (ratio: profit/loss), which I think is the most important indicator. I do this procedure manually after completion of the tester's run. Is it possible to automate this process? Or, how does each of you determine this parameter? Thank you in advance.
I do so
I do so