Some help needed - page 8

 
qgmql:

Is this code ok? if not then please write some code instead of link, i am still confused.


NO https://www.mql5.com/en/forum/133792/page3#550831

gives pipvalue for a lot traded on specific symbol

 

1. There are some buy orders are opened and one buy pending order is placed. all orders are in same currency pair. how an EA will select only last opened order to check its stop limits?

2. every opened order was placed at different prices with tp 20. is it possible for ea to to modify all opened orders except the last one, and change their stop limits to the stop limits of last opened order?

EXAMPLE:

Sr    type   price     tp
1     buy    1.23950   1.23750
------------------------------
# buylimit   1.23750   1.23550

//////////////////////////////

1    buy     1.23950   1.23550 // tp modified and now equal to 2nd tp
2    buy     1.23750   1.23550 // 2nd tp
------------------------------
# buylimit   1.23550   1.23350

//////////////////////////////

1    buy     1.23950   1.23350 // tp modified and now equal to 3rd tp
2    buy     1.23750   1.23350 // tp modified and now equal to 3rd tp
3    buy     1.23550   1.23350 // 3rd tp
------------------------------
# buylimit   1.23350   1.23150
 

Some confusion with...

//Signal Filter
#define XXX   0
#define AAA   1
#define BBB   2

int SignalS = XXX;

if(SignalS & AAA !=0)
OrderSend(NULL, OP_BUY, LotSize, Ask, Slippage, SL, TP, WindowExpertName(), MagicID, 0, Blue);

Old editor accepts the highlighted lines, but new editor gives warning "Expression not boolean"

I tried then...

if(SignalS && AAA !=0)
//or
if(SignalS !=0 & AAA !=0)

Now new editor accepts both, but... which one will work the same like the highlighted line? if both true, then which one should i use? (more convenient?)

PS: Below code is also accepted by new editor...

if((SignalS & AAA) !=0)

New editor accepts all three, but... which one will work the same like the highlighted line? if all true, then which one will be more convenient for me?

 
qgmql: New editor accepts all three, but... which one will work the same like the highlighted line? if all true, then which one will be more convenient for me?
  1. Don't use a bit mask
    //Signal Filter
    #define XXX   0
    #define AAA   1
    #define BBB   2
    
    int SignalS = XXX;
    
    if(SignalS & AAA !=0)
    enum eSignals = {XXX, AAA, BBB};
    
    eSignals SignalS = XXX;
    
    if(SignalS == AAA)
    
    Self documenting code.

  2. Using a bit mask:
    On build 600+ != has higher precedence than bitwise and, you MUST use
    (SignalS & AAA) !=0
    On prior builds bitwise and was higher than multiplication

    Operation

    Desciption

    Execution Order

    ()

    []

    .

    Function Call

    Referencing to an array element

    Referencing to a structure element

    From left to right

    !

    ~

    –

    ++

    --

    (type)

    sizeof

    Logical negation

    Bitwise negation (complement)

    Sign changing

    Increment by one

    Decrement by one

    Typecasting

    Determining size in bytes

    Right to left

    *

    /

    %

    Multiplication

    Division

    Module division

    From left to right

    +

    –

    Addition

    Subtraction

    From left to right

    <<

    >>

    Left shift

    Right shift

    From left to right

    <

    <=

    >

    >=

    Less than

    Less than or equal

    Greater than

    Greater than or equal

    From left to right

    ==

    !=

    Equal

    Not equal

    From left to right

    &

    Bitwise AND operation

    From left to right

    ^

    Bitwise exclusive OR

    From left to right

    |

    Bitwise OR operation

    From left to right

    &&

    Logical AND operation

    From left to right

    ||

    Logical OR operation

    From left to right

    ?:

    Conditional Operator

    Right to left

    =

    *=

    /=

    %=

    +=

    -=

    <<=

    >>=

    &=

    ^=

    |=

    Assignment

    Multiplication with assignment

    Division with assignment

    Module with assignment

    Addition with assignment

    Subtraction with assignment

    Left shift with assignment

    Right shift with assignment

    Bitwise AND with assignment

    Exclusive OR with assignment

    Bitwise OR with assignment

    Right to left

    ,

    Comma

    From left to right

    ()     Function call                     From left to right
    []     Referencing to an array element
    
    !      Logical negation                  From right to left
    -      Sign changing operation
    ++     Increment
    --     Decrement
    ~      Bitwise negation (complement)
    
    &      Bitwise operation AND             From left to right
    |      Bitwise operation OR
    ^      Bitwise operation exclusive OR
    <<     Left shift
    >>     Right shift
    
    *      Multiplication                    From left to right
    /      Division
    %      Module division
    
    +      Addition                          From left to right
    -      Subtraction
    
    <      Less than                         From left to right
    <=     Less than or equal
    >      Greater than
    >=     Greater than or equal
    ==     Equal
    !=     Not equal
    
    ||     Logical OR                        From left to right
    &&     Logical AND                       From left to right
    =      Assignment                        From right to left
    +=     Assignment addition
    -=     Assignment subtraction
    *=     Assignment multiplication
    /=     Assignment division
    %=     Assignment module
    >>=    Assignment right shift
    <<=    Assignment left shift
    &=     Assignment bitwise AND
    |=     Assignment bitwise OR
    ^=     Assignment exclusive OR
    
    ,      Comma                             From left to right
 

