ATcl - Tcl interpreter for MT4 - page 6

 
Maxim Kuznetsov:

In terms of software technology, potentially yes. Libraries can be called from the optimizer as long as it is not in the cloud.

on the NS side - how do you envisage this ?

In the optimizer a pass is made and data is written to the file, then it is passed to the network training, after training the results of training evaluation are returned to MT4/5 and the network (rules) is written to the file. And the other view is when we use the recorded files of NS logic to conduct optimization (of the NS variants) and fix standard indicators of TS.

 

I extended the Tk chart demo - now it shows the table of orders as well.

Table of orders in a separate window

The MQL code that refers to the table of orders
- selects all of its orders and sends them to tcl in the OnOrderList method
- in the output we get 3 ticket lists - the ones that are new, the ones that changed and the ones that were deleted

void
SendOrderList() 
{
   int total=OrdersTotal();
   Tcl_Obj list=tcl.Ref(tcl.Obj()); // пустой список
   for(int pos=0;pos<total;pos++) {
      if (!OrderSelect(pos,SELECT_BY_POS,MODE_TRADES) ||
         OrderMagicNumber()!=MAGIC ||
         OrderSymbol()!=_Symbol ||
         OrderCloseTime()!=0) continue;
      Tcl_Obj ord=tcl.Ref(tcl.List(
         tcl.Obj(OrderTicket()),
         tcl.Obj(OrderType()),
         tcl.Obj(OrderOpenTime()),
         tcl.Obj(OrderSymbol()),
         tcl.Obj(OrderLots()),
         tcl.Obj(OrderOpenPrice()),
         tcl.Obj(OrderStopLoss()),
         tcl.Obj(OrderTakeProfit()),
         tcl.Obj(OrderComment()),
         tcl.Obj(OrderSwap()),
         tcl.Obj(OrderCommission())
      ));
      tcl.AppendObj(list,ord);
      tcl.Unref(ord);
   }
   if (tcl.Call(panel,methodOnOrderList,list)!=TCL_OK) {
      PrintFormat("OrderSendList failed : %s",tcl.StringResult());
   } else {
      Tcl_Obj triplet=tcl.Ref(tcl.Result()); // 0-новые 1-изменённые 2-удалённые
      Tcl_Obj created=tcl.Ref(tcl.Index(triplet,0));  // список новых ордеров
      Tcl_Obj changed=tcl.Ref(tcl.Index(triplet,1));  // список изменённых ордеров
      Tcl_Obj removed=tcl.Ref(tcl.Index(triplet,2));  // список удалённых ордеров
      PrintOrderList("New orders",created);
      PrintOrderList("Modified orders",changed);
      PrintOrderList("Deleted orders",removed);
      // объекты больше ненужны
      tcl.Unref(removed);
      tcl.Unref(changed);
      tcl.Unref(created);
      tcl.Unref(triplet);
   }
}

and the Tcl method that does the main work :
- gets a new list of orders
- compare with previous calls
- builds 3 lists (new, changed, deleted).
- it creates a table ...which actually is a tree and can be made in several levels.


# надо обновить внутренние структуры
# и вернуть триплет (список из трёх списков)
#   1 - список новых ордеров
#   2 - ордера которые поменялись
#    3 - ордера которые удалены
method OnOrderList { orderList } {
    set created {}
    set changed {}
    set removed {}
    foreach order $orderList {
        set ticket [ lindex $order 0 ]
        set known($ticket) $order
        if { ! [ info exists Orders($ticket) ] } {
            # новый тикет
            # добавить в список свежесозданных
            lappend created $ticket
            set Orders($ticket) $order
            continue
        }
        if { $Orders($ticket) != $order } {
            # что-то поменялось
            # добавить в список изменённых
            set Orders($ticket) $order
            lappend changed $ticket
        }
    }
    foreach ticket [ array names Orders ] {
        if { ! [ info exists known($ticket) ] } {
            # прежнего ордера нет в новом списке - значит удалён
            lappend removed $ticket
            unset Orders($ticket)
        }
    }
    # обновить грфику :-)
    foreach ticket $removed {
        my OnRemoveOrder $ticket
    }
    foreach ticket $changed {
        my OnChangeOrder $ticket
    }
    foreach ticket $created {
        my OnCreateOrder $ticket
    }
    return [ list $created $changed $removed ]
}

everything is very compact.
You can use the strengths of both languages - MQL is close to the trading environment and counts quickly in arrays,
Tcl can easily handle lists and hashes.
MQL implements a tough trading algorithm while scripts handle interaction with the world and the user.

The archive is attached.

Files:
atcl.zip  6662 kb
 

A script to export quotes to Excel

I made a short script to export quotes directly to Excel.
Without any entries in CSV or any parameters at all - just throw it on the chart, the Excel sheet will open and all the quotes will be copied into it.

I have commented the text as much as possible and attached it. I have provided the details of the script on my website http://nektomk.ru/atcl:ratestoexcel.
The volume goes beyond the forum, so there. Maybe when I'm in the mood I'll duplicate it in the local blog so that the information was not lost for sure.

The script attached

PS/ Does anybody have a make - file for batch compilation of mql ? that will change one mqh, push make and rebuild a bunch of mq4 that are listed in dependencies...

update/ duplicated the article on the local blog https://www.mql5.com/ru/blogs/post/718304 - now it probably won't go away
RatesToExcel
  • nektomk.ru
Часто возникающий (и довольно практичный) вопрос у пользователей MetaTrader - «Как скопировать котировки в Excel?» . При помощи библиотеки ATcl это программируется довольно легко. В состав библиотеки входит «большая» программа работающая с Excel, но для частых потребностей сделал короткий скрипт, который делает самую простую вещь - экспорт...
Files:
 

The mailer works, but it still needs more work to be done...

In the meantime, a question for people - will the GUI-Builder be in demand?
for Tk, they are there, but because of the fact that scripts in text write faster than in draw, they are little in demand.

something like this :

PS/ the result of such GUI-builder can be started from MT4...

 
Maxim Kuznetsov:

the mailer works, but it still needs more work to be done...

but meanwhile a question for people - will there be a demand for GUI-Builder ?
for Tk they are, but due to the fact that scripts are faster to write in text than in drawing they are not much in demand.

something like this :

PS/ The result of such a GUI-builder and now with the help of "such and such a mother" can be run from MT4...

What interesting stuff... only how to apply them?

Ah, I have an idea for just graphical interfaces - creating trading logic like a decision tree! That is, create a tree in the graphical editor (i.e. shell) and use a button to convert it into simple rules, or even directly into code! However, rules can also be read in code in a very compact manner.

Why do we need it? This approach allows detailing the trading strategy, for example, we can easily divide it into time series - not only deciding whether to trade or not, but also whether to trade in this time and at this time in a different manner. Signs of a change of tactics are many and various, but it is not very convenient to write it in the code and secondly, it is difficult to read visually - you can make a lot of mistakes.

Interested in such an idea to apply your talents?

 
Aleksey Vyazmikin:

What interesting stuff... but how to apply them?

Ah, I have an idea for just graphical interfaces - creating trading logic like a decision tree! I.e. we create a tree in the graphical editor (i.e. shell) and use a button to convert it into simple rules or even directly into code! However, rules can also be read in code in a very compact manner.

Why do we need it? This approach allows detailing the trading strategy, for example, we can easily divide it into time series - not only deciding whether to trade or not, but also whether to trade in this time and at this time in a different manner. Signs of a change of tactics are many and various, but it is not very convenient to write it in the code and secondly, it is difficult to visually read - you can make a lot of mistakes.

Interested in such an idea for an application of your talents?

I don't understand the idea of a "graphical decision tree". :-) maybe your talent isn't enough :-)

 
Maxim Kuznetsov:

I don't get the "graphical decision tree" idea at all :-) maybe you're not talented enough :-)

Imagine a data table with a set of rules



These rules are arranged in code in the following way

      for(int i=1;i<StrokTotal_Buy; i++)
        {
         UslovieSumm_Buy=
                          Sravnenief(arr_Vektor_Week,arrRead_Buy_01[i])+
                          Sravnenief(arr_Vektor_Day,arrRead_Buy_02[i])+
                          Sravnenief(arr_Vektor_Don,arrRead_Buy_03[i])+
                          Sravnenief(arr_DonProc,arrRead_Buy_04[i])+
                          Sravnenief(arr_iDelta_H1,arrRead_Buy_05[i])+
                          Sravnenief(arr_iDelta_H3,arrRead_Buy_06[i])+
                          Sravnenief(arr_iDelta_H4,arrRead_Buy_07[i])+
                          Sravnenief(arr_iDelta_H6,arrRead_Buy_08[i])+
                          Sravnenief(arr_iDelta_H12,arrRead_Buy_09[i])+
                          Sravnenief(arr_iDelta_D1,arrRead_Buy_10[i])+
                          Sravnenief(arr_iDelta_W1,arrRead_Buy_11[i])+
                          Sravnenief(arr_iDelta_MN1,arrRead_Buy_12[i])+
                          Sravnenief(arr_RSI_Open_M1,arrRead_Buy_13[i])+
                          Sravnenief(arr_RSI_Open_H1,arrRead_Buy_14[i])+
                          Sravnenief(arr_BB_Center_Open,arrRead_Buy_15[i])+
                          Sravnenief(arr_BB_Up_Open,arrRead_Buy_16[i])+
                          Sravnenief(arr_BB_Down_Open,arrRead_Buy_17[i])+
                          Sravnenief(arr_TimeH,arrRead_Buy_18[i])+
                          Sravnenief(arr_Den_Nedeli,arrRead_Buy_19[i])+
                          Sravnenief(arr_iDelta_Max_H1,arrRead_Buy_20[i])+
                          Sravnenief(arr_iDelta_Min_H1,arrRead_Buy_21[i])+
                          Sravnenief(arr_iDelta_Max_D1,arrRead_Buy_22[i])+
                          Sravnenief(arr_iDelta_Min_D1,arrRead_Buy_23[i]);                                                                              
;




         if(UslovieSumm_Buy==23)
           {
            Pattern_Buy=1;
            Pravilo_Buy=i;
            break;
           }
        }

If we have a rule value and a calculated value (indicator value/time/other pattern) coincide, then a trade action is performed, for example.

This method of trading decisions is very compact and versatile - we can code in such a simple way, for example, many strategies - giving them different magic symbols.

But the catch is that we need just the environment for such style of programming. This environment should look like a decision tree (a primitive block diagram) where we can create blocks (calculation result for examplearr_iDelta_Max_D1 with predefined values (1,2,3,4 ...n) and/or with possibility to limit values from and to, creating many different groups this way), from this block will branch for each value of variable or range of values of variable, and so on till next block and so on. Thus, we will have a set of rules, each of which, by the way, doesn't have to use all blocks.

Does this make you understand? If you need explanations, please ask.

 
Aleksey Vyazmikin:

Present a data table with a set of rules



These rules are coded as follows

If we have a coincidence of the rule values and calculated values (indicator value/time/other pattern), then, for example, a trade action is performed.

This method of trading decisions is very compact and versatile - we can code in such a simple way, for example, many strategies - giving them different magic symbols.

But the catch is that we need just the environment for such style of programming. This environment should look like a decision tree (a primitive block diagram) where we can create blocks (calculation result for examplearr_iDelta_Max_D1 with predefined values (1,2,3,4 ...n) and/or with possibility to limit values from and to, creating many different groups this way), from this block will branch for each value of variable or range of values of variable, and so on till next block and so on. Thus, we will have a set of rules, each of which, by the way, doesn't have to use all blocks.

Does this make you understand? If you need explanations, please ask.

Like Xcos (http://www.scilab.org/en/scilab/features/xcos) and similar fancy ones in simulations ?
I've seen it in tcl - an environment where they connect blocks with arrows... that's how they programmed sound/video/graphics processing. http://wiki.tcl.tk/8565 seems to be a lot of stuff, they even stuck Maxima in some block
If it is - will pay close attention
Xcos / Features / Scilab / Home - Scilab
Xcos / Features / Scilab / Home - Scilab
  • Scilab Enterprises
  • www.scilab.org
Xcos is a graphical editor to design hybrid dynamical systems models. Models can be designed, loaded, saved, compiled and simulated.
 
Maxim Kuznetsov:
Like Xcos (http://www.scilab.org/en/scilab/features/xcos) and similar fashionable in simulations ?
I've seen it in tcl - environment where they connect the blocks with arrows... that's how they programmed the sound/video/graphics processing. http://wiki.tcl.tk/8565 seems to be a lot of things, they even stuck Maxima into some block
If it is - will pay close attention

Yes, this is the approach! The main thing is not to complicate things, and to make a correct interpreter, so that all blocks are collected in one line (one branch), with which the program in MQL will already work.

 
Aleksey Vyazmikin:

Yes, this is the approach! The main thing is not to complicate things, and to make a correct interpreter, so that all blocks are collected in one line (one branch), which will already work with the program in MQL.

I don't think I want to overcomplicate, e.g. I don't want to mess with bwise code.

At most, I'll adapt it for using together with ATcl (i.e. transfer data from Mql to its inputs) and take the outputs.
Of course, I will have to write some HowTo "how to draw squares and attach them to EA". And practice English when communicating with the author(s) :-)

Reason: