[Qualsiasi domanda da principiante, per non ingombrare il forum. Professionisti, non passate oltre. Da nessuna parte senza di te - 4. - pagina 121

 

dove aggiungere il trailing stop e l'uscita di pareggio? e non aumenta il lotto quando si aumenta il deposito

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

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

{

int Ticket = 0;

doppio SL = 0;

doppio TP = 0;

doppio VolumeLot = 0;

RefreshRates();

se (StopLoss != 0)

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

se (TakeProfit != 0)

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

se (Lotto == 0)

VolumeLot = GetLot ();

else

VolumeLot = Lotto;

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

se (Biglietto == -1)

{

return (GetLastError ();

}

else

{

ritorno (biglietto);

}

}

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

{

int Ticket = 0;

doppio SL = 0;

doppio TP = 0;

doppio VolumeLot = 0;

RefreshRates();

se (StopLoss != 0)

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

se (TakeProfit != 0)

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

se (Lotto == 0)

VolumeLot = GetLot ();

else

VolumeLot = Lotto;

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

se (Biglietto == -1)

return (GetLastError ();

else

ritorno (biglietto);

}

doppio GetLot ()

{

lotto int;

se (AccountBalance()>=300) lotto=0,01;

se (AccountBalance()>=500) lotto=0,02;

se (AccountBalance()>=800) lotto=0,03;

ritorno (lotto);

}

 
mahla:

dove aggiungere il trailing stop e l'uscita di pareggio? e non aumenta il lotto quando si aumenta il deposito

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

Nel consigliere

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

funzione lotto increase...... è probabilmente meglio cambiare

esempio:

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

Guarda la media mobile.mq4

 

Puoi per favore dirmi come usare le bande di bollinger per il momentum e non per il prezzo? Ho provato così:

BandOPeriodT - variabile esterna, periodo delle bande di bollinger.

MomentumPeriodT - periodo di momentum, rispettivamente.

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

e anche come questo:

MomO=iMomentum(NULL,0,MomentumPeriodT,PRICE_OPEN,0); - variabile interna che restituisce il valore

BandOBottom=iBands(NULL,0,BandOPeriodT,1,0,MomO,MODE_LOWER,0); - la variabile dovrebbe restituire il valore della linea di Bollinger inferiore per il valore precedente della variabile.

Inoltre, ho ragione nel supporre che MODE_LOWER significa che ottengo il valore di BOLLINGER BOLLINGER in una variabile? Se no, come posso ottenerlo esattamente?

 
Ovari:

Puoi per favore dirmi come usare le bande di bollinger per il momentum e non per il prezzo? Ho provato così:

BandOPeriodT - variabile esterna, periodo delle bande di bollinger.

MomentumPeriodT - periodo di momentum, rispettivamente.

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

e anche come questo:

MomO=iMomentum(NULL,0,MomentumPeriodT,PRICE_OPEN,0); - variabile interna che restituisce il valore

BandOBottom=iBands(NULL,0,BandOPeriodT,1,0, MomO,MODE_LOWER,0); - la variabile dovrebbe restituire il valore della linea di Bollinger inferiore per il valore precedente della variabile.

Inoltre, ho ragione a pensare che MODE_LOWER significa che ottengo il valore di Bollinger BOW in una variabile? Se no, come posso ottenerlo esattamente?


Vedi trailer - ci Bande per RSI - fai lo stesso per Momentum.

Descrizione - nel log - vedi codice all'inizio.

 
Grazie, perché sono molto nuovo, e non sono neanche un gran programmatore:)
 

Ciao, per favore aiutatemi! Voglio provare l'indicatore PVT:

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

Potete dirmi per favore cosa manca?

Dice: 2012.05.14 19:34:46 Impossibile aprire il file 'C:\Program Files\Alpari NZ MT4\experts\indicators\PVT.ex4' su EURUSD,H4

Grazie!

 
mahla:

dove aggiungere il trailing stop e l'uscita di pareggio? e non aumenta il lotto quando si aumenta il deposito

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

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

{

int Ticket = 0;

doppio SL = 0;

doppio TP = 0;

doppio VolumeLot = 0;

RefreshRates();

se (StopLoss != 0)

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

se (TakeProfit != 0)

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

se (Lotto == 0)

VolumeLot = GetLot ();

else

VolumeLot = Lotto;

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

se (Biglietto == -1)

{

return (GetLastError ();

}

else

{

ritorno (biglietto);

}

}

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

{

int Ticket = 0;

doppio SL = 0;

doppio TP = 0;

doppio VolumeLot = 0;

RefreshRates();

se (StopLoss != 0)

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

se (TakeProfit != 0)

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

se (Lotto == 0)

VolumeLot = GetLot ();

else

VolumeLot = Lotto;

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

se (Biglietto == -1)

return (GetLastError ();

else

ritorno (biglietto);

}

doppio GetLot ()

{

lotto int;

se (AccountBalance()>=300) lotto=0,01;

se (AccountBalance()>=500) lotto=0,02;

se (AccountBalance()>=800) lotto=0,03;

ritorno (lotto);

}

Supponiamo che la posizione aperta sia già stata selezionata e sappiamo per certo che questa posizione è aperta
per il simbolo a cui è collegato l'Expert Advisor. Supponiamo anche che il valore del trailing stop
in pip sia contenuto nella variabile 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 funzione OrderProfit() restituisce il profitto per l'ordine selezionato utilizzando la funzione OrderSelect().

Supponiamo di voler calcolare il profitto che abbiamo ottenuto dalle posizioni chiuse.

   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);
E il codice completo che calcola il profitto per tutte le posizioni chiuse,
che sono aperte oggi, sarà:

   //---- вычислим начало дня - переменная 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:

E non aumenta la dimensione del lotto quando si aumenta il deposito

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


Forse c'è qualcos'altro che manca nel codice:

doppio OrderLots( )
Restituisce il numero di lotti per l'ordine selezionato.
L'ordine deve essere preselezionato usando OrderSelect().
Esempio:
 if(OrderSelect(10,SELECT_BY_POS)==true) Print("lots for the order 10 ",OrderLots()); else Print("OrderSelect() has returned an error - ",GetLastError());
 
borilunad:

Ciao, per favore aiutatemi! Voglio provare l'indicatore PVT:

Potete dirmi per favore cosa manca?

Dice: 2012.05.14 19:34:46 Impossibile aprire il file 'C:\Program Files\Alpari NZ MT4\experts\indicators\PVT.ex4' su EURUSD,H4

Grazie!

Manca l'indicatore PVT stesso (sei sicuro di averne uno?).
 
alsu:
Manca l'indicatore PVT stesso (sei sicuro di averne uno?).

Certo che ce l'ho ed è compilato e eh4. E mettetelo anche sul grafico. Forse ho scritto qualcosa di sbagliato? Grazie!
Motivazione: