test_group/ba/RusBafet_ma.mq5

142 lines
9 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 16:31:23 +02:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| RusBafetma.mq5 |
//| Copyright 2019, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
enum sell_or_buy1
{
up,//!=87C 225@E (?>:C?:0)
down, // !25@EC 2=87 (?@>4060)
all // 10
};
input int ma_big=14;
input int ma_small=7;
//input int ma_trend=100;
//input bool trend=false;
input int pips=3;
input ENUM_TIMEFRAMES frame=PERIOD_M1;
input sell_or_buy1 sell_or_buy=all;
input double lot=0.01;
double mbig[],msmall[],mtrend[];
int mabig_handle,masmall_handle,matrend_handle,mid;
#include <Trade\Trade.mqh>
CTrade trade;
int OnInit()
{
//---
EventSetTimer(1);
mabig_handle=iMA(NULL,frame,ma_big,0,MODE_EMA,PRICE_CLOSE);
masmall_handle=iMA(NULL,frame,ma_small,0,MODE_EMA,PRICE_CLOSE);
// matrend_handle=iMA(NULL,frame,ma_trend,0,MODE_EMA,PRICE_CLOSE);
if(masmall_handle<0)
{
Print("1J5:B iMA =5 A>740=: MA_handle= ",INVALID_HANDLE);
Print("H81:0 8A?>;=5=8O = ",GetLastError());
//--- ?@8=C48B5;L=>5 7025@H5=85 ?@>3@0<<K
return(-1);
}
if(mabig_handle<0)
{
Print("1J5:B iMA =5 A>740=: MA_handle= ",INVALID_HANDLE);
Print("H81:0 8A?>;=5=8O = ",GetLastError());
//--- ?@8=C48B5;L=>5 7025@H5=85 ?@>3@0<<K
return(-1);
}
/*
if(matrend_handle<0)
{
Print("1J5:B iMA =5 A>740=: MA_handle= ",INVALID_HANDLE);
Print("H81:0 8A?>;=5=8O = ",GetLastError());
//--- ?@8=C48B5;L=>5 7025@H5=85 ?@>3@0<<K
return(-1);
}
*/
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTimer()
{
//---
if(CopyBuffer(mabig_handle,0,0,3,mbig)<=0)
return;
if(CopyBuffer(masmall_handle,0,0,3,msmall)<=0)
return;
// if(CopyBuffer(matrend_handle,0,0,3,mtrend)<=0)
// return;
// ArraySetAsSeries(mtrend,true);
ArraySetAsSeries(mbig,true);
ArraySetAsSeries(msmall,true);
long buy_id,sell_id;
ulong ticket;
//string type;
uint total=PositionsTotal();
int order_buy_c=0;
int order_sell_c=0;
//Alert(total);
//--- ?@>945< 2 F8:;5 ?> 2A5< >@45@0<
for(uint i=0;i<total;i++)
{
//--- ?>;CG8< B8:5B >@45@0 ?> 53> ?>78F88 2 A?8A:5
if((ticket=PositionGetTicket(i))>0)
{
//--- ?>;CG8< A2>9AB20 >@45@0
// type =EnumToString(ENUM_ORDER_TYPE(OrderGetInteger(ORDER_TYPE)));
//--- ?>43>B>28< 8 2K2545< 8=D>@<0F8N >1 >@45@5
// Alert(PositionGetInteger(POSITION_TYPE));
if(PositionGetString(POSITION_SYMBOL)==_Symbol)
{
if(PositionGetInteger(POSITION_TYPE)==1)
{
order_sell_c++;
sell_id=PositionGetInteger(POSITION_IDENTIFIER);
}
else
{
order_buy_c++;
buy_id=PositionGetInteger(POSITION_IDENTIFIER);
}
}
}
}
double Bid=SymbolInfoDouble(_Symbol,SYMBOL_BID);
if(mbig[1]>=msmall[1] && (msmall[0]-mbig[0])>pips*_Point && order_buy_c<1){trade.PositionClose(sell_id);trade.Buy(lot);}
//sell
if(mbig[1]<=msmall[1] && (mbig[0]-msmall[0])>pips*_Point && order_sell_c<1){trade.PositionClose(buy_id); trade.Sell(lot);}
}
//+------------------------------------------------------------------+