[Qualsiasi domanda da principiante, per non ingombrare il forum. Professionisti, non passate. Non posso andare da nessuna parte senza di te. - pagina 945

 

Grazie, ma non riesco a capire dove sia l'errore...

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

int start()
{
   int  counted_bars=IndicatorCounted();
   int  i,limit;

   if(counted_bars < 0) return(-1);
   if(counted_bars > 0) counted_bars--;
           limit = Bars-counted_bars;

   //
   
   for(i=limit; i>=0; i--)
   {  
      Prices[i] = iMA(NULL,0,1,0,MODE_SMA,PriceType,i);
            
         double MaxH = Prices[ArrayMaximum(Prices,period,i)];
         double MinL = Prices[ArrayMinimum(Prices,period,i)];
         if (MaxH!=MinL)
               Values[i] = 0.33*2*((Prices[i]-MinL)/(MaxH-MinL)-0.5)+0.67*Values[i+1];
         else  Values[i] = 0.00;
               Values[i] = MathMin(MathMax(Values[i],-0.999),0.999); 
               buffer5[i] = 0.5*MathLog((1+Values[i])/(1-Values[i]))+0.5*buffer5[i+1];

         if(buffer5[i]==buffer5[i+1])
            {
               buffer1[i]=buffer1[i+1];
               buffer2[i]=buffer2[i+1];
               buffer3[i]=buffer3[i+1];
               buffer4[i]=buffer4[i+1];
               continue;
            }
      
            buffer1[i]=EMPTY_VALUE;
            buffer2[i]=EMPTY_VALUE;
            buffer3[i]=EMPTY_VALUE;
            buffer4[i]=EMPTY_VALUE;
            if(buffer5[i]<0)
               {
                  if (buffer5[i]<buffer5[i+1]) buffer3[i]=buffer5[i];
                  if (buffer5[i]>buffer5[i+1]) buffer4[i]=buffer5[i];
               }
            if(buffer5[i]>0)
               {
                  if (buffer5[i]<buffer5[i+1]) buffer2[i]=buffer5[i];
                  if (buffer5[i]>buffer5[i+1]) buffer1[i]=buffer5[i];
               }
   }
   return(0);
}
 

Brava gente, per favore consigliatemi, ho bisogno di un CODICE per implementare TrailingStop!

Quelli che ho trovato online non funzionano (strisciando avanti e indietro)

 
void TrailPositions()
{
  int Orders = OrdersTotal();
  for (int i=0; i<Orders; i++)
  {
    if (!(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))) continue;
    if (OrderSymbol() != Symbol()) continue;
    {    
      if (OrderType() == OP_BUY)  
      {
        if (Bid-OrderOpenPrice() > MinProfit*Point) 
        {
          if (OrderStopLoss() < Bid-(TrailingStop+TrailingStep-1)*Point) 
          {
          OrderModify(OrderTicket(), OrderOpenPrice(), Bid-TrailingStop*Point,OrderTakeProfit(), 0, 0);
            if(UseSound == true)
            {
            PlaySound(SuccesSound);
            }           
          }
        }
      }   
      if (OrderType() == OP_SELL)  
      {
        if (OrderOpenPrice()-Ask > MinProfit*Point) 
        {
          if (OrderStopLoss() > Ask+(TrailingStop+TrailingStep-1)*Point) 
          {
          OrderModify(OrderTicket(), OrderOpenPrice(), Ask+TrailingStop*Point,OrderTakeProfit(), 0, 0);
            if(UseSound == true)
            {
            PlaySound(SuccesSound);
            }           
          }
        }
      }   
    }   
  }  
}
//+------------------------------------------------------------------+
sergeyka2003:

Brava gente, per favore consigliatemi, ho bisogno di un CODICE per implementare TrailingStop!

Quelli che ho trovato online non funzionano (strisciando avanti e indietro)

 
rustein:

Grazie, ma non riesco a capire dove sia l'errore...


bisogno di un indicatore completo
 
Vinin:

Bisogno di un indicatore completo

grazie

#property  indicator_separate_window
#property  indicator_buffers 5
#property  indicator_color1  Green
#property  indicator_color2  Red
#property  indicator_color3  Red
#property  indicator_color4  Green
#property  indicator_color5  DimGray
#property  indicator_width1  2
#property  indicator_width3  2
#property  indicator_width5  0

//
 
extern int  period = 21;
int  PriceType = PRICE_MEDIAN;

double buffer1[];
double buffer2[];
double buffer3[];
double buffer4[];
double buffer5[];
double Prices[];
double Values[];

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

