I am working with SAR() and I noticed the manual says "Provisionally implemented; uses the current asset price series and supports a single asset only"
Is it difficult to adjust SAR() to work in a multi-asset loop? Otherwise, do you know of a workaround or similar indicator?
Thanks
Re: can SAR() be more fully implemented?
[Re: dusktrader]
#439141 03/27/1415:3703/27/1415:37
It can not be adjusted because it's sloppy implemented in the TA-Lib, using a static variable. Thus it can never support more than one asset. But of course, the SAR can be rewritten in lite-C and included in the indicators.c library. Maybe a user can do this?
Re: can SAR() be more fully implemented?
[Re: jcl]
#439197 03/28/1412:5003/28/1412:50
var PSAR(var AF, var Max)
{
static var psar0;
static var psar1;
static int lng;
static var af;
static var ep;
static var hp;
static var lp;
if (is(INITRUN))
{
lng = 1; //assume long for initial conditions
af = AF; //init acelleration factor
psar0 = 0;
psar1 = 0;
ep = 0;
hp = 0;
lp = 0;
return; // do not run on bar 0
}
if (Bar == 1)
{
psar0 = priceClose(0); // initialise
psar1 = priceClose(0);
ep = priceHigh(0); // init extreme point as assuming long
hp = priceHigh(0);
lp = priceLow(0);
return psar0;
}
if (lng == 1) psar0 = psar1 + af * (hp - psar1);
else psar0 = psar1 + af * (lp - psar1);
int reverse = 0;
if (lng == 1) //check for reversal
{
if (priceLow(0) < psar0)
{
lng = 0;
reverse = 1; //reverse position to short
psar0 = hp;
lp = priceLow(0);
af = AF;
}
}
else
{
if (priceHigh(0) > psar0)
{
lng = 1;
reverse = 1; //reverse position to long
psar0 = lp;
hp = priceHigh(0);
af = AF;
}
}
if (reverse == 0)
{
if (lng == 1)
{
if (priceHigh(0) > hp)
{
hp = priceHigh(0);
af += AF;
af = min(af,Max);
}
psar0 = min(psar0, min(priceLow(1),priceLow(2)));
}
else
{
if (priceLow(0) < lp)
{
lp = priceLow(0);
af += AF;
af = min(af,Max);
}
psar0 = max(psar0,max(priceHigh(1),priceHigh(2)));
}
}
psar1 = psar0;
return psar0;
}
I'm thinking not, though I haven't had time to play with this yet. The issue, as I understand, is that the static variables need to be linked to the asset. When you use static vars inside the function, that would imply every time the function is called, it refers back to the same static history (regardless of the asset -- which is a problem because every iteration of Zorro would be flipping through multiple assets)
So to fix it, I think the function either needs to somehow be re-written not to use static vars (if even possible), or use static storage that is linked to the asset. AlgoVar is one potential option (those are statics linked to each asset) but since they are in limited supply (only 8 i think)... then it doesn't seem ideal.
Thanks for posting this code. It's a good starting point. Perhaps I can play around with this and see if I can come up with anything.
Re: can SAR() be more fully implemented?
[Re: dusktrader]
#439205 03/28/1416:4303/28/1416:43
You can either use AlgoVar, or a series. Both are asset linked. As far as I can see from the above code, most of those variables need not be static anyway.
Re: can SAR() be more fully implemented?
[Re: jcl]
#446483 10/17/1403:5210/17/1403:52
Thank you everyone for your suggestions and effort. Zorro team, any news on the PSAR? I think it's very important for any serious trading platform to have a proper implementation of the Parabolic SAR.
Alternatively, is there a way to use the PSAR from MT4 through the bridge if Zorro does not make it available natively?
Re: can SAR() be more fully implemented?
[Re: mustang]
#446541 10/20/1417:2710/20/1417:27
It's certainly easier to write a PSAR in lite-C than using the MT4 bridge for it. But for us there was no reason for implementing a PSAR in lite-C so far. We have not yet seen that it could be used for a profitable system.
Re: can SAR() be more fully implemented?
[Re: jcl]
#446546 10/20/1418:0310/20/1418:03
Sure. Use the ta-lib SAR, do a profitable system with it, and we'll implement at once a lite-C SAR. If an indicator can be shown to be useful in any way, you'll normally get it.