Me Gusta y Comparto
Get Adobe Flash player

Ideas para este primer EA que he creado

Ver el tema anterior Ver el tema siguiente Ir abajo

Ideas para este primer EA que he creado

Mensaje  Invitado el Dom Dic 18, 2011 3:20 pm

Buenos días...

Hace algún tiempo estoy dedicado (de forma autonoma, no vendo robot) a diseñar algunos robots con el fin de facilitar un poco el trading y poder salir de delante de la pantalla sin pensar "Perderé la operación" o peor aún "para que salí de acá si era obvio que el precio se iba a mover"...la ley de murphy es terrible!

En fin... sobre el EA (basado en otro ea que se llama Generic Breakout V5.5):

Yo lo uso en una hora, tiene un TP de 30 y SL de 60, y pese a que las pribabilidad se dan en contra ha sido bueno.
Basicamente el robot mostrará en el gráfico las siguientes líneas :

Dos lineas verticales punteadas de color rojo, las cuales se usan para determinar el horario en que se quiere considerar el rango.

Dos lineas (una roja y otra lima) punteadas...esas son los rangos superior e inferior. Estrictamente hablando la roja es el rango y la lima es para la entrada (unos puntos más arriba o abajo del rango según compra o venta).

La linea azul sólida = Precio de apertura diaria

La linea rosada (bajo el rango bajo) = -0.24 % en la cotización
La linea roja (bajo el rango también) = -0.50 % en la cotización
La linea magenta (bajo el rango minimo) = -0.75 % en la cotización
(la misma idea para las lineas verdes sobre el rango alto)

Estas líneas las uso porque usaba un indicador que se llama lineas de porcentaje, pero lo usaba en PRT y en MT4 no está creo.

Además se puede delimitar la cantidad de trades al día, por ejemplo si queremos que haga 1 solo o 2 o 10 por día (siempre y cuando cumpla las condiciones...no creo que haga 10 ni aunque se le permita, jajaja)

Condiciones de entrada:
un cierre sobre el rango máximo / la vela con mas de 15 pips / MACD sobre 0.0005 / la apertura de la vela menor al 0.24% pero el cierre mayor que el 0.24% / tiene que ser entre las 3 y 12 horas (porque mi broker tiene horario de NY)

La misma idea para las ventas.

En fin, si no es como robot, por lo menos es muy util para saber como está el mercado (para aquellos que lo descarguen). Pero, si a alguien se le ocurre una idea de algún aspecto que se le pudiese mejorar al robot...que me lo haga saber e intentaré hacerlo...por lo pronto lel siguiente aspecto no lo mejora:

Cierre parcial de lotes en +20 y +40 (1/2 en cada uno)
El horario me parece que es el más optimo, porque estamos entre la apertura europea y la 1/2 de la sesión de nueva york

El testeo es desde junio de 2010 hasta hoy, porque tengo unos baches importantísimos en los historicos,
no se si lo hacen a proposito para que uno no pueda probar con exactitud un robot o si es un error hecho por mi. Si alguien ha bajado los historicos y le quedan completos que me diga el broker asi abro una demo y los descargo.

Imagen en http://img13.imageshack.us/content_round.php?page=done&l=img13/5576/43865555.gif

Pego el robot aqui debajo porque no se como subirlo

//+------------------------------------------------------------------+
//| Mi EA.mq4 |
//| Copyright © 2011, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
//+------------------------------------------------------------------+
#define SIGNAL_NONE 0
#define SIGNAL_BUY 1
#define SIGNAL_SELL 2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4

#property copyright "Ronald Raygun"

extern string Remark1 = "== Main Settings ==";
extern int MagicNumber = 0;
extern bool SignalsOnly = False;
extern bool Alerts = False;
extern bool SignalMail = False;
extern bool PlaySounds = true;
extern bool EachTickMode = False;
extern double Lots = 1.0;
extern bool MoneyManagement = false;
extern int Risk = 0;
extern int Slippage = 5;
extern bool UseStopLoss = true;
extern bool UsePercentageStopLoss = False;
extern int PercentofRangeSL = 50;
extern bool UseFixedStopLoss = True;
extern int StopLoss = 60;
extern bool UseTakeProfit = True;
extern bool UsePercentageTakeProfit = False;
extern int PercentofRangeTP = 100;
extern bool UseFixedTakeProfit = True;
extern int TakeProfit = 30;
extern bool UseTrailingStop = True;
extern int TrailingStop = 80;
extern bool MoveStopOnce = true;
extern int MoveStopWhenPrice = 25;
extern int MoveStopTo = 1;
extern string Remark2 = "";
extern string Remark3 = "== Breakout Settings ==";
extern string StartTime = "00:00";
extern string EndTime = "04:00";
extern string ResetTime = "23:00";
extern int BreakoutBuffer = 15;
extern int BreakoutBuffer1 = 15;
extern bool UseMaxRange = false;
extern int MaxRange = 60;
extern int MaxTradesPerDay = 2;
extern int MaxLongTrades = 1;
extern int MaxShortTrades = 1;
extern double M = 15;



//Version 2.01

int OpenBarCount;
int CloseBarCount;

int RemainingTrades;
int RemainingLongs;
int RemainingShorts;

int Current;
bool TickCheck = False;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init() {
OpenBarCount = Bars;
CloseBarCount = Bars;

RemainingTrades = MaxTradesPerDay;
RemainingLongs = MaxLongTrades;
RemainingShorts = MaxShortTrades;

if (EachTickMode) Current = 0; else Current = 1;

return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit() {

ObjectDelete("LowerEntry");
ObjectDelete("UpperEntry");
ObjectDelete("LowerRange");
ObjectDelete("UpperRange");
ObjectDelete("EndTime");
ObjectDelete("StartTime");
ObjectDelete("apertura");
ObjectDelete("primero");
ObjectDelete("segundo");
ObjectDelete("tercero");
ObjectDelete("cuarto");
ObjectDelete("primero2");
ObjectDelete("segundo2");
ObjectDelete("tercero2");
ObjectDelete("cuarto2");

return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()


{
int Order = SIGNAL_NONE;
int Total, Ticket;
double StopLossLevel, TakeProfitLevel;



if (EachTickMode && Bars != CloseBarCount) TickCheck = False;
Total = OrdersTotal();
Order = SIGNAL_NONE;

//Money Management sequence
if (MoneyManagement)
{
if (Risk<1 || Risk>100)
{
Comment("Invalid Risk Value.");
return(0);
}
else
{
Lots=MathFloor((AccountFreeMargin()*AccountLeverage()*Risk*Point*100)/(Ask*MarketInfo(Symbol(),MODE_LOTSIZE)*MarketInfo(Symbol(),MODE_MINLOT)))*MarketInfo(Symbol(),MODE_MINLOT);
}
}

//+------------------------------------------------------------------+
//| Variable Begin |
//+------------------------------------------------------------------+



/*
//Find End Time Shift
int EndTimeShift = 1;
int EndTimeUsed = 0;
bool EndTimeFound = False;

while (!EndTimeFound)
{
if(TimeHour(Time[EndTimeShift + 1]) <= EndHour && TimeHour(Time[EndTimeShift]) >= EndHour && TimeMinute(Time[EndTimeShift + 1]) <= EndMinute && TimeMinute(Time[EndTimeShift]) >= EndMinute)
{
EndTimeFound = True;
EndTimeUsed = EndTimeShift;
}
else
{
EndTimeShift++;
}
}

//Find the most recent Start Time before end time
bool StartTimeFound = False;
int StartTimeShift = EndTimeUsed;
int StartTimeShiftUsed = 0;

while (!StartTimeFound)
{
if(TimeHour(Time[StartTimeShift + 1]) <= StartHour && TimeHour(Time[StartTimeShift]) >= StartHour && TimeMinute(Time[StartTimeShift + 1]) <= StartMinute && TimeMinute(Time[StartTimeShift]) >= StartMinute)
{
StartTimeFound = True;
StartTimeShiftUsed = StartTimeShift;
}
else
{
StartTimeShift++;
//Print("Here I am: 1");
}
//Print("Here I am: 2");
}
*/
//////////////////////////////////////////////////////////////////////////////////////
//The following block of code is courtesy of Hanover from ForexFactory.///////////////
//////////////////////////////////////////////////////////////////////////////////////
double dt0 = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) + " 00:00:00");
double dt1 = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) + " " + StartTime + ":00");
double dt2 = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) + " " + EndTime + ":00");
double dt3 = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) + " " + ResetTime + ":00");
if (dt3 < dt2) dt3 += 86400;
if (dt1 > dt2) dt1 -= 86400;
int StartTimeShift = iBarShift(NULL,0,dt1, false);
int EndTimeShift = iBarShift(NULL,0,dt2, false);
if (TimeCurrent() >= dt2 && TimeCurrent() <= dt3) {
double RangeHigh = iHigh(NULL, 0, iHighest(NULL, 0, MODE_HIGH, (StartTimeShift - EndTimeShift), EndTimeShift));
double RangeLow = iLow(NULL, 0, iLowest(NULL, 0, MODE_LOW, (StartTimeShift - EndTimeShift), EndTimeShift));


}
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
//Reset Remaining Trades Count
if(Time[1] < dt3 && Time[0] >= dt3)
{
RemainingTrades = MaxTradesPerDay;
RemainingLongs = MaxLongTrades;
RemainingShorts = MaxShortTrades;
}

