Hi,
I'm looking for your help for my code mql4. Although I tried a lot of things I don't find a solution to resolve my problem.
So, according to my strategy:
1st PART: I take a Long trade 0.10lots without SL and with TP1,at the same time, I take a Buy Limit 100pis below the Openprice with 0.20lots and TP2, and an other Buy Limit 175pips below the first OpenPrice with 0.40lots and TP3.
2nd PART: _ Then, if TP1 is hit I want that the 2 Buy Limit are cancelled.
_ If the first Buy limit is opened and the TP2 is hit, I want that the first trade is closed and the last Buy Limit is cancelled.
_ If the last Buy limit is opened and the TP is hit, I want that the first trade is close and the first Buy Limit is closed too.
For the 1st PART, I succedeed to program this but I have tried a lot of method to program the 2nd PART for 2 weeks without success.
If anyone can help me please, it should be very pleasant.
Thanks a lot for all,
King regards !
Goodgame42. ;-)
Save the ticket number, check it later with OrderSelect()'s SELECT_BY_TICKET, https://docs.mql4.com/trading/OrderSelect
if (OrderSelect(ticket_number, SELECT_BY_TICKET) == false) Print ("closed");
If it return true, you may check the OrderType() https://docs.mql4.com/trading/OrderType to see if it change from pending type to open one. If it is false, that mean the position is closed and moved to historical trades
I tried to program what you tell me but I totally don't understand:
//BUY: if (Order == SIGNAL_BUY && (EachTickMode && !TickCheck)) { if(!IsTrade) { //Check free margin if (AccountFreeMargin() < (1000 * Lots)) { Print("We have no money. Free Margin = ", AccountFreeMargin()); return(0); } TakeProfitLevel = Ask + TakeProfit * Point; TakeProfitLevel1 = (Ask - Point * Perte1) + (TakeProfit1 * Point); TakeProfitLevel2 = (Ask - Point * Perte2) + (TakeProfit2 * Point); Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue); Ticket1 = OrderSend(Symbol(), OP_BUYLIMIT, LotsDouble, Ask - Point * Perte1, Slippage, 0, TakeProfitLevel1, "BuyLimit(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue); Ticket2= OrderSend(Symbol(), OP_BUYLIMIT, LotsQuadruple, Ask - Point * Perte2, Slippage, 0, TakeProfitLevel2, "BuyLimit(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue); if (EachTickMode) TickCheck = True; if (!EachTickMode) BarCount = Bars; return(0); } } if (OrderSelect(Ticket, SELECT_BY_TICKET) == false) { Print("closed"); }else{ int order_type = OrderType(); if(order_type==OP_BUY || order_type==OP_SELL){ Print("opened"); } else { Print("closed"); } }
Please edit your post . . .
Please use this to post code . . . it makes it easier to read.
Thanks, Sorry ;-)
Thanks, Sorry ;-)
If you doubling your lot size like that without any SL, you will soon have nothing.
Sorry it look like I only explain it half. Below is what I mean, I didn't check the logic, so you should check it.
//--- if TPs is hit it should be on historical trades //--- check if TP2 is hit, if (OrderSelect(Ticket2, SELECT_BY_TICKET, MODE_HISTORY) == true) { if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES) == true) OrderClose (Ticket, OrderLots(), OrderClosePrice(), Slippage, Red); if (OrderSelect(Ticket1, SELECT_BY_TICKET, MODE_TRADES) == true) OrderClose (Ticket1, OrderLots(), OrderClosePrice(), Slippage, Red); } else //--- check if TP1 is hit, { if (OrderSelect(Ticket1, SELECT_BY_TICKET, MODE_HISTORY) == true) { if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES) == true) OrderClose (Ticket, OrderLots(), OrderClosePrice(), Slippage, Red); if (OrderSelect(Ticket2, SELECT_BY_TICKET, MODE_TRADES) == true) OrderDelete (Ticket2); } else //--- check if TP is hit, { if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_HISTORY) == true) { if (OrderSelect(Ticket1, SELECT_BY_TICKET, MODE_TRADES) == true) OrderDelete (Ticket1); if (OrderSelect(Ticket2, SELECT_BY_TICKET, MODE_TRADES) == true) OrderDelete (Ticket2); } } }
- 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'm looking for your help for my code mql4. Although I tried a lot of things I don't find a solution to resolve my problem.
So, according to my strategy:
1st PART: I take a Long trade 0.10lots without SL and with TP1,at the same time, I take a Buy Limit 100pis below the Openprice with 0.20lots and TP2, and an other Buy Limit 175pips below the first OpenPrice with 0.40lots and TP3.
2nd PART: _ Then, if TP1 is hit I want that the 2 Buy Limit are cancelled.
_ If the first Buy limit is opened and the TP2 is hit, I want that the first trade is closed and the last Buy Limit is cancelled.
_ If the last Buy limit is opened and the TP is hit, I want that the first trade is close and the first Buy Limit is closed too.
For the 1st PART, I succedeed to program this but I have tried a lot of method to program the 2nd PART for 2 weeks without success.
If anyone can help me please, it should be very pleasant.
Thanks a lot for all,
King regards !
Goodgame42. ;-)