WHRoeder i found your code (select last market order) and added highlighted lines to check its tp price and to set the same tp price on previous orders:

int PositionIndex;    //  <-- this variable is the index used for the loop

int TotalNumberOfOrders;   //  <-- this variable will hold the number of orders currently in the Trade pool
double Ord_TP=0;
TotalNumberOfOrders = OrdersTotal();    // <-- we store the number of Orders in the variable

for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --)  //  <-- for loop to loop through all Orders . .   COUNT DOWN TO ZERO !
   {
   if( ! OrderSelect(PositionIndex, SELECT_BY_POS, MODE_TRADES) ) continue;   // <-- if the OrderSelect fails advance the loop to the next PositionIndex
   
   if( OrderMagicNumber() == MagicNo       // <-- does the Order's Magic Number match our EA's magic number ? 
      && OrderSymbol() == Symbol()         // <-- does the Order's Symbol match the Symbol our EA is working on ? 
      && ( OrderType() == OP_BUY           // <-- is the Order a Buy Order ? 
      ||   OrderType() == OP_SELL ) )      // <-- or is it a Sell Order ?
   if(OrderTakeProfit()>0) 
   Ord_TP = OrderTakeProfit(); break;
   if(OrderTakeProfit() == Ord_TP) continue;
    OrderModify(OrderTicket(),0,0,Ord_TP,0,CLR_NONE);
      //if ( ! OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), Slippage ) )               // <-- try to close the order
         //Print("Order Close failed, order number: ", OrderTicket(), " Error: ", GetLastError() );  // <-- if the Order Close failed print some helpful information 
      
   } //  end of For loop

An extra line...

if(OrderTakeProfit()>0) 
   Ord_TP = OrderTakeProfit(); break;
   if(OrderTakeProfit() == Ord_TP) continue;
   if(OrderTakeProfit() != Ord_TP)
    OrderModify(OrderTicket(),0,0,Ord_TP,0,CLR_NONE);

Please guide, if i am wrong.

(All market+pending orders type is only buy, not sell or only sell, not buy and i want the tp of all market orders to be changed every time, when new market order is opened).

THIS IS REALLY TOUGH FOR ME, BUT I WANT TO DO IT. :(

 
Your indenting is wrong because you didn't use braces
if(OrderTakeProfit()>0) 
   Ord_TP = OrderTakeProfit(); break;
   if(OrderTakeProfit() == Ord_TP) continue;
   if(OrderTakeProfit() != Ord_TP)
    OrderModify(OrderTicket(),0,0,Ord_TP,0,CLR_NONE);
What your code actually is
if(OrderTakeProfit()>0) 
   Ord_TP = OrderTakeProfit(); 
break;
/*NOTREACHED
   if(OrderTakeProfit() == Ord_TP) continue;
   if(OrderTakeProfit() != Ord_TP)
    OrderModify(OrderTicket(),0,0,Ord_TP,0,CLR_NONE);
*/
 
Things are getting complicated for me. I think i should write code from start. and i will paste each part of code here. maybe i could understand that better.
Reason: