
#property copyright ""
#property link ""
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_color1 Red
#property indicator_color2 DeepSkyBlue
#property indicator_color3 Gold
#property indicator_color4 Lime
#property indicator_color5 Green
#property indicator_color6 Magenta
#property indicator_color7 Brown
#property indicator_width1 3
#property indicator_width2 2
#property indicator_width3 3
#property indicator_width4 3
#property indicator_width5 3
#property indicator_width6 2
extern int NumberOfBars = 100;
extern string Note = "0 means Display all bars";
extern int MAPeriod = 100;
extern int LookBack = 20;
double red[],blue[],yellow[],green[],white[],magenta[],v4[];
//+----------------------------------------------------------------------------+
//| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru |
//+----------------------------------------------------------------------------+
//| Версия : 30.03.2008 |
//| Описание : Установка объекта OBJ_HLINE горизонтальная линия |
//+----------------------------------------------------------------------------+
//| Параметры: |
//| cl - цвет линии |
//| nm - наименование ("" - время открытия текущего бара) |
//| p1 - ценовой уровень (0 - Bid) |
//| st - стиль линии (0 - простая линия) |
//| wd - ширина линии (0 - по умолчанию) |
//+----------------------------------------------------------------------------+
void SetHLine(color cl, string nm="", double p1=0, int st=0, int wd=1) {
if (nm=="") nm=DoubleToStr(Time[0], 0);
if (p1<=0) p1=Bid;
if (ObjectFind(nm)<0) ObjectCreate(nm, OBJ_HLINE, 0, 0,0);
ObjectSet(nm, OBJPROP_PRICE1, p1);
ObjectSet(nm, OBJPROP_COLOR , cl);
ObjectSet(nm, OBJPROP_STYLE , st);
ObjectSet(nm, OBJPROP_WIDTH , wd);
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexBuffer(0,red);
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexLabel(0,"Climax High ");
SetIndexBuffer(1,blue);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexLabel(1,"Neutral");
SetIndexBuffer(2,yellow);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexLabel(2,"Low ");
SetIndexBuffer(3,green);
SetIndexStyle(3,DRAW_HISTOGRAM);
SetIndexLabel(3,"HighChurn ");
SetIndexBuffer(4,white);
SetIndexStyle(4,DRAW_HISTOGRAM);
SetIndexLabel(4,"Climax Low ");
SetIndexBuffer(5,magenta);
SetIndexStyle(5,DRAW_HISTOGRAM);
SetIndexLabel(5,"ClimaxChurn ");
SetIndexBuffer(6,v4);
SetIndexStyle(6,DRAW_LINE,0,2);
SetIndexLabel(6,"Average("+MAPeriod+")");
IndicatorShortName("Better Volume 1.4" );
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
double VolLowest,Range,Value2,Value3,HiValue2,HiValue3,LoValue3,tempv2,tempv3,tempv;
int limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
if ( NumberOfBars == 0 )
NumberOfBars = Bars-counted_bars;
limit=NumberOfBars; //Bars-counted_bars;
for(int i=0; i<limit; i++)
{
red[i] = 0; blue[i] = Volume[i]; yellow[i] = 0; green[i] = 0; white[i] = 0; magenta[i] = 0;
Value2=0;Value3=0;HiValue2=0;HiValue3=0;LoValue3=99999999;tempv2=0;tempv3=0;tempv=0;
// -- определяем самый низкий объем за 20 свечек и рисуем столбик
VolLowest = Volume[iLowest(NULL,0,MODE_VOLUME,20,i)];
if (Volume[i] == VolLowest)
{
yellow[i] = NormalizeDouble(Volume[i],0);
blue[i]=0;
}
// -- определяем волатильность
Range = (High[i]-Low[i]);
Value2 = Volume[i]*Range;
if ( Range != 0 )
Value3 = Volume[i]/Range;
for ( int n=i;n<i+MAPeriod;n++ )
{
tempv= Volume[n] + tempv;
}
v4[i] = NormalizeDouble(tempv/MAPeriod,0);
for ( n=i;n<i+LookBack;n++)
{
tempv2 = Volume[n]*((High[n]-Low[n]));
if ( tempv2 >= HiValue2 )
HiValue2 = tempv2;
if ( Volume[n]*((High[n]-Low[n])) != 0 )
{
tempv3 = Volume[n] / ((High[n]-Low[n]));
if ( tempv3 > HiValue3 )
HiValue3 = tempv3;
if ( tempv3 < LoValue3 )
LoValue3 = tempv3;
}
}
if ( Value2 == HiValue2 && Close[i] > (High[i] + Low[i]) / 2 )
{
red[i] = NormalizeDouble(Volume[i],0);
blue[i]=0;
yellow[i]=0;
}
if ( Value3 == HiValue3 )
{
green[i] = NormalizeDouble(Volume[i],0);
blue[i] =0;
yellow[i]=0;
red[i]=0;
}
if ( Value2 == HiValue2 && Value3 == HiValue3 )
{
magenta[i] = NormalizeDouble(Volume[i],0);
blue[i]=0;
red[i]=0;
green[i]=0;
yellow[i]=0;
}
if ( Value2 == HiValue2 && Close[i] <= (High[i] + Low[i]) / 2 )
{
white[i] = NormalizeDouble(Volume[i],0);
magenta[i]=0;
blue[i]=0;
red[i]=0;
green[i]=0;
yellow[i]=0;
}
if(red[i]!=0)
{
//ObjectsDeleteAll();
SetHLine(clrRed,"RedOpen "+TimeToString(Time[i],TIME_DATE),Open[i],0,2);
SetHLine(clrRed,"RedClose "+TimeToString(Time[i],TIME_DATE),Close[i],0,2);
}
if(green[i]!=0)
{
//ObjectsDeleteAll();
SetHLine(clrGreen,"GreenOpen "+TimeToString(Time[i],TIME_DATE),Open[i],0,2);
SetHLine(clrGreen,"GreenClose "+TimeToString(Time[i],TIME_DATE),Close[i],0,2);
}
}
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| 4-7 GMT Breakout.mq4 |
//| Copyright © 2009. |
//| http://strategy4you.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009."
#property link "http://strategy4you.ru"
#define h2s 3600
extern double Lot=1.0; // Размер лота для одного ордера(если 0 - расчитывается автоматически)
extern int MaxRisk=2; // % от свободных средств(для расчета лота)
extern int GMTShift=2; // Смещение времени брокера относительно GMT
extern string StartTime="04:00"; // Время начала интервала(время GMT)
extern string EndTime="06:59"; // Время окончания интервала(время GMT)
extern string DelTime="18:00"; // Час удаления отложенных ордеров(время GMT)
extern int TakeProfit=30; // Тейкпрофит(если 0 - то ширина коробки) для 1 ордера. Для 2 удваивается.
extern int StopLoss=0; // Стоплосс(если 0 - то ширина коробки)
extern int Delta=7; // Смещение для установки ордеров
extern int NoTrade=0; // Кол-во пунктов больше которого не торгуем(если 0 - торгуем всегда)
extern bool ShowWarn=true; // Выводить пользователю предупреждения
extern int Magic = 91006; // Magic
string StrategyName="4-7 GMT Breakout";
string error;
double h=0;
double l=0;
datetime d=0;
//+------------------------------------------------------------------+
int init()
{if(!IsTradeAllowed()) return(INIT_FAILED);
if(TakeProfit!=0 && TakeProfit<MarketInfo(Symbol(),MODE_STOPLEVEL))
{Alert("Тейкпрофит меньше разрешенного борокером!");return(INIT_FAILED);}
if(StopLoss!=0 && StopLoss<MarketInfo(Symbol(),MODE_STOPLEVEL))
{Alert("Стоплосс меньше разрешенного борокером!"); return(INIT_FAILED);}
if(Lot!=0 && Lot<MarketInfo(Symbol(),MODE_MINLOT))
{Alert("Лот меньше разрешенного брокером!"); return(INIT_FAILED);}
if(Lot!=0 && Lot>MarketInfo(Symbol(),MODE_MAXLOT))
{Alert("Лот больше разрешенного брокером!"); return(INIT_FAILED);}
if(Lot==0 && MaxRisk<1)
{Alert("Неправильно задан % от свободных средств для расчета лота!"); return(INIT_FAILED);}
if(Lot==0 && MaxRisk>100)
{Alert("Неправильно задан % от свободных средств для расчета лота!"); return(INIT_FAILED);}
return(INIT_SUCCEEDED);}
//+------------------------------------------------------------------+
int deinit() {Comment("");return(0);}
//+------------------------------------------------------------------+
int start()
{
if(DayOfWeek()==0 || DayOfWeek()==6) return(0); // в выходные не работаем
if(!IsTradeAllowed()) return(0); // пропустим тик если терминал занят
double mLot=Lot;
if(Lot==0.0) mLot=GetOptimalLot(MaxRisk);
double a=NormalizeDouble(Ask,Digits);
double b=NormalizeDouble(Bid,Digits);
//...подсчет ордеров
int oBuy=0,oSell=0,sBuy=0,sSell=0;
for(int i=0;i<OrdersTotal();i++)
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{if(OrderType()==OP_BUY) oBuy++;
if(OrderType()==OP_SELL) oSell++;
if(OrderType()==OP_BUYSTOP) sBuy++;
if(OrderType()==OP_SELLSTOP) sSell++;}
//...Удалим не сработавшие отложки если есть и перенесем в безубыток
if(oBuy+oSell+sBuy+sSell>0)
for(i=0;i<OrdersTotal();i++)
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{if(OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP)
if(StrToTime(DelTime+":00")+GMTShift*h2s<=TimeCurrent()) DelOrder();
if(OrderType()==OP_BUY && oBuy==1 && OrderOpenPrice()>OrderStopLoss()+2*Point)
EditOrder(OrderOpenPrice(),OrderTakeProfit(),OrderOpenPrice());
if(OrderType()==OP_SELL && oSell==1 && OrderOpenPrice()<OrderStopLoss()-2*Point)
EditOrder(OrderOpenPrice(),OrderTakeProfit(),OrderOpenPrice());}
//...проверка что сегодня уже торговали
if(d==TimeDay(TimeCurrent())) return(0);
//...расчет коробки
if(TimeCurrent()<StrToTime(StartTime+":00")+GMTShift*h2s) return(0);
int sBar=iBarShift(NULL,0,StrToTime(StartTime+":00")+GMTShift*h2s);
int eBar=iBarShift(NULL,0,StrToTime(EndTime+":59")+GMTShift*h2s);
int cBar=sBar-eBar+1;
h=NormalizeDouble(High[iHighest(NULL,0,MODE_HIGH,cBar,eBar)],Digits);
l=NormalizeDouble(Low[iLowest(NULL,0,MODE_LOW,cBar,eBar)],Digits);
int box=(h-l)*MathPow(10,Digits);
//...проверим размер коробки
if(NoTrade!=0 && box>NoTrade)
{error="Размер коробки: "+box+" больше разрешенного: "+NoTrade+"! Не торгуем.";
if(ShowWarn) Alert(error);
Print(error);
d=TimeDay(TimeCurrent());
return(0);}
//...наступило время Ч?
if(TimeCurrent()<=StrToTime(EndTime+":59")+GMTShift*h2s) return(0);
//...Выставим отложенные ордера
if(oBuy+oSell+sBuy+sSell==0 && a<h && b>l)
{double level=MarketInfo(Symbol(),MODE_STOPLEVEL)*Point;
if((h-a)<level)
{error="Цена слишком близко от верхнего уровня! Верхний уровень увеличен.";
if(ShowWarn) Alert(error);
Print(error);
h=a+level+2*Point;}
if((b-l)<level)
{error="Цена слишком близко от нижнего уровня! Нижний уровень уменьшен.";
if(ShowWarn) Alert(error);
Print(error);
l=b-level-2*Point;}
double bp=NormalizeDouble(h+Delta*Point,Digits);
double sp=NormalizeDouble(l-Delta*Point,Digits);
double TP=0,SL=0;
//при стопе = 0 стоп на противоположной стороне коробки плюс стоплосс пунктов
if(StopLoss>=0) SL=StopLoss*Point; //else SL=h-l;
if(TakeProfit>0) TP=TakeProfit*Point; else TP=h-l;
if(SL<level)
{error="Цена слишком близко от уровня Стоплосса! Уровень Стоплосса увеличен.";
if(ShowWarn) Alert(error);
Print(error);
SL=level;}
if(TP<level)
{error="Цена слишком близко от уровня Профита! Уровень Профита увеличен.";
if(ShowWarn) Alert(error);
Print(error);
TP=level;}
if(StopLoss>=0)
{
NewOrder(OP_BUYSTOP,mLot,bp,bp+TP,l-SL);
NewOrder(OP_BUYSTOP,mLot,bp,bp+TP*2,l-SL);
}
//NewOrder(OP_BUYSTOP,mLot,bp,bp+TP,bp-SL);
//NewOrder(OP_BUYSTOP,mLot,bp,bp+TP*2,bp-SL);
if(StopLoss>=0)
{
NewOrder(OP_SELLSTOP,mLot,sp,sp-TP,h+SL);
NewOrder(OP_SELLSTOP,mLot,sp,sp-TP*2,h+SL);
}
//NewOrder(OP_SELLSTOP,mLot,sp,sp-TP,sp+SL);
//NewOrder(OP_SELLSTOP,mLot,sp,sp-TP*2,sp+SL);
d=TimeDay(TimeCurrent());
}
//...конец
return(0);}
//+------------------------------------------------------------------+
int NewOrder(int Cmd,double lot,double pr,double tp=0,double sl=0)
{int tick=0;
for(int er=0;er<3;er++)
{while(!IsTradeAllowed()) Sleep(100);
tick=OrderSend(Symbol(),Cmd,lot,pr,3,sl,tp,StrategyName,Magic,0,CLR_NONE);
if(tick>0) break;
Print("#",OrderTicket()," Error: ",GetLastError()," Function: NewOrder(",Cmd,",",lot,",",pr,",",tp,",",sl,") №",er);
Sleep(1000);}
return(tick);}
//+------------------------------------------------------------------+
void EditOrder(double pr,double tp,double sl)
{for(int er=0;er<3;er++)
{while(!IsTradeAllowed()) Sleep(100);
if(OrderModify(OrderTicket(),pr,sl,tp,0,CLR_NONE)) break;
Print("#",OrderTicket()," Error: ",GetLastError()," Function: EditOrder(",pr,",",tp,",",sl,") №",er);
Sleep(1000);}}
//+------------------------------------------------------------------+
void DelOrder()
{for(int er=0;er<3;er++)
{while(!IsTradeAllowed()) Sleep(100);
if(OrderDelete(OrderTicket(),CLR_NONE)) break;
Print("#",OrderTicket()," Error: ",GetLastError()," Function: DelOrder() №",er);
Sleep(1000);}}
//+------------------------------------------------------------------+
double NormLot(double lot)
{double Min_Lot=MarketInfo(Symbol(),MODE_MINLOT);
double Max_Lot=MarketInfo(Symbol(),MODE_MAXLOT);
double Step =MarketInfo(Symbol(),MODE_LOTSTEP);
int DigLot =0;
if(Step<0.1) DigLot=2;
if(Step>=0.1) DigLot=1;
if(Step>=1) DigLot=0;
if(lot<Min_Lot) lot=Min_Lot;
if(lot>Max_Lot) lot=Max_Lot;
return(NormalizeDouble(lot,DigLot));}
//+------------------------------------------------------------------+
double GetOptimalLot(int Percent)
{double Free =AccountFreeMargin();
double One_Lot =MarketInfo(Symbol(),MODE_MARGINREQUIRED);
double Step =MarketInfo(Symbol(),MODE_LOTSTEP);
double Lots_New=MathFloor(Free*Percent/100/One_Lot/Step)*Step;
return(NormLot(Lots_New));}
//+------------------------------------------------------------------+
double StMain=iStochastic(NULL,0,8,13,5,MODE_SMA,1,MODE_MAIN,1);
//+------------------------------------------------------------------+
//| ProjectName |
//| Copyright 2012, CompanyName |
//| http://www.companyname.net |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 clrNONE
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
extern int period =16;
extern int method= 3; // MODE_SMA
extern int price = 0; // PRICE_CLOSE
extern int shift = 0;
double Uptrend[];
double Dntrend[];
double ExtMapBuffer[];
double vect[];
static bool bs=false,ba=false;
static int bTime=0;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(4);
SetIndexBuffer(0,ExtMapBuffer);
SetIndexBuffer(1,Uptrend);
SetIndexBuffer(2,Dntrend);
SetIndexBuffer(3,vect);
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);
SetIndexDrawBegin(0,1*period);
SetIndexDrawBegin(1,2*period);
SetIndexDrawBegin(2,3*period);
IndicatorShortName("IFX HMA("+period+")");
SetIndexLabel(1,"UP");
SetIndexLabel(2,"DN");
bs = false;
ba = false;
bTime=0;
return (0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int deinit()
{
return (0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetWMA(int x,int p)
{
return (iMA(NULL, 0, p, 0, method, price, x + shift));
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int p=MathSqrt(period);
int i,limit0,limit1,limit2;
int counted_bars=IndicatorCounted();
if(counted_bars<0)
return (-1);
if(counted_bars>0)
counted_bars--;
limit2=Bars-counted_bars;
if(counted_bars==0)
limit2--;
limit1 = limit2;
limit0 = limit1;
if(counted_bars==0)
{
limit1 -= (period);
limit2 -= (2*period);
}
for(i=limit0; i>=0; i--)
vect[i]=2*GetWMA(i,period/2)-GetWMA(i,period);
for(i=limit1; i>=0; i--)
ExtMapBuffer[i]=iMAOnArray(vect,0,p,0,method,i);
for(i=limit2; i>=0; i--)
{
Uptrend[i]=EMPTY_VALUE;
if(ExtMapBuffer[i]>ExtMapBuffer[i+1])
{
Uptrend[i+1]=ExtMapBuffer[i+1];
Uptrend[i]=ExtMapBuffer[i];
}
Dntrend[i]=EMPTY_VALUE;
if(ExtMapBuffer[i]<ExtMapBuffer[i+1])
{
Dntrend[i+1]=ExtMapBuffer[i+1];
Dntrend[i]=ExtMapBuffer[i];
}
}
if(bTime!=Time[0])
{
bTime=Time[0];
bs = false;
ba = false;
}
return (0);
}
// +------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| HMAColor.mq4 |
//| Copyright 2015, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2015, AM2"
#property link "http://www.forexsystems.biz"
#property description "HMA Color simple expert advisor"
#define MAGICMA 20141020
//--- Inputs
input double StopLoss = 500;
input double TakeProfit = 500;
input double Lots = 0.1;
//----
extern int HMAPeriod = 16;
extern int Method = 3;
extern int Price = 0;
extern int Shift = 0;
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForOpen()
{
int res;
//--- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//--- get Moving Average
double HMABlue=iCustom(Symbol(),0,"HMA",HMAPeriod,Method,Price,Shift,1,1);
double HMARed=iCustom(Symbol(),0,"HMA",HMAPeriod,Method,Price,Shift,2,1);
//--- sell conditions
if(HMABlue>HMARed)
{
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",MAGICMA,0,Red);
return;
}
//--- buy conditions
if(HMARed>HMABlue)
{
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",MAGICMA,0,Blue);
return;
}
//---
}
//+------------------------------------------------------------------+
//| Check for close order conditions |
//+------------------------------------------------------------------+
void CheckForClose()
{
//--- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//--- get Moving Average
double HMABlue=iCustom(Symbol(),0,"HMA",HMAPeriod,Method,Price,Shift,1,1);
double HMARed=iCustom(Symbol(),0,"HMA",HMAPeriod,Method,Price,Shift,2,1);
//---
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
//--- check order type
if(OrderType()==OP_BUY)
{
if(HMABlue>HMARed)
{
if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
if(OrderType()==OP_SELL)
{
if(HMARed>HMABlue)
{
if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
}
//---
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--- check for history and trading
if(Bars<100 || IsTradeAllowed()==false)
return;
//--- calculate open orders by current symbol
if(OrdersTotal()<1) CheckForOpen();
else CheckForClose();
//---
}
//+------------------------------------------------------------------+
if(OrdersTotal()<1 && Month()!=3 && Month()!=4 && Month()!=6 && Month()!=8 /*&& Month()==month*/)
//+------------------------------------------------------------------+
//| 20/200 expert.mq4 |
//| 1H EUR/USD |
//| Smirnov Pavel |
//| www.autoforex.ru |
//+------------------------------------------------------------------+
#property copyright "Smirnov Pavel"
#property link "www.autoforex.ru"
extern int TakeProfit= 200; // Уровень тейкпрофит в пунктах
extern int StopLoss = 2000; // уровень стоплосс в пунктах
extern int TradeTime=18;
extern int t1=7;
extern int t2=2;
extern int delta=70;
extern int month=1;
extern double lot=0.1;
int ticket;
bool cantrade=true;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OpenLong(double volume=0.1)
{
int slippage=10;
string comment="20/200 expert (Long)";
color arrow_color=Red;
int magic=0;
ticket=OrderSend(Symbol(),OP_BUY,volume,Ask,slippage,Ask-StopLoss*Point,
Ask+TakeProfit*Point,comment,magic,0,arrow_color);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
{
Print("Buy order opened : ",OrderOpenPrice());
return(0);
}
}
else
{
Print("Error opening Buy order : ",GetLastError());
return(-1);
}
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OpenShort(double volume=0.1)
{
int slippage=10;
string comment="20/200 expert (Short)";
color arrow_color=Red;
int magic=0;
ticket=OrderSend(Symbol(),OP_SELL,volume,Bid,slippage,Bid+StopLoss*Point,
Bid-TakeProfit*Point,comment,magic,0,arrow_color);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
{
Print("Sell order opened : ",OrderOpenPrice());
return(0);
}
}
else
{
Print("Error opening Sell order : ",GetLastError());
return(-1);
}
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
if((TimeHour(TimeCurrent())>TradeTime)) cantrade=true;
// проверяем есть ли открытые ордера ...
if(OrdersTotal()<1 && Month()!=3 && Month()!=4 && Month()!=6 && Month()!=8 /*&& Month()==month*/)
{
// ... если нет ни одного открытого ордера, то идем дальше
// проверяем настало ли время для торговли
if((TimeHour(TimeCurrent())==TradeTime) && (cantrade))
{
// ... если настало время, то
if((Open[t1]-Open[t2])>delta*Point) //Если цена изменилась на величину delta
{
//условие выполнено значит входим в короткую позицию:
// проверяем есть ли свободные деньги для открытия короткой позиции
if(AccountFreeMarginCheck(Symbol(),OP_SELL,lot)<=0 || GetLastError()==134)
{
Print("Not enough money");
return(0);
}
OpenShort(lot);
cantrade=false; //запрещаем торговать повторно до следующего бара
return(0);
}
if((Open[t2]-Open[t1])>delta*Point) //Если цена изменилась на величину delta
{
// условие выполнено значит входим в длинную позицию
// проверяем есть ли свободные деньги на счету
if(AccountFreeMarginCheck(Symbol(),OP_BUY,lot)<=0 || GetLastError()==134)
{
Print("Not enough money");
return(0);
}
OpenLong(lot);
cantrade=false;
return(0);
}
}
}
return(0);
}
//+------------------------------------------------------------------+
AM2