问题
There are 3 RSI indicators, each having its own period.
I want to tie all 3 to one Bollinger Band.
Tell me how to do this better?
for(i=limit; i>=0; i--) {
ma=iMAOnArray(RSI,0,bb_period,0,0,i); // midle
stdev=iStdDevOnArray(RSI,0,bb_period,0,0,i); // dev
BBUP[i]=ma+bb_dev*stdev; // up
BBDOWN[i]=ma-bb_dev*stdev; // down
Buff4[i]=0;
Buff5[i]=0;
}
if(limit<Bars-1) limit++;
for(i=limit; i>0; i--) {
if(PrevSignal >= 0) {
if( RSI[i] < BBDOWN[i]
&& RSI[i+1] < BBUP[i+1]
&& RSI2[i] < BBDOWN[i]
&& RSI2[i+1] < BBUP[i+1]
&& RSI3[i] < BBDOWN[i]
&& RSI3[i+1] < BBUP[i+1]
) {
Buff4[i] = Low[i]-5*MarketInfo(Symbol(),MODE_POINT); // MathMin(BBDOWN[i],WPR[i]); // Low[i]-5*MarketInfo(Symbol(),MODE_POINT);
PrevSignal = -1;
}
}
}
I want that when all 3 RSI were below BB, then the signal https://i.stack.imgur.com/fKff7.jpg
回答1:
The code AS-IS could be designed with 4x less overhead:
Even before O/P will define the target ( how to tie three values into one ), one might have already detected the code-blocks are sync-stepped / aligned in [i]
-indexing, not peeking into the future, non-intervening each to the other's values ( princially indeendent ) and thus redundant, so one could safely save a lot from these "shared" overheads:
int i;
double ma,
stdev;
for(i=limit; i>=0; i--) { RSI[ i] = iRSI( Symbol(), Period(), rsi_period, PRICE_CLOSE, i );
RSI2[i] = iRSI( Symbol(), Period(), rsi_period_2, PRICE_CLOSE, i );
RSI3[i] = iRSI( Symbol(), Period(), rsi_period_3, PRICE_CLOSE, i );
/* the "last" for(){...} code-block body is not included,
until the calculus of how to tie three vectors
into a common Bollinger Band is defined by O/P,
but
could fit in this common "stream"-processing too
*/
}
The O/P code has been remarkably changed - may check the revisions
Nota bene: ad-hoc the presented update
Given the Quantitative Finance heritage, from J. Welles Wilder, the author of the said RSI model, the definition says:
Relative Strength Index (RSI) is a momentum oscillator that measures the speed and change of price movements. RSI oscillates between zero and 100.
It turns out, that any attempt to mix apples and oranges leads to just a principal confusion. Taking the apples == the Bollinger Band ( having a clear PriceDOMAIN dimension [CCY2] ) and trying to mix it ( additively, using { ADD | SUB } operations ) with oranges == RSI ( a dimension-less relative / percent indicator ) will yield an uninterpretable result ( has a hidden superposition + scaling uncertainties ).
Still in doubts?
Just let's take XAUUSD for a second. It's Bollinger Band values, bearing in mind any reasonable multiples of sigma ( StDev ), the RSI will always be under the lower-band ... thus such construct will have zero information value, as:RSI-<0..100> << BollingerBandLOWER-( 1257.000 - ( N * sigma ) )
So a model ought be revised, so as to have some Quantitative Finance support built-in. Mixing apples with oranges simply will not help in any serious business sense.
来源:https://stackoverflow.com/questions/44102558/how-to-tie-3-rsi-indicators-to-one-bollinger-band-using-imaonarray