Due to the limitations of the Maic language itself, the strategy had to be re-implemented with JS.
Since the JS re-implementation of the Mac language strategy, many problems have been found, in real-time operation, it is found that the same K line, due to volatility, will return 1-2 times to buy and sell. This leads to a loss.
Ask yourself, how is the language designed to avoid this, what is the general logic?
Or: How can I use JS to prevent buying and selling twice on the same K line? If you want to solve the problem with a time stamp, and find that there is no time stamp in the order, you can use the Date.parse ((new Date))) JS-compliant to solve the problem.
xionglonghuiThere is also a problem, using the code below, is to prevent the same K line from causing a loss due to a bit of fluctuation in the same K line. But there is also a new problem, after the same K line is flat, wanting to immediately counter the hand empty, it is limited, you have to wait until the next K line to open a position. Or after the flat, wanting to counter more on the same K line, also limited, you have to wait until the next K line to start trading, often miss the best buy point. The code is as follows: if (before_record_time!= now_records.Time) // the time of the previous K-line is not equal to the time error of this K-line, then for different K-lines {pos (192,210) } // Write the business logic of the drawdown here, so you can't drawdown the same K line repeatedly. I'm not sure. So my solution is this: the K-line timestamp that used to be a variable store on one of the lines is now a two-variable store. A multi-directional time stamp duo_before_record_time A time of doing blank directions kong_before_record_time So if you want to do more, use this limitation, the same K line, the same position, not the same direction. The code is as follows: if (duo_before_record_time!= now_records.Time) // the time of the previous K-line is not equal to the time error of this K-line, then for different K-lines {pos (192,210) } // Write the business logic of the drawdown here, so you can't drawdown the same K line repeatedly. I'm not sure. When you're doing a blank, you can also limit the number of positions that are not the same in reverse after the same K-line is aligned. if (kong_before_record_time!= now_records.Time) // the time of the previous K-line is not equal to the time error of this K-line. {pos (192,210) } // Write the business logic of the drawdown here, so you can't drawdown the same K line repeatedly. I'm not sure. In this way, the same K line can be opened in the opposite direction immediately after the position is leveled, if the opening conditions are met. I hope that my question will be helpful to my friends later.
The grassThe work order is back to you.
Cool and GoodThe k-axis is time, and should be solved with time.
xionglonghuiThe code is as follows: if (before_record_time!= now_records.Time) // the time of the previous K-line is not equal to the time error of this K-line, then for different K-lines {pos (192,210) } // Write the business logic of the drawdown here, so you can't drawdown the same K line repeatedly. I'm not sure.
xionglonghuiA better solution is to first declare a variable for the current time frame of the latest K-line at the time of each order (whether you do more or less empty open positions, as long as the order is covered by this variable), and then decide that the last time frame of the last open position is not equal to the time frame of the current K-line, which can be solved perfectly.
xionglonghuiBy the way, exchange.GetOrders (().length>0 determines that there are no pending orders and saves the order time.
xionglonghuiAfter a while of groping, I finally found the solution, the code is as follows: if (Math.abs ((before_order_time - now_records.Time)/1000 > now_period)) // The last time subtract the time offset from the current time offset of the K line, divide by 1000 to get the number of seconds, and take the absolute value of the difference between the two, if it is greater than the number of seconds of the cycle, it is not on the same K line. // You need to set the variable before_order_time yourself, save the ordered time stamp each time. before_order_time = Date.parse ((new Date)))); // Record the current time stamp // the number of seconds for the period, is by var now_period = _C ((exchange.GetPeriod); // retrieves the current period, e.g. 5 minutes, 15 minutes, 1 day, and returns the result number of seconds.
Summer won't beat you.It should be possible to intercept by time stamps in the K-line data. Judging if the same time stamp is not ordered is fine.