Code stuck at "if" statement.

 
Hyy guys...i need help please. The "Newpositionprofit" in the code there doesnt seem to update itself. The programm just stops at ...
if(Newpositionprofit>=0)
it doesnt do nothing anymore, it doesnt even call the ontick function anymore. please how do i solve this??
if(tradecount==1 && firstpositiontype==EnumToString(POSITION_TYPE_BUY))
   {
    Alert(firstpositiontype);
    Alert(stoplossprice);
    if(firstpositionpricecurrent<=stoplossprice && tradecount==1)
    {
     Alert("Position Hedge");
     Trade.Sell(firstpositionvolume,Symbol(),stoplossprice,0,0);
     ulong Newpositionticket=positionselector("POSITION_TYPE_SELL");
     PositionSelectByTicket(Newpositionticket);
     string Newpositiontype=Getpositiontype();
     if(Newpositiontype=="POSITION_TYPE_SELL")
     {
      double Newpositionprofit=profitcounter();
      Alert(Newpositionprofit);
      Alert(Newpositiontype);
      if(Newpositionprofit>=0)
      {
       Alert("positionzeroeing");
       if(Newpositionprofit==0)
       {
        double positionpriceclosed=PositionGetDouble(POSITION_PRICE_CURRENT);
        stoplossprice=positionpriceclosed;
        Alert("positionzeroeing price = ",stoplossprice);
       }
       if(Newpositionprofit<=0)
       {
        Alert("Position Hedge Closed");
        Trade.PositionClose(Newpositionticket);
       }
      }
     }
    }
   }
The Fundamentals of Testing in MetaTrader 5
The Fundamentals of Testing in MetaTrader 5
  • www.mql5.com
What are the differences between the three modes of testing in MetaTrader 5, and what should be particularly looked for? How does the testing of an EA, trading simultaneously on multiple instruments, take place? When and how are the indicator values calculated during testing, and how are the events handled? How to synchronize the bars from different instruments during testing in an "open prices only" mode? This article aims to provide answers to these and many other questions.
 
JUDE UZO: . The "Newpositionprofit" in the code there doesnt seem to update itself. The programm just stops at ... it doesnt do nothing anymore, it doesnt even call the ontick function anymore.
  1. There is no self-changing code

  2. What is "it". Your code should never call OnTick.

  3. Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
              Code debugging - Developing programs - MetaEditor Help
              Error Handling and Logging in MQL5 - MQL5 Articles (2015)
              Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
              Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

 
William Roeder #:
  1. There is no self-changing code

  2. What is "it". Your code should never call OnTick.

  3. Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
              Code debugging - Developing programs - MetaEditor Help
              Error Handling and Logging in MQL5 - MQL5 Articles (2015)
              Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
              Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

Thanks for your reply... the code always stops at 
if(Newpositionprofit>=0)

if doesnt do nothing anymore from there...please what can i do?

 
JUDE UZO #:
Thanks for your reply... the code always stops at 

if doesnt do nothing anymore from there...please what can i do?

Did you set Debug stop points and it doesn't return to OnTick or does the entire Meta Editor crash?
 
pennyhunter #:
Did you set Debug stop points and it doesn't return to OnTick or does the entire Meta Editor crash?
Thanks so much for your reply... no i didnt set Debug stop points and no the Meta Editor doesnt crash. the code just stops working there. 
if(Newpositionprofit>=0)

it gives me the alerts right before that code line. but when i reaches that code line it does nothing else.

 
Read this: https://www.mql5.com/en/articles/654, use it and most probably you will find and solve your problem.
Reason: