And the VBA script for anyone thats interested in it
LR = .Range("B" & Rows.Count).End(xlUp).Row For i = 2 To LR If .Range("B" & i).Value > 0 Then Set CellRef = .Range("B" & i) Else Set CellRef = .Range("Z4667") If Not Application.Intersect(DateRange, CellRef) Is Nothing Then iSect = True Else iSect = False If iSect = True Then Set avgRange = .Range("J" & (i - 1) & ":" & "J" & (i - 6)) If iSect = True Then CellRef.Offset(0, 9) = WorksheetFunction.Sum(avgRange) / 5 If iSect = True And CellRef.Offset(0, 8) > (CellRef.Offset(0, 9).Value * 1.3) Then CellRef.Offset(0, 9) = "LONG" Else _ If iSect = True And CellRef.Offset(0, 8) < (CellRef.Offset(0, 9).Value * 0.5) Then CellRef.Offset(0, 9) = "SHORT" Else _ If iSect = True Then CellRef.Offset(0, 9) = "VANILLA" Next i End With
SteepCurve: The labels work but the calculations are off. |
|
Apologies, the post has been updated. It was quite late here and had been a long day in the lab.
ResgisterPattern sends the outcome to the labeling function. I have created a similar fragment which labels the bars Bear or Bull (more as an excercise than anything actually useful) and it works as expected. The above script is based off of the Bear/Bull script
This question comes down to my inability to write a loop for a moving average in general.
The loop loops. The values are recaulculated at every loop. The loop is stepped by start(). I just have no idea what bar values the loop is actually using.
So after adding some print statements to find what time and prices the loop is using, it appears to only be looping through the most recent 5 bars. As all bars in the chart have been labelled I can only guess it is comparing all bars in the history to the average of the most recent 5 bars.
What is missing to make it look back through all bars?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
The following snipett is meant to label bars as either "LONG" or "SHORT" when thier length is compared against a moving average of the previous 5 bars bodies. The labels work but the calculations are off.
I have got this to work in excel/vba though it is not much good to me there.
It should be obvious from this diagram that the bars are being mislabelled. If avgPERIOD period is output to print at each bar the value is being updated. Though I'm just not sure what values it is being updated with