//+------------------------------------------------------------------+
//| High_Low.mq4 |
//| 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"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
input double lot= 0.22;
extern int TP = 1000; // ПРОФИТ
input int _period_ma = 55; // Период МА
extern bool _trailingStop = true; // вкл. трала
input int magic = 123;
// -----------------------------------------------Number of bars to scan
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу |
//+------------------------------------------------------------------+
int CountOrders(int type=-1)
{
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()==type || type==-1)
count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Profit()
{
double pr=0;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
{
pr=OrderProfit();
break;
}
}
}
return(pr);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(CountOrders()<1)
{
Alert("Order Profit: ",Profit());
}
if(_trailingStop)
{
_TrailingStop();
}
int r=0;
CountOrders();
if(NormalizeDouble(iHigh(_Symbol, _Period, 1), Digits) < Ask && CountOrders(OP_BUY) < 1 &&
NormalizeDouble(iMA(NULL,0,_period_ma,0,MODE_SMA,PRICE_CLOSE,1), Digits)< NormalizeDouble(iClose(_Symbol, _Period, 1), Digits) &&
NormalizeDouble(iMA(NULL,0,_period_ma,0,MODE_SMA,PRICE_CLOSE,1), Digits)> NormalizeDouble(iLow(_Symbol, _Period, 1), Digits))
{
r = OrderSend(Symbol(),
OP_BUY,
NormalizeDouble(lot, 2),
Ask,
30,
0, //SL
NormalizeDouble(iHigh(_Symbol, _Period, 1) + TP*Point, Digits), //TP
"МАША",
magic,
0,
Blue); // BUY
}
else
if(NormalizeDouble(iLow(_Symbol, _Period, 1), Digits) > Bid && CountOrders(OP_SELL) < 1 &&
NormalizeDouble(iMA(NULL,0,_period_ma,0,MODE_SMA,PRICE_CLOSE,1), Digits)> NormalizeDouble(iClose(_Symbol, _Period, 1), Digits) &&
NormalizeDouble(iMA(NULL,0,_period_ma,0,MODE_SMA,PRICE_CLOSE,1), Digits)< NormalizeDouble(iHigh(_Symbol, _Period, 1), Digits))
{
r = OrderSend(Symbol(),
OP_SELL,
NormalizeDouble(lot, 2),
Bid,
30,
0, //SL
NormalizeDouble(iLow(_Symbol, _Period, 1) - TP*Point, Digits), //TP
"МАША",
magic,
0,
Red); // SELL
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void _TrailingStop()
{
int i;
bool m;
double _stopLossSellF=NormalizeDouble(iMA(NULL,0,_period_ma,0,MODE_SMA,PRICE_CLOSE,1), Digits),
_stopLossBuyF=NormalizeDouble(iMA(NULL,0,_period_ma,0,MODE_SMA,PRICE_CLOSE,1), Digits);
if(OrdersTotal()>0)
{
for(i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i, SELECT_BY_POS))
{
if(OrderSymbol()==Symbol() /*&& OrderMagicNumber()==-1*/)
{
if(OrderType()==OP_BUY && OrderOpenPrice() < _stopLossBuyF)
{
while(IsTradeContextBusy())
Sleep(1000);
RefreshRates();
m = OrderModify(OrderTicket(),OrderOpenPrice(),_stopLossBuyF,OrderTakeProfit(),OrderExpiration(),CLR_NONE);
}
if(OrderType()==OP_SELL && OrderOpenPrice() > _stopLossSellF && _stopLossSellF!=0.0)
{
while(IsTradeContextBusy())
Sleep(1000);
RefreshRates();
m = OrderModify(OrderTicket(),OrderOpenPrice(),_stopLossSellF,OrderTakeProfit(),OrderExpiration(),CLR_NONE);
}
}
}
}
}
return;
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Candle.mq4 |
//| Copyright 2020, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, 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 = 0; // лось
extern int TakeProfit = 0; // язь
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
extern string Comm = "";
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;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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 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()
{
if(t!=Time[0])
{
CloseAll();
if(Close[1]>Open[1])
{
PutOrder(0,Ask);
}
if(Close[1]<Open[1])
{
PutOrder(1,Bid);
}
t=Time[0];
}
Comment("\n Lot: ",Lot());
}
//+------------------------------------------------------------------+
Советник под любой стрелочный индикатор
AM2