as recommended by TJ I am breaking down my questions from here :
viewtopic.php?f=1&t=51486&p=129617#p129617
1. What I am trying to do: If the Close>HighestBar(Close,48) and RSI(Close,30)>50 then buy. That’s the easy part.
The next condition is a little bit trickier: If the last trade was a winner, then we delay the next entry for x bars. If the last trade was a looser, then we delay the next entry for y bars. I tried to solve that with the positionprofit reserved word.
The next obstacle: the first trade this strategy is going to open, there is no previous trade to refer to?!
Here is the code I came up so far:
Code: Select all
Input:
Waitperiod_(1),
Waitperiod_W(5),
Waitperiod_L(5);
Variable:
EntryCondition(false),
TakeSignal_(false),
TakeSignal_W(false),
TakeSignal_L(false),
MyWaitPeriod_(0),
MyWaitPeriod_W(0),
MyWaitPeriod_L(0),
Last_trade_W(false),
Last_trade_L(false),
x(0);
X=averagetruerange(14)*100000;
EntryCondition= Close>HighestBar(Close,48) and RSI(Close,30)>50;
Last_trade_W= positionprofit(1)>=0;
Last_trade_L=positionprofit(1)<0;
If EntryCondition then
begin MyWaitPeriod_ = WaitPeriod_;
Last_trade_W=false;
Last_trade_L=false;
end;
If EntryCondition then
begin Last_trade_W=true;
Last_trade_L=false;
MyWaitPeriod_W = WaitPeriod_W;
end;
If EntryCondition then
begin Last_trade_L=true;
Last_trade_W=false;
MyWaitPeriod_W = WaitPeriod_W;
end;
If ((Last_trade_W) and (date <> date[1])) then
MyWaitPeriod_W = MyWaitPeriod_W - 1;
If ((Last_trade_L) and (date <> date[1])) then
MyWaitPeriod_L = MyWaitPeriod_L - 1;
Takesignal_= (MyWaitPeriod_ = 0) and (MyWaitPeriod_[1] = 1);
TakeSignal_W = (MyWaitPeriod_W = 0) and (MyWaitPeriod_W[1] = 1);
TakeSignal_L = (MyWaitPeriod_L = 0) and (MyWaitPeriod_L[1] = 1);
If Last_trade_W and TakeSignal_W then buy("LE") next bar at market;
If Last_trade_L and TakeSignal_W then buy("LE_") next bar at market;
setstoploss(X);
setprofittarget(X);