Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by M_D. 04/26/24 20:22
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (M_D, AndrewAMD, Quad, Ayumi), 806 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
Indicator coding #479309
03/16/20 19:32
03/16/20 19:32
Joined: Mar 2019
Posts: 357
D
danatrader Offline OP
Senior Member
danatrader  Offline OP
Senior Member
D

Joined: Mar 2019
Posts: 357
hi alltogether,

still I am a noob, so excuse...

I try to calculate a simple indicator.

Workshop 4a is already nice, but a bit for a beginner.

May someone assist?

Indicator formula is rather primitive, it is called "Psychology Line".

PSL=UpMovementsinthelastPeriodsn/Periodsn×100

I only got some Sierra Chart code frown

Code

float Count = 0;
		if (sc.GetBarHasClosedStatus(sc.Index) == BHCS_BAR_HAS_CLOSED) {
			for (int ictr = 1; ictr <= (perioda); ictr++)
			{
				if (sc.Close[sc.Index] > sc.Close[sc.Index-ictr])
				{
					Count++;
				}
			}

			PSL[sc.Index] = (Count / (perioda)) *100.0f;
		}
		else {
			PSL[sc.Index] = PSL[sc.Index-1];
		}


Last edited by danatrader; 03/16/20 20:27.
Re: Indicator coding [Re: danatrader] #479316
03/17/20 09:02
03/17/20 09:02
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
The code would be very similar for Zorro. Only make sure that Count is an int, not a float, and find out what sc.GetBarHasClosedStatus(sc.Index) is doing.

On Financial Hacker, Petra has written a few articles about indicator coding.

Re: Indicator coding [Re: danatrader] #479325
03/18/20 07:32
03/18/20 07:32
Joined: Mar 2019
Posts: 357
D
danatrader Offline OP
Senior Member
danatrader  Offline OP
Senior Member
D

Joined: Mar 2019
Posts: 357
sc.Index is an array called once per bar.

if (sc.GetBarHasClosedStatus(sc.Index) == BHCS_BAR_HAS_CLOSED) is just making sure the actual bar is closed, since SC offers many different bars.

More simple pine script from tradingview:

xPSY = sum(close > close[1],Length) / Length * 100


