1. Please insert the code correctly: when editing a message, press the button and paste your code into the pop-up window. (The first time I corrected your message)
2. To access the properties of a position, this position must first be selected (for example, using PositionGetTicket )
Documentation on MQL5: Trade Functions / PositionGetTicket
- www.mql5.com
PositionGetTicket - Trade Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
i added an input for the index of the position you want to modify
void ModifyPorfit(int index) { if(!PositionSelectByTicket(PositionGetTicket(index))) return; double p = PositionGetDouble(POSITION_PROFIT); if(p < 0) return; double volume = PositionGetDouble(POSITION_VOLUME); double points = p / volume ; if(points > 100) { double sl = PositionGetDouble(POSITION_PRICE_OPEN); double tp = PositionGetDouble(POSITION_TP); if(!ExtTrade.PositionModify(PositionGetTicket(0), sl, tp)) { int code = ExtTrade.ResultRetcode(); printf("Modify failed:" + code); } } }
Hi brianinchrist
Example code
#include <Trade\PositionInfo.mqh>
CPositionInfo eaposition;
if(eaposition.SelectByIndex(i))
{
// Get Value here
}
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
I tried to modify the loss. But I got error code 10016.
How to call PositionModify correctly?
Thanks.