How to get barssince a ApplyStop and what sell value the ApplyStop created

Hi

A newbie question, but what are the ways I can get BarsSince() my last ApplyStop was triggered, and on what (in my case) what SellPrice that it triggered?

My problem is that my system enters a new position when my stopTypeProfit is triggered and it uses the Open price, and it should use the stopTypeProfit price instead.

Best Regards

You should post your code.

ApplyStop is used to exit trades so it is confusing, when you say enter a new position.

Price at entry is defined in the Settings or by code using BuyPrice, ShortPrice etc

Kindly go through this:

Hi

Please find the relevant part of my code below;

Buy = HHV( H, 10 ) == HHV( H, 50 )
AND ROC( O, 50 )  > 0;

Sell = null;

BuyPrice = Open ;
tp =  ATR( 20 ) * 5;
sl = ATR( 20 )  * 10;

ApplyStop( stopTypeProfit, stopModePoint, tp , 1, 0, 0, 0 );
ApplyStop( stopTypeLoss, stopModePoint, SL , 1, 0, 0, 0 );

The problem occurs when a ApplyStop / stopTypeProfit exits trade #1, but the Buy requirements still are fulfilled, hence enters Trade #2 on the same bar. It will buy Trade #2 on the same bar as the exit of Trade #1, and to the Open price formula as above. This creates a huge error as the actual sell price in real life is above the Open price...

I want the BuyPrice for Trade #2 to be the old sellprice (Sellprice Trade #1) if this earlier position (Trade #1) have triggered an ApplyStop / stopTypeProfit on the same bar as a New trade (Trade #2) is opened.

Sorry for the confusion and I hope this makes my headache more visible.

My initial thought was to use some Bars since () function to see if a exit have happened when Trade#2 occurred, but i never got it right. And I guess there are better solutions.

Best Regards

You have to follow the manual precisely.

You have to read everything.
There are four supported scenarios mentioned there.

In your case of entry at open and exit intraday at stop you have to apply Scenario #1

Scenario 1:
you trade on next bar OPEN and want to exit intraday on stop price

Correct settings:
ActivateStopsImmediately turned ON
ExitAtStop = 1
Trade delays set to one
Trade price set to open

SetTradeDelays(1,1,1,1);
SetOption("ActivateStopsImmediately", 1);

BuyPrice = Open ;
Buy = HHV( H, 10 ) == HHV( H, 50 ) AND ROC( O, 50 )  > 0;
Sell = 0;

tp = ATR( 20 ) * 5;
sl = ATR( 20 ) * 10;
ApplyStop( stopTypeProfit, stopModePoint, tp, exitatstop = 1, 0, 0, 0 );
ApplyStop( stopTypeLoss, stopModePoint, SL, exitatstop, 0, 0, 0 );

Create a custom looping code (instead of ApplyStop then).

2 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.