Gamestudio Links
Zorro Links
Newest Posts
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
M1 Oversampling
by 11honza11. 04/20/24 20:57
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 533 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 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: 206
Germany
Smon Offline
Member
Smon  Offline
Member

Joined: Dec 2014
Posts: 206
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