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

 

Hi all) advise me please - I can not figure out how to write the code (Example; 2 robots work - each one has its own magik) most of the buy or sell orders fall on the order history, ie if the order was a sell, the next transaction is a buy order - the problem is that I can not select the last order and the magik togetherand therefore identify the type of order for a particular robot (only part of the code works - if I choose only the last order of the history - perfectly works when the robot is one and the second code written for lists all the orders with a magic number prints its number and writes its type but why then does not return the value last and I can not understand why) help me bring it together into one whole here is 1 and 2 code;

1) code to determine the last order, or more precisely, its type

int orderBS;

int total1=OrdersHistoryTotal()-1;

if(OrderSelect(total1, SELECT_BY_POS, MODE_HISTORY) == true) // order type

{ orderBS=OrderType();}

2) the code counts all executed trades and records their order number and type but does not output the last order

int k ;

int orderBS;

if(OrdersHistoryTotal()>0)

{ for(int O=OrdersHistoryTotal()-1; O>=0; O--)

{ if(OrderSelect(O,SELECT_BY_POS,MODE_HISTORY))

{ if(OrderMagicNumber()!=136) continue;

if(OrderMagicNumber()==136)

k=OrderMagicNumber();

orderBS=OrderType();

Alert("last order number 136 = ", "order number in history=",O, "magic number=",k, "order sat buy=",orderBS); }}}

HOW TO RETURN LAST ORDER FROM HISTORY WITH A WANTED MAGIC NUMBER !!!


help me pliz!!!!!

 
Tema97:

Hi all) advise me please - I can not figure out how to write the code (Example; 2 robots work - each one has its own magik) most of the buy or sell orders fall on the order history, ie if the order was a sell, the next transaction is a buy order - the problem is that I can not select the last order and the magik togetherand therefore identify the type of order for a particular robot (only part of the code works - if I choose only the last order from the history - perfectly works when the robot is one and the second code written for lists all the orders with a magic number prints its number and writes its type but why then does not return the value last and I can not understand why) help me connect this into one whole here 1 and 2 code;


1) To properly paste the source code in the forum, click on SRC and paste your code in the window that appears.


2) Try a script like this, quickly sketched it out, didn't test it as I have no orders in history.

#property strict

void OnStart()
  {
   if(OrdersHistoryTotal()>0)
     {
      for(int i=OrdersHistoryTotal()-1; i>=0; i--)
        {
         if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
           {
            if(OrderMagicNumber()!=136) continue;
              {
               Print("Последний ордер с магик-номером 136: индекс ордера в истории = ",i,
                     " магик номер = ",OrderMagicNumber(),
                     " тип ордера = ",OrderType());
               return;
              }
           }
        }
     }
  }

3) Remember, if after if there is only one instruction, you don't have to put curly brackets { }, but if you have 2 or more instructions that depend on this if, you have to put them inside { }. In your example above, after the condition if(OrderMagicNumber()==136) there are 3 instructions to=...; orderBS=...; and Alert(); but they are not placed inside { }.

 

"One man is not a soldier in the field!"

Hello everyone!

Is there anyone from LITMO(St. Petersburg State University of Information Technologies Mechanics and Optics), living in St. Petersburg, with whom you can meet in person and discuss programming issues?
Please, contact me personally or by e-mail: leonid.belskiy@gmail.com !!!!!
 
paladin80:

1) To properly paste the source code in the forum, click on SRC and paste your code in the window that appears.


2) Try this script, quickly sketched it out, didn't check it as I have no orders in history.

3) Remember, if there is only one instruction after if, you don't have to put curly braces { }, but if there are 2 or more instructions depending on this if, you have to put them inside { }. In your example above, after the condition if(OrderMagicNumber()==136) there are 3 instructions to=...; orderBS=...; and Alert(); but they are not placed inside { }.

- It does the same as the 2 code - the last one does not select ((((((((((((

can i do something like ????? at closing time or no selection there either?

 
Hi all. Who knows what is the lifetime of a one-dimensional static array? Is it the same as a local variable or not?
 
i999i:
Hi all. Who knows what is the lifetime of a one-dimensional static array? Is it the same as a local variable or not?
After execution of a function, in which the array is declared, should I delete it or do something with it to free up memory, or it will be deleted by itself?
 
i999i:
After executing a function, in which an array is declared, should it be deleted or something done to free up memory, or will it delete itself?
As long as the program is running, it (the array) exists
 
Vinin:
As long as the program is running, it (array) exists
But if I need it for 1 tick per hour and don't need it the rest of the time ... how do I delete it ... it's taking up memory
 
Can you tell me how often the chart is redrawn by itself? (as well as forced byChartRedraw() )
 
i999i:
If I need it for 1 tick an hour and don't need it the rest of the time ... how do I remove it ... it takes up memory the whole time
How much memory does it take up? The time of programmable calculators with a dozen kilobytes of memory is over =)