¿Cómo codificar? - página 100

 

solo compra, no venta

creando un ea rentable, pero podría ser el doble de bueno (tal vez) por ahora sólo se colocan las compras, nunca las órdenes de venta.

¿Alguien sabe por qué?

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

//| Comienzo de la señal |||

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

double sig_buy = iCustom(NULL, 0, "Slope Direction Line",40, 2, 0, 0, 0);

double sig_sell = iCustom(NULL, 0, "Línea de dirección de la pendiente",40, 2, 0, 1, 0);

double Sg=iCustom(NULL,0, "RSIFilter_v1",5,5,0,1);

si (sig_buy>0 && Sg>0) Orden = SIGNAL_BUY;

si (sig_sell>0 && Sg<0 ) Orden = SIGNAL_SELL;

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

//| Fin de la señal ||

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

 

publicar el código total, hay otra cosa mal...

el segundo paso es quizás sus funciones iCustom().

panteraschoice:
creando un ea rentable, pero podría ser el doble de bueno (tal vez) por ahora sólo se colocan las compras, nunca las órdenes de venta.

¿Alguien sabe por qué?

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

//| Comienzo de la señal |||

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

double sig_buy = iCustom(NULL, 0, "Línea de dirección de la pendiente",40, 2, 0, 0, 0);

double sig_sell = iCustom(NULL, 0, "Línea de dirección de la pendiente",40, 2, 0, 1, 0);

double Sg=iCustom(NULL,0, "RSIFilter_v1",5,5,0,1);

si (sig_buy>0 && Sg>0) Orden = SIGNAL_BUY;

si (sig_sell>0 && Sg<0 ) Orden = SIGNAL_SELL;

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

//| Final de la señal |

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

¿Colocación y visualización de objetos en el futuro?

Hola, ¿alguien sabe si MQL4 soporta la colocación de un objeto indicador en el futuro y la visualización del objeto futuro? He intentado ObjectMove a una fecha futura (sin retorno de error), pero la visualización se detiene en la fecha de la última garrapata. Gracias

 

Las MA's tienen una función de desplazamiento... si a eso te refieres. +2 lo deslizará hacia adelante 2 barras TF. -2 se deslizará hacia atrás 2.

 
IN10TION:
publicar el código total, hay otra cosa mal ... el segundo paso es tal vez su iCustom() funciones.

#enlace de la propiedad "https://www.forex-tsd.com"

extern int NúmeroMágico = 1001;

extern bool EachTickMode = False;

extern double Lots = 0.01

extern int Slippage = 4;

extern bool StopLossMode = True

extern int StopLoss = 70

extern bool TakeProfitMode = True

extern int TakeProfit = 300;

extern bool TrailingStopMode = True

extern int TrailingStop = 25

extern double MaximumRisk =0;//0.15

extern double DecreaseFactor =3

extern int MaxOrders = 3000;

extern bool UseHourTrade = False;

extern int FromHourTrade = 8;

extern int ToHourTrade = 18;

#define SIGNAL_NONE 0

#define SEÑAL_BUY 1

#define SEÑAL_VENTA 2

#define SEÑAL_CLOSEBUY 3

#define SEÑAL_CLOSESELL 4

int BarCount;

int Actual;

bool TickCheck = False;

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

//| función de inicialización de los 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() {

if (UseHourTrade){

if (!(Hour()>=FromHourTrade && Hour()<=ToHourTrade)) {

Comment("¡La hora para el comercio no ha llegado más!");

return(0);

}

}

int Orden = SIGNAL_NONE;

int Total, Ticket;

double StopLossLevel, TakeProfitLevel;

int digit = MarketInfo(Symbol(),MODE_DIGITS);

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

Total = OrdersTotal();

Orden = SIGNAL_NONE;

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

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

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

double sig_buy = iCustom(NULL, 0, "Slope Direction Line",40, 2, 0, 0, 0);

double sig_sell = iCustom(NULL, 0, "Línea de dirección de la pendiente",40, 2, 0, 1, 0);

double Sg=iCustom(NULL,0, "RSIFilter_v1",5,5,0,1);

si (sig_buy>0 && Sg>0) Orden = SIGNAL_BUY;

si (sig_sell>0 && Sg<0 ) Orden = SIGNAL_SELL;

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

//| Fin de la señal ||

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

//Compra

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

if(ScanTrades() < MaxOrders) {

//Comprobar el margen libre

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

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

return(0);

}

StopLossLevel = Ask - StopLoss * Point;

TakeProfitLevel = Ask + TakeProfit * Point;

Ticket = OrderSend(Symbol(), OP_BUY, LotsOptimized(),

NormalizeDouble(Ask,digit),

Slippage,

NormalizeDouble(StopLossLevel,digit),

NormalizeDouble(TakeProfitLevel,digit),

"Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);

if(Ticket > 0) {

if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) Print("Orden de COMPRA abierta : ", OrderOpenPrice()); 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(ScanTrades() < MaxOrders) {

//Comprobar el margen libre

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

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

return(0);

}

StopLossLevel = Oferta + StopLoss * Punto;

TakeProfitLevel = Bid - TakeProfit * Point;

Ticket = OrderSend(Symbol(), OP_SELL, LotsOptimized(),

NormalizeDouble(Bid,digit),

deslizamiento,

NormalizeDouble(StopLossLevel,digit),

NormalizeDouble(TakeProfitLevel,digit),

"Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);

if(Ticket > 0) {

if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) Print("Orden de venta abierta : ", OrderOpenPrice()); else Print("Error al abrir la orden de venta : ", GetLastError());

}

if (EachTickMode) TickCheck = True;

if (!EachTickMode) BarCount = Bars;

return(0);

}

}

//Comprobar posición

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

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

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

if(OrderType() == OP_BUY && OrderMagicNumber()==MagicNumber ) {

//Cerrar

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

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

si (EachTickMode) TickCheck = True;

if (!EachTickMode) BarCount = Bars;

return(0);

}

//Trailing stop

if(TrailingStopMode && 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;

return(0);

}

}

}

} else {

if(OrderType()==OP_SELL && OrderMagicNumber()==MagicNumber)

{

//Cierre

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

{

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

if (EachTickMode) TickCheck = True;

if (!EachTickMode) BarCount = Bars;

return(0);

}

//Trailing stop

if (TrailingStopMode && 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;

return(0);

}

}

}

}}

}

}

if (!EachTickMode) BarCount = Bars;

return(0);

}

int ScanTrades()

{

int total = OrdersTotal();

int numords = 0;

for(int cnt=0; cnt<total; cnt++)

{

OrderSelect(cnt, SELECT_BY_POS);

if(OrderSymbol() == Symbol() && OrderType()<=OP_SELLSTOP && OrderMagicNumber() == MagicNumber)

numords++;

}

return(numords);

}

//bool ExistPositions() {

// for (int i=0; i<OrdersTotal(); i++) {

// if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {

// si (OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) {

// return(True);

// }

// }

// }

// return(false);

//}

double LotsOptimized()

{

double lote=Lotes;

int orders=HistoryTotal(); // historial total de órdenes

int losses=0; // número de órdenes con pérdidas sin pausa

//---- seleccione el tamaño del lote

if(RiesgoMáximo>0)lot=NormalizeDouble(Lots*AccountFreeMargin()*RiesgoMáximo/1000.0,1);

//---- calcule el número de órdenes de pérdidas sin pausa

if(DecreaseFactor>0)

{

for(int i=órdenes-1;i>=0;i--)

{

if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("¡Error en el historial!"); break; }

if(OrderSymbol()!=Symbol() | OrderType()>OP_SELL) continue;

//----

if(OrderProfit()>0) break;

if(OrderProfit()<0) losses++;

}

if(losses>1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);

}

//---- devolver el tamaño del lote

if(lote<0.1) lot=0.1;

return(lote);

}

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

 

¿Recibes algún código de error o algo más (en el backtesting) que te dé una pista de lo que está fallando?

panteraschoice:
#enlace de la propiedad "https://www.forex-tsd.com"

extern int NúmeroMágico = 1001;

extern bool EachTickMode = False;

extern double Lots = 0.01;

extern int Slippage = 4;

extern bool StopLossMode = True

extern int StopLoss = 70

extern bool TakeProfitMode = True

