MQL4 - automated forex trading   /  

Code Base

Read Financial Magazines in MetaTrader 4 and MetaTrader 5!

Code Base  Expert Advisors  Place OCO Order, One pip Limit Order and One Pip Stop Order To post a new code, please log in or register

Download MetaTrader 5 and visit MQL5.community Code Base
and Trade on the Go!
and Trade on the Go!
Couldn't find the right code? Order it in the Jobs section

This Expert Advisor is for
MetaTrader 4
Download MT 4 - 455 Kb

and Trade on the Go!

and Trade on the Go!

Name:
Place OCO Order, One pip Limit Order and One Pip Stop Order
Author: Raymond (2011.04.01 10:31)
Rating: 9
Downloaded: 10174
Download:
 OCO_EA.mq4 (8.4 Kb) View

Description:

Places One-Cancels-the-Other Order (OCO Order), One pip Limit Order and One Pip Stop Order on MetaTrader 4 (MT4) platform.

Global variables:

  • OCO_BUY_LIMIT - Buy Limit Price
  • OCO_BUY_STOP - Buy Stop Price
  • OCO_SELL_LIMIT - Sell Limit Price
  • OCO_SELL_STOP - Sell Stop Price
  • OCO_confirmation - After input Buy Limit Price, Buy Stop Price, Sell Limit Price or Sell Stop Price set OCO_confirmation = "1"
  • OCO_lots - Lots
  • OCO_oCO - if OCO_oCO = "1", One Canel Others
  • OCO_sL_Pips - Stop Loss Pips
  • OCO_tP_Pips -Take Profit Pips

7 comments  To post a new comment, please log in or register

What am I doing wrong:

downloaded the EA into my MT4 experts folder - shut down the MT4 dealing station - double-clicked the EA, and compiled it. It now became .ex file - re-open MT4, OCO EA appears in experts (it has lost all colours, just like other EAs) - dragging it onto a chart, (click allow live trading) OCO EA appears in top right corner

but then what - nothing else happens: no dialog window for parameters pops up.

tky!


03.09.2013 22:12 NoMQL4Shark
hkjonus:

Sorry, 2 questions:

1. OCO? whats this EA supposed to do?


OCO stands for 'Order Cancels Other' This places two (pending) orders: both a Buy and a Sell order; When the market movement triggers one in the direction that is profitable, the other order is automatically cancelled. Here is a description from BabyPips.Com:

One-Cancels-the-Other (OCO)

An OCO order is a mixture of two entry and/or stop-loss orders. Two orders with price and duration variables are placed above and below the current price. When one of the orders is executed the other order is canceled.

Let's say the price of EUR/USD is 1.2040. You want to either buy at 1.2095 over the resistance level in anticipation of a breakout or initiate a selling position if the price falls below 1.1985. The understanding is that if 1.2095 is reached, your buy order will be triggered and the 1.1985 sell order will be automatically canceled.

Read more: http://www.babypips.com/school/types-of-orders.html#ixzz1RX7qZaJg
08.07.2011 20:51 FourX

Hi,

I haven't tried this yet. But as a NuB wanting to build up a Library of reusable programming modules and looking for OCO, which I didn't expect to be native to MQL4; a very hearty 'Thanks: VERY nice! (< 8)

OTO = One-Triggers-the-Other Module?

08.07.2011 20:42 FourX
somaare:

thanks but in fact i have some question

how could this EA place pending order about 1 pip from current price while the broker doesn't accept below 5 pips ( descibe the idea )

i put it on chart and it didn't place any orders how does it work

i need such expert but to place only sellstop and buystop from 1 or 2 pips from the current price


No conern the broker doesn't accept below 5 pips

Market Price Bid 1.44226 Ask 1.44250

OCO_BUY_STOP - Buy Stop Price set to "1.44260"

OCO_SELL_STOP - Sell Stop Price set to "1.44216"

OCO_confirmation - set "1"

OCO_oCO - if OCO_oCO = "1", One Canel Others

OCO_sL_Pips - Stop Loss Pips set to "50"

OCO_tP_Pips -Take Profit Pips set to "50"

Fine

15.06.2011 09:45 fxpingpong

thanks but in fact i have some question

how could this EA place pending order about 1 pip from current price while the broker doesn't accept below 5 pips ( descibe the idea )

i put it on chart and it didn't place any orders how does it work

i need such expert but to place only sellstop and buystop from 1 or 2 pips from the current price

14.06.2011 10:37 somaare
hkjonus:

Sorry, 2 questions:

1. OCO? whats this EA supposed to do?

2. what does // InitGlobalVar = (InitGlobalVar || true) // do?


1. i) OCO (One Cancels the Others Order).

ii) All Broker limit the pending order price which differ to market price 2-3 pips.

Market Price Bid: 1.40000 Ask : 1.40020
You can not place Limit Buy Pending Order at 1.40010.
Use this OCO_EA, you can set to limit Buy at 1.40010 or 1.40016 (No limit).

2. Sorry, InitGlobalVar = (InitGlobalVar || true) is used for debuging, they are redundant !

End of reply

------------------------------------------------------------------------------------------------------------

A Expert Advisor MonitorScreen.mq4 will be release on 8-15 April 2011

After open a trade,
i) take a screen shot in METATRADER/expert/files .
ii) notice to you via email.

02.04.2011 21:25 fxpingpong

Sorry, 2 questions:

1. OCO? whats this EA supposed to do?

2. what does // InitGlobalVar = (InitGlobalVar || true) // do?

02.04.2011 09:34 hkjonus