[ARCHIVE !] Toute question de débutant, pour ne pas encombrer le forum. Professionnels, ne passez pas à côté. Nulle part sans toi - 4. - page 121

 

où ajouter le trailing stop et le breakeven ? et il n'augmente pas le lot lorsque vous augmentez le dépôt.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int Buy (int StopLoss = 0, int TakeProfit = 0, double Lot = 0)

{

int Ticket = 0 ;

double SL = 0 ;

double TP = 0 ;

double VolumeLot = 0 ;

RefreshRates() ;

si (StopLoss != 0)

SL = NormalizeDouble(Bid-StopLoss*Point, Digits) ;

si (TakeProfit != 0)

TP = NormalizeDouble(Ask+TakeProfit*Point, Digits) ;

si (Lot == 0)

VolumeLot = GetLot () ;

sinon

VolumeLot = Lot ;

Ticket = OrderSend(Symbol(), OP_BUY, VolumeLot, NormalizeDouble(Ask, Digits), 20, SL, TP, NULL, AccountNumber(), 0, Green) ;

si (Ticket == -1)

{

retourner (GetLastError () ;

}

sinon

{

retour (Ticket) ;

}

}

int Sell (int StopLoss = 0, int TakeProfit = 0, double Lot = 0)

{

int Ticket = 0 ;

double SL = 0 ;

double TP = 0 ;

double VolumeLot = 0 ;

RefreshRates() ;

si (StopLoss != 0)

SL = NormalizeDouble(Ask+StopLoss*Point, Digits) ;

si (TakeProfit != 0)

TP = NormalizeDouble(Bid-TakeProfit*Point, Digits) ;

si (Lot == 0)

VolumeLot = GetLot () ;

sinon

VolumeLot = Lot ;

Ticket = OrderSend(Symbol(), OP_SELL, VolumeLot, NormalizeDouble(Bid, Digits), 20, SL, TP, NULL, AccountNumber(), 0, Red) ;

si (Ticket == -1)

retourner (GetLastError () ;

sinon

retour (Ticket) ;

}

double GetLot ()

{

int lot ;

si (AccountBalance()>=300) lot=0.01 ;

si (AccountBalance()>=500) lot=0.02 ;

si (AccountBalance()>=800) lot=0.03 ;

retour (lot) ;

}

 
mahla:

où ajouter le trailing stop et le breakeven ? et il n'augmente pas le lot lorsque vous augmentez le dépôt.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Dans le conseiller

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

l'augmentation du lot de fonction...... est probablement mieux de changer

exemple :

extern double Lots               = 0.1;
extern double MaximumRisk        = 0.02;
extern double DecreaseFactor     = 3;
//////
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double LotsOptimized()
  {
   double lot=Lots;
   int    orders=HistoryTotal();     // history orders total
   int    losses=0;                  // number of losses orders without a break
//---- select lot size
   lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,1);
//---- calcuulate number of losses orders without a break
   if(DecreaseFactor>0)
     {
      for(int i=orders-1;i>=0;i--)
        {
         if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error in history!"); 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);
     }
//---- return lot size
   if(lot<0.1) lot=0.1;
   return(lot);
  }

Regardez la moyenne mobile.mq4

 

Pouvez-vous me dire comment utiliser les bandes de bollinger pour le momentum et non pour le prix ? J'ai essayé comme ceci :

BandOPeriodT - variable externe, période des bandes de bollinger.

MomentumPeriodT - période du momentum, respectivement.

BandOBottom=iBands (NULL,0,BandOPeriodT,1,0,iMomentum(NULL,0,MomentumPeriodT,PRICE_OPEN,0),MODE_LOWER,0) ;

et aussi comme ça :

MomO=iMomentum(NULL,0,MomentumPeriodT,PRICE_OPEN,0) ; - variable interne qui retourne la valeur

BandOBottom=iBands(NULL,0,BandOPeriodT,1,0,MomO,MODE_LOWER,0) ; - la variable doit retourner la valeur de la ligne de Bollinger inférieure pour la valeur de la variable précédente.

Par ailleurs, ai-je raison de penser que MODE_LOWER signifie que je récupère la valeur de la ligne BOLLINGER BOLLINGER dans une variable ? Si non, comment puis-je l'obtenir exactement ?

 
Ovari:

Pouvez-vous me dire comment utiliser les bandes de bollinger pour le momentum et non pour le prix ? J'ai essayé comme ceci :

BandOPeriodT - variable externe, période des bandes de bollinger.

MomentumPeriodT - période du momentum, respectivement.

BandOBottom=iBands (NULL,0,BandOPeriodT,1,0,iMomentum(NULL,0,MomentumPeriodT,PRICE_OPEN,0),MODE_LOWER,0) ;

et aussi comme ça :

MomO=iMomentum(NULL,0,MomentumPeriodT,PRICE_OPEN,0) ; - variable interne qui renvoie une valeur

BandOBottom=iBands(NULL,0,BandOPeriodT,1,0, MomO,MODE_LOWER,0) ; - la variable doit retourner la valeur de la ligne de Bollinger inférieure pour la valeur de la variable précédente.

Par ailleurs, ai-je raison de penser que MODE_LOWER signifie que je récupère la valeur de Bollinger BOW dans une variable ? Si non, comment puis-je l'obtenir exactement ?


Voir la bande-annonce - il y a des bandes pour le RSI - faites de même pour le Momentum.

Description - dans le journal - voir le code au début.

Dossiers :
 
Merci, parce que je suis très nouveau, et pas vraiment un programmeur non plus :)
 

Bonjour ! Aidez-nous ! Je veux essayer l'indicateur PVT :

double PVT = iCustom(NULL,240,"PVT",PRICE_CLOSE,1,1)

Pouvez-vous me dire ce qui manque ?

Le message suivant apparaît : 2012.05.14 19:34:46 Impossible d'ouvrir le fichier 'C:\Program Files\Alpari NZ MT4\experts\indicators\PVT.ex4' sur l'EURUSD,H4.

Merci !

 
mahla:

où ajouter le trailing stop et le breakeven ? et il n'augmente pas le lot lorsque vous augmentez le dépôt.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int Buy (int StopLoss = 0, int TakeProfit = 0, double Lot = 0)

{

int Ticket = 0 ;

double SL = 0 ;

double TP = 0 ;

double VolumeLot = 0 ;

RefreshRates() ;

si (StopLoss != 0)

SL = NormalizeDouble(Bid-StopLoss*Point, Digits) ;

si (TakeProfit != 0)

TP = NormalizeDouble(Ask+TakeProfit*Point, Digits) ;

si (Lot == 0)

VolumeLot = GetLot () ;

sinon

VolumeLot = Lot ;

Ticket = OrderSend(Symbol(), OP_BUY, VolumeLot, NormalizeDouble(Ask, Digits), 20, SL, TP, NULL, AccountNumber(), 0, Green) ;

si (Ticket == -1)

{

retourner (GetLastError () ;

}

sinon

{

retour (Ticket) ;

}

}

int Sell (int StopLoss = 0, int TakeProfit = 0, double Lot = 0)

{

int Ticket = 0 ;

double SL = 0 ;

double TP = 0 ;

double VolumeLot = 0 ;

RefreshRates() ;

si (StopLoss != 0)

SL = NormalizeDouble(Ask+StopLoss*Point, Digits) ;

si (TakeProfit != 0)

TP = NormalizeDouble(Bid-TakeProfit*Point, Digits) ;

si (Lot == 0)

VolumeLot = GetLot () ;

sinon

VolumeLot = Lot ;

Ticket = OrderSend(Symbol(), OP_SELL, VolumeLot, NormalizeDouble(Bid, Digits), 20, SL, TP, NULL, AccountNumber(), 0, Red) ;

si (Ticket == -1)

retourner (GetLastError () ;

sinon

retour (Ticket) ;

}

double GetLot ()

{

int lot ;

si (AccountBalance()>=300) lot=0.01 ;

si (AccountBalance()>=500) lot=0.02 ;

si (AccountBalance()>=800) lot=0.03 ;

retour (lot) ;

}

Supposons que la position ouverte a déjà été sélectionnée et que nous savons avec certitude que cette position est ouverte
pour le symbole auquel le conseiller expert est attaché. Supposons également que la valeur du trailing stop
en pips soit contenue dans la variable TrailingStop.

   int err;
   if (OrderType() == OP_BUY)
     {
       // позиция на покупку
       if ((Bid-OrderOpenPrice())>=(TrailingStop*Point))
         {
           // выставляем Stop Loss
           if (OrderModify(OrderTicket(), OrderOpenPrice(), Bid-TrailingStop*Point,
                                    OrderTakeProfit(), 0))
             Print("#", OrderTicket(),": trailing stop ", Bid-TrailingStop*Point);
           else
             {
              err = GetLastError();
              Print("#", OrderTicket(),": trailing stop error ", err);
             }
         }
     }
   else
     {
       // позиция на продажу
       if ((OrderOpenPrice()-Ask)>=(TrailingStop*Point))
         {
           // выставляем Stop Loss
           if (OrderModify(OrderTicket(), OrderOpenPrice(), Ask+TrailingStop*Point,
                                    OrderTakeProfit(), 0))
             Print("#", OrderTicket(),": trailing stop ", Ask+TrailingStop*Point);
           else
             {
              err = GetLastError();
              Print("#", OrderTicket(),": trailing stop error ", err);
             }
         }
     }
La fonction OrderProfit() renvoie le bénéfice de l'ordre sélectionné à l'aide de la fonction OrderSelect().

Supposons que nous voulions calculer le bénéfice que nous avons réalisé à partir de positions fermées.

   int profit = 0;
   int pos;
   for ( pos = 0; pos<HistoryTotal(); pos++ )
     {
       // выделим позицию
       if (OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY) == true)
         {
           // это не отложенный ордер?
           if ( OrderType() <= OP_SELL) profit += OrderProfit();            
         }
       else
           Print("Ошибка ", GetLastError(), " при выделении ордера ", OrderTicket());
     }
   Print("Суммарный профит по закрытым позициям = ", profit);
Et le code complet qui calcule le profit pour toutes les positions fermées,
qui sont ouvertes aujourd'hui, sera :

.
   //---- вычислим начало дня - переменная day_start
   int c_time = CurTime();  
   datetime day_start;
   day_start=c_time-TimeHour(c_time)*60*60-TimeMinute(c_time)*60-TimeSeconds(c_time);
   //---- подсчитаем прибыль
   int profit = 0;
   int pos;
   for ( pos = 0; pos<HistoryTotal(); pos++ )
     {
       // выделим позицию
       if (OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY) == true)
         {
           // это не отложенный ордер?
           if ( OrderType() <= OP_SELL)
             {
               // ордер был открыт сегодня?
               if (OrderOpenTime()>=day_start) profit += OrderProfit();
             }
         }
       else
           Print("Ошибка ", GetLastError(), " при выделении ордера ", OrderTicket());
     }
   Print("Суммарный профит по закрытым позициям = ", profit);
 
mahla:

? et il n'augmente pas la taille du lot lorsque vous augmentez le dépôt.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


Peut-être qu'il manque quelque chose d'autre dans le code :

double OrderLots( )
Renvoie le nombre de lots pour la commande sélectionnée.
La commande doit être présélectionnée à l'aide de OrderSelect().
Exemple :
 si(OrderSelect(10,SELECT_BY_POS)==true) Print("lots pour l'ordre 10 ",OrderLots()) ; sinon Print("OrderSelect() a retourné une erreur - ",GetLastError()) ;
 
borilunad:

Bonjour ! Aidez-nous ! Je veux essayer l'indicateur PVT :

Pouvez-vous me dire ce qui manque ?

Le message suivant apparaît : 2012.05.14 19:34:46 Impossible d'ouvrir le fichier 'C:\Program Files\Alpari NZ MT4\experts\indicators\PVT.ex4' sur l'EURUSD,H4.

Merci !

L'indicateur PVT lui-même est absent (êtes-vous sûr d'en avoir un ?).
 
alsu:
L'indicateur PVT lui-même est absent (êtes-vous sûr d'en avoir un ?).

Bien sûr que je l'ai et qu'il est compilé et eh4. Et mettez-le sur le tableau aussi. Peut-être que j'ai écrit quelque chose de mal ? Merci !