Yesterday, again, started crazy orders for which I cannot give a clear explanation. It's already the third time it happens... unfortunately with real money
In backtest all run perfectly!
I don't know if the problem is produced by my scripts or by my bank interface plugin or something else. I am grooping in the dark so any idea will be really appreciated..
Yesterday my script, which is not turned on for autotrading, entered correctly short @9:04am. If during day it doesn’t reach the profit target or stop loss, it exits from the position forcedly at the end of daily session around 5:30pm. It doesn’t execute the orders directly and autotrading mode is not anabled. It only runs on the chart and sets a global variable GVSetNamedInt (obtained by currentposition*marketposition) and then this GV is passed to another script, with autotrading turned on, and this second script decides to entry or exit position or to stay flat by checking the differences between marketoprdeposition_atBroker and the GV passed from the first script. To place an order it uses Placemarketorder .
When it reached the end of daily session (about 5:30pm) the first and not trading script closed the short position and transferred the value by GV to the real trading script but as you can see below a lot of orders buy and sell ware sent (attached in the "order and position tracker" output including orders, position history and log).
I also attach two printscreens and the code for the generating script and the second script for autotranding:
first script (no autotrade):
Code: Select all
[intrabarordergeneration=true]
....
....
//Profit target
if marketposition=1 then if (close this bar/entryprice-1) >= PT_perc_long then Sell ("BB_PT_Long") next bar at open;
if marketposition=-1 then if (entryprice/close this bar-1) >= PT_perc_short then buytocover ("BB_PT_Short") next bar at open;
//Stop Loss
if marketposition=1 then if (entryprice-close this bar) >= SL_Long then Sell ("BB_SL_Long") next bar at open;
if marketposition=-1 then if (close this bar-entryprice) >= SL_Short then buytocover ("BB_SL_Short") next bar at open;
IF time = 1734 and marketposition=1 then Sell ("ForceFinalLong") next bar at open ;
if time = 1734 and marketposition=-1 THEN buytocover ("ForceFinalShort") next bar at open;
GVSetNamedInt("GV_1", currentcontracts*marketposition);
second script (autotrading AA):
Code: Select all
[IntrabarOrderGeneration=True]
var: mp(0), GV_1(0), GV_2(0), GV_3(0), Result(0), ;
mp = MarketPosition_at_Broker;
GV_1=GVGetNamedInt("GV_1", -999);
GV_2=GVGetNamedInt("GV_2", -999);
GV_3=GVGetNamedInt("GV_3", -999);
Result=GV_1+GV_2+GV_3;
if mp=2 and mp<>Result then Begin
if Result=1 then PlaceMarketOrder(false, false, 1);
if Result=0 then PlaceMarketOrder(false, false, 2);
if Result=-1 then PlaceMarketOrder(false, true, 3);
if Result=-2 then PlaceMarketOrder(false, true, 4);
End;
if mp=1 and mp<>Result then Begin
if Result=2 then PlaceMarketOrder(true, true, 1);
if Result=0 then PlaceMarketOrder(false, false, 1);
if Result=-1 then PlaceMarketOrder(false, true, 2);
if Result=-2 then PlaceMarketOrder(false, true, 3);
End;
if mp=0 and mp<>Result then Begin
if Result=2 then PlaceMarketOrder(true, true, 2);
if Result=1 then PlaceMarketOrder(true, true, 1);
if Result=-1 then PlaceMarketOrder(false, true, 1);
if Result=-2 then PlaceMarketOrder(false, true, 2);
End;
if mp=-1 and mp<>Result then Begin
if Result=2 then PlaceMarketOrder(true, true, 3);
if Result=1 then PlaceMarketOrder(true, true, 2);
if Result=0 then PlaceMarketOrder(true, false, 1);
if Result=-2 then PlaceMarketOrder(false, true, 1);
End;
if mp=-2 and mp<>Result then Begin
if Result=2 then PlaceMarketOrder(true, true, 4);
if Result=1 then PlaceMarketOrder(true, true, 3);
if Result=0 then PlaceMarketOrder(true, false, 2);
if Result=-1 then PlaceMarketOrder(true, false, 1);
End;
Of course,as you can see, in the Log a lot of 3CAS and 3DUP and LRE messages from bank plugin I received to alert me about insufficinet fund (luckily ) and repetitive attempts to cancel orders.
I can provide further details.
Thank you
auato