【发布时间】:2021-06-13 19:17:53
【问题描述】:
谁能告诉我为什么 SL 没有移动,我收到错误 130(ERR_INVALID_STOPS,无效止损)并且我运行了 Print("Minimum Stop Level=", minstoplevel, " points" );在我的代码中并得到“10”并尝试运行代码,即使是 11 并且仍然存在相同的错误。
有人可以看看并告诉我,我几乎没有任何头发可以尝试所有的可能性。
非常感谢
...
//+------------------------------------------------------------------+
//| Emotality EA.mq4 |
//| Daniel Fourie |
//| https://www.emotality.com/ |
//+------------------------------------------------------------------+
#property copyright "Daniel Fourie"
#property link "https://www.emotality.com/"
#property version "1.00"
#property strict
#property script_show_inputs
extern int takeProfitPoints = 100;
extern int maxPipStopLoss = 11;
extern double volumeSize = 0.01;
extern double maxSlippageAllowed = 0.1;
int orderID;
int magicNB = 1337;
int trailingStop = 110;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit() {
//---
//---
return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick() {
// Create an empty string for the signal
string signal = "";
// Calculate the two Fractal values
double UpperFractalsValue = iFractals(NULL, PERIOD_M5, MODE_UPPER, 2);
double LowerFractalsValue = iFractals(NULL, PERIOD_M5, MODE_LOWER, 2);
// Buy Signal
//When it is going up
if (LowerFractalsValue != 0) {
if (LowerFractalsValue < Low[1]) {
signal = "buy";
}
}
//When it is going down
if (UpperFractalsValue != 0) {
if (UpperFractalsValue > High[1]) {
signal = "sell";
}
}
// If we have a buy signal and no positions
if (signal == "buy" && CheckIfOpenOrdersByMagicNB(magicNB) == false) //need to see if the argument is correct that new orders will open if other ones is open
//Send a buy order
int orderID = OrderSend(_Symbol, OP_BUY, volumeSize, Ask, maxSlippageAllowed, Ask - maxPipStopLoss, Ask + takeProfitPoints, NULL, magicNB);
int openOrders = OrdersTotal();
for (int i = 0; i < openOrders; i++) {
if (OrderSelect(i, SELECT_BY_POS) == true) {
if (OrderMagicNumber() == magicNB)
if (OrderType() == 0) {
if (UpperFractalsValue != 0) {
OrderClose(OrderTicket(), volumeSize, Ask, 5);
}
}
}
}
int newSl = Bid - NormalizeDouble(trailingStop * Point,Digits);
Print(newSl);
for (int i = 0; i < openOrders; i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderMagicNumber() == magicNB) {
if (OrderType() == 0) {
if(Bid - OrderOpenPrice() > trailingStop * Point && OrderStopLoss() < Bid - trailingStop * Point){
if(newSl < Bid) {
OrderModify(OrderTicket(), OrderOpenPrice(),newSl , takeProfitPoints, 0);
}
}
}
}
}
}
// If we have a sell signal and no positions
if (signal == "sell" && CheckIfOpenOrdersByMagicNB(magicNB) == false) //need to see if the argument is correct that new orders will open if other ones is open
//Send a sell order
int orderID = OrderSend(_Symbol, OP_SELL, volumeSize, Ask, maxSlippageAllowed, Bid + maxPipStopLoss, Bid - takeProfitPoints, NULL, magicNB);
for (int i = 0; i < openOrders; i++) {
if (OrderSelect(i, SELECT_BY_POS) == true) {
if (OrderMagicNumber() == magicNB)
if (OrderType() == 1) {
if (LowerFractalsValue != 0) {
OrderClose(OrderTicket(), volumeSize, Ask, 5);
}
}
}
}
Comment(
"Upper Fractals Value: ", UpperFractalsValue, "\n",
"Lower Fractals Value: ", LowerFractalsValue, "\n",
"The current signal is:", signal
);
}
//+------------------------------------------------------------------+
bool CheckIfOpenOrdersByMagicNB(int magicNM)
{
int openOrders = OrdersTotal();
for(int i = 0; i < openOrders; i++)
{
if(OrderSelect(i,SELECT_BY_POS)==true)
{
if(OrderMagicNumber() == magicNB)
{
return true;
}
}
}
return false;
}
//+------------------------------------------------------------------+
...
【问题讨论】:
标签: mql4