• Sign up >>

Supertrend -> Icustom - page 2

To add comments, please log in or register
Alekseu Fedotov
1473
Alekseu Fedotov  
ale mariani:

I have converted it in a function because I was so sick with the indicator and now it works...it buys and sell as well...just repeats selling and buy consecutive times also...but it is not difficult to fix that one i think...


Do you think I have written correctly the function?...is it the same?


it got also some money, in the last two weeks EUR/USD according to the tester...:D


correct the mistakes


int Super_Trend(int Nbr_Periods,double Multiplier, int timeframe, int shift){
  
   double price_now=0;
   
   if(shift == 0){
   
      price_now = Bid;
   
    }else if(shift > 0){
   
      price_now = iClose(NULL,timeframe,0 + shift);
    

    }
   
   double price_prev = iClose(NULL,timeframe,1 + shift);
   double ma1=iMA(NULL,timeframe,Nbr_Periods,0,MODE_EMA,PRICE_MEDIAN,0 + shift);
   double ma1_prev=iMA(NULL,timeframe,Nbr_Periods,0,MODE_EMA,PRICE_MEDIAN,1 + shift);
   double atr  =iATR(NULL,timeframe,Nbr_Periods,0);
   double atr_prev  =iATR(NULL,timeframe,Nbr_Periods,1);
   double up = ma1 + atr*Multiplier;
   double down = ma1 - atr*Multiplier;
   double up_prev = ma1_prev + atr_prev*Multiplier; 
   double down_prev = ma1_prev - atr_prev*Multiplier;
   
   Print("up: ",up," down: ",down," up_prev: ",up_prev," down_prev: ",down_prev);
//
//----

   if(price_now > up && price_prev < up_prev){
   
   //trendup
   
      return(1);
   
   }
   if(price_now < down && price_prev > down_prev){
   
   //trenddown
   
      return(2);
   
   }
    
  return(0); 


}
Alessandro Mariani
336
Alessandro Mariani  
ok thanks. It seemed to work also mine...but with a lower value comparing with the indicator like 2 or 2.5 ...in tester, the last 3-4 months with some details added in the SL e TP and moment to enter...has gained and pretty constantly.
Pathmanathan Sujeeve
19
Pathmanathan Sujeeve  
in EA,
int init()
  {
  
   double supertrend0 = iCustom(NULL, PERIOD_CURRENT, "SuperTrend", 10, 3.0, 0, 55);
   double supertrend1 = iCustom(NULL, PERIOD_CURRENT, "SuperTrend", 10, 3.0, 1, 55);
   Print(" st0 : ",supertrend0," st1 : ",supertrend1," high: "+High[55]+" Low: ",Low[55]);
   
   return(0);
  }


Results:
down trend
st0 : 2147483647 st1 : 0.9903 high: 0.98763 Low: 0.9859

up trend
st0 : 0.988 st1 : 2147483647 high: 0.99021 Low: 0.9882

  
Here I'm trying to identify the trend of 55th bar. 
If down trend supertrend0 == 2147483647
If up trend supertrend1 == 2147483647
Pathmanathan Sujeeve
19
Pathmanathan Sujeeve  
valid super trend indicator attached
Files:
Pathmanathan Sujeeve
19
Pathmanathan Sujeeve  
int init()
  {
  
  for(int x=0;x<1000;x++){
      double supertrend0 = iCustom(NULL, PERIOD_CURRENT, "SuperTrend", 10, 3.0, 0, x);
      double supertrend1 = iCustom(NULL, PERIOD_CURRENT, "SuperTrend", 10, 3.0, 1, x);
      
      if(supertrend0==2147483647){
         Print("Sell red bar count : ",x," time: ",TimeToStr(iTime(NULL,PERIOD_CURRENT,x),TIME_DATE|TIME_SECONDS) );
      }
      
      if(supertrend1==2147483647){
         Print("Buy Blue bar count : ",x," time: ",TimeToStr(iTime(NULL,PERIOD_CURRENT,x),TIME_DATE|TIME_SECONDS));
      }
  }
   
   return(0);
  }
This code snippet gives clear identification of buy and sell. enjoy :)
12
To add comments, please log in or register