Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (TipmyPip, AndrewAMD, Quad, aliswee, degenerate_762), 970 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
static variable #477216
05/31/19 18:32
05/31/19 18:32
Joined: Feb 2018
Posts: 68
T
tomaslolo Offline OP
Junior Member
tomaslolo  Offline OP
Junior Member
T

Joined: Feb 2018
Posts: 68
Hi all, I want to create a custom RSI indicator that just plots besides price series.

As you know RSI values go from 0 to 100 so if I want to plot it together with price series I need to multiply its value. So I want to create a multiplier.

This multiplier would get the first RSI value of the series and first priceClose value and divide them, so it will store a double variable (var?). As this variable must remain unchanged has to be declared as static (global?).

It will also take the first value of the series so has to be calculated at FIRSTRUN.

Obviously I´m doing it wrong as I get a few different error messages and I´m stucked. This is my code:
Code:
// PRUEBA DE MULTIPLICADOR ////////////////

var multiplier=0.0;

function run() 
{
	StartDate = 20160101; // 20160101
	//EndDate = 20170301;
	EndDate = 20181231;
	BarPeriod = 5;	// 1 hour
	LookBack = 200;

	asset("EUR/USD"); //"EUR/USD"
	
	if(is(FIRSTRUN)){
	vars myRSI=series(RSI(priceClose,100));
	static var multiplier=(priceClose(0)/myRSI[0]);
	}
	
	vars myRSI=series(RSI(priceClose,100));
	//var multiplier=priceClose(0)/myRSI[0]; this one would change multiplier value at every new bar, so delete it.
	vars myPrice=series(myRSI[0]* multiplier);
	

// plot signals and thresholds

   plot("myPrice", myPrice, 0, RED);
	
	PlotWidth = 600;
	PlotHeight1 = 300;
	set(PLOTNOW);
}



Any clues?

Thank you in advanced.

Re: static variable [Re: tomaslolo] #477219
06/01/19 11:10
06/01/19 11:10
Joined: Dec 2014
Posts: 204
Germany
Smon Offline
Member
Smon  Offline
Member

Joined: Dec 2014
Posts: 204
Germany
This might put you back on track:

Code:
// PRUEBA DE MULTIPLICADOR ////////////////

var multiplier=0.0;

function run() 
{
	StartDate = 20160101; // 20160101
	//EndDate = 20170301;
	EndDate = 20181231;
	BarPeriod = 5;	// 1 hour
	LookBack = 200;

	asset("EUR/USD"); //"EUR/USD"
	
	
	static var multiplier=1;

	vars Price = series(priceClose());
	
	var myRSI = RSI(Price, 100);
	
	static int neverplotted = 1;
	
	if(!is(LOOKBACK) && neverplotted) 
	{
		neverplotted = 0;
		printf("nmyRSI = %.1f, multiplier before set = %.1f, priceClose() = %.5f", myRSI, multiplier, priceClose());
		multiplier=priceClose()/myRSI;
		printf("nmultiplier after set = %.5f", multiplier);
	}
	
	//var multiplier=priceClose(0)/myRSI[0]; this one would change multiplier value at every new bar, so delete it.
	vars myPrice=series(myRSI*multiplier);
	
	//if(!is(INITRUN)) printf("nmultiplier = %.5f, Price[0] = %.5f, myRSI = %.0f, myPrice[0] = %.5f", multiplier, Price[0], myRSI, myPrice[0]);
	

// plot signals and thresholds

   plot("myPrice", myPrice, 0, RED);
	
	PlotWidth = 600;
	PlotHeight1 = 300;
	set(PLOTNOW);
}


Re: static variable [Re: Smon] #477232
06/03/19 21:10
06/03/19 21:10
Joined: Feb 2018
Posts: 68
T
tomaslolo Offline OP
Junior Member
tomaslolo  Offline OP
Junior Member
T

Joined: Feb 2018
Posts: 68
It does.

Thank you very much!


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1