| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| Execute Function when OrdersTotal() = N https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=4658 |
Page 1 of 1 |
| Author: | desmondc [ Sun Mar 20, 2016 3:48 pm ] |
| Post subject: | Execute Function when OrdersTotal() = N |
I know what I am want to do and I know that I am almost there, but I cant see what I am missing. Please help.. been at this for hours. It must be something simple .. must be!! Argh~!! Objective: 1) Have the function only execute at ever new bar not every tick to reduce CPU logic 2) Close all position when all active open order is at n count (e.g. OrdersTotal()=3) Problem: When adding if ( varOrderCount = 3), i notice that my function funcCloseAll() keeps getting executed at every bar. What i expect is that it would execute every 3rd bar. Code without Condition Code: Select all FailedCodeSnip Code: Select all |
|
| Author: | SteveHopwood [ Sun Mar 20, 2016 8:46 pm ] |
| Post subject: | Execute Function when OrdersTotal() = N |
The chances of trading volume being <= 1 are remote even at the open of a new candle. Thinking about it, and playing from memory here, it takes a ridiculous number of trades to be placed at the same time to generate a tick, so the chances are actually zero. Instead, use a construct like this: Code: Select all |
|
| Author: | desmondc [ Mon Mar 21, 2016 6:00 pm ] |
| Post subject: | Execute Function when OrdersTotal() = N |
Hey Steve.. I'll guess you are right. i notice that there will be times a new bar has no entry; if what i understand from your post.. this does mean that there was a certain vol for that bar at that time which is why no entry was executed. Will look at the time based entry later.. ~~~ To update this thread, i did find a solution to my problem. In summary since I can't get seem to get the if condition to work direclty with OrderTotal() what I did was get a loop to pull out that figure for my IF condition. Its stupid but hell as long as we get the result we want.. Code: Select all |
|
| Author: | renexxxx [ Tue Mar 22, 2016 12:55 am ] |
| Post subject: | Execute Function when OrdersTotal() = N |
Your code is both faulty, inefficient and ineffective. I get goosebumps even looking at it: Faulty because there is no function OrderTotal(). You probably mean OrdersTotal(). Inefficient as OrdersTotal() is re-evaluated for every iteration in the loop. If you want to iterate over the open-orders cursor in chronological order use: Code: Select all Code: Select all Code: Select all Ineffective As I don't think you achieve what you have set out to do, and the above code is good to know but has nothing to do with what you want. The requirement is to execute a function when OrdersTotal() has reached a set number (N). So, presumably, there is another thread (may be the same thread) or process that is opening trades. You just need to add somewhere in your OnTick() or OnTimer() thread the following code: Code: Select all Note, that OrdersTotal() returns all active orders on the account, including pending orders and orders with different magic numbers (manual orders have MagicNumber == 0 ). So, if you want to execute the required function only when the total of your orders equal or exceed N, you'd need to do something like: Code: Select all |
|
| Author: | desmondc [ Tue Mar 22, 2016 2:48 am ] |
| Post subject: | Execute Function when OrdersTotal() = N |
Hey Renexx.. Many thanks. Sorry about the code, I had to look at another computer screen and type it in to another. Hence I only put in what is enough to show my work around.. I'll give a try on your example and see how much I can tweak it to what i need.. Again.. Many thanks. |
|
| All times are UTC | Page 1 of 1 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|