MT人工智能之一(AIP)
Metatrader expert advice
----测试结果惊人
/*[[
ALWAYS IN PLAY
Lots := 1.00
Notes := Best if use in H1 or higher timeframe
Update on every tick := Yes
Enable Alerts := Yes
Disable alert once hit := No
Lots := 1
Stop Loss := 999
Take Profit := 25
Trailing Stop := 999
]]*/
// =========================================================
// DECLARATION
defines: risk(25),mm(1);
vars: spread(0),
Slippage(5),
sl(0),tp(0),maxSimOpen(0),
mode(0),
buffer(0),
lastHigh(0),
target(0),
entryTS(0),
lastLow(0),
cnt(0),
first(0),
lotMM(0),
tHour(0);
cnt= 1;
// =========================================================
// VALIDATION
If CurTime - LastTradeTime < 300 Then Exit;
If Bars<100 or TakeProfit<10 then Exit;
If IsIndirect(Symbol)=TRUE then Exit;
// =========================================================
// DATE CHOKE - For testing purposes
If TimeYear(time[0]) < 2004 then {
Exit;
} else if
TimeMonth(time[0]) < 2 then {
Exit;
};
// =========================================================
// PYRAMIDING - LINEAR
//
// Money management risk exposure compounding
if mm<>0 then
{
lotMM=Ceil(Balance*risk/10000)/10;
if lotMM < 0.1 then {
lotMM = lots;
};
If lotMM > 1 then {
lotMM = Ceil(lotMM);
};
If lotMM > 100 then {
lotMM = 100;
};
} else {
lotMM=Lots;
};
// Adding simultaneously opened position
if mm = 1 then {
If balance < 1000000 then maxSimOpen=1;
If balance > 1000000 then {
maxSimOpen=(Balance*risk/10000)/1000;
} else {
maxSimOpen=1;
}
};
if mm = 2 then {
if balance < 1000000 then maxSimOpen=1;
if balance > 1000000 then {
maxSimOpen=(Balance*risk/10000)/1000;
if maxSimOpen > 20 then maxSimOpen=20;
} else {
maxSimOpen=1;
};
};
entryTS = 10*Point; //Entry trailing stop - points
buffer = 1.0*Point; //Filter/buffer above or below bar High/Low - points
target = TakeProfit*Point; //Profit target - points
lastHigh = High[1]; //Last bar high
lastLow = Low[1]; //Last bar low
spread = Bid-Ask; //Spread
// =========================================================
// TRADE ENTRY
tHour = GetGlobalVariable("tHour");
If TotalTrades<maxSimOpen Then {
//SHORT TRADES ENTRY CRITERIA
If Open[1]>Close[1] and //Last bar bearish, open greater than close;
Ask-lastLow<10*Point and //if Bid rises or falls to within 10pips of Low [1] bar ago, allow order to set;
iSAR(0.05,0.5,0)>Bid and
tHour != TimeHour(time[0]) then
{
SetGlobalVariable("tHour",TimeMinute(time[0]));
// Set stoploss to last bar high + spread
sl = lastHigh+spread;
//place order to sell m-s equals Low[1]-1pip;
//Sell on stop, 1 lot,at:Low[1]-1pip,slip0,Target:Low[1]-1pip-25pip;
SetOrder(OP_SELLSTOP,
lotMM,
lastLow-buffer-spread,
Slippage,
sl,
lastLow-buffer-spread-target,
RED);
Exit;
};
//LONG TRADES ENTRY CRITERIA
If Open[1]<Close[1] and //Last bar bullish, Open less than Close;
lastHigh-Bid<10*Point and //if Bid rises or falls to within 10pips of High[1] bar ago, allow order to set;
iSAR(0.05,0.5,0)<Bid and
tHour != TimeHour(time[0]) then
{
SetGlobalVariable("tHour",TimeMinute(time[0]));
sl = lastLow+spread;
SetOrder(OP_BUYSTOP,
lotMM,
lastHigh+buffer+spread,
Slippage,
sl,
lastHigh+buffer+spread+target,
LIME);
Exit;
};
};
// =========================================================
// TRAILING STOP ADJUSTMENT
If TrailingStop<5 then {print("invalid Trailing Stop");Exit;};
For cnt=1 to TotalTrades
{
mode=OrderValue(cnt,VAL_TYPE);
If mode=OP_BUY then
{
//if Bid-open price is now higher than 10pips profit....
If (Bid-OrderValue(cnt,VAL_OPENPRICE))>(entryTS) then
{
//and the value of the stop loss order is lower than 10pips below the Bid...
If OrderValue(cnt,VAL_STOPLOSS)<(Bid-entryTS) then
{
//then adjust the stop loss part of the order to the Bid - 10pips
ModifyOrder(OrderValue(cnt,VAL_TICKET),
OrderValue(cnt,VAL_OPENPRICE),
Bid-entryTS,
OrderValue(cnt,VAL_TAKEPROFIT),
BLUE);
Exit;
};
};
If OrderValue(cnt,VAL_STOPLOSS)>=OrderValue(cnt,VAL_OPENPRICE) then
{
ModifyOrder(OrderValue(cnt,VAL_TICKET),
OrderValue(cnt,VAL_OPENPRICE),
OrderValue(cnt,VAL_STOPLOSS),
Ask+TakeProfit*Point,
BLUE);
Exit;
};
};
If mode=OP_SELL then
{
//if current Ask price dropped 10 pips or more below the open price
If (OrderValue(cnt,VAL_OPENPRICE)-Ask)>(entryTS) then
{
//and the stop loss order is greater than 10pips above the current Ask..
If OrderValue(cnt,VAL_STOPLOSS)>(Ask+entryTS) then
{
//then adjust the stop loss part of the order to Ask+10pips
ModifyOrder(OrderValue(cnt,VAL_TICKET),
OrderValue(cnt,VAL_OPENPRICE),
Ask+entryTS,
OrderValue(cnt,VAL_TAKEPROFIT),
BLUE);
Exit;
};
};
If OrderValue(cnt,VAL_STOPLOSS)<=OrderValue(cnt,VAL_OPENPRICE) then
{
ModifyOrder(OrderValue(cnt,VAL_TICKET),
OrderValue(cnt,VAL_OPENPRICE),
OrderValue(cnt,VAL_STOPLOSS),
Bid-TakeProfit*Point,
BLUE);
Exit;
};
// =========================================================
// CLEANING PENDING TRADES
// check how long it exists in the trading terminal - time is counted in seconds
// if the current time ignoring hours is greater than 58minutes cancel the open order(allowing new one to place).
If mode>OP_SELLSTOP then
{
If Minute>58 then
{
DeleteOrder(OrderValue(cnt,VAL_TICKET),INDIGO);
Exit;
};
};
If mode>OP_BUYSTOP then
{
If Minute>58 then
{
DeleteOrder(OrderValue(cnt,VAL_TICKET),INDIGO);
Exit;
};
};
};
};
Exit;
[此帖子已被 hilow 在 2004-9-27 2:44:47 编辑过]
发表于:2005-02-01 08:28只看该作者
3楼
有 ; 是什么呀?
发表于:2005-02-01 10:12只看该作者
4楼
;测试通不过啊。。。