Who can help with the robot, why isn't it working? - page 6

 
So what's the fault, at least show me?
 

here is my function for mt4 ecn, ndd, stp ...

Not a single error in a year

//+----------------------------------------------------------------------------+

//| Order opening function (BeerGod) |

//+----------------------------------------------------------------------------+

//| Parameters: |

//| sy - instrument name ("" - current symbol) |

//| op - operation |

| //| ll - lot |

//| sl - stop level |

//| tp - take level |

//| mn - MagicNumber |

//+----------------------------------------------------------------------------+


bool OpenPosition(string sy, int op, double ll, double sl=0, double tp=0, int MagicNumber=0)

{

double MinLl = MarketInfo(Symbol(),MODE_MINLOT);

double MaxLl = MarketInfo(Symbol(),MODE_MAXLOT);

ll = NormalizeDouble(ll,2);

if (ll < MinLl) ll = MinLl; else ll = ll;

if (ll > MaxLl) ll = MaxLl; else ll = ll;

if (op == 0) // BUY opening

{

// Check if free funds are available

if((AccountFreeMarginCheck(sy,OP_BUY,ll)<=0) || (GetLastError()==134))

{

Print(sy," ",ll," It is impossible to open the order Buy, not enough money.");

return(0);

}

RefreshRates();


// Open order

int ticketbuy = OrderSend(sy,OP_BUY,ll,MarketInfo(sy,MODE_ASK),Slippage,0,0,Comments,MagicNumber,0,BuyColor);

if(ticketbuy<0)

Print(sy," OpenPosition. OrderSend Buy fail #",GetLastError());

else

Print(sy," OpenPosition. OrderSend Buy successfully");


// Sleep (Pause);


// Modify the order (set take profit and stop loss)

if (sl !=0 || tp !=0)

{

//--- Calculated SL and TP prices must be normalized

double BSLoss = NormalizeDouble(MarketInfo(sy,MODE_ASK)-sl*MarketInfo(sy,MODE_POINT),(int)MarketInfo(sy,MODE_DIGITS))

double BTProfit = NormalizeDouble(MarketInfo(sy,MODE_ASK)+tp*MarketInfo(sy,MODE_POINT),(int)MarketInfo(sy,MODE_DIGITS));

//--- If the input value is zero, replace the modification price with zero

if (sl == 0) BSLoss = 0;

if (tp == 0) BTProfit = 0;


bool resbuy = OrderModify (ticketbuy,OrderOpenPrice(),BSLoss,BTProfit,0,StopColor);

if(!resbuy)

Print(sy," OpenPosition. OrderModify Buy fail #",GetLastError());

else

Print(sy," OpenPosition. OrderModify Buy successfully");

}

}


if (op == 1) // Open Sell.

{

// Check availability of free funds

if((AccountFreeMarginCheck(sy,OP_SELL,ll)<=0) || (GetLastError()==134))

{

Print(sy," ",ll," It is impossible to open the order Sell, not enough money.");

return(0);

}

RefreshRates();


// Open order

int ticketsell = OrderSend(sy,OP_SELL,ll,MarketInfo(sy,MODE_BID),Slippage,0,0,Comments,MagicNumber,0,SellColor);

if(ticketsell<0)

Print(sy," OpenPosition. OrderSend Sell fail #",GetLastError());

else

Print(sy," OpenPosition. OrderSend Sell successfully");


// Sleep (Pause);


// Modify the order (set take profit and stop loss)

if (sl !=0 || tp !=0)

{

//--- The calculated SL and TP prices must be normalized

double SSLoss = NormalizeDouble(MarketInfo(sy,MODE_BID)+sl*MarketInfo(sy,MODE_POINT),(int)MarketInfo(sy,MODE_DIGITS))

double STProfit = NormalizeDouble(MarketInfo(sy,MODE_BID)-tp*MarketInfo(sy,MODE_POINT),(int)MarketInfo(sy,MODE_DIGITS));

//--- If the input value is zero, replace the modification price with zero

if (sl == 0) SSLoss = 0;

if (tp == 0) STProfit = 0;


bool ressell = OrderModify (ticketsell,OrderOpenPrice(),SSLoss,STProfit,0,StopColor);

if(!ressell)

Print(sy," OpenPosition. OrderModify Sell fail #",GetLastError());

else

Print(sy," OpenPosition. OrderModify Sell successfully");

}

}

return(True);

}

//End

 
P.S. Moderators, the code cannot be inserted through the button.
 
Vladimir Zubov:
P.S. Moderators, the code cannot be inserted via the button.

I'm giving free (no charge) online Skype lessons on code insertion:)

 if (sl == 0) SSLoss = 0;
 
Karputov Vladimir:

I give free (no charge) online Skype lessons on code insertion:)

//+----------------------------------------------------------------------------+
//|    Функция открытия ордера  (BeerGod)                                      |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   ("" - текущий символ)                   |
//|    op - операция                                                           |
//|    ll - лот                                                                |
//|    sl - уровень стоп                                                       |
//|    tp - уровень тейк                                                       |
//|    mn - MagicNumber                                                        |
//+----------------------------------------------------------------------------+

