How can I place a new trade right after losing a one?

 
Hi guys,


I have a portion of code that I can't get to work.. The whole idea is that if the sum of profit for my magic number is negative (ie the last trade lost), then I'd like for the EA to place a new trade. Am I going off on the wrong direction with the code I've pasted below?? Any help is greatly appreciated! Thanks! :)




//*******************MERCANTILE*******************************

{
int total=OrdersTotal()-1;
double profsumm=0;
for (int cnt = total ; cnt >=0 ; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber() == MAGICMA)
{
profsumm+=OrderProfit();
}
}
return(profsumm);
}

if((profsumm<0) && Condition1 = "True")
{
res=OrderSend(Symbol(),OP_SELL,LotSize*3.2,Bid,3,Bid + SLShort,Bid - TPShort,"",MAGICMA,0,Red);

return;
}

if ((profsumm<0) && Condition1 = "False")
{
res=OrderSend(Symbol(),OP_BUY,LotSize*3.2,Ask,3,Ask - SLLong,Ask + TPLong,"",MAGICMA,0,Blue);

return;
}
//**********************************************************
 
heyarn wrote >>


Hi guys,

I have a portion of code that I can't get to work.. The whole idea is that if the sum of profit for my magic number is negative (ie the last trade lost), then I'd like for the EA to place a new trade. Am I going off on the wrong direction with the code I've pasted below?? Any help is greatly appreciated! Thanks! :)

if the last trade is a loss, then the conditions to check is in the ordershisory, not the current market orders.

1. first check if order is still in market

2. if not it is either profit or loss -> go to orderhistory and look for the last order by comparing the close time of the orders ie the latest close time

3. check if the last order is +ve or -ve and get the optype ie buy or sell

4. then execute the new order based on the opposite optype

Reason: