코드를 도와주세요

 
.
 

컴파일할 때 코드를 도와주세요.

 //+------------------------------------------------------------------+
//|                                                      stock K.mq4 |
//|                                                    mohsin mewati |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "mohsin mewati"
#property link        ""

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return ( 0 );
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return ( 0 );
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   //<snip>...begin of start()
 
       //calculate Stochastic Fast %K 
       for (i = ArraySize (MyArray)-StochPeriod- 1 ; i >= 0 ; i--)
      {
         ExtMapBuffer1[i] = CalculateStochOnArray(MyArray,i);
      }
 
//<snip>...end of start()...
}
 
//calculates Stochastics fast %k. takes the array holding our values and current index we are iterating through
double CalculateStochOnArray( double TheArray[], int i)
{
   double 
      SmallestBuffer[],       //buffer to hold the smallest value
      LargestBuffer[],         //buffer to hold the largest value
      StochFastK,             //Stochastic Fast %K
      top,                     //holds top half of calculation
      bottom;                 //holds bottom half of calculation
      
   int 
      position= 0 ;             //place in SmallestBuffer/Largestbuffer for our largest or smallest value
   
   ArrayResize (SmallestBuffer, ArraySize (TheArray));               //size our array accordingly
   ArrayResize (LargestBuffer, ArraySize (TheArray));  
   
   position = ArrayMinimum (TheArray, StochPeriod, i);           //find the smallest value that starts at index i and is of StochasticPeriod length
   SmallestBuffer[i] = TheArray[position];
 
   position = ArrayMaximum (TheArray, StochPeriod, i);           //find the largest value that starts at index i and is of StochasticPeriod length
   LargestBuffer[i] = TheArray[position];
 
   top = TheArray[i]-SmallestBuffer[i];                             //holds top half of StochFastK calculation
   bottom = MathMax ( 0.0001 , LargestBuffer[i] - SmallestBuffer[i]); //holds bottom half of StochFastK calculation. Use MathMax to prevent divide by zero errors
      
   StochFastK = (top/bottom)* 100 ;
   
   return (StochFastK);
}

//----
   return ( 0 );
  }
//+------------------------------------------------------------------+
 
여기에 오류가 있습니다
 
         ExtMapBuffer1[i] = CalculateStochOnArray(MyArray,i);

RTFM , 코딩 배우고 배열 ExtMapBuffer를 정의하십시오. 우리는 당신을 위해 그것을 코딩하지 않을 것입니다. 귀하의 시도( SRC 사용)와 문제의 특성을 게시 때 기꺼이 도와드리겠습니다.

다음에 원본 게시물을 편집할 때 다시 게시 하지 마십시오.

 

답장과 귀중한 시간을 할애해 주셔서 감사합니다. 이전 대화에 대한 사과를 받아주세요. 저는 대학에서 배운 C에 대한 지식이 거의 없습니다. 이것은 내가 이미 언급한 내 코드가 아닙니다.

주요 문제는 한 번에 구매 및 판매를 여는 전략을 가지고 컴파일할 때 11개의 오류가 있는 EA를 만들고 20핍 이득 및 마감 주문을 확인하는 것입니다. 지금은 확률적 지표 를 사용하고 싶습니다.

stochtics가 =>"75" 또는 <="25"이면 주문이 열리지 않습니다.

여기 코드가 있습니다.

도와주시면 전체 코드를 수정하여 다시 게시해 주세요. 감사합니다.

 //+------------------------------------------------------------------+
//|                                                 every tick20.mq4 |
//|                                                    mohsin mewati |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "mohsin mewati"
#property link        ""

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
 
int init()
  {
//----
   int order_open_time_buy = 0 ; //intiger to save buy open Time
   int order_open_time_sell = 0 ; //intiger to save sell open Time
   bool err_close_all_orders = 0 ; //bolean to save get last error for close all opened orders code
   
   bool err_sell= 0 ;
   bool err_buy= 0 ;
   bool err_selection_buy= 0 ;
   bool err_selection_sell= 0 ;
   bool buy_modified= 0 ;
   bool sell_modified= 0 ;
   double mf_buy= 0 ;
   double mf_sell= 0 ;
   int buy_trail= 0 ;
 
   int err_trail_buy= 0 ;
   int err_modify_sell= 0 ;
   int buy_selection= 0 ;
   bool buy_open_price= 0 ;
   int sell_selection= 0 ;
//----
   return ( 0 );
  }

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+

//----
 
   int start()
  {
  
   bool err_buy;
   int buy_ticket;
   bool err_sell;
   int sell_ticket;
   bool err_selection_buy;
   int buy_selection;
   double buy_open_price;
   bool err_selection_sell;
   int sell_selection;
   bool err_mf_buy;
   bool srr_mf_sell;
   bool err_mf_sell;
   bool err_trail_buy;
   bool err_modify_sell;
   bool buy_modified;
   bool err_trail_sell;
   bool err_modify_buy;
   
   
   
 
   //coding starts
  
  
   while (err_buy= 1 ){ //for loop started to execute a buy Order
  
   buy_ticket= OrderSend ( Symbol (), OP_BUY , 1 , Ask , 3 , Ask + 20 * Point , 0 ,Green); //code to execute a buy (buy order placed without SL but with a TP of 20 pips
  err_buy=GetLastError; //code to check either buy is executed or not?
  
 } //for loop end
   while (err_sell= 1 ){ //for loop to place a sell order
    sell_ticket = OrderSend ( Symbol (), OP_SELL , 1 , Ask , 3 , Ask - 20 * Point , 0 ,Red); //code to place a sell ,order placed without SL but with a TP of 20 pips
   err_sell=GetLastError; //code to check either sell is placed or not?
   } //for loop ends
   Alert ();
   
   //__________________________________________________________________________________________________________________________________
   
   while (err_selection_buy= "true" ){ // for loop start to selection of first executed order for further procedure
   buy_selection= OrderSelect ( "Buy_ticket" , SELECT_BY_TICKET ); //order select and stored in intiger
   err_selection_buy=GetLastError; //code to check eithet order is selected or not
   } //for loop ends
   buy_open_price= OrderOpenPrice ; //taking open price for the first selected order
   
     while (err_selection_sell= "true" ){ // for loop start to selection of second executed order for further procedure
   sell_selection= OrderSelect ( "Sell_ticket" , SELECT_BY_TICKET ); //order select and stored in intiger
   err_selection_sell=GetLastError; //code to check eithet order is selected or not
   } //for loop ends
   int sell_open_price= OrderOpenPrice ; //taking open price for the second selected order
   
   
   
   
   while ( "buy_trail=1" ; "Sell_trail=1" ){ // while loop started to check if thow of them or one is true
      
       while (err_mf_buy= "true" &&   "err_mf_sell=" true "" ){ //while loop start to take price quote every time for buy and sell
         double mf_buy= MarketInfo ( "GBPUSD" , MODE_POINT ); //code to store markeet info in integer mf_buy
        err_mf_buy=GetLastError; //code to confirm the previous line of code executed? 
       double mf_sell= MarketInfo ( "GBPUSD" , MODE_POINT ); //code to store markeet info in integer mf_sell
        err_mf_sell=GetLastError; //code to confirm the previous line of code executed? 
       }
       if (mf_buy- 20 =>buy_open_price && "Buy_trail=0" ){ //if condition to compare if current markeet quote which stored in mf_buy is 20 times greater than the open price of buy Order?
       while (err_trail_buy= "true" ){ //if above condition true for loop started to start trailing on buy order.
       OrderModify (buy_ticket,buy_open_price,+ 20 *TrailingStop); //code to start trailig stop on buy for 5 pips since our buy is in 20 pips profit the trail start at 15 pips
        err_trail_buy=GetLastError; //code to confirm the previous line of code executed? 
        }
         while (err_modify_sell= "true" ){ //if buy is in profit for 20 pips and trailing stop started on it i want my sell to modify for take profit for just 5 pips.
       OrderModify ( "Sell_ticket" , double stoploss,Order_Open_Price- 5 , "ORANGE" ) //code to modify sell for tp just for 5 pips
       err_modify_sell=GetLastError; //code to confirm the previous line of code executed? 
       buy_trail= 1 ; //intiger use to remember that the buy was in profit and all the cooding associated with it was executed there is no need to check .
       }
       else if (mf_sell+ 20 <= "Sell_open_price" && "Sell_trail=0" ){ //another logical test to check if buy was not in 20 pips if our sell is in 20 pips profit if so then in the next for loop statrted
       while (err_trail_sell= "true" ){ //for loop start to modify sell for trail
         OrderModify (sell_ticket),sell_open_price,- 20 *TrailingStop,); //code to modify sell for trailing as above mentioned for buy sell is also for 20 pips and if it is in 20 pips profit trailing start on 15 pips
        err_trail_sell=GetLastError; //code to confirm the previous line of code executed? 
        }
       while (err_modify_buy= "true" ){ //if our sell is in 20 pips profit and trailing executed on it while loop start to modify buy for tp for just 5 pips 
         OrderModify (   buy_ticket, double OrderOpenPrice + 5 ,   color arrow_color= "blue" ) //code to modify buy for tp just 5 pips
         err_modify_buy=GetLastError; //code to confirm the previous line of code executed? 
         sell_trail= 1 ; //intiger use to remember that the sell was in profit and all the cooding associated with it was executed there is no need to check .
         }
       
       }
       
       
   }

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

코드의 모든 줄에는 주석이 있어 코드를 쉽게 이해할 수 있습니다.

 

다음은 컴파일할 때 오류가 0인 메타 따옴표 확률적 코드입니다.

 //+------------------------------------------------------------------+
//|                                                   Stochastic.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link        "http://www.metaquotes.net/"

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 2
#property indicator_color1 LightSeaGreen
#property indicator_color2 Red
//---- input parameters
extern int KPeriod= 5 ;
extern int DPeriod= 3 ;
extern int Slowing= 3 ;
//---- buffers
double MainBuffer[];
double SignalBuffer[];
double HighesBuffer[];
double LowesBuffer[];
//----
int draw_begin1= 0 ;
int draw_begin2= 0 ;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- 2 additional buffers are used for counting.
   IndicatorBuffers ( 4 );
   SetIndexBuffer ( 2 , HighesBuffer);
   SetIndexBuffer ( 3 , LowesBuffer);
//---- indicator lines
   SetIndexStyle ( 0 , DRAW_LINE );
   SetIndexBuffer ( 0 , MainBuffer);
   SetIndexStyle ( 1 , DRAW_LINE );
   SetIndexBuffer ( 1 , SignalBuffer);
//---- name for DataWindow and indicator subwindow label
   short_name= "Sto(" +KPeriod+ "," +DPeriod+ "," +Slowing+ ")" ;
   IndicatorShortName (short_name);
   SetIndexLabel ( 0 ,short_name);
   SetIndexLabel ( 1 , "Signal" );
//----
   draw_begin1=KPeriod+Slowing;
   draw_begin2=draw_begin1+DPeriod;
   SetIndexDrawBegin ( 0 ,draw_begin1);
   SetIndexDrawBegin ( 1 ,draw_begin2);
//----
   return ( 0 );
  }
