¡Pide! - página 174

 

pregunta sobre el indicador code-----(3 líneas)

1.¿por qué las 2 funciones marcadas están en el deinit?

2.¿por qué el valor 720 en la línea marcada?

el código:

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

//| DailyBreakout.mq4 |

//| Copyright © 2008, Robert Hill. |

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

#property copyright "Copyright © 2008, Robert Hill"

#property link "NONE"

#property indicator_chart_window

//---- input parameters

extern bool Alerts = false;

extern int GMTshift = 0;

extern int LabelShift = 20;

extern int LineShift = 40;

extern string pd = "PipsAboveBelowSR for Alert";

extern int PipDistance = 1;

extern color StandardFontColor = White;

extern int StandardFontSize = 8;

extern color SupportColor = Red;

extern color ResistanceColor = Lime;

datetime LabelShiftTime, LineShiftTime;

double yesterday_high=0;

double yesterday_low=0;

double LastHigh,LastLow,x;

double R1=0;

double S1=0;

bool firstS1=true;

bool firstR1=true;

double myPoint;

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

//| Custom indicator initialization function |

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

int init()

{

//---- indicators

myPoint = SetPoint(Symbol());

//----

return(0);

}

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

//| Custor indicator deinitialization function |

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

int deinit()

{

//---- TODO: add your code here

//----

ObjectDelete("R1 Label");

ObjectDelete("R1 Line");

ObjectDelete("S1 Label");

ObjectDelete("S1 Line");

return(0);

}

double SetPoint(string mySymbol)// <<<<<<<-----why here on the deinit?????----------------

{

double mPoint, myDigits;

myDigits = MarketInfo (mySymbol, MODE_DIGITS);

if (myDigits < 4)

mPoint = 0.01;

else

mPoint = 0.0001;

return(mPoint);

}

int DoAlerts()//<<<<<<<<<-------why here on the deint??????-----------------

{

double DifAboveR1,PipsLimit;

double DifBelowS1;

DifBelowS1 = S1 - Close[0];

DifAboveR1 = Close[0] - R1;

PipsLimit = PipDistance * myPoint;

if (DifBelowS1 > PipsLimit) firstS1 = true;

if (DifBelowS1 0)

{

if (firstS1)

{

Alert("Below S1 Line by ",DifBelowS1, " for ", Symbol(),"-",Period());

PlaySound("alert.wav");

firstS1=false;

}

}

if (DifAboveR1 > PipsLimit) firstR1 = true;

if (DifAboveR1 0)

{

if (firstR1)

{

Alert("Above R1 Line by ",DifAboveR1," for ", Symbol(),"-",Period());

Sleep(2000);

PlaySound("timeout.wav");

firstR1=false;

}

}

}

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

//| Custom indicator iteration function |

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

int start()

{

int counted_bars=IndicatorCounted();

//---- TODO: add your code here

double day_high=0;

double day_low=0;

double yesterday_open=0;

double today_open=0;

double cur_day=0;

double prev_day=0;

int cnt=720;//<<<<<----why 720 ????????--------------------------------------------------

//---- exit if period is greater than 4 hr charts

if(Period() > 240)

{

Print("Error - Chart period is greater than 4 hr.");

return(-1); // then exit

}

//---- Get new daily prices & calculate pivots

cur_day=0;

prev_day=0;

//---- Get new daily prices & calculate pivots

while (cnt!= 0)

{

cur_day = TimeDay(Time[cnt]- (GMTshift*3600));

if (prev_day != cur_day)

{

yesterday_high = day_high;

yesterday_low = day_low;

day_high = High[cnt];

day_low = Low[cnt];

prev_day = cur_day;

}

if (High[cnt]>day_high)

{

day_high = High[cnt];

}

if (Low[cnt]<day_low)

{

day_low = Low[cnt];

}

cnt--;

}

S1 = yesterday_low;

R1 = yesterday_high;

LabelShiftTime = Time[LabelShift];

LineShiftTime = Time[LineShift];

//---- Set line labels on chart window

DisplayLabel("R1 label", "R1", R1, StandardFontSize, StandardFontColor);

DisplayLabel("S1 label", "S1", S1, StandardFontSize, StandardFontColor);

//--- Draw Pivot lines on chart

DisplayLine("S1 line", S1, 0, STYLE_DASHDOTDOT, SupportColor);

DisplayLine("R1 line", R1, 0, STYLE_DASHDOTDOT, ResistanceColor);

//---- done

// Now check for Alert

if (Alerts) DoAlerts();

//----

return(0);

}