int init()
{
   IndicatorBuffers(7);
      SetIndexBuffer(0,buffer1); SetIndexStyle(0,DRAW_HISTOGRAM);
      SetIndexBuffer(1,buffer2); SetIndexStyle(1,DRAW_HISTOGRAM);
      SetIndexBuffer(2,buffer3); SetIndexStyle(2,DRAW_HISTOGRAM);
      SetIndexBuffer(3,buffer4); SetIndexStyle(3,DRAW_HISTOGRAM);
      SetIndexBuffer(4,buffer5);
      SetIndexBuffer(5,Prices);
      SetIndexBuffer(6,Values);
   IndicatorShortName("Fisher ("+period+")");
   return(0);
}

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

int start()
{
   int  counted_bars=IndicatorCounted();
   int  i,limit;

   if(counted_bars < 0) return(-1);
   if(counted_bars > 0) counted_bars--;
           limit = Bars-counted_bars;

   //
   
   for(i=limit; i>=0; i--)
   {  
      Prices[i] = iMA(NULL,0,1,0,MODE_SMA,PriceType,i);
            
         double MaxH = Prices[ArrayMaximum(Prices,period,i)];
         double MinL = Prices[ArrayMinimum(Prices,period,i)];
         if (MaxH!=MinL)
               Values[i] = 0.33*2*((Prices[i]-MinL)/(MaxH-MinL)-0.5)+0.67*Values[i+1];
         else  Values[i] = 0.00;
               Values[i] = MathMin(MathMax(Values[i],-0.999),0.999); 
               buffer5[i] = 0.5*MathLog((1+Values[i])/(1-Values[i]))+0.5*buffer5[i+1];

         if(buffer5[i]==buffer5[i+1])
            {
               buffer1[i]=buffer1[i+1];
               buffer2[i]=buffer2[i+1];
               buffer3[i]=buffer3[i+1];
               buffer4[i]=buffer4[i+1];
               continue;
            }
      
            buffer1[i]=EMPTY_VALUE;
            buffer2[i]=EMPTY_VALUE;
            buffer3[i]=EMPTY_VALUE;
            buffer4[i]=EMPTY_VALUE;
            if(buffer5[i]<0)
               {
                  if (buffer5[i]<buffer5[i+1]) buffer3[i]=buffer5[i];
                  if (buffer5[i]>buffer5[i+1]) buffer4[i]=buffer5[i];
               }
            if(buffer5[i]>0)
               {
                  if (buffer5[i]<buffer5[i+1]) buffer2[i]=buffer5[i];
                  if (buffer5[i]>buffer5[i+1]) buffer1[i]=buffer5[i];
               }
   }
   return(0);
}
 

Alla prima esecuzione, le funzioni ArrayMaximum e ArrayMinimum erano fuori portata

#property  indicator_separate_window
#property  indicator_buffers 5
#property  indicator_color1  Green
#property  indicator_color2  Red
#property  indicator_color3  Red
#property  indicator_color4  Green
#property  indicator_color5  DimGray
#property  indicator_width1  2
#property  indicator_width3  2
#property  indicator_width5  0

//

extern int  period = 21;
int  PriceType = PRICE_MEDIAN;

double buffer1[];
double buffer2[];
double buffer3[];
double buffer4[];
double buffer5[];
double Prices[];
double Values[];

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

int init()
{
   IndicatorBuffers(7);
      SetIndexBuffer(0,buffer1); SetIndexStyle(0,DRAW_HISTOGRAM);
      SetIndexBuffer(1,buffer2); SetIndexStyle(1,DRAW_HISTOGRAM);
      SetIndexBuffer(2,buffer3); SetIndexStyle(2,DRAW_HISTOGRAM);
      SetIndexBuffer(3,buffer4); SetIndexStyle(3,DRAW_HISTOGRAM);
      SetIndexBuffer(4,buffer5);
      SetIndexBuffer(5,Prices);
      SetIndexBuffer(6,Values);
   IndicatorShortName("Fisher ("+period+")");
   return(0);
}

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

int start()
{
   int  counted_bars=IndicatorCounted();
   int  i,limit=Bars-counted_bars;

   if(limit > 1) 
      limit = Bars-period-1;


   
   for(i=limit; i>=0; i--)
   {  
      Prices[i] = iMA(NULL,0,1,0,MODE_SMA,PriceType,i);
            
         double MaxH = Prices[ArrayMaximum(Prices,period,i)];
         double MinL = Prices[ArrayMinimum(Prices,period,i)];
         if (MaxH!=MinL)
               Values[i] = 0.33*2*((Prices[i]-MinL)/(MaxH-MinL)-0.5)+0.67*Values[i+1];
         else  Values[i] = 0.00;
               Values[i] = MathMin(MathMax(Values[i],-0.999),0.999); 
               buffer5[i] = 0.5*MathLog((1+Values[i])/(1-Values[i]))+0.5*buffer5[i+1];

         if(buffer5[i]==buffer5[i+1])
            {
               buffer1[i]=buffer1[i+1];
               buffer2[i]=buffer2[i+1];
               buffer3[i]=buffer3[i+1];
               buffer4[i]=buffer4[i+1];
               continue;
            }
      
            buffer1[i]=EMPTY_VALUE;
            buffer2[i]=EMPTY_VALUE;
            buffer3[i]=EMPTY_VALUE;
            buffer4[i]=EMPTY_VALUE;
            if(buffer5[i]<0)
               {
                  if (buffer5[i]<buffer5[i+1]) buffer3[i]=buffer5[i];
                  if (buffer5[i]>buffer5[i+1]) buffer4[i]=buffer5[i];
               }
            if(buffer5[i]>0)
               {
                  if (buffer5[i]<buffer5[i+1]) buffer2[i]=buffer5[i];
                  if (buffer5[i]>buffer5[i+1]) buffer1[i]=buffer5[i];
               }
   }
   return(0);
}
 
Vinin:

Alla prima esecuzione, le funzioni ArrayMaximum e ArrayMinimum erano fuori portata

Grazie !!!
 

Cercando di implementare una semplice inversione. Quando si raggiunge una posizione di arresto --> aprire la posizione opposta. Non riesco a fare in modo che apra una volta la posizione opposta e non apra nient'altro. Si prega di avvisare.

 

L'ho implementato nel seguente modo - questa è una condizione - se la posizione precedente ha chiuso con una perdita, allora aprendo quella opposta... Se hai bisogno di aprire la posizione opposta esattamente quando viene raggiunto lo stop loss della posizione precedente, allora Kim Igor Vladimirovich su http://www.kimiv.ru/ ha una funzione che determina esattamente come l'ordine viene chiuso esattamente dallo stop loss. Quindi, quando si collega questa funzione, si deve prescrivere la condizione se la posa è stata chiusa quando è stato raggiunto lo stop loss. Se lo è stata, se ne deve aprire un'altra.

PS: Mi sono appena ricordato che questo codice fi chiusura per una posa a stop loss è stato postato su questo thread qualche pagina prima... Date un'occhiata.

//---Поиск последнего отработавшего ордера для открытия очередной позиции ---
   
   for (orderIndex = (OrdersHistoryTotal() - 1); orderIndex >= 0; orderIndex--)
   {   
      if (!OrderSelect(orderIndex, SELECT_BY_POS, MODE_HISTORY))
      {
         Print("Ошибка при доступе к исторической базе (",GetLastError(),")");
         continue;
      }
   
      if ((OrderSymbol() != Symbol()) || (OrderMagicNumber() != MagicNumber))
      {
         continue;
      }
      
        
   //-------------------------Принимаем в расчет только ордер, закрытый недавно-----------------------
         
      if (OrderCloseTime() >= iTime(NULL, 0, 1))
      {
         int lastType = OrderType();
         double lastLots = OrderLots();
         double lastProfit = OrderProfit() + OrderSwap();
         
        // Print ("lastProfit = ", NormalizeDouble(lastProfit, 1));
         
       
         
         // Анализ только что закрывшегося ордера
      
         if (lastProfit < 0.0)
         {
  //---Ордер закрылся с убытком открываемся в ОБРАТНОМ направлении
                           
           
 // ---------НОРМАЛИЗУЕМ НОВЫЕ РАСЧЕТНЫЕ ЛОТЫ И ОТКРЫВАЕМ ОЧЕРЕДНУЮ ПОЗИЦИЮ...            
    
  // -----если предыдущий ордер был бай, то открываем очередной ордер   
            lots = NormalizeLots(lots);
            if (lastType == OP_SELL)  OrderSend(Symbol(), OP_BUY, lots,...);
                          
            if (lastType == OP_BUY)   OrderSend(Symbol(), OP_SELL, lots, ...);
          }           
        
         
         return (0);
       }
      
      // Найден закрытый ордер, но он старый
      
      break;
   }
 
001:

Cercando di implementare una semplice inversione. Quando si raggiunge una posizione di arresto --> aprire la posizione opposta. Non riesco a fare in modo che apra una volta la posizione opposta e non apra nient'altro. Si prega di avvisare.

Cosa succede se a livello di stop si mette semplicemente l'ordine pendente? Non funzionerebbe così?
Motivazione: