//+------------------------------------------------------------------+
//| SAR trail v4.mq4 |
//| Copyright © 2009, Maxim Markov |
//| marmax@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Maxim Markov"
#property link "marmax@mail.ru"
extern int DistancePoints =1;
extern bool AllowLoss =FALSE;
int AccuracyPoints =1;
double SARstep =0.02;
double SARmaximum =0.2;
int init()
{
Print("SAR Trail v.4 Copyright © 2009, Maxim Markov marmax@mail.ru");
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
double Distance =DistancePoints*Point;
double Accuracy =AccuracyPoints*Point;
double StopCurrent =0;
double StopRequired =0;
double StopAllowed =0;
double StopSet =0;
double Spread =MarketInfo(Symbol(), MODE_SPREAD)*Point;
double Minimum_Distance =MarketInfo(Symbol(), MODE_STOPLEVEL)*Point;
for(int i=0;i<OrdersTotal();i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==FALSE) break;
if (OrderSymbol()==Symbol())
{
StopCurrent=OrderStopLoss();
if ((OrderType()==OP_BUY) && (Close[0]>iSAR(NULL,0,SARstep,SARmaximum,0)))
{
StopRequired=iSAR(NULL,0,SARstep,SARmaximum,0)-Distance;
StopAllowed=Close[0]-Minimum_Distance;
StopSet=MathMin(StopAllowed, StopRequired);
if ((StopSet > StopCurrent+Accuracy) && (StopRequired >= OrderOpenPrice()||AllowLoss))
OrderModify(OrderTicket(),OrderOpenPrice(),StopSet,OrderTakeProfit(),0);
}
if ((OrderType()==OP_SELL) && (Close[0]<iSAR(NULL,0,SARstep,SARmaximum,0)))
{
StopRequired=iSAR(NULL,0,SARstep,SARmaximum,0)+Spread+Distance;
StopAllowed=Close[0]+Spread+Minimum_Distance;
StopSet=MathMax(StopAllowed, StopRequired);
if (((StopSet < StopCurrent-Accuracy) || (StopCurrent == 0)) && (StopRequired <= OrderOpenPrice() || AllowLoss))
OrderModify(OrderTicket(),OrderOpenPrice(),StopSet,OrderTakeProfit(),0);
}
}
}
return(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Renko.mq4 |
//| Copyright © 2014, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, AM2"
#property link "http://www.forexsystems.biz"
#property description "indalekseifx Directional Line expert advisor"
//--- Inputs
extern double StopLoss = 2000; // стоп лосс ордера
extern double TakeProfit = 2000; // тейк профит ордера
extern double Lots = 0.1; // объем позиции
//----
extern int Amplitude = 2; // период средней indalekseifx Directional Line
extern int shift = 2; // смещение средней
//----
extern int FastPeriod = 12; // период быстрого макди
extern int SlowPeriod = 26; // период медленного макди
extern int SignalPeriod = 9; // период сигнального макди
//----
extern int MACDAC = 0; // включение макди(1-включен,0-отключен)
extern int MAGIC = 2014;// магик
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForOpen()
{
int res,b,s;
bool sp=true,bp=true;
//--- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//--- get Moving Average
double indalekseifxDeepSkyBlue=iCustom(Symbol(),0,"indalekseifx",Amplitude,1,1);
double indalekseifxTomato=iCustom(Symbol(),0,"indalekseifx",Amplitude,0,1);
double MACDGreen=iCustom(Symbol(),0,"MACDTraditional",FastPeriod,SlowPeriod,SignalPeriod,1,1);
double MACDRed=iCustom(Symbol(),0,"MACDTraditional",FastPeriod,SlowPeriod,SignalPeriod,0,1);
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
{
if(OrderMagicNumber()!=MAGIC || OrderSymbol()!=Symbol()) continue;
{
if(OrderType()==OP_BUY) b++;sp=false;
if(OrderType()==OP_SELL) s++;bp=false;
}
}
}
//--- sell conditions
if(MACDAC==1)
{
if(indalekseifxDeepSkyBlue>indalekseifxTomato && MACDGreen<MACDRed && s<1 && sp)
{
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",MAGIC,0,Tomato);
return;
}
//--- buy conditions
if(indalekseifxTomato>indalekseifxDeepSkyBlue && MACDGreen>MACDRed && b<1 && bp)
{
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",MAGIC,0,DeepSkyBlue);
return;
}
}
else
{
if(indalekseifxDeepSkyBlue>indalekseifxTomato && s<1 && sp)
{
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",MAGIC,0,Tomato);
return;
}
//--- buy conditions
if(indalekseifxTomato>indalekseifxDeepSkyBlue && b<1 && bp)
{
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",MAGIC,0,DeepSkyBlue);
return;
}
}
}
//+------------------------------------------------------------------+
//| Check for close order conditions |
//+------------------------------------------------------------------+
void CheckForClose()
{
//--- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//--- get Moving Average
double indalekseifxDeepSkyBlue=iCustom(Symbol(),0,"indalekseifx",Amplitude,1,shift);
double indalekseifxTomato=iCustom(Symbol(),0,"indalekseifx",Amplitude,0,shift);
//---
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=MAGIC || OrderSymbol()!=Symbol()) continue;
//--- check order type
if(OrderType()==OP_BUY)
{
if(indalekseifxDeepSkyBlue>indalekseifxTomato)
{
if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
if(OrderType()==OP_SELL)
{
if(indalekseifxTomato>indalekseifxDeepSkyBlue)
{
if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
}
//---
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--- check for history and trading
if(Bars<100 || IsTradeAllowed()==false)
return;
//--- calculate open orders by current symbol
CheckForOpen();
CheckForClose();
//---
}
//+------------------------------------------------------------------+
#property copyright "alekseifx"
#property link "http://lux-profit.ru/"
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 DeepSkyBlue
#property indicator_width1 2
#property indicator_color2 Tomato
#property indicator_width2 2
#property indicator_color3 Teal
#property indicator_color4 Teal
//+------------------------------------------------------------------+
extern int Amplitude = 2;
extern bool UseAlert = true; // Алерт вкл/выкл.
extern string Sound = "alert.wav"; // Если пусто - звук выкл.
//+------------------------------------------------------------------+
int tf=0;
string txt="",sym="";
bool nexttrend;
double minh,maxl,up[],down[],trend[],atrlo[],atrhi[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
sym=Symbol();
txt="";
tf=Period();
SetIndexBuffer(0,up);SetIndexStyle(0,DRAW_LINE);SetIndexEmptyValue(0,0.0);
SetIndexBuffer(1,down);SetIndexStyle(1,DRAW_LINE);SetIndexEmptyValue(1,0.0);
SetIndexBuffer(2,atrlo);SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(3,atrhi);SetIndexStyle(3,DRAW_LINE);
SetIndexBuffer(4,trend);SetIndexStyle(4,DRAW_NONE);SetIndexEmptyValue(4,0.0);
IndicatorDigits(Digits);
nexttrend=0;
minh = High[Bars - 1];
maxl = Low[Bars - 1];
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
double atr,ll,hh,lma,hma;
int workbar=1;
int c=IndicatorCounted();
if(c<0)return(-1);
for(int i=Bars-1-c; i>=workbar; i --)
{
ll=iLow(sym,tf,iLowest(sym,tf,MODE_LOW,Amplitude,i));
hh=iHigh(sym,tf,iHighest(sym,tf,MODE_HIGH,Amplitude,i));
lma = iMA (sym, 0, Amplitude, 0, MODE_SMA, PRICE_LOW, i);
hma = iMA (sym, 0, Amplitude, 0, MODE_SMA, PRICE_HIGH, i);
trend[i]=trend[i+1];
atr=iATR(Symbol(),0,100,i)/2;
if(nexttrend==1){maxl=MathMax(ll,maxl);if(hma<maxl && Close[i]<Low[i+1]){trend[i]=1;nexttrend=0;minh=hh;}}
if(nexttrend==0){minh=MathMin(hh,minh);if(lma>minh && Close[i]>High[i+1]){trend[i]=0;nexttrend=1;maxl=ll;}}
if(trend[i]==0.0)
{
if(trend[i+1]!=0.0){up[i]=down[i+1];up[i+1]=up[i];} else up[i]=MathMax(maxl,up[i+1]);
atrhi[i] = up[i] + atr;
atrlo[i] = up[i] - atr;
down[i]=0.0;
}
else
{
if(trend[i+1]!=1.0){down[i]=up[i+1];down[i+1]=down[i];} else down[i]=MathMin(minh,down[i+1]);
atrhi[i] = down[i] + atr;
atrlo[i] = down[i] - atr;
up[i]=0.0;
}
}
if(txt==""){if(up[1]==0.0)txt=" Sell ";if(down[1]==0.0)txt=" Buy ";}
if(up[1]==0.0 && txt==" Buy "){txt=" Sell ";if(UseAlert)Alert(sym+txt);if(Sound!="")PlaySound(Sound);}
if(down[1]==0.0 && txt==" Sell "){txt=" Buy ";if(UseAlert)Alert(sym+txt);if(Sound!="")PlaySound(Sound);}
return(0);
}
//+------------------------------------------------------------------+
alekseifx