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...

[VC20] Momentum indicator RSI, ADX

  I. Nguyên Tắc Nền Tảng: Xu Hướng Là Vua Bài Học Sống Còn:  Nguyên tắc quan trọng nhất là phải xác định và đi theo  xu hướng chính (Trend) . Công việc của nhà giao dịch là "dò sóng" và "nương theo sóng", không phải chống lại nó. Tránh Bắt Đỉnh, Dò Đáy:  Đừng cố gắng tìm điểm mua thấp nhất (bottom) và điểm bán cao nhất (top). Thay vào đó, hãy tập trung kiếm lợi nhuận ở  "khúc giữa" của xu hướng  để đảm bảo sự an toàn và bền vững. II. Định Nghĩa Cốt Lõi: Phân Biệt Rõ Trend và Momentum Trend (Xu hướng):  Là  hướng đi  của thị trường (lên, xuống, hoặc đi ngang). Đây là yếu tố quyết định cho việc mua hay bán. Momentum (Động lượng):  Là  Rate of Change  (Tốc độ/Cường độ thay đổi) của giá. Nó được dùng để đo lường  SỨC MẠNH (Strength)  của giá, chứ  không thể dùng để đo hướng đi . III. Cách Sử Dụng Các Chỉ Báo Kỹ Thuật Một Cách Hiệu Quả Luô...