MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal

Automated Trading and Strategy Testing Forum

The Player of Trading Based on Deal History The Player of Trading Based on Deal History Screenshot
T[DAX30], None
Real
Subscribe to signal
SilNix 1
5 995.13%, 60 951.30 USD
Diagram of Trades LimitedDiagram of Trades Limited Try product
Diagram of Trades Limited
Author: song_song
F2a_AO Indicator
F2a_AO
Author: GODZILLA
To add comments, please log in or register
previous12next
phenix
24
phenix 2012.05.06 14:15 
#property show_inputs
extern double Lot = 0.1;
extern string  TradeComment="IA 8 Paires";



//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
   int TradesSent=0;


 
    while(true)
     {
  int ticket= OrderSend("AUDUSD",OP_SELL, Lot, MarketInfo("AUDUSD",MODE_BID), 2, NULL, NULL, TradeComment, 0, 0, CLR_NONE);
   
    if(ticket<=0) Print("Error = ",GetLastError());
      else { Print("ticket = ",ticket);TradesSent++; break; }
     }   
    
    while(true)
     {
  ticket= OrderSend("EURUSD",OP_SELL, Lot, MarketInfo("EURUSD",MODE_BID), 2, NULL, NULL, TradeComment, 0, 0, CLR_NONE);
  
   if(ticket<=0) Print("Error = ",GetLastError());
      else { Print("ticket = ",ticket);TradesSent++; break; }
     }   
   
    while(true)
     {
  ticket= OrderSend("GBPUSD",OP_SELL, Lot, MarketInfo("GBPUSD",MODE_BID), 2, NULL, NULL, TradeComment, 0, 0, CLR_NONE);
   
    if(ticket<=0) Print("Error = ",GetLastError());
      else { Print("ticket = ",ticket);TradesSent++; break; }
     }   
    
    while(true)
     {
   ticket=OrderSend("NZDUSD",OP_SELL, Lot, MarketInfo("NZDUSD",MODE_BID), 2, NULL, NULL, TradeComment, 0, 0, CLR_NONE);
   
   if(ticket<=0) Print("Error = ",GetLastError());
      else { Print("ticket = ",ticket);TradesSent++; break; }
     }   
   
    while(true)
     {
   ticket=OrderSend("NZDJPY",OP_BUY, Lot, MarketInfo("NZDJPY",MODE_ASK), 2, NULL, NULL, TradeComment, 0, 0, CLR_NONE);
   
    if(ticket<=0) Print("Error = ",GetLastError());
      else { Print("ticket = ",ticket);TradesSent++; break; }
     }   
    
    while(true)
     {
   ticket=OrderSend("EURJPY",OP_BUY, Lot, MarketInfo("EURJPY",MODE_ASK), 2, NULL, NULL, TradeComment, 0, 0, CLR_NONE);
   
    if(ticket<=0) Print("Error = ",GetLastError());
      else { Print("ticket = ",ticket);TradesSent++; break; }
     }   
    
    while(true)
     {
   ticket=OrderSend("AUDJPY",OP_BUY, Lot, MarketInfo("AUDJPY",MODE_ASK), 2, NULL, NULL, TradeComment, 0, 0, CLR_NONE);
   
    if(ticket<=0) Print("Error = ",GetLastError());
      else { Print("ticket = ",ticket);TradesSent++; break; }
     }   
    
    while(true)
     {
   ticket=OrderSend("GBPJPY",OP_BUY, Lot, MarketInfo("GBPJPY",MODE_ASK), 2, NULL, NULL, TradeComment, 0, 0, CLR_NONE);
   
    if(ticket<=0) Print("Error = ",GetLastError());
      else { Print("ticket = ",ticket);TradesSent++; break; }
     }   
   
   
   return(0);
  }
//+----------------------------------------------------------------------------------------------------+
Hello to all.
I started in programming and I try to learn the MQL5, I know a bit MQL4, therefore I would like to know if someone could bring me this MQL5 code so that I can understand the difference between MQL5 and MQL4 this help me much.

thank you sincerely

Sorry for my English i am French


Interview with Ge Senlin (ATC 2011)
The Expert Advisor by Ge Senlin (yyy999) from China got featured in the top ten of the Automated Trading Championship 2011 in late October and hasn't left it since then. Not often participants from the PRC show good results in the Championship - Forex trading is not allowed in this country. After the poor results in the previous year ATC, Senlin has prepared a new multicurrency Expert Advisor that never closes loss positions and uses position increase instead. Let's see whether this EA will be able to rise even higher with such a risky strategy.
onewithzachy
961
onewithzachy 2012.05.06 15:08  
phenix
24
phenix 2012.05.07 12:04  
Good morning.
I've already seen all the pages but I do not understand is why I would love a person for me to convert this code in MQL5, again I speak English so it's not easy for me if it does not help me.
thank you for your help.
cordially
Rosh
Admin
4535
Rosh 2012.05.07 17:55  
phenix
24
phenix 2012.05.08 15:57  
Good morning.
thank you for all your answers but I speak ENGLISH and to understand it faudrais translation of this code MQL5 because you will send me on codes I do not understand because I have no referential my repos is my code that I know well that is why it is very important to me that a person is willing to spend some time to convert it is very important to me.
I'm not a computer specialist and I am not a genius :-) so help me.
thank you
cordially
onewithzachy
961
onewithzachy 2012.05.09 14:05  

Hi phenix, I rewrite your MQL4 code to be like this below;

//+------------------------------------------------------------------+
//|                                                    MQL4 Note.mq4 |
//|                           Copyright 08 May 2012 , onewithzachy   |
//|                                                                  |
//+------------------------------------------------------------------+

#property show_inputs
extern double  Lot          = 0.1;
extern string  TradeComment = "IA 8 Paires";

int TradesSent = 0;
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
  ORDER_SEND_FUNC ("AUDUSD", OP_SELL);
  ORDER_SEND_FUNC ("EURUSD", OP_SELL);
  ORDER_SEND_FUNC ("GBPUSD", OP_SELL);
  ORDER_SEND_FUNC ("NZDUSD", OP_SELL);
  ORDER_SEND_FUNC ("NZDJPY", OP_BUY);
  ORDER_SEND_FUNC ("EURJPY", OP_BUY);
  ORDER_SEND_FUNC ("AUDJPY", OP_BUY);
  ORDER_SEND_FUNC ("GBPJPY", OP_BUY);
  
   return(0);
  }
//+----------------------------------------------------------------------------------------------------+          
int ORDER_SEND_FUNC (string my_symbol, int trade_type)
   {
   
   int ticket, mode_price, try;
   
   if (trade_type == OP_BUY)  mode_price = MODE_ASK;
   if (trade_type == OP_SELL) mode_price = MODE_BID;    
   
   while(true)
     {
     try ++;
     ticket= OrderSend(my_symbol, trade_type, Lot, MarketInfo(my_symbol,mode_price), 10, 0, 0, TradeComment, 0, 0, CLR_NONE);
   
     if(ticket <= 0) 
        {
        Print("Error = ",GetLastError());
        // some error code process here to decide whether to continue open position or not
        }
        else 
        {
        Print("Success sending order for ",my_symbol," with ticket = ", ticket," after ",try," trying.");
        TradesSent++; 
        break; 
        }
     } 
   return (ticket);
   }
   
//+----------------------------------------------------------------------------------------------------+

 

Here's the conversion to MQL5. I did not test this because I have bad internet connection. Rosh would you please be kind to help us to correct the codes if there's any error. :) 

1st conversion

// the codes is removed to save some space, please download the attachment to review the codes. Thank you. onewithzachy

 

Personally, I don't think it's good idea to send order with while loop like that.

I'll write more, when I have time, you just have to check this topic again phenix. :) 

BTW, what's the french of Hello, Good luck and Have fun ?

Have Fun :) 

Attached files
trade_1.mq5 (4.43 KB)
trade_2.mq5 (3.73 KB)
phenix
24
phenix 2012.05.10 09:42  

Hello all.

onewithzachy, a very very big big thank you to you for your help and your availability this will help me a lot.
and it is heartwarming to find people who still helps as you did.
yes I would be happy even when you have time the improvements of this script :-)
thank you again for your patience and your help.
friendly
onewithzachy
961
onewithzachy 2012.05.10 16:32  

Phenix, I don't have much time right now, so this is the best that I can help.

In the attachments below are the same code with adding tp and sl after position successfully opened. I only test this briefly, and it looks like it's running well.

Personally I think we should process the error codes, for example if there is requote, we can adjust the opening price properly so the position will be opened anyway. 

Have fun :) 

Attached files
trade_1-1.mq5 (5.31 KB)
trade_2-1.mq5 (4.51 KB)
phenix
24
phenix 2012.05.11 08:25  

onewithzachy thank you very much for your availability.
friendly
Rosh
Admin
4535
Rosh 2012.05.11 11:56  

Use Standard library class CTrade, try this:

#property description "http://www.mql5.com/en/forum/6666"
#property link "http://www.mql5.com/en/forum/6666"

#include <Trade\Trade.mqh>

#property script_show_inputs

input double Lot          = 0.1;
input double SL           = 300;
input double TP           = 300;
input string TradeComment = "IA 8 Paires";

double My_SL=0.0,My_TP=0.0;
int TradesSent=0;

CTrade trade;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+

void OnStart()
  {
   PlaySound("wait.wav");
//---
//ORDER_SEND_FUNC ("AUDUSD", ORDER_TYPE_SELL);
//ORDER_SEND_FUNC ("EURUSD", ORDER_TYPE_SELL);
//ORDER_SEND_FUNC ("GBPUSD", ORDER_TYPE_SELL);
//ORDER_SEND_FUNC ("NZDUSD", ORDER_TYPE_SELL);
//ORDER_SEND_FUNC ("NZDJPY", ORDER_TYPE_BUY);
//ORDER_SEND_FUNC ("EURJPY", ORDER_TYPE_BUY);
//ORDER_SEND_FUNC ("AUDJPY", ORDER_TYPE_BUY);
//ORDER_SEND_FUNC ("GBPJPY", ORDER_TYPE_BUY);
//--- sell one pair
   double open_price=SymbolInfoDouble("AUDUSD",SYMBOL_BID);
   int digits=(int)SymbolInfoInteger("AUDUSD",SYMBOL_DIGITS);
   double SLprice=NormalizeDouble(SymbolInfoDouble("AUDUSD",SYMBOL_ASK)+SL*_Point,digits);
   double TPprice=NormalizeDouble(SymbolInfoDouble("AUDUSD",SYMBOL_ASK)-TP*_Point,digits);
   if(trade.Sell(Lot,"AUDUSD",open_price,SLprice,TPprice,TradeComment)==false)
     {
      Print("Sell AUDUAS failed, Error=",GetLastError(),
            "   Retcode description:",trade.CheckResultRetcodeDescription());
     }
   PlaySound("wait.wav");
  }
//+------------------------------------------------------------------+
onewithzachy
961
onewithzachy 2012.05.11 12:16  
Rosh:

Use Standard library class CTrade, try this:

Dear Rosh, thanks for the codes. The reason I didn't try that (for trade 3.mq5) was that Ctrade trade.sell (or trade.buy) doesn't have slippage, so we may end up in requotes. 

BTW,  I think that's a copy paste typo, you usually calculate TP for sell base on Bid price :).

/ /previous12next
To add comments, please log in or register