[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 101

 

Hello again :)

As I thought, problems have arisen. Here is the code. The point is that orders on the tester are closed by TP, and by function TP is removed when the order is modified during Trailing Stop.

double my_ord[31][2];                                           //ордера советника
                                                                //[][0] Ticket
                                                                //[][1] Вид операции 
//---------------------------------------------------------------------------------

void FindMyOrders()                                             //ищем свои ордера(от советника)
   {
    for (int a = 0;a<32;a++)                                    //во избежание ошибок заполняем все нулями
      {
       my_ord[a][0]=0;
       my_ord[a][1]=0;
      }
    int pos = 0;
    for(int i=0; i<32; i++)
      {
       if (Mas_Ord_New[i][8]==1)                                //есть ли комментарий
         {
          int num = Mas_Ord_New[i][4];
          OrderSelect(SELECT_BY_TICKET, num);
          string str = OrderComment();
          if (str == "AO Day Profiter Trade")                   //наш ли это комментарий
            {
             my_ord[pos][0] = num;
             my_ord[pos][1] = Mas_Ord_New[i][6];                //если наш, записываем Ticket и вид операции
             pos++;
            }
          else { }
         }
       else { }
      }
   }
//---------------------------------------------------------------
void TrailStop(int ticket, int TStop)                           //ф-ция трейлинг стопа, TStop-расстояние в пп
   {
    int minDist = MarketInfo(symb, MODE_STOPLEVEL);
    if (TStop<minDist)
      {
       TStop = minDist;
      }
    else { }
    if (TStop>0)
      {
       OrderSelect(ticket, SELECT_BY_TICKET);
       if(OrderType()==OP_BUY)
         {
          if(Bid - OrderOpenPrice()>Point*TStop)
            {
             if(OrderStopLoss()<Bid-Point*TStop)
               {
                OrderModify(OrderTicket(), OrderOpenPrice(), 
                Bid-Point*TStop, 0, 0, Blue);
                return;
               }
             else { }
            }
            else{ }
         }
       else if (OrderType()==OP_SELL)
         {
          if(OrderOpenPrice() - Ask>Point*TStop)
            {
             if(OrderStopLoss()>Ask + TStop*Point)
               {
                OrderModify(OrderTicket(), OrderOpenPrice(), 
                Ask+Point*TStop, 0, 0, Blue);                           //ordertakeprofit!!
                return;
               }
             else { }
            }
          else { }
         }
       else { }
      }
    else { }
    }
//-----------------------------------а это кусочек Start(), отвечающий за трейлинг стоп
   for (int i = 0; i<32; i++)                                   //трейлинг стоп для наших ордеров
      {
       if (my_ord[i][0]>0)
         {
          TrailStop(my_ord[i][0], TralingStop);
         }
       else {break;}
      }
Which means the trailing stop is not executed, and there were no errors with wrong TP and SL in the tester's log. So what is wrong?
 

Dear Professionals, could you please tell me this question?

I have a previously written one dimensional string array in a text file

EURUSD 1654.31

GBPUSD -1654.61

USDCAD 110.98

USDJPY 1180.17

Suppose the total profit of USDCAD has changed and I need to replace the 3rd line with "USDCAD 115.64".

I read this data as a one-dimensional string array, but I can't replace only this element in the text file (can someone write a function?)

Or is it better not to bother and overwrite the entire array?

I just have data coming in from EAs standing on different pairs - each pair has a different string - it would of course be better to change only 1 element probably.

 

Hi all!!! Help to understand the example from HELPA

//--------------------------------------------------------------------
//obviousexpert.mq4
// Intended to be used as an example in the MQL4 Tutorial.
//--------------------------------------------------------------- 1 --
#property copyright "Copyright © Book, 2007"
#property link "http://AutoGraf.dp.ua"
//--------------------------------------------------------------- 2 --
#include <stdlib.mqh>
#include <stderror.mqh>
#include <WinUser32.mqh>
//--------------------------------------------------------------- 3 --
#include <Variables.mqh> //Variables description
#include <Check.mqh> // Checking the legality of the program.
#include <Terminal.mqh> // Order accounting
#include <Events.mqh> // Event tracking, updated.
#include <Inform.mqh> // Information function
#include <Trade.mqh> // Trade function
#include <Open_Ord.mqh> // Opening of a single order of a specified type
#include <Close_All.mqh> // Closing of all orders of a specified type
#include <Tral_Stop.mqh> // Modification of StopLoss of all orders of a specified type
#include <Lot.mqh> // Calculation of the number of lots
#include <Criterion.mqh> // Trade criteria
#include <Errors.mqh> // Error handling function.
//--------------------------------------------------------------- 4 --
int init() // Special function init
{
Level_old=MarketInfo(Symbol(),MODE_STOPLEVEL );//min. dist.
Terminal(); // Order function
return; // Exit from init()
}
//--------------------------------------------------------------- 5 --
int start() // Special function start
{
if(Check()==false) // If the conditions of use.
return; // ...are not met, exit.
PlaySound("tick.wav"); // On every tick
Terminal(); // Order accounting function
Events(); // Events information
Trade(Criterion()); // Trade function
Inform(0); // To recolor objects
return; // Exit()
}
//--------------------------------------------------------------- 6 --
int deinit() // Special function deinit()
{
Inform(-1); // To remove objects
return; // Exit deinit()
}
//--------------------------------------------------------------- 7 --

