¿Cómo codificar? - página 145

 

Hola Roger09,

Gracias de nuevo por tu ayuda. Mi objetivo es utilizar una secuencia de comandos para mover mi pérdida de la parada de romper incluso más x pips en un comercio de compra o romper incluso menos x pips en un comercio de venta. He establecido una tecla de acceso rápido para la secuencia de comandos para que pueda bloquear rápidamente en algunos beneficios cuando el comercio se mueve a mi favor. Sé que algunos ES'a tienen esta característica pero prefiero usar un script para poder hacerlo manualmente.

 

Progrmming un stop buy y stop sell

Hola,

Yo uso un EA con CCI.

Mi programa pone un buy cuando la barra precedente está sobre CCI>100, pero quiero comprar 5 pips más arriba de la última barra.

Quiero lo mismo con el stop de venta (5 pips por debajo del último mínimo)

Aquí mi EA, me pueden ayudar

Gracias

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

//| Este MQL es generado por el Expert Advisor Builder.

//| |

/+------------------- NO ELIMINE ESTA CABECERA --------------------+

#define SIGNAL_NONE 0

#define SEÑAL_BUY 1

#define SEÑAL_VENTA 2

#define SEÑAL_CLOSEBUY 3

#define SEÑAL_CLOSESELL 4

#propiedad copyright "Expert Advisor Builder"

#property link "http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/"

extern int NúmeroMágico = 0;

extern bool SignalMail = False;

extern bool EachTickMode = False

extern double Lots = 1.0

extern int Slippage = 30;

extern bool UseStopLoss = True

extern int StopLoss = 200;

extern bool UseTakeProfit = True

extern int TakeProfit = 600

extern bool UseTrailingStop = True

extern int TrailingStop = 250

int BarCount;

int Actual;

bool TickCheck = False;

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

//| función de inicialización de expertos ||.

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

int init() {

BarCount = Bars;

si (EachTickMode) Current = 0; si no, Current = 1;

return(0);

}

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

//| función de desinicialización experta ||.

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

int deinit() {

return(0);

}

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

//| función de inicio experta |

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

int inicio() {

int Orden = SIGNAL_NONE;

int Total, Ticket;

double StopLossLevel, TakeProfitLevel;

if (EachTickMode && Bars != BarCount) TickCheck = False;

Total = OrdersTotal();

Orden = SIGNAL_NONE;

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

//| Comienzo de la variable |++

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

double Var1 = iCCI(NULL, 0, 20, PRICE_CLOSE, Current + 0);

double Var2 = iCCI(NULL, 0, 20, PRICE_CLOSE, Current + 1);

double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Buy2_1 = Var1 ;

double Buy2_2 = 100;

double Buy3_1 = Var2 ;

double Buy3_2 = 100;

double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Venta2_1 = Var1 ;

double Sell2_2 = - 100

double Sell3_1 = Var2 ;

double Sell3_2 = - 100;

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

//| Fin de la variable

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

//Comprobar posición

bool IsTrade = False;

for (int i = 0; i < Total; i ++) {

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {

IsTrade = True;

if(OrderType() == OP_BUY) {

//Cerrar

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

//| Señal Inicio(Salida Compra) || /Cerrar

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

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

//| Señal de Fin(Salir de la Compra) |||

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

if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);

if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");

if (!EachTickMode) BarCount = Bars;

IsTrade = False;

continuar;

}

//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) BarCount = Bars;

continuar;

}

}

}

} else {

//Cerrar

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

//| Señal de inicio (salida de la venta)

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

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

//| Señal Fin(Salir de la venta) ||||++ //++

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

if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);

if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");

if (!EachTickMode) BarCount = Bars;

IsTrade = False;

continuar;

}

/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) BarCount = Bars;

continuar;

}

}

}

}

}

}

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

//| Señal Begin(Entry) |

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

