|
OrderSend(Symbol(),OP_BUY,1,Ask, iSlippage, 0, 0,"My order #2",16384,0,Green);
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 answered your question with code and an example (in the comment) I stated SL/TP AND slippage.
- So why this double post?
- 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(
- I answered your question with code and an example (in the comment) I stated SL/TP AND slippage.
- So why this double post?
- 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 ?
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.
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.
Since the Point function always returns 0 for me I cannot use it and created "myPoint".
- What function, Point is a predefined variable
pips2dbl = Point*10;
- 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); }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.