MT4 expert closes trade at price 0.00000

To add comments, please log in or register
basophil
44
basophil  

Hello, I am very new in coding EA.

I have some problems when I practice with help of online EA making tool.

The EA works as I want in back test but not in real transaction (both real and demo account).
In real transaction, it just open and close several seconds after open. 
And open another trade right after closing.(This is what I set so I think open is not the problem.) 
I check the journal find this strange, it closed at price  0.00000:

  • close order #27115967 buy 0.03 EURUSD at 1.09468 sl: 0.00000 tp: 1.09558 at price 0.00000


The EA I write is very simple, I want to practice using Martigale for lot.

I limited the EA with buy order only and not setting SL.


The stradegy is:

Entry when there is no current trade. (No matter the price.)

Set the TP from inputs for the first trade.

If the price reaches TP -> close trade at TP

If dropped certain pips -> open another trade


If there is more than one trade, the TP will not be modified but will be defined by another code.

TP will be [total trade lots * take profit value from imput]

So the scenario should be like:

 open buy 0.01 at 1.09000, set TP at 1.09090

 next should close trade at 1.09090

               or open buy 0.03 at 1.08350 and close both trades at 1.8612


The code:

#include <stdlib.mqh>
#include <stderror.mqh>

//Input (and default value):
//StartTakeProfit (90): the TP for the first trade.
//MartFactor (3): Martingale multiply factor
//MartDistance (650): after how many pips should open the next trade
//MartTakeProfit (100): The profit
//MaxLongTrades (3): the maximum trade number
//MartStartLot (0.03): the start l

extern int StartTakeProfit = 90;
extern int MartFactor = 3;
extern int MartDistance = 650;
extern int MartTakeProfit = 100;
extern double MartStartLot = 0.03;
extern int MaxLongTrades = 3;
int LotDigits; //initialized in OnInit
int MagicNumber = 1738833;
int MaxSlippage = 3; //adjusted in OnInit
bool crossed[1]; //initialized to true, used in function Cross
int MaxOpenTrades = 1000;
extern int MaxShortTrades = 3;
int MaxPendingOrders = 1000;
bool Hedging = false;
int OrderRetry = 5; //# of retries if sending order returns error
int OrderWait = 5; //# of seconds to wait if sending order returns error

bool Cross(int i, bool condition) //returns true if "condition" is true and was false in the previous call
  {
   bool ret = condition && !crossed[i];
   crossed[i] = condition;
   return(ret);
  }

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | Double @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
  }

int TradesCount(int type) //returns # of open trades for order type, current symbol and magic number
  {
   int result = 0;
   int total = OrdersTotal();
   for(int i = 0; i < total; i++)
     {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false) continue;
      if(OrderMagicNumber() != MagicNumber || OrderSymbol() != Symbol() || OrderType() != type) continue;
      result++;
     }
   return(result);
  }


double OpenTradeSize()
  {
   double result = 0;
   int total = OrdersTotal();
   for(int i = 0; i < total; i++)
     {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false) break;
      if(OrderMagicNumber() != MagicNumber || OrderSymbol() != Symbol() || (OrderType() != OP_BUY && OrderType() != OP_SELL)) continue;
      result += OrderLots();
     }
   return(result);
  }

double LastLongTradePrice()
  {
   double result = 0;
   for(int i = OrdersTotal()-1; i >= 0; i--)
     {
      if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
      if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_BUY)
        {
         result = OrderOpenPrice();
         break;
        }
     } 
   return(result);
  }

