Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 732

 
artmedia70:
Upload the history for the character being tested. The error is in the history data, not in iCustom()
Thank you!!!
 
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!
 

Printing to a file. I am learning to print on this file.

Why does it print zeros in cl_time ?

1,37243 1,37253 -1 07:27:13 00:00:00
1,37248 1,37256 -1 07:57:21 00:00:00
1,37256 1,37256 -1 08:17:30 00:00:00
1,37266 1,37268 -1 08:48:11 00:00:00
1,37267 1,37293 -1 08:53:15 00:00:00
1,37269 1,37307 1 09:17:57 00:00:00
1,37275 1,3727 1 10:23:02 00:00:00
1,37269 1,37269 1 10:28:03 00:00:00
1,37268 1,37231 1 10:33:10 00:00:00
1,37278 1,37255 1 10:57:38 00:00:00
1,37256 1,37269 -1 11:02:42 00:00:00
1,37268 1,37284 1 11:07:45 00:00:00
1,37283 1,37307 -1 11:12:49 00:00:00
1,37314 1,37335 1 12:11:37 00:00:00
1,37317 1,37323 1 12:23:12 00:00:00
1,37324 1,37326 1 12:28:20 00:00:00
1,37396 1,37415 1 13:26:32 00:00:00
1,37413 1,37419 1 13:37:20 00:00:00
1,3744 1,37578 1 13:56:29 00:00:00

//+------------------------------------------------------------------+
//|                                                    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 strict

input double Lots                   =0.1;

input int Expiration           =5; //laikas minutemis

//---- input parameters
input int cci_p                     = 89;
input int ma                        = 13;
input int NumberOfBarsToCalculate   = 100;

input string   comment=".csv  or  .txt";//коментарий
input string   FileType="csv";//тип файла 

datetime op_time=0,cl_time=0;
double  op_price=0,cl_price=0;
int op_type=0;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick(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 variables
   double 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) possibility
      if(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);
           }
         else
            Print("Error opening BUY order : ",GetLastError());
         return;
        }
      //--- check for short position (SELL) possibility
      if(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);
           }
         else
            Print("Error opening SELL order : ",GetLastError());
        }
      //--- exit from the "no opened orders" block
      return;
     }
//--- 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 opened
         if(OrderType()==OP_BUY)
           {
            //--- should it be closed?
            if(TimeCurrent()>=op_time+Expiration*60)
              {
               //--- close order and exit
               if(!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 exit
               if(!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);
               }
               else
               PrintFormat("Не удалось открыть файл %s, Код ошибки = %d",fileName,GetLastError());
}
 
Can you tell me how to identify a withdrawal on the board?
 
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.

 
simpleton:


Thank you!
 
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() --------------------------------+
double OnTester()
{
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));
}
//+------------------------------------------------------------------+

 
vadynik:

I do so

Sorry, I'm 0 in MKL programming, could you please point out how this is done in practice?