2) Only in the storage location? or in the design of the code as well?

The questions are, 1) What is the difference between include files (#include<...> and #include "..."), 3) And what is the difference between imported functions (#import) and #include directive?

The example from HELPA of usualexpert.mq4 illustrates the Expert Advisor, which was built on the include files, judging by the <> brackets in its #include directory.

Questions: Is the #include <Variables.mqh> file included // A description of variables, when created according to the example:

//--------------------------------------------------------------------
// Variables.mqh
// Intended to be used as an example in MQL4 tutorial.
//--------------------------------------------------------------- 1 --
// Description of global variables
extern double Lots =0.0; // Number of lots
extern int Percent =0; // Percentage of allotted funds
extern int StopLoss =100; // StopLoss for new orders (points)
extern int TakeProfit =40; // TakeProfit for new orders (points)
extern inttern TralingStop=100; // TralingStop for market orders (points)
//--------------------------------------------------------------- 2 --
int
Level_new, // New value of the minimum distance
Level_old, // Previous value of minimum distance
Mas_Tip[6]; // Array of order types
// [] type of orders: 0=B,1=S,2=BL,3=SL,4=BS,5=SS
//--------------------------------------------------------------- 3 --
double
Lots_New, // Number of lots for new orders
Mas_Ord_New[31][9], // Array of orders current .
Mas_Ord_Old[31][9]; // .
// index 1 = order number
// [][0] is not defined
// [][1] open order price (absolute value)
// [][2] StopLoss order (absolute value)
// [][3] TakeProfit order (abs. rate value)
// [][4] order number
// [][5] number of lots of the order. (abs. rate)
// [][6] Order type 0=B,1=S,2=BL,3=SL,4=BS,5=SS
// [][7] magic number of the order
// [][8] 0/1
//--------------------------------------------------------------- 4 --

Compiling gives an error -- '\end_of_program' - no function defined what does it mean and should I add something to the end of this example

And should the included files look like this or should they be added to the header:

#property copyright "Copyright © 2004, MetaQuotes Software Corp.
#property link "http://www.metaquotes.net/"
#property library
//+------------------------------------------------------------------+
//| return error description |
//+------------------------------------------------------------------+

For example, as a part of ( usualexpert.mq4 // intended for use as an example in MQL4 tutorial. ) There is #include <Check.mqh> // Checking legitimacy of programs used. Without this hat, it generates an error (Start function not found and cannot be run). All is OK with it?

Or, the include files contain only descriptions of custom functions located in the library of functions at the address (libraries). If it already exists in the Expert Advisor file?

 
Las-tochka:

Hi all!!! Help me to understand an example from HELPA

//--------------------------------------------------------------------
// usualexpert.mq4
// Designed to be used as an example in MQL4 tutorial.
//--------------------------------------------------------------- 1 --
#property copyright "Copyright © Book, 2007"
#property link "http://AutoGraf.dp.ua"
//--------------------------------------------------------------- 2 --
#include <stdlib.mqh>
#include <stderror.mqh>
#include <WinUser32.mqh>
//--------------------------------------------------------------- 3 --
#include <Variables.mqh> //Variables description
#include <Check.mqh> // Verify legality of program usage
#include <Terminal.mqh> // Order accounting
#include <Events.mqh> // Event tracking function, updated
#include <Inform.mqh> // Information function
#include <Trade.mqh> // Trade function
#include <Open_Ord.mqh> // Opening a single order of a specified type
#include <Close_All.mqh> // Closing all orders of a specified type
#include <Tral_Stop.mqh> // Modification of StopLoss of all orders of a specified type
#include <Lot.mqh> // Calculation of lots number
#include <Criterion.mqh> // Trade criteria
#include <Errors.mqh> // Error handling function.
//--------------------------------------------------------------- 4 --
int init() // Special function init
{
Level_old=MarketInfo(Symbol(),MODE_STOPLEVEL );// Minimal dist.
Terminal(); // Order counting function
return; // Exit init()
}
//--------------------------------------------------------------- 5 --
int start() // Special function start
{
if(Check()==false) // If conditions of use.
return; // ..are not met, exit
PlaySound("tick.wav"); // On every tick
Terminal(); // Order accounting function
Events(); // Event information
Trade(Criterion()); // Trade function
Inform(0); // To recolor objects
return; // Exit start()
}
//--------------------------------------------------------------- 6 --
int deinit() // Specific function deinit() function deinit()
{
Inform(-1); // To delete objects
return; // Exit deinit()
}
//--------------------------------------------------------------- 7 --

2) Only in the storage location? Or in the design of the code as well?

The questions are, 1) What is the difference between include files (#include<...> and #include "..."), 3) And what is the difference between imported functions (#import) and #include directive?

The example from HELPA, in particular, illustrates the Expert Advisor, which was built based on the included files, judging by the <> brackets in its #include file.

Questions: Include\file #include <Variables.mqh> //Variables description, when created by the example:

//--------------------------------------------------------------------
// Variables.mqh
// Designed to be used as an example in the MQL4 tutorial.
//--------------------------------------------------------------- 1 --
// Description of global variables
extern double Lots =0.0; // Number of lots
extern int Percent =0; // Percentage allocated
extern int StopLoss =100; // StopLoss for new orders (pips)
extern int TakeProfit =40; // TakeProfit for new orders (pips)
extern int TralingStop=100; // TralingStop for market orders (pips)
//--------------------------------------------------------------- 2 --
int
Level_new, // New minimum distance value
Level_old, // Previous minimum distance value
Mas_Tip[6]; // Order type array
// [] order type 0=B,1=S,2=BL,3=SL,4=BS,5=SS
//--------------------------------------------------------------- 3 --
double
Lots_New, // Number of lots for new orders
Mas_Ord_New[31][9], // Order array current ..
Mas_Ord_Old[31][9]; // ... and old
// 1st index = order number
// [][0] cannot be defined
// [][1] open order price (abc rate)
// [][2] StopLoss order (abc rate)
// [][3] TakeProfit order (abc rate)
// [][4] order number
// [][5] number of lots an order (abc rate). (Abc Rate)
// [][6] Order type 0=B,1=S,2=BL,3=SL,4=BS,5=SS
// [][7] order magic number
// [][8] 0/1 comment fact
//--------------------------------------------------------------- 4 --

At compiling gives out an error -- '\end_of_program' - no function defined what it means and whether it is necessary to add something to the end of this example

And should the include files look like this or should they be added to the header

#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property library
//+------------------------------------------------------------------+
//| return error description |
//+------------------------------------------------------------------+

For example, as a part of ( usualexpert.mq4 // intended for use as an example in MQL4 tutorial. ) There is #include <Check.mqh> // Checking legality of programs used. Without this hat, it generates an error (Start function not found and cannot be run). Is everything OK with it?

Or, the include files only contain descriptions of custom functions, which are located in the library of functions at the address (libraries). If it exists in the Expert Advisor's file?

Read the textbook example properly - it's all there... Includes are included program sections (structurally named according to their content, depending on the task performed by each of them) - they do not need to be compiled. They are copied by the expert and the inclusions are placed in *.ex4 file sequentially, depending on how you wrote them in the program text. That's why the custom #include <Variables.mqh> //Variables description is the FIRST in block 3 of the program. Try to move it to the end of this block and compile the Expert Advisor - see how many errors there will be.
 
alsu:
.......

A better way to calculate the mode is to construct an empirical distribution function (not to be confused with the frequency distribution), then interpolate it from piecewise linear to smooth, and finally look for the point of maximum derivative. Such an algorithm is free of the drawbacks listed above and works quite effectively even with small sample sizes. At least, I had to solve just the task of searching for modes in samples of 50-100 elements with a comparable number of intervals using MQL - and everything was OK. The only disadvantage is that the speed of calculation usually decreases significantly when using interpolations, of course, if we want to smooth it out qualitatively.

Alexey, thank you very much.... The general principle of this function is clear to me))))
 
Hello, could you tell me what Comment("") means, what will the function output in this case?
 
Chuma:
Hello, could you tell me what Comment("") means, what will the function output in this case?
A box with the text in quotes
 
Comment() displays the text not in the box but in the top left corner of the graph
 
I have encountered a discrepancy, there is an indicator that works at opening prices and there is an EA where the TF it trades at is set using signals from this indicator. I set 15 min in the EA and in the tester - by opening prices, I get some result. But if we set for example 1 minute in the Strategy Tester - at open prices the result is not too radically, but changes. I do not understand what is going on? Does it turn out that the opening price of the minute does not coincide with the opening price of the hour? Or is it the tester's error? Can you tell me where the dog is buried?
 
moskitman:
the box with the text in quotes

I meant when there are only quotes in brackets: Comment("")

Reason: