-
bool SendTicket = OrderModify(O
OrderModify does not return a ticket.
- This is your code, properly indented. Select and filter, then work of the if( typeA ) else (typeB), You are processing all non-symbol non-magic sell trades together. @Maskin
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==Magic && OrderType()==OP_BUY) { if(Bid-OrderOpenPrice()>= ATR) if(OrderStopLoss()<GetStopLossBuy(Symbol(),ATR_Period)) bool SendTicket = OrderModify(OrderTicket(),OrderOpenPrice(),GetStopLossBuy(Symbol(),ATR_Period),OrderTakeProfit(),0,clrGreen); } else if(OrderType()==OP_SELL)
-
OrderModify does not return a ticket.
- This is your code, properly indented. Select and filter, then work of the if( typeA ) else (typeB), You are processing all non-symbol non-magic sell trades together. @Maskin
Thank you for your speedy answer ! I directly edited my code, however result is the same..
Updated version below here;
void ATRTrailingStop() { double ATR = NormalizeDouble(iATR(Symbol(),ATRTRSPERIOD,ATR_Period,0)*Trailing_ATR_Multiplier,3); RefreshRates(); for(int i=OrdersTotal()-1; i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY) { if(Bid-OrderOpenPrice()> ATR) if(OrderStopLoss()<GetStopLossBuy(Symbol(),ATR_Period)) bool ModifyTicket = OrderModify(OrderTicket(),OrderOpenPrice(),GetStopLossBuy(Symbol(),ATR_Period),OrderTakeProfit(),0,clrGreen); } else if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL) Sleep(100); { if(OrderOpenPrice()-Ask>ATR) if(OrderStopLoss()>GetStopLossSell(Symbol(),ATR_Period)) bool ModifyTicket = OrderModify(OrderTicket(),OrderOpenPrice(),GetStopLossSell(Symbol(),ATR_Period),OrderTakeProfit(),0,clrRed); } } } double GetStopLossBuy(string Instrument,int ATRPeriod) { double SLValue=Close[1]-iATR(Instrument,ATRTRSPERIOD,ATRPeriod,Shift)*Trailing_ATR_Multiplier; return SLValue; } double GetStopLossSell(string Instrument,int ATRPeriod) { double SLValue=Close[1]+iATR(Instrument,ATRTRSPERIOD,ATRPeriod,Shift)*Trailing_ATR_Multiplier; return SLValue; }
Thank you for your speedy answer ! I directly edited my code, however result is the same..
Updated version below here;
It simply works this way. The image is attached. Since I do not know the input values, it can only be written this way.
@ Maskin
#property copyright "Copyright 2021, HaskayaFx" #property link "https://www.haskayayazilim.net" #property version "1.00" #property strict input double Lots=0.02; input int ATRTRSPERIOD,ATR_Period=14; input double Trailing_ATR_Multiplier=1; input int Shift=1; input string BuySellComment="MaskinEA"; input int Magic=99243; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } void OnTick() { int ticket; if(OrdersTotal()==0) ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,BuySellComment,Magic,0,clrBlue); // ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,2,0,0,NULL,0,0,clrRed); if(OrdersTotal()==0) ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,2,0,0,NULL,0,0,clrRed); ATRTrailingStop(); } //+------------------------------------------------------------------+ void ATRTrailingStop() { bool ModifyTicket; double ATR = NormalizeDouble(iATR(Symbol(),ATRTRSPERIOD,ATR_Period,0)*Trailing_ATR_Multiplier,3); RefreshRates(); for(int i=OrdersTotal()-1; i>=0;i--) { bool tst=OrderSelect(i,SELECT_BY_POS,MODE_TRADES); // Print("dd ",OrderSymbol()," ",Symbol()," ",OrderMagicNumber()," ",Magic," ",OrderType()," ",OP_BUY); if( OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY) { Print("Burda BUY " ,Bid-OrderOpenPrice()," ATR ",ATR); if(Bid-OrderOpenPrice()> ATR) if(OrderStopLoss()<GetStopLossBuy(Symbol(),ATR_Period)) { ModifyTicket = OrderModify(OrderTicket(),OrderOpenPrice(),GetStopLossBuy(Symbol(),ATR_Period),OrderTakeProfit(),0,clrGreen); Print("Modify BUY ",ModifyTicket); } } else if( OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL) { Sleep(100); if(OrderOpenPrice()-Ask>ATR) if(OrderStopLoss()>GetStopLossSell(Symbol(),ATR_Period)) { Print("Burda SELL " ,OrderOpenPrice()-Ask," ATR ",ATR); ModifyTicket = OrderModify(OrderTicket(),OrderOpenPrice(),GetStopLossSell(Symbol(),ATR_Period),OrderTakeProfit(),0,clrRed); Print("Modify SELL ",ModifyTicket); } } } } double GetStopLossBuy(string Instrument,int ATRPeriod) { double SLValue=Close[1]-iATR(Instrument,ATRTRSPERIOD,ATRPeriod,Shift)*Trailing_ATR_Multiplier; return SLValue; } double GetStopLossSell(string Instrument,int ATRPeriod) { double SLValue=Close[1]+iATR(Instrument,ATRTRSPERIOD,ATRPeriod,Shift)*Trailing_ATR_Multiplier; return SLValue; }
It simply works this way. The image is attached. Since I do not know the input values, it can only be written this way.
@ Maskin
Thank you Mehmet Bey,
I also tried that codes but undeclared identifier error has sent on print command of buy row. When I delete ModifyTicket to Text, code works but for only buy section. I couldn't understand why it does not work properly. I assume that first and second if statement before modify order always turn true. Still working on it.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello everyone,
I'm new on mql and trying to develope myself. I've created my very first own EA and looking it's going well.
I have a problem that I couldn't find a solution and searched a lot about it..
TrailingStop works well on Buy trades however couldn't get any modify attemp on Sell positions. I don't know why..
and also I want to try code that is below on the strategy tester but didn't get any reaction but in normal, it works.
I will appriciate if you help me, Thank you for your interest.