Regisztráció Elfelejtett jelszó

Re: Import

Amatoregy Előzmény: #540077

oco_sajat. (se indikatorkenr, se expertkent nem latja..)

OCO.mq4 is One Cancels the Other script. It should be put in

MetatradeInstall/experts/scripts folder and after compilation it

will be available in Navigator/Scripts.

With default parameters it opens two pending stop orders, one for

sell and one for buy. This is also known as Straddle and very

popular among News Trades. One have a possibility to

change order type, set Slippage and Expiration. Also

when StopLoss and/or TakeProfits are set to different value than 0

this value will be used during sending orders.

One should note, that setting pending orders require that they

are put in minimum distance from a market price, Ask for BUYSTOP

and Bid for SELLSTOP. This minimum price is different among

brokers and can be found in Symbol Properties as Stops level.

Most of brokers have value 5 which means that a BUYSTOP can be

put with minimum distance of 6 pips above Ask, and SELLSTOP 6

pips below Bid. In case that orders are set too close then

'ERROR #130 : invalid stops' message is put.

MQL Service, 24/01/2007

*/

//| $Id: //mqlservice/mt4files/experts/scripts/OCO.mq4#1 $

//+------------------------------------------------------------------+

#property copyright "Copyright Š 2007, MQL Service"

#property link " http://www.mqlservice.com"

#property show_inputs

//---- Parametres Externes --- changed the orders to my preference

extern double BuyOrderPrice = 0.0000;

extern double BuyLots = 0.01;

extern int BuyStopLoss = 100;

extern int BuyTakeProfit = 30;

extern double SellOrderPrice = 0.0000;

extern double SellLots = 0.01;

extern int SellStopLoss = 100;

extern int SellTakeProfit = 30;

extern int BuyOrderType = OP_BUYSTOP;

extern int SellOrderType = OP_SELLSTOP;

extern int Slippage = 5;

extern int Magic = 20070401;

//---- Section Define

#define LABEL "OCOLabel"

#define TIMEOUT 3

//---- Variables

double bsl,ssl,btp,stp;

int bt,st;

bool cont = false;

bool flip = true;

int err1,err;

//+------------------------------------------------------------------+

//| script program start function |

//+------------------------------------------------------------------+

int start()

{

//----

if(BuyStopLoss > 0)

bsl = BuyOrderPrice - BuyStopLoss*Point;

else

bsl = 0.0;

if(SellStopLoss > 0)

ssl = SellOrderPrice + SellStopLoss*Point;

else

ssl = 0.0;

if(BuyTakeProfit > 0)

btp = BuyOrderPrice + BuyTakeProfit*Point;

else

btp = 0.0;

if(SellTakeProfit > 0)

stp = SellOrderPrice - SellTakeProfit*Point;

else

stp = 0.0;

bt = OrderSend(Symbol(), BuyOrderType, BuyLots, BuyOrderPrice, Slippage, bsl, btp, "Buy OCO", Magic, 0, Blue);

if(CheckError())

{

RemoveOrder(st); //Added this because when it buys, the sell order didn't cancel - Felipe Penna

return(-1);

}

st = OrderSend(Symbol(), SellOrderType, SellLots, SellOrderPrice, Slippage, ssl, stp, "Sell OCO", Magic, 0, Red);

if(CheckError())

{

RemoveOrder(bt);

return(-1);

}

cont = IsTradeAllowed();

err1 = 0;

while(cont)

{

if(flip)

ShowLabel();

else

HideLabel();

flip = !flip;

err = 0;

if(OrderSelect(bt, SELECT_BY_TICKET, MODE_TRADES))

{

if(OrderType() TIMEOUT)

cont = false;

Sleep(500);

cont = cont && IsTradeAllowed();

}

HideLabel();

//----

return(0);

}

//+------------------------------------------------------------------+

//+------------------------------------------------------------------+

//| script program VOID functions |

//+------------------------------------------------------------------+

#include

#include

void ShowLabel()

{

ObjectCreate(LABEL, OBJ_LABEL, 0, 0, 0);

ObjectSet(LABEL, OBJPROP_CORNER, 2);

ObjectSet(LABEL, OBJPROP_XDISTANCE, 4);

ObjectSet(LABEL, OBJPROP_YDISTANCE, 2);

ObjectSetText(LABEL, "OCO by http://www.mqlservice.com modified by Felipe Penna", 8, "Arial", Red);

WindowRedraw();

}

void HideLabel()

{

ObjectDelete(LABEL);

WindowRedraw();

}

bool CheckError()

{

int err = GetLastError();

if(err == ERR_NO_ERROR) return(false);

Print("ERROR #",err,": ",ErrorDescription(err));

Alert("ERROR #",err,": ",ErrorDescription(err));

return(true);

}

void RemoveOrder(int ticket)

{

if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))

if(OrderType() <= OP_SELL)

OrderClose(ticket, OrderLots(), OrderClosePrice(), Slippage);

else

OrderDelete(ticket);

CheckError();

}

//+---- Coded by M. Rutka -------------------------------------------+