si (Compra1_1 > Compra1_2 && Compra2_1 > Compra2_2 && Compra3_1 <= Compra3_2) Orden = SEÑAL_BUY;

if (Sell1_1 < Sell1_2 && Sell2_1 Sell3_2) Order = SIGNAL_SELL;

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

//| Fin de la señal |++

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

//Compra

if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

if(!IsTrade) {

//Comprobar el margen libre

if (AccountFreeMargin() < (1000 * Lots)) {

Print("No tenemos dinero. Margen libre = ", AccountFreeMargin());

return(0);

}

if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; si no, StopLossLevel = 0.0;

si (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; si no, TakeProfitLevel = 0.0;

Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);

if(Ticket > 0) {

if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {

Print("Orden de COMPRA abierta : ", OrderOpenPrice());

if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");

} else {

Print("Error al abrir la orden de COMPRA : ", GetLastError());

}

}

if (EachTickMode) TickCheck = True;

if (!EachTickMode) BarCount = Bars;

return(0);

}

}

/Vender

if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

if(!IsTrade) {

//Comprobar el margen libre

if (AccountFreeMargin() < (1000 * Lots)) {

Print("No tenemos dinero. Margen libre = ", AccountFreeMargin());

return(0);

}

if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; si no, StopLossLevel = 0.0;

si (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; si no, TakeProfitLevel = 0.0;

Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);

if(Ticket > 0) {

if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {

Print("Orden de venta abierta : ", OrderOpenPrice());

if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");

} else {

Print("Error al abrir una orden de VENTA : ", GetLastError());

}

}

if (EachTickMode) TickCheck = True;

if (!EachTickMode) BarCount = Bars;

return(0);

}

}

if (!EachTickMode) BarCount = Bars;

return(0);

}

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

 
tk748:
Hola Roger09, Gracias de nuevo por su ayuda. Mi objetivo es utilizar una secuencia de comandos para mover mi pérdida de la parada de romper incluso más x pips en un comercio de compra o romper incluso menos x pips en un comercio de venta. He establecido una tecla de acceso rápido para la secuencia de comandos para que pueda bloquear rápidamente en algunos beneficios cuando el comercio se mueve a mi favor. Sé que algunos ES'a tienen esta característica pero prefiero usar un script para poder hacerlo manualmente.

Si necesitas establecer tu stop sólo una vez, utiliza este código de EA

extern int pips=10;//

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

//| función de inicio del programa de scripting ||.

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

int inicio()

{

//----

int ot = PedidosTotal();

for (int i=0; i<ot; i++)

{

int o = OrderSelect(i, SELECT_BY_POS);

if (OrderSymbol() == Symbol()&&OrderType() <2)

{

double sl = 0;

if (OrderType() == OP_BUY&& OrderStopLoss() =pips*Point)

sl = OrderOpenPrice() +pips*Point;

si (OrderType() == OP_SELL && (OrderStopLoss() > OrderOpenPrice()||OrderStopLoss()==0)

&&OrderOpenPrice()-Ask>=pips*Point)

sl = OrderOpenPrice() -pips*Point;

if (!OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0))

Print("Error_Modificación - ",GetLastError());

}

}

//----

return(0);

}

 
cgassfr67:
Hola,

Yo uso un EA con CCI.

Mi programa pone una orden de compra cuando la barra precedente está por encima del CCI>100, pero quiero comprar 5 pips por encima de la última barra.

Quiero lo mismo con el stop de venta (5 pips por debajo del último mínimo)

Aquí mi EA, me pueden ayudar

Gracias

Reemplazar

double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Buy2_1 = Var1 ;

double Buy2_2 = 100;

double Buy3_1 = Var2 ;

double Buy3_2 = 100;

double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Sell2_1 = Var1 ;

double Sell2_2 = - 100;

double Sell3_1 = Var2 ;

double Sell3_2 = - 100;[/CODE]

To

[CODE]

double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Buy2_1 = Var1 ;

