SuperTrend - page 22

 

Could someone please modify this SuperTrend.mq4 in the form of: int OnInit()   int OnCalculate  and with #property strict

included

 //+------------------------------------------------------------------+

//|                                                         dfsf.mq4 |

//|                        Copyright 2016, MetaQuotes Software Corp. |

//|                                             https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "Copyright 2016, MetaQuotes Software Corp."

#property link      "https://www.mql5.com"

#property version   "1.00"

#property strict

#property indicator_chart_window

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- indicator buffers mapping

   

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+


//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

//---

   

//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+

 appreciate a lot

thanks in advance

with regards 

Files:
 
tsedawa:

Could someone please modify this SuperTrend.mq4 in the form of: int OnInit()   int OnCalculate  and with #property strict

included

 //+------------------------------------------------------------------+

//|                                                         dfsf.mq4 |

//|                        Copyright 2016, MetaQuotes Software Corp. |

//|                                             https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "Copyright 2016, MetaQuotes Software Corp."

#property link      "https://www.mql5.com"

#property version   "1.00"

#property strict

#property indicator_chart_window

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- indicator buffers mapping

   

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+


//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

//---

   

//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+

 appreciate a lot

thanks in advance

with regards 

Use some of the new versions. The version you posted is very, very old, and is repainting.
 

This is the code for non-repainting super trend in new metatrader 4 format (even though there is no need for conversion of the "old" non-repainting version to this format - it works too, but just in case that someone wants to learn how the "new format" can be used)

//------------------------------------------------------------------
#property copyright "Copyright 2016, mladen - MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//------------------------------------------------------------------
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 clrLimeGreen
#property indicator_color2 clrOrange
#property indicator_color3 clrOrange
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property strict

extern int     period     = 10;  // Super trend period
extern double  multiplier = 4.0; // Super trend multiplier

double Trend[],TrendDoA[],TrendDoB[],Direction[],Up[],Dn[];

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

int OnInit()
{
   IndicatorBuffers(6);
      SetIndexBuffer(0, Trend);
      SetIndexBuffer(1, TrendDoA);
      SetIndexBuffer(2, TrendDoB);
      SetIndexBuffer(3, Direction);
      SetIndexBuffer(4, Up);
      SetIndexBuffer(5, Dn);
   IndicatorShortName("SuperTrend");
   return(0);
}
void OnDeinit(const int reason) { }

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double   &open[],
                const double   &high[],
                const double   &low[],
                const double   &close[],
                const long     &tick_volume[],
                const long     &volume[],
                const int &spread[])
{
   int counted_bars = prev_calculated;
      if(counted_bars < 0) return(-1);
      if(counted_bars > 0) counted_bars--;
           int limit=MathMin(rates_total-counted_bars,rates_total-1);

   //
   //
   //
   //
   //

   if (Direction[limit] <= 0) CleanPoint(limit,TrendDoA,TrendDoB);
   for(int i = limit; i >= 0; i--)
   {
      double atr    = iATR(NULL,0,period,i);
      double cprice =  close[i];
      double mprice = (high[i]+low[i])/2;
         Up[i]  = mprice+multiplier*atr;
         Dn[i]  = mprice-multiplier*atr;
         
         //
         //
         //
         //
         //
         
         Direction[i] = (i<rates_total-1) ? (cprice > Up[i+1]) ? 1 : (cprice < Dn[i+1]) ? -1 : Direction[i+1] : 0;
         TrendDoA[i]  = EMPTY_VALUE;
         TrendDoB[i]  = EMPTY_VALUE;
            if (Direction[i] ==  1) { Dn[i] = MathMax(Dn[i],Dn[i+1]); Trend[i] = Dn[i]; }
            if (Direction[i] == -1) { Up[i] = MathMin(Up[i],Up[i+1]); Trend[i] = Up[i]; PlotPoint(i,TrendDoA,TrendDoB,Trend); }
   }
   return(rates_total);
}

//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
//
//
//
//
//

void CleanPoint(int i,double& first[],double& second[])
{
   if (i>Bars-2) return;
   if ((second[i]  != EMPTY_VALUE) && (second[i+1] != EMPTY_VALUE))
        second[i+1] = EMPTY_VALUE;
   else
      if ((first[i] != EMPTY_VALUE) && (first[i+1] != EMPTY_VALUE) && (first[i+2] == EMPTY_VALUE))
          first[i+1] = EMPTY_VALUE;
}

void PlotPoint(int i,double& first[],double& second[],double& from[])
{
   if (i>Bars-3) return;
   if (first[i+1] == EMPTY_VALUE)
         if (first[i+2] == EMPTY_VALUE) 
               { first[i]  = from[i]; first[i+1]  = from[i+1]; second[i] = EMPTY_VALUE; }
         else  { second[i] = from[i]; second[i+1] = from[i+1]; first[i]  = EMPTY_VALUE; }
   else        { first[i]  = from[i];                          second[i] = EMPTY_VALUE; }
}



 
mladen:

This is the code for non-repainting super trend in new metatrader 4 format (even though there is no need for conversion of the "old" non-repainting version to this format - it works too, but just in case that someone wants to learn how the "new format" can be used)



thats quick. thank you so much. one favor please. could you make it like the original one repainting. for my ea repainting is better than nonrepainting because if the price suddenly reverses hugely i do not want my ea to look back at the past bar. 

thank you very much mladen

regards 

 
tsedawa:

thats quick. thank you so much. one favor please. could you make it like the original one repainting. for my ea repainting is better than nonrepainting because if the price suddenly reverses hugely i do not want my ea to look back at the past bar. 

thank you very much mladen

regards 

:):):)

Sorry, but if you want it to repaint, then you shall have to make it repaint. Not my favorite sport to make repainters :)

 
What a Wonderful! idea for a new thread...."Make it Repaint Please!"...with exclamation mark at the end...
 
mladen:

:):):)

Sorry, but if you want it to repaint, then you shall have to make it repaint. Not my favorite sport to make repainters :)

sorry to hear that. i am very bad at indicators. i was really hoping you would help me thinking that its just a cakewalk for you. anyways could you just give me a hint please? i know its to do with (i), but dont know where.

thanks anyway.

regards 

 
tsedawa:

sorry to hear that. i am very bad at indicators. i was really hoping you would help me thinking that its just a cakewalk for you. anyways could you just give me a hint please? i know its to do with (i), but dont know where.

thanks anyway.

regards 

Looks like you forcing users inverse mode :) anyway decrease periods you using for early signaling.
 

tsedawa:

thanks anyway.

regards 

Don't mention it, no need to thank me :)
 
mntiwana:
anyway decrease periods you using for early signaling.
I'm not using it :(