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)?
- What is and how to set the magic number at EA's ?
- MQL5: Run Multiple Expert (with different MAGIC NUMBER) on same Symbol
- How to check magic numbers of open positions
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
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
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register