顺水外汇EA交易网MT4

标题: MACD中的老大四色双线背离自划线 [打印本页]

作者: 股道清扬    时间: 2018-1-11 16:26
标题: MACD中的老大四色双线背离自划线
MACD是指标中的趋势王子
图已上

作者: a545147424    时间: 2018-1-11 17:23
//==========================================================================================================================
#property copyright "MT-4"
#property link  "fx.09@mail.ru"   
//==========================================================================================================================
extern double LotExponent = 3.1;
extern double Lots = 0.01;        
extern int lotdecimal = 2;      
extern double TakeProfit = 10.0;  
extern double PipStep = 30.0;     
extern double slip = 30.0;        
bool UseEquityStop = FALSE;      
bool UseTrailingStop = FALSE;     
bool UseTimeOut = FALSE;         
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
double Stoploss = 5000.0;        
double TrailStart = 100.0;
double TrailStop = 100.0;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
double PriceTarget, StartEquity, BuyTarget, SellTarget ;
double AveragePrice, SellLimit, BuyLimit ;
double LastBuyPrice, LastSellPrice, Spread;
bool flag;
string EAName = "Ilan_HiLo_RSI";
int timeprev = 0, expiration;
int NumOfTrades = 0;
double iLots;
int cnt = 0, total;
double Stopper = 0.0;
bool TradeNow = FALSE, LongTrade = FALSE, ShortTrade = FALSE;
int ticket;
bool NewOrdersPlaced = FALSE;
double AccountEquityHighAmt, PrevEquity;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int init() {
   Spread = MarketInfo(Symbol(), MODE_SPREAD) * Point;
   return (0);
}

int deinit() {
   return (0);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int start() {
   double PrevCl;
   double CurrCl;
   if (UseTrailingStop) TrailingAlls(TrailStart, TrailStop, AveragePrice);
   if (UseTimeOut) {
      if (TimeCurrent() >= expiration) {
         CloseThisSymbolAll();
         Print("Closed All due to TimeOut");
      }
   }
   if (timeprev == Time[0]) return (0);
   timeprev = Time[0];
   double CurrentPairProfit = CalculateProfit();
   if (UseEquityStop) {
      if (CurrentPairProfit  TotalEquityRisk / 100.0 * AccountEquityHigh()) {
         CloseThisSymbolAll();
         Print("Closed All due to Stop Out");
         NewOrdersPlaced = FALSE;
      }
   }
   total = CountTrades();
   if (total == 0) flag = FALSE;
   for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
         if (OrderType() == OP_BUY) {
            LongTrade = TRUE;
            ShortTrade = FALSE;
            break;
         }
      }
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
         if (OrderType() == OP_SELL) {
            LongTrade = FALSE;
            ShortTrade = TRUE;
            break;
         }
      }
   }
   if (total > 0 && total = PipStep * Point) TradeNow = TRUE;
      if (ShortTrade && Bid - LastSellPrice >= PipStep * Point) TradeNow = TRUE;
   }
   if (total  CurrCl) {

//HHHHHHHH~~~~~~~~~~~~~ 软濑?RSI ~~~~~~~~~~HHHHHHHHH~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~         
            if (iRSI(NULL, PERIOD_H1, 14, PRICE_CLOSE, 1) > 30.0) {
               ticket = OpenPendingOrder(1, iLots, SellLimit, slip, SellLimit, 0, 0, EAName + "-" + NumOfTrades, MagicNumber, 0, HotPink);
               if (ticket  0) expiration = TimeCurrent() + 60.0 * (60.0 * MaxTradeOpenHours);
TradeNow = FALSE;
}
}
total = CountTrades();
AveragePrice = 0;
double Count = 0;
for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
if (OrderType() == OP_BUY || OrderType() == OP_SELL) {
AveragePrice += OrderOpenPrice() * OrderLots();
Count += OrderLots();
}
}
}
if (total > 0) AveragePrice = NormalizeDouble(AveragePrice / Count, Digits);
if (NewOrdersPlaced) {
for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
if (OrderType() == OP_BUY) {
PriceTarget = AveragePrice + TakeProfit * Point;
BuyTarget = PriceTarget;
Stopper = AveragePrice - Stoploss * Point;
flag = TRUE;
}
}
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
if (OrderType() == OP_SELL) {
PriceTarget = AveragePrice - TakeProfit * Point;
SellTarget = PriceTarget;
Stopper = AveragePrice + Stoploss * Point;
flag = TRUE;
}
}
}
}
if (NewOrdersPlaced) {
if (flag == TRUE) {
for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) OrderModify(OrderTicket(), AveragePrice, OrderStopLoss(), PriceTarget, 0, Yellow);
NewOrdersPlaced = FALSE;
}
}
}
return (0);
}

//镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲

int CountTrades() {
int count = 0;
for (int trade = OrdersTotal() - 1; trade >= 0; trade--) {
OrderSelect(trade, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
if (OrderType() == OP_SELL || OrderType() == OP_BUY) count++;
}
return (count);
}

//镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲

void CloseThisSymbolAll() {
for (int trade = OrdersTotal() - 1; trade >= 0; trade--) {
OrderSelect(trade, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol()) {
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, slip, Blue);
if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, slip, Red);
}
Sleep(1000);
}
}
}

//镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲

int OpenPendingOrder(int pType, double pLots, double pPrice, int pSlippage, double pr, int sl, int tp, string pComment, int pMagic, int pDatetime, color pColor) {
int ticket = 0;
int err = 0;
int c = 0;
int NumberOfTries = 100;
switch (pType) {
case 2:
for (c = 0; c = 0; cnt--) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
if (OrderType() == OP_BUY || OrderType() == OP_SELL) Profit += OrderProfit();
}
return (Profit);
}

//镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲

void TrailingAlls(int pType, int stop, double AvgPrice) {
int profit;
double stoptrade;
double stopcal;
if (stop != 0) {
for (int trade = OrdersTotal() - 1; trade >= 0; trade--) {
if (OrderSelect(trade, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() || OrderMagicNumber() == MagicNumber) {
if (OrderType() == OP_BUY) {
profit = NormalizeDouble((Bid - AvgPrice) / Point, 0);
if (profit  stoptrade)) OrderModify(OrderTicket(), AvgPrice, stopcal, OrderTakeProfit(), 0, Aqua);
}
if (OrderType() == OP_SELL) {
profit = NormalizeDouble((AvgPrice - Ask) / Point, 0);
if (profit = 0; cnt--) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_BUY) {
oldticketnumber = OrderTicket();
if (oldticketnumber > ticketnumber) {
oldorderopenprice = OrderOpenPrice();
unused = oldorderopenprice;
ticketnumber = oldticketnumber;
}
}
}
return (oldorderopenprice);
}

//镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲

double FindLastSellPrice() {
double oldorderopenprice;
int oldticketnumber;
double unused = 0;
int ticketnumber = 0;
for (int cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_SELL) {
oldticketnumber = OrderTicket();
if (oldticketnumber > ticketnumber) {
oldorderopenprice = OrderOpenPrice();
unused = oldorderopenprice;
作者: a545147424    时间: 2018-1-11 17:29
//==========================================================================================================================
#property copyright "MT-4"
#property link  "fx.09@mail.ru"   
//==========================================================================================================================
extern double LotExponent = 3.1;
extern double Lots = 0.01;        
extern int lotdecimal = 2;      
extern double TakeProfit = 10.0;  
extern double PipStep = 30.0;     
extern double slip = 30.0;        
bool UseEquityStop = FALSE;      
bool UseTrailingStop = FALSE;     
bool UseTimeOut = FALSE;         
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
double Stoploss = 5000.0;        
double TrailStart = 100.0;
double TrailStop = 100.0;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
double PriceTarget, StartEquity, BuyTarget, SellTarget ;
double AveragePrice, SellLimit, BuyLimit ;
double LastBuyPrice, LastSellPrice, Spread;
bool flag;
string EAName = "Ilan_HiLo_RSI";
int timeprev = 0, expiration;
int NumOfTrades = 0;
double iLots;
int cnt = 0, total;
double Stopper = 0.0;
bool TradeNow = FALSE, LongTrade = FALSE, ShortTrade = FALSE;
int ticket;
bool NewOrdersPlaced = FALSE;
double AccountEquityHighAmt, PrevEquity;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int init() {
   Spread = MarketInfo(Symbol(), MODE_SPREAD) * Point;
   return (0);
}

int deinit() {
   return (0);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int start() {
   double PrevCl;
   double CurrCl;
   if (UseTrailingStop) TrailingAlls(TrailStart, TrailStop, AveragePrice);
   if (UseTimeOut) {
      if (TimeCurrent() >= expiration) {
         CloseThisSymbolAll();
         Print("Closed All due to TimeOut");
      }
   }
   if (timeprev == Time[0]) return (0);
   timeprev = Time[0];
   double CurrentPairProfit = CalculateProfit();
   if (UseEquityStop) {
      if (CurrentPairProfit  TotalEquityRisk / 100.0 * AccountEquityHigh()) {
         CloseThisSymbolAll();
         Print("Closed All due to Stop Out");
         NewOrdersPlaced = FALSE;
      }
   }
   total = CountTrades();
   if (total == 0) flag = FALSE;
   for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
         if (OrderType() == OP_BUY) {
            LongTrade = TRUE;
            ShortTrade = FALSE;
            break;
         }
      }
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
         if (OrderType() == OP_SELL) {
            LongTrade = FALSE;
            ShortTrade = TRUE;
            break;
         }
      }
   }
   if (total > 0 && total = PipStep * Point) TradeNow = TRUE;
      if (ShortTrade && Bid - LastSellPrice >= PipStep * Point) TradeNow = TRUE;
   }
   if (total  CurrCl) {

//HHHHHHHH~~~~~~~~~~~~~ 软濑?RSI ~~~~~~~~~~HHHHHHHHH~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~         
            if (iRSI(NULL, PERIOD_H1, 14, PRICE_CLOSE, 1) > 30.0) {
               ticket = OpenPendingOrder(1, iLots, SellLimit, slip, SellLimit, 0, 0, EAName + "-" + NumOfTrades, MagicNumber, 0, HotPink);
               if (ticket  0) expiration = TimeCurrent() + 60.0 * (60.0 * MaxTradeOpenHours);
TradeNow = FALSE;
}
}
total = CountTrades();
AveragePrice = 0;
double Count = 0;
for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
if (OrderType() == OP_BUY || OrderType() == OP_SELL) {
AveragePrice += OrderOpenPrice() * OrderLots();
Count += OrderLots();
}
}
}
if (total > 0) AveragePrice = NormalizeDouble(AveragePrice / Count, Digits);
if (NewOrdersPlaced) {
for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
if (OrderType() == OP_BUY) {
PriceTarget = AveragePrice + TakeProfit * Point;
BuyTarget = PriceTarget;
Stopper = AveragePrice - Stoploss * Point;
flag = TRUE;
}
}
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
if (OrderType() == OP_SELL) {
PriceTarget = AveragePrice - TakeProfit * Point;
SellTarget = PriceTarget;
Stopper = AveragePrice + Stoploss * Point;
flag = TRUE;
}
}
}
}
if (NewOrdersPlaced) {
if (flag == TRUE) {
for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) OrderModify(OrderTicket(), AveragePrice, OrderStopLoss(), PriceTarget, 0, Yellow);
NewOrdersPlaced = FALSE;
}
}
}
return (0);
}

//镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲

int CountTrades() {
int count = 0;
for (int trade = OrdersTotal() - 1; trade >= 0; trade--) {
OrderSelect(trade, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
if (OrderType() == OP_SELL || OrderType() == OP_BUY) count++;
}
return (count);
}

//镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲

void CloseThisSymbolAll() {
for (int trade = OrdersTotal() - 1; trade >= 0; trade--) {
OrderSelect(trade, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol()) {
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, slip, Blue);
if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, slip, Red);
}
Sleep(1000);
}
}
}

//镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲

int OpenPendingOrder(int pType, double pLots, double pPrice, int pSlippage, double pr, int sl, int tp, string pComment, int pMagic, int pDatetime, color pColor) {
int ticket = 0;
int err = 0;
int c = 0;
int NumberOfTries = 100;
switch (pType) {
case 2:
for (c = 0; c = 0; cnt--) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
if (OrderType() == OP_BUY || OrderType() == OP_SELL) Profit += OrderProfit();
}
return (Profit);
}

//镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲

void TrailingAlls(int pType, int stop, double AvgPrice) {
int profit;
double stoptrade;
double stopcal;
if (stop != 0) {
for (int trade = OrdersTotal() - 1; trade >= 0; trade--) {
if (OrderSelect(trade, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() || OrderMagicNumber() == MagicNumber) {
if (OrderType() == OP_BUY) {
profit = NormalizeDouble((Bid - AvgPrice) / Point, 0);
if (profit  stoptrade)) OrderModify(OrderTicket(), AvgPrice, stopcal, OrderTakeProfit(), 0, Aqua);
}
if (OrderType() == OP_SELL) {
profit = NormalizeDouble((AvgPrice - Ask) / Point, 0);
if (profit = 0; cnt--) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_BUY) {
oldticketnumber = OrderTicket();
if (oldticketnumber > ticketnumber) {
oldorderopenprice = OrderOpenPrice();
unused = oldorderopenprice;
ticketnumber = oldticketnumber;
}
}
}
return (oldorderopenprice);
}

//镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲

double FindLastSellPrice() {
double oldorderopenprice;
int oldticketnumber;
double unused = 0;
int ticketnumber = 0;
for (int cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_SELL) {
oldticketnumber = OrderTicket();
if (oldticketnumber > ticketnumber) {
oldorderopenprice = OrderOpenPrice();
unused = oldorderopenprice;
作者: a545147424    时间: 2018-1-11 18:16
//==========================================================================================================================
#property copyright "MT-4"
#property link  "fx.09@mail.ru"   
//==========================================================================================================================
extern double LotExponent = 3.1;
extern double Lots = 0.01;        
extern int lotdecimal = 2;      
extern double TakeProfit = 10.0;  
extern double PipStep = 30.0;     
extern double slip = 30.0;        
bool UseEquityStop = FALSE;      
bool UseTrailingStop = FALSE;     
bool UseTimeOut = FALSE;         
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
double Stoploss = 5000.0;        
double TrailStart = 100.0;
double TrailStop = 100.0;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
double PriceTarget, StartEquity, BuyTarget, SellTarget ;
double AveragePrice, SellLimit, BuyLimit ;
double LastBuyPrice, LastSellPrice, Spread;
bool flag;
string EAName = "Ilan_HiLo_RSI";
int timeprev = 0, expiration;
int NumOfTrades = 0;
double iLots;
int cnt = 0, total;
double Stopper = 0.0;
bool TradeNow = FALSE, LongTrade = FALSE, ShortTrade = FALSE;
int ticket;
bool NewOrdersPlaced = FALSE;
double AccountEquityHighAmt, PrevEquity;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int init() {
   Spread = MarketInfo(Symbol(), MODE_SPREAD) * Point;
   return (0);
}

int deinit() {
   return (0);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int start() {
   double PrevCl;
   double CurrCl;
   if (UseTrailingStop) TrailingAlls(TrailStart, TrailStop, AveragePrice);
   if (UseTimeOut) {
      if (TimeCurrent() >= expiration) {
         CloseThisSymbolAll();
         Print("Closed All due to TimeOut");
      }
   }
   if (timeprev == Time[0]) return (0);
   timeprev = Time[0];
   double CurrentPairProfit = CalculateProfit();
   if (UseEquityStop) {
      if (CurrentPairProfit  TotalEquityRisk / 100.0 * AccountEquityHigh()) {
         CloseThisSymbolAll();
         Print("Closed All due to Stop Out");
         NewOrdersPlaced = FALSE;
      }
   }
   total = CountTrades();
   if (total == 0) flag = FALSE;
   for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
         if (OrderType() == OP_BUY) {
            LongTrade = TRUE;
            ShortTrade = FALSE;
            break;
         }
      }
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
         if (OrderType() == OP_SELL) {
            LongTrade = FALSE;
            ShortTrade = TRUE;
            break;
         }
      }
   }
   if (total > 0 && total = PipStep * Point) TradeNow = TRUE;
      if (ShortTrade && Bid - LastSellPrice >= PipStep * Point) TradeNow = TRUE;
   }
   if (total  CurrCl) {

//HHHHHHHH~~~~~~~~~~~~~ 软濑?RSI ~~~~~~~~~~HHHHHHHHH~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~         
            if (iRSI(NULL, PERIOD_H1, 14, PRICE_CLOSE, 1) > 30.0) {
               ticket = OpenPendingOrder(1, iLots, SellLimit, slip, SellLimit, 0, 0, EAName + "-" + NumOfTrades, MagicNumber, 0, HotPink);
               if (ticket  0) expiration = TimeCurrent() + 60.0 * (60.0 * MaxTradeOpenHours);
TradeNow = FALSE;
}
}
total = CountTrades();
AveragePrice = 0;
double Count = 0;
for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
if (OrderType() == OP_BUY || OrderType() == OP_SELL) {
AveragePrice += OrderOpenPrice() * OrderLots();
Count += OrderLots();
}
}
}
if (total > 0) AveragePrice = NormalizeDouble(AveragePrice / Count, Digits);
if (NewOrdersPlaced) {
for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
if (OrderType() == OP_BUY) {
PriceTarget = AveragePrice + TakeProfit * Point;
BuyTarget = PriceTarget;
Stopper = AveragePrice - Stoploss * Point;
flag = TRUE;
}
}
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
if (OrderType() == OP_SELL) {
PriceTarget = AveragePrice - TakeProfit * Point;
SellTarget = PriceTarget;
Stopper = AveragePrice + Stoploss * Point;
flag = TRUE;
}
}
}
}
if (NewOrdersPlaced) {
if (flag == TRUE) {
for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) OrderModify(OrderTicket(), AveragePrice, OrderStopLoss(), PriceTarget, 0, Yellow);
NewOrdersPlaced = FALSE;
}
}
}
return (0);
}

//镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲

int CountTrades() {
int count = 0;
for (int trade = OrdersTotal() - 1; trade >= 0; trade--) {
OrderSelect(trade, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
if (OrderType() == OP_SELL || OrderType() == OP_BUY) count++;
}
return (count);
}

//镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲

void CloseThisSymbolAll() {
for (int trade = OrdersTotal() - 1; trade >= 0; trade--) {
OrderSelect(trade, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol()) {
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, slip, Blue);
if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, slip, Red);
}
Sleep(1000);
}
}
}

//镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲

int OpenPendingOrder(int pType, double pLots, double pPrice, int pSlippage, double pr, int sl, int tp, string pComment, int pMagic, int pDatetime, color pColor) {
int ticket = 0;
int err = 0;
int c = 0;
int NumberOfTries = 100;
switch (pType) {
case 2:
for (c = 0; c = 0; cnt--) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
if (OrderType() == OP_BUY || OrderType() == OP_SELL) Profit += OrderProfit();
}
return (Profit);
}

//镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲

void TrailingAlls(int pType, int stop, double AvgPrice) {
int profit;
double stoptrade;
double stopcal;
if (stop != 0) {
for (int trade = OrdersTotal() - 1; trade >= 0; trade--) {
if (OrderSelect(trade, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() || OrderMagicNumber() == MagicNumber) {
if (OrderType() == OP_BUY) {
profit = NormalizeDouble((Bid - AvgPrice) / Point, 0);
if (profit  stoptrade)) OrderModify(OrderTicket(), AvgPrice, stopcal, OrderTakeProfit(), 0, Aqua);
}
if (OrderType() == OP_SELL) {
profit = NormalizeDouble((AvgPrice - Ask) / Point, 0);
if (profit = 0; cnt--) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_BUY) {
oldticketnumber = OrderTicket();
if (oldticketnumber > ticketnumber) {
oldorderopenprice = OrderOpenPrice();
unused = oldorderopenprice;
ticketnumber = oldticketnumber;
}
}
}
return (oldorderopenprice);
}

//镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲镲

double FindLastSellPrice() {
double oldorderopenprice;
int oldticketnumber;
double unused = 0;
int ticketnumber = 0;
for (int cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_SELL) {
oldticketnumber = OrderTicket();
if (oldticketnumber > ticketnumber) {
oldorderopenprice = OrderOpenPrice();
unused = oldorderopenprice;
作者: Roy_PUtmt    时间: 2018-1-11 19:35
老大,有图吗?

作者: cck    时间: 2018-1-11 20:27
老大,有图吗?
作者: 很忙    时间: 2018-1-11 20:34
谢谢分享
作者: jiuhongzhi    时间: 2018-1-11 20:55
图呢?????
作者: ytywsy    时间: 2018-1-11 21:55

图呢?????
作者: haohan123    时间: 2018-1-11 22:41
我来研究研究  这个东西  哈哈
作者: 股道清扬    时间: 2018-1-12 00:12
还行吧,好用
作者: 点点青果    时间: 2018-1-12 01:06
我喜欢用MACD
作者: wx_Zp4mxZsr    时间: 2018-1-12 01:56
谢谢分享
作者: yufeng001    时间: 2018-1-12 03:34
谢谢分享
作者: yufeng001    时间: 2018-1-12 03:52
貌似很好用




欢迎光临 顺水外汇EA交易网MT4 (http://waterforex.com/) Powered by Discuz! X3.2