это не изменение алгоритма, а только проверка расчета.
сделаем проверку. на 15-е
Выставлять позиции через сигнал (сигнал от индикатора 1 сигнал ставка ,2 сигнал в ту же сторону пропускаем ,3 сигнал ставим и т.д.
double cci = iCCI(NULL,0,CCIPeriod,PRICE_TYPICAL,Shift);
if(CountTrades()<1)
{
if(cci>0)
{
PutOrder(0,Ask);
}
if(cci<0)
{
PutOrder(1,Bid);
}
}
//+------------------------------------------------------------------+
//| SuperTrend7.mq4 |
//| Copyright 2021, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // лот
extern double Risk = 2; // риск
extern double Depo = 10000; // депо
extern int StopLoss = 444; // лось
extern int TakeProfit = 555; // язь
extern int Round = 2; // округление
extern int Shift = 1; // бар индикатора
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
int Zero = 0;
int CCI_Period = 50;
extern int ATR_Period = 55;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
switch(Period())
{
case PERIOD_M1:
CCI_Period = 80;
break;
case PERIOD_M5:
CCI_Period = 55;
break;
case PERIOD_M15:
CCI_Period = 70;
break;
case PERIOD_M30:
CCI_Period = 60;
break;
case PERIOD_H1:
CCI_Period = 50;
break;
case PERIOD_H4:
CCI_Period = 50;
break;
default:
CCI_Period = 50;
}
//---
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);
}
if(AccountFreeMarginCheck(Symbol(),type,Lot())<=0)
{
Print("Недостаточно средств для открытия позиции объемом: ",Lot());
return;
}
r=OrderSend(NULL,type,Lot(),NormalizeDouble(price,_Digits),Slip,sl,tp,"",Magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
double maxl=MarketInfo(NULL,MODE_MAXLOT);
double minl=MarketInfo(NULL,MODE_MINLOT);
if(Lots==0)
{
lot=NormalizeDouble((AccountEquity()*Risk/100)/StopLoss,Round);
}
if(lot<minl)
lot=minl;
if(lot>maxl)
lot=maxl;
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double cci1 = iCCI(NULL, 0, CCI_Period, PRICE_TYPICAL, Shift);
double cci2 = iCCI(NULL, 0, CCI_Period, PRICE_TYPICAL, Shift + 1);
double SumDifHighLow = 0;
double AverCandleHeight = 0;
for(int i = Shift; i <= Shift + 3; i++)
SumDifHighLow += High[i] - Low[i];
AverCandleHeight = SumDifHighLow / 4.0;
if(CountTrades()<1)
{
if(cci1>0 && cci2<0)
{
PutOrder(0,Ask);
}
if(cci1<0 && cci2>0)
{
PutOrder(1,Bid);
}
}
Comment("\n Lot: ",NormalizeDouble((Depo*Risk/100)/StopLoss,Round));
}
//+------------------------------------------------------------------+
AM2