if(MaxTradesPerDay == 0)
{
RemainingTrades = 9999;
}

if(MaxLongTrades == 0)
{
RemainingLongs = 9999;
}
if(MaxShortTrades == 0)
{
RemainingShorts = 9999;
}

double UpperEntry = RangeHigh + (BreakoutBuffer1 * Point);
double LowerEntry = RangeLow - (BreakoutBuffer * Point);
double medio = (RangeHigh + RangeLow) / 2;

double apertura = iOpen(NULL, 1440, 0);

double primero = apertura + (apertura * 0.24/100);
double segundo = apertura + (apertura * 0.5/100);
double tercero = apertura + (apertura * 0.63/100);
double cuarto = apertura + (apertura * 1.0/100);

double primero2 = apertura - (apertura * 0.24/100);
double segundo2 = apertura - (apertura * 0.5/100);
double tercero2 = apertura - (apertura * 0.63/100);
double cuarto2 = apertura - (apertura * 1.0/100);

double velaA = Close[1] - Open[1];
double velaB = Open[1] - Close[1];

double pips = 15 * Point;
double MACD1 = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 1);

string RangeStatus = "Cannot Trade";
if(UseMaxRange && (RangeHigh - RangeLow) <= (MaxRange * Point)) RangeStatus = "Can Trade";
if(!UseMaxRange) RangeStatus = "Not Used";

string TradeTrigger = "None";


//CCCCOOOMMMPPPRRRRAAASSS-----------------------------
if(RemainingTrades > 0 && RemainingLongs > 0 && RangeStatus != "Cannot Trade" && Close[1] >= UpperEntry && velaA > pips && MACD1 > 0.0005 && Open[1] < primero && Close[1] > primero && Hour() > 3 && Hour() < 12 ) TradeTrigger = "Open Long";//cambie Ask por Close[1] y Open[0] por Close[2]
if(RemainingTrades > 0 && RemainingLongs > 0 && RangeStatus != "Cannot Trade" && Close[1] >= UpperEntry && velaA > pips && MACD1 > 0.0005 && Open[1] < segundo && Close[1] > segundo && Hour() > 3 && Hour() < 12 ) TradeTrigger = "Open Long";//cambie Ask por Close[1] y Open[0] por Close[2]
if(RemainingTrades > 0 && RemainingLongs > 0 && RangeStatus != "Cannot Trade" && Close[1] >= UpperEntry && velaA > pips && MACD1 > 0.0005 && Open[1] < segundo && Close[1] > tercero && Hour() > 3 && Hour() < 12 ) TradeTrigger = "Open Long";//cambie Ask por Close[1] y Open[0] por Close[2]
if(RemainingTrades > 0 && RemainingLongs > 0 && RangeStatus != "Cannot Trade" && Close[1] >= UpperEntry && velaA > pips && MACD1 > 0.0005 && Open[1] < primero && Close[1] > segundo && Hour() > 3 && Hour() < 12 ) TradeTrigger = "Open Long";//cambie Ask por Close[1] y Open[0] por Close[2]
if(RemainingTrades > 0 && RemainingLongs > 0 && RangeStatus != "Cannot Trade" && Close[1] >= UpperEntry && velaA > pips && MACD1 > 0.0005 && Open[1] < cuarto && Close[1] > cuarto && Hour() > 3 && Hour() < 12 ) TradeTrigger = "Open Long";//cambie Ask por Close[1] y Open[0] por Close[2]




if(RemainingTrades > 0 && RemainingShorts > 0 && RangeStatus != "Cannot Trade" && Close[1] <= LowerEntry && velaB > pips && MACD1 < -0.0005 && Open[1] > primero2 && Close[1] < primero2 && Hour() > 3 && Hour() < 12 ) TradeTrigger = "Open Short";//cambie Bid por Close[1]y Open[0] por Close[2]
if(RemainingTrades > 0 && RemainingShorts > 0 && RangeStatus != "Cannot Trade" && Close[1] <= LowerEntry && velaB > pips && MACD1 < -0.0005 && Open[1] > segundo2 && Close[1] < segundo2 && Hour() > 3 && Hour() < 12 ) TradeTrigger = "Open Short";//cambie Bid por Close[1]y Open[0] por Close[2]
if(RemainingTrades > 0 && RemainingShorts > 0 && RangeStatus != "Cannot Trade" && Close[1] <= LowerEntry && velaB > pips && MACD1 < -0.0005 && Open[1] > segundo2 && Close[1] < tercero2 && Hour() > 3 && Hour() < 12 ) TradeTrigger = "Open Short";//cambie Bid por Close[1]y Open[0] por Close[2]
if(RemainingTrades > 0 && RemainingShorts > 0 && RangeStatus != "Cannot Trade" && Close[1] <= LowerEntry && velaB > pips && MACD1 < -0.0005 && Open[1] > primero2 && Close[1] < segundo2 && Hour() > 3 && Hour() < 12 ) TradeTrigger = "Open Short";//cambie Bid por Close[1]y Open[0] por Close[2]
if(RemainingTrades > 0 && RemainingShorts > 0 && RangeStatus != "Cannot Trade" && Close[1] <= LowerEntry && velaB > pips && MACD1 < -0.0005 && Open[1] > cuarto2 && Close[1] < cuarto2 && Hour() > 3 && Hour() < 12 ) TradeTrigger = "Open Short";//cambie Bid por Close[1]y Open[0] por Close[2]

//Print("Here I am: 3");

Comment("Range Status: ", RangeStatus, "\n",
"Remaining Trades: ", RemainingTrades, "\n",
"Remaining Longs: ", RemainingLongs, "\n",
"Remaining Shorts: ", RemainingShorts, "\n",
"Trade Trigger: ", TradeTrigger);

ObjectDelete("StartTime");
ObjectCreate("StartTime", OBJ_VLINE, 0, Time[StartTimeShift], 0);
ObjectSet("StartTime", OBJPROP_COLOR, Red);
ObjectSet("StartTime", OBJPROP_STYLE, STYLE_DASHDOT);

ObjectDelete("EndTime");
ObjectCreate("EndTime", OBJ_VLINE, 0, Time[EndTimeShift], 0);
ObjectSet("EndTime", OBJPROP_COLOR, Red);
ObjectSet("EndTime", OBJPROP_STYLE, STYLE_DASHDOT);

ObjectDelete("UpperRange");
ObjectCreate("UpperRange", OBJ_HLINE, 0, 0, RangeHigh);
ObjectSet("UpperRange", OBJPROP_COLOR, Red);
ObjectSet("UpperRange", OBJPROP_STYLE, STYLE_DASHDOT);

ObjectDelete("LowerRange");
ObjectCreate("LowerRange", OBJ_HLINE, 0, 0, RangeLow);
ObjectSet("LowerRange", OBJPROP_COLOR, Red);
ObjectSet("LowerRange", OBJPROP_STYLE, STYLE_DASHDOT);

ObjectDelete("UpperEntry");
ObjectCreate("UpperEntry", OBJ_HLINE, 0, 0, UpperEntry);
ObjectSet("UpperEntry", OBJPROP_COLOR, Lime);
ObjectSet("UpperEntry", OBJPROP_STYLE, STYLE_DASHDOT);

ObjectDelete("LowerEntry");
ObjectCreate("LowerEntry", OBJ_HLINE, 0, 0, LowerEntry);
ObjectSet("LowerEntry", OBJPROP_COLOR, Lime);
ObjectSet("LowerEntry", OBJPROP_STYLE, STYLE_DASHDOT);

ObjectDelete("apertura");
ObjectCreate("apertura", OBJ_HLINE, 0, 3, apertura);
ObjectSet("apertura", OBJPROP_COLOR, Blue);
ObjectSet("apertura", OBJPROP_STYLE, STYLE_SOLID);

ObjectDelete("primero");
ObjectCreate("primero", OBJ_HLINE, 0, 0, primero);
ObjectSet("primero", OBJPROP_COLOR, Lime);
ObjectSet("primero", OBJPROP_STYLE, STYLE_DASHDOT);

ObjectDelete("segundo");
ObjectCreate("segundo", OBJ_HLINE, 0, 0, segundo);
ObjectSet("segundo", OBJPROP_COLOR, Green);
ObjectSet("segundo", OBJPROP_STYLE, STYLE_DASHDOTDOT);

ObjectDelete("tercero");
ObjectCreate("tercero", OBJ_HLINE, 0, 0, tercero);
ObjectSet("tercero", OBJPROP_COLOR, DarkGreen);
ObjectSet("tercero", OBJPROP_STYLE, STYLE_DOT);

ObjectDelete("cuarto");
ObjectCreate("cuarto", OBJ_HLINE, 0, 0, cuarto);
ObjectSet("cuarto", OBJPROP_COLOR, Black);
ObjectSet("cuarto", OBJPROP_STYLE, STYLE_SOLID);

ObjectDelete("primero2");
ObjectCreate("primero2", OBJ_HLINE, 0, 0, primero2);
ObjectSet("primero2", OBJPROP_COLOR, Pink);
ObjectSet("primero2", OBJPROP_STYLE, STYLE_DASHDOT);

ObjectDelete("segundo2");
ObjectCreate("segundo2", OBJ_HLINE, 0, 0, segundo2);
ObjectSet("segundo2", OBJPROP_COLOR, Red);
ObjectSet("segundo2", OBJPROP_STYLE, STYLE_DASHDOTDOT);

ObjectDelete("tercero2");
ObjectCreate("tercero2", OBJ_HLINE, 0, 0, tercero2);
ObjectSet("tercero2", OBJPROP_COLOR, Magenta);
ObjectSet("tercero2", OBJPROP_STYLE, STYLE_DOT);

ObjectDelete("cuarto2");
ObjectCreate("cuarto2", OBJ_HLINE, 0, 0, cuarto2);
ObjectSet("cuarto2", OBJPROP_COLOR, Black);
ObjectSet("cuarto2", OBJPROP_STYLE, STYLE_SOLID);

//+------------------------------------------------------------------+
//| Variable End |
//+------------------------------------------------------------------+

//Check position
bool IsTrade = False;

for (int i = 0; i < Total; i ++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
IsTrade = True;
if(OrderType() == OP_BUY) {


//Close

//+------------------------------------------------------------------+
//| Signal Begin(Exit Buy) |
//+------------------------------------------------------------------+


//if ( Hour() == 23 && Minute() == 00) Order = SIGNAL_CLOSEBUY;
// if (Close[1] < apertura ) Order = SIGNAL_CLOSEBUY;


//+------------------------------------------------------------------+
//| Signal End(Exit Buy) |
//+------------------------------------------------------------------+

if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != CloseBarCount)))) {
OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Bid, Digits), Slippage, MediumSeaGreen);
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
if (!EachTickMode) CloseBarCount = Bars;
IsTrade = False;
continue;
}
//MoveOnce
if(MoveStopOnce && MoveStopWhenPrice > 0) {
if(Bid - OrderOpenPrice() >= Point * MoveStopWhenPrice) {
if(OrderStopLoss() < OrderOpenPrice() + Point * MoveStopTo) {
OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() + Point * MoveStopTo, OrderTakeProfit(), 0, Red);
if (!EachTickMode) CloseBarCount = Bars;
continue;
}
}
}
//Trailing stop
if(UseTrailingStop && TrailingStop > 0) {
if(Bid - OrderOpenPrice() > Point * TrailingStop) {
if(OrderStopLoss() < Bid - Point * TrailingStop) {
OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
if (!EachTickMode) CloseBarCount = Bars;
continue;
}
}
}
} else {

//Close

//+------------------------------------------------------------------+
//| Signal Begin(Exit Sell) |
//+------------------------------------------------------------------+

// if (Hour() == 23 && Minute() == 00) Order = SIGNAL_CLOSESELL;
// if (Close[1] > apertura) Order = SIGNAL_CLOSESELL;


//+------------------------------------------------------------------+
//| Signal End(Exit Sell) |
//+------------------------------------------------------------------+

if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != CloseBarCount)))) {
OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Ask, Digits), Slippage, DarkOrange);
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
if (!EachTickMode) CloseBarCount = Bars;
IsTrade = False;
continue;
}
//MoveOnce
if(MoveStopOnce && MoveStopWhenPrice > 0) {
if(OrderOpenPrice() - Ask >= Point * MoveStopWhenPrice) {
if(OrderStopLoss() > OrderOpenPrice() - Point * MoveStopTo) {
OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() - Point * MoveStopTo, OrderTakeProfit(), 0, Red);
if (!EachTickMode) CloseBarCount = Bars;
continue;
}
}
}
//Trailing stop
if(UseTrailingStop && TrailingStop > 0) {
if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {
OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
if (!EachTickMode) CloseBarCount = Bars;
continue;
}
}
}
}
}
}

//+------------------------------------------------------------------+
//| Signal Begin(Entry) |
//+------------------------------------------------------------------+

if(TradeTrigger == "Open Long") Order = SIGNAL_BUY;
if(TradeTrigger == "Open Short") Order = SIGNAL_SELL;

//+------------------------------------------------------------------+
//| Signal End |
//+------------------------------------------------------------------+

//Buy
if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != OpenBarCount)))) {
if(SignalsOnly) {
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + "Buy Signal");
if (Alerts) Alert("[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + "Buy Signal");
if (PlaySounds) PlaySound("alert.wav");

}

if(!IsTrade && !SignalsOnly) {
//Check free margin
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}

if (UseStopLoss && UsePercentageStopLoss && Ask - ((RangeHigh - RangeLow) * (PercentofRangeSL * 0.01)) > StopLossLevel) StopLossLevel = Ask - ((RangeHigh - RangeLow) * (PercentofRangeSL / 100) );
if (UseStopLoss && UseFixedStopLoss && Ask - (StopLoss * Point) > StopLossLevel) StopLossLevel = Ask - (StopLoss * Point);
//if (UseStopLoss && (Ask - StopLossLevel) / Point < MarketInfo(NULL, MODE_STOPLEVEL)) StopLossLevel = Ask - MarketInfo(NULL, MODE_STOPLEVEL);
if (!UseStopLoss) StopLossLevel = 0.0;


if (UseTakeProfit && UsePercentageTakeProfit && Ask + ((RangeHigh - RangeLow) * (PercentofRangeTP * 0.01)) > TakeProfitLevel) TakeProfitLevel = Ask + ((RangeHigh - RangeLow) * (PercentofRangeTP / 100));
if (UseTakeProfit && UseFixedTakeProfit && Ask + (TakeProfit * Point) > TakeProfitLevel) TakeProfitLevel = Ask + TakeProfit * Point;
if (!UseTakeProfit) TakeProfitLevel = 0.0;
Print("TakeProfit: ", TakeProfitLevel);

//ticket____________________________cambiado a NormalizeDouble el Ask
Ticket = OrderSend(Symbol(), OP_BUY, Lots, NormalizeDouble(Ask, Digits), Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
/*
//ticket II

Ticket = OrderSend(Symbol(), OP_BUY, Lots, NormalizeDouble(Ask, Digits), Slippage, Ask - 30 * Point, Ask + 40 * Point, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
*/
if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("BUY order opened : ", OrderOpenPrice());
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + "Buy Signal");
if (Alerts) Alert("[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + "Buy Signal");
if (PlaySounds) PlaySound("alert.wav");
RemainingTrades--;
RemainingLongs--;
} else {
Print("Error opening BUY order : ", GetLastError());
}
}
if (EachTickMode) TickCheck = True;
if (!EachTickMode) OpenBarCount = Bars;
return(0);
}
}

