Open Order

From Boolean Trader
Jump to: navigation, search

Description

The Open Order function opens an order. This function will execute immediately if not inside a condition.

Syntax



Inputs

eaid
Identifies the Expert Advisor which has to perform the trade.

symbol
Forex pair for the order, such as EURUSD. Write it like this “EURUSD” and make sure the pair name matches exactly the name in MetaTrader. This is required and cannot be empty.

cmd
Command to execute. Supported values: 0 (buy), 1 (sell), 2 (buy limit pending), 3 (sell limit pending), 4 (buy stop pending), 5 (sell stop pending). It cannot be empty or given numbers other than the specified above. This is required and cannot be empty.

volume
How many lots to order. Minimum is 0.01 lot. Please check with your broker the minimum and maximum lot sizes. This is required and cannot be empty.

price
Price at which to place the order. If price is set to 0 then it will open order at market price on the tick.

slippage
Allowed difference (in pips not points) between requested price and market price when executing the order. If we say 3 pips slippage you accept to open an order anywhere between 3 pips above or below the price and 0 or no input mean you won't accept anything but the exact price. This is not required and can be empty.

stopLoss
Stop Loss is maximum loss on order you are willing to take and will close your order if price hit it. Stop loss line will be placed Above current price for Sell order and Below the current price for Buy orders. Its value is in Pips. For example if it were 20 pips and you want to change that to either a distance in account currency like 10 dollars or absolute price like 112.343 then you can change it in useAbsolutePrice and usePLDistances by setting one of them to 1. trailProfit or trailStop parameter will adjust this line so bear this in mind when you set both. Stop loss cannot accept negative values. Input ex. = 1.5 (for pips) 113.231 (for price) 11.5 (for account currency). This is not required and can be empty.

takeProfit
Take profit is maximum profit on order you are willing to take and will close your order if price hit it. Take profit line will be placed Above current price for Buy order and Below the current price for Sell orders. Its value is in Pips. For example 20 pips, and you want to change that to either a distance in account currency like 10 dollars or absolute price like 112.343 then you can change it in useAbsolutePrice and usePLDistances by setting one of them to 1. Stop loss cannot accept negative values. Input ex. = 1.5 (for pips) 113.231 (for price) 11.5 (for account currency). This is not required and can be empty.

comment
You can write up to 31 characters without commas “,” as a description for each order. This is useful for grouping orders or marking them in strategies. You can later search for what you wrote in full or in part in BT_CloseGroup function. This is not required and can be empty.

magic
This is your own private order ID it can be from 0 to 2 billion. Like the comment it is useful to group orders or to call them specifically in the BT_CloseGroup function.

expiration
Pending order expiration. For example if the input is 5 and the timeFrame parameter is not specified then the value it will wait for 5 M1 candles (5 minutes) before canceling the pending order, else if timeFrame parameter is set to "H1" then it will wait 5 H1 candles (5 hours). Please check with your broker on pending orders time limit. This is not required and can be empty.

newCandle
Open an order only on the new candle of the specified timeframe. For example, setting this to “H1” will only open an order in the first tick of the hour. This parameter accepts M1,M5,M15,M30,H1,H4,D1,W1,MN. This is not required and can be empty.

trailStop
This makes your stop loss line follow the current price with a pip distance. So when current price go away from it it will go after it and when price come close to it then it will not move until the price hits it and it closes the order. Bear in mind trailing stop start from a loss price and can trail order to profit. The value is in Pips only. This is not required and can be empty.

trailProfit
Trailing profit is the same as trailing stop but starting from profit price. So if you set profit at 50 pips, it will not do anything until you get 50 pips in profit, then it will put the line at the price you opened the order, then e.g. when you get 60 pips in profit the line will be moved to 10 pips in profit. This is not required and can be empty.

timeFrame
This is to specify the timeframe you want to work with the following parameters: Price, Expiration, Candle Distance, please read their description to know how they are affected by it. If left empty we assume you want to work with Ticks. Inputs can be M1,M5,M15,M30,H1,H4,D1,W1,MN. This is not required and can be empty.

pipDistance
This makes sure that there is a minimum pip distance between this order and the one before it. Applies to all orders with the same magic number. This is not required and can be empty.

timeDistance
This makes sure there is a candle distance between this order and the one before it. So if you set timeFrame parameter to H1 and this parameter to 2 then it will keep a space of two 1 hour candles between the orders. If you leave the timeFrame parameter empty it will assume 1M candle. You cannot use fractions. This is not required and can be empty.

maxOpenPerCell
This decides the maximum number of orders to open with this cell for this function. Let's say you don't want this cell to open more than 10 orders then you set it to 10. Zero or empty means unlimited. This is not required and can be empty.

useAbsolutePrice
Set to 1 for using absolute prices for Take Profit and Stop Loss (instead of pips). Make sure you if you set this to 1 then leave the usePLDistances parameter empty. This is not required and can be empty.

usePLDistances
Set it to 1 to use account currency amount for Take Profit, Stop Loss, Trail Stop and Trail Profit. Make sure you if you set this to 1 and leave the useAbsolutePrice parameter empty. This is not required and can be empty.

Outputs

Ready. Start Trading to place request
Awaiting start for execution.
Posted
Function executed. Bear in mind, because of some parameters like pipDistance or timeDistance it might still say "posted" while not actually opening any orders because one or more conditions have not been met.

Function Calculations

eaid symbol cmd volume price slippage stopLoss takeProfit comment magic expiration newCandle trailStop trailProfit timeFrame pipDistance maxOpenPerCell useAbsolutePrice usePLDistances
"tester" "EURUSD" 0 1 0 0 100 "risky" 12 "H1" 1 20
RESULT
It will open a 1 lot buy order in the EURUSD pair on the H1 timeframe at exact market price with a magic number of 12, a "risky" comment and a take profit of 100 pips while having a minimum distance of 1 pip between orders of the same magic number and a limit of maximum 20 orders.