EA for each currency pair - what code to open only once per currency pair? - page 4

 
onewithzachy:
You are dead wrong. Your code never gets executed !!!. Use RaptorUK's.

Okay :)

I simply got confused by this:

"finish when j = 0"

thanks!

 
grey.unit:

So it should look like this:

because you wrote this:

or am I wrong?

You are wrong . . . take a look at this: for

In my code expression 2 is j >= 0 meaning . . . while ( j >= 0 ) so the loop executes while j is 0 or greater, i.e. from OrdersTotal() - 1 down to and including 0

If you use j = 0 (maybe it would have to be written j == 0) it means while (j == 0) and the loop only executes when j is 0

 
Ah okay, now i understood it
 
RaptorUK:

No, do this . . .

The first order position is 0 so if you have 5 orders the positions are 0, 1, 2, 3, 4 . . . so the last is OrdersTotal() - 1 . . . so to count down you start at OrdersTotal()-1 and end at 0

       

Does this mean that OrdersTotal () -1 is No Orders , then 0 is 1st order, 1 is 2 orders and so on to 4 which equal the 5 orders.

Would someone let me know if my understanding that -1 is equal to No orders , is this correct ?

Thanks 

 
barnacle7:

Does this mean that OrdersTotal () -1 is No Orders , then 0 is 1st order, 1 is 2 orders and so on to 4 which equal the 5 orders.

OrdersTotal() is the number of open orders.  Yes,  if you have 5 in total they are numbered 0 to 4
 

I also need help concerning the same issue. I'm a novice coder and I've been trying to input the code I saw here but its not working at all can you help me. The Orderselect was used 

to replace OrdersTotal and control number of trades each EA makes but now the others won't place trades

void OnTick()

{
       double movingAverageSS = iMA(NULL,60,LowerMAS,0,MODE_SMA,PRICE_CLOSE,0);    
       double lastmovingAverageSS = iMA(NULL,60,LowerMAS,0,MODE_SMA,PRICE_CLOSE,1);     
       double movingAverageSB = iMA(NULL,60,LowerMAB,0,MODE_SMA,PRICE_CLOSE,0);       
       double lastmovingAverageSB = iMA(NULL,60,LowerMAB,0,MODE_SMA,PRICE_CLOSE,1);          
       double movingAverageFS = iMA(NULL,60,UpperMAS,0,MODE_SMA,PRICE_CLOSE,0);    
       double lastmovingAverageFS = iMA(NULL,60,UpperMAS,0,MODE_SMA,PRICE_CLOSE,1);   
       double movingAverageFB = iMA(NULL,60,UpperMAB,0,MODE_SMA,PRICE_CLOSE,0);    
       double lastmovingAverageFB = iMA(NULL,60,UpperMAB,0,MODE_SMA,PRICE_CLOSE,1);    
       int b;int bM;int s;int sM;    
       bool res = (OrderSelect(b,SELECT_BY_POS));    
       bool resM = (OrderSelect(bM,SELECT_BY_POS));    
       bool ses = (OrderSelect(s,SELECT_BY_POS));    
       bool sesM = (OrderSelect(sM,SELECT_BY_POS));    
       
       if((lastmovingAverageFB<lastmovingAverageSB) && (movingAverageFB > movingAverageSB) && res == false  && resM == false )      
         {
         b = OrderSend (Symbol(),OP_BUY,lotSize,Ask,4,Ask - SLPB*_Point, Ask + TPB1*_Point,NULL,1,0,Green);       
         bM = OrderSend (Symbol(),OP_BUY,lotSize,Ask,4,Ask - SLPB*_Point, Ask + TPB2*_Point,NULL,2,0,Green);       
         }       
         else if((lastmovingAverageFS>lastmovingAverageSS)&&(movingAverageFS<movingAverageSS) && ses == false && sesM == false)     
         {  
         s = OrderSend (Symbol(),OP_SELL,lotSize,Bid,4,Ask + SLPS*_Point,Ask - TPS1*_Point,NULL,3,0,Red);       
        sM = OrderSend (Symbol(),OP_SELL,lotSize,Bid,4,Ask + SLPS*_Point,Ask - TPS2*_Point,NULL,4,0,Red);   
}


    

                 
 
&& res == false

Orderselect will return true if it selected an order.

Maybe you can use a magic number in combination with the symbolname.

Here is an example in article you can study: https://www.mql5.com/en/articles/1359

MagicNumber: "Magic" Identifier of the Order
MagicNumber: "Magic" Identifier of the Order
  • www.mql5.com
In МТ3, management of open positions was rather time-taking. Traders had at their disposal a rather limited tool set to work with the list of open and closed positions. The problem of distinguishing between "own" and "someone else's" positions was solved in rather complicated ways. In МТ4, the situation has cardinally changed. Now, trader can...
 
  1.        int b;int bM;int s;int sM;    
           bool res = (OrderSelect(b,SELECT_BY_POS));    
           bool resM = (OrderSelect(bM,SELECT_BY_POS));    
           bool ses = (OrderSelect(s,SELECT_BY_POS));    
           bool sesM = (OrderSelect(sM,SELECT_BY_POS));    

    b as no value, OrderSelect fails. bM as no value, OrderSelect fails. s as no value, OrderSelect fails. sM as no value, OrderSelect fails.

  2. What is the point of selecting multiple orders? The result is the last successful select.

  3.          b = OrderSend (Symbol(),OP_BUY,lotSize,Ask,4,Ask - SLPB*_Point, Ask + TPB1*_Point,NULL,1,0,Green);       
             bM = OrderSend (Symbol(),OP_BUY,lotSize,Ask,4,Ask - SLPB*_Point, Ask + TPB2*_Point,NULL,2,0,Green);       
    
    b and bM are local variables. Ticket numbers are lost when you return.

  4. Why are you trying to select by position, but trying to store ticket numbers? If you select by a valid ticket number that doesn't mean the order is open.

  5. You buy at the Ask and sell at the Bid.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using the Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
      Most brokers with variable spread widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134.

 
onewithzachy #:

Code it like this :

Please can I use this code in my project
 
The Chosen #:
Please can I use this code in my project
If I am not wrong, anything posted on forum is free to use...

You could mention the source in your code, but I would guess that is in fact up to you, as long as you do not publish on code base. For code base, I suggest, if it is a major part of code, you at least mention the source in the code somewhere.

It will make it easier for people (and you) to backtrack your work.
Reason: