2016-11-29 6 views
0

私は取引のためにEA(エキスパート・アドバイザリー)を構築していますが、第1注文が実行された場合、5分後に注文を実行する機能を設定することができますか?5分ごとに特定の機能を実行するにはどうすればよいですか?

私の現在のコードの問題は、一度要件を満たせば、私はお金がなくなるまで同じ注文を置いていきますが、一度それが要件を満たしていれば、 5分、条件が依然として要件を満たしているかどうかを再度チェックし、そうであれば再度注文を行い、そうでなければ要件が満たされるまで毎分チェックを続ける。

簡潔に言えば、第1注文が実行されると、5分以内に注文が行われず、5分後に条件がテストされます。

ここにコードがあります。

あなたはこのような任意の間隔での関数の呼び出しを行うことができます
extern int MagicNumber=10001; 
extern double Lots =0.1; 
extern double StopLoss=0; 
extern double TakeProfit=0; 
extern int TrailingStop=0; 
extern int Slippage=3; 
//+------------------------------------------------------------------+ 
// expert start function 
//+------------------------------------------------------------------+ 
int start() 
{ 
    double MyPoint=Point; 
    if(Digits==3 || Digits==5) MyPoint=Point*10; 

    double TheStopLoss=0; 
    double TheTakeProfit=0; 
    if(TotalOrdersCount()>=0) 
    { 
    int result=0; 
    if((iRSI(NULL,PERIOD_M1,5,PRICE_CLOSE,1)<21)) // Here is your open buy rule 
    { 
     result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Blue); 
     if(result>0) 
     { 
     TheStopLoss=0; 
     TheTakeProfit=0; 
     if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint; 
     if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint; 
     OrderSelect(result,SELECT_BY_TICKET); 
     OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green); 
     } 
     return(0); 
    } 
    if((iRSI(NULL,PERIOD_M1,5,PRICE_CLOSE,1)>79)) // Here is your open Sell rule 
    { 
     result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Red); 
     if(result>0) 
     { 
     TheStopLoss=0; 
     TheTakeProfit=0; 
     if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint; 
     if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint; 
     OrderSelect(result,SELECT_BY_TICKET); 
     OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green); 
     } 
     return(0); 
    } 
    } 

    for(int cnt=0;cnt<OrdersTotal();cnt++) 
    { 
     OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); 
     if(OrderType()<=OP_SELL && 
     OrderSymbol()==Symbol() && 
     OrderMagicNumber()==MagicNumber 
     ) 
     { 
     if(OrderType()==OP_BUY) 
      { 
       if((iRSI(NULL,PERIOD_M1,5,PRICE_CLOSE,1)>70)) //here is your close buy rule 
       { 
        OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red); 
       } 
      if(TrailingStop>0) 
       {     
       if(Bid-OrderOpenPrice()>MyPoint*TrailingStop) 
       { 
        if(OrderStopLoss()<Bid-MyPoint*TrailingStop) 
        { 
        OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green); 
        return(0); 
        } 
       } 
       } 
      } 
     else 
      { 
       if((iRSI(NULL,PERIOD_M1,5,PRICE_CLOSE,1)<30)) // here is your close sell rule 
       { 
        OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red); 
       } 
      if(TrailingStop>0) 
       {     
       if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop)) 
       { 
        if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0)) 
        { 
        OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red); 
        return(0); 
        } 
       } 
       } 
      } 
     } 
    } 
    return(0); 
} 

int TotalOrdersCount() 
{ 
    int result=0; 
    for(int i=0;i<OrdersTotal();i++) 
    { 
    OrderSelect(i,SELECT_BY_POS ,MODE_TRADES); 
    if (OrderMagicNumber()==MagicNumber) result++; 

    } 
    return (result); 
} 
+0

であなたの関数を置くことができます。 x回チェックした後、次の反復で順序を入れ直すには、それを再びtrueに設定します。 – Jules

+0

こんにちは、私はこれをどうやって行うことができますか?申し訳ありませんが、私は実際にコーディングに新しいです。 – DouglasQ

+0

次のようなSystem.Threading.Timerを使用できますtr = new Timer(val => { // 5秒ごとに実行するコード }、0,0、 5000)。 –

答えて

0

static void Main(string[] args) 
{ 
    int num = 0; 
    TimerCallback tm = new TimerCallback(Count); 
    Timer timer = new Timer(tm, num, 0, 2000);//where the 4-th number is interval in milliseconds 

    Console.ReadLine(); 
} 
public static void Count(object obj) 
{ 
    int x = (int)obj; 
    for (int i = 1; i < 9; i++, x++) 
    { 
     Console.WriteLine("{0}", x*i);  
    } 
} 
0

あなたがイベントをチェックすべての5 mintuesはそう発火する後を意味する、あなたの間隔は5つのミントであることで、タイマーを追加することができますあなたはそれがfalseに設定順序が置かれた場合、trueにフラグの初期化を追加し、そのイベント

Timer objtimer; 
static void Main() 
{ 
    objtimer = new Timer(); 
    objtimer.Interval =50000; 
    objtimer.Tick += objtimer_Tick; 
} 
void objtimer_Tick(object sender, EventArgs e) 
{ 
     // your function 
} 
0
... 
System.Windows.Forms.Timer t=new System.Windows.Forms.Timer(); 
t.Interval=300000; 
t.Enabled=true; 
t.Tick+= new EventHandler(t_Tick); 
... 
void t_Tick(object sender, EventArgs e) 
{ 
Console.WriteLine("5 MIN"); 
} 
... 
関連する問題