NexusFi: Find Your Edge


Home Menu

 





Switches in function


Discussion in EasyLanguage Programming

Updated
    1. trending_up 1,119 views
    2. thumb_up 1 thanks given
    3. group 4 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
Linow
Odense, Denmark
 
Posts: 3 since May 2021
Thanks Given: 1
Thanks Received: 0

HI I´m trying code a function that has some switches so that I can finde the best filter.
Am I right that is a Boolean type?
I can´t get it to work, some one that knows what I´m missing here?

Input: Filter (numeric);

Switch ( Filter )
Begin
Case 0: xFilter= True;
Case 1: xFilter= Close < Average(Close, 5);
Case 2: xFilter= ADX(5) > 25;
Case 3: xFilter= (Volume > Average(Volume, 5));
End;

xFilter = True;


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Strike Pause Holds, Oil Erases Monday Spike -- May CPI W …
Traders Hideout
The May 31 Binary: 60% Trump Declares Iran Ops Over, Onl …
Prediction Markets & Event Contracts
June 15 Peace Odds Surge From 3.6% to 12.25% After Trump …
Prediction Markets & Event Contracts
Wood Mackenzie Drops $200 Oil Forecast -- Airspace Expir …
Prediction Markets & Event Contracts
Iran Deal "In Review" at 87% on Deadline Day - …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Big Mike in Ecuador
196 thanks
Sober Journey With S&P
27 thanks
30 Sessions
20 thanks
Volume Indicators
8 thanks
BERN ALGOS algo trading journal
8 thanks
  #2 (permalink)
 bfulks 
Boston MA
 
Experience: Advanced
Platform: TradeStation
Trading: Stocks and options
Posts: 24 since Aug 2022
Thanks Given: 2
Thanks Received: 4

You are mixing variable types; Try this:

Input: Filter (numeric); // values = 0, 1 , 2, 3, ...
Vars: xFilter(False);

Switch ( Filter )
Begin
Case 0: xFilter= True;
Case 1: xFilter= Close < Average(Close, 5);
Case 2: xFilter= ADX(5) > 25;
Case 3: xFilter= (Volume > Average(Volume, 5));
End;

Bob


Reply With Quote
  #3 (permalink)
Linow
Odense, Denmark
 
Posts: 3 since May 2021
Thanks Given: 1
Thanks Received: 0


Hi Bob

Vars: xFilter(False);
I keep getting: A value was never assigned to user funtion

Do I not need a return value?
It keeps turnning of the strategy when I´m testing it...

Thomas


Reply With Quote
  #4 (permalink)
 TraderDoc2 
Plainview
 
Experience: Intermediate
Platform: TradeStation
Broker: TradeStation
Trading: Futures
Posts: 37 since Mar 2012
Thanks Given: 2
Thanks Received: 22

Here is a simple function and strategy that you can test. The function must have a Boolean (True/False) Return Type. You will optimize the strategy with filter values varying from 0 to 3.
I think that this should work. Give it a try.

 
Code
{Function: NexusFi_Test_1}

Input: Filter (numeric); 
Vars: xFilter(False);

Switch ( Filter )
Begin
Case 0: xFilter= True;
Case 1: xFilter= Close < Average(Close, 5);
Case 2: xFilter= ADX(5) > 25;
Case 3: xFilter= (Volume > Average(Volume, 5));
End;

NexusFi_Test_1 = xFilter;


{Strategy: Test.NexusFi.1}

Input: Filter (1); // values = 0, 1 , 2, 3, ...
Vars: MyBoolean(False);

MyBoolean = NexusFi_Test_1(Filter);

If MyBoolean then Buy next bar at market;
If Not MyBoolean then Sell Short next bar at market;


Follow me on X Reply With Quote
Thanked by:
  #5 (permalink)
Linow
Odense, Denmark
 
Posts: 3 since May 2021
Thanks Given: 1
Thanks Received: 0

Thanks TraderDoc2


Reply With Quote




Last Updated on October 3, 2023


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts