//+------------------------------------------------------------------+
//| BBProcent.mq4 |
//| Copyright 2017, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Green
#property indicator_color2 Green
#property indicator_color3 Red
input int MAPeriod=8; // MA Period
input int BBPeriod=20; // Bands Period
input int BBShift=0; // Bands Shift
input double BBDeviations=2.0; // Bands Deviations
double up[];
double dn[];
double ma[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,up);
//--- upper band
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,dn);
//--- lower band
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,ma);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetAppliedPrice(int nAppliedPrice, int nIndex)
{
double dPrice;
//----
switch(nAppliedPrice)
{
case 0: dPrice=Close[nIndex]; break;
case 1: dPrice=Open[nIndex]; break;
case 2: dPrice=High[nIndex]; break;
case 3: dPrice=Low[nIndex]; break;
case 4: dPrice=(High[nIndex]+Low[nIndex])/2.0; break;
case 5: dPrice=(High[nIndex]+Low[nIndex]+Close[nIndex])/3.0; break;
case 6: dPrice=(High[nIndex]+Low[nIndex]+2*Close[nIndex])/4.0; break;
default: dPrice=0.0;
}
//----
return(dPrice);
}
//+------------------------------------------------------------------+
//| 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[])
{
//---
for(int i=0;i<1000;i++)
{
double bup=iBands(NULL,0,BBPeriod,BBDeviations,BBShift,0,1,i);
double bdn=iBands(NULL,0,BBPeriod,BBDeviations,BBShift,0,2,i);
ma[i]=iMA(NULL,0,MAPeriod,0,0,0,i);
up[i]=bup;
dn[i]=bdn;
//ma[i]=(Close[i]-bdn)/(bup-bdn);
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
Андрей, а проверку доливки (усреднения) от фильтра (машки) нельзя сделать?
double ma=iMA(NULL,0,MAPeriod,0,0,0,0);
bool b=(CountTrades(0)<1 && (Star()==1 || Pogl()==1) && (BuySell==0 || BuySell==2));
bool s=(CountTrades(1)<1 && (Star()==2 || Pogl()==2) && (BuySell==1 || BuySell==2));
bool b2=FindOrderType()==0 && FindLastBuyPrice()-Ask>=Step*Point;
bool s2=FindOrderType()==1 && Bid-FindLastSellPrice()>=Step*Point;
if(MA)
{
b=(CountTrades(0)<1 && Bid>ma && (Star()==1 || Pogl()==1) && (BuySell==0 || BuySell==2));
s=(CountTrades(1)<1 && Bid<ma && (Star()==2 || Pogl()==2) && (BuySell==1 || BuySell==2));
b2=FindOrderType()==0 && Bid>ma && FindLastBuyPrice()-Ask>=Step*Point;
s2=FindOrderType()==1 && Bid>ma && Bid-FindLastSellPrice()>=Step*Point;
}
1) Поместить индикатор на график.
2) Поместить советник на график, который будет искать горизонтальные линии по уникальному имени. И по их значениям работать.
Андрей привет, код взят с трейдинг вьев.ком
код скрипта на ТВ:
//+------------------------------------------------------------------+
//| Real.mq4 |
//| Copyright 2017, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // лот
extern double Risk = 5; // риск
extern double StopLoss = 500; // лось
extern double TakeProfit = 500; // язь
extern int Step = 200; // шаг
extern int Orders = 5; // макс ордеров в рынке
extern int Shift = 1; // на каком баре сигнал индикатора
extern int Slip = 30; // реквот
extern int CloseSig = 0; // 1-закрытие по сигналу
extern int Magic = 123; // магик
extern bool Buy = true; // buy
extern bool Sell = true; // sell
extern string IndName="Real Trend";
extern int SignalPeriod= 15;
extern int ArrowPeriod = 2;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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,Lot(),NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| Check for close order conditions |
//+------------------------------------------------------------------+
void ClosePos()
{
double buy=iCustom(NULL,0,IndName,SignalPeriod,ArrowPeriod,2,Shift);
double sell=iCustom(NULL,0,IndName,SignalPeriod,ArrowPeriod,3,Shift);
if(sell>0)
{
CloseAll(0);
}
if(buy>0)
{
CloseAll(1);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
}
}
}
}
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
double lotstep=MarketInfo(Symbol(),MODE_LOTSTEP);
double MinLot=MarketInfo(Symbol(),MODE_MINLOT);
double MaxLot=MarketInfo(Symbol(),MODE_MAXLOT);
if(Lots==0) lot=AccountBalance()/100000*Risk;
lot=NormalizeDouble(lot/lotstep,0)*lotstep;
if(lot<MinLot) lot=MinLot;
if(lot>MaxLot) lot=MaxLot;
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double LastPrice()
{
double lp=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) lp=OrderOpenPrice();
break;
}
}
}
return(lp);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int LastType()
{
int tp=8;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()<2) tp=OrderType();
break;
}
}
}
return(tp);
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
double buy=iCustom(NULL,0,IndName,SignalPeriod,ArrowPeriod,2,Shift);
double sell=iCustom(NULL,0,IndName,SignalPeriod,ArrowPeriod,3,Shift);
if((CountTrades()<1 && buy>0 && Buy) || (CountTrades()<Orders && LastType()==0 && Bid-LastPrice()>Step*Point)) PutOrder(0,Ask);
if((CountTrades()<1 && sell>0 && Sell) || (CountTrades()<Orders && LastType()==1 && LastPrice()-Bid>Step*Point)) PutOrder(1,Bid);
if(CloseSig>0) ClosePos();
}
//+------------------------------------------------------------------+
AM2