Hey everyone,
I'm working on an Expert Adviser for a grid trading system. My bug is somewhere in the initialization.
I have a number of grid sectors numbered from 0-63 each 50 pips wide. Upon the first run of the expert, I want to place a limit order at each grid line, with the lower half being BUY_LIMIT and the upper half SELL_LIMIT. The problem is some of the trades return from OrderSend() with error 130 (bad stops). I understand what the error means, but my code gives the same stop margin to each trade, and the opening price is in many cases nowhere near the market price. So I'm a bit confused as to why the error occurrs to some trades and not others.
I've run my code on IBFX Demo Strategy Tester on a number of different currency pairs with in a number of different timeframes, and there is always a group of 3+ trades that succumb to error 130. The default grid values in my code are for AUDNZD in the first two weeks of January, 2009. (I've been using a 1 hour timeframe, but I'm really only concerned with the outcome of the first bar).
I've attached the code below. I've isolated the bugged code to make it easier for you to read. The broken function is "openPendingTrades"
I'm going to try testing this in real time demo, but I anticipate the same problem will happen, unless this is specifically a bug in the Strategy Tester.
I appreciate any help you can lend.
I'm working on an Expert Adviser for a grid trading system. My bug is somewhere in the initialization.
I have a number of grid sectors numbered from 0-63 each 50 pips wide. Upon the first run of the expert, I want to place a limit order at each grid line, with the lower half being BUY_LIMIT and the upper half SELL_LIMIT. The problem is some of the trades return from OrderSend() with error 130 (bad stops). I understand what the error means, but my code gives the same stop margin to each trade, and the opening price is in many cases nowhere near the market price. So I'm a bit confused as to why the error occurrs to some trades and not others.
I've run my code on IBFX Demo Strategy Tester on a number of different currency pairs with in a number of different timeframes, and there is always a group of 3+ trades that succumb to error 130. The default grid values in my code are for AUDNZD in the first two weeks of January, 2009. (I've been using a 1 hour timeframe, but I'm really only concerned with the outcome of the first bar).
I've attached the code below. I've isolated the bugged code to make it easier for you to read. The broken function is "openPendingTrades"
I'm going to try testing this in real time demo, but I anticipate the same problem will happen, unless this is specifically a bug in the Strategy Tester.
I appreciate any help you can lend.
Attached File(s)