Ich habe den Code mal etwas reduziert, um nur das Wesentliche zu zeigen.
Die Strategie ist dem ersten Bild zu entnehmen.
Code:
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 LightSeaGreen
#property indicator_color2 LightSeaGreen
#property indicator_color3 LightSeaGreen
extern int UpperBandPeriod = 34;
extern int UpperBandShift = 0;
extern double UpperBandDeviation = 2.0;
extern int MA_Period = 21;
extern int MA_Shift = 0;
extern int LowerBandPeriod = 34;
extern int LowerBandShift = 0;
extern double LowerBandDeviation = 2.0;
extern int LowerBandPierced = 26; //Anzahl Candles, die vergangan sind, seit das Lower Band unterschritten wurde
extern int UpperBandPierced = 26;
//============================= Dummies ======================
double Multiplier;
double AdjustedUpperBand;
double AdjustedMA;
double AdjustedLowerBand;
datetime TimeOld;
double BandDiff = 0;
bool SetArrowUp = false;
bool SetArrowDown = false;
int x = 0;
//============================== Parameters ==================
double dDiff=0;
bool bArrowPlacedLong = false;
bool bArrowPlacedShort = false;
int MinClose = 0;
int MaxClose = 0;
int counterUP = 1;
// ================================= Arrays =====================
double MA[];
double Lower_Band[];
//============================= Place Arrow Up ==== ORIGINAL ======================================
void PlaceArrowUp(int i){
if( (Open[i] > iMA(NULL,0,21,MA_Shift,MODE_SMA,PRICE_CLOSE,i))
&& (Open[i+1] < iMA(NULL,0,21,MA_Shift,MODE_SMA,PRICE_CLOSE,i+1))
&& (Close[i+1] > iMA(NULL,0,21,MA_Shift,MODE_SMA,PRICE_CLOSE,i+1)) ){
for(int k=1;k<=26;k++){
if( Low[i+k] < (iMA(NULL,0,21,MA_Shift,MODE_SMA,PRICE_CLOSE,i+k)-0.02) ){
x++;
ObjectCreate("BUY" + x,OBJ_ARROW,0,Time[i],Low[MinClose]);
ObjectSet ("BUY" + x,OBJPROP_COLOR,Blue);
ObjectSet ("BUY" + x,OBJPROP_ARROWCODE,SYMBOL_ARROWUP);
ObjectSet ("BUY" + x,OBJPROP_WIDTH,5);
ObjectSet ("BUY" + x,OBJPROP_BACK,true);
break;
}
}
}
}
//================================================ INIT =============================================
int init(){
int period = Period();
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,MA);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,Lower_Band);
SetIndexDrawBegin(1,AdjustedMA+MA_Shift);
SetIndexDrawBegin(2,AdjustedLowerBand+LowerBandShift+LowerBandPierced);
return(0);
}
//===================================== ON TICK ===============================================
int start(){
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
int uncounted_bars=Bars-counted_bars;
for(int i=0;i<uncounted_bars;i++){
if( Time[i] != TimeOld ){
MA[i] = iMA(NULL,0,21,MA_Shift,MODE_SMA,PRICE_CLOSE,i);
Lower_Band[i] = iMA(NULL,0,21,MA_Shift,MODE_SMA,PRICE_CLOSE,i)-0.02;
MinClose = iLowest (NULL,0,MODE_CLOSE,6,i);//Kleinster Schlusskurs
PlaceArrowUp(i);
}
}
return(0);
}
//===================================== DEINIT =================================================
int deinit(){
ObjectsDeleteAll(); // delete all objects from chart
return 0;
}
Ich dachte mir ich löse das Problem durch das Setzen eines Flags:
counterUp wird 0, wenn der untere MA unterschritten wurde und wird 1, wenn der obere MA überschritten wurde, aber es verschwinden dann die guten Pfeile. Ich verstehe nicht, warum der Pfeil erst gesetzt wird, wenn der obere MA 2mal durchstoßen wurde.....
Code:
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 LightSeaGreen
#property indicator_color2 LightSeaGreen
#property indicator_color3 LightSeaGreen
extern int UpperBandPeriod = 34;
extern int UpperBandShift = 0;
extern double UpperBandDeviation = 2.0;
extern int MA_Period = 21;
extern int MA_Shift = 0;
extern int LowerBandPeriod = 34;
extern int LowerBandShift = 0;
extern double LowerBandDeviation = 2.0;
extern int LowerBandPierced = 26; //Anzahl Candles, die vergangan sind, seit das Lower Band unterschritten wurde
extern int UpperBandPierced = 26;
//============================= Dummies ======================
double Multiplier;
double AdjustedUpperBand;
double AdjustedMA;
double AdjustedLowerBand;
datetime TimeOld;
double BandDiff = 0;
bool SetArrowUp = false;
bool SetArrowDown = false;
int x = 0;
//============================== Parameters ==================
double dDiff=0;
bool bArrowPlacedLong = false;
bool bArrowPlacedShort = false;
int MinClose = 0;
int MaxClose = 0;
int counterUP = 1;
// ================================= Arrays =====================
double MA[];
double Lower_Band[];
//============================= Place Arrow Up ==== ORIGINAL ======================================
void PlaceArrowUp(int i){
if(counterUP == 0){ // NEU
if( (Open[i] > iMA(NULL,0,21,MA_Shift,MODE_SMA,PRICE_CLOSE,i))
&& (Open[i+1] < iMA(NULL,0,21,MA_Shift,MODE_SMA,PRICE_CLOSE,i+1))
&& (Close[i+1] > iMA(NULL,0,21,MA_Shift,MODE_SMA,PRICE_CLOSE,i+1)) ){
for(int k=1;k<=26;k++){
if( Low[i+k] < (iMA(NULL,0,21,MA_Shift,MODE_SMA,PRICE_CLOSE,i+k)-0.02) ){
x++;
ObjectCreate("BUY" + x,OBJ_ARROW,0,Time[i],Low[MinClose]);
ObjectSet ("BUY" + x,OBJPROP_COLOR,Blue);
ObjectSet ("BUY" + x,OBJPROP_ARROWCODE,SYMBOL_ARROWUP);
ObjectSet ("BUY" + x,OBJPROP_WIDTH,5);
ObjectSet ("BUY" + x,OBJPROP_BACK,true);
counterUP = 1; // NEU
break;
}
}
}
}
}
//================================================ INIT =============================================
int init(){
int period = Period();
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,MA);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,Lower_Band);
SetIndexDrawBegin(1,AdjustedMA+MA_Shift);
SetIndexDrawBegin(2,AdjustedLowerBand+LowerBandShift+LowerBandPierced);
return(0);
}
//===================================== ON TICK ===============================================
int start(){
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
int uncounted_bars=Bars-counted_bars;
for(int i=0;i<uncounted_bars;i++){
if( Time[i] != TimeOld ){
MA[i] = iMA(NULL,0,21,MA_Shift,MODE_SMA,PRICE_CLOSE,i);
Lower_Band[i] = iMA(NULL,0,21,MA_Shift,MODE_SMA,PRICE_CLOSE,i)-0.02;
MinClose = iLowest (NULL,0,MODE_CLOSE,6,i);//Kleinster Schlusskurs
if(Low[i] < Lower_Band[i]) {counterUP = 0;} // NEU
PlaceArrowUp(i);
}
}
return(0);
}
//===================================== DEINIT =================================================
int deinit(){
ObjectsDeleteAll(); // delete all objects from chart
return 0;
}
Geändert von Biatsch (28.04.15 um 20:12 Uhr)
|