Çaydanlıktan gelen sorular - sayfa 186

 
Yedelkin :
Tam olarak değil. for ifadesi için, i değişkeninin türünü belirtmeniz gerekir. Bir pozisyon seçmek için önce PositionGetSymbol (i)'yi kullanın , ardından seçilen pozisyonun özelliklerini görüntüleyin.

  Sayesinde. Böyle?

 int TotalBullPositions()
{
   int Counter= 0 ;
   for ( int i = 0 ; i < PositionsTotal (); i++)
  {
    if(PositionSelect(Symbol()))
    {
       if ( PositionGetInteger ( POSITION_MAGIC )==Magic && PositionGetInteger ( POSITION_TYPE )== POSITION_TYPE_BUY ) 
      Counter++;}}
   return (Counter);
}
 
G001 :

  Sayesinde. Böyle?

Evet şema bu şekilde. İşte bu satırda

 PositionGetInteger ( POSITION_TYPE )== POSITION_TYPE_BUY

derleyici büyük olasılıkla bir uyarı verecektir. PositionGetInteger ( POSITION_TYPE ) değeri açıkça istenen numaralandırma türüne dönüştürülerek işlenir.

İşte bu çizgi

 for ( int i = 0 ; i < PositionsTotal (); i++)

bazıları artan sırada değil, azalan sırada koşmayı tercih eder.

Ek. Doğru satırı neden if(PositionSelect(Symbol())) olarak değiştirdiniz?

 
Yedelkin :

Evet şema bu şekilde. İşte bu satırda

derleyici büyük olasılıkla bir uyarı verecektir. PositionGetInteger ( POSITION_TYPE ) değeri açıkça istenen numaralandırma türüne dönüştürülerek işlenir.

İşte bu çizgi

bazıları artan sırada değil, azalan sırada koşmayı tercih eder.

Ek. Doğru satırı neden if(PositionSelect(Symbol())) olarak değiştirdiniz?

Çok teşekkürler.

 if ( PositionSelect ( Symbol ()))

Şu şekilde değiştirildi:

 PositionGetSymbol (i)== Symbol ()

Veya bununla değiştirin:

 PositionSelect ( PositionGetSymbol (i))

Hangi seçeneğin işe yaradığını kontrol edeceğim.

Teşekkür ederim.

 
G001 : şekilde değiştirildi:

Veya bununla değiştirin:

Hangisinin çalıştığını kontrol edin

Sadece PositionGetSymbol() fonksiyonunun açıklamasını okuyun. :)
 
çok teşekkür ederim Her şey zaten çalışıyor.

Şimdi göstergeden sinyalleri almamız gerekiyor:

 //+------------------------------------------------------------------+ 
//|                                                      MACDATR.mq5 | 
//|                                      Copyright © 2011, Svinozavr | 
//+------------------------------------------------------------------+ 
//---- Indicator settings
#property indicator_separate_window 
#property indicator_buffers 4 
#property indicator_plots   4
#property indicator_level1 + 0.0005
#property indicator_level2 - 0.0005
#property indicator_levelcolor DimGray
#define RESET 0
//-----
#property indicator_type1 DRAW_HISTOGRAM
#property indicator_color1 Gray
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
#property indicator_label1 "MACD"
//-----
#property indicator_type2 DRAW_HISTOGRAM
#property indicator_color2 Green
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
#property indicator_label2 "Bull"
//-----
#property indicator_type3 DRAW_HISTOGRAM
#property indicator_color3 Red
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
#property indicator_label3 "Bear"
//-----
#property indicator_type4 DRAW_LINE
#property indicator_color4 Olive
#property indicator_style4 STYLE_SOLID
#property indicator_width4 1
#property indicator_label4 "ATR"
//-----
//----- Indicator parameters
//+------------------------------------------------------------------+
input uint FastEMA      = 12 ;
input uint SlowEMA      = 26 ;
input uint SignalEMA = 9 ;
input int   ATRG         = 0 ;
input ENUM_APPLIED_PRICE AppliedPrice= PRICE_CLOSE ;
//+------------------------------------------------------------------+
//-----
double ATRmin= 0 ;
double kATR= 1 ;
int min_rates_total;
int ATRHandle,MACDHandle;
double MACDBuffer[],ATRBuffer[],Bull[],Bear[];
//+------------------------------------------------------------------+    
//| MACD indicator initialization function                           | 
//+------------------------------------------------------------------+  
void OnInit ()
{
//-----
   if (ATRG) min_rates_total= int ( MathMax (FastEMA,SlowEMA)+ATRG);
   else min_rates_total= 2 * int ( MathMax (FastEMA,SlowEMA));
//-----
   int ATR;
   if (!ATRG) ATR= int (SlowEMA); 
   else ATR=ATRG;
  ATRmin*= _Point ;
//-----
  ATRHandle= iATR ( NULL , 0 ,ATR);
   if (ATRHandle== INVALID_HANDLE ) Print ( " Íå óäàëîñü ïîëó÷èòü õåíäë èíäèêàòîðà ATR" );
//-----
  MACDHandle= iMACD ( NULL , 0 ,FastEMA,SlowEMA,SignalEMA,AppliedPrice);
   if (MACDHandle== INVALID_HANDLE ) Print ( " Íå óäàëîñü ïîëó÷èòü õåíäë èíäèêàòîðà MACD" );
//-----
   SetIndexBuffer ( 0 ,MACDBuffer, INDICATOR_DATA );
   PlotIndexSetInteger ( 0 , PLOT_DRAW_BEGIN ,min_rates_total);
   ArraySetAsSeries (MACDBuffer, true );
//-----
   SetIndexBuffer ( 1 ,Bull, INDICATOR_DATA );
   PlotIndexSetInteger ( 1 , PLOT_DRAW_BEGIN ,min_rates_total);
   ArraySetAsSeries (Bull, true );
//-----
   SetIndexBuffer ( 2 ,Bear, INDICATOR_DATA );
   PlotIndexSetInteger ( 2 , PLOT_DRAW_BEGIN ,min_rates_total);
   ArraySetAsSeries (Bear, true );
//-----
   SetIndexBuffer ( 3 ,ATRBuffer, INDICATOR_DATA );
   PlotIndexSetInteger ( 3 , PLOT_DRAW_BEGIN ,min_rates_total);
   ArraySetAsSeries (ATRBuffer, true );
//-----
   string shortname;
   StringConcatenate (shortname, "MACDATR (" ,FastEMA, ", " ,SlowEMA, ", " ,SignalEMA, ", " , EnumToString (AppliedPrice), ")" );
//-----
   IndicatorSetString ( INDICATOR_SHORTNAME ,shortname);
//-----
   IndicatorSetInteger ( INDICATOR_DIGITS , _Digits + 1 );
//-----
}
//+------------------------------------------------------------------+  
//| MACD iteration function                                          | 
//+------------------------------------------------------------------+  
int OnCalculate (
                 const int rates_total,
                 const int prev_calculated,
                 const datetime &time[],
                 const double &open[],
                 const double &high[],
                 const double &low[],
                 const double &close[],
                 const long &tick_volume[],
                 const long &volume[],
                 const int &spread[]
                )
  {
//----- Check for data
   if (rates_total<min_rates_total) return ( 0 );
//-----
   int to_copy,limit,i;
   double atr,Atr[];
   datetime Time[ 1 ];
//-----
   if (prev_calculated>rates_total || prev_calculated<= 0 )
  {
    limit=rates_total-min_rates_total;
  }
   else limit=rates_total-prev_calculated;
//----- 
   ArraySetAsSeries (Atr, true );
//-----
  to_copy=limit+ 1 ;
//-----
   if ( CopyBuffer (ATRHandle, 0 , 0 ,to_copy,Atr)<= 0 ) return (RESET);
   if ( CopyBuffer (MACDHandle, MAIN_LINE , 0 ,to_copy,MACDBuffer)<= 0 ) return (RESET);
//-----
   for (i=limit; i>= 0 && ! IsStopped (); i--)
  {
    atr=kATR*Atr[i]; // ATR
    atr= MathMax (atr,ATRmin);
//-----
     if (MACDBuffer[i]> 0 ) {ATRBuffer[i]=MACDBuffer[i]-atr;}
     if (MACDBuffer[i]< 0 ) {ATRBuffer[i]=MACDBuffer[i]+atr;}
  }
//-----
   for (i=limit; i>= 0 && ! IsStopped (); i--)
  {
//-----
    Bear[i]= 0 ;
    Bull[i]= 0 ;
//-----
     if (MACDBuffer[i]> 0 && MACDBuffer[i+ 1 ]<MACDBuffer[i] && ATRBuffer[i]>= 0 ) {Bull[i]=MACDBuffer[i];}
     if (MACDBuffer[i]< 0 && MACDBuffer[i+ 1 ]>MACDBuffer[i] && ATRBuffer[i]<= 0 ) {Bear[i]=MACDBuffer[i];}
  }
//+------------------------------------------------------------------+
//----- Done
   return (rates_total);
}
//+------------------------------------------------------------------+

Bunu yapıyorum ve işe yaramıyor.

 double Bull[ 3 ];
double Bear[ 3 ];

Indicator= iCustom ( NULL ,IndiTF, "MACDATR" ,FastEMA,SlowEMA,SignalEMA,ATRG,AppliedPrice);
return ( 0 );}
..................
   CopyBuffer (Indicator, 1 , 0 , 3 ,Bull);
   ArraySetAsSeries (Bull, true );
   CopyBuffer (Indicator, 2 , 0 , 3 ,Bear);
   ArraySetAsSeries (Bear, true );
.....................
 if (Bull[ 1 ] > 0.0 && Bull[ 2 ] <= 0.0 )
........................
if (Baer[ 1 ] < 0.0 && Bear[ 2 ] >= 0.0 )
........................
 
G001 : Şimdi göstergeden sinyalleri almamız gerekiyor: Bunu yapıyorum ve çalışmıyor.

Tutamacı geçersizlik açısından kontrol ediyor musunuz?

Indicator= iCustom ( NULL ,IndiTF, "MACDATR" ,FastEMA,SlowEMA,SignalEMA,ATRG,AppliedPrice);
 
Yedelkin :

Tutamacı geçersizlik için kontrol ediyor musunuz?

Numara. Lütfen bana ne olduğunu ve nasıl yapılacağını göster.
Zaman ayırdığınız için teşekkür ederim.
 
G001 :
Numara. Lütfen bana ne olduğunu ve nasıl yapılacağını göster.
Zaman ayırdığınız için teşekkür ederim.

Evet, başka bir yerde benzer bir çekiniz zaten var:

MACDHandle= iMACD ( NULL , 0 ,FastEMA,SlowEMA,SignalEMA,AppliedPrice);
   if (MACDHandle== INVALID_HANDLE ) Print ( " Íå óäàëîñü ïîëó÷èòü õåíäë èíäèêàòîðà MACD" );

INVALID_HANDLE ise, hatayı yazdırın

 ResetLastError ();
  Indicator= iCustom(....) ;
   if (Indicator== INVALID_HANDLE ) Print ( "_LastError=" , _LastError ); 
 
Yedelkin :

Evet, başka bir yerde benzer bir çekiniz zaten var:

INVALID_HANDLE ise, hatayı yazdırın

Çok teşekkürler. Şimdi anladım ki indikatörü ben yazmamışım ve bunu Expert Advisor'da yapmam gerektiğini bilmiyordum.
Tekrar teşekkürler.
 

Tamamen bitkin. Doğru açılmıyor.

Gösterge sinyallerini doğru okumuyor.

Lütfen yardım edin. Hata nerede?

 //+------------------------------------------------------------------+
