Download MetaTrader 5

My EA has multiple entries, how to i stage exits without closing all lots

To add comments, please log in or register
jazzpur
77
jazzpur  

im learning to to code by modifying existing EAs so please bear with me

im having trouble getting this technique to work


i figured out how to simply load up multiple orders upon a condition

CODE IS ATTACHED

so my entries grab two positions

but how do i hold onto one, and close the other at 20pips profit, unless reversal..in that case all close

it seems when i use TP and SL all positions close


im assuming this must be a magic number issue but everthing i try seems to not function properly


do i somehow need to make all the orders different magic numbers??

whroeder1
14780
whroeder1  
jazzpur: but how do i hold onto one, and close the other at 20pips profit, unless reversal..
ticket=OrderSend(Symbol(),OP_BUY,ManualLots,Ask,Slippage,StopLossLevel,TakeProfitLevel,Koment,MagicNumber,0,DodgerBlue);
   ticket=OrderSend(Symbol(),OP_BUYLIMIT,ManualLots,Ask+0.001,Slippage,10,10,Koment,MagicNumber,0,DodgerBlue)
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it

  2. Check your return codes What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  3. You are not adjusting SL, TP, and slippage; for 4/5 digit brokers and for JPY pairs.
    double   pip          = StringFind(_Symbol,"JPY") < 0 ? 0.01 : 0.0001;
    int      pipDigits    = (int)MathLog10(pip/_Point);
    int      pipsToPoints = int(pip / _Point);
    int      slippage     = 3 * pipsToPoints;
    0.001 is 10 pips on non-jpy pairs but 1/10 pip on JPY pairs.
  4. "10" is not a valid stop loss or a take profit. You need a price. The first send works because the extern's are zero.
jazzpur
77
jazzpur  
whroeder1:
  1. Please edit your post.
    For large amounts of code, attach it

  2. Check your return codes What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  3. You are not adjusting SL, TP, and slippage; for 4/5 digit brokers and for JPY pairs.
    double   pip          = StringFind(_Symbol,"JPY") < 0 ? 0.01 : 0.0001;
    int      pipDigits    = (int)MathLog10(pip/_Point);
    int      pipsToPoints = int(pip / _Point);
    int      slippage     = 3 * pipsToPoints;
    0.001 is 10 pips on non-jpy pairs but 1/10 pip on JPY pairs.
  4. "10" is not a valid stop loss or a take profit. You need a price. The first send works because the extern's are zero.


1. FIXED

2. good reads i def need to dig pages deep into these

3. ive adjusted for this by just shifting my input decimal places, and only trade eur/usd

but assuming i copy and paste this in will be a great universal fix?

4. ok i see i got ahead of myself, so TakeProfitLevel is a function that determines a price from the TakeProfit


if i make a TakeProfitLevel2 with a different function and apply to my second position opened, will this Take Profit only effect the second position? 


i know there are issues will FIFO rule so i will have to make it sequential exit

but i know when i set a manual TP all positions close and i dont like that

whroeder1
14780
whroeder1  

3) not universal see https://www.mql5.com/en/forum/169828#comment_4075614 #3

FIFO) If your TP on the second send is larger than the first that complies with FIFO. But my broker won't let them be different. You'll have to use the maximum and close the first order at a hidden SL.

jazzpur
77
jazzpur  
whroeder1:

3) not universal see https://www.mql5.com/en/forum/169828#comment_4075614 #3

FIFO) If your TP on the second send is larger than the first that complies with FIFO. But my broker won't let them be different. You'll have to use the maximum and close the first order at a hidden SL.


ok so perhaps the issue is my broker only allowing one TP level? im using forex.com

any link to code using a "hidden SL" or tp?

whroeder1
14780
whroeder1  
jazzpur: any link to code using a "hidden SL" or tp?
  1. How do you think you code a "hidden SL or TP?"
    static double hiddenSL, hiddenTP;
    for(...){
       if(OrderSelect(...){
          if(Bid < hiddenSL
          || Bid > hiddenTP) CloseOrder();
       }
    }
    #define NO_SL 0
    if(condition){
       hiddenSL=...; hidenTP=...; 
       ...OrderSend(..., NO_SL, NO_TP...);
    }

  2. EA's must be coded to recover. If the power fails, OS crashes, terminal or chart is accidentally closed, on the next tick, any static/global ticket variables will have been lost. You will have an open order but don't know it, so the EA will never try to close it, trail SL, etc. How are you going to recover? Use a OrderSelect loop to recover, or persistent storage (GV+flush or files) of ticket numbers required.
    ticket numbers and hidden stops.
jazzpur
77
jazzpur  
whroeder1:
  1. How do you think you code a "hidden SL or TP?"
  2. ticket numbers and hidden stops.


ok so with that code i need to get the return value from the order A, and B

ill need to create 

int ticketA;
int ticketB;

ticketA=OrderSend(Symbol(),OP_BUY,ManualLots,Ask,Slippage,StopLossLevel,TakeProfitLevel,Koment,MagicNumber,0,DodgerBlue);

ticketB=OrderSend(Symbol(),OP_BUY,ManualLots,Ask-0.001,Slippage,StopLossLevel,TakeProfitLevel,Koment,MagicNumber,0,DodgerBlue);


am i defining that right?


then for ticket A i use 

static double hiddenSL, hiddenTP;
for(...){
   if(OrderSelect(...){
      if(Bid < hiddenSL
      || Bid > hiddenTP) CloseOrder();
   }
}
#define NO_SL 0
if(condition){
   hiddenSL=...; hidenTP=...; 
   ...OrderSend(..., NO_SL, NO_TP...);
}


ticket B i will let ride until hard stops


am i getting somewhere close?

sorry im still new at this, what you are saying is still pretty advance to me

jazzpur
77
jazzpur  
jazzpur:


ok so with that code i need to get the return value from the order A, and B

ill need to create 


am i defining that right?


then for ticket A i use 


ticket B i will let ride until hard stops


am i getting somewhere close?

sorry im still new at this, what you are saying is still pretty advance to me

and now 

if(OrderSelect(ticketA, SELECT_BY_TICKET)==true)

.......

is that the correct syntax to continue with your hidden exits?

To add comments, please log in or register