| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| Order Select Question? https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=1296 |
Page 1 of 1 |
| Author: | ewinner [ Mon Dec 10, 2012 3:48 pm ] |
| Post subject: | Order Select Question? |
Hi Guys, Im having a bit of trouble with some code and going round and round in circles!!!! any help much appreciated before i go totally mad!! What im trying to do, is check to see if there is an open order already, before it sends another order at the same price (yes, im working on a grid trader!!) The code i have come up with so far finds the last order OrderOpenPrice ok, but i need it to find an order if it exists with the same price, NOT just the last one placed - make any sense?? Thanks for any help Mark Code: Select all |
|
| Author: | dietcoke [ Mon Dec 10, 2012 7:47 pm ] |
| Post subject: | Re: Order Select Question? |
The same price as what?? Your code does not mention any price except the last order price. The code you have posted might tell you the price of the last buy trade but you are relying on the order history being in the right order (not always true in Empty4). If you are programming grid system, I presume you are either placing trades a fixed distance apart or using an algorithm of some sort to determine where the next trade is to be placed. Your function needs to know what price to compare the order open price with. Perhaps your function rather than returning true/or false should be a double and return the last orderopenprice or zero if there is none. You can then calculate where the next order should be based on that price and see if the bid has reached that level yet. I would also suggest it is dangerous to try and compare an open order with a price as if the there is a single digit difference in the two decimals the result will be false. Comparing supposedly identical double values is fraught with that sort of difficulty |
|
| Author: | ewinner [ Mon Dec 10, 2012 8:09 pm ] |
| Post subject: | Re: Order Select Question? |
Hi Dietcoke, Thanks for your reply. I think im getting myself a little confused here, as to how to go about this...! Heres an example of what im trying to do: Bid gets to 1.30000 BUYSTOP order sent at 1.30100 BUYSTOP order fills Bid retraces to 1.29900 Bid moves back to 1.30000 BUYSTOP order sent AGAIN at 1.30100 Its at the last stage where it opens another order at 1.30100 <<< This is what im trying to stop >>> Before it sends the order, i want it to check all open orders, if an order already exists at that price it doesn't send the order. That is why i was trying to use the last OpenOrderPrice, but your right about the order history not being in order, ive found that out today!!! sure is Empty4! Thanks for your tips, ill give it a rethink tonight Cheers Mark |
|
| Author: | SteveHopwood [ Mon Dec 10, 2012 10:31 pm ] |
| Post subject: | Re: Order Select Question? |
Welcome to my world Mark. I spend most of my life going round in the sort of circles you have been running today. I would solve the problem by using a grid of lines on the chart, with properties that can alter as they are passed and which will tell the ea whether to send a trade or not. So, taking buys as an example, I would define some constants at the start of my code: #define buyline0 "Buy line 0" #define buyline1 "Buy line 1" . . . . . #define buyline10 "Buy line 10" or however many buy lines my grid required. Then I would say to myself, "Ok, if a line is passed, the ea will send a trade and delete the line so it will not be traded again." Then I have this function: Code: Select all DrawHorizontalLine(buyline0, 1.30000, green, STYLE_SOLID, 0) DrawHorizontalLine(buyline1, 1.30100, green, STYLE_SOLID, 0) DrawHorizontalLine(buyline2, 1.30200, green, STYLE_SOLID, 0) etc Then, when the market crosses buyline(x) and the trade send is successful (whole can of worms there but I assume you are on top of that) use ObjectDelete(buyline0) to delete the line so it cannot be traded twice. Ok, so some detail missed out of this but I assume you can work out a few thingies for yourself. Also, not saying that mine is necessarily the best approach. It is the one I would take. |
|
| Author: | ewinner [ Mon Dec 10, 2012 10:38 pm ] |
| Post subject: | Re: Order Select Question? |
Thanks Steve, thats a really cool approach...... ill have another look at it tomorrow when ive cooled down Cheers Mark |
|
| Author: | f-trader [ Fri Dec 14, 2012 12:42 pm ] |
| Post subject: | Re: Order Select Question? |
Another way to find an already existing order at the price-level: Code: Select all you should not compare prices like it is done in the code above but use buffer-distance. Something like Code: Select all which is available for free here: https://sites.google.com/site/prof7bit/common_functions I use it in all of my EAs. |
|
| Author: | ewinner [ Fri Dec 14, 2012 4:25 pm ] |
| Post subject: | Re: Order Select Question? |
Thanks f-trader, really useful info, new there had to be a way, just hadn't found it!!! Your a star! Much appreciated. Have a Great Christmas Mark |
|
| All times are UTC | Page 1 of 1 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|