Skip to main content

Process to dev google script

Since you are building a mission-critical application (trading signals), managing versions and bugs is essential to avoid "losing" orders or making execution errors.

Here is the professional process you should follow to manage your Google Apps Script project.

1. Version Control: Stop Coding in the Browser

Developing directly in the Google Script Editor is risky because there is no "Undo" for mistakes made yesterday.

  • Use clasp (Command Line Apps Script Projects): This tool allows you to develop locally on your computer.[1][2][3][4]
  • Git & GitHub: Once the code is on your computer, use Git.
    • Workflow: Code locally     git commit (saves your progress)         clasp push (uploads to Google).
  • Why? If a new update breaks your TradingView alert processing, you can revert to a previous working version in seconds.

2. Manage Environments (Dev vs. Production)

Never test new code on the same Google Sheet you use for live trading alerts.

  • The "Two-Sheet" Rule:
    • Sheet A (Dev): Connect this to a "Paper Trading" account or just log the alerts without executing. This is where you test new logic.
    • Sheet B (Production): This is the stable version. Never change the code here directly.
  • Separate Web App URLs: Every time you "Deploy," you can create a new version. Use one URL for your TradingView/cTrader test alerts and another for live alerts.

3. Deployment & Versioning

In Google Apps Script, "Saving" is not the same as "Deploying."

  • Use Versioned Deployments: When you have a working version, go to Deploy > New Deployment.[5]
  • Labeling: Give it a name like v1.2 - Added cTrader Support.
  • The Benefit: If you make a mistake in the code and click "Save," the live Web App URL will not change until you create a new deployment. This protects your live trading from "work-in-progress" bugs.

4. Robust Bug Tracking & Logging

Trading alerts happen in the background (asynchronously), so you won't see errors in real-time.

  • Dedicated "Error Log" Sheet: Create a tab in your Google Sheet called SystemLogs. Use a try-catch block in your code to write errors there:

code JavaScript

downloadcontent_copy

expand_less

function doPost(e) {

  try {

    // Your processing logic here

  } catch (err) {

    var logSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SystemLogs");

    logSheet.appendRow([new Date(), "ERROR", err.message, e.postData.contents]);

  }

}

  • Cloud Logging: Enable Google Cloud Logging. It allows you to see every request TradingView sent, even if the script crashed before it could write to the Sheet.

5. Trading-Specific Best Practices

  • PropertiesService: Never hardcode your cTrader API keys or TradingView "secret" in the code. Use Project Settings > Script Properties. This keeps secrets out of your version control (GitHub).
  • Validate the Payload: Both TradingView and cTrader allow you to send custom JSON. Always check if the incoming data is valid before processing:

code JavaScript

downloadcontent_copy

expand_less

var data = JSON.parse(e.postData.contents);

if (!data.symbol || !data.signal) return; // Ignore bad alerts

  • Handling Timeouts: Google Apps Script has a 30-second limit for Web App requests. If your processing takes too long (e.g., calling multiple APIs), use the CacheService or Trigger to process the alert "later" and respond to TradingView immediately with a 200 OK.

Summary Checklist for Every Update:

  1. Code the change in your Dev Sheet.
  2. Test with a TradingView "Test Alert."
  3. Commit code to Git.
  4. Deploy as a new version.
  5. Monitor the SystemLogs tab for the first 1 hour of live trading.

Comments

Popular posts from this blog

Viet Currency - Phan 20

  BASIC INDICATORS   

Viet Currency - Phan 21

  Trading technique with ADX        Trong western T/A nó có 4 cái indicators chính mà trên hầu hết các trading desks trên thế giới đều xài. Đó là: MACD, RSI, ADX, và gần đây nữa là CCI. Bên stocks thì MACD là dẫn đầu. MACD, nếu biết xài, thì có thể nói nó đúng chừng 80% trở lên trong US stocks. VN thì tôi không biết. RSI thì tôi không rành lém. Tôi thấy thằng Q đó quờ quạng làm sao ấy. Nhưng có rất nhiều người thề sống chít với nó. Và họ đều là cao thủ hơn tôi, nên tôi không dám chê thằng Q đó nhiều. Vì trong đời tôi gặp ít nhất là 5 cụ. Cụ ở đây có nghĩa là ít gì cũng 50 năm (yeah..50 years on the Street). Cụ nào cũng khen nó còn hơn thuốc Tiên. Có 2 lão dám nói là chỉ cần nhìn RSI thui, không cần nhìn giá mà vẫn trade được như thường. Anyway, thằng thứ 3 là ADX. ADX ở tại Mỹ, nhất là các trading desks mà tôi làm việc khi xưa, đều xài nó cho Currency market. Xin mở dấu hoặc ở đây để phân biệt được cái gọi là currency market và cái gọi là forex marke...

Viet Currency - Phan 22

    5. STOCHASTIC:  Anh VC cho Q hoỉ, nếu nhìn lại năm 2006, 2/8 là đáy, nhưng trong suốt xu hướng giảm giá Momentum giao động thấp nhất là -100. Còn VNI hiện tại, dù chưa giảm nhiều như vậy, nhưng Momentum đã <-100 và đang từ dưới đi lên, điều đó trong PTKT có phản ánh điều gì không?      Momentum nó khác với giá. Nó là sự thay đổi của giá QUA thời gian. Trong một khoảng thời gian nhất định nào đó nếu giá thay đổi nhiều thì momentum sẽ đi xuống và ngược lại. Tôi không xài momentum vì trong giai đoạn này tôi chỉ nhìn trend qua các điểm reactionary points để xác định hướng đi của nó. Khi trend được xác định rồi thì tôi mới xài momentum để dò la sức mạnh của nó. Như cái chart của tôi phía trên, nếu giá đi lên khỏi 1155 hay đi xuống điểm thấp nhất của VNI hôm tuần trước thì lúc đó mới lấy momentum ra đo. Vì lúc đó nó sẽ nói cho tôi biết cái break out (trên 1155) và cái break down có thật sự mạnh hay không? Còn bây giờ chỉ số này chỉ trade trong ...