* Multicharts version 8.0 build 5620
* Broker is IB
* using live simulated trading
* symbol = ES
The strategy submits limit orders with price levels given by the variables buyLevel and sellLevel. The actual orders that get placed are using values of these variables for a previous bar and not the latest as calculated at the close of the bar. Those levels should be active for the next bar. In other words its almost like its using buyLevel[1] and sellLevel[1]. Below is a strategy that I created to illustrate the issue. If you run this with the setup as described and compare the output of the print statement with the order price levels in IB or in the Order and Position Tracker for that matter, you will see what I mean.
Code: Select all
[IntrabarOrderGeneration = True]
variables: intrabarpersist int statusOfBar_data1(0), intrabarpersist int statusOfBar_data2(0),
intrabarpersist double avgBarRange(0.0), intrabarpersist double sellLevel(0.0),
intrabarpersist double buyLevel(0.0), intrabarpersist bool isInitialized(false);
// barstatus of data1 and data2
statusOfBar_data1 = barstatus(1);
statusOfBar_data2 = barstatus(2);
// calculate buy and sell limit levels
if statusOfBar_data1 = 2 then begin
avgBarRange = XAverage(high-low,5);
sellLevel = close + (2*avgBarRange);
buyLevel = close - (2*avgBarRange);
isInitialized = true;
end;
if (getappinfo(aiRealTimeCalc) > 0) then
print("time_s(of data2)=",(time_s of data2),", barstatus(1)=",statusOfBar_data1,", barstatus(2)=",statusOfBar_data2,", buyLevel=",buyLevel,", sellLevel=",sellLevel);
// submit orders
if isInitialized then begin
buy("buy(1)") next bar at buyLevel limit;
sellshort("sell(1)") next bar at sellLevel limit;
end;
https://www.multicharts.com/pm/viewissu ... _no=MC-235
Or am I missing something in the code above?