//Sell
if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != OpenBarCount)))) {
if(SignalsOnly) {
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + "Sell Signal");
if (Alerts) Alert("[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + "Sell Signal");
if (PlaySounds) PlaySound("alert.wav");
}
if(!IsTrade && !SignalsOnly) {
//Check free margin
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}

if (UseStopLoss && UsePercentageStopLoss && Bid + ((RangeHigh - RangeLow) * (PercentofRangeSL * 0.01)) > StopLossLevel) StopLossLevel = Bid + ((RangeHigh - RangeLow) * (PercentofRangeSL / 100) );
if (UseStopLoss && UseFixedStopLoss && Bid + (StopLoss * Point) > StopLossLevel) StopLossLevel = Bid + (StopLoss * Point);
//if (UseStopLoss && (Bid + StopLossLevel) / Point < MarketInfo(Symbol(0, MODE_STOPLEVEL)) StopLossLevel = Bid + MarketInfo(NULL, MODE_STOPLEVEL);
if (!UseStopLoss) StopLossLevel = 0.0;

if (UseTakeProfit && UsePercentageTakeProfit && Bid - ((RangeHigh - RangeLow) * (PercentofRangeTP * 0.01)) > TakeProfitLevel) TakeProfitLevel = Bid - ((RangeHigh - RangeLow) * (PercentofRangeTP / 100));
if (UseTakeProfit && UseFixedTakeProfit && Bid - (TakeProfit * Point) > TakeProfitLevel) TakeProfitLevel = Bid - TakeProfit * Point;
if (!UseTakeProfit) TakeProfitLevel = 0.0;
Print("TakeProfit: ", TakeProfitLevel);

//ticket_______________cambiado NormalizeDouble Bid
Ticket = OrderSend(Symbol(), OP_SELL, Lots, NormalizeDouble(Bid, Digits), Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
/*
//ticket II

Ticket = OrderSend(Symbol(), OP_SELL, Lots, NormalizeDouble(Bid, Digits), Slippage, Bid + 30 * Point, Bid - 40 * Point, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
*/
if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("SELL order opened : ", OrderOpenPrice());
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + "Sell Signal");
if (Alerts) Alert("[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + "Sell Signal");
if (PlaySounds) PlaySound("alert.wav");
RemainingTrades--;
RemainingShorts--;
} else {
Print("Error opening SELL order : ", GetLastError());
}
}
if (EachTickMode) TickCheck = True;
if (!EachTickMode) OpenBarCount = Bars;
return(0);
}
}

if (!EachTickMode) CloseBarCount = Bars;

return(0);
}

Invitado
Invitado


Volver arriba Ir abajo

Ver el tema anterior Ver el tema siguiente Volver arriba


 
Permisos de este foro:
No puedes responder a temas en este foro.