Closing out half lots. - page 15

 
I am using this? Couple that with "if(OpenOrdersThisPair(Symbol())>0)" above, that should keep the EA's separated from each pair? I see what you're saying though. Any suggestions on how I can distinguish a trade that has been halved against one that has not using OrderOpenTime()? Little kick in the right direction...?

//+----------------------------------------------------------------------------------------------------------------------------------------+  
//| Check to see if any order open on this currency pair                                                                                   |
//+----------------------------------------------------------------------------------------------------------------------------------------+   

int OpenOrdersThisPair(string pair)
  {
   int total=0;
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()==pair) total++;
     }
   return(total);
  }
 
DomGilberto:
I am using this? Couple that with "if(OpenOrdersThisPair(Symbol())>0)" above, that should keep the EA's separated from each pair?

Nope, assume you have 2 EAs running and each has an Order open, you have a 50:50 chance that the last OrderSelected() by the OpenOrdersThisPair() function will be the wrong one . . . the function will return one but you may well have the wrong Order selected.
 
Forgive me, but I don't understand how that is true? I am making sure the OrderSymbol()==pair? So the relevant EA that is attached to EURUSD, would pick up it is the orderselect on EURUSD?
 
Would this sort it? In the journal it is telling me this? What about "OrderSymbol()==OrderSymbol()" lol? if it is THIS symbol... not sure if that is retarded or not...

   if(OpenOrdersThisPair(Symbol())>0) //If there is a trade open = do below, which ever is applicable.
     {
     if(OrderSelect(OrderTicket(),SELECT_BY_TICKET, MODE_TRADES)==True)
         {   
         Print("The Symbol is: ", OrderSymbol());  
         }
         
         if(OrderType()==OP_BUY && OrderOpenPrice() > OrderStopLoss() && OrderSymbol()==OrderSymbol())
               {
               CloseHalfOrder(); // Closes half at 1:1 - then calls another void to break even on the trade +3.
               }

         if(OrderType()==OP_SELL && OrderStopLoss() > OrderOpenPrice() && OrderSymbol()==OrderSymbol()) // lol? If this symbol is, this symbol...
               {
               CloseHalfOrder1(); // Closes half at 1:1 - then calls another void to break even on the trade +3.
               }
            
2013.08.08 18:51:21	2010.02.08 01:00  Trend Fishing 3 Exits GBPJPY,H1: The Symbol is: GBPJPY

 

Ah! What if I compared compared the OrderCloseTime() and the OrderOpenTime()!?

Surely this would be the BEST way of doing what I want? That way I can add as many OrderClose functions as I want? After-all, I could simply select the trade in the history that had the same OrderOpenTime() as the current "OP_BUY", but if the OrderCloseTime() > OrderOpenTime(), then this would stop the OrderClose(), closing halves out continuously!?!

Someone please tell me that I have got something to work with here :( haha.

 
DomGilberto:
Forgive me, but I don't understand how that is true? I am making sure the OrderSymbol()==pair? So the relevant EA that is attached to EURUSD, would pick up it is the orderselect on EURUSD?

You OrderSelect() first . . . then you check . .

if(OrderSymbol()==pair) total++;

. . . an that is fine for that function, if the symbols don't match you don't increment the count . . . but it still means that the last Order you selected was not for the symbol you are working on.

You need an additional loop and find a valid order then exit the loop . . . then you have the correct Order Selected.

 
I'm confused, I've forward tested my EA on 16 different pairs, simultaneously this week and it has never selected the wrong one :s? Am I missing something?
 
DomGilberto:
I'm confused, I've forward tested my EA on 16 different pairs, simultaneously this week and it has never selected the wrong one :s? Am I missing something?
As far as i can see it seems possible that it can select the wrong Order, I would fix it to be certain rather than risking it. Check your code, if it can't happen then you don't need to fix it.
 

DomGilberto:
I thought that too - It says I need OrderSelect() before using OrderType, but it works? I only ever have one order open at any given time...

I can't think of how to use OrderOpenTime() to my advantage and stop CloseHalfOrder being called every time...

EA part closes order, EA needs to know which order not to part close again, so get OrderOpenTime() before you part close. Code EA not to partclose orders on that currency pair with that same OrderOpenTime() again.

 
SDC:

EA part closes order, EA needs to know which order not to part close again, so get OrderOpenTime() before you part close. Code EA not to partclose orders on that currency pair with that same OrderOpenTime() again.


Yea I'm starting to get there now - I assume I need to compare with trades that have closed in history on the same OrderSymbol()?

The problem I have though; I am trying to partial close the same "OP_BUY" or "OP_SELL" up to 4 times at different prices... I think the question I should be asking is, can I get a way, where by I have a rule that ALL partial closes (of any lots and price on ONE given trade) will only partially close ONCE at their predefined "OrderClose()" parameters set...

This way I am looking at doing it now with comparing the OrderOpenTime() will essentially only work once, and will restrict any other type of OrderClose() function from happening at all... I am wanting to find a way where I can have one rule applied to 4 OrderClose() functions... (if that makes sense?)

I know people are suggesting open 4 orders, but without going too deep, it's less efficient for me doing it that way.
Reason: