//------------------------------------------------------------------
#property copyright "mladen"
#property link "mladenfx@gmail.com"
//------------------------------------------------------------------
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 clrLimeGreen
#property indicator_color2 clrMaroon
#property indicator_width1 2
#property indicator_width2 2
extern int period = 10;
extern ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE;
extern double multiplier = 4.0;
extern ENUM_TIMEFRAMES TimeFrame = 0; //default chart TF :: Use 5, 15, 30, 60, etc...
input string s1 = "EURUSD";
//
//
//
//
//
double Trend[];
double TrendDoA[];
double TrendDoB[];
double Direction[];
double Up[];
double Dn[];
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
int OnInit()
{
for (int i=0; i<indicator_buffers; i++) SetIndexStyle(i,DRAW_LINE);
IndicatorBuffers(6);
SetIndexBuffer(0, Trend);
SetIndexBuffer(1, TrendDoA);
SetIndexBuffer(2, TrendDoB);
SetIndexBuffer(3, Direction);
SetIndexBuffer(4, Up);
SetIndexBuffer(5, Dn);
IndicatorDigits(Digits);
IndicatorShortName("SuperTrend multi");
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--)
{
int y = iBarShift(s1,TimeFrame,Time[i]);
double atr = iATR(s1,TimeFrame,period,y);
double cprice = iClose(s1,TimeFrame,y);
double mprice = (iHigh(s1,TimeFrame,y)+iLow(s1,TimeFrame,y))/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; }
}

<code>if(red>0 && AllProfit(0)>1 && 1>0) CloseAll(0);
if(blu>0 && AllProfit(1)>1 && 1>0) CloseAll(1);
if(t!=Time[0])
{
if(CountOrders(0)<1)
{
if(blu>0)
{
PutOrder(0,Ask); PutOrder(5,zz2); DelOrder(4);
}
}
if(CountOrders(1)<1)
{
if(red>0)
{
PutOrder(1,Bid); PutOrder(4,zz2); DelOrder(5);
}
}
t=Time[0];
}</code>
Slava78