Project_N_1/Project_N_1.mq5

223 lines
16 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 16:18:18 +02:00
<EFBFBD><EFBFBD>// 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; //5@8>4 CA@54=5=8O
input Applied_Extrem Extremes=HIGH_LOW; //"8? M:AB@5<C<>2
input int Margins=-2;
input int Shift=0; //A4283 8=48:0B>@0 ?> 3>@87>=B0;8 2 10@0E
//+-----------------------------------+
//---- 8=48:0B>@=K5 1CD5@K
double upperBuffer[];
double middleBuffer[];
double lowerBuffer[];
//-----------------------------------------------------------
input group "---------------"
input bool NewBar = true;
input bool TimeCheck = true;
input ENUM_TIMEFRAMES per = PERIOD_M1; //5@8>4 4;O B5:CI59 B>@3>2;8
input ENUM_TIMEFRAMES per2 = PERIOD_M5; //5@8>4 4;O 4>;3>A@>G=>3> B@5=40
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); // ?>;CG05< F5=C 0A:
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]; // 07=8F0 <564C 25@E=8< 8 =86=8< Bollinger
int ob = 0, os = 0;
datetime t_ob = 0, t_os = 0;
gc.CheckOpen(ob, os, t_ob, t_os); // =0 :064>< B8:5 ?@>25@O5< =0;8G85 >B:@KB>9 ?>78F88
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;
}
////-------------------0:@KB85 ?>78F88---------------------------------------------
// if(ob > 0 && Ask >= up[0])
// {
// gc.CloseBuy();
// }
//
// if(os > 0 && Bid <= dn[0])
// {
// gc.CloseSell();
// }
//-------------------B:@KB85 ?>78F88---------------------------------------------
// 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() // =0E>48B :>;-2> ?C=:B>2 >B F5=K >B:@KB8O 4> B5:CI59 F5=K
{
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);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+