How to change an input value WITHIN a strat ?

Questions about MultiCharts and user contributed studies.
User avatar
ym
Posts: 53
Joined: 26 Feb 2010

How to change an input value WITHIN a strat ?

Postby ym » 07 Mar 2010

How may I change an input value from within a strategy ?
Something like that :

Code: Select all

inputs:
MaxRisk$(10);

// code starts here :
if MaxRisk$ < 10 then MaxRisk$ = 10;
etc ... etc ...
// end of code
Thanks for any suggestion.
Yann

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 07 Mar 2010

You can not change an input on the fly unless you are using a GV for input as I often do. Just make a variable copy like below.

Code: Select all

inputs:
MaxRisk$(10);

Variable: WorkMaxRisk(0);

// code starts here :

If CurrentBar = 1 then
begin
WorkMaxRisk = MaxRisk$;
{Note that MaxRisk$ is no longer referenced}
if WorkMaxRisk < 10 then WorkMaxRisk = 10;
end;

etc ... etc ...
// end of code
Last edited by bowlesj3 on 07 Mar 2010, edited 1 time in total.

User avatar
ym
Posts: 53
Joined: 26 Feb 2010

Postby ym » 07 Mar 2010

John,

That's what I wanted to avoid (having to use a 'replica' variable, be it a standard one or a GV) ...

I thought there would be a 'trick' to change directly the input value ...

Sigh ;-)

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 07 Mar 2010

You get an error. No tricks here. You will never notice the extra time it takes. Maybe .00000000000001 of a second. You would normally limit it to the first bar.

Actually I do not duplicate my inputs with GVs (normally). I just replace them. That way I can change an input from my database program and kick off a recalculate just after.

I have an RSI study that recalculates a lot because I put new historic plots on it. When I wrote it I could not figure out how to get a line on the study. Now I know. Eventually I want to try a rewrite to see if putting new lines on and taking them off constantly is faster. However it is a lot of work so this things does at least 1000 recalcualtes a day.
Last edited by bowlesj3 on 07 Mar 2010, edited 1 time in total.

User avatar
ym
Posts: 53
Joined: 26 Feb 2010

Postby ym » 07 Mar 2010

Matter of fact, that was PURE LAZINESS (shame on me) ...
I didn't want to REWRITE my code !!!
---
To achieve that goal, I think I'll rather use normal 'in-code' standard variables than GV ...
Guess that'll process a bit faster (maybe a dozen of inputs or so are concerned).

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 07 Mar 2010

Ouch! Being a trader and Lazy do not mix! It will cure laziness pretty quick. You are pretty much on your own in this business. Other traders are glued ot their screens most of the time and you can not trust other peoples system's. You have to find what works for you. You get forum help when others have nothing better to do at that moment (so for the most part we have to figure stuff out on our own - like 99.999% of the time).

User avatar
ym
Posts: 53
Joined: 26 Feb 2010

Postby ym » 07 Mar 2010

don't misunderstand me, I also spend 100% of my day-time and 50% of my night-time coding strats ...
I would then requalify my laziness as 'selective' laziness :
"why wasting time on unessential matters wheras important things await you to tackle them !"

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 07 Mar 2010

Sounds very good YM. Trading is a fun challenge.

User avatar
Bruce DeVault
Posts: 438
Joined: 19 Jan 2010
Location: Washington DC
Been thanked: 2 times
Contact:

Postby Bruce DeVault » 08 Mar 2010

Input is short for "input parameter". And a parameter, by definition, is something that DOESN'T CHANGE during the course of a test. A trading platform that allowed you to change an input parameter during the course of a test would have a defect, in that it would lead to results that could be misinterpreted by those who assumed that the inputs were in fact parametric. Anything that can change during the course of a test should in an EasyLanguage context be handled as a numeric series. In the case of "enforced minimum" values for input parameters specifically, you have two basic choices - mirror it into a new variable and enforce the minimum there, or simply throw an error at startup thus informing the user there is a problem and what the problem is.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 08 Mar 2010

Hey Ym,

Bruce has an amazing way (amazing ability) of wording things to get me to put my thinking cap on.

Yes YM. Now that I think about it I agree with Bruce. If you are going to be forcing your input to a different value than the one you set on the chart where your study is loaded it probably would be good to put out an alert to remind you that this is happening. I think that is what Bruce is saying. If that alert reminder is bugging you too much maybe limit it to once a week or once a month. Maybe a reminder as to why you want this restriction. LOL. Whatever. Life is good. Such fun.

The main thing about trading is it has been proven that the best traders have a sense of humour. If they do not they just can't last. I keep working on it. Getting better as I get older.

John.

User avatar
Bruce DeVault
Posts: 438
Joined: 19 Jan 2010
Location: Washington DC
Been thanked: 2 times
Contact:

Postby Bruce DeVault » 08 Mar 2010

Thank you for your kind words. Regarding notification that an input is out of bounds, if you would like it fixed immediately, consider using the keyword RaiseRunTimeError("Your message here"); to stop the strategy from running, forcing the user to fix the value that is out of range.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 08 Mar 2010

Sometimes the word input might have an implied meaning that could cause one to limit its use too much. I try not to restrict myself. Here is an example.

I use the bollinger bands. They are suppose to be adjusted at times. It is true. Often you can see a turn in the market close to a band and if you adjust the band to it (takes a few tries to get it right) just like magic you can find that with this new adjustment prices will bounce off the band later on (sometimes perfectly at that adjustment). Try to do that with a computer loop and you will find MC bombs (tried that and no cigar on that) (besides the code is not simple to write for this and there are times you can visually see other factors that make doing this adjustment very questionable - down right dumb) So it is pretty much a manual operation that only the human mind and eyes can decide correctly on. MC inputs are way to slow for this operation so I send GVs to get the job done quickly. Besides I store a history in a database of all these finalized adjustments and I can jump back to any record in that history with a simple single button click. Now is this an input as Bruce describes it? I don't know. My thinking cap hasn't been able to give me that answer on this question. For me it is simply a solution to a problem. You have to adjust the input (or whatever it is) and recalculate. There is absolutely no way to know what this input will be until you give it a few runs.

John.
Last edited by bowlesj3 on 08 Mar 2010, edited 1 time in total.

User avatar
ym
Posts: 53
Joined: 26 Feb 2010

Postby ym » 08 Mar 2010

John and Bruce,

Thanks for your 'inputs'
;-)

Yann

User avatar
Bruce DeVault
Posts: 438
Joined: 19 Jan 2010
Location: Washington DC
Been thanked: 2 times
Contact:

Postby Bruce DeVault » 08 Mar 2010

Thanks for your 'inputs'
Boo...


Return to “MultiCharts”