I need some help regarding a condition status on multidata symbols.
So I came up with functions for RSI and Moving Average directly aiming at data2 (Daily).
The functions for data2 do work and the signal also does, so when I set up a chart with 2 datastreams for 5 min (data1) and Daily (data2) it works as supposed, only incorporating data2.
So when certain conditions are met according to data2 (Daily) I am assuming that the condition is valid from that specific (Daily) time on.
So once this daily (data2) condition is met I am trying to dig deeper into the 5 min chart (data1). What I don’t understand is that I am not able to define conditions for data1 now.
So for example data2 with a strategy using the RSI function at the bottom
Code: Select all
If…_RSIDaily crosses above 20…then…condition1
And I am assuming for that day when the cross happened I am able to look for more conditions on data1 5 min to define my signal more specific.
This doesnt work. The daily condition is only valid for the first bar intraday. But I want it to be valid for that whole day.
Can somebody help?
Code: Select all
inputs:
Price( numericseries ),
Length( numericsimple ) ; { this input assumed to be a constant >= 1 }
variables:
NetChgAvg( 0 ),
TotChgAvg( 0 ),
Change( 0 ),
SF( 1 / Length ), { smoothing factor }
ChgRatio( 0 ),
// Added these variables for RSI Daily calculations
DailyCnt( 0 ),
FirstDailyPrice( 0 ),
DailyPrice( 0 ),
OldDailyPrice( 0 ),
SumDailyPriceDiff( 0 ),
HoldRSIDaily( 0 ),
OldNetChgAvg( 0 ),
OldTotChgAvg( 0 ) ;
// Check Length
if CurrentBar = 1 then
begin
if Length < 2 then
RaiseRunTimeError( " Length must be > 1" ) ;
end ;
// Only make calculations on the closing bar ticks and date changes.
// If the prior bar Date is not equal to the current bar Date and we
// are on the closing tick of the bar, then we are on the closing tick
// of the first bar.
if Date[1] <> Date and BarStatus(1) = 2 then
begin
DailyCnt = DailyCnt + 1 ;
// Get the first daily price. Note that we must wait for
// two (2) date changes before recording the first daily price
// for this calculation to line up with the built-in RSI calculation.
if DailyCnt = 2 then
FirstDailyPrice = Price[1] ;
// Capture the prior values of key variables before updating them
// with new daily price information.
OldNetChgAvg = NetChgAvg ;
OldTotChgAvg = TotChgAvg ;
OldDailyPrice = DailyPrice ;
DailyPrice = Price[1] ;
Change = DailyPrice - OldDailyPrice ;
// Sum the daily price changes for the initial calculations
if DailyCnt >= 3 and DailyCnt <= Length + 2 then
SumDailyPriceDiff = SumDailyPriceDiff + AbsValue( Change ) ;
// Set initial values of the NetChgAvg and TotChgAvg
if DailyCnt = Length + 2 then
begin
NetChgAvg = ( DailyPrice - FirstDailyPrice ) / Length ;
TotChgAvg = SumDailyPriceDiff / Length ;
end ;
// Update the values for each new daily price once the initial
// values are defined.
if DailyCnt > Length + 2 then
begin
NetChgAvg = OldNetChgAvg + SF * ( Change - OldNetChgAvg ) ;
TotChgAvg = OldTotChgAvg + SF * ( AbsValue( Change ) - OldTotChgAvg ) ;
end ;
// Adjust values and calculate the daily RSI
if DailyCnt >= Length + 2 then
begin
if TotChgAvg <> 0 then
ChgRatio = NetChgAvg / TotChgAvg
else
ChgRatio = 0 ;
HoldRSIDaily = 50 * ( ChgRatio + 1 ) ;
end ;
end ;
_RSIDaily = HoldRSIDaily ;