The strategy takes a calculated position from our trade logic, and then in IOG strategy automation (SA) mode (with multiple signals in the same direction allowed), we buy, sell, short, buy to cover depending the relationship between our target position we want, and the current chart position.
The code is shown below. Usually, for most of the trading day and most symbols running in different charts, no problems occur. It all trades as expected. But then once in a while (like once a day-- randomly), no trade is executed.
Code: Select all
intrabarpersist signal_Pos (0),
intrabarpersist t_marketPos (0);
signal_Pos = mytradelogic;
// Signal (delta) change in position is generated from my trade logic functions
t_marketPos = MarketPosition * CurrentContracts; // Current market position
if signal_Pos <> 0 then begin
if signal_Pos > 0 then begin
if t_marketPos <= 0 then begin
if absValue (t_marketPos) >= signal_Pos then begin
Buy to Cover ("SX-cover") signal_Pos Contracts Next Bar at Market;
Buy ("LE-new") (signal_Pos - absValue (t_marketPos)) Contracts Next Bar at Market;
end else begin
Buy ("LE-more") signal_Pos Contracts Next Bar at Market;
if signal_Pos < 0 then begin
if t_marketPos >= 0 then begin
if t_marketPos >= absValue (signal_Pos) then begin
Sell ("LX-cover") absValue (signal_Pos) Contracts Next Bar at Market;
Sell Short ("SE-new") (absValue(signal_Pos) - t_marketPos) Contracts Next Bar at Market;
end else begin
Sell Short ("SE-more") absValue (signal_Pos) Contracts Next Bar at Market;
I give an example of the debugging results we have when inserting print statements.
Before the if-then statements to decide what buy/sell commands to run, the variables are like this:
signal_Pos = -386 (shares of EWZ ETF) -- this is a delta of the position, or the number of shares that need to be bought or sold
t_marketPos = -1
1) As we enter the loop, if signal_Pos < 0 should evaluate to true
2) if t_marketPos >= 0 should evaluate to false
3) Sell Short ("SE-more") should execute
However, when we come out of this if-then statement, the chart position is still = -1. And it appears that Sell Short ("SE-more") signal never gets run.
signal_Pos = -386 (shares of EWZ ETF)
t_marketPos = -1
This doesn't happen for hundreds of trades on 1 minute charts for a long time. Even the same target position and current position values.
Then for some reason, a trade like this doesn't trigger in the chart. New ticks come in, but the conditional evaluation produces the same result. No change in the chart position, and seemingly no buy/sell commands executed on the chart.
It seems that the if-then conditions are not even evaluated correctly because the print statements in same begin-end segment of the buy/sell commands don't print out.
We're running MC version 8.0, the most recent release candidate.
As we go into the loop again and again, for sometimes about 1/2 hour of trades, the chart position never changes even with new signals. Then with some new trade signal (randomly), this starts working again.
Anyone come across this type of behavior?
Thanks in advance.