Actually the indicator is so simple, but really great for trend determination, so if someone could help out would be awesome (I don't expect JCL to do so, since I assume he has his hands full with things to do).

But thank you a lot.

Re: Indicator coding [Re: danatrader] #479327
03/18/20 08:58
03/18/20 08:58
Joined: Apr 2008
Posts: 586
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 586
Austria
I am not 100% sure but believe the pinescript is not the same as the sierra code. The sierra code sums up by differences to the current close but the pinescript sums up by differences of subsequent closes.

In Zorro: SumUp(series(priceClose()),Length) / Length * 100;


Re: Indicator coding [Re: danatrader] #479329
03/18/20 12:42
03/18/20 12:42
Joined: Mar 2019
Posts: 357
D
danatrader Offline OP
Senior Member
danatrader  Offline OP
Senior Member
D

Joined: Mar 2019
Posts: 357
The SC code is from a really great futures / SC devleoper from Czech.
Sadly he won't share all, (which I understand fully).

So, the code from Sierra I assume is better (since I veryfied it graphically in the past).

In Zorro: SumUp(series(priceClose()),Length) / Length * 100; -> is the pince script version?
I will giv it a try, actually I was already working with SumUp, but didn't get it fully.

Thank you Petra.


BTW, this indicator allows to do really nice things, since most indicators may be piped through.
And it is almost realtime and really "cheap" in calculation costs.

Last edited by danatrader; 03/18/20 12:46.
Re: Indicator coding [Re: danatrader] #480303
05/30/20 21:41
05/30/20 21:41
Joined: Mar 2019
Posts: 357
D
danatrader Offline OP
Senior Member
danatrader  Offline OP
Senior Member
D

Joined: Mar 2019
Posts: 357
Psychological Line is an indicator developed by Ken Muranaka

The indicator’svalues may range from 0 to 100. It is a simple indicator which shows the numberof increasing/decreasing prices over a specified period; thereby is a means for deter-mining the overbought/oversold price level.
The standard calculation of theindicator is as follows:

PSL = n / 12 * 100

where n is the number of days that the price is closed higher than the previous period.

n and the number of comparison days (i.e. 12) in the above calculation are subject to change.

https://www.questia.com/magazine/1G1-63024940/opinion-oscillator

Last edited by danatrader; 05/30/20 22:20.
Re: Indicator coding [Re: danatrader] #480412
06/05/20 09:29
06/05/20 09:29
Joined: May 2015
Posts: 390
Czech Republic
G
Grat Offline
Senior Member
Grat  Offline
Senior Member
G

Joined: May 2015
Posts: 390
Czech Republic
not nice, but working

Code
#define _SUM_PLUS  0         // register for AssetInt
#define _SUM_MINUS 1         // register for AssetInt

//---------------- indicator -----------------------------

double idxPL(){
    int sumUP = AssetInt[_SUM_PLUS];
    int sumDN = AssetInt[_SUM_MINUS];
    var pl=0;
	if (priceClose() > priceClose(1)){
        sumUP++;
        sumDN=0;
        pl=(sumUP/12.0)*100;
    }
	
	if (priceClose() < priceClose(1)){
        sumUP=0;
        sumDN++;
        pl=-(sumDN/12.0)*100;
    }
	//watch("\n",sumDN,sumUP,pl);
    AssetInt[_SUM_PLUS] = sumUP;
    AssetInt[_SUM_MINUS]= sumDN;
	
    return pl;
		
}


function run()
{

	set(PLOTNOW+LOGFILE);
    //set(STEPWISE);
	StartDate=2020;
	BarPeriod = 60;
	LookBack = 1;
	
	PlotScale = 8;
	PlotWidth = 1600;
	PlotHeight1 = 600;
	PlotHeight2 = 120;
    assetList("Assets");
    if (is(INITRUN)){
        assetHistory(Asset,1);
    }

	vars aPL = series(idxPL());
	plot("PLine",aPL,NEW,BLUE);
		 		  
}

Last edited by Grat; 06/05/20 09:30.
Re: Indicator coding [Re: danatrader] #480423
06/06/20 05:50
06/06/20 05:50
Joined: Mar 2019
Posts: 357
D
danatrader Offline OP
Senior Member
danatrader  Offline OP
Senior Member
D

Joined: Mar 2019
Posts: 357
It goes into the direction, thank you, I will continue working on it.
Thats a good start I have right here.

Thank you both Grat and Petra.

Re: Indicator coding [Re: danatrader] #480424
06/06/20 07:08
06/06/20 07:08
Joined: Mar 2019
Posts: 357
D
danatrader Offline OP
Senior Member
danatrader  Offline OP
Senior Member
D

Joined: Mar 2019
Posts: 357
Did receive another snippet of code from the original developer... the thing is, of course it should be smoothed, but somehow calculations don't fit, it should move btween 0 and 100.
i will work on it, and crack it, I now have some approaches availabel, thanks to all again (sadly I am still fighting myself into it).

Seems like having winning ideas is so easy, coding so difficult laugh

// definition
Length1.Name = "Psychological area period";
Length1.SetInt(30);
Length1.SetIntLimits(1, MAX_STUDY_LENGTH);


//body
int &perioda = sc.GetPersistentInt(1);
perioda = Length1.GetInt();






//example output
//2: ATR Simple
if (CalculationMethod.GetIndex() == 2) {
sc.ATR(sc.BaseDataIn, outputID, Lengthfirst.GetInt(), MOVAVGTYPE_SIMPLE);
}




//PSL
for (int ictr = 1; ictr <= (perioda); ictr++)
{
if (outputID[sc.Index] > outputID[sc.Index - ictr])
{
Count = Count + 1.0f;
}
}

PSL[sc.Index] = (Count / (perioda)) *100.0f;

Last edited by danatrader; 06/06/20 07:10.
Re: Indicator coding [Re: danatrader] #480426
06/06/20 11:21
06/06/20 11:21
Joined: May 2015
Posts: 390
Czech Republic
G
Grat Offline
Senior Member
Grat  Offline
Senior Member
G

Joined: May 2015
Posts: 390
Czech Republic
This indicator / original is not good for FX. Becouse calculate only the LONG. If is a downtrend, show zero. ( from head ). For this I have a modification (-100;100)

Re: Indicator coding [Re: danatrader] #480427
06/06/20 11:33
06/06/20 11:33
Joined: May 2015
Posts: 390
Czech Republic
G
Grat Offline
Senior Member
Grat  Offline
Senior Member
G

Joined: May 2015
Posts: 390
Czech Republic
Depend on the theory:

Psychological Line is an indicator developed by Ken Muranaka.
The indicator’s values may range from 0 to 100. It is a simple indicator which shows the number of increasing/decreasing prices over a specified period; thereby is a means for deter- mining the overbought/oversold price level. The standard calculation of the indicator is as follows:

PI= n/12 ∗100

where n is the number of days(period) that the price is closed higher than the previous period.
n and the number of comparison days (i.e. 12) in the above calculation are subject to change.

[Linked Image]

Attached Files
Last edited by Grat; 06/06/20 11:37.
Re: Indicator coding [Re: danatrader] #480428
06/06/20 11:35
06/06/20 11:35
Joined: Mar 2019
Posts: 357
D
danatrader Offline OP
Senior Member
danatrader  Offline OP
Senior Member
D

Joined: Mar 2019
Posts: 357
Yes, I was originally thinking that for the Sierra Chart developer too, but a nice effect can be achieved by just switching the length of the comparision period with indicator period.
Then it would be somewhat upside down.

I will try your way, actually it needs to be smoothed, anyway, I will work on it a bit.

it is a nice sample for me to learn more coding and the behaviour of Zorro.

Just I don't get, how I would let the sumDN / sumUP shift, since comparing the complete periods is not so good.
The periods compared should be created by HTDcPeriod / DominantPeriod.

Re: Indicator coding [Re: danatrader] #480429
06/06/20 11:38
06/06/20 11:38
Joined: May 2015
Posts: 390
Czech Republic
G
Grat Offline
Senior Member
Grat  Offline
Senior Member
G

Joined: May 2015
Posts: 390
Czech Republic
Yes, for this I not finish, me code is only draft. Now I work on finish version.

Re: Indicator coding [Re: danatrader] #480430
06/06/20 11:53
06/06/20 11:53
Joined: Mar 2019
Posts: 357
D
danatrader Offline OP
Senior Member
danatrader  Offline OP
Senior Member
D

Joined: Mar 2019
Posts: 357
I promise you, it is so simple logic, but you can pipe anything through and it is really powerful.

E.g. preprocess Data with only candles matching a given ATR condition.

NumWhiteBlack(ATR(24)/3, 0, 1) or the moving average of it.
And so on...

Just my plot looks different from yours, I assume you did already change the code postet before.

Last edited by danatrader; 06/06/20 12:02.
Re: Indicator coding [Re: danatrader] #480440
06/06/20 19:04
06/06/20 19:04
Joined: Mar 2019
Posts: 357
D
danatrader Offline OP
Senior Member
danatrader  Offline OP
Senior Member
D

Joined: Mar 2019
Posts: 357
Grat,

I think there is something not as it should be, look at the plot below.
I did try already to change your code, eventually I will get it done, just if you say yours is not nice, mine will be horrible.... laugh

double idxPL(){
int sumUP = AssetInt[_SUM_PLUS];
int sumDN = AssetInt[_SUM_MINUS];
var pl=0;
if (priceClose() > priceClose(1)){
sumUP++;
sumDN=0;
pl=(sumUP/12.0)*100;
}

if (priceClose() < priceClose(1)){
sumUP=0;
sumDN++;
pl=-(sumDN/12.0)*100;
}
//watch("\n",sumDN,sumUP,pl);
AssetInt[_SUM_PLUS] = sumUP;
AssetInt[_SUM_MINUS]= sumDN;

return pl;

}


I think it goes too sharp down, as far I understand, the code above returns either the minus count or the plus count.
But in case to make your idea work with the down count, ther must be something like sumUP-sumDN if sumUP is bigger than sumDN, and the other way round sumDown - sumUP if sumDN is bigger than sumUP.

Of course only, if the opposite bar / close occurs.



Attached Files
PSL-Plot.png (13 downloads)
Last edited by danatrader; 06/07/20 05:29.
Re: Indicator coding [Re: danatrader] #480450
06/07/20 05:45
06/07/20 05:45
Joined: Mar 2019
Posts: 357
D
danatrader Offline OP
Senior Member
danatrader  Offline OP
Senior Member
D

Joined: Mar 2019
Posts: 357
How would I make it to oscillate between 100 and 0.
For me it is about also about understanding the tool (Zorro functions).

The version of Petra is simple, just it goes beyond 100 as max. value.
So I would just use the Max function?

Re: Indicator coding [Re: danatrader] #480451
06/07/20 06:50
06/07/20 06:50
Joined: May 2015
Posts: 390
Czech Republic
G
Grat Offline
Senior Member
Grat  Offline
Senior Member
G

Joined: May 2015
Posts: 390
Czech Republic
theory:

Quote
where n is the number of days(period) that the price is closed higher than the previous period.


but

zorro fce sumUp - not calculate how many is close Price higher the price older, but sumOfprice if is highers

Code
var vUp, vDn;
var ProfitFactor(var* Data,int Length)
{
	vUp = 0.,vDn = 0.;
	for(int i=1; i<Length; i++) {
		if(Data[i-1] > Data[i])
			vUp += Data[i-1]-Data[i];
		else
			vDn += Data[i]-Data[i-1];
	}
	if(vDn == 0.) 
		return vUp == 0.? 1. : 10.;
	return Clamp(vUp/vDn,0.,9.999);
}

var SumUp(var* Data,int Length)
{
	ProfitFactor(Data,Length);
	return vUp;
}

Re: Indicator coding [Re: danatrader] #480453
06/07/20 06:56
06/07/20 06:56
Joined: Mar 2019
Posts: 357
D
danatrader Offline OP
Senior Member
danatrader  Offline OP
Senior Member
D

Joined: Mar 2019
Posts: 357
That is I assume it would need before the SumUp this

if (priceClose() > priceClose(1)){

still I really need the original version.

Can we get there together?
I can then show you why.

BTW, can you crack the EUR/CAD laugh

Re: Indicator coding [Re: danatrader] #480454
06/07/20 07:28
06/07/20 07:28
Joined: Mar 2019
Posts: 357
D
danatrader Offline OP
Senior Member
danatrader  Offline OP
Senior Member
D

Joined: Mar 2019
Posts: 357
But even using the code from Petra, I don't get it oscillating between 0 and 100.
What would I need to do to get it / any line oscillating between 0 / 100?

Re: Indicator coding [Re: danatrader] #480455
06/07/20 07:35
06/07/20 07:35
Joined: May 2015
Posts: 390
Czech Republic
G
Grat Offline
Senior Member
Grat  Offline
Senior Member
G

Joined: May 2015
Posts: 390
Czech Republic
I don't know, how looking the original idx. Like this?

Attached Files
Re: Indicator coding [Re: Grat] #480456
06/07/20 08:51
06/07/20 08:51
Joined: Mar 2019
Posts: 357
D
danatrader Offline OP
Senior Member
danatrader  Offline OP
Senior Member
D

Joined: Mar 2019
Posts: 357
You mean original in Sierra Chart, or original Petra or original your code implementation?

Re: Indicator coding [Re: danatrader] #480460
06/07/20 09:18
06/07/20 09:18
Joined: May 2015
Posts: 390
Czech Republic
G
Grat Offline
Senior Member
Grat  Offline
Senior Member
G

Joined: May 2015
Posts: 390
Czech Republic
Original Sierra chart

Re: Indicator coding [Re: danatrader] #480464
06/07/20 17:55
06/07/20 17:55
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

Attached Files
xcor4_PL.c (11 downloads)
Re: Indicator coding [Re: danatrader] #480518
06/12/20 10:09
06/12/20 10:09
Joined: May 2015
Posts: 390
Czech Republic
G
Grat Offline
Senior Member
Grat  Offline
Senior Member
G

Joined: May 2015
Posts: 390
Czech Republic
I found also this:

NumRiseFall(vars Data, int TimePeriod): var

Middle Blue line

Attached Files
Last edited by Grat; 06/12/20 10:17.
Re: Indicator coding [Re: danatrader] #480525
06/12/20 16:54
06/12/20 16:54
Joined: Mar 2019
Posts: 357
D
danatrader Offline OP
Senior Member
danatrader  Offline OP
Senior Member
D

Joined: Mar 2019
Posts: 357
Thank you Grat, I can learn a lot from you laugh

Page 1 of 3 1 2 3

Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1