Errors, bugs, questions - page 770

 
maryan.dirtyn:
...

p.s. those who tell me to use standard libraries please don't bother, I like to know what my expert is doing and not hope it doesn't flatten out later

At least the standard libraries can be viewed/studied and you can understand what mistakes have been made. A very good opportunity.
 

I've been trying to do this for the last 6 hours and I'm inclined to think it's impossible

I won't use any of the standard ones, if you'll excuse me...

 
maryan.dirtyn:

I've been trying to do this for the last 6 hours and I'm inclined to think it's impossible

I won't use anything standard, if you'll excuse me...

What is it about standard libraries that scares you so much? Look what is in the file Trade.mqh:

Function to open a position:

//+------------------------------------------------------------------+
//| Open position.                                                   |
//+------------------------------------------------------------------+
bool CTrade::PositionOpen(const string symbol,const ENUM_ORDER_TYPE order_type,const double volume,
                          const double price,const double sl,const double tp,const string comment)
  {
//--- check stopped
   if(IsStopped(__FUNCTION__)) return(false);
//--- clean
   ClearStructures();
//--- checking
   if(order_type!=ORDER_TYPE_BUY && order_type!=ORDER_TYPE_SELL)
     {
      m_result.retcode=TRADE_RETCODE_INVALID;
      m_result.comment="Invalid order type";
      return(false);
     }
//--- setting request
   m_request.action      =TRADE_ACTION_DEAL;
   m_request.symbol      =symbol;
   m_request.magic       =m_magic;
   m_request.volume      =volume;
   m_request.type        =order_type;
   m_request.price       =price;
   m_request.sl          =sl;
   m_request.tp          =tp;
   m_request.deviation   =m_deviation;
   m_request.type_filling=m_type_filling;
   m_request.comment     =comment;
//--- action and return the result
   return(OrderSend(m_request,m_result));
  }

//---

You should agree that it is not that much different from what you are trying to do. Pay attention to function ClearStructures(). If the stops need to be set after the position has been opened, then the following function will help you with this:

//+------------------------------------------------------------------+
//| Modify specified opened position.                                |
//+------------------------------------------------------------------+
bool CTrade::PositionModify(const string symbol,const double sl,const double tp)
  {
//--- check stopped
   if(IsStopped(__FUNCTION__)) return(false);
//--- clean
   ClearStructures();
//--- setting request
   m_request.action=TRADE_ACTION_SLTP;
   m_request.symbol=symbol;
   m_request.sl    =sl;
   m_request.tp    =tp;
//--- action and return the result
   return(OrderSend(m_request,m_result));
  }

//---

It is simple and everything works. And then you can add/change/experiment as you see fit.

Документация по MQL5: Стандартная библиотека
Документация по MQL5: Стандартная библиотека
  • www.mql5.com
Стандартная библиотека - Документация по MQL5
 
maryan.dirtyn:

I've been trying to do this for the last 6 hours and I'm inclined to think it's impossible

I won't use any of the standard ones, if you'll excuse me...

Especially for you:

#include <trade\trade.mqh>
void OnStart()
  {
   CTrade trade;
   trade.Buy(1.0,"EURUSD",SymbolInfoDouble("EURUSD",SYMBOL_ASK),1.20000,1.50000,"Yeah, baby!");
  }

To touch the unknown, simply insert this code into the script, compile, and then put the cursor on Buy and press Alt + G.

You will start to travel through the innards of all libraries. At the same time look at error handling.

 
Renat:

Especially for you:

To touch the unknown, simply insert this code into the script, compile it, then place the cursor on Buy and press Alt+G.

You will start to travel through the innards of all libraries. At the same time look at error handling.


"Yeah, baby!"
You can even voice the above and everything will be fine. )))
 

I take it there is no other way to do this, is there?

#include <trade\trade.mqh>
 
maryan.dirtyn:

I take it there is no other way to do this, is there?

Make similar function(s) in the main file and you don't need to plug anything in.
 

That's what I'm doing))... 6th hour... and I can't figure out where the error is

the reluctance to use standard libraries is due to the fact that flags and global variables are used within functions, and it doesn't seem reasonable to take apart trade.mqh and other parts

void OnTick(){ if(PositionsTotal()<1){OPEN();}}

bool OPEN(){
             MqlTradeRequest request; ZeroMemory(request);
             MqlTradeResult  result;  ZeroMemory(result);
             

             request.symbol       = _Symbol;
             request.action       = TRADE_ACTION_DEAL;
             request.type_filling = ORDER_FILLING_FOK;
             request.deviation    = 100;
             request.volume       = NormalizeDouble(2,2);
             request.type         = ORDER_TYPE_BUY;
             request.price        = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
             request.tp           = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK) + 500*_Point,_Digits);
             request.sl           = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK) - 500*_Point,_Digits);

             OrderSend(request,result);     
                        
             if(result.retcode==10009 || result.retcode==10008)  Print("Succsesful open");
             else                                               Print("Error open: ",DoubleToString(GetLastError(),0),"  response code: ",result.retcode);
    
   return(true);}
 
maryan.dirtyn:

That's what I'm doing))... 6th hour... and I can't figure out where the error is

I don't want to use standard libraries because flags and global variables are used within functions, and it doesn't seem reasonable to break down trade.mqh and other functions by parts

On what server and what symbol are you trying?

I ran your code on MetaQuotes-Demo and the transaction was successful:

2012.07.11 15:08:36     Trades  '1026582': deal #109507221 buy 2.00 EURUSD at 1.22625 done (based on order #115678901)
2012.07.11 15:08:36     Trades  '1026582': order #115678901 buy 2.00 / 2.00 EURUSD at 1.22625 done
2012.07.11 15:08:36     Trades  '1026582': instant buy 2.00 EURUSD at 1.22627 sl: 1.22127 tp: 1.23127 (deviation: 100)
 

MetaQuotes-Demo

Login: 1219233

EURUSD

I have just tried it on the pound, same story. no stops. i do everything in the tester

Build 655 (if it helps)