besoin d'aide en mql4
-
marko
- Messages : 5
- Enregistré le : 09 févr. 2019 11:38
besoin d'aide en mql4
Bonjour à tous,
Je suis débutant en codage mql4 et en codage informatique en général.
J'essaye de développer un code simple sur le stochastic et lorsque mon signal apparaît, un ordre s'ouvre.
Mon souci est qu' a un ordre est passé à chaque tick donc je me retrouve parfois avec 12 ordres ouverts en meme temps.
J'aimerais qu'un seul ordre ne s'ouvre lorsque mon signal apparaît.
Pouvez-vous m'aider?
Merci d'avance pour vos réponses.
Bon trading à tous
Je suis débutant en codage mql4 et en codage informatique en général.
J'essaye de développer un code simple sur le stochastic et lorsque mon signal apparaît, un ordre s'ouvre.
Mon souci est qu' a un ordre est passé à chaque tick donc je me retrouve parfois avec 12 ordres ouverts en meme temps.
J'aimerais qu'un seul ordre ne s'ouvre lorsque mon signal apparaît.
Pouvez-vous m'aider?
Merci d'avance pour vos réponses.
Bon trading à tous
-
Benoist Rousseau
- Trader Futures / CME Member
- Messages : 174798
- Enregistré le : 06 sept. 2011 22:45
Re: besoin d'aide en mql4
Bonjour , avant de participer au forum, il faut se présenter dans présentation des membres comme l'exige la Nétiquette. Cela permet aux membres de mieux répondre à tes questions en connaissant ton niveau, ton expérience et ton compte sera débloqué.
-
VB6backtester
- Padawan
- Messages : 261
- Enregistré le : 17 sept. 2018 19:17
Re: besoin d'aide en mql4
Bonjour à toi,
Tu dois toujours avant d'envoyer des ordres, vérifier ce qui est déjà en cours avec par exemple :
total = 0;
for (n=0; n < OrdersTotal(); n++) {
if (OrderSelect(n, SELECT_BY_POS)) {
if ( (OrderSymbol()==Symb)&&(OrderMagicNumber()==magic) )
total++;
}
}
Ensuite pour passer un ordre, je te conseille de faire de façon asynchrone en vérifiant si l'ordre est passé ou pas. Le flag (Osellticket sert d'indicateur).
tp = NormalizeDouble(ASK - extremGain * myPoint, myDigit);
Print(TimeCurrent()," - Sell ",BID," Lots=",IntegerToString(lot));
OSellticket =OrderSend(Symbol(), OP_SELL, lot, BID, 5, stoploss, tp,"Sell4817", magic, 0,Red);
if(OSellticket != -1) {
OSellFlag=0;
} else
Print("Error opening SELL order : ",GetLastError());
Bye
Tu dois toujours avant d'envoyer des ordres, vérifier ce qui est déjà en cours avec par exemple :
total = 0;
for (n=0; n < OrdersTotal(); n++) {
if (OrderSelect(n, SELECT_BY_POS)) {
if ( (OrderSymbol()==Symb)&&(OrderMagicNumber()==magic) )
total++;
}
}
Ensuite pour passer un ordre, je te conseille de faire de façon asynchrone en vérifiant si l'ordre est passé ou pas. Le flag (Osellticket sert d'indicateur).
tp = NormalizeDouble(ASK - extremGain * myPoint, myDigit);
Print(TimeCurrent()," - Sell ",BID," Lots=",IntegerToString(lot));
OSellticket =OrderSend(Symbol(), OP_SELL, lot, BID, 5, stoploss, tp,"Sell4817", magic, 0,Red);
if(OSellticket != -1) {
OSellFlag=0;
} else
Print("Error opening SELL order : ",GetLastError());
Bye
-
ano77
Re: besoin d'aide en mql4
Oui, je confirme les infos de V6
Toujours lire les ordres en cours ainsi
for(int i=0; i<OrdersTotal(); i++) {
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true) {
if(OrderSymbol() == Symbol() && OrderMagicNumber() == magicnumber && OrderType() == OP_BUY) {
.......................................................................
aux_buys++;}
Dans cet exemple aux_buys te donnera le nombre d'ordres buy ouvert. Suffit de conditionner l'ouverture d'un ordre à ce que cette valeur soit <=0.
A toi de faire pour les sells...
Et voilà
Toujours lire les ordres en cours ainsi
for(int i=0; i<OrdersTotal(); i++) {
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true) {
if(OrderSymbol() == Symbol() && OrderMagicNumber() == magicnumber && OrderType() == OP_BUY) {
.......................................................................
aux_buys++;}
Dans cet exemple aux_buys te donnera le nombre d'ordres buy ouvert. Suffit de conditionner l'ouverture d'un ordre à ce que cette valeur soit <=0.
A toi de faire pour les sells...
Et voilà
-
marko
- Messages : 5
- Enregistré le : 09 févr. 2019 11:38
Re: besoin d'aide en mql4
Super, merci à vous deux, je vai essayer ça !!!
Bye
Bye
-
marko
- Messages : 5
- Enregistré le : 09 févr. 2019 11:38
Re: besoin d'aide en mql4
Hello les programmeurs!!!
Un problème résolu laisse la place à un autre...
Quelqu’un pourrait-il m’aider, je galère pour programmer un stop suiveur qui avance de 1 pour 1 au fur et à mesure que le prix évolue
Merci d’avance pour votre aide
Un problème résolu laisse la place à un autre...
Quelqu’un pourrait-il m’aider, je galère pour programmer un stop suiveur qui avance de 1 pour 1 au fur et à mesure que le prix évolue
Merci d’avance pour votre aide
-
Philippe56380
- Ewok
- Messages : 28
- Enregistré le : 23 févr. 2019 20:16
Re: besoin d'aide en mql4
je peux te donner l'astuce en MQL5:
void MoveToBreakEven()
{
//--- reset the error value
ResetLastError();
// Normalization of the digits
double nDigits = CalculateNormalizedDigits();
// We calculate the Ask price
double Ask = NormalizeDouble(SymbolInfoDouble(Symbol(), SYMBOL_ASK), Digits());
// We calculate the Bid price
double Bid = NormalizeDouble(SymbolInfoDouble(Symbol(), SYMBOL_BID), Digits());
//--- number of current pending orders
uint total = PositionsTotal();
double ticksize = SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_SIZE);
double pips = 0.0;
if (ticksize == 0.00001 || ticksize == 0.001)
pips = ticksize * 10;
else
pips = ticksize;
for(uint i = 0; i < total; i++)
{
ulong ticket = PositionGetTicket(i);
if(PositionSelectByTicket(ticket))
{
// Check we are on the right symbol
if (PositionGetString(POSITION_SYMBOL) != Symbol())
continue;
//--- check Expert Magic number
if(PositionGetInteger(POSITION_MAGIC) != Expert_MagicNumber)
continue;
//Prepare the prices
double TakeProfitPrice = 0;
double StopLossPrice = 0;
double OpenPrice = PositionGetDouble(POSITION_PRICE_OPEN);
double positionTakeProfit = PositionGetDouble(POSITION_TP);
double positionStopLoss = PositionGetDouble(POSITION_SL);
// Get position type
long positionType = PositionGetInteger(POSITION_TYPE);
if (positionType == POSITION_TYPE_BUY)
{
if ((Bid - positionStopLoss) > (pips * WHENTOMOVETOBE))
{
positionStopLoss = Bid - (pips * WHENTOMOVETOBE);
positionTakeProfit = Bid + (pips * TakeProfit);
if (!m_trade.PositionModify(ticket, positionStopLoss, positionTakeProfit))
{
Comment(__FUNCTION__,", #1 => false. Result Retcode: ",m_trade.ResultRetcode(),", LastError: ", GetLastError(),", description of result: ",m_trade.ResultRetcodeDescription());
}
}
}
else if (positionType == POSITION_TYPE_SELL)
{
if ((positionStopLoss - Ask) > (pips * WHENTOMOVETOBE))
{
positionStopLoss = Ask + (pips * WHENTOMOVETOBE);
positionTakeProfit = Ask - (pips * TakeProfit);
if (!m_trade.PositionModify(ticket, positionStopLoss, positionTakeProfit))
{
Comment(__FUNCTION__,", #1 => false. Result Retcode: ",m_trade.ResultRetcode(),", LastError: ", GetLastError(),", description of result: ",m_trade.ResultRetcodeDescription());
}
}
}
}
}
}
void MoveToBreakEven()
{
//--- reset the error value
ResetLastError();
// Normalization of the digits
double nDigits = CalculateNormalizedDigits();
// We calculate the Ask price
double Ask = NormalizeDouble(SymbolInfoDouble(Symbol(), SYMBOL_ASK), Digits());
// We calculate the Bid price
double Bid = NormalizeDouble(SymbolInfoDouble(Symbol(), SYMBOL_BID), Digits());
//--- number of current pending orders
uint total = PositionsTotal();
double ticksize = SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_SIZE);
double pips = 0.0;
if (ticksize == 0.00001 || ticksize == 0.001)
pips = ticksize * 10;
else
pips = ticksize;
for(uint i = 0; i < total; i++)
{
ulong ticket = PositionGetTicket(i);
if(PositionSelectByTicket(ticket))
{
// Check we are on the right symbol
if (PositionGetString(POSITION_SYMBOL) != Symbol())
continue;
//--- check Expert Magic number
if(PositionGetInteger(POSITION_MAGIC) != Expert_MagicNumber)
continue;
//Prepare the prices
double TakeProfitPrice = 0;
double StopLossPrice = 0;
double OpenPrice = PositionGetDouble(POSITION_PRICE_OPEN);
double positionTakeProfit = PositionGetDouble(POSITION_TP);
double positionStopLoss = PositionGetDouble(POSITION_SL);
// Get position type
long positionType = PositionGetInteger(POSITION_TYPE);
if (positionType == POSITION_TYPE_BUY)
{
if ((Bid - positionStopLoss) > (pips * WHENTOMOVETOBE))
{
positionStopLoss = Bid - (pips * WHENTOMOVETOBE);
positionTakeProfit = Bid + (pips * TakeProfit);
if (!m_trade.PositionModify(ticket, positionStopLoss, positionTakeProfit))
{
Comment(__FUNCTION__,", #1 => false. Result Retcode: ",m_trade.ResultRetcode(),", LastError: ", GetLastError(),", description of result: ",m_trade.ResultRetcodeDescription());
}
}
}
else if (positionType == POSITION_TYPE_SELL)
{
if ((positionStopLoss - Ask) > (pips * WHENTOMOVETOBE))
{
positionStopLoss = Ask + (pips * WHENTOMOVETOBE);
positionTakeProfit = Ask - (pips * TakeProfit);
if (!m_trade.PositionModify(ticket, positionStopLoss, positionTakeProfit))
{
Comment(__FUNCTION__,", #1 => false. Result Retcode: ",m_trade.ResultRetcode(),", LastError: ", GetLastError(),", description of result: ",m_trade.ResultRetcodeDescription());
}
}
}
}
}
}