Utility "Tracert.mqh"

 
Hi .
Small and usefull utility for visual analys worked orders after completed back-testing.
Manual:

1. Put this file Tracert.mqh in folder experts\include\
2. Add in code of expert the line #include <Tracert.mqh>
#property copyright "Rosh, conversed only"
#property link      "http://*****************"
#include <stdlib.mqh>
#include <Tracert.mqh>
extern double TakeProfit = 200;
extern double Lots = 0.1;
extern double TrailingStop = 0;
extern double StopLoss = 65;



3. Add function SetTrace(); in block start()

int start()
   {
   int ticket, total,totalExpert; 
   //------------------------------------------------------
   // For the sake of simplification and acceleration of a code,
   // we shall keep the necessary data of indicators in time variables


   SetTrace();



4. After back-testing click "Open Chart" - must be like this:



Code:

//+------------------------------------------------------------------+
//|                                                      Tracert.mq4 |
//|                                                             Rosh |
//|                           http://forexsystems.ru/phpBB/index.php |
//+------------------------------------------------------------------+
#property copyright "Rosh"
#property link      "http://forexsystems.ru/phpBB/index.php"

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
double tr_AOPLong,tr_AOPShort;
double tr_LongLots,tr_ShortLots;
int tr_CurrLongOrders,tr_CurrShortOrders;
int tr_Total,tr_Counter;
int tr_PrevLongOrders,tr_PrevShortOrders;
int tr_CurrTotalOpenedOrders,tr_PrevTotalOpenedOrders;
double tr_CurrBalance,tr_PrevCurrBalance;
color tr_ProfitColor=Lime, tr_LossColor=DeepPink,tr_LongAOPColor=Blue,tr_ShortAOPColor=Red, tr_CurrCloseColor;
int tr_CloseLabelArrow=108, tr_AOPLabelArrow=159;
bool tr_CloseLong,tr_CloseShort;
double tr_CloseLabelPrice;
int tr_CloseLabelShift=20;
int tr_CounterCloseLabel=0,tr_CounterAOPLabel=0;
int tr_Bars;

void SetTrace()
  {
//---- 
   if (IsTesting()&&(tr_Bars!=Bars))
      {
      tr_CloseLong=false;
            tr_CloseShort=false;
      tr_AOPLong=0.0;
      tr_AOPShort=0.0;
      tr_LongLots=0.0;
      tr_ShortLots=0.0;
      tr_CloseLabelShift=iATR(NULL,0,50,1)*3.0/10.0/Point;
      if (tr_CurrBalance==0.0)   
         {
         tr_CurrBalance=AccountBalance();
         tr_PrevCurrBalance=AccountBalance();
         }
//----------------Проверка открытых позиций ---------------------------
      tr_CurrLongOrders=0;
      tr_CurrShortOrders=0;
      tr_CurrTotalOpenedOrders=0;
      tr_Total=OrdersTotal();
      if (tr_Total>0)// есть открытые позиции
         {
         for (tr_Counter=0;tr_Counter<tr_Total;tr_Counter++)// Counting of open positions
            {
            OrderSelect(tr_Counter, SELECT_BY_POS, MODE_TRADES);
            if (OrderType()==OP_BUY) 
               {
               tr_CurrLongOrders++;
               tr_AOPLong=tr_AOPLong+OrderLots()*OrderOpenPrice();
               tr_LongLots=tr_LongLots+OrderLots();
               }
            if (OrderType()==OP_SELL) 
               {
               tr_CurrShortOrders++;
               tr_AOPShort=tr_AOPShort+OrderLots()*OrderOpenPrice();
               tr_ShortLots=tr_ShortLots+OrderLots();
               }
            }// Counting of open positions


            //---------------  Averaging ---------------------
            
         if (tr_CurrLongOrders>0) tr_AOPLong=tr_AOPLong/tr_LongLots;
         if (tr_CurrShortOrders>0)tr_AOPShort=tr_AOPShort/tr_ShortLots;
            
            //---------------  Averaging ---------------------
            
         if (tr_AOPLong>0.0)
            {
            ObjectCreate("AOP"+tr_CounterAOPLabel,OBJ_ARROW,0,Time[1],tr_AOPLong);// Not absolutely correctly, but while will go
            ObjectSet("AOP"+tr_CounterAOPLabel,OBJPROP_ARROWCODE,tr_AOPLabelArrow);
            ObjectSet("AOP"+tr_CounterAOPLabel,OBJPROP_COLOR,tr_LongAOPColor);
            tr_CounterAOPLabel++;
            }

         if (tr_AOPShort>0.0)
            {
            ObjectCreate("AOP"+tr_CounterAOPLabel,OBJ_ARROW,0,Time[1],tr_AOPShort);// Not absolutely correctly, but while will go
            ObjectSet("AOP"+tr_CounterAOPLabel,OBJPROP_ARROWCODE,tr_AOPLabelArrow);
            ObjectSet("AOP"+tr_CounterAOPLabel,OBJPROP_COLOR,tr_ShortAOPColor);
            tr_CounterAOPLabel++;
            }



//         Print("Long=",tr_CurrLongOrders,"  tr_AOPLong=",tr_AOPLong,"    ***   Short=",tr_CurrShortOrders,"   tr_AOPShort=",tr_AOPShort);            
         tr_CurrTotalOpenedOrders=tr_CurrLongOrders+tr_CurrShortOrders;
         if ((tr_CurrTotalOpenedOrders!=tr_PrevTotalOpenedOrders)||(tr_PrevLongOrders!=tr_CurrLongOrders)||(tr_PrevShortOrders!=tr_CurrShortOrders)) // The quantity(amount) of warrants in the market has changed
            {
            if (tr_PrevLongOrders>tr_CurrLongOrders) // изменилось число ордеров в Long
               {
               tr_CloseLong=true;            
               tr_CloseLabelPrice=High[1]+tr_CloseLabelShift*Point;
               }
            if (tr_PrevShortOrders>tr_CurrShortOrders) // изменилось число ордеров в Short
               {
               tr_CloseShort=true;            
               tr_CloseLabelPrice=Low[1]-tr_CloseLabelShift*Point;
               }
            tr_PrevLongOrders=tr_CurrLongOrders;
            tr_PrevShortOrders=tr_CurrShortOrders;
            tr_PrevTotalOpenedOrders=tr_CurrTotalOpenedOrders;
            }
         }// There are open positions

//---------------- Check of change of Balance -------------------------------

      tr_CurrBalance=AccountBalance();  
      if (tr_CurrBalance!=tr_PrevCurrBalance)// проверка изменения Balance
         {
         if (tr_CurrBalance-tr_PrevCurrBalance>0.0) tr_CurrCloseColor=tr_ProfitColor; else tr_CurrCloseColor=tr_LossColor;
         tr_PrevCurrBalance=tr_CurrBalance;
         //------------------ Installation of the Label of closing --------------------
         ObjectCreate("Close"+tr_CounterCloseLabel,OBJ_ARROW,0,Time[1],tr_CloseLabelPrice);
         ObjectSet("Close"+tr_CounterCloseLabel,OBJPROP_ARROWCODE,tr_CloseLabelArrow);
         ObjectSet("Close"+tr_CounterCloseLabel,OBJPROP_COLOR,tr_CurrCloseColor);
         tr_CounterCloseLabel++;
         //------------------ Installation of the Label of closing --------------------
         }// Check of change of Balance  
      }//(IsTesting()) 
//----
   tr_Bars=Bars;
   return(0);
  }
//+------------------------------------------------------------------+
 
thx a lot

looking forward to other useful stuffs from u :>
 
Thanks

Pity, my russian language skills are non-existent. You never know how important those little notes after the '//' marks are until you can't understand it.

Good work though!!

JF
 
Yeah, I actually wandered over to the forum listed in the expert.

Needless to say I didn't dwell long even with the help of a web translator :)
 
3. Add function SetTrace(); in block start()

int start()
{
int ticket, total,totalExpert;
//------------------------------------------------------
// ради упрощения и ускорения кода, сохраним необходимые
// данные индикаторов во временных переменных

SetTrace();


Translated by Promt - http://www.e-promt.com/en/


3. Add function SetTrace(); in block start()

int start()
{
int ticket, total,totalExpert;
//------------------------------------------------------

// For the sake of simplification and acceleration of a code,
// we shall keep the necessary data of indicators in time variables


SetTrace();

 
Thanks

Pity, my russian language skills are non-existent. You never know how important those little notes after the '//' marks are until you can't understand it.

Good work though!!

JF


Anything essential in comments is not present. They are made only for simplification of perception(recognition)
 


Anything essential in comments is not present. They are made only for simplification of perception(recognition)


The only answer I find on this forum and from MQ to learn to code with MQL4 is to look around to other experts and scripts that I can find. As there is not a lot of them floating around, those that I found most helpfull are the ones where the coders make these //notes for themselves and others. It helps me to figure out what certain lines and codes actually do.

I spent some time on a russian tug and saw some translation programs. The crew and I amused ourselves for hours on end by trying to translate certain phrases. For above phrase I take it you mean "Anything present in comments are not essential"?? (See what I mean?)
 
I too studied language on another's advisers and indicators. Probably, it is a unique way.
I have replaced in a code Russian comments on English.
Code very simple and problems should not be.
 
I too studied language on another's advisers and indicators. Probably, it is a unique way.
I have replaced in a code Russian comments on English.
Code very simple and problems should not be.


To you it may be simple, but the last programming language I realy used was Turbo Pascal in 1993. In it a variable was defined as "var:price, open, high;" then a value could be given to it by "price:=1.259;". Constants was defined "constant:stop, slip, spread;". If there was an error in the script, the compiler takes you back to where it thinks the problem is (no need to count lines!!). With my experience in Turbo Pascal, MQL for MT3 was a relatively simple learning proccess.

Imagine my horror when MQL4 started! suddenly there are terms like "double, extern double", and a whole lot of commands, and changes in syntax. Now capitalization is important. To think I actually believed the comments on the web site about how simple MQL4 is to use!! For someone as out of date as me, the help file is just not good enough. I'm just glad there are people like you that take the time and effort to share helpfull codes and procedures like the one above. MANY THANKS!!!

Regards
JF
 
Jan,

Wander over to the Yahoo forums - fantastic bunch of the most helpful guys around.

http://groups.yahoo.com/group/MetaTrader_Experts_and_Indicators

Cheers
Martin
 
Jan,

Wander over to the Yahoo forums - fantastic bunch of the most helpful guys around.

http://groups.yahoo.com/group/MetaTrader_Experts_and_Indicators

Cheers
Martin


Agree, only I do not read them - time is not present

WBR
Reason: