Delayed Entry after Looser/ Winner trade

Questions about MultiCharts and user contributed studies.
Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Delayed Entry after Looser/ Winner trade

Postby Jonny473 » 22 Jun 2018

Hi,

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);
Last edited by Jonny473 on 22 Jun 2018, edited 1 time in total.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Delayed Entry after Looser/ Winner trade

Postby TJ » 22 Jun 2018

See posts #1 & #2
viewtopic.php?t=11713

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Delayed Entry after Looser/ Winner trade

Postby Jonny473 » 22 Jun 2018

8) :!:


Return to “MultiCharts”