input int sec1=10; // нахождение на тф1
input int sec2=1; // нахождение на тф2
input ENUM_TIMEFRAMES tf1=PERIOD_M15;
input ENUM_TIMEFRAMES tf2=PERIOD_M30;
1209 errors, 0 warnings
//+------------------------------------------------------------------+
//| Coridor.mq4 |
//| Copyright 2022, AM2 |
//| https://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, AM2"
#property link "https://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 = 0; // лось
extern int TakeProfit = 0; // язь
extern int Slip = 30; // реквот
extern int CloseSig = 1; // закрытие по сигналу
extern int Shift = 1; // бар индикатора
extern int Magic = 123; // магик
extern bool Buy = 1; // покупки
extern bool Sell = 1; // продажи
extern string Comm = "Coridor"; // коментарий
extern string IndName = "Coridor";
extern string TimeFrame = "Current time frame";
extern int Lag = 25;
extern int NumComps = 2;
extern int PeriodNom = 10;
extern int N = 400;
extern double HighLowStep = 0.005;
extern double Level = 0.1;
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,Lot(),NormalizeDouble(price,_Digits),Slip,sl,tp,"",Magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderProfit()>0)
{
lot=Lots;
break;
}
if(OrderProfit()<0)
{
lot=OrderLots()*KLot;
break;
}
}
}
if(lot>MaxLot)
lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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 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 yel1 = iCustom(NULL,0,IndName,TimeFrame,Lag,NumComps,PeriodNom,N,HighLowStep,0,Shift);
double yel2 = iCustom(NULL,0,IndName,TimeFrame,Lag,NumComps,PeriodNom,N,HighLowStep,0,Shift+1);
bool buy=yel1>-Level && yel2<-Level;
bool sell=yel1<Level && yel2>Level;
if(CountTrades()<1)
{
if(buy && Buy)
PutOrder(0,Ask);
if(sell && Sell)
PutOrder(1,Bid);
}
if(CloseSig>0)
{
if(buy)
CloseAll(1);
if(sell)
CloseAll(0);
}
Comment("\n yel: ",yel1);
}
//+------------------------------------------------------------------+
За основу берётся среднее движение из максимумов м5 за 20 или 'Х' дней и переменную называем 'трал' =^.^=.
AM2