Position stopped even without stop loss / exit rule

Posted By: marr

Position stopped even without stop loss / exit rule - 07/03/19 12:46

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 picture EMA3_TSLA.png
Posted By: AndrewAMD

Re: Position stopped even without stop loss / exit rule - 07/03/19 14:34

If you set LOGFILE and Verbose = 7+DIAG, you should find the reason why in your logs.
Posted By: marr

Re: Position stopped even without stop loss / exit rule - 07/03/19 15:55

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
Posted By: jcl

Re: Position stopped even without stop loss / exit rule - 07/04/19 06:36

When you get a margin call, your trades are liquidated at market.
Posted By: marr

Re: Position stopped even without stop loss / exit rule - 07/04/19 07:03

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
Posted By: Petra

Re: Position stopped even without stop loss / exit rule - 07/04/19 07:23

Your margin size looks wrong, such a trade will not live long.
Posted By: marr

Re: Position stopped even without stop loss / exit rule - 07/04/19 12:30

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
Posted By: Petra

Re: Position stopped even without stop loss / exit rule - 07/04/19 14:25

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.
Posted By: marr

Re: Position stopped even without stop loss / exit rule - 07/04/19 14:38

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
Posted By: AndrewAMD

Re: Position stopped even without stop loss / exit rule - 07/04/19 15:40

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])
Posted By: marr

Re: Position stopped even without stop loss / exit rule - 07/04/19 15:49

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
Posted By: Spirit

Re: Position stopped even without stop loss / exit rule - 07/04/19 16:53

Post the log of the first trade.
Posted By: marr

Re: Position stopped even without stop loss / exit rule - 07/05/19 06:18

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
Posted By: Spirit

Re: Position stopped even without stop loss / exit rule - 07/05/19 10:12

A log is a file with type log in the folder Log.
Posted By: marr

Re: Position stopped even without stop loss / exit rule - 07/05/19 11:49

you meant this?

Attached File
EMA3_test.txt  (66 downloads)
Posted By: Spirit

Re: Position stopped even without stop loss / exit rule - 07/05/19 13:40

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.
Posted By: marr

Re: Position stopped even without stop loss / exit rule - 07/05/19 13:56

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
Posted By: AndrewAMD

Re: Position stopped even without stop loss / exit rule - 07/05/19 14:51

Put it in a zip file.
Posted By: marr

Re: Position stopped even without stop loss / exit rule - 07/05/19 15:19

Here is the log from the LOGFILE

Attached File
EMA3_test.rar  (14 downloads)
Posted By: Spirit

Re: Position stopped even without stop loss / exit rule - 07/05/19 18:55

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.
© 2024 lite-C Forums