Prevent Order Generation Before Session Close  [SOLVED]

Questions about MultiCharts and user contributed studies.
Doctor Al
Posts: 24
Joined: 15 Aug 2019
Has thanked: 4 times

Prevent Order Generation Before Session Close

Postby Doctor Al » 23 Oct 2019

I developed a trading system that trades on 240 Minute price bars, although the last bar of the trading session is 180 Minutes in Length, cut short because the session ends at 16:00 (exchange time) ( i.e. trading does not extend to 17:00 exchange time, when the bar would otherwise end).
The next day's session opens at 17:00 (exchange time), after the one hour break. I hold positions over the one hour break. I was attempting to maintain
my strategy automation over the one hour break, but my stop-loss orders are being repetitively sent to the market during the break, and therefore strategy automation is being disabled due to the numerous order rejections. I asked support about this situation and was advised that I could consider

"2) Move the logic for generating the special orders in a separate signal script. Enable IOG for this signal (Format -> Signal -> Format -> Properties):

https://www.multicharts.com/trading-sof ... Generation

Enhance this script with the logic that will monitor the current time and stop generating the orders in several minutes (or seconds) before the session end.

I am wondering if someone would be willing to help me with the logic that would monitor the current time and stop generating orders before the session end.

Preliminarily, I could copy code like below from my original strategy (for exiting a short position), but it doesn't monitor the time and prevent orders
from being generated near the close of the day session

Code: Select all

Inputs:
NBarEx1 (25), { Number of bars from entry for market exit }
NATRTrail (28), { Indicator look-back length (bars) }
ATRFrTrail (2.1301), { Multiple of price difference (e.g., ATR); exit }
TrailPct (63), { Trailing stop percentage }
MMStopPct (1.485), { Value of percentage money management stop }
MMStop(1.4878);

Var: ATRTrail (0),
SStop (0),
NewSStop (0),
StopAmnt (0),
STrailOn (false),
EndofSess (false);

{ Average true range }
ATRTrail = AvgTrueRange(NATRTrail);

{ Exit orders, short trades }
If MarketPosition = -1 then begin
If BarsSinceEntry = 0 then begin
SStop = (1 + MMStopPct/100.0) * EntryPrice;
STrailOn = false;
end;

If EntryPrice - C > ATRFrTrail * ATRTrail then
STrailOn = true;

If STrailOn then begin
NewSStop = EntryPrice - TrailPct * (EntryPrice - C)/100.0;
SStop = MinList(SStop, NewSStop);
end;

Buy to cover("ExStop-S") next bar at SStop stop;

If BarsSinceEntry >= NBarEx1 then
Buy to cover("ExMark-S") next bar at market;
end;

SetStopShare;
If MarketPosition <> 0 then
Begin
StopAmnt = MMStop;
SetStopLoss(StopAmnt);
End

else
Begin
StopAmnt = MMStop;
SetStopLoss(StopAmnt);
End;

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

Re: Prevent Order Generation Before Session Close

Postby TJ » 23 Oct 2019


Doctor Al
Posts: 24
Joined: 15 Aug 2019
Has thanked: 4 times

Re: Prevent Order Generation Before Session Close  [SOLVED]

Postby Doctor Al » 24 Oct 2019

Thanks TJ. Post 15 was also very helpful for this.


Return to “MultiCharts”