• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 4:11am
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 4:11am
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

Closing Multiple Position By Magic Number 2 replies

Need Script/EA can only generate Magic number 5 replies

GBPUSD Magic Number 45 replies

Comment vs. Magic Number 2 replies

can we manually assign a magic number 4 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe

Ever seen this magic number bug?

  • Post #1
  • Quote
  • First Post: Jul 5, 2007 4:04am Jul 5, 2007 4:04am
  •  Ghamm
  • | Joined Jun 2007 | Status: Member | 107 Posts
Hi,
Ive got some code that creates orders. Im passing a magic number to it..
for some reason, when I call the function


OrderSelect(cnt,SELECT_BY_POS);
if (OrderMagicNumber() == MagicNumber)
Blah blah.


About half the time, it returns zero for the magic number.. Its like it wont store it..
Ive even tried a hard coded constant.. Still acts up.. I noticed the think in my CloseAllOrders routine.. It was only closing half of them..


Any Ideas??



Gordon
  • Post #2
  • Quote
  • Jul 5, 2007 4:25am Jul 5, 2007 4:25am
  •  Ghamm
  • | Joined Jun 2007 | Status: Member | 107 Posts
This is weird, but maybe by design..

If you close the orders from 0-x on the loop, it gives faulty results..

if you close the orders from top down, works perfect.. something about counting up, makes it get messed up..

Any idea why?
 
 
  • Post #3
  • Quote
  • Jul 5, 2007 4:35am Jul 5, 2007 4:35am
  •  BaasHarm!
  • | Joined May 2007 | Status: Selling Yen for a living | 80 Posts
Quoting Ghamm
Disliked
This is weird, but maybe by design..

If you close the orders from 0-x on the loop, it gives faulty results..

if you close the orders from top down, works perfect.. something about counting up, makes it get messed up..

Any idea why?
Ignored
I'm having a similar issue with deleting pending orders. Every so ofter my EA will delete all pending orders based on MagicNumber. But every now and then it "misses" an order, so instead of deleting all pending orders there is one left.
I've been staring at the code for weeks but can't find the issue. I'm 100% confident my code is correct (the same routines work flawless in other EA's)
But like you, my loop iterates from 0-i, I'll try to see if it works better counting down....
 
 
  • Post #4
  • Quote
  • Jul 5, 2007 5:47am Jul 5, 2007 5:47am
  •  Yannis
  • | Joined May 2004 | Status: Life is a beach | 24 Posts
Never encountered any issues when using the loop as follows, so this might help.

for (int cnt=OrdersTotal()-1;cnt>=0;cnt--)
{ ............
............
}

Yannis
 
 
  • Post #5
  • Quote
  • Last Post: Jul 5, 2007 11:54am Jul 5, 2007 11:54am
  •  tesla
  • Joined Oct 2006 | Status: Friendly Neighborhood Programmer | 533 Posts
There's a reason counting up when iterating orders is a bad idea.

Assume you have five open orders (A,B,C,D,E and they're in that order)
Let's see what happens if you need to close orders B & C

Iterating up...
Examine order at position 0 (Order A), no action, continue
Examine order at position 1 (Order B), close the order
Examine order at position 2 (Order D).

Confused as to why order D is at position 2? That's because order B has been deleted and your order position now looks like this:
A = 0
C = 1
D = 2
E = 3

Look at this for a bit and if you still have questions post 'em.
 
 
  • Platform Tech
  • /
  • Ever seen this magic number bug?
  • Reply to Thread
0 traders viewing now
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2022