Multicurrency advisor question - page 3

 

Thank you, komposter. Started to do it!

But here comes another question! My Expert Advisor has position opening blocks and trailing bars separately.

int start()
  {
// ЗАДАЕМ ПЕРЕМЕННЫЕ ДЛЯ ВСЕХ ПАР
 
 
 // ОТКРЫВАЕМ ПОЗИЦИИ ПО ВСЕМ ПАРАМ
 
//----------------------------------------------
// -------- ТРЕЙЛИНГ СТОПЫ -----------------------
if (UseTrailing_ == True)                                             {                  
for (int r=0; r<OrdersTotal(); r++)                                    {
    if (OrderSelect(r, SELECT_BY_POS, MODE_TRADES))                     {
//--------------------------------------------------
     if (OrderSymbol()=="GBPUSD" && OrderMagicNumber()==MagicGBPUSD)     
      {  Трейлинг по фунту }
//--------------------------------------------------
     if (OrderSymbol()=="EURUSD" && OrderMagicNumber()==MagicEURUSD)     
      {  Трейлинг по евро }
//--------------------------------------------------------------------
                                                                       }
                                                                      }
                                                                     }
//----------------------------------------------------------------------
   } 
  return(0);
HOWEVER, I put a piece of code (e.g. for the pound) into the trawl -

double bid_GBP = MarketInfo("GBPUSD", MODE_BID);
 double ask_GBP = MarketInfo("GBPUSD", MODE_ASK);
 double point_GBP =MarketInfo("GBPUSD",MODE_POINT);

But I already used this bit when I opened position on GBP. Now may I use the same trailing stopper again? Or, do I need to re-enter the same trailing slice for the pound, with slightly different values' names?

 
rid:
HOWEVER, I put a piece of code (e.g. for the pound) into the trailing -
double bid_GBP = MarketInfo("GBPUSD", MODE_BID);
 double ask_GBP = MarketInfo("GBPUSD", MODE_ASK);
 double point_GBP =MarketInfo("GBPUSD",MODE_POINT);

But I have already used this slice before when I opened a position on the pound. Can I now use the same piece in the trawl again? Or do I have to re-enter the same piece with slightly different names for these values in the trawl for the pound?

You can insert "this bit" at the very beginning of the start() function and use variable values in all blocks.
 

Thank you very much for your answer! komposter !

One last important question. (I'm afraid of sounding too intrusive, but...) -

For the third pair I ( due to various reasons) call the trailing library. From the librares folder, for example.

How to be in this case? Is it necessary to specify the same thing inside the library for this pair

//RefreshRates();
 double bid = MarketInfo("USDCHF", MODE_BID);
 double ask = MarketInfo("USDCHF", MODE_ASK);
 double point =MarketInfo("USDCHF",MODE_POINT);

and change the symbol and magik accordingly:

... .... .....
if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) {
        if (OrderType()==OP_BUY) {
          if (!ProfitTrailing || (Bid-OrderOpenPrice())>TrailingStop*Point) {
            if (OrderStopLoss()<Bid-(TrailingStop+TrailingStep-1)*Point) {
              ModifyStopLoss(Bid-TrailingStop*Point, clModifyBuy); 
 .... ... ...
 
rid:

For the third pair I (for various reasons) call the trailing library. From the libraris folder, for example.
How to be in this case? Do I need to set similarly within the library

It depends on the library. If it knows how to work with nonnative character orders, it won't be a problem. If it does not, it will be bad ;)
 

This is Kim's three-level output library. Now I've gone into the code. Instead of a symbol everywhere I set the name of the pair and instead of a magik I set the magik of my pair.

//+------------------------------------------------------------------+
//|                                                  a-TLE_v.1.6.mqh |
//|                                           Ким Игорь В. aka KimIV |
//|                                              http://www.kimiv.ru |
//|                                                                  |
//|  v.1.6  Три уровня переноса стопа.                               |
//| 23.11.2005 v.a1.6  Реализация в виде универсального модуля.      |
//|                                                                  |
//|   Для использования добавить строку в модуле start               |
//|   if (UseTrailing) TrailingPositions();                          |
//+------------------------------------------------------------------+
 
//------- Внешние параметры модуля - уровни переноса--------------------
... ... ... ...
 
//+------------------------------------------------------------------+
//| Сопровождение позиций                                            |
//+------------------------------------------------------------------+
void TrailingPositions()                                  {
  for (int i=0; i<OrdersTotal(); i++)                       {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))           {
      if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) {
        ThreeLevelSystemOfOutput();
      }
    }
  }
}
 
//+------------------------------------------------------------------+
//| Трёхуровневая система выходов                                    |
//+------------------------------------------------------------------+
void ThreeLevelSystemOfOutput()                      {
   int sp=MarketInfo(OrderSymbol(), MODE_SPREAD);
  if ( бла-бла-бла)                                  {
    SimpleTrailingPositions();
                                                      }
                                                      }
 
//+------------------------------------------------------------------+
//| Сопровождение позиции простым тралом                             |
//+------------------------------------------------------------------+
void SimpleTrailingPositions() {
  double pBid, pAsk, pp=MarketInfo(OrderSymbol(), MODE_POINT);
... ... ...
   
//+------------------------------------------------------------------+
//| Перенос уровня StopLoss                                          |
//| Параметры:                                                       |
//|   ldStopLoss - уровень StopLoss                                  |
//+------------------------------------------------------------------+
... ... ...
//+------------------------------------------------------------------+
//| Перенос уровня StopLoss                                          |
//| Параметры:                                                       |
//|   ldStopLoss - уровень StopLoss                                  |
//+------------------------------------------------------------------+
void ModifyStopLossInPoint(int pp) {
    double ldSL=0, mp=MarketInfo(OrderSymbol(), MODE_POINT);  
 ... ... ...  
//+------------------------------------------------------------------+
//| Возвращает профит позиции в пунктах                              |
//+------------------------------------------------------------------+
int ProfitPosition() {
  double pBid, pAsk, pp=MarketInfo(OrderSymbol(), MODE_POINT);
  double pr=0;
 
  if (OrderType()==OP_BUY) {
    pBid=MarketInfo(OrderSymbol(), MODE_BID);
    pr=(pBid-OrderOpenPrice())/pp;
  }
  if (OrderType()==OP_SELL) {
    pAsk=MarketInfo(OrderSymbol(), MODE_ASK);
    pr=(OrderOpenPrice()-pAsk)/pp;
  }
  return(MathRound(pr));
}
 
//+------------------------------------------------------------------+
//| Возвращает StopLoss позиции в пунктах                            |
//+------------------------------------------------------------------+
int StopLossInPoint() {
  double pp=MarketInfo(OrderSymbol(), MODE_POINT);
  double sp=0;
 
  if (OrderType()==OP_BUY) {
    sp=(OrderStopLoss()-OrderOpenPrice())/pp;
  }
  if (OrderType()==OP_SELL) {
    sp=(OrderOpenPrice()-OrderStopLoss())/pp;
  }
  if (OrderStopLoss()==0) sp=-OrderOpenPrice()/pp;
  return(MathRound(sp));
}
//+------------------------------------------------------------------+

You can see it's a little blurry with all the different

MarketInfo(OrderSymbol(), MODE_POINT);
MarketInfo(OrderSymbol(), MODE_BID);
MarketInfo(OrderSymbol(), MODE_ASK);

and that in almost every operation!

But I have only changed the symbol (I have specified the pair) and the magician at the very beginning! I have started the Expert Advisor online in 1 minute timeframe. I have waited for profit and stopped price movement on this pair. Everything seems to be working fine. I am in accordance with the algorithm of this library.

But I have not yet profit on two other pairs (with my own trawls).

I will watch it tomorrow online.

 
rid:

This is Kim's three-level output library. Now I've gone into the code. Instead of a symbol everywhere I set the name of the pair and instead of a magik I set the magik of my pair.

...

You can see it's a little blurry with all the different

MarketInfo(OrderSymbol(), MODE_POINT);
MarketInfo(OrderSymbol(), MODE_BID);
MarketInfo(OrderSymbol(), MODE_ASK);
The library is competently written - there is no linkage to the chart tool.
It can therefore be used without modification.
 

Thank you again, komposter, for your answers!

Now I waited online for the profits on all three pairs of my Expert Advisor. It seems that each pair works according to its trawl mode! Including the pair with the library call!

 
komposter:
rid:

This is Kim's three-level output library. Now I've gone into the code. Instead of a symbol everywhere I set the name of the pair and instead of a magik I set the magik of my pair.

...

You can see it's a little blurry with all the different

MarketInfo(OrderSymbol(), MODE_POINT);
MarketInfo(OrderSymbol(), MODE_BID);
MarketInfo(OrderSymbol(), MODE_ASK);
The library is competently written - there is no linkage to the chart tool.
It can therefore be used without modification.

I'll throw in my own version... cut code:


extern int    MagicNum = 400400, Stop = 33;
extern double Lot1 = 0.3;
int LotStop [8] = {28,33,43,33,33,33,33,33}; //можно юзать просто Stop
 
//| Start function                                                   |
//+------------------------------------------------------------------+
void start()
{ 
 int i, SymPermitted = 3;
 string Symbols[8] = {"EURUSD","GBPUSD","USDJPY","EURJPY","USDCHF","Reserved","Reserved","Reserved"};
 
  // Ma defence
  if (Bars<100)
    return(0);  
  
  for (i=0; i < SymPermitted; i++)
  {
    // Compile/reload/crash config defence
    if      (Symbols[i] == "EURUSD") { Stop = 28; Lot1 = 0.6; }
    else if (Symbols[i] == "GBPUSD") { Stop = 33; Lot1 = 0.2; }
    else if (Symbols[i] == "USDJPY") { Stop = 43; Lot1 = 0.6; }
    Sleep (1000); // Просто так
    Checking (Symbols[i], i);
  }
  return (0);
}
 
void Checking (string Sym, int LotStopIndex)
{
 int Total, LotStop = LotStop[LotStopIndex], i, j, Tic = 0;
 double VPoint, VAsk, VBid;
 
   Total = OrdersTotal();
 
   // Check opened
   for (i=0; i<Total; i++)
   {
     if (OrderSelect (i, SELECT_BY_POS, MODE_TRADES) == true)
     {  
       if (OrderSymbol() == Sym && OrderMagicNumber() == MagicNum)
         return (0);
     }
   }
   
   VPoint = MarketInfo(Sym, MODE_POINT);
   //... кучка кода расчётов
   Total = HistoryTotal();
   
   if (Total == 0)
   { // Reset to default
     LotSize = Lot1;
     LotStop[LotStopIndex] = Stop;
   }
   
   for (i=0; i<Total; i++)
   {
     if (OrderSelect (Total-i-1, SELECT_BY_POS, MODE_HISTORY) == true)
     { 
       if (OrderSymbol() == Sym && OrderMagicNumber() == MagicNum)
       { // Was loss (Alpari иногда выбивает положительные лосы и отрицательные профиты... мистика
         if (((OrderProfit ()) < 0) || (OrderClosePrice() == OrderStopLoss()))
         { ..код
         }
           
         else
         { // Reset to default
           LotSize = Lot1;
           LotStop[LotStopIndex] = Stop;
         }
         break;
       }
     }
 
     else
     {
       Print("Ошибка <", GetLastError(), "> при выборе хистори - ордера");
       return (1);
     }
  }
 
  if(AccountFreeMarginCheck(Sym, OP_BUY, LotSize) <= 0) 
  {  return (0); }
 
  
  VAsk = MarketInfo (Sym, MODE_ASK);
  VBid = MarketInfo (Sym, MODE_BID);
  // bay|sell...
  
  if (условие 1)
    Tic = OrderSend (Sym, OP_BUY, LotSize, VAsk, 3, VAsk-LotStop[LotStopIndex]*VPoint, VAsk+LotStop*VPoint, "CMATest5m", MagicNum, 0, Lime);
    
  else if (условие 2)
    Tic = OrderSend (Sym, OP_SELL, LotSize, VBid, 3, VBid+LotStop[LotStopIndex]*VPoint, VBid-LotStop*VPoint, "CMATest5m", MagicNum, 0, Red);
  
  if (Tic <= 0)
  {
    Print("Ошибка <", GetLastError(), "> при запросе ордера");
    Sleep (60000); // Ждём минуту... рынок никуда не убежит :-)...
  }
}
 

VassaV, tell us a little more about what you have posted here and how to use it.

What does the expression "cut code" mean?

Why isn't there a comment in the third line. //can you use...?

 
rid:

VassaV, tell us a little more about what you have posted here and how to use it.

What does the expression "cut code" mean?

Why isn't there a comment in the third line. //can you use...?


Cut up means cut down so that only the base is left. How to use it is up to you, here is just an example.

Correspondingly:

//... a bunch of calculation code - here its own signal/indicator processing code.

// ...code - here we have our own code for loss processing

condition 1 - here we have our own code of buy/sell conditions

// can you use...? - it is a comment, it is just displayed this way.

It means that you can use arrays to store the parameters of each currency or you can store the parameters in the code

(section // Compile/reload/crash config)

Reason: