//+------------------------------------------------------------------+
//| Activator.mq4 |
//| Copyright 2015, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2015, AM2"
#property link "http://www.forexsystems.biz"
#property description "Simple expert advisor"
//--- Inputs
extern double Loss = 50; //лось
extern double Profit = 10; //язь
extern int Slip = 100; //проскальзывание
extern int Magic = 123; //магик
extern double Lots = 0.1; //лот
extern double KLot = 2; //уменьшение лота
extern double MaxLot = 10; //максимальный лот
//----Настройки Gann_HiLo_Activator_v2
extern int LookBack=12; //
int trade=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
if(CountTrades()>0) lot=NormalizeDouble(Lots*MathPow(KLot,CountTrades()),2);
if(lot>MaxLot)lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseAll()
{
bool del;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderMagicNumber()==Magic || OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY) del=OrderClose(OrderTicket(),OrderLots(),Bid,Slip,White);
if(OrderType()==OP_SELL) del=OrderClose(OrderTicket(),OrderLots(),Ask,Slip,White);
}
}
}
return;
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void OpenPos()
{
int res=0;
//--- get ind
double ind=iCustom(Symbol(),0,"Gann_HiLo_Activator_v2",LookBack,0,1);
//--- sell conditions
if(Close[1]<ind)
{
res=OrderSend(NULL,1,Lot(),fND(Bid),Slip,0,0,"",Magic,0,Red);
return;
}
//--- buy conditions
if(Close[1]>ind)
{
res=OrderSend(NULL,0,Lot(),fND(Ask),Slip,0,0,"",Magic,0,Blue);
return;
}
//---
}
//+------------------------------------------------------------------+
double fND(double d,int n=-1)
{
if(n<0) return(NormalizeDouble(d, Digits));
return(NormalizeDouble(d, n));
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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()==OP_BUY || OrderType()==OP_SELL) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--- get ind
double ind=iCustom(Symbol(),0,"Gann_HiLo_Activator_v2",LookBack,0,1);
double BALANCE=AccountInfoDouble(ACCOUNT_BALANCE);
double EQUITY=AccountInfoDouble(ACCOUNT_EQUITY);
double Prosadka=0;
if((Close[1]>ind && Close[3]<ind) || (Close[1]<ind && Close[3]>ind))trade=0;
if(trade==0)
{
OpenPos();
trade++;
}
if(Loss>0)
{
Prosadka=100*(BALANCE-EQUITY)/BALANCE;
{
if(Prosadka>=Loss)
{
CloseAll();
Print("Closed All due to Stop Out");
}
}
}
if(Profit>0)
{
Prosadka=100*(EQUITY-BALANCE)/BALANCE;
{
if(Prosadka>=Profit)
{
CloseAll();
Print("Closed All due to All Profit");
}
}
}
Comment("\n Ind",ind,
"\n Trade",trade);
//---
}
//+------------------------------------------------------------------+
extern string IndName="ticks_volume_indicator_1.1";
Новостей не ждёт
я так понимаю чт о параметры стоха — это утовень от 0-100? тоесть ставлю например 20 — выставляется в стохастике 20 с низу и 80 с верху, я правильно понял?
разница цен
на этой свече должен был открыться ордер
AM2