auroagwei

NAND Perceptron

Experimental NAND Perceptron based upon Python template that aims to predict NAND Gate Outputs. A Perceptron is one of the foundational building blocks of nearly all advanced Neural Network layers and models for Algo trading and Machine Learning.

The goal behind this script was threefold:
  • To prove and demonstrate that an ACTUAL working neural net can be implemented in Pine, even if incomplete.
  • To pave the way for other traders and coders to iterate on this script and push the boundaries of Tradingview strategies and indicators.
  • To see if a self-contained neural network component for parameter optimization within Pinescript was hypothetically possible.

NOTE: This is a highly experimental proof of concept - this is NOT a ready-made template to include or integrate into existing strategies and indicators, yet (emphasis YET - neural networks have a lot of potential utility and potential when utilized and implemented properly).


Hardcoded NAND Gate outputs with Bias column (X0):
// NAND Gate + X0 Bias and Y-true
// X0 // X1 // X2 // Y
// 1 // 0 // 0 // 1
// 1 // 0 // 1 // 1
// 1 // 1 // 0 // 1
// 1 // 1 // 1 // 0


  • Column X0 is bias feature/input
  • Column X1 and X2 are the NAND Gate
  • Column Y is the y-true values for the NAND gate
  • yhat is the prediction at that timestep
  • F0,F1,F2,F3 are the Dot products of the Weights (W0,W1,W2) and the input features (X0,X1,X2)
  • Learning rate and activation function threshold are enabled by default as input parameters

  • Uncomment sections for more training iterations/epochs:
  • Loop optimizations would be amazing to have for a selectable length for training iterations/epochs but I'm not sure if it's possible in Pine with how this script is structured.


  • Error metrics and loss have not been implemented due to difficulty with script length and iterations vs epochs - I haven't been able to configure the input parameters to successfully predict the right values for all four y-true values for the NAND gate (only been able to get 3/4; If you're able to get all four predictions to be correct, let me know, please).

// //---- REFERENCE for final output
// A3 := 1, y0 true
// B3 := 1, y1 true
// C3 := 1, y2 true
// D3 := 0, y3 true

PLEASE READ: Source article/template and main code reference:
https://towardsdatascience.com/6-steps-t...
https://towardsdatascience.com/what-the-...
https://towardsdatascience.com/how-to-bu...
Nov 12
릴리즈 노트: //v5.6c - activation function error fix (was F > 0.25; corrected 1), line 99
Nov 13
릴리즈 노트: //v5.6d - correction to activation function variable z not being keyed in + W0/W1/W2 not being factored in for initial iterations
Nov 14
릴리즈 노트: // v6.4 - Dot product operation error for F0-F3 and W0-F3 fixed. Test for loop iterator for training.
// v6.5d -
// Loop Iteration for epoch training implemented
// Sum of Squared Error (SSE) implemented
// Y-pred vs Y-true color coded output option function (green/red)
// Custom input options for all arrays, including W0-W2
// Allows for custom of input features, weights, and bias - Default is NAND gate.
// Placeholder "========" for input options seperator for settings panel
// 3x Infopanel component for display output + match color (green/orange/red.)
// v6.6
// Gate detection including XOR/NOR (despite not being able to converge/solve with SLP Neurons - MLP + nonlinear activations required for XOR/NOR training and detection)
Nov 15
릴리즈 노트: // v6.6b
// Missing XOR/XNOR MLP + nonlinear activation warning/message in yellow upon detection - fixed.
즐겨찾기 스크립트에서 빼기 즐겨찾기 스크립트에 넣기

코멘트

how to use it? Please describe it in layman language. Thanks.
+1 응답
OutsourcE jackxryan
@jackxryan, greenish output means a long bias/redish output means a short bias, me thinks
응답
WOW!!
+1 응답
Very nice. Thank you for pushing the boundaries of Pine and also for sharing!
+1 응답
auroagwei allanster
@allanster, ye real neural network components/applications is some exciting stuff - I'm looking forward to seeing how this script is potentially used by other traders/programmers
응답
and the oscar for hardcoding goes toooo .... =))

can it be used on xbt/usd pair?
응답
auroagwei mrgr888n
@mrgr888n, see the description:

"NOTE: This is a highly experimental proof of concept - this is NOT a ready-made template to include or integrate into existing strategies and indicators, yet (emphasis YET - neural networks have a lot of potential utility and potential when utilized and implemented properly).

The goal behind this script was threefold:
To prove and demonstrate that an ACTUAL working neural net can be implemented in Pine, even if incomplete.
To pave the way for other traders and coders to iterate on this script and push the boundaries of Tradingview strategies and indicators.
To see if a self-contained neural network component for parameter optimization within Pinescript was hypothetically possible."
응답
RafaelZioni auroagwei
@auroagwei, look very interesting idea, great work :)
응답
auroagwei RafaelZioni
@RafaelZioni, technically it's incomplete - loss/error func isn't in,i couldn't figure out how to make the iterations/epochs component dynamically selectable with a loop since each state has to be updated manually. It should in theory be possible to make a loop for the above but it's something I'm having difficulty getting to work properly/if at all
응답
auroagwei auroagwei
If and when real array structures and access methods come to pinescript ----> I'm pretty hype for the future, since once real array methods are in pinescript, doing what I did in this script becomes massively easier + opens the door toward more complex data structures and script components
응답
홈으로 스탁 스크리너 포렉스 스크리너 크립토 스크리너 이코노믹 캘린더 사용안내 차트 특징 프라이싱 프렌드 리퍼하기 하우스룰(내부규정) 헬프 센터 웹사이트 & 브로커 솔루션 위젯 차팅 솔루션 라이트웨이트 차팅 라이브러리 블로그 & 뉴스 트위터
프로화일 프로화일설정 계정 및 빌링 프렌드 리퍼하기 나의 서포트 티켓 헬프 센터 공개아이디어 팔로어 팔로잉 비밀메시지 채팅 로그아웃