- Joined
- 13 June 2007
- Posts
- 838
- Reactions
- 136
Hi to all
I am writing a code .
but ,
I don't know , why my Code for Buy Stop order only work for 1 Day after and dont work for 2 Days or 3Day after,...
if you know my problem, please help me.
Thank you
Code:BuyStop = Ref(HHV(High,1),-1); Buy=Ref(Close,-1)<Ref(Open,-1) AND Cross(High,BuyStop); BuyPrice=Max(BuyStop,Low); Sell = MA(C,5)<Close; Sell=ExRem(Sell,Buy);
View attachment 66117
Greetings --
The first line sets the BuyStop as the highest high for the 1 day period, as of yesterday. If that logic is what you intended, you do not need the HHV function and it would be more straight-forward to write:
BuyStop = Ref(H,-1);
The second line computes the Buy signal.
Buy is set to True when two conditions are both met on the same bar:
1. Yesterday's close is below yesterday's open.
2. Today's High is greater then BuyStop, but it was not yesterday.
Alternative code for rule 2, given the code posted, is:
2. H > Ref(H,-1);
The problem may be in the first line -- BuyStop is reset every day when you intended to have it retain its value for a longer period.
Best,
Howard