- 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
BuyStop=Ref(High,-1);
mode1=Ref(Close,-1)<Ref(Open,-1) AND H>Ref(High,-1);
mode2=Ref(Close,-2)<Ref(Open,-2) AND Ref(High,-1)<Ref(High,-2) AND H>Ref(High,-2));
Buy=mode1 OR mode2 ;
BuyPrice=Max(BuyStop,Low);
Sell=MA(C,8)<Close;
Sell=ExRem(Sell,Buy);
Ask yourself the question how the hell you can buy exactly at the extremity (e.g. high or low price) of a bar? Gotta be realistic otherwise you are wasting your time. On top of that the idea will not be profitable.But I have a question, How Can I have Several mode for Buy and Buy Stop in a Code.
Ask yourself the question how the hell you can buy exactly at the extremity (e.g. high or low price) of a bar? Gotta be realistic otherwise you are wasting your time. On top of that the idea will not be profitable.
It is very profitable for me.Because I am learning programming , But it is not profitable for you.Because you know programming.
Regards
I am only a novice, mate. A novice still because price action is always a little bit different than it was before.It is very profitable for me.Because I am learning programming , But it is not profitable for you.Because you know programming.
Regards
IIf function is either true or false according to the expression. If true XAO is the Index, if false XJO is the Index.
Counter = 1;
IXAO = Foreign("XAO", "C");
IXJO = Foreign("XJO", "C");
Index = IIf(Counter, IXAO, IXJO);
Note they are very similar indices.
Well it should not work becuase the return will always be XAO with the statement as I put.Thanks, working now.Thought it was more like the traditional if/then/else style command.
JJZ
Well it should not work becuase the return will always be XAO with the statement as I put.
Really though, what part of index data do you want to optimise for the past?
Hi, could someone guide me to code to be able to reflect stops as follows:
1. The initial stop is just below the last significant trough.
2. Each time the price makes a new high for the trend by rising above
the last peak, the sell stop level for the whole position is trailed up to just
below the last significant confirmed trough
This is shown as per the attached.
View attachment 66146
The idea is taken from Colin Nicholson's book Building Wealth in The Stock Market.
Any help will be appreciated.
Search "scaling into positions", because that's what you're trying to do.
Then use this code by EM Pottasch as a start.
nbar = Param("nbar",5,2,50,1); // number of bars on each side
// define fractals
PHigh = H > Ref(HHV(H,nbar),-1) AND Ref(HHV(H,nbar),nbar) <= H;
PHighPrice = ValueWhen(PHigh,H);
PLow = L < Ref(LLV(L,nbar),-1) AND Ref(LLV(L,nbar),nbar) >= L;
PLowPrice = ValueWhen(PLow,L);
Is there an easy way to adjust a stop based on holding time?
For example, purchase a stock with a 15% stop loss:
ApplyStop( stopTypeLoss, stopModePercent, 15, 2, 0, 0 );
Then after 30 days reduce it to:
ApplyStop( stopTypeLoss, stopModePercent, 10, 2, 0, 0 );
Thanks
JJZ
If you want to tighten things after a certain amount of time, an indicator would be a better option.
SAR tightens up with time. That's its selling point.
Is there an easy way to adjust a stop based on holding time?
For example, purchase a stock with a 15% stop loss:
ApplyStop( stopTypeLoss, stopModePercent, 15, 2, 0, 0 );
Then after 30 days reduce it to:
ApplyStop( stopTypeLoss, stopModePercent, 10, 2, 0, 0 );
Thanks
JJZ
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?