How to check when live or demo in script?

Posted By: Mr_Rob

How to check when live or demo in script? - 11/09/19 15:39

I want to be able to send my .x script for others to test. I want it to only work in demo mode. If tried to go live, It will execute the quit() function.

Tried browsing the manual but couldn't find what I was looking for.

Any ideas on how to get zorro to know if its in live mode or demo mode? if live, then quit();
Posted By: Grant

Re: How to check when live or demo in script? - 11/09/19 16:15

By using the DEMO status flag like:
Code
if(is(!DEMO)) 
    {
    quit();
    }


Posted By: Mr_Rob

Re: How to check when live or demo in script? - 11/09/19 17:00

Originally Posted by Grant
By using the DEMO status flag like:
Code
if(is(!DEMO)) 
    {
    quit();
    }




I'll give this try. I'm curious if this will interfere with backtesting as it will neither be live nor demo
Posted By: Grant

Re: How to check when live or demo in script? - 11/09/19 17:12

It's only account related, so it should work laugh
Posted By: AndrewAMD

Re: How to check when live or demo in script? - 11/09/19 17:23

It should **not** work because the exclamation point "!" is in the wrong place!

Before:
Code
if(is(!DEMO)) 
    {
    quit();
    }
After:
Code
if(!is(DEMO)) 
    {
    quit();
    }


Here's a better code sample:
Code
void run(){
	if(is(DEMO)){
		printf("\nDEMO flag is ON");
	}
	else{
		printf("\nDEMO flag is OFF");
	}
	quit("#Done.");
}


Also, the description of DEMO is:
Quote
A demo account is selected through the [Account] scrollbox.
It does not care what mode you are in.
Posted By: Grant

Re: How to check when live or demo in script? - 11/09/19 19:10

My bad, thanks!
© 2024 lite-C Forums