English

Function "TrailingStop" is not referenced and will be removed from exp-file

 53 phipho 2013.03.19 05:03   ```//+------------------------------------------------------------------+ //|                                               Moving Average.mq4 | //|                      Copyright © 2005, MetaQuotes Software Corp. | //|                                       http://www.metaquotes.net/ | //+------------------------------------------------------------------+ #define MAGICMA  20050610 extern double Lots               = 0.1; extern double MaximumRisk        = 0.02; extern double DecreaseFactor     = 3; extern int     iTakeProfit    = 100; extern int     iTrailingStop  = 35; extern int     iStopLoss      = 30; extern int     iMagicNumber   = 12444; //+------------------------------------------------------------------+ //| Calculate open positions                                         | //+------------------------------------------------------------------+ int CalculateCurrentOrders(string symbol)   {    int buys=0,sells=0; //----    for(int i=0;i0) return(buys);    else       return(-sells);   } //+------------------------------------------------------------------+ //| 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);   }      //---- trailin stop void TrailingStop(int iTotal){    int iCount;       if(iTrailingStop < 1)return(-1); // error       for(iCount=0;iCountPoint*iTrailingStop){                   if(OrderStopLoss()(Point*iTrailingStop)){                   if((OrderStopLoss()>(Ask+Point*iTrailingStop)) || (OrderStopLoss()==0)){                      OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*iTrailingStop,OrderTakeProfit(),0,Red);                   }                }                break;          }       }          return(0); } //+------------------------------------------------------------------+ //| Check for open order conditions                                  | //+------------------------------------------------------------------+ void CheckForOpen()   {    double ma5,ma10,v1;    int    res; //---- go trading only for first tiks of new bar    if(Volume[0]>1) return; //---- get Moving Average                      // get the current prices for each moving average    ma5= iMA(NULL,0,12,0,MODE_EMA,PRICE_CLOSE,0);    ma10=iMA(NULL,0,100,0,MODE_EMA,PRICE_CLOSE,0);    v1=iRSI (NULL, 0,14, PRICE_MEDIAN, 0); //---- sell conditions    if(ma5ma10 && v1>50)        {       res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,Bid-iStopLoss*Point,Ask+iTakeProfit*Point,"",MAGICMA,0,Blue);       return;      } //----   } //+------------------------------------------------------------------+ //| Check for close order conditions                                 | //+------------------------------------------------------------------+ void CheckForClose()   {     double ma5,ma10,v1; //---- go trading only for first tiks of new bar    if(Volume[0]>1) return; //---- get Moving Average     ma5= iMA(NULL,0,12,0,MODE_EMA,PRICE_CLOSE,0);    ma10=iMA(NULL,0,100,0,MODE_EMA,PRICE_CLOSE,0);    v1=iRSI (NULL, 0,14, PRICE_MEDIAN, 0); //----    for(int i=0;ima10) OrderClose(OrderTicket(),OrderLots(),Ask,3,White);          break;         }      } //----   } //+------------------------------------------------------------------+ //| Start function                                                   | //+------------------------------------------------------------------+ void start()   { //---- check for history and trading    if(Bars<100 || IsTradeAllowed()==false) return; //---- calculate open orders by current symbol    if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();    else                                    CheckForClose(); //----   } //+------------------------------------------------------------------+``` similar
 2408 deVries 2013.03.19 12:08 #   phipho: so i must do what?  ```void start()   { //---- check for history and trading    if(Bars<100 || IsTradeAllowed()==false) return; //---- calculate open orders by current symbol    if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();    else                                    CheckForClose();```.....  you can try```void start()   { //---- check for history and trading    if(Bars<100 || IsTradeAllowed()==false) return; //---- calculate open orders by current symbol    if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();    else{        CheckForClose();        TrailingStop(OrdersTotal());        }```