double Buy2_2 = 105;

double Buy3_1 = Var2 ;

double Buy3_2 = 105;

double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Sell2_1 = Var1 ;

double Sell2_2 = - 105;

double Sell3_1 = Var2 ;

double Sell3_2 = - 105;
 
Roger09:
Reemplazar
double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Buy2_1 = Var1 ;

double Buy2_2 = 100;

double Buy3_1 = Var2 ;

double Buy3_2 = 100;

double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Sell2_1 = Var1 ;

double Sell2_2 = - 100;

double Sell3_1 = Var2 ;

double Sell3_2 = - 100;[/CODE]

To

[CODE]

double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Buy2_1 = Var1 ;

double Buy2_2 = 105;

double Buy3_1 = Var2 ;

double Buy3_2 = 105;

double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Sell1_2 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Sell2_1 = Var1 ;

double Sell2_2 = - 105;

double Sell3_1 = Var2 ;

double Sell3_2 = - 105;

Sí, pero con este código, entraría en la apertura de la siguiente barra, y estaría seguro de que la siguiente barra aumentará, por lo que debe comprar con 5 pips sobre el último máximo

 

top of hour trade

Hola- Estoy buscando para invocar mi EA basado en la hora del día. tal vez 5am y 5pm, o cada 30 minutos, etc.

¿Cómo puedo hacer eso?

Muchas gracias por cualquier ayuda.

Kevin

 

Tal vez esto le ayude:

if((Hora(TimeLocal( ) )!=5&&TimeMinute(TimeLocal( ) )!=0)||(Hora(TimeLocal( ) )!=17

&&TimeMinute(TimeLocal( ) )!=0))return();

Póngalo al principio de start().

 

¿Podría alguien echar un vistazo a esto y decirme por qué no funciona?

Quiero utilizarlo como comentario.

double AvgWin()

{

double CountTrades = 0;

double CountPips = 0;

for(int Ticket=0;Ticket<OrdersHistoryTotal();Ticket++)

{

OrderSelect(Ticket,SELECT_BY_TICKET,MODE_HISTORY);

if(MyAccount==AccountNumber() && OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber)

{

//------>>>>

if(OrderType()==OP_BUY && OrderClosePrice()>=OrderOpenPrice())

CountTrades++;

{

if(OrderProfit() >= 0)

CountPips++;

}

if(OrderType()==OP_SELL && OrderClosePrice()<=OrderOpenPrice())

CountTrades++;

{

if(OrderProfit() >= 0)

CountPips++;

}

}

}

if(CountPips < 0)

return(MathRound(CountPips/CountTrades)*10);

si no

Print("AvgWin en tiempo real no disponible");

return(mAvgWin);

}

 

En primer lugar, sustituya

SELECT_BY_TICKET por SELECT_BY_POS

Segundo, CountPips siempre más que 0.

 
Roger09:
En primer lugar reemplazar

SELECT_BY_TICKET a SELECT_BY_POS

Segundo, CountPips siempre más que 0.

¿Esto está bien?

int AvgWin()

{

int CountTrades = 0;

int CountPips = 0;

for(int Ticket=0;Ticket<OrdersHistoryTotal();Ticket++)

{

OrderSelect(Ticket,SELECT_BY_POS,MODE_HISTORY);

if(MyAccount==AccountNumber() && OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber)

{

//------>>>>

if(OrderType()==OP_BUY && OrderClosePrice()>=OrderOpenPrice())

CountTrades++;

{

if(OrderProfit() >= 0)

CountPips++;

}

if(OrderType()==OP_SELL && OrderClosePrice()<=OrderOpenPrice())

CountTrades++;

{

if(OrderProfit() >= 0)

CountPips++;

}

}

}

if(CountPips > 0)

return(MathRound(CountPips/CountTrades)*10);

si no

Print("AvgWin en tiempo real no disponible");

return(mAvgWin);

}

Razón de la queja: