Auto Trading function used by one chart/symbol use even other symbols of other charts

 

I programmed just a function for trailing stop, I attached my Expert Advisor to a Chart/Symbol an I activated auto trading.

The problem ist that the my Expert Advisor modifie even the other symbols from other open charts in the order list which one runs with other expert advisors.

I tried to add a string with I've to add with the symbolname, but if i've other charts open with the same symbol the same problem

What have I to add, that my expert Advisor performs only the order(s) attached to the chart/symbol ?

Thanks for Feedbacks

Marcel

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

extern string sHelp1 = "------- Symbols";
extern string sOrderType="Ger30Sep15";
extern string sHelp2 = "------- Parameters";
extern double dStop=40;
extern double dTP=200;
// Help
extern string sHelp3 = "------- Help";
extern string sHelp4 = "";

double dBuyTP;
double dBuySL;

double dSellTP;
double dSellSL;

double dBid;   // sell
double iAsk;   // buy
//double dStop=dSellStop/* *10 */;
//double dTP=dTakeProfit/* *10 */;
int    iTicket;
int    iPos;
int    iLastTicket=0;
int    iLastOrdersTotal;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

void OnTick()
  {

  iPos = 0;

  while (iPos < OrdersTotal())
    {
    if(OrderSelect(iPos,SELECT_BY_POS)==true) // Select Order for ask Order Lots
      {
      // Print info
      iTicket = OrderTicket();
      if (iLastOrdersTotal != OrdersTotal())
        {

        //
        Print("### -----------------------------");
        Print("### Orders in List: ",OrdersTotal());
        Print("### Orderspos in List: ",iPos+1);
        Print("### Recognized new ticket: ",iTicket);
        Print("### Ordertype: ",OrderType());
        Print("### Symbol: ",OrderSymbol());
        Print("### PointSize: ",Point());
        Print("### -----------------------------");
        //

        }
      //

      if(OrderCloseTime()==0) // Select Order open
        {
 
        //+------------------------------------------------------------------+
        //| open ticket -> check buy                                         |
        //+------------------------------------------------------------------+
        if (OrderType()==OP_BUY && OrderSymbol()==sOrderType)
          {
          dBid = MarketInfo(OrderSymbol(),MODE_BID);  // Get actual BID
          Print("### Orderspos in List: ",iPos+1);
          Print("### Symbol: ",OrderSymbol());
          Print("### dBid: ",dBid);
          dBuySL = OrderStopLoss();
          if(dBid > (dBuySL + dStop) || dBuySL == 0)
            {
            dBuyTP = OrderTakeProfit();
            dBuySL = dBid-(dStop/* *Point()*/ );
            if (OrderModify(iTicket,0,dBuySL,dBuyTP,0,Green)==true)
              Print("### Buy: Set new trailing stop: ",OrderStopLoss()," ticket: ",iTicket);
            }
          }
        //+------------------------------------------------------------------+

        //+------------------------------------------------------------------+
        //| open ticket -> check sell                                         |
        //+------------------------------------------------------------------+
        if ( OrderType()==OP_SELL && OrderSymbol()==sOrderType)
          {
          iAsk = MarketInfo(OrderSymbol(),MODE_ASK);  // Get actual BID
          Print("### Orderspos in List: ",iPos+1);
          Print("### Symbol: ",OrderSymbol());
          Print("### iAsk: ",iAsk);
          dSellSL = OrderStopLoss();
          if(iAsk < ( dSellSL - dStop ) || dSellSL == 0)
            {
            dSellTP = OrderTakeProfit();
            dSellSL = iAsk+(dStop/* *Point() */);
            if (OrderModify(iTicket,0,dSellSL,dSellTP,0,Green)==true)
              Print("### Sell: Set new trailing stop: ",OrderStopLoss()," ticket: ",iTicket);
            }
          }
        //+------------------------------------------------------------------+

        }
      }
    iPos++;
    }
    iLastOrdersTotal = OrdersTotal();
  // Exit
  //return(0);
  }
//+------------------------------------------------------------------+
 

Forum on trading, automated trading systems and testing trading strategies


Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.


 
if( OrderMagicNumber() == magic ) //Magic number of the specific EA
   {
    // Trailingcode for orders with this magic number only.
   }
 
Alain Verleyen:

Thank you, I'm new here. Ok for the next time
 
Marco vd Heijden:

Ok I understand, I found the article for explains:

MagicNumber: "Magic" Identifier of the Order


if the magicnumber is 0 -> Traded manualy