Gamestudio Links
Zorro Links
Newest Posts
folder management functions
by 7th_zorro. 04/16/24 13:19
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
LPDIRECT3DCUBETEXTUR
E9

by Ayumi. 04/12/24 11:00
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 04/11/24 14:56
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (7th_zorro), 442 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
11honza11, ccorrea, sakolin, rajesh7827, juergen_wue
19045 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
New to Zorro and getting tripped up on some fundamental things #487253
02/25/23 05:12
02/25/23 05:12
Joined: Feb 2023
Posts: 10
S
ShawnM Offline OP
Newbie
ShawnM  Offline OP
Newbie
S

Joined: Feb 2023
Posts: 10
Hello all, I just discovered Zorro and I'm pretty excited about what I've found. I'm testing scripts and things out slowly and deliberately and just taking my time to observe how things behave. I've run into some hurdles however on some seemingly basic and fundamental things. I've started out with a very very basic script with no frills just to check out if everything I'm doing is correct:

Code
function run() 
{
   StartDate = 20221012;
   EndDate = 20221013;
	
   StartMarket = 1430; // 2:30pm UTC equals 9:30am EST?
   EndMarket = 2200;   // 10:00pm UTC equals 5:00pm EST?
   
   MaxLong = 1;
   Fill = 0;
   Slippage = 0;
   Penalty = 0;
   Stop = 10;
   TakeProfit = 20;

   BarPeriod = 5;
   asset("US30");
	
   var r = random();
   if (r >= .90) enterLong();
}



In my silly little test script, I just want to enter long in the Dow US30 at random times (basically 1 out of every 10 bars) on a 5 minute chart over a couple of days data only. I'm getting tripped up on a few things though:

(1) When I run the backtest, I do not get any trades listed out in the appropriate file in my LOG folder (even though my backtest does successfully produce trades, about 30 or so)... please see attached screenshot zorro-1. Maybe I'm not even looking in the right place? I did read how there's file-writing issues when you install Zorro to folders that have a "space" in the directory name... like "Program Files". So I just used what the installation default gave and installed to my "Users" folder (I'm using Windows 10).

(2) I wish to backtest only during Regular Session Hours (plus 1 additional hour) of the NYSE (ie. 9:30am EST till 5:00pm EST). I'm using the freely provided Forex/CFD data from the Zorro website and I do understand that it is all in UTC time, so I made what I thought is the appropriate adjustments to "StartMarket" and "EndMarket" in order to hone in on only the data I want. It doesn't seem to make any difference however, as my strategy still places trades outside of these hours as you can see in attached screenshot zorro-2 (easiest to see are trades at 01:00 through 04:00 on Oct 13). Should the chart even display data at all from outside my desired hours? I guess there must be something more to it than simply setting StartMarket/EndMarket in the script, I would gather.

(3) My strategy has a simple takeprofit of 20 points and stoploss of 10 points, and in eyeballing the backtest trades from the "Results" chart, most seem bang on, except for a few occurrences where a trade will get stopped out at only 5 points, as you can see in the attached screenshot zorro-3 below. Puzzled as to why.


So a few basic things causing me to get off to a bit of a sputtering start here. I think once I get these basic things ironed out however, I ought to really be able to start cruising and get proper work done.

Thanks to all!
ShawnM

Attached Files zorro-1.jpgzorro-2.jpgzorro-3.jpg
Re: New to Zorro and getting tripped up on some fundamental things [Re: ShawnM] #487254
02/25/23 08:12
02/25/23 08:12
Joined: Feb 2016
Posts: 15
Russia
nsg Offline
Newbie
nsg  Offline
Newbie

Joined: Feb 2016
Posts: 15
Russia
Hi, welcome to the Zorro community!

(1) You need to set the LOGFILE flag for Zorro to generate the trade log. Manual entry: https://zorro-project.com/manual/en/mode.htm

Code
function run() 
{
set(LOGFILE);
...
}


(2) StartMarket and EndMarket work only when the appropriate BarMode is set. You need to use BarMode = BR_MARKET. Again, when it doubt, it's a good to cosult the manual: https://zorro-project.com/manual/en/barmode.htm

Code
function run() 
{
...
BarMode = BR_MARKET;
StartMarket = 1430; // 2:30pm UTC equals 9:30am EST?
EndMarket = 2200;   // 10:00pm UTC equals 5:00pm EST?
...
}


Note that BarMode affects bar processing. A better idea might be to use date and time functions: https://zorro-project.com/manual/en/month.htm

(3) By using Stop = 10 and TakeProfit = 20 you're setting your SL and TP to $10 and $20. Use Stop = x*PIP for setting pip values. Manual: https://zorro-project.com/manual/en/stop.htm

Re: New to Zorro and getting tripped up on some fundamental things [Re: nsg] #487257
02/26/23 05:34
02/26/23 05:34
Joined: Feb 2023
Posts: 10
S
ShawnM Offline OP
Newbie
ShawnM  Offline OP
Newbie
S

Joined: Feb 2023
Posts: 10
Thank you so much NSG for the response. I actually have indeed referred a fair bit to the manual, and also watched the training video series at www.robotwealth.com. I was still stumped by the problems I encountered... thank you very much for your assistance. After your suggested fixes, a few puzzling issues still arise though:


"(1) You need to set the LOGFILE flag for Zorro to generate the trade log. Manual entry: https://zorro-project.com/manual/en/mode.htm"


Ahh okay... this indeed created the files. I had wrongly assumed the LOGFILE was for only tracing purposes and the standard output file of trades would always be written. But still though, the ".htm" version of the trades listing file is empty, as you see in zorro-1.jpg screenshot from my initial post. Is this normal?


"(2) StartMarket and EndMarket work only when the appropriate BarMode is set. You need to use BarMode = BR_MARKET. Again, when it doubt, it's a good to cosult the manual: https://zorro-project.com/manual/en/barmode.htm"


Thanks NSG, but this doesn't seem to be behaving quite right, I'm afraid. Please see the attached screenshot zorro-4 with comments on it. And you can see more evidence of this in my attached screenshot zorro-5 of my .log file.


"(3) By using Stop = 10 and TakeProfit = 20 you're setting your SL and TP to $10 and $20. Use Stop = x*PIP for setting pip values. Manual: https://zorro-project.com/manual/en/stop.htm"


This part is actually working correctly... it is indeed using 10 pts as my stop and 20 pts as my profit target (1 point=$5). I think since my instrument (Dow US30) is 1 full point for 1 pip, that it does not make any difference in this case. I can use Stop = 10*PIP and there is no change in behaviour.
But one thing I noticed in the log file (see again screenshot zorro-5), is that it says I am risking 50 p, when in fact I am risking 10 p ($50). The trades evaluate correctly, but I am curious why it would say this. My entry in the AssetsFix.csv file for this instrument is as follows:

US30,25319,0,0.6794,-1.3588,1,5,-1,0,1,0,US30/USD

(you will notice I took out slippage, spread, and commission values. During my initial testing, it's easier to evaluate things this way).


Thanks very much!
ShawnM

Attached Files zorro-4.jpgzorro-5.jpg
Re: New to Zorro and getting tripped up on some fundamental things [Re: ShawnM] #487258
02/26/23 06:27
02/26/23 06:27
Joined: Feb 2023
Posts: 10
S
ShawnM Offline OP
Newbie
ShawnM  Offline OP
Newbie
S

Joined: Feb 2023
Posts: 10
Dear NSG, an update please to my last post where I wrote:


"(2) StartMarket and EndMarket work only when the appropriate BarMode is set. You need to use BarMode = BR_MARKET. Again, when it doubt, it's a good to cosult the manual: https://zorro-project.com/manual/en/barmode.htm"

Thanks NSG, but this doesn't seem to be behaving quite right, I'm afraid. Please see the attached screenshot zorro-4 with comments on it. And you can see more evidence of this in my attached screenshot zorro-5 of my .log file.


Well, I tried loading in a couple of different days for history data (20221122 and 20221123), and none of those above problems occurred! Everything looked perfect, StartMarket and EndMarket times all looked fine on the chart - I even checked it against the 5 min chart of the same instrument (DJI) on Tradingview and it all matches up. I don't know why those other 2 days of history from Oct 2022 looked so weird, but all is okay now... so please disregard item (2) in my last post!

NSG, one other thing I noticed while reviewing my backtest trades, was that one of them hit a profit of $160. TakeProfit was set at 20 points ($100) so this is strange why this happened. See attached screenshot zorro-6 where I have red arrows pointing to the entry and exit of the trade. Is it possible that in the higher-resolution 1 minute bar data, there was a gap up, or very quick move up, that caused my exit to happen at an unexpectedly higher price? All the other 28 trades of my backtest evaluated as expected (either $50 stopped out or $100 profit target).

Thank You!
ShawnM

Attached Files zorro-6.jpg
Re: New to Zorro and getting tripped up on some fundamental things [Re: ShawnM] #487259
02/26/23 06:51
02/26/23 06:51
Joined: Feb 2016
Posts: 15
Russia
nsg Offline
Newbie
nsg  Offline
Newbie

Joined: Feb 2016
Posts: 15
Russia
You're welcome Shawn. Zorro is a great piece of software. It certainly involves some learning curve, but once you understand the basics, it'll become easier to explore it further.

(1) The ".htm" report is used only in the trade mode, i.e. when your Zorro instance is connected to either real or demo brokerage account. It tracks your system's equity curve, lists active trades and collects trading statistics similar to the perofrmance report. You can make the page visible to the web and check it with your smartphone anytime. This is the whole idea.
For "offline" testing and training refer to the both trade log and performance report. And maybe even some customly-exported stuff :-)

(2) This is what I meant by "bar processing" in my previous reply. I personally use BarMode only in trade mode when a broker can't adequately handle offline hours and returns flat bars when the market is inactive. This way, messing up indicators' inputs. Really, try using datetime functions instead prepending your entry logic with another if statement. It'll be much more straightforward this way. And ask for help if it's needed.

(3) I dunno :-) Maybe the folks from the development team will be willing to shed some light.

Regards,
nsg

Re: New to Zorro and getting tripped up on some fundamental things [Re: ShawnM] #487260
02/26/23 07:18
02/26/23 07:18
Joined: Feb 2016
Posts: 15
Russia
nsg Offline
Newbie
nsg  Offline
Newbie

Joined: Feb 2016
Posts: 15
Russia
Quote

NSG, one other thing I noticed while reviewing my backtest trades, was that one of them hit a profit of $160. TakeProfit was set at 20 points ($100) so this is strange why this happened. See attached screenshot zorro-6 where I have red arrows pointing to the entry and exit of the trade. Is it possible that in the higher-resolution 1 minute bar data, there was a gap up, or very quick move up, that caused my exit to happen at an unexpectedly higher price? All the other 28 trades of my backtest evaluated as expected (either $50 stopped out or $100 profit target).


Yeah, my best bet is that the slippage played in your favor here. Check the "slp" value in the performance report. It should be positive and high enough.
From my experience, I wouldn't be much excited about it as in real trading slippage tends to be negative even though Zorro simulates a positive one.

Re: New to Zorro and getting tripped up on some fundamental things [Re: ShawnM] #487262
02/26/23 21:34
02/26/23 21:34
Joined: Feb 2023
Posts: 10
S
ShawnM Offline OP
Newbie
ShawnM  Offline OP
Newbie
S

Joined: Feb 2023
Posts: 10
Thank you for all of this help NSG... but as I examine individual backtest trades closer, there is something just not right. Please look at attached screenshot zorro-7. In the trade I circled in red, it didn't exit at the 20 point profit target and instead employed a "Trail" stop... yet I do not specify any trail stop in my strategy code (as you see in my first post). I only use a straight stop loss and a profit target. However the .log file shows "Trail" for that trade. Here is the portion of the log file that shows it (with some entries of before and after):

Code
[314: Tue 22-11-22 18:55] (34022.32)
[315: Tue 22-11-22 19:00] (34015.32)
[US30::L31504] Long 1@34015.32 Risk 50 p at 19:00:00
[US30::L31504] Stop 1@34005.32: -50.00 at 19:05:00

[316: Tue 22-11-22 19:05] -50.00 0 3/7 (34019.82)
[317: Tue 22-11-22 19:10] (33993.32)
[318: Tue 22-11-22 19:15] (33997.82)
[319: Tue 22-11-22 19:20] (34020.32)
[US30::L31904] Long 1@34020.32 Risk 50 p at 19:20:00

[320: Tue 22-11-22 19:25] -20.00 +30.00 4/7 (34026.32)
[US30::L31904] Trail 1@34020.32 Stop 34016.32 at 19:30:00                 <<<<<<<<<< Trail stop ????

[321: Tue 22-11-22 19:30] 20.00 +70.00 4/7 (34034.32)
[US30::L31904] Stop 1@34024.32: +20.00 at 19:35:00

[322: Tue 22-11-22 19:35] -30.00 0 4/7 (34014.82)
[US30::L32204] Long 1@34014.82 Risk 50 p at 19:35:00
[US30::L32204] TP 1@34034.82: +100 at 19:40:00

[323: Tue 22-11-22 19:40] 70.00 0 5/7 (34045.32)



The corresponding entry in the "testtrades.txt" file shows this:

MyCont1Test,Long,US30,31904,1,2022-11-22 19:20,2022-11-22 19:35,34020.32,34024.32,+20.00,0.00,Stop


It's very unsettling for a new user... it looks like Zorro does things that my strategy never specifies at all.


Thank You
ShawnM

Attached Files zorro-7.jpg
Re: New to Zorro and getting tripped up on some fundamental things [Re: ShawnM] #487266
02/27/23 15:42
02/27/23 15:42
Joined: Apr 2008
Posts: 585
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 585
Austria
A message with "Trail" always means that the stop was moved. Check where your script is doing that. If it's unintended, it might also cause other bugs.

Re: New to Zorro and getting tripped up on some fundamental things [Re: Petra] #487269
02/28/23 03:52
02/28/23 03:52
Joined: Feb 2023
Posts: 10
S
ShawnM Offline OP
Newbie
ShawnM  Offline OP
Newbie
S

Joined: Feb 2023
Posts: 10
Thank you for your input Petra, but my very basic script just uses a simple stoploss with a set value, and doesn't move it. Here is the code:


Code
function run() 
{
   StartDate = 20221012;
   EndDate = 20221013;
	
   StartMarket = 1430; // 2:30pm UTC equals 9:30am EST?
   EndMarket = 2200;   // 10:00pm UTC equals 5:00pm EST?
   
   MaxLong = 1;
   Fill = 0;
   Slippage = 0;
   Penalty = 0;
   Stop = 10;
   TakeProfit = 20;

   BarPeriod = 5;
   asset("US30");
	
   var r = random();
   if (r >= .90) enterLong();
}



Thank You!
ShawnM

Re: New to Zorro and getting tripped up on some fundamental things [Re: ShawnM] #487273
03/01/23 10:19
03/01/23 10:19
Joined: Apr 2008
Posts: 585
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 585
Austria
I meant the script where you had a "Trail" problem with. The script that you posted does not trail. It does not even create a log.

Re: New to Zorro and getting tripped up on some fundamental things [Re: ShawnM] #487275
03/01/23 20:12
03/01/23 20:12
Joined: Feb 2023
Posts: 10
S
ShawnM Offline OP
Newbie
ShawnM  Offline OP
Newbie
S

Joined: Feb 2023
Posts: 10
That is my only script Petra... that's what makes it so puzzling.

Re: New to Zorro and getting tripped up on some fundamental things [Re: ShawnM] #487277
03/02/23 09:01
03/02/23 09:01
Joined: Apr 2008
Posts: 585
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 585
Austria
Ok, but this script does not trail, as far as I see. Please set LOGFILE and run this script in Test mode. Then go through the log and let me know if you see a "Trail" message anywhere. If so, please post that part of the log. Make also sure that you have the recent Zorro version.

Re: New to Zorro and getting tripped up on some fundamental things [Re: ShawnM] #487293
03/05/23 22:10
03/05/23 22:10
Joined: Feb 2023
Posts: 10
S
ShawnM Offline OP
Newbie
ShawnM  Offline OP
Newbie
S

Joined: Feb 2023
Posts: 10
Sorry Petra, I mistakenly sent you the code of my very first "original" script before my few changes advised by user NSG. My very latest script is logically not much different and is the following:


Code
function run() 
{	
   set(LOGFILE);
   BarMode = BR_MARKET;
   //StartDate = 20221012;
   //EndDate = 20221013;	
	
   StartDate = 20221122;
   EndDate = 20221123;

   StartMarket = 1430; // 9:30am EST
   EndMarket = 2200;   // 5:00pm EST
   
   MaxLong = 1;
   Fill = 0;
   Slippage = 0;
   Penalty = 0;
   Stop = 10*PIP;
   TakeProfit = 20*PIP;

   BarPeriod = 5;
   asset("US30");
   //vars Prices = series(price());
	
   var r = random();
   if (r >= .60) enterLong();
}



...this was the version of the script that produced the mysterious "Trail" in the logfile, which I show in my post #487262 to user NSG (also in that post is part of the logfile, as you requested. I have attached the full logfile also). Nowhere in the above script do I move my stoploss or my profit target - they are static.

Thanks!
ShawnM

P.S: There are actually 2 instances of this "trail" occurrence in the logfile. Also my version of Zorro is 2.53.9. I just downloaded it and installed it about a week ago.

Attached Files
MyCont1Test_test.log (28 downloads)
Re: New to Zorro and getting tripped up on some fundamental things [Re: ShawnM] #487303
03/07/23 11:11
03/07/23 11:11
Joined: Apr 2008
Posts: 585
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 585
Austria
Yes, this one trails. You're updating the stop with MaxLong.

You can find the MaxLong description in the manual, but in short, if you only want to limit the trades without updating the open trades, set MaxLong to -1.

https://zorro-project.com/manual/en/log.htm


Re: New to Zorro and getting tripped up on some fundamental things [Re: Petra] #487316
03/09/23 20:38
03/09/23 20:38
Joined: Feb 2023
Posts: 10
S
ShawnM Offline OP
Newbie
ShawnM  Offline OP
Newbie
S

Joined: Feb 2023
Posts: 10
Ah that fixed it, thank you so much Petra! I was under the impression that MaxLong simply put a limit on the number of allowed open positions...

Thanks!

Page 1 of 2 1 2

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1