//+------------------------------------------------------------------+
//| Custom MACD.mq4 |
//| Copyright 2005-2014, MetaQuotes Software Corp. |
//| http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "2005-2014, MetaQuotes Software Corp."
#property link "http://www.mql4.com"
#property description "Moving Averages Convergence/Divergence"
#property strict
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Silver
#property indicator_color3 Blue
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width3 2
//--- indicator parameters
input int InpFastEMA=12; // Fast EMA Period
input int InpSlowEMA=26; // Slow EMA Period
input int InpSignalSMA=9; // Signal SMA Period
input int Procent = 80;
//--- indicator buffers
double ExtMacdBuffer[];
double ExtSignalBuffer[];
double ExtMacdBlueBuffer[];
//--- right input parameters flag
bool ExtParameters=false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit(void)
{
IndicatorDigits(Digits+1);
//--- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexStyle(1,DRAW_LINE);
SetIndexDrawBegin(1,InpSignalSMA);
//--- indicator buffers mapping
SetIndexBuffer(0,ExtMacdBuffer);
SetIndexBuffer(1,ExtSignalBuffer);
SetIndexBuffer(2,ExtMacdBlueBuffer);
//--- name for DataWindow and indicator subwindow label
IndicatorShortName("MACD("+IntegerToString(InpFastEMA)+","+IntegerToString(InpSlowEMA)+","+IntegerToString(InpSignalSMA)+")");
SetIndexLabel(0,"MACD");
SetIndexLabel(1,"Signal");
//--- check for input parameters
if(InpFastEMA<=1 || InpSlowEMA<=1 || InpSignalSMA<=1 || InpFastEMA>=InpSlowEMA)
{
Print("Wrong input parameters");
ExtParameters=false;
return(INIT_FAILED);
}
else
ExtParameters=true;
//--- initialization done
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
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 i,limit;
//---
if(rates_total<=InpSignalSMA || !ExtParameters)
return(0);
//--- last counted bar will be recounted
limit=rates_total-prev_calculated;
if(prev_calculated>0)
limit++;
//--- macd counted in the 1-st buffer
for(i=0; i<limit; i++)
{
ExtMacdBuffer[i]=iMA(NULL,0,InpFastEMA,0,MODE_EMA,PRICE_CLOSE,i)-
iMA(NULL,0,InpSlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
ExtMacdBlueBuffer[i]=ExtMacdBuffer[i]*Procent*0.01;
}
//--- signal line counted in the 2-nd buffer
SimpleMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer);
//--- done
return(rates_total);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| 3MA.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property description "Simple expert advisor"
//--- Inputs
extern int MA1Period = 50;
extern int MA2Period = 100;
extern int MA3Period = 200;
extern int StopLoss = 500;
extern int TakeProfit = 500;
extern int Slip = 30;
extern int TrailingStop = 0;
extern double Lots = 0.1;
extern int Magic = 123;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountTrades()
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()<2) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
{
int r=0;
color clr=Green;
double sl=0,tp=0;
if(type==1 || type==3 || type==5)
{
clr=Red;
if(StopLoss>0) sl=NormalizeDouble(price+StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(price-TakeProfit*Point,Digits);
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
if(StopLoss>0) sl=NormalizeDouble(price-StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(price+TakeProfit*Point,Digits);
}
r=OrderSend(NULL,type,Lots,NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| Закрытие позиции по типу ордера |
//+------------------------------------------------------------------+
void CloseAll(int ot=-1)
{
bool cl;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==0 && (ot==0 || ot==-1))
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slip,White);
}
if(OrderType()==1 && (ot==1 || ot==-1))
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slip,White);
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OpenPos()
{
double MA1=iMA(NULL,0,MA1Period,0,1,0,1);
double MA2=iMA(NULL,0,MA2Period,0,1,0,1);
double MA3=iMA(NULL,0,MA3Period,0,1,0,1);
double MA12=iMA(NULL,0,MA1Period,0,1,0,2);
double MA22=iMA(NULL,0,MA2Period,0,1,0,2);
double MA32=iMA(NULL,0,MA3Period,0,1,0,2);
bool buy=MA1>MA2 && MA1>MA3;
bool sell=MA1<MA2 && MA1<MA3;
//--- sell
if(sell)
{
PutOrder(1,Bid);
}
//--- buy
if(buy)
{
PutOrder(0,Ask);
}
//---
}
//+------------------------------------------------------------------+
void ClosePos()
{
double MA1=iMA(NULL,0,MA1Period,0,1,0,1);
double MA2=iMA(NULL,0,MA2Period,0,1,0,1);
double MA3=iMA(NULL,0,MA3Period,0,1,0,1);
double MA12=iMA(NULL,0,MA1Period,0,1,0,2);
double MA22=iMA(NULL,0,MA2Period,0,1,0,2);
double MA32=iMA(NULL,0,MA3Period,0,1,0,2);
bool buy=MA1>MA2;
bool sell=MA1<MA2;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderMagicNumber()==Magic || OrderSymbol()==Symbol())
{
//--- check order type
if(OrderType()==OP_BUY)
if(sell) CloseAll(0);
if(OrderType()==OP_SELL)
if(buy)CloseAll(1);
}
}
}
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Trailing()
{
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()==Symbol() || OrderMagicNumber()==Magic)
if(OrderType()==OP_BUY)
{
if(TrailingStop>0)
{
double BID=MarketInfo(Symbol(),MODE_BID);
if(BID-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<BID-Point*TrailingStop)
{
bool m=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(BID-Point*TrailingStop,Digits),OrderTakeProfit(),0,Yellow);
}
}
}
}
if(OrderType()==OP_SELL)
{
if(TrailingStop>0)
{
double ASK=MarketInfo(Symbol(),MODE_ASK);
if((OrderOpenPrice()-ASK)>(Point*TrailingStop))
{
if((OrderStopLoss()>(ASK+Point*TrailingStop)) || (OrderStopLoss()==0))
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(ASK+Point*TrailingStop,Digits),OrderTakeProfit(),0,Yellow);
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(CountTrades()<1) OpenPos();
if(CountTrades()>0) ClosePos();
if(TrailingStop>0) Trailing();
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Casha.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
//--- Inputs
extern double Lots = 0.1; // лот
extern int StopLoss = 50; // лось
extern int TakeProfit = 70; // язь
extern int BULevel = 0; // уровень БУ
extern int BUPoint = 30; // пункты БУ
extern int Expiration = 3; // истечение ордера в часах
extern int Delta = 100; // дельта
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
{
int r=0;
color clr=Green;
double sl=0,tp=0;
if(type==1 || type==3 || type==5)
{
clr=Red;
if(StopLoss>0) sl=NormalizeDouble(price+StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(price-TakeProfit*Point,Digits);
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
if(StopLoss>0) sl=NormalizeDouble(price-StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(price+TakeProfit*Point,Digits);
}
r=OrderSend(NULL,type,Lots,NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,TimeCurrent()+Expiration*3600,clr);
return;
}
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу |
//+------------------------------------------------------------------+
int CountOrders(int type)
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==type) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void BU()
{
bool m;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() || OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY)
{
if(OrderOpenPrice()<=(Bid-(BULevel+BUPoint)*Point) && OrderOpenPrice()>OrderStopLoss())
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+BUPoint*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
if(OrderType()==OP_SELL)
{
if(OrderOpenPrice()>=(Ask+(BULevel+BUPoint)*Point) && (OrderOpenPrice()<OrderStopLoss() || OrderStopLoss()==0))
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-BUPoint*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Mode()
{
bool m;
double delta=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() || OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUYSTOP)
{
delta=NormalizeDouble(OrderOpenPrice()-Bid,Digits);
if(delta>Delta*Point)
{
m=OrderModify(OrderTicket(),NormalizeDouble(Bid+Delta*Point,Digits),OrderStopLoss(),OrderTakeProfit(),0,Yellow);
return;
}
}
if(OrderType()==OP_SELLSTOP)
{
delta=NormalizeDouble(Bid-OrderOpenPrice(),Digits);
if(delta>Delta*Point)
{
m=OrderModify(OrderTicket(),NormalizeDouble(Bid-Delta*Point,Digits),OrderStopLoss(),OrderTakeProfit(),0,Yellow);
return;
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
Mode();
if(BULevel>0) BU();
if(CountOrders(4)<1) PutOrder(4,Bid+Delta*Point);
if(CountOrders(5)<1) PutOrder(5,Bid-Delta*Point);
}
//+------------------------------------------------------------------+
Значки штатного фрактала не нужны(либо параметр на отключение). Нужны только точки и только в местах пропадания фрактала, желательно с отображением истории. Точка ровно на том месте, где пропал, без смещения.
AM2