Исходный код · ID 3843
nadaraya_watson_aspri-fix.mq5
Вы автор или правообладатель?
Сообщите нам, если считаете, что материал размещён без разрешения.
Сообщить о материале
Обращение по товару «nadaraya_watson_aspri-fix.mq5» отправится на рассмотрение. Укажите контакт для ответа и опишите причину.
Поиск по коду файла
#property version "2.00"
#property strict
#include <Trade\Trade.mqh>
input group "===== Indicator Settings ====="
input double InpBandwidth = 8.0; // Bandwidth (h)
input ENUM_APPLIED_PRICE InpPrice = PRICE_CLOSE; // Price to smooth
input int InpLookback = 300; // Lookback Bars
input group "===== EA Settings ====="
input double InpLotSize = 0.01; // Initial Lot Size
input string InpComment = "EA Nadaraya Watson"; // Order Comment
input bool InpDebugMode = false; // Show Debug Prints
input int InpMinBarsBetweenTrades = 1; // Min Bars Between Trades
input bool InpAllowHedge = true; // Allow Hedge (BUY+SELL)
input group "== Aspri Trade Function =="
enum ENUM_MARTIN_TYPE { Multiplier, Addition };
input int InpMaxEntri = 1000; // Max Entri
input int InpPipSteps = 2000; // Pip Steps (points)
input ENUM_MARTIN_TYPE InpMartinType = Multiplier; // Martin Type
input double InpMultiplier = 1.0; // Multiplier / Lot Step
input group "== Exit Tools =="
enum ENUM_TP_DOLLAR_TYPE { OFF, USD, Percent };
input ENUM_TP_DOLLAR_TYPE InpTPDollarType = OFF; // TP Dollar Type
input double InpTakeProfitUSD = 250.0; // Take Profit USD
enum ENUM_SL_TYPE { SL_OFF, SL_USD, SL_PERCENT };
input ENUM_SL_TYPE InpStoplossType = SL_OFF; // Stoploss Type (All Pairs)
input double InpStoplossValue = 0.0; // Stoploss in USD / Percent
input bool InpEnableTPPoints = true; // Enable Take Profit Points
input int InpTPPoints = 5000; // Take Profit Points
input bool InpEnableTrailing = false; // Enable Trailing
input int InpTrailingStart = 200; // Trailing Start Points
input int InpTrailingStep = 50; // Trailing Step Points
input int InpMagicNumber = 489471; // Magic Number (use 0 for Manual)
CTrade trade;
datetime lastBarTime;
double lastNW = 0;
int barsSinceLastTrade = 999;
bool firstRun = true;
int lastSignalDir = 0; // 1=BUY, -1=SELL, 0=none
int OnInit()
{
// код доступен только после оплаты
}
void OnDeinit(const int reason)
{
Print("===== Nadaraya-Watson Aspri EA Stopped =====");
}
double GaussianKernel(double x, double h)
{
return MathExp(-(MathPow(x, 2) / (h * h * 2)));
}
double CalculateNW(int shift)
{
double sum = 0;
double sumw = 0;
int maxBars = MathMin(InpLookback, Bars(_Symbol, PERIOD_CURRENT) - shift);
for(int j = 0; j < maxBars; j++)
{
double price = 0;
switch(InpPrice)
{
case PRICE_CLOSE: price = iClose(_Symbol, PERIOD_CURRENT, shift + j); break;
case PRICE_OPEN: price = iOpen(_Symbol, PERIOD_CURRENT, shift + j); break;
case PRICE_HIGH: price = iHigh(_Symbol, PERIOD_CURRENT, shift + j); break;
case PRICE_LOW: price = iLow(_Symbol, PERIOD_CURRENT, shift + j); break;
case PRICE_MEDIAN: price = (iHigh(_Symbol, PERIOD_CURRENT, shift + j) + iLow(_Symbol, PERIOD_CURRENT, shift + j)) / 2; break;
case PRICE_TYPICAL: price = (iHigh(_Symbol, PERIOD_CURRENT, shift + j) + iLow(_Symbol, PERIOD_CURRENT, shift + j) + iClose(_Symbol, PERIOD_CURRENT, shift + j)) / 3; break;
case PRICE_WEIGHTED: price = (iHigh(_Symbol, PERIOD_CURRENT, shift + j) + iLow(_Symbol, PERIOD_CURRENT, shift + j) + 2*iClose(_Symbol, PERIOD_CURRENT, shift + j)) / 4; break;
default: price = iClose(_Symbol, PERIOD_CURRENT, shift + j);
}
double w = GaussianKernel((double)j, InpBandwidth);
sum += price * w;
sumw += w;
}
return (sumw != 0) ? sum / sumw : 0;
}
int CountPositions(ENUM_POSITION_TYPE posType)
{
int count = 0;
for(int i = PositionsTotal() - 1; i >= 0; i--)
{
ulong ticket = PositionGetTicket(i);
if(ticket > 0)
{
if(PositionGetString(POSITION_SYMBOL) == _Symbol)
{
if(InpMagicNumber == 0 || PositionGetInteger(POSITION_MAGIC) == InpMagicNumber)
{
if(PositionGetInteger(POSITION_TYPE) == posType)
count++;
}
}
}
}
return count;
}
int GetTotalPositions(ENUM_POSITION_TYPE posType)
{
return CountPositions(posType);
}
double GetAveragePrice(ENUM_POSITION_TYPE posType)
{
double totalLots = 0;
double totalValue = 0;
for(int i = PositionsTotal() - 1; i >= 0; i--)
{
ulong ticket = PositionGetTicket(i);
if(ticket > 0)
{
if(PositionGetString(POSITION_SYMBOL) == _Symbol)
{
if(InpMagicNumber == 0 || PositionGetInteger(POSITION_MAGIC) == InpMagicNumber)
{
if(PositionGetInteger(POSITION_TYPE) == posType)
{
double lots = PositionGetDouble(POSITION_VOLUME);
double price = PositionGetDouble(POSITION_PRICE_OPEN);
totalLots += lots;
totalValue += lots * price;
}
}
}
}
}
return (totalLots > 0) ? totalValue / totalLots : 0;
}
double GetTotalLots(ENUM_POSITION_TYPE posType)
{
double totalLots = 0;
for(int i = PositionsTotal() - 1; i >= 0; i--)
{
ulong ticket = PositionGetTicket(i);
if(ticket > 0)
{
if(PositionGetString(POSITION_SYMBOL) == _Symbol)
{
if(InpMagicNumber == 0 || PositionGetInteger(POSITION_MAGIC) == InpMagicNumber)
{
if(PositionGetInteger(POSITION_TYPE) == posType)
{
totalLots += PositionGetDouble(POSITION_VOLUME);
}
}
}
}
}
return totalLots;
}
double GetTotalProfit(ENUM_POSITION_TYPE posType)
{
double totalProfit = 0;
for(int i = PositionsTotal() - 1; i >= 0; i--)
{
ulong ticket = PositionGetTicket(i);
if(ticket > 0)
{
if(PositionGetString(POSITION_SYMBOL) == _Symbol)
{
if(InpMagicNumber == 0 || PositionGetInteger(POSITION_MAGIC) == InpMagicNumber)
{
if(PositionGetInteger(POSITION_TYPE) == posType)
{
totalProfit += PositionGetDouble(POSITION_PROFIT) +
PositionGetDouble(POSITION_SWAP);
}
}
}
}
}
return totalProfit;
}
double GetLastPositionPrice(ENUM_POSITION_TYPE posType)
{
datetime lastTime = 0;
double lastPrice = 0;
for(int i = PositionsTotal() - 1; i >= 0; i--)
{
ulong ticket = PositionGetTicket(i);
if(ticket > 0)
{
if(PositionGetString(POSITION_SYMBOL) == _Symbol)
{
if(InpMagicNumber == 0 || PositionGetInteger(POSITION_MAGIC) == InpMagicNumber)
{
if(PositionGetInteger(POSITION_TYPE) == posType)
{
datetime posTime = (datetime)PositionGetInteger(POSITION_TIME);
if(posTime > lastTime)
{
lastTime = posTime;
lastPrice = PositionGetDouble(POSITION_PRICE_OPEN);
}
}
}
}
}
}
return lastPrice;
}
double CalculateNextLot(int entryCount)
{
double nextLot = InpLotSize;
if(entryCount > 0)
{
if(InpMartinType == Multiplier)
{
nextLot = InpLotSize * MathPow(InpMultiplier, entryCount);
}
else // Addition
{
nextLot = InpLotSize + (InpMultiplier * entryCount);
}
}
double minLot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
double maxLot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX);
double lotStep = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);
nextLot = MathMax(minLot, nextLot);
nextLot = MathMin(maxLot, nextLot);
nextLot = NormalizeDouble(MathRound(nextLot / lotStep) * lotStep, 2);
return nextLot;
}
bool CanAddAveraging(ENUM_POSITION_TYPE posType)
{
int count = CountPositions(posType);
if(count >= InpMaxEntri) return false;
if(count == 0) return false; // No position to average
double lastPrice = GetLastPositionPrice(posType);
if(lastPrice == 0) return false;
double currentPrice = (posType == POSITION_TYPE_BUY) ?
SymbolInfoDouble(_Symbol, SYMBOL_ASK) :
SymbolInfoDouble(_Symbol, SYMBOL_BID);
double distance = MathAbs(currentPrice - lastPrice) / _Point;
if(posType == POSITION_TYPE_BUY)
{
if(currentPrice < lastPrice && distance >= InpPipSteps)
return true;
}
else
{
if(currentPrice >Показано первые 50% кода (символов: 13301)
Что вы получите после оплаты
На этой странице откроется полный исходный код файла вместо ознакомительного фрагмента.
Зачем нужен email? Адрес передаётся вместе с заказом в магазин и сохраняется для связи заказа с оплатой. Укажите адрес, к которому у вас есть доступ.
Чтобы оформить заказ, введите email и перейдите к оплате.
Стоимость полного кода: 1 330 ₽ (≈ $15.70 USDT)