[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 404

 
Dimka-novitsek:
I can't organise a loop, X and Y always equal 0.

First, clear away the rubbish in your mind.

Make your code nice and structured.

And don't be greedy for comments.

 

Yes. Of course.

I first select orders with the required magic number and on that currency pair. if( OrderMagicNumber( )==2000 &&OrderSymbol()==Symbol()) {

Then the loop for( i=OrdersTotal();i==0;i--) in which I select the orders like this OrderSelect(i,SELECT_BY_POS ); and then count how many orders as OP_SELLSTOP

If there are no orders, then we open an order of the order type that does not exist. The X variable in the upper loop and the Y variable in the lower loop are used to count orders of the necessary type. Both loops are the same in structure and purpose.

I have already written with explanations, but here dad came, called, brought milk, tea and halva, and I did not send a message, I went to pee, and my father erased the unsent message, said, but what, you could write in another search engine window? I was wondering what nettle paste is. I got a little freaked out and sent it with almost no explanation.

Well, X and Y are always 0. The for loop must not be working. I don't understand at all what may not work, because of this the orders open 2 on every tick.


 
Dimka-novitsek:

Yes. Of course.

I first select orders with the required magic number and on that currency pair. if( OrderMagicNumber( )==2000 &&OrderSymbol()==Symbol()) {

Then the loop for( i=OrdersTotal();i==0;i--) in which I select the orders like this OrderSelect(i,SELECT_BY_POS ); and then count how many orders as OP_SELLSTOP

If there are no orders, then we open an order of the order type that does not exist. The X variable in the upper loop and the Y variable in the lower loop are used to count orders of the necessary type. Both loops are the same in structure and purpose.

I have already written with explanations, but here dad came, called, brought milk, tea and halva, and I did not send a message, I went to pee, and my father erased the unsent message, said, but what, you could write in another search engine window? I was wondering what nettle paste is. I got a little freaked out and sent it with almost no explanation.

Well, X and Y are always 0. The for loop must not be working. In short, I don't understand at all what could be not working there, it's causing orders to open 2 on each tick.


That's exactly right, the for loops do not do what you need.

You have the following: for( i=OrdersTotal();i==0;i--)

1) If there are 0 orders, the loop will be executed 1 time. In this case, it will select the unknown and do the unknown with it =)

2) If there are more than 0 orders, the loop will not start at all, because the condition "i==0" is not met

 
Thank you!!! I'll reread the reference again in a moment!
 
Yes! Thank you!!!
 
Ds you know, I can't get it right, everything is the same.
//+------------------------------------------------------------------+
//|                                                    для лавин.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);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
 int tiket,tikett;double volume=0.1;int i=0,R1=0,R2=0,A=1 ;double price=PRICE_OPEN;
   //  R1=((PRICE_OPEN- stoploss*Point)*stoploss)/stoploss;R2=((PRICE_OPEN+ stoploss*Point)*stoploss)/stoploss;
     
     
int start()
  {       int X,Y; double price=(Ask+Bid)/2;            
//----
       Alert ("OrdersTotal()",OrdersTotal());

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


   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( )); }
   
if( OrderMagicNumber( )==2000 &&OrderSymbol()==Symbol()) { 
 for ( i=OrdersTotal();i>0;i--){Alert ("i", i); OrderSelect(i,SELECT_BY_POS );
if(OrderType( ) ==OP_SELLSTOP) { 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);
  }
//+-------------------------------------------
In help it says

Expression2 is a check for the loop end condition. If it is true, then the for loop body operator is executed.

etc. I fixed everything and nothing has changed..also tried to put i=5 instead of i=OrdersTotal(), nothing has changed, the loop doesn't work.
 
Dimka-novitsek:
The help text says

Expression2 is a check for the loop end condition. If it is true, the for loop body operator is executed.

etc. I fixed everything and nothing has changed..also tried to write i=5 instead of i=OrdersTotal(), nothing has changed, the loop doesn't work.

Right, the loop doesn't get to the loop.

if(OrderSymbol()==Symbol()&&OrderMagicNumber( )==1000){
 for(int i=OrdersTotal();i>0;i--){Alert ("i", i);

You have written: "If the order symbol (which order? there are many of them... or none at all) equals the current order and its magic (what order?) equals 1000, then execute the loop".

and you have to : "start a loop. In it: 1) select an order. 2) and if symbol =... and magic =1000, then X++;"

 

Some DCs in real accounts assign all sorts of prefixes like "." or "FXF" to symbol names.

How can I use these prefixes?

I did it this way:

#define DEF_SPEC "FXF"

string SymbolsTrade[] = {"AUDCAD "DEF_SPEC ... -does not work

string SymbolsTrade[] = {"AUDCAD "+DEF_SPEC ... -it doesn't work like that either

as the result I get just FXF instead of AUDCADFXF.

Can you tell me how to implement this?
 
pusheax:

Some DCs in real accounts assign all sorts of prefixes like "." or "FXF" to symbol names.

How can I use these prefixes?

I did this:

#define DEF_SPEC "FXF"

string SymbolsTrade[] = {"AUDCAD "DEF_SPEC ... -does not work

string SymbolsTrade[] = {"AUDCAD "+DEF_SPEC ... -it doesn't work like that either

as the result I get just FXF instead of AUDCADFXF.

Can you tell me how to implement this?

Well, that's how it works on the fly:

#define DEF_SPEC "FXF"
string SymbolsTrade[] = {"AUDCAD", "EURUSD"};

int init()
{
   for (int i = 0; i < ArraySize(SymbolsTrade); i++)
      SymbolsTrade[i] = SymbolsTrade[i] + DEF_SPEC;
 

Got it, I'll do it...

Also, the condition doesn't work.

OrderSelect(i,SELECT_BY_POS );
if(OrderType( ) ==OP_SELLSTOP) { Y++;}Alert ("Y", Y);}
Reason: