[存档!]任何菜鸟问题,为了不使论坛变得混乱。专业人士,不要路过。没有你,哪里都不能去 - 4. - 页 121

 
mahla:

在哪里添加跟踪止损和平衡输出?当你增加存款时,它不会增加手数

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

在顾问中

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

函数lot increase......,可能更好的是改变

例子。

extern double Lots               = 0.1;
extern double MaximumRisk        = 0.02;
extern double DecreaseFactor     = 3;
//////
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double LotsOptimized()
  {
   double lot=Lots;
   int    orders=HistoryTotal();     // history orders total
   int    losses=0;                  // number of losses orders without a break
//---- select lot size
   lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,1);
//---- calcuulate number of losses orders without a break
   if(DecreaseFactor>0)
     {
      for(int i=orders-1;i>=0;i--)
        {
         if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error in history!"); break; }
         if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL) continue;
         //----
         if(OrderProfit()>0) break;
         if(OrderProfit()<0) losses++;
        }
      if(losses>1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);
     }
//---- return lot size
   if(lot<0.1) lot=0.1;
   return(lot);
  }

查看移动平均线.mq4

 

你能告诉我如何将布林带 用于动量,而不是用于价格吗? 我是这样尝试的。

BandOPeriodT - 外部变量,布林带的周期。

MomentumPeriodT - 动量的周期,分别为

BandOBottom=iBands(NULL,0,BandOPeriodT,1,0,iMomentum(NULL,0,MomentumPeriodT,PRICE_OPEN,0),MODE_LOWER,0) 。

也像这样。

MomO=iMomentum(NULL,0,MomentumPeriodT,PRICE_OPEN,0); - 内部变量,返回数值。

BandOBottom=iBands(NULL,0,BandOPeriodT,1,0,MomO,MODE_LOWER,0); - 该变量应返回前一个变量值的布林线下限值。

另外,我认为MODE_LOWER意味着我在一个变量中获得BOLLINGER BOLLINGER的值,这样的假设是否正确?如果没有,我到底该如何得到它?

 
Ovari:

你能告诉我如何将布林带用于动量,而不是用于价格吗? 我是这样尝试的。

BandOPeriodT - 外部变量,布林带的周期。

MomentumPeriodT - 动量的周期,分别为

BandOBottom=iBands(NULL,0,BandOPeriodT,1,0,iMomentum(NULL,0,MomentumPeriodT,PRICE_OPEN,0),MODE_LOWER,0) 。

也像这样。

MomO=iMomentum(NULL,0,MomentumPeriodT,PRICE_OPEN,0); - 内部变量,返回数值。

BandOBottom=iBands(NULL,0,BandOPeriodT,1,0,MomO,MODE_LOWER,0); - 该变量应返回前一变量值的布林线下限值。

另外,我认为MODE_LOWER意味着我在一个变量中获得BOLLINGER BOLLINGER的值,这样的假设是否正确?如果没有,我到底该如何得到它?


请看拖车--RSI的Bands--对Momentum 做同样的处理。

描述 - 在日志中 - 见开头的代码。

附加的文件:
 
谢谢你,因为我是非常新的,也不是什么程序员:)
 

你好!请帮助我我想试试PVT指标。

double PVT = iCustom(NULL,240,"PVT",PRICE_CLOSE,1,1)

你能告诉我缺少什么吗?

它说:2012.05.14 19:34:46 无法打开 EURUSD,H4的'C:\Program Files\Alpari NZ MT4\expertsindicators\PVT.ex4'文件

谢谢你!

 
mahla:

在哪里添加跟踪止损和平衡输出? 当你增加存款时,它不会增加手数

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int Buy (int StopLoss = 0, int TakeProfit = 0, double Lot = 0)

{

int Ticket = 0;

双倍SL=0。

双重TP=0。

double VolumeLot = 0;

RefreshRates()。

如果(StopLoss != 0)

SL = NormalizeDouble(Bid-StopLoss*Point, Digits)。

如果(TakeProfit != 0)

TP = NormalizeDouble(Ask+TakeProfit*Point, Digits);

如果(Lot == 0)

VolumeLot = GetLot()。

否则

VolumeLot = Lot;

Ticket = OrderSend(Symbol(), OP_BUY, VolumeLot, NormalizeDouble(Ask, Digits), 20, SL, TP, NULL, AccountNumber(), 0, Green);

如果(Ticket == -1)

{

返回(GetLastError()。

}

否则

{

返回(票)。

}

}

int Sell (int StopLoss = 0, int TakeProfit = 0, double Lot = 0)

{

int Ticket = 0;

双倍SL=0。

双重TP=0。

double VolumeLot = 0;

RefreshRates()。

如果(StopLoss != 0)

SL = NormalizeDouble(Ask+StopLoss*Point, Digits);

如果(TakeProfit != 0)

TP = NormalizeDouble(Bid-TakeProfit*Point, Digits)。

如果(Lot == 0)

VolumeLot = GetLot()。

否则

VolumeLot = Lot;

Ticket = OrderSend(Symbol(), OP_SELL, VolumeLot, NormalizeDouble(Bid, Digits), 20, SL, TP, NULL, AccountNumber(), 0, Red) 。

如果(Ticket == -1)

返回(GetLastError()。

否则

返回(票)。

}

双倍的GetLot()。

{

场地。

如果(AccountBalance()>=300)lot=0.01。

如果(AccountBalance()>=500)lot=0.02。

如果(AccountBalance()>=800)lot=0.03。

返回(地段)。

}

让我们假设已经选择了开仓,并且我们肯定知道这个仓位是为专家顾问所连接的符号开的
。还假设追踪止损的值
,单位是点,包含在追踪止损变量中。

   int err;
   if (OrderType() == OP_BUY)
     {
       // позиция на покупку
       if ((Bid-OrderOpenPrice())>=(TrailingStop*Point))
         {
           // выставляем Stop Loss
           if (OrderModify(OrderTicket(), OrderOpenPrice(), Bid-TrailingStop*Point,
                                    OrderTakeProfit(), 0))
             Print("#", OrderTicket(),": trailing stop ", Bid-TrailingStop*Point);
           else
             {
              err = GetLastError();
              Print("#", OrderTicket(),": trailing stop error ", err);
             }
         }
     }
   else
     {
       // позиция на продажу
       if ((OrderOpenPrice()-Ask)>=(TrailingStop*Point))
         {
           // выставляем Stop Loss
           if (OrderModify(OrderTicket(), OrderOpenPrice(), Ask+TrailingStop*Point,
                                    OrderTakeProfit(), 0))
             Print("#", OrderTicket(),": trailing stop ", Ask+TrailingStop*Point);
           else
             {
              err = GetLastError();
              Print("#", OrderTicket(),": trailing stop error ", err);
             }
         }
     }
OrderProfit()函数返回使用OrderSelect()函数选择 的订单的利润。

假设我们想计算我们从平仓中获得的利润。

   int profit = 0;
   int pos;
   for ( pos = 0; pos<HistoryTotal(); pos++ )
     {
       // выделим позицию
       if (OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY) == true)
         {
           // это не отложенный ордер?
           if ( OrderType() <= OP_SELL) profit += OrderProfit();            
         }
       else
           Print("Ошибка ", GetLastError(), " при выделении ордера ", OrderTicket());
     }
   Print("Суммарный профит по закрытым позициям = ", profit);
而计算所有平仓的利润的完整代码,
,今天开仓的,将是:

   //---- вычислим начало дня - переменная day_start
   int c_time = CurTime();  
   datetime day_start;
   day_start=c_time-TimeHour(c_time)*60*60-TimeMinute(c_time)*60-TimeSeconds(c_time);
   //---- подсчитаем прибыль
   int profit = 0;
   int pos;
   for ( pos = 0; pos<HistoryTotal(); pos++ )
     {
       // выделим позицию
       if (OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY) == true)
         {
           // это не отложенный ордер?
           if ( OrderType() <= OP_SELL)
             {
               // ордер был открыт сегодня?
               if (OrderOpenTime()>=day_start) profit += OrderProfit();
             }
         }
       else
           Print("Ошибка ", GetLastError(), " при выделении ордера ", OrderTicket());
     }
   Print("Суммарный профит по закрытым позициям = ", profit);
 
mahla:

当你增加押金时,它不会增加地段大小。

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


也许代码中还缺少一些东西。

doubleOrderLots( )
返回所选订单的手数。
该订单必须使用OrderSelect() 进行预选。
例子。
 如果(OrderSelect(10,SELECT_BY_POS)==true) Print("lot for the order 10",OrderLots()); else Print("OrderSelect() has returned an error - " GetLastError())。
 
borilunad:

你好!请帮助我我想试试PVT指标。

你能告诉我缺少什么吗?

它说:2012.05.14 19:34:46 无法打开EURUSD,H4的'C:\Program Files\Alpari NZ MT4\expertsindicators\PVT.ex4'文件。

谢谢你!

PVT指标本身缺失(你确定你有吗?)
 
alsu:
PVT指标本身缺失(你确定你有吗?)

当然,我有,而且已经编译好了,还有eh4。并把它也放在图表上。也许我写错了什么?谢谢你!
 

borilunad

当然,既有编译的,也有eh4的。并把它放在图表上。也许我写错了什么?谢谢!


它只有一个缓冲区,EA调用一个不存在的第二个缓冲区有什么意义?