How can I debug this code?

 

I am new to programming, I wrote this program to place buystops and modify them at intervals if not triggered or close them after some time if triggered. Who can help me get it working?

//+------------------------------------------------------------------+
//|                                                  Codeboomtry.mq5 |
//|                                             Copyright Dozie 2022 |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright Dozie 2022"
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetTimer(60);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
#include <Trade\Trade.mqh>
#include <Trade\PositionInfo.mqh>

class CTrade : public CObject
class CPositionInfo : public CObject

//Variables and constants
double prev0close = iClose(_Symbol, PERIOD_M1, 0);
double prev1open = iOpen(_Symbol, PERIOD_M1, 1);
double prev1close = iClose(_Symbol,PERIOD_M1 , 1);
double prev3open = iOpen(_Symbol, PERIOD_M1, 3);
double prev3close = iClose(_Symbol, PERIOD_M1, 3);
long spread = iSpread(_Symbol,PERIOD_M1,0);
long bstopprice = double prev1close+ long spread;
long sstopprice = double prev1close-long spread;
    
void OnTick()
  {
//---
   //OPEN ORDERS
if (OrdersTotal()=<1 && double prev3close> double prev1close){
    bool OrderOpen(_Symbol,ORDER_BUY_STOP, 0.5,long bstopprice,0,0,ORDER_TIME_GTC, 200, "TRY");
    }
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   //MODIFY ORDER
if (OrdersTotal()>0 && double prev1open>double prev0close){
    for(i=0;i<OdersTotal();i++;){
        ulong ticket = PositionGetTicket(int i);
        bool OrderModify(ulong ticket,long bstopprice,0,0,ORDER_TIME_GTC);
        }
    }

//CLOSE POSITION
if (PositionsTotal()>0){
    for(i=0;i<PositionsTotal();i++;){
        ulong ticket = PositionGetTicket(int i);
        bool PositionSelectByTicket(ulong ticket);
        datetime opentime = Time() const;
        datetime currtime = TimeUpdate() const;
        datetime durmin = (opentime-currtime)/60;
        if (datetime durmin>=1)
            {
            bool PositionClose(ulong ticket);
            }
        }
    }
  }
//+------------------------------------------------------------------+
 

All you need to know you'll find here:

https://www.metatrader5.com/en/metaeditor/help/development/debug // Code debugging
https://www.mql5.com/en/articles/2041 // Error Handling and Logging in MQL5
https://www.mql5.com/en/articles/272 // Tracing, Debugging and Structural Analysis of Source Code
https://www.mql5.com/en/articles/35 // scrol down to: "Launching and Debuggin"

Code debugging - Developing programs - MetaEditor Help
Code debugging - Developing programs - MetaEditor Help
  • www.metatrader5.com
MetaEditor has a built-in debugger allowing you to check a program execution step by step (by individual functions). Place breakpoints in the code...
 
Chukwudozie Thankgod:

I am new to programming, I wrote this program to place buystops and modify them at intervals if not triggered or close them after some time if triggered. Who can help me get it working?

This code contains dozens of errors - the first thing to do is use the compiler and fix all the syntax errors.

It helps if you compile regularly while typing to avoid ending up with a large number of errors at the end, as we see here.

I suggest you comment out sections of code so you can handle this in a bite-sized manner - all part of the journey in learning how to program