Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
EasyLanguage. Code for no script action when condition is met. NT8 Return equivalence
I’m trying to find an EasyLanguage example about how to work the cases where you want the script doesn’t execute any action of the code (any action of the main logic) when a kind of “general” condition is met, even if the rest of the code contains other conditions that could do certain actions during that general condition. But I’m unable to find examples that covers this kind of cases.
For example, in NinjaScript when you want a strategy doesn’t do anything under a certain general condition, like for example not to place trades on Sundays, then a way to get this is with:
And with this simple code as a general condition, then the strategy won’t execute any action when this condition is true, even if the entry condition is met.
Of course I understand that for this specific simple example, in EasyLanguage you could do the opposite with something like:
But that was just a very simple example, just to illustrate the idea, because I need this for other kind of situations (but with a similar base).
By the way, I tried with something like:
But it shows a compilation error saying that “Return keyword can be used only inside a method”, so it seems that `Return` couldn’t be used in the exact way as used in the given NinjaTrader example here, and if possible the idea would be to have an equivalence in a kind of simple and efficient way just as the ` Return` example here.
Thank you for any help
Can you help answer these questions from other members on NexusFi?
you would have to move parts of your code inside a method if you want to be able to use the return statement. The approach @kevinkdog shared will do exactly what you have in mind while sticking to legacy EasyLanguage principles and a method might not give you any benefit here.
Regards,
ABCTG
futurenow
Hello
I’m trying to find an EasyLanguage example about how to work the cases where you want the script doesn’t execute any action of the code (any action of the main logic) when a kind of “general” condition is met, even if the rest of the code contains other conditions that could do certain actions during that general condition. But I’m unable to find examples that covers this kind of cases.
For example, in NinjaScript when you want a strategy doesn’t do anything under a certain general condition, like for example not to place trades on Sundays, then a way to get this is with:
if (Time[0].DayOfWeek == DayOfWeek.Sunday)
return;
And with this simple code as a general condition, then the strategy won’t execute any action when this condition is true, even if the entry condition is met.
Of course I understand that for this specific simple example, in EasyLanguage you could do the opposite with something like:
If Dayofweek <> 0 Then
// you can trade
But that was just a very simple example, just to illustrate the idea, because I need this for other kind of situations (but with a similar base).
By the way, I tried with something like:
If Dayofweek = 0 Then
Return;
But it shows a compilation error saying that “Return keyword can be used only inside a method”, so it seems that `Return` couldn’t be used in the exact way as used in the given NinjaTrader example here, and if possible the idea would be to have an equivalence in a kind of simple and efficient way just as the ` Return` example here.
OP didn't mention whether the EL was on TradeStation or MultiCharts, but if MultiCharts, there is support for the #Return keyword that doesn't exist on TradeStation.
If on TradeStation, what the others mentioned already is great though I still have always wondered why TS never provided a way to "return early and often" .
OP didn't mention whether the EL was on TradeStation or MultiCharts, but if MultiCharts, there is support for the #Return keyword that doesn't exist on TradeStation.
If on TradeStation, what the others mentioned already is great though I still have always wondered why TS never provided a way to "return early and often" .
you would have to move parts of your code inside a method if you want to be able to use the return statement. The approach @kevinkdog shared will do exactly what you have in mind while sticking to legacy EasyLanguage principles and a method might not give you any benefit here.
As you say, in this case the @kevinkdog answer works well.
About to work with a Method, in EasyLanguage I haven't yet tried specifically using an empty Return specifying no variable value as returned result from the Method, with the idea to avoid running any script process when the condition inside the Method is met, but I think it could also work for that purpose.