in Search

Auto Zoom

Last post 04-02-2009, 23:31 by wabbit. 16 replies.
Sort Posts: Previous Next
  •  03-06-2005, 0:07 555

    Auto Zoom

    I am trying to write a daily pivot indicator for MetaStock, However, I want the display to auto scale to the price and not the indicator (otherwise the price would be squashed considerably). I mean if the indicator is not in the price range it should not be displayed.
    For example a simple line indicator might be:
    Test :=0;
    Test
    Which will plot a 0 line even of the price is at 10000! I have noticed that if you actually draw a trend line at 0 it will not be shown until it comes within the price range.
    Can anybody help?
    Many thanks
  •  03-07-2005, 15:56 562 in reply to 555

    Re: Auto Zoom

    Hi,

    I would love to try and help you, but I'm really confused as to what you are asking for.
    Would it be possible for you to post a specific example I can look at?

    Thank you
    My Site
  •  03-07-2005, 17:02 564 in reply to 555

    Re: Auto Zoom

    Hi
    Thanks for getting back to me.
    Suppose I am looking at Dow Future. It currently stands at say 10500. The daily pivot indicator calculates the pivots for today based on yesterday prices and they are for example:
    10400
    10502
    10550
    10800
    If I plot the daily pivot indicator on the price chart (Merge with scale on the left “price” to see the relation between the price and the pivot) the display will zoom to at least 10400 to 10800 (pivots) even if the price range in the displayed window is 10490-10510.
    What I really want is the display to show only 10502 pivot as it is the only one within the price range.

    The options:
    1- Display New Scale
    2- Overlay without scale
    Are not suitable, as it would distort the relative relation between the price and the indicator.

    If the above is still confusing please let me know.
    Regards
  •  03-07-2005, 18:38 565 in reply to 555

    Re: Auto Zoom

    What about something like :

    PivotA:={your Formula};
    PivotB:={your Formula};
    PivotC:={your Formula};
    PivotD:={your Formula};
    Min(Abs(C-PivotA),
    Min(Abs(C-PivotB),
    Min(Abs(C-PivotC),Abs(C-PivotD))))

    It might useful to know how you calculate these pivots too, but that might work.
    Let me know.
    My Site
  •  03-07-2005, 20:34 567 in reply to 555

    Re: Auto Zoom

    Hi

    Here is my formula for the pivots:

    Start:=DayOfWeek()<>Ref(DayOfWeek(),-1);
    Hi := ValueWhen(1,Start, Ref(HighestSince(1,Start,H),-1));
    Lo := ValueWhen(1,Start, Ref(LowestSince(1,Start,L),-1));
    Clse := ValueWhen(1,Start, Ref(C,-1));

    Pivot := (Hi+Lo+Clse)/3;
    R1 := 2*Pivot -Lo;
    S1 := 2*Pivot -Hi;
    R2 := Pivot + (Hi-Lo);
    S2 := Pivot - (Hi - Lo);

    Min(Abs(C-Pivot),
    Min(Abs(C-R1),
    Min(Abs(C-S1),
    Min(Abs(C-R2), Abs(C-S2) ))))

    Your code prints the minimum difference to the close and not the actual pivot points (I suppose it can be modified to print the actual pivot). However, it is still display scale independent, I mean, if for example two pivots are within the display window (price), only the one closest to the close will print and not both of them. Also if the nearest pivot is 50 points away, the display will shrinks to show it.
    Regards
  •  03-07-2005, 20:51 569 in reply to 555

    Re: Auto Zoom

    I guess we could do a filter where if Pivot is % greater or lower than price then do not plot it.

    If you want to plot all the pivots values but do not want the chart to be shrunk, I don't think it is possible. And if it is what you want then should just quit here. ( Though someone else might have a solution ... )

    Now if you only want the pivots within a reasonable % of the price we should be able to do something like that.
    My Site
  •  03-07-2005, 21:01 570 in reply to 555

    Re: Auto Zoom

    OK
    Suppose we want to include a filter that only print pivots that are a maximum of 30 points away from the close price how do we do it?(I mean if a pivot is not found within +-30 points of the close, no pivots is printed).
    I did do a code which I can post that does what you suggest but I could not turn off the indicator and had to default to the closest pivot to the close.
  •  03-07-2005, 21:04 571 in reply to 555

    Re: Auto Zoom

    Do you mind posting that code?

    I will take a look at it and see what I can do.

    Thanks
    My Site
  •  03-07-2005, 21:52 572 in reply to 555

    Re: Auto Zoom

    Here is my code:

    Period := Input("Period " ,2 ,150 ,60 );
    Distance := Input("Distance " ,5 ,100 ,30 );

    Start:= DayOfWeek()<>Ref(DayOfWeek(),-1);
    Hi := ValueWhen(1,Start, Ref(HighestSince(1,Start,H),-1));
    Lo := ValueWhen(1,Start, Ref(LowestSince(1,Start,L),-1));
    Clse := ValueWhen(1,Start,Ref(C,-1));

    Pivot := (Hi+Lo+Clse)/3;
    R1 := 2*Pivot -Lo;
    S1 := 2*Pivot -Hi;
    R2 := Pivot + (Hi-Lo);
    S2 := Pivot - (Hi - Lo);

    HiPeriod := HHV(H,Period)+Distance;
    LoPeriod := LLV(L,Period)-Distance;
    Default :=
    If(R1<HiPeriod AND R1>LoPeriod,R1,
    If(R2<HiPeriod AND R2>LoPeriod,R2,
    If(S1<HiPeriod AND S1>LoPeriod,S1,
    If(S2<HiPeriod AND S2>LoPeriod,S2, Pivot
    )
    )
    )
    );

    HiPeriod := HiPeriod-Distance;
    LoPeriod := LoPeriod+Distance;

    If(Abs(Pivot- HiPeriod)<Distance,Pivot,Default);
    If(Abs(R1- HiPeriod)<Distance OR Abs(R1- LoPeriod)<Distance,R1,Default);
    If(Abs(R2- HiPeriod)<Distance OR Abs(R2- LoPeriod)<Distance,R2,Default);
    If(Abs(S1- HiPeriod)<Distance OR Abs(S1- LoPeriod)<Distance,S1 ,Default);
    If(Abs(S2- HiPeriod)<Distance OR Abs(S2- LoPeriod)<Distance,S2 ,Default);

    It is a bit more complicated. Since I do not know what is the current display price range is I ask for a loopback period (variable Period). And I try to find at least a pivot within that range to use as default, If I do not find any and since I can not turn the indicator off I have chosen Pivot as my default value.
    The above code is by no means elegant. It is much better to see what is the range of prices currently being displayed and show only relevant pivots.
    Disadvantages of the above code so far are:
    1- The default pivot could be far off from the current price if the price has been rising or falling significantly compare to yesterday range.
    2- As the price moves, the default pivot position might change and you could see lines joining the Pivots gone out of range to the default value.
    3- Any other things that you might come up or I can not remember now!
  •  03-07-2005, 22:29 573 in reply to 555

    Re: Auto Zoom

    Also, is there any command or external program allowing Metastock to replay tick data (like Sierra charts or trade station)?
    I need that to practice my realtime chart reading skill.
  •  03-08-2005, 17:47 583 in reply to 555

    Re: Auto Zoom

    This formula here is the same as the one you posted :
    ( Just less confusing and it will be easier to fix this one )

    Pivot :=(Ref(H,-1)+Ref(L,-1)+Ref(C,-1))/3;
    R1:=2*Pivot-Ref(L,-1);
    S1:=2*Pivot-Ref(H,-1);
    R2:=Pivot+(Ref(H,-1)-Ref(L,-1));
    S2:=Pivot-(Ref(H,-1)-Ref(L,-1));
    R1;S1;R2;S2;Pivot

    I unfortunately have to go right now but I will try to give an answer on this by the end of the day.

    Patrick
    My Site
  •  03-08-2005, 17:57 584 in reply to 555

    Re: Auto Zoom

    Hi Patrick
    Perhaps I did not explain this but, I look at intraday data i.e. 3 or 5 minutes charts (day trading) and not dailys. The pivots are calculated based on the previous day Hi, Low and Close. Perhaps that’s why it become complicated.
  •  03-08-2005, 21:32 587 in reply to 555

    Re: Auto Zoom

    Ah I see, now I feel extra dumb :lol:

    In any case, let see what we can do :)
    My Site
  •  03-08-2005, 22:07 588 in reply to 555

    Re: Auto Zoom

    Alright, hopefully I'm not making a fool of myself again ...
    I don't have realtime here at homeso I could not test it but I believe this should work or something similar.

    Period:=Input("Period",2,150,60);
    Distance:=Input("Distance",5,100,30);
    Start:= DayOfWeek()<>Ref(DayOfWeek(),-1);
    Hi:=ValueWhen(1,Start,Ref(HighestSince(1,Start,H),-1));
    Lo:=ValueWhen(1,Start,Ref(LowestSince(1,Start,L),-1));
    Clse:=ValueWhen(1,Start,Ref(C,-1));
    Pivot:=(Hi+Lo+Clse)/3;
    R1 := 2*Pivot -Lo;
    S1 := 2*Pivot -Hi;
    R2 := Pivot + (Hi-Lo);
    S2 := Pivot - (Hi - Lo);
    HiPeriod:=HHV(H,Period)+Distance;
    LoPeriod:=LLV(L,Period)-Distance;
    R1Fix:=ValueWhen(1,R1>=LoPeriod AND R1<=hiPeriod AND Cum(1)>=LastValue(Cum(1))-period,LastValue(R1));
    R2Fix:=ValueWhen(1,R2>=LoPeriod AND R2<=hiPeriod AND Cum(1)>=LastValue(Cum(1))-period,LastValue(R2));
    S1Fix:=ValueWhen(1,S1>=LoPeriod AND S1<=hiPeriod AND Cum(1)>=LastValue(Cum(1))-period,LastValue(S1));
    S2Fix:=ValueWhen(1,S2>=LoPeriod AND S2<=hiPeriod AND Cum(1)>=LastValue(Cum(1))-period,LastValue(S2));
    PivotFix:=ValueWhen(1,Pivot>=LoPeriod AND Pivot<=hiPeriod AND Cum(1)>=LastValue(Cum(1))-period,LastValue(Pivot));
    R1Fix;
    R2Fix;
    S1Fix;
    S2Fix;
    PivotFix;

    Let me know what you think.
    My Site
  •  03-09-2005, 22:34 601 in reply to 555

    Re: Auto Zoom

    Hi Patrick
    Sorry I could not get back to you before, as I am travelling now and don't have an access to my computer, I will let you know next week. First impression, it seems that it displays the pivot for the current day only, we might have to modify it to work on all days to test strategies and etc.
    Jhon
  •  03-31-2009, 23:15 29321 in reply to 555

    Re: Auto Zoom

    I am trying to do the exact same thing, and having the exact same problem.

    How I get an indicator to behave like a trendline and not re-scale the y axis?

  •  04-02-2009, 23:31 29335 in reply to 29321

    Re: Auto Zoom

    Answered at http://forum.equis.com/forums/29334/ShowThread.aspx#29334


    wabbit Big Smile [:D]


    "The question of whether a computer can think is no more interesting than the question of whether a submarine can swim."
    Edsgar W. Dijkstra

     

    MS: 6.52 EOD, 7.x EOD, 8.0 PRO, 9.2 PRO w/QC, 10 PRO w/QC C, 11 PRO w/QC & MDK
    For custom MetaStock programming : http://www.wabbit.com.au
    My SkyPE status :
    My SkyPE account : wabbit.com.au

View as RSS news feed in XML