//+------------------------------------------------------------------+
//| Diver.mq4 |
//| Copyright 2018, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // лот
extern double KLot = 1; // умножение лота
extern double MaxLot = 5; // максимальный лот
extern int StopLoss = 2000; // лось
extern int TakeProfit = 3000; // язь
extern int Slip = 30; // реквот
extern int Shift = 1; // на каком баре сигнал индикатора
extern int Magic = 123; // магик
extern string IndName = "rsx_nrp_reg_histo_mtfdivergence_nmc";
//+------------------------------------------------------------------+
//| 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,Lot(),NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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 OpenPos()
{
double lim = iCustom(NULL,0,IndName,3,Shift);
double red = iCustom(NULL,0,IndName,3,Shift);
if(lim!=EMPTY_VALUE)PutOrder(0,Ask);
if(red!=EMPTY_VALUE)PutOrder(1,Bid);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ClosePos()
{
double lim = iCustom(NULL,0,IndName,3,Shift);
double red = iCustom(NULL,0,IndName,4,Shift);
if(red!=EMPTY_VALUE) CloseAll(0);
if(lim!=EMPTY_VALUE) CloseAll(1);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
for(int i=OrdersHistoryTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderProfit()>0) break;
if(OrderProfit()<0)
{
lot=OrderLots()*KLot;
break;
}
}
}
}
if(lot>MaxLot)lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double lime= iCustom(NULL,0,IndName,3,Shift);
double red = iCustom(NULL,0,IndName,4,Shift);
if(CountTrades()<1) OpenPos();
else ClosePos();
Comment("\n lime: ",lime,
"\n red: ",red);
}
//+------------------------------------------------------------------+
вот интересно будет
//+------------------------------------------------------------------+
//| InrunInduk.mq4 |
//| Copyright 2018, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_width1 2
#property indicator_color2 Red
#property indicator_width2 2
#property indicator_color3 Red
#property indicator_width3 2
double mi[];
double up[];
double dn[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(0,mi);
SetIndexBuffer(1,up);
SetIndexBuffer(2,dn);
//---
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[])
{
//---
for(int i=0;i<1111;i++)
{
mi[i]=(high[i]+low[i])/2;
double sum=(high[i]-low[i]);
up[i]=mi[i]+sum;
dn[i]=mi[i]-sum;
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
среднение не работает, трал не работает. Закрытие получается нет.
double lev[5]={10,20,30,40,70};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutFibo(string name,datetime time1,double price1,datetime time2,double price2)
{
ObjectDelete(0,name);
ObjectCreate(0,name,OBJ_FIBO,0,time1,price1,time2,price2);
for(int i=0;i<5;i++) ObjectSetDouble(0,name,OBJPROP_LEVELVALUE,i,lev[i]);
return;
}
double isi = iIchimoku(NULL,0,Tenkan,Kijun,Senkou,1,Shift);
//+------------------------------------------------------------------+
//| Ishi.mq4 |
//| Copyright 2018, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // лот
extern double KLot = 2; // умножение лота
extern double MaxLot = 5; // максимальный лот
extern int StopLoss = 333; // лось
extern int TakeProfit = 444; // язь
extern int BULevel = 0; // уровень БУ
extern int BUPoint = 30; // пункты БУ
extern int TrailingStop = 0; // трал
extern int Slip = 30; // реквот
extern int Shift = 1; // на каком баре сигнал индикатора
extern int Magic = 123; // магик
extern string IndName="Hist_StepMA_Stoch_KV1_Ex_03";
extern int PeriodWATR = 10;
extern double Kwatr = 1.0000;
input int Tenkan = 9; // Tenkan-sen
input int Kijun = 26; // Kijun-sen
input int Senkou = 52; // Senkou Span B
//+------------------------------------------------------------------+
//| 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,Lot(),NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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;
for(int i=OrdersHistoryTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderProfit()>0) break;
if(OrderProfit()<0)
{
lot=OrderLots()*KLot;
break;
}
}
}
}
if(lot>MaxLot)lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Trailing()
{
bool mod;
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(Bid-OrderOpenPrice()>TrailingStop*Point)
{
if(OrderStopLoss()<Bid-TrailingStop*Point)
{
mod=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
}
if(OrderType()==OP_SELL)
{
if((OrderOpenPrice()-Ask)>TrailingStop*Point)
{
if((OrderStopLoss()>(Ask+TrailingStop*Point)) || (OrderStopLoss()==0))
{
mod=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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;
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(BULevel>0) BU();
if(TrailingStop>0) Trailing();
double isi = iIchimoku(NULL,0,Tenkan,Kijun,Senkou,1,Shift);
double red = iCustom(NULL,0,IndName,PeriodWATR,Kwatr,0,Shift);
double gre = iCustom(NULL,0,IndName,PeriodWATR,Kwatr,1,Shift);
if(CountTrades()<1)
{
if(Close[1]>isi && Close[2]<isi) PutOrder(0,Ask);
if(Close[1]<isi && Close[2]>isi) PutOrder(1,Bid);
}
Comment(isi);
}
//+------------------------------------------------------------------+
AM2