Dukascopy
 
 
Wiki JStore Search Login

Strategy problem with initiating variables to their default value.
 Post subject: Strategy problem with initiating variables to their default value. Post rating: 0   New post Posted: Mon 18 May, 2015, 18:21 
User avatar

User rating: 0
Joined: Sun 01 Feb, 2015, 22:49
Posts: 81
Location: RomaniaRomania
Hi,

Suppose you want to count how many up candles there are in the last 6 historical candles.
You would define a local variable counter and assign 0 to its default value.

You would expect not to get more then 6 candles right?
Wrong.

The counter keeps on counting endlessly.
The Strategy does not initiate the local variable back to its default value at the beginning of each execution. Instead, it keeps on adding to the value of the previous execution.


See for yourself in Default_1.01.vfs

Obviously one could place an Assign block at the beginning of the strategy.
But what is the point of assigning a default value, other than missleade you.

This is simple for a trivial example, but gets chaotic for a bigger strategy.

Cheers,
mosu_d


Attachments:
Default_1.01.vfs [32.62 KiB]
Downloaded 128 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: Strategy problem with initiating variables to their default value. Post rating: 0   New post Posted: Wed 20 May, 2015, 10:02 
Visual JForex expert at Dukascopy
User avatar

User rating: 288
Joined: Thu 18 Apr, 2013, 09:26
Posts: 1496
Location: Switzerland, Geneva
Hiya,

Quote:
Suppose you want to count how many up candles there are in the last 6 historical candles.
You would define a local variable counter and assign 0 to its default value.

True
Quote:
You would expect not to get more then 6 candles right?

False as the condition "More than 6 candles" is not defined anywhere. How do you expect a code to execute an instruction that is not defined/declared ?
Quote:
The counter keeps on counting endlessly.

Normal behavior as the counter is incrementing at every candle's event.
Quote:
The Strategy does not initiate the local variable back to its default value at the beginning of each execution. Instead, it keeps on adding to the value of the previous execution.

False, a default value is attributed to a variable at the "OnStart" & "OnStop" methods unless the user assign the default start value within the strategy itself.
In any case, resetting a counter is a matter of 2 blocks : "IF" & "Assign" that's it.

Quote:
This is simple for a trivial example, but gets chaotic for a bigger strategy.

We'll do our best to avoid you chaotic kinematics :) Slowly but surely !

Cheers


 
 Post subject: Re: Strategy problem with initiating variables to their default value. Post rating: 0   New post Posted: Wed 20 May, 2015, 11:11 
User avatar

User rating: 0
Joined: Sun 01 Feb, 2015, 22:49
Posts: 81
Location: RomaniaRomania
amine_chourou wrote:
Hiya,

Quote:
Suppose you want to count how many up candles there are in the last 6 historical candles.
You would define a local variable counter and assign 0 to its default value.

True
Quote:
You would expect not to get more then 6 candles right?

False as the condition "More than 6 candles" is not defined anywhere. How do you expect a code to execute an instruction that is not defined/declared ?



Forgive my limited understanding... Let me rephrase so I can understand.

I have 6 apples in a bag, I take them one by one, counting how many Red Apples I have.
I expect not to get more then 6 Red Apples,
regardless how many times I try.

I don't have to place any condition to count less then 6 Apples
Do I have to explain why?
.
.


 
 Post subject: Re: Strategy problem with initiating variables to their default value. Post rating: 0   New post Posted: Wed 20 May, 2015, 14:15 
Visual JForex expert at Dukascopy
User avatar

User rating: 288
Joined: Thu 18 Apr, 2013, 09:26
Posts: 1496
Location: Switzerland, Geneva
Quote:
I expect not to get more then 6 Red Apples,

If an expectation is not specified then the system will not get it: In other words, you need to tell the system what expectation are you waiting for and here comes the condition to define this expectation. A counter is a counter, it just counts till the strategy is stopped or the whole system get crashed. If say : Do: X+1=X the system will keep on summing but if you say

X+1=X and
If X=6
then
Assign 0 to X

Then the system will count till 6 and then back to 0


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com