Vim as ide for mql - page 6

 
Vladimir Simakov :

Hi green, haven't seen you in ages)))) Where's your motorcade?)))

It's all good. Everything is in place.

 
Dmitry Fedoseev:

It's all good. Everything is in place.

You got it. I didn't even know such a language existed until now. Live and learn!
 

Moderator, why did you have to translate it forcibly? Just an exchange of greetings between two old friends, yes, not in Russian, but whoever is interested could translate it himself.

For those who are not on the subject: I wrote in boring English, but Dmitry really struck, he answered in the purest Telugu, I did not even know about it. But, unfortunately, ran a moderator))).

Just kidding.

 
Vladimir Simakov:

Moderator, why did you have to translate it forcibly? Just an exchange of greetings between two old friends, yes, not in Russian, but whoever is interested could translate it himself.

For those who are not on the subject: I wrote in boring English, but Dmitri really struck, he answered in pure Telugu, which I did not even suspect. But, unfortunately, a moderator came running)))

Just kidding.

Need to write out a medal at least. Probably waiting for someone to call him into the office and give him a certificate in front of everyone!


 
Vitaly Muzichenko:

Well, there is nothing new, everything is in a circle: "Opened -> Melted -> Closed".

Once upon a time I worked on a monolithic construction site, just as it was a few years ago: "Assembled the formwork -> Tied the rebar -> Poured the concrete -> Stripped the formwork" and so on in circles, because no other is given :)

Why:

cPos=new CRealPosition(cParam);

This is how the position is activated,

//----------------------------------------------------
void CTradePos::RealControl(uint &mCount,double &mProfit){
   if (cPos.Control(mProfit)){
      if (!cFlag.Check(TRADE_POS_FLAG_ACTIVE)&&cPos.IsActivate()){
         if (!cParam.isExtraLimit) ++mCount;
         cFlag+=TRADE_POS_FLAG_ACTIVE_ON;}}
   else{
      if (!cParam.isExtraLimit&&cFlag.Check(TRADE_POS_FLAG_ACTIVE)) --mCount;
      cFlag+=TRADE_POS_FLAG_STOP_TRADE;
      if (cPos.IsTPClosed()) cFlag+=TRADE_POS_FLAG_STOP_TP;
      DELETE(cPos);}}

And this is how it is accompanied. And this is mql5, on mql4 the code would be identical. CRealPosition is:

#include <MyMQLLib\Objects\Trade\CPosition.mqh>
#include "CTPTral.mqh"

class CRealPosition:public CPosition
  {
   CTPTral*          cTPTral;
   double            cControlSL;
public:
                     CRealPosition(SOrderParam &mParam);
                    ~CRealPosition() {DEL(cTPTral);}
   bool              Control(double &mProfit);
   bool              CheckChangeSL();
   void              SetNewStops(double mSL,double mTP);
   void              TPTralSet(double mStep,double mPrice,double mTPDelta);
   int               GetSLPoint()   {return !_sl?0:int(MathRound(MathAbs((_price-_sl)/_point)));}
  };

...

void CRealPosition::CRealPosition(SOrderParam &mParam):
   CPosition(_Symbol,
             mParam.type,
             mParam.volume,
             mParam.price,
             mParam.sl,
             mParam.tp,
             0,0,0,
             mParam.comment),
   cTPTral(NULL)
   {cControlSL=cOrderSL;}
//---------------------------------------------------------------------------------------------------------
bool CRealPosition::Control(double &mProfit){
   ulong res=CPosition::Control();
   if (!(res&TRADE_FINISH)) mProfit+=GetTotalProfit();
   if (IsOpen()){
      if (cTPTral!=NULL){
         double price=TradePrice(_symbol,-_direct),
                tp=cTPTral.GetTP(price,GetTP(),_price);
         if (tp!=_tp) NewTP(tp,price);}}
   return !(res&TRADE_FINISH);}

And the CPosition is already a part of the library that accompanies a trade operation (whether it's mql4 or mql5, though the netting is not fully implemented yet) from initiation to closing.

And yes, one more thing, the enumeration of all positions that are in the grid, which is a grid operator with branched logic, is performed as follows:

#define _FIRST (mIsRevers?cTrade.End():cTrade.Begine())
#define _DELETE (mIsRevers?cTrade.Delete():cTrade.DeleteRevers())
#define _NEXT (mIsRevers?cTrade.Prev():cTrade.Next())
uint CGrid::Control(bool mIsRevers){
   double newSL=0.0;
   double trendProfit=0.0,
          oppositeProfit=0.0;
   CheckVirtualSL();
   for (CTrade* it=_FIRST;it!=NULL;){
      if (gFlag.Check(G_FLAG_CLOSE_ALL)) it=it.Close()?_DELETE:_NEXT;
      else{
         bool res=it.Control(cOpenControlCount,trendProfit,oppositeProfit);
         if (it.IsNewOppositeActivate()) ChangePrevOppositeSL(it);
         if (mIsRevers){
            if (!(cFlag&GRID_FLAG_TRAL_START)&&res) StartTral(it);
            if (it.CheckChangeTrendSL()) newSL=it.GetTrendSL();
            else if (newSL!=0.0) it.SetTrendSL(newSL);}
         else{
            if (it.IsStart()) CheckPrevTrades(it);
            if (it.IsNewTrendActivate()){
               ChangePrevTP(it);
               if (cTrade.IsLast()) 
                  cFlag|=GRID_FLAG_LAST_OPEN;}
            if (eIsXProfit&&!(cFlag&GRID_FLAG_X_START)&&res&&it.IsTrendActivate()) CheckXTrade(it);}
         it=res?_NEXT:_DELETE;}}
   if (eIsOppositOrder&&oppositeProfit>trendProfit&&oppositeProfit+trendProfit>=eVirtualTP) gFlag+=G_FLAG_CLOSE_ALL;
   if (!(cFlag&GRID_FLAG_X_START)      &&
       !(gFlag&G_FLAG_CLOSE_ALL)       &&
       bool(cFlag&GRID_FLAG_LAST_OPEN) &&
       eIsXProfit)                     StartXGrid();
   if (cXTrade!=NULL&&!cXTrade.Control()) DELETE(cXTrade);
   return cOpenControlCount.Total();}
#undef _FIRST
#undef _DELETE
#undef _NEXT
 

Another release.

1. Expecting MK to include guards into std is useless, I think. Made it myself. The idea is this - during first co-implementation (via F7 in vime) whole Include directory will be converted to utf-8 and include guard will be added to all the files (on next runs this will not work). In compile_mql (which is a bash script) there is a line at the top which specifies the subdirectories in Include, where the script does not change anything. Well the idea is to leave the user data untouched.

#!/bin/bash
#home  page - https://www.mql5.com/ru/users/vict

user_include_subdir=""
...

Possible values:

* empty (default) - function disabled (no guards added, no encoding changed)

* single directory user_include_subdir="any_dir"

* multiple directories user_include_subdir="{dir1,dir2}"

I.e. we put in this variable directories where our own header files live. For example I have

user_include_subdir="myincl"

and in all mqh in ~/.wine/MQL5/Include/myincl and subdirectories will not be added. Now you can plug std headers in the usual way + clang will give type hints from there.

ZS: link to the latest version in the profile


#vim_as_mql_ide_2

Files:
 
Vict:

Another release.

1. Expecting MK to include guards into std is useless, I think. Made it myself. The idea is this - during first co-implementation (via F7 in vime) whole Include directory will be converted to utf-8 and include guard will be added to all the files (on next runs this will not work). In compile_mql (which is a bash script) there is a line at the top which specifies the subdirectories in Include, where the script does not change anything. Well the idea is to leave the user data untouched.

Possible values:

* empty (default) - function disabled (no guards added, no encoding changed)

* single directory user_include_subdir="any_dir"

* multiple directories user_include_subdir="{dir1,dir2}"

I.e. we put in this variable directories where our own header files live. For example I have

and in all mqh in ~/.wine/MQL5/Include/myincl and subdirectories will not be added. Now you can plug std headers in the usual way + clang will give type hints from there.

ZS: link to the latest version in the profile


#vim_as_mql_ide_2

Garda inlude in std in vim with headings and type prompts. I'm being smartly silent and reflecting.))) An idea struck me - maybe the MCs just do not know what it's about?))) Users want something, but what - do not know ... So they don't.))). You explain in popular Russian what you mean and maybe do it.)
 
Vict:

Another release.


the only thing left is to screw in m4 preprocessor and get ex4/5 from a unique vinigrette :-)

the solution is not portable (without matte at least) even between a pair of linux+wine+metatrader kits. The resulting source code will be nailed to the IDE as vim/clang.

 
Maxim Kuznetsov:

The solution is not portable (without matte, at least) even between a pair of linux+wine+metatrader packages. The resulting source code will be nailed to the IDE as vim/clang.

No, the requirements are only "~/.wine/drive_c/Program Files/MetaTrader 5" and a link to MQL5. Is it a nail? And I was too hasty, I could only require MQL5 link in the right place (I may finish it).

The compile_mql is a standard bash script, you can view/edit it. As a last resort, run sed commands with lines 68-70 (in release 2) over the sources and get back code suitable for metaeditor.

And in general, your questions are wrong, more interesting others - I've made ide with all goodies and much higher quality than meta editor (well, the same autocomplit templates, ME still can not do it and according to Renat it is difficult, childish preprocessor, and functionality vim generally higher order) on which worked the whole team of coders and not the first year and for a decent fee. You can even change the entire µl compiler to clang. Yes, efficient private business, everyone pretends to be important activities, but in fact the wheel is reinvented.

And let me tell a secret - I don't count on millionth audience, if a couple of geeks will use it, it's not bad. The rest will continue to pray to the MC, obediently put ampersands in front of arrays and dereferencing through a point.

 
Vict:

No, the requirements are only "~/.wine/drive_c/Program Files/MetaTrader 5" and a link to MQL5. Is it a nail? And I was too hasty, I could only require MQL5 link in the right place (maybe I'll finish it).

The compile_mql is a standard bash script, you can view/edit it. As a last resort, run sed commands with lines 68-70 (in release 2) over the sources and get back code suitable for metaeditor.

And in general, your questions are wrong, more interesting others - I've made ide with all goodies and much higher quality than meta editor (well, the same autocomplit templates, ME still can not do it and according to Renat it is difficult, childish preprocessor, and functionality vim generally higher order) on which worked the whole team of coders and not the first year and for a decent fee. You could even change the entire µl compiler to clang. Yes, efficient private business, everyone pretends to be important activities, but in fact they reinvent the wheel.

Well, I'll tell a secret - I don't count on millionth audience, if a couple of geeks will use it, it's not bad. The rest will continue to pray to MC, obediently put ampersands in front of arrays and dereferencing.

If I got it right, it is still desirable to put guard`s and there are still special requirements to the code ?

On the one hand it is good - why not? I myself build projects with more than 2 files through make :-)

No offence - it's not a critique for the sake of it, it's a discussion

PS/ here 9 out of 10 will not be able to "exit VIM" willingly, except for powering down :-)