Questions from Beginners MQL4 MT4 MetaTrader 4 - page 31

 
Alternatively, advise how to write this delete function into this condition.
 
spoiltboy:
Alternatively, tell me how to write this delete function in this condition.

you must first define the ticket of the pending order to be deleted

if the ticket is null or undefined - then do not delete it

 
spoiltboy:

This is for different orders. The function of removing one by a condition, removing the other without a condition.

The question is why in my case deletion function works successfully without a condition, but if I put it in a condition, it generates an error when the condition occurs.

The condition must be corrected, you cannot do it without the condition, the logs will take up the whole hard drive
 
Renat Akhtyamov:

you must first define the ticketD and the ticketUP to be deleted

If the ticket is null or undefined, then no deletion

So defined, one ticketD, the otherticketUP .

Or am I mixing something up?

 
spoiltboy:

So defined, one ticketD, the otherticketUP .

Or am I confusing something?

How can it be defined ifticketUP is already deleted?

You have deleted it, update ticketUP to the state you need, in which the condition to delete the ticketUP will not work, and this condition must be added to the code as well

 
Renat Akhtyamov:

How can it be defined ifthe ticketUP has already been deleted?

You have deleted it, update ticketUP to the state you need, in which the condition to delete the ticket will not work, and this condition must also be added to the code.

So, the orders withticketD, anotherticketUP are created first (according to the absence condition), and after that they are already deleted.

if(BuyLimitCount()==0&& BuyCount()==0){
slB=NormalizeDouble(minpr1-pointsl*Point,5);
tpB=NormalizeDouble(minpr1+pointtp*Point,5);
int ticketUP=OrderSend(Symbol(),OP_BUYLIMIT, lotB, minpr1,3, slB, tpB,"", MagicB,0, Red);
if(ticketUP==-1)Print("ERROR OP_BUY"); elsePrint("OP_BUY OK");}

if(SellLimitCount()==0&& SellCount() ==0){
slS=NormalizeDouble(maxpr1+pointsl*Point,5);
tpS=NormalizeDouble(maxpr1-pointtp*Point,5);
int ticketD=OrderSend(Symbol(),OP_SELLLIMIT, lotS, maxpr1,3, slS, tpS,"", MagicS,0, Blue);
if(ticketD==-1)Print("ERROR OP_SELL"); elsePrint("OP_SELL OK");}

if(x!=maxpr1){x=maxpr1;OrderDelete(ticketD);}

OrderDelete(ticketUP);

If I am confused, what?

 
spoiltboy:

So orders withticketD, anotherticketUP are created first (according to the absence condition), and then they are deleted.

if(BuyLimitCount()==0&& BuyCount()==0){
slB=NormalizeDouble(minpr1-pointsl*Point,5);
tpB=NormalizeDouble(minpr1+pointsl*Point,5);
int ticketUP=OrderSend(Symbol(),OP_BUYLIMIT, lotB, minpr1,3, slB, tpB,"", MagicB,0, Red);
if(ticketUP==-1)Print("ERROR OP_BUY"); elsePrint("OP_BUY OK");}

if(SellLimitCount()==0&& SellCount() ==0){
slS=NormalizeDouble(maxpr1+pointsl*Point,5);
tpS=NormalizeDouble(maxpr1+pointsl*Point,5);
int ticketD=OrderSend(Symbol(),OP_SELLLIMIT, lotS, maxpr1,3, slS, tpS,"", MagicS,0, Blue);
if(ticketD==-1)Print("ERROR OP_SELL"); elsePrint("OP_SELL OK");}

if(x!=maxpr1){x=maxpr1;OrderDelete(ticketD);}

OrderDelete(ticketUP);

If I confuse what?

Again you have a command without a condition:

OrderDelete(ticketUP);

Why didn't you change the code?

Take a time-out to "think" at least and sort it out + read what you've written, what advice was given.

By the way, there's freelancing here, if you can't...

 
Renat Akhtyamov:

So again you have a command without a condition:

OrderDelete(ticketUP);

Why didn't you change the code?

Take a time-out to "think" at least and figure it out + read what you've been written, what advice you've been given.

By the way, there's freelancing here if it doesn't work...

It's without a condition - because that's how removal occurs, and with a condition - no. So wrote to indicate that I can not. You should write it in this way:

OrderDelete(ticketD);

OrderDelete(ticketUP);

Then every tick deletes orders already created on every tick (according to the absence condition). And if we write it with the condition:

if (x!=maxpr1){x=maxpr1; OrderDelete(ticketD);}

if (z!=minpr1){z=minpr1; OrderDelete(ticketUP);}

Then when the condition occurs, it writes a deletion error.

How do I write the deletion of the specified orders in this condition?

 
spoiltboy:

It's without a condition - because that's how deletion works, but with a condition it doesn't. I wrote it this way to point out what I can't do. If you write it in this way:

OrderDelete(ticketD);

OrderDelete(ticketUP);

Then every tick deletes orders already created on every tick (according to the absence condition). And if we write it with the condition:

if (x!=maxpr1){x=maxpr1; OrderDelete(ticketD);}

if (z!=minpr1){z=minpr1; OrderDelete(ticketUP);}

Then when the condition occurs, it writes a deletion error.

How should we write the condition on deleting the specified orders?


You cannot remove the condition to delete orders!

ticketUP and ticketD should be written in the global variables when opening a ticket

GlobalVariableSet("ticketUP",ticketUP);

GlobalVariableSet("ticketD",ticketD);

and read from there before deleting a pending ticket

ticketUP=GlobalVariableGet("ticketUP")

ticketD=GlobalVariableGet("ticketD")

By the way, look there (in global) - what you have, what ticket is written

I think, that after that all will work as it should

 
Hello! Who can help to solve the problem, I am writing a viper for a dynamic array, here is the code of the class:
class CArray
{  
private:
   template <typename T>
   T _array[];
   int _index;
   int _err;
   int _err_sys;
public:
   CArray(){_index = -1; _err = 0; _err_sys = 0;}
   ~CArray(){}
  // template <typename T>
   T operator[](int i){
      if((_index == -1) || (i < 0) || (i > _index)) {_err_sys = -1;}
      return (_array[i]);
   }
   T at(int i){  
      if((_index == -1) || (i < 0) || (i > _index)) {_err_sys = -1;}
      return (_array[i]);
   }
   void push_back(T value){
      _array[++_index] = value;
   }
};

part of the program code:

#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.1"
#property strict

#include "Array.mqh"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
CArray *array;


int OnInit()
  {
  int b = 1;
   array = new CArray();
   array.push_back(b);
   int a = array.at(0);
  
//---
   return(INIT_SUCCEEDED);
  }
...

After trying to run the Expert Advisor on real data, the following error is thrown: internal error #-1005

What I do wrong? Thanks in advance!


Reason: