Pergunte! - página 174

 

pergunta sobre código indicador-----(3 linhas)

1.por que as 2 funções marcadas estão no deinit ?

2.por que 720 valor na linha marcada ?

o 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);

}

}

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

graças a um saque.

 

ERAN123

1. Eles não estão no deinit() mas logo atrás do deinit() (entre deinit() e start())). Em mql você não precisa seguir nenhuma ordem de como os procedimentos e funções são escritos. Você pode colocar o deinit() no final do código e ele ainda funcionará OK ) uma pequena digressão " mql não permite funções ou procedimentos aninhados, portanto eles nunca podem estar dentro do corpo de outra função ou procedimento em mql)

2. Ele fixa o cálculo em 720 barras a cada tick. Por quê? Acho que você deveria perguntar ao autor sobre isso.

ERAN123:
1.por que as 2 funções marcadas estão no deinit ?

2.Por que 720 barras na linha marcada?

o 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);

}

}

//+------------------------------------------------------------------+
graças a um saque.
 

oi mladen

obrigado por sua repetição.

1. acabei de notar esta (eu não notei esta não notei esta)

2. seu verdadeiro mistério

 

pedidos pendentes precisam de ajuda !!!!!!!!

olá amigos

tenho uma pergunta sobre ordem pendente:

tenho 2 ordens pendentes de compra e venda uma vez que uma delas acertou o que fechar a outra.

sou apenas um programador de mql novato e está além de minha capacidade neste momento.

qualquer direção amigos????

muito obrigado.

 

Você pode usar algo como isto :

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());

}

}

}

Ele apagará qualquer ordem pendente se for encontrada uma ordem regular com o mesmo número mágico e símbolos

ERAN123:
olá amigos

tenho uma pergunta sobre ordem pendente:

tenho 2 ordens pendentes de compra e venda uma vez que uma delas acertou o que fechar a outra .

sou apenas um programador novato de mql e está além de minhas possibilidades neste momento.

qualquer direção amigos????

muito obrigado.
 

mladen

Muito obrigado, vou verificar.

mais uma vez, obrigado

 

Deve funcionar bem

Tenha um bom fim de semana

ERAN123:
mladen

Muito obrigado, vou verificar.

obrigado novamente
 

Olá colegas comerciantes!

Já há alguns meses estou negociando com uma estratégia que estou tentando programar em mql4.

Eu executo uma ordem com um "take profit" assim

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

Agora quando o pedido fechar (t/p ou s/l), eu quero fazer outro pedido idêntico:

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

e assim por diante, para que introduza uma posição de compra sempre que a compra anterior tiver sido fechada.

Comecei a aprender o mql4 há alguns dias e estou preso a isto. Por favor, ajude-me!

 

Por que você simplesmente não conta o número de ordens atualmente abertas (ordens de compra ou de venda) e quando for 0, abre uma nova posição?

qwertet:
Olá colegas comerciantes!

Já há alguns meses estou negociando com uma estratégia que estou tentando programar em mql4.

Eu executo uma ordem com um take profit assim

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

Agora, quando o pedido fechar (t/p ou s/l), eu quero fazer outro pedido idêntico:

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

e assim por diante, para que introduza uma posição de compra sempre que a compra anterior tiver sido fechada.

Comecei a aprender o mql4 há alguns dias e estou preso a isto. Por favor, ajudem-me!
 
qwertet:

e assim por diante, de modo a introduzir uma posição de compra sempre que a compra anterior tiver sido fechada.

Comecei a aprender o mql4 há alguns dias e estou preso a isto. Por favor, ajudem-me!

Ei, MLaden está certo - você precisa contar os pedidos para verificar se você está pronto para uma nova.

Aqui está a função que você pode querer usar.

Ela contará quantos pedidos você já abriu de selecionados com um número mágico especificado e tipo de pedido.

Se você colocar -1 como seu tipo de ordem, ele contará todas as ordens por número mágico selecionado.

Aproveite.

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);

}