Problem with 'ticket'

 

Hi there!


This is probably easy for you, but I don't see my mistake. So I would be glad if you could give me some relief! :)


In short:

I open a position:

int ticket = OrderSend(Symbol(),OP_BUY,10,Ask,5,Ask-10,Ask+10,"Long Order",1234,0,Green);

i want to close this position:

OrderClose(ticket,10,Bid,10,Red);

what I get:

Unknown ticket 1 for OrderClose function.


Thank you!! :)
 
  1. Since ticket is an int, not a static int, it won't be valid on the next tick
  2. Did you check that the orderSend worked? Ask-10 is a negative number on most pairs. Did you mean Bid - 10*pips2dbl? You open a buy at the Ask, the stops are relative to the Bid.
  3. OrderClose (,, 10, Bid .. won't be valid generally If you do an OrderSelect first you can OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), ...
  4. Your orderSend won't work on ECN broker and isn't adjusting for 4/5 digit brokers
  5. Post ALL the code - No mind readers here.
 

Thank you for your answer. Well, there isn't any code yet, I'm trying some things, just to check if I'm able to do something big ;) I just didn't manage to close a position.

1. I'll have to check that

2. Yes, I did. The parameters are not from my tests, just to make sure you see I filled every parameter ;)

3. What do you mean with that? Sorry, I'm not native English speaking, and I'm not sure where I should insert the commas here ;)

 
WHRoeder:

  1. ... You open a buy at the Ask, the stops are relative to the Bid.
This is an interesting comment. I have seen Raptor do the same thing. If the stop is how much you are willing to lose on the trade, as in "I am willing to lose 10 pips on this trade", then I would argue that you should use Ask throughout the Buy OrderSend. Otherwise you lose the 10 pips (of the stop) plus the spread on a bad trade. Now obviously you can change the stop to take into account the spread but that seems a more complicated way of doing it to my mind.
 

What I found now: The order is executed, I also see the line and the arrows on the chart. But it looks like the ticket variable is "0".


Does this information help a bit more?

 

Now I noticed something very interesting! The very first time I receive ticket=0; but only with the very first trade. The second trade gets the ticket 2. So ticket 1 is never issued. How is this possible?

Well i could check and check if ticket is 0 and change it to 1, but you see that this isn't the correct solution :D

 
dabbler:
This is an interesting comment. I have seen Raptor do the same thing. If the stop is how much you are willing to lose on the trade, as in "I am willing to lose 10 pips on this trade", then I would argue that you should use Ask throughout the Buy OrderSend. Otherwise you lose the 10 pips (of the stop) plus the spread on a bad trade. Now obviously you can change the stop to take into account the spread but that seems a more complicated way of doing it to my mind.
I think it depends on how your SL position is determined . . . my SL is determined by a Fib and my position size is determined by my risk and the position of my SL. It's a question of perspective I think, what is most important is that people understand the mechanics behind calculating entry and exit prices and how spread is involved . . . then they can code correctly to their needs.
 
dabbler:
This is an interesting comment. I have seen Raptor do the same thing. If the stop is how much you are willing to lose on the trade, as in "I am willing to lose 10 pips on this trade", then I would argue that you should use Ask throughout the Buy OrderSend. Otherwise you lose the 10 pips (of the stop) plus the spread on a bad trade. Now obviously you can change the stop to take into account the spread but that seems a more complicated way of doing it to my mind.

If the spread becomes more than 10 pips (your example) the OrderSend/OrderModify fails.

If you want the stop near MarketInfo(chart.symbol, MODE_STOPLEVEL) then you have to subtract the spread or it fails.

Yes you can think about it your way but then 10 pips is a variable stop on variable spread brokers and fixed stop on fixed spread broker. Shouldn't it be the same for all orders?

 
GoingForGold:

Now I noticed something very interesting! The very first time I receive ticket=0; but only with the very first trade. The second trade gets the ticket 2. So ticket 1 is never issued. How is this possible?

Well i could check and check if ticket is 0 and change it to 1, but you see that this isn't the correct solution :D

That would be a totally horrible and incorrect thing to do. It is far more probable that your MQL4 logic is wrong somewhere which is causing you to get a 0 ticket value. You see an invalid ticket would be -1 but if your ticket variable is not otherwise initialized it will be set to 0 by default. Without seeing your code it is a guessing game as to where you have gone wrong.
 

WHRoeder:

Yes you can think about it your way but then 10 pips is a variable stop on variable spread brokers and fixed stop on fixed spread broker. Shouldn't it be the same for all orders?

As usual I think about the problem backwards compared to you and Raptor -apparently :-(

"My way", when setting a 10 pip stop and trading $10/pip (in terms of lotsize) you would always see a loss of $100 (not counting swap and commission) regardless of the spread. Obviously it makes no difference in the great scheme of things because we would all be back test using whatever stop-setting method was encoded in our EAs.

As far as I am concerned it is you guys who are effectively using a variable stop when the spread is variable, and it is interesting that you see it the other way around :-)

But since you guys are evidently profitable doing it that way, it must be ok!

 
dabbler:

But since you guys are evidently profitable doing it that way, it must be ok!

LOL . . . who said that ? I'm still on my journey . . . not at my destination yet ;-)