//+------------------------------------------------------------------+
//| FractalPoints.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_width1 2
#property indicator_color2 Blue
#property indicator_width2 2
//---- buffers
double up[];
double dn[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,217);
SetIndexBuffer(0,up);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,218);
SetIndexBuffer(1,dn);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutArrow(string name,double price,int code,color clr)
{
ObjectCreate(0,name,OBJ_ARROW,0,Time[2],price);
//--- установим код стрелки
ObjectSetInteger(0,name,OBJPROP_ARROWCODE,code);
//--- установим цвет стрелки
ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
//--- установим размер стрелки
ObjectSetInteger(0,name,OBJPROP_WIDTH,2);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---
int limit=rates_total-prev_calculated;
for(int i=2;i<555;i++)
{
up[i]=iFractals(NULL,0,MODE_UPPER,i);
dn[i]=iFractals(NULL,0,MODE_LOWER,i);
}
double upf=iFractals(NULL,0,MODE_UPPER,2);
double dnf=iFractals(NULL,0,MODE_LOWER,2);
if(upf!=0) PutArrow("UP"+(string)Time[0],High[2],108,Blue);
if(dnf!=0) PutArrow("DN"+(string)Time[0],Low[2],108,Red);
return(rates_total);
}
//+------------------------------------------------------------------+
Если же без шуток — то мне ничего не стоило(вернее стоило бы чего-ниТь, конечно) заказать сова или индюка на стороне, да и сейчас ничего не мешает. Но, почему-то, я разместил свою мыслЮ тут.
//+------------------------------------------------------------------+
//| Lots.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
extern double Lots = 0.1; // лот
extern double DeltaLots = 0.3; // разница в лотах
extern int StopLoss = 0; // лось
extern int TakeProfit = 0; // язь
extern int BULevel = 0; // уровень БУ
extern int BUPoint = 30; // пункты БУ
extern int TrailingStop = 0; // трал
extern int TrailingStep = 20; // шаг трала
extern int Procent = 100; // процент
extern int Delta = 300; // расстояние от цены
extern int Slip = 30; // реквот
extern int Magic = 0; // магик
bool one=true;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price,double lot)
{
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)
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()==type) count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Подсчет лота ордеров по типу |
//+------------------------------------------------------------------+
double CountLots(int type)
{
double count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()==type) count+=OrderLots();
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Ступенчатый трал if(TrailingStop>0) Trailing(); |
//+------------------------------------------------------------------+
void Trailing()
{
bool mod;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY)
{
if(Bid-OrderOpenPrice()>TrailingStop*Point)
{
if(OrderStopLoss()<Bid-(TrailingStop+TrailingStep-1)*Point)
{
mod=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
}
if(OrderType()==OP_SELL)
{
if((OrderOpenPrice()-Ask)>TrailingStop*Point)
{
if(OrderStopLoss()>Ask+(TrailingStop+TrailingStep-1)*Point || OrderStopLoss()==0)
{
mod=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Безубыток ордеров if(BULevel>0) BU(); |
//+------------------------------------------------------------------+
void BU()
{
bool m;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY)
{
if(OrderOpenPrice()<=(Bid-(BULevel+BUPoint)*Point) && OrderOpenPrice()>OrderStopLoss())
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+BUPoint*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
if(OrderType()==OP_SELL)
{
if(OrderOpenPrice()>=(Ask+(BULevel+BUPoint)*Point) && (OrderOpenPrice()<OrderStopLoss() || OrderStopLoss()==0))
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-BUPoint*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(IsTesting() && OrdersTotal()<1)
{
for(int i=1;i<=5;i++)
{
PutOrder(4,Bid+200*Point*i,0.1);
PutOrder(5,Bid-200*Point*i,0.1);
}
}
if(BULevel>0) BU();
if(TrailingStop>0) Trailing();
double delta=MathAbs(CountLots(0)-CountLots(1));
if(delta>=DeltaLots && CountLots(0)>CountLots(1) && one)
{
PutOrder(5,Bid-Delta*Point,delta*Procent*0.01);
one=false;
}
if(delta>=DeltaLots && CountLots(1)>CountLots(0) && one)
{
PutOrder(4,Bid+Delta*Point,delta*Procent*0.01);
one=false;
}
Comment("\n Buy Lots: ",CountLots(0),
"\n Sell Lots: ",CountLots(1),
"\n Delta Lots: ",MathAbs(CountLots(0)-CountLots(1)));
}
//+------------------------------------------------------------------+
сам бы я не справился? там все так сложно?
Сделайте пожалуйста в этом советнике завершение торговли при срабатывании стоплосса так, чтобы новые противоположные ордера уже не открывались больше.
Иногда после запятой много цифр
100 п за 25 часов
Этот вариант удаляет самый последний в истории а другой по времени и ни один не дает пока нужной картины:
AM2