ARIMA_Handle = iARIMA(0, 0, ArraySize(clos), clos, 1, 1, 5, 0);
Она при добавлении на график появляется(
//+------------------------------------------------------------------+
//| ProjectName |
//| Copyright 2018, CompanyName |
//| http://www.companyname.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2023 OpenAI"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 LightSeaGreen
double ARIMA_Buffer[];
double clos[];
int ARIMA_Handle;
// ARIMA calculation function
int iARIMA(const int handle,
const int start,
const int length,
const double &data[],
const int order_diff,
const int order_MA,
const int order_AR,
const int lag)
{
int i, j;
double a, b;
static double arr_MA[], arr_AR[];
if(handle == 0)
{
ArrayResize(arr_MA, length + 1);
ArrayResize(arr_AR, length + 1);
}
for(i = start; i < length; i++)
{
a = data[i];
for(j = 1; j <= order_diff; j++)
{
a -= data[i - j];
}
arr_MA[0] = a / (1 + order_diff);
for(j = 1; j <= order_MA; j++)
{
b = (a - arr_AR[j - 1]) / (1 + order_diff) + arr_MA[j - 1] * (1 - lag);
arr_MA[j] = b;
}
for(j = 0; j < order_AR; j++)
{
arr_AR[j] = arr_AR[j + 1];
}
arr_AR[order_AR] = arr_MA[order_MA];
ARIMA_Buffer[i - start] = arr_MA[0];
}
return handle;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnInit()
{
ArrayResize(clos, Bars(NULL,0));
for(int i = 0; i < Bars(NULL,0); i++)
{
clos[i] = iClose(Symbol(), PERIOD_CURRENT, i);
}
ARIMA_Handle = iARIMA(NULL, 0, 0, clos, ArraySize(clos), 1, 1, 5);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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;
if(prev_calculated == 0)
limit = rates_total - 5;
else
limit = rates_total - prev_calculated;
ARIMA_Handle = iARIMA(ARIMA_Handle, prev_calculated, limit, close, 1, 1, 1, 5);
return limit;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void BU()
{
bool cl=0;
double Ask=SymbolInfoDouble(_Symbol,SYMBOL_ASK);
double Bid=SymbolInfoDouble(_Symbol,SYMBOL_BID);
for(int i=PositionsTotal()-1; i >= 0; i--)
{
if(PositionSelect(_Symbol) && PositionGetDouble(POSITION_VOLUME)==Lots)
{
if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY && PositionGetDouble(POSITION_PRICE_OPEN) > BULevel*_Point)
{
cl = trade.PositionClosePartial(PositionGetTicket(i),0.1);
}
if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL && PositionGetDouble(POSITION_PRICE_OPEN) - Bid > BULevel*_Point)
{
cl = trade.PositionClosePartial(PositionGetTicket(i),0.1);
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void BU2()
{
double lots = 0;
double leave = SymbolInfoDouble(NULL,SYMBOL_VOLUME_MIN);
double Ask=SymbolInfoDouble(_Symbol,SYMBOL_ASK);
double Bid=SymbolInfoDouble(_Symbol,SYMBOL_BID);
for(int i=PositionsTotal()-1; i >= 0; i--)
{
if(PositionSelect(_Symbol))
{
lots = PositionGetDouble(POSITION_VOLUME) - leave;
lots = NormalizeDouble(lots,2);
if(lots < SymbolInfoDouble(NULL,SYMBOL_VOLUME_MIN))
continue;
if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY && Ask - PositionGetDouble(POSITION_PRICE_OPEN) > BULevel*_Point)
{
// make sure lot is not smaller than allowed value
if(leave < SymbolInfoDouble(NULL,SYMBOL_VOLUME_MIN))
Print("BreakEven block error - Leave Lots value is smaller than minimal allowed value by your broker.");
else
{
bool ret1 = trade.PositionClosePartial(PositionGetTicket(i),lots);
if(ret1 == false)
Print("OrderModify() error - ", (GetLastError()));
}
}
if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL && PositionGetDouble(POSITION_PRICE_OPEN) - Bid > BULevel*_Point)
{
// make sure lot is not smaller than allowed value
if(leave < SymbolInfoDouble(NULL,SYMBOL_VOLUME_MIN))
Print("BreakEven block error - Leave Lots value is smaller than minimal allowed value by your broker.");
else
{
bool ret2 = trade.PositionClose(PositionGetTicket(i));
if(ret2 == false)
Print("OrderModify() error - ", (GetLastError()));
}
}
}
else
Print("OrderSelect() error - ", (GetLastError()));
}
}
AM2