MAs data and graph are wonky

Posted By: kwyx

MAs data and graph are wonky - 08/15/22 06:40

Why my middle MAs are wonky. Golden is SMA, Blue is EMA.
Three bands being High, Close, Low respectively.
My code:

Code
	StartDate = 20180101;
	EndDate = 20201231;
	LookBack = 300;
	
	BarPeriod = 60;
        int SMA_PERIOD = 72;
        int EMA_PERIOD = 12;
        int ADX_PERIOD = 14;
        sma_high  = series(SMA(seriesH(),SMA_PERIOD)); 
	sma_mid   = series(SMA(series(price()),SMA_PERIOD));
	sma_low   = series(SMA(seriesL(),SMA_PERIOD));
	ema_high  = series(EMA(seriesH(),EMA_PERIOD));
	ema_mid  = series(EMA(series(price()),EMA_PERIOD));
	ema_low  = series(EMA(seriesL(),EMA_PERIOD));
	adx = series(ADX(ADX_PERIOD));

	 plot("ema_high",ema_high,LINE ,BLUE);
	 plot("ema_mid",ema_mid,LINE ,BLUE+TRANSP);
	 plot("ema_low",ema_low,LINE ,BLUE);
	 plot("sma_high",sma_high,LINE ,ORANGE);
	 plot("sma_mid",sma_mid,LINE ,ORANGE+TRANSP);
	 plot("sma_low",sma_low,LINE ,ORANGE);


Attached picture wonky MA.jpg
Posted By: jcl

Re: MAs data and graph are wonky - 08/15/22 14:27

series(price) is not Close. seriesC() is Close.

Aside from that, series() is filled with the inital value at start, while seriesC() is not.
Posted By: kwyx

Re: MAs data and graph are wonky - 08/15/22 16:30

Actually I wanted the typical price for the mid line (H+L+C)/3. Can I do something like:
sma_low = series(SMA((seriesL()+seriesC()+seriesH())/3,SMA_PERIOD));

Also- would seriesC[0] give the current price for the current (incomplete bar).

One more query- I migrated my algo from MQL5 to Zorro which is kinda C++ to C migration.
The business logic lines are hardly changed. I'm raking my brains but I can't figure out why the algo is severely bad(negative profit) results in Zorro- any pointers how do I debug?

Does Zorro change TP/SL despite me setting up exclusively when I do enterLong()/enterShort?
Posted By: jcl

Re: MAs data and graph are wonky - 08/16/22 07:13

That would be SMA(series((priceH()+priceL()+priceC())/3),Period). And there is no incomplete bar in the run function.

Even with the same strategy, you will likely get a different and usually worse backtest result from Zorro than from MT5. At least I hope so. For the details, read the chapter about code migration in the manual.
© 2024 lite-C Forums