Да ладно. Это серьёзно ссылка на файл?
То есть, что бы тебе сделали алерт в индикаторе, кто то должен зарегистрироваться где то.
Это не правильно.
double spead = SymbolInfoInteger(_Symbol, SYMBOL_SPREAD) * _Point;
if(spead > max_Spread)
return;
<code>//+------------------------------------------------------------------+ //| Break_out_trend_EA.mq5 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2018, MetaQuotes Software Corp." #property link "https://www.mql5.com/ru/users/s22aa" #property version "1.0" #property description "Открывает сделки при пробое трендовой линии" #property description "рисуются четыре трендовые каждой присваиваем имя" #define _ask SymbolInfoDouble(_Symbol, SYMBOL_ASK) #define _bid SymbolInfoDouble(_Symbol, SYMBOL_BID) #define _time SymbolInfoInteger(_Symbol, SYMBOL_TIME) #include <Trade\Trade.mqh> #include <Trade\symbolInfo.mqh> CTrade atrade; CSymbolInfo asymbol; input string PPB = "PPB"; //имя трендовой позиции Byu input string TPB = "TPB"; //имя трендовой тейкпрофит Byu input string PPS = "PPS"; //имя трендовой позиции Sell input string TPS = "TPS"; //имя трендовой тейкпрофит Sell color color_Byu = clrBlue; //цвет трендовой Byu color color_Sell = clrRed; //цвет трендовой Sell sinput ulong MagicNumber = 12345; ulong Slippage = 30; input double Lots = 1; double price_Sell, price_SL_Sell, price_TP_Sell, price_Buy, price_SL_Buy, price_TP_Buy; //+------------------------------------------------------------------+ int OnInit() { if(!asymbol.Name(Symbol())) return(INIT_FAILED); RefreshRates(); atrade.SetExpertMagicNumber(MagicNumber); if(IsFillingTypeAllowed(SYMBOL_FILLING_FOK)) atrade.SetTypeFilling(ORDER_FILLING_FOK); else if(IsFillingTypeAllowed(SYMBOL_FILLING_IOC)) atrade.SetTypeFilling(ORDER_FILLING_IOC); else atrade.SetTypeFilling(ORDER_FILLING_RETURN); atrade.SetDeviationInPoints(Slippage); Trend_line("PPB",_ask+20*_Point,_time-6000,_time+600,color_Byu); Trend_line("TPB",_ask+40*_Point,_time-6000,_time+600,color_Byu); Trend_line("PPS",_bid-20*_Point,_time-6000,_time+600,color_Sell); Trend_line("TPS",_bid-40*_Point,_time-6000,_time+600,color_Sell); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ void OnDeinit(const int reason) {} //+------------------------------------------------------------------+ void OnTick() { if(!RefreshRates()) return; int x = 0; static int tempBuy = 0, tempSell = 0; static double price = 0; static string Name, Text; static datetime last_time = 0; datetime cur_time = iTime(_Symbol, PERIOD_CURRENT, 0); int Total = ObjectsTotal(0, 0, OBJ_TREND); MqlTick Prise; if(SymbolInfoTick(Symbol(), Prise)) { for(int i = 0; i <= Total; i++) { Name = ObjectName(0, i, 0, OBJ_TREND); //находит имя price = ObjectGetValueByTime(0, Name, cur_time); // цена обьекта во время открытия нового бара if(Name == PPS) price_Sell = price; if(Name == TPS) price_TP_Sell = price; if(Name == PPB) price_Buy = price; if(Name == TPB) price_TP_Buy = price; if(PositionsTotal() == 0 && Prise.bid >= price_Sell) tempSell = 1; if(Prise.bid <= price_Sell && Name == PPS && tempSell != 0 && price_Sell != 0) { OpenSell(price_Buy, price_TP_Sell); tempSell = 0; return; } if(PositionsTotal() == 0 && Prise.ask <= price_Buy) tempBuy = 1; if(Prise.ask >= price_Buy && Name == PPB && tempBuy != 0) { OpenBuy(price_Sell, price_TP_Buy); tempBuy = 0; return; } } } if(PositionsTotal() > 0 && cur_time != last_time) { if(PositionSelect(Symbol())) // выбираем позицию { if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL) { Request(price_Buy, price_TP_Sell); } else { Request(price_Sell, price_TP_Buy); } } last_time = cur_time; } } //+------------------------------------------------------------------+ void Request(double sl, double tp) { ResetLastError(); MqlTradeRequest request; // параметры торгового запроса MqlTradeResult result; // результат торгового запроса ZeroMemory(request); if(PositionSelect(Symbol())) // выбираем позицию { double PositionSL = PositionGetDouble(POSITION_SL); // записываем в переменную уровень стоплосса double PositionTP = PositionGetDouble(POSITION_TP); // записываем в переменную уровень тейкпрофита sl = NormalizeDouble(sl, Digits()); tp = NormalizeDouble(tp, Digits()); if(PositionSL != sl || PositionTP != tp) { request.action = TRADE_ACTION_SLTP; request.position = PositionGetInteger(POSITION_TICKET); request.symbol = Symbol(); request.sl = sl; request.tp = tp; if(!OrderSend(request, result)) Print("error ", GetLastError()); } } } //+------------------------------------------------------------------+ //| Открываем Buy позицию | //+------------------------------------------------------------------+ void OpenBuy(double sl, double tp) { ResetLastError(); sl = NormalizeDouble(sl, Digits()); tp = NormalizeDouble(tp, Digits()); if(atrade.Buy(Lots, asymbol.Name(), asymbol.Ask(), sl, tp)) { if(atrade.ResultDeal() == 0) { Print("error ", GetLastError()); } } else { Print("error ", GetLastError()); } } //+------------------------------------------------------------------+ //| Открываем Sell позицию | //+------------------------------------------------------------------+ void OpenSell(double sl, double tp) { ResetLastError(); sl = NormalizeDouble(sl, Digits()); tp = NormalizeDouble(tp, Digits()); if(atrade.Sell(Lots, asymbol.Name(), asymbol.Bid(), sl, tp)) { if(atrade.ResultDeal() == 0) { Print("error ", GetLastError()); } } else { Print("error ", GetLastError()); } } //+------------------------------------------------------------------+ //| Обновление котировок | //+------------------------------------------------------------------+ bool RefreshRates() { if(!asymbol.RefreshRates()) { Print("не удалось обновить котировки!"); return(false); } if(asymbol.Ask() == 0 || asymbol.Bid() == 0) return(false); return(true); } //+------------------------------------------------------------------+ bool IsFillingTypeAllowed(int fill_type) { //--- Obtain the value of the property that describes allowed filling modes int filling = asymbol.TradeFillFlags(); //--- Return true, if mode fill_type is allowed return((filling & fill_type) == fill_type); } //+------------------------------------------------------------------+ void Trend_line(string name, double price, datetime Time1, datetime Time2, color col) { NormalizeDouble(price,_Digits); if(ObjectFind(0,name)) { ObjectDelete(0,name); } if(!ObjectCreate(0,name,OBJ_TREND,0,Time2,price,Time1,price)) //--- создадим линию по заданной цене { Print(__FUNCTION__, ": не удалось создать прямоугольник! Код ошибки = ",GetLastError()); } ObjectSetInteger(0,name,OBJPROP_COLOR,col); //--- установим цвет линии ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_SOLID); //--- установим стиль линии ObjectSetInteger(0,name,OBJPROP_WIDTH,1); //--- установим толщину линии ObjectSetInteger(0,name,OBJPROP_BACK,false); //--- отобразим на переднем (false) или заднем (true) плане ObjectSetInteger(0,name,OBJPROP_SELECTABLE,true); //--- включим (true) или отключим (false) режим выделения для перемещений (доступность выделения) ObjectSetInteger(0,name,OBJPROP_SELECTED,false); //--- true, что позволяет выделять и перемещать этот объект ObjectSetInteger(0,name,OBJPROP_HIDDEN,false); //--- скроем (true) или отобразим (false) имя графического объекта в списке объектов ObjectSetInteger(0,name,OBJPROP_RAY_LEFT,true); //--- луч вправо return; }</code>
//+------------------------------------------------------------------+ //| Insid_Bar.mq5 | //| Copyright 2018, MetaQuotes Software Corp. | //| https://www.mql5.com/ru/users/s22aa | //+------------------------------------------------------------------+ #property copyright "Copyright 2018, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property indicator_chart_window #property indicator_buffers 2 #property indicator_plots 2 #property indicator_type1 DRAW_ARROW #property indicator_type2 DRAW_ARROW #property indicator_color1 clrRed #property indicator_color2 clrBlue #property indicator_width1 2 #property indicator_width2 2 double BuffUp[]; double BuffDn[]; input int ArrowShift = 0; // оступ точек от свечи, по высоте //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { SetIndexBuffer(0,BuffUp, INDICATOR_DATA); SetIndexBuffer(1,BuffDn, INDICATOR_DATA); IndicatorSetString (INDICATOR_SHORTNAME,"Insid_Bar"); IndicatorSetInteger(INDICATOR_DIGITS, _Digits); PlotIndexSetInteger(0, PLOT_ARROW, 159); PlotIndexSetInteger(1, PLOT_ARROW, 159); PlotIndexSetInteger(0, PLOT_ARROW_SHIFT, ArrowShift); PlotIndexSetInteger(1, PLOT_ARROW_SHIFT, -ArrowShift); PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ 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 i, limit; if (rates_total < 2) return(0); if (prev_calculated < 3) { limit = 2; ArrayInitialize(BuffDn, EMPTY_VALUE); ArrayInitialize(BuffUp, EMPTY_VALUE); } else limit = rates_total - 2; for(i = limit; i<rates_total-1; i++) { if (high[i] <= high[i-1] && low[i] >= low[i-1]) { BuffUp[i-1] = low[i-1]; BuffDn[i-1] = high[i-1]; } else { BuffUp[i] = EMPTY_VALUE; BuffDn[i] = EMPTY_VALUE; } } return(rates_total); }
Топикстартер просил, чтобы вместо тейк профита, выставлялся лимитный ордер, а советник выставляет тейк профит, а затем вдобавок лимитник.
Чем отличается тейк профит от лимитного ордера? И зачем заменять тейк профит лимитником?
Тейк профит такой же лимитный ордер как и обычный, разница только в том, что тейк хранится на серверах брокера и отправляется на биржу только при касании ценой, а обычный лимитник, отправляется на биржу сразу.
В итоге при сильных движениях тейк может иметь проскальзывания как положительные, так и отрицательные, а лимитник проскальзываний иметь не может.
s22aa