в тесте было несколько пар
первое падение до почти нуля — usdchf
второе — да, еврей
//+------------------------------------------------------------------+
//| Sila.mq4 |
//| Copyright 2017, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, 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 = 2000; // лось
extern int TakeProfit = 3000; // язь
extern int Slip = 30; // реквот
extern int Shift = 1; // на каком баре сигнал индикатора
extern int Magic = 123; // магик
extern string IndName = "Trend Strength";
extern int STPeriod = 13;
extern string IndName1 = "Trend Momentum";
extern int Period1 = 5;
extern int DPeriod1 = 3;
extern int SlowingPeriod1=3;
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,Lots,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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OpenPos()
{
double ao = iAO(NULL,0,Shift);
double ao1 = iAO(NULL,0,Shift+1);
double blue = iCustom(NULL,0,IndName,STPeriod,0,Shift);
double red = iCustom(NULL,0,IndName,STPeriod,1,Shift);
double blue1 = iCustom(NULL,0,IndName1,Period1,DPeriod1,SlowingPeriod1,0,Shift);
double red1 = iCustom(NULL,0,IndName1,Period1,DPeriod1,SlowingPeriod1,1,Shift);
/*
Покупки:
-АО окрашен в зеленый цвет;
-Trend Momentum в синий;
-Trend Strength синяя и выше 16 уровня
Продажи:
-АО окрашен в красный цвет;
-Trend Momentum в красный;
-Trend Strength красная и выше 16 уровня
*/
if(ao1>ao && blue1<1000 && blue>0 && blue>16)
{
PutOrder(0,Ask);
}
if(ao1<ao && red1<1000 && red>0 && red>16)
{
PutOrder(1,Bid);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ClosePos()
{
double ao = iAO(NULL,0,Shift);
double ao1 = iAO(NULL,0,Shift+1);
double blue = iCustom(NULL,0,IndName,STPeriod,0,Shift);
double red = iCustom(NULL,0,IndName,STPeriod,1,Shift);
double blue1 = iCustom(NULL,0,IndName1,Period1,DPeriod1,SlowingPeriod1,0,Shift);
double red1 = iCustom(NULL,0,IndName1,Period1,DPeriod1,SlowingPeriod1,1,Shift);
//---Выход из сделки когда 2 индикатора АО и Trend Momentum показывают противоположное направление
if((ao<ao1 && blue1<1000) || (ao>ao1 && red1<1000))
{
CloseAll();
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseAll()
{
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()==OP_BUY)
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slip,White);
}
if(OrderType()==OP_SELL)
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slip,White);
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double ao = iAO(NULL,0,Shift);
double blue = iCustom(NULL,0,IndName,STPeriod,0,Shift);
double red = iCustom(NULL,0,IndName,STPeriod,1,Shift);
double blue1 = iCustom(NULL,0,IndName1,Period1,DPeriod1,SlowingPeriod1,0,Shift);
double red1 = iCustom(NULL,0,IndName1,Period1,DPeriod1,SlowingPeriod1,1,Shift);
if(CountTrades()<1 && t!=Time[0])
{
OpenPos();
}
else ClosePos();
t=Time[0];
Comment("\n blue: ",blue,
"\n red: ",red,
"\n blue1: ",blue1,
"\n red1: ",red1);
}
//+------------------------------------------------------------------+
Когда вы услышите, что об акциях начинает говорить чистильщик ботинок, знайте – пришло время продавать.
Биткоин — будущее или пирамида?
Уважаемый АМ2, немного не понял, как он выстраивает проценты)
double Procent(double p)
{
double proc=(up-dn)*p/100;
return(proc);
}
M-mason