Loading ...

收盘价与均线策略(商品期货)

Author: Hukybo, Date: 2019-03-01 10:03:11
Tags:

策略逻辑: 多头开仓:如果当前没有仓位,并且收盘价大于50周期均线。 空头开仓:如果当前没有仓位,并且收盘价小于50周期均线。 多头平仓:如果当前持有多单,并且收盘价小于50周期均线。 空头平仓:如果当前持有空单,并且收盘价大于50周期均线。


{"xml":"<xml xmlns=\"http://www.w3.org/1999/xhtml\">\n  <variables>\n    <variable type=\"\" id=\"0Q~pTJN*sTC5tv;gCm/s\">K线数组</variable>\n    <variable type=\"\" id=\"DR*XaHrqE%2X))-_.:0S\">上根K线的50周期均值</variable>\n    <variable type=\"\" id=\"f;?Rgg#c%[:(#=x7]i?.\">长根K线的收盘价</variable>\n    <variable type=\"\" id=\":FQBK~[Wm:[.PehYwmUM\">持仓数组</variable>\n  </variables>\n  <block type=\"ext_exchange_SetContractType\" id=\"9-lAK=wwaJ0b+#FPS6Hh\" x=\"2226\" y=\"-692\">\n    <field name=\"INPUT_0\">0</field>\n    <value name=\"INPUT_1\">\n      <shadow type=\"text\" id=\"]}1Vlo/QGDeRM#k[e9#v\">\n        <field name=\"TEXT\">rb000</field>\n      </shadow>\n    </value>\n    <next>\n      <block type=\"ext_Loop_Interval\" id=\"3[wi=rhu}ivT+!@K6Y8P\">\n        <statement name=\"INPUT_0\">\n          <block type=\"variables_set\" id=\"~/]JlPfOi}ux:Dyy}D)a\">\n            <field name=\"VAR\" id=\"0Q~pTJN*sTC5tv;gCm/s\" variabletype=\"\">K线数组</field>\n            <value name=\"VALUE\">\n              <block type=\"ext_exchange_GetRecords\" id=\"oUCqs7vQ:El*33o{JSfQ\">\n                <field name=\"INPUT_0\">0</field>\n              </block>\n            </value>\n            <next>\n              <block type=\"ext_Log\" id=\"R5Pj:9b1R6_ilUAH,?[2\">\n                <value name=\"VALUE\">\n                  <block type=\"variables_get\" id=\"ta}pi^/6IgQ[S$Lq.^e0\">\n                    <field name=\"VAR\" id=\"0Q~pTJN*sTC5tv;gCm/s\" variabletype=\"\">K线数组</field>\n                  </block>\n                </value>\n                <next>\n                  <block type=\"variables_set\" id=\"^xc:$D|l?z!6Ucns!Ql~\">\n                    <field name=\"VAR\" id=\"DR*XaHrqE%2X))-_.:0S\" variabletype=\"\">上根K线的50周期均值</field>\n                    <value name=\"VALUE\">\n                      <block type=\"lists_getIndex\" id=\"`IuU94#GZFlctf~HWSB}\">\n                        <mutation statement=\"false\" at=\"true\"></mutation>\n                        <field name=\"MODE\">GET</field>\n                        <field name=\"WHERE\">FROM_END</field>\n                        <value name=\"VALUE\">\n                          <block type=\"indicator_EMA\" id=\"~agy9wIPlk(|SMY+@Y*{\">\n                            <value name=\"INPUT_0\">\n                              <block type=\"ext_exchange_GetRecords\" id=\"z!@/=N#3Sq-th]EFvHhd\">\n                                <field name=\"INPUT_0\">0</field>\n                              </block>\n                            </value>\n                            <value name=\"INPUT_1\">\n                              <shadow type=\"math_number\" id=\"xJhirOz,cadpq2c?=bC~\">\n                                <field name=\"NUM\">50</field>\n                              </shadow>\n                            </value>\n                          </block>\n                        </value>\n                        <value name=\"AT\">\n                          <block type=\"math_number\" id=\"{BQ8u-VQc;]#ca;d|tvl\">\n                            <field name=\"NUM\">2</field>\n                          </block>\n                        </value>\n                      </block>\n                    </value>\n                    <next>\n                      <block type=\"variables_set\" id=\"s68FQ/;Tp!$=V3h$}LrF\">\n                        <field name=\"VAR\" id=\"f;?Rgg#c%[:(#=x7]i?.\" variabletype=\"\">长根K线的收盘价</field>\n                        <value name=\"VALUE\">\n                          <block type=\"ext_RecordOf\" id=\"z,$OJo3C+/d*;8vlP51:\">\n                            <field name=\"INPUT_2\">Close</field>\n                            <value name=\"INPUT_0\">\n                              <block type=\"ext_exchange_GetRecords\" id=\"_s]y;Tja-jd5qhfwh@8z\">\n                                <field name=\"INPUT_0\">0</field>\n                              </block>\n                            </value>\n                            <value name=\"INPUT_1\">\n                              <shadow type=\"math_number\" id=\"FR8~zGHDaXsk}Q*xR$7`\">\n                                <field name=\"NUM\">0</field>\n                              </shadow>\n                              <block type=\"math_arithmetic\" id=\"4D(`!cUgZUvXnY8=D`%U\">\n                                <field name=\"OP\">MINUS</field>\n                                <value name=\"A\">\n                                  <shadow type=\"math_number\" id=\"(~eQU8wB_t/jxs39Kj4w\">\n                                    <field name=\"NUM\">1</field>\n                                  </shadow>\n                                  <block type=\"lists_length\" id=\"KIWHB[D9N^2mVAhd+[XO\">\n                                    <value name=\"VALUE\">\n                                      <block type=\"variables_get\" id=\"{zc#1VvN~(9Th]}v~WyO\">\n                                        <field name=\"VAR\" id=\"0Q~pTJN*sTC5tv;gCm/s\" variabletype=\"\">K线数组</field>\n                                      </block>\n                                    </value>\n                                  </block>\n                                </value>\n                                <value name=\"B\">\n                                  <shadow type=\"math_number\" id=\"dxxS9Ib{(8r0x]}h*]2^\">\n                                    <field name=\"NUM\">2</field>\n                                  </shadow>\n                                </value>\n                              </block>\n                            </value>\n                          </block>\n                        </value>\n                        <next>\n                          <block type=\"variables_set\" id=\"vN4c9rach|_cg~1;-JFv\">\n                            <field name=\"VAR\" id=\":FQBK~[Wm:[.PehYwmUM\" variabletype=\"\">持仓数组</field>\n                            <value name=\"VALUE\">\n                              <block type=\"ext_exchange_GetPosition\" id=\"U2KW,3lB?*H;=j{?yTrL\">\n                                <field name=\"INPUT_0\">0</field>\n                              </block>\n                            </value>\n                            <next>\n                              <block type=\"controls_if\" id=\"Wq8+iVtFhLg2MnkU:qcE\">\n                                <mutation else=\"1\"></mutation>\n                                <value name=\"IF0\">\n                                  <block type=\"logic_compare\" id=\",-Bt9vV=Mm5jaI)4Y7/P\">\n                                    <field name=\"OP\">EQ</field>\n                                    <value name=\"A\">\n                                      <block type=\"lists_length\" id=\"`6t,}[kGuE44#=kb}l|y\">\n                                        <value name=\"VALUE\">\n                                          <block type=\"variables_get\" id=\"Ca-{O`w5k#e$)Igbfr/=\">\n                                            <field name=\"VAR\" id=\":FQBK~[Wm:[.PehYwmUM\" variabletype=\"\">持仓数组</field>\n                                          </block>\n                                        </value>\n                                      </block>\n                                    </value>\n                                    <value name=\"B\">\n                                      <block type=\"math_number\" id=\"v!qNPkoN[w5s$s/iq8mA\">\n                                        <field name=\"NUM\">0</field>\n                                      </block>\n                                    </value>\n                                  </block>\n                                </value>\n                                <statement name=\"DO0\">\n                                  <block type=\"controls_if\" id=\":3?eNhuoR/=fHAA~x%d@\">\n                                    <mutation elseif=\"1\"></mutation>\n                                    <value name=\"IF0\">\n                                      <block type=\"logic_compare\" id=\"#(R$6$t#QtsRZ3HorRx%\">\n                                        <field name=\"OP\">GT</field>\n                                        <value name=\"A\">\n                                          <block type=\"variables_get\" id=\"TW7pZl#kZk`38Lul!LqD\">\n                                            <field name=\"VAR\" id=\"f;?Rgg#c%[:(#=x7]i?.\" variabletype=\"\">长根K线的收盘价</field>\n                                          </block>\n                                        </value>\n                                        <value name=\"B\">\n                                          <block type=\"variables_get\" id=\"5rb{={ID.oweL^`w(;qL\">\n                                            <field name=\"VAR\" id=\"DR*XaHrqE%2X))-_.:0S\" variabletype=\"\">上根K线的50周期均值</field>\n                                          </block>\n                                        </value>\n                                      </block>\n                                    </value>\n                                    <statement name=\"DO0\">\n                                      <block type=\"ext_CTP_Trade\" id=\":?I(8i`JenEW][CZ$2n!\">\n                                        <field name=\"INPUT_0\">OpenLong</field>\n                                        <value name=\"INPUT_1\">\n                                          <shadow type=\"text\" id=\"17I`lvcYoold!aQ~@-du\">\n                                            <field name=\"TEXT\">rb000</field>\n                                          </shadow>\n                                        </value>\n                                        <value name=\"INPUT_2\">\n                                          <shadow type=\"math_number\" id=\"YBz9ujy^?2,/,b?IAT7E\">\n                                            <field name=\"NUM\">1</field>\n                                          </shadow>\n                                        </value>\n                                      </block>\n                                    </statement>\n                                    <value name=\"IF1\">\n                                      <block type=\"logic_compare\" id=\"C$e7`Ng[0+t,6H1bX!O%\">\n                                        <field name=\"OP\">LT</field>\n                                        <value name=\"A\">\n                                          <block type=\"variables_get\" id=\"8cOeR6Cq-u_r.M,{#E2Y\">\n                                            <field name=\"VAR\" id=\"f;?Rgg#c%[:(#=x7]i?.\" variabletype=\"\">长根K线的收盘价</field>\n                                          </block>\n                                        </value>\n                                        <value name=\"B\">\n                                          <block type=\"variables_get\" id=\"Xt=M:EX/f(xi~fzCAqyo\">\n                                            <field name=\"VAR\" id=\"DR*XaHrqE%2X))-_.:0S\" variabletype=\"\">上根K线的50周期均值</field>\n                                          </block>\n                                        </value>\n                                      </block>\n                                    </value>\n                                    <statement name=\"DO1\">\n                                      <block type=\"ext_CTP_Trade\" id=\"K*V^iGI))`b]$s6F/Xr#\">\n                                        <field name=\"INPUT_0\">OpenShort</field>\n                                        <value name=\"INPUT_1\">\n                                          <shadow type=\"text\" id=\"rmOQ4nThl5:HT3v~,UDI\">\n                                            <field name=\"TEXT\">rb000</field>\n                                          </shadow>\n                                        </value>\n                                        <value name=\"INPUT_2\">\n                                          <shadow type=\"math_number\" id=\"e{@/jcy+)+4gdJv}oUab\">\n                                            <field name=\"NUM\">1</field>\n                                          </shadow>\n                                        </value>\n                                      </block>\n                                    </statement>\n                                  </block>\n                                </statement>\n                                <statement name=\"ELSE\">\n                                  <block type=\"controls_if\" id=\"~F`n^.wEJS6*xEg%lGP-\">\n                                    <mutation else=\"1\"></mutation>\n                                    <value name=\"IF0\">\n                                      <block type=\"math_number_property\" id=\")9=tvaiXazCae:|LR7]2\">\n                                        <mutation divisor_input=\"false\"></mutation>\n                                        <field name=\"PROPERTY\">EVEN</field>\n                                        <value name=\"NUMBER_TO_CHECK\">\n                                          <shadow type=\"math_number\" id=\"Z%m@lYRA]dnm+w#DDJ)^\">\n                                            <field name=\"NUM\">0</field>\n                                          </shadow>\n                                          <block type=\"ext_PositionOf\" id=\"jucjg1-$L/yG6]t|IJ!n\">\n                                            <field name=\"INPUT_2\">Type</field>\n                                            <value name=\"INPUT_0\">\n                                              <block type=\"ext_exchange_GetPosition\" id=\"f_WZKK`1qkLA/Y=4n/in\">\n                                                <field name=\"INPUT_0\">0</field>\n                                              </block>\n                                            </value>\n                                            <value name=\"INPUT_1\">\n                                              <shadow type=\"math_number\" id=\"UKv5!jo-n/Sfy{]hx3-J\">\n                                                <field name=\"NUM\">0</field>\n                                              </shadow>\n                                            </value>\n                                          </block>\n                                        </value>\n                                      </block>\n                                    </value>\n                                    <statement name=\"DO0\">\n                                      <block type=\"controls_if\" id=\"JjGWqk%Pw+81}Q{hp[j(\">\n                                        <value name=\"IF0\">\n                                          <block type=\"logic_compare\" id=\"-S|Tj^j~wfUI_[TlS7`i\">\n                                            <field name=\"OP\">LT</field>\n                                            <value name=\"A\">\n                                              <block type=\"variables_get\" id=\"|S%`0V_$w:M(nz{@n6]c\">\n                                                <field name=\"VAR\" id=\"f;?Rgg#c%[:(#=x7]i?.\" variabletype=\"\">长根K线的收盘价</field>\n                                              </block>\n                                            </value>\n                                            <value name=\"B\">\n                                              <block type=\"variables_get\" id=\"I#iJzMzQ{lLG?jj#Zd/^\">\n                                                <field name=\"VAR\" id=\"DR*XaHrqE%2X))-_.:0S\" variabletype=\"\">上根K线的50周期均值</field>\n                                              </block>\n                                            </value>\n                                          </block>\n                                        </value>\n                                        <statement name=\"DO0\">\n                                          <block type=\"ext_CTP_CoverAll\" id=\"aC^.{%uHh,A=t8T}D(.T\"></block>\n                                        </statement>\n                                      </block>\n                                    </statement>\n                                    <statement name=\"ELSE\">\n                                      <block type=\"controls_if\" id=\"U+1~D;4W[jAKB~M?Qf72\">\n                                        <value name=\"IF0\">\n                                          <block type=\"logic_compare\" id=\"..fVo?jBj/C[9%Zc_P+#\">\n                                            <field name=\"OP\">GT</field>\n                                            <value name=\"A\">\n                                              <block type=\"variables_get\" id=\"l$__RPg@Ic?zwA5*,b|1\">\n                                                <field name=\"VAR\" id=\"f;?Rgg#c%[:(#=x7]i?.\" variabletype=\"\">长根K线的收盘价</field>\n                                              </block>\n                                            </value>\n                                            <value name=\"B\">\n                                              <block type=\"variables_get\" id=\")Lx+U^y@9n95~T!:8wWi\">\n                                                <field name=\"VAR\" id=\"DR*XaHrqE%2X))-_.:0S\" variabletype=\"\">上根K线的50周期均值</field>\n                                              </block>\n                                            </value>\n                                          </block>\n                                        </value>\n                                        <statement name=\"DO0\">\n                                          <block type=\"ext_CTP_CoverAll\" id=\"K)S5dQM@XYN(obPo*nxW\"></block>\n                                        </statement>\n                                      </block>\n                                    </statement>\n                                  </block>\n                                </statement>\n                              </block>\n                            </next>\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=\"%Ri?*x3*e[h(7=4*6X8+\">\n            <field name=\"NUM\">1</field>\n          </shadow>\n        </value>\n      </block>\n    </next>\n  </block>\n</xml>","javascript":"function main() {\n    var K_E7_BA_BF_E6_95_B0_E7_BB_84, _E4_B8_8A_E6_A0_B9K_E7_BA_BF_E7_9A_8450_E5_91_A8_E6_9C_9F_E5_9D_87_E5_80_BC, _E9_95_BF_E6_A0_B9K_E7_BA_BF_E7_9A_84_E6_94_B6_E7_9B_98_E4_BB_B7, _E6_8C_81_E4_BB_93_E6_95_B0_E7_BB_84;\n\n\n    exchanges[0].SetContractType('rb000');\n    while (true) {\n        K_E7_BA_BF_E6_95_B0_E7_BB_84 = _C(exchanges[0].GetRecords);\n        Log(K_E7_BA_BF_E6_95_B0_E7_BB_84);\n        _E4_B8_8A_E6_A0_B9K_E7_BA_BF_E7_9A_8450_E5_91_A8_E6_9C_9F_E5_9D_87_E5_80_BC = TA.EMA(_C(exchanges[0].GetRecords), 50).slice(-2)[0];\n        _E9_95_BF_E6_A0_B9K_E7_BA_BF_E7_9A_84_E6_94_B6_E7_9B_98_E4_BB_B7 = _C(exchanges[0].GetRecords)[K_E7_BA_BF_E6_95_B0_E7_BB_84.length - 2].Close;\n        _E6_8C_81_E4_BB_93_E6_95_B0_E7_BB_84 = _C(exchanges[0].GetPosition);\n        if (_E6_8C_81_E4_BB_93_E6_95_B0_E7_BB_84.length == 0) {\n            if (_E9_95_BF_E6_A0_B9K_E7_BA_BF_E7_9A_84_E6_94_B6_E7_9B_98_E4_BB_B7 > _E4_B8_8A_E6_A0_B9K_E7_BA_BF_E7_9A_8450_E5_91_A8_E6_9C_9F_E5_9D_87_E5_80_BC) {\n                $.Util.OpenLong('rb000', 1);\n            } else if (_E9_95_BF_E6_A0_B9K_E7_BA_BF_E7_9A_84_E6_94_B6_E7_9B_98_E4_BB_B7 < _E4_B8_8A_E6_A0_B9K_E7_BA_BF_E7_9A_8450_E5_91_A8_E6_9C_9F_E5_9D_87_E5_80_BC) {\n                $.Util.OpenShort('rb000', 1);\n            }\n        } else {\n            if (_C(exchanges[0].GetPosition)[0].Type % 2 == 0) {\n                if (_E9_95_BF_E6_A0_B9K_E7_BA_BF_E7_9A_84_E6_94_B6_E7_9B_98_E4_BB_B7 < _E4_B8_8A_E6_A0_B9K_E7_BA_BF_E7_9A_8450_E5_91_A8_E6_9C_9F_E5_9D_87_E5_80_BC) {\n                    $.Util.CoverAll();\n                }\n            } else {\n                if (_E9_95_BF_E6_A0_B9K_E7_BA_BF_E7_9A_84_E6_94_B6_E7_9B_98_E4_BB_B7 > _E4_B8_8A_E6_A0_B9K_E7_BA_BF_E7_9A_8450_E5_91_A8_E6_9C_9F_E5_9D_87_E5_80_BC) {\n                    $.Util.CoverAll();\n                }\n            }\n        }\n\n        Sleep(1 * 1000);\n    }\n}"}

More