mql4 - 如何修复关闭 [1] 和关闭 [2]
问题描述
我的 EA 交易有问题,现在我将向您展示带有交易屏幕截图的代码(这种情况经常发生)记住
void OnTimer()
{
//---
if (currBars != Bars){
calculate_price_levels();
//debug_levels();
check_nearest_levels();
if (is_session()){
if (Close[2] < Nearest_Up_Level && Close[1] >= Nearest_Up_Level && isAvailableOrder()){
//Print("BUY entry, Nearest_Up_Level:",Nearest_Up_Level, ",Close[2]:",Close[2], ",Close[1]:",Close[1]);
double lot = _get_lot_size (Stop_Loss);
OpenTrade(Symbol(), OP_BUY, lot);
}
if (Close[2] > Nearest_Down_Level && Close[1] <= Nearest_Down_Level && isAvailableOrder()){
//Print("SELL entry, Nearest_Down_Level:",Nearest_Down_Level, ",Close[2]:",Close[2], ",Close[1]:",Close[1]);
double lot = _get_lot_size (Stop_Loss);
OpenTrade(Symbol(), OP_SELL, lot);
}
}
currBars = Bars;
}
if (Trailing_Stop > 0) trail_sl();
// if (BE > 0) check_be();
int trades_number = _get_number_of_trades();
if (trades_number < Trades_Number_0) check_last_trade_result();
Trades_Number_0 = trades_number;
}
void check_nearest_levels(){
int size = ArraySize(Price_Levels);
for (int i = 0; i < size; i++){
if (Close[2] > Price_Levels[i] && Close[2] < Price_Levels[i + 1]){
Nearest_Down_Level = Price_Levels[i];
Nearest_Up_Level = Price_Levels[i + 1];
BUY_TP_Price = 0;
if (size > i + 2) BUY_TP_Price = Price_Levels[i + 2];
else BUY_TP_Price = Nearest_Up_Level + StepPips * Point * mp;
Next_BUY_TP_Price = 0;
if (size > i + 3) Next_BUY_TP_Price = Price_Levels[i + 3];
else Next_BUY_TP_Price = BUY_TP_Price + StepPips * Point * mp;
SELL_TP_Price = 0;
if (i >= 1) SELL_TP_Price = Price_Levels[i - 1];
else SELL_TP_Price = Nearest_Down_Level - StepPips * Point * mp;
Next_SELL_TP_Price = 0;
if (i >= 2) Next_SELL_TP_Price = Price_Levels[i - 2];
else Next_SELL_TP_Price = SELL_TP_Price - StepPips * Point * mp;
break;
}
}
}
解决方案
推荐阅读
- android - Unity Admobs 无法在 Android 设备上运行
- javascript - 纯 JS json 解析与本地 JSON 文件中的许多对象
- amazon-web-services - 在 AWS ELB 应用程序负载平衡器中启用 HSTS
- android - Quickblox 组对话框加入在 android 上不起作用
- mysql - Laravel 5.6 中的控制器继承
- timer - STM32F4 定时器 - 计算周期和预分频,并产生 1 ms 延迟
- jquery - 使用 jquery 的多个复选框过滤器
- javascript - 错误:找不到模块“socket.io-client/dist/socket.io.min.js”
- iphone - 多部分/表单数据操作请求在 iPhone Liferay 7 上不起作用
- processing - 找到柏林噪声的斜率