Do I need to write magic number?

 
if I want to run different ea on different chart,
so lets say I create "EURUSD" and "USDJPY" this two ea,
I open two positions from this two ea,
one from "EURUSD" and one from "USDJPY"
if I want to change the position SL from "EURUSD",
do I need to write magic number to let ea identify it,
or I just use positionselect(_symbol)?
 
Hello friend... Just try make an attempt on the code, display it here and we'll correct it for you
 
Osazee Asikhemhen #:
Hello friend... Just try make an attempt on the code, display it here and we'll correct it for you
void ProcessPos()
  {
      if(PositionSelect(_Symbol))
        {
         if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
           {
            double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
            if(bid > PositionGetDouble(POSITION_PRICE_OPEN) + TslTriggerPoint* _Point)
               SLPrice = NormalizeDouble((bid - TslPoint * _Point),_Digits);

            if(SLPrice > PositionGetDouble(POSITION_SL))
               PosModify(SLPrice,PositionGetInteger(POSITION_TICKET));
           }

         if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
           {
            double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
            if(ask < PositionGetDouble(POSITION_PRICE_OPEN) - TslTriggerPoint* _Point)
               SLPrice = NormalizeDouble((ask + TslPoint * _Point),_Digits);

            if(SLPrice < PositionGetDouble(POSITION_SL))
               PosModify(SLPrice,PositionGetInteger(POSITION_TICKET));
           }
        }
  }
void PosModify(double sl,ulong Position)
  {
   MqlTradeRequest Request;
   MqlTradeResult Result;
   ZeroMemory(Request);
   ZeroMemory(Result);
   Request.action = TRADE_ACTION_SLTP;
   Request.position = Position;
   Request.symbol = _Symbol;
   Request.sl = sl;
   OrderSend(Request,Result);
  }
 
void ProcessPos()
  {
      if(PositionSelect(_Symbol) && PositionGetInteger(POSITION_MAGIC) == magic && PositionGetInteger(POSITION_SYMBOL) == Symbol())
        {
         if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
           {
            double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
            if(bid > PositionGetDouble(POSITION_PRICE_OPEN) + TslTriggerPoint* _Point)
               SLPrice = NormalizeDouble((bid - TslPoint * _Point),_Digits);

            if(SLPrice > PositionGetDouble(POSITION_SL))
               PosModify(SLPrice,PositionGetInteger(POSITION_TICKET));
           }

         if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
           {
            double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
            if(ask < PositionGetDouble(POSITION_PRICE_OPEN) - TslTriggerPoint* _Point)
               SLPrice = NormalizeDouble((ask + TslPoint * _Point),_Digits);

            if(SLPrice < PositionGetDouble(POSITION_SL))
               PosModify(SLPrice,PositionGetInteger(POSITION_TICKET));
           }
        }
  }
void PosModify(double sl,ulong Position)
  {
   MqlTradeRequest Request;
   MqlTradeResult Result;
   ZeroMemory(Request);
   ZeroMemory(Result);
   Request.action = TRADE_ACTION_SLTP;
   Request.position = Position;
   Request.symbol = _Symbol;
   Request.sl = sl;
   OrderSend(Request,Result);
  }

 
Define "magic" as a global variable and use it for your "ordersend" functions
 
Osazee Asikhemhen #:
Define "magic" as a global variable and use it for your "ordersend" functions

thanks man.

 
ziyang2048 #:

thanks man.



👍 

Reason: