찻주전자의 질문 - 페이지 186

 
Yedelkin :
설마. for 문의 경우 변수 i의 유형을 지정해야 합니다. 위치를 선택하려면 먼저 PositionGetSymbol(i)을 사용한 다음 선택한 위치의 속성을 확인합니다.

  덕분에. 그래서?

 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 :

  덕분에. 그래서?

예, 계획은 이렇습니다. 여기 이 줄에

 PositionGetInteger ( POSITION_TYPE )== POSITION_TYPE_BUY

컴파일러는 경고를 발행할 가능성이 큽니다. PositionGetInteger ( POSITION_TYPE ) 값을 원하는 열거형 유형으로 명시적으로 캐스팅하여 처리합니다.

여기이 라인입니다

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

일부는 오름차순이 아닌 내림차순으로 실행하는 것을 선호합니다.

덧셈. 올바른 행을 if(PositionSelect(Symbol()))로 변경한 이유는 무엇입니까?

 
Yedelkin :

예, 계획은 이렇습니다. 여기 이 줄에

컴파일러는 경고를 발행할 가능성이 큽니다. PositionGetInteger ( POSITION_TYPE ) 값을 원하는 열거형 유형으로 명시적으로 캐스팅하여 처리합니다.

여기이 라인입니다

일부는 오름차순이 아닌 내림차순으로 실행하는 것을 선호합니다.

덧셈. 올바른 행을 if(PositionSelect(Symbol()))로 변경한 이유는 무엇입니까?

정말 감사합니다.

 if ( PositionSelect ( Symbol ()))

로 변경:

 PositionGetSymbol (i)== Symbol ()

또는 다음으로 변경하십시오.

 PositionSelect ( PositionGetSymbol (i))

어떤 옵션이 작동하는지 확인하겠습니다.

고맙습니다.

 
G001 : 으로 변경됨:

또는 다음으로 변경하십시오.

어느 것이 작동하는지 확인

PositionGetSymbol() 함수에 대한 설명을 읽으십시오. :)
 
정말 감사합니다 . 모든 것이 이미 작동하고 있습니다.

이제 표시기에서 신호를 가져와야 합니다.

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

나는 이것을하고 작동하지 않습니다.

 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 : 이제 표시기에서 신호를 가져와야 합니다. 이 작업을 수행했지만 작동하지 않습니다.

핸들이 무효인지 확인합니까?

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

핸들이 무효인지 확인하고 있습니까?

아니요. 그것이 무엇인지, 어떻게 하는지 보여주세요.
시간 내 주셔서 감사합니다.
 
G001 :
아니요. 그것이 무엇인지, 어떻게 하는지 보여주세요.
시간 내 주셔서 감사합니다.

예, 다른 곳에서 이미 유사한 수표를 가지고 있습니다.

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

INVALID_HANDLE 인 경우 오류를 인쇄하십시오.

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

예, 다른 곳에서 이미 유사한 수표를 가지고 있습니다.

INVALID_HANDLE 인 경우 오류를 인쇄하십시오.

정말 감사합니다. 이제 지표를 작성하지 않았다는 것을 이해하고 Expert Advisor에서해야하는지 몰랐습니다.
다시 한번 감사합니다.
 

완전히 지쳤습니다. 제대로 열리지 않습니다.

표시기 신호를 올바르게 읽지 않습니다.

도와주세요. 실수는 어디에 있습니까?

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