Stop trading for consecutive loss

Questions about MultiCharts and user contributed studies.
User avatar
johnmok
Posts: 85
Joined: 18 Oct 2011
Has thanked: 30 times
Been thanked: 8 times

Stop trading for consecutive loss

Postby johnmok » 12 Mar 2020

Hi all,

with reference to these two topics;

viewtopic.php?t=8243

viewtopic.php?f=5&t=8215

i also want to set a simple counter to stop system from trading for two consecutive loses intraday until the next trading day, using the following code

Code: Select all

[IntrabarOrderGeneration = false] var: LossCount(0); if marketposition = 0 and marketposition[1] <> 0 and positionprofit(1) < 0 then LossCount = LossCount + 1; if LossCount < 2 then begin {Trading signals.....} end; if date <> date[1] then LossCount = 0;
but the results is totally unsatisfying. the trading signal just keep trading and completely ignore my control code.

any idea what's wrong with my code? thank you!

User avatar
Svetlana MultiCharts
Posts: 645
Joined: 19 Oct 2017
Has thanked: 3 times
Been thanked: 163 times

Re: Stop trading for consecutive loss

Postby Svetlana MultiCharts » 16 Mar 2020

Hello johnmok,

Please try to replace square brackets with round brackets:
marketposition[1] ... marketposition(1)

User avatar
johnmok
Posts: 85
Joined: 18 Oct 2011
Has thanked: 30 times
Been thanked: 8 times

Re: Stop trading for consecutive loss

Postby johnmok » 18 Mar 2020

Hello johnmok,

Please try to replace square brackets with round brackets:
marketposition[1] ... marketposition(1)
i have tried replacing the brackets, it works, but only works for one time. when it stops, it stop forever.

as far as i knows, changing bracket from [ ] to ( ) would means returning value of last closing position rather than the value of last bar, so that the counter can't be reset to zero according to my code.

when loss trades = 2, no matter how many days or bars advanced, the counters will just keep adding up to 2 in 2 bars, as it checks marketposition(1) and positionprofit(1) every bar.

that's why i use marketposition[1] instead of marketposition(1)

i want to do the checking only right after each position close(i.e. one bar back) rather than checking last closing position every bar so that the loss counter keep adding every bar.

thanks Svetlana, hope you can provide more insights for me, thank you so much.

User avatar
johnmok
Posts: 85
Joined: 18 Oct 2011
Has thanked: 30 times
Been thanked: 8 times

Re: Stop trading for consecutive loss

Postby johnmok » 18 Mar 2020

i have change the cade from

Code: Select all

if marketposition = 0 and marketposition[1] <> 0 and positionprofit(1) < 0 then
to

Code: Select all

if marketposition = 0 and marketposition(1) <> 0 and positionprofit(1) < 0 and entrydate(1) = date then
seems can make the counter reset again after date change, solved part of the problems....but still kind of weird.

i have multiple entries for each trade, but it seems stop trading for 2 single loss rather than stop trading for 2 trades(i.e. trade with multiple entries but win as a whole should not be count as loss...)

User avatar
Svetlana MultiCharts
Posts: 645
Joined: 19 Oct 2017
Has thanked: 3 times
Been thanked: 163 times

Re: Stop trading for consecutive loss

Postby Svetlana MultiCharts » 01 May 2020

Hello johnmok,

You can try the following code as an option

Code: Select all

inputs: LECondition( C > O ) ; inputs: SECondition( C < O ) ; var: trade_on(true); var: date_trade(""); date_trade = datetostring(date); if (positionprofit(1) < 0 and positionprofit(2) < 0) and ( datetostring(PosTradeEntryDateTime(1, 0)) = datetostring(PosTradeEntryDateTime(2, 0)) ) then begin print( " ", positionprofit(1), " ", positionprofit(2), " ", datetostring(PosTradeEntryDateTime(2, 0)), " ", datetostring(PosTradeEntryDateTime(1, 0)) ); trade_on = false; Print(" false ", currentbar + maxbarsback); sell next bar at market; buytocover next bar at market; end; if date_trade[1] <> date_trade then begin print(" true ", currentbar + maxbarsback); trade_on = true; end; if trade_on = true then begin print(" true generate ", currentbar + maxbarsback); if LECondition then begin Print (" generator buy ", currentbar + maxbarsback); Buy ( "CustomLE" ) next bar at market; end; if SECondition then begin Print (" generator sellshort ", currentbar + maxbarsback); Sell Short ( "CustomSE" ) next bar at market ; end; end;


Return to “MultiCharts”