智能移动止损的 EA 脚本
2013-06-30 13:08:50| 分类:
金融证券
| 标签:
|举报
|字号大中小 订阅
学习mt4,发个智能移动止损的 EA 脚本。
在网上找了一个老外写的StepStopExpert_v1.1,貌似还是2007年写的,功能完全不满意。干脆自己做一个。
算法如下:
1. 检测所下单子,若单子未设置止损和止盈,则根据默认输入参数设置止损和止盈。
2. 若单子发生盈利,并达到移动止损触发线,则动态提高原有止损线,进入追踪止损状态。
3. 若单子一直盈利,止损的范围也会随着盈利的比例变大而变大。
4. 若单子盈利已经达到预期止盈目标的 75%,则动态提高止盈线,给出更多上涨空间。
总而言之,即是上涨时尽量扩大盈利目标,跌落时尽量保住既有盈利。
欢迎测试指证。
[font=courier new][code]#property copyright "CN.ineztia"
#property link "http://www.metaquotes.net"
extern bool g_debug = true;
extern double g_initStop = 27;
extern double g_breakEven = 20;
extern double g_stepSize = 3;
extern double g_measure = 10;
extern double g_stopMax = 200;
extern double g_profitExtendThreshold = 0.75;
extern double g_profitMax = 0; // close order if profit reaches the pre-defined max value
int doStepStop() {
int total = OrdersTotal();
for (int i = 0; i < total; i++) {
if (OrderSelect(i, SELECT_BY_POS)) {
if (OrderSymbol() != Symbol()) {
continue;
}
double flag = 0;
double price = 0; // current price
double desiredProfit = 0;
double realProfit = 0;
double profitModifier = 0;
double takeProfit = OrderTakeProfit();
double stopLoss = OrderStopLoss();
double stepStopTrigger = (g_breakEven + g_initStop) * Point;
if (OrderType() == OP_BUY) {
flag = 1;
price = Bid;
} else if (OrderType() == OP_SELL) {
flag = -1;
price = Ask;
} else {