Chiedete! - pagina 174

 

domanda sull'indicatore code-----(3 righe)

1.perché le 2 funzioni marcate sono nel deinit?

2.perché 720 valore sulla linea marcata?

il codice:

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

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

}

}

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

grazie mille.

 

ERAN123

1. Non sono nella deinit() ma appena dietro la deinit() (tra deinit() e start()). In mql non è necessario seguire alcun ordine di scrittura delle procedure e delle funzioni. Potete mettere la init() alla fine del codice e funzionerà ancora bene (una piccola digressione "mql non permette funzioni o procedure annidate, quindi non possono mai essere all'interno del corpo di un'altra funzione o procedura in mql)

2. Fissa il calcolo a 720 barre ad ogni tick. Perché? Penso che dovresti chiedere all'autore di questo.

ERAN123:
1.perché le 2 funzioni marcate sono nel deinit?

2.perché 720 valore sulla linea segnata?

il codice:

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

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

}

}

//+------------------------------------------------------------------+
grazie mille.
 

ciao mladen

grazie per il tuo replay.

1. ho appena notato questo (ho appannato questo non l'ho notato)

2. il suo vero mistero

 

ordini pendenti bisogno di un aiuto leggero !!!!!!!!

ciao amici

ho una domanda sull'ordine in sospeso:

Ho 2 ordini pendenti di acquisto e di vendita, una volta che uno di loro ha colpito io cosa per chiudere l'altro.

Sono solo un principiante programmatore mql ed è al di là delle mie capacità in questo momento.

qualsiasi direzione amici????

molte grazie.

 

Puoi usare qualcosa come questo:

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

}

}

}

Cancellerà qualsiasi ordine in sospeso se viene trovato un ordine regolare con lo stesso numero magico e gli stessi simboli

ERAN123:
ciao amici

Ho una domanda sull'ordine in sospeso:

Ho 2 ordini pendenti di acquisto e di vendita, una volta che uno di loro ha colpito io cosa per chiudere l'altro.

Sono solo un principiante programmatore mql ed è al di là delle mie capacità in questo momento.

qualsiasi direzione amici????

molte grazie.
 

mladen

grazie mille, lo controllerò.

Grazie ancora

 

Dovrebbe funzionare bene

Buon fine settimana

ERAN123:
mladen

Grazie mille, lo controllerò.

grazie ancora
 

Ciao colleghi trader!

Faccio trading da qualche mese con una strategia che sto cercando di programmare in mql4.

Eseguo un ordine con un take profit in questo modo

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

Ora quando l'ordine si chiude (t/p o s/l), voglio fare un altro ordine identico:

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

e così via in modo da introdurre una posizione di acquisto ogni volta che il precedente acquisto si è chiuso.

Ho iniziato a imparare mql4 un paio di giorni fa e sono bloccato su questo. Per favore aiutatemi!

 

Perché non si conta semplicemente il numero di ordini attualmente aperti (sia ordini di acquisto che di vendita) e quando è 0, si apre una nuova posizione?

qwertet:
Ciao colleghi trader!

Faccio trading da qualche mese con una strategia che sto cercando di programmare in mql4.

Eseguo un ordine con un take profit in questo modo

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

Ora quando l'ordine si chiude (t/p o s/l), voglio fare un altro ordine identico:

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

e così via in modo da introdurre una posizione di acquisto ogni volta che il precedente acquisto è stato chiuso.

Ho iniziato a imparare mql4 un paio di giorni fa e sono bloccato su questo. Per favore aiutatemi!
 
qwertet:

e così via in modo da introdurre una posizione di acquisto ogni volta che il precedente acquisto si è chiuso.

Ho iniziato ad imparare mql4 un paio di giorni fa e sono bloccato su questo. Per favore aiutatemi!

Ehi, MLaden ha ragione - hai bisogno di contare gli ordini per controllare se sei pronto per uno nuovo.

Ecco la funzione che potresti voler usare.

Conterà quanti ordini hai già aperto da selezionati con il numero magico specificato e il tipo di ordine.

Se metti -1 come tipo di ordine, conterà tutti gli ordini in base al numero magico selezionato.

Buon divertimento.

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

}

Motivazione: