ATR stop loss not working correctly

Questions about MultiCharts and user contributed studies.
sgjohnson1981
Posts: 29
Joined: 05 May 2021

ATR stop loss not working correctly

Postby sgjohnson1981 » 05 May 2021

Trying to use the synchronizers to manually trade with automatic exits as here: https://www.multicharts.com/trading-sof ... _at_a_Time

Yesterday I kept receiving warnings about tick to strategy calculation start lag warnings that ended up escalating to about 45 seconds until it finally automatically disabled auto trading. Today I haven't received any so who knows. Only had one workspace and three charts open while testing in only one of them. Broker was "Paper Trader." Datafeed is Rithmic.

Stop loss doesn't seem to work correctly either. Code below. Even though I can set it to 2X ATR, it stops out at only half-point loss. If ATR is about 6, then the stop should be 12 points, correct? The only three signals loaded are this, and the two synchronizers. Btw, this signal is a modified version of the "Stops & Targets" signal. I just commented out lines I didn't want to use. Thanks.

Code: Select all

[IntrabarOrderGeneration = true] inputs: ShareOrPosition( 1 ), {ProfitTargetAmt( 5 ),} ATRLength(14), StopLossPct( 1 ), {BreakevenFloorAmt( 0 ), DollarTrailingAmt( 0 ),} PctTrailingFloorPct( 0 ), PctTrailingPct( 0 ), ExitOnClose( false ) ; variables: StopLossAmt( 0 ), ATR( 0 ), PctTrailingFloorAmt( 0 ); ATR = AvgTrueRange(ATRLength); StopLossAmt = ATR * StopLossPct; PctTrailingFloorAmt = ATR * PctTrailingFloorPct; if ShareOrPosition = 1 then SetStopShare else SetStopPosition ; {if ProfitTargetAmt > 0 then SetProfitTarget( ProfitTargetAmt ) ;} if StopLossAmt > 0 then SetStopLoss( StopLossAmt ) ; {if BreakevenFloorAmt > 0 then SetBreakeven( BreakevenFloorAmt ) ; if DollarTrailingAmt > 0 then SetDollarTrailing( DollarTrailingAmt ) ;} condition1 = PctTrailingFloorPct > 0 and PctTrailingPct > 0 ; if condition1 then SetPercentTrailing( PctTrailingFloorAmt, PctTrailingPct ) ; if ExitOnClose = true then SetExitOnClose ;

sgjohnson1981
Posts: 29
Joined: 05 May 2021

Re: ATR stop loss not working correctly

Postby sgjohnson1981 » 05 May 2021

Here's applicable settings. Maybe something is set wrong.
Image
Attachments
Untitled.png
(33.01 KiB) Not downloaded yet

User avatar
syswizard
Posts: 295
Joined: 15 Dec 2012
Has thanked: 16 times
Been thanked: 28 times

Re: ATR stop loss not working correctly

Postby syswizard » 05 May 2021

re: "and the two synchronizers"
Which are those ?

sgjohnson1981
Posts: 29
Joined: 05 May 2021

Re: ATR stop loss not working correctly

Postby sgjohnson1981 » 05 May 2021

Untitled2.png
(21.82 KiB) Not downloaded yet

sgjohnson1981
Posts: 29
Joined: 05 May 2021

Re: ATR stop loss not working correctly

Postby sgjohnson1981 » 05 May 2021

Just received another of those warnings. 300 seconds this time. That's a whole 5 minutes. Something's def not right there.

User avatar
syswizard
Posts: 295
Joined: 15 Dec 2012
Has thanked: 16 times
Been thanked: 28 times

Re: ATR stop loss not working correctly

Postby syswizard » 06 May 2021

Try and disable the synchronizers.

sgjohnson1981
Posts: 29
Joined: 05 May 2021

Re: ATR stop loss not working correctly

Postby sgjohnson1981 » 06 May 2021

Try and disable the synchronizers.
And what would the point of that be considering it would disable the ability to sync manual trades with auto trades, which is one component of what I'm trying to do?

User avatar
syswizard
Posts: 295
Joined: 15 Dec 2012
Has thanked: 16 times
Been thanked: 28 times

Re: ATR stop loss not working correctly

Postby syswizard » 06 May 2021

so which one applies to you ? :
!From Broker To Strategy MP Synchronizer!
The strategy checks the market position at broker and then checks chart market position. If the positions are different, then the signal generates an emulated order with the number of contracts and average entry price as on broker end to match the broker position. The order is not sent to broker, so it affects only market position on chart for the strategy. It is displayed on the chart, but it is not shown in Order and Position Tracker window.

!From Strategy To Broker MP Synchronizer!
The strategy checks the market position at broker and then checks chart market position. If the positions are different, then the signal generates a market order with the number of contracts to match the chart position. The order is sent to broker, but the strategy itself is not aware of market position change, so it affects only broker position.

sgjohnson1981
Posts: 29
Joined: 05 May 2021

Re: ATR stop loss not working correctly

Postby sgjohnson1981 » 06 May 2021

Trying to follow the instructions from here: viewtopic.php?f=16&t=8499&p=56745&hilit ... try#p56745

It says you need one or the other in the link I shared in the first post. This link above says to use Broker to Strategy. Just tried every combination: both, and one or the other. Same results.

sgjohnson1981
Posts: 29
Joined: 05 May 2021

Re: ATR stop loss not working correctly

Postby sgjohnson1981 » 06 May 2021

Went through my exit code once more and found the error:

if StopLossAmt > 0 then SetStopLoss( StopLossAmt ) ;

should have been

if StopLossPct > 0 then SetStopLoss( StopLossAmt ) ;

That part seems to work OK now. Still getting the lag warning messages. Only have three charts open. Watching the processor usage, it doesn't go above 10%. Quad Core 2.6Ghz, 12GB memory....


Return to “MultiCharts”