主题:外汇交易者聚集地 讨论帖1 -- 江阔云低
特别是需要盯盘的日内交易,长期由人操作身体吃不消。
用计算机语言构造交易计划这个早就有了。
这是MT4的Expert Advisors自带的一段示范程序,以移动平均线作为下单指标
//+------------------------------------------------------------------+
//| Moving Average.mq4 |
//| Copyright 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#define MAGICMA 20050610
extern double Lots = 0.1;
extern double MaximumRisk = 0.02;
extern double DecreaseFactor = 3;
extern double MovingPeriod = 12;
extern double MovingShift = 6;
//+------------------------------------------------------------------+
//| Calculate open positions |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
{
int buys=0,sells=0;
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
{
if(OrderType()==OP_BUY) buys++;
if(OrderType()==OP_SELL) sells++;
}
}
//---- return orders volume
if(buys>0) return(buys);
else return(-sells);
}
//+------------------------------------------------------------------+
//| Calculate optimal lot size |
//+------------------------------------------------------------------+
double LotsOptimized()
{
double lot=Lots;
int orders=HistoryTotal(); // history orders total
int losses=0; // number of losses orders without a break
//---- select lot size
lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,1);
//---- calcuulate number of losses orders without a break
if(DecreaseFactor>0)
{
for(int i=orders-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error in history!"); break; }
if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL) continue;
//----
if(OrderProfit()>0) break;
if(OrderProfit()<0) losses++;
}
if(losses>1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);
}
//---- return lot size
if(lot<0.1) lot=0.1;
return(lot);
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForOpen()
{
double ma;
int res;
//---- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//---- get Moving Average
ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
//---- sell conditions
if(Open[1]>ma && Close[1]<ma)
{
res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Red);
return;
}
//---- buy conditions
if(Open[1]<ma && Close[1]>ma)
{
res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"",MAGICMA,0,Blue);
return;
}
//----
}
//+------------------------------------------------------------------+
//| Check for close order conditions |
//+------------------------------------------------------------------+
void CheckForClose()
{
double ma;
//---- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//---- get Moving Average
ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
//---- check order type
if(OrderType()==OP_BUY)
{
if(Open[1]>ma && Close[1]<ma) OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
break;
}
if(OrderType()==OP_SELL)
{
if(Open[1]<ma && Close[1]>ma) OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
break;
}
}
//----
}
//+------------------------------------------------------------------+
//| Start function |
//+------------------------------------------------------------------+
void start()
{
//---- check for history and trading
if(Bars<100 || IsTradeAllowed()==false) return;
//---- calculate open orders by current symbol
if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
else CheckForClose();
//----
}
//+------------------------------------------------------------------+
有C语言基础上手很快。我就自学了2个周业余时间基本就完全上手。但调制优化到赚钱花了半年时间,这个急不来。
Expert Advisors计算机交易有两大好处。第一就是你能用几年的历史数据来检验自己的交易系统,优化参数,毕竟同一种货币对的主要操盘手们不会都换人,他们总体的操作风格是稳定的。第二就是完全的机械操作下单,像海龟交易法这种就可以完全计算机化,而且24小时在线,不受人的精神体力限制,不受贪婪恐惧的影响。
我个人的建议是,就算不用机器下单,但一定要用程序和历史数据来检验一下自己的交易系统,用自己的钱和时间来检验有点不划算。
- 相关回复 上下关系8
🙂谢谢你的回复,我只是注意到镑美和欧美的相似性,由此产生的 江阔云低 字196 2012-02-23 03:04:08
🙂这个判断怎么做? PBS 字99 2012-05-16 18:12:25
🙂外汇交易者聚集地 讨论帖2 关于欧元 2 江阔云低 字778 2012-02-22 02:01:31
🙂今后计算机取代人主导外汇交易是一个长期的趋势
🙂计算机想取代人很难 霜迹板桥 字138 2012-02-26 12:45:28
🙂从你的回答和船长的预测,可以知道你们对1.31位点很在意 PBS 字173 2012-02-22 14:43:56
🙂呵呵,我不知道你平常是怎么做的 江阔云低 字345 2012-02-23 03:46:19
🙂现在欧元已经跌破1.3171,接下去的走向会是什么? PBS 字62 2012-03-06 10:25:02