PDA

View Full Version : MQL to VTL conversion



mayankj990@gmail.com
01-07-2014, 12:43 PM
I am converting MQL Script to VTL script.As I am new to this VTL so facing difficulty in conversion. Can anyone help me to find similar functions in VTL

MQL Functions:
1.int variable1=MarketInfo("EURUSD",MODE_DIGITS);
// Returns various data about securities listed in the Market Watch window

2. int OrderMagicNumber( ) //Returns an identifying (magic) number for the currently selected order.

3.int Hour( ) //Returns the hour (0,1,2,..23) of the last known server time by the moment of the program star

4. int OrderSend( string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)
//returns number of the ticket assigned to the order by the trade server

Hassan-HS
01-07-2014, 01:52 PM
Hello,



I am converting MQL Script to VTL script.As I am new to this VTL so facing difficulty in conversion. Can anyone help me to find similar functions in VTL


You are welcome :)

Feel free to let me know if you have any inquiries and I suggest to you that read the following articles and course it will help you:


VTL Course (http://www.hybrid-solutions.com/VTL%20Course.pdf) .
VTL Server Documentation (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/2566)
VTL Client Documentation (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/2567)







1.int variable1=MarketInfo("EURUSD",MODE_DIGITS);
// Returns various data about securities listed in the Market Watch window


You should use SymbolInfoInteger (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/1733)

sample:



Public Sub main()

Dim x

MsgBox SymbolInfoInteger("EUR/USD",SYMBOL_PIP_LOCATION,x) 'Returns true/false

MsgBox x

End Sub




2. int OrderMagicNumber( ) //Returns an identifying (magic) number for the currently selected order.


We have ID that identifying that theorders and positions , use the following methods to get it OrderGetID (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/3968), PositionGetTicket (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/2906).


You should know the difference between orders & position when use VTL.

Positions:
The orders that have been already opened.

Orders:
The pending orders (limits orders, SLTP orders)
I- Limit Type: means the order is pending order (Buy Limit, Sell Limit, Buy Stop, Sell Stop)
II- SLTP Type: it's a manage order for a open position (Buy manage, Sell manage)



In the attachment photo that describe the location of the positions and orders in the trade panel.
1=> Positions
2=>Orders

Functions related to positions:
PositionTotal
PositionGetSymbol
PositionSelect
PositionGetDouble
GetPositionType
GetPositionTime
GetPositionSymbol
CloseMultiPositions
PositionGetTicket
RequestManageOrders



Functions related to orders:
OrdersTotal
OrderSelect
OrderGetDouble
OrderGetString
OrderPrice
OrderSymbol
OrderTime
OrderType
OrderLots
OrderSelectByIndex
OrderGetID





3.int Hour( ) //Returns the hour (0,1,2,..23) of the last known server time by the moment of the program star


you can use CurTime (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/3443)to get the server time



4. int OrderSend( string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)
//returns number of the ticket assigned to the order by the trade server.


you can use NewMarketOrder (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/1736)

mayankj990@gmail.com
01-08-2014, 11:05 AM
Thank you for reply.. But sorry I can't understand answer for 2nd function


2. int OrderMagicNumber( ) //Returns an identifying (magic) number for the currently selected order.

In MQL it is returning magic number for currently selected order.. How can I get that magic no for selected order in VTL? Depending on this magic number BUY or SELL Order function( "OrderSend( )" ) called .

Hassan-HS
01-08-2014, 11:25 AM
Hello,

There is no magic number in VTL, we have only the IDs for the orders.

Is everything is clear now?

mayankj990@gmail.com
01-08-2014, 12:37 PM
Hi Dear,

Can you convert this line into vtl?

//-------------------------------------------------------------------+
//Check open orders
//-------------------------------------------------------------------+
if(OrdersTotal()>0){
for(int i=1; i<=OrdersTotal(); i++) // Cycle searching in orders
{
if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
{
if(OrderMagicNumber()==BuyMagicNumber) {int halt1=1;}
if(OrderMagicNumber()==SellMagicNumber) {int halt2=1;}
}
}
}
//-------------------------------------------------------------------+


if((halt1!=1)&&(AllowBuy==true)){// halt1

// Buy criteria
if ((TradeHour==Hour())&&(TradeMinutes==Minute())&&(TradeSeconds>=Seconds())) //Signal Buy
{
int openbuy=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippag e,slb,tpb,"time trader buy order ",BuyMagicNumber,0,Blue);
if(openbuy<1){int buyfail=1;}
}

}// halt1

if((halt2!=1)&&(AllowSell==true)){// halt2
RefreshRates();
// Sell criteria
if ((TradeHour==Hour())&&(TradeMinutes==Minute())&&(TradeSeconds>=Seconds())) //Signal Sell
{
int opensell=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slipp age,sls,tps,"time trader sell order ",SellMagicNumber,0,Green);
if(opensell<1){int sellfail=1;}
}

}// halt2


Thank you

Hassan-HS
01-08-2014, 12:57 PM
Hello,




if(OrdersTotal()>0){
for(int i=1; i<=OrdersTotal(); i++) // Cycle searching in orders
{
if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
{
if(OrderMagicNumber()==BuyMagicNumber) {int halt1=1;}
if(OrderMagicNumber()==SellMagicNumber) {int halt2=1;}
}
}
}



Please check the following code !



For i=1 to PositionTotal()
PosID =CSTR(PositionGetTicket(Cint(i)))
If PositionSelect(CLNG(OrderId)) Then
If(GetPositionType() = TRADE_ACTION_BUY) Then
Halt1=1
End If

If GetPositionType() = TRADE_ACTION_SELL ) Then
Halt2 =1
End If
End If
Next

mayankj990@gmail.com
01-09-2014, 02:17 PM
Hi Sir, I need this MQL code to be converted to VTL

int TakeProfit=20;
int StopLoss=20;
int StopMultd,Sleeper=1;

int digits=MarketInfo("EURUSD",MODE_DIGITS);
if(digits==5)
{
StopMultd=10;
}
else
{
StopMultd=1;
}
double TP=NormalizeDouble(TakeProfit*StopMultd,Digits);
double SL=NormalizeDouble(StopLoss*StopMultd,Digits);
int Slippage=Slip*StopMultd;

// Calculate stop loss
double slb=NormalizeDouble(Ask-SL*Point,Digits);
double sls=NormalizeDouble(Bid+SL*Point,Digits);

// Calculate take profit
double tpb=NormalizeDouble(Ask+TP*Point,Digits);
double tps=NormalizeDouble(Bid-TP*Point,Digits);

Hassan-HS
01-09-2014, 03:02 PM
Hi too,





int digits=MarketInfo("EURUSD",MODE_DIGITS);




You can get the digits in this way




SymbolInfoInteger Cstr(ChartSymbol(0)),SYMBOL_PIP_LOCATION,PipLoc
digits = - PipLoc



[QUOTE]
NormalizeDouble(Ask-SL*Point,Digits);



You can use Round as follwoing




Round ( expression, [decimal_places] )

mayankj990@gmail.com
01-16-2014, 02:35 PM
Hi..
how to get Current Time in individual variables Hours, Minutes, Seconds..

I have used CurTime( ) function but it is returning Date/Hour/Minutes/Seconds as single String

Hassan-HS
01-16-2014, 03:40 PM
Hi too :)

You can split the date as you want using Right function, note our date format is "dd/mm/yyyy HH:MM:SS"

RIGHT( text, [number_of_characters] ), Sample:



Dim TradeTime
Dim STime="00:00"
Dim ETime="23:59"

If (Cdate( Trim(Right(CurTime,9)))>= Cdate(StartTime) ) And ( Cdate( Trim(Right(CurTime,9))) <= Cdate(EndTime) ) Then
TradeTime=true

Else
TradeTime=false
End If