Gamestudio Links
Zorro Links
Newest Posts
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
M1 Oversampling
by 11honza11. 04/20/24 20:57
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (frutza, Quad, AndrewAMD), 385 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Problems with EMA #482636
03/11/21 15:22
03/11/21 15:22
Joined: Mar 2021
Posts: 3
L
Lennardd Offline OP
Guest
Lennardd  Offline OP
Guest
L

Joined: Mar 2021
Posts: 3
Hi guys,

I only recently started to use Zorro for backtesting my trading idea's but I've fallen in love with it immediately blush. However, I'm having trouble with using EMA, while other indicators don't cause any problems. However, if I use the following code snippet, it doesn't matter whether I use 'EMA50 > EMA200' or 'EMA50 < EMA200', backtest result is the same. Yet, if I look at the chart there are trades both when EMA50 is higher and when it's lower dan EMA200.
Code
	vars Price = series(priceClose());
	vars EMA50 = series(EMA(Price, 50));
	vars EMA200 = series(EMA(Price, 200));
	vars Macd = series(MACD(Price, 12, 26, 9));
	var *MacdHist = series(rMACDHist);
	
	if (!TradeIsOpen && EMA50 > EMA200 && crossOver(MacdHist, 0)){
		enterLong();
	}
	
	else if (TradeIsOpen && crossOver(MacdHist, 0)){
		exitLong();
	}


So I'm certainly making a mistake with using EMA indicator (Zorro doesn't give any error messages). Does anybody know what I'm doing wrong? Thanks in advance!

Re: Problems with EMA [Re: Lennardd] #482638
03/11/21 18:39
03/11/21 18:39
Joined: Mar 2021
Posts: 6
Z
ZorroTradeAA Offline
Newbie
ZorroTradeAA  Offline
Newbie
Z

Joined: Mar 2021
Posts: 6
Hi,

I see here two potential issues:
1. Can you tell us to which value you set LookBack? For a 200-EMA you need a high number in LookBack (I would say more than 200 as this is only valid for SMA and not EMA).
2. The variable TradeIsOpen has only valid entries when using in a tmf or in a loop like for(open_trades). If you use it outside of those two this is incorrect.

To tell more I need to see the rest of you code. But maybe you can search in the manual for tmf and you will find the answer by your own.

Cheers

Re: Problems with EMA [Re: Lennardd] #482642
03/12/21 07:58
03/12/21 07:58
Joined: May 2015
Posts: 390
Czech Republic
G
Grat Offline
Senior Member
Grat  Offline
Senior Member
G

Joined: May 2015
Posts: 390
Czech Republic
try this:
Code
	if (!TradeIsOpen && EMA50[0] > EMA200[0] && crossOver(MacdHist, 0)){
		enterLong();
	}

Re: Problems with EMA [Re: Grat] #482643
03/12/21 10:21
03/12/21 10:21
Joined: Mar 2021
Posts: 3
L
Lennardd Offline OP
Guest
Lennardd  Offline OP
Guest
L

Joined: Mar 2021
Posts: 3
Hi Grat,

Thanks a lot! This worked for me! smile

Regards,
Lennardd

Re: Problems with EMA [Re: ZorroTradeAA] #482644
03/12/21 10:25
03/12/21 10:25
Joined: Mar 2021
Posts: 3
L
Lennardd Offline OP
Guest
Lennardd  Offline OP
Guest
L

Joined: Mar 2021
Posts: 3
Hi ZorroTradeAA,

Thanks for your reply. My LookBack period was at 250 and I used it indeed in a loop. The problem was the absense of a index in my array as Grat indicated.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1