//|                                                       Expert.mq5 |
//+------------------------------------------------------------------+
// Input Parameters
//+------------------------------------------------------------------+
input int     TakeProfit     = 550 ;
input int     StopLoss       = 550 ;
input int     OrderDrive     = 20 ;
input double  LotSize       = 0.01 ;
//+------------------------------------------------------------------+
input ENUM_TIMEFRAMES IndiTF= PERIOD_CURRENT ;
input int     FastEMA        = 12 ;
input int     SlowEMA        = 26 ;
input int     SignalEMA      = 9 ;
input int     ATRG           = 0 ;
input ENUM_APPLIED_PRICE AppliedPrice= PRICE_CLOSE ;
//+------------------------------------------------------------------+
MqlTradeRequest request;
MqlTradeResult result;
MqlTradeCheckResult check;
int Indicator;
double Bull[];
double Bear[];
double Ask,Bid;
int i,pos,Spread;
ulong StopLevel;
//+------------------------------------------------------------------+
int OnInit ()
{
   ResetLastError ();
  Indicator= iCustom ( Symbol (),IndiTF, "MACDATR" ,FastEMA,SlowEMA,SignalEMA,ATRG,AppliedPrice);
   if (Indicator== INVALID_HANDLE ) Print ( "HandleError = " , _LastError ); 
   return ( 0 );
}
//+------------------------------------------------------------------+
void OnDeinit ( const int reason){}
//+------------------------------------------------------------------+
void OnTick ()
{
//-----
   CopyBuffer (Indicator, 1 , 0 , 3 ,Bull);
   ArraySetAsSeries (Bull, true );
//-----
   CopyBuffer (Indicator, 2 , 0 , 3 ,Bear);
   ArraySetAsSeries (Bear, true );
//-----
  Ask = NormalizeDouble ( SymbolInfoDouble ( Symbol (), SYMBOL_ASK ), _Digits );
  Bid = NormalizeDouble ( SymbolInfoDouble ( Symbol (), SYMBOL_BID ), _Digits );
  Spread= int ( SymbolInfoInteger ( Symbol (), SYMBOL_SPREAD ));
  StopLevel= SymbolInfoInteger ( Symbol (), SYMBOL_TRADE_STOPS_LEVEL );
//+------------------------------------------------------------------+
   if ( OrdersTotal () < 1 && PositionsTotal () < 1 )
  {
//----- Open BUY_STOP
     if (Bear[ 1 ] >= 0.0 && Bear[ 2 ] < 0.0 )
    {
      request.action = TRADE_ACTION_PENDING ;
      request.symbol = _Symbol ;
      request.volume = LotSize;
      request.price= NormalizeDouble (Ask+StopLevel* _Point , _Digits );
      request.sl = NormalizeDouble (request.price - StopLoss* _Point , _Digits );
      request.tp = NormalizeDouble (request.price + TakeProfit* _Point , _Digits );
      request.type= ORDER_TYPE_BUY_STOP ;
      request.type_filling= ORDER_FILLING_FOK ;
       if ( OrderCheck (request,check))
      {
         OrderSend (request,result);
      }
    }
//----- Open SELL_STOP
     if (Bull[ 1 ] <= 0.0 && Bull[ 2 ] > 0.0 )
    {
      request.action = TRADE_ACTION_PENDING ;
      request.symbol = _Symbol ;
      request.volume = LotSize;
      request.price= NormalizeDouble (Bid-StopLevel* _Point , _Digits );
      request.sl = NormalizeDouble (request.price + StopLoss* _Point , _Digits );
      request.tp = NormalizeDouble (request.price - TakeProfit* _Point , _Digits );
      request.type= ORDER_TYPE_SELL_STOP ;
      request.type_filling= ORDER_FILLING_FOK ;
       if ( OrderCheck (request,check))
      {
         OrderSend (request,result);
      }                             
    }
  }
}
//+------------------------------------------------------------------+