MT4 often-used function

ok,

void enterAskPosition(double lots)
{
   if(0 > OrderSend(Symbol(),OP_SELL,lots,Bid,slippoint,stoploss,takeprofit,"My Order #kay",13603,0,Red))
   {
      writeLog("sell open failure");
   }
}

//---write log to another file for convienience to debug
void writeLog(string s)
{ 
    int handle = FileOpen("log.txt",FILE_READ | FILE_WRITE,';'); 
    if( handle == -1) 
    { 
        Print("------------ XXXXXXXXXXXXXXXXX ----------------");
    } 
    else 
    { 
        FileSeek(handle, 0, SEEK_END); 
        FileWrite(handle,s); 
        FileClose(handle); 
    }
}
//---close all the bid position include limit or stop order
void closeAllBidPosition()
{
   writeLog("---- enter function close all bid position");
   for(int i = OrdersTotal()-1;i >= 0;i--)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
         if(OrderType() == OP_BUY)
         {
            OrderClose(OrderTicket(),OrderLots(),Bid,0,White);
         }
         else if(OrderType() == OP_BUYLIMIT || OrderType() == OP_BUYSTOP)
         {
            OrderDelete(OrderTicket());
         }
      }
   }
}

//---close all the ask position include limit or stop order
void closeAllAskPosition()
{
   writeLog("---- enter function close all ask position");
   for(int i = OrdersTotal()-1;i >= 0;i--)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
         if(OrderType() == OP_SELL)
         {
            OrderClose(OrderTicket(),OrderLots(),Ask,0,White);
         }
         else if(OrderType() == OP_SELLLIMIT || OrderType() == OP_SELLSTOP)
         {
            OrderDelete(OrderTicket());
         }
      }
   }
}


void enterBidPosition(double lots)
{
   if(0 > OrderSend(Symbol(),OP_BUY,lots,Ask,slippoint,stoploss,takeprofit,"My Order #kay",13602,0,Blue))
   {
      writeLog("buy open failure");
   }
}


//---calculate the number of all the bid ticket
double calculate_totalCount_bid()
{
   double tb = 0;
   for(int i = OrdersTotal() - 1;i >= 0;i--)
   {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
         if(OrderSymbol() == Symbol())
         {
            if(OrderType() == OP_BUY)
            {
               tb++;
            }
         }
      }
   }
   totalCount_bid = tb;
   return (tb); 
}

//---calculate the number of all the ask ticket
double calculate_totalCount_ask()
{
   double ta = 0;
   for(int i = OrdersTotal() - 1;i >= 0;i--)
   {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
         if(OrderSymbol() == Symbol())
         {
            if(OrderType() == OP_SELL)
            {
               ta++;
            }
         }
      }
   }
   totalCount_ask = ta;
   return (ta); 
}

//---calculate the number of all position
double calculate_totalCount_pos()
{
   double tp = 0;
   for(int i = OrdersTotal() - 1;i >= 0;i--)
   {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
         if(OrderSymbol() == Symbol())
         {
            if(OrderType() == OP_SELL || OrderType() == OP_BUY)
            {
               tp++;
            }
         }
      }
   }
   totalCount_pos = tp;
   return (tp); 
}

//---calculate all the cost price besides bid and ask
void calculate_cost_price()
{
   if(!ifChangedOfTotalCount_pos())
   {
      return;
   }
   for(int i = OrdersTotal() - 1;i >= 0;i--)
   {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
         if(OrderSymbol() == Symbol())
         {
            if(OrderType() == OP_BUY)
            {
               Print("-------- hi hi");
               totalLots_bid += OrderLots();
               totalValue_bid += OrderLots() * OrderOpenPrice();
               Print("-----------totalValue_bid = ",totalValue_bid);
            }
            else if(OrderType() == OP_SELL)
            {
               totalLots_ask += OrderLots();
               totalValue_ask += OrderLots() * OrderOpenPrice();
               Print("----------totalValue_ask = ",totalValue_ask);
            }
         }
      }
   } 
   if(totalLots_bid > 0)
   {
      costPrice_bid = totalValue_bid / totalLots_bid;
   }
   if(totalLots_ask > 0)
   {
      costPrice_ask = totalValue_ask / totalLots_ask;
   } 
   if(costPrice_bid > 0 && costPrice_ask > 0)
   {
      Print("------------ costPrice_bid = ",costPrice_bid);
      Print("------------ costPrice_ask = ",costPrice_ask);
   }
}

//---check for whether there is a ask position
bool ifExistAskPosition()
{
   bool flag = false;
   for(int i = OrdersTotal();i > 0;i--)
   {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
         if(OrderSymbol() == Symbol())
         {
            if(OrderType() == OP_SELL)
            {
               flag = true;
            }
         }
      }
   }
   return (flag);
}

//---check for whether there is a bid position
bool ifExistBidPosition()
{
   bool flag = false;
   for(int i = OrdersTotal();i > 0;i--)
   {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
         if(OrderSymbol() == Symbol())
         {
            if(OrderType() == OP_BUY)
            {
               flag = true;
            }
         }
      }
   }
   return (flag);
}

//---calculate all the profit in the current symbol
double totalProfit()
{
   double totalProfit = 0;
   for(int i = OrdersTotal();i > 0;i--)
   {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
         if(OrderSymbol() == Symbol())
         {
            if(OrderType() == OP_BUY || OrderType() == OP_SELL)
            {
               totalProfit += OrderProfit();
            }
         }
      }
   }
   return (totalProfit);
}

//---calculate all the bid position profit in the current Symbol
double totalBidProfit()
{
   double totalBidProfit = 0;
   for(int i = OrdersTotal();i > 0;i--)
   {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
         if(OrderSymbol() == Symbol())
         {
            if(OrderType() == OP_BUY)
            {
               totalBidProfit += OrderProfit();
            }
         }
      }
   }
   return (totalBidProfit);
}

//---calculate all the ask position profit in the current symbol
double totalAskProfit()
{
   double totalAskProfit = 0;
   for(int i = OrdersTotal();i > 0;i--)
   {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
         if(OrderSymbol() == Symbol())
         {
            if(OrderType() == OP_SELL)
            {
               totalAskProfit += OrderProfit();
            }
         }
      }
   }
   return (totalAskProfit);
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: MT4-DKX多空分水线是一款专为MetaTrader 4平台设计的技术指标扩展文件(.ex4)。该指标的主要作用是帮助交易者判断市场的多空力量变化和趋势反转的时机。 该指标的计算基于市场价格和成交量的综合分析。它通过分析市场的多空力量平衡来判断市场趋势的转折点。在图表上,MT4-DKX多空分水线以分水线的形式呈现,当多头力量高于空头力量时,分水线上升,表示多头趋势;当空头力量高于多头力量时,分水线下降,表示空头趋势。交叉分水线的位置则表示市场趋势发生了反转的可能,提示交易者注意趋势变化。 该指标的应用可以帮助交易者更好地理解市场趋势,并作出相应的交易决策。当分水线上升或下降时,交易者可以借此确认市场的多空力量强弱,并考虑进一步的买入或卖出机会。当分水线交叉时,交易者可以借此判断趋势反转的可能性,以避免错过逆势交易机会。 总结而言,MT4-DKX多空分水线是一款可在MetaTrader 4平台上使用的技术指标,通过对市场多空力量的综合分析来判断市场趋势的转折点。它的应用能够帮助交易者更好地把握市场行情,作出更明智的交易决策。 ### 回答2: MT4-DKX多空分水线是一种基于MetaTrader 4(MT4)平台的技术指标,它的全称是MT4-DKX Bull Bear Separation Line。这个指标旨在帮助交易者观察市场趋势的转变。它通过计算一段时间内的股价波动平均值,并将其以曲线图的形式呈现,以便交易者更加直观地观察市场的多空力量。 在MT4-DKX多空分水线指标中,分水线的主要含义是表示市场空多力量的分割线。当股价在分水线上方运动时,意味着市场处于多头(上涨)状态;而当股价低于分水线时,意味着市场处于空头(下跌)状态。交易者可以根据这个指标的图表变动来判断市场当前的多空态势,从而制定相应的交易策略。 此外,MT4-DKX多空分水线指标还可以配合其他技术指标一起使用,以增强分析和决策的准确性。比如,交易者可以将其与其他趋势指标如移动平均线等进行比较,来进一步确认市场的多空趋势,并推测未来价格的走势。 总之,MT4-DKX多空分水线是一种用于辅助交易决策的技术指标,通过分析股价的均值波动情况,帮助交易者判断市场的多空力量和趋势变化。使用此指标可以更好地把握市场的行情,从而更加科学和有依据地进行交易操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值