Special Bars Script

Posted By: danatrader

Special Bars Script - 09/19/20 00:41

How would I create here a multi - asset Renko strategy?

Whatever I fill in where it says "perform algorithm" seems to have no effect at all.


void run()
{
BarPeriod = 1; // determines here the time resolution of the bar
StartDate = 20180601;
EndDate = 20180901;
LookBack = 13;
set(PLOTNOW);
set(TICKS);
assetList("P:\\AssetsCur3.csv");
while(asset(loop("EUR/USD","GBP/USD")))
{
_bar = HA;
vars O = series(priceOpen(),-LookBack), // series must be static here
H = series(priceHigh(),-LookBack),
L = series(priceLow(),-LookBack),
C = series(priceClose(),-LookBack);
if(nextBar(O,H,L,C)) {

// ... perform the algorithm. Shift other series.
printf("#\nNew Bar");
}
plot("Renko",C,LINE,RED);
}
}
#endif
Posted By: jcl

Re: Special Bars Script - 09/21/20 06:37

The script collection contains a script for multi-asset Renko.
Posted By: atr

Re: Special Bars Script - 10/25/20 11:08

You mentioned that the collection contains a script for multi-asset Renko. I found the script specialBars.c .The problem for me because I am a beginner programing in C-lite is that where it says in the script " // ... perform the algorithm. Use only static series. // Do not use indicators that internally create series." there is not an exemple of an algorithm that use only static series. Could anyone put a simple algorithm with static series in the multi-asset script specialBars.c as an exemple in order to know how an algo with static series work?

Thanks.
Posted By: atr

Re: Special Bars Script - 10/25/20 12:30

As an exemple I put a simple algo int the specialBars.c script. It doesn't work. So what I have to do in order to make work the algo with multi asset special bars?


// Special bars example //////////////////////////////

#define MULTI_ASSET

var BarRange = 0.0030; // 0.3 cents bar range

// Range Bars
int Range(vars Open,vars High,vars Low,vars Close)
{
if(Open[0] != Close[1]) {
High[0] = max(Open[0],Close[1]);
Low[0] = min(Open[0],Close[1]);
Open[0] = Close[1];
}
if(High[0]-Low[0] >= BarRange)
return 1;
return 4;
}

// Renko Bars, variant 1
int Renko1(vars Open,vars High,vars Low,vars Close)
{
Open[0] = roundto(Close[1],BarRange);
if(Close[0]-Open[0] >= BarRange) {
Close[0] = Open[0]+BarRange;
High[0] = Close[0];
Low[0] = Open[0];
return 1;
}
if(Open[0]-Close[0] >= BarRange) {
Close[0] = Open[0]-BarRange;
High[0] = Open[0];
Low[0] = Close[0];
return 1;
}
return 4;
}

// Renko Bars, variant 2
int Renko2(vars Open, vars High, vars Low, vars Close)
{
var OpenDiff = abs(Close[0]-Open[1]);
var CloseDiff = abs(Close[0]-Close[1]);
if(OpenDiff < CloseDiff) // we have a valley or peak
Open[0] = Open[1];
else // we are moving with the trend
Open[0] = roundto(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;
}

// Mean Renko Bars
int Renko3(vars Open, vars High, vars Low, vars Close)
{
Open[0] = 0.5*(Close[1]+Open[1]);
if(Close[0] <= Open[0] - BarRange) {
Close[0] = Open[0] - BarRange;
return 1;
} else if(Close[0] >= Open[0] + BarRange) {
Close[0] = Open[0] + BarRange;
return 1;
}
return 4;
}

// Haiken Ashi Bars
int HA(vars Open,vars High,vars Low,vars Close)
{
Close[0] = (Open[0]+High[0]+Low[0]+Close[0])/4;
Open[0] = (Open[1]+Close[1])/2;
High[0] = max(High[0],max(Open[0],Close[0]));
Low[0] = min(Low[0],min(Open[0],Close[0]));
return 8;
}

// Point-and-Figure Bars
int PAF(vars Open,vars High,vars Low,vars Close)
{
static int direction = 0;
if(direction == 1 && High[0]-Close[0] >= BarRange) {
Open[0] = roundto(Low[0],BarRange);
Close[0] = roundto(High[0],BarRange);
Low[0] = Open[0];
High[0] = Close[0];
direction = 0;
return 1;
}
if(direction == 0 && Close[0]-Low[0] >= BarRange) {
Open[0] = roundto(High[0],BarRange);
Close[0] = roundto(Low[0],BarRange);
High[0] = Open[0];
Low[0] = Close[0];
direction = 1;
return 1;
}
return 4;
}

#ifndef MULTI_ASSET // single asset user bars ////////////////////

int bar() {} // dummy function to be set to the real bar function

void run()
{
bar = Renko1;
BarPeriod = 15; // determines only the number of allocated bars, not the bar period
StartDate = 20180601;
EndDate = 20180901;
LookBack = 0;
set(PLOTNOW);
// ... perform the algorithm.



#else // multi asset user bars ///////////////////////////////////

int _bar(vars Open,vars High,vars Low,vars Close); // prototype

int nextBar(vars Open,vars High,vars Low,vars Close)
{
var O[2],H[2],L[2],C[2]; // parameters for the bar function
O[0] = priceOpen(0); O[1] = Open[1];
H[0] = priceHigh(0); H[1] = High[1];
L[0] = priceLow(0); L[1] = Low[1];
C[0] = priceClose(0); C[1] = Close[1];
if(_bar(O,H,L,C) == 1) {
shift(Open,O[0],LookBack);
shift(High,H[0],LookBack);
shift(Low,L[0],LookBack);
shift(Close,C[0],LookBack);
return 1;
} else return 0;
}

void run()
{
BarPeriod = 1; // determines here the time resolution of the bar
StartDate = 20180601;
EndDate = 20180901;
LookBack = 0;
set(PLOTNOW+TICKS);

while(asset(loop("EUR/USD","GBP/USD")))
{
_bar = Renko1;
vars O = series(priceOpen(),-LookBack), // series must be static here
H = series(priceHigh(),-LookBack),
L = series(priceLow(),-LookBack),
C = series(priceClose(),-LookBack);
if(nextBar(O,H,L,C)) {
// ... perform the algorithm. Use only static series.
// Do not use indicators that internally create series.

vars Closes=series(priceClose());

if(Closes[0]>Closes[1] and NumOpenLong<1)
{
enterLong(1);
}

if(Closes[0]<Closes[1] and NumOpenShort<1)
{
enterShort(1);
}


printf("#\nNew Bar");
}
plot("Renko",C,LINE,RED);
}
}
#endif
Posted By: atr

Re: Special Bars Script - 10/27/20 09:06

Please. Does anybody have any ideas about how to perform an algorithm in the specialBars.c script for multiasset user bars?
Any help will be appreciated.
Thanks.
Posted By: atr

Re: Special Bars Script - 11/09/20 09:20

I tried to write an algo with static series in the multi asset special bars script specialBars.c. Is it correct the way I wrote the algo?

// Special bars example //////////////////////////////

#define MULTI_ASSET

var BarRange = 0.0030; // 0.3 cents bar range

// Range Bars
int Range(vars Open,vars High,vars Low,vars Close)
{
if(Open[0] != Close[1]) {
High[0] = max(Open[0],Close[1]);
Low[0] = min(Open[0],Close[1]);
Open[0] = Close[1];
}
if(High[0]-Low[0] >= BarRange)
return 1;
return 4;
}

// Renko Bars, variant 1
int Renko1(vars Open,vars High,vars Low,vars Close)
{
Open[0] = roundto(Close[1],BarRange);
if(Close[0]-Open[0] >= BarRange) {
Close[0] = Open[0]+BarRange;
High[0] = Close[0];
Low[0] = Open[0];
return 1;
}
if(Open[0]-Close[0] >= BarRange) {
Close[0] = Open[0]-BarRange;
High[0] = Open[0];
Low[0] = Close[0];
return 1;
}
return 4;
}

// Renko Bars, variant 2
int Renko2(vars Open, vars High, vars Low, vars Close)
{
var OpenDiff = abs(Close[0]-Open[1]);
var CloseDiff = abs(Close[0]-Close[1]);
if(OpenDiff < CloseDiff) // we have a valley or peak
Open[0] = Open[1];
else // we are moving with the trend
Open[0] = roundto(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;
}

// Mean Renko Bars
int Renko3(vars Open, vars High, vars Low, vars Close)
{
Open[0] = 0.5*(Close[1]+Open[1]);
if(Close[0] <= Open[0] - BarRange) {
Close[0] = Open[0] - BarRange;
return 1;
} else if(Close[0] >= Open[0] + BarRange) {
Close[0] = Open[0] + BarRange;
return 1;
}
return 4;
}

// Haiken Ashi Bars
int HA(vars Open,vars High,vars Low,vars Close)
{
Close[0] = (Open[0]+High[0]+Low[0]+Close[0])/4;
Open[0] = (Open[1]+Close[1])/2;
High[0] = max(High[0],max(Open[0],Close[0]));
Low[0] = min(Low[0],min(Open[0],Close[0]));
return 8;
}

// Point-and-Figure Bars
int PAF(vars Open,vars High,vars Low,vars Close)
{
static int direction = 0;
if(direction == 1 && High[0]-Close[0] >= BarRange) {
Open[0] = roundto(Low[0],BarRange);
Close[0] = roundto(High[0],BarRange);
Low[0] = Open[0];
High[0] = Close[0];
direction = 0;
return 1;
}
if(direction == 0 && Close[0]-Low[0] >= BarRange) {
Open[0] = roundto(High[0],BarRange);
Close[0] = roundto(Low[0],BarRange);
High[0] = Open[0];
Low[0] = Close[0];
direction = 1;
return 1;
}
return 4;
}

#ifndef MULTI_ASSET // single asset user bars ////////////////////

int bar() {} // dummy function to be set to the real bar function

void run()
{
bar = Renko1;
BarPeriod = 15; // determines only the number of allocated bars, not the bar period
StartDate = 20180601;
EndDate = 20180901;
LookBack = 0;
set(PLOTNOW);
// ... perform the algorithm.



#else // multi asset user bars ///////////////////////////////////

int _bar(vars Open,vars High,vars Low,vars Close); // prototype

int nextBar(vars Open,vars High,vars Low,vars Close)
{
var O[2],H[2],L[2],C[2]; // parameters for the bar function
O[0] = priceOpen(0); O[1] = Open[1];
H[0] = priceHigh(0); H[1] = High[1];
L[0] = priceLow(0); L[1] = Low[1];
C[0] = priceClose(0); C[1] = Close[1];
if(_bar(O,H,L,C) == 1) {
shift(Open,O[0],LookBack);
shift(High,H[0],LookBack);
shift(Low,L[0],LookBack);
shift(Close,C[0],LookBack);
return 1;
} else return 0;
}

void run()
{
BarPeriod = 1; // determines here the time resolution of the bar
StartDate = 20180601;
EndDate = 20180901;
LookBack = 0;
set(PLOTNOW+TICKS);
TradesPerBar=5;
while(asset(loop("EUR/USD","GBP/USD")))
{
_bar = Renko1;
vars O = series(priceOpen(),-LookBack), // series must be static here
H = series(priceHigh(),-LookBack),
L = series(priceLow(),-LookBack),
C = series(priceClose(),-LookBack);
if(nextBar(O,H,L,C)) {
// ... perform the algorithm. Use only static series.
// Do not use indicators that internally create series.

vars Closes=series(priceClose());
vars ClosesCurrent=series(0,-20);

if(Closes[0]<Closes[1] and NumOpenLong<1)
shift(ClosesCurrent, Closes[0],20);
{
enterLong();
}

if(Closes[0]>Closes[1] and NumOpenShort<1)
shift(ClosesCurrent, Closes[0],20);
{
enterShort();
}


printf("#\nNew Bar");
}
plot("Renko",C,LINE,RED);
}
}
#endif
Posted By: danatrader

Re: Special Bars Script - 11/09/20 10:36

I think you need to manually shift both series:

vars Closes=series(priceClose()); <--- shifting missing? Needs to be static too I guess.
vars ClosesCurrent=series(0,-20);

if(Closes[0]<Closes[1] and NumOpenLong<1)
shift(ClosesCurrent, Closes[0],20);
Posted By: atr

Re: Special Bars Script - 11/09/20 10:52

Thank you very much for your answer! How can I do that? I am lost... I tried to do vars Closes into static series but I don't know how to do that... I am just a beginner.
Posted By: danatrader

Re: Special Bars Script - 11/09/20 11:19

Since you shift ClosesCurrent, why do you use a series for Closes?
Just use a var maybe, I am beginner too wink
Posted By: atr

Re: Special Bars Script - 11/09/20 11:36

Do you think this is correct answer?

var Closes[100];
vars ClosesCurrent=series(0,-20);

if(Closes[0]<Closes[1] and NumOpenLong<1)
shift(ClosesCurrent, Closes[0],20);
{
enterLong();
}

if(Closes[0]>Closes[1] and NumOpenShort<1)
shift(ClosesCurrent, Closes[0],20);
{
enterShort();
}
Posted By: danatrader

Re: Special Bars Script - 11/09/20 22:14

To be honest, I don't know much, but I would suggest you, to start with the workshops and buy the black book.
Start with something easy, the special bars are really nice, cause based on renko you can create awesome strategies with really good returns.

But Zorro is Zorro and has all the advantages a scripting based tool brings.
Sadly, those advantages come with not being graphical.


I would love to rebuild my SC strategy here too, just I am missing the dev skills, so, move on to easier returns...
Posted By: atr

Re: Special Bars Script - 11/16/20 10:16

Thank you for your kindness. In my opinion Zorro is a powerfull and a good development tool. I don't understand why is so difficult to perform a simple algo like this one in the SpecialBars.c script. The answer should be very simple...



vars Closes = series(priceClose());
if(Closes[0]<Closes[1] and NumOpenLong<1)
{
enterLong();
}

if(Closes[0]>Closes[1] and NumOpenShort<1)
{
enterShort();
}
Posted By: jcl

Re: Special Bars Script - 11/16/20 13:49

You must declare a static series and shift it by script at any bar end. That's how the multiasset renko system is supposed to work.

Alternatively, use the current beta version. It has a new function for shifting dynamic series at the end of a special bar. Then you need not declare static series and can use normal strategies without much adaption.
Posted By: danatrader

Re: Special Bars Script - 11/16/20 14:28

http://manual.zorro-trader.com/shift
shiftSeries (int Filter)

?
Posted By: atr

Re: Special Bars Script - 11/16/20 14:36

Thank you for your answer. I am trying the current beta version 2.33.6b. Which is the new function you mentioned for shifting dynamic series? Maybe the function shiftSeries() ?
In any case, could you put some code as an example in the SpecialBars.c script? It would be very useful for beginners like me.
Thanks a lot.
Posted By: atr

Re: Special Bars Script - 11/17/20 10:58

I tried with shitSeries(int Filter) in the current beta version 2.33.6b and didn't work...

void run()
{
BarPeriod = 1; // determines here the time resolution of the bar
StartDate = 20180601;
EndDate = 20180901;
LookBack = 0;
set(PLOTNOW);

while(asset(loop("EUR/USD","GBP/USD")))
{
_bar = Renko1;

vars O = series(priceOpen(),-LookBack), // series must be static here
H = series(priceHigh(),-LookBack),
L = series(priceLow(),-LookBack),
C = series(priceClose(),-LookBack);
if(nextBar(O,H,L,C)) {
// ... perform the algorithm. Use only static series.
// Do not use indicators that internally create series.

vars Closes = series(priceClose());
shiftSeries(3);
if(Closes[0]<Closes[1] and NumOpenLong<1)

{
enterLong();
}


if(Closes[0]>Closes[1] and NumOpenShort<1)

{
enterShort();
}


printf("#\nNew Bar");
}
plot("Renko",C,LINE,RED);
}
}
#endif[color:#FF6600][/color]
Posted By: atr

Re: Special Bars Script - 11/23/20 10:07

I tried the NOSHIFT flag with the beta Zorro version 2.33.8b and didn't work. NOSHIFT is supposed to control shift dynamic series... Any ideas?


void run()
{
BarPeriod = 1; // determines here the time resolution of the bar
StartDate = 20180601;
EndDate = 20180901;
LookBack = 0;
set(PLOTNOW,NOSHIFT,TICKS);

while(asset(loop("EUR/USD","GBP/USD")))
{
_bar = Renko1;

vars O = series(priceOpen(),-LookBack), // series must be static here
H = series(priceHigh(),-LookBack),
L = series(priceLow(),-LookBack),
C = series(priceClose(),-LookBack);
if(nextBar(O,H,L,C)) {
// ... perform the algorithm. Use only static series.
// Do not use indicators that internally create series.

vars Closes = series(priceClose());

if(Closes[0]<Closes[1] and NumOpenLong<1)

{
enterLong();
}


if(Closes[0]>Closes[1] and NumOpenShort<1)

{
enterShort();
}

printf("#\nNew Bar");
}
plot("Renko",C,LINE,RED);
}
}[color:#FF6666][/color]
Posted By: jcl

Re: Special Bars Script - 11/24/20 08:11

You can use any flag in 3 ways: right way, wrong way, and the Dada way.

The difference between the last two is that when it's the wrong way, one can at least see the intention.
© 2024 lite-C Forums