Project_N_1/Project_N_1.mq5
super.admin fca2fc1d82 convert
2025-05-30 16:18:18 +02:00

222 lines
16 KiB
MQL5

// Project_N_1.mq5
#include <General_class_.mqh>
#include <Indicators_class.mqh>
#include <ExternalIndicators_class.mqh>
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
CGeneral_class gc;
CIndicators_class ind;
CExternalIndicators_class externalind;
input group "---- Donchian Chanel ----"
//+-----------------------------------+
//| ВХОДНЫЕ ПАРАМЕТРЫ Donchian Chanel|
//+-----------------------------------+
input int DonchianPeriod=20; //Период усреднения
input Applied_Extrem Extremes=HIGH_LOW; //Тип экстремумов
input int Margins=-2;
input int Shift=0; //сдвиг индикатора по горизонтали в барах
//+-----------------------------------+
//---- индикаторные буферы
double upperBuffer[];
double middleBuffer[];
double lowerBuffer[];
//-----------------------------------------------------------
input group "---------------"
input bool NewBar = true;
input bool TimeCheck = true;
input ENUM_TIMEFRAMES per = PERIOD_M1; //Период для текущей торговли
input ENUM_TIMEFRAMES per2 = PERIOD_M5; //Период для долгосрочного тренда
int Slippage = 30;
input group "------------------ Bollinger_bands ------------------ "
//Bollinger_bands
input int BBPeriod = 30; // Bands Period1
input double BBDev = 1; // Bands Deviation1
input double Razmah = 20; // Bands Deviation1 in Points
input ENUM_APPLIED_PRICE Bollinger_Applied_price = PRICE_CLOSE;
double up[], dn[], bs[];
int _bars = 0;
//Stohastic
input int InpPeriodK1 = 5; // First Stochastic %K period
input int InpPeriodD1 = 3; // First Stochastic %D period
input int InpSlowing1 = 3; // First Stochastic slowing
input ENUM_MA_METHOD Stohastic_MA_Mode = MODE_CLOSE;
input ENUM_STO_PRICE Stohastic_STO_PRICE = STO_LOWHIGH;
input int low_lim=20;
input int up_lim=80;
double Stohastic_main[];
double Stohastic_signal[];
string Start_Time = "20";
string End_Time = "06";
double Volume_last_buy = 0;
double Volume_last_sell = 0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
a_trade.SetExpertMagicNumber(Magic);
//ind.Bollinger_handle(_Symbol,per,BBPeriod,0,BBDev,Bollinger_Applied_price,false);
//i.Stochastic_handle(_Symbol,per,InpPeriodK1,InpPeriodD1,InpSlowing1,Stohastic_MA_Mode,Stohastic_STO_PRICE, true);
// ternalind._Donchian_handle(_Symbol,per,DonchianPeriod,Margins,Shift,false);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
int flag = 1;
void OnTick()
{
double Ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK); // получаем цену аск
double Bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
//
// externalind._Dochian_buffer(upperBuffer,middleBuffer,lowerBuffer);
//
// ind.Bollinger_buffers(up,dn,bs);
// ind.Stohastic_buffers(Stohastic_main,Stohastic_signal);
//
//double r_Bollinger = up[0] - dn[0]; // Разница между верхним и нижним Bollinger
int ob = 0, os = 0;
datetime t_ob = 0, t_os = 0;
gc.CheckOpen(ob, os, t_ob, t_os); // на каждом тике проверяем наличие открытой позиции
if(ob == 0)
Volume_last_buy = 0;
if(os == 0)
Volume_last_sell = 0;
double Volume_current_sell = 0;
double Volume_current_buy = 0;
gc.CheckVolume(Volume_current_sell,Volume_current_buy);
Print("buy ",Volume_current_buy," sell ",Volume_current_sell);
int first_st_stop = 700;
int second_stop = 1000;
Print("last_buy ", Volume_last_buy," last_sell ",Volume_last_sell);
if(Volume_current_buy>Volume_last_buy /*&& DeltaPos() > first_st_stop* _Point && DeltaPos() < second_stop * _Point*/)
{
CloseBuyPartial(_Symbol,3);
Volume_last_buy = Volume_current_buy;
}
if(Volume_current_sell>Volume_last_sell /*&& DeltaPos() > first_st_stop* _Point && DeltaPos() < second_stop * _Point*/)
{
CloseSellPartial(_Symbol,3);
Volume_last_sell = Volume_current_sell;
}
// if(NewBar)
{
if(!gc.isNewBar(per))
return;
}
////-------------------Закрытие позиции---------------------------------------------
// if(ob > 0 && Ask >= up[0])
// {
// gc.CloseBuy();
// }
//
// if(os > 0 && Bid <= dn[0])
// {
// gc.CloseSell();
// }
//-------------------Открытие позиции---------------------------------------------
// if(TimeCheck)
// {
// if(!gc.CheckTimePeriod(Start_Time,End_Time))
// return;
// }
//
// if(ob == 0 && Ask <= dn[0] && r_Bollinger > Razmah * _Point && Stohastic_main[0] < low_lim)
// {
// a_trade.Buy(0.1,_Symbol,Ask,0,0);
// }
// if(os == 0 && Bid >= up[0] && r_Bollinger > Razmah * _Point && Stohastic_main[0] > up_lim)
// {
// a_trade.Sell(0.1,_Symbol,Bid,0,0);
// }
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseBuyPartial(string Symbol_, int x)
{
double Volume_current_buy = 0;
for(int i = PositionsTotal() - 1; i >= 0; i--)
{
a_position.SelectByIndex(i);
if(a_position.Magic() == Magic && a_position.Symbol() == Symbol_)
{
if(a_position.PositionType() == POSITION_TYPE_BUY)
{
Volume_current_buy += PositionGetDouble(POSITION_VOLUME);
double Lot = NormalizeDouble(Volume_current_buy/x, 2);
bool o = a_trade.PositionClosePartial(Symbol_,Lot,-1);
if(o == false)
Print("<--- CloseBuy ", _LastError, " ", __LINE__);
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseSellPartial(string Symbol_, int x)
{
double Volume_current_sell = 0;
for(int i = PositionsTotal() - 1; i >= 0; i--)
{
a_position.SelectByIndex(i);
if(a_position.PositionType() == POSITION_TYPE_SELL)
{
Volume_current_sell += PositionGetDouble(POSITION_VOLUME);
double Lot = NormalizeDouble(Volume_current_sell/x, 2);
bool o = a_trade.PositionClosePartial(Symbol_,Lot,-1);
if(o == false)
Print("<--- CloseBuy ", _LastError, " ", __LINE__);
}
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double DeltaPos() // находит кол-во пунктов от цены открытия до текущей цены
{
double Bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
double price = 0;
for(int i = 0; i < PositionsTotal(); i++)
{
a_position.SelectByIndex(i);
if(a_position.Symbol() == _Symbol && a_position.Magic() == Magic)
{
price = a_position.PriceOpen();
break;
}
}
return MathAbs(Bid - price);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+