//---- Set line labels on chart window

void DisplayLabel(string LabelName, string LabelText, double LabelPos, int LabelFontSize, color LabelColor)

{

if(ObjectFind(LabelName) != 0)

{

ObjectCreate(LabelName, OBJ_TEXT, 0, LabelShiftTime, LabelPos);

ObjectSetText(LabelName, LabelText, LabelFontSize, "Arial", LabelColor);

}

else

{

ObjectMove(LabelName, 0, LabelShiftTime, LabelPos);

}

}

//--- Draw Pivot lines on chart

void DisplayLine(string LineName, double LinePos, int LineWidth, int LineStyle, color LineColor)

{

if(ObjectFind(LineName) != 0)

{

ObjectCreate(LineName, OBJ_HLINE, 0, LineShiftTime, LinePos);

ObjectSet(LineName, OBJPROP_STYLE, LineStyle);

ObjectSet(LineName, OBJPROP_COLOR, LineColor);

if (LineWidth > 0) ObjectSet(LineName, OBJPROP_WIDTH, LineWidth);

}

else

{

ObjectMove(LineName, 0, LineShiftTime, LinePos);

}

}

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

Gracias.

 

ERAN123

1. No están en el deinit() sino justo detrás del deinit() (entre el deinit() y el start()). En mql no es necesario seguir ningún orden de cómo se escriben los procedimientos y las funciones. Puedes poner el init() al final del código y seguirá funcionando bien )una pequeña digresión " mql no permite funciones o procedimientos anidados, por lo que nunca pueden estar dentro del cuerpo de otra función o procedimiento en mql)

2. Fija el cálculo a 720 barras en cada tick. ¿Por qué? Creo que deberías preguntarle al autor sobre eso.

ERAN123:
1.¿por qué las 2 funciones marcadas están en el deinit?

2.¿por qué el valor de 720 en la línea marcada?

el código:

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

//| DailyBreakout.mq4 |

//| Copyright © 2008, Robert Hill. |

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

#property copyright "Copyright © 2008, Robert Hill"

#property link "NONE"

#property indicator_chart_window

//---- input parameters

extern bool Alerts = false;

extern int GMTshift = 0;

extern int LabelShift = 20;

extern int LineShift = 40;

extern string pd = "PipsAboveBelowSR for Alert";

extern int PipDistance = 1;

extern color StandardFontColor = White;

extern int StandardFontSize = 8;

extern color SupportColor = Red;

extern color ResistanceColor = Lime;

datetime LabelShiftTime, LineShiftTime;

double yesterday_high=0;

double yesterday_low=0;

double LastHigh,LastLow,x;

double R1=0;

double S1=0;

bool firstS1=true;

bool firstR1=true;

double myPoint;

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

//| Custom indicator initialization function |

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

int init()

{

//---- indicators

myPoint = SetPoint(Symbol());

//----

return(0);

}

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

//| Custor indicator deinitialization function |

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

int deinit()

{

//---- TODO: add your code here

//----

ObjectDelete("R1 Label");

ObjectDelete("R1 Line");

ObjectDelete("S1 Label");

ObjectDelete("S1 Line");

return(0);

}

double SetPoint(string mySymbol)// <<<<<<<-----why here on the deinit?????----------------

{

double mPoint, myDigits;

myDigits = MarketInfo (mySymbol, MODE_DIGITS);

if (myDigits < 4)

mPoint = 0.01;

else

mPoint = 0.0001;

return(mPoint);

}

int DoAlerts()//<<<<<<<<<-------why here on the deint??????-----------------

{

double DifAboveR1,PipsLimit;

double DifBelowS1;

DifBelowS1 = S1 - Close[0];

DifAboveR1 = Close[0] - R1;

PipsLimit = PipDistance * myPoint;

if (DifBelowS1 > PipsLimit) firstS1 = true;

if (DifBelowS1 0)

{

if (firstS1)

{

Alert("Below S1 Line by ",DifBelowS1, " for ", Symbol(),"-",Period());

PlaySound("alert.wav");

firstS1=false;

}

}

if (DifAboveR1 > PipsLimit) firstR1 = true;

if (DifAboveR1 0)

{

if (firstR1)

{

Alert("Above R1 Line by ",DifAboveR1," for ", Symbol(),"-",Period());

Sleep(2000);

PlaySound("timeout.wav");

firstR1=false;

}

}

}

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

//| Custom indicator iteration function |

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

int start()

{

int counted_bars=IndicatorCounted();

//---- TODO: add your code here

double day_high=0;

double day_low=0;

double yesterday_open=0;

double today_open=0;

double cur_day=0;

double prev_day=0;

int cnt=720;//<<<<<----why 720 ????????--------------------------------------------------

//---- exit if period is greater than 4 hr charts

if(Period() > 240)

{

Print("Error - Chart period is greater than 4 hr.");

return(-1); // then exit

}

//---- Get new daily prices & calculate pivots

cur_day=0;

prev_day=0;

//---- Get new daily prices & calculate pivots

while (cnt!= 0)

{

cur_day = TimeDay(Time[cnt]- (GMTshift*3600));

if (prev_day != cur_day)

{

yesterday_high = day_high;

yesterday_low = day_low;

day_high = High[cnt];

day_low = Low[cnt];

prev_day = cur_day;

}

if (High[cnt]>day_high)

{

day_high = High[cnt];

}

if (Low[cnt]<day_low)

{

day_low = Low[cnt];

}

cnt--;

}

S1 = yesterday_low;

R1 = yesterday_high;

LabelShiftTime = Time[LabelShift];

LineShiftTime = Time[LineShift];

//---- Set line labels on chart window

DisplayLabel("R1 label", "R1", R1, StandardFontSize, StandardFontColor);

DisplayLabel("S1 label", "S1", S1, StandardFontSize, StandardFontColor);

//--- Draw Pivot lines on chart

DisplayLine("S1 line", S1, 0, STYLE_DASHDOTDOT, SupportColor);

DisplayLine("R1 line", R1, 0, STYLE_DASHDOTDOT, ResistanceColor);

//---- done

// Now check for Alert

if (Alerts) DoAlerts();

//----

return(0);

}

//---- Set line labels on chart window

void DisplayLabel(string LabelName, string LabelText, double LabelPos, int LabelFontSize, color LabelColor)

{

if(ObjectFind(LabelName) != 0)

{

ObjectCreate(LabelName, OBJ_TEXT, 0, LabelShiftTime, LabelPos);

ObjectSetText(LabelName, LabelText, LabelFontSize, "Arial", LabelColor);

}

else

{

ObjectMove(LabelName, 0, LabelShiftTime, LabelPos);

}

}

//--- Draw Pivot lines on chart

void DisplayLine(string LineName, double LinePos, int LineWidth, int LineStyle, color LineColor)

{

if(ObjectFind(LineName) != 0)

{

ObjectCreate(LineName, OBJ_HLINE, 0, LineShiftTime, LinePos);

ObjectSet(LineName, OBJPROP_STYLE, LineStyle);

ObjectSet(LineName, OBJPROP_COLOR, LineColor);

if (LineWidth > 0) ObjectSet(LineName, OBJPROP_WIDTH, LineWidth);

}

else

{

ObjectMove(LineName, 0, LineShiftTime, LinePos);

}

}

//+------------------------------------------------------------------+
Gracias.
 

hola mladen

gracias por tu respuesta.

1. Acabo de darme cuenta de esto (no me di cuenta de esto)

2. es un verdadero misterio

 

¡¡¡¡¡¡¡¡lospedidos pendientes necesitan una ayuda ligera !!!!!!!!

hola amigos

tengo una pregunta sobre las ordenes pendientes:

tengo 2 ordenes pendientes de compra y venta, una vez que una de ellas se ejecuta, tengo que cerrar la otra.

Soy un programador novato de mql y su más allá de mi capacidad en este momento.

cualquier dirección amigos????

Muchas gracias.

 

Puede utilizar algo como esto :

void CleanPendingOrders()

{

bool trade.BuyEntered = false;

bool trade.SellEntered = false;

for (int i=OrdersTotal()-1; i>=0; i--)

{

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

//

//

//

//

//

if ( OrderSymbol()==trade.symbol && OrderMagicNumber()==MagicNumber )

{

int type = OrderType();

if (type==OP_BUY && !trade.ByEntered) trade.BuyEntered = true;

if (type==OP_SELL && !trade.SellEntered) trade.SellEntered = true;

if (type >OP_SELL && (trade.ByEntered || trade.BuyEntered))

OrderDelete(OrderTicket());

}

}

}

Eliminará cualquier orden pendiente si se encuentra una orden regular con el mismo número mágico y símbolos

ERAN123:
hola amigos

Tengo una pregunta sobre la orden pendiente:

Tengo 2 ordenes pendientes de compra y venta, una vez que una de ellas se ejecuta, debo cerrar la otra.

Soy un programador novato de mql y esta mas alla de mi capacidad en este momento.

cualquier dirección amigos????

muchas gracias.
 

mladen

Muchas gracias, lo comprobaré.

Gracias de nuevo

 

Debería funcionar bien

Que tengas un buen fin de semana

ERAN123:
mladen

Muchas gracias, lo comprobaré.

gracias de nuevo
 

¡Hola amigos traders!

Llevo unos meses operando con una estrategia que estoy intentando programar en mql4.

Ejecuto una orden con un take profit así

"OrderSend(Symbol(), OP_BUY, lots, Ask, 10, 30, Ask+takeprofit, "test", 12345, 0, Green);"

Ahora cuando la orden se cierre (t/p o s/l), quiero hacer otra orden idéntica:

"OrderSend(Symbol(), OP_BUY, lots, Ask, 10, 30, Ask+takeprofit, "test", 12345, 0, Green);"

y así sucesivamente para que introduzca una posición de compra siempre que se haya cerrado la compra anterior.

He empezado a aprender mql4 hace un par de días y estoy atascado en esto. ¡Por favor, ayuda!

 

¿Por qué no cuenta simplemente el número de órdenes abiertas actualmente (ya sean órdenes de compra o de venta) y cuando es 0, abre una nueva posición?

qwertet:
¡Hola compañeros comerciantes!

Llevo unos meses operando con una estrategia que estoy intentando programar en mql4.

Ejecuto una orden con un take profit así

"OrderSend(Symbol(), OP_BUY, lots, Ask, 10, 30, Ask+takeprofit, "test", 12345, 0, Green);"

Ahora cuando la orden se cierre (t/p o s/l), quiero hacer otra orden idéntica:

"OrderSend(Symbol(), OP_BUY, lots, Ask, 10, 30, Ask+takeprofit, "test", 12345, 0, Green);"

y así sucesivamente para que introduzca una posición de compra cada vez que la compra anterior se haya cerrado.

He empezado a aprender mql4 hace un par de días y estoy atascado en esto. ¡Por favor, ayuda!
 
qwertet:

y así sucesivamente para que introduzca una posición de compra siempre que la compra anterior se haya cerrado.

He empezado a aprender mql4 hace un par de días y estoy atascado en esto. Por favor, ayúdenme.

Oye, MLaden tiene razón - necesitas contar las órdenes para comprobar si estás listo para una nueva.

Aquí está la función que puede querer usar.

Contará cuántas órdenes ya has abierto de las seleccionadas con el número mágico especificado y el tipo de orden.

Si usted pone -1 como su tipo de orden, contará todas las órdenes por número mágico seleccionado.

Disfrute.

int orderCount(int type,int magic)

{

int oc = 0;

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

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderMagicNumber() == magic && (OrderType() == type || type == -1))

oc+=1;

}

return(oc);

}

Razón de la queja: