Adding Time Restrictions To Calculation of Indicators

Questions about MultiCharts and user contributed studies.
fibonaccci
Posts: 49
Joined: 26 Dec 2009
Has thanked: 34 times
Been thanked: 1 time

Adding Time Restrictions To Calculation of Indicators

Postby fibonaccci » 08 Oct 2010

Hi, need some help please on adding a simple time restriction for calculating indicators....
Just to make sure, all I want is to limit the order executions and the calculations of all system settings for the predefined time period 600 to 1300.

In other words by setting up a custom session (600 - 1300) under properties and comparing the system results with results generated by a code that contains your time limitation (... if Time >= BegMACDCalcTime and Time <= EndMACDCalcTime...) and has a 24 hour chart (Forex - regular session) then the very same results should be expected. Unfortunately just the entries and exits are within the custom session but they differ. That's why I believe that the calculation of the indicators does not work.

Below you will find two different examples. It is confusing that it does not matter if variables and inputs are set before or after the time restriction (..if Time >= BegCalcTime and Time <= EndCalcTime..)

Please help, thank you very much. Regards.


Code: Select all

// MACD
inputs: BegCalcTime( 600 ), EndCalcTime( 1300 ) ;

if Time >= BegCalcTime and Time <= EndCalcTime then
begin

inputs: Length( 14 ), OverSold( 20 ), OverBought( 80 ) ;
variables: oFastK( 0 ), oFastD( 0 ), oSlowK( 0 ), oSlowD( 0 ) ;
Value1 = Stochastic( H, L, C, Length, 3, 3, 1, oFastK, oFastD, oSlowK, oSlowD ) ;

if CurrentBar > 2 and oSlowK crosses over oSlowD and oSlowK < OverSold then
Buy ( "StochLE" ) next bar at market ;

if CurrentBar > 2 and oSlowK crosses under oSlowD and oSlowK > OverBought then
Sell ( "StochLX" ) next bar at market ;

end ;

Code: Select all


// Stoch
inputs: BegMACDCalcTime( 600 ), EndMACDCalcTime( 1300 ) ;
variables: MyMACD( 0 ), MACDAvg( 0 ), MACDDiff( 0 ) ;
variables: MACDValue( 0 ) ;

if Time >= BegMACDCalcTime and Time <= EndMACDCalcTime then
begin
inputs: FastLength( 12 ), SlowLength( 26 ), MACDLength( 9 ) ;


MyMACD = MACD( Close, FastLength, SlowLength ) ;
MACDAvg = XAverage( MyMACD, MACDLength ) ;
MACDDiff = MyMACD - MACDAvg ;



MACDValue = MACD( Close, 12, 26 ) ;
{ put other code here }
if CurrentBar > 2 and MACDDiff crosses over 0 then
Buy ( "MacdLE" ) next bar at market ;
if CurrentBar > 2 and MACDDiff crosses under 0 then
Sell ( "MacdLX" ) next bar at market ;

end ;

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Adding Time Restrictions To Calculation of Indicators

Postby TJ » 08 Oct 2010

Hi, need some help please on adding a simple time restriction for calculating indicators....
Just to make sure, all I want is to limit the order executions and the calculations of all system settings for the predefined time period 600 to 1300.

In other words by setting up a custom session (600 - 1300) under properties and comparing the system results with results generated by a code that contains your time limitation (... if Time >= BegMACDCalcTime and Time <= EndMACDCalcTime...) and has a 24 hour chart (Forex - regular session) then the very same results should be expected. Unfortunately just the entries and exits are within the custom session but they differ. That's why I believe that the calculation of the indicators does not work.

Below you will find two different examples. It is confusing that it does not matter if variables and inputs are set before or after the time restriction (..if Time >= BegCalcTime and Time <= EndCalcTime..)

Please help, thank you very much. Regards.

try this: change the strategy to an indicator

1. replace the buy/sell orders with a Plot statement.
say, plot a large red dot at the high of the bar for SELL,
and plot a large green dot at the low of the bar for BUY,

2. plot the Stochastics and MACD on the chart

3. Visually verify the integrity of your logic

If you have further question,
you can post your chart, with notes to the problem area of your plots/logic.



NB. always always always use plot/paintbar to verify a logic before proceeding to code your strategy.
If you cannot get an indicator to plot at the location you want,
you are not likely to get a BUY/SELL order at the time/place you expected.

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: Adding Time Restrictions To Calculation of Indicators

Postby furytrader » 14 Oct 2010

This is a very unusual question. When you're using a custom time period, is it the case that the indicators only have a limited amount of price data to calculate from (as opposed to the full 24 hour data?)

In other words, if you're using a custom time period and you calculated a 200 bar Moving Average, it's only going to base that calculation on the price data that occurred within your custom time frame? This would seem to be the case.

However, if you told the indicator that is a placed on a 24 hour chart to only calculate during certain times, it will still use price data that falls beyond the parameters of your custom time period.

I'm thinking this may be the cause of your issue ...

fibonaccci
Posts: 49
Joined: 26 Dec 2009
Has thanked: 34 times
Been thanked: 1 time

Re: Adding Time Restrictions To Calculation of Indicators

Postby fibonaccci » 15 Oct 2010

@TJ, thank you very much for your important tips,
as a non-programer I assume that your visual procedure is a general suggestion
in order to prove my system right or wrong. For my special problem I already know that it is not doing what I'm expecting it to do, for that I have compared two charts with different sessions.

@furytrader, thank you very much for your insight, that's exactly the main issue.

I didn't believe that this issue cannot be solved that easy or at all.

Best regards

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: Adding Time Restrictions To Calculation of Indicators

Postby furytrader » 15 Oct 2010

Two quick suggestions for fixing this:

1) Manually calculate the indicators yourself during the specific window you want to use, using variables. This would probably be tedious, depending on which indicator you want to calculate. You'd probably have to use the ELCollections set to manage lists of data; or

2) Could you have two data sets in one chart: one showing 24 hour data and one showing the custom time frame? You could even hide the custom time frame and write indicators that simply key off the data from the second data set?

Just a few thoughts.

fibonaccci
Posts: 49
Joined: 26 Dec 2009
Has thanked: 34 times
Been thanked: 1 time

Re: Adding Time Restrictions To Calculation of Indicators

Postby fibonaccci » 22 Oct 2010

Hi furytrader,

many thanks again for your very helpful suggestions.
I will try to use a second data set.

Regarding the hide function: do mean Format Instrument / Settings / Hide
or anything else?

Thank you. Best Regards

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Adding Time Restrictions To Calculation of Indicators

Postby TJ » 22 Oct 2010

@TJ, thank you very much for your important tips,
as a non-programer I assume that your visual procedure is a general suggestion
in order to prove my system right or wrong. For my special problem I already know that it is not doing what I'm expecting it to do, for that I have compared two charts with different sessions.
...
Best regards
there are 2 parts in debugging a strategy,

1. does my logic work?
ie. are the triggers firing at the right time and right places?

2. does my order processing work?
ie. when the triggers are fired, are my BUY/SELL orders doing what they are supposed to be doing.

...

User avatar
furytrader
Posts: 354
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 155 times
Been thanked: 217 times

Re: Adding Time Restrictions To Calculation of Indicators

Postby furytrader » 22 Oct 2010

Fibo,

Yes, I mean to hide the second, time-restricted dataset from your chart so that it's not distracting to you.

Good luck!


Return to “MultiCharts”