I need help to figure out how to close all my positions.

 
      string symbol = Symbol();
      ulong deviation = ULONG_MAX;
      if (PositionClose(symbol, deviation){
         Print("Position for symbol ", symbol, " closed successfully");
      }else{
         Print("Error closing position for symbol ", symbol, ". Error code:", GetLastError());
      }

I am trying to write code so that I can close my positions when a certain signal appears on the charts. I have been trying this for a long time but I cannot figure out how to solve this. This is what I have so far but I keep getting errors saying that there is some operator expected in 'symbol' and that ruins the third line of the code and leads to a few other areas in that line. 

 

You can just search codebase.

https://www.mql5.com/en/code/36010

Close All Orders and Positions
Close All Orders and Positions
  • www.mql5.com
This is a simple script that Closes all Orders and Positions available
 
Yashar Seyyedin #:

You can just search codebase.

https://www.mql5.com/en/code/36010

Yashar is right, check the code base and furthermore you can always check youtube there are plenty of videos on that topic.

 
Jonathan Durance:

I am trying to write code so that I can close my positions when a certain signal appears on the charts. I have been trying this for a long time but I cannot figure out how to solve this. This is what I have so far but I keep getting errors saying that there is some operator expected in 'symbol' and that ruins the third line of the code and leads to a few other areas in that line. 

Is this chatGPT?