Gamestudio Links
Zorro Links
Newest Posts
Alternative to Stooq for Zorro S
by Petra. 10/14/26 07:04
ZorroGPT
by TipmyPip. 10/13/26 17:08
Stooq now requires an API key
by cwford. 10/08/26 23:27
Purchase A8 full licence version
by jcl. 10/05/26 12:12
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
2 registered members (TipmyPip, DonQuijote), 25,207 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
JimSimons, julienp, julienper, KelleyAbbey, Yopachi
19246 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
When Close zorro with (CTRL+ALT+SUP) shares position is lost #489700
Yesterday at 14:31
Yesterday at 14:31
Joined: Sep 2026
Posts: 4
M
mistery Offline OP
Guest
mistery  Offline OP
Guest
M

Joined: Sep 2026
Posts: 4
Hello! I am testing extreme failures and reaming, the issue:

1-Open script in trade mode (script buys and sell every 5 min, wait until zorro open a trade at 10:00 NY
2-At 10:02 NY i close zorro with (CTRL+ALT+SUP)
3-At 10:03 NY i open zorro in trade mode and then a second bought is made
4-At 10:05 NY zorro close just the second bought but not the first.

Question is: How to avoid this? There is a proper rearming step guide? I have to code new solution to avoid this, comparing Broker with zorro number of shares? My code is wrong?

I copy the code, it is not any trading strategy, it just for testing:






//CODE BELLOW

// AMZN intraday: invests NAV/3 in AMZN in fixed New York time windows
// Backtest starts with 100,000 USD. Live/demo uses the account equity.
// Robust version: tolerates missing 1-minute bars (acts on the next bar).

#define NWIN 6

// NY time NowMin
// 10:00 600
// 11:00 660
// 12:00 720
// 13:00 780
// 14:00 840
// 15:00 900
// 16:00 (close) 960
// New York time in minutes since midnight (10:00 = 600)

int BuyTime[NWIN] = { 600, 610, 620, 630, 640, 650};
int SellTime[NWIN] = { 605, 615, 625, 635, 645, 655};

// TODO Meter bucle aqui debajo
BuyTime [0] = 800;
SellTime [0] = 800;

// per-day state: what has already been done in each window
int Bought[NWIN];
int Sold[NWIN];
int LastMin = 0;

function run()
{
BarPeriod = 1;
LookBack = 0;
StartDate = 2023;
EndDate = 2024;
int i, NowMin, Shares;
var NAV;

set(LOGFILE, PLOTNOW); // must be inside run()
set(NFA); //IBKR need this to close

if(!is(TRADEMODE))
Capital = 100000;

if(is(INITRUN))
assetList("History\\TEST\\AssetsTest.csv");
asset("AMZN");

if(is(LOOKBACK)) return;

NowMin = lhour(ET)*60 + minute();
if(is(TRADEMODE))
printf("\nNowMin %d = %02d:%02d NY", NowMin, lhour(ET), minute());

// New day detected: NY time went backwards -> reset the flags
if(NowMin < LastMin || is(INITRUN))
{
for(i = 0; i < NWIN; i++) {
Bought[i] = 0;
Sold[i] = 0;
}
}
LastMin = NowMin;

for(i = 0; i < NWIN; i++)
{
// SELL: window was entered, sell time reached, not yet sold
if(Bought[i] && !Sold[i] && NowMin >= SellTime[i])
{
Sold[i] = 1;
if(is(TRADEMODE))
printf("\n%02i:%02i NY SELL all SHARES (%i open)",
lhour(ET), minute(), NumOpenLong);
exitLong();
}

// BUY: inside the window [BuyTime, SellTime), not yet bought today, flat
if(!Bought[i] && NowMin >= BuyTime[i] && NowMin < SellTime[i] && NumOpenLong == 0)
{
NAV = Equity; // cash + open trades
Shares = floor(NAV/3./priceClose());
if(is(TRADEMODE))
printf("\n%02i:%02i NY BUY NAV %.0f price %.2f shares %i",
lhour(ET), minute(), NAV, priceClose(), Shares);
if(Shares > 0) {
Bought[i] = 1;
Amount = Shares; // number of IWM shares
enterLong();
}
}

// window passed without a buy (e.g. no bars): mark it as done
if(!Bought[i] && NowMin >= SellTime[i])
Bought[i] = Sold[i] = 1;
}

if(NowMin > SellTime[NWIN-1] && NumOpenLong > 0) // safety: flat after 10:55
exitLong();

plot("NAV", Equity, NEW, BLUE);
}

Re: When Close zorro with (CTRL+ALT+SUP) shares position is lost [Re: mistery] #489702
15 hours ago
15 hours ago
Joined: Apr 2008
Posts: 603
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 603
Austria
For finding the reason of the bug, print your variables and the open trades after restarting. If you cannot find the bug, you can contact support and let them fix your script. As usual, if it is not a bug in your script, but a Zorro bug, the fix is free.

But you can easily test if it is really a Zorro bug by writing a simple 3-line script that just opens and closes positions.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1