Discussion of article "MQL5 Cookbook - Multi-Currency Expert Advisor and Working with Pending Orders in MQL5" - page 3

 

Otto ...now you can use it :-)

It makes trades for me.

 

That's quite a response. Thank you!

I just wanted to point out that the authors of the articles should take care of them.

All you have to do is

CheckTradingPermission()
and all the MQL5xxx rubbish and it will work;)
 
Otto Pauser:

That's quite a response. Thank you!

I just wanted to point out that the authors of the articles should take care of them.

Mmmhhh ... yes, we know.

And I gave it some expression.

Something like that works, you notice it in other places, even if nobody says anything about it :-)

 
Christian:

Mmmhhh ... yes, we know.

And I've given it some expression.

Something like that works, you notice it in other places, even if nobody says anything about it :-)

My intention was to reprogramme the MarketOrders into PendigOrders.

Whoever can use it, here is the code how it works.

This is not a useful EA but just an example of how to calculate it. I hope it is correct, it works in the tester.

It's also not my real programming style, but kept very simple.

#include <Trade\Trade.mqh> CTrade Trade;

//+------------------------------------------------------------------+
input int    inp_Dist     =  120;   // Distance pending order (points)
input int    inp_Stop     =  125;   // SL (points)
input int    inp_Take     =  150;   // TP (points)
input double inp_Volume   = 0.01;   // Volume

//+------------------------------------------------------------------+
double distPend = inp_Dist*_Point;
double distStop = inp_Stop*_Point;
double distTake = inp_Take*_Point;

//+------------------------------------------------------------------+
bool   done     = false;
double ask;
double bid;
double levelSell;
double levelBuy;
double stopSell;
double stopBuy;
double takeSell;
double takeBuy;

void OnTick()
{
   if(done)
      return;
   
   ask=SymbolInfoDouble(_Symbol,SYMBOL_ASK);
   bid=SymbolInfoDouble(_Symbol,SYMBOL_BID);

   levelBuy =NormalizeDouble(bid-distPend,_Digits);
   levelSell=NormalizeDouble(ask+distPend,_Digits);

   stopBuy  =NormalizeDouble(levelBuy -distStop,_Digits);
   stopSell =NormalizeDouble(levelSell+distStop,_Digits);

   takeBuy  =NormalizeDouble(levelBuy +distTake,_Digits);
   takeSell =NormalizeDouble(levelSell-distTake,_Digits);

   SellLimit();
   BuyLimit();

   done=true;
}

bool BuyLimit()
{
   //return(Trade.BuyLimit (inp_Volume,levelBuy ));
   return(Trade.BuyLimit (inp_Volume,levelBuy ,_Symbol,stopBuy,takeBuy ));
}

bool SellLimit()
{
   //return(Trade.SellLimit(inp_Volume,levelSell));
   return(Trade.SellLimit(inp_Volume,levelSell,_Symbol,stopSell,takeSell));
}