//+------------------------------------------------------------------+
//| Stochastic oscillator                                            |
//+------------------------------------------------------------------+
int start()
  {
   int     i,k;
   int     counted_bars= IndicatorCounted ();
   double price;
//----
   if ( Bars <=draw_begin2) return ( 0 );
//---- initial zero
   if (counted_bars< 1 )
     {
       for (i= 1 ;i<=draw_begin1;i++) MainBuffer[ Bars -i]= 0 ;
       for (i= 1 ;i<=draw_begin2;i++) SignalBuffer[ Bars -i]= 0 ;
     }
//---- minimums counting
   i= Bars -KPeriod;
   if (counted_bars>KPeriod) i= Bars -counted_bars- 1 ;
   while (i>= 0 )
     {
       double min= 1000000 ;
      k=i+KPeriod- 1 ;
       while (k>=i)
        {
         price= Low [k];
         if (min>price) min=price;
         k--;
        }
      LowesBuffer[i]=min;
      i--;
     }
//---- maximums counting
   i= Bars -KPeriod;
   if (counted_bars>KPeriod) i= Bars -counted_bars- 1 ;
   while (i>= 0 )
     {
       double max=- 1000000 ;
      k=i+KPeriod- 1 ;
       while (k>=i)
        {
         price= High [k];
         if (max<price) max=price;
         k--;
        }
      HighesBuffer[i]=max;
      i--;
     }
//---- %K line
   i= Bars -draw_begin1;
   if (counted_bars>draw_begin1) i= Bars -counted_bars- 1 ;
   while (i>= 0 )
     {
       double sumlow= 0.0 ;
       double sumhigh= 0.0 ;
       for (k=(i+Slowing- 1 );k>=i;k--)
        {
         sumlow+= Close [k]-LowesBuffer[k];
         sumhigh+=HighesBuffer[k]-LowesBuffer[k];
        }
       if (sumhigh== 0.0 ) MainBuffer[i]= 100.0 ;
       else MainBuffer[i]=sumlow/sumhigh* 100 ;
      i--;
     }
//---- last counted bar will be recounted
   if (counted_bars> 0 ) counted_bars--;
   int limit= Bars -counted_bars;
//---- signal line is simple movimg average
   for (i= 0 ; i<limit; i++)
      SignalBuffer[i]= iMAOnArray (MainBuffer, Bars ,DPeriod, 0 , MODE_SMA ,i);
//----
   return ( 0 );
  }
//+------------------------------------------------------------------+

빠른 K 값을 추출하고 (My_stockK)라는 이름의 intiger에 저장하기만 하면 됩니다.

 
mohsin360 :

컴파일할 때 코드를 도와주세요.

나는 어디에 선언되어 있습니까?

MyArray 는 어디에 선언되어 있습니까?

 for (i = ArraySize (MyArray)-StochPeriod- 1 ; i >= 0 ; i--)
 

위의 코드는 mt4 표시기 확률적 코드에서 선택합니다. 내 EA에서 사용할 수 있도록 intiger로 읽는 확률론을 추출하고 싶습니다.

 
mohsin360 :

위의 코드는 mt4 표시기 확률적 코드에서 선택합니다. 내 EA에서 사용할 수 있도록 intiger로 읽는 확률론을 추출하고 싶습니다.

알겠습니다. 계속하십시오.
 
mohsin360 : 빠른 K 값을 추출하고 (My_stockK)라는 이름의 intiger에 저장하기만 하면 됩니다.
빠른 K(및 D 및 감속)는 EA에서 가져오고 iStochastic에 전달합니다. - MQL4 문서
 

Ok mt 실수 나는 코드를 순서대로 붙여 넣습니다.

쉽게 이해할 수 있도록 여기에 다시 붙여넣습니다.

 //+------------------------------------------------------------------+
//|                                                   Stochastic.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link        "http://www.metaquotes.net/"

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 2
#property indicator_color1 LightSeaGreen
#property indicator_color2 Red
//---- input parameters
extern int KPeriod= 5 ;
extern int DPeriod= 3 ;
extern int Slowing= 3 ;
//---- buffers
double MainBuffer[];
double SignalBuffer[];
double HighesBuffer[];
double LowesBuffer[];
//----
int draw_begin1= 0 ;
int draw_begin2= 0 ;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- 2 additional buffers are used for counting.
   IndicatorBuffers ( 4 );
   SetIndexBuffer ( 2 , HighesBuffer);
   SetIndexBuffer ( 3 , LowesBuffer);
//---- indicator lines
   SetIndexStyle ( 0 , DRAW_LINE );
   SetIndexBuffer ( 0 , MainBuffer);
   SetIndexStyle ( 1 , DRAW_LINE );
   SetIndexBuffer ( 1 , SignalBuffer);
//---- name for DataWindow and indicator subwindow label
   short_name= "Sto(" +KPeriod+ "," +DPeriod+ "," +Slowing+ ")" ;
   IndicatorShortName (short_name);
   SetIndexLabel ( 0 ,short_name);
   SetIndexLabel ( 1 , "Signal" );
//----
   draw_begin1=KPeriod+Slowing;
   draw_begin2=draw_begin1+DPeriod;
   SetIndexDrawBegin ( 0 ,draw_begin1);
   SetIndexDrawBegin ( 1 ,draw_begin2);
//----
   return ( 0 );
  }
//+------------------------------------------------------------------+
//| Stochastic oscillator                                            |
//+------------------------------------------------------------------+
int start()
  {
   int     i,k;
   int     counted_bars= IndicatorCounted ();
   double price;
//----
   if ( Bars <=draw_begin2) return ( 0 );
//---- initial zero
   if (counted_bars< 1 )
     {
       for (i= 1 ;i<=draw_begin1;i++) MainBuffer[ Bars -i]= 0 ;
       for (i= 1 ;i<=draw_begin2;i++) SignalBuffer[ Bars -i]= 0 ;
     }
//---- minimums counting
   i= Bars -KPeriod;
   if (counted_bars>KPeriod) i= Bars -counted_bars- 1 ;
   while (i>= 0 )
     {
       double min= 1000000 ;
      k=i+KPeriod- 1 ;
       while (k>=i)
        {
         price= Low [k];
         if (min>price) min=price;
         k--;
        }
      LowesBuffer[i]=min;
      i--;
     }
//---- maximums counting
   i= Bars -KPeriod;
   if (counted_bars>KPeriod) i= Bars -counted_bars- 1 ;
   while (i>= 0 )
     {
       double max=- 1000000 ;
      k=i+KPeriod- 1 ;
       while (k>=i)
        {
         price= High [k];
         if (max<price) max=price;
         k--;
        }
      HighesBuffer[i]=max;
      i--;
     }
//---- %K line
   i= Bars -draw_begin1;
   if (counted_bars>draw_begin1) i= Bars -counted_bars- 1 ;
   while (i>= 0 )
     {
       double sumlow= 0.0 ;
       double sumhigh= 0.0 ;
       for (k=(i+Slowing- 1 );k>=i;k--)
        {
         sumlow+= Close [k]-LowesBuffer[k];
         sumhigh+=HighesBuffer[k]-LowesBuffer[k];
        }
       if (sumhigh== 0.0 ) MainBuffer[i]= 100.0 ;
       else MainBuffer[i]=sumlow/sumhigh* 100 ;
      i--;
     }
//---- last counted bar will be recounted
   if (counted_bars> 0 ) counted_bars--;
   int limit= Bars -counted_bars;
//---- signal line is simple movimg average
   for (i= 0 ; i<limit; i++)
      SignalBuffer[i]= iMAOnArray (MainBuffer, Bars ,DPeriod, 0 , MODE_SMA ,i);
//----
   return ( 0 );
  }
//+------------------------------------------------------------------+



다음은 한 intiger에서 빠른 K를 추출하고 다른 intiger에서 D를 추출하려는 코드입니다.

사유: