资源加载中... loading...

Dynamic balance strategy of blockly

Author: Zero, Date: 2018-10-12 15:43:00
Tags: StudyVisualization

快速体验程序化交易, 新手入门1分钟尝鲜必备

你认为可视化编程有用吗 ?

  • 实用, 降低门槛, 先提高兴趣, 再研究代码
  • 无用, 直接接触代码比较好
  • 观察, 教孩子学量化也不错, 长大了不当韭菜

{"xml":"<xml xmlns=\"https://developers.google.com/blockly/xml\">\n  <variables>\n    <variable id=\"opm1F)[XXt8TnZe.Y`4*\">当前行情</variable>\n    <variable id=\"bwb?U1_yiX:~*3ccn.jt\">当前资产</variable>\n    <variable id=\"fhT;l76])[r2v]cu@PGp\">币总市值</variable>\n    <variable id=\"Y$k.q~c}[N*0Gype+oDd\">资产差</variable>\n  </variables>\n  <block type=\"ext_Loop_Interval\" id=\"2_5}1ZFn9CEx-Ku/nt?1\" x=\"18\" y=\"14\">\n    <statement name=\"INPUT_0\">\n      <block type=\"variables_set\" id=\"(B9Do#l;+D*nzbkOE7ui\">\n        <field name=\"VAR\" id=\"opm1F)[XXt8TnZe.Y`4*\">当前行情</field>\n        <value name=\"VALUE\">\n          <block type=\"ext_exchange_GetTicker\" id=\"ed4pQ5oBu2b7tcmGm;u@\">\n            <field name=\"INPUT_0\">0</field>\n          </block>\n        </value>\n        <next>\n          <block type=\"variables_set\" id=\"(]L|NHCAwCbRY9cG2B)d\">\n            <field name=\"VAR\" id=\"bwb?U1_yiX:~*3ccn.jt\">当前资产</field>\n            <value name=\"VALUE\">\n              <block type=\"ext_exchange_GetAccount\" id=\"K9rAY_hc:KHlI4G.3:%2\">\n                <field name=\"INPUT_0\">0</field>\n              </block>\n            </value>\n            <next>\n              <block type=\"variables_set\" id=\"mzoZW%xi$Yy1rf@ct3TY\">\n                <field name=\"VAR\" id=\"fhT;l76])[r2v]cu@PGp\">币总市值</field>\n                <value name=\"VALUE\">\n                  <block type=\"math_arithmetic\" id=\"i@R^,niuw-Xloo00KLoc\">\n                    <field name=\"OP\">MULTIPLY</field>\n                    <value name=\"A\">\n                      <shadow type=\"math_number\" id=\"atz4^?:~jgWKC+azU11$\">\n                        <field name=\"NUM\">1</field>\n                      </shadow>\n                      <block type=\"ext_TickerOf\" id=\"8*hu;x;u||=Vb#4u|fcP\">\n                        <field name=\"INPUT_0\">Last</field>\n                        <value name=\"INPUT_1\">\n                          <block type=\"variables_get\" id=\"5jiBBlF6c9QiocG|,sBB\">\n                            <field name=\"VAR\" id=\"opm1F)[XXt8TnZe.Y`4*\">当前行情</field>\n                          </block>\n                        </value>\n                      </block>\n                    </value>\n                    <value name=\"B\">\n                      <shadow type=\"math_number\" id=\"RYQCcA!,^sCR0ybqK1UO\">\n                        <field name=\"NUM\">1</field>\n                      </shadow>\n                      <block type=\"ext_AccountOf\" id=\",vWh_Wz3uZ*xcX2=:-($\">\n                        <field name=\"INPUT_0\">Stocks</field>\n                        <value name=\"INPUT_1\">\n                          <block type=\"variables_get\" id=\"5~H0;Fg5wJ|Gt8D1mlCw\">\n                            <field name=\"VAR\" id=\"bwb?U1_yiX:~*3ccn.jt\">当前资产</field>\n                          </block>\n                        </value>\n                      </block>\n                    </value>\n                  </block>\n                </value>\n                <next>\n                  <block type=\"variables_set\" id=\"hbs1DlJ7LsOnyrGY0$hs\">\n                    <field name=\"VAR\" id=\"Y$k.q~c}[N*0Gype+oDd\">资产差</field>\n                    <value name=\"VALUE\">\n                      <block type=\"math_arithmetic\" id=\"lgUPZBFGU-,q5/6^MyIK\">\n                        <field name=\"OP\">MINUS</field>\n                        <value name=\"A\">\n                          <shadow type=\"math_number\" id=\"W[{%5}h:Urd66={r{$}|\">\n                            <field name=\"NUM\">1</field>\n                          </shadow>\n                          <block type=\"variables_get\" id=\"[[]52H*;ugs7VIkOG(KQ\">\n                            <field name=\"VAR\" id=\"fhT;l76])[r2v]cu@PGp\">币总市值</field>\n                          </block>\n                        </value>\n                        <value name=\"B\">\n                          <shadow type=\"math_number\" id=\".)z$~`awZjhy[0jH~w#i\">\n                            <field name=\"NUM\">1</field>\n                          </shadow>\n                          <block type=\"ext_AccountOf\" id=\"L858}xOAg:H5ghqE)r!v\">\n                            <field name=\"INPUT_0\">Balance</field>\n                            <value name=\"INPUT_1\">\n                              <block type=\"variables_get\" id=\"bZ`6[;K?Kcta)yoonA5|\">\n                                <field name=\"VAR\" id=\"bwb?U1_yiX:~*3ccn.jt\">当前资产</field>\n                              </block>\n                            </value>\n                          </block>\n                        </value>\n                      </block>\n                    </value>\n                    <next>\n                      <block type=\"controls_if\" id=\"bHMNS]7^XGv8uIj!7mV)\">\n                        <mutation elseif=\"1\"></mutation>\n                        <value name=\"IF0\">\n                          <block type=\"logic_compare\" id=\"WUX%5bGB@W9]^ZJ7N4Kb\">\n                            <field name=\"OP\">GT</field>\n                            <value name=\"A\">\n                              <block type=\"variables_get\" id=\"A9IuZ8B}BKi+oKj{^b6G\">\n                                <field name=\"VAR\" id=\"Y$k.q~c}[N*0Gype+oDd\">资产差</field>\n                              </block>\n                            </value>\n                            <value name=\"B\">\n                              <block type=\"math_arithmetic\" id=\"*I#f0wAu(bbti|$/s`kY\">\n                                <field name=\"OP\">MULTIPLY</field>\n                                <value name=\"A\">\n                                  <shadow type=\"math_number\" id=\"]?`N@FpK;pbGCNZ%S5rk\">\n                                    <field name=\"NUM\">1</field>\n                                  </shadow>\n                                  <block type=\"ext_AccountOf\" id=\"1k~;0),1`UBe/kS/j7C,\">\n                                    <field name=\"INPUT_0\">Balance</field>\n                                    <value name=\"INPUT_1\">\n                                      <block type=\"variables_get\" id=\"r|-reGD;$7~U^LHk1pEu\">\n                                        <field name=\"VAR\" id=\"bwb?U1_yiX:~*3ccn.jt\">当前资产</field>\n                                      </block>\n                                    </value>\n                                  </block>\n                                </value>\n                                <value name=\"B\">\n                                  <shadow type=\"math_number\" id=\"a1?ZF!cM{Rtt8YnSARLj\">\n                                    <field name=\"NUM\">0.05</field>\n                                  </shadow>\n                                </value>\n                              </block>\n                            </value>\n                          </block>\n                        </value>\n                        <statement name=\"DO0\">\n                          <block type=\"ext_Log\" id=\"Qc}LQw@T6:rtYLoEJZ|A\">\n                            <value name=\"VALUE\">\n                              <block type=\"ext_Trade\" id=\"f+iy@8FMAqP@XhF:SVi8\">\n                                <field name=\"INPUT_0\">Sell</field>\n                                <value name=\"INPUT_1\">\n                                  <shadow type=\"math_number\" id=\"=oOIMb|iB0sbiML8uvkK\">\n                                    <field name=\"NUM\">0</field>\n                                  </shadow>\n                                  <block type=\"ext_N\" id=\"xoLcKwiU,CA%2h~seEAK\">\n                                    <value name=\"INPUT_0\">\n                                      <shadow type=\"math_number\" id=\"h+wbX]Y@{6j|m,}PIn^j\">\n                                        <field name=\"NUM\">0</field>\n                                      </shadow>\n                                      <block type=\"math_arithmetic\" id=\"]`jR7]yP6DWp*u~F[NO,\">\n                                        <field name=\"OP\">DIVIDE</field>\n                                        <value name=\"A\">\n                                          <shadow type=\"math_number\" id=\"yK#HpSy8[o,!#py0Q$U1\">\n                                            <field name=\"NUM\">1</field>\n                                          </shadow>\n                                          <block type=\"math_arithmetic\" id=\"6-H-dlq@R5mP*@6K)eV@\">\n                                            <field name=\"OP\">DIVIDE</field>\n                                            <value name=\"A\">\n                                              <shadow type=\"math_number\" id=\"YK`Se]H~B1-jH,^aWj5p\">\n                                                <field name=\"NUM\">1</field>\n                                              </shadow>\n                                              <block type=\"variables_get\" id=\"1WXx-(Vf_EQ%.4xwdg3q\">\n                                                <field name=\"VAR\" id=\"Y$k.q~c}[N*0Gype+oDd\">资产差</field>\n                                              </block>\n                                            </value>\n                                            <value name=\"B\">\n                                              <shadow type=\"math_number\" id=\"Zcun)[a(E$V9;_z,/7El\">\n                                                <field name=\"NUM\">2</field>\n                                              </shadow>\n                                            </value>\n                                          </block>\n                                        </value>\n                                        <value name=\"B\">\n                                          <shadow type=\"math_number\" id=\"`{h}x:,c$2$:QTYzW.mY\">\n                                            <field name=\"NUM\">1</field>\n                                          </shadow>\n                                          <block type=\"ext_TickerOf\" id=\"Fd{UtGo79IL@5q^@-0a0\">\n                                            <field name=\"INPUT_0\">Buy</field>\n                                            <value name=\"INPUT_1\">\n                                              <block type=\"variables_get\" id=\"OW.tji2|N3N+w)=Tj-RS\">\n                                                <field name=\"VAR\" id=\"opm1F)[XXt8TnZe.Y`4*\">当前行情</field>\n                                              </block>\n                                            </value>\n                                          </block>\n                                        </value>\n                                      </block>\n                                    </value>\n                                    <value name=\"INPUT_1\">\n                                      <shadow type=\"math_number\" id=\"ql+8Lcm3{S#67g):0lB;\">\n                                        <field name=\"NUM\">5</field>\n                                      </shadow>\n                                    </value>\n                                  </block>\n                                </value>\n                              </block>\n                            </value>\n                          </block>\n                        </statement>\n                        <value name=\"IF1\">\n                          <block type=\"logic_compare\" id=\"mNgfW_rMOL!tyVQ9gIO*\">\n                            <field name=\"OP\">LT</field>\n                            <value name=\"A\">\n                              <block type=\"variables_get\" id=\"v?2/Y-X={HtE{ikH:PhQ\">\n                                <field name=\"VAR\" id=\"Y$k.q~c}[N*0Gype+oDd\">资产差</field>\n                              </block>\n                            </value>\n                            <value name=\"B\">\n                              <block type=\"math_arithmetic\" id=\".cSBOTTN9^vs.m/q8WzS\">\n                                <field name=\"OP\">MULTIPLY</field>\n                                <value name=\"A\">\n                                  <shadow type=\"math_number\" id=\"]?`N@FpK;pbGCNZ%S5rk\">\n                                    <field name=\"NUM\">1</field>\n                                  </shadow>\n                                  <block type=\"ext_AccountOf\" id=\"(UZoBKXBcXFu/sF9)~@[\">\n                                    <field name=\"INPUT_0\">Balance</field>\n                                    <value name=\"INPUT_1\">\n                                      <block type=\"variables_get\" id=\"=/Y~8cGTUr5yG2zThwm_\">\n                                        <field name=\"VAR\" id=\"bwb?U1_yiX:~*3ccn.jt\">当前资产</field>\n                                      </block>\n                                    </value>\n                                  </block>\n                                </value>\n                                <value name=\"B\">\n                                  <shadow type=\"math_number\" id=\"SjkKBk?htB}:0OOavFdX\">\n                                    <field name=\"NUM\">-0.05</field>\n                                  </shadow>\n                                </value>\n                              </block>\n                            </value>\n                          </block>\n                        </value>\n                        <statement name=\"DO1\">\n                          <block type=\"ext_Log\" id=\"]6QE+AJuCGJcJ!mM79Aw\">\n                            <value name=\"VALUE\">\n                              <block type=\"ext_Trade\" id=\"0I(RwOKo^!Aa,,U,7bUQ\">\n                                <field name=\"INPUT_0\">Buy</field>\n                                <value name=\"INPUT_1\">\n                                  <shadow type=\"math_number\" id=\"=oOIMb|iB0sbiML8uvkK\">\n                                    <field name=\"NUM\">0</field>\n                                  </shadow>\n                                  <block type=\"ext_N\" id=\"cC/pIj)]o5dZtUXcuWW6\">\n                                    <value name=\"INPUT_0\">\n                                      <shadow type=\"math_number\" id=\"tF7B^Y~~dqljm4j)(ay4\">\n                                        <field name=\"NUM\">0</field>\n                                      </shadow>\n                                      <block type=\"math_arithmetic\" id=\"0%k4hie-y))L1%i/+pm5\">\n                                        <field name=\"OP\">DIVIDE</field>\n                                        <value name=\"A\">\n                                          <shadow type=\"math_number\" id=\"yK#HpSy8[o,!#py0Q$U1\">\n                                            <field name=\"NUM\">1</field>\n                                          </shadow>\n                                          <block type=\"math_arithmetic\" id=\",D]OH)D##:[SL!m.Y=If\">\n                                            <field name=\"OP\">DIVIDE</field>\n                                            <value name=\"A\">\n                                              <shadow type=\"math_number\" id=\"YK`Se]H~B1-jH,^aWj5p\">\n                                                <field name=\"NUM\">1</field>\n                                              </shadow>\n                                              <block type=\"variables_get\" id=\"PYESS@O{0h3*hIQloZs*\">\n                                                <field name=\"VAR\" id=\"Y$k.q~c}[N*0Gype+oDd\">资产差</field>\n                                              </block>\n                                            </value>\n                                            <value name=\"B\">\n                                              <shadow type=\"math_number\" id=\"q1+D-kt.!6b[+.Y43Uu^\">\n                                                <field name=\"NUM\">-2</field>\n                                              </shadow>\n                                            </value>\n                                          </block>\n                                        </value>\n                                        <value name=\"B\">\n                                          <shadow type=\"math_number\" id=\"`{h}x:,c$2$:QTYzW.mY\">\n                                            <field name=\"NUM\">1</field>\n                                          </shadow>\n                                          <block type=\"ext_TickerOf\" id=\"l5Nt[6yf,t,A)g]Y=^P+\">\n                                            <field name=\"INPUT_0\">Sell</field>\n                                            <value name=\"INPUT_1\">\n                                              <block type=\"variables_get\" id=\"%zW)lwo8ZB-[bkM,4fPy\">\n                                                <field name=\"VAR\" id=\"opm1F)[XXt8TnZe.Y`4*\">当前行情</field>\n                                              </block>\n                                            </value>\n                                          </block>\n                                        </value>\n                                      </block>\n                                    </value>\n                                    <value name=\"INPUT_1\">\n                                      <shadow type=\"math_number\" id=\"t|}4L?~Z/Pam|e#tZ9,I\">\n                                        <field name=\"NUM\">5</field>\n                                      </shadow>\n                                    </value>\n                                  </block>\n                                </value>\n                              </block>\n                            </value>\n                          </block>\n                        </statement>\n                      </block>\n                    </next>\n                  </block>\n                </next>\n              </block>\n            </next>\n          </block>\n        </next>\n      </block>\n    </statement>\n    <value name=\"INPUT_1\">\n      <shadow type=\"math_number\" id=\"B!_::#726BEt/6-?!Ui!\">\n        <field name=\"NUM\">1</field>\n      </shadow>\n    </value>\n  </block>\n</xml>","javascript":"/*backtest\nstart: 2023-01-01 00:00:00\nend: 2023-08-16 00:00:00\nperiod: 1d\nbasePeriod: 1h\nexchanges: [{\"eid\":\"Binance\",\"currency\":\"BTC_USDT\"}]\n*/\nfunction main() {\n    var _E5_BD_93_E5_89_8D_E8_A1_8C_E6_83_85, _E5_BD_93_E5_89_8D_E8_B5_84_E4_BA_A7, _E5_B8_81_E6_80_BB_E5_B8_82_E5_80_BC, _E8_B5_84_E4_BA_A7_E5_B7_AE;\n\n\nwhile(true){  _E5_BD_93_E5_89_8D_E8_A1_8C_E6_83_85 = _C(exchanges[0].GetTicker);\n  _E5_BD_93_E5_89_8D_E8_B5_84_E4_BA_A7 = _C(exchanges[0].GetAccount);\n  _E5_B8_81_E6_80_BB_E5_B8_82_E5_80_BC = _E5_BD_93_E5_89_8D_E8_A1_8C_E6_83_85.Last * _E5_BD_93_E5_89_8D_E8_B5_84_E4_BA_A7.Stocks;\n  _E8_B5_84_E4_BA_A7_E5_B7_AE = _E5_B8_81_E6_80_BB_E5_B8_82_E5_80_BC - _E5_BD_93_E5_89_8D_E8_B5_84_E4_BA_A7.Balance;\n  if (_E8_B5_84_E4_BA_A7_E5_B7_AE > _E5_BD_93_E5_89_8D_E8_B5_84_E4_BA_A7.Balance * 0.05) {\n    Log((function(){var r = $.Sell(_N((_E8_B5_84_E4_BA_A7_E5_B7_AE / 2) / _E5_BD_93_E5_89_8D_E8_A1_8C_E6_83_85.Buy, 5)); return r ? r.amount : 0; })());} else if (_E8_B5_84_E4_BA_A7_E5_B7_AE < _E5_BD_93_E5_89_8D_E8_B5_84_E4_BA_A7.Balance * -0.05) {\n    Log((function(){var r = $.Buy(_N((_E8_B5_84_E4_BA_A7_E5_B7_AE / -2) / _E5_BD_93_E5_89_8D_E8_A1_8C_E6_83_85.Sell, 5)); return r ? r.amount : 0; })());}\n\nSleep(1*1000);}\n}"}

Related

More

bamsmen 非常好的功能,准备给学生讲这个,当编程入门了

Nightsky 教孩子学量化也不错, 长大了不当韭菜 这话牛,我就是因为在BITMEX当了一回韭菜才来这的

yaoyaobutao 请尽快补充布林带指标 bb

zhuanqian 描述有点东西,是个狠角色 “- 观察, 教孩子学量化也不错, 长大了不当韭菜"

wula 想问一下这个功能支持期货吗

轻轻的云 介个太好玩了。直接堆积木就行了。O(∩_∩)O

jkyei 谢谢,很好。希望再做个商品期货的。

jacob210 支持,可以让一些策略思维先用可视化实现进行测试,再通过代码来完善

q23250 妙啊!支持!

jkyei 好,开拓性的。可否做出可视化运行在触屏系统的,如能行的话用户数巨大

snowboy good

kmmkk 支持!!

Tbanco 牛逼!

Zero 支持, 商品期货也支持, 可以勾选上内置的交易类库就可以

Zero 这个本来就支持触屏的, 编辑器全屏就可以了