double TotalOpenProfit(int direction)
  {
   double result = 0;
   int total = OrdersTotal();
   for(int i = 0; i < total; i++)   
     {
      if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
      if(OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
          if((direction < 0 && OrderType() == OP_BUY) || (direction > 0 && OrderType() == OP_SELL)) continue;
      result += OrderProfit();
     }
   return(result);
  }

int myOrderSend(int type, double price, double volume, string ordername) //send order, return ticket ("price" is irrelevant for market orders)
  {
   if(!IsTradeAllowed()) return(-1);
   int ticket = -1;
   int retries = 0;
   int err = 0;
   int long_trades = TradesCount(OP_BUY);
   int short_trades = TradesCount(OP_SELL);
   int long_pending = TradesCount(OP_BUYLIMIT) + TradesCount(OP_BUYSTOP);
   int short_pending = TradesCount(OP_SELLLIMIT) + TradesCount(OP_SELLSTOP);
   string ordername_ = ordername;
   if(ordername != "")
      ordername_ = "("+ordername+")";
   //test Hedging
   if(!Hedging && ((type % 2 == 0 && short_trades + short_pending > 0) || (type % 2 == 1 && long_trades + long_pending > 0)))
     {
      myAlert("print", "Order"+ordername_+" not sent, hedging not allowed");
      return(-1);
     }
   //test maximum trades
   if((type % 2 == 0 && long_trades >= MaxLongTrades)
   || (type % 2 == 1 && short_trades >= MaxShortTrades)
   || (long_trades + short_trades >= MaxOpenTrades)
   || (type > 1 && long_pending + short_pending >= MaxPendingOrders))
     {
      myAlert("print", "Order"+ordername_+" not sent, maximum reached");
      return(-1);
     }
   //prepare to send order
   while(IsTradeContextBusy()) Sleep(100);
   RefreshRates();
   if(type == OP_BUY)
      price = Ask;
   else if(type == OP_SELL)
      price = Bid;
   else if(price < 0) //invalid price for pending order
     {
      myAlert("order", "Order"+ordername_+" not sent, invalid price for pending order");
          return(-1);
     }
   int clr = (type % 2 == 1) ? clrRed : clrBlue;
   while(ticket < 0 && retries < OrderRetry+1)
     {
      ticket = OrderSend(Symbol(), type, NormalizeDouble(volume, LotDigits), NormalizeDouble(price, Digits()), MaxSlippage, 0, 0, ordername, MagicNumber, 

0, clr);
      if(ticket < 0)
        {
         err = GetLastError();
         myAlert("print", "OrderSend"+ordername_+" error #"+IntegerToString(err)+" "+ErrorDescription(err));
         Sleep(OrderWait*1000);
        }
      retries++;
     }
   if(ticket < 0)
     {
      myAlert("error", "OrderSend"+ordername_+" failed "+IntegerToString(OrderRetry+1)+" times; error #"+IntegerToString(err)+" "+ErrorDescription(err));
      return(-1);
     }
   string typestr[6] = {"Buy", "Sell", "Buy Limit", "Sell Limit", "Buy Stop", "Sell Stop"};
   myAlert("order", "Order sent"+ordername_+": "+typestr[type]+" "+Symbol()+" Magic #"+IntegerToString(MagicNumber));
   return(ticket);
  }

int myOrderModifyRel(int ticket, double SL, double TP) //modify SL and TP (relative to open price), zero targets do not modify
  {
   if(!IsTradeAllowed()) return(-1);
   bool success = false;
   int retries = 0;
   int err = 0;
   SL = NormalizeDouble(SL, Digits());
   TP = NormalizeDouble(TP, Digits());
   if(SL < 0) SL = 0;
   if(TP < 0) TP = 0;
   //prepare to select order
   while(IsTradeContextBusy()) Sleep(100);
   if(!OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
     {
      err = GetLastError();
      myAlert("error", "OrderSelect failed; error #"+IntegerToString(err)+" "+ErrorDescription(err));
      return(-1);
     }
   //prepare to modify order
   while(IsTradeContextBusy()) Sleep(100);
   RefreshRates();
   //convert relative to absolute
   if(OrderType() % 2 == 0) //buy
     {
      if(NormalizeDouble(SL, Digits()) != 0)
         SL = OrderOpenPrice() - SL;
      if(NormalizeDouble(TP, Digits()) != 0)
         TP = OrderOpenPrice() + TP;
     }
   else //sell
     {
      if(NormalizeDouble(SL, Digits()) != 0)
         SL = OrderOpenPrice() + SL;
      if(NormalizeDouble(TP, Digits()) != 0)
         TP = OrderOpenPrice() - TP;
     }
   if(CompareDoubles(SL, 0)) SL = OrderStopLoss(); //not to modify
   if(CompareDoubles(TP, 0)) TP = OrderTakeProfit(); //not to modify
   if(CompareDoubles(SL, OrderStopLoss()) && CompareDoubles(TP, OrderTakeProfit())) return(0); //nothing to do
   while(!success && retries < OrderRetry+1)
     {
      success = OrderModify(ticket, NormalizeDouble(OrderOpenPrice(), Digits()), NormalizeDouble(SL, Digits()), NormalizeDouble(TP, Digits()), 

OrderExpiration(), CLR_NONE);
      if(!success)
        {
         err = GetLastError();
         myAlert("print", "OrderModify error #"+IntegerToString(err)+" "+ErrorDescription(err));
         Sleep(OrderWait*1000);
        }
      retries++;
     }
   if(!success)
     {
      myAlert("error", "OrderModify failed "+IntegerToString(OrderRetry+1)+" times; error #"+IntegerToString(err)+" "+ErrorDescription(err));
      return(-1);
     }
   string alertstr = "Order modified: ticket="+IntegerToString(ticket);
   if(!CompareDoubles(SL, 0)) alertstr = alertstr+" SL="+DoubleToString(SL);
   if(!CompareDoubles(TP, 0)) alertstr = alertstr+" TP="+DoubleToString(TP);
   myAlert("modify", alertstr);
   return(0);
  }

void myOrderClose(int type, int volumepercent, string ordername) //close open orders for current symbol, magic number and "type" (OP_BUY or OP_SELL)
  {
   if(!IsTradeAllowed()) return;
   if (type > 1)
     {
      myAlert("error", "Invalid type in myOrderClose");
      return;
     }
   bool success = false;
   int err = 0;
   string ordername_ = ordername;
   if(ordername != "")
      ordername_ = "("+ordername+")";
   int total = OrdersTotal();
   int orderList[][2];
   int orderCount = 0;
   for(int i = 0; i < total; i++)
     {
      while(IsTradeContextBusy()) Sleep(100);
      if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
      if(OrderMagicNumber() != MagicNumber || OrderSymbol() != Symbol() || OrderType() != type) continue;
      orderCount++;
      ArrayResize(orderList, orderCount);
      orderList[orderCount - 1][0] = OrderOpenTime();
      orderList[orderCount - 1][1] = OrderTicket();
     }
   if(orderCount > 0)
      ArraySort(orderList, WHOLE_ARRAY, 0, MODE_ASCEND);
   for(i = 0; i < orderCount; i++)
     {
      if(!OrderSelect(orderList[i][1], SELECT_BY_TICKET, MODE_TRADES)) continue;
      while(IsTradeContextBusy()) Sleep(100);
      RefreshRates();
      double price = (type == OP_SELL) ? Ask : Bid;
      double volume = NormalizeDouble(OrderLots()*volumepercent * 1.0 / 100, LotDigits);
      if (NormalizeDouble(volume, LotDigits) == 0) continue;
      success = OrderClose(OrderTicket(), volume, NormalizeDouble(price, Digits()), MaxSlippage, clrWhite);
      if(!success)
        {
         err = GetLastError();
         myAlert("error", "OrderClose"+ordername_+" failed; error #"+IntegerToString(err)+" "+ErrorDescription(err));
        }
     }
   string typestr[6] = {"Buy", "Sell", "Buy Limit", "Sell Limit", "Buy Stop", "Sell Stop"};
   if(success) myAlert("order", "Orders closed"+ordername_+": "+typestr[type]+" "+Symbol()+" Magic #"+IntegerToString(MagicNumber));
  }

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {   
   //initialize LotDigits
   double LotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
   if(LotStep >= 1) LotDigits = 0;
   else if(LotStep >= 0.1) LotDigits = 1;
   else if(LotStep >= 0.01) LotDigits = 2;
   else LotDigits = 3;
   int i;
   //initialize crossed
   for (i = 0; i < ArraySize(crossed); i++)
      crossed[i] = true;
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  }

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   int ticket = -1;
   double price;   
   double TP;
   
   
   //Close Long Positions
   if(TotalOpenProfit(1) > MartTakeProfit * OpenTradeSize() //Total Open Profit (Long) > fixed value * Open Trade Size
   )
     {   
      if(IsTradeAllowed())
         myOrderClose(OP_BUY, 100, "");
      else //not autotrading => only send alert
         myAlert("order", "");
     }
   
   //Open Buy Order
   if(TradesCount(OP_BUY) == 0 //Long Trades is equal to fixed value
   )
     {
      RefreshRates();
      price = Ask;
      TP = StartTakeProfit * Point(); //Take Profit = value in points (relative to price)   
      if(IsTradeAllowed())
        {
         ticket = myOrderSend(OP_BUY, price, MartStartLot, "");
         if(ticket <= 0) return;
        }
      else //not autotrading => only send alert
         myAlert("order", "");
      myOrderModifyRel(ticket, 0, TP);
     }
   
   //Open Buy Order, instant signal is tested first
   RefreshRates();
   if(Cross(0, Bid < LastLongTradePrice() - MartDistance * Point()) //Price crosses below Last Open Trade Price (Long) - fixed value
   )
     {
      RefreshRates();
      price = Ask;   
      if(IsTradeAllowed())
        {
         int expo = TradesCount(OP_BUY) ;
         double zz = MathPow(MartFactor,expo);
         ticket = myOrderSend(OP_BUY, price, MartStartLot* MathPow(MartFactor,expo), "");
         if(ticket <= 0) return;
        }
      else //not autotrading => only send alert
         myAlert("order", "");
     }
  }
//+------------------------------------------------------------------+

The full journal in real transaction:

2020.02.27 21:29:05.140 '13003601': order was opened : #27116017 buy 0.03 EURUSD at 1.09475 sl: 0.00000 tp: 0.00000
2020.02.27 21:29:04.404 '13003601': order buy market 0.03 EURUSD sl: 0.00000 tp: 0.00000

2020.02.27 21:29:04.404 '13003601': order #27115989 buy 0.03 EURUSD at 1.09470 sl: 0.00000 tp: 1.09560 closed at price 1.09473
2020.02.27 21:29:03.683 '13003601': close order #27115989 buy 0.03 EURUSD at 1.09470 sl: 0.00000 tp: 1.09560 at price 0.00000
2020.02.27 21:28:22.659 '13003601': order #27115989 buy 0.03 EURUSD at 1.09470 was modified -> sl: 0.00000 tp: 1.09560
2020.02.27 21:28:22.130 '13003601': modify order #27115989 buy 0.03 EURUSD at 1.09470 sl: 0.00000 tp: 0.00000 -> sl: 0.00000 tp: 1.09560
2020.02.27 21:28:22.130 '13003601': order was opened : #27115989 buy 0.03 EURUSD at 1.09470 sl: 0.00000 tp: 0.00000
2020.02.27 21:28:21.611 '13003601': order buy market 0.03 EURUSD sl: 0.00000 tp: 0.00000

2020.02.27 21:28:21.611 '13003601': order #27115967 buy 0.03 EURUSD at 1.09468 sl: 0.00000 tp: 1.09558 closed at price 1.09468
2020.02.27 21:28:20.981 '13003601': close order #27115967 buy 0.03 EURUSD at 1.09468 sl: 0.00000 tp: 1.09558 at price 0.00000
2020.02.27 21:27:29.335 '13003601': order #27115967 buy 0.03 EURUSD at 1.09468 was modified -> sl: 0.00000 tp: 1.09558
2020.02.27 21:27:28.892 '13003601': modify order #27115967 buy 0.03 EURUSD at 1.09468 sl: 0.00000 tp: 0.00000 -> sl: 0.00000 tp: 1.09558
2020.02.27 21:27:28.892 '13003601': order was opened : #27115967 buy 0.03 EURUSD at 1.09468 sl: 0.00000 tp: 0.00000
2020.02.27 21:27:28.431 '13003601': order buy market 0.03 EURUSD sl: 0.00000 tp: 0.00000

It works good in back test:

I feel like this is a very simple error. 
Someone in the forum also had this problem but no specific answer. (https://www.mql5.com/en/forum/141989)

Anyone has any idea?

Thank you!

why expert closes trade at price 0.00000 ?
why expert closes trade at price 0.00000 ?
  • 2012.11.05
  • www.mql5.com
My expert closes some orders NOT from TP and SL like it should, but for no apparent reason at price 0...
William Roeder
20674
William Roeder  
  1. Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. basophil: I check the journal find this strange, it closed at price  0.00000: I feel like this is a very simple error.
    Message from the terminal, not your code. Not an error since it is followed by a valid result and not your error message. ECN brokers ignore price and slippage.

  3. basophil: The EA I write is very simple, I want to practice using Martigale for lot.d
    Martingale, guaranteed to blow your account eventually. If it's not profitable without, it is definitely not profitable with.
              Martingale vs. Non Martingale (Simplified RoR vs Profit and the Illusions) - MQL5 programming forum
    Why it won't work: Calculate Loss from Lot Pips - MQL5 programming forum

  4. basophil: If the price reaches TP -> close trade at TP
    Take profit automatically closed the trade.

  5. basophil:I limited the EA with buy order only and not setting SL.
    No SL means infinite risk — you can't compute your lot size without it. Never risk more than a small percentage of your account, certainly less than 2% per trade, 6% total to the account. Risk depends on your initial stop loss, lot size, and the value of the pair. It does not depend on margin and leverage.
    1. You place the stop where it needs to be — where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
    2. AccountBalance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the spread, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
    3. Do NOT use TickValue by itself - DeltaPerLot and verify that MODE_TICKVALUE is returning a value in your deposit currency, as promised by the documentation, or whether it is returning a value in the instrument's base currency.
                MODE_TICKVALUE is not reliable on non-fx instruments with many brokers - MQL4 programming forum 2017.10.10
                Is there an universal solution for Tick value? - Currency Pairs - General - MQL5 programming forum 2018.02.11
                Lot value calculation off by a factor of 100 - MQL5 programming forum 2019.07.19
    4. You must normalize lots properly and check against min and max.
    5. You must also check FreeMargin to avoid stop out

    Most pairs are worth about $10 per PIP. A $5 risk with a (very small) 5 PIP SL is $5/$10/5 or 0.1 Lots maximum.

basophil
44
basophil  

Hello, William, 

Thank you for your reply. Sorry I didn't realize that EA section is for MT5 only. Will keep that in mind next time!

I have experience of use EA and understand it's dangerous using martingale also not setting SL. I just wanted to code something quickly and see how home-build EA runs like. 

Message from the terminal, not your code. Not an error since it is followed by a valid result and not your error message. ECN brokers ignore price and slippage.

Can you explain a little more? I know it' not an error message but I think this is the clue of why the trade closed unexpectedly.

I want to know the reason why the trade is closed. They are not closed at certain profit/loss or some specific time interval.

More curious is why it works in backtest.

    Do NOT use TickValue by itself - DeltaPerLot and verify that MODE_TICKVALUE is returning a value in your deposit currency, as promised by the documentation, or whether it is returning a value in the instrument's base currency.
              MODE_TICKVALUE is not reliable on non-fx instruments with many brokers - MQL4 programming forum 2017.10.10
              Is there an universal solution for Tick value? - Currency Pairs - General - MQL5 programming forum 2018.02.11
              Lot value calculation off by a factor of 100 - MQL5 programming forum 2019.07.19

    Thank you for the tips!! I will check into these articles.

    And also the suggestion of money management is much appreciated! Never really think too deep about this and always try with 1000 USD / 0.01 lot every time using a new EA.

    Cheers!

    William Roeder
    20674
    William Roeder  

    basophil:

    Can you explain a little more? I know it' not an error message but I think this is the clue of why the trade closed unexpectedly.

    Never really think too deep about this and always try with 1000 USD / 0.01 lot every time using a new EA.

    Your EA opened 0.03 lots, with only $1K balance. Likely free margin was exhausted and the order closed. See #1 № 5.5

    Alain Verleyen
    39516
    Alain Verleyen  
    basophil:

    Hello, William, 

    Thank you for your reply. Sorry I didn't realize that EA section is for MT5 only. Will keep that in mind next time!

    I have experience of use EA and understand it's dangerous using martingale also not setting SL. I just wanted to code something quickly and see how home-build EA runs like. 

    Can you explain a little more? I know it' not an error message but I think this is the clue of why the trade closed unexpectedly.

    I want to know the reason why the trade is closed. They are not closed at certain profit/loss or some specific time interval.

    More curious is why it works in backtest.

    Thank you for the tips!! I will check into these articles.

    And also the suggestion of money management is much appreciated! Never really think too deep about this and always try with 1000 USD / 0.01 lot every time using a new EA.

    Cheers!

    Your order was not closed at a price = 0.00000. It's the way the Terminal output an order with a Market Execution as the price at which it will be executed is unknown.

    2020.02.27 21:28:21.611 '13003601': order #27115967 buy 0.03 EURUSD at 1.09468 sl: 0.00000 tp: 1.09558 closed at price 1.09468            => close execution
    2020.02.27 21:28:20.981 '13003601': close order #27115967 buy 0.03 EURUSD at 1.09468 sl: 0.00000 tp: 1.09558 at price 0.00000              => order to close send

    Your EA request to close the order, as there is only 1 place in your code when it can be done :

      if(TotalOpenProfit(1) > MartTakeProfit * OpenTradeSize() //Total Open Profit (Long) > fixed value * Open Trade Size
        )
       {
        if(IsTradeAllowed())
          myOrderClose(OP_BUY, 100, "");
        else //not autotrading => only send alert
          myAlert("order", "");
       }
    

    That means this condition was true and the myOrderClose() was executed.

    This condition doesn't make sense, you are comparing a value in $ (or whatever the account currency) from TotalOpenProfit(), with a number of lots (returned by OpenTradeSize) multiplied by some factor.

    Most probably your MartTakeProfit was equal to 1.

    Fix your coding logic.

    basophil
    44
    basophil  
    William Roeder:

    Your EA opened 0.03 lots, with only $1K balance. Likely free margin was exhausted and the order closed. See #1 № 5.5

    Hello, Willam. 

    This also happen when I use 0.01 lost and with 10K usd balance. And the equity is always much more than the margin required.

    But you are totally right, I should definitely add money management  in my EA.

    Alain Verleyen:

    Your order was not closed at a price = 0.00000. It's the way the Terminal output an order with a Market Execution as the price at which it will be executed is unknown.

    2020.02.27 21:28:21.611 '13003601': order #27115967 buy 0.03 EURUSD at 1.09468 sl: 0.00000 tp: 1.09558 closed at price 1.09468            => close execution
    2020.02.27 21:28:20.981 '13003601': close order #27115967 buy 0.03 EURUSD at 1.09468 sl: 0.00000 tp: 1.09558 at price 0.00000              => order to close send

    Your EA request to close the order, as there is only 1 place in your code when it can be done :

    That means this condition was true amd the myOrderClose() was executed.

    This condition doesn't make sense, you are comparing a value in $ (or whatever the account currency) fron TotalOpenProfit(), with a number of lots (returned by OpenTradeSize) multiplied by some factor.

    Most probably your MartTakeProfit was equal to 1.

    Fix your coding logic.

    Hello, Alain


    You are right! this profit part is the problem.


    When I remove or modify the writing there, the trades doesn't close for unknown reason.

    I use USD account and trade with EURUSD, so I think by calculating total profit and compare with  ((desired profit points/0.01 lots) * total lots) can achieve what I want. (and it does in the backtest! this is the most strange thing!) Maybe using different type of integrates (currency/value) is really a bad idea as you said.

    I will try to modify the profit part into modifying TP in all trades when new trade opens.


    Thank you sososo much!

    To add comments, please log in or register