Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Trading Journey
by howardR. 04/24/24 20:04
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (howardR, AndrewAMD, EternallyCurious, Petra, 1 invisible), 791 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Position stopped even without stop loss / exit rule #477508
07/03/19 12:46
07/03/19 12:46
Joined: Apr 2019
Posts: 48
Albay
M
marr Offline OP
Newbie
marr  Offline OP
Newbie
M

Joined: Apr 2019
Posts: 48
Albay
Im testing a simple strategy enter long when the price is above the MAs , I wanted to see if the variable are behaving properly including the entry / exit and stop loss but I encounter this behavior where the position have its own exit, even without specifying any rules, on zorro manual Stop is default to 0. Can someone explain why is it happening

Heres the code:

Code
function run()	{
	set(TICKS|LOGFILE);
	
	// Minute
	BarPeriod = 1;
	Capital = 10000;
	LookBack = 500;
	NumWFOCycles = 10;
	Margin = 0.50 * Capital;

	while(asset(loop(Assets))){

		vars Close = series(priceClose());
		vars Low = series(priceLow());

		int EMA13TimePeriod = 13;
		int EMA8TimePeriod  = 8;
		int EMA5TimePeriod  = 5;
		int ADXTimePeriod   = 14;
		

		vars EMA13 =  series(EMA(Close, EMA13TimePeriod));
		vars EMA8  = series(EMA(Close, EMA8TimePeriod));
		vars EMA5  = series(EMA(Close, EMA5TimePeriod));
		
		vars ADX   = series(ADX(ADXTimePeriod));
	
		MaxLong = MaxShort = 1;
		
		if (Close > EMA13 && Close > EMA8 && Close > EMA5)
		{

			enterLong();
			
		}

		plot("EMA13",EMA13,LINE,ORANGE);
		plot("EMA8",EMA8,LINE,ORANGE);
		plot("EMA5",EMA5,LINE,ORANGE);
		plot("ADX",ADX,NEW|LINE,BLUE);

	}

	
}


Attached Files EMA3_TSLA.png
Re: Position stopped even without stop loss / exit rule [Re: marr] #477510
07/03/19 14:34
07/03/19 14:34
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
If you set LOGFILE and Verbose = 7+DIAG, you should find the reason why in your logs.

Re: Position stopped even without stop loss / exit rule [Re: AndrewAMD] #477512
07/03/19 15:55
07/03/19 15:55
Joined: Apr 2019
Posts: 48
Albay
M
marr Offline OP
Newbie
marr  Offline OP
Newbie
M

Joined: Apr 2019
Posts: 48
Albay
this is what i get when i set that

Code
Sell 1@325.32: -2088 Bid 325.12 at 13:09:00
Opn 327.21 Cls 325.32 Spr 0.200000 Slp 342.11 Rol -0.00 Com 0.00 Net 1
Max Loss 0.00 -> 2087.88
Max Bars 0 -> 569-480


clearly Max Loss have something to do with my issue, tho i can't find about this on the manual

Re: Position stopped even without stop loss / exit rule [Re: marr] #477517
07/04/19 06:36
07/04/19 06:36
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
When you get a margin call, your trades are liquidated at market.

Re: Position stopped even without stop loss / exit rule [Re: jcl] #477520
07/04/19 07:03
07/04/19 07:03
Joined: Apr 2019
Posts: 48
Albay
M
marr Offline OP
Newbie
marr  Offline OP
Newbie
M

Joined: Apr 2019
Posts: 48
Albay
I wanted to prevent this but i dont understant why the trades are exiting too early even without specifying exitlong and stop, since they are default at 0, i should expect a 1 huge loss

Re: Position stopped even without stop loss / exit rule [Re: marr] #477521
07/04/19 07:23
07/04/19 07:23
Joined: Apr 2008
Posts: 586
Austria
Petra Online
Support
Petra  Online
Support

Joined: Apr 2008
Posts: 586
Austria
Your margin size looks wrong, such a trade will not live long.

Re: Position stopped even without stop loss / exit rule [Re: Petra] #477526
07/04/19 12:30
07/04/19 12:30
Joined: Apr 2019
Posts: 48
Albay
M
marr Offline OP
Newbie
marr  Offline OP
Newbie
M

Joined: Apr 2019
Posts: 48
Albay
the margin that I used came from a book, it is originally 5% of my capital, and experimented with different values, tho the time of margin call is different, but i wanted to know why the trade exits too early which causes failure of the system , even specifying hard rules

Re: Position stopped even without stop loss / exit rule [Re: marr] #477528
07/04/19 14:25
07/04/19 14:25
Joined: Apr 2008
Posts: 586
Austria
Petra Online
Support
Petra  Online
Support

Joined: Apr 2008
Posts: 586
Austria
A margin call is not good. That your trades are closed is then the least of your worries! grin

Delete your lines with "Margin" and "Capital", they are the reason of the margin call. Your trade signal is also wrong. Begin with the tutorial, there is also a workshop where you learn what "Margin" and "Capital" are and how to use them.

Re: Position stopped even without stop loss / exit rule [Re: Petra] #477529
07/04/19 14:38
07/04/19 14:38
Joined: Apr 2019
Posts: 48
Albay
M
marr Offline OP
Newbie
marr  Offline OP
Newbie
M

Joined: Apr 2019
Posts: 48
Albay
I understand that the strategy is bad, i dont mind margin call actually, its just, there are trades that exit at 0 sec after it enter which is kinda weird for me, since I did not set up a stop loss and risk which is now default to 0 and the code doesnt have exitLong() that would make the trade exit right away. That is the mystery that i am trying to look out for days.

Here is the testrade logs of some part on the image. ive also display the duration of the trade.

Code
"Name","Type","Asset","ID","Lots","Open","Close","Entry","Exit","Profit","Roll","ExitType","Duration"
"cloud","Long","TSLA",4802701,1,2019-03-20 09:07:00,2019-03-20 09:07:00,269.22,269.02,-200,0,"Sold",0
"cloud","Long","TSLA",4803601,1,2019-03-20 09:16:00,2019-03-20 09:16:00,269.22,269.02,-200,0,"Sold",0
"cloud","Long","TSLA",4805101,1,2019-03-20 09:31:00,2019-03-20 09:31:00,269.95,269.75,-200,0,"Sold",0
"cloud","Long","TSLA",4805801,1,2019-03-20 09:38:00,2019-03-20 09:38:00,270,269.64,-365,0,"Sold",0

Re: Position stopped even without stop loss / exit rule [Re: marr] #477532
07/04/19 15:40
07/04/19 15:40
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Originally Posted by marr
i dont mind margin call actually
Your broker will strongly disagree.

Also, this is wrong:
Code
if (Close > EMA13 && Close > EMA8 && Close > EMA5)
Write it like this:
Code
if (Close[0] > EMA13[0] && Close[0] > EMA8[0] && Close[0] > EMA5[0])

Re: Position stopped even without stop loss / exit rule [Re: AndrewAMD] #477533
07/04/19 15:49
07/04/19 15:49
Joined: Apr 2019
Posts: 48
Albay
M
marr Offline OP
Newbie
marr  Offline OP
Newbie
M

Joined: Apr 2019
Posts: 48
Albay
I updated the code to your suggestion and get the same behavior, the duration of the trades is 0, no stop loss define and risk no exit rule too, same thing will happen even if I set a wide stop loss. which causes to lose always, it is weird why it happens. im using the latest zorro version

Re: Position stopped even without stop loss / exit rule [Re: marr] #477535
07/04/19 16:53
07/04/19 16:53
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
Post the log of the first trade.

Re: Position stopped even without stop loss / exit rule [Re: Spirit] #477541
07/05/19 06:18
07/05/19 06:18
Joined: Apr 2019
Posts: 48
Albay
M
marr Offline OP
Newbie
marr  Offline OP
Newbie
M

Joined: Apr 2019
Posts: 48
Albay
Here is the log of the whole trade, note that I put a Stop = EMA13[0] - 2000 * PIP. I don't have any problem on trades that are exited by stop but the trades that are exited by sell. If you observe that the duration of the trades on the ExitType with Sold goes to 0. Also, I did not put any exitLong() and Risk.

Code
"Name","Type","Asset","ID","Lots","Open","Close","Entry","Exit","Profit","Roll","ExitType","Duration"
"EMA3","Long","TSLA",4303501,1,2019-03-12 17:55:00,2019-03-12 18:18:00,283.25,284.64,1384,0,"Stop",1380
"EMA3","Long","TSLA",4307401,1,2019-03-12 18:34:00,2019-03-12 18:41:00,284.13,283.42,-713,0,"Stop",420
"EMA3","Long","TSLA",4313901,1,2019-03-12 19:39:00,2019-03-12 19:39:00,282.94,282.63,-307,0,"Stop",0
"EMA3","Long","TSLA",4314501,1,2019-03-12 19:45:00,2019-03-12 19:51:00,283.09,282.84,-247,0,"Stop",360
"EMA3","Long","TSLA",4315201,1,2019-03-12 19:52:00,2019-03-12 20:12:00,283.07,282.8,-272,0,"Stop",1200
"EMA3","Long","TSLA",4317901,1,2019-03-12 20:19:00,2019-03-12 20:50:00,283.14,282.75,-393,0,"Stop",1860
"EMA3","Long","TSLA",4321301,1,2019-03-12 20:53:00,2019-03-12 20:56:00,283.21,282.81,-395,0,"Stop",180
"EMA3","Long","TSLA",4321701,1,2019-03-12 20:57:00,2019-03-12 21:01:00,283.26,282.83,-426,0,"Stop",240
"EMA3","Long","TSLA",4324301,1,2019-03-12 21:23:00,2019-03-12 21:42:00,283.2,282.73,-473,0,"Stop",1140
"EMA3","Long","TSLA",4326801,1,2019-03-12 21:48:00,2019-03-12 22:09:00,283.11,282.71,-402,0,"Stop",1260
"EMA3","Long","TSLA",4330201,1,2019-03-12 22:22:00,2019-03-12 22:24:00,283,282.74,-258,0,"Stop",120
"EMA3","Long","TSLA",4330501,1,2019-03-12 22:25:00,2019-03-12 23:12:00,282.91,282.57,-339,0,"Stop",2820
"EMA3","Long","TSLA",4335501,1,2019-03-12 23:15:00,2019-03-12 23:20:00,282.89,282.47,-420,0,"Stop",300
"EMA3","Long","TSLA",4336701,1,2019-03-12 23:27:00,2019-03-12 23:32:00,282.69,282.44,-246,0,"Stop",300
"EMA3","Long","TSLA",4337801,1,2019-03-12 23:38:00,2019-03-12 23:42:00,282.84,282.49,-352,0,"Stop",240
"EMA3","Long","TSLA",4338301,1,2019-03-12 23:43:00,2019-03-12 23:43:00,282.68,282.33,-349,0,"Stop",0
"EMA3","Long","TSLA",4338401,1,2019-03-12 23:44:00,2019-03-12 23:45:00,282.75,282.32,-434,0,"Stop",60
"EMA3","Long","TSLA",4338601,1,2019-03-12 23:46:00,2019-03-12 23:49:00,282.87,282.37,-498,0,"Stop",180
"EMA3","Long","TSLA",4339601,1,2019-03-12 23:56:00,2019-03-12 23:57:00,282.74,282.51,-237,0,"Stop",60
"EMA3","Long","TSLA",4339901,1,2019-03-12 23:59:00,2019-03-13 08:04:00,282.86,283.13,272,0,"Stop",29100
"EMA3","Long","TSLA",4350101,1,2019-03-13 09:41:00,2019-03-13 09:50:00,281.75,281.35,-400,0,"Stop",540
"EMA3","Long","TSLA",4357801,1,2019-03-13 10:58:00,2019-03-13 11:31:00,282,283.32,1323,0,"Stop",1980
"EMA3","Long","TSLA",4361201,1,2019-03-13 11:32:00,2019-03-13 11:40:00,283.89,283.51,-376,0,"Stop",480
"EMA3","Long","TSLA",4362301,1,2019-03-13 11:43:00,2019-03-13 11:45:00,284,283.17,-826,0,"Stop",120
"EMA3","Long","TSLA",4362601,1,2019-03-13 11:46:00,2019-03-13 11:46:00,283.68,283.51,-165,0,"Stop",0
"EMA3","Long","TSLA",4363201,1,2019-03-13 11:52:00,2019-03-13 12:23:00,283.99,283.47,-516,0,"Stop",1860
"EMA3","Long","TSLA",4366501,1,2019-03-13 12:25:00,2019-03-13 12:36:00,283.86,283.47,-390,0,"Stop",660
"EMA3","Long","TSLA",4367701,1,2019-03-13 12:37:00,2019-03-13 12:38:00,283.87,282.83,-1038,0,"Sold",60
"EMA3","Long","TSLA",4370801,1,2019-03-13 13:08:00,2019-03-13 13:08:00,282.96,282.73,-232,0,"Sold",0
"EMA3","Long","TSLA",4370901,1,2019-03-13 13:09:00,2019-03-13 13:09:00,283.03,282.8,-232,0,"Sold",0
"EMA3","Long","TSLA",4371001,1,2019-03-13 13:10:00,2019-03-13 13:10:00,283.05,283.02,-32.15,0,"Sold",0
"EMA3","Long","TSLA",4371101,1,2019-03-13 13:11:00,2019-03-13 13:11:00,283.22,282.85,-368,0,"Sold",0
"EMA3","Long","TSLA",4371201,1,2019-03-13 13:12:00,2019-03-13 13:12:00,283.31,283.11,-200,0,"Sold",0
"EMA3","Long","TSLA",4371301,1,2019-03-13 13:13:00,2019-03-13 13:13:00,283.31,283.11,-200,0,"Sold",0
"EMA3","Long","TSLA",4371401,1,2019-03-13 13:14:00,2019-03-13 13:14:00,283.31,282.99,-324,0,"Sold",0
"EMA3","Long","TSLA",4371501,1,2019-03-13 13:15:00,2019-03-13 13:15:00,283.45,283.29,-155,0,"Sold",0
"EMA3","Long","TSLA",4371601,1,2019-03-13 13:16:00,2019-03-13 13:16:00,283.7,283.32,-381,0,"Sold",0
"EMA3","Long","TSLA",4371701,1,2019-03-13 13:17:00,2019-03-13 13:17:00,283.8,283.6,-200,0,"Sold",0
"EMA3","Long","TSLA",4371801,1,2019-03-13 13:18:00,2019-03-13 13:18:00,283.8,283.59,-206,0,"Sold",0

Re: Position stopped even without stop loss / exit rule [Re: marr] #477544
07/05/19 10:12
07/05/19 10:12
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
A log is a file with type log in the folder Log.

Re: Position stopped even without stop loss / exit rule [Re: Spirit] #477545
07/05/19 11:49
07/05/19 11:49
Joined: Apr 2019
Posts: 48
Albay
M
marr Offline OP
Newbie
marr  Offline OP
Newbie
M

Joined: Apr 2019
Posts: 48
Albay
you meant this?

Attached Files
EMA3_test.txt (65 downloads)
Re: Position stopped even without stop loss / exit rule [Re: marr] #477548
07/05/19 13:40
07/05/19 13:40
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
No, thats a txt file. I mean the log file. Which you produce with LOGFILE flag and in which you look when you dont understand what your script is doing.

If all this is unfamilar to you then it might be better when you take the tutorial first or read a Zorro book or take a Zorro course. Trading software is not totally easy.

Re: Position stopped even without stop loss / exit rule [Re: marr] #477550
07/05/19 13:56
07/05/19 13:56
Joined: Apr 2019
Posts: 48
Albay
M
marr Offline OP
Newbie
marr  Offline OP
Newbie
M

Joined: Apr 2019
Posts: 48
Albay
I cant upload a logfile in this forum, it rejects the file i converted it to a .txt, that EMA3_test.txt is copy pasted from the LOGFILE produced when the flag is set

Re: Position stopped even without stop loss / exit rule [Re: marr] #477551
07/05/19 14:51
07/05/19 14:51
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Put it in a zip file.

Re: Position stopped even without stop loss / exit rule [Re: AndrewAMD] #477553
07/05/19 15:19
07/05/19 15:19
Joined: Apr 2019
Posts: 48
Albay
M
marr Offline OP
Newbie
marr  Offline OP
Newbie
M

Joined: Apr 2019
Posts: 48
Albay
Here is the log from the LOGFILE

Attached Files
EMA3_test.rar (13 downloads)
Re: Position stopped even without stop loss / exit rule [Re: marr] #477555
07/05/19 18:55
07/05/19 18:55
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
Ok, now look in that log for the trade that you did not understand, you see there clearly what happened and why it was closed. It seems you have still not fixed your script as suggested. Its still the same problem. BTW, the error messages at the begin mean that the historical data is also missing.

Page 1 of 2 1 2

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1