#property show_inputs
#include <stdlib.mqh>
extern int RangeFilter = 20;
extern int MagicNumber = 293875;
extern string TradeComment = "Liquidex";
extern int StopLoss = 30;
extern double MinLots = 0.01;
extern double MaxLots = 100000.0;
extern double Risk = 25.0;
extern double MaxSpreadWithCommission = 15.0;
extern int TrailingLimit = 15;
extern int TrailingDistance = 15;
extern int MAPeriod = 3;
extern int MAShift = 0;
extern int MAMethod = MODE_LWMA;
extern double DefaultCommisionPoints = 0;
extern string RangeFilterNote = "H-S 0-0: 250 0-1: 300 1-0: 80 1-1: 250";
extern string MAMethodNote = "SMA: 0 EMA: 1 SMMA: 2 LWMA 3";
int digits = 0;
double point = 0.0;
int lotsDigits;
double minLots;
double maxLots;
double risk;
double maxSpreadWithCommission;
double trailingLimit;
double trailingDistance;
double rangeFilter;
int slippage = 3;
bool gotCommissionPointsFromTrade;
double commissionPoints;
double spreadHistory[30];
int spreadHistoryCount = 0;
double last_history_check;
int init()
{
// код доступен только после оплаты
}
int start()
{
// код доступен только после оплаты
}
int errorCode;
string errorMessage;
int ticket;
double openPrice;
bool modified;
double orderOpenPrice;
double orderStopLoss;
double orderTakeProfit;
double stopLoss;
double high = iHigh(NULL, 0, 0);
double low = iLow(NULL, 0, 0);
double open = iOpen(NULL, 0, 0);
double ma = iMA(NULL, 0, MAPeriod, MAShift, MAMethod, PRICE_CLOSE, 0);
if (!gotCommissionPointsFromTrade)
{
for (int i = OrdersHistoryTotal() - 1; i >= 0; i--)
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
continue;
}
if (OrderProfit() == 0.0)
{
continue;
}
if (OrderClosePrice() == OrderOpenPrice())
{
continue;
}
if (OrderSymbol() != Symbol())
{
continue;
}
gotCommissionPointsFromTrade = true;
double pipRate = MathAbs(OrderProfit() / (OrderClosePrice() - OrderOpenPrice()));
commissionPoints = (-OrderCommission()) / pipRate;
Print("CommissionPoints: " + DoubleToStr(commissionPoints, digits));
break;
}
}
double spread = Ask - Bid;
ArrayCopy(spreadHistory, spreadHistory, 0, 1, 29);
spreadHistory[29] = spread;
if (spreadHistoryCount < 30)
{
spreadHistoryCount++;
}
double spreadHistorySum = 0;
i = 29;
for (int count_8 = 0; count_8 < spreadHistoryCount; count_8++)
{
spreadHistorySum += spreadHistory[i];
i--;
}
double spreadAverage = spreadHistorySum / spreadHistoryCount;
double askWithCommission = NormalizeDouble(Ask + commissionPoints, digits);
double bidWithCommission = NormalizeDouble(Bid - commissionPoints, digits);
double spreadAverageWithCommission = NormalizeDouble(spreadAverage + commissionPoints, digits + 1);
double range = high - low;
if (range > rangeFilter)
{
if (Bid < ma && open>Bid)
{
int direction = +1; // SELL
}
else if (Bid > ma && open<Bid)
{
direction = -1; // BUY
}
}
for(i=OrdersHistoryTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==True)
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() ==MagicNumber && OrderType()<=1)
{
last_history_check=GetHLineValue("last_history_check_"+Symbol()+strtf(Period())+"_"+MagicNumber);
if(OrderCloseTime()<last_history_check) break;
else if(OrderCloseTime()>last_history_check)
{
int tck;
double money2 = (AccountBalance() * AccountLeverage()) * risk;
double lots2 = NormalizeDouble(money2 / MarketInfo(Symbol(), MODE_LOTSIZE), lotsDigits);
lots2 = MathMax(minLots, lots2);
lots2 = MathMin(maxLots, lots2);
if(direction<0 && range > rangeFilter && Bid > ma && open<Bid) //BUYSTOP
{
openPrice = NormalizeDouble(Ask + trailingLimit, digits);
stopLoss = NormalizeDouble(openPrice - StopLoss * Point, digits);
tck = OrderSend(Symbol(), OP_BUYSTOP, lots2, openPrice, slippage, stopLoss, 0, TradeComment, MagicNumber, 0, Lime);
if (tck <= 0)
{
errorCode = GetLastError();
errorMessage = ErrorDescription(errorCode);
Print("BUY Send Error Code: " + errorCode + " Message: " + errorMessage + " LT: " + DoubleToStr(lots2, lotsDigits) + " OP: " + DoubleToStr(openPrice, digits) + " SL: " + DoubleToStr(stopLoss, digits) + " Bid: " + DoubleToStr(Bid, digits) + " Ask: " + DoubleToStr(Ask, digits));
}
}
else if(direction>0 && range > rangeFilter && Bid < ma && open>Bid) //SELLSTOP
{
openPrice = NormalizeDouble(Bid - trailingLimit, digits);
stopLoss = NormalizeDouble(openPrice + StopLoss * Point, digits);
tck = OrderSend(Symbol(), OP_SELLSTOP, lots2, openPrice, slippage, stopLoss, 0, TradeComment, MagicNumber, 0, Orange);
if (tck <= 0)
{
errorCode = GetLastError();
errorMessage = ErrorDescription(errorCode);
Print("SELL Send Error Code: " + errorCode + " Message: " + errorMessage + " LT: " + DoubleToStr(lots2, lotsDigits) + " OP: " + DoubleToStr(openPrice, digits) + " SL: " + DoubleToStr(stopLoss, digits) + " Bid: " + DoubleToStr(Bid, digits) + " Ask: " + DoubleToStr(Ask, digits));
}
}
DrawLine("last_history_check_"+Symbol()+strtf(Period())+"_"+MagicNumber,TimeCurrent());
}
}
}
}
int openTrades = 0;
for (i = 0; i < OrdersTotal(); i++)
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
continue;
}
if (OrderMagicNumber() != MagicNumber)
{
continue;
}
int type = OrderType();
if (type == OP_BUYLIMIT || type == OP_SELLLIMIT)
{
continue;
}
if (OrderSymbol() != Symbol())
{
continue;
}
openTrades++;
switch (type)
{
case OP_BUY:
if (TrailingDistance >= 0)
{
Показано первые 50% кода (символов: 10701)
Введите ваш email и нажмите кнопку, чтобы перейти к оплате.