//+------------------------------------------------------------------+
//| Supply2.mq4 |
//| Copyright 2021, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // лот
extern double KLot = 1; // умножение лота
extern double MaxLot = 5; // максимальный лот
extern int StopLoss = 200; // лось
extern int TakeProfit = 300; // язь
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
extern string ZoneType = "Untested"; // Untested, Weak
extern string IndName = "shved_supply_and_demand"; //
extern string IndName2 = "TS-1#2"; //
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 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 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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Sup()
{
double max=0;
for(int i=ObjectsTotal()-1; i>=0; i--)
{
if(ObjectType(ObjectName(i))==OBJ_RECTANGLE)
{
if(StringFind(ObjectName(i),"SSSR#S",0)>=0)
{
double p1=ObjectGetDouble(0,ObjectName(i),OBJPROP_PRICE1);
if(p1>max)
{
max=p1;
}
}
}
}
return(max);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Res()
{
// 1. берем 1-е значение
// 2. оно минимальное
// 3. берем следующее
// 4. сравниваем
// 5. если меньше то оно минимальное
double min=0;
for(int i=ObjectsTotal()-1; i>=0; i--)
{
if(ObjectType(ObjectName(i))==OBJ_RECTANGLE)
{
if(StringFind(ObjectName(i),"SSSR#R",0)>=0)
{
double p2=ObjectGetDouble(0,ObjectName(i),OBJPROP_PRICE2);
if(min==0)
{
min=p2;
}
if(p2<min)
{
min=p2;
}
}
}
}
return(min);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
bool buy=1,sell=1;
double gre=iCustom(NULL,0,IndName2,1,0);
double red=iCustom(NULL,0,IndName2,2,0);
buy=Open[1]<Sup() && Close[1]>Sup() && red<111;
sell=Open[1]>Res() && Close[1]<Res() && gre<111;
if(CountOrders()<1)
{
for(int i=ObjectsTotal()-1; i>=0; i--)
{
if(ObjectType(ObjectName(i))==OBJ_RECTANGLE)
{
if(buy)
{
PutOrder(0,Ask);
}
if(sell)
{
PutOrder(1,Bid);
}
}
}
}
double ind = iCustom(NULL,0,IndName,0,0);
Comment("\n Support: ",Sup(),
"\n Resist: ",Res());
}
//+------------------------------------------------------------------+
2021.04.14 20:43:15.903 RSICross EURUSD,H1: array out of range in 'RSICross.mq4' (58,12)
А на некоторых таймфреймах вообще не ставит стрелки.
AM2