[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 425

 
Elenn:


Any variables are lost when you exit the program (restart the computer, etc.). Except for global variables, because they are stored on the hard disk. But they can only be of type double. What to do, if it's necessary to store variables of other types (int or string for example)? What is unclear here?

The type of variable.

I.e. G.P. can only be real numbers. It is also possible to declare any global variables for a given program inside the program, it says here

 

Greetings MQL gurus !

Help a newbie write a piece of code : I know it's easy for you, but for a newbie .....

The condition - to close several positions opened one side at a time according to the same condition (for me, after the price has crossed a MA)

i have been trying for a couple of days, i have used some examples from Kim's and Sergey's scripts (no more information about him), but nothing works.

I have three orders open and only the last one has to close by condition.

According to the condition but one at a time. I want them all to be closed at once at the first crossing...

This is how I tried it, now it does not close at all.


//+------------------------------------------------------------------+
//| Check for close order Buy |
//+------------------------------------------------------------------+
void CheckForClosebuy()
{
double maclosebuy;
//---- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//---- get Moving Average
maclosebuy=iMA(NULL,TF,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
//----
for(int i=0;i<OrderMagicNumber()==MAGIC;i++)
{
while (i>0)
{

if (Open[1]>maclosebuy && Close[1]<maclosebuy)
OrderClose(OrderTicket(),OrderLots(),Bid,3,Aqua);
continue;
}
}
return(0);
}

 
Elenn:

"Not complaining" is sort of not really a mathematical concept.

It is written here:


There are client terminal global variables, they are double - https://book.mql4.com/ru/variables/globals they are for exchanging between EAs

And there are just global variables, they can be of any type https://book.mql4.com/ru/variables/types they are within one EA

What is your task?

 

Good evening! I'm totally stumped here. I am messing with code, which should open two orders, buystop and sellstop, and that's it. It seems to be not very smart code, everything seems clear, but it opens five orders, and that's it! I pored over his alerts during debugging, but it turned out an absolutely amazing thing, he first opens two bars (2011.06.04 20:20:48 2011.02.10 19:00 for EURUSD avalanche, H1: Alert: OrderType ( )0) Can not, can not be!!!!!! Well, he has nothing to open them with! No way!!!!!

It only has an order type OP_BUYSTOP and OP_SELLSTOP. And at distances of 20pp up and down.

Is my computer glitchy?

I quote // 0 - OP_BUY buy
1 - OP_SELL Sell
2 - OP_BUYLIMIT pending Buy Limit
3 - OP_SELLLIMIT deferred Sell Limit
4 - OP_BUYSTOP pending Buy Stop
5 - OP_SELLSTOP Pending Sell Stop

There cannot be any other values.


//

Anyway, I'm not shocked, but I'm in a deadlock. Below is the code and screenshot

//+------------------------------------------------------------------+
//|                                                   ля лавин б.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
extern double stoploss=0; extern double takeprofit=20;extern int otstup=20; extern datetime expiration=0;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
  
  
  
  int tiket,tikett;double volume=0.1;int i=0,R1=0,R2=0,A=1 ;double price; int stsBUY;int stsSELL;double Price;int C=0;
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
int X,Y; double price=(Ask+Bid)/2;            

       Alert ("OrdersTotal()",OrdersTotal());
       
       if(C==0){ Price = price ;  C=1;}


 for(int i=OrdersTotal();i>0;i--){Alert ("i", i);Alert ("OrderType( )", OrderType( ));OrderSelect(i,SELECT_BY_POS );if(OrderSymbol()==Symbol()&&OrderMagicNumber( )==1000){
if(OrderType( )==OP_BUYSTOP){X++;Alert ("X-v tsikle", X);}}}Alert ("X", X);
if (X==0){Alert ("Price", Price);Alert ("Price +otstup*Point",Price +otstup*Point);Alert ("Price+takeprofit*Point+otstup*Point", Price+takeprofit*Point+otstup*Point);


   tiket= OrderSend( Symbol(), OP_BUYSTOP,  volume*A, Price +otstup*Point, Point* 3, R1, Price+takeprofit*Point+otstup*Point, "OP_BUYSTOP", 1000,  expiration, Red); 
   Alert ("OP_BUYSTOP", GetLastError( )); }
   

 for ( i=OrdersTotal();i>0;i--){Alert ("i", i);Alert ("OrderType( )", OrderType( )); OrderSelect(i,SELECT_BY_POS );if( OrderMagicNumber( )==2000 &&OrderSymbol()==Symbol()) { 
if(OrderType( ) ==OP_SELLSTOP) { Y++;Alert ("Y-v tsikle", Y);}}}Alert ("Y", Y);
 if (Y==0){ 
 
 
   tikett= OrderSend( Symbol(), OP_SELLSTOP,  volume*A, Price -otstup*Point, Point* 3,R2, Price-takeprofit*Point-otstup*Point, "OP_SELLSTOP" , 2000,  expiration,C'0,128,255' );
    Alert ("OP_SELLSTOP", GetLastError( )); 
    } 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

I just don't know what to think about it.

 

The X b Y variables are the number of bypass and sellstop orders.

In the log, you can see that the order is triggered first, bypassing the order, and there is no error. Then suddenly it turns out that when we check the order type, we have a buy order with a numerical constant of zero. etc.

Maybe the warrantsend function is glitchy?

And only then, orders 5 and 4 show up!!!


 
Dimka-novitsek:

Good evening! I'm totally stumped here.

I get the impression that you are hopeless. You already have an advisor made up piece by piece, and you put the old mistakes into every new version. Replace everything

 for(int i=OrdersTotal();i>0;i--)

with .

 for(int i=OrdersTotal()-1;i>=0;i--)
 
Snaf:


What is your task?

My task is to be able to store different types of data and to be able to access them quickly. I think it would be long through files. Through the global variables can be fast, but they can only store type double. That's what I'm thinking.
 
Elenn:
My goal is to be able to store different types of data with the ability to quickly access them. I think it would take a long time to use files. Global variables can be fast, but they can only store type double. So I wonder what to do.
It won't take long through a file. It will be rather quick. There is yet another variant. You can store data in graphical objects. Names are written in advance, and you can store integer and fractional types in values, date in date coordinates. The string type in the object description
 
Store data in objects. Easy and quick to pick up. Easy to search. Easy to search. Convenient.
 
Porter:
Store data in objects. Easy and quick to pick up. Easy to search. Easy to search. Convenient.

And how does object storage work and what happens to objects in case of a computer crash?
Reason: