Vancouver Canada
Posts: 3 since Jun 2012
Thanks Given: 0
Thanks Received: 0
|
So I'm building a indicator that needs to check whether a lower high or higher was initiated first on a double switched bar. I was able to get this working for real time data but for the historical data (non real time) I am unable to access the individual ticks (from what I understand).
So i have decided to use a second data stream at a higher resolution (more bars) to determine what was triggered first on the double switch. However, when I compile my code it seems to get the barnumber of the first double switch right so I can simply step back resolution2/resolution1 bars back and see how the price changes to determined what was triggered first. However, it seems to show me the wrong barnumbers for the remaining double switches (it is off by 10 bars when using data1=30 days and data2=6 days). Here is the code I'm currently running. Any help would be greatly appreciated thanks.
//------------------------------------------------------------------------------------ //Double Switch statements (Historical)
if (GetAppInfo(aiRealTimeCalc)= 0) then begin
if ((High of Data1 >= (High [1] of Data1 + HigherHigh)) of Data1 and (Low of Data1 <= (Low[1] of Data1 - LowerLow)) of Data1) then begin // Check if a higher high and lower low are hit on the same bar (double switch)
BarTime = Time of Data1;
PrevTime = Time[1] of Data1;
Resolution2 = barinterval Data2;
Resolution1 = barinterval Data1;
BarCount = Resolution1/Resolution2; ;
D2_Bar = (BarNumber* BarCount);
Print ("D2_Bar: ", D2_Bar);
for x=BarCount downto 1 begin
D2_High = High[x] of Data2;
D2_Low = Low[x] of Data2;
Print ("NewBar: :", (D2_Bar - X));
if ((D2_High>= (High[1] + HigherHigh)) and (D2_Low > (Low[1]- LowerLow) and new_High = False and new_Low = False)) then begin //New High
new_High = True;
RefHigh = High;
Print ("New High: ", D2_High:1:5);
end;
if(D2_Low <= (Low[1] - LowerLow)) and (D2_High < (High[1]+ HigherHigh) and new_Low = False and new_High = False) then begin // New Low
new_Low = True;
RefLow = Low;
Print ("New Low: ", D2_Low:1:5);
end;
//------------------------------------------------------------------------------Double Switch
if ((D2_Low <= (Low[1] - LowerLow) and new_High = True) and newLH=False and newHL= False) then begin //New Low after High
newHL = True;
Print (" New HL: ");
end;
if ( ((D2_High >= (High[1] + HigherHigh))and new_Low = True) and newHL=False and newLH=False) then begin //New High after Low
newLH = True;
Print (" New LH: ");
end;
end;
end;
end;
Also, the code seems to run multiple times for the same bar. It seems as if it runs the same thing for the number of bars from data2 between the current bar of data1 and the previous bar on it.
|