inControl
Похожие материалы по тегам
Сообщите нам, если считаете, что материал размещён без разрешения.
Сообщить о материале
Обращение по товару «incontrol_v1_33_clean.mq4» отправится на рассмотрение. Укажите контакт для ответа и опишите причину.
О программе
inControl v1.33 — торговый советник для MetaTrader 4, работающий исключительно на таймфрейме M30. Поддерживает четыре валютные пары: USDJPY, AUDUSD, EURGBP, GBPJPY. Для каждой пары предусмотрены индивидуальные параметры стратегии, включая настройки скользящих средних, сетки уровней и стоп-лоссов.
Советник анализирует ценовые данные и технические индикаторы для определения точек входа. На AUDUSD применяется фильтр из нескольких индикаторов (RSI, MACD, SAR, MFI, AO, Bollinger Bands, скользящая средняя), тогда как для остальных пар используется стратегия на основе скользящей средней MA_Trend. Вход осуществляется через рыночные ордера и отложенные ордера (BuyStop, SellStop, BuyLimit, SellLimit).
Встроены функции управления рисками: автоматический расчёт лота (AutoLot), усреднение позиции (Compounding), ограничение максимальной просадки (MaxDrawDown), контроль проскальзывания и временные ограничения торгов. Также реализована функция CloseAll для закрытия всех позиций.
Настройки программы
| Настройка | Описание |
|---|---|
| Notice | Текстовый параметр, содержащий предупреждение о рисках торговли, отображаемый в комментарии на графике. |
| SimpleForexTeam__ | Текстовый параметр с информацией о команде разработчика и ссылкой на канал. |
| AutoLot | Переключатель автоматического расчёта размера лота на основе баланса счёта и заданной максимальной просадки. |
| Compounding | Переключатель режима усреднения, при котором размер лота пересчитывается на основе текущей маржи. |
| MaxDrawDown | Целочисленный параметр, задающий максимальный процент просадки для расчёта размера лота. |
| ManualLot | Числовой параметр, задающий фиксированный размер лота при отключённом автоматическом расчёте. |
| Slippage | Целочисленный параметр, задающий допустимое проскальзывание в пунктах при исполнении ордеров. |
| AccMini | Переключатель мини-аккаунта, уменьшающий требование к капиталу в 10 раз. |
| CloseAll | Переключатель для принудительного закрытия всех открытых позиций и удаления отложенных ордеров. |
Поиск по коду файла
#property version "1.33"
#property strict
input string Notice = "Trading are risky! Trade only if you can loss your money";
input string SimpleForexTeam__ = "free tools for forex! Join our channel for more free eas";
input string The_our_telegram = "";
input bool AutoLot = true;
input bool Compounding = false;
input int MaxDrawDown = 100;
input double ManualLot = 0.1;
input int Slippage = 10;
input bool AccMini = false;
input bool CloseAll = false;
double g_workLot = 0.1;
int g_slippage = 10;
double g_outCapitalReq[1];
int g_pairId = 0; // 1=USDJPY, 2=AUDUSD, 3=EURGBP, 4=GBPJPY
int g_magic = 481547;
bool g_useSignalFilter = false; // true on AUDUSD, false (MA_Trend) on USDJPY/EURGBP/GBPJPY
bool g_digSwitched = false;
double g_anchorUSD = 0.0;
double g_anchorConv = 0.0;
double g_usdRate = 1.0;
int g_maTF = 30;
int g_maPeriod = 12;
int g_maShift = 0;
int g_maTrendDist = 50;
int g_maOppDist = 1;
int g_ecnMode = 2;
int g_maxSpread = 0; // 0 = disabled
int g_stepOrderShift = 10;
int g_slPips = 800;
int g_buyStopGap = 50;
int g_buyStopOffset = 50;
int g_sellStopGap = 50;
int g_stepCheckMult = 5;
int g_stepCheckMode = 2;
int g_tpTierPips[5] = {250, 300, 360, 500, 550};
int g_gridSpan = 600;
int g_gridSteps[6] = {130, 80, 60, 65, 60, 100};
int g_gridTP[6] = {80, 80, 80, 80, 80, 80};
int g_baseStep = 50;
int g_stepDiv = 10;
int g_baseTP = 80;
int g_hedgeReset = 1;
int g_openHour = 0;
int g_closeHour = 24;
int g_friEndHour = 24;
double g_maxBrokerLot = 10000.0;
bool g_allowSameBar = false;
bool g_centScale = false;
double g_startLot = 0.1;
double g_workLotCopy = 0.1;
int g_curTP = 0;
int g_curStep = 0;
double g_curLotScale = 0.0;
int g_curDDPips = 0;
double g_buyEntryRef = 0.0;
double g_sellEntryRef = 0.0;
double g_stepLotScale[6] = {0.1, 0.1, 0.1, 0.1, 0.1, 0.1};
int g_lotDigits = 2;
int g_freeMarginDiv = 1;
int g_stepDivStep = 0;
int g_tpDivTier = 0;
int g_chartHandle = 0;
int g_maxBarsNeeded = 0;
int g_lastAccount = 0;
int g_maBarsScanned = 0;
int g_isDemoFlag = 0;
int g_sigState = 1;
int g_commentTick = 0;
int g_accountAnchorId = 0;
bool g_buyPendingDelFlag = false;
bool g_sellPendingDelFlag = false;
bool g_buyTPReached = false;
bool g_sellTPReached = false;
bool g_buyOpenLock = false;
bool g_sellOpenLock = false;
int g_lastOpenTime = 0;
int g_tpCloseDelay = 0;
int g_tpTimerBuy = 0;
int g_tpTimerSell = 0;
datetime g_lastBuyBarTime = 0;
datetime g_lastSellBarTime = 0;
double g_ma0 = 0.0;
double g_ma1 = 0.0;
double g_maHighDist = 0.0;
double g_maLowDist = 0.0;
double g_initBalance = 0.0;
double g_minBrokerLot = 0.0;
double g_lotStepBroker = 0.0;
bool g_rsiEnabled = false;
bool g_rsiNewBarOnly = true;
bool g_rsiReverse = false;
int g_rsiTF = 30;
int g_rsiPeriod = 12;
double g_rsiUpper = 70.0;
double g_rsiLower = 30.0;
bool g_macdEnabled = false;
bool g_macdNewBarOnly = true;
bool g_macdReverse = false;
bool g_macdCrossMode = false;
int g_macdTF = 15;
int g_macdFast = 12;
int g_macdSlow = 26;
int g_macdSignal = 9;
bool g_sarEnabled = false;
bool g_sarNewBarOnly = true;
bool g_sarReverse = false;
int g_sarTF = 60;
double g_sarStep = 0.02;
double g_sarMax = 0.2;
bool g_maFilterEn = false;
bool g_maFilterNewBar = true;
bool g_maFilterReverse = false;
int g_maFilterTF = 60;
int g_maFilterPeriod = 14;
int g_maFilterShift = 0;
int g_maFilterDist = 46;
int g_maFilterMethod = 0;
bool g_mfiEnabled = false;
bool g_mfiNewBarOnly = true;
bool g_mfiReverse = false;
int g_mfiTF = 15;
int g_mfiPeriod = 14;
double g_mfiUpper = 80.0;
double g_mfiLower = 20.0;
bool g_aoEnabled = false;
bool g_aoNewBarOnly = true;
bool g_aoReverse = false;
int g_aoTF = 30;
bool g_bbEnabled = false;
bool g_bbNewBarOnly = true;
bool g_bbReverse = false;
int g_bbTF = 30;
int g_bbPeriod = 20;
int g_bbDev = 2;
bool g_indSigReady = false;
bool g_firstCycleEntry = false;
bool g_sarBuy=false, g_sarSell=false;
bool g_rsiBuy=false, g_rsiSell=false;
bool g_macdBuy=false, g_macdSell=false;
bool g_maBuy=false, g_maSell=false;
bool g_mfiBuy=false, g_mfiSell=false;
bool g_aoBuy=false, g_aoSell=false;
bool g_bbBuy=false, g_bbSell=false;
bool g_buyBarOk=false, g_sellBarOk=false;
int g_dllMaTrendUp = 0; // dword_8593F0
int g_dllMaTrendDown = 0; // dword_8593F4
string g_warnExpired = "";
string g_warnHoliday = "";
string g_warnFreeMarginB = "";
string g_warnFreeMarginS = "";
string g_warnTradeStop = "";
string g_warnStopDate = "";
string g_warnWaitInit = "";
string g_warnMaxDD = "";
string g_warnLowDeposit = "";
string g_warnTPZero = "";
string g_warnGeneric = "";
string g_msgHoliday = "This EA does not trade from December, 20 till January, 7";
string g_msgLowDep = "You need to increase your deposit or set AutoLot = FALSE and set manual Lot setting.";
string g_msgBadMaxDD = "MaxDrawDown can not be more than 100 or less than 1";
string g_msgTPZero = "TPn can not be 0. Change TPn!";
double DllTierCapital(const int pairId, const double lotVal)
{
int idx = (int)MathRound(lotVal * 100.0);
if(pairId == 1) // USDJPY
{
if(idx == 1) return 1300.0;
if(idx == 2) return 1900.0;
if(idx == 3) return 2400.0;
if(idx == 4) return 3100.0;
if(idx == 5) return 3600.0;
if(idx == 6) return 4300.0;
if(idx == 7) return 4800.0;
if(idx == 8) return 5500.0;
if(idx == 9) return 6100.0;
}
else if(pairId == 2) // AUDUSD
{
if(idx == 1) return 450.0;
if(idx == 2) return 800.0;
if(idx == 3) return 1000.0;
if(idx == 4) return 1300.0;
if(idx == 5) return 1600.0;
if(idx == 6) return 1900.0;
if(idx == 7) return 2200.0;
if(idx == 8) return 2500.0;
if(idx == 9) return 2800.0;
}
else if(pairId == 3) // EURGBP
{
if(idx == 1) return 320.0;
if(idx == 2) return 600.0;
if(idx == 3) return 850.0;
if(idx == 4) return 1100.0;
if(idx == 5) return 1300.0;
if(idx == 6) return 1550.0;
if(idx == 7) return 1800.0;
if(idx == 8) return 2050.0;
if(idx == 9) return 2300.0;
}
else if(pairId == 4) // GBPJPY
{
if(idx == 1) return 500.0;
if(idx == 2) return 830.0;
if(idx == 3) return 1150.0;
if(idx == 4) return 1450.0;
if(idx == 5) return 1800.0;
if(idx == 6) return 2100.0;
if(idx == 7) return 2350.0;
if(idx == 8) return 2700.0;
if(idx == 9) return 3000.0;
}
return 0.0;
}
double DllMicroLotFromCapital(const int pairId, const double riskCapital, const double anchorConv)
{
double lot = 0.0;
if(pairId == 1) // USDJPY
{
if(anchorConv > riskCapital) lot = 0.09;
if(6100.0 > riskCapital) lot = 0.08;
if(5500.0 > riskCapital) lot = 0.07;
if(4800.0 > riskCapital) lot = 0.06;
if(4300.0 > riskCapital) lot = 0.05;
if(3600.0 > riskCapital) lot = 0.04;
if(3100.0 > riskCapital) lot = 0.03;
if(2400.0 > riskCapital) lot = 0.02;
if(1900.0 > riskCapital) lot = 0.01;
}
else if(pairId == 2) // AUDUSD
{
if(anchorConv > riskCapital) lot = 0.09;
if(2800.0 > riskCapital) lot = 0.08;
if(2500.0 > riskCapital) lot = 0.07;
if(2200.0 > riskCapital) lot = 0.06;
if(1900.0 > riskCapital) lot = 0.05;
if(1600.0 > riskCapital) lot = 0.04;
if(1300.0 > riskCapital) lot = 0.03;
if(1000.0 > riskCapital) lot = 0.02;
if(800.0 > riskCapital) lot = 0.01;
}
else if(pairId == 3) // EURGBP
{
if(anchorConv > riskCapital) lot = 0.09;
if(2300.0 > riskCapital) lot = 0.08;
if(2050.0 > riskCapital) lot = 0.07;
if(1800.0 > riskCapital) lot = 0.06;
if(1550.0 > riskCapital) lot = 0.05;
if(1300.0 > riskCapital) lot = 0.04;
if(1100.0 > riskCapital) lot = 0.03;
if(850.0 > riskCapital) lot = 0.02;
if(600.0 > riskCapital) lot = 0.01;
}
else if(pairId == 4) // GBPJPY
{
if(anchorConv > riskCapital) lot = 0.09;
if(3000.0 > riskCapital) lot = 0.08;
if(2700.0 > riskCapital) lot = 0.07;
if(2350.0 > riskCapital) lot = 0.06;
if(2100.0 > riskCapital) lot = 0.05;
if(1800.0 > riskCapital) lot = 0.04;
if(1450.0 > riskCapital) lot = 0.03;
if(1150.0 > riskCapital) lot = 0.02;
if(830.0 > riskCapital) lot = 0.01;
}
return lot;
}
double DllGetLot(const int pairId, double manualLot, const int autoLotFlag, const int maxDD,
const double balance, const int isDemo, const int gmtOffset, const double anchorConv,
const int chartHwnd, const int accNum, const int lotDigits, const double maxLot,
const double minLot, double &outCapital[])
{
double lot = manualLot;
if(pairId >= 1 && pairId <= 4)
{
if(autoLotFlag == 1)
{
double raw = 0.1 * balance / anchorConv * (double)maxDD / 100.0;
lot = MathPow(0.1, (double)lotDigits) * MathFloor(MathPow(10.0, (double)lotDigits) * raw);
}
if(0.1 <= lot && minLot == 0.01)
{
outCapital[0] = lot * anchorConv * 10.0;
}
else
{
if(autoLotFlag == 1)
{
double riskCapital = (double)maxDD * balance / 100.0;
lot = DllMicroLotFromCapital(pairId, riskCapital, anchorConv);
}
double tierCap = DllTierCapital(pairId, lot);
if(tierCap > 0.0)
outCapital[0] = tierCap;
}
}
return lot;
}
double DllComp(const int pairId, const int maxDD, const double anchorConv, const double equity, double &outCapital[])
{
double lot = 0.0;
if(pairId >= 1 && pairId <= 4)
{
double raw = 0.1 * equity / anchorConv * (double)maxDD / 100.0;
lot = MathPow(0.1, (double)g_lotDigits) * MathFloor(MathPow(10.0, (double)g_lotDigits) * raw);
if(0.1 <= lot && g_minBrokerLot == 0.01)
{
outCapital[0] = lot * anchorConv * 10.0;
}
else
{
double riskCapital = (double)maxDD * equity / 100.0;
lot = DllMicroLotFromCapital(pairId, riskCapital, anchorConv);
double tierCap = DllTierCapital(pairId, lot);
if(tierCap > 0.0)
outCapital[0] = tierCap;
}
}
return lot;
}
int DllSig()
{
return 1;
}
int DllMA_Trend(const double upDist, const double downDist, const int trendThreshold,
const double maCur, const double maPrev, int &outBuy[], int &outSell[],
const int oppThreshold, const double ma0, const double ma1,
const int hedgeReset, const double pointVal)
{
if((double)trendThreshold < upDist / pointVal)
g_dllMaTrendUp = 1;
if((double)trendThreshold < downDist / pointVal)
g_dllMaTrendDown = 1;
if(hedgeReset == 1)
{
if(g_dllMaTrendUp == 1 && maCur <= maPrev)
{
g_dllMaTrendUp = 0;
outBuy[0] = 1;
if(oppThreshold != 0 && (double)oppThreshold < ma1 / pointVal)
{
g_dllMaTrendUp = 0;
outBuy[0] = 0;
outSell[0] = 1;
}
}
else
{
outBuy[0] = 0;
}
if(g_dllMaTrendDown == 1 && maCur >= maPrev)
{
g_dllMaTrendDown = 0;
outSell[0] = 1;
if(oppThreshold != 0 && (double)oppThreshold < ma0 / pointVal)
{
g_dllMaTrendDown = 0;
outSell[0] = 0;
outBuy[0] = 1;
}
}
else
{
outSell[0] = 0;
}
}
else if(hedgeReset == 0)
{
if(g_dllMaTrendUp == 1 && maCur <= maPrev)
{
g_dllMaTrendUp = 0;
outSell[0] = 1;
}
else
{
outSell[0] = 0;
}
if(g_dllMaTrendDown == 1 && maCur >= maPrev)
{
g_dllMaTrendDown = 0;
outBuy[0] = 1;
}
else
{
outBuy[0] = 0;
}
}
return 0;
}
int DllOpenSig(int &buyTkt[], int &buyLimTkt[], int &buyStopTkt[],
int &sellTkt[], int &sellLimTkt[], int &sellStopTkt[],
const int buyLock, const int sellLock,
int &buyReady[], int &sellReady[],
const int hedgeReset, const int firstCycle, const double pointVal)
{
int sig = 0;
if(buyTkt[0] == 0 && buyLimTkt[0] == 0 && buyStopTkt[0] == 0 && buyLock != 1 && buyReady[0] == 1
&& ((hedgeReset == 1 && sellTkt[0] == 0) || hedgeReset == 0 || firstCycle == 1))
{
sig = 1;
}
if(sellTkt[0] == 0 && sellLimTkt[0] == 0 && sellStopTkt[0] == 0 && sellLock != 1 && sellReady[0] == 1
&& ((hedgeReset == 1 && buyTkt[0] == 0) || hedgeReset == 0 || firstCycle == 1))
{
sig = 2;
}
return sig;
}
bool DllTimeMng(int &curTimeArr[], const datetime minTime, const datetime maxTime,
const int yr, const int mo, const int dy)
{
datetime t = (datetime)curTimeArr[0];
if(t < minTime) return false;
if(t > maxTime) return false;
if(!((mo > 1 && mo < 12) || (mo == 1 && dy >= 7) || (mo == 12 && dy < 20)))
return false;
if(t >= 1232064000 && t <= 1232150400) return false; // 2009-01-16
if(t >= 1386288000 && t <= 1386374400) return false; // 2013-12-06
if(t >= 1216684800 && t <= 1216771200) return false; // 2008-07-22
if(g_pairId == 1 && yr >= 2003) return true;
if(g_pairId == 2 && yr >= 2003) return true;
if(g_pairId == 3 && yr >= 2002) return true;
if(g_pairId == 4 && yr >= 2004) return true;
if(g_pairId == 4 && yr == 2003 && mo >= 3) return true;
return false;
}
bool DllOpenBuyStop(int &maxBuyLvl[], int &buyStopTkt[], const double buyEntryRef, const double askVal,
const int stepCheckShift, double &totalBuyLots[], double &buyStopTgtLots[],
double &lastBuyOpen[], const int curTPPips)
{
if(maxBuyLvl[0] <= 1) return false;
bool condA = (buyStopTkt[0] == 0 && ((double)stepCheckShift * _Point + buyEntryRef <= askVal));
bool condB = (buyStopTgtLots[0] > totalBuyLots[0] && (lastBuyOpen[0] - (double)curTPPips * _Point <= buyEntryRef));
return (condA || condB);
}
bool DllOpenSellStop(int &maxSellLvl[], int &sellStopTkt[], const double sellEntryRef, const double bidVal,
const int stepCheckShift, double &totalSellLots[], double &sellStopTgtLots[],
double &lastSellOpen[], const int curTPPips)
{
if(maxSellLvl[0] <= 1) return false;
bool condA = (sellStopTkt[0] == 0 && (sellEntryRef - (double)stepCheckShift * _Point >= bidVal));
bool condB = (sellStopTgtLots[0] > totalSellLots[0] && ((double)curTPPips * _Point + lastSellOpen[0] >= sellEntryRef));
return (condA || condB);
}
double DllGetLotBuy(const int lotDigits, double &sumBuyPriceLots[], const double entry,
const int curTP, const int curStep, double &sumBuyLots[], const double buyStopEntry,
double &lastBuyOpen[], const int stepOrderShift, const double buyStopTP,
double &lastBuyTP[], const double startLot)
{
double scaleUp = MathPow(10.0, (double)lotDigits);
double scaleDown = MathPow(0.1, (double)lotDigits);
double extra = MathCeil(scaleUp * (sumBuyPriceLots[0] - ((double)(curStep + curTP) * _Point + entry) * sumBuyLots[0]) / ((double)curStep * _Point)) * scaleDown;
if(extra <= 0.0) extra = 0.0;
if(lastBuyOpen[0] - (double)stepOrderShift * _Point <= buyStopEntry && lastBuyTP[0] == buyStopTP)
return (scaleDown + extra);
return (scaleDown + extra + startLot);
}
double DllGetLotSell(const int lotDigits, double &sumSellPriceLots[], const double entry,
const int curTP, const int curStep, double &sumSellLots[], const double sellStopEntry,
double &lastSellOpen[], const int stepOrderShift, const double sellStopTP,
double &lastSellTP[], const double startLot)
{
double scaleUp = MathPow(10.0, (double)lotDigits);
double scaleDown = MathPow(0.1, (double)lotDigits);
double extra = MathCeil(scaleUp * (sumSellPriceLots[0] - (entry - (double)(curStep + curTP) * _Point) * sumSellLots[0]) / ((double)(-curStep) * _Point)) * scaleDown;
if(extra <= 0.0) extra = 0.0;
if((double)stepOrderShift * _Point + lastSellOpen[0] >= sellStopEntry && lastSellTP[0] == sellStopTP)
return (scaleDown + extra);
return (scaleDown + extra + startLot);
}
double DllGetLoss(const int side, double &sumPriceLots[], const double nextEntry, const double nextLots,
double &sumLots[], double &capReq[], const double tickVal)
{
if(tickVal <= 0.0 || (sumLots[0] + nextLots) <= 0.0) return 0.0;
double avg = (nextEntry * nextLots + sumPriceLots[0]) / (sumLots[0] + nextLots);
double distPrice = capReq[0] / tickVal / (sumLots[0] + nextLots) * _Point;
if(side == 1)
return (MathCeil((avg - distPrice) / _Point) * _Point);
if(side == 2)
return (MathCeil((avg + distPrice) / _Point) * _Point);
return 0.0;
}
int DllGetPermission(const int maxOrdersFlag, const int freeMarginFlag,
const int c1, const int c2, const int c3, const int c4, const int c5, const int c6,
const int bSig, const int sSig, const double ddPct, const double maxDD,
const int maxTradesLim, const int curTrades, const int extraErr)
{
int perm = 0;
if(freeMarginFlag > 0 && maxOrdersFlag == 0 && (c1 != 0 || c2 != 0 || c3 != 0 || c4 != 0 || c5 != 0 || c6 != 0))
perm = 1;
if(bSig == 0 && sSig == 0 && maxOrdersFlag == 0)
perm = 4;
if(ddPct > 0.0 && ddPct <= maxDD)
return 3;
if(maxTradesLim > 0)
{
if(curTrades > maxTradesLim) return 3;
if(curTrades == maxTradesLim) perm = 2;
}
return perm;
}
int GMTOffset()
{
datetime srv = TimeCurrent();
datetime gmt = TimeGMT();
if(gmt <= 0) return 0;
return (int)MathRound((double)(srv - gmt) / 3600.0);
}
void DigSwitch()
{
if((_Digits == 5 || _Digits == 3) && !g_digSwitched)
{
g_digSwitched = true;
g_maTrendDist *= 10;
g_slPips *= 10;
g_stepCheckMult *= 10;
g_stepCheckMode *= 10;
g_slippage *= 10;
g_gridSpan *= 10;
g_baseStep *= 10;
g_baseTP *= 10;
g_buyStopGap *= 10;
g_buyStopOffset *= 10;
g_sellStopGap *= 10;
for(int i = 0; i < 5; i++)
g_tpTierPips[i] *= 10;
if(g_stepDiv == 0)
{
for(int i = 0; i < 6; i++)
g_gridSteps[i] = g_baseStep;
}
else
{
g_stepDivStep = g_baseStep / g_stepDiv;
for(int i = 0; i < 6; i++)
g_gridSteps[i] *= 10;
}
for(int i = 0; i < 6; i++)
g_gridTP[i] *= 10;
g_tpDivTier = 4681;
}
}
void SetParameters()
{
if(g_curDDPips <= g_tpTierPips[0])
{
g_curStep = g_gridSteps[0];
g_curTP = g_gridTP[0];
g_curLotScale = g_stepLotScale[0];
}
else if(g_curDDPips > g_tpTierPips[0] && g_curDDPips <= g_tpTierPips[1])
{
g_curStep = g_gridSteps[1];
g_curTP = g_gridTP[1];
g_curLotScale = g_stepLotScale[1];
}
else if(g_curDDPips > g_tpTierPips[1] && g_curDDPips <= g_tpTierPips[2])
{
g_curStep = g_gridSteps[2];
g_curTP = g_gridTP[2];
g_curLotScale = g_stepLotScale[2];
}
else if(g_curDDPips > g_tpTierPips[2] && g_curDDPips <= g_tpTierPips[3])
{
g_curStep = g_gridSteps[3];
g_curTP = g_gridTP[3];
g_curLotScale = g_stepLotScale[3];
}
else if(g_curDDPips > g_tpTierPips[3] && g_curDDPips <= g_tpTierPips[4])
{
g_curStep = g_gridSteps[4];
g_curTP = g_gridTP[4];
g_curLotScale = g_stepLotScale[4];
}
else if(g_curDDPips > g_tpTierPips[4])
{
g_curStep = g_gridSteps[5];
g_curTP = g_gridTP[5];
g_curLotScale = g_stepLotScale[5];
}
}
void ReadRSI()
{
double r1 = iRSI(_Symbol, g_rsiTF, g_rsiPeriod, PRICE_CLOSE, 1);
double r2 = iRSI(_Symbol, g_rsiTF, g_rsiPeriod, PRICE_CLOSE, 2);
if(g_maxBarsNeeded < g_rsiTF)
g_maxBarsNeeded = g_rsiTF;
if(g_rsiNewBarOnly)
{
if(r1 < g_rsiLower && r2 >= g_rsiLower) { g_rsiBuy = true; g_rsiSell = false; }
if(r1 > g_rsiUpper && r2 <= g_rsiUpper) { g_rsiBuy = false; g_rsiSell = true; }
}
else
{
if(r1 < g_rsiLower) { g_rsiBuy = true; g_rsiSell = false; }
if(r1 > g_rsiUpper) { g_rsiBuy = false; g_rsiSell = true; }
}
if(g_rsiReverse)
{
if(g_rsiBuy && !g_rsiSell) { g_rsiBuy = false; g_rsiSell = true; }
else if(g_rsiSell && !g_rsiBuy) { g_rsiBuy = true; g_rsiSell = false; }
else { g_rsiBuy = true; g_rsiSell = true; }
}
}
void ReadMACD()
{
double m1 = iMACD(_Symbol, g_macdTF, g_macdFast, g_macdSlow, g_macdSignal, PRICE_CLOSE, MODE_MAIN, 1);
double m2 = iMACD(_Symbol, g_macdTF, g_macdFast, g_macdSlow, g_macdSignal, PRICE_CLOSE, MODE_MAIN, 2);
double s1 = iMACD(_Symbol, g_macdTF, g_macdFast, g_macdSlow, g_macdSignal, PRICE_CLOSE, MODE_SIGNAL, 1);
double s2 = iMACD(_Symbol, g_macdTF, g_macdFast, g_macdSlow, g_macdSignal, PRICE_CLOSE, MODE_SIGNAL, 2);
if(g_maxBarsNeeded < g_macdTF)
g_maxBarsNeeded = g_macdTF;
if(g_macdCrossMode)
{
if(g_macdNewBarOnly)
{
if(m1 > s1 && m2 <= s2) { g_macdBuy = true; g_macdSell = false; }
if(m1 < s1 && m2 >= s2) { g_macdBuy = false; g_macdSell = true; }
}
else
{
if(m1 > s1) { g_macdBuy = true; g_macdSell = false; }
if(m1 < s1) { g_macdBuy = false; g_macdSell = true; }
}
}
else
{
if(g_macdNewBarOnly)
{
if(m1 > 0.0 && m2 <= 0.0) { g_macdBuy = true; g_macdSell = false; }
if(m1 < 0.0 && m2 >= 0.0) { g_macdBuy = false; g_macdSell = true; }
}
else
{
if(m1 > 0.0) { g_macdBuy = true; g_macdSell = false; }
if(m1 < 0.0) { g_macdBuy = false; g_macdSell = true; }
}
}
if(g_macdReverse)
{
if(g_macdBuy && !g_macdSell) { g_macdBuy = false; g_macdSell = true; }
else if(g_macdSell && !g_macdBuy) { g_macdBuy = true; g_macdSell = false; }
else { g_macdBuy = true; g_macdSell = true; }
}
}
void ReadSAR()
{
double sar1 = iSAR(_Symbol, g_sarTF, g_sarStep, g_sarMax, 1);
double sar2 = iSAR(_Symbol, g_sarTF, g_sarStep, g_sarMax, 2);
double hi1 = iHigh(_Symbol, g_sarTF, 1);
double lo1 = iLow(_Symbol, g_sarTF, 1);
double hi2 = iHigh(_Symbol, g_sarTF, 2);
double lo2 = iLow(_Symbol, g_sarTF, 2);
if(g_maxBarsNeeded < g_sarTF)
g_maxBarsNeeded = g_sarTF;
if(g_sarNewBarOnly)
{
if(sar1 < Bid && sar2 >= hi2) { g_sarBuy = true; g_sarSell = false; }
if(sar1 > Bid && sar2 <= lo2) { g_sarBuy = false; g_sarSell = true; }
}
else
{
if(sar1 < lo1) { g_sarBuy = true; g_sarSell = false; }
if(sar1 > hi1) { g_sarBuy = false; g_sarSell = true; }
}
if(g_sarReverse)
{
if(g_sarBuy && !g_sarSell) { g_sarBuy = false; g_sarSell = true; }
else if(g_sarSell && !g_sarBuy) { g_sarBuy = true; g_sarSell = false; }
else { g_sarBuy = true; g_sarSell = true; }
}
}
void ReadMA()
{
double m1 = iMA(_Symbol, g_maFilterTF, g_maFilterPeriod, g_maFilterShift, g_maFilterMethod, PRICE_CLOSE, 1);
double m2 = iMA(_Symbol, g_maFilterTF, g_maFilterPeriod, g_maFilterShift, g_maFilterMethod, PRICE_CLOSE, 2);
double c1 = iClose(_Symbol, g_maFilterTF, 1);
double c2 = iClose(_Symbol, g_maFilterTF, 2);
if(g_maxBarsNeeded < g_maFilterTF)
g_maxBarsNeeded = g_maFilterTF;
if(g_maFilterNewBar)
{
if(m1 < c1 && m2 >= c2) { g_maBuy = true; g_maSell = false; }
if(m1 > c1 && m2 <= c2) { g_maBuy = false; g_maSell = true; }
}
else
{
if(m1 < c1) { g_maBuy = true; g_maSell = false; }
if(m1 > c1) { g_maBuy = false; g_maSell = true; }
}
if(g_maFilterReverse)
{
if(g_maBuy && !g_maSell) { g_maBuy = false; g_maSell = true; }
else if(g_maSell && !g_maBuy) { g_maBuy = true; g_maSell = false; }
else { g_maBuy = true; g_maSell = true; }
}
}
void ReadMFI()
{
double f1 = iMFI(_Symbol, g_mfiTF, g_mfiPeriod, 1);
double f2 = iMFI(_Symbol, g_mfiTF, g_mfiPeriod, 2);
if(g_maxBarsNeeded < g_mfiTF)
g_maxBarsNeeded = g_mfiTF;
if(g_mfiNewBarOnly)
{
if(f1 < g_mfiLower && f2 >= g_mfiLower) { g_mfiBuy = true; g_mfiSell = false; }
if(f1 > g_mfiUpper && f2 <= g_mfiUpper) { g_mfiBuy = false; g_mfiSell = true; }
}
else
{
if(f1 < g_mfiLower) { g_mfiBuy = true; g_mfiSell = false; }
if(f1 > g_mfiUpper) { g_mfiBuy = false; g_mfiSell = true; }
}
if(g_mfiReverse)
{
if(g_mfiBuy && !g_mfiSell) { g_mfiBuy = false; g_mfiSell = true; }
else if(g_mfiSell && !g_mfiBuy) { g_mfiBuy = true; g_mfiSell = false; }
else { g_mfiBuy = true; g_mfiSell = true; }
}
}
void ReadAO()
{
double a1 = iAO(_Symbol, g_aoTF, 1);
double a2 = iAO(_Symbol, g_aoTF, 2);
if(g_maxBarsNeeded < g_aoTF)
g_maxBarsNeeded = g_aoTF;
if(g_aoNewBarOnly)
{
if(a1 > 0.0 && a2 <= 0.0) { g_aoBuy = true; g_aoSell = false; }
if(a1 < 0.0 && a2 >= 0.0) { g_aoBuy = false; g_aoSell = true; }
}
else
{
if(a1 > a2) { g_aoBuy = true; g_aoSell = false; }
if(a2 > a1) { g_aoBuy = false; g_aoSell = true; }
}
if(g_aoReverse)
{
if(g_aoBuy && !g_aoSell) { g_aoBuy = false; g_aoSell = true; }
else if(g_aoSell && !g_aoBuy) { g_aoBuy = true; g_aoSell = false; }
else { g_aoBuy = true; g_aoSell = true; }
}
}
void ReadBB()
{
double u1 = iBands(_Symbol, g_bbTF, g_bbPeriod, g_bbDev, 0, PRICE_CLOSE, MODE_UPPER, 1);
double l1 = iBands(_Symbol, g_bbTF, g_bbPeriod, g_bbDev, 0, PRICE_CLOSE, MODE_LOWER, 1);
double c1 = iClose(_Symbol, g_bbTF, 1);
double u2 = iBands(_Symbol, g_bbTF, g_bbPeriod, g_bbDev, 0, PRICE_CLOSE, MODE_UPPER, 2);
double l2 = iBands(_Symbol, g_bbTF, g_bbPeriod, g_bbDev, 0, PRICE_CLOSE, MODE_LOWER, 2);
double c2 = iClose(_Symbol, g_bbTF, 2);
if(g_maxBarsNeeded < g_bbTF)
g_maxBarsNeeded = g_bbTF;
if(g_bbNewBarOnly)
{
if(c1 < l1 && c2 >= l2) { g_bbBuy = true; g_bbSell = false; }
if(c1 > u1 && c2 <= u2) { g_bbBuy = false; g_bbSell = true; }
}
else
{
if(c1 < l1) { g_bbBuy = true; g_bbSell = false; }
if(c1 > u1) { g_bbBuy = false; g_bbSell = true; }
}
if(g_bbReverse)
{
if(g_bbBuy && !g_bbSell) { g_bbBuy = false; g_bbSell = true; }
else if(g_bbSell && !g_bbBuy) { g_bbBuy = true; g_bbSell = false; }
else { g_bbBuy = true; g_bbSell = true; }
}
}
void Comments()
{
string dots = "";
if(g_commentTick == 0) dots = ".";
if(g_commentTick == 1) dots = "..";
if(g_commentTick == 2) dots = "...";
if(g_commentTick == 3) dots = "....";
if(g_commentTick == 4) dots = ".....";
if(g_commentTick == 5) dots = "......";
if(g_commentTick == 6) dots = ".......";
if(g_commentTick == 7) dots = "........";
if(g_commentTick == 8) dots = ".........";
if(g_commentTick == 9) dots = "inControl";
if(g_commentTick == 11) dots = "inControl.";
if(g_commentTick == 12) dots = "inControl..";
if(g_commentTick == 13) dots = "inControl...";
g_commentTick++;
if(g_commentTick == 10) g_commentTick++;
if(g_commentTick > 14) g_commentTick = 0;
if(g_warnExpired != "")
Comment(g_warnExpired);
else if(g_warnHoliday != "")
Comment(g_warnHoliday);
else if(g_warnFreeMarginB != "")
Comment(g_warnFreeMarginB);
else if(g_warnFreeMarginS != "")
Comment(g_warnFreeMarginS);
else if(g_warnTradeStop != "")
Comment(g_warnTradeStop);
else if(g_warnStopDate != "")
Comment(g_warnStopDate);
else if(g_warnWaitInit != "")
Comment(g_warnWaitInit);
else if(g_warnMaxDD != "")
Comment(g_warnMaxDD);
else if(g_warnLowDeposit != "")
Comment(g_warnLowDeposit);
else if(g_warnTPZero != "")
Comment(g_warnTPZero);
else if(g_warnGeneric != "")
Comment(g_warnGeneric);
else if(g_outCapitalReq[0] > 0.0)
Comment("\nDeposit for trading is = ", g_outCapitalReq[0],
"\nStart Lot = ", g_workLot,
"\n", dots);
else
Comment("Wait for a tick...");
g_chartHandle = WindowHandle(_Symbol, 30);
}
void ConfigurePair()
{
string sym6 = StringSubstr(_Symbol, 0, 6);
if(sym6 == "USDJPY")
{
g_pairId = 1;
g_anchorUSD = 6800.0;
g_useSignalFilter = false;
g_magic = 481541;
g_maBarsScanned = 0;
g_maTF = 30;
g_maPeriod = 8;
g_maShift = 0;
g_maTrendDist = 50;
g_maOppDist = 1;
g_hedgeReset = 1;
g_gridSpan = 300;
g_stepDiv = 13;
g_baseStep = 55;
g_baseTP = 60;
g_buyStopGap = 50;
g_buyStopOffset = 50;
g_sellStopGap = 50;
int tier = 300 / 5;
for(int i = 0; i < 5; i++) g_tpTierPips[i] = tier * (i + 1);
int sdiv = 55 / 13;
g_stepDivStep = sdiv;
g_gridSteps[0] = 55;
g_gridSteps[1] = sdiv + 55;
g_gridSteps[2] = sdiv * 2 + 55;
g_gridSteps[3] = sdiv * 3 + 55;
g_gridSteps[4] = sdiv * 4 + 55;
g_gridSteps[5] = sdiv * 5 + 55 - 1;
for(int i = 0; i < 6; i++) g_gridTP[i] = 60;
}
else if(sym6 == "AUDUSD")
{
g_pairId = 2;
g_anchorUSD = 3100.0;
g_useSignalFilter = true;
g_rsiEnabled = true;
g_rsiNewBarOnly = false;
g_rsiReverse = false;
g_rsiTF = 30;
g_rsiPeriod = 12;
g_rsiUpper = 70.0;
g_rsiLower = 30.0;
g_maFilterEn = true;
g_maFilterNewBar = false;
g_maFilterReverse = false;
g_maFilterTF = 30;
g_maFilterPeriod = 14;
g_maFilterShift = 0;
g_maFilterDist = 46;
g_maFilterMethod = 0;
g_magic = 481542;
g_gridSpan = 500;
g_stepDiv = 12;
g_baseStep = 50;
g_baseTP = 34;
g_buyStopGap = 65;
g_buyStopOffset = 60;
g_sellStopGap = 65;
int tier = 500 / 5;
for(int i = 0; i < 5; i++) g_tpTierPips[i] = tier * (i + 1);
int sdiv = 50 / 12;
g_stepDivStep = sdiv;
g_gridSteps[0] = 50;
g_gridSteps[1] = 50 + 15;
g_gridSteps[2] = 50 + 13;
g_gridSteps[3] = sdiv * 3 + 50 - 3;
g_gridSteps[4] = sdiv * 4 + 50;
g_gridSteps[5] = sdiv * 5 + 50;
for(int i = 0; i < 6; i++) g_gridTP[i] = 34;
}
else if(sym6 == "EURGBP")
{
g_pairId = 3;
g_anchorUSD = 2600.0;
g_useSignalFilter = false;
g_magic = 481543;
g_maBarsScanned = 0;
g_maTF = 30;
g_maPeriod = 12;
g_maShift = 0;
g_maTrendDist = 50;
g_maOppDist = 1;
g_hedgeReset = 1;
g_gridSpan = 600;
g_stepDiv = 0;
g_baseStep = 34;
g_baseTP = 54;
g_buyStopGap = 30;
g_buyStopOffset = 30;
g_sellStopGap = 30;
int tier = 600 / 5;
for(int i = 0; i < 5; i++) g_tpTierPips[i] = tier * (i + 1);
for(int i = 0; i < 6; i++) g_gridSteps[i] = 34;
for(int i = 0; i < 6; i++) g_gridTP[i] = 54;
}
else if(sym6 == "GBPJPY")
{
g_pairId = 4;
g_anchorUSD = 3300.0;
g_useSignalFilter = false;
g_magic = 481544;
g_maBarsScanned = 0;
g_maTF = 30;
g_maPeriod = 14;
g_maShift = 0;
g_maTrendDist = 80;
g_maOppDist = 1;
g_hedgeReset = 1;
g_gridSpan = 300;
g_stepDiv = 6;
g_baseStep = 32;
g_baseTP = 30;
g_buyStopGap = 17;
g_buyStopOffset = 20;
g_sellStopGap = 15;
int tier = 300 / 5;
for(int i = 0; i < 5; i++) g_tpTierPips[i] = tier * (i + 1);
int sdiv = 32 / 6;
g_stepDivStep = sdiv;
g_gridSteps[0] = 36;
g_gridSteps[1] = 32 + 10;
g_gridSteps[2] = 32 + 25;
g_gridSteps[3] = sdiv * 3 + 32 - 1;
g_gridSteps[4] = sdiv * 4 + 32;
g_gridSteps[5] = sdiv * 5 + 32;
g_gridTP[0] = 32;
g_gridTP[1] = 24;
g_gridTP[2] = 19;
g_gridTP[3] = 30;
g_gridTP[4] = 30;
g_gridTP[5] = 30;
}
else
{
g_pairId = 0;
}
g_anchorConv = g_anchorUSD;
}
void UpdateCapitalAnchor()
{
string sfx = StringSubstr(_Symbol, 6, 7);
string cur = AccountCurrency();
g_usdRate = 1.0;
if(cur == "EUR")
{
double rate = MarketInfo("EURUSD" + sfx, MODE_BID);
if(rate > 0.0) { g_usdRate = rate; g_anchorConv = g_anchorUSD / g_usdRate; }
}
else if(cur == "JPY")
{
double rate = MarketInfo("USDJPY" + sfx, MODE_BID);
if(rate > 0.0) { g_usdRate = rate; g_anchorConv = g_anchorUSD * g_usdRate; }
}
else if(cur == "GBP")
{
double rate = MarketInfo("GBPUSD" + sfx, MODE_BID);
if(rate > 0.0) { g_usdRate = rate; g_anchorConv = g_anchorUSD / g_usdRate; }
}
else if(cur == "CHF")
{
double rate = MarketInfo("USDCHF" + sfx, MODE_BID);
if(rate > 0.0) { g_usdRate = rate; g_anchorConv = g_anchorUSD * g_usdRate; }
}
elsПоказано первые 50% кода (символов: 47878)