extern int TakeProfit = 300;

extern bool TrailingStopMode = True

extern int TrailingStop = 25

extern double MaximumRisk =0;//0.15

extern double DecreaseFactor =3

extern int MaxOrders = 3000;

extern bool UseHourTrade = False;

extern int FromHourTrade = 8;

extern int ToHourTrade = 18;

#define SIGNAL_NONE 0

#define SEÑAL_BUY 1

#define SEÑAL_VENTA 2

#define SEÑAL_CLOSEBUY 3

#define SEÑAL_CLOSESELL 4

int BarCount;

int Actual;

bool TickCheck = False;

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

//| función de inicialización de los 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() {

if (UseHourTrade){

if (!(Hour()>=FromHourTrade && Hour()<=ToHourTrade)) {

Comment("¡La hora para el comercio no ha llegado más!");

return(0);

}

}

int Orden = SIGNAL_NONE;

int Total, Ticket;

double StopLossLevel, TakeProfitLevel;

int digit = MarketInfo(Symbol(),MODE_DIGITS);

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

Total = OrdersTotal();

Orden = SIGNAL_NONE;

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

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

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

double sig_buy = iCustom(NULL, 0, "Slope Direction Line",40, 2, 0, 0, 0);

double sig_sell = iCustom(NULL, 0, "Línea de dirección de la pendiente",40, 2, 0, 1, 0);

double Sg=iCustom(NULL,0, "RSIFilter_v1",5,5,0,1);

if (sig_buy>0 && Sg>0) Orden = SIGNAL_BUY;

si (sig_sell>0 && Sg<0 ) Orden = SIGNAL_SELL;

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

//| Fin de la señal

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

//Compra

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

if(ScanTrades() < MaxOrders) {

//Comprobar el margen libre

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

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

return(0);

}

StopLossLevel = Ask - StopLoss * Point;

TakeProfitLevel = Ask + TakeProfit * Point;

Ticket = OrderSend(Symbol(), OP_BUY, LotsOptimized(),

NormalizeDouble(Ask,digit),

Slippage,

NormalizeDouble(StopLossLevel,digit),

NormalizeDouble(TakeProfitLevel,digit),

"Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);

if(Ticket > 0) {

if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) Print("Orden de COMPRA abierta : ", OrderOpenPrice()); 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(ScanTrades() < MaxOrders) {

//Comprobar el margen libre

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

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

return(0);

}

StopLossLevel = Oferta + StopLoss * Punto;

TakeProfitLevel = Bid - TakeProfit * Point;

Ticket = OrderSend(Symbol(), OP_SELL, LotsOptimized(),

NormalizeDouble(Bid,digit),

deslizamiento,

NormalizeDouble(StopLossLevel,digit),

NormalizeDouble(TakeProfitLevel,digit),

"Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);

if(Ticket > 0) {

if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) Print("Orden de venta abierta : ", OrderOpenPrice()); else Print("Error al abrir la orden de venta : ", GetLastError());

}

if (EachTickMode) TickCheck = True;

if (!EachTickMode) BarCount = Bars;

return(0);

}

}

//Comprobar posición

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

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

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

if(OrderType() == OP_BUY && OrderMagicNumber()==MagicNumber ) {

//Cerrar

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

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

si (EachTickMode) TickCheck = True;

if (!EachTickMode) BarCount = Bars;

return(0);

}

//Trailing stop

if(TrailingStopMode && 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;

return(0);

}

}

}

} else {

if(OrderType()==OP_SELL && OrderMagicNumber()==MagicNumber)

{

//Cierre

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

{

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

if (EachTickMode) TickCheck = True;

if (!EachTickMode) BarCount = Bars;

return(0);

}

//Trailing stop

if (TrailingStopMode && 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;

return(0);

}

}

}

}}

}

}

if (!EachTickMode) BarCount = Bars;

return(0);

}

int ScanTrades()

{

int total = OrdersTotal();

int numords = 0;

for(int cnt=0; cnt<total; cnt++)

{

OrderSelect(cnt, SELECT_BY_POS);

if(OrderSymbol() == Symbol() && OrderType()<=OP_SELLSTOP && OrderMagicNumber() == MagicNumber)

numords++;

}

return(numords);

}

//bool ExistPositions() {

// for (int i=0; i<OrdersTotal(); i++) {

// if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {

// si (OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) {

// return(True);

// }

// }

// }

// return(false);

//}

double LotsOptimized()

{

double lote=Lotes;

int orders=HistoryTotal(); // historial total de órdenes

int losses=0; // número de órdenes con pérdidas sin pausa

//---- seleccione el tamaño del lote

if(RiesgoMáximo>0)lot=NormalizeDouble(Lots*AccountFreeMargin()*RiesgoMáximo/1000.0,1);

//---- calcule el número de órdenes de pérdidas sin pausa

if(DecreaseFactor>0)

{

for(int i=órdenes-1;i>=0;i--)

{

if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("¡Error en el historial!"); break; }

if(OrderSymbol()!=Symbol() | OrderType()>OP_SELL) continue;

//----

if(OrderProfit()>0) break;

if(OrderProfit()<0) losses++;

}

if(losses>1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);

}

//---- devolver el tamaño del lote

if(lote<0.1) lot=0.1;

return(lote);

}

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

Estoy haciendo un backtest ahora sólo con el RSIFilter, sí uso el RSIMixFilter hace unos posts en este hilo, publiqué ese indicador, y sí consigo COMPRAS y VENTAS, así que la lógica para hacer las órdenes de COMPRA y VENTA están bien, el tema es con sus señales iCustom...

RSIMixFilter, no está en este hilo, lo siento, está aquí PREGUNTA

panteraschoice:
creando un ea rentable, pero podría ser el doble de bueno (tal vez) por ahora sólo se colocan las compras, nunca las órdenes de venta.

¿Alguien sabe por qué?

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

//| Comienzo de la señal |||

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

double sig_buy = iCustom(NULL, 0, "Slope Direction Line",40, 2, 0, 0, 0);

double sig_sell = iCustom(NULL, 0, "Línea de dirección de la pendiente",40, 2, 0, 1, 0);

double Sg=iCustom(NULL,0, "RSIFilter_v1",5,5,0,1);

if (sig_buy>0 && Sg>0) Orden = SIGNAL_BUY;

si (sig_sell>0 && Sg<0 ) Orden = SIGNAL_SELL;

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

//| Final de la señal |

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

Hice algunos backtesting, EURUSD H1 desde abril de 2007 hasta ahora, con este RSIMixFilter solamente...

Tiene que ser un 90% de calidad de modelado, no sé por qué no se muestra.

panteraschoice:
creando un ea rentable, pero podría ser el doble de bueno (tal vez) por ahora sólo se colocan las compras, nunca las órdenes de venta.

¿Alguien sabe por qué?

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

//| Comienzo de la señal |||

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

double sig_buy = iCustom(NULL, 0, "Slope Direction Line",40, 2, 0, 0, 0);

double sig_sell = iCustom(NULL, 0, "Línea de dirección de la pendiente",40, 2, 0, 1, 0);

double Sg=iCustom(NULL,0, "RSIFilter_v1",5,5,0,1);

si (sig_buy>0 && Sg>0) Orden = SIGNAL_BUY;

si (sig_sell>0 && Sg<0 ) Orden = SIGNAL_SELL;

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

//| Final de la señal |

//+------------------------------------------------------------------+
Archivos adjuntos:
 

Este backtesting, ¿daba compras y ventas o sólo una de ellas? En mi caso sólo he obtenido compras (o sólo ventas cuando he cambiado el código).

Realmente no he visto nada que muestre un error.

 
IN10TION:
Estoy haciendo un backtest ahora sólo con el RSIFilter, sí uso el RSIMixFilter hace unos posts en este hilo, publiqué ese indicador, y sí obtengo COMPRAS y VENTAS, así que la lógica para hacer las órdenes de COMPRA y VENTA están bien, el problema es con sus señales iCustom...

Entonces, ¿esto está bien?

double Sg=iCustom(NULL,0, "RSIFilter_v1",5,5,0,1);

si ( Sg>0) Orden = SIGNAL_BUY;

si ( Sg<0 ) Orden = SEÑAL_VENTA;

Razón de la queja: