forLoop Misunderstanding stalking multiple opened Orders...

 

Hy, i am working for a year on my first ea...its a complete virtual trailing stop....there is a problem:

the ea shall stalk each order separate and nor cumulated...

lets say we buy at broken Hjgh[1] and with new candle we buy again at broken High[1]....Now we got two open Buys with different prices..

if i let my ea trail these positions by example 27points to follow, he follows them not separate, but closes them at the same time....

i know its a loop thing, maybe a loop in a loop thing, i never learned this stuff and i am trying to understand it for myself, but i just dont get it in my head, how to write this....

i really just need the formula for loops...the rest i will handle myself...is it possible that ONE ea cannot handle two different Orders at the same time? Please help, Thanks in regard..

 
the key problem might be the fact, that i want the ea to trail them at the SAME time, NOT one after another and NOT with the same "orderclose"-Trigger
 

I don't understand what your problem is.

If both orders go 27 points in profit, then they will both be trailing at 27 points and will close at the same level.

 
Keith Watford:

I don't understand what your problem is.

If both orders go 27 points in profit, then they will both be trailing at 27 points and will close at the same level.

thats totally right, sorry, if it was a percentage of profit, situation becomes clearer For 50Percent, order one has 80 Profit, trailing stop is 40 from actual price, order two has 60 Profit, trailing stop is 30 from actual price... i want only order two to close when price falling 30points and only order one closed when ita falls 10 points further to minus 40...

 
Tim Rittel:

thats totally right, sorry, if it was a percentage of profit, situation becomes clearer For 50Percent, order one has 80 Profit, trailing stop is 40 from actual price, order two has 60 Profit, trailing stop is 30 from actual price... i want only order two to close when price falling 30points and only order one closed when ita falls 10 points further to minus 40...

In the case of a buy.

calculate difference between the current price and the open price 

calculate the percentage and add to the open price or deduct from the current price (whichever way you want to do it)

if this value is higher than the current SL, then modify it.

 
Keith Watford:

In the case of a buy.

calculate difference between the current price and the open price 

calculate the percentage and add to the open price or deduct from the current price (whichever way you want to do it)

if this value is higher than the current SL, then modify it.

thank you keith, thanks for attention, yes of course, thats not my problem, the problem is ,,,,how can the ea handle two opened orders separately, SL for Order 1 is +40 and SL for Order 2 is +30 ((because of 50% from individual orderProfit))

 
Tim Rittel:

thank you keith, thanks for attention, yes of course, thats not my problem, the problem is ,,,,how can the ea handle two opened orders separately, SL for Order 1 is +40 and SL for Order 2 is +30 ((because of 50% from individual orderProfit))

I am sorry, but if my earlier response doesn't answer your question, then I must be misunderstanding something.

 
Tim Rittel:

thank you keith, thanks for attention, yes of course, thats not my problem, the problem is ,,,,how can the ea handle two opened orders separately, SL for Order 1 is +40 and SL for Order 2 is +30 ((because of 50% from individual orderProfit))

Please show your code if you need coding help.
 
Keith Watford:

I am sorry, but if my earlier response doesn't answer your question, then I must be misunderstanding something.

ok i try to get more concrete...


for(int x=OrdersTotal();x>0;x++) ???                                                        //<-- direct every detected order to the following for loop

  {

  if(OrderSelect(x, SELECT_BY_POS, MODE_TRADES)==true){}; ???

      {

      for(int y=???;y>0;<???) ???                                                                 //<-- now handle the detected order with all the following stuff, while every other detected order is also in a parrallel loop..

          {

          if(OrderSelect(y, SELECT_BY_POS, MODE_TRADES)==true){}; ???

          }
      }

  }

 
Alain Verleyen:
Please show your code if you need coding help.

for(int j=0; j<OrdersTotal(); j++)

     {

      if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES)==true)

        {

         tip=OrderType();

         if((which_MagicNumber_to_trail==OrderMagicNumber() || which_MagicNumber_to_trail==-1) 

         && (which_Comment_to_trail==OrderComment() || which_Comment_to_trail=="ALL")

         && OrderSymbol()==Symbol()

         &&(includeManualTrades==true||OrderMagicNumber()!=0))

           {

            OSL    = OrderStopLoss();

            OOP    = OrderOpenPrice();

            Ticket = OrderTicket();

            n++;

            if(tip==OP_BUY)

              { AND SO ON.....

 

Please show relevant code

AND SO ON...

is not any use.

Reason: