Zorro

Post Reply
jcl
Trader
Posts: 82
Joined: Wed Oct 31, 2012 8:04 am
Location: Frankfurt / Germany

Zorro

Post by jcl »

The code is just the algorithm of a Renko bar (I hope). If you use it, you trade and test with Renko bars. Otherwise you would trade and test with standard bars.

But for trading you need some system of when to open and close positions. The Renko bar code is just for the bars. It does not trade.
Shoddy
Trader
Posts: 37
Joined: Tue Jan 13, 2015 8:18 am
Location: New Nose Harbour (Nynäshamn south of Stockholm in Sweden)

Zorro

Post by Shoddy »

Yes I understand that the bars do not trade, I was just in the dark as how to the bar function worked, a friend did some testing and found out that, as far as we understand, the bar function is used to replace the calculation of bars in general during the script, never seen that before in any language. Cool! :good:

But I think the renko calculation is a bit wrong, when we plot the bars sometimes we get bull/bear bars right next to each other on the same 'height', the close of a bull bar is the next open of a bear bar, that's incorrect, we'll have to do some more testing.

Thanks!

//R
jcl
Trader
Posts: 82
Joined: Wed Oct 31, 2012 8:04 am
Location: Frankfurt / Germany

Zorro

Post by jcl »

Yes, the bar() function replaces standard bars. It is in fact possible that the Renko bar calculation is wrong - if I remember right, the Renko algorithm was described slightly differently on several websites, so I am not sure which algorithm is the "true" one. But you can change the algorithm as you want and experiment with it. If you find the true Renko, please let me know.
Shoddy
Trader
Posts: 37
Joined: Tue Jan 13, 2015 8:18 am
Location: New Nose Harbour (Nynäshamn south of Stockholm in Sweden)

Zorro

Post by Shoddy »

Will do :good:
hirdman
Posts: 2
Joined: Fri Oct 23, 2015 11:56 am

Zorro

Post by hirdman »

Hi, I'm the friend =)
I think I have solved the renko bars at a trend change now:

Code: Select all

var BarRange = 0.0030;
var OpenDiff;
var CloseDiff;
int bar(vars Open, vars High, vars Low, vars Close)
{
    OpenDiff = abs(Close[0]-Open[1]);
    CloseDiff = abs(Close[0]-Close[1]);
    if(OpenDiff < CloseDiff) { 
    // If this matches we have a valley or peak
        Open[0] = Open[1];
    } else {                               
    // This is for when we are moving with the trend
	    Open[0] = round(Close[1],BarRange);
    }
	if(Close[0]-Open[0] >= BarRange) {  // Going up
		Close[0] = Open[0]+BarRange;
		High[0] = Close[0];
		Low[0] = Open[0];
		return 1;
	}
	if(Open[0]-Close[0] >= BarRange) { // Going Down
		Close[0] = Open[0]-BarRange;
		High[0] = Open[0];
		Low[0] = Close[0];
		return 1;
	}
	return 4;
}
Still need to test it and match it with other sources to verify that it works correctly. Because the graphs differ more than I thought they would.
You do not have the required permissions to view the files attached to this post.
jcl
Trader
Posts: 82
Joined: Wed Oct 31, 2012 8:04 am
Location: Frankfurt / Germany

Zorro

Post by jcl »

Thanks! Your algorithm indeed produces more bars and more details in the bar curve. I'll mention the several Renko variants in the Zorro documentation and will include your code, with your permission. I think it does not matter much which one is the original Renko - the best version is always the version with the best profits.
hirdman
Posts: 2
Joined: Fri Oct 23, 2015 11:56 am

Zorro

Post by hirdman »

jcl » Thu Nov 05, 2015 10:41 am wrote:Thanks! Your algorithm indeed produces more bars and more details in the bar curve. I'll mention the several Renko variants in the Zorro documentation and will include your code, with your permission. I think it does not matter much which one is the original Renko - the best version is always the version with the best profits.
But of course, feel free to include it just glad to contribute in some small way. =)
I've matched it to a Renko generated in Empty4 and it correlates quite well, not an exact match but close enough.
ForMyEx
Posts: 6
Joined: Fri Dec 19, 2014 12:26 pm
Location: Berlin - Germany

Zorro

Post by ForMyEx »

Hi all,

I just started with zorro and I'm glad to have the experts here :good:
The features Zorro offers out of the box are very valueable in my opinion. Especially things like the neural network (@jcl: would be great if you share some experiments with us regarding this) and the walk forward optimization.
I'm don't have any C programming experience but know Java, so I hoped that learning Lite-C would be a piece of cake but it isn't.

Since I just play around and am still far away from developing a profitable EA with Zorro I decided to take the first step towards "taking money from the rich and givint it to the poor" by adding two Indicators to indicators.c that you might know as well: Dr. Elders BullsPower and BearsPower, which are calculated slightly different from what Dr. Elder describes, but anyways.

In MQL this would look somehow like that:

Code: Select all

   double myBull = High[shift] - iMA(symbol, tf, 13, 0, MODE_EMA, PRICE_MEDIAN, shift);
   double myBear = Low[shift] - iMA(symbol, tf, 13, 0, MODE_EMA, PRICE_MEDIAN, shift);
So I tried this in Lite-C within indicators.c and ended up this way:

Code: Select all

var BullsPower(int timeframe, int Period);
var BearsPower(int timeframe, int Period);

var BullsPower(int timeframe, int Period){
	vars priceHighs = series(priceHigh(), Period); //getting Highs of last Period # of bars
	var ema = EMA(price(),Period); //calculating the exponential MA with given Period # of bars
	return priceHighs(0) - ema; //Calculate BullsPower by reducing the current High by calculated EMA
}

var BearsPower(int timeframe, int Period){
	vars lowPrices = series(priceLow(), Period);
	var ema = EMA(price(), Period);
	return lowPrices(0) - ema;
}
Next I manipulated the IndicatorTest Skript and added two lines calling my indicators:

Code: Select all

// plot some other indicators	
	plot("BullsPower", BullsPower(60, 13),NEW,GREEN);
	plot("BearsPower", BearsPower(60, 13),NEW,RED);
When I run the IndicatorTest Skript in Zorro I get the following output:

IndicatorTest compiling..................
Undefined function called!
BackTest: IndicatorTest EUR/USD 2015
Error 037: Invalid value in plot "BullsPower" bar 1
Chart - please wait.. ok


Do anyone of you guys know what's wrong with the code in the indicators.c file? I obviously don't know :arrrg: Any help/hint would be appreciated.

Merry Christmas to all of you!
Bye
Ahmet
----------------------------------------------------------------------
Everybody said "That's not possible" until someone came, who did not know about that and did it.
jcl
Trader
Posts: 82
Joined: Wed Oct 31, 2012 8:04 am
Location: Frankfurt / Germany

Zorro

Post by jcl »

I see two simple syntax errors:

The EMA function needs a series, so it should be series(price()). And series elements are accessed with [], not (), so it's priceHighs[0] for the recent price.

Have a great Christmas!
ForMyEx
Posts: 6
Joined: Fri Dec 19, 2014 12:26 pm
Location: Berlin - Germany

Zorro

Post by ForMyEx »

Hi jcl,
thank you for the tips. So now the corrected code looks like this:

Code: Select all

var BullsPower(int Period){
	vars highPrices = series(priceHigh(), Period);
	var ema = EMA(series(price()),Period);
	return highPrices[0] - ema;
}

// BearsPower
var BearsPower(int Period){
	vars lowPrices = series(priceLow(), Period);
	var ema = EMA(series(price()), Period);
	return lowPrices[0] - ema;

}
But it still does not work. Same error like before:

IndicatorTest compiling...................
Undefined function called!
BackTest: IndicatorTest EUR/USD 2015
Error 037: Invalid value in plot "BullsPower" bar 1
Chart - please wait.. ok


Two errors seem to exist:
1. Undefined function called!
Which function is it referring to? Unfortunately it does not give me any hint (name, or line number) where to look for it. A little frustrating.
2. Error 037
The FAQs say that there could be a false calculation result, which leads to this error. So I suspect the BullsPower function in the indicators.c file. Unfortunately I did not find any means of debugging. Am I missing something? How can I check what the function is calculating? Can I introspect the execution?
:? So many questions ...
----------------------------------------------------------------------
Everybody said "That's not possible" until someone came, who did not know about that and did it.
Post Reply

Return to “Coders Hangout”