double main=iBands(NULL,0,BBPeriod,BBDev,0,0,0,Shift);
...
tp=NormalizeDouble(main,Digits);
Андрей пожалуйста можно как первом RSI надстраиваемый
//+------------------------------------------------------------------+
//| HedgeMartin.mq4 |
//| Copyright 2017, AM2 |
//| www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, AM2"
#property link "http://forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Loss = 9000; // убыток в валюте
extern double Profit = 10; // профит в валюте
extern double Lots = 0.1; // лот
extern double KLot = 2; // увеличение лота
extern double MaxLot = 10; // максимальный лот
extern int Delta = 100; // дельта
extern int Slip = 30; // проскальзывание
extern int Magic = 123; // магик
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
{
int r=0;
color clr=Green;
if(type==1 || type==3 || type==5)
{
clr=Red;
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
}
r=OrderSend(NULL,type,Lot(),NormalizeDouble(price,Digits),Slip,0,0,"",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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int LastOrderType()
{
int type=0;
if(OrderSelect(OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY) type=1; //buy
if(OrderType()==OP_SELL) type=2; //sell
}
}
return(type);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double LastOrderOpenPrice()
{
double pr=0;
if(OrderSelect(OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && (OrderMagicNumber()==Magic || OrderMagicNumber()==0))
{
if(OrderType()<2) pr=OrderOpenPrice();
}
}
return(pr);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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 || OrderMagicNumber()==0))
{
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);
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double AllProfit()
{
double profit=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && (OrderMagicNumber()==Magic || OrderMagicNumber()==0))
{
if(OrderType()<2) profit+=OrderProfit()+OrderSwap()+OrderCommission();
}
}
}
return(profit);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
if(CountTrades()>0) lot=NormalizeDouble(Lots*MathPow(KLot,CountTrades()),2);
if(lot>MaxLot)lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountOrders(int type)
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && (OrderMagicNumber()==Magic || OrderMagicNumber()==0))
{
if(OrderType()==type) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DelOrder()
{
bool del;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()>1) del=OrderDelete(OrderTicket());
}
}
}
return;
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
// открытие первого ордера
if(CountTrades()<1)
{
PutOrder(0,Ask);
}
// открытие последующих ордеров
if(CountTrades()>0)
{
if(LastOrderType()==1)
{
if(CountOrders(5)<1) PutOrder(5,LastOrderOpenPrice()-Delta*Point);
}
if(LastOrderType()==2)
{
if(CountOrders(4)<1) PutOrder(4,LastOrderOpenPrice()+Delta*Point);
}
}
if(AllProfit()>Profit || AllProfit()<-Loss)
{
CloseAll();
DelOrder();
}
Comment("\n Profit: ",DoubleToString(AllProfit(),2),
"\n Last Order Type: ",LastOrderType(),
"\n Count Trades: ",CountTrades());
}
//+------------------------------------------------------------------+
AM2