Trouble with OrderSend

 

All -

I am using CitiFX Pro (an ECN broker) with 5 digits.

According to a post WHRoeder, I must send out a successful order first and then set my SL/TP. Is there any sample code that does this?

I Keep getting an error code 130 when I set the SL/TP with the OrderSend() function.

I would appreciate all / any help.

Thanks.

 
int OrderSend( string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)
Parameters:
symbol - Symbol for trading.
cmd - Operation type. It can be any of the Trade operation enumeration.
volume - Number of lots.
price - Preferred price of the trade.
slippage - Maximum price slippage for buy or sell orders.
stoploss - Stop loss level.
takeprofit - Take profit level.
comment - Order comment text. Last part of the comment may be changed by server.
magic - Order magic number. May be used as user defined identifier.
expiration - Order expiration time (for pending orders only).
arrow_color - Color of the opening arrow on the chart. If parameter is missing or has CLR_NONE value opening arrow is not drawn on the chart.

My Example: You have to send the order with Sl=0 && Tp=0. Then use order select loop and then order modify to set the Sl and Tp.
OrderSend(Symbol(),OP_BUY,1,Ask, iSlippage, 0, 0,"My order #2",16384,0,Green);
 
mathurpratik:
According to a post WHRoeder, I must send out a successful order first and then set my SL/TP. Is there any sample code that does this?
I Keep getting an error code 130 when I set the SL/TP with the OrderSend() function.
  1. I answered your question with code and an example (in the comment) I stated SL/TP AND slippage.
  2. So why this double post?
  3. I also stated on ECN brokers you must open first and THEN set stops
    int ticket = OrderSend(
    if (ticket < 0) Alert(
    else if (!OrderModify(
      Alert(

 
WHRoeder:
  1. I answered your question with code and an example (in the comment) I stated SL/TP AND slippage.
  2. So why this double post?
  3. I also stated on ECN brokers you must open first and THEN set stops

Ubzen, WHRoeder -

Thanks! Your comments were very helpful! I was able to finally send an order and set the stop loss / take profit (I could see the horizontal dotted lines on the candle chart).

I am noticing occasional errors saying "invalid stops".

I am using the following functions to set my stop levels. Can you let me know if you see a flaw in this logic? The "myPoint" variable is a constant set to 0.0001. Since the Point function always returns 0 for me I cannot use it and created "myPoint".

double normalizeBuySL(double pSL){
   RefreshRates();
   double min_dist = myPoint*MarketInfo(Symbol(),MODE_STOPLEVEL);
   
   if (pSL < (Bid - min_dist)){
      return (pSL);
   }
   
   return (Bid - min_dist);
}
double normalizeBuyTP(double pTP){
   RefreshRates();
   double min_dist = myPoint*MarketInfo(Symbol(),MODE_STOPLEVEL);
   
   if (pTP < (Bid + min_dist)){
      return (Bid+min_dist);
   }
   
   return (pTP);
}
double normalizeSellSL(double pSL){
   RefreshRates();
   double min_dist = myPoint*MarketInfo(Symbol(),MODE_STOPLEVEL);
   if (pSL > (Ask+min_dist)){
      return (pSL);
   }
   
   return (Ask+min_dist);
}
double normalizeSellTP(double pTP){
   RefreshRates();
   double min_dist = myPoint*MarketInfo(Symbol(),MODE_STOPLEVEL);
   
   if (pTP < (Ask - min_dist)){
      return (pTP);
   }
   
   return (Ask-min_dist);
}

So, for example, when I place a buy market order I want to also place the stop loss and take profit. To do that I would call

normalizeBuySL()

normalizeBuyTP()

Do you see any flaws in the code above? If so, how would I change it?

 
Shouldn't you be using MODE_FREEZELEVEL to determine your min_dist for your TP ?
 
RaptorUK:
Shouldn't you be using MODE_FREEZELEVEL to determine your min_dist for your TP ?

On IBFX (an ECN) freeze level is always zero, but you still can't place stops closer than stop level (30 points) nor modify orders if market is closer to tp/sl. I just use the max of both in my comparison.
 
WHRoeder:

On IBFX (an ECN) freeze level is always zero, but you still can't place stops closer than stop level (30 points) nor modify orders if market is closer to tp/sl. I just use the max of both in my comparison.
Thank you.
 
mathurpratik:
Since the Point function always returns 0 for me I cannot use it and created "myPoint".
  1. What function, Point is a predefined variable
    pips2dbl    = Point*10;
  2. Did you use doubleToStr to print it. Print defaults to 4 digits and point would be the 5th decimal.
    string  PriceToStr(double p){
        string pFrc = DoubleToStr(p, Digits);       if(Digits.pips==0) return(pFrc);
        string pPip = DoubleToStr(p, Digits-1);
        if (pPip+"0" == pFrc)       return(pPip);           return(pFrc);          }
    

Reason: