StopLoss order canceled on every bar open

Questions about MultiCharts and user contributed studies.
dvdkite
Posts: 65
Joined: 16 May 2018
Has thanked: 10 times
Been thanked: 1 time

StopLoss order canceled on every bar open

Postby dvdkite » 08 Jul 2020

Hello,

Inside my strategy I need to set an OCO order with Stoploss and Target immediately after the system has opened a position.
I NEED to set the Stoploss only at the close of the candle where the entry order has been filled, because i need some time for the exact calculation of the stop loss value (in my case the TRADEstopLoss value ).
So I thought to simply put the condition " if barstatus = 2 " before the stop order and this worked just fine in the backtest, but TODAY in realtime (with real money) testing when the system entered a position it was able to set up the target easily but the STOP loss order keeping to be set and then rejected/canceled at the end of every bar.
The system is running over a 100tick chart and really at the end of every bar , when market position is 1 or -1, it continued to set the stop loss and cancel it the second later.
So basically I only had a target on the chart, the stop loss appear for a millisecond and then disappear the second after and by this way I cannot protect myself from sudden movement.

This is the code I'm using ( short position example ):

Code: Select all

if marketposition = -1 then begin if currentcontracts = 1 then begin buytocover ( " Target SE ")1 contract next bar at entryprice - (TargetPoints * TickSize ) limit; if barstatus = 2 then buytocover ( " Stop SE ")1 contract next bar at TRADEstopLoss + StopOffSet stop; if time >= Time_CLOSE_SESSION - 10 and time < Time_CLOSE_SESSION - 1 then buytocover("SE CLOSE SESSION") 1 ontract next bar at market; end; ...................................... ............................... .............
Do you have any suggestion about how can I make it work? I just need to send the stoploss order at the end of the bar (that's why I used barstatus = 2)....
Thanks

David

User avatar
Tammy MultiCharts
Posts: 200
Joined: 06 Aug 2020
Has thanked: 6 times
Been thanked: 65 times

Re: StopLoss order canceled on every bar open

Postby Tammy MultiCharts » 21 Aug 2020

Hello,

1. Orders in MultiCharts are sent to the broker if the conditions for sending them are met in the code. If the conditions are not met the orders are cancelled.
2. You probably have Intra-Bar Order Generation on. In this case the strategy is calculated on each tick. When the bar is closed, its Barstatus(1) = 2, the orders are placed. Then, on the next tick the Barstatus(1) = 1, it does not meet the condition “if Barstatus(1)=2, then”, therefore the orders are not placed.
The possible solutions would be:
1. Disable IOG
2. Modify your signal so that the orders are placed on the bar close, but not cancelled if Barstatus(1)=1

(see an example in the next post)

User avatar
Tammy MultiCharts
Posts: 200
Joined: 06 Aug 2020
Has thanked: 6 times
Been thanked: 65 times

Re: StopLoss order canceled on every bar open

Postby Tammy MultiCharts » 21 Aug 2020

For example:

Code: Select all

var: flag(false); once cleardebug; sellshort next bar market; if marketposition = -1 then begin if currentcontracts = 1 then begin if barstatus(1) = 2 then begin flag = true; end; if barstatus(1) = 0 then begin flag = false; end; if (flag) then begin print("currentbar = ", currentbar + maxbarsback, " bs1 = ", barstatus(1), " ", flag); buytocover ( " Target SE ") 1 contract next bar at entryprice - (5 * TickSize ) limit; buytocover ( " Stop SE ") 1 contract next bar at entryprice + (5 * TickSize ) stop; end; end; end;


Return to “MultiCharts”