RAQ

How do you use an ATR as a stop and target?

Q:


How do you use an ATR as a stop and target?


A:


This is a little tricky. The iATR value is a “price-like” value. Not a currrency price like 1.3456, but a portion of a price like 0.00256. See the chart below.



The value 0.00256 will not work as a StopLoss or TakeProfit value.  However, the number 256 can work. So, how do we go from 0.00256 to 256?


We can do this uisng the MQL built-in variable named Point. The Point variable contains the value of one point for the currency. For most USD denominated currencies, this is equal to 0.00001.


So we can convert our iATR value into a usable stoploss (or takeprofit) value by dividing by Point:


0.00256  /  0.00001 => 256


We can do this in VTS by creating a variable, and using the Assignment tab to directly enter the expression:



Some notes:


(1) The variable that holds the value of the iATR2 function is named “_iATR2”.  VTS automatically creates this variable when you drag and drop the iATR


function.


(2) VTS offers an expression editor, select the Choose menu and choose “expression editor”.  It’s not that useful, but it was my attempt at allowing traders to entery complicated mathematical expression in VTS:



(3) The assignment tab is one of a few places in VTS where you can enter MQL. Because of this, you should always build right after using the assignement tab so that if you created a syntax error you see it right away (and can fix it right away).


(4) I like to use the Message tab to write these values to the chart so I can verify my math:



 Here is a simple drawing, I have enabled Messages for both the iATR2 function and the MyAtrStop variable.



 Here is the output on the MetaTrader price chart:



 OK, now to set the value. In the StopLoss (and/or) TakeProfit parameter of the fnOpenOrder function, leave the radio-button selection on “Offset value” and set the value to MyAtrStop.



I added fnOpenOrder to the drawing pad, so it now looks like this:



Here is the MetaTrader price chart and terminal with this EA running. Note the stoploss and takeprofit values.