Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
592 views
in Technique[技术] by (71.8m points)

mql4 - How do I call the most recent arrow on the chart?

I need some help in calling the most recent up or down arrow on a trading chart. I know 0 means current candle, 1 means previous candle and so on. Trading on different time frames would alert me that the current or previous candle has a value to it as the indicator points out, but on a different timeframe there wouldn't be an arrow on the current bar or the previous one. so in mql, how do I find out what arrow was placed on the chart from that different timeframe when it is quite a few candles away. I know that I could go the long way around using EMPTY_VALUE and if statements, but I would guess there's a better way of doing it. In advance, Thank you very much for your time.

double GetOpenTradesThisPair(string CurrencyPair)
 {
  int counter=0;
  for(int i=OrdersTotal()-1; i>=0; i--)
   {
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    if(OrderSymbol()==CurrencyPair)counter++;
   }
  return (counter);
 }
double closeAllTradesThisPair()
 {
  for (int i=OrdersTotal();i>=0;i--)
   {
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    if (OrderSymbol()==Symbol())
     {
      OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),3,Red);
     }
   }
 }

void OnTick()
 {
  string lots = AccountBalance()/3500;
  string saisignal = "";

  double up = iCustom(Symbol(),PERIOD_M1,"super-arrow-indicator",0,1);
  double dn = iCustom(Symbol(),PERIOD_M1,"super-arrow-indicator",1,1);

  if(up < 1000)
   {
    saisignal = "buy";
   }
  if(dn < 1000)
   {
    saisignal = "sell";
   }

  if(GetOpenTradesThisPair(Symbol())==0)
   {
    if(saisignal == "buy")
     {
      double buyticket = OrderSend(Symbol(),OP_BUY,lots,Ask,3,Bid-100*_Point,0,NULL,0,0,Blue);
     }
    if(saisignal == "sell")
     {
      double sellticket = OrderSend(Symbol(),OP_SELL,lots,Bid,3,Ask+100*_Point,0,NULL,0,0,Orange);
     }  
   }

  if(GetOpenTradesThisPair(Symbol())>0)
   {
    for(int b=OrdersTotal()-1;b>=0;b--)
     {
      if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
       {
        if(OrderSymbol()==Symbol())
         {
          if(OrderType()==OP_BUY)
           {
            if(saisignal == "sell")
             {
              closeAllTradesThisPair();
             } 
           }
          if(OrderType()==OP_SELL)
           {
            if(saisignal == "buy")
             {
              closeAllTradesThisPair();
             } 
           }
         }
       }
     }
   } 
  Comment("
","
","      sai:  ",saisignal);
 }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...