OrdersTotal() work on 2 or more Charts by opening trades - page 2

 
Keith Watford:

Always use #property strict in your code

This check does nothing except declare a bool variable

Profit is in currency, not pips

What is the point of this loop? You don't change the values for Loop or Loop2, so how will it ever exit the loop?

Do you really expect the order to be selected?

The Point of that loop is an infinite loop, i want my ea to run non stop. Is it wrong?

  int Loop=-1;
  int Loop2=0;
  while(Loop<Loop2)


Should I change this to Loop2 then?
int Loop=-1;
//
//
    if(OrderSelect(Loop,SELECT_BY_POS,MODE_TRADES))
 
Jefferson Metha:

Just looked at your code you have an error 

You will never have a position thats both a BUY and a SELL. 
change that line to 

Thank You Jefferson I will change it
 
Jack Buda:

The Point of that loop is an infinite loop, i want my ea to run non stop. Is it wrong?


Should I change this to Loop2 then?
Do this for me, 
Get a paper and make a flow diagram, of how the EA works 
When it enters into a loop, how will it come out, 
Ur then run Debug u will notice ur EA will get stuck somewhere
 
Jack Buda:

look at OrderSelect 
so we have 10 Open Positions with numbers  0-9 
we are selecting 1st trade we say 

OrderSelect(0,SELECT_BY_POS)

next trade we say OrderSelect(2~~~
Orderselect(3~~~~  etc

hence the Loop so that we select the trades Automatically hence this line 




for(int i=OrdersTotal()-1;i>=0;i--)
   {
    if(OrderSelect(Loop,SELECT_BY_POS,MODE_TRADES))

Is a desaster waiting to happen cause Loop is a constant from what I see 

 int Loop=-1;
  int Loop2=0;

Which means u will always be selecting the SAME trade over and over again
 for each time the Loop runs.  plus Loop = -1 I thkink that will return an error and no trade will be selected. 

 
Jack Buda:

The Point of that loop is an infinite loop, i want my ea to run non stop. Is it wrong?


Should I change this to Loop2 then?

int Loop=-1;
//
//
    if(OrderSelect(Loop,SELECT_BY_POS,MODE_TRADES))


Yes, it is wrong. EAs should be designed to run when a new tick arrives (usually).

Read and properly study my previous amswer.

 
Jefferson Metha:

look at OrderSelect 
so we have 10 Open Positions with numbers  0-9 
we are selecting 1st trade we say 

next trade we say OrderSelect(2~~~
Orderselect(3~~~~  etc

hence the Loop so that we select the trades Automatically hence this line 




Is a desaster waiting to happen cause Loop is a constant from what I see 

Which means u will always be selecting the SAME trade over and over again
 for each time the Loop runs.  plus Loop = -1 I thkink that will return an error and no trade will be selected. 

Correct me if I'm wrong, "int" are numbers 0,1,2,3,4,5,6 etc right? So what you guys are saying is that my Loop should be as follows:
 int Loop=0;
 int Loop2=1;
 
Keith Watford:

Yes, it is wrong. EAs should be designed to run when a new tick arrives (usually).

Read and properly study my previous amswer.

 int Loop=0;
 int Loop2=1;
Is this how its suppose to be right?
 
Jack Buda:
Is this how its suppose to be right?

No - you don't want the loop variables at all, nor the while

and you definitely don't want to use the variable here.

   for(int i=OrdersTotal()-1;i>=0;i--)
   {
    if(OrderSelect(Loop,SELECT_BY_POS,MODE_TRADES))
 
Jack Buda:
Correct me if I'm wrong, "int" are numbers 0,1,2,3,4,5,6 etc right? So what you guys are saying is that my Loop should be as follows:
So u want to select a different trade with each loop. 

Where as OrdersTotal() has number of open trades. 

Let's say you have 10 open trades 
If u use 
OrderSelect(Loop ~~
U are only selecting the American trade over and over again 
So that Loop constant has to be changed by another variable that changes its value with each loop run  

HINT: delete Loop word from ur code
 
Jefferson Metha:
So u want to select a different trade with each loop. 

Where as OrdersTotal() has number of open trades. 

Let's say you have 10 open trades 
If u use 
OrderSelect(Loop ~~
U are only selecting the American trade over and over again 
So that Loop constant has to be changed by another variable that changes its value with each loop run  

HINT: delete Loop word from ur code

I understand what you & Keith were saying now .

I noticed that my Stop Loss were incorrect. So i changed it to this:

if(OrderSelect(1000,SELECT_BY_POS,MODE_TRADES))
Reason: