Исходный код · ID 2661
newstrader.mq4
Похожие материалы по тегам
ea robofibo source v.11.2.mq4MetaTrader 4 · 1 общих теговsma crossover scalper ea for mt4.mq4MetaTrader 4 · 1 общих теговr15 pivot points expert advisor by @fundedmillionairess.mq4MetaTrader 4 · 1 общих теговnewstrader.mq5MetaTrader 5 · 1 общих теговmm3.0_flip_codepro_v3.1_with_cooldown@lifeindreamsworld.mq5MetaTrader 5 · 1 общих теговmm3.0_flip_codepro_v3.1_with_cooldown.mq5MetaTrader 5 · 1 общих тегов
Вы автор или правообладатель?
Сообщите нам, если считаете, что материал размещён без разрешения.
Сообщить о материале
Обращение по товару «newstrader.mq4» отправится на рассмотрение. Укажите контакт для ответа и опишите причину.
Поиск по коду файла
#property version "1.10"
#property strict
#property description "Opens a buy/sell trade (random, chosen direction, or both directions) seconds before news release."
#property description "Sets SL and TP. Keeps updating them until the very release."
#property description "Can set SL to breakeven when unrealized profit = SL."
#property description "Alternatively, adds ATR based trailing stop."
#property description "Closes trade after one hour."
enum dir_enum
{
Buy,
Sell,
Both,
Random
};
enum trailing_enum
{
Breakeven,
Full,
None
};
input group "Trading"
input datetime NewsTime = __DATE__; // News date/time.
input int StopLoss = 15; // Stop-loss in broker's pips.
input int TakeProfit = 75; // Take-profit in broker's pips.
input dir_enum Direction = Both; // Direction of the trade to open.
input trailing_enum TrailingStop = None; // Trailing stop type.
input bool PreAdjustSLTP = false; // Preadjust SL/TP until news is out.
input int SecondsBefore = 18; // Seconds before the news to open a trade.
input int CloseAfterSeconds = 3600; // Close trade X seconds after the news, 0 - turn the feature off.
input bool SpreadFuse = true; // SpreadFuse - prevent trading if spread >= stop-loss.
input group "ATR"
input bool UseATR = false; // Use ATR-based stop-loss and take-profit levels.
input int ATR_Period = 14; // ATR Period.
input double ATR_Multiplier_SL = 1; // ATR multiplier for SL.
input double ATR_Multiplier_TP = 5; // ATR multiplier for TP.
input group "Money management"
input double Lots = 0.01;
input bool MM = true; // Money Management, if true - position sizing based on stop-loss.
input double Risk = 1; // Risk - Risk tolerance in percentage points.
input double FixedBalance = 0; // FixedBalance: If > 0, trade size calc. uses it as balance.
input double MoneyRisk = 0; // MoneyRisk: Risk tolerance in account currency.
input bool UseMoneyInsteadOfPercentage = false; // Use money risk instead of percentage.
input bool UseEquityInsteadOfBalance = false; // Use equity instead of balance.
input group "Timer"
input bool ShowTimer = true; // Show timer before and after news.
input int FontSize = 18;
input string Font = "Arial";
input color FontColor = clrRed;
input ENUM_BASE_CORNER Corner = CORNER_LEFT_UPPER;
input int X_Distance = 10; // X-axis distance from the chart corner.
input int Y_Distance = 130; // Y-axis distance from the chart corner.
input group "Miscellaneous"
input int Slippage = 3;
input int Magic = 794823491;
input string Commentary = "NewsTrader"; // Comment - trade description (e.g. "US CPI", "EU GDP", etc.).
bool HaveLongPosition, HaveShortPosition;
bool ECN_Mode;
int news_time;
bool CanTrade = false;
bool Terminal_Trade_Allowed = true;
double SL, TP;
string ProfitCurrency = "", account_currency = "", BaseCurrency = "", ReferenceSymbol = NULL, AdditionalReferenceSymbol = NULL;
bool ReferenceSymbolMode, AdditionalReferenceSymbolMode;
int ProfitCalcMode;
void OnInit()
{
// код доступен только после оплаты
}
void OnDeinit(const int reason)
{
ObjectDelete(ChartID(), "NewsTraderTimer");
}
void OnTimer()
{
DoTrading();
string text;
int difference = (int)TimeCurrent() - news_time;
if (difference <= 0) text = "Time to news: " + TimeDistance(-difference);
else text = "Time after news: " + TimeDistance(difference) + ".";
ObjectSetString(ChartID(), "NewsTraderTimer", OBJPROP_TEXT, text);
ObjectSetString(ChartID(), "NewsTraderTimer", OBJPROP_FONT, Font);
ObjectSetInteger(ChartID(), "NewsTraderTimer", OBJPROP_FONTSIZE, FontSize);
ObjectSetInteger(ChartID(), "NewsTraderTimer", OBJPROP_COLOR, FontColor);
}
string TimeDistance(int t)
{
if (t == 0) return "0 seconds";
string s = "";
int y = 0;
int d = 0;
int h = 0;
int m = 0;
y = t / 31536000;
t -= y * 31536000;
d = t / 86400;
t -= d * 86400;
h = t / 3600;
t -= h * 3600;
m = t / 60;
t -= m * 60;
if (y) s += IntegerToString(y) + " year";
if (y > 1) s += "s";
if (d) s += " " + IntegerToString(d) + " day";
if (d > 1) s += "s";
if (h) s += " " + IntegerToString(h) + " hour";
if (h > 1) s += "s";
if (m) s += " " + IntegerToString(m) + " minute";
if (m > 1) s += "s";
if (t) s += " " + IntegerToString(t) + " second";
if (t > 1) s += "s";
return StringTrimLeft(s);
}
void OnTick()
{
// код доступен только после оплаты
}
void DoTrading()
{
if ((TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) == false) || (!CanTrade))
{
if ((TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) == false) && (Terminal_Trade_Allowed == true))
{
Print("Trading not allowed.");
Terminal_Trade_Allowed = false;
}
else if ((TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) == true) && (Terminal_Trade_Allowed == false))
{
Print("Trading allowed.");
Terminal_Trade_Allowed = true;
}
return;
}
ENUM_SYMBOL_TRADE_EXECUTION Execution_Mode = (ENUM_SYMBOL_TRADE_EXECUTION)SymbolInfoInteger(Symbol(), SYMBOL_TRADE_EXEMODE);
if (Execution_Mode == SYMBOL_TRADE_EXECUTION_MARKET) ECN_Mode = true;
else ECN_Mode = false;
int time = (int)TimeCurrent();
if (time < news_time - SecondsBefore) return;
if (UseATR)
{
double ATR = iATR(NULL, 0, ATR_Period, 0);
SL = ATR * ATR_Multiplier_SL;
if (SL <= (SymbolInfoInteger(Symbol(), SYMBOL_TRADE_STOPS_LEVEL) + SymbolInfoInteger(Symbol(), SYMBOL_SPREAD)) * Point) SL = (SymbolInfoInteger(Symbol(), SYMBOL_TRADE_STOPS_LEVEL) + SymbolInfoInteger(Symbol(), SYMBOL_SPREAD)) * Point;
TP = ATR * ATR_Multiplier_TP;
if (TP <= (SymbolInfoInteger(Symbol(), SYMBOL_TRADE_STOPS_LEVEL) + SymbolInfoInteger(Symbol(), SYMBOL_SPREAD)) * Point) TP = (SymbolInfoInteger(Symbol(), SYMBOL_TRADE_STOPS_LEVEL) + SymbolInfoInteger(Symbol(), SYMBOL_SPREAD)) * Point;
SL /= Point;
TP /= Point;
}
GetPositionStates();
if ((HaveLongPosition) || (HaveShortPosition)) ControlPosition();
else
{
if ((news_time - time <= SecondsBefore) && (news_time > time))
{
int spread = (int)MarketInfo(Symbol(), MODE_SPREAD);
if ((SpreadFuse) && (spread >= StopLoss))
{
Print(Symbol(), ": Spread fuse prevents positions from opening. Current spread: ", spread, " points.");
return;
}
if (Direction == Buy) fBuy();
else if (Direction == Sell) fSell();
else if (Direction == Both)
{
fBuy();
fSell();
}
else if (Direction == Random)
{
MathSrand((uint)TimeCurrent());
if (MathRand() % 2 == 1) fBuy();
else fSell();
}
if (ECN_Mode) ControlPosition();
}
}
}
void GetPositionStates()
{
HaveLongPosition = false;
HaveShortPosition = false;
int total = OrdersTotal();
for (int cnt = 0; cnt < total; cnt++)
{
if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) == false) continue;
if (OrderMagicNumber() != Magic) continue;
if (OrderSymbol() != Symbol()) continue;
if (OrderType() == OP_BUY) HaveLongPosition = true;
else if (OrderType() == OP_SELL) HaveShortPosition = true;
}
}
void ControlPosition()
{
int total = OrdersTotal();
for (int cnt = total - 1; cnt >= 0; cnt--)
{
if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) == false) continue;
if (OrderMagicNumber() != Magic) continue;
if (OrderSymbol() != Symbol()) continue;
if ((OrderType() == OP_BUY) || (OrderType() == OP_SELL))
{
int time = (int)TimeCurrent();
double new_sl, new_tp;
if (SL < MarketInfo(Symbol(), MODE_STOPLEVEL) + MarketInfo(Symbol(), MODE_SPREAD)) SL = MarketInfo(Symbol(), MODE_STOPLEVEL) + MarketInfo(Symbol(), MODE_SPREAD);
if (TP < MarketInfo(Symbol(), MODE_STOPLEVEL) + MarketInfo(Symbol(), MODE_SPREAD)) TP = MarketInfo(Symbol(), MODE_STOPLEVEL) + MarketInfo(Symbol(), MODE_SPREAD);
if (OrderType() == OP_BUY)
{
RefreshRates();
new_sl = NormalizeDouble(Ask - SL * Point, Digits);
new_tp = NormalizeDouble(Ask + TP * Point, Digits);
}
else if (OrderType() == OP_SELL)
{
RefreshRates();
new_sl = NormalizeDouble(Bid + SL * Point, Digits);
new_tp = NormalizeDouble(Bid - TP * Point, Digits);
}
if (time < news_time)
{
if ((((new_sl != NormalizeDouble(OrderStopLoss(), Digits)) || (new_tp != NormalizeDouble(OrderTakeProfit(), Digits))) && (PreAdjustSLTP)) ||
(((OrderStopLoss() == 0) || (OrderTakeProfit() == 0)) && (ECN_Mode)))
{
Print("Adjusting SL: ", new_sl, " and TP: ", new_tp, ".");
for (int i = 0; i < 10; i++)
{
bool result = OrderModify(OrderTicket(), OrderOpenPrice(), new_sl, new_tp, 0);
if (result) return;
else Print("Error modifying the order: ", GetLastError());
}
}
}
else
{
RefreshRates();
if (((OrderStopLoss() == 0) || (OrderTakeProfit() == 0)) && (ECN_Mode))
{
Print("Adjusting SL: ", new_sl, " and TP: ", new_tp, ".");
for (int i = 0; i < 10; i++)
{
bool result = OrderModify(OrderTicket(), OrderOpenPrice(), new_sl, new_tp, 0);
if (result) return;
else Print("Error modifying the order: ", GetLastError());
}
}
if ((TrailingStop == Breakeven) && ((((OrderType() == OP_BUY) && (Ask - OrderOpenPrice() >= SL * Point)) || ((OrderType() == OP_SELL) && (OrderOpenPrice() - Bid >= SL * Point)))))
{
new_sl = NormalizeDouble(OrderOpenPrice(), Digits);
if (new_sl != NormalizeDouble(OrderStopLoss(), Digits))
{
Print("Moving SL to breakeven: ", new_sl, ".");
for (int i = 0; i < 10; i++)
{
bool result = OrderModify(OrderTicket(), OrderOpenPrice(), new_sl, OrderTakeProfit(), 0);
if (result) break;
}
}
}
else if ((TrailingStop == Full) && ((((OrderType() == OP_BUY) && (Ask - OrderStopLoss() >= SL * Point)) || ((OrderType() == OP_SELL) && (OrderStopLoss() - Bid >= SL * Point)))))
{
if (OrderType() == OP_BUY) new_sl = NormalizeDouble(Ask - SL * Point, Digits);
else if (OrderType() == OP_SELL) new_sl = NormalizeDouble(Bid + SL * Point, Digits);
if (((OrderType() == OP_BUПоказано первые 50% кода (символов: 17472)
Что вы получите после оплаты
На этой странице откроется полный исходный код файла вместо ознакомительного фрагмента.
Зачем нужен email? Адрес передаётся вместе с заказом в магазин и сохраняется для связи заказа с оплатой. Укажите адрес, к которому у вас есть доступ.
Чтобы оформить заказ, введите email и перейдите к оплате.
Стоимость полного кода
1 747₽
≈ $20.54