Entry from Fibonacci

 

Hello,

I want to send pending order with entry price value from Fibonacci.

 double p1,p2,tp1,tp2,tp3;
 p1=ObjectGet(FibName,OBJPROP_PRICE1);        //100% fib price
 string sp1=DoubleToStr(p1,5);                // price to string
 p1=NormalizeDouble(StrToDouble(sp1),5);      //string to double
 p2=ObjectGet(FibName,OBJPROP_PRICE2);       //0 % fib price
 string sp2=DoubleToStr(p2,5);                // price to string
 p2=NormalizeDouble(StrToDouble(sp2),5);      //string to double
 tp2=(p2-p1)*0.382+p1;                        //61.8 fib price
 OrderSend(Symbol(),OP_BUYLIMIT,0.03,tp2,3,0,0);

I got this error: fibo1 EURUSD,H1: invalid price 1.26993234 for OrderSend function

What is wrong here, that tp2 isn't with 5 digits?
Thank you.

 

" What is wrong here, that tp2 isn't with 5 digits? "
.

Nothing tp2 is not 5 digit so price 1.26993234 is correct

0.00001 * 0.001 = 0.00000001 (5 digits * 3 digits ==> 8 digit answer)

 
Try:
OrderSend(Symbol(),OP_BUYLIMIT,0.03,NormalizeDouble(tp2, Digits),3,0,0);
Might want to check tp2 is not too close to the current ask price for buy limit. Brokers have different limits
 
deVries:

" What is wrong here, that tp2 isn't with 5 digits? "
.

Nothing tp2 is not 5 digit so price 1.26993234 is correct

0.00001 * 0.001 = 0.00000001 (5 digits * 3 digits ==> 8 digit answer)


Thanks, I added this, and now works fine.

tp2=NormalizeDouble(tp2,5);

 
  1. Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a cludge, don't use it.Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum
    Can price != price ? - MQL4 forum
  2. On Currencies, Point=TickSize, so you will get the same answer. It won't work on Metals.
  3. I suspect that either the market was to close (MarketInfo(analyze.pair, MODE_STOPLEVEL)*Point) or more likely, his price was above the market and he's using a BUY_LIMIT
  4. Also not adjusting slippage for 4/5 digit brokers.
 
Eggo:

Thanks, I added this, and now works fine.

tp2=NormalizeDouble(tp2,5);

Not always.....

See comment above from WHRoeder think it fails on point 3

And if you think I have to use normalizeDouble then don't use it this way but as

tp2=NormalizeDouble(tp2,Digits);
 

Well I found one case were using NormalizeDouble helped. My history data had decimal places on its Bid and Ask values that were considered illegal when sending orders. Downloading new history values did not seem to help.

Reason: