Usually people who can't code don't receive free help on this forum.
If you show your attempts and describe your problem clearly, you will most probably receive an answer from the community. Use the CODE button (Alt-S) when inserting code.
To learn MQL programming, you can research the many available Articles on the subject, or examples in the Codebase, as well as reference the online Book and Documentation. Remember also, that you can debug your code with MetaEditor's own debugging functionality.
If you do not want to learn to code, that is not a problem. You can either look at the Codebase if something free already exists, or in the Market for paid products (also sometimes free). However, recommendations or suggestions for Market products are not allowed on the forum, so you will have to do your own research.
Finally, you also have the option to hire a programmer in the Freelance section.
Usually people who can't code don't receive free help on this forum.
If you show your attempts and describe your problem clearly, you will most probably receive an answer from the community. Use the CODE button (Alt-S) when inserting code.
To learn MQL programming, you can research the many available Articles on the subject, or examples in the Codebase, as well as reference the online Book and Documentation. Remember also, that you can debug your code with MetaEditor's own debugging functionality.
If you do not want to learn to code, that is not a problem. You can either look at the Codebase if something free already exists, or in the Market for paid products (also sometimes free). However, recommendations or suggestions for Market products are not allowed on the forum, so you will have to do your own research.
Finally, you also have the option to hire a programmer in the Freelance section.
Thanks for that!
So my Source Code looks like this.
I dont really know how to handle the closed positions.
I would like to search for the previous closed position. Currently i am using the comment property which is has a unique ID.
But i read that the broker can change the comment property.
void OnTradeTransaction(const MqlTradeTransaction& trans, const MqlTradeRequest& request, const MqlTradeResult& result) { CDealInfo m_deal; // object of CDealInfo class //--- get transaction type as enumeration value ENUM_TRADE_TRANSACTION_TYPE type=trans.type; //--- if transaction is result of addition of the transaction in history if(type==TRADE_TRANSACTION_DEAL_ADD) { if(HistoryDealSelect(trans.deal)) m_deal.Ticket(trans.deal); else { Print(__FILE__," ",__FUNCTION__,", ERROR: HistoryDealSelect(",trans.deal,")"); return; } //--- long reason=-1; if(!m_deal.InfoInteger(DEAL_REASON,reason)) { Print(__FILE__," ",__FUNCTION__,", ERROR: InfoInteger(DEAL_REASON,reason)"); return; } if((ENUM_DEAL_REASON)reason==DEAL_REASON_TP) ManageTrailingStopLoss(m_deal.PositionId(), m_deal, trans); //OnTpHit(m_deal.PositionId(), trans); } } void ManageTrailingStopLoss(ulong closed_ticket, const CDealInfo& m_deal, const MqlTradeTransaction& trans) { CTrade trade; double closed_tp = 0; double entryPrice = 0; string closed_comment = ""; // Get the closed position's TP, entry price, and comment //if (HistorySelectByPosition(closed_ticket)) //if(PositionSelectByTicket(closed_ticket)) //if(HistoryDealSelect(closed_ticket)) if(OrderSelect(closed_ticket)) { //closed_tp = HistoryDealGetDouble(closed_ticket, DEAL_TP); //entryPrice = HistoryDealGetDouble(closed_ticket, DEAL_PRICE); //closed_comment = HistoryDealGetString(closed_ticket, DEAL_COMMENT); closed_tp = OrderGetDouble(ORDER_TP); entryPrice = OrderGetDouble(ORDER_PRICE_OPEN); closed_comment = OrderGetString(ORDER_COMMENT); //closed_tp = trans.price_tp; //entryPrice = trans.price; for (int i = 0; i < PositionsTotal(); i++) { if (PositionSelectByTicket(PositionGetTicket(i))) { string comment = PositionGetString(POSITION_COMMENT); double tp = PositionGetDouble(POSITION_TP); double sl = PositionGetDouble(POSITION_SL); // Check if the comment matches the closed position's comment if (StringFind(comment, closed_comment) != -1) { if (closed_tp > 0 && sl < closed_tp) { trade.PositionModify(PositionGetTicket(i), closed_tp, tp); } else if (closed_tp == 0 && sl < entryPrice) { trade.PositionModify(PositionGetTicket(i), entryPrice, tp); } } } } } }
Any help guys?
I just need a push in the right direction :)
I could code it myself then
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
i am really new to MQL coding.
Can anyone help me on my problem?
Just an example:
I open multiple positions on the same entryprice. Lets say 5 positions.
Every position has its own TP.
All the positions have the same SL.
When the first TP hits the SL of all the positions should change to BE.
When the second TP hits the SL of all the positions should change to the first TP.
My 5 BUY positions:
When first TP Hits:
I am already using the event "OnTradeTransaction".
Can someone help me how to solve it?