Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 279

 
LSM:
I edited my question and added the code. There is a loop going on. It is not clear what I will get when it happens in the loop.
Everything is clear there,
for example, in the cycle, the indicator has counted 15. 5-minute candle
and took the value from the 15+1. The 16th 15 minute candle.


 
LSM:

I'll answer my own question in case anyone needs it.)

That's right.
 

Good afternoon.

Please advise me, I have an idea, but from which side to approach, I "do not understand" yet.

I have an indicator, I opened access to it for a certain list of account numbers from a CSV file on the server.

Is it technically possible to write a message for a specific account from the list and display it on the chart for this specific user.

For example, I specify the account number in CSV and write the text like "Hello..." and the user sees it on the chart? If it is at all possible, in what direction "to dig"? Thank you...

 

Good afternoon, could you help me understand some mql4 syntax? I have an idea to write a trend-following EA which would for example enter a long position with a stop of 150 pips from the open order and take profit of 50 and then if the price reached tp a new buy would be opened with stop 150 and take profit 50 and if it failed on stop loss a sell would be performed with the same risk/profit ratio as for long positions. I tried to write a code with such logic but it failed because the Expert Advisor does not make any deals during testing.

double b, difference;
int ticket;

int OnInit()
{
   b=Bid;
   return(b);
}

void OnTick()
{
   difference = Bid-b;
   if(OrdersTotal()==0)
   {
      if(difference==150*Point)
      {
         ticket=OrderSend(Symbol(),OP_BUY,1,Ask,0,Ask-150*Point,Ask+50*Point,0);
         if(difference==0){b=Bid+150*Point;}
            if(ticket<0)
            {
               Print("lose");
            }
      }
      if(difference==200*Point){b=Bid-150*Point;}

      if(difference==-150*Point)
      {
         ticket=OrderSend(Symbol(),OP_SELL,1,Bid,0,Bid+150*Point,Ask-50*Point,0);
         if(difference==0){b=Bid-150*Point;}
            if(ticket<0)
            {
               Print("lose");
            }
      }
      if(difference==-200*Point){b=Bid+150*Point;}
   }
}
Как самому создать советника или индикатор - Алгоритмический трейдинг, торговые роботы - Справка по MetaTrader 5
Как самому создать советника или индикатор - Алгоритмический трейдинг, торговые роботы - Справка по MetaTrader 5
  • www.metatrader5.com
Для разработки торговых систем в платформу встроен собственный язык программирования MetaQuotes Language 5 ( MQL5 ), среда разработки MetaEditor и...
 
MosheDayan:

Good afternoon.

Please advise me, I have an idea, but from which side to approach, I "do not understand" yet.

I have an indicator, I opened access to it for a certain list of account numbers from a CSV file on the server.

Is it technically possible to write a message for a specific account from the list and display it on the chart for this specific user.

For example, specify the account number in CSV and write the text like "Hello..." and the user will see it on the chart? If it is at all possible, in what direction "to dig"? Thank you...

Send to the server a post-request with the account number

IntegerToString(AccountInfoInteger(ACCOUNT_LOGIN)

On the server check the incoming number with all the lines in the CSV file, and if there is a match, then from this line in the file send a response to the terminal. All that remains is to read the response from the server in the terminal and display it on the chart.

In general, such things are easier to implement on MySQL than on file.

 
Maxim235v34:
And yes, if you don't mind, suggest a way to reduce line spacing in this forum.

Write first in a text file (notepad) - then copy via the clipboard. You'll get it like this

double b, difference;
int ticket;

int OnInit()
{
   b=Bid;
   return(b);
}

void OnTick()
{
   difference = Bid-b;
   if(OrdersTotal()==0)
   {
      if(difference==150*Point)
      {
         ticket=OrderSend(Symbol(),OP_BUY,1,Ask,0,Ask-150*Point,Ask+50*Point,0);
         if(difference==0){b=Bid+150*Point;}
            if(ticket<0)
            {
               Print("lose");
            }
      }
      if(difference==200*Point){b=Bid-150*Point;}

      if(difference==-150*Point)
      {
         ticket=OrderSend(Symbol(),OP_SELL,1,Bid,0,Bid+150*Point,Ask-50*Point,0);
         if(difference==0){b=Bid-150*Point;}
            if(ticket<0)
            {
               Print("lose");
            }
      }
      if(difference==-200*Point){b=Bid+150*Point;}
   }
}
read about OnInit() function - put cursor on it and press F1. The word int is in front - so this function returns an integer value. You are trying to return a value of type double. The result of OnInit() function is analyzed by the runtime subsystem of the terminal and it hardly needs this value.
 
LRA:

Write first in a text file (in notepad) - then copy via the clipboard. It goes like this

Thank you. Good to know.

Read about OnInit() function - put cursor on it and press F1. The word int is in front - so this function returns an integer value. You are trying to return a value of the double type. The result of OnInit() is analyzed by the runtime subsystem of the terminal and it hardly needs this value.
Then what event handler of what type should be used to implement this - to
to fix the price value at the beginning of program operation, relative to which the future calculations will be performed?
I tried to remove everything that was in int OnInit and put the following code in the void OnTick at the very beginning by adding the variable varStart
if(varStart==0)
{
b=Bid;
varStart=1;
}
The result is unchanged.
 

There is a function with a pointer:


  TickReturn *returntick(int period, int timeposition)
   {
      TickReturn *returntick = new TickReturn();
      MqlRates rates[];
      MqlTick last_tick;
      
      if(SymbolInfoTick(symbol,last_tick)){}
      else Print("SymbolInfoTick() failed, error = ",GetLastError());
      
      //int timeposition=0;
      ArraySetAsSeries(rates,true);
      ArrayResize(rates,1);
      int copied=CopyRates(symbol,period,timeposition,1,rates);
      
      returntick.curtime = rates[0].time;
      returntick.open = rates[0].open;
      returntick.close = rates[0].close;
      returntick.high = rates[0].high;
      returntick.low = rates[0].low;
      returntick.priceask = last_tick.ask;
      returntick.pricebid = last_tick.bid;
      
      return(returntick);

   } 

I still call it in another function:


string timeis = returntick(period, 1).curtime;

How do I clear the memory behind it?

On delete(TickReturn); I get an error operand excepted.

 
hamsteruser:

There is a function with a pointer:


I still call it in another function:


How do I clear the memory behind it?

At delete(TickReturn); I get an error operand excepted.


If I read your code correctly, TickReturn is a class. You've created a pointer to a variable of this class's type. And you delete... the class itself? You need to destroy the pointer and make sure it exists and is dynamic.

 
Алексей Барбашин:

If I read your code correctly, TickReturn is a class. You've created a pointer to a variable of that class's type, but you're destroying... ...the class itself? You must destroy the pointer and make sure it exists and is dynamic.


The *returntick is not destructible either. I'm just confused by the trading terminal's output. It's telling me it's not clearing memory.

Reason: