PDA

View Full Version : Similar VTL Function Needed



AmitSharma
12-24-2013, 05:29 PM
Hi Sir,

I need similar function in VTL. Please give me suggestions

It is MQL 4 function
1. NormalizeDouble( ,Digits);
2. OrderMagicNumber()
3. OrderOpenPrice()
4. TimeCurrent()
5. OrderSend()
6. What is "Point" in VTL. How to access it?


Thanks
Amit

Reply by
Hassan-HS


VTL Documentation

1- MathRound returns a double value containing the number rounded to the nearest specified digit.

2- There is no property like OrderMagicNumber(), you can ignore it.

3-

for position:
1- Select a certain position using PositionSelect.
2-use PositionGetDouble to get the open price.

for orders:

I-Select a certain order use OrderSelect
II-use OrderPrice to get the open price


4-Use CurTime to return the server time

5- if do you need to open a marker order use NewMarketOrder or if do you need to open limit order use NewLimitOrder or if you need to open SLTP order use NewSLTPOrder

6-

Dim Point
SymbolInfoInteger Cstr(ChartSymbol(0)),SYMBOL_PIP_LOCATION,PipLoc
Point=( 1/(10^Cint(-PipLoc)))

Hassan-HS
12-24-2013, 07:29 PM
Dear Amit,

Thanks or your post, and please don't hesitate to contact us if you have any further questions.


You can find the mentioned method in VTL documntation (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/2567).

For more information about VTL read this course (http://www.hybrid-solutions.com/VTL%20Course.pdf).

AmitSharma
12-27-2013, 11:58 AM
Hi Sir,

I need similar code in VTL. Please update me this information.


int Error=GetLastError();
if(Error==130){Alert("Wrong stops. Retrying."); RefreshRates();}
if(Error==133){Alert("Trading prohibited.");}
if(Error==2){Alert("Common error.");}
if(Error==146){Alert("Trading subsystem is busy. Retrying."); Sleep(500); RefreshRates();}


Thank you

Hassan-HS
12-27-2013, 12:30 PM
Dear Amit,


The following example describe how to use GetLastError (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/2668)& how to alert the user.


Public Sub main()

Dim x

MsgBox SymbolInfoDouble("EUR/USd",SYMBOL_ASK,x) 'Passed wrong symbol name[names are case sensitive].=>False

MsgBox ErrorDescription(GetLastError()) 'Returns a description of the error "invalid Symbol" in this case

End Sub




Notes:
I- There is no need to use function like Refresh-Rates in the VTL, because there is no predefined variables in the VTL.
The VTL have functions ( not predefined variables ) to return (Ask,Bars,Bid,Close,Digits,High,Low,Open,Point,Tim e) whenever you want and it's values already updated.

AmitSharma
12-27-2013, 02:09 PM
Hi Sir,

Thank you for updates.

Can you tell me about similar function in VTL.

Example 1

OrderModify(OrderTicket(),0,OrderStopLoss(),tpb,0, CLR_NONE);

Example 2

SimpleMovingAvarage(0, PRICE_HIGH ,0)

I want to use "PRICE_MEDIAN" in above function. "PRICE_MEDIAN" in MQL4 applied price. How can i use in VTL?

Example 3

Similar function need in VTL "OrderTakeProfit()".

Example 4
OrderStopLoss() function in VTL?

Thank you

Hassan-HS
12-27-2013, 05:04 PM
Dear Amit,


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


Finally


How to identify to which open position is a managed order belong to? read this thread (http://www.hybrid-solutions.com/forum/showthread.php?31439-Managed-Orders)

========================================

Use UpdateSLTPOrder (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/3632)function to update the SL & TP & the amount for managed orders.

Use UpdateLimitOrder (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/1739) function to update the SL & TP & the amount & the open price for limit orders.

========================================

SimpleMovingAverageOnArray (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/3481)(): It's a procedure that calculate SimpleMovingAverage, based on custom prices array.

Notes:
Median_Price = (High+Low)/2

To get High & Low Prices use the following methods CopyHigh (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/3439), CopyLow (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/3440)

The array that filled by CopyXXXX function is option base 1, the first index is 1.

========================



If you need to get TP or SL for certain pending order do the following:

1- Select order using OrderSelect (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/1748)method

2- Use OrderGetDouble (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/1749)method to return (SL or TP etc..) values through ByRef parameter, and pass a value of type ENUM_ORDER_PROPERTY_DOUBLE to decide which one of information do you need (SL or TP etc..) .

If you need to get TP or SL for certain position do the following:

1- Select order using PositionSelect (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/1742) method

2- Use PositionGetDouble (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/1743)method to return (SL or TP etc..) values through ByRef parameter,and pass a value of type
ENUM_POSITION_PROPERTY_DOUBLE to decide which one of information do you need (SL or TP etc..)

AmitSharma
12-28-2013, 01:05 PM
Hi Sir,

I have MQL 4 Expert adviser. I am converting in VTL. How can i match the result in VTL?

Thank you

Hassan-HS
12-28-2013, 02:15 PM
Hi Amit,
You can trace the code using message boxes to understand the behaviour of your script

AmitSharma
01-03-2014, 02:13 PM
Hi Sir,

Dim lowPrice
lowPrice = SimpleMovingAverage(0, PRICE_LOW ,0)

Above function through exception how to handle in vtl. I want to get lowprice for period 0.

Thank you

Hassan-HS
01-03-2014, 03:05 PM
Dear Amit,

You can't use "0" because it's a invalid period, the minimum period amount is "1".

To get a Simple Moving Average result values as array please use SimpleMovingAverageOnArray (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/3481)


Sample:



Public Sub main()

Dim ary()

Dim lowPrice ()

Dim Period

Period = 1

CopyLow 0, 1, Bars (0), Ary

SimpleMovingAverageOnArray Ary,CInt (Period), lowPrice

MsgBox "The indicator value of the record 50 : " & lowPrice (50)
End Sub

AmitSharma
01-03-2014, 05:19 PM
Hi Sir,

I want to use the function in vtl. As you tell me i can use using SimpleMovingAverageOnArray(). How can access it shift value in SimpleMovingAverageOnArray().


example

iMA(NULL,0,16,8,MODE_SMA,PRICE_MEDIAN,0);
iMA(NULL,0,16,8,MODE_SMA,PRICE_MEDIAN,1);
iMA(NULL,0,16,8,MODE_SMA,PRICE_MEDIAN,2);

double iMA( string symbol, int timeframe, int period, int ma_shift, int ma_method, int applied_price, int shift)
Calculates the Moving average indicator and returns its value.
Parameters:
symbol - Symbol the data of which should be used to calculate indicator. NULL means the current symbol.
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.
period - Averaging period for calculation.
ma_shift - MA shift. Indicators line offset relate to the chart by timeframe.
ma_method - MA method. It can be any of the Moving Average method enumeration value.
applied_price - Applied price. It can be any of Applied price enumeration values.
shift - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

How can i use "shif"t value in VTL?


How to use in vtl above function ?
Thank you

Hassan-HS
01-03-2014, 06:08 PM
Hello Amit


As previous post, the array "lowPrice" have the all results values of applying SMA over current chart.

now: lowPrice(bars(0)) = iMA(NULL,0,16,8,MODE_SMA,PRICE_MEDIAN,0)
lowPrice(bars(0)-1) = iMA(NULL,0,16,8,MODE_SMA,PRICE_MEDIAN,1)

I hope that everything is clear now, please don't hesitate to contact me if you have any further questions. :D

AmitSharma
01-03-2014, 06:17 PM
thank you sir. great job. I really appreciate your reply.

AmitSharma
01-03-2014, 06:57 PM
Hi Sir,

I have one more doubt about "ma_shift" value. How can we use it in vtl? sorry for my basic question.

Thank you for your great support...

Hassan-HS
01-03-2014, 07:34 PM
Dear Amit,

You are welcome any time brother, Ignore it just.