trades by Magic

alttear
37
alttear  

Hi

I have a Working Ea which open one trade at a certain condition

I want to add Multiple trades, each one by it`s uniqe magic number

the problem is when I try to close the trade, My code close all the trade at once and I want to close each one by it`s uniqe MagicNumber

extern int Magic = 1;
extern int MagicABC = 1;

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

for(int pos1=0;pos1<OrdersHistoryTotal();pos1++)
      {
       OrderSelect(pos1,SELECT_BY_POS, MODE_HISTORY);
         OTK=OrderTakeProfit();
         OSL=OrderStopLoss();
         int ORP=OrderProfit();
                         /////////////////////////// 
                         OTKABC=OrderTakeProfit();
                         OSLABC=OrderStopLoss();
                         int ORPABC=OrderProfit();
                         //////////////////////////         
         }

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

for(int pos2=0;pos2<OrdersTotal();pos2++)
{
OrderSelect(0, SELECT_BY_TICKET, MODE_TRADES);    
if ( MarketInfo(Symbol(),MODE_Ask) <= OrderTakeProfit()+(1000)*Point || MarketInfo(Symbol(),MODE_Ask) >= OrderStopLoss()-(1000)*Point )
OrderClose(OrderTicket(),Lots,Ask,20,CLR_NONE);                               
}

the OrderClose Function close all the trade at once, and I need each trade close when it`s Takeprofit or StopLoss condition is reached by the Magic Number

ydrol
513
ydrol  

Orders are automatically closed at SL/TP.

If you are trying to stealth then:

Check the OrderMagicNumber and OrderSymbol functons.

Read this Loops and Closing or Deleting Orders

alttear
37
alttear  

Thank you

I`ve already seen This, but it`s not always Closed as the Tp and Sl

I want each trade contains a uniqe Magic number closed alone not with any other trade

I tried my self and did not find a good way

as you seen my trades take the Tp and Sl from the OrderHistoryTotal .. and as for this it takes the ( Tp and Sl ) From last closed Order not for the last closed order specified by each Magic Number

I guess thats the problem,,,, But Don`t Know how to fix it :)

ydrol
513
ydrol  

Are you trying to fix the code? I think the answers are all in the links? I would suggest you at least change the loop as suggested, then that alone will help reduce the number of errors in your code.

Then if your code needs to check MagicNumber then check it.

Also your code does not make any distinction based on OrderType(), which doesnt make sense to me.

You should also read this What are Function return values ? How do I use them ?

ydrol
513
ydrol  
Alttear:

as you seen my trades take the Tp and Sl from the OrderHistoryTotal .. and as for this it takes the ( Tp and Sl ) From last closed Order not for the last closed order specified by each Magic Number


BTW You code sets variables OTK, OSL but it doesnt do anything with them.
Keith Watford
Moderator
28968
Keith Watford  
OrderSelect(0, SELECT_BY_TICKET, MODE_TRADES);    

A ticket number will always be more than zero

alttear
37
alttear  
GumRai:

A ticket number will always be more than zero


Thanks My friend .... That`s fixed the Problem
alttear
37
alttear  
ydrol:

Orders are automatically closed at SL/TP.

If you are trying to stealth then:

Check the OrderMagicNumber and OrderSymbol functons.

Read this Loops and Closing or Deleting Orders


I Changed The loop and Made it as The CloseAllOrder Code,,, Now It`s Working

Thanks