bool OpenPosition(string sy, int op, double ll, double sl=0, double tp=0, int MagicNumber=0)
{
   double MinLl = MarketInfo(Symbol(),MODE_MINLOT);
   double MaxLl = MarketInfo(Symbol(),MODE_MAXLOT);
   ll = NormalizeDouble(ll,2);
   if (ll < MinLl) ll = MinLl; else ll = ll;
   if (ll > MaxLl) ll = MaxLl; else ll = ll;
   
   if (op == 0) // Открытие BUY
   {
      // Проверяем доступность свободных средств
      if((AccountFreeMarginCheck(sy,OP_BUY,ll)<=0) || (GetLastError()==134))
            {
               Print(sy," ",ll," It is impossible to open the order Buy, not enough money.");
               return(0);
            }
      RefreshRates();

      // Открываем ордер
      int ticketbuy = OrderSend(sy,OP_BUY,ll,MarketInfo(sy,MODE_ASK),Slippage,0,0,Comments,MagicNumber,0,BuyColor);
         if(ticketbuy<0)
         Print(sy," OpenPosition. OrderSend Buy fail #",GetLastError());
         else
         Print(sy," OpenPosition. OrderSend Buy successfully");

      // Sleep (Pause);

      // Модифицируем ордер (выставляем тейкпрофит и стоплосс)
      if (sl !=0 || tp !=0)
            {
            //--- Вычисленные значения цен SL и TP должны быть нормализованы
            double BSLoss = NormalizeDouble(MarketInfo(sy,MODE_ASK)-sl*MarketInfo(sy,MODE_POINT),(int)MarketInfo(sy,MODE_DIGITS));
            double BTProfit = NormalizeDouble(MarketInfo(sy,MODE_ASK)+tp*MarketInfo(sy,MODE_POINT),(int)MarketInfo(sy,MODE_DIGITS));
            //--- Если входящие значения ноль то заменяем цену модификации на ноль
            if (sl == 0) BSLoss = 0;
            if (tp == 0) BTProfit = 0;

            bool resbuy = OrderModify (ticketbuy,OrderOpenPrice(),BSLoss,BTProfit,0,StopColor);
                  if(!resbuy)
                     Print(sy," OpenPosition. OrderModify Buy fail #",GetLastError());
                  else
                     Print(sy," OpenPosition. OrderModify Buy successfully");
            }
   }

   if (op == 1) // Открытие Sell
   {
      // Проверяем доступность свободных средств
      if((AccountFreeMarginCheck(sy,OP_SELL,ll)<=0) || (GetLastError()==134))
            {
               Print(sy," ",ll," It is impossible to open the order Sell, not enough money.");
               return(0);
            }
      RefreshRates();

      // Открываем ордер
      int ticketsell = OrderSend(sy,OP_SELL,ll,MarketInfo(sy,MODE_BID),Slippage,0,0,Comments,MagicNumber,0,SellColor);
         if(ticketsell<0)
         Print(sy," OpenPosition. OrderSend Sell fail #",GetLastError());
         else
         Print(sy," OpenPosition. OrderSend Sell successfully");

      // Sleep (Pause);

      // Модифицируем ордер (выставляем тейкпрофит и стоплосс)
      if (sl !=0 || tp !=0)
            {
            //--- Вычисленные значения цен SL и TP должны быть нормализованы
            double SSLoss = NormalizeDouble(MarketInfo(sy,MODE_BID)+sl*MarketInfo(sy,MODE_POINT),(int)MarketInfo(sy,MODE_DIGITS));
            double STProfit = NormalizeDouble(MarketInfo(sy,MODE_BID)-tp*MarketInfo(sy,MODE_POINT),(int)MarketInfo(sy,MODE_DIGITS));
            //--- Если входящие значения ноль то заменяем цену модификации на ноль
            if (sl == 0) SSLoss = 0;
            if (tp == 0) STProfit = 0;

            bool ressell = OrderModify (ticketsell,OrderOpenPrice(),SSLoss,STProfit,0,StopColor);
                  if(!ressell)
                     Print(sy," OpenPosition. OrderModify Sell fail #",GetLastError());
                  else
                     Print(sy," OpenPosition. OrderModify Sell successfully");
            }
   }
return (True);
}
//End
 
Karputov Vladimir:

I give free (no charge) online Skype lessons on code insertion:)

If I just paste the code, yes, but if I write more, the code disappears
 
There is an error somewhere, when calculating PHP & MQL, if you need assembler then help.
 
GIM:
Thank you!

Done, if you have any questions about the code write, also available in person or on Skype

Files:
GIM.mq4  9 kb
 
Sergey Gritsay:

ready, if you have any questions about the code, email or Skype

Alert comes out with the message: No prices. Waiting for new tick...
 
GIM:
The Alert comes out with the message: No price. We wait for new tick...

I had a demo account that worked fine and opened